@agent-os-sdk/client 0.9.26 → 0.9.27

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 (209) hide show
  1. package/dist/client/AgentOsClient.d.ts +141 -0
  2. package/dist/client/AgentOsClient.d.ts.map +1 -0
  3. package/{src/client/AgentOsClient.ts → dist/client/AgentOsClient.js} +61 -105
  4. package/dist/client/HttpRequestBuilder.d.ts +50 -0
  5. package/dist/client/HttpRequestBuilder.d.ts.map +1 -0
  6. package/{src/client/HttpRequestBuilder.ts → dist/client/HttpRequestBuilder.js} +9 -41
  7. package/{src/client/OperationContext.ts → dist/client/OperationContext.d.ts} +6 -9
  8. package/dist/client/OperationContext.d.ts.map +1 -0
  9. package/dist/client/OperationContext.js +13 -0
  10. package/dist/client/OperationContextProvider.d.ts +54 -0
  11. package/dist/client/OperationContextProvider.d.ts.map +1 -0
  12. package/{src/client/OperationContextProvider.ts → dist/client/OperationContextProvider.js} +17 -35
  13. package/{src/client/auth.ts → dist/client/auth.d.ts} +29 -65
  14. package/dist/client/auth.d.ts.map +1 -0
  15. package/dist/client/auth.js +38 -0
  16. package/dist/client/config.d.ts +49 -0
  17. package/dist/client/config.d.ts.map +1 -0
  18. package/{src/client/config.ts → dist/client/config.js} +5 -43
  19. package/dist/client/helpers.d.ts +63 -0
  20. package/dist/client/helpers.d.ts.map +1 -0
  21. package/{src/client/helpers.ts → dist/client/helpers.js} +9 -52
  22. package/dist/client/pagination.d.ts +105 -0
  23. package/dist/client/pagination.d.ts.map +1 -0
  24. package/{src/client/pagination.ts → dist/client/pagination.js} +15 -116
  25. package/dist/client/raw.d.ts +277 -0
  26. package/dist/client/raw.d.ts.map +1 -0
  27. package/dist/client/raw.js +337 -0
  28. package/dist/client/retry.d.ts +37 -0
  29. package/dist/client/retry.d.ts.map +1 -0
  30. package/{src/client/retry.ts → dist/client/retry.js} +13 -55
  31. package/dist/client/sanitize.d.ts +19 -0
  32. package/dist/client/sanitize.d.ts.map +1 -0
  33. package/{src/client/sanitize.ts → dist/client/sanitize.js} +4 -7
  34. package/dist/client/timeout.d.ts +26 -0
  35. package/dist/client/timeout.d.ts.map +1 -0
  36. package/{src/client/timeout.ts → dist/client/timeout.js} +10 -18
  37. package/dist/errors/factory.d.ts +22 -0
  38. package/dist/errors/factory.d.ts.map +1 -0
  39. package/{src/errors/factory.ts → dist/errors/factory.js} +18 -57
  40. package/dist/errors/index.d.ts +210 -0
  41. package/dist/errors/index.d.ts.map +1 -0
  42. package/{src/errors/index.ts → dist/errors/index.js} +74 -156
  43. package/{src/generated/client.ts → dist/generated/client.d.ts} +5 -17
  44. package/dist/generated/client.d.ts.map +1 -0
  45. package/dist/generated/client.js +15 -0
  46. package/{src/generated/index.ts → dist/generated/index.d.ts} +1 -1
  47. package/dist/generated/index.d.ts.map +1 -0
  48. package/dist/generated/index.js +1 -0
  49. package/{src/generated/openapi.ts → dist/generated/openapi.d.ts} +1 -1
  50. package/dist/generated/openapi.d.ts.map +1 -0
  51. package/dist/generated/openapi.js +5 -0
  52. package/dist/index.d.ts +69 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/{src/index.ts → dist/index.js} +13 -63
  55. package/dist/modules/a2a.d.ts +48 -0
  56. package/dist/modules/a2a.d.ts.map +1 -0
  57. package/dist/modules/a2a.js +37 -0
  58. package/dist/modules/agents.d.ts +346 -0
  59. package/dist/modules/agents.d.ts.map +1 -0
  60. package/dist/modules/agents.js +296 -0
  61. package/dist/modules/apiTokens.d.ts +62 -0
  62. package/dist/modules/apiTokens.d.ts.map +1 -0
  63. package/dist/modules/apiTokens.js +56 -0
  64. package/dist/modules/approvals.d.ts +75 -0
  65. package/dist/modules/approvals.d.ts.map +1 -0
  66. package/dist/modules/approvals.js +91 -0
  67. package/dist/modules/audit.d.ts +78 -0
  68. package/dist/modules/audit.d.ts.map +1 -0
  69. package/{src/modules/audit.ts → dist/modules/audit.js} +23 -74
  70. package/{src/modules/auth.ts → dist/modules/auth.d.ts} +6 -11
  71. package/dist/modules/auth.d.ts.map +1 -0
  72. package/dist/modules/auth.js +22 -0
  73. package/dist/modules/builder.d.ts +242 -0
  74. package/dist/modules/builder.d.ts.map +1 -0
  75. package/dist/modules/builder.js +248 -0
  76. package/dist/modules/catalog.d.ts +142 -0
  77. package/dist/modules/catalog.d.ts.map +1 -0
  78. package/dist/modules/catalog.js +136 -0
  79. package/dist/modules/chatwoot.d.ts +59 -0
  80. package/dist/modules/chatwoot.d.ts.map +1 -0
  81. package/dist/modules/chatwoot.js +200 -0
  82. package/dist/modules/checkpoints.d.ts +62 -0
  83. package/dist/modules/checkpoints.d.ts.map +1 -0
  84. package/dist/modules/checkpoints.js +48 -0
  85. package/dist/modules/contracts.d.ts +48 -0
  86. package/dist/modules/contracts.d.ts.map +1 -0
  87. package/dist/modules/contracts.js +25 -0
  88. package/dist/modules/credentials.d.ts +105 -0
  89. package/dist/modules/credentials.d.ts.map +1 -0
  90. package/dist/modules/credentials.js +135 -0
  91. package/dist/modules/crons.d.ts +73 -0
  92. package/dist/modules/crons.d.ts.map +1 -0
  93. package/dist/modules/crons.js +67 -0
  94. package/dist/modules/datasets.d.ts +80 -0
  95. package/dist/modules/datasets.d.ts.map +1 -0
  96. package/dist/modules/datasets.js +91 -0
  97. package/{src/modules/evaluation.ts → dist/modules/evaluation.d.ts} +23 -109
  98. package/dist/modules/evaluation.d.ts.map +1 -0
  99. package/dist/modules/evaluation.js +108 -0
  100. package/dist/modules/files.d.ts +89 -0
  101. package/dist/modules/files.d.ts.map +1 -0
  102. package/dist/modules/files.js +133 -0
  103. package/dist/modules/graphs.d.ts +120 -0
  104. package/dist/modules/graphs.d.ts.map +1 -0
  105. package/dist/modules/graphs.js +69 -0
  106. package/{src/modules/improvements.ts → dist/modules/improvements.d.ts} +8 -27
  107. package/dist/modules/improvements.d.ts.map +1 -0
  108. package/dist/modules/improvements.js +27 -0
  109. package/dist/modules/info.d.ts +76 -0
  110. package/dist/modules/info.d.ts.map +1 -0
  111. package/{src/modules/info.ts → dist/modules/info.js} +16 -66
  112. package/dist/modules/knowledge.d.ts +91 -0
  113. package/dist/modules/knowledge.d.ts.map +1 -0
  114. package/dist/modules/knowledge.js +80 -0
  115. package/{src/modules/me.ts → dist/modules/me.d.ts} +7 -23
  116. package/dist/modules/me.d.ts.map +1 -0
  117. package/dist/modules/me.js +28 -0
  118. package/dist/modules/members.d.ts +124 -0
  119. package/dist/modules/members.d.ts.map +1 -0
  120. package/dist/modules/members.js +142 -0
  121. package/dist/modules/memberships.d.ts +25 -0
  122. package/dist/modules/memberships.d.ts.map +1 -0
  123. package/dist/modules/memberships.js +20 -0
  124. package/{src/modules/metaAgent.ts → dist/modules/metaAgent.d.ts} +8 -44
  125. package/dist/modules/metaAgent.d.ts.map +1 -0
  126. package/dist/modules/metaAgent.js +32 -0
  127. package/dist/modules/metrics.d.ts +20 -0
  128. package/dist/modules/metrics.d.ts.map +1 -0
  129. package/{src/modules/metrics.ts → dist/modules/metrics.js} +7 -14
  130. package/dist/modules/observability.d.ts +19 -0
  131. package/dist/modules/observability.d.ts.map +1 -0
  132. package/dist/modules/observability.js +14 -0
  133. package/dist/modules/playground.d.ts +42 -0
  134. package/dist/modules/playground.d.ts.map +1 -0
  135. package/dist/modules/playground.js +48 -0
  136. package/dist/modules/presets.d.ts +32 -0
  137. package/dist/modules/presets.d.ts.map +1 -0
  138. package/dist/modules/presets.js +199 -0
  139. package/dist/modules/prompts.d.ts +87 -0
  140. package/dist/modules/prompts.d.ts.map +1 -0
  141. package/dist/modules/prompts.js +87 -0
  142. package/dist/modules/roles.d.ts +64 -0
  143. package/dist/modules/roles.d.ts.map +1 -0
  144. package/dist/modules/roles.js +79 -0
  145. package/dist/modules/runs.d.ts +451 -0
  146. package/dist/modules/runs.d.ts.map +1 -0
  147. package/{src/modules/runs.ts → dist/modules/runs.js} +96 -438
  148. package/dist/modules/store.d.ts +37 -0
  149. package/dist/modules/store.d.ts.map +1 -0
  150. package/dist/modules/store.js +48 -0
  151. package/{src/modules/templates.ts → dist/modules/templates.d.ts} +8 -32
  152. package/dist/modules/templates.d.ts.map +1 -0
  153. package/dist/modules/templates.js +26 -0
  154. package/dist/modules/tenants.d.ts +49 -0
  155. package/dist/modules/tenants.d.ts.map +1 -0
  156. package/dist/modules/tenants.js +56 -0
  157. package/dist/modules/threads.d.ts +205 -0
  158. package/dist/modules/threads.d.ts.map +1 -0
  159. package/dist/modules/threads.js +225 -0
  160. package/dist/modules/tools.d.ts +62 -0
  161. package/dist/modules/tools.d.ts.map +1 -0
  162. package/dist/modules/tools.js +45 -0
  163. package/dist/modules/traces.d.ts +89 -0
  164. package/dist/modules/traces.d.ts.map +1 -0
  165. package/dist/modules/traces.js +65 -0
  166. package/{src/modules/triggers.ts → dist/modules/triggers.d.ts} +24 -153
  167. package/dist/modules/triggers.d.ts.map +1 -0
  168. package/dist/modules/triggers.js +176 -0
  169. package/{src/modules/usage.ts → dist/modules/usage.d.ts} +14 -46
  170. package/dist/modules/usage.d.ts.map +1 -0
  171. package/dist/modules/usage.js +43 -0
  172. package/dist/modules/vectorStores.d.ts +100 -0
  173. package/dist/modules/vectorStores.d.ts.map +1 -0
  174. package/dist/modules/vectorStores.js +159 -0
  175. package/dist/modules/workspaces.d.ts +138 -0
  176. package/dist/modules/workspaces.d.ts.map +1 -0
  177. package/dist/modules/workspaces.js +121 -0
  178. package/dist/sse/client.d.ts +140 -0
  179. package/dist/sse/client.d.ts.map +1 -0
  180. package/{src/sse/client.ts → dist/sse/client.js} +24 -100
  181. package/package.json +8 -15
  182. package/src/client/raw.ts +0 -609
  183. package/src/generated/swagger.json +0 -17014
  184. package/src/modules/a2a.ts +0 -64
  185. package/src/modules/agents.ts +0 -604
  186. package/src/modules/apiTokens.ts +0 -101
  187. package/src/modules/approvals.ts +0 -151
  188. package/src/modules/catalog.ts +0 -241
  189. package/src/modules/chatwoot.ts +0 -242
  190. package/src/modules/checkpoints.ts +0 -87
  191. package/src/modules/contracts.ts +0 -80
  192. package/src/modules/credentials.ts +0 -216
  193. package/src/modules/crons.ts +0 -115
  194. package/src/modules/datasets.ts +0 -142
  195. package/src/modules/files.ts +0 -208
  196. package/src/modules/members.ts +0 -199
  197. package/src/modules/memberships.ts +0 -42
  198. package/src/modules/observability.ts +0 -28
  199. package/src/modules/playground.ts +0 -68
  200. package/src/modules/presets.ts +0 -246
  201. package/src/modules/prompts.ts +0 -147
  202. package/src/modules/roles.ts +0 -112
  203. package/src/modules/store.ts +0 -65
  204. package/src/modules/tenants.ts +0 -79
  205. package/src/modules/threads.ts +0 -343
  206. package/src/modules/tools.ts +0 -91
  207. package/src/modules/traces.ts +0 -133
  208. package/src/modules/vectorStores.ts +0 -257
  209. package/src/modules/workspaces.ts +0 -216
