@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,493 @@
|
|
|
1
|
+
import type { EngineError, Operation } from '../errors.ts';
|
|
2
|
+
import type { RunBudget } from '../../run-log/protocol-types.ts';
|
|
3
|
+
export type { RunBudget } from '../../run-log/protocol-types.ts';
|
|
4
|
+
export interface Message {
|
|
5
|
+
role: string;
|
|
6
|
+
content: string;
|
|
7
|
+
attachments?: {
|
|
8
|
+
path: string;
|
|
9
|
+
}[];
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
export interface FailureResultReference {
|
|
13
|
+
type: 'qvac-failure-result-ref';
|
|
14
|
+
ref: string;
|
|
15
|
+
callId: string;
|
|
16
|
+
}
|
|
17
|
+
export type CompletionHistoryEntry = Message | FailureResultReference;
|
|
18
|
+
export type StoredFailureResult = {
|
|
19
|
+
value: unknown;
|
|
20
|
+
} | {
|
|
21
|
+
undefined: true;
|
|
22
|
+
};
|
|
23
|
+
export interface FailureResultValue {
|
|
24
|
+
name: string;
|
|
25
|
+
result: StoredFailureResult;
|
|
26
|
+
}
|
|
27
|
+
export interface HistorySplice {
|
|
28
|
+
at: number;
|
|
29
|
+
messages: CompletionHistoryEntry[];
|
|
30
|
+
}
|
|
31
|
+
export interface RunBackendUse {
|
|
32
|
+
tool: string;
|
|
33
|
+
requestedGpu: boolean;
|
|
34
|
+
device: 'gpu' | 'cpu' | 'unknown';
|
|
35
|
+
backend: string;
|
|
36
|
+
}
|
|
37
|
+
export type ToolEffect = 'read' | 'write';
|
|
38
|
+
export type ToolDecision = 'auto' | 'allowed' | 'denied' | 'skip-all' | 'blocked';
|
|
39
|
+
export interface ResourceDescriptor {
|
|
40
|
+
kind: string;
|
|
41
|
+
label: string;
|
|
42
|
+
}
|
|
43
|
+
export interface ToolActivityEvent {
|
|
44
|
+
type: 'tool-activity';
|
|
45
|
+
name: string;
|
|
46
|
+
args: Record<string, unknown>;
|
|
47
|
+
resource: ResourceDescriptor | null;
|
|
48
|
+
effect: ToolEffect;
|
|
49
|
+
decision: ToolDecision;
|
|
50
|
+
}
|
|
51
|
+
export interface CompletionStats {
|
|
52
|
+
timeToFirstToken?: number | undefined;
|
|
53
|
+
promptTokensPerSecond?: number | undefined;
|
|
54
|
+
generatedTokens?: number | undefined;
|
|
55
|
+
tokensPerSecond?: number | undefined;
|
|
56
|
+
promptTokens?: number | undefined;
|
|
57
|
+
cacheTokens?: number | undefined;
|
|
58
|
+
}
|
|
59
|
+
export type RunOutcome = 'answered' | 'mute' | 'exhausted' | 'search-capped' | 'time-capped';
|
|
60
|
+
export interface ToolCallDisplay {
|
|
61
|
+
readonly label: string;
|
|
62
|
+
readonly description?: string;
|
|
63
|
+
readonly iconEmoji?: string;
|
|
64
|
+
}
|
|
65
|
+
export type ToolExecutionOutcome = {
|
|
66
|
+
readonly kind: 'success';
|
|
67
|
+
} | {
|
|
68
|
+
readonly kind: 'error';
|
|
69
|
+
readonly message?: string;
|
|
70
|
+
readonly error?: unknown;
|
|
71
|
+
} | {
|
|
72
|
+
readonly kind: 'denied';
|
|
73
|
+
readonly reason?: string;
|
|
74
|
+
} | {
|
|
75
|
+
readonly kind: 'blocked';
|
|
76
|
+
readonly reason?: string;
|
|
77
|
+
} | {
|
|
78
|
+
readonly kind: 'guidance';
|
|
79
|
+
readonly message: string;
|
|
80
|
+
};
|
|
81
|
+
export interface HookRejection {
|
|
82
|
+
kind: 'hook-rejection';
|
|
83
|
+
hook: string;
|
|
84
|
+
phase: 'preToolCall' | 'postToolCall' | 'runStart' | 'runEnd' | 'runPause' | 'runResume';
|
|
85
|
+
error: string;
|
|
86
|
+
guidance: true;
|
|
87
|
+
}
|
|
88
|
+
export type TrustedOrigin = 'user' | 'tool-result' | 'skill';
|
|
89
|
+
export interface TrustedSource {
|
|
90
|
+
origin: TrustedOrigin;
|
|
91
|
+
text: string;
|
|
92
|
+
}
|
|
93
|
+
export interface TrustedSourceFacts {
|
|
94
|
+
origin: Exclude<TrustedOrigin, 'user'>;
|
|
95
|
+
addresses: string[];
|
|
96
|
+
refused: boolean;
|
|
97
|
+
}
|
|
98
|
+
export interface EngineEvent {
|
|
99
|
+
type: string;
|
|
100
|
+
runId?: string;
|
|
101
|
+
round?: number;
|
|
102
|
+
callId?: string;
|
|
103
|
+
replacedTypes?: ('content' | 'thinking')[];
|
|
104
|
+
}
|
|
105
|
+
export type RunLifecycleEvent = {
|
|
106
|
+
type: 'run-started' | 'run-resumed' | 'paused';
|
|
107
|
+
runId: string;
|
|
108
|
+
} | {
|
|
109
|
+
type: 'round-reset';
|
|
110
|
+
runId: string;
|
|
111
|
+
round: number;
|
|
112
|
+
replacedTypes?: ('content' | 'thinking')[];
|
|
113
|
+
} | {
|
|
114
|
+
type: 'recovery-required';
|
|
115
|
+
runId: string;
|
|
116
|
+
operation: Operation;
|
|
117
|
+
};
|
|
118
|
+
export interface EngineFacts extends Record<string, unknown> {
|
|
119
|
+
runBudget: RunBudget;
|
|
120
|
+
}
|
|
121
|
+
export interface CompletionMetrics {
|
|
122
|
+
ttft?: number;
|
|
123
|
+
promptTokensPerSecond?: number;
|
|
124
|
+
tokens: number;
|
|
125
|
+
timedTokens: number;
|
|
126
|
+
durationMs: number;
|
|
127
|
+
promptTokens?: number;
|
|
128
|
+
cacheTokens?: number;
|
|
129
|
+
ctxSize?: number;
|
|
130
|
+
backends?: RunBackendUse[];
|
|
131
|
+
stopReason?: string;
|
|
132
|
+
}
|
|
133
|
+
export interface ApprovalCall {
|
|
134
|
+
callId?: string;
|
|
135
|
+
round?: number;
|
|
136
|
+
name: string;
|
|
137
|
+
arguments: Record<string, unknown>;
|
|
138
|
+
resource?: {
|
|
139
|
+
kind: string;
|
|
140
|
+
label: string;
|
|
141
|
+
} | null;
|
|
142
|
+
effect?: 'read' | 'write';
|
|
143
|
+
intent?: string | null;
|
|
144
|
+
display?: ToolCallDisplay | null;
|
|
145
|
+
}
|
|
146
|
+
export interface RoundToolCall {
|
|
147
|
+
id: string;
|
|
148
|
+
name: string;
|
|
149
|
+
arguments: Record<string, unknown>;
|
|
150
|
+
raw?: string;
|
|
151
|
+
}
|
|
152
|
+
export interface RoundDonePayload {
|
|
153
|
+
contentText: string;
|
|
154
|
+
thinkingText?: string;
|
|
155
|
+
promptPrefix?: string;
|
|
156
|
+
toolCalls: RoundToolCall[];
|
|
157
|
+
stats?: CompletionStats;
|
|
158
|
+
stopReason?: string;
|
|
159
|
+
replay: string | null;
|
|
160
|
+
response?: string;
|
|
161
|
+
history?: HistorySplice;
|
|
162
|
+
cacheable?: boolean;
|
|
163
|
+
fallbackResponse?: string;
|
|
164
|
+
}
|
|
165
|
+
export interface ResolvedCallSnapshot {
|
|
166
|
+
key: string;
|
|
167
|
+
id: string;
|
|
168
|
+
name: string;
|
|
169
|
+
args: Record<string, unknown>;
|
|
170
|
+
rawCall?: string;
|
|
171
|
+
intent?: string;
|
|
172
|
+
rejection?: HookRejection;
|
|
173
|
+
}
|
|
174
|
+
export interface ToolExecutionSnapshot {
|
|
175
|
+
kind: 'direct' | 'tool' | 'skill';
|
|
176
|
+
effect: ToolEffect;
|
|
177
|
+
skillName: string | null;
|
|
178
|
+
webSearch: boolean;
|
|
179
|
+
gate?: ApprovalGate | null;
|
|
180
|
+
}
|
|
181
|
+
export type SkillToolExecutionSnapshot = Omit<ToolExecutionSnapshot, 'kind' | 'skillName'> & {
|
|
182
|
+
kind: 'skill';
|
|
183
|
+
skillName: string;
|
|
184
|
+
};
|
|
185
|
+
export type GatedToolExecutionSnapshot = ToolExecutionSnapshot & {
|
|
186
|
+
gate: ApprovalGate;
|
|
187
|
+
};
|
|
188
|
+
export interface RepeatOfFailedCallParams {
|
|
189
|
+
call: ResolvedCallSnapshot;
|
|
190
|
+
prior: SettledCall;
|
|
191
|
+
}
|
|
192
|
+
export type ToolPreflight = {
|
|
193
|
+
status: 'blocked';
|
|
194
|
+
reason: 'validation' | 'refusal';
|
|
195
|
+
result: unknown;
|
|
196
|
+
effect: ToolEffect;
|
|
197
|
+
} | {
|
|
198
|
+
status: 'denied';
|
|
199
|
+
result: {
|
|
200
|
+
error: string;
|
|
201
|
+
denied: true;
|
|
202
|
+
};
|
|
203
|
+
key: string;
|
|
204
|
+
} | {
|
|
205
|
+
status: 'ready';
|
|
206
|
+
key: string;
|
|
207
|
+
effect: ToolEffect;
|
|
208
|
+
resource: ResourceDescriptor | null;
|
|
209
|
+
autoRun: boolean;
|
|
210
|
+
};
|
|
211
|
+
export interface ToolPreflightFacts {
|
|
212
|
+
key: string;
|
|
213
|
+
validationError: string | null;
|
|
214
|
+
refusal: string | null;
|
|
215
|
+
deniedKey: string | null;
|
|
216
|
+
effect: ToolEffect;
|
|
217
|
+
autoApprove: boolean;
|
|
218
|
+
skipApprovals: boolean;
|
|
219
|
+
resource: ResourceDescriptor | null;
|
|
220
|
+
}
|
|
221
|
+
export interface ApprovalGate {
|
|
222
|
+
facts: ToolPreflightFacts;
|
|
223
|
+
approver: boolean;
|
|
224
|
+
call: ApprovalCall;
|
|
225
|
+
}
|
|
226
|
+
export interface ToolDonePayload {
|
|
227
|
+
deniedKey?: string;
|
|
228
|
+
webSearch?: boolean;
|
|
229
|
+
searchCapped?: boolean;
|
|
230
|
+
history?: HistorySplice;
|
|
231
|
+
source?: TrustedSourceFacts;
|
|
232
|
+
failed?: {
|
|
233
|
+
key: string;
|
|
234
|
+
resultRef: string;
|
|
235
|
+
outcome: ToolExecutionOutcome;
|
|
236
|
+
value?: FailureResultValue;
|
|
237
|
+
};
|
|
238
|
+
progressed?: boolean;
|
|
239
|
+
blockedRepeat?: boolean;
|
|
240
|
+
}
|
|
241
|
+
export interface SettledCall {
|
|
242
|
+
resultRef: string;
|
|
243
|
+
outcome: ToolExecutionOutcome;
|
|
244
|
+
}
|
|
245
|
+
export type RejectedToolResult = {
|
|
246
|
+
result: unknown;
|
|
247
|
+
resultRef?: never;
|
|
248
|
+
} | {
|
|
249
|
+
resultRef: string;
|
|
250
|
+
result?: never;
|
|
251
|
+
};
|
|
252
|
+
export type ToolRejectedPayload = RejectedToolResult & {
|
|
253
|
+
call: ResolvedCallSnapshot;
|
|
254
|
+
activity: ToolActivityEvent | null;
|
|
255
|
+
effect?: ToolEffect;
|
|
256
|
+
outcome?: ToolExecutionOutcome;
|
|
257
|
+
deniedKey?: string;
|
|
258
|
+
emitCall: boolean;
|
|
259
|
+
emitResult: boolean;
|
|
260
|
+
capped: boolean;
|
|
261
|
+
source: 'skill' | 'tool-result';
|
|
262
|
+
repeat?: ToolExecutionOutcome;
|
|
263
|
+
};
|
|
264
|
+
export type ToolPolicyRejection = 'skill-already-loaded' | 'skill-unready' | 'skill-unavailable' | 'search-cap' | 'hook-rejected' | 'unknown-tool' | 'validation' | 'outbound-refusal' | 'already-denied' | 'denied-without-approver';
|
|
265
|
+
export type DirectToolRejectedPayload = ToolRejectedPayload & {
|
|
266
|
+
execution: ToolExecutionSnapshot;
|
|
267
|
+
preparation: PreparingPayload;
|
|
268
|
+
};
|
|
269
|
+
export interface ToolStartedPayload {
|
|
270
|
+
call: ResolvedCallSnapshot;
|
|
271
|
+
execution: ToolExecutionSnapshot;
|
|
272
|
+
preparation: PreparingPayload;
|
|
273
|
+
}
|
|
274
|
+
export interface PreparingPayload {
|
|
275
|
+
history?: HistorySplice;
|
|
276
|
+
loadedSkills?: string[];
|
|
277
|
+
webSearches?: number;
|
|
278
|
+
deniedKeys?: string[];
|
|
279
|
+
sources?: TrustedSourceFacts[];
|
|
280
|
+
availableTools?: string[];
|
|
281
|
+
promptPrefix?: string;
|
|
282
|
+
}
|
|
283
|
+
export type SkillPreloadPayload = PreparingPayload & {
|
|
284
|
+
name: string;
|
|
285
|
+
history: HistorySplice;
|
|
286
|
+
pendingSearch: string | null;
|
|
287
|
+
};
|
|
288
|
+
export interface SkillPreloadState {
|
|
289
|
+
name: string;
|
|
290
|
+
args?: Record<string, unknown>;
|
|
291
|
+
facts?: ToolPreflightFacts;
|
|
292
|
+
}
|
|
293
|
+
export interface SkillSnapshot {
|
|
294
|
+
loaded: string[];
|
|
295
|
+
}
|
|
296
|
+
export interface SkillReadyPayload {
|
|
297
|
+
name: string;
|
|
298
|
+
history?: HistorySplice;
|
|
299
|
+
source?: TrustedSourceFacts;
|
|
300
|
+
cacheable?: boolean;
|
|
301
|
+
}
|
|
302
|
+
export interface SkillFailedPayload {
|
|
303
|
+
name: string;
|
|
304
|
+
error: string;
|
|
305
|
+
history?: HistorySplice;
|
|
306
|
+
}
|
|
307
|
+
export type SkillLoad = {
|
|
308
|
+
status: 'pending';
|
|
309
|
+
} | {
|
|
310
|
+
status: 'success';
|
|
311
|
+
} | {
|
|
312
|
+
status: 'error';
|
|
313
|
+
error: string;
|
|
314
|
+
};
|
|
315
|
+
export interface AnsweredPayload {
|
|
316
|
+
history?: HistorySplice;
|
|
317
|
+
response?: string;
|
|
318
|
+
stats?: CompletionStats;
|
|
319
|
+
stopReason?: string;
|
|
320
|
+
narrated?: string;
|
|
321
|
+
}
|
|
322
|
+
export interface ToolsResolvedPayload {
|
|
323
|
+
calls: ResolvedCallSnapshot[];
|
|
324
|
+
history?: HistorySplice;
|
|
325
|
+
}
|
|
326
|
+
export interface CompletionContext {
|
|
327
|
+
runId: string;
|
|
328
|
+
timeUp: boolean;
|
|
329
|
+
pauseCount: number;
|
|
330
|
+
durable: EngineFacts | null;
|
|
331
|
+
recovery: Operation | undefined;
|
|
332
|
+
history: CompletionHistoryEntry[];
|
|
333
|
+
failureResults: Record<string, FailureResultValue>;
|
|
334
|
+
response: string;
|
|
335
|
+
sources: TrustedSourceFacts[];
|
|
336
|
+
availableTools: string[];
|
|
337
|
+
promptPrefix: string;
|
|
338
|
+
round: number;
|
|
339
|
+
roundsSent: number;
|
|
340
|
+
mute: number;
|
|
341
|
+
narrated: boolean;
|
|
342
|
+
webSearches: number;
|
|
343
|
+
directSearchDone: boolean;
|
|
344
|
+
pendingSearch: string | null;
|
|
345
|
+
cappedRounds: number;
|
|
346
|
+
deniedKeys: string[];
|
|
347
|
+
failedCalls: Record<string, SettledCall>;
|
|
348
|
+
blockedRepeats: number;
|
|
349
|
+
roundProgressed: boolean;
|
|
350
|
+
skills: {
|
|
351
|
+
snapshot: SkillSnapshot | null;
|
|
352
|
+
loads: Record<string, SkillLoad>;
|
|
353
|
+
pending: string[];
|
|
354
|
+
};
|
|
355
|
+
outcome: RunOutcome | 'failed' | null;
|
|
356
|
+
metrics: CompletionMetrics;
|
|
357
|
+
agentId: string | null;
|
|
358
|
+
cacheKey: string | null;
|
|
359
|
+
lastRound: RoundDonePayload | null;
|
|
360
|
+
skillPreload: SkillPreloadState | null;
|
|
361
|
+
pendingCall: ApprovalCall | null;
|
|
362
|
+
approval: {
|
|
363
|
+
status: 'idle' | 'pending' | 'approved' | 'denied';
|
|
364
|
+
key: string | null;
|
|
365
|
+
};
|
|
366
|
+
currentCall: ResolvedCallSnapshot | null;
|
|
367
|
+
execution: ToolExecutionSnapshot | null;
|
|
368
|
+
rejectedCall: ToolRejectedPayload | null;
|
|
369
|
+
toolQueue: ResolvedCallSnapshot[];
|
|
370
|
+
cappedCalls: number;
|
|
371
|
+
resolvedCount: number;
|
|
372
|
+
failure: Extract<EngineError, {
|
|
373
|
+
tag: 'failed';
|
|
374
|
+
}> | null;
|
|
375
|
+
failMessage: string | null;
|
|
376
|
+
}
|
|
377
|
+
export interface CompletionActionArgs<Params = undefined> {
|
|
378
|
+
readonly context: Readonly<CompletionContext>;
|
|
379
|
+
readonly params: Params;
|
|
380
|
+
}
|
|
381
|
+
export interface PreparingOutput {
|
|
382
|
+
preparation: PreparingPayload;
|
|
383
|
+
skillCandidate: string | null;
|
|
384
|
+
skillLoaderAvailable: boolean;
|
|
385
|
+
skillLoaderEffect: ToolEffect | null;
|
|
386
|
+
skillAlreadyLoaded: boolean;
|
|
387
|
+
preload: SkillPreloadPayload | null;
|
|
388
|
+
searchQuery: string | null;
|
|
389
|
+
}
|
|
390
|
+
export interface DirectToolOutput {
|
|
391
|
+
call: ResolvedCallSnapshot;
|
|
392
|
+
execution: ToolExecutionSnapshot;
|
|
393
|
+
hookRejection: HookRejection | null;
|
|
394
|
+
resource: ResourceDescriptor | null;
|
|
395
|
+
rejection?: ToolRejection;
|
|
396
|
+
}
|
|
397
|
+
export interface ToolRejection {
|
|
398
|
+
result: unknown;
|
|
399
|
+
outcome?: ToolExecutionOutcome;
|
|
400
|
+
activity: ToolActivityEvent | null;
|
|
401
|
+
effect?: ToolEffect;
|
|
402
|
+
source: 'skill' | 'tool-result';
|
|
403
|
+
deniedKey?: string;
|
|
404
|
+
emitCall?: boolean;
|
|
405
|
+
emitResult?: boolean;
|
|
406
|
+
capped?: boolean;
|
|
407
|
+
}
|
|
408
|
+
export interface SearchingOutput {
|
|
409
|
+
directTool: DirectToolOutput | null;
|
|
410
|
+
}
|
|
411
|
+
export interface RejectDeniedApprovalParams {
|
|
412
|
+
call: ResolvedCallSnapshot;
|
|
413
|
+
execution: GatedToolExecutionSnapshot;
|
|
414
|
+
}
|
|
415
|
+
export interface PreloadInspectionOutput {
|
|
416
|
+
name: string;
|
|
417
|
+
args: Record<string, unknown>;
|
|
418
|
+
facts: ToolPreflightFacts | null;
|
|
419
|
+
hookRejection: HookRejection | null;
|
|
420
|
+
failure: SkillFailedPayload | null;
|
|
421
|
+
}
|
|
422
|
+
export type SkillLoadOutput = SkillReadyPayload | {
|
|
423
|
+
failure: SkillFailedPayload;
|
|
424
|
+
};
|
|
425
|
+
export type ResolvingOutput = ToolsResolvedPayload & AnsweredPayload;
|
|
426
|
+
export interface InspectingOutput {
|
|
427
|
+
call: ResolvedCallSnapshot;
|
|
428
|
+
toolAvailable: boolean;
|
|
429
|
+
skillCall: boolean;
|
|
430
|
+
skillAlreadyLoaded: boolean;
|
|
431
|
+
skillStatus: string | null;
|
|
432
|
+
skillActive: boolean;
|
|
433
|
+
skillName: string;
|
|
434
|
+
alreadyLoadedLabel: string;
|
|
435
|
+
unavailableSkillMessage: string;
|
|
436
|
+
searchCapReached: boolean;
|
|
437
|
+
searchCapMessage: string;
|
|
438
|
+
hookRejection: HookRejection | null;
|
|
439
|
+
rejection?: ToolRejection;
|
|
440
|
+
source: 'skill' | 'tool-result';
|
|
441
|
+
effect: ToolEffect | undefined;
|
|
442
|
+
resource: ResourceDescriptor | null;
|
|
443
|
+
execution: ToolExecutionSnapshot | null;
|
|
444
|
+
}
|
|
445
|
+
export interface CompletionActorOutputs {
|
|
446
|
+
preparing: PreparingOutput;
|
|
447
|
+
inspectPreload: PreloadInspectionOutput;
|
|
448
|
+
preloading: SkillLoadOutput;
|
|
449
|
+
searching: SearchingOutput;
|
|
450
|
+
generating: RoundDonePayload;
|
|
451
|
+
resolving: ResolvingOutput;
|
|
452
|
+
answering: AnsweredPayload;
|
|
453
|
+
inspecting: InspectingOutput;
|
|
454
|
+
rejecting: ToolDonePayload;
|
|
455
|
+
loadingSkill: SkillLoadOutput;
|
|
456
|
+
approving: {
|
|
457
|
+
approved: boolean;
|
|
458
|
+
};
|
|
459
|
+
executing: ToolDonePayload;
|
|
460
|
+
wrapping: RoundDonePayload & {
|
|
461
|
+
response: string;
|
|
462
|
+
};
|
|
463
|
+
finishing: void;
|
|
464
|
+
}
|
|
465
|
+
export type CompletionActorOutput = CompletionActorOutputs[keyof CompletionActorOutputs];
|
|
466
|
+
export type CompletionMachineEvent = {
|
|
467
|
+
type: 'START';
|
|
468
|
+
} | {
|
|
469
|
+
type: 'PAUSE';
|
|
470
|
+
} | {
|
|
471
|
+
type: 'RESUME';
|
|
472
|
+
pausedMs?: number;
|
|
473
|
+
} | {
|
|
474
|
+
type: 'RECOVERY_REQUIRED';
|
|
475
|
+
operation: Operation;
|
|
476
|
+
} | {
|
|
477
|
+
type: 'FACTS';
|
|
478
|
+
value: EngineFacts;
|
|
479
|
+
} | {
|
|
480
|
+
type: 'FAIL';
|
|
481
|
+
value: {
|
|
482
|
+
error: string;
|
|
483
|
+
};
|
|
484
|
+
} | {
|
|
485
|
+
type: `xstate.error.actor.${string}`;
|
|
486
|
+
error: EngineError;
|
|
487
|
+
} | {
|
|
488
|
+
type: `xstate.done.actor.${string}`;
|
|
489
|
+
output: CompletionActorOutput;
|
|
490
|
+
} | {
|
|
491
|
+
type: 'OUTPUT';
|
|
492
|
+
event: EngineEvent;
|
|
493
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type SnapshotFrom } from 'xstate';
|
|
2
|
+
import { createCompletionMachine } from './completion/machine.ts';
|
|
3
|
+
import { type EnginePorts, type InvokeTracker } from './completion/ports.ts';
|
|
4
|
+
import type { CompletionContext, EngineEvent, RunBudget } from './completion/types.ts';
|
|
5
|
+
import { type Operation } from './errors.ts';
|
|
6
|
+
import { type EngineBoot, type EngineStep } from '../run-log/protocol.ts';
|
|
7
|
+
export { stableStringify } from './stable-stringify.ts';
|
|
8
|
+
import { type RecoveryResolution, type RunRecord, type Receipt } from '../run-log/run-journal.ts';
|
|
9
|
+
export type CompletionSnapshot = SnapshotFrom<ReturnType<typeof createCompletionMachine>>;
|
|
10
|
+
export interface MachineDefinitionNode {
|
|
11
|
+
id: string;
|
|
12
|
+
type: string;
|
|
13
|
+
initial?: string;
|
|
14
|
+
tags: string[];
|
|
15
|
+
entry: string[];
|
|
16
|
+
exit: string[];
|
|
17
|
+
states?: Record<string, MachineDefinitionNode>;
|
|
18
|
+
on?: Record<string, MachineTransitionDefinition[]>;
|
|
19
|
+
always?: MachineTransitionDefinition[];
|
|
20
|
+
invoke: {
|
|
21
|
+
id: string;
|
|
22
|
+
src: string;
|
|
23
|
+
}[];
|
|
24
|
+
}
|
|
25
|
+
export interface MachineTransitionDefinition {
|
|
26
|
+
eventType: string;
|
|
27
|
+
target?: string[];
|
|
28
|
+
guard?: string;
|
|
29
|
+
actions?: string[];
|
|
30
|
+
}
|
|
31
|
+
export declare function completionMachineDefinition(): MachineDefinitionNode;
|
|
32
|
+
export interface EngineRun {
|
|
33
|
+
runId: string;
|
|
34
|
+
resume?: boolean;
|
|
35
|
+
recovery?: RecoveryResolution[];
|
|
36
|
+
request?: unknown;
|
|
37
|
+
requestDigest?: string;
|
|
38
|
+
budget: RunBudget;
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
lockOwner?: object;
|
|
41
|
+
now?(): number;
|
|
42
|
+
start(run: {
|
|
43
|
+
operations: EngineOperationPort;
|
|
44
|
+
invokes: InvokeTracker;
|
|
45
|
+
boot: EngineBoot;
|
|
46
|
+
}): Promise<{
|
|
47
|
+
ports: EnginePorts;
|
|
48
|
+
context: CompletionContext;
|
|
49
|
+
}>;
|
|
50
|
+
settled?(snapshot: CompletionSnapshot): void;
|
|
51
|
+
}
|
|
52
|
+
export interface EngineOperationPort {
|
|
53
|
+
flush(): Promise<void>;
|
|
54
|
+
operation<Result>(operation: Operation, execute: () => Promise<Result>, facts?: OperationFactsPort, signal?: {
|
|
55
|
+
readonly aborted: boolean;
|
|
56
|
+
}): Promise<Result>;
|
|
57
|
+
getReceipt(id: string): Receipt | undefined;
|
|
58
|
+
commitResultFacts(id: string, facts: unknown): Promise<void>;
|
|
59
|
+
uncertainWrite(): import('./errors.ts').Operation | undefined;
|
|
60
|
+
settledCall(receiptId: string): boolean;
|
|
61
|
+
pendingArgumentsWereRedacted(snapshot: unknown): boolean | null;
|
|
62
|
+
}
|
|
63
|
+
export interface OperationFactsPort {
|
|
64
|
+
capture(): unknown;
|
|
65
|
+
restore(value: unknown): void;
|
|
66
|
+
}
|
|
67
|
+
export interface EngineBoundaryOptions {
|
|
68
|
+
boot?: EngineBoot;
|
|
69
|
+
onStep?: (step: EngineStep) => Promise<void>;
|
|
70
|
+
hostAppendTimeoutMs?: number;
|
|
71
|
+
redact?: <Value>(value: Value) => Value;
|
|
72
|
+
redactShared?: <Value>(value: Value) => Value;
|
|
73
|
+
redactOperationResult?: <Value>(operation: import('./errors.ts').Operation, value: Value) => Value;
|
|
74
|
+
redactRecord?: (record: RunRecord) => RunRecord;
|
|
75
|
+
redactStep?: (step: EngineStep) => EngineStep;
|
|
76
|
+
lockOwner?: object;
|
|
77
|
+
onDetached?: (pending: Promise<void>, runId?: string) => void;
|
|
78
|
+
}
|
|
79
|
+
export declare const HOST_APPEND_TIMEOUT_MS = 5000;
|
|
80
|
+
export type EngineResult = {
|
|
81
|
+
status: 'replayed';
|
|
82
|
+
} | {
|
|
83
|
+
status: 'paused';
|
|
84
|
+
snapshot: CompletionSnapshot;
|
|
85
|
+
} | {
|
|
86
|
+
status: 'done';
|
|
87
|
+
snapshot: CompletionSnapshot;
|
|
88
|
+
} | {
|
|
89
|
+
status: 'error';
|
|
90
|
+
snapshot: CompletionSnapshot;
|
|
91
|
+
error: unknown;
|
|
92
|
+
};
|
|
93
|
+
export declare function runEngine(run: EngineRun, options?: EngineBoundaryOptions): AsyncGenerator<EngineEvent, EngineResult>;
|