stitchkit 0.89.0 → 0.90.1

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 (65) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/dist/agent-runtime/coding-tool-refusals.d.ts +31 -10
  3. package/dist/agent-runtime/coding-tool-refusals.d.ts.map +1 -1
  4. package/dist/agent-runtime/spill.d.ts.map +1 -1
  5. package/dist/agent-runtime-coding-tools.js +4 -4
  6. package/dist/agent-runtime-harness.js +5 -5
  7. package/dist/agent-runtime-sandbox.js +5 -5
  8. package/dist/agent-runtime.js +17 -29
  9. package/dist/application/watch-hub.d.ts +24 -2
  10. package/dist/application/watch-hub.d.ts.map +1 -1
  11. package/dist/application-grammy.js +1 -1
  12. package/dist/application.js +103 -13
  13. package/dist/cli.js +7 -7
  14. package/dist/contract/errors.d.ts +3 -0
  15. package/dist/contract/errors.d.ts.map +1 -1
  16. package/dist/contract/index.js +2 -2
  17. package/dist/{index-qmgs7y68.js → index-1txvygak.js} +1 -1
  18. package/dist/{index-8c3a7m4g.js → index-2hrfpw2c.js} +1 -1
  19. package/dist/{index-7evdsyez.js → index-2hryh65w.js} +1 -1
  20. package/dist/index-2na0qrfn.js +214 -0
  21. package/dist/{index-zyvby92n.js → index-44ht2790.js} +2 -2
  22. package/dist/{index-27gm3d6g.js → index-6q3zjwaz.js} +2 -2
  23. package/dist/{index-mnm4qp0p.js → index-79hb1wyh.js} +3 -3
  24. package/dist/{index-apn8repm.js → index-7gqx71yd.js} +2 -2
  25. package/dist/{index-7601qfg1.js → index-8dph3pw6.js} +4 -4
  26. package/dist/{index-90d7h2cr.js → index-bg8ypxzn.js} +3 -3
  27. package/dist/{index-vchzar7e.js → index-db51n3xr.js} +5 -5
  28. package/dist/{index-hw2chdvy.js → index-f475yj00.js} +1 -1
  29. package/dist/{index-q3ve2d1k.js → index-gbqjt8jz.js} +3 -3
  30. package/dist/index-gte38nbm.js +101 -0
  31. package/dist/{index-cp20z0n6.js → index-j7q0xj6d.js} +7 -55
  32. package/dist/{index-2bxcmqkb.js → index-kazec06k.js} +1 -1
  33. package/dist/{index-0w9abg87.js → index-scs3f1eg.js} +3 -0
  34. package/dist/{index-31jw8fjq.js → index-wb15909q.js} +1 -1
  35. package/dist/{index-p18f59zy.js → index-z78bjcxj.js} +1 -1
  36. package/dist/{index-t7fkyxcr.js → index-zkcqhxx8.js} +1 -1
  37. package/dist/index.js +6 -6
  38. package/dist/live/watch-client.d.ts +2 -1
  39. package/dist/live/watch-client.d.ts.map +1 -1
  40. package/dist/live/watch-contract.d.ts +70 -4
  41. package/dist/live/watch-contract.d.ts.map +1 -1
  42. package/dist/live/watch-delta.d.ts +110 -0
  43. package/dist/live/watch-delta.d.ts.map +1 -0
  44. package/dist/live.d.ts +2 -1
  45. package/dist/live.d.ts.map +1 -1
  46. package/dist/live.js +56 -4
  47. package/dist/node.js +6 -6
  48. package/dist/observability/changes.d.ts +55 -0
  49. package/dist/observability/changes.d.ts.map +1 -0
  50. package/dist/observability/index.d.ts +2 -0
  51. package/dist/observability/index.d.ts.map +1 -1
  52. package/dist/observability/index.js +130 -3
  53. package/dist/observability/spool.d.ts +53 -0
  54. package/dist/observability/spool.d.ts.map +1 -0
  55. package/dist/primitives.js +2 -2
  56. package/dist/remote.js +5 -5
  57. package/dist/server/index.js +8 -8
  58. package/dist/testing.js +6 -6
  59. package/dist/tool-invoker.js +6 -6
  60. package/dist/tools.js +11 -11
  61. package/dist/tracking.js +2 -2
  62. package/llms-full.txt +156 -15
  63. package/package.json +1 -1
  64. package/dist/index-dre2ywck.js +0 -48
  65. package/dist/index-gskm1k5a.js +0 -50
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/contract/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE;QACL,2CAA2C;QAC3C,IAAI,EAAE,MAAM,CAAC;QACb,8BAA8B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,CAEvE;AAED,+FAA+F;AAC/F,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,KAAK,CAOP"}
@@ -8,7 +8,7 @@ import {
8
8
  defineErrors,
9
9
  encodeCursor,
10
10
  paginatedSchema
11
- } from "../index-2bxcmqkb.js";
11
+ } from "../index-kazec06k.js";
12
12
  import {
13
13
  ManagedFilePathSchema,
14
14
  ManagedFileRefSchema
@@ -24,7 +24,7 @@ import {
24
24
  notFound,
25
25
  rateLimited,
26
26
  unauthorized
27
- } from "../index-0w9abg87.js";
27
+ } from "../index-scs3f1eg.js";
28
28
  import"../index-kzfs85xp.js";
