@qvac/harness 1.0.0-rc.16 → 1.0.0-rc.18
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.
- package/CHANGELOG.md +139 -2
- package/dist-lib/index.d.ts +6 -2
- package/dist-lib/index.js +17 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +28 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +1 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +13 -8
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +6 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +2 -2
- package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/durable.js +7 -1
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/operations.js +28 -9
- package/dist-lib/lib/capabilities/completion-engine/ports.js +3 -2
- package/dist-lib/lib/capabilities/completion-engine/prepare-step.d.ts +3 -1
- package/dist-lib/lib/capabilities/completion-engine/session.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/session.js +1 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +2 -1
- package/dist-lib/lib/capabilities/completion-engine/turns.js +5 -2
- package/dist-lib/lib/capabilities/enhance.js +3 -3
- package/dist-lib/lib/capabilities/sdk-tool.d.ts +1 -1
- package/dist-lib/lib/capabilities/sdk-tool.js +3 -2
- package/dist-lib/lib/capabilities/skill-entry.d.ts +9 -1
- package/dist-lib/lib/capabilities/skill-entry.js +11 -7
- package/dist-lib/lib/capabilities/tool-turns.d.ts +5 -0
- package/dist-lib/lib/capabilities/tool-turns.js +24 -27
- package/dist-lib/lib/client/index.js +3 -2
- package/dist-lib/lib/connect.d.ts +2 -0
- package/dist-lib/lib/connect.js +33 -3
- package/dist-lib/lib/contract/completion.d.ts +14 -0
- package/dist-lib/lib/contract/exec.d.ts +1 -0
- package/dist-lib/lib/contract/ocr.d.ts +4 -0
- package/dist-lib/lib/contract/run.d.ts +8 -0
- package/dist-lib/lib/contract-types.d.ts +4 -1
- package/dist-lib/lib/errors.d.ts +4 -0
- package/dist-lib/lib/errors.js +5 -1
- package/dist-lib/lib/guards.d.ts +2 -0
- package/dist-lib/lib/guards.js +7 -0
- package/dist-lib/lib/hardware/capability-probe.js +10 -7
- package/dist-lib/lib/hardware/gpu-probe-addon.js +26 -11
- package/dist-lib/lib/hardware/gpu-stats.native.cjs +17 -1
- package/dist-lib/lib/helpers/completion-params.d.ts +2 -1
- package/dist-lib/lib/helpers/completion-params.js +16 -1
- package/dist-lib/lib/helpers/control-tokens.d.ts +3 -0
- package/dist-lib/lib/helpers/control-tokens.js +25 -0
- package/dist-lib/lib/machine/completion/actions/completion.js +34 -5
- package/dist-lib/lib/machine/completion/actions/tools.js +4 -1
- package/dist-lib/lib/machine/completion/rules.d.ts +2 -0
- package/dist-lib/lib/machine/completion/rules.js +7 -0
- package/dist-lib/lib/machine/completion/types.d.ts +6 -0
- package/dist-lib/lib/machine/index.d.ts +2 -1
- package/dist-lib/lib/machine/index.js +2 -1
- package/dist-lib/lib/no-redirect-fetch-impl.d.ts +1 -1
- package/dist-lib/lib/no-redirect-fetch-impl.js +13 -7
- package/dist-lib/lib/office/engine/xlsx/sheet.js +10 -4
- package/dist-lib/lib/plugins/registry.d.ts +3 -0
- package/dist-lib/lib/plugins/registry.js +15 -1
- package/dist-lib/lib/plugins/require-bare.d.ts +1 -0
- package/dist-lib/lib/plugins/require-bare.js +13 -0
- package/dist-lib/lib/run-log/request-codec.js +2 -2
- package/dist-lib/lib/serve.js +38 -1
- package/dist-lib/lib/sidecar/index.d.ts +1 -1
- package/dist-lib/lib/sidecar/index.js +5 -6
- package/dist-lib/lib/skills-host/index.js +13 -8
- package/dist-lib/lib/spawn.d.ts +2 -0
- package/dist-lib/lib/spawn.js +5 -3
- package/dist-lib/lib/tools/ask-user.d.ts +2 -0
- package/dist-lib/lib/tools/ask-user.js +137 -0
- package/dist-lib/lib/tools/attachments/delivered.d.ts +5 -0
- package/dist-lib/lib/tools/attachments/delivered.js +16 -0
- package/dist-lib/lib/tools/attachments/fetched-file.d.ts +32 -0
- package/dist-lib/lib/tools/attachments/fetched-file.js +134 -0
- package/dist-lib/lib/tools/exec.js +2 -1
- package/dist-lib/lib/tools/fs/document-text.js +3 -26
- package/dist-lib/lib/tools/http-request/request.d.ts +2 -2
- package/dist-lib/lib/tools/http-request/request.js +1 -1
- package/dist-lib/lib/tools/http-request.d.ts +1 -0
- package/dist-lib/lib/tools/http-request.js +54 -3
- package/dist-lib/lib/tools/index.d.ts +3 -1
- package/dist-lib/lib/tools/index.js +6 -2
- package/dist-lib/lib/tools/office.js +20 -12
- package/dist-lib/lib/tools/pdf/pages.d.ts +12 -0
- package/dist-lib/lib/tools/pdf/pages.js +28 -0
- package/dist-lib/lib/tools/pdf.js +24 -9
- package/dist-lib/lib/tools/skills/bundled-dir.d.ts +5 -1
- package/dist-lib/lib/tools/skills/bundled-dir.js +23 -20
- package/dist-lib/lib/tools/skills/catalog.d.ts +1 -1
- package/dist-lib/lib/tools/skills/catalog.js +1 -1
- package/dist-lib/lib/tools/skills/overlay-crud.d.ts +3 -3
- package/dist-lib/lib/tools/skills/overlay-crud.js +4 -4
- package/dist-lib/lib/tools/skills/scope-key.d.ts +1 -0
- package/dist-lib/lib/tools/skills/scope-key.js +4 -0
- package/dist-lib/lib/tools/web-fetch.js +41 -130
- package/dist-lib/plugins/knowledge/index.js +3 -3
- package/dist-lib/plugins/mcp/call.js +5 -1
- package/dist-lib/plugins/mcp/protocol.d.ts +6 -1
- package/dist-lib/plugins/mcp/protocol.js +2 -2
- package/dist-lib/plugins/ocr/reading-order.js +151 -4
- package/dist-lib/plugins/python/bare-floor.d.ts +1 -0
- package/dist-lib/plugins/python/bare-floor.js +2 -0
- package/dist-lib/plugins/python/index.d.ts +1 -0
- package/dist-lib/plugins/python/index.js +1 -0
- package/dist-lib/plugins/python/language.js +9 -8
- package/dist-lib/plugins/python/python-adapter.d.ts +4 -0
- package/dist-lib/plugins/python/python-adapter.js +26 -0
- package/dist-lib/plugins/python/worker/client.js +1 -1
- package/dist-lib/plugins/python/worker/entry.js +2 -8
- package/dist-lib/plugins/python/worker/preload.d.ts +1 -0
- package/dist-lib/plugins/python/worker/preload.js +2 -0
- package/dist-lib/plugins/python/worker/spawn.js +1 -1
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/weather/lookup.js +1 -0
- package/dist-lib/schema/harness.js +17 -0
- package/dist-lib/spec/bind.js +3 -0
- package/dist-lib/spec/calls.js +1 -0
- package/dist-lib/spec/hrpc/hrpc.json +13 -0
- package/dist-lib/spec/hrpc/index.js +15 -3
- package/dist-lib/spec/hrpc/messages.js +32 -0
- package/dist-lib/spec/hyperschema/index.js +32 -0
- package/dist-lib/spec/hyperschema/schema.json +40 -0
- package/dist-lib/spec/hyperschema/types.d.ts +12 -0
- package/package.json +18 -9
package/CHANGELOG.md
CHANGED
|
@@ -21,6 +21,42 @@ breaking change is listed under Changed and Removed.
|
|
|
21
21
|
|
|
22
22
|
### Added
|
|
23
23
|
|
|
24
|
+
- A vision model sees an image a tool attaches. A call whose result attached a
|
|
25
|
+
file (`attachmentId`, or a list under `attachments`) offers it to a new host
|
|
26
|
+
port, `showImage({ attachmentId })`. The host answers with its own file for
|
|
27
|
+
the image, or `null`. Up to four a round ride the user turn that closes the
|
|
28
|
+
round, as its `attachments`, with a line naming them. A host without the
|
|
29
|
+
port changes nothing. Over the wire it is a `fetch-ask` with
|
|
30
|
+
`payload: { show: true }`, so the schema is unchanged.
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
harness.completion({
|
|
34
|
+
...run,
|
|
35
|
+
showImage: async ({ attachmentId }) => imageFileFor(attachmentId) // or null
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
See [the decision record](docs/decisions/2026-11-06-a-tool-image-rides-the-turn-closing-its-round.md).
|
|
40
|
+
|
|
41
|
+
- The model can ask the user with a form. `ask_user` takes a question and its
|
|
42
|
+
fields (single choice, multiple choice, date, short text, note, number;
|
|
43
|
+
`required` per field) and waits on `askUser`, which now carries the fields as
|
|
44
|
+
`form`. The host answers with a JSON object of field id to value, or `null`
|
|
45
|
+
for Skip; any other text reaches the model as the user's own reply. A form
|
|
46
|
+
with a file pick, an unknown type or a choice without options is refused.
|
|
47
|
+
Off by default: `Tools.product({ ask: true })`, or `spawnHarness({ ask: true })`
|
|
48
|
+
for the sidecar
|
|
49
|
+
([#728](https://github.com/tetherto/qvac-harness/issues/728)).
|
|
50
|
+
- `http_request` attaches a 2xx response whose `Content-Type` names a file
|
|
51
|
+
(PDF, Office, image, audio, video, any binary) to the chat instead of
|
|
52
|
+
returning it as text, and the result carries its `attachmentId`, `fileName`,
|
|
53
|
+
`mimeType` and `byteLength`. A skill reaches a private file with the
|
|
54
|
+
credential it already holds, such as a Drive file through `alt=media`. The
|
|
55
|
+
new `fileName` argument names it; without one, the server's
|
|
56
|
+
`Content-Disposition` or the URL does. The total timeout is 120 s, up from
|
|
57
|
+
30 s; a stalled server still fails at 10 s. A text file cut to the context
|
|
58
|
+
window, such as a long log, is attached whole beside the cut text, and the
|
|
59
|
+
`truncated` note says how to stage it into `exec` to read the rest. (#812)
|
|
24
60
|
- A scanned PDF page is read by OCR. The `ocr` plugin
|
|
25
61
|
(`@qvac/harness/plugins/ocr`) runs DocTR over the SDK's `ggml-ocr` as one
|
|
26
62
|
pooled model, unloaded when idle; `pdf` and `read_file` use it for a page with
|
|
@@ -471,6 +507,28 @@ breaking change is listed under Changed and Removed.
|
|
|
471
507
|
|
|
472
508
|
### Changed
|
|
473
509
|
|
|
510
|
+
- **Breaking:** `@qvac/harness` no longer depends on `@qvac/skills`; the host
|
|
511
|
+
installs the skills version it ships and hands it in.
|
|
512
|
+
`Tools.bundledSkillsDir(bundle)` takes `{ skills, hash }` (what
|
|
513
|
+
`@qvac/skills/bundled` and `@qvac/skills/hash` export) and materializes it
|
|
514
|
+
under a directory keyed on that hash, refusing a tree that does not hash to
|
|
515
|
+
it as before. A `Harness` or a sidecar given no `skillsDir` serves no base
|
|
516
|
+
skills, only the user's overlay, where it used to materialize the bundled
|
|
517
|
+
ones, and `SidecarContext.skillsDir` is then `undefined`. `Tools.product`
|
|
518
|
+
adds `skill` for a `skillCatalog` that lists a skill even with no
|
|
519
|
+
`skillsDir`, so the overlay can be loaded. `@qvac/skills` names the oldest
|
|
520
|
+
harness that loads it as a peer dependency. (#837)
|
|
521
|
+
|
|
522
|
+
```js
|
|
523
|
+
import { SKILLS } from '@qvac/skills/bundled'
|
|
524
|
+
import { SKILLS_HASH } from '@qvac/skills/hash'
|
|
525
|
+
|
|
526
|
+
// before
|
|
527
|
+
const skillsDir = await Tools.bundledSkillsDir()
|
|
528
|
+
// after
|
|
529
|
+
const skillsDir = await Tools.bundledSkillsDir({ skills: SKILLS, hash: SKILLS_HASH })
|
|
530
|
+
```
|
|
531
|
+
|
|
474
532
|
- Importing `@qvac/harness/plugins/image` or `@qvac/harness/plugins/music` no
|
|
475
533
|
longer needs their peers; constructing `Image` or `Music` without them throws
|
|
476
534
|
the error naming the plugin and the missing packages. A sidecar host passing no
|
|
@@ -995,8 +1053,7 @@ breaking change is listed under Changed and Removed.
|
|
|
995
1053
|
- **Breaking:** nothing a run does can load a new native addon: the sidecar
|
|
996
1054
|
seals addon loading once the harness is ready. A plugin or tool that imports
|
|
997
1055
|
a native addon lazily declares it in `HarnessPlugin.addons` or
|
|
998
|
-
`ToolDefinition.addons`.
|
|
999
|
-
`workerData.preload` is true. See the
|
|
1056
|
+
`ToolDefinition.addons`. See the
|
|
1000
1057
|
[decision record](docs/decisions/2026-10-02-the-sidecar-seals-addon-loading-after-boot.md).
|
|
1001
1058
|
(#177)
|
|
1002
1059
|
- **Breaking:** `SandboxWorkspace` gains `start(command, { cwd? })`, returning a
|
|
@@ -1187,6 +1244,61 @@ breaking change is listed under Changed and Removed.
|
|
|
1187
1244
|
|
|
1188
1245
|
### Fixed
|
|
1189
1246
|
|
|
1247
|
+
- Text that spells a chat-template token no longer becomes one. A tool result,
|
|
1248
|
+
file, page, user turn or tool description holding `<|im_start|>`,
|
|
1249
|
+
`<tool_response>`, `<think>` and the like reaches the model with a word joiner
|
|
1250
|
+
after the `<`, so its words are read but cannot open a turn. A log holding a
|
|
1251
|
+
captured prompt used to hand the model a fake user turn mid-run, and it
|
|
1252
|
+
answered that instead. A tool never sees the joiner: a call copying that text
|
|
1253
|
+
runs with it as the file held it. A tool result now reaches the model as the
|
|
1254
|
+
same bytes in its own run and on replay, where replay used to strip it. (#825)
|
|
1255
|
+
- A model that cannot see images now hears when a new `pptx`, `docx` or `xlsx`
|
|
1256
|
+
file leaves out the image the user uploaded. Without `turnImages` the tool
|
|
1257
|
+
said "Done", and a deck shipped without the image while the model claimed it
|
|
1258
|
+
was there. (#817)
|
|
1259
|
+
- `web_fetch` downloads a file of up to 100 MB, as large as one a user can
|
|
1260
|
+
attach, instead of refusing anything past 8 MB. The cap is picked from the
|
|
1261
|
+
response's `Content-Type`, so a page keeps its 8 MB budget, and a declared
|
|
1262
|
+
file attaches without being decoded as text first. A stalled download fails
|
|
1263
|
+
after 15 s without a byte; one that keeps arriving has 120 s, where any fetch
|
|
1264
|
+
used to stop at 15 s. (#811)
|
|
1265
|
+
- A tool that attaches a large file no longer stalls the run. Every host
|
|
1266
|
+
callback's input went through JSON twice and into the run journal whole, so
|
|
1267
|
+
a 24 MB file became tens of millions of object keys and the attach never
|
|
1268
|
+
reached the host. The bytes now go to the host as a copy, and the journal
|
|
1269
|
+
records them as `{ byteLength, sha256 }`, which a resume still matches. (#811)
|
|
1270
|
+
- `weather_lookup` is listed under `weather` in the `tool_search` catalog, not
|
|
1271
|
+
under its `http-request` toolset. The search scores a tool's heading, so a
|
|
1272
|
+
query such as "http request tool" also loaded the weather tool next to
|
|
1273
|
+
`http_request`. (#818)
|
|
1274
|
+
- The package loads on Bare 1.33.4, the runtime of `react-native-bare-kit`
|
|
1275
|
+
0.16.0: `engines.bare` is `>=1.33.4`, so a mobile host no longer patches it.
|
|
1276
|
+
Python still needs Bare 1.34.0, and importing `@qvac/harness/plugins/python`
|
|
1277
|
+
on an older Bare throws `@qvac/harness/plugins/python needs Bare 1.34.0 or
|
|
1278
|
+
later` instead of a stowed harness failing to open with `ADDON_NOT_FOUND` for
|
|
1279
|
+
`bare-channel`. A plugin names its own floor with
|
|
1280
|
+
`PluginRegistry.requireBare(plugin, floor)`. (#806)
|
|
1281
|
+
- The refusal for a skill that is `disconnected` or `needs-setup` carries
|
|
1282
|
+
`setup: { skill, state }` beside its `error`, so a host can offer the setup
|
|
1283
|
+
itself. Its text asks the model to say it once and to name no menu path,
|
|
1284
|
+
which a small model invented as "Settings → Skills".
|
|
1285
|
+
- `@qvac/turbovec-ggml` is an optional peer at `^0.3.1`. 0.3.0 depends on
|
|
1286
|
+
`@qvac/fabric` ^0.24.0 while every other model addon is on ^0.25.0, so a host
|
|
1287
|
+
that resolved it loaded two fabric copies into one process. A host whose lock
|
|
1288
|
+
holds 0.3.0 updates it. (#807)
|
|
1289
|
+
- A credential the host removes from `setCredentials` forgets its rejected
|
|
1290
|
+
verdict, so its skill reads as needing setup instead of disconnected, and a
|
|
1291
|
+
token pushed for the same key at another scope is probed afresh. (#807)
|
|
1292
|
+
- An MCP session is keyed by the token that opened it, so a token rotated under
|
|
1293
|
+
the same credential key opens its own session instead of reusing the old one,
|
|
1294
|
+
which a server that binds a session to its user refused with 403 and marked
|
|
1295
|
+
the fresh token rejected. (#807)
|
|
1296
|
+
- A `%` that starts no escape in an `http_request` URL (`?q=50%`) is kept as
|
|
1297
|
+
text, as in Node, instead of throwing `URI malformed` on Bare when `query` is
|
|
1298
|
+
also given; the skill-eval judge crashed on the same URL. Both now parse with
|
|
1299
|
+
the `bare-url` package, at least 2.5.6 (holepunchto/bare-url#46), instead of
|
|
1300
|
+
the global `URL` built into the Bare runtime, which no Bare release has
|
|
1301
|
+
updated yet. (#799)
|
|
1190
1302
|
- Calendar reads build their own query: validated arguments, encoded dates
|
|
1191
1303
|
and timezone offsets, and a local day range resolved from the turn's clock
|
|
1192
1304
|
that holds across pages and DST, so "today" and "tomorrow" no longer fail
|
|
@@ -1199,6 +1311,31 @@ breaking change is listed under Changed and Removed.
|
|
|
1199
1311
|
coalescing, or count/byte limits. Pending steer/follow-up inputs no longer have
|
|
1200
1312
|
admission limits in the engine or transport. Unread output and pending input
|
|
1201
1313
|
remain unbounded in memory.
|
|
1314
|
+
- A skill-gated tool is sent only once the run may call it, from the round its
|
|
1315
|
+
skill loads, so `tool_search`'s catalog no longer names it before. The catalog
|
|
1316
|
+
line read as a tool to search for and call, so a 9B asked for a PDF skipped the
|
|
1317
|
+
pdf skill and wrote Python with reportlab or fpdf instead: 4 of 5 runs on 0.8.12
|
|
1318
|
+
against 0 of 10 on 0.8.11. The tool joins on the round the SDK already
|
|
1319
|
+
re-prefills to declare what the skill loaded, so it costs no cache. A gated tool
|
|
1320
|
+
a small model may call early, such as `pdf` on a 2B, is sent from the first
|
|
1321
|
+
round. (QVAC-27769)
|
|
1322
|
+
- `exec` refuses Python that imports `reportlab`, `fpdf`, `pypdf` or `PyPDF2`,
|
|
1323
|
+
or declares their packages, before it runs, when the run offers the `pdf`
|
|
1324
|
+
tool, and names that tool instead, or the skill to load first when it has not
|
|
1325
|
+
loaded yet. Offline, a model asked for a PDF reached for reportlab before
|
|
1326
|
+
loading the pdf skill, could not install it, and wrote the PDF bytes by hand:
|
|
1327
|
+
the file attached as a success with only its title, or no text at all. A
|
|
1328
|
+
skill's own script and a run without the `pdf` tool still run as before. A
|
|
1329
|
+
tool now also gets `offeredTools`, every tool the run offers, alongside
|
|
1330
|
+
`toolNames`, the ones it can call now. (QVAC-27769)
|
|
1331
|
+
- A repeat save by the `pdf`, `pptx`, `docx` or `xlsx` tool in a later round of
|
|
1332
|
+
the same run, or after the run resumes, returns the file already attached
|
|
1333
|
+
instead of attaching it again. Each round got its own `attach`, which the
|
|
1334
|
+
tools' per-turn record keyed on, so a small model that called again delivered
|
|
1335
|
+
the same file twice. The record now lives in the run budget as `delivered`,
|
|
1336
|
+
saved with the run.
|
|
1337
|
+
- A `pdf` save under a name already attached with different content is refused
|
|
1338
|
+
as the Office tools already refuse it, instead of returning the old file.
|
|
1202
1339
|
- `tools/list` through `mcp_call` comes back as a line per tool, with each
|
|
1203
1340
|
argument's type and allowed values, and `params.names` gives the tools named
|
|
1204
1341
|
whole. Asana's 52 tools were 148 KB, so the model saw 5 of them cut or waited
|
package/dist-lib/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import ReadyResource from 'ready-resource';
|
|
|
3
3
|
import { Policy } from './lib/policy/index.ts';
|
|
4
4
|
import type { EngineBoot, EngineStep, RecoveryResolution } from './lib/run-log/index.ts';
|
|
5
5
|
import { type CompletionArgs, type ModelRoundIo, type ModelRoundPort, type ModelRoundRequest, type ModelRoundResult } from './lib/capabilities/completion-engine/index.ts';
|
|
6
|
-
import type { AccessPolicy, AgentConfig, ApproveFn, AskUserFn, AttachFn, CompletionEvent, FetchAttachmentFn, Message, ProgressFn, ResponseFormat, RunGoal, RunInput, ToolDefinition, ToolExecuteContext } from './lib/contract/index.ts';
|
|
6
|
+
import type { AccessPolicy, AgentConfig, ApproveFn, AskUserFn, AttachFn, CompletionEvent, FetchAttachmentFn, Message, ProgressFn, ResponseFormat, RunGoal, RunInput, ShowImageFn, ToolDefinition, ToolExecuteContext } from './lib/contract/index.ts';
|
|
7
7
|
import { type DetectLanguageContext, type DetectedLanguage } from './lib/capabilities/detect-language.ts';
|
|
8
8
|
import { type Capability } from './lib/capabilities/invoke.ts';
|
|
9
9
|
import { type ModelSourcePreview, type PreviewModelSourceContext } from './lib/capabilities/preview-model-source.ts';
|
|
@@ -12,6 +12,7 @@ import { type DownloadArgs, type DownloadEventStream } from './lib/capabilities/
|
|
|
12
12
|
import type { EmbedContext } from './lib/capabilities/embed.ts';
|
|
13
13
|
import { type KvCacheDeletionResult } from './lib/capabilities/kv-cache.ts';
|
|
14
14
|
import type { LlmGenerationParams } from './lib/models/llm-presets.ts';
|
|
15
|
+
import type { OcrReadContext } from './lib/contract/ocr.ts';
|
|
15
16
|
import type { SpeakContext, SpeakResult, SpeakStreamContext, TranscribeContext } from './lib/contract/speech.ts';
|
|
16
17
|
import type { CapabilityInfo, CredentialEntry, HarnessDiagnostics, InfraModel, LoadModelResult, MemoryUsage, SkillWriteResult, UnloadModelContext, UnloadModelResult } from './lib/contract-types.ts';
|
|
17
18
|
import { type CustomModelEntry } from './lib/models/model-catalog.ts';
|
|
@@ -44,7 +45,7 @@ export type { ModelSourceFile, ModelSourcePreview, ModelSourceRefusal, PreviewMo
|
|
|
44
45
|
export type { ModelFitBasis, ModelFitEvidence, ModelFitVerdict } from './lib/models/model-fit.ts';
|
|
45
46
|
export * from './lib/capabilities/download.ts';
|
|
46
47
|
export type { EmbedContext } from './lib/capabilities/embed.ts';
|
|
47
|
-
export type { OcrImage, OcrService } from './lib/contract/ocr.ts';
|
|
48
|
+
export type { OcrImage, OcrReadContext, OcrService } from './lib/contract/ocr.ts';
|
|
48
49
|
export type { SpeakContext, SpeakResult, SpeakStreamContext, SpeechService, TranscribeContext } from './lib/contract/speech.ts';
|
|
49
50
|
export type { EmbedDevice } from './lib/models/embed-config.ts';
|
|
50
51
|
export type { MemoryBudget } from './lib/hardware/memory-budget.ts';
|
|
@@ -154,6 +155,7 @@ export interface CompletionContext {
|
|
|
154
155
|
approve?: ApproveFn;
|
|
155
156
|
attach?: AttachFn;
|
|
156
157
|
fetchAttachment?: FetchAttachmentFn;
|
|
158
|
+
showImage?: ShowImageFn;
|
|
157
159
|
progress?: ProgressFn;
|
|
158
160
|
askUser?: AskUserFn;
|
|
159
161
|
boot?: EngineBoot;
|
|
@@ -285,6 +287,8 @@ export declare class Harness extends ReadyResource {
|
|
|
285
287
|
knowledgeStatus(): Promise<KnowledgeStatus>;
|
|
286
288
|
transcribe(context: TranscribeContext): Promise<string>;
|
|
287
289
|
private _transcribe;
|
|
290
|
+
ocrRead({ image, signal }: OcrReadContext): Promise<string>;
|
|
291
|
+
private _ocrService;
|
|
288
292
|
detectLanguage(context: DetectLanguageContext): Promise<DetectedLanguage[]>;
|
|
289
293
|
speak(context: SpeakContext): Promise<SpeakResult>;
|
|
290
294
|
private _speak;
|
package/dist-lib/index.js
CHANGED
|
@@ -77,6 +77,7 @@ export const PLUGIN_API_VERSION = PluginRegistry.API_VERSION;
|
|
|
77
77
|
const SUSPEND_SETTLE_MS = 500;
|
|
78
78
|
const SPEECH_PLUGIN_MISSING = 'speech needs the speech plugin';
|
|
79
79
|
const KNOWLEDGE_PLUGIN_MISSING = 'knowledge needs the knowledge plugin';
|
|
80
|
+
const OCR_PLUGIN_MISSING = 'ocr needs the ocr plugin';
|
|
80
81
|
const UNLOAD_FAILED = 'Runtime unload failed; close the harness before loading models again';
|
|
81
82
|
const HOST_SHELL = { name: 'host' };
|
|
82
83
|
function execOptions(exec) {
|
|
@@ -246,8 +247,10 @@ export class Harness extends ReadyResource {
|
|
|
246
247
|
async _open() {
|
|
247
248
|
try {
|
|
248
249
|
installResolutionDetector(import.meta);
|
|
250
|
+
const core = PluginRegistry.loadAddons('the harness', this._sdk.addons);
|
|
251
|
+
core.catch(noop);
|
|
249
252
|
await this._startPlugins();
|
|
250
|
-
await this._loadAddons();
|
|
253
|
+
await this._loadAddons(core);
|
|
251
254
|
await this._skills.open();
|
|
252
255
|
HarnessLog.info('open', { skills: this._skills.names.length, tools: this._tools.length });
|
|
253
256
|
}
|
|
@@ -376,9 +379,9 @@ export class Harness extends ReadyResource {
|
|
|
376
379
|
sdk: () => this._sdk.loadEmbed()
|
|
377
380
|
};
|
|
378
381
|
}
|
|
379
|
-
async _loadAddons() {
|
|
382
|
+
async _loadAddons(core) {
|
|
380
383
|
await Promise.all([
|
|
381
|
-
|
|
384
|
+
core,
|
|
382
385
|
...this._tools.map((tool) => PluginRegistry.loadAddons(`tool '${tool.name}'`, tool.addons))
|
|
383
386
|
]);
|
|
384
387
|
}
|
|
@@ -653,6 +656,17 @@ export class Harness extends ReadyResource {
|
|
|
653
656
|
signal
|
|
654
657
|
});
|
|
655
658
|
}
|
|
659
|
+
ocrRead({ image, signal }) {
|
|
660
|
+
return this._residency.busy(async () => (await this._ocrService()).read(image, signal));
|
|
661
|
+
}
|
|
662
|
+
async _ocrService() {
|
|
663
|
+
if (!this.opened)
|
|
664
|
+
await this.ready();
|
|
665
|
+
if (!this._plugins.ctx.ocr) {
|
|
666
|
+
throw new Error(OCR_PLUGIN_MISSING);
|
|
667
|
+
}
|
|
668
|
+
return this._plugins.ctx.ocr;
|
|
669
|
+
}
|
|
656
670
|
detectLanguage(context) {
|
|
657
671
|
return detectLanguage(context);
|
|
658
672
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CompletionActor, CompletionActorInput } from '../session.ts';
|
|
2
2
|
import { type ToolExecutionPlan } from './execution-plan.ts';
|
|
3
3
|
import { type ToolCallRunResult } from './execute.ts';
|
|
4
|
-
import type
|
|
4
|
+
import { type CompletionContext, type ShownImage } from '../../../machine/index.ts';
|
|
5
5
|
import type { CompletionEvent } from '../../../contract/index.ts';
|
|
6
6
|
import type { ToolDonePayload, ToolExecutionSnapshot } from '../stages.ts';
|
|
7
7
|
export declare const executing: CompletionActor<ToolDonePayload>;
|
|
@@ -16,6 +16,7 @@ export interface RanCall {
|
|
|
16
16
|
landedBefore: number;
|
|
17
17
|
executed: ToolCallRunResult;
|
|
18
18
|
durationMs: number;
|
|
19
|
+
shown?: ShownImage[] | undefined;
|
|
19
20
|
}
|
|
20
21
|
export declare function runCall({ input: deps, context }: CompletionActorInput, { plan: vetted, execution, emit }: RunCallInput): Promise<RanCall>;
|
|
21
22
|
interface SettleCallInput {
|
|
@@ -4,12 +4,13 @@ import { spliceFrom } from '../splice.js';
|
|
|
4
4
|
import { answerOf, callSucceeded, readyPreflightFromFacts, reportFailure, settledFailure } from '../tool-execution.js';
|
|
5
5
|
import { directToolHistory } from '../turns.js';
|
|
6
6
|
import { labelOf } from '../loop.js';
|
|
7
|
-
import { DIRECT_CALL_ID, FAILURE_STREAK, TOOL_FAILING_MESSAGE, deliversFile, historyPayload, materializeCompletionHistory, withHookContext, toolResultHistoryEntry, toolResultTurn } from '../../tool-turns.js';
|
|
7
|
+
import { attachedFiles, DIRECT_CALL_ID, FAILURE_STREAK, TOOL_FAILING_MESSAGE, deliversFile, historyPayload, materializeCompletionHistory, withHookContext, toolResultHistoryEntry, toolResultTurn } from '../../tool-turns.js';
|
|
8
8
|
import { defers, TOOL_SEARCH_TOOL_NAME } from '../../sdk-tool.js';
|
|
9
9
|
import { executionPlan, trustedSources } from './execution-plan.js';
|
|
10
10
|
import { runToolCall } from './execute.js';
|
|
11
11
|
import { toolCaller } from '../tool-caller.js';
|
|
12
12
|
import { loadSkill } from './loading-skill.js';
|
|
13
|
+
import { CompletionMachine } from '../../../machine/index.js';
|
|
13
14
|
import { failureResultRef, storeFailureResult } from '../../../helpers/failure-result.js';
|
|
14
15
|
import { namesPath, provesResult, runsCheck, writtenTexts } from '../../../helpers/goal-check.js';
|
|
15
16
|
const CHECK_OUTPUT_CHARS = 2000;
|
|
@@ -52,6 +53,7 @@ export const executing = async function executing(input) {
|
|
|
52
53
|
answer: settled.answer,
|
|
53
54
|
delivered: settled.delivered,
|
|
54
55
|
deliveryEndsRun: settled.deliveryEndsRun,
|
|
56
|
+
shown: settled.shown,
|
|
55
57
|
endedRun: succeeded && plan.resolved.tool.endsRun === true ? true : undefined,
|
|
56
58
|
durationMs: settled.durationMs,
|
|
57
59
|
checked: settled.checked,
|
|
@@ -107,7 +109,8 @@ export async function runCall({ input: deps, context }, { plan: vetted, executio
|
|
|
107
109
|
display
|
|
108
110
|
});
|
|
109
111
|
const durationMs = Date.now() - startedAt;
|
|
110
|
-
const
|
|
112
|
+
const succeeded = callSucceeded(executed.output, executed.outcome);
|
|
113
|
+
const output = succeeded
|
|
111
114
|
? executed.output
|
|
112
115
|
: await reportFailure(session.pipeline, {
|
|
113
116
|
runId: session.runId,
|
|
@@ -119,7 +122,28 @@ export async function runCall({ input: deps, context }, { plan: vetted, executio
|
|
|
119
122
|
outcome: executed.outcome,
|
|
120
123
|
result: executed.output
|
|
121
124
|
});
|
|
122
|
-
|
|
125
|
+
const shown = succeeded ? await shownImages(args.showImage, output, args.signal) : undefined;
|
|
126
|
+
return { plan, denied, landedBefore, executed: { ...executed, output }, durationMs, shown };
|
|
127
|
+
}
|
|
128
|
+
async function shownImages(show, output, signal) {
|
|
129
|
+
if (!show) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
const shown = [];
|
|
133
|
+
for (const { attachmentId, fileName } of attachedFiles(output)) {
|
|
134
|
+
if (shown.length === CompletionMachine.MAX_SHOWN_IMAGES) {
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
const path = await show({ attachmentId, signal }).catch((err) => {
|
|
138
|
+
if (signal?.aborted)
|
|
139
|
+
throw err;
|
|
140
|
+
return null;
|
|
141
|
+
});
|
|
142
|
+
if (path) {
|
|
143
|
+
shown.push({ path, fileName });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return shown.length ? shown : undefined;
|
|
123
147
|
}
|
|
124
148
|
function withRunPorts({ input: deps, context }, { plan, denied, emit }) {
|
|
125
149
|
const { tool, call } = plan.resolved;
|
|
@@ -200,6 +224,7 @@ export function settleCall({ input: { session }, context }, { ran, direct, emit
|
|
|
200
224
|
answer: succeeded ? answerOf(output) : undefined,
|
|
201
225
|
delivered: delivered ? true : undefined,
|
|
202
226
|
deliveryEndsRun: delivered && plan.resolved.tool.deliversMany !== true ? true : undefined,
|
|
227
|
+
shown: ran.shown,
|
|
203
228
|
durationMs: executed.executed ? durationMs : undefined,
|
|
204
229
|
checked: executed.executed
|
|
205
230
|
? checksRun(context, {
|
|
@@ -32,6 +32,7 @@ export function toolContext({ deps, context, name }) {
|
|
|
32
32
|
fsWriteRoots: session.writableRoots,
|
|
33
33
|
policy: session.access,
|
|
34
34
|
toolNames: session.enabled.map((tool) => tool.name),
|
|
35
|
+
offeredTools: [...session.grantable],
|
|
35
36
|
knowledge: args.knowledge,
|
|
36
37
|
ocr: deps.services?.ocr,
|
|
37
38
|
planMode: context.planMode,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ToolPolicyFacts } from '../../tool-plan.ts';
|
|
2
|
-
import type
|
|
2
|
+
import { type CompletionActor, type CompletionDeps } from '../session.ts';
|
|
3
3
|
import type { CompletionContext } from '../../../machine/index.ts';
|
|
4
4
|
import type { InspectingOutput, ResolvedCallSnapshot } from '../stages.ts';
|
|
5
5
|
import type { ResourceDescriptor } from '../../../contract/index.ts';
|
|
@@ -2,9 +2,10 @@ import { AbortedError } from '../../../helpers/race-abort.js';
|
|
|
2
2
|
import { HarnessLog } from '../../../log.js';
|
|
3
3
|
import { Agent } from '../../../agent/index.js';
|
|
4
4
|
import { planToolCall } from '../../tool-plan.js';
|
|
5
|
+
import { loadedSkills } from '../session.js';
|
|
5
6
|
import { approvalGate, resolvedCall, toolContext, trustedSources } from './execution-plan.js';
|
|
6
7
|
import { detachJson } from '../../../helpers/detach-json.js';
|
|
7
|
-
import {
|
|
8
|
+
import { unreadySkillRefusal } from '../../skill-entry.js';
|
|
8
9
|
import { deniedWithoutApprover, gateRejection, policyActivity } from './rejection.js';
|
|
9
10
|
export const inspecting = async function inspecting({ input: deps, context }) {
|
|
10
11
|
const snapshot = context.currentCall;
|
|
@@ -89,7 +90,7 @@ export function inspectCall(deps, context, snapshot) {
|
|
|
89
90
|
resource,
|
|
90
91
|
call: snapshot,
|
|
91
92
|
answeredRead,
|
|
92
|
-
unknownTool: unknownToolError(session, resolved.call.name)
|
|
93
|
+
unknownTool: unknownToolError(session, context, resolved.call.name)
|
|
93
94
|
});
|
|
94
95
|
return {
|
|
95
96
|
call: snapshot,
|
|
@@ -111,11 +112,12 @@ export function inspectCall(deps, context, snapshot) {
|
|
|
111
112
|
rejection
|
|
112
113
|
};
|
|
113
114
|
}
|
|
114
|
-
function unknownToolError(session, name) {
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
? (Agent.collectToolGrants(session.inContextSkills).grantedOwners.get(name) ?? [])
|
|
115
|
+
function unknownToolError(session, context, name) {
|
|
116
|
+
const loaded = loadedSkills(context, session);
|
|
117
|
+
const owners = session.grantable.has(name)
|
|
118
|
+
? [...(Agent.collectToolGrants(session.inContextSkills).grantedOwners.get(name) ?? [])]
|
|
118
119
|
: [];
|
|
120
|
+
const owner = owners.find((skill) => !loaded.has(skill));
|
|
119
121
|
return owner
|
|
120
122
|
? `${name} needs the ${owner} skill. Load it first, then call ${name}.`
|
|
121
123
|
: `unknown tool: ${name}`;
|
|
@@ -137,8 +139,11 @@ function inspectRejection({ context, plan, execution, resource, call, answeredRe
|
|
|
137
139
|
};
|
|
138
140
|
}
|
|
139
141
|
if (plan.skillStatus) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
return {
|
|
143
|
+
...base,
|
|
144
|
+
result: unreadySkillRefusal(plan.skillName, plan.skillStatus),
|
|
145
|
+
activity: policyActivity({ call, effect, resource })
|
|
146
|
+
};
|
|
142
147
|
}
|
|
143
148
|
if (plan.skillCall && (!plan.toolAvailable || !plan.skillActive)) {
|
|
144
149
|
return {
|
|
@@ -111,8 +111,9 @@ async function prepare({ input, context, reconstruct, source, emit }) {
|
|
|
111
111
|
const names = new Set(resolved.select(loaded).map(({ name }) => name));
|
|
112
112
|
return catalog.filter(({ name }) => name === TOOL_SEARCH_TOOL_NAME || names.has(name));
|
|
113
113
|
};
|
|
114
|
+
const sendable = (tools) => toSdkTools(catalog, new Set(tools.map(({ name }) => name)));
|
|
114
115
|
const enabled = callable(loadedSkills);
|
|
115
|
-
const sdkTools =
|
|
116
|
+
const sdkTools = sendable(enabled);
|
|
116
117
|
const { skillsSelected } = activation;
|
|
117
118
|
const sent = reconstruct ? context.history[0] : undefined;
|
|
118
119
|
let systemContent = sent && 'role' in sent && sent.role === 'system' ? sent.content : system.text;
|
|
@@ -140,8 +141,9 @@ async function prepare({ input, context, reconstruct, source, emit }) {
|
|
|
140
141
|
const changed = names !== session.enabled.map((tool) => tool.name).join();
|
|
141
142
|
if (changed) {
|
|
142
143
|
session.enabled = reselected;
|
|
144
|
+
session.sdkTools = sendable(reselected);
|
|
143
145
|
}
|
|
144
|
-
const tools = renderedTools(sdkTools, history);
|
|
146
|
+
const tools = renderedTools(session.sdkTools, history);
|
|
145
147
|
const prefix = promptPrefixHash({ system: systemContent, tools });
|
|
146
148
|
if (changed) {
|
|
147
149
|
logSelection(prefix);
|
|
@@ -153,7 +155,7 @@ async function prepare({ input, context, reconstruct, source, emit }) {
|
|
|
153
155
|
systemContent = systemParts.text;
|
|
154
156
|
session.promptParts = promptUsageParts({
|
|
155
157
|
system: systemParts,
|
|
156
|
-
toolSchemas: renderedTools(sdkTools, history)
|
|
158
|
+
toolSchemas: renderedTools(session.sdkTools, history)
|
|
157
159
|
});
|
|
158
160
|
return systemContent;
|
|
159
161
|
};
|
|
@@ -192,6 +194,7 @@ async function prepare({ input, context, reconstruct, source, emit }) {
|
|
|
192
194
|
prepareSession(session, {
|
|
193
195
|
enabled,
|
|
194
196
|
sdkTools,
|
|
197
|
+
grantable: new Set(catalog.map(({ name }) => name)),
|
|
195
198
|
grantedOps,
|
|
196
199
|
activation,
|
|
197
200
|
inContextSkills,
|
|
@@ -7,7 +7,7 @@ import { skillLoadTurns } from '../../sdk-tool.js';
|
|
|
7
7
|
import { Agent } from '../../../agent/index.js';
|
|
8
8
|
import { errorMessage, isRecord } from '../../../guards.js';
|
|
9
9
|
import { isFailureResultReference } from '../../../helpers/failure-result.js';
|
|
10
|
-
import { mentionHandle,
|
|
10
|
+
import { mentionHandle, unreadySkillRefusal, unreadySkillState } from '../../skill-entry.js';
|
|
11
11
|
export const skillStep = {
|
|
12
12
|
label: 'Skill loading',
|
|
13
13
|
propose({ session }, { preload }) {
|
|
@@ -27,7 +27,7 @@ export const skillStep = {
|
|
|
27
27
|
refusal({ args }, step) {
|
|
28
28
|
const name = skillOf(step);
|
|
29
29
|
const state = unreadySkillState(name, args.skillCatalog ?? []);
|
|
30
|
-
return state ?
|
|
30
|
+
return state ? unreadySkillRefusal(name, state) : null;
|
|
31
31
|
},
|
|
32
32
|
settle({ deps, context, step, result, announce }) {
|
|
33
33
|
const { session } = deps;
|
|
@@ -54,10 +54,11 @@ export interface DurableFacts extends Record<string, unknown> {
|
|
|
54
54
|
}
|
|
55
55
|
export interface ToolOperationFacts {
|
|
56
56
|
backends: RunBackendUse[];
|
|
57
|
-
runBudget: Pick<RunBudget, 'outputBytesUsed'>;
|
|
57
|
+
runBudget: Pick<RunBudget, 'outputBytesUsed' | 'delivered'>;
|
|
58
58
|
outcome: Pick<RunOutcomeState, 'confirmedWrites'>;
|
|
59
59
|
}
|
|
60
60
|
export declare function captureFacts(session: Session): DurableFacts;
|
|
61
61
|
export declare function captureToolOperationFacts(session: Session): ToolOperationFacts;
|
|
62
|
+
export declare function laterDelivered(current: RunBudget['delivered'], recorded: RunBudget['delivered']): RunBudget['delivered'];
|
|
62
63
|
export declare function restoreFacts(deps: CompletionDeps, facts: DurableFacts): void;
|
|
63
64
|
export {};
|
|
@@ -106,10 +106,16 @@ export function captureFacts(session) {
|
|
|
106
106
|
export function captureToolOperationFacts(session) {
|
|
107
107
|
return copy({
|
|
108
108
|
backends: [...session.backends],
|
|
109
|
-
runBudget: {
|
|
109
|
+
runBudget: {
|
|
110
|
+
outputBytesUsed: session.runBudget.outputBytesUsed,
|
|
111
|
+
delivered: session.runBudget.delivered
|
|
112
|
+
},
|
|
110
113
|
outcome: { confirmedWrites: session.runOutcomes.snapshot().confirmedWrites }
|
|
111
114
|
});
|
|
112
115
|
}
|
|
116
|
+
export function laterDelivered(current, recorded) {
|
|
117
|
+
return (recorded?.length ?? 0) > (current?.length ?? 0) ? recorded : current;
|
|
118
|
+
}
|
|
113
119
|
export function restoreFacts(deps, facts) {
|
|
114
120
|
facts = copy(facts);
|
|
115
121
|
const session = deps.session;
|
|
@@ -2,7 +2,7 @@ import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
|
|
|
2
2
|
import type { RecoveryResolution } from '../../run-log/index.ts';
|
|
3
3
|
import type { KnowledgeGrant } from '../../contract/knowledge.ts';
|
|
4
4
|
import type { ToolCallDisplay } from '../../contract/index.ts';
|
|
5
|
-
import type { AgentConfig, AccessPolicy, CompiledPolicy, CompletionEvent, ApproveFn, AskUserFn, AttachFn, DriveRoot, FetchAttachmentFn, LlmGenerationParams, Message, ProgressFn, ResponseFormat, RunBudget, RunGoal, RunInput, RoundModelLease, ToolDefinition, ToolExecuteContext } from '../../contract/index.ts';
|
|
5
|
+
import type { AgentConfig, AccessPolicy, CompiledPolicy, CompletionEvent, ApproveFn, AskUserFn, AttachFn, DriveRoot, FetchAttachmentFn, LlmGenerationParams, Message, ProgressFn, ResponseFormat, RunBudget, RunGoal, RunInput, RoundModelLease, ShowImageFn, ToolDefinition, ToolExecuteContext } from '../../contract/index.ts';
|
|
6
6
|
import type { CompletionSkillEntry } from '../skill-entry.ts';
|
|
7
7
|
import type { ModelRoundPort } from './model-round.ts';
|
|
8
8
|
export interface CompletionArgs {
|
|
@@ -32,6 +32,7 @@ export interface CompletionArgs {
|
|
|
32
32
|
approve?: ApproveFn;
|
|
33
33
|
attach?: AttachFn;
|
|
34
34
|
fetchAttachment?: FetchAttachmentFn;
|
|
35
|
+
showImage?: ShowImageFn;
|
|
35
36
|
progress?: ProgressFn;
|
|
36
37
|
askUser?: AskUserFn;
|
|
37
38
|
signal?: BareAbortSignal;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'crypto';
|
|
2
2
|
import { normalizeToolExecutionOutcome, writeResult } from '../../helpers/run-outcome.js';
|
|
3
3
|
import { isMetadataMethod } from '../../helpers/mcp-methods.js';
|
|
4
|
-
import { captureFacts, captureToolOperationFacts, restoreFacts } from './durable.js';
|
|
4
|
+
import { captureFacts, captureToolOperationFacts, laterDelivered, restoreFacts } from './durable.js';
|
|
5
5
|
import { AbortedError } from '../../helpers/race-abort.js';
|
|
6
6
|
import { isRecord } from '../../guards.js';
|
|
7
7
|
import { detachJson } from '../../helpers/detach-json.js';
|
|
@@ -43,11 +43,13 @@ export function toolOperationFacts(value) {
|
|
|
43
43
|
}
|
|
44
44
|
const backends = value.backends.filter(isBackendUse);
|
|
45
45
|
const runBudget = value.runBudget.outputBytesUsed;
|
|
46
|
+
const delivered = value.runBudget.delivered;
|
|
46
47
|
const outcome = value.outcome;
|
|
47
48
|
if (backends.length !== value.backends.length ||
|
|
48
49
|
typeof runBudget !== 'number' ||
|
|
49
50
|
!Number.isSafeInteger(runBudget) ||
|
|
50
51
|
runBudget < 0 ||
|
|
52
|
+
(delivered !== undefined && !(Array.isArray(delivered) && delivered.every(isDeliveredFile))) ||
|
|
51
53
|
!isRecord(outcome) ||
|
|
52
54
|
!Array.isArray(outcome.confirmedWrites)) {
|
|
53
55
|
throw new TypeError('Malformed tool operation facts');
|
|
@@ -56,7 +58,19 @@ export function toolOperationFacts(value) {
|
|
|
56
58
|
if (confirmedWrites.length !== outcome.confirmedWrites.length) {
|
|
57
59
|
throw new TypeError('Malformed tool operation facts');
|
|
58
60
|
}
|
|
59
|
-
return {
|
|
61
|
+
return {
|
|
62
|
+
backends,
|
|
63
|
+
runBudget: { outputBytesUsed: runBudget, delivered },
|
|
64
|
+
outcome: { confirmedWrites }
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function isDeliveredFile(value) {
|
|
68
|
+
return (isRecord(value) &&
|
|
69
|
+
typeof value.name === 'string' &&
|
|
70
|
+
typeof value.sha256 === 'string' &&
|
|
71
|
+
typeof value.attachmentId === 'string' &&
|
|
72
|
+
typeof value.fileName === 'string' &&
|
|
73
|
+
typeof value.byteLength === 'number');
|
|
60
74
|
}
|
|
61
75
|
function runHookOperation({ deps, base, phase, id, name, payload, check, run }) {
|
|
62
76
|
check();
|
|
@@ -71,8 +85,8 @@ function wrapHostCallback({ deps, check, prefix, stage, callId, name, effect, ca
|
|
|
71
85
|
const release = deps.session.trackInvoke();
|
|
72
86
|
try {
|
|
73
87
|
check();
|
|
74
|
-
const journalInput = detachHostCallbackInput(input);
|
|
75
|
-
const callbackInput = detachHostCallbackInput(
|
|
88
|
+
const journalInput = detachHostCallbackInput(input, digestBytes);
|
|
89
|
+
const callbackInput = detachHostCallbackInput(input, (bytes) => Uint8Array.from(bytes));
|
|
76
90
|
return await deps.operations.operation({
|
|
77
91
|
id: `${prefix}:${stage}:${callId}:host-${name}-${count++}`,
|
|
78
92
|
name: `host:${name}`,
|
|
@@ -85,13 +99,17 @@ function wrapHostCallback({ deps, check, prefix, stage, callId, name, effect, ca
|
|
|
85
99
|
}
|
|
86
100
|
};
|
|
87
101
|
}
|
|
88
|
-
function detachHostCallbackInput(input) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
Reflect.set(detached, 'bytes', Uint8Array.from(input.bytes));
|
|
102
|
+
function detachHostCallbackInput(input, bytesAs) {
|
|
103
|
+
if (!isRecord(input) || !(input.bytes instanceof Uint8Array)) {
|
|
104
|
+
return detachJson(input);
|
|
92
105
|
}
|
|
106
|
+
const detached = detachJson({ ...input, bytes: null });
|
|
107
|
+
Reflect.set(detached, 'bytes', bytesAs(input.bytes));
|
|
93
108
|
return detached;
|
|
94
109
|
}
|
|
110
|
+
function digestBytes(bytes) {
|
|
111
|
+
return { byteLength: bytes.byteLength, sha256: createHash('sha256').update(bytes).digest('hex') };
|
|
112
|
+
}
|
|
95
113
|
function plannedEffect(context, { stage, callId, name }) {
|
|
96
114
|
if (context.execution && context.currentCall?.name === name) {
|
|
97
115
|
return context.execution.effect;
|
|
@@ -146,7 +164,8 @@ export function bindOperations(deps, context, stage) {
|
|
|
146
164
|
runBudget: {
|
|
147
165
|
deadlineMs: current.runBudget.deadlineMs,
|
|
148
166
|
totalMs: current.runBudget.totalMs,
|
|
149
|
-
outputBytesUsed: Math.max(current.runBudget.outputBytesUsed, recorded.runBudget.outputBytesUsed)
|
|
167
|
+
outputBytesUsed: Math.max(current.runBudget.outputBytesUsed, recorded.runBudget.outputBytesUsed),
|
|
168
|
+
delivered: laterDelivered(current.runBudget.delivered, recorded.runBudget.delivered)
|
|
150
169
|
},
|
|
151
170
|
outcome: {
|
|
152
171
|
...current.outcome,
|