@hachej/boring-agent 0.1.64 → 0.1.65

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.
@@ -1,377 +0,0 @@
1
- // src/shared/tool-ui.ts
2
- function isRecord(value) {
3
- return typeof value === "object" && value !== null && !Array.isArray(value);
4
- }
5
- function isToolUiMetadata(value) {
6
- if (!isRecord(value)) return false;
7
- return (value.rendererId === void 0 || typeof value.rendererId === "string") && (value.displayGroup === void 0 || typeof value.displayGroup === "string") && (value.icon === void 0 || typeof value.icon === "string");
8
- }
9
- function sanitizeToolUiMetadata(value) {
10
- if (!isToolUiMetadata(value)) return void 0;
11
- const rendererId = value.rendererId?.trim();
12
- const displayGroup = value.displayGroup?.trim();
13
- const icon = value.icon?.trim();
14
- return {
15
- ...rendererId ? { rendererId } : {},
16
- ...displayGroup ? { displayGroup } : {},
17
- ...icon ? { icon } : {},
18
- ...value.details !== void 0 ? { details: value.details } : {}
19
- };
20
- }
21
- function extractToolUiMetadata(output) {
22
- if (!isRecord(output)) return void 0;
23
- const details = output.details;
24
- if (!isRecord(details)) return void 0;
25
- return sanitizeToolUiMetadata(details.ui);
26
- }
27
-
28
- // src/shared/error-codes.ts
29
- import { z } from "zod";
30
- var ErrorCode = z.enum([
31
- // Auth / config
32
- "UNAUTHORIZED",
33
- "MISSING_API_KEY",
34
- "INVALID_API_KEY",
35
- "OIDC_REFRESH_FAILED",
36
- "VERCEL_AUTH_FAILED",
37
- "CONFIG_INVALID",
38
- // Workspace / path
39
- "PATH_ESCAPE",
40
- "PATH_ABSOLUTE",
41
- "PATH_NULL_BYTE",
42
- "PATH_SYMLINK_ESCAPE",
43
- "PATH_NOT_FOUND",
44
- "PATH_NOT_WRITABLE",
45
- "WORKSPACE_UNINITIALIZED",
46
- "WORKSPACE_NOT_READY",
47
- // Agent runtime / provisioning
48
- "AGENT_RUNTIME_NOT_READY",
49
- "RUNTIME_PROVISIONING_FAILED",
50
- "RUNTIME_PROVISIONING_LOCKED",
51
- // Sandbox / exec
52
- "BWRAP_UNAVAILABLE",
53
- "BWRAP_TIMEOUT",
54
- "OUTPUT_TRUNCATED",
55
- "SANDBOX_NOT_READY",
56
- "SANDBOX_EXPIRED",
57
- "VERCEL_API_ERROR",
58
- "REMOTE_WORKER_TIMEOUT",
59
- "REMOTE_WORKER_STREAM_CLOSED",
60
- "CIRCUIT_OPEN",
61
- "ABORTED",
62
- // Billing / metering
63
- "PAYMENT_REQUIRED",
64
- // Session / bridge
65
- "SESSION_NOT_FOUND",
66
- "SESSION_LOCKED",
67
- "STREAM_BUFFER_EVICTED",
68
- "CURSOR_OUT_OF_RANGE",
69
- "BRIDGE_COMMAND_INVALID",
70
- // Tool
71
- "TOOL_NOT_FOUND",
72
- "TOOL_INVALID_INPUT",
73
- "TOOL_EXECUTION_ERROR",
74
- // Plugin
75
- "PLUGIN_LOAD_FAILED",
76
- "PLUGIN_NAME_COLLISION",
77
- "PLUGIN_RUNTIME_REVISION_MISMATCH",
78
- "PLUGIN_RUNTIME_PRIVATE_FILE",
79
- "PLUGIN_RUNTIME_UNSAFE_IMPORT",
80
- "PLUGIN_RUNTIME_TRANSFORM_FAILED",
81
- "RUNTIME_PLUGIN_NOT_FOUND",
82
- "RUNTIME_PLUGIN_ROUTE_NOT_FOUND",
83
- "RUNTIME_PLUGIN_HANDLER_FAILED",
84
- "RUNTIME_PLUGIN_LOAD_FAILED",
85
- "RUNTIME_PLUGIN_RESPONSE_UNSUPPORTED",
86
- // Runtime provisioning
87
- "PROVISIONING_LAYOUT_FAILED",
88
- "PROVISIONING_SKILLS_FAILED",
89
- "PROVISIONING_TEMPLATES_FAILED",
90
- "PROVISIONING_NODE_PREFLIGHT_FAILED",
91
- "PROVISIONING_NPM_INSTALL_FAILED",
92
- "PROVISIONING_UV_BOOTSTRAP_FAILED",
93
- "PROVISIONING_UV_INSTALL_FAILED",
94
- "PROVISIONING_ARTIFACT_FAILED",
95
- // Internal
96
- "INTERNAL_ERROR"
97
- ]);
98
- var ERROR_CODES = ErrorCode.options;
99
- var ApiErrorPayloadSchema = z.object({
100
- code: ErrorCode,
101
- message: z.string().min(1),
102
- details: z.record(z.unknown()).optional()
103
- });
104
- var ApiErrorResponseSchema = z.object({
105
- error: ApiErrorPayloadSchema
106
- });
107
- var ErrorLogFieldsSchema = z.object({
108
- level: z.enum(["warn", "error"]),
109
- code: ErrorCode,
110
- prefix: z.string().min(1),
111
- msg: z.string().min(1)
112
- }).catchall(z.unknown());
113
-
114
- // src/shared/chat/piChatSchemas.ts
115
- import { z as z2 } from "zod";
116
- var nonEmptyString = z2.string().min(1);
117
- var seqNumber = z2.number().int().nonnegative();
118
- var ShallowPayloadSchema = z2.union([
119
- z2.string(),
120
- z2.number(),
121
- z2.boolean(),
122
- z2.null(),
123
- z2.array(z2.unknown()),
124
- z2.record(z2.unknown())
125
- ]);
126
- function isRecord2(value) {
127
- return typeof value === "object" && value !== null && !Array.isArray(value);
128
- }
129
- var ToolUiMetadataSchema = z2.object({
130
- rendererId: z2.string().optional(),
131
- displayGroup: z2.string().optional(),
132
- icon: z2.string().optional(),
133
- details: z2.unknown().optional()
134
- });
135
- function sanitizeToolUiMetadata2(value) {
136
- if (!isRecord2(value)) return void 0;
137
- const parsed = ToolUiMetadataSchema.safeParse(value);
138
- return parsed.success ? parsed.data : void 0;
139
- }
140
- var OptionalToolUiMetadataSchema = z2.preprocess(
141
- (value) => sanitizeToolUiMetadata2(value),
142
- ToolUiMetadataSchema.optional()
143
- );
144
- var ChatErrorSchema = z2.object({
145
- code: ErrorCode,
146
- message: nonEmptyString,
147
- retryable: z2.boolean().optional(),
148
- details: z2.unknown().optional()
149
- });
150
- var BoringChatPartSchema = z2.discriminatedUnion("type", [
151
- z2.object({ type: z2.literal("text"), id: z2.string().optional(), text: z2.string() }),
152
- z2.object({
153
- type: z2.literal("reasoning"),
154
- id: nonEmptyString,
155
- text: z2.string(),
156
- state: z2.enum(["streaming", "done"]).optional()
157
- }),
158
- z2.object({
159
- type: z2.literal("tool-call"),
160
- id: nonEmptyString,
161
- toolName: nonEmptyString,
162
- input: z2.unknown().optional(),
163
- state: z2.enum(["input-streaming", "input-available", "output-available", "output-error", "aborted"]),
164
- output: z2.unknown().optional(),
165
- errorText: z2.string().optional(),
166
- ui: OptionalToolUiMetadataSchema
167
- }),
168
- z2.object({
169
- type: z2.literal("file"),
170
- id: z2.string().optional(),
171
- filename: z2.string().optional(),
172
- mediaType: z2.string().optional(),
173
- url: z2.string().optional(),
174
- path: z2.string().optional(),
175
- filesystem: z2.string().optional()
176
- }),
177
- z2.object({
178
- type: z2.literal("notice"),
179
- id: z2.string().optional(),
180
- level: z2.enum(["info", "warning", "error"]),
181
- text: z2.string()
182
- })
183
- ]);
184
- var BoringChatMessageSchema = z2.object({
185
- id: nonEmptyString,
186
- role: z2.enum(["user", "assistant", "system"]),
187
- status: z2.enum(["pending", "streaming", "done", "aborted", "error"]).optional(),
188
- parts: z2.array(BoringChatPartSchema),
189
- createdAt: z2.string().optional(),
190
- clientNonce: z2.string().optional(),
191
- clientSeq: z2.number().int().nonnegative().optional(),
192
- piEntryId: z2.string().optional(),
193
- turnId: z2.string().optional()
194
- });
195
- var QueuedUserMessageSchema = z2.object({
196
- id: nonEmptyString,
197
- kind: z2.literal("followup"),
198
- clientNonce: z2.string().optional(),
199
- clientSeq: z2.number().int().nonnegative().optional(),
200
- displayText: z2.string(),
201
- createdAt: z2.string().optional()
202
- });
203
- var PiChatStatusSchema = z2.enum(["idle", "hydrating", "submitted", "streaming", "aborting", "error"]);
204
- var PiChatSnapshotSchema = z2.object({
205
- protocolVersion: z2.literal(1),
206
- sessionId: nonEmptyString,
207
- seq: seqNumber,
208
- status: PiChatStatusSchema,
209
- activeTurnId: z2.string().optional(),
210
- messages: z2.array(BoringChatMessageSchema),
211
- queue: z2.object({ followUps: z2.array(QueuedUserMessageSchema) }),
212
- followUpMode: z2.literal("one-at-a-time"),
213
- error: ChatErrorSchema.optional()
214
- });
215
- var baseEvent = z2.object({ seq: seqNumber });
216
- var PiChatEventSchema = z2.discriminatedUnion("type", [
217
- baseEvent.extend({ type: z2.literal("agent-start"), turnId: nonEmptyString }),
218
- baseEvent.extend({ type: z2.literal("agent-end"), turnId: nonEmptyString, status: z2.enum(["ok", "aborted", "error"]), willRetry: z2.boolean().optional() }),
219
- baseEvent.extend({
220
- type: z2.literal("message-start"),
221
- messageId: nonEmptyString,
222
- role: z2.enum(["user", "assistant"]),
223
- clientNonce: z2.string().optional(),
224
- clientSeq: z2.number().int().nonnegative().optional(),
225
- createdAt: z2.string().optional(),
226
- text: z2.string().optional(),
227
- files: z2.array(BoringChatPartSchema).optional()
228
- }),
229
- baseEvent.extend({
230
- type: z2.literal("message-delta"),
231
- messageId: nonEmptyString,
232
- partId: nonEmptyString,
233
- kind: z2.enum(["text", "reasoning"]),
234
- delta: z2.string()
235
- }),
236
- baseEvent.extend({
237
- type: z2.literal("message-part-end"),
238
- messageId: nonEmptyString,
239
- partId: nonEmptyString,
240
- kind: z2.enum(["text", "reasoning"]),
241
- text: z2.string()
242
- }),
243
- baseEvent.extend({ type: z2.literal("message-end"), messageId: nonEmptyString, final: BoringChatMessageSchema }),
244
- baseEvent.extend({
245
- type: z2.literal("tool-call"),
246
- messageId: nonEmptyString,
247
- toolCallId: nonEmptyString,
248
- toolName: nonEmptyString,
249
- input: ShallowPayloadSchema,
250
- ui: OptionalToolUiMetadataSchema
251
- }),
252
- baseEvent.extend({
253
- type: z2.literal("tool-result"),
254
- messageId: nonEmptyString,
255
- toolCallId: nonEmptyString,
256
- output: ShallowPayloadSchema,
257
- isError: z2.boolean().optional(),
258
- errorText: z2.string().optional(),
259
- ui: OptionalToolUiMetadataSchema
260
- }),
261
- baseEvent.extend({ type: z2.literal("queue-updated"), queue: z2.object({ followUps: z2.array(QueuedUserMessageSchema) }) }),
262
- baseEvent.extend({
263
- type: z2.literal("followup-consumed"),
264
- clientNonce: z2.string().optional(),
265
- clientSeq: z2.number().int().nonnegative().optional(),
266
- messageId: nonEmptyString
267
- }),
268
- baseEvent.extend({ type: z2.literal("file-changed"), path: nonEmptyString, changeType: nonEmptyString }),
269
- baseEvent.extend({ type: z2.literal("ui-command"), command: ShallowPayloadSchema, displayOnly: z2.literal(true) }),
270
- baseEvent.extend({ type: z2.literal("usage"), usage: ShallowPayloadSchema }),
271
- baseEvent.extend({
272
- type: z2.literal("auto-retry-start"),
273
- attempt: z2.number().int().nonnegative(),
274
- maxAttempts: z2.number().int().nonnegative(),
275
- delayMs: z2.number().int().nonnegative(),
276
- errorMessage: z2.string()
277
- }),
278
- baseEvent.extend({
279
- type: z2.literal("auto-retry-end"),
280
- success: z2.boolean(),
281
- attempt: z2.number().int().nonnegative(),
282
- finalError: z2.string().optional()
283
- }),
284
- baseEvent.extend({ type: z2.literal("error"), turnId: z2.string().optional(), retryable: z2.boolean().optional(), error: ChatErrorSchema })
285
- ]);
286
- var PiChatHeartbeatFrameSchema = z2.object({ type: z2.literal("heartbeat"), now: z2.string() });
287
- var PiChatStreamFrameSchema = z2.union([PiChatEventSchema, PiChatHeartbeatFrameSchema]);
288
- var ChatModelSelectionSchema = z2.object({
289
- provider: nonEmptyString,
290
- id: nonEmptyString
291
- });
292
- var ThinkingLevelSchema = z2.enum(["off", "low", "medium", "high"]);
293
- var ChatAttachmentPayloadSchema = z2.object({
294
- filename: z2.string().optional(),
295
- mediaType: z2.string().optional(),
296
- url: nonEmptyString,
297
- path: z2.string().optional()
298
- });
299
- var PromptPayloadSchema = z2.object({
300
- message: z2.string().min(1).max(1e6),
301
- displayMessage: z2.string().min(1).max(1e6).optional(),
302
- clientNonce: nonEmptyString.max(128),
303
- model: ChatModelSelectionSchema.optional(),
304
- thinkingLevel: ThinkingLevelSchema.optional(),
305
- attachments: z2.array(ChatAttachmentPayloadSchema).max(20).optional()
306
- });
307
- var FollowUpPayloadSchema = z2.object({
308
- message: z2.string().min(1).max(1e6),
309
- displayMessage: z2.string().min(1).max(1e6).optional(),
310
- clientNonce: nonEmptyString.max(128),
311
- clientSeq: z2.number().int().nonnegative()
312
- });
313
- var QueueClearPayloadSchema = z2.preprocess(
314
- (value) => value ?? {},
315
- z2.object({
316
- clientNonce: nonEmptyString.max(128).optional(),
317
- clientSeq: z2.number().int().nonnegative().optional()
318
- }).strict()
319
- );
320
- var InterruptPayloadSchema = z2.object({}).strict();
321
- var StopPayloadSchema = z2.object({}).strict();
322
- var CommandReceiptSchema = z2.object({
323
- accepted: z2.literal(true),
324
- cursor: seqNumber
325
- });
326
- var PromptReceiptSchema = CommandReceiptSchema.extend({
327
- clientNonce: nonEmptyString,
328
- duplicate: z2.boolean().optional()
329
- });
330
- var FollowUpReceiptSchema = CommandReceiptSchema.extend({
331
- clientNonce: nonEmptyString,
332
- clientSeq: z2.number().int().nonnegative(),
333
- queued: z2.literal(true),
334
- duplicate: z2.boolean().optional()
335
- });
336
- var QueueClearReceiptSchema = CommandReceiptSchema.extend({
337
- cleared: z2.number().int().nonnegative()
338
- });
339
- var StopReceiptSchema = CommandReceiptSchema.extend({
340
- stopped: z2.boolean(),
341
- clearedQueue: z2.array(QueuedUserMessageSchema)
342
- });
343
-
344
- export {
345
- isToolUiMetadata,
346
- sanitizeToolUiMetadata,
347
- extractToolUiMetadata,
348
- ErrorCode,
349
- ERROR_CODES,
350
- ApiErrorPayloadSchema,
351
- ApiErrorResponseSchema,
352
- ErrorLogFieldsSchema,
353
- ToolUiMetadataSchema,
354
- sanitizeToolUiMetadata2,
355
- ChatErrorSchema,
356
- BoringChatPartSchema,
357
- BoringChatMessageSchema,
358
- QueuedUserMessageSchema,
359
- PiChatStatusSchema,
360
- PiChatSnapshotSchema,
361
- PiChatEventSchema,
362
- PiChatHeartbeatFrameSchema,
363
- PiChatStreamFrameSchema,
364
- ChatModelSelectionSchema,
365
- ThinkingLevelSchema,
366
- ChatAttachmentPayloadSchema,
367
- PromptPayloadSchema,
368
- FollowUpPayloadSchema,
369
- QueueClearPayloadSchema,
370
- InterruptPayloadSchema,
371
- StopPayloadSchema,
372
- CommandReceiptSchema,
373
- PromptReceiptSchema,
374
- FollowUpReceiptSchema,
375
- QueueClearReceiptSchema,
376
- StopReceiptSchema
377
- };