@agent-os-sdk/client 0.9.25 → 0.9.26
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/package.json +15 -8
- package/src/generated/openapi.ts +82 -0
- package/src/generated/swagger.json +163 -0
- package/src/modules/templates.ts +35 -0
- package/dist/client/AgentOsClient.d.ts +0 -141
- package/dist/client/AgentOsClient.d.ts.map +0 -1
- package/dist/client/AgentOsClient.js +0 -250
- package/dist/client/HttpRequestBuilder.d.ts +0 -50
- package/dist/client/HttpRequestBuilder.d.ts.map +0 -1
- package/dist/client/HttpRequestBuilder.js +0 -83
- package/dist/client/OperationContext.d.ts +0 -19
- package/dist/client/OperationContext.d.ts.map +0 -1
- package/dist/client/OperationContext.js +0 -13
- package/dist/client/OperationContextProvider.d.ts +0 -54
- package/dist/client/OperationContextProvider.d.ts.map +0 -1
- package/dist/client/OperationContextProvider.js +0 -71
- package/dist/client/auth.d.ts +0 -100
- package/dist/client/auth.d.ts.map +0 -1
- package/dist/client/auth.js +0 -38
- package/dist/client/config.d.ts +0 -49
- package/dist/client/config.d.ts.map +0 -1
- package/dist/client/config.js +0 -62
- package/dist/client/helpers.d.ts +0 -63
- package/dist/client/helpers.d.ts.map +0 -1
- package/dist/client/helpers.js +0 -55
- package/dist/client/pagination.d.ts +0 -105
- package/dist/client/pagination.d.ts.map +0 -1
- package/dist/client/pagination.js +0 -117
- package/dist/client/raw.d.ts +0 -277
- package/dist/client/raw.d.ts.map +0 -1
- package/dist/client/raw.js +0 -337
- package/dist/client/retry.d.ts +0 -37
- package/dist/client/retry.d.ts.map +0 -1
- package/dist/client/retry.js +0 -108
- package/dist/client/sanitize.d.ts +0 -19
- package/dist/client/sanitize.d.ts.map +0 -1
- package/dist/client/sanitize.js +0 -28
- package/dist/client/timeout.d.ts +0 -26
- package/dist/client/timeout.d.ts.map +0 -1
- package/dist/client/timeout.js +0 -51
- package/dist/errors/factory.d.ts +0 -22
- package/dist/errors/factory.d.ts.map +0 -1
- package/dist/errors/factory.js +0 -101
- package/dist/errors/index.d.ts +0 -210
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js +0 -283
- package/dist/generated/client.d.ts +0 -20
- package/dist/generated/client.d.ts.map +0 -1
- package/dist/generated/client.js +0 -15
- package/dist/generated/index.d.ts +0 -2
- package/dist/generated/index.d.ts.map +0 -1
- package/dist/generated/index.js +0 -1
- package/dist/generated/openapi.d.ts +0 -12302
- package/dist/generated/openapi.d.ts.map +0 -1
- package/dist/generated/openapi.js +0 -5
- package/dist/index.d.ts +0 -69
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -81
- package/dist/modules/a2a.d.ts +0 -48
- package/dist/modules/a2a.d.ts.map +0 -1
- package/dist/modules/a2a.js +0 -37
- package/dist/modules/agents.d.ts +0 -346
- package/dist/modules/agents.d.ts.map +0 -1
- package/dist/modules/agents.js +0 -296
- package/dist/modules/apiTokens.d.ts +0 -62
- package/dist/modules/apiTokens.d.ts.map +0 -1
- package/dist/modules/apiTokens.js +0 -56
- package/dist/modules/approvals.d.ts +0 -75
- package/dist/modules/approvals.d.ts.map +0 -1
- package/dist/modules/approvals.js +0 -91
- package/dist/modules/audit.d.ts +0 -78
- package/dist/modules/audit.d.ts.map +0 -1
- package/dist/modules/audit.js +0 -94
- package/dist/modules/auth.d.ts +0 -28
- package/dist/modules/auth.d.ts.map +0 -1
- package/dist/modules/auth.js +0 -22
- package/dist/modules/builder.d.ts +0 -242
- package/dist/modules/builder.d.ts.map +0 -1
- package/dist/modules/builder.js +0 -248
- package/dist/modules/catalog.d.ts +0 -142
- package/dist/modules/catalog.d.ts.map +0 -1
- package/dist/modules/catalog.js +0 -136
- package/dist/modules/chatwoot.d.ts +0 -59
- package/dist/modules/chatwoot.d.ts.map +0 -1
- package/dist/modules/chatwoot.js +0 -200
- package/dist/modules/checkpoints.d.ts +0 -62
- package/dist/modules/checkpoints.d.ts.map +0 -1
- package/dist/modules/checkpoints.js +0 -48
- package/dist/modules/contracts.d.ts +0 -48
- package/dist/modules/contracts.d.ts.map +0 -1
- package/dist/modules/contracts.js +0 -25
- package/dist/modules/credentials.d.ts +0 -105
- package/dist/modules/credentials.d.ts.map +0 -1
- package/dist/modules/credentials.js +0 -135
- package/dist/modules/crons.d.ts +0 -73
- package/dist/modules/crons.d.ts.map +0 -1
- package/dist/modules/crons.js +0 -67
- package/dist/modules/datasets.d.ts +0 -80
- package/dist/modules/datasets.d.ts.map +0 -1
- package/dist/modules/datasets.js +0 -91
- package/dist/modules/evaluation.d.ts +0 -183
- package/dist/modules/evaluation.d.ts.map +0 -1
- package/dist/modules/evaluation.js +0 -108
- package/dist/modules/files.d.ts +0 -89
- package/dist/modules/files.d.ts.map +0 -1
- package/dist/modules/files.js +0 -133
- package/dist/modules/graphs.d.ts +0 -120
- package/dist/modules/graphs.d.ts.map +0 -1
- package/dist/modules/graphs.js +0 -69
- package/dist/modules/improvements.d.ts +0 -52
- package/dist/modules/improvements.d.ts.map +0 -1
- package/dist/modules/improvements.js +0 -27
- package/dist/modules/info.d.ts +0 -76
- package/dist/modules/info.d.ts.map +0 -1
- package/dist/modules/info.js +0 -93
- package/dist/modules/knowledge.d.ts +0 -91
- package/dist/modules/knowledge.d.ts.map +0 -1
- package/dist/modules/knowledge.js +0 -80
- package/dist/modules/me.d.ts +0 -58
- package/dist/modules/me.d.ts.map +0 -1
- package/dist/modules/me.js +0 -28
- package/dist/modules/members.d.ts +0 -124
- package/dist/modules/members.d.ts.map +0 -1
- package/dist/modules/members.js +0 -142
- package/dist/modules/memberships.d.ts +0 -25
- package/dist/modules/memberships.d.ts.map +0 -1
- package/dist/modules/memberships.js +0 -20
- package/dist/modules/metaAgent.d.ts +0 -95
- package/dist/modules/metaAgent.d.ts.map +0 -1
- package/dist/modules/metaAgent.js +0 -32
- package/dist/modules/metrics.d.ts +0 -20
- package/dist/modules/metrics.d.ts.map +0 -1
- package/dist/modules/metrics.js +0 -27
- package/dist/modules/observability.d.ts +0 -19
- package/dist/modules/observability.d.ts.map +0 -1
- package/dist/modules/observability.js +0 -14
- package/dist/modules/playground.d.ts +0 -42
- package/dist/modules/playground.d.ts.map +0 -1
- package/dist/modules/playground.js +0 -48
- package/dist/modules/presets.d.ts +0 -32
- package/dist/modules/presets.d.ts.map +0 -1
- package/dist/modules/presets.js +0 -199
- package/dist/modules/prompts.d.ts +0 -87
- package/dist/modules/prompts.d.ts.map +0 -1
- package/dist/modules/prompts.js +0 -87
- package/dist/modules/roles.d.ts +0 -64
- package/dist/modules/roles.d.ts.map +0 -1
- package/dist/modules/roles.js +0 -79
- package/dist/modules/runs.d.ts +0 -451
- package/dist/modules/runs.d.ts.map +0 -1
- package/dist/modules/runs.js +0 -536
- package/dist/modules/store.d.ts +0 -37
- package/dist/modules/store.d.ts.map +0 -1
- package/dist/modules/store.js +0 -48
- package/dist/modules/templates.d.ts +0 -28
- package/dist/modules/templates.d.ts.map +0 -1
- package/dist/modules/templates.js +0 -19
- package/dist/modules/tenants.d.ts +0 -49
- package/dist/modules/tenants.d.ts.map +0 -1
- package/dist/modules/tenants.js +0 -56
- package/dist/modules/threads.d.ts +0 -205
- package/dist/modules/threads.d.ts.map +0 -1
- package/dist/modules/threads.js +0 -225
- package/dist/modules/tools.d.ts +0 -62
- package/dist/modules/tools.d.ts.map +0 -1
- package/dist/modules/tools.js +0 -45
- package/dist/modules/traces.d.ts +0 -89
- package/dist/modules/traces.d.ts.map +0 -1
- package/dist/modules/traces.js +0 -65
- package/dist/modules/triggers.d.ts +0 -228
- package/dist/modules/triggers.d.ts.map +0 -1
- package/dist/modules/triggers.js +0 -176
- package/dist/modules/usage.d.ts +0 -85
- package/dist/modules/usage.d.ts.map +0 -1
- package/dist/modules/usage.js +0 -43
- package/dist/modules/vectorStores.d.ts +0 -100
- package/dist/modules/vectorStores.d.ts.map +0 -1
- package/dist/modules/vectorStores.js +0 -159
- package/dist/modules/workspaces.d.ts +0 -138
- package/dist/modules/workspaces.d.ts.map +0 -1
- package/dist/modules/workspaces.js +0 -121
- package/dist/sse/client.d.ts +0 -140
- package/dist/sse/client.d.ts.map +0 -1
- package/dist/sse/client.js +0 -103
package/dist/modules/audit.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Audit Module - Fully Typed
|
|
3
|
-
*/
|
|
4
|
-
export class AuditModule {
|
|
5
|
-
client;
|
|
6
|
-
headers;
|
|
7
|
-
constructor(client, headers) {
|
|
8
|
-
this.client = client;
|
|
9
|
-
this.headers = headers;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* List audit log entries.
|
|
13
|
-
*/
|
|
14
|
-
async list(params) {
|
|
15
|
-
const queryParams = { ...params };
|
|
16
|
-
if (params?.limit !== undefined) {
|
|
17
|
-
queryParams.take = params.limit;
|
|
18
|
-
delete queryParams.limit;
|
|
19
|
-
}
|
|
20
|
-
if (params?.offset !== undefined) {
|
|
21
|
-
queryParams.skip = params.offset;
|
|
22
|
-
delete queryParams.offset;
|
|
23
|
-
}
|
|
24
|
-
return this.client.GET("/v1/api/audit", {
|
|
25
|
-
params: { query: queryParams },
|
|
26
|
-
headers: this.headers(),
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Get a specific audit log entry.
|
|
31
|
-
*/
|
|
32
|
-
async get(auditId) {
|
|
33
|
-
return this.client.GET("/v1/api/audit/{id}", {
|
|
34
|
-
params: { path: { id: auditId } },
|
|
35
|
-
headers: this.headers(),
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Search audit logs by action pattern.
|
|
40
|
-
*/
|
|
41
|
-
async search(params) {
|
|
42
|
-
const queryParams = { ...params };
|
|
43
|
-
if (params?.limit !== undefined) {
|
|
44
|
-
queryParams.take = params.limit;
|
|
45
|
-
delete queryParams.limit;
|
|
46
|
-
}
|
|
47
|
-
if (params?.offset !== undefined) {
|
|
48
|
-
queryParams.skip = params.offset;
|
|
49
|
-
delete queryParams.offset;
|
|
50
|
-
}
|
|
51
|
-
return this.client.GET("/v1/api/audit/search", {
|
|
52
|
-
params: { query: queryParams },
|
|
53
|
-
headers: this.headers(),
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Iterate through all audit logs with automatic pagination.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```ts
|
|
61
|
-
* // Get all audit logs for a specific action
|
|
62
|
-
* for await (const entry of client.audit.iterate({ action: "agent.created" })) {
|
|
63
|
-
* console.log(entry.actor, entry.action);
|
|
64
|
-
* }
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
async *iterate(filters, options) {
|
|
68
|
-
const pageSize = options?.pageSize ?? 100;
|
|
69
|
-
const maxItems = options?.maxItems ?? Infinity;
|
|
70
|
-
let offset = 0;
|
|
71
|
-
let yielded = 0;
|
|
72
|
-
let hasMore = true;
|
|
73
|
-
while (hasMore && yielded < maxItems) {
|
|
74
|
-
if (options?.signal?.aborted)
|
|
75
|
-
return;
|
|
76
|
-
const response = await this.list({
|
|
77
|
-
...filters,
|
|
78
|
-
limit: Math.min(pageSize, maxItems - yielded),
|
|
79
|
-
offset,
|
|
80
|
-
});
|
|
81
|
-
if (response.error)
|
|
82
|
-
throw response.error;
|
|
83
|
-
const data = response.data;
|
|
84
|
-
for (const entry of data.items) {
|
|
85
|
-
if (yielded >= maxItems)
|
|
86
|
-
return;
|
|
87
|
-
yield entry;
|
|
88
|
-
yielded++;
|
|
89
|
-
}
|
|
90
|
-
offset += data.items.length;
|
|
91
|
-
hasMore = offset < data.total && data.items.length > 0;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
package/dist/modules/auth.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auth Module - Bootstrap & Identity
|
|
3
|
-
*/
|
|
4
|
-
import type { RawClient, APIResponse } from "../client/raw.js";
|
|
5
|
-
export interface BootstrapResponse {
|
|
6
|
-
status: "existing" | "created";
|
|
7
|
-
tenant_id: string;
|
|
8
|
-
tenant_name?: string;
|
|
9
|
-
tenant_slug?: string;
|
|
10
|
-
workspace_id?: string;
|
|
11
|
-
workspace_name?: string;
|
|
12
|
-
workspace_slug?: string;
|
|
13
|
-
member_id: string;
|
|
14
|
-
role_name?: string;
|
|
15
|
-
}
|
|
16
|
-
export declare class AuthModule {
|
|
17
|
-
private client;
|
|
18
|
-
private headers;
|
|
19
|
-
constructor(client: RawClient, headers: () => Record<string, string>);
|
|
20
|
-
/**
|
|
21
|
-
* Bootstrap the authenticated user with a default tenant, workspace, and roles.
|
|
22
|
-
* Idempotent: returns existing resources if already provisioned.
|
|
23
|
-
*
|
|
24
|
-
* @returns 200 if already bootstrapped, 201 if newly created.
|
|
25
|
-
*/
|
|
26
|
-
bootstrap(): Promise<APIResponse<BootstrapResponse>>;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/modules/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/D,MAAM,WAAW,iBAAiB;IAC9B,MAAM,EAAE,UAAU,GAAG,SAAS,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,UAAU;IACP,OAAO,CAAC,MAAM;IAAa,OAAO,CAAC,OAAO;gBAAlC,MAAM,EAAE,SAAS,EAAU,OAAO,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAEpF;;;;;OAKG;IACG,SAAS,IAAI,OAAO,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;CAK7D"}
|
package/dist/modules/auth.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auth Module - Bootstrap & Identity
|
|
3
|
-
*/
|
|
4
|
-
export class AuthModule {
|
|
5
|
-
client;
|
|
6
|
-
headers;
|
|
7
|
-
constructor(client, headers) {
|
|
8
|
-
this.client = client;
|
|
9
|
-
this.headers = headers;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Bootstrap the authenticated user with a default tenant, workspace, and roles.
|
|
13
|
-
* Idempotent: returns existing resources if already provisioned.
|
|
14
|
-
*
|
|
15
|
-
* @returns 200 if already bootstrapped, 201 if newly created.
|
|
16
|
-
*/
|
|
17
|
-
async bootstrap() {
|
|
18
|
-
return this.client.POST("/v1/api/auth/bootstrap", {
|
|
19
|
-
headers: this.headers(),
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,242 +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
|
-
import type { RawClient } from "../client/raw.js";
|
|
30
|
-
import type { SSEOptions } from "../sse/client.js";
|
|
31
|
-
export type CatalogVersions = {
|
|
32
|
-
nodes: string;
|
|
33
|
-
tools: string;
|
|
34
|
-
triggers: string;
|
|
35
|
-
};
|
|
36
|
-
export type ChatHistoryMessage = {
|
|
37
|
-
role: 'user' | 'assistant';
|
|
38
|
-
content: string;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Builder chat request.
|
|
42
|
-
*
|
|
43
|
-
* KERNEL-FIRST: Frontend sends INTENTION only.
|
|
44
|
-
* - Graph spec is loaded from artifact storage by CP
|
|
45
|
-
* - Catalogs are loaded from DB by CP
|
|
46
|
-
* - Frontend should NOT send graph_spec or catalogs
|
|
47
|
-
*/
|
|
48
|
-
export type BuilderChatRequest = {
|
|
49
|
-
/** Chat message/intention */
|
|
50
|
-
message: string;
|
|
51
|
-
/** Thread ID for conversation continuity */
|
|
52
|
-
thread_id?: string;
|
|
53
|
-
/** Chat history for context (optional, sent from frontend) */
|
|
54
|
-
history?: {
|
|
55
|
-
role: 'user' | 'assistant';
|
|
56
|
-
content: string;
|
|
57
|
-
}[];
|
|
58
|
-
/** Optional ETag for concurrency control */
|
|
59
|
-
base_graph_etag?: string;
|
|
60
|
-
};
|
|
61
|
-
export type HintTargetModel = {
|
|
62
|
-
node_id?: string;
|
|
63
|
-
edge_id?: string;
|
|
64
|
-
panel?: "credentials" | "triggers" | "logs" | "validation" | "deploy" | string;
|
|
65
|
-
action?: "create_credential" | "save_draft" | "publish_version" | string;
|
|
66
|
-
};
|
|
67
|
-
export type HintDataModel = {
|
|
68
|
-
credential_slug?: string;
|
|
69
|
-
reason?: string;
|
|
70
|
-
fields?: string[];
|
|
71
|
-
code?: string;
|
|
72
|
-
path?: string;
|
|
73
|
-
run_id?: string;
|
|
74
|
-
error_code?: string;
|
|
75
|
-
tokens_in?: number;
|
|
76
|
-
tokens_out?: number;
|
|
77
|
-
usd_estimate?: number;
|
|
78
|
-
action_id?: string;
|
|
79
|
-
params?: Record<string, any>;
|
|
80
|
-
};
|
|
81
|
-
export type HintModel = {
|
|
82
|
-
id?: string;
|
|
83
|
-
scope: "graph" | "thread" | "run" | string;
|
|
84
|
-
type: "highlight_node" | "needs_credential" | "missing_config" | "error_marker" | "warning_marker" | "toast" | "run_started" | "node_running" | "node_failed" | "rate_limited" | "cost_estimate" | "action_suggested" | string;
|
|
85
|
-
severity: "info" | "warn" | "error" | "success";
|
|
86
|
-
target?: HintTargetModel;
|
|
87
|
-
message?: string;
|
|
88
|
-
ttl_ms?: number;
|
|
89
|
-
data?: HintDataModel;
|
|
90
|
-
};
|
|
91
|
-
export type GraphUpdateAction = {
|
|
92
|
-
graph_spec: Record<string, unknown>;
|
|
93
|
-
hints?: HintModel[];
|
|
94
|
-
has_errors?: boolean;
|
|
95
|
-
};
|
|
96
|
-
export type BuilderStreamEvent = {
|
|
97
|
-
type: "message";
|
|
98
|
-
data: {
|
|
99
|
-
text: string;
|
|
100
|
-
};
|
|
101
|
-
} | {
|
|
102
|
-
type: "validation";
|
|
103
|
-
data: {
|
|
104
|
-
valid: boolean;
|
|
105
|
-
errors: any[];
|
|
106
|
-
};
|
|
107
|
-
} | {
|
|
108
|
-
type: "graph_update";
|
|
109
|
-
data: {
|
|
110
|
-
graph_spec: Record<string, unknown>;
|
|
111
|
-
hints: HintModel[];
|
|
112
|
-
has_errors?: boolean;
|
|
113
|
-
};
|
|
114
|
-
} | {
|
|
115
|
-
type: "done";
|
|
116
|
-
data: {
|
|
117
|
-
response: string;
|
|
118
|
-
thread_id: string;
|
|
119
|
-
};
|
|
120
|
-
} | {
|
|
121
|
-
type: "error";
|
|
122
|
-
data: {
|
|
123
|
-
error: string;
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
export type BuilderChatResponse = {
|
|
127
|
-
response: string;
|
|
128
|
-
graph_spec?: Record<string, unknown>;
|
|
129
|
-
valid: boolean;
|
|
130
|
-
errors: any[];
|
|
131
|
-
thread_id: string;
|
|
132
|
-
hints: HintModel[];
|
|
133
|
-
};
|
|
134
|
-
/** Supported patch operation types */
|
|
135
|
-
export type OpType = "add_node" | "remove_node" | "update_node" | "add_edge" | "remove_edge" | "set_entrypoint" | "rename_node";
|
|
136
|
-
/** A single graph modification operation */
|
|
137
|
-
export type PatchOp = {
|
|
138
|
-
op: OpType;
|
|
139
|
-
node_id?: string;
|
|
140
|
-
kind?: string;
|
|
141
|
-
label?: string;
|
|
142
|
-
data?: Record<string, unknown>;
|
|
143
|
-
set?: Record<string, unknown>;
|
|
144
|
-
from?: string;
|
|
145
|
-
to?: string;
|
|
146
|
-
entrypoint?: string;
|
|
147
|
-
};
|
|
148
|
-
/** A collection of patch operations with deterministic ID */
|
|
149
|
-
export type GraphPatch = {
|
|
150
|
-
patch_id: string;
|
|
151
|
-
ops: PatchOp[];
|
|
152
|
-
description?: string;
|
|
153
|
-
};
|
|
154
|
-
/** Validation error from applying patch */
|
|
155
|
-
export type PatchValidationError = {
|
|
156
|
-
code: string;
|
|
157
|
-
message: string;
|
|
158
|
-
node_id?: string;
|
|
159
|
-
path?: string;
|
|
160
|
-
};
|
|
161
|
-
/** Meta-chat request */
|
|
162
|
-
export type MetaChatRequest = {
|
|
163
|
-
instruction: string;
|
|
164
|
-
};
|
|
165
|
-
/** Meta-chat stream events */
|
|
166
|
-
export type MetaChatStreamEvent = {
|
|
167
|
-
type: "assistant.delta";
|
|
168
|
-
data: {
|
|
169
|
-
text: string;
|
|
170
|
-
};
|
|
171
|
-
} | {
|
|
172
|
-
type: "patch.validation";
|
|
173
|
-
data: {
|
|
174
|
-
valid: boolean;
|
|
175
|
-
errors: PatchValidationError[];
|
|
176
|
-
};
|
|
177
|
-
} | {
|
|
178
|
-
type: "patch.proposed";
|
|
179
|
-
data: GraphPatch;
|
|
180
|
-
} | {
|
|
181
|
-
type: "final";
|
|
182
|
-
data: {
|
|
183
|
-
ok: boolean;
|
|
184
|
-
patch_id: string;
|
|
185
|
-
};
|
|
186
|
-
} | {
|
|
187
|
-
type: "error";
|
|
188
|
-
data: {
|
|
189
|
-
error: string;
|
|
190
|
-
};
|
|
191
|
-
};
|
|
192
|
-
/** Meta-chat sync response */
|
|
193
|
-
export type MetaChatResponse = {
|
|
194
|
-
patch: GraphPatch | null;
|
|
195
|
-
applied_spec: Record<string, unknown> | null;
|
|
196
|
-
valid: boolean;
|
|
197
|
-
errors: PatchValidationError[];
|
|
198
|
-
message: string;
|
|
199
|
-
};
|
|
200
|
-
export declare class BuilderModule {
|
|
201
|
-
private client;
|
|
202
|
-
constructor(client: RawClient);
|
|
203
|
-
/**
|
|
204
|
-
* Stream chat with meta-agent (SSE).
|
|
205
|
-
* Returns async generator of events.
|
|
206
|
-
*
|
|
207
|
-
* Uses rawClient.streamPost() - headers resolved asynchronously.
|
|
208
|
-
*/
|
|
209
|
-
chat(agentId: string, request: BuilderChatRequest, options?: SSEOptions): AsyncGenerator<BuilderStreamEvent>;
|
|
210
|
-
/**
|
|
211
|
-
* Sync chat with meta-agent (no streaming).
|
|
212
|
-
*
|
|
213
|
-
* Uses rawClient.POST() - headers resolved asynchronously.
|
|
214
|
-
*/
|
|
215
|
-
chatSync(agentId: string, request: BuilderChatRequest): Promise<BuilderChatResponse>;
|
|
216
|
-
/**
|
|
217
|
-
* Convenience method: chat and collect all events.
|
|
218
|
-
*/
|
|
219
|
-
chatCollect(agentId: string, request: BuilderChatRequest): Promise<BuilderChatResponse>;
|
|
220
|
-
/**
|
|
221
|
-
* Stream meta-chat with patch-ops architecture (SSE).
|
|
222
|
-
* Returns GraphPatch proposals instead of full graph specs.
|
|
223
|
-
*
|
|
224
|
-
* @example
|
|
225
|
-
* ```ts
|
|
226
|
-
* for await (const event of client.builder.metaChat(agentId, {
|
|
227
|
-
* instruction: "Add a log node after the main agent"
|
|
228
|
-
* })) {
|
|
229
|
-
* if (event.type === 'patch.proposed') {
|
|
230
|
-
* const patch = event.data;
|
|
231
|
-
* console.log(`Proposed ${patch.ops.length} operations`);
|
|
232
|
-
* }
|
|
233
|
-
* }
|
|
234
|
-
* ```
|
|
235
|
-
*/
|
|
236
|
-
metaChat(agentId: string, request: MetaChatRequest, options?: SSEOptions): AsyncGenerator<MetaChatStreamEvent>;
|
|
237
|
-
/**
|
|
238
|
-
* Meta-chat and collect the proposed patch.
|
|
239
|
-
*/
|
|
240
|
-
metaChatCollect(agentId: string, request: MetaChatRequest): Promise<MetaChatResponse>;
|
|
241
|
-
}
|
|
242
|
-
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/modules/builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,MAAM,eAAe,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC7B,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC7B,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CACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,kBAAkB,GAC5B,OAAO,CAAC,mBAAmB,CAAC;IAgB/B;;OAEG;IACG,WAAW,CACb,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,kBAAkB,GAC5B,OAAO,CAAC,mBAAmB,CAAC;IA0C/B;;;;;;;;;;;;;;;OAeG;IACI,QAAQ,CACX,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,eAAe,EACxB,OAAO,CAAC,EAAE,UAAU,GACrB,cAAc,CAAC,mBAAmB,CAAC;IAwDtC;;OAEG;IACG,eAAe,CACjB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,eAAe,GACzB,OAAO,CAAC,gBAAgB,CAAC;CAyB/B"}
|
package/dist/modules/builder.js
DELETED
|
@@ -1,248 +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
|
-
export class BuilderModule {
|
|
30
|
-
client;
|
|
31
|
-
constructor(client) {
|
|
32
|
-
this.client = client;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Stream chat with meta-agent (SSE).
|
|
36
|
-
* Returns async generator of events.
|
|
37
|
-
*
|
|
38
|
-
* Uses rawClient.streamPost() - headers resolved asynchronously.
|
|
39
|
-
*/
|
|
40
|
-
async *chat(agentId, request, options) {
|
|
41
|
-
// Use rawClient.streamPost() - ALL auth headers resolved automatically
|
|
42
|
-
const response = await this.client.streamPost("/v1/api/builder/{agentId}/chat", {
|
|
43
|
-
params: { path: { agentId } },
|
|
44
|
-
body: request,
|
|
45
|
-
signal: options?.signal,
|
|
46
|
-
});
|
|
47
|
-
if (!response.ok) {
|
|
48
|
-
const errorText = await response.text();
|
|
49
|
-
throw new Error(`Builder chat failed: ${response.status} - ${errorText}`);
|
|
50
|
-
}
|
|
51
|
-
if (!response.body) {
|
|
52
|
-
throw new Error("No response body");
|
|
53
|
-
}
|
|
54
|
-
options?.onOpen?.();
|
|
55
|
-
const reader = response.body.getReader();
|
|
56
|
-
const decoder = new TextDecoder();
|
|
57
|
-
let buffer = "";
|
|
58
|
-
try {
|
|
59
|
-
while (true) {
|
|
60
|
-
const { done, value } = await reader.read();
|
|
61
|
-
if (done)
|
|
62
|
-
break;
|
|
63
|
-
buffer += decoder.decode(value, { stream: true });
|
|
64
|
-
const lines = buffer.split("\n");
|
|
65
|
-
buffer = lines.pop() ?? "";
|
|
66
|
-
let eventType = "message";
|
|
67
|
-
let eventData = "";
|
|
68
|
-
for (const line of lines) {
|
|
69
|
-
if (line.startsWith("event:")) {
|
|
70
|
-
eventType = line.slice(6).trim();
|
|
71
|
-
}
|
|
72
|
-
else if (line.startsWith("data:")) {
|
|
73
|
-
eventData = line.slice(5).trim();
|
|
74
|
-
}
|
|
75
|
-
else if (line === "" && eventData) {
|
|
76
|
-
try {
|
|
77
|
-
const parsed = JSON.parse(eventData);
|
|
78
|
-
yield { type: eventType, data: parsed };
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
// Skip invalid JSON
|
|
82
|
-
}
|
|
83
|
-
eventData = "";
|
|
84
|
-
eventType = "message";
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
finally {
|
|
90
|
-
reader.releaseLock();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Sync chat with meta-agent (no streaming).
|
|
95
|
-
*
|
|
96
|
-
* Uses rawClient.POST() - headers resolved asynchronously.
|
|
97
|
-
*/
|
|
98
|
-
async chatSync(agentId, request) {
|
|
99
|
-
const { data, error } = await this.client.POST("/v1/api/builder/{agentId}/chat/sync", {
|
|
100
|
-
params: { path: { agentId } },
|
|
101
|
-
body: request,
|
|
102
|
-
});
|
|
103
|
-
if (error) {
|
|
104
|
-
throw new Error(`Builder chat failed: ${error.code} - ${error.message}`);
|
|
105
|
-
}
|
|
106
|
-
return data;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Convenience method: chat and collect all events.
|
|
110
|
-
*/
|
|
111
|
-
async chatCollect(agentId, request) {
|
|
112
|
-
let fullResponse = "";
|
|
113
|
-
let lastGraphSpec;
|
|
114
|
-
let allHints = [];
|
|
115
|
-
const allErrors = [];
|
|
116
|
-
let threadId = request.thread_id ?? "";
|
|
117
|
-
let isValid = true;
|
|
118
|
-
for await (const event of this.chat(agentId, request)) {
|
|
119
|
-
if (event.type === "message") {
|
|
120
|
-
fullResponse += event.data.text;
|
|
121
|
-
}
|
|
122
|
-
else if (event.type === "graph_update") {
|
|
123
|
-
if ('graph_spec' in event.data) {
|
|
124
|
-
lastGraphSpec = event.data.graph_spec;
|
|
125
|
-
if (event.data.hints) {
|
|
126
|
-
allHints.push(...event.data.hints);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
else if (event.type === "validation") {
|
|
131
|
-
isValid = event.data.valid;
|
|
132
|
-
if (event.data.errors) {
|
|
133
|
-
allErrors.push(...event.data.errors);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
else if (event.type === "done") {
|
|
137
|
-
threadId = event.data.thread_id;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return {
|
|
141
|
-
response: fullResponse,
|
|
142
|
-
graph_spec: lastGraphSpec,
|
|
143
|
-
hints: allHints,
|
|
144
|
-
valid: isValid,
|
|
145
|
-
errors: allErrors,
|
|
146
|
-
thread_id: threadId,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
// ============================================
|
|
150
|
-
// META-CHAT V2 (PATCH-OPS ARCHITECTURE)
|
|
151
|
-
// ============================================
|
|
152
|
-
/**
|
|
153
|
-
* Stream meta-chat with patch-ops architecture (SSE).
|
|
154
|
-
* Returns GraphPatch proposals instead of full graph specs.
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```ts
|
|
158
|
-
* for await (const event of client.builder.metaChat(agentId, {
|
|
159
|
-
* instruction: "Add a log node after the main agent"
|
|
160
|
-
* })) {
|
|
161
|
-
* if (event.type === 'patch.proposed') {
|
|
162
|
-
* const patch = event.data;
|
|
163
|
-
* console.log(`Proposed ${patch.ops.length} operations`);
|
|
164
|
-
* }
|
|
165
|
-
* }
|
|
166
|
-
* ```
|
|
167
|
-
*/
|
|
168
|
-
async *metaChat(agentId, request, options) {
|
|
169
|
-
const response = await this.client.streamPost("/v1/builder/{agentId}/meta-chat", {
|
|
170
|
-
params: { path: { agentId } },
|
|
171
|
-
body: request,
|
|
172
|
-
signal: options?.signal,
|
|
173
|
-
});
|
|
174
|
-
if (!response.ok) {
|
|
175
|
-
const errorText = await response.text();
|
|
176
|
-
throw new Error(`Meta-chat failed: ${response.status} - ${errorText}`);
|
|
177
|
-
}
|
|
178
|
-
if (!response.body) {
|
|
179
|
-
throw new Error("No response body");
|
|
180
|
-
}
|
|
181
|
-
options?.onOpen?.();
|
|
182
|
-
const reader = response.body.getReader();
|
|
183
|
-
const decoder = new TextDecoder();
|
|
184
|
-
let buffer = "";
|
|
185
|
-
try {
|
|
186
|
-
while (true) {
|
|
187
|
-
const { done, value } = await reader.read();
|
|
188
|
-
if (done)
|
|
189
|
-
break;
|
|
190
|
-
buffer += decoder.decode(value, { stream: true });
|
|
191
|
-
const lines = buffer.split("\n");
|
|
192
|
-
buffer = lines.pop() ?? "";
|
|
193
|
-
let eventType = "message";
|
|
194
|
-
let eventData = "";
|
|
195
|
-
for (const line of lines) {
|
|
196
|
-
if (line.startsWith("event:")) {
|
|
197
|
-
eventType = line.slice(6).trim();
|
|
198
|
-
}
|
|
199
|
-
else if (line.startsWith("data:")) {
|
|
200
|
-
eventData = line.slice(5).trim();
|
|
201
|
-
}
|
|
202
|
-
else if (line === "" && eventData) {
|
|
203
|
-
try {
|
|
204
|
-
const parsed = JSON.parse(eventData);
|
|
205
|
-
yield { type: eventType, data: parsed };
|
|
206
|
-
}
|
|
207
|
-
catch {
|
|
208
|
-
// Skip invalid JSON
|
|
209
|
-
}
|
|
210
|
-
eventData = "";
|
|
211
|
-
eventType = "message";
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
finally {
|
|
217
|
-
reader.releaseLock();
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Meta-chat and collect the proposed patch.
|
|
222
|
-
*/
|
|
223
|
-
async metaChatCollect(agentId, request) {
|
|
224
|
-
let patch = null;
|
|
225
|
-
let isValid = true;
|
|
226
|
-
const errors = [];
|
|
227
|
-
let message = "";
|
|
228
|
-
for await (const event of this.metaChat(agentId, request)) {
|
|
229
|
-
if (event.type === "assistant.delta") {
|
|
230
|
-
message += event.data.text;
|
|
231
|
-
}
|
|
232
|
-
else if (event.type === "patch.proposed") {
|
|
233
|
-
patch = event.data;
|
|
234
|
-
}
|
|
235
|
-
else if (event.type === "patch.validation") {
|
|
236
|
-
isValid = event.data.valid;
|
|
237
|
-
errors.push(...event.data.errors);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return {
|
|
241
|
-
patch,
|
|
242
|
-
applied_spec: null, // Frontend should apply patch locally
|
|
243
|
-
valid: isValid,
|
|
244
|
-
errors,
|
|
245
|
-
message,
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
}
|