@agent-os-sdk/client 0.3.15 → 0.4.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.
Files changed (59) hide show
  1. package/dist/client/config.d.ts +49 -0
  2. package/dist/client/config.d.ts.map +1 -0
  3. package/dist/client/config.js +62 -0
  4. package/dist/client/pagination.d.ts +105 -0
  5. package/dist/client/pagination.d.ts.map +1 -0
  6. package/dist/client/pagination.js +117 -0
  7. package/dist/client/raw.d.ts +65 -0
  8. package/dist/client/raw.d.ts.map +1 -1
  9. package/dist/client/raw.js +78 -17
  10. package/dist/client/retry.d.ts +37 -0
  11. package/dist/client/retry.d.ts.map +1 -0
  12. package/dist/client/retry.js +108 -0
  13. package/dist/client/timeout.d.ts +26 -0
  14. package/dist/client/timeout.d.ts.map +1 -0
  15. package/dist/client/timeout.js +51 -0
  16. package/dist/errors/factory.d.ts +20 -0
  17. package/dist/errors/factory.d.ts.map +1 -0
  18. package/dist/errors/factory.js +97 -0
  19. package/dist/errors/index.d.ts +210 -0
  20. package/dist/errors/index.d.ts.map +1 -0
  21. package/dist/errors/index.js +283 -0
  22. package/dist/index.d.ts +11 -3
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +26 -0
  25. package/dist/modules/audit.d.ts +27 -4
  26. package/dist/modules/audit.d.ts.map +1 -1
  27. package/dist/modules/audit.js +58 -2
  28. package/dist/modules/checkpoints.d.ts +1 -1
  29. package/dist/modules/checkpoints.d.ts.map +1 -1
  30. package/dist/modules/info.d.ts +49 -0
  31. package/dist/modules/info.d.ts.map +1 -1
  32. package/dist/modules/info.js +66 -0
  33. package/dist/modules/runs.d.ts +103 -0
  34. package/dist/modules/runs.d.ts.map +1 -1
  35. package/dist/modules/runs.js +258 -0
  36. package/dist/modules/tenants.d.ts +4 -1
  37. package/dist/modules/tenants.d.ts.map +1 -1
  38. package/dist/modules/tenants.js +3 -0
  39. package/dist/modules/threads.d.ts +24 -0
  40. package/dist/modules/threads.d.ts.map +1 -1
  41. package/dist/modules/threads.js +48 -1
  42. package/dist/sse/client.d.ts.map +1 -1
  43. package/dist/sse/client.js +17 -5
  44. package/package.json +49 -50
  45. package/src/client/config.ts +100 -0
  46. package/src/client/pagination.ts +218 -0
  47. package/src/client/raw.ts +138 -17
  48. package/src/client/retry.ts +150 -0
  49. package/src/client/timeout.ts +59 -0
  50. package/src/errors/factory.ts +135 -0
  51. package/src/errors/index.ts +365 -0
  52. package/src/index.ts +72 -2
  53. package/src/modules/audit.ts +77 -6
  54. package/src/modules/checkpoints.ts +1 -1
  55. package/src/modules/info.ts +108 -0
  56. package/src/modules/runs.ts +333 -0
  57. package/src/modules/tenants.ts +5 -2
  58. package/src/modules/threads.ts +57 -1
  59. package/src/sse/client.ts +21 -5
package/src/index.ts CHANGED
@@ -64,6 +64,68 @@ export {
64
64
  type Unwrapped,
65
65
  } from "./client/helpers.js";
66
66
 
