@kraken-ai/platform 0.0.4 → 0.0.7

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/index.cjs CHANGED
@@ -39,41 +39,24 @@ __export(index_exports, {
39
39
  PlatformClient: () => PlatformClient,
40
40
  PlatformError: () => PlatformError,
41
41
  SecurityError: () => SecurityError,
42
- actionVariantConfigSchema: () => actionVariantConfigSchema,
43
- actionsConfigSchema: () => actionsConfigSchema,
44
- agentDefinitionSchema: () => agentDefinitionSchema,
45
42
  buildActionOutputSchema: () => buildActionOutputSchema,
46
- concurrencyPolicySchema: () => concurrencyPolicySchema,
47
43
  defineAction: () => defineAction,
48
- defineActions: () => defineActions,
49
44
  defineConnector: () => defineConnector,
50
45
  definePlatformAgent: () => definePlatformAgent,
51
46
  defineSkill: () => defineSkill,
52
47
  defineTool: () => defineTool,
53
- environmentSchema: () => environmentSchema,
54
- identityConfigSchema: () => identityConfigSchema,
48
+ isQualified: () => isQualified,
55
49
  isValidActionName: () => isValidActionName,
56
- jitPolicySchema: () => jitPolicySchema,
57
50
  mcpResult: () => mcpResult,
58
- notificationConfigSchema: () => notificationConfigSchema,
51
+ parse: () => parse,
59
52
  parseManifestFromOutput: () => parseManifestFromOutput,
60
- platformAgentConfigSchema: () => platformAgentConfigSchema,
61
- projectManifestSchema: () => projectManifestSchema,
62
- resourceLimitsSchema: () => resourceLimitsSchema,
63
- retryPolicySchema: () => retryPolicySchema,
64
- teamConfigSchema: () => teamConfigSchema,
65
- triggerConfigSchema: () => triggerConfigSchema,
53
+ qualify: () => qualify,
66
54
  wrapToolError: () => wrapToolError,
67
55
  wrapToolResult: () => wrapToolResult
68
56
  });
69
57
  module.exports = __toCommonJS(index_exports);
70
58
 
