@agent-os-sdk/client 0.9.25 → 0.9.26

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 (184) hide show
  1. package/package.json +15 -8
  2. package/src/generated/openapi.ts +82 -0
  3. package/src/generated/swagger.json +163 -0
  4. package/src/modules/templates.ts +35 -0
  5. package/dist/client/AgentOsClient.d.ts +0 -141
  6. package/dist/client/AgentOsClient.d.ts.map +0 -1
  7. package/dist/client/AgentOsClient.js +0 -250
  8. package/dist/client/HttpRequestBuilder.d.ts +0 -50
  9. package/dist/client/HttpRequestBuilder.d.ts.map +0 -1
  10. package/dist/client/HttpRequestBuilder.js +0 -83
  11. package/dist/client/OperationContext.d.ts +0 -19
  12. package/dist/client/OperationContext.d.ts.map +0 -1
  13. package/dist/client/OperationContext.js +0 -13
  14. package/dist/client/OperationContextProvider.d.ts +0 -54
  15. package/dist/client/OperationContextProvider.d.ts.map +0 -1
  16. package/dist/client/OperationContextProvider.js +0 -71
  17. package/dist/client/auth.d.ts +0 -100
  18. package/dist/client/auth.d.ts.map +0 -1
  19. package/dist/client/auth.js +0 -38
  20. package/dist/client/config.d.ts +0 -49
  21. package/dist/client/config.d.ts.map +0 -1
  22. package/dist/client/config.js +0 -62
  23. package/dist/client/helpers.d.ts +0 -63
  24. package/dist/client/helpers.d.ts.map +0 -1
  25. package/dist/client/helpers.js +0 -55
  26. package/dist/client/pagination.d.ts +0 -105
  27. package/dist/client/pagination.d.ts.map +0 -1
  28. package/dist/client/pagination.js +0 -117
  29. package/dist/client/raw.d.ts +0 -277
  30. package/dist/client/raw.d.ts.map +0 -1
  31. package/dist/client/raw.js +0 -337
  32. package/dist/client/retry.d.ts +0 -37
  33. package/dist/client/retry.d.ts.map +0 -1
  34. package/dist/client/retry.js +0 -108
  35. package/dist/client/sanitize.d.ts +0 -19
  36. package/dist/client/sanitize.d.ts.map +0 -1
  37. package/dist/client/sanitize.js +0 -28
  38. package/dist/client/timeout.d.ts +0 -26
  39. package/dist/client/timeout.d.ts.map +0 -1
  40. package/dist/client/timeout.js +0 -51
  41. package/dist/errors/factory.d.ts +0 -22
  42. package/dist/errors/factory.d.ts.map +0 -1
  43. package/dist/errors/factory.js +0 -101
  44. package/dist/errors/index.d.ts +0 -210
  45. package/dist/errors/index.d.ts.map +0 -1
  46. package/dist/errors/index.js +0 -283
  47. package/dist/generated/client.d.ts +0 -20
  48. package/dist/generated/client.d.ts.map +0 -1
  49. package/dist/generated/client.js +0 -15
  50. package/dist/generated/index.d.ts +0 -2
  51. package/dist/generated/index.d.ts.map +0 -1
  52. package/dist/generated/index.js +0 -1
  53. package/dist/generated/openapi.d.ts +0 -12302
  54. package/dist/generated/openapi.d.ts.map +0 -1
  55. package/dist/generated/openapi.js +0 -5
  56. package/dist/index.d.ts +0 -69
  57. package/dist/index.d.ts.map +0 -1
  58. package/dist/index.js +0 -81
  59. package/dist/modules/a2a.d.ts +0 -48
  60. package/dist/modules/a2a.d.ts.map +0 -1
  61. package/dist/modules/a2a.js +0 -37
  62. package/dist/modules/agents.d.ts +0 -346
  63. package/dist/modules/agents.d.ts.map +0 -1
  64. package/dist/modules/agents.js +0 -296
  65. package/dist/modules/apiTokens.d.ts +0 -62
  66. package/dist/modules/apiTokens.d.ts.map +0 -1
  67. package/dist/modules/apiTokens.js +0 -56
  68. package/dist/modules/approvals.d.ts +0 -75
  69. package/dist/modules/approvals.d.ts.map +0 -1
  70. package/dist/modules/approvals.js +0 -91
  71. package/dist/modules/audit.d.ts +0 -78
  72. package/dist/modules/audit.d.ts.map +0 -1
  73. package/dist/modules/audit.js +0 -94
  74. package/dist/modules/auth.d.ts +0 -28
  75. package/dist/modules/auth.d.ts.map +0 -1
  76. package/dist/modules/auth.js +0 -22
  77. package/dist/modules/builder.d.ts +0 -242
  78. package/dist/modules/builder.d.ts.map +0 -1
  79. package/dist/modules/builder.js +0 -248
  80. package/dist/modules/catalog.d.ts +0 -142
  81. package/dist/modules/catalog.d.ts.map +0 -1
  82. package/dist/modules/catalog.js +0 -136
  83. package/dist/modules/chatwoot.d.ts +0 -59
  84. package/dist/modules/chatwoot.d.ts.map +0 -1
  85. package/dist/modules/chatwoot.js +0 -200
  86. package/dist/modules/checkpoints.d.ts +0 -62
  87. package/dist/modules/checkpoints.d.ts.map +0 -1
  88. package/dist/modules/checkpoints.js +0 -48
  89. package/dist/modules/contracts.d.ts +0 -48
  90. package/dist/modules/contracts.d.ts.map +0 -1
  91. package/dist/modules/contracts.js +0 -25
  92. package/dist/modules/credentials.d.ts +0 -105
  93. package/dist/modules/credentials.d.ts.map +0 -1
  94. package/dist/modules/credentials.js +0 -135
  95. package/dist/modules/crons.d.ts +0 -73
  96. package/dist/modules/crons.d.ts.map +0 -1
  97. package/dist/modules/crons.js +0 -67
  98. package/dist/modules/datasets.d.ts +0 -80
  99. package/dist/modules/datasets.d.ts.map +0 -1
  100. package/dist/modules/datasets.js +0 -91
  101. package/dist/modules/evaluation.d.ts +0 -183
  102. package/dist/modules/evaluation.d.ts.map +0 -1
  103. package/dist/modules/evaluation.js +0 -108
  104. package/dist/modules/files.d.ts +0 -89
  105. package/dist/modules/files.d.ts.map +0 -1
  106. package/dist/modules/files.js +0 -133
  107. package/dist/modules/graphs.d.ts +0 -120
  108. package/dist/modules/graphs.d.ts.map +0 -1
  109. package/dist/modules/graphs.js +0 -69
  110. package/dist/modules/improvements.d.ts +0 -52
  111. package/dist/modules/improvements.d.ts.map +0 -1
  112. package/dist/modules/improvements.js +0 -27
  113. package/dist/modules/info.d.ts +0 -76
  114. package/dist/modules/info.d.ts.map +0 -1
  115. package/dist/modules/info.js +0 -93
  116. package/dist/modules/knowledge.d.ts +0 -91
  117. package/dist/modules/knowledge.d.ts.map +0 -1
  118. package/dist/modules/knowledge.js +0 -80
  119. package/dist/modules/me.d.ts +0 -58
  120. package/dist/modules/me.d.ts.map +0 -1
  121. package/dist/modules/me.js +0 -28
  122. package/dist/modules/members.d.ts +0 -124
  123. package/dist/modules/members.d.ts.map +0 -1
  124. package/dist/modules/members.js +0 -142
  125. package/dist/modules/memberships.d.ts +0 -25
  126. package/dist/modules/memberships.d.ts.map +0 -1
  127. package/dist/modules/memberships.js +0 -20
  128. package/dist/modules/metaAgent.d.ts +0 -95
  129. package/dist/modules/metaAgent.d.ts.map +0 -1
  130. package/dist/modules/metaAgent.js +0 -32
  131. package/dist/modules/metrics.d.ts +0 -20
  132. package/dist/modules/metrics.d.ts.map +0 -1
  133. package/dist/modules/metrics.js +0 -27
  134. package/dist/modules/observability.d.ts +0 -19
  135. package/dist/modules/observability.d.ts.map +0 -1
  136. package/dist/modules/observability.js +0 -14
  137. package/dist/modules/playground.d.ts +0 -42
  138. package/dist/modules/playground.d.ts.map +0 -1
  139. package/dist/modules/playground.js +0 -48
  140. package/dist/modules/presets.d.ts +0 -32
  141. package/dist/modules/presets.d.ts.map +0 -1
  142. package/dist/modules/presets.js +0 -199
  143. package/dist/modules/prompts.d.ts +0 -87
  144. package/dist/modules/prompts.d.ts.map +0 -1
  145. package/dist/modules/prompts.js +0 -87
  146. package/dist/modules/roles.d.ts +0 -64
  147. package/dist/modules/roles.d.ts.map +0 -1
  148. package/dist/modules/roles.js +0 -79
  149. package/dist/modules/runs.d.ts +0 -451
  150. package/dist/modules/runs.d.ts.map +0 -1
  151. package/dist/modules/runs.js +0 -536
  152. package/dist/modules/store.d.ts +0 -37
  153. package/dist/modules/store.d.ts.map +0 -1
  154. package/dist/modules/store.js +0 -48
  155. package/dist/modules/templates.d.ts +0 -28
  156. package/dist/modules/templates.d.ts.map +0 -1
  157. package/dist/modules/templates.js +0 -19
  158. package/dist/modules/tenants.d.ts +0 -49
  159. package/dist/modules/tenants.d.ts.map +0 -1
  160. package/dist/modules/tenants.js +0 -56
  161. package/dist/modules/threads.d.ts +0 -205
  162. package/dist/modules/threads.d.ts.map +0 -1
  163. package/dist/modules/threads.js +0 -225
  164. package/dist/modules/tools.d.ts +0 -62
  165. package/dist/modules/tools.d.ts.map +0 -1
  166. package/dist/modules/tools.js +0 -45
  167. package/dist/modules/traces.d.ts +0 -89
  168. package/dist/modules/traces.d.ts.map +0 -1
  169. package/dist/modules/traces.js +0 -65
  170. package/dist/modules/triggers.d.ts +0 -228
  171. package/dist/modules/triggers.d.ts.map +0 -1
  172. package/dist/modules/triggers.js +0 -176
  173. package/dist/modules/usage.d.ts +0 -85
  174. package/dist/modules/usage.d.ts.map +0 -1
  175. package/dist/modules/usage.js +0 -43
  176. package/dist/modules/vectorStores.d.ts +0 -100
  177. package/dist/modules/vectorStores.d.ts.map +0 -1
  178. package/dist/modules/vectorStores.js +0 -159
  179. package/dist/modules/workspaces.d.ts +0 -138
  180. package/dist/modules/workspaces.d.ts.map +0 -1
  181. package/dist/modules/workspaces.js +0 -121
  182. package/dist/sse/client.d.ts +0 -140
  183. package/dist/sse/client.d.ts.map +0 -1
  184. package/dist/sse/client.js +0 -103
