@dsh-enhanced/assistant-evaluation 0.1.23 → 0.1.30
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/README.md +109 -3
- package/bin/dsh-benchmark.js +21 -0
- package/lib/benchmark/cli.d.ts +6 -0
- package/lib/benchmark/cli.d.ts.map +1 -0
- package/lib/benchmark/cli.js +332 -0
- package/lib/benchmark/cli.js.map +1 -0
- package/lib/benchmark/corpus.d.ts +28 -0
- package/lib/benchmark/corpus.d.ts.map +1 -0
- package/lib/benchmark/corpus.js +173 -0
- package/lib/benchmark/corpus.js.map +1 -0
- package/lib/benchmark/deepseek.d.ts +15 -0
- package/lib/benchmark/deepseek.d.ts.map +1 -0
- package/lib/benchmark/deepseek.js +143 -0
- package/lib/benchmark/deepseek.js.map +1 -0
- package/lib/benchmark/holdout-evidence.d.ts +126 -0
- package/lib/benchmark/holdout-evidence.d.ts.map +1 -0
- package/lib/benchmark/holdout-evidence.js +466 -0
- package/lib/benchmark/holdout-evidence.js.map +1 -0
- package/lib/benchmark/holdout-protocol.d.ts +68 -0
- package/lib/benchmark/holdout-protocol.d.ts.map +1 -0
- package/lib/benchmark/holdout-protocol.js +271 -0
- package/lib/benchmark/holdout-protocol.js.map +1 -0
- package/lib/benchmark/holdout-provider.d.ts +26 -0
- package/lib/benchmark/holdout-provider.d.ts.map +1 -0
- package/lib/benchmark/holdout-provider.js +382 -0
- package/lib/benchmark/holdout-provider.js.map +1 -0
- package/lib/benchmark/holdout.d.ts +83 -0
- package/lib/benchmark/holdout.d.ts.map +1 -0
- package/lib/benchmark/holdout.js +391 -0
- package/lib/benchmark/holdout.js.map +1 -0
- package/lib/benchmark/index.d.ts +9 -0
- package/lib/benchmark/index.d.ts.map +1 -0
- package/lib/benchmark/index.js +7 -0
- package/lib/benchmark/index.js.map +1 -0
- package/lib/benchmark/memory-corpus.d.ts +55 -0
- package/lib/benchmark/memory-corpus.d.ts.map +1 -0
- package/lib/benchmark/memory-corpus.js +153 -0
- package/lib/benchmark/memory-corpus.js.map +1 -0
- package/lib/benchmark/memory-runtime.d.ts +63 -0
- package/lib/benchmark/memory-runtime.d.ts.map +1 -0
- package/lib/benchmark/memory-runtime.js +75 -0
- package/lib/benchmark/memory-runtime.js.map +1 -0
- package/lib/benchmark/native.d.ts +46 -0
- package/lib/benchmark/native.d.ts.map +1 -0
- package/lib/benchmark/native.js +300 -0
- package/lib/benchmark/native.js.map +1 -0
- package/lib/benchmark/report.d.ts +4 -0
- package/lib/benchmark/report.d.ts.map +1 -0
- package/lib/benchmark/report.js +153 -0
- package/lib/benchmark/report.js.map +1 -0
- package/lib/benchmark/runner.d.ts +25 -0
- package/lib/benchmark/runner.d.ts.map +1 -0
- package/lib/benchmark/runner.js +119 -0
- package/lib/benchmark/runner.js.map +1 -0
- package/lib/benchmark/schema.d.ts +20 -0
- package/lib/benchmark/schema.d.ts.map +1 -0
- package/lib/benchmark/schema.js +183 -0
- package/lib/benchmark/schema.js.map +1 -0
- package/lib/benchmark/store.d.ts +18 -0
- package/lib/benchmark/store.d.ts.map +1 -0
- package/lib/benchmark/store.js +321 -0
- package/lib/benchmark/store.js.map +1 -0
- package/lib/benchmark/strategy-capabilities.d.ts +154 -0
- package/lib/benchmark/strategy-capabilities.d.ts.map +1 -0
- package/lib/benchmark/strategy-capabilities.js +300 -0
- package/lib/benchmark/strategy-capabilities.js.map +1 -0
- package/lib/benchmark/strategy-config.d.ts +26 -0
- package/lib/benchmark/strategy-config.d.ts.map +1 -0
- package/lib/benchmark/strategy-config.js +80 -0
- package/lib/benchmark/strategy-config.js.map +1 -0
- package/lib/benchmark/strategy-corpus.d.ts +21 -0
- package/lib/benchmark/strategy-corpus.d.ts.map +1 -0
- package/lib/benchmark/strategy-corpus.js +95 -0
- package/lib/benchmark/strategy-corpus.js.map +1 -0
- package/lib/benchmark/strategy-evidence.d.ts +161 -0
- package/lib/benchmark/strategy-evidence.d.ts.map +1 -0
- package/lib/benchmark/strategy-evidence.js +520 -0
- package/lib/benchmark/strategy-evidence.js.map +1 -0
- package/lib/benchmark/strategy-executor.d.ts +27 -0
- package/lib/benchmark/strategy-executor.d.ts.map +1 -0
- package/lib/benchmark/strategy-executor.js +178 -0
- package/lib/benchmark/strategy-executor.js.map +1 -0
- package/lib/benchmark/strategy-goal-runtime.d.ts +78 -0
- package/lib/benchmark/strategy-goal-runtime.d.ts.map +1 -0
- package/lib/benchmark/strategy-goal-runtime.js +324 -0
- package/lib/benchmark/strategy-goal-runtime.js.map +1 -0
- package/lib/benchmark/strategy-meter.d.ts +62 -0
- package/lib/benchmark/strategy-meter.d.ts.map +1 -0
- package/lib/benchmark/strategy-meter.js +236 -0
- package/lib/benchmark/strategy-meter.js.map +1 -0
- package/lib/benchmark/strategy-owner.d.ts +71 -0
- package/lib/benchmark/strategy-owner.d.ts.map +1 -0
- package/lib/benchmark/strategy-owner.js +282 -0
- package/lib/benchmark/strategy-owner.js.map +1 -0
- package/lib/benchmark/strategy-plan.d.ts +51 -0
- package/lib/benchmark/strategy-plan.d.ts.map +1 -0
- package/lib/benchmark/strategy-plan.js +71 -0
- package/lib/benchmark/strategy-plan.js.map +1 -0
- package/lib/benchmark/strategy-policy.d.ts +16 -0
- package/lib/benchmark/strategy-policy.d.ts.map +1 -0
- package/lib/benchmark/strategy-policy.js +77 -0
- package/lib/benchmark/strategy-policy.js.map +1 -0
- package/lib/benchmark/strategy.d.ts +17 -0
- package/lib/benchmark/strategy.d.ts.map +1 -0
- package/lib/benchmark/strategy.js +21 -0
- package/lib/benchmark/strategy.js.map +1 -0
- package/lib/benchmark/types.d.ts +133 -0
- package/lib/benchmark/types.d.ts.map +1 -0
- package/lib/benchmark/types.js +3 -0
- package/lib/benchmark/types.js.map +1 -0
- package/lib/benchmark/usage.d.ts +36 -0
- package/lib/benchmark/usage.d.ts.map +1 -0
- package/lib/benchmark/usage.js +84 -0
- package/lib/benchmark/usage.js.map +1 -0
- package/lib/service.d.ts +50 -1
- package/lib/service.d.ts.map +1 -1
- package/lib/service.js +556 -9
- package/lib/service.js.map +1 -1
- package/lib/sqlite.d.ts +1 -1
- package/lib/sqlite.d.ts.map +1 -1
- package/lib/sqlite.js +94 -2
- package/lib/sqlite.js.map +1 -1
- package/lib/store.d.ts +27 -5
- package/lib/store.d.ts.map +1 -1
- package/lib/store.js +324 -25
- package/lib/store.js.map +1 -1
- package/lib/types.d.ts +114 -5
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +125 -18
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { normalizeTokenUsage, tokenUsageCost, tokenUsageReserveCost } from './usage.js';
|
|
2
|
+
const MAX = 1_000_000_000;
|
|
3
|
+
const valid = (value) => typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 && value <= MAX;
|
|
4
|
+
const fail = (reason) => { throw new Error(`strategy benchmark meter: ${reason}`); };
|
|
5
|
+
const frozen = (value) => Object.freeze(value);
|
|
6
|
+
const sum = (a, b) => { if (a > MAX - b)
|
|
7
|
+
fail('budget overflow'); return a + b; };
|
|
8
|
+
function clockBound(value, signal, deadline) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
const abort = () => done(() => reject(new Error('strategy benchmark meter: cancelled or timed out')));
|
|
11
|
+
const timer = setTimeout(abort, Math.max(0, deadline - Date.now()));
|
|
12
|
+
timer.unref?.();
|
|
13
|
+
const done = (complete) => { clearTimeout(timer); signal.removeEventListener('abort', abort); complete(); };
|
|
14
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
15
|
+
value.then(result => done(() => resolve(result)), error => done(() => reject(error)));
|
|
16
|
+
if (signal.aborted)
|
|
17
|
+
abort();
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function metadata(ctx, options) {
|
|
21
|
+
// GenerateOptions.sessionId covers auxiliary calls; currentInitiator cross-checks native AgentLoop calls.
|
|
22
|
+
const agent = ctx.get('agents')?.currentInitiator?.();
|
|
23
|
+
const sessionId = options.sessionId === undefined ? (typeof agent?.session?.id === 'string' ? agent.session.id : null) : String(options.sessionId);
|
|
24
|
+
return { sessionId, agentId: typeof agent?.id === 'string' ? agent.id : null };
|
|
25
|
+
}
|
|
26
|
+
function checkInput(input) {
|
|
27
|
+
const { budget, model, binding } = input;
|
|
28
|
+
if (!valid(input.modelCalls) || input.modelCalls < 1 || input.modelCalls > 10_000 || !valid(input.maxOutputTokens) || input.maxOutputTokens < 1
|
|
29
|
+
|| !valid(budget.durationMs) || budget.durationMs < 1 || !valid(budget.inputTokens) || !valid(budget.outputTokens)
|
|
30
|
+
|| !valid(budget.toolCalls) || (budget.costUsdMicros !== null && !valid(budget.costUsdMicros))
|
|
31
|
+
|| (model.inputLimitMode ?? 'upper-bound') !== 'upper-bound' || (model.outputLimitMode ?? 'provider') !== 'provider'
|
|
32
|
+
|| model.maxOutputTokens !== input.maxOutputTokens || input.maxOutputTokens > budget.outputTokens || typeof binding.inputTokenUpperBound !== 'function')
|
|
33
|
+
fail('invalid enforced observation configuration');
|
|
34
|
+
if ((model.inputUsdMicrosPerMillionTokens === null) !== (model.outputUsdMicrosPerMillionTokens === null))
|
|
35
|
+
fail('incomplete tariff');
|
|
36
|
+
if (budget.costUsdMicros !== null && [model.inputUsdMicrosPerMillionTokens, model.outputUsdMicrosPerMillionTokens, model.cacheReadUsdMicrosPerMillionTokens, model.cacheWriteUsdMicrosPerMillionTokens].some(rate => rate === null || rate === undefined))
|
|
37
|
+
fail('priced budget needs complete tariff');
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Install before any cell work. It rejects estimate/observed modes at setup;
|
|
41
|
+
* there is deliberately no best-effort observation-only fallback in v1.
|
|
42
|
+
*/
|
|
43
|
+
export function installStrategyBenchmarkMeter(ctx, input) {
|
|
44
|
+
checkInput(input);
|
|
45
|
+
const budget = frozen({ ...input.budget });
|
|
46
|
+
const model = frozen({ ...input.model });
|
|
47
|
+
const countInput = input.binding.inputTokenUpperBound.bind(input.binding);
|
|
48
|
+
const maxCalls = input.modelCalls;
|
|
49
|
+
const outputCap = input.maxOutputTokens;
|
|
50
|
+
const deadline = Date.now() + budget.durationMs;
|
|
51
|
+
const controller = new AbortController();
|
|
52
|
+
const meterSignal = AbortSignal.any([input.signal, controller.signal]);
|
|
53
|
+
const deadlineTimer = setTimeout(() => controller.abort(new Error('strategy benchmark meter timed out')), budget.durationMs);
|
|
54
|
+
deadlineTimer.unref?.();
|
|
55
|
+
let live = true;
|
|
56
|
+
let calls = 0;
|
|
57
|
+
let tools = 0;
|
|
58
|
+
let activeTools = 0;
|
|
59
|
+
let measuredInput = 0;
|
|
60
|
+
let measuredOutput = 0;
|
|
61
|
+
let toolRejected = false;
|
|
62
|
+
let measuredCost = budget.costUsdMicros === null ? null : 0;
|
|
63
|
+
let heldCalls = 0;
|
|
64
|
+
let heldInput = 0;
|
|
65
|
+
let heldOutput = 0;
|
|
66
|
+
let heldCost = budget.costUsdMicros === null ? null : 0;
|
|
67
|
+
const traces = [];
|
|
68
|
+
const attemptCap = maxCalls + 1;
|
|
69
|
+
const nativeAgents = new Map();
|
|
70
|
+
const cancelNative = () => { for (const agent of nativeAgents.values())
|
|
71
|
+
try {
|
|
72
|
+
agent.cancel({ kind: 'hook', reason: 'strategy-benchmark-meter-cancelled' });
|
|
73
|
+
}
|
|
74
|
+
catch { } };
|
|
75
|
+
meterSignal.addEventListener('abort', cancelNative, { once: true });
|
|
76
|
+
function reject(trace, reason) {
|
|
77
|
+
trace.phase = 'rejected';
|
|
78
|
+
trace.reason = reason;
|
|
79
|
+
trace.completedAt = Date.now();
|
|
80
|
+
return fail(reason);
|
|
81
|
+
}
|
|
82
|
+
const stream = async function* (options, next) {
|
|
83
|
+
const requestSignal = options.signal === undefined ? meterSignal : AbortSignal.any([meterSignal, options.signal]);
|
|
84
|
+
if (traces.length >= attemptCap)
|
|
85
|
+
fail('request attempt cap exceeded');
|
|
86
|
+
const trace = { id: traces.length + 1, ...metadata(ctx, options), startedAt: Date.now(), completedAt: null, phase: 'preflight', dispatched: false, reservedInputTokens: 0, reservedOutputTokens: 0, reservedCostUsdMicros: null, usage: null, reason: null };
|
|
87
|
+
traces.push(trace);
|
|
88
|
+
if (trace.sessionId !== null) {
|
|
89
|
+
const agent = ctx.get('agents')?.get?.(trace.sessionId);
|
|
90
|
+
if (typeof agent?.cancel === 'function')
|
|
91
|
+
nativeAgents.set(trace.sessionId, agent);
|
|
92
|
+
}
|
|
93
|
+
if (!live)
|
|
94
|
+
reject(trace, 'disposed');
|
|
95
|
+
if (meterSignal.aborted || options.signal?.aborted || Date.now() > deadline)
|
|
96
|
+
reject(trace, 'cancelled');
|
|
97
|
+
if (options.provider !== model.provider || options.model !== model.model || options.maxTokens !== outputCap || options.temperature !== (model.temperature ?? undefined))
|
|
98
|
+
reject(trace, 'request-contract');
|
|
99
|
+
let upper;
|
|
100
|
+
try {
|
|
101
|
+
upper = await clockBound(Promise.resolve(countInput(options)), requestSignal, deadline);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return reject(trace, 'input-bound');
|
|
105
|
+
}
|
|
106
|
+
// The awaited counter may have crossed a cancellation, disposal, or route-change boundary.
|
|
107
|
+
if (!live)
|
|
108
|
+
reject(trace, 'disposed');
|
|
109
|
+
if (meterSignal.aborted || options.signal?.aborted || Date.now() > deadline)
|
|
110
|
+
reject(trace, 'cancelled');
|
|
111
|
+
if (options.provider !== model.provider || options.model !== model.model || options.maxTokens !== outputCap || options.temperature !== (model.temperature ?? undefined) || !valid(upper) || upper > budget.inputTokens)
|
|
112
|
+
return reject(trace, 'input-bound');
|
|
113
|
+
const reserveCost = tokenUsageReserveCost(upper, outputCap, model);
|
|
114
|
+
if (budget.costUsdMicros !== null && reserveCost === null)
|
|
115
|
+
reject(trace, 'cost');
|
|
116
|
+
if (calls + heldCalls >= maxCalls || sum(measuredInput, heldInput) > budget.inputTokens - upper
|
|
117
|
+
|| sum(measuredOutput, heldOutput) > budget.outputTokens - outputCap
|
|
118
|
+
|| (budget.costUsdMicros !== null && (measuredCost === null || heldCost === null || reserveCost === null || measuredCost + heldCost > budget.costUsdMicros - reserveCost)))
|
|
119
|
+
reject(trace, 'shared-budget');
|
|
120
|
+
heldCalls++;
|
|
121
|
+
heldInput += upper;
|
|
122
|
+
heldOutput += outputCap;
|
|
123
|
+
if (heldCost !== null && reserveCost !== null)
|
|
124
|
+
heldCost += reserveCost;
|
|
125
|
+
trace.phase = 'reserved';
|
|
126
|
+
trace.reservedInputTokens = upper;
|
|
127
|
+
trace.reservedOutputTokens = outputCap;
|
|
128
|
+
trace.reservedCostUsdMicros = reserveCost;
|
|
129
|
+
let usage;
|
|
130
|
+
let finished = false;
|
|
131
|
+
let iterator;
|
|
132
|
+
try {
|
|
133
|
+
// GenerateOptions is deep-frozen by native AgentLoop. We never mutate it:
|
|
134
|
+
// cancellation reaches native adapters by cancelling the session's actual Agent.
|
|
135
|
+
iterator = next()[Symbol.asyncIterator]();
|
|
136
|
+
trace.dispatched = true;
|
|
137
|
+
trace.phase = 'streaming';
|
|
138
|
+
while (true) {
|
|
139
|
+
const item = await clockBound(iterator.next(), requestSignal, deadline);
|
|
140
|
+
if (item.done)
|
|
141
|
+
break;
|
|
142
|
+
if (finished)
|
|
143
|
+
reject(trace, 'stream');
|
|
144
|
+
if (item.value.type === 'usage') {
|
|
145
|
+
if (usage !== undefined || finished)
|
|
146
|
+
reject(trace, 'usage');
|
|
147
|
+
usage = { ...item.value.usage };
|
|
148
|
+
}
|
|
149
|
+
if (item.value.type === 'finish') {
|
|
150
|
+
if (finished || usage === undefined || !['stop', 'tool-calls', 'max-tokens'].includes(item.value.reason.kind))
|
|
151
|
+
reject(trace, 'stream');
|
|
152
|
+
finished = true;
|
|
153
|
+
}
|
|
154
|
+
yield item.value;
|
|
155
|
+
}
|
|
156
|
+
if (!live)
|
|
157
|
+
reject(trace, 'disposed');
|
|
158
|
+
if (requestSignal.aborted || !finished)
|
|
159
|
+
reject(trace, 'cancelled');
|
|
160
|
+
const normalized = usage === undefined ? undefined : normalizeTokenUsage(usage);
|
|
161
|
+
if (!normalized)
|
|
162
|
+
return reject(trace, 'usage');
|
|
163
|
+
if (normalized.inputTokens > upper || normalized.outputTokens > outputCap)
|
|
164
|
+
return reject(trace, 'usage');
|
|
165
|
+
const cost = tokenUsageCost(normalized, model);
|
|
166
|
+
if (budget.costUsdMicros !== null && (cost === null || measuredCost === null || cost > budget.costUsdMicros - measuredCost))
|
|
167
|
+
reject(trace, 'cost');
|
|
168
|
+
heldCalls--;
|
|
169
|
+
heldInput -= upper;
|
|
170
|
+
heldOutput -= outputCap;
|
|
171
|
+
if (heldCost !== null && reserveCost !== null)
|
|
172
|
+
heldCost -= reserveCost;
|
|
173
|
+
calls++;
|
|
174
|
+
measuredInput = sum(measuredInput, normalized.inputTokens);
|
|
175
|
+
measuredOutput = sum(measuredOutput, normalized.outputTokens);
|
|
176
|
+
if (measuredCost !== null && cost !== null)
|
|
177
|
+
measuredCost = sum(measuredCost, cost);
|
|
178
|
+
trace.usage = frozen({ ...normalized });
|
|
179
|
+
trace.phase = 'settled';
|
|
180
|
+
trace.completedAt = Date.now();
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
// Reservation intentionally remains held: a thrown/aborted/late stream cannot prove no bill.
|
|
184
|
+
if (trace.phase !== 'settled') {
|
|
185
|
+
trace.phase = 'retained';
|
|
186
|
+
trace.reason = meterSignal.aborted ? 'cancelled' : live ? 'stream' : 'disposed';
|
|
187
|
+
trace.completedAt = Date.now();
|
|
188
|
+
}
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
try {
|
|
193
|
+
void iterator?.return?.().catch(() => { });
|
|
194
|
+
}
|
|
195
|
+
catch { }
|
|
196
|
+
if (trace.phase === 'reserved' || trace.phase === 'streaming') {
|
|
197
|
+
trace.phase = 'retained';
|
|
198
|
+
trace.reason = live ? 'stream' : 'disposed';
|
|
199
|
+
trace.completedAt = Date.now();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
ctx.on('llm/stream', stream);
|
|
204
|
+
ctx.on('tools/execute', async (execution, next) => {
|
|
205
|
+
if (!live || meterSignal.aborted || Date.now() > deadline || execution.signal.aborted || tools >= budget.toolCalls) {
|
|
206
|
+
toolRejected = true;
|
|
207
|
+
fail('tool-budget');
|
|
208
|
+
}
|
|
209
|
+
if (execution.agent !== undefined)
|
|
210
|
+
nativeAgents.set(String(execution.agent.id), execution.agent);
|
|
211
|
+
tools++;
|
|
212
|
+
activeTools++; // Tool failure is still an attempted external action.
|
|
213
|
+
try {
|
|
214
|
+
return await next();
|
|
215
|
+
}
|
|
216
|
+
finally {
|
|
217
|
+
activeTools--;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
const snapshot = () => frozen({ observationMode: 'enforced-upper-bound-provider-output', budget,
|
|
221
|
+
modelCalls: calls, toolCalls: tools, activeToolCalls: activeTools, inputTokens: measuredInput, outputTokens: measuredOutput, costUsdMicros: measuredCost,
|
|
222
|
+
heldModelCalls: heldCalls, heldInputTokens: heldInput, heldOutputTokens: heldOutput, heldCostUsdMicros: heldCost,
|
|
223
|
+
traces: frozen(traces.map(trace => frozen({ ...trace, usage: trace.usage === null ? null : frozen({ ...trace.usage }) }))) });
|
|
224
|
+
const assertComplete = () => {
|
|
225
|
+
const value = snapshot();
|
|
226
|
+
if (meterSignal.aborted || !live || Date.now() >= deadline || value.modelCalls === 0 || toolRejected || activeTools !== 0 || value.heldModelCalls !== 0 || value.traces.some(trace => trace.phase !== 'settled')
|
|
227
|
+
|| value.modelCalls > maxCalls || value.toolCalls > budget.toolCalls || value.inputTokens > budget.inputTokens || value.outputTokens > budget.outputTokens
|
|
228
|
+
|| (budget.costUsdMicros !== null && (value.costUsdMicros === null || value.costUsdMicros > budget.costUsdMicros)))
|
|
229
|
+
fail('incomplete benchmark meter measurement');
|
|
230
|
+
};
|
|
231
|
+
const dispose = () => { if (!live)
|
|
232
|
+
return; live = false; clearTimeout(deadlineTimer); controller.abort(new Error('strategy benchmark meter disposed')); cancelNative(); };
|
|
233
|
+
ctx.effect(() => () => dispose(), 'assistant-evaluation.strategy-benchmark-meter');
|
|
234
|
+
return frozen({ signal: meterSignal, snapshot, assertComplete, dispose });
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=strategy-meter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy-meter.js","sourceRoot":"","sources":["../../src/benchmark/strategy-meter.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,qBAAqB,EAA6B,MAAM,YAAY,CAAA;AAkDlH,MAAM,GAAG,GAAG,aAAa,CAAA;AACzB,MAAM,KAAK,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,GAAG,CAAA;AACzI,MAAM,IAAI,GAAG,CAAC,MAAc,EAAS,EAAE,GAAG,MAAM,IAAI,KAAK,CAAC,6BAA6B,MAAM,EAAE,CAAC,CAAA,CAAC,CAAC,CAAA;AAClG,MAAM,MAAM,GAAG,CAAI,KAAQ,EAAe,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACjE,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,GAAG,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA,CAAC,CAAC,CAAA;AACxG,SAAS,UAAU,CAAI,KAAiB,EAAE,MAAmB,EAAE,QAAgB;IAC7E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG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Lineage, InboundEnvelope, OutboundIntent, OwnerRouteValidationReceipt } from '@dsh-enhanced/assistant-delivery/types';
|
|
4
|
+
import { type PolicyRule } from '@dsh-enhanced/assistant-policy';
|
|
5
|
+
export interface BenchmarkStrategyOwnerOptions {
|
|
6
|
+
/** Fresh Context owned by one benchmark cell. The helper installs its Host services into it. */
|
|
7
|
+
ctx: Context;
|
|
8
|
+
/** Isolated candidate workspace, never a user profile directory. */
|
|
9
|
+
workspace: string;
|
|
10
|
+
/** Separate per-cell durable state root, outside the candidate workspace. */
|
|
11
|
+
stateRoot: string;
|
|
12
|
+
/** Stable plan/cell identity; it becomes only local channel identifiers. */
|
|
13
|
+
cellId: string;
|
|
14
|
+
provider: string;
|
|
15
|
+
model: string;
|
|
16
|
+
maxOutputTokens: number;
|
|
17
|
+
persona: string;
|
|
18
|
+
/** Extra fixed policy rules, normally the two allowed Goal tools and goal actions. */
|
|
19
|
+
policyRules: readonly PolicyRule[];
|
|
20
|
+
/** Global tools visible to this Delivery owner. Defaults to the two Goal tools. */
|
|
21
|
+
allowedToolNames?: readonly string[];
|
|
22
|
+
agentPreset?: string;
|
|
23
|
+
/** Bounded wait for the native goal driver, disabled for plain owner runtimes. */
|
|
24
|
+
goalContinuationTimeoutMs?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface BenchmarkStrategyOwnerScope {
|
|
27
|
+
readonly workspace: string;
|
|
28
|
+
readonly preset: string;
|
|
29
|
+
readonly principalId: string;
|
|
30
|
+
readonly owner: Readonly<DeliveryOwnerLineage>;
|
|
31
|
+
readonly route: Readonly<OwnerRouteValidationReceipt>;
|
|
32
|
+
}
|
|
33
|
+
export interface BenchmarkStrategyOwnerRuntime {
|
|
34
|
+
readonly ctx: Context;
|
|
35
|
+
readonly workspace: string;
|
|
36
|
+
readonly stateRoot: string;
|
|
37
|
+
/** Fresh, private state directory for this exact runtime; retained for evidence after shutdown. */
|
|
38
|
+
readonly runtimeRoot: string;
|
|
39
|
+
/** Configured local identity; route validity still requires ownerScope after inbound. */
|
|
40
|
+
readonly principalId: string;
|
|
41
|
+
readonly ownerRouteId: string;
|
|
42
|
+
readonly principal: Readonly<InboundEnvelope['principal']>;
|
|
43
|
+
readonly conversation: Readonly<InboundEnvelope['conversation']>;
|
|
44
|
+
readonly outbound: readonly Readonly<OutboundIntent>[];
|
|
45
|
+
/** Register the sole exact model route after the caller installs its outer meter. */
|
|
46
|
+
installModel(adapter: LlmAdapter): Promise<void>;
|
|
47
|
+
/** Pair the synthetic owner before the one public inbound message is admitted. */
|
|
48
|
+
pairOwner(): Readonly<DeliveryOwnerLineage>;
|
|
49
|
+
/** Admit exactly one synthetic public owner message through Delivery. */
|
|
50
|
+
sendPublicInbound(text: string): Promise<Readonly<{
|
|
51
|
+
inboxId: string;
|
|
52
|
+
duplicate: boolean;
|
|
53
|
+
status: string;
|
|
54
|
+
}>>;
|
|
55
|
+
/** Drain actual Delivery work and, when supplied, actual Goals work. */
|
|
56
|
+
waitForQuiescence(goals?: Readonly<{
|
|
57
|
+
whenIdle(): Promise<void>;
|
|
58
|
+
}>): Promise<void>;
|
|
59
|
+
/** Read only public Delivery owner-route evidence after the owner binding exists. */
|
|
60
|
+
ownerScope(): Readonly<BenchmarkStrategyOwnerScope>;
|
|
61
|
+
shutdown(): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Compose the real DSH/Delivery stack needed by a native strategy cell.
|
|
65
|
+
*
|
|
66
|
+
* Goals, Verifier, the in-process Subagent provider, the outer meter, and the
|
|
67
|
+
* model adapter deliberately remain caller-owned: they differ by cell or arm
|
|
68
|
+
* and must be installed before `sendPublicInbound()`.
|
|
69
|
+
*/
|
|
70
|
+
export declare function createBenchmarkStrategyOwnerRuntime(input: BenchmarkStrategyOwnerOptions): Promise<BenchmarkStrategyOwnerRuntime>;
|
|
71
|
+
//# sourceMappingURL=strategy-owner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy-owner.d.ts","s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
@@ -0,0 +1,282 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Ephemeral, production-native owner runtime for one strategy benchmark cell.
|
|
11
|
+
*
|
|
12
|
+
* This is deliberately a Host helper rather than a benchmark fixture. It
|
|
13
|
+
* composes the public DSH services used by Delivery and keeps every durable
|
|
14
|
+
* artifact below the caller-provided benchmark state root. It never opens a
|
|
15
|
+
* real channel adapter and does not discover a user's DSH profile.
|
|
16
|
+
*/
|
|
17
|
+
import { createHash } from 'node:crypto';
|
|
18
|
+
import { lstat, mkdir, realpath } from 'node:fs/promises';
|
|
19
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
20
|
+
import { Context } from '@deepseek-ai/cordis';
|
|
21
|
+
import AgentLoop from '@deepseek-ai/dsh-agent-loop';
|
|
22
|
+
import { AgentRegistry } from '@deepseek-ai/dsh-agent';
|
|
23
|
+
import { LlmAdapter, LlmRuntime } from '@deepseek-ai/dsh-llm';
|
|
24
|
+
import { JsonlSessionPersistence } from '@deepseek-ai/dsh-session-persistence-jsonl';
|
|
25
|
+
import { SessionStore } from '@deepseek-ai/dsh-session';
|
|
26
|
+
import { SessionProjectionRegistry } from '@deepseek-ai/dsh-session-projection';
|
|
27
|
+
import SystemPrompt from '@deepseek-ai/dsh-system-prompt';
|
|
28
|
+
import ToolRuntime from '@deepseek-ai/dsh-tools';
|
|
29
|
+
import { AssistantPolicyService } from '@dsh-enhanced/assistant-policy';
|
|
30
|
+
import { benchmarkSnapshot } from './schema.js';
|
|
31
|
+
const MAX_TEXT_BYTES = 64 * 1024;
|
|
32
|
+
const safeId = (value, label) => {
|
|
33
|
+
if (typeof value !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(value))
|
|
34
|
+
throw new Error(`invalid ${label}`);
|
|
35
|
+
return value;
|
|
36
|
+
};
|
|
37
|
+
const safeRoute = (value, label) => {
|
|
38
|
+
if (typeof value !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._:/-]{0,511}$/u.test(value))
|
|
39
|
+
throw new Error(`invalid ${label}`);
|
|
40
|
+
return value;
|
|
41
|
+
};
|
|
42
|
+
const positive = (value, label, max) => {
|
|
43
|
+
if (!Number.isSafeInteger(value))
|
|
44
|
+
throw new Error(`invalid ${label}`);
|
|
45
|
+
const number = value;
|
|
46
|
+
if (number < 1 || number > max)
|
|
47
|
+
throw new Error(`invalid ${label}`);
|
|
48
|
+
return number;
|
|
49
|
+
};
|
|
50
|
+
const inside = (parent, child) => child === parent || child.startsWith(`${parent}/`);
|
|
51
|
+
async function privateCanonicalDirectory(path, label) {
|
|
52
|
+
const metadata = await lstat(path);
|
|
53
|
+
if (!metadata.isDirectory() || metadata.isSymbolicLink() || (metadata.mode & 0o077) !== 0) {
|
|
54
|
+
throw new Error(`${label} must be a private non-symlink directory`);
|
|
55
|
+
}
|
|
56
|
+
if (process.getuid !== undefined && metadata.uid !== process.getuid())
|
|
57
|
+
throw new Error(`${label} must belong to the current OS user`);
|
|
58
|
+
const canonical = await realpath(path);
|
|
59
|
+
if (canonical !== path)
|
|
60
|
+
throw new Error(`${label} must be canonical`);
|
|
61
|
+
return canonical;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Compose the real DSH/Delivery stack needed by a native strategy cell.
|
|
65
|
+
*
|
|
66
|
+
* Goals, Verifier, the in-process Subagent provider, the outer meter, and the
|
|
67
|
+
* model adapter deliberately remain caller-owned: they differ by cell or arm
|
|
68
|
+
* and must be installed before `sendPublicInbound()`.
|
|
69
|
+
*/
|
|
70
|
+
export async function createBenchmarkStrategyOwnerRuntime(input) {
|
|
71
|
+
const ctx = input.ctx;
|
|
72
|
+
if (['llm', 'sessions', 'agents', 'tools', 'assistantDelivery'].some(name => ctx.get(name) !== undefined)) {
|
|
73
|
+
throw new Error('benchmark owner requires a fresh dedicated Context');
|
|
74
|
+
}
|
|
75
|
+
const workspace = resolve(input.workspace);
|
|
76
|
+
const stateRoot = resolve(input.stateRoot);
|
|
77
|
+
if (!isAbsolute(input.workspace) || !isAbsolute(input.stateRoot) || inside(workspace, stateRoot) || inside(stateRoot, workspace)) {
|
|
78
|
+
throw new Error('benchmark workspace and state root must be distinct absolute directories');
|
|
79
|
+
}
|
|
80
|
+
const cellId = safeId(input.cellId, 'benchmark cell id');
|
|
81
|
+
const provider = safeRoute(input.provider, 'provider');
|
|
82
|
+
const model = safeRoute(input.model, 'model');
|
|
83
|
+
const preset = safeId(input.agentPreset ?? 'benchmark', 'agent preset');
|
|
84
|
+
const maxOutputTokens = positive(input.maxOutputTokens, 'max output tokens', 1_000_000);
|
|
85
|
+
if (typeof input.persona !== 'string' || Buffer.byteLength(input.persona, 'utf8') > MAX_TEXT_BYTES)
|
|
86
|
+
throw new Error('invalid benchmark persona');
|
|
87
|
+
const persona = input.persona;
|
|
88
|
+
const policyRules = benchmarkSnapshot(input.policyRules);
|
|
89
|
+
const allowedToolNames = Object.freeze([...(input.allowedToolNames ?? ['goal_create', 'goal_strategy'])].map(value => safeId(value, 'allowed tool name')));
|
|
90
|
+
if (new Set(allowedToolNames).size !== allowedToolNames.length)
|
|
91
|
+
throw new Error('duplicate allowed tool name');
|
|
92
|
+
const goalContinuationTimeoutMs = input.goalContinuationTimeoutMs === undefined ? 0 : positive(input.goalContinuationTimeoutMs, 'goal continuation timeout', 300_000);
|
|
93
|
+
const fingerprint = createHash('sha256').update(`${cellId}\0${workspace}\0${stateRoot}`).digest('hex').slice(0, 24);
|
|
94
|
+
const channel = `benchmark-${fingerprint.slice(0, 12)}`;
|
|
95
|
+
const account = `cell-${fingerprint.slice(12)}`;
|
|
96
|
+
const principal = Object.freeze({ channel, account, tenant: 'isolated', user: `owner-${fingerprint}` });
|
|
97
|
+
const conversation = Object.freeze({ channel, account, tenant: 'isolated', kind: 'dm', chat: `private-${fingerprint}` });
|
|
98
|
+
const deliveryPackage = '@dsh-enhanced/assistant-delivery';
|
|
99
|
+
const deliveryModule = await import(__rewriteRelativeImportExtension(deliveryPackage));
|
|
100
|
+
if (typeof deliveryModule.AssistantDeliveryService !== 'function' || typeof deliveryModule.externalPrincipalId !== 'function')
|
|
101
|
+
throw new Error('benchmark Delivery peer lacks required public APIs');
|
|
102
|
+
const principalId = deliveryModule.externalPrincipalId(principal);
|
|
103
|
+
const Delivery = deliveryModule.AssistantDeliveryService;
|
|
104
|
+
let delivery;
|
|
105
|
+
const authorityId = `benchmark-owner-${fingerprint}`;
|
|
106
|
+
const bootstrapId = `benchmark-bootstrap-${fingerprint}`;
|
|
107
|
+
const runtimeRoot = join(stateRoot, `owner-${fingerprint}`);
|
|
108
|
+
const sent = [];
|
|
109
|
+
let paired = false;
|
|
110
|
+
let inboundSent = false;
|
|
111
|
+
let closed = false;
|
|
112
|
+
let shutdownFlight;
|
|
113
|
+
let eventNumber = 0;
|
|
114
|
+
let removeAdapter;
|
|
115
|
+
let removeChannel;
|
|
116
|
+
await privateCanonicalDirectory(workspace, 'benchmark workspace');
|
|
117
|
+
await privateCanonicalDirectory(stateRoot, 'benchmark state root');
|
|
118
|
+
await mkdir(runtimeRoot, { recursive: false, mode: 0o700 });
|
|
119
|
+
await privateCanonicalDirectory(runtimeRoot, 'benchmark runtime root');
|
|
120
|
+
try {
|
|
121
|
+
await ctx.plugin(LlmRuntime);
|
|
122
|
+
await ctx.plugin(SessionStore);
|
|
123
|
+
new SessionProjectionRegistry(ctx);
|
|
124
|
+
await ctx.plugin(SystemPrompt, { includeHarnessIdentity: false, includeRuntimeContext: true, persona: '' });
|
|
125
|
+
ctx.systemPrompt.section({ name: 'benchmark-strategy-persona', order: 0, text: persona, complete: true });
|
|
126
|
+
await ctx.plugin(ToolRuntime, { mode: 'native' });
|
|
127
|
+
await ctx.plugin(AgentRegistry);
|
|
128
|
+
await ctx.plugin(JsonlSessionPersistence, { root: join(runtimeRoot, 'sessions'), compression: 'none', writeBatchMaxDelayMs: 1 });
|
|
129
|
+
// Delivery first persists an unstarted Session, then disposes and resumes
|
|
130
|
+
// it for the inbound turn. JSONL flush alone leaves an empty log lazy;
|
|
131
|
+
// explicitly materialize its real header without fabricating an event.
|
|
132
|
+
ctx.on('session/flush', session => ctx.sessionPersistence.ensureMaterialized(session));
|
|
133
|
+
await ctx.plugin(AssistantPolicyService, { databasePath: join(runtimeRoot, 'policy.sqlite'), toolDefaultEffect: 'deny', rules: [
|
|
134
|
+
{ id: 'benchmark-pair-issue', effect: 'allow', subject: { kind: 'external', id: `local:${bootstrapId}` }, actions: ['pair.issue'], resource: { kind: 'message', id: 'pairing' }, context: { initiators: ['foreground'] } },
|
|
135
|
+
{ id: 'benchmark-owner-ingest', effect: 'allow', subject: { kind: 'external', id: principalId }, actions: ['pair.confirm', 'ingest'], resource: { kind: 'message', id: '*' }, context: { initiators: ['external'] } },
|
|
136
|
+
{ id: 'benchmark-owner-reply', effect: 'allow', subject: { kind: 'agent', id: preset, workspace, principal: principalId }, actions: ['reply'], resource: { kind: 'message', id: '*' }, context: { initiators: ['external'] } },
|
|
137
|
+
...policyRules,
|
|
138
|
+
] });
|
|
139
|
+
ctx.on('agent/created', ({ agent }) => {
|
|
140
|
+
// Delivery creates all benchmark foreground agents after the arm has
|
|
141
|
+
// mounted its public tools. Restrict only global tools; arm-scoped tools
|
|
142
|
+
// still need an explicit Policy allow and are therefore not a bypass.
|
|
143
|
+
agent.ctx.tools.restrict({ allow: allowedToolNames });
|
|
144
|
+
});
|
|
145
|
+
await ctx.plugin(Delivery, {
|
|
146
|
+
databasePath: join(runtimeRoot, 'delivery.sqlite'), spoolPath: join(runtimeRoot, 'spool'), schedulerEnabled: false,
|
|
147
|
+
defaultWorkspace: workspace, defaultAgentPreset: preset, policyRef: 'benchmark-owner', agentProvider: provider, agentModel: model,
|
|
148
|
+
agentMaxOutputTokens: maxOutputTokens, agentMaxAutoContinuationTurns: 0, agentGoalContinuationTimeoutMs: goalContinuationTimeoutMs,
|
|
149
|
+
ownerRoutes: [{ id: authorityId, conversation, principal, workspace, agentPreset: preset, policyRef: 'benchmark-owner', minimumGeneration: 1 }],
|
|
150
|
+
});
|
|
151
|
+
delivery = ctx.get('assistantDelivery');
|
|
152
|
+
if (!delivery || typeof delivery.validateOwnerRoute !== 'function')
|
|
153
|
+
throw new Error('benchmark Delivery service unavailable');
|
|
154
|
+
await ctx.plugin(AgentLoop, { agents: [] });
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
try {
|
|
158
|
+
await ctx.fiber.dispose();
|
|
159
|
+
}
|
|
160
|
+
catch (cleanup) {
|
|
161
|
+
throw new AggregateError([error, cleanup], 'benchmark owner runtime setup and disposal failed');
|
|
162
|
+
}
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
const adapter = {
|
|
166
|
+
channel, account,
|
|
167
|
+
capabilities: Object.freeze({ reconcileUnknownSend: false, receipts: [], formats: ['plain'] }),
|
|
168
|
+
async start() { },
|
|
169
|
+
async send(intent) {
|
|
170
|
+
// The only channel is a local capture sink. No network, provider
|
|
171
|
+
// notification, browser, or user profile is reachable from this adapter.
|
|
172
|
+
sent.push(structuredClone(intent));
|
|
173
|
+
return { outcome: 'accepted', providerMessageId: `benchmark-${createHash('sha256').update(intent.idempotencyKey).digest('hex').slice(0, 32)}` };
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
const assertOpen = () => { if (closed)
|
|
177
|
+
throw new Error('benchmark owner runtime is shut down'); };
|
|
178
|
+
const snapshotOutbound = () => Object.freeze(sent.map(intent => Object.freeze(structuredClone(intent))));
|
|
179
|
+
const ownerScope = () => {
|
|
180
|
+
assertOpen();
|
|
181
|
+
const route = delivery.validateOwnerRoute({ authorityId, principalId, workspace, agentPreset: preset });
|
|
182
|
+
return Object.freeze({ workspace, preset, principalId, owner: Object.freeze({ principalRecordId: route.principalRecordId, principalVersion: route.principalVersion }), route });
|
|
183
|
+
};
|
|
184
|
+
const waitForQuiescence = async (goals) => {
|
|
185
|
+
assertOpen();
|
|
186
|
+
// A second Delivery tick flushes a reply queued by the completed foreground
|
|
187
|
+
// turn. Goals is caller supplied because this helper never installs it.
|
|
188
|
+
await delivery.tick();
|
|
189
|
+
await delivery.whenIdle();
|
|
190
|
+
await goals?.whenIdle();
|
|
191
|
+
await delivery.tick();
|
|
192
|
+
await delivery.whenIdle();
|
|
193
|
+
await goals?.whenIdle();
|
|
194
|
+
const health = delivery.health();
|
|
195
|
+
if (health.pendingInbox !== 0 || health.pendingOutbox !== 0 || health.deadLetterInbox !== 0
|
|
196
|
+
|| health.deadLetterOutbox !== 0 || health.unknownOutbox !== 0 || health.pendingPresentations !== 0 || health.deadPresentations !== 0) {
|
|
197
|
+
throw new Error('benchmark Delivery work is pending or unresolved');
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
try {
|
|
201
|
+
removeChannel = await delivery.registerAdapter(adapter);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
try {
|
|
205
|
+
await ctx.fiber.dispose();
|
|
206
|
+
}
|
|
207
|
+
catch (cleanup) {
|
|
208
|
+
throw new AggregateError([error, cleanup], 'benchmark owner adapter setup and disposal failed');
|
|
209
|
+
}
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
return Object.freeze({
|
|
213
|
+
ctx, workspace, stateRoot, runtimeRoot, principal, principalId, ownerRouteId: authorityId, conversation,
|
|
214
|
+
get outbound() { return snapshotOutbound(); },
|
|
215
|
+
async installModel(modelAdapter) {
|
|
216
|
+
assertOpen();
|
|
217
|
+
if (removeAdapter !== undefined)
|
|
218
|
+
throw new Error('benchmark model adapter is already installed');
|
|
219
|
+
if (!(modelAdapter instanceof LlmAdapter))
|
|
220
|
+
throw new Error('benchmark model adapter must be an LlmAdapter');
|
|
221
|
+
removeAdapter = ctx.llm.registerAdapter([provider], modelAdapter);
|
|
222
|
+
try {
|
|
223
|
+
await ctx.llm.resolveModelInfo(provider, model);
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
removeAdapter();
|
|
227
|
+
removeAdapter = undefined;
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
pairOwner() {
|
|
232
|
+
assertOpen();
|
|
233
|
+
if (paired)
|
|
234
|
+
throw new Error('benchmark owner is already paired');
|
|
235
|
+
const pairing = delivery.issuePairing(bootstrapId, principal);
|
|
236
|
+
const confirmed = delivery.confirmPairing({ challengeId: pairing.challenge.id, principal, code: pairing.code });
|
|
237
|
+
if (confirmed.role !== 'owner' || confirmed.status !== 'active' || confirmed.id === '') {
|
|
238
|
+
throw new Error('benchmark owner pairing was not confirmed');
|
|
239
|
+
}
|
|
240
|
+
const owner = Object.freeze({ principalRecordId: confirmed.id, principalVersion: confirmed.version });
|
|
241
|
+
paired = true;
|
|
242
|
+
return owner;
|
|
243
|
+
},
|
|
244
|
+
async sendPublicInbound(text) {
|
|
245
|
+
assertOpen();
|
|
246
|
+
if (!paired || inboundSent)
|
|
247
|
+
throw new Error('benchmark owner inbound must follow one pairing and precede shutdown');
|
|
248
|
+
if (removeAdapter === undefined)
|
|
249
|
+
throw new Error('benchmark model adapter is not installed');
|
|
250
|
+
if (typeof text !== 'string' || text.trim() === '' || Buffer.byteLength(text, 'utf8') > MAX_TEXT_BYTES)
|
|
251
|
+
throw new Error('invalid benchmark inbound text');
|
|
252
|
+
inboundSent = true;
|
|
253
|
+
const accepted = await delivery.acceptInbound({ channel, account, eventId: `benchmark-inbound-${fingerprint}-${++eventNumber}`,
|
|
254
|
+
occurredAt: Date.now(), principal, conversation, kind: 'text', text });
|
|
255
|
+
return Object.freeze(accepted);
|
|
256
|
+
},
|
|
257
|
+
waitForQuiescence,
|
|
258
|
+
ownerScope,
|
|
259
|
+
shutdown() {
|
|
260
|
+
if (shutdownFlight !== undefined)
|
|
261
|
+
return shutdownFlight;
|
|
262
|
+
closed = true;
|
|
263
|
+
shutdownFlight = (async () => {
|
|
264
|
+
for (const agent of ctx.agents.list())
|
|
265
|
+
agent.cancel({ kind: 'hook', reason: 'benchmark-owner-shutdown' });
|
|
266
|
+
const errors = [];
|
|
267
|
+
for (const cleanup of [() => delivery.whenIdle(), () => removeChannel?.(), () => removeAdapter?.(), () => ctx.fiber.dispose()]) {
|
|
268
|
+
try {
|
|
269
|
+
await cleanup();
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
errors.push(error);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (errors.length > 0)
|
|
276
|
+
throw new AggregateError(errors, 'benchmark owner shutdown failed');
|
|
277
|
+
})();
|
|
278
|
+
return shutdownFlight;
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=strategy-owner.js.map
|