@qvac/harness 1.0.0-rc.18 → 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 (53) hide show
  1. package/CHANGELOG.md +37 -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 +4 -0
  15. package/dist-lib/lib/errors.js +4 -0
  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/plugins/registry.d.ts +3 -0
  30. package/dist-lib/lib/serve.js +37 -1
  31. package/dist-lib/lib/tools/pdf/pages.js +6 -3
  32. package/dist-lib/lib/tools/pdf/recognize.js +2 -1
  33. package/dist-lib/plugins/image/edit-image.js +3 -9
  34. package/dist-lib/plugins/image/generate-image.d.ts +14 -2
  35. package/dist-lib/plugins/image/generate-image.js +94 -8
  36. package/dist-lib/plugins/image/index.d.ts +2 -1
  37. package/dist-lib/plugins/image/index.js +8 -3
  38. package/dist-lib/plugins/music/generate-music.d.ts +18 -2
  39. package/dist-lib/plugins/music/generate-music.js +98 -16
  40. package/dist-lib/plugins/music/index.d.ts +2 -1
  41. package/dist-lib/plugins/music/index.js +6 -2
  42. package/dist-lib/plugins/python/bare-floor.js +1 -1
  43. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  44. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  45. package/dist-lib/plugins/walkie-talkie/index.d.ts +2 -0
  46. package/dist-lib/plugins/walkie-talkie/index.js +6 -1
  47. package/dist-lib/schema/generate.js +8 -1
  48. package/dist-lib/schema/harness.js +9 -2
  49. package/dist-lib/spec/hrpc/messages.js +46 -4
  50. package/dist-lib/spec/hyperschema/index.js +46 -4
  51. package/dist-lib/spec/hyperschema/schema.json +28 -0
  52. package/dist-lib/spec/hyperschema/types.d.ts +2 -2
  53. package/package.json +7 -8
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
@@ -703,10 +716,13 @@ breaking change is listed under Changed and Removed.
703
716
  const [best] = await harness.detectLanguage({ text })
704
717
  ```
705
718
 
706
- - `bare-worker` is pinned to 4.5.0 and `bare-module` is a dependency at
707
- `~7.1.0`, so a host's install resolves a `bare-module` that runs on Bare
708
- 1.34: `bare-worker` 4.5.3 asks for `bare-module` 7.4, and npm gives it 7.5,
709
- 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)
710
726
  - The `sandbox-vm` plugin (`VmShell`, `./plugins/sandbox-vm`) is back, with
711
727
  `barevisor` an optional peer instead of a dependency every host installed.
712
728
  (#626)
@@ -1244,6 +1260,21 @@ breaking change is listed under Changed and Removed.
1244
1260
 
1245
1261
  ### Fixed
1246
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)
1247
1278
  - Text that spells a chat-template token no longer becomes one. A tool result,
1248
1279
  file, page, user turn or tool description holding `<|im_start|>`,
1249
1280
  `<tool_response>`, `<think>` and the like reaches the model with a word joiner
@@ -1273,8 +1304,8 @@ breaking change is listed under Changed and Removed.
1273
1304
  `http_request`. (#818)
1274
1305
  - The package loads on Bare 1.33.4, the runtime of `react-native-bare-kit`
1275
1306
  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
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
1278
1309
  later` instead of a stowed harness failing to open with `ADDON_NOT_FOUND` for
1279
1310
  `bare-channel`. A plugin names its own floor with
1280
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;
@@ -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.'
@@ -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";
@@ -353,12 +353,12 @@ const createCompletionMachineImplementation = (context, now = noClock) => setup(
353
353
  input: withParent,
354
354
  onDone: [
355
355
  {
356
- guard: and(['hasInput', 'hasRoundsLeft', not('timeUp')]),
356
+ guard: and(['hasFollowUp', 'hasRoundsLeft', not('timeUp')]),
357
357
  target: 'retrieving',
358
358
  actions: [
359
359
  { type: 'answerCompletion', params: ({ event }) => event.output },
360
- 'ackInput',
361
- 'continueWithInput'
360
+ 'ackFollowUps',
361
+ 'continueWithFollowUps'
362
362
  ]
363
363
  },
364
364
  {
@@ -120,7 +120,7 @@ export declare class CompletionMachine {
120
120
  }, import("./index.ts").InvocationInput>;
121
121
  id: string | undefined;
122
122
  }, {
123
- type: "ackInput";
123
+ type: "ackFollowUps";
124
124
  params: undefined;
125
125
  } | {
126
126
  type: "ackSteering";
@@ -147,7 +147,7 @@ export declare class CompletionMachine {
147
147
  type: "continueStop";
148
148
  params: import("./completion/types.ts").AnsweredPayload;
149
149
  } | {
150
- type: "continueWithInput";
150
+ type: "continueWithFollowUps";
151
151
  params: undefined;
152
152
  } | {
153
153
  type: "endRunOnTool";
@@ -360,7 +360,7 @@ export declare class CompletionMachine {
360
360
  type: "hasAnswer";
361
361
  params: unknown;
362
362
  } | {
363
- type: "hasInput";
363
+ type: "hasFollowUp";
364
364
  params: unknown;
365
365
  } | {
366
366
  type: "hasQueuedTool";
@@ -0,0 +1,12 @@
1
+ import type { MediaRoundPort } from './contract/index.ts';
2
+ export declare class MediaHost {
3
+ private readonly _port;
4
+ private readonly _out;
5
+ private readonly _rounds;
6
+ constructor(port: MediaRoundPort, send: (frame: object) => void);
7
+ ask(callId: string, payload: unknown): void;
8
+ cancel(callId: string): void;
9
+ close(): void;
10
+ private _settle;
11
+ private _drain;
12
+ }