29
29
  import"../index-77fekveh.js";
30
30
  export {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  normalizeError
3
- } from "./index-7evdsyez.js";
3
+ } from "./index-2hryh65w.js";
4
4
 
5
5
  // src/internal/bounded-lines.ts
6
6
  var DEFAULT_STREAM_LINE_BYTES = 1024 * 1024;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  executeToolMethod
3
- } from "./index-zyvby92n.js";
3
+ } from "./index-44ht2790.js";
4
4
  import {
5
5
  assertToolExtensionCompatible,
6
6
  mergeSchemas,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AppError
3
- } from "./index-0w9abg87.js";
3
+ } from "./index-scs3f1eg.js";
4
4
  import {
5
5
  isRecord
6
6
  } from "./index-77fekveh.js";
@@ -0,0 +1,214 @@
1
+ import {
2
+ LiveStatePhaseSchema,
3
+ LiveStateStopReasonSchema
4
+ } from "./index-ywd0y6m1.js";
5
+ import {
6
+ stableValue
7
+ } from "./index-a916km3r.js";
8
+
9
+ // src/live/watch-delta.ts
10
+ import { z } from "zod";
11
+ var WatchDeltaSchema = z.lazy(() => z.union([
12
+ z.object({ t: z.literal("set"), v: z.unknown() }),
13
+ z.object({
14
+ t: z.literal("obj"),
15
+ set: z.record(z.string(), WatchDeltaSchema).optional(),
16
+ drop: z.array(z.string()).optional()
17
+ }),
18
+ z.object({ t: z.literal("arr"), ops: z.array(WatchArrayOpSchema) })
19
+ ]));
20
+ var WatchArrayOpSchema = z.lazy(() => z.union([
21
+ z.object({
22
+ o: z.literal("copy"),
23
+ from: z.number().int().nonnegative(),
24
+ count: z.number().int().positive()
25
+ }),
26
+ z.object({
27
+ o: z.literal("patch"),
28
+ from: z.number().int().nonnegative(),
29
+ d: WatchDeltaSchema
30
+ }),
31
+ z.object({ o: z.literal("put"), v: z.unknown() })
32
+ ]));
33
+ function isRecord(value) {
34
+ return typeof value === "object" && value !== null && !Array.isArray(value);
35
+ }
36
+ function signature(value) {
37
+ return JSON.stringify(stableValue(value)) ?? "undefined";
38
+ }
39
+ function diff(previous, next) {
40
+ if (signature(previous) === signature(next))
41
+ return;
42
+ if (isRecord(previous) && isRecord(next))
43
+ return objectDiff(previous, next);
44
+ if (Array.isArray(previous) && Array.isArray(next))
45
+ return arrayDiff(previous, next);
46
+ return { t: "set", v: next };
47
+ }
48
+ function objectDiff(previous, next) {
49
+ const set = {};
50
+ const drop = [];
51
+ for (const key of Object.keys(next)) {
52
+ if (!Object.hasOwn(previous, key)) {
53
+ set[key] = { t: "set", v: next[key] };
54
+ continue;
55
+ }
56
+ const nested = diff(previous[key], next[key]);
57
+ if (nested !== undefined)
58
+ set[key] = nested;
59
+ }
60
+ for (const key of Object.keys(previous)) {
61
+ if (!Object.hasOwn(next, key))
62
+ drop.push(key);
63
+ }
64
+ return {
65
+ t: "obj",
66
+ ...Object.keys(set).length > 0 && { set },
67
+ ...drop.length > 0 && { drop }
68
+ };
69
+ }
70
+ function arrayDiff(previous, next) {
71
+ const previousSignatures = previous.map(signature);
72
+ const positions = new Map;
73
+ previousSignatures.forEach((value, index) => {
74
+ const bucket = positions.get(value);
75
+ if (bucket)
76
+ bucket.push(index);
77
+ else
78
+ positions.set(value, [index]);
79
+ });
80
+ const taken = new Set;
81
+ const ops = [];
82
+ let cursor = 0;
83
+ const extend = (from) => {
84
+ const last = ops.at(-1);
85
+ if (last?.o !== "copy" || last.from + last.count !== from)
86
+ return false;
87
+ ops[ops.length - 1] = { o: "copy", from: last.from, count: last.count + 1 };
88
+ return true;
89
+ };
90
+ for (const element of next) {
91
+ const wanted = signature(element);
92
+ const last = ops.at(-1);
93
+ const continuation = last?.o === "copy" ? last.from + last.count : undefined;
94
+ if (continuation !== undefined && continuation < previous.length && previousSignatures[continuation] === wanted && !taken.has(continuation)) {
95
+ taken.add(continuation);
96
+ extend(continuation);
97
+ cursor = continuation + 1;
98
+ continue;
99
+ }
100
+ const bucket = positions.get(wanted);
101
+ const found = bucket?.find((index) => !taken.has(index));
102
+ if (found !== undefined) {
103
+ taken.add(found);
104
+ if (!extend(found))
105
+ ops.push({ o: "copy", from: found, count: 1 });
106
+ cursor = found + 1;
107
+ continue;
108
+ }
109
+ const counterpart = cursor < previous.length && !taken.has(cursor) ? cursor : undefined;
110
+ const nested = counterpart === undefined ? undefined : diff(previous[counterpart], element);
111
+ if (counterpart !== undefined && nested !== undefined) {
112
+ taken.add(counterpart);
113
+ ops.push({ o: "patch", from: counterpart, d: nested });
114
+ cursor = counterpart + 1;
115
+ continue;
116
+ }
117
+ ops.push({ o: "put", v: element });
118
+ }
119
+ return { t: "arr", ops };
120
+ }
121
+ function apply(previous, delta) {
122
+ if (delta.t === "set")
123
+ return delta.v;
124
+ if (delta.t === "obj") {
125
+ if (!isRecord(previous))
126
+ throw new Error("an object difference needs an object to apply to");
127
+ const result2 = { ...previous };
128
+ for (const key of delta.drop ?? [])
129
+ delete result2[key];
130
+ for (const [key, nested] of Object.entries(delta.set ?? {})) {
131
+ result2[key] = apply(Object.hasOwn(result2, key) ? result2[key] : undefined, nested);
132
+ }
133
+ return result2;
134
+ }
135
+ if (!Array.isArray(previous))
136
+ throw new Error("an array difference needs an array to apply to");
137
+ const result = [];
138
+ for (const op of delta.ops) {
139
+ if (op.o === "put") {
140
+ result.push(op.v);
141
+ continue;
142
+ }
143
+ if (op.from >= previous.length) {
144
+ throw new Error(`the difference reads element ${op.from} of an array of ${previous.length}`);
145
+ }
146
+ if (op.o === "patch") {
147
+ result.push(apply(previous[op.from], op.d));
148
+ continue;
149
+ }
150
+ if (op.from + op.count > previous.length) {
151
+ throw new Error(`the difference copies ${op.count} from ${op.from} of an array of ${previous.length}`);
152
+ }
153
+ result.push(...previous.slice(op.from, op.from + op.count));
154
+ }
155
+ return result;
156
+ }
157
+ function deltaWins(delta, value) {
158
+ return JSON.stringify(delta).length < (JSON.stringify(value) ?? "null").length;
159
+ }
160
+
161
+ // src/live/watch-contract.ts
162
+ import { z as z2 } from "zod";
163
+ var WatchKeySchema = z2.object({
164
+ service: z2.string().min(1),
165
+ action: z2.string().min(1),
166
+ digest: z2.string().min(1)
167
+ }).strict().readonly();
168
+ var WatchHaveSchema = z2.object({ revision: z2.number().int().nonnegative(), fingerprint: z2.string().min(1) }).strict().readonly();
169
+ var WatchOpenSchema = z2.object({ key: WatchKeySchema, args: z2.unknown(), have: WatchHaveSchema.optional() }).readonly();
170
+ var WatchAcceptedSchema = z2.object({
171
+ accepted: z2.boolean(),
172
+ reason: z2.string().optional()
173
+ }).strict().readonly();
174
+ var watchValueParts = {
175
+ key: WatchKeySchema,
176
+ revision: z2.number().int().nonnegative(),
177
+ fingerprint: z2.string().min(1)
178
+ };
179
+ var WatchValueSchema = z2.discriminatedUnion("kind", [
180
+ z2.object({ kind: z2.literal("full"), ...watchValueParts, value: z2.unknown() }).readonly(),
181
+ z2.object({
182
+ kind: z2.literal("delta"),
183
+ ...watchValueParts,
184
+ base: z2.number().int().nonnegative(),
185
+ delta: WatchDeltaSchema
186
+ }).readonly(),
187
+ z2.object({ kind: z2.literal("unchanged"), ...watchValueParts }).readonly()
188
+ ]);
189
+ var WatchStateSchema = z2.object({
190
+ key: WatchKeySchema,
191
+ phase: LiveStatePhaseSchema,
192
+ reason: LiveStateStopReasonSchema.optional(),
193
+ code: z2.string().optional(),
194
+ message: z2.string().optional()
195
+ }).readonly();
196
+ var WATCH_OPEN = "stitchkit.watch.open";
197
+ var WATCH_CLOSE = "stitchkit.watch.close";
198
+ var WATCH_VALUE = "stitchkit.watch.value";
199
+ var WATCH_STATE = "stitchkit.watch.state";
200
+ var watchContract = {
201
+ serverToClient: {
202
+ [WATCH_VALUE]: { args: z2.tuple([WatchValueSchema]) },
203
+ [WATCH_STATE]: { args: z2.tuple([WatchStateSchema]) }
204
+ },
205
+ clientToServer: {
206
+ [WATCH_OPEN]: { args: z2.tuple([WatchOpenSchema]), ack: WatchAcceptedSchema },
207
+ [WATCH_CLOSE]: { args: z2.tuple([z2.object({ key: WatchKeySchema }).readonly()]) }
208
+ }
209
+ };
210
+ function watchKeyString(key) {
211
+ return `${key.service}/${key.action}/${key.digest}`;
212
+ }
213
+
214
+ export { WatchDeltaSchema, WatchArrayOpSchema, diff, apply, deltaWins, WatchKeySchema, WatchHaveSchema, WatchValueSchema, WatchStateSchema, WATCH_OPEN, WATCH_CLOSE, WATCH_VALUE, WATCH_STATE, watchContract, watchKeyString };
@@ -6,12 +6,12 @@ import {
6
6
  formatZodError,
7
7
  normalizeError,
8
8
  validateDeclaredOutput
9
- } from "./index-7evdsyez.js";
9
+ } from "./index-2hryh65w.js";
10
10
  import {
11
11
  AppError,
12
12
  STITCH_ERROR_STATUS,
13
13
  isStitchErrorCode
14
- } from "./index-0w9abg87.js";
14
+ } from "./index-scs3f1eg.js";
15
15
  import {
16
16
  coerceJsonArgs
17
17
  } from "./index-7zbps32p.js";
