@kraken-ai/platform 0.0.3 → 0.0.6

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/server.cjs CHANGED
@@ -39,9 +39,9 @@ module.exports = __toCommonJS(server_exports);
39
39
  // src/agents/connector-server.ts
40
40
  var import_node_crypto = require("crypto");
41
41
  var import_node_http = require("http");
42
- var z = __toESM(require("zod"), 1);
42
+ var z9 = __toESM(require("zod"), 1);
43
43
 
44
- // src/agents/errors.ts
44
+ // ../../../private-packages/platform-core/dist/errors.js
45
45
  var ConnectorError = class extends Error {
46
46
  code = "CONNECTOR_ERROR";
47
47
  constructor(message) {
@@ -50,6 +50,205 @@ var ConnectorError = class extends Error {
50
50
  }
51
51
  };
52
52
 
53
+ // ../../../private-packages/platform-core/dist/qualified-name.js
54
+ var parse = (qualified) => {
55
+ const slashIndex = qualified.indexOf("/");
56
+ if (slashIndex === -1) {
57
+ throw new Error(`Expected qualified name with "/" separator, got: "${qualified}"`);
58
+ }
59
+ if (qualified.indexOf("/", slashIndex + 1) !== -1) {
60
+ throw new Error(`Expected exactly one "/" in qualified name, got: "${qualified}"`);
61
+ }
62
+ const repoName = qualified.slice(0, slashIndex);
63
+ const primitiveName = qualified.slice(slashIndex + 1);
64
+ if (!repoName || !primitiveName) {
65
+ throw new Error(`Both repo and primitive segments must be non-empty, got: "${qualified}"`);
66
+ }
67
+ return { repoName, primitiveName };
68
+ };
69
+ var isQualified = (name) => {
70
+ const slashIndex = name.indexOf("/");
71
+ if (slashIndex === -1 || slashIndex === 0 || slashIndex === name.length - 1)
72
+ return false;
73
+ return name.indexOf("/", slashIndex + 1) === -1;
74
+ };
75
+
76
+ // ../../../private-packages/platform-core/dist/types/environment.js
77
+ var z = __toESM(require("zod"), 1);
78
+ var environmentSchema = z.enum(["dev", "staging", "prod"]);
79
+
80
+ // ../../../private-packages/platform-core/dist/types/identity.js
81
+ var z2 = __toESM(require("zod"), 1);
82
+ var jitPolicySchema = z2.enum(["auto-approve", "policy-based", "require-approval"]);
83
+ var identityConfigSchema = z2.object({
84
+ basePermissions: z2.array(z2.string()),
85
+ requestablePermissions: z2.array(z2.string()).optional(),
86
+ jitPolicy: jitPolicySchema.optional(),
87
+ maxJitDurationMinutes: z2.number().int().positive().optional()
88
+ });
89
+
90
+ // ../../../private-packages/platform-core/dist/types/notifications.js
91
+ var z3 = __toESM(require("zod"), 1);
92
+ var notificationConfigSchema = z3.object({
93
+ slack: z3.string().optional(),
94
+ onSuccess: z3.boolean().optional(),
95
+ onFailure: z3.boolean().optional(),
96
+ onTimeout: z3.boolean().optional()
97
+ });
98
+
99
+ // ../../../private-packages/platform-core/dist/types/platform-agent.js
100
+ var z7 = __toESM(require("zod"), 1);
101
+
102
+ // ../../../private-packages/platform-core/dist/validate.js
103
+ var PRIMITIVE_NAME_REGEX = /^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$/;
104
+ var isValidPrimitiveName = (name) => name.length === 1 ? /^[a-z0-9]$/.test(name) : PRIMITIVE_NAME_REGEX.test(name);
105
+ var SKILL_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9-]{0,62}[a-zA-Z0-9]$/;
106
+ var isValidSkillName = (basename) => basename.length === 1 ? /^[a-zA-Z0-9]$/.test(basename) : SKILL_NAME_REGEX.test(basename);
107
+ var isValidSkillId = (id) => {
108
+ const base = id.endsWith(".md") ? id.slice(0, -3) : id;
109
+ return isValidSkillName(base);
110
+ };
111
+ var isValidQualifiedName = (name) => {
112
+ if (!isQualified(name))
113
+ return false;
114
+ const { repoName, primitiveName } = parse(name);
115
+ return isValidPrimitiveName(repoName) && isValidPrimitiveName(primitiveName);
116
+ };
117
+ var isValidQualifiedSkillId = (id) => {
118
+ if (!isQualified(id))
119
+ return false;
120
+ const { repoName, primitiveName } = parse(id);
121
+ return isValidPrimitiveName(repoName) && isValidSkillId(primitiveName);
122
+ };
123
+
124
+ // ../../../private-packages/platform-core/dist/types/resources.js
125
+ var z4 = __toESM(require("zod"), 1);
126
+ var resourceLimitsSchema = z4.object({
127
+ maxTokens: z4.number().int().positive().optional(),
128
+ maxCostUsd: z4.number().positive().optional(),
129
+ timeoutSeconds: z4.number().int().positive().optional()
130
+ });
131
+ var retryPolicySchema = z4.object({
132
+ maxAttempts: z4.number().int().min(1).optional(),
133
+ backoffSeconds: z4.number().positive().optional()
134
+ });
135
+ var concurrencyPolicySchema = z4.object({
136
+ maxParallelRuns: z4.number().int().min(1).optional()
137
+ });
138
+
139
+ // ../../../private-packages/platform-core/dist/types/team.js
140
+ var z5 = __toESM(require("zod"), 1);
141
+ var teamConfigSchema = z5.object({
142
+ members: z5.array(z5.string()).min(1),
143
+ maxConcurrentWorkers: z5.number().int().min(1).optional(),
144
+ maxTokenBudgetPerWorker: z5.number().int().positive().optional(),
145
+ maxDurationPerWorker: z5.number().positive().optional()
146
+ });
147
+
148
+ // ../../../private-packages/platform-core/dist/types/trigger.js
149
+ var z6 = __toESM(require("zod"), 1);
150
+ var cronTriggerSchema = z6.object({
151
+ type: z6.literal("cron"),
152
+ expression: z6.string(),
153
+ timezone: z6.string().optional()
154
+ });
155
+ var webhookTriggerSchema = z6.object({
156
+ type: z6.literal("webhook"),
157
+ path: z6.string().startsWith("/"),
158
+ method: z6.enum(["POST", "GET"]).optional()
159
+ });
160
+ var eventTriggerSchema = z6.object({
161
+ type: z6.literal("event"),
162
+ source: z6.string(),
163
+ event: z6.string()
164
+ });
165
+ var apiTriggerSchema = z6.object({ type: z6.literal("api") });
166
+ var manualTriggerSchema = z6.object({ type: z6.literal("manual") });
167
+ var triggerConfigSchema = z6.discriminatedUnion("type", [
168
+ cronTriggerSchema,
169
+ webhookTriggerSchema,
170
+ eventTriggerSchema,
171
+ apiTriggerSchema,
172
+ manualTriggerSchema
173
+ ]);
174
+
175
+ // ../../../private-packages/platform-core/dist/types/platform-agent.js
176
+ var thinkingLevelSchema = z7.enum(["low", "medium", "high"]);
177
+ var logLevelSchema = z7.enum(["silent", "debug", "info", "warn", "error"]);
178
+ var agentDefinitionSchema = z7.object({
179
+ name: z7.string().min(1),
180
+ model: z7.string().min(1),
181
+ instructions: z7.string().min(1),
182
+ description: z7.string().optional(),
183
+ skills: z7.array(z7.string()).optional(),
184
+ temperature: z7.number().min(0).max(2).optional(),
185
+ allowTemperatureOverride: z7.boolean().optional(),
186
+ maxOutputTokens: z7.number().int().positive().optional(),
187
+ thinkingLevel: thinkingLevelSchema.optional(),
188
+ logLevel: logLevelSchema.optional()
189
+ }).strict();
190
+ var platformAgentConfigSchema = z7.object({
191
+ agent: agentDefinitionSchema,
192
+ connectors: z7.array(z7.string()).optional(),
193
+ triggers: z7.array(triggerConfigSchema),
194
+ identity: identityConfigSchema.optional(),
195
+ resources: resourceLimitsSchema.optional(),
196
+ retries: retryPolicySchema.optional(),
197
+ concurrency: concurrencyPolicySchema.optional(),
198
+ team: teamConfigSchema.optional(),
199
+ notifications: notificationConfigSchema.optional(),
200
+ environment: environmentSchema.optional(),
201
+ actions: z7.array(z7.string()).optional()
202
+ }).strict().superRefine((data, ctx) => {
203
+ for (const member of data.team?.members ?? []) {
204
+ const valid = isQualified(member) ? isValidQualifiedName(member) : isValidPrimitiveName(member);
205
+ if (!valid) {
206
+ ctx.addIssue({
207
+ code: z7.ZodIssueCode.custom,
208
+ path: ["team", "members"],
209
+ message: `Invalid team member name: "${member}"`
210
+ });
211
+ }
212
+ }
213
+ for (const connector of data.connectors ?? []) {
214
+ const valid = isQualified(connector) ? isValidQualifiedName(connector) : isValidPrimitiveName(connector);
215
+ if (!valid) {
216
+ ctx.addIssue({
217
+ code: z7.ZodIssueCode.custom,
218
+ path: ["connectors"],
219
+ message: `Invalid connector name: "${connector}"`
220
+ });
221
+ }
222
+ }
223
+ for (const skill of data.agent.skills ?? []) {
224
+ const valid = isQualified(skill) ? isValidQualifiedSkillId(skill) : isValidSkillId(skill);
225
+ if (!valid) {
226
+ ctx.addIssue({
227
+ code: z7.ZodIssueCode.custom,
228
+ path: ["agent", "skills"],
229
+ message: `Invalid skill ID: "${skill}"`
230
+ });
231
+ }
232
+ }
233
+ for (const action of data.actions ?? []) {
234
+ const valid = isQualified(action) ? isValidQualifiedName(action) : isValidPrimitiveName(action);
235
+ if (!valid) {
236
+ ctx.addIssue({
237
+ code: z7.ZodIssueCode.custom,
238
+ path: ["actions"],
239
+ message: `Invalid action name: "${action}"`
240
+ });
241
+ }
242
+ }
243
+ });
244
+
245
+ // ../../../private-packages/platform-core/dist/types/skill.js
246
+ var z8 = __toESM(require("zod"), 1);
247
+ var platformSkillInputSchema = z8.object({
248
+ name: z8.string().min(1),
249
+ description: z8.string().optional()
250
+ }).strict();
251
+
53
252
  // src/agents/connector-wrap.ts
