@qvac/harness 1.0.0-rc.6 → 1.0.0-rc.7

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 (85) hide show
  1. package/CHANGELOG.md +157 -10
  2. package/README.md +19 -7
  3. package/dist-lib/index.d.ts +2 -2
  4. package/dist-lib/index.js +1 -1
  5. package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +2 -0
  6. package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +31 -3
  7. package/dist-lib/lib/capabilities/completion-engine/driver.js +3 -0
  8. package/dist-lib/lib/capabilities/completion-engine/index.d.ts +1 -0
  9. package/dist-lib/lib/capabilities/completion-engine/index.js +1 -0
  10. package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +1 -0
  11. package/dist-lib/lib/capabilities/completion-engine/round.js +5 -2
  12. package/dist-lib/lib/capabilities/completion-engine/tool-sets.d.ts +24 -0
  13. package/dist-lib/lib/capabilities/completion-engine/tool-sets.js +15 -0
  14. package/dist-lib/lib/capabilities/detect-language.d.ts +2 -1
  15. package/dist-lib/lib/capabilities/detect-language.js +14 -2
  16. package/dist-lib/lib/connect.d.ts +2 -0
  17. package/dist-lib/lib/connect.js +73 -7
  18. package/dist-lib/lib/contract-types.d.ts +4 -0
  19. package/dist-lib/lib/helpers/require-peers.d.ts +3 -0
  20. package/dist-lib/lib/helpers/require-peers.js +23 -0
  21. package/dist-lib/lib/models/llm-presets.d.ts +1 -0
  22. package/dist-lib/lib/models/model-catalog.js +1 -1
  23. package/dist-lib/lib/models/opencl-cache.js +2 -2
  24. package/dist-lib/lib/plugins/registry.d.ts +2 -0
  25. package/dist-lib/lib/plugins/registry.js +4 -0
  26. package/dist-lib/lib/round-host.d.ts +12 -0
  27. package/dist-lib/lib/round-host.js +57 -0
  28. package/dist-lib/lib/round-port.d.ts +24 -0
  29. package/dist-lib/lib/round-port.js +81 -0
  30. package/dist-lib/lib/sdk-loader.d.ts +1 -1
  31. package/dist-lib/lib/sdk-loader.js +30 -6
  32. package/dist-lib/lib/sdk-storage.d.ts +1 -0
  33. package/dist-lib/lib/sdk-storage.js +18 -2
  34. package/dist-lib/lib/serve.js +61 -1
  35. package/dist-lib/lib/sidecar/index.d.ts +10 -0
  36. package/dist-lib/lib/sidecar/index.js +35 -3
  37. package/dist-lib/lib/sidecar/user-plugins.d.ts +1 -0
  38. package/dist-lib/lib/sidecar/user-plugins.js +1 -1
  39. package/dist-lib/lib/tools/files/grep.js +113 -15
  40. package/dist-lib/lib/tools/fs/edit-match.js +75 -7
  41. package/dist-lib/lib/tools/fs/search.d.ts +1 -1
  42. package/dist-lib/lib/tools/fs/search.js +2 -1
  43. package/dist-lib/lib/tools/index.d.ts +2 -1
  44. package/dist-lib/lib/tools/index.js +2 -2
  45. package/dist-lib/lib/tools/skills/skill-state-constants.d.ts +1 -0
  46. package/dist-lib/lib/tools/skills/skill-state-constants.js +4 -0
  47. package/dist-lib/lib/wire.d.ts +13 -0
  48. package/dist-lib/lib/wire.js +44 -1
  49. package/dist-lib/plugins/coding/read-only.d.ts +1 -0
  50. package/dist-lib/plugins/coding/read-only.js +264 -0
  51. package/dist-lib/plugins/coding/session.d.ts +3 -1
  52. package/dist-lib/plugins/coding/session.js +19 -2
  53. package/dist-lib/plugins/egress-proxy/index.d.ts +2 -2
  54. package/dist-lib/plugins/egress-proxy/index.js +5 -3
  55. package/dist-lib/plugins/image/index.js +7 -2
  56. package/dist-lib/plugins/language-hint/index.js +4 -1
  57. package/dist-lib/plugins/music/index.js +6 -2
  58. package/dist-lib/plugins/python/index.js +1 -0
  59. package/dist-lib/plugins/python/loader.d.ts +1 -0
  60. package/dist-lib/plugins/python/loader.js +8 -0
  61. package/dist-lib/plugins/quickjs/index.js +4 -0
  62. package/dist-lib/plugins/quickjs/runtime.js +8 -3
  63. package/dist-lib/plugins/run-report/index.js +6 -2
  64. package/dist-lib/plugins/run-report/layout.js +1 -1
  65. package/dist-lib/plugins/sandbox-vm/index.js +3 -0
  66. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  67. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  68. package/dist-lib/plugins/speech/audio-resample.js +2 -1
  69. package/dist-lib/plugins/speech/index.d.ts +1 -0
  70. package/dist-lib/plugins/speech/index.js +8 -1
  71. package/dist-lib/plugins/speech/speech-runtime.js +3 -3
  72. package/dist-lib/plugins/translation/index.d.ts +1 -1
  73. package/dist-lib/plugins/translation/index.js +7 -3
  74. package/dist-lib/plugins/translation/translate.d.ts +2 -2
  75. package/dist-lib/plugins/translation/translate.js +7 -8
  76. package/dist-lib/plugins/walkie-talkie/index.d.ts +2 -2
  77. package/dist-lib/plugins/walkie-talkie/index.js +13 -5
  78. package/dist-lib/plugins/walkie-talkie/wire.d.ts +5 -0
  79. package/dist-lib/plugins/walkie-talkie/wire.js +6 -5
  80. package/dist-lib/schema/harness.js +13 -4
  81. package/dist-lib/spec/hrpc/messages.js +205 -151
  82. package/dist-lib/spec/hyperschema/index.js +205 -151
  83. package/dist-lib/spec/hyperschema/schema.json +125 -89
  84. package/dist-lib/spec/hyperschema/types.d.ts +4 -4
  85. package/package.json +149 -24
