@hachej/boring-agent 0.1.89 → 0.1.91

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.
Files changed (39) hide show
  1. package/dist/{chunk-GOM3VJOJ.js → chunk-2GBHYJVC.js} +31 -1
  2. package/dist/{chunk-I7UEASPG.js → chunk-BHH5NH7P.js} +5534 -8253
  3. package/dist/{chunk-M32FXCIN.js → chunk-CJ2BW2W2.js} +23 -8
  4. package/dist/{chunk-WZCTVT57.js → chunk-IWBC6SF7.js} +94 -112
  5. package/dist/chunk-NITBKFG6.js +1246 -0
  6. package/dist/{chunk-BDYXKHWY.js → chunk-PZC76CIA.js} +7 -1
  7. package/dist/core/index.d.ts +5 -5
  8. package/dist/core/index.js +2 -2
  9. package/dist/{createHarness-CCQLHKUF.js → createHarness-PMYRKDE4.js} +2 -2
  10. package/dist/errors-BEmw9HMp.d.ts +200 -0
  11. package/dist/front/index.d.ts +30 -5
  12. package/dist/front/index.js +230 -44
  13. package/dist/{harness-VvP0l5Mj.d.ts → harness-Bt_GMNYR.d.ts} +2 -2
  14. package/dist/{workspaceAgentDispatcher-CKEeNPjW.d.ts → lease-2aXepSBL.d.ts} +254 -59
  15. package/dist/{protocol-B_OQKfbI.d.ts → middleware-CzW8n7B7.d.ts} +20 -18
  16. package/dist/piChatEvent-DBO3M5lu.d.ts +367 -0
  17. package/dist/{piChatSessionService-DPjJ0g71.d.ts → piChatSessionService-BaaVWke7.d.ts} +5 -1
  18. package/dist/{sandbox-DthfJaOB.d.ts → sandbox-DAD8cWQR.d.ts} +14 -1
  19. package/dist/server/agent-host/testing/gatewayConformance.d.ts +41 -0
  20. package/dist/server/agent-host/testing/gatewayConformance.js +465 -0
  21. package/dist/server/index.d.ts +507 -708
  22. package/dist/server/index.js +53 -50
  23. package/dist/server/worker/index.d.ts +9 -7
  24. package/dist/server/worker/index.js +19 -28
  25. package/dist/shared/index.d.ts +119 -27
  26. package/dist/shared/index.js +65 -282
  27. package/dist/types-jcMapYr9.d.ts +759 -0
  28. package/docs/ACCESSIBILITY.md +4 -5
  29. package/docs/API.md +3 -0
  30. package/docs/AUTHORING.md +68 -0
  31. package/docs/ERROR_CODES.md +29 -0
  32. package/docs/README.md +1 -0
  33. package/docs/RISKS-MULTI-TAB.md +1 -1
  34. package/docs/runtime-provisioning.md +1 -1
  35. package/docs/runtime.md +9 -6
  36. package/package.json +18 -9
  37. package/dist/chunk-DGRKMMXO.js +0 -8
  38. package/dist/chunk-XPQEF32D.js +0 -385
  39. package/dist/piChatEvent-nmOBSNU9.d.ts +0 -367