71
- // src/agents/connector-server.ts
72
- var import_node_crypto = require("crypto");
73
- var import_node_http = require("http");
74
- var z = __toESM(require("zod"), 1);
75
-
76
- // src/agents/errors.ts
59
+ // ../../../private-packages/platform-core/dist/errors.js
77
60
  var SecurityError = class extends Error {
78
61
  code = "SECURITY_VIOLATION";
79
62
  constructor(message) {
@@ -89,6 +72,222 @@ var ConnectorError = class extends Error {
89
72
  }
90
73
  };
91
74
 
75
+ // ../../../private-packages/platform-core/dist/qualified-name.js
76
+ var qualify = (repoName, primitiveName) => {
77
+ if (!repoName)
78
+ throw new Error("repoName must not be empty");
79
+ if (!primitiveName)
80
+ throw new Error("primitiveName must not be empty");
81
+ return `${repoName}/${primitiveName}`;
82
+ };
83
+ var parse = (qualified) => {
84
+ const slashIndex = qualified.indexOf("/");
85
+ if (slashIndex === -1) {
86
+ throw new Error(`Expected qualified name with "/" separator, got: "${qualified}"`);
87
+ }
88
+ if (qualified.indexOf("/", slashIndex + 1) !== -1) {
89
+ throw new Error(`Expected exactly one "/" in qualified name, got: "${qualified}"`);
90
+ }
91
+ const repoName = qualified.slice(0, slashIndex);
92
+ const primitiveName = qualified.slice(slashIndex + 1);
93
+ if (!repoName || !primitiveName) {
94
+ throw new Error(`Both repo and primitive segments must be non-empty, got: "${qualified}"`);
95
+ }
96
+ return { repoName, primitiveName };
97
+ };
98
+ var isQualified = (name) => {
99
+ const slashIndex = name.indexOf("/");
100
+ if (slashIndex === -1 || slashIndex === 0 || slashIndex === name.length - 1)
101
+ return false;
102
+ return name.indexOf("/", slashIndex + 1) === -1;
103
+ };
104
+
105
+ // ../../../private-packages/platform-core/dist/types/action.js
106
+ var ACTION_NAME_REGEX = /^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$/;
107
+ var isValidActionName = (name) => name.length === 1 ? /^[a-z0-9]$/.test(name) : ACTION_NAME_REGEX.test(name);
108
+
109
+ // ../../../private-packages/platform-core/dist/types/environment.js
110
+ var z = __toESM(require("zod"), 1);
111
+ var environmentSchema = z.enum(["dev", "staging", "prod"]);
112
+
113
+ // ../../../private-packages/platform-core/dist/types/identity.js
114
+ var z2 = __toESM(require("zod"), 1);
115
+ var jitPolicySchema = z2.enum(["auto-approve", "policy-based", "require-approval"]);
116
+ var identityConfigSchema = z2.object({
117
+ basePermissions: z2.array(z2.string()),
118
+ requestablePermissions: z2.array(z2.string()).optional(),
119
+ jitPolicy: jitPolicySchema.optional(),
120
+ maxJitDurationMinutes: z2.number().int().positive().optional()
121
+ });
122
+
123
+ // ../../../private-packages/platform-core/dist/types/notifications.js
124
+ var z3 = __toESM(require("zod"), 1);
125
+ var notificationConfigSchema = z3.object({
126
+ slack: z3.string().optional(),
127
+ onSuccess: z3.boolean().optional(),
128
+ onFailure: z3.boolean().optional(),
129
+ onTimeout: z3.boolean().optional()
130
+ });
131
+
132
+ // ../../../private-packages/platform-core/dist/types/platform-agent.js
133
+ var z7 = __toESM(require("zod"), 1);
134
+
135
+ // ../../../private-packages/platform-core/dist/validate.js
136
+ var PRIMITIVE_NAME_REGEX = /^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$/;
137
+ var isValidPrimitiveName = (name) => name.length === 1 ? /^[a-z0-9]$/.test(name) : PRIMITIVE_NAME_REGEX.test(name);
138
+ var SKILL_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9-]{0,62}[a-zA-Z0-9]$/;
139
+ var isValidSkillName = (basename) => basename.length === 1 ? /^[a-zA-Z0-9]$/.test(basename) : SKILL_NAME_REGEX.test(basename);
140
+ var isValidSkillId = (id) => {
141
+ const base = id.endsWith(".md") ? id.slice(0, -3) : id;
142
+ return isValidSkillName(base);
143
+ };
144
+ var isValidQualifiedName = (name) => {
145
+ if (!isQualified(name))
146
+ return false;
147
+ const { repoName, primitiveName } = parse(name);
148
+ return isValidPrimitiveName(repoName) && isValidPrimitiveName(primitiveName);
149
+ };
150
+ var isValidQualifiedSkillId = (id) => {
151
+ if (!isQualified(id))
152
+ return false;
153
+ const { repoName, primitiveName } = parse(id);
154
+ return isValidPrimitiveName(repoName) && isValidSkillId(primitiveName);
155
+ };
156
+
157
+ // ../../../private-packages/platform-core/dist/types/resources.js
158
+ var z4 = __toESM(require("zod"), 1);
159
+ var resourceLimitsSchema = z4.object({
160
+ maxTokens: z4.number().int().positive().optional(),
161
+ maxCostUsd: z4.number().positive().optional(),
162
+ timeoutSeconds: z4.number().int().positive().optional()
163
+ });
164
+ var retryPolicySchema = z4.object({
165
+ maxAttempts: z4.number().int().min(1).optional(),
166
+ backoffSeconds: z4.number().positive().optional()
167
+ });
168
+ var concurrencyPolicySchema = z4.object({
169
+ maxParallelRuns: z4.number().int().min(1).optional()
170
+ });
171
+
172
+ // ../../../private-packages/platform-core/dist/types/team.js
173
+ var z5 = __toESM(require("zod"), 1);
174
+ var teamConfigSchema = z5.object({
175
+ members: z5.array(z5.string()).min(1),
176
+ maxConcurrentWorkers: z5.number().int().min(1).optional(),
177
+ maxTokenBudgetPerWorker: z5.number().int().positive().optional(),
178
+ maxDurationPerWorker: z5.number().positive().optional()
179
+ });
180
+
181
+ // ../../../private-packages/platform-core/dist/types/trigger.js
182
+ var z6 = __toESM(require("zod"), 1);
183
+ var cronTriggerSchema = z6.object({
184
+ type: z6.literal("cron"),
185
+ expression: z6.string(),
186
+ timezone: z6.string().optional()
187
+ });
188
+ var webhookTriggerSchema = z6.object({
189
+ type: z6.literal("webhook"),
190
+ path: z6.string().startsWith("/"),
191
+ method: z6.enum(["POST", "GET"]).optional()
192
+ });
193
+ var eventTriggerSchema = z6.object({
194
+ type: z6.literal("event"),
195
+ source: z6.string(),
196
+ event: z6.string()
197
+ });
198
+ var apiTriggerSchema = z6.object({ type: z6.literal("api") });
199
+ var manualTriggerSchema = z6.object({ type: z6.literal("manual") });
200
+ var triggerConfigSchema = z6.discriminatedUnion("type", [
201
+ cronTriggerSchema,
202
+ webhookTriggerSchema,
203
+ eventTriggerSchema,
204
+ apiTriggerSchema,
205
+ manualTriggerSchema
206
+ ]);
207
+
208
+ // ../../../private-packages/platform-core/dist/types/platform-agent.js
209
+ var thinkingLevelSchema = z7.enum(["low", "medium", "high"]);
210
+ var logLevelSchema = z7.enum(["silent", "debug", "info", "warn", "error"]);
211
+ var agentDefinitionSchema = z7.object({
212
+ name: z7.string().min(1),
213
+ model: z7.string().min(1),
214
+ instructions: z7.string().min(1),
215
+ description: z7.string().optional(),
216
+ skills: z7.array(z7.string()).optional(),
217
+ temperature: z7.number().min(0).max(2).optional(),
218
+ allowTemperatureOverride: z7.boolean().optional(),
219
+ maxOutputTokens: z7.number().int().positive().optional(),
220
+ thinkingLevel: thinkingLevelSchema.optional(),
221
+ logLevel: logLevelSchema.optional()
222
+ }).strict();
223
+ var platformAgentConfigSchema = z7.object({
224
+ agent: agentDefinitionSchema,
225
+ connectors: z7.array(z7.string()).optional(),
226
+ triggers: z7.array(triggerConfigSchema),
227
+ identity: identityConfigSchema.optional(),
228
+ resources: resourceLimitsSchema.optional(),
229
+ retries: retryPolicySchema.optional(),
230
+ concurrency: concurrencyPolicySchema.optional(),
231
+ fast: z7.boolean().optional(),
232
+ team: teamConfigSchema.optional(),
233
+ notifications: notificationConfigSchema.optional(),
234
+ environment: environmentSchema.optional(),
235
+ actions: z7.array(z7.string()).optional()
236
+ }).strict().superRefine((data, ctx) => {
237
+ for (const member of data.team?.members ?? []) {
238
+ const valid = isQualified(member) ? isValidQualifiedName(member) : isValidPrimitiveName(member);
239
+ if (!valid) {
240
+ ctx.addIssue({
241
+ code: z7.ZodIssueCode.custom,
242
+ path: ["team", "members"],
243
+ message: `Invalid team member name: "${member}"`
244
+ });
245
+ }
246
+ }
247
+ for (const connector of data.connectors ?? []) {
248
+ const valid = isQualified(connector) ? isValidQualifiedName(connector) : isValidPrimitiveName(connector);
249
+ if (!valid) {
250
+ ctx.addIssue({
251
+ code: z7.ZodIssueCode.custom,
252
+ path: ["connectors"],
253
+ message: `Invalid connector name: "${connector}"`
254
+ });
255
+ }
256
+ }
257
+ for (const skill of data.agent.skills ?? []) {
258
+ const valid = isQualified(skill) ? isValidQualifiedSkillId(skill) : isValidSkillId(skill);
259
+ if (!valid) {
260
+ ctx.addIssue({
261
+ code: z7.ZodIssueCode.custom,
262
+ path: ["agent", "skills"],
263
+ message: `Invalid skill ID: "${skill}"`
264
+ });
265
+ }
266
+ }
267
+ for (const action of data.actions ?? []) {
268
+ const valid = isQualified(action) ? isValidQualifiedName(action) : isValidPrimitiveName(action);
269
+ if (!valid) {
270
+ ctx.addIssue({
271
+ code: z7.ZodIssueCode.custom,
272
+ path: ["actions"],
273
+ message: `Invalid action name: "${action}"`
274
+ });
275
+ }
276
+ }
277
+ });
278
+
279
+ // ../../../private-packages/platform-core/dist/types/skill.js
280
+ var z8 = __toESM(require("zod"), 1);
281
+ var platformSkillInputSchema = z8.object({
282
+ name: z8.string().min(1),
283
+ description: z8.string().optional()
284
+ }).strict();
285
+
286
+ // src/agents/connector-server.ts
287
+ var import_node_crypto = require("crypto");
288
+ var import_node_http = require("http");
289
+ var z9 = __toESM(require("zod"), 1);
290
+
92
291
  // src/agents/connector-wrap.ts
