@agent-os-sdk/client 0.3.0 → 0.3.2

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.
Files changed (41) hide show
  1. package/dist/client/AgentOsClient.d.ts +2 -0
  2. package/dist/client/AgentOsClient.d.ts.map +1 -1
  3. package/dist/client/AgentOsClient.js +6 -3
  4. package/dist/client/raw.d.ts +25 -0
  5. package/dist/client/raw.d.ts.map +1 -1
  6. package/dist/client/raw.js +61 -0
  7. package/dist/generated/openapi.d.ts +156 -26
  8. package/dist/generated/openapi.d.ts.map +1 -1
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +1 -0
  12. package/dist/modules/builder.d.ts +19 -4
  13. package/dist/modules/builder.d.ts.map +1 -1
  14. package/dist/modules/builder.js +21 -30
  15. package/dist/modules/catalog.d.ts +104 -0
  16. package/dist/modules/catalog.d.ts.map +1 -0
  17. package/dist/modules/catalog.js +92 -0
  18. package/dist/modules/graphs.d.ts +7 -0
  19. package/dist/modules/graphs.d.ts.map +1 -1
  20. package/dist/modules/graphs.js +1 -0
  21. package/dist/modules/metrics.d.ts +7 -3
  22. package/dist/modules/metrics.d.ts.map +1 -1
  23. package/dist/modules/metrics.js +10 -7
  24. package/dist/modules/runs.d.ts +1 -3
  25. package/dist/modules/runs.d.ts.map +1 -1
  26. package/dist/modules/runs.js +12 -28
  27. package/dist/sse/client.d.ts +26 -1
  28. package/dist/sse/client.d.ts.map +1 -1
  29. package/dist/sse/client.js +36 -11
  30. package/package.json +51 -50
  31. package/src/client/AgentOsClient.ts +6 -3
  32. package/src/client/raw.ts +74 -0
  33. package/src/generated/openapi.ts +156 -26
  34. package/src/generated/swagger.json +144 -82
  35. package/src/index.ts +1 -0
  36. package/src/modules/builder.ts +35 -32
  37. package/src/modules/catalog.ts +155 -0
  38. package/src/modules/graphs.ts +7 -0
  39. package/src/modules/metrics.ts +10 -3
  40. package/src/modules/runs.ts +12 -28
  41. package/src/sse/client.ts +43 -14
@@ -1,20 +1,27 @@
1
1
  /**
2
2
  * Metrics Module - Fully Typed
3
+ *
4
+ * ALL HTTP goes through rawClient - no direct fetch calls.
3
5
  */
4
6
 
7
+ import type { RawClient } from "../client/raw.js";
8
+
5
9
  export interface MetricsResponse {
6
10
  raw: string;
7
11
  }
8
12
 