@@ -1,385 +0,0 @@
1
- import {
2
- AgentDefinitionErrorCode,
3
- AgentDeploymentErrorCode,
4
- ErrorCode
5
- } from "./chunk-GOM3VJOJ.js";
6
-
7
- // src/shared/agent-definition.ts
8
- import { z as z2 } from "zod";
9
-
10
- // src/shared/digest.ts
11
- function toHex(bytes) {
12
- return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
13
- }
14
- async function digestBytes(bytes) {
15
- const hash = await globalThis.crypto.subtle.digest("SHA-256", new Uint8Array(bytes));
16
- return `sha256:${toHex(new Uint8Array(hash))}`;
17
- }
18
- async function sha256(value) {
19
- return digestBytes(new TextEncoder().encode(value));
20
- }
21
- async function sha256Bytes(bytes) {
22
- return digestBytes(bytes);
23
- }
24
- function canonicalStringify(value) {
25
- if (value === null || typeof value !== "object") {
26
- const encoded = JSON.stringify(value);
27
- if (encoded === void 0) throw new TypeError("Cannot canonicalize undefined");
28
- return encoded;
29
- }
30
- if (Array.isArray(value)) return `[${value.map(canonicalStringify).join(",")}]`;
31
- const record = value;
32
- return `{${Object.keys(record).filter((key) => record[key] !== void 0).sort().map((key) => `${JSON.stringify(key)}:${canonicalStringify(record[key])}`).join(",")}}`;
33
- }
34
-
35
- // src/shared/schema-issue.ts
36
- import { z } from "zod";
37
- function formatPath(path) {
38
- if (path.length === 0) return "<root>";
39
- return path.reduce(
40
- (result, part) => typeof part === "number" ? `${result}[${part}]` : result.length === 0 ? String(part) : `${result}.${String(part)}`,
41
- ""
42
- );
43
- }
44
- function mapZodIssues(issues, invalidCode, unsupportedCode) {
45
- return issues.flatMap((issue) => {
46
- if (issue.code === z.ZodIssueCode.unrecognized_keys) {
47
- const parent = formatPath(issue.path);
48
- return [...issue.keys].sort().map((key) => ({
49
- code: unsupportedCode,
50
- field: parent === "<root>" ? key : `${parent}.${key}`,
51
- message: `${key} is not supported by schema version 1`
52
- }));
53
- }
54
- const field = formatPath(issue.path);
55
- return [{
56
- code: invalidCode,
57
- field,
58
- message: field === "<root>" ? issue.message : `${field} ${issue.message}`
59
- }];
60
- });
61
- }
62
- var SchemaValidationError = class extends Error {
63
- code = ErrorCode.enum.CONFIG_INVALID;
64
- field;
65
- validationCode;
66
- constructor(issue) {
67
- super(issue.message);
68
- this.field = issue.field;
69
- this.validationCode = issue.code;
70
- }
71
- };
72
-
73
- // src/shared/agent-definition.ts
74
- var SHA256_DIGEST_RE = /^sha256:[a-f0-9]{64}$/;
75
- function hasWellFormedUnicode(value) {
76
- for (let index = 0; index < value.length; index += 1) {
77
- const code = value.charCodeAt(index);
78
- if (code >= 55296 && code <= 56319) {
79
- if (index + 1 >= value.length) return false;
80
- const next = value.charCodeAt(index + 1);
81
- if (next < 56320 || next > 57343) return false;
82
- index += 1;
83
- } else if (code >= 56320 && code <= 57343) {
84
- return false;
85
- }
86
- }
87
- return true;
88
- }
89
- function isOpaqueRef(value) {
90
- return hasWellFormedUnicode(value) && value.trim() === value && !/[\0-\x1f\x7f]/.test(value);
91
- }
92
- function isSafeAssetPath(value) {
93
- const segments = value.split("/");
94
- return hasWellFormedUnicode(value) && value.normalize("NFC") === value && !/[\0-\x1f\x7f]/.test(value) && !value.includes("\\") && !value.startsWith("/") && !/^[A-Za-z]:[\\/]/.test(value) && !value.startsWith("./") && segments.every((segment) => segment !== "" && segment !== "." && segment !== "..");
95
- }
96
- var OpaqueRefSchema = z2.string().min(1, "must be a non-empty reference").max(256, "must be at most 256 characters").refine(isOpaqueRef, "must be a non-empty reference");
97
- var ReferenceArraySchema = z2.array(OpaqueRefSchema).superRefine((refs, ctx) => {
98
- const seen = /* @__PURE__ */ new Set();
99
- refs.forEach((ref, index) => {
100
- if (seen.has(ref)) {
101
- ctx.addIssue({
102
- code: z2.ZodIssueCode.custom,
103
- path: [index],
104
- message: "must not contain duplicate references"
105
- });
106
- }
107
- seen.add(ref);
108
- });
109
- });
110
- var SafeAssetPathSchema = z2.string().min(1).refine(isSafeAssetPath, "must be a safe relative asset path");
111
- var Sha256DigestSchema = z2.string().regex(SHA256_DIGEST_RE, "must be a lowercase sha256 digest").transform((value) => value);
112
- var AgentDefinitionSchema = z2.object({
113
- schemaVersion: z2.literal(1),
114
- definitionId: OpaqueRefSchema,
115
- version: OpaqueRefSchema,
116
- label: z2.string().refine(hasWellFormedUnicode, "must contain well-formed Unicode").optional(),
117
- instructionsRef: SafeAssetPathSchema,
118
- capabilityRequirements: ReferenceArraySchema.optional(),
119
- toolRefs: ReferenceArraySchema.optional(),
120
- skillRefs: ReferenceArraySchema.optional(),
121
- mcpServerRefs: ReferenceArraySchema.optional()
122
- }).strict();
123
- var AgentDefinitionReferenceSchema = z2.object({
124
- definitionId: OpaqueRefSchema,
125
- version: OpaqueRefSchema,
126
- digest: Sha256DigestSchema
127
- }).strict();
128
- var AgentDeploymentSchema = z2.object({
129
- deploymentId: OpaqueRefSchema,
130
- version: OpaqueRefSchema,
131
- agentId: OpaqueRefSchema,
132
- definition: AgentDefinitionReferenceSchema
133
- }).strict();
134
- var AgentDefinitionDigestAssetSchema = z2.object({
135
- path: SafeAssetPathSchema,
136
- digest: Sha256DigestSchema,
137
- content: z2.string().refine(hasWellFormedUnicode, "must contain well-formed Unicode")
138
- }).strict();
139
- function validateAgentDefinition(raw) {
140
- const result = AgentDefinitionSchema.safeParse(raw);
141
- if (!result.success) {
142
- return {
143
- valid: false,
144
- issues: mapZodIssues(
145
- result.error.issues,
146
- AgentDefinitionErrorCode.enum.AGENT_DEFINITION_INVALID,
147
- AgentDefinitionErrorCode.enum.AGENT_DEFINITION_UNSUPPORTED_FIELD
148
- )
149
- };
150
- }
151
- return { valid: true, value: result.data };
152
- }
153
- function validateAgentDeployment(raw) {
154
- const result = AgentDeploymentSchema.safeParse(raw);
155
- if (!result.success) {
156
- return {
157
- valid: false,
158
- issues: mapZodIssues(
159
- result.error.issues,
160
- AgentDeploymentErrorCode.enum.AGENT_DEPLOYMENT_INVALID,
161
- AgentDeploymentErrorCode.enum.AGENT_DEPLOYMENT_UNSUPPORTED_FIELD
162
- )
163
- };
164
- }
165
- return { valid: true, value: result.data };
166
- }
167
- async function createAgentAssetDigest(content) {
168
- if (!hasWellFormedUnicode(content)) {
169
- throw new AgentDefinitionValidationError({
170
- code: AgentDefinitionErrorCode.enum.AGENT_DEFINITION_INVALID,
171
- field: "content",
172
- message: "content must contain well-formed Unicode"
173
- });
174
- }
175
- return sha256(content);
176
- }
177
- var AgentDefinitionValidationError = class extends SchemaValidationError {
178
- constructor(issue) {
179
- super(issue);
180
- this.name = "AgentDefinitionValidationError";
181
- }
182
- };
183
- var AgentDeploymentValidationError = class extends SchemaValidationError {
184
- constructor(issue) {
185
- super(issue);
186
- this.name = "AgentDeploymentValidationError";
187
- }
188
- };
189
- async function validatedDefinitionAssets(definition, assets) {
190
- if (!Array.isArray(assets)) {
191
- throw new AgentDefinitionValidationError({
192
- code: AgentDefinitionErrorCode.enum.AGENT_DEFINITION_INVALID,
193
- field: "assets",
194
- message: "assets must be an array"
195
- });
196
- }
197
- const canonicalAssets = [];
198
- for (const [index, input] of assets.entries()) {
199
- const result = AgentDefinitionDigestAssetSchema.safeParse(input);
200
- if (!result.success) {
201
- const issue = mapZodIssues(
202
- result.error.issues,
203
- AgentDefinitionErrorCode.enum.AGENT_DEFINITION_INVALID,
204
- AgentDefinitionErrorCode.enum.AGENT_DEFINITION_UNSUPPORTED_FIELD
205
- )[0];
206
- throw new AgentDefinitionValidationError({
207
- ...issue,
208
- field: `assets[${index}].${issue.field}`
209
- });
210
- }
211
- if (await createAgentAssetDigest(result.data.content) !== result.data.digest) {
212
- throw new AgentDefinitionValidationError({
213
- code: AgentDefinitionErrorCode.enum.AGENT_DEFINITION_INVALID,
214
- field: "assets.digest",
215
- message: `asset digest does not match UTF-8 content: ${result.data.path}`
216
- });
217
- }
218
- canonicalAssets.push(result.data);
219
- }
220
- canonicalAssets.sort(
221
- (left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0
222
- );
223
- for (let index = 1; index < canonicalAssets.length; index += 1) {
224
- if (canonicalAssets[index - 1].path === canonicalAssets[index].path) {
225
- throw new AgentDefinitionValidationError({
226
- code: AgentDefinitionErrorCode.enum.AGENT_DEFINITION_INVALID,
227
- field: "assets.path",
228
- message: `duplicate asset path: ${canonicalAssets[index].path}`
229
- });
230
- }
231
- }
232
- if (!canonicalAssets.some((asset) => asset.path === definition.instructionsRef)) {
233
- throw new AgentDefinitionValidationError({
234
- code: AgentDefinitionErrorCode.enum.AGENT_DEFINITION_INVALID,
235
- field: "instructionsRef",
236
- message: "instructionsRef must name an included verified asset"
237
- });
238
- }
239
- return canonicalAssets;
240
- }
241
- async function createAgentDefinitionDigest(input) {
242
- const validated = validateAgentDefinition(input.definition);
243
- if (!validated.valid) throw new AgentDefinitionValidationError(validated.issues[0]);
244
- const assets = await validatedDefinitionAssets(validated.value, input.assets);
245
- return sha256(canonicalStringify({ definition: validated.value, assets }));
246
- }
247
- async function createAgentDeploymentDigest(deployment) {
248
- const validated = validateAgentDeployment(deployment);
249
- if (!validated.valid) throw new AgentDeploymentValidationError(validated.issues[0]);
250
- return sha256(canonicalStringify(validated.value));
251
- }
252
-
253
- // src/shared/validateTool.ts
254
- function validateTool(tool) {
255
- if (typeof tool !== "object" || tool === null) return null;
256
- const t = tool;
257
- if (typeof t.name !== "string" || t.name.length === 0) return null;
258
- if (typeof t.description !== "string") return null;
259
- if (typeof t.parameters !== "object" || t.parameters === null) return null;
260
- if (typeof t.execute !== "function") return null;
261
- return t;
262
- }
263
-
264
- // src/shared/share-entry.ts
265
- import { z as z3 } from "zod";
266
- var nonEmptyString = z3.string().min(1);
267
- function isOpaqueLocatorId(value) {
268
- return value.trim() === value && !/[\0-\x1f\x7f]/.test(value) && !value.includes("/") && !value.includes("\\") && !value.includes(":") && value !== "." && value !== "..";
269
- }
270
- var OpaqueShareLocatorIdSchema = z3.string().min(1, "must be a non-empty opaque id").max(256, "must be at most 256 characters").refine(isOpaqueLocatorId, "must be an opaque platform-owned id (no path separators, no scheme, no traversal)");
271
- function mintShareEntryId() {
272
- return globalThis.crypto.randomUUID();
273
- }
274
- var ShareEntryProvenanceSchema = z3.object({
275
- producerPrincipalRef: nonEmptyString,
276
- createdAt: nonEmptyString
277
- }).strict();
278
- var ShareEntryV1Schema = z3.object({
279
- schemaVersion: z3.literal(1),
280
- id: OpaqueShareLocatorIdSchema,
281
- workspaceId: OpaqueShareLocatorIdSchema,
282
- path: nonEmptyString,
283
- provenance: ShareEntryProvenanceSchema
284
- }).strict();
285
- var ShareEntryErrorCode = z3.enum(["AR1_SHARE_NOT_FOUND", "AR1_SHARE_TOMBSTONED"]);
286
- var ShareEntryValidationCode = z3.enum(["SHARE_ENTRY_INPUT_INVALID"]);
287
- var ShareEntryValidationError = class extends Error {
288
- code = ErrorCode.enum.CONFIG_INVALID;
289
- field;
290
- constructor(issue) {
291
- super(issue.message);
292
- this.name = "ShareEntryValidationError";
293
- this.field = issue.field;
294
- }
295
- };
296
- function assertValidCreateInput(raw) {
297
- const result = CreateShareEntryInputSchema.safeParse(raw);
298
- if (result.success) return;
299
- const issue = result.error.issues[0];
300
- const field = formatPath(issue.path);
301
- throw new ShareEntryValidationError({
302
- code: ShareEntryValidationCode.enum.SHARE_ENTRY_INPUT_INVALID,
303
- field,
304
- message: field === "<root>" ? issue.message : `${field} ${issue.message}`
305
- });
306
- }
307
- var CreateShareEntryInputSchema = z3.object({
308
- workspaceId: OpaqueShareLocatorIdSchema,
309
- path: nonEmptyString,
310
- provenance: z3.object({
311
- producerPrincipalRef: nonEmptyString,
312
- createdAt: nonEmptyString.optional()
313
- }).strict()
314
- }).strict();
315
- var InMemoryShareEntryStore = class {
316
- entries = /* @__PURE__ */ new Map();
317
- async create(input) {
318
- assertValidCreateInput(input);
319
- const entry = {
320
- schemaVersion: 1,
321
- id: mintShareEntryId(),
322
- workspaceId: input.workspaceId,
323
- path: input.path,
324
- provenance: {
325
- producerPrincipalRef: input.provenance.producerPrincipalRef,
326
- createdAt: input.provenance.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
327
- }
328
- };
329
- this.entries.set(entry.id, entry);
330
- return entry;
331
- }
332
- async get(id) {
333
- return this.entries.get(id) ?? null;
334
- }
335
- async delete(id) {
336
- this.entries.delete(id);
337
- }
338
- async list(workspaceId) {
339
- return Array.from(this.entries.values()).filter((entry) => entry.workspaceId === workspaceId);
340
- }
341
- };
342
- async function resolveShareEntry(store, id, workspace) {
343
- const entry = await store.get(id);
344
- if (!entry) {
345
- return { status: "not_found", code: ShareEntryErrorCode.enum.AR1_SHARE_NOT_FOUND };
346
- }
347
- try {
348
- await workspace.stat(entry.path);
349
- } catch {
350
- return {
351
- status: "tombstoned",
352
- code: ShareEntryErrorCode.enum.AR1_SHARE_TOMBSTONED,
353
- tombstone: {
354
- id: entry.id,
355
- workspaceId: entry.workspaceId,
356
- provenance: entry.provenance
357
- }
358
- };
359
- }
360
- return { status: "ok", entry };
361
- }
362
-
363
- export {
364
- sha256Bytes,
365
- canonicalStringify,
366
- formatPath,
367
- SchemaValidationError,
368
- OpaqueRefSchema,
369
- Sha256DigestSchema,
370
- validateAgentDefinition,
371
- validateAgentDeployment,
372
- createAgentAssetDigest,
373
- AgentDefinitionValidationError,
374
- AgentDeploymentValidationError,
375
- createAgentDefinitionDigest,
376
- createAgentDeploymentDigest,
377
- validateTool,
378
- OpaqueShareLocatorIdSchema,
379
- ShareEntryProvenanceSchema,
380
- ShareEntryV1Schema,
381
- ShareEntryErrorCode,
382
- ShareEntryValidationError,
383
- InMemoryShareEntryStore,
384
- resolveShareEntry
385
- };