93
292
  var MAX_TOOL_RESULT_SIZE = 10 * 1024 * 1024;
94
293
  var isMcpContent = (val) => typeof val === "object" && val !== null && "__mcpPassThrough" in val && val.__mcpPassThrough === true;
@@ -144,132 +343,6 @@ var mcpResult = (content, isError) => ({
144
343
  // src/agents/connector-server.ts
145
344
  var MAX_BODY_SIZE = 10 * 1024 * 1024;
146
345
 
147
- // src/agents/types/action.ts
148
- var z2 = __toESM(require("zod"), 1);
149
- var ACTION_NAME_REGEX = /^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$/;
150
- var isValidActionName = (name) => name.length === 1 ? /^[a-z0-9]$/.test(name) : ACTION_NAME_REGEX.test(name);
151
- var actionVariantConfigSchema = z2.object({
152
- schema: z2.record(z2.string(), z2.unknown()),
153
- webhook: z2.string().url().optional(),
154
- hasHandler: z2.boolean()
155
- });
156
- var actionsConfigSchema = z2.object({
157
- variants: z2.record(z2.string(), actionVariantConfigSchema)
158
- }).strict();
159
-
160
- // src/agents/types/environment.ts
161
- var z3 = __toESM(require("zod"), 1);
162
- var environmentSchema = z3.enum(["dev", "staging", "prod"]);
163
-
164
- // src/agents/types/identity.ts
165
- var z4 = __toESM(require("zod"), 1);
166
- var jitPolicySchema = z4.enum(["auto-approve", "policy-based", "require-approval"]);
167
- var identityConfigSchema = z4.object({
168
- basePermissions: z4.array(z4.string()),
169
- requestablePermissions: z4.array(z4.string()).optional(),
170
- jitPolicy: jitPolicySchema.optional(),
171
- maxJitDurationMinutes: z4.number().int().positive().optional()
172
- });
173
-
174
- // src/agents/types/notifications.ts
175
- var z5 = __toESM(require("zod"), 1);
176
- var notificationConfigSchema = z5.object({
177
- slack: z5.string().optional(),
178
- onSuccess: z5.boolean().optional(),
179
- onFailure: z5.boolean().optional(),
180
- onTimeout: z5.boolean().optional()
181
- });
182
-
183
- // src/agents/types/platform-agent.ts
184
- var z9 = __toESM(require("zod"), 1);
185
-
186
- // src/agents/types/resources.ts
187
- var z6 = __toESM(require("zod"), 1);
188
- var resourceLimitsSchema = z6.object({
189
- maxTokens: z6.number().int().positive().optional(),
190
- maxCostUsd: z6.number().positive().optional(),
191
- timeoutSeconds: z6.number().int().positive().optional()
192
- });
193
- var retryPolicySchema = z6.object({
194
- maxAttempts: z6.number().int().min(1).optional(),
195
- backoffSeconds: z6.number().positive().optional()
196
- });
197
- var concurrencyPolicySchema = z6.object({
198
- maxParallelRuns: z6.number().int().min(1).optional()
199
- });
200
-
201
- // src/agents/types/team.ts
202
- var z7 = __toESM(require("zod"), 1);
203
- var teamConfigSchema = z7.object({
204
- members: z7.array(z7.string()).min(1),
205
- maxConcurrentWorkers: z7.number().int().min(1).optional(),
206
- maxTokenBudgetPerWorker: z7.number().int().positive().optional(),
207
- maxDurationPerWorker: z7.number().positive().optional()
208
- });
209
-
210
- // src/agents/types/trigger.ts
211
- var z8 = __toESM(require("zod"), 1);
212
- var cronTriggerSchema = z8.object({
213
- type: z8.literal("cron"),
214
- expression: z8.string(),
215
- timezone: z8.string().optional()
216
- });
217
- var webhookTriggerSchema = z8.object({
218
- type: z8.literal("webhook"),
219
- path: z8.string().startsWith("/"),
220
- method: z8.enum(["POST", "GET"]).optional()
221
- });
222
- var eventTriggerSchema = z8.object({
223
- type: z8.literal("event"),
224
- source: z8.string(),
225
- event: z8.string()
226
- });
227
- var apiTriggerSchema = z8.object({ type: z8.literal("api") });
228
- var manualTriggerSchema = z8.object({ type: z8.literal("manual") });
229
- var triggerConfigSchema = z8.discriminatedUnion("type", [
230
- cronTriggerSchema,
231
- webhookTriggerSchema,
232
- eventTriggerSchema,
233
- apiTriggerSchema,
234
- manualTriggerSchema
235
- ]);
236
-
237
- // src/agents/types/platform-agent.ts
238
- var thinkingLevelSchema = z9.enum(["low", "medium", "high"]);
239
- var logLevelSchema = z9.enum(["silent", "debug", "info", "warn", "error"]);
240
- var agentDefinitionSchema = z9.object({
241
- name: z9.string().min(1),
242
- model: z9.string().min(1),
243
- instructions: z9.string().min(1),
244
- description: z9.string().optional(),
245
- skills: z9.array(z9.string()).optional(),
246
- temperature: z9.number().min(0).max(2).optional(),
247
- allowTemperatureOverride: z9.boolean().optional(),
248
- maxOutputTokens: z9.number().int().positive().optional(),
249
- thinkingLevel: thinkingLevelSchema.optional(),
250
- logLevel: logLevelSchema.optional()
251
- }).strict();
252
- var platformAgentConfigSchema = z9.object({
253
- agent: agentDefinitionSchema,
254
- connectors: z9.array(z9.string()).optional(),
255
- triggers: z9.array(triggerConfigSchema),
256
- identity: identityConfigSchema.optional(),
257
- resources: resourceLimitsSchema.optional(),
258
- retries: retryPolicySchema.optional(),
259
- concurrency: concurrencyPolicySchema.optional(),
260
- team: teamConfigSchema.optional(),
261
- notifications: notificationConfigSchema.optional(),
262
- environment: environmentSchema.optional(),
263
- actions: actionsConfigSchema.optional()
264
- }).strict();
265
-
266
- // src/agents/types/skill.ts
267
- var z10 = __toESM(require("zod"), 1);
268
- var platformSkillInputSchema = z10.object({
269
- name: z10.string().min(1),
270
- description: z10.string().optional()
271
- }).strict();
272
-
273
346
  // src/agents/define.ts
274
347
  var FORBIDDEN_AGENT_KEYS = ["tools", "team", "kernel"];
275
348
  var isAgentInstance = (value) => value != null && typeof value === "object" && "definition" in value && "name" in value && "run" in value && typeof value.run === "function";
@@ -290,7 +363,8 @@ var isPlatformAgent = (v) => v != null && typeof v === "object" && v.__type ===
290
363
  var normalizeSkillRef = (ref) => isPlatformSkill(ref) ? ref.name : ref;
291
364
  var normalizeConnectorRef = (ref) => isPlatformConnector(ref) ? ref.name : ref;
292
365
  var normalizeTeamMember = (ref) => isPlatformAgent(ref) ? ref.config.agent.name : ref;
293
- var isPlatformActions = (v) => v != null && typeof v === "object" && v.__type === "PlatformActions";
366
+ var isPlatformAction = (v) => v != null && typeof v === "object" && v.__type === "PlatformAction";
367
+ var normalizeActionRef = (ref) => isPlatformAction(ref) ? ref.name : ref;
294
368
  var definePlatformAgent = (config) => {
295
369
  assertNoInjection(config.agent);
296
370
  let agentDef;
@@ -301,7 +375,7 @@ var definePlatformAgent = (config) => {
301
375
  runtime = config.agent;
302
376
  } else {
303
377
  const {
304
- outputSchema: os,
378
+ outputSchema: os2,
305
379
  skills: rawSkills,
306
380
  ...rest
307
381
  } = config.agent;
@@ -309,26 +383,39 @@ var definePlatformAgent = (config) => {
309
383
  ...rest,
310
384
  skills: rawSkills?.map(normalizeSkillRef)
311
385
  };
312
- outputSchema = os;
386
+ outputSchema = os2;
313
387
  }
314
388
  const normalizedConnectors = config.connectors?.map(normalizeConnectorRef);
315
389
  const normalizedTeam = config.team ? { ...config.team, members: config.team.members.map(normalizeTeamMember) } : void 0;
316
390
  const teamAgents = config.team?.members.filter((m) => isPlatformAgent(m));
317
- let actionsConfig;
391
+ const actionObjects = config.actions?.filter((a) => isPlatformAction(a));
392
+ const normalizedActions = config.actions?.map(normalizeActionRef);
318
393
  let actionZodSchemas;
319
394
  let actionHandlers;
320
- if (config.actions && isPlatformActions(config.actions)) {
321
- actionsConfig = config.actions.config;
322
- actionZodSchemas = config.actions.zodSchemas;
323
- const h = config.actions.handlers;
324
- actionHandlers = Object.keys(h).length > 0 ? h : void 0;
395
+ let actionWebhooks;
396
+ if (actionObjects && actionObjects.length > 0) {
397
+ const schemas = {};
398
+ const handlers = {};
399
+ const webhooks = {};
400
+ for (const action of actionObjects) {
401
+ schemas[action.name] = action.zodSchema;
402
+ if (action.handler) {
403
+ handlers[action.name] = action.handler;
404
+ }
405
+ if (action.config.webhook) {
406
+ webhooks[action.name] = action.config.webhook;
407
+ }
408
+ }
409
+ actionZodSchemas = Object.freeze(schemas);
410
+ actionHandlers = Object.keys(handlers).length > 0 ? Object.freeze(handlers) : void 0;
411
+ actionWebhooks = Object.keys(webhooks).length > 0 ? Object.freeze(webhooks) : void 0;
325
412
  }
326
413
  const parsed = platformAgentConfigSchema.parse({
327
414
  ...config,
328
415
  agent: agentDef,
329
416
  connectors: normalizedConnectors,
330
417
  team: normalizedTeam,
331
- actions: actionsConfig
418
+ actions: normalizedActions
332
419
  });
333
420
  return {
334
421
  __type: "PlatformAgent",
@@ -337,61 +424,43 @@ var definePlatformAgent = (config) => {
337
424
  outputSchema,
338
425
  actionZodSchemas,
339
426
  actionHandlers,
427
+ actionWebhooks,
340
428
  teamAgents: teamAgents && teamAgents.length > 0 ? teamAgents : void 0
341
429
  };
342
430
  };
343
431
 
344
432
  // src/agents/define-actions.ts
345
- var z11 = __toESM(require("zod"), 1);
346
- var defineAction = (input) => input;
347
- var defineActions = (variants) => {
348
- const entries = Object.entries(variants);
349
- if (entries.length === 0) {
350
- throw new Error("defineActions() requires at least one action variant");
351
- }
352
- if (entries.length > 20) {
353
- throw new Error("defineActions() supports a maximum of 20 action variants");
354
- }
355
- const serialized = {};
356
- const zodSchemas = {};
357
- const handlers = {};
358
- for (const [name, variant] of entries) {
359
- if (!isValidActionName(name)) {
360
- throw new Error(
361
- `Invalid action name "${name}": must be lowercase alphanumeric with hyphens, 1-64 chars`
362
- );
363
- }
364
- const v = variant;
365
- serialized[name] = {
366
- schema: z11.toJSONSchema(v.schema, { target: "draft-2020-12" }),
367
- webhook: v.webhook,
368
- hasHandler: !!v.handler
369
- };
370
- zodSchemas[name] = v.schema;
371
- if (v.handler) {
372
- handlers[name] = v.handler;
373
- }
433
+ var z10 = __toESM(require("zod"), 1);
434
+ var defineAction = (input) => {
435
+ if (!input.name || !isValidActionName(input.name)) {
436
+ throw new Error(
437
+ `Invalid action name "${input.name}": must be lowercase alphanumeric with hyphens, 1-64 chars`
438
+ );
374
439
  }
375
440
  return Object.freeze({
376
- __type: "PlatformActions",
377
- config: Object.freeze({ variants: Object.freeze(serialized) }),
378
- zodSchemas: Object.freeze(zodSchemas),
379
- handlers: Object.freeze(handlers)
441
+ __type: "PlatformAction",
442
+ name: input.name,
443
+ config: Object.freeze({
444
+ schema: z10.toJSONSchema(input.schema, { target: "draft-2020-12" }),
445
+ webhook: input.webhook,
446
+ hasHandler: !!input.handler
447
+ }),
448
+ zodSchema: input.schema,
449
+ handler: input.handler
380
450
  });
381
451
  };
382
452
  var buildActionOutputSchema = (actions) => {
383
- const entries = Object.entries(actions.zodSchemas);
384
- if (entries.length === 0) {
453
+ if (actions.length === 0) {
385
454
  throw new Error("Cannot build output schema from empty action definitions");
386
455
  }
387
- const variants = entries.map(
388
- ([name, schema]) => z11.object({ action: z11.literal(name) }).extend(schema.shape)
456
+ const variants = actions.map(
457
+ (action) => z10.object({ action: z10.literal(action.name) }).extend(action.zodSchema.shape)
389
458
  );
390
459
  const [first, ...rest] = variants;
391
460
  if (!first) {
392
461
  throw new Error("Cannot build output schema from empty action definitions");
393
462
  }
394
- return z11.discriminatedUnion("action", [first, ...rest]);
463
+ return z10.discriminatedUnion("action", [first, ...rest]);
395
464
  };
396
465
 
397
466
  // src/agents/define-connector.ts
@@ -426,9 +495,10 @@ var defineSkill = (input) => {
426
495
 
427
496
  // src/cli/discover.ts
428
497
  var import_node_fs = __toESM(require("fs"), 1);
498
+ var import_node_module = require("module");
429
499
  var import_node_path = __toESM(require("path"), 1);
430
500
  var import_node_url = require("url");
431
- var z12 = __toESM(require("zod"), 1);
501
+ var z11 = __toESM(require("zod"), 1);
432
502
 
433
503
  // src/cli/log.ts
434
504
  var supportsColor = !("NO_COLOR" in process.env) && process.env.FORCE_COLOR !== "0" && (process.stderr.isTTY ?? false);
@@ -447,24 +517,65 @@ var cyan = code(36, 39);
447
517
  // src/cli/discover.ts
448
518
  var MANIFEST_START = "---KRAKEN-MANIFEST-START---";
449
519
  var MANIFEST_END = "---KRAKEN-MANIFEST-END---";
450
- var skillEntrySchema = z12.object({
451
- name: z12.string().min(1),
452
- path: z12.string().min(1),
453
- content: z12.string()
520
+ var skillEntrySchema = z11.object({
521
+ name: z11.string().min(1),
522
+ path: z11.string().min(1),
523
+ content: z11.string()
524
+ });
525
+ var toolSpecSchema = z11.object({
526
+ name: z11.string(),
527
+ description: z11.string(),
528
+ parameters: z11.record(z11.string(), z11.unknown()).default({}),
529
+ annotations: z11.object({
530
+ readOnlyHint: z11.boolean().optional(),
531
+ destructiveHint: z11.boolean().optional(),
532
+ idempotentHint: z11.boolean().optional()
533
+ }).optional()
454
534
  });
455
- var connectorEntrySchema = z12.object({
456
- name: z12.string().min(1),
457
- path: z12.string().min(1)
535
+ var resourceSpecSchema = z11.object({
536
+ name: z11.string(),
537
+ uri: z11.string(),
538
+ description: z11.string(),
539
+ mimeType: z11.string().optional()
458
540
  });
459
- var agentEntrySchema = z12.object({
460
- name: z12.string().min(1),
461
- entryPoint: z12.string().min(1),
541
+ var promptSpecSchema = z11.object({
542
+ name: z11.string(),
543
+ description: z11.string(),
544
+ arguments: z11.array(
545
+ z11.object({
546
+ name: z11.string(),
547
+ description: z11.string().optional(),
548
+ required: z11.boolean().optional()
549
+ })
550
+ ).optional()
551
+ });
552
+ var connectorEntrySchema = z11.object({
553
+ name: z11.string().min(1),
554
+ path: z11.string().min(1),
555
+ toolSpecs: z11.array(toolSpecSchema).default([]),
556
+ resourceSpecs: z11.array(resourceSpecSchema).default([]),
557
+ promptSpecs: z11.array(promptSpecSchema).default([])
558
+ });
559
+ var agentEntrySchema = z11.object({
560
+ name: z11.string().min(1),
561
+ entryPoint: z11.string().min(1),
462
562
  config: platformAgentConfigSchema
463
563
  });
464
- var projectManifestSchema = z12.object({
465
- agents: z12.array(agentEntrySchema),
466
- skills: z12.array(skillEntrySchema),
467
- connectors: z12.array(connectorEntrySchema)
564
+ var actionConfigSchema = z11.object({
565
+ schema: z11.record(z11.string(), z11.unknown()),
566
+ webhook: z11.string().url().optional(),
567
+ hasHandler: z11.boolean()
568
+ });
569
+ var actionEntrySchema = z11.object({
570
+ name: z11.string().min(1),
571
+ entryPoint: z11.string().min(1),
572
+ config: actionConfigSchema
573
+ });
574
+ var projectManifestSchema = z11.object({
575
+ agents: z11.array(agentEntrySchema),
576
+ skills: z11.array(skillEntrySchema),
577
+ connectors: z11.array(connectorEntrySchema),
578
+ actions: z11.array(actionEntrySchema).default([])
468
579
  });
469
580
  var MAX_SKILL_SIZE = 100 * 1024;
470
581
  var parseManifestFromOutput = (stdout) => {
@@ -487,6 +598,31 @@ var parseManifestFromOutput = (stdout) => {
487
598
  return result.data;
488
599
  };
489
600
 
601
+ // src/internal/secret-string.ts
602
+ var import_node_util = require("util");
603
+ var SecretString = class {
604
+ #value;
605
+ constructor(value) {
606
+ this.#value = value;
607
+ }
608
+ unmasked() {
609
+ return this.#value;
610
+ }
611
+ toJSON() {
612
+ return "[REDACTED]";
613
+ }
614
+ toString() {
615
+ return "[REDACTED]";
616
+ }
617
+ [Symbol.toPrimitive]() {
618
+ return "[REDACTED]";
619
+ }
620
+ [import_node_util.inspect.custom]() {
621
+ return "SecretString([REDACTED])";
622
+ }
623
+ };
624
+ var unwrapSecret = (value) => value instanceof SecretString ? value.unmasked() : value;
625
+
490
626
  // src/platform/http.ts
491
627
  var PlatformError = class extends Error {
492
628
  constructor(message, status) {
@@ -494,6 +630,7 @@ var PlatformError = class extends Error {
494
630
  this.status = status;
495
631
  this.name = "PlatformError";
496
632
  }
633
+ status;
497
634
  };
498
635
  var HttpClient = class {
499
636
  baseUrlForStream;
@@ -502,7 +639,7 @@ var HttpClient = class {
502
639
  constructor(config) {
503
640
  this.baseUrl = config.baseUrl.replace(/\/+$/, "");
504
641
  this.baseUrlForStream = this.baseUrl;
505
- this.apiKey = config.apiKey;
642
+ this.apiKey = new SecretString(config.apiKey);
506
643
  const isLocalhost = this.baseUrl.includes("localhost") || this.baseUrl.includes("127.0.0.1");
507
644
  if (this.baseUrl.startsWith("http://") && !isLocalhost) {
508
645
  console.warn(
@@ -510,24 +647,24 @@ var HttpClient = class {
510
647
  );
511
648
  }
512
649
  }
513
- async get(path2, params) {
514
- const url = this.buildUrl(path2, params);
650
+ async get(path3, params) {
651
+ const url = this.buildUrl(path3, params);
515
652
  const response = await fetch(url, {
516
653
  method: "GET",
517
654
  headers: this.authHeaders()
518
655
  });
519
656
  return this.handleResponse(response);
520
657
  }
521
- async post(path2, body) {
522
- const response = await fetch(this.buildUrl(path2), {
658
+ async post(path3, body) {
659
+ const response = await fetch(this.buildUrl(path3), {
523
660
  method: "POST",
524
661
  headers: { ...this.authHeaders(), "Content-Type": "application/json" },
525
662
  body: body ? JSON.stringify(body) : void 0
526
663
  });
527
664
  return this.handleResponse(response);
528
665
  }
529
- async postStream(path2, body, signal) {
530
- const response = await fetch(this.buildUrl(path2), {
666
+ async postStream(path3, body, signal) {
667
+ const response = await fetch(this.buildUrl(path3), {
531
668
  method: "POST",
532
669
  headers: {
533
670
  ...this.authHeaders(),
@@ -543,14 +680,14 @@ var HttpClient = class {
543
680
  }
544
681
  return response;
545
682
  }
546
- buildUrl(path2, params) {
547
- const url = `${this.baseUrl}${path2}`;
683
+ buildUrl(path3, params) {
684
+ const url = `${this.baseUrl}${path3}`;
548
685
  if (!params || Object.keys(params).length === 0) return url;
549
686
  const qs = new URLSearchParams(params).toString();
550
687
  return `${url}?${qs}`;
551
688
  }
552
689
  authHeaders() {
553
- return { Authorization: `Bearer ${this.apiKey}` };
690
+ return { Authorization: `Bearer ${unwrapSecret(this.apiKey)}` };
554
691
  }
555
692
  async handleResponse(response) {
556
693
  if (!response.ok) {
@@ -631,6 +768,8 @@ var AgentHandle = class {
631
768
  this.agentId = agentId;
632
769
  this.threadId = opts?.threadId;
633
770
  }
771
+ http;
772
+ agentId;
634
773
  actionHandlers = /* @__PURE__ */ new Map();
635
774
  threadId;
636
775
  onAction(name, handler) {
@@ -723,6 +862,9 @@ var AgentThread = class {
723
862
  this.agentId = agentId;
724
863
  this.threadId = threadId;
725
864
  }
865
+ http;
866
+ agentId;
867
+ threadId;
726
868
  async sendMessage(content, opts) {
727
869
  const response = await this.http.postStream(
728
870
  `/api/v1/agents/${this.agentId}/threads/${this.threadId}/messages`,
@@ -743,6 +885,7 @@ var AgentsNamespace = class {
743
885
  constructor(http) {
744
886
  this.http = http;
745
887
  }
888
+ http;
746
889
  async list() {
747
890
  const result = await this.http.get("/api/v1/agents");
748
891
  return result.data;
@@ -768,11 +911,39 @@ var buildPaginationQuery = (params) => {
768
911
  return Object.keys(qs).length > 0 ? qs : void 0;
769
912
  };
770
913
 
914
+ // src/cli/credentials.ts
915
+ var import_node_fs2 = __toESM(require("fs"), 1);
916
+ var import_node_os = __toESM(require("os"), 1);
917
+ var import_node_path2 = __toESM(require("path"), 1);
918
+ var credentialsDir = () => import_node_path2.default.join(import_node_os.default.homedir(), ".kraken-ai");
919
+ var credentialsPath = () => import_node_path2.default.join(credentialsDir(), "credentials.json");
920
+ var loadCredentials = () => {
921
+ const filePath = credentialsPath();
922
+ let creds = null;
923
+ if (import_node_fs2.default.existsSync(filePath)) {
924
+ try {
925
+ creds = JSON.parse(import_node_fs2.default.readFileSync(filePath, "utf-8"));
926
+ } catch {
927
+ return null;
928
+ }
929
+ }
930
+ const envKey = process.env.KRAKEN_API_KEY;
931
+ const envUrl = process.env.KRAKEN_BASE_URL;
932
+ if (envKey || envUrl) {
933
+ return {
934
+ apiKey: envKey ?? creds?.apiKey ?? "",
935
+ baseUrl: envUrl ?? creds?.baseUrl ?? ""
936
+ };
937
+ }
938
+ return creds;
939
+ };
940
+
771
941
  // src/platform/data.ts
772
942
  var DataNamespace = class {
773
943
  constructor(http) {
774
944
  this.http = http;
775
945
  }
946
+ http;
776
947
  async list() {
777
948
  const result = await this.http.get("/api/v1/data/queries");
778
949
  return result.data;
@@ -789,18 +960,19 @@ var DataNamespace = class {
789
960
  };
790
961
 
791
962
  // src/platform/pipelines.ts
792
- var z13 = __toESM(require("zod"), 1);
963
+ var z12 = __toESM(require("zod"), 1);
793
964
  var PipelinesNamespace = class {
794
965
  constructor(http) {
795
966
  this.http = http;
796
967
  }
968
+ http;
797
969
  async query(pipeline, queryName, schema, params) {
798
970
  const result = await this.http.post(
799
971
  `/api/v1/pipelines/${encodeURIComponent(pipeline)}/queries/${encodeURIComponent(queryName)}`,
800
972
  params
801
973
  );
802
974
  try {
803
- return z13.array(schema.returns).parse(result.rows);
975
+ return z12.array(schema.returns).parse(result.rows);
804
976
  } catch (e) {
805
977
  throw new Error(
806
978
  `Pipeline schema may have changed \u2014 run 'kraken generate' to update types.
@@ -816,6 +988,7 @@ var RunsNamespace = class {
816
988
  constructor(http) {
817
989
  this.http = http;
818
990
  }
991
+ http;
819
992
  async start(params) {
820
993
  return this.http.post("/api/v1/runs", params);
821
994
  }
@@ -870,6 +1043,22 @@ var RunsNamespace = class {
870
1043
  };
871
1044
 
872
1045
  // src/platform/client.ts
1046
+ var resolveConfig = (config) => {
1047
+ const creds = loadCredentials();
1048
+ const baseUrl = config?.baseUrl ?? creds?.baseUrl;
1049
+ const apiKey = config?.apiKey ?? creds?.apiKey;
1050
+ if (!baseUrl) {
1051
+ throw new Error(
1052
+ "No Kraken platform endpoint configured.\n\nEither:\n 1. Log in via the CLI: npx kraken login\n 2. Set the environment variable: export KRAKEN_BASE_URL=https://your-platform-url\n 3. Pass baseUrl to PlatformClient: new PlatformClient({ baseUrl: '...' })\n"
1053
+ );
1054
+ }
1055
+ if (!apiKey) {
1056
+ throw new Error(
1057
+ "No Kraken API key configured.\n\nEither:\n 1. Log in via the CLI: npx kraken login\n 2. Set the environment variable: export KRAKEN_API_KEY=your-api-key\n 3. Pass apiKey to PlatformClient: new PlatformClient({ apiKey: '...' })\n"
1058
+ );
1059
+ }
1060
+ return { baseUrl, apiKey };
1061
+ };
873
1062
  var PlatformClient = class {
874
1063
  agents;
875
1064
  data;
@@ -877,9 +1066,8 @@ var PlatformClient = class {
877
1066
  runs;
878
1067
  http;
879
1068
  constructor(config) {
880
- if (!config.baseUrl) throw new Error("baseUrl is required");
881
- if (!config.apiKey) throw new Error("apiKey is required");
882
- this.http = new HttpClient(config);
1069
+ const resolved = resolveConfig(config);
1070
+ this.http = new HttpClient(resolved);
883
1071
  this.agents = new AgentsNamespace(this.http);
884
1072
  this.data = new DataNamespace(this.http);
885
1073
  this.pipelines = new PipelinesNamespace(this.http);
@@ -905,30 +1093,18 @@ var PlatformClient = class {
905
1093
  PlatformClient,
906
1094
  PlatformError,
907
1095
  SecurityError,
908
- actionVariantConfigSchema,
909
- actionsConfigSchema,
910
- agentDefinitionSchema,
911
1096
  buildActionOutputSchema,
912
- concurrencyPolicySchema,
913
1097
  defineAction,
914
- defineActions,
915
1098
  defineConnector,
916
1099
  definePlatformAgent,
917
1100
  defineSkill,
918
1101
  defineTool,
919
- environmentSchema,
920
- identityConfigSchema,
1102
+ isQualified,
921
1103
  isValidActionName,
922
- jitPolicySchema,
923
1104
  mcpResult,
924
- notificationConfigSchema,
1105
+ parse,
925
1106
  parseManifestFromOutput,
926
- platformAgentConfigSchema,
927
- projectManifestSchema,
928
- resourceLimitsSchema,
929
- retryPolicySchema,
930
- teamConfigSchema,
931
- triggerConfigSchema,
1107
+ qualify,
932
1108
  wrapToolError,
933
1109
  wrapToolResult
934
1110
  });