@agent-os-sdk/client 0.2.2 → 0.3.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/dist/client/AgentOsClient.d.ts +19 -53
- package/dist/client/AgentOsClient.d.ts.map +1 -1
- package/dist/client/AgentOsClient.js +59 -175
- package/dist/client/auth.d.ts +15 -27
- package/dist/client/auth.d.ts.map +1 -1
- package/dist/client/auth.js +2 -8
- package/dist/client/raw.d.ts +1 -0
- package/dist/client/raw.d.ts.map +1 -1
- package/dist/client/raw.js +4 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/modules/approvals.d.ts +50 -39
- package/dist/modules/approvals.d.ts.map +1 -1
- package/dist/modules/approvals.js +71 -34
- package/package.json +50 -49
- package/src/client/AgentOsClient.ts +66 -184
- package/src/client/auth.ts +15 -38
- package/src/client/raw.ts +7 -1
- package/src/index.ts +2 -3
- package/src/modules/approvals.ts +106 -64
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* Agent OS SDK - Main Client
|
|
3
3
|
*
|
|
4
4
|
* Fully typed API client for Agent OS platform.
|
|
5
|
-
*
|
|
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
|
|
6
9
|
*
|
|
7
10
|
* @example
|
|
8
11
|
* ```ts
|
|
@@ -17,8 +20,8 @@
|
|
|
17
20
|
* baseUrl: "https://api.agentos.io",
|
|
18
21
|
* auth: {
|
|
19
22
|
* type: "jwt",
|
|
20
|
-
* getToken: () => supabase.auth.getSession().then(s => s.data.session?.access_token),
|
|
21
|
-
* getWorkspaceId: () => localStorage.getItem("agentos.workspaceId")
|
|
23
|
+
* getToken: () => supabase.auth.getSession().then(s => s.data.session?.access_token ?? ""),
|
|
24
|
+
* getWorkspaceId: () => localStorage.getItem("agentos.workspaceId") ?? ""
|
|
22
25
|
* }
|
|
23
26
|
* });
|
|
24
27
|
* ```
|
|
@@ -27,12 +30,9 @@
|
|
|
27
30
|
import { createRawClient, type RawClient } from "./raw.js";
|
|
28
31
|
import {
|
|
29
32
|
type AgentOsClientOptions,
|
|
30
|
-
type AgentOsClientOptionsLegacy,
|
|
31
33
|
type AuthProvider,
|
|
32
|
-
isNewAuthOptions,
|
|
33
34
|
isApiTokenAuth,
|
|
34
35
|
isJwtAuth,
|
|
35
|
-
isApiToken,
|
|
36
36
|
isBrowser,
|
|
37
37
|
} from "./auth.js";
|
|
38
38
|
|
|
@@ -48,7 +48,7 @@ import { MembersModule } from "../modules/members.js";
|
|
|
48
48
|
import { TenantsModule } from "../modules/tenants.js";
|
|
49
49
|
import { WorkspacesModule } from "../modules/workspaces.js";
|
|
50
50
|
|
|
51
|
-
//
|
|
51
|
+
// Platform modules
|
|
52
52
|
import { PromptsModule } from "../modules/prompts.js";
|
|
53
53
|
import { TracesModule } from "../modules/traces.js";
|
|
54
54
|
import { FilesModule } from "../modules/files.js";
|
|
@@ -68,7 +68,7 @@ import { InfoModule } from "../modules/info.js";
|
|
|
68
68
|
import { MetricsModule } from "../modules/metrics.js";
|
|
69
69
|
import { GraphsModule } from "../modules/graphs.js";
|
|
70
70
|
|
|
71
|
-
//
|
|
71
|
+
// Future modules (mocked)
|
|
72
72
|
import { HandoffModule } from "../modules/handoff.js";
|
|
73
73
|
import { FlowsModule } from "../modules/flows.js";
|
|
74
74
|
import { CapabilitiesModule } from "../modules/capabilities.js";
|
|
@@ -80,84 +80,49 @@ import { IncidentsModule } from "../modules/incidents.js";
|
|
|
80
80
|
import { ArtifactsModule } from "../modules/artifacts.js";
|
|
81
81
|
|
|
82
82
|
// Re-export auth types
|
|
83
|
-
export type { AgentOsClientOptions,
|
|
84
|
-
export { isApiTokenAuth, isJwtAuth
|
|
83
|
+
export type { AgentOsClientOptions, AuthProvider } from "./auth.js";
|
|
84
|
+
export { isApiTokenAuth, isJwtAuth } from "./auth.js";
|
|
85
85
|
|
|
86
86
|
export class AgentOsClient {
|
|
87
87
|
private readonly _client: RawClient;
|
|
88
88
|
private readonly _baseUrl: string;
|
|
89
|
-
private readonly _auth: AuthProvider
|
|
89
|
+
private readonly _auth: AuthProvider;
|
|
90
90
|
private readonly _customHeaders: Record<string, string>;
|
|
91
91
|
|
|
92
|
-
// Legacy fields (for backwards compat)
|
|
93
|
-
private readonly _tenantId?: string;
|
|
94
|
-
private readonly _workspaceId?: string;
|
|
95
|
-
private readonly _token?: string;
|
|
96
|
-
private readonly _memberId?: string;
|
|
97
|
-
|
|
98
92
|
// Core modules
|
|
99
|
-
/** Agents API: CRUD, versions, graph */
|
|
100
93
|
readonly agents: AgentsModule;
|
|
101
|
-
/** Runs API: create, stream, cancel, resume, replay */
|
|
102
94
|
readonly runs: RunsModule;
|
|
103
|
-
/** Threads API: conversations, state, messages */
|
|
104
95
|
readonly threads: ThreadsModule;
|
|
105
|
-
/** Tools API: definitions, registry */
|
|
106
96
|
readonly tools: ToolsModule;
|
|
107
|
-
/** Knowledge API: vector stores, RAG */
|
|
108
97
|
readonly knowledge: KnowledgeModule;
|
|
109
|
-
/** Triggers API: webhooks, crons */
|
|
110
98
|
readonly triggers: TriggersModule;
|
|
111
|
-
/** Credentials API: BYOK secrets */
|
|
112
99
|
readonly credentials: CredentialsModule;
|
|
113
|
-
/** Builder API: Meta-agent for AI-assisted agent creation */
|
|
114
100
|
readonly builder: BuilderModule;
|
|
115
|
-
/** Members API: Tenant member management */
|
|
116
101
|
readonly members: MembersModule;
|
|
117
|
-
/** Tenants API: Tenant settings */
|
|
118
102
|
readonly tenants: TenantsModule;
|
|
119
|
-
/** Workspaces API: Workspace management */
|
|
120
103
|
readonly workspaces: WorkspacesModule;
|
|
121
104
|
|
|
122
|
-
//
|
|
123
|
-
/** Prompts API: Prompt Hub CMS */
|
|
105
|
+
// Platform modules
|
|
124
106
|
readonly prompts: PromptsModule;
|
|
125
|
-
/** Traces API: OTEL observability */
|
|
126
107
|
readonly traces: TracesModule;
|
|
127
|
-
/** Files API: S3 file storage */
|
|
128
108
|
readonly files: FilesModule;
|
|
129
|
-
/** VectorStores API: pgvector semantic search */
|
|
130
109
|
readonly vectorStores: VectorStoresModule;
|
|
131
|
-
/** Evaluation API: Datasets & experiments */
|
|
132
110
|
readonly evaluation: EvaluationModule;
|
|
133
|
-
/** Checkpoints API: Time-travel debugging */
|
|
134
111
|
readonly checkpoints: CheckpointsModule;
|
|
135
|
-
/** Playground API: Ephemeral sandbox */
|
|
136
112
|
readonly playground: PlaygroundModule;
|
|
137
|
-
/** Crons API: Cron job scheduling */
|
|
138
113
|
readonly crons: CronsModule;
|
|
139
|
-
/** DLQ API: Dead letter queue */
|
|
140
114
|
readonly dlq: DlqModule;
|
|
141
|
-
/** Store API: Key-value storage */
|
|
142
115
|
readonly store: StoreModule;
|
|
143
|
-
/** Audit API: Audit logs */
|
|
144
116
|
readonly audit: AuditModule;
|
|
145
|
-
/** Usage API: Quotas and usage */
|
|
146
117
|
readonly usage: UsageModule;
|
|
147
|
-
/** MCP API: Model Context Protocol */
|
|
148
118
|
readonly mcp: McpModule;
|
|
149
|
-
/** A2A API: Agent-to-Agent protocol */
|
|
150
119
|
readonly a2a: A2aModule;
|
|
151
|
-
/** Me API: Current user identity */
|
|
152
120
|
readonly me: MeModule;
|
|
153
|
-
/** Info API: Server information */
|
|
154
121
|
readonly info: InfoModule;
|
|
155
|
-
/** Metrics API: Prometheus metrics */
|
|
156
122
|
readonly metrics: MetricsModule;
|
|
157
|
-
/** Graphs API: Validation and introspection */
|
|
158
123
|
readonly graphs: GraphsModule;
|
|
159
124
|
|
|
160
|
-
//
|
|
125
|
+
// Future modules (mocked)
|
|
161
126
|
readonly handoff: HandoffModule;
|
|
162
127
|
readonly flows: FlowsModule;
|
|
163
128
|
readonly capabilities: CapabilitiesModule;
|
|
@@ -168,7 +133,7 @@ export class AgentOsClient {
|
|
|
168
133
|
readonly incidents: IncidentsModule;
|
|
169
134
|
readonly artifacts: ArtifactsModule;
|
|
170
135
|
|
|
171
|
-
// Convenience
|
|
136
|
+
// Convenience aliases
|
|
172
137
|
readonly experiments: {
|
|
173
138
|
list: EvaluationModule["listExperiments"];
|
|
174
139
|
get: EvaluationModule["getExperiment"];
|
|
@@ -181,46 +146,24 @@ export class AgentOsClient {
|
|
|
181
146
|
create: (agentId: string, body: Parameters<AgentsModule["createVersion"]>[1]) => ReturnType<AgentsModule["createVersion"]>;
|
|
182
147
|
};
|
|
183
148
|
|
|
184
|
-
constructor(options: AgentOsClientOptions
|
|
149
|
+
constructor(options: AgentOsClientOptions) {
|
|
185
150
|
this._baseUrl = options.baseUrl;
|
|
151
|
+
this._auth = options.auth;
|
|
186
152
|
this._customHeaders = options.headers ?? {};
|
|
187
153
|
|
|
188
|
-
//
|
|
189
|
-
|
|
190
|
-
// New auth provider mode
|
|
191
|
-
this._auth = options.auth;
|
|
192
|
-
this._validateAuth(options);
|
|
193
|
-
} else {
|
|
194
|
-
// Legacy mode - convert to new auth if possible
|
|
195
|
-
this._tenantId = options.tenantId;
|
|
196
|
-
this._workspaceId = options.workspaceId;
|
|
197
|
-
this._token = options.token;
|
|
198
|
-
this._memberId = options.memberId;
|
|
199
|
-
|
|
200
|
-
// Attempt to detect auth type from token
|
|
201
|
-
if (options.token && isApiToken(options.token)) {
|
|
202
|
-
// Token looks like API token - use as api_token
|
|
203
|
-
this._auth = { type: "api_token", apiKey: options.token };
|
|
204
|
-
console.warn(
|
|
205
|
-
"[AgentOS SDK] Using legacy options with API token. " +
|
|
206
|
-
"Consider migrating to: new AgentOsClient({ auth: { type: 'api_token', apiKey: '...' } })"
|
|
207
|
-
);
|
|
208
|
-
} else {
|
|
209
|
-
// Legacy JWT mode - keep using headers
|
|
210
|
-
this._auth = null;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
154
|
+
// Validate auth configuration
|
|
155
|
+
this._validateAuth(options);
|
|
213
156
|
|
|
214
|
-
// Create raw
|
|
157
|
+
// Create raw client with async header provider
|
|
215
158
|
this._client = createRawClient({
|
|
216
159
|
baseUrl: options.baseUrl,
|
|
217
|
-
|
|
160
|
+
headerProvider: () => this._resolveHeaders(),
|
|
218
161
|
});
|
|
219
162
|
|
|
220
|
-
//
|
|
221
|
-
const getHeaders = () => this.
|
|
222
|
-
const getWorkspaceId = () =>
|
|
223
|
-
const getTenantId = () =>
|
|
163
|
+
// Module header getter (sync fallback for backwards compat with module internals)
|
|
164
|
+
const getHeaders = () => this._customHeaders;
|
|
165
|
+
const getWorkspaceId = () => "";
|
|
166
|
+
const getTenantId = () => "";
|
|
224
167
|
|
|
225
168
|
// Initialize core modules
|
|
226
169
|
this.agents = new AgentsModule(this._client, getHeaders);
|
|
@@ -235,7 +178,7 @@ export class AgentOsClient {
|
|
|
235
178
|
this.tenants = new TenantsModule(this._client, getHeaders);
|
|
236
179
|
this.workspaces = new WorkspacesModule(this._client, getTenantId, getHeaders);
|
|
237
180
|
|
|
238
|
-
// Initialize
|
|
181
|
+
// Initialize platform modules
|
|
239
182
|
this.prompts = new PromptsModule(this._client, getHeaders);
|
|
240
183
|
this.traces = new TracesModule(this._client, getHeaders);
|
|
241
184
|
this.files = new FilesModule(this._client, getHeaders);
|
|
@@ -255,7 +198,7 @@ export class AgentOsClient {
|
|
|
255
198
|
this.metrics = new MetricsModule(this._baseUrl, getHeaders);
|
|
256
199
|
this.graphs = new GraphsModule(this._client, getHeaders);
|
|
257
200
|
|
|
258
|
-
//
|
|
201
|
+
// Initialize future modules (mocked)
|
|
259
202
|
this.handoff = new HandoffModule(this._client, getHeaders);
|
|
260
203
|
this.flows = new FlowsModule(this._client, getHeaders);
|
|
261
204
|
this.capabilities = new CapabilitiesModule(this._client, getHeaders);
|
|
@@ -281,140 +224,79 @@ export class AgentOsClient {
|
|
|
281
224
|
}
|
|
282
225
|
|
|
283
226
|
/**
|
|
284
|
-
* Validate auth configuration
|
|
227
|
+
* Validate auth configuration at construction time
|
|
285
228
|
*/
|
|
286
229
|
private _validateAuth(options: AgentOsClientOptions): void {
|
|
287
230
|
const { auth, allowApiTokenInBrowser } = options;
|
|
288
231
|
|
|
289
|
-
// Browser guard for API tokens
|
|
232
|
+
// Browser security guard for API tokens
|
|
290
233
|
if (isApiTokenAuth(auth) && isBrowser() && !allowApiTokenInBrowser) {
|
|
291
234
|
throw new Error(
|
|
292
|
-
"[AgentOS SDK] API tokens
|
|
293
|
-
"
|
|
294
|
-
"Use JWT auth for browser clients, or set allowApiTokenInBrowser: true if you understand the risks."
|
|
235
|
+
"[AgentOS SDK] SECURITY: API tokens (aosk_*) are SERVER-SIDE only. " +
|
|
236
|
+
"Use JWT auth in the browser. Set allowApiTokenInBrowser: true only if you understand the risks."
|
|
295
237
|
);
|
|
296
238
|
}
|
|
297
239
|
}
|
|
298
240
|
|
|
299
241
|
/**
|
|
300
|
-
*
|
|
242
|
+
* Resolve headers for each request (async)
|
|
243
|
+
*
|
|
244
|
+
* SECURITY INVARIANTS:
|
|
245
|
+
* - JWT: Authorization + X-Workspace-Id (REQUIRED), NO X-Tenant-Id
|
|
246
|
+
* - API Token: Authorization only, NO X-Workspace-Id, NO X-Tenant-Id
|
|
301
247
|
*/
|
|
302
|
-
private
|
|
248
|
+
private async _resolveHeaders(): Promise<Record<string, string>> {
|
|
303
249
|
const headers: Record<string, string> = {
|
|
304
250
|
"Content-Type": "application/json",
|
|
305
251
|
...this._customHeaders,
|
|
306
252
|
};
|
|
307
253
|
|
|
308
|
-
if (this._auth) {
|
|
309
|
-
//
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
? "" // Will be resolved async
|
|
314
|
-
: this._auth.apiKey;
|
|
315
|
-
if (apiKey) {
|
|
316
|
-
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
317
|
-
}
|
|
318
|
-
// NO X-Tenant-Id, NO X-Workspace-Id (backend resolves from claims)
|
|
319
|
-
} else if (isJwtAuth(this._auth)) {
|
|
320
|
-
// JWT: Authorization + X-Workspace-Id
|
|
321
|
-
// Note: For sync header getter, we use empty strings as placeholders
|
|
322
|
-
// The actual values are resolved in _getHeadersAsync
|
|
323
|
-
// This is a limitation of the current module architecture
|
|
324
|
-
}
|
|
325
|
-
} else {
|
|
326
|
-
// Legacy mode - use stored values
|
|
327
|
-
if (this._token) {
|
|
328
|
-
headers["Authorization"] = `Bearer ${this._token}`;
|
|
329
|
-
}
|
|
330
|
-
if (this._tenantId) {
|
|
331
|
-
headers["X-Tenant-Id"] = this._tenantId;
|
|
332
|
-
}
|
|
333
|
-
if (this._workspaceId) {
|
|
334
|
-
headers["X-Workspace-Id"] = this._workspaceId;
|
|
335
|
-
}
|
|
336
|
-
if (this._memberId) {
|
|
337
|
-
headers["X-Member-Id"] = this._memberId;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
return headers;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Get headers for current request (async version - resolves auth functions)
|
|
346
|
-
*/
|
|
347
|
-
async getHeadersAsync(): Promise<Record<string, string>> {
|
|
348
|
-
const headers: Record<string, string> = {
|
|
349
|
-
"Content-Type": "application/json",
|
|
350
|
-
...this._customHeaders,
|
|
351
|
-
};
|
|
254
|
+
if (isApiTokenAuth(this._auth)) {
|
|
255
|
+
// API Token: Authorization header only
|
|
256
|
+
const apiKey = typeof this._auth.apiKey === "function"
|
|
257
|
+
? await this._auth.apiKey()
|
|
258
|
+
: this._auth.apiKey;
|
|
352
259
|
|
|
353
|
-
|
|
354
|
-
if (isApiTokenAuth(this._auth)) {
|
|
355
|
-
// API Token
|
|
356
|
-
const apiKey = typeof this._auth.apiKey === "function"
|
|
357
|
-
? await this._auth.apiKey()
|
|
358
|
-
: this._auth.apiKey;
|
|
260
|
+
if (apiKey) {
|
|
359
261
|
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
if (!workspaceId) {
|
|
372
|
-
throw new Error("[AgentOS SDK] Workspace ID not available. Please select a workspace first.");
|
|
373
|
-
}
|
|
262
|
+
}
|
|
263
|
+
// NO X-Workspace-Id (embedded in token claims)
|
|
264
|
+
// NO X-Tenant-Id (embedded in token claims)
|
|
265
|
+
|
|
266
|
+
} else if (isJwtAuth(this._auth)) {
|
|
267
|
+
// JWT: Authorization + X-Workspace-Id
|
|
268
|
+
const [token, workspaceId] = await Promise.all([
|
|
269
|
+
Promise.resolve(this._auth.getToken()),
|
|
270
|
+
Promise.resolve(this._auth.getWorkspaceId()),
|
|
271
|
+
]);
|
|
374
272
|
|
|
273
|
+
if (token) {
|
|
375
274
|
headers["Authorization"] = `Bearer ${token}`;
|
|
376
|
-
headers["X-Workspace-Id"] = workspaceId;
|
|
377
|
-
// NO X-Tenant-Id (backend derives from workspace membership)
|
|
378
|
-
}
|
|
379
|
-
} else {
|
|
380
|
-
// Legacy mode
|
|
381
|
-
if (this._token) {
|
|
382
|
-
headers["Authorization"] = `Bearer ${this._token}`;
|
|
383
|
-
}
|
|
384
|
-
if (this._tenantId) {
|
|
385
|
-
headers["X-Tenant-Id"] = this._tenantId;
|
|
386
275
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
276
|
+
|
|
277
|
+
// CRITICAL: Workspace ID is REQUIRED for JWT auth
|
|
278
|
+
if (!workspaceId) {
|
|
279
|
+
throw new Error(
|
|
280
|
+
"[AgentOS SDK] No active workspace selected. " +
|
|
281
|
+
"Call getWorkspaceId() must return a valid workspace ID."
|
|
282
|
+
);
|
|
392
283
|
}
|
|
284
|
+
headers["X-Workspace-Id"] = workspaceId;
|
|
285
|
+
// NO X-Tenant-Id (backend derives from workspace membership)
|
|
393
286
|
}
|
|
394
287
|
|
|
395
288
|
return headers;
|
|
396
289
|
}
|
|
397
290
|
|
|
398
291
|
/**
|
|
399
|
-
* Get
|
|
292
|
+
* Get resolved headers (for debugging/testing)
|
|
400
293
|
*/
|
|
401
|
-
|
|
402
|
-
return this.
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
/** Current tenant ID (legacy) */
|
|
406
|
-
get tenantId(): string {
|
|
407
|
-
return this._tenantId ?? "";
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/** Current workspace ID (legacy) */
|
|
411
|
-
get workspaceId(): string {
|
|
412
|
-
return this._workspaceId ?? "";
|
|
294
|
+
async getHeadersAsync(): Promise<Record<string, string>> {
|
|
295
|
+
return this._resolveHeaders();
|
|
413
296
|
}
|
|
414
297
|
|
|
415
298
|
/** Auth provider type */
|
|
416
|
-
get authType(): "api_token" | "jwt"
|
|
417
|
-
if (!this._auth) return "legacy";
|
|
299
|
+
get authType(): "api_token" | "jwt" {
|
|
418
300
|
return this._auth.type;
|
|
419
301
|
}
|
|
420
302
|
|
package/src/client/auth.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Auth Provider Types for Agent OS SDK
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* - JWT (browser): Uses Supabase JWT +
|
|
4
|
+
* Two modes only:
|
|
5
|
+
* - JWT (browser): Uses Supabase JWT + X-Workspace-Id header
|
|
6
6
|
* - API Token (server): Uses aosk_* token with embedded claims
|
|
7
7
|
*/
|
|
8
8
|
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
* API Token authentication for server-to-server integrations.
|
|
15
15
|
* Token format: aosk_live_* or aosk_test_*
|
|
16
16
|
*
|
|
17
|
+
* SECURITY: API tokens contain embedded workspace/tenant claims.
|
|
18
|
+
* The SDK sends ONLY Authorization header (no X-Workspace-Id, no X-Tenant-Id).
|
|
19
|
+
*
|
|
17
20
|
* @example
|
|
18
21
|
* ```ts
|
|
19
22
|
* const client = new AgentOsClient({
|
|
@@ -30,7 +33,11 @@ export type ApiTokenAuth = {
|
|
|
30
33
|
|
|
31
34
|
/**
|
|
32
35
|
* JWT authentication for browser/frontend clients.
|
|
33
|
-
* Uses Supabase JWT with
|
|
36
|
+
* Uses Supabase JWT with X-Workspace-Id header.
|
|
37
|
+
*
|
|
38
|
+
* SECURITY:
|
|
39
|
+
* - X-Workspace-Id is REQUIRED (throws if missing)
|
|
40
|
+
* - X-Tenant-Id is NEVER sent (backend derives from workspace membership)
|
|
34
41
|
*
|
|
35
42
|
* @example
|
|
36
43
|
* ```ts
|
|
@@ -48,12 +55,12 @@ export type JwtAuth = {
|
|
|
48
55
|
type: "jwt"
|
|
49
56
|
/** Function to get the JWT access token */
|
|
50
57
|
getToken: () => string | Promise<string>
|
|
51
|
-
/** Function to get the current workspace ID */
|
|
58
|
+
/** Function to get the current workspace ID (REQUIRED) */
|
|
52
59
|
getWorkspaceId: () => string | Promise<string>
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
/**
|
|
56
|
-
* Auth provider union type
|
|
63
|
+
* Auth provider union type - only two modes supported
|
|
57
64
|
*/
|
|
58
65
|
export type AuthProvider = ApiTokenAuth | JwtAuth
|
|
59
66
|
|
|
@@ -62,57 +69,27 @@ export type AuthProvider = ApiTokenAuth | JwtAuth
|
|
|
62
69
|
// ============================================================================
|
|
63
70
|
|
|
64
71
|
/**
|
|
65
|
-
*
|
|
72
|
+
* Options for AgentOsClient - auth is REQUIRED
|
|
66
73
|
*/
|
|
67
74
|
export type AgentOsClientOptions = {
|
|
68
75
|
/** Base URL of the Agent OS Control Plane */
|
|
69
76
|
baseUrl: string
|
|
70
|
-
/** Authentication provider */
|
|
77
|
+
/** Authentication provider (REQUIRED) */
|
|
71
78
|
auth: AuthProvider
|
|
72
79
|
/**
|
|
73
80
|
* Allow API token in browser environment.
|
|
74
81
|
* Default: false (throws error to prevent accidental exposure)
|
|
82
|
+
* Only set to true if you understand the security implications.
|
|
75
83
|
*/
|
|
76
84
|
allowApiTokenInBrowser?: boolean
|
|
77
85
|
/** Custom headers to add to all requests */
|
|
78
86
|
headers?: Record<string, string>
|
|
79
87
|
}
|
|
80
88
|
|
|
81
|
-
/**
|
|
82
|
-
* Legacy options (backwards compatibility)
|
|
83
|
-
* @deprecated Use AgentOsClientOptions with auth provider instead
|
|
84
|
-
*/
|
|
85
|
-
export type AgentOsClientOptionsLegacy = {
|
|
86
|
-
/** Base URL of the Agent OS API */
|
|
87
|
-
baseUrl: string
|
|
88
|
-
/** Tenant ID @deprecated */
|
|
89
|
-
tenantId: string
|
|
90
|
-
/** Workspace ID @deprecated */
|
|
91
|
-
workspaceId: string
|
|
92
|
-
/** Auth token @deprecated */
|
|
93
|
-
token?: string
|
|
94
|
-
/** Member ID @deprecated */
|
|
95
|
-
memberId?: string
|
|
96
|
-
/** Custom headers */
|
|
97
|
-
headers?: Record<string, string>
|
|
98
|
-
}
|
|
99
|
-
|
|
100
89
|
// ============================================================================
|
|
101
90
|
// Type Guards
|
|
102
91
|
// ============================================================================
|
|
103
92
|
|
|
104
|
-
export function isNewAuthOptions(
|
|
105
|
-
opts: AgentOsClientOptions | AgentOsClientOptionsLegacy
|
|
106
|
-
): opts is AgentOsClientOptions {
|
|
107
|
-
return "auth" in opts && opts.auth !== undefined
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function isLegacyOptions(
|
|
111
|
-
opts: AgentOsClientOptions | AgentOsClientOptionsLegacy
|
|
112
|
-
): opts is AgentOsClientOptionsLegacy {
|
|
113
|
-
return "tenantId" in opts || "workspaceId" in opts
|
|
114
|
-
}
|
|
115
|
-
|
|
116
93
|
export function isApiTokenAuth(auth: AuthProvider): auth is ApiTokenAuth {
|
|
117
94
|
return auth.type === "api_token"
|
|
118
95
|
}
|
package/src/client/raw.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type { paths, components };
|
|
|
14
14
|
export type ClientOptions = {
|
|
15
15
|
baseUrl: string;
|
|
16
16
|
headers?: Record<string, string>;
|
|
17
|
+
headerProvider?: () => Promise<Record<string, string>>;
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
/**
|
|
@@ -52,7 +53,7 @@ export function createTypedClient(options: ClientOptions): TypedClient {
|
|
|
52
53
|
* Wraps openapi-fetch to provide the old interface while maintaining types.
|
|
53
54
|
*/
|
|
54
55
|
export function createRawClient(options: ClientOptions) {
|
|
55
|
-
const { baseUrl, headers: defaultHeaders = {} } = options;
|
|
56
|
+
const { baseUrl, headers: defaultHeaders = {}, headerProvider } = options;
|
|
56
57
|
|
|
57
58
|
async function request<T>(
|
|
58
59
|
method: string,
|
|
@@ -88,8 +89,13 @@ export function createRawClient(options: ClientOptions) {
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
const fullUrl = `${baseUrl}${url}`;
|
|
92
|
+
|
|
93
|
+
// Resolve dynamic headers (e.g. auth)
|
|
94
|
+
const dynamicHeaders = headerProvider ? await headerProvider() : {};
|
|
95
|
+
|
|
91
96
|
const headers: Record<string, string> = {
|
|
92
97
|
...defaultHeaders,
|
|
98
|
+
...dynamicHeaders,
|
|
93
99
|
...opts?.headers,
|
|
94
100
|
};
|
|
95
101
|
|
package/src/index.ts
CHANGED
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
// ============================================================================
|
|
39
39
|
// Main Client
|
|
40
40
|
// ============================================================================
|
|
41
|
-
export { AgentOsClient, type AgentOsClientOptions, type
|
|
41
|
+
export { AgentOsClient, type AgentOsClientOptions, type AuthProvider } from "./client/AgentOsClient.js";
|
|
42
42
|
|
|
43
43
|
// Auth Provider Types
|
|
44
44
|
export {
|
|
@@ -46,7 +46,6 @@ export {
|
|
|
46
46
|
type JwtAuth,
|
|
47
47
|
isApiTokenAuth,
|
|
48
48
|
isJwtAuth,
|
|
49
|
-
isNewAuthOptions,
|
|
50
49
|
isBrowser,
|
|
51
50
|
isApiToken,
|
|
52
51
|
isJwtToken,
|
|
@@ -122,7 +121,7 @@ export { HandoffModule, type HandoffOptions, type HandoffResult, type ForkOption
|
|
|
122
121
|
export { FlowsModule, type Flow, type FlowStep, type FlowRun, type FlowVisualization, type FlowSimulationResult, type FlowStatus, type FlowListResponse } from "./modules/flows.js";
|
|
123
122
|
export { CapabilitiesModule, type Capability, type CapabilityType, type CapabilityTest, type CapabilityMatrix } from "./modules/capabilities.js";
|
|
124
123
|
export { PoliciesModule, type Policy, type PolicyScope, type PolicyEnforcement, type PolicyRule, type PolicyEvaluation, type PolicyEvaluationResult } from "./modules/policies.js";
|
|
125
|
-
export { ApprovalsModule, type Approval, type ApprovalStatus, type
|
|
124
|
+
export { ApprovalsModule, type Approval, type ApprovalStatus, type ApprovalDecision, type ApprovalListResponse, type ApprovalStatusResponse } from "./modules/approvals.js";
|
|
126
125
|
export { BudgetsModule, type Budget, type BudgetPeriod, type BudgetScope, type BudgetResourceType, type BudgetUsage, type BudgetAlert, type BudgetBreakdownItem } from "./modules/budgets.js";
|
|
127
126
|
export { DeploymentsModule, type Environment, type Deployment, type DeploymentStatus, type DeploymentConfig, type DeploymentHealth } from "./modules/deployments.js";
|
|
128
127
|
export { IncidentsModule, type Incident, type IncidentSeverity, type IncidentStatus, type IncidentUpdate, type IncidentMetrics } from "./modules/incidents.js";
|