@nyte-ai/core 0.0.18 → 0.0.21

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 (186) hide show
  1. package/README.md +1 -1
  2. package/THIRD-PARTY-NOTICES.md +66 -0
  3. package/dist/chunks/{compose-yk3y0jap.js → compose-0m65m83c.js} +7 -7
  4. package/dist/chunks/{compose-r12cnkpc.js → compose-12jnd50a.js} +11 -11
  5. package/dist/chunks/{compose-q1n2dgrs.js → compose-1knxqqm1.js} +4 -4
  6. package/dist/chunks/{compose-xtkavyrw.js → compose-1r0wr5dc.js} +17 -9
  7. package/dist/chunks/{compose-9tqm6g18.js → compose-2rha31fc.js} +4 -4
  8. package/dist/chunks/{compose-0bpspysf.js → compose-4ppmas7g.js} +5 -5
  9. package/dist/chunks/compose-5rg7askh.js +52 -0
  10. package/dist/chunks/{compose-mryw0674.js → compose-5z835ej2.js} +6 -1
  11. package/dist/chunks/{compose-7k6nsmtq.js → compose-6gt28900.js} +11 -14
  12. package/dist/chunks/{compose-2eg8w67t.js → compose-6r5ymwyr.js} +15 -4
  13. package/dist/chunks/{compose-xd0kdp3t.js → compose-753gc057.js} +8 -8
  14. package/dist/chunks/{compose-q1ts0v6k.js → compose-767bb340.js} +1 -1
  15. package/dist/chunks/{compose-rpq9n0nz.js → compose-8mkfr84d.js} +89 -32
  16. package/dist/chunks/{compose-5w5bbakh.js → compose-8pp3vtv0.js} +5 -5
  17. package/dist/chunks/{compose-gaps3heh.js → compose-9hy3p236.js} +9 -9
  18. package/dist/chunks/{compose-pgeemk2b.js → compose-a7k9h27z.js} +6 -5
  19. package/dist/chunks/{compose-dc2ns6gd.js → compose-a8ddt55n.js} +10 -10
  20. package/dist/chunks/{compose-7b8ajk7a.js → compose-ad80nkkn.js} +8 -8
  21. package/dist/chunks/{compose-064y3n82.js → compose-ae5t6v5b.js} +5 -5
  22. package/dist/chunks/{compose-amr0k1m1.js → compose-b2bf1jvy.js} +122 -41
  23. package/dist/chunks/{compose-xpfr4wt3.js → compose-bbhk8vnr.js} +7 -4
  24. package/dist/chunks/compose-bd8c5n7k.js +32 -0
  25. package/dist/chunks/{compose-rehp8epe.js → compose-byse0eqj.js} +7 -7
  26. package/dist/chunks/{compose-ef936rsa.js → compose-bz70g01d.js} +27 -11
  27. package/dist/chunks/compose-c4238qkb.js +105 -0
  28. package/dist/chunks/{compose-q1b0tppc.js → compose-c9wxgbjp.js} +4 -4
  29. package/dist/chunks/{compose-h272znxk.js → compose-cdj05t7x.js} +7 -7
  30. package/dist/chunks/{compose-kb22bkpt.js → compose-cqpjcx2t.js} +12 -1
  31. package/dist/chunks/{compose-dbx6ftbm.js → compose-csh5vv2t.js} +42 -4
  32. package/dist/chunks/{compose-eqr5qwp1.js → compose-d1m94kzq.js} +62 -22
  33. package/dist/chunks/{compose-drdej9yt.js → compose-d95fwwvw.js} +4 -4
  34. package/dist/chunks/{compose-jc22rsz4.js → compose-dbsn3bsy.js} +2 -2
  35. package/dist/chunks/{compose-s2aew2c9.js → compose-e2fyz3xc.js} +5 -5
  36. package/dist/chunks/{compose-gg8b9b21.js → compose-e9f6nrwp.js} +23 -18
  37. package/dist/chunks/{compose-52afaf3v.js → compose-fnncnk81.js} +7 -7
  38. package/dist/chunks/{compose-bjx8s01m.js → compose-fqsqjbrf.js} +1 -1
  39. package/dist/chunks/{compose-1gd9vkye.js → compose-gj2ypr7q.js} +3 -3
  40. package/dist/chunks/compose-gvm49f4b.js +155 -0
  41. package/dist/chunks/{compose-1jz2j92f.js → compose-gxjc6vz9.js} +30 -2
  42. package/dist/chunks/{compose-cq1zx4gp.js → compose-h14pmqv3.js} +1 -1
  43. package/dist/chunks/{compose-d2s80zg2.js → compose-hfrjm4a1.js} +5 -5
  44. package/dist/chunks/{compose-kmzr06mw.js → compose-hfsn6pnt.js} +8 -5
  45. package/dist/chunks/{compose-jjchxce6.js → compose-j42p9wfs.js} +1 -1
  46. package/dist/chunks/{compose-4b1zf3p0.js → compose-jd4bsnqh.js} +63 -47
  47. package/dist/chunks/{compose-2g3enfv5.js → compose-jeemzja1.js} +4 -4
  48. package/dist/chunks/{compose-y478gv6x.js → compose-jmmyw9hd.js} +4 -4
  49. package/dist/chunks/{compose-5tkyrzr0.js → compose-jwy1gba9.js} +4 -4
  50. package/dist/chunks/{compose-k35b75k9.js → compose-kwkna3cg.js} +2 -4
  51. package/dist/chunks/{compose-t53j8yxv.js → compose-m01wspwf.js} +1 -1
  52. package/dist/chunks/{compose-n93897b0.js → compose-m91ffwss.js} +1 -1
  53. package/dist/chunks/{compose-madtxnp1.js → compose-matk94se.js} +7 -7
  54. package/dist/chunks/{compose-aa73dbe8.js → compose-mcz93154.js} +117 -58
  55. package/dist/chunks/{compose-r7dx7rpz.js → compose-mdwr0er9.js} +72 -15
  56. package/dist/chunks/{compose-j12n448k.js → compose-nj4nj5n9.js} +36 -3
  57. package/dist/chunks/{compose-yn2et568.js → compose-nkxwrphm.js} +141 -15
  58. package/dist/chunks/{compose-k8aghhv2.js → compose-pkprmn5b.js} +16 -16
  59. package/dist/chunks/{compose-1z7q169s.js → compose-q2zxbg41.js} +69 -41
  60. package/dist/chunks/{compose-b5xz0dj7.js → compose-qwbe95qs.js} +2 -2
  61. package/dist/chunks/{compose-vmhv4e00.js → compose-qxfq6dn9.js} +13 -12
  62. package/dist/chunks/{compose-wgphshsn.js → compose-r8tz1xfj.js} +8 -8
  63. package/dist/chunks/{compose-ffk8dnbh.js → compose-smsafpqe.js} +3 -3
  64. package/dist/chunks/{compose-djq2bt61.js → compose-sprfv38c.js} +6 -6
  65. package/dist/chunks/{compose-cdy4q5mv.js → compose-t9fcqtby.js} +17 -16
  66. package/dist/chunks/{compose-p3q14yt1.js → compose-tppkp915.js} +5 -5
  67. package/dist/chunks/{compose-dckpgtks.js → compose-ts08bth2.js} +3 -3
  68. package/dist/chunks/{compose-n10w4nkk.js → compose-vn7b7fdj.js} +12 -3
  69. package/dist/chunks/{compose-9m19b27b.js → compose-w6zb11k1.js} +7 -7
  70. package/dist/chunks/{compose-j3tkz0tb.js → compose-wvzzf8n2.js} +6 -6
  71. package/dist/chunks/{compose-6vf6dkk2.js → compose-xhtgytrh.js} +2 -2
  72. package/dist/chunks/{compose-4tb2vn84.js → compose-y6xgbg2h.js} +1 -1
  73. package/dist/chunks/compose-yfcb6w2h.js +58 -0
  74. package/dist/chunks/{compose-0rx7ygxq.js → compose-zaanjpb7.js} +1 -1
  75. package/dist/chunks/{compose-7pc3p5ex.js → compose-zjj072km.js} +8 -8
  76. package/dist/src/agent/compaction.js +41 -39
  77. package/dist/src/agent/images.d.ts +7 -0
  78. package/dist/src/agent/images.js +8 -0
  79. package/dist/src/agent/request.js +30 -30
  80. package/dist/src/agent/tool-runner.d.ts +3 -7
  81. package/dist/src/agent/tool-runner.js +34 -30
  82. package/dist/src/agent/transcript.d.ts +0 -1
  83. package/dist/src/agent/transcript.js +37 -35
  84. package/dist/src/agent/turn.js +46 -43
  85. package/dist/src/api/connection.js +60 -56
  86. package/dist/src/api/head.js +42 -41
  87. package/dist/src/api/part.js +22 -22
  88. package/dist/src/api/server.js +48 -44
  89. package/dist/src/api/session.js +48 -47
  90. package/dist/src/builtins/delegation.js +2 -2
  91. package/dist/src/builtins/environment.js +1 -2
  92. package/dist/src/compose.d.ts +6 -7
  93. package/dist/src/compose.js +72 -67
  94. package/dist/src/contract/fold.d.ts +1 -3
  95. package/dist/src/contract/host.d.ts +30 -1
  96. package/dist/src/contract/host.js +4 -2
  97. package/dist/src/contract/kernel.d.ts +6 -35
  98. package/dist/src/contract/parts.d.ts +4 -0
  99. package/dist/src/contract/parts.js +1 -1
  100. package/dist/src/contract/records.d.ts +69 -3
  101. package/dist/src/contract/records.js +5 -1
  102. package/dist/src/contract/session.d.ts +2 -1
  103. package/dist/src/contract/tools.d.ts +10 -1
  104. package/dist/src/contract/workspace.d.ts +7 -3
  105. package/dist/src/drive/execution.js +46 -42
  106. package/dist/src/drive/interruptions.d.ts +7 -0
  107. package/dist/src/drive/interruptions.js +17 -0
  108. package/dist/src/engine/admission.js +24 -24
  109. package/dist/src/engine/batches.js +22 -22
  110. package/dist/src/engine/branch-summary.js +21 -21
  111. package/dist/src/engine/durable.d.ts +0 -2
  112. package/dist/src/engine/durable.js +20 -20
  113. package/dist/src/engine/fence.js +20 -20
  114. package/dist/src/engine/jobs.d.ts +2 -0
  115. package/dist/src/engine/jobs.js +31 -27
  116. package/dist/src/engine/move.js +23 -23
  117. package/dist/src/engine/part-definitions.js +2 -2
  118. package/dist/src/engine/presence.d.ts +39 -0
  119. package/dist/src/engine/presence.js +16 -0
  120. package/dist/src/engine/principals.js +17 -17
  121. package/dist/src/engine/receipts.js +21 -21
  122. package/dist/src/engine/runs.d.ts +1 -1
  123. package/dist/src/engine/runs.js +25 -25
  124. package/dist/src/engine/start.js +36 -35
  125. package/dist/src/engine/surface.d.ts +4 -0
  126. package/dist/src/engine/surface.js +13 -0
  127. package/dist/src/engine/waits.d.ts +5 -15
  128. package/dist/src/engine/waits.js +23 -19
  129. package/dist/src/env/browser.js +27 -27
  130. package/dist/src/env/environment.js +29 -29
  131. package/dist/src/env/mcp.js +31 -31
  132. package/dist/src/env/session-changes.d.ts +10 -0
  133. package/dist/src/env/session-changes.js +15 -0
  134. package/dist/src/env/trust.js +30 -30
  135. package/dist/src/env/workspaces.js +34 -33
  136. package/dist/src/env/worktrees.js +35 -34
  137. package/dist/src/extend/activation.js +35 -34
  138. package/dist/src/extend/hooks.js +22 -22
  139. package/dist/src/extend/models.d.ts +2 -1
  140. package/dist/src/extend/models.js +32 -30
  141. package/dist/src/extend/plugin-api.js +18 -18
  142. package/dist/src/extend/plugin-runtime.js +42 -41
  143. package/dist/src/extend/registry.js +27 -27
  144. package/dist/src/extend/resources.js +31 -31
  145. package/dist/src/extend/setting-layers.js +4 -4
  146. package/dist/src/extend/settings.js +38 -37
  147. package/dist/src/extend/workspace-commands.js +43 -42
  148. package/dist/src/fold/calls.js +5 -5
  149. package/dist/src/fold/checkpoint.js +11 -11
  150. package/dist/src/fold/code.d.ts +1 -2
  151. package/dist/src/fold/code.js +1 -1
  152. package/dist/src/fold/commit.d.ts +0 -4
  153. package/dist/src/fold/commit.js +16 -16
  154. package/dist/src/fold/draft.js +4 -4
  155. package/dist/src/fold/fold.js +7 -7
  156. package/dist/src/fold/paths.js +5 -5
  157. package/dist/src/fold/project.d.ts +3 -1
  158. package/dist/src/fold/project.js +8 -6
  159. package/dist/src/fold/reads.js +5 -5
  160. package/dist/src/fold/seen.js +19 -19
  161. package/dist/src/fold/view.d.ts +1 -1
  162. package/dist/src/fold/view.js +20 -20
  163. package/dist/src/fold/watch.js +15 -15
  164. package/dist/src/harness.d.ts +3 -1
  165. package/dist/src/harness.js +75 -70
  166. package/dist/src/index.d.ts +3 -3
  167. package/dist/src/index.js +5 -3
  168. package/dist/src/server.js +70 -65
  169. package/dist/src/store/inspect.js +4 -4
  170. package/dist/src/store/log.d.ts +0 -2
  171. package/dist/src/store/log.js +2 -2
  172. package/dist/src/store/memory-store.js +5 -5
  173. package/dist/src/store/migrations.js +3 -3
  174. package/dist/src/store/model-state.d.ts +6 -1
  175. package/dist/src/store/model-state.js +14 -4
  176. package/dist/src/store/parts.js +5 -5
  177. package/dist/src/store/refs.d.ts +6 -5
  178. package/dist/src/store/refs.js +11 -1
  179. package/dist/src/store/session-index.js +2 -2
  180. package/dist/src/store/session.d.ts +3 -1
  181. package/dist/src/store/session.js +5 -3
  182. package/dist/src/store.d.ts +1 -1
  183. package/dist/src/store.js +11 -7
  184. package/dist/src/testing.d.ts +2 -0
  185. package/dist/src/testing.js +83 -70
  186. package/package.json +4 -4
