@kraken-ai/platform 0.0.1 → 0.0.2

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.
@@ -0,0 +1,451 @@
1
+ import * as z from 'zod';
2
+ import { ModelString } from 'kraken-ai';
3
+
4
+ /** MCP tool annotations per the MCP spec (v1.27.1) */
5
+ interface ToolAnnotations {
6
+ readonly readOnlyHint?: boolean;
7
+ readonly destructiveHint?: boolean;
8
+ readonly idempotentHint?: boolean;
9
+ readonly openWorldHint?: boolean;
10
+ }
11
+ /** Explicit MCP content pass-through (returned by mcpResult() helper) */
12
+ interface McpContent {
13
+ readonly __mcpPassThrough: true;
14
+ readonly content: ReadonlyArray<{
15
+ readonly type: string;
16
+ [key: string]: unknown;
17
+ }>;
18
+ readonly isError?: boolean;
19
+ }
20
+ /**
21
+ * Union of valid handler return types.
22
+ * Prevents returning unsupported types at compile time.
23
+ */
24
+ type ConnectorHandlerResult = string | number | boolean | Record<string, unknown> | ReadonlyArray<unknown> | McpContent | null | undefined;
25
+ /** Minimal context passed to resource/prompt handlers — business logic only */
26
+ interface ConnectorHandlerContext {
27
+ readonly signal: AbortSignal;
28
+ }
29
+ /** MCP-native resource content (text or binary) */
30
+ type ResourceContent = {
31
+ readonly uri: string;
32
+ readonly mimeType?: string;
33
+ readonly text: string;
34
+ } | {
35
+ readonly uri: string;
36
+ readonly mimeType?: string;
37
+ readonly blob: string;
38
+ };
39
+ /** MCP-native ReadResourceResult — returned by resource read handlers */
40
+ interface ReadResourceResult {
41
+ readonly contents: ReadonlyArray<ResourceContent>;
42
+ }
43
+ /** MCP-native prompt message content */
44
+ type PromptMessageContent = {
45
+ readonly type: "text";
46
+ readonly text: string;
47
+ } | {
48
+ readonly type: "image";
49
+ readonly data: string;
50
+ readonly mimeType: string;
51
+ };
52
+ /** MCP-native GetPromptResult — returned by prompt get handlers */
53
+ interface GetPromptResult {
54
+ readonly description?: string;
55
+ readonly messages: ReadonlyArray<{
56
+ readonly role: "user" | "assistant";
57
+ readonly content: PromptMessageContent;
58
+ }>;
59
+ }
60
+ /** A tool definition within a connector */
61
+ interface ConnectorToolDef<TInput extends z.ZodType = z.ZodType> {
62
+ readonly description: string;
63
+ readonly input: TInput;
64
+ readonly annotations?: ToolAnnotations;
65
+ handler(args: z.infer<TInput>): Promise<ConnectorHandlerResult> | ConnectorHandlerResult;
66
+ }
67
+ /** A resource definition within a connector */
68
+ interface ConnectorResourceDef {
69
+ readonly description: string;
70
+ readonly uri: string;
71
+ readonly mimeType?: string;
72
+ read(ctx: ConnectorHandlerContext): Promise<ReadResourceResult> | ReadResourceResult;
73
+ }
74
+ /** A prompt definition within a connector */
75
+ interface ConnectorPromptDef {
76
+ readonly description: string;
77
+ readonly arguments?: ReadonlyArray<{
78
+ readonly name: string;
79
+ readonly description?: string;
80
+ readonly required?: boolean;
81
+ }>;
82
+ get(args: Record<string, string>, ctx: ConnectorHandlerContext): Promise<GetPromptResult> | GetPromptResult;
83
+ }
84
+ /** Input to defineConnector() */
85
+ interface ConnectorDefinition {
86
+ readonly name: string;
87
+ readonly description?: string;
88
+ readonly instructions?: string;
89
+ readonly tools?: Record<string, ConnectorToolDef>;
90
+ readonly resources?: Record<string, ConnectorResourceDef>;
91
+ readonly prompts?: Record<string, ConnectorPromptDef>;
92
+ }
93
+ /** Output of defineConnector() — frozen, carries handlers for server builder */
94
+ interface PlatformConnector {
95
+ readonly __type: "PlatformConnector";
96
+ readonly name: string;
97
+ readonly description?: string;
98
+ readonly instructions?: string;
99
+ readonly tools?: Readonly<Record<string, ConnectorToolDef>>;
100
+ readonly resources?: Readonly<Record<string, ConnectorResourceDef>>;
101
+ readonly prompts?: Readonly<Record<string, ConnectorPromptDef>>;
102
+ }
103
+
104
+ /** Action names follow entity naming convention: lowercase alphanumeric with hyphens, 1-64 chars. */
105
+ declare const ACTION_NAME_REGEX: RegExp;
106
+ /** Validates an action name (allows single-char names like "a"). */
107
+ declare const isValidActionName: (name: string) => boolean;
108
+ /** Input for a single action variant in defineActions(). */
109
+ interface ActionVariantInput<S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>> {
110
+ schema: S;
111
+ webhook?: string;
112
+ handler?(payload: z.infer<S>): Promise<void>;
113
+ }
114
+ /** Serializable config for a single action variant (stored in manifest/DB). */
115
+ interface ActionVariantConfig {
116
+ schema: Record<string, unknown>;
117
+ webhook?: string;
118
+ hasHandler: boolean;
119
+ }
120
+ /** Serializable portion of action definitions (stored in agent config). */
121
+ interface PlatformActionsConfig {
122
+ variants: Record<string, ActionVariantConfig>;
123
+ }
124
+ /** Full action definitions including in-memory schemas and handlers for runtime use. */
125
+ interface PlatformActions {
126
+ readonly __type: "PlatformActions";
127
+ readonly config: PlatformActionsConfig;
128
+ readonly zodSchemas: Record<string, z.ZodObject<z.ZodRawShape>>;
129
+ readonly handlers: Readonly<Record<string, (payload: unknown) => Promise<void>>>;
130
+ }
131
+ declare const actionVariantConfigSchema: z.ZodObject<{
132
+ schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
133
+ webhook: z.ZodOptional<z.ZodString>;
134
+ hasHandler: z.ZodBoolean;
135
+ }, z.core.$strip>;
136
+ declare const actionsConfigSchema: z.ZodObject<{
137
+ variants: z.ZodRecord<z.ZodString, z.ZodObject<{
138
+ schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
139
+ webhook: z.ZodOptional<z.ZodString>;
140
+ hasHandler: z.ZodBoolean;
141
+ }, z.core.$strip>>;
142
+ }, z.core.$strict>;
143
+
144
+ /**
145
+ * Type registry populated by `kraken generate` via module augmentation.
146
+ *
147
+ * Before generating, all ID types resolve to an error-message string —
148
+ * only local typed refs (PlatformAgent, PlatformSkill, PlatformConnector) compile.
149
+ *
150
+ * After `kraken generate`, the generated `.kraken-ai/platform-types.d.ts` augments
151
+ * this interface with `agentId`, `connectorId`, and `skillId` string unions,
152
+ * enabling autocomplete on remote IDs.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * // .kraken-ai/platform-types.d.ts (generated)
157
+ * declare module "@kraken-ai/platform" {
158
+ * interface KrakenTypeRegistry {
159
+ * agentId: "analyst" | "writer";
160
+ * connectorId: "slack" | "jira";
161
+ * skillId: "competitor-deep-dive";
162
+ * }
163
+ * }
164
+ * ```
165
+ */
166
+ interface KrakenTypeRegistry {
167
+ }
168
+ /** Remote agent IDs. Resolves to an error hint before `kraken generate`. */
169
+ type AgentId = KrakenTypeRegistry extends {
170
+ agentId: infer T extends string;
171
+ } ? T : "ERROR: Run 'kraken generate' to unlock agent IDs";
172
+ /** Remote connector IDs. Resolves to an error hint before `kraken generate`. */
173
+ type ConnectorId = KrakenTypeRegistry extends {
174
+ connectorId: infer T extends string;
175
+ } ? T : "ERROR: Run 'kraken generate' to unlock connector IDs";
176
+ /** Remote skill IDs. Resolves to an error hint before `kraken generate`. */
177
+ type SkillId = KrakenTypeRegistry extends {
178
+ skillId: infer T extends string;
179
+ } ? T : "ERROR: Run 'kraken generate' to unlock skill IDs";
180
+
181
+ declare const agentDefinitionSchema: z.ZodObject<{
182
+ name: z.ZodString;
183
+ model: z.ZodString;
184
+ instructions: z.ZodString;
185
+ description: z.ZodOptional<z.ZodString>;
186
+ skills: z.ZodOptional<z.ZodArray<z.ZodString>>;
187
+ temperature: z.ZodOptional<z.ZodNumber>;
188
+ allowTemperatureOverride: z.ZodOptional<z.ZodBoolean>;
189
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
190
+ thinkingLevel: z.ZodOptional<z.ZodEnum<{
191
+ low: "low";
192
+ medium: "medium";
193
+ high: "high";
194
+ }>>;
195
+ logLevel: z.ZodOptional<z.ZodEnum<{
196
+ error: "error";
197
+ silent: "silent";
198
+ debug: "debug";
199
+ info: "info";
200
+ warn: "warn";
201
+ }>>;
202
+ }, z.core.$strict>;
203
+ type AgentDefinition = Omit<z.infer<typeof agentDefinitionSchema>, "model"> & {
204
+ model: ModelString;
205
+ };
206
+ declare const platformAgentConfigSchema: z.ZodObject<{
207
+ agent: z.ZodObject<{
208
+ name: z.ZodString;
209
+ model: z.ZodString;
210
+ instructions: z.ZodString;
211
+ description: z.ZodOptional<z.ZodString>;
212
+ skills: z.ZodOptional<z.ZodArray<z.ZodString>>;
213
+ temperature: z.ZodOptional<z.ZodNumber>;
214
+ allowTemperatureOverride: z.ZodOptional<z.ZodBoolean>;
215
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
216
+ thinkingLevel: z.ZodOptional<z.ZodEnum<{
217
+ low: "low";
218
+ medium: "medium";
219
+ high: "high";
220
+ }>>;
221
+ logLevel: z.ZodOptional<z.ZodEnum<{
222
+ error: "error";
223
+ silent: "silent";
224
+ debug: "debug";
225
+ info: "info";
226
+ warn: "warn";
227
+ }>>;
228
+ }, z.core.$strict>;
229
+ connectors: z.ZodOptional<z.ZodArray<z.ZodString>>;
230
+ trigger: z.ZodDiscriminatedUnion<[z.ZodObject<{
231
+ type: z.ZodLiteral<"cron">;
232
+ expression: z.ZodString;
233
+ timezone: z.ZodOptional<z.ZodString>;
234
+ }, z.core.$strip>, z.ZodObject<{
235
+ type: z.ZodLiteral<"webhook">;
236
+ path: z.ZodString;
237
+ method: z.ZodOptional<z.ZodEnum<{
238
+ GET: "GET";
239
+ POST: "POST";
240
+ }>>;
241
+ }, z.core.$strip>, z.ZodObject<{
242
+ type: z.ZodLiteral<"event">;
243
+ source: z.ZodString;
244
+ event: z.ZodString;
245
+ }, z.core.$strip>, z.ZodObject<{
246
+ type: z.ZodLiteral<"api">;
247
+ }, z.core.$strip>, z.ZodObject<{
248
+ type: z.ZodLiteral<"manual">;
249
+ }, z.core.$strip>], "type">;
250
+ identity: z.ZodOptional<z.ZodObject<{
251
+ basePermissions: z.ZodArray<z.ZodString>;
252
+ requestablePermissions: z.ZodOptional<z.ZodArray<z.ZodString>>;
253
+ jitPolicy: z.ZodOptional<z.ZodEnum<{
254
+ "auto-approve": "auto-approve";
255
+ "policy-based": "policy-based";
256
+ "require-approval": "require-approval";
257
+ }>>;
258
+ maxJitDurationMinutes: z.ZodOptional<z.ZodNumber>;
259
+ }, z.core.$strip>>;
260
+ resources: z.ZodOptional<z.ZodObject<{
261
+ maxTokens: z.ZodOptional<z.ZodNumber>;
262
+ maxCostUsd: z.ZodOptional<z.ZodNumber>;
263
+ timeoutSeconds: z.ZodOptional<z.ZodNumber>;
264
+ }, z.core.$strip>>;
265
+ retries: z.ZodOptional<z.ZodObject<{
266
+ maxAttempts: z.ZodOptional<z.ZodNumber>;
267
+ backoffSeconds: z.ZodOptional<z.ZodNumber>;
268
+ }, z.core.$strip>>;
269
+ concurrency: z.ZodOptional<z.ZodObject<{
270
+ maxParallelRuns: z.ZodOptional<z.ZodNumber>;
271
+ }, z.core.$strip>>;
272
+ team: z.ZodOptional<z.ZodObject<{
273
+ members: z.ZodArray<z.ZodString>;
274
+ maxConcurrentWorkers: z.ZodOptional<z.ZodNumber>;
275
+ maxTokenBudgetPerWorker: z.ZodOptional<z.ZodNumber>;
276
+ maxDurationPerWorker: z.ZodOptional<z.ZodNumber>;
277
+ }, z.core.$strip>>;
278
+ notifications: z.ZodOptional<z.ZodObject<{
279
+ slack: z.ZodOptional<z.ZodString>;
280
+ onSuccess: z.ZodOptional<z.ZodBoolean>;
281
+ onFailure: z.ZodOptional<z.ZodBoolean>;
282
+ onTimeout: z.ZodOptional<z.ZodBoolean>;
283
+ }, z.core.$strip>>;
284
+ environment: z.ZodOptional<z.ZodEnum<{
285
+ dev: "dev";
286
+ staging: "staging";
287
+ prod: "prod";
288
+ }>>;
289
+ actions: z.ZodOptional<z.ZodObject<{
290
+ variants: z.ZodRecord<z.ZodString, z.ZodObject<{
291
+ schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
292
+ webhook: z.ZodOptional<z.ZodString>;
293
+ hasHandler: z.ZodBoolean;
294
+ }, z.core.$strip>>;
295
+ }, z.core.$strict>>;
296
+ }, z.core.$strict>;
297
+ type PlatformAgentConfig = Omit<z.infer<typeof platformAgentConfigSchema>, "agent" | "actions"> & {
298
+ agent: AgentDefinition;
299
+ actions?: PlatformActionsConfig;
300
+ };
301
+ interface PlatformAgent {
302
+ readonly __type: "PlatformAgent";
303
+ readonly config: PlatformAgentConfig;
304
+ readonly runtime?: unknown;
305
+ /** In-memory schemas for action variants. Not serialized — runtime use only. */
306
+ readonly actionZodSchemas?: Record<string, z.ZodObject<z.ZodRawShape>>;
307
+ /** Action handler functions. Not serialized — runtime use only. */
308
+ readonly actionHandlers?: Readonly<Record<string, (payload: unknown) => Promise<void>>>;
309
+ /** Team member PlatformAgent objects. Not serialized — runtime use only (dev mode delegation). */
310
+ readonly teamAgents?: readonly PlatformAgent[];
311
+ }
312
+ /** Team member reference: local PlatformAgent or remote AgentId string. */
313
+ type TeamMember = PlatformAgent | AgentId;
314
+
315
+ interface PlatformClientConfig {
316
+ baseUrl: string;
317
+ apiKey: string;
318
+ }
319
+ interface PaginationParams {
320
+ cursor?: string;
321
+ limit?: number;
322
+ }
323
+ interface PaginatedResponse<T> {
324
+ data: T[];
325
+ cursor: string | null;
326
+ hasMore: boolean;
327
+ }
328
+ type AgentEvent = {
329
+ type: "text";
330
+ content: string;
331
+ } | {
332
+ type: "tool_call";
333
+ name: string;
334
+ args: Record<string, unknown>;
335
+ } | {
336
+ type: "tool_result";
337
+ name: string;
338
+ result: unknown;
339
+ } | {
340
+ type: "thinking";
341
+ content: string;
342
+ } | {
343
+ type: "action";
344
+ name: string;
345
+ payload: Record<string, unknown>;
346
+ actionExecutionId: string;
347
+ } | {
348
+ type: "done";
349
+ output: string;
350
+ usage?: {
351
+ tokens: number;
352
+ };
353
+ } | {
354
+ type: "error";
355
+ message: string;
356
+ code: string;
357
+ };
358
+ interface AgentInfo {
359
+ id: string;
360
+ name: string;
361
+ description?: string;
362
+ }
363
+ interface ThreadInfo {
364
+ id: string;
365
+ agentId: string;
366
+ createdAt: string;
367
+ updatedAt: string;
368
+ }
369
+ interface ThreadMessage {
370
+ id: string;
371
+ threadId: string;
372
+ role: "user" | "assistant";
373
+ content: string;
374
+ toolCalls?: Array<{
375
+ name: string;
376
+ args: Record<string, unknown>;
377
+ result: unknown;
378
+ }>;
379
+ createdAt: string;
380
+ usage?: {
381
+ tokens: number;
382
+ };
383
+ }
384
+ interface QueryInfo {
385
+ name: string;
386
+ description?: string;
387
+ params: Record<string, unknown>;
388
+ columns: QueryColumn[];
389
+ }
390
+ interface QueryColumn {
391
+ name: string;
392
+ type: string;
393
+ description?: string;
394
+ }
395
+ interface QueryResult<TRow = Record<string, unknown>> {
396
+ rows: TRow[];
397
+ cursor: string | null;
398
+ hasMore: boolean;
399
+ }
400
+ type RunState = "QUEUED" | "PROVISIONING" | "RUNNING" | "DRAINING" | "COMPLETED" | "FAILED" | "AWAITING_APPROVAL" | "RETRYING";
401
+ interface RunRecord {
402
+ runId: string;
403
+ agentId: string;
404
+ input: string;
405
+ state: RunState;
406
+ exitCode?: number;
407
+ createdAt: string;
408
+ updatedAt: string;
409
+ retryCount: number;
410
+ error?: string;
411
+ }
412
+ interface StartRunParams {
413
+ agentId: string;
414
+ tag?: string;
415
+ environment?: "dev" | "staging" | "prod";
416
+ input: string;
417
+ connectors?: string[];
418
+ envVars?: Record<string, string>;
419
+ }
420
+ interface RunEvent {
421
+ eventId: string;
422
+ eventType: string;
423
+ payload: Record<string, unknown>;
424
+ }
425
+ interface AgentSchema {
426
+ id: string;
427
+ name: string;
428
+ input: Record<string, unknown>;
429
+ output: Record<string, unknown>;
430
+ actions?: Record<string, Record<string, unknown>>;
431
+ }
432
+ interface QuerySchema {
433
+ name: string;
434
+ params: Record<string, unknown>;
435
+ columns: QueryColumn[];
436
+ }
437
+ interface ConnectorSchema {
438
+ id: string;
439
+ tools: Array<{
440
+ name: string;
441
+ description: string;
442
+ parameters: Record<string, unknown>;
443
+ }>;
444
+ }
445
+ interface SkillSchema {
446
+ id: string;
447
+ name: string;
448
+ description?: string;
449
+ }
450
+
451
+ export { type ActionVariantInput as A, type PromptMessageContent as B, type ConnectorId as C, type QueryColumn as D, type QuerySchema as E, type ReadResourceResult as F, type GetPromptResult as G, type ResourceContent as H, type RunState as I, type SkillSchema as J, type KrakenTypeRegistry as K, type ToolAnnotations as L, type McpContent as M, actionVariantConfigSchema as N, actionsConfigSchema as O, type PlatformConnector as P, type QueryInfo as Q, type RunRecord as R, type SkillId as S, type TeamMember as T, agentDefinitionSchema as U, isValidActionName as V, platformAgentConfigSchema as W, type PlatformAgentConfig as a, type PlatformActions as b, type PlatformAgent as c, type ConnectorDefinition as d, type ConnectorToolDef as e, type PlatformClientConfig as f, type AgentEvent as g, type PaginationParams as h, type PaginatedResponse as i, type ThreadMessage as j, type AgentInfo as k, type ThreadInfo as l, type QueryResult as m, type StartRunParams as n, type RunEvent as o, ACTION_NAME_REGEX as p, type ActionVariantConfig as q, type AgentDefinition as r, type AgentId as s, type AgentSchema as t, type ConnectorHandlerContext as u, type ConnectorHandlerResult as v, type ConnectorPromptDef as w, type ConnectorResourceDef as x, type ConnectorSchema as y, type PlatformActionsConfig as z };