@@ -3,7 +3,7 @@ import {
3
3
  inputIsQuery,
4
4
  parseSSE,
5
5
  readBoundedUtf8Lines
6
- } from "./index-qmgs7y68.js";
6
+ } from "./index-1txvygak.js";
7
7
  import {
8
8
  ApiError,
9
9
  RequestCancellationError,
@@ -16,7 +16,7 @@ import {
16
16
  ContractStreamFrameSchema,
17
17
  DEFAULT_CONTRACT_STREAM_FRAME_BYTES,
18
18
  parseTrailingWildcard
19
- } from "./index-2bxcmqkb.js";
19
+ } from "./index-kazec06k.js";
20
20
  import {
21
21
  isRecord,
22
22
  mapObject,
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  collectTools,
3
3
  createToolRunner
4
- } from "./index-8c3a7m4g.js";
4
+ } from "./index-2hrfpw2c.js";
5
5
  import {
6
6
  toolErrorFromResult
7
- } from "./index-zyvby92n.js";
7
+ } from "./index-44ht2790.js";
8
8
  import {
9
9
  AppError
10
- } from "./index-0w9abg87.js";
10
+ } from "./index-scs3f1eg.js";
11
11
  import {
12
12
  assertUniqueToolName
13
13
  } from "./index-r159gjwy.js";
