@kraken-ai/platform 0.0.1
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/LICENSE +67 -0
- package/README.md +36 -0
- package/dist/chunk-HGJSK6MW.js +294 -0
- package/dist/chunk-HGJSK6MW.js.map +1 -0
- package/dist/cli.js +1297 -0
- package/dist/cli.js.map +1 -0
- package/dist/connector-CumEDPfS.d.cts +103 -0
- package/dist/connector-CumEDPfS.d.ts +103 -0
- package/dist/index.cjs +1381 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +796 -0
- package/dist/index.d.ts +796 -0
- package/dist/index.js +1240 -0
- package/dist/index.js.map +1 -0
- package/dist/server.cjs +315 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +15 -0
- package/dist/server.d.ts +15 -0
- package/dist/server.js +7 -0
- package/dist/server.js.map +1 -0
- package/package.json +46 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1381 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
ACTION_NAME_REGEX: () => ACTION_NAME_REGEX,
|
|
34
|
+
AgentHandle: () => AgentHandle,
|
|
35
|
+
AgentThread: () => AgentThread,
|
|
36
|
+
ConnectorError: () => ConnectorError,
|
|
37
|
+
MANIFEST_END: () => MANIFEST_END,
|
|
38
|
+
MANIFEST_START: () => MANIFEST_START,
|
|
39
|
+
MockToolSet: () => MockToolSet,
|
|
40
|
+
PlatformClient: () => PlatformClient,
|
|
41
|
+
PlatformError: () => PlatformError,
|
|
42
|
+
SecurityError: () => SecurityError,
|
|
43
|
+
actionVariantConfigSchema: () => actionVariantConfigSchema,
|
|
44
|
+
actionsConfigSchema: () => actionsConfigSchema,
|
|
45
|
+
agentDefinitionSchema: () => agentDefinitionSchema,
|
|
46
|
+
buildActionOutputSchema: () => buildActionOutputSchema,
|
|
47
|
+
concurrencyPolicySchema: () => concurrencyPolicySchema,
|
|
48
|
+
defineAction: () => defineAction,
|
|
49
|
+
defineActions: () => defineActions,
|
|
50
|
+
defineConnector: () => defineConnector,
|
|
51
|
+
definePlatformAgent: () => definePlatformAgent,
|
|
52
|
+
defineSkill: () => defineSkill,
|
|
53
|
+
defineTool: () => defineTool,
|
|
54
|
+
environmentSchema: () => environmentSchema,
|
|
55
|
+
identityConfigSchema: () => identityConfigSchema,
|
|
56
|
+
isValidActionName: () => isValidActionName,
|
|
57
|
+
jitPolicySchema: () => jitPolicySchema,
|
|
58
|
+
mcpResult: () => mcpResult,
|
|
59
|
+
notificationConfigSchema: () => notificationConfigSchema,
|
|
60
|
+
parseManifestFromOutput: () => parseManifestFromOutput,
|
|
61
|
+
platformAgentConfigSchema: () => platformAgentConfigSchema,
|
|
62
|
+
projectManifestSchema: () => projectManifestSchema,
|
|
63
|
+
resourceLimitsSchema: () => resourceLimitsSchema,
|
|
64
|
+
retryPolicySchema: () => retryPolicySchema,
|
|
65
|
+
runDev: () => runDev,
|
|
66
|
+
teamConfigSchema: () => teamConfigSchema,
|
|
67
|
+
triggerConfigSchema: () => triggerConfigSchema,
|
|
68
|
+
wrapToolError: () => wrapToolError,
|
|
69
|
+
wrapToolResult: () => wrapToolResult
|
|
70
|
+
});
|
|
71
|
+
module.exports = __toCommonJS(index_exports);
|
|
72
|
+
|
|
73
|
+
// src/agents/connector-server.ts
|
|
74
|
+
var import_node_crypto = require("crypto");
|
|
75
|
+
var import_node_http = require("http");
|
|
76
|
+
var z = __toESM(require("zod"), 1);
|
|
77
|
+
|
|
78
|
+
// src/agents/errors.ts
|
|
79
|
+
var SecurityError = class extends Error {
|
|
80
|
+
code = "SECURITY_VIOLATION";
|
|
81
|
+
constructor(message) {
|
|
82
|
+
super(message);
|
|
83
|
+
this.name = "SecurityError";
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var ConnectorError = class extends Error {
|
|
87
|
+
code = "CONNECTOR_ERROR";
|
|
88
|
+
constructor(message) {
|
|
89
|
+
super(message);
|
|
90
|
+
this.name = "ConnectorError";
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// src/agents/connector-wrap.ts
|
|
95
|
+
var MAX_TOOL_RESULT_SIZE = 10 * 1024 * 1024;
|
|
96
|
+
var isMcpContent = (val) => typeof val === "object" && val !== null && "__mcpPassThrough" in val && val.__mcpPassThrough === true;
|
|
97
|
+
var wrapToolResult = (value) => {
|
|
98
|
+
if (value === null || value === void 0) {
|
|
99
|
+
return { content: [] };
|
|
100
|
+
}
|
|
101
|
+
if (typeof value === "string") {
|
|
102
|
+
return { content: [{ type: "text", text: value }] };
|
|
103
|
+
}
|
|
104
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
105
|
+
return { content: [{ type: "text", text: String(value) }] };
|
|
106
|
+
}
|
|
107
|
+
if (isMcpContent(value)) {
|
|
108
|
+
const result = { content: value.content };
|
|
109
|
+
if (value.isError) {
|
|
110
|
+
return { ...result, isError: true };
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
const json = JSON.stringify(value, null, 2);
|
|
115
|
+
if (json.length > MAX_TOOL_RESULT_SIZE) {
|
|
116
|
+
return {
|
|
117
|
+
content: [{ type: "text", text: `[Result truncated: ${json.length} bytes]` }],
|
|
118
|
+
isError: true
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return { content: [{ type: "text", text: json }] };
|
|
122
|
+
};
|
|
123
|
+
var wrapToolError = (error) => {
|
|
124
|
+
if (error instanceof ConnectorError) {
|
|
125
|
+
return {
|
|
126
|
+
content: [{ type: "text", text: error.message }],
|
|
127
|
+
isError: true
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (error instanceof Error) {
|
|
131
|
+
console.error("[connector] Internal handler error:", error.message, error.stack);
|
|
132
|
+
} else {
|
|
133
|
+
console.error("[connector] Internal handler error:", String(error));
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
content: [{ type: "text", text: "Internal handler error" }],
|
|
137
|
+
isError: true
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
var mcpResult = (content, isError) => ({
|
|
141
|
+
__mcpPassThrough: true,
|
|
142
|
+
content,
|
|
143
|
+
isError
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// src/agents/connector-server.ts
|
|
147
|
+
var MAX_BODY_SIZE = 10 * 1024 * 1024;
|
|
148
|
+
|
|
149
|
+
// src/agents/types/action.ts
|
|
150
|
+
var z2 = __toESM(require("zod"), 1);
|
|
151
|
+
var ACTION_NAME_REGEX = /^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$/;
|
|
152
|
+
var isValidActionName = (name) => name.length === 1 ? /^[a-z0-9]$/.test(name) : ACTION_NAME_REGEX.test(name);
|
|
153
|
+
var actionVariantConfigSchema = z2.object({
|
|
154
|
+
schema: z2.record(z2.string(), z2.unknown()),
|
|
155
|
+
webhook: z2.string().url().optional(),
|
|
156
|
+
hasHandler: z2.boolean()
|
|
157
|
+
});
|
|
158
|
+
var actionsConfigSchema = z2.object({
|
|
159
|
+
variants: z2.record(z2.string(), actionVariantConfigSchema)
|
|
160
|
+
}).strict();
|
|
161
|
+
|
|
162
|
+
// src/agents/types/environment.ts
|
|
163
|
+
var z3 = __toESM(require("zod"), 1);
|
|
164
|
+
var environmentSchema = z3.enum(["dev", "staging", "prod"]);
|
|
165
|
+
|
|
166
|
+
// src/agents/types/identity.ts
|
|
167
|
+
var z4 = __toESM(require("zod"), 1);
|
|
168
|
+
var jitPolicySchema = z4.enum(["auto-approve", "policy-based", "require-approval"]);
|
|
169
|
+
var identityConfigSchema = z4.object({
|
|
170
|
+
basePermissions: z4.array(z4.string()),
|
|
171
|
+
requestablePermissions: z4.array(z4.string()).optional(),
|
|
172
|
+
jitPolicy: jitPolicySchema.optional(),
|
|
173
|
+
maxJitDurationMinutes: z4.number().int().positive().optional()
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// src/agents/types/notifications.ts
|
|
177
|
+
var z5 = __toESM(require("zod"), 1);
|
|
178
|
+
var notificationConfigSchema = z5.object({
|
|
179
|
+
slack: z5.string().optional(),
|
|
180
|
+
onSuccess: z5.boolean().optional(),
|
|
181
|
+
onFailure: z5.boolean().optional(),
|
|
182
|
+
onTimeout: z5.boolean().optional()
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// src/agents/types/platform-agent.ts
|
|
186
|
+
var z9 = __toESM(require("zod"), 1);
|
|
187
|
+
|
|
188
|
+
// src/agents/types/resources.ts
|
|
189
|
+
var z6 = __toESM(require("zod"), 1);
|
|
190
|
+
var resourceLimitsSchema = z6.object({
|
|
191
|
+
maxTokens: z6.number().int().positive().optional(),
|
|
192
|
+
maxCostUsd: z6.number().positive().optional(),
|
|
193
|
+
timeoutSeconds: z6.number().int().positive().optional()
|
|
194
|
+
});
|
|
195
|
+
var retryPolicySchema = z6.object({
|
|
196
|
+
maxAttempts: z6.number().int().min(1).optional(),
|
|
197
|
+
backoffSeconds: z6.number().positive().optional()
|
|
198
|
+
});
|
|
199
|
+
var concurrencyPolicySchema = z6.object({
|
|
200
|
+
maxParallelRuns: z6.number().int().min(1).optional()
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// src/agents/types/team.ts
|
|
204
|
+
var z7 = __toESM(require("zod"), 1);
|
|
205
|
+
var teamConfigSchema = z7.object({
|
|
206
|
+
members: z7.array(z7.string()).min(1),
|
|
207
|
+
maxConcurrentWorkers: z7.number().int().min(1).optional(),
|
|
208
|
+
maxTokenBudgetPerWorker: z7.number().int().positive().optional(),
|
|
209
|
+
maxDurationPerWorker: z7.number().positive().optional()
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// src/agents/types/trigger.ts
|
|
213
|
+
var z8 = __toESM(require("zod"), 1);
|
|
214
|
+
var cronTriggerSchema = z8.object({
|
|
215
|
+
type: z8.literal("cron"),
|
|
216
|
+
expression: z8.string(),
|
|
217
|
+
timezone: z8.string().optional()
|
|
218
|
+
});
|
|
219
|
+
var webhookTriggerSchema = z8.object({
|
|
220
|
+
type: z8.literal("webhook"),
|
|
221
|
+
path: z8.string().startsWith("/"),
|
|
222
|
+
method: z8.enum(["POST", "GET"]).optional()
|
|
223
|
+
});
|
|
224
|
+
var eventTriggerSchema = z8.object({
|
|
225
|
+
type: z8.literal("event"),
|
|
226
|
+
source: z8.string(),
|
|
227
|
+
event: z8.string()
|
|
228
|
+
});
|
|
229
|
+
var apiTriggerSchema = z8.object({ type: z8.literal("api") });
|
|
230
|
+
var manualTriggerSchema = z8.object({ type: z8.literal("manual") });
|
|
231
|
+
var triggerConfigSchema = z8.discriminatedUnion("type", [
|
|
232
|
+
cronTriggerSchema,
|
|
233
|
+
webhookTriggerSchema,
|
|
234
|
+
eventTriggerSchema,
|
|
235
|
+
apiTriggerSchema,
|
|
236
|
+
manualTriggerSchema
|
|
237
|
+
]);
|
|
238
|
+
|
|
239
|
+
// src/agents/types/platform-agent.ts
|
|
240
|
+
var thinkingLevelSchema = z9.enum(["low", "medium", "high"]);
|
|
241
|
+
var logLevelSchema = z9.enum(["silent", "debug", "info", "warn", "error"]);
|
|
242
|
+
var agentDefinitionSchema = z9.object({
|
|
243
|
+
name: z9.string().min(1),
|
|
244
|
+
model: z9.string().min(1),
|
|
245
|
+
instructions: z9.string().min(1),
|
|
246
|
+
description: z9.string().optional(),
|
|
247
|
+
skills: z9.array(z9.string()).optional(),
|
|
248
|
+
temperature: z9.number().min(0).max(2).optional(),
|
|
249
|
+
allowTemperatureOverride: z9.boolean().optional(),
|
|
250
|
+
maxOutputTokens: z9.number().int().positive().optional(),
|
|
251
|
+
thinkingLevel: thinkingLevelSchema.optional(),
|
|
252
|
+
logLevel: logLevelSchema.optional()
|
|
253
|
+
}).strict();
|
|
254
|
+
var platformAgentConfigSchema = z9.object({
|
|
255
|
+
agent: agentDefinitionSchema,
|
|
256
|
+
connectors: z9.array(z9.string()).optional(),
|
|
257
|
+
trigger: triggerConfigSchema,
|
|
258
|
+
identity: identityConfigSchema.optional(),
|
|
259
|
+
resources: resourceLimitsSchema.optional(),
|
|
260
|
+
retries: retryPolicySchema.optional(),
|
|
261
|
+
concurrency: concurrencyPolicySchema.optional(),
|
|
262
|
+
team: teamConfigSchema.optional(),
|
|
263
|
+
notifications: notificationConfigSchema.optional(),
|
|
264
|
+
environment: environmentSchema.optional(),
|
|
265
|
+
actions: actionsConfigSchema.optional()
|
|
266
|
+
}).strict();
|
|
267
|
+
|
|
268
|
+
// src/agents/types/skill.ts
|
|
269
|
+
var z10 = __toESM(require("zod"), 1);
|
|
270
|
+
var platformSkillInputSchema = z10.object({
|
|
271
|
+
name: z10.string().min(1),
|
|
272
|
+
description: z10.string().optional()
|
|
273
|
+
}).strict();
|
|
274
|
+
|
|
275
|
+
// src/agents/define.ts
|
|
276
|
+
var FORBIDDEN_AGENT_KEYS = ["tools", "team", "kernel"];
|
|
277
|
+
var isAgentInstance = (value) => value != null && typeof value === "object" && "definition" in value && "name" in value && "run" in value && typeof value.run === "function";
|
|
278
|
+
var assertNoInjection = (agent) => {
|
|
279
|
+
if (agent == null || typeof agent !== "object") return;
|
|
280
|
+
if (isAgentInstance(agent)) return;
|
|
281
|
+
for (const key of FORBIDDEN_AGENT_KEYS) {
|
|
282
|
+
if (key in agent) {
|
|
283
|
+
throw new SecurityError(
|
|
284
|
+
`"agent.${key}" is not allowed in PlatformAgentConfig. Tools come from "connectors", team members from "team.members". All are platform-managed and injected via the governance gateway.`
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
var isPlatformSkill = (v) => v != null && typeof v === "object" && v.__type === "PlatformSkill";
|
|
290
|
+
var isPlatformConnector = (v) => v != null && typeof v === "object" && v.__type === "PlatformConnector";
|
|
291
|
+
var isPlatformAgent = (v) => v != null && typeof v === "object" && v.__type === "PlatformAgent";
|
|
292
|
+
var normalizeSkillRef = (ref) => isPlatformSkill(ref) ? ref.name : ref;
|
|
293
|
+
var normalizeConnectorRef = (ref) => isPlatformConnector(ref) ? ref.name : ref;
|
|
294
|
+
var normalizeTeamMember = (ref) => isPlatformAgent(ref) ? ref.config.agent.name : ref;
|
|
295
|
+
var isPlatformActions = (v) => v != null && typeof v === "object" && v.__type === "PlatformActions";
|
|
296
|
+
var definePlatformAgent = (config) => {
|
|
297
|
+
assertNoInjection(config.agent);
|
|
298
|
+
let agentDef;
|
|
299
|
+
let runtime;
|
|
300
|
+
let outputSchema;
|
|
301
|
+
if (isAgentInstance(config.agent)) {
|
|
302
|
+
agentDef = config.agent.definition;
|
|
303
|
+
runtime = config.agent;
|
|
304
|
+
} else {
|
|
305
|
+
const {
|
|
306
|
+
outputSchema: os,
|
|
307
|
+
skills: rawSkills,
|
|
308
|
+
...rest
|
|
309
|
+
} = config.agent;
|
|
310
|
+
agentDef = {
|
|
311
|
+
...rest,
|
|
312
|
+
skills: rawSkills?.map(normalizeSkillRef)
|
|
313
|
+
};
|
|
314
|
+
outputSchema = os;
|
|
315
|
+
}
|
|
316
|
+
const normalizedConnectors = config.connectors?.map(normalizeConnectorRef);
|
|
317
|
+
const normalizedTeam = config.team ? { ...config.team, members: config.team.members.map(normalizeTeamMember) } : void 0;
|
|
318
|
+
const teamAgents = config.team?.members.filter((m) => isPlatformAgent(m));
|
|
319
|
+
let actionsConfig;
|
|
320
|
+
let actionZodSchemas;
|
|
321
|
+
let actionHandlers;
|
|
322
|
+
if (config.actions && isPlatformActions(config.actions)) {
|
|
323
|
+
actionsConfig = config.actions.config;
|
|
324
|
+
actionZodSchemas = config.actions.zodSchemas;
|
|
325
|
+
const h = config.actions.handlers;
|
|
326
|
+
actionHandlers = Object.keys(h).length > 0 ? h : void 0;
|
|
327
|
+
}
|
|
328
|
+
const parsed = platformAgentConfigSchema.parse({
|
|
329
|
+
...config,
|
|
330
|
+
agent: agentDef,
|
|
331
|
+
connectors: normalizedConnectors,
|
|
332
|
+
team: normalizedTeam,
|
|
333
|
+
actions: actionsConfig
|
|
334
|
+
});
|
|
335
|
+
return {
|
|
336
|
+
__type: "PlatformAgent",
|
|
337
|
+
config: parsed,
|
|
338
|
+
runtime,
|
|
339
|
+
outputSchema,
|
|
340
|
+
actionZodSchemas,
|
|
341
|
+
actionHandlers,
|
|
342
|
+
teamAgents: teamAgents && teamAgents.length > 0 ? teamAgents : void 0
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// src/agents/define-actions.ts
|
|
347
|
+
var z11 = __toESM(require("zod"), 1);
|
|
348
|
+
var defineAction = (input) => input;
|
|
349
|
+
var defineActions = (variants) => {
|
|
350
|
+
const entries = Object.entries(variants);
|
|
351
|
+
if (entries.length === 0) {
|
|
352
|
+
throw new Error("defineActions() requires at least one action variant");
|
|
353
|
+
}
|
|
354
|
+
if (entries.length > 20) {
|
|
355
|
+
throw new Error("defineActions() supports a maximum of 20 action variants");
|
|
356
|
+
}
|
|
357
|
+
const serialized = {};
|
|
358
|
+
const zodSchemas = {};
|
|
359
|
+
const handlers = {};
|
|
360
|
+
for (const [name, variant] of entries) {
|
|
361
|
+
if (!isValidActionName(name)) {
|
|
362
|
+
throw new Error(
|
|
363
|
+
`Invalid action name "${name}": must be lowercase alphanumeric with hyphens, 1-64 chars`
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
const v = variant;
|
|
367
|
+
serialized[name] = {
|
|
368
|
+
schema: z11.toJSONSchema(v.schema, { target: "draft-2020-12" }),
|
|
369
|
+
webhook: v.webhook,
|
|
370
|
+
hasHandler: !!v.handler
|
|
371
|
+
};
|
|
372
|
+
zodSchemas[name] = v.schema;
|
|
373
|
+
if (v.handler) {
|
|
374
|
+
handlers[name] = v.handler;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return Object.freeze({
|
|
378
|
+
__type: "PlatformActions",
|
|
379
|
+
config: Object.freeze({ variants: Object.freeze(serialized) }),
|
|
380
|
+
zodSchemas: Object.freeze(zodSchemas),
|
|
381
|
+
handlers: Object.freeze(handlers)
|
|
382
|
+
});
|
|
383
|
+
};
|
|
384
|
+
var buildActionOutputSchema = (actions) => {
|
|
385
|
+
const entries = Object.entries(actions.zodSchemas);
|
|
386
|
+
if (entries.length === 0) {
|
|
387
|
+
throw new Error("Cannot build output schema from empty action definitions");
|
|
388
|
+
}
|
|
389
|
+
const variants = entries.map(
|
|
390
|
+
([name, schema]) => z11.object({ action: z11.literal(name) }).extend(schema.shape)
|
|
391
|
+
);
|
|
392
|
+
const [first, ...rest] = variants;
|
|
393
|
+
if (!first) {
|
|
394
|
+
throw new Error("Cannot build output schema from empty action definitions");
|
|
395
|
+
}
|
|
396
|
+
return z11.discriminatedUnion("action", [first, ...rest]);
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
// src/agents/define-connector.ts
|
|
400
|
+
var defineTool = (def) => def;
|
|
401
|
+
var defineConnector = (input) => {
|
|
402
|
+
if (!input.name || input.name.length === 0) {
|
|
403
|
+
throw new Error("Connector name must not be empty");
|
|
404
|
+
}
|
|
405
|
+
const tools = input.tools ? Object.freeze({ ...input.tools }) : void 0;
|
|
406
|
+
const resources = input.resources ? Object.freeze({ ...input.resources }) : void 0;
|
|
407
|
+
const prompts = input.prompts ? Object.freeze({ ...input.prompts }) : void 0;
|
|
408
|
+
return Object.freeze({
|
|
409
|
+
__type: "PlatformConnector",
|
|
410
|
+
name: input.name,
|
|
411
|
+
description: input.description,
|
|
412
|
+
instructions: input.instructions,
|
|
413
|
+
tools,
|
|
414
|
+
resources,
|
|
415
|
+
prompts
|
|
416
|
+
});
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
// src/agents/define-skill.ts
|
|
420
|
+
var defineSkill = (input) => {
|
|
421
|
+
const parsed = platformSkillInputSchema.parse(input);
|
|
422
|
+
return Object.freeze({
|
|
423
|
+
__type: "PlatformSkill",
|
|
424
|
+
name: parsed.name,
|
|
425
|
+
description: parsed.description
|
|
426
|
+
});
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
// src/cli/discover.ts
|
|
430
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
431
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
432
|
+
var import_node_url = require("url");
|
|
433
|
+
var z12 = __toESM(require("zod"), 1);
|
|
434
|
+
|
|
435
|
+
// src/cli/log.ts
|
|
436
|
+
var supportsColor = !("NO_COLOR" in process.env) && process.env.FORCE_COLOR !== "0" && (process.stderr.isTTY ?? false);
|
|
437
|
+
var code = (open, close) => {
|
|
438
|
+
const openStr = `\x1B[${open}m`;
|
|
439
|
+
const closeStr = `\x1B[${close}m`;
|
|
440
|
+
return (s) => supportsColor ? `${openStr}${s}${closeStr}` : s;
|
|
441
|
+
};
|
|
442
|
+
var bold = code(1, 22);
|
|
443
|
+
var dim = code(2, 22);
|
|
444
|
+
var red = code(31, 39);
|
|
445
|
+
var yellow = code(33, 39);
|
|
446
|
+
var green = code(32, 39);
|
|
447
|
+
var cyan = code(36, 39);
|
|
448
|
+
|
|
449
|
+
// src/cli/validate.ts
|
|
450
|
+
var ENTITY_NAME_REGEX = /^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$/;
|
|
451
|
+
var isValidEntityName = (name) => name.length === 1 ? /^[a-z0-9]$/.test(name) : ENTITY_NAME_REGEX.test(name);
|
|
452
|
+
|
|
453
|
+
// src/cli/discover.ts
|
|
454
|
+
var MANIFEST_START = "---KRAKEN-MANIFEST-START---";
|
|
455
|
+
var MANIFEST_END = "---KRAKEN-MANIFEST-END---";
|
|
456
|
+
var skillEntrySchema = z12.object({
|
|
457
|
+
name: z12.string().min(1),
|
|
458
|
+
path: z12.string().min(1),
|
|
459
|
+
content: z12.string()
|
|
460
|
+
});
|
|
461
|
+
var connectorEntrySchema = z12.object({
|
|
462
|
+
name: z12.string().min(1),
|
|
463
|
+
path: z12.string().min(1)
|
|
464
|
+
});
|
|
465
|
+
var agentEntrySchema = z12.object({
|
|
466
|
+
name: z12.string().min(1),
|
|
467
|
+
entryPoint: z12.string().min(1),
|
|
468
|
+
config: platformAgentConfigSchema
|
|
469
|
+
});
|
|
470
|
+
var projectManifestSchema = z12.object({
|
|
471
|
+
agents: z12.array(agentEntrySchema),
|
|
472
|
+
skills: z12.array(skillEntrySchema),
|
|
473
|
+
connectors: z12.array(connectorEntrySchema)
|
|
474
|
+
});
|
|
475
|
+
var MAX_SKILL_SIZE = 100 * 1024;
|
|
476
|
+
var parseManifestFromOutput = (stdout) => {
|
|
477
|
+
const startIdx = stdout.indexOf(MANIFEST_START);
|
|
478
|
+
const endIdx = stdout.indexOf(MANIFEST_END);
|
|
479
|
+
if (startIdx === -1 || endIdx === -1 || endIdx <= startIdx) {
|
|
480
|
+
throw new Error("Discovery produced no output: sentinel markers not found");
|
|
481
|
+
}
|
|
482
|
+
const jsonStr = stdout.slice(startIdx + MANIFEST_START.length, endIdx).trim();
|
|
483
|
+
let raw;
|
|
484
|
+
try {
|
|
485
|
+
raw = JSON.parse(jsonStr);
|
|
486
|
+
} catch {
|
|
487
|
+
throw new Error(`Discovery produced invalid JSON: ${jsonStr.slice(0, 200)}`);
|
|
488
|
+
}
|
|
489
|
+
const result = projectManifestSchema.safeParse(raw);
|
|
490
|
+
if (!result.success) {
|
|
491
|
+
throw new Error(`Discovery produced invalid manifest: ${result.error.message}`);
|
|
492
|
+
}
|
|
493
|
+
return result.data;
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
// src/dev.ts
|
|
497
|
+
var import_node_fs2 = require("fs");
|
|
498
|
+
var import_node_readline = require("readline");
|
|
499
|
+
var import_kraken_ai2 = require("kraken-ai");
|
|
500
|
+
|
|
501
|
+
// src/dev-actions.ts
|
|
502
|
+
var buildActionInstructions = (zodSchemas) => {
|
|
503
|
+
const entries = Object.entries(zodSchemas);
|
|
504
|
+
if (entries.length === 0) return "";
|
|
505
|
+
const variants = entries.map(([name, schema]) => {
|
|
506
|
+
const fields = Object.keys(schema.shape).join(", ");
|
|
507
|
+
return ` - "${name}": { ${fields} }`;
|
|
508
|
+
});
|
|
509
|
+
return [
|
|
510
|
+
'You MUST respond with a JSON object containing an "action" field set to one of the following action names, plus the fields for that action:',
|
|
511
|
+
"",
|
|
512
|
+
...variants,
|
|
513
|
+
"",
|
|
514
|
+
'Example: { "action": "<name>", ...fields }'
|
|
515
|
+
].join("\n");
|
|
516
|
+
};
|
|
517
|
+
var dispatchDevAction = async (output, zodSchemas, handlers, webhooks) => {
|
|
518
|
+
if (output == null || typeof output !== "object" || !("action" in output)) {
|
|
519
|
+
throw new Error('Action output must contain an "action" field');
|
|
520
|
+
}
|
|
521
|
+
const { action: actionName, ...rest } = output;
|
|
522
|
+
if (typeof actionName !== "string") {
|
|
523
|
+
throw new Error('Action output "action" field must be a string');
|
|
524
|
+
}
|
|
525
|
+
const schema = zodSchemas[actionName];
|
|
526
|
+
if (!schema) {
|
|
527
|
+
throw new Error(
|
|
528
|
+
`Unknown action "${actionName}". Expected one of: ${Object.keys(zodSchemas).join(", ")}`
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
const parsed = schema.parse(rest);
|
|
532
|
+
const payload = parsed;
|
|
533
|
+
let handlerCalled = false;
|
|
534
|
+
const handler = handlers?.[actionName];
|
|
535
|
+
if (handler) {
|
|
536
|
+
await handler(payload);
|
|
537
|
+
handlerCalled = true;
|
|
538
|
+
}
|
|
539
|
+
return {
|
|
540
|
+
actionName,
|
|
541
|
+
payload,
|
|
542
|
+
handlerCalled,
|
|
543
|
+
webhookUrl: webhooks[actionName]
|
|
544
|
+
};
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
// src/dev-connectors.ts
|
|
548
|
+
var import_node_path2 = require("path");
|
|
549
|
+
var import_kraken_ai = require("kraken-ai");
|
|
550
|
+
var isPlatformConnector2 = (v) => v != null && typeof v === "object" && v.__type === "PlatformConnector";
|
|
551
|
+
var importConnector = async (name, projectRoot) => {
|
|
552
|
+
const basePath = (0, import_node_path2.resolve)(projectRoot, "connectors", name, "index");
|
|
553
|
+
for (const ext of [".ts", ".js"]) {
|
|
554
|
+
try {
|
|
555
|
+
const mod = await import(`${basePath}${ext}`);
|
|
556
|
+
const connector = mod.default;
|
|
557
|
+
if (!isPlatformConnector2(connector)) {
|
|
558
|
+
console.warn(`[connector:${name}] Default export is not a PlatformConnector \u2014 skipping`);
|
|
559
|
+
return null;
|
|
560
|
+
}
|
|
561
|
+
return connector;
|
|
562
|
+
} catch (err) {
|
|
563
|
+
if (ext === ".ts") continue;
|
|
564
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
565
|
+
console.warn(`[connector:${name}] Failed to import \u2014 skipping. Error: ${message}`);
|
|
566
|
+
return null;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
return null;
|
|
570
|
+
};
|
|
571
|
+
var createToolsFromConnector = (connector) => {
|
|
572
|
+
const tools = connector.tools ?? {};
|
|
573
|
+
return Object.entries(tools).map(
|
|
574
|
+
([name, def]) => (0, import_kraken_ai.tool)({
|
|
575
|
+
name,
|
|
576
|
+
description: def.description,
|
|
577
|
+
parameters: def.input,
|
|
578
|
+
execute: async (args) => {
|
|
579
|
+
try {
|
|
580
|
+
const result = await Promise.resolve(def.handler(args));
|
|
581
|
+
return wrapToolResult(result);
|
|
582
|
+
} catch (error) {
|
|
583
|
+
return wrapToolError(error);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
})
|
|
587
|
+
);
|
|
588
|
+
};
|
|
589
|
+
var buildConnectorTools = (connectors) => {
|
|
590
|
+
const toolOwners = /* @__PURE__ */ new Map();
|
|
591
|
+
for (const { name, connector } of connectors) {
|
|
592
|
+
for (const toolName of Object.keys(connector.tools ?? {})) {
|
|
593
|
+
const existing = toolOwners.get(toolName);
|
|
594
|
+
if (existing) {
|
|
595
|
+
throw new Error(
|
|
596
|
+
`Tool name collision: "${toolName}" is defined by both connectors "${existing}" and "${name}". Rename one of the tools or use a unique prefix.`
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
toolOwners.set(toolName, name);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
const resourceOwners = /* @__PURE__ */ new Map();
|
|
603
|
+
for (const { name, connector } of connectors) {
|
|
604
|
+
for (const resourceName of Object.keys(connector.resources ?? {})) {
|
|
605
|
+
const existing = resourceOwners.get(resourceName);
|
|
606
|
+
if (existing) {
|
|
607
|
+
throw new Error(
|
|
608
|
+
`Resource name collision: "${resourceName}" is defined by both connectors "${existing}" and "${name}". Rename one of the resources or use a unique prefix.`
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
resourceOwners.set(resourceName, name);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
const promptOwners = /* @__PURE__ */ new Map();
|
|
615
|
+
for (const { name, connector } of connectors) {
|
|
616
|
+
for (const promptName of Object.keys(connector.prompts ?? {})) {
|
|
617
|
+
const existing = promptOwners.get(promptName);
|
|
618
|
+
if (existing) {
|
|
619
|
+
throw new Error(
|
|
620
|
+
`Prompt name collision: "${promptName}" is defined by both connectors "${existing}" and "${name}". Rename one of the prompts or use a unique prefix.`
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
promptOwners.set(promptName, name);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
const allTools = [];
|
|
627
|
+
const allResources = [];
|
|
628
|
+
const allPrompts = [];
|
|
629
|
+
const allInstructions = [];
|
|
630
|
+
for (const { name, connector } of connectors) {
|
|
631
|
+
const tools = createToolsFromConnector(connector);
|
|
632
|
+
allTools.push(...tools);
|
|
633
|
+
for (const [resName, resDef] of Object.entries(connector.resources ?? {})) {
|
|
634
|
+
allResources.push({
|
|
635
|
+
name: resName,
|
|
636
|
+
uri: resDef.uri,
|
|
637
|
+
description: resDef.description,
|
|
638
|
+
mimeType: resDef.mimeType,
|
|
639
|
+
read: (ctx) => resDef.read(ctx)
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
for (const [promptName, promptDef] of Object.entries(connector.prompts ?? {})) {
|
|
643
|
+
allPrompts.push({
|
|
644
|
+
name: promptName,
|
|
645
|
+
description: promptDef.description,
|
|
646
|
+
arguments: promptDef.arguments,
|
|
647
|
+
get: (args, ctx) => promptDef.get(args, ctx)
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
const toolCount = Object.keys(connector.tools ?? {}).length;
|
|
651
|
+
const resourceCount = Object.keys(connector.resources ?? {}).length;
|
|
652
|
+
const promptCount = Object.keys(connector.prompts ?? {}).length;
|
|
653
|
+
const parts = [
|
|
654
|
+
`${toolCount} tool${toolCount !== 1 ? "s" : ""}`,
|
|
655
|
+
`${resourceCount} resource${resourceCount !== 1 ? "s" : ""}`,
|
|
656
|
+
`${promptCount} prompt${promptCount !== 1 ? "s" : ""}`
|
|
657
|
+
];
|
|
658
|
+
console.log(` Connector: ${name} (${parts.join(", ")})`);
|
|
659
|
+
if (connector.instructions) {
|
|
660
|
+
allInstructions.push(connector.instructions);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return {
|
|
664
|
+
tools: allTools,
|
|
665
|
+
resources: allResources,
|
|
666
|
+
prompts: allPrompts,
|
|
667
|
+
instructions: allInstructions
|
|
668
|
+
};
|
|
669
|
+
};
|
|
670
|
+
var loadConnectorTools = async (connectorNames, projectRoot) => {
|
|
671
|
+
if (connectorNames.length === 0) {
|
|
672
|
+
return { tools: [], resources: [], prompts: [], instructions: [] };
|
|
673
|
+
}
|
|
674
|
+
const root = projectRoot ?? process.cwd();
|
|
675
|
+
const connectors = [];
|
|
676
|
+
for (const name of connectorNames) {
|
|
677
|
+
if (!isValidEntityName(name)) {
|
|
678
|
+
console.warn(
|
|
679
|
+
`[connector] Invalid connector name "${name}" \u2014 must match ${ENTITY_NAME_REGEX}. Skipping.`
|
|
680
|
+
);
|
|
681
|
+
continue;
|
|
682
|
+
}
|
|
683
|
+
const connector = await importConnector(name, root);
|
|
684
|
+
if (connector) {
|
|
685
|
+
connectors.push({ name, connector });
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
return buildConnectorTools(connectors);
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
// src/dev.ts
|
|
692
|
+
var loadDotenv = () => {
|
|
693
|
+
try {
|
|
694
|
+
const content = (0, import_node_fs2.readFileSync)(".env", "utf-8");
|
|
695
|
+
for (const line of content.split("\n")) {
|
|
696
|
+
const trimmed = line.trim();
|
|
697
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
698
|
+
const eqIdx = trimmed.indexOf("=");
|
|
699
|
+
if (eqIdx === -1) continue;
|
|
700
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
701
|
+
const value = trimmed.slice(eqIdx + 1).trim();
|
|
702
|
+
if (!process.env[key]) {
|
|
703
|
+
process.env[key] = value;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
} catch {
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
var FRONTMATTER_RE = /^---\n[\s\S]*?\n---\n([\s\S]*)$/;
|
|
710
|
+
var resolveSkillContent = (refs) => refs.map((ref) => {
|
|
711
|
+
try {
|
|
712
|
+
return (0, import_node_fs2.readFileSync)(`skills/${ref}`, "utf-8");
|
|
713
|
+
} catch {
|
|
714
|
+
return ref;
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
var buildInstructions = (base, skillContent) => {
|
|
718
|
+
if (skillContent.length === 0) return base;
|
|
719
|
+
const bodies = skillContent.map((s) => {
|
|
720
|
+
const m = FRONTMATTER_RE.exec(s);
|
|
721
|
+
return m?.[1]?.trim() ?? s;
|
|
722
|
+
});
|
|
723
|
+
return `${base}
|
|
724
|
+
|
|
725
|
+
${bodies.join("\n\n")}`;
|
|
726
|
+
};
|
|
727
|
+
var buildDevAgent = async (pa) => {
|
|
728
|
+
const {
|
|
729
|
+
name,
|
|
730
|
+
model,
|
|
731
|
+
instructions,
|
|
732
|
+
skills,
|
|
733
|
+
temperature,
|
|
734
|
+
thinkingLevel,
|
|
735
|
+
maxOutputTokens,
|
|
736
|
+
logLevel
|
|
737
|
+
} = pa.config.agent;
|
|
738
|
+
const connectorNames = pa.config.connectors ?? [];
|
|
739
|
+
const { tools: connectorTools, instructions: connectorInstructions } = await loadConnectorTools(connectorNames);
|
|
740
|
+
const skillContent = resolveSkillContent(skills ?? []);
|
|
741
|
+
let fullInstructions = buildInstructions(instructions, skillContent);
|
|
742
|
+
if (connectorInstructions.length > 0) {
|
|
743
|
+
fullInstructions = `${fullInstructions}
|
|
744
|
+
|
|
745
|
+
${connectorInstructions.join("\n\n")}`;
|
|
746
|
+
}
|
|
747
|
+
let outputSchema;
|
|
748
|
+
if (pa.actionZodSchemas && Object.keys(pa.actionZodSchemas).length > 0) {
|
|
749
|
+
const actionInstructions = buildActionInstructions(pa.actionZodSchemas);
|
|
750
|
+
if (actionInstructions) {
|
|
751
|
+
fullInstructions = `${fullInstructions}
|
|
752
|
+
|
|
753
|
+
${actionInstructions}`;
|
|
754
|
+
}
|
|
755
|
+
outputSchema = buildActionOutputSchema({
|
|
756
|
+
__type: "PlatformActions",
|
|
757
|
+
config: pa.config.actions ?? { variants: {} },
|
|
758
|
+
zodSchemas: pa.actionZodSchemas,
|
|
759
|
+
handlers: pa.actionHandlers ?? {}
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
let team;
|
|
763
|
+
if (pa.teamAgents && pa.teamAgents.length > 0) {
|
|
764
|
+
team = await Promise.all(pa.teamAgents.map(buildDevAgent));
|
|
765
|
+
}
|
|
766
|
+
return new import_kraken_ai2.Agent({
|
|
767
|
+
name,
|
|
768
|
+
model,
|
|
769
|
+
instructions: fullInstructions,
|
|
770
|
+
tools: connectorTools.length > 0 ? connectorTools : void 0,
|
|
771
|
+
outputSchema,
|
|
772
|
+
team,
|
|
773
|
+
temperature,
|
|
774
|
+
thinkingLevel,
|
|
775
|
+
maxOutputTokens,
|
|
776
|
+
logLevel
|
|
777
|
+
});
|
|
778
|
+
};
|
|
779
|
+
var runDev = async (agent) => {
|
|
780
|
+
loadDotenv();
|
|
781
|
+
const hasActions = agent.actionZodSchemas && Object.keys(agent.actionZodSchemas).length > 0;
|
|
782
|
+
const sdkAgent = await buildDevAgent(agent);
|
|
783
|
+
const { name, model } = agent.config.agent;
|
|
784
|
+
const connectorNames = agent.config.connectors ?? [];
|
|
785
|
+
try {
|
|
786
|
+
await sdkAgent.preflight();
|
|
787
|
+
} catch (err) {
|
|
788
|
+
console.error(`
|
|
789
|
+
${err instanceof Error ? err.message : String(err)}
|
|
790
|
+
`);
|
|
791
|
+
process.exit(1);
|
|
792
|
+
}
|
|
793
|
+
console.log(`
|
|
794
|
+
Agent: ${name}`);
|
|
795
|
+
console.log(` Model: ${model}`);
|
|
796
|
+
if (connectorNames.length > 0) {
|
|
797
|
+
console.log(` Connectors: ${connectorNames.join(", ")}`);
|
|
798
|
+
}
|
|
799
|
+
if (agent.teamAgents && agent.teamAgents.length > 0) {
|
|
800
|
+
console.log(` Team: ${agent.teamAgents.map((a) => a.config.agent.name).join(", ")}`);
|
|
801
|
+
}
|
|
802
|
+
if (hasActions && agent.actionZodSchemas) {
|
|
803
|
+
console.log(` Actions: ${Object.keys(agent.actionZodSchemas).join(", ")}`);
|
|
804
|
+
}
|
|
805
|
+
console.log(`
|
|
806
|
+
Type a message to start. Ctrl+C to exit.
|
|
807
|
+
`);
|
|
808
|
+
const rl = (0, import_node_readline.createInterface)({ input: process.stdin, output: process.stdout });
|
|
809
|
+
const messages = [];
|
|
810
|
+
const cleanup = () => {
|
|
811
|
+
rl.close();
|
|
812
|
+
process.exit(0);
|
|
813
|
+
};
|
|
814
|
+
process.on("SIGINT", cleanup);
|
|
815
|
+
process.on("SIGTERM", cleanup);
|
|
816
|
+
const ask = () => {
|
|
817
|
+
rl.question("You: ", (input) => {
|
|
818
|
+
if (!input.trim()) {
|
|
819
|
+
ask();
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
messages.push({ role: "user", content: input });
|
|
823
|
+
void (async () => {
|
|
824
|
+
try {
|
|
825
|
+
const result = await sdkAgent.run(messages, {
|
|
826
|
+
onEvent: (event) => {
|
|
827
|
+
if (event.type === "thought") {
|
|
828
|
+
console.log(
|
|
829
|
+
` [thinking] ${event.text.slice(0, 120)}${event.text.length > 120 ? "\u2026" : ""}`
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
if (event.type === "tool_call" && event.status === "success") {
|
|
833
|
+
console.log(` [tool] ${event.toolName}`);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
if (result.status === "complete") {
|
|
838
|
+
const output = typeof result.output === "string" ? result.output : JSON.stringify(result.output, null, 2);
|
|
839
|
+
if (hasActions && agent.actionZodSchemas && result.output != null && typeof result.output === "object" && "action" in result.output) {
|
|
840
|
+
const webhooks = {};
|
|
841
|
+
if (agent.config.actions?.variants) {
|
|
842
|
+
for (const [k, v] of Object.entries(agent.config.actions.variants)) {
|
|
843
|
+
webhooks[k] = v.webhook;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
try {
|
|
847
|
+
const dispatched = await dispatchDevAction(
|
|
848
|
+
result.output,
|
|
849
|
+
agent.actionZodSchemas,
|
|
850
|
+
agent.actionHandlers,
|
|
851
|
+
webhooks
|
|
852
|
+
);
|
|
853
|
+
console.log(`
|
|
854
|
+
${cyan("Action:")} ${green(dispatched.actionName)}`);
|
|
855
|
+
console.log(` ${dim("Payload:")} ${JSON.stringify(dispatched.payload, null, 2)}`);
|
|
856
|
+
if (dispatched.handlerCalled) {
|
|
857
|
+
console.log(` ${dim("Handler:")} ${green("called")}`);
|
|
858
|
+
}
|
|
859
|
+
if (dispatched.webhookUrl) {
|
|
860
|
+
console.log(
|
|
861
|
+
` ${dim("Webhook:")} ${yellow(dispatched.webhookUrl)} ${dim("(skipped in dev)")}`
|
|
862
|
+
);
|
|
863
|
+
}
|
|
864
|
+
console.log();
|
|
865
|
+
} catch (err) {
|
|
866
|
+
console.error(
|
|
867
|
+
`
|
|
868
|
+
Action dispatch error: ${err instanceof Error ? err.message : String(err)}
|
|
869
|
+
`
|
|
870
|
+
);
|
|
871
|
+
}
|
|
872
|
+
} else {
|
|
873
|
+
console.log(`
|
|
874
|
+
Agent: ${output}
|
|
875
|
+
`);
|
|
876
|
+
}
|
|
877
|
+
messages.push({ role: "assistant", content: output });
|
|
878
|
+
} else if (result.status === "interrupted") {
|
|
879
|
+
console.log(`
|
|
880
|
+
[Interrupted: ${result.interrupt.toolName} requires approval]
|
|
881
|
+
`);
|
|
882
|
+
}
|
|
883
|
+
} catch (err) {
|
|
884
|
+
console.error(`
|
|
885
|
+
Error: ${err instanceof Error ? err.message : String(err)}
|
|
886
|
+
`);
|
|
887
|
+
}
|
|
888
|
+
ask();
|
|
889
|
+
})();
|
|
890
|
+
});
|
|
891
|
+
};
|
|
892
|
+
ask();
|
|
893
|
+
return new Promise(() => {
|
|
894
|
+
});
|
|
895
|
+
};
|
|
896
|
+
|
|
897
|
+
// src/mock-tool-set.ts
|
|
898
|
+
var MockToolSet = class _MockToolSet {
|
|
899
|
+
defs;
|
|
900
|
+
overrides;
|
|
901
|
+
toolNames;
|
|
902
|
+
constructor(tools, overrides = {}) {
|
|
903
|
+
this.defs = tools;
|
|
904
|
+
this.overrides = overrides;
|
|
905
|
+
this.toolNames = new Set(tools.map((t) => t.name));
|
|
906
|
+
}
|
|
907
|
+
static fromConnectors(connectors, opts) {
|
|
908
|
+
const include = opts?.include;
|
|
909
|
+
const filtered = include ? connectors.filter((c) => include.includes(c.id)) : connectors;
|
|
910
|
+
const tools = filtered.flatMap(
|
|
911
|
+
(c) => c.tools.map((t) => ({
|
|
912
|
+
name: t.name,
|
|
913
|
+
description: t.description,
|
|
914
|
+
parameters: t.parameters
|
|
915
|
+
}))
|
|
916
|
+
);
|
|
917
|
+
return new _MockToolSet(tools, opts?.overrides);
|
|
918
|
+
}
|
|
919
|
+
definitions() {
|
|
920
|
+
return this.defs;
|
|
921
|
+
}
|
|
922
|
+
async call(name, params) {
|
|
923
|
+
if (!this.toolNames.has(name)) {
|
|
924
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
925
|
+
}
|
|
926
|
+
const override = this.overrides[name];
|
|
927
|
+
if (override) {
|
|
928
|
+
return override(params);
|
|
929
|
+
}
|
|
930
|
+
return {};
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
|
|
934
|
+
// src/platform/http.ts
|
|
935
|
+
var PlatformError = class extends Error {
|
|
936
|
+
constructor(message, status) {
|
|
937
|
+
super(message);
|
|
938
|
+
this.status = status;
|
|
939
|
+
this.name = "PlatformError";
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
var HttpClient = class {
|
|
943
|
+
baseUrlForStream;
|
|
944
|
+
baseUrl;
|
|
945
|
+
apiKey;
|
|
946
|
+
constructor(config) {
|
|
947
|
+
this.baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
948
|
+
this.baseUrlForStream = this.baseUrl;
|
|
949
|
+
this.apiKey = config.apiKey;
|
|
950
|
+
const isLocalhost = this.baseUrl.includes("localhost") || this.baseUrl.includes("127.0.0.1");
|
|
951
|
+
if (this.baseUrl.startsWith("http://") && !isLocalhost) {
|
|
952
|
+
console.warn(
|
|
953
|
+
"[kraken-ai] WARNING: baseUrl does not use HTTPS. API keys will be sent in plaintext."
|
|
954
|
+
);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
async get(path2, params) {
|
|
958
|
+
const url = this.buildUrl(path2, params);
|
|
959
|
+
const response = await fetch(url, {
|
|
960
|
+
method: "GET",
|
|
961
|
+
headers: this.authHeaders()
|
|
962
|
+
});
|
|
963
|
+
return this.handleResponse(response);
|
|
964
|
+
}
|
|
965
|
+
async post(path2, body) {
|
|
966
|
+
const response = await fetch(this.buildUrl(path2), {
|
|
967
|
+
method: "POST",
|
|
968
|
+
headers: { ...this.authHeaders(), "Content-Type": "application/json" },
|
|
969
|
+
body: body ? JSON.stringify(body) : void 0
|
|
970
|
+
});
|
|
971
|
+
return this.handleResponse(response);
|
|
972
|
+
}
|
|
973
|
+
async postStream(path2, body, signal) {
|
|
974
|
+
const response = await fetch(this.buildUrl(path2), {
|
|
975
|
+
method: "POST",
|
|
976
|
+
headers: {
|
|
977
|
+
...this.authHeaders(),
|
|
978
|
+
"Content-Type": "application/json",
|
|
979
|
+
Accept: "text/event-stream"
|
|
980
|
+
},
|
|
981
|
+
body: JSON.stringify(body),
|
|
982
|
+
signal
|
|
983
|
+
});
|
|
984
|
+
if (!response.ok) {
|
|
985
|
+
const err = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
986
|
+
throw new PlatformError(err.error ?? "Unknown error", response.status);
|
|
987
|
+
}
|
|
988
|
+
return response;
|
|
989
|
+
}
|
|
990
|
+
buildUrl(path2, params) {
|
|
991
|
+
const url = `${this.baseUrl}${path2}`;
|
|
992
|
+
if (!params || Object.keys(params).length === 0) return url;
|
|
993
|
+
const qs = new URLSearchParams(params).toString();
|
|
994
|
+
return `${url}?${qs}`;
|
|
995
|
+
}
|
|
996
|
+
authHeaders() {
|
|
997
|
+
return { Authorization: `Bearer ${this.apiKey}` };
|
|
998
|
+
}
|
|
999
|
+
async handleResponse(response) {
|
|
1000
|
+
if (!response.ok) {
|
|
1001
|
+
const body = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
1002
|
+
throw new PlatformError(body.error ?? "Unknown error", response.status);
|
|
1003
|
+
}
|
|
1004
|
+
return response.json();
|
|
1005
|
+
}
|
|
1006
|
+
};
|
|
1007
|
+
|
|
1008
|
+
// src/platform/sse.ts
|
|
1009
|
+
var VALID_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
1010
|
+
"text",
|
|
1011
|
+
"tool_call",
|
|
1012
|
+
"tool_result",
|
|
1013
|
+
"thinking",
|
|
1014
|
+
"action",
|
|
1015
|
+
"done",
|
|
1016
|
+
"error"
|
|
1017
|
+
]);
|
|
1018
|
+
async function* parseSSEStream(stream) {
|
|
1019
|
+
const decoder = new TextDecoder();
|
|
1020
|
+
const reader = stream.getReader();
|
|
1021
|
+
let buffer = "";
|
|
1022
|
+
try {
|
|
1023
|
+
while (true) {
|
|
1024
|
+
const { done, value } = await reader.read();
|
|
1025
|
+
if (done) break;
|
|
1026
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1027
|
+
const parts = buffer.split("\n\n");
|
|
1028
|
+
buffer = parts.pop() ?? "";
|
|
1029
|
+
for (const part of parts) {
|
|
1030
|
+
const event = parseBlock(part);
|
|
1031
|
+
if (event) yield event;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
if (buffer.trim()) {
|
|
1035
|
+
const event = parseBlock(buffer);
|
|
1036
|
+
if (event) yield event;
|
|
1037
|
+
}
|
|
1038
|
+
} finally {
|
|
1039
|
+
reader.releaseLock();
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
var parseBlock = (block) => {
|
|
1043
|
+
let eventType = null;
|
|
1044
|
+
let data = null;
|
|
1045
|
+
for (const line of block.split("\n")) {
|
|
1046
|
+
if (line.startsWith(":")) continue;
|
|
1047
|
+
if (line.startsWith("event: ")) {
|
|
1048
|
+
eventType = line.slice(7).trim();
|
|
1049
|
+
} else if (line.startsWith("data: ")) {
|
|
1050
|
+
data = line.slice(6);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
if (!eventType || !data || !VALID_EVENT_TYPES.has(eventType)) return null;
|
|
1054
|
+
try {
|
|
1055
|
+
const parsed = JSON.parse(data);
|
|
1056
|
+
return { type: eventType, ...parsed };
|
|
1057
|
+
} catch {
|
|
1058
|
+
return null;
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
|
|
1062
|
+
// src/platform/agent-handle.ts
|
|
1063
|
+
var deferred = () => {
|
|
1064
|
+
let resolve2;
|
|
1065
|
+
let reject;
|
|
1066
|
+
const promise = new Promise((res, rej) => {
|
|
1067
|
+
resolve2 = res;
|
|
1068
|
+
reject = rej;
|
|
1069
|
+
});
|
|
1070
|
+
return { promise, resolve: resolve2, reject };
|
|
1071
|
+
};
|
|
1072
|
+
var AgentHandle = class {
|
|
1073
|
+
constructor(http, agentId, opts) {
|
|
1074
|
+
this.http = http;
|
|
1075
|
+
this.agentId = agentId;
|
|
1076
|
+
this.threadId = opts?.threadId;
|
|
1077
|
+
}
|
|
1078
|
+
actionHandlers = /* @__PURE__ */ new Map();
|
|
1079
|
+
threadId;
|
|
1080
|
+
onAction(name, handler) {
|
|
1081
|
+
this.actionHandlers.set(name, handler);
|
|
1082
|
+
}
|
|
1083
|
+
async generate(input, opts) {
|
|
1084
|
+
if (!this.threadId) {
|
|
1085
|
+
const info = await this.http.post(`/api/v1/agents/${this.agentId}/threads`);
|
|
1086
|
+
this.threadId = info.id;
|
|
1087
|
+
}
|
|
1088
|
+
const response = await this.http.postStream(
|
|
1089
|
+
`/api/v1/agents/${this.agentId}/threads/${this.threadId}/messages`,
|
|
1090
|
+
{ content: typeof input === "string" ? input : JSON.stringify(input) },
|
|
1091
|
+
opts?.signal
|
|
1092
|
+
);
|
|
1093
|
+
if (!response.body) {
|
|
1094
|
+
throw new PlatformError("Response body is empty", 0);
|
|
1095
|
+
}
|
|
1096
|
+
const rawStream = parseSSEStream(response.body);
|
|
1097
|
+
const {
|
|
1098
|
+
promise: resultPromise,
|
|
1099
|
+
resolve: resolveResult,
|
|
1100
|
+
reject: rejectResult
|
|
1101
|
+
} = deferred();
|
|
1102
|
+
const actionHandlers = this.actionHandlers;
|
|
1103
|
+
const http = this.http;
|
|
1104
|
+
const agentId = this.agentId;
|
|
1105
|
+
const threadId = this.threadId;
|
|
1106
|
+
async function* streamWithDispatch() {
|
|
1107
|
+
try {
|
|
1108
|
+
for await (const event of rawStream) {
|
|
1109
|
+
if (event.type === "action") {
|
|
1110
|
+
const handler = actionHandlers.get(event.name);
|
|
1111
|
+
if (handler) {
|
|
1112
|
+
await handler(event.payload);
|
|
1113
|
+
}
|
|
1114
|
+
void http.post(
|
|
1115
|
+
`/api/v1/agents/${agentId}/threads/${threadId}/actions/${event.actionExecutionId}/ack`
|
|
1116
|
+
).catch(() => {
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
if (event.type === "done") {
|
|
1120
|
+
resolveResult(event.output);
|
|
1121
|
+
}
|
|
1122
|
+
if (event.type === "error") {
|
|
1123
|
+
rejectResult(new PlatformError(event.message, 0));
|
|
1124
|
+
}
|
|
1125
|
+
yield event;
|
|
1126
|
+
}
|
|
1127
|
+
} catch (err) {
|
|
1128
|
+
rejectResult(err instanceof Error ? err : new Error(String(err)));
|
|
1129
|
+
throw err;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
let streamGenerator = null;
|
|
1133
|
+
let streamStarted = false;
|
|
1134
|
+
const ensureStream = () => {
|
|
1135
|
+
if (!streamGenerator) {
|
|
1136
|
+
streamGenerator = streamWithDispatch();
|
|
1137
|
+
}
|
|
1138
|
+
return streamGenerator;
|
|
1139
|
+
};
|
|
1140
|
+
const backgroundConsume = async () => {
|
|
1141
|
+
if (streamStarted) return;
|
|
1142
|
+
streamStarted = true;
|
|
1143
|
+
const gen = ensureStream();
|
|
1144
|
+
for await (const _ of gen) {
|
|
1145
|
+
void _;
|
|
1146
|
+
}
|
|
1147
|
+
};
|
|
1148
|
+
const result = {
|
|
1149
|
+
threadId,
|
|
1150
|
+
stream() {
|
|
1151
|
+
streamStarted = true;
|
|
1152
|
+
return ensureStream();
|
|
1153
|
+
},
|
|
1154
|
+
get result() {
|
|
1155
|
+
void backgroundConsume();
|
|
1156
|
+
return resultPromise;
|
|
1157
|
+
}
|
|
1158
|
+
};
|
|
1159
|
+
return result;
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
|
|
1163
|
+
// src/platform/agents.ts
|
|
1164
|
+
var AgentThread = class {
|
|
1165
|
+
constructor(http, agentId, threadId) {
|
|
1166
|
+
this.http = http;
|
|
1167
|
+
this.agentId = agentId;
|
|
1168
|
+
this.threadId = threadId;
|
|
1169
|
+
}
|
|
1170
|
+
async sendMessage(content, opts) {
|
|
1171
|
+
const response = await this.http.postStream(
|
|
1172
|
+
`/api/v1/agents/${this.agentId}/threads/${this.threadId}/messages`,
|
|
1173
|
+
{ content },
|
|
1174
|
+
opts?.signal
|
|
1175
|
+
);
|
|
1176
|
+
if (!response.body) {
|
|
1177
|
+
throw new PlatformError("Response body is empty", 0);
|
|
1178
|
+
}
|
|
1179
|
+
return parseSSEStream(response.body);
|
|
1180
|
+
}
|
|
1181
|
+
async getMessages(params) {
|
|
1182
|
+
const qs = buildPaginationQuery(params);
|
|
1183
|
+
return this.http.get(`/api/v1/agents/${this.agentId}/threads/${this.threadId}/messages`, qs);
|
|
1184
|
+
}
|
|
1185
|
+
};
|
|
1186
|
+
var AgentsNamespace = class {
|
|
1187
|
+
constructor(http) {
|
|
1188
|
+
this.http = http;
|
|
1189
|
+
}
|
|
1190
|
+
async list() {
|
|
1191
|
+
const result = await this.http.get("/api/v1/agents");
|
|
1192
|
+
return result.data;
|
|
1193
|
+
}
|
|
1194
|
+
async createThread(agentId) {
|
|
1195
|
+
const info = await this.http.post(`/api/v1/agents/${agentId}/threads`);
|
|
1196
|
+
return new AgentThread(this.http, agentId, info.id);
|
|
1197
|
+
}
|
|
1198
|
+
async getThread(agentId, threadId) {
|
|
1199
|
+
await this.http.get(`/api/v1/agents/${agentId}/threads/${threadId}`);
|
|
1200
|
+
return new AgentThread(this.http, agentId, threadId);
|
|
1201
|
+
}
|
|
1202
|
+
async listThreads(agentId, params) {
|
|
1203
|
+
const qs = buildPaginationQuery(params);
|
|
1204
|
+
return this.http.get(`/api/v1/agents/${agentId}/threads`, qs);
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
var buildPaginationQuery = (params) => {
|
|
1208
|
+
if (!params) return void 0;
|
|
1209
|
+
const qs = {};
|
|
1210
|
+
if (params.cursor) qs.cursor = params.cursor;
|
|
1211
|
+
if (params.limit != null) qs.limit = String(params.limit);
|
|
1212
|
+
return Object.keys(qs).length > 0 ? qs : void 0;
|
|
1213
|
+
};
|
|
1214
|
+
|
|
1215
|
+
// src/platform/data.ts
|
|
1216
|
+
var DataNamespace = class {
|
|
1217
|
+
constructor(http) {
|
|
1218
|
+
this.http = http;
|
|
1219
|
+
}
|
|
1220
|
+
async list() {
|
|
1221
|
+
const result = await this.http.get("/api/v1/data/queries");
|
|
1222
|
+
return result.data;
|
|
1223
|
+
}
|
|
1224
|
+
async describe(queryName) {
|
|
1225
|
+
return this.http.get(`/api/v1/data/queries/${queryName}`);
|
|
1226
|
+
}
|
|
1227
|
+
async query(queryName, params, pagination) {
|
|
1228
|
+
return this.http.post(`/api/v1/data/queries/${queryName}/execute`, {
|
|
1229
|
+
params,
|
|
1230
|
+
...pagination
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
};
|
|
1234
|
+
|
|
1235
|
+
// src/platform/pipelines.ts
|
|
1236
|
+
var z13 = __toESM(require("zod"), 1);
|
|
1237
|
+
var PipelinesNamespace = class {
|
|
1238
|
+
constructor(http) {
|
|
1239
|
+
this.http = http;
|
|
1240
|
+
}
|
|
1241
|
+
async query(pipeline, queryName, schema, params) {
|
|
1242
|
+
const result = await this.http.post(
|
|
1243
|
+
`/api/v1/pipelines/${encodeURIComponent(pipeline)}/queries/${encodeURIComponent(queryName)}`,
|
|
1244
|
+
params
|
|
1245
|
+
);
|
|
1246
|
+
try {
|
|
1247
|
+
return z13.array(schema.returns).parse(result.rows);
|
|
1248
|
+
} catch (e) {
|
|
1249
|
+
throw new Error(
|
|
1250
|
+
`Pipeline schema may have changed \u2014 run 'kraken generate' to update types.
|
|
1251
|
+
|
|
1252
|
+
Original error: ${e.message}`
|
|
1253
|
+
);
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
|
|
1258
|
+
// src/platform/runs.ts
|
|
1259
|
+
var RunsNamespace = class {
|
|
1260
|
+
constructor(http) {
|
|
1261
|
+
this.http = http;
|
|
1262
|
+
}
|
|
1263
|
+
async start(params) {
|
|
1264
|
+
return this.http.post("/api/v1/runs", params);
|
|
1265
|
+
}
|
|
1266
|
+
async get(runId) {
|
|
1267
|
+
return this.http.get(`/api/v1/runs/${runId}`);
|
|
1268
|
+
}
|
|
1269
|
+
async cancel(runId) {
|
|
1270
|
+
return this.http.post(`/api/v1/runs/${runId}/cancel`);
|
|
1271
|
+
}
|
|
1272
|
+
async getEvents(runId, opts) {
|
|
1273
|
+
const params = opts?.afterEventId ? { afterEventId: opts.afterEventId } : void 0;
|
|
1274
|
+
return this.http.get(`/api/v1/runs/${runId}/events`, params);
|
|
1275
|
+
}
|
|
1276
|
+
async *streamEvents(runId, opts) {
|
|
1277
|
+
const response = await fetch(
|
|
1278
|
+
`${this.http.baseUrlForStream}/api/v1/runs/${runId}/events/stream`,
|
|
1279
|
+
{
|
|
1280
|
+
headers: {
|
|
1281
|
+
Accept: "text/event-stream",
|
|
1282
|
+
...this.http.authHeaders()
|
|
1283
|
+
},
|
|
1284
|
+
signal: opts?.signal
|
|
1285
|
+
}
|
|
1286
|
+
);
|
|
1287
|
+
if (!response.ok || !response.body) {
|
|
1288
|
+
throw new PlatformError("Failed to connect to event stream", response.status);
|
|
1289
|
+
}
|
|
1290
|
+
const reader = response.body.getReader();
|
|
1291
|
+
const decoder = new TextDecoder();
|
|
1292
|
+
let buffer = "";
|
|
1293
|
+
try {
|
|
1294
|
+
while (true) {
|
|
1295
|
+
const { done, value } = await reader.read();
|
|
1296
|
+
if (done) break;
|
|
1297
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1298
|
+
const lines = buffer.split("\n");
|
|
1299
|
+
buffer = lines.pop() ?? "";
|
|
1300
|
+
for (const line of lines) {
|
|
1301
|
+
if (!line.startsWith("data: ")) continue;
|
|
1302
|
+
const raw = line.slice(6).trim();
|
|
1303
|
+
if (!raw || raw === "[DONE]") continue;
|
|
1304
|
+
try {
|
|
1305
|
+
yield JSON.parse(raw);
|
|
1306
|
+
} catch {
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
} finally {
|
|
1311
|
+
reader.cancel();
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1315
|
+
|
|
1316
|
+
// src/platform/client.ts
|
|
1317
|
+
var PlatformClient = class {
|
|
1318
|
+
agents;
|
|
1319
|
+
data;
|
|
1320
|
+
pipelines;
|
|
1321
|
+
runs;
|
|
1322
|
+
http;
|
|
1323
|
+
constructor(config) {
|
|
1324
|
+
if (!config.baseUrl) throw new Error("baseUrl is required");
|
|
1325
|
+
if (!config.apiKey) throw new Error("apiKey is required");
|
|
1326
|
+
this.http = new HttpClient(config);
|
|
1327
|
+
this.agents = new AgentsNamespace(this.http);
|
|
1328
|
+
this.data = new DataNamespace(this.http);
|
|
1329
|
+
this.pipelines = new PipelinesNamespace(this.http);
|
|
1330
|
+
this.runs = new RunsNamespace(this.http);
|
|
1331
|
+
}
|
|
1332
|
+
agent(id, opts) {
|
|
1333
|
+
if (opts?.mode === "local") {
|
|
1334
|
+
throw new PlatformError("Local mode not yet implemented", 0);
|
|
1335
|
+
}
|
|
1336
|
+
return new AgentHandle(this.http, id, {
|
|
1337
|
+
threadId: opts?.threadId
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
};
|
|
1341
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1342
|
+
0 && (module.exports = {
|
|
1343
|
+
ACTION_NAME_REGEX,
|
|
1344
|
+
AgentHandle,
|
|
1345
|
+
AgentThread,
|
|
1346
|
+
ConnectorError,
|
|
1347
|
+
MANIFEST_END,
|
|
1348
|
+
MANIFEST_START,
|
|
1349
|
+
MockToolSet,
|
|
1350
|
+
PlatformClient,
|
|
1351
|
+
PlatformError,
|
|
1352
|
+
SecurityError,
|
|
1353
|
+
actionVariantConfigSchema,
|
|
1354
|
+
actionsConfigSchema,
|
|
1355
|
+
agentDefinitionSchema,
|
|
1356
|
+
buildActionOutputSchema,
|
|
1357
|
+
concurrencyPolicySchema,
|
|
1358
|
+
defineAction,
|
|
1359
|
+
defineActions,
|
|
1360
|
+
defineConnector,
|
|
1361
|
+
definePlatformAgent,
|
|
1362
|
+
defineSkill,
|
|
1363
|
+
defineTool,
|
|
1364
|
+
environmentSchema,
|
|
1365
|
+
identityConfigSchema,
|
|
1366
|
+
isValidActionName,
|
|
1367
|
+
jitPolicySchema,
|
|
1368
|
+
mcpResult,
|
|
1369
|
+
notificationConfigSchema,
|
|
1370
|
+
parseManifestFromOutput,
|
|
1371
|
+
platformAgentConfigSchema,
|
|
1372
|
+
projectManifestSchema,
|
|
1373
|
+
resourceLimitsSchema,
|
|
1374
|
+
retryPolicySchema,
|
|
1375
|
+
runDev,
|
|
1376
|
+
teamConfigSchema,
|
|
1377
|
+
triggerConfigSchema,
|
|
1378
|
+
wrapToolError,
|
|
1379
|
+
wrapToolResult
|
|
1380
|
+
});
|
|
1381
|
+
//# sourceMappingURL=index.cjs.map
|