@@ -4,10 +4,6 @@ import {
4
4
  import {
5
5
  lineDiff2
6
6
  } from "./compose-j50h13pg.js";
7
- import {
8
- followedTrace2,
9
- traceparent2
10
- } from "./compose-sd0stm97.js";
11
7
 
12
8
  // src/builtins/environment.ts
13
9
  import { PatchEntrySchema, standard, writePatch } from "@nyte-ai/schema";
@@ -17,6 +13,7 @@ var READ_CHARS = 50 * 1024;
17
13
  var LIST_LIMIT = 500;
18
14
  var SHELL_BYTES = 32 * 1024;
19
15
  var PROGRESS_BYTES = 4 * 1024;
16
+ var FIRST_OUTPUT_MS = 1000;
20
17
  var MIME_TYPES = new Map([
21
18
  ["png", "image/png"],
22
19
  ["jpg", "image/jpeg"],
@@ -49,7 +46,16 @@ var listParameters = standard(Type.Object({
49
46
  }));
50
47
  var bashParameters = standard(Type.Object({
51
48
  command: Type.String({ description: "The shell command to run." }),
52
- description: Type.Optional(Type.String({ description: "What the command does, in a few words, for the user." }))
49
+ description: Type.Optional(Type.String({ description: "What the command does, in a few words, for the user." })),
50
+ background: Type.Optional(Type.Boolean({
51
+ description: "Start the command and return a job id with its first output instead of waiting for it to exit. Use for servers, watchers, and other long-lived commands, without a trailing &. The command keeps running across turns, and you are told when it exits; read its output or stop it with the job tool. Do not use it to speed up ordinary commands."
52
+ }))
53
+ }));
54
+ var jobParameters = standard(Type.Object({
55
+ id: Type.String({ description: "The job id a background bash call returned." }),
56
+ action: Type.Enum(["output", "stop"], {
57
+ description: "output reads the job's state and latest output; stop ends it."
58
+ })
53
59
  }));
54
60
  var read = {
55
61
  name: "read",
@@ -79,7 +85,7 @@ var write = {
79
85
  parameters: writeParameters,
80
86
  output: PatchEntrySchema,
81
87
  class: (args) => ({ kind: "edit", path: args.path }),
82
- replay: "safe",
88
+ replay: "never",
83
89
  async execute(args, invocation) {
84
90
  const { files } = invocation.env;
85
91
  const previous = await files.read(args.path);
@@ -99,7 +105,7 @@ var edit = {
99
105
  parameters: editParameters,
100
106
  output: PatchEntrySchema,
101
107
  class: (args) => ({ kind: "edit", path: args.path }),
102
- replay: "safe",
108
+ replay: "never",
103
109
  async execute(args, invocation) {
104
110
  const { files } = invocation.env;
105
111
  const document = await files.read(args.path);
@@ -177,44 +183,119 @@ var bash = {
177
183
  class: (args) => args.description === undefined ? { kind: "shell", command: args.command } : { kind: "shell", command: args.command, description: args.description },
178
184
  replay: "never",
179
185
  async execute(args, invocation) {
180
- const { env } = invocation;
181
- const trace = followedTrace2(invocation.session.id);
182
- const job = await env.exec(args.command, {
183
- cwd: env.cwd,
184
- signal: invocation.signal,
185
- env: trace === null ? undefined : { TRACEPARENT: traceparent2(trace) }
186
+ const { foreground, signal } = invocation;
187
+ const running = await foreground.start({
188
+ command: args.command,
189
+ title: args.description ?? args.command
186
190
  });
187
- const chunks = [];
188
- let kept = 0;
189
- let dropped = 0;
190
- let code = null;
191
- for await (const frame of job.output()) {
192
- if (frame.kind === "exit") {
193
- code = frame.code;
194
- break;
195
- }
196
- if (frame.kind === "gap")
197
- continue;
198
- chunks.push(frame.data);
199
- kept += frame.data.byteLength;
200
- while (kept - (chunks[0]?.byteLength ?? 0) >= SHELL_BYTES && chunks.length > 1) {
201
- const first = chunks.shift();
202
- kept -= first?.byteLength ?? 0;
203
- dropped += first?.byteLength ?? 0;
191
+ const stop = () => void running.stop().catch(() => {
192
+ return;
193
+ });
194
+ signal.addEventListener("abort", stop, { once: true });
195
+ if (signal.aborted)
196
+ stop();
197
+ const shell = createShellOutput((tail) => invocation.progress({ text: tail }));
198
+ const frames = running.output()[Symbol.asyncIterator]();
199
+ try {
200
+ const exited = await shell.read(frames, args.background === true ? AbortSignal.any([foreground.released, AbortSignal.timeout(FIRST_OUTPUT_MS)]) : foreground.released);
201
+ if (!exited && (foreground.released.aborted || foreground.release())) {
202
+ await frames.return?.();
203
+ return text(shell.render(`[running in the background as job ${running.id}: you are told when it exits; the job tool reads its output or stops it]`));
204
204
  }
205
- invocation.progress({ text: decodeOutputTail(chunks, PROGRESS_BYTES) });
205
+ if (!exited)
206
+ await shell.read(frames, new AbortController().signal);
207
+ const end = await running.settled();
208
+ const exit = end.kind === "exited" ? end.code ?? shell.code() : shell.code();
209
+ return text(shell.render(end.kind === "lost" ? "[the process was lost]" : `[exit code ${exit ?? "none"}${end.reason === "exited" ? "" : `, ${end.reason}`}]`));
210
+ } catch (error) {
211
+ stop();
212
+ throw error;
213
+ } finally {
214
+ signal.removeEventListener("abort", stop);
206
215
  }
207
- const end = await job.settled();
208
- const exit = end.kind === "exited" ? end.code ?? code : code;
209
- const joined = joinBytes(chunks);
210
- const cut = Math.max(0, joined.byteLength - SHELL_BYTES);
211
- const output = new TextDecoder().decode(joined.subarray(cut)).trimEnd();
212
- const truncated = dropped + cut > 0 ? [`[truncated: the first ${dropped + cut} bytes of output are not shown]`] : [];
213
- const status = end.kind === "lost" ? "[the process was lost]" : `[exit code ${exit ?? "none"}${end.reason === "exited" ? "" : `, ${end.reason}`}]`;
214
- return text([...truncated, ...output === "" ? [] : [output], status].join(`
215
- `));
216
216
  }
217
217
  };
218
+ var job = {
219
+ name: "job",
220
+ description: "Read the state and latest output of a job a background bash call started, or stop it.",
221
+ parameters: jobParameters,
222
+ class: (args) => ({
223
+ kind: "custom",
224
+ label: args.action === "stop" ? `Stopping job ${args.id}` : `Reading job ${args.id}`
225
+ }),
226
+ effects: "none",
227
+ replay: "safe",
228
+ async execute(args, invocation) {
229
+ const { jobs } = invocation.workspace;
230
+ const find = async () => (await jobs.list()).find((view) => view.id === args.id && view.session === invocation.session.id);
231
+ const found = await find();
232
+ if (found === undefined)
233
+ return text(`This chat has no job ${args.id}.`);
234
+ if (args.action === "stop")
235
+ await invocation.workspace.job(found.id).stop();
236
+ const view = args.action === "stop" ? await find() ?? found : found;
237
+ const tail = view.tail.trimEnd();
238
+ const state = describeJobState(view.state);
239
+ return text(tail === "" ? `Job ${view.id} ${state}.` : `Job ${view.id} ${state}:
240
+ ${tail}`);
241
+ }
242
+ };
243
+ function describeJobState(state) {
244
+ if (state.kind === "running")
245
+ return "is running";
246
+ if (state.kind === "lost")
247
+ return "was lost with the host";
248
+ return state.reason === "exited" ? `exited with code ${state.code ?? "none"}` : `ended (${state.reason}) with code ${state.code ?? "none"}`;
249
+ }
250
+ function createShellOutput(progress) {
251
+ const chunks = [];
252
+ let kept = 0;
253
+ let dropped = 0;
254
+ let code = null;
255
+ let pending = null;
256
+ return {
257
+ async read(frames, until) {
258
+ const detached = new Promise((resolve) => {
259
+ if (until.aborted)
260
+ resolve(null);
261
+ until.addEventListener("abort", () => resolve(null), { once: true });
262
+ });
263
+ for (;; ) {
264
+ pending ??= frames.next();
265
+ const next = await Promise.race([pending, detached]);
266
+ if (next === null)
267
+ return false;
268
+ pending = null;
269
+ if (next.done === true)
270
+ return true;
271
+ const frame = next.value;
272
+ if (frame.kind === "exit") {
273
+ code = frame.code;
274
+ return true;
275
+ }
276
+ if (frame.kind === "gap")
277
+ continue;
278
+ chunks.push(frame.data);
279
+ kept += frame.data.byteLength;
280
+ while (kept - (chunks[0]?.byteLength ?? 0) >= SHELL_BYTES && chunks.length > 1) {
281
+ const first = chunks.shift();
282
+ kept -= first?.byteLength ?? 0;
283
+ dropped += first?.byteLength ?? 0;
284
+ }
285
+ progress(decodeOutputTail(chunks, PROGRESS_BYTES));
286
+ }
287
+ },
288
+ code: () => code,
289
+ render(status) {
290
+ const joined = joinBytes(chunks);
291
+ const cut = Math.max(0, joined.byteLength - SHELL_BYTES);
292
+ const output = new TextDecoder().decode(joined.subarray(cut)).trimEnd();
293
+ const truncated = dropped + cut > 0 ? [`[truncated: the first ${dropped + cut} bytes of output are not shown]`] : [];
294
+ return [...truncated, ...output === "" ? [] : [output], status].join(`
295
+ `);
296
+ }
297
+ };
298
+ }
218
299
  function joinBytes(chunks) {
219
300
  const joined = new Uint8Array(chunks.reduce((size, chunk) => size + chunk.byteLength, 0));
220
301
  let offset = 0;
@@ -241,7 +322,7 @@ function decodeOutputTail(chunks, limit) {
241
322
  }
242
323
  var environmentPlugin2 = {
243
324
  id: "environment",
244
- contribute: { tools: [read, write, edit, list, bash] },
325
+ contribute: { tools: [read, write, edit, list, bash, job] },
245
326
  activate(api) {
246
327
  const cwd = tryReadCwd(() => api.env);
247
328
  if (cwd !== null)
@@ -2,7 +2,7 @@ import {
2
2
  liveRef2,
3
3
  receiptRef2,
4
4
  callRef2
5
- } from "./compose-kb22bkpt.js";
5
+ } from "./compose-cqpjcx2t.js";
6
6
  import {
7
7
  dev2
8
8
  } from "./compose-n116fnmp.js";
@@ -10,10 +10,10 @@ import {
10
10
  readRefExpectation2,
11
11
  put2,
12
12
  readCall2
13
- } from "./compose-n10w4nkk.js";
13
+ } from "./compose-vn7b7fdj.js";
14
14
  import {
15
15
  publishSet2
16
- } from "./compose-7b8ajk7a.js";
16
+ } from "./compose-ad80nkkn.js";
17
17
 
18
18
  // src/fold/commit.ts
19
19
  import { SdkError } from "@nyte-ai/schema";
@@ -32,7 +32,10 @@ async function writeReceipt2(kernel, session, record) {
32
32
  throw new SdkError("stale", `Receipt ${record.id} already exists.`);
33
33
  }
34
34
  async function commit2(kernel, updates, under = null) {
35
- const fenced = under === null ? updates : updates.map((update) => ({ ...update, fence: liveRef2(under.session, under.run) }));
35
+ const fenced = under === null ? updates : updates.map((update) => ({
36
+ ...update,
37
+ fences: [...update.fences ?? [], liveRef2(under.session, under.run)]
38
+ }));
36
39
  const outcome = await kernel.store.refs.set(fenced);
37
40
  dev2("store", "refs.set", { names: updates.map(({ name }) => name), outcome });
38
41
  if (outcome.kind === "fenced" && under !== null)
@@ -0,0 +1,32 @@
1
+ import {
2
+ decodeRunRecord2
3
+ } from "./compose-gxjc6vz9.js";
4
+ import {
5
+ runRef2
6
+ } from "./compose-cqpjcx2t.js";
7
+ import {
8
+ load2
9
+ } from "./compose-vn7b7fdj.js";
10
+
11
+ // src/engine/surface.ts
12
+ var NONE = new Set;
13
+ async function readRequires(kernel, session, run) {
14
+ const found = await load2(kernel.store, await kernel.store.refs.get(runRef2(session, run)), decodeRunRecord2);
15
+ return found?.record.requires;
16
+ }
17
+ async function hiddenOwners2(kernel, session, run) {
18
+ const mine = kernel.presence?.member.capabilities ?? [];
19
+ if (mine.length === 0 || run === null)
20
+ return NONE;
21
+ const requires = await readRequires(kernel, session, run);
22
+ return requires === undefined ? NONE : new Set(mine.filter((owner) => !requires.includes(owner)));
23
+ }
24
+ async function missingCapabilities2(kernel, session, run) {
25
+ if (run === null)
26
+ return [];
27
+ const mine = kernel.presence?.member.capabilities ?? [];
28
+ const requires = await readRequires(kernel, session, run) ?? [];
29
+ return requires.filter((capability) => !mine.includes(capability));
30
+ }
31
+
32
+ export { hiddenOwners2, missingCapabilities2 };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  decodePartRecord2
3
- } from "./compose-1jz2j92f.js";
3
+ } from "./compose-gxjc6vz9.js";
4
4
  import {
5
5
  partRef2
6
- } from "./compose-kb22bkpt.js";
6
+ } from "./compose-cqpjcx2t.js";
7
7
  import {
8
8
  dev2
9
9
  } from "./compose-n116fnmp.js";
@@ -11,17 +11,17 @@ import {
11
11
  load2,
12
12
  put2,
13
13
  readCall2
14
- } from "./compose-n10w4nkk.js";
14
+ } from "./compose-vn7b7fdj.js";
15
15
  import {
16
16
  storedAnswer2
17
- } from "./compose-drdej9yt.js";
17
+ } from "./compose-d95fwwvw.js";
18
18
  import {
19
19
  waitIndex2,
20
20
  wokenIndex2
21
21
  } from "./compose-0wq555bd.js";
22
22
  import {
23
23
  changeCall2
24
- } from "./compose-xpfr4wt3.js";
24
+ } from "./compose-bbhk8vnr.js";
25
25
  import {
26
26
  holdLease2
27
27
  } from "./compose-vzvm76dn.js";
@@ -30,7 +30,7 @@ import {
30
30
  readParkedWait2,
31
31
  waitingOn2,
32
32
  lapsed2
33
- } from "./compose-ef936rsa.js";
33
+ } from "./compose-bz70g01d.js";
34
34
 
35
35
  // src/engine/durable.ts
36
36
  import { isJson, isJsonObject, SdkError } from "@nyte-ai/schema";
@@ -88,7 +88,7 @@ async function runStep2(kernel, input) {
88
88
  dev2("durable", "replayed", { session, call });
89
89
  return { kind: "done", value: read(record.result) };
90
90
  }
91
- if (!opened.wrote && input.replay === "never") {
91
+ if (!opened.wrote && record.replay === "never") {
92
92
  return { kind: "interrupted", value: await settle({ kind: "interrupted" }) };
93
93
  }
94
94
  const writes = [];
@@ -1,13 +1,15 @@
1
1
  import {
2
2
  decodeRunRecord2,
3
3
  decodePartRecord2,
4
- decodeCallRecord2
5
- } from "./compose-1jz2j92f.js";
4
+ decodeCallRecord2,
5
+ decodeJobRecord2
6
+ } from "./compose-gxjc6vz9.js";
6
7
  import {
7
8
  runRef2,
8
9
  partRef2,
9
- callRef2
10
- } from "./compose-kb22bkpt.js";
10
+ callRef2,
11
+ jobRef2
12
+ } from "./compose-cqpjcx2t.js";
11
13
  import {
12
14
  dev2
13
15
  } from "./compose-n116fnmp.js";
@@ -15,10 +17,10 @@ import {
15
17
  load2,
16
18
  put2,
17
19
  readCall2
18
- } from "./compose-n10w4nkk.js";
20
+ } from "./compose-vn7b7fdj.js";
19
21
  import {
20
22
  storedAnswer2
21
- } from "./compose-drdej9yt.js";
23
+ } from "./compose-d95fwwvw.js";
22
24
  import {
23
25
  WAITS2,
24
26
  TIME2,
@@ -33,10 +35,10 @@ import {
33
35
  import {
34
36
  commit2,
35
37
  changeCall2
36
- } from "./compose-xpfr4wt3.js";
38
+ } from "./compose-bbhk8vnr.js";
37
39
  import {
38
40
  readRunEnd2
39
- } from "./compose-6vf6dkk2.js";
41
+ } from "./compose-xhtgytrh.js";
40
42
 
41
43
  // src/engine/waits.ts
42
44
  import { asId, SdkError } from "@nyte-ai/schema";
@@ -141,8 +143,8 @@ function createWaitRegistry2(kernel, rerunAction) {
141
143
  return answer === null ? null : { kind: "part", part: target.part, answer };
142
144
  }
143
145
  case "job": {
144
- const state = kernel.jobs.get(target.job)?.view.state ?? LOST;
145
- return state.kind === "running" ? null : { kind: "job", job: target.job, end: state };
146
+ const end = await jobOutcome2(kernel, target.job);
147
+ return end === null ? null : { kind: "job", job: target.job, end };
146
148
  }
147
149
  case "timer":
148
150
  return null;
@@ -304,6 +306,20 @@ async function pendingCalls(kernel, sessions) {
304
306
  }));
305
307
  return found.flat();
306
308
  }