9
13
  export class MetricsModule {
10
- constructor(private baseUrl: string, private headers: () => Record<string, string>) { }
14
+ constructor(private client: RawClient) { }
11
15
 
12
16
  /**
13
17
  * Get Prometheus metrics.
18
+ *
19
+ * Uses rawClient - headers resolved asynchronously.
14
20
  */
15
21
  async get(): Promise<MetricsResponse> {
16
- const response = await fetch(`${this.baseUrl}/metrics`, {
17
- headers: this.headers(),
22
+ // Use streamGet for raw text response (metrics endpoint returns text/plain)
23
+ const response = await this.client.streamGet("/metrics", {
24
+ headers: { Accept: "text/plain" }
18
25
  });
19
26
 
20
27
  if (!response.ok) {
@@ -9,7 +9,7 @@
9
9
 
10
10
  import type { RawClient, APIResponse, components } from "../client/raw.js";
11
11
  import type { PaginationParams, PaginatedResponse } from "../client/helpers.js";
12
- import { streamSSE, type SSEEvent, type RunStreamEvent, type SSEOptions } from "../sse/client.js";
12
+ import { parseSSE, type SSEEvent, type RunStreamEvent, type SSEOptions } from "../sse/client.js";
13
13
 
14
14
  // Type aliases from OpenAPI
15
15
  type WaitRunResponse = components["schemas"]["WaitRunResponse"];
@@ -91,11 +91,7 @@ export interface RunEventDto {
91
91
  }
92
92
 
93
93
  export class RunsModule {
94
- constructor(
95
- private client: RawClient,
96
- private baseUrl: string,
97
- private headers: () => Record<string, string>
98
- ) { }
94
+ constructor(private client: RawClient) { }
99
95
 
100
96
  // ======================== CRUD ========================
101
97
 
@@ -117,7 +113,6 @@ export class RunsModule {
117
113
  }): Promise<APIResponse<CreateRunResponse>> {
118
114
  return this.client.POST<CreateRunResponse>("/v1/api/runs", {
119
115
  body,
120
- headers: this.headers(),
121
116
  });
122
117
  }
123
118
 
@@ -127,7 +122,6 @@ export class RunsModule {
127
122
  async get(runId: string): Promise<APIResponse<Run>> {
128
123
  return this.client.GET<Run>("/v1/api/runs/{runId}", {
129
124
  params: { path: { runId } },
130
- headers: this.headers(),
131
125
  });
132
126
  }
133
127
 
@@ -141,7 +135,6 @@ export class RunsModule {
141
135
  }): Promise<APIResponse<RunListResponse>> {
142
136
  return this.client.GET<RunListResponse>("/v1/api/runs", {
143
137
  params: { query: params },
144
- headers: this.headers(),
145
138
  });
146
139
  }
147
140
 
@@ -158,7 +151,6 @@ export class RunsModule {
158
151
  }): Promise<APIResponse<WaitRunResponse>> {
159
152
  return this.client.POST<WaitRunResponse>("/v1/api/runs/wait", {
160
153
  body,
161
- headers: this.headers(),
162
154
  });
163
155
  }
164
156
 
@@ -171,7 +163,6 @@ export class RunsModule {
171
163
  }): Promise<APIResponse<BatchRunResponse>> {
172
164
  return this.client.POST<BatchRunResponse>("/v1/api/runs/batch", {
173
165
  body,
174
- headers: this.headers(),
175
166
  });
176
167
  }
177
168
 
@@ -182,7 +173,6 @@ export class RunsModule {
182
173
  return this.client.POST<CancelRunResponse>("/v1/api/runs/{runId}/cancel", {
183
174
  params: { path: { runId } },
184
175
  body: { reason },
185
- headers: this.headers(),
186
176
  });
187
177
  }
188
178
 
@@ -212,7 +202,6 @@ export class RunsModule {
212
202
  return this.client.POST<Run>("/v1/api/runs/{runId}/resume", {
213
203
  params: { path: { runId } },
214
204
  body,
215
- headers: this.headers(),
216
205
  });
217
206
  }
218
207
 
@@ -222,7 +211,6 @@ export class RunsModule {
222
211
  async rerun(runId: string): Promise<APIResponse<CreateRunResponse>> {
223
212
  return this.client.POST<CreateRunResponse>("/v1/api/runs/{runId}/rerun", {
224
213
  params: { path: { runId } },
225
- headers: this.headers(),
226
214
  });
227
215
  }
228
216
 
@@ -259,7 +247,6 @@ export class RunsModule {
259
247
  mode: options?.mode,
260
248
  reason: options?.reason
261
249
  },
262
- headers: this.headers(),
263
250
  });
264
251
  }
265
252
 
@@ -275,7 +262,6 @@ export class RunsModule {
275
262
  async getEvents(runId: string, params?: PaginationParams): Promise<APIResponse<RunEventsResponse>> {
276
263
  return this.client.GET<RunEventsResponse>("/v1/api/runs/{runId}/events", {
277
264
  params: { path: { runId }, query: params },
278
- headers: this.headers(),
279
265
  });
280
266
  }
281
267
 
@@ -315,7 +301,6 @@ export class RunsModule {
315
301
  limit: params?.limit ?? 100
316
302
  }
317
303
  },
318
- headers: this.headers(),
319
304
  });
320
305
  }
321
306
 
