@sema-agent/client-core 0.100.0 → 0.102.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 (358) hide show
  1. package/CHANGELOG.md +452 -0
  2. package/README.md +172 -120
  3. package/dist/adapt/arms.js +51 -16
  4. package/dist/adapt/textStream.js +7 -4
  5. package/dist/adapt/toolCards.d.ts +2 -1
  6. package/dist/adapt/toolCards.js +28 -13
  7. package/dist/adapt.d.ts +1 -1
  8. package/dist/adapt.js +8 -2
  9. package/dist/adapter/activeRunSelfHeal.d.ts +24 -2
  10. package/dist/adapter/activeRunSelfHeal.js +108 -6
  11. package/dist/adapter/downstream/eventToSdkMessage.js +38 -79
  12. package/dist/adapter/downstream/terminalToSdkResult.d.ts +60 -1
  13. package/dist/adapter/downstream/terminalToSdkResult.js +209 -39
  14. package/dist/adapter/downstream/wiringManifestView.d.ts +1 -0
  15. package/dist/adapter/downstream/wiringManifestView.js +138 -0
  16. package/dist/adapter/runStream.d.ts +4 -4
  17. package/dist/adapter/runStream.js +158 -43
  18. package/dist/agentsWireCaps.d.ts +2 -7
  19. package/dist/agentsWireCaps.js +1 -2
  20. package/dist/approvalDecidedByCapability.js +2 -2
  21. package/dist/approvalFrameFamilies.d.ts +33 -0
  22. package/dist/approvalFrameFamilies.js +120 -0
  23. package/dist/approvalsStreamLiveCapability.js +2 -2
  24. package/dist/attachmentsWireCaps.js +41 -13
  25. package/dist/callerCwdCapability.js +2 -2
  26. package/dist/centerWiringCapability.js +2 -2
  27. package/dist/clockReading.d.ts +2 -0
  28. package/dist/clockReading.js +4 -0
  29. package/dist/cloudConfigWireCaps.d.ts +19 -5
  30. package/dist/cloudConfigWireCaps.js +193 -56
  31. package/dist/compensations.js +1 -1
  32. package/dist/coreValuePorts.d.ts +12 -2
  33. package/dist/coreValuePorts.js +9 -0
  34. package/dist/decideFailureNote.js +5 -3
  35. package/dist/decideReceipt.js +2 -2
  36. package/dist/deviceExecutorManagementCapability.js +2 -2
  37. package/dist/deviceFlowPolling.js +1 -1
  38. package/dist/disableSkillsWire.d.ts +1 -1
  39. package/dist/disableSkillsWire.js +4 -3
  40. package/dist/displayUntrusted.d.ts +9 -4
  41. package/dist/displayUntrusted.js +834 -104
  42. package/dist/engineCapReader.js +1 -1
  43. package/dist/engineConfigDrift.js +1 -1
  44. package/dist/engineErrorCodes.d.ts +14 -5
  45. package/dist/engineErrorCodes.js +27 -6
  46. package/dist/engineGenerationConvergence.d.ts +39 -0
  47. package/dist/engineGenerationConvergence.js +95 -0
  48. package/dist/engineGenerationPort.d.ts +61 -0
  49. package/dist/engineGenerationPort.js +144 -0
  50. package/dist/engineHealthFacts.d.ts +23 -0
  51. package/dist/engineHealthFacts.js +92 -0
  52. package/dist/engineIdentity.d.ts +4 -0
  53. package/dist/engineIdentity.js +11 -0
  54. package/dist/engineNoticeCodes.d.ts +2 -5
  55. package/dist/engineRowRef.js +4 -0
  56. package/dist/engineSessionMessages.js +2 -2
  57. package/dist/engineToolDirectory.js +2 -2
  58. package/dist/engineWireFor.d.ts +99 -0
  59. package/dist/engineWireFor.js +248 -6
  60. package/dist/engineWireTarget.d.ts +1 -0
  61. package/dist/engineWireTarget.js +8 -0
  62. package/dist/env/uiLanguage.js +1 -1
  63. package/dist/errorSupplementRoles.d.ts +3 -0
  64. package/dist/errorSupplementRoles.js +37 -0
  65. package/dist/executionLaneCapability.js +2 -2
  66. package/dist/fileHistoryCaptureCapability.js +3 -3
  67. package/dist/finalVerifyWire.d.ts +6 -3
  68. package/dist/finalVerifyWire.js +6 -23
  69. package/dist/flagInput.d.ts +4 -0
  70. package/dist/flagInput.js +24 -0
  71. package/dist/fleet/fleetLedger.js +5 -2
  72. package/dist/fleet/fleetProjection.d.ts +1 -0
  73. package/dist/fleet/fleetProjection.js +16 -3
  74. package/dist/gateVocabulary.js +3 -0
  75. package/dist/generated/engineFactTables.d.ts +7 -3
  76. package/dist/generated/engineFactTables.js +52 -0
  77. package/dist/generated/engineNoticeTables.js +12 -0
  78. package/dist/generated/settingsSchemaActiveTiers.d.ts +1 -0
  79. package/dist/generated/settingsSchemaActiveTiers.js +14 -0
  80. package/dist/generated/settingsSchemaCallerTextEcho.d.ts +1 -0
  81. package/dist/generated/settingsSchemaCallerTextEcho.js +8 -0
  82. package/dist/generated/settingsSchemaControlAndBidi.d.ts +1 -0
  83. package/dist/generated/settingsSchemaControlAndBidi.js +8 -0
  84. package/dist/generated/settingsSchemaDefaultModel.d.ts +11 -0
  85. package/dist/generated/settingsSchemaDefaultModel.js +25 -0
  86. package/dist/generated/settingsSchemaFns.d.ts +54 -0
  87. package/dist/generated/settingsSchemaFns.js +26 -1
  88. package/dist/generated/settingsSchemaMcpRequestEntry.d.ts +1 -1
  89. package/dist/generated/settingsSchemaMcpRequestEntry.js +1 -7
  90. package/dist/generated/settingsSchemaSafetyMergeSpec.d.ts +1 -0
  91. package/dist/generated/settingsSchemaSafetyMergeSpec.js +95 -0
  92. package/dist/generated/settingsSchemaSettingsSources.d.ts +1 -0
  93. package/dist/generated/settingsSchemaSettingsSources.js +58 -0
  94. package/dist/generated/settingsSchemaTables.d.ts +2 -0
  95. package/dist/generated/settingsSchemaTables.js +13 -0
  96. package/dist/generated/settingsSchemaUrlPattern.d.ts +1 -0
  97. package/dist/generated/settingsSchemaUrlPattern.js +183 -0
  98. package/dist/headlessPermissionModeWire.d.ts +18 -2
  99. package/dist/headlessPermissionModeWire.js +30 -19
  100. package/dist/hitl/allowRuleShadow.js +7 -5
  101. package/dist/hitl/approvalCardReading.d.ts +3 -0
  102. package/dist/hitl/approvalCardReading.js +17 -0
  103. package/dist/hitl/approvalCompleteParked.js +1 -1
  104. package/dist/hitl/approvalDelivery.d.ts +87 -0
  105. package/dist/hitl/approvalDelivery.js +193 -0
  106. package/dist/hitl/approvalResolution.d.ts +11 -0
  107. package/dist/hitl/approvalResolution.js +50 -11
  108. package/dist/hitl/askClassPair.d.ts +6 -0
  109. package/dist/hitl/askClassPair.js +30 -3
  110. package/dist/hitl/askParkAutoReopenBlock.d.ts +30 -0
  111. package/dist/hitl/askParkAutoReopenBlock.js +117 -0
  112. package/dist/hitl/askParkRowRouting.js +4 -1
  113. package/dist/hitl/attributionLadder.d.ts +42 -3
  114. package/dist/hitl/attributionLadder.js +79 -8
  115. package/dist/hitl/automaticAnswerVerdict.d.ts +6 -1
  116. package/dist/hitl/automaticAnswerVerdict.js +46 -11
  117. package/dist/hitl/crashConverged.js +2 -2
  118. package/dist/hitl/decisionConflict.d.ts +6 -2
  119. package/dist/hitl/decisionConflict.js +24 -9
  120. package/dist/hitl/decisionRefusal.d.ts +20 -10
  121. package/dist/hitl/decisionRefusal.js +99 -54
  122. package/dist/hitl/decisionSend.d.ts +3 -0
  123. package/dist/hitl/decisionSend.js +87 -103
  124. package/dist/hitl/frameRouter.d.ts +1 -0
  125. package/dist/hitl/frameRouter.js +9 -2
  126. package/dist/hitl/hitlBridge.d.ts +18 -6
  127. package/dist/hitl/hitlBridge.js +41 -37
  128. package/dist/hitl/livePendingAsk.js +4 -3
  129. package/dist/hitl/noAllowCause.js +1 -1
  130. package/dist/hitl/parkResolver.js +3 -2
  131. package/dist/hitl/persistedRulesWire.js +1 -0
  132. package/dist/hitl/planReviewWire.d.ts +4 -0
  133. package/dist/hitl/planReviewWire.js +59 -30
  134. package/dist/hitl/resumeRunningCard.d.ts +3 -2
  135. package/dist/hitl/resumeRunningCard.js +17 -11
  136. package/dist/hitl/sessionPolicyDeliverable.d.ts +5 -2
  137. package/dist/hitl/sessionPolicyDeliverable.js +62 -29
  138. package/dist/hitl/sessionPolicyWire.d.ts +13 -3
  139. package/dist/hitl/sessionPolicyWire.js +81 -16
  140. package/dist/hitl/standingRows.js +1 -1
  141. package/dist/hitl/toolApprovalWire.d.ts +9 -10
  142. package/dist/hitl/toolApprovalWire.js +72 -54
  143. package/dist/hookMatcherVerdict.d.ts +2 -0
  144. package/dist/hookMatcherVerdict.js +12 -0
  145. package/dist/hooksCompactTransition.d.ts +19 -0
  146. package/dist/hooksCompactTransition.js +41 -0
  147. package/dist/hooksWireCaps.d.ts +1 -1
  148. package/dist/hooksWireCaps.js +202 -203
  149. package/dist/host.d.ts +1 -14
  150. package/dist/host.js +0 -8
  151. package/dist/hostCallbackGuard.d.ts +1 -0
  152. package/dist/hostCallbackGuard.js +1 -1
  153. package/dist/hostSettingsSource.d.ts +172 -0
  154. package/dist/hostSettingsSource.js +675 -0
  155. package/dist/hostTurnSettings.d.ts +73 -17
  156. package/dist/hostTurnSettings.js +594 -97
  157. package/dist/httpHookPolicy.d.ts +37 -0
  158. package/dist/httpHookPolicy.js +176 -0
  159. package/dist/humanTurn.d.ts +2 -1
  160. package/dist/humanTurn.js +37 -7
  161. package/dist/humanTurnRead.js +4 -3
  162. package/dist/humanTurnSentences.d.ts +10 -0
  163. package/dist/humanTurnSentences.js +74 -0
  164. package/dist/i18n/messages.en.d.ts +222 -2
  165. package/dist/i18n/messages.en.js +225 -5
  166. package/dist/i18n/messages.zh.js +237 -5
  167. package/dist/i18n/translate.js +3 -3
  168. package/dist/index.d.ts +77 -15
  169. package/dist/index.js +50 -13
  170. package/dist/inheritEnvCapability.d.ts +3 -1
  171. package/dist/inheritEnvCapability.js +31 -17
  172. package/dist/inheritEnvWire.d.ts +2 -1
  173. package/dist/inheritEnvWire.js +11 -5
  174. package/dist/interactiveHalt.d.ts +3 -1
  175. package/dist/interactiveHalt.js +2 -0
  176. package/dist/interactiveInterrupt.d.ts +2 -0
  177. package/dist/interactiveInterrupt.js +15 -0
  178. package/dist/interactiveToolsWire.d.ts +4 -2
  179. package/dist/interactiveToolsWire.js +5 -5
  180. package/dist/jsonFaithful.d.ts +20 -0
  181. package/dist/jsonFaithful.js +152 -0
  182. package/dist/limitsWire.d.ts +7 -2
  183. package/dist/limitsWire.js +19 -13
  184. package/dist/liveInitToolFace.d.ts +6 -1
  185. package/dist/liveInitToolFace.js +5 -3
  186. package/dist/liveModelCatalog.d.ts +22 -0
  187. package/dist/liveModelCatalog.js +132 -18
  188. package/dist/mcpPanel.js +1 -1
  189. package/dist/mcpProbeCapability.js +2 -2
  190. package/dist/mcpStatusSupersetKeys.d.ts +24 -0
  191. package/dist/mcpStatusSupersetKeys.js +45 -0
  192. package/dist/mcpToolToggles.js +2 -1
  193. package/dist/mcpWireCaps.d.ts +39 -1
  194. package/dist/mcpWireCaps.js +254 -50
  195. package/dist/memoryComplianceCapability.js +2 -2
  196. package/dist/memoryOriginCapability.js +2 -2
  197. package/dist/model/catalogDefault.d.ts +24 -0
  198. package/dist/model/catalogDefault.js +4 -0
  199. package/dist/model/liveCatalogShape.js +5 -4
  200. package/dist/model/modelsPolicy.js +4 -3
  201. package/dist/model/onboardJudgement.d.ts +1 -0
  202. package/dist/model/onboardJudgement.js +1 -1
  203. package/dist/model/subagentModelWord.js +2 -2
  204. package/dist/modelCapabilityProbe.js +6 -6
  205. package/dist/modelIdentityResolvability.d.ts +10 -1
  206. package/dist/modelIdentityResolvability.js +62 -39
  207. package/dist/modsFace.d.ts +8 -0
  208. package/dist/modsFace.js +59 -0
  209. package/dist/modsKernelIdentity.d.ts +10 -0
  210. package/dist/modsKernelIdentity.js +103 -0
  211. package/dist/modsKernelTransit.d.ts +8 -0
  212. package/dist/modsKernelTransit.js +6 -0
  213. package/dist/notifications.d.ts +30 -12
  214. package/dist/notifications.js +241 -53
  215. package/dist/outputStyleSeatCapability.js +2 -2
  216. package/dist/ownKey.d.ts +12 -0
  217. package/dist/ownKey.js +179 -3
  218. package/dist/panelReduce.js +1 -1
  219. package/dist/peerFrames.d.ts +1 -1
  220. package/dist/peerFrames.js +6 -2
  221. package/dist/peerLaneCapability.js +2 -2
  222. package/dist/permissionModesCapability.js +4 -4
  223. package/dist/permissionRuleIssue.js +2 -0
  224. package/dist/permissionRulesWriteCapability.js +2 -2
  225. package/dist/permissionsAllowGrantCapability.js +2 -2
  226. package/dist/permissionsDeclaration.d.ts +43 -4
  227. package/dist/permissionsDeclaration.js +102 -35
  228. package/dist/pluginHooksWire.d.ts +20 -4
  229. package/dist/pluginHooksWire.js +92 -53
  230. package/dist/prepareRefusal.d.ts +3 -2
  231. package/dist/prepareRefusal.js +27 -9
  232. package/dist/printInitToolFace.js +2 -2
  233. package/dist/printModelStatus.js +1 -1
  234. package/dist/printToolResultFrame.js +1 -1
  235. package/dist/projectMemory.d.ts +32 -0
  236. package/dist/projectMemory.js +70 -0
  237. package/dist/promptBlockedCopy.d.ts +2 -1
  238. package/dist/promptBlockedCopy.js +2 -1
  239. package/dist/promptDelivery.d.ts +23 -3
  240. package/dist/promptDelivery.js +169 -30
  241. package/dist/providerRejection.d.ts +19 -1
  242. package/dist/providerRejection.js +75 -4
  243. package/dist/queuedDelivery.d.ts +48 -0
  244. package/dist/queuedDelivery.js +233 -0
  245. package/dist/reattachWindow.d.ts +94 -0
  246. package/dist/reattachWindow.js +127 -0
  247. package/dist/request/printNotification.d.ts +1 -1
  248. package/dist/request/printNotification.js +6 -2
  249. package/dist/request/submissionIdentity.d.ts +37 -0
  250. package/dist/request/submissionIdentity.js +65 -0
  251. package/dist/request/taskRequest.d.ts +33 -4
  252. package/dist/request/taskRequest.js +341 -156
  253. package/dist/resultFrameKeys.d.ts +1 -0
  254. package/dist/resultFrameKeys.js +4 -1
  255. package/dist/retryStatus.d.ts +8 -0
  256. package/dist/retryStatus.js +57 -9
  257. package/dist/rewindArchiveCapability.js +2 -2
  258. package/dist/rewindEngineAction.d.ts +2 -0
  259. package/dist/rewindEngineAction.js +23 -1
  260. package/dist/rowKind.d.ts +36 -0
  261. package/dist/rowKind.js +97 -0
  262. package/dist/ruleCompileVerdict.d.ts +18 -0
  263. package/dist/ruleCompileVerdict.js +67 -2
  264. package/dist/ruleReadings.d.ts +58 -0
  265. package/dist/ruleReadings.js +132 -0
  266. package/dist/ruleRefusalSentence.d.ts +4 -0
  267. package/dist/ruleRefusalSentence.js +9 -3
  268. package/dist/runCancelContext.d.ts +0 -1
  269. package/dist/runCancelContext.js +1 -2
  270. package/dist/runTerminal.d.ts +5 -0
  271. package/dist/runTerminal.js +52 -17
  272. package/dist/sandboxWire.d.ts +1 -1
  273. package/dist/sandboxWire.js +4 -6
  274. package/dist/scenarioRefusal.js +1 -1
  275. package/dist/scenarioSkills.d.ts +20 -0
  276. package/dist/scenarioSkills.js +72 -0
  277. package/dist/scenarioWire.d.ts +5 -2
  278. package/dist/scenarioWire.js +9 -9
  279. package/dist/sealedKeyCapability.js +2 -2
  280. package/dist/seam.d.ts +2 -0
  281. package/dist/seam.js +3 -3
  282. package/dist/seatContract.d.ts +68 -7
  283. package/dist/seatContract.js +84 -25
  284. package/dist/selfOrchestrationDenial.js +1 -1
  285. package/dist/sessionBackground.d.ts +165 -0
  286. package/dist/sessionBackground.js +781 -0
  287. package/dist/sessionBackgroundHandoff.d.ts +54 -0
  288. package/dist/sessionBackgroundHandoff.js +321 -0
  289. package/dist/sessionMap.js +4 -1
  290. package/dist/sessionPolicyCapability.js +2 -2
  291. package/dist/sessionRulesChildrenReadLive.d.ts +6 -0
  292. package/dist/sessionRulesChildrenReadLive.js +5 -0
  293. package/dist/sessionRulesNamespaceFormsCapability.d.ts +12 -0
  294. package/dist/sessionRulesNamespaceFormsCapability.js +29 -0
  295. package/dist/sessionSyncFileHistoryCapability.js +2 -2
  296. package/dist/settingsCredentialKeyPaths.js +55 -15
  297. package/dist/settingsHooksSalvage.d.ts +1 -0
  298. package/dist/settingsHooksSalvage.js +7 -1
  299. package/dist/settingsLayerAdmission.d.ts +4 -0
  300. package/dist/settingsLayerAdmission.js +16 -0
  301. package/dist/skillToolListsCapability.js +6 -5
  302. package/dist/skillsWireCaps.d.ts +14 -0
  303. package/dist/skillsWireCaps.js +47 -16
  304. package/dist/slashCommandGate.d.ts +24 -0
  305. package/dist/slashCommandGate.js +74 -0
  306. package/dist/slashCommandTable.d.ts +14 -0
  307. package/dist/slashCommandTable.js +99 -0
  308. package/dist/sqlEngineCapability.js +2 -2
  309. package/dist/steerPriorityCapability.js +2 -2
  310. package/dist/storePostureCapability.js +2 -2
  311. package/dist/subagent/agentStateDetail.js +1 -1
  312. package/dist/subagent/engineDelegatedPrompt.d.ts +9 -0
  313. package/dist/subagent/engineDelegatedPrompt.js +38 -7
  314. package/dist/subagent/engineRowStopGate.js +2 -2
  315. package/dist/subagent/engineSubagentResume.js +3 -3
  316. package/dist/subagent/engineTaskHandleWire.d.ts +1 -0
  317. package/dist/subagent/engineTaskHandleWire.js +10 -0
  318. package/dist/submitFailure.d.ts +8 -0
  319. package/dist/submitFailure.js +17 -0
  320. package/dist/supportFloor.d.ts +1 -0
  321. package/dist/supportFloor.js +7 -0
  322. package/dist/terminationIntent.d.ts +55 -0
  323. package/dist/terminationIntent.js +352 -0
  324. package/dist/thinkingLatch.d.ts +69 -0
  325. package/dist/thinkingLatch.js +255 -0
  326. package/dist/thinkingLatchWords.d.ts +7 -0
  327. package/dist/thinkingLatchWords.js +4 -0
  328. package/dist/toolHistoryMismatch.d.ts +8 -0
  329. package/dist/toolHistoryMismatch.js +37 -6
  330. package/dist/toolResult.d.ts +13 -3
  331. package/dist/toolResult.js +159 -32
  332. package/dist/toolResultContent.d.ts +13 -0
  333. package/dist/toolResultContent.js +82 -7
  334. package/dist/toolRoster.d.ts +18 -0
  335. package/dist/toolRoster.js +64 -0
  336. package/dist/turnFailurePresentation.js +27 -90
  337. package/dist/usageLimitAutoResume.d.ts +74 -0
  338. package/dist/usageLimitAutoResume.js +227 -0
  339. package/dist/userAttachmentEnvelope.js +1 -1
  340. package/dist/userAttachmentSeat.js +5 -5
  341. package/dist/userInvokedSkillsCapability.js +2 -2
  342. package/dist/webSearchBackendCapability.js +2 -2
  343. package/dist/wireErrorTriage.js +99 -50
  344. package/dist/wireFailureShape.d.ts +25 -1
  345. package/dist/wireFailureShape.js +92 -5
  346. package/dist/wireRefusalCopy.d.ts +24 -1
  347. package/dist/wireRefusalCopy.js +253 -32
  348. package/dist/wiringFleetDoctor.d.ts +3 -0
  349. package/dist/wiringFleetDoctor.js +21 -0
  350. package/dist/workflow.d.ts +2 -1
  351. package/dist/workflow.js +38 -1
  352. package/dist/workflowClient.d.ts +2 -7
  353. package/dist/workflowsJournalCapability.js +2 -2
  354. package/dist/writeProtectionCapability.js +2 -2
  355. package/docs/INTEGRATION-CLIENTS.md +907 -182
  356. package/package.json +14 -3
  357. package/dist/argvFlagValue.d.ts +0 -8
  358. package/dist/argvFlagValue.js +0 -37
