@happyvertical/smrt-inference 0.61.5 → 0.62.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.
Files changed (72) hide show
  1. package/AGENTS.md +3 -1
  2. package/README.md +4 -0
  3. package/agents/engines.md +87 -90
  4. package/agents/fusions.md +13 -5
  5. package/dist/agent-cli/session.d.ts +8 -2
  6. package/dist/agent-cli/session.d.ts.map +1 -1
  7. package/dist/agent-cli/stream.d.ts +5 -0
  8. package/dist/agent-cli/stream.d.ts.map +1 -1
  9. package/dist/agent-cli/turn.d.ts +12 -5
  10. package/dist/agent-cli/turn.d.ts.map +1 -1
  11. package/dist/assistant-settings.d.ts +26 -0
  12. package/dist/assistant-settings.d.ts.map +1 -0
  13. package/dist/chatgpt/model.d.ts +14 -6
  14. package/dist/chatgpt/model.d.ts.map +1 -1
  15. package/dist/chunks/{InferenceOverrideCollection-CBtHeGyB.js → InferenceOverrideCollection-DXfD7iq5.js} +3 -66
  16. package/dist/chunks/InferenceOverrideCollection-DXfD7iq5.js.map +1 -0
  17. package/dist/chunks/model-fallback-BVD3BzkG.js +171 -0
  18. package/dist/chunks/model-fallback-BVD3BzkG.js.map +1 -0
  19. package/dist/chunks/{provider-config-BSpIQRVM.js → provider-config-Q1WaQKfo.js} +164 -31
  20. package/dist/chunks/provider-config-Q1WaQKfo.js.map +1 -0
  21. package/dist/classify.d.ts +9 -0
  22. package/dist/classify.d.ts.map +1 -1
  23. package/dist/engine-tiers.d.ts +100 -0
  24. package/dist/engine-tiers.d.ts.map +1 -0
  25. package/dist/executor.d.ts.map +1 -1
  26. package/dist/fusion.d.ts +7 -1
  27. package/dist/fusion.d.ts.map +1 -1
  28. package/dist/index.d.ts +3 -2
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +3 -3
  31. package/dist/index.js.map +1 -1
  32. package/dist/manifest.json +92 -205
  33. package/dist/model-fallback.d.ts +63 -0
  34. package/dist/model-fallback.d.ts.map +1 -0
  35. package/dist/models.d.ts +0 -1
  36. package/dist/models.d.ts.map +1 -1
  37. package/dist/models.js +2 -2
  38. package/dist/node.js +1 -1
  39. package/dist/resolver.js +1 -1
  40. package/dist/server.d.ts +3 -4
  41. package/dist/server.d.ts.map +1 -1
  42. package/dist/server.js +79 -130
  43. package/dist/server.js.map +1 -1
  44. package/dist/smrt-knowledge.json +16 -88
  45. package/dist/smrt-knowledge.okf.md +6 -11
  46. package/dist/svelte/components/InferenceAssistantSettings.svelte +98 -0
  47. package/dist/svelte/components/InferenceAssistantSettings.svelte.d.ts +19 -0
  48. package/dist/svelte/components/InferenceAssistantSettings.svelte.d.ts.map +1 -0
  49. package/dist/svelte/components/InferenceSettingsPanel.svelte +22 -1
  50. package/dist/svelte/components/InferenceSettingsPanel.svelte.d.ts +10 -2
  51. package/dist/svelte/components/InferenceSettingsPanel.svelte.d.ts.map +1 -1
  52. package/dist/svelte/components/InferenceUsageTable.svelte +7 -7
  53. package/dist/svelte/components/InferenceUsageTable.svelte.d.ts +1 -1
  54. package/dist/svelte/index.d.ts +1 -1
  55. package/dist/svelte/index.d.ts.map +1 -1
  56. package/dist/svelte/types.d.ts +27 -4
  57. package/dist/svelte/types.d.ts.map +1 -1
  58. package/dist/svelte/types.js +4 -4
  59. package/package.json +99 -8
  60. package/agents/design-runs.md +0 -110
  61. package/dist/chunks/InferenceOverrideCollection-CBtHeGyB.js.map +0 -1
  62. package/dist/chunks/provider-config-BSpIQRVM.js.map +0 -1
  63. package/dist/chunks/work-profiles-DCgIbilc.js +0 -484
  64. package/dist/chunks/work-profiles-DCgIbilc.js.map +0 -1
  65. package/dist/design-run-store.d.ts +0 -26
  66. package/dist/design-run-store.d.ts.map +0 -1
  67. package/dist/design-run.d.ts +0 -146
  68. package/dist/design-run.d.ts.map +0 -1
  69. package/dist/models/DesignRunRecord.d.ts +0 -22
  70. package/dist/models/DesignRunRecord.d.ts.map +0 -1
  71. package/dist/work-profiles.d.ts +0 -127
  72. package/dist/work-profiles.d.ts.map +0 -1