67
+ // ============================================================================
68
+ // Typed Errors (Enterprise)
69
+ // ============================================================================
70
+ export {
71
+ // Base class
72
+ AgentOsError,
73
+ type ErrorOptions,
74
+ // Error classes
75
+ UnauthorizedError,
76
+ ForbiddenError,
77
+ NotFoundError,
78
+ ConflictError,
79
+ ValidationError,
80
+ RateLimitError,
81
+ ServerError,
82
+ NetworkError,
83
+ TimeoutError,
84
+ // Field errors
85
+ type FieldError,
86
+ // Type guards
87
+ isAgentOsError,
88
+ isRetryableError,
89
+ isAuthError,
90
+ isClientError,
91
+ isServerError,
92
+ } from "./errors/index.js";
93
+
94
+ export { createErrorFromResponse } from "./errors/factory.js";
95
+
96
+ // ============================================================================
97
+ // Network Configuration
98
+ // ============================================================================
99
+ export {
100
+ type RetryConfig,
101
+ type NetworkConfig,
102
+ DEFAULT_NETWORK_CONFIG,
103
+ INTERACTIVE_NETWORK_CONFIG,
104
+ BACKGROUND_NETWORK_CONFIG,
105
+ mergeNetworkConfig,
106
+ } from "./client/config.js";
107
+
108
+ // ============================================================================
109
+ // Retry & Timeout Utilities
110
+ // ============================================================================
111
+ export { withRetry, type RetryContext, sleep } from "./client/retry.js";
112
+ export { withTimeout, createTimeoutController } from "./client/timeout.js";
113
+
114
+ // ============================================================================
115
+ // Pagination Utilities
116
+ // ============================================================================
117
+ export {
118
+ paginate,
119
+ collectAll,
120
+ getFirst,
121
+ type OffsetPaginatedResponse,
122
+ type CursorPaginatedResponse,
123
+ type OffsetParams,
124
+ type CursorParams,
125
+ type PaginateOptions,
126
+ } from "./client/pagination.js";
127
+
128
+
67
129
  // ============================================================================
68
130
  // Raw Client & Core Types
69
131
  // ============================================================================
@@ -74,6 +136,11 @@ export {
74
136
  type TypedClient,
75
137
  type ClientOptions,
76
138
  type APIResponse,
139
+ // SDK Hooks for observability (OTEL, Sentry, etc.)
140
+ type SDKHooks,
141
+ type HookRequestContext,
142
+ type HookResponseContext,
143
+ type HookErrorContext,
77
144
  } from "./client/raw.js";
78
145
 
79
146
  // Export OpenAPI types
@@ -85,7 +152,7 @@ export type { paths, components } from "./client/raw.js";
85
152
 
86
153
  // Core modules
87
154
  export { AgentsModule, type Agent, type AgentVersion, type AgentListResponse, type AgentGraphResponse } from "./modules/agents.js";
88
- export { RunsModule, type Run, type RunStatus, type RunEvent, type RunListResponse, type RunEventsResponse, type CreateRunResponse, type RunEventsPollResponse, type RunEventDto } from "./modules/runs.js";
155
+ export { RunsModule, type Run, type RunStatus, type RunEvent, type RunListResponse, type RunEventsResponse, type CreateRunResponse, type RunEventsPollResponse, type RunEventDto, type FollowOptions, type FollowEvent } from "./modules/runs.js";
89
156
  export { ThreadsModule, type Thread, type ThreadState, type ThreadMessage, type ThreadRun, type ThreadListResponse, type ThreadMessagesResponse } from "./modules/threads.js";
90
157
  export { ToolsModule, type Tool, type ToolListResponse } from "./modules/tools.js";
91
158
  export { KnowledgeModule, type KnowledgeDataset, type KnowledgeSearchResponse } from "./modules/knowledge.js";
@@ -112,7 +179,7 @@ export { UsageModule, type UsageResponse, type UsageQuota } from "./modules/usag
112
179
  export { McpModule, type McpServer } from "./modules/mcp.js";
113
180
  export { A2aModule, type JsonRpcRequest, type JsonRpcResponse, type A2aAgentCard } from "./modules/a2a.js";
114
181
  export { MeModule, type MeResponse } from "./modules/me.js";
115
- export { InfoModule, type ServerInfo } from "./modules/info.js";
182
+ export { InfoModule, type ServerInfo, type ServerCapabilities } from "./modules/info.js";
116
183
  export { MetricsModule, type MetricsResponse } from "./modules/metrics.js";
117
184
  export { GraphsModule, type GraphValidationResult, type GraphIntrospectionResult } from "./modules/graphs.js";
118
185
  export { CatalogModule, type CatalogVersions, type NodeCatalogResponse, type ToolCatalogResponse, type TriggerCatalogResponse, type NodeDefinition, type ToolDefinition, type TriggerTemplate } from "./modules/catalog.js";