@@ -4,10 +4,10 @@ import {
4
4
  } from "./index-2qzskm8h.js";
5
5
  import {
6
6
  zodIssues
7
- } from "./index-7evdsyez.js";
7
+ } from "./index-2hryh65w.js";
8
8
  import {
9
9
  AppError
10
- } from "./index-0w9abg87.js";
10
+ } from "./index-scs3f1eg.js";
11
11
 
12
12
  // src/realtime/rejected-frame.ts
13
13
  var REALTIME_REJECTION_KEY = "@stitchkit/realtime-rejected";
@@ -3,18 +3,18 @@ import {
3
3
  } from "./index-sbdmyz75.js";
4
4
  import {
5
5
  collectToolSurface
6
- } from "./index-31jw8fjq.js";
6
+ } from "./index-wb15909q.js";
7
7
  import {
8
8
  createToolRunner,
9
9
  formatToolError
10
- } from "./index-8c3a7m4g.js";
10
+ } from "./index-2hrfpw2c.js";
11
11
  import {
12
12
  toolResultFromError
13
- } from "./index-zyvby92n.js";
13
+ } from "./index-44ht2790.js";
14
14
  import {
15
15
  formatZodError,
16
16
  validateDeclaredOutput
17
- } from "./index-7evdsyez.js";
17
+ } from "./index-2hryh65w.js";
18
18
  import {
19
19
  coerceJsonArgs
20
20
  } from "./index-7zbps32p.js";