@@ -4,24 +4,181 @@ import { clearEnginePanelTaskResidentByWire, publishEngineAgentPanelEvent, } fro
4
4
  import { panelEndFact } from './panelReduce.js';
5
5
  import { isCoreTaskNotificationTerminal, isCoreTaskNotificationTerminalNotSuccess } from './terminalStatuses.js';
6
6
  import { cycleSeqValue } from './cycleOrder.js';
7
+ import { CORE_ENGINE_AUTHORITY_ENVELOPE_TAGS } from './generated/engineFactTables.js';
8
+ import { guardedRead, ownSnapshot, ownSnapshotRecord, ownSnapshotTyped, readOwnDataValue } from './ownKey.js';
7
9
  function escapeXml(v) {
8
10
  return v.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
9
11
  }
10
- export function renderTaskNotificationXml(n) {
11
- const openTag = n.taskType === 'external' && n.externalSource
12
- ? `<task-notification type="external" from="${escapeXml(n.externalSource.replace(/\s+/g, ' ').slice(0, 120)).replace(/"/g, '&quot;')}">`
13
- : '<task-notification>';
14
- const seg = (tag, v) => (v !== undefined && v.length > 0 ? `\n<${tag}>${escapeXml(v)}</${tag}>` : '');
15
- const linesBlock = n.lines && n.lines.length > 0 ? `\n<output-lines>\n${n.lines.map(escapeXml).join('\n')}\n</output-lines>` : '';
16
- const stepsBlock = n.recentSteps && n.recentSteps.length > 0 ? `\n<recent-steps>${n.recentSteps.map(escapeXml).join('\n')}</recent-steps>` : '';
17
- return `${openTag}
18
- <task-id>${escapeXml(n.taskId)}</task-id>${seg('tool-use-id', n.toolUseId)}${seg('output-file', n.outputFile)}${seg('diagnostics', n.diagnostics)}
19
- <status>${escapeXml(n.status)}</status>${seg('stopped-by', n.stoppedBy)}${n.partial === true ? '\n<partial>true</partial>' : ''}${typeof n.exitCode === 'number' ? `\n<exit-code>${n.exitCode}</exit-code>` : ''}
20
- <summary>${escapeXml(n.summary)}</summary>${seg('result', n.result)}${linesBlock}${stepsBlock}${typeof n.resumable === 'boolean' ? `\n<resumable>${n.resumable}</resumable>` : ''}
21
- </task-notification>`;
22
- }
23
- export function deriveNotificationResidualLines(n) {
12
+ export const CORE_TASK_NOTIFICATION_TAGS = Object.freeze([
13
+ 'task-notification',
14
+ 'task-id',
15
+ 'task-type',
16
+ 'tool-use-id',
17
+ 'status',
18
+ 'summary',
19
+ 'result',
20
+ 'output-file',
21
+ 'usage',
22
+ 'diagnostics',
23
+ 'session-id',
24
+ 'recent-steps',
25
+ 'edited-files',
26
+ 'resumable',
27
+ 'agent-name',
28
+ 'handback',
29
+ 'context',
30
+ ]);
31
+ function breakoutReOf(tags) {
32
+ const alternation = tags.map((t) => t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
33
+ return new RegExp(`<\\s*\\/?\\s*(?:system-reminder|${alternation})(?:\\s[^>]*)?>`, 'gi');
34
+ }
35
+ function neutralizeBreakouts(text, tags) {
36
+ return text.replace(breakoutReOf(tags), (hit) => '&lt;' + hit.slice(1));
37
+ }
38
+ function shownValue(value) {
39
+ if (typeof value === 'string')
40
+ return value;
41
+ try {
42
+ return String(value);
43
+ }
44
+ catch {
45
+ return `[unrenderable ${typeof value}]`;
46
+ }
47
+ }
48
+ function coreTag(name, value) {
49
+ return `<${name}>${escapeXml(neutralizeBreakouts(shownValue(value), CORE_TASK_NOTIFICATION_TAGS))}</${name}>`;
50
+ }
51
+ function attrEscape(value) {
52
+ return value.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
53
+ }
54
+ const EXTERNAL_SOURCE_MAX = 120;
55
+ const INLINE_TRUNCATION_MARK = '…';
56
+ function defuseFenceMarkers(body) {
57
+ return body.replace(/<{3,}|>{3,}/g, (run) => run.replace(/(..)./g, (_g, keep) => keep + (run.startsWith('<') ? '&lt;' : '&gt;')));
58
+ }
59
+ function inlineUntrustedSource(text, maxLen) {
60
+ const oneLine = text.replace(/[\s\u0000-\u001f\u007f-\u009f]+/g, ' ').trim();
61
+ const cps = Array.from(oneLine);
62
+ const capped = cps.length > maxLen ? cps.slice(0, maxLen).join('') + INLINE_TRUNCATION_MARK : oneLine;
63
+ const out = defuseFenceMarkers(neutralizeBreakouts(capped, CORE_ENGINE_AUTHORITY_ENVELOPE_TAGS));
64
+ if (maxLen <= 0)
65
+ return '';
66
+ const outCps = Array.from(out);
67
+ return outCps.length > maxLen + Array.from(INLINE_TRUNCATION_MARK).length ? outCps.slice(0, maxLen).join('') + INLINE_TRUNCATION_MARK : out;
68
+ }
69
+ export function renderTaskNotificationXml(raw) {
70
+ const n = ownSnapshotTyped(raw) ?? {};
71
+ const open = n.taskType === 'external'
72
+ ? `<${TASK_NOTIFICATION_TAG} type="external"${n.externalSource !== undefined
73
+ ? ` from="${attrEscape(inlineUntrustedSource(shownValue(n.externalSource), EXTERNAL_SOURCE_MAX))}" from-unverified="true"`
74
+ : ''}>`
75
+ : `<${TASK_NOTIFICATION_TAG}>`;
76
+ return [
77
+ open,
78
+ coreTag(TASK_ID_TAG, n.taskId),
79
+ ...(n.taskType !== undefined ? [coreTag('task-type', n.taskType)] : []),
80
+ ...(n.toolUseId !== undefined ? [coreTag('tool-use-id', n.toolUseId)] : []),
81
+ coreTag(STATUS_TAG, n.status),
82
+ coreTag(SUMMARY_TAG, n.summary),
83
+ ...(n.result !== undefined ? [coreTag('result', n.result)] : []),
84
+ ...(n.outputFile !== undefined ? [coreTag('output-file', n.outputFile)] : []),
85
+ ...(n.diagnostics !== undefined ? [coreTag('diagnostics', n.diagnostics)] : []),
86
+ ...(Array.isArray(n.recentSteps) && n.recentSteps.length > 0 ? [coreTag('recent-steps', n.recentSteps.join('\n'))] : []),
87
+ ...(n.resumable !== undefined ? [coreTag('resumable', n.resumable)] : []),
88
+ `</${TASK_NOTIFICATION_TAG}>`,
89
+ ].join('\n');
90
+ }
91
+ const TASK_NOTIFICATION_CARRIER_KEY = '_sema_task_notification';
92
+ export function freezeTaskNotificationFields(n) {
93
+ const completionIdIn = n.completionId;
94
+ const completionId = typeof completionIdIn === 'string' && completionIdIn.length > 0 ? completionIdIn : undefined;
95
+ const seq = cycleSeqValue(n.seq);
96
+ return Object.freeze({
97
+ taskId: n.taskId,
98
+ status: n.status,
99
+ summary: n.summary,
100
+ ...(n.taskType !== undefined ? { taskType: n.taskType } : {}),
101
+ ...(n.toolUseId !== undefined ? { toolUseId: n.toolUseId } : {}),
102
+ ...(n.outputFile !== undefined ? { outputFile: n.outputFile } : {}),
103
+ ...(n.diagnostics !== undefined ? { diagnostics: n.diagnostics } : {}),
104
+ ...(n.result !== undefined ? { result: n.result } : {}),
105
+ ...(n.stoppedBy !== undefined ? { stoppedBy: n.stoppedBy } : {}),
106
+ ...(n.partial !== undefined ? { partial: n.partial } : {}),
107
+ ...(n.exitCode !== undefined ? { exitCode: n.exitCode } : {}),
108
+ ...(n.lines !== undefined ? { lines: Object.freeze([...n.lines]) } : {}),
109
+ ...(n.recentSteps !== undefined ? { recentSteps: Object.freeze([...n.recentSteps]) } : {}),
110
+ ...(n.resumable !== undefined ? { resumable: n.resumable } : {}),
111
+ ...(n.externalSource !== undefined ? { externalSource: n.externalSource } : {}),
112
+ ...(completionId !== undefined ? { completionId } : {}),
113
+ ...(seq !== undefined ? { seq } : {}),
114
+ });
115
+ }
116
+ export function taskNotificationQueueCommand(n) {
117
+ const fact = freezeTaskNotificationFields(n);
118
+ return { value: renderTaskNotificationXml(fact), mode: 'task-notification', _sema_task_notification: fact };
119
+ }
120
+ export function taskNotificationOf(carrier) {
121
+ const raw = ownSnapshotRecord(guardedRead(() => readOwnDataValue(carrier, TASK_NOTIFICATION_CARRIER_KEY)));
122
+ if (raw === undefined)
123
+ return undefined;
124
+ const slot = (k) => guardedRead(() => readOwnDataValue(raw, k));
125
+ const taskId = slot('taskId');
126
+ const status = slot('status');
127
+ const summary = slot('summary');
128
+ if (typeof taskId !== 'string' || taskId.length === 0 || typeof status !== 'string' || typeof summary !== 'string')
129
+ return undefined;
130
+ const out = { taskId, status, summary };
131
+ for (const k of ['taskType', 'toolUseId', 'outputFile', 'diagnostics', 'result', 'stoppedBy', 'externalSource']) {
132
+ const v = slot(k);
133
+ if (typeof v === 'string')
134
+ out[k] = v;
135
+ }
136
+ for (const k of ['lines', 'recentSteps']) {
137
+ const v = slot(k);
138
+ if (Array.isArray(v)) {
139
+ const copy = [];
140
+ let ok = true;
141
+ for (let i = 0; i < v.length; i++) {
142
+ const e = guardedRead(() => readOwnDataValue(v, String(i)));
143
+ if (typeof e !== 'string') {
144
+ ok = false;
145
+ break;
146
+ }
147
+ copy.push(e);
148
+ }
149
+ if (ok)
150
+ out[k] = copy;
151
+ }
152
+ }
153
+ if (slot('partial') === true)
154
+ out.partial = true;
155
+ const exitCode = slot('exitCode');
156
+ if (typeof exitCode === 'number' && Number.isInteger(exitCode))
157
+ out.exitCode = exitCode;
158
+ const resumable = slot('resumable');
159
+ if (typeof resumable === 'boolean')
160
+ out.resumable = resumable;
161
+ const completionId = slot('completionId');
162
+ if (typeof completionId === 'string' && completionId.length > 0)
163
+ out.completionId = completionId;
164
+ const seq = cycleSeqValue(slot('seq'));
165
+ if (seq !== undefined)
166
+ out.seq = seq;
167
+ return freezeTaskNotificationFields(out);
168
+ }
169
+ function carriesTaskNotification(carrier) {
170
+ try {
171
+ return Object.hasOwn(carrier, TASK_NOTIFICATION_CARRIER_KEY);
172
+ }
173
+ catch {
174
+ return true;
175
+ }
176
+ }
177
+ export function deriveNotificationResidualLines(raw) {
24
178
  const out = [];
179
+ const n = ownSnapshotRecord(raw);
180
+ if (n === undefined)
181
+ return out;
25
182
  if (Array.isArray(n.recentSteps)) {
26
183
  for (const s of n.recentSteps) {
27
184
  const step = (s ?? {});
@@ -42,7 +199,10 @@ export function deriveNotificationResidualLines(n) {
42
199
  }
43
200
  return out;
44
201
  }
45
- export function normalizeTaskNotification(n) {
202
+ export function normalizeTaskNotification(raw) {
203
+ const n = ownSnapshotRecord(raw);
204
+ if (n === undefined)
205
+ return null;
46
206
  const taskId = typeof n.task_id === 'string' && n.task_id.length > 0 ? n.task_id : undefined;
47
207
  if (taskId === undefined)
48
208
  return null;
@@ -75,6 +235,8 @@ export function normalizeTaskNotification(n) {
75
235
  ...(recentSteps.length > 0 ? { recentSteps } : {}),
76
236
  ...(typeof n.resumable === 'boolean' ? { resumable: n.resumable } : {}),
77
237
  ...(typeof n.source === 'string' && n.source.length > 0 ? { externalSource: n.source } : {}),
238
+ ...(typeof n.completionId === 'string' && n.completionId.length > 0 ? { completionId: n.completionId } : {}),
239
+ ...(cycleSeqValue(n.seq) !== undefined ? { seq: cycleSeqValue(n.seq) } : {}),
78
240
  };
79
241
  }
80
242
  export function taskNotificationDedupKey(n) {
@@ -82,7 +244,8 @@ export function taskNotificationDedupKey(n) {
82
244
  const lane = n.taskType === 'external' ? 'external:' : '';
83
245
  return `${lane}${n.taskId}:${n.status}${seq ? `:${seq}` : ''}`;
84
246
  }
85
- export function taskNotificationDedupKeyFromWire(n) {
247
+ export function taskNotificationDedupKeyFromWire(raw) {
248
+ const n = ownSnapshotRecord(raw) ?? {};
86
249
  return taskNotificationDedupKey({
87
250
  taskId: typeof n.task_id === 'string' ? n.task_id : '',
88
251
  status: typeof n.status === 'string' ? n.status : 'unknown',
@@ -94,7 +257,10 @@ export function parseTranscriptNotificationSeeds(messages) {
94
257
  const renderedKeys = [];
95
258
  const notifiedKeys = [];
96
259
  let seeded = 0;
97
- for (const m of messages) {
260
+ const snap = ownSnapshot(messages);
261
+ if (!Array.isArray(snap))
262
+ return { renderedKeys, notifiedKeys, seeded };
263
+ for (const m of snap) {
98
264
  const rec = m;
99
265
  if (rec?.type !== 'user')
100
266
  continue;
@@ -189,7 +355,7 @@ function readTaskNotificationBlock(block) {
189
355
  external: /\btype="external"/.test(block.attrs),
190
356
  };
191
357
  }
192
- const TASK_NOTIFICATION_TAG = 'task-notification';
358
+ export const TASK_NOTIFICATION_TAG = 'task-notification';
193
359
  const TASK_ID_TAG = 'task-id';
194
360
  const STATUS_TAG = 'status';
195
361
  const SUMMARY_TAG = 'summary';
@@ -259,6 +425,7 @@ export function enqueuePlanReviewOutcome(value, meta) {
259
425
  dispatchNo: meta.dispatchNo,
260
426
  decision: meta.decision,
261
427
  effect: meta.effect,
428
+ ...(meta.effect === 'still_parked' && meta.cause === 'stored_form_unsupported' ? { cause: meta.cause } : {}),
262
429
  }),
263
430
  }
264
431
  : {}),
@@ -272,8 +439,9 @@ export function dropQueuedNotificationsForRun(taskId) {
272
439
  return 0;
273
440
  const dropped = p.removeByFilter(cmd => cmd.mode === 'task-notification' &&
274
441
  cmd.agentId === undefined &&
275
- typeof cmd.value === 'string' &&
276
- cmd.value.includes(needle));
442
+ (typeof cmd === 'object' && cmd !== null && carriesTaskNotification(cmd)
443
+ ? taskNotificationOf(cmd)?.taskId === taskId
444
+ : typeof cmd.value === 'string' && cmd.value.includes(needle)));
277
445
  if (dropped.length > 0) {
278
446
  cardEnqueuedRunIds.delete(taskId);
279
447
  traceNotif(`dropped ${dropped.length} queued task-notification(s) for ${taskId} — engine echo already delivered (B1); card ownership returned to the frame lane`);
@@ -515,6 +683,11 @@ async function tickWatch(nowMs) {
515
683
  tickStartedAtMs = null;
516
684
  }
517
685
  }
686
+ function probeAnswerSnapshot(answer) {
687
+ if (answer === null || answer === undefined)
688
+ return null;
689
+ return ownSnapshotRecord(answer) ?? null;
690
+ }
518
691
  async function tickWatchInner(now) {
519
692
  const bgProbe = bgStatusProbe;
520
693
  for (const [key, meta] of [...outstandingBgTasks]) {
@@ -532,8 +705,8 @@ async function tickWatchInner(now) {
532
705
  let alive;
533
706
  bgProbeInFlight.set(key, now);
534
707
  try {
535
- const res = await withProbeDeadline(bgProbe(meta.taskId), probeTimeoutMs());
536
- if (res === null || res === undefined)
708
+ const res = probeAnswerSnapshot(await withProbeDeadline(bgProbe(meta.taskId), probeTimeoutMs()));
709
+ if (res === null)
537
710
  continue;
538
711
  alive = !res.terminal;
539
712
  }
@@ -563,15 +736,16 @@ async function tickWatchInner(now) {
563
736
  continue;
564
737
  bgProbeInFlight.set(key, now);
565
738
  try {
566
- const res = await withProbeDeadline(bgProbe(meta.taskId), probeTimeoutMs());
739
+ const res = probeAnswerSnapshot(await withProbeDeadline(bgProbe(meta.taskId), probeTimeoutMs()));
567
740
  if (res?.terminal) {
741
+ const completionId = typeof res.completionId === 'string' && res.completionId.length > 0 ? res.completionId : undefined;
568
742
  outstandingBgTasks.delete(key);
569
- enqueueBgChildNotification({
743
+ enqueueBgChild({
570
744
  taskId: meta.taskId,
571
745
  seq: meta.seq,
572
746
  status: res.status,
573
- summary: `Background agent "${meta.description}" ${res.status}`,
574
- });
747
+ summary: `Background agent "${meta.description}" ${String(res.status)}`,
748
+ }, completionId !== undefined ? { completionId } : {});
575
749
  }
576
750
  }
577
751
  catch {
@@ -591,7 +765,7 @@ async function tickWatchInner(now) {
591
765
  continue;
592
766
  runProbeInFlight.set(runId, now);
593
767
  try {
594
- const res = await withProbeDeadline(probe(runId), probeTimeoutMs());
768
+ const res = probeAnswerSnapshot(await withProbeDeadline(probe(runId), probeTimeoutMs()));
595
769
  if (res?.terminal) {
596
770
  if (outstandingRuns.delete(runId))
597
771
  notifyOutstanding();
@@ -610,7 +784,18 @@ async function tickWatchInner(now) {
610
784
  }
611
785
  }
612
786
  const bgNotifiedKeys = new Set();
613
- export function enqueueBgChildNotification(n) {
787
+ export function enqueueBgChildNotification(raw) {
788
+ const n = ownSnapshotRecord(raw);
789
+ if (n === undefined) {
790
+ traceNotif('bg-notification dropped:payload-unreadable');
791
+ return;
792
+ }
793
+ enqueueBgChild(n, {
794
+ ...(typeof n.completionId === 'string' && n.completionId.length > 0 ? { completionId: n.completionId } : {}),
795
+ ...(cycleSeqValue(n.seq) !== undefined ? { seq: cycleSeqValue(n.seq) } : {}),
796
+ });
797
+ }
798
+ function enqueueBgChild(n, identity) {
614
799
  const cycle = normalizeBgSeq(n.seq);
615
800
  const key = `${n.taskId}:${cycle}:${n.status}`;
616
801
  if (bgNotifiedKeys.has(key)) {
@@ -637,17 +822,20 @@ export function enqueueBgChildNotification(n) {
637
822
  catch {
638
823
  }
639
824
  }
640
- const message = `<${TASK_NOTIFICATION_TAG}>
641
- <${TASK_ID_TAG}>${escapeXml(n.taskId)}</${TASK_ID_TAG}>
642
- <${STATUS_TAG}>${escapeXml(n.status)}</${STATUS_TAG}>
643
- <${SUMMARY_TAG}>${escapeXml(n.summary ?? `Background agent ${n.status}`)}</${SUMMARY_TAG}>
644
- </${TASK_NOTIFICATION_TAG}>`;
645
- port()?.enqueuePendingNotification({
646
- value: message,
647
- mode: 'task-notification',
648
- });
649
- }
650
- export function enqueueEngineWorkflowNotification(c) {
825
+ port()?.enqueuePendingNotification(taskNotificationQueueCommand({
826
+ taskId: n.taskId,
827
+ taskType: 'background_agent',
828
+ status: n.status,
829
+ summary: n.summary ?? `Background agent ${n.status}`,
830
+ ...identity,
831
+ }));
832
+ }
833
+ export function enqueueEngineWorkflowNotification(raw) {
834
+ const c = ownSnapshotRecord(raw);
835
+ if (c === undefined) {
836
+ traceNotif('workflow-notification dropped:payload-unreadable');
837
+ return;
838
+ }
651
839
  if (notifiedRunIds.has(c.runId)) {
652
840
  workflowDedupDropped++;
653
841
  traceNotif(`workflow notification suppressed (run already notified) runId=${c.runId} status=${c.status}`);
@@ -655,15 +843,7 @@ export function enqueueEngineWorkflowNotification(c) {
655
843
  }
656
844
  markRunNotified(c.runId);
657
845
  cardEnqueuedRunIds.add(c.runId);
658
- const message = `<${TASK_NOTIFICATION_TAG}>
659
- <${TASK_ID_TAG}>${escapeXml(c.runId)}</${TASK_ID_TAG}>
660
- <${STATUS_TAG}>${c.status}</${STATUS_TAG}>
661
- <${SUMMARY_TAG}>${escapeXml(c.summary)}</${SUMMARY_TAG}>
662
- </${TASK_NOTIFICATION_TAG}>`;
663
- port()?.enqueuePendingNotification({
664
- value: message,
665
- mode: 'task-notification',
666
- });
846
+ port()?.enqueuePendingNotification(taskNotificationQueueCommand({ taskId: c.runId, taskType: 'workflow', status: c.status, summary: c.summary }));
667
847
  }
668
848
  export function _resetEngineTaskNotificationForTest() {
669
849
  notifiedRunIds.clear();
@@ -703,15 +883,23 @@ export function _setWatcherTimingForTest(o) {
703
883
  stuckTickResetOverrideMs = o?.stuckTickResetMs ?? null;
704
884
  }
705
885
  const SUPPLEMENT_LINE_PREFIX = 'The background task itself ';
706
- export function isTaskNotificationObjective(objective) {
886
+ export function isTaskNotificationObjective(objective, kind) {
887
+ if (kind !== undefined)
888
+ return kind === 'wake';
707
889
  return (typeof objective === 'string' &&
708
890
  objective.trimStart().startsWith(`<${TASK_NOTIFICATION_TAG}>`));
709
891
  }
710
- export function taskNotificationDeliverySupplement(objective) {
711
- if (!isTaskNotificationObjective(objective))
892
+ export function taskNotificationDeliverySupplement(objective, kind, notification) {
893
+ if (!isTaskNotificationObjective(objective, kind))
712
894
  return undefined;
713
- const m = new RegExp(`<${STATUS_TAG}>([^<]*)</${STATUS_TAG}>`).exec(objective);
714
- const status = m?.[1]?.trim();
895
+ const status = notification !== undefined
896
+ ? (() => {
897
+ const v = guardedRead(() => readOwnDataValue(notification, 'status'));
898
+ return typeof v === 'string' ? v.trim() : undefined;
899
+ })()
900
+ : typeof objective === 'string'
901
+ ? new RegExp(`<${STATUS_TAG}>([^<]*)</${STATUS_TAG}>`).exec(objective)?.[1]?.trim()
902
+ : undefined;
715
903
  if (status === 'completed') {
716
904
  return `${SUPPLEMENT_LINE_PREFIX}completed — only this notification delivery failed. Check /tasks for the result.`;
717
905
  }
@@ -1,4 +1,4 @@
1
- import { engineWireTarget } from './engineWireTarget.js';
1
+ import { engineWireTargetBaseUrl } from './engineWireTarget.js';
2
2
  import { createEngineCapReader } from './engineCapReader.js';
3
3
  import { ownDataField, readOwnDataValue } from './ownKey.js';
4
4
  export function projectOutputStyleSeatCapability(caps) {
@@ -18,7 +18,7 @@ const reader = createEngineCapReader({
18
18
  name: 'outputStyleSeat',
19
19
  project: projectOutputStyleSeatCapability,
20
20
  });
21
- export function observedOutputStyleSeat(baseUrl = engineWireTarget()?.baseUrl) {
21
+ export function observedOutputStyleSeat(baseUrl = engineWireTargetBaseUrl()) {
22
22
  return reader.observed(baseUrl);
23
23
  }
24
24
  export function outputStyleSeatAdmitted(reading) {
package/dist/ownKey.d.ts CHANGED
@@ -4,6 +4,9 @@ export declare function readAskOrigin(carrier: object | null | undefined): strin
4
4
  export declare function readOwnDataNonEmptyString(v: object | null | undefined, key: string): string | undefined;
5
5
  export declare function readOwnDataFiniteNumber(v: object | null | undefined, key: string): number | undefined;
6
6
  export declare function readOwnDataValue<T>(v: object | null | undefined, key: string): T | undefined;
7
+ export declare function carriesAnswerText(text: string): boolean;
8
+ export declare function appendOwnElement<T>(list: T[], value: T): void;
9
+ export declare function toolResultBlockOf(record: object): object | undefined;
7
10
  export declare function guardedRead<T>(read: () => T | undefined): T | undefined;
8
11
  export declare function ownDataField(v: object, key: string): unknown;
9
12
  export declare function ownSendableField(v: object, key: string): unknown;
@@ -59,3 +62,12 @@ export interface PromptIdentityLayersRow {
59
62
  export declare function promptManifestSectionViewOf(row: object): PromptManifestSectionRow | undefined;
60
63
  export declare function promptManifestIdentityOfFrame(frame: object): PromptManifestIdentityRow | undefined;
61
64
  export declare function promptManifestIdentityOf(raw: {} | null | undefined): PromptManifestIdentityRow | undefined;
65
+ export declare function isOwnSnapshot<V>(v: V): boolean;
66
+ export declare function ownSnapshot<V>(value: V): SampledJson;
67
+ export type SampledJson = string | number | boolean | null | undefined | readonly SampledJson[] | SampledRecord;
68
+ export interface SampledRecord {
69
+ readonly [key: string]: SampledJson;
70
+ }
71
+ export declare function ownSnapshotWhenTyped<V>(value: V, word: string): SampledJson;
72
+ export declare function ownSnapshotTyped<T extends object>(value: T): T | undefined;
73
+ export declare function ownSnapshotRecord<V>(value: V): SampledRecord | undefined;
package/dist/ownKey.js CHANGED
@@ -34,6 +34,27 @@ export function readOwnDataValue(v, key) {
34
34
  const d = Object.getOwnPropertyDescriptor(v, key);
35
35
  return d !== undefined && Object.hasOwn(d, 'value') ? d.value : undefined;
36
36
  }
37
+ export function carriesAnswerText(text) {
38
+ return text.trim().length > 0;
39
+ }
40
+ export function appendOwnElement(list, value) {
41
+ Object.defineProperty(list, list.length, { value, writable: true, enumerable: true, configurable: true });
42
+ }
43
+ export function toolResultBlockOf(record) {
44
+ const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
45
+ const message = ownDataField(record, 'message');
46
+ if (!isRecord(message))
47
+ return undefined;
48
+ const content = ownDataField(message, 'content');
49
+ if (!Array.isArray(content))
50
+ return undefined;
51
+ for (let i = 0; i < content.length; i++) {
52
+ const block = ownDataField(content, String(i));
53
+ if (isRecord(block) && ownDataField(block, 'type') === 'tool_result')
54
+ return block;
55
+ }
56
+ return undefined;
57
+ }
37
58
  export function guardedRead(read) {
38
59
  try {
39
60
  return read();
@@ -106,7 +127,7 @@ function contextUsageSectionRowsOf(raw) {
106
127
  for (let i = 0; i < n; i++) {
107
128
  const row = guardedRead(() => contextUsageSectionRowOf(raw, i));
108
129
  if (row !== undefined)
109
- rows.push(row);
130
+ appendOwnElement(rows, row);
110
131
  }
111
132
  return rows.length > 0 ? rows : undefined;
112
133
  }
@@ -157,7 +178,7 @@ export function humanInputAttachmentsOf(frame) {
157
178
  return { ordinal, ...(kind !== undefined ? { kind } : {}), outcome, ...(label !== undefined ? { label } : {}) };
158
179
  });
159
180
  if (row !== undefined)
160
- rows.push(row);
181
+ appendOwnElement(rows, row);
161
182
  }
162
183
  return rows.length > 0 ? rows : undefined;
163
184
  }
@@ -255,7 +276,7 @@ export function promptManifestIdentityOf(raw) {
255
276
  for (const [k, v] of Object.entries(renderersRaw)) {
256
277
  if (typeof v !== 'number' || !Number.isFinite(v))
257
278
  return undefined;
258
- entries.push([k, v]);
279
+ appendOwnElement(entries, [k, v]);
259
280
  }
260
281
  const renderers = Object.fromEntries(entries);
261
282
  return { artifact, layers: { catalog, renderers, ...optional, binding }, epoch, activatedBy };
@@ -264,3 +285,158 @@ export function promptManifestIdentityOf(raw) {
264
285
  return undefined;
265
286
  }
266
287
  }
288
+ const SAMPLED = new WeakSet();
289
+ const SAMPLE_MAX_DEPTH = 256;
290
+ export function isOwnSnapshot(v) {
291
+ return isBranded(v);
292
+ }
293
+ function isBranded(v) {
294
+ return typeof v === 'object' && v !== null && SAMPLED.has(v);
295
+ }
296
+ function arrayIndexOfKey(k) {
297
+ if (!/^(?:0|[1-9]\d*)$/.test(k))
298
+ return undefined;
299
+ const n = Number(k);
300
+ return n < 4294967295 ? n : undefined;
301
+ }
302
+ export function ownSnapshot(value) {
303
+ return snapshotOf(value);
304
+ }
305
+ function snapshotOf(value) {
306
+ if (typeof value === 'object' && value !== null) {
307
+ if (SAMPLED.has(value))
308
+ return value;
309
+ return sampleObject(value, 0, { done: new Map(), path: new Set(), seen: new Set(), rework: 0, depthCuts: 0 });
310
+ }
311
+ return samplePrimitive(value);
312
+ }
313
+ export function ownSnapshotWhenTyped(value, word) {
314
+ return snapshotWhenTyped(value, word);
315
+ }
316
+ function snapshotWhenTyped(value, word) {
317
+ if (typeof value !== 'object' || value === null)
318
+ return value;
319
+ if (guardedRead(() => Array.isArray(value)) === true)
320
+ return value;
321
+ const read = guardedRead(() => ({ own: Object.getOwnPropertyDescriptor(value, 'type') }));
322
+ if (read !== undefined) {
323
+ const own = read.own;
324
+ if (own === undefined) {
325
+ if (guardedRead(() => 'type' in value) === false)
326
+ return value;
327
+ }
328
+ else if (Object.hasOwn(own, 'value') && typeof own.value === 'string' && own.value !== '' && own.value !== word) {
329
+ return value;
330
+ }
331
+ }
332
+ return recordOf(value);
333
+ }
334
+ export function ownSnapshotTyped(value) {
335
+ return recordOf(value);
336
+ }
337
+ export function ownSnapshotRecord(value) {
338
+ return recordOf(value);
339
+ }
340
+ function recordOf(value) {
341
+ const s = snapshotOf(value);
342
+ return typeof s === 'object' && s !== null && !Array.isArray(s) ? s : undefined;
343
+ }
344
+ function samplePrimitive(v) {
345
+ return typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean' ? v : v === null ? null : undefined;
346
+ }
347
+ const SAMPLE_MAX_TRAILING_HOLES = 1024;
348
+ const SAMPLE_MAX_INDEX = 1 << 20;
349
+ const SAMPLE_MAX_REWORK = 2048;
350
+ function sampleValue(v, depth, run) {
351
+ return typeof v === 'object' && v !== null ? sampleObject(v, depth, run) : samplePrimitive(v);
352
+ }
353
+ function sampleObject(src, depth, run) {
354
+ const hit = run.done.get(src);
355
+ if (hit !== undefined)
356
+ return hit ?? undefined;
357
+ if (SAMPLED.has(src))
358
+ return src;
359
+ if (run.path.has(src))
360
+ return undefined;
361
+ if (depth >= SAMPLE_MAX_DEPTH) {
362
+ run.depthCuts++;
363
+ return undefined;
364
+ }
365
+ if (run.seen.has(src)) {
366
+ if (++run.rework > SAMPLE_MAX_REWORK) {
367
+ run.depthCuts++;
368
+ return undefined;
369
+ }
370
+ }
371
+ else {
372
+ run.seen.add(src);
373
+ }
374
+ let isArray;
375
+ let keys;
376
+ try {
377
+ isArray = Array.isArray(src);
378
+ keys = Reflect.ownKeys(src);
379
+ }
380
+ catch {
381
+ run.done.set(src, null);
382
+ return undefined;
383
+ }
384
+ run.path.add(src);
385
+ const cutsBefore = run.depthCuts;
386
+ try {
387
+ const rec = {};
388
+ const arr = [];
389
+ let tail = 0;
390
+ let good = 0;
391
+ let declared = 0;
392
+ for (const k of keys) {
393
+ if (typeof k !== 'string')
394
+ continue;
395
+ if (isArray && k === 'length') {
396
+ const lv = guardedRead(() => {
397
+ const ld = Object.getOwnPropertyDescriptor(src, 'length');
398
+ return ld !== undefined && Object.hasOwn(ld, 'value') ? ld.value : undefined;
399
+ });
400
+ if (typeof lv === 'number' && Number.isInteger(lv) && lv > 0 && lv <= 0xffffffff)
401
+ declared = lv;
402
+ continue;
403
+ }
404
+ const index = isArray ? arrayIndexOfKey(k) : undefined;
405
+ if (isArray && index === undefined)
406
+ continue;
407
+ if (index !== undefined && index >= SAMPLE_MAX_INDEX)
408
+ continue;
409
+ if (index !== undefined && index + 1 > tail)
410
+ tail = index + 1;
411
+ const d = guardedRead(() => Object.getOwnPropertyDescriptor(src, k));
412
+ if (d === undefined)
413
+ continue;
414
+ if (d.enumerable !== true || !Object.hasOwn(d, 'value'))
415
+ continue;
416
+ const child = sampleValue(d.value, depth + 1, run);
417
+ if (child === undefined)
418
+ continue;
419
+ if (index !== undefined) {
420
+ Object.defineProperty(arr, index, { value: child, writable: true, enumerable: true, configurable: true });
421
+ if (index + 1 > good)
422
+ good = index + 1;
423
+ }
424
+ else
425
+ putOwnKey(rec, k, child);
426
+ }
427
+ if (isArray) {
428
+ const want = Math.max(good, Math.min(Math.max(tail, declared), good + SAMPLE_MAX_TRAILING_HOLES));
429
+ if (arr.length < want)
430
+ arr.length = want;
431
+ }
432
+ const out = isArray ? arr : rec;
433
+ Object.freeze(out);
434
+ SAMPLED.add(out);
435
+ if (run.depthCuts === cutsBefore)
436
+ run.done.set(src, out);
437
+ return out;
438
+ }
439
+ finally {
440
+ run.path.delete(src);
441
+ }
442
+ }
@@ -580,7 +580,7 @@ function ownDataOf(o, key) {
580
580
  return undefined;
581
581
  try {
582
582
  const d = Object.getOwnPropertyDescriptor(o, key);
583
- return d !== undefined && 'value' in d ? d.value : undefined;
583
+ return d !== undefined && Object.hasOwn(d, 'value') ? d.value : undefined;
584
584
  }
585
585
  catch {
586
586
  return undefined;