@@ -120,6 +187,9 @@ export { CatalogModule, type CatalogVersions, type NodeCatalogResponse, type Too
120
187
  // Approvals is real (has backend implementation)
121
188
  export { ApprovalsModule, type Approval, type ApprovalStatus, type ApprovalDecision, type ApprovalListResponse, type ApprovalStatusResponse } from "./modules/approvals.js";
122
189
 
190
+ export { ApiTokensModule, type ApiToken, type ApiTokenSecret, type CreateTokenRequest, type RotateTokenResponse } from "./modules/apiTokens.js";
191
+ export { MembershipsModule, type MembershipResponse, type EnsureMembershipRequest } from "./modules/memberships.js";
192
+
123
193
  // ============================================================================
124
194
  // SSE Streaming
125
195
  // ============================================================================
@@ -37,11 +37,21 @@ export class AuditModule {
37
37
  workspace_id?: string;
38
38
  from?: string;
39
39
  to?: string;
40
- skip?: number;
41
- take?: number;
40
+ limit?: number;
41
+ offset?: number;
42
42
  }): Promise<APIResponse<AuditListResponse>> {
43
+ const queryParams: any = { ...params };
44
+ if (params?.limit !== undefined) {
45
+ queryParams.take = params.limit;
46
+ delete queryParams.limit;
47
+ }
48
+ if (params?.offset !== undefined) {
49
+ queryParams.skip = params.offset;
50
+ delete queryParams.offset;
51
+ }
52
+
43
53
  return this.client.GET<AuditListResponse>("/v1/api/audit", {
44
- params: { query: params },
54
+ params: { query: queryParams },
45
55
  headers: this.headers(),
46
56
  });
47
57
  }
@@ -63,12 +73,73 @@ export class AuditModule {
63
73
  query?: string;
64
74
  from?: string;
65
75
  to?: string;
66
- skip?: number;
67
- take?: number;
76
+ limit?: number;
77
+ offset?: number;
68
78
  }): Promise<APIResponse<AuditListResponse>> {
79
+ const queryParams: any = { ...params };
80
+ if (params?.limit !== undefined) {
81
+ queryParams.take = params.limit;
82
+ delete queryParams.limit;
83
+ }
84
+ if (params?.offset !== undefined) {
85
+ queryParams.skip = params.offset;
86
+ delete queryParams.offset;
87
+ }
88
+
69
89
  return this.client.GET<AuditListResponse>("/v1/api/audit/search", {
70
- params: { query: params },
90
+ params: { query: queryParams },
71
91
  headers: this.headers(),
72
92
  });
73
93
  }
94
+
95
+ /**
96
+ * Iterate through all audit logs with automatic pagination.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * // Get all audit logs for a specific action
101
+ * for await (const entry of client.audit.iterate({ action: "agent.created" })) {
102
+ * console.log(entry.actor, entry.action);
103
+ * }
104
+ * ```
105
+ */
106
+ async *iterate(
107
+ filters?: {
108
+ actor?: string;
109
+ action?: string;
110
+ resource?: string;
111
+ workspace_id?: string;
112
+ from?: string;
113
+ to?: string;
114
+ },
115
+ options?: { pageSize?: number; maxItems?: number; signal?: AbortSignal }
116
+ ): AsyncGenerator<AuditLogEntry, void, unknown> {
117
+ const pageSize = options?.pageSize ?? 100;
118
+ const maxItems = options?.maxItems ?? Infinity;
119
+ let offset = 0;
120
+ let yielded = 0;
121
+ let hasMore = true;
122
+
123
+ while (hasMore && yielded < maxItems) {
124
+ if (options?.signal?.aborted) return;
125
+
126
+ const response = await this.list({
127
+ ...filters,
128
+ limit: Math.min(pageSize, maxItems - yielded),
129
+ offset,
130
+ });
131
+
132
+ if (response.error) throw response.error;
133
+ const data = response.data!;
134
+
135
+ for (const entry of data.items) {
136
+ if (yielded >= maxItems) return;
137
+ yield entry;
138
+ yielded++;
139
+ }
140
+
141
+ offset += data.items.length;
142
+ hasMore = offset < data.total && data.items.length > 0;
143
+ }
144
+ }
74
145
  }
