@qvac/harness 1.0.0-rc.5 → 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.
- package/CHANGELOG.md +245 -23
- package/README.md +19 -7
- package/dist-lib/index.d.ts +5 -3
- package/dist-lib/index.js +43 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +13 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +8 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +21 -19
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +11 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +10 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +9 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +36 -19
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +9 -11
- package/dist-lib/lib/capabilities/completion-engine/driver.js +3 -0
- package/dist-lib/lib/capabilities/completion-engine/index.d.ts +4 -1
- package/dist-lib/lib/capabilities/completion-engine/index.js +3 -0
- package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +15 -1
- package/dist-lib/lib/capabilities/completion-engine/model-round.js +52 -0
- package/dist-lib/lib/capabilities/completion-engine/round.d.ts +3 -3
- package/dist-lib/lib/capabilities/completion-engine/round.js +5 -2
- package/dist-lib/lib/capabilities/completion-engine/tool-sets.d.ts +24 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-sets.js +15 -0
- package/dist-lib/lib/capabilities/completion-engine/turns.js +14 -4
- package/dist-lib/lib/capabilities/detect-language.d.ts +2 -1
- package/dist-lib/lib/capabilities/detect-language.js +14 -2
- package/dist-lib/lib/capabilities/sdk-tool.d.ts +9 -1
- package/dist-lib/lib/capabilities/sdk-tool.js +21 -2
- package/dist-lib/lib/capabilities/tool-plan.d.ts +4 -0
- package/dist-lib/lib/capabilities/tool-plan.js +15 -0
- package/dist-lib/lib/connect.d.ts +2 -0
- package/dist-lib/lib/connect.js +79 -3
- package/dist-lib/lib/contract/run.d.ts +2 -0
- package/dist-lib/lib/contract-types.d.ts +5 -0
- package/dist-lib/lib/errors.d.ts +4 -0
- package/dist-lib/lib/errors.js +6 -0
- package/dist-lib/lib/hardware/cpu-placement.d.ts +8 -0
- package/dist-lib/lib/hardware/cpu-placement.js +48 -0
- package/dist-lib/lib/helpers/goal-check.d.ts +2 -0
- package/dist-lib/lib/helpers/goal-check.js +18 -0
- package/dist-lib/lib/helpers/require-peers.d.ts +3 -0
- package/dist-lib/lib/helpers/require-peers.js +23 -0
- package/dist-lib/lib/machine/completion/actions/completion.js +30 -11
- package/dist-lib/lib/machine/completion/context.js +2 -1
- package/dist-lib/lib/machine/completion/rules.d.ts +1 -1
- package/dist-lib/lib/machine/completion/rules.js +7 -8
- package/dist-lib/lib/machine/completion/types.d.ts +1 -0
- package/dist-lib/lib/models/llm-presets.d.ts +1 -0
- package/dist-lib/lib/models/model-catalog.js +1 -1
- package/dist-lib/lib/models/model-pool.d.ts +4 -0
- package/dist-lib/lib/models/model-pool.js +4 -1
- package/dist-lib/lib/models/opencl-cache.js +2 -2
- package/dist-lib/lib/plugins/registry.d.ts +2 -0
- package/dist-lib/lib/plugins/registry.js +4 -0
- package/dist-lib/lib/prompt.d.ts +2 -1
- package/dist-lib/lib/prompt.js +12 -12
- package/dist-lib/lib/residency/completion-runtime.d.ts +9 -1
- package/dist-lib/lib/residency/completion-runtime.js +29 -26
- package/dist-lib/lib/residency/index.d.ts +4 -0
- package/dist-lib/lib/residency/index.js +6 -1
- package/dist-lib/lib/round-host.d.ts +12 -0
- package/dist-lib/lib/round-host.js +57 -0
- package/dist-lib/lib/round-port.d.ts +24 -0
- package/dist-lib/lib/round-port.js +81 -0
- package/dist-lib/lib/sdk-loader.d.ts +1 -1
- package/dist-lib/lib/sdk-loader.js +30 -6
- package/dist-lib/lib/sdk-storage.d.ts +1 -0
- package/dist-lib/lib/sdk-storage.js +18 -2
- package/dist-lib/lib/serve.js +68 -6
- package/dist-lib/lib/sidecar/index.d.ts +10 -0
- package/dist-lib/lib/sidecar/index.js +35 -3
- package/dist-lib/lib/sidecar/user-plugins.d.ts +1 -0
- package/dist-lib/lib/sidecar/user-plugins.js +1 -1
- package/dist-lib/lib/tools/files/grep.js +113 -15
- package/dist-lib/lib/tools/fs/edit-match.js +75 -7
- package/dist-lib/lib/tools/fs/search.d.ts +1 -1
- package/dist-lib/lib/tools/fs/search.js +2 -1
- package/dist-lib/lib/tools/http-request.js +1 -0
- package/dist-lib/lib/tools/index.d.ts +2 -1
- package/dist-lib/lib/tools/index.js +2 -2
- package/dist-lib/lib/tools/skills/skill-state-constants.d.ts +1 -0
- package/dist-lib/lib/tools/skills/skill-state-constants.js +4 -0
- package/dist-lib/lib/wire.d.ts +13 -0
- package/dist-lib/lib/wire.js +44 -1
- package/dist-lib/plugins/coding/read-only.d.ts +1 -0
- package/dist-lib/plugins/coding/read-only.js +264 -0
- package/dist-lib/plugins/coding/session.d.ts +3 -1
- package/dist-lib/plugins/coding/session.js +19 -2
- package/dist-lib/plugins/egress-proxy/index.d.ts +2 -2
- package/dist-lib/plugins/egress-proxy/index.js +5 -3
- package/dist-lib/plugins/image/index.js +7 -2
- package/dist-lib/plugins/language-hint/index.js +4 -1
- package/dist-lib/plugins/mcp/server.js +1 -1
- package/dist-lib/plugins/music/index.js +6 -2
- package/dist-lib/plugins/obsidian/readiness.js +2 -2
- package/dist-lib/plugins/obsidian/vault-read.js +17 -16
- package/dist-lib/plugins/python/index.js +1 -0
- package/dist-lib/plugins/python/loader.d.ts +1 -0
- package/dist-lib/plugins/python/loader.js +8 -0
- package/dist-lib/plugins/quickjs/index.js +4 -0
- package/dist-lib/plugins/quickjs/runtime.js +8 -3
- package/dist-lib/plugins/run-report/index.js +6 -2
- package/dist-lib/plugins/run-report/layout.js +1 -1
- package/dist-lib/plugins/sandbox-vm/index.js +3 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/speech/audio-resample.js +2 -1
- package/dist-lib/plugins/speech/index.d.ts +1 -0
- package/dist-lib/plugins/speech/index.js +8 -1
- package/dist-lib/plugins/speech/speech-runtime.js +3 -3
- package/dist-lib/plugins/translation/index.d.ts +1 -1
- package/dist-lib/plugins/translation/index.js +7 -3
- package/dist-lib/plugins/translation/translate.d.ts +2 -2
- package/dist-lib/plugins/translation/translate.js +7 -8
- package/dist-lib/plugins/walkie-talkie/index.d.ts +2 -2
- package/dist-lib/plugins/walkie-talkie/index.js +13 -5
- package/dist-lib/plugins/walkie-talkie/wire.d.ts +5 -0
- package/dist-lib/plugins/walkie-talkie/wire.js +6 -5
- package/dist-lib/schema/harness.js +12 -2
- package/dist-lib/spec/hrpc/messages.js +208 -150
- package/dist-lib/spec/hyperschema/index.js +208 -150
- package/dist-lib/spec/hyperschema/schema.json +125 -84
- package/dist-lib/spec/hyperschema/types.d.ts +4 -3
- package/package.json +150 -25
|
@@ -166,8 +166,16 @@ async function importPyodide() {
|
|
|
166
166
|
export async function loadPyodideAddons() {
|
|
167
167
|
await importPyodide();
|
|
168
168
|
}
|
|
169
|
+
export function glueIsPatched(src) {
|
|
170
|
+
return /function addEmJs\([^)]*\)\{throw /.test(src);
|
|
171
|
+
}
|
|
172
|
+
let warnedUnpatched = false;
|
|
169
173
|
export const defaultLoad = async () => {
|
|
170
174
|
const { loadPyodide, createPyodideModule } = await importPyodide();
|
|
175
|
+
if (!warnedUnpatched && !glueIsPatched(String(createPyodideModule))) {
|
|
176
|
+
warnedUnpatched = true;
|
|
177
|
+
console.warn('qvac-harness: pyodide is unpatched, guest Python can run host JS; copy patches/pyodide@314.0.2.patch');
|
|
178
|
+
}
|
|
171
179
|
const options = pyodideLoadOptions();
|
|
172
180
|
if (options.packageCacheDir) {
|
|
173
181
|
seedPackageCache(options.packageCacheDir);
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
2
2
|
import { createJavaScriptLanguage } from './language.js';
|
|
3
3
|
import { Interpreter, MAX_DEADLINE_MS, SLICE_MS } from './runtime.js';
|
|
4
|
+
PluginRegistry.requirePeers('quickjs', {
|
|
5
|
+
'@jitl/quickjs-singlefile-mjs-release-sync': () => import.meta.resolve('@jitl/quickjs-singlefile-mjs-release-sync'),
|
|
6
|
+
'quickjs-emscripten-core': () => import.meta.resolve('quickjs-emscripten-core')
|
|
7
|
+
});
|
|
4
8
|
export class QuickJs {
|
|
5
9
|
static MAX_DEADLINE_MS = MAX_DEADLINE_MS;
|
|
6
10
|
static SLICE_MS = SLICE_MS;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import variant from '@jitl/quickjs-singlefile-mjs-release-sync';
|
|
2
|
-
import { newQuickJSWASMModuleFromVariant } from 'quickjs-emscripten-core';
|
|
3
1
|
import { errorMessage, isRecord } from '../../lib/guards.js';
|
|
4
2
|
import { AbortedError } from '../../lib/helpers/race-abort.js';
|
|
5
3
|
import { appendOutput, createCapturedOutput, DEFAULT_TIMEOUT_MS, formatOutput, MAX_OUTPUT_CHARS } from '../../lib/tools/exec/runner.js';
|
|
@@ -338,6 +336,13 @@ class Script {
|
|
|
338
336
|
settle();
|
|
339
337
|
}
|
|
340
338
|
}
|
|
339
|
+
async function loadModule() {
|
|
340
|
+
const [{ default: variant }, { newQuickJSWASMModuleFromVariant }] = await Promise.all([
|
|
341
|
+
import('@jitl/quickjs-singlefile-mjs-release-sync'),
|
|
342
|
+
import('quickjs-emscripten-core')
|
|
343
|
+
]);
|
|
344
|
+
return newQuickJSWASMModuleFromVariant(variant);
|
|
345
|
+
}
|
|
341
346
|
export class Interpreter {
|
|
342
347
|
_limits;
|
|
343
348
|
_module = null;
|
|
@@ -349,7 +354,7 @@ export class Interpreter {
|
|
|
349
354
|
_load() {
|
|
350
355
|
if (!this._module) {
|
|
351
356
|
ensureTextDecoder();
|
|
352
|
-
const loading =
|
|
357
|
+
const loading = loadModule();
|
|
353
358
|
this._module = loading;
|
|
354
359
|
loading.catch(() => this._drop(loading));
|
|
355
360
|
}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { randomBytes } from 'crypto';
|
|
2
2
|
import { RunLog } from '../../lib/run-log/index.js';
|
|
3
3
|
import { chain } from './chain.js';
|
|
4
4
|
import { flow } from './flow.js';
|
|
5
5
|
import { layout } from './layout.js';
|
|
6
6
|
import { reportModel } from './model.js';
|
|
7
|
+
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
7
8
|
import { parts, shell } from './page.js';
|
|
9
|
+
PluginRegistry.requirePeers('run-report', {
|
|
10
|
+
elkjs: () => import.meta.resolve('elkjs/lib/elk.bundled.js')
|
|
11
|
+
});
|
|
8
12
|
export class RunReport {
|
|
9
13
|
static record() {
|
|
10
14
|
const hops = [];
|
|
11
|
-
const requestDigestKey =
|
|
15
|
+
const requestDigestKey = randomBytes(32);
|
|
12
16
|
const hopLog = () => {
|
|
13
17
|
const records = [];
|
|
14
18
|
let boot = RunLog.createEngineBoot();
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import ELK, {} from 'elkjs/lib/elk.bundled.js';
|
|
2
1
|
const KINDS = { final: 'final', history: 'history' };
|
|
3
2
|
const CHAR = 7.4;
|
|
4
3
|
const LINE = 15;
|
|
@@ -22,6 +21,7 @@ export async function layout(definition, ran) {
|
|
|
22
21
|
const graph = new Graph(definition);
|
|
23
22
|
graph.walk(definition);
|
|
24
23
|
const { nodes, edges } = ran ? only(graph, ran) : graph;
|
|
24
|
+
const { default: ELK } = await import('elkjs/lib/elk.bundled.js');
|
|
25
25
|
const laid = await new ELK().layout({
|
|
26
26
|
id: '__root',
|
|
27
27
|
layoutOptions: OPTIONS,
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
2
2
|
import { barevisorSandbox, GuestShell } from './vm-shell.js';
|
|
3
|
+
PluginRegistry.requirePeers('sandbox-vm', {
|
|
4
|
+
barevisor: () => import.meta.resolve('barevisor/sandbox')
|
|
5
|
+
});
|
|
3
6
|
export { WORKDIR_REFUSED } from './vm-shell.js';
|
|
4
7
|
function imageError(image) {
|
|
5
8
|
return image?.kernel && image.initrd
|
|
Binary file
|
|
Binary file
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
-
import { decodeToPcm16kMono, transcodeToWav16kMono } from '#audio-transcode';
|
|
3
2
|
const TARGET_SAMPLE_RATE = 16000;
|
|
4
3
|
const TARGET_CHANNELS = 1;
|
|
5
4
|
const TARGET_BITS_PER_SAMPLE = 16;
|
|
@@ -57,6 +56,7 @@ export async function resampleForTranscription(bytes) {
|
|
|
57
56
|
if (!needsResample(bytes)) {
|
|
58
57
|
return { bytes, transcoded: false };
|
|
59
58
|
}
|
|
59
|
+
const { transcodeToWav16kMono } = await import('#audio-transcode');
|
|
60
60
|
const wav = await transcodeToWav16kMono(bytes);
|
|
61
61
|
return wav ? { bytes: wav, transcoded: true } : { bytes, transcoded: false };
|
|
62
62
|
}
|
|
@@ -79,5 +79,6 @@ export async function* pcmForTranscription(bytes) {
|
|
|
79
79
|
yield pcm;
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
|
+
const { decodeToPcm16kMono } = await import('#audio-transcode');
|
|
82
83
|
yield* decodeToPcm16kMono(bytes);
|
|
83
84
|
}
|
|
@@ -9,6 +9,7 @@ export declare class Speech implements HarnessPlugin {
|
|
|
9
9
|
readonly addons: {
|
|
10
10
|
'tts-ggml': () => Promise<typeof import("@qvac/tts-ggml/addonLogging")>;
|
|
11
11
|
'asr-ggml': () => Promise<typeof import("@qvac/asr-ggml/addonLogging")>;
|
|
12
|
+
'bare-ffmpeg': () => Promise<typeof import("#audio-transcode")>;
|
|
12
13
|
};
|
|
13
14
|
private readonly _options;
|
|
14
15
|
constructor(options?: SpeechOptions);
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
2
2
|
import { invalidOptions } from './speech-engine.js';
|
|
3
3
|
import { SpeechRuntime } from './speech-runtime.js';
|
|
4
|
+
PluginRegistry.requirePeers('speech', {
|
|
5
|
+
'@qvac/asr-ggml': () => import.meta.resolve('@qvac/asr-ggml/addonLogging'),
|
|
6
|
+
'@qvac/decoder-audio': () => import.meta.resolve('@qvac/decoder-audio'),
|
|
7
|
+
'@qvac/tts-ggml': () => import.meta.resolve('@qvac/tts-ggml/addonLogging'),
|
|
8
|
+
'bare-ffmpeg': () => import.meta.resolve('bare-ffmpeg')
|
|
9
|
+
});
|
|
4
10
|
export class Speech {
|
|
5
11
|
name = 'speech';
|
|
6
12
|
api = PluginRegistry.API_VERSION;
|
|
@@ -8,7 +14,8 @@ export class Speech {
|
|
|
8
14
|
needs = ['models'];
|
|
9
15
|
addons = {
|
|
10
16
|
'tts-ggml': () => import('@qvac/tts-ggml/addonLogging'),
|
|
11
|
-
'asr-ggml': () => import('@qvac/asr-ggml/addonLogging')
|
|
17
|
+
'asr-ggml': () => import('@qvac/asr-ggml/addonLogging'),
|
|
18
|
+
'bare-ffmpeg': () => import('#audio-transcode')
|
|
12
19
|
};
|
|
13
20
|
_options;
|
|
14
21
|
constructor(options = {}) {
|
|
@@ -15,9 +15,9 @@ function voiceSdk(models) {
|
|
|
15
15
|
const sdk = await models.sdk();
|
|
16
16
|
if (typeof globalThis.Bare !== 'undefined') {
|
|
17
17
|
const [{ ttsPlugin }, { parakeetPlugin }, { registerPlugin }] = await Promise.all([
|
|
18
|
-
import('@qvac/
|
|
19
|
-
import('@qvac/
|
|
20
|
-
import('@qvac/
|
|
18
|
+
import('@qvac/inference/tts-ggml/plugin'),
|
|
19
|
+
import('@qvac/inference/parakeet-transcription/plugin'),
|
|
20
|
+
import('@qvac/inference/plugin-registry')
|
|
21
21
|
]);
|
|
22
22
|
for (const [name, plugin] of [
|
|
23
23
|
['tts', ttsPlugin],
|
|
@@ -16,7 +16,7 @@ export declare class TranslationPlugin implements HarnessPlugin {
|
|
|
16
16
|
readonly provides: string[];
|
|
17
17
|
readonly needs: string[];
|
|
18
18
|
readonly addons: {
|
|
19
|
-
translation: () => Promise<typeof import("@qvac/
|
|
19
|
+
translation: () => Promise<typeof import("@qvac/inference/nmtcpp-translation/plugin")>;
|
|
20
20
|
'translation-nmtcpp': () => Promise<typeof import("@qvac/translation-nmtcpp/addonLogging")>;
|
|
21
21
|
};
|
|
22
22
|
setup(ctx: PluginContext): PluginSetup;
|
|
@@ -4,13 +4,17 @@ import { retryMemo } from '../../lib/helpers/retry-memo.js';
|
|
|
4
4
|
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
5
5
|
import { EURONANO_LANGUAGES, NMT_FROM_ENGLISH, NMT_TO_ENGLISH, SLM_LANGUAGE_CODES, SLM_LANGUAGE_NAMES, translationPlanFor } from './nmt-catalog.js';
|
|
6
6
|
import { createTranslate, createTranslateTool, createTranslationRuntime } from './translate.js';
|
|
7
|
+
PluginRegistry.requirePeers('translation', {
|
|
8
|
+
'@qvac/langdetect-text': () => import.meta.resolve('@qvac/langdetect-text'),
|
|
9
|
+
'@qvac/translation-nmtcpp': () => import.meta.resolve('@qvac/translation-nmtcpp/addonLogging')
|
|
10
|
+
});
|
|
7
11
|
function nmtSdk(models) {
|
|
8
12
|
return retryMemo(async () => {
|
|
9
13
|
const sdk = await models.sdk();
|
|
10
14
|
if (typeof globalThis.Bare !== 'undefined') {
|
|
11
15
|
const [{ nmtPlugin }, { registerPlugin }] = await Promise.all([
|
|
12
|
-
import('@qvac/
|
|
13
|
-
import('@qvac/
|
|
16
|
+
import('@qvac/inference/nmtcpp-translation/plugin'),
|
|
17
|
+
import('@qvac/inference/plugin-registry')
|
|
14
18
|
]);
|
|
15
19
|
try {
|
|
16
20
|
registerPlugin(nmtPlugin);
|
|
@@ -47,7 +51,7 @@ export class TranslationPlugin {
|
|
|
47
51
|
provides = ['translation'];
|
|
48
52
|
needs = ['models'];
|
|
49
53
|
addons = {
|
|
50
|
-
translation: () => import('@qvac/
|
|
54
|
+
translation: () => import('@qvac/inference/nmtcpp-translation/plugin'),
|
|
51
55
|
'translation-nmtcpp': () => import('@qvac/translation-nmtcpp/addonLogging')
|
|
52
56
|
};
|
|
53
57
|
setup(ctx) {
|
|
@@ -69,7 +69,7 @@ export type SlmTranslateFn = (model: string, params: {
|
|
|
69
69
|
from: string;
|
|
70
70
|
to: string;
|
|
71
71
|
}, signal?: BareAbortSignal) => Promise<string>;
|
|
72
|
-
export declare function stripLanguageLabel(text: string, ...codes: string[]): string
|
|
72
|
+
export declare function stripLanguageLabel(text: string, ...codes: string[]): Promise<string>;
|
|
73
73
|
export interface TranslateArgs {
|
|
74
74
|
text: string;
|
|
75
75
|
to: string;
|
|
@@ -79,7 +79,7 @@ export interface TranslateError {
|
|
|
79
79
|
error: string;
|
|
80
80
|
}
|
|
81
81
|
export declare function parseTranslateArgs(args: Record<string, unknown>): TranslateArgs | TranslateError;
|
|
82
|
-
export declare function sourceLanguage(text: string, from?: string): string | TranslateError
|
|
82
|
+
export declare function sourceLanguage(text: string, from?: string): Promise<string | TranslateError>;
|
|
83
83
|
export interface TranslateToolOptions {
|
|
84
84
|
slm?: SlmTranslateFn;
|
|
85
85
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import ScopeLock from 'scope-lock';
|
|
2
|
-
import {
|
|
3
|
-
import { detectLanguage, UNDETERMINED } from '../../lib/capabilities/detect-language.js';
|
|
2
|
+
import { detectLanguage, languageName, UNDETERMINED } from '../../lib/capabilities/detect-language.js';
|
|
4
3
|
import { HarnessError } from '../../lib/errors.js';
|
|
5
4
|
import { createLoadStall } from '../../lib/helpers/load-stall.js';
|
|
6
5
|
import { AbortedError, raceAbort } from '../../lib/helpers/race-abort.js';
|
|
@@ -135,13 +134,13 @@ export function createTranslationRuntime({ loadSdk, loads = { track: (pending) =
|
|
|
135
134
|
}
|
|
136
135
|
};
|
|
137
136
|
}
|
|
138
|
-
export function stripLanguageLabel(text, ...codes) {
|
|
137
|
+
export async function stripLanguageLabel(text, ...codes) {
|
|
139
138
|
const at = text.indexOf(':');
|
|
140
139
|
if (at === -1) {
|
|
141
140
|
return text;
|
|
142
141
|
}
|
|
143
142
|
const head = text.slice(0, at).trim();
|
|
144
|
-
const labels = codes.map((code) => languageLabel(code) ??
|
|
143
|
+
const labels = await Promise.all(codes.map((code) => languageLabel(code) ?? languageName(code)));
|
|
145
144
|
return labels.includes(head) ? text.slice(at + 1).trim() : text;
|
|
146
145
|
}
|
|
147
146
|
export function parseTranslateArgs(args) {
|
|
@@ -156,10 +155,10 @@ export function parseTranslateArgs(args) {
|
|
|
156
155
|
const from = typeof args.from === 'string' ? args.from.trim() : undefined;
|
|
157
156
|
return { text, to, from };
|
|
158
157
|
}
|
|
159
|
-
export function sourceLanguage(text, from) {
|
|
158
|
+
export async function sourceLanguage(text, from) {
|
|
160
159
|
if (from)
|
|
161
160
|
return from;
|
|
162
|
-
const [{ code }] = detectLanguage({ text });
|
|
161
|
+
const [{ code }] = await detectLanguage({ text });
|
|
163
162
|
if (code === UNDETERMINED) {
|
|
164
163
|
return { error: NEEDS_SOURCE };
|
|
165
164
|
}
|
|
@@ -168,7 +167,7 @@ export function sourceLanguage(text, from) {
|
|
|
168
167
|
const NEEDS_SOURCE = 'could not detect the source language; pass `from` explicitly';
|
|
169
168
|
export function createTranslate(runtime, { slm } = {}) {
|
|
170
169
|
return async (request, signal) => {
|
|
171
|
-
const from = sourceLanguage(request.text, request.from);
|
|
170
|
+
const from = await sourceLanguage(request.text, request.from);
|
|
172
171
|
if (typeof from === 'object') {
|
|
173
172
|
return from;
|
|
174
173
|
}
|
|
@@ -192,7 +191,7 @@ export function createTranslate(runtime, { slm } = {}) {
|
|
|
192
191
|
}
|
|
193
192
|
const text = await slm(plan.model, { text: request.text, from: plan.from, to: plan.to }, signal);
|
|
194
193
|
return {
|
|
195
|
-
text: stripLanguageLabel(text, plan.from, plan.to),
|
|
194
|
+
text: await stripLanguageLabel(text, plan.from, plan.to),
|
|
196
195
|
from,
|
|
197
196
|
to: request.to,
|
|
198
197
|
engine: 'slm',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Hyperswarm from 'hyperswarm';
|
|
1
|
+
import type Hyperswarm from 'hyperswarm';
|
|
2
2
|
import type { TargetEvent } from '../../lib/agent/index.ts';
|
|
3
3
|
import type { HarnessPlugin, PluginSetup } from '../../lib/plugins/index.ts';
|
|
4
4
|
import { type Attachments, type Crew, type CrewOptions, type Outgoing, type Reply } from './crew.ts';
|
|
@@ -100,7 +100,7 @@ export declare class WalkieTalkie implements HarnessPlugin {
|
|
|
100
100
|
private _stopped;
|
|
101
101
|
constructor(options: WalkieTalkieOptions);
|
|
102
102
|
validate(): string | null;
|
|
103
|
-
setup(): PluginSetup
|
|
103
|
+
setup(): Promise<PluginSetup>;
|
|
104
104
|
agents(): AgentInfo[];
|
|
105
105
|
crew(options?: CrewOptions): Crew;
|
|
106
106
|
teammates(): string[];
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
-
import
|
|
3
|
-
import Hyperswarm from 'hyperswarm';
|
|
2
|
+
import { randomBytes } from 'crypto';
|
|
4
3
|
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
5
4
|
import { crew } from './crew.js';
|
|
6
5
|
import { openLine } from './wire.js';
|
|
6
|
+
PluginRegistry.requirePeers('walkie-talkie', {
|
|
7
|
+
'hypercore-crypto': () => import.meta.resolve('hypercore-crypto'),
|
|
8
|
+
hyperswarm: () => import.meta.resolve('hyperswarm')
|
|
9
|
+
});
|
|
7
10
|
const NAME = /^[\w.-]+$/;
|
|
8
11
|
const GRACE_MS = 5_000;
|
|
9
12
|
const NOBODY = { by: null, text: null };
|
|
@@ -46,14 +49,19 @@ export class WalkieTalkie {
|
|
|
46
49
|
? null
|
|
47
50
|
: 'the name and each agent name must be letters, digits, dot, dash or underscore';
|
|
48
51
|
}
|
|
49
|
-
setup() {
|
|
52
|
+
async setup() {
|
|
53
|
+
const [{ default: crypto }, { default: Swarm }] = await Promise.all([
|
|
54
|
+
import('hypercore-crypto'),
|
|
55
|
+
import('hyperswarm')
|
|
56
|
+
]);
|
|
50
57
|
const team = b4a.from(this._options.team, 'hex');
|
|
51
58
|
const topic = crypto.discoveryKey(team);
|
|
52
59
|
const lent = this._options.swarm;
|
|
53
|
-
const swarm = lent ?? new
|
|
60
|
+
const swarm = lent ?? new Swarm({ bootstrap: this._options.bootstrap });
|
|
54
61
|
const me = { name: this._options.name, agents: this._infos(), people: this._self.people };
|
|
55
62
|
const onConnection = (connection) => isConnection(connection) &&
|
|
56
63
|
openLine(connection, {
|
|
64
|
+
crypto,
|
|
57
65
|
team,
|
|
58
66
|
me,
|
|
59
67
|
onOpen: (line) => this._onOpen(line),
|
|
@@ -335,6 +343,6 @@ function errorText(error) {
|
|
|
335
343
|
return String(Reflect.get(Object(error), 'message') ?? error);
|
|
336
344
|
}
|
|
337
345
|
function randomId() {
|
|
338
|
-
return b4a.toHex(
|
|
346
|
+
return b4a.toHex(randomBytes(8));
|
|
339
347
|
}
|
|
340
348
|
function noop() { }
|
|
@@ -57,7 +57,12 @@ export interface Connection {
|
|
|
57
57
|
on(event: 'close' | 'error', listener: () => void): unknown;
|
|
58
58
|
destroy(): void;
|
|
59
59
|
}
|
|
60
|
+
export interface TeamCrypto {
|
|
61
|
+
hash(data: Buffer[]): Buffer;
|
|
62
|
+
discoveryKey(key: Buffer): Buffer;
|
|
63
|
+
}
|
|
60
64
|
export interface LineOptions {
|
|
65
|
+
crypto: TeamCrypto;
|
|
61
66
|
team: Buffer;
|
|
62
67
|
me: Pick<Line, 'name' | 'agents' | 'people'>;
|
|
63
68
|
onOpen(line: Line): void;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import { raw } from 'compact-encoding';
|
|
3
|
-
import crypto from 'hypercore-crypto';
|
|
4
3
|
import Protomux from 'protomux';
|
|
5
4
|
import { isRecord } from '../../lib/guards.js';
|
|
6
5
|
const PROTOCOL = 'qvac/walkie-talkie/1';
|
|
@@ -21,11 +20,11 @@ const EVENTS = {
|
|
|
21
20
|
error: 'error'
|
|
22
21
|
};
|
|
23
22
|
const USAGE = ['inputTokens', 'outputTokens', 'costUsd', 'turns'];
|
|
24
|
-
function proof(team, connection) {
|
|
23
|
+
function proof(crypto, team, connection) {
|
|
25
24
|
return b4a.toHex(crypto.hash([team, connection.handshakeHash]));
|
|
26
25
|
}
|
|
27
26
|
export function openLine(connection, options) {
|
|
28
|
-
const { team, me, onOpen, onFrame, onClose } = options;
|
|
27
|
+
const { crypto, team, me, onOpen, onFrame, onClose } = options;
|
|
29
28
|
let line = null;
|
|
30
29
|
const channel = Protomux.from(connection).createChannel({
|
|
31
30
|
protocol: PROTOCOL,
|
|
@@ -40,7 +39,9 @@ export function openLine(connection, options) {
|
|
|
40
39
|
if (line && message && message.type !== 'hello') {
|
|
41
40
|
onFrame(line, { message, bodies });
|
|
42
41
|
}
|
|
43
|
-
else if (!line &&
|
|
42
|
+
else if (!line &&
|
|
43
|
+
message?.type === 'hello' &&
|
|
44
|
+
message.proof === proof(crypto, team, connection)) {
|
|
44
45
|
const { name, agents, people } = message;
|
|
45
46
|
line = { name, agents, people, send, close: () => channel.close() };
|
|
46
47
|
onOpen(line);
|
|
@@ -56,7 +57,7 @@ export function openLine(connection, options) {
|
|
|
56
57
|
const send = (message, bodies = []) => out.send(pack({ head: message, bodies }));
|
|
57
58
|
connection.on('error', noop);
|
|
58
59
|
channel.open();
|
|
59
|
-
send({ type: 'hello', ...me, agents: [...me.agents], proof: proof(team, connection) });
|
|
60
|
+
send({ type: 'hello', ...me, agents: [...me.agents], proof: proof(crypto, team, connection) });
|
|
60
61
|
}
|
|
61
62
|
function pack({ head, bodies }) {
|
|
62
63
|
const parts = [b4a.from(JSON.stringify(head)), ...bodies];
|
|
@@ -53,6 +53,7 @@ export function registerHarnessTypes(ns) {
|
|
|
53
53
|
{ name: 'role', type: '@harness/message-role', required: true },
|
|
54
54
|
{ name: 'content', type: 'string', required: true },
|
|
55
55
|
{ name: 'attachments', type: '@harness/message-attachment', array: true },
|
|
56
|
+
{ name: 'sentAt', type: 'uint' },
|
|
56
57
|
{ name: 'toolCalls', type: 'json' },
|
|
57
58
|
{ name: 'toolCallId', type: 'string' },
|
|
58
59
|
{ name: 'name', type: 'string' },
|
|
@@ -90,7 +91,12 @@ export function registerHarnessTypes(ns) {
|
|
|
90
91
|
'run-log-result',
|
|
91
92
|
'pause',
|
|
92
93
|
'steer',
|
|
93
|
-
'follow-up'
|
|
94
|
+
'follow-up',
|
|
95
|
+
'model-round-ask',
|
|
96
|
+
'model-round-chunk',
|
|
97
|
+
'model-round-retake',
|
|
98
|
+
'model-round-result',
|
|
99
|
+
'round-cut'
|
|
94
100
|
],
|
|
95
101
|
strings: true
|
|
96
102
|
});
|
|
@@ -170,7 +176,11 @@ export function registerHarnessTypes(ns) {
|
|
|
170
176
|
'goal',
|
|
171
177
|
'fold',
|
|
172
178
|
'input-rejected',
|
|
173
|
-
'context'
|
|
179
|
+
'context',
|
|
180
|
+
'model-round-ask',
|
|
181
|
+
'model-round-cancel',
|
|
182
|
+
'model-round-retake',
|
|
183
|
+
'model-round-result'
|
|
174
184
|
],
|
|
175
185
|
strings: true
|
|
176
186
|
});
|