@qvac/harness 0.8.12 → 0.8.14
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 +101 -1
- package/dist-lib/index.js +9 -4
- package/dist-lib/lib/capabilities/completion.d.ts +6 -1
- package/dist-lib/lib/capabilities/completion.js +135 -66
- package/dist-lib/lib/capabilities/tool-turns.d.ts +1 -0
- package/dist-lib/lib/capabilities/tool-turns.js +14 -3
- package/dist-lib/lib/connect.js +3 -2
- package/dist-lib/lib/contract-types.d.ts +1 -0
- package/dist-lib/lib/hardware/cpu-placement.d.ts +8 -0
- package/dist-lib/lib/hardware/cpu-placement.js +48 -0
- package/dist-lib/lib/models/custom-model-cache.d.ts +1 -0
- package/dist-lib/lib/models/custom-model-cache.js +3 -0
- package/dist-lib/lib/models/gguf-header.d.ts +6 -0
- package/dist-lib/lib/models/gguf-header.js +38 -1
- package/dist-lib/lib/models/kv-cache.d.ts +2 -0
- package/dist-lib/lib/models/kv-cache.js +8 -0
- package/dist-lib/lib/models/llm-presets.d.ts +2 -1
- package/dist-lib/lib/models/model-handle.d.ts +1 -0
- package/dist-lib/lib/models/model-pool.d.ts +6 -1
- package/dist-lib/lib/models/model-pool.js +20 -8
- package/dist-lib/lib/no-redirect-fetch-impl.d.ts +1 -0
- package/dist-lib/lib/no-redirect-fetch-impl.js +32 -1
- package/dist-lib/lib/prompt.d.ts +6 -3
- package/dist-lib/lib/prompt.js +28 -17
- package/dist-lib/lib/serve.js +3 -2
- package/dist-lib/lib/tools/edit-image.js +4 -3
- package/dist-lib/lib/tools/exec/adapters/python/attachments.d.ts +1 -0
- package/dist-lib/lib/tools/exec/adapters/python/attachments.js +11 -0
- package/dist-lib/lib/tools/generate-image.js +4 -3
- package/dist-lib/lib/tools/http-request/request.d.ts +3 -1
- package/dist-lib/lib/tools/http-request/request.js +2 -1
- package/dist-lib/lib/tools/http-request/truncate-response.d.ts +17 -1
- package/dist-lib/lib/tools/http-request/truncate-response.js +51 -9
- package/dist-lib/lib/tools/http-request.js +12 -6
- package/dist-lib/lib/tools/office/ops.d.ts +1 -0
- package/dist-lib/lib/tools/office/ops.js +5 -1
- package/dist-lib/lib/tools/office.d.ts +1 -0
- package/dist-lib/lib/tools/office.js +151 -21
- package/dist-lib/lib/tools/operations/compile.js +4 -4
- package/dist-lib/lib/tools/skills/credential-check.d.ts +1 -0
- package/dist-lib/lib/tools/skills/credential-check.js +1 -0
- package/dist-lib/lib/tools/skills/manifest-parse.js +27 -3
- package/dist-lib/lib/tools/skills/manifest.d.ts +1 -0
- package/dist-lib/schema/harness.js +2 -1
- package/dist-lib/spec/hrpc/messages.js +8 -5
- package/dist-lib/spec/hyperschema/index.js +8 -5
- package/dist-lib/spec/hyperschema/schema.json +6 -1
- package/dist-lib/spec/hyperschema/types.d.ts +2 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,104 @@ While the major version is `0`, a breaking change bumps the minor version.
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.8.14] - 2026-10-26
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- A skill picked with `@` that cannot serve the request, or whose input is not
|
|
16
|
+
in the chat, now makes the model say so in one sentence instead of calling
|
|
17
|
+
tools to force it. (#643)
|
|
18
|
+
- A loaded skill's body reaches the model as text, not one JSON-escaped line,
|
|
19
|
+
so small models no longer copy `\"` into Mermaid blocks they write. (#639)
|
|
20
|
+
- An enabled skill that is `disconnected` or `needs-setup` stays listed with
|
|
21
|
+
its remedy, and an `@mention` or load of it returns that remedy, so the agent
|
|
22
|
+
tells the user to reconnect instead of improvising. The system prompt names
|
|
23
|
+
the host OS. (#638)
|
|
24
|
+
|
|
25
|
+
## [0.8.13] - 2026-10-23
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
- `ToolDefinition.deliversMany`, for a tool one request may call several times
|
|
30
|
+
for several files. A file it delivers gets the delivered-file nudge but does
|
|
31
|
+
not end the run one tool round later, so "draw a cat, a dog and a bird" made
|
|
32
|
+
one image per round still gets all three. `generate_image` and `edit_image`
|
|
33
|
+
set it. (#610)
|
|
34
|
+
- A skill whose oauth setup route has a `verify` probe and a `credentialKey`
|
|
35
|
+
gets that probe as its `requires.credentialChecks` entry for the key, when
|
|
36
|
+
the skill declares none, so a dead token reads as rejected instead of
|
|
37
|
+
needs-setup. A hand-written check still wins. A credential check may now
|
|
38
|
+
carry a `body`. A `verify` rule keyed on a response field (Spotify Premium)
|
|
39
|
+
still marks the token rejected in the health probe only on 401 or 403.
|
|
40
|
+
(#618)
|
|
41
|
+
- `sentAt` on a chat message, on the `@harness/message` wire type and the
|
|
42
|
+
contract `ChatMessage`: each user turn is stamped with its own send time,
|
|
43
|
+
and the stamp names the weekday. (#592)
|
|
44
|
+
|
|
45
|
+
### Changed
|
|
46
|
+
|
|
47
|
+
- **Breaking** for a host that reads `attachmentId` off a `generate_image` or
|
|
48
|
+
`edit_image` result, in a chat or from `invoke` with the `image` capability:
|
|
49
|
+
the image is now `attachments[0]`, `{ attachmentId, fileName, byteLength }`,
|
|
50
|
+
the shape a delivered file has everywhere else. (#610)
|
|
51
|
+
- On Android, a CPU completion load runs on the performance cores only
|
|
52
|
+
(`threads` and `cpu-mask` from each core's max frequency), instead of one
|
|
53
|
+
thread per core. GPU loads, iOS and desktop are unchanged. (#601)
|
|
54
|
+
|
|
55
|
+
### Fixed
|
|
56
|
+
|
|
57
|
+
- A loaded skill's body reaches the model as text under its `[Tool: skill …]`
|
|
58
|
+
header, with only `name` and `file` on the JSON line, instead of stringified
|
|
59
|
+
whole. Qwen3.5-4B copied the escaped quotes of `A[\"First step\"]` into its
|
|
60
|
+
own Mermaid block, which the app then could not render (QVAC-24502). Turns
|
|
61
|
+
an older harness stringified whole still read as loaded; an existing chat
|
|
62
|
+
with a replayed skill stub re-reads once after the update.
|
|
63
|
+
- The wrap-up round a run ends on after blocked repeats keeps the tool block in
|
|
64
|
+
the prompt and forbids a call with `tool_choice: "none"`, instead of dropping
|
|
65
|
+
the block. Under `@qvac/sdk` 0.22 the dropped block rewrote the chat's one
|
|
66
|
+
cache file, so that round and the next turn each re-read the whole chat
|
|
67
|
+
(19.6 s to first token on Qwen3.5-2B after a 12-turn chat). (#605)
|
|
68
|
+
- Every user turn of a saved chat renders the same bytes on the next request,
|
|
69
|
+
instead of losing its time stamp, so Qwen 3.5 and 3.8 resume from the cache
|
|
70
|
+
rather than re-reading the whole chat each turn. (#592)
|
|
71
|
+
- A `skill` call resolves a display name, any case, or a tool name exactly one
|
|
72
|
+
skill grants (`pptx`), instead of refusing anything but the folder name.
|
|
73
|
+
(#528)
|
|
74
|
+
- `pptx` skips look-only keys, an invented theme, a body a layout cannot hold
|
|
75
|
+
and a picture with no upload, listing them in `skipped`, instead of
|
|
76
|
+
refusing the whole deck. (#527)
|
|
77
|
+
- After `generate_image` or `edit_image`, the next round is told the image is
|
|
78
|
+
attached and shown to the user, as it is after `pdf`, the office tools and
|
|
79
|
+
`exec`, instead of "call the next tool, or answer". On that nudge Qwen3.5-4B
|
|
80
|
+
sometimes called `generate_image` again to show the image it had just made,
|
|
81
|
+
and the chat got two. (#610)
|
|
82
|
+
- A custom model whose head width a quantized KV block does not divide loads
|
|
83
|
+
with an `f16` cache instead of failing with "Failed to initialize context"
|
|
84
|
+
(BeeLLM, head width 40, under the hosts' `q8_0`). (#614)
|
|
85
|
+
- A custom model whose chat template has no `<think>` tag no longer starts its
|
|
86
|
+
reply inside a think block, so the reply stops streaming as thinking and then
|
|
87
|
+
repeating as the answer (Qwen2.5-Coder with thinking on). Its reasoning
|
|
88
|
+
budget is unchanged. (#614)
|
|
89
|
+
- An `http_request` body, or a shaped skill operation response, is cut at a
|
|
90
|
+
share of the context window instead of a fixed 8 KB: half the room the last
|
|
91
|
+
round left, at a character per token so Chinese or Japanese text cannot
|
|
92
|
+
overflow it, and shared by every call in the round. With 11k tokens used of
|
|
93
|
+
a 51k window that is 20,000 characters where it was 8,192. A cut result
|
|
94
|
+
carries `truncated`, with the characters kept, the total, the share read and
|
|
95
|
+
a note that the reply must say so. A Google Doc export came back as its
|
|
96
|
+
first fragment and the model summarized that as the whole document. See
|
|
97
|
+
[the decision record](./docs/decisions/2026-10-23-a-tool-response-is-cut-to-the-window-and-says-so.md). (#615)
|
|
98
|
+
- `http_request` gives up once no byte has arrived for 10 seconds, at any
|
|
99
|
+
point in the request, instead of 10 seconds for the whole response. A body
|
|
100
|
+
that keeps arriving gets up to 30 seconds, so a large Google Doc export on a
|
|
101
|
+
slow link finishes, while a server that stops answering still fails as fast
|
|
102
|
+
as before. (#619)
|
|
103
|
+
|
|
104
|
+
### Security
|
|
105
|
+
|
|
106
|
+
- Requires `bare-tls` 3.1.13, whose CA bundle drops emSign ECC Root CA – G3,
|
|
107
|
+
whose subordinate keys were recovered. Bare checks no revocation. (#593)
|
|
108
|
+
|
|
11
109
|
## [0.8.12] - 2026-10-21
|
|
12
110
|
|
|
13
111
|
### Added
|
|
@@ -2136,7 +2234,9 @@ Install 0.2.12 or later to get them.
|
|
|
2136
2234
|
- Every dependency installs from the public npm registry: GPU stats are read
|
|
2137
2235
|
through `bare-gpu-info`. (#12)
|
|
2138
2236
|
|
|
2139
|
-
[Unreleased]: https://github.com/tetherto/qvac-harness/compare/v0.8.
|
|
2237
|
+
[Unreleased]: https://github.com/tetherto/qvac-harness/compare/v0.8.14...HEAD
|
|
2238
|
+
[0.8.14]: https://github.com/tetherto/qvac-harness/compare/v0.8.13...v0.8.14
|
|
2239
|
+
[0.8.13]: https://github.com/tetherto/qvac-harness/compare/v0.8.12...v0.8.13
|
|
2140
2240
|
[0.8.12]: https://github.com/tetherto/qvac-harness/compare/v0.8.11...v0.8.12
|
|
2141
2241
|
[0.8.11]: https://github.com/tetherto/qvac-harness/compare/v0.8.10...v0.8.11
|
|
2142
2242
|
[0.8.10]: https://github.com/tetherto/qvac-harness/compare/v0.8.9...v0.8.10
|
package/dist-lib/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { platform, totalmem } from 'os';
|
|
|
4
4
|
import process from 'process';
|
|
5
5
|
import ReadyResource from 'ready-resource';
|
|
6
6
|
import { HarnessError } from './lib/errors.js';
|
|
7
|
+
import { androidCpuPlacement } from './lib/hardware/cpu-placement.js';
|
|
7
8
|
import { probeGpuStats } from './lib/hardware/gpu-probe.js';
|
|
8
9
|
import { probeCapabilityProfile } from './lib/hardware/capability-probe.js';
|
|
9
10
|
import { closePythonWorker } from './lib/tools/exec/adapters/python/worker/active.js';
|
|
@@ -721,7 +722,8 @@ export class Harness extends ReadyResource {
|
|
|
721
722
|
kvCacheK: this._kvCacheK,
|
|
722
723
|
kvCacheV: this._kvCacheV,
|
|
723
724
|
mainGpu: resolveMainGpu,
|
|
724
|
-
openclCacheDir
|
|
725
|
+
openclCacheDir,
|
|
726
|
+
cpuPlacement: androidCpuPlacement
|
|
725
727
|
};
|
|
726
728
|
}
|
|
727
729
|
_createPool() {
|
|
@@ -731,7 +733,8 @@ export class Harness extends ReadyResource {
|
|
|
731
733
|
loads: this._loads,
|
|
732
734
|
beforeLoad: (load) => this._beforeLoad(load),
|
|
733
735
|
chooseContext: (load, tier) => this._chooseContext(load, tier),
|
|
734
|
-
hold: this._hold
|
|
736
|
+
hold: this._hold,
|
|
737
|
+
modelsDir: this._modelsDir
|
|
735
738
|
});
|
|
736
739
|
}
|
|
737
740
|
_createEmbedPool() {
|
|
@@ -1749,7 +1752,7 @@ export class Harness extends ReadyResource {
|
|
|
1749
1752
|
};
|
|
1750
1753
|
this._replying.push(key);
|
|
1751
1754
|
try {
|
|
1752
|
-
const { modelId, ctxSize } = await raceAbort(handle.load(), signal);
|
|
1755
|
+
const { modelId, ctxSize, canThink } = await raceAbort(handle.load(), signal);
|
|
1753
1756
|
log.info('model ready', { model });
|
|
1754
1757
|
const sdk = await this._sdk.load();
|
|
1755
1758
|
const turns = projectionModel ? messages : messages.map(({ attachments, ...turn }) => turn);
|
|
@@ -1772,6 +1775,7 @@ export class Harness extends ReadyResource {
|
|
|
1772
1775
|
cacheKey,
|
|
1773
1776
|
session,
|
|
1774
1777
|
thinkingDefault,
|
|
1778
|
+
canThink,
|
|
1775
1779
|
generationParams,
|
|
1776
1780
|
responseFormat,
|
|
1777
1781
|
captureInferenceCalls,
|
|
@@ -1788,7 +1792,8 @@ export class Harness extends ReadyResource {
|
|
|
1788
1792
|
ragSearch,
|
|
1789
1793
|
progress,
|
|
1790
1794
|
askUser,
|
|
1791
|
-
signal
|
|
1795
|
+
signal,
|
|
1796
|
+
platform: this._platform ?? detectPlatform()
|
|
1792
1797
|
});
|
|
1793
1798
|
this._modelFaults.delete(model);
|
|
1794
1799
|
}
|
|
@@ -18,6 +18,7 @@ export interface Message {
|
|
|
18
18
|
role: string;
|
|
19
19
|
content: string;
|
|
20
20
|
attachments?: MessageAttachment[];
|
|
21
|
+
sentAt?: number | undefined;
|
|
21
22
|
[key: string]: unknown;
|
|
22
23
|
}
|
|
23
24
|
export interface Agent {
|
|
@@ -120,6 +121,7 @@ export type AskUserFn = (question: {
|
|
|
120
121
|
export interface RunBudget {
|
|
121
122
|
readonly deadlineMs: number;
|
|
122
123
|
outputBytesUsed: number;
|
|
124
|
+
responseRoomChars?: number | undefined;
|
|
123
125
|
}
|
|
124
126
|
export interface ToolExecuteContext {
|
|
125
127
|
agentId?: string | null | undefined;
|
|
@@ -189,6 +191,7 @@ export interface ToolDefinition {
|
|
|
189
191
|
validate?: (args: Record<string, unknown>, ctx?: ToolExecuteContext) => string | null;
|
|
190
192
|
effect: (args: Record<string, unknown>, ctx?: ToolExecuteContext) => ToolEffect;
|
|
191
193
|
stableRead?: true;
|
|
194
|
+
deliversMany?: true;
|
|
192
195
|
resource?: (args: Record<string, unknown>, ctx?: ToolExecuteContext) => ResourceDescriptor | null;
|
|
193
196
|
compiled?: true;
|
|
194
197
|
execute: (args: Record<string, unknown>, ctx?: ToolExecuteContext) => Promise<unknown>;
|
|
@@ -315,6 +318,7 @@ interface CompletionArgs {
|
|
|
315
318
|
cacheKey?: string;
|
|
316
319
|
session?: string;
|
|
317
320
|
thinkingDefault?: string;
|
|
321
|
+
canThink?: boolean | undefined;
|
|
318
322
|
generationParams?: LlmGenerationParams;
|
|
319
323
|
responseFormat?: ResponseFormat;
|
|
320
324
|
messages: Message[];
|
|
@@ -332,6 +336,7 @@ interface CompletionArgs {
|
|
|
332
336
|
fsRoots?: readonly DriveRoot[];
|
|
333
337
|
fsWriteRoots?: readonly DriveRoot[];
|
|
334
338
|
captureInferenceCalls?: boolean;
|
|
339
|
+
platform?: string;
|
|
335
340
|
}
|
|
336
341
|
export { CONTEXT_OVERFLOW_MESSAGE } from '../errors.ts';
|
|
337
342
|
export declare function trustedSourcesFrom(history: readonly Message[]): TrustedSource[];
|
|
@@ -340,4 +345,4 @@ export declare function toSdkTool(tool: ToolDefinition): SdkTool;
|
|
|
340
345
|
export type CompletionSkillEntry = SkillCatalogEntry & {
|
|
341
346
|
readonly status?: SkillState;
|
|
342
347
|
};
|
|
343
|
-
export declare function completion(sdk: CompletionSdk, { modelId, acquireRound, model, agent, ctxSize, cacheKey, session, thinkingDefault, generationParams: generationParamsOverride, responseFormat, messages: storedMessages, typedText, tools: allTools, skillCatalog, approve, attach, fetchAttachment, ragSearch, progress, askUser, signal, toolConfigs, fsRoots, fsWriteRoots, captureInferenceCalls }: CompletionArgs): AsyncGenerator<CompletionEvent>;
|
|
348
|
+
export declare function completion(sdk: CompletionSdk, { modelId, acquireRound, model, agent, ctxSize, cacheKey, session, thinkingDefault, canThink, generationParams: generationParamsOverride, responseFormat, messages: storedMessages, typedText, tools: allTools, skillCatalog, approve, attach, fetchAttachment, ragSearch, progress, askUser, signal, toolConfigs, fsRoots, fsWriteRoots, captureInferenceCalls, platform }: CompletionArgs): AsyncGenerator<CompletionEvent>;
|
|
@@ -18,7 +18,7 @@ import { resolveLlmGenerationParams } from '../models/llm-presets.js';
|
|
|
18
18
|
import { toolDialectFor } from '../models/model-catalog.js';
|
|
19
19
|
import { modelNameToCapabilityProfile } from '../models/model-catalog-constants.js';
|
|
20
20
|
import { isContextOverflowError, isGrammarOverrunError, isSdkModelWedgedError } from '../models/sdk-faults.js';
|
|
21
|
-
import {
|
|
21
|
+
import { annotateUserTimes, skillsPromptSection, systemPromptParts } from '../prompt.js';
|
|
22
22
|
import { isMetadataMethod } from '../tools/mcp/protocol.js';
|
|
23
23
|
import { unquoteArg } from '../tools/model-args.js';
|
|
24
24
|
import { SKILL_TOOL_NAME, WEB_SEARCH_TOOL_NAME } from './tool-names.js';
|
|
@@ -27,13 +27,14 @@ import { executeToolSearch, loadedToolNames, renderedTools, TOOL_SEARCH_NAME } f
|
|
|
27
27
|
import { promptUsageParts, usageBreakdown } from './usage-breakdown.js';
|
|
28
28
|
import { collectToolGrants, enabledTools, isSelected, skillIsActive, skillsAreSelected } from './tool-selection.js';
|
|
29
29
|
import { guardToolCall } from '../tools/outbound-guard.js';
|
|
30
|
-
import { isAvailableState } from '../tools/skills/skill-state-constants.js';
|
|
31
|
-
import { resolveImplicitSkill, resolveSkillMention } from '../tools/skills/mention.js';
|
|
30
|
+
import { isAvailableState, SKILL_STATE } from '../tools/skills/skill-state-constants.js';
|
|
31
|
+
import { resolveImplicitSkill, resolveSkillMention, skillMentionHandle } from '../tools/skills/mention.js';
|
|
32
32
|
import { parseToolGrant } from '../tools/skills/tool-grants.js';
|
|
33
33
|
import { NETWORK_TOOLSETS, permittedTools } from '../tools/toolsets.js';
|
|
34
34
|
import { promptPrefixHash } from './prompt-prefix.js';
|
|
35
35
|
import { logToolPrompt } from './tool-prompt-log.js';
|
|
36
|
-
import {
|
|
36
|
+
import { responseRoomChars } from '../tools/http-request/truncate-response.js';
|
|
37
|
+
import { DIRECT_CALL_ID, deliversFile, FILE_DELIVERED_NUDGE, loadedSkillFilesFrom, loadedSkillsFrom, skillMentionNudge, TOOL_CONTINUATION_NUDGE, toolResultTurn } from './tool-turns.js';
|
|
37
38
|
export function imageSettingsFrom(agent) {
|
|
38
39
|
if (!agent)
|
|
39
40
|
return undefined;
|
|
@@ -153,12 +154,13 @@ function explicitlyDisablesWebSearch(text) {
|
|
|
153
154
|
return (/\b(?:do\s+not|don't|dont|never)\s+(?:search|browse|look\s+up|find|use)\s+(?:the\s+)?(?:web|internet|online)\b/i.test(text) ||
|
|
154
155
|
/\b(?:avoid|without)\s+(?:searching|browsing|using)\s+(?:the\s+)?(?:web|internet|online)\b/i.test(text));
|
|
155
156
|
}
|
|
156
|
-
function directToolHistory(history, call, output) {
|
|
157
|
+
function directToolHistory(history, { call, output, loads = [], nudge = TOOL_CONTINUATION_NUDGE }) {
|
|
157
158
|
return [
|
|
158
159
|
...history,
|
|
159
160
|
{ role: 'assistant', content: toolCallMarkup([call]) },
|
|
160
161
|
{ role: 'tool', content: toolResultTurn(call.name, DIRECT_CALL_ID, output) },
|
|
161
|
-
|
|
162
|
+
...loads,
|
|
163
|
+
{ role: 'user', content: nudge }
|
|
162
164
|
];
|
|
163
165
|
}
|
|
164
166
|
function assistantToolTurn(contentText, calls) {
|
|
@@ -414,6 +416,33 @@ function unreadySkillState(name, catalog) {
|
|
|
414
416
|
const status = catalog.find((entry) => entry.name === name)?.status;
|
|
415
417
|
return status !== undefined && !isAvailableState(status) ? status : null;
|
|
416
418
|
}
|
|
419
|
+
const FIXABLE_STATES = new Set([
|
|
420
|
+
SKILL_STATE.disconnected,
|
|
421
|
+
SKILL_STATE.needsSetup
|
|
422
|
+
]);
|
|
423
|
+
function fixableInSkills(entry) {
|
|
424
|
+
return entry.status !== undefined && FIXABLE_STATES.has(entry.status);
|
|
425
|
+
}
|
|
426
|
+
function unreadyRemedy(state) {
|
|
427
|
+
if (state === SKILL_STATE.disconnected)
|
|
428
|
+
return 'reconnect it in Skills';
|
|
429
|
+
if (state === SKILL_STATE.needsSetup)
|
|
430
|
+
return 'set it up in Skills';
|
|
431
|
+
return 'open it in Skills to see what it needs';
|
|
432
|
+
}
|
|
433
|
+
function promptSkill(entry) {
|
|
434
|
+
const state = skillInContext(entry) ? undefined : entry.status;
|
|
435
|
+
return {
|
|
436
|
+
name: entry.name,
|
|
437
|
+
description: entry.description,
|
|
438
|
+
note: state ? `${state} — tell the user to ${unreadyRemedy(state)}` : undefined
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
function unreadyCall(name, state) {
|
|
442
|
+
const reason = `skill "${name}" is ${state} and cannot be used yet. Tell the user to ${unreadyRemedy(state)}, ` +
|
|
443
|
+
`and do not do this task with another tool.`;
|
|
444
|
+
return blockedResult({ error: reason }, reason);
|
|
445
|
+
}
|
|
417
446
|
function blockedSkillMessage(name, catalog, listShown) {
|
|
418
447
|
if (catalog.some((entry) => entry.name === name)) {
|
|
419
448
|
return (`skill "${name}" is not enabled for this agent. Do not rebuild what it does with another ` +
|
|
@@ -426,6 +455,22 @@ function blockedSkillMessage(name, catalog, listShown) {
|
|
|
426
455
|
`skill is available this turn — do not guess another name, and answer from what you ` +
|
|
427
456
|
`already have.`;
|
|
428
457
|
}
|
|
458
|
+
function withSkillName(call, catalog) {
|
|
459
|
+
if (call.name !== SKILL_TOOL_NAME)
|
|
460
|
+
return call;
|
|
461
|
+
const args = call.arguments;
|
|
462
|
+
const asked = unquoteArg(args.name ?? args.skill_name ?? args.skill).toLowerCase();
|
|
463
|
+
const entry = catalog.find((skill) => skill.name.toLowerCase() === asked) ??
|
|
464
|
+
catalog.find((skill) => skill.displayName?.toLowerCase() === asked) ??
|
|
465
|
+
soleOwner(catalog, asked);
|
|
466
|
+
return entry && entry.name !== args.name
|
|
467
|
+
? { ...call, arguments: { ...args, name: entry.name } }
|
|
468
|
+
: call;
|
|
469
|
+
}
|
|
470
|
+
function soleOwner(catalog, toolName) {
|
|
471
|
+
const owners = catalog.filter((skill) => skill.tools.some((grant) => parseToolGrant(grant).name === toolName));
|
|
472
|
+
return owners.length === 1 ? owners[0] : undefined;
|
|
473
|
+
}
|
|
429
474
|
async function resolveToolCalls(toolCalls, { enabled, agentId, pipeline, skillNames, sandboxMode, signal }) {
|
|
430
475
|
const resolved = [];
|
|
431
476
|
for (const call of toolCalls) {
|
|
@@ -627,7 +672,7 @@ async function* runRecoveredRoundWith(sdk, args, modelId) {
|
|
|
627
672
|
try {
|
|
628
673
|
const result = sdk.completion(params);
|
|
629
674
|
result.final.catch(noop);
|
|
630
|
-
const startInThink = args.generationParams?.reasoning_budget === -1;
|
|
675
|
+
const startInThink = args.generationParams?.reasoning_budget === -1 && args.canThink !== false;
|
|
631
676
|
for await (const event of runRoundTokens(result, state, {
|
|
632
677
|
sdk,
|
|
633
678
|
signal: args.signal,
|
|
@@ -718,7 +763,7 @@ function* reportUnnamedWrites(said, landed) {
|
|
|
718
763
|
yield { type: 'content', text: unreported };
|
|
719
764
|
}
|
|
720
765
|
}
|
|
721
|
-
export async function* completion(sdk, { modelId, acquireRound, model, agent, ctxSize, cacheKey, session, thinkingDefault, generationParams: generationParamsOverride, responseFormat, messages: storedMessages, typedText, tools: allTools = [], skillCatalog = [], approve, attach, fetchAttachment, ragSearch, progress, askUser, signal, toolConfigs, fsRoots = [], fsWriteRoots = [], captureInferenceCalls = false }) {
|
|
766
|
+
export async function* completion(sdk, { modelId, acquireRound, model, agent, ctxSize, cacheKey, session, thinkingDefault, canThink, generationParams: generationParamsOverride, responseFormat, messages: storedMessages, typedText, tools: allTools = [], skillCatalog = [], approve, attach, fetchAttachment, ragSearch, progress, askUser, signal, toolConfigs, fsRoots = [], fsWriteRoots = [], captureInferenceCalls = false, platform }) {
|
|
722
767
|
const pipeline = new HookPipeline();
|
|
723
768
|
const agentId = agent?.id ?? null;
|
|
724
769
|
const disabledToolsets = agent?.sandboxMode
|
|
@@ -758,15 +803,19 @@ export async function* completion(sdk, { modelId, acquireRound, model, agent, ct
|
|
|
758
803
|
const turnImages = lastUserImages(messages);
|
|
759
804
|
const toolsSelected = isSelected(agent?.toolsScope, agent?.enabledTools);
|
|
760
805
|
const skillsSelected = skillsAreSelected(agent?.skillsScope, Boolean(agent));
|
|
761
|
-
const inContextSkills = skillCatalog.filter(skillInContext);
|
|
762
806
|
const loadedSkills = loadedSkillsFrom(messages);
|
|
763
807
|
const loadedSkillFiles = loadedSkillFilesFrom(messages);
|
|
764
808
|
const activation = {
|
|
765
809
|
skillsSelected,
|
|
766
810
|
enabledSkills: agent?.enabledSkills ?? []
|
|
767
811
|
};
|
|
768
|
-
const
|
|
769
|
-
|
|
812
|
+
const listedSkills = skillCatalog.filter((skill) => skillIsActive(skill.name, activation) &&
|
|
813
|
+
(skillInContext(skill) || (skillsSelected && fixableInSkills(skill))));
|
|
814
|
+
const activeSkills = listedSkills.filter(skillInContext);
|
|
815
|
+
const unreadySkills = listedSkills.filter((skill) => !skillInContext(skill));
|
|
816
|
+
const inContextSkills = [...skillCatalog.filter(skillInContext), ...unreadySkills];
|
|
817
|
+
const spendsCredentials = (name) => skillIsActive(name, activation) && !unreadySkillState(name, skillCatalog);
|
|
818
|
+
const mention = resolveSkillMention(userText, listedSkills);
|
|
770
819
|
const { grantedNames, grantedOwners, grantedOps } = collectToolGrants(activeSkills);
|
|
771
820
|
function selectEnabled(offered = false) {
|
|
772
821
|
if (responseFormat)
|
|
@@ -780,7 +829,7 @@ export async function* completion(sdk, { modelId, acquireRound, model, agent, ct
|
|
|
780
829
|
loadedGrantedNames: offered ? grantedNames : collectToolGrants(loaded).grantedNames,
|
|
781
830
|
hasRoots: fsRoots.length > 0,
|
|
782
831
|
hasWriteRoots: writableRoots.length > 0,
|
|
783
|
-
hasActiveSkills:
|
|
832
|
+
hasActiveSkills: listedSkills.length > 0,
|
|
784
833
|
capabilityProfile: model ? modelNameToCapabilityProfile(model) : undefined
|
|
785
834
|
});
|
|
786
835
|
}
|
|
@@ -830,46 +879,51 @@ export async function* completion(sdk, { modelId, acquireRound, model, agent, ct
|
|
|
830
879
|
let preloadedSkill = null;
|
|
831
880
|
let preloadedResult = null;
|
|
832
881
|
const preload = mention ?? resolveImplicitSkill(userText, activeSkills);
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
const
|
|
882
|
+
const loader = tools.find((tool) => tool.name === SKILL_TOOL_NAME);
|
|
883
|
+
if (preload && loader) {
|
|
884
|
+
const preloadState = unreadySkillState(preload.name, skillCatalog);
|
|
885
|
+
const loaded = preloadState
|
|
886
|
+
? null
|
|
887
|
+
: await loader.execute({ name: preload.name }, toolContext());
|
|
836
888
|
if (loaded && typeof loaded === 'object' && 'content' in loaded) {
|
|
837
889
|
preloadedSkill = String(loaded.content);
|
|
838
890
|
preloadedResult = loaded;
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
891
|
+
}
|
|
892
|
+
if (preloadState || (preloadedSkill !== null && !loadedSkills.has(preload.name))) {
|
|
893
|
+
const preloadArgs = { name: preload.name };
|
|
894
|
+
const preloadEffect = 'read';
|
|
895
|
+
const preloadResource = loader.resource?.(preloadArgs) ?? null;
|
|
896
|
+
yield {
|
|
897
|
+
type: 'tool-call',
|
|
898
|
+
name: SKILL_TOOL_NAME,
|
|
899
|
+
args: preloadArgs,
|
|
900
|
+
effect: preloadEffect,
|
|
901
|
+
display: labelOf(SKILL_TOOL_NAME, preloadArgs, skillEmoji(preload.name))
|
|
902
|
+
};
|
|
903
|
+
yield {
|
|
904
|
+
type: 'tool-activity',
|
|
905
|
+
name: SKILL_TOOL_NAME,
|
|
906
|
+
args: { name: preload.name },
|
|
907
|
+
resource: null,
|
|
908
|
+
effect: 'read',
|
|
909
|
+
decision: preloadState ? 'blocked' : 'auto'
|
|
910
|
+
};
|
|
911
|
+
const settled = await settleToolCall(pipeline, preloadState
|
|
912
|
+
? unreadyCall(preload.name, preloadState)
|
|
913
|
+
: executedCall(loaded, { kind: 'success' }), {
|
|
914
|
+
agentId,
|
|
915
|
+
tool: loader,
|
|
916
|
+
name: SKILL_TOOL_NAME,
|
|
917
|
+
args: preloadArgs,
|
|
918
|
+
effect: preloadEffect,
|
|
919
|
+
resource: preloadResource
|
|
920
|
+
});
|
|
921
|
+
preloadedResult = settled.result;
|
|
922
|
+
yield {
|
|
923
|
+
type: 'tool-result',
|
|
924
|
+
name: SKILL_TOOL_NAME,
|
|
925
|
+
result: settled.result
|
|
926
|
+
};
|
|
873
927
|
}
|
|
874
928
|
}
|
|
875
929
|
if (preload && preloadedSkill) {
|
|
@@ -883,7 +937,8 @@ export async function* completion(sdk, { modelId, acquireRound, model, agent, ct
|
|
|
883
937
|
const system = systemPromptParts({
|
|
884
938
|
bio: agent?.bio,
|
|
885
939
|
toolNames: enabled.map((tool) => tool.name),
|
|
886
|
-
skillsSection: skillsPromptSection(
|
|
940
|
+
skillsSection: skillsPromptSection(listedSkills.map(promptSkill)),
|
|
941
|
+
platform
|
|
887
942
|
});
|
|
888
943
|
const systemContent = system.text;
|
|
889
944
|
const promptPrefix = promptPrefixHash({ system: systemContent, tools: sdkTools });
|
|
@@ -907,10 +962,14 @@ export async function* completion(sdk, { modelId, acquireRound, model, agent, ct
|
|
|
907
962
|
});
|
|
908
963
|
}
|
|
909
964
|
logSelection();
|
|
910
|
-
let history =
|
|
911
|
-
if (preload &&
|
|
912
|
-
history = directToolHistory(history, {
|
|
913
|
-
|
|
965
|
+
let history = annotateUserTimes(systemContent ? [{ role: 'system', content: systemContent }, ...messages] : messages);
|
|
966
|
+
if (preload && preloadedResult !== null) {
|
|
967
|
+
history = directToolHistory(history, {
|
|
968
|
+
call: { name: SKILL_TOOL_NAME, arguments: { name: preload.name } },
|
|
969
|
+
output: preloadedResult,
|
|
970
|
+
loads: preloadedSkill !== null ? skillToolLoads(preload.name, history) : [],
|
|
971
|
+
nudge: mention ? skillMentionNudge(skillMentionHandle(mention)) : undefined
|
|
972
|
+
});
|
|
914
973
|
}
|
|
915
974
|
let roundCacheKey = cacheKey;
|
|
916
975
|
const runUsage = () => usageBreakdown(promptParts, stats.cacheTokens, model);
|
|
@@ -921,7 +980,7 @@ export async function* completion(sdk, { modelId, acquireRound, model, agent, ct
|
|
|
921
980
|
let webSearches = 0;
|
|
922
981
|
const sources = trustedSourcesFrom(history);
|
|
923
982
|
const query = explicitWebSearchQuery(userText, enabled, {
|
|
924
|
-
skillPreloaded:
|
|
983
|
+
skillPreloaded: preloadedResult !== null
|
|
925
984
|
});
|
|
926
985
|
const webSearch = enabled.find((tool) => tool.name === WEB_SEARCH_TOOL_NAME);
|
|
927
986
|
if (query && webSearch) {
|
|
@@ -996,19 +1055,24 @@ export async function* completion(sdk, { modelId, acquireRound, model, agent, ct
|
|
|
996
1055
|
name: webSearch.name,
|
|
997
1056
|
result: output
|
|
998
1057
|
};
|
|
999
|
-
history = directToolHistory(history, {
|
|
1058
|
+
history = directToolHistory(history, {
|
|
1059
|
+
call: { name: webSearch.name, arguments: args },
|
|
1060
|
+
output
|
|
1061
|
+
});
|
|
1000
1062
|
}
|
|
1001
1063
|
let outcome = 'exhausted';
|
|
1002
1064
|
let said = '';
|
|
1003
1065
|
let mute = 0;
|
|
1004
1066
|
let narrated = false;
|
|
1005
1067
|
let cappedRounds = 0;
|
|
1068
|
+
let lastToolRound = false;
|
|
1006
1069
|
let roundsSent = 0;
|
|
1007
1070
|
let round = 0;
|
|
1008
1071
|
for (; round < MAX_TOOL_ROUNDS; round++) {
|
|
1009
1072
|
if (signal?.aborted)
|
|
1010
1073
|
throw new AbortedError();
|
|
1011
1074
|
let deliveredThisRound = false;
|
|
1075
|
+
let deliveryEndsRun = false;
|
|
1012
1076
|
if (Date.now() >= runBudget.deadlineMs) {
|
|
1013
1077
|
outcome = 'time-capped';
|
|
1014
1078
|
break;
|
|
@@ -1027,6 +1091,7 @@ export async function* completion(sdk, { modelId, acquireRound, model, agent, ct
|
|
|
1027
1091
|
history,
|
|
1028
1092
|
tools: sdkTools,
|
|
1029
1093
|
generationParams,
|
|
1094
|
+
canThink,
|
|
1030
1095
|
responseFormat,
|
|
1031
1096
|
toolDialect,
|
|
1032
1097
|
cacheKey: roundCacheKey,
|
|
@@ -1042,6 +1107,7 @@ export async function* completion(sdk, { modelId, acquireRound, model, agent, ct
|
|
|
1042
1107
|
}
|
|
1043
1108
|
history = recovered.history;
|
|
1044
1109
|
collectStats(stats, final.stats, final.stopReason);
|
|
1110
|
+
runBudget.responseRoomChars = responseRoomChars(ctxSize, final.stats?.cacheTokens);
|
|
1045
1111
|
log.debug('round stats', { round, wallMs: Date.now() - roundStarted, ...final.stats });
|
|
1046
1112
|
const markup = stripToolResponseBlocks(truncateAtControlToken(final.raw.fullText) || recovered.unproven || '');
|
|
1047
1113
|
const deferred = sdkTools?.filter((tool) => tool.deferLoading) ?? [];
|
|
@@ -1115,7 +1181,8 @@ export async function* completion(sdk, { modelId, acquireRound, model, agent, ct
|
|
|
1115
1181
|
});
|
|
1116
1182
|
toolCalls = toolCalls.slice(0, MAX_CALLS_PER_ROUND);
|
|
1117
1183
|
}
|
|
1118
|
-
const
|
|
1184
|
+
const named = toolCalls.map((call) => withSkillName(call, skillCatalog));
|
|
1185
|
+
const resolved = await resolveToolCalls(named, {
|
|
1119
1186
|
enabled,
|
|
1120
1187
|
agentId: agent?.id ?? null,
|
|
1121
1188
|
pipeline,
|
|
@@ -1154,7 +1221,7 @@ export async function* completion(sdk, { modelId, acquireRound, model, agent, ct
|
|
|
1154
1221
|
const searchCapped = tool?.name === WEB_SEARCH_TOOL_NAME && webSearches >= MAX_WEB_SEARCHES_PER_TURN;
|
|
1155
1222
|
const callCtx = {
|
|
1156
1223
|
...toolContext(turnImages, ctxSize),
|
|
1157
|
-
skills: [...loadedSkills].filter(
|
|
1224
|
+
skills: [...loadedSkills].filter(spendsCredentials),
|
|
1158
1225
|
skillsLoadedThisTurn: [...loadedThisTurn],
|
|
1159
1226
|
settings: toolConfigs?.[call.name],
|
|
1160
1227
|
toolOps: grantedOps,
|
|
@@ -1186,9 +1253,7 @@ export async function* completion(sdk, { modelId, acquireRound, model, agent, ct
|
|
|
1186
1253
|
const unreadyState = skillCall ? unreadySkillState(skillName, skillCatalog) : null;
|
|
1187
1254
|
const skillBlocked = skillCall && !unreadyState && (!tool || !skillIsActive(skillName, activation));
|
|
1188
1255
|
let activity = null;
|
|
1189
|
-
const blockedReason = blockedSkillMessage(skillName, skillCatalog,
|
|
1190
|
-
const unreadyReason = `skill "${skillName}" is ${unreadyState ?? 'unavailable'} and cannot be used yet. ` +
|
|
1191
|
-
`Tell the user to open it in Skills and finish its setup; do not retry.`;
|
|
1256
|
+
const blockedReason = blockedSkillMessage(skillName, skillCatalog, listedSkills.length > 0);
|
|
1192
1257
|
let execution;
|
|
1193
1258
|
if (priorFailure) {
|
|
1194
1259
|
blockedRepeats++;
|
|
@@ -1217,7 +1282,7 @@ export async function* completion(sdk, { modelId, acquireRound, model, agent, ct
|
|
|
1217
1282
|
execution = blockedResult({ error: blockedReason }, blockedReason);
|
|
1218
1283
|
}
|
|
1219
1284
|
else if (unreadyState) {
|
|
1220
|
-
execution =
|
|
1285
|
+
execution = unreadyCall(skillName, unreadyState);
|
|
1221
1286
|
}
|
|
1222
1287
|
else if (searchCapped) {
|
|
1223
1288
|
execution = terminalCall({ content: WEB_SEARCH_LIMIT_MESSAGE }, { kind: 'success' }, { executed: false });
|
|
@@ -1324,6 +1389,7 @@ export async function* completion(sdk, { modelId, acquireRound, model, agent, ct
|
|
|
1324
1389
|
}
|
|
1325
1390
|
if (executionOutcome.kind === 'success' && deliversFile(output)) {
|
|
1326
1391
|
deliveredThisRound = true;
|
|
1392
|
+
deliveryEndsRun ||= tool?.deliversMany !== true;
|
|
1327
1393
|
}
|
|
1328
1394
|
const turn = toolResultTurn(call.name, call.id, output);
|
|
1329
1395
|
sources.push({
|
|
@@ -1351,13 +1417,14 @@ export async function* completion(sdk, { modelId, acquireRound, model, agent, ct
|
|
|
1351
1417
|
role: 'user',
|
|
1352
1418
|
content: deliveredThisRound ? FILE_DELIVERED_NUDGE : TOOL_CONTINUATION_NUDGE
|
|
1353
1419
|
});
|
|
1354
|
-
if (
|
|
1420
|
+
if (lastToolRound) {
|
|
1355
1421
|
outcome = 'delivered';
|
|
1356
1422
|
break;
|
|
1357
1423
|
}
|
|
1358
1424
|
if (deliveredThisRound) {
|
|
1359
1425
|
runOutcomes.confirmDelivery();
|
|
1360
1426
|
}
|
|
1427
|
+
lastToolRound ||= deliveryEndsRun;
|
|
1361
1428
|
if (blockedRepeats >= MAX_BLOCKED_REPEATS) {
|
|
1362
1429
|
break;
|
|
1363
1430
|
}
|
|
@@ -1387,12 +1454,14 @@ export async function* completion(sdk, { modelId, acquireRound, model, agent, ct
|
|
|
1387
1454
|
modelId,
|
|
1388
1455
|
acquireRound,
|
|
1389
1456
|
history,
|
|
1390
|
-
tools:
|
|
1391
|
-
generationParams,
|
|
1457
|
+
tools: sdkTools,
|
|
1458
|
+
generationParams: { ...generationParams, tool_choice: 'none' },
|
|
1459
|
+
canThink,
|
|
1460
|
+
toolDialect,
|
|
1392
1461
|
cacheKey: roundCacheKey,
|
|
1393
1462
|
signal,
|
|
1394
1463
|
round: roundsSent,
|
|
1395
|
-
promptPrefix
|
|
1464
|
+
promptPrefix,
|
|
1396
1465
|
capture: captureInferenceCalls
|
|
1397
1466
|
});
|
|
1398
1467
|
collectStats(stats, recovered.final.stats, recovered.final.stopReason);
|
|
@@ -2,6 +2,7 @@ import type { Message } from './completion.ts';
|
|
|
2
2
|
export declare const DIRECT_CALL_ID = "call-direct";
|
|
3
3
|
export declare const TOOL_CONTINUATION_NUDGE = "[Tool results above. Continue the user's request: call the next tool, or answer.]";
|
|
4
4
|
export declare const FILE_DELIVERED_NUDGE = "[Tool results above. The file is attached to the chat and shown to the user. Answer now, unless the request still needs a file that is not made yet.]";
|
|
5
|
+
export declare function skillMentionNudge(handle: string): string;
|
|
5
6
|
export declare function isContinuationNudge(content: string): boolean;
|
|
6
7
|
export declare function deliversFile(output: unknown): boolean;
|
|
7
8
|
export declare function toolResultTurn(name: string, id: string, output: unknown): string;
|