@agent-os-sdk/client 0.7.12 → 0.8.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/dist/client/AgentOsClient.d.ts +25 -23
- package/dist/client/AgentOsClient.d.ts.map +1 -1
- package/dist/client/AgentOsClient.js +26 -22
- package/dist/client/HttpRequestBuilder.d.ts +48 -0
- package/dist/client/HttpRequestBuilder.d.ts.map +1 -0
- package/dist/client/HttpRequestBuilder.js +73 -0
- package/dist/client/OperationContext.d.ts +19 -0
- package/dist/client/OperationContext.d.ts.map +1 -0
- package/dist/client/OperationContext.js +13 -0
- package/dist/client/OperationContextProvider.d.ts +54 -0
- package/dist/client/OperationContextProvider.d.ts.map +1 -0
- package/dist/client/OperationContextProvider.js +71 -0
- package/dist/client/raw.d.ts +31 -0
- package/dist/client/raw.d.ts.map +1 -1
- package/dist/client/raw.js +11 -6
- package/dist/client/sanitize.d.ts +19 -0
- package/dist/client/sanitize.d.ts.map +1 -0
- package/dist/client/sanitize.js +28 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/modules/agents.d.ts +22 -6
- package/dist/modules/agents.d.ts.map +1 -1
- package/dist/modules/agents.js +26 -7
- package/dist/modules/credentials.d.ts +1 -0
- package/dist/modules/credentials.d.ts.map +1 -1
- package/dist/modules/credentials.js +2 -1
- package/dist/modules/crons.d.ts +1 -0
- package/dist/modules/crons.d.ts.map +1 -1
- package/dist/modules/crons.js +2 -1
- package/dist/modules/presets.d.ts +32 -0
- package/dist/modules/presets.d.ts.map +1 -0
- package/dist/modules/presets.js +116 -0
- package/dist/modules/triggers.d.ts +11 -0
- package/dist/modules/triggers.d.ts.map +1 -1
- package/dist/modules/triggers.js +17 -2
- package/package.json +51 -49
- package/src/client/AgentOsClient.ts +27 -24
- package/src/client/HttpRequestBuilder.ts +102 -0
- package/src/client/OperationContext.ts +22 -0
- package/src/client/OperationContextProvider.ts +89 -0
- package/src/client/raw.ts +19 -8
- package/src/client/sanitize.ts +31 -0
- package/src/index.ts +15 -0
- package/src/modules/agents.ts +44 -14
- package/src/modules/credentials.ts +2 -1
- package/src/modules/crons.ts +2 -1
- package/src/modules/presets.ts +162 -0
- package/src/modules/triggers.ts +21 -2
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type { RawClient } from "../client/raw.js";
|
|
2
|
+
import { AgentsModule } from "./agents.js";
|
|
3
|
+
import { TriggersModule } from "./triggers.js";
|
|
4
|
+
|
|
5
|
+
export interface AgentTemplateConfig {
|
|
6
|
+
name: string;
|
|
7
|
+
trigger_type: "chatwoot" | "webhook" | "schedule";
|
|
8
|
+
output_type: "chatwoot" | "http";
|
|
9
|
+
llm?: {
|
|
10
|
+
credential_id?: string;
|
|
11
|
+
model?: string;
|
|
12
|
+
system_prompt?: string;
|
|
13
|
+
};
|
|
14
|
+
bindings?: Array<{
|
|
15
|
+
credential_id: string;
|
|
16
|
+
alias: string;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface CreatedAgentResult {
|
|
21
|
+
agent_id: string;
|
|
22
|
+
agent_name: string;
|
|
23
|
+
bundle_id?: string;
|
|
24
|
+
trigger_id?: string;
|
|
25
|
+
trigger_url?: string;
|
|
26
|
+
status: "live" | "draft";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const TRIGGER_TYPE_MAP: Record<string, { type: string; template_slug: string }> = {
|
|
30
|
+
chatwoot: { type: "webhook", template_slug: "chatwoot" },
|
|
31
|
+
webhook: { type: "webhook", template_slug: "generic" },
|
|
32
|
+
schedule: { type: "schedule", template_slug: "cron" },
|
|
33
|
+
};
|
|
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
|
+
};
|
|
39
|
+
|
|
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 } : {}),
|
|
57
|
+
},
|
|
58
|
+
ui: { x: 300, y: 200 },
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "node-output",
|
|
62
|
+
...outputMapping,
|
|
63
|
+
label: "Output",
|
|
64
|
+
ui: { x: 500, y: 200 },
|
|
65
|
+
},
|
|
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"] },
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
version: "1",
|
|
81
|
+
entrypoint: "node-llm",
|
|
82
|
+
nodes,
|
|
83
|
+
edges,
|
|
84
|
+
triggers,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export class PresetsModule {
|
|
89
|
+
private _client: RawClient;
|
|
90
|
+
private _headers: () => Record<string, string>;
|
|
91
|
+
|
|
92
|
+
// Internal modules needed for orchestration
|
|
93
|
+
private _agents: AgentsModule;
|
|
94
|
+
private _triggers: TriggersModule;
|
|
95
|
+
|
|
96
|
+
constructor(client: RawClient, getHeaders: () => Record<string, string>) {
|
|
97
|
+
this._client = client;
|
|
98
|
+
this._headers = getHeaders;
|
|
99
|
+
this._agents = new AgentsModule(client, getHeaders);
|
|
100
|
+
this._triggers = new TriggersModule(client, getHeaders);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async createAgent(config: AgentTemplateConfig): Promise<CreatedAgentResult | null> {
|
|
104
|
+
try {
|
|
105
|
+
console.log("[AgentOS SDK] Creating agent from preset...", {
|
|
106
|
+
name: config.name,
|
|
107
|
+
trigger_type: config.trigger_type,
|
|
108
|
+
output_type: config.output_type,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const { data: agent, error: createError } = await this._agents.create({ name: config.name });
|
|
112
|
+
|
|
113
|
+
if (createError || !agent) {
|
|
114
|
+
console.error("[AgentOS SDK] Failed to create agent:", createError);
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const graphSpec = generateGraphSpec(config);
|
|
119
|
+
|
|
120
|
+
const { data: bundle, error: publishError } = await this._agents.publish(
|
|
121
|
+
agent.id,
|
|
122
|
+
graphSpec,
|
|
123
|
+
{ set_as_live: true }
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
if (publishError) {
|
|
127
|
+
console.error("[AgentOS SDK] Failed to publish bundle:", publishError);
|
|
128
|
+
return {
|
|
129
|
+
agent_id: agent.id,
|
|
130
|
+
agent_name: agent.name,
|
|
131
|
+
status: "draft",
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const triggerMapping = TRIGGER_TYPE_MAP[config.trigger_type] ?? TRIGGER_TYPE_MAP.webhook;
|
|
136
|
+
if (!triggerMapping) throw new Error("Trigger mapping failed");
|
|
137
|
+
|
|
138
|
+
const { data: trigger, error: triggerError } = await this._triggers.create({
|
|
139
|
+
name: `${config.name} - ${config.trigger_type}`,
|
|
140
|
+
agent_id: agent.id,
|
|
141
|
+
trigger_type: triggerMapping.type,
|
|
142
|
+
template_slug: triggerMapping.template_slug,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (triggerError) {
|
|
146
|
+
console.warn("[AgentOS SDK] Failed to create trigger:", triggerError);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
agent_id: agent.id,
|
|
151
|
+
agent_name: agent.name,
|
|
152
|
+
bundle_id: bundle?.id,
|
|
153
|
+
trigger_id: trigger?.id,
|
|
154
|
+
trigger_url: (trigger as any)?.invoke_url,
|
|
155
|
+
status: "live",
|
|
156
|
+
};
|
|
157
|
+
} catch (err) {
|
|
158
|
+
console.error("[AgentOS SDK] Exception creating agent from preset:", err);
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
package/src/modules/triggers.ts
CHANGED
|
@@ -150,6 +150,15 @@ export class TriggersModule {
|
|
|
150
150
|
|
|
151
151
|
/**
|
|
152
152
|
* Create a new trigger.
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* const { data: trigger } = await client.triggers.create({
|
|
156
|
+
* name: "My Webhook",
|
|
157
|
+
* agent_id: "agent-uuid",
|
|
158
|
+
* trigger_type: "webhook",
|
|
159
|
+
* idempotency_key: "create-trigger-unique-key"
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
153
162
|
*/
|
|
154
163
|
async create(body: {
|
|
155
164
|
name: string;
|
|
@@ -157,10 +166,20 @@ export class TriggersModule {
|
|
|
157
166
|
trigger_type: string;
|
|
158
167
|
template_slug?: string;
|
|
159
168
|
config?: Record<string, unknown>;
|
|
169
|
+
/** Idempotency key for safe retries. When set, duplicate requests with the same key return 409 Conflict. */
|
|
170
|
+
idempotency_key?: string;
|
|
160
171
|
}): Promise<APIResponse<Trigger>> {
|
|
172
|
+
const headers: Record<string, string> = { ...this.headers() };
|
|
173
|
+
if (body.idempotency_key) {
|
|
174
|
+
headers["X-Idempotency-Key"] = body.idempotency_key;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Send body without idempotency_key (it's header-only)
|
|
178
|
+
const { idempotency_key, ...requestBody } = body;
|
|
179
|
+
|
|
161
180
|
return this.client.POST<Trigger>("/v1/api/triggers", {
|
|
162
|
-
body,
|
|
163
|
-
headers
|
|
181
|
+
body: requestBody,
|
|
182
|
+
headers,
|
|
164
183
|
});
|
|
165
184
|
}
|
|
166
185
|
|