@agent-os-sdk/client 0.1.2 → 0.2.1
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,24 +2,29 @@
|
|
|
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
|
import { type RawClient } from "./raw.js";
|
|
27
|
+
import { type AgentOsClientOptions, type AgentOsClientOptionsLegacy } from "./auth.js";
|
|
23
28
|
import { AgentsModule } from "../modules/agents.js";
|
|
24
29
|
import { RunsModule } from "../modules/runs.js";
|
|
25
30
|
import { ThreadsModule } from "../modules/threads.js";
|
|
@@ -58,28 +63,17 @@ import { BudgetsModule } from "../modules/budgets.js";
|
|
|
58
63
|
import { DeploymentsModule } from "../modules/deployments.js";
|
|
59
64
|
import { IncidentsModule } from "../modules/incidents.js";
|
|
60
65
|
import { ArtifactsModule } from "../modules/artifacts.js";
|
|
61
|
-
export type AgentOsClientOptions
|
|
62
|
-
|
|
63
|
-
baseUrl: string;
|
|
64
|
-
/** Tenant ID (multi-tenant) */
|
|
65
|
-
tenantId: string;
|
|
66
|
-
/** Workspace ID */
|
|
67
|
-
workspaceId: string;
|
|
68
|
-
/** Optional auth token */
|
|
69
|
-
token?: string;
|
|
70
|
-
/** Optional member ID (for identity header) */
|
|
71
|
-
memberId?: string;
|
|
72
|
-
/** Custom headers */
|
|
73
|
-
headers?: Record<string, string>;
|
|
74
|
-
};
|
|
66
|
+
export type { AgentOsClientOptions, AgentOsClientOptionsLegacy, AuthProvider } from "./auth.js";
|
|
67
|
+
export { isApiTokenAuth, isJwtAuth, isNewAuthOptions } from "./auth.js";
|
|
75
68
|
export declare class AgentOsClient {
|
|
76
69
|
private readonly _client;
|
|
77
70
|
private readonly _baseUrl;
|
|
78
|
-
private readonly
|
|
79
|
-
private readonly
|
|
71
|
+
private readonly _auth;
|
|
72
|
+
private readonly _customHeaders;
|
|
73
|
+
private readonly _tenantId?;
|
|
74
|
+
private readonly _workspaceId?;
|
|
80
75
|
private readonly _token?;
|
|
81
76
|
private readonly _memberId?;
|
|
82
|
-
private readonly _customHeaders;
|
|
83
77
|
/** Agents API: CRUD, versions, graph */
|
|
84
78
|
readonly agents: AgentsModule;
|
|
85
79
|
/** Runs API: create, stream, cancel, resume, replay */
|
|
@@ -138,47 +132,48 @@ export declare class AgentOsClient {
|
|
|
138
132
|
readonly metrics: MetricsModule;
|
|
139
133
|
/** Graphs API: Validation and introspection */
|
|
140
134
|
readonly graphs: GraphsModule;
|
|
141
|
-
/** Handoff API: Multi-agent delegation */
|
|
142
135
|
readonly handoff: HandoffModule;
|
|
143
|
-
/** Flows API: Workflow orchestration */
|
|
144
136
|
readonly flows: FlowsModule;
|
|
145
|
-
/** Capabilities API: Agent/run permissions */
|
|
146
137
|
readonly capabilities: CapabilitiesModule;
|
|
147
|
-
/** Policies API: Governance rules */
|
|
148
138
|
readonly policies: PoliciesModule;
|
|
149
|
-
/** Approvals API: Human-in-the-loop */
|
|
150
139
|
readonly approvals: ApprovalsModule;
|
|
151
|
-
/** Budgets API: Cost control */
|
|
152
140
|
readonly budgets: BudgetsModule;
|
|
153
|
-
/** Deployments API: Release management */
|
|
154
141
|
readonly deployments: DeploymentsModule;
|
|
155
|
-
/** Incidents API: Operational incidents & SLOs */
|
|
156
142
|
readonly incidents: IncidentsModule;
|
|
157
|
-
/** Artifacts API: Output management */
|
|
158
143
|
readonly artifacts: ArtifactsModule;
|
|
159
|
-
/**
|
|
160
|
-
* Alias for evaluation.listExperiments() - provides first-level access to experiments
|
|
161
|
-
* @example client.experiments.list() // same as client.evaluation.listExperiments()
|
|
162
|
-
*/
|
|
163
144
|
readonly experiments: {
|
|
164
145
|
list: EvaluationModule["listExperiments"];
|
|
165
146
|
get: EvaluationModule["getExperiment"];
|
|
166
147
|
create: EvaluationModule["createExperiment"];
|
|
167
148
|
};
|
|
168
|
-
/**
|
|
169
|
-
* Alias for agents.listVersions() - provides first-level access to agent versions
|
|
170
|
-
*/
|
|
171
149
|
readonly agentVersions: {
|
|
172
150
|
list: (agentId: string) => ReturnType<AgentsModule["listVersions"]>;
|
|
173
151
|
get: (agentId: string, versionId: string) => ReturnType<AgentsModule["getVersion"]>;
|
|
174
152
|
create: (agentId: string, body: Parameters<AgentsModule["createVersion"]>[1]) => ReturnType<AgentsModule["createVersion"]>;
|
|
175
153
|
};
|
|
176
|
-
constructor(options: AgentOsClientOptions);
|
|
154
|
+
constructor(options: AgentOsClientOptions | AgentOsClientOptionsLegacy);
|
|
155
|
+
/**
|
|
156
|
+
* Validate auth configuration
|
|
157
|
+
*/
|
|
158
|
+
private _validateAuth;
|
|
159
|
+
/**
|
|
160
|
+
* Get headers for current request (sync version for modules)
|
|
161
|
+
*/
|
|
177
162
|
private _getHeaders;
|
|
178
|
-
/**
|
|
163
|
+
/**
|
|
164
|
+
* Get headers for current request (async version - resolves auth functions)
|
|
165
|
+
*/
|
|
166
|
+
getHeadersAsync(): Promise<Record<string, string>>;
|
|
167
|
+
/**
|
|
168
|
+
* Get workspace ID synchronously (for modules that need it)
|
|
169
|
+
*/
|
|
170
|
+
private _getWorkspaceIdSync;
|
|
171
|
+
/** Current tenant ID (legacy) */
|
|
179
172
|
get tenantId(): string;
|
|
180
|
-
/** Current workspace ID */
|
|
173
|
+
/** Current workspace ID (legacy) */
|
|
181
174
|
get workspaceId(): string;
|
|
175
|
+
/** Auth provider type */
|
|
176
|
+
get authType(): "api_token" | "jwt" | "legacy";
|
|
182
177
|
/** Raw HTTP client (use modules instead) */
|
|
183
178
|
get raw(): RawClient;
|
|
184
179
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentOsClient.d.ts","sourceRoot":"","sources":["../../src/client/AgentOsClient.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"AgentOsClient.d.ts","sourceRoot":"","sources":["../../src/client/AgentOsClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EACH,KAAK,oBAAoB,EACzB,KAAK,0BAA0B,EAOlC,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,YAAY,EAAE,MAAM,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AAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,UAAU,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC;QACpF,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC;KAC9H,CAAC;gBAEU,OAAO,EAAE,oBAAoB,GAAG,0BAA0B;IAmGtE;;OAEG;IACH,OAAO,CAAC,aAAa;IAarB;;OAEG;IACH,OAAO,CAAC,WAAW;IA0CnB;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAmDxD;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAI3B,iCAAiC;IACjC,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,oCAAoC;IACpC,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,yBAAyB;IACzB,IAAI,QAAQ,IAAI,WAAW,GAAG,KAAK,GAAG,QAAQ,CAG7C;IAED,4CAA4C;IAC5C,IAAI,GAAG,IAAI,SAAS,CAEnB;CACJ"}
|
|
@@ -2,24 +2,29 @@
|
|
|
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
|
import { createRawClient } from "./raw.js";
|
|
27
|
+
import { isNewAuthOptions, isApiTokenAuth, isJwtAuth, isApiToken, isBrowser, } from "./auth.js";
|
|
23
28
|
import { AgentsModule } from "../modules/agents.js";
|
|
24
29
|
import { RunsModule } from "../modules/runs.js";
|
|
25
30
|
import { ThreadsModule } from "../modules/threads.js";
|
|
@@ -60,14 +65,17 @@ import { BudgetsModule } from "../modules/budgets.js";
|
|
|
60
65
|
import { DeploymentsModule } from "../modules/deployments.js";
|
|
61
66
|
import { IncidentsModule } from "../modules/incidents.js";
|
|
62
67
|
import { ArtifactsModule } from "../modules/artifacts.js";
|
|
68
|
+
export { isApiTokenAuth, isJwtAuth, isNewAuthOptions } from "./auth.js";
|
|
63
69
|
export class AgentOsClient {
|
|
64
70
|
_client;
|
|
65
71
|
_baseUrl;
|
|
72
|
+
_auth;
|
|
73
|
+
_customHeaders;
|
|
74
|
+
// Legacy fields (for backwards compat)
|
|
66
75
|
_tenantId;
|
|
67
76
|
_workspaceId;
|
|
68
77
|
_token;
|
|
69
78
|
_memberId;
|
|
70
|
-
_customHeaders;
|
|
71
79
|
// Core modules
|
|
72
80
|
/** Agents API: CRUD, versions, graph */
|
|
73
81
|
agents;
|
|
@@ -128,49 +136,55 @@ export class AgentOsClient {
|
|
|
128
136
|
metrics;
|
|
129
137
|
/** Graphs API: Validation and introspection */
|
|
130
138
|
graphs;
|
|
131
|
-
// MOCK - Future modules
|
|
132
|
-
/** Handoff API: Multi-agent delegation */
|
|
139
|
+
// MOCK - Future modules
|
|
133
140
|
handoff;
|
|
134
|
-
/** Flows API: Workflow orchestration */
|
|
135
141
|
flows;
|
|
136
|
-
/** Capabilities API: Agent/run permissions */
|
|
137
142
|
capabilities;
|
|
138
|
-
/** Policies API: Governance rules */
|
|
139
143
|
policies;
|
|
140
|
-
/** Approvals API: Human-in-the-loop */
|
|
141
144
|
approvals;
|
|
142
|
-
/** Budgets API: Cost control */
|
|
143
145
|
budgets;
|
|
144
|
-
/** Deployments API: Release management */
|
|
145
146
|
deployments;
|
|
146
|
-
/** Incidents API: Operational incidents & SLOs */
|
|
147
147
|
incidents;
|
|
148
|
-
/** Artifacts API: Output management */
|
|
149
148
|
artifacts;
|
|
150
|
-
//
|
|
151
|
-
/**
|
|
152
|
-
* Alias for evaluation.listExperiments() - provides first-level access to experiments
|
|
153
|
-
* @example client.experiments.list() // same as client.evaluation.listExperiments()
|
|
154
|
-
*/
|
|
149
|
+
// Convenience Aliases
|
|
155
150
|
experiments;
|
|
156
|
-
/**
|
|
157
|
-
* Alias for agents.listVersions() - provides first-level access to agent versions
|
|
158
|
-
*/
|
|
159
151
|
agentVersions;
|
|
160
152
|
constructor(options) {
|
|
161
153
|
this._baseUrl = options.baseUrl;
|
|
162
|
-
this._tenantId = options.tenantId;
|
|
163
|
-
this._workspaceId = options.workspaceId;
|
|
164
|
-
this._token = options.token;
|
|
165
|
-
this._memberId = options.memberId;
|
|
166
154
|
this._customHeaders = options.headers ?? {};
|
|
155
|
+
// Detect auth mode
|
|
156
|
+
if (isNewAuthOptions(options)) {
|
|
157
|
+
// New auth provider mode
|
|
158
|
+
this._auth = options.auth;
|
|
159
|
+
this._validateAuth(options);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
// Legacy mode - convert to new auth if possible
|
|
163
|
+
this._tenantId = options.tenantId;
|
|
164
|
+
this._workspaceId = options.workspaceId;
|
|
165
|
+
this._token = options.token;
|
|
166
|
+
this._memberId = options.memberId;
|
|
167
|
+
// Attempt to detect auth type from token
|
|
168
|
+
if (options.token && isApiToken(options.token)) {
|
|
169
|
+
// Token looks like API token - use as api_token
|
|
170
|
+
this._auth = { type: "api_token", apiKey: options.token };
|
|
171
|
+
console.warn("[AgentOS SDK] Using legacy options with API token. " +
|
|
172
|
+
"Consider migrating to: new AgentOsClient({ auth: { type: 'api_token', apiKey: '...' } })");
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
// Legacy JWT mode - keep using headers
|
|
176
|
+
this._auth = null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// Create raw HTTP client
|
|
167
180
|
this._client = createRawClient({
|
|
168
181
|
baseUrl: options.baseUrl,
|
|
169
|
-
headers:
|
|
182
|
+
headers: {}, // Headers resolved dynamically
|
|
170
183
|
});
|
|
184
|
+
// Bound header getter
|
|
171
185
|
const getHeaders = () => this._getHeaders();
|
|
172
|
-
const getWorkspaceId = () => this.
|
|
173
|
-
const getTenantId = () => this._tenantId;
|
|
186
|
+
const getWorkspaceId = () => this._getWorkspaceIdSync();
|
|
187
|
+
const getTenantId = () => this._tenantId ?? "";
|
|
174
188
|
// Initialize core modules
|
|
175
189
|
this.agents = new AgentsModule(this._client, getHeaders);
|
|
176
190
|
this.runs = new RunsModule(this._client, this._baseUrl, getHeaders);
|
|
@@ -224,28 +238,132 @@ export class AgentOsClient {
|
|
|
224
238
|
create: (agentId, body) => this.agents.createVersion(agentId, body),
|
|
225
239
|
};
|
|
226
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Validate auth configuration
|
|
243
|
+
*/
|
|
244
|
+
_validateAuth(options) {
|
|
245
|
+
const { auth, allowApiTokenInBrowser } = options;
|
|
246
|
+
// Browser guard for API tokens
|
|
247
|
+
if (isApiTokenAuth(auth) && isBrowser() && !allowApiTokenInBrowser) {
|
|
248
|
+
throw new Error("[AgentOS SDK] API tokens should not be used in the browser. " +
|
|
249
|
+
"They may be exposed in network requests. " +
|
|
250
|
+
"Use JWT auth for browser clients, or set allowApiTokenInBrowser: true if you understand the risks.");
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Get headers for current request (sync version for modules)
|
|
255
|
+
*/
|
|
227
256
|
_getHeaders() {
|
|
228
257
|
const headers = {
|
|
229
258
|
"Content-Type": "application/json",
|
|
230
|
-
"X-Tenant-Id": this._tenantId,
|
|
231
|
-
"X-Workspace-Id": this._workspaceId,
|
|
232
259
|
...this._customHeaders,
|
|
233
260
|
};
|
|
234
|
-
if (this.
|
|
235
|
-
|
|
261
|
+
if (this._auth) {
|
|
262
|
+
// New auth mode
|
|
263
|
+
if (isApiTokenAuth(this._auth)) {
|
|
264
|
+
// API Token: Only Authorization header
|
|
265
|
+
const apiKey = typeof this._auth.apiKey === "function"
|
|
266
|
+
? "" // Will be resolved async
|
|
267
|
+
: this._auth.apiKey;
|
|
268
|
+
if (apiKey) {
|
|
269
|
+
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
270
|
+
}
|
|
271
|
+
// NO X-Tenant-Id, NO X-Workspace-Id (backend resolves from claims)
|
|
272
|
+
}
|
|
273
|
+
else if (isJwtAuth(this._auth)) {
|
|
274
|
+
// JWT: Authorization + X-Workspace-Id
|
|
275
|
+
// Note: For sync header getter, we use empty strings as placeholders
|
|
276
|
+
// The actual values are resolved in _getHeadersAsync
|
|
277
|
+
// This is a limitation of the current module architecture
|
|
278
|
+
}
|
|
236
279
|
}
|
|
237
|
-
|
|
238
|
-
|
|
280
|
+
else {
|
|
281
|
+
// Legacy mode - use stored values
|
|
282
|
+
if (this._token) {
|
|
283
|
+
headers["Authorization"] = `Bearer ${this._token}`;
|
|
284
|
+
}
|
|
285
|
+
if (this._tenantId) {
|
|
286
|
+
headers["X-Tenant-Id"] = this._tenantId;
|
|
287
|
+
}
|
|
288
|
+
if (this._workspaceId) {
|
|
289
|
+
headers["X-Workspace-Id"] = this._workspaceId;
|
|
290
|
+
}
|
|
291
|
+
if (this._memberId) {
|
|
292
|
+
headers["X-Member-Id"] = this._memberId;
|
|
293
|
+
}
|
|
239
294
|
}
|
|
240
295
|
return headers;
|
|
241
296
|
}
|
|
242
|
-
/**
|
|
297
|
+
/**
|
|
298
|
+
* Get headers for current request (async version - resolves auth functions)
|
|
299
|
+
*/
|
|
300
|
+
async getHeadersAsync() {
|
|
301
|
+
const headers = {
|
|
302
|
+
"Content-Type": "application/json",
|
|
303
|
+
...this._customHeaders,
|
|
304
|
+
};
|
|
305
|
+
if (this._auth) {
|
|
306
|
+
if (isApiTokenAuth(this._auth)) {
|
|
307
|
+
// API Token
|
|
308
|
+
const apiKey = typeof this._auth.apiKey === "function"
|
|
309
|
+
? await this._auth.apiKey()
|
|
310
|
+
: this._auth.apiKey;
|
|
311
|
+
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
312
|
+
// NO X-Tenant-Id, NO X-Workspace-Id
|
|
313
|
+
}
|
|
314
|
+
else if (isJwtAuth(this._auth)) {
|
|
315
|
+
// JWT
|
|
316
|
+
const [token, workspaceId] = await Promise.all([
|
|
317
|
+
this._auth.getToken(),
|
|
318
|
+
this._auth.getWorkspaceId(),
|
|
319
|
+
]);
|
|
320
|
+
if (!token) {
|
|
321
|
+
throw new Error("[AgentOS SDK] JWT token not available. User may not be authenticated.");
|
|
322
|
+
}
|
|
323
|
+
if (!workspaceId) {
|
|
324
|
+
throw new Error("[AgentOS SDK] Workspace ID not available. Please select a workspace first.");
|
|
325
|
+
}
|
|
326
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
327
|
+
headers["X-Workspace-Id"] = workspaceId;
|
|
328
|
+
// NO X-Tenant-Id (backend derives from workspace membership)
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
// Legacy mode
|
|
333
|
+
if (this._token) {
|
|
334
|
+
headers["Authorization"] = `Bearer ${this._token}`;
|
|
335
|
+
}
|
|
336
|
+
if (this._tenantId) {
|
|
337
|
+
headers["X-Tenant-Id"] = this._tenantId;
|
|
338
|
+
}
|
|
339
|
+
if (this._workspaceId) {
|
|
340
|
+
headers["X-Workspace-Id"] = this._workspaceId;
|
|
341
|
+
}
|
|
342
|
+
if (this._memberId) {
|
|
343
|
+
headers["X-Member-Id"] = this._memberId;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return headers;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Get workspace ID synchronously (for modules that need it)
|
|
350
|
+
*/
|
|
351
|
+
_getWorkspaceIdSync() {
|
|
352
|
+
return this._workspaceId ?? "";
|
|
353
|
+
}
|
|
354
|
+
/** Current tenant ID (legacy) */
|
|
243
355
|
get tenantId() {
|
|
244
|
-
return this._tenantId;
|
|
356
|
+
return this._tenantId ?? "";
|
|
245
357
|
}
|
|
246
|
-
/** Current workspace ID */
|
|
358
|
+
/** Current workspace ID (legacy) */
|
|
247
359
|
get workspaceId() {
|
|
248
|
-
return this._workspaceId;
|
|
360
|
+
return this._workspaceId ?? "";
|
|
361
|
+
}
|
|
362
|
+
/** Auth provider type */
|
|
363
|
+
get authType() {
|
|
364
|
+
if (!this._auth)
|
|
365
|
+
return "legacy";
|
|
366
|
+
return this._auth.type;
|
|
249
367
|
}
|
|
250
368
|
/** Raw HTTP client (use modules instead) */
|
|
251
369
|
get raw() {
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
* API Token authentication for server-to-server integrations.
|
|
10
|
+
* Token format: aosk_live_* or aosk_test_*
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const client = new AgentOsClient({
|
|
15
|
+
* baseUrl: "https://api.example.com",
|
|
16
|
+
* auth: { type: "api_token", apiKey: "aosk_live_xxx" }
|
|
17
|
+
* })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export type ApiTokenAuth = {
|
|
21
|
+
type: "api_token";
|
|
22
|
+
/** API key (aosk_*) or function that returns one */
|
|
23
|
+
apiKey: string | (() => string | Promise<string>);
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* JWT authentication for browser/frontend clients.
|
|
27
|
+
* Uses Supabase JWT with workspace header.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const client = new AgentOsClient({
|
|
32
|
+
* baseUrl: "https://api.example.com",
|
|
33
|
+
* auth: {
|
|
34
|
+
* type: "jwt",
|
|
35
|
+
* getToken: async () => (await supabase.auth.getSession()).data.session?.access_token,
|
|
36
|
+
* getWorkspaceId: () => localStorage.getItem("agentos.workspaceId")!,
|
|
37
|
+
* }
|
|
38
|
+
* })
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export type JwtAuth = {
|
|
42
|
+
type: "jwt";
|
|
43
|
+
/** Function to get the JWT access token */
|
|
44
|
+
getToken: () => string | Promise<string>;
|
|
45
|
+
/** Function to get the current workspace ID */
|
|
46
|
+
getWorkspaceId: () => string | Promise<string>;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Auth provider union type
|
|
50
|
+
*/
|
|
51
|
+
export type AuthProvider = ApiTokenAuth | JwtAuth;
|
|
52
|
+
/**
|
|
53
|
+
* New auth-aware options for AgentOsClient
|
|
54
|
+
*/
|
|
55
|
+
export type AgentOsClientOptions = {
|
|
56
|
+
/** Base URL of the Agent OS Control Plane */
|
|
57
|
+
baseUrl: string;
|
|
58
|
+
/** Authentication provider */
|
|
59
|
+
auth: AuthProvider;
|
|
60
|
+
/**
|
|
61
|
+
* Allow API token in browser environment.
|
|
62
|
+
* Default: false (throws error to prevent accidental exposure)
|
|
63
|
+
*/
|
|
64
|
+
allowApiTokenInBrowser?: boolean;
|
|
65
|
+
/** Custom headers to add to all requests */
|
|
66
|
+
headers?: Record<string, string>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Legacy options (backwards compatibility)
|
|
70
|
+
* @deprecated Use AgentOsClientOptions with auth provider instead
|
|
71
|
+
*/
|
|
72
|
+
export type AgentOsClientOptionsLegacy = {
|
|
73
|
+
/** Base URL of the Agent OS API */
|
|
74
|
+
baseUrl: string;
|
|
75
|
+
/** Tenant ID @deprecated */
|
|
76
|
+
tenantId: string;
|
|
77
|
+
/** Workspace ID @deprecated */
|
|
78
|
+
workspaceId: string;
|
|
79
|
+
/** Auth token @deprecated */
|
|
80
|
+
token?: string;
|
|
81
|
+
/** Member ID @deprecated */
|
|
82
|
+
memberId?: string;
|
|
83
|
+
/** Custom headers */
|
|
84
|
+
headers?: Record<string, string>;
|
|
85
|
+
};
|
|
86
|
+
export declare function isNewAuthOptions(opts: AgentOsClientOptions | AgentOsClientOptionsLegacy): opts is AgentOsClientOptions;
|
|
87
|
+
export declare function isLegacyOptions(opts: AgentOsClientOptions | AgentOsClientOptionsLegacy): opts is AgentOsClientOptionsLegacy;
|
|
88
|
+
export declare function isApiTokenAuth(auth: AuthProvider): auth is ApiTokenAuth;
|
|
89
|
+
export declare function isJwtAuth(auth: AuthProvider): auth is JwtAuth;
|
|
90
|
+
/**
|
|
91
|
+
* Detect browser environment
|
|
92
|
+
*/
|
|
93
|
+
export declare function isBrowser(): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Check if token looks like an API token (aosk_*)
|
|
96
|
+
*/
|
|
97
|
+
export declare function isApiToken(token: string): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Check if token looks like a JWT (three base64 segments)
|
|
100
|
+
*/
|
|
101
|
+
export declare function isJwtToken(token: string): boolean;
|
|
102
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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M,CAAC,CAAA;CACnC,CAAA;AAMD,wBAAgB,gBAAgB,CAC5B,IAAI,EAAE,oBAAoB,GAAG,0BAA0B,GACxD,IAAI,IAAI,oBAAoB,CAE9B;AAED,wBAAgB,eAAe,CAC3B,IAAI,EAAE,oBAAoB,GAAG,0BAA0B,GACxD,IAAI,IAAI,0BAA0B,CAEpC;AAED,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"}
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
// Type Guards
|
|
10
|
+
// ============================================================================
|
|
11
|
+
export function isNewAuthOptions(opts) {
|
|
12
|
+
return "auth" in opts && opts.auth !== undefined;
|
|
13
|
+
}
|
|
14
|
+
export function isLegacyOptions(opts) {
|
|
15
|
+
return "tenantId" in opts || "workspaceId" in opts;
|
|
16
|
+
}
|
|
17
|
+
export function isApiTokenAuth(auth) {
|
|
18
|
+
return auth.type === "api_token";
|
|
19
|
+
}
|
|
20
|
+
export function isJwtAuth(auth) {
|
|
21
|
+
return auth.type === "jwt";
|
|
22
|
+
}
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// Helpers
|
|
25
|
+
// ============================================================================
|
|
26
|
+
/**
|
|
27
|
+
* Detect browser environment
|
|
28
|
+
*/
|
|
29
|
+
export function isBrowser() {
|
|
30
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if token looks like an API token (aosk_*)
|
|
34
|
+
*/
|
|
35
|
+
export function isApiToken(token) {
|
|
36
|
+
return token.startsWith("aosk_");
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if token looks like a JWT (three base64 segments)
|
|
40
|
+
*/
|
|
41
|
+
export function isJwtToken(token) {
|
|
42
|
+
const parts = token.split(".");
|
|
43
|
+
return parts.length === 3 && parts.every(p => p.length > 0);
|
|
44
|
+
}
|