@qvac/harness 1.0.0-rc.17 → 1.0.0-rc.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +59 -6
- package/dist-lib/index.d.ts +3 -1
- package/dist-lib/index.js +30 -0
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +3 -2
- package/dist-lib/lib/capabilities/completion-engine/loop.js +4 -1
- package/dist-lib/lib/connect.d.ts +2 -0
- package/dist-lib/lib/connect.js +57 -0
- package/dist-lib/lib/contract/completion.d.ts +2 -0
- package/dist-lib/lib/contract/index.d.ts +1 -0
- package/dist-lib/lib/contract/media.d.ts +51 -0
- package/dist-lib/lib/contract/media.js +1 -0
- package/dist-lib/lib/contract/models.d.ts +2 -0
- package/dist-lib/lib/contract-types.d.ts +3 -1
- package/dist-lib/lib/errors.d.ts +8 -0
- package/dist-lib/lib/errors.js +9 -1
- package/dist-lib/lib/machine/completion/actions/completion.d.ts +1 -1
- package/dist-lib/lib/machine/completion/actions/completion.js +3 -7
- package/dist-lib/lib/machine/completion/implementations.d.ts +3 -3
- package/dist-lib/lib/machine/completion/implementations.js +4 -4
- package/dist-lib/lib/machine/completion/machine.d.ts +3 -3
- package/dist-lib/lib/machine/completion/machine.js +3 -3
- package/dist-lib/lib/machine/index.d.ts +3 -3
- package/dist-lib/lib/media-host.d.ts +12 -0
- package/dist-lib/lib/media-host.js +52 -0
- package/dist-lib/lib/media-port.d.ts +20 -0
- package/dist-lib/lib/media-port.js +77 -0
- package/dist-lib/lib/media-wire.d.ts +8 -0
- package/dist-lib/lib/media-wire.js +96 -0
- package/dist-lib/lib/office/engine/xlsx/sheet.js +10 -4
- package/dist-lib/lib/plugins/registry.d.ts +3 -0
- package/dist-lib/lib/serve.js +37 -1
- package/dist-lib/lib/sidecar/index.d.ts +1 -1
- package/dist-lib/lib/sidecar/index.js +3 -5
- package/dist-lib/lib/skills-host/index.js +6 -7
- package/dist-lib/lib/tools/index.d.ts +1 -0
- package/dist-lib/lib/tools/index.js +1 -1
- package/dist-lib/lib/tools/pdf/pages.js +6 -3
- package/dist-lib/lib/tools/pdf/recognize.js +2 -1
- package/dist-lib/lib/tools/skills/bundled-dir.d.ts +5 -1
- package/dist-lib/lib/tools/skills/bundled-dir.js +23 -20
- package/dist-lib/lib/tools/skills/catalog.d.ts +1 -1
- package/dist-lib/lib/tools/skills/catalog.js +1 -1
- package/dist-lib/lib/tools/skills/overlay-crud.d.ts +3 -3
- package/dist-lib/lib/tools/skills/overlay-crud.js +4 -4
- package/dist-lib/plugins/image/edit-image.js +3 -9
- package/dist-lib/plugins/image/generate-image.d.ts +14 -2
- package/dist-lib/plugins/image/generate-image.js +94 -8
- package/dist-lib/plugins/image/index.d.ts +2 -1
- package/dist-lib/plugins/image/index.js +8 -3
- package/dist-lib/plugins/music/generate-music.d.ts +18 -2
- package/dist-lib/plugins/music/generate-music.js +98 -16
- package/dist-lib/plugins/music/index.d.ts +2 -1
- package/dist-lib/plugins/music/index.js +6 -2
- package/dist-lib/plugins/python/bare-floor.js +1 -1
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/walkie-talkie/index.d.ts +2 -0
- package/dist-lib/plugins/walkie-talkie/index.js +6 -1
- package/dist-lib/schema/generate.js +8 -1
- package/dist-lib/schema/harness.js +9 -2
- package/dist-lib/spec/hrpc/messages.js +46 -4
- package/dist-lib/spec/hyperschema/index.js +46 -4
- package/dist-lib/spec/hyperschema/schema.json +28 -0
- package/dist-lib/spec/hyperschema/types.d.ts +2 -2
- package/package.json +8 -9
|
@@ -353,12 +353,12 @@ const createCompletionMachineImplementation = (context, now = noClock) => setup(
|
|
|
353
353
|
input: withParent,
|
|
354
354
|
onDone: [
|
|
355
355
|
{
|
|
356
|
-
guard: and(['
|
|
356
|
+
guard: and(['hasFollowUp', 'hasRoundsLeft', not('timeUp')]),
|
|
357
357
|
target: 'retrieving',
|
|
358
358
|
actions: [
|
|
359
359
|
{ type: 'answerCompletion', params: ({ event }) => event.output },
|
|
360
|
-
'
|
|
361
|
-
'
|
|
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: "
|
|
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: "
|
|
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: "
|
|
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
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { AbortController } from 'bare-abort-controller';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { mediaRequestFrom, mediaResultWire } from './media-wire.js';
|
|
4
|
+
import { pushQueue } from './queue.js';
|
|
5
|
+
import { roundFailureWire } from './wire.js';
|
|
6
|
+
export class MediaHost {
|
|
7
|
+
_port;
|
|
8
|
+
_out = pushQueue();
|
|
9
|
+
_rounds = new Map();
|
|
10
|
+
constructor(port, send) {
|
|
11
|
+
this._port = port;
|
|
12
|
+
void this._drain(send);
|
|
13
|
+
}
|
|
14
|
+
ask(callId, payload) {
|
|
15
|
+
const controller = new AbortController();
|
|
16
|
+
this._rounds.set(callId, controller);
|
|
17
|
+
const tick = (payload) => {
|
|
18
|
+
if (this._rounds.has(callId)) {
|
|
19
|
+
void this._out.push({ type: 'media-round-tick', callId, payload });
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
void mediaRequestFrom(payload)
|
|
23
|
+
.then((request) => this._port(request, { signal: controller.signal, tick }))
|
|
24
|
+
.then(mediaResultWire)
|
|
25
|
+
.then((wire) => this._settle(callId, wire, wire.path), (err) => this._settle(callId, roundFailureWire(err)));
|
|
26
|
+
}
|
|
27
|
+
cancel(callId) {
|
|
28
|
+
this._rounds.get(callId)?.abort(undefined);
|
|
29
|
+
this._rounds.delete(callId);
|
|
30
|
+
}
|
|
31
|
+
close() {
|
|
32
|
+
for (const callId of [...this._rounds.keys()]) {
|
|
33
|
+
this.cancel(callId);
|
|
34
|
+
}
|
|
35
|
+
this._out.end();
|
|
36
|
+
}
|
|
37
|
+
_settle(callId, frame, staged) {
|
|
38
|
+
if (this._rounds.delete(callId)) {
|
|
39
|
+
void this._out.push({ type: 'media-round-result', callId, ...frame });
|
|
40
|
+
}
|
|
41
|
+
else if (staged) {
|
|
42
|
+
void fs.promises.unlink(staged).catch(noop);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async _drain(send) {
|
|
46
|
+
for await (const frame of this._out) {
|
|
47
|
+
send(frame);
|
|
48
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function noop() { }
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MediaRoundPort } from './contract/index.ts';
|
|
2
|
+
import type { RoundFrame } from './round-port.ts';
|
|
3
|
+
import type { WireEvent } from './wire.ts';
|
|
4
|
+
interface MediaFrame extends RoundFrame {
|
|
5
|
+
path?: string | null;
|
|
6
|
+
}
|
|
7
|
+
export declare class MediaPort {
|
|
8
|
+
private readonly _push;
|
|
9
|
+
private readonly _asked;
|
|
10
|
+
private _calls;
|
|
11
|
+
private _closed;
|
|
12
|
+
constructor(push: (event: WireEvent) => unknown);
|
|
13
|
+
port: MediaRoundPort;
|
|
14
|
+
frame(frame: MediaFrame): boolean;
|
|
15
|
+
close(): void;
|
|
16
|
+
private _settle;
|
|
17
|
+
private _assertLive;
|
|
18
|
+
private _take;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { HarnessError } from './errors.js';
|
|
2
|
+
import { AbortedError } from './helpers/engine-error.js';
|
|
3
|
+
import { discardRequestWire, mediaRequestWire, mediaResultFrom, mediaTickFrom } from './media-wire.js';
|
|
4
|
+
export class MediaPort {
|
|
5
|
+
_push;
|
|
6
|
+
_asked = new Map();
|
|
7
|
+
_calls = 0;
|
|
8
|
+
_closed = false;
|
|
9
|
+
constructor(push) {
|
|
10
|
+
this._push = push;
|
|
11
|
+
}
|
|
12
|
+
port = async (request, io) => {
|
|
13
|
+
this._assertLive(io);
|
|
14
|
+
const payload = await mediaRequestWire(request);
|
|
15
|
+
try {
|
|
16
|
+
this._assertLive(io);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
await discardRequestWire(payload);
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
const callId = String(this._calls++);
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
const cancel = () => {
|
|
25
|
+
if (!this._take(callId))
|
|
26
|
+
return;
|
|
27
|
+
this._push({ type: 'media-round-cancel', callId });
|
|
28
|
+
reject(new AbortedError());
|
|
29
|
+
};
|
|
30
|
+
this._asked.set(callId, { io, cancel, resolve, reject });
|
|
31
|
+
io.signal.addEventListener('abort', cancel, { once: true });
|
|
32
|
+
this._push({ type: 'media-round-ask', callId, payload });
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
frame(frame) {
|
|
36
|
+
switch (frame.type) {
|
|
37
|
+
case 'media-round-tick':
|
|
38
|
+
this._asked.get(frame.callId ?? '')?.io.tick(mediaTickFrom(frame.payload));
|
|
39
|
+
return true;
|
|
40
|
+
case 'media-round-result':
|
|
41
|
+
void this._settle(frame);
|
|
42
|
+
return true;
|
|
43
|
+
default:
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
close() {
|
|
48
|
+
this._closed = true;
|
|
49
|
+
for (const callId of [...this._asked.keys()]) {
|
|
50
|
+
this._take(callId)?.reject(new HarnessError('CLIENT_GONE'));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async _settle(frame) {
|
|
54
|
+
const asked = this._take(frame.callId ?? '');
|
|
55
|
+
try {
|
|
56
|
+
const result = await mediaResultFrom(frame);
|
|
57
|
+
asked?.resolve(result);
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
asked?.reject(err);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
_assertLive(io) {
|
|
64
|
+
if (this._closed) {
|
|
65
|
+
throw new HarnessError('CLIENT_GONE');
|
|
66
|
+
}
|
|
67
|
+
if (io.signal.aborted) {
|
|
68
|
+
throw new AbortedError();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
_take(callId) {
|
|
72
|
+
const asked = this._asked.get(callId);
|
|
73
|
+
this._asked.delete(callId);
|
|
74
|
+
asked?.io.signal.removeEventListener('abort', asked.cancel);
|
|
75
|
+
return asked;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MediaRoundRequest, MediaRoundResult, MediaTick } from './contract/index.ts';
|
|
2
|
+
import { type WireEvent } from './wire.ts';
|
|
3
|
+
export declare function mediaRequestWire(request: MediaRoundRequest): Promise<Record<string, unknown>>;
|
|
4
|
+
export declare function discardRequestWire(payload: Record<string, unknown>): Promise<void>;
|
|
5
|
+
export declare function mediaRequestFrom(payload: unknown): Promise<MediaRoundRequest>;
|
|
6
|
+
export declare function mediaResultWire(result: MediaRoundResult): Promise<Pick<WireEvent, 'path' | 'result'>>;
|
|
7
|
+
export declare function mediaResultFrom(wire: Pick<WireEvent, 'path' | 'result' | 'message' | 'payload'>): Promise<MediaRoundResult>;
|
|
8
|
+
export declare function mediaTickFrom(payload: unknown): MediaTick;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { isRecord } from './guards.js';
|
|
3
|
+
import { stageFile } from './staging.js';
|
|
4
|
+
import { roundFailureFrom } from './wire.js';
|
|
5
|
+
const KINDS = ['image', 'music'];
|
|
6
|
+
export async function mediaRequestWire(request) {
|
|
7
|
+
const { images, ...json } = request;
|
|
8
|
+
const imagePaths = images
|
|
9
|
+
? await Promise.all(images.map((bytes) => stageFile('media-source', bytes)))
|
|
10
|
+
: undefined;
|
|
11
|
+
return { ...json, imagePaths };
|
|
12
|
+
}
|
|
13
|
+
export async function discardRequestWire(payload) {
|
|
14
|
+
const paths = Array.isArray(payload.imagePaths) ? payload.imagePaths.map(String) : [];
|
|
15
|
+
await Promise.all(paths.map((file) => fs.promises.unlink(file).catch(noop)));
|
|
16
|
+
}
|
|
17
|
+
export async function mediaRequestFrom(payload) {
|
|
18
|
+
if (!isRecord(payload) || !KINDS.some((kind) => kind === payload.kind)) {
|
|
19
|
+
throw new TypeError('invalid media round request');
|
|
20
|
+
}
|
|
21
|
+
const paths = Array.isArray(payload.imagePaths) ? payload.imagePaths.map(String) : [];
|
|
22
|
+
const images = await Promise.all(paths.map(readStaged));
|
|
23
|
+
return {
|
|
24
|
+
kind: payload.kind === 'music' ? 'music' : 'image',
|
|
25
|
+
runId: String(payload.runId ?? ''),
|
|
26
|
+
modelChoice: typeof payload.modelChoice === 'string' ? payload.modelChoice : undefined,
|
|
27
|
+
params: isRecord(payload.params) ? payload.params : {},
|
|
28
|
+
images: paths.length ? images : undefined
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export async function mediaResultWire(result) {
|
|
32
|
+
if ('error' in result) {
|
|
33
|
+
return { result: { error: result.error, code: result.code } };
|
|
34
|
+
}
|
|
35
|
+
const { bytes, ...json } = result;
|
|
36
|
+
return { path: await stageFile('media-output', bytes), result: json };
|
|
37
|
+
}
|
|
38
|
+
export async function mediaResultFrom(wire) {
|
|
39
|
+
const result = isRecord(wire.result) ? wire.result : {};
|
|
40
|
+
if (wire.path) {
|
|
41
|
+
return outputFrom(result, await readStaged(wire.path));
|
|
42
|
+
}
|
|
43
|
+
if (typeof result.error === 'string') {
|
|
44
|
+
return { error: result.error, code: typeof result.code === 'string' ? result.code : undefined };
|
|
45
|
+
}
|
|
46
|
+
throw roundFailureFrom(wire);
|
|
47
|
+
}
|
|
48
|
+
function outputFrom(result, bytes) {
|
|
49
|
+
if (result.kind === 'image') {
|
|
50
|
+
return { kind: 'image', bytes };
|
|
51
|
+
}
|
|
52
|
+
const format = isRecord(result.format) ? result.format : {};
|
|
53
|
+
const sampleRate = positive(format.sampleRate);
|
|
54
|
+
const channels = positive(format.channels);
|
|
55
|
+
const bitsPerSample = positive(format.bitsPerSample);
|
|
56
|
+
if (result.kind !== 'music' || !sampleRate || !channels || !bitsPerSample) {
|
|
57
|
+
throw new TypeError('invalid media round output');
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
kind: 'music',
|
|
61
|
+
bytes,
|
|
62
|
+
format: { sampleRate, channels, bitsPerSample },
|
|
63
|
+
gpuRequested: result.gpuRequested === true,
|
|
64
|
+
stats: isRecord(result.stats) ? statsFrom(result.stats) : undefined
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function statsFrom(stats) {
|
|
68
|
+
const number = (value) => (typeof value === 'number' ? value : undefined);
|
|
69
|
+
return {
|
|
70
|
+
audioDurationMs: number(stats.audioDurationMs),
|
|
71
|
+
totalTimeMs: number(stats.totalTimeMs),
|
|
72
|
+
realTimeFactor: number(stats.realTimeFactor),
|
|
73
|
+
backendDevice: number(stats.backendDevice),
|
|
74
|
+
backendId: number(stats.backendId)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function positive(value) {
|
|
78
|
+
return typeof value === 'number' && value > 0 ? value : undefined;
|
|
79
|
+
}
|
|
80
|
+
export function mediaTickFrom(payload) {
|
|
81
|
+
const tick = isRecord(payload) ? payload : {};
|
|
82
|
+
return {
|
|
83
|
+
step: Number(tick.step ?? 0),
|
|
84
|
+
total: Number(tick.total ?? 0),
|
|
85
|
+
stage: typeof tick.stage === 'string' ? tick.stage : undefined
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async function readStaged(file) {
|
|
89
|
+
try {
|
|
90
|
+
return await fs.promises.readFile(file);
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
void fs.promises.unlink(file).catch(noop);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function noop() { }
|
|
@@ -93,7 +93,7 @@ export function isoToSerial(value, date1904) {
|
|
|
93
93
|
return { serial, time: match[4] !== undefined };
|
|
94
94
|
}
|
|
95
95
|
function formulaError(input, why) {
|
|
96
|
-
return new DocsError('INVALID_FORMULA', `${JSON.stringify(input)} is not a formula (${why}); to store it as text
|
|
96
|
+
return new DocsError('INVALID_FORMULA', `${JSON.stringify(input)} is not a formula (${why}); to store it as text write ${JSON.stringify(`'${input}`)}`);
|
|
97
97
|
}
|
|
98
98
|
function parenthesisProblem(body) {
|
|
99
99
|
let depth = 0;
|
|
@@ -140,15 +140,18 @@ function isCellValue(value) {
|
|
|
140
140
|
typeof value === 'boolean' ||
|
|
141
141
|
(typeof value === 'number' && Number.isFinite(value)));
|
|
142
142
|
}
|
|
143
|
-
function normalizeText(input) {
|
|
143
|
+
function normalizeText(input, style = {}) {
|
|
144
144
|
if (input.length > 32767) {
|
|
145
145
|
throw new DocsError('INVALID_VALUE', 'a cell holds at most 32767 characters');
|
|
146
146
|
}
|
|
147
|
+
if (input.startsWith("'=")) {
|
|
148
|
+
return { content: true, value: input.slice(1), style };
|
|
149
|
+
}
|
|
147
150
|
if (input.length > 1 && input.startsWith('=')) {
|
|
148
151
|
checkFormula(input);
|
|
149
|
-
return { content: true, formula: input, style
|
|
152
|
+
return { content: true, formula: input, style };
|
|
150
153
|
}
|
|
151
|
-
return { content: true, value: input, style
|
|
154
|
+
return { content: true, value: input, style };
|
|
152
155
|
}
|
|
153
156
|
function normalizeObject(input) {
|
|
154
157
|
const { value, formula, date, ...style } = input;
|
|
@@ -175,6 +178,9 @@ function normalizeObject(input) {
|
|
|
175
178
|
if (!isCellValue(value)) {
|
|
176
179
|
throw new DocsError('INVALID_VALUE', 'value must be a string, a finite number, a boolean or null');
|
|
177
180
|
}
|
|
181
|
+
if (typeof value === 'string') {
|
|
182
|
+
return normalizeText(value, style);
|
|
183
|
+
}
|
|
178
184
|
return { content: true, value, style };
|
|
179
185
|
}
|
|
180
186
|
function normalize(input) {
|
|
@@ -4,6 +4,7 @@ import type { OcrService } from '../contract/ocr.ts';
|
|
|
4
4
|
import type { SandboxService } from '../contract/sandbox.ts';
|
|
5
5
|
import type { EgressProxyService } from '../contract/egress-proxy.ts';
|
|
6
6
|
import type { EmbedHost, ModelHost } from '../contract/models.ts';
|
|
7
|
+
import type { MediaRoundServer } from '../contract/media.ts';
|
|
7
8
|
import type { SpeechService } from '../contract/speech.ts';
|
|
8
9
|
import type { HarnessHook, SkillReadiness } from '../contract/index.ts';
|
|
9
10
|
import type { ExecLanguage, ExecRoute, ExecShell } from '../contract/exec.ts';
|
|
@@ -19,6 +20,8 @@ declare module './context.ts' {
|
|
|
19
20
|
ocr: OcrService;
|
|
20
21
|
sandbox: SandboxService;
|
|
21
22
|
'egress-proxy': EgressProxyService;
|
|
23
|
+
'image-rounds': MediaRoundServer;
|
|
24
|
+
'music-rounds': MediaRoundServer;
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
export interface PluginContext {
|
package/dist-lib/lib/serve.js
CHANGED
|
@@ -2,6 +2,7 @@ import b4a from 'b4a';
|
|
|
2
2
|
import { AbortController } from 'bare-abort-controller';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import { HarnessError } from './errors.js';
|
|
5
|
+
import { AbortedError } from './helpers/engine-error.js';
|
|
5
6
|
import { settleOnClose } from './rpc-session.js';
|
|
6
7
|
import { pipeline, Readable } from 'streamx';
|
|
7
8
|
import { bindApi } from '../spec/bind.js';
|
|
@@ -15,6 +16,8 @@ import { RunLog } from './run-log/index.js';
|
|
|
15
16
|
import { errorMessage, isRecord } from './guards.js';
|
|
16
17
|
import { HarnessLog } from './log.js';
|
|
17
18
|
import { pushQueue } from './queue.js';
|
|
19
|
+
import { MediaPort } from './media-port.js';
|
|
20
|
+
import { mediaRequestFrom, mediaResultWire } from './media-wire.js';
|
|
18
21
|
import { RoundPort } from './round-port.js';
|
|
19
22
|
import { TextCoalescer } from './helpers/text-coalescer.js';
|
|
20
23
|
import { prepareOpenclCache } from './models/opencl-cache.js';
|
|
@@ -185,6 +188,9 @@ function startPayloadFrom(value) {
|
|
|
185
188
|
if (value.showImage === true) {
|
|
186
189
|
payload.showImage = true;
|
|
187
190
|
}
|
|
191
|
+
if (value.mediaRound === true) {
|
|
192
|
+
payload.mediaRound = true;
|
|
193
|
+
}
|
|
188
194
|
if (value.runLog === null) {
|
|
189
195
|
payload.runLog = null;
|
|
190
196
|
}
|
|
@@ -663,6 +669,7 @@ function completion(harness) {
|
|
|
663
669
|
const input = pushQueue();
|
|
664
670
|
const controller = new AbortController();
|
|
665
671
|
const rounds = new RoundPort((event) => events.push(event));
|
|
672
|
+
const media = new MediaPort((event) => events.push(event));
|
|
666
673
|
let calls = 0;
|
|
667
674
|
let started = false;
|
|
668
675
|
let clientGone = false;
|
|
@@ -702,6 +709,7 @@ function completion(harness) {
|
|
|
702
709
|
}
|
|
703
710
|
pendingRunLog.clear();
|
|
704
711
|
rounds.close();
|
|
712
|
+
media.close();
|
|
705
713
|
input.end();
|
|
706
714
|
events.end();
|
|
707
715
|
};
|
|
@@ -709,7 +717,12 @@ function completion(harness) {
|
|
|
709
717
|
duplex.on('end', gone);
|
|
710
718
|
duplex.readStream?.on('close', gone);
|
|
711
719
|
duplex.on('data', (frame) => {
|
|
712
|
-
if (rounds.frame(frame)) {
|
|
720
|
+
if (rounds.frame(frame) || media.frame(frame)) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
if (frame.type === 'media-round-ask' && !started) {
|
|
724
|
+
started = true;
|
|
725
|
+
void serveMedia(harness, frame.payload, { signal: controller.signal, events });
|
|
713
726
|
return;
|
|
714
727
|
}
|
|
715
728
|
if (frame.type === 'model-round-ask' && !started) {
|
|
@@ -912,6 +925,7 @@ function completion(harness) {
|
|
|
912
925
|
typedText: startPayload.typedText,
|
|
913
926
|
replaysContext: startPayload.replaysContext,
|
|
914
927
|
modelRound: startPayload.modelRound ? rounds.port : undefined,
|
|
928
|
+
mediaRound: startPayload.mediaRound ? media.port : undefined,
|
|
915
929
|
roundCut: startPayload.roundCut ? rounds.roundCut : undefined,
|
|
916
930
|
knowledge: startPayload.knowledge,
|
|
917
931
|
planMode: startPayload.planMode,
|
|
@@ -1133,6 +1147,28 @@ function completion(harness) {
|
|
|
1133
1147
|
HarnessLog.info('wire handed off');
|
|
1134
1148
|
};
|
|
1135
1149
|
}
|
|
1150
|
+
async function serveMedia(harness, payload, { signal, events }) {
|
|
1151
|
+
let settled;
|
|
1152
|
+
try {
|
|
1153
|
+
if (!harness.serveMediaRound) {
|
|
1154
|
+
throw new HarnessError('CAPABILITY_UNSUPPORTED', ['serveMediaRound']);
|
|
1155
|
+
}
|
|
1156
|
+
const result = await harness.serveMediaRound(await mediaRequestFrom(payload), {
|
|
1157
|
+
signal,
|
|
1158
|
+
tick: (tick) => void events.push({ type: 'media-round-tick', payload: tick })
|
|
1159
|
+
});
|
|
1160
|
+
if (signal.aborted) {
|
|
1161
|
+
throw new AbortedError();
|
|
1162
|
+
}
|
|
1163
|
+
settled = { type: 'media-round-result', ...(await mediaResultWire(result)) };
|
|
1164
|
+
}
|
|
1165
|
+
catch (err) {
|
|
1166
|
+
settled = { type: 'media-round-result', ...roundFailureWire(err) };
|
|
1167
|
+
}
|
|
1168
|
+
await events.push(settled);
|
|
1169
|
+
await events.push({ type: 'done' });
|
|
1170
|
+
events.end();
|
|
1171
|
+
}
|
|
1136
1172
|
async function serveRound(harness, request, { signal, events }) {
|
|
1137
1173
|
let sent = Promise.resolve();
|
|
1138
1174
|
const queue = (step) => {
|
|
@@ -11,7 +11,7 @@ import { type ImageClamps, type ImageModelSet, type MusicClamps } from '../model
|
|
|
11
11
|
export interface SidecarContext {
|
|
12
12
|
pluginOptions: HarnessPluginOptions;
|
|
13
13
|
sdkStorage: SdkStorage;
|
|
14
|
-
skillsDir: string;
|
|
14
|
+
skillsDir: string | undefined;
|
|
15
15
|
skillCatalog: SkillCatalogEntry[] | undefined;
|
|
16
16
|
credentialStore: CredentialStoreFn | undefined;
|
|
17
17
|
imageModel: string | ImageModelSet | undefined;
|
|
@@ -60,16 +60,14 @@ export class HarnessSidecar {
|
|
|
60
60
|
HarnessLog.setSink((line, level) => log[level](SCOPE, line));
|
|
61
61
|
captureConsole(log);
|
|
62
62
|
await alignSdkConsoleWithHost(hostWantsLogs);
|
|
63
|
-
const skillsDir = argv[2] ||
|
|
63
|
+
const skillsDir = argv[2] || undefined;
|
|
64
64
|
if (argv[11]) {
|
|
65
65
|
process.env.QVAC_PYTHON_WHEELS_DIR = argv[11];
|
|
66
66
|
}
|
|
67
67
|
configureSdkStorage(sdkStorage);
|
|
68
68
|
process.env.QVAC_PYODIDE_CACHE_DIR = `${sdkStorage.home}/pyodide-cache`;
|
|
69
|
-
const skillCatalog =
|
|
70
|
-
const credentialStore =
|
|
71
|
-
? (key, ctx) => harness?.resolveCredential(key, ctx) ?? null
|
|
72
|
-
: undefined;
|
|
69
|
+
const skillCatalog = await loadSkillCatalog(skillsDir ?? null);
|
|
70
|
+
const credentialStore = (key, ctx) => harness?.resolveCredential(key, ctx) ?? null;
|
|
73
71
|
const tools = Tools.product({
|
|
74
72
|
sdkHome: sdkStorage.home,
|
|
75
73
|
skillsDir,
|
|
@@ -4,7 +4,6 @@ import { errorMessage } from '../guards.js';
|
|
|
4
4
|
import { HarnessLog } from '../log.js';
|
|
5
5
|
import { modelNameToCapabilityProfile } from '../models/model-catalog.js';
|
|
6
6
|
import { probeBinVersions } from '../tools/skills/bin-check.js';
|
|
7
|
-
import { ensureBundledSkillsDir } from '../tools/skills/bundled-dir.js';
|
|
8
7
|
import { availableSkills, detectPlatform, loadSkillCatalog, resolveSkillStatuses, skillSupportsPlatform, versionProbeSkills } from '../tools/skills/catalog.js';
|
|
9
8
|
import { resetCredentialHealth } from '../tools/skills/credential-health.js';
|
|
10
9
|
import { ensureSkillsOverlayDir } from '../tools/skills/overlay-dir.js';
|
|
@@ -98,10 +97,10 @@ export class SkillsHost {
|
|
|
98
97
|
return this._allSkills.find((entry) => entry.name === skill)?.env;
|
|
99
98
|
}
|
|
100
99
|
async listManagedSkills() {
|
|
101
|
-
return listManagedSkills(
|
|
100
|
+
return listManagedSkills(this._baseDir(), await ensureSkillsOverlayDir());
|
|
102
101
|
}
|
|
103
102
|
async readSkillFile(name) {
|
|
104
|
-
return readSkillFile(
|
|
103
|
+
return readSkillFile(this._baseDir(), await ensureSkillsOverlayDir(), name);
|
|
105
104
|
}
|
|
106
105
|
async writeSkillFile(name, content) {
|
|
107
106
|
const overlay = await this._overlayDir();
|
|
@@ -111,7 +110,7 @@ export class SkillsHost {
|
|
|
111
110
|
}
|
|
112
111
|
async copyBaseForEdit(name) {
|
|
113
112
|
const overlay = await this._overlayDir();
|
|
114
|
-
const result = await copyBaseForEdit(
|
|
113
|
+
const result = await copyBaseForEdit(this._baseDir(), overlay, name);
|
|
115
114
|
if (result.copied) {
|
|
116
115
|
await this._reload();
|
|
117
116
|
}
|
|
@@ -186,8 +185,8 @@ export class SkillsHost {
|
|
|
186
185
|
_installedTools() {
|
|
187
186
|
return new Set(this._tools().map((tool) => tool.name));
|
|
188
187
|
}
|
|
189
|
-
|
|
190
|
-
return this._skillsDir ??
|
|
188
|
+
_baseDir() {
|
|
189
|
+
return this._skillsDir ?? null;
|
|
191
190
|
}
|
|
192
191
|
async _overlayDir() {
|
|
193
192
|
const overlay = await ensureSkillsOverlayDir();
|
|
@@ -197,7 +196,7 @@ export class SkillsHost {
|
|
|
197
196
|
return overlay;
|
|
198
197
|
}
|
|
199
198
|
async _reload() {
|
|
200
|
-
this._allSkills = await loadSkillCatalog(
|
|
199
|
+
this._allSkills = await loadSkillCatalog(this._baseDir(), { platform: null });
|
|
201
200
|
this._filter();
|
|
202
201
|
}
|
|
203
202
|
_filter() {
|
|
@@ -6,6 +6,7 @@ import type { CredentialStoreFn } from './skills/auth-resolver.ts';
|
|
|
6
6
|
import { ensureBundledSkillsDir } from './skills/bundled-dir.ts';
|
|
7
7
|
import type { SkillCatalogEntry } from './skills/catalog.ts';
|
|
8
8
|
export type { ExecInput } from './attachments/staging.ts';
|
|
9
|
+
export type { SkillsBundle } from './skills/bundled-dir.ts';
|
|
9
10
|
export interface ProductToolsOptions {
|
|
10
11
|
readonly sdkHome: string;
|
|
11
12
|
readonly skillsDir?: string | undefined;
|
|
@@ -16,11 +16,14 @@ export async function pdfPages(bytes, { ocr, signal } = {}) {
|
|
|
16
16
|
const recognized = ocr
|
|
17
17
|
? (await recognizePages({ doc, bytes }, { ocr, signal })).pages
|
|
18
18
|
: undefined;
|
|
19
|
-
|
|
19
|
+
const pages = [];
|
|
20
|
+
for await (const { page, text } of doc.textPagesAsync()) {
|
|
21
|
+
signal?.throwIfAborted();
|
|
20
22
|
const read = recognized?.get(page) ?? cleanText(text);
|
|
21
23
|
const unread = !read && !recognized?.has(page) && doc.pageFlags(page).hasImage;
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
+
pages.push({ page: page + 1, text: read, unread });
|
|
25
|
+
}
|
|
26
|
+
return pages;
|
|
24
27
|
}
|
|
25
28
|
finally {
|
|
26
29
|
doc.close();
|
|
@@ -9,7 +9,8 @@ export async function recognizePages({ doc, bytes }, { ocr, signal, budget }) {
|
|
|
9
9
|
const pages = new Map();
|
|
10
10
|
let kept = null;
|
|
11
11
|
let failed = false;
|
|
12
|
-
for (const { page, text } of doc.
|
|
12
|
+
for await (const { page, text } of doc.textPagesAsync()) {
|
|
13
|
+
signal?.throwIfAborted();
|
|
13
14
|
if (budget && budget.chars <= 0) {
|
|
14
15
|
return { pages, unreadFrom: page };
|
|
15
16
|
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface SkillsBundle {
|
|
2
|
+
readonly skills: Readonly<Record<string, string>>;
|
|
3
|
+
readonly hash: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function ensureBundledSkillsDir(bundle: SkillsBundle): Promise<string>;
|
|
2
6
|
export declare function randomSuffix(): string;
|