@kraken-ai/platform 0.0.1 → 0.0.3
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/{chunk-HGJSK6MW.js → chunk-PPT6GGYL.js} +99 -2
- package/dist/chunk-PPT6GGYL.js.map +1 -0
- package/dist/cli.js +47 -19
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +3 -449
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -369
- package/dist/index.d.ts +14 -369
- package/dist/index.js +92 -611
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +498 -6
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +19 -2
- package/dist/server.d.ts +19 -2
- package/dist/server.js +451 -2
- package/dist/server.js.map +1 -1
- package/dist/types-CkknNKNr.d.cts +451 -0
- package/dist/types-CkknNKNr.d.ts +451 -0
- package/package.json +3 -3
- package/dist/chunk-HGJSK6MW.js.map +0 -1
- package/dist/connector-CumEDPfS.d.cts +0 -103
- package/dist/connector-CumEDPfS.d.ts +0 -103
package/dist/index.js
CHANGED
|
@@ -1,94 +1,88 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ACTION_NAME_REGEX,
|
|
2
3
|
ConnectorError,
|
|
3
4
|
SecurityError,
|
|
5
|
+
actionVariantConfigSchema,
|
|
6
|
+
actionsConfigSchema,
|
|
7
|
+
buildActionOutputSchema,
|
|
8
|
+
defineAction,
|
|
9
|
+
defineActions,
|
|
10
|
+
isValidActionName,
|
|
4
11
|
mcpResult,
|
|
5
12
|
wrapToolError,
|
|
6
13
|
wrapToolResult
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
|
|
9
|
-
// src/agents/types/action.ts
|
|
10
|
-
import * as z from "zod";
|
|
11
|
-
var ACTION_NAME_REGEX = /^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$/;
|
|
12
|
-
var isValidActionName = (name) => name.length === 1 ? /^[a-z0-9]$/.test(name) : ACTION_NAME_REGEX.test(name);
|
|
13
|
-
var actionVariantConfigSchema = z.object({
|
|
14
|
-
schema: z.record(z.string(), z.unknown()),
|
|
15
|
-
webhook: z.string().url().optional(),
|
|
16
|
-
hasHandler: z.boolean()
|
|
17
|
-
});
|
|
18
|
-
var actionsConfigSchema = z.object({
|
|
19
|
-
variants: z.record(z.string(), actionVariantConfigSchema)
|
|
20
|
-
}).strict();
|
|
14
|
+
} from "./chunk-PPT6GGYL.js";
|
|
21
15
|
|
|
22
16
|
// src/agents/types/environment.ts
|
|
23
|
-
import * as
|
|
24
|
-
var environmentSchema =
|
|
17
|
+
import * as z from "zod";
|
|
18
|
+
var environmentSchema = z.enum(["dev", "staging", "prod"]);
|
|
25
19
|
|
|
26
20
|
// src/agents/types/identity.ts
|
|
27
|
-
import * as
|
|
28
|
-
var jitPolicySchema =
|
|
29
|
-
var identityConfigSchema =
|
|
30
|
-
basePermissions:
|
|
31
|
-
requestablePermissions:
|
|
21
|
+
import * as z2 from "zod";
|
|
22
|
+
var jitPolicySchema = z2.enum(["auto-approve", "policy-based", "require-approval"]);
|
|
23
|
+
var identityConfigSchema = z2.object({
|
|
24
|
+
basePermissions: z2.array(z2.string()),
|
|
25
|
+
requestablePermissions: z2.array(z2.string()).optional(),
|
|
32
26
|
jitPolicy: jitPolicySchema.optional(),
|
|
33
|
-
maxJitDurationMinutes:
|
|
27
|
+
maxJitDurationMinutes: z2.number().int().positive().optional()
|
|
34
28
|
});
|
|
35
29
|
|
|
36
30
|
// src/agents/types/notifications.ts
|
|
37
|
-
import * as
|
|
38
|
-
var notificationConfigSchema =
|
|
39
|
-
slack:
|
|
40
|
-
onSuccess:
|
|
41
|
-
onFailure:
|
|
42
|
-
onTimeout:
|
|
31
|
+
import * as z3 from "zod";
|
|
32
|
+
var notificationConfigSchema = z3.object({
|
|
33
|
+
slack: z3.string().optional(),
|
|
34
|
+
onSuccess: z3.boolean().optional(),
|
|
35
|
+
onFailure: z3.boolean().optional(),
|
|
36
|
+
onTimeout: z3.boolean().optional()
|
|
43
37
|
});
|
|
44
38
|
|
|
45
39
|
// src/agents/types/platform-agent.ts
|
|
46
|
-
import * as
|
|
40
|
+
import * as z7 from "zod";
|
|
47
41
|
|
|
48
42
|
// src/agents/types/resources.ts
|
|
49
|
-
import * as
|
|
50
|
-
var resourceLimitsSchema =
|
|
51
|
-
maxTokens:
|
|
52
|
-
maxCostUsd:
|
|
53
|
-
timeoutSeconds:
|
|
43
|
+
import * as z4 from "zod";
|
|
44
|
+
var resourceLimitsSchema = z4.object({
|
|
45
|
+
maxTokens: z4.number().int().positive().optional(),
|
|
46
|
+
maxCostUsd: z4.number().positive().optional(),
|
|
47
|
+
timeoutSeconds: z4.number().int().positive().optional()
|
|
54
48
|
});
|
|
55
|
-
var retryPolicySchema =
|
|
56
|
-
maxAttempts:
|
|
57
|
-
backoffSeconds:
|
|
49
|
+
var retryPolicySchema = z4.object({
|
|
50
|
+
maxAttempts: z4.number().int().min(1).optional(),
|
|
51
|
+
backoffSeconds: z4.number().positive().optional()
|
|
58
52
|
});
|
|
59
|
-
var concurrencyPolicySchema =
|
|
60
|
-
maxParallelRuns:
|
|
53
|
+
var concurrencyPolicySchema = z4.object({
|
|
54
|
+
maxParallelRuns: z4.number().int().min(1).optional()
|
|
61
55
|
});
|
|
62
56
|
|
|
63
57
|
// src/agents/types/team.ts
|
|
64
|
-
import * as
|
|
65
|
-
var teamConfigSchema =
|
|
66
|
-
members:
|
|
67
|
-
maxConcurrentWorkers:
|
|
68
|
-
maxTokenBudgetPerWorker:
|
|
69
|
-
maxDurationPerWorker:
|
|
58
|
+
import * as z5 from "zod";
|
|
59
|
+
var teamConfigSchema = z5.object({
|
|
60
|
+
members: z5.array(z5.string()).min(1),
|
|
61
|
+
maxConcurrentWorkers: z5.number().int().min(1).optional(),
|
|
62
|
+
maxTokenBudgetPerWorker: z5.number().int().positive().optional(),
|
|
63
|
+
maxDurationPerWorker: z5.number().positive().optional()
|
|
70
64
|
});
|
|
71
65
|
|
|
72
66
|
// src/agents/types/trigger.ts
|
|
73
|
-
import * as
|
|
74
|
-
var cronTriggerSchema =
|
|
75
|
-
type:
|
|
76
|
-
expression:
|
|
77
|
-
timezone:
|
|
67
|
+
import * as z6 from "zod";
|
|
68
|
+
var cronTriggerSchema = z6.object({
|
|
69
|
+
type: z6.literal("cron"),
|
|
70
|
+
expression: z6.string(),
|
|
71
|
+
timezone: z6.string().optional()
|
|
78
72
|
});
|
|
79
|
-
var webhookTriggerSchema =
|
|
80
|
-
type:
|
|
81
|
-
path:
|
|
82
|
-
method:
|
|
73
|
+
var webhookTriggerSchema = z6.object({
|
|
74
|
+
type: z6.literal("webhook"),
|
|
75
|
+
path: z6.string().startsWith("/"),
|
|
76
|
+
method: z6.enum(["POST", "GET"]).optional()
|
|
83
77
|
});
|
|
84
|
-
var eventTriggerSchema =
|
|
85
|
-
type:
|
|
86
|
-
source:
|
|
87
|
-
event:
|
|
78
|
+
var eventTriggerSchema = z6.object({
|
|
79
|
+
type: z6.literal("event"),
|
|
80
|
+
source: z6.string(),
|
|
81
|
+
event: z6.string()
|
|
88
82
|
});
|
|
89
|
-
var apiTriggerSchema =
|
|
90
|
-
var manualTriggerSchema =
|
|
91
|
-
var triggerConfigSchema =
|
|
83
|
+
var apiTriggerSchema = z6.object({ type: z6.literal("api") });
|
|
84
|
+
var manualTriggerSchema = z6.object({ type: z6.literal("manual") });
|
|
85
|
+
var triggerConfigSchema = z6.discriminatedUnion("type", [
|
|
92
86
|
cronTriggerSchema,
|
|
93
87
|
webhookTriggerSchema,
|
|
94
88
|
eventTriggerSchema,
|
|
@@ -97,23 +91,23 @@ var triggerConfigSchema = z7.discriminatedUnion("type", [
|
|
|
97
91
|
]);
|
|
98
92
|
|
|
99
93
|
// src/agents/types/platform-agent.ts
|
|
100
|
-
var thinkingLevelSchema =
|
|
101
|
-
var logLevelSchema =
|
|
102
|
-
var agentDefinitionSchema =
|
|
103
|
-
name:
|
|
104
|
-
model:
|
|
105
|
-
instructions:
|
|
106
|
-
description:
|
|
107
|
-
skills:
|
|
108
|
-
temperature:
|
|
109
|
-
allowTemperatureOverride:
|
|
110
|
-
maxOutputTokens:
|
|
94
|
+
var thinkingLevelSchema = z7.enum(["low", "medium", "high"]);
|
|
95
|
+
var logLevelSchema = z7.enum(["silent", "debug", "info", "warn", "error"]);
|
|
96
|
+
var agentDefinitionSchema = z7.object({
|
|
97
|
+
name: z7.string().min(1),
|
|
98
|
+
model: z7.string().min(1),
|
|
99
|
+
instructions: z7.string().min(1),
|
|
100
|
+
description: z7.string().optional(),
|
|
101
|
+
skills: z7.array(z7.string()).optional(),
|
|
102
|
+
temperature: z7.number().min(0).max(2).optional(),
|
|
103
|
+
allowTemperatureOverride: z7.boolean().optional(),
|
|
104
|
+
maxOutputTokens: z7.number().int().positive().optional(),
|
|
111
105
|
thinkingLevel: thinkingLevelSchema.optional(),
|
|
112
106
|
logLevel: logLevelSchema.optional()
|
|
113
107
|
}).strict();
|
|
114
|
-
var platformAgentConfigSchema =
|
|
108
|
+
var platformAgentConfigSchema = z7.object({
|
|
115
109
|
agent: agentDefinitionSchema,
|
|
116
|
-
connectors:
|
|
110
|
+
connectors: z7.array(z7.string()).optional(),
|
|
117
111
|
trigger: triggerConfigSchema,
|
|
118
112
|
identity: identityConfigSchema.optional(),
|
|
119
113
|
resources: resourceLimitsSchema.optional(),
|
|
@@ -126,10 +120,10 @@ var platformAgentConfigSchema = z8.object({
|
|
|
126
120
|
}).strict();
|
|
127
121
|
|
|
128
122
|
// src/agents/types/skill.ts
|
|
129
|
-
import * as
|
|
130
|
-
var platformSkillInputSchema =
|
|
131
|
-
name:
|
|
132
|
-
description:
|
|
123
|
+
import * as z8 from "zod";
|
|
124
|
+
var platformSkillInputSchema = z8.object({
|
|
125
|
+
name: z8.string().min(1),
|
|
126
|
+
description: z8.string().optional()
|
|
133
127
|
}).strict();
|
|
134
128
|
|
|
135
129
|
// src/agents/define.ts
|
|
@@ -203,59 +197,6 @@ var definePlatformAgent = (config) => {
|
|
|
203
197
|
};
|
|
204
198
|
};
|
|
205
199
|
|
|
206
|
-
// src/agents/define-actions.ts
|
|
207
|
-
import * as z10 from "zod";
|
|
208
|
-
var defineAction = (input) => input;
|
|
209
|
-
var defineActions = (variants) => {
|
|
210
|
-
const entries = Object.entries(variants);
|
|
211
|
-
if (entries.length === 0) {
|
|
212
|
-
throw new Error("defineActions() requires at least one action variant");
|
|
213
|
-
}
|
|
214
|
-
if (entries.length > 20) {
|
|
215
|
-
throw new Error("defineActions() supports a maximum of 20 action variants");
|
|
216
|
-
}
|
|
217
|
-
const serialized = {};
|
|
218
|
-
const zodSchemas = {};
|
|
219
|
-
const handlers = {};
|
|
220
|
-
for (const [name, variant] of entries) {
|
|
221
|
-
if (!isValidActionName(name)) {
|
|
222
|
-
throw new Error(
|
|
223
|
-
`Invalid action name "${name}": must be lowercase alphanumeric with hyphens, 1-64 chars`
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
const v = variant;
|
|
227
|
-
serialized[name] = {
|
|
228
|
-
schema: z10.toJSONSchema(v.schema, { target: "draft-2020-12" }),
|
|
229
|
-
webhook: v.webhook,
|
|
230
|
-
hasHandler: !!v.handler
|
|
231
|
-
};
|
|
232
|
-
zodSchemas[name] = v.schema;
|
|
233
|
-
if (v.handler) {
|
|
234
|
-
handlers[name] = v.handler;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
return Object.freeze({
|
|
238
|
-
__type: "PlatformActions",
|
|
239
|
-
config: Object.freeze({ variants: Object.freeze(serialized) }),
|
|
240
|
-
zodSchemas: Object.freeze(zodSchemas),
|
|
241
|
-
handlers: Object.freeze(handlers)
|
|
242
|
-
});
|
|
243
|
-
};
|
|
244
|
-
var buildActionOutputSchema = (actions) => {
|
|
245
|
-
const entries = Object.entries(actions.zodSchemas);
|
|
246
|
-
if (entries.length === 0) {
|
|
247
|
-
throw new Error("Cannot build output schema from empty action definitions");
|
|
248
|
-
}
|
|
249
|
-
const variants = entries.map(
|
|
250
|
-
([name, schema]) => z10.object({ action: z10.literal(name) }).extend(schema.shape)
|
|
251
|
-
);
|
|
252
|
-
const [first, ...rest] = variants;
|
|
253
|
-
if (!first) {
|
|
254
|
-
throw new Error("Cannot build output schema from empty action definitions");
|
|
255
|
-
}
|
|
256
|
-
return z10.discriminatedUnion("action", [first, ...rest]);
|
|
257
|
-
};
|
|
258
|
-
|
|
259
200
|
// src/agents/define-connector.ts
|
|
260
201
|
var defineTool = (def) => def;
|
|
261
202
|
var defineConnector = (input) => {
|
|
@@ -290,47 +231,27 @@ var defineSkill = (input) => {
|
|
|
290
231
|
import fs from "fs";
|
|
291
232
|
import path from "path";
|
|
292
233
|
import { pathToFileURL } from "url";
|
|
293
|
-
import * as
|
|
294
|
-
|
|
295
|
-
// src/cli/log.ts
|
|
296
|
-
var supportsColor = !("NO_COLOR" in process.env) && process.env.FORCE_COLOR !== "0" && (process.stderr.isTTY ?? false);
|
|
297
|
-
var code = (open, close) => {
|
|
298
|
-
const openStr = `\x1B[${open}m`;
|
|
299
|
-
const closeStr = `\x1B[${close}m`;
|
|
300
|
-
return (s) => supportsColor ? `${openStr}${s}${closeStr}` : s;
|
|
301
|
-
};
|
|
302
|
-
var bold = code(1, 22);
|
|
303
|
-
var dim = code(2, 22);
|
|
304
|
-
var red = code(31, 39);
|
|
305
|
-
var yellow = code(33, 39);
|
|
306
|
-
var green = code(32, 39);
|
|
307
|
-
var cyan = code(36, 39);
|
|
308
|
-
|
|
309
|
-
// src/cli/validate.ts
|
|
310
|
-
var ENTITY_NAME_REGEX = /^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$/;
|
|
311
|
-
var isValidEntityName = (name) => name.length === 1 ? /^[a-z0-9]$/.test(name) : ENTITY_NAME_REGEX.test(name);
|
|
312
|
-
|
|
313
|
-
// src/cli/discover.ts
|
|
234
|
+
import * as z9 from "zod";
|
|
314
235
|
var MANIFEST_START = "---KRAKEN-MANIFEST-START---";
|
|
315
236
|
var MANIFEST_END = "---KRAKEN-MANIFEST-END---";
|
|
316
|
-
var skillEntrySchema =
|
|
317
|
-
name:
|
|
318
|
-
path:
|
|
319
|
-
content:
|
|
237
|
+
var skillEntrySchema = z9.object({
|
|
238
|
+
name: z9.string().min(1),
|
|
239
|
+
path: z9.string().min(1),
|
|
240
|
+
content: z9.string()
|
|
320
241
|
});
|
|
321
|
-
var connectorEntrySchema =
|
|
322
|
-
name:
|
|
323
|
-
path:
|
|
242
|
+
var connectorEntrySchema = z9.object({
|
|
243
|
+
name: z9.string().min(1),
|
|
244
|
+
path: z9.string().min(1)
|
|
324
245
|
});
|
|
325
|
-
var agentEntrySchema =
|
|
326
|
-
name:
|
|
327
|
-
entryPoint:
|
|
246
|
+
var agentEntrySchema = z9.object({
|
|
247
|
+
name: z9.string().min(1),
|
|
248
|
+
entryPoint: z9.string().min(1),
|
|
328
249
|
config: platformAgentConfigSchema
|
|
329
250
|
});
|
|
330
|
-
var projectManifestSchema =
|
|
331
|
-
agents:
|
|
332
|
-
skills:
|
|
333
|
-
connectors:
|
|
251
|
+
var projectManifestSchema = z9.object({
|
|
252
|
+
agents: z9.array(agentEntrySchema),
|
|
253
|
+
skills: z9.array(skillEntrySchema),
|
|
254
|
+
connectors: z9.array(connectorEntrySchema)
|
|
334
255
|
});
|
|
335
256
|
var MAX_SKILL_SIZE = 100 * 1024;
|
|
336
257
|
var parseManifestFromOutput = (stdout) => {
|
|
@@ -353,444 +274,6 @@ var parseManifestFromOutput = (stdout) => {
|
|
|
353
274
|
return result.data;
|
|
354
275
|
};
|
|
355
276
|
|
|
356
|
-
// src/dev.ts
|
|
357
|
-
import { readFileSync } from "fs";
|
|
358
|
-
import { createInterface } from "readline";
|
|
359
|
-
import { Agent } from "kraken-ai";
|
|
360
|
-
|
|
361
|
-
// src/dev-actions.ts
|
|
362
|
-
var buildActionInstructions = (zodSchemas) => {
|
|
363
|
-
const entries = Object.entries(zodSchemas);
|
|
364
|
-
if (entries.length === 0) return "";
|
|
365
|
-
const variants = entries.map(([name, schema]) => {
|
|
366
|
-
const fields = Object.keys(schema.shape).join(", ");
|
|
367
|
-
return ` - "${name}": { ${fields} }`;
|
|
368
|
-
});
|
|
369
|
-
return [
|
|
370
|
-
'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:',
|
|
371
|
-
"",
|
|
372
|
-
...variants,
|
|
373
|
-
"",
|
|
374
|
-
'Example: { "action": "<name>", ...fields }'
|
|
375
|
-
].join("\n");
|
|
376
|
-
};
|
|
377
|
-
var dispatchDevAction = async (output, zodSchemas, handlers, webhooks) => {
|
|
378
|
-
if (output == null || typeof output !== "object" || !("action" in output)) {
|
|
379
|
-
throw new Error('Action output must contain an "action" field');
|
|
380
|
-
}
|
|
381
|
-
const { action: actionName, ...rest } = output;
|
|
382
|
-
if (typeof actionName !== "string") {
|
|
383
|
-
throw new Error('Action output "action" field must be a string');
|
|
384
|
-
}
|
|
385
|
-
const schema = zodSchemas[actionName];
|
|
386
|
-
if (!schema) {
|
|
387
|
-
throw new Error(
|
|
388
|
-
`Unknown action "${actionName}". Expected one of: ${Object.keys(zodSchemas).join(", ")}`
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
const parsed = schema.parse(rest);
|
|
392
|
-
const payload = parsed;
|
|
393
|
-
let handlerCalled = false;
|
|
394
|
-
const handler = handlers?.[actionName];
|
|
395
|
-
if (handler) {
|
|
396
|
-
await handler(payload);
|
|
397
|
-
handlerCalled = true;
|
|
398
|
-
}
|
|
399
|
-
return {
|
|
400
|
-
actionName,
|
|
401
|
-
payload,
|
|
402
|
-
handlerCalled,
|
|
403
|
-
webhookUrl: webhooks[actionName]
|
|
404
|
-
};
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
// src/dev-connectors.ts
|
|
408
|
-
import { resolve } from "path";
|
|
409
|
-
import { tool } from "kraken-ai";
|
|
410
|
-
var isPlatformConnector2 = (v) => v != null && typeof v === "object" && v.__type === "PlatformConnector";
|
|
411
|
-
var importConnector = async (name, projectRoot) => {
|
|
412
|
-
const basePath = resolve(projectRoot, "connectors", name, "index");
|
|
413
|
-
for (const ext of [".ts", ".js"]) {
|
|
414
|
-
try {
|
|
415
|
-
const mod = await import(`${basePath}${ext}`);
|
|
416
|
-
const connector = mod.default;
|
|
417
|
-
if (!isPlatformConnector2(connector)) {
|
|
418
|
-
console.warn(`[connector:${name}] Default export is not a PlatformConnector \u2014 skipping`);
|
|
419
|
-
return null;
|
|
420
|
-
}
|
|
421
|
-
return connector;
|
|
422
|
-
} catch (err) {
|
|
423
|
-
if (ext === ".ts") continue;
|
|
424
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
425
|
-
console.warn(`[connector:${name}] Failed to import \u2014 skipping. Error: ${message}`);
|
|
426
|
-
return null;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
return null;
|
|
430
|
-
};
|
|
431
|
-
var createToolsFromConnector = (connector) => {
|
|
432
|
-
const tools = connector.tools ?? {};
|
|
433
|
-
return Object.entries(tools).map(
|
|
434
|
-
([name, def]) => tool({
|
|
435
|
-
name,
|
|
436
|
-
description: def.description,
|
|
437
|
-
parameters: def.input,
|
|
438
|
-
execute: async (args) => {
|
|
439
|
-
try {
|
|
440
|
-
const result = await Promise.resolve(def.handler(args));
|
|
441
|
-
return wrapToolResult(result);
|
|
442
|
-
} catch (error) {
|
|
443
|
-
return wrapToolError(error);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
})
|
|
447
|
-
);
|
|
448
|
-
};
|
|
449
|
-
var buildConnectorTools = (connectors) => {
|
|
450
|
-
const toolOwners = /* @__PURE__ */ new Map();
|
|
451
|
-
for (const { name, connector } of connectors) {
|
|
452
|
-
for (const toolName of Object.keys(connector.tools ?? {})) {
|
|
453
|
-
const existing = toolOwners.get(toolName);
|
|
454
|
-
if (existing) {
|
|
455
|
-
throw new Error(
|
|
456
|
-
`Tool name collision: "${toolName}" is defined by both connectors "${existing}" and "${name}". Rename one of the tools or use a unique prefix.`
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
|
-
toolOwners.set(toolName, name);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
const resourceOwners = /* @__PURE__ */ new Map();
|
|
463
|
-
for (const { name, connector } of connectors) {
|
|
464
|
-
for (const resourceName of Object.keys(connector.resources ?? {})) {
|
|
465
|
-
const existing = resourceOwners.get(resourceName);
|
|
466
|
-
if (existing) {
|
|
467
|
-
throw new Error(
|
|
468
|
-
`Resource name collision: "${resourceName}" is defined by both connectors "${existing}" and "${name}". Rename one of the resources or use a unique prefix.`
|
|
469
|
-
);
|
|
470
|
-
}
|
|
471
|
-
resourceOwners.set(resourceName, name);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
const promptOwners = /* @__PURE__ */ new Map();
|
|
475
|
-
for (const { name, connector } of connectors) {
|
|
476
|
-
for (const promptName of Object.keys(connector.prompts ?? {})) {
|
|
477
|
-
const existing = promptOwners.get(promptName);
|
|
478
|
-
if (existing) {
|
|
479
|
-
throw new Error(
|
|
480
|
-
`Prompt name collision: "${promptName}" is defined by both connectors "${existing}" and "${name}". Rename one of the prompts or use a unique prefix.`
|
|
481
|
-
);
|
|
482
|
-
}
|
|
483
|
-
promptOwners.set(promptName, name);
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
const allTools = [];
|
|
487
|
-
const allResources = [];
|
|
488
|
-
const allPrompts = [];
|
|
489
|
-
const allInstructions = [];
|
|
490
|
-
for (const { name, connector } of connectors) {
|
|
491
|
-
const tools = createToolsFromConnector(connector);
|
|
492
|
-
allTools.push(...tools);
|
|
493
|
-
for (const [resName, resDef] of Object.entries(connector.resources ?? {})) {
|
|
494
|
-
allResources.push({
|
|
495
|
-
name: resName,
|
|
496
|
-
uri: resDef.uri,
|
|
497
|
-
description: resDef.description,
|
|
498
|
-
mimeType: resDef.mimeType,
|
|
499
|
-
read: (ctx) => resDef.read(ctx)
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
for (const [promptName, promptDef] of Object.entries(connector.prompts ?? {})) {
|
|
503
|
-
allPrompts.push({
|
|
504
|
-
name: promptName,
|
|
505
|
-
description: promptDef.description,
|
|
506
|
-
arguments: promptDef.arguments,
|
|
507
|
-
get: (args, ctx) => promptDef.get(args, ctx)
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
const toolCount = Object.keys(connector.tools ?? {}).length;
|
|
511
|
-
const resourceCount = Object.keys(connector.resources ?? {}).length;
|
|
512
|
-
const promptCount = Object.keys(connector.prompts ?? {}).length;
|
|
513
|
-
const parts = [
|
|
514
|
-
`${toolCount} tool${toolCount !== 1 ? "s" : ""}`,
|
|
515
|
-
`${resourceCount} resource${resourceCount !== 1 ? "s" : ""}`,
|
|
516
|
-
`${promptCount} prompt${promptCount !== 1 ? "s" : ""}`
|
|
517
|
-
];
|
|
518
|
-
console.log(` Connector: ${name} (${parts.join(", ")})`);
|
|
519
|
-
if (connector.instructions) {
|
|
520
|
-
allInstructions.push(connector.instructions);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
return {
|
|
524
|
-
tools: allTools,
|
|
525
|
-
resources: allResources,
|
|
526
|
-
prompts: allPrompts,
|
|
527
|
-
instructions: allInstructions
|
|
528
|
-
};
|
|
529
|
-
};
|
|
530
|
-
var loadConnectorTools = async (connectorNames, projectRoot) => {
|
|
531
|
-
if (connectorNames.length === 0) {
|
|
532
|
-
return { tools: [], resources: [], prompts: [], instructions: [] };
|
|
533
|
-
}
|
|
534
|
-
const root = projectRoot ?? process.cwd();
|
|
535
|
-
const connectors = [];
|
|
536
|
-
for (const name of connectorNames) {
|
|
537
|
-
if (!isValidEntityName(name)) {
|
|
538
|
-
console.warn(
|
|
539
|
-
`[connector] Invalid connector name "${name}" \u2014 must match ${ENTITY_NAME_REGEX}. Skipping.`
|
|
540
|
-
);
|
|
541
|
-
continue;
|
|
542
|
-
}
|
|
543
|
-
const connector = await importConnector(name, root);
|
|
544
|
-
if (connector) {
|
|
545
|
-
connectors.push({ name, connector });
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
return buildConnectorTools(connectors);
|
|
549
|
-
};
|
|
550
|
-
|
|
551
|
-
// src/dev.ts
|
|
552
|
-
var loadDotenv = () => {
|
|
553
|
-
try {
|
|
554
|
-
const content = readFileSync(".env", "utf-8");
|
|
555
|
-
for (const line of content.split("\n")) {
|
|
556
|
-
const trimmed = line.trim();
|
|
557
|
-
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
558
|
-
const eqIdx = trimmed.indexOf("=");
|
|
559
|
-
if (eqIdx === -1) continue;
|
|
560
|
-
const key = trimmed.slice(0, eqIdx).trim();
|
|
561
|
-
const value = trimmed.slice(eqIdx + 1).trim();
|
|
562
|
-
if (!process.env[key]) {
|
|
563
|
-
process.env[key] = value;
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
} catch {
|
|
567
|
-
}
|
|
568
|
-
};
|
|
569
|
-
var FRONTMATTER_RE = /^---\n[\s\S]*?\n---\n([\s\S]*)$/;
|
|
570
|
-
var resolveSkillContent = (refs) => refs.map((ref) => {
|
|
571
|
-
try {
|
|
572
|
-
return readFileSync(`skills/${ref}`, "utf-8");
|
|
573
|
-
} catch {
|
|
574
|
-
return ref;
|
|
575
|
-
}
|
|
576
|
-
});
|
|
577
|
-
var buildInstructions = (base, skillContent) => {
|
|
578
|
-
if (skillContent.length === 0) return base;
|
|
579
|
-
const bodies = skillContent.map((s) => {
|
|
580
|
-
const m = FRONTMATTER_RE.exec(s);
|
|
581
|
-
return m?.[1]?.trim() ?? s;
|
|
582
|
-
});
|
|
583
|
-
return `${base}
|
|
584
|
-
|
|
585
|
-
${bodies.join("\n\n")}`;
|
|
586
|
-
};
|
|
587
|
-
var buildDevAgent = async (pa) => {
|
|
588
|
-
const {
|
|
589
|
-
name,
|
|
590
|
-
model,
|
|
591
|
-
instructions,
|
|
592
|
-
skills,
|
|
593
|
-
temperature,
|
|
594
|
-
thinkingLevel,
|
|
595
|
-
maxOutputTokens,
|
|
596
|
-
logLevel
|
|
597
|
-
} = pa.config.agent;
|
|
598
|
-
const connectorNames = pa.config.connectors ?? [];
|
|
599
|
-
const { tools: connectorTools, instructions: connectorInstructions } = await loadConnectorTools(connectorNames);
|
|
600
|
-
const skillContent = resolveSkillContent(skills ?? []);
|
|
601
|
-
let fullInstructions = buildInstructions(instructions, skillContent);
|
|
602
|
-
if (connectorInstructions.length > 0) {
|
|
603
|
-
fullInstructions = `${fullInstructions}
|
|
604
|
-
|
|
605
|
-
${connectorInstructions.join("\n\n")}`;
|
|
606
|
-
}
|
|
607
|
-
let outputSchema;
|
|
608
|
-
if (pa.actionZodSchemas && Object.keys(pa.actionZodSchemas).length > 0) {
|
|
609
|
-
const actionInstructions = buildActionInstructions(pa.actionZodSchemas);
|
|
610
|
-
if (actionInstructions) {
|
|
611
|
-
fullInstructions = `${fullInstructions}
|
|
612
|
-
|
|
613
|
-
${actionInstructions}`;
|
|
614
|
-
}
|
|
615
|
-
outputSchema = buildActionOutputSchema({
|
|
616
|
-
__type: "PlatformActions",
|
|
617
|
-
config: pa.config.actions ?? { variants: {} },
|
|
618
|
-
zodSchemas: pa.actionZodSchemas,
|
|
619
|
-
handlers: pa.actionHandlers ?? {}
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
let team;
|
|
623
|
-
if (pa.teamAgents && pa.teamAgents.length > 0) {
|
|
624
|
-
team = await Promise.all(pa.teamAgents.map(buildDevAgent));
|
|
625
|
-
}
|
|
626
|
-
return new Agent({
|
|
627
|
-
name,
|
|
628
|
-
model,
|
|
629
|
-
instructions: fullInstructions,
|
|
630
|
-
tools: connectorTools.length > 0 ? connectorTools : void 0,
|
|
631
|
-
outputSchema,
|
|
632
|
-
team,
|
|
633
|
-
temperature,
|
|
634
|
-
thinkingLevel,
|
|
635
|
-
maxOutputTokens,
|
|
636
|
-
logLevel
|
|
637
|
-
});
|
|
638
|
-
};
|
|
639
|
-
var runDev = async (agent) => {
|
|
640
|
-
loadDotenv();
|
|
641
|
-
const hasActions = agent.actionZodSchemas && Object.keys(agent.actionZodSchemas).length > 0;
|
|
642
|
-
const sdkAgent = await buildDevAgent(agent);
|
|
643
|
-
const { name, model } = agent.config.agent;
|
|
644
|
-
const connectorNames = agent.config.connectors ?? [];
|
|
645
|
-
try {
|
|
646
|
-
await sdkAgent.preflight();
|
|
647
|
-
} catch (err) {
|
|
648
|
-
console.error(`
|
|
649
|
-
${err instanceof Error ? err.message : String(err)}
|
|
650
|
-
`);
|
|
651
|
-
process.exit(1);
|
|
652
|
-
}
|
|
653
|
-
console.log(`
|
|
654
|
-
Agent: ${name}`);
|
|
655
|
-
console.log(` Model: ${model}`);
|
|
656
|
-
if (connectorNames.length > 0) {
|
|
657
|
-
console.log(` Connectors: ${connectorNames.join(", ")}`);
|
|
658
|
-
}
|
|
659
|
-
if (agent.teamAgents && agent.teamAgents.length > 0) {
|
|
660
|
-
console.log(` Team: ${agent.teamAgents.map((a) => a.config.agent.name).join(", ")}`);
|
|
661
|
-
}
|
|
662
|
-
if (hasActions && agent.actionZodSchemas) {
|
|
663
|
-
console.log(` Actions: ${Object.keys(agent.actionZodSchemas).join(", ")}`);
|
|
664
|
-
}
|
|
665
|
-
console.log(`
|
|
666
|
-
Type a message to start. Ctrl+C to exit.
|
|
667
|
-
`);
|
|
668
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
669
|
-
const messages = [];
|
|
670
|
-
const cleanup = () => {
|
|
671
|
-
rl.close();
|
|
672
|
-
process.exit(0);
|
|
673
|
-
};
|
|
674
|
-
process.on("SIGINT", cleanup);
|
|
675
|
-
process.on("SIGTERM", cleanup);
|
|
676
|
-
const ask = () => {
|
|
677
|
-
rl.question("You: ", (input) => {
|
|
678
|
-
if (!input.trim()) {
|
|
679
|
-
ask();
|
|
680
|
-
return;
|
|
681
|
-
}
|
|
682
|
-
messages.push({ role: "user", content: input });
|
|
683
|
-
void (async () => {
|
|
684
|
-
try {
|
|
685
|
-
const result = await sdkAgent.run(messages, {
|
|
686
|
-
onEvent: (event) => {
|
|
687
|
-
if (event.type === "thought") {
|
|
688
|
-
console.log(
|
|
689
|
-
` [thinking] ${event.text.slice(0, 120)}${event.text.length > 120 ? "\u2026" : ""}`
|
|
690
|
-
);
|
|
691
|
-
}
|
|
692
|
-
if (event.type === "tool_call" && event.status === "success") {
|
|
693
|
-
console.log(` [tool] ${event.toolName}`);
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
});
|
|
697
|
-
if (result.status === "complete") {
|
|
698
|
-
const output = typeof result.output === "string" ? result.output : JSON.stringify(result.output, null, 2);
|
|
699
|
-
if (hasActions && agent.actionZodSchemas && result.output != null && typeof result.output === "object" && "action" in result.output) {
|
|
700
|
-
const webhooks = {};
|
|
701
|
-
if (agent.config.actions?.variants) {
|
|
702
|
-
for (const [k, v] of Object.entries(agent.config.actions.variants)) {
|
|
703
|
-
webhooks[k] = v.webhook;
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
try {
|
|
707
|
-
const dispatched = await dispatchDevAction(
|
|
708
|
-
result.output,
|
|
709
|
-
agent.actionZodSchemas,
|
|
710
|
-
agent.actionHandlers,
|
|
711
|
-
webhooks
|
|
712
|
-
);
|
|
713
|
-
console.log(`
|
|
714
|
-
${cyan("Action:")} ${green(dispatched.actionName)}`);
|
|
715
|
-
console.log(` ${dim("Payload:")} ${JSON.stringify(dispatched.payload, null, 2)}`);
|
|
716
|
-
if (dispatched.handlerCalled) {
|
|
717
|
-
console.log(` ${dim("Handler:")} ${green("called")}`);
|
|
718
|
-
}
|
|
719
|
-
if (dispatched.webhookUrl) {
|
|
720
|
-
console.log(
|
|
721
|
-
` ${dim("Webhook:")} ${yellow(dispatched.webhookUrl)} ${dim("(skipped in dev)")}`
|
|
722
|
-
);
|
|
723
|
-
}
|
|
724
|
-
console.log();
|
|
725
|
-
} catch (err) {
|
|
726
|
-
console.error(
|
|
727
|
-
`
|
|
728
|
-
Action dispatch error: ${err instanceof Error ? err.message : String(err)}
|
|
729
|
-
`
|
|
730
|
-
);
|
|
731
|
-
}
|
|
732
|
-
} else {
|
|
733
|
-
console.log(`
|
|
734
|
-
Agent: ${output}
|
|
735
|
-
`);
|
|
736
|
-
}
|
|
737
|
-
messages.push({ role: "assistant", content: output });
|
|
738
|
-
} else if (result.status === "interrupted") {
|
|
739
|
-
console.log(`
|
|
740
|
-
[Interrupted: ${result.interrupt.toolName} requires approval]
|
|
741
|
-
`);
|
|
742
|
-
}
|
|
743
|
-
} catch (err) {
|
|
744
|
-
console.error(`
|
|
745
|
-
Error: ${err instanceof Error ? err.message : String(err)}
|
|
746
|
-
`);
|
|
747
|
-
}
|
|
748
|
-
ask();
|
|
749
|
-
})();
|
|
750
|
-
});
|
|
751
|
-
};
|
|
752
|
-
ask();
|
|
753
|
-
return new Promise(() => {
|
|
754
|
-
});
|
|
755
|
-
};
|
|
756
|
-
|
|
757
|
-
// src/mock-tool-set.ts
|
|
758
|
-
var MockToolSet = class _MockToolSet {
|
|
759
|
-
defs;
|
|
760
|
-
overrides;
|
|
761
|
-
toolNames;
|
|
762
|
-
constructor(tools, overrides = {}) {
|
|
763
|
-
this.defs = tools;
|
|
764
|
-
this.overrides = overrides;
|
|
765
|
-
this.toolNames = new Set(tools.map((t) => t.name));
|
|
766
|
-
}
|
|
767
|
-
static fromConnectors(connectors, opts) {
|
|
768
|
-
const include = opts?.include;
|
|
769
|
-
const filtered = include ? connectors.filter((c) => include.includes(c.id)) : connectors;
|
|
770
|
-
const tools = filtered.flatMap(
|
|
771
|
-
(c) => c.tools.map((t) => ({
|
|
772
|
-
name: t.name,
|
|
773
|
-
description: t.description,
|
|
774
|
-
parameters: t.parameters
|
|
775
|
-
}))
|
|
776
|
-
);
|
|
777
|
-
return new _MockToolSet(tools, opts?.overrides);
|
|
778
|
-
}
|
|
779
|
-
definitions() {
|
|
780
|
-
return this.defs;
|
|
781
|
-
}
|
|
782
|
-
async call(name, params) {
|
|
783
|
-
if (!this.toolNames.has(name)) {
|
|
784
|
-
throw new Error(`Unknown tool: ${name}`);
|
|
785
|
-
}
|
|
786
|
-
const override = this.overrides[name];
|
|
787
|
-
if (override) {
|
|
788
|
-
return override(params);
|
|
789
|
-
}
|
|
790
|
-
return {};
|
|
791
|
-
}
|
|
792
|
-
};
|
|
793
|
-
|
|
794
277
|
// src/platform/http.ts
|
|
795
278
|
var PlatformError = class extends Error {
|
|
796
279
|
constructor(message, status) {
|
|
@@ -921,13 +404,13 @@ var parseBlock = (block) => {
|
|
|
921
404
|
|
|
922
405
|
// src/platform/agent-handle.ts
|
|
923
406
|
var deferred = () => {
|
|
924
|
-
let
|
|
407
|
+
let resolve;
|
|
925
408
|
let reject;
|
|
926
409
|
const promise = new Promise((res, rej) => {
|
|
927
|
-
|
|
410
|
+
resolve = res;
|
|
928
411
|
reject = rej;
|
|
929
412
|
});
|
|
930
|
-
return { promise, resolve
|
|
413
|
+
return { promise, resolve, reject };
|
|
931
414
|
};
|
|
932
415
|
var AgentHandle = class {
|
|
933
416
|
constructor(http, agentId, opts) {
|
|
@@ -1093,7 +576,7 @@ var DataNamespace = class {
|
|
|
1093
576
|
};
|
|
1094
577
|
|
|
1095
578
|
// src/platform/pipelines.ts
|
|
1096
|
-
import * as
|
|
579
|
+
import * as z10 from "zod";
|
|
1097
580
|
var PipelinesNamespace = class {
|
|
1098
581
|
constructor(http) {
|
|
1099
582
|
this.http = http;
|
|
@@ -1104,7 +587,7 @@ var PipelinesNamespace = class {
|
|
|
1104
587
|
params
|
|
1105
588
|
);
|
|
1106
589
|
try {
|
|
1107
|
-
return
|
|
590
|
+
return z10.array(schema.returns).parse(result.rows);
|
|
1108
591
|
} catch (e) {
|
|
1109
592
|
throw new Error(
|
|
1110
593
|
`Pipeline schema may have changed \u2014 run 'kraken generate' to update types.
|
|
@@ -1205,7 +688,6 @@ export {
|
|
|
1205
688
|
ConnectorError,
|
|
1206
689
|
MANIFEST_END,
|
|
1207
690
|
MANIFEST_START,
|
|
1208
|
-
MockToolSet,
|
|
1209
691
|
PlatformClient,
|
|
1210
692
|
PlatformError,
|
|
1211
693
|
SecurityError,
|
|
@@ -1231,7 +713,6 @@ export {
|
|
|
1231
713
|
projectManifestSchema,
|
|
1232
714
|
resourceLimitsSchema,
|
|
1233
715
|
retryPolicySchema,
|
|
1234
|
-
runDev,
|
|
1235
716
|
teamConfigSchema,
|
|
1236
717
|
triggerConfigSchema,
|
|
1237
718
|
wrapToolError,
|