@@ -327,7 +312,6 @@ export class RunsModule {
327
312
  async getCheckpoints(runId: string): Promise<APIResponse<CheckpointListResponse>> {
328
313
  return this.client.GET<CheckpointListResponse>("/v1/api/runs/{runId}/checkpoints", {
329
314
  params: { path: { runId } },
330
- headers: this.headers(),
331
315
  });
332
316
  }
333
317
 
@@ -345,12 +329,12 @@ export class RunsModule {
345
329
  * }
346
330
  * ```
347
331
  */
348
- stream(runId: string, options?: SSEOptions): AsyncGenerator<SSEEvent<RunStreamEvent>> {
349
- const url = `${this.baseUrl}/v1/api/runs/${runId}/stream`;
350
- return streamSSE<RunStreamEvent>(url, {
351
- ...options,
352
- headers: { ...this.headers(), ...options?.headers },
332
+ async *stream(runId: string, options?: SSEOptions): AsyncGenerator<SSEEvent<RunStreamEvent>> {
333
+ const response = await this.client.streamGet("/v1/api/runs/{runId}/stream", {
334
+ params: { path: { runId } },
335
+ headers: options?.headers,
353
336
  });
337
+ yield* parseSSE<RunStreamEvent>(response, { onOpen: options?.onOpen });
354
338
  }
355
339
 
356
340
  /**
@@ -385,11 +369,11 @@ export class RunsModule {
385
369
  /**
386
370
  * Join an existing run's stream (resume watching).
387
371
  */
388
- join(runId: string, options?: SSEOptions): AsyncGenerator<SSEEvent<RunStreamEvent>> {
389
- const url = `${this.baseUrl}/v1/api/runs/${runId}/join`;
390
- return streamSSE<RunStreamEvent>(url, {
391
- ...options,
392
- headers: { ...this.headers(), ...options?.headers },
372
+ async *join(runId: string, options?: SSEOptions): AsyncGenerator<SSEEvent<RunStreamEvent>> {
373
+ const response = await this.client.streamGet("/v1/api/runs/{runId}/join", {
374
+ params: { path: { runId } },
375
+ headers: options?.headers,
393
376
  });
377
+ yield* parseSSE<RunStreamEvent>(response, { onOpen: options?.onOpen });
394
378
  }
395
379
  }
package/src/sse/client.ts CHANGED
@@ -2,6 +2,9 @@
2
2
  * Agent OS SDK - SSE Client
3
3
  *
4
4
  * Typed Server-Sent Events client for streaming endpoints.
5
+ *
6
+ * This module provides utilities for parsing SSE responses.
7
+ * The actual HTTP request should be made via rawClient.streamGet/streamPost.
5
8
  */
6
9
 
7
10
  export type SSEEvent<T = unknown> = {
@@ -19,21 +22,23 @@ export type SSEOptions = {
19
22
  };
20
23
 
21
24
  /**
22
- * Creates a typed SSE stream from a URL.
25
+ * Parse SSE events from a Response object.
26
+ * Use this with rawClient.streamGet() or rawClient.streamPost().
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const response = await client.streamGet("/v1/api/runs/{runId}/stream", {
31
+ * params: { path: { runId } }
32
+ * });
33
+ * for await (const event of parseSSE<RunStreamEvent>(response)) {
34
+ * console.log(event);
35
+ * }
36
+ * ```
23
37
  */
24
- export async function* streamSSE<T>(
25
- url: string,
26
- options: SSEOptions = {}
38
+ export async function* parseSSE<T>(
39
+ response: Response,
40
+ options?: { onOpen?: () => void }
27
41
  ): AsyncGenerator<SSEEvent<T>> {
28
- const response = await fetch(url, {
29
- method: "GET",
30
- headers: {
31
- Accept: "text/event-stream",
32
- ...options.headers,
33
- },
34
- signal: options.signal,
35
- });
36
-
37
42
  if (!response.ok) {
38
43
  throw new Error(`SSE connection failed: ${response.status}`);
39
44
  }
@@ -42,7 +47,7 @@ export async function* streamSSE<T>(
42
47
  throw new Error("No response body");
43
48
  }
44
49
 
45
- options.onOpen?.();
50
+ options?.onOpen?.();
46
51
 
47
52
  const reader = response.body.getReader();
48
53
  const decoder = new TextDecoder();
@@ -84,6 +89,30 @@ export async function* streamSSE<T>(
84
89
  }
85
90
  }
86
91
 
92
+ /**
93
+ * Legacy streamSSE function - DEPRECATED.
94
+ * Use rawClient.streamGet() + parseSSE() instead.
95
+ *
96
+ * Kept for backward compatibility during migration.
97
+ *
98
+ * @deprecated Use rawClient.streamGet() + parseSSE() instead
99
+ */
100
+ export async function* streamSSE<T>(
101
+ url: string,
102
+ options: SSEOptions = {}
103
+ ): AsyncGenerator<SSEEvent<T>> {
104
+ const response = await fetch(url, {
105
+ method: "GET",
106
+ headers: {
107
+ Accept: "text/event-stream",
108
+ ...options.headers,
109
+ },
110
+ signal: options.signal,
111
+ });
112
+
113
+ yield* parseSSE<T>(response, { onOpen: options.onOpen });
114
+ }
115
+
87
116
  /**
88
117
  * SSE Event types for Run streaming
89
118
  */