@agent-os-sdk/client 0.9.26 → 0.9.28
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 +141 -0
- package/dist/client/AgentOsClient.d.ts.map +1 -0
- package/{src/client/AgentOsClient.ts → dist/client/AgentOsClient.js} +61 -105
- package/dist/client/HttpRequestBuilder.d.ts +50 -0
- package/dist/client/HttpRequestBuilder.d.ts.map +1 -0
- package/{src/client/HttpRequestBuilder.ts → dist/client/HttpRequestBuilder.js} +9 -41
- package/{src/client/OperationContext.ts → dist/client/OperationContext.d.ts} +6 -9
- package/dist/client/OperationContext.d.ts.map +1 -0
- package/dist/client/OperationContext.js +13 -0
- package/dist/client/OperationContextProvider.d.ts +54 -0
- package/dist/client/OperationContextProvider.d.ts.map +1 -0
- package/{src/client/OperationContextProvider.ts → dist/client/OperationContextProvider.js} +17 -35
- package/{src/client/auth.ts → dist/client/auth.d.ts} +29 -65
- package/dist/client/auth.d.ts.map +1 -0
- package/dist/client/auth.js +38 -0
- package/dist/client/config.d.ts +49 -0
- package/dist/client/config.d.ts.map +1 -0
- package/{src/client/config.ts → dist/client/config.js} +5 -43
- package/dist/client/helpers.d.ts +63 -0
- package/dist/client/helpers.d.ts.map +1 -0
- package/{src/client/helpers.ts → dist/client/helpers.js} +9 -52
- package/dist/client/pagination.d.ts +105 -0
- package/dist/client/pagination.d.ts.map +1 -0
- package/{src/client/pagination.ts → dist/client/pagination.js} +15 -116
- package/dist/client/raw.d.ts +277 -0
- package/dist/client/raw.d.ts.map +1 -0
- package/dist/client/raw.js +337 -0
- package/dist/client/retry.d.ts +37 -0
- package/dist/client/retry.d.ts.map +1 -0
- package/{src/client/retry.ts → dist/client/retry.js} +13 -55
- package/dist/client/sanitize.d.ts +19 -0
- package/dist/client/sanitize.d.ts.map +1 -0
- package/{src/client/sanitize.ts → dist/client/sanitize.js} +4 -7
- package/dist/client/timeout.d.ts +26 -0
- package/dist/client/timeout.d.ts.map +1 -0
- package/{src/client/timeout.ts → dist/client/timeout.js} +10 -18
- package/dist/errors/factory.d.ts +22 -0
- package/dist/errors/factory.d.ts.map +1 -0
- package/{src/errors/factory.ts → dist/errors/factory.js} +18 -57
- package/dist/errors/index.d.ts +210 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/{src/errors/index.ts → dist/errors/index.js} +74 -156
- package/{src/generated/client.ts → dist/generated/client.d.ts} +5 -17
- package/dist/generated/client.d.ts.map +1 -0
- package/dist/generated/client.js +15 -0
- package/{src/generated/index.ts → dist/generated/index.d.ts} +1 -1
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +1 -0
- package/{src/generated/openapi.ts → dist/generated/openapi.d.ts} +1 -1
- package/dist/generated/openapi.d.ts.map +1 -0
- package/dist/generated/openapi.js +5 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.d.ts.map +1 -0
- package/{src/index.ts → dist/index.js} +13 -63
- package/dist/modules/a2a.d.ts +48 -0
- package/dist/modules/a2a.d.ts.map +1 -0
- package/dist/modules/a2a.js +37 -0
- package/dist/modules/agents.d.ts +346 -0
- package/dist/modules/agents.d.ts.map +1 -0
- package/dist/modules/agents.js +296 -0
- package/dist/modules/apiTokens.d.ts +62 -0
- package/dist/modules/apiTokens.d.ts.map +1 -0
- package/dist/modules/apiTokens.js +56 -0
- package/dist/modules/approvals.d.ts +77 -0
- package/dist/modules/approvals.d.ts.map +1 -0
- package/dist/modules/approvals.js +91 -0
- package/dist/modules/audit.d.ts +78 -0
- package/dist/modules/audit.d.ts.map +1 -0
- package/{src/modules/audit.ts → dist/modules/audit.js} +23 -74
- package/{src/modules/auth.ts → dist/modules/auth.d.ts} +6 -11
- package/dist/modules/auth.d.ts.map +1 -0
- package/dist/modules/auth.js +22 -0
- package/dist/modules/builder.d.ts +242 -0
- package/dist/modules/builder.d.ts.map +1 -0
- package/dist/modules/builder.js +248 -0
- package/dist/modules/catalog.d.ts +142 -0
- package/dist/modules/catalog.d.ts.map +1 -0
- package/dist/modules/catalog.js +136 -0
- package/dist/modules/chatwoot.d.ts +59 -0
- package/dist/modules/chatwoot.d.ts.map +1 -0
- package/dist/modules/chatwoot.js +200 -0
- package/dist/modules/checkpoints.d.ts +62 -0
- package/dist/modules/checkpoints.d.ts.map +1 -0
- package/dist/modules/checkpoints.js +48 -0
- package/dist/modules/contracts.d.ts +48 -0
- package/dist/modules/contracts.d.ts.map +1 -0
- package/dist/modules/contracts.js +25 -0
- package/dist/modules/credentials.d.ts +105 -0
- package/dist/modules/credentials.d.ts.map +1 -0
- package/dist/modules/credentials.js +135 -0
- package/dist/modules/crons.d.ts +73 -0
- package/dist/modules/crons.d.ts.map +1 -0
- package/dist/modules/crons.js +67 -0
- package/dist/modules/datasets.d.ts +80 -0
- package/dist/modules/datasets.d.ts.map +1 -0
- package/dist/modules/datasets.js +91 -0
- package/{src/modules/evaluation.ts → dist/modules/evaluation.d.ts} +23 -109
- package/dist/modules/evaluation.d.ts.map +1 -0
- package/dist/modules/evaluation.js +108 -0
- package/dist/modules/files.d.ts +89 -0
- package/dist/modules/files.d.ts.map +1 -0
- package/dist/modules/files.js +133 -0
- package/dist/modules/graphs.d.ts +120 -0
- package/dist/modules/graphs.d.ts.map +1 -0
- package/dist/modules/graphs.js +69 -0
- package/{src/modules/improvements.ts → dist/modules/improvements.d.ts} +8 -27
- package/dist/modules/improvements.d.ts.map +1 -0
- package/dist/modules/improvements.js +27 -0
- package/dist/modules/info.d.ts +76 -0
- package/dist/modules/info.d.ts.map +1 -0
- package/{src/modules/info.ts → dist/modules/info.js} +16 -66
- package/dist/modules/knowledge.d.ts +91 -0
- package/dist/modules/knowledge.d.ts.map +1 -0
- package/dist/modules/knowledge.js +80 -0
- package/{src/modules/me.ts → dist/modules/me.d.ts} +7 -23
- package/dist/modules/me.d.ts.map +1 -0
- package/dist/modules/me.js +28 -0
- package/dist/modules/members.d.ts +124 -0
- package/dist/modules/members.d.ts.map +1 -0
- package/dist/modules/members.js +142 -0
- package/dist/modules/memberships.d.ts +25 -0
- package/dist/modules/memberships.d.ts.map +1 -0
- package/dist/modules/memberships.js +20 -0
- package/{src/modules/metaAgent.ts → dist/modules/metaAgent.d.ts} +8 -44
- package/dist/modules/metaAgent.d.ts.map +1 -0
- package/dist/modules/metaAgent.js +32 -0
- package/dist/modules/metrics.d.ts +20 -0
- package/dist/modules/metrics.d.ts.map +1 -0
- package/{src/modules/metrics.ts → dist/modules/metrics.js} +7 -14
- package/dist/modules/observability.d.ts +19 -0
- package/dist/modules/observability.d.ts.map +1 -0
- package/dist/modules/observability.js +14 -0
- package/dist/modules/playground.d.ts +42 -0
- package/dist/modules/playground.d.ts.map +1 -0
- package/dist/modules/playground.js +48 -0
- package/dist/modules/presets.d.ts +32 -0
- package/dist/modules/presets.d.ts.map +1 -0
- package/dist/modules/presets.js +199 -0
- package/dist/modules/prompts.d.ts +87 -0
- package/dist/modules/prompts.d.ts.map +1 -0
- package/dist/modules/prompts.js +87 -0
- package/dist/modules/roles.d.ts +64 -0
- package/dist/modules/roles.d.ts.map +1 -0
- package/dist/modules/roles.js +79 -0
- package/dist/modules/runs.d.ts +451 -0
- package/dist/modules/runs.d.ts.map +1 -0
- package/{src/modules/runs.ts → dist/modules/runs.js} +96 -438
- package/dist/modules/store.d.ts +37 -0
- package/dist/modules/store.d.ts.map +1 -0
- package/dist/modules/store.js +48 -0
- package/{src/modules/templates.ts → dist/modules/templates.d.ts} +8 -32
- package/dist/modules/templates.d.ts.map +1 -0
- package/dist/modules/templates.js +26 -0
- package/dist/modules/tenants.d.ts +49 -0
- package/dist/modules/tenants.d.ts.map +1 -0
- package/dist/modules/tenants.js +56 -0
- package/dist/modules/threads.d.ts +205 -0
- package/dist/modules/threads.d.ts.map +1 -0
- package/dist/modules/threads.js +225 -0
- package/dist/modules/tools.d.ts +62 -0
- package/dist/modules/tools.d.ts.map +1 -0
- package/dist/modules/tools.js +45 -0
- package/dist/modules/traces.d.ts +89 -0
- package/dist/modules/traces.d.ts.map +1 -0
- package/dist/modules/traces.js +65 -0
- package/{src/modules/triggers.ts → dist/modules/triggers.d.ts} +24 -153
- package/dist/modules/triggers.d.ts.map +1 -0
- package/dist/modules/triggers.js +176 -0
- package/{src/modules/usage.ts → dist/modules/usage.d.ts} +14 -46
- package/dist/modules/usage.d.ts.map +1 -0
- package/dist/modules/usage.js +43 -0
- package/dist/modules/vectorStores.d.ts +100 -0
- package/dist/modules/vectorStores.d.ts.map +1 -0
- package/dist/modules/vectorStores.js +159 -0
- package/dist/modules/workspaces.d.ts +138 -0
- package/dist/modules/workspaces.d.ts.map +1 -0
- package/dist/modules/workspaces.js +121 -0
- package/dist/sse/client.d.ts +140 -0
- package/dist/sse/client.d.ts.map +1 -0
- package/{src/sse/client.ts → dist/sse/client.js} +24 -100
- package/package.json +8 -15
- package/src/client/raw.ts +0 -609
- package/src/generated/swagger.json +0 -17014
- package/src/modules/a2a.ts +0 -64
- package/src/modules/agents.ts +0 -604
- package/src/modules/apiTokens.ts +0 -101
- package/src/modules/approvals.ts +0 -151
- package/src/modules/catalog.ts +0 -241
- package/src/modules/chatwoot.ts +0 -242
- package/src/modules/checkpoints.ts +0 -87
- package/src/modules/contracts.ts +0 -80
- package/src/modules/credentials.ts +0 -216
- package/src/modules/crons.ts +0 -115
- package/src/modules/datasets.ts +0 -142
- package/src/modules/files.ts +0 -208
- package/src/modules/members.ts +0 -199
- package/src/modules/memberships.ts +0 -42
- package/src/modules/observability.ts +0 -28
- package/src/modules/playground.ts +0 -68
- package/src/modules/presets.ts +0 -246
- package/src/modules/prompts.ts +0 -147
- package/src/modules/roles.ts +0 -112
- package/src/modules/store.ts +0 -65
- package/src/modules/tenants.ts +0 -79
- package/src/modules/threads.ts +0 -343
- package/src/modules/tools.ts +0 -91
- package/src/modules/traces.ts +0 -133
- package/src/modules/vectorStores.ts +0 -257
- package/src/modules/workspaces.ts +0 -216
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent OS SDK - Main Client
|
|
3
|
+
*
|
|
4
|
+
* Fully typed API client for Agent OS platform.
|
|
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
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* // API Token (server-to-server)
|
|
13
|
+
* const api = new AgentOsClient({
|
|
14
|
+
* baseUrl: "https://api.agentos.io",
|
|
15
|
+
* auth: { type: "api_token", apiKey: "aosk_live_xxx" }
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // JWT (browser)
|
|
19
|
+
* const api = new AgentOsClient({
|
|
20
|
+
* baseUrl: "https://api.agentos.io",
|
|
21
|
+
* auth: {
|
|
22
|
+
* type: "jwt",
|
|
23
|
+
* getToken: () => supabase.auth.getSession().then(s => s.data.session?.access_token ?? ""),
|
|
24
|
+
* getWorkspaceId: () => localStorage.getItem("agentos.workspaceId") ?? ""
|
|
25
|
+
* }
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
import { type AgentOsClientOptions } from "./auth.js";
|
|
30
|
+
import { type RawClient } from "./raw.js";
|
|
31
|
+
import { AgentsModule } from "../modules/agents.js";
|
|
32
|
+
import { ChatwootModule } from "../modules/chatwoot.js";
|
|
33
|
+
import { CredentialsModule } from "../modules/credentials.js";
|
|
34
|
+
import { DatasetsModule } from "../modules/datasets.js";
|
|
35
|
+
import { RolesModule } from "../modules/roles.js";
|
|
36
|
+
import { MembersModule } from "../modules/members.js";
|
|
37
|
+
import { RunsModule } from "../modules/runs.js";
|
|
38
|
+
import { TenantsModule } from "../modules/tenants.js";
|
|
39
|
+
import { ThreadsModule } from "../modules/threads.js";
|
|
40
|
+
import { ToolsModule } from "../modules/tools.js";
|
|
41
|
+
import { TriggersModule } from "../modules/triggers.js";
|
|
42
|
+
import { WorkspacesModule } from "../modules/workspaces.js";
|
|
43
|
+
import { A2aModule } from "../modules/a2a.js";
|
|
44
|
+
import { ApiTokensModule } from "../modules/apiTokens.js";
|
|
45
|
+
import { ApprovalsModule } from "../modules/approvals.js";
|
|
46
|
+
import { AuditModule } from "../modules/audit.js";
|
|
47
|
+
import { AuthModule } from "../modules/auth.js";
|
|
48
|
+
import { CatalogModule } from "../modules/catalog.js";
|
|
49
|
+
import { CheckpointsModule } from "../modules/checkpoints.js";
|
|
50
|
+
import { ContractsModule } from "../modules/contracts.js";
|
|
51
|
+
import { CronsModule } from "../modules/crons.js";
|
|
52
|
+
import { EvaluationModule } from "../modules/evaluation.js";
|
|
53
|
+
import { FilesModule } from "../modules/files.js";
|
|
54
|
+
import { InfoModule } from "../modules/info.js";
|
|
55
|
+
import { ImprovementsModule } from "../modules/improvements.js";
|
|
56
|
+
import { MeModule } from "../modules/me.js";
|
|
57
|
+
import { MembershipsModule } from "../modules/memberships.js";
|
|
58
|
+
import { MetaAgentModule } from "../modules/metaAgent.js";
|
|
59
|
+
import { MetricsModule } from "../modules/metrics.js";
|
|
60
|
+
import { ObservabilityModule } from "../modules/observability.js";
|
|
61
|
+
import { PlaygroundModule } from "../modules/playground.js";
|
|
62
|
+
import { PresetsModule } from "../modules/presets.js";
|
|
63
|
+
import { PromptsModule } from "../modules/prompts.js";
|
|
64
|
+
import { StoreModule } from "../modules/store.js";
|
|
65
|
+
import { TemplatesModule } from "../modules/templates.js";
|
|
66
|
+
import { TracesModule } from "../modules/traces.js";
|
|
67
|
+
import { UsageModule } from "../modules/usage.js";
|
|
68
|
+
import { VectorStoresModule } from "../modules/vectorStores.js";
|
|
69
|
+
export { isApiTokenAuth, isJwtAuth } from "./auth.js";
|
|
70
|
+
export type { AgentOsClientOptions, AuthProvider } from "./auth.js";
|
|
71
|
+
export declare class AgentOsClient {
|
|
72
|
+
private readonly _client;
|
|
73
|
+
private readonly _baseUrl;
|
|
74
|
+
private readonly _auth;
|
|
75
|
+
private readonly _customHeaders;
|
|
76
|
+
readonly agents: AgentsModule;
|
|
77
|
+
readonly runs: RunsModule;
|
|
78
|
+
readonly threads: ThreadsModule;
|
|
79
|
+
readonly tools: ToolsModule;
|
|
80
|
+
readonly datasets: DatasetsModule;
|
|
81
|
+
readonly roles: RolesModule;
|
|
82
|
+
readonly triggers: TriggersModule;
|
|
83
|
+
readonly credentials: CredentialsModule;
|
|
84
|
+
readonly members: MembersModule;
|
|
85
|
+
readonly tenants: TenantsModule;
|
|
86
|
+
readonly workspaces: WorkspacesModule;
|
|
87
|
+
readonly chatwoot: ChatwootModule;
|
|
88
|
+
readonly prompts: PromptsModule;
|
|
89
|
+
readonly traces: TracesModule;
|
|
90
|
+
readonly files: FilesModule;
|
|
91
|
+
readonly vectorStores: VectorStoresModule;
|
|
92
|
+
readonly evaluation: EvaluationModule;
|
|
93
|
+
readonly checkpoints: CheckpointsModule;
|
|
94
|
+
readonly playground: PlaygroundModule;
|
|
95
|
+
readonly crons: CronsModule;
|
|
96
|
+
readonly store: StoreModule;
|
|
97
|
+
readonly audit: AuditModule;
|
|
98
|
+
readonly usage: UsageModule;
|
|
99
|
+
readonly a2a: A2aModule;
|
|
100
|
+
readonly me: MeModule;
|
|
101
|
+
readonly info: InfoModule;
|
|
102
|
+
readonly improvements: ImprovementsModule;
|
|
103
|
+
readonly metrics: MetricsModule;
|
|
104
|
+
readonly metaAgent: MetaAgentModule;
|
|
105
|
+
readonly contracts: ContractsModule;
|
|
106
|
+
readonly catalog: CatalogModule;
|
|
107
|
+
readonly approvals: ApprovalsModule;
|
|
108
|
+
readonly auth: AuthModule;
|
|
109
|
+
readonly observability: ObservabilityModule;
|
|
110
|
+
readonly templates: TemplatesModule;
|
|
111
|
+
readonly experiments: {
|
|
112
|
+
list: EvaluationModule["listExperiments"];
|
|
113
|
+
get: EvaluationModule["getExperiment"];
|
|
114
|
+
create: EvaluationModule["createExperiment"];
|
|
115
|
+
};
|
|
116
|
+
readonly apiTokens: ApiTokensModule;
|
|
117
|
+
readonly memberships: MembershipsModule;
|
|
118
|
+
readonly presets: PresetsModule;
|
|
119
|
+
constructor(options: AgentOsClientOptions);
|
|
120
|
+
/**
|
|
121
|
+
* Validate auth configuration at construction time
|
|
122
|
+
*/
|
|
123
|
+
private _validateAuth;
|
|
124
|
+
/**
|
|
125
|
+
* Resolve headers for each request (async)
|
|
126
|
+
*
|
|
127
|
+
* SECURITY INVARIANTS:
|
|
128
|
+
* - JWT: Authorization + X-Workspace-Id (REQUIRED), NO X-Tenant-Id
|
|
129
|
+
* - API Token: Authorization only, NO X-Workspace-Id, NO X-Tenant-Id
|
|
130
|
+
*/
|
|
131
|
+
private _resolveHeaders;
|
|
132
|
+
/**
|
|
133
|
+
* Get resolved headers (for debugging/testing)
|
|
134
|
+
*/
|
|
135
|
+
getHeadersAsync(): Promise<Record<string, string>>;
|
|
136
|
+
/** Auth provider type */
|
|
137
|
+
get authType(): "api_token" | "jwt";
|
|
138
|
+
/** Raw HTTP client (use modules instead) */
|
|
139
|
+
get raw(): RawClient;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=AgentOsClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentOsClient.d.ts","sourceRoot":"","sources":["../../src/client/AgentOsClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EACH,KAAK,oBAAoB,EAK5B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAE3D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,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eAAe,CAAC,CAAC;QACvC,MAAM,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;KAChD,CAAC;IAEF,SAAgB,SAAS,EAAE,eAAe,CAAC;IAC3C,SAAgB,WAAW,EAAE,iBAAiB,CAAC;IAC/C,SAAgB,OAAO,EAAE,aAAa,CAAC;gBAI3B,OAAO,EAAE,oBAAoB;IA0EzC;;OAEG;IACH,OAAO,CAAC,aAAa;IAYrB;;;;;;OAMG;YACW,eAAe;IAwC7B;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAIxD,yBAAyB;IACzB,IAAI,QAAQ,IAAI,WAAW,GAAG,KAAK,CAElC;IAED,4CAA4C;IAC5C,IAAI,GAAG,IAAI,SAAS,CAEnB;CACJ"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Agent OS SDK - Main Client
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* Fully typed API client for Agent OS platform.
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* Two authentication modes:
|
|
7
7
|
* - API Token (server-to-server): aosk_* tokens with embedded claims
|
|
8
8
|
* - JWT (browser): Supabase JWT + X-Workspace-Id header
|
|
9
|
-
*
|
|
9
|
+
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
12
12
|
* // API Token (server-to-server)
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* baseUrl: "https://api.agentos.io",
|
|
15
15
|
* auth: { type: "api_token", apiKey: "aosk_live_xxx" }
|
|
16
16
|
* });
|
|
17
|
-
*
|
|
17
|
+
*
|
|
18
18
|
* // JWT (browser)
|
|
19
19
|
* const api = new AgentOsClient({
|
|
20
20
|
* baseUrl: "https://api.agentos.io",
|
|
@@ -26,16 +26,8 @@
|
|
|
26
26
|
* });
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
|
-
|
|
30
|
-
import {
|
|
31
|
-
type AgentOsClientOptions,
|
|
32
|
-
type AuthProvider,
|
|
33
|
-
isApiTokenAuth,
|
|
34
|
-
isBrowser,
|
|
35
|
-
isJwtAuth,
|
|
36
|
-
} from "./auth.js";
|
|
37
|
-
import { createRawClient, type RawClient } from "./raw.js";
|
|
38
|
-
|
|
29
|
+
import { isApiTokenAuth, isBrowser, isJwtAuth, } from "./auth.js";
|
|
30
|
+
import { createRawClient } from "./raw.js";
|
|
39
31
|
import { AgentsModule } from "../modules/agents.js";
|
|
40
32
|
import { ChatwootModule } from "../modules/chatwoot.js";
|
|
41
33
|
import { CredentialsModule } from "../modules/credentials.js";
|
|
@@ -48,7 +40,6 @@ import { ThreadsModule } from "../modules/threads.js";
|
|
|
48
40
|
import { ToolsModule } from "../modules/tools.js";
|
|
49
41
|
import { TriggersModule } from "../modules/triggers.js";
|
|
50
42
|
import { WorkspacesModule } from "../modules/workspaces.js";
|
|
51
|
-
|
|
52
43
|
// Platform modules
|
|
53
44
|
import { A2aModule } from "../modules/a2a.js";
|
|
54
45
|
import { ApiTokensModule } from "../modules/apiTokens.js";
|
|
@@ -76,77 +67,61 @@ import { TemplatesModule } from "../modules/templates.js";
|
|
|
76
67
|
import { TracesModule } from "../modules/traces.js";
|
|
77
68
|
import { UsageModule } from "../modules/usage.js";
|
|
78
69
|
import { VectorStoresModule } from "../modules/vectorStores.js";
|
|
79
|
-
|
|
80
70
|
// Re-export auth types
|
|
81
71
|
export { isApiTokenAuth, isJwtAuth } from "./auth.js";
|
|
82
|
-
export type { AgentOsClientOptions, AuthProvider } from "./auth.js";
|
|
83
|
-
|
|
84
72
|
export class AgentOsClient {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
73
|
+
_client;
|
|
74
|
+
_baseUrl;
|
|
75
|
+
_auth;
|
|
76
|
+
_customHeaders;
|
|
90
77
|
// Core modules
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
78
|
+
agents;
|
|
79
|
+
runs;
|
|
80
|
+
threads;
|
|
81
|
+
tools;
|
|
82
|
+
datasets;
|
|
83
|
+
roles;
|
|
84
|
+
triggers;
|
|
85
|
+
credentials;
|
|
86
|
+
members;
|
|
87
|
+
tenants;
|
|
88
|
+
workspaces;
|
|
89
|
+
chatwoot;
|
|
104
90
|
// Platform modules
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
91
|
+
prompts;
|
|
92
|
+
traces;
|
|
93
|
+
files;
|
|
94
|
+
vectorStores;
|
|
95
|
+
evaluation;
|
|
96
|
+
checkpoints;
|
|
97
|
+
playground;
|
|
98
|
+
crons;
|
|
99
|
+
store;
|
|
100
|
+
audit;
|
|
101
|
+
usage;
|
|
102
|
+
a2a;
|
|
103
|
+
me;
|
|
104
|
+
info;
|
|
105
|
+
improvements;
|
|
106
|
+
metrics;
|
|
107
|
+
metaAgent;
|
|
108
|
+
contracts;
|
|
109
|
+
catalog;
|
|
110
|
+
approvals;
|
|
111
|
+
auth;
|
|
112
|
+
observability;
|
|
113
|
+
templates;
|
|
129
114
|
// Convenience aliases
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
public readonly apiTokens: ApiTokensModule;
|
|
137
|
-
public readonly memberships: MembershipsModule;
|
|
138
|
-
public readonly presets: PresetsModule;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
constructor(options: AgentOsClientOptions) {
|
|
115
|
+
experiments;
|
|
116
|
+
apiTokens;
|
|
117
|
+
memberships;
|
|
118
|
+
presets;
|
|
119
|
+
constructor(options) {
|
|
143
120
|
this._baseUrl = options.baseUrl;
|
|
144
121
|
this._auth = options.auth;
|
|
145
122
|
this._customHeaders = options.headers ?? {};
|
|
146
|
-
|
|
147
123
|
// Validate auth configuration
|
|
148
124
|
this._validateAuth(options);
|
|
149
|
-
|
|
150
125
|
// Create raw client with async header provider
|
|
151
126
|
this._client = createRawClient({
|
|
152
127
|
baseUrl: options.baseUrl,
|
|
@@ -155,12 +130,10 @@ export class AgentOsClient {
|
|
|
155
130
|
network: options.network,
|
|
156
131
|
hooks: options.hooks,
|
|
157
132
|
});
|
|
158
|
-
|
|
159
133
|
// Module header getter (sync fallback for backwards compat with module internals)
|
|
160
134
|
const getHeaders = () => this._customHeaders;
|
|
161
135
|
const getWorkspaceId = () => "";
|
|
162
136
|
const getTenantId = () => "";
|
|
163
|
-
|
|
164
137
|
// Initialize core modules
|
|
165
138
|
this.agents = new AgentsModule(this._client, getHeaders);
|
|
166
139
|
this.runs = new RunsModule(this._client);
|
|
@@ -174,7 +147,6 @@ export class AgentOsClient {
|
|
|
174
147
|
this.tenants = new TenantsModule(this._client, getHeaders);
|
|
175
148
|
this.workspaces = new WorkspacesModule(this._client, getTenantId, getHeaders);
|
|
176
149
|
this.chatwoot = new ChatwootModule(this._client, getHeaders);
|
|
177
|
-
|
|
178
150
|
// Initialize platform modules
|
|
179
151
|
this.prompts = new PromptsModule(this._client, getHeaders);
|
|
180
152
|
this.traces = new TracesModule(this._client, getHeaders);
|
|
@@ -199,71 +171,59 @@ export class AgentOsClient {
|
|
|
199
171
|
this.auth = new AuthModule(this._client, getHeaders);
|
|
200
172
|
this.observability = new ObservabilityModule(this._client, getHeaders);
|
|
201
173
|
this.templates = new TemplatesModule(this._client, getHeaders);
|
|
202
|
-
|
|
203
174
|
// Initialize convenience aliases
|
|
204
175
|
this.experiments = {
|
|
205
176
|
list: this.evaluation.listExperiments.bind(this.evaluation),
|
|
206
177
|
get: this.evaluation.getExperiment.bind(this.evaluation),
|
|
207
178
|
create: this.evaluation.createExperiment.bind(this.evaluation),
|
|
208
179
|
};
|
|
209
|
-
|
|
210
180
|
this.apiTokens = new ApiTokensModule(this._client);
|
|
211
181
|
this.memberships = new MembershipsModule(this._client);
|
|
212
182
|
this.presets = new PresetsModule(this._client, getHeaders);
|
|
213
|
-
|
|
214
183
|
}
|
|
215
|
-
|
|
216
184
|
/**
|
|
217
185
|
* Validate auth configuration at construction time
|
|
218
186
|
*/
|
|
219
|
-
|
|
187
|
+
_validateAuth(options) {
|
|
220
188
|
const { auth, allowApiTokenInBrowser } = options;
|
|
221
|
-
|
|
222
189
|
// Browser security guard for API tokens
|
|
223
190
|
if (isApiTokenAuth(auth) && isBrowser() && !allowApiTokenInBrowser) {
|
|
224
|
-
throw new Error(
|
|
225
|
-
"
|
|
226
|
-
"Use JWT auth in the browser. Set allowApiTokenInBrowser: true only if you understand the risks."
|
|
227
|
-
);
|
|
191
|
+
throw new Error("[AgentOS SDK] SECURITY: API tokens (aosk_*) are SERVER-SIDE only. " +
|
|
192
|
+
"Use JWT auth in the browser. Set allowApiTokenInBrowser: true only if you understand the risks.");
|
|
228
193
|
}
|
|
229
194
|
}
|
|
230
|
-
|
|
231
195
|
/**
|
|
232
196
|
* Resolve headers for each request (async)
|
|
233
|
-
*
|
|
197
|
+
*
|
|
234
198
|
* SECURITY INVARIANTS:
|
|
235
199
|
* - JWT: Authorization + X-Workspace-Id (REQUIRED), NO X-Tenant-Id
|
|
236
200
|
* - API Token: Authorization only, NO X-Workspace-Id, NO X-Tenant-Id
|
|
237
201
|
*/
|
|
238
|
-
|
|
239
|
-
const headers
|
|
202
|
+
async _resolveHeaders() {
|
|
203
|
+
const headers = {
|
|
240
204
|
"Content-Type": "application/json",
|
|
241
205
|
...this._customHeaders,
|
|
242
206
|
};
|
|
243
|
-
|
|
244
207
|
if (isApiTokenAuth(this._auth)) {
|
|
245
208
|
// API Token: Authorization header only
|
|
246
209
|
const apiKey = typeof this._auth.apiKey === "function"
|
|
247
210
|
? await this._auth.apiKey()
|
|
248
211
|
: this._auth.apiKey;
|
|
249
|
-
|
|
250
212
|
if (apiKey) {
|
|
251
213
|
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
252
214
|
}
|
|
253
215
|
// NO X-Workspace-Id (embedded in token claims)
|
|
254
216
|
// NO X-Tenant-Id (embedded in token claims)
|
|
255
|
-
|
|
256
|
-
|
|
217
|
+
}
|
|
218
|
+
else if (isJwtAuth(this._auth)) {
|
|
257
219
|
// JWT: Authorization + X-Workspace-Id
|
|
258
220
|
const [token, workspaceId] = await Promise.all([
|
|
259
221
|
Promise.resolve(this._auth.getToken()),
|
|
260
222
|
Promise.resolve(this._auth.getWorkspaceId()),
|
|
261
223
|
]);
|
|
262
|
-
|
|
263
224
|
if (token) {
|
|
264
225
|
headers["Authorization"] = `Bearer ${token}`;
|
|
265
226
|
}
|
|
266
|
-
|
|
267
227
|
// Workspace ID is optional for bootstrap endpoints (e.g., /me)
|
|
268
228
|
// Most endpoints require it, but the header provider allows empty strings
|
|
269
229
|
if (workspaceId) {
|
|
@@ -271,24 +231,20 @@ export class AgentOsClient {
|
|
|
271
231
|
}
|
|
272
232
|
// NO X-Tenant-Id (backend derives from workspace membership)
|
|
273
233
|
}
|
|
274
|
-
|
|
275
234
|
return headers;
|
|
276
235
|
}
|
|
277
|
-
|
|
278
236
|
/**
|
|
279
237
|
* Get resolved headers (for debugging/testing)
|
|
280
238
|
*/
|
|
281
|
-
async getHeadersAsync()
|
|
239
|
+
async getHeadersAsync() {
|
|
282
240
|
return this._resolveHeaders();
|
|
283
241
|
}
|
|
284
|
-
|
|
285
242
|
/** Auth provider type */
|
|
286
|
-
get authType()
|
|
243
|
+
get authType() {
|
|
287
244
|
return this._auth.type;
|
|
288
245
|
}
|
|
289
|
-
|
|
290
246
|
/** Raw HTTP client (use modules instead) */
|
|
291
|
-
get raw()
|
|
247
|
+
get raw() {
|
|
292
248
|
return this._client;
|
|
293
249
|
}
|
|
294
250
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HttpRequestBuilder — Single source of truth for headers
|
|
3
|
+
*
|
|
4
|
+
* All header generation flows through this builder.
|
|
5
|
+
* raw.ts should NOT generate headers directly.
|
|
6
|
+
*
|
|
7
|
+
* Headers generated:
|
|
8
|
+
* - X-Request-Id: Per-request, always new (crypto.randomUUID)
|
|
9
|
+
* - X-Correlation-Id: Per-flow, immutable within flow
|
|
10
|
+
* - Authorization: Bearer token
|
|
11
|
+
* - X-Workspace-Id: Workspace binding (from context)
|
|
12
|
+
* - X-Idempotency-Key: Opt-in for POST requests
|
|
13
|
+
* - User-Agent: SDK version + runtime info
|
|
14
|
+
*
|
|
15
|
+
* @see sdk-upgrade.md Section 1.3
|
|
16
|
+
*/
|
|
17
|
+
import type { OperationContext } from "./OperationContext.js";
|
|
18
|
+
export declare function sanitizeValidCorrelationId(raw?: string): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Options for building request headers
|
|
21
|
+
*/
|
|
22
|
+
export interface HttpRequestBuilderOptions {
|
|
23
|
+
/** Bearer token for Authorization header */
|
|
24
|
+
token?: string;
|
|
25
|
+
/** Operation context with correlationId and workspaceId */
|
|
26
|
+
context?: OperationContext;
|
|
27
|
+
/** Idempotency key for POST requests */
|
|
28
|
+
idempotencyKey?: string;
|
|
29
|
+
/** If true, throws if correlationId is missing */
|
|
30
|
+
requireFlow?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Build headers for HTTP requests.
|
|
34
|
+
* This is the SINGLE SOURCE OF TRUTH for header generation.
|
|
35
|
+
*/
|
|
36
|
+
export declare class HttpRequestBuilder {
|
|
37
|
+
/**
|
|
38
|
+
* Build headers from options.
|
|
39
|
+
*
|
|
40
|
+
* @throws Error if requireFlow is true and correlationId is missing
|
|
41
|
+
*/
|
|
42
|
+
build(opts: HttpRequestBuilderOptions): Record<string, string>;
|
|
43
|
+
private resolveCorrelationId;
|
|
44
|
+
/**
|
|
45
|
+
* Build User-Agent string with SDK version and runtime info
|
|
46
|
+
*/
|
|
47
|
+
private buildUserAgent;
|
|
48
|
+
}
|
|
49
|
+
export declare const httpRequestBuilder: HttpRequestBuilder;
|
|
50
|
+
//# sourceMappingURL=HttpRequestBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpRequestBuilder.d.ts","sourceRoot":"","sources":["../../src/client/HttpRequestBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAQ9D,wBAAgB,0BAA0B,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGtE;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACtC,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,wCAAwC;IACxC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kDAAkD;IAClD,WAAW,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;GAGG;AACH,qBAAa,kBAAkB;IAC3B;;;;OAIG;IACH,KAAK,CAAC,IAAI,EAAE,yBAAyB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAiC9D,OAAO,CAAC,oBAAoB;IAS5B;;OAEG;IACH,OAAO,CAAC,cAAc;CAYzB;AAGD,eAAO,MAAM,kBAAkB,oBAA2B,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* HttpRequestBuilder — Single source of truth for headers
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* All header generation flows through this builder.
|
|
5
5
|
* raw.ts should NOT generate headers directly.
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
* Headers generated:
|
|
8
8
|
* - X-Request-Id: Per-request, always new (crypto.randomUUID)
|
|
9
9
|
* - X-Correlation-Id: Per-flow, immutable within flow
|
|
@@ -11,37 +11,16 @@
|
|
|
11
11
|
* - X-Workspace-Id: Workspace binding (from context)
|
|
12
12
|
* - X-Idempotency-Key: Opt-in for POST requests
|
|
13
13
|
* - User-Agent: SDK version + runtime info
|
|
14
|
-
*
|
|
14
|
+
*
|
|
15
15
|
* @see sdk-upgrade.md Section 1.3
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
import type { OperationContext } from "./OperationContext.js";
|
|
19
17
|
import { sanitizeHeader, sanitizeHeaders } from "./sanitize.js";
|
|
20
|
-
|
|
21
|
-
// SDK version injected at build time, fallback for local dev
|
|
22
|
-
declare const __SDK_VERSION__: string | undefined;
|
|
23
18
|
const SDK_VERSION = typeof __SDK_VERSION__ !== "undefined" ? __SDK_VERSION__ : "0.7.12-dev";
|
|
24
19
|
const CORRELATION_ID_PATTERN = /^[A-Za-z0-9._:-]{8,128}$/;
|
|
25
|
-
|
|
26
|
-
export function sanitizeValidCorrelationId(raw?: string): string | null {
|
|
20
|
+
export function sanitizeValidCorrelationId(raw) {
|
|
27
21
|
const candidate = sanitizeHeader((raw ?? "").trim());
|
|
28
22
|
return CORRELATION_ID_PATTERN.test(candidate) ? candidate : null;
|
|
29
23
|
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Options for building request headers
|
|
33
|
-
*/
|
|
34
|
-
export interface HttpRequestBuilderOptions {
|
|
35
|
-
/** Bearer token for Authorization header */
|
|
36
|
-
token?: string;
|
|
37
|
-
/** Operation context with correlationId and workspaceId */
|
|
38
|
-
context?: OperationContext;
|
|
39
|
-
/** Idempotency key for POST requests */
|
|
40
|
-
idempotencyKey?: string;
|
|
41
|
-
/** If true, throws if correlationId is missing */
|
|
42
|
-
requireFlow?: boolean;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
24
|
/**
|
|
46
25
|
* Build headers for HTTP requests.
|
|
47
26
|
* This is the SINGLE SOURCE OF TRUTH for header generation.
|
|
@@ -49,55 +28,45 @@ export interface HttpRequestBuilderOptions {
|
|
|
49
28
|
export class HttpRequestBuilder {
|
|
50
29
|
/**
|
|
51
30
|
* Build headers from options.
|
|
52
|
-
*
|
|
31
|
+
*
|
|
53
32
|
* @throws Error if requireFlow is true and correlationId is missing
|
|
54
33
|
*/
|
|
55
|
-
build(opts
|
|
56
|
-
const headers
|
|
57
|
-
|
|
34
|
+
build(opts) {
|
|
35
|
+
const headers = {};
|
|
58
36
|
// I2: X-Request-Id always exists (per request)
|
|
59
37
|
headers["X-Request-Id"] = crypto.randomUUID();
|
|
60
|
-
|
|
61
38
|
// User-Agent: Dynamic SDK version
|
|
62
39
|
headers["User-Agent"] = this.buildUserAgent();
|
|
63
|
-
|
|
64
40
|
// I3: X-Correlation-Id is per flow
|
|
65
41
|
if (opts.requireFlow && !opts.context?.correlationId) {
|
|
66
42
|
throw new Error("X-Correlation-Id required for flow-scoped operations");
|
|
67
43
|
}
|
|
68
44
|
headers["X-Correlation-Id"] = this.resolveCorrelationId(opts.context?.correlationId);
|
|
69
|
-
|
|
70
45
|
// Authorization
|
|
71
46
|
if (opts.token) {
|
|
72
47
|
headers["Authorization"] = `Bearer ${opts.token}`;
|
|
73
48
|
}
|
|
74
|
-
|
|
75
49
|
// X-Workspace-Id from context
|
|
76
50
|
if (opts.context?.workspaceId) {
|
|
77
51
|
headers["X-Workspace-Id"] = opts.context.workspaceId;
|
|
78
52
|
}
|
|
79
|
-
|
|
80
53
|
// I7: Idempotency is opt-in
|
|
81
54
|
if (opts.idempotencyKey) {
|
|
82
55
|
headers["X-Idempotency-Key"] = sanitizeHeader(opts.idempotencyKey);
|
|
83
56
|
}
|
|
84
|
-
|
|
85
57
|
return sanitizeHeaders(headers);
|
|
86
58
|
}
|
|
87
|
-
|
|
88
|
-
private resolveCorrelationId(raw?: string): string {
|
|
59
|
+
resolveCorrelationId(raw) {
|
|
89
60
|
const candidate = sanitizeValidCorrelationId(raw);
|
|
90
61
|
if (candidate) {
|
|
91
62
|
return candidate;
|
|
92
63
|
}
|
|
93
|
-
|
|
94
64
|
return crypto.randomUUID();
|
|
95
65
|
}
|
|
96
|
-
|
|
97
66
|
/**
|
|
98
67
|
* Build User-Agent string with SDK version and runtime info
|
|
99
68
|
*/
|
|
100
|
-
|
|
69
|
+
buildUserAgent() {
|
|
101
70
|
// Node.js environment
|
|
102
71
|
if (typeof process !== "undefined" && process.version) {
|
|
103
72
|
return `agent-os-sdk/${SDK_VERSION} (node/${process.version})`;
|
|
@@ -110,6 +79,5 @@ export class HttpRequestBuilder {
|
|
|
110
79
|
return `agent-os-sdk/${SDK_VERSION}`;
|
|
111
80
|
}
|
|
112
81
|
}
|
|
113
|
-
|
|
114
82
|
// Singleton instance for convenience
|
|
115
83
|
export const httpRequestBuilder = new HttpRequestBuilder();
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* OperationContext — Immutable flow context
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* Created at the start of a logical flow and never mutates.
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* - correlationId: Tracks the entire logical operation (immutable per flow)
|
|
7
7
|
* - workspaceId: Optional workspace binding
|
|
8
|
-
*
|
|
8
|
+
*
|
|
9
9
|
* @see sdk-upgrade.md Section 1.1
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
11
|
export type OperationContext = Readonly<{
|
|
13
12
|
correlationId: string;
|
|
14
13
|
workspaceId?: string;
|
|
15
14
|
}>;
|
|
16
|
-
|
|
17
|
-
export function createOperationContext(input: {
|
|
15
|
+
export declare function createOperationContext(input: {
|
|
18
16
|
correlationId: string;
|
|
19
17
|
workspaceId?: string;
|
|
20
|
-
}): OperationContext
|
|
21
|
-
|
|
22
|
-
}
|
|
18
|
+
}): OperationContext;
|
|
19
|
+
//# sourceMappingURL=OperationContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OperationContext.d.ts","sourceRoot":"","sources":["../../src/client/OperationContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC,CAAC;AAEH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAC1C,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG,gBAAgB,CAEnB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OperationContext — Immutable flow context
|
|
3
|
+
*
|
|
4
|
+
* Created at the start of a logical flow and never mutates.
|
|
5
|
+
*
|
|
6
|
+
* - correlationId: Tracks the entire logical operation (immutable per flow)
|
|
7
|
+
* - workspaceId: Optional workspace binding
|
|
8
|
+
*
|
|
9
|
+
* @see sdk-upgrade.md Section 1.1
|
|
10
|
+
*/
|
|
11
|
+
export function createOperationContext(input) {
|
|
12
|
+
return Object.freeze({ ...input });
|
|
13
|
+
}
|