@qvac/harness 1.0.0-rc.12 → 1.0.0-rc.13
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 +29 -0
- package/README.md +3 -1
- package/dist-lib/index.js +0 -1
- package/dist-lib/lib/agent/follow.js +9 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +13 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +11 -6
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.js +19 -11
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +10 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +3 -0
- package/dist-lib/lib/capabilities/completion-engine/driver.js +2 -1
- package/dist-lib/lib/capabilities/completion-engine/engine.js +39 -23
- package/dist-lib/lib/capabilities/completion-engine/event-mailbox.d.ts +20 -0
- package/dist-lib/lib/capabilities/completion-engine/event-mailbox.js +110 -0
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +2 -0
- package/dist-lib/lib/capabilities/completion-engine/model-round.js +2 -0
- package/dist-lib/lib/capabilities/completion-engine/round.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/round.js +38 -19
- package/dist-lib/lib/capabilities/completion-engine/turns.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/turns.js +16 -0
- package/dist-lib/lib/capabilities/tool-turns.d.ts +1 -0
- package/dist-lib/lib/capabilities/tool-turns.js +1 -0
- package/dist-lib/lib/connect.js +4 -2
- package/dist-lib/lib/contract/completion.d.ts +2 -1
- package/dist-lib/lib/contract/knowledge.d.ts +10 -0
- package/dist-lib/lib/fold/index.d.ts +3 -2
- package/dist-lib/lib/fold/index.js +7 -6
- package/dist-lib/lib/helpers/goal-check.d.ts +12 -0
- package/dist-lib/lib/helpers/goal-check.js +89 -7
- package/dist-lib/lib/helpers/html-helpers.js +9 -6
- package/dist-lib/lib/helpers/input-budget.d.ts +8 -0
- package/dist-lib/lib/helpers/input-budget.js +9 -0
- package/dist-lib/lib/machine/completion/actions/completion.d.ts +1 -1
- package/dist-lib/lib/machine/completion/actions/completion.js +34 -14
- package/dist-lib/lib/machine/completion/actions/tools.js +19 -1
- package/dist-lib/lib/machine/completion/rules.d.ts +1 -0
- package/dist-lib/lib/machine/completion/rules.js +14 -5
- package/dist-lib/lib/machine/completion/types.d.ts +3 -0
- package/dist-lib/lib/plugins/registry.d.ts +1 -0
- package/dist-lib/lib/plugins/registry.js +49 -10
- package/dist-lib/lib/residency/index.js +2 -0
- package/dist-lib/lib/serve.js +56 -15
- package/dist-lib/lib/tools/files/glob.js +2 -2
- package/dist-lib/lib/tools/files/read-file.js +134 -15
- package/dist-lib/lib/tools/fs/walk.d.ts +1 -0
- package/dist-lib/lib/tools/fs/walk.js +2 -1
- package/dist-lib/lib/tools/http-request/truncate-response.js +11 -2
- package/dist-lib/lib/tools/http-request.js +28 -11
- package/dist-lib/lib/tools/office.d.ts +1 -1
- package/dist-lib/lib/tools/office.js +34 -12
- package/dist-lib/lib/wire.js +23 -3
- package/dist-lib/plugins/knowledge/index.js +1 -0
- package/dist-lib/plugins/knowledge/manifest.d.ts +29 -0
- package/dist-lib/plugins/knowledge/manifest.js +41 -0
- package/dist-lib/plugins/knowledge/search-tool.js +8 -8
- package/dist-lib/plugins/knowledge/store.d.ts +35 -7
- package/dist-lib/plugins/knowledge/store.js +335 -143
- package/dist-lib/plugins/mcp/call.js +10 -3
- package/dist-lib/plugins/mcp/protocol.d.ts +4 -1
- package/dist-lib/plugins/mcp/protocol.js +11 -10
- package/dist-lib/plugins/mcp/tool-listing.d.ts +6 -0
- package/dist-lib/plugins/mcp/tool-listing.js +97 -0
- package/dist-lib/plugins/music/generate-music.js +2 -2
- package/dist-lib/plugins/python/language.js +2 -2
- 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/schema/harness.js +4 -2
- package/dist-lib/spec/hrpc/messages.js +19 -4
- package/dist-lib/spec/hyperschema/index.js +19 -4
- package/dist-lib/spec/hyperschema/schema.json +12 -1
- package/dist-lib/spec/hyperschema/types.d.ts +2 -0
- package/package.json +5 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hasRoundsLeft, stuckResult } from '../guards/retry.js';
|
|
2
|
-
import { mergeChecks, namedChecks } from '../../../helpers/goal-check.js';
|
|
2
|
+
import { asksChecks, mergeChecks, namedChecks } from '../../../helpers/goal-check.js';
|
|
3
3
|
import { activate, applyHistorySplice, applySplice, foldMetrics, goalMet, goalTokensLeft, nudgeWithChecks, nudgeWithPlan, retainFailureResults, settledSince } from '../rules.js';
|
|
4
4
|
export function startInitialRound({ context, params }) {
|
|
5
5
|
return applyPreparation(context, params);
|
|
@@ -102,21 +102,27 @@ function closeFailureMemo(context) {
|
|
|
102
102
|
roundProgressed: false
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
|
-
function endToolRound(context) {
|
|
105
|
+
function endToolRound(context, { last = false } = {}) {
|
|
106
106
|
return {
|
|
107
|
-
history: [...context.history, ...continuation(context)],
|
|
107
|
+
history: [...context.history, ...continuation(context, { last })],
|
|
108
108
|
steering: [],
|
|
109
109
|
delivered: context.delivered || context.deliveryEndsRun,
|
|
110
110
|
deliveredThisRound: false,
|
|
111
111
|
deliveryEndsRun: false
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
|
-
function continuation(context) {
|
|
115
|
-
const {
|
|
116
|
-
const nudge = deliveredThisRound ? policy.deliveredNudge : policy.continuationNudge;
|
|
114
|
+
function continuation(context, { last = false } = {}) {
|
|
115
|
+
const { plan } = context;
|
|
117
116
|
return context.steering.length
|
|
118
117
|
? userTurns(context.steering)
|
|
119
|
-
: [{ role: 'user', content: nudgeWithPlan(
|
|
118
|
+
: [{ role: 'user', content: nudgeWithPlan(roundNudge(context, last), plan) }];
|
|
119
|
+
}
|
|
120
|
+
function roundNudge(context, last) {
|
|
121
|
+
const { policy, deliveredThisRound } = context;
|
|
122
|
+
if (deliveredThisRound) {
|
|
123
|
+
return policy.deliveredNudge;
|
|
124
|
+
}
|
|
125
|
+
return last ? (policy.wrapUpNudge ?? policy.continuationNudge) : policy.continuationNudge;
|
|
120
126
|
}
|
|
121
127
|
function userTurns(queued) {
|
|
122
128
|
return queued.map(({ text, content }) => ({ role: 'user', content: content ?? text }));
|
|
@@ -153,7 +159,7 @@ export function addKnowledge({ context, params }) {
|
|
|
153
159
|
}
|
|
154
160
|
export function goalTurn({ policy, goal, plan }, stall) {
|
|
155
161
|
const nudge = stall ? `${policy.goalNudge}\n${stall}` : policy.goalNudge;
|
|
156
|
-
return nudgeWithChecks(nudgeWithPlan(`${nudge}\nGoal: ${goal?.objective ?? ''}`, plan), goal?.checks ?? [], goal
|
|
162
|
+
return nudgeWithChecks(nudgeWithPlan(`${nudge}\nGoal: ${goal?.objective ?? ''}`, plan), goal?.checks ?? [], !!goal && asksChecks(goal));
|
|
157
163
|
}
|
|
158
164
|
export function continueStalledGoal({ context }) {
|
|
159
165
|
const { goal, policy } = context;
|
|
@@ -268,20 +274,34 @@ function settledAfterSend(context, params) {
|
|
|
268
274
|
}
|
|
269
275
|
: {};
|
|
270
276
|
}
|
|
271
|
-
export function wrapCompletion({ params }) {
|
|
272
|
-
return { outcome: params };
|
|
277
|
+
export function wrapCompletion({ context, params }) {
|
|
278
|
+
return { ...swapStandingNudge(context), outcome: params };
|
|
279
|
+
}
|
|
280
|
+
function swapStandingNudge(context) {
|
|
281
|
+
const last = context.history.at(-1);
|
|
282
|
+
const [standing] = continuation(context);
|
|
283
|
+
if (!last || !standing || !('role' in last) || !('role' in standing)) {
|
|
284
|
+
return {};
|
|
285
|
+
}
|
|
286
|
+
if (last.role !== 'user' || last.content !== standing.content) {
|
|
287
|
+
return {};
|
|
288
|
+
}
|
|
289
|
+
return { history: [...context.history.slice(0, -1), ...continuation(context, { last: true })] };
|
|
273
290
|
}
|
|
274
291
|
export function wrapMuteCompletion(args) {
|
|
275
|
-
|
|
292
|
+
const turns = args.params.cutOff
|
|
293
|
+
? swapStandingNudge(args.context)
|
|
294
|
+
: silentTurn(args, continuation(args.context, { last: true }));
|
|
295
|
+
return { ...turns, outcome: 'mute' };
|
|
276
296
|
}
|
|
277
297
|
export function wrapSearchCappedCompletion({ context }) {
|
|
278
|
-
return { ...endToolRound(context), outcome: 'search-capped' };
|
|
298
|
+
return { ...endToolRound(context, { last: true }), outcome: 'search-capped' };
|
|
279
299
|
}
|
|
280
300
|
export function wrapDeliveredCompletion({ context }) {
|
|
281
|
-
return { ...endToolRound(context), outcome: 'delivered' };
|
|
301
|
+
return { ...endToolRound(context, { last: true }), outcome: 'delivered' };
|
|
282
302
|
}
|
|
283
303
|
export function wrapExhaustedCompletion({ context }) {
|
|
284
|
-
return { ...endToolRound(context), outcome: 'exhausted' };
|
|
304
|
+
return { ...endToolRound(context, { last: true }), outcome: 'exhausted' };
|
|
285
305
|
}
|
|
286
306
|
export function answerCompletion({ context, params }) {
|
|
287
307
|
const historyState = applyHistorySplice(context, params.history);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { activate, applyHistorySplice, applySplice, cutOffMessage, recordTool, retainFailureResults, settledSince } from '../rules.js';
|
|
2
2
|
import { failureResultRef, storeFailureResult, toolDeniedResult } from '../../../helpers/failure-result.js';
|
|
3
3
|
import { applyPreparation } from './completion.js';
|
|
4
|
+
import { asksChecks, existenceOnly, mergeChecks } from '../../../helpers/goal-check.js';
|
|
4
5
|
export function resolveTools({ context, params }) {
|
|
5
6
|
return {
|
|
6
7
|
toolQueue: [...params.calls],
|
|
@@ -214,7 +215,7 @@ function applyToolResult(context, payload, call) {
|
|
|
214
215
|
metrics: recordTool(context, call, payload.durationMs),
|
|
215
216
|
activated: activate(context.activated, payload.activate ? [payload.activate] : []),
|
|
216
217
|
plan: payload.plan ?? context.plan,
|
|
217
|
-
goal: applyChecks(context.goal, payload.checked),
|
|
218
|
+
goal: applyChecks(adoptProof(context.goal, payload.proved), payload.checked),
|
|
218
219
|
planMode: context.planMode && payload.leftPlanMode !== true,
|
|
219
220
|
pendingCall: null,
|
|
220
221
|
approval: { status: 'idle', key: null },
|
|
@@ -297,3 +298,20 @@ function applyChecks(goal, checked) {
|
|
|
297
298
|
checks: goal.checks.map((check) => checked.find(({ name }) => name === check.name) ?? check)
|
|
298
299
|
};
|
|
299
300
|
}
|
|
301
|
+
function adoptProof(goal, proved) {
|
|
302
|
+
if (!goal ||
|
|
303
|
+
!proved ||
|
|
304
|
+
!asksChecks(goal) ||
|
|
305
|
+
!existenceOnly(goal.checks.map((check) => check.name))) {
|
|
306
|
+
return goal;
|
|
307
|
+
}
|
|
308
|
+
const names = mergeChecks(goal.checks.map((check) => check.name), [proved.name]);
|
|
309
|
+
if (!names.length) {
|
|
310
|
+
return goal;
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
...goal,
|
|
314
|
+
checks: names.map((name) => goal.checks.find((check) => check.name === name) ?? proved),
|
|
315
|
+
named: true
|
|
316
|
+
};
|
|
317
|
+
}
|
|
@@ -42,6 +42,7 @@ export interface FinishedRound {
|
|
|
42
42
|
ctxSize?: number | undefined;
|
|
43
43
|
overflows?: number | undefined;
|
|
44
44
|
reasoningDeltas?: number | undefined;
|
|
45
|
+
keyed?: boolean | undefined;
|
|
45
46
|
}
|
|
46
47
|
export declare function foldMetrics(state: MetricsState, round: number, finished: FinishedRound): void;
|
|
47
48
|
type StoppedRound = Pick<FinishedRound, 'stats' | 'stopReason'> & {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isFailureResultReference } from '../../helpers/failure-result.js';
|
|
2
|
-
import { GOAL_CHECKS_ASK, GOAL_PROOF_ASK } from '../../helpers/goal-check.js';
|
|
2
|
+
import { asksChecks, GOAL_CHECKS_ASK, GOAL_PROOF_ASK } from '../../helpers/goal-check.js';
|
|
3
3
|
export function runsUnasked(facts) {
|
|
4
4
|
if (facts.permission === 'ask')
|
|
5
5
|
return false;
|
|
@@ -35,7 +35,7 @@ function planDone(plan) {
|
|
|
35
35
|
}
|
|
36
36
|
export function goalMet({ plan, goal }) {
|
|
37
37
|
const checks = goal?.checks ?? [];
|
|
38
|
-
return
|
|
38
|
+
return planDone(plan) && !(goal && asksChecks(goal)) && checks.every((check) => check.passed);
|
|
39
39
|
}
|
|
40
40
|
export function nudgeWithChecks(nudge, checks, unnamed) {
|
|
41
41
|
if (!checks.length) {
|
|
@@ -96,6 +96,9 @@ export function foldMetrics(state, round, finished) {
|
|
|
96
96
|
state.ctxSize = finished.ctxSize;
|
|
97
97
|
}
|
|
98
98
|
if (!stats) {
|
|
99
|
+
if (finished.keyed === false) {
|
|
100
|
+
delete state.cacheTokens;
|
|
101
|
+
}
|
|
99
102
|
return;
|
|
100
103
|
}
|
|
101
104
|
if (state.ttft === undefined && stats.timeToFirstToken) {
|
|
@@ -108,12 +111,15 @@ export function foldMetrics(state, round, finished) {
|
|
|
108
111
|
state.timedTokens += stats.generatedTokens;
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
|
-
if (stats.promptTokens) {
|
|
114
|
+
if (stats.promptTokens !== undefined) {
|
|
112
115
|
state.promptTokens = stats.promptTokens;
|
|
113
116
|
}
|
|
114
|
-
if (stats.cacheTokens) {
|
|
117
|
+
if (stats.cacheTokens !== undefined) {
|
|
115
118
|
state.cacheTokens = stats.cacheTokens;
|
|
116
119
|
}
|
|
120
|
+
if (finished.keyed === false && stats.cacheTokens === undefined) {
|
|
121
|
+
delete state.cacheTokens;
|
|
122
|
+
}
|
|
117
123
|
}
|
|
118
124
|
const ROUND_STATS = [
|
|
119
125
|
'promptTokens',
|
|
@@ -123,7 +129,7 @@ const ROUND_STATS = [
|
|
|
123
129
|
'tokensPerSecond',
|
|
124
130
|
'timeToFirstToken'
|
|
125
131
|
];
|
|
126
|
-
function roundSpeed(round, { stats, stopReason, durationMs, overflows, reasoningDeltas }) {
|
|
132
|
+
function roundSpeed(round, { stats, stopReason, durationMs, overflows, reasoningDeltas, keyed }) {
|
|
127
133
|
const speed = { round, durationMs: durationMs ?? 0 };
|
|
128
134
|
for (const key of ROUND_STATS) {
|
|
129
135
|
const value = stats?.[key];
|
|
@@ -131,6 +137,9 @@ function roundSpeed(round, { stats, stopReason, durationMs, overflows, reasoning
|
|
|
131
137
|
speed[key] = value;
|
|
132
138
|
}
|
|
133
139
|
}
|
|
140
|
+
if (keyed === false) {
|
|
141
|
+
speed.cacheTokens = 0;
|
|
142
|
+
}
|
|
134
143
|
if (stopReason) {
|
|
135
144
|
speed.stopReason = stopReason;
|
|
136
145
|
}
|
|
@@ -81,6 +81,7 @@ export interface RoundDonePayload {
|
|
|
81
81
|
response?: string;
|
|
82
82
|
history?: HistorySplice;
|
|
83
83
|
cacheable?: boolean;
|
|
84
|
+
keyed?: boolean;
|
|
84
85
|
fallbackResponse?: string;
|
|
85
86
|
cut?: string;
|
|
86
87
|
}
|
|
@@ -156,6 +157,7 @@ export interface ToolDonePayload {
|
|
|
156
157
|
plan?: PlanStep[];
|
|
157
158
|
leftPlanMode?: boolean;
|
|
158
159
|
checked?: GoalCheck[];
|
|
160
|
+
proved?: GoalCheck;
|
|
159
161
|
}
|
|
160
162
|
export interface BatchDonePayload {
|
|
161
163
|
history?: HistorySplice;
|
|
@@ -249,6 +251,7 @@ export interface RunPolicy {
|
|
|
249
251
|
maxToolRounds: number;
|
|
250
252
|
continuationNudge: string;
|
|
251
253
|
deliveredNudge: string;
|
|
254
|
+
wrapUpNudge?: string;
|
|
252
255
|
deniedMessage: string;
|
|
253
256
|
cutOffMessage: string;
|
|
254
257
|
contextBoundaryMessage: string;
|
|
@@ -344,8 +344,16 @@ export class PluginRegistry {
|
|
|
344
344
|
}
|
|
345
345
|
};
|
|
346
346
|
}
|
|
347
|
-
unload() {
|
|
348
|
-
|
|
347
|
+
async unload() {
|
|
348
|
+
const setups = [...this._held];
|
|
349
|
+
const outcomes = await Promise.allSettled(setups.map((setup) => setup.unload?.()));
|
|
350
|
+
outcomes.forEach((outcome, index) => {
|
|
351
|
+
if (outcome.status === 'fulfilled' &&
|
|
352
|
+
!this._loaded.some((loaded) => loaded.setup === setups[index])) {
|
|
353
|
+
this._forget(setups[index]);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
return outcomes;
|
|
349
357
|
}
|
|
350
358
|
unloadIdle() {
|
|
351
359
|
return Promise.allSettled(this._held.map(async (setup) => setup.unloadIdle?.()));
|
|
@@ -445,27 +453,58 @@ export class PluginRegistry {
|
|
|
445
453
|
await this._runtime.add(this._plugin(plugin, ++this._revision, place));
|
|
446
454
|
}
|
|
447
455
|
catch (error) {
|
|
448
|
-
|
|
449
|
-
|
|
456
|
+
const acquired = this._held.slice(setups);
|
|
457
|
+
const outcomes = await Promise.allSettled(acquired.map((setup) => setup.unload?.()));
|
|
458
|
+
const failures = [error];
|
|
459
|
+
outcomes.forEach((outcome, index) => {
|
|
460
|
+
if (outcome.status === 'fulfilled') {
|
|
461
|
+
this._forget(acquired[index]);
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
failures.push(outcome.reason);
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
throw failures.length === 1
|
|
468
|
+
? error
|
|
469
|
+
: new AggregateError(failures, 'Plugin setup and model cleanup failed', { cause: error });
|
|
450
470
|
}
|
|
451
471
|
}
|
|
452
472
|
async _drop(name) {
|
|
453
473
|
const index = this._loaded.findIndex((loaded) => loaded.plugin.name === name);
|
|
454
474
|
const [{ plugin, setup }] = this._loaded.splice(index, 1);
|
|
455
|
-
this._held.splice(this._held.indexOf(setup), 1);
|
|
456
475
|
const errors = this._cleanupErrors.length;
|
|
476
|
+
const failures = [];
|
|
457
477
|
try {
|
|
458
478
|
await this._runtime.remove(name);
|
|
459
479
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
480
|
+
catch (error) {
|
|
481
|
+
failures.push(error);
|
|
482
|
+
}
|
|
483
|
+
this._cleanupErrors.length = errors;
|
|
484
|
+
for (const service of plugin.provides ?? []) {
|
|
485
|
+
this._services.delete(service);
|
|
486
|
+
}
|
|
487
|
+
try {
|
|
465
488
|
await setup.unload?.();
|
|
489
|
+
this._forget(setup);
|
|
490
|
+
}
|
|
491
|
+
catch (error) {
|
|
492
|
+
failures.push(error);
|
|
493
|
+
}
|
|
494
|
+
if (failures.length === 1) {
|
|
495
|
+
throw failures[0];
|
|
496
|
+
}
|
|
497
|
+
if (failures.length > 1) {
|
|
498
|
+
throw new AggregateError(failures, `Plugin '${name}' removal and model cleanup failed`);
|
|
466
499
|
}
|
|
467
500
|
return index;
|
|
468
501
|
}
|
|
502
|
+
_forget(setup) {
|
|
503
|
+
const index = this._held.indexOf(setup);
|
|
504
|
+
if (index !== -1) {
|
|
505
|
+
this._held.splice(index, 1);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
469
508
|
_check(plugin, replacing) {
|
|
470
509
|
const others = this._loaded
|
|
471
510
|
.map((loaded) => loaded.plugin)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ScopeLock from 'scope-lock';
|
|
2
2
|
import { HarnessError } from '../errors.js';
|
|
3
3
|
import { errorMessage, isRecord } from '../guards.js';
|
|
4
|
+
import { androidCpuPlacement } from '../hardware/cpu-placement.js';
|
|
4
5
|
import { AbortedError, raceAbort } from '../helpers/race-abort.js';
|
|
5
6
|
import { HarnessLog } from '../log.js';
|
|
6
7
|
import { ContextChoice as ContextClimb } from '../models/context-choice.js';
|
|
@@ -259,6 +260,7 @@ export class Residency {
|
|
|
259
260
|
slots: this._slots,
|
|
260
261
|
mainGpu: resolveMainGpu,
|
|
261
262
|
openclCacheDir,
|
|
263
|
+
cpuPlacement: androidCpuPlacement,
|
|
262
264
|
contextFor: (key) => this._contexts.chosen(key) ?? this.fit.chosen(key),
|
|
263
265
|
slotsFor: (key) => this.fit.chosenSlots(key)
|
|
264
266
|
};
|
package/dist-lib/lib/serve.js
CHANGED
|
@@ -8,6 +8,7 @@ import { bindApi } from '../spec/bind.js';
|
|
|
8
8
|
import HRPC from '../spec/hrpc/index.js';
|
|
9
9
|
import { encode } from '../spec/hrpc/messages.js';
|
|
10
10
|
import { checkGoal, checkMaxToolRounds } from './capabilities/tool-turns.js';
|
|
11
|
+
import { acceptsInput, inputBytes } from './helpers/input-budget.js';
|
|
11
12
|
import { isCapability } from './capabilities/invoke.js';
|
|
12
13
|
import { CUSTOM_TASK_TYPES } from './models/model-catalog.js';
|
|
13
14
|
import { unsupportedKvCacheDeletion } from './capabilities/kv-cache.js';
|
|
@@ -153,11 +154,7 @@ function startPayloadFrom(value) {
|
|
|
153
154
|
});
|
|
154
155
|
}
|
|
155
156
|
if (isRecord(value.knowledge)) {
|
|
156
|
-
|
|
157
|
-
if (!Array.isArray(scopes) || !scopes.every((scope) => typeof scope === 'string')) {
|
|
158
|
-
throw new TypeError('Invalid knowledge grant');
|
|
159
|
-
}
|
|
160
|
-
payload.knowledge = { scopes };
|
|
157
|
+
payload.knowledge = knowledgeGrant(value.knowledge);
|
|
161
158
|
}
|
|
162
159
|
if (value.planMode === true) {
|
|
163
160
|
payload.planMode = true;
|
|
@@ -461,11 +458,12 @@ export function serveHarness(stream, harness) {
|
|
|
461
458
|
}
|
|
462
459
|
return harness.knowledgeRemove(artifactId);
|
|
463
460
|
},
|
|
464
|
-
knowledgeSearch: async ({ text, scopes, k }) => {
|
|
461
|
+
knowledgeSearch: async ({ text, scopes, k, focus }) => {
|
|
465
462
|
if (!harness.knowledgeSearch) {
|
|
466
463
|
throw unsupportedKnowledge();
|
|
467
464
|
}
|
|
468
|
-
|
|
465
|
+
const query = { text, scopes, k: k || undefined, focus: focus?.length ? focus : undefined };
|
|
466
|
+
return { hits: await harness.knowledgeSearch(query) };
|
|
469
467
|
},
|
|
470
468
|
knowledgeStatus: async () => {
|
|
471
469
|
if (!harness.knowledgeStatus) {
|
|
@@ -642,6 +640,8 @@ function runFrame(harness, frame, context) {
|
|
|
642
640
|
});
|
|
643
641
|
}
|
|
644
642
|
function completion(harness) {
|
|
643
|
+
let writeTurn = Promise.resolve();
|
|
644
|
+
const waitForWriteTurn = () => (writeTurn = writeTurn.then(tick));
|
|
645
645
|
return async function* (duplex) {
|
|
646
646
|
const events = pushQueue({ highWaterMark: WIRE_HIGH_WATER_MARK });
|
|
647
647
|
const pending = new Map();
|
|
@@ -650,7 +650,19 @@ function completion(harness) {
|
|
|
650
650
|
const pendingQuestion = new Map();
|
|
651
651
|
const pendingDrive = new Map();
|
|
652
652
|
const pendingRunLog = new Map();
|
|
653
|
-
const
|
|
653
|
+
const inputQueue = pushQueue();
|
|
654
|
+
let queuedInputCount = 0;
|
|
655
|
+
let queuedInputBytes = 0;
|
|
656
|
+
let inputLimitNotified = false;
|
|
657
|
+
const input = {
|
|
658
|
+
async *[Symbol.asyncIterator]() {
|
|
659
|
+
for await (const item of inputQueue) {
|
|
660
|
+
queuedInputCount--;
|
|
661
|
+
queuedInputBytes -= inputBytes(item);
|
|
662
|
+
yield item;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
};
|
|
654
666
|
const controller = new AbortController();
|
|
655
667
|
const rounds = new RoundPort((event) => events.push(event));
|
|
656
668
|
let calls = 0;
|
|
@@ -688,7 +700,7 @@ function completion(harness) {
|
|
|
688
700
|
}
|
|
689
701
|
pendingRunLog.clear();
|
|
690
702
|
rounds.close();
|
|
691
|
-
|
|
703
|
+
inputQueue.end();
|
|
692
704
|
events.end();
|
|
693
705
|
};
|
|
694
706
|
duplex.on('close', gone);
|
|
@@ -801,11 +813,27 @@ function completion(harness) {
|
|
|
801
813
|
return;
|
|
802
814
|
}
|
|
803
815
|
if (frame.type === 'steer' || frame.type === 'follow-up') {
|
|
804
|
-
|
|
816
|
+
const item = {
|
|
805
817
|
mode: frame.type,
|
|
806
818
|
text: frame.messages?.[0]?.content ?? '',
|
|
807
819
|
id: frame.callId || undefined
|
|
808
|
-
}
|
|
820
|
+
};
|
|
821
|
+
const bytes = inputBytes(item);
|
|
822
|
+
if (!acceptsInput(queuedInputCount, queuedInputBytes, item)) {
|
|
823
|
+
if (!inputLimitNotified) {
|
|
824
|
+
inputLimitNotified = true;
|
|
825
|
+
void events.push({
|
|
826
|
+
type: 'input-rejected',
|
|
827
|
+
text: 'Input queue limit exceeded; one or more inputs were rejected'
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
else {
|
|
832
|
+
inputLimitNotified = false;
|
|
833
|
+
queuedInputCount++;
|
|
834
|
+
queuedInputBytes += bytes;
|
|
835
|
+
void inputQueue.push(item);
|
|
836
|
+
}
|
|
809
837
|
return;
|
|
810
838
|
}
|
|
811
839
|
if (frame.type === 'run-log-result') {
|
|
@@ -1071,7 +1099,7 @@ function completion(harness) {
|
|
|
1071
1099
|
await text.flush();
|
|
1072
1100
|
events.push({ type: 'error', message: errorMessage(err) });
|
|
1073
1101
|
}
|
|
1074
|
-
|
|
1102
|
+
inputQueue.end();
|
|
1075
1103
|
events.push({ type: 'done' });
|
|
1076
1104
|
HarnessLog.debug('wire end', { produced, frames });
|
|
1077
1105
|
events.end();
|
|
@@ -1082,16 +1110,18 @@ function completion(harness) {
|
|
|
1082
1110
|
encode('@harness/completion-event', event);
|
|
1083
1111
|
}
|
|
1084
1112
|
catch (err) {
|
|
1113
|
+
await waitForWriteTurn();
|
|
1085
1114
|
yield { type: 'error', message: `cannot encode ${event.type} event: ${errorMessage(err)}` };
|
|
1086
|
-
await
|
|
1115
|
+
await waitForWriteTurn();
|
|
1087
1116
|
yield { type: 'done' };
|
|
1088
|
-
await
|
|
1117
|
+
await waitForWriteTurn();
|
|
1089
1118
|
gone();
|
|
1090
1119
|
return;
|
|
1091
1120
|
}
|
|
1121
|
+
await waitForWriteTurn();
|
|
1092
1122
|
yield event;
|
|
1093
|
-
await tick();
|
|
1094
1123
|
}
|
|
1124
|
+
await waitForWriteTurn();
|
|
1095
1125
|
HarnessLog.info('wire handed off');
|
|
1096
1126
|
};
|
|
1097
1127
|
}
|
|
@@ -1218,3 +1248,14 @@ function downloadStream(harness, req) {
|
|
|
1218
1248
|
};
|
|
1219
1249
|
return stream;
|
|
1220
1250
|
}
|
|
1251
|
+
function knowledgeGrant({ scopes, focus, k }) {
|
|
1252
|
+
if (!isStrings(scopes) ||
|
|
1253
|
+
(focus !== undefined && !isStrings(focus)) ||
|
|
1254
|
+
(k !== undefined && !(typeof k === 'number' && Number.isSafeInteger(k) && k > 0))) {
|
|
1255
|
+
throw new TypeError('Invalid knowledge grant');
|
|
1256
|
+
}
|
|
1257
|
+
return { scopes, focus, k };
|
|
1258
|
+
}
|
|
1259
|
+
function isStrings(value) {
|
|
1260
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'string');
|
|
1261
|
+
}
|
|
@@ -51,8 +51,8 @@ export function createGlobTool({ realpath = defaultRealpath, deniedRoots } = {})
|
|
|
51
51
|
if (isDeniedPath(file.path, deny) || !(test(rel) || (byName && test(name)))) {
|
|
52
52
|
continue;
|
|
53
53
|
}
|
|
54
|
-
const
|
|
55
|
-
hits.push({ path: shownPath(file.path, anchorOf(ctx)), mtime
|
|
54
|
+
const mtime = file.mtime ?? (await target.root.drive.entry(file.key))?.mtime ?? 0;
|
|
55
|
+
hits.push({ path: shownPath(file.path, anchorOf(ctx)), mtime });
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
hits.sort((a, b) => b.mtime - a.mtime);
|