@@ -599,7 +599,12 @@ function isInferenceAbort(error) {
599
599
  const facts = collectFacts(error);
600
600
  return hasAny(facts.codes, ABORT_CODES) || hasAny(facts.names, ABORT_NAMES);
601
601
  }
602
+ function isAiRunInterruption(error) {
603
+ const code = error?.code;
604
+ return code === "AI_RUN_STOPPED" || code === "AI_RUN_CLAIM_LOST";
605
+ }
602
606
  function classifyInferenceFailure(error) {
607
+ if (isAiRunInterruption(error)) return void 0;
603
608
  const unavailable = error;
604
609
  if (unavailable && typeof unavailable === "object" && unavailable.code === "AI_UNAVAILABLE" && unavailable.reason === "capability") return "missing-capability";
605
610
  const facts = collectFacts(error);
@@ -775,6 +780,7 @@ var ChainCall = class {
775
780
  async recordFailure(outcome, reason) {
776
781
  const step = this.lastStep;
777
782
  const { tierResolved: _unanswered, ...callerTags } = this.callerOptions.usageTags ?? {};
783
+ const { runContext } = this.callerOptions;
778
784
  try {
779
785
  await this.context.recordUsage({
780
786
  ...typeof step?.target.provider === "string" ? { provider: step.target.provider } : {},
@@ -787,7 +793,8 @@ var ChainCall = class {
787
793
  outcome,
788
794
  reason,
789
795
  substitutions: JSON.stringify(this.substitutions)
790
- }
796
+ },
797
+ ...runContext ? { runContext } : {}
791
798
  });
792
799
  } catch {}
793
800
  }
@@ -843,7 +850,7 @@ var ChainCall = class {
843
850
  });
844
851
  }
