@sema-agent/client-core 0.97.1 → 0.99.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 (353) hide show
  1. package/CHANGELOG.md +607 -0
  2. package/README.md +96 -46
  3. package/dist/adapt/arms.d.ts +1 -0
  4. package/dist/adapt/arms.js +188 -53
  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/panelTasks.d.ts +1 -1
  10. package/dist/adapt/panelTasks.js +2 -2
  11. package/dist/adapt/textStream.d.ts +1 -0
  12. package/dist/adapt/textStream.js +24 -7
  13. package/dist/adapt/toolCards.d.ts +27 -5
  14. package/dist/adapt/toolCards.js +39 -6
  15. package/dist/adapt/wireShapes.js +6 -2
  16. package/dist/adapt.d.ts +2 -0
  17. package/dist/adapt.js +8 -3
  18. package/dist/adapter/activeRunSelfHeal.d.ts +9 -3
  19. package/dist/adapter/activeRunSelfHeal.js +205 -313
  20. package/dist/adapter/downstream/eventToSdkMessage.d.ts +2 -5
  21. package/dist/adapter/downstream/eventToSdkMessage.js +77 -36
  22. package/dist/adapter/downstream/terminalToSdkResult.js +11 -4
  23. package/dist/adapter/downstream/turnUsageToModelUsage.d.ts +5 -2
  24. package/dist/adapter/downstream/turnUsageToModelUsage.js +2 -0
  25. package/dist/adapter/runStream.js +79 -48
  26. package/dist/adapter/types.d.ts +4 -4
  27. package/dist/adapter/types.js +2 -1
  28. package/dist/agentSession/backgroundView.js +2 -1
  29. package/dist/agentSession/engineAgentRegistryRead.d.ts +2 -2
  30. package/dist/agentSession/engineAgentRegistryRead.js +12 -13
  31. package/dist/agentSession/engineSessionBackgroundStop.js +16 -8
  32. package/dist/agentsWireCaps.d.ts +8 -11
  33. package/dist/agentsWireCaps.js +196 -194
  34. package/dist/approvalDecidedByCapability.d.ts +0 -4
  35. package/dist/approvalDecidedByCapability.js +0 -6
  36. package/dist/approvalsStreamLiveCapability.d.ts +0 -4
  37. package/dist/approvalsStreamLiveCapability.js +0 -6
  38. package/dist/assistantInbox.d.ts +34 -0
  39. package/dist/assistantInbox.js +118 -0
  40. package/dist/centerWiringCapability.js +9 -1
  41. package/dist/clientSlice.d.ts +0 -9
  42. package/dist/clientSlice.js +0 -3
  43. package/dist/cloudConfigWireCaps.d.ts +5 -3
  44. package/dist/cloudConfigWireCaps.js +106 -64
  45. package/dist/compensations.js +1 -1
  46. package/dist/connectorStatus.d.ts +21 -0
  47. package/dist/connectorStatus.js +112 -0
  48. package/dist/controlRouter.d.ts +18 -3
  49. package/dist/controlRouter.js +106 -67
  50. package/dist/coreValuePorts.d.ts +29 -4
  51. package/dist/coreValuePorts.js +10 -0
  52. package/dist/corruptSessionCopy.d.ts +2 -1
  53. package/dist/corruptSessionCopy.js +3 -3
  54. package/dist/decideReceipt.d.ts +2 -2
  55. package/dist/decideReceipt.js +5 -2
  56. package/dist/declared/supportFloorDeclared.js +3 -3
  57. package/dist/detachWire.js +3 -2
  58. package/dist/deviceExecutorManagementCapability.d.ts +0 -4
  59. package/dist/deviceExecutorManagementCapability.js +0 -6
  60. package/dist/deviceRebind.d.ts +49 -1
  61. package/dist/deviceRebind.js +221 -3
  62. package/dist/devicesFace.d.ts +34 -0
  63. package/dist/devicesFace.js +90 -0
  64. package/dist/displayUntrusted.d.ts +2 -0
  65. package/dist/displayUntrusted.js +253 -76
  66. package/dist/engineAgentAbsence.d.ts +1 -1
  67. package/dist/engineAgentPanelStore.d.ts +12 -4
  68. package/dist/engineAgentPanelStore.js +16 -11
  69. package/dist/engineCapReader.d.ts +2 -5
  70. package/dist/engineCapReader.js +8 -10
  71. package/dist/engineCapsCache.d.ts +12 -0
  72. package/dist/engineCapsCache.js +76 -18
  73. package/dist/engineCapsChange.d.ts +2 -0
  74. package/dist/engineCapsChange.js +9 -0
  75. package/dist/engineClosedSets.d.ts +1 -0
  76. package/dist/engineClosedSets.js +4 -1
  77. package/dist/engineErrorCodes.d.ts +11 -3
  78. package/dist/engineErrorCodes.js +11 -8
  79. package/dist/engineIdentity.d.ts +1 -0
  80. package/dist/engineIdentity.js +8 -0
  81. package/dist/engineRowRef.d.ts +28 -0
  82. package/dist/engineRowRef.js +114 -0
  83. package/dist/engineSessionMessages.d.ts +68 -0
  84. package/dist/engineSessionMessages.js +370 -0
  85. package/dist/engineTargetSeat.d.ts +27 -0
  86. package/dist/engineTargetSeat.js +199 -0
  87. package/dist/engineToolDirectory.d.ts +0 -9
  88. package/dist/engineToolDirectory.js +1 -94
  89. package/dist/engineUrl.d.ts +18 -0
  90. package/dist/engineUrl.js +52 -0
  91. package/dist/engineWireFor.js +3 -8
  92. package/dist/env/uiLanguage.d.ts +11 -1
  93. package/dist/env/uiLanguage.js +38 -2
  94. package/dist/eventLeg.d.ts +100 -0
  95. package/dist/eventLeg.js +305 -0
  96. package/dist/executionLaneCapability.d.ts +0 -4
  97. package/dist/executionLaneCapability.js +3 -16
  98. package/dist/fileHistoryCaptureCapability.d.ts +2 -5
  99. package/dist/fileHistoryCaptureCapability.js +13 -21
  100. package/dist/fileHistoryLegNotice.d.ts +2 -1
  101. package/dist/fileHistoryLegNotice.js +3 -3
  102. package/dist/fleet/fleetLedger.d.ts +0 -3
  103. package/dist/fleet/fleetLedger.js +21 -36
  104. package/dist/fleet/fleetProjection.d.ts +2 -2
  105. package/dist/fleet/fleetProjection.js +10 -8
  106. package/dist/frameBinding.d.ts +8 -0
  107. package/dist/frameBinding.js +35 -0
  108. package/dist/gateFailureCodes.d.ts +2 -0
  109. package/dist/gateFailureCodes.js +15 -0
  110. package/dist/gateOutcome.d.ts +3 -1
  111. package/dist/gateOutcome.js +41 -8
  112. package/dist/gateVocabulary.d.ts +10 -4
  113. package/dist/gateVocabulary.js +107 -47
  114. package/dist/generated/engineAskFaceTables.js +2 -2
  115. package/dist/generated/engineFactTables.d.ts +22 -3
  116. package/dist/generated/engineFactTables.js +51 -4
  117. package/dist/generated/engineNoticeTables.js +18 -3
  118. package/dist/generated/settingsSchemaFns.d.ts +6 -0
  119. package/dist/generated/settingsSchemaFns.js +57 -0
  120. package/dist/generated/settingsSchemaHooksClassifier.d.ts +2 -0
  121. package/dist/generated/settingsSchemaHooksClassifier.js +254 -0
  122. package/dist/generated/settingsSchemaTables.d.ts +1 -0
  123. package/dist/generated/settingsSchemaTables.js +4 -0
  124. package/dist/generated/settingsSchemaTypes.d.ts +105 -0
  125. package/dist/generated/settingsSchemaTypes.js +1 -0
  126. package/dist/generated/toolNameTables.d.ts +1 -0
  127. package/dist/generated/toolNameTables.js +1 -0
  128. package/dist/hitl/allowRuleShadow.d.ts +8 -2
  129. package/dist/hitl/allowRuleShadow.js +36 -29
  130. package/dist/hitl/approvalCardReading.d.ts +15 -0
  131. package/dist/hitl/approvalCardReading.js +154 -0
  132. package/dist/hitl/approvalCardReasons.d.ts +14 -0
  133. package/dist/hitl/approvalCardReasons.js +119 -0
  134. package/dist/hitl/approvalHolds.d.ts +50 -15
  135. package/dist/hitl/approvalHolds.js +177 -27
  136. package/dist/hitl/approvalResolution.d.ts +51 -26
  137. package/dist/hitl/approvalResolution.js +86 -122
  138. package/dist/hitl/approvalsFeed.js +6 -18
  139. package/dist/hitl/askClassPair.d.ts +2 -0
  140. package/dist/hitl/askClassPair.js +17 -0
  141. package/dist/hitl/askGateWire.d.ts +20 -2
  142. package/dist/hitl/askGateWire.js +50 -1
  143. package/dist/hitl/askParkRowRouting.d.ts +5 -0
  144. package/dist/hitl/askParkRowRouting.js +32 -1
  145. package/dist/hitl/askSettlementLine.d.ts +28 -0
  146. package/dist/hitl/askSettlementLine.js +99 -0
  147. package/dist/hitl/automaticAnswerVerdict.d.ts +3 -2
  148. package/dist/hitl/automaticAnswerVerdict.js +29 -13
  149. package/dist/hitl/crashConverged.d.ts +11 -20
  150. package/dist/hitl/crashConverged.js +56 -0
  151. package/dist/hitl/crashConvergedNotice.d.ts +6 -3
  152. package/dist/hitl/crashConvergedNotice.js +48 -24
  153. package/dist/hitl/decisionConflict.js +3 -10
  154. package/dist/hitl/decisionRefusal.d.ts +40 -1
  155. package/dist/hitl/decisionRefusal.js +199 -42
  156. package/dist/hitl/frameRouter.d.ts +5 -2
  157. package/dist/hitl/frameRouter.js +27 -24
  158. package/dist/hitl/gateLedger.d.ts +2 -0
  159. package/dist/hitl/gateLedger.js +50 -13
  160. package/dist/hitl/hitlBridge.d.ts +2 -2
  161. package/dist/hitl/hitlBridge.js +13 -10
  162. package/dist/hitl/livePendingAsk.d.ts +3 -3
  163. package/dist/hitl/livePendingAsk.js +7 -18
  164. package/dist/hitl/parkResolver.d.ts +2 -24
  165. package/dist/hitl/parkResolver.js +61 -97
  166. package/dist/hitl/persistedRulesWire.d.ts +25 -0
  167. package/dist/hitl/persistedRulesWire.js +104 -2
  168. package/dist/hitl/planReviewWire.d.ts +31 -13
  169. package/dist/hitl/planReviewWire.js +120 -78
  170. package/dist/hitl/refusedToolNameProse.d.ts +0 -1
  171. package/dist/hitl/refusedToolNameProse.js +0 -3
  172. package/dist/hitl/replayedApproval.d.ts +4 -3
  173. package/dist/hitl/replayedApproval.js +7 -4
  174. package/dist/hitl/sessionPolicyDeliverable.d.ts +2 -0
  175. package/dist/hitl/sessionPolicyDeliverable.js +48 -7
  176. package/dist/hitl/sessionPolicyWire.d.ts +34 -21
  177. package/dist/hitl/sessionPolicyWire.js +179 -70
  178. package/dist/hitl/standingRows.d.ts +20 -2
  179. package/dist/hitl/standingRows.js +69 -8
  180. package/dist/hitl/suspendedReopen.d.ts +2 -1
  181. package/dist/hitl/suspendedReopen.js +7 -10
  182. package/dist/hitl/toolApprovalWire.d.ts +103 -156
  183. package/dist/hitl/toolApprovalWire.js +661 -411
  184. package/dist/hookMatcherVerdict.d.ts +6 -1
  185. package/dist/hookMatcherVerdict.js +14 -7
  186. package/dist/hooksWireCaps.d.ts +2 -2
  187. package/dist/hooksWireCaps.js +174 -81
  188. package/dist/host.d.ts +21 -0
  189. package/dist/hostTurnSettings.d.ts +71 -0
  190. package/dist/hostTurnSettings.js +291 -0
  191. package/dist/humanTurn.d.ts +14 -1
  192. package/dist/humanTurn.js +100 -12
  193. package/dist/humanTurnRead.d.ts +2 -0
  194. package/dist/humanTurnRead.js +22 -1
  195. package/dist/i18n/messages.en.d.ts +703 -0
  196. package/dist/i18n/messages.en.js +701 -0
  197. package/dist/i18n/messages.zh.d.ts +3 -0
  198. package/dist/i18n/messages.zh.js +837 -0
  199. package/dist/i18n/translate.d.ts +25 -0
  200. package/dist/i18n/translate.js +127 -0
  201. package/dist/index.d.ts +78 -29
  202. package/dist/index.js +54 -18
  203. package/dist/inheritEnvCapability.d.ts +32 -0
  204. package/dist/inheritEnvCapability.js +104 -0
  205. package/dist/inheritEnvWire.d.ts +3 -2
  206. package/dist/inheritEnvWire.js +12 -14
  207. package/dist/interactiveHalt.js +17 -6
  208. package/dist/liveModelCatalog.d.ts +3 -3
  209. package/dist/liveModelCatalog.js +15 -13
  210. package/dist/liveQuestionStore.d.ts +2 -21
  211. package/dist/mcpLiveness.d.ts +2 -1
  212. package/dist/mcpPanel.d.ts +10 -1
  213. package/dist/mcpPanel.js +40 -13
  214. package/dist/mcpProbeCapability.d.ts +2 -1
  215. package/dist/mcpProbeCapability.js +7 -11
  216. package/dist/mcpProbeWire.d.ts +9 -2
  217. package/dist/mcpProbeWire.js +6 -1
  218. package/dist/mcpWireCaps.d.ts +47 -2
  219. package/dist/mcpWireCaps.js +164 -16
  220. package/dist/memoryEntriesWire.d.ts +4 -9
  221. package/dist/memoryEntriesWire.js +5 -10
  222. package/dist/model/modelSupplyRules.d.ts +0 -2
  223. package/dist/model/modelSupplyRules.js +3 -12
  224. package/dist/model/modelsPolicy.d.ts +0 -5
  225. package/dist/model/modelsPolicy.js +6 -36
  226. package/dist/model/onboardJudgement.d.ts +93 -0
  227. package/dist/model/onboardJudgement.js +415 -0
  228. package/dist/model/subagentModelWord.d.ts +31 -0
  229. package/dist/model/subagentModelWord.js +261 -0
  230. package/dist/model/tierVocabulary.d.ts +2 -0
  231. package/dist/model/tierVocabulary.js +17 -5
  232. package/dist/modelCapabilityProbe.d.ts +64 -0
  233. package/dist/modelCapabilityProbe.js +600 -0
  234. package/dist/modelIdentityResolvability.d.ts +3 -0
  235. package/dist/modelIdentityResolvability.js +26 -17
  236. package/dist/notifications.d.ts +6 -0
  237. package/dist/notifications.js +71 -23
  238. package/dist/outputStyleSeatCapability.d.ts +0 -3
  239. package/dist/outputStyleSeatCapability.js +0 -3
  240. package/dist/ownKey.d.ts +22 -0
  241. package/dist/ownKey.js +94 -3
  242. package/dist/panelReduce.d.ts +21 -10
  243. package/dist/panelReduce.js +728 -550
  244. package/dist/panelStateHolder.d.ts +3 -7
  245. package/dist/panelStateHolder.js +14 -130
  246. package/dist/peerLaneCapability.d.ts +0 -4
  247. package/dist/peerLaneCapability.js +0 -6
  248. package/dist/permissionRuleIssue.js +2 -0
  249. package/dist/permissionRulesWriteCapability.d.ts +2 -5
  250. package/dist/permissionRulesWriteCapability.js +8 -12
  251. package/dist/permissionWireCaps.d.ts +2 -2
  252. package/dist/permissionWireCaps.js +2 -0
  253. package/dist/permissionsAllowGrantCapability.d.ts +0 -4
  254. package/dist/permissionsAllowGrantCapability.js +0 -6
  255. package/dist/permissionsDeclaration.d.ts +0 -11
  256. package/dist/permissionsDeclaration.js +60 -53
  257. package/dist/pluginHooksWire.d.ts +46 -3
  258. package/dist/pluginHooksWire.js +219 -16
  259. package/dist/preemptWire.d.ts +44 -0
  260. package/dist/preemptWire.js +83 -0
  261. package/dist/printModelStatus.d.ts +63 -0
  262. package/dist/printModelStatus.js +155 -0
  263. package/dist/printToolResultFrame.js +15 -4
  264. package/dist/replayBody.d.ts +3 -0
  265. package/dist/replayBody.js +14 -0
  266. package/dist/request/taskRequest.d.ts +11 -6
  267. package/dist/request/taskRequest.js +112 -19
  268. package/dist/resumeRefusalCopy.d.ts +13 -9
  269. package/dist/resumeRefusalCopy.js +81 -118
  270. package/dist/retryStatus.d.ts +45 -0
  271. package/dist/retryStatus.js +185 -1
  272. package/dist/rewindArchiveCapability.d.ts +0 -4
  273. package/dist/rewindArchiveCapability.js +2 -10
  274. package/dist/rewindArchiveReading.d.ts +0 -1
  275. package/dist/rewindArchiveReading.js +0 -3
  276. package/dist/runCancelContext.d.ts +2 -1
  277. package/dist/runCancelContext.js +4 -2
  278. package/dist/runReattachPolicy.d.ts +31 -0
  279. package/dist/runReattachPolicy.js +46 -0
  280. package/dist/runTerminal.d.ts +3 -6
  281. package/dist/runTerminal.js +8 -9
  282. package/dist/sandboxWire.d.ts +3 -1
  283. package/dist/sandboxWire.js +76 -27
  284. package/dist/scenarioRefusal.d.ts +9 -0
  285. package/dist/scenarioRefusal.js +111 -0
  286. package/dist/scenarioWire.js +1 -1
  287. package/dist/seam.d.ts +48 -2
  288. package/dist/seam.js +25 -4
  289. package/dist/seatContract.d.ts +311 -18
  290. package/dist/seatContract.js +824 -100
  291. package/dist/selfOrchestrationDenial.js +7 -19
  292. package/dist/sessionIdSegment.d.ts +6 -0
  293. package/dist/sessionIdSegment.js +24 -0
  294. package/dist/sessionMemoryStatus.js +6 -11
  295. package/dist/sessionPolicyCapability.d.ts +2 -5
  296. package/dist/sessionPolicyCapability.js +8 -12
  297. package/dist/sessionSyncFileHistoryCapability.d.ts +0 -3
  298. package/dist/sessionSyncFileHistoryCapability.js +0 -3
  299. package/dist/settingsHooksSalvage.d.ts +44 -0
  300. package/dist/settingsHooksSalvage.js +211 -0
  301. package/dist/skillToolListsCapability.d.ts +2 -4
  302. package/dist/skillToolListsCapability.js +8 -9
  303. package/dist/sqlEngineCapability.d.ts +0 -4
  304. package/dist/sqlEngineCapability.js +0 -6
  305. package/dist/sseIdleTriage.js +3 -2
  306. package/dist/steerPriorityCapability.d.ts +0 -3
  307. package/dist/steerPriorityCapability.js +0 -3
  308. package/dist/streamDrainingLegs.d.ts +4 -0
  309. package/dist/streamDrainingLegs.js +6 -1
  310. package/dist/subagent/engineCompactWire.d.ts +0 -1
  311. package/dist/subagent/engineCompactWire.js +7 -5
  312. package/dist/subagent/engineSubagentResume.js +15 -9
  313. package/dist/subagent/engineTaskHandleWire.js +4 -7
  314. package/dist/subagentContentStore.d.ts +3 -0
  315. package/dist/subagentContentStore.js +22 -10
  316. package/dist/submitReopen.d.ts +24 -0
  317. package/dist/submitReopen.js +75 -0
  318. package/dist/terminalStatuses.d.ts +3 -0
  319. package/dist/terminalStatuses.js +10 -2
  320. package/dist/toolHistoryMismatch.js +3 -2
  321. package/dist/toolResult.d.ts +10 -1
  322. package/dist/toolResult.js +34 -6
  323. package/dist/toolRoster.d.ts +3 -4
  324. package/dist/toolRoster.js +21 -22
  325. package/dist/turnFailurePresentation.d.ts +39 -0
  326. package/dist/turnFailurePresentation.js +402 -0
  327. package/dist/usageAnalytics.js +6 -11
  328. package/dist/userAttachmentEnvelope.d.ts +1 -0
  329. package/dist/userAttachmentEnvelope.js +37 -7
  330. package/dist/userAttachmentSeat.d.ts +21 -0
  331. package/dist/userAttachmentSeat.js +75 -0
  332. package/dist/userInvokedSkillsCapability.d.ts +11 -4
  333. package/dist/userInvokedSkillsCapability.js +31 -10
  334. package/dist/webSearchBackendCapability.d.ts +0 -4
  335. package/dist/webSearchBackendCapability.js +0 -6
  336. package/dist/wireErrorTriage.d.ts +7 -0
  337. package/dist/wireErrorTriage.js +26 -23
  338. package/dist/wireFailureShape.d.ts +62 -5
  339. package/dist/wireFailureShape.js +106 -5
  340. package/dist/wireRefusalCopy.d.ts +25 -3
  341. package/dist/wireRefusalCopy.js +74 -80
  342. package/dist/workflowsJournalCapability.d.ts +2 -5
  343. package/dist/workflowsJournalCapability.js +8 -12
  344. package/dist/writeProtectionCapability.d.ts +0 -4
  345. package/dist/writeProtectionCapability.js +0 -6
  346. package/docs/INTEGRATION-CLIENTS.md +1775 -56
  347. package/package.json +6 -5
  348. package/dist/attachmentSeatCapability.d.ts +0 -12
  349. package/dist/attachmentSeatCapability.js +0 -23
  350. package/dist/hitl/approvalOutcomeNote.d.ts +0 -10
  351. package/dist/hitl/approvalOutcomeNote.js +0 -29
  352. package/dist/sessionReadRedactionCapability.d.ts +0 -13
  353. package/dist/sessionReadRedactionCapability.js +0 -35
