@qvac/harness 0.7.0 → 1.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -1
- package/README.md +239 -2
- package/dist-lib/index.d.ts +58 -3
- package/dist-lib/index.js +736 -239
- package/dist-lib/lib/capabilities/completion-engine/abort-polyfill.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/abort-polyfill.js +10 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/answering.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/answering.js +17 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/approval.d.ts +4 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/approval.js +29 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.d.ts +4 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.js +73 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/execute.d.ts +41 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/execute.js +49 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +102 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.d.ts +47 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +87 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/finishing.d.ts +2 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/finishing.js +32 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/inspect-preload.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/inspect-preload.js +75 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +152 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +94 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/preload-failure.d.ts +9 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/preload-failure.js +11 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/preloading.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/preloading.js +114 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +198 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.js +71 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/rejection.d.ts +18 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/rejection.js +70 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +60 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +21 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +48 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +156 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.d.ts +7 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +61 -0
- package/dist-lib/lib/capabilities/completion-engine/driver.d.ts +25 -0
- package/dist-lib/lib/capabilities/completion-engine/driver.js +553 -0
- package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +61 -0
- package/dist-lib/lib/capabilities/completion-engine/durable.js +150 -0
- package/dist-lib/lib/capabilities/completion-engine/operations.d.ts +6 -0
- package/dist-lib/lib/capabilities/completion-engine/operations.js +239 -0
- package/dist-lib/lib/capabilities/completion-engine/ports.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/ports.js +267 -0
- package/dist-lib/lib/capabilities/completion-engine/session.d.ts +76 -0
- package/dist-lib/lib/capabilities/completion-engine/session.js +70 -0
- package/dist-lib/lib/capabilities/completion-loop/index.d.ts +80 -0
- package/dist-lib/lib/capabilities/completion-loop/index.js +158 -0
- package/dist-lib/lib/capabilities/completion-loop/metrics.d.ts +5 -0
- package/dist-lib/lib/capabilities/completion-loop/metrics.js +29 -0
- package/dist-lib/lib/capabilities/completion-loop/round.d.ts +33 -0
- package/dist-lib/lib/capabilities/completion-loop/round.js +353 -0
- package/dist-lib/lib/capabilities/completion-loop/tool-execution.d.ts +60 -0
- package/dist-lib/lib/capabilities/completion-loop/tool-execution.js +270 -0
- package/dist-lib/lib/capabilities/completion-loop/turns.d.ts +23 -0
- package/dist-lib/lib/capabilities/completion-loop/turns.js +112 -0
- package/dist-lib/lib/capabilities/completion-runtime.d.ts +46 -0
- package/dist-lib/lib/capabilities/completion-runtime.js +74 -0
- package/dist-lib/lib/capabilities/completion.d.ts +18 -335
- package/dist-lib/lib/capabilities/completion.js +20 -1301
- package/dist-lib/lib/capabilities/download.d.ts +1 -1
- package/dist-lib/lib/capabilities/download.js +7 -2
- package/dist-lib/lib/capabilities/invoke.js +5 -3
- package/dist-lib/lib/capabilities/tool-plan.d.ts +35 -0
- package/dist-lib/lib/capabilities/tool-plan.js +66 -0
- package/dist-lib/lib/capabilities/tool-turns.d.ts +11 -2
- package/dist-lib/lib/capabilities/tool-turns.js +30 -2
- package/dist-lib/lib/capabilities/types.d.ts +287 -0
- package/dist-lib/lib/capabilities/types.js +1 -0
- package/dist-lib/lib/completion-lifecycle.d.ts +14 -0
- package/dist-lib/lib/completion-lifecycle.js +126 -0
- package/dist-lib/lib/connect.d.ts +10 -3
- package/dist-lib/lib/connect.js +329 -23
- package/dist-lib/lib/contract-types.d.ts +19 -2
- package/dist-lib/lib/harness-lifecycle.d.ts +66 -0
- package/dist-lib/lib/harness-lifecycle.js +129 -0
- package/dist-lib/lib/helpers/detach-json.d.ts +1 -0
- package/dist-lib/lib/helpers/detach-json.js +146 -0
- package/dist-lib/lib/helpers/markup-scanner.d.ts +26 -0
- package/dist-lib/lib/helpers/markup-scanner.js +156 -0
- package/dist-lib/lib/helpers/markup-stream-filter.js +138 -35
- package/dist-lib/lib/helpers/race-abort.d.ts +9 -4
- package/dist-lib/lib/helpers/race-abort.js +2 -7
- package/dist-lib/lib/helpers/recovery-required.d.ts +1 -0
- package/dist-lib/lib/helpers/recovery-required.js +1 -0
- package/dist-lib/lib/helpers/run-outcome.d.ts +10 -2
- package/dist-lib/lib/helpers/run-outcome.js +8 -5
- package/dist-lib/lib/helpers/tool-call-markup.d.ts +2 -0
- package/dist-lib/lib/helpers/tool-call-markup.js +197 -82
- package/dist-lib/lib/hooks/built-in/arg-repair.d.ts +1 -0
- package/dist-lib/lib/hooks/built-in/arg-repair.js +1 -0
- package/dist-lib/lib/hooks/built-in/egress.d.ts +1 -0
- package/dist-lib/lib/hooks/built-in/egress.js +2 -1
- package/dist-lib/lib/hooks/built-in/sandbox.d.ts +1 -0
- package/dist-lib/lib/hooks/built-in/sandbox.js +6 -1
- package/dist-lib/lib/hooks/built-in/skill-catalog.d.ts +1 -0
- package/dist-lib/lib/hooks/built-in/skill-catalog.js +2 -1
- package/dist-lib/lib/hooks/pipeline.d.ts +4 -1
- package/dist-lib/lib/hooks/pipeline.js +24 -2
- package/dist-lib/lib/hooks/run.d.ts +2 -1
- package/dist-lib/lib/hooks/run.js +19 -7
- package/dist-lib/lib/hooks/types.d.ts +17 -6
- package/dist-lib/lib/machine/completion/actions/approval.d.ts +3 -0
- package/dist-lib/lib/machine/completion/actions/approval.js +16 -0
- package/dist-lib/lib/machine/completion/actions/completion.d.ts +23 -0
- package/dist-lib/lib/machine/completion/actions/completion.js +142 -0
- package/dist-lib/lib/machine/completion/actions/skills.d.ts +9 -0
- package/dist-lib/lib/machine/completion/actions/skills.js +83 -0
- package/dist-lib/lib/machine/completion/actions/tools.d.ts +16 -0
- package/dist-lib/lib/machine/completion/actions/tools.js +173 -0
- package/dist-lib/lib/machine/completion/context.d.ts +9 -0
- package/dist-lib/lib/machine/completion/context.js +44 -0
- package/dist-lib/lib/machine/completion/contract.d.ts +6 -0
- package/dist-lib/lib/machine/completion/contract.js +1 -0
- package/dist-lib/lib/machine/completion/guards/retry.d.ts +9 -0
- package/dist-lib/lib/machine/completion/guards/retry.js +25 -0
- package/dist-lib/lib/machine/completion/implementations.d.ts +81 -0
- package/dist-lib/lib/machine/completion/implementations.js +152 -0
- package/dist-lib/lib/machine/completion/machine.d.ts +375 -0
- package/dist-lib/lib/machine/completion/machine.js +511 -0
- package/dist-lib/lib/machine/completion/ports.d.ts +65 -0
- package/dist-lib/lib/machine/completion/ports.js +224 -0
- package/dist-lib/lib/machine/completion/rules.d.ts +39 -0
- package/dist-lib/lib/machine/completion/rules.js +115 -0
- package/dist-lib/lib/machine/completion/types.d.ts +493 -0
- package/dist-lib/lib/machine/completion/types.js +1 -0
- package/dist-lib/lib/machine/engine.d.ts +93 -0
- package/dist-lib/lib/machine/engine.js +483 -0
- package/dist-lib/lib/machine/errors.d.ts +44 -0
- package/dist-lib/lib/machine/errors.js +373 -0
- package/dist-lib/lib/machine/guards.d.ts +2 -0
- package/dist-lib/lib/machine/guards.js +6 -0
- package/dist-lib/lib/machine/index.d.ts +20 -0
- package/dist-lib/lib/machine/index.js +11 -0
- package/dist-lib/lib/machine/replay-output.d.ts +24 -0
- package/dist-lib/lib/machine/replay-output.js +50 -0
- package/dist-lib/lib/machine/stable-stringify.d.ts +1 -0
- package/dist-lib/lib/machine/stable-stringify.js +11 -0
- package/dist-lib/lib/models/model-handle.d.ts +5 -1
- package/dist-lib/lib/models/model-handle.js +8 -3
- package/dist-lib/lib/models/model-list.d.ts +5 -3
- package/dist-lib/lib/models/model-pool.d.ts +18 -7
- package/dist-lib/lib/models/model-pool.js +126 -38
- package/dist-lib/lib/run-log/history-codec.d.ts +23 -0
- package/dist-lib/lib/run-log/history-codec.js +973 -0
- package/dist-lib/lib/run-log/patch.d.ts +6 -0
- package/dist-lib/lib/run-log/patch.js +93 -0
- package/dist-lib/lib/run-log/persisted-actor.d.ts +18 -0
- package/dist-lib/lib/run-log/persisted-actor.js +218 -0
- package/dist-lib/lib/run-log/protocol-types.d.ts +153 -0
- package/dist-lib/lib/run-log/protocol-types.js +1 -0
- package/dist-lib/lib/run-log/protocol.d.ts +27 -0
- package/dist-lib/lib/run-log/protocol.js +1056 -0
- package/dist-lib/lib/run-log/replay.d.ts +25 -0
- package/dist-lib/lib/run-log/replay.js +129 -0
- package/dist-lib/lib/run-log/run-journal.d.ts +125 -0
- package/dist-lib/lib/run-log/run-journal.js +783 -0
- package/dist-lib/lib/run-log-inspect.d.ts +25 -0
- package/dist-lib/lib/run-log-inspect.js +627 -0
- package/dist-lib/lib/run-log-protocol.d.ts +2 -0
- package/dist-lib/lib/run-log-protocol.js +1 -0
- package/dist-lib/lib/run-log-redact.d.ts +27 -0
- package/dist-lib/lib/run-log-redact.js +1107 -0
- package/dist-lib/lib/serve.js +308 -12
- package/dist-lib/lib/spawn.js +3 -2
- package/dist-lib/lib/tool-call-display.d.ts +1 -21
- package/dist-lib/lib/tools/exec.d.ts +2 -1
- package/dist-lib/lib/tools/exec.js +57 -2
- package/dist-lib/lib/tools/generate-image.js +1 -1
- package/dist-lib/lib/tools/generate-music.js +1 -1
- package/dist-lib/lib/tools/http-request.d.ts +2 -1
- package/dist-lib/lib/tools/http-request.js +2 -1
- package/dist-lib/lib/tools/mcp-call.js +8 -1
- package/dist-lib/lib/tools/operations/builders.d.ts +1 -0
- package/dist-lib/lib/tools/operations/builders.js +1 -0
- package/dist-lib/lib/tools/operations/compile.js +11 -1
- package/dist-lib/lib/tools/operations/manifest.js +1 -0
- package/dist-lib/lib/tools/outbound-guard.d.ts +8 -6
- package/dist-lib/lib/tools/outbound-guard.js +25 -8
- package/dist-lib/lib/tools/skills/catalog.d.ts +1 -0
- package/dist-lib/lib/tools/skills/catalog.js +35 -0
- package/dist-lib/lib/tools/skills/cli-schema-types.d.ts +1 -0
- package/dist-lib/lib/tools/skills/cli-schema.js +25 -0
- package/dist-lib/lib/wire.d.ts +5 -0
- package/dist-lib/lib/wire.js +128 -5
- package/dist-lib/schema/harness.js +22 -6
- package/dist-lib/spec/hrpc/messages.js +100 -18
- package/dist-lib/spec/hyperschema/index.js +100 -18
- package/dist-lib/spec/hyperschema/schema.json +74 -1
- package/dist-lib/spec/hyperschema/types.d.ts +11 -3
- package/package.json +19 -1
- package/patches/@qvac%2Finference@0.20.0.patch +67 -0
- package/patches/bare-stow@0.1.5.patch +68 -0
- package/patches/hypercore-blob-server@1.15.0.patch +15 -0
- package/patches/localwatch@1.4.3.patch +13 -0
- package/patches/pyodide@314.0.2.patch +144 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
export class RecoveryRequired extends Error {
|
|
2
|
+
operation;
|
|
3
|
+
constructor(operation) {
|
|
4
|
+
super(`The outcome of ${operation.name} (${operation.id}) is uncertain. Supply its result or explicitly authorize a retry.${operation.reason ? ` ${operation.reason}` : ''}`);
|
|
5
|
+
this.operation = operation;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export class AbortedError extends Error {
|
|
9
|
+
constructor() {
|
|
10
|
+
super('aborted');
|
|
11
|
+
this.name = 'AbortedError';
|
|
12
|
+
Error.captureStackTrace?.(this, AbortedError);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class ToolPolicyChanged extends Error {
|
|
16
|
+
constructor(tool) {
|
|
17
|
+
super(`Tool effect changed after approval: ${tool}`);
|
|
18
|
+
this.name = 'ToolPolicyChanged';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export const EFFECT_DRAIN_TIMEOUT_MS = 5000;
|
|
22
|
+
const TIMED_OUT = Symbol('timed-out');
|
|
23
|
+
export async function raceDrain(promise, timeoutMs = EFFECT_DRAIN_TIMEOUT_MS) {
|
|
24
|
+
let timer;
|
|
25
|
+
const timeout = new Promise((resolve) => {
|
|
26
|
+
timer = setTimeout(() => resolve(TIMED_OUT), timeoutMs);
|
|
27
|
+
});
|
|
28
|
+
try {
|
|
29
|
+
return await Promise.race([promise, timeout]);
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
if (timer !== undefined) {
|
|
33
|
+
clearTimeout(timer);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function didDrainTimeOut(value) {
|
|
38
|
+
return value === TIMED_OUT;
|
|
39
|
+
}
|
|
40
|
+
const CAUSE_DEPTH = 3;
|
|
41
|
+
function tagCause(error, depth) {
|
|
42
|
+
if (depth <= 0 || error === undefined || error === null)
|
|
43
|
+
return undefined;
|
|
44
|
+
const object = typeof error === 'object' || typeof error === 'function' ? error : undefined;
|
|
45
|
+
const ownMessage = object ? ownData(object, 'message') : undefined;
|
|
46
|
+
let message;
|
|
47
|
+
if (error instanceof Error) {
|
|
48
|
+
message = error.message;
|
|
49
|
+
}
|
|
50
|
+
else if (typeof ownMessage === 'string') {
|
|
51
|
+
message = ownMessage;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
message = errorMessage(error);
|
|
55
|
+
}
|
|
56
|
+
let name = 'Error';
|
|
57
|
+
if (error instanceof Error) {
|
|
58
|
+
name = error.name;
|
|
59
|
+
}
|
|
60
|
+
else if (object && typeof ownData(object, 'name') === 'string') {
|
|
61
|
+
name = ownData(object, 'name');
|
|
62
|
+
}
|
|
63
|
+
const code = object && typeof ownData(object, 'code') === 'string'
|
|
64
|
+
?
|
|
65
|
+
ownData(object, 'code')
|
|
66
|
+
: undefined;
|
|
67
|
+
const stack = error instanceof Error ? error.stack : undefined;
|
|
68
|
+
const cause = object ? tagCause(ownData(object, 'cause'), depth - 1) : undefined;
|
|
69
|
+
const taggedCause = { message, name };
|
|
70
|
+
if (code) {
|
|
71
|
+
taggedCause.code = code;
|
|
72
|
+
}
|
|
73
|
+
if (stack) {
|
|
74
|
+
taggedCause.stack = stack;
|
|
75
|
+
}
|
|
76
|
+
if (cause) {
|
|
77
|
+
taggedCause.cause = cause;
|
|
78
|
+
}
|
|
79
|
+
return taggedCause;
|
|
80
|
+
}
|
|
81
|
+
function ownData(object, key) {
|
|
82
|
+
try {
|
|
83
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, key);
|
|
84
|
+
return descriptor && 'value' in descriptor ? descriptor.value : undefined;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function jsonClone(value) {
|
|
91
|
+
const active = new Set();
|
|
92
|
+
const clone = (current) => {
|
|
93
|
+
if (current === null ||
|
|
94
|
+
typeof current === 'string' ||
|
|
95
|
+
typeof current === 'boolean' ||
|
|
96
|
+
(typeof current === 'number' && Number.isFinite(current))) {
|
|
97
|
+
return current;
|
|
98
|
+
}
|
|
99
|
+
if (typeof current !== 'object')
|
|
100
|
+
throw new TypeError('Not JSON data');
|
|
101
|
+
if (active.has(current))
|
|
102
|
+
throw new TypeError('Circular JSON data');
|
|
103
|
+
active.add(current);
|
|
104
|
+
try {
|
|
105
|
+
if (Array.isArray(current)) {
|
|
106
|
+
const result = [];
|
|
107
|
+
for (let index = 0; index < current.length; index++) {
|
|
108
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, String(index));
|
|
109
|
+
result.push(descriptor && 'value' in descriptor ? clone(descriptor.value) : null);
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
const prototype = Object.getPrototypeOf(current);
|
|
114
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
115
|
+
throw new TypeError('Not a plain JSON object');
|
|
116
|
+
}
|
|
117
|
+
const result = {};
|
|
118
|
+
for (const key of Object.keys(current)) {
|
|
119
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, key);
|
|
120
|
+
if (!descriptor || !('value' in descriptor)) {
|
|
121
|
+
throw new TypeError('Not JSON data');
|
|
122
|
+
}
|
|
123
|
+
Object.defineProperty(result, key, {
|
|
124
|
+
value: clone(descriptor.value),
|
|
125
|
+
enumerable: true,
|
|
126
|
+
configurable: true,
|
|
127
|
+
writable: true
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
active.delete(current);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
return clone(value);
|
|
137
|
+
}
|
|
138
|
+
function normalizeOperation(value) {
|
|
139
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
let argsDescriptor;
|
|
143
|
+
try {
|
|
144
|
+
argsDescriptor = Object.getOwnPropertyDescriptor(value, 'args');
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
const id = ownData(value, 'id');
|
|
150
|
+
const name = ownData(value, 'name');
|
|
151
|
+
const effect = ownData(value, 'effect');
|
|
152
|
+
const args = ownData(value, 'args');
|
|
153
|
+
if (typeof id !== 'string' ||
|
|
154
|
+
typeof name !== 'string' ||
|
|
155
|
+
(effect !== 'read' && effect !== 'write') ||
|
|
156
|
+
!argsDescriptor ||
|
|
157
|
+
!('value' in argsDescriptor)) {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
const reason = ownData(value, 'reason');
|
|
162
|
+
const operation = {
|
|
163
|
+
id,
|
|
164
|
+
name,
|
|
165
|
+
args: jsonClone(args),
|
|
166
|
+
effect
|
|
167
|
+
};
|
|
168
|
+
if (typeof reason === 'string') {
|
|
169
|
+
operation.reason = reason;
|
|
170
|
+
}
|
|
171
|
+
return operation;
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function normalizeTaggedEngineError(value) {
|
|
178
|
+
if (!value || typeof value !== 'object')
|
|
179
|
+
return undefined;
|
|
180
|
+
const tag = ownData(value, 'tag');
|
|
181
|
+
const message = ownData(value, 'message');
|
|
182
|
+
const name = ownData(value, 'name');
|
|
183
|
+
const stack = ownData(value, 'stack');
|
|
184
|
+
if (typeof message !== 'string' || typeof name !== 'string') {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
if (tag === 'aborted') {
|
|
188
|
+
const aborted = { tag, message, name };
|
|
189
|
+
if (typeof stack === 'string') {
|
|
190
|
+
aborted.stack = stack;
|
|
191
|
+
}
|
|
192
|
+
return aborted;
|
|
193
|
+
}
|
|
194
|
+
if (tag === 'failed') {
|
|
195
|
+
const code = ownData(value, 'code');
|
|
196
|
+
const cause = ownData(value, 'cause');
|
|
197
|
+
const taggedCause = tagCause(cause, CAUSE_DEPTH);
|
|
198
|
+
const failed = {
|
|
199
|
+
tag,
|
|
200
|
+
message,
|
|
201
|
+
name
|
|
202
|
+
};
|
|
203
|
+
if (typeof code === 'string') {
|
|
204
|
+
failed.code = code;
|
|
205
|
+
}
|
|
206
|
+
if (typeof stack === 'string') {
|
|
207
|
+
failed.stack = stack;
|
|
208
|
+
}
|
|
209
|
+
if (taggedCause) {
|
|
210
|
+
failed.cause = taggedCause;
|
|
211
|
+
}
|
|
212
|
+
return failed;
|
|
213
|
+
}
|
|
214
|
+
if (tag === 'recovery') {
|
|
215
|
+
const operation = normalizeOperation(ownData(value, 'operation'));
|
|
216
|
+
if (!operation) {
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
const recovery = {
|
|
220
|
+
tag,
|
|
221
|
+
message,
|
|
222
|
+
name,
|
|
223
|
+
operation
|
|
224
|
+
};
|
|
225
|
+
if (typeof stack === 'string') {
|
|
226
|
+
recovery.stack = stack;
|
|
227
|
+
}
|
|
228
|
+
return recovery;
|
|
229
|
+
}
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
export function tagError(error) {
|
|
233
|
+
const tagged = normalizeTaggedEngineError(error);
|
|
234
|
+
if (tagged) {
|
|
235
|
+
return tagged;
|
|
236
|
+
}
|
|
237
|
+
const object = error && (typeof error === 'object' || typeof error === 'function') ? error : undefined;
|
|
238
|
+
const ownMessage = object ? ownData(object, 'message') : undefined;
|
|
239
|
+
let message;
|
|
240
|
+
if (error instanceof Error) {
|
|
241
|
+
message = error.message;
|
|
242
|
+
}
|
|
243
|
+
else if (typeof ownMessage === 'string') {
|
|
244
|
+
message = ownMessage;
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
message = errorMessage(error);
|
|
248
|
+
}
|
|
249
|
+
let name = 'Error';
|
|
250
|
+
if (error instanceof Error) {
|
|
251
|
+
name = error.name;
|
|
252
|
+
}
|
|
253
|
+
else if (object && typeof ownData(object, 'name') === 'string') {
|
|
254
|
+
name = ownData(object, 'name');
|
|
255
|
+
}
|
|
256
|
+
const stack = error instanceof Error ? error.stack : undefined;
|
|
257
|
+
if (error instanceof RecoveryRequired) {
|
|
258
|
+
const operation = normalizeOperation(error.operation);
|
|
259
|
+
if (operation) {
|
|
260
|
+
const recovery = {
|
|
261
|
+
tag: 'recovery',
|
|
262
|
+
message,
|
|
263
|
+
name,
|
|
264
|
+
operation
|
|
265
|
+
};
|
|
266
|
+
if (stack) {
|
|
267
|
+
recovery.stack = stack;
|
|
268
|
+
}
|
|
269
|
+
return recovery;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (error instanceof AbortedError) {
|
|
273
|
+
const aborted = { tag: 'aborted', message, name };
|
|
274
|
+
if (stack) {
|
|
275
|
+
aborted.stack = stack;
|
|
276
|
+
}
|
|
277
|
+
return aborted;
|
|
278
|
+
}
|
|
279
|
+
let code;
|
|
280
|
+
if (object && typeof ownData(object, 'code') === 'string') {
|
|
281
|
+
code = ownData(object, 'code');
|
|
282
|
+
}
|
|
283
|
+
const cause = object ? tagCause(ownData(object, 'cause'), CAUSE_DEPTH) : undefined;
|
|
284
|
+
const failed = {
|
|
285
|
+
tag: 'failed',
|
|
286
|
+
message,
|
|
287
|
+
name
|
|
288
|
+
};
|
|
289
|
+
if (code) {
|
|
290
|
+
failed.code = code;
|
|
291
|
+
}
|
|
292
|
+
if (stack) {
|
|
293
|
+
failed.stack = stack;
|
|
294
|
+
}
|
|
295
|
+
if (cause) {
|
|
296
|
+
failed.cause = cause;
|
|
297
|
+
}
|
|
298
|
+
return failed;
|
|
299
|
+
}
|
|
300
|
+
export function rehydrateError(value, fallbackMessage = 'Completion failed') {
|
|
301
|
+
if (!value) {
|
|
302
|
+
return new Error(fallbackMessage);
|
|
303
|
+
}
|
|
304
|
+
const normalized = normalizeTaggedEngineError(value) ?? tagError(value);
|
|
305
|
+
if (normalized.tag === 'recovery') {
|
|
306
|
+
const error = new RecoveryRequired(normalized.operation);
|
|
307
|
+
error.message = normalized.message || fallbackMessage;
|
|
308
|
+
error.name = normalized.name || error.name;
|
|
309
|
+
if (normalized.stack) {
|
|
310
|
+
error.stack = normalized.stack;
|
|
311
|
+
}
|
|
312
|
+
return error;
|
|
313
|
+
}
|
|
314
|
+
if (normalized.tag === 'aborted') {
|
|
315
|
+
const error = new AbortedError();
|
|
316
|
+
error.message = normalized.message || fallbackMessage;
|
|
317
|
+
error.name = normalized.name || error.name;
|
|
318
|
+
if (normalized.stack) {
|
|
319
|
+
error.stack = normalized.stack;
|
|
320
|
+
}
|
|
321
|
+
return error;
|
|
322
|
+
}
|
|
323
|
+
const options = {};
|
|
324
|
+
if (normalized.cause) {
|
|
325
|
+
options.cause = rehydrateCause(normalized.cause);
|
|
326
|
+
}
|
|
327
|
+
const error = new Error(normalized.message || fallbackMessage, options);
|
|
328
|
+
error.name = normalized.name || 'Error';
|
|
329
|
+
if (normalized.code) {
|
|
330
|
+
Object.assign(error, { code: normalized.code });
|
|
331
|
+
}
|
|
332
|
+
if (normalized.stack) {
|
|
333
|
+
error.stack = normalized.stack;
|
|
334
|
+
}
|
|
335
|
+
return error;
|
|
336
|
+
}
|
|
337
|
+
function rehydrateCause(value, depth = CAUSE_DEPTH) {
|
|
338
|
+
const cause = value.cause && depth > 1 ? rehydrateCause(value.cause, depth - 1) : undefined;
|
|
339
|
+
const error = new Error(value.message, cause ? { cause } : undefined);
|
|
340
|
+
error.name = value.name;
|
|
341
|
+
if (value.code) {
|
|
342
|
+
Object.assign(error, { code: value.code });
|
|
343
|
+
}
|
|
344
|
+
if (value.stack) {
|
|
345
|
+
error.stack = value.stack;
|
|
346
|
+
}
|
|
347
|
+
return error;
|
|
348
|
+
}
|
|
349
|
+
function errorMessage(value) {
|
|
350
|
+
if (typeof value === 'string')
|
|
351
|
+
return value;
|
|
352
|
+
if (value && typeof value === 'object') {
|
|
353
|
+
const message = ownData(value, 'message');
|
|
354
|
+
if (typeof message === 'string') {
|
|
355
|
+
return message;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (value === null) {
|
|
359
|
+
return 'null';
|
|
360
|
+
}
|
|
361
|
+
if (value === undefined) {
|
|
362
|
+
return 'undefined';
|
|
363
|
+
}
|
|
364
|
+
if (typeof value === 'object') {
|
|
365
|
+
try {
|
|
366
|
+
return JSON.stringify(value);
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
return '[object with circular references]';
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return String(value);
|
|
373
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { completionMachineDefinition, runEngine, type CompletionSnapshot as EngineSnapshot, type EngineResult, type EngineRun, type EngineBoundaryOptions, type EngineOperationPort } from './engine.ts';
|
|
2
|
+
export type { MachineDefinitionNode, MachineTransitionDefinition } from './engine.ts';
|
|
3
|
+
export { contextFromBoot, requestFromBoot } from '../run-log/protocol.ts';
|
|
4
|
+
export { brandCapturedRecord, isCapturedJson } from '../run-log/protocol.ts';
|
|
5
|
+
export type { EngineBoot, EngineStep, MachineTransitionTrace, HistoryReference } from '../run-log/protocol.ts';
|
|
6
|
+
export { emptyCompletionContext } from './completion/context.ts';
|
|
7
|
+
export { createCompletionMachine } from './completion/machine.ts';
|
|
8
|
+
export { replayRun, ReplayDivergence, ReplayTraceDivergence } from '../run-log/replay.ts';
|
|
9
|
+
export { createInvokeTracker } from './completion/ports.ts';
|
|
10
|
+
export type { EnginePorts, Invocation, InvokeTracker } from './completion/ports.ts';
|
|
11
|
+
export type { CompletionContext as CompletionMachineContext, CompletionActorOutput, CompletionActorOutputs, CompletionHistoryEntry, FailureResultReference, FailureResultValue, SettledCall, StoredFailureResult, Message, RunBackendUse, RunBudget, RunLifecycleEvent, RunOutcome, ToolCallDisplay, ToolExecutionOutcome, TrustedOrigin, TrustedSource, TrustedSourceFacts, ToolEffect, ToolDecision, ToolActivityEvent, ResourceDescriptor, ResolvedCallSnapshot, ToolPreflight, ToolExecutionSnapshot, ToolDonePayload, HookRejection, DirectToolOutput, SearchingOutput, PreparingOutput, InspectingOutput, SkillLoadOutput, SkillPreloadState, PreloadInspectionOutput, ResolvingOutput, ApprovalGate, ToolPreflightFacts, ToolPolicyRejection, RoundDonePayload, ToolRejectedPayload, DirectToolRejectedPayload, PreparingPayload, SkillReadyPayload, SkillFailedPayload, AnsweredPayload, ToolsResolvedPayload, ToolStartedPayload } from './completion/types.ts';
|
|
12
|
+
export type { EngineError, Operation } from './errors.ts';
|
|
13
|
+
export { AbortedError, RecoveryRequired, ToolPolicyChanged, didDrainTimeOut, raceDrain, rehydrateError, tagError } from './errors.ts';
|
|
14
|
+
export { stableStringify } from './stable-stringify.ts';
|
|
15
|
+
export { MAX_BLOCKED_REPEATS, MAX_CAPPED_ROUNDS, MAX_MUTE_ROUNDS, MAX_TOOL_ROUNDS, TOOL_CONTINUATION_NUDGE, foldMetrics, failureResultRef, isFailureResultReference, readFailureResult, storeFailureResult, spliceFrom, toolCallKey, TOOL_DENIED_MESSAGE, toolDeniedResult } from './completion/rules.ts';
|
|
16
|
+
export type { MetricsState } from './completion/rules.ts';
|
|
17
|
+
export { MACHINE_VERSION, RUN_LOG_VERSION, XSTATE_VERSION, RunIncompatible, readRunLog, copy, safeForkLength, unresolvedWriteIds, unsettledRedactedIds, forkRepeatsSettledWrite, recoveryAdvice } from '../run-log/run-journal.ts';
|
|
18
|
+
export type { ToolRejection } from './completion/types.ts';
|
|
19
|
+
export type { MachineLog } from '../run-log/persisted-actor.ts';
|
|
20
|
+
export type { ForkSegment, RecoveryResolution, Operation as RecoveryOperation, RunRecord } from '../run-log/run-journal.ts';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { completionMachineDefinition, runEngine } from './engine.js';
|
|
2
|
+
export { contextFromBoot, requestFromBoot } from '../run-log/protocol.js';
|
|
3
|
+
export { brandCapturedRecord, isCapturedJson } from '../run-log/protocol.js';
|
|
4
|
+
export { emptyCompletionContext } from './completion/context.js';
|
|
5
|
+
export { createCompletionMachine } from './completion/machine.js';
|
|
6
|
+
export { replayRun, ReplayDivergence, ReplayTraceDivergence } from '../run-log/replay.js';
|
|
7
|
+
export { createInvokeTracker } from './completion/ports.js';
|
|
8
|
+
export { AbortedError, RecoveryRequired, ToolPolicyChanged, didDrainTimeOut, raceDrain, rehydrateError, tagError } from './errors.js';
|
|
9
|
+
export { stableStringify } from './stable-stringify.js';
|
|
10
|
+
export { MAX_BLOCKED_REPEATS, MAX_CAPPED_ROUNDS, MAX_MUTE_ROUNDS, MAX_TOOL_ROUNDS, TOOL_CONTINUATION_NUDGE, foldMetrics, failureResultRef, isFailureResultReference, readFailureResult, storeFailureResult, spliceFrom, toolCallKey, TOOL_DENIED_MESSAGE, toolDeniedResult } from './completion/rules.js';
|
|
11
|
+
export { MACHINE_VERSION, RUN_LOG_VERSION, XSTATE_VERSION, RunIncompatible, readRunLog, copy, safeForkLength, unresolvedWriteIds, unsettledRedactedIds, forkRepeatsSettledWrite, recoveryAdvice } from '../run-log/run-journal.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { EngineEvent } from './completion/types.ts';
|
|
2
|
+
export interface ReplayedRoundText {
|
|
3
|
+
contentText: string;
|
|
4
|
+
thinkingText?: string;
|
|
5
|
+
}
|
|
6
|
+
interface ReplayEvent extends EngineEvent {
|
|
7
|
+
text: string;
|
|
8
|
+
}
|
|
9
|
+
interface ReplayFinalRoundArgs {
|
|
10
|
+
runId: string;
|
|
11
|
+
round: number;
|
|
12
|
+
last: ReplayedRoundText;
|
|
13
|
+
response: string | undefined;
|
|
14
|
+
}
|
|
15
|
+
interface ReplaySuccessOutputArgs {
|
|
16
|
+
runId: string;
|
|
17
|
+
round: unknown;
|
|
18
|
+
context: Record<string, unknown> | undefined;
|
|
19
|
+
output: unknown;
|
|
20
|
+
}
|
|
21
|
+
export declare function readLastRoundText(context: Record<string, unknown> | undefined): ReplayedRoundText | undefined;
|
|
22
|
+
export declare function replayFinalRound(args: ReplayFinalRoundArgs): Generator<ReplayEvent>;
|
|
23
|
+
export declare function replaySuccessOutput(args: ReplaySuccessOutputArgs): Generator<ReplayEvent>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isRecord } from '../run-log/patch.js';
|
|
2
|
+
export function readLastRoundText(context) {
|
|
3
|
+
const lastRound = context?.lastRound;
|
|
4
|
+
if (!isRecord(lastRound)) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
return {
|
|
8
|
+
contentText: typeof lastRound.contentText === 'string' ? lastRound.contentText : '',
|
|
9
|
+
thinkingText: typeof lastRound.thinkingText === 'string' ? lastRound.thinkingText : undefined
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function* replayRoundText(runId, round, last) {
|
|
13
|
+
if (last.thinkingText) {
|
|
14
|
+
yield { type: 'thinking', text: last.thinkingText, runId, round };
|
|
15
|
+
}
|
|
16
|
+
if (last.contentText) {
|
|
17
|
+
yield { type: 'content', text: last.contentText, runId, round };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function* replayFinalRound(args) {
|
|
21
|
+
const { runId, round, last, response } = args;
|
|
22
|
+
yield* replayRoundText(runId, round, last);
|
|
23
|
+
if (typeof response !== 'string') {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const prefix = last.contentText;
|
|
27
|
+
if (response.length > prefix.length && response.startsWith(prefix)) {
|
|
28
|
+
const remainder = response.slice(prefix.length);
|
|
29
|
+
if (remainder) {
|
|
30
|
+
yield { type: 'content', text: remainder, runId, round };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function* replaySuccessOutput(args) {
|
|
35
|
+
const { runId, round, context, output } = args;
|
|
36
|
+
if (!isRecord(output) || output.status !== 'success' || typeof output.response !== 'string') {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const lastRound = readLastRoundText(context);
|
|
40
|
+
if (lastRound && typeof round === 'number') {
|
|
41
|
+
yield* replayFinalRound({ runId, round, last: lastRound, response: output.response });
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
yield {
|
|
45
|
+
type: 'content',
|
|
46
|
+
text: output.response,
|
|
47
|
+
runId,
|
|
48
|
+
round: typeof round === 'number' ? round : undefined
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function stableStringify(value: unknown): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isRecord } from './guards.js';
|
|
2
|
+
export function stableStringify(value) {
|
|
3
|
+
if (Array.isArray(value)) {
|
|
4
|
+
return `[${value.map(stableStringify).join(',')}]`;
|
|
5
|
+
}
|
|
6
|
+
if (isRecord(value)) {
|
|
7
|
+
const keys = Object.keys(value).sort();
|
|
8
|
+
return `{${keys.map((key) => `${JSON.stringify(key)}:${stableStringify(value[key])}`).join(',')}}`;
|
|
9
|
+
}
|
|
10
|
+
return JSON.stringify(value);
|
|
11
|
+
}
|
|
@@ -5,13 +5,17 @@ export interface ModelResource {
|
|
|
5
5
|
}
|
|
6
6
|
export interface ModelHandleOptions {
|
|
7
7
|
load(): Promise<ModelResource>;
|
|
8
|
+
onLoaded?(): void;
|
|
9
|
+
onFailed?(err: unknown): void;
|
|
8
10
|
}
|
|
9
11
|
export declare class ModelHandle {
|
|
10
12
|
private readonly _load;
|
|
11
13
|
private readonly _peek;
|
|
14
|
+
private readonly _onLoaded;
|
|
15
|
+
private readonly _onFailed;
|
|
12
16
|
private _tracked;
|
|
13
17
|
private _loading;
|
|
14
|
-
constructor({ load }: ModelHandleOptions);
|
|
18
|
+
constructor({ load, onLoaded, onFailed }: ModelHandleOptions);
|
|
15
19
|
load(): Promise<ModelResource>;
|
|
16
20
|
get loading(): boolean;
|
|
17
21
|
peek(): Promise<ModelResource> | null;
|
|
@@ -2,12 +2,16 @@ import { retryMemo } from '../helpers/retry-memo.js';
|
|
|
2
2
|
export class ModelHandle {
|
|
3
3
|
_load;
|
|
4
4
|
_peek;
|
|
5
|
+
_onLoaded;
|
|
6
|
+
_onFailed;
|
|
5
7
|
_tracked = null;
|
|
6
8
|
_loading = false;
|
|
7
|
-
constructor({ load }) {
|
|
9
|
+
constructor({ load, onLoaded, onFailed }) {
|
|
8
10
|
const memo = retryMemo(load);
|
|
9
11
|
this._load = memo;
|
|
10
12
|
this._peek = memo.peek;
|
|
13
|
+
this._onLoaded = onLoaded;
|
|
14
|
+
this._onFailed = onFailed;
|
|
11
15
|
this.load().catch(noop);
|
|
12
16
|
}
|
|
13
17
|
load() {
|
|
@@ -15,12 +19,13 @@ export class ModelHandle {
|
|
|
15
19
|
if (attempt !== this._tracked) {
|
|
16
20
|
this._tracked = attempt;
|
|
17
21
|
this._loading = true;
|
|
18
|
-
const
|
|
22
|
+
const settle = (report) => {
|
|
19
23
|
if (this._tracked === attempt) {
|
|
20
24
|
this._loading = false;
|
|
25
|
+
report();
|
|
21
26
|
}
|
|
22
27
|
};
|
|
23
|
-
attempt.then(
|
|
28
|
+
attempt.then(() => settle(() => this._onLoaded?.()), (err) => settle(() => this._onFailed?.(err)));
|
|
24
29
|
}
|
|
25
30
|
return attempt;
|
|
26
31
|
}
|
|
@@ -16,12 +16,14 @@ export interface ModelInfo {
|
|
|
16
16
|
registrySource: string;
|
|
17
17
|
isCached: boolean;
|
|
18
18
|
isLoaded: boolean;
|
|
19
|
+
isLoading: boolean;
|
|
19
20
|
supportsImages: boolean;
|
|
20
21
|
expectedSize: number;
|
|
21
22
|
actualSize?: number;
|
|
22
23
|
label?: string;
|
|
23
24
|
taskType: ModelTaskType;
|
|
24
25
|
}
|
|
26
|
+
export type CatalogRow = Omit<ModelInfo, 'isLoading'>;
|
|
25
27
|
export interface ListModelsOptions {
|
|
26
28
|
type?: ModelType;
|
|
27
29
|
cachedOnly?: boolean;
|
|
@@ -45,11 +47,11 @@ export interface ListModelsRuntime {
|
|
|
45
47
|
cache?: ModelStatusCache | undefined;
|
|
46
48
|
projectionFor?: ((name: string) => string | undefined) | undefined;
|
|
47
49
|
}
|
|
48
|
-
export declare function listModels(sdk: ModelListSdk, { type, cachedOnly, fullRegistry }?: ListModelsOptions, { cache, projectionFor }?: ListModelsRuntime): Promise<
|
|
50
|
+
export declare function listModels(sdk: ModelListSdk, { type, cachedOnly, fullRegistry }?: ListModelsOptions, { cache, projectionFor }?: ListModelsRuntime): Promise<CatalogRow[]>;
|
|
49
51
|
export interface CustomModelRowsContext {
|
|
50
52
|
readonly modelsDir?: string;
|
|
51
53
|
readonly loaded: ReadonlySet<string>;
|
|
52
54
|
}
|
|
53
|
-
export declare function customModelRows({ type, cachedOnly }: ListModelsOptions, { modelsDir, loaded }: CustomModelRowsContext): Promise<
|
|
54
|
-
export declare function mergeCustomRows(catalog: ReadonlyArray<
|
|
55
|
+
export declare function customModelRows({ type, cachedOnly }: ListModelsOptions, { modelsDir, loaded }: CustomModelRowsContext): Promise<CatalogRow[]>;
|
|
56
|
+
export declare function mergeCustomRows(catalog: ReadonlyArray<CatalogRow>, custom: ReadonlyArray<CatalogRow>): CatalogRow[];
|
|
55
57
|
export {};
|
|
@@ -5,11 +5,15 @@ import { type ModelAddon } from './model-source.ts';
|
|
|
5
5
|
import type { GpuFaultState } from './sdk-faults.ts';
|
|
6
6
|
type SdkModule = typeof import('@qvac/sdk');
|
|
7
7
|
export interface ModelState {
|
|
8
|
-
status: 'loading' | 'downloading' | 'downloaded' | 'ready' | 'unloading' | 'unloaded';
|
|
8
|
+
status: 'loading' | 'downloading' | 'downloaded' | 'ready' | 'error' | 'unloading' | 'unloaded';
|
|
9
9
|
model: string;
|
|
10
|
+
catalogChanged?: boolean;
|
|
10
11
|
[key: string]: unknown;
|
|
11
12
|
}
|
|
12
13
|
export type NotifyFn = (state: ModelState) => void;
|
|
14
|
+
export declare class ModelUnloadError extends Error {
|
|
15
|
+
constructor(cause: unknown);
|
|
16
|
+
}
|
|
13
17
|
export interface LlmDeviceConfig {
|
|
14
18
|
device?: 'cpu' | 'gpu';
|
|
15
19
|
gpuLayers?: number;
|
|
@@ -29,8 +33,8 @@ export interface CancelSdk {
|
|
|
29
33
|
}
|
|
30
34
|
export interface LoadTracker {
|
|
31
35
|
readonly draining: boolean;
|
|
32
|
-
track(pending: TrackedLoad): TrackedLoad;
|
|
33
|
-
drain(sdk
|
|
36
|
+
track(pending: TrackedLoad, sdk?: Partial<CancelSdk>): TrackedLoad;
|
|
37
|
+
drain(sdk?: Partial<CancelSdk>): void;
|
|
34
38
|
undrain(): void;
|
|
35
39
|
}
|
|
36
40
|
export declare function createLoadTracker(): LoadTracker;
|
|
@@ -74,10 +78,12 @@ interface PuddleEntry {
|
|
|
74
78
|
declare class ModelPuddle extends ResourcePuddle<string, ModelHandle> {
|
|
75
79
|
readonly resources: Map<string, PuddleEntry>;
|
|
76
80
|
}
|
|
77
|
-
type PoolLike = ModelPuddle;
|
|
81
|
+
export type PoolLike = ModelPuddle;
|
|
78
82
|
export declare function modelOf(key: string): string;
|
|
79
83
|
export declare function releaseModel(pool: PoolLike, key: string): void;
|
|
80
84
|
export declare function loadedModels(pool: PoolLike): LoadedModel[];
|
|
85
|
+
export declare function settledModels(pool: PoolLike): string[];
|
|
86
|
+
export declare function loadingModels(pool: PoolLike): string[];
|
|
81
87
|
export interface ResidentLease {
|
|
82
88
|
model: string;
|
|
83
89
|
modelId: string;
|
|
@@ -128,18 +134,22 @@ interface LoadClockGuard {
|
|
|
128
134
|
race: (pending: TrackedLoad) => Promise<string>;
|
|
129
135
|
}
|
|
130
136
|
export declare function loadClockGuard(model: string, sdk: Partial<CancelSdk>, { now, monoMs, sampleMs, jumpMs }?: LoadClockGuardOptions): LoadClockGuard;
|
|
137
|
+
export declare function resolveCtxSize(loadSdk: LoadSdk, model: string, opts: ModelLoadOptions): Promise<number>;
|
|
138
|
+
type UnloadFailureFn = (modelId: string, error: unknown) => void;
|
|
131
139
|
export interface ModelPoolOptions {
|
|
132
140
|
deviceConfig?: LlmDeviceConfig;
|
|
133
141
|
loads?: LoadTracker;
|
|
142
|
+
onUnloadFailure?: UnloadFailureFn | undefined;
|
|
134
143
|
}
|
|
135
|
-
export declare function createModelPool(loadSdk: LoadSdk, notify: NotifyFn, { deviceConfig, loads }?: ModelPoolOptions): ModelPuddle;
|
|
144
|
+
export declare function createModelPool(loadSdk: LoadSdk, notify: NotifyFn, { deviceConfig, loads, onUnloadFailure }?: ModelPoolOptions): ModelPuddle;
|
|
136
145
|
export interface EmbedPoolOptions {
|
|
137
146
|
faults: GpuFaultState;
|
|
138
147
|
batchSize?: number;
|
|
139
148
|
openclCacheDir?: (() => string | undefined) | undefined;
|
|
140
149
|
loads?: LoadTracker;
|
|
150
|
+
onUnloadFailure?: UnloadFailureFn | undefined;
|
|
141
151
|
}
|
|
142
|
-
export declare function createEmbedPool(loadSdk: LoadEmbedSdk, notify: NotifyFn, { faults, batchSize, openclCacheDir, loads }: EmbedPoolOptions): ModelPuddle;
|
|
152
|
+
export declare function createEmbedPool(loadSdk: LoadEmbedSdk, notify: NotifyFn, { faults, batchSize, openclCacheDir, loads, onUnloadFailure }: EmbedPoolOptions): ModelPuddle;
|
|
143
153
|
export type VoiceLifecycleSdk = Pick<SdkModule, 'unloadModel' | 'modelRegistrySearch'> & Partial<CancelSdk> & {
|
|
144
154
|
loadModel(params: {
|
|
145
155
|
modelSrc: ModelSrc;
|
|
@@ -155,6 +165,7 @@ export interface VoicePoolOptions {
|
|
|
155
165
|
modelConfig?: Record<string, unknown> | undefined;
|
|
156
166
|
openclCacheDir?: (() => string | undefined) | undefined;
|
|
157
167
|
loads?: LoadTracker;
|
|
168
|
+
onUnloadFailure?: UnloadFailureFn | undefined;
|
|
158
169
|
}
|
|
159
|
-
export declare function createVoicePool(loadSdk: LoadVoiceSdk, notify: NotifyFn, { modelType, addon, modelConfig, openclCacheDir, loads }: VoicePoolOptions): ModelPuddle;
|
|
170
|
+
export declare function createVoicePool(loadSdk: LoadVoiceSdk, notify: NotifyFn, { modelType, addon, modelConfig, openclCacheDir, loads, onUnloadFailure }: VoicePoolOptions): ModelPuddle;
|
|
160
171
|
export {};
|