309
+ async function readJob2(store, id) {
310
+ return load2(store, await store.refs.get(jobRef2(id)), decodeJobRecord2);
311
+ }
312
+ async function jobOutcome2(kernel, id) {
313
+ const local = kernel.jobs.get(id)?.view.state;
314
+ if (local !== undefined)
315
+ return local.kind === "running" ? null : local;
316
+ const found = await readJob2(kernel.store, id);
317
+ if (found === null)
318
+ return LOST;
319
+ if (found.record.end !== null)
320
+ return found.record.end;
321
+ return found.record.instance === kernel.instance || kernel.presence === null ? LOST : null;
322
+ }
307
323
  function wake(kernel, session, record) {
308
324
  if (record.head === null && lapsed2(kernel, record))
309
325
  kernel.waits.rerun(session, record.id);
@@ -428,4 +444,4 @@ function lapsed2(kernel, record) {
428
444
  return record.result === null && record.waiting === null && record.reran !== null && record.reran.waits === record.waits.length && record.reran.holder !== kernel.instance && record.reran.expiresAt <= Date.now();
429
445
  }
430
446
 
431
- export { createWaitRegistry2, listSessionWaits2, loadWaits2, earliestWake2, waitFor2, runWait2, readParkedWait2, waitingOn2, lapsed2 };
447
+ export { createWaitRegistry2, listSessionWaits2, loadWaits2, readJob2, jobOutcome2, earliestWake2, waitFor2, runWait2, readParkedWait2, waitingOn2, lapsed2 };
@@ -0,0 +1,105 @@
1
+ import {
2
+ IMAGE_LIMITS2
3
+ } from "./compose-5z835ej2.js";
4
+ import {
5
+ dev2
6
+ } from "./compose-n116fnmp.js";
7
+
8
+ // src/agent/images.ts
9
+ var INLINE_IMAGE_TYPES = new Set([
10
+ "image/png",
11
+ "image/jpeg",
12
+ "image/gif",
13
+ "image/webp"
14
+ ]);
15
+ async function modelImage2(images, file) {
16
+ const mime = normalizeImageType(file.mime);
17
+ const label = `Image ${file.name}, ${mime}`;
18
+ if (images === null)
19
+ return passThrough(file.bytes, mime, label, "no image processor is configured");
20
+ let prepared;
21
+ try {
22
+ prepared = await images.prepare(file.bytes, mime, IMAGE_LIMITS2);
23
+ } catch (cause) {
24
+ dev2("images", "prepare failed", { name: file.name, mime, cause: String(cause) });
25
+ return passThrough(file.bytes, mime, label, "the image processor failed");
26
+ }
27
+ if (prepared === undefined)
28
+ return [{ type: "text", text: `[${label}: left out, it cannot be prepared for the model]` }];
29
+ const image = { type: "image", data: prepared.data, mimeType: prepared.mimeType };
30
+ if (prepared.resized === undefined)
31
+ return [image];
32
+ const { from, to } = prepared.resized;
33
+ return [
34
+ image,
35
+ {
36
+ type: "text",
37
+ text: `[${label}: resized from ${from.width}x${from.height} to ${to.width}x${to.height}. Multiply coordinates by ${(from.width / to.width).toFixed(2)} to map them to the original.]`
38
+ }
39
+ ];
40
+ }
41
+ function passThrough(bytes, mime, label, unprepared) {
42
+ const omitted = (reason) => [
43
+ { type: "text", text: `[${label}: left out, ${reason} and ${unprepared}]` }
44
+ ];
45
+ if (!INLINE_IMAGE_TYPES.has(mime))
46
+ return omitted("the model does not take this format");
47
+ if (Math.ceil(bytes.byteLength / 3) * 4 > IMAGE_LIMITS2.maxBase64Bytes)
48
+ return omitted(`${String(bytes.byteLength)} bytes is too large to send`);
49
+ const size = imageDimensions(bytes, mime);
50
+ if (size === undefined)
51
+ return omitted("its size cannot be read");
52
+ if (size.width > IMAGE_LIMITS2.maxWidth || size.height > IMAGE_LIMITS2.maxHeight)
53
+ return omitted(`${String(size.width)}x${String(size.height)} is larger than ${String(IMAGE_LIMITS2.maxWidth)}x${String(IMAGE_LIMITS2.maxHeight)}`);
54
+ return [{ type: "image", data: bytes.toBase64(), mimeType: mime }];
55
+ }
56
+ function normalizeImageType(mime) {
57
+ const base = mime.split(";")[0]?.trim().toLowerCase() ?? "";
58
+ return base === "image/jpg" ? "image/jpeg" : base;
59
+ }
60
+ function imageDimensions(bytes, mime) {
61
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
62
+ switch (mime) {
63
+ case "image/png":
64
+ return bytes.length < 24 ? undefined : { width: view.getUint32(16), height: view.getUint32(20) };
65
+ case "image/gif":
66
+ return bytes.length < 10 ? undefined : { width: view.getUint16(6, true), height: view.getUint16(8, true) };
67
+ case "image/webp": {
68
+ if (bytes.length < 30)
69
+ return;
70
+ const chunk = new TextDecoder().decode(bytes.subarray(12, 16));
71
+ if (chunk === "VP8 ")
72
+ return {
73
+ width: view.getUint16(26, true) & 16383,
74
+ height: view.getUint16(28, true) & 16383
75
+ };
76
+ if (chunk === "VP8L") {
77
+ const bits = view.getUint32(21, true);
78
+ return { width: (bits & 16383) + 1, height: (bits >>> 14 & 16383) + 1 };
79
+ }
80
+ if (chunk === "VP8X") {
81
+ const uint24 = (offset) => view.getUint16(offset, true) + view.getUint8(offset + 2) * 65536;
82
+ return { width: uint24(24) + 1, height: uint24(27) + 1 };
83
+ }
84
+ return;
85
+ }
86
+ case "image/jpeg":
87
+ for (let offset = 2;offset + 9 <= bytes.length; ) {
88
+ if (bytes[offset] !== 255)
89
+ return;
90
+ const marker = view.getUint8(offset + 1);
91
+ if (marker === 255) {
92
+ offset++;
93
+ continue;
94
+ }
95
+ if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204)
96
+ return { width: view.getUint16(offset + 7), height: view.getUint16(offset + 5) };
97
+ offset += 2 + view.getUint16(offset + 2);
98
+ }
99
+ return;
100
+ default:
101
+ return;
102
+ }
103
+ }
104
+
105
+ export { modelImage2 };
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  CORE_CONTEXT2
3
- } from "./compose-mryw0674.js";
3
+ } from "./compose-5z835ej2.js";
4
4
  import {
5
5
  kvRef2
6
- } from "./compose-kb22bkpt.js";
6
+ } from "./compose-cqpjcx2t.js";
7
7
  import {
8
8
  requireSession2,
9
9
  put2,
10
10
  readKv2
11
- } from "./compose-n10w4nkk.js";
11
+ } from "./compose-vn7b7fdj.js";
12
12
  import {
13
13
  commit2
14
- } from "./compose-xpfr4wt3.js";
14
+ } from "./compose-bbhk8vnr.js";
15
15
 