@@ -2,15 +2,15 @@ import {
2
2
  contextContributionDelta,
3
3
  mergeContextContribution,
4
4
  prepareContextContribution
5
- } from "./index-p18f59zy.js";
5
+ } from "./index-z78bjcxj.js";
6
6
  import {
7
7
  base64UrlToBytes,
8
8
  bytesToBase64Url
9
- } from "./index-2bxcmqkb.js";
9
+ } from "./index-kazec06k.js";
10
10
  import {
11
11
  forbidden,
12
12
  unauthorized
13
- } from "./index-0w9abg87.js";
13
+ } from "./index-scs3f1eg.js";
14
14
  import {
15
15
  isUnsafeKey,
16
16
  safeJsonParse
@@ -10,7 +10,7 @@ import {
10
10
  import {
11
11
  createValidatedRealtimeSocket,
12
12
  isModuleNotFound
13
- } from "./index-apn8repm.js";
13
+ } from "./index-7gqx71yd.js";
14
14
  import {
15
15
  DEFAULT_PROCESS_SIGNALS,
16
16
  RUNTIME_CONTEXT_RESERVED_KEYS,
@@ -22,7 +22,7 @@ import {
22
22
  isOriginAllowed,
23
23
  mediaTypeEssence,
24
24
  reportSignalError
25
- } from "./index-p18f59zy.js";
25
+ } from "./index-z78bjcxj.js";
26
26
  import {
27
27
  getRequestContext,
28
28
  runWithRequestContext,
@@ -41,17 +41,17 @@ import {
41
41
  normalizeError,
42
42
  recordedErrorMessage,
43
43
  validateDeclaredOutput
44
- } from "./index-7evdsyez.js";
44
+ } from "./index-2hryh65w.js";
45
45
  import {
46
46
  DEFAULT_CONTRACT_STREAM_FRAME_BYTES,
47
47
  joinRoutePath,
48
48
  parseTrailingWildcard
49
- } from "./index-2bxcmqkb.js";
49
+ } from "./index-kazec06k.js";
50
50
  import {
51
51
  AppError,
52
52
  badRequest,
53
53
  forbidden
54
- } from "./index-0w9abg87.js";
54
+ } from "./index-scs3f1eg.js";
55
55
  import {
56
56
  resolveTraceContext
57
57
  } from "./index-zcgf3gqf.js";
