@sema-agent/core 7.67.0 → 7.67.1
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 +35 -0
- package/dist/brain/model-lane.d.ts +26 -2
- package/dist/brain/model-lane.js +67 -6
- package/dist/core/engine-notice.d.ts +5 -2
- package/dist/core/model-fallbacks.d.ts +5 -3
- package/dist/core/roles.d.ts +18 -25
- package/dist/core/roles.js +106 -40
- package/dist/core/runner/model-fallback-seat.d.ts +7 -4
- package/dist/core/runner/model-fallback-seat.js +31 -10
- package/dist/core/runner/run-harness-handlers.js +3 -3
- package/dist/core/runner/run-telemetry-and-budget-seats.js +7 -1
- package/dist/core/runner/side-call-account.d.ts +1 -1
- package/dist/core/runner/side-call-account.js +1 -1
- package/dist/core/task-result.d.ts +11 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +11 -1
- package/wire-changes/core-stores-sql@7.67.1.json +39 -0
- package/wire-changes/core@7.67.1.json +406 -0
- package/wire-changes/mods-kernel@7.67.1.json +39 -0
- package/wire-changes/primitives@7.67.1.json +39 -0
- package/wire-changes/wiki-gate@7.67.1.json +39 -0
package/dist/core/roles.js
CHANGED
|
@@ -13,8 +13,20 @@ function catalogEntry(ref, models) {
|
|
|
13
13
|
return m || undefined;
|
|
14
14
|
}
|
|
15
15
|
export function catalogModel(ref, models, seat, what = `${bindingShown(ref)} (a catalog entry)`) {
|
|
16
|
-
const
|
|
17
|
-
return
|
|
16
|
+
const at = entryAt(ref, models, seat, what);
|
|
17
|
+
return at === undefined ? undefined : chainedRead(at, models, seat, () => readSubject(ref, seat), (word) => entryAt(word, models, seat, `${bindingShown(word)} (a fallback of the catalog entry ${bindingShown(ref)})`)?.entry);
|
|
18
|
+
}
|
|
19
|
+
const readSubject = (ref, seat) => `the \`fallbacks\` of the catalog entry ${bindingShown(ref)} (read at ${seat})`;
|
|
20
|
+
function entryAt(ref, models, seat, what) {
|
|
21
|
+
const written = catalogEntry(ref, models);
|
|
22
|
+
return written === undefined ? undefined : { written, entry: receiveModel(written, seat, what, "", true) };
|
|
23
|
+
}
|
|
24
|
+
function chainedRead(at, models, seat, subject, hopOf) {
|
|
25
|
+
const { written, entry } = at;
|
|
26
|
+
const words = entry.fallbacks;
|
|
27
|
+
if (words === undefined || written === entry)
|
|
28
|
+
return entry;
|
|
29
|
+
return chainedSnapshot(entry, chainHops(entry, words, hopOf, models, seat, subject()));
|
|
18
30
|
}
|
|
19
31
|
export function isCatalogEntry(ref, models) {
|
|
20
32
|
return catalogEntry(ref, models) !== undefined;
|
|
@@ -120,7 +132,7 @@ export function resolveModelDisplayLabel(ref) {
|
|
|
120
132
|
}
|
|
121
133
|
const TIERS_ACTIVE = Symbol.for("sema.tiersActive");
|
|
122
134
|
const TIER_ALIAS_VIA = Symbol.for("sema.tierAliasVia");
|
|
123
|
-
|
|
135
|
+
function expandTierKeys(models, tiers, laidOut) {
|
|
124
136
|
if (!tiers || Object.keys(tiers).length === 0)
|
|
125
137
|
return models;
|
|
126
138
|
const out = { ...models };
|
|
@@ -131,7 +143,13 @@ export function expandTiers(models, tiers) {
|
|
|
131
143
|
const b = Object.hasOwn(tiers, name) ? tiers[name] : undefined;
|
|
132
144
|
if (b === undefined)
|
|
133
145
|
return undefined;
|
|
134
|
-
|
|
146
|
+
const seat = `tiers.${name}`;
|
|
147
|
+
if (typeof b !== "string")
|
|
148
|
+
return { model: modelObjectAt(b, seat, TIER_BINDS), written: b };
|
|
149
|
+
const at = entryAt(b, models, seat, `${bindingShown(b)} (a catalog entry)`);
|
|
150
|
+
if (at === undefined)
|
|
151
|
+
throw unknownModelRefRefusal(b, seat);
|
|
152
|
+
return { model: at.entry, written: at.written };
|
|
135
153
|
};
|
|
136
154
|
const ownKey = (k) => models !== undefined && Object.hasOwn(models, k) && Boolean(models[k]);
|
|
137
155
|
const landing = (t, self) => {
|
|
@@ -139,7 +157,7 @@ export function expandTiers(models, tiers) {
|
|
|
139
157
|
if (!m)
|
|
140
158
|
return undefined;
|
|
141
159
|
const b = Object.hasOwn(tiers, t) ? tiers[t] : undefined;
|
|
142
|
-
return {
|
|
160
|
+
return { ...m, via: [...(t !== self && !ownKey(t) ? [t] : []), ...(typeof b === "string" ? [b] : [])], seat: `tiers.${t}` };
|
|
143
161
|
};
|
|
144
162
|
const resolveTier = (name, self = name) => {
|
|
145
163
|
const direct = landing(name, self);
|
|
@@ -151,14 +169,15 @@ export function expandTiers(models, tiers) {
|
|
|
151
169
|
for (let i = at + 1; i < DEFAULT_TIER_ORDER.length; i++) {
|
|
152
170
|
const next = landing(DEFAULT_TIER_ORDER[i], self);
|
|
153
171
|
if (next)
|
|
154
|
-
return {
|
|
172
|
+
return { ...next, via: [...(name !== self && !ownKey(name) ? [name] : []), ...next.via] };
|
|
155
173
|
}
|
|
156
174
|
return undefined;
|
|
157
175
|
};
|
|
158
176
|
const shadowed = (key) => Object.hasOwn(out, key) && Boolean(out[key]);
|
|
159
|
-
const put = (key,
|
|
160
|
-
Object.defineProperty(out, key, { value:
|
|
161
|
-
aliasVia.set(key, via);
|
|
177
|
+
const put = (key, r) => {
|
|
178
|
+
Object.defineProperty(out, key, { value: r.model, writable: true, enumerable: true, configurable: true });
|
|
179
|
+
aliasVia.set(key, r.via);
|
|
180
|
+
laidOut?.set(key, r);
|
|
162
181
|
};
|
|
163
182
|
const tierNames = new Set([...DEFAULT_TIER_ORDER, ...Object.keys(tiers)]);
|
|
164
183
|
for (const name of tierNames) {
|
|
@@ -166,26 +185,39 @@ export function expandTiers(models, tiers) {
|
|
|
166
185
|
continue;
|
|
167
186
|
const r = resolveTier(name);
|
|
168
187
|
if (r)
|
|
169
|
-
put(name, r
|
|
188
|
+
put(name, r);
|
|
170
189
|
}
|
|
171
190
|
for (const [alias, tier] of Object.entries(CC_MODEL_TIER_ALIASES)) {
|
|
172
191
|
if (shadowed(alias))
|
|
173
192
|
continue;
|
|
174
193
|
const r = resolveTier(tier, alias);
|
|
175
194
|
if (r)
|
|
176
|
-
put(alias, r
|
|
195
|
+
put(alias, r);
|
|
177
196
|
}
|
|
178
197
|
if (!shadowed("best")) {
|
|
179
198
|
for (const name of DEFAULT_TIER_ORDER) {
|
|
180
199
|
const r = landing(name, "best");
|
|
181
200
|
if (r) {
|
|
182
|
-
put("best", r
|
|
201
|
+
put("best", r);
|
|
183
202
|
break;
|
|
184
203
|
}
|
|
185
204
|
}
|
|
186
205
|
}
|
|
187
206
|
return out;
|
|
188
207
|
}
|
|
208
|
+
export function expandTiers(models, tiers) {
|
|
209
|
+
const laidOut = new Map();
|
|
210
|
+
const out = expandTierKeys(models, tiers, laidOut);
|
|
211
|
+
if (out === undefined || out === models)
|
|
212
|
+
return out;
|
|
213
|
+
for (const [key, { model, seat, written }] of laidOut) {
|
|
214
|
+
const subject = () => `the \`fallbacks\` of the model the tier key ${bindingShown(key)} lays out (${seat})`;
|
|
215
|
+
const chained = chainedRead({ written, entry: model }, out, seat, subject, (word) => entryAt(word, out, seat, `${bindingShown(word)} (a fallback of the model the tier key ${bindingShown(key)} lays out)`)?.entry);
|
|
216
|
+
if (chained !== model)
|
|
217
|
+
Object.defineProperty(out, key, { value: chained, writable: true, enumerable: true, configurable: true });
|
|
218
|
+
}
|
|
219
|
+
return out;
|
|
220
|
+
}
|
|
189
221
|
const RECEIVED_CATALOGS = new WeakSet();
|
|
190
222
|
export function isReceivedCatalog(models) {
|
|
191
223
|
return models !== undefined && RECEIVED_CATALOGS.has(models);
|
|
@@ -213,7 +245,7 @@ export function receiveModelCatalog(models, tiers, field) {
|
|
|
213
245
|
}
|
|
214
246
|
Object.freeze(bindings);
|
|
215
247
|
}
|
|
216
|
-
const expanded = bindings !== undefined && Object.keys(bindings).length > 0 ?
|
|
248
|
+
const expanded = bindings !== undefined && Object.keys(bindings).length > 0 ? expandTierKeys(held, bindings) : held;
|
|
217
249
|
if (expanded !== undefined) {
|
|
218
250
|
resolveFallbackChains(expanded, field);
|
|
219
251
|
RECEIVED_CATALOGS.add(Object.freeze(expanded));
|
|
@@ -233,32 +265,13 @@ function resolveFallbackChains(catalog, field) {
|
|
|
233
265
|
if (words === undefined)
|
|
234
266
|
continue;
|
|
235
267
|
const seat = `${field}.models.${key}.fallbacks`;
|
|
236
|
-
|
|
237
|
-
throw modelFallbackRefusal(seat, `${seat} names ${words.length} models — a chain holds at most ${MAX_MODEL_FALLBACKS} (more is refused, never cut).`);
|
|
238
|
-
}
|
|
239
|
-
const hops = [];
|
|
240
|
-
for (const word of words) {
|
|
241
|
-
const hop = catalogEntry(word, catalog);
|
|
242
|
-
if (hop === undefined)
|
|
243
|
-
throw modelFallbackRefusal(seat, `${seat} names ${bindingShown(word)}, which this catalog does not hold — a fallback is a catalog word.`);
|
|
244
|
-
if (hop === entry || hop.id === entry.id)
|
|
245
|
-
throw modelFallbackRefusal(seat, `${seat} names ${bindingShown(word)}, which is the model ${bindingShown(entry.id)} itself — a fallback is another model.`);
|
|
246
|
-
if (hops.some((h) => h === hop || h.id === hop.id))
|
|
247
|
-
throw modelFallbackRefusal(seat, `${seat} names ${bindingShown(word)}, the model ${bindingShown(hop.id)} a word before it already names — each hop is a different model.`);
|
|
248
|
-
hops.push(hop);
|
|
249
|
-
}
|
|
250
|
-
resolved.set(entry, hops);
|
|
268
|
+
resolved.set(entry, chainHops(entry, words, (word) => catalogEntry(word, catalog), catalog, seat, seat));
|
|
251
269
|
}
|
|
252
270
|
const forks = new Map();
|
|
253
271
|
for (const [entry, hops] of resolved) {
|
|
254
|
-
const
|
|
255
|
-
if (
|
|
256
|
-
|
|
257
|
-
else if (before.length !== hops.length || before.some((h, i) => h !== hops[i])) {
|
|
258
|
-
const fork = forkModelSnapshot(entry);
|
|
259
|
-
recordFallbackChain(fork, hops);
|
|
260
|
-
forks.set(entry, fork);
|
|
261
|
-
}
|
|
272
|
+
const chained = chainedSnapshot(entry, hops);
|
|
273
|
+
if (chained !== entry)
|
|
274
|
+
forks.set(entry, chained);
|
|
262
275
|
}
|
|
263
276
|
if (forks.size === 0)
|
|
264
277
|
return;
|
|
@@ -268,6 +281,51 @@ function resolveFallbackChains(catalog, field) {
|
|
|
268
281
|
Object.defineProperty(catalog, key, { value: fork, writable: true, enumerable: true, configurable: true });
|
|
269
282
|
}
|
|
270
283
|
}
|
|
284
|
+
function chainHops(entry, words, hopOf, catalog, field, subject) {
|
|
285
|
+
if (words.length > MAX_MODEL_FALLBACKS) {
|
|
286
|
+
throw modelFallbackRefusal(field, `${subject} names ${words.length} models — a chain holds at most ${MAX_MODEL_FALLBACKS} (more is refused, never cut).`);
|
|
287
|
+
}
|
|
288
|
+
const hops = [];
|
|
289
|
+
for (const word of words) {
|
|
290
|
+
const hop = hopOf(word);
|
|
291
|
+
if (hop === undefined)
|
|
292
|
+
throw modelFallbackRefusal(field, `${subject} names ${bindingShown(word)}, which this catalog does not hold — a fallback is a catalog word.${unexpandedTierWordNote(word, catalog)}`);
|
|
293
|
+
if (hop === entry || hop.id === entry.id)
|
|
294
|
+
throw modelFallbackRefusal(field, `${subject} names ${bindingShown(word)}, which is the model ${bindingShown(entry.id)} itself — a fallback is another model.`);
|
|
295
|
+
if (hops.some((h) => h === hop || h.id === hop.id))
|
|
296
|
+
throw modelFallbackRefusal(field, `${subject} names ${bindingShown(word)}, the model ${bindingShown(hop.id)} a word before it already names — each hop is a different model.`);
|
|
297
|
+
hops.push(hop);
|
|
298
|
+
}
|
|
299
|
+
return hops;
|
|
300
|
+
}
|
|
301
|
+
function chainedSnapshot(entry, hops) {
|
|
302
|
+
const before = recordedFallbackChainOf(entry);
|
|
303
|
+
if (before === undefined) {
|
|
304
|
+
recordFallbackChain(entry, hops);
|
|
305
|
+
return entry;
|
|
306
|
+
}
|
|
307
|
+
return sameHops(before, hops) ? entry : chainedFork(entry, hops);
|
|
308
|
+
}
|
|
309
|
+
function sameHops(a, b) {
|
|
310
|
+
return a.length === b.length && a.every((h, i) => h === b[i]);
|
|
311
|
+
}
|
|
312
|
+
const FORKS = new WeakMap();
|
|
313
|
+
function chainedFork(entry, hops) {
|
|
314
|
+
const known = FORKS.get(entry) ?? [];
|
|
315
|
+
const found = known.find((f) => sameHops(recordedFallbackChainOf(f) ?? [], hops));
|
|
316
|
+
if (found !== undefined)
|
|
317
|
+
return found;
|
|
318
|
+
const fork = forkModelSnapshot(entry);
|
|
319
|
+
recordFallbackChain(fork, hops);
|
|
320
|
+
FORKS.set(entry, [...known, fork]);
|
|
321
|
+
return fork;
|
|
322
|
+
}
|
|
323
|
+
function unexpandedTierWordNote(word, catalog) {
|
|
324
|
+
const tierWord = DEFAULT_TIER_ORDER.includes(word) || Object.hasOwn(CC_MODEL_TIER_ALIASES, word) || word === "best";
|
|
325
|
+
if (!tierWord || catalog?.[TIERS_ACTIVE] === true)
|
|
326
|
+
return "";
|
|
327
|
+
return ` ${bindingShown(word)} is a tier word, and this catalog was handed over without its tier expansion: hand over the tier bindings beside it (\`tiers\`), or its expansion (\`expandTiers(models, tiers)\`), and the word is one of its keys.`;
|
|
328
|
+
}
|
|
271
329
|
export function tierAliasVia(word, models) {
|
|
272
330
|
const via = models?.[TIER_ALIAS_VIA];
|
|
273
331
|
return via?.get(word) ?? [];
|
|
@@ -393,13 +451,21 @@ function partsModel(parts, models, seat = "a role seat") {
|
|
|
393
451
|
if (needs != null && !Array.isArray(needs)) {
|
|
394
452
|
throw modelBindingRefusal(`${seat}.select`, "not_a_model_ref", `${seat}.select.needs is ${bindingShown(needs)}, not a list of capabilities (vision / reasoning).`);
|
|
395
453
|
}
|
|
454
|
+
const at = `${seat}.select`;
|
|
396
455
|
const held = [];
|
|
456
|
+
const byKey = new Map();
|
|
397
457
|
for (const key of models != null && typeof models === "object" ? Object.keys(models) : []) {
|
|
398
|
-
const
|
|
399
|
-
if (
|
|
400
|
-
|
|
458
|
+
const read = entryAt(key, models, at, `the catalog entry ${bindingShown(key)} the criteria read`);
|
|
459
|
+
if (read === undefined)
|
|
460
|
+
continue;
|
|
461
|
+
held.push(read.entry);
|
|
462
|
+
byKey.set(key, read);
|
|
401
463
|
}
|
|
402
|
-
|
|
464
|
+
const picked = selectModel(held, parts.select);
|
|
465
|
+
if (picked === undefined)
|
|
466
|
+
return undefined;
|
|
467
|
+
const [key, read] = [...byKey].find(([, r]) => r.entry === picked);
|
|
468
|
+
return chainedRead(read, models, at, () => readSubject(key, at), (word) => byKey.get(word)?.entry ?? entryAt(word, models, at, `${bindingShown(word)} (a fallback of the catalog entry ${bindingShown(key)})`)?.entry);
|
|
403
469
|
}
|
|
404
470
|
return undefined;
|
|
405
471
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The leg's announcement of a walked model request — `model.fallback` (audience `user`): the requested model could not serve,
|
|
3
|
-
* and either a fallback model answered (`outcome: "served"`) or none could (`"exhausted"`). Read off the answer
|
|
3
|
+
* and either a fallback model answered (`outcome: "served"`) or none could (`"exhausted"`). Read off the answer at the
|
|
4
4
|
* accounting points that read every answer (the main loop's, and the side-call lanes' book), so the lane that made the call
|
|
5
|
-
* is named
|
|
5
|
+
* is named: the marker for a walk that tried a hop, and the statement of a walk that sent none (every later hop's route refused
|
|
6
|
+
* before sending — `exhausted` with no hop tried, no `to`). Fires ONCE PER LEG PER (from, to, reason, outcome).
|
|
6
7
|
*/
|
|
7
8
|
import { type EngineNotice } from "../engine-notice.js";
|
|
8
9
|
import type { Model } from "../../internal/llm.js";
|
|
@@ -11,10 +12,12 @@ import type { UsageLane } from "./side-call-account.js";
|
|
|
11
12
|
/** Which call of the leg the request was: the lane it is booked on. */
|
|
12
13
|
export type ModelFallbackLane = UsageLane;
|
|
13
14
|
export interface ModelFallbackSeat {
|
|
14
|
-
/** Announce a
|
|
15
|
+
/** Announce a walk on the answer to a request for `requested` on `lane`, unless this leg already announced the same walk. */
|
|
15
16
|
observe(lane: ModelFallbackLane, requested: Model, reading: ServedReading): void;
|
|
16
17
|
}
|
|
18
|
+
/** `alert` is the leg's operational alert for a walk that sent no hop on the main lane (a walk that tried one has its own, with the
|
|
19
|
+
* switch it records): told the announced sentence, once. */
|
|
17
20
|
export declare function createModelFallbackSeat(onNotice: ((notice: EngineNotice) => void) | undefined, ids: {
|
|
18
21
|
sessionId: string;
|
|
19
22
|
runId?: string;
|
|
20
|
-
}): ModelFallbackSeat;
|
|
23
|
+
}, alert?: (sentence: string) => void): ModelFallbackSeat;
|
|
@@ -3,25 +3,46 @@ function windowOf(model) {
|
|
|
3
3
|
const w = model?.contextWindow;
|
|
4
4
|
return typeof w === "number" && Number.isFinite(w) && w > 0 ? w : undefined;
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
const refusedListOf = (skipped) => skipped.map((s) => (s.code !== undefined ? `${s.model} (${s.code})` : s.model)).join(", ");
|
|
7
|
+
export function createModelFallbackSeat(onNotice, ids, alert) {
|
|
7
8
|
const announced = new Set();
|
|
9
|
+
const once = (key) => {
|
|
10
|
+
const k = key.join("\u0000");
|
|
11
|
+
if (announced.has(k))
|
|
12
|
+
return false;
|
|
13
|
+
announced.add(k);
|
|
14
|
+
return true;
|
|
15
|
+
};
|
|
16
|
+
const attribution = { sessionId: ids.sessionId, ...(ids.runId !== undefined ? { runId: ids.runId } : {}) };
|
|
8
17
|
return {
|
|
9
18
|
observe(lane, requested, reading) {
|
|
19
|
+
const fromWindow = windowOf(requested);
|
|
10
20
|
const d = reading.degraded;
|
|
11
|
-
if (d === undefined)
|
|
21
|
+
if (d === undefined) {
|
|
22
|
+
const u = reading.unsent;
|
|
23
|
+
if (u === undefined || !once([u.from, "", u.reason, "unsent"]))
|
|
24
|
+
return;
|
|
25
|
+
const message = `${u.from} could not serve this request (${u.reason}); none of its fallbacks was sent — its route was refused before sending: ${refusedListOf(u.skipped)}; the request ended with ${u.from}'s own failure.`;
|
|
26
|
+
deliverEngineNotice(onNotice, {
|
|
27
|
+
code: "model.fallback",
|
|
28
|
+
message,
|
|
29
|
+
detail: { from: u.from, reason: u.reason, outcome: "exhausted", chain: [], skipped: u.skipped.map((s) => ({ ...s })), lane, ...(fromWindow !== undefined ? { fromWindow } : {}), ...attribution },
|
|
30
|
+
});
|
|
31
|
+
if (lane === "main")
|
|
32
|
+
alert?.(message);
|
|
12
33
|
return;
|
|
34
|
+
}
|
|
13
35
|
const outcome = d.outcome ?? "served";
|
|
14
|
-
|
|
15
|
-
if (announced.has(key))
|
|
36
|
+
if (!once([d.from, d.to, d.reason, outcome]))
|
|
16
37
|
return;
|
|
17
|
-
announced.add(key);
|
|
18
38
|
const to = outcome === "served" ? reading.served : undefined;
|
|
19
|
-
const fromWindow = windowOf(requested);
|
|
20
39
|
const toWindow = windowOf(to);
|
|
21
40
|
const smaller = fromWindow !== undefined && toWindow !== undefined && toWindow < fromWindow ? ` ${d.to} has a smaller context window (${toWindow} tokens; ${d.from} has ${fromWindow}).` : "";
|
|
41
|
+
const skipped = d.skipped ?? [];
|
|
42
|
+
const refused = skipped.length > 0 ? ` Not tried — its route was refused before sending: ${refusedListOf(skipped)}.` : "";
|
|
22
43
|
const message = outcome === "served"
|
|
23
|
-
? `${d.from} could not serve this request (${d.reason}); its fallback ${d.to} answered instead.${smaller}`
|
|
24
|
-
: `${d.from} could not serve this request (${d.reason}), and none of its fallbacks could (tried ${(d.chain ?? [d.to]).join(", ")}); the request ended with ${d.from}'s own failure
|
|
44
|
+
? `${d.from} could not serve this request (${d.reason}); its fallback ${d.to} answered instead.${smaller}${refused}`
|
|
45
|
+
: `${d.from} could not serve this request (${d.reason}), and none of its fallbacks could (tried ${(d.chain ?? [d.to]).join(", ")}); the request ended with ${d.from}'s own failure.${refused}`;
|
|
25
46
|
deliverEngineNotice(onNotice, {
|
|
26
47
|
code: "model.fallback",
|
|
27
48
|
message,
|
|
@@ -31,11 +52,11 @@ export function createModelFallbackSeat(onNotice, ids) {
|
|
|
31
52
|
reason: d.reason,
|
|
32
53
|
outcome,
|
|
33
54
|
chain: [...(d.chain ?? [])],
|
|
55
|
+
...(skipped.length > 0 ? { skipped: skipped.map((s) => ({ ...s })) } : {}),
|
|
34
56
|
lane,
|
|
35
57
|
...(fromWindow !== undefined ? { fromWindow } : {}),
|
|
36
58
|
...(toWindow !== undefined ? { toWindow } : {}),
|
|
37
|
-
|
|
38
|
-
...(ids.runId !== undefined ? { runId: ids.runId } : {}),
|
|
59
|
+
...attribution,
|
|
39
60
|
},
|
|
40
61
|
});
|
|
41
62
|
},
|
|
@@ -108,10 +108,10 @@ export function createHarnessHandlers(input) {
|
|
|
108
108
|
const requestedModel = rs.telemetry.requestedModel ?? prepared.model;
|
|
109
109
|
const answerBills = m.role === "assistant" ? billsOf(requestedModel, m) : undefined;
|
|
110
110
|
const walked = answerBills?.reading.degraded;
|
|
111
|
-
if (walked !== undefined
|
|
112
|
-
rs.degrade.recordDegraded({ from: walked.from, to: walked.to, reason: walked.reason, atTurn: stats.turns + 1, ...(walked.chain && { chain: walked.chain }) });
|
|
111
|
+
if (walked !== undefined)
|
|
112
|
+
rs.degrade.recordDegraded({ from: walked.from, to: walked.to, reason: walked.reason, atTurn: stats.turns + 1, ...(walked.chain && { chain: walked.chain }), ...(walked.skipped && { skipped: walked.skipped }), ...(walked.outcome !== undefined ? { outcome: walked.outcome } : {}), ...(walked.answeredBy !== undefined ? { answeredBy: walked.answeredBy } : {}) });
|
|
113
|
+
if (answerBills !== undefined)
|
|
113
114
|
rs.degrade.fallbackSeat.observe("main", requestedModel, answerBills.reading);
|
|
114
|
-
}
|
|
115
115
|
if (answeredWithoutModel(m)) {
|
|
116
116
|
rs.turn.turnUsage ??= { inputTokens: 0, totalInputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0, costMicroUsd: 0 };
|
|
117
117
|
}
|
|
@@ -93,7 +93,13 @@ export function runTelemetryAndBudgetSeats(input) {
|
|
|
93
93
|
noteUnevaluablePriceTable(pricing);
|
|
94
94
|
return { pricing, pricingConfigured: isModelPriced(model, runner.deps.pricing), cacheFamily: cacheFamilyOf(model) };
|
|
95
95
|
};
|
|
96
|
-
rs.degrade.fallbackSeat = createModelFallbackSeat(runner.deps.onNotice, { sessionId: prepared.sessionId, runId: prepared.runId })
|
|
96
|
+
rs.degrade.fallbackSeat = createModelFallbackSeat(runner.deps.onNotice, { sessionId: prepared.sessionId, runId: prepared.runId }, (sentence) => {
|
|
97
|
+
try {
|
|
98
|
+
runner.deps.onError?.(new Error(sentence), { phase: "degraded", sessionId: prepared.sessionId });
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
}
|
|
102
|
+
});
|
|
97
103
|
rs.degrade.recordDegraded = (info) => {
|
|
98
104
|
if (rs.degrade.degraded !== undefined)
|
|
99
105
|
return;
|
|
@@ -49,7 +49,7 @@ export interface SideCallAccount {
|
|
|
49
49
|
pricing: () => RunnerDeps["pricing"];
|
|
50
50
|
/** The telemetry lane's price-table door, consulted for every table a side call adopts. */
|
|
51
51
|
noteUnevaluablePriceTable: (p: ModelPricing) => void;
|
|
52
|
-
/** Where a walked reply is announced (the leg's `model.fallback` seat); absent ⇒ not announced. */
|
|
52
|
+
/** Where a walked reply — or one whose walk sent no hop — is announced (the leg's `model.fallback` seat); absent ⇒ not announced. */
|
|
53
53
|
noteFallback?: (lane: SideCallLane, requested: Model, reading: ServedReading) => void;
|
|
54
54
|
}
|
|
55
55
|
/** What one billed call tells the account beyond its usage: the model it is priced at and the marks of what is unknown. */
|
|
@@ -71,7 +71,7 @@ export function sideCallBookOf(stats, account) {
|
|
|
71
71
|
...(i === entries.length - 1 && typeof reply?.stopReason === "string" ? { stopReason: reply.stopReason } : {}),
|
|
72
72
|
});
|
|
73
73
|
});
|
|
74
|
-
if (reading.degraded !== undefined)
|
|
74
|
+
if (reading.degraded !== undefined || reading.unsent !== undefined)
|
|
75
75
|
account.noteFallback?.(lane, model, reading);
|
|
76
76
|
};
|
|
77
77
|
}
|
|
@@ -454,6 +454,17 @@ export interface TaskResult {
|
|
|
454
454
|
reason: import("./model-fallbacks.js").DegradeReason;
|
|
455
455
|
/** The fallback-chain model ids tried after the requested model, in order (absent on the budget path). */
|
|
456
456
|
chain?: string[];
|
|
457
|
+
/** The fallback-chain hops the deployment Brain's route judgment refused before they were sent, in chain order — each model id
|
|
458
|
+
* and the refusal code the judgment stated (absent when it stated none); absent when none was refused and on the budget path. */
|
|
459
|
+
skipped?: {
|
|
460
|
+
model: string;
|
|
461
|
+
code?: string;
|
|
462
|
+
}[];
|
|
463
|
+
/** How the walk ended, the marker's word: `served` (a fallback hop answered — `to`) or `exhausted` (no hop could; the turn's
|
|
464
|
+
* answer is the requested model's own failure — `to` is the last hop tried, not the model that answered). Absent on the budget path. */
|
|
465
|
+
outcome?: "served" | "exhausted";
|
|
466
|
+
/** Whose message the walked turn's answer is: `to` when a hop served, `from` when the chain was exhausted. Absent on the budget path. */
|
|
467
|
+
answeredBy?: string;
|
|
457
468
|
/** 1-based turn during which the switch happened. A walk: the turn whose answer was walked. Budget: the
|
|
458
469
|
* turn whose cumulative cost crossed the threshold (the switch takes effect from the next turn). */
|
|
459
470
|
atTurn: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export { LspDiagnosticsRegistry, formatDiagnosticsBlock, formatDiagnosticsSummar
|
|
|
52
52
|
export { NodeLspManager, DEFAULT_LSP_SERVERS, languageFor, defaultLspSpawn, type NodeLspManagerOptions, type LspSpawn, } from "./engine/lsp/node-lsp-manager.js";
|
|
53
53
|
export { StdioLspTransport, type LspChildProcess } from "./engine/lsp/stdio-lsp-transport.js";
|
|
54
54
|
export { encodeFrame, createFrameDecoder } from "./engine/lsp/frame-decoder.js";
|
|
55
|
-
export { resolveModel, resolveTaskModel, parseModelMention, expandTiers, tierAliasVia, DEFAULT_TIER_ORDER, CC_MODEL_TIER_ALIASES, ROLE_TIER_DEFAULTS, MODEL_ROLES, type ModelRole, type RoleSpec, type ModelRoles, type ResolvedRole, type ModelMention, } from "./core/roles.js";
|
|
55
|
+
export { resolveModel, resolveTaskModel, parseModelMention, expandTiers, catalogOfDeps, tierAliasVia, DEFAULT_TIER_ORDER, CC_MODEL_TIER_ALIASES, ROLE_TIER_DEFAULTS, MODEL_ROLES, type ModelRole, type RoleSpec, type ModelRoles, type ResolvedRole, type ModelMention, } from "./core/roles.js";
|
|
56
56
|
export { modelOriginOf } from "./core/model-receipt.js";
|
|
57
57
|
export { selectModel, selectModelOrThrow, type ModelCriteria, type ModelTier } from "./core/select-model.js";
|
|
58
58
|
export { BrainError, classifyHttp, isProviderEchoShape, PROVIDER_ECHO_SHAPE, PROXY_TUNNEL_REFUSED, type BrainErrorCode } from "./brain/errors.js";
|
|
@@ -477,7 +477,8 @@ export { createFailoverBrain } from "./brain/failover.js";
|
|
|
477
477
|
export { createRoutingBrain, brainLaneOf, type RoutingBrainOptions } from "./brain/routing.js";
|
|
478
478
|
export { repairTextToolCalls } from "./brain/tool-call-repair.js";
|
|
479
479
|
export { createCircuitBreakerBrain, type CircuitBreakerOptions, type BreakerState, type BreakerSnapshot, type BreakerPhase, CIRCUIT_OPEN_MARKER, } from "./brain/circuit-breaker.js";
|
|
480
|
-
export { readDegradation, DEGRADED_DIAGNOSTIC_TYPE, type DegradeReason, type DegradationInfo } from "./brain/model-lane.js";
|
|
480
|
+
export { readDegradation, DEGRADED_DIAGNOSTIC_TYPE, type DegradeReason, type DegradationInfo, type SkippedHop } from "./brain/model-lane.js";
|
|
481
|
+
export { readFallbackUnsent, FALLBACK_UNSENT_DIAGNOSTIC_TYPE, type FallbackUnsent } from "./brain/model-lane.js";
|
|
481
482
|
export type { ModelFallbackPolicy } from "./core/model-fallbacks.js";
|
|
482
483
|
export { retryBackoffMs, parseRetryAfter } from "./brain/retry.js";
|
|
483
484
|
export { WAITING_FIRST_TOKEN_AFTER_MS, WAITING_FIRST_TOKEN_EVERY_MS } from "./brain/stream-engine.js";
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ export { LspDiagnosticsRegistry, formatDiagnosticsBlock, formatDiagnosticsSummar
|
|
|
36
36
|
export { NodeLspManager, DEFAULT_LSP_SERVERS, languageFor, defaultLspSpawn, } from "./engine/lsp/node-lsp-manager.js";
|
|
37
37
|
export { StdioLspTransport } from "./engine/lsp/stdio-lsp-transport.js";
|
|
38
38
|
export { encodeFrame, createFrameDecoder } from "./engine/lsp/frame-decoder.js";
|
|
39
|
-
export { resolveModel, resolveTaskModel, parseModelMention, expandTiers, tierAliasVia, DEFAULT_TIER_ORDER, CC_MODEL_TIER_ALIASES, ROLE_TIER_DEFAULTS, MODEL_ROLES, } from "./core/roles.js";
|
|
39
|
+
export { resolveModel, resolveTaskModel, parseModelMention, expandTiers, catalogOfDeps, tierAliasVia, DEFAULT_TIER_ORDER, CC_MODEL_TIER_ALIASES, ROLE_TIER_DEFAULTS, MODEL_ROLES, } from "./core/roles.js";
|
|
40
40
|
export { modelOriginOf } from "./core/model-receipt.js";
|
|
41
41
|
export { selectModel, selectModelOrThrow } from "./core/select-model.js";
|
|
42
42
|
export { BrainError, classifyHttp, isProviderEchoShape, PROVIDER_ECHO_SHAPE, PROXY_TUNNEL_REFUSED } from "./brain/errors.js";
|
|
@@ -392,6 +392,7 @@ export { createRoutingBrain, brainLaneOf } from "./brain/routing.js";
|
|
|
392
392
|
export { repairTextToolCalls } from "./brain/tool-call-repair.js";
|
|
393
393
|
export { createCircuitBreakerBrain, CIRCUIT_OPEN_MARKER, } from "./brain/circuit-breaker.js";
|
|
394
394
|
export { readDegradation, DEGRADED_DIAGNOSTIC_TYPE } from "./brain/model-lane.js";
|
|
395
|
+
export { readFallbackUnsent, FALLBACK_UNSENT_DIAGNOSTIC_TYPE } from "./brain/model-lane.js";
|
|
395
396
|
export { retryBackoffMs, parseRetryAfter } from "./brain/retry.js";
|
|
396
397
|
export { WAITING_FIRST_TOKEN_AFTER_MS, WAITING_FIRST_TOKEN_EVERY_MS } from "./brain/stream-engine.js";
|
|
397
398
|
export { adjudicateModelRoute, resolveRouteCredential, admitRouteRequest, rebindCredentialOrigin, routeRefusalText, routePairingStatus, routeKeyOf, displayUrlOf, resolveRequestRoot, resolveRequestRootOf, joinRequestUrl, hasAuthCarrier, __resetCredentialOriginBindings, } from "./brain/route-adjudicator.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sema-agent/core",
|
|
3
|
-
"version": "7.67.
|
|
3
|
+
"version": "7.67.1",
|
|
4
4
|
"description": "Stateless, task-oriented AI agent core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "BUSL-1.1",
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
"dependencies": {
|
|
132
132
|
"@modelcontextprotocol/client": "2.4.0",
|
|
133
133
|
"@modelcontextprotocol/core": "2.4.0",
|
|
134
|
-
"@sema-agent/primitives": "7.67.
|
|
134
|
+
"@sema-agent/primitives": "7.67.1",
|
|
135
135
|
"typebox": "1.1.39",
|
|
136
136
|
"undici": "7.30.0"
|
|
137
137
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_comment": "design/87 L3 — frozen public export surface of src/index.ts (name -> kind). DO NOT edit by hand to silence a red test. A removed/changed entry = a BREAKING change: name every removed entry in the CHANGELOG's BREAKING lines (what was removed / who is hurt / what to read instead) and update this fixture in the SAME commit. Regenerate via REGEN in test/export-surface.test.ts.",
|
|
3
3
|
"_tierComment": "#435 v1 — machine-readable layering of the public surface: stable = demonstrated by README.md / src/examples; internal = an `Internal`-marked name or a runner/engine deep-subtree declaration (the model seam src/engine/llm is excluded — it is the BYOM contract, not an engine internal); advanced = a supported export the front door does not walk you through. THIS IS AN INITIAL HEURISTIC, derived mechanically and expected to be refined ticket by ticket: no human reviewed these 1700+ entries one by one, and nothing here claims otherwise. Known bias: a short or English-word export name (ok, err, Result, Usage) can match ordinary prose in README.md and land `stable` on a coincidence. Every export MUST carry a tier — a new export with no row fails the gate in export-surface.test.ts.",
|
|
4
|
-
"count":
|
|
4
|
+
"count": 3315,
|
|
5
5
|
"exports": {
|
|
6
6
|
"A2ATaskState": "type",
|
|
7
7
|
"A2ATaskStateReversal": "type",
|
|
@@ -645,6 +645,7 @@
|
|
|
645
645
|
"ExternalNotificationInput": "interface",
|
|
646
646
|
"F012_CHECKPOINT_VERSION": "variable",
|
|
647
647
|
"FABLE_5_COMPAT": "variable",
|
|
648
|
+
"FALLBACK_UNSENT_DIAGNOSTIC_TYPE": "variable",
|
|
648
649
|
"FILE_HISTORY_DIFF_LINE_BUDGET": "variable",
|
|
649
650
|
"FILE_HISTORY_ERROR_CODES": "variable",
|
|
650
651
|
"FILE_HISTORY_REFUSAL_CLASSES": "variable",
|
|
@@ -656,6 +657,7 @@
|
|
|
656
657
|
"FORK_SUBAGENT_TYPE": "variable",
|
|
657
658
|
"FRONTMATTER_FENCE": "variable",
|
|
658
659
|
"FROZEN_DENYLIST_FLOOR": "variable",
|
|
660
|
+
"FallbackUnsent": "interface",
|
|
659
661
|
"FileBackgroundAgentStore": "class",
|
|
660
662
|
"FileBackgroundAgentStoreOptions": "interface",
|
|
661
663
|
"FileBackupCapture": "type",
|
|
@@ -1958,6 +1960,7 @@
|
|
|
1958
1960
|
"SkillsDirectoryOptions": "interface",
|
|
1959
1961
|
"SkillsDirectoryWarning": "interface",
|
|
1960
1962
|
"SkillsDirectoryWarningCode": "type",
|
|
1963
|
+
"SkippedHop": "interface",
|
|
1961
1964
|
"SnapshotId": "type",
|
|
1962
1965
|
"SpecContract": "interface",
|
|
1963
1966
|
"SqlToolOptions": "interface",
|
|
@@ -2426,6 +2429,7 @@
|
|
|
2426
2429
|
"carriesBidiControls": "function",
|
|
2427
2430
|
"carriesCredential": "function",
|
|
2428
2431
|
"catalogEntriesNamed": "function",
|
|
2432
|
+
"catalogOfDeps": "function",
|
|
2429
2433
|
"catalogRuleFaceOf": "function",
|
|
2430
2434
|
"catalogRuleFaceView": "function",
|
|
2431
2435
|
"catalogText": "function",
|
|
@@ -3018,6 +3022,7 @@
|
|
|
3018
3022
|
"readDenyHomesOf": "function",
|
|
3019
3023
|
"readDenyPatternRun": "function",
|
|
3020
3024
|
"readDenyRowAnchor": "function",
|
|
3025
|
+
"readFallbackUnsent": "function",
|
|
3021
3026
|
"readIncarnationCell": "function",
|
|
3022
3027
|
"readJsonlRecords": "function",
|
|
3023
3028
|
"readMailboxAppend": "function",
|
|
@@ -3957,6 +3962,7 @@
|
|
|
3957
3962
|
"ExternalNotificationInput": "advanced",
|
|
3958
3963
|
"F012_CHECKPOINT_VERSION": "advanced",
|
|
3959
3964
|
"FABLE_5_COMPAT": "advanced",
|
|
3965
|
+
"FALLBACK_UNSENT_DIAGNOSTIC_TYPE": "advanced",
|
|
3960
3966
|
"FILE_HISTORY_DIFF_LINE_BUDGET": "advanced",
|
|
3961
3967
|
"FILE_HISTORY_ERROR_CODES": "advanced",
|
|
3962
3968
|
"FILE_HISTORY_REFUSAL_CLASSES": "advanced",
|
|
@@ -3968,6 +3974,7 @@
|
|
|
3968
3974
|
"FORK_SUBAGENT_TYPE": "advanced",
|
|
3969
3975
|
"FRONTMATTER_FENCE": "advanced",
|
|
3970
3976
|
"FROZEN_DENYLIST_FLOOR": "advanced",
|
|
3977
|
+
"FallbackUnsent": "advanced",
|
|
3971
3978
|
"FileBackgroundAgentStore": "advanced",
|
|
3972
3979
|
"FileBackgroundAgentStoreOptions": "advanced",
|
|
3973
3980
|
"FileBackupCapture": "advanced",
|
|
@@ -5270,6 +5277,7 @@
|
|
|
5270
5277
|
"SkillsDirectoryOptions": "advanced",
|
|
5271
5278
|
"SkillsDirectoryWarning": "advanced",
|
|
5272
5279
|
"SkillsDirectoryWarningCode": "advanced",
|
|
5280
|
+
"SkippedHop": "advanced",
|
|
5273
5281
|
"SnapshotId": "advanced",
|
|
5274
5282
|
"SpecContract": "advanced",
|
|
5275
5283
|
"SqlToolOptions": "advanced",
|
|
@@ -5738,6 +5746,7 @@
|
|
|
5738
5746
|
"carriesBidiControls": "advanced",
|
|
5739
5747
|
"carriesCredential": "advanced",
|
|
5740
5748
|
"catalogEntriesNamed": "advanced",
|
|
5749
|
+
"catalogOfDeps": "advanced",
|
|
5741
5750
|
"catalogRuleFaceOf": "advanced",
|
|
5742
5751
|
"catalogRuleFaceView": "advanced",
|
|
5743
5752
|
"catalogText": "advanced",
|
|
@@ -6330,6 +6339,7 @@
|
|
|
6330
6339
|
"readDenyHomesOf": "advanced",
|
|
6331
6340
|
"readDenyPatternRun": "advanced",
|
|
6332
6341
|
"readDenyRowAnchor": "advanced",
|
|
6342
|
+
"readFallbackUnsent": "advanced",
|
|
6333
6343
|
"readIncarnationCell": "internal",
|
|
6334
6344
|
"readJsonlRecords": "advanced",
|
|
6335
6345
|
"readMailboxAppend": "advanced",
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"repo": "core",
|
|
3
|
+
"package": "@sema-agent/core-stores-sql",
|
|
4
|
+
"version": "7.67.1",
|
|
5
|
+
"from": "d59f845b5daf6d41297dd0433304787c2fa2eb49",
|
|
6
|
+
"to": "v7.67.1",
|
|
7
|
+
"added": [],
|
|
8
|
+
"removed": [],
|
|
9
|
+
"changed": [],
|
|
10
|
+
"subpaths": [],
|
|
11
|
+
"subpathsUnread": [
|
|
12
|
+
"from",
|
|
13
|
+
"to"
|
|
14
|
+
],
|
|
15
|
+
"narrowed": [],
|
|
16
|
+
"faces": {
|
|
17
|
+
"open": [],
|
|
18
|
+
"source": null
|
|
19
|
+
},
|
|
20
|
+
"closedSetMembers": [],
|
|
21
|
+
"closedSetsUnreadable": [],
|
|
22
|
+
"typeKeys": [],
|
|
23
|
+
"typeKeysUnreadableArms": [],
|
|
24
|
+
"typeKeysFlattenedCount": 3,
|
|
25
|
+
"signatures": [],
|
|
26
|
+
"versionLiterals": [],
|
|
27
|
+
"declarationMoves": [],
|
|
28
|
+
"mintMoves": [],
|
|
29
|
+
"criteriaObserves": [],
|
|
30
|
+
"consumersHint": {
|
|
31
|
+
"cli": [],
|
|
32
|
+
"server": [],
|
|
33
|
+
"sdk": [],
|
|
34
|
+
"note": "scanned cli@a78ccb3d server@fbcb3ff18 sdk@3708338 — a name listed is MENTIONED there today, which is evidence of consumption, not proof of it"
|
|
35
|
+
},
|
|
36
|
+
"breakingCount": 0,
|
|
37
|
+
"breakingItems": [],
|
|
38
|
+
"toResolvedAt": "93c06dc3214f604207d2bd2ea6c5e94b8362748c"
|
|
39
|
+
}
|