@qvac/harness 1.0.0-rc.16 → 1.0.0-rc.18
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 +139 -2
- package/dist-lib/index.d.ts +6 -2
- package/dist-lib/index.js +17 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +28 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +1 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +13 -8
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +6 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +2 -2
- package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/durable.js +7 -1
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/operations.js +28 -9
- package/dist-lib/lib/capabilities/completion-engine/ports.js +3 -2
- package/dist-lib/lib/capabilities/completion-engine/prepare-step.d.ts +3 -1
- package/dist-lib/lib/capabilities/completion-engine/session.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/session.js +1 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +2 -1
- package/dist-lib/lib/capabilities/completion-engine/turns.js +5 -2
- package/dist-lib/lib/capabilities/enhance.js +3 -3
- package/dist-lib/lib/capabilities/sdk-tool.d.ts +1 -1
- package/dist-lib/lib/capabilities/sdk-tool.js +3 -2
- package/dist-lib/lib/capabilities/skill-entry.d.ts +9 -1
- package/dist-lib/lib/capabilities/skill-entry.js +11 -7
- package/dist-lib/lib/capabilities/tool-turns.d.ts +5 -0
- package/dist-lib/lib/capabilities/tool-turns.js +24 -27
- package/dist-lib/lib/client/index.js +3 -2
- package/dist-lib/lib/connect.d.ts +2 -0
- package/dist-lib/lib/connect.js +33 -3
- package/dist-lib/lib/contract/completion.d.ts +14 -0
- package/dist-lib/lib/contract/exec.d.ts +1 -0
- package/dist-lib/lib/contract/ocr.d.ts +4 -0
- package/dist-lib/lib/contract/run.d.ts +8 -0
- package/dist-lib/lib/contract-types.d.ts +4 -1
- package/dist-lib/lib/errors.d.ts +4 -0
- package/dist-lib/lib/errors.js +5 -1
- package/dist-lib/lib/guards.d.ts +2 -0
- package/dist-lib/lib/guards.js +7 -0
- package/dist-lib/lib/hardware/capability-probe.js +10 -7
- package/dist-lib/lib/hardware/gpu-probe-addon.js +26 -11
- package/dist-lib/lib/hardware/gpu-stats.native.cjs +17 -1
- package/dist-lib/lib/helpers/completion-params.d.ts +2 -1
- package/dist-lib/lib/helpers/completion-params.js +16 -1
- package/dist-lib/lib/helpers/control-tokens.d.ts +3 -0
- package/dist-lib/lib/helpers/control-tokens.js +25 -0
- package/dist-lib/lib/machine/completion/actions/completion.js +34 -5
- package/dist-lib/lib/machine/completion/actions/tools.js +4 -1
- package/dist-lib/lib/machine/completion/rules.d.ts +2 -0
- package/dist-lib/lib/machine/completion/rules.js +7 -0
- package/dist-lib/lib/machine/completion/types.d.ts +6 -0
- package/dist-lib/lib/machine/index.d.ts +2 -1
- package/dist-lib/lib/machine/index.js +2 -1
- package/dist-lib/lib/no-redirect-fetch-impl.d.ts +1 -1
- package/dist-lib/lib/no-redirect-fetch-impl.js +13 -7
- 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/plugins/registry.js +15 -1
- package/dist-lib/lib/plugins/require-bare.d.ts +1 -0
- package/dist-lib/lib/plugins/require-bare.js +13 -0
- package/dist-lib/lib/run-log/request-codec.js +2 -2
- package/dist-lib/lib/serve.js +38 -1
- package/dist-lib/lib/sidecar/index.d.ts +1 -1
- package/dist-lib/lib/sidecar/index.js +5 -6
- package/dist-lib/lib/skills-host/index.js +13 -8
- package/dist-lib/lib/spawn.d.ts +2 -0
- package/dist-lib/lib/spawn.js +5 -3
- package/dist-lib/lib/tools/ask-user.d.ts +2 -0
- package/dist-lib/lib/tools/ask-user.js +137 -0
- package/dist-lib/lib/tools/attachments/delivered.d.ts +5 -0
- package/dist-lib/lib/tools/attachments/delivered.js +16 -0
- package/dist-lib/lib/tools/attachments/fetched-file.d.ts +32 -0
- package/dist-lib/lib/tools/attachments/fetched-file.js +134 -0
- package/dist-lib/lib/tools/exec.js +2 -1
- package/dist-lib/lib/tools/fs/document-text.js +3 -26
- package/dist-lib/lib/tools/http-request/request.d.ts +2 -2
- package/dist-lib/lib/tools/http-request/request.js +1 -1
- package/dist-lib/lib/tools/http-request.d.ts +1 -0
- package/dist-lib/lib/tools/http-request.js +54 -3
- package/dist-lib/lib/tools/index.d.ts +3 -1
- package/dist-lib/lib/tools/index.js +6 -2
- package/dist-lib/lib/tools/office.js +20 -12
- package/dist-lib/lib/tools/pdf/pages.d.ts +12 -0
- package/dist-lib/lib/tools/pdf/pages.js +28 -0
- package/dist-lib/lib/tools/pdf.js +24 -9
- 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/lib/tools/skills/scope-key.d.ts +1 -0
- package/dist-lib/lib/tools/skills/scope-key.js +4 -0
- package/dist-lib/lib/tools/web-fetch.js +41 -130
- package/dist-lib/plugins/knowledge/index.js +3 -3
- package/dist-lib/plugins/mcp/call.js +5 -1
- package/dist-lib/plugins/mcp/protocol.d.ts +6 -1
- package/dist-lib/plugins/mcp/protocol.js +2 -2
- package/dist-lib/plugins/ocr/reading-order.js +151 -4
- package/dist-lib/plugins/python/bare-floor.d.ts +1 -0
- package/dist-lib/plugins/python/bare-floor.js +2 -0
- package/dist-lib/plugins/python/index.d.ts +1 -0
- package/dist-lib/plugins/python/index.js +1 -0
- package/dist-lib/plugins/python/language.js +9 -8
- package/dist-lib/plugins/python/python-adapter.d.ts +4 -0
- package/dist-lib/plugins/python/python-adapter.js +26 -0
- package/dist-lib/plugins/python/worker/client.js +1 -1
- package/dist-lib/plugins/python/worker/entry.js +2 -8
- package/dist-lib/plugins/python/worker/preload.d.ts +1 -0
- package/dist-lib/plugins/python/worker/preload.js +2 -0
- package/dist-lib/plugins/python/worker/spawn.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/weather/lookup.js +1 -0
- package/dist-lib/schema/harness.js +17 -0
- 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 +32 -0
- package/dist-lib/spec/hyperschema/index.js +32 -0
- package/dist-lib/spec/hyperschema/schema.json +40 -0
- package/dist-lib/spec/hyperschema/types.d.ts +12 -0
- package/package.json +18 -9
|
@@ -19,7 +19,7 @@ import { skillStep } from './actors/skill-step.js';
|
|
|
19
19
|
import { streaming } from './actors/streaming.js';
|
|
20
20
|
import { wrapUp } from './actors/wrap-up.js';
|
|
21
21
|
import { toolContext } from './actors/execution-plan.js';
|
|
22
|
-
import { capabilityPolicy, captureFacts, restoreFacts, schemaDigest } from './durable.js';
|
|
22
|
+
import { capabilityPolicy, captureFacts, laterDelivered, restoreFacts, schemaDigest } from './durable.js';
|
|
23
23
|
import { bindOperations, toolOperationFacts } from './operations.js';
|
|
24
24
|
import { loadedSkills } from './session.js';
|
|
25
25
|
import { errorMessage, isRecord } from '../../guards.js';
|
|
@@ -79,7 +79,8 @@ export function completionPorts(deps) {
|
|
|
79
79
|
backends: recorded.backends.length > currentBackends.length ? recorded.backends : currentBackends,
|
|
80
80
|
runBudget: {
|
|
81
81
|
...currentBudget,
|
|
82
|
-
outputBytesUsed: Math.max(typeof currentBudget.outputBytesUsed === 'number' ? currentBudget.outputBytesUsed : 0, recorded.runBudget.outputBytesUsed)
|
|
82
|
+
outputBytesUsed: Math.max(typeof currentBudget.outputBytesUsed === 'number' ? currentBudget.outputBytesUsed : 0, recorded.runBudget.outputBytesUsed),
|
|
83
|
+
delivered: laterDelivered(Array.isArray(currentBudget.delivered) ? currentBudget.delivered : undefined, recorded.runBudget.delivered)
|
|
83
84
|
},
|
|
84
85
|
outcome: {
|
|
85
86
|
...currentOutcome,
|
|
@@ -21,7 +21,9 @@ export interface PrepareStepSource {
|
|
|
21
21
|
readonly label: string;
|
|
22
22
|
propose(deps: CompletionDeps, agent: ResolvedAgent<CompletionSkillEntry>): PrepareCall | null;
|
|
23
23
|
display(deps: CompletionDeps, step: PrepareStep): ToolCallDisplay;
|
|
24
|
-
refusal?(deps: CompletionDeps, step: PrepareStep):
|
|
24
|
+
refusal?(deps: CompletionDeps, step: PrepareStep): {
|
|
25
|
+
readonly error: string;
|
|
26
|
+
} | null;
|
|
25
27
|
settle(input: PrepareSettleInput): PrepareRunOutput;
|
|
26
28
|
fail(input: PrepareFailInput): PrepareFailure;
|
|
27
29
|
}
|
|
@@ -19,6 +19,7 @@ export interface Session extends InvokeTracker {
|
|
|
19
19
|
outbound: OutboundGuard;
|
|
20
20
|
enabled: ToolDefinition[];
|
|
21
21
|
sdkTools: SdkTool[] | undefined;
|
|
22
|
+
grantable: ReadonlySet<string>;
|
|
22
23
|
grantedOps: Map<string, CliValidator[]>;
|
|
23
24
|
behaviorDigest: string;
|
|
24
25
|
activation: SkillActivation;
|
|
@@ -2,6 +2,7 @@ import { HookHalt, RecoveryRequired } from '../../helpers/engine-error.js';
|
|
|
2
2
|
import { AbortedError, raceAbort } from '../../helpers/race-abort.js';
|
|
3
3
|
import { errorCode, errorMessage, isRecord } from '../../guards.js';
|
|
4
4
|
import { detachJson } from '../../helpers/detach-json.js';
|
|
5
|
+
import { mapStrings, restoreTemplateTokens } from '../../helpers/control-tokens.js';
|
|
5
6
|
import { clipRawCall, normalizeToolArgs } from '../../helpers/tool-call-markup.js';
|
|
6
7
|
import { INTENT_PARAM, takeToolIntent } from '../../helpers/tool-intent.js';
|
|
7
8
|
import { withHookContext } from '../tool-turns.js';
|
|
@@ -228,7 +229,7 @@ export async function executeCall(tool, args, ctx, { runId, deniedMessage, appro
|
|
|
228
229
|
}
|
|
229
230
|
let output;
|
|
230
231
|
let outcome = { kind: 'success' };
|
|
231
|
-
const toolArgs = detachJson(args);
|
|
232
|
+
const toolArgs = mapStrings(detachJson(args), restoreTemplateTokens);
|
|
232
233
|
try {
|
|
233
234
|
output = await tool.execute(toolArgs, { ...ctx, signal, runId, callId, approval: decision });
|
|
234
235
|
HarnessLog.debug('tool done', { tool: tool.name });
|
|
@@ -22,6 +22,9 @@ function originOfToolTurn(text) {
|
|
|
22
22
|
return text.startsWith(`[Tool: ${Agent.SKILL_TOOL_NAME} (`) ? 'skill' : 'tool-result';
|
|
23
23
|
}
|
|
24
24
|
export function sanitizeTurn(turn, answered = false) {
|
|
25
|
+
if (turn.role === 'tool') {
|
|
26
|
+
return turn;
|
|
27
|
+
}
|
|
25
28
|
const stripped = stripControlTokens(turn.content);
|
|
26
29
|
const content = turn.role === 'assistant' && !answered ? stripToolCallMarkup(stripped) : stripped;
|
|
27
30
|
return content === turn.content ? turn : { ...turn, content };
|
|
@@ -63,7 +66,7 @@ function preloadTurns({ messages, at, nudge, consumed }) {
|
|
|
63
66
|
}
|
|
64
67
|
return [
|
|
65
68
|
{ role: 'assistant', content: assistantToolTurn('', [call]) },
|
|
66
|
-
|
|
69
|
+
{ role: 'tool', content: toolResultTurn(call.name, call.id, output) },
|
|
67
70
|
{
|
|
68
71
|
role: 'user',
|
|
69
72
|
content: typeof output.mention === 'string' ? skillMentionNudge(output.mention) : nudge
|
|
@@ -99,7 +102,7 @@ function modelTurn(turn, answered) {
|
|
|
99
102
|
}
|
|
100
103
|
if (isReplayedResult(turn)) {
|
|
101
104
|
const content = replayedResult(turn.name, turn.toolCallId, turn.content);
|
|
102
|
-
return
|
|
105
|
+
return { role: 'tool', content };
|
|
103
106
|
}
|
|
104
107
|
return sanitizeTurn(turn, answered);
|
|
105
108
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { completionParams } from '../helpers/completion-params.js';
|
|
1
2
|
import { cleanAnswer } from '../helpers/clean-answer.js';
|
|
2
3
|
import { raceAbort } from '../helpers/race-abort.js';
|
|
3
4
|
import { withoutRepeatedReply } from '../helpers/repeated-reply.js';
|
|
@@ -23,15 +24,14 @@ export async function expandImagePrompt(sdk, prompt, options) {
|
|
|
23
24
|
return { text, model: options.model, totalTokens: final.stats?.generatedTokens };
|
|
24
25
|
}
|
|
25
26
|
async function rewrite(sdk, prompt, { modelId, signal }) {
|
|
26
|
-
const run = withoutRepeatedReply(sdk.completion({
|
|
27
|
+
const run = withoutRepeatedReply(sdk.completion(completionParams({
|
|
27
28
|
modelId,
|
|
28
29
|
history: [
|
|
29
30
|
{ role: 'system', content: SYSTEM },
|
|
30
31
|
{ role: 'user', content: prompt }
|
|
31
32
|
],
|
|
32
|
-
stream: true,
|
|
33
33
|
generationParams: { temp: 0.7, reasoning_budget: 0 }
|
|
34
|
-
}));
|
|
34
|
+
})));
|
|
35
35
|
try {
|
|
36
36
|
return await raceAbort(run.final, signal);
|
|
37
37
|
}
|
|
@@ -4,7 +4,7 @@ export declare const TOOL_SEARCH_TOOL_NAME: string;
|
|
|
4
4
|
export declare function defers(tool: ToolDefinition): boolean;
|
|
5
5
|
export declare function deferredForRun(tool: ToolDefinition): ToolDefinition;
|
|
6
6
|
export declare function toSdkTool(tool: ToolDefinition): SdkTool;
|
|
7
|
-
export declare function toSdkTools(tools: readonly ToolDefinition[]): SdkTool[] | undefined;
|
|
7
|
+
export declare function toSdkTools(tools: readonly ToolDefinition[], callable?: ReadonlySet<string>): SdkTool[] | undefined;
|
|
8
8
|
export declare function renderedTools(tools: SdkTool[] | undefined, history: readonly CompletionHistoryEntry[]): SdkTool[] | undefined;
|
|
9
9
|
export declare function loadedTools(history: readonly CompletionHistoryEntry[]): Set<string>;
|
|
10
10
|
export declare function loadTurns(sent: readonly SdkTool[] | undefined, names: Iterable<string>, history: readonly CompletionHistoryEntry[]): Message[];
|
|
@@ -97,9 +97,10 @@ export function toSdkTool(tool) {
|
|
|
97
97
|
const group = tool.group ?? tool.owningSkill ?? tool.toolset ?? undefined;
|
|
98
98
|
return defers(tool) ? { ...sent, deferLoading: true, group } : sent;
|
|
99
99
|
}
|
|
100
|
-
export function toSdkTools(tools) {
|
|
100
|
+
export function toSdkTools(tools, callable) {
|
|
101
101
|
const searching = tools.some(defers);
|
|
102
|
-
const
|
|
102
|
+
const waits = (tool) => tool.skillGated === true && callable?.has(tool.name) === false;
|
|
103
|
+
const sent = tools.filter((tool) => (!searching || tool.name !== TOOL_SEARCH_NAME) && !waits(tool));
|
|
103
104
|
return sent.length ? sent.map((tool) => toSdkTool(tool)) : undefined;
|
|
104
105
|
}
|
|
105
106
|
export function renderedTools(tools, history) {
|
|
@@ -6,7 +6,15 @@ export type CompletionSkillEntry = SkillCatalogEntry & {
|
|
|
6
6
|
};
|
|
7
7
|
export declare function skillInContext(entry: CompletionSkillEntry): boolean;
|
|
8
8
|
export declare function unreadySkillState(name: string, catalog: readonly CompletionSkillEntry[]): SkillState | null;
|
|
9
|
-
export
|
|
9
|
+
export interface UnreadySkillSetup {
|
|
10
|
+
readonly skill: string;
|
|
11
|
+
readonly state: string;
|
|
12
|
+
}
|
|
13
|
+
export interface UnreadySkillRefusal {
|
|
14
|
+
readonly error: string;
|
|
15
|
+
readonly setup?: UnreadySkillSetup;
|
|
16
|
+
}
|
|
17
|
+
export declare function unreadySkillRefusal(name: string, state: string): UnreadySkillRefusal;
|
|
10
18
|
export declare function fixableInSkills(entry: CompletionSkillEntry): boolean;
|
|
11
19
|
export declare function promptSkill(entry: CompletionSkillEntry): PromptSkill;
|
|
12
20
|
export declare function mentionHandle(entry: CompletionSkillEntry): string;
|
|
@@ -7,17 +7,21 @@ export function unreadySkillState(name, catalog) {
|
|
|
7
7
|
const status = catalog.find((entry) => entry.name === name)?.status;
|
|
8
8
|
return status !== undefined && !isAvailableState(status) ? status : null;
|
|
9
9
|
}
|
|
10
|
-
export function unreadySkillMessage(name, state) {
|
|
11
|
-
if (state === SKILL_STATE.incompatibleModel) {
|
|
12
|
-
return `skill "${name}" needs a larger model than the one loaded. Tell the user to pick a larger model to use it; do not retry.`;
|
|
13
|
-
}
|
|
14
|
-
return (`skill "${name}" is ${state} and cannot be used yet. Tell the user to ${unreadyRemedy(state)}, ` +
|
|
15
|
-
`and do not do this task with another tool.`);
|
|
16
|
-
}
|
|
17
10
|
const FIXABLE_STATES = new Set([
|
|
18
11
|
SKILL_STATE.disconnected,
|
|
19
12
|
SKILL_STATE.needsSetup
|
|
20
13
|
]);
|
|
14
|
+
export function unreadySkillRefusal(name, state) {
|
|
15
|
+
const error = unreadySkillMessage(name, state);
|
|
16
|
+
return FIXABLE_STATES.has(state) ? { error, setup: { skill: name, state } } : { error };
|
|
17
|
+
}
|
|
18
|
+
function unreadySkillMessage(name, state) {
|
|
19
|
+
if (state === SKILL_STATE.incompatibleModel) {
|
|
20
|
+
return `skill "${name}" needs a larger model than the one loaded. Tell the user to pick a larger model to use it; do not retry.`;
|
|
21
|
+
}
|
|
22
|
+
return (`skill "${name}" is ${state} and cannot be used yet. Tell the user once, in one sentence, to ` +
|
|
23
|
+
`${unreadyRemedy(state)}. Name no other menu or settings path, and do not do this task with another tool.`);
|
|
24
|
+
}
|
|
21
25
|
export function fixableInSkills(entry) {
|
|
22
26
|
return entry.status !== undefined && FIXABLE_STATES.has(entry.status);
|
|
23
27
|
}
|
|
@@ -42,6 +42,11 @@ export interface FailureTurn extends FailureResultValue {
|
|
|
42
42
|
}
|
|
43
43
|
export declare function redactFailureTurns(history: readonly SdkMessage[], failures: readonly FailureTurn[], redact: <Value>(value: Value) => Value): SdkMessage[];
|
|
44
44
|
export declare function skillLoadedTurn(name: string, id?: string): string;
|
|
45
|
+
export interface AttachedFile {
|
|
46
|
+
attachmentId: string;
|
|
47
|
+
fileName: string;
|
|
48
|
+
}
|
|
49
|
+
export declare function attachedFiles(result: unknown): AttachedFile[];
|
|
45
50
|
export declare function attachmentTurn(name: string, result: unknown): string | null;
|
|
46
51
|
export declare function loadedSkillsFrom(messages: readonly Message[]): Set<string>;
|
|
47
52
|
export declare function loadedSkillFilesFrom(messages: readonly Message[]): Map<string, Set<string>>;
|
|
@@ -4,6 +4,7 @@ import { headTail } from '../helpers/head-tail.js';
|
|
|
4
4
|
import { MALFORMED_CALL_ID } from '../helpers/tool-call-markup.js';
|
|
5
5
|
import { MAX_GOAL_CHECKS } from '../helpers/goal-check.js';
|
|
6
6
|
import { compactContent } from '../context-window.js';
|
|
7
|
+
import { defuseTemplateTokens } from '../helpers/control-tokens.js';
|
|
7
8
|
import { TOOL_SEARCH_TOOL_NAME } from './sdk-tool.js';
|
|
8
9
|
import { isFailureResultReference, readFailureResult } from '../helpers/failure-result.js';
|
|
9
10
|
import { TOOL_FAILED_NOTE } from './tool-failed-note.js';
|
|
@@ -166,10 +167,8 @@ export function redactFailureTurns(history, failures, redact) {
|
|
|
166
167
|
const out = [...history];
|
|
167
168
|
for (const { at, name, callId, result, compactedTo } of redact(failures)) {
|
|
168
169
|
const content = toolResultTurn(name, callId, readFailureResult(result));
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
content: compactedTo === undefined ? content : compactContent(content, compactedTo)
|
|
172
|
-
};
|
|
170
|
+
const sent = compactedTo === undefined ? content : compactContent(content, compactedTo);
|
|
171
|
+
out[at] = { role: 'tool', content: defuseTemplateTokens(sent) };
|
|
173
172
|
}
|
|
174
173
|
return out;
|
|
175
174
|
}
|
|
@@ -179,41 +178,39 @@ export function skillLoadedTurn(name, id = DIRECT_CALL_ID) {
|
|
|
179
178
|
content: `${name} was loaded in an earlier turn but its instructions are not in this context. Call the skill tool with this name again before doing its work.`
|
|
180
179
|
});
|
|
181
180
|
}
|
|
182
|
-
function
|
|
183
|
-
if (!value || typeof value !== '
|
|
181
|
+
function attachedFile(value) {
|
|
182
|
+
if (!isRecord(value) || typeof value.attachmentId !== 'string') {
|
|
184
183
|
return null;
|
|
185
184
|
}
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
const fileName = typeof value.fileName === 'string' ? value.fileName : '';
|
|
186
|
+
return { attachmentId: value.attachmentId, fileName };
|
|
187
|
+
}
|
|
188
|
+
export function attachedFiles(result) {
|
|
189
|
+
const direct = attachedFile(result);
|
|
190
|
+
if (direct) {
|
|
191
|
+
return [direct];
|
|
188
192
|
}
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
const listed = isRecord(result) ? result.attachments : undefined;
|
|
194
|
+
return Array.isArray(listed) ? listed.flatMap((entry) => attachedFile(entry) ?? []) : [];
|
|
195
|
+
}
|
|
196
|
+
function refFrom({ attachmentId, fileName }) {
|
|
197
|
+
const ref = { attachmentId };
|
|
198
|
+
const dot = fileName.lastIndexOf('.');
|
|
192
199
|
if (dot > 0) {
|
|
193
|
-
ref.type =
|
|
200
|
+
ref.type = fileName.slice(dot + 1).toLowerCase();
|
|
194
201
|
}
|
|
195
202
|
return ref;
|
|
196
203
|
}
|
|
197
204
|
export function attachmentTurn(name, result) {
|
|
198
|
-
const direct =
|
|
205
|
+
const direct = attachedFile(result);
|
|
199
206
|
if (direct) {
|
|
200
|
-
return toolResultTurn(name, DIRECT_CALL_ID, direct);
|
|
201
|
-
}
|
|
202
|
-
const listed = isRecord(result) ? result.attachments : undefined;
|
|
203
|
-
if (!Array.isArray(listed)) {
|
|
204
|
-
return null;
|
|
205
|
-
}
|
|
206
|
-
const refs = [];
|
|
207
|
-
for (const entry of listed) {
|
|
208
|
-
const ref = refFrom(entry);
|
|
209
|
-
if (ref) {
|
|
210
|
-
refs.push(ref);
|
|
211
|
-
}
|
|
207
|
+
return toolResultTurn(name, DIRECT_CALL_ID, refFrom(direct));
|
|
212
208
|
}
|
|
213
|
-
|
|
209
|
+
const files = attachedFiles(result);
|
|
210
|
+
if (!files.length) {
|
|
214
211
|
return null;
|
|
215
212
|
}
|
|
216
|
-
return toolResultTurn(name, DIRECT_CALL_ID, { attachments:
|
|
213
|
+
return toolResultTurn(name, DIRECT_CALL_ID, { attachments: files.map(refFrom) });
|
|
217
214
|
}
|
|
218
215
|
export function loadedSkillsFrom(messages) {
|
|
219
216
|
const loaded = new Set();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { harnessClient } from '../../spec/calls.js';
|
|
2
2
|
import HRPC from '../../spec/hrpc/index.js';
|
|
3
3
|
import { encode } from '../../spec/hrpc/messages.js';
|
|
4
|
-
import { errorMessage, isRecord } from '../guards.js';
|
|
4
|
+
import { errorMessage, isAskForm, isRecord } from '../guards.js';
|
|
5
5
|
import { addonTaskType } from '../models/model-task.js';
|
|
6
6
|
import { pushQueue } from '../queue.js';
|
|
7
7
|
import { settleOnClose } from '../rpc-session.js';
|
|
@@ -234,7 +234,8 @@ function answerQuestion(event, askUser, send) {
|
|
|
234
234
|
void Promise.resolve()
|
|
235
235
|
.then(() => askUser({
|
|
236
236
|
question: event.question ?? '',
|
|
237
|
-
options: Array.isArray(event.options) ? event.options.map(String) : undefined
|
|
237
|
+
options: Array.isArray(event.options) ? event.options.map(String) : undefined,
|
|
238
|
+
form: isAskForm(event.payload) ? event.payload : undefined
|
|
238
239
|
}))
|
|
239
240
|
.then((answer) => send({ type: 'question-result', callId, answer: answer ?? '' }), (err) => send({ type: 'question-result', callId, message: errorMessage(err) }));
|
|
240
241
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
2
|
import { type Transport } from './rpc-session.ts';
|
|
3
3
|
import { type KvCacheDeletionResult } from './capabilities/kv-cache.ts';
|
|
4
|
+
import type { OcrReadContext } from './contract/ocr.ts';
|
|
4
5
|
import type { CustomModelEntry } from './models/model-catalog.ts';
|
|
5
6
|
import { type ModelSourcePreview, type PreviewModelSourceContext } from './capabilities/preview-model-source.ts';
|
|
6
7
|
import type { CapabilityInfo, CompletionContext, CredentialEntry, DetectedLanguage, DetectLanguageContext, DownloadContext, EmbedContext, HarnessContract, HarnessDiagnostics, HarnessEvent, HarnessInfo, HostContext, InfraModel, InvokeContext, ListModelsOptions, ModelInfo, ResolvedSkillCatalogEntry, SkillsOptions, SkillWriteResult, SpeakContext, SpeakResult, SpeakStreamContext, ToolCatalogEntry, TranscribeContext, LoadModelContext, LoadModelResult, MemoryUsage, UnloadModelContext, UnloadModelResult, WarmModelContext, DownloadsAllowedOptions } from './contract-types.ts';
|
|
@@ -39,6 +40,7 @@ export declare class RemoteHarness extends EventEmitter implements HarnessContra
|
|
|
39
40
|
download(context: HostContext<DownloadContext>): AsyncIterable<HarnessEvent>;
|
|
40
41
|
embed(context: HostContext<EmbedContext>): Promise<number[][]>;
|
|
41
42
|
transcribe(context: HostContext<TranscribeContext>): Promise<string>;
|
|
43
|
+
ocrRead(context: HostContext<OcrReadContext>): Promise<string>;
|
|
42
44
|
detectLanguage(context: DetectLanguageContext): Promise<DetectedLanguage[]>;
|
|
43
45
|
speak(context: HostContext<SpeakContext>): Promise<SpeakResult>;
|
|
44
46
|
speakStream(context: HostContext<SpeakStreamContext>): AsyncIterable<SpeakResult>;
|
package/dist-lib/lib/connect.js
CHANGED
|
@@ -18,7 +18,7 @@ import { RoundHost } from './round-host.js';
|
|
|
18
18
|
import { HarnessLog } from './log.js';
|
|
19
19
|
import { assertEmbedDevice } from './models/embed-config.js';
|
|
20
20
|
import { addonTaskType } from './models/model-task.js';
|
|
21
|
-
import { errorCode, errorMessage, isRecord } from './guards.js';
|
|
21
|
+
import { errorCode, errorMessage, isAskForm, isRecord } from './guards.js';
|
|
22
22
|
import { pushQueue } from './queue.js';
|
|
23
23
|
import { stageFile, sweepStaging } from './staging.js';
|
|
24
24
|
import { sweepSpill } from './spill.js';
|
|
@@ -160,6 +160,9 @@ export class RemoteHarness extends EventEmitter {
|
|
|
160
160
|
if (context.roundCut) {
|
|
161
161
|
payload.roundCut = true;
|
|
162
162
|
}
|
|
163
|
+
if (context.showImage) {
|
|
164
|
+
payload.showImage = true;
|
|
165
|
+
}
|
|
163
166
|
if (context.maxToolRounds !== undefined && context.maxToolRounds !== 0) {
|
|
164
167
|
payload.maxToolRounds = checkMaxToolRounds(context.maxToolRounds);
|
|
165
168
|
}
|
|
@@ -428,7 +431,8 @@ export class RemoteHarness extends EventEmitter {
|
|
|
428
431
|
}
|
|
429
432
|
if (event.type === 'fetch-ask') {
|
|
430
433
|
const callId = event.callId;
|
|
431
|
-
|
|
434
|
+
const show = isRecord(event.payload) && event.payload.show === true;
|
|
435
|
+
void (show ? bridgeShow(event, context) : bridgeFetch(event, context, staged))
|
|
432
436
|
.then((frame) => {
|
|
433
437
|
if (closed) {
|
|
434
438
|
return reclaim();
|
|
@@ -625,6 +629,16 @@ export class RemoteHarness extends EventEmitter {
|
|
|
625
629
|
const response = await abortable(client.transcribe({ model: context.model, audio: context.audio }), context.signal);
|
|
626
630
|
return response.text;
|
|
627
631
|
}
|
|
632
|
+
async ocrRead(context) {
|
|
633
|
+
const { client } = await this._ensure();
|
|
634
|
+
const { width, height, data } = context.image;
|
|
635
|
+
const response = await abortable(client.ocrRead({
|
|
636
|
+
width,
|
|
637
|
+
height,
|
|
638
|
+
data: b4a.from(data.buffer, data.byteOffset, data.byteLength)
|
|
639
|
+
}), context.signal);
|
|
640
|
+
return response.text;
|
|
641
|
+
}
|
|
628
642
|
async detectLanguage(context) {
|
|
629
643
|
const { client } = await this._ensure();
|
|
630
644
|
const response = await client.detectLanguage({
|
|
@@ -1138,6 +1152,21 @@ async function bridgeAttach(event, attach) {
|
|
|
1138
1152
|
}
|
|
1139
1153
|
}
|
|
1140
1154
|
}
|
|
1155
|
+
async function bridgeShow(event, context) {
|
|
1156
|
+
if (!context.showImage) {
|
|
1157
|
+
return { type: 'fetch-result', message: 'the host cannot show images' };
|
|
1158
|
+
}
|
|
1159
|
+
try {
|
|
1160
|
+
const path = await context.showImage({
|
|
1161
|
+
attachmentId: event.attachmentId ?? '',
|
|
1162
|
+
signal: context.signal
|
|
1163
|
+
});
|
|
1164
|
+
return path ? { type: 'fetch-result', path } : { type: 'fetch-result' };
|
|
1165
|
+
}
|
|
1166
|
+
catch (err) {
|
|
1167
|
+
return { type: 'fetch-result', message: errorMessage(err) };
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1141
1170
|
async function bridgeFetch(event, context, staged) {
|
|
1142
1171
|
if (!context.fetchAttachment) {
|
|
1143
1172
|
return { type: 'fetch-result', message: 'the host cannot read attachments' };
|
|
@@ -1245,7 +1274,8 @@ function answerQuestion(event, { askUser, reply }) {
|
|
|
1245
1274
|
void Promise.resolve()
|
|
1246
1275
|
.then(() => askUser({
|
|
1247
1276
|
question: event.question ?? '',
|
|
1248
|
-
options: Array.isArray(event.options) ? event.options.map(String) : undefined
|
|
1277
|
+
options: Array.isArray(event.options) ? event.options.map(String) : undefined,
|
|
1278
|
+
form: isAskForm(event.payload) ? event.payload : undefined
|
|
1249
1279
|
}))
|
|
1250
1280
|
.then((answer) => reply({ type: 'question-result', callId, answer: answer ?? '' }), (err) => reply({ type: 'question-result', callId, message: errorMessage(err) }))
|
|
1251
1281
|
.catch((err) => HarnessLog.warn('question reply failed', { callId, message: errorMessage(err) }));
|
|
@@ -96,12 +96,25 @@ export type FetchAttachmentFn = (query: {
|
|
|
96
96
|
signal?: BareAbortSignal;
|
|
97
97
|
meta?: boolean;
|
|
98
98
|
}) => Promise<FetchedAttachment | AttachmentMeta | null>;
|
|
99
|
+
export type ShowImageFn = (query: {
|
|
100
|
+
attachmentId: string;
|
|
101
|
+
signal?: BareAbortSignal;
|
|
102
|
+
}) => Promise<string | null>;
|
|
99
103
|
export type ProgressFn = (update: {
|
|
100
104
|
percentage: number;
|
|
101
105
|
} | null) => void;
|
|
106
|
+
export type AskFieldType = 'single' | 'multiple' | 'date' | 'text' | 'note' | 'number';
|
|
107
|
+
export interface AskField {
|
|
108
|
+
id: string;
|
|
109
|
+
label: string;
|
|
110
|
+
type: AskFieldType;
|
|
111
|
+
options?: string[];
|
|
112
|
+
required?: boolean;
|
|
113
|
+
}
|
|
102
114
|
export type AskUserFn = (question: {
|
|
103
115
|
question: string;
|
|
104
116
|
options?: string[];
|
|
117
|
+
form?: AskField[];
|
|
105
118
|
}) => Promise<string | null>;
|
|
106
119
|
export interface ToolFetchInit {
|
|
107
120
|
method?: string;
|
|
@@ -161,6 +174,7 @@ export interface ToolExecuteContext {
|
|
|
161
174
|
uncappedResponse?: boolean | undefined;
|
|
162
175
|
policy?: CompiledPolicy | undefined;
|
|
163
176
|
toolNames?: readonly string[] | undefined;
|
|
177
|
+
offeredTools?: readonly string[] | undefined;
|
|
164
178
|
approval?: ToolDecision | undefined;
|
|
165
179
|
fetch?: ToolFetch | undefined;
|
|
166
180
|
knowledge?: KnowledgeGrant | undefined;
|
|
@@ -97,6 +97,7 @@ export interface ExecScope {
|
|
|
97
97
|
export interface ExecValidateScope extends ExecScope {
|
|
98
98
|
readonly trusted: boolean;
|
|
99
99
|
readonly toolNames?: readonly string[] | undefined;
|
|
100
|
+
readonly offeredTools?: readonly string[] | undefined;
|
|
100
101
|
}
|
|
101
102
|
export interface LanguageRun {
|
|
102
103
|
readonly args: Record<string, unknown>;
|
|
@@ -3,6 +3,14 @@ export interface RunBudget {
|
|
|
3
3
|
readonly totalMs?: number | undefined;
|
|
4
4
|
outputBytesUsed: number;
|
|
5
5
|
responseRoomChars?: number | undefined;
|
|
6
|
+
delivered?: readonly DeliveredFile[] | undefined;
|
|
7
|
+
}
|
|
8
|
+
export interface DeliveredFile {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly sha256: string;
|
|
11
|
+
readonly attachmentId: string;
|
|
12
|
+
readonly fileName: string;
|
|
13
|
+
readonly byteLength: number;
|
|
6
14
|
}
|
|
7
15
|
export interface HistoryToolCall {
|
|
8
16
|
id: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
|
|
2
2
|
import type { HarnessCapabilityProfile } from '../spec/hyperschema/types.d.ts';
|
|
3
|
-
import type { AccessPolicy, AgentHandoff, ApproveFn, AskUserFn, AttachFn, FetchAttachmentFn, HistoryToolCall, ProgressFn, ResourceDescriptor, ResponseFormat } from './contract/index.ts';
|
|
3
|
+
import type { AccessPolicy, AgentHandoff, ApproveFn, AskUserFn, AttachFn, FetchAttachmentFn, HistoryToolCall, ProgressFn, ResourceDescriptor, ResponseFormat, ShowImageFn } from './contract/index.ts';
|
|
4
4
|
import type { KvCacheDeletionResult } from './capabilities/kv-cache.ts';
|
|
5
5
|
import type { ModelRoundIo, ModelRoundPort, ModelRoundRequest, ModelRoundResult } from './capabilities/completion-engine/index.ts';
|
|
6
6
|
import type { ModelSourcePreview, PreviewModelSourceContext } from './capabilities/preview-model-source.ts';
|
|
@@ -13,6 +13,7 @@ import type { ListModelsOptions, ModelInfo } from './models/model-list.ts';
|
|
|
13
13
|
import type { ToolCatalogEntry } from './tools/catalog.ts';
|
|
14
14
|
import type { ManagedSkill, SkillFileContent } from './tools/skills/overlay-crud.ts';
|
|
15
15
|
import type { DriveOpFn, GrantedDrive } from './tools/fs/remote-protocol.ts';
|
|
16
|
+
import type { OcrReadContext } from './contract/ocr.ts';
|
|
16
17
|
import type { SpeakResult } from './contract/speech.ts';
|
|
17
18
|
import type { RunInput } from './contract/completion.ts';
|
|
18
19
|
import type { RunGoal, TurnContext } from './contract/run.ts';
|
|
@@ -89,6 +90,7 @@ export interface CompletionContext {
|
|
|
89
90
|
approve?: (call: ApprovalCall) => Promise<boolean>;
|
|
90
91
|
attach?: AttachFn;
|
|
91
92
|
fetchAttachment?: FetchAttachmentFn;
|
|
93
|
+
showImage?: ShowImageFn;
|
|
92
94
|
progress?: ProgressFn;
|
|
93
95
|
askUser?: AskUserFn;
|
|
94
96
|
runLog?: HostRunLog;
|
|
@@ -264,6 +266,7 @@ export interface HarnessContract {
|
|
|
264
266
|
describe?(): Promise<HarnessInfo | null> | HarnessInfo;
|
|
265
267
|
embed?(context: EmbedContext): Promise<number[][]>;
|
|
266
268
|
transcribe?(context: TranscribeContext): Promise<string>;
|
|
269
|
+
ocrRead?(context: OcrReadContext): Promise<string>;
|
|
267
270
|
detectLanguage?(context: DetectLanguageContext): DetectedLanguage[] | Promise<DetectedLanguage[]>;
|
|
268
271
|
speak?(context: SpeakContext): Promise<SpeakResult>;
|
|
269
272
|
speakStream?(context: SpeakStreamContext): AsyncIterable<SpeakResult>;
|
package/dist-lib/lib/errors.d.ts
CHANGED
|
@@ -248,6 +248,10 @@ declare const HARNESS_ERRORS: {
|
|
|
248
248
|
readonly code: 102711;
|
|
249
249
|
readonly message: () => string;
|
|
250
250
|
};
|
|
251
|
+
readonly BUNDLED_SKILLS_HASH_INVALID: {
|
|
252
|
+
readonly code: 102712;
|
|
253
|
+
readonly message: (hash: string) => string;
|
|
254
|
+
};
|
|
251
255
|
};
|
|
252
256
|
type Errors = typeof HARNESS_ERRORS;
|
|
253
257
|
export type HarnessErrorName = keyof Errors;
|
package/dist-lib/lib/errors.js
CHANGED
|
@@ -180,7 +180,11 @@ const HARNESS_ERRORS = {
|
|
|
180
180
|
message: () => 'cannot fence the app storage root: the SDK home is unknown'
|
|
181
181
|
},
|
|
182
182
|
SLM_TRANSLATION_UNAVAILABLE: { code: 102710, message: () => 'slm translation is unavailable' },
|
|
183
|
-
PDF_TEXT_UNAVAILABLE: { code: 102711, message: () => 'PDF text is not available on this device' }
|
|
183
|
+
PDF_TEXT_UNAVAILABLE: { code: 102711, message: () => 'PDF text is not available on this device' },
|
|
184
|
+
BUNDLED_SKILLS_HASH_INVALID: {
|
|
185
|
+
code: 102712,
|
|
186
|
+
message: (hash) => `bundled skills hash ${hash} is not 16 hex characters`
|
|
187
|
+
}
|
|
184
188
|
};
|
|
185
189
|
addCodes(Object.fromEntries(Object.entries(HARNESS_ERRORS).map(([name, { code, message }]) => [code, { name, message }])), { name: '@qvac/harness', version: `${Object.keys(HARNESS_ERRORS).length}.0.0` });
|
|
186
190
|
export class HarnessError extends QvacErrorBase {
|
package/dist-lib/lib/guards.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { AskField } from './contract/index.ts';
|
|
1
2
|
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
2
3
|
export declare function errorMessage(err: unknown): string;
|
|
3
4
|
export declare function errorCode(err: unknown): string | undefined;
|
|
5
|
+
export declare function isAskForm(value: unknown): value is AskField[];
|
package/dist-lib/lib/guards.js
CHANGED
|
@@ -9,3 +9,10 @@ export function errorCode(err) {
|
|
|
9
9
|
return undefined;
|
|
10
10
|
return typeof err.code === 'string' ? err.code : undefined;
|
|
11
11
|
}
|
|
12
|
+
export function isAskForm(value) {
|
|
13
|
+
return (Array.isArray(value) &&
|
|
14
|
+
value.every((field) => isRecord(field) &&
|
|
15
|
+
typeof field.id === 'string' &&
|
|
16
|
+
typeof field.label === 'string' &&
|
|
17
|
+
typeof field.type === 'string'));
|
|
18
|
+
}
|
|
@@ -49,6 +49,11 @@ async function probeSysfs(reads) {
|
|
|
49
49
|
}
|
|
50
50
|
return null;
|
|
51
51
|
}
|
|
52
|
+
async function probeAmdVram(reads) {
|
|
53
|
+
const rocm = await reads.run('rocm-smi --showmeminfo vram');
|
|
54
|
+
const rocmBudget = rocm ? parseRocmSmiOutput(rocm) : null;
|
|
55
|
+
return rocmBudget ?? (await probeSysfs(reads));
|
|
56
|
+
}
|
|
52
57
|
async function probeDesktop(reads) {
|
|
53
58
|
const ram = reads.totalmem();
|
|
54
59
|
const addon = probeWithAddon(await reads.readGpuStats(), ram);
|
|
@@ -60,14 +65,12 @@ async function probeDesktop(reads) {
|
|
|
60
65
|
if (nvidiaBudget) {
|
|
61
66
|
return nvidiaBudget;
|
|
62
67
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (rocmBudget) {
|
|
66
|
-
return rocmBudget;
|
|
68
|
+
if (addon?.source === 'integrated') {
|
|
69
|
+
return addon;
|
|
67
70
|
}
|
|
68
|
-
const
|
|
69
|
-
if (
|
|
70
|
-
return
|
|
71
|
+
const amd = await probeAmdVram(reads);
|
|
72
|
+
if (amd) {
|
|
73
|
+
return amd;
|
|
71
74
|
}
|
|
72
75
|
const registry = await reads.run(`powershell -Command "${WINDOWS_REGISTRY_QUERY}"`);
|
|
73
76
|
const registryBudget = registry ? parseWindowsRegistryOutput(registry, ram) : null;
|