@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
@@ -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';
8
+ import { contextUsageReadingOf, markMcpSectionDroppedNamedRows, readFrameTrueMark } from '../../ownKey.js';
9
9
  import { SEGMENT_END_IDENTITY_KEYS, 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,6 +24,7 @@ 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',
28
30
  'task_notification',
@@ -69,7 +71,22 @@ const dropped = (why, type) => ({ kind: 'dropped', why, type });
69
71
  function assertNeverArm(_ev) {
70
72
  }
71
73
  export function eventToSdkMessage(ev, ctx) {
74
+ return withEngineIdentity(projectEvent(ev, ctx), ev, ctx);
75
+ }
76
+ function withEngineIdentity(p, ev, ctx) {
77
+ if (p.kind !== 'message')
78
+ return p;
79
+ const eventId = wireEventIdOf(ev);
80
+ if (eventId === undefined)
81
+ return p;
82
+ const env = p.message;
83
+ const ref = mintEngineRowRef(eventId, ctx.boundRun === undefined ? undefined : readBoundRun(() => ctx.boundRun?.(ev)));
84
+ return projected(Object.assign({}, env, { uuid: envelopeUuidOf(eventId, env.type), _sema_engine_ref: ref }));
85
+ }
86
+ function projectEvent(ev, ctx) {
72
87
  switch (ev.type) {
88
+ case 'task_started':
89
+ return dropped('unsupported_arm', 'task_started');
73
90
  case 'text_end':
74
91
  return textEndProjection(ev, ctx);
75
92
  case 'reasoning_end':
@@ -178,7 +195,6 @@ export function eventToSdkMessage(ev, ctx) {
178
195
  const toolEndGatedCallId = ev.gatedCallId;
179
196
  const collateralAbort = ev._sema_collateral_abort;
180
197
  const denialKind = ccToolDenialKindForToolEnd(ev);
181
- const denialUnclassified = denialKind === undefined && toolEndGate?.disposition.kind === 'denied';
182
198
  const toolEndNotExecuted = readFrameTrueMark(ev, 'notExecuted');
183
199
  return projected(stamp(ctx, armBody({
184
200
  type: 'tool_end_result',
@@ -201,7 +217,6 @@ export function eventToSdkMessage(ev, ctx) {
201
217
  : {}),
202
218
  ...(collateralAbort === true ? { _sema_collateral_abort: true } : {}),
203
219
  ...(denialKind !== undefined ? { _sema_denial_kind: denialKind } : {}),
204
- ...(denialUnclassified ? { _sema_denial_unclassified: true } : {}),
205
220
  ...(toolEndNotExecuted ? { notExecuted: true } : {}),
206
221
  ...(ev.eventId !== undefined ? { eventId: ev.eventId } : {}),
207
222
  ...(ev.parentToolCallId !== undefined
@@ -210,19 +225,18 @@ export function eventToSdkMessage(ev, ctx) {
210
225
  })));
211
226
  }
212
227
  case 'status': {
213
- const st2 = ev;
214
228
  const num = (v) => typeof v === 'number' && Number.isFinite(v) ? v : undefined;
215
229
  const attempt = num(ev.attempt);
216
230
  const maxRetries = num(ev.maxRetries);
217
231
  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);
232
+ const retryAtMs = num(ev.retryAtMs);
233
+ const errorStatus = num(ev.errorStatus);
234
+ const elapsedMs = num(ev.elapsedMs);
235
+ const timeoutMs = num(ev.timeoutMs);
222
236
  const errClass = typeof ev.errClass === 'string' && ev.errClass.length > 0 ? ev.errClass : undefined;
223
237
  const nonEmptyStr = (v) => (typeof v === 'string' && v.length > 0 ? v : undefined);
224
- const providerCondition = nonEmptyStr(st2.providerCondition);
225
- const providerConditionSource = nonEmptyStr(st2.providerConditionSource);
238
+ const providerCondition = nonEmptyStr(ev.providerCondition);
239
+ const providerConditionSource = nonEmptyStr(ev.providerConditionSource);
226
240
  return projected(stamp(ctx, armBody({
227
241
  type: 'retry_status',
228
242
  phase: ev.phase,
@@ -648,33 +662,12 @@ function contextUsageProjection(ev, ctx) {
648
662
  const { identity, bad } = identityOrMalformed(ev, 'context_usage');
649
663
  if (bad !== null)
650
664
  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)
665
+ const reading = contextUsageReadingOf(ev);
666
+ if (reading === undefined)
671
667
  return nothing('empty_payload');
672
668
  return projected(internalArmExit(stamp(ctx, armBody({
673
669
  type: 'context_usage',
674
- ...(usedTokens !== undefined ? { usedTokens } : {}),
675
- ...(windowTokens !== undefined ? { windowTokens } : {}),
676
- ...(compactAtTokens !== undefined ? { compactAtTokens } : {}),
677
- ...(sections !== undefined ? { sections } : {}),
670
+ ...reading,
678
671
  ...identity,
679
672
  }))));
680
673
  }
@@ -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,13 +2,16 @@ 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 { terminalRunIdOf, terminalUuidOf } from '../engineRowRef.js';
5
6
  import { coerceOutput, publishSubagentContentEvent } 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
16
  import { washCredentials } from '../displayUntrusted.js';
14
17
  import { PROMPT_BLOCKED_BY_HOOK_ROW_LEAD, runBlockedText } from '../promptBlockedCopy.js';
@@ -108,9 +111,9 @@ export function isModelOutputErrorRowText(text) {
108
111
  return text.trimStart().startsWith(`${MODEL_OUTPUT_ERROR_PREFIX}:`);
109
112
  }
110
113
  export const OUTCOME_UNKNOWN_ROW_PREFIX = 'Outcome unknown';
111
- function syntheticTerminalRow(ctx, text, historyKey, resend) {
114
+ function syntheticTerminalRow(ctx, identity, replayed, text, historyKey, resend) {
112
115
  return stamp(ctx, {
113
- uuid: undefined,
116
+ uuid: identity.runId === undefined ? undefined : terminalUuidOf(identity.runId, identity.label),
114
117
  session_id: undefined,
115
118
  type: 'assistant',
116
119
  message: { role: 'assistant', model: '<synthetic>', content: [{ type: 'text', text: washCredentials(text) }] },
@@ -118,12 +121,9 @@ function syntheticTerminalRow(ctx, text, historyKey, resend) {
118
121
  _sema_api_error_message: true,
119
122
  ...(historyKey !== undefined ? { _sema_tool_history_mismatch: historyKey } : {}),
120
123
  ...(resend !== undefined ? { _sema_provider_rejection_resend: { resend: resend.resend, text: resend.text, kind: resend.kind } } : {}),
124
+ ...(replayed ? { _sema_replay: true } : {}),
121
125
  });
122
126
  }
123
- function engineRunIdOf(result) {
124
- const v = result?.runId;
125
- return typeof v === 'string' && v.length > 0 ? v : undefined;
126
- }
127
127
  function engineResultOf(result) {
128
128
  const v = doneResultView(result);
129
129
  return v.replay ? (v.engine ?? result) : result;
@@ -142,6 +142,19 @@ export function isGovernanceTerminal(input) {
142
142
  return true;
143
143
  return input.errorCode === OUTPUT_INVALID;
144
144
  }
145
+ function terminalFactOf(ev, doneTerminal) {
146
+ const engine = ev.type === 'done' ? engineResultOf(ev.result) : ev;
147
+ const taskId = readFrameStringKey(engine, 'taskId');
148
+ if (ev.type !== 'done' || doneTerminal?.kind !== 'paused')
149
+ return { type: 'terminal_fact', ...(taskId !== undefined ? { taskId } : {}) };
150
+ const checkpointId = doneTerminal.checkpointId;
151
+ const heldCallId = parkHeldCallIdOf(engine);
152
+ return {
153
+ type: 'terminal_fact',
154
+ ...(taskId !== undefined ? { taskId } : {}),
155
+ paused: { ...(checkpointId !== undefined ? { checkpointId } : {}), ...(heldCallId !== undefined ? { heldCallId } : {}) },
156
+ };
157
+ }
145
158
  function terminalRowFacts(ev) {
146
159
  const doneTerminal = ev.type === 'done' ? readRunTerminal(ev.result) : null;
147
160
  const errTextRaw = ev.type === 'failed'
@@ -625,6 +638,8 @@ async function* runStreamInner(events, ctx, handle = {}) {
625
638
  if (ev.type === 'done' || ev.type === 'failed') {
626
639
  const rowFacts = terminalRowFacts(ev);
627
640
  const doneTerminal = rowFacts.doneTerminal;
641
+ const terminalRunId = terminalRunIdOf(ev);
642
+ const replayed = isReplayedTerminal(ev);
628
643
  const errText = rowFacts.errText;
629
644
  if (errText) {
630
645
  const busy = rowFacts.busy;
@@ -655,8 +670,8 @@ async function* runStreamInner(events, ctx, handle = {}) {
655
670
  sessionId: historyEchoedSid ?? ctx.sessionId,
656
671
  sessionEchoed: historyEchoedSid !== undefined,
657
672
  generation: historyGeneration,
658
- runId: ev.type === 'done' ? engineRunIdOf(engineResultOf(ev.result)) : undefined,
659
- replay: ev.type === 'done' && ev.replay === true,
673
+ runId: terminalRunId,
674
+ replay: replayed,
660
675
  mismatch: historyMismatch,
661
676
  });
662
677
  const rewindOffered = historyMismatch !== null && ctx.lane !== 'print' && ctx.lane !== 'utility' && toolHistoryRewindOffered(ctx.offersRewind);
@@ -665,7 +680,7 @@ async function* runStreamInner(events, ctx, handle = {}) {
665
680
  : '';
666
681
  const resend = historyTerminal.detail !== undefined ? providerRejectionResend(historyTerminal.detail, historyTerminal.carrier) : undefined;
667
682
  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);
683
+ 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);
669
684
  }
670
685
  else {
671
686
  const echoedSid = ev.type === 'done' ? engineSessionIdOf(engineResultOf(ev.result)) : undefined;
@@ -673,8 +688,8 @@ async function* runStreamInner(events, ctx, handle = {}) {
673
688
  sessionId: echoedSid ?? ctx.sessionId,
674
689
  sessionEchoed: echoedSid !== undefined,
675
690
  generation: historyGeneration,
676
- runId: ev.type === 'done' ? engineRunIdOf(engineResultOf(ev.result)) : undefined,
677
- replay: ev.type === 'done' && ev.replay === true,
691
+ runId: terminalRunId,
692
+ replay: replayed,
678
693
  mismatch: null,
679
694
  });
680
695
  }
@@ -707,8 +722,9 @@ async function* runStreamInner(events, ctx, handle = {}) {
707
722
  if (outcome === 'unknown') {
708
723
  const errs = resultFrame.errors;
709
724
  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}`);
725
+ yield syntheticTerminalRow(ctx, { runId: terminalRunId, label: 'outcome-unknown' }, replayed, `${OUTCOME_UNKNOWN_ROW_PREFIX}: ${sentence}`);
711
726
  }
727
+ yield terminalFactOf(ev, doneTerminal);
712
728
  yield resultFrame;
713
729
  return;
714
730
  }
@@ -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,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>;
@@ -1,7 +1,7 @@
1
1
  import { errCodes } from '../controlRouter.js';
2
2
  import { hostLog } from '../host.js';
3
3
  import { isSessionIdPathSegment } from '../sessionIdSegment.js';
4
- import { ownDataField } from '../ownKey.js';
4
+ import { engineCapNestedValue } from '../engineCapsCache.js';
5
5
  const unavailable = (why) => ({
6
6
  kind: 'unavailable',
7
7
  why,
@@ -58,13 +58,11 @@ export function registryListingProvenanceOf(listing) {
58
58
  export function isEngineAgentRegistryListingSuperseded(listing) {
59
59
  return registryListingProvenanceOf(listing)?.superseded === true;
60
60
  }
61
- function listFaceOn(caps) {
62
- if (typeof caps !== 'object' || caps === null)
63
- return false;
64
- const bg = ownDataField(caps, 'background');
65
- if (typeof bg !== 'object' || bg === null)
66
- return false;
67
- return ownDataField(bg, 'listFace') === true;
61
+ function listFaceGate(capsBaseUrl) {
62
+ const v = engineCapNestedValue(typeof capsBaseUrl === 'string' ? capsBaseUrl : undefined, 'background', 'listFace');
63
+ if (v.kind === 'unobserved' || v.kind === 'unreadable')
64
+ return 'capability_unknown';
65
+ return v.kind === 'value' && v.value === true ? null : 'no_list_face';
68
66
  }
69
67
  function readRow(v) {
70
68
  if (typeof v !== 'object' || v === null || Array.isArray(v))
@@ -85,18 +83,19 @@ function readRow(v) {
85
83
  ...(typeof createdAt === 'number' && Number.isFinite(createdAt) ? { createdAt } : {}),
86
84
  };
87
85
  }
88
- export async function readEngineAgentRegistry(client, sessionId, caps, opts) {
86
+ export async function readEngineAgentRegistry(client, sessionId, capsBaseUrl, opts) {
89
87
  try {
90
- return await readOnce(client, sessionId, caps, opts);
88
+ return await readOnce(client, sessionId, capsBaseUrl, opts);
91
89
  }
92
90
  catch {
93
91
  noteReadFailed('reader threw');
94
92
  return unavailable('read_failed');
95
93
  }
96
94
  }
97
- async function readOnce(client, sessionId, caps, opts) {
98
- if (!listFaceOn(caps))
99
- return unavailable('no_list_face');
95
+ async function readOnce(client, sessionId, capsBaseUrl, opts) {
96
+ const gate = listFaceGate(capsBaseUrl);
97
+ if (gate !== null)
98
+ return unavailable(gate);
100
99
  if (!isSessionIdPathSegment(sessionId)) {
101
100
  noteReadFailed('bad session id');
102
101
  return unavailable('read_failed');
@@ -1,14 +1,11 @@
1
1
  import { type EngineProbeOpts, type WireAuthTokenSource } from './engineWireSdk.js';
2
2
  import type { ReasoningEffort } from './effortWire.js';
3
3
  import type { ToolRosterView } from './toolRoster.js';
4
+ import { type AssemblyRefusal } from './wireFailureShape.js';
4
5
  export declare const MAX_TASK_AGENTS = 32;
5
- export declare const MAX_AGENT_NAME_CHARS = 64;
6
6
  export declare const MAX_AGENT_TEXT_CHARS = 4096;
7
7
  export declare const MAX_AGENT_SYSTEM_PROMPT_CHARS = 65536;
8
- export declare const MAX_AGENT_TOOLS = 64;
9
- export declare const MAX_AGENT_TOOL_NAME_CHARS = 128;
10
8
  export declare const MAX_AGENT_SKILL_CONTENT_CHARS = 1048576;
11
- export declare const MAX_AGENT_MAX_TURNS = 1000;
12
9
  export declare const TASK_AGENT_WIRE_FIELDS: readonly ["name", "whenToUse", "whenToUseLean", "allowTools", "denyTools", "skills", "background", "isolation", "model", "thinking", "systemPrompt", "maxTurns", "memory", "observer", "observerMessage"];
13
10
  export type WireThinkingLevel = ReasoningEffort;
14
11
  export type TaskAgentWireSkill = {
@@ -60,7 +57,6 @@ export type ProjectAgentsDeps = {
60
57
  effortToThinking: (effort: unknown) => WireThinkingLevel | undefined;
61
58
  skillSpecs?: TaskAgentWireSkill[];
62
59
  toolRoster?: ToolRosterView | null;
63
- withholdRefusedDenyLists?: boolean;
64
60
  agentSourceLabel?: (agentName: string) => string | undefined;
65
61
  };
66
62
  export type ProjectAgentsResult = {
@@ -76,6 +72,7 @@ export interface AgentToolListFlaw {
76
72
  readonly kind: AgentToolListFlawKind;
77
73
  readonly currentName?: string;
78
74
  readonly toolName?: string;
75
+ readonly rewritten?: true;
79
76
  }
80
77
  export declare function agentToolListFlaws(agents: readonly TaskAgentWireItem[] | undefined, roster?: ToolRosterView | null): AgentToolListFlaw[];
81
78
  export declare function projectAgentsForWire(defs: readonly AgentDefLike[], deps: ProjectAgentsDeps): ProjectAgentsResult;
@@ -88,7 +85,12 @@ export type WireConfig = {
88
85
  export type ProjectorFn = () => Promise<ProjectAgentsResult>;
89
86
  export declare function prepareTaskAgentsWireWith(cfg: WireConfig, projector: ProjectorFn): Promise<void>;
90
87
  export declare function invalidateTaskAgentsWire(): Promise<void>;
91
- export declare function awaitTaskAgentsWire(timeoutMs?: number): Promise<void>;
88
+ export declare function awaitTaskAgentsWire(timeoutMs?: number): Promise<{
89
+ readonly ok: true;
90
+ } | {
91
+ readonly ok: false;
92
+ readonly refusal: AssemblyRefusal;
93
+ }>;
92
94
  export declare function taskAgentsField(): {
93
95
  agents?: TaskAgentWireItem[];
94
96
  };