@agent-os-sdk/client 0.1.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/README.md +71 -0
- package/dist/client/AgentOsClient.d.ts +161 -0
- package/dist/client/AgentOsClient.d.ts.map +1 -0
- package/dist/client/AgentOsClient.js +217 -0
- package/dist/client/helpers.d.ts +63 -0
- package/dist/client/helpers.d.ts.map +1 -0
- package/dist/client/helpers.js +55 -0
- package/dist/client/raw.d.ts +138 -0
- package/dist/client/raw.d.ts.map +1 -0
- package/dist/client/raw.js +97 -0
- package/dist/generated/index.d.ts +2 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +1 -0
- package/dist/generated/openapi.d.ts +6810 -0
- package/dist/generated/openapi.d.ts.map +1 -0
- package/dist/generated/openapi.js +5 -0
- package/dist/index.d.ts +72 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +86 -0
- 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 +137 -0
- package/dist/modules/agents.d.ts.map +1 -0
- package/dist/modules/agents.js +154 -0
- package/dist/modules/audit.d.ts +55 -0
- package/dist/modules/audit.d.ts.map +1 -0
- package/dist/modules/audit.js +38 -0
- package/dist/modules/builder.d.ts +65 -0
- package/dist/modules/builder.d.ts.map +1 -0
- package/dist/modules/builder.js +119 -0
- package/dist/modules/checkpoints.d.ts +53 -0
- package/dist/modules/checkpoints.d.ts.map +1 -0
- package/dist/modules/checkpoints.js +39 -0
- package/dist/modules/credentials.d.ts +89 -0
- package/dist/modules/credentials.d.ts.map +1 -0
- package/dist/modules/credentials.js +79 -0
- package/dist/modules/crons.d.ts +72 -0
- package/dist/modules/crons.d.ts.map +1 -0
- package/dist/modules/crons.js +66 -0
- package/dist/modules/dlq.d.ts +60 -0
- package/dist/modules/dlq.d.ts.map +1 -0
- package/dist/modules/dlq.js +56 -0
- package/dist/modules/evaluation.d.ts +119 -0
- package/dist/modules/evaluation.d.ts.map +1 -0
- package/dist/modules/evaluation.js +96 -0
- package/dist/modules/files.d.ts +68 -0
- package/dist/modules/files.d.ts.map +1 -0
- package/dist/modules/files.js +66 -0
- package/dist/modules/graphs.d.ts +51 -0
- package/dist/modules/graphs.d.ts.map +1 -0
- package/dist/modules/graphs.js +29 -0
- package/dist/modules/info.d.ts +27 -0
- package/dist/modules/info.d.ts.map +1 -0
- package/dist/modules/info.js +27 -0
- 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/dist/modules/mcp.d.ts +39 -0
- package/dist/modules/mcp.d.ts.map +1 -0
- package/dist/modules/mcp.js +38 -0
- package/dist/modules/me.d.ts +27 -0
- package/dist/modules/me.d.ts.map +1 -0
- package/dist/modules/me.js +19 -0
- package/dist/modules/members.d.ts +77 -0
- package/dist/modules/members.d.ts.map +1 -0
- package/dist/modules/members.js +77 -0
- package/dist/modules/metrics.d.ts +16 -0
- package/dist/modules/metrics.d.ts.map +1 -0
- package/dist/modules/metrics.js +24 -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/prompts.d.ts +87 -0
- package/dist/modules/prompts.d.ts.map +1 -0
- package/dist/modules/prompts.js +87 -0
- package/dist/modules/runs.d.ts +181 -0
- package/dist/modules/runs.d.ts.map +1 -0
- package/dist/modules/runs.js +187 -0
- 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/dist/modules/tenants.d.ts +42 -0
- package/dist/modules/tenants.d.ts.map +1 -0
- package/dist/modules/tenants.js +45 -0
- package/dist/modules/threads.d.ts +181 -0
- package/dist/modules/threads.d.ts.map +1 -0
- package/dist/modules/threads.js +178 -0
- package/dist/modules/tools.d.ts +44 -0
- package/dist/modules/tools.d.ts.map +1 -0
- package/dist/modules/tools.js +39 -0
- package/dist/modules/traces.d.ts +79 -0
- package/dist/modules/traces.d.ts.map +1 -0
- package/dist/modules/traces.js +56 -0
- package/dist/modules/triggers.d.ts +71 -0
- package/dist/modules/triggers.d.ts.map +1 -0
- package/dist/modules/triggers.js +67 -0
- package/dist/modules/usage.d.ts +26 -0
- package/dist/modules/usage.d.ts.map +1 -0
- package/dist/modules/usage.js +19 -0
- package/dist/modules/vectorStores.d.ts +97 -0
- package/dist/modules/vectorStores.d.ts.map +1 -0
- package/dist/modules/vectorStores.js +87 -0
- package/dist/modules/workspaces.d.ts +52 -0
- package/dist/modules/workspaces.d.ts.map +1 -0
- package/dist/modules/workspaces.js +59 -0
- package/dist/sse/client.d.ts +62 -0
- package/dist/sse/client.d.ts.map +1 -0
- package/dist/sse/client.js +66 -0
- package/package.json +50 -0
- package/src/client/AgentOsClient.ts +269 -0
- package/src/client/helpers.ts +98 -0
- package/src/client/raw.ts +241 -0
- package/src/generated/index.ts +2 -0
- package/src/generated/openapi.ts +6810 -0
- package/src/generated/swagger.json +8549 -0
- package/src/index.ts +161 -0
- package/src/modules/a2a.ts +64 -0
- package/src/modules/agents.ts +229 -0
- package/src/modules/audit.ts +74 -0
- package/src/modules/builder.ts +166 -0
- package/src/modules/checkpoints.ts +78 -0
- package/src/modules/credentials.ts +144 -0
- package/src/modules/crons.ts +114 -0
- package/src/modules/dlq.ts +93 -0
- package/src/modules/evaluation.ts +189 -0
- package/src/modules/files.ts +112 -0
- package/src/modules/graphs.ts +50 -0
- package/src/modules/info.ts +35 -0
- package/src/modules/knowledge.ts +147 -0
- package/src/modules/mcp.ts +59 -0
- package/src/modules/me.ts +32 -0
- package/src/modules/members.ts +117 -0
- package/src/modules/metrics.ts +27 -0
- package/src/modules/playground.ts +68 -0
- package/src/modules/prompts.ts +147 -0
- package/src/modules/runs.ts +277 -0
- package/src/modules/store.ts +65 -0
- package/src/modules/tenants.ts +67 -0
- package/src/modules/threads.ts +287 -0
- package/src/modules/tools.ts +65 -0
- package/src/modules/traces.ts +117 -0
- package/src/modules/triggers.ts +113 -0
- package/src/modules/usage.ts +32 -0
- package/src/modules/vectorStores.ts +160 -0
- package/src/modules/workspaces.ts +89 -0
- package/src/sse/client.ts +100 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent OS SDK - Main Client
|
|
3
|
+
*
|
|
4
|
+
* Fully typed API client for Agent OS platform.
|
|
5
|
+
* All HTTP calls must go through this client.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const api = new AgentOsClient({
|
|
10
|
+
* baseUrl: "http://localhost:5000",
|
|
11
|
+
* tenantId: "...",
|
|
12
|
+
* workspaceId: "...",
|
|
13
|
+
* token: "...",
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* const run = await api.runs.create({
|
|
17
|
+
* agent_id: "...",
|
|
18
|
+
* input: { message: "Hello" },
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { createRawClient, type RawClient } from "./raw.js";
|
|
24
|
+
import { AgentsModule } from "../modules/agents.js";
|
|
25
|
+
import { RunsModule } from "../modules/runs.js";
|
|
26
|
+
import { ThreadsModule } from "../modules/threads.js";
|
|
27
|
+
import { ToolsModule } from "../modules/tools.js";
|
|
28
|
+
import { KnowledgeModule } from "../modules/knowledge.js";
|
|
29
|
+
import { TriggersModule } from "../modules/triggers.js";
|
|
30
|
+
import { CredentialsModule } from "../modules/credentials.js";
|
|
31
|
+
import { BuilderModule } from "../modules/builder.js";
|
|
32
|
+
import { MembersModule } from "../modules/members.js";
|
|
33
|
+
import { TenantsModule } from "../modules/tenants.js";
|
|
34
|
+
import { WorkspacesModule } from "../modules/workspaces.js";
|
|
35
|
+
|
|
36
|
+
// New modules
|
|
37
|
+
import { PromptsModule } from "../modules/prompts.js";
|
|
38
|
+
import { TracesModule } from "../modules/traces.js";
|
|
39
|
+
import { FilesModule } from "../modules/files.js";
|
|
40
|
+
import { VectorStoresModule } from "../modules/vectorStores.js";
|
|
41
|
+
import { EvaluationModule } from "../modules/evaluation.js";
|
|
42
|
+
import { CheckpointsModule } from "../modules/checkpoints.js";
|
|
43
|
+
import { PlaygroundModule } from "../modules/playground.js";
|
|
44
|
+
import { CronsModule } from "../modules/crons.js";
|
|
45
|
+
import { DlqModule } from "../modules/dlq.js";
|
|
46
|
+
import { StoreModule } from "../modules/store.js";
|
|
47
|
+
import { AuditModule } from "../modules/audit.js";
|
|
48
|
+
import { UsageModule } from "../modules/usage.js";
|
|
49
|
+
import { McpModule } from "../modules/mcp.js";
|
|
50
|
+
import { A2aModule } from "../modules/a2a.js";
|
|
51
|
+
import { MeModule } from "../modules/me.js";
|
|
52
|
+
import { InfoModule } from "../modules/info.js";
|
|
53
|
+
import { MetricsModule } from "../modules/metrics.js";
|
|
54
|
+
import { GraphsModule } from "../modules/graphs.js";
|
|
55
|
+
|
|
56
|
+
export type AgentOsClientOptions = {
|
|
57
|
+
/** Base URL of the Agent OS API */
|
|
58
|
+
baseUrl: string;
|
|
59
|
+
|
|
60
|
+
/** Tenant ID (multi-tenant) */
|
|
61
|
+
tenantId: string;
|
|
62
|
+
|
|
63
|
+
/** Workspace ID */
|
|
64
|
+
workspaceId: string;
|
|
65
|
+
|
|
66
|
+
/** Optional auth token */
|
|
67
|
+
token?: string;
|
|
68
|
+
|
|
69
|
+
/** Optional member ID (for identity header) */
|
|
70
|
+
memberId?: string;
|
|
71
|
+
|
|
72
|
+
/** Custom headers */
|
|
73
|
+
headers?: Record<string, string>;
|
|
74
|
+
|
|
75
|
+
/** Kernel base URL (for meta-agent, different from control plane) */
|
|
76
|
+
kernelBaseUrl?: string;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export class AgentOsClient {
|
|
80
|
+
private readonly _client: RawClient;
|
|
81
|
+
private readonly _baseUrl: string;
|
|
82
|
+
private readonly _tenantId: string;
|
|
83
|
+
private readonly _workspaceId: string;
|
|
84
|
+
private readonly _token?: string;
|
|
85
|
+
private readonly _memberId?: string;
|
|
86
|
+
private readonly _customHeaders: Record<string, string>;
|
|
87
|
+
private readonly _kernelBaseUrl: string;
|
|
88
|
+
|
|
89
|
+
// Core modules
|
|
90
|
+
/** Agents API: CRUD, versions, graph */
|
|
91
|
+
readonly agents: AgentsModule;
|
|
92
|
+
/** Runs API: create, stream, cancel, resume, replay */
|
|
93
|
+
readonly runs: RunsModule;
|
|
94
|
+
/** Threads API: conversations, state, messages */
|
|
95
|
+
readonly threads: ThreadsModule;
|
|
96
|
+
/** Tools API: definitions, registry */
|
|
97
|
+
readonly tools: ToolsModule;
|
|
98
|
+
/** Knowledge API: vector stores, RAG */
|
|
99
|
+
readonly knowledge: KnowledgeModule;
|
|
100
|
+
/** Triggers API: webhooks, crons */
|
|
101
|
+
readonly triggers: TriggersModule;
|
|
102
|
+
/** Credentials API: BYOK secrets */
|
|
103
|
+
readonly credentials: CredentialsModule;
|
|
104
|
+
/** Builder API: Meta-agent for AI-assisted agent creation */
|
|
105
|
+
readonly builder: BuilderModule;
|
|
106
|
+
/** Members API: Tenant member management */
|
|
107
|
+
readonly members: MembersModule;
|
|
108
|
+
/** Tenants API: Tenant settings */
|
|
109
|
+
readonly tenants: TenantsModule;
|
|
110
|
+
/** Workspaces API: Workspace management */
|
|
111
|
+
readonly workspaces: WorkspacesModule;
|
|
112
|
+
|
|
113
|
+
// New modules
|
|
114
|
+
/** Prompts API: Prompt Hub CMS */
|
|
115
|
+
readonly prompts: PromptsModule;
|
|
116
|
+
/** Traces API: OTEL observability */
|
|
117
|
+
readonly traces: TracesModule;
|
|
118
|
+
/** Files API: S3 file storage */
|
|
119
|
+
readonly files: FilesModule;
|
|
120
|
+
/** VectorStores API: pgvector semantic search */
|
|
121
|
+
readonly vectorStores: VectorStoresModule;
|
|
122
|
+
/** Evaluation API: Datasets & experiments */
|
|
123
|
+
readonly evaluation: EvaluationModule;
|
|
124
|
+
/** Checkpoints API: Time-travel debugging */
|
|
125
|
+
readonly checkpoints: CheckpointsModule;
|
|
126
|
+
/** Playground API: Ephemeral sandbox */
|
|
127
|
+
readonly playground: PlaygroundModule;
|
|
128
|
+
/** Crons API: Cron job scheduling */
|
|
129
|
+
readonly crons: CronsModule;
|
|
130
|
+
/** DLQ API: Dead letter queue */
|
|
131
|
+
readonly dlq: DlqModule;
|
|
132
|
+
/** Store API: Key-value storage */
|
|
133
|
+
readonly store: StoreModule;
|
|
134
|
+
/** Audit API: Audit logs */
|
|
135
|
+
readonly audit: AuditModule;
|
|
136
|
+
/** Usage API: Quotas and usage */
|
|
137
|
+
readonly usage: UsageModule;
|
|
138
|
+
/** MCP API: Model Context Protocol */
|
|
139
|
+
readonly mcp: McpModule;
|
|
140
|
+
/** A2A API: Agent-to-Agent protocol */
|
|
141
|
+
readonly a2a: A2aModule;
|
|
142
|
+
/** Me API: Current user identity */
|
|
143
|
+
readonly me: MeModule;
|
|
144
|
+
/** Info API: Server information */
|
|
145
|
+
readonly info: InfoModule;
|
|
146
|
+
/** Metrics API: Prometheus metrics */
|
|
147
|
+
readonly metrics: MetricsModule;
|
|
148
|
+
/** Graphs API: Validation and introspection */
|
|
149
|
+
readonly graphs: GraphsModule;
|
|
150
|
+
|
|
151
|
+
// ======================== Convenience Aliases ========================
|
|
152
|
+
/**
|
|
153
|
+
* Alias for evaluation.listExperiments() - provides first-level access to experiments
|
|
154
|
+
* @example client.experiments.list() // same as client.evaluation.listExperiments()
|
|
155
|
+
*/
|
|
156
|
+
readonly experiments: {
|
|
157
|
+
list: EvaluationModule["listExperiments"];
|
|
158
|
+
get: EvaluationModule["getExperiment"];
|
|
159
|
+
create: EvaluationModule["createExperiment"];
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Alias for agents.listVersions() - provides first-level access to agent versions
|
|
164
|
+
*/
|
|
165
|
+
readonly agentVersions: {
|
|
166
|
+
list: (agentId: string) => ReturnType<AgentsModule["listVersions"]>;
|
|
167
|
+
get: (agentId: string, versionId: string) => ReturnType<AgentsModule["getVersion"]>;
|
|
168
|
+
create: (agentId: string, body: Parameters<AgentsModule["createVersion"]>[1]) => ReturnType<AgentsModule["createVersion"]>;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
constructor(options: AgentOsClientOptions) {
|
|
172
|
+
this._baseUrl = options.baseUrl;
|
|
173
|
+
this._kernelBaseUrl = options.kernelBaseUrl ?? options.baseUrl.replace(':5000', ':8001');
|
|
174
|
+
this._tenantId = options.tenantId;
|
|
175
|
+
this._workspaceId = options.workspaceId;
|
|
176
|
+
this._token = options.token;
|
|
177
|
+
this._memberId = options.memberId;
|
|
178
|
+
this._customHeaders = options.headers ?? {};
|
|
179
|
+
|
|
180
|
+
this._client = createRawClient({
|
|
181
|
+
baseUrl: options.baseUrl,
|
|
182
|
+
headers: this._getHeaders(),
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const getHeaders = () => this._getHeaders();
|
|
186
|
+
const getWorkspaceId = () => this._workspaceId;
|
|
187
|
+
const getTenantId = () => this._tenantId;
|
|
188
|
+
|
|
189
|
+
// Initialize core modules
|
|
190
|
+
this.agents = new AgentsModule(this._client, getHeaders);
|
|
191
|
+
this.runs = new RunsModule(this._client, this._baseUrl, getHeaders);
|
|
192
|
+
this.threads = new ThreadsModule(this._client, getHeaders);
|
|
193
|
+
this.tools = new ToolsModule(this._client, getHeaders);
|
|
194
|
+
this.knowledge = new KnowledgeModule(this._client, getWorkspaceId, getHeaders);
|
|
195
|
+
this.triggers = new TriggersModule(this._client, getHeaders);
|
|
196
|
+
this.credentials = new CredentialsModule(this._client, getWorkspaceId, getHeaders);
|
|
197
|
+
this.builder = new BuilderModule(this._kernelBaseUrl, getHeaders);
|
|
198
|
+
this.members = new MembersModule(this._client, getHeaders);
|
|
199
|
+
this.tenants = new TenantsModule(this._client, getHeaders);
|
|
200
|
+
this.workspaces = new WorkspacesModule(this._client, getTenantId, getHeaders);
|
|
201
|
+
|
|
202
|
+
// Initialize new modules
|
|
203
|
+
this.prompts = new PromptsModule(this._client, getHeaders);
|
|
204
|
+
this.traces = new TracesModule(this._client, getHeaders);
|
|
205
|
+
this.files = new FilesModule(this._client, getHeaders);
|
|
206
|
+
this.vectorStores = new VectorStoresModule(this._client, getHeaders);
|
|
207
|
+
this.evaluation = new EvaluationModule(this._client, getHeaders);
|
|
208
|
+
this.checkpoints = new CheckpointsModule(this._client, getHeaders);
|
|
209
|
+
this.playground = new PlaygroundModule(this._client, getHeaders);
|
|
210
|
+
this.crons = new CronsModule(this._client, getHeaders);
|
|
211
|
+
this.dlq = new DlqModule(this._client, getHeaders);
|
|
212
|
+
this.store = new StoreModule(this._client, getHeaders);
|
|
213
|
+
this.audit = new AuditModule(this._client, getHeaders);
|
|
214
|
+
this.usage = new UsageModule(this._client, getHeaders);
|
|
215
|
+
this.mcp = new McpModule(this._client, getHeaders);
|
|
216
|
+
this.a2a = new A2aModule(this._client, getHeaders);
|
|
217
|
+
this.me = new MeModule(this._client, getHeaders);
|
|
218
|
+
this.info = new InfoModule(this._client, getHeaders);
|
|
219
|
+
this.metrics = new MetricsModule(this._baseUrl, getHeaders);
|
|
220
|
+
this.graphs = new GraphsModule(this._client, getHeaders);
|
|
221
|
+
|
|
222
|
+
// Initialize convenience aliases
|
|
223
|
+
this.experiments = {
|
|
224
|
+
list: this.evaluation.listExperiments.bind(this.evaluation),
|
|
225
|
+
get: this.evaluation.getExperiment.bind(this.evaluation),
|
|
226
|
+
create: this.evaluation.createExperiment.bind(this.evaluation),
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
this.agentVersions = {
|
|
230
|
+
list: (agentId: string) => this.agents.listVersions(agentId),
|
|
231
|
+
get: (agentId: string, versionId: string) => this.agents.getVersion(agentId, versionId),
|
|
232
|
+
create: (agentId: string, body: any) => this.agents.createVersion(agentId, body),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
private _getHeaders(): Record<string, string> {
|
|
237
|
+
const headers: Record<string, string> = {
|
|
238
|
+
"Content-Type": "application/json",
|
|
239
|
+
"X-Tenant-Id": this._tenantId,
|
|
240
|
+
"X-Workspace-Id": this._workspaceId,
|
|
241
|
+
...this._customHeaders,
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
if (this._token) {
|
|
245
|
+
headers["Authorization"] = `Bearer ${this._token}`;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (this._memberId) {
|
|
249
|
+
headers["X-Member-Id"] = this._memberId;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return headers;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** Current tenant ID */
|
|
256
|
+
get tenantId(): string {
|
|
257
|
+
return this._tenantId;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Current workspace ID */
|
|
261
|
+
get workspaceId(): string {
|
|
262
|
+
return this._workspaceId;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Raw HTTP client (use modules instead) */
|
|
266
|
+
get raw(): RawClient {
|
|
267
|
+
return this._client;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Helper Types and Functions
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for working with API responses.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { APIResponse } from "./raw.js";
|
|
8
|
+
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Pagination
|
|
11
|
+
// ============================================================================
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Standard pagination parameters used across all list endpoints.
|
|
15
|
+
* Extends Record to be compatible with query parameter types.
|
|
16
|
+
*/
|
|
17
|
+
export interface PaginationParams extends Record<string, unknown> {
|
|
18
|
+
/** Maximum number of items to return (default: 20) */
|
|
19
|
+
limit?: number;
|
|
20
|
+
/** Number of items to skip (default: 0) */
|
|
21
|
+
offset?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Paginated list response wrapper.
|
|
26
|
+
*/
|
|
27
|
+
export interface PaginatedResponse<T> {
|
|
28
|
+
items: T[];
|
|
29
|
+
total: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ============================================================================
|
|
33
|
+
// Error Handling
|
|
34
|
+
// ============================================================================
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* SDK-specific error class with structured error data.
|
|
38
|
+
*/
|
|
39
|
+
export class SDKError extends Error {
|
|
40
|
+
readonly code: string;
|
|
41
|
+
readonly status: number;
|
|
42
|
+
readonly details?: unknown;
|
|
43
|
+
|
|
44
|
+
constructor(response: APIResponse<unknown>) {
|
|
45
|
+
const message = response.error?.message || `HTTP ${response.response.status}`;
|
|
46
|
+
super(message);
|
|
47
|
+
this.name = "SDKError";
|
|
48
|
+
this.code = response.error?.code || `HTTP_${response.response.status}`;
|
|
49
|
+
this.status = response.response.status;
|
|
50
|
+
this.details = response.error?.details;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Unwraps an APIResponse, returning the data directly or throwing on error.
|
|
56
|
+
* Use this when you want the cleaner "throws on error" pattern.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* // Instead of:
|
|
61
|
+
* const { data, error } = await client.agents.list();
|
|
62
|
+
* if (error) throw new Error(error.message);
|
|
63
|
+
*
|
|
64
|
+
* // Use:
|
|
65
|
+
* const agents = await unwrap(client.agents.list());
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export async function unwrap<T>(promise: Promise<APIResponse<T>>): Promise<T> {
|
|
69
|
+
const result = await promise;
|
|
70
|
+
if (result.error || !result.data) {
|
|
71
|
+
throw new SDKError(result);
|
|
72
|
+
}
|
|
73
|
+
return result.data;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Type helper for unwrapped responses.
|
|
78
|
+
*/
|
|
79
|
+
export type Unwrapped<T> = T extends APIResponse<infer U> ? U : never;
|
|
80
|
+
|
|
81
|
+
// ============================================================================
|
|
82
|
+
// Result Pattern (Alternative to exceptions)
|
|
83
|
+
// ============================================================================
|
|
84
|
+
|
|
85
|
+
export type Result<T, E = SDKError> =
|
|
86
|
+
| { success: true; data: T }
|
|
87
|
+
| { success: false; error: E };
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Converts an APIResponse to a Result type for pattern matching.
|
|
91
|
+
*/
|
|
92
|
+
export async function toResult<T>(promise: Promise<APIResponse<T>>): Promise<Result<T>> {
|
|
93
|
+
const result = await promise;
|
|
94
|
+
if (result.error || !result.data) {
|
|
95
|
+
return { success: false, error: new SDKError(result) };
|
|
96
|
+
}
|
|
97
|
+
return { success: true, data: result.data };
|
|
98
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent OS SDK - Raw HTTP Client
|
|
3
|
+
*
|
|
4
|
+
* Fully typed HTTP client using openapi-fetch with generated OpenAPI types.
|
|
5
|
+
* All types are automatically inferred from the backend Swagger specification.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import createClient, { type Client, type FetchOptions } from "openapi-fetch";
|
|
9
|
+
import type { paths, components } from "../generated/openapi.js";
|
|
10
|
+
|
|
11
|
+
// Re-export types for external use
|
|
12
|
+
export type { paths, components };
|
|
13
|
+
|
|
14
|
+
export type ClientOptions = {
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Standard API response wrapper.
|
|
21
|
+
* This matches the pattern used by openapi-fetch.
|
|
22
|
+
*/
|
|
23
|
+
export interface APIResponse<T> {
|
|
24
|
+
data?: T;
|
|
25
|
+
error?: {
|
|
26
|
+
code: string;
|
|
27
|
+
message: string;
|
|
28
|
+
details?: unknown;
|
|
29
|
+
};
|
|
30
|
+
response: Response;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Typed API client using openapi-fetch.
|
|
35
|
+
* All paths and responses are fully typed from OpenAPI spec.
|
|
36
|
+
*/
|
|
37
|
+
export type TypedClient = Client<paths>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Creates a typed HTTP client with openapi-fetch.
|
|
41
|
+
* This provides full type inference for all API endpoints.
|
|
42
|
+
*/
|
|
43
|
+
export function createTypedClient(options: ClientOptions): TypedClient {
|
|
44
|
+
return createClient<paths>({
|
|
45
|
+
baseUrl: options.baseUrl,
|
|
46
|
+
headers: options.headers,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Legacy raw client interface (for backward compatibility).
|
|
52
|
+
* Wraps openapi-fetch to provide the old interface while maintaining types.
|
|
53
|
+
*/
|
|
54
|
+
export function createRawClient(options: ClientOptions) {
|
|
55
|
+
const { baseUrl, headers: defaultHeaders = {} } = options;
|
|
56
|
+
|
|
57
|
+
async function request<T>(
|
|
58
|
+
method: string,
|
|
59
|
+
path: string,
|
|
60
|
+
opts?: {
|
|
61
|
+
params?: { path?: Record<string, string>; query?: Record<string, unknown> };
|
|
62
|
+
body?: unknown;
|
|
63
|
+
headers?: Record<string, string>;
|
|
64
|
+
}
|
|
65
|
+
): Promise<APIResponse<T>> {
|
|
66
|
+
// Replace path params
|
|
67
|
+
let url = path;
|
|
68
|
+
if (opts?.params?.path) {
|
|
69
|
+
for (const [key, value] of Object.entries(opts.params.path)) {
|
|
70
|
+
url = url.replace(`{${key}}`, encodeURIComponent(value));
|
|
71
|
+
// Also handle {id} pattern common in our API
|
|
72
|
+
url = url.replace(`{id}`, encodeURIComponent(value));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Build query string
|
|
77
|
+
if (opts?.params?.query) {
|
|
78
|
+
const query = new URLSearchParams();
|
|
79
|
+
for (const [key, value] of Object.entries(opts.params.query)) {
|
|
80
|
+
if (value !== undefined && value !== null) {
|
|
81
|
+
query.append(key, String(value));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const queryStr = query.toString();
|
|
85
|
+
if (queryStr) {
|
|
86
|
+
url += `?${queryStr}`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const fullUrl = `${baseUrl}${url}`;
|
|
91
|
+
const headers: Record<string, string> = {
|
|
92
|
+
...defaultHeaders,
|
|
93
|
+
...opts?.headers,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
if (opts?.body) {
|
|
97
|
+
headers["Content-Type"] = "application/json";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const response = await fetch(fullUrl, {
|
|
101
|
+
method,
|
|
102
|
+
headers,
|
|
103
|
+
body: opts?.body ? JSON.stringify(opts.body) : undefined,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (!response.ok) {
|
|
107
|
+
let error: APIResponse<T>["error"];
|
|
108
|
+
try {
|
|
109
|
+
const json = await response.json();
|
|
110
|
+
error = {
|
|
111
|
+
code: json.code || `HTTP_${response.status}`,
|
|
112
|
+
message: json.message || response.statusText,
|
|
113
|
+
details: json.details,
|
|
114
|
+
};
|
|
115
|
+
} catch {
|
|
116
|
+
error = {
|
|
117
|
+
code: `HTTP_${response.status}`,
|
|
118
|
+
message: response.statusText,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return { error, response };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Handle no-content responses
|
|
125
|
+
if (response.status === 204) {
|
|
126
|
+
return { data: undefined as T, response };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
const data = await response.json();
|
|
131
|
+
return { data: data as T, response };
|
|
132
|
+
} catch {
|
|
133
|
+
return { data: undefined as T, response };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
GET: <T>(path: string, opts?: Parameters<typeof request>[2]) =>
|
|
139
|
+
request<T>("GET", path, opts),
|
|
140
|
+
POST: <T>(path: string, opts?: Parameters<typeof request>[2]) =>
|
|
141
|
+
request<T>("POST", path, opts),
|
|
142
|
+
PUT: <T>(path: string, opts?: Parameters<typeof request>[2]) =>
|
|
143
|
+
request<T>("PUT", path, opts),
|
|
144
|
+
PATCH: <T>(path: string, opts?: Parameters<typeof request>[2]) =>
|
|
145
|
+
request<T>("PATCH", path, opts),
|
|
146
|
+
DELETE: <T>(path: string, opts?: Parameters<typeof request>[2]) =>
|
|
147
|
+
request<T>("DELETE", path, opts),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export type RawClient = ReturnType<typeof createRawClient>;
|
|
152
|
+
|
|
153
|
+
// ============================================================================
|
|
154
|
+
// Convenience type exports from OpenAPI schemas
|
|
155
|
+
// ============================================================================
|
|
156
|
+
|
|
157
|
+
// Agent types
|
|
158
|
+
export type Agent = components["schemas"]["AgentBundleAgent"];
|
|
159
|
+
export type CreateAgentRequest = components["schemas"]["CreateAgentRequest"];
|
|
160
|
+
export type UpdateAgentRequest = components["schemas"]["UpdateAgentRequest"];
|
|
161
|
+
export type AgentBundle = components["schemas"]["AgentBundle"];
|
|
162
|
+
export type AgentVersion = components["schemas"]["AgentBundleVersion"];
|
|
163
|
+
export type CreateAgentVersionRequest = components["schemas"]["CreateAgentVersionRequest"];
|
|
164
|
+
|
|
165
|
+
// Run types
|
|
166
|
+
export type RunResponse = components["schemas"]["RunResponse"];
|
|
167
|
+
export type RunDetailResponse = components["schemas"]["RunDetailResponse"];
|
|
168
|
+
export type CreateRunRequest = components["schemas"]["CreateRunRequest"];
|
|
169
|
+
export type WaitRunRequest = components["schemas"]["WaitRunRequest"];
|
|
170
|
+
export type WaitRunResponse = components["schemas"]["WaitRunResponse"];
|
|
171
|
+
export type BatchRunRequest = components["schemas"]["BatchRunRequest"];
|
|
172
|
+
export type BatchRunResponse = components["schemas"]["BatchRunResponse"];
|
|
173
|
+
export type ReplayRequest = components["schemas"]["ReplayRequest"];
|
|
174
|
+
export type CancelRequest = components["schemas"]["CancelRequest"];
|
|
175
|
+
export type CancelRunResponse = components["schemas"]["CancelRunResponse"];
|
|
176
|
+
|
|
177
|
+
// Thread types
|
|
178
|
+
export type ThreadRequest = components["schemas"]["ThreadRequest"];
|
|
179
|
+
export type ThreadSearchRequest = components["schemas"]["ThreadSearchRequest"];
|
|
180
|
+
export type ThreadCopyRequest = components["schemas"]["ThreadCopyRequest"];
|
|
181
|
+
export type ThreadPruneRequest = components["schemas"]["ThreadPruneRequest"];
|
|
182
|
+
export type AddMessageRequest = components["schemas"]["AddMessageRequest"];
|
|
183
|
+
|
|
184
|
+
// Checkpoint types
|
|
185
|
+
export type CheckpointDetail = components["schemas"]["CheckpointDetail"];
|
|
186
|
+
export type CheckpointNode = components["schemas"]["CheckpointNode"];
|
|
187
|
+
export type CheckpointListResponse = components["schemas"]["CheckpointListResponse"];
|
|
188
|
+
export type CheckpointIndexResponse = components["schemas"]["CheckpointIndexResponse"];
|
|
189
|
+
export type CreateCheckpointRequest = components["schemas"]["CreateCheckpointRequest"];
|
|
190
|
+
|
|
191
|
+
// Credential types
|
|
192
|
+
export type CreateCredentialRequest = components["schemas"]["CreateCredentialRequest"];
|
|
193
|
+
export type UpdateCredentialRequest = components["schemas"]["UpdateCredentialRequest"];
|
|
194
|
+
|
|
195
|
+
// Evaluation types
|
|
196
|
+
export type CreateDatasetRequest = components["schemas"]["CreateDatasetRequest"];
|
|
197
|
+
export type CreateExperimentRequest = components["schemas"]["CreateExperimentRequest"];
|
|
198
|
+
export type ExampleData = components["schemas"]["ExampleData"];
|
|
199
|
+
export type AddExamplesRequest = components["schemas"]["AddExamplesRequest"];
|
|
200
|
+
|
|
201
|
+
// Vector Store types
|
|
202
|
+
export type VectorStoreResponse = components["schemas"]["VectorStoreResponse"];
|
|
203
|
+
export type VectorQueryRequest = components["schemas"]["VectorQueryRequest"];
|
|
204
|
+
export type VectorQueryResponse = components["schemas"]["VectorQueryResponse"];
|
|
205
|
+
export type VectorSearchResult = components["schemas"]["VectorSearchResult"];
|
|
206
|
+
export type VectorStoreFileResponse = components["schemas"]["VectorStoreFileResponse"];
|
|
207
|
+
|
|
208
|
+
// Cron types
|
|
209
|
+
export type CreateCronJobRequest = components["schemas"]["CreateCronJobRequest"];
|
|
210
|
+
export type UpdateCronJobRequest = components["schemas"]["UpdateCronJobRequest"];
|
|
211
|
+
|
|
212
|
+
// Member types
|
|
213
|
+
export type InviteMemberRequest = components["schemas"]["InviteMemberRequest"];
|
|
214
|
+
export type UpdateMemberRequest = components["schemas"]["UpdateMemberRequest"];
|
|
215
|
+
|
|
216
|
+
// Tenant/Workspace types
|
|
217
|
+
export type UpdateTenantRequest = components["schemas"]["UpdateTenantRequest"];
|
|
218
|
+
export type UpdateWorkspaceRequest = components["schemas"]["UpdateWorkspaceRequest"];
|
|
219
|
+
|
|
220
|
+
// Prompt types
|
|
221
|
+
export type CreatePromptRequest = components["schemas"]["CreatePromptRequest"];
|
|
222
|
+
export type CreatePromptVersionRequest = components["schemas"]["CreatePromptVersionRequest"];
|
|
223
|
+
|
|
224
|
+
// File types
|
|
225
|
+
export type CreatePresignedUploadRequest = components["schemas"]["CreatePresignedUploadRequest"];
|
|
226
|
+
export type PresignedUploadResponse = components["schemas"]["PresignedUploadResponse"];
|
|
227
|
+
export type ConfirmUploadRequest = components["schemas"]["ConfirmUploadRequest"];
|
|
228
|
+
|
|
229
|
+
// Trace types
|
|
230
|
+
export type SpanData = components["schemas"]["SpanData"];
|
|
231
|
+
export type BatchIngestRequest = components["schemas"]["BatchIngestRequest"];
|
|
232
|
+
export type AddFeedbackRequest = components["schemas"]["AddFeedbackRequest"];
|
|
233
|
+
|
|
234
|
+
// Trigger types
|
|
235
|
+
export type UpdateTriggerRequest = components["schemas"]["UpdateTriggerRequest"];
|
|
236
|
+
|
|
237
|
+
// Store types
|
|
238
|
+
export type StoreValueRequest = components["schemas"]["StoreValueRequest"];
|
|
239
|
+
|
|
240
|
+
// Problem details (errors)
|
|
241
|
+
export type ProblemDetails = components["schemas"]["ProblemDetails"];
|