@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.
Files changed (58) hide show
  1. package/dist/client/AgentOsClient.d.ts +8 -4
  2. package/dist/client/AgentOsClient.d.ts.map +1 -1
  3. package/dist/client/AgentOsClient.js +12 -6
  4. package/dist/errors/factory.d.ts +2 -0
  5. package/dist/errors/factory.d.ts.map +1 -1
  6. package/dist/errors/factory.js +5 -1
  7. package/dist/generated/openapi.d.ts +544 -744
  8. package/dist/generated/openapi.d.ts.map +1 -1
  9. package/dist/index.d.ts +8 -2
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +8 -2
  12. package/dist/modules/agents.d.ts +25 -7
  13. package/dist/modules/agents.d.ts.map +1 -1
  14. package/dist/modules/agents.js +36 -7
  15. package/dist/modules/catalog.d.ts +63 -0
  16. package/dist/modules/catalog.d.ts.map +1 -1
  17. package/dist/modules/catalog.js +5 -0
  18. package/dist/modules/contracts.d.ts +48 -0
  19. package/dist/modules/contracts.d.ts.map +1 -0
  20. package/dist/modules/contracts.js +25 -0
  21. package/dist/modules/evaluation.d.ts +64 -0
  22. package/dist/modules/evaluation.d.ts.map +1 -1
  23. package/dist/modules/evaluation.js +12 -0
  24. package/dist/modules/improvements.d.ts +52 -0
  25. package/dist/modules/improvements.d.ts.map +1 -0
  26. package/dist/modules/improvements.js +27 -0
  27. package/dist/modules/metaAgent.d.ts +62 -0
  28. package/dist/modules/metaAgent.d.ts.map +1 -0
  29. package/dist/modules/metaAgent.js +25 -0
  30. package/dist/modules/presets.d.ts.map +1 -1
  31. package/dist/modules/presets.js +113 -44
  32. package/dist/modules/runs.d.ts +9 -0
  33. package/dist/modules/runs.d.ts.map +1 -1
  34. package/dist/modules/runs.js +14 -1
  35. package/dist/modules/templates.d.ts +28 -0
  36. package/dist/modules/templates.d.ts.map +1 -0
  37. package/dist/modules/templates.js +19 -0
  38. package/dist/modules/tools.d.ts +15 -0
  39. package/dist/modules/tools.d.ts.map +1 -1
  40. package/dist/modules/tools.js +6 -0
  41. package/package.json +51 -52
  42. package/src/client/AgentOsClient.ts +12 -6
  43. package/src/errors/factory.ts +7 -2
  44. package/src/generated/openapi.ts +544 -744
  45. package/src/generated/swagger.json +551 -924
  46. package/src/index.ts +22 -2
  47. package/src/modules/agents.ts +62 -8
  48. package/src/modules/catalog.ts +73 -0
  49. package/src/modules/contracts.ts +80 -0
  50. package/src/modules/evaluation.ts +80 -0
  51. package/src/modules/improvements.ts +71 -0
  52. package/src/modules/metaAgent.ts +87 -0
  53. package/src/modules/presets.ts +118 -50
  54. package/src/modules/runs.ts +20 -1
  55. package/src/modules/templates.ts +40 -0
  56. package/src/modules/tools.ts +23 -0
  57. package/src/modules/builder.ts +0 -456
  58. package/src/modules/graphs.ts +0 -188
@@ -32,56 +32,111 @@ const TRIGGER_TYPE_MAP: Record<string, { type: string; template_slug: string }>
32
32
  schedule: { type: "schedule", template_slug: "cron" },
33
33
  };
34
34
 
35
- const OUTPUT_NODE_MAP: Record<string, { kind: string; config: Record<string, unknown> }> = {
36
- chatwoot: { kind: "output.chatwoot", config: {} },
37
- http: { kind: "output.http", config: {} },
38
- };
35
+ function buildAgentDefinitionId(name: string): string {
36
+ const normalized = name
37
+ .trim()
38
+ .toLowerCase()
39
+ .replace(/[^a-z0-9]+/g, ".")
40
+ .replace(/\.{2,}/g, ".")
41
+ .replace(/^\.|\.$/g, "");
42
+ return `agent.${normalized || "untitled"}`;
43
+ }
39
44
 