@@ -1,47 +1,19 @@
1
1
  /**
2
2
  * SDK Helper Types and Functions
3
- *
3
+ *
4
4
  * Provides utilities for working with API responses.
5
5
  */
6
-
7
- import type { APIResponse } from "./raw.js";
8
-
9
- // ============================================================================
10
- // Pagination
11
- // ============================================================================
12
-
13
- /**
14
- * Standard pagination parameters used across all list endpoints.
15
- * Extends Record to be compatible with query parameter types.
16
- */
17
- export interface PaginationParams extends Record<string, unknown> {
18
- /** Maximum number of items to return (default: 20) */
19
- limit?: number;
20
- /** Number of items to skip (default: 0) */
21
- offset?: number;
22
- }
23
-
24
- /**
25
- * Paginated list response wrapper.
26
- */
27
- export interface PaginatedResponse<T> {
28
- items: T[];
29
- total: number;
30
- }
31
-
32
6
  // ============================================================================
33
7
  // Error Handling
34
8
  // ============================================================================
35
-
36
9
  /**
37
10
  * SDK-specific error class with structured error data.
38
11
  */
39
12
  export class SDKError extends Error {
40
- readonly code: string;
41
- readonly status: number;
42
- readonly details?: unknown;
43
-
44
- constructor(response: APIResponse<unknown>) {
13
+ code;
14
+ status;
15
+ details;
16
+ constructor(response) {
45
17
  const message = response.error?.message || `HTTP ${response.response.status}`;
46
18
  super(message);
47
19
  this.name = "SDKError";
@@ -50,46 +22,31 @@ export class SDKError extends Error {
50
22
  this.details = response.error?.details;
51
23
  }
52
24
  }
53
-
54
25
  /**
55
26
  * Unwraps an APIResponse, returning the data directly or throwing on error.
56
27
  * Use this when you want the cleaner "throws on error" pattern.
57
- *
28
+ *
58
29
  * @example
59
30
  * ```ts
60
31
  * // Instead of:
61
32
  * const { data, error } = await client.agents.list();
62
33
  * if (error) throw new Error(error.message);
63
- *
34
+ *
64
35
  * // Use:
65
36
  * const agents = await unwrap(client.agents.list());
66
37
  * ```
67
38
  */
68
- export async function unwrap<T>(promise: Promise<APIResponse<T>>): Promise<T> {
39
+ export async function unwrap(promise) {
69
40
  const result = await promise;
70
41
  if (result.error || !result.data) {
71
42
  throw new SDKError(result);
72
43
  }
73
44
  return result.data;
74
45
  }
75
-
76
- /**
77
- * Type helper for unwrapped responses.
78
- */
79
- export type Unwrapped<T> = T extends APIResponse<infer U> ? U : never;
80
-
81
- // ============================================================================
82
- // Result Pattern (Alternative to exceptions)
83
- // ============================================================================
84
-
85
- export type Result<T, E = SDKError> =
86
- | { success: true; data: T }
87
- | { success: false; error: E };
88
-
89
46
  /**
90
47
  * Converts an APIResponse to a Result type for pattern matching.
91
48
  */
92
- export async function toResult<T>(promise: Promise<APIResponse<T>>): Promise<Result<T>> {
49
+ export async function toResult(promise) {
93
50
  const result = await promise;
94
51
  if (result.error || !result.data) {
95
52
  return { success: false, error: new SDKError(result) };
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Agent OS SDK - Pagination Utilities
3
+ *
4
+ * Auto-paginating iterators that support both offset and cursor pagination.
5
+ * Designed to work with any list endpoint.
6
+ */
7
+ import type { APIResponse } from "./raw.js";
8
+ /**
9
+ * Offset-based paginated response.
10
+ * Most common format for list endpoints.
11
+ */
12
+ export interface OffsetPaginatedResponse<T> {
13
+ items: T[];
14
+ total: number;
15
+ }
16
+ /**
17
+ * Cursor-based paginated response.
18
+ * Better for large datasets and real-time consistency.
19
+ */
20
+ export interface CursorPaginatedResponse<T> {
21
+ items: T[];
22
+ next_cursor?: string;
23
+ has_more: boolean;
24
+ }
25
+ /**
26
+ * Union type for both pagination styles.
27
+ */
28
+ export type PaginatedResponse<T> = OffsetPaginatedResponse<T> | CursorPaginatedResponse<T>;
29
+ /**
30
+ * Offset pagination parameters.
31
+ */
32
+ export interface OffsetParams {
33
+ limit?: number;
34
+ offset?: number;
35
+ }
36
+ /**
37
+ * Cursor pagination parameters.
38
+ */
39
+ export interface CursorParams {
40
+ limit?: number;
41
+ after?: string;
42
+ }
43
+ /**
44
+ * Combined pagination parameters.
45
+ */
46
+ export type PaginationParams = OffsetParams | CursorParams;
47
+ /**
48
+ * Options for pagination behavior.
49
+ */
50
+ export interface PaginateOptions {
51
+ /** Number of items per page (default: 100) */
52
+ pageSize?: number;
53
+ /** Maximum total items to fetch (default: unlimited) */
54
+ maxItems?: number;
55
+ /** AbortSignal for cancellation */
56
+ signal?: AbortSignal;
57
+ }
58
+ /**
59
+ * Creates an async iterator that automatically paginates through results.
60
+ * Supports both offset and cursor pagination transparently.
61
+ *
62
+ * @example
63
+ * // Basic usage
64
+ * for await (const run of paginate(
65
+ * (p) => client.runs.list(p),
66
+ * { status: "completed" }
67
+ * )) {
68
+ * console.log(run.id);
69
+ * }
70
+ *
71
+ * @example
72
+ * // With options
73
+ * for await (const agent of paginate(
74
+ * (p) => client.agents.list(p),
75
+ * { workspace_id: "ws_123" },
76
+ * { pageSize: 50, maxItems: 200 }
77
+ * )) {
78
+ * console.log(agent.name);
79
+ * }
80
+ */
81
+ export declare function paginate<T, P extends PaginationParams>(fetchPage: (params: P) => Promise<APIResponse<PaginatedResponse<T>>>, baseParams: Omit<P, "limit" | "offset" | "after">, options?: PaginateOptions): AsyncGenerator<T, void, unknown>;
82
+ /**
83
+ * Collects all items from a paginated endpoint into an array.
84
+ * Useful when you need all items at once.
85
+ *
86
+ * @example
87
+ * const allRuns = await collectAll(
88
+ * (p) => client.runs.list(p),
89
+ * { status: "completed" },
90
+ * { maxItems: 1000 }
91
+ * );
92
+ */
93
+ export declare function collectAll<T, P extends PaginationParams>(fetchPage: (params: P) => Promise<APIResponse<PaginatedResponse<T>>>, baseParams: Omit<P, "limit" | "offset" | "after">, options?: PaginateOptions): Promise<T[]>;
94
+ /**
95
+ * Gets the first item from a paginated endpoint.
96
+ * More efficient than collecting all items when you only need one.
97
+ *
98
+ * @example
99
+ * const latestRun = await getFirst(
100
+ * (p) => client.runs.list({ ...p, order: "desc" }),
101
+ * { agent_id: "agent_123" }
102
+ * );
103
+ */
104
+ export declare function getFirst<T, P extends PaginationParams>(fetchPage: (params: P) => Promise<APIResponse<PaginatedResponse<T>>>, baseParams: Omit<P, "limit" | "offset" | "after">): Promise<T | undefined>;
105
+ //# sourceMappingURL=pagination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../../src/client/pagination.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAM5C;;;GAGG;AACH,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACtC,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACtC,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IACzB,uBAAuB,CAAC,CAAC,CAAC,GAC1B,uBAAuB,CAAC,CAAC,CAAC,CAAC;AAMjC;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG,YAAY,CAAC;AAiB3D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,mCAAmC;IACnC,MAAM,CAAC,EAAE,WAAW,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAuB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,gBAAgB,EACzD,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,EACpE,UAAU,EAAE,IAAI,CAAC,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC,EACjD,OAAO,CAAC,EAAE,eAAe,GAC1B,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAgDlC;AAMD;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,gBAAgB,EAC1D,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,EACpE,UAAU,EAAE,IAAI,CAAC,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC,EACjD,OAAO,CAAC,EAAE,eAAe,GAC1B,OAAO,CAAC,CAAC,EAAE,CAAC,CAQd;AAED;;;;;;;;;GASG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,gBAAgB,EACxD,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,EACpE,UAAU,EAAE,IAAI,CAAC,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC,GAClD,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAKxB"}
@@ -1,100 +1,22 @@
1
1
  /**
2
2
  * Agent OS SDK - Pagination Utilities
3
- *
3
+ *
4
4
  * Auto-paginating iterators that support both offset and cursor pagination.
5
5
  * Designed to work with any list endpoint.
6
6
  */
7
-
8
- import type { APIResponse } from "./raw.js";
9
-
10
- // ============================================================================
11
- // Response Types
12
- // ============================================================================
13
-
14
- /**
15
- * Offset-based paginated response.
16
- * Most common format for list endpoints.
17
- */
18
- export interface OffsetPaginatedResponse<T> {
19
- items: T[];
20
- total: number;
21
- }
22
-
23
- /**
24
- * Cursor-based paginated response.
25
- * Better for large datasets and real-time consistency.
26
- */
27
- export interface CursorPaginatedResponse<T> {
28
- items: T[];
29
- next_cursor?: string;
30
- has_more: boolean;
31
- }
32
-
33
- /**
34
- * Union type for both pagination styles.
35
- */
36
- export type PaginatedResponse<T> =
37
- | OffsetPaginatedResponse<T>
38
- | CursorPaginatedResponse<T>;
39
-
40
- // ============================================================================
41
- // Parameter Types
42
- // ============================================================================
43
-
44
- /**
45
- * Offset pagination parameters.
46
- */
47
- export interface OffsetParams {
48
- limit?: number;
49
- offset?: number;
50
- }
51
-
52
- /**
53
- * Cursor pagination parameters.
54
- */
55
- export interface CursorParams {
56
- limit?: number;
57
- after?: string;
58
- }
59
-
60
- /**
61
- * Combined pagination parameters.
62
- */
63
- export type PaginationParams = OffsetParams | CursorParams;
64
-
65
7
  // ============================================================================
66
8
  // Type Guards
67
9
  // ============================================================================
68
-
69
10
  /**
70
11
  * Checks if response uses cursor pagination.
71
12
  */
72
- function isCursorResponse<T>(response: PaginatedResponse<T>): response is CursorPaginatedResponse<T> {
13
+ function isCursorResponse(response) {
73
14
  return "has_more" in response;
74
15
  }
75
-
76
- // ============================================================================
77
- // Paginate Function
78
- // ============================================================================
79
-
80
- /**
81
- * Options for pagination behavior.
82
- */
83
- export interface PaginateOptions {
84
- /** Number of items per page (default: 100) */
85
- pageSize?: number;
86
-
87
- /** Maximum total items to fetch (default: unlimited) */
88
- maxItems?: number;
89
-
90
- /** AbortSignal for cancellation */
91
- signal?: AbortSignal;
92
- }
93
-
94
16
  /**
95
17
  * Creates an async iterator that automatically paginates through results.
96
18
  * Supports both offset and cursor pagination transparently.
97
- *
19
+ *
98
20
  * @example
99
21
  * // Basic usage
100
22
  * for await (const run of paginate(
@@ -103,7 +25,7 @@ export interface PaginateOptions {
103
25
  * )) {
104
26
  * console.log(run.id);
105
27
  * }
106
- *
28
+ *
107
29
  * @example
108
30
  * // With options
109
31
  * for await (const agent of paginate(
@@ -114,41 +36,30 @@ export interface PaginateOptions {
114
36
  * console.log(agent.name);
115
37
  * }
116
38
  */
117
- export async function* paginate<T, P extends PaginationParams>(
118
- fetchPage: (params: P) => Promise<APIResponse<PaginatedResponse<T>>>,
119
- baseParams: Omit<P, "limit" | "offset" | "after">,
120
- options?: PaginateOptions
121
- ): AsyncGenerator<T, void, unknown> {
39
+ export async function* paginate(fetchPage, baseParams, options) {
122
40
  const pageSize = options?.pageSize ?? 100;
123
41
  const maxItems = options?.maxItems ?? Infinity;
124
42
  const signal = options?.signal;
125
-
126
43
  let offset = 0;
127
- let cursor: string | undefined;
44
+ let cursor;
128
45
  let hasMore = true;
129
46
  let yielded = 0;
130
-
131
47
  while (hasMore && yielded < maxItems) {
132
48
  // Check for cancellation
133
49
  if (signal?.aborted) {
134
50
  return;
135
51
  }
136
-
137
52
  // Build params based on pagination style
138
53
  const params = {
139
54
  ...baseParams,
140
55
  limit: Math.min(pageSize, maxItems - yielded),
141
56
  ...(cursor !== undefined ? { after: cursor } : { offset }),
142
- } as P;
143
-
57
+ };
144
58
  const response = await fetchPage(params);
145
-
146
59
  if (response.error) {
147
60
  throw response.error;
148
61
  }
149
-
150
- const data = response.data!;
151
-
62
+ const data = response.data;
152
63
  for (const item of data.items) {
153
64
  if (yielded >= maxItems) {
154
65
  return;
@@ -156,26 +67,24 @@ export async function* paginate<T, P extends PaginationParams>(
156
67
  yield item;
157
68
  yielded++;
158
69
  }
159
-
160
70
  // Update pagination state based on response type
161
71
  if (isCursorResponse(data)) {
162
72
  cursor = data.next_cursor;
163
73
  hasMore = data.has_more && data.items.length > 0;
164
- } else {
74
+ }
75
+ else {
165
76
  offset += data.items.length;
166
77
  hasMore = offset < data.total && data.items.length > 0;
167
78
  }
168
79
  }
169
80
  }
170
-
171
81
  // ============================================================================
172
82
  // Collect Utility
173
83
  // ============================================================================
174
-
175
84
  /**
176
85
  * Collects all items from a paginated endpoint into an array.
177
86
  * Useful when you need all items at once.
178
- *
87
+ *
179
88
  * @example
180
89
  * const allRuns = await collectAll(
181
90
  * (p) => client.runs.list(p),
@@ -183,34 +92,24 @@ export async function* paginate<T, P extends PaginationParams>(
183
92
  * { maxItems: 1000 }
184
93
  * );
185
94
  */
186
- export async function collectAll<T, P extends PaginationParams>(
187
- fetchPage: (params: P) => Promise<APIResponse<PaginatedResponse<T>>>,
188
- baseParams: Omit<P, "limit" | "offset" | "after">,
189
- options?: PaginateOptions
190
- ): Promise<T[]> {
191
- const items: T[] = [];
192
-
95
+ export async function collectAll(fetchPage, baseParams, options) {
96
+ const items = [];
193
97
  for await (const item of paginate(fetchPage, baseParams, options)) {
194
98
  items.push(item);
195
99
  }
196
-
197
100
  return items;
198
101
  }
199
-
200
102
  /**
201
103
  * Gets the first item from a paginated endpoint.
202
104
  * More efficient than collecting all items when you only need one.
203
- *
105
+ *
204
106
  * @example
205
107
  * const latestRun = await getFirst(
206
108
  * (p) => client.runs.list({ ...p, order: "desc" }),
207
109
  * { agent_id: "agent_123" }
208
110
  * );
209
111
  */
210
- export async function getFirst<T, P extends PaginationParams>(
211
- fetchPage: (params: P) => Promise<APIResponse<PaginatedResponse<T>>>,
212
- baseParams: Omit<P, "limit" | "offset" | "after">
213
- ): Promise<T | undefined> {
112
+ export async function getFirst(fetchPage, baseParams) {
214
113
  for await (const item of paginate(fetchPage, baseParams, { pageSize: 1, maxItems: 1 })) {
215
114
  return item;
216
115
  }