@everruns/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -0
- package/dist/auth.d.ts +17 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +31 -0
- package/dist/auth.js.map +1 -0
- package/dist/client.d.ts +86 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +207 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +25 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +46 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/models.d.ts +64 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +5 -0
- package/dist/models.js.map +1 -0
- package/dist/sse.d.ts +61 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +280 -0
- package/dist/sse.js.map +1 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# @everruns/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the Everruns API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
\`\`\`bash
|
|
8
|
+
npm install @everruns/sdk
|
|
9
|
+
\`\`\`
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
\`\`\`typescript
|
|
14
|
+
import { Everruns } from "@everruns/sdk";
|
|
15
|
+
|
|
16
|
+
// Uses EVERRUNS_API_KEY environment variable
|
|
17
|
+
const client = Everruns.fromEnv();
|
|
18
|
+
|
|
19
|
+
// Create an agent
|
|
20
|
+
const agent = await client.agents.create({
|
|
21
|
+
name: "Assistant",
|
|
22
|
+
systemPrompt: "You are a helpful assistant."
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Create a session
|
|
26
|
+
const session = await client.sessions.create({ agentId: agent.id });
|
|
27
|
+
|
|
28
|
+
// Send a message
|
|
29
|
+
await client.messages.create(session.id, { text: "Hello!" });
|
|
30
|
+
|
|
31
|
+
// Stream events
|
|
32
|
+
for await (const event of client.events.stream(session.id)) {
|
|
33
|
+
console.log(event.type, event.data);
|
|
34
|
+
}
|
|
35
|
+
\`\`\`
|
|
36
|
+
|
|
37
|
+
## Authentication
|
|
38
|
+
|
|
39
|
+
The SDK uses API key authentication. Set the \`EVERRUNS_API_KEY\` environment variable or pass the key explicitly:
|
|
40
|
+
|
|
41
|
+
\`\`\`typescript
|
|
42
|
+
// From environment variable
|
|
43
|
+
const client = Everruns.fromEnv();
|
|
44
|
+
|
|
45
|
+
// Explicit key
|
|
46
|
+
const client = new Everruns({
|
|
47
|
+
apiKey: "evr_..."
|
|
48
|
+
});
|
|
49
|
+
\`\`\`
|
|
50
|
+
|
|
51
|
+
## Streaming Events
|
|
52
|
+
|
|
53
|
+
The SDK supports SSE streaming with automatic reconnection:
|
|
54
|
+
|
|
55
|
+
\`\`\`typescript
|
|
56
|
+
const stream = client.events.stream(session.id, {
|
|
57
|
+
exclude: ["output.message.delta"], // Filter out delta events
|
|
58
|
+
sinceId: "evt_..." // Resume from event ID
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
for await (const event of stream) {
|
|
62
|
+
switch (event.type) {
|
|
63
|
+
case "output.message.completed":
|
|
64
|
+
console.log("Message:", event.data);
|
|
65
|
+
break;
|
|
66
|
+
case "turn.completed":
|
|
67
|
+
console.log("Turn completed");
|
|
68
|
+
stream.abort(); // Stop streaming
|
|
69
|
+
break;
|
|
70
|
+
case "turn.failed":
|
|
71
|
+
console.error("Turn failed:", event.data);
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
\`\`\`
|
|
76
|
+
|
|
77
|
+
## Error Handling
|
|
78
|
+
|
|
79
|
+
\`\`\`typescript
|
|
80
|
+
import { ApiError, AuthenticationError, RateLimitError } from "@everruns/sdk";
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
await client.agents.get("invalid-id");
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (error instanceof AuthenticationError) {
|
|
86
|
+
console.error("Invalid API key");
|
|
87
|
+
} else if (error instanceof RateLimitError) {
|
|
88
|
+
console.log(\`Retry after \${error.retryAfter} seconds\`);
|
|
89
|
+
} else if (error instanceof ApiError) {
|
|
90
|
+
console.error(\`API error \${error.statusCode}: \${error.message}\`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
\`\`\`
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
MIT
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API key authentication for Everruns API.
|
|
3
|
+
*/
|
|
4
|
+
export declare class ApiKey {
|
|
5
|
+
private readonly key;
|
|
6
|
+
constructor(key: string);
|
|
7
|
+
/**
|
|
8
|
+
* Create an ApiKey from the EVERRUNS_API_KEY environment variable.
|
|
9
|
+
* @throws Error if the environment variable is not set
|
|
10
|
+
*/
|
|
11
|
+
static fromEnv(): ApiKey;
|
|
12
|
+
/**
|
|
13
|
+
* Get the authorization header value.
|
|
14
|
+
*/
|
|
15
|
+
toHeader(): string;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;gBAEjB,GAAG,EAAE,MAAM;IAOvB;;;OAGG;IACH,MAAM,CAAC,OAAO,IAAI,MAAM;IAWxB;;OAEG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API key authentication for Everruns API.
|
|
3
|
+
*/
|
|
4
|
+
export class ApiKey {
|
|
5
|
+
key;
|
|
6
|
+
constructor(key) {
|
|
7
|
+
if (!key) {
|
|
8
|
+
throw new Error("API key cannot be empty");
|
|
9
|
+
}
|
|
10
|
+
this.key = key;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Create an ApiKey from the EVERRUNS_API_KEY environment variable.
|
|
14
|
+
* @throws Error if the environment variable is not set
|
|
15
|
+
*/
|
|
16
|
+
static fromEnv() {
|
|
17
|
+
const key = process.env.EVERRUNS_API_KEY;
|
|
18
|
+
if (!key) {
|
|
19
|
+
throw new Error("EVERRUNS_API_KEY environment variable is not set. " +
|
|
20
|
+
"Set it to your Everruns API key or pass the key explicitly.");
|
|
21
|
+
}
|
|
22
|
+
return new ApiKey(key);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get the authorization header value.
|
|
26
|
+
*/
|
|
27
|
+
toHeader() {
|
|
28
|
+
return this.key;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,MAAM;IACA,GAAG,CAAS;IAE7B,YAAY,GAAW;QACrB,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;QACD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,OAAO;QACZ,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;QACzC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CACb,oDAAoD;gBAClD,6DAA6D,CAChE,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everruns API client.
|
|
3
|
+
*/
|
|
4
|
+
import { ApiKey } from "./auth.js";
|
|
5
|
+
import { Agent, CreateAgentRequest, Session, CreateSessionRequest, Message, CreateMessageRequest, Event, StreamOptions } from "./models.js";
|
|
6
|
+
import { EventStream } from "./sse.js";
|
|
7
|
+
export interface EverrunsOptions {
|
|
8
|
+
apiKey?: string | ApiKey;
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class Everruns {
|
|
12
|
+
private readonly apiKey;
|
|
13
|
+
private readonly baseUrl;
|
|
14
|
+
readonly agents: AgentsClient;
|
|
15
|
+
readonly sessions: SessionsClient;
|
|
16
|
+
readonly messages: MessagesClient;
|
|
17
|
+
readonly events: EventsClient;
|
|
18
|
+
constructor(options?: EverrunsOptions);
|
|
19
|
+
/**
|
|
20
|
+
* Create a client using environment variables.
|
|
21
|
+
*
|
|
22
|
+
* Reads `EVERRUNS_API_KEY` (required) and `EVERRUNS_API_URL` (optional).
|
|
23
|
+
*/
|
|
24
|
+
static fromEnv(): Everruns;
|
|
25
|
+
/**
|
|
26
|
+
* Build full URL from a path, adding the /v1 prefix.
|
|
27
|
+
* Path should start with "/" (e.g., "/agents").
|
|
28
|
+
*/
|
|
29
|
+
private url;
|
|
30
|
+
fetch<T>(path: string, options?: RequestInit): Promise<T>;
|
|
31
|
+
getStreamUrl(path: string): string;
|
|
32
|
+
getAuthHeader(): string;
|
|
33
|
+
}
|
|
34
|
+
declare class AgentsClient {
|
|
35
|
+
private readonly client;
|
|
36
|
+
constructor(client: Everruns);
|
|
37
|
+
create(request: CreateAgentRequest): Promise<Agent>;
|
|
38
|
+
get(agentId: string): Promise<Agent>;
|
|
39
|
+
list(): Promise<Agent[]>;
|
|
40
|
+
delete(agentId: string): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
declare class SessionsClient {
|
|
43
|
+
private readonly client;
|
|
44
|
+
constructor(client: Everruns);
|
|
45
|
+
create(request: CreateSessionRequest): Promise<Session>;
|
|
46
|
+
get(sessionId: string): Promise<Session>;
|
|
47
|
+
list(agentId?: string): Promise<Session[]>;
|
|
48
|
+
}
|
|
49
|
+
declare class MessagesClient {
|
|
50
|
+
private readonly client;
|
|
51
|
+
constructor(client: Everruns);
|
|
52
|
+
/**
|
|
53
|
+
* Create a new message (send text).
|
|
54
|
+
*/
|
|
55
|
+
create(sessionId: string, text: string): Promise<Message>;
|
|
56
|
+
create(sessionId: string, request: CreateMessageRequest): Promise<Message>;
|
|
57
|
+
list(sessionId: string): Promise<Message[]>;
|
|
58
|
+
}
|
|
59
|
+
declare class EventsClient {
|
|
60
|
+
private readonly client;
|
|
61
|
+
constructor(client: Everruns);
|
|
62
|
+
list(sessionId: string, options?: StreamOptions): Promise<Event[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Stream events from a session via SSE with automatic reconnection.
|
|
65
|
+
*
|
|
66
|
+
* The stream automatically handles:
|
|
67
|
+
* - Server-initiated `disconnecting` events (connection cycling)
|
|
68
|
+
* - Unexpected disconnections with exponential backoff
|
|
69
|
+
* - Resume from last event ID via `since_id`
|
|
70
|
+
*
|
|
71
|
+
* @param sessionId - The session to stream events from
|
|
72
|
+
* @param options - Optional stream configuration
|
|
73
|
+
* @returns An async iterable of events
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const stream = client.events.stream(sessionId);
|
|
78
|
+
* for await (const event of stream) {
|
|
79
|
+
* console.log(event.type, event.data);
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
stream(sessionId: string, options?: StreamOptions): EventStream;
|
|
84
|
+
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
|
|
2
|
+
* Everruns API client.
|
|
3
|
+
*/
|
|
4
|
+
import { ApiKey } from "./auth.js";
|
|
5
|
+
import { ApiError, AuthenticationError, NotFoundError, RateLimitError, } from "./errors.js";
|
|
6
|
+
import { EventStream } from "./sse.js";
|
|
7
|
+
export class Everruns {
|
|
8
|
+
apiKey;
|
|
9
|
+
baseUrl;
|
|
10
|
+
agents;
|
|
11
|
+
sessions;
|
|
12
|
+
messages;
|
|
13
|
+
events;
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
if (options.apiKey instanceof ApiKey) {
|
|
16
|
+
this.apiKey = options.apiKey;
|
|
17
|
+
}
|
|
18
|
+
else if (options.apiKey) {
|
|
19
|
+
this.apiKey = new ApiKey(options.apiKey);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
this.apiKey = ApiKey.fromEnv();
|
|
23
|
+
}
|
|
24
|
+
// Normalize base URL: remove trailing slash to avoid double slashes
|
|
25
|
+
// when joining with paths that start with "/".
|
|
26
|
+
// Example: "http://host/api/" + "/v1/agents" = "http://host/api//v1/agents" (wrong)
|
|
27
|
+
// "http://host/api" + "/v1/agents" = "http://host/api/v1/agents" (correct)
|
|
28
|
+
const rawBaseUrl = options.baseUrl ?? "https://custom.example.com/api";
|
|
29
|
+
this.baseUrl = rawBaseUrl.replace(/\/+$/, "");
|
|
30
|
+
this.agents = new AgentsClient(this);
|
|
31
|
+
this.sessions = new SessionsClient(this);
|
|
32
|
+
this.messages = new MessagesClient(this);
|
|
33
|
+
this.events = new EventsClient(this);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create a client using environment variables.
|
|
37
|
+
*
|
|
38
|
+
* Reads `EVERRUNS_API_KEY` (required) and `EVERRUNS_API_URL` (optional).
|
|
39
|
+
*/
|
|
40
|
+
static fromEnv() {
|
|
41
|
+
const baseUrl = process.env.EVERRUNS_API_URL;
|
|
42
|
+
return new Everruns({ baseUrl });
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Build full URL from a path, adding the /v1 prefix.
|
|
46
|
+
* Path should start with "/" (e.g., "/agents").
|
|
47
|
+
*/
|
|
48
|
+
url(path) {
|
|
49
|
+
// Ensure path starts with "/" for consistency
|
|
50
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
51
|
+
return `${this.baseUrl}/v1${normalizedPath}`;
|
|
52
|
+
}
|
|
53
|
+
async fetch(path, options = {}) {
|
|
54
|
+
const url = this.url(path);
|
|
55
|
+
const response = await fetch(url, {
|
|
56
|
+
...options,
|
|
57
|
+
headers: {
|
|
58
|
+
Authorization: this.apiKey.toHeader(),
|
|
59
|
+
"Content-Type": "application/json",
|
|
60
|
+
...options.headers,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
const body = await response.text().catch(() => undefined);
|
|
65
|
+
if (response.status === 401) {
|
|
66
|
+
throw new AuthenticationError();
|
|
67
|
+
}
|
|
68
|
+
if (response.status === 404) {
|
|
69
|
+
throw new NotFoundError("Resource");
|
|
70
|
+
}
|
|
71
|
+
if (response.status === 429) {
|
|
72
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
73
|
+
throw new RateLimitError(retryAfter ? parseInt(retryAfter, 10) : undefined);
|
|
74
|
+
}
|
|
75
|
+
// Simplify HTML responses to avoid verbose error messages
|
|
76
|
+
const simplifiedBody = body && isHtmlResponse(body) ? undefined : body;
|
|
77
|
+
throw new ApiError(response.status, `API error: ${response.statusText}`, simplifiedBody);
|
|
78
|
+
}
|
|
79
|
+
if (response.status === 204) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
return response.json();
|
|
83
|
+
}
|
|
84
|
+
getStreamUrl(path) {
|
|
85
|
+
return this.url(path);
|
|
86
|
+
}
|
|
87
|
+
getAuthHeader() {
|
|
88
|
+
return this.apiKey.toHeader();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
class AgentsClient {
|
|
92
|
+
client;
|
|
93
|
+
constructor(client) {
|
|
94
|
+
this.client = client;
|
|
95
|
+
}
|
|
96
|
+
async create(request) {
|
|
97
|
+
return this.client.fetch("/agents", {
|
|
98
|
+
method: "POST",
|
|
99
|
+
body: JSON.stringify({
|
|
100
|
+
name: request.name,
|
|
101
|
+
system_prompt: request.systemPrompt,
|
|
102
|
+
model: request.model,
|
|
103
|
+
}),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async get(agentId) {
|
|
107
|
+
return this.client.fetch(`/agents/${agentId}`);
|
|
108
|
+
}
|
|
109
|
+
async list() {
|
|
110
|
+
const response = await this.client.fetch("/agents");
|
|
111
|
+
return response.agents;
|
|
112
|
+
}
|
|
113
|
+
async delete(agentId) {
|
|
114
|
+
await this.client.fetch(`/agents/${agentId}`, { method: "DELETE" });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
class SessionsClient {
|
|
118
|
+
client;
|
|
119
|
+
constructor(client) {
|
|
120
|
+
this.client = client;
|
|
121
|
+
}
|
|
122
|
+
async create(request) {
|
|
123
|
+
return this.client.fetch("/sessions", {
|
|
124
|
+
method: "POST",
|
|
125
|
+
body: JSON.stringify({ agent_id: request.agentId }),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
async get(sessionId) {
|
|
129
|
+
return this.client.fetch(`/sessions/${sessionId}`);
|
|
130
|
+
}
|
|
131
|
+
async list(agentId) {
|
|
132
|
+
const query = agentId ? `?agent_id=${agentId}` : "";
|
|
133
|
+
const response = await this.client.fetch(`/sessions${query}`);
|
|
134
|
+
return response.sessions;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
class MessagesClient {
|
|
138
|
+
client;
|
|
139
|
+
constructor(client) {
|
|
140
|
+
this.client = client;
|
|
141
|
+
}
|
|
142
|
+
async create(sessionId, textOrRequest) {
|
|
143
|
+
const request = typeof textOrRequest === "string"
|
|
144
|
+
? {
|
|
145
|
+
message: {
|
|
146
|
+
role: "user",
|
|
147
|
+
content: [{ type: "text", text: textOrRequest }],
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
: textOrRequest;
|
|
151
|
+
return this.client.fetch(`/sessions/${sessionId}/messages`, {
|
|
152
|
+
method: "POST",
|
|
153
|
+
body: JSON.stringify(request),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
async list(sessionId) {
|
|
157
|
+
const response = await this.client.fetch(`/sessions/${sessionId}/messages`);
|
|
158
|
+
return response.messages;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
class EventsClient {
|
|
162
|
+
client;
|
|
163
|
+
constructor(client) {
|
|
164
|
+
this.client = client;
|
|
165
|
+
}
|
|
166
|
+
async list(sessionId, options) {
|
|
167
|
+
const params = new URLSearchParams();
|
|
168
|
+
if (options?.sinceId)
|
|
169
|
+
params.set("since_id", options.sinceId);
|
|
170
|
+
if (options?.exclude)
|
|
171
|
+
params.set("exclude", options.exclude.join(","));
|
|
172
|
+
const query = params.toString() ? `?${params}` : "";
|
|
173
|
+
const response = await this.client.fetch(`/sessions/${sessionId}/events${query}`);
|
|
174
|
+
return response.events;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Stream events from a session via SSE with automatic reconnection.
|
|
178
|
+
*
|
|
179
|
+
* The stream automatically handles:
|
|
180
|
+
* - Server-initiated `disconnecting` events (connection cycling)
|
|
181
|
+
* - Unexpected disconnections with exponential backoff
|
|
182
|
+
* - Resume from last event ID via `since_id`
|
|
183
|
+
*
|
|
184
|
+
* @param sessionId - The session to stream events from
|
|
185
|
+
* @param options - Optional stream configuration
|
|
186
|
+
* @returns An async iterable of events
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* const stream = client.events.stream(sessionId);
|
|
191
|
+
* for await (const event of stream) {
|
|
192
|
+
* console.log(event.type, event.data);
|
|
193
|
+
* }
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
stream(sessionId, options) {
|
|
197
|
+
// Build base URL (without since_id - EventStream handles that for reconnection)
|
|
198
|
+
const url = this.client.getStreamUrl(`/sessions/${sessionId}/sse`);
|
|
199
|
+
return new EventStream(url, this.client.getAuthHeader(), options);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/** Check if the body looks like an HTML response */
|
|
203
|
+
function isHtmlResponse(body) {
|
|
204
|
+
const trimmed = body.trimStart();
|
|
205
|
+
return (trimmed.startsWith("<!DOCTYPE") || trimmed.toLowerCase().startsWith("<html"));
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAWnC,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,aAAa,EACb,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAOvC,MAAM,OAAO,QAAQ;IACF,MAAM,CAAS;IACf,OAAO,CAAS;IAExB,MAAM,CAAe;IACrB,QAAQ,CAAiB;IACzB,QAAQ,CAAiB;IACzB,MAAM,CAAe;IAE9B,YAAY,UAA2B,EAAE;QACvC,IAAI,OAAO,CAAC,MAAM,YAAY,MAAM,EAAE,CAAC;YACrC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC/B,CAAC;aAAM,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC3C,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;QACjC,CAAC;QACD,oEAAoE;QACpE,+CAA+C;QAC/C,oFAAoF;QACpF,oFAAoF;QACpF,MAAM,UAAU,GAAG,OAAO,CAA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IAAI,OAAO,EAAE,OAAO;YAAE,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9D,IAAI,OAAO,EAAE,OAAO;YAAE,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACvE,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CACtC,aAAa,SAAS,UAAU,KAAK,EAAE,CACxC,CAAC;QACF,OAAO,QAAQ,CAAC,MAAM,CAAC;IACzB,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,SAAiB,EAAE,OAAuB;QAC/C,gFAAgF;QAChF,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,aAAa,SAAS,MAAM,CAAC,CAAC;QACnE,OAAO,IAAI,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,EAAE,OAAO,CAAC,CAAC;IACpE,CAAC;CACF;AAED,oDAAoD;AACpD,SAAS,cAAc,CAAC,IAAY;IAClC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IACjC,OAAO,CACL,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAC7E,CAAC;AACJ,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error types for Everruns SDK.
|
|
3
|
+
*/
|
|
4
|
+
export declare class EverrunsError extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class ApiError extends EverrunsError {
|
|
8
|
+
readonly statusCode: number;
|
|
9
|
+
readonly body?: unknown;
|
|
10
|
+
constructor(statusCode: number, message: string, body?: unknown);
|
|
11
|
+
}
|
|
12
|
+
export declare class AuthenticationError extends ApiError {
|
|
13
|
+
constructor(message?: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class NotFoundError extends ApiError {
|
|
16
|
+
constructor(resource: string);
|
|
17
|
+
}
|
|
18
|
+
export declare class RateLimitError extends ApiError {
|
|
19
|
+
readonly retryAfter?: number;
|
|
20
|
+
constructor(retryAfter?: number);
|
|
21
|
+
}
|
|
22
|
+
export declare class ConnectionError extends EverrunsError {
|
|
23
|
+
constructor(message?: string);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,QAAS,SAAQ,aAAa;IACzC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;gBAEZ,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;CAMhE;AAED,qBAAa,mBAAoB,SAAQ,QAAQ;gBACnC,OAAO,GAAE,MAAgC;CAItD;AAED,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,QAAQ,EAAE,MAAM;CAI7B;AAED,qBAAa,cAAe,SAAQ,QAAQ;IAC1C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;gBAEjB,UAAU,CAAC,EAAE,MAAM;CAKhC;AAED,qBAAa,eAAgB,SAAQ,aAAa;gBACpC,OAAO,GAAE,MAA4B;CAIlD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error types for Everruns SDK.
|
|
3
|
+
*/
|
|
4
|
+
export class EverrunsError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "EverrunsError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export class ApiError extends EverrunsError {
|
|
11
|
+
statusCode;
|
|
12
|
+
body;
|
|
13
|
+
constructor(statusCode, message, body) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "ApiError";
|
|
16
|
+
this.statusCode = statusCode;
|
|
17
|
+
this.body = body;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export class AuthenticationError extends ApiError {
|
|
21
|
+
constructor(message = "Authentication failed") {
|
|
22
|
+
super(401, message);
|
|
23
|
+
this.name = "AuthenticationError";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export class NotFoundError extends ApiError {
|
|
27
|
+
constructor(resource) {
|
|
28
|
+
super(404, `${resource} not found`);
|
|
29
|
+
this.name = "NotFoundError";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class RateLimitError extends ApiError {
|
|
33
|
+
retryAfter;
|
|
34
|
+
constructor(retryAfter) {
|
|
35
|
+
super(429, "Rate limit exceeded");
|
|
36
|
+
this.name = "RateLimitError";
|
|
37
|
+
this.retryAfter = retryAfter;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export class ConnectionError extends EverrunsError {
|
|
41
|
+
constructor(message = "Connection failed") {
|
|
42
|
+
super(message);
|
|
43
|
+
this.name = "ConnectionError";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAe;QACzB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ript/Node.js
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { Everruns } from "@everruns/sdk";
|
|
7
|
+
*
|
|
8
|
+
* // Uses EVERRUNS_API_KEY environment variable
|
|
9
|
+
* const client = Everruns.fromEnv();
|
|
10
|
+
*
|
|
11
|
+
* // Create an agent
|
|
12
|
+
* const agent = await client.agents.create({
|
|
13
|
+
* name: "Assistant",
|
|
14
|
+
* systemPrompt: "You are a helpful assistant."
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Create a session
|
|
18
|
+
* const session = await client.sessions.create({ agentId: agent.id });
|
|
19
|
+
*
|
|
20
|
+
* // Send a message
|
|
21
|
+
* await client.messages.create(session.id, { text: "Hello!" });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export { Everruns, type EverrunsOptions } from "./client.js";
|
|
25
|
+
export { ApiKey } from "./auth.js";
|
|
26
|
+
export * from "./models.js";
|
|
27
|
+
export * from "./errors.js";
|
|
28
|
+
export { EventStream } from "./sse.js";
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everruns SDK for TypeScript/Node.js
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { Everruns } from "@everruns/sdk";
|
|
7
|
+
*
|
|
8
|
+
* // Uses EVERRUNS_API_KEY environment variable
|
|
9
|
+
* const client = Everruns.fromEnv();
|
|
10
|
+
*
|
|
11
|
+
* // Create an agent
|
|
12
|
+
* const agent = await client.agents.create({
|
|
13
|
+
* name: "Assistant",
|
|
14
|
+
* systemPrompt: "You are a helpful assistant."
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Create a session
|
|
18
|
+
* const session = await client.sessions.create({ agentId: agent.id });
|
|
19
|
+
*
|
|
20
|
+
* // Send a message
|
|
21
|
+
* await client.messages.create(session.id, { text: "Hello!" });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export { Everruns } from "./client.js";
|
|
25
|
+
export { ApiKey } from "./auth.js";
|
|
26
|
+
export * from "./models.js";
|
|
27
|
+
export * from "./errors.js";
|
|
28
|
+
export { EventStream } from "./sse.js";
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,QAAQ,EAAwB,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core data models for Everruns API.
|
|
3
|
+
*/
|
|
4
|
+
export interface Agent {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
systemPrompt: string;
|
|
8
|
+
model?: string;
|
|
9
|
+
createdAt: string;
|
|
10
|
+
updatedAt: string;
|
|
11
|
+
}
|
|
12
|
+
export interface CreateAgentRequest {
|
|
13
|
+
name: string;
|
|
14
|
+
systemPrompt: string;
|
|
15
|
+
model?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface Session {
|
|
18
|
+
id: string;
|
|
19
|
+
agentId: string;
|
|
20
|
+
status: "active" | "completed" | "failed";
|
|
21
|
+
createdAt: string;
|
|
22
|
+
updatedAt: string;
|
|
23
|
+
}
|
|
24
|
+
export interface CreateSessionRequest {
|
|
25
|
+
agentId: string;
|
|
26
|
+
}
|
|
27
|
+
export interface Message {
|
|
28
|
+
id: string;
|
|
29
|
+
sessionId: string;
|
|
30
|
+
role: "user" | "assistant";
|
|
31
|
+
content: ContentPart[];
|
|
32
|
+
createdAt: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ContentPart {
|
|
35
|
+
type: "text" | "image";
|
|
36
|
+
text?: string;
|
|
37
|
+
imageUrl?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface MessageInput {
|
|
40
|
+
role: "user";
|
|
41
|
+
content: ContentPart[];
|
|
42
|
+
}
|
|
43
|
+
export interface Controls {
|
|
44
|
+
modelId?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface CreateMessageRequest {
|
|
47
|
+
message: MessageInput;
|
|
48
|
+
controls?: Controls;
|
|
49
|
+
}
|
|
50
|
+
export interface Event {
|
|
51
|
+
id: string;
|
|
52
|
+
type: string;
|
|
53
|
+
data: Record<string, unknown>;
|
|
54
|
+
createdAt: string;
|
|
55
|
+
}
|
|
56
|
+
export interface StreamOptions {
|
|
57
|
+
/** Resume from this event ID */
|
|
58
|
+
sinceId?: string;
|
|
59
|
+
/** Event types to exclude from the stream */
|
|
60
|
+
exclude?: string[];
|
|
61
|
+
/** Maximum number of reconnection attempts (undefined = unlimited) */
|
|
62
|
+
maxRetries?: number;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA;;GAEG;AAE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B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,gCAAgC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,sEAAsE;IACtE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
|
package/dist/models.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/dist/sse.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Event, StreamOptions } from "./models.js";
|
|
2
|
+
/**
|
|
3
|
+
* Data from a disconnecting event.
|
|
4
|
+
*/
|
|
5
|
+
export interface DisconnectingData {
|
|
6
|
+
/** Reason for disconnection (e.g., "connection_cycle") */
|
|
7
|
+
reason: string;
|
|
8
|
+
/** Suggested retry delay in milliseconds */
|
|
9
|
+
retry_ms: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Async iterator for SSE events with automatic reconnection.
|
|
13
|
+
*
|
|
14
|
+
* This stream handles:
|
|
15
|
+
* - Graceful `disconnecting` events from the server
|
|
16
|
+
* - Unexpected connection drops with exponential backoff
|
|
17
|
+
* - Server retry hints
|
|
18
|
+
* - Automatic resume using `since_id`
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const stream = client.events.stream(sessionId);
|
|
23
|
+
* for await (const event of stream) {
|
|
24
|
+
* console.log(event.type, event.data);
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare class EventStream implements AsyncIterable<Event> {
|
|
29
|
+
private readonly baseUrl;
|
|
30
|
+
private readonly authHeader;
|
|
31
|
+
private readonly options;
|
|
32
|
+
private lastEventId?;
|
|
33
|
+
private abortController?;
|
|
34
|
+
private serverRetryMs?;
|
|
35
|
+
private currentBackoffMs;
|
|
36
|
+
private retryCount;
|
|
37
|
+
private shouldReconnect;
|
|
38
|
+
private gracefulDisconnect;
|
|
39
|
+
constructor(url: string, authHeader: string, options?: StreamOptions);
|
|
40
|
+
/**
|
|
41
|
+
* Get the last received event ID (for resuming).
|
|
42
|
+
*/
|
|
43
|
+
getLastEventId(): string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Get the current retry count.
|
|
46
|
+
*/
|
|
47
|
+
getRetryCount(): number;
|
|
48
|
+
/**
|
|
49
|
+
* Abort the stream and prevent further reconnection attempts.
|
|
50
|
+
*/
|
|
51
|
+
abort(): void;
|
|
52
|
+
private buildUrl;
|
|
53
|
+
private getRetryDelay;
|
|
54
|
+
private updateBackoff;
|
|
55
|
+
private resetBackoff;
|
|
56
|
+
private shouldRetry;
|
|
57
|
+
private sleep;
|
|
58
|
+
[Symbol.asyncIterator](): AsyncGenerator<Event>;
|
|
59
|
+
private connect;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=sse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAUnD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,WAAY,YAAW,aAAa,CAAC,KAAK,CAAC;IACtD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;IACxC,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,OAAO,CAAC,eAAe,CAAC,CAAkB;IAC1C,OAAO,CAAC,aAAa,CAAC,CAAS;IAC/B,OAAO,CAAC,gBAAgB,CAA8B;IACtD,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,eAAe,CAAiB;IACxC,OAAO,CAAC,kBAAkB,CAAkB;gBAEhC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB;IAOxE;;OAEG;IACH,cAAc,IAAI,MAAM,GAAG,SAAS;IAIpC;;OAEG;IACH,aAAa,IAAI,MAAM;IAIvB;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb,OAAO,CAAC,QAAQ;IAsBhB,OAAO,CAAC,aAAa;IAUrB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,WAAW;YAUL,KAAK;IAIZ,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,cAAc,CAAC,KAAK,CAAC;YA8DvC,OAAO;CAgHvB"}
|
package/dist/sse.js
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-Sent Events streaming with automatic reconnection.
|
|
3
|
+
*
|
|
4
|
+
* Implements robust SSE streaming with:
|
|
5
|
+
* - Automatic reconnection on disconnect
|
|
6
|
+
* - Server retry hints
|
|
7
|
+
* - Graceful handling of `disconnecting` events
|
|
8
|
+
* - Exponential backoff for unexpected disconnections
|
|
9
|
+
* - Resume from last event ID via `since_id`
|
|
10
|
+
*/
|
|
11
|
+
import { createParser } from "eventsource-parser";
|
|
12
|
+
import { ConnectionError } from "./errors.js";
|
|
13
|
+
/** Maximum retry delay for exponential backoff */
|
|
14
|
+
const MAX_RETRY_MS = 30_000;
|
|
15
|
+
/** Initial retry delay for exponential backoff */
|
|
16
|
+
const INITIAL_BACKOFF_MS = 1000;
|
|
17
|
+
/** Read timeout for detecting stalled connections (2 minutes) */
|
|
18
|
+
const READ_TIMEOUT_MS = 120_000;
|
|
19
|
+
/**
|
|
20
|
+
* Async iterator for SSE events with automatic reconnection.
|
|
21
|
+
*
|
|
22
|
+
* This stream handles:
|
|
23
|
+
* - Graceful `disconnecting` events from the server
|
|
24
|
+
* - Unexpected connection drops with exponential backoff
|
|
25
|
+
* - Server retry hints
|
|
26
|
+
* - Automatic resume using `since_id`
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const stream = client.events.stream(sessionId);
|
|
31
|
+
* for await (const event of stream) {
|
|
32
|
+
* console.log(event.type, event.data);
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export class EventStream {
|
|
37
|
+
baseUrl;
|
|
38
|
+
authHeader;
|
|
39
|
+
options;
|
|
40
|
+
lastEventId;
|
|
41
|
+
abortController;
|
|
42
|
+
serverRetryMs;
|
|
43
|
+
currentBackoffMs = INITIAL_BACKOFF_MS;
|
|
44
|
+
retryCount = 0;
|
|
45
|
+
shouldReconnect = true;
|
|
46
|
+
gracefulDisconnect = false;
|
|
47
|
+
constructor(url, authHeader, options = {}) {
|
|
48
|
+
this.baseUrl = url;
|
|
49
|
+
this.authHeader = authHeader;
|
|
50
|
+
this.options = options;
|
|
51
|
+
this.lastEventId = options.sinceId;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the last received event ID (for resuming).
|
|
55
|
+
*/
|
|
56
|
+
getLastEventId() {
|
|
57
|
+
return this.lastEventId;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get the current retry count.
|
|
61
|
+
*/
|
|
62
|
+
getRetryCount() {
|
|
63
|
+
return this.retryCount;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Abort the stream and prevent further reconnection attempts.
|
|
67
|
+
*/
|
|
68
|
+
abort() {
|
|
69
|
+
this.shouldReconnect = false;
|
|
70
|
+
this.abortController?.abort();
|
|
71
|
+
}
|
|
72
|
+
buildUrl() {
|
|
73
|
+
let url = this.baseUrl;
|
|
74
|
+
const params = [];
|
|
75
|
+
if (this.lastEventId) {
|
|
76
|
+
params.push(`since_id=${encodeURIComponent(this.lastEventId)}`);
|
|
77
|
+
}
|
|
78
|
+
if (this.options.exclude) {
|
|
79
|
+
for (const e of this.options.exclude) {
|
|
80
|
+
params.push(`exclude=${encodeURIComponent(e)}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (params.length > 0) {
|
|
84
|
+
const separator = url.includes("?") ? "&" : "?";
|
|
85
|
+
url += separator + params.join("&");
|
|
86
|
+
}
|
|
87
|
+
return url;
|
|
88
|
+
}
|
|
89
|
+
getRetryDelay() {
|
|
90
|
+
if (this.gracefulDisconnect) {
|
|
91
|
+
// Use server hint for graceful disconnect, or short default
|
|
92
|
+
return this.serverRetryMs ?? 100;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// Use exponential backoff for unexpected disconnects
|
|
96
|
+
return this.currentBackoffMs;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
updateBackoff() {
|
|
100
|
+
if (!this.gracefulDisconnect) {
|
|
101
|
+
this.currentBackoffMs = Math.min(this.currentBackoffMs * 2, MAX_RETRY_MS);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
resetBackoff() {
|
|
105
|
+
this.currentBackoffMs = INITIAL_BACKOFF_MS;
|
|
106
|
+
this.retryCount = 0;
|
|
107
|
+
}
|
|
108
|
+
shouldRetry() {
|
|
109
|
+
if (!this.shouldReconnect) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
if (this.options.maxRetries !== undefined) {
|
|
113
|
+
return this.retryCount < this.options.maxRetries;
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
async sleep(ms) {
|
|
118
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
119
|
+
}
|
|
120
|
+
async *[Symbol.asyncIterator]() {
|
|
121
|
+
while (this.shouldReconnect) {
|
|
122
|
+
this.abortController = new AbortController();
|
|
123
|
+
try {
|
|
124
|
+
for await (const event of this.connect()) {
|
|
125
|
+
yield event;
|
|
126
|
+
}
|
|
127
|
+
// Stream ended normally - always retry to handle read timeout case
|
|
128
|
+
if (this.shouldRetry()) {
|
|
129
|
+
this.retryCount++;
|
|
130
|
+
const delay = this.getRetryDelay();
|
|
131
|
+
this.updateBackoff();
|
|
132
|
+
console.debug(`Stream ended, reconnecting in ${delay}ms (attempt ${this.retryCount})`);
|
|
133
|
+
await this.sleep(delay);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
if (error instanceof GracefulDisconnect) {
|
|
140
|
+
// Server-initiated graceful disconnect
|
|
141
|
+
this.serverRetryMs = error.retryMs;
|
|
142
|
+
this.gracefulDisconnect = true;
|
|
143
|
+
if (this.shouldRetry()) {
|
|
144
|
+
this.retryCount++;
|
|
145
|
+
const delay = this.getRetryDelay();
|
|
146
|
+
console.debug(`Graceful reconnect in ${delay}ms`);
|
|
147
|
+
await this.sleep(delay);
|
|
148
|
+
this.gracefulDisconnect = false;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
154
|
+
// Clean shutdown
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
// Unexpected error - use exponential backoff
|
|
158
|
+
this.gracefulDisconnect = false;
|
|
159
|
+
if (this.shouldRetry()) {
|
|
160
|
+
this.retryCount++;
|
|
161
|
+
const delay = this.getRetryDelay();
|
|
162
|
+
this.updateBackoff();
|
|
163
|
+
console.debug(`Reconnecting after error in ${delay}ms (attempt ${this.retryCount}): ${error}`);
|
|
164
|
+
await this.sleep(delay);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
async *connect() {
|
|
172
|
+
const url = this.buildUrl();
|
|
173
|
+
console.debug(`Connecting to SSE: ${url}`);
|
|
174
|
+
// Create abort controller with timeout for stalled connections
|
|
175
|
+
const timeoutId = setTimeout(() => {
|
|
176
|
+
this.abortController?.abort();
|
|
177
|
+
}, READ_TIMEOUT_MS);
|
|
178
|
+
try {
|
|
179
|
+
const response = await fetch(url, {
|
|
180
|
+
headers: {
|
|
181
|
+
Authorization: this.authHeader,
|
|
182
|
+
Accept: "text/event-stream",
|
|
183
|
+
"Cache-Control": "no-cache",
|
|
184
|
+
},
|
|
185
|
+
signal: this.abortController?.signal,
|
|
186
|
+
});
|
|
187
|
+
// Clear initial timeout, we'll reset it on each chunk
|
|
188
|
+
clearTimeout(timeoutId);
|
|
189
|
+
if (!response.ok) {
|
|
190
|
+
throw new ConnectionError(`Stream connection failed: ${response.status}`);
|
|
191
|
+
}
|
|
192
|
+
if (!response.body) {
|
|
193
|
+
throw new ConnectionError("No response body");
|
|
194
|
+
}
|
|
195
|
+
const reader = response.body.getReader();
|
|
196
|
+
const decoder = new TextDecoder();
|
|
197
|
+
const eventQueue = [];
|
|
198
|
+
let readTimeoutId;
|
|
199
|
+
const resetReadTimeout = () => {
|
|
200
|
+
clearTimeout(readTimeoutId);
|
|
201
|
+
readTimeoutId = setTimeout(() => {
|
|
202
|
+
console.debug("SSE read timeout, triggering reconnect");
|
|
203
|
+
reader.cancel();
|
|
204
|
+
}, READ_TIMEOUT_MS);
|
|
205
|
+
};
|
|
206
|
+
const parser = createParser({
|
|
207
|
+
onEvent: (event) => {
|
|
208
|
+
// Handle special lifecycle events
|
|
209
|
+
if (event.event === "connected") {
|
|
210
|
+
console.debug("SSE connected event received");
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (event.event === "disconnecting") {
|
|
214
|
+
// Parse disconnecting data for retry hint
|
|
215
|
+
try {
|
|
216
|
+
const data = JSON.parse(event.data);
|
|
217
|
+
console.debug(`SSE disconnecting: reason=${data.reason}, retry_ms=${data.retry_ms}`);
|
|
218
|
+
throw new GracefulDisconnect(data.retry_ms);
|
|
219
|
+
}
|
|
220
|
+
catch (e) {
|
|
221
|
+
if (e instanceof GracefulDisconnect) {
|
|
222
|
+
throw e;
|
|
223
|
+
}
|
|
224
|
+
console.debug("SSE disconnecting event received (no data)");
|
|
225
|
+
throw new GracefulDisconnect(100);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (event.event === "done") {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
// Parse and yield regular events
|
|
232
|
+
try {
|
|
233
|
+
const data = JSON.parse(event.data);
|
|
234
|
+
this.lastEventId = data.id;
|
|
235
|
+
this.resetBackoff();
|
|
236
|
+
eventQueue.push(data);
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
// Skip malformed events
|
|
240
|
+
console.trace(`Skipping malformed event: ${event.event}`);
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
resetReadTimeout();
|
|
245
|
+
try {
|
|
246
|
+
while (true) {
|
|
247
|
+
const { done, value } = await reader.read();
|
|
248
|
+
if (done)
|
|
249
|
+
break;
|
|
250
|
+
// Reset timeout on each chunk received
|
|
251
|
+
resetReadTimeout();
|
|
252
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
253
|
+
parser.feed(chunk);
|
|
254
|
+
// Yield any events that were parsed
|
|
255
|
+
while (eventQueue.length > 0) {
|
|
256
|
+
yield eventQueue.shift();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
finally {
|
|
261
|
+
clearTimeout(readTimeoutId);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
finally {
|
|
265
|
+
clearTimeout(timeoutId);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Internal error to signal graceful disconnect.
|
|
271
|
+
*/
|
|
272
|
+
class GracefulDisconnect extends Error {
|
|
273
|
+
retryMs;
|
|
274
|
+
constructor(retryMs) {
|
|
275
|
+
super(`Graceful disconnect, retry in ${retryMs}ms`);
|
|
276
|
+
this.name = "GracefulDisconnect";
|
|
277
|
+
this.retryMs = retryMs;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
//# sourceMappingURL=sse.js.map
|
package/dist/sse.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,YAAY,EAA2B,MAAM,oBAAoB,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,kDAAkD;AAClD,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,kDAAkD;AAClD,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,iEAAiE;AACjE,MAAM,eAAe,GAAG,OAAO,CAAC;AAYhC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,WAAW;IACL,OAAO,CAAS;IAChB,UAAU,CAAS;IACnB,OAAO,CAAgB;IAChC,WAAW,CAAU;IACrB,eAAe,CAAmB;IAClC,aAAa,CAAU;IACvB,gBAAgB,GAAW,kBAAkB,CAAC;IAC9C,UAAU,GAAW,CAAC,CAAC;IACvB,eAAe,GAAY,IAAI,CAAC;IAChC,kBAAkB,GAAY,KAAK,CAAC;IAE5C,YAAY,GAAW,EAAE,UAAkB,EAAE,UAAyB,EAAE;QACtE,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;QACnB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IACrC,CAAC;I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ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@everruns/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript SDK for Everruns API",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"test:watch": "vitest",
|
|
21
|
+
"lint": "oxlint src",
|
|
22
|
+
"format": "prettier --write src",
|
|
23
|
+
"prepublishOnly": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"everruns",
|
|
27
|
+
"sdk",
|
|
28
|
+
"api",
|
|
29
|
+
"ai",
|
|
30
|
+
"agents"
|
|
31
|
+
],
|
|
32
|
+
"author": "Everruns Contributors",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/everruns/sdk.git",
|
|
37
|
+
"directory": "typescript"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/everruns/sdk#readme",
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"eventsource-parser": "^3.0.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^22.0.0",
|
|
48
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
49
|
+
"oxlint": "^1.41.0",
|
|
50
|
+
"prettier": "^3.4.0",
|
|
51
|
+
"typescript": "^5.7.0",
|
|
52
|
+
"vitest": "^3.0.0"
|
|
53
|
+
}
|
|
54
|
+
}
|