@agent-os-sdk/client 0.2.3 → 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 +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- 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 +1 -2
package/dist/client/raw.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raw.d.ts","sourceRoot":"","sources":["../../src/client/raw.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAqB,EAAE,KAAK,MAAM,EAAqB,MAAM,eAAe,CAAC;AAC7E,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGjE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;AAElC,MAAM,MAAM,aAAa,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"raw.d.ts","sourceRoot":"","sources":["../../src/client/raw.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAqB,EAAE,KAAK,MAAM,EAAqB,MAAM,eAAe,CAAC;AAC7E,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGjE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE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ypedClient(options) {
|
|
|
20
20
|
* Wraps openapi-fetch to provide the old interface while maintaining types.
|
|
21
21
|
*/
|
|
22
22
|
export function createRawClient(options) {
|
|
23
|
-
const { baseUrl, headers: defaultHeaders = {} } = options;
|
|
23
|
+
const { baseUrl, headers: defaultHeaders = {}, headerProvider } = options;
|
|
24
24
|
async function request(method, path, opts) {
|
|
25
25
|
// Replace path params
|
|
26
26
|
let url = path;
|
|
@@ -45,8 +45,11 @@ export function createRawClient(options) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
const fullUrl = `${baseUrl}${url}`;
|
|
48
|
+
// Resolve dynamic headers (e.g. auth)
|
|
49
|
+
const dynamicHeaders = headerProvider ? await headerProvider() : {};
|
|
48
50
|
const headers = {
|
|
49
51
|
...defaultHeaders,
|
|
52
|
+
...dynamicHeaders,
|
|
50
53
|
...opts?.headers,
|
|
51
54
|
};
|
|
52
55
|
if (opts?.body) {
|
package/dist/index.d.ts
CHANGED
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
* }
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
|
-
export { AgentOsClient, type AgentOsClientOptions, type
|
|
38
|
-
export { type ApiTokenAuth, type JwtAuth, isApiTokenAuth, isJwtAuth,
|
|
37
|
+
export { AgentOsClient, type AgentOsClientOptions, type AuthProvider } from "./client/AgentOsClient.js";
|
|
38
|
+
export { type ApiTokenAuth, type JwtAuth, isApiTokenAuth, isJwtAuth, isBrowser, isApiToken, isJwtToken, } from "./client/auth.js";
|
|
39
39
|
export { unwrap, toResult, SDKError, type PaginationParams, type PaginatedResponse, type Result, type Unwrapped, } from "./client/helpers.js";
|
|
40
40
|
export { createRawClient, createTypedClient, type RawClient, type TypedClient, type ClientOptions, type APIResponse, } from "./client/raw.js";
|
|
41
41
|
export type { paths, components } from "./client/raw.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../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KAAK,QAAQ,EAAE,KAAK,gBAAgB,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC/J,OAAO,EAAE,eAAe,EAAE,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAKnH,OAAO,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAKjG,YAAY,EAER,KAAK,IAAI,WAAW,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,yBAAyB,EAEzB,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EAEb,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EAEjB,gBAAgB,EAChB,sBAAsB,EAEtB,uBAAuB,EACvB,uBAAuB,EAEvB,oBAAoB,EACpB,oBAAoB,EAEpB,mBAAmB,EACnB,mBAAmB,EAEnB,mBAAmB,EACnB,0BAA0B,EAE1B,4BAA4B,EAC5B,uBAAuB,EAEvB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EAEnB,oBAAoB,EACpB,uBAAuB,EAEvB,cAAc,GACjB,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
// ============================================================================
|
|
40
40
|
export { AgentOsClient } from "./client/AgentOsClient.js";
|
|
41
41
|
// Auth Provider Types
|
|
42
|
-
export { isApiTokenAuth, isJwtAuth,
|
|
42
|
+
export { isApiTokenAuth, isJwtAuth, isBrowser, isApiToken, isJwtToken, } from "./client/auth.js";
|
|
43
43
|
// ============================================================================
|
|
44
44
|
// Helpers & Utilities
|
|
45
45
|
// ============================================================================
|
package/package.json
CHANGED
|
@@ -1,50 +1,51 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
2
|
+
"name": "@agent-os-sdk/client",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Official TypeScript SDK for Agent OS platform",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"agent-os",
|
|
17
|
+
"sdk",
|
|
18
|
+
"ai",
|
|
19
|
+
"agents",
|
|
20
|
+
"typescript"
|
|
21
|
+
],
|
|
22
|
+
"author": "Agent OS Team",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/yuri12344/agent-os.git"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"openapi-fetch": "^0.13.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"openapi-typescript": "^7.4.0",
|
|
36
|
+
"tsx": "^4.19.0",
|
|
37
|
+
"typescript": "^5.5.0",
|
|
38
|
+
"vitest": "^4.0.18"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"src"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"generate": "tsx scripts/generate.ts",
|
|
46
|
+
"build": "tsc",
|
|
47
|
+
"dev": "tsc --watch",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"typecheck": "tsc --noEmit"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -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
|
|