@flexkit/agent-protocol 0.2.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Flexkit.io
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # @flexkit/agent-protocol
2
+
3
+ Schemas and types shared between the Flexkit agent platform and the Studio UI (`@flexkit/ai`):
4
+
5
+ - `dataPartSchema`: the custom `data-*` parts the platform streams while a chat turn or automation run executes, as zod schemas. The server validates what it writes against them; the UI derives its part types from them.
6
+ - Run, approval and chat DTO types returned by the automations and agent chat APIs.
7
+
8
+ Adding a part: add it here first (minor bump), publish, then emit it on the server and render it in the UI. The UI ignores unknown parts, so publishing ahead of the server is safe.
@@ -0,0 +1,417 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Custom `data-*` parts streamed by the Flexkit agent platform and rendered by
5
+ * Studio. The server validates what it writes against these schemas and the
6
+ * UI derives its part types from them, so the two can never drift.
7
+ */
8
+ declare const errorSchema: z.ZodObject<{
9
+ message: z.ZodString;
10
+ }, z.core.$strip>;
11
+ declare const dataPartSchema: z.ZodObject<{
12
+ 'plugin-connection': z.ZodObject<{
13
+ pluginId: z.ZodString;
14
+ connectionId: z.ZodOptional<z.ZodString>;
15
+ }, z.core.$strip>;
16
+ 'plugin-call': z.ZodObject<{
17
+ pluginId: z.ZodString;
18
+ tool: z.ZodString;
19
+ status: z.ZodEnum<{
20
+ loading: "loading";
21
+ done: "done";
22
+ error: "error";
23
+ }>;
24
+ error: z.ZodOptional<z.ZodObject<{
25
+ message: z.ZodString;
26
+ }, z.core.$strip>>;
27
+ }, z.core.$strip>;
28
+ 'context-compaction': z.ZodObject<{
29
+ reason: z.ZodEnum<{
30
+ threshold: "threshold";
31
+ context_length_error: "context_length_error";
32
+ }>;
33
+ status: z.ZodEnum<{
34
+ done: "done";
35
+ }>;
36
+ summarizedMessageCount: z.ZodNumber;
37
+ }, z.core.$strip>;
38
+ plan: z.ZodObject<{
39
+ explanation: z.ZodOptional<z.ZodString>;
40
+ steps: z.ZodArray<z.ZodObject<{
41
+ status: z.ZodEnum<{
42
+ pending: "pending";
43
+ in_progress: "in_progress";
44
+ completed: "completed";
45
+ }>;
46
+ step: z.ZodString;
47
+ }, z.core.$strip>>;
48
+ updatedAt: z.ZodString;
49
+ }, z.core.$strip>;
50
+ subtask: z.ZodObject<{
51
+ error: z.ZodOptional<z.ZodObject<{
52
+ message: z.ZodString;
53
+ }, z.core.$strip>>;
54
+ resultPreview: z.ZodOptional<z.ZodString>;
55
+ status: z.ZodEnum<{
56
+ done: "done";
57
+ error: "error";
58
+ running: "running";
59
+ }>;
60
+ stepsUsed: z.ZodOptional<z.ZodNumber>;
61
+ subtaskId: z.ZodString;
62
+ title: z.ZodString;
63
+ }, z.core.$strip>;
64
+ spec: z.ZodUnion<readonly [z.ZodObject<{
65
+ type: z.ZodLiteral<"patch">;
66
+ patch: z.ZodUnknown;
67
+ }, z.core.$strip>, z.ZodObject<{
68
+ type: z.ZodLiteral<"flat">;
69
+ spec: z.ZodUnknown;
70
+ }, z.core.$strip>, z.ZodObject<{
71
+ type: z.ZodLiteral<"nested">;
72
+ spec: z.ZodUnknown;
73
+ }, z.core.$strip>]>;
74
+ 'create-sandbox': z.ZodObject<{
75
+ sandboxId: z.ZodOptional<z.ZodString>;
76
+ status: z.ZodEnum<{
77
+ loading: "loading";
78
+ done: "done";
79
+ error: "error";
80
+ }>;
81
+ error: z.ZodOptional<z.ZodObject<{
82
+ message: z.ZodString;
83
+ }, z.core.$strip>>;
84
+ }, z.core.$strip>;
85
+ 'generating-files': z.ZodObject<{
86
+ paths: z.ZodArray<z.ZodString>;
87
+ status: z.ZodEnum<{
88
+ done: "done";
89
+ error: "error";
90
+ generating: "generating";
91
+ uploading: "uploading";
92
+ uploaded: "uploaded";
93
+ }>;
94
+ error: z.ZodOptional<z.ZodObject<{
95
+ message: z.ZodString;
96
+ }, z.core.$strip>>;
97
+ }, z.core.$strip>;
98
+ 'run-artifact': z.ZodObject<{
99
+ artifactId: z.ZodOptional<z.ZodString>;
100
+ contentType: z.ZodOptional<z.ZodString>;
101
+ error: z.ZodOptional<z.ZodObject<{
102
+ message: z.ZodString;
103
+ }, z.core.$strip>>;
104
+ filename: z.ZodString;
105
+ kind: z.ZodOptional<z.ZodEnum<{
106
+ html: "html";
107
+ pdf: "pdf";
108
+ }>>;
109
+ sizeBytes: z.ZodOptional<z.ZodNumber>;
110
+ status: z.ZodEnum<{
111
+ done: "done";
112
+ error: "error";
113
+ uploading: "uploading";
114
+ }>;
115
+ url: z.ZodOptional<z.ZodString>;
116
+ }, z.core.$strip>;
117
+ 'run-command': z.ZodObject<{
118
+ sandboxId: z.ZodString;
119
+ commandId: z.ZodOptional<z.ZodString>;
120
+ command: z.ZodString;
121
+ args: z.ZodArray<z.ZodString>;
122
+ status: z.ZodEnum<{
123
+ done: "done";
124
+ error: "error";
125
+ running: "running";
126
+ executing: "executing";
127
+ waiting: "waiting";
128
+ }>;
129
+ exitCode: z.ZodOptional<z.ZodNumber>;
130
+ error: z.ZodOptional<z.ZodObject<{
131
+ message: z.ZodString;
132
+ }, z.core.$strip>>;
133
+ }, z.core.$strip>;
134
+ 'search-schema': z.ZodObject<{
135
+ query: z.ZodOptional<z.ZodString>;
136
+ status: z.ZodEnum<{
137
+ loading: "loading";
138
+ done: "done";
139
+ error: "error";
140
+ }>;
141
+ error: z.ZodOptional<z.ZodObject<{
142
+ message: z.ZodString;
143
+ }, z.core.$strip>>;
144
+ }, z.core.$strip>;
145
+ 'web-search': z.ZodObject<{
146
+ query: z.ZodString;
147
+ status: z.ZodEnum<{
148
+ loading: "loading";
149
+ done: "done";
150
+ error: "error";
151
+ }>;
152
+ error: z.ZodOptional<z.ZodObject<{
153
+ message: z.ZodString;
154
+ }, z.core.$strip>>;
155
+ }, z.core.$strip>;
156
+ 'tool-delivery': z.ZodObject<{
157
+ channelId: z.ZodString;
158
+ channelName: z.ZodString;
159
+ provider: z.ZodEnum<{
160
+ slack: "slack";
161
+ teams: "teams";
162
+ }>;
163
+ status: z.ZodEnum<{
164
+ loading: "loading";
165
+ done: "done";
166
+ error: "error";
167
+ }>;
168
+ error: z.ZodOptional<z.ZodObject<{
169
+ message: z.ZodString;
170
+ }, z.core.$strip>>;
171
+ }, z.core.$strip>;
172
+ 'validate-graphql': z.ZodObject<{
173
+ status: z.ZodEnum<{
174
+ loading: "loading";
175
+ error: "error";
176
+ valid: "valid";
177
+ invalid: "invalid";
178
+ }>;
179
+ errorCount: z.ZodOptional<z.ZodNumber>;
180
+ error: z.ZodOptional<z.ZodObject<{
181
+ message: z.ZodString;
182
+ }, z.core.$strip>>;
183
+ }, z.core.$strip>;
184
+ 'execute-graphql': z.ZodObject<{
185
+ operationType: z.ZodOptional<z.ZodEnum<{
186
+ query: "query";
187
+ mutation: "mutation";
188
+ }>>;
189
+ status: z.ZodEnum<{
190
+ loading: "loading";
191
+ done: "done";
192
+ error: "error";
193
+ }>;
194
+ error: z.ZodOptional<z.ZodObject<{
195
+ message: z.ZodString;
196
+ }, z.core.$strip>>;
197
+ }, z.core.$strip>;
198
+ 'mutation-approval': z.ZodObject<{
199
+ approvalId: z.ZodString;
200
+ affectedCount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
201
+ decidedBy: z.ZodOptional<z.ZodString>;
202
+ operationsSummary: z.ZodString;
203
+ reason: z.ZodOptional<z.ZodString>;
204
+ status: z.ZodEnum<{
205
+ error: "error";
206
+ pending: "pending";
207
+ approved: "approved";
208
+ rejected: "rejected";
209
+ expired: "expired";
210
+ cancelled: "cancelled";
211
+ executed: "executed";
212
+ }>;
213
+ error: z.ZodOptional<z.ZodObject<{
214
+ message: z.ZodString;
215
+ }, z.core.$strip>>;
216
+ }, z.core.$strip>;
217
+ 'bulk-graphql-action': z.ZodObject<{
218
+ changedItems: z.ZodOptional<z.ZodNumber>;
219
+ failedItems: z.ZodOptional<z.ZodNumber>;
220
+ jobId: z.ZodOptional<z.ZodString>;
221
+ operationName: z.ZodString;
222
+ processedItems: z.ZodOptional<z.ZodNumber>;
223
+ status: z.ZodEnum<{
224
+ loading: "loading";
225
+ done: "done";
226
+ error: "error";
227
+ running: "running";
228
+ }>;
229
+ totalItems: z.ZodOptional<z.ZodNumber>;
230
+ error: z.ZodOptional<z.ZodObject<{
231
+ message: z.ZodString;
232
+ }, z.core.$strip>>;
233
+ }, z.core.$strip>;
234
+ 'update-memory': z.ZodObject<{
235
+ status: z.ZodEnum<{
236
+ loading: "loading";
237
+ done: "done";
238
+ error: "error";
239
+ }>;
240
+ error: z.ZodOptional<z.ZodObject<{
241
+ message: z.ZodString;
242
+ }, z.core.$strip>>;
243
+ }, z.core.$strip>;
244
+ 'load-skill': z.ZodObject<{
245
+ attached: z.ZodOptional<z.ZodBoolean>;
246
+ skillName: z.ZodOptional<z.ZodString>;
247
+ status: z.ZodEnum<{
248
+ loading: "loading";
249
+ done: "done";
250
+ error: "error";
251
+ }>;
252
+ error: z.ZodOptional<z.ZodObject<{
253
+ message: z.ZodString;
254
+ }, z.core.$strip>>;
255
+ }, z.core.$strip>;
256
+ 'user-message': z.ZodObject<{
257
+ parts: z.ZodArray<z.ZodUnknown>;
258
+ }, z.core.$strip>;
259
+ 'run-summary': z.ZodObject<{
260
+ status: z.ZodEnum<{
261
+ success: "success";
262
+ skipped: "skipped";
263
+ failed: "failed";
264
+ }>;
265
+ summary: z.ZodString;
266
+ }, z.core.$strip>;
267
+ 'turn-error': z.ZodObject<{
268
+ message: z.ZodString;
269
+ }, z.core.$strip>;
270
+ 'suggested-prompt': z.ZodObject<{
271
+ prompt: z.ZodString;
272
+ }, z.core.$strip>;
273
+ }, z.core.$strip>;
274
+ type DataPart = z.infer<typeof dataPartSchema>;
275
+ type DataPartType = keyof DataPart;
276
+ declare const DATA_PART_TYPES: DataPartType[];
277
+ declare function isDataPartType(type: string): type is DataPartType;
278
+ /** The `type` of a UI message part carrying this data part. */
279
+ type DataPartMessageType = `data-${DataPartType}`;
280
+
281
+ /** Run and approval shapes returned by the automations API. */
282
+ type AutomationRunStatus = 'running' | 'awaiting_approval' | 'success' | 'skipped' | 'failed' | 'cancelled';
283
+ type AutomationTriggerType = 'entity' | 'manual' | 'schedule' | 'webhook';
284
+ type AutomationApprovalStatus = 'pending' | 'approved' | 'rejected' | 'expired' | 'cancelled';
285
+ type AutomationApprovalKind = 'graphql' | 'bulk' | 'plugin' | 'exec';
286
+ type AutomationApprovalPreviewKind = 'create' | 'update' | 'delete' | 'unknown';
287
+ type AutomationMutationPolicy = 'require_approval' | 'auto_approve';
288
+ interface AutomationApprovalOperation {
289
+ query: string;
290
+ variables: {
291
+ [key: string]: unknown;
292
+ } | null;
293
+ }
294
+ interface AutomationApprovalPreviewRow {
295
+ after: {
296
+ [key: string]: unknown;
297
+ } | null;
298
+ before: {
299
+ [key: string]: unknown;
300
+ } | null;
301
+ id: string | null;
302
+ }
303
+ interface AutomationApprovalPreviewOperation {
304
+ affectedCount: number | null;
305
+ columns: string[];
306
+ /** Read-only fields shown alongside the changed columns for reviewer context. */
307
+ contextColumns?: string[];
308
+ entity: string | null;
309
+ kind: AutomationApprovalPreviewKind;
310
+ rows: AutomationApprovalPreviewRow[];
311
+ truncated: boolean;
312
+ }
313
+ interface AutomationApprovalPreview {
314
+ operations: AutomationApprovalPreviewOperation[];
315
+ }
316
+ interface AutomationApproval {
317
+ affectedCount: number | null;
318
+ /** Null for approvals raised by a chat turn. */
319
+ automationId: string | null;
320
+ automationName: string;
321
+ /** Set for approvals raised by a chat turn. */
322
+ chatId: string | null;
323
+ chatMessageId: string | null;
324
+ decidedAt: string | null;
325
+ decidedBy: string | null;
326
+ error: string | null;
327
+ executedAt: string | null;
328
+ expiresAt: string;
329
+ id: string;
330
+ kind: AutomationApprovalKind;
331
+ operations: AutomationApprovalOperation[];
332
+ operationsSummary: string;
333
+ preview: AutomationApprovalPreview | null;
334
+ projectId: string;
335
+ reason: string | null;
336
+ requestedAt: string;
337
+ /** Null for approvals raised by a chat turn. */
338
+ runId: string | null;
339
+ status: AutomationApprovalStatus;
340
+ }
341
+ interface AutomationRun {
342
+ automationId: string;
343
+ completedAt: string | null;
344
+ error: string | null;
345
+ id: string;
346
+ projectId: string;
347
+ startedAt: string;
348
+ status: AutomationRunStatus;
349
+ summary: string | null;
350
+ triggerPayload: unknown;
351
+ triggerType: AutomationTriggerType;
352
+ workflowRunId: string | null;
353
+ }
354
+ /** A plugin tool a reviewer chose to always allow for one automation. */
355
+ interface AutomationToolAllowRule {
356
+ addedAt: string;
357
+ addedBy: string | null;
358
+ pluginId: string;
359
+ server: string;
360
+ tool: string;
361
+ }
362
+
363
+ /** Chat shapes returned by the agent chat API. */
364
+ type AgentChatMessageRole = 'user' | 'assistant';
365
+ /** `pending` exists only client-side, for a turn whose record has not been created yet. */
366
+ type AgentChatMessageStatus = 'pending' | 'streaming' | 'awaiting_approval' | 'complete' | 'failed';
367
+ interface AgentChat {
368
+ createdAt: string;
369
+ id: string;
370
+ lastMessageAt: string | null;
371
+ modelId: string | null;
372
+ title: string | null;
373
+ updatedAt: string;
374
+ }
375
+ /** A file the user uploaded for a chat message. */
376
+ interface AgentChatAttachment {
377
+ filename: string;
378
+ mediaType: string;
379
+ sizeBytes: number;
380
+ url: string;
381
+ }
382
+ /** UIMessage-shaped part persisted for finished turns. */
383
+ interface AgentChatPart {
384
+ data?: unknown;
385
+ errorText?: string;
386
+ /** `file` parts: original filename of a user attachment. */
387
+ filename?: string;
388
+ input?: unknown;
389
+ /** `file` parts: IANA media type of a user attachment. */
390
+ mediaType?: string;
391
+ output?: unknown;
392
+ /** `file` parts: byte size of a user attachment. */
393
+ sizeBytes?: number;
394
+ state?: string;
395
+ text?: string;
396
+ toolCallId?: string;
397
+ type: string;
398
+ /** `file` parts: public URL of a user attachment. */
399
+ url?: string;
400
+ }
401
+ interface AgentChatMessage {
402
+ createdAt: string;
403
+ error: string | null;
404
+ id: string;
405
+ parts: AgentChatPart[] | null;
406
+ role: AgentChatMessageRole;
407
+ status: AgentChatMessageStatus;
408
+ textContent: string;
409
+ workflowRunId: string | null;
410
+ }
411
+ interface AgentChatTurn {
412
+ assistantMessage: AgentChatMessage;
413
+ userMessage: AgentChatMessage;
414
+ workflowRunId: string;
415
+ }
416
+
417
+ export { type AgentChat, type AgentChatAttachment, type AgentChatMessage, type AgentChatMessageRole, type AgentChatMessageStatus, type AgentChatPart, type AgentChatTurn, type AutomationApproval, type AutomationApprovalKind, type AutomationApprovalOperation, type AutomationApprovalPreview, type AutomationApprovalPreviewKind, type AutomationApprovalPreviewOperation, type AutomationApprovalPreviewRow, type AutomationApprovalStatus, type AutomationMutationPolicy, type AutomationRun, type AutomationRunStatus, type AutomationToolAllowRule, type AutomationTriggerType, DATA_PART_TYPES, type DataPart, type DataPartMessageType, type DataPartType, dataPartSchema, errorSchema, isDataPartType };
package/dist/index.js ADDED
@@ -0,0 +1,172 @@
1
+ // src/data-parts.ts
2
+ import { z } from "zod";
3
+ var errorSchema = z.object({
4
+ message: z.string()
5
+ });
6
+ var dataPartSchema = z.object({
7
+ "plugin-connection": z.object({ pluginId: z.string(), connectionId: z.string().optional() }),
8
+ /** Lifecycle of one plugin tool call, so the UI can name the in-flight call in its status line. */
9
+ "plugin-call": z.object({
10
+ pluginId: z.string(),
11
+ tool: z.string(),
12
+ status: z.enum(["loading", "done", "error"]),
13
+ error: errorSchema.optional()
14
+ }),
15
+ /** Written when the chat history was summarized before or during a turn. */
16
+ "context-compaction": z.object({
17
+ reason: z.enum(["threshold", "context_length_error"]),
18
+ status: z.enum(["done"]),
19
+ summarizedMessageCount: z.number()
20
+ }),
21
+ /** The agent's working plan; replaced in place as steps complete. */
22
+ plan: z.object({
23
+ explanation: z.string().optional(),
24
+ steps: z.array(
25
+ z.object({
26
+ status: z.enum(["pending", "in_progress", "completed"]),
27
+ step: z.string()
28
+ })
29
+ ),
30
+ updatedAt: z.string()
31
+ }),
32
+ /** A delegated subtask of an automation run. */
33
+ subtask: z.object({
34
+ error: errorSchema.optional(),
35
+ resultPreview: z.string().optional(),
36
+ status: z.enum(["running", "done", "error"]),
37
+ stepsUsed: z.number().optional(),
38
+ subtaskId: z.string(),
39
+ title: z.string()
40
+ }),
41
+ /** json-render patch lines, extracted from the assistant text by the stream pipeline. */
42
+ spec: z.union([
43
+ z.object({
44
+ type: z.literal("patch"),
45
+ patch: z.unknown()
46
+ }),
47
+ z.object({
48
+ type: z.literal("flat"),
49
+ spec: z.unknown()
50
+ }),
51
+ z.object({
52
+ type: z.literal("nested"),
53
+ spec: z.unknown()
54
+ })
55
+ ]),
56
+ "create-sandbox": z.object({
57
+ sandboxId: z.string().optional(),
58
+ status: z.enum(["loading", "done", "error"]),
59
+ error: errorSchema.optional()
60
+ }),
61
+ "generating-files": z.object({
62
+ paths: z.array(z.string()),
63
+ status: z.enum(["generating", "uploading", "uploaded", "done", "error"]),
64
+ error: errorSchema.optional()
65
+ }),
66
+ "run-artifact": z.object({
67
+ artifactId: z.string().optional(),
68
+ contentType: z.string().optional(),
69
+ error: errorSchema.optional(),
70
+ filename: z.string(),
71
+ kind: z.enum(["html", "pdf"]).optional(),
72
+ sizeBytes: z.number().optional(),
73
+ status: z.enum(["uploading", "done", "error"]),
74
+ /** Persistent public URL of the stored artifact. */
75
+ url: z.string().optional()
76
+ }),
77
+ "run-command": z.object({
78
+ sandboxId: z.string(),
79
+ commandId: z.string().optional(),
80
+ command: z.string(),
81
+ args: z.array(z.string()),
82
+ status: z.enum(["executing", "running", "waiting", "done", "error"]),
83
+ exitCode: z.number().optional(),
84
+ error: errorSchema.optional()
85
+ }),
86
+ "search-schema": z.object({
87
+ query: z.string().optional(),
88
+ status: z.enum(["loading", "done", "error"]),
89
+ error: errorSchema.optional()
90
+ }),
91
+ "web-search": z.object({
92
+ query: z.string(),
93
+ status: z.enum(["loading", "done", "error"]),
94
+ error: errorSchema.optional()
95
+ }),
96
+ "tool-delivery": z.object({
97
+ channelId: z.string(),
98
+ channelName: z.string(),
99
+ provider: z.enum(["slack", "teams"]),
100
+ status: z.enum(["loading", "done", "error"]),
101
+ error: errorSchema.optional()
102
+ }),
103
+ "validate-graphql": z.object({
104
+ status: z.enum(["loading", "valid", "invalid", "error"]),
105
+ errorCount: z.number().optional(),
106
+ error: errorSchema.optional()
107
+ }),
108
+ "execute-graphql": z.object({
109
+ operationType: z.enum(["query", "mutation"]).optional(),
110
+ status: z.enum(["loading", "done", "error"]),
111
+ error: errorSchema.optional()
112
+ }),
113
+ /** Emitted for proposals; the UI fetches the full proposal from the approvals API by id. */
114
+ "mutation-approval": z.object({
115
+ approvalId: z.string(),
116
+ affectedCount: z.number().nullable().optional(),
117
+ decidedBy: z.string().optional(),
118
+ operationsSummary: z.string(),
119
+ reason: z.string().optional(),
120
+ status: z.enum(["pending", "approved", "rejected", "expired", "cancelled", "executed", "error"]),
121
+ error: errorSchema.optional()
122
+ }),
123
+ "bulk-graphql-action": z.object({
124
+ changedItems: z.number().optional(),
125
+ failedItems: z.number().optional(),
126
+ jobId: z.string().optional(),
127
+ operationName: z.string(),
128
+ processedItems: z.number().optional(),
129
+ status: z.enum(["loading", "running", "done", "error"]),
130
+ totalItems: z.number().optional(),
131
+ error: errorSchema.optional()
132
+ }),
133
+ "update-memory": z.object({
134
+ status: z.enum(["loading", "done", "error"]),
135
+ error: errorSchema.optional()
136
+ }),
137
+ "load-skill": z.object({
138
+ /** True for skills attached to the automation, injected at run start rather than loaded on demand. */
139
+ attached: z.boolean().optional(),
140
+ skillName: z.string().optional(),
141
+ status: z.enum(["loading", "done", "error"]),
142
+ error: errorSchema.optional()
143
+ }),
144
+ /** Marker written by the run workflow for the trigger event so a run replays as a conversation. */
145
+ "user-message": z.object({
146
+ parts: z.array(z.unknown())
147
+ }),
148
+ /** Final report written by the run workflow when the agent finishes. */
149
+ "run-summary": z.object({
150
+ status: z.enum(["success", "skipped", "failed"]),
151
+ summary: z.string()
152
+ }),
153
+ /** A chat turn that ended with an error. */
154
+ "turn-error": z.object({
155
+ message: z.string()
156
+ }),
157
+ /** One follow-up instruction offered under a finished chat reply; clicking it fills the composer. */
158
+ "suggested-prompt": z.object({
159
+ prompt: z.string()
160
+ })
161
+ });
162
+ var DATA_PART_TYPES = Object.keys(dataPartSchema.shape);
163
+ function isDataPartType(type) {
164
+ return DATA_PART_TYPES.includes(type);
165
+ }
166
+ export {
167
+ DATA_PART_TYPES,
168
+ dataPartSchema,
169
+ errorSchema,
170
+ isDataPartType
171
+ };
172
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/data-parts.ts"],"sourcesContent":["import { z } from 'zod';\n\n/**\n * Custom `data-*` parts streamed by the Flexkit agent platform and rendered by\n * Studio. The server validates what it writes against these schemas and the\n * UI derives its part types from them, so the two can never drift.\n */\nexport const errorSchema = z.object({\n message: z.string(),\n});\n\nexport const dataPartSchema = z.object({\n 'plugin-connection': z.object({ pluginId: z.string(), connectionId: z.string().optional() }),\n /** Lifecycle of one plugin tool call, so the UI can name the in-flight call in its status line. */\n 'plugin-call': z.object({\n pluginId: z.string(),\n tool: z.string(),\n status: z.enum(['loading', 'done', 'error']),\n error: errorSchema.optional(),\n }),\n /** Written when the chat history was summarized before or during a turn. */\n 'context-compaction': z.object({\n reason: z.enum(['threshold', 'context_length_error']),\n status: z.enum(['done']),\n summarizedMessageCount: z.number(),\n }),\n /** The agent's working plan; replaced in place as steps complete. */\n plan: z.object({\n explanation: z.string().optional(),\n steps: z.array(\n z.object({\n status: z.enum(['pending', 'in_progress', 'completed']),\n step: z.string(),\n })\n ),\n updatedAt: z.string(),\n }),\n /** A delegated subtask of an automation run. */\n subtask: z.object({\n error: errorSchema.optional(),\n resultPreview: z.string().optional(),\n status: z.enum(['running', 'done', 'error']),\n stepsUsed: z.number().optional(),\n subtaskId: z.string(),\n title: z.string(),\n }),\n /** json-render patch lines, extracted from the assistant text by the stream pipeline. */\n spec: z.union([\n z.object({\n type: z.literal('patch'),\n patch: z.unknown(),\n }),\n z.object({\n type: z.literal('flat'),\n spec: z.unknown(),\n }),\n z.object({\n type: z.literal('nested'),\n spec: z.unknown(),\n }),\n ]),\n 'create-sandbox': z.object({\n sandboxId: z.string().optional(),\n status: z.enum(['loading', 'done', 'error']),\n error: errorSchema.optional(),\n }),\n 'generating-files': z.object({\n paths: z.array(z.string()),\n status: z.enum(['generating', 'uploading', 'uploaded', 'done', 'error']),\n error: errorSchema.optional(),\n }),\n 'run-artifact': z.object({\n artifactId: z.string().optional(),\n contentType: z.string().optional(),\n error: errorSchema.optional(),\n filename: z.string(),\n kind: z.enum(['html', 'pdf']).optional(),\n sizeBytes: z.number().optional(),\n status: z.enum(['uploading', 'done', 'error']),\n /** Persistent public URL of the stored artifact. */\n url: z.string().optional(),\n }),\n 'run-command': z.object({\n sandboxId: z.string(),\n commandId: z.string().optional(),\n command: z.string(),\n args: z.array(z.string()),\n status: z.enum(['executing', 'running', 'waiting', 'done', 'error']),\n exitCode: z.number().optional(),\n error: errorSchema.optional(),\n }),\n 'search-schema': z.object({\n query: z.string().optional(),\n status: z.enum(['loading', 'done', 'error']),\n error: errorSchema.optional(),\n }),\n 'web-search': z.object({\n query: z.string(),\n status: z.enum(['loading', 'done', 'error']),\n error: errorSchema.optional(),\n }),\n 'tool-delivery': z.object({\n channelId: z.string(),\n channelName: z.string(),\n provider: z.enum(['slack', 'teams']),\n status: z.enum(['loading', 'done', 'error']),\n error: errorSchema.optional(),\n }),\n 'validate-graphql': z.object({\n status: z.enum(['loading', 'valid', 'invalid', 'error']),\n errorCount: z.number().optional(),\n error: errorSchema.optional(),\n }),\n 'execute-graphql': z.object({\n operationType: z.enum(['query', 'mutation']).optional(),\n status: z.enum(['loading', 'done', 'error']),\n error: errorSchema.optional(),\n }),\n /** Emitted for proposals; the UI fetches the full proposal from the approvals API by id. */\n 'mutation-approval': z.object({\n approvalId: z.string(),\n affectedCount: z.number().nullable().optional(),\n decidedBy: z.string().optional(),\n operationsSummary: z.string(),\n reason: z.string().optional(),\n status: z.enum(['pending', 'approved', 'rejected', 'expired', 'cancelled', 'executed', 'error']),\n error: errorSchema.optional(),\n }),\n 'bulk-graphql-action': z.object({\n changedItems: z.number().optional(),\n failedItems: z.number().optional(),\n jobId: z.string().optional(),\n operationName: z.string(),\n processedItems: z.number().optional(),\n status: z.enum(['loading', 'running', 'done', 'error']),\n totalItems: z.number().optional(),\n error: errorSchema.optional(),\n }),\n 'update-memory': z.object({\n status: z.enum(['loading', 'done', 'error']),\n error: errorSchema.optional(),\n }),\n 'load-skill': z.object({\n /** True for skills attached to the automation, injected at run start rather than loaded on demand. */\n attached: z.boolean().optional(),\n skillName: z.string().optional(),\n status: z.enum(['loading', 'done', 'error']),\n error: errorSchema.optional(),\n }),\n /** Marker written by the run workflow for the trigger event so a run replays as a conversation. */\n 'user-message': z.object({\n parts: z.array(z.unknown()),\n }),\n /** Final report written by the run workflow when the agent finishes. */\n 'run-summary': z.object({\n status: z.enum(['success', 'skipped', 'failed']),\n summary: z.string(),\n }),\n /** A chat turn that ended with an error. */\n 'turn-error': z.object({\n message: z.string(),\n }),\n /** One follow-up instruction offered under a finished chat reply; clicking it fills the composer. */\n 'suggested-prompt': z.object({\n prompt: z.string(),\n }),\n});\n\nexport type DataPart = z.infer<typeof dataPartSchema>;\nexport type DataPartType = keyof DataPart;\n\nexport const DATA_PART_TYPES = Object.keys(dataPartSchema.shape) as DataPartType[];\n\nexport function isDataPartType(type: string): type is DataPartType {\n return (DATA_PART_TYPES as string[]).includes(type);\n}\n\n/** The `type` of a UI message part carrying this data part. */\nexport type DataPartMessageType = `data-${DataPartType}`;\n"],"mappings":";AAAA,SAAS,SAAS;AAOX,IAAM,cAAc,EAAE,OAAO;AAAA,EAClC,SAAS,EAAE,OAAO;AACpB,CAAC;AAEM,IAAM,iBAAiB,EAAE,OAAO;AAAA,EACrC,qBAAqB,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,GAAG,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAAA;AAAA,EAE3F,eAAe,EAAE,OAAO;AAAA,IACtB,UAAU,EAAE,OAAO;AAAA,IACnB,MAAM,EAAE,OAAO;AAAA,IACf,QAAQ,EAAE,KAAK,CAAC,WAAW,QAAQ,OAAO,CAAC;AAAA,IAC3C,OAAO,YAAY,SAAS;AAAA,EAC9B,CAAC;AAAA;AAAA,EAED,sBAAsB,EAAE,OAAO;AAAA,IAC7B,QAAQ,EAAE,KAAK,CAAC,aAAa,sBAAsB,CAAC;AAAA,IACpD,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC;AAAA,IACvB,wBAAwB,EAAE,OAAO;AAAA,EACnC,CAAC;AAAA;AAAA,EAED,MAAM,EAAE,OAAO;AAAA,IACb,aAAa,EAAE,OAAO,EAAE,SAAS;AAAA,IACjC,OAAO,EAAE;AAAA,MACP,EAAE,OAAO;AAAA,QACP,QAAQ,EAAE,KAAK,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,OAAO,EAAE,SAAS;AAAA,IAChC,OAAO,YAAY,SAAS;AAAA,EAC9B,CAAC;AAAA,EACD,iBAAiB,EAAE,OAAO;AAAA,IACxB,QAAQ,EAAE,KAAK,CAAC,WAAW,QAAQ,OAAO,CAAC;AAAA,IAC3C,OAAO,YAAY,SAAS;AAAA,EAC9B,CAAC;AAAA,EACD,cAAc,EAAE,OAAO;AAAA;AAAA,IAErB,UAAU,EAAE,QAAQ,EAAE,SAAS;AAAA,IAC/B,WAAW,EAAE,OAAO,EAAE,SAAS;AAAA,IAC/B,QAAQ,EAAE,KAAK,CAAC,WAAW,QAAQ,OAAO,CAAC;AAAA,IAC3C,OAAO,YAAY,SAAS;AAAA,EAC9B,CAAC;AAAA;AAAA,EAED,gBAAgB,EAAE,OAAO;AAAA,IACvB,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC;AAAA,EAC5B,CAAC;AAAA;AAAA,EAED,eAAe,EAAE,OAAO;AAAA,IACtB,QAAQ,EAAE,KAAK,CAAC,WAAW,WAAW,QAAQ,CAAC;AAAA,IAC/C,SAAS,EAAE,OAAO;AAAA,EACpB,CAAC;AAAA;AAAA,EAED,cAAc,EAAE,OAAO;AAAA,IACrB,SAAS,EAAE,OAAO;AAAA,EACpB,CAAC;AAAA;AAAA,EAED,oBAAoB,EAAE,OAAO;AAAA,IAC3B,QAAQ,EAAE,OAAO;AAAA,EACnB,CAAC;AACH,CAAC;AAKM,IAAM,kBAAkB,OAAO,KAAK,eAAe,KAAK;AAExD,SAAS,eAAe,MAAoC;AACjE,SAAQ,gBAA6B,SAAS,IAAI;AACpD;","names":[]}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@flexkit/agent-protocol",
3
+ "version": "0.2.0",
4
+ "description": "Schemas and types shared between the Flexkit agent platform and its Studio UI: streamed data parts, run, approval and chat DTOs.",
5
+ "keywords": [
6
+ "flexkit",
7
+ "agent",
8
+ "automations",
9
+ "protocol"
10
+ ],
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/flexkit-io/flexkit",
19
+ "directory": "packages/agent-protocol"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js",
25
+ "default": "./dist/index.js"
26
+ }
27
+ },
28
+ "sideEffects": false,
29
+ "files": [
30
+ "dist/**"
31
+ ],
32
+ "devDependencies": {
33
+ "@types/node": "^20.5.2",
34
+ "eslint": "^9.0.0",
35
+ "tsup": "8.5.1",
36
+ "typescript": "^5.3.3",
37
+ "zod": "4.4.3",
38
+ "eslint-config-custom": "0.0.0",
39
+ "tsconfig": "0.0.0"
40
+ },
41
+ "peerDependencies": {
42
+ "zod": "^4.0.0"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "scripts": {
48
+ "build": "tsup src/index.ts --format esm --dts --sourcemap",
49
+ "dev": "tsup src/index.ts --format esm --dts --watch src",
50
+ "lint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\"",
51
+ "test": "tsup --config tests/tsup.config.ts && node --test build/tests/data-parts.test.js",
52
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf build"
53
+ }
54
+ }