@@ -1,15 +1,18 @@
1
- import type { ApprovalHolderIdentity, FsApprovalOutcome, ToolApprovalFrameOutcome } from './toolApprovalWire.js';
1
+ import type { ApprovalHolderIdentity } from './toolApprovalWire.js';
2
+ import type { ApprovalResolution, ApprovalResolutionLane } from './approvalResolution.js';
2
3
  export declare const APPROVAL_SETTLED_HOWS: readonly ["answered", "interrupted", "closed_by_engine"];
3
4
  export type ApprovalSettledHow = (typeof APPROVAL_SETTLED_HOWS)[number];
4
5
  export declare const SETTLED_APPROVALS_MAX_ENTRIES = 4096;
5
6
  export interface SettledApprovalEntry {
6
7
  readonly how: ApprovalSettledHow;
7
8
  readonly parked: boolean;
8
- readonly outcome: ToolApprovalFrameOutcome;
9
+ readonly outcome: ApprovalResolution;
9
10
  }
10
11
  export interface DurableDecisionHold {
11
12
  readonly lane: 'durable';
12
- readonly outcome: Promise<FsApprovalOutcome>;
13
+ readonly identity: HoldIdentity;
14
+ phase: 'card' | 'respond';
15
+ readonly outcome: Promise<ApprovalResolution>;
13
16
  presented: boolean;
14
17
  readonly interrupt: () => void;
15
18
  readonly cardSignal: AbortSignal;
@@ -18,7 +21,7 @@ export interface DurableDecisionHold {
18
21
  export interface LiveCardHold {
19
22
  readonly lane: 'live';
20
23
  readonly identity: LiveCardIdentity;
21
- readonly outcome: Promise<ToolApprovalFrameOutcome>;
24
+ readonly outcome: Promise<ApprovalResolution>;
22
25
  phase: 'card' | 'respond';
23
26
  superseded?: {
24
27
  readonly parked: boolean;
@@ -27,17 +30,47 @@ export interface LiveCardHold {
27
30
  readonly interrupt: () => void;
28
31
  trailing?: Promise<boolean>;
29
32
  }
30
- export type ApprovalHold = DurableDecisionHold | LiveCardHold;
31
- export interface LiveCardIdentity {
33
+ export interface HostCardHold {
34
+ readonly lane: 'host';
35
+ readonly identity: HoldIdentity;
36
+ phase: 'card' | 'respond';
37
+ readonly released: Promise<'answered' | 'interrupted' | undefined>;
38
+ }
39
+ export type ApprovalHold = DurableDecisionHold | LiveCardHold | HostCardHold;
40
+ export interface LiveCardIdentity extends HoldIdentity {
32
41
  readonly approvalId: string;
33
- readonly toolCallId?: string;
34
- readonly taskId?: string;
35
- readonly sessionId?: string;
36
42
  }
37
- export declare function liveCardHoldFor(who: ApprovalHolderIdentity): LiveCardHold | undefined;
43
+ export interface HoldIdentity extends ApprovalHolderIdentity {
44
+ readonly askSig?: string;
45
+ }
46
+ export declare function approvalHoldFor(who: HoldIdentity, except?: (h: ApprovalHold) => boolean): ApprovalHold | undefined;
38
47
  export declare function settledForDurableLane(entry: SettledApprovalEntry | undefined): boolean;
39
- export declare function liveCardAnsweredHow(o: ToolApprovalFrameOutcome): 'answered' | 'interrupted' | undefined;
40
- export declare function awaitLiveCardHolder(hold: LiveCardHold, signal: AbortSignal | undefined): Promise<ToolApprovalFrameOutcome | undefined>;
48
+ export declare function liveCardAnsweredHow(r: ApprovalResolution): 'answered' | 'interrupted' | undefined;
49
+ export type ApprovalHolderWait = {
50
+ readonly kind: 'settled';
51
+ readonly how: 'answered' | 'interrupted';
52
+ readonly outcome: ApprovalResolution;
53
+ } | {
54
+ readonly kind: 'free';
55
+ } | {
56
+ readonly kind: 'left';
57
+ };
58
+ export declare function awaitApprovalHolder(hold: ApprovalHold, signal: AbortSignal | undefined, asker: ApprovalResolutionLane): Promise<ApprovalHolderWait>;
59
+ export interface HostApprovalCardHold {
60
+ readonly identity: ApprovalHolderIdentity;
61
+ sending(): void;
62
+ release(settled?: 'answered' | 'interrupted'): void;
63
+ }
64
+ export type ApprovalCardClaim = {
65
+ readonly kind: 'held';
66
+ readonly hold: HostApprovalCardHold;
67
+ } | {
68
+ readonly kind: 'joined';
69
+ readonly outcome: ApprovalResolution;
70
+ } | {
71
+ readonly kind: 'aborted';
72
+ };
73
+ export declare function claimApprovalCardFor(who: HoldIdentity, signal: AbortSignal | undefined): Promise<ApprovalCardClaim>;
41
74
  export interface ApprovalDecisionHoldTable {
42
75
  readonly inFlight: Map<string, ApprovalHold>;
43
76
  readonly settled: Map<string, DurableSettledHold>;
@@ -54,8 +87,10 @@ export declare function settledApprovalOf(approvalId: string | undefined): Settl
54
87
  export declare function clearSettledApprovals(): void;
55
88
  export declare function anyApprovalSettled(): boolean;
56
89
  export declare function noteEngineClosedApproval(approvalId: string, parked: boolean): void;
57
- export declare function settledLiveCardOutcome(approvalId: string): ToolApprovalFrameOutcome | undefined;
90
+ export declare function settleEngineClosedApproval(frame: object, parked: boolean): boolean;
91
+ export declare function noteHolderSettledApproval(approvalId: string, how: 'answered' | 'interrupted', outcome: ApprovalResolution): void;
92
+ export declare function settledLiveCardOutcome(approvalId: string): ApprovalResolution | undefined;
58
93
  export declare function liveCardHoldOf(key: string): LiveCardHold | undefined;
59
- export declare function holdLiveCard(identity: LiveCardIdentity, callerSignal: AbortSignal | undefined, present: (hold: LiveCardHold) => Promise<ToolApprovalFrameOutcome>): Promise<ToolApprovalFrameOutcome>;
60
- export declare function joinLiveCard(hold: LiveCardHold, signal: AbortSignal | undefined): Promise<ToolApprovalFrameOutcome>;
94
+ export declare function holdLiveCard(identity: LiveCardIdentity, callerSignal: AbortSignal | undefined, present: (hold: LiveCardHold) => Promise<ApprovalResolution>): Promise<ApprovalResolution>;
95
+ export declare function joinLiveCard(hold: LiveCardHold, signal: AbortSignal | undefined): Promise<ApprovalResolution>;
61
96
  export declare function supersedeLiveCard(key: string, parked: boolean): boolean;
@@ -1,51 +1,179 @@
1
1
  import { hostLog } from '../host.js';
2
2
  import { liveFrameCallKey } from './gateIdentity.js';
3
- import { approvalResolutionOf } from './approvalResolution.js';
3
+ import { decideReceiptReopen, readDecideReceipt } from '../decideReceipt.js';
4
4
  export const APPROVAL_SETTLED_HOWS = Object.freeze(['answered', 'interrupted', 'closed_by_engine']);
5
5
  export const SETTLED_APPROVALS_MAX_ENTRIES = 4096;
6
6
  const nonEmpty = (v) => typeof v === 'string' && v !== '';
7
- export function liveCardHoldFor(who) {
8
- if (nonEmpty(who.approvalId))
9
- return liveCardHoldOf(liveFrameCallKey(who.approvalId));
10
- if (!nonEmpty(who.taskId) || !nonEmpty(who.toolCallId))
11
- return undefined;
7
+ function sameApproval(who, h) {
8
+ const id = h.identity;
9
+ if (nonEmpty(who.approvalId) && nonEmpty(id.approvalId))
10
+ return who.approvalId === id.approvalId;
11
+ if (h.phase !== 'card')
12
+ return false;
13
+ if (!nonEmpty(who.taskId) || !nonEmpty(who.toolCallId) || id.taskId !== who.taskId || id.toolCallId !== who.toolCallId)
14
+ return false;
15
+ if (nonEmpty(who.sessionId) && nonEmpty(id.sessionId) && id.sessionId !== who.sessionId)
16
+ return false;
17
+ return !(nonEmpty(who.askSig) && nonEmpty(id.askSig) && id.askSig !== who.askSig);
18
+ }
19
+ export function approvalHoldFor(who, except) {
12
20
  for (const h of approvalDecisionHolds.inFlight.values()) {
13
- if (h.lane !== 'live' || h.phase !== 'card')
21
+ if (except?.(h) === true)
14
22
  continue;
15
- const id = h.identity;
16
- if (id.taskId !== who.taskId || id.toolCallId !== who.toolCallId)
17
- continue;
18
- if (nonEmpty(who.sessionId) && nonEmpty(id.sessionId) && id.sessionId !== who.sessionId)
19
- continue;
20
- return h;
23
+ if (sameApproval(who, h))
24
+ return h;
21
25
  }
22
26
  return undefined;
23
27
  }
24
28
  export function settledForDurableLane(entry) {
25
29
  return entry !== undefined && !entry.parked;
26
30
  }
27
- export function liveCardAnsweredHow(o) {
28
- return answeredHowOf(approvalResolutionOf(o));
29
- }
30
- function answeredHowOf(r) {
31
+ export function liveCardAnsweredHow(r) {
31
32
  if (r.kind === 'decided')
32
33
  return 'answered';
33
34
  return r.kind === 'unsettled' && r.cause === 'interrupted' ? 'interrupted' : undefined;
34
35
  }
35
- export async function awaitLiveCardHolder(hold, signal) {
36
+ const HOLDER_FREE = Object.freeze({ kind: 'free' });
37
+ function nothingSentHere(asker) {
38
+ return Object.freeze({ kind: 'not_sent', lane: asker, cause: 'retracted' });
39
+ }
40
+ function interruptedThere(asker) {
41
+ return Object.freeze({ kind: 'unsettled', lane: asker, cause: 'interrupted' });
42
+ }
43
+ export async function awaitApprovalHolder(hold, signal, asker) {
44
+ if (hold.lane === 'host')
45
+ return awaitHostHolder(hold, signal, asker);
36
46
  const unsubscribe = followCallerSignal(signal, hold.interrupt);
37
- let o;
38
47
  try {
39
- o = await hold.outcome;
48
+ if (hold.lane === 'live') {
49
+ let o;
50
+ try {
51
+ o = await hold.outcome;
52
+ }
53
+ catch {
54
+ return HOLDER_FREE;
55
+ }
56
+ const stillHeld = approvalDecisionHolds.inFlight.get(liveFrameCallKey(hold.identity.approvalId)) === hold;
57
+ const entry = settledApprovalOf(hold.identity.approvalId);
58
+ if (!stillHeld && !settledForDurableLane(entry))
59
+ return HOLDER_FREE;
60
+ return Object.freeze({ kind: 'settled', how: entry?.how === 'answered' ? 'answered' : 'interrupted', outcome: o });
61
+ }
62
+ let r;
63
+ try {
64
+ r = await hold.outcome;
65
+ }
66
+ catch {
67
+ return HOLDER_FREE;
68
+ }
69
+ if (r.kind === 'decided') {
70
+ if (decideReceiptReopen(r.receipt) !== null)
71
+ return HOLDER_FREE;
72
+ return Object.freeze({ kind: 'settled', how: 'answered', outcome: r });
73
+ }
74
+ if (r.kind !== 'unsettled' || r.cause !== 'interrupted' || hold.trailing === undefined)
75
+ return HOLDER_FREE;
76
+ const landed = await hold.trailing.then((raw) => decideReceiptReopen(readDecideReceipt(raw)) === null, () => false);
77
+ return landed ? Object.freeze({ kind: 'settled', how: 'interrupted', outcome: r }) : HOLDER_FREE;
78
+ }
79
+ finally {
80
+ unsubscribe();
81
+ }
82
+ }
83
+ async function awaitHostHolder(hold, signal, asker) {
84
+ let leave = () => { };
85
+ const left = new Promise((resolve) => {
86
+ leave = () => resolve('left');
87
+ });
88
+ const unsubscribe = followCallerSignal(signal, leave);
89
+ try {
90
+ const r = await Promise.race([hold.released, left]);
91
+ if (r === 'left')
92
+ return Object.freeze({ kind: 'left' });
93
+ if (r === undefined)
94
+ return HOLDER_FREE;
95
+ return Object.freeze({ kind: 'settled', how: r, outcome: r === 'interrupted' ? interruptedThere(asker) : nothingSentHere(asker) });
96
+ }
97
+ finally {
98
+ unsubscribe();
99
+ }
100
+ }
101
+ function holdHostCard(identity, signal) {
102
+ const h = approvalDecisionHolds;
103
+ const key = `hitl-host:${++h.clock}`;
104
+ let resolveReleased = () => { };
105
+ const released = new Promise((resolve) => {
106
+ resolveReleased = resolve;
107
+ });
108
+ const frozen = Object.freeze({ ...identity });
109
+ const hold = { lane: 'host', identity: frozen, phase: 'card', released };
110
+ h.inFlight.set(key, hold);
111
+ let done = false;
112
+ let stopFollowing = () => { };
113
+ const release = (settled) => {
114
+ if (done)
115
+ return;
116
+ done = true;
117
+ stopFollowing();
118
+ const how = settled === 'answered' || settled === 'interrupted' ? settled : undefined;
119
+ if (how !== undefined && nonEmpty(frozen.approvalId))
120
+ noteSettled(frozen.approvalId, how, false, how === 'interrupted' ? interruptedThere('decide') : nothingSentHere('decide'), true);
121
+ if (h.inFlight.get(key) === hold)
122
+ h.inFlight.delete(key);
123
+ resolveReleased(how);
124
+ };
125
+ const handle = Object.freeze({
126
+ identity: frozen,
127
+ sending: () => {
128
+ if (done)
129
+ return;
130
+ hold.phase = 'respond';
131
+ stopFollowing();
132
+ },
133
+ release,
134
+ });
135
+ stopFollowing = followCallerSignal(signal, () => {
136
+ if (!done && hold.phase === 'card')
137
+ release();
138
+ });
139
+ return handle;
140
+ }
141
+ function callerSignalAborted(signal) {
142
+ if (signal === undefined || signal === null)
143
+ return false;
144
+ try {
145
+ return signal.aborted === true;
40
146
  }
41
147
  catch {
42
- return undefined;
148
+ return false;
149
+ }
150
+ }
151
+ export async function claimApprovalCardFor(who, signal) {
152
+ let leave = () => { };
153
+ const left = new Promise((resolve) => {
154
+ leave = () => resolve('aborted');
155
+ });
156
+ const unsubscribe = followCallerSignal(signal, leave);
157
+ try {
158
+ for (;;) {
159
+ if (callerSignalAborted(signal))
160
+ return Object.freeze({ kind: 'aborted' });
161
+ const entry = settledApprovalOf(who.approvalId);
162
+ if (settledForDurableLane(entry) && entry !== undefined)
163
+ return Object.freeze({ kind: 'joined', outcome: { ...entry.outcome, joinedInFlight: true } });
164
+ const holder = approvalHoldFor(who);
165
+ if (holder === undefined)
166
+ return Object.freeze({ kind: 'held', hold: holdHostCard(who, signal) });
167
+ const wait = await Promise.race([awaitApprovalHolder(holder, undefined, 'decide'), left]);
168
+ if (wait === 'aborted')
169
+ return Object.freeze({ kind: 'aborted' });
170
+ if (wait.kind === 'settled')
171
+ return Object.freeze({ kind: 'joined', outcome: { ...wait.outcome, joinedInFlight: true } });
172
+ }
43
173
  }
44
174
  finally {
45
175
  unsubscribe();
46
176
  }
47
- const stillHeld = approvalDecisionHolds.inFlight.get(liveFrameCallKey(hold.identity.approvalId)) === hold;
48
- return stillHeld || settledForDurableLane(settledApprovalOf(hold.identity.approvalId)) ? { ...o, joinedInFlight: true } : undefined;
49
177
  }
50
178
  export const approvalDecisionHolds = { inFlight: new Map(), settled: new Map(), openReads: new Set(), outcomes: new Map(), clock: 0 };
51
179
  export function settledApprovalOf(approvalId) {
@@ -57,14 +185,17 @@ export function clearSettledApprovals() {
57
185
  export function anyApprovalSettled() {
58
186
  return approvalDecisionHolds.outcomes.size > 0;
59
187
  }
60
- function noteSettled(approvalId, how, parked, outcome) {
188
+ function noteSettled(approvalId, how, parked, outcome, upgradesParked = false) {
61
189
  if (typeof approvalId !== 'string' || approvalId === '')
62
190
  return;
63
191
  if (!APPROVAL_SETTLED_HOWS.includes(how))
64
192
  return;
65
193
  const t = approvalDecisionHolds.outcomes;
66
- if (t.has(approvalId))
194
+ const prev = t.get(approvalId);
195
+ if (prev !== undefined && !(upgradesParked && prev.parked && how !== 'closed_by_engine'))
67
196
  return;
197
+ if (prev !== undefined)
198
+ t.delete(approvalId);
68
199
  t.set(approvalId, Object.freeze({ how, parked, outcome: Object.freeze({ ...outcome }) }));
69
200
  while (t.size > SETTLED_APPROVALS_MAX_ENTRIES) {
70
201
  const oldest = t.keys().next();
@@ -73,9 +204,28 @@ function noteSettled(approvalId, how, parked, outcome) {
73
204
  t.delete(oldest.value);
74
205
  }
75
206
  }
76
- const ENGINE_CLOSED_OUTCOME = Object.freeze({ decision: 'unresolved', retracted: true });
207
+ function engineClosedOutcome() {
208
+ return Object.freeze({ kind: 'not_sent', lane: 'respond', cause: 'retracted' });
209
+ }
77
210
  export function noteEngineClosedApproval(approvalId, parked) {
78
- noteSettled(approvalId, 'closed_by_engine', parked, ENGINE_CLOSED_OUTCOME);
211
+ noteSettled(approvalId, 'closed_by_engine', parked, engineClosedOutcome());
212
+ }
213
+ export function settleEngineClosedApproval(frame, parked) {
214
+ let id;
215
+ try {
216
+ const d = typeof frame === 'object' && frame !== null ? Object.getOwnPropertyDescriptor(frame, 'approvalId') : undefined;
217
+ id = d !== undefined && Object.hasOwn(d, 'value') ? d.value : undefined;
218
+ }
219
+ catch {
220
+ return false;
221
+ }
222
+ if (!nonEmpty(id))
223
+ return false;
224
+ noteEngineClosedApproval(id, parked);
225
+ return supersedeLiveCard(liveFrameCallKey(id), parked);
226
+ }
227
+ export function noteHolderSettledApproval(approvalId, how, outcome) {
228
+ noteSettled(approvalId, how, false, outcome, true);
79
229
  }
80
230
  export function settledLiveCardOutcome(approvalId) {
81
231
  const e = settledApprovalOf(approvalId);
@@ -1,36 +1,61 @@
1
1
  import type { DecideReceiptView } from '../decideReceipt.js';
2
- import type { HitlSafetyCode } from './hitlBridge.js';
3
- import type { FsApprovalOutcome, ToolApprovalFrameOutcome, ToolApprovalRespondAckView, ToolApprovalRespondDecision, ToolApprovalRespondParkingView } from './toolApprovalWire.js';
4
- export declare const APPROVAL_NOT_SENT_CAUSES: readonly ["retracted", "edit_refused", "no_pending", "fetch_failed", "no_input", "card_unavailable"];
2
+ import { type HitlSafetyCode } from './hitlBridge.js';
3
+ import type { AskAnsweredOutput } from './gateLedger.js';
4
+ import type { ApprovalDenySettledBy, ToolApprovalRespondAckView, ToolApprovalRespondDecision, ToolApprovalRespondParkingView } from './toolApprovalWire.js';
5
+ import { type DecisionRefusalReading, type RefusalRouteContext } from './decisionRefusal.js';
6
+ export declare const APPROVAL_RESOLUTION_LANES: readonly ["respond", "decide", "ask"];
7
+ export type ApprovalResolutionLane = (typeof APPROVAL_RESOLUTION_LANES)[number];
8
+ export declare const APPROVAL_NOT_SENT_CAUSES: readonly ["retracted", "edit_refused", "no_pending", "wrong_gate", "fetch_failed", "no_input", "card_unavailable", "safety_stop"];
5
9
  export type ApprovalNotSentCause = (typeof APPROVAL_NOT_SENT_CAUSES)[number];
6
- export declare const APPROVAL_UNSETTLED_CAUSES: readonly ["engine_refused", "decide_failed", "transport_exhausted", "safety_stop", "respond_failed", "parking_in_progress", "interrupted", "orchestration", "unreadable"];
10
+ export declare const APPROVAL_UNSETTLED_CAUSES: readonly ["engine_refused", "engine_error", "no_answer", "transport_exhausted", "parking_in_progress", "interrupted", "orchestration", "unreadable"];
7
11
  export type ApprovalUnsettledCause = (typeof APPROVAL_UNSETTLED_CAUSES)[number];
8
- export interface ApprovalResolutionDecided {
9
- kind: 'decided';
10
- decision: ToolApprovalRespondDecision;
11
- gatedCallId?: string;
12
- receipt?: DecideReceiptView;
13
- ack?: ToolApprovalRespondAckView;
12
+ export interface ApprovalDenyFacts {
13
+ readonly settledBy?: ApprovalDenySettledBy;
14
+ readonly reason?: string;
15
+ readonly attributionKey?: 'dropped' | 'renamed';
14
16
  }
15
- export interface ApprovalResolutionNotSent {
16
- kind: 'not_sent';
17
- cause: ApprovalNotSentCause;
18
- gatedCallId?: string;
19
- detail?: string;
17
+ interface ApprovalResolutionBase {
18
+ readonly lane: ApprovalResolutionLane;
19
+ readonly gatedCallId?: string;
20
+ readonly joinedInFlight?: true;
20
21
  }
21
- export interface ApprovalResolutionUnsettled {
22
- kind: 'unsettled';
23
- cause: ApprovalUnsettledCause;
24
- gatedCallId?: string;
25
- safetyCode?: HitlSafetyCode;
26
- errorCode?: string;
27
- status?: number;
28
- detail?: string;
29
- parking?: ToolApprovalRespondParkingView;
22
+ export interface ApprovalResolutionDecided extends ApprovalResolutionBase {
23
+ readonly kind: 'decided';
24
+ readonly decision: ToolApprovalRespondDecision;
25
+ readonly deny?: ApprovalDenyFacts;
26
+ readonly receipt?: DecideReceiptView;
27
+ readonly ack?: ToolApprovalRespondAckView;
28
+ readonly answered?: AskAnsweredOutput;
29
+ }
30
+ export interface ApprovalResolutionNotSent extends ApprovalResolutionBase {
31
+ readonly kind: 'not_sent';
32
+ readonly cause: ApprovalNotSentCause;
33
+ readonly safetyCode?: Exclude<HitlSafetyCode, 'binding_mismatch' | 'no_pending' | 'wrong_gate'>;
34
+ readonly detail?: string;
35
+ }
36
+ export interface ApprovalResolutionUnsettled extends ApprovalResolutionBase {
37
+ readonly kind: 'unsettled';
38
+ readonly cause: ApprovalUnsettledCause;
39
+ readonly safetyCode?: 'binding_mismatch';
40
+ readonly refusal?: DecisionRefusalReading;
41
+ readonly parking?: ToolApprovalRespondParkingView;
42
+ readonly detail?: string;
30
43
  }
31
44
  export type ApprovalResolution = ApprovalResolutionDecided | ApprovalResolutionNotSent | ApprovalResolutionUnsettled;
32
- export type ApprovalLegOutcome = FsApprovalOutcome | ToolApprovalFrameOutcome;
33
- export declare function approvalResolutionOf(outcome: ApprovalLegOutcome): ApprovalResolution;
34
45
  export declare function isApprovalDecided(r: ApprovalResolution): r is ApprovalResolutionDecided;
35
46
  export declare function approvalNotSentCause(r: ApprovalResolution): ApprovalNotSentCause | undefined;
36
47
  export declare function approvalUnsettledCause(r: ApprovalResolution): ApprovalUnsettledCause | undefined;
48
+ export declare const APPROVAL_NOTE_RETRACTED_DETAIL = "the card was retracted (this host no longer has a decision port for it)";
49
+ export declare const APPROVAL_NOTE_EDIT_REFUSED_DETAIL = "edits are not accepted on this card";
50
+ export declare function approvalResolutionDetail(r: ApprovalResolution): string | undefined;
51
+ export declare function unsettledCauseOfReading(reading: DecisionRefusalReading): 'engine_refused' | 'engine_error' | 'no_answer';
52
+ export interface DecisionFailureMint {
53
+ readonly lane: ApprovalResolutionLane;
54
+ readonly route: NonNullable<RefusalRouteContext['route']>;
55
+ readonly gatedCallId?: string | undefined;
56
+ readonly detail?: string | undefined;
57
+ readonly attributionCarried?: boolean | undefined;
58
+ }
59
+ export declare function resolutionOfDecisionFailure(e: {} | null | undefined, m: DecisionFailureMint): ApprovalResolution;
60
+ export declare function joinedResolution(r: ApprovalResolution, gatedCallId?: string): ApprovalResolution;
61
+ export {};