54
253
  var MAX_TOOL_RESULT_SIZE = 10 * 1024 * 1024;
55
254
  var isMcpContent = (val) => typeof val === "object" && val !== null && "__mcpPassThrough" in val && val.__mcpPassThrough === true;
@@ -125,7 +324,7 @@ var buildPromptArgsSchema = (def) => {
125
324
  if (!def.arguments?.length) return void 0;
126
325
  const shape = {};
127
326
  for (const arg of def.arguments) {
128
- shape[arg.name] = arg.required ? z.string() : z.string().optional();
327
+ shape[arg.name] = arg.required ? z9.string() : z9.string().optional();
129
328
  }
130
329
  return shape;
131
330
  };
@@ -317,33 +516,19 @@ var import_node_readline = require("readline");
317
516
  var import_kraken_ai2 = require("kraken-ai");
318
517
 
319
518
  // src/agents/define-actions.ts
320
- var z3 = __toESM(require("zod"), 1);
321
-
322
- // src/agents/types/action.ts
323
- var z2 = __toESM(require("zod"), 1);
324
- var actionVariantConfigSchema = z2.object({
325
- schema: z2.record(z2.string(), z2.unknown()),
326
- webhook: z2.string().url().optional(),
327
- hasHandler: z2.boolean()
328
- });
329
- var actionsConfigSchema = z2.object({
330
- variants: z2.record(z2.string(), actionVariantConfigSchema)
331
- }).strict();
332
-
333
- // src/agents/define-actions.ts
519
+ var z10 = __toESM(require("zod"), 1);
334
520
  var buildActionOutputSchema = (actions) => {
335
- const entries = Object.entries(actions.zodSchemas);
336
- if (entries.length === 0) {
521
+ if (actions.length === 0) {
337
522
  throw new Error("Cannot build output schema from empty action definitions");
338
523
  }
339
- const variants = entries.map(
340
- ([name, schema]) => z3.object({ action: z3.literal(name) }).extend(schema.shape)
524
+ const variants = actions.map(
525
+ (action) => z10.object({ action: z10.literal(action.name) }).extend(action.zodSchema.shape)
341
526
  );
342
527
  const [first, ...rest] = variants;
343
528
  if (!first) {
344
529
  throw new Error("Cannot build output schema from empty action definitions");
345
530
  }
346
- return z3.discriminatedUnion("action", [first, ...rest]);
531
+ return z10.discriminatedUnion("action", [first, ...rest]);
347
532
  };
348
533
 
349
534
  // src/cli/log.ts
@@ -409,15 +594,9 @@ var dispatchDevAction = async (output, zodSchemas, handlers, webhooks) => {
409
594
  // src/dev-connectors.ts
410
595
  var import_node_path = require("path");
411
596
  var import_kraken_ai = require("kraken-ai");
412
-
413
- // src/cli/validate.ts
414
- var ENTITY_NAME_REGEX = /^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$/;
415
- var isValidEntityName = (name) => name.length === 1 ? /^[a-z0-9]$/.test(name) : ENTITY_NAME_REGEX.test(name);
416
-
417
- // src/dev-connectors.ts
418
597
  var isPlatformConnector = (v) => v != null && typeof v === "object" && v.__type === "PlatformConnector";
419
598
  var importConnector = async (name, projectRoot) => {
420
- const basePath = (0, import_node_path.resolve)(projectRoot, "connectors", name, "index");
599
+ const basePath = (0, import_node_path.resolve)(projectRoot, "src", "connectors", name, "index");
421
600
  for (const ext of [".ts", ".js"]) {
422
601
  try {
423
602
  const mod = await import(`${basePath}${ext}`);
@@ -542,9 +721,9 @@ var loadConnectorTools = async (connectorNames, projectRoot) => {
542
721
  const root = projectRoot ?? process.cwd();
543
722
  const connectors = [];
544
723
  for (const name of connectorNames) {
545
- if (!isValidEntityName(name)) {
724
+ if (!isValidPrimitiveName(name)) {
546
725
  console.warn(
547
- `[connector] Invalid connector name "${name}" \u2014 must match ${ENTITY_NAME_REGEX}. Skipping.`
726
+ `[connector] Invalid connector name "${name}" \u2014 must match ${PRIMITIVE_NAME_REGEX}. Skipping.`
548
727
  );
549
728
  continue;
550
729
  }
@@ -577,7 +756,7 @@ var loadDotenv = () => {
577
756
  var FRONTMATTER_RE = /^---\n[\s\S]*?\n---\n([\s\S]*)$/;
578
757
  var resolveSkillContent = (refs) => refs.map((ref) => {
579
758
  try {
580
- return (0, import_node_fs.readFileSync)(`skills/${ref}`, "utf-8");
759
+ return (0, import_node_fs.readFileSync)(`src/skills/${ref}`, "utf-8");
581
760
  } catch {
582
761
  return ref;
583
762
  }
@@ -620,12 +799,13 @@ ${connectorInstructions.join("\n\n")}`;
620
799
 
621
800
  ${actionInstructions}`;
622
801
  }
623
- outputSchema = buildActionOutputSchema({
624
- __type: "PlatformActions",
625
- config: pa.config.actions ?? { variants: {} },
626
- zodSchemas: pa.actionZodSchemas,
627
- handlers: pa.actionHandlers ?? {}
628
- });
802
+ const actions = Object.entries(pa.actionZodSchemas).map(([name2, zodSchema]) => ({
803
+ __type: "PlatformAction",
804
+ name: name2,
805
+ config: { schema: {}, hasHandler: false },
806
+ zodSchema
807
+ }));
808
+ outputSchema = buildActionOutputSchema(actions);
629
809
  }
630
810
  let team;
631
811
  if (pa.teamAgents && pa.teamAgents.length > 0) {
@@ -705,18 +885,12 @@ var runDev = async (agent) => {
705
885
  if (result.status === "complete") {
706
886
  const output = typeof result.output === "string" ? result.output : JSON.stringify(result.output, null, 2);
707
887
  if (hasActions && agent.actionZodSchemas && result.output != null && typeof result.output === "object" && "action" in result.output) {
708
- const webhooks = {};
709
- if (agent.config.actions?.variants) {
710
- for (const [k, v] of Object.entries(agent.config.actions.variants)) {
711
- webhooks[k] = v.webhook;
712
- }
713
- }
714
888
  try {
715
889
  const dispatched = await dispatchDevAction(
716
890
  result.output,
717
891
  agent.actionZodSchemas,
718
892
  agent.actionHandlers,
719
- webhooks
893
+ agent.actionWebhooks ?? {}
720
894
  );
721
895
  console.log(`
722
896
  ${cyan("Action:")} ${green(dispatched.actionName)}`);