@qvac/harness 1.0.0-rc.17 → 1.0.0-rc.19

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 +59 -6
  2. package/dist-lib/index.d.ts +3 -1
  3. package/dist-lib/index.js +30 -0
  4. package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +3 -2
  5. package/dist-lib/lib/capabilities/completion-engine/loop.js +4 -1
  6. package/dist-lib/lib/connect.d.ts +2 -0
  7. package/dist-lib/lib/connect.js +57 -0
  8. package/dist-lib/lib/contract/completion.d.ts +2 -0
  9. package/dist-lib/lib/contract/index.d.ts +1 -0
  10. package/dist-lib/lib/contract/media.d.ts +51 -0
  11. package/dist-lib/lib/contract/media.js +1 -0
  12. package/dist-lib/lib/contract/models.d.ts +2 -0
  13. package/dist-lib/lib/contract-types.d.ts +3 -1
  14. package/dist-lib/lib/errors.d.ts +8 -0
  15. package/dist-lib/lib/errors.js +9 -1
  16. package/dist-lib/lib/machine/completion/actions/completion.d.ts +1 -1
  17. package/dist-lib/lib/machine/completion/actions/completion.js +3 -7
  18. package/dist-lib/lib/machine/completion/implementations.d.ts +3 -3
  19. package/dist-lib/lib/machine/completion/implementations.js +4 -4
  20. package/dist-lib/lib/machine/completion/machine.d.ts +3 -3
  21. package/dist-lib/lib/machine/completion/machine.js +3 -3
  22. package/dist-lib/lib/machine/index.d.ts +3 -3
  23. package/dist-lib/lib/media-host.d.ts +12 -0
  24. package/dist-lib/lib/media-host.js +52 -0
  25. package/dist-lib/lib/media-port.d.ts +20 -0
  26. package/dist-lib/lib/media-port.js +77 -0
  27. package/dist-lib/lib/media-wire.d.ts +8 -0
  28. package/dist-lib/lib/media-wire.js +96 -0
  29. package/dist-lib/lib/office/engine/xlsx/sheet.js +10 -4
  30. package/dist-lib/lib/plugins/registry.d.ts +3 -0
  31. package/dist-lib/lib/serve.js +37 -1
  32. package/dist-lib/lib/sidecar/index.d.ts +1 -1
  33. package/dist-lib/lib/sidecar/index.js +3 -5
  34. package/dist-lib/lib/skills-host/index.js +6 -7
  35. package/dist-lib/lib/tools/index.d.ts +1 -0
  36. package/dist-lib/lib/tools/index.js +1 -1
  37. package/dist-lib/lib/tools/pdf/pages.js +6 -3
  38. package/dist-lib/lib/tools/pdf/recognize.js +2 -1
  39. package/dist-lib/lib/tools/skills/bundled-dir.d.ts +5 -1
  40. package/dist-lib/lib/tools/skills/bundled-dir.js +23 -20
  41. package/dist-lib/lib/tools/skills/catalog.d.ts +1 -1
  42. package/dist-lib/lib/tools/skills/catalog.js +1 -1
  43. package/dist-lib/lib/tools/skills/overlay-crud.d.ts +3 -3
  44. package/dist-lib/lib/tools/skills/overlay-crud.js +4 -4
  45. package/dist-lib/plugins/image/edit-image.js +3 -9
  46. package/dist-lib/plugins/image/generate-image.d.ts +14 -2
  47. package/dist-lib/plugins/image/generate-image.js +94 -8
  48. package/dist-lib/plugins/image/index.d.ts +2 -1
  49. package/dist-lib/plugins/image/index.js +8 -3
  50. package/dist-lib/plugins/music/generate-music.d.ts +18 -2
  51. package/dist-lib/plugins/music/generate-music.js +98 -16
  52. package/dist-lib/plugins/music/index.d.ts +2 -1
  53. package/dist-lib/plugins/music/index.js +6 -2
  54. package/dist-lib/plugins/python/bare-floor.js +1 -1
  55. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  56. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  57. package/dist-lib/plugins/walkie-talkie/index.d.ts +2 -0
  58. package/dist-lib/plugins/walkie-talkie/index.js +6 -1
  59. package/dist-lib/schema/generate.js +8 -1
  60. package/dist-lib/schema/harness.js +9 -2
  61. package/dist-lib/spec/hrpc/messages.js +46 -4
  62. package/dist-lib/spec/hyperschema/index.js +46 -4
  63. package/dist-lib/spec/hyperschema/schema.json +28 -0
  64. package/dist-lib/spec/hyperschema/types.d.ts +2 -2
  65. package/package.json +8 -9
package/CHANGELOG.md CHANGED
@@ -21,6 +21,19 @@ breaking change is listed under Changed and Removed.
21
21
 
22
22
  ### Added
23
23
 