@@ -36,7 +36,7 @@ import {
36
36
  import {
37
37
  ToolExecutionControlError,
38
38
  isToolExecutionControlError
39
- } from "./index-zyvby92n.js";
39
+ } from "./index-44ht2790.js";
40
40
  import {
41
41
  isRecord,
42
42
  transportResult
@@ -4,16 +4,16 @@ import {
4
4
  } from "./index-7rkhw9ec.js";
5
5
  import {
6
6
  collectToolSurface
7
- } from "./index-31jw8fjq.js";
7
+ } from "./index-wb15909q.js";
8
8
  import {
9
9
  createToolRunner,
10
10
  formatToolError
11
- } from "./index-8c3a7m4g.js";
11
+ } from "./index-2hrfpw2c.js";
12
12
  import {
13
13
  isToolExecutionControlError,
14
14
  toolCauseFromResult,
15
15
  toolResultFromError
16
- } from "./index-zyvby92n.js";
16
+ } from "./index-44ht2790.js";
17
17
  import {
18
18
  isRecord
19
19
  } from "./index-77fekveh.js";
@@ -0,0 +1,101 @@
1
+ import {
2
+ AppError,
3
+ STITCH_ERROR_STATUS
4
+ } from "./index-scs3f1eg.js";
5
+
6
+ // src/agent-runtime/sandbox.ts
7
+ import { z } from "zod";
8
+ var AgentSandboxRestrictionSchema = z.enum([
9
+ "network-denied",
10
+ "write-contained",
11
+ "secrets-hidden",
12
+ "process-contained"
13
+ ]);
14
+ var AgentSandboxGradeSchema = z.discriminatedUnion("grade", [
15
+ z.object({ grade: z.literal("full"), restrictions: z.array(AgentSandboxRestrictionSchema) }).strict(),
16
+ z.object({
17
+ grade: z.literal("partial"),
18
+ restrictions: z.array(AgentSandboxRestrictionSchema),
19
+ gaps: z.array(AgentSandboxRestrictionSchema)
20
+ }).strict(),
21
+ z.object({ grade: z.literal("unavailable"), reason: z.string().min(1) }).strict()
22
+ ]);
23
+ var probes = new WeakMap;
24
+ function probeAgentProcessSandbox(sandbox, options = {}) {
25
+ if (options.refresh)
26
+ probes.delete(sandbox);
27
+ const present = probes.get(sandbox);
28
+ if (present)
29
+ return present;
30
+ const pending = Promise.resolve(sandbox.probe()).then((grade) => AgentSandboxGradeSchema.parse(grade));
31
+ probes.set(sandbox, pending);
32
+ return pending;
33
+ }
34
+ function missingSandboxRestrictions(grade, required) {
35
+ if (grade.grade === "unavailable")
36
+ return required;
37
+ const present = new Set(grade.restrictions);
38
+ return required.filter((restriction) => !present.has(restriction));
39
+ }
40
+ async function recordAgentSandboxProbe(input) {
41
+ const grade = await probeAgentProcessSandbox(input.sandbox);
42
+ const missing = missingSandboxRestrictions(grade, input.required);
43
+ await input.store.appendEvent({
44
+ conversationId: input.conversationId,
45
+ kind: "sandbox/probed",
46
+ payload: {
47
+ result: grade,
48
+ required: [...input.required],
49
+ missing: [...missing]
50
+ }
51
+ });
52
+ return grade;
53
+ }
54
+
55
+ // src/agent-runtime/coding-tool-refusals.ts
56
+ function codingRefusal(code, message, options = {}) {
57
+ throw new AppError(code, message, STITCH_ERROR_STATUS[code], { message, ...options.details }, options.hint);
58
+ }
59
+ function codingPathRefusal(code, message, path, options = {}) {
60
+ codingRefusal(code, message, {
61
+ details: { path, ...options.details },
62
+ ...options.hint && { hint: options.hint }
63
+ });
64
+ }
65
+ function refuseMissingCodingPath(error, relative) {
66
+ const code = error?.code;
67
+ if (error instanceof Error && error.message.includes("is not a regular file")) {
68
+ codingPathRefusal("BAD_REQUEST", "This path is not a regular file", relative, {
69
+ hint: "Use list_directory to see what is here."
70
+ });
71
+ }
72
+ if (code === "ENOENT") {
73
+ codingPathRefusal("NOT_FOUND", "This path does not exist", relative, {
74
+ hint: "Use list_directory or glob to find the right path."
75
+ });
76
+ }
77
+ if (code === "ENOTDIR") {
78
+ codingPathRefusal("BAD_REQUEST", "A segment of this path is not a directory", relative, {
79
+ hint: "Check the path with list_directory."
80
+ });
81
+ }
82
+ if (code === "ELOOP") {
83
+ codingPathRefusal("FORBIDDEN", "This path is a symlink, which is not followed", relative, {
84
+ hint: "Read or write the target directly, by its own workspace-relative path."
85
+ });
86
+ }
87
+ if (code === "EISDIR") {
88
+ codingPathRefusal("BAD_REQUEST", "This path is not a regular file", relative, {
89
+ hint: "Use list_directory to see what is here."
90
+ });
91
+ }
92
+ throw error;
93
+ }
94
+ function refuseUnknownSpillReference(reference) {
95
+ codingRefusal("SPILL_REFERENCE_UNKNOWN", `No spilled output is held under \`${reference}\``, {
96
+ details: { reference },
97
+ hint: "Use the reference returned by the command that spilled its output, not a session or call id."
98
+ });
99
+ }
100
+
101
+ export { AgentSandboxRestrictionSchema, AgentSandboxGradeSchema, probeAgentProcessSandbox, missingSandboxRestrictions, recordAgentSandboxProbe, codingRefusal, codingPathRefusal, refuseMissingCodingPath, refuseUnknownSpillReference };
@@ -12,14 +12,16 @@ import {
12
12
  writeContainedFile
13
13
  } from "./index-bn2cjajt.js";
