@sema-agent/client-core 0.97.0 → 0.98.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 (281) hide show
  1. package/CHANGELOG.md +429 -0
  2. package/README.md +74 -36
  3. package/dist/adapt/arms.d.ts +1 -0
  4. package/dist/adapt/arms.js +128 -34
  5. package/dist/adapt/ids.d.ts +12 -1
  6. package/dist/adapt/ids.js +59 -8
  7. package/dist/adapt/instanceLedger.d.ts +50 -0
  8. package/dist/adapt/instanceLedger.js +147 -0
  9. package/dist/adapt/textStream.d.ts +1 -0
  10. package/dist/adapt/textStream.js +24 -7
  11. package/dist/adapt/toolCards.d.ts +27 -5
  12. package/dist/adapt/toolCards.js +39 -6
  13. package/dist/adapt/wireShapes.js +6 -2
  14. package/dist/adapt.d.ts +2 -0
  15. package/dist/adapt.js +8 -3
  16. package/dist/adapter/activeRunSelfHeal.d.ts +5 -0
  17. package/dist/adapter/activeRunSelfHeal.js +51 -28
  18. package/dist/adapter/downstream/eventToSdkMessage.d.ts +2 -5
  19. package/dist/adapter/downstream/eventToSdkMessage.js +27 -34
  20. package/dist/adapter/downstream/terminalToSdkResult.js +11 -4
  21. package/dist/adapter/downstream/turnUsageToModelUsage.d.ts +5 -2
  22. package/dist/adapter/downstream/turnUsageToModelUsage.js +2 -0
  23. package/dist/adapter/runStream.js +29 -13
  24. package/dist/adapter/types.d.ts +4 -4
  25. package/dist/agentSession/backgroundView.js +2 -1
  26. package/dist/agentSession/engineAgentRegistryRead.d.ts +2 -2
  27. package/dist/agentSession/engineAgentRegistryRead.js +12 -13
  28. package/dist/agentsWireCaps.d.ts +8 -6
  29. package/dist/agentsWireCaps.js +177 -162
  30. package/dist/approvalDecidedByCapability.d.ts +0 -4
  31. package/dist/approvalDecidedByCapability.js +0 -6
  32. package/dist/approvalsStreamLiveCapability.d.ts +0 -4
  33. package/dist/approvalsStreamLiveCapability.js +0 -6
  34. package/dist/assistantInbox.d.ts +34 -0
  35. package/dist/assistantInbox.js +118 -0
  36. package/dist/centerWiringCapability.js +9 -1
  37. package/dist/clientSlice.d.ts +0 -9
  38. package/dist/clientSlice.js +0 -3
  39. package/dist/cloudConfigWireCaps.d.ts +4 -2
  40. package/dist/cloudConfigWireCaps.js +81 -61
  41. package/dist/compensations.js +1 -1
  42. package/dist/connectorStatus.d.ts +21 -0
  43. package/dist/connectorStatus.js +112 -0
  44. package/dist/controlRouter.d.ts +14 -1
  45. package/dist/controlRouter.js +68 -17
  46. package/dist/coreValuePorts.d.ts +3 -3
  47. package/dist/decideReceipt.d.ts +2 -2
  48. package/dist/decideReceipt.js +5 -2
  49. package/dist/declared/supportFloorDeclared.js +3 -3
  50. package/dist/deviceExecutorManagementCapability.d.ts +0 -4
  51. package/dist/deviceExecutorManagementCapability.js +0 -6
  52. package/dist/deviceRebind.d.ts +49 -1
  53. package/dist/deviceRebind.js +221 -3
  54. package/dist/displayUntrusted.d.ts +1 -0
  55. package/dist/displayUntrusted.js +250 -76
  56. package/dist/engineAgentAbsence.d.ts +1 -1
  57. package/dist/engineAgentPanelStore.d.ts +5 -4
  58. package/dist/engineAgentPanelStore.js +3 -12
  59. package/dist/engineCapReader.d.ts +0 -4
  60. package/dist/engineCapReader.js +1 -5
  61. package/dist/engineCapsCache.d.ts +4 -0
  62. package/dist/engineCapsCache.js +17 -12
  63. package/dist/engineClosedSets.d.ts +1 -0
  64. package/dist/engineClosedSets.js +4 -1
  65. package/dist/engineErrorCodes.d.ts +9 -2
  66. package/dist/engineErrorCodes.js +9 -1
  67. package/dist/engineIdentity.d.ts +1 -0
  68. package/dist/engineIdentity.js +8 -0
  69. package/dist/engineRowRef.d.ts +28 -0
  70. package/dist/engineRowRef.js +111 -0
  71. package/dist/engineSessionMessages.d.ts +67 -0
  72. package/dist/engineSessionMessages.js +364 -0
  73. package/dist/engineToolDirectory.d.ts +18 -0
  74. package/dist/engineToolDirectory.js +85 -0
  75. package/dist/engineUrl.d.ts +18 -0
  76. package/dist/engineUrl.js +52 -0
  77. package/dist/env/uiLanguage.d.ts +9 -0
  78. package/dist/env/uiLanguage.js +35 -0
  79. package/dist/eventLeg.d.ts +92 -0
  80. package/dist/eventLeg.js +285 -0
  81. package/dist/executionLaneCapability.d.ts +0 -4
  82. package/dist/executionLaneCapability.js +3 -16
  83. package/dist/fileHistoryCaptureCapability.d.ts +0 -4
  84. package/dist/fileHistoryCaptureCapability.js +5 -7
  85. package/dist/fleet/fleetLedger.d.ts +0 -3
  86. package/dist/fleet/fleetLedger.js +21 -36
  87. package/dist/fleet/fleetProjection.d.ts +2 -2
  88. package/dist/fleet/fleetProjection.js +10 -8
  89. package/dist/frameBinding.d.ts +5 -0
  90. package/dist/frameBinding.js +23 -0
  91. package/dist/gateFailureCodes.d.ts +2 -0
  92. package/dist/gateFailureCodes.js +15 -0
  93. package/dist/gateOutcome.d.ts +3 -1
  94. package/dist/gateOutcome.js +25 -6
  95. package/dist/gateVocabulary.d.ts +5 -0
  96. package/dist/gateVocabulary.js +64 -2
  97. package/dist/generated/engineAskFaceTables.js +2 -2
  98. package/dist/generated/engineFactTables.d.ts +6 -3
  99. package/dist/generated/engineFactTables.js +22 -4
  100. package/dist/generated/engineNoticeTables.js +9 -0
  101. package/dist/generated/toolNameTables.d.ts +1 -0
  102. package/dist/generated/toolNameTables.js +1 -0
  103. package/dist/hitl/allowRuleShadow.d.ts +6 -1
  104. package/dist/hitl/allowRuleShadow.js +21 -17
  105. package/dist/hitl/approvalCardReading.d.ts +15 -0
  106. package/dist/hitl/approvalCardReading.js +154 -0
  107. package/dist/hitl/approvalCardReasons.d.ts +13 -0
  108. package/dist/hitl/approvalCardReasons.js +120 -0
  109. package/dist/hitl/approvalHolds.d.ts +47 -15
  110. package/dist/hitl/approvalHolds.js +134 -28
  111. package/dist/hitl/approvalResolution.d.ts +51 -26
  112. package/dist/hitl/approvalResolution.js +86 -122
  113. package/dist/hitl/approvalsFeed.js +6 -18
  114. package/dist/hitl/askClassPair.d.ts +2 -0
  115. package/dist/hitl/askClassPair.js +1 -0
  116. package/dist/hitl/askGateWire.d.ts +20 -2
  117. package/dist/hitl/askGateWire.js +49 -1
  118. package/dist/hitl/askParkRowRouting.d.ts +5 -0
  119. package/dist/hitl/askParkRowRouting.js +32 -1
  120. package/dist/hitl/askSettlementLine.d.ts +18 -0
  121. package/dist/hitl/askSettlementLine.js +79 -0
  122. package/dist/hitl/automaticAnswerVerdict.d.ts +1 -1
  123. package/dist/hitl/automaticAnswerVerdict.js +21 -5
  124. package/dist/hitl/crashConverged.d.ts +11 -20
  125. package/dist/hitl/crashConverged.js +56 -0
  126. package/dist/hitl/crashConvergedNotice.d.ts +3 -1
  127. package/dist/hitl/crashConvergedNotice.js +48 -11
  128. package/dist/hitl/decisionConflict.js +3 -10
  129. package/dist/hitl/decisionRefusal.d.ts +40 -1
  130. package/dist/hitl/decisionRefusal.js +199 -42
  131. package/dist/hitl/frameRouter.d.ts +5 -2
  132. package/dist/hitl/frameRouter.js +20 -16
  133. package/dist/hitl/gateLedger.d.ts +2 -0
  134. package/dist/hitl/gateLedger.js +50 -13
  135. package/dist/hitl/hitlBridge.d.ts +1 -2
  136. package/dist/hitl/hitlBridge.js +10 -7
  137. package/dist/hitl/livePendingAsk.d.ts +3 -3
  138. package/dist/hitl/livePendingAsk.js +7 -18
  139. package/dist/hitl/parkResolver.d.ts +2 -24
  140. package/dist/hitl/parkResolver.js +61 -97
  141. package/dist/hitl/persistedRulesWire.d.ts +24 -0
  142. package/dist/hitl/persistedRulesWire.js +122 -2
  143. package/dist/hitl/planReviewWire.d.ts +26 -13
  144. package/dist/hitl/planReviewWire.js +112 -78
  145. package/dist/hitl/refusedToolNameProse.d.ts +0 -1
  146. package/dist/hitl/refusedToolNameProse.js +0 -3
  147. package/dist/hitl/replayedApproval.d.ts +4 -3
  148. package/dist/hitl/replayedApproval.js +7 -4
  149. package/dist/hitl/sessionPolicyDeliverable.js +2 -4
  150. package/dist/hitl/sessionPolicyWire.d.ts +32 -20
  151. package/dist/hitl/sessionPolicyWire.js +162 -52
  152. package/dist/hitl/standingRows.d.ts +20 -2
  153. package/dist/hitl/standingRows.js +69 -8
  154. package/dist/hitl/toolApprovalWire.d.ts +87 -152
  155. package/dist/hitl/toolApprovalWire.js +591 -380
  156. package/dist/hookMatcherVerdict.d.ts +6 -1
  157. package/dist/hookMatcherVerdict.js +14 -7
  158. package/dist/hooksWireCaps.d.ts +2 -2
  159. package/dist/hooksWireCaps.js +59 -55
  160. package/dist/i18n/messages.en.d.ts +121 -0
  161. package/dist/i18n/messages.en.js +119 -0
  162. package/dist/i18n/messages.zh.d.ts +3 -0
  163. package/dist/i18n/messages.zh.js +120 -0
  164. package/dist/i18n/translate.d.ts +25 -0
  165. package/dist/i18n/translate.js +127 -0
  166. package/dist/index.d.ts +53 -18
  167. package/dist/index.js +38 -10
  168. package/dist/inheritEnvCapability.d.ts +31 -0
  169. package/dist/inheritEnvCapability.js +104 -0
  170. package/dist/liveModelCatalog.d.ts +1 -2
  171. package/dist/liveModelCatalog.js +2 -6
  172. package/dist/liveQuestionStore.d.ts +2 -21
  173. package/dist/mcpLiveness.d.ts +2 -1
  174. package/dist/mcpProbeWire.d.ts +6 -1
  175. package/dist/mcpProbeWire.js +1 -1
  176. package/dist/mcpWireCaps.d.ts +13 -2
  177. package/dist/mcpWireCaps.js +48 -0
  178. package/dist/memoryEntriesWire.d.ts +4 -9
  179. package/dist/model/modelSupplyRules.d.ts +0 -2
  180. package/dist/model/modelSupplyRules.js +3 -12
  181. package/dist/model/modelsPolicy.d.ts +0 -5
  182. package/dist/model/modelsPolicy.js +6 -36
  183. package/dist/model/subagentModelWord.d.ts +31 -0
  184. package/dist/model/subagentModelWord.js +261 -0
  185. package/dist/notifications.d.ts +6 -0
  186. package/dist/notifications.js +71 -23
  187. package/dist/outputStyleSeatCapability.d.ts +0 -3
  188. package/dist/outputStyleSeatCapability.js +0 -3
  189. package/dist/ownKey.d.ts +15 -0
  190. package/dist/ownKey.js +60 -3
  191. package/dist/panelReduce.d.ts +15 -9
  192. package/dist/panelReduce.js +680 -549
  193. package/dist/panelStateHolder.d.ts +3 -7
  194. package/dist/panelStateHolder.js +14 -130
  195. package/dist/peerLaneCapability.d.ts +0 -4
  196. package/dist/peerLaneCapability.js +0 -6
  197. package/dist/permissionRulesWriteCapability.d.ts +0 -4
  198. package/dist/permissionRulesWriteCapability.js +0 -6
  199. package/dist/permissionWireCaps.d.ts +2 -2
  200. package/dist/permissionWireCaps.js +2 -0
  201. package/dist/permissionsAllowGrantCapability.d.ts +0 -4
  202. package/dist/permissionsAllowGrantCapability.js +0 -6
  203. package/dist/permissionsDeclaration.d.ts +0 -11
  204. package/dist/permissionsDeclaration.js +60 -53
  205. package/dist/pluginHooksWire.d.ts +1 -1
  206. package/dist/pluginHooksWire.js +3 -6
  207. package/dist/preemptWire.d.ts +44 -0
  208. package/dist/preemptWire.js +83 -0
  209. package/dist/printToolResultFrame.js +15 -4
  210. package/dist/replayBody.d.ts +3 -0
  211. package/dist/replayBody.js +14 -0
  212. package/dist/request/taskRequest.d.ts +0 -1
  213. package/dist/request/taskRequest.js +0 -3
  214. package/dist/resumeRefusalCopy.d.ts +2 -1
  215. package/dist/resumeRefusalCopy.js +38 -2
  216. package/dist/retryStatus.d.ts +8 -0
  217. package/dist/retryStatus.js +106 -1
  218. package/dist/rewindArchiveCapability.d.ts +0 -4
  219. package/dist/rewindArchiveCapability.js +2 -10
  220. package/dist/rewindArchiveReading.d.ts +0 -1
  221. package/dist/rewindArchiveReading.js +0 -3
  222. package/dist/runCancelContext.d.ts +2 -1
  223. package/dist/runCancelContext.js +4 -2
  224. package/dist/runReattachPolicy.d.ts +31 -0
  225. package/dist/runReattachPolicy.js +46 -0
  226. package/dist/runTerminal.d.ts +3 -6
  227. package/dist/runTerminal.js +8 -9
  228. package/dist/sandboxWire.d.ts +3 -1
  229. package/dist/sandboxWire.js +76 -27
  230. package/dist/scenarioWire.js +1 -1
  231. package/dist/seam.d.ts +24 -2
  232. package/dist/seam.js +15 -3
  233. package/dist/seatContract.d.ts +53 -10
  234. package/dist/seatContract.js +132 -81
  235. package/dist/sessionPolicyCapability.d.ts +0 -4
  236. package/dist/sessionPolicyCapability.js +0 -6
  237. package/dist/sessionSyncFileHistoryCapability.d.ts +0 -3
  238. package/dist/sessionSyncFileHistoryCapability.js +0 -3
  239. package/dist/skillToolListsCapability.d.ts +0 -3
  240. package/dist/skillToolListsCapability.js +0 -3
  241. package/dist/sqlEngineCapability.d.ts +0 -4
  242. package/dist/sqlEngineCapability.js +0 -6
  243. package/dist/steerPriorityCapability.d.ts +0 -3
  244. package/dist/steerPriorityCapability.js +0 -3
  245. package/dist/streamDrainingLegs.d.ts +4 -0
  246. package/dist/streamDrainingLegs.js +6 -1
  247. package/dist/subagent/engineCompactWire.d.ts +0 -1
  248. package/dist/subagent/engineCompactWire.js +7 -5
  249. package/dist/subagent/engineTaskHandleWire.js +4 -7
  250. package/dist/subagentContentStore.js +1 -11
  251. package/dist/submitReopen.d.ts +24 -0
  252. package/dist/submitReopen.js +75 -0
  253. package/dist/terminalStatuses.d.ts +3 -0
  254. package/dist/terminalStatuses.js +10 -2
  255. package/dist/toolResult.d.ts +10 -1
  256. package/dist/toolResult.js +34 -6
  257. package/dist/toolRoster.d.ts +0 -2
  258. package/dist/toolRoster.js +0 -2
  259. package/dist/turnFailurePresentation.d.ts +28 -0
  260. package/dist/turnFailurePresentation.js +205 -0
  261. package/dist/userInvokedSkillsCapability.d.ts +0 -3
  262. package/dist/userInvokedSkillsCapability.js +0 -3
  263. package/dist/webSearchBackendCapability.d.ts +0 -4
  264. package/dist/webSearchBackendCapability.js +0 -6
  265. package/dist/wireErrorTriage.js +5 -24
  266. package/dist/wireFailureShape.d.ts +62 -5
  267. package/dist/wireFailureShape.js +105 -5
  268. package/dist/wireRefusalCopy.d.ts +12 -2
  269. package/dist/wireRefusalCopy.js +50 -52
  270. package/dist/workflowsJournalCapability.d.ts +0 -4
  271. package/dist/workflowsJournalCapability.js +0 -6
  272. package/dist/writeProtectionCapability.d.ts +0 -4
  273. package/dist/writeProtectionCapability.js +0 -6
  274. package/docs/INTEGRATION-CLIENTS.md +1305 -46
  275. package/package.json +5 -4
  276. package/dist/attachmentSeatCapability.d.ts +0 -12
  277. package/dist/attachmentSeatCapability.js +0 -23
  278. package/dist/hitl/approvalOutcomeNote.d.ts +0 -10
  279. package/dist/hitl/approvalOutcomeNote.js +0 -29
  280. package/dist/sessionReadRedactionCapability.d.ts +0 -13
  281. package/dist/sessionReadRedactionCapability.js +0 -35