24
+ - Image and music generation can run on a device that holds the model. A run
25
+ that passes `mediaRound` has `generate_image`, `edit_image` and
26
+ `generate_music` ask it for the model call, and the device with the model
27
+ answers through `serveMediaRound(request, io)`; parsing, attaching and
28
+ progress stay with the run. A host without the model refuses with
29
+ `MEDIA_MODEL_MISSING` and downloads nothing, so the caller can ask another
30
+ device. It crosses the sidecar and worker wire as model rounds do. See
31
+ [docs/hosting.md](docs/hosting.md). (#845, #849)
32
+
33
+ ```js
34
+ owner.completion({ ...run, mediaRound: (request, io) => host.serveMediaRound(request, io) })
35
+ ```
36
+
24
37
  - A vision model sees an image a tool attaches. A call whose result attached a
25
38
  file (`attachmentId`, or a list under `attachments`) offers it to a new host
26
39
  port, `showImage({ attachmentId })`. The host answers with its own file for
@@ -507,6 +520,28 @@ breaking change is listed under Changed and Removed.
507
520
 
508
521
  ### Changed
509
522
 
523
+ - **Breaking:** `@qvac/harness` no longer depends on `@qvac/skills`; the host
524
+ installs the skills version it ships and hands it in.
525
+ `Tools.bundledSkillsDir(bundle)` takes `{ skills, hash }` (what
526
+ `@qvac/skills/bundled` and `@qvac/skills/hash` export) and materializes it
527
+ under a directory keyed on that hash, refusing a tree that does not hash to
528
+ it as before. A `Harness` or a sidecar given no `skillsDir` serves no base
529
+ skills, only the user's overlay, where it used to materialize the bundled
530
+ ones, and `SidecarContext.skillsDir` is then `undefined`. `Tools.product`
531
+ adds `skill` for a `skillCatalog` that lists a skill even with no
532
+ `skillsDir`, so the overlay can be loaded. `@qvac/skills` names the oldest
533
+ harness that loads it as a peer dependency. (#837)
534
+
535
+ ```js
536
+ import { SKILLS } from '@qvac/skills/bundled'
537
+ import { SKILLS_HASH } from '@qvac/skills/hash'
538
+
539
+ // before
540
+ const skillsDir = await Tools.bundledSkillsDir()
541
+ // after
542
+ const skillsDir = await Tools.bundledSkillsDir({ skills: SKILLS, hash: SKILLS_HASH })
543
+ ```
544
+
510
545
  - Importing `@qvac/harness/plugins/image` or `@qvac/harness/plugins/music` no
511
546
  longer needs their peers; constructing `Image` or `Music` without them throws
512
547
  the error naming the plugin and the missing packages. A sidecar host passing no
@@ -681,10 +716,13 @@ breaking change is listed under Changed and Removed.
681
716
  const [best] = await harness.detectLanguage({ text })
682
717
  ```
683
718
 
684
- - `bare-worker` is pinned to 4.5.0 and `bare-module` is a dependency at
685
- `~7.1.0`, so a host's install resolves a `bare-module` that runs on Bare
686
- 1.34: `bare-worker` 4.5.3 asks for `bare-module` 7.4, and npm gives it 7.5,
687
- which needs Bare 1.35. (#630)
719
+ - `bare-worker` is a dependency at `^4.5.3` and `bare-module` is not one, so a
720
+ host shares its own `bare-worker` copy. The exact 4.5.0 pin kept a second copy
721
+ under `@qvac/harness` in any host on a newer one, and that copy, built against
722
+ `bare-module` 7.1, could not start the python worker under the host.s
723
+ `bare-thread` 1.4 (`MODULE_NOT_FOUND` for `bare-worker/lib/worker-thread.js`).
724
+ `bare-worker` 4.5.3 runs on `bare-module` 7.5, so the python plugin needs Bare
725
+ 1.35. (#852)
688
726
  - The `sandbox-vm` plugin (`VmShell`, `./plugins/sandbox-vm`) is back, with
689
727
  `barevisor` an optional peer instead of a dependency every host installed.
690
728
  (#626)
@@ -1222,6 +1260,21 @@ breaking change is listed under Changed and Removed.
1222
1260
 
1223
1261
  ### Fixed
1224
1262
 
1263
+ - Two walkie-talkie machines in one process no longer miss each other. Started
1264
+ together they dialed each other at once, each could keep a different one of
1265
+ the two connections, and `teammate()` then never resolved: the agent-team
1266
+ example and its test hung. `walkie.announced()` resolves once a machine can
1267
+ be found, and the example starts its second machine after it.
1268
+ - A steer sent while a run writes its answer no longer continues that run. It
1269
+ is left untaken, so the host runs it on its own: a second chat message used
1270
+ to be answered inside the first message's reply, and got none of its own.
1271
+ ([QVAC-28184](https://app.asana.com/1/45238840754660/project/1216236248324478/task/1220368764270002))
1272
+ - `generate_music` progress stops at 99% until the track is saved. The VAE
1273
+ stage reported 100% while the WAV was still being attached, so a slow or
1274
+ failed save left a full bar over a chat with no audio. ([QVAC-28182](https://app.asana.com/1/45238840754660/project/1213510748674624/task/1220363856167110), #843)
1275
+ - Generated capability streams expose their `destroyed` state, and upload
1276
+ streams their `drain` listeners, so a host can respect upload backpressure
1277
+ without casts or a downstream patch. (#842)
1225
1278
  - Text that spells a chat-template token no longer becomes one. A tool result,
1226
1279
  file, page, user turn or tool description holding `<|im_start|>`,
1227
1280
  `<tool_response>`, `<think>` and the like reaches the model with a word joiner
@@ -1251,8 +1304,8 @@ breaking change is listed under Changed and Removed.
1251
1304
  `http_request`. (#818)
1252
1305
  - The package loads on Bare 1.33.4, the runtime of `react-native-bare-kit`
1253
1306
  0.16.0: `engines.bare` is `>=1.33.4`, so a mobile host no longer patches it.
1254
- Python still needs Bare 1.34.0, and importing `@qvac/harness/plugins/python`
1255
- on an older Bare throws `@qvac/harness/plugins/python needs Bare 1.34.0 or
1307
+ Python still needs Bare 1.35.0, and importing `@qvac/harness/plugins/python`
1308
+ on an older Bare throws `@qvac/harness/plugins/python needs Bare 1.35.0 or
1256
1309
  later` instead of a stowed harness failing to open with `ADDON_NOT_FOUND` for
1257
1310
  `bare-channel`. A plugin names its own floor with
1258
1311
  `PluginRegistry.requireBare(plugin, floor)`. (#806)
@@ -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, ShowImageFn, ToolDefinition, ToolExecuteContext } from './lib/contract/index.ts';
6
+ import type { AccessPolicy, AgentConfig, ApproveFn, AskUserFn, AttachFn, CompletionEvent, FetchAttachmentFn, MediaRoundIo, MediaRoundPort, MediaRoundRequest, MediaRoundResult, 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';
@@ -166,6 +166,7 @@ export interface CompletionContext {
166
166
  input?: AsyncIterable<RunInput>;
167
167
  roundCut?: (cut: (note: string) => void) => void;
168
168
  modelRound?: ModelRoundPort;
169
+ mediaRound?: MediaRoundPort;
169
170
  hopLog?: (hop: RunHop) => RunHopLog;
170
171
  }
171
172
  export interface RunHop {
@@ -308,6 +309,7 @@ export declare class Harness extends ReadyResource {
308
309
  private _invoke;
309
310
  completion(context: CompletionContext | ResumeCompletionContext): AsyncGenerator<CompletionEvent>;
310
311
  serveModelRound(request: ModelRoundRequest, io: ModelRoundIo): Promise<ModelRoundResult>;
312
+ serveMediaRound(request: MediaRoundRequest, io: MediaRoundIo): Promise<MediaRoundResult>;
311
313
  private _servedRoundFailed;
312
314
  private _completion;
313
315
  private _runCompletion;
package/dist-lib/index.js CHANGED
@@ -78,6 +78,7 @@ 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
80
  const OCR_PLUGIN_MISSING = 'ocr needs the ocr plugin';
81
+ const MEDIA_ROUND_SERVICES = { image: 'image-rounds', music: 'music-rounds' };
81
82
  const UNLOAD_FAILED = 'Runtime unload failed; close the harness before loading models again';
82
83
  const HOST_SHELL = { name: 'host' };
83
84
  function execOptions(exec) {
@@ -326,6 +327,7 @@ export class Harness extends ReadyResource {
326
327
  track: (load, sdk) => this._loads.track(load, sdk),
327
328
  makeRoom: (signal, busy, srcs) => this._residency.makeRoomForPlugin(signal, busy, srcs),
328
329
  hold: this._hold,
330
+ isCached: (model, addon) => this._isModelCached(catalogModelName(model, addon), addon),
329
331
  get requests() {
330
332
  return residency().requests;
331
333
  },
@@ -891,6 +893,34 @@ export class Harness extends ReadyResource {
891
893
  this._residency.clearFaults(modelId);
892
894
  return served;
893
895
  }
896
+ async serveMediaRound(request, io) {
897
+ if (!this.opened)
898
+ await this.ready();
899
+ this._lifecycle.assertNotClosing();
900
+ if (this.suspended || this._lifecycle.draining) {
901
+ throw new HarnessError('HARNESS_SUSPENDED');
902
+ }
903
+ const releasePlugins = await this._plugins.hold();
904
+ try {
905
+ const server = this._plugins.ctx[MEDIA_ROUND_SERVICES[request.kind]];
906
+ if (!server) {
907
+ throw new HarnessError('MEDIA_MODEL_MISSING', [
908
+ request.kind,
909
+ request.modelChoice ?? 'default'
910
+ ]);
911
+ }
912
+ const leave = this._lifecycle.enterWork();
913
+ try {
914
+ return await server.serve(request, io);
915
+ }
916
+ finally {
917
+ leave();
918
+ }
919
+ }
920
+ finally {
921
+ releasePlugins();
922
+ }
923
+ }
894
924
  async _servedRoundFailed(err, model, key) {
895
925
  const aborted = err instanceof AbortedError || this.suspended || this._lifecycle.draining;
896
926
  if (aborted || !isSdkModelWedgedError(err)) {
@@ -1,7 +1,7 @@
1
1
  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
- import type { ToolCallDisplay } from '../../contract/index.ts';
4
+ import type { MediaRoundPort, ToolCallDisplay } from '../../contract/index.ts';
5
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';
@@ -14,6 +14,7 @@ export interface CompletionArgs {
14
14
  modelId: string;
15
15
  acquireRound?: (signal?: BareAbortSignal) => Promise<RoundModelLease>;
16
16
  modelRound?: ModelRoundPort;
17
+ mediaRound?: MediaRoundPort;
17
18
  model?: string;
18
19
  agent?: AgentConfig;
19
20
  ctxSize?: number;
@@ -74,4 +75,4 @@ export declare function createRunBudget(startedAt: number, ms?: number): RunBudg
74
75
  export type ToolContextFactory = (turnImages?: {
75
76
  path: string;
76
77
  }[], ctxSize?: number, signal?: BareAbortSignal) => ToolExecuteContext;
77
- export declare function runToolContext(args: Pick<CompletionArgs, 'agent' | 'attach' | 'fetchAttachment' | 'progress' | 'askUser' | 'signal' | 'fsRoots' | 'fsWriteRoots' | 'session' | 'cacheKey'>, runBudget: RunBudget): ToolContextFactory;
78
+ export declare function runToolContext(args: Pick<CompletionArgs, 'agent' | 'attach' | 'fetchAttachment' | 'progress' | 'askUser' | 'mediaRound' | 'signal' | 'fsRoots' | 'fsWriteRoots' | 'session' | 'cacheKey'>, runBudget: RunBudget): ToolContextFactory;
@@ -29,7 +29,7 @@ export function createRunBudget(startedAt, ms) {
29
29
  return { deadlineMs: startedAt + totalMs, totalMs, outputBytesUsed: 0 };
30
30
  }
31
31
  export function runToolContext(args, runBudget) {
32
- const { agent, attach, fetchAttachment, progress, askUser, signal } = args;
32
+ const { agent, attach, fetchAttachment, progress, askUser, mediaRound, signal } = args;
33
33
  const image = imageSettingsFrom(agent);
34
34
  const session = args.session ?? sessionOf(args.cacheKey);
35
35
  return (turnImages = [], ctxSize, invocationSignal) => {
@@ -62,6 +62,9 @@ export function runToolContext(args, runBudget) {
62
62
  if (askUser) {
63
63
  context.askUser = askUser;
64
64
  }
65
+ if (mediaRound) {
66
+ context.mediaRound = mediaRound;
67
+ }
65
68
  return context;
66
69
  };
67
70
  }
@@ -9,6 +9,7 @@ import type { KnowledgeArtifact, KnowledgeHit, KnowledgeQuery, KnowledgeRemoved,
9
9
  import type { ModelRoundIo, ModelRoundRequest, ModelRoundResult } from './capabilities/completion-engine/index.ts';
10
10
  import { type EmbedDevice } from './models/embed-config.ts';
11
11
  import type { DeleteModelSummary } from './models/model-delete.ts';
12
+ import type { MediaRoundIo, MediaRoundRequest, MediaRoundResult } from './contract/index.ts';
12
13
  import type { CopyBaseResult, DeleteOverlayResult, ManagedSkill, SkillFileContent } from './tools/skills/overlay-crud.ts';
13
14
  import type { SkillSettingEntry } from './tools/skills/skill-settings.ts';
14
15
  export declare const HARNESS_DIED = "HARNESS_DIED";
@@ -35,6 +36,7 @@ export declare class RemoteHarness extends EventEmitter implements HarnessContra
35
36
  completion(context: HostContext<CompletionContext | import('./contract-types.ts').ResumeCompletionContext>): AsyncIterable<HarnessEvent>;
36
37
  private _hop;
37
38
  serveModelRound(request: ModelRoundRequest, io: HostContext<ModelRoundIo>): Promise<ModelRoundResult>;
39
+ serveMediaRound(request: MediaRoundRequest, io: HostContext<MediaRoundIo>): Promise<MediaRoundResult>;
38
40
  invoke(context: HostContext<InvokeContext>): AsyncIterable<HarnessEvent>;
39
41
  private _run;
40
42
  download(context: HostContext<DownloadContext>): AsyncIterable<HarnessEvent>;
@@ -14,6 +14,8 @@ import { Agent } from './agent/index.js';
14
14
  import { readModelSourcePreview } from './capabilities/preview-model-source.js';
15
15
  import { RunLog } from './run-log/index.js';
16
16
  import { AbortedError } from './helpers/engine-error.js';
17
+ import { MediaHost } from './media-host.js';
18
+ import { discardRequestWire, mediaRequestWire, mediaResultFrom, mediaTickFrom } from './media-wire.js';
17
19
  import { RoundHost } from './round-host.js';
18
20
  import { HarnessLog } from './log.js';
19
21
  import { assertEmbedDevice } from './models/embed-config.js';
@@ -157,6 +159,9 @@ export class RemoteHarness extends EventEmitter {
157
159
  if (context.modelRound) {
158
160
  payload.modelRound = true;
159
161
  }
162
+ if (context.mediaRound) {
163
+ payload.mediaRound = true;
164
+ }
160
165
  if (context.roundCut) {
161
166
  payload.roundCut = true;
162
167
  }
@@ -214,6 +219,30 @@ export class RemoteHarness extends EventEmitter {
214
219
  duplex.destroy();
215
220
  }
216
221
  }
222
+ async serveMediaRound(request, io) {
223
+ const aborted = abortedRound(io.signal);
224
+ const { client } = await Promise.race([this._ensure(), aborted]);
225
+ const payload = await mediaRequestWire(request);
226
+ const duplex = client.completion();
227
+ const stop = () => duplex.destroy();
228
+ io.signal?.addEventListener?.('abort', stop, { once: true });
229
+ try {
230
+ const frame = { type: 'media-round-ask', payload };
231
+ encode('@harness/completion-frame', frame);
232
+ duplex.write(frame);
233
+ const served = servedMedia(frames(duplex), io);
234
+ served.catch(noop);
235
+ return await Promise.race([served, aborted]);
236
+ }
237
+ catch (err) {
238
+ await discardRequestWire(payload);
239
+ throw err;
240
+ }
241
+ finally {
242
+ io.signal?.removeEventListener?.('abort', stop);
243
+ duplex.destroy();
244
+ }
245
+ }
217
246
  async *invoke(context) {
218
247
  const agent = context.agent ?? {};
219
248
  yield* this._run({
@@ -306,6 +335,12 @@ export class RemoteHarness extends EventEmitter {
306
335
  send({ ...frame });
307
336
  }
308
337
  });
338
+ const media = context.mediaRound &&
339
+ new MediaHost(context.mediaRound, (frame) => {
340
+ if (!closed) {
341
+ send({ ...frame });
342
+ }
343
+ });
309
344
  let failure = null;
310
345
  const send = (frame) => {
311
346
  if (!duplex)
@@ -517,6 +552,14 @@ export class RemoteHarness extends EventEmitter {
517
552
  rounds?.cancel(event.callId ?? '');
518
553
  continue;
519
554
  }
555
+ if (event.type === 'media-round-ask') {
556
+ media?.ask(event.callId ?? '', event.payload);
557
+ continue;
558
+ }
559
+ if (event.type === 'media-round-cancel') {
560
+ media?.cancel(event.callId ?? '');
561
+ continue;
562
+ }
520
563
  const wire = fromWire(event);
521
564
  if (wire.type === 'aborted' || wire.type === 'paused') {
522
565
  emittedAborted = true;
@@ -547,6 +590,7 @@ export class RemoteHarness extends EventEmitter {
547
590
  duplex?.destroy();
548
591
  closed = true;
549
592
  rounds?.close();
593
+ media?.close();
550
594
  reclaim();
551
595
  if (hostLease && leasedRunId && context.runLog) {
552
596
  let timer;
@@ -1060,6 +1104,19 @@ async function servedRound(events, io) {
1060
1104
  }
1061
1105
  throw died('the harness ended a served round without its result');
1062
1106
  }
1107
+ async function servedMedia(events, io) {
1108
+ for await (const event of events) {
1109
+ if (io.signal?.aborted)
1110
+ break;
1111
+ if (event.type === 'media-round-tick') {
1112
+ io.tick(mediaTickFrom(event.payload));
1113
+ }
1114
+ else if (event.type === 'media-round-result') {
1115
+ return await mediaResultFrom(event);
1116
+ }
1117
+ }
1118
+ throw died('the harness ended a served media round without its result');
1119
+ }
1063
1120
  function abortable(promise, signal) {
1064
1121
  if (!signal)
1065
1122
  return promise;
@@ -7,6 +7,7 @@ import type { DriveRoot } from '../tools/fs/scope.ts';
7
7
  import type { CliValidator } from '../tools/skills/cli-schema-types.ts';
8
8
  import type { UsageBreakdown } from '../capabilities/usage-breakdown.ts';
9
9
  import type { KnowledgeGrant, KnowledgeSource } from './knowledge.ts';
10
+ import type { MediaRoundPort } from './media.ts';
10
11
  import type { OcrService } from './ocr.ts';
11
12
  import type { AccessPolicy, CompiledPolicy } from './policy.ts';
12
13
  import type { GoalStatus, HistoryToolCall, HookRejection, Message, ResourceDescriptor, RoundSpeed, RunBackendUse, RunBudget, RunLifecycleEvent, RunOutcome, ToolActivityEvent, ToolCallDisplay, ToolDecision, ToolEffect, ToolSpeed, TrustedSource, TrustedSourceFacts, TurnContext } from './run.ts';
@@ -165,6 +166,7 @@ export interface ToolExecuteContext {
165
166
  fetchAttachment?: FetchAttachmentFn | undefined;
166
167
  progress?: ProgressFn | undefined;
167
168
  askUser?: AskUserFn | undefined;
169
+ mediaRound?: MediaRoundPort | undefined;
168
170
  signal?: BareAbortSignal | undefined;
169
171
  fsRoots?: readonly DriveRoot[] | undefined;
170
172
  fsWriteRoots?: readonly DriveRoot[] | undefined;
@@ -3,6 +3,7 @@ export type * from './completion.ts';
3
3
  export type * from './drive.ts';
4
4
  export type * from './hooks.ts';
5
5
  export type * from './managed-skills.ts';
6
+ export type * from './media.ts';
6
7
  export type * from './policy.ts';
7
8
  export type * from './run.ts';
8
9
  export type * from './skill-readiness.ts';
@@ -0,0 +1,51 @@
1
+ import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
2
+ export type MediaKind = 'image' | 'music';
3
+ export interface MediaRoundRequest {
4
+ kind: MediaKind;
5
+ runId: string;
6
+ modelChoice?: string | undefined;
7
+ params: Record<string, unknown>;
8
+ images?: Uint8Array[] | undefined;
9
+ }
10
+ export interface MediaTick {
11
+ step: number;
12
+ total: number;
13
+ stage?: string | undefined;
14
+ }
15
+ export interface MediaRoundIo {
16
+ signal: BareAbortSignal;
17
+ tick(tick: MediaTick): void;
18
+ }
19
+ export interface ImageRoundOutput {
20
+ kind: 'image';
21
+ bytes: Uint8Array;
22
+ }
23
+ export interface MediaAudioFormat {
24
+ sampleRate: number;
25
+ channels: number;
26
+ bitsPerSample: number;
27
+ }
28
+ export interface MediaMusicStats {
29
+ audioDurationMs?: number | undefined;
30
+ totalTimeMs?: number | undefined;
31
+ realTimeFactor?: number | undefined;
32
+ backendDevice?: number | undefined;
33
+ backendId?: number | undefined;
34
+ }
35
+ export interface MusicRoundOutput {
36
+ kind: 'music';
37
+ bytes: Uint8Array;
38
+ format: MediaAudioFormat;
39
+ gpuRequested: boolean;
40
+ stats?: MediaMusicStats | undefined;
41
+ }
42
+ export type MediaRoundOutput = ImageRoundOutput | MusicRoundOutput;
43
+ export interface MediaRoundRefusal {
44
+ error: string;
45
+ code?: string | undefined;
46
+ }
47
+ export type MediaRoundResult = MediaRoundOutput | MediaRoundRefusal;
48
+ export type MediaRoundPort = (request: MediaRoundRequest, io: MediaRoundIo) => Promise<MediaRoundResult>;
49
+ export interface MediaRoundServer {
50
+ serve: MediaRoundPort;
51
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -2,6 +2,7 @@ import type { createVectorIndex, loadVectorIndex } from '@qvac/inference';
2
2
  import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
3
3
  import type { ModelSrc } from '../models/context.ts';
4
4
  import type { HoldFn } from '../models/download-gate.ts';
5
+ import type { ModelAddon } from '../models/model-source.ts';
5
6
  import type { LoadRequests } from '../models/load-requests.ts';
6
7
  import type { CancelSdk, ModelState, PendingLoad, TrackedLoad } from '../models/model-pool.ts';
7
8
  export type { CancelSdk, HoldFn, LoadRequests, ModelState, TrackedLoad };
@@ -10,6 +11,7 @@ export interface ModelHost {
10
11
  track(load: TrackedLoad, sdk?: Partial<CancelSdk>): TrackedLoad;
11
12
  makeRoom(signal: BareAbortSignal | undefined, busy: string | Error, srcs?: ReadonlyArray<string>): Promise<void>;
12
13
  hold: HoldFn;
14
+ isCached(model: string, addon: ModelAddon): Promise<boolean>;
13
15
  readonly requests: LoadRequests;
14
16
  completionModel(model: string, signal?: BareAbortSignal): Promise<BorrowedModel>;
15
17
  emit(state: ModelState): void;
@@ -1,6 +1,6 @@
1
1
  import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
2
2
  import type { HarnessCapabilityProfile } from '../spec/hyperschema/types.d.ts';
3
- import type { AccessPolicy, AgentHandoff, ApproveFn, AskUserFn, AttachFn, FetchAttachmentFn, HistoryToolCall, ProgressFn, ResourceDescriptor, ResponseFormat, ShowImageFn } from './contract/index.ts';
3
+ import type { AccessPolicy, AgentHandoff, ApproveFn, AskUserFn, AttachFn, FetchAttachmentFn, HistoryToolCall, ProgressFn, ResourceDescriptor, ResponseFormat, MediaRoundIo, MediaRoundPort, MediaRoundRequest, MediaRoundResult, ShowImageFn } from './contract/index.ts';
4
4
  import type { KvCacheDeletionResult } from './capabilities/kv-cache.ts';
5
5
  import type { ModelRoundIo, ModelRoundPort, ModelRoundRequest, ModelRoundResult } from './capabilities/completion-engine/index.ts';
6
6
  import type { ModelSourcePreview, PreviewModelSourceContext } from './capabilities/preview-model-source.ts';
@@ -102,6 +102,7 @@ export interface CompletionContext {
102
102
  input?: AsyncIterable<RunInput>;
103
103
  roundCut?: (cut: (note: string) => void) => void;
104
104
  modelRound?: ModelRoundPort;
105
+ mediaRound?: MediaRoundPort;
105
106
  }
106
107
  export interface HostSignal {
107
108
  aborted?: boolean;
@@ -261,6 +262,7 @@ export interface InfraModel {
261
262
  export interface HarnessContract {
262
263
  completion(context: CompletionContext | ResumeCompletionContext): AsyncIterable<HarnessEvent>;
263
264
  serveModelRound?(request: ModelRoundRequest, io: ModelRoundIo): Promise<ModelRoundResult>;
265
+ serveMediaRound?(request: MediaRoundRequest, io: MediaRoundIo): Promise<MediaRoundResult>;
264
266
  invoke?(context: InvokeContext): AsyncIterable<HarnessEvent>;
265
267
  download?(context: DownloadContext): AsyncIterable<HarnessEvent>;
266
268
  describe?(): Promise<HarnessInfo | null> | HarnessInfo;
@@ -68,6 +68,10 @@ declare const HARNESS_ERRORS: {
68
68
  readonly code: 102107;
69
69
  readonly message: () => string;
70
70
  };
71
+ readonly MEDIA_MODEL_MISSING: {
72
+ readonly code: 102108;
73
+ readonly message: (kind: string, model: string) => string;
74
+ };
71
75
  readonly CONTEXT_WINDOW_EXCEEDED: {
72
76
  readonly code: 102201;
73
77
  readonly message: () => string;
@@ -248,6 +252,10 @@ declare const HARNESS_ERRORS: {
248
252
  readonly code: 102711;
249
253
  readonly message: () => string;
250
254
  };
255
+ readonly BUNDLED_SKILLS_HASH_INVALID: {
256
+ readonly code: 102712;
257
+ readonly message: (hash: string) => string;
258
+ };
251
259
  };
252
260
  type Errors = typeof HARNESS_ERRORS;
253
261
  export type HarnessErrorName = keyof Errors;
@@ -45,6 +45,10 @@ const HARNESS_ERRORS = {
45
45
  code: 102107,
46
46
  message: () => 'translation model download stalled'
47
47
  },
48
+ MEDIA_MODEL_MISSING: {
49
+ code: 102108,
50
+ message: (kind, model) => `this device does not hold the ${kind} model ${model}`
51
+ },
48
52
  CONTEXT_WINDOW_EXCEEDED: {
49
53
  code: 102201,
50
54
  message: () => 'This message is too large for the model context window.'
@@ -180,7 +184,11 @@ const HARNESS_ERRORS = {
180
184
  message: () => 'cannot fence the app storage root: the SDK home is unknown'
181
185
  },
182
186
  SLM_TRANSLATION_UNAVAILABLE: { code: 102710, message: () => 'slm translation is unavailable' },
183
- PDF_TEXT_UNAVAILABLE: { code: 102711, message: () => 'PDF text is not available on this device' }
187
+ PDF_TEXT_UNAVAILABLE: { code: 102711, message: () => 'PDF text is not available on this device' },
188
+ BUNDLED_SKILLS_HASH_INVALID: {
189
+ code: 102712,
190
+ message: (hash) => `bundled skills hash ${hash} is not 16 hex characters`
191
+ }
184
192
  };
185
193
  addCodes(Object.fromEntries(Object.entries(HARNESS_ERRORS).map(([name, { code, message }]) => [code, { name, message }])), { name: '@qvac/harness', version: `${Object.keys(HARNESS_ERRORS).length}.0.0` });
186
194
  export class HarnessError extends QvacErrorBase {
@@ -9,7 +9,7 @@ export declare function retryMalformedRound({ context, params }: CompletionActio
9
9
  export declare function retryCappedSearch({ context }: CompletionActionArgs): Partial<CompletionContext>;
10
10
  export declare function retryCutRound({ context }: CompletionActionArgs): Partial<CompletionContext>;
11
11
  export declare function wrapCutCompletion({ context }: CompletionActionArgs): Partial<CompletionContext>;
12
- export declare function continueWithInput({ context }: CompletionActionArgs): Partial<CompletionContext>;
12
+ export declare function continueWithFollowUps({ context }: CompletionActionArgs): Partial<CompletionContext>;
13
13
  export declare function addKnowledge({ context, params }: CompletionActionArgs<RetrievingOutput>): Partial<CompletionContext>;
14
14
  export declare function goalTurn(context: Readonly<CompletionContext>, stall?: string): string;
15
15
  export declare function continueStalledGoal({ context }: CompletionActionArgs): Partial<CompletionContext>;
@@ -157,15 +157,11 @@ function continueAfterAnswer(context, turns) {
157
157
  cappedRounds: 0
158
158
  };
159
159
  }
160
- export function continueWithInput({ context }) {
160
+ export function continueWithFollowUps({ context }) {
161
161
  return {
162
- ...continueAfterAnswer(context, [
163
- ...userTurns(context.steering),
164
- ...userTurns(context.followUps)
165
- ]),
166
- steering: [],
162
+ ...continueAfterAnswer(context, userTurns(context.followUps)),
167
163
  followUps: [],
168
- edgeInputs: [...context.steering, ...context.followUps]
164
+ edgeInputs: context.followUps
169
165
  };
170
166
  }
171
167
  export function addKnowledge({ context, params }) {
@@ -39,7 +39,7 @@ export declare const completionGuards: {
39
39
  toolEndedRun: ({ event }: Args) => boolean;
40
40
  timeUp: ({ context }: Args) => boolean;
41
41
  failedOutcome: ({ context }: Args) => boolean;
42
- hasInput: ({ context }: Args) => boolean;
42
+ hasFollowUp: ({ context }: Args) => boolean;
43
43
  stopContinues: ({ event }: Args) => boolean;
44
44
  goalUnmet: ({ context }: Args) => boolean;
45
45
  goalTokensLeft: ({ context }: Args) => boolean;
@@ -61,7 +61,7 @@ export declare const completionActions: {
61
61
  wrapCompletion: import("xstate").ActionFunction<CompletionContext, CompletionMachineEvent, CompletionMachineEvent, import("../../contract/run.ts").RunOutcome, never, never, never, never, never>;
62
62
  resolveTools: import("xstate").ActionFunction<CompletionContext, CompletionMachineEvent, CompletionMachineEvent, import("./types.ts").ToolsResolvedPayload, never, never, never, never, never>;
63
63
  answerCompletion: import("xstate").ActionFunction<CompletionContext, CompletionMachineEvent, CompletionMachineEvent, import("./types.ts").AnsweredPayload, never, never, never, never, never>;
64
- continueWithInput: import("xstate").ActionFunction<CompletionContext, CompletionMachineEvent, CompletionMachineEvent, undefined, never, never, never, never, never>;
64
+ continueWithFollowUps: import("xstate").ActionFunction<CompletionContext, CompletionMachineEvent, CompletionMachineEvent, undefined, never, never, never, never, never>;
65
65
  addKnowledge: import("xstate").ActionFunction<CompletionContext, CompletionMachineEvent, CompletionMachineEvent, import("./types.ts").RetrievingOutput, never, never, never, never, never>;
66
66
  continueStop: import("xstate").ActionFunction<CompletionContext, CompletionMachineEvent, CompletionMachineEvent, import("./types.ts").AnsweredPayload, never, never, never, never, never>;
67
67
  continueGoal: import("xstate").ActionFunction<CompletionContext, CompletionMachineEvent, CompletionMachineEvent, undefined, never, never, never, never, EngineEvent>;
@@ -106,7 +106,7 @@ export declare const completionActions: {
106
106
  resumeRun: import("xstate").ActionFunction<CompletionContext, CompletionMachineEvent, CompletionMachineEvent, undefined, never, never, never, never, never>;
107
107
  ackSteering: import("xstate").ActionFunction<CompletionContext, CompletionMachineEvent, CompletionMachineEvent, RoundParams, never, never, never, never, EngineEvent>;
108
108
  resetCutRound: import("xstate").ActionFunction<CompletionContext, CompletionMachineEvent, CompletionMachineEvent, ResolvingOutput, never, never, never, never, EngineEvent>;
109
- ackInput: import("xstate").ActionFunction<CompletionContext, CompletionMachineEvent, CompletionMachineEvent, undefined, never, never, never, never, EngineEvent>;
109
+ ackFollowUps: import("xstate").ActionFunction<CompletionContext, CompletionMachineEvent, CompletionMachineEvent, undefined, never, never, never, never, EngineEvent>;
110
110
  queueInput: import("xstate").ActionFunction<CompletionContext, CompletionMachineEvent, CompletionMachineEvent, undefined, never, never, never, never, never>;
111
111
  recordFacts: import("xstate").ActionFunction<CompletionContext, CompletionMachineEvent, CompletionMachineEvent, undefined, never, never, never, never, never>;
112
112
  };
@@ -1,7 +1,7 @@
1
1
  import { assign, enqueueActions } from 'xstate';
2
2
  import { isFailureResultReference } from '../../helpers/failure-result.js';
3
3
  import { approveCompletion, requestApproval } from './actions/approval.js';
4
- import { addKnowledge, answerCompletion, continueGoal, continueStalledGoal, continueStop, continueWithInput, failCompletion, finishWrapRound, finishRound, markGoalStalled, retryCappedSearch, retryCutRound, retryMalformedRound, retryMuteRound, retryNarratedRound, settleGoal, startInitialRound, startNextRound, wrapCompletion, wrapCutCompletion, wrapDeliveredCompletion, wrapExhaustedCompletion, wrapMuteCompletion, wrapSearchCappedCompletion } from './actions/completion.js';
4
+ import { addKnowledge, answerCompletion, continueGoal, continueStalledGoal, continueStop, continueWithFollowUps, failCompletion, finishWrapRound, finishRound, markGoalStalled, retryCappedSearch, retryCutRound, retryMalformedRound, retryMuteRound, retryNarratedRound, settleGoal, startInitialRound, startNextRound, wrapCompletion, wrapCutCompletion, wrapDeliveredCompletion, wrapExhaustedCompletion, wrapMuteCompletion, wrapSearchCappedCompletion } from './actions/completion.js';
5
5
  import { authorizePrepare, requestPrepare, settlePrepare, settlePrepareFailure } from './actions/prepare.js';
6
6
  import { finishBatch, finishDirectTool, finishTool, endRunOnTool, queueDirectSearch, rejectCutOffTool, rejectDeniedApproval, rejectPlanModeWrite, rejectRepeatedTool, rejectTool, resolveTools, selectNextTool, startDirectTool, startTool } from './actions/tools.js';
7
7
  import { allResolvedToolsCapped, canMuteRetry, canRetryCut, canRetryMalformed, canRetryNarrated, canRetrySearchCap, hasQueuedTool, hasRoundsLeft, repeatsBlocked, searchPending } from './guards/retry.js';
@@ -79,7 +79,7 @@ export const completionGuards = {
79
79
  toolEndedRun: ({ event }) => output(event).endedRun === true,
80
80
  timeUp: ({ context }) => context.timeUp,
81
81
  failedOutcome: ({ context }) => context.outcome === 'failed',
82
- hasInput: ({ context }) => context.steering.length + context.followUps.length > 0,
82
+ hasFollowUp: ({ context }) => context.followUps.length > 0,
83
83
  stopContinues: ({ event }) => Boolean(output(event).continue),
84
84
  goalUnmet: ({ context }) => context.goal !== null && !goalMet(context),
85
85
  goalTokensLeft: ({ context }) => goalTokensLeft(context),
@@ -101,7 +101,7 @@ export const completionActions = {
101
101
  wrapCompletion: assignAction(wrapCompletion),
102
102
  resolveTools: assignAction(resolveTools),
103
103
  answerCompletion: assignAction(answerCompletion),
104
- continueWithInput: assignAction(continueWithInput),
104
+ continueWithFollowUps: assignAction(continueWithFollowUps),
105
105
  addKnowledge: assignAction(addKnowledge),
106
106
  continueStop: assignAction(continueStop),
107
107
  continueGoal: goalAction(continueGoal),
@@ -180,7 +180,7 @@ export const completionActions = {
180
180
  }
181
181
  ]
182
182
  : []),
183
- ackInput: ackAction(({ context }) => [...context.steering, ...context.followUps].map((queued) => inputEvent(context.runId, queued, context.round + 1))),
183
+ ackFollowUps: ackAction(({ context }) => context.followUps.map((queued) => inputEvent(context.runId, queued, context.round + 1))),
184
184
  queueInput: assign(({ context, event }) => {
185
185
  if (event.type !== 'INPUT')
186
186
  return {};
@@ -115,7 +115,7 @@ declare const createCompletionMachineImplementation: (context?: CompletionContex
115
115
  }, InvocationInput>;
116
116
  id: string | undefined;
117
117
  }, {
118
- type: "ackInput";
118
+ type: "ackFollowUps";
119
119
  params: undefined;
120
120
  } | {
121
121
  type: "ackSteering";
@@ -142,7 +142,7 @@ declare const createCompletionMachineImplementation: (context?: CompletionContex
142
142
  type: "continueStop";
143
143
  params: import("./types.ts").AnsweredPayload;
144
144
  } | {
145
- type: "continueWithInput";
145
+ type: "continueWithFollowUps";
146
146
  params: undefined;
147
147
  } | {
148
148
  type: "endRunOnTool";
@@ -355,7 +355,7 @@ declare const createCompletionMachineImplementation: (context?: CompletionContex
355
355
  type: "hasAnswer";
356
356
  params: unknown;
357
357
  } | {
358
- type: "hasInput";
358
+ type: "hasFollowUp";
359
359
  params: unknown;
360
360
  } | {
361
361
  type: "hasQueuedTool";