@agent-os-sdk/client 0.9.14 → 0.9.16
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 +8 -4
- package/dist/client/AgentOsClient.d.ts.map +1 -1
- package/dist/client/AgentOsClient.js +12 -6
- package/dist/errors/factory.d.ts +2 -0
- package/dist/errors/factory.d.ts.map +1 -1
- package/dist/errors/factory.js +5 -1
- package/dist/generated/openapi.d.ts +544 -744
- package/dist/generated/openapi.d.ts.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/modules/agents.d.ts +25 -7
- package/dist/modules/agents.d.ts.map +1 -1
- package/dist/modules/agents.js +36 -7
- package/dist/modules/catalog.d.ts +63 -0
- package/dist/modules/catalog.d.ts.map +1 -1
- package/dist/modules/catalog.js +5 -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/evaluation.d.ts +64 -0
- package/dist/modules/evaluation.d.ts.map +1 -1
- package/dist/modules/evaluation.js +12 -0
- package/dist/modules/improvements.d.ts +52 -0
- package/dist/modules/improvements.d.ts.map +1 -0
- package/dist/modules/improvements.js +27 -0
- package/dist/modules/metaAgent.d.ts +62 -0
- package/dist/modules/metaAgent.d.ts.map +1 -0
- package/dist/modules/metaAgent.js +25 -0
- package/dist/modules/presets.d.ts.map +1 -1
- package/dist/modules/presets.js +113 -44
- package/dist/modules/runs.d.ts +9 -0
- package/dist/modules/runs.d.ts.map +1 -1
- package/dist/modules/runs.js +14 -1
- package/dist/modules/templates.d.ts +28 -0
- package/dist/modules/templates.d.ts.map +1 -0
- package/dist/modules/templates.js +19 -0
- package/dist/modules/tools.d.ts +15 -0
- package/dist/modules/tools.d.ts.map +1 -1
- package/dist/modules/tools.js +6 -0
- package/package.json +51 -52
- package/src/client/AgentOsClient.ts +12 -6
- package/src/errors/factory.ts +7 -2
- package/src/generated/openapi.ts +544 -744
- package/src/generated/swagger.json +551 -924
- package/src/index.ts +22 -2
- package/src/modules/agents.ts +62 -8
- package/src/modules/catalog.ts +73 -0
- package/src/modules/contracts.ts +80 -0
- package/src/modules/evaluation.ts +80 -0
- package/src/modules/improvements.ts +71 -0
- package/src/modules/metaAgent.ts +87 -0
- package/src/modules/presets.ts +118 -50
- package/src/modules/runs.ts +20 -1
- package/src/modules/templates.ts +40 -0
- package/src/modules/tools.ts +23 -0
- package/src/modules/builder.ts +0 -456
- package/src/modules/graphs.ts +0 -188
package/src/modules/builder.ts
DELETED
|
@@ -1,456 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Builder Module - Meta-Agent for Agent Building
|
|
3
|
-
*
|
|
4
|
-
* Connects to the Control Plane's builder endpoint which proxies to the
|
|
5
|
-
* Data Plane's meta-agent for AI-assisted agent creation.
|
|
6
|
-
* Uses SSE streaming for real-time responses and graph updates.
|
|
7
|
-
*
|
|
8
|
-
* Flow: Frontend → CP:5000/v1/api/builder/{agentId}/chat → DP:8001/v1/internal/builder/{agentId}/chat
|
|
9
|
-
*
|
|
10
|
-
* ALL HTTP goes through rawClient - no direct fetch calls.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* const client = new AgentOsClient({ ... })
|
|
15
|
-
*
|
|
16
|
-
* // SSE streaming chat
|
|
17
|
-
* for await (const event of client.builder.chat(agentId, {
|
|
18
|
-
* message: "Adicione um nó de pesquisa web",
|
|
19
|
-
* current_graph_spec: { nodes: [...], edges: [...] }
|
|
20
|
-
* })) {
|
|
21
|
-
* if (event.type === 'message') console.log(event.data.text)
|
|
22
|
-
* if (event.type === 'graph_update') applyAction(event.data)
|
|
23
|
-
* }
|
|
24
|
-
*
|
|
25
|
-
* // Sync chat (no streaming)
|
|
26
|
-
* const result = await client.builder.chatSync(agentId, { message: "Mude as instruções" })
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
import type { RawClient, APIResponse } from "../client/raw.js";
|
|
31
|
-
import type { SSEOptions } from "../sse/client.js";
|
|
32
|
-
|
|
33
|
-
export type CatalogVersions = {
|
|
34
|
-
nodes: string;
|
|
35
|
-
tools: string;
|
|
36
|
-
triggers: string;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export type ChatHistoryMessage = {
|
|
40
|
-
role: 'user' | 'assistant';
|
|
41
|
-
content: string;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Builder chat request.
|
|
46
|
-
*
|
|
47
|
-
* KERNEL-FIRST: Frontend sends INTENTION only.
|
|
48
|
-
* - Graph spec is loaded from artifact storage by CP
|
|
49
|
-
* - Catalogs are loaded from DB by CP
|
|
50
|
-
* - Frontend should NOT send graph_spec or catalogs
|
|
51
|
-
*/
|
|
52
|
-
export type BuilderChatRequest = {
|
|
53
|
-
/** Chat message/intention */
|
|
54
|
-
message: string;
|
|
55
|
-
/** Thread ID for conversation continuity */
|
|
56
|
-
thread_id?: string;
|
|
57
|
-
/** Chat history for context (optional, sent from frontend) */
|
|
58
|
-
history?: { role: 'user' | 'assistant'; content: string }[];
|
|
59
|
-
/** Optional ETag for concurrency control */
|
|
60
|
-
base_graph_etag?: string;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export type HintTargetModel = {
|
|
64
|
-
node_id?: string;
|
|
65
|
-
edge_id?: string;
|
|
66
|
-
panel?: "credentials" | "triggers" | "logs" | "validation" | "deploy" | string;
|
|
67
|
-
action?: "create_credential" | "save_draft" | "publish_version" | string;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export type HintDataModel = {
|
|
71
|
-
// Credential hints
|
|
72
|
-
credential_slug?: string;
|
|
73
|
-
reason?: string;
|
|
74
|
-
|
|
75
|
-
// Config hints
|
|
76
|
-
fields?: string[];
|
|
77
|
-
|
|
78
|
-
// Error/validation hints
|
|
79
|
-
code?: string;
|
|
80
|
-
path?: string;
|
|
81
|
-
|
|
82
|
-
// Run/execution hints
|
|
83
|
-
run_id?: string;
|
|
84
|
-
error_code?: string;
|
|
85
|
-
|
|
86
|
-
// Cost/performance hints
|
|
87
|
-
tokens_in?: number;
|
|
88
|
-
tokens_out?: number;
|
|
89
|
-
usd_estimate?: number;
|
|
90
|
-
|
|
91
|
-
// Action hints
|
|
92
|
-
action_id?: string;
|
|
93
|
-
params?: Record<string, any>;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export type HintModel = {
|
|
97
|
-
id?: string;
|
|
98
|
-
scope: "graph" | "thread" | "run" | string;
|
|
99
|
-
type:
|
|
100
|
-
| "highlight_node"
|
|
101
|
-
| "needs_credential"
|
|
102
|
-
| "missing_config"
|
|
103
|
-
| "error_marker"
|
|
104
|
-
| "warning_marker"
|
|
105
|
-
| "toast"
|
|
106
|
-
| "run_started"
|
|
107
|
-
| "node_running"
|
|
108
|
-
| "node_failed"
|
|
109
|
-
| "rate_limited"
|
|
110
|
-
| "cost_estimate"
|
|
111
|
-
| "action_suggested"
|
|
112
|
-
| string;
|
|
113
|
-
severity: "info" | "warn" | "error" | "success";
|
|
114
|
-
target?: HintTargetModel;
|
|
115
|
-
message?: string;
|
|
116
|
-
ttl_ms?: number;
|
|
117
|
-
data?: HintDataModel;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export type GraphUpdateAction = {
|
|
121
|
-
graph_spec: Record<string, unknown>;
|
|
122
|
-
hints?: HintModel[];
|
|
123
|
-
has_errors?: boolean;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
export type BuilderStreamEvent =
|
|
127
|
-
| { type: "message"; data: { text: string } }
|
|
128
|
-
| { type: "validation"; data: { valid: boolean; errors: any[] } }
|
|
129
|
-
| { type: "graph_update"; data: { graph_spec: Record<string, unknown>; hints: HintModel[]; has_errors?: boolean } }
|
|
130
|
-
| { type: "done"; data: { response: string; thread_id: string } }
|
|
131
|
-
| { type: "error"; data: { error: string } };
|
|
132
|
-
|
|
133
|
-
export type BuilderChatResponse = {
|
|
134
|
-
response: string;
|
|
135
|
-
graph_spec?: Record<string, unknown>;
|
|
136
|
-
valid: boolean;
|
|
137
|
-
errors: any[];
|
|
138
|
-
thread_id: string;
|
|
139
|
-
hints: HintModel[];
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
// ============================================
|
|
143
|
-
// PATCH-OPS ARCHITECTURE (Meta-Agent V2)
|
|
144
|
-
// ============================================
|
|
145
|
-
|
|
146
|
-
/** Supported patch operation types */
|
|
147
|
-
export type OpType =
|
|
148
|
-
| "add_node"
|
|
149
|
-
| "remove_node"
|
|
150
|
-
| "update_node"
|
|
151
|
-
| "add_edge"
|
|
152
|
-
| "remove_edge"
|
|
153
|
-
| "set_entrypoint"
|
|
154
|
-
| "rename_node";
|
|
155
|
-
|
|
156
|
-
/** A single graph modification operation */
|
|
157
|
-
export type PatchOp = {
|
|
158
|
-
op: OpType;
|
|
159
|
-
node_id?: string;
|
|
160
|
-
kind?: string;
|
|
161
|
-
label?: string;
|
|
162
|
-
data?: Record<string, unknown>;
|
|
163
|
-
set?: Record<string, unknown>;
|
|
164
|
-
from?: string;
|
|
165
|
-
to?: string;
|
|
166
|
-
entrypoint?: string;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
/** A collection of patch operations with deterministic ID */
|
|
170
|
-
export type GraphPatch = {
|
|
171
|
-
patch_id: string;
|
|
172
|
-
ops: PatchOp[];
|
|
173
|
-
description?: string;
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
/** Validation error from applying patch */
|
|
177
|
-
export type PatchValidationError = {
|
|
178
|
-
code: string;
|
|
179
|
-
message: string;
|
|
180
|
-
node_id?: string;
|
|
181
|
-
path?: string;
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
/** Meta-chat request */
|
|
185
|
-
export type MetaChatRequest = {
|
|
186
|
-
instruction: string;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
/** Meta-chat stream events */
|
|
190
|
-
export type MetaChatStreamEvent =
|
|
191
|
-
| { type: "assistant.delta"; data: { text: string } }
|
|
192
|
-
| { type: "patch.validation"; data: { valid: boolean; errors: PatchValidationError[] } }
|
|
193
|
-
| { type: "patch.proposed"; data: GraphPatch }
|
|
194
|
-
| { type: "final"; data: { ok: boolean; patch_id: string } }
|
|
195
|
-
| { type: "error"; data: { error: string } };
|
|
196
|
-
|
|
197
|
-
/** Meta-chat sync response */
|
|
198
|
-
export type MetaChatResponse = {
|
|
199
|
-
patch: GraphPatch | null;
|
|
200
|
-
applied_spec: Record<string, unknown> | null;
|
|
201
|
-
valid: boolean;
|
|
202
|
-
errors: PatchValidationError[];
|
|
203
|
-
message: string;
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
export class BuilderModule {
|
|
208
|
-
constructor(private client: RawClient) { }
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Stream chat with meta-agent (SSE).
|
|
212
|
-
* Returns async generator of events.
|
|
213
|
-
*
|
|
214
|
-
* Uses rawClient.streamPost() - headers resolved asynchronously.
|
|
215
|
-
*/
|
|
216
|
-
async *chat(
|
|
217
|
-
agentId: string,
|
|
218
|
-
request: BuilderChatRequest,
|
|
219
|
-
options?: SSEOptions
|
|
220
|
-
): AsyncGenerator<BuilderStreamEvent> {
|
|
221
|
-
// Use rawClient.streamPost() - ALL auth headers resolved automatically
|
|
222
|
-
const response = await this.client.streamPost("/v1/api/builder/{agentId}/chat", {
|
|
223
|
-
params: { path: { agentId } },
|
|
224
|
-
body: request,
|
|
225
|
-
signal: options?.signal,
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
if (!response.ok) {
|
|
229
|
-
const errorText = await response.text();
|
|
230
|
-
throw new Error(`Builder chat failed: ${response.status} - ${errorText}`);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (!response.body) {
|
|
234
|
-
throw new Error("No response body");
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
options?.onOpen?.();
|
|
238
|
-
|
|
239
|
-
const reader = response.body.getReader();
|
|
240
|
-
const decoder = new TextDecoder();
|
|
241
|
-
let buffer = "";
|
|
242
|
-
|
|
243
|
-
try {
|
|
244
|
-
while (true) {
|
|
245
|
-
const { done, value } = await reader.read();
|
|
246
|
-
if (done) break;
|
|
247
|
-
|
|
248
|
-
buffer += decoder.decode(value, { stream: true });
|
|
249
|
-
const lines = buffer.split("\n");
|
|
250
|
-
buffer = lines.pop() ?? "";
|
|
251
|
-
|
|
252
|
-
let eventType = "message";
|
|
253
|
-
let eventData = "";
|
|
254
|
-
|
|
255
|
-
for (const line of lines) {
|
|
256
|
-
if (line.startsWith("event:")) {
|
|
257
|
-
eventType = line.slice(6).trim();
|
|
258
|
-
} else if (line.startsWith("data:")) {
|
|
259
|
-
eventData = line.slice(5).trim();
|
|
260
|
-
} else if (line === "" && eventData) {
|
|
261
|
-
try {
|
|
262
|
-
const parsed = JSON.parse(eventData);
|
|
263
|
-
yield { type: eventType, data: parsed } as BuilderStreamEvent;
|
|
264
|
-
} catch {
|
|
265
|
-
// Skip invalid JSON
|
|
266
|
-
}
|
|
267
|
-
eventData = "";
|
|
268
|
-
eventType = "message";
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
} finally {
|
|
273
|
-
reader.releaseLock();
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Sync chat with meta-agent (no streaming).
|
|
279
|
-
*
|
|
280
|
-
* Uses rawClient.POST() - headers resolved asynchronously.
|
|
281
|
-
*/
|
|
282
|
-
async chatSync(
|
|
283
|
-
agentId: string,
|
|
284
|
-
request: BuilderChatRequest
|
|
285
|
-
): Promise<BuilderChatResponse> {
|
|
286
|
-
const { data, error } = await this.client.POST<BuilderChatResponse>(
|
|
287
|
-
"/v1/api/builder/{agentId}/chat/sync",
|
|
288
|
-
{
|
|
289
|
-
params: { path: { agentId } },
|
|
290
|
-
body: request,
|
|
291
|
-
}
|
|
292
|
-
);
|
|
293
|
-
|
|
294
|
-
if (error) {
|
|
295
|
-
throw new Error(`Builder chat failed: ${error.code} - ${error.message}`);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
return data!;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Convenience method: chat and collect all events.
|
|
303
|
-
*/
|
|
304
|
-
async chatCollect(
|
|
305
|
-
agentId: string,
|
|
306
|
-
request: BuilderChatRequest
|
|
307
|
-
): Promise<BuilderChatResponse> {
|
|
308
|
-
let fullResponse = "";
|
|
309
|
-
let lastGraphSpec: Record<string, unknown> | undefined;
|
|
310
|
-
let allHints: HintModel[] = [];
|
|
311
|
-
const allErrors: any[] = [];
|
|
312
|
-
let threadId = request.thread_id ?? "";
|
|
313
|
-
let isValid = true;
|
|
314
|
-
|
|
315
|
-
for await (const event of this.chat(agentId, request)) {
|
|
316
|
-
if (event.type === "message") {
|
|
317
|
-
fullResponse += event.data.text;
|
|
318
|
-
} else if (event.type === "graph_update") {
|
|
319
|
-
if ('graph_spec' in event.data) {
|
|
320
|
-
lastGraphSpec = event.data.graph_spec;
|
|
321
|
-
if (event.data.hints) {
|
|
322
|
-
allHints.push(...event.data.hints);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
} else if (event.type === "validation") {
|
|
326
|
-
isValid = event.data.valid;
|
|
327
|
-
if (event.data.errors) {
|
|
328
|
-
allErrors.push(...event.data.errors);
|
|
329
|
-
}
|
|
330
|
-
} else if (event.type === "done") {
|
|
331
|
-
threadId = event.data.thread_id;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
return {
|
|
336
|
-
response: fullResponse,
|
|
337
|
-
graph_spec: lastGraphSpec,
|
|
338
|
-
hints: allHints,
|
|
339
|
-
valid: isValid,
|
|
340
|
-
errors: allErrors,
|
|
341
|
-
thread_id: threadId,
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// ============================================
|
|
346
|
-
// META-CHAT V2 (PATCH-OPS ARCHITECTURE)
|
|
347
|
-
// ============================================
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Stream meta-chat with patch-ops architecture (SSE).
|
|
351
|
-
* Returns GraphPatch proposals instead of full graph specs.
|
|
352
|
-
*
|
|
353
|
-
* @example
|
|
354
|
-
* ```ts
|
|
355
|
-
* for await (const event of client.builder.metaChat(agentId, {
|
|
356
|
-
* instruction: "Add a log node after the main agent"
|
|
357
|
-
* })) {
|
|
358
|
-
* if (event.type === 'patch.proposed') {
|
|
359
|
-
* const patch = event.data;
|
|
360
|
-
* console.log(`Proposed ${patch.ops.length} operations`);
|
|
361
|
-
* }
|
|
362
|
-
* }
|
|
363
|
-
* ```
|
|
364
|
-
*/
|
|
365
|
-
async *metaChat(
|
|
366
|
-
agentId: string,
|
|
367
|
-
request: MetaChatRequest,
|
|
368
|
-
options?: SSEOptions
|
|
369
|
-
): AsyncGenerator<MetaChatStreamEvent> {
|
|
370
|
-
const response = await this.client.streamPost("/v1/builder/{agentId}/meta-chat", {
|
|
371
|
-
params: { path: { agentId } },
|
|
372
|
-
body: request,
|
|
373
|
-
signal: options?.signal,
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
if (!response.ok) {
|
|
377
|
-
const errorText = await response.text();
|
|
378
|
-
throw new Error(`Meta-chat failed: ${response.status} - ${errorText}`);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
if (!response.body) {
|
|
382
|
-
throw new Error("No response body");
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
options?.onOpen?.();
|
|
386
|
-
|
|
387
|
-
const reader = response.body.getReader();
|
|
388
|
-
const decoder = new TextDecoder();
|
|
389
|
-
let buffer = "";
|
|
390
|
-
|
|
391
|
-
try {
|
|
392
|
-
while (true) {
|
|
393
|
-
const { done, value } = await reader.read();
|
|
394
|
-
if (done) break;
|
|
395
|
-
|
|
396
|
-
buffer += decoder.decode(value, { stream: true });
|
|
397
|
-
const lines = buffer.split("\n");
|
|
398
|
-
buffer = lines.pop() ?? "";
|
|
399
|
-
|
|
400
|
-
let eventType = "message";
|
|
401
|
-
let eventData = "";
|
|
402
|
-
|
|
403
|
-
for (const line of lines) {
|
|
404
|
-
if (line.startsWith("event:")) {
|
|
405
|
-
eventType = line.slice(6).trim();
|
|
406
|
-
} else if (line.startsWith("data:")) {
|
|
407
|
-
eventData = line.slice(5).trim();
|
|
408
|
-
} else if (line === "" && eventData) {
|
|
409
|
-
try {
|
|
410
|
-
const parsed = JSON.parse(eventData);
|
|
411
|
-
yield { type: eventType, data: parsed } as MetaChatStreamEvent;
|
|
412
|
-
} catch {
|
|
413
|
-
// Skip invalid JSON
|
|
414
|
-
}
|
|
415
|
-
eventData = "";
|
|
416
|
-
eventType = "message";
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
} finally {
|
|
421
|
-
reader.releaseLock();
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Meta-chat and collect the proposed patch.
|
|
427
|
-
*/
|
|
428
|
-
async metaChatCollect(
|
|
429
|
-
agentId: string,
|
|
430
|
-
request: MetaChatRequest
|
|
431
|
-
): Promise<MetaChatResponse> {
|
|
432
|
-
let patch: GraphPatch | null = null;
|
|
433
|
-
let isValid = true;
|
|
434
|
-
const errors: PatchValidationError[] = [];
|
|
435
|
-
let message = "";
|
|
436
|
-
|
|
437
|
-
for await (const event of this.metaChat(agentId, request)) {
|
|
438
|
-
if (event.type === "assistant.delta") {
|
|
439
|
-
message += event.data.text;
|
|
440
|
-
} else if (event.type === "patch.proposed") {
|
|
441
|
-
patch = event.data;
|
|
442
|
-
} else if (event.type === "patch.validation") {
|
|
443
|
-
isValid = event.data.valid;
|
|
444
|
-
errors.push(...event.data.errors);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
return {
|
|
449
|
-
patch,
|
|
450
|
-
applied_spec: null, // Frontend should apply patch locally
|
|
451
|
-
valid: isValid,
|
|
452
|
-
errors,
|
|
453
|
-
message,
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
}
|
package/src/modules/graphs.ts
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Graphs Module - V2 Graph Specification Management
|
|
3
|
-
*
|
|
4
|
-
* Pure V2 contract - no legacy. All types namespaced with "Graphs" prefix.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { RawClient, APIResponse } from "../client/raw.js";
|
|
8
|
-
|
|
9
|
-
// ============ Shared Types ============
|
|
10
|
-
|
|
11
|
-
export interface GraphsValidationMessage {
|
|
12
|
-
code: string;
|
|
13
|
-
message: string;
|
|
14
|
-
path?: string;
|
|
15
|
-
node_id?: string;
|
|
16
|
-
severity?: "error" | "warning";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface GraphsValidationResult {
|
|
20
|
-
valid: boolean;
|
|
21
|
-
errors?: GraphsValidationMessage[];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// ============ GET /v2/api/graph/{agentId} ============
|
|
25
|
-
|
|
26
|
-
export interface GraphsGetResponse {
|
|
27
|
-
agent_id: string;
|
|
28
|
-
revision: string;
|
|
29
|
-
canonical_spec: unknown;
|
|
30
|
-
committed_at: string;
|
|
31
|
-
warnings?: GraphsValidationMessage[];
|
|
32
|
-
validation?: GraphsValidationResult;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// ============ POST /v2/api/graph/commit ============
|
|
36
|
-
|
|
37
|
-
export interface GraphsCommitRequest {
|
|
38
|
-
agent_id: string;
|
|
39
|
-
graph_spec: unknown;
|
|
40
|
-
expected_revision?: string;
|
|
41
|
-
source?: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export type GraphsCommitStatus = "committed" | "no_change";
|
|
45
|
-
|
|
46
|
-
export interface GraphsCommitResponse {
|
|
47
|
-
status: GraphsCommitStatus;
|
|
48
|
-
agent_id: string;
|
|
49
|
-
revision: string;
|
|
50
|
-
canonical_spec: unknown;
|
|
51
|
-
committed_at: string;
|
|
52
|
-
warnings?: GraphsValidationMessage[];
|
|
53
|
-
validation?: GraphsValidationResult;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// 409 Conflict body (ProblemDetails.Extensions)
|
|
57
|
-
// Envelope around GET response - agent_id lives in current.agent_id
|
|
58
|
-
export interface GraphsConflictPayload {
|
|
59
|
-
hint: "reload_and_retry";
|
|
60
|
-
expected_revision: string;
|
|
61
|
-
current: GraphsGetResponse;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// ============ GET /v2/api/graph/{agentId}/revisions ============
|
|
65
|
-
|
|
66
|
-
export interface GraphsRevisionSummary {
|
|
67
|
-
revision: string;
|
|
68
|
-
created_at: string;
|
|
69
|
-
source?: string;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface GraphsRevisionsListResponse {
|
|
73
|
-
agent_id: string;
|
|
74
|
-
revisions: GraphsRevisionSummary[];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// ============ GET /v2/api/graph/{agentId}/revisions/{revision} ============
|
|
78
|
-
|
|
79
|
-
export interface GraphsRevisionResponse {
|
|
80
|
-
revision: string;
|
|
81
|
-
canonical_spec: unknown;
|
|
82
|
-
created_at: string;
|
|
83
|
-
source?: string;
|
|
84
|
-
warnings?: GraphsValidationMessage[];
|
|
85
|
-
validation?: GraphsValidationResult;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// ============ Validation (DP) ============
|
|
89
|
-
|
|
90
|
-
export interface GraphsValidateRequest {
|
|
91
|
-
graph_spec: unknown;
|
|
92
|
-
normalize?: boolean;
|
|
93
|
-
catalog_versions?: Record<string, string>;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export interface GraphsValidateResponse {
|
|
97
|
-
valid: boolean;
|
|
98
|
-
canonical_spec_json?: string;
|
|
99
|
-
mermaid?: string;
|
|
100
|
-
nodes?: string[];
|
|
101
|
-
edges?: [string, string][];
|
|
102
|
-
errors?: GraphsValidationMessage[];
|
|
103
|
-
warnings?: GraphsValidationMessage[];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// ============ Introspection (DP) ============
|
|
107
|
-
|
|
108
|
-
export interface GraphsIntrospectRequest {
|
|
109
|
-
agent_id?: string;
|
|
110
|
-
graph_spec?: unknown;
|
|
111
|
-
catalog_versions?: Record<string, string>;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface GraphsIntrospectResponse {
|
|
115
|
-
mermaid: string;
|
|
116
|
-
nodes: string[];
|
|
117
|
-
edges: [string, string][];
|
|
118
|
-
type?: string;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// ============ Module ============
|
|
122
|
-
|
|
123
|
-
export class GraphsModule {
|
|
124
|
-
constructor(private client: RawClient, private headers: () => Record<string, string>) { }
|
|
125
|
-
|
|
126
|
-
// ============ V2 Graph Spec (CP) ============
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Get current graph spec by revision.
|
|
130
|
-
* @returns 200 with graph spec, or 404 if not initialized
|
|
131
|
-
*/
|
|
132
|
-
async get(agentId: string): Promise<APIResponse<GraphsGetResponse>> {
|
|
133
|
-
return this.client.GET<GraphsGetResponse>(`/v1/api/graph/${agentId}`, {
|
|
134
|
-
headers: this.headers(),
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Commit graph spec atomically.
|
|
140
|
-
* @returns 200 (committed/no_change), or 409 on conflict
|
|
141
|
-
*/
|
|
142
|
-
async commit(request: GraphsCommitRequest): Promise<APIResponse<GraphsCommitResponse>> {
|
|
143
|
-
return this.client.POST<GraphsCommitResponse>("/v1/api/graph/commit", {
|
|
144
|
-
body: request,
|
|
145
|
-
headers: this.headers(),
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* List revision history for an agent.
|
|
151
|
-
*/
|
|
152
|
-
async listRevisions(agentId: string): Promise<APIResponse<GraphsRevisionsListResponse>> {
|
|
153
|
-
return this.client.GET<GraphsRevisionsListResponse>(`/v1/api/graph/${agentId}/revisions`, {
|
|
154
|
-
headers: this.headers(),
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Get a specific revision.
|
|
160
|
-
*/
|
|
161
|
-
async getRevision(agentId: string, revision: string): Promise<APIResponse<GraphsRevisionResponse>> {
|
|
162
|
-
return this.client.GET<GraphsRevisionResponse>(`/v1/api/graph/${agentId}/revisions/${revision}`, {
|
|
163
|
-
headers: this.headers(),
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// ============ Validation (DP proxy) ============
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Validate a graph specification.
|
|
171
|
-
*/
|
|
172
|
-
async validate(body: GraphsValidateRequest): Promise<APIResponse<GraphsValidateResponse>> {
|
|
173
|
-
return this.client.POST<GraphsValidateResponse>("/v1/api/graphs/validate", {
|
|
174
|
-
body,
|
|
175
|
-
headers: this.headers(),
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Introspect a graph structure.
|
|
181
|
-
*/
|
|
182
|
-
async introspect(body: GraphsIntrospectRequest): Promise<APIResponse<GraphsIntrospectResponse>> {
|
|
183
|
-
return this.client.POST<GraphsIntrospectResponse>("/v1/api/graphs/introspect", {
|
|
184
|
-
body,
|
|
185
|
-
headers: this.headers(),
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|