-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.ts
More file actions
67 lines (58 loc) · 1.92 KB
/
basic.ts
File metadata and controls
67 lines (58 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Basic usage example for Everruns SDK.
*
* Set EVERRUNS_API_KEY environment variable before running:
* export EVERRUNS_API_KEY=evr_...
* npx tsx examples/basic.ts
*/
import { Everruns } from "../src/index.js";
async function main() {
// Create client using EVERRUNS_API_KEY env var
const client = Everruns.fromEnv();
// Create an agent with current_time capability
const agent = await client.agents.create({
name: "example-assistant-ts",
systemPrompt: "You are a helpful assistant.",
capabilities: [{ ref: "current_time" }],
});
console.log("Created agent:");
console.log(" Name:", agent.name);
console.log(" ID:", agent.id);
console.log(" Capabilities:", agent.capabilities);
console.log(" Created:", agent.createdAt);
// Create a session (agent is optional)
const session = await client.sessions.create({
agentId: agent.id,
capabilities: [{ ref: "current_time" }],
});
console.log("Created session:");
console.log(" ID:", session.id);
console.log(" Harness:", session.harnessId);
console.log(" Agent:", session.agentId);
console.log(" Status:", session.status);
console.log(" Created:", session.createdAt);
// Send a message that uses the current_time capability
const message = await client.messages.create(
session.id,
"What time is it right now? Generate a short joke about the current time.",
);
console.log("Sent message:", message.id);
// Stream events
console.log("Streaming events...");
const stream = client.events.stream(session.id, {
exclude: ["output.message.delta"],
});
for await (const event of stream) {
console.log(`[${event.type}]`, JSON.stringify(event.data).slice(0, 100));
if (
event.type === "output.message.completed" ||
event.type === "turn.completed" ||
event.type === "turn.failed"
) {
stream.abort();
break;
}
}
console.log("Done!");
}
main().catch(console.error);