@qvac/harness 1.0.1 → 1.1.0
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 +137 -6
- package/README.md +28 -0
- package/dist-lib/index.d.ts +32 -304
- package/dist-lib/index.js +16 -1147
- package/dist-lib/lib/agent/child-run.d.ts +29 -0
- package/dist-lib/lib/agent/child-run.js +32 -0
- package/dist-lib/lib/agent/delegate.d.ts +3 -19
- package/dist-lib/lib/agent/delegate.js +8 -31
- package/dist-lib/lib/agent/index.d.ts +4 -0
- package/dist-lib/lib/agent/index.js +3 -0
- package/dist-lib/lib/agent/read-parts.d.ts +45 -0
- package/dist-lib/lib/agent/read-parts.js +60 -0
- package/dist-lib/lib/capabilities/completion-engine/driver.js +6 -2
- package/dist-lib/lib/capabilities/completion-engine/engine.d.ts +4 -0
- package/dist-lib/lib/capabilities/completion-engine/engine.js +27 -18
- package/dist-lib/lib/capabilities/completion-engine/round.js +5 -4
- package/dist-lib/lib/client/index.js +1 -3
- package/dist-lib/lib/connect/decode.d.ts +3 -2
- package/dist-lib/lib/connect/decode.js +14 -0
- package/dist-lib/lib/connect.d.ts +1 -0
- package/dist-lib/lib/connect.js +11 -5
- package/dist-lib/lib/context-window.d.ts +2 -0
- package/dist-lib/lib/context-window.js +17 -14
- package/dist-lib/lib/contract/models.d.ts +8 -1
- package/dist-lib/lib/contract-types.d.ts +9 -0
- package/dist-lib/lib/harness.d.ts +267 -0
- package/dist-lib/lib/harness.js +1154 -0
- package/dist-lib/lib/models/custom-model-cache.d.ts +2 -0
- package/dist-lib/lib/models/custom-model-cache.js +21 -0
- package/dist-lib/lib/models/memory-cap.d.ts +6 -0
- package/dist-lib/lib/models/memory-cap.js +20 -0
- package/dist-lib/lib/models/model-catalog.d.ts +2 -0
- package/dist-lib/lib/models/model-catalog.js +8 -2
- package/dist-lib/lib/models/model-fit.d.ts +39 -7
- package/dist-lib/lib/models/model-fit.js +133 -18
- package/dist-lib/lib/models/model-handle.d.ts +2 -1
- package/dist-lib/lib/models/model-pool.d.ts +3 -2
- package/dist-lib/lib/models/model-pool.js +30 -13
- package/dist-lib/lib/models/tts-model-default.d.ts +1 -1
- package/dist-lib/lib/models/tts-model-default.js +7 -6
- package/dist-lib/lib/residency/index.d.ts +21 -7
- package/dist-lib/lib/residency/index.js +187 -80
- package/dist-lib/lib/run-log/boundary.d.ts +4 -1
- package/dist-lib/lib/run-log/boundary.js +2 -1
- package/dist-lib/lib/run-log/index.d.ts +2 -1
- package/dist-lib/lib/run-log/index.js +2 -1
- package/dist-lib/lib/run-log/persisted-actor.d.ts +10 -0
- package/dist-lib/lib/run-log/persisted-actor.js +15 -0
- package/dist-lib/lib/run-log/run-journal.d.ts +3 -0
- package/dist-lib/lib/run-log/run-journal.js +19 -8
- package/dist-lib/lib/serve/requests.d.ts +3 -0
- package/dist-lib/lib/serve.js +3 -0
- package/dist-lib/lib/spawn.d.ts +4 -1
- package/dist-lib/lib/tools/files/list-dir.js +79 -32
- package/dist-lib/lib/tools/fs/walk.d.ts +11 -1
- package/dist-lib/lib/tools/fs/walk.js +64 -30
- package/dist-lib/lib/tools/office.js +8 -5
- package/dist-lib/lib/tools/pdf/pages.d.ts +1 -1
- package/dist-lib/lib/tools/pdf/pages.js +3 -14
- package/dist-lib/lib/tools/pdf/recognize.d.ts +3 -0
- package/dist-lib/lib/tools/pdf/recognize.js +45 -7
- package/dist-lib/plugins/image/generate-image.d.ts +2 -2
- package/dist-lib/plugins/image/generate-image.js +9 -1
- package/dist-lib/plugins/image/index.js +6 -2
- package/dist-lib/plugins/knowledge/chunk-index.d.ts +4 -0
- package/dist-lib/plugins/knowledge/chunk-index.js +191 -0
- package/dist-lib/plugins/knowledge/index.d.ts +1 -0
- package/dist-lib/plugins/knowledge/index.js +1 -0
- package/dist-lib/plugins/knowledge/manifest.d.ts +2 -1
- package/dist-lib/plugins/knowledge/manifest.js +2 -9
- package/dist-lib/plugins/knowledge/store.d.ts +5 -1
- package/dist-lib/plugins/knowledge/store.js +44 -16
- package/dist-lib/plugins/lsp/rpc.d.ts +9 -1
- package/dist-lib/plugins/lsp/rpc.js +81 -17
- package/dist-lib/plugins/music/generate-music.d.ts +2 -2
- package/dist-lib/plugins/music/generate-music.js +14 -1
- package/dist-lib/plugins/music/index.js +4 -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/speech/speech-engine.d.ts +5 -2
- package/dist-lib/plugins/speech/speech-engine.js +28 -7
- package/dist-lib/schema/harness.js +28 -2
- package/dist-lib/spec/bind.js +3 -0
- package/dist-lib/spec/calls.js +1 -0
- package/dist-lib/spec/hrpc/hrpc.json +13 -0
- package/dist-lib/spec/hrpc/index.js +15 -3
- package/dist-lib/spec/hrpc/messages.js +87 -6
- package/dist-lib/spec/hyperschema/index.js +87 -6
- package/dist-lib/spec/hyperschema/schema.json +70 -2
- package/dist-lib/spec/hyperschema/types.d.ts +21 -1
- package/package.json +29 -28
- package/scripts/addon-externals.cjs +1 -0
- package/worker/harness-sidecar.mjs +12 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { FollowEvent, FollowHost } from './follow.ts';
|
|
2
|
+
export interface ChildRequest {
|
|
3
|
+
runId?: string;
|
|
4
|
+
parentRunId?: string;
|
|
5
|
+
cacheKey?: string;
|
|
6
|
+
messages?: ReadonlyArray<{
|
|
7
|
+
role: string;
|
|
8
|
+
content: string;
|
|
9
|
+
}>;
|
|
10
|
+
tools?: ReadonlyArray<{
|
|
11
|
+
name: string;
|
|
12
|
+
}>;
|
|
13
|
+
resume?: unknown;
|
|
14
|
+
recovery?: unknown;
|
|
15
|
+
input?: unknown;
|
|
16
|
+
goal?: unknown;
|
|
17
|
+
latency?: unknown;
|
|
18
|
+
}
|
|
19
|
+
export interface ChildRun {
|
|
20
|
+
parent: string | undefined;
|
|
21
|
+
id: string;
|
|
22
|
+
prompt: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ChildResult {
|
|
25
|
+
status: 'answered' | 'paused' | 'aborted' | 'error';
|
|
26
|
+
text: string;
|
|
27
|
+
}
|
|
28
|
+
export declare function childRun<Request extends ChildRequest>(base: Request, { parent, id, prompt }: ChildRun): Request;
|
|
29
|
+
export declare function collect<Request, Event extends FollowEvent>(host: FollowHost<Request, Event>, request: Request): Promise<ChildResult>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function childRun(base, { parent, id, prompt }) {
|
|
2
|
+
const run = {
|
|
3
|
+
...base,
|
|
4
|
+
runId: parent === undefined ? undefined : `${parent}/${id}`,
|
|
5
|
+
parentRunId: parent,
|
|
6
|
+
messages: [{ role: 'user', content: prompt }]
|
|
7
|
+
};
|
|
8
|
+
delete run.resume;
|
|
9
|
+
delete run.recovery;
|
|
10
|
+
delete run.input;
|
|
11
|
+
delete run.goal;
|
|
12
|
+
delete run.latency;
|
|
13
|
+
return run;
|
|
14
|
+
}
|
|
15
|
+
export async function collect(host, request) {
|
|
16
|
+
let text = '';
|
|
17
|
+
let status = 'answered';
|
|
18
|
+
for await (const event of host.completion(request)) {
|
|
19
|
+
const { type } = event;
|
|
20
|
+
if (type === 'content') {
|
|
21
|
+
text += String(Object(event).text ?? '');
|
|
22
|
+
}
|
|
23
|
+
else if (type === 'error') {
|
|
24
|
+
status = type;
|
|
25
|
+
text = String(Object(event).message ?? '');
|
|
26
|
+
}
|
|
27
|
+
else if (type === 'paused' || type === 'aborted') {
|
|
28
|
+
status = type;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return { status, text };
|
|
32
|
+
}
|
|
@@ -1,28 +1,14 @@
|
|
|
1
1
|
import type { AccessPolicy, ToolDefinition, ToolExecuteContext } from '../contract/index.ts';
|
|
2
|
+
import type { ChildRequest, ChildResult } from './child-run.ts';
|
|
2
3
|
import type { FollowEvent, FollowHost } from './follow.ts';
|
|
3
4
|
export declare const DELEGATE_TOOL_NAME = "delegate";
|
|
4
|
-
export interface DelegateRequest {
|
|
5
|
-
runId?: string;
|
|
6
|
-
parentRunId?: string;
|
|
7
|
-
cacheKey?: string;
|
|
5
|
+
export interface DelegateRequest extends ChildRequest {
|
|
8
6
|
signal?: ToolExecuteContext['signal'];
|
|
9
|
-
messages?: ReadonlyArray<{
|
|
10
|
-
role: string;
|
|
11
|
-
content: string;
|
|
12
|
-
}>;
|
|
13
|
-
tools?: ReadonlyArray<{
|
|
14
|
-
name: string;
|
|
15
|
-
}>;
|
|
16
7
|
agent?: {
|
|
17
8
|
handoffs?: unknown;
|
|
18
9
|
policy?: AccessPolicy | null;
|
|
19
10
|
};
|
|
20
11
|
policy?: AccessPolicy;
|
|
21
|
-
resume?: unknown;
|
|
22
|
-
recovery?: unknown;
|
|
23
|
-
input?: unknown;
|
|
24
|
-
goal?: unknown;
|
|
25
|
-
latency?: unknown;
|
|
26
12
|
}
|
|
27
13
|
export type TargetAccess = 'read' | 'write';
|
|
28
14
|
export interface TargetTask {
|
|
@@ -62,10 +48,8 @@ export interface DelegateOptions {
|
|
|
62
48
|
read?: readonly string[];
|
|
63
49
|
maxExternal?: number;
|
|
64
50
|
}
|
|
65
|
-
export interface LocalResult {
|
|
51
|
+
export interface LocalResult extends ChildResult {
|
|
66
52
|
task: string;
|
|
67
|
-
status: 'answered' | 'paused' | 'aborted' | 'error';
|
|
68
|
-
text: string;
|
|
69
53
|
}
|
|
70
54
|
export interface ExternalResult {
|
|
71
55
|
task: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Policy } from '../policy/index.js';
|
|
2
|
+
import { childRun, collect } from './child-run.js';
|
|
2
3
|
export const DELEGATE_TOOL_NAME = 'delegate';
|
|
3
4
|
const LOCAL = 'local';
|
|
4
5
|
const MAX_EXTERNAL = 2;
|
|
@@ -149,7 +150,7 @@ async function fanOut(host, base, { slots, maxExternal, args, ctx, ...roster })
|
|
|
149
150
|
await Promise.all([
|
|
150
151
|
pool(local, slots, async (index, worker) => {
|
|
151
152
|
const request = child(base, ctx, { ...tasks[index], summary, index, worker });
|
|
152
|
-
fanned.results[index] =
|
|
153
|
+
fanned.results[index] = { task: tasks[index].task, ...(await collect(host, request)) };
|
|
153
154
|
}),
|
|
154
155
|
pool(outside, maxExternal, async ({ index, target }, worker) => {
|
|
155
156
|
const { task } = tasks[index];
|
|
@@ -226,39 +227,15 @@ function deadlineTimer(deadlineMs, controller) {
|
|
|
226
227
|
return deadline;
|
|
227
228
|
}
|
|
228
229
|
function child(base, ctx, { task, summary, index, worker }) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
230
|
+
return {
|
|
231
|
+
...childRun(base, {
|
|
232
|
+
parent: ctx?.runId ?? base.runId,
|
|
233
|
+
id: `d-${ctx?.callId ?? 0}-${index}`,
|
|
234
|
+
prompt: summary ? `${summary}\n\n${task}` : task
|
|
235
|
+
}),
|
|
234
236
|
signal: ctx?.signal ?? base.signal,
|
|
235
237
|
cacheKey: base.cacheKey === undefined ? undefined : `${base.cacheKey}/d-${worker}`,
|
|
236
|
-
messages: [{ role: 'user', content: summary ? `${summary}\n\n${task}` : task }],
|
|
237
238
|
tools: base.tools?.filter((tool) => tool.name !== DELEGATE_TOOL_NAME),
|
|
238
239
|
agent: base.agent && { ...base.agent, handoffs: null }
|
|
239
240
|
};
|
|
240
|
-
delete run.resume;
|
|
241
|
-
delete run.recovery;
|
|
242
|
-
delete run.input;
|
|
243
|
-
delete run.goal;
|
|
244
|
-
delete run.latency;
|
|
245
|
-
return run;
|
|
246
|
-
}
|
|
247
|
-
async function subagent(host, task, request) {
|
|
248
|
-
let text = '';
|
|
249
|
-
let status = 'answered';
|
|
250
|
-
for await (const event of host.completion(request)) {
|
|
251
|
-
const { type } = event;
|
|
252
|
-
if (type === 'content') {
|
|
253
|
-
text += String(Object(event).text ?? '');
|
|
254
|
-
}
|
|
255
|
-
else if (type === 'error') {
|
|
256
|
-
status = type;
|
|
257
|
-
text = String(Object(event).message ?? '');
|
|
258
|
-
}
|
|
259
|
-
else if (type === 'paused' || type === 'aborted') {
|
|
260
|
-
status = type;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return { task, status, text };
|
|
264
241
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AgentConfig, AgentPolicy, AgentPorts, AgentRequest, AgentSkill, ResolvedAgent } from '../contract/index.ts';
|
|
2
2
|
import { createDelegateTool } from './delegate.ts';
|
|
3
3
|
import { follow, untransferred } from './follow.ts';
|
|
4
|
+
import { notesContext, readParts } from './read-parts.ts';
|
|
4
5
|
import { agentPolicy, resolveAgent } from './resolve.ts';
|
|
5
6
|
import { planFromMessages, planSteps } from './plan.ts';
|
|
6
7
|
import { parseToolGrant } from './tool-grants.ts';
|
|
@@ -23,6 +24,8 @@ export declare class Agent<Skill extends AgentSkill = AgentSkill> {
|
|
|
23
24
|
static skillIsActive: typeof skillIsActive;
|
|
24
25
|
static follow: typeof follow;
|
|
25
26
|
static delegateTool: typeof createDelegateTool;
|
|
27
|
+
static readParts: typeof readParts;
|
|
28
|
+
static notesContext: typeof notesContext;
|
|
26
29
|
static untransferred: typeof untransferred;
|
|
27
30
|
static planSteps: typeof planSteps;
|
|
28
31
|
static planFromMessages: typeof planFromMessages;
|
|
@@ -34,4 +37,5 @@ export declare class Agent<Skill extends AgentSkill = AgentSkill> {
|
|
|
34
37
|
}
|
|
35
38
|
export type { DelegateOptions, DelegateRequest, DelegateResult, DelegateTarget, ExternalResult, ExternalRun, LocalResult, TargetAccess, TargetEvent, TargetResult, TargetTask, TargetUsage } from './delegate.ts';
|
|
36
39
|
export type { FollowAgent, FollowEvent, FollowHost, FollowRequest } from './follow.ts';
|
|
40
|
+
export type { DocumentNotes, DocumentPart, PartNote, PartProgress, ReadPartsOptions, ReadPartsRequest } from './read-parts.ts';
|
|
37
41
|
export type { TransferResult } from './transfer.ts';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createDelegateTool, DELEGATE_TOOL_NAME } from './delegate.js';
|
|
2
2
|
import { follow, MAX_TRANSFERS, untransferred } from './follow.js';
|
|
3
|
+
import { notesContext, readParts } from './read-parts.js';
|
|
3
4
|
import { agentPolicy, resolveAgent } from './resolve.js';
|
|
4
5
|
import { MAX_PLAN_STEPS, PLAN_TOOL_NAME, planFromMessages, planSteps } from './plan.js';
|
|
5
6
|
import { parseToolGrant } from './tool-grants.js';
|
|
@@ -24,6 +25,8 @@ export class Agent {
|
|
|
24
25
|
static skillIsActive = skillIsActive;
|
|
25
26
|
static follow = follow;
|
|
26
27
|
static delegateTool = createDelegateTool;
|
|
28
|
+
static readParts = readParts;
|
|
29
|
+
static notesContext = notesContext;
|
|
27
30
|
static untransferred = untransferred;
|
|
28
31
|
static planSteps = planSteps;
|
|
29
32
|
static planFromMessages = planFromMessages;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ChildRequest, ChildResult } from './child-run.ts';
|
|
2
|
+
import type { FollowEvent, FollowHost } from './follow.ts';
|
|
3
|
+
export interface ReadPartsRequest extends ChildRequest {
|
|
4
|
+
signal?: {
|
|
5
|
+
readonly aborted: boolean;
|
|
6
|
+
};
|
|
7
|
+
agent?: {
|
|
8
|
+
handoffs?: unknown;
|
|
9
|
+
toolsScope?: 'all' | 'selected' | null;
|
|
10
|
+
enabledTools?: string[] | null;
|
|
11
|
+
skillsScope?: 'all' | 'selected' | null;
|
|
12
|
+
enabledSkills?: string[] | null;
|
|
13
|
+
};
|
|
14
|
+
generationParams?: {
|
|
15
|
+
reasoning_budget?: number;
|
|
16
|
+
predict?: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface DocumentPart {
|
|
20
|
+
text: string;
|
|
21
|
+
span?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ReadPartsOptions {
|
|
24
|
+
read: string;
|
|
25
|
+
title: string;
|
|
26
|
+
parts: ReadonlyArray<DocumentPart>;
|
|
27
|
+
noteTokens: number;
|
|
28
|
+
onPart?: (progress: PartProgress) => void;
|
|
29
|
+
}
|
|
30
|
+
export interface PartProgress {
|
|
31
|
+
part: number;
|
|
32
|
+
parts: number;
|
|
33
|
+
}
|
|
34
|
+
export interface PartNote extends ChildResult {
|
|
35
|
+
span?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface DocumentNotes {
|
|
38
|
+
title: string;
|
|
39
|
+
notes: ReadonlyArray<{
|
|
40
|
+
text: string;
|
|
41
|
+
span?: string;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
export declare function readParts<Request extends ReadPartsRequest, Event extends FollowEvent>(host: FollowHost<Request, Event>, base: Request, { read: id, title, parts, noteTokens, onPart }: ReadPartsOptions): Promise<PartNote[]>;
|
|
45
|
+
export declare function notesContext(documents: ReadonlyArray<DocumentNotes>): string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { childRun, collect } from './child-run.js';
|
|
2
|
+
const WORDS_PER_TOKEN = 0.55;
|
|
3
|
+
export async function readParts(host, base, { read: id, title, parts, noteTokens, onPart }) {
|
|
4
|
+
const notes = [];
|
|
5
|
+
for (const [index, part] of parts.entries()) {
|
|
6
|
+
if (base.signal?.aborted) {
|
|
7
|
+
notes.push({ status: 'aborted', text: '' });
|
|
8
|
+
break;
|
|
9
|
+
}
|
|
10
|
+
onPart?.({ part: index + 1, parts: parts.length });
|
|
11
|
+
const prompt = notesPrompt({ title, part, index, count: parts.length, noteTokens });
|
|
12
|
+
const note = await collect(host, child(base, { prompt, id, index, noteTokens }));
|
|
13
|
+
notes.push({ status: note.status, text: note.text.trim(), span: part.span });
|
|
14
|
+
if (note.status !== 'answered') {
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return notes;
|
|
19
|
+
}
|
|
20
|
+
export function notesContext(documents) {
|
|
21
|
+
const names = documents.map((document) => `"${document.title}"`).join(', ');
|
|
22
|
+
const lines = [
|
|
23
|
+
`Notes taken while reading the whole of ${names} part by part follow, in reading order. Answer the user from them directly.`
|
|
24
|
+
];
|
|
25
|
+
for (const { title, notes } of documents) {
|
|
26
|
+
for (const [index, note] of notes.entries()) {
|
|
27
|
+
const span = note.span ? ` (${note.span})` : '';
|
|
28
|
+
lines.push('', `--- ${title}, part ${index + 1} of ${notes.length}${span} ---`, note.text);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return lines.join('\n');
|
|
32
|
+
}
|
|
33
|
+
function notesPrompt({ title, part, index, count, noteTokens }) {
|
|
34
|
+
const span = part.span ? ` (${part.span})` : '';
|
|
35
|
+
const words = Math.floor((noteTokens * WORDS_PER_TOKEN) / 10) * 10;
|
|
36
|
+
return [
|
|
37
|
+
`Part ${index + 1} of ${count} of the document "${title}"${span} follows.`,
|
|
38
|
+
'',
|
|
39
|
+
`--- ${title}${span} ---`,
|
|
40
|
+
part.text,
|
|
41
|
+
'',
|
|
42
|
+
`You are reading this document part by part so it can be summarized afterwards. Write notes on this part only: its main argument, then every specific claim, recommendation, number, definition and caveat a faithful summary would need. State each claim itself, do not just name its topic. Use at most ${words} words. Add nothing that is not in the text.`
|
|
43
|
+
].join('\n');
|
|
44
|
+
}
|
|
45
|
+
function child(base, { prompt, id, index, noteTokens }) {
|
|
46
|
+
return {
|
|
47
|
+
...childRun(base, { parent: base.runId, id: `r-${id}-${index}`, prompt }),
|
|
48
|
+
cacheKey: undefined,
|
|
49
|
+
tools: [],
|
|
50
|
+
agent: base.agent && {
|
|
51
|
+
...base.agent,
|
|
52
|
+
handoffs: null,
|
|
53
|
+
toolsScope: 'selected',
|
|
54
|
+
enabledTools: [],
|
|
55
|
+
skillsScope: 'selected',
|
|
56
|
+
enabledSkills: []
|
|
57
|
+
},
|
|
58
|
+
generationParams: { ...base.generationParams, reasoning_budget: 0, predict: noteTokens }
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -521,7 +521,7 @@ export async function* driveCompletion(args, runtime, options) {
|
|
|
521
521
|
: args.input,
|
|
522
522
|
lockOwner: args.lockOwner ?? options.lockOwner ?? completionLockOwner,
|
|
523
523
|
now,
|
|
524
|
-
async start({ operations, invokes, boot: openedBoot }) {
|
|
524
|
+
async start({ operations, invokes, boot: openedBoot, initial }) {
|
|
525
525
|
if (resume &&
|
|
526
526
|
RunLog.unsettledRedactedIds(openedBoot.redactedPendingIds, openedBoot.receipts).length > 0) {
|
|
527
527
|
const forkAt = safeForkLength(openedBoot);
|
|
@@ -570,10 +570,14 @@ export async function* driveCompletion(args, runtime, options) {
|
|
|
570
570
|
outbound: options.outbound,
|
|
571
571
|
agentPorts: worded(options.agentPorts, full.wording?.guidelines)
|
|
572
572
|
});
|
|
573
|
-
session.startedAt =
|
|
573
|
+
session.startedAt =
|
|
574
|
+
openedBoot.metadata?.startedAt ?? openedBoot.firstSavedAt ?? initial?.startedAt ?? now();
|
|
574
575
|
if (openedBoot.metadata?.budget) {
|
|
575
576
|
session.runBudget = { ...openedBoot.metadata.budget };
|
|
576
577
|
}
|
|
578
|
+
else if (initial?.budget) {
|
|
579
|
+
session.runBudget = { ...initial.budget };
|
|
580
|
+
}
|
|
577
581
|
session.toolContext = runToolContext(full, session.runBudget);
|
|
578
582
|
const context = CompletionMachine.emptyContext({
|
|
579
583
|
policy,
|
|
@@ -43,7 +43,8 @@ function started({ runId, resume, parentRunId }) {
|
|
|
43
43
|
}
|
|
44
44
|
export async function* runEngine(run, options = {}) {
|
|
45
45
|
const { runId } = run;
|
|
46
|
-
const
|
|
46
|
+
const transient = !run.resume && !options.boot && typeof options.onStep !== 'function';
|
|
47
|
+
const journal = RunLog.openBoundary(options, { transient });
|
|
47
48
|
const core = journal.core;
|
|
48
49
|
const release = RunLog.acquireRun(run.lockOwner ?? options.lockOwner ?? core, runId);
|
|
49
50
|
try {
|
|
@@ -53,6 +54,7 @@ export async function* runEngine(run, options = {}) {
|
|
|
53
54
|
else if (journal.knownLength !== core.length) {
|
|
54
55
|
throw new Error(`Run ${runId} changed while opening`);
|
|
55
56
|
}
|
|
57
|
+
let startedAt;
|
|
56
58
|
if (run.resume) {
|
|
57
59
|
if (!journal.metadata) {
|
|
58
60
|
throw new Error(`Run ${runId} does not exist`);
|
|
@@ -76,20 +78,23 @@ export async function* runEngine(run, options = {}) {
|
|
|
76
78
|
if (run.recovery?.length) {
|
|
77
79
|
throw new Error('Recovery resolutions require resume mode');
|
|
78
80
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
81
|
+
startedAt = run.now ? run.now() : undefined;
|
|
82
|
+
if (!transient) {
|
|
83
|
+
const metadata = {
|
|
84
|
+
version: RunLog.VERSION,
|
|
85
|
+
type: 'metadata',
|
|
86
|
+
machine: CompletionMachine.VERSION,
|
|
87
|
+
definition: CompletionMachine.definition(),
|
|
88
|
+
xstate: RunLog.XSTATE_VERSION,
|
|
89
|
+
runId,
|
|
90
|
+
request: run.request,
|
|
91
|
+
requestDigest: run.requestDigest,
|
|
92
|
+
digestRunId: run.requestDigest ? runId : undefined,
|
|
93
|
+
budget: run.budget,
|
|
94
|
+
startedAt
|
|
95
|
+
};
|
|
96
|
+
await journal.append(metadata);
|
|
97
|
+
}
|
|
93
98
|
}
|
|
94
99
|
const restored = readRestoredSnapshot(journal.snapshot);
|
|
95
100
|
if (restored && restored.context?.runId !== runId) {
|
|
@@ -118,7 +123,8 @@ export async function* runEngine(run, options = {}) {
|
|
|
118
123
|
const { ports, context } = await run.start({
|
|
119
124
|
operations: createOperationPort(journal),
|
|
120
125
|
invokes,
|
|
121
|
-
boot
|
|
126
|
+
boot,
|
|
127
|
+
initial: transient ? { budget: run.budget, startedAt } : undefined
|
|
122
128
|
});
|
|
123
129
|
return yield* drive({
|
|
124
130
|
journal,
|
|
@@ -135,6 +141,7 @@ export async function* runEngine(run, options = {}) {
|
|
|
135
141
|
invokes,
|
|
136
142
|
now: ports.now,
|
|
137
143
|
durable: typeof options.onStep === 'function',
|
|
144
|
+
transient,
|
|
138
145
|
onDetached: options.onDetached,
|
|
139
146
|
mailbox
|
|
140
147
|
});
|
|
@@ -146,7 +153,7 @@ export async function* runEngine(run, options = {}) {
|
|
|
146
153
|
release();
|
|
147
154
|
}
|
|
148
155
|
}
|
|
149
|
-
async function* drive({ journal, run, machine, invokes, now, durable, onDetached, mailbox }) {
|
|
156
|
+
async function* drive({ journal, run, machine, invokes, now, durable, transient, onDetached, mailbox }) {
|
|
150
157
|
const { runId, signal } = run;
|
|
151
158
|
const pausedMs = run.resume && journal.snapshotSavedAt !== undefined
|
|
152
159
|
? Math.max(0, now() - journal.snapshotSavedAt)
|
|
@@ -167,7 +174,9 @@ async function* drive({ journal, run, machine, invokes, now, durable, onDetached
|
|
|
167
174
|
wake();
|
|
168
175
|
};
|
|
169
176
|
mailbox.notify = notify;
|
|
170
|
-
const { actor, persistence } =
|
|
177
|
+
const { actor, persistence } = transient
|
|
178
|
+
? RunLog.createTransientActor(machine, journal, notify)
|
|
179
|
+
: await RunLog.createPersistedActor(journal, machine, notify, now);
|
|
171
180
|
actor.on('*', (event) => {
|
|
172
181
|
queue.push(event);
|
|
173
182
|
notify();
|
|
@@ -372,8 +372,12 @@ async function* runRecoveredRoundWith(send) {
|
|
|
372
372
|
}
|
|
373
373
|
async function* runLadder({ send, history, origins, fold }) {
|
|
374
374
|
let lastOverflow = null;
|
|
375
|
-
|
|
375
|
+
let tried = 0;
|
|
376
|
+
const candidates = ContextWindow.contextCandidateIterator(history, ...harnessTurns(send.args, history));
|
|
376
377
|
for (const candidate of candidates) {
|
|
378
|
+
if (tried++ === 1) {
|
|
379
|
+
await dropShrunkKey(send);
|
|
380
|
+
}
|
|
377
381
|
const outcome = yield* runCandidateAttempts({ ...send, candidate, history, origins });
|
|
378
382
|
if ('round' in outcome) {
|
|
379
383
|
const cacheable = !send.attempts.uncached;
|
|
@@ -386,9 +390,6 @@ async function* runLadder({ send, history, origins, fold }) {
|
|
|
386
390
|
if (folded) {
|
|
387
391
|
return { folded };
|
|
388
392
|
}
|
|
389
|
-
if (candidates.length > 1) {
|
|
390
|
-
await dropShrunkKey(send);
|
|
391
|
-
}
|
|
392
393
|
}
|
|
393
394
|
}
|
|
394
395
|
if (!lastOverflow) {
|
|
@@ -149,9 +149,7 @@ export class HarnessClient {
|
|
|
149
149
|
actualSize: actualSize || undefined,
|
|
150
150
|
label: label || undefined,
|
|
151
151
|
taskType: addonTaskType(row.type),
|
|
152
|
-
fit: (fit || undefined)
|
|
153
|
-
fitBasis: (fitBasis || undefined),
|
|
154
|
-
fitEvidence: (fitEvidence || undefined)
|
|
152
|
+
fit: (fit || undefined)
|
|
155
153
|
}));
|
|
156
154
|
}
|
|
157
155
|
close() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { HarnessLoadedModel } from '../../spec/hyperschema/types.d.ts';
|
|
2
|
-
import type { AgentKnobs, CompletionContext, HarnessEvent, HostContext, LoadedModel } from '../contract-types.ts';
|
|
1
|
+
import type { HarnessLoadedModel, HarnessMemoryUsage } from '../../spec/hyperschema/types.d.ts';
|
|
2
|
+
import type { AgentKnobs, CompletionContext, HarnessEvent, HostContext, LoadedModel, MemoryUsage } from '../contract-types.ts';
|
|
3
3
|
import type { ToolCallDisplay } from '../contract/index.ts';
|
|
4
4
|
import { type SkillState } from '../tools/skills/skill-state.ts';
|
|
5
5
|
import type { WireDownloadEvent } from '../wire.ts';
|
|
@@ -11,6 +11,7 @@ export interface WireModelEvent extends HarnessEvent {
|
|
|
11
11
|
loaded?: HarnessLoadedModel[];
|
|
12
12
|
}
|
|
13
13
|
export declare function loadedModel({ model, refs, fit }: HarnessLoadedModel | LoadedModel): LoadedModel;
|
|
14
|
+
export declare function memoryUsage({ usedBytes, pools }: HarnessMemoryUsage): MemoryUsage;
|
|
14
15
|
export declare function parseSkillState(value: string): SkillState;
|
|
15
16
|
export declare function errorDetails(err: unknown): ErrorDetails;
|
|
16
17
|
export declare function isToolCallDisplay(value: unknown): value is ToolCallDisplay;
|
|
@@ -19,6 +19,20 @@ export function loadedModel({ model, refs, fit }) {
|
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
+
export function memoryUsage({ usedBytes, pools }) {
|
|
23
|
+
if (!pools) {
|
|
24
|
+
return { usedBytes };
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
usedBytes,
|
|
28
|
+
pools: pools.map(({ id, usedBytes: used, capBytes, totalBytes }) => ({
|
|
29
|
+
id,
|
|
30
|
+
usedBytes: used,
|
|
31
|
+
capBytes: capBytes || undefined,
|
|
32
|
+
totalBytes: totalBytes || undefined
|
|
33
|
+
}))
|
|
34
|
+
};
|
|
35
|
+
}
|
|
22
36
|
export function parseSkillState(value) {
|
|
23
37
|
return value ? value : SKILL_STATE.failed;
|
|
24
38
|
}
|
|
@@ -41,6 +41,7 @@ export declare class RemoteHarness extends EventEmitter implements HarnessContra
|
|
|
41
41
|
private _run;
|
|
42
42
|
download(context: HostContext<DownloadContext>): AsyncIterable<HarnessEvent>;
|
|
43
43
|
embed(context: HostContext<EmbedContext>): Promise<number[][]>;
|
|
44
|
+
embeddingWeights(model: string): Promise<string | undefined>;
|
|
44
45
|
transcribe(context: HostContext<TranscribeContext>): Promise<string>;
|
|
45
46
|
ocrRead(context: HostContext<OcrReadContext>): Promise<OcrPage>;
|
|
46
47
|
detectLanguage(context: DetectLanguageContext): Promise<DetectedLanguage[]>;
|
package/dist-lib/lib/connect.js
CHANGED
|
@@ -22,7 +22,7 @@ import { sweepSpill } from './spill.js';
|
|
|
22
22
|
import { readInstall, readSetup } from './tools/skills/manifest-parse.js';
|
|
23
23
|
import { asToolset } from './tools/toolsets.js';
|
|
24
24
|
import { Wire } from './wire.js';
|
|
25
|
-
import { loadedModel, parseSkillState, errorDetails, knobs, explicitEmptyIdentityFields, frames, downloadFrames } from './connect/decode.js';
|
|
25
|
+
import { loadedModel, memoryUsage, parseSkillState, errorDetails, knobs, explicitEmptyIdentityFields, frames, downloadFrames } from './connect/decode.js';
|
|
26
26
|
import { died, noop, abortable, awaitWithAbort } from './connect/abort.js';
|
|
27
27
|
import { abortedRound, servedRound, servedMedia } from './connect/served.js';
|
|
28
28
|
import { bridgeAttach, bridgeShow, bridgeFetch, bridgeDrive, sendInput, answerQuestion, approvalCall } from './connect/bridges.js';
|
|
@@ -686,6 +686,11 @@ export class RemoteHarness extends EventEmitter {
|
|
|
686
686
|
}
|
|
687
687
|
return rows;
|
|
688
688
|
}
|
|
689
|
+
async embeddingWeights(model) {
|
|
690
|
+
const { client } = await this._ensure();
|
|
691
|
+
const response = await client.embeddingWeights({ model });
|
|
692
|
+
return response.weights || undefined;
|
|
693
|
+
}
|
|
689
694
|
async transcribe(context) {
|
|
690
695
|
const { client } = await this._ensure();
|
|
691
696
|
const response = await abortable(client.transcribe({ model: context.model, audio: context.audio }), context.signal);
|
|
@@ -770,7 +775,7 @@ export class RemoteHarness extends EventEmitter {
|
|
|
770
775
|
}
|
|
771
776
|
async memoryUsage() {
|
|
772
777
|
const { client } = await this._ensure();
|
|
773
|
-
return await client.memoryUsage({});
|
|
778
|
+
return memoryUsage(await client.memoryUsage({}));
|
|
774
779
|
}
|
|
775
780
|
async setDownloadsAllowed({ allowed }) {
|
|
776
781
|
const { client } = await this._ensure();
|
|
@@ -952,9 +957,7 @@ export class RemoteHarness extends EventEmitter {
|
|
|
952
957
|
memoryBytes: memoryBytes || undefined,
|
|
953
958
|
label: label || undefined,
|
|
954
959
|
taskType: addonTaskType(row.type),
|
|
955
|
-
fit: (fit || undefined)
|
|
956
|
-
fitBasis: (fitBasis || undefined),
|
|
957
|
-
fitEvidence: (fitEvidence || undefined)
|
|
960
|
+
fit: (fit || undefined)
|
|
958
961
|
}));
|
|
959
962
|
}
|
|
960
963
|
async deleteModel(name) {
|
|
@@ -1019,6 +1022,9 @@ export class RemoteHarness extends EventEmitter {
|
|
|
1019
1022
|
if (response.hostRunLog === true) {
|
|
1020
1023
|
capability.hostRunLog = true;
|
|
1021
1024
|
}
|
|
1025
|
+
if (response.mobileMemoryCap === true) {
|
|
1026
|
+
capability.mobileMemoryCap = true;
|
|
1027
|
+
}
|
|
1022
1028
|
if (response.hostRunLogVersion && response.hostRunLogVersion > 0) {
|
|
1023
1029
|
capability.hostRunLogVersion = response.hostRunLogVersion;
|
|
1024
1030
|
}
|
|
@@ -5,6 +5,7 @@ interface ContextCandidate {
|
|
|
5
5
|
history: Message[];
|
|
6
6
|
droppedTurns: number;
|
|
7
7
|
}
|
|
8
|
+
declare function contextCandidateIterator(history: Message[], ...nudges: string[]): Generator<ContextCandidate>;
|
|
8
9
|
declare function contextCandidates(history: Message[], ...nudges: string[]): ContextCandidate[];
|
|
9
10
|
declare function compactContent(content: string, target: number): string;
|
|
10
11
|
export type { ContextCandidate };
|
|
@@ -13,5 +14,6 @@ export declare class ContextWindow {
|
|
|
13
14
|
static compactContent: typeof compactContent;
|
|
14
15
|
static compactedFrom: typeof compactedFrom;
|
|
15
16
|
static contextCandidates: typeof contextCandidates;
|
|
17
|
+
static contextCandidateIterator: typeof contextCandidateIterator;
|
|
16
18
|
static responseRoomChars: typeof responseRoomChars;
|
|
17
19
|
}
|
|
@@ -11,19 +11,25 @@ const compactedSources = new WeakMap();
|
|
|
11
11
|
function compactedFrom(message) {
|
|
12
12
|
return compactedSources.get(message);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function* contextCandidateIterator(history, ...nudges) {
|
|
15
|
+
yield { history, droppedTurns: 0 };
|
|
15
16
|
const isBoundary = (message) => Fold.isTurn(message, nudges);
|
|
16
17
|
const { prefix, turns } = splitTurns(history, isBoundary);
|
|
17
18
|
if (!turns.length) {
|
|
18
|
-
return
|
|
19
|
+
return;
|
|
19
20
|
}
|
|
20
21
|
const maxDropped = Math.max(0, turns.length - 1);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
droppedTurns
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
let last = { history, droppedTurns: 0 };
|
|
23
|
+
for (const droppedTurns of dropCounts(maxDropped)) {
|
|
24
|
+
if (droppedTurns === 0)
|
|
25
|
+
continue;
|
|
26
|
+
last = { history: [...prefix, ...turns.slice(droppedTurns).flat()], droppedTurns };
|
|
27
|
+
yield last;
|
|
28
|
+
}
|
|
29
|
+
yield* toolCompactionCandidates(last, isBoundary);
|
|
30
|
+
}
|
|
31
|
+
function contextCandidates(history, ...nudges) {
|
|
32
|
+
return [...contextCandidateIterator(history, ...nudges)];
|
|
27
33
|
}
|
|
28
34
|
function splitTurns(history, isBoundary) {
|
|
29
35
|
const firstUser = history.findIndex(isBoundary);
|
|
@@ -53,11 +59,7 @@ function dropCounts(max) {
|
|
|
53
59
|
}
|
|
54
60
|
return counts;
|
|
55
61
|
}
|
|
56
|
-
function
|
|
57
|
-
const last = candidates[candidates.length - 1];
|
|
58
|
-
if (!last) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
62
|
+
function* toolCompactionCandidates(last, isBoundary) {
|
|
61
63
|
const tools = compactableTools(last.history, isBoundary);
|
|
62
64
|
let history = last.history;
|
|
63
65
|
while (true) {
|
|
@@ -67,7 +69,7 @@ function appendToolCompactions(candidates, isBoundary) {
|
|
|
67
69
|
}
|
|
68
70
|
selected.target = Math.max(TOOL_RESULT_TRUNCATION_MARKER.length, Math.floor(selected.target / 2));
|
|
69
71
|
history = history.map(compactTool.bind(null, selected));
|
|
70
|
-
|
|
72
|
+
yield { history, droppedTurns: last.droppedTurns };
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
function compactableTools(history, isBoundary) {
|
|
@@ -114,5 +116,6 @@ export class ContextWindow {
|
|
|
114
116
|
static compactContent = compactContent;
|
|
115
117
|
static compactedFrom = compactedFrom;
|
|
116
118
|
static contextCandidates = contextCandidates;
|
|
119
|
+
static contextCandidateIterator = contextCandidateIterator;
|
|
117
120
|
static responseRoomChars = responseRoomChars;
|
|
118
121
|
}
|