@@ -13,6 +13,8 @@ import { checkGoal, checkMaxToolRounds } from './capabilities/tool-turns.js';
13
13
  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
+ import { AbortedError } from './helpers/engine-error.js';
17
+ import { RoundHost } from './round-host.js';
16
18
  import { HarnessLog } from './log.js';
17
19
  import { assertEmbedDevice } from './models/embed-config.js';
18
20
  import { addonTaskType } from './models/model-task.js';
@@ -23,10 +25,9 @@ import { sweepSpill } from './spill.js';
23
25
  import { readInstall, readSetup } from './tools/skills/manifest-parse.js';
24
26
  import { SKILL_STATE } from './tools/skills/skill-state.js';
25
27
  import { asToolset } from './tools/toolsets.js';
26
- import { fromDownloadWire, fromKnowledgeHitWire, fromKnowledgeStatusWire, fromKnowledgeUpsertResultWire, fromWire, toKnowledgeUpsertWire, unpackVectors } from './wire.js';
28
+ import { fromDownloadWire, roundResultFrom, fromKnowledgeHitWire, fromKnowledgeStatusWire, fromKnowledgeUpsertResultWire, fromWire, toKnowledgeUpsertWire, unpackVectors } from './wire.js';
27
29
  export const HARNESS_DIED = 'HARNESS_DIED';
28
30
  const PAUSE_GRACE_MS = 10_000;
29
- const IN_PROCESS_ONLY_FIELDS = ['modelRound', 'roundCut'];
30
31
  export function connectHarness(transport, options = {}) {
31
32
  return new RemoteHarness(transport, options);
32
33
  }
@@ -117,7 +118,6 @@ export class RemoteHarness extends EventEmitter {
117
118
  : this._hop(context);
118
119
  }