16
16
  // src/extend/plugin-api.ts
17
17
  import { isJsonObject, SdkError } from "@nyte-ai/schema";
@@ -1,31 +1,31 @@
1
1
  import {
2
2
  envelope2
3
- } from "./compose-1jz2j92f.js";
3
+ } from "./compose-gxjc6vz9.js";
4
4
  import {
5
5
  partRef2,
6
6
  workspaceRef2,
7
7
  trustRef2,
8
8
  leaseRef2
9
- } from "./compose-kb22bkpt.js";
9
+ } from "./compose-cqpjcx2t.js";
10
10
  import {
11
11
  publishSet2
12
- } from "./compose-7b8ajk7a.js";
12
+ } from "./compose-ad80nkkn.js";
13
13
  import {
14
14
  newRun2,
15
15
  begin2
16
- } from "./compose-vmhv4e00.js";
16
+ } from "./compose-qxfq6dn9.js";
17
17
  import {
18
18
  createHostState2
19
19
  } from "./compose-xm52jghq.js";
20
20
  import {
21
21
  createHost2
22
- } from "./compose-7pc3p5ex.js";
22
+ } from "./compose-zjj072km.js";
23
23
  import {
24
24
  createKernel2
25
- } from "./compose-1z7q169s.js";
25
+ } from "./compose-q2zxbg41.js";
26
26
  import {
27
27
  memoryStore2
28
- } from "./compose-dckpgtks.js";
28
+ } from "./compose-ts08bth2.js";
29
29
 
