@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/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,
|