845
852
  if (outcome.cls === void 0) {
846
- if (!isInferenceAbort(outcome.error) && !isInferenceUnavailableError(outcome.error)) {
853
+ if (!isInferenceAbort(outcome.error) && !isInferenceUnavailableError(outcome.error) && !isAiRunInterruption(outcome.error)) {
847
854
  this.substitutions.push({
848
855
  from: step.label,
849
856
  to: null,
@@ -1130,6 +1137,9 @@ This seat produced no output; answer from the other material.`;
1130
1137
  ${seatOutputText(seat)}
1131
1138
  --- end of ${seat.name} ---`;
1132
1139
  }
1140
+ var DEFAULT_SEAT_OUTPUT_TOKENS = 4096;
1141
+ var JUDGE_FRAMING_CHARS = 240;
1142
+ var GATE_OUTPUT_TOKENS = 512;
1133
1143
  var FusionRun = class {
1134
1144
  constructor(context, key, definition, callerOptions, options) {
1135
1145
  this.context = context;
@@ -1137,7 +1147,8 @@ var FusionRun = class {
1137
1147
  this.definition = definition;
1138
1148
  this.options = options;
1139
1149
  this.started = options.now();
1140
- const { usageTags, model: _model, ...rest } = callerOptions;
1150
+ this.entryOptions = callerOptions;
1151
+ const { usageTags, model: _model, runContext: _runContext, ...rest } = callerOptions;
1141
1152
  this.callerTags = Object.fromEntries(Object.entries(usageTags ?? {}).filter(([tag]) => !ENTRY_TAGS.has(tag)));
1142
1153
  this.finalOptions = rest;
1143
1154
  this.transport = {};
@@ -1156,6 +1167,9 @@ var FusionRun = class {
1156
1167
  definition;
1157
1168
  options;
1158
1169
  runId = newRunId();
1170
+ /** The run opened at the start (#5005), on cores with `openRun`. */
1171
+ handle;
1172
+ entryOptions;
1159
1173
  seats;
1160
1174
  usage = /* @__PURE__ */ new Map();
1161
1175
  gate;
@@ -1263,9 +1277,11 @@ var FusionRun = class {
1263
1277
  role: "system",
1264
1278
  content: prompt.instructions
1265
1279
  }],
1280
+ ...this.handle?.seatOptions(result.name) ?? {},
1266
1281
  usageTags: {
1267
1282
  ...this.callerTags,
1268
1283
  ...prompt.usageTags ?? {},
1284
+ ...this.handle ? { callId: this.handle.entryCallId } : {},
1269
1285
  promptKey: seat.prompt,
1270
1286
  runId: this.runId,
1271
1287
  fusionKey: this.key,
@@ -1289,6 +1305,14 @@ var FusionRun = class {
1289
1305
  }
1290
1306
  else result.text = text;
1291
1307
  } catch (error) {
1308
+ if (isAiRunInterruption(error)) {
1309
+ result.status = "failed";
1310
+ result.failure = {
1311
+ reason: "stopped",
1312
+ message: shortMessage(error)
1313
+ };
1314
+ throw error;
1315
+ }
1292
1316
  if (error instanceof InferenceConfigError || isInferenceAbort(error) || final && error instanceof InferenceExhaustedError && error.reason === "partial") {
1293
1317
  result.status = "failed";
1294
1318
  result.failure = {
@@ -1337,10 +1361,11 @@ var FusionRun = class {
1337
1361
  }, {
1338
1362
  usageTags: {
1339
1363
  ...this.callerTags,
1340
- runId: this.runId,
1364
+ ...this.handle ? {} : { runId: this.runId },
1341
1365
  fusionKey: this.key,
1342
1366
  seat: FUSION_GATE_SEAT
1343
1367
  },
1368
+ ...this.handle ? this.handle.seatOptions(FUSION_GATE_SEAT) : {},
1344
1369
  ...this.signal ? { signal: this.signal } : {}
1345
1370
  });
1346
1371
  if (!result) return { status: "unavailable" };
@@ -1356,7 +1381,7 @@ var FusionRun = class {
1356
1381
  model: `${result.provenance.provider}/${result.provenance.model}`
1357
1382
  };
1358
1383
  } catch (error) {
1359
- if (isInferenceAbort(error)) throw error;
1384
+ if (isInferenceAbort(error) || isAiRunInterruption(error)) throw error;
1360
1385
  return {
1361
1386
  status: "error",
1362
1387
  message: shortMessage(error)
@@ -1432,9 +1457,102 @@ var FusionRun = class {
1432
1457
  durationMs: Math.max(0, this.options.now() - this.started)
1433
1458
  };
1434
1459
  }
1460
+ /**
1461
+ * Each seat's share of the joint reservation (#5005): every seat that may
1462
+ * run, judge included, sized like any call. The judge's input is the
1463
+ * request plus the panel's output allowances, since their answers are
1464
+ * its input; it is checked `running` just before it is sent.
1465
+ */
1466
+ async shares(input) {
1467
+ const { definition } = this;
1468
+ const finalIndex = definition.seats.length - 1;
1469
+ const panel = definition.mode === "single" ? [0] : [...Array(finalIndex).keys()];
1470
+ const finalLimit = typeof this.finalOptions.maxTokens === "number" ? this.finalOptions.maxTokens : void 0;
1471
+ const out = [];
1472
+ let panelAllowance = 0;
1473
+ for (const [index, seat] of definition.seats.entries()) {
1474
+ const final = index === finalIndex;
1475
+ const target = await this.priceTarget(seat);
1476
+ const outputLimit = final ? finalLimit : void 0;
1477
+ const sent = input.length + await this.instructionChars(seat);
1478
+ if (definition.mode === "single" || panel.includes(index)) {
1479
+ panelAllowance += outputLimit ?? DEFAULT_SEAT_OUTPUT_TOKENS;
1480
+ out.push({
1481
+ name: seatName(seat),
1482
+ ...target ? { target } : {},
1483
+ inputTokens: Math.ceil(sent / 4),
1484
+ ...outputLimit !== void 0 ? { outputLimit } : {}
1485
+ });
1486
+ } else out.push({
1487
+ name: seatName(seat),
1488
+ ...target ? { target } : {},
1489
+ inputTokens: Math.ceil((sent + JUDGE_FRAMING_CHARS) / 4) + panelAllowance,
1490
+ ...outputLimit !== void 0 ? { outputLimit } : {},
1491
+ later: true
1492
+ });
1493
+ }
1494
+ if (definition.gate) out.push({
1495
+ name: FUSION_GATE_SEAT,
1496
+ inputTokens: Math.ceil((input.length + JUDGE_FRAMING_CHARS) / 4) + panelAllowance,
1497
+ expectedOutputTokens: GATE_OUTPUT_TOKENS,
1498
+ later: true
1499
+ });
1500
+ return out;
1501
+ }
1502
+ /** Characters of a seat's resolved prompt instructions; 0 when unreadable. */
1503
+ async instructionChars(seat) {
1504
+ try {
1505
+ const prompt = await promptResolver()(seat.prompt, {
1506
+ ...this.context.request.tenantId !== void 0 ? { tenantId: this.context.request.tenantId } : {},
1507
+ ...this.context.db ? { db: this.context.db } : {}
1508
+ });
1509
+ return String(prompt.instructions ?? "").length;
1510
+ } catch {
1511
+ return 0;
1512
+ }
1513
+ }
1514
+ /** A seat's first concrete target, for pricing its share; best effort. */
1515
+ async priceTarget(seat) {
1516
+ try {
1517
+ let target;
1518
+ if (typeof seat.target === "string") {
1519
+ const tier = seat.target === "auto" ? resolveAutoTier(this.context.config) : seat.target;
1520
+ target = (await this.context.resolveTier(tier, { promptKey: seat.prompt })).target;
1521
+ } else target = seat.target;
1522
+ return this.firstConcrete(target, 0);
1523
+ } catch {
1524
+ return;
1525
+ }
1526
+ }
1527
+ /**
1528
+ * The first single target a chain would try (an alias entry, an inline
1529
+ * candidate, or an alias a candidate names), for its price.
1530
+ */
1531
+ firstConcrete(target, depth) {
1532
+ if (depth > 8) return void 0;
1533
+ const kind = inferenceTargetKind(target);
1534
+ if (kind === "single") return target;
1535
+ let list;
1536
+ if (kind === "alias") list = this.context.config?.aliases?.[String(target.alias)]?.candidates;
1537
+ else if (kind === "candidates") list = target.candidates;
1538
+ const first = Array.isArray(list) ? list[0] : void 0;
1539
+ if (!first || typeof first !== "object") return void 0;
1540
+ const candidate = first;
1541
+ return candidate.alias ? this.firstConcrete({ alias: candidate.alias }, depth + 1) : candidate;
1542
+ }
1435
1543
  async record(result) {
1436
- if (!this.context.recordRun) return;
1437
1544
  const ran = result.seats.filter((seat) => seat.status === "ok" || seat.status === "failed");
1545
+ const details = this.details(result);
1546
+ if (this.handle) {
1547
+ await this.handle.close({
1548
+ status: result.status,
1549
+ seats: ran.length,
1550
+ degradedSeats: ran.filter(isDegraded).length,
1551
+ details
1552
+ });
1553
+ return;
1554
+ }
1555
+ if (!this.context.recordRun) return;
1438
1556
  try {
1439
1557
  await this.context.recordRun({
1440
1558
  id: result.runId,
@@ -1445,34 +1563,47 @@ var FusionRun = class {
1445
1563
  degradedSeats: ran.filter(isDegraded).length,
1446
1564
  status: result.status,
1447
1565
  duration: result.durationMs,
1448
- details: {
1449
- seats: result.seats.map((seat) => ({
1450
- persona: seat.name,
1451
- prompt: seat.prompt,
1452
- status: seat.status,
1453
- target: seat.target,
1454
- ...seat.model ? { model: seat.model } : {},
1455
- ...seat.usage ? { usage: seat.usage } : {},
1456
- ...seat.substitutions ? { substitutions: seat.substitutions } : {},
1457
- ...seat.failure ? { failure: {
1458
- reason: seat.failure.reason,
1459
- ...seat.failure.code ? { code: seat.failure.code } : {}
1460
- } } : {},
1461
- ...seat.raw !== void 0 ? { json: "unparsed" } : {},
1462
- ...seat.json !== void 0 ? { json: "parsed" } : {},
1463
- ...seat.durationMs !== void 0 ? { durationMs: seat.durationMs } : {}
1464
- })),
1465
- ...result.gate ? { gate: {
1466
- status: result.gate.status,
1467
- ...result.gate.choice ? { choice: result.gate.choice } : {},
1468
- ...result.gate.confidence !== void 0 ? { confidence: result.gate.confidence } : {},
1469
- ...result.gate.model ? { model: result.gate.model } : {}
1470
- } } : {}
1471
- }
1566
+ details
1472
1567
  });
1473
1568
  } catch {}
1474
1569
  }
1570
+ details(result) {
1571
+ return {
1572
+ seats: result.seats.map((seat) => ({
1573
+ persona: seat.name,
1574
+ prompt: seat.prompt,
1575
+ status: seat.status,
1576
+ target: seat.target,
1577
+ ...seat.model ? { model: seat.model } : {},
1578
+ ...seat.usage ? { usage: seat.usage } : {},
1579
+ ...seat.substitutions ? { substitutions: seat.substitutions } : {},
1580
+ ...seat.failure ? { failure: {
1581
+ reason: seat.failure.reason,
1582
+ ...seat.failure.code ? { code: seat.failure.code } : {}
1583
+ } } : {},
1584
+ ...seat.raw !== void 0 ? { json: "unparsed" } : {},
1585
+ ...seat.json !== void 0 ? { json: "parsed" } : {},
1586
+ ...seat.durationMs !== void 0 ? { durationMs: seat.durationMs } : {}
1587
+ })),
1588
+ ...result.gate ? { gate: {
1589
+ status: result.gate.status,
1590
+ ...result.gate.choice ? { choice: result.gate.choice } : {},
1591
+ ...result.gate.confidence !== void 0 ? { confidence: result.gate.confidence } : {},
1592
+ ...result.gate.model ? { model: result.gate.model } : {}
1593
+ } } : {}
1594
+ };
1595
+ }
1475
1596
  async run(input) {
1597
+ if (this.context.openRun) {
1598
+ this.handle = await this.context.openRun({
1599
+ type: "fusion",
1600
+ definitionKey: this.key,
1601
+ mode: this.definition.mode,
1602
+ ...this.entryPromptKey ? { promptKey: this.entryPromptKey } : {},
1603
+ callOptions: this.entryOptions
1604
+ });
1605
+ this.runId = this.handle.runId;
1606
+ }
1476
1607
  const stop = this.context.observeUsage?.(this.runId, (event) => {
1477
1608
  const seat = event.tags.seat;
1478
1609
  if (!seat) return;
@@ -1490,8 +1621,10 @@ var FusionRun = class {
1490
1621
  try {
1491
1622
  let text;
1492
1623
  try {
1624
+ if (this.handle) await this.handle.reserve(await this.shares(input));
1493
1625
  text = await this.interpret(input);
1494
1626
  } catch (error) {
1627
+ if (this.handle && isAiRunInterruption(error)) throw await this.handle.stop(error);
1495
1628
  const failed = this.result("failed", "");
1496
1629
  await this.record(failed);
1497
1630
  if (error instanceof InferenceConfigError || isInferenceAbort(error)) throw error;
@@ -1870,4 +2003,4 @@ function inferenceProviderConfigSecretName(scope) {
1870
2003
  //#endregion
1871
2004
  export { candidateLabel as A, InferenceConfigError as B, createChainClient as C, EXECUTOR_KINDS as D, CHAIN_KINDS as E, findFusionPromptIssues as F, InferenceFusionError as H, findInferenceConfigIssues as I, hasInferenceChains as L, expandTarget as M, findFusionDefinitionIssues as N, FUSION_GATE_CONTINUE as O, findFusionDefinitionPromptIssues as P, validateInferenceConfig as R, setFusionPromptResolver as S, isInferenceAbort as T, InferenceExhaustedError as V, createFusionClient as _, inferenceProviderBindingFor as a, listFusions as b, inferenceProviderTargets as c, redactInferenceTarget as d, createInferenceResolver as f, createChainExecutor as g, clearFusions as h, InferenceProviderConfigError as i, candidateToStep as j, FUSION_SEAT_COUNTS as k, parseInferenceProviderConfig as l, registerInference as m, INFERENCE_PROVIDER_CONFIG_SOURCES as n, inferenceProviderConfigSecretName as o, isInferenceRegistered as p, INFERENCE_PROVIDER_PARAM_KEYS as r, inferenceProviderSource as s, INFERENCE_PROVIDER_CONFIG_SECRET_TYPE as t, redactInferenceProviderConfig as u, defineFusion as v, classifyInferenceFailure as w, runFusion as x, getFusion as y, validateInferenceTarget as z };
1872
2005
 
1873
- //# sourceMappingURL=provider-config-BSpIQRVM.js.map
2006
+ //# sourceMappingURL=provider-config-Q1WaQKfo.js.map