14
14
  import {
15
+ codingPathRefusal,
16
+ codingRefusal,
15
17
  missingSandboxRestrictions,
16
- probeAgentProcessSandbox
17
- } from "./index-gskm1k5a.js";
18
+ probeAgentProcessSandbox,
19
+ refuseMissingCodingPath
20
+ } from "./index-gte38nbm.js";
18
21
  import {
19
- AppError,
20
22
  conflict,
21
23
  forbidden
22
- } from "./index-0w9abg87.js";
24
+ } from "./index-scs3f1eg.js";
23
25
  import {
24
26
  defineRuntimeTool
25
27
  } from "./index-kc6h6hg0.js";
@@ -178,56 +180,6 @@ import { realpath as realpath2 } from "node:fs/promises";
178
180
  // src/agent-runtime/coding-tool-paths.ts
179
181
  import { lstat, realpath } from "node:fs/promises";
180
182
  import path from "node:path";
181
-
182
- // src/agent-runtime/coding-tool-refusals.ts
183
- var REFUSAL_STATUS = {
184
- BAD_REQUEST: 400,
185
- FORBIDDEN: 403,
186
- NOT_FOUND: 404,
187
- CONFLICT: 409,
188
- SANDBOX_UNAVAILABLE: 503,
189
- SANDBOX_INSUFFICIENT: 503
190
- };
191
- function codingRefusal(code, message, options = {}) {
192
- throw new AppError(code, message, REFUSAL_STATUS[code], { message, ...options.details }, options.hint);
193
- }
194
- function codingPathRefusal(code, message, path, options = {}) {
195
- codingRefusal(code, message, {
196
- details: { path, ...options.details },
197
- ...options.hint && { hint: options.hint }
198
- });
199
- }
200
- function refuseMissingCodingPath(error, relative) {
201
- const code = error?.code;
202
- if (error instanceof Error && error.message.includes("is not a regular file")) {
203
- codingPathRefusal("BAD_REQUEST", "This path is not a regular file", relative, {
204
- hint: "Use list_directory to see what is here."
205
- });
206
- }
207
- if (code === "ENOENT") {
208
- codingPathRefusal("NOT_FOUND", "This path does not exist", relative, {
209
- hint: "Use list_directory or glob to find the right path."
210
- });
211
- }
212
- if (code === "ENOTDIR") {
213
- codingPathRefusal("BAD_REQUEST", "A segment of this path is not a directory", relative, {
214
- hint: "Check the path with list_directory."
215
- });
216
- }
217
- if (code === "ELOOP") {
218
- codingPathRefusal("FORBIDDEN", "This path is a symlink, which is not followed", relative, {
219
- hint: "Read or write the target directly, by its own workspace-relative path."
220
- });
221
- }
222
- if (code === "EISDIR") {
223
- codingPathRefusal("BAD_REQUEST", "This path is not a regular file", relative, {
224
- hint: "Use list_directory to see what is here."
225
- });
226
- }
227
- throw error;
228
- }
229
-
230
- // src/agent-runtime/coding-tool-paths.ts
231
183
  function within(root, target) {
232
184
  const relative = path.relative(root, target);
233
185
  return relative === "" || !relative.startsWith(`..${path.sep}`) && relative !== ".." && !path.isAbsolute(relative);
@@ -1348,4 +1300,4 @@ function createAgentCodingTools(config) {
1348
1300
  ];
1349
1301
  }
