@aexol/spectral 0.9.231 → 0.9.240

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 (157) hide show
  1. package/README.md +47 -0
  2. package/dist/agent/index.d.ts +32 -5
  3. package/dist/agent/index.d.ts.map +1 -1
  4. package/dist/agent/index.js +209 -36
  5. package/dist/backend/generated-images.d.ts +1 -1
  6. package/dist/backend/generated-images.d.ts.map +1 -1
  7. package/dist/cli.d.ts +2 -0
  8. package/dist/cli.d.ts.map +1 -1
  9. package/dist/cli.js +18 -4
  10. package/dist/commands/desktop.d.ts +167 -0
  11. package/dist/commands/desktop.d.ts.map +1 -0
  12. package/dist/commands/desktop.js +540 -0
  13. package/dist/commands/serve.d.ts +9 -1
  14. package/dist/commands/serve.d.ts.map +1 -1
  15. package/dist/commands/serve.js +90 -2
  16. package/dist/commands/update.d.ts +85 -5
  17. package/dist/commands/update.d.ts.map +1 -1
  18. package/dist/commands/update.js +288 -58
  19. package/dist/extensions/desktop-control/macos.d.ts.map +1 -1
  20. package/dist/extensions/desktop-control/macos.js +2 -2
  21. package/dist/extensions/logic-trace.d.ts +1 -1
  22. package/dist/extensions/logic-trace.d.ts.map +1 -1
  23. package/dist/extensions/logic-trace.js +199 -70
  24. package/dist/extensions/video-generation/index.d.ts +3 -0
  25. package/dist/extensions/video-generation/index.d.ts.map +1 -0
  26. package/dist/extensions/video-generation/index.js +299 -0
  27. package/dist/generated/zeus/const.d.ts.map +1 -1
  28. package/dist/generated/zeus/const.js +30 -0
  29. package/dist/generated/zeus/index.d.ts +140 -0
  30. package/dist/generated/zeus/index.d.ts.map +1 -1
  31. package/dist/generated/zeus/index.js +5 -0
  32. package/dist/mcp/server-manager.d.ts.map +1 -1
  33. package/dist/mcp/server-manager.js +6 -0
  34. package/dist/memory/tools/receive-agent-observations.d.ts.map +1 -1
  35. package/dist/memory/tools/receive-agent-observations.js +12 -2
  36. package/dist/relay/dispatcher.d.ts +13 -1
  37. package/dist/relay/dispatcher.d.ts.map +1 -1
  38. package/dist/relay/dispatcher.js +41 -2
  39. package/dist/sdk/agent-core/agent-loop.js +13 -3
  40. package/dist/sdk/agent-core/agent.d.ts +11 -4
  41. package/dist/sdk/agent-core/agent.d.ts.map +1 -1
  42. package/dist/sdk/agent-core/agent.js +16 -4
  43. package/dist/sdk/agent-core/tool-call-registry.d.ts +75 -0
  44. package/dist/sdk/agent-core/tool-call-registry.d.ts.map +1 -0
  45. package/dist/sdk/agent-core/tool-call-registry.js +131 -0
  46. package/dist/sdk/agent-core/tool-execution.d.ts.map +1 -1
  47. package/dist/sdk/agent-core/tool-execution.js +103 -4
  48. package/dist/sdk/agent-core/types.d.ts +15 -4
  49. package/dist/sdk/agent-core/types.d.ts.map +1 -1
  50. package/dist/sdk/ai/index.d.ts +3 -0
  51. package/dist/sdk/ai/index.d.ts.map +1 -1
  52. package/dist/sdk/ai/index.js +3 -0
  53. package/dist/sdk/ai/providers/faux.d.ts.map +1 -1
  54. package/dist/sdk/ai/providers/faux.js +3 -0
  55. package/dist/sdk/ai/providers/leaked-tool-call-parser.d.ts +39 -6
  56. package/dist/sdk/ai/providers/leaked-tool-call-parser.d.ts.map +1 -1
  57. package/dist/sdk/ai/providers/leaked-tool-call-parser.js +159 -18
  58. package/dist/sdk/ai/providers/openai-completions.d.ts.map +1 -1
  59. package/dist/sdk/ai/providers/openai-completions.js +22 -8
  60. package/dist/sdk/ai/providers/openrouter-videos.d.ts +3 -0
  61. package/dist/sdk/ai/providers/openrouter-videos.d.ts.map +1 -0
  62. package/dist/sdk/ai/providers/openrouter-videos.js +412 -0
  63. package/dist/sdk/ai/providers/register-builtins.d.ts.map +1 -1
  64. package/dist/sdk/ai/providers/register-builtins.js +6 -0
  65. package/dist/sdk/ai/providers/simple-options.d.ts +1 -6
  66. package/dist/sdk/ai/providers/simple-options.d.ts.map +1 -1
  67. package/dist/sdk/ai/providers/simple-options.js +0 -22
  68. package/dist/sdk/ai/providers/transform-messages.d.ts.map +1 -1
  69. package/dist/sdk/ai/providers/transform-messages.js +52 -1
  70. package/dist/sdk/ai/types.d.ts +91 -10
  71. package/dist/sdk/ai/types.d.ts.map +1 -1
  72. package/dist/sdk/ai/video-models.d.ts +10 -0
  73. package/dist/sdk/ai/video-models.d.ts.map +1 -0
  74. package/dist/sdk/ai/video-models.generated.d.ts +440 -0
  75. package/dist/sdk/ai/video-models.generated.d.ts.map +1 -0
  76. package/dist/sdk/ai/video-models.generated.js +441 -0
  77. package/dist/sdk/ai/video-models.js +22 -0
  78. package/dist/sdk/ai/videos-api-registry.d.ts +14 -0
  79. package/dist/sdk/ai/videos-api-registry.d.ts.map +1 -0
  80. package/dist/sdk/ai/videos-api-registry.js +21 -0
  81. package/dist/sdk/ai/videos.d.ts +4 -0
  82. package/dist/sdk/ai/videos.d.ts.map +1 -0
  83. package/dist/sdk/ai/videos.js +13 -0
  84. package/dist/sdk/coding-agent/core/agent-session.d.ts +8 -0
  85. package/dist/sdk/coding-agent/core/agent-session.d.ts.map +1 -1
  86. package/dist/sdk/coding-agent/core/agent-session.js +11 -0
  87. package/dist/sdk/coding-agent/core/extensions/loader.d.ts.map +1 -1
  88. package/dist/sdk/coding-agent/core/extensions/loader.js +14 -0
  89. package/dist/sdk/coding-agent/core/extensions/native-extensions.d.ts +26 -0
  90. package/dist/sdk/coding-agent/core/extensions/native-extensions.d.ts.map +1 -1
  91. package/dist/sdk/coding-agent/core/extensions/native-extensions.js +23 -0
  92. package/dist/sdk/coding-agent/core/extensions/session-events.d.ts +2 -2
  93. package/dist/sdk/coding-agent/core/extensions/session-events.d.ts.map +1 -1
  94. package/dist/sdk/coding-agent/core/extensions/types.d.ts +12 -2
  95. package/dist/sdk/coding-agent/core/extensions/types.d.ts.map +1 -1
  96. package/dist/sdk/coding-agent/core/messages.d.ts.map +1 -1
  97. package/dist/sdk/coding-agent/core/messages.js +42 -2
  98. package/dist/sdk/coding-agent/core/resource-loader.d.ts +11 -0
  99. package/dist/sdk/coding-agent/core/resource-loader.d.ts.map +1 -1
  100. package/dist/sdk/coding-agent/core/resource-loader.js +23 -6
  101. package/dist/sdk/coding-agent/core/sdk.d.ts +24 -2
  102. package/dist/sdk/coding-agent/core/sdk.d.ts.map +1 -1
  103. package/dist/sdk/coding-agent/core/sdk.js +15 -3
  104. package/dist/sdk/coding-agent/core/settings-manager.d.ts +0 -8
  105. package/dist/sdk/coding-agent/core/settings-manager.d.ts.map +1 -1
  106. package/dist/sdk/coding-agent/core/settings-manager.js +3 -3
  107. package/dist/sdk/coding-agent/core/system-prompt.d.ts.map +1 -1
  108. package/dist/sdk/coding-agent/core/system-prompt.js +5 -0
  109. package/dist/sdk/coding-agent/index.d.ts +2 -2
  110. package/dist/sdk/coding-agent/index.d.ts.map +1 -1
  111. package/dist/sdk/coding-agent/index.js +1 -1
  112. package/dist/sdk-public.d.ts +96 -0
  113. package/dist/sdk-public.d.ts.map +1 -0
  114. package/dist/sdk-public.js +109 -0
  115. package/dist/server/agent-bridge/rehydrate.d.ts +2 -2
  116. package/dist/server/agent-bridge/rehydrate.d.ts.map +1 -1
  117. package/dist/server/agent-bridge/rehydrate.js +14 -0
  118. package/dist/server/agent-bridge/tps-metrics.d.ts +34 -0
  119. package/dist/server/agent-bridge/tps-metrics.d.ts.map +1 -1
  120. package/dist/server/agent-bridge/tps-metrics.js +22 -0
  121. package/dist/server/agent-bridge.d.ts +17 -2
  122. package/dist/server/agent-bridge.d.ts.map +1 -1
  123. package/dist/server/agent-bridge.js +108 -5
  124. package/dist/server/handlers/paths-list.d.ts +1 -1
  125. package/dist/server/handlers/paths-list.js +1 -1
  126. package/dist/server/inter-agent-broker.d.ts +12 -0
  127. package/dist/server/inter-agent-broker.d.ts.map +1 -1
  128. package/dist/server/inter-agent-broker.js +1 -0
  129. package/dist/server/preset-chain.d.ts +151 -0
  130. package/dist/server/preset-chain.d.ts.map +1 -0
  131. package/dist/server/preset-chain.js +250 -0
  132. package/dist/server/session-stream.d.ts +74 -1
  133. package/dist/server/session-stream.d.ts.map +1 -1
  134. package/dist/server/session-stream.js +238 -24
  135. package/dist/server/storage/rows.d.ts +2 -0
  136. package/dist/server/storage/rows.d.ts.map +1 -1
  137. package/dist/server/storage/schema.d.ts +2 -2
  138. package/dist/server/storage/schema.d.ts.map +1 -1
  139. package/dist/server/storage/schema.js +2 -1
  140. package/dist/server/storage.d.ts +7 -0
  141. package/dist/server/storage.d.ts.map +1 -1
  142. package/dist/server/storage.js +142 -9
  143. package/dist/server/wire.d.ts +84 -0
  144. package/dist/server/wire.d.ts.map +1 -1
  145. package/dist/utils/augment-path.d.ts +51 -0
  146. package/dist/utils/augment-path.d.ts.map +1 -0
  147. package/dist/utils/augment-path.js +234 -0
  148. package/dist/utils/open-browser.d.ts +55 -0
  149. package/dist/utils/open-browser.d.ts.map +1 -0
  150. package/dist/utils/open-browser.js +163 -0
  151. package/dist/utils/serve-state.d.ts +264 -0
  152. package/dist/utils/serve-state.d.ts.map +1 -0
  153. package/dist/utils/serve-state.js +563 -0
  154. package/dist/utils/standalone.d.ts +14 -0
  155. package/dist/utils/standalone.d.ts.map +1 -0
  156. package/dist/utils/standalone.js +23 -0
  157. package/package.json +7 -3
