@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.
- 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 +12 -12
- package/dist/chunk-HGJSK6MW.js.map +0 -1
- package/dist/connector-CumEDPfS.d.cts +0 -103
- package/dist/connector-CumEDPfS.d.ts +0 -103
|
@@ -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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kraken-ai/platform",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Kraken AI Platform SDK — PlatformClient and kraken CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -21,10 +21,17 @@
|
|
|
21
21
|
"bin": {
|
|
22
22
|
"kraken": "./dist/cli.js"
|
|
23
23
|
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup && chmod +x dist/cli.js",
|
|
26
|
+
"test": "vitest run",
|
|
27
|
+
"test:watch": "vitest",
|
|
28
|
+
"check": "tsc --noEmit && biome check",
|
|
29
|
+
"check:write": "biome check --write"
|
|
30
|
+
},
|
|
24
31
|
"dependencies": {
|
|
25
32
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
33
|
+
"kraken-ai": "workspace:*",
|
|
34
|
+
"zod": "^4.3.6"
|
|
28
35
|
},
|
|
29
36
|
"devDependencies": {
|
|
30
37
|
"@types/node": "^25.5.0",
|
|
@@ -35,12 +42,5 @@
|
|
|
35
42
|
"files": [
|
|
36
43
|
"dist"
|
|
37
44
|
],
|
|
38
|
-
"license": "BUSL-1.1"
|
|
39
|
-
|
|
40
|
-
"build": "tsup",
|
|
41
|
-
"test": "vitest run",
|
|
42
|
-
"test:watch": "vitest",
|
|
43
|
-
"check": "biome check && tsc --noEmit",
|
|
44
|
-
"check:write": "biome check --write"
|
|
45
|
-
}
|
|
46
|
-
}
|
|
45
|
+
"license": "BUSL-1.1"
|
|
46
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/agents/errors.ts","../src/agents/connector-wrap.ts","../src/agents/connector-server.ts"],"sourcesContent":["// Copyright (c) Optima Engineering LLC\n// SPDX-License-Identifier: BUSL-1.1\n\nexport class SecurityError extends Error {\n readonly code = \"SECURITY_VIOLATION\";\n\n constructor(message: string) {\n super(message);\n this.name = \"SecurityError\";\n }\n}\n\nexport class ConnectorError extends Error {\n readonly code = \"CONNECTOR_ERROR\";\n\n constructor(message: string) {\n super(message);\n this.name = \"ConnectorError\";\n }\n}\n","// Copyright (c) Optima Engineering LLC\n// SPDX-License-Identifier: BUSL-1.1\n\nimport { ConnectorError } from \"./errors\";\nimport type { McpContent } from \"./types/connector\";\n\nconst MAX_TOOL_RESULT_SIZE = 10 * 1024 * 1024; // 10MB\n\ninterface ToolResultContent {\n readonly type: string;\n [key: string]: unknown;\n}\n\ninterface ToolResult {\n readonly content: ReadonlyArray<ToolResultContent>;\n readonly isError?: boolean;\n}\n\nconst isMcpContent = (val: unknown): val is McpContent =>\n typeof val === \"object\" &&\n val !== null &&\n \"__mcpPassThrough\" in val &&\n (val as McpContent).__mcpPassThrough === true;\n\n/** Wrap a handler return value into MCP CallToolResult format */\nexport const wrapToolResult = (value: unknown): ToolResult => {\n if (value === null || value === undefined) {\n return { content: [] };\n }\n\n if (typeof value === \"string\") {\n return { content: [{ type: \"text\", text: value }] };\n }\n\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return { content: [{ type: \"text\", text: String(value) }] };\n }\n\n if (isMcpContent(value)) {\n const result: ToolResult = { content: value.content };\n if (value.isError) {\n return { ...result, isError: true };\n }\n return result;\n }\n\n const json = JSON.stringify(value, null, 2);\n if (json.length > MAX_TOOL_RESULT_SIZE) {\n return {\n content: [{ type: \"text\", text: `[Result truncated: ${json.length} bytes]` }],\n isError: true,\n };\n }\n return { content: [{ type: \"text\", text: json }] };\n};\n\n/** Wrap a thrown error into MCP CallToolResult format with isError: true */\nexport const wrapToolError = (error: unknown): ToolResult => {\n if (error instanceof ConnectorError) {\n return {\n content: [{ type: \"text\", text: error.message }],\n isError: true,\n };\n }\n\n if (error instanceof Error) {\n console.error(\"[connector] Internal handler error:\", error.message, error.stack);\n } else {\n console.error(\"[connector] Internal handler error:\", String(error));\n }\n\n return {\n content: [{ type: \"text\", text: \"Internal handler error\" }],\n isError: true,\n };\n};\n\n/** Create an explicit MCP content pass-through result */\nexport const mcpResult = (content: McpContent[\"content\"], isError?: boolean): McpContent => ({\n __mcpPassThrough: true as const,\n content,\n isError,\n});\n","// Copyright (c) Optima Engineering LLC\n// SPDX-License-Identifier: BUSL-1.1\n\nimport { randomUUID } from \"node:crypto\";\nimport { createServer, type IncomingMessage, type ServerResponse } from \"node:http\";\nimport type { AddressInfo } from \"node:net\";\n\nimport * as z from \"zod\";\nimport { wrapToolError, wrapToolResult } from \"./connector-wrap\";\nimport type { ConnectorPromptDef, PlatformConnector } from \"./types/connector\";\n\nconst DEFAULT_HANDLER_TIMEOUT_MS = 30_000;\nconst MAX_BODY_SIZE = 10 * 1024 * 1024; // 10MB\n\nexport interface ConnectorServerOptions {\n readonly port?: number;\n readonly host?: string;\n readonly handlerTimeoutMs?: number;\n}\n\nexport interface ConnectorServerHandle {\n readonly port: number;\n readonly close: () => Promise<void>;\n}\n\nconst withTimeout = <T>(promise: Promise<T>, ms: number): Promise<T> =>\n Promise.race([\n promise,\n new Promise<never>((_, reject) =>\n setTimeout(() => reject(new Error(`Handler timed out after ${ms}ms`)), ms),\n ),\n ]);\n\nconst readBody = (req: IncomingMessage, maxSize: number): Promise<string> =>\n new Promise((resolve, reject) => {\n const chunks: Buffer[] = [];\n let size = 0;\n req.on(\"data\", (chunk: Buffer) => {\n size += chunk.length;\n if (size > maxSize) {\n req.destroy();\n reject(new Error(\"Request body too large\"));\n return;\n }\n chunks.push(chunk);\n });\n req.on(\"end\", () => resolve(Buffer.concat(chunks).toString()));\n req.on(\"error\", reject);\n });\n\n/** Convert ConnectorPromptDef.arguments array to a raw shape for MCP SDK */\nconst buildPromptArgsSchema = (\n def: ConnectorPromptDef,\n): Record<string, z.ZodString | z.ZodOptional<z.ZodString>> | undefined => {\n if (!def.arguments?.length) return undefined;\n const shape: Record<string, z.ZodString | z.ZodOptional<z.ZodString>> = {};\n for (const arg of def.arguments) {\n shape[arg.name] = arg.required ? z.string() : z.string().optional();\n }\n return shape;\n};\n\nexport const startConnectorServer = async (\n connector: PlatformConnector,\n options?: ConnectorServerOptions,\n): Promise<ConnectorServerHandle> => {\n const mcpServerModule = await import(\"@modelcontextprotocol/sdk/server/mcp.js\").catch(() => {\n throw new Error(\n \"@modelcontextprotocol/sdk is required for startConnectorServer. \" +\n \"Install it: pnpm add @modelcontextprotocol/sdk\",\n );\n });\n const transportModule = await import(\"@modelcontextprotocol/sdk/server/streamableHttp.js\").catch(\n () => {\n throw new Error(\n \"@modelcontextprotocol/sdk is required for startConnectorServer. \" +\n \"Install it: pnpm add @modelcontextprotocol/sdk\",\n );\n },\n );\n\n const { McpServer } = mcpServerModule;\n const { StreamableHTTPServerTransport } = transportModule;\n\n const timeoutMs = options?.handlerTimeoutMs ?? DEFAULT_HANDLER_TIMEOUT_MS;\n\n const mcpServer = new McpServer(\n { name: connector.name, version: \"0.0.0\" },\n { capabilities: { tools: {}, resources: {}, prompts: {} } },\n );\n\n const tools = connector.tools ?? {};\n const toolEntries = Object.entries(tools);\n\n if (toolEntries.length === 0) {\n console.warn(\n `[connector:${connector.name}] No tools defined — server will start with zero tools`,\n );\n }\n\n for (const [name, def] of toolEntries) {\n mcpServer.registerTool(\n name,\n {\n description: def.description,\n inputSchema: def.input,\n ...(def.annotations ? { annotations: def.annotations } : {}),\n },\n async (args: unknown) => {\n try {\n // args is already validated by the MCP SDK against the Zod schema\n const result = await withTimeout(Promise.resolve(def.handler(args)), timeoutMs);\n const wrapped = wrapToolResult(result);\n return {\n content: wrapped.content.map((c) => ({\n type: \"text\" as const,\n text: String(\"text\" in c ? c.text : \"\"),\n })),\n ...(wrapped.isError === true ? { isError: true as const } : {}),\n };\n } catch (error: unknown) {\n const wrapped = wrapToolError(error);\n return {\n content: wrapped.content.map((c) => ({\n type: \"text\" as const,\n text: String(\"text\" in c ? c.text : \"\"),\n })),\n isError: true as const,\n };\n }\n },\n );\n }\n\n const resources = connector.resources ?? {};\n for (const [name, def] of Object.entries(resources)) {\n mcpServer.registerResource(\n name,\n def.uri,\n {\n description: def.description,\n ...(def.mimeType ? { mimeType: def.mimeType } : {}),\n },\n async (_uri: URL, extra: { signal: AbortSignal }) => {\n try {\n const result = await withTimeout(\n Promise.resolve(def.read({ signal: extra.signal })),\n timeoutMs,\n );\n return { contents: [...result.contents] };\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error(`[connector:${connector.name}] Resource read error:`, error.message);\n }\n throw error;\n }\n },\n );\n }\n\n const prompts = connector.prompts ?? {};\n for (const [name, def] of Object.entries(prompts)) {\n const argsSchema = buildPromptArgsSchema(def);\n mcpServer.registerPrompt(\n name,\n {\n description: def.description,\n ...(argsSchema ? { argsSchema } : {}),\n },\n async (args: Record<string, string | undefined>, extra: { signal: AbortSignal }) => {\n try {\n const cleanArgs: Record<string, string> = {};\n for (const [k, v] of Object.entries(args)) {\n if (v !== undefined) cleanArgs[k] = v;\n }\n const result = await withTimeout(\n Promise.resolve(def.get(cleanArgs, { signal: extra.signal })),\n timeoutMs,\n );\n return { messages: [...result.messages] };\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error(`[connector:${connector.name}] Prompt get error:`, error.message);\n }\n throw error;\n }\n },\n );\n }\n\n const transport = new StreamableHTTPServerTransport({\n sessionIdGenerator: () => randomUUID(),\n });\n\n const host = options?.host ?? \"127.0.0.1\";\n const port = options?.port ?? 0;\n\n const httpServer = createServer(async (req: IncomingMessage, res: ServerResponse) => {\n if (req.url === \"/health\" && req.method === \"GET\") {\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify({ status: \"ok\" }));\n return;\n }\n\n if (\n req.url === \"/mcp\" &&\n (req.method === \"POST\" || req.method === \"GET\" || req.method === \"DELETE\")\n ) {\n if (req.method === \"POST\") {\n // Check Content-Length before reading body (fast reject for oversized payloads)\n const contentLength = parseInt(req.headers[\"content-length\"] ?? \"0\", 10);\n if (contentLength > MAX_BODY_SIZE) {\n req.resume(); // drain the request body to prevent EPIPE\n res.writeHead(413, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify({ error: \"Request body too large\" }));\n return;\n }\n\n try {\n const body = await readBody(req, MAX_BODY_SIZE);\n const parsed: unknown = JSON.parse(body);\n await transport.handleRequest(req, res, parsed);\n } catch (err: unknown) {\n if (!res.headersSent) {\n const isTooLarge = err instanceof Error && err.message === \"Request body too large\";\n res.writeHead(isTooLarge ? 413 : 400, { \"Content-Type\": \"application/json\" });\n res.end(\n JSON.stringify({\n error: isTooLarge ? \"Request body too large\" : \"Invalid request body\",\n }),\n );\n }\n }\n return;\n }\n\n // GET (SSE) and DELETE (session end)\n try {\n await transport.handleRequest(req, res);\n } catch {\n if (!res.headersSent) {\n res.writeHead(500, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify({ error: \"Internal server error\" }));\n }\n }\n return;\n }\n\n res.writeHead(404);\n res.end(\"Not found\");\n });\n\n // Connect MCP server to transport AFTER tool registration\n await mcpServer.connect(transport);\n\n await new Promise<void>((resolve) => {\n httpServer.listen(port, host, () => resolve());\n });\n\n const addr = httpServer.address();\n if (!addr || typeof addr === \"string\") {\n throw new Error(\"Failed to get server address\");\n }\n\n return {\n port: (addr as AddressInfo).port,\n close: async () => {\n await mcpServer.close();\n await new Promise<void>((resolve, reject) => {\n httpServer.close((err) => (err ? reject(err) : resolve()));\n });\n },\n };\n};\n"],"mappings":";AAGO,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAC9B,OAAO;AAAA,EAEhB,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,iBAAN,cAA6B,MAAM;AAAA,EAC/B,OAAO;AAAA,EAEhB,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ACbA,IAAM,uBAAuB,KAAK,OAAO;AAYzC,IAAM,eAAe,CAAC,QACpB,OAAO,QAAQ,YACf,QAAQ,QACR,sBAAsB,OACrB,IAAmB,qBAAqB;AAGpC,IAAM,iBAAiB,CAAC,UAA+B;AAC5D,MAAI,UAAU,QAAQ,UAAU,QAAW;AACzC,WAAO,EAAE,SAAS,CAAC,EAAE;AAAA,EACvB;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,EAAE,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,MAAM,CAAC,EAAE;AAAA,EACpD;AAEA,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU,WAAW;AAC3D,WAAO,EAAE,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,OAAO,KAAK,EAAE,CAAC,EAAE;AAAA,EAC5D;AAEA,MAAI,aAAa,KAAK,GAAG;AACvB,UAAM,SAAqB,EAAE,SAAS,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M,UAAU,cAAc,KAAK,GAAG;AAAA,MACxC,QAAQ;AACN,YAAI,CAAC,IAAI,aAAa;AACpB,cAAI,UAAU,KAAK,EAAE,gBAAgB,mBAAmB,CAAC;AACzD,cAAI,IAAI,KAAK,UAAU,EAAE,OAAO,wBAAwB,CAAC,CAAC;AAAA,QAC5D;AAAA,MACF;AACA;AAAA,IACF;AAEA,QAAI,UAAU,GAAG;AACjB,QAAI,IAAI,WAAW;AAAA,EACrB,CAAC;AAGD,QAAM,UAAU,QAAQ,SAAS;AAEjC,QAAM,IAAI,QAAc,CAAC,YAAY;AACnC,eAAW,OAAO,MAAM,MAAM,MAAM,QAAQ,CAAC;AAAA,EAC/C,CAAC;AAED,QAAM,OAAO,WAAW,QAAQ;AAChC,MAAI,CAAC,QAAQ,OAAO,SAAS,UAAU;AACrC,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AAEA,SAAO;AAAA,IACL,MAAO,KAAqB;AAAA,IAC5B,OAAO,YAAY;AACjB,YAAM,UAAU,MAAM;AACtB,YAAM,IAAI,QAAc,CAAC,SAAS,WAAW;AAC3C,mBAAW,MAAM,CAAC,QAAS,MAAM,OAAO,GAAG,IAAI,QAAQ,CAAE;AAAA,MAC3D,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import * as z from 'zod';
|
|
2
|
-
|
|
3
|
-
/** MCP tool annotations per the MCP spec (v1.27.1) */
|
|
4
|
-
interface ToolAnnotations {
|
|
5
|
-
readonly readOnlyHint?: boolean;
|
|
6
|
-
readonly destructiveHint?: boolean;
|
|
7
|
-
readonly idempotentHint?: boolean;
|
|
8
|
-
readonly openWorldHint?: boolean;
|
|
9
|
-
}
|
|
10
|
-
/** Explicit MCP content pass-through (returned by mcpResult() helper) */
|
|
11
|
-
interface McpContent {
|
|
12
|
-
readonly __mcpPassThrough: true;
|
|
13
|
-
readonly content: ReadonlyArray<{
|
|
14
|
-
readonly type: string;
|
|
15
|
-
[key: string]: unknown;
|
|
16
|
-
}>;
|
|
17
|
-
readonly isError?: boolean;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Union of valid handler return types.
|
|
21
|
-
* Prevents returning unsupported types at compile time.
|
|
22
|
-
*/
|
|
23
|
-
type ConnectorHandlerResult = string | number | boolean | Record<string, unknown> | ReadonlyArray<unknown> | McpContent | null | undefined;
|
|
24
|
-
/** Minimal context passed to resource/prompt handlers — business logic only */
|
|
25
|
-
interface ConnectorHandlerContext {
|
|
26
|
-
readonly signal: AbortSignal;
|
|
27
|
-
}
|
|
28
|
-
/** MCP-native resource content (text or binary) */
|
|
29
|
-
type ResourceContent = {
|
|
30
|
-
readonly uri: string;
|
|
31
|
-
readonly mimeType?: string;
|
|
32
|
-
readonly text: string;
|
|
33
|
-
} | {
|
|
34
|
-
readonly uri: string;
|
|
35
|
-
readonly mimeType?: string;
|
|
36
|
-
readonly blob: string;
|
|
37
|
-
};
|
|
38
|
-
/** MCP-native ReadResourceResult — returned by resource read handlers */
|
|
39
|
-
interface ReadResourceResult {
|
|
40
|
-
readonly contents: ReadonlyArray<ResourceContent>;
|
|
41
|
-
}
|
|
42
|
-
/** MCP-native prompt message content */
|
|
43
|
-
type PromptMessageContent = {
|
|
44
|
-
readonly type: "text";
|
|
45
|
-
readonly text: string;
|
|
46
|
-
} | {
|
|
47
|
-
readonly type: "image";
|
|
48
|
-
readonly data: string;
|
|
49
|
-
readonly mimeType: string;
|
|
50
|
-
};
|
|
51
|
-
/** MCP-native GetPromptResult — returned by prompt get handlers */
|
|
52
|
-
interface GetPromptResult {
|
|
53
|
-
readonly description?: string;
|
|
54
|
-
readonly messages: ReadonlyArray<{
|
|
55
|
-
readonly role: "user" | "assistant";
|
|
56
|
-
readonly content: PromptMessageContent;
|
|
57
|
-
}>;
|
|
58
|
-
}
|
|
59
|
-
/** A tool definition within a connector */
|
|
60
|
-
interface ConnectorToolDef<TInput extends z.ZodType = z.ZodType> {
|
|
61
|
-
readonly description: string;
|
|
62
|
-
readonly input: TInput;
|
|
63
|
-
readonly annotations?: ToolAnnotations;
|
|
64
|
-
handler(args: z.infer<TInput>): Promise<ConnectorHandlerResult> | ConnectorHandlerResult;
|
|
65
|
-
}
|
|
66
|
-
/** A resource definition within a connector */
|
|
67
|
-
interface ConnectorResourceDef {
|
|
68
|
-
readonly description: string;
|
|
69
|
-
readonly uri: string;
|
|
70
|
-
readonly mimeType?: string;
|
|
71
|
-
read(ctx: ConnectorHandlerContext): Promise<ReadResourceResult> | ReadResourceResult;
|
|
72
|
-
}
|
|
73
|
-
/** A prompt definition within a connector */
|
|
74
|
-
interface ConnectorPromptDef {
|
|
75
|
-
readonly description: string;
|
|
76
|
-
readonly arguments?: ReadonlyArray<{
|
|
77
|
-
readonly name: string;
|
|
78
|
-
readonly description?: string;
|
|
79
|
-
readonly required?: boolean;
|
|
80
|
-
}>;
|
|
81
|
-
get(args: Record<string, string>, ctx: ConnectorHandlerContext): Promise<GetPromptResult> | GetPromptResult;
|
|
82
|
-
}
|
|
83
|
-
/** Input to defineConnector() */
|
|
84
|
-
interface ConnectorDefinition {
|
|
85
|
-
readonly name: string;
|
|
86
|
-
readonly description?: string;
|
|
87
|
-
readonly instructions?: string;
|
|
88
|
-
readonly tools?: Record<string, ConnectorToolDef>;
|
|
89
|
-
readonly resources?: Record<string, ConnectorResourceDef>;
|
|
90
|
-
readonly prompts?: Record<string, ConnectorPromptDef>;
|
|
91
|
-
}
|
|
92
|
-
/** Output of defineConnector() — frozen, carries handlers for server builder */
|
|
93
|
-
interface PlatformConnector {
|
|
94
|
-
readonly __type: "PlatformConnector";
|
|
95
|
-
readonly name: string;
|
|
96
|
-
readonly description?: string;
|
|
97
|
-
readonly instructions?: string;
|
|
98
|
-
readonly tools?: Readonly<Record<string, ConnectorToolDef>>;
|
|
99
|
-
readonly resources?: Readonly<Record<string, ConnectorResourceDef>>;
|
|
100
|
-
readonly prompts?: Readonly<Record<string, ConnectorPromptDef>>;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export type { ConnectorDefinition as C, GetPromptResult as G, McpContent as M, PlatformConnector as P, ReadResourceResult as R, ToolAnnotations as T, ConnectorToolDef as a, ConnectorHandlerContext as b, ConnectorHandlerResult as c, ConnectorPromptDef as d, ConnectorResourceDef as e, PromptMessageContent as f, ResourceContent as g };
|