@@ -66,7 +66,7 @@ export class CheckpointsModule {
66
66
  * Replay from a checkpoint.
67
67
  */
68
68
  async replay(checkpointId: string, options?: {
69
- mode?: "best_effort" | "deterministic";
69
+ mode?: "best_effort" | "strict";
70
70
  modified_state?: unknown;
71
71
  }): Promise<APIResponse<ReplayResponse>> {
72
72
  return this.client.POST<ReplayResponse>("/v1/api/checkpoints/{id}/replay", {
@@ -10,8 +10,44 @@ export interface ServerInfo {
10
10
  environment: string;
11
11
  features?: string[];
12
12
  uptime_seconds?: number;
13
+ commit_hash?: string;
14
+ api_version?: string;
13
15
  }
14
16
 
17
+ /** Normalized server capabilities (camelCase, with defaults) */
18
+ export interface ServerCapabilities {
19
+ /** Server version */
20
+ version?: string;
21
+ /** Git commit hash */
22
+ commitHash?: string;
23
+ /** API version */
24
+ apiVersion?: string;
25
+ /** Environment (production, staging, development) */
26
+ environment?: string;
27
+ /** Feature flags - all default to false if not present */
28
+ features: {
29
+ sseResume: boolean;
30
+ cronTriggers: boolean;
31
+ batchRuns: boolean;
32
+ hitl: boolean;
33
+ traces: boolean;
34
+ vectorStores: boolean;
35
+ evaluations: boolean;
36
+ [key: string]: boolean;
37
+ };
38
+ /** Server limits */
39
+ limits?: {
40
+ maxBatchSize?: number;
41
+ maxFileSize?: number;
42
+ [key: string]: number | undefined;
43
+ };
44
+ /** SDK version that fetched this (useful for support) */
45
+ sdkVersion: string;
46
+ }
47
+
48
+ // SDK version from package (will be replaced at build time or use constant)
49
+ const SDK_VERSION = "0.4.0";
50
+
15
51
  export class InfoModule {
16
52
  constructor(private client: RawClient, private headers: () => Record<string, string>) { }
17
53
 
@@ -32,4 +68,76 @@ export class InfoModule {
32
68
  headers: this.headers(),
33
69
  });
34
70
  }
71
+
72
+ /**
73
+ * Get normalized server capabilities for feature detection.
74
+ *
75
+ * This method never assumes feature availability - all features
76
+ * default to false unless explicitly enabled by the server.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const caps = await client.info.capabilities();
81
+ * if (caps.data?.features.sseResume) {
82
+ * // Use follow() with resume
83
+ * } else {
84
+ * // Fall back to polling
85
+ * }
86
+ * ```
87
+ */
88
+ async capabilities(): Promise<APIResponse<ServerCapabilities>> {
89
+ const response = await this.get();
90
+
91
+ if (response.error || !response.data) {
92
+ // Pass through error - construct proper response without data
93
+ return {
94
+ error: response.error,
95
+ response: response.response,
96
+ meta: response.meta,
97
+ };
98
+ }
99
+
100
+ const info = response.data;
101
+
102
+ // Transform snake_case features array to camelCase object
103
+ // CRITICAL: Never assume true - default everything to false
104
+ const featureArray = info.features ?? [];
105
+ const features: ServerCapabilities["features"] = {
106
+ sseResume: featureArray.includes("sse_resume"),
107
+ cronTriggers: featureArray.includes("cron_triggers"),
108
+ batchRuns: featureArray.includes("batch_runs"),
109
+ hitl: featureArray.includes("hitl"),
110
+ traces: featureArray.includes("traces"),
111
+ vectorStores: featureArray.includes("vector_stores"),
112
+ evaluations: featureArray.includes("evaluations"),
113
+ };
114
+
115
+ // Add any other features from array as snake_case → camelCase
116
+ for (const feature of featureArray) {
117
+ const camelCase = snakeToCamel(feature);
118
+ if (!(camelCase in features)) {
119
+ features[camelCase] = true;
120
+ }
121
+ }
122
+
123
+ const capabilities: ServerCapabilities = {
124
+ version: info.version,
125
+ commitHash: info.commit_hash,
126
+ apiVersion: info.api_version,
127
+ environment: info.environment,
128
+ features,
129
+ sdkVersion: SDK_VERSION,
130
+ };
131
+
132
+ return {
133
+ data: capabilities,
134
+ response: response.response,
135
+ meta: response.meta,
136
+ };
137
+ }
138
+ }
139
+
140
+ /** Convert snake_case to camelCase */
141
+ function snakeToCamel(str: string): string {
142
+ return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
35
143
  }