@@ -70,7 +70,7 @@ import { humanizeProviderError } from "./error-humanizer.js";
70
70
  import { readStudioBinding, getBindingFilePath } from "../studio-binding.js";
71
71
  // Facade imports: cohesive helpers extracted verbatim to `./agent-bridge/` modules.
72
72
  import { calculateCredits, getModelCost, resolveCreditRatesForModel, } from "./agent-bridge/pricing.js";
73
- import { computeTpsMetrics } from "./agent-bridge/tps-metrics.js";
73
+ import { buildTpsUsageFields, computeTpsMetrics, } from "./agent-bridge/tps-metrics.js";
74
74
  import { SPECTRAL_PROXY_OPENAI, SPECTRAL_PROXY_USER_MODEL, inferSyntheticContextWindow, inferSyntheticOpenAICompat, inferSyntheticThinkingLevelMap, } from "./agent-bridge/synthetic-model.js";
75
75
  import { parseWireToolEvents, sanitizeRehydratedBlock, toRestoredMemorySnapshot, } from "./agent-bridge/rehydrate.js";
76
76
  import { createHeadlessUIContext } from "./agent-bridge/headless-ui.js";
@@ -280,6 +280,15 @@ export class AgentBridge {
280
280
  * timer flushes it once the minimum interval has elapsed.
281
281
  */
282
282
  subagentProgressThrottle = new Map();
283
+ /**
284
+ * Latest LIVE TPS snapshot per parent subagent tool call id, folded from
285
+ * the internal `subagent_tps` events the runner emits after each LLM round
286
+ * with tokens. Consumed when building throttled `subagent_progress` frames
287
+ * so they carry durationMs/tokensPerSecond/ttftMs/lastRoundTps; cleared at
288
+ * subagent completion (see flushSubagentProgress) so state never leaks into
289
+ * a later invocation.
290
+ */
291
+ subagentTpsSnapshot = new Map();
283
292
  /**
284
293
  * toolCallId → startedAt captured at `tool_execution_start` so the
285
294
  * terminal `tool_result` can carry the real start time (durations
@@ -748,6 +757,12 @@ export class AgentBridge {
748
757
  });
749
758
  this.allowedModels = allowedModels;
750
759
  this.registerSyntheticProviders(allowedModels);
760
+ const visionDefaults = allowedModels.filter((m) => m.isVisionDefault);
761
+ if (visionDefaults.length > 1) {
762
+ console.warn(`[AgentBridge] Multiple vision-default models reported by backend (${visionDefaults
763
+ .map((m) => m.modelId)
764
+ .join(", ")}); using the first one: ${visionDefaults[0].modelId}`);
765
+ }
751
766
  return allowedModels;
752
767
  }
753
768
  /**
@@ -908,6 +923,22 @@ export class AgentBridge {
908
923
  isBusy() {
909
924
  return this.isStreaming() || this.isRetrying();
910
925
  }
926
+ /**
927
+ * Stop a single in-flight tool call (user-initiated per-call stop).
928
+ * Delegates to the SDK session; returns false for unknown/finished
929
+ * toolCallIds or when the session has not started.
930
+ */
931
+ async stopToolCall(toolCallId, reason) {
932
+ if (!this.session)
933
+ return false;
934
+ try {
935
+ return await this.session.stopToolCall(toolCallId, reason);
936
+ }
937
+ catch {
938
+ // best-effort: a per-call stop must never surface as a bridge error
939
+ return false;
940
+ }
941
+ }
911
942
  getSessionBranch() {
912
943
  return (this.sessionManager?.getBranch() ?? []);
913
944
  }
@@ -1013,10 +1044,10 @@ export class AgentBridge {
1013
1044
  /**
1014
1045
  * Map a frontend reasoning-effort string to spectral's ThinkingLevel.
1015
1046
  * Frontend sends: xhigh | high | medium | low | minimal | none | undefined
1016
- * spectral expects: "high" | "medium" | "low" | "minimal" | "off"
1047
+ * spectral accepts: "off" | "minimal" | "low" | "medium" | "high" | "xhigh"
1017
1048
  *
1018
1049
  * Mapping:
1019
- * xhigh → high (spectral doesn't have xhigh, default to max)
1050
+ * xhigh → xhigh (passed through as-is)
1020
1051
  * high → high
1021
1052
  * medium → medium
1022
1053
  * low → low
@@ -1376,6 +1407,21 @@ export class AgentBridge {
1376
1407
  this.memoryPhase = "compacting";
1377
1408
  if (event.type === "compaction_end")
1378
1409
  this.memoryPhase = "idle";
1410
+ // LIVE TPS snapshots (`subagent_tps`) are internal transport between the
1411
+ // subagent extension and this bridge. Fold them into the per-toolCallId
1412
+ // progress state and keep them off the wire + out of the persisted JSONL —
1413
+ // subscribers receive the values on throttled `subagent_progress` frames
1414
+ // instead (subagent_progress contract: live, token-weighted, omitted
1415
+ // until the first round with tokens).
1416
+ if (event.type === "subagent_tps") {
1417
+ this.subagentTpsSnapshot.set(event.toolCallId, {
1418
+ durationMs: event.durationMs,
1419
+ tokensPerSecond: event.tokensPerSecond,
1420
+ ttftMs: event.ttftMs,
1421
+ lastRoundTps: event.lastRoundTps,
1422
+ });
1423
+ return;
1424
+ }
1379
1425
  // Subagent progress events flow through emitAndBuffer (not handleEvent),
1380
1426
  // so they must bump the inactivity watchdog here — otherwise a working
1381
1427
  // subagent that streams progress for >PROMPT_INACTIVITY_TIMEOUT_MS would
@@ -1437,6 +1483,10 @@ export class AgentBridge {
1437
1483
  * then drop the throttle state for that tool call.
1438
1484
  */
1439
1485
  flushSubagentProgress(toolCallId) {
1486
+ // The live TPS snapshot is torn down together with the throttle: the
1487
+ // final pending frame already carries the values it needs (attached at
1488
+ // build time), so a later invocation of the same tool call starts clean.
1489
+ this.subagentTpsSnapshot.delete(toolCallId);
1440
1490
  const slot = this.subagentProgressThrottle.get(toolCallId);
1441
1491
  if (!slot)
1442
1492
  return;
@@ -1712,6 +1762,11 @@ export class AgentBridge {
1712
1762
  const thinkingText = typeof runningResult?.thinkingText === "string"
1713
1763
  ? runningResult.thinkingText
1714
1764
  : undefined;
1765
+ // LIVE TPS snapshot folded from the runner's `subagent_tps`
1766
+ // events (subagent_progress contract). Absent until the subagent
1767
+ // completes its first LLM round with tokens; cleared at
1768
+ // subagent_end so a later invocation starts clean.
1769
+ const liveTps = this.subagentTpsSnapshot.get(ev.toolCallId);
1715
1770
  const se = {
1716
1771
  type: "subagent_progress",
1717
1772
  toolCallId: ev.toolCallId,
@@ -1746,6 +1801,7 @@ export class AgentBridge {
1746
1801
  firstMessage: typeof r.firstMessage === "string" ? r.firstMessage : undefined,
1747
1802
  }))
1748
1803
  : undefined,
1804
+ ...(liveTps ?? {}),
1749
1805
  };
1750
1806
  // Progress snapshots carry full accumulated streaming/thinking text.
1751
1807
  // Keep them live-only so per-message events_jsonl does not grow by
@@ -1822,9 +1878,47 @@ export class AgentBridge {
1822
1878
  systemPrompt: r.systemPrompt,
1823
1879
  firstMessage: r.firstMessage,
1824
1880
  attempts: r.attempts,
1825
- usage: { ...usage, creditsUsed },
1881
+ usage: {
1882
+ ...usage,
1883
+ creditsUsed,
1884
+ // Per-LLM-round timing (TPS contract): stamped in the
1885
+ // subagent runner per assistant round and token-weighted
1886
+ // across its rounds. Optional/unreliable indicators.
1887
+ ...(r.tps
1888
+ ? {
1889
+ durationMs: r.tps.durationMs,
1890
+ tokensPerSecond: r.tps.tokensPerSecond,
1891
+ ttftMs: r.tps.ttftMs,
1892
+ lastRoundTps: r.tps.lastRoundTps,
1893
+ }
1894
+ : {}),
1895
+ },
1826
1896
  };
1827
1897
  });