40
- function generateGraphSpec(config: AgentTemplateConfig): Record<string, unknown> {
41
- const triggerMapping = TRIGGER_TYPE_MAP[config.trigger_type] ?? TRIGGER_TYPE_MAP.webhook;
42
- const outputMapping = OUTPUT_NODE_MAP[config.output_type] ?? OUTPUT_NODE_MAP.http;
43
-
44
- // Safe validation (TS knows these keys exist in the constant, but runtime check is good practice)
45
- if (!triggerMapping) throw new Error(`Invalid trigger type: ${config.trigger_type}`);
46
- if (!outputMapping) throw new Error(`Invalid output type: ${config.output_type}`);
47
-
48
- const nodes = [
49
- {
50
- id: "node-llm",
51
- kind: "llm.chat",
52
- label: "LLM",
53
- config: {
54
- model: config.llm?.model || "gpt-4o",
55
- system_prompt: config.llm?.system_prompt || "You are a helpful assistant.",
56
- ...(config.llm?.credential_id ? { credential_id: config.llm.credential_id } : {}),
45
+ function generateAgentIr(config: AgentTemplateConfig): Record<string, unknown> {
46
+ const agentDefinitionId = buildAgentDefinitionId(config.name);
47
+ const triggerLabel = config.trigger_type === "schedule" ? "Scheduled Trigger" : "Incoming Trigger";
48
+ const outputLabel = config.output_type === "chatwoot" ? "Chatwoot Output" : "HTTP Output";
49
+
50
+ return {
51
+ ir_version: "1.0",
52
+ agent_definition_id: agentDefinitionId,
53
+ version: "1.0.0",
54
+ metadata: {
55
+ name: config.name,
56
+ description: "Preset-generated agent_ir.v1 draft",
57
+ },
58
+ state_schema: {
59
+ type: "object",
60
+ properties: {
61
+ global: {
62
+ type: "object",
63
+ },
57
64
  },
58
- ui: { x: 300, y: 200 },
59
65
  },
60
- {
61
- id: "node-output",
62
- ...outputMapping,
63
- label: "Output",
64
- ui: { x: 500, y: 200 },
66
+ inputs_schema: {
67
+ type: "object",
68
+ properties: {
69
+ message: {
70
+ type: "string",
71
+ },
72
+ },
73
+ required: ["message"],
65
74
  },
66
- ];
67
-
68
- const edges = [
69
- { from: "node-llm", to: "node-output" },
70
- ];
71
-
72
- const triggers = [
73
- {
74
- type: `${triggerMapping.template_slug}.${triggerMapping.type}`,
75
- config: { events: ["message_created"] },
75
+ outputs_schema: {
76
+ type: "object",
76
77
  },
77
- ];
78
-
79
- return {
80
- version: "1",
81
- entrypoint: "node-llm",
82
- nodes,
83
- edges,
84
- triggers,
78
+ outcome_schema: {
79
+ type: "object",
80
+ properties: {
81
+ preset_ready: {
82
+ type: "boolean",
83
+ },
84
+ },
85
+ required: ["preset_ready"],
86
+ },
87
+ kpi_bindings: [
88
+ {
89
+ kpi_ref: `${agentDefinitionId}.preset_ready`,
90
+ source_scope: "outcome",
91
+ source_path: "preset_ready",
92
+ },
93
+ ],
94
+ evaluation_policy: {
95
+ execution_mode: "async",
96
+ evaluators: [
97
+ {
98
+ evaluator_ref: `eval.${agentDefinitionId}.preset_shape_v1`,
99
+ kind: "rule",
100
+ },
101
+ ],
102
+ sampling_policy: {
103
+ mode: "all",
104
+ },
105
+ },
106
+ improvement_policy_ref: null,
107
+ nodes: [
108
+ {
109
+ id: "start",
110
+ kind: "start",
111
+ label: triggerLabel,
112
+ config: {},
113
+ bindings: {},
114
+ editability: { mode: "read_only" },
115
+ },
116
+ {
117
+ id: "draft_output",
118
+ kind: "end",
119
+ label: outputLabel,
120
+ config: {},
121
+ bindings: {},
122
+ editability: { mode: "full" },
123
+ },
124
+ ],
125
+ edges: [
126
+ {
127
+ id: "edge_start_to_output",
128
+ from: "start",
129
+ to: "draft_output",
130
+ kind: "default",
131
+ priority: 0,
132
+ },
133
+ ],
134
+ capability_registry_refs: [],
135
+ policies: {},
136
+ editability: {
137
+ mode: "full",
138
+ },
139
+ entrypoints: ["start"],
85
140
  };
86
141
  }
87
142
 
@@ -129,14 +184,27 @@ export class PresetsModule {
129
184
  return null;
130
185
  }
131
186
 
132
- const graphSpec = generateGraphSpec(config);
133
-
134
- const { data: bundle, error: publishError } = await this._agents.publish(
187
+ const { error: draftError } = await this._agents.updateDraftIr(
135
188
  agent.id,
136
- graphSpec,
137
- { set_as_live: true, idempotency_key: generateUUID() }
189
+ generateAgentIr(config),
190
+ { if_match: `"${agent.id}:0"` },
138
191
  );
139
192
 
193
+ if (draftError) {
194
+ console.error("[AgentOS SDK] Failed to save agent_ir.v1 draft:", draftError);
195
+ return {
196
+ agent_id: agent.id,
197
+ agent_name: agent.name,
198
+ status: "draft",
199
+ };
200
+ }
201
+
202
+ const { data: bundle, error: publishError } = await this._agents.publish(agent.id, {
203
+ set_as_live: true,
204
+ required_tools: [],
205
+ idempotency_key: generateUUID(),
206
+ });
207
+
140
208
  if (publishError) {
141
209
  console.error("[AgentOS SDK] Failed to publish bundle:", publishError);
142
210
  return {
@@ -82,6 +82,9 @@ export interface RunEventDto {
82
82
  timestamp: string;
83
83
  attempt_id: string;
84
84
  payload: Record<string, unknown> | null;
85
+ operation_id: string;
86
+ parent_operation_id?: string | null;
87
+ root_operation_id: string;
85
88
  }
86
89
 
87
90
  export class RunsModule {
@@ -645,12 +648,15 @@ export interface FollowEvent {
645
648
  seq: number;
646
649
  timestamp: string;
647
650
  payload?: Record<string, unknown> | null;
651
+ operation_id?: string;
652
+ parent_operation_id?: string | null;
653
+ root_operation_id?: string;
648
654
  /** For run_event: the node that emitted this event */
649
655
  node?: string;
650
656
  }
651
657
 
652
658
  /** Narrow raw SSE event to FollowEvent */
653
- function narrowFollowEvent(raw: SSEEvent<unknown>): FollowEvent | null {
659
+ export function narrowFollowEvent(raw: SSEEvent<unknown>): FollowEvent | null {
654
660
  const eventType = raw.event ?? "message";
655
661
  const validTypes = ["run_event", "heartbeat", "close", "error"];
656
662
 
@@ -668,6 +674,13 @@ function narrowFollowEvent(raw: SSEEvent<unknown>): FollowEvent | null {
668
674
  const innerPayload = (typeof data.payload === "object" && data.payload !== null)
669
675
  ? (data.payload as Record<string, unknown>)
670
676
  : null;
677
+ const operationId = typeof data.operation_id === "string" ? data.operation_id : undefined;
678
+ const parentOperationId = typeof data.parent_operation_id === "string"
679
+ ? data.parent_operation_id
680
+ : data.parent_operation_id === null
681
+ ? null
682
+ : undefined;
683
+ const rootOperationId = typeof data.root_operation_id === "string" ? data.root_operation_id : undefined;
671
684
 
672
685
  return {
673
686
  type: "run_event",
@@ -677,7 +690,13 @@ function narrowFollowEvent(raw: SSEEvent<unknown>): FollowEvent | null {
677
690
  ...(innerPayload ?? {}),
678
691
  type: typeof data.type === "string" ? data.type : "UNKNOWN",
679
692
  attempt_id: typeof data.attempt_id === "string" ? data.attempt_id : undefined,
693
+ operation_id: operationId,
694
+ parent_operation_id: parentOperationId,
695
+ root_operation_id: rootOperationId,
680
696
  },
697
+ operation_id: operationId,
698
+ parent_operation_id: parentOperationId,
699
+ root_operation_id: rootOperationId,
681
700
  node: typeof innerPayload?.node === "string" ? innerPayload.node : undefined,
682
701
  };
683
702
  }
@@ -0,0 +1,40 @@
1
+ import type { APIResponse, RawClient } from "../client/raw.js";
2
+
3
+ export interface AuthoringTemplateSummary {
4
+ template_ref: string;
5
+ version: string;
6
+ display_name: string;
7
+ description?: string | null;
8
+ template_kind: string;
9
+ category: string;
10
+ editability_mode: string;
11
+ required_capability_refs: string[];
12
+ default_policy_refs?: Record<string, unknown> | null;
13
+ default_runtime_config_refs?: Record<string, unknown> | null;
14
+ }
15
+
16
+ export interface AuthoringTemplateDetail extends AuthoringTemplateSummary {
17
+ base_agent_ir: Record<string, unknown>;
18
+ }
19
+
20
+ export interface AuthoringTemplateListResponse {
21
+ items: AuthoringTemplateSummary[];
22
+ total: number;
23
+ }
24
+
25
+ export class TemplatesModule {
26
+ constructor(private client: RawClient, private headers: () => Record<string, string>) {}
27
+
28
+ async list(): Promise<APIResponse<AuthoringTemplateListResponse>> {
29
+ return this.client.GET<AuthoringTemplateListResponse>("/v1/api/templates", {
30
+ headers: this.headers(),
31
+ });
32
+ }
33
+
34
+ async get(templateRef: string): Promise<APIResponse<AuthoringTemplateDetail>> {
35
+ return this.client.GET<AuthoringTemplateDetail>("/v1/api/templates/{templateRef}", {
36
+ params: { path: { templateRef } },
37
+ headers: this.headers(),
38
+ });
39
+ }
40
+ }
@@ -19,6 +19,22 @@ export interface ToolListResponse {
19
19
  total: number;
20
20
  }
21
21
 
22
+ export interface ToolDefinitionCatalogItem {
23
+ slug: string;
24
+ name: string;
25
+ description?: string;
26
+ type: string;
27
+ version?: number;
28
+ input_schema?: Record<string, unknown>;
29
+ output_schema?: Record<string, unknown>;
30
+ credential_requirements?: unknown[];
31
+ }
32
+
33
+ export interface ToolDefinitionCatalogResponse {
34
+ version: string;
35
+ tools: ToolDefinitionCatalogItem[];
36
+ }
37
+
22
38
  export interface ToolCallResult {
23
39
  success: boolean;
24
40
  output?: unknown;
@@ -52,6 +68,13 @@ export class ToolsModule {
52
68
  });
53
69
  }
54
70
 
71
+ async getDefinitions(version: string = "1"): Promise<APIResponse<ToolDefinitionCatalogResponse>> {
72
+ return this.client.GET<ToolDefinitionCatalogResponse>("/v1/api/tools/definitions", {
73
+ params: { query: { version } },
74
+ headers: this.headers(),
75
+ });
76
+ }
77
+
55
78
  /**
56
79
  * Call a tool directly (testing).
57
80
  */