@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
@@ -2,6 +2,7 @@ import type { AgentEvent, CheckpointGate, TaskResult } from '@sema-agent/sdk';
2
2
  import { type WiringManifestView } from './wiringManifestView.js';
3
3
  import { type SDKMessage, type EmitContext, type ModelUsage } from '../types.js';
4
4
  import { type McpLivenessView } from '../../mcpLiveness.js';
5
+ import { type ContextUsageSectionRow } from '../../ownKey.js';
5
6
  export declare const INTERNAL_SDK_ARM_TYPES: ReadonlySet<string>;
6
7
  export type EventProjectionNoneReason = 'usage_only' | 'terminal_delegated' | 'hitl_out_of_slice' | 'not_in_slice' | 'empty_payload';
7
8
  export type EventProjectionDropReason = 'malformed' | 'unknown_arm' | 'unsupported_arm';
@@ -66,11 +67,7 @@ export interface WiringManifestLspSeamView {
66
67
  mounted: boolean;
67
68
  lane?: string;
68
69
  }
69
- export interface ContextUsageSectionView {
70
- id: string;
71
- tokens: number;
72
- kind?: string;
73
- }
70
+ export type ContextUsageSectionView = ContextUsageSectionRow;
74
71
  export interface PromptManifestSectionView {
75
72
  id: string;
76
73
  chars: number;
@@ -5,10 +5,11 @@ import { ccToolDenialKindForToolEnd, gateOutcomeOf } from '../../gateOutcome.js'
5
5
  import { projectToolRoster, projectToolRosterDelta } from '../../toolRoster.js';
6
6
  import { projectHandsSection } from '../../handsSeam.js';
7
7
  import { readMcpLiveness } from '../../mcpLiveness.js';
8
- import { markMcpSectionDroppedNamedRows, readFrameTrueMark } from '../../ownKey.js';
9
- import { SEGMENT_END_IDENTITY_KEYS, stripToolUseSideChannels } from '../types.js';
8
+ import { contextUsageReadingOf, humanInputAttachmentsOf, markMcpSectionDroppedNamedRows, readFrameTrueMark } from '../../ownKey.js';
9
+ import { SEGMENT_END_IDENTITY_KEYS, eventSeq, stripToolUseSideChannels } from '../types.js';
10
10
  import { frozenSet } from '../../frozenSet.js';
11
11
  import { isCoreWorkflowRunTerminal } from '../../terminalStatuses.js';
12
+ import { envelopeUuidOf, mintEngineRowRef, readBoundRun, wireEventIdOf } from '../../engineRowRef.js';
12
13
  function armBody(body) {
13
14
  return body;
14
15
  }
@@ -23,8 +24,10 @@ export const INTERNAL_SDK_ARM_TYPES = frozenSet([
23
24
  'prompt_assembled',
24
25
  'workflow_complete',
25
26
  'tool_end_result',
27
+ 'terminal_fact',
26
28
  'retry_status',
27
29
  'task_progress',
30
+ 'task_started',
28
31
  'task_notification',
29
32
  'diagnostics',
30
33
  'steering_injected',
@@ -69,7 +72,22 @@ const dropped = (why, type) => ({ kind: 'dropped', why, type });
69
72
  function assertNeverArm(_ev) {
70
73
  }
71
74
  export function eventToSdkMessage(ev, ctx) {
75
+ return withEngineIdentity(projectEvent(ev, ctx), ev, ctx);
76
+ }
77
+ function withEngineIdentity(p, ev, ctx) {
78
+ if (p.kind !== 'message')
79
+ return p;
80
+ const eventId = wireEventIdOf(ev);
81
+ if (eventId === undefined)
82
+ return p;
83
+ const env = p.message;
84
+ const ref = mintEngineRowRef(eventId, ctx.boundRun === undefined ? undefined : readBoundRun(() => ctx.boundRun?.(ev)));
85
+ return projected(Object.assign({}, env, { uuid: envelopeUuidOf(eventId, env.type), _sema_engine_ref: ref }));
86
+ }
87
+ function projectEvent(ev, ctx) {
72
88
  switch (ev.type) {
89
+ case 'task_started':
90
+ return taskStartedProjection(ev, ctx);
73
91
  case 'text_end':
74
92
  return textEndProjection(ev, ctx);
75
93
  case 'reasoning_end':
@@ -178,7 +196,6 @@ export function eventToSdkMessage(ev, ctx) {
178
196
  const toolEndGatedCallId = ev.gatedCallId;
179
197
  const collateralAbort = ev._sema_collateral_abort;
180
198
  const denialKind = ccToolDenialKindForToolEnd(ev);
181
- const denialUnclassified = denialKind === undefined && toolEndGate?.disposition.kind === 'denied';
182
199
  const toolEndNotExecuted = readFrameTrueMark(ev, 'notExecuted');
183
200
  return projected(stamp(ctx, armBody({
184
201
  type: 'tool_end_result',
@@ -201,7 +218,6 @@ export function eventToSdkMessage(ev, ctx) {
201
218
  : {}),
202
219
  ...(collateralAbort === true ? { _sema_collateral_abort: true } : {}),
203
220
  ...(denialKind !== undefined ? { _sema_denial_kind: denialKind } : {}),
204
- ...(denialUnclassified ? { _sema_denial_unclassified: true } : {}),
205
221
  ...(toolEndNotExecuted ? { notExecuted: true } : {}),
206
222
  ...(ev.eventId !== undefined ? { eventId: ev.eventId } : {}),
207
223
  ...(ev.parentToolCallId !== undefined
@@ -210,19 +226,18 @@ export function eventToSdkMessage(ev, ctx) {
210
226
  })));
211
227
  }
212
228
  case 'status': {
213
- const st2 = ev;
214
229
  const num = (v) => typeof v === 'number' && Number.isFinite(v) ? v : undefined;
215
230
  const attempt = num(ev.attempt);
216
231
  const maxRetries = num(ev.maxRetries);
217
232
  const retryInMs = num(ev.retryInMs);
218
- const retryAtMs = num(st2.retryAtMs);
219
- const errorStatus = num(st2.errorStatus);
220
- const elapsedMs = num(st2.elapsedMs);
221
- const timeoutMs = num(st2.timeoutMs);
233
+ const retryAtMs = num(ev.retryAtMs);
234
+ const errorStatus = num(ev.errorStatus);
235
+ const elapsedMs = num(ev.elapsedMs);
236
+ const timeoutMs = num(ev.timeoutMs);
222
237
  const errClass = typeof ev.errClass === 'string' && ev.errClass.length > 0 ? ev.errClass : undefined;
223
238
  const nonEmptyStr = (v) => (typeof v === 'string' && v.length > 0 ? v : undefined);
224
- const providerCondition = nonEmptyStr(st2.providerCondition);
225
- const providerConditionSource = nonEmptyStr(st2.providerConditionSource);
239
+ const providerCondition = nonEmptyStr(ev.providerCondition);
240
+ const providerConditionSource = nonEmptyStr(ev.providerConditionSource);
226
241
  return projected(stamp(ctx, armBody({
227
242
  type: 'retry_status',
228
243
  phase: ev.phase,
@@ -648,33 +663,54 @@ function contextUsageProjection(ev, ctx) {
648
663
  const { identity, bad } = identityOrMalformed(ev, 'context_usage');
649
664
  if (bad !== null)
650
665
  return bad;
651
- const fin = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : undefined);
652
- const usedTokens = fin(ev.usedTokens);
653
- const windowTokens = fin(ev.windowTokens);
654
- const compactAtTokens = fin(ev.compactAtTokens);
655
- let sections;
656
- if (Array.isArray(ev.sections)) {
657
- const rows = [];
658
- for (const r of ev.sections) {
659
- if (typeof r !== 'object' || r === null || Array.isArray(r))
660
- continue;
661
- const o = r;
662
- const tokens = fin(o.tokens);
663
- if (typeof o.id !== 'string' || o.id.length === 0 || tokens === undefined)
664
- continue;
665
- rows.push({ id: o.id, tokens, ...(typeof o.kind === 'string' && o.kind.length > 0 ? { kind: o.kind } : {}) });
666
- }
667
- if (rows.length > 0)
668
- sections = rows;
669
- }
670
- if (usedTokens === undefined && windowTokens === undefined && compactAtTokens === undefined && sections === undefined)
666
+ const reading = contextUsageReadingOf(ev);
667
+ if (reading === undefined)
671
668
  return nothing('empty_payload');
672
669
  return projected(internalArmExit(stamp(ctx, armBody({
673
670
  type: 'context_usage',
674
- ...(usedTokens !== undefined ? { usedTokens } : {}),
675
- ...(windowTokens !== undefined ? { windowTokens } : {}),
676
- ...(compactAtTokens !== undefined ? { compactAtTokens } : {}),
677
- ...(sections !== undefined ? { sections } : {}),
671
+ ...reading,
672
+ ...identity,
673
+ }))));
674
+ }
675
+ function taskStartedProjection(frame, ctx) {
676
+ const ev = frame;
677
+ const { identity, bad } = identityOrMalformed(ev, 'task_started');
678
+ if (bad !== null)
679
+ return bad;
680
+ const str = (v) => (typeof v === 'string' && v.length > 0 ? v : undefined);
681
+ const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : undefined);
682
+ const taskId = str(ev.taskId);
683
+ if (taskId === undefined)
684
+ return dropped('malformed', 'task_started');
685
+ const sessionId = str(ev.sessionId);
686
+ const model = str(ev.model);
687
+ const taskType = str(ev.taskType);
688
+ const seq = num(ev.seq);
689
+ const workflowRunId = str(ev.workflowRunId);
690
+ const workflowAgentLabel = str(ev.workflowAgentLabel);
691
+ const parentTaskId = str(ev.parentTaskId);
692
+ const parentSessionId = str(ev.parentSessionId);
693
+ const rootSessionId = str(ev.rootSessionId);
694
+ const name = str(ev.name);
695
+ const spawnName = str(ev.spawnName);
696
+ const agentType = str(ev.agentType);
697
+ const startedAt = num(ev.startedAt);
698
+ return projected(internalArmExit(stamp(ctx, armBody({
699
+ type: 'task_started',
700
+ taskId,
701
+ ...(sessionId !== undefined ? { sessionId } : {}),
702
+ ...(model !== undefined ? { model } : {}),
703
+ ...(taskType !== undefined ? { taskType } : {}),
704
+ ...(seq !== undefined ? { seq } : {}),
705
+ ...(workflowRunId !== undefined ? { workflowRunId } : {}),
706
+ ...(workflowAgentLabel !== undefined ? { workflowAgentLabel } : {}),
707
+ ...(parentTaskId !== undefined ? { parentTaskId } : {}),
708
+ ...(parentSessionId !== undefined ? { parentSessionId } : {}),
709
+ ...(rootSessionId !== undefined ? { rootSessionId } : {}),
710
+ ...(name !== undefined ? { name } : {}),
711
+ ...(spawnName !== undefined ? { spawnName } : {}),
712
+ ...(agentType !== undefined ? { agentType } : {}),
713
+ ...(startedAt !== undefined ? { startedAt } : {}),
678
714
  ...identity,
679
715
  }))));
680
716
  }
@@ -774,6 +810,7 @@ function engineNoticeProjection(ev, ctx) {
774
810
  const detail = typeof rawDetail === 'object' && rawDetail !== null && !Array.isArray(rawDetail)
775
811
  ? rawDetail
776
812
  : {};
813
+ const seq = eventSeq(ev);
777
814
  return projected(stamp(ctx, armBody({
778
815
  type: 'engine_notice',
779
816
  code,
@@ -782,7 +819,7 @@ function engineNoticeProjection(ev, ctx) {
782
819
  ...(sessionId !== undefined ? { sessionId } : {}),
783
820
  ...(ts !== undefined ? { ts } : {}),
784
821
  ...(typeof ev.eventId === 'string' && ev.eventId.length > 0 ? { eventId: ev.eventId } : {}),
785
- ...(typeof ev.id === 'string' && ev.id.length > 0 ? { eventSeq: ev.id } : {}),
822
+ ...(seq !== undefined ? { eventSeq: seq } : {}),
786
823
  })));
787
824
  }
788
825
  function approvalFrameBody(ev) {
@@ -820,8 +857,12 @@ function humanInputProjection(ev, ctx) {
820
857
  ...(str(ev.entryId) !== undefined ? { entryId: str(ev.entryId) } : {}),
821
858
  ...(str(ev.eventId) !== undefined ? { eventId: str(ev.eventId) } : {}),
822
859
  ...(str(ev.parentToolCallId) !== undefined ? { parentToolCallId: str(ev.parentToolCallId) } : {}),
860
+ ...attachmentsKey(humanInputAttachmentsOf(ev)),
823
861
  })));
824
862
  }
863
+ function attachmentsKey(rows) {
864
+ return rows !== undefined ? { attachments: rows } : {};
865
+ }
825
866
  export function turnEndUsage(ev) {
826
867
  const rawValue = ev.usage;
827
868
  if (typeof rawValue !== 'object' || rawValue === null || Array.isArray(rawValue))
@@ -4,7 +4,8 @@ import { putOwnKey, readFrameStringKey } from '../../ownKey.js';
4
4
  import { REDACTION_MARKER_PREFIX, washCredentials } from '../../displayUntrusted.js';
5
5
  import { readEffectiveReasoning, readEffectiveMemoryScopes } from '../../effectiveFacts.js';
6
6
  import { isReviewPark, readRunTerminal, runTerminalCode, runTerminalGateToolName, } from '../../runTerminal.js';
7
- import { doneResultView } from '../../replayBody.js';
7
+ import { doneResultView, isReplayedTerminal } from '../../replayBody.js';
8
+ import { terminalRunIdOf, terminalUuidOf } from '../../engineRowRef.js';
8
9
  import { toCcModelUsage } from './turnUsageToModelUsage.js';
9
10
  import { LIMITS_MAX_COST_EXCEEDED, LIMITS_MAX_TOKENS_EXCEEDED, LIMITS_MAX_TURNS_EXCEEDED, LIMITS_MAX_WALLTIME_EXCEEDED, OUTPUT_INVALID, isCorruptSessionCode, idempotencyPayloadMismatchContent, isIdempotencyPayloadMismatchCode, isRewindFamilyCode, } from '../../engineErrorCodes.js';
10
11
  import { corruptSessionContent } from '../../corruptSessionCopy.js';
@@ -497,7 +498,7 @@ function cutoffParts(r, message, fallbackMessage, code) {
497
498
  }
498
499
  function errorResult(ctx, parts) {
499
500
  return stamp(ctx, {
500
- uuid: undefined,
501
+ uuid: parts.uuid,
501
502
  session_id: undefined,
502
503
  type: 'result',
503
504
  subtype: parts.subtype,
@@ -525,6 +526,10 @@ function errorResult(ctx, parts) {
525
526
  });
526
527
  }
527
528
  export function doneToSdkResult(ev, ctx, observed) {
529
+ const msg = doneToSdkResultBody(ev, ctx, observed);
530
+ return isReplayedTerminal(ev) ? Object.assign({}, msg, { _sema_replay: true }) : msg;
531
+ }
532
+ function doneToSdkResultBody(ev, ctx, observed) {
528
533
  const view = doneResultView(ev.result);
529
534
  const rRaw = view.engine;
530
535
  const rec = typeof rRaw === 'object' && rRaw !== null ? rRaw : {};
@@ -539,7 +544,9 @@ export function doneToSdkResult(ev, ctx, observed) {
539
544
  const errorCode = runTerminalCode(terminal);
540
545
  const degraded = degradedOf(r);
541
546
  const parkFailedReason = readFrameStringKey(ev, '_sema_park_failed_reason');
542
- const errorBase = { durationMs, stats, model: r.model, errorCode, degraded, observed, facts: effectiveFactParts(rec), parkFailedReason, abortCause: abortCauseWordOf(ev) };
547
+ const terminalRunId = terminalRunIdOf(ev);
548
+ const resultUuid = terminalRunId === undefined ? undefined : terminalUuidOf(terminalRunId, 'result');
549
+ const errorBase = { uuid: resultUuid, durationMs, stats, model: r.model, errorCode, degraded, observed, facts: effectiveFactParts(rec), parkFailedReason, abortCause: abortCauseWordOf(ev) };
543
550
  if (terminal?.kind === 'failed') {
544
551
  const failedCode = terminal.code;
545
552
  const failedMessage = terminal.message;
@@ -613,7 +620,7 @@ export function doneToSdkResult(ev, ctx, observed) {
613
620
  });
614
621
  }
615
622
  return stamp(ctx, {
616
- uuid: undefined,
623
+ uuid: resultUuid,
617
624
  session_id: undefined,
618
625
  type: 'result',
619
626
  subtype: 'success',
@@ -12,10 +12,13 @@ export interface EngineUsageLike {
12
12
  readonly costMicroUsd?: number | undefined;
13
13
  readonly webSearchRequests?: number | undefined;
14
14
  }
15
- export type SemaModelUsage = ModelUsage & {
15
+ export type SemaModelUsage = ModelUsage & SemaModelUsageAbsenceBits;
16
+ export interface SemaModelUsageAbsenceBits {
16
17
  readonly _sema_cost_absent?: true;
17
18
  readonly _sema_web_search_requests_absent?: true;
18
- };
19
+ readonly _sema_context_window_absent?: true;
20
+ readonly _sema_max_output_tokens_absent?: true;
21
+ }
19
22
  export declare function toCcModelUsage(raw: EngineUsageLike): SemaModelUsage;
20
23
  export declare function turnUsageToModelUsage(usage: TurnUsage): SemaModelUsage;
21
24
  export {};
@@ -15,6 +15,8 @@ export function toCcModelUsage(raw) {
15
15
  maxOutputTokens: 0,
16
16
  ...(costPriced ? {} : { _sema_cost_absent: true }),
17
17
  ...(webSearchKnown ? {} : { _sema_web_search_requests_absent: true }),
18
+ _sema_context_window_absent: true,
19
+ _sema_max_output_tokens_absent: true,
18
20
  };
19
21
  }
20
22
  export function turnUsageToModelUsage(usage) {
@@ -2,19 +2,36 @@ import { eventSeq, stamp, } from './types.js';
2
2
  import { eventToSdkMessage, turnEndUsage } from './downstream/eventToSdkMessage.js';
3
3
  import { turnUsageToModelUsage } from './downstream/turnUsageToModelUsage.js';
4
4
  import { readRunCostFacts, terminalToSdkResult, TOOL_INPUT_JOIN_MAX_CALLS } from './downstream/terminalToSdkResult.js';
5
- import { coerceOutput, publishSubagentContentEvent } from '../subagentContentStore.js';
5
+ import { terminalRunIdOf, terminalUuidOf } from '../engineRowRef.js';
6
+ import { publishSubagentContentEvent, subagentContentEventOf } from '../subagentContentStore.js';
6
7
  import { OUTPUT_INVALID, activeRunBusyCarrierOf, classifyActiveRunBusy, isCorruptSessionCode, isLimitsExceededCode } from '../engineErrorCodes.js';
7
- import { doneResultView } from '../replayBody.js';
8
+ import { doneResultView, isReplayedTerminal } from '../replayBody.js';
9
+ import { readFrameStringKey } from '../ownKey.js';
8
10
  import { corruptSessionContent } from '../corruptSessionCopy.js';
9
11
  import { abortCauseNoteOf } from '../runCancelContext.js';
10
12
  import { classifyToolHistoryMismatch, noteToolHistoryTerminal, openToolHistoryGeneration, TOOL_HISTORY_REWIND_SENTENCE, toolHistoryMismatchRowKey, toolHistoryRepeatSentence, toolHistoryRewindOffered, } from '../toolHistoryMismatch.js';
11
13
  import { isReviewPark, readRunTerminal, runTerminalCode } from '../runTerminal.js';
14
+ import { parkHeldCallIdOf } from '../engineRowRef.js';
12
15
  import { providerRejectionResend } from '../providerRejection.js';
13
- import { washCredentials } from '../displayUntrusted.js';
16
+ import { displayUntrusted, washCredentials } from '../displayUntrusted.js';
14
17
  import { PROMPT_BLOCKED_BY_HOOK_ROW_LEAD, runBlockedText } from '../promptBlockedCopy.js';
15
18
  import { ccToolDenialKindForToolEnd, gateDeniedBy, gateOutcomeOf } from '../gateOutcome.js';
16
19
  import { resumeReopenContent, resumeReopenFromError, suspendedReopenOf } from '../hitl/suspendedReopen.js';
17
20
  import { isCcToolDenialKind, isCcToolDenialKindADenial, isGateDeniedByWord } from '../gateVocabulary.js';
21
+ const ENGINE_TURN_USAGE_KEYS = Object.freeze(['inputTokens', 'totalInputTokens', 'outputTokens', 'cacheReadTokens', 'cacheWriteTokens', 'costMicroUsd']);
22
+ const _engineTurnUsageKeysPin = true;
23
+ void _engineTurnUsageKeysPin;
24
+ function closedEngineTurnUsage(raw) {
25
+ const out = {};
26
+ let unknownKeys = 0;
27
+ for (const k of Object.keys(raw)) {
28
+ if (ENGINE_TURN_USAGE_KEYS.includes(k))
29
+ out[k] = raw[k];
30
+ else
31
+ unknownKeys++;
32
+ }
33
+ return { usage: out, unknownKeys };
34
+ }
18
35
  const mainLane = () => ({ lane: 'main' });
19
36
  function emitChromeFireAndForget(ctx, event) {
20
37
  try {
@@ -108,9 +125,25 @@ export function isModelOutputErrorRowText(text) {
108
125
  return text.trimStart().startsWith(`${MODEL_OUTPUT_ERROR_PREFIX}:`);
109
126
  }
110
127
  export const OUTCOME_UNKNOWN_ROW_PREFIX = 'Outcome unknown';
111
- function syntheticTerminalRow(ctx, text, historyKey, resend) {
128
+ function apiErrorRowBitsOf(read) {
129
+ try {
130
+ const status = read.carrier.status;
131
+ const providerCondition = read.detail !== undefined && ownDataBit(read.detail, 'kind') === PROVIDER_REJECTED_DETAIL ? nonEmptyStr(ownDataBit(read.detail, 'providerCondition')) : undefined;
132
+ const errorCode = nonEmptyStr(read.carrier.code);
133
+ const bits = {
134
+ ...(typeof status === 'number' && Number.isInteger(status) && status >= 100 && status <= 999 ? { status } : {}),
135
+ ...(providerCondition !== undefined ? { providerCondition } : {}),
136
+ ...(errorCode !== undefined ? { errorCode } : {}),
137
+ };
138
+ return Object.keys(bits).length > 0 ? bits : undefined;
139
+ }
140
+ catch {
141
+ return undefined;
142
+ }
143
+ }
144
+ function syntheticTerminalRow(ctx, identity, replayed, text, historyKey, resend, apiError) {
112
145
  return stamp(ctx, {
113
- uuid: undefined,
146
+ uuid: identity.runId === undefined ? undefined : terminalUuidOf(identity.runId, identity.label),
114
147
  session_id: undefined,
115
148
  type: 'assistant',
116
149
  message: { role: 'assistant', model: '<synthetic>', content: [{ type: 'text', text: washCredentials(text) }] },
@@ -118,12 +151,12 @@ function syntheticTerminalRow(ctx, text, historyKey, resend) {
118
151
  _sema_api_error_message: true,
119
152
  ...(historyKey !== undefined ? { _sema_tool_history_mismatch: historyKey } : {}),
120
153
  ...(resend !== undefined ? { _sema_provider_rejection_resend: { resend: resend.resend, text: resend.text, kind: resend.kind } } : {}),
154
+ ...(apiError?.status !== undefined ? { _sema_api_error_status: apiError.status } : {}),
155
+ ...(apiError?.providerCondition !== undefined ? { _sema_provider_condition: apiError.providerCondition } : {}),
156
+ ...(apiError?.errorCode !== undefined ? { _sema_api_error_code: apiError.errorCode } : {}),
157
+ ...(replayed ? { _sema_replay: true } : {}),
121
158
  });
122
159
  }
123
- function engineRunIdOf(result) {
124
- const v = result?.runId;
125
- return typeof v === 'string' && v.length > 0 ? v : undefined;
126
- }
127
160
  function engineResultOf(result) {
128
161
  const v = doneResultView(result);
129
162
  return v.replay ? (v.engine ?? result) : result;
@@ -142,6 +175,19 @@ export function isGovernanceTerminal(input) {
142
175
  return true;
143
176
  return input.errorCode === OUTPUT_INVALID;
144
177
  }
178
+ function terminalFactOf(ev, doneTerminal) {
179
+ const engine = ev.type === 'done' ? engineResultOf(ev.result) : ev;
180
+ const taskId = readFrameStringKey(engine, 'taskId');
181
+ if (ev.type !== 'done' || doneTerminal?.kind !== 'paused')
182
+ return { type: 'terminal_fact', ...(taskId !== undefined ? { taskId } : {}) };
183
+ const checkpointId = doneTerminal.checkpointId;
184
+ const heldCallId = parkHeldCallIdOf(engine);
185
+ return {
186
+ type: 'terminal_fact',
187
+ ...(taskId !== undefined ? { taskId } : {}),
188
+ paused: { ...(checkpointId !== undefined ? { checkpointId } : {}), ...(heldCallId !== undefined ? { heldCallId } : {}) },
189
+ };
190
+ }
145
191
  function terminalRowFacts(ev) {
146
192
  const doneTerminal = ev.type === 'done' ? readRunTerminal(ev.result) : null;
147
193
  const errTextRaw = ev.type === 'failed'
@@ -220,7 +266,7 @@ function ownTerminalSnapshot(result) {
220
266
  const ts = ownDataCopy(t, ['kind', 'code', 'message']);
221
267
  const detail = plainObjectOf(ownDataBit(t, 'detail'));
222
268
  if (detail !== undefined)
223
- ts.detail = ownDataCopy(detail, ['kind', 'status', 'code']);
269
+ ts.detail = ownDataCopy(detail, ['kind', 'status', 'code', 'providerCondition']);
224
270
  snap.terminal = ts;
225
271
  return snap;
226
272
  }
@@ -301,12 +347,10 @@ function apiErrorTerminalOfRowFrame(ev, facts) {
301
347
  }
302
348
  const reportedDroppedTypes = new Set();
303
349
  const DROPPED_TYPE_MEMO_CAP = 64;
304
- const DROPPED_TYPE_DISPLAY_CAP = 60;
305
- function sanitizeFrameType(type) {
306
- const flattened = type.replace(/[\u0000-\u001f\u007f-\u009f]/g, '\uFFFD');
307
- return flattened.length > DROPPED_TYPE_DISPLAY_CAP
308
- ? `${flattened.slice(0, DROPPED_TYPE_DISPLAY_CAP)}…`
309
- : flattened;
350
+ const DROPPED_TYPE_DISPLAY_MAX = 60;
351
+ function droppedTypeForLog(type) {
352
+ const full = displayUntrusted(type);
353
+ return full.length > DROPPED_TYPE_DISPLAY_MAX ? `${displayUntrusted(type, { max: DROPPED_TYPE_DISPLAY_MAX })}…` : full;
310
354
  }
311
355
  const DROPPED_WHY_SENTENCE = Object.freeze({
312
356
  duplicate_seq: 'a frame with this event id was already consumed on this run stream, so it was dropped as a replay (durable idempotency, contract 02 §1.1). ' +
@@ -335,7 +379,7 @@ function reportDroppedFrame(why, type, ctx) {
335
379
  return;
336
380
  if (reportedDroppedTypes.size < DROPPED_TYPE_MEMO_CAP)
337
381
  reportedDroppedTypes.add(type);
338
- console.error(`[client-core] dropped an engine frame (${why}): type="${sanitizeFrameType(type)}" — ${droppedWhySentence(why)}`);
382
+ console.error(`[client-core] dropped an engine frame (${why}): type="${droppedTypeForLog(type)}" — ${droppedWhySentence(why)}`);
339
383
  }
340
384
  export function _resetDroppedFrameReportForTest() {
341
385
  reportedDroppedTypes.clear();
@@ -499,27 +543,9 @@ async function* runStreamInner(events, ctx, handle = {}) {
499
543
  }
500
544
  }
501
545
  }
502
- if ((ev.type === 'text_delta' ||
503
- ev.type === 'reasoning_delta' ||
504
- ev.type === 'text' ||
505
- ev.type === 'reasoning' ||
506
- ev.type === 'tool_start' ||
507
- ev.type === 'tool_end') &&
508
- typeof ev.parentToolCallId === 'string') {
509
- const sub = ev;
510
- publishSubagentContentEvent({
511
- type: sub.type,
512
- taskId: sub.taskId ?? sub.parentToolCallId,
513
- parentToolCallId: sub.parentToolCallId,
514
- delta: sub.delta,
515
- text: sub.text,
516
- eventId: sub.eventId,
517
- toolCallId: sub.toolCallId,
518
- toolName: sub.toolName,
519
- args: sub.args,
520
- output: coerceOutput(sub.output),
521
- isError: sub.isError,
522
- });
546
+ const sub = subagentContentEventOf(ev);
547
+ if (sub !== undefined) {
548
+ publishSubagentContentEvent(sub);
523
549
  if (!(ctx.lane === 'print' && (sub.type === 'tool_start' || sub.type === 'tool_end')))
524
550
  continue;
525
551
  }
@@ -533,10 +559,10 @@ async function* runStreamInner(events, ctx, handle = {}) {
533
559
  const responseModelRaw = turnEndLoose.responseModel;
534
560
  const responseModelWord = typeof responseModelRaw === 'string' && responseModelRaw.length > 0 ? responseModelRaw : undefined;
535
561
  const rawUsage = ev.usage;
536
- const engineUsage = typeof rawUsage === 'object' && rawUsage !== null && !Array.isArray(rawUsage)
537
- ? rawUsage
538
- : undefined;
539
- const usage = engineUsage !== undefined ? turnUsageToModelUsage(engineUsage) : undefined;
562
+ const closedUsage = typeof rawUsage === 'object' && rawUsage !== null && !Array.isArray(rawUsage) ? closedEngineTurnUsage(rawUsage) : undefined;
563
+ const engineUsage = closedUsage?.usage;
564
+ const usageUnknownKeys = closedUsage !== undefined && closedUsage.unknownKeys > 0 ? { engineUsageUnknownKeys: closedUsage.unknownKeys } : {};
565
+ const usage = closedUsage !== undefined ? turnUsageToModelUsage(rawUsage) : undefined;
540
566
  const measured = turnEndUsage(ev);
541
567
  if (engineUsage === undefined || usage === undefined) {
542
568
  usageMissingObserved = true;
@@ -564,6 +590,7 @@ async function* runStreamInner(events, ctx, handle = {}) {
564
590
  laneProof: mainLane(),
565
591
  usage,
566
592
  engineUsage,
593
+ ...usageUnknownKeys,
567
594
  ...(usageMissing ? { usageMissing: true } : {}),
568
595
  ...(stopWord !== undefined ? { stopReason: stopWord } : {}),
569
596
  ...(responseModelWord !== undefined ? { responseModel: responseModelWord } : {}),
@@ -587,6 +614,7 @@ async function* runStreamInner(events, ctx, handle = {}) {
587
614
  parentToolCallId: parent,
588
615
  usage,
589
616
  engineUsage,
617
+ ...usageUnknownKeys,
590
618
  ...(usageMissing ? { usageMissing: true } : {}),
591
619
  ...(stopWord !== undefined ? { stopReason: stopWord } : {}),
592
620
  ...(responseModelWord !== undefined ? { responseModel: responseModelWord } : {}),
@@ -625,6 +653,8 @@ async function* runStreamInner(events, ctx, handle = {}) {
625
653
  if (ev.type === 'done' || ev.type === 'failed') {
626
654
  const rowFacts = terminalRowFacts(ev);
627
655
  const doneTerminal = rowFacts.doneTerminal;
656
+ const terminalRunId = terminalRunIdOf(ev);
657
+ const replayed = isReplayedTerminal(ev);
628
658
  const errText = rowFacts.errText;
629
659
  if (errText) {
630
660
  const busy = rowFacts.busy;
@@ -655,8 +685,8 @@ async function* runStreamInner(events, ctx, handle = {}) {
655
685
  sessionId: historyEchoedSid ?? ctx.sessionId,
656
686
  sessionEchoed: historyEchoedSid !== undefined,
657
687
  generation: historyGeneration,
658
- runId: ev.type === 'done' ? engineRunIdOf(engineResultOf(ev.result)) : undefined,
659
- replay: ev.type === 'done' && ev.replay === true,
688
+ runId: terminalRunId,
689
+ replay: replayed,
660
690
  mismatch: historyMismatch,
661
691
  });
662
692
  const rewindOffered = historyMismatch !== null && ctx.lane !== 'print' && ctx.lane !== 'utility' && toolHistoryRewindOffered(ctx.offersRewind);
@@ -665,7 +695,7 @@ async function* runStreamInner(events, ctx, handle = {}) {
665
695
  : '';
666
696
  const resend = historyTerminal.detail !== undefined ? providerRejectionResend(historyTerminal.detail, historyTerminal.carrier) : undefined;
667
697
  const resendLine = resend !== undefined ? `\n${resend.text}` : '';
668
- yield syntheticTerminalRow(ctx, `${sessionUnreadable ? `${rowText}\n${corruptSessionContent()}` : rowText}${abortNote !== undefined ? `\n${abortNote}` : ''}${rewindLine}${resendLine}`, historyMismatch === null ? undefined : toolHistoryMismatchRowKey(historyMismatch, historyRepeat, rewindOffered), resend);
698
+ yield syntheticTerminalRow(ctx, { runId: terminalRunId, label: 'terminal-row' }, replayed, `${sessionUnreadable ? `${rowText}\n${corruptSessionContent()}` : rowText}${abortNote !== undefined ? `\n${abortNote}` : ''}${rewindLine}${resendLine}`, historyMismatch === null ? undefined : toolHistoryMismatchRowKey(historyMismatch, historyRepeat, rewindOffered), resend, arm === 'apiError' ? apiErrorRowBitsOf(historyTerminal) : undefined);
669
699
  }
670
700
  else {
671
701
  const echoedSid = ev.type === 'done' ? engineSessionIdOf(engineResultOf(ev.result)) : undefined;
@@ -673,8 +703,8 @@ async function* runStreamInner(events, ctx, handle = {}) {
673
703
  sessionId: echoedSid ?? ctx.sessionId,
674
704
  sessionEchoed: echoedSid !== undefined,
675
705
  generation: historyGeneration,
676
- runId: ev.type === 'done' ? engineRunIdOf(engineResultOf(ev.result)) : undefined,
677
- replay: ev.type === 'done' && ev.replay === true,
706
+ runId: terminalRunId,
707
+ replay: replayed,
678
708
  mismatch: null,
679
709
  });
680
710
  }
@@ -707,8 +737,9 @@ async function* runStreamInner(events, ctx, handle = {}) {
707
737
  if (outcome === 'unknown') {
708
738
  const errs = resultFrame.errors;
709
739
  const sentence = Array.isArray(errs) && typeof errs[0] === 'string' ? errs[0] : 'the run ended without a terminal record this client can read';
710
- yield syntheticTerminalRow(ctx, `${OUTCOME_UNKNOWN_ROW_PREFIX}: ${sentence}`);
740
+ yield syntheticTerminalRow(ctx, { runId: terminalRunId, label: 'outcome-unknown' }, replayed, `${OUTCOME_UNKNOWN_ROW_PREFIX}: ${sentence}`);
711
741
  }
742
+ yield terminalFactOf(ev, doneTerminal);
712
743
  yield resultFrame;
713
744
  return;
714
745
  }
@@ -1,11 +1,10 @@
1
- import type { AgentEvent } from '@sema-agent/sdk';
1
+ import type { AgentEvent, StampedAgentEvent } from '@sema-agent/sdk';
2
2
  import type { ModelUsage, SDKMessage } from '@sema-agent/agent-types';
3
3
  import type { ChromeEvent } from '../seam.js';
4
4
  import type { RequestLane } from '../request/taskRequest.js';
5
+ import type { EngineBoundRun } from '../engineRowRef.js';
5
6
  export type { ModelUsage, SDKMessage };
6
- export type StampedAgentEvent = AgentEvent & {
7
- id?: string;
8
- };
7
+ export type { StampedAgentEvent };
9
8
  export declare function eventSeq(ev: AgentEvent): string | undefined;
10
9
  export declare function uuid(): string;
11
10
  export interface DroppedFrameInfo {
@@ -23,6 +22,7 @@ export interface EmitContext {
23
22
  };
24
23
  emitChrome?(event: ChromeEvent): void | Promise<void>;
25
24
  onDroppedFrame?(info: DroppedFrameInfo): void;
25
+ boundRun?(frame: AgentEvent): EngineBoundRun | undefined;
26
26
  }
27
27
  export declare function stamp<T extends {
28
28
  uuid?: string | undefined;
@@ -1,5 +1,6 @@
1
1
  export function eventSeq(ev) {
2
- return ev.id;
2
+ const id = ev.id;
3
+ return typeof id === 'string' && id.length > 0 ? id : undefined;
3
4
  }
4
5
  export function uuid() {
5
6
  const g = typeof globalThis !== 'undefined' ? globalThis.crypto : undefined;
@@ -1,4 +1,5 @@
1
1
  import { abortableSleep } from '../abortableSleep.js';
2
+ import { isAssistantLaneAbsent } from '../assistantInbox.js';
2
3
  import { errCodes } from '../controlRouter.js';
3
4
  import { engineWireDebugEnabled } from '../engineWireTarget.js';
4
5
  import { hostLog } from '../host.js';
@@ -145,7 +146,7 @@ export function createBackgroundView(client, opts) {
145
146
  }
146
147
  catch (err) {
147
148
  debugLog(`assistant.tasks degrade: ${String(err)}`);
148
- const health = isNotImplemented(err)
149
+ const health = isAssistantLaneAbsent(err)
149
150
  ? 'not-configured'
150
151
  : isReadCredentialRefusal(err)
151
152
  ? 'unauthorized'
@@ -1,4 +1,4 @@
1
- import type { AgentClient, Capabilities } from '@sema-agent/sdk';
1
+ import type { AgentClient } from '@sema-agent/sdk';
2
2
  import type { EngineAgentRegistryListing, EngineAgentRegistryRowView } from '../engineAgentAbsence.js';
3
3
  export interface EngineAgentRegistryClient {
4
4
  readonly sessions: Pick<AgentClient['sessions'], 'background'>;
@@ -13,6 +13,6 @@ export interface RegistryListingProvenance {
13
13
  }
14
14
  export declare function registryListingProvenanceOf(listing: EngineAgentRegistryListing | null | undefined): RegistryListingProvenance | undefined;
15
15
  export declare function isEngineAgentRegistryListingSuperseded(listing: EngineAgentRegistryListing | null | undefined): boolean;
16
- export declare function readEngineAgentRegistry(client: EngineAgentRegistryClient, sessionId: string, caps: Pick<Capabilities, 'background'> | null | undefined, opts?: {
16
+ export declare function readEngineAgentRegistry(client: EngineAgentRegistryClient, sessionId: string, capsBaseUrl: string | undefined, opts?: {
17
17
  readonly signal?: AbortSignal;
18
18
  }): Promise<EngineAgentRegistryListing>;