@hachej/boring-agent 0.1.80 → 0.1.82

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.
@@ -2,14 +2,16 @@ import {
2
2
  AgentDefinitionValidationError,
3
3
  AgentDeploymentValidationError,
4
4
  OpaqueRefSchema,
5
+ SchemaValidationError,
5
6
  Sha256DigestSchema,
6
7
  createAgentAssetDigest,
7
8
  createAgentDefinitionDigest,
8
9
  createAgentDeploymentDigest,
10
+ formatPath,
9
11
  validateAgentDefinition,
10
12
  validateAgentDeployment,
11
13
  validateTool
12
- } from "../chunk-CUF7ELFO.js";
14
+ } from "../chunk-WODTQBXR.js";
13
15
  import {
14
16
  AGENT_NOT_IMPLEMENTED_UNTIL_T1,
15
17
  AgentNotImplementedError,
@@ -46,12 +48,13 @@ import {
46
48
  extractToolUiMetadata,
47
49
  isToolUiMetadata,
48
50
  sanitizeToolUiMetadata2 as sanitizeToolUiMetadata
49
- } from "../chunk-UJQXCOHR.js";
51
+ } from "../chunk-DC3S7SZG.js";
50
52
  import {
51
53
  noopTelemetry,
52
54
  safeCapture
53
55
  } from "../chunk-AQBXNPMD.js";
54
56
  import {
57
+ AgentConsumptionErrorCode,
55
58
  AgentDefinitionErrorCode,
56
59
  AgentDeploymentErrorCode,
57
60
  ApiErrorPayloadSchema,
@@ -59,7 +62,7 @@ import {
59
62
  ERROR_CODES,
60
63
  ErrorCode,
61
64
  ErrorLogFieldsSchema
62
- } from "../chunk-CCNXYCD5.js";
65
+ } from "../chunk-PG2WOJ22.js";
63
66
 
64
67
  // src/shared/config-schema.ts
65
68
  import { z } from "zod";
@@ -124,15 +127,154 @@ var PI_AGENT_RUNTIME_CAPABILITIES = {
124
127
  nativeFollowUp: true,
125
128
  aiSdkOwnsHistory: false
126
129
  };