119
120
  async *_hop(context) {
120
- refuseInProcessOnly(context);
121
121
  const runId = context.runId ?? b4a.toHex(randomBytes(16));
122
122
  if (context.signal?.aborted) {
123
123
  yield { type: 'aborted', runId };
@@ -153,6 +153,12 @@ export class RemoteHarness extends EventEmitter {
153
153
  if (context.replaysContext) {
154
154
  payload.replaysContext = true;
155
155
  }
156
+ if (context.modelRound) {
157
+ payload.modelRound = true;
158
+ }
159
+ if (context.roundCut) {
160
+ payload.roundCut = true;
161
+ }
156
162
  if (context.maxToolRounds !== undefined && context.maxToolRounds !== 0) {
157
163
  payload.maxToolRounds = checkMaxToolRounds(context.maxToolRounds);
158
164
  }
@@ -185,6 +191,25 @@ export class RemoteHarness extends EventEmitter {
185
191
  grantedWriteDirs: context.grantedWriteDirs
186
192
  }, { ...context, runId });
187
193
  }
194
+ async serveModelRound(request, io) {
195
+ const aborted = abortedRound(io.signal);
196
+ const { client } = await Promise.race([this._ensure(), aborted]);
197
+ const duplex = client.completion();
198
+ const stop = () => duplex.destroy();
199
+ io.signal?.addEventListener?.('abort', stop, { once: true });
200
+ try {
201
+ const frame = { type: 'model-round-ask', payload: request };
202
+ encode('@harness/completion-frame', frame);
203
+ duplex.write(frame);
204
+ const served = servedRound(frames(duplex), io);
205
+ served.catch(noop);
206
+ return await Promise.race([served, aborted]);
207
+ }
208
+ finally {
209
+ io.signal?.removeEventListener?.('abort', stop);
210
+ duplex.destroy();
211
+ }
212
+ }
188
213
  async *invoke(context) {
189
214
  const agent = context.agent ?? {};
190
215
  yield* this._run({
@@ -271,6 +296,12 @@ export class RemoteHarness extends EventEmitter {
271
296
  };
272
297
  let pauseTimer;
273
298
  let started = false;
299
+ const rounds = context.modelRound &&
300
+ new RoundHost(context.modelRound, (frame) => {
301
+ if (!closed) {
302
+ send({ ...frame });
303
+ }
304
+ });
274
305
  let failure = null;
275
306
  const send = (frame) => {
276
307
  if (!duplex)
@@ -330,6 +361,11 @@ export class RemoteHarness extends EventEmitter {
330
361
  throw failure;
331
362
  }
332
363
  started = true;
364
+ context.roundCut?.((note) => {
365
+ if (!closed) {
366
+ send({ type: 'round-cut', message: note });
367
+ }
368
+ });
333
369
  if (context.input) {
334
370
  void sendInput(context.input, (item) => {
335
371
  if (closed)
@@ -468,6 +504,14 @@ export class RemoteHarness extends EventEmitter {
468
504
  context.progress?.(event.cleared ? null : { percentage: event.percentage ?? 0 });
469
505
  continue;
470
506
  }
507
+ if (event.type === 'model-round-ask') {
508
+ rounds?.ask(event.callId ?? '', event.payload);
509
+ continue;
510
+ }
511
+ if (event.type === 'model-round-cancel') {
512
+ rounds?.cancel(event.callId ?? '');
513
+ continue;
514
+ }
471
515
  const wire = fromWire(event);
472
516
  if (wire.type === 'aborted' || wire.type === 'paused') {
473
517
  emittedAborted = true;
@@ -497,6 +541,7 @@ export class RemoteHarness extends EventEmitter {
497
541
  clearTimeout(pauseTimer);
498
542
  duplex?.destroy();
499
543
  closed = true;
544
+ rounds?.close();
500
545
  reclaim();
501
546
  if (hostLease && leasedRunId && context.runLog) {
502
547
  let timer;
@@ -971,12 +1016,33 @@ function died(message) {
971
1016
  return Object.assign(new Error(message), { code: HARNESS_DIED });
972
1017
  }
973
1018
  const noop = () => { };
974
- function refuseInProcessOnly(context) {
975
- for (const field of IN_PROCESS_ONLY_FIELDS) {
976
- if (context[field] !== undefined) {
977
- throw new HarnessError('CAPABILITY_UNSUPPORTED', [field]);
1019
+ function abortedRound(signal) {
1020
+ const aborted = new Promise((_resolve, reject) => {
1021
+ const abort = () => reject(new AbortedError());
1022
+ if (signal?.aborted) {
1023
+ abort();
1024
+ }
1025
+ signal?.addEventListener?.('abort', abort, { once: true });
1026
+ });
1027
+ aborted.catch(noop);
1028
+ return aborted;
1029
+ }
1030
+ async function servedRound(events, io) {
1031
+ let emit = io.emit;
1032
+ for await (const event of events) {
1033
+ if (io.signal?.aborted)
1034
+ break;
1035
+ if (event.type === 'content' || event.type === 'thinking') {
1036
+ emit({ type: event.type, text: event.text ?? '' });
1037
+ }
1038
+ else if (event.type === 'model-round-retake') {
1039
+ emit = io.retake();
1040
+ }
1041
+ else if (event.type === 'model-round-result') {
1042
+ return roundResultFrom(event);
978
1043
  }
979
1044
  }
1045
+ throw died('the harness ended a served round without its result');
980
1046
  }
981
1047
  function abortable(promise, signal) {
982
1048
  if (!signal)
@@ -2,6 +2,7 @@ import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
2
2
  import type { HarnessCapabilityProfile } from '../spec/hyperschema/types.d.ts';
3
3
  import type { AccessPolicy, AgentHandoff, ApproveFn, AskUserFn, AttachFn, FetchAttachmentFn, HistoryToolCall, ProgressFn, ResourceDescriptor, ResponseFormat } from './contract/index.ts';
4
4
  import type { KvCacheDeletionResult } from './capabilities/kv-cache.ts';
5
+ import type { ModelRoundIo, ModelRoundPort, ModelRoundRequest, ModelRoundResult } from './capabilities/completion-engine/index.ts';
5
6
  import type { ModelSourcePreview, PreviewModelSourceContext } from './capabilities/preview-model-source.ts';
6
7
  import type { MemoryBudget } from './hardware/memory-budget.ts';
7
8
  import type { EmbedDevice } from './models/embed-config.ts';
@@ -97,6 +98,8 @@ export interface CompletionContext {
97
98
  requestDigestKey?: Uint8Array;
98
99
  signal?: BareAbortSignal;
99
100
  input?: AsyncIterable<RunInput>;
101
+ roundCut?: (cut: (note: string) => void) => void;
102
+ modelRound?: ModelRoundPort;
100
103
  }
101
104
  export interface HostSignal {
102
105
  aborted?: boolean;
@@ -255,6 +258,7 @@ export interface InfraModel {
255
258
  }
256
259
  export interface HarnessContract {
257
260
  completion(context: CompletionContext | ResumeCompletionContext): AsyncIterable<HarnessEvent>;
261
+ serveModelRound?(request: ModelRoundRequest, io: ModelRoundIo): Promise<ModelRoundResult>;
258
262
  invoke?(context: InvokeContext): AsyncIterable<HarnessEvent>;
259
263
  download?(context: DownloadContext): AsyncIterable<HarnessEvent>;
260
264
  describe?(): Promise<HarnessInfo | null> | HarnessInfo;
@@ -0,0 +1,3 @@
1
+ export type PeerResolvers = Readonly<Record<string, () => unknown>>;
2
+ export declare function missingPeers(peers: PeerResolvers): string[];
3
+ export declare function requirePeers(subject: string, peers: PeerResolvers): void;
@@ -0,0 +1,23 @@
1
+ export function missingPeers(peers) {
2
+ return Object.keys(peers).filter((name) => !resolves(peers[name]));
3
+ }
4
+ export function requirePeers(subject, peers) {
5
+ const missing = missingPeers(peers);
6
+ if (missing.length === 0) {
7
+ return;
8
+ }
9
+ throw new Error(`${subject} needs ${missing.join(', ')}, not installed (optional peers of @qvac/harness): npm install ${missing.join(' ')}`);
10
+ }
11
+ function resolves(resolve) {
12
+ try {
13
+ resolve?.();
14
+ return true;
15
+ }
16
+ catch (error) {
17
+ const code = Reflect.get(Object(error), 'code');
18
+ if (code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND') {
19
+ return false;
20
+ }
21
+ throw error;
22
+ }
23
+ }
@@ -7,6 +7,7 @@ export interface LlmGenerationParams {
7
7
  frequency_penalty?: number;
8
8
  seed?: number;
9
9
  reasoning_budget?: number;
10
+ reasoning_rounds?: 'every' | 'plan';
10
11
  tool_choice?: 'auto' | 'none' | 'required';
11
12
  predict?: number;
12
13
  parallel_tool_calls?: boolean;
@@ -1,4 +1,4 @@
1
- import { AUDIOGEN_ACESTEP_5HZ_LM_0_6B_Q8_0, AUDIOGEN_ACESTEP_V15_BASE_Q4_K_M, AUDIOGEN_ACESTEP_V15_SFT_Q8_0, AUDIOGEN_ACESTEP_V15_TURBO_Q4_K_M, AUDIOGEN_ACESTEP_V15_TURBO_Q8_0, AUDIOGEN_QWEN3_EMBEDDING_0_6B_Q8_0, AUDIOGEN_VAE_BF16, EMBEDDINGGEMMA_300M_Q4_0, FLUX_2_KLEIN_4B_Q4_0, FLUX_2_KLEIN_4B_VAE, HEALTHCARE_1_7B_MEDICAL_Q4_K_M, HEALTHCARE_4B_MEDICAL_Q4_K_M, MMPROJ_QWEN3_5_2B_MULTIMODAL_Q8_0, MMPROJ_QWEN3_5_4B_MULTIMODAL_Q8_0, MMPROJ_QWEN3_5_9B_MULTIMODAL_F16, MMPROJ_QWEN3_6_27B_MULTIMODAL_F16, MMPROJ_QWEN3_6_35B_A3B_MULTIMODAL_F16, MMPROJ_QWEN3_8_27B_MULTIMODAL_F16, MMPROJ_TERNARY_BONSAI_2_27B_MULTIMODAL_Q8_0, QWEN3_5_2B_MULTIMODAL_Q4_K_M, QWEN3_5_4B_MULTIMODAL_Q4_K_M, QWEN3_5_9B_MULTIMODAL_Q4_K_M, PARAKEET_TDT_0_6B_V3_Q8_0, PARAKEET_TDT_1_1B_Q8_0, QWEN3_4B_Q4_K_M, QWEN3_6_27B_MULTIMODAL_Q4_K_XL, QWEN3_6_35B_A3B_MULTIMODAL_Q4_K_M, QWEN3_8_27B_MULTIMODAL_UD_Q4_K_XL, SD_V2_1_1B_Q8_0, SDXL_BASE_1_0_3B_Q4_0, TERNARY_BONSAI_2_27B_MULTIMODAL_PQ2_0, TERNARY_BONSAI_2_27B_MULTIMODAL_PTQ1_0, TTS_CODEC_DECODER_MOSS_TTS_F16, TTS_CODEC_ENCODER_MOSS_TTS_F16, TTS_DELAY_LLM_MOSS_TTS_F16, TTS_MULTILINGUAL_SUPERTONIC3_FP16, TTS_MULTILINGUAL_SUPERTONIC3_Q4_0, TTS_MULTILINGUAL_SUPERTONIC3_Q8_0 } from '@qvac/sdk/models';
1
+ import { AUDIOGEN_ACESTEP_5HZ_LM_0_6B_Q8_0, AUDIOGEN_ACESTEP_V15_BASE_Q4_K_M, AUDIOGEN_ACESTEP_V15_SFT_Q8_0, AUDIOGEN_ACESTEP_V15_TURBO_Q4_K_M, AUDIOGEN_ACESTEP_V15_TURBO_Q8_0, AUDIOGEN_QWEN3_EMBEDDING_0_6B_Q8_0, AUDIOGEN_VAE_BF16, EMBEDDINGGEMMA_300M_Q4_0, FLUX_2_KLEIN_4B_Q4_0, FLUX_2_KLEIN_4B_VAE, HEALTHCARE_1_7B_MEDICAL_Q4_K_M, HEALTHCARE_4B_MEDICAL_Q4_K_M, MMPROJ_QWEN3_5_2B_MULTIMODAL_Q8_0, MMPROJ_QWEN3_5_4B_MULTIMODAL_Q8_0, MMPROJ_QWEN3_5_9B_MULTIMODAL_F16, MMPROJ_QWEN3_6_27B_MULTIMODAL_F16, MMPROJ_QWEN3_6_35B_A3B_MULTIMODAL_F16, MMPROJ_QWEN3_8_27B_MULTIMODAL_F16, MMPROJ_TERNARY_BONSAI_2_27B_MULTIMODAL_Q8_0, QWEN3_5_2B_MULTIMODAL_Q4_K_M, QWEN3_5_4B_MULTIMODAL_Q4_K_M, QWEN3_5_9B_MULTIMODAL_Q4_K_M, PARAKEET_TDT_0_6B_V3_Q8_0, PARAKEET_TDT_1_1B_Q8_0, QWEN3_4B_Q4_K_M, QWEN3_6_27B_MULTIMODAL_Q4_K_XL, QWEN3_6_35B_A3B_MULTIMODAL_Q4_K_M, QWEN3_8_27B_MULTIMODAL_UD_Q4_K_XL, SD_V2_1_1B_Q8_0, SDXL_BASE_1_0_3B_Q4_0, TERNARY_BONSAI_2_27B_MULTIMODAL_PQ2_0, TERNARY_BONSAI_2_27B_MULTIMODAL_PTQ1_0, TTS_CODEC_DECODER_MOSS_TTS_F16, TTS_CODEC_ENCODER_MOSS_TTS_F16, TTS_DELAY_LLM_MOSS_TTS_F16, TTS_MULTILINGUAL_SUPERTONIC3_FP16, TTS_MULTILINGUAL_SUPERTONIC3_Q4_0, TTS_MULTILINGUAL_SUPERTONIC3_Q8_0 } from '@qvac/inference/models';
2
2
  import { detectToolDialect } from './tool-dialect.js';
3
3
  import { defaultTtsModelName } from './tts-model-default.js';
4
4
  import { CAPABILITY_PROFILE_ORDER, QWEN_35_2B, QWEN_35_4B, QWEN_35_9B, QWEN_36_27B, QWEN_36_35B_A3B, QWEN_38_27B, BONSAI_2_27B_PQ2, BONSAI_2_27B_PTQ1, MEDPSY_1_7B, MEDPSY_4B, isCapabilityProfile, meetsMinCapabilityProfile, modelNameToCapabilityProfile, capabilityProfileToModelName, isMultimodalLlm, AGENT_MODEL_NAMES, modelDisplayName, capabilityProfileModelLabel, DEFAULT_IMAGE_MODEL_CHOICE, IMAGE_CHOICE_CATALOG, isMobilePlatform, runnableModelName } from './model-catalog-constants.js';
@@ -2,11 +2,11 @@ import fs from 'fs';
2
2
  import { platform } from 'os';
3
3
  import path from 'path';
4
4
  import process from 'process';
5
- import sdkPkg from '@qvac/sdk/package' with { type: 'json' };
5
+ import enginePkg from '@qvac/inference/package' with { type: 'json' };
6
6
  const OPENCL_CACHE_DIR_ENV = 'QVAC_OPENCL_CACHE_DIR';
7
7
  export const OPENCL_CACHE_MAX_AGE_MS = 60 * 60 * 1000;
8
8
  const noop = () => { };
9
- export function openclEngineKey(sdkVersion = sdkPkg.version) {
9
+ export function openclEngineKey(sdkVersion = enginePkg.version) {
10
10
  return `sdk-${sdkVersion}`.replace(/[^A-Za-z0-9._-]/g, '_');
11
11
  }
12
12
  export function openclCacheRoot(env = process.env, hostPlatform = platform()) {
@@ -6,6 +6,7 @@ import type { EmbedHost, ModelHost } from '../contract/models.ts';
6
6
  import type { SpeechService } from '../contract/speech.ts';
7
7
  import type { HarnessHook, SkillReadiness } from '../contract/index.ts';
8
8
  import type { ExecLanguage, ExecRoute, ExecShell } from '../contract/exec.ts';
9
+ import { type PeerResolvers } from '../helpers/require-peers.ts';
9
10
  import type { Context, Services } from './context.ts';
10
11
  import type { Dispose } from './scope.ts';
11
12
  declare module './context.ts' {
@@ -99,6 +100,7 @@ export declare class PluginRegistry {
99
100
  private _closing;
100
101
  constructor(plugins: readonly HarnessPlugin[], options?: PluginRegistryOptions);
101
102
  static loadAddons(owner: string, addons?: AddonLoaders): Promise<void>;
103
+ static requirePeers(plugin: string, peers: PeerResolvers): void;
102
104
  start(reserved: Iterable<string>, { fetch, publish }?: PluginStartOptions): Promise<StartedPlugins>;
103
105
  add(plugin: HarnessPlugin): Promise<void>;
104
106
  remove(name: string): Promise<void>;
@@ -3,6 +3,7 @@ import { Policy } from '../policy/index.js';
3
3
  import { canonicalDenyRoots, defaultRealpath } from '../tools/fs/scope.js';
4
4
  import { TOOLSETS } from '../tools/toolsets.js';
5
5
  import { loadAddons } from './addons.js';
6
+ import { requirePeers } from '../helpers/require-peers.js';
6
7
  import { PluginRuntime } from './runtime.js';
7
8
  const API_VERSION = 1;
8
9
  const EXEC_TOOL = 'exec';
@@ -283,6 +284,9 @@ export class PluginRegistry {
283
284
  static loadAddons(owner, addons) {
284
285
  return loadAddons(owner, addons);
285
286
  }
287
+ static requirePeers(plugin, peers) {
288
+ requirePeers(`@qvac/harness/plugins/${plugin}`, peers);
289
+ }
286
290
  start(reserved, { fetch, publish } = {}) {
287
291
  if (this._closing) {
288
292
  return Promise.reject(new Error('Plugin registry is closing or closed'));
@@ -0,0 +1,12 @@
1
+ import type { ModelRoundPort } from './capabilities/completion-engine/index.ts';
2
+ export declare class RoundHost {
3
+ private readonly _port;
4
+ private readonly _out;
5
+ private readonly _rounds;
6
+ constructor(port: ModelRoundPort, 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
+ }
@@ -0,0 +1,57 @@
1
+ import { AbortController } from 'bare-abort-controller';
2
+ import { pushQueue } from './queue.js';
3
+ import { roundFailureWire, roundRequestFrom } from './wire.js';
4
+ export class RoundHost {
5
+ _port;
6
+ _out = pushQueue();
7
+ _rounds = new Map();
8
+ constructor(port, send) {
9
+ this._port = port;
10
+ void this._drain(send);
11
+ }
12
+ ask(callId, payload) {
13
+ const controller = new AbortController();
14
+ this._rounds.set(callId, controller);
15
+ let taker = 0;
16
+ const emitter = (generation) => (event) => {
17
+ if (generation !== taker || !this._rounds.has(callId))
18
+ return;
19
+ void this._out.push({ type: 'model-round-chunk', callId, payload: event });
20
+ };
21
+ const retake = () => {
22
+ if (!this._rounds.has(callId))
23
+ return noop;
24
+ void this._out.push({ type: 'model-round-retake', callId });
25
+ return emitter(++taker);
26
+ };
27
+ void Promise.resolve()
28
+ .then(() => this._port(roundRequestFrom(payload), {
29
+ signal: controller.signal,
30
+ emit: emitter(0),
31
+ retake
32
+ }))
33
+ .then((result) => this._settle(callId, { result }), (err) => this._settle(callId, roundFailureWire(err)));
34
+ }
35
+ cancel(callId) {
36
+ this._rounds.get(callId)?.abort(undefined);
37
+ this._rounds.delete(callId);
38
+ }
39
+ close() {
40
+ for (const callId of [...this._rounds.keys()]) {
41
+ this.cancel(callId);
42
+ }
43
+ this._out.end();
44
+ }
45
+ _settle(callId, frame) {
46
+ if (this._rounds.delete(callId)) {
47
+ void this._out.push({ type: 'model-round-result', callId, ...frame });
48
+ }
49
+ }
50
+ async _drain(send) {
51
+ for await (const frame of this._out) {
52
+ send(frame);
53
+ await new Promise((resolve) => setTimeout(resolve, 0));
54
+ }
55
+ }
56
+ }
57
+ function noop() { }
@@ -0,0 +1,24 @@
1
+ import type { ModelRoundPort } from './capabilities/completion-engine/index.ts';
2
+ import { type WireEvent } from './wire.ts';
3
+ export interface RoundFrame {
4
+ type: string;
5
+ callId?: string | null;
6
+ message?: string | null;
7
+ result?: unknown;
8
+ payload?: unknown;
9
+ }
10
+ export declare class RoundPort {
11
+ private readonly _push;
12
+ private readonly _asked;
13
+ private _calls;
14
+ private _cut;
15
+ private _closed;
16
+ constructor(push: (event: WireEvent) => unknown);
17
+ port: ModelRoundPort;
18
+ roundCut: (cut: (note: string) => void) => void;
19
+ frame(frame: RoundFrame): boolean;
20
+ close(): void;
21
+ private _retake;
22
+ private _settle;
23
+ private _take;
24
+ }
@@ -0,0 +1,81 @@
1
+ import { HarnessError } from './errors.js';
2
+ import { AbortedError } from './helpers/engine-error.js';
3
+ import { roundChunkFrom, roundResultFrom } from './wire.js';
4
+ export class RoundPort {
5
+ _push;
6
+ _asked = new Map();
7
+ _calls = 0;
8
+ _cut = null;
9
+ _closed = false;
10
+ constructor(push) {
11
+ this._push = push;
12
+ }
13
+ port = (request, io) => {
14
+ if (this._closed) {
15
+ return Promise.reject(new HarnessError('CLIENT_GONE'));
16
+ }
17
+ if (io.signal.aborted) {
18
+ return Promise.reject(new AbortedError());
19
+ }
20
+ const callId = String(this._calls++);
21
+ return new Promise((resolve, reject) => {
22
+ const cancel = () => {
23
+ if (!this._take(callId))
24
+ return;
25
+ this._push({ type: 'model-round-cancel', callId });
26
+ reject(new AbortedError());
27
+ };
28
+ this._asked.set(callId, { io, emit: io.emit, cancel, resolve, reject });
29
+ io.signal.addEventListener('abort', cancel, { once: true });
30
+ this._push({ type: 'model-round-ask', callId, payload: request });
31
+ });
32
+ };
33
+ roundCut = (cut) => {
34
+ this._cut = cut;
35
+ };
36
+ frame(frame) {
37
+ switch (frame.type) {
38
+ case 'model-round-chunk':
39
+ this._asked.get(frame.callId ?? '')?.emit(roundChunkFrom(frame.payload));
40
+ return true;
41
+ case 'model-round-retake':
42
+ this._retake(frame.callId ?? '');
43
+ return true;
44
+ case 'model-round-result':
45
+ this._settle(frame);
46
+ return true;
47
+ case 'round-cut':
48
+ this._cut?.(frame.message ?? '');
49
+ return true;
50
+ default:
51
+ return false;
52
+ }
53
+ }
54
+ close() {
55
+ this._closed = true;
56
+ for (const callId of [...this._asked.keys()]) {
57
+ this._take(callId)?.reject(new HarnessError('CLIENT_GONE'));
58
+ }
59
+ }
60
+ _retake(callId) {
61
+ const asked = this._asked.get(callId);
62
+ if (asked) {
63
+ asked.emit = asked.io.retake();
64
+ }
65
+ }
66
+ _settle(frame) {
67
+ const asked = this._take(frame.callId ?? '');
68
+ try {
69
+ asked?.resolve(roundResultFrom(frame));
70
+ }
71
+ catch (err) {
72
+ asked?.reject(err);
73
+ }
74
+ }
75
+ _take(callId) {
76
+ const asked = this._asked.get(callId);
77
+ this._asked.delete(callId);
78
+ asked?.io.signal.removeEventListener('abort', asked.cancel);
79
+ return asked;
80
+ }
81
+ }
@@ -1,6 +1,6 @@
1
1
  import type { AddonLoaders } from './contract/index.ts';
2
2
  type Sdk = typeof import('#sdk');
3
- export type SdkPlugin = Parameters<(typeof import('@qvac/sdk/plugins'))['registerPlugin']>[0];
3
+ export type SdkPlugin = Parameters<(typeof import('@qvac/inference/plugin-registry'))['registerPlugin']>[0];
4
4
  type Plugin = SdkPlugin;
5
5
  interface PluginRegistry {
6
6
  registerPlugin(plugin: Plugin): void;
@@ -1,11 +1,12 @@
1
1
  import { errorMessage } from './guards.js';
2
+ import { missingPeers, requirePeers } from './helpers/require-peers.js';
2
3
  import { retryMemo } from './helpers/retry-memo.js';
3
4
  import { HarnessLog } from './log.js';
4
5
  const defaultImports = {
5
6
  sdk: () => import('#sdk'),
6
- plugins: () => import('@qvac/sdk/plugins'),
7
- llm: () => import('@qvac/sdk/llamacpp-completion/plugin'),
8
- embeddings: () => import('@qvac/sdk/llamacpp-embedding/plugin')
7
+ plugins: () => import('@qvac/inference/plugin-registry'),
8
+ llm: () => import('@qvac/inference/llamacpp-completion/plugin'),
9
+ embeddings: () => import('@qvac/inference/llamacpp-embedding/plugin')
9
10
  };
10
11
  function register(registry, name, plugin) {
11
12
  try {
@@ -19,8 +20,19 @@ function register(registry, name, plugin) {
19
20
  }
20
21
  }
21
22
  const IN_PROCESS = typeof globalThis.Bare !== 'undefined';
23
+ const COMPLETION_PEERS = IN_PROCESS
24
+ ? {
25
+ '@qvac/llm-llamacpp': () => import.meta.resolve('@qvac/llm-llamacpp/addonLogging'),
26
+ '@qvac/langdetect-text': () => import.meta.resolve('@qvac/langdetect-text')
27
+ }
28
+ : { '@qvac/sdk': () => import.meta.resolve('#sdk') };
29
+ const EMBEDDING_PEERS = {
30
+ '@qvac/embed-llamacpp': () => import.meta.resolve('@qvac/embed-llamacpp/addonLogging')
31
+ };
32
+ const requireCompletion = () => requirePeers('@qvac/harness completion', COMPLETION_PEERS);
22
33
  export function createSdkLoader(imports = defaultImports) {
23
34
  const load = retryMemo(async () => {
35
+ requireCompletion();
24
36
  if (!IN_PROCESS) {
25
37
  return imports.sdk();
26
38
  }
@@ -34,6 +46,7 @@ export function createSdkLoader(imports = defaultImports) {
34
46
  });
35
47
  const loadEmbed = IN_PROCESS
36
48
  ? retryMemo(async () => {
49
+ requirePeers('@qvac/harness embeddings', EMBEDDING_PEERS);
37
50
  const [sdk, { embeddingsPlugin }, registry] = await Promise.all([
38
51
  load(),
39
52
  imports.embeddings(),
@@ -43,11 +56,22 @@ export function createSdkLoader(imports = defaultImports) {
43
56
  return sdk;
44
57
  })
45
58
  : load;
46
- const addons = {
59
+ return { load, loadEmbed, peek: () => load.peek(), addons: addonLoaders(load, loadEmbed) };
60
+ }
61
+ function addonLoaders(load, loadEmbed) {
62
+ const completion = {
47
63
  sdk: load,
64
+ 'llm-llamacpp': () => {
65
+ requireCompletion();
66
+ return import('@qvac/llm-llamacpp/addonLogging');
67
+ }
68
+ };
69
+ if (missingPeers(EMBEDDING_PEERS).length > 0) {
70
+ return completion;
71
+ }
72
+ return {
73
+ ...completion,
48
74
  embeddings: loadEmbed,
49
- 'llm-llamacpp': () => import('@qvac/llm-llamacpp/addonLogging'),
50
75
  'embed-llamacpp': () => import('@qvac/embed-llamacpp/addonLogging')
51
76
  };
52
- return { load, loadEmbed, peek: () => load.peek(), addons };
53
77
  }
@@ -1,6 +1,7 @@
1
1
  import { type SdkStorage } from './storage.ts';
2
2
  export declare const SDK_CONFIG_PATH_ENV = "QVAC_CONFIG_PATH";
3
3
  export declare const OPENCL_CACHE_DIR_ENV = "QVAC_OPENCL_CACHE_DIR";
4
+ export declare const SDK_OPTIONS_ENV = "QVAC_SDK_OPTIONS";
4
5
  export interface SdkStorageChannels {
5
6
  readonly env?: Record<string, string | undefined>;
6
7
  readonly argv?: Array<string> | null;
@@ -1,18 +1,24 @@
1
- import { mkdirSync, writeFileSync } from 'fs';
1
+ import { mkdirSync, readFileSync, writeFileSync } from 'fs';
2
2
  import { join } from 'path';
3
3
  import process from 'process';
4
4
  import { isBareKit } from 'which-runtime';
5
5
  import { installSdkConfigLoader } from '#sdk-config-loader';
6
+ import { isRecord } from './guards.js';
6
7
  import { SDK_HOME_ENV } from './storage.js';
7
8
  export const SDK_CONFIG_PATH_ENV = 'QVAC_CONFIG_PATH';
8
9
  export const OPENCL_CACHE_DIR_ENV = 'QVAC_OPENCL_CACHE_DIR';
10
+ export const SDK_OPTIONS_ENV = 'QVAC_SDK_OPTIONS';
9
11
  const FIT_STUB_BUDGET_MS = 10_000;
10
12
  export function configureSdkStorage(storage, channels = {}) {
11
13
  const { env = process.env, argv = isBareKit ? Bare.argv : null } = channels;
12
14
  installSdkConfigLoader();
13
15
  mkdirSync(storage.home, { recursive: true });
14
16
  const configPath = join(storage.home, 'qvac.config.json');
15
- const config = { cacheDirectory: storage.models, fitStubBudgetMs: FIT_STUB_BUDGET_MS };
17
+ const config = {
18
+ ...hostOptions(env[SDK_OPTIONS_ENV]),
19
+ cacheDirectory: storage.models,
20
+ fitStubBudgetMs: FIT_STUB_BUDGET_MS
21
+ };
16
22
  writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
17
23
  const openclCacheDir = join(storage.home, 'opencl-cache');
18
24
  mkdirSync(openclCacheDir, { recursive: true });
@@ -26,3 +32,13 @@ export function configureSdkStorage(storage, channels = {}) {
26
32
  env[OPENCL_CACHE_DIR_ENV] = openclCacheDir;
27
33
  return configPath;
28
34
  }
35
+ function hostOptions(file) {
36
+ if (!file) {
37
+ return {};
38
+ }
39
+ const options = JSON.parse(readFileSync(file, 'utf8'));
40
+ if (!isRecord(options) || Array.isArray(options)) {
41
+ throw new Error(`${SDK_OPTIONS_ENV} must name a JSON object: ${file}`);
42
+ }
43
+ return options;
44
+ }