@agent-os-sdk/client 0.1.2 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/AgentOsClient.d.ts +39 -44
- package/dist/client/AgentOsClient.d.ts.map +1 -1
- package/dist/client/AgentOsClient.js +162 -44
- package/dist/client/auth.d.ts +102 -0
- package/dist/client/auth.d.ts.map +1 -0
- package/dist/client/auth.js +44 -0
- package/dist/generated/openapi.d.ts +914 -202
- package/dist/generated/openapi.d.ts.map +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/modules/approvals.d.ts +8 -22
- package/dist/modules/approvals.d.ts.map +1 -1
- package/dist/modules/approvals.js +27 -130
- package/dist/modules/artifacts.d.ts +28 -79
- package/dist/modules/artifacts.d.ts.map +1 -1
- package/dist/modules/artifacts.js +30 -197
- package/dist/modules/budgets.d.ts +47 -70
- package/dist/modules/budgets.d.ts.map +1 -1
- package/dist/modules/budgets.js +28 -139
- package/dist/modules/builder.d.ts +21 -1
- package/dist/modules/builder.d.ts.map +1 -1
- package/dist/modules/builder.js +25 -3
- package/dist/modules/capabilities.d.ts +39 -50
- package/dist/modules/capabilities.d.ts.map +1 -1
- package/dist/modules/capabilities.js +32 -95
- package/dist/modules/deployments.d.ts +49 -92
- package/dist/modules/deployments.d.ts.map +1 -1
- package/dist/modules/deployments.js +37 -209
- package/dist/modules/flows.d.ts +11 -31
- package/dist/modules/flows.d.ts.map +1 -1
- package/dist/modules/flows.js +33 -157
- package/dist/modules/handoff.d.ts +7 -4
- package/dist/modules/handoff.d.ts.map +1 -1
- package/dist/modules/handoff.js +25 -88
- package/dist/modules/incidents.d.ts +40 -101
- package/dist/modules/incidents.d.ts.map +1 -1
- package/dist/modules/incidents.js +31 -208
- package/dist/modules/policies.d.ts +42 -69
- package/dist/modules/policies.d.ts.map +1 -1
- package/dist/modules/policies.js +25 -159
- package/dist/modules/runs.d.ts +89 -3
- package/dist/modules/runs.d.ts.map +1 -1
- package/dist/modules/runs.js +75 -4
- package/package.json +1 -1
- package/src/client/AgentOsClient.ts +185 -67
- package/src/client/auth.ts +148 -0
- package/src/generated/openapi.ts +914 -202
- package/src/generated/swagger.json +770 -630
- package/src/index.ts +22 -10
- package/src/modules/approvals.ts +31 -132
- package/src/modules/artifacts.ts +41 -245
- package/src/modules/budgets.ts +65 -181
- package/src/modules/builder.ts +25 -3
- package/src/modules/capabilities.ts +58 -139
- package/src/modules/deployments.ts +67 -271
- package/src/modules/flows.ts +37 -163
- package/src/modules/handoff.ts +29 -93
- package/src/modules/incidents.ts +56 -282
- package/src/modules/policies.ts +57 -203
- package/src/modules/runs.ts +123 -5
|
@@ -2,25 +2,40 @@
|
|
|
2
2
|
* Agent OS SDK - Main Client
|
|
3
3
|
*
|
|
4
4
|
* Fully typed API client for Agent OS platform.
|
|
5
|
-
*
|
|
5
|
+
* Supports both API Token (server) and JWT (browser) authentication.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```ts
|
|
9
|
+
* // API Token (server-to-server)
|
|
9
10
|
* const api = new AgentOsClient({
|
|
10
|
-
* baseUrl: "
|
|
11
|
-
*
|
|
12
|
-
* workspaceId: "...",
|
|
13
|
-
* token: "...",
|
|
11
|
+
* baseUrl: "https://api.agentos.io",
|
|
12
|
+
* auth: { type: "api_token", apiKey: "aosk_live_xxx" }
|
|
14
13
|
* });
|
|
15
14
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
15
|
+
* // JWT (browser)
|
|
16
|
+
* const api = new AgentOsClient({
|
|
17
|
+
* baseUrl: "https://api.agentos.io",
|
|
18
|
+
* auth: {
|
|
19
|
+
* type: "jwt",
|
|
20
|
+
* getToken: () => supabase.auth.getSession().then(s => s.data.session?.access_token),
|
|
21
|
+
* getWorkspaceId: () => localStorage.getItem("agentos.workspaceId")!
|
|
22
|
+
* }
|
|
19
23
|
* });
|
|
20
24
|
* ```
|
|
21
25
|
*/
|
|
22
26
|
|
|
23
27
|
import { createRawClient, type RawClient } from "./raw.js";
|
|
28
|
+
import {
|
|
29
|
+
type AgentOsClientOptions,
|
|
30
|
+
type AgentOsClientOptionsLegacy,
|
|
31
|
+
type AuthProvider,
|
|
32
|
+
isNewAuthOptions,
|
|
33
|
+
isApiTokenAuth,
|
|
34
|
+
isJwtAuth,
|
|
35
|
+
isApiToken,
|
|
36
|
+
isBrowser,
|
|
37
|
+
} from "./auth.js";
|
|
38
|
+
|
|
24
39
|
import { AgentsModule } from "../modules/agents.js";
|
|
25
40
|
import { RunsModule } from "../modules/runs.js";
|
|
26
41
|
import { ThreadsModule } from "../modules/threads.js";
|
|
@@ -64,35 +79,21 @@ import { DeploymentsModule } from "../modules/deployments.js";
|
|
|
64
79
|
import { IncidentsModule } from "../modules/incidents.js";
|
|
65
80
|
import { ArtifactsModule } from "../modules/artifacts.js";
|
|
66
81
|
|
|
67
|
-
export
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
/** Tenant ID (multi-tenant) */
|
|
72
|
-
tenantId: string;
|
|
73
|
-
|
|
74
|
-
/** Workspace ID */
|
|
75
|
-
workspaceId: string;
|
|
76
|
-
|
|
77
|
-
/** Optional auth token */
|
|
78
|
-
token?: string;
|
|
79
|
-
|
|
80
|
-
/** Optional member ID (for identity header) */
|
|
81
|
-
memberId?: string;
|
|
82
|
-
|
|
83
|
-
/** Custom headers */
|
|
84
|
-
headers?: Record<string, string>;
|
|
85
|
-
};
|
|
82
|
+
// Re-export auth types
|
|
83
|
+
export type { AgentOsClientOptions, AgentOsClientOptionsLegacy, AuthProvider } from "./auth.js";
|
|
84
|
+
export { isApiTokenAuth, isJwtAuth, isNewAuthOptions } from "./auth.js";
|
|
86
85
|
|
|
87
86
|
export class AgentOsClient {
|
|
88
87
|
private readonly _client: RawClient;
|
|
89
88
|
private readonly _baseUrl: string;
|
|
90
|
-
private readonly
|
|
91
|
-
private readonly _workspaceId: string;
|
|
92
|
-
private readonly _token?: string;
|
|
93
|
-
private readonly _memberId?: string;
|
|
89
|
+
private readonly _auth: AuthProvider | null;
|
|
94
90
|
private readonly _customHeaders: Record<string, string>;
|
|
95
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;
|
|
96
97
|
|
|
97
98
|
// Core modules
|
|
98
99
|
/** Agents API: CRUD, versions, graph */
|
|
@@ -156,62 +157,70 @@ export class AgentOsClient {
|
|
|
156
157
|
/** Graphs API: Validation and introspection */
|
|
157
158
|
readonly graphs: GraphsModule;
|
|
158
159
|
|
|
159
|
-
// MOCK - Future modules
|
|
160
|
-
/** Handoff API: Multi-agent delegation */
|
|
160
|
+
// MOCK - Future modules
|
|
161
161
|
readonly handoff: HandoffModule;
|
|
162
|
-
/** Flows API: Workflow orchestration */
|
|
163
162
|
readonly flows: FlowsModule;
|
|
164
|
-
/** Capabilities API: Agent/run permissions */
|
|
165
163
|
readonly capabilities: CapabilitiesModule;
|
|
166
|
-
/** Policies API: Governance rules */
|
|
167
164
|
readonly policies: PoliciesModule;
|
|
168
|
-
/** Approvals API: Human-in-the-loop */
|
|
169
165
|
readonly approvals: ApprovalsModule;
|
|
170
|
-
/** Budgets API: Cost control */
|
|
171
166
|
readonly budgets: BudgetsModule;
|
|
172
|
-
/** Deployments API: Release management */
|
|
173
167
|
readonly deployments: DeploymentsModule;
|
|
174
|
-
/** Incidents API: Operational incidents & SLOs */
|
|
175
168
|
readonly incidents: IncidentsModule;
|
|
176
|
-
/** Artifacts API: Output management */
|
|
177
169
|
readonly artifacts: ArtifactsModule;
|
|
178
170
|
|
|
179
|
-
//
|
|
180
|
-
/**
|
|
181
|
-
* Alias for evaluation.listExperiments() - provides first-level access to experiments
|
|
182
|
-
* @example client.experiments.list() // same as client.evaluation.listExperiments()
|
|
183
|
-
*/
|
|
171
|
+
// Convenience Aliases
|
|
184
172
|
readonly experiments: {
|
|
185
173
|
list: EvaluationModule["listExperiments"];
|
|
186
174
|
get: EvaluationModule["getExperiment"];
|
|
187
175
|
create: EvaluationModule["createExperiment"];
|
|
188
176
|
};
|
|
189
177
|
|
|
190
|
-
/**
|
|
191
|
-
* Alias for agents.listVersions() - provides first-level access to agent versions
|
|
192
|
-
*/
|
|
193
178
|
readonly agentVersions: {
|
|
194
179
|
list: (agentId: string) => ReturnType<AgentsModule["listVersions"]>;
|
|
195
180
|
get: (agentId: string, versionId: string) => ReturnType<AgentsModule["getVersion"]>;
|
|
196
181
|
create: (agentId: string, body: Parameters<AgentsModule["createVersion"]>[1]) => ReturnType<AgentsModule["createVersion"]>;
|
|
197
182
|
};
|
|
198
183
|
|
|
199
|
-
constructor(options: AgentOsClientOptions) {
|
|
184
|
+
constructor(options: AgentOsClientOptions | AgentOsClientOptionsLegacy) {
|
|
200
185
|
this._baseUrl = options.baseUrl;
|
|
201
|
-
this._tenantId = options.tenantId;
|
|
202
|
-
this._workspaceId = options.workspaceId;
|
|
203
|
-
this._token = options.token;
|
|
204
|
-
this._memberId = options.memberId;
|
|
205
186
|
this._customHeaders = options.headers ?? {};
|
|
206
187
|
|
|
188
|
+
// Detect auth mode
|
|
189
|
+
if (isNewAuthOptions(options)) {
|
|
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
|
+
}
|
|
213
|
+
|
|
214
|
+
// Create raw HTTP client
|
|
207
215
|
this._client = createRawClient({
|
|
208
216
|
baseUrl: options.baseUrl,
|
|
209
|
-
headers:
|
|
217
|
+
headers: {}, // Headers resolved dynamically
|
|
210
218
|
});
|
|
211
219
|
|
|
220
|
+
// Bound header getter
|
|
212
221
|
const getHeaders = () => this._getHeaders();
|
|
213
|
-
const getWorkspaceId = () => this.
|
|
214
|
-
const getTenantId = () => this._tenantId;
|
|
222
|
+
const getWorkspaceId = () => this._getWorkspaceIdSync();
|
|
223
|
+
const getTenantId = () => this._tenantId ?? "";
|
|
215
224
|
|
|
216
225
|
// Initialize core modules
|
|
217
226
|
this.agents = new AgentsModule(this._client, getHeaders);
|
|
@@ -271,33 +280,142 @@ export class AgentOsClient {
|
|
|
271
280
|
};
|
|
272
281
|
}
|
|
273
282
|
|
|
283
|
+
/**
|
|
284
|
+
* Validate auth configuration
|
|
285
|
+
*/
|
|
286
|
+
private _validateAuth(options: AgentOsClientOptions): void {
|
|
287
|
+
const { auth, allowApiTokenInBrowser } = options;
|
|
288
|
+
|
|
289
|
+
// Browser guard for API tokens
|
|
290
|
+
if (isApiTokenAuth(auth) && isBrowser() && !allowApiTokenInBrowser) {
|
|
291
|
+
throw new Error(
|
|
292
|
+
"[AgentOS SDK] API tokens should not be used in the browser. " +
|
|
293
|
+
"They may be exposed in network requests. " +
|
|
294
|
+
"Use JWT auth for browser clients, or set allowApiTokenInBrowser: true if you understand the risks."
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Get headers for current request (sync version for modules)
|
|
301
|
+
*/
|
|
274
302
|
private _getHeaders(): Record<string, string> {
|
|
275
303
|
const headers: Record<string, string> = {
|
|
276
304
|
"Content-Type": "application/json",
|
|
277
|
-
"X-Tenant-Id": this._tenantId,
|
|
278
|
-
"X-Workspace-Id": this._workspaceId,
|
|
279
305
|
...this._customHeaders,
|
|
280
306
|
};
|
|
281
307
|
|
|
282
|
-
if (this.
|
|
283
|
-
|
|
308
|
+
if (this._auth) {
|
|
309
|
+
// New auth mode
|
|
310
|
+
if (isApiTokenAuth(this._auth)) {
|
|
311
|
+
// API Token: Only Authorization header
|
|
312
|
+
const apiKey = typeof this._auth.apiKey === "function"
|
|
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
|
+
}
|
|
284
339
|
}
|
|
285
340
|
|
|
286
|
-
|
|
287
|
-
|
|
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
|
+
};
|
|
352
|
+
|
|
353
|
+
if (this._auth) {
|
|
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;
|
|
359
|
+
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
360
|
+
// NO X-Tenant-Id, NO X-Workspace-Id
|
|
361
|
+
} else if (isJwtAuth(this._auth)) {
|
|
362
|
+
// JWT
|
|
363
|
+
const [token, workspaceId] = await Promise.all([
|
|
364
|
+
this._auth.getToken(),
|
|
365
|
+
this._auth.getWorkspaceId(),
|
|
366
|
+
]);
|
|
367
|
+
|
|
368
|
+
if (!token) {
|
|
369
|
+
throw new Error("[AgentOS SDK] JWT token not available. User may not be authenticated.");
|
|
370
|
+
}
|
|
371
|
+
if (!workspaceId) {
|
|
372
|
+
throw new Error("[AgentOS SDK] Workspace ID not available. Please select a workspace first.");
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
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
|
+
}
|
|
387
|
+
if (this._workspaceId) {
|
|
388
|
+
headers["X-Workspace-Id"] = this._workspaceId;
|
|
389
|
+
}
|
|
390
|
+
if (this._memberId) {
|
|
391
|
+
headers["X-Member-Id"] = this._memberId;
|
|
392
|
+
}
|
|
288
393
|
}
|
|
289
394
|
|
|
290
395
|
return headers;
|
|
291
396
|
}
|
|
292
397
|
|
|
293
|
-
/**
|
|
398
|
+
/**
|
|
399
|
+
* Get workspace ID synchronously (for modules that need it)
|
|
400
|
+
*/
|
|
401
|
+
private _getWorkspaceIdSync(): string {
|
|
402
|
+
return this._workspaceId ?? "";
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/** Current tenant ID (legacy) */
|
|
294
406
|
get tenantId(): string {
|
|
295
|
-
return this._tenantId;
|
|
407
|
+
return this._tenantId ?? "";
|
|
296
408
|
}
|
|
297
409
|
|
|
298
|
-
/** Current workspace ID */
|
|
410
|
+
/** Current workspace ID (legacy) */
|
|
299
411
|
get workspaceId(): string {
|
|
300
|
-
return this._workspaceId;
|
|
412
|
+
return this._workspaceId ?? "";
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/** Auth provider type */
|
|
416
|
+
get authType(): "api_token" | "jwt" | "legacy" {
|
|
417
|
+
if (!this._auth) return "legacy";
|
|
418
|
+
return this._auth.type;
|
|
301
419
|
}
|
|
302
420
|
|
|
303
421
|
/** Raw HTTP client (use modules instead) */
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth Provider Types for Agent OS SDK
|
|
3
|
+
*
|
|
4
|
+
* Supports two modes:
|
|
5
|
+
* - JWT (browser): Uses Supabase JWT + workspace header
|
|
6
|
+
* - API Token (server): Uses aosk_* token with embedded claims
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Auth Provider Types
|
|
11
|
+
// ============================================================================
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* API Token authentication for server-to-server integrations.
|
|
15
|
+
* Token format: aosk_live_* or aosk_test_*
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const client = new AgentOsClient({
|
|
20
|
+
* baseUrl: "https://api.example.com",
|
|
21
|
+
* auth: { type: "api_token", apiKey: "aosk_live_xxx" }
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export type ApiTokenAuth = {
|
|
26
|
+
type: "api_token"
|
|
27
|
+
/** API key (aosk_*) or function that returns one */
|
|
28
|
+
apiKey: string | (() => string | Promise<string>)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* JWT authentication for browser/frontend clients.
|
|
33
|
+
* Uses Supabase JWT with workspace header.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const client = new AgentOsClient({
|
|
38
|
+
* baseUrl: "https://api.example.com",
|
|
39
|
+
* auth: {
|
|
40
|
+
* type: "jwt",
|
|
41
|
+
* getToken: async () => (await supabase.auth.getSession()).data.session?.access_token,
|
|
42
|
+
* getWorkspaceId: () => localStorage.getItem("agentos.workspaceId")!,
|
|
43
|
+
* }
|
|
44
|
+
* })
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export type JwtAuth = {
|
|
48
|
+
type: "jwt"
|
|
49
|
+
/** Function to get the JWT access token */
|
|
50
|
+
getToken: () => string | Promise<string>
|
|
51
|
+
/** Function to get the current workspace ID */
|
|
52
|
+
getWorkspaceId: () => string | Promise<string>
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Auth provider union type
|
|
57
|
+
*/
|
|
58
|
+
export type AuthProvider = ApiTokenAuth | JwtAuth
|
|
59
|
+
|
|
60
|
+
// ============================================================================
|
|
61
|
+
// Client Options
|
|
62
|
+
// ============================================================================
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* New auth-aware options for AgentOsClient
|
|
66
|
+
*/
|
|
67
|
+
export type AgentOsClientOptions = {
|
|
68
|
+
/** Base URL of the Agent OS Control Plane */
|
|
69
|
+
baseUrl: string
|
|
70
|
+
/** Authentication provider */
|
|
71
|
+
auth: AuthProvider
|
|
72
|
+
/**
|
|
73
|
+
* Allow API token in browser environment.
|
|
74
|
+
* Default: false (throws error to prevent accidental exposure)
|
|
75
|
+
*/
|
|
76
|
+
allowApiTokenInBrowser?: boolean
|
|
77
|
+
/** Custom headers to add to all requests */
|
|
78
|
+
headers?: Record<string, string>
|
|
79
|
+
}
|
|
80
|
+
|
|
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
|
+
// ============================================================================
|
|
101
|
+
// Type Guards
|
|
102
|
+
// ============================================================================
|
|
103
|
+
|
|
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
|
+
export function isApiTokenAuth(auth: AuthProvider): auth is ApiTokenAuth {
|
|
117
|
+
return auth.type === "api_token"
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function isJwtAuth(auth: AuthProvider): auth is JwtAuth {
|
|
121
|
+
return auth.type === "jwt"
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ============================================================================
|
|
125
|
+
// Helpers
|
|
126
|
+
// ============================================================================
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Detect browser environment
|
|
130
|
+
*/
|
|
131
|
+
export function isBrowser(): boolean {
|
|
132
|
+
return typeof window !== "undefined" && typeof document !== "undefined"
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Check if token looks like an API token (aosk_*)
|
|
137
|
+
*/
|
|
138
|
+
export function isApiToken(token: string): boolean {
|
|
139
|
+
return token.startsWith("aosk_")
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Check if token looks like a JWT (three base64 segments)
|
|
144
|
+
*/
|
|
145
|
+
export function isJwtToken(token: string): boolean {
|
|
146
|
+
const parts = token.split(".")
|
|
147
|
+
return parts.length === 3 && parts.every(p => p.length > 0)
|
|
148
|
+
}
|