130
+
131
+ // src/shared/agent-consumption.ts
132
+ import { z as z2 } from "zod";
133
+ var nonEmptyString = z2.string().min(1);
134
+ var TASK_STATES = [
135
+ "submitted",
136
+ "working",
137
+ "input-required",
138
+ "completed",
139
+ "failed",
140
+ "canceled",
141
+ "rejected"
142
+ ];
143
+ var TaskStateSchema = z2.enum(TASK_STATES);
144
+ var TASK_TRANSITIONS = {
145
+ submitted: ["working", "rejected", "canceled"],
146
+ working: ["input-required", "completed", "failed", "canceled", "rejected"],
147
+ "input-required": ["working", "canceled"],
148
+ completed: [],
149
+ failed: [],
150
+ canceled: [],
151
+ rejected: []
152
+ };
153
+ function isValidTaskTransition(from, to) {
154
+ return TASK_TRANSITIONS[from].includes(to);
155
+ }
156
+ function assertValidTransition(from, to) {
157
+ if (!isValidTaskTransition(from, to)) {
158
+ throw new AgentConsumptionValidationError({
159
+ code: AgentConsumptionErrorCode.enum.AGENT_CONSUMPTION_INVALID_TRANSITION,
160
+ field: "state",
161
+ message: `invalid task state transition: '${from}' -> '${to}'`
162
+ });
163
+ }
164
+ }
165
+ var PrincipalRefSchema = z2.object({
166
+ userId: nonEmptyString,
167
+ workspaceId: nonEmptyString
168
+ }).strict();
169
+ var AgentRefSchema = z2.object({
170
+ agentId: nonEmptyString,
171
+ deploymentId: nonEmptyString.optional()
172
+ }).strict();
173
+ function agentRefEquals(a, b) {
174
+ return a.agentId === b.agentId && (a.deploymentId ?? null) === (b.deploymentId ?? null);
175
+ }
176
+ var ArtifactRefSchema = z2.object({
177
+ artifactId: nonEmptyString,
178
+ name: z2.string().optional(),
179
+ mimeType: nonEmptyString,
180
+ uri: nonEmptyString
181
+ }).strict();
182
+ var PartSchema = z2.discriminatedUnion("type", [
183
+ z2.object({ type: z2.literal("text"), text: z2.string() }).strict(),
184
+ z2.object({ type: z2.literal("file"), file: ArtifactRefSchema }).strict(),
185
+ z2.object({ type: z2.literal("data"), mimeType: nonEmptyString, data: z2.unknown() }).strict()
186
+ ]);
187
+ var AgentMessageSchema = z2.object({
188
+ role: z2.enum(["consumer", "agent"]),
189
+ parts: z2.array(PartSchema),
190
+ ts: nonEmptyString
191
+ }).strict();
192
+ var AgentTaskSchema = z2.object({
193
+ id: nonEmptyString,
194
+ contextId: nonEmptyString,
195
+ state: TaskStateSchema,
196
+ messages: z2.array(AgentMessageSchema),
197
+ artifacts: z2.array(ArtifactRefSchema),
198
+ principal: PrincipalRefSchema,
199
+ actor: AgentRefSchema.optional(),
200
+ schemaVersion: z2.literal("1"),
201
+ createdAt: nonEmptyString,
202
+ updatedAt: nonEmptyString
203
+ }).strict();
204
+ function schemaMismatchIssues(issues) {
205
+ return issues.map((issue) => {
206
+ const field = formatPath(issue.path);
207
+ return {
208
+ code: AgentConsumptionErrorCode.enum.AGENT_CONSUMPTION_SCHEMA_MISMATCH,
209
+ field,
210
+ message: field === "<root>" ? issue.message : `${field} ${issue.message}`
211
+ };
212
+ });
213
+ }
214
+ function validateAgentTask(raw) {
215
+ const result = AgentTaskSchema.safeParse(raw);
216
+ if (!result.success) {
217
+ return { valid: false, issues: schemaMismatchIssues(result.error.issues) };
218
+ }
219
+ return { valid: true, value: result.data };
220
+ }
221
+ var AgentConsumptionValidationError = class extends SchemaValidationError {
222
+ constructor(issue) {
223
+ super(issue);
224
+ this.name = "AgentConsumptionValidationError";
225
+ }
226
+ };
227
+ var ConsumptionGuardsSchema = z2.object({
228
+ maxDepth: z2.number().int().positive(),
229
+ inputRequiredTimeoutMs: z2.number().int().positive()
230
+ }).strict();
231
+ function validateConsumptionGuards(raw) {
232
+ const result = ConsumptionGuardsSchema.safeParse(raw);
233
+ if (!result.success) {
234
+ return { valid: false, issues: schemaMismatchIssues(result.error.issues) };
235
+ }
236
+ return { valid: true, value: result.data };
237
+ }
238
+ function detectConsumptionCycle(chain, next) {
239
+ return chain.some((ref) => agentRefEquals(ref, next));
240
+ }
241
+ function assertNoConsumptionCycle(chain, next) {
242
+ if (detectConsumptionCycle(chain, next)) {
243
+ const label = next.deploymentId ? `${next.agentId}@${next.deploymentId}` : next.agentId;
244
+ throw new AgentConsumptionValidationError({
245
+ code: AgentConsumptionErrorCode.enum.AGENT_CONSUMPTION_CYCLE_DETECTED,
246
+ field: "actor",
247
+ message: `consumption cycle detected: agent '${label}' already present in the delegation chain`
248
+ });
249
+ }
250
+ }
251
+ function isWithinConsumptionDepth(chain, guards) {
252
+ return chain.length < guards.maxDepth;
253
+ }
254
+ function assertWithinConsumptionDepth(chain, guards) {
255
+ if (!isWithinConsumptionDepth(chain, guards)) {
256
+ throw new AgentConsumptionValidationError({
257
+ code: AgentConsumptionErrorCode.enum.AGENT_CONSUMPTION_DEPTH_EXCEEDED,
258
+ field: "depth",
259
+ message: `consumption depth exceeded: chain length ${chain.length} >= max depth ${guards.maxDepth}`
260
+ });
261
+ }
262
+ }
127
263
  export {
128
264
  AGENT_NOT_IMPLEMENTED_UNTIL_T1,
265
+ AgentConsumptionErrorCode,
266
+ AgentConsumptionValidationError,
129
267
  AgentDefinitionErrorCode,
130
268
  AgentDefinitionValidationError,
131
269
  AgentDeploymentErrorCode,
132
270
  AgentDeploymentValidationError,
271
+ AgentMessageSchema,
133
272
  AgentNotImplementedError,
273
+ AgentRefSchema,
274
+ AgentTaskSchema,
134
275
  ApiErrorPayloadSchema,
135
276
  ApiErrorResponseSchema,
277
+ ArtifactRefSchema,
136
278
  BoringChatMessageSchema,
137
279
  BoringChatPartSchema,
138
280
  ChatAttachmentPayloadSchema,
@@ -140,6 +282,7 @@ export {
140
282
  ChatModelSelectionSchema,
141
283
  CommandReceiptSchema,
142
284
  ConfigSchema,
285
+ ConsumptionGuardsSchema,
143
286
  DEFAULT_AGENT_RUNTIME_CAPABILITIES,
144
287
  ERROR_CODES,
145
288
  EnvSchema,
@@ -150,11 +293,13 @@ export {
150
293
  InterruptPayloadSchema,
151
294
  OpaqueRefSchema,
152
295
  PI_AGENT_RUNTIME_CAPABILITIES,
296
+ PartSchema,
153
297
  PiChatEventSchema,
154
298
  PiChatHeartbeatFrameSchema,
155
299
  PiChatSnapshotSchema,
156
300
  PiChatStatusSchema,
157
301
  PiChatStreamFrameSchema,
302
+ PrincipalRefSchema,
158
303
  PromptPayloadSchema,
159
304
  PromptReceiptSchema,
160
305
  QueueClearPayloadSchema,
@@ -164,21 +309,32 @@ export {
164
309
  Sha256DigestSchema,
165
310
  StopPayloadSchema,
166
311
  StopReceiptSchema,
312
+ TASK_STATES,
313
+ TaskStateSchema,
167
314
  ThinkingLevelSchema,
168
315
  ToolUiMetadataSchema,
169
316
  WORKSPACE_AGENT_PLUGINS_RELOADED_EVENT,
170
317
  WORKSPACE_COMMAND_NOTIFY_EVENT,
318
+ agentRefEquals,
319
+ assertNoConsumptionCycle,
320
+ assertValidTransition,
321
+ assertWithinConsumptionDepth,
171
322
  createAgentAssetDigest,
172
323
  createAgentDefinitionDigest,
173
324
  createAgentDeploymentDigest,
325
+ detectConsumptionCycle,
174
326
  extractToolUiMetadata,
175
327
  isToolUiMetadata,
328
+ isValidTaskTransition,
329
+ isWithinConsumptionDepth,
176
330
  noopTelemetry,
177
331
  safeCapture,
178
332
  sanitizeToolUiMetadata,
179
333
  sessionStreamPath,
180
334
  validateAgentDefinition,
181
335
  validateAgentDeployment,
336
+ validateAgentTask,
182
337
  validateConfig,
338
+ validateConsumptionGuards,
183
339
  validateTool
184
340
  };
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { A as AgentDefinitionErrorCode, p as AgentDeploymentErrorCode, z as InterruptReceipt, i as StopReceipt } from './piChatEvent-CpoTZau1.js';
3
- import { p as AgentSendInput, j as AgentEvent } from './harness-BZW5Jiy3.js';
2
+ import { p as AgentDefinitionErrorCode, q as AgentDeploymentErrorCode, D as InterruptReceipt, i as StopReceipt } from './piChatEvent-3pFPXYPx.js';
3
+ import { p as AgentSendInput, j as AgentEvent } from './harness-C53mjCcq.js';
4
4
 
5
5
  interface SandboxHandleRecord {
6
6
  workspaceId: string;
@@ -21,6 +21,26 @@ interface FileSearch {
21
21
  }
22
22
 
23
23
  type Sha256Digest = `sha256:${string}`;
24
+
25
+ interface AgentSchemaIssue<Code extends string> {
26
+ code: Code;
27
+ field: string;
28
+ message: string;
29
+ }
30
+ type AgentSchemaValidationResult<T, Code extends string> = {
31
+ valid: true;
32
+ value: T;
33
+ } | {
34
+ valid: false;
35
+ issues: AgentSchemaIssue<Code>[];
36
+ };
37
+ declare abstract class SchemaValidationError<Code extends string> extends Error {
38
+ readonly code: "CONFIG_INVALID";
39
+ readonly field: string;
40
+ readonly validationCode: Code;
41
+ constructor(issue: AgentSchemaIssue<Code>);
42
+ }
43
+
24
44
  interface AgentDefinition {
25
45
  schemaVersion: 1;
26
46
  definitionId: string;
@@ -56,33 +76,15 @@ interface CompiledAgentBundle {
56
76
  readonly definitionDigest: Sha256Digest;
57
77
  readonly assets: readonly Readonly<AgentDefinitionDigestAsset>[];
58
78
  }
59
- interface AgentSchemaIssue<Code extends string> {
60
- code: Code;
61
- field: string;
62
- message: string;
63
- }
64
- type AgentSchemaValidationResult<T, Code extends string> = {
65
- valid: true;
66
- value: T;
67
- } | {
68
- valid: false;
69
- issues: AgentSchemaIssue<Code>[];
70
- };
71
79
  declare const OpaqueRefSchema: z.ZodEffects<z.ZodString, string, string>;
72
80
  declare const Sha256DigestSchema: z.ZodEffects<z.ZodString, `sha256:${string}`, string>;
73
81
  declare function validateAgentDefinition(raw: unknown): AgentSchemaValidationResult<AgentDefinition, AgentDefinitionErrorCode>;
74
82
  declare function validateAgentDeployment(raw: unknown): AgentSchemaValidationResult<AgentDeployment, AgentDeploymentErrorCode>;
75
83
  declare function createAgentAssetDigest(content: string): Promise<Sha256Digest>;
76
- declare class AgentDefinitionValidationError extends Error {
77
- readonly code: "CONFIG_INVALID";
78
- readonly field: string;
79
- readonly validationCode: AgentDefinitionErrorCode;
84
+ declare class AgentDefinitionValidationError extends SchemaValidationError<AgentDefinitionErrorCode> {
80
85
  constructor(issue: AgentSchemaIssue<AgentDefinitionErrorCode>);
81
86
  }
82
- declare class AgentDeploymentValidationError extends Error {
83
- readonly code: "CONFIG_INVALID";
84
- readonly field: string;
85
- readonly validationCode: AgentDeploymentErrorCode;
87
+ declare class AgentDeploymentValidationError extends SchemaValidationError<AgentDeploymentErrorCode> {
86
88
  constructor(issue: AgentSchemaIssue<AgentDeploymentErrorCode>);
87
89
  }
88
90
  declare function createAgentDefinitionDigest(input: {
@@ -146,4 +148,4 @@ interface WorkspaceAgentDispatcher {
146
148
  stop(sessionId: string): Promise<StopReceipt>;
147
149
  }
148
150
 
149
- export { type AgentDeployment as A, type CompiledAgentBundle as C, type FileSearch as F, OpaqueRefSchema as O, type PluginRestartWarning as P, type SandboxHandleStore as S, type WorkspaceAgentDispatcherContext as W, type SandboxHandleRecord as a, type Sha256Digest as b, type WorkspaceAgentDispatcher as c, type AgentDefinition as d, type AgentDefinitionDigestAsset as e, type AgentDefinitionReference as f, AgentDefinitionValidationError as g, AgentDeploymentValidationError as h, type AgentSchemaIssue as i, type AgentSchemaValidationResult as j, type CommandNotifyPayload as k, type CompiledAgentDefinition as l, Sha256DigestSchema as m, WORKSPACE_AGENT_PLUGINS_RELOADED_EVENT as n, WORKSPACE_COMMAND_NOTIFY_EVENT as o, type WorkspaceAgentDispatcherSendInput as p, createAgentAssetDigest as q, createAgentDefinitionDigest as r, createAgentDeploymentDigest as s, validateAgentDeployment as t, validateAgentDefinition as v };
151
+ export { type AgentDeployment as A, type CompiledAgentBundle as C, type FileSearch as F, OpaqueRefSchema as O, type PluginRestartWarning as P, type SandboxHandleStore as S, type WorkspaceAgentDispatcherContext as W, type SandboxHandleRecord as a, type Sha256Digest as b, type WorkspaceAgentDispatcher as c, SchemaValidationError as d, type AgentSchemaIssue as e, type AgentSchemaValidationResult as f, type AgentDefinition as g, type AgentDefinitionDigestAsset as h, type AgentDefinitionReference as i, AgentDefinitionValidationError as j, AgentDeploymentValidationError as k, type CommandNotifyPayload as l, type CompiledAgentDefinition as m, Sha256DigestSchema as n, WORKSPACE_AGENT_PLUGINS_RELOADED_EVENT as o, WORKSPACE_COMMAND_NOTIFY_EVENT as p, type WorkspaceAgentDispatcherSendInput as q, createAgentAssetDigest as r, createAgentDefinitionDigest as s, createAgentDeploymentDigest as t, validateAgentDeployment as u, validateAgentDefinition as v };
@@ -35,6 +35,7 @@ All API failures must use the response envelope:
35
35
  | `PATH_NOT_WRITABLE` | Path parent missing or write denied | 403 | user-fix | warn | stable (public API) |
36
36
  | `WORKSPACE_UNINITIALIZED` | Workspace adapter/store not initialized yet | 503 | retry | warn | stable (public API) |
37
37
  | `WORKSPACE_NOT_READY` | Workspace substrate (`workspace-fs`, `sandbox-exec`, or `ui-bridge`) is still preparing | 503 | retry | warn | stable (public API) |
38
+ | `D1_HOST_SCOPE_VIOLATION` | Presented workspace selector conflicts with the trusted dedicated-host request scope | 421 | user-fix | warn | stable (public API) |
38
39
  | `AGENT_RUNTIME_NOT_READY` | Selected workspace runtime dependencies (`runtime-dependencies` or `runtime:<name>`, e.g. `runtime:python`/`runtime:node`) are still preparing | 503 | retry | warn | stable (public API) |
39
40
  | `AGENT_BINDING_DISPOSED` | A caller retained an agent binding after its host retired it | 410 | resolve a fresh binding | warn | stable (trusted API) |
40
41
  | `AGENT_CONTROL_RECEIPT_INVALID` | The existing agent runtime returned a malformed interrupt/stop receipt through the trusted dispatcher | 500 | report-bug | error | stable (trusted API) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hachej/boring-agent",
3
- "version": "0.1.80",
3
+ "version": "0.1.82",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Pane-embeddable coding agent. Ships direct/local/vercel-sandbox execution modes behind one interface.",
@@ -84,7 +84,7 @@
84
84
  "use-stick-to-bottom": "^1.1.6",
85
85
  "yaml": "^2.9.0",
86
86
  "zod": "^3.25.76",
87
- "@hachej/boring-ui-kit": "0.1.80"
87
+ "@hachej/boring-ui-kit": "0.1.82"
88
88
  },
89
89
  "devDependencies": {
90
90
  "@antithesishq/bombadil": "0.6.1",