1898
+ // Token-weighted TPS aggregation across results (subagent_end
1899
+ // contract): Σ outputTokens / Σ durationMs over TPS-eligible
1900
+ // rounds, arithmetic-mean TTFT across rounds, and the last
1901
+ // round's TPS in results order.
1902
+ const tpsTotal = details.results.reduce((acc, r) => {
1903
+ if (!r.tps)
1904
+ return acc;
1905
+ acc.durationMsSum += r.tps.durationMs ?? 0;
1906
+ acc.outputTokens += r.tps.outputTokens;
1907
+ acc.outputDurationMs += r.tps.outputDurationMs;
1908
+ acc.ttftMsSum += r.tps.ttftMsSum;
1909
+ acc.ttftRounds += r.tps.ttftRounds;
1910
+ if (r.tps.lastRoundTps != null) {
1911
+ acc.lastRoundTps = r.tps.lastRoundTps;
1912
+ }
1913
+ return acc;
1914
+ }, {
1915
+ durationMsSum: 0,
1916
+ outputTokens: 0,
1917
+ outputDurationMs: 0,
1918
+ ttftMsSum: 0,
1919
+ ttftRounds: 0,
1920
+ lastRoundTps: null,
1921
+ });
1828
1922
  const totalUsage = results.reduce((acc, r) => ({
1829
1923
  inputTokens: acc.inputTokens + r.usage.inputTokens,
1830
1924
  outputTokens: acc.outputTokens + r.usage.outputTokens,
@@ -1842,6 +1936,14 @@ export class AgentBridge {
1842
1936
  turns: 0,
1843
1937
  creditsUsed: 0,
1844
1938
  });
1939
+ const totalTps = buildTpsUsageFields({
1940
+ durationMsSum: tpsTotal.durationMsSum,
1941
+ outputTokens: tpsTotal.outputTokens,
1942
+ outputDurationMs: tpsTotal.outputDurationMs,
1943
+ ttftMsSum: tpsTotal.ttftMsSum,
1944
+ ttftRounds: tpsTotal.ttftRounds,
1945
+ lastRoundTps: tpsTotal.lastRoundTps,
1946
+ });
1845
1947
  const se = {
1846
1948
  type: "subagent_end",
1847
1949
  toolCallId: ev.toolCallId,
@@ -1849,7 +1951,7 @@ export class AgentBridge {
1849
1951
  finishedAt: Date.now(),
1850
1952
  mode,
1851
1953
  results,
1852
- totalUsage,
1954
+ totalUsage: { ...totalUsage, ...totalTps },
1853
1955
  };
1854
1956
  this.emitAndBuffer(se);
1855
1957
  }
@@ -1860,6 +1962,7 @@ export class AgentBridge {
1860
1962
  id: ev.toolCallId,
1861
1963
  result: ev.result,
1862
1964
  isError: ev.isError,
1965
+ ...(ev.stoppedByUser ? { stoppedByUser: true } : {}),
1863
1966
  startedAt: this.toolStartedAt.get(ev.toolCallId) ?? Date.now(),
1864
1967
  finishedAt: Date.now(),
1865
1968
  });
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * List the contents of an absolute directory path.
3
3
  *
4
- * Used by the inline directory picker fallback in the browser/Electron
4
+ * Used by the inline directory picker fallback in the browser/desktop wrapper
5
5
  * when a native OS dialog cannot be opened. Returns a sorted list of
6
6
  * entries with enough metadata to render a navigable directory tree.
7
7
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * List the contents of an absolute directory path.
3
3
  *
4
- * Used by the inline directory picker fallback in the browser/Electron
4
+ * Used by the inline directory picker fallback in the browser/desktop wrapper
5
5
  * when a native OS dialog cannot be opened. Returns a sorted list of
6
6
  * entries with enough metadata to render a navigable directory tree.
7
7
  */
@@ -38,6 +38,13 @@ export interface InterAgentMessage {
38
38
  createdAt: number;
39
39
  /** Timestamp (ms) when the recipient first polled it, if ever. */
40
40
  deliveredAt?: number;
41
+ /**
42
+ * Session ids this message has been delivered to (per-recipient
43
+ * bookkeeping). Absent/empty means the message has not been delivered to
44
+ * anyone yet. `deliveredAt` stays the FIRST-delivery timestamp for
45
+ * TTL/debug purposes.
46
+ */
47
+ deliveredTo?: string[];
41
48
  /** Timestamp (ms) after which the message may be garbage collected. */
42
49
  expiresAt?: number;
43
50
  }
@@ -59,6 +66,11 @@ export interface InterAgentPollInput {
59
66
  channel?: string;
60
67
  /** Poll only messages addressed to this session (or broadcast). Omit to poll all. */
61
68
  recipientSessionId?: string;
69
+ /**
70
+ * Exclude messages sent by this session id (self-filtering). Omit to
71
+ * include the poller's own messages (legacy behavior).
72
+ */
73
+ excludeSenderSessionId?: string;
62
74
  /** Only return messages created after this timestamp (exclusive). */
63
75
  since?: number;
64
76
  /** Maximum messages to return. Default 100. */
@@ -1 +1 @@
1
- {"version":3,"file":"inter-agent-broker.d.ts","sourceRoot":"","sources":["../../src/server/inter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MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,CAAC,GAAG,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAC3C;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,YAAY,CAAC;IACpB,iFAAiF;IACjF,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;GAKG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IACrC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAE3C;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4D;gBAE9E,IAAI,EAAE,uBAAuB;IAKzC;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,mBAAmB,GAAG,iBAAiB;IAyBnD;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,mBAAmB,GAAG,iBAAiB,EAAE;IAYrD;;;OAGG;IACH,SAAS,CAAC,KAAK,EAAE,wBAAwB,GAAG,MAAM,IAAI;IA4BtD;;OAEG;IACH,OAAO,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IAQrC,OAAO,CAAC,iBAAiB;CAqB1B"}
@@ -69,6 +69,7 @@ export class InterAgentBroker {
69
69
  projectId: input.projectId,
70
70
  channel: input.channel,
71
71
  recipientSessionId: input.recipientSessionId,
72
+ excludeSenderSessionId: input.excludeSenderSessionId,
72
73
  since: input.since,
73
74
  limit: input.limit ?? 100,
74
75
  markDelivered: input.markDelivered ?? true,
@@ -0,0 +1,151 @@
1
+ /**
2
+ * "@preset:<name>" chain expansion.
3
+ *
4
+ * A queued prompt whose content starts with `@preset:<name>` references a
5
+ * backend preset. When such an item is dequeued, it expands into:
6
+ * 1. the preset's QUEUE follow-up messages, enqueued (in order, trimmed)
7
+ * BEFORE the turn starts, and
8
+ * 2. the preset's main prompt with its INJECT follow-up messages (and any
9
+ * remainder text from the reference) appended as paragraphs, which runs
10
+ * as the turn — the same composition the frontend apply-preset flow
11
+ * produces for the composer text.
12
+ *
13
+ * Because follow-ups are enqueued verbatim and each dequeued item is itself
14
+ * checked for a reference, a follow-up that is `@preset:<other>` expands at
15
+ * its own dequeue — chained presets therefore behave like programs.
16
+ *
17
+ * Safety valves:
18
+ * - `PRESET_CHAIN_BUDGET` caps expansions between non-reference prompts so
19
+ * a preset that (indirectly) references itself terminates instead of
20
+ * looping forever. Budget resets whenever a non-reference item is seen.
21
+ * - Every failure mode (resolver down, unknown preset, blank prompt)
22
+ * falls back to running the raw reference text — a queued item is never
23
+ * silently dropped.
24
+ *
25
+ * Everything here is pure/injectable so it is unit-testable without a
26
+ * backend; the only I/O helper is `resolvePresetByName`.
27
+ */
28
+ /** Expansions allowed before a raw-run fallback (reset on non-references). */
29
+ export declare const PRESET_CHAIN_BUDGET = 25;
30
+ /** Maximum follow-up messages enqueued per expansion. Mirrors the backend
31
+ * resolver cap (`MAX_FOLLOW_UP_MESSAGES`). */
32
+ export declare const MAX_PRESET_FOLLOW_UPS = 20;
33
+ /** A preset row as returned by `GET /v1/presets/resolve`. */
34
+ export interface ResolvedPreset {
35
+ id: string;
36
+ name: string;
37
+ prompt: string;
38
+ followUpMessages: unknown;
39
+ scope?: "TEAM" | "PROJECT" | null;
40
+ projectId?: string | null;
41
+ loopEnabled?: boolean | null;
42
+ maxIterations?: number | null;
43
+ goal?: string | null;
44
+ intervalMinutes?: number | null;
45
+ }
46
+ /** Why an expansion did not happen. */
47
+ export type PresetSkipReason = "not-reference" | "budget" | "unresolved";
48
+ /** Result of {@link parsePresetReference}. */
49
+ export interface PresetReference {
50
+ name: string;
51
+ remainder: string;
52
+ }
53
+ /**
54
+ * Parse a queued prompt into a preset reference, or `null` when the content
55
+ * is not a reference. `@preset:` without a name does NOT match.
56
+ */
57
+ export declare function parsePresetReference(content: string): PresetReference | null;
58
+ /**
59
+ * Resolve a preset by name through the backend machine-JWT REST route.
60
+ * Never throws: any failure (network, timeout, non-2xx, malformed body)
61
+ * resolves to `null` so callers fall back to the raw reference text.
62
+ */
63
+ export declare function resolvePresetByName(backendUrl: string, machineJwt: string, teamId: string | undefined, name: string): Promise<ResolvedPreset | null>;
64
+ /**
65
+ * A follow-up message extracted from the stored `followUpMessages` JSON,
66
+ * with its delivery mode preserved.
67
+ */
68
+ export interface PresetFollowUp {
69
+ content: string;
70
+ mode: "INJECT" | "QUEUE";
71
+ }
72
+ /**
73
+ * Extract follow-up messages from the stored `followUpMessages` JSON,
74
+ * preserving each entry's mode. Canonical entries are `{ content, mode }`
75
+ * objects; plain strings are tolerated for robustness and default to INJECT
76
+ * (matching the backend resolver and the frontend apply-preset flow, which
77
+ * only special-case QUEUE). Empty/blank entries are skipped, output is
78
+ * capped at {@link MAX_PRESET_FOLLOW_UPS}, and non-arrays yield `[]`.
79
+ */
80
+ export declare function extractFollowUpContents(raw: unknown): PresetFollowUp[];
81
+ /**
82
+ * Compose the turn prompt for an expansion: the preset prompt with the
83
+ * reference remainder appended as a separate paragraph (when non-empty).
84
+ */
85
+ export declare function composeExpandedPrompt(presetPrompt: string, remainder: string): string;
86
+ /**
87
+ * Compose the full running prompt for a preset expansion: the preset prompt,
88
+ * then its INJECT follow-up contents, then the reference remainder — all
89
+ * joined as paragraphs (identical shape to the frontend apply-preset flow's
90
+ * composer text). Blank parts are dropped.
91
+ */
92
+ export declare function composePresetRunPrompt(presetPrompt: string, injectContents: readonly string[], remainder: string): string;
93
+ /** Injectable collaborators for {@link expandIfPresetReference}. */
94
+ export interface PresetChainDeps {
95
+ parse: (content: string) => PresetReference | null;
96
+ resolve: (name: string) => Promise<ResolvedPreset | null>;
97
+ enqueue: (content: string) => void;
98
+ run: (content: string) => void;
99
+ onSkip: (reason: PresetSkipReason) => void;
100
+ }
101
+ export interface ExpandPresetReferenceInput extends PresetChainDeps {
102
+ /** The dequeued prompt content. */
103
+ content: string;
104
+ /** Expansions still allowed; defaults to {@link PRESET_CHAIN_BUDGET}. */
105
+ chainBudget?: number;
106
+ }
107
+ export interface PresetExpansionOutcome {
108
+ /** True when a preset resolved and its follow-ups were enqueued. */
109
+ expanded: boolean;
110
+ /** True when `run` was invoked (all paths except `not-reference`). */
111
+ ran: boolean;
112
+ /** Content passed to `run` (null when nothing ran). */
113
+ ranContent: string | null;
114
+ /** QUEUE follow-up contents enqueued, in order (INJECT follow-ups are
115
+ * folded into `ranContent` instead). */
116
+ enqueuedFollowUps: string[];
117
+ /** Why expansion did not happen (null on success). */
118
+ skipReason: PresetSkipReason | null;
119
+ /** Budget left after this call (unchanged on skip paths). */
120
+ budgetRemaining: number;
121
+ /** True when the caller should reset its stored budget to the default. */
122
+ budgetReset: boolean;
123
+ }
124
+ /**
125
+ * Orchestrate one dequeued item:
126
+ * - not a reference → skip signal + budget reset; nothing runs
127
+ * (the caller keeps its plain dequeue path).
128
+ * - reference, budget spent → run the raw content, skip "budget".
129
+ * - reference, resolve fails → run the raw content, skip "unresolved".
130
+ * - otherwise → enqueue each QUEUE follow-up (capped, in
131
+ * order), THEN run the composed prompt
132
+ * (`preset prompt + INJECT follow-ups +
133
+ * remainder`, paragraph-separated); spend one
134
+ * unit of budget. A preset whose follow-ups
135
+ * are all INJECT enqueues nothing.
136
+ *
137
+ * `resolve` never throws (see {@link resolvePresetByName}); errors thrown by
138
+ * the injected `enqueue`/`run` deps propagate to the caller.
139
+ */
140
+ export declare function expandIfPresetReference(input: ExpandPresetReferenceInput): Promise<PresetExpansionOutcome>;
141
+ /**
142
+ * Expand a prompt that is about to be REPLAYED (autonomous loop arming).
143
+ * Returns the input unchanged when it is not a reference or the resolver
144
+ * fails, so loop arming never blocks on or loses the original prompt. Does
145
+ * NOT touch the chain budget: expansion happens once at arming time, not on
146
+ * every iteration. INJECT follow-ups are folded into the replayed prompt
147
+ * (same composition as the queue-expansion path); QUEUE follow-ups are not
148
+ * enqueued here — loop arming only rewrites the replayed prompt.
149
+ */
150
+ export declare function expandPresetPrompt(prompt: string, resolve: (name: string) => Promise<ResolvedPreset | null>): Promise<string>;
151
+ //# sourceMappingURL=preset-chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preset-chain.d.ts","sourceRoot":"","sources":["../../src/server/preset-chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,8EAA8E;AAC9E,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC;8CAC8C;AAC9C,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAKxC,6DAA6D;AAC7D,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,OAAO,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IAClC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED,uCAAuC;AACvC,MAAM,MAAM,gBAAgB,GAAG,eAAe,GAAG,QAAQ,GAAG,YAAY,CAAC;AAEzE,8CAA8C;AAC9C,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAcD;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,GACd,eAAe,GAAG,IAAI,CAOxB;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC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