1350
1302
 
1351
- export { codingRefusal, AgentCodingToolLimitsSchema, AgentCodingToolAuthorizationSchema, AgentCodingToolPathAuthorizationSchema, createAgentCodingTools };
1303
+ export { AgentCodingToolLimitsSchema, AgentCodingToolAuthorizationSchema, AgentCodingToolPathAuthorizationSchema, createAgentCodingTools };
@@ -2,7 +2,7 @@ import {
2
2
  AppError,
3
3
  STITCH_ERROR_STATUS,
4
4
  isStitchErrorCode
5
- } from "./index-0w9abg87.js";
5
+ } from "./index-scs3f1eg.js";
6
6
  import {
7
7
  isUnsafeKey
8
8
  } from "./index-kzfs85xp.js";
@@ -77,6 +77,9 @@ var STITCH_ERROR_STATUS = {
77
77
  STREAM_FRAME_TOO_LARGE: 500,
78
78
  STREAM_TERMINAL_MISSING: 500,
79
79
  STREAM_LIFETIME_EXCEEDED: 408,
80
+ SANDBOX_UNAVAILABLE: 503,
81
+ SANDBOX_INSUFFICIENT: 503,
82
+ SPILL_REFERENCE_UNKNOWN: 404,
80
83
  INTERNAL_SERVER_ERROR: 500
81
84
  };
82
85
  function isStitchErrorCode(code) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  contractToolMountable
3
- } from "./index-8c3a7m4g.js";
3
+ } from "./index-2hrfpw2c.js";
4
4
  import {
5
5
  runtimeToolMountable
6
6
  } from "./index-kc6h6hg0.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  mergeMeta,
3
3
  resolveRouteParamsSchema
4
- } from "./index-2bxcmqkb.js";
4
+ } from "./index-kazec06k.js";
5
5
  import {
6
6
  isUnsafeKey
7
7
  } from "./index-kzfs85xp.js";