@@ -1,250 +0,0 @@
1
- /**
2
- * Agent OS SDK - Main Client
3
- *
4
- * Fully typed API client for Agent OS platform.
5
- *
6
- * Two authentication modes:
7
- * - API Token (server-to-server): aosk_* tokens with embedded claims
8
- * - JWT (browser): Supabase JWT + X-Workspace-Id header
9
- *
10
- * @example
11
- * ```ts
12
- * // API Token (server-to-server)
13
- * const api = new AgentOsClient({
14
- * baseUrl: "https://api.agentos.io",
15
- * auth: { type: "api_token", apiKey: "aosk_live_xxx" }
16
- * });
17
- *
18
- * // JWT (browser)
19
- * const api = new AgentOsClient({
20
- * baseUrl: "https://api.agentos.io",
21
- * auth: {
22
- * type: "jwt",
23
- * getToken: () => supabase.auth.getSession().then(s => s.data.session?.access_token ?? ""),
24
- * getWorkspaceId: () => localStorage.getItem("agentos.workspaceId") ?? ""
25
- * }
26
- * });
27
- * ```
28
- */
29
- import { isApiTokenAuth, isBrowser, isJwtAuth, } from "./auth.js";
30
- import { createRawClient } from "./raw.js";
31
- import { AgentsModule } from "../modules/agents.js";
32
- import { ChatwootModule } from "../modules/chatwoot.js";
33
- import { CredentialsModule } from "../modules/credentials.js";
34
- import { DatasetsModule } from "../modules/datasets.js";
35
- import { RolesModule } from "../modules/roles.js";
36
- import { MembersModule } from "../modules/members.js";
37
- import { RunsModule } from "../modules/runs.js";
38
- import { TenantsModule } from "../modules/tenants.js";
39
- import { ThreadsModule } from "../modules/threads.js";
40
- import { ToolsModule } from "../modules/tools.js";
41
- import { TriggersModule } from "../modules/triggers.js";
42
- import { WorkspacesModule } from "../modules/workspaces.js";
43
- // Platform modules
44
- import { A2aModule } from "../modules/a2a.js";
45
- import { ApiTokensModule } from "../modules/apiTokens.js";
46
- import { ApprovalsModule } from "../modules/approvals.js";
47
- import { AuditModule } from "../modules/audit.js";
48
- import { AuthModule } from "../modules/auth.js";
49
- import { CatalogModule } from "../modules/catalog.js";
50
- import { CheckpointsModule } from "../modules/checkpoints.js";
51
- import { ContractsModule } from "../modules/contracts.js";
52
- import { CronsModule } from "../modules/crons.js";
53
- import { EvaluationModule } from "../modules/evaluation.js";
54
- import { FilesModule } from "../modules/files.js";
55
- import { InfoModule } from "../modules/info.js";
56
- import { ImprovementsModule } from "../modules/improvements.js";
57
- import { MeModule } from "../modules/me.js";
58
- import { MembershipsModule } from "../modules/memberships.js";
59
- import { MetaAgentModule } from "../modules/metaAgent.js";
60
- import { MetricsModule } from "../modules/metrics.js";
61
- import { ObservabilityModule } from "../modules/observability.js";
62
- import { PlaygroundModule } from "../modules/playground.js";
63
- import { PresetsModule } from "../modules/presets.js";
64
- import { PromptsModule } from "../modules/prompts.js";
65
- import { StoreModule } from "../modules/store.js";
66
- import { TemplatesModule } from "../modules/templates.js";
67
- import { TracesModule } from "../modules/traces.js";
68
- import { UsageModule } from "../modules/usage.js";
69
- import { VectorStoresModule } from "../modules/vectorStores.js";
70
- // Re-export auth types
71
- export { isApiTokenAuth, isJwtAuth } from "./auth.js";
72
- export class AgentOsClient {
73
- _client;
74
- _baseUrl;
75
- _auth;
76
- _customHeaders;
77
- // Core modules
78
- agents;
79
- runs;
80
- threads;
81
- tools;
82
- datasets;
83
- roles;
84
- triggers;
85
- credentials;
86
- members;
87
- tenants;
88
- workspaces;
89
- chatwoot;
90
- // Platform modules
91
- prompts;
92
- traces;
93
- files;
94
- vectorStores;
95
- evaluation;
96
- checkpoints;
97
- playground;
98
- crons;
99
- store;
100
- audit;
101
- usage;
102
- a2a;
103
- me;
104
- info;
105
- improvements;
106
- metrics;
107
- metaAgent;
108
- contracts;
109
- catalog;
110
- approvals;
111
- auth;
112
- observability;
113
- templates;
114
- // Convenience aliases
115
- experiments;
116
- apiTokens;
117
- memberships;
118
- presets;
119
- constructor(options) {
120
- this._baseUrl = options.baseUrl;
121
- this._auth = options.auth;
122
- this._customHeaders = options.headers ?? {};
123
- // Validate auth configuration
124
- this._validateAuth(options);
125
- // Create raw client with async header provider
126
- this._client = createRawClient({
127
- baseUrl: options.baseUrl,
128
- headerProvider: () => this._resolveHeaders(),
129
- contextProvider: options.contextProvider,
130
- network: options.network,
131
- hooks: options.hooks,
132
- });
133
- // Module header getter (sync fallback for backwards compat with module internals)
134
- const getHeaders = () => this._customHeaders;
135
- const getWorkspaceId = () => "";
136
- const getTenantId = () => "";
137
- // Initialize core modules
138
- this.agents = new AgentsModule(this._client, getHeaders);
139
- this.runs = new RunsModule(this._client);
140
- this.threads = new ThreadsModule(this._client, getHeaders);
141
- this.tools = new ToolsModule(this._client, getHeaders);
142
- this.datasets = new DatasetsModule(this._client, getHeaders);
143
- this.roles = new RolesModule(this._client, getHeaders);
144
- this.triggers = new TriggersModule(this._client, getHeaders);
145
- this.credentials = new CredentialsModule(this._client, getWorkspaceId, getHeaders);
146
- this.members = new MembersModule(this._client, getHeaders);
147
- this.tenants = new TenantsModule(this._client, getHeaders);
148
- this.workspaces = new WorkspacesModule(this._client, getTenantId, getHeaders);
149
- this.chatwoot = new ChatwootModule(this._client, getHeaders);
150
- // Initialize platform modules
151
- this.prompts = new PromptsModule(this._client, getHeaders);
152
- this.traces = new TracesModule(this._client, getHeaders);
153
- this.files = new FilesModule(this._client, getHeaders);
154
- this.vectorStores = new VectorStoresModule(this._client, getHeaders);
155
- this.evaluation = new EvaluationModule(this._client, getHeaders);
156
- this.checkpoints = new CheckpointsModule(this._client, getHeaders);
157
- this.playground = new PlaygroundModule(this._client, getHeaders);
158
- this.crons = new CronsModule(this._client, getHeaders);
159
- this.store = new StoreModule(this._client, getHeaders);
160
- this.audit = new AuditModule(this._client, getHeaders);
161
- this.usage = new UsageModule(this._client, getHeaders);
162
- this.a2a = new A2aModule(this._client, getHeaders);
163
- this.me = new MeModule(this._client, getHeaders);
164
- this.info = new InfoModule(this._client, getHeaders);
165
- this.improvements = new ImprovementsModule(this._client, getHeaders);
166
- this.metrics = new MetricsModule(this._client);
167
- this.metaAgent = new MetaAgentModule(this._client, getHeaders);
168
- this.contracts = new ContractsModule(this._client, getHeaders);
169
- this.catalog = new CatalogModule(this._client);
170
- this.approvals = new ApprovalsModule(this._client, getHeaders);
171
- this.auth = new AuthModule(this._client, getHeaders);
172
- this.observability = new ObservabilityModule(this._client, getHeaders);
173
- this.templates = new TemplatesModule(this._client, getHeaders);
174
- // Initialize convenience aliases
175
- this.experiments = {
176
- list: this.evaluation.listExperiments.bind(this.evaluation),
177
- get: this.evaluation.getExperiment.bind(this.evaluation),
178
- create: this.evaluation.createExperiment.bind(this.evaluation),
179
- };
180
- this.apiTokens = new ApiTokensModule(this._client);
181
- this.memberships = new MembershipsModule(this._client);
182
- this.presets = new PresetsModule(this._client, getHeaders);
183
- }
184
- /**
185
- * Validate auth configuration at construction time
186
- */
187
- _validateAuth(options) {
188
- const { auth, allowApiTokenInBrowser } = options;
189
- // Browser security guard for API tokens
190
- if (isApiTokenAuth(auth) && isBrowser() && !allowApiTokenInBrowser) {
191
- throw new Error("[AgentOS SDK] SECURITY: API tokens (aosk_*) are SERVER-SIDE only. " +
192
- "Use JWT auth in the browser. Set allowApiTokenInBrowser: true only if you understand the risks.");
193
- }
194
- }
195
- /**
196
- * Resolve headers for each request (async)
197
- *
198
- * SECURITY INVARIANTS:
199
- * - JWT: Authorization + X-Workspace-Id (REQUIRED), NO X-Tenant-Id
200
- * - API Token: Authorization only, NO X-Workspace-Id, NO X-Tenant-Id
201
- */
202
- async _resolveHeaders() {
203
- const headers = {
204
- "Content-Type": "application/json",
205
- ...this._customHeaders,
206
- };
207
- if (isApiTokenAuth(this._auth)) {
208
- // API Token: Authorization header only
209
- const apiKey = typeof this._auth.apiKey === "function"
210
- ? await this._auth.apiKey()
211
- : this._auth.apiKey;
212
- if (apiKey) {
213
- headers["Authorization"] = `Bearer ${apiKey}`;
214
- }
215
- // NO X-Workspace-Id (embedded in token claims)
216
- // NO X-Tenant-Id (embedded in token claims)
217
- }
218
- else if (isJwtAuth(this._auth)) {
219
- // JWT: Authorization + X-Workspace-Id
220
- const [token, workspaceId] = await Promise.all([
221
- Promise.resolve(this._auth.getToken()),
222
- Promise.resolve(this._auth.getWorkspaceId()),
223
- ]);
224
- if (token) {
225
- headers["Authorization"] = `Bearer ${token}`;
226
- }
227
- // Workspace ID is optional for bootstrap endpoints (e.g., /me)
228
- // Most endpoints require it, but the header provider allows empty strings
229
- if (workspaceId) {
230
- headers["X-Workspace-Id"] = workspaceId;
231
- }
232
- // NO X-Tenant-Id (backend derives from workspace membership)
233
- }
234
- return headers;
235
- }
236
- /**
237
- * Get resolved headers (for debugging/testing)
238
- */
239
- async getHeadersAsync() {
240
- return this._resolveHeaders();
241
- }
242
- /** Auth provider type */
243
- get authType() {
244
- return this._auth.type;
245
- }
246
- /** Raw HTTP client (use modules instead) */
247
- get raw() {
248
- return this._client;
249
- }
250
- }
@@ -1,50 +0,0 @@
1
- /**
2
- * HttpRequestBuilder — Single source of truth for headers
3
- *
4
- * All header generation flows through this builder.
5
- * raw.ts should NOT generate headers directly.
6
- *
7
- * Headers generated:
8
- * - X-Request-Id: Per-request, always new (crypto.randomUUID)
9
- * - X-Correlation-Id: Per-flow, immutable within flow
10
- * - Authorization: Bearer token
11
- * - X-Workspace-Id: Workspace binding (from context)
12
- * - X-Idempotency-Key: Opt-in for POST requests
13
- * - User-Agent: SDK version + runtime info
14
- *
15
- * @see sdk-upgrade.md Section 1.3
16
- */
17
- import type { OperationContext } from "./OperationContext.js";
18
- export declare function sanitizeValidCorrelationId(raw?: string): string | null;
19
- /**
20
- * Options for building request headers
21
- */
22
- export interface HttpRequestBuilderOptions {
23
- /** Bearer token for Authorization header */
24
- token?: string;
25
- /** Operation context with correlationId and workspaceId */
26
- context?: OperationContext;
27
- /** Idempotency key for POST requests */
28
- idempotencyKey?: string;
29
- /** If true, throws if correlationId is missing */
30
- requireFlow?: boolean;
31
- }
32
- /**
33
- * Build headers for HTTP requests.
34
- * This is the SINGLE SOURCE OF TRUTH for header generation.
35
- */
36
- export declare class HttpRequestBuilder {
37
- /**
38
- * Build headers from options.
39
- *
40
- * @throws Error if requireFlow is true and correlationId is missing
41
- */
42
- build(opts: HttpRequestBuilderOptions): Record<string, string>;
43
- private resolveCorrelationId;
44
- /**
45
- * Build User-Agent string with SDK version and runtime info
46
- */
47
- private buildUserAgent;
48
- }
49
- export declare const httpRequestBuilder: HttpRequestBuilder;
50
- //# sourceMappingURL=HttpRequestBuilder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"HttpRequestBuilder.d.ts","sourceRoot":"","sources":["../../src/client/HttpRequestBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAQ9D,wBAAgB,0BAA0B,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGtE;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACtC,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,wCAAwC;IACxC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kDAAkD;IAClD,WAAW,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;GAGG;AACH,qBAAa,kBAAkB;IAC3B;;;;OAIG;IACH,KAAK,CAAC,IAAI,EAAE,yBAAyB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAiC9D,OAAO,CAAC,oBAAoB;IAS5B;;OAEG;IACH,OAAO,CAAC,cAAc;CAYzB;AAGD,eAAO,MAAM,kBAAkB,oBAA2B,CAAC"}
@@ -1,83 +0,0 @@
1
- /**
2
- * HttpRequestBuilder — Single source of truth for headers
3
- *
4
- * All header generation flows through this builder.
5
- * raw.ts should NOT generate headers directly.
6
- *
7
- * Headers generated:
8
- * - X-Request-Id: Per-request, always new (crypto.randomUUID)
9
- * - X-Correlation-Id: Per-flow, immutable within flow
10
- * - Authorization: Bearer token
11
- * - X-Workspace-Id: Workspace binding (from context)
12
- * - X-Idempotency-Key: Opt-in for POST requests
13
- * - User-Agent: SDK version + runtime info
14
- *
15
- * @see sdk-upgrade.md Section 1.3
16
- */
17
- import { sanitizeHeader, sanitizeHeaders } from "./sanitize.js";
18
- const SDK_VERSION = typeof __SDK_VERSION__ !== "undefined" ? __SDK_VERSION__ : "0.7.12-dev";
19
- const CORRELATION_ID_PATTERN = /^[A-Za-z0-9._:-]{8,128}$/;
20
- export function sanitizeValidCorrelationId(raw) {
21
- const candidate = sanitizeHeader((raw ?? "").trim());
22
- return CORRELATION_ID_PATTERN.test(candidate) ? candidate : null;
23
- }
24
- /**
25
- * Build headers for HTTP requests.
26
- * This is the SINGLE SOURCE OF TRUTH for header generation.
27
- */
28
- export class HttpRequestBuilder {
29
- /**
30
- * Build headers from options.
31
- *
32
- * @throws Error if requireFlow is true and correlationId is missing
33
- */
34
- build(opts) {
35
- const headers = {};
36
- // I2: X-Request-Id always exists (per request)
37
- headers["X-Request-Id"] = crypto.randomUUID();
38
- // User-Agent: Dynamic SDK version
39
- headers["User-Agent"] = this.buildUserAgent();
40
- // I3: X-Correlation-Id is per flow
41
- if (opts.requireFlow && !opts.context?.correlationId) {
42
- throw new Error("X-Correlation-Id required for flow-scoped operations");
43
- }
44
- headers["X-Correlation-Id"] = this.resolveCorrelationId(opts.context?.correlationId);
45
- // Authorization
46
- if (opts.token) {
47
- headers["Authorization"] = `Bearer ${opts.token}`;
48
- }
49
- // X-Workspace-Id from context
50
- if (opts.context?.workspaceId) {
51
- headers["X-Workspace-Id"] = opts.context.workspaceId;
52
- }
53
- // I7: Idempotency is opt-in
54
- if (opts.idempotencyKey) {
55
- headers["X-Idempotency-Key"] = sanitizeHeader(opts.idempotencyKey);
56
- }
57
- return sanitizeHeaders(headers);
58
- }
59
- resolveCorrelationId(raw) {
60
- const candidate = sanitizeValidCorrelationId(raw);
61
- if (candidate) {
62
- return candidate;
63
- }
64
- return crypto.randomUUID();
65
- }
66
- /**
67
- * Build User-Agent string with SDK version and runtime info
68
- */
69
- buildUserAgent() {
70
- // Node.js environment
71
- if (typeof process !== "undefined" && process.version) {
72
- return `agent-os-sdk/${SDK_VERSION} (node/${process.version})`;
73
- }
74
- // Browser environment
75
- if (typeof navigator !== "undefined" && navigator.userAgent) {
76
- return `agent-os-sdk/${SDK_VERSION} (browser)`;
77
- }
78
- // Unknown environment
79
- return `agent-os-sdk/${SDK_VERSION}`;
80
- }
81
- }
82
- // Singleton instance for convenience
83
- export const httpRequestBuilder = new HttpRequestBuilder();
@@ -1,19 +0,0 @@
1
- /**
2
- * OperationContext — Immutable flow context
3
- *
4
- * Created at the start of a logical flow and never mutates.
5
- *
6
- * - correlationId: Tracks the entire logical operation (immutable per flow)
7
- * - workspaceId: Optional workspace binding
8
- *
9
- * @see sdk-upgrade.md Section 1.1
10
- */
11
- export type OperationContext = Readonly<{
12
- correlationId: string;
13
- workspaceId?: string;
14
- }>;
15
- export declare function createOperationContext(input: {
16
- correlationId: string;
17
- workspaceId?: string;
18
- }): OperationContext;
19
- //# sourceMappingURL=OperationContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OperationContext.d.ts","sourceRoot":"","sources":["../../src/client/OperationContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC,CAAC;AAEH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAC1C,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG,gBAAgB,CAEnB"}
@@ -1,13 +0,0 @@
1
- /**
2
- * OperationContext — Immutable flow context
3
- *
4
- * Created at the start of a logical flow and never mutates.
5
- *
6
- * - correlationId: Tracks the entire logical operation (immutable per flow)
7
- * - workspaceId: Optional workspace binding
8
- *
9
- * @see sdk-upgrade.md Section 1.1
10
- */
11
- export function createOperationContext(input) {
12
- return Object.freeze({ ...input });
13
- }
@@ -1,54 +0,0 @@
1
- /**
2
- * OperationContextProvider — Flow lifecycle management
3
- *
4
- * Provider defines the lifecycle of a flow context.
5
- * Implementations can use AsyncLocalStorage or manual context passing.
6
- *
7
- * @see sdk-upgrade.md Section 1.2
8
- */
9
- import type { OperationContext } from "./OperationContext.js";
10
- /**
11
- * Interface for context providers
12
- */
13
- export interface OperationContextProvider {
14
- get(): OperationContext | undefined;
15
- }
16
- /**
17
- * Default provider that always returns undefined.
18
- * Used when no flow context is established.
19
- */
20
- export declare class DefaultContextProvider implements OperationContextProvider {
21
- get(): OperationContext | undefined;
22
- }
23
- /**
24
- * AsyncLocalStorage-based provider for Node.js environments.
25
- * Automatically propagates context through async call chains.
26
- *
27
- * Note: This class requires Node.js async_hooks module.
28
- * Import and use only in Node.js environments.
29
- */
30
- export declare class AsyncLocalStorageContextProvider implements OperationContextProvider {
31
- private readonly storage;
32
- constructor();
33
- get(): OperationContext | undefined;
34
- /**
35
- * Run a function within a context.
36
- * The context is automatically available to all async operations within.
37
- */
38
- run<T>(context: OperationContext, fn: () => T): T;
39
- /**
40
- * Run an async function within a context.
41
- */
42
- runAsync<T>(context: OperationContext, fn: () => Promise<T>): Promise<T>;
43
- }
44
- /**
45
- * Manual provider for environments without AsyncLocalStorage.
46
- * Context must be explicitly set and cleared.
47
- */
48
- export declare class ManualContextProvider implements OperationContextProvider {
49
- private context;
50
- get(): OperationContext | undefined;
51
- set(context: OperationContext): void;
52
- clear(): void;
53
- }
54
- //# sourceMappingURL=OperationContextProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OperationContextProvider.d.ts","sourceRoot":"","sources":["../../src/client/OperationContextProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACrC,GAAG,IAAI,gBAAgB,GAAG,SAAS,CAAC;CACvC;AAED;;;GAGG;AACH,qBAAa,sBAAuB,YAAW,wBAAwB;IACnE,GAAG,IAAI,gBAAgB,GAAG,SAAS;CAGtC;AAED;;;;;;GAMG;AACH,qBAAa,gCAAiC,YAAW,wBAAwB;IAE7E,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAM;;IAa9B,GAAG,IAAI,gBAAgB,GAAG,SAAS;IAInC;;;OAGG;IACH,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAIjD;;OAEG;IACH,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAG3E;AAED;;;GAGG;AACH,qBAAa,qBAAsB,YAAW,wBAAwB;IAClE,OAAO,CAAC,OAAO,CAA+B;IAE9C,GAAG,IAAI,gBAAgB,GAAG,SAAS;IAInC,GAAG,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAIpC,KAAK,IAAI,IAAI;CAGhB"}
@@ -1,71 +0,0 @@
1
- /**
2
- * OperationContextProvider — Flow lifecycle management
3
- *
4
- * Provider defines the lifecycle of a flow context.
5
- * Implementations can use AsyncLocalStorage or manual context passing.
6
- *
7
- * @see sdk-upgrade.md Section 1.2
8
- */
9
- /**
10
- * Default provider that always returns undefined.
11
- * Used when no flow context is established.
12
- */
13
- export class DefaultContextProvider {
14
- get() {
15
- return undefined;
16
- }
17
- }
18
- /**
19
- * AsyncLocalStorage-based provider for Node.js environments.
20
- * Automatically propagates context through async call chains.
21
- *
22
- * Note: This class requires Node.js async_hooks module.
23
- * Import and use only in Node.js environments.
24
- */
25
- export class AsyncLocalStorageContextProvider {
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
- storage;
28
- constructor() {
29
- // Dynamic import to avoid browser errors
30
- try {
31
- // eslint-disable-next-line @typescript-eslint/no-require-imports
32
- const asyncHooks = require("async_hooks");
33
- this.storage = new asyncHooks.AsyncLocalStorage();
34
- }
35
- catch {
36
- throw new Error("AsyncLocalStorage requires Node.js environment");
37
- }
38
- }
39
- get() {
40
- return this.storage?.getStore();
41
- }
42
- /**
43
- * Run a function within a context.
44
- * The context is automatically available to all async operations within.
45
- */
46
- run(context, fn) {
47
- return this.storage.run(context, fn);
48
- }
49
- /**
50
- * Run an async function within a context.
51
- */
52
- runAsync(context, fn) {
53
- return this.storage.run(context, fn);
54
- }
55
- }
56
- /**
57
- * Manual provider for environments without AsyncLocalStorage.
58
- * Context must be explicitly set and cleared.
59
- */
60
- export class ManualContextProvider {
61
- context;
62
- get() {
63
- return this.context;
64
- }
65
- set(context) {
66
- this.context = context;
67
- }
68
- clear() {
69
- this.context = undefined;
70
- }
71
- }
@@ -1,100 +0,0 @@
1
- /**
2
- * Auth Provider Types for Agent OS SDK
3
- *
4
- * Two modes only:
5
- * - JWT (browser): Uses Supabase JWT + X-Workspace-Id header
6
- * - API Token (server): Uses aosk_* token with embedded claims
7
- */
8
- import type { NetworkConfig } from "./config.js";
9
- import type { SDKHooks } from "./raw.js";
10
- import type { OperationContextProvider } from "./OperationContextProvider.js";
11
- /**
12
- * API Token authentication for server-to-server integrations.
13
- * Token format: aosk_live_* or aosk_test_*
14
- *
15
- * SECURITY: API tokens contain embedded workspace/tenant claims.
16
- * The SDK sends ONLY Authorization header (no X-Workspace-Id, no X-Tenant-Id).
17
- *
18
- * @example
19
- * ```ts
20
- * const client = new AgentOsClient({
21
- * baseUrl: "https://api.example.com",
22
- * auth: { type: "api_token", apiKey: "aosk_live_xxx" }
23
- * })
24
- * ```
25
- */
26
- export type ApiTokenAuth = {
27
- type: "api_token";
28
- /** API key (aosk_*) or function that returns one */
29
- apiKey: string | (() => string | Promise<string>);
30
- };
31
- /**
32
- * JWT authentication for browser/frontend clients.
33
- * Uses Supabase JWT with X-Workspace-Id header.
34
- *
35
- * SECURITY:
36
- * - X-Workspace-Id is REQUIRED (throws if missing)
37
- * - X-Tenant-Id is NEVER sent (backend derives from workspace membership)
38
- *
39
- * @example
40
- * ```ts
41
- * const client = new AgentOsClient({
42
- * baseUrl: "https://api.example.com",
43
- * auth: {
44
- * type: "jwt",
45
- * getToken: async () => (await supabase.auth.getSession()).data.session?.access_token,
46
- * getWorkspaceId: () => localStorage.getItem("agentos.workspaceId")!,
47
- * }
48
- * })
49
- * ```
50
- */
51
- export type JwtAuth = {
52
- type: "jwt";
53
- /** Function to get the JWT access token */
54
- getToken: () => string | Promise<string>;
55
- /** Function to get the current workspace ID (REQUIRED) */
56
- getWorkspaceId: () => string | Promise<string>;
57
- };
58
- /**
59
- * Auth provider union type - only two modes supported
60
- */
61
- export type AuthProvider = ApiTokenAuth | JwtAuth;
62
- /**
63
- * Options for AgentOsClient - auth is REQUIRED
64
- */
65
- export type AgentOsClientOptions = {
66
- /** Base URL of the Agent OS Control Plane */
67
- baseUrl: string;
68
- /** Authentication provider (REQUIRED) */
69
- auth: AuthProvider;
70
- /**
71
- * Allow API token in browser environment.
72
- * Default: false (throws error to prevent accidental exposure)
73
- * Only set to true if you understand the security implications.
74
- */
75
- allowApiTokenInBrowser?: boolean;
76
- /** Network policy (timeouts/retries). */
77
- network?: Partial<NetworkConfig>;
78
- /** Optional request lifecycle hooks for observability */
79
- hooks?: SDKHooks;
80
- /** Optional flow context provider (ALS/manual) for sticky correlation per operation. */
81
- /** Recommended for long-lived server clients to avoid process-wide sticky fallback correlation. */
82
- contextProvider?: OperationContextProvider;
83
- /** Custom headers to add to all requests */
84
- headers?: Record<string, string>;
85
- };
86
- export declare function isApiTokenAuth(auth: AuthProvider): auth is ApiTokenAuth;
87
- export declare function isJwtAuth(auth: AuthProvider): auth is JwtAuth;
88
- /**
89
- * Detect browser environment
90
- */
91
- export declare function isBrowser(): boolean;
92
- /**
93
- * Check if token looks like an API token (aosk_*)
94
- */
95
- export declare function isApiToken(token: string): boolean;
96
- /**
97
- * Check if token looks like a JWT (three base64 segments)
98
- */
99
- export declare function isJwtToken(token: string): boolean;
100
- //# sourceMappingURL=auth.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/client/auth.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAM9E;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,YAAY,GAAG;IACvB,IAAI,EAAE,WAAW,CAAA;IACjB,oDAAoD;IACpD,MAAM,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;CACpD,CAAA;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,OAAO,GAAG;IAClB,IAAI,EAAE,KAAK,CAAA;IACX,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IACxC,0DAA0D;IAC1D,cAAc,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CACjD,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,OAAO,CAAA;AAMjD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IAC/B,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAA;IACf,yCAAyC;IACzC,IAAI,EAAE,YAAY,CAAA;IAClB;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,yCAAyC;IACzC,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;IAChC,yDAAyD;IACzD,KAAK,CAAC,EAAE,QAAQ,CAAA;IAChB,wFAAwF;IACxF,mGAAmG;IACnG,eAAe,CAAC,EAAE,wBAAwB,CAAA;IAC1C,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACnC,CAAA;AAMD,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,IAAI,YAAY,CAEvE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,IAAI,OAAO,CAE7D;AAMD;;GAEG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGjD"}