@@ -1,6 +1,7 @@
1
1
  import { hostLog, hostTimersFor } from '../host.js';
2
2
  import { invokeHostCallbackIsolated } from '../hostCallbackGuard.js';
3
- import { COMPACT_NOT_RUNNING, isUnavailableFaceCode } from '../engineErrorCodes.js';
3
+ import { COMPACT_NOT_RUNNING } from '../engineErrorCodes.js';
4
+ import { refusalDeliveryOf } from '../hitl/decisionRefusal.js';
4
5
  import { surfaceCompactNotRunning } from '../hitl/hitlHostSurface.js';
5
6
  import { wireFailureShapeOf, wireFailureTextsOf } from '../wireFailureShape.js';
6
7
  import { clientHasVerbs, engineWireFor, INJECTED_WIRE_SETTLE_MS, noAnswerDetailFrom, settleInjected, } from '../engineWireFor.js';
@@ -30,7 +31,6 @@ function probeManualCompactCapability(wire) {
30
31
  return;
31
32
  kickEngineCapsProbe(base, () => client.capabilities());
32
33
  }
33
- export function resetManualCompactCapability() { }
34
34
  export function __resetEngineCompactArmForTests() {
35
35
  pendingCompactKeys.clear();
36
36
  pendingCompactSinks.clear();
@@ -86,9 +86,11 @@ function compactFailureOutcomeOf(e) {
86
86
  const status = typeof shape.status === 'number' && Number.isFinite(shape.status) ? shape.status : undefined;
87
87
  const code = shape.errorCode !== undefined && shape.errorCode !== '' ? shape.errorCode : undefined;
88
88
  if (status !== undefined) {
89
- if ((status >= 400 && status < 500) || isUnavailableFaceCode(code)) {
90
- return { kind: 'refused', status, ...(code !== undefined ? { errorCode: code } : {}) };
91
- }
89
+ const d = refusalDeliveryOf(e, { route: 'compact' });
90
+ if (d.delivery === 'refused')
91
+ return { kind: 'refused', status: d.status ?? status, ...(code !== undefined ? { errorCode: code } : {}) };
92
+ if (d.delivery === 'ambiguous')
93
+ return { kind: 'failed', status: d.status ?? status, detail: wireFailureTextsOf(e).reason, unconfirmed: true };
92
94
  return { kind: 'failed', status, detail: wireFailureTextsOf(e).reason };
93
95
  }
94
96
  const noAnswer = typeof e === 'object' && e !== null ? noAnswerDetailFrom(e) : null;
@@ -2,7 +2,6 @@ import { TaskStopConflictError } from '@sema-agent/sdk';
2
2
  import { hostLog } from '../host.js';
3
3
  import { clientHasVerbs, engineWireFor, INJECTED_WIRE_SETTLE_MS, noAnswerDetailFrom, sendOnce, settleInjected } from '../engineWireFor.js';
4
4
  import { engineWireDebugEnabled } from '../engineWireTarget.js';
5
- import { engineCapTrue } from '../engineCapsCache.js';
6
5
  import { engineSessionParamFor } from '../engineSessionParam.js';
7
6
  import { resolveOwnerContext } from './engineSubagentResume.js';
8
7
  import { engineTaskHandlesCapable } from './engineRowStopGate.js';
@@ -15,7 +14,7 @@ function usableTaskStopClient(client) {
15
14
  }
16
15
  const CAPS_KEY_REQUIRED_DETAIL = 'capability evidence for taskHandles is not available under the key the host named (capsBaseUrl) — nothing sent';
17
16
  import { spoolMarkerOf } from '../toolResult.js';
18
- import { STOP_CONFLICT_CODES, STOP_NOT_LANDED, STOP_NOT_LOCAL, STOP_PARKED, STOP_PARK_ARBITER_UNREACHABLE, STOP_PARK_RESUME_WON, } from '../engineErrorCodes.js';
17
+ import { STOP_NOT_LANDED, STOP_NOT_LOCAL, STOP_PARKED, STOP_PARK_ARBITER_UNREACHABLE, STOP_PARK_RESUME_WON, } from '../engineErrorCodes.js';
19
18
  function resolveHostRun(handle) {
20
19
  const runId = resolveOwnerContext(handle).runId;
21
20
  if (!runId) {
@@ -38,7 +37,7 @@ export async function fetchEngineTaskOutput(handle, opts) {
38
37
  if (wire.kind === 'no-target' || wire.kind === 'injected-unusable')
39
38
  return null;
40
39
  if (wire.kind === 'injected') {
41
- if (!engineCapTrue(wire.capsBaseUrl, 'taskHandles')) {
40
+ if (wire.capsBaseUrl === undefined || !engineTaskHandlesCapable(owner.key, wire.capsBaseUrl)) {
42
41
  hostLog('debug', `[task-handle] output ${handle}: ${CAPS_KEY_REQUIRED_DETAIL}`);
43
42
  return null;
44
43
  }
@@ -115,9 +114,7 @@ function terminalOutputHint(output) {
115
114
  export function classifyTaskStopConflict(e) {
116
115
  const detail = e instanceof Error ? e.message : String(e);
117
116
  const raw = e?.errorCode;
118
- const code = typeof raw === 'string'
119
- ? raw
120
- : (STOP_CONFLICT_CODES.find(c => detail.includes(c)) ?? '');
117
+ const code = typeof raw === 'string' ? raw : '';
121
118
  switch (code) {
122
119
  case STOP_NOT_LOCAL:
123
120
  return { ok: false, reason: 'not_local', detail };
@@ -139,7 +136,7 @@ export async function stopEngineTask(handle, opts) {
139
136
  if (wire.kind === 'no-target' || wire.kind === 'injected-unusable')
140
137
  return { ok: false, reason: 'unavailable' };
141
138
  if (wire.kind === 'injected') {
142
- if (!engineCapTrue(wire.capsBaseUrl, 'taskHandles'))
139
+ if (wire.capsBaseUrl === undefined || !engineTaskHandlesCapable(owner.key, wire.capsBaseUrl))
143
140
  return { ok: false, reason: 'unavailable', detail: CAPS_KEY_REQUIRED_DETAIL };
144
141
  }
145
142
  else if (!engineTaskHandlesCapable(owner.key)) {
@@ -1,17 +1,7 @@
1
1
  import { DEFAULT_SESSION_KEY } from './sessionSlot.js';
2
2
  import { toolEndOutputText } from './toolResultContent.js';
3
3
  export function coerceOutput(v) {
4
- if (v === undefined || v === null)
5
- return undefined;
6
- const text = toolEndOutputText(v);
7
- if (text !== undefined)
8
- return text;
9
- try {
10
- return JSON.stringify(v);
11
- }
12
- catch {
13
- return String(v);
14
- }
4
+ return toolEndOutputText(v);
15
5
  }
16
6
  const MAX_ITEMS_PER_TASK = 200;
17
7
  const MAX_TASKS = 32;
@@ -0,0 +1,24 @@
1
+ import { type AgentClient, type AgentEvent, type TaskRequest } from '@sema-agent/sdk';
2
+ type TasksStreamOptions = Parameters<AgentClient['tasks']['stream']>[1];
3
+ export type SubmitStreamOptions = Omit<TasksStreamOptions, 'idempotencyKey'>;
4
+ export interface SubmitStreamReopenDeps {
5
+ readonly client: {
6
+ readonly tasks: {
7
+ stream(request: TaskRequest, options: TasksStreamOptions): AsyncGenerator<AgentEvent>;
8
+ };
9
+ };
10
+ readonly request: TaskRequest;
11
+ readonly options: SubmitStreamOptions;
12
+ }
13
+ export interface SubmitStreamReading {
14
+ readonly idempotencyKey: string;
15
+ readonly attempts: 0 | 1 | 2;
16
+ readonly reopened: boolean;
17
+ readonly replay: boolean;
18
+ }
19
+ export interface BoundedSubmitStream {
20
+ readonly frames: AsyncGenerator<AgentEvent>;
21
+ reading(): SubmitStreamReading;
22
+ }
23
+ export declare function submitStreamWithBoundedReopen(deps: SubmitStreamReopenDeps): BoundedSubmitStream;
24
+ export {};
@@ -0,0 +1,75 @@
1
+ import { newIdempotencyKey } from '@sema-agent/sdk';
2
+ import { transportFailureScene } from './engineWireFor.js';
3
+ import { isReplayedTerminal } from './replayBody.js';
4
+ function boundByResponse(res) {
5
+ try {
6
+ const id = res.headers.get('x-task-id');
7
+ return typeof id === 'string' && id.length > 0;
8
+ }
9
+ catch {
10
+ return true;
11
+ }
12
+ }
13
+ function callerAborted(signal) {
14
+ try {
15
+ return signal !== null && signal !== undefined && signal.aborted === true;
16
+ }
17
+ catch {
18
+ return true;
19
+ }
20
+ }
21
+ function lostConnectionWithoutAnswer(error) {
22
+ const scene = transportFailureScene(error);
23
+ return scene.status === undefined && scene.end !== 'unreadable' && scene.noAnswer === 'connection-lost';
24
+ }
25
+ export function submitStreamWithBoundedReopen(deps) {
26
+ const idempotencyKey = newIdempotencyKey();
27
+ let attempts = 0;
28
+ let replay = false;
29
+ let consumerStopped = false;
30
+ async function* run() {
31
+ for (const attempt of [1, 2]) {
32
+ attempts = attempt;
33
+ let bound = false;
34
+ try {
35
+ const source = deps.client.tasks.stream(deps.request, {
36
+ ...deps.options,
37
+ idempotencyKey,
38
+ onResponse: (res) => {
39
+ if (boundByResponse(res))
40
+ bound = true;
41
+ deps.options.onResponse?.(res);
42
+ },
43
+ });
44
+ for await (const frame of source) {
45
+ bound = true;
46
+ if (isReplayedTerminal(frame))
47
+ replay = true;
48
+ yield frame;
49
+ }
50
+ return;
51
+ }
52
+ catch (error) {
53
+ if (attempt === 2 || bound || !lostConnectionWithoutAnswer(error))
54
+ throw error;
55
+ if (consumerStopped || callerAborted(deps.options.signal))
56
+ throw error;
57
+ }
58
+ }
59
+ }
60
+ const frames = run();
61
+ const innerReturn = frames.return.bind(frames);
62
+ const innerThrow = frames.throw.bind(frames);
63
+ frames.return = (value) => {
64
+ consumerStopped = true;
65
+ return innerReturn(value);
66
+ };
67
+ frames.throw = (error) => {
68
+ consumerStopped = true;
69
+ return innerThrow(error);
70
+ };
71
+ return {
72
+ frames,
73
+ reading: () => Object.freeze({ idempotencyKey, attempts, reopened: attempts === 2, replay }),
74
+ };
75
+ }
@@ -9,6 +9,9 @@ export declare function isSdkRunTerminal(status: unknown): status is SdkRunTermi
9
9
  export declare function isSdkRunTerminalNotSuccess(status: unknown): status is Exclude<SdkRunTerminalStatus, 'completed'>;
10
10
  export declare const SDK_PARKED_RUN_STATUSES: readonly ["suspended", "needs_review"];
11
11
  export declare function isSdkRunParked(status: unknown): status is (typeof SDK_PARKED_RUN_STATUSES)[number];
12
+ export declare const SDK_RUN_LIVE_STATUSES: readonly ["running", "suspended", "needs_review"];
13
+ export type SdkRunLiveStatus = (typeof SDK_RUN_LIVE_STATUSES)[number];
14
+ export declare function isSdkRunLive(status: string): status is SdkRunLiveStatus;
12
15
  export declare function isSdkRunFrameSynthesizable(status: unknown): boolean;
13
16
  export declare const SDK_FLEET_TASK_TERMINAL_STATUSES: readonly ["completed", "failed", "killed"];
14
17
  export type SdkFleetTaskTerminalStatus = (typeof SDK_FLEET_TASK_TERMINAL_STATUSES)[number];
@@ -1,4 +1,4 @@
1
- import { CORE_TERMINAL_CAUSE_KINDS } from './generated/engineFactTables.js';
1
+ import { CORE_TERMINAL_CAUSE_KINDS, CORE_TASK_NOTIFICATION_TERMINAL_STATUSES as GENERATED_TASK_NOTIFICATION_TERMINAL_STATUSES } from './generated/engineFactTables.js';
2
2
  function memberOf(table, word) {
3
3
  return typeof word === 'string' && table.includes(word);
4
4
  }
@@ -20,6 +20,14 @@ export const SDK_PARKED_RUN_STATUSES = Object.freeze(['suspended', 'needs_review
20
20
  export function isSdkRunParked(status) {
21
21
  return memberOf(SDK_PARKED_RUN_STATUSES, status);
22
22
  }
23
+ export const SDK_RUN_LIVE_STATUSES = Object.freeze(['running', ...SDK_PARKED_RUN_STATUSES]);
24
+ const _runLiveCoversPartition = true;
25
+ const _partitionCoversRunLive = true;
26
+ void _runLiveCoversPartition;
27
+ void _partitionCoversRunLive;
28
+ export function isSdkRunLive(status) {
29
+ return memberOf(SDK_RUN_LIVE_STATUSES, status);
30
+ }
23
31
  export function isSdkRunFrameSynthesizable(status) {
24
32
  return isSdkRunTerminal(status) || isSdkRunParked(status);
25
33
  }
@@ -30,7 +38,7 @@ export function isSdkFleetTaskTerminal(status) {
30
38
  export function isSdkFleetTaskTerminalNotSuccess(status) {
31
39
  return terminalNotSuccessOf(SDK_FLEET_TASK_TERMINAL_STATUSES, status);
32
40
  }
33
- export const CORE_TASK_NOTIFICATION_TERMINAL_STATUSES = Object.freeze(['completed', 'failed', 'killed', 'cancelled']);
41
+ export const CORE_TASK_NOTIFICATION_TERMINAL_STATUSES = GENERATED_TASK_NOTIFICATION_TERMINAL_STATUSES;
34
42
  export function isCoreTaskNotificationTerminal(status) {
35
43
  return memberOf(CORE_TASK_NOTIFICATION_TERMINAL_STATUSES, status);
36
44
  }
@@ -1,5 +1,6 @@
1
1
  import type { TaskResult, TaskStats } from '@sema-agent/sdk';
2
2
  import { type ModelFallbackReason } from './engineErrorCodes.js';
3
+ import type { toolKillCauseAcrossEngineIdentity } from './engineIdentity.js';
3
4
  export declare const STRUCTURED_DETAIL_TYPES: ReadonlySet<string>;
4
5
  export declare function structuredDetailType(structured: unknown): string | undefined;
5
6
  export declare const PROTOCOL_MARKERS: {
@@ -103,7 +104,15 @@ export type ToolCardOutcomeReading = {
103
104
  readonly kind: 'unreadable';
104
105
  };
105
106
  export declare function readToolCardOutcome(record: object | null | undefined): ToolCardOutcomeReading;
106
- export declare function wireOutputToBody(toolName: string, output: unknown, isError: boolean, truncated: boolean, flatten: FlattenWireOutput, structured?: unknown, leaderLedger?: boolean): ToolResultBody;
107
+ export interface ToolResultRowFlags {
108
+ readonly collateralAbort: boolean;
109
+ readonly interruptedNeverStarted: boolean;
110
+ readonly approvalWindowExpired: boolean;
111
+ readonly denialLimitWindowExpired: boolean;
112
+ }
113
+ export declare function toolResultRowFlagsOf(row: object | null | undefined): ToolResultRowFlags;
114
+ export type ToolKillCause = NonNullable<ReturnType<typeof toolKillCauseAcrossEngineIdentity>> | 'memory_pressure';
115
+ export declare function wireOutputToBody(toolName: string, output: unknown, isError: boolean, truncated: boolean, flatten: FlattenWireOutput, structured?: unknown, leaderLedger?: boolean, killCauseOf?: () => ToolKillCause | undefined): ToolResultBody;
107
116
  export declare function structuredToToolUseResult(structured: unknown, modelText?: string, leaderLedger?: boolean): {
108
117
  toolUseResult: unknown;
109
118
  isError?: boolean;
@@ -4,7 +4,7 @@ import { parseWorkflowPollEnvelope, projectWorkflowTaskOutput } from './workflow
4
4
  import { asModelFallbackReason } from './engineErrorCodes.js';
5
5
  import { frozenSet } from './frozenSet.js';
6
6
  import { bashExitOf, bashExitReadingFailed } from './bashExitReading.js';
7
- import { readFrameTrueMark } from './ownKey.js';
7
+ import { readFrameTrueMark, readFrameTrueMarkReading } from './ownKey.js';
8
8
  import { isCoreSemaTaskTerminal } from './terminalStatuses.js';
9
9
  import { CORE_ENGINE_CARD_TYPES } from './generated/engineFactTables.js';
10
10
  export const STRUCTURED_DETAIL_TYPES = frozenSet(CORE_ENGINE_CARD_TYPES);
@@ -314,7 +314,10 @@ export function readToolCardOutcome(record) {
314
314
  const block = toolResultBlockOf(record);
315
315
  if (block === undefined)
316
316
  return { kind: 'unreadable' };
317
- if (readFrameTrueMark(record, '_sema_not_executed'))
317
+ const notExecuted = readFrameTrueMarkReading(record, '_sema_not_executed');
318
+ if (notExecuted === 'unreadable')
319
+ return { kind: 'unreadable' };
320
+ if (notExecuted === 'marked')
318
321
  return cardDegraded('not-executed');
319
322
  const markerDesc = Object.getOwnPropertyDescriptor(record, '_sema_degraded');
320
323
  if (markerDesc === undefined)
@@ -329,7 +332,31 @@ export function readToolCardOutcome(record) {
329
332
  return { kind: 'unreadable' };
330
333
  }
331
334
  }
332
- export function wireOutputToBody(toolName, output, isError, truncated, flatten, structured, leaderLedger = true) {
335
+ export function toolResultRowFlagsOf(row) {
336
+ return Object.freeze({
337
+ collateralAbort: readFrameTrueMark(row, '_sema_collateral_abort'),
338
+ interruptedNeverStarted: readFrameTrueMark(row, '_sema_interrupted_never_started'),
339
+ approvalWindowExpired: readFrameTrueMark(row, '_sema_approval_window_expired'),
340
+ denialLimitWindowExpired: readFrameTrueMark(row, '_sema_denial_limit_window_expired'),
341
+ });
342
+ }
343
+ const TOOL_KILL_TEXT = {
344
+ engine_restarted: 'Command was killed when the engine restarted (exit 137)',
345
+ memory_pressure: 'Command was killed (exit 137 — the system ran out of memory; consider lowering build parallelism e.g. make -j2)',
346
+ unknown: 'Command was killed by signal 9 (exit 137)',
347
+ };
348
+ const isToolKillCause = (v) => v === 'engine_restarted' || v === 'memory_pressure';
349
+ const killedBySignalSentence = (killCauseOf) => {
350
+ let cause;
351
+ try {
352
+ cause = killCauseOf?.();
353
+ }
354
+ catch {
355
+ cause = undefined;
356
+ }
357
+ return TOOL_KILL_TEXT[isToolKillCause(cause) ? cause : 'unknown'];
358
+ };
359
+ export function wireOutputToBody(toolName, output, isError, truncated, flatten, structured, leaderLedger = true, killCauseOf) {
333
360
  const text = flatten(output);
334
361
  const name = (toolName || '').toLowerCase();
335
362
  const sType = structuredDetailType(structured);
@@ -380,7 +407,7 @@ export function wireOutputToBody(toolName, output, isError, truncated, flatten,
380
407
  const reason = slots.stderr.length > 0 ? slots.stderr : slots.stdout;
381
408
  let body = slots.exitCode != null ? `Exit code ${slots.exitCode}\n${reason}` : reason;
382
409
  if (slots.exitCode === 137) {
383
- body += `\nCommand was killed (exit 137 — possibly out-of-memory; consider lowering build parallelism e.g. make -j2)`;
410
+ body += `\n${killedBySignalSentence(killCauseOf)}`;
384
411
  }
385
412
  if (body.trim() === '' && text.trim() !== '')
386
413
  body = text;
@@ -400,8 +427,9 @@ export function wireOutputToBody(toolName, output, isError, truncated, flatten,
400
427
  };
401
428
  }
402
429
  const stdout = truncated ? `${text}\n…(truncated)` : text;
403
- if (isError || bashExitReadingFailed(exit))
404
- return { content: stdout, isError: true };
430
+ if (isError || bashExitReadingFailed(exit)) {
431
+ return { content: exit.exitCode === 137 ? `${stdout}\n${killedBySignalSentence(killCauseOf)}` : stdout, isError: true };
432
+ }
405
433
  return { content: stdout, isError, toolUseResult: { stdout, stderr: '', interrupted: false } };
406
434
  }
407
435
  if (name === 'taskoutput' || name === 'task_output') {
@@ -12,7 +12,6 @@ export interface ToolRosterRenderHintsView {
12
12
  activity?: string;
13
13
  summaryParams?: readonly string[];
14
14
  resultCards?: readonly string[];
15
- approvalCard?: string;
16
15
  }
17
16
  export interface ToolRosterEntryView {
18
17
  name: string;
@@ -87,7 +86,6 @@ export interface ToolShim {
87
86
  family?: string;
88
87
  userFacingName?: string;
89
88
  activity?: string;
90
- approvalCard?: string;
91
89
  summaryParams?: readonly string[];
92
90
  effect?: string;
93
91
  egress?: boolean;
@@ -77,7 +77,6 @@ function readEntry(raw) {
77
77
  ...(str(hintsRaw.activity) !== undefined ? { activity: str(hintsRaw.activity) } : {}),
78
78
  ...(strArr(hintsRaw.summaryParams) !== undefined ? { summaryParams: strArr(hintsRaw.summaryParams) } : {}),
79
79
  ...(strArr(hintsRaw.resultCards) !== undefined ? { resultCards: strArr(hintsRaw.resultCards) } : {}),
80
- ...(str(hintsRaw.approvalCard) !== undefined ? { approvalCard: str(hintsRaw.approvalCard) } : {}),
81
80
  },
82
81
  }
83
82
  : {}),
@@ -208,7 +207,6 @@ export function toolShimFromRoster(entry) {
208
207
  ...(e.family !== undefined ? { family: e.family } : {}),
209
208
  ...(e.renderHints?.userFacingName !== undefined ? { userFacingName: e.renderHints.userFacingName } : {}),
210
209
  ...(e.renderHints?.activity !== undefined ? { activity: e.renderHints.activity } : {}),
211
- ...(e.renderHints?.approvalCard !== undefined ? { approvalCard: e.renderHints.approvalCard } : {}),
212
210
  ...(e.renderHints?.summaryParams !== undefined ? { summaryParams: e.renderHints.summaryParams } : {}),
213
211
  ...(e.effect !== undefined ? { effect: e.effect } : {}),
214
212
  ...(e.egress !== undefined ? { egress: e.egress } : {}),
@@ -0,0 +1,28 @@
1
+ import { type TurnWireErrorVerdict } from './wireErrorTriage.js';
2
+ export type TurnFailureCategory = 'auth' | 'billing' | 'rate_limited' | 'invalid_request' | 'capability_unavailable' | 'timeout' | 'server_error' | 'connection_lost' | 'parked' | 'internal';
3
+ export declare const TURN_FAILURE_CATEGORIES: readonly TurnFailureCategory[];
4
+ export interface TurnFailureRetry {
5
+ readonly offer: boolean;
6
+ readonly basis: 'wire' | 'category';
7
+ }
8
+ export interface TurnFailurePresentation {
9
+ readonly category: TurnFailureCategory;
10
+ readonly kind: TurnWireErrorVerdict['kind'];
11
+ readonly status?: number;
12
+ readonly errorCode?: string;
13
+ readonly detail: string;
14
+ readonly headline?: string;
15
+ readonly name?: string;
16
+ readonly retry: TurnFailureRetry;
17
+ readonly waitSec?: number;
18
+ }
19
+ export declare function turnFailurePresentation(err: {} | null | undefined, evidence?: {
20
+ readonly bound?: boolean;
21
+ readonly reopened?: boolean;
22
+ }): TurnFailurePresentation;
23
+ export type SeatTurnFailure = Pick<TurnFailurePresentation, 'category' | 'retry' | 'waitSec' | 'headline' | 'errorCode'>;
24
+ export declare function seatTurnFailureOf(err: {} | null | undefined, evidence?: {
25
+ readonly bound?: boolean;
26
+ readonly reopened?: boolean;
27
+ }): SeatTurnFailure;
28
+ export declare function readSeatTurnFailure(event: {} | null | undefined): SeatTurnFailure | undefined;
@@ -0,0 +1,205 @@
1
+ import { classifyTurnWireError, effectiveWireErrorCode, isPreStreamDrainingReject } from './wireErrorTriage.js';
2
+ import { isSseIdleError } from './sseIdleTriage.js';
3
+ import { isCodeClassifiedGateFailure } from './gateFailureCodes.js';
4
+ import { CORRUPT_ROW_ERROR_CODE, CORRUPT_SESSION_ERROR_CODE, MEMORY_CONTROL_PLANE_CORRUPT, SCENARIO_ASSIGNMENT_UNKNOWN_ERROR_CODE } from './engineErrorCodes.js';
5
+ import { toolDeclarationRefusalFromError } from './wireRefusalCopy.js';
6
+ import { THROWN_SLOT_UNREADABLE, readErrorNumber, readThrownSlot, wireFailureTextsOf } from './wireFailureShape.js';
7
+ import { provablyNotSent } from './engineWireFor.js';
8
+ const CATEGORY_TABLE = Object.freeze({
9
+ auth: true,
10
+ billing: true,
11
+ rate_limited: true,
12
+ invalid_request: true,
13
+ capability_unavailable: true,
14
+ timeout: true,
15
+ server_error: true,
16
+ connection_lost: true,
17
+ parked: true,
18
+ internal: true,
19
+ });
20
+ export const TURN_FAILURE_CATEGORIES = Object.freeze(Object.keys(CATEGORY_TABLE));
21
+ const TURN_FAILURE_HEADLINES = Object.freeze({
22
+ connection_lost_not_sent: 'The engine is unreachable — your message did not run. Check that the engine is up, then send it again.',
23
+ connection_lost: 'The connection to the engine was lost — it is not known whether your message ran. Check the run’s status, or reattach to it, before sending it again.',
24
+ timeout: 'The event stream went silent — the run may still be going on the engine. Check its status before sending again.',
25
+ parked: 'The event stream ended while the run had not reached a terminal state — the run is likely parked waiting for a decision, not crashed. Check its status and decide anything pending; the turn did not complete here.',
26
+ internal: 'This client hit an internal error — it is a bug in the client, not an engine outage, and the turn did not complete.',
27
+ });
28
+ function waitSecOf(err) {
29
+ const ms = readThrownSlot(err, 'retryAfterMs', 'data');
30
+ if (typeof ms === 'number' && Number.isFinite(ms) && ms > 0)
31
+ return Math.max(1, Math.ceil(ms / 1000));
32
+ if (typeof err === 'object' && err !== null) {
33
+ const bodySec = readErrorNumber(err, 'retryAfterSec');
34
+ if (typeof bodySec === 'number' && Number.isFinite(bodySec) && bodySec > 0)
35
+ return Math.max(1, Math.ceil(bodySec));
36
+ const detail = readThrownSlot(err, 'detail', 'data');
37
+ if (typeof detail === 'object' && detail !== null) {
38
+ const sec = readThrownSlot(detail, 'retryAfterSec', 'data');
39
+ if (typeof sec === 'number' && Number.isFinite(sec) && sec > 0)
40
+ return Math.max(1, Math.ceil(sec));
41
+ }
42
+ }
43
+ return undefined;
44
+ }
45
+ function isIdleWatchdog(err) {
46
+ try {
47
+ return isSseIdleError(err);
48
+ }
49
+ catch {
50
+ return false;
51
+ }
52
+ }
53
+ const DETERMINISTIC_SERVER_CODES = new Set([CORRUPT_SESSION_ERROR_CODE, CORRUPT_ROW_ERROR_CODE, SCENARIO_ASSIGNMENT_UNKNOWN_ERROR_CODE, MEMORY_CONTROL_PLANE_CORRUPT]);
54
+ const BROWSER_FETCH_FAILURE = /\bfailed to fetch\b|\bnetworkerror\b|\bnetwork error\b|\bload failed\b/i;
55
+ function httpShapeOf(err, verdict) {
56
+ const status = verdict.status;
57
+ const code = effectiveWireErrorCode(err) ?? verdict.errorCode;
58
+ if (verdict.sessionUnreadable === true || verdict.storedRowWhere !== undefined)
59
+ return { category: 'server_error', offer: false };
60
+ if (toolDeclarationRefusalFromError(err) !== null)
61
+ return { category: 'invalid_request', offer: false };
62
+ if (code !== undefined && DETERMINISTIC_SERVER_CODES.has(code))
63
+ return { category: 'server_error', offer: false };
64
+ if (code === 'quota_exhausted')
65
+ return { category: 'rate_limited', offer: false };
66
+ if (code === 'budget.precall' || code === 'budget.exceeded')
67
+ return { category: 'billing', offer: false };
68
+ if (code === 'draining' || verdict.leaseUnavailable === true || isPreStreamDrainingReject(err))
69
+ return { category: 'server_error', offer: true };
70
+ if (status === 501 || (code !== undefined && code.startsWith('capability.')))
71
+ return { category: 'capability_unavailable', offer: false };
72
+ if (status === 401 || status === 403)
73
+ return { category: 'auth', offer: false };
74
+ if (status === 402)
75
+ return { category: 'billing', offer: false };
76
+ if (status === 408)
77
+ return { category: 'timeout', offer: true };
78
+ if (status === 429)
79
+ return { category: 'rate_limited', offer: true };
80
+ if (status >= 500)
81
+ return { category: 'server_error', offer: true };
82
+ if (status >= 400)
83
+ return { category: 'invalid_request', offer: false };
84
+ return { category: 'internal', offer: false };
85
+ }
86
+ function connectionLostBeforeSend(err, evidence) {
87
+ if (readThrownSlot(evidence, 'bound', 'data') === true || readThrownSlot(evidence, 'reopened', 'data') === true)
88
+ return false;
89
+ return typeof err === 'object' && err !== null && provablyNotSent(err);
90
+ }
91
+ export function turnFailurePresentation(err, evidence) {
92
+ const verdict = classifyTurnWireError(err);
93
+ let shape;
94
+ let headline;
95
+ let detail;
96
+ let name;
97
+ if (verdict.kind === 'http') {
98
+ shape = httpShapeOf(err, verdict);
99
+ detail = verdict.message;
100
+ if (shape.category === 'internal')
101
+ headline = TURN_FAILURE_HEADLINES.internal;
102
+ }
103
+ else if (verdict.kind === 'stream-ended-without-terminal') {
104
+ shape = { category: 'parked', offer: false };
105
+ headline = TURN_FAILURE_HEADLINES.parked;
106
+ detail = wireFailureTextsOf(err).reason;
107
+ }
108
+ else if (verdict.kind === 'transport') {
109
+ const notSent = connectionLostBeforeSend(err, evidence);
110
+ shape = { category: 'connection_lost', offer: notSent };
111
+ headline = notSent ? TURN_FAILURE_HEADLINES.connection_lost_not_sent : TURN_FAILURE_HEADLINES.connection_lost;
112
+ detail = verdict.detail;
113
+ }
114
+ else if (isIdleWatchdog(err)) {
115
+ shape = { category: 'timeout', offer: true };
116
+ headline = TURN_FAILURE_HEADLINES.timeout;
117
+ detail = verdict.detail;
118
+ }
119
+ else if (BROWSER_FETCH_FAILURE.test(verdict.detail)) {
120
+ const notSent = connectionLostBeforeSend(err, evidence);
121
+ shape = { category: 'connection_lost', offer: notSent };
122
+ headline = notSent ? TURN_FAILURE_HEADLINES.connection_lost_not_sent : TURN_FAILURE_HEADLINES.connection_lost;
123
+ detail = verdict.detail;
124
+ }
125
+ else {
126
+ shape = { category: 'internal', offer: false };
127
+ headline = TURN_FAILURE_HEADLINES.internal;
128
+ detail = verdict.detail;
129
+ name = verdict.name;
130
+ }
131
+ const status = verdict.kind === 'http' ? verdict.status : undefined;
132
+ const errorCode = verdict.kind === 'http' ? (effectiveWireErrorCode(err) ?? verdict.errorCode) : undefined;
133
+ const wireRetriable = readThrownSlot(err, 'retriable', 'data') === true && !isCodeClassifiedGateFailure(errorCode, true);
134
+ const retry = wireRetriable && shape.category !== 'parked' ? { offer: true, basis: 'wire' } : { offer: shape.offer, basis: 'category' };
135
+ const waitSec = waitSecOf(err);
136
+ return Object.freeze({
137
+ category: shape.category,
138
+ kind: verdict.kind,
139
+ ...(status !== undefined ? { status } : {}),
140
+ ...(errorCode !== undefined ? { errorCode } : {}),
141
+ detail,
142
+ ...(headline !== undefined ? { headline } : {}),
143
+ ...(name !== undefined ? { name } : {}),
144
+ retry: Object.freeze(retry),
145
+ ...(waitSec !== undefined ? { waitSec } : {}),
146
+ });
147
+ }
148
+ export function seatTurnFailureOf(err, evidence) {
149
+ const p = turnFailurePresentation(err, evidence);
150
+ return {
151
+ category: p.category,
152
+ retry: { offer: p.retry.offer, basis: p.retry.basis },
153
+ ...(p.waitSec !== undefined ? { waitSec: p.waitSec } : {}),
154
+ ...(p.headline !== undefined ? { headline: p.headline } : {}),
155
+ ...(p.errorCode !== undefined ? { errorCode: p.errorCode } : {}),
156
+ };
157
+ }
158
+ function seatDataField(o, key) {
159
+ const v = readThrownSlot(o, key, 'data');
160
+ return v === THROWN_SLOT_UNREADABLE ? SEAT_UNREADABLE : v;
161
+ }
162
+ const SEAT_UNREADABLE = Symbol('seat-unreadable');
163
+ export function readSeatTurnFailure(event) {
164
+ try {
165
+ return seatTurnFailureShapeOf(event);
166
+ }
167
+ catch {
168
+ return undefined;
169
+ }
170
+ }
171
+ function seatTurnFailureShapeOf(event) {
172
+ if (event === null || event === undefined || typeof event !== 'object' || Array.isArray(event))
173
+ return undefined;
174
+ if (seatDataField(event, 'type') !== 'error')
175
+ return undefined;
176
+ const raw = seatDataField(event, '_sema_turnFailure');
177
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
178
+ return undefined;
179
+ const category = seatDataField(raw, 'category');
180
+ if (!TURN_FAILURE_CATEGORIES.includes(category))
181
+ return undefined;
182
+ const retry = seatDataField(raw, 'retry');
183
+ if (retry === null || typeof retry !== 'object' || Array.isArray(retry))
184
+ return undefined;
185
+ const offer = seatDataField(retry, 'offer');
186
+ const basis = seatDataField(retry, 'basis');
187
+ if (typeof offer !== 'boolean' || (basis !== 'wire' && basis !== 'category'))
188
+ return undefined;
189
+ const waitSec = seatDataField(raw, 'waitSec');
190
+ if (waitSec !== undefined && !(typeof waitSec === 'number' && Number.isInteger(waitSec) && waitSec >= 1))
191
+ return undefined;
192
+ const headline = seatDataField(raw, 'headline');
193
+ if (headline !== undefined && !(typeof headline === 'string' && headline.length > 0))
194
+ return undefined;
195
+ const errorCode = seatDataField(raw, 'errorCode');
196
+ if (errorCode !== undefined && !(typeof errorCode === 'string' && errorCode.length > 0))
197
+ return undefined;
198
+ return Object.freeze({
199
+ category: category,
200
+ retry: Object.freeze({ offer, basis }),
201
+ ...(waitSec !== undefined ? { waitSec } : {}),
202
+ ...(headline !== undefined ? { headline } : {}),
203
+ ...(errorCode !== undefined ? { errorCode } : {}),
204
+ });
205
+ }
@@ -10,9 +10,6 @@ export type UserInvokedSkillsReading = {
10
10
  kind: 'present';
11
11
  };
12
12
  export declare function projectUserInvokedSkillsCapability(caps: unknown): UserInvokedSkillsReading | undefined;
13
- export declare function noteEngineCapsForUserInvokedSkills(baseUrl: string, caps: unknown, opts?: {
14
- generation?: number;
15
- }): void;
16
13
  export declare function observedUserInvokedSkills(baseUrl?: string | undefined): UserInvokedSkillsReading;
17
14
  export declare function userInvokedSkillsAvailable(reading: UserInvokedSkillsReading): 'yes' | 'no' | 'unknown';
18
15
  export declare function userInvokedSkillsDoctorDetail(reading: UserInvokedSkillsReading): string;
@@ -20,9 +20,6 @@ const reader = createEngineCapReader({
20
20
  name: 'userInvokedSkills',
21
21
  project: projectUserInvokedSkillsCapability,
22
22
  });
23
- export function noteEngineCapsForUserInvokedSkills(baseUrl, caps, opts) {
24
- reader.note(baseUrl, caps, opts);
25
- }
26
23
  export function observedUserInvokedSkills(baseUrl = engineWireTarget()?.baseUrl) {
27
24
  return reader.observed(baseUrl);
28
25
  }
@@ -15,9 +15,5 @@ export type WebSearchBackendReading = {
15
15
  view: WebSearchBackendCapabilityView;
16
16
  };
17
17
  export declare function projectWebSearchBackendCapability(caps: unknown): WebSearchBackendReading | undefined;
18
- export declare function noteEngineCapsForWebSearchBackend(baseUrl: string, caps: unknown, opts?: {
19
- generation?: number;
20
- }): void;
21
18
  export declare function observedWebSearchBackend(baseUrl?: string | undefined): WebSearchBackendReading;
22
19
  export declare function webSearchBackendDoctorDetail(reading: WebSearchBackendReading): string;
23
- export declare function __resetWebSearchBackendReadingsForTests(): void;
@@ -29,9 +29,6 @@ const reader = createEngineCapReader({
29
29
  name: 'webSearch.backend',
30
30
  project: projectWebSearchBackendCapability,
31
31
  });
32
- export function noteEngineCapsForWebSearchBackend(baseUrl, caps, opts) {
33
- reader.note(baseUrl, caps, opts);
34
- }
35
32
  export function observedWebSearchBackend(baseUrl = engineWireTarget()?.baseUrl) {
36
33
  return reader.observed(baseUrl);
37
34
  }
@@ -56,6 +53,3 @@ export function webSearchBackendDoctorDetail(reading) {
56
53
  '(per-request overrides are not echoed here)');
57
54
  }
58
55
  }
59
- export function __resetWebSearchBackendReadingsForTests() {
60
- reader.__resetForTests();
61
- }