30
30
  // src/harness.ts
31
31
  import { asId } from "@nyte-ai/schema";
@@ -33,6 +33,9 @@ function endedRunRef2(id, run) {
33
33
  function liveRef2(id, run) {
34
34
  return `sessions/${id}/live/${run}`;
35
35
  }
36
+ function runCallsPrefix2(id, run) {
37
+ return `sessions/${id}/calls/${run}:`;
38
+ }
36
39
  function partRef2(id, part) {
37
40
  return `sessions/${id}/parts/${part}`;
38
41
  }
@@ -57,6 +60,14 @@ function kvRef2(scope, owner, key) {
57
60
  function leaseRef2(id, head) {
58
61
  return `sessions/${id}/leases/${head}`;
59
62
  }
63
+ var PROCESSES2 = "processes/";
64
+ function processRef2(instance) {
65
+ return `${PROCESSES2}${instance}`;
66
+ }
67
+ var JOBS2 = "jobs/";
68
+ function jobRef2(id) {
69
+ return `${JOBS2}${id}`;
70
+ }
60
71
  function hostIdentityRef2() {
61
72
  return "host/identity";
62
73
  }
@@ -64,4 +75,4 @@ function hostPrincipalsRef2() {
64
75
  return "host/principals";
65
76
  }
66
77
 
67
- export { sessionRef2, parseSessionRef2, parseHeadRef2, headRef2, inboxRef2, seenRef2, runRef2, endedRunRef2, liveRef2, partRef2, receiptRef2, callRef2, workspaceRef2, trustRef2, trustTarget2, kvRef2, leaseRef2, hostIdentityRef2, hostPrincipalsRef2 };
78
+ export { sessionRef2, parseSessionRef2, parseHeadRef2, headRef2, inboxRef2, seenRef2, runRef2, endedRunRef2, liveRef2, runCallsPrefix2, partRef2, receiptRef2, callRef2, workspaceRef2, trustRef2, trustTarget2, kvRef2, leaseRef2, PROCESSES2, processRef2, JOBS2, jobRef2, hostIdentityRef2, hostPrincipalsRef2 };
@@ -1,15 +1,53 @@
1
1
  import {
2
2
  decodeKvValue2
3
- } from "./compose-1jz2j92f.js";
3
+ } from "./compose-gxjc6vz9.js";
4
4
  import {
5
5
  kvRef2
6
- } from "./compose-kb22bkpt.js";
6
+ } from "./compose-cqpjcx2t.js";
7
7
 
8
8
  // src/store/model-state.ts
9
- import { ModelRefType } from "@nyte-ai/schema";
9
+ import { ModelRefType, ThinkingType } from "@nyte-ai/schema";
10
+ import { Type } from "typebox";
10
11
  import { Value } from "typebox/value";
11
12
  var CHECK_INTERVAL_MS = 60000;
12
13
  var MODEL_PREFERENCE2 = kvRef2("host", "models", "default");
14
+ var THINKING_PREFERENCES = kvRef2("host", "models", "thinking/");
15
+ var MODEL_LISTINGS = kvRef2("host", "models", "listing/");
16
+ var SavedListingType = Type.Enum(["hidden", "favorite"]);
17
+ function modelListingRef2(model) {
18
+ return `${MODEL_LISTINGS}${model.provider}/${model.id}`;
19
+ }
20
+ async function readModelListings2(store) {
21
+ const refs = await store.refs.list(MODEL_LISTINGS);
22
+ const entries = await Promise.all(refs.map(async (ref) => {
23
+ if (ref.target === null)
24
+ return [];
25
+ const value = decodeKvValue2(await store.objects.get(ref.target));
26
+ return Value.Check(SavedListingType, value) ? [[ref.name.slice(MODEL_LISTINGS.length), value]] : [];
27
+ }));
28
+ return new Map(entries.flat());
29
+ }
30
+ function thinkingPreferenceRef2(model) {
31
+ return `${THINKING_PREFERENCES}${model.provider}/${model.id}`;
32
+ }
33
+ async function readThinkingPreference2(store, model) {
34
+ const ref = await store.refs.get(thinkingPreferenceRef2(model));
35
+ return ref === null || ref.target === null ? undefined : decodeThinking(await store.objects.get(ref.target));
36
+ }
37
+ async function readThinkingPreferences2(store) {
38
+ const refs = await store.refs.list(THINKING_PREFERENCES);
39
+ const entries = await Promise.all(refs.map(async (ref) => {
40
+ if (ref.target === null)
41
+ return [];
42
+ const level = decodeThinking(await store.objects.get(ref.target));
43
+ return level === undefined ? [] : [[ref.name.slice(THINKING_PREFERENCES.length), level]];
44
+ }));
45
+ return new Map(entries.flat());
46
+ }
47
+ function decodeThinking(object) {
48
+ const value = decodeKvValue2(object);
49
+ return Value.Check(ThinkingType, value) ? value : undefined;
50
+ }
13
51
  async function readModelSelection2(store) {
14
52
  const ref = await store.refs.get(MODEL_PREFERENCE2);
15
53
  const value = ref === null || ref.target === null ? undefined : decodeKvValue2(await store.objects.get(ref.target));
@@ -147,4 +185,4 @@ function createModelState2(changed) {
147
185
  };
148
186
  }
149
187
 
150
- export { MODEL_PREFERENCE2, readModelSelection2, createModelState2 };
188
+ export { MODEL_PREFERENCE2, modelListingRef2, readModelListings2, thinkingPreferenceRef2, readThinkingPreference2, readThinkingPreferences2, readModelSelection2, createModelState2 };