@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,7 +4,8 @@ import { parseWorkflowPollEnvelope, projectWorkflowTaskOutput } from './workflow
4
4
  import { asModelFallbackReason } from './engineErrorCodes.js';
5
5
  import { frozenSet } from './frozenSet.js';
6
6
  import { bashExitOf, bashExitReadingFailed } from './bashExitReading.js';
7
- import { readFrameTrueMark, readFrameTrueMarkReading } from './ownKey.js';
7
+ import { guardedRead, ownDataField, ownSnapshotWhenTyped, readFrameTrueMark, readFrameTrueMarkReading, readOwnDataFiniteNumber, readOwnDataNonEmptyString, readOwnDataValue, toolResultBlockOf, } from './ownKey.js';
8
+ import { displayUntrusted } from './displayUntrusted.js';
8
9
  import { isCoreSemaTaskTerminal } from './terminalStatuses.js';
9
10
  import { CORE_ENGINE_CARD_TYPES } from './generated/engineFactTables.js';
10
11
  export const STRUCTURED_DETAIL_TYPES = frozenSet(CORE_ENGINE_CARD_TYPES);
@@ -284,29 +285,7 @@ const TOOL_CARD_DEGRADED_TEXT = {
284
285
  unrecognised: 'This tool call carries a result marker this client does not recognise, so no result is shown for it.',
285
286
  };
286
287
  const cardDegraded = (cause) => ({ kind: 'degraded', cause, text: TOOL_CARD_DEGRADED_TEXT[cause] });
287
- function cardOwnData(o, key) {
288
- const d = Object.getOwnPropertyDescriptor(o, key);
289
- if (d === undefined)
290
- return undefined;
291
- if (!Object.hasOwn(d, 'value'))
292
- throw new TypeError(`own property "${key}" is an accessor`);
293
- return d.value;
294
- }
295
288
  const isCardRecordObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
296
- function toolResultBlockOf(record) {
297
- const message = cardOwnData(record, 'message');
298
- if (!isCardRecordObject(message))
299
- return undefined;
300
- const content = cardOwnData(message, 'content');
301
- if (!Array.isArray(content))
302
- return undefined;
303
- for (let i = 0; i < content.length; i++) {
304
- const block = cardOwnData(content, String(i));
305
- if (isCardRecordObject(block) && cardOwnData(block, 'type') === 'tool_result')
306
- return block;
307
- }
308
- return undefined;
309
- }
310
289
  export function readToolCardOutcome(record) {
311
290
  try {
312
291
  if (!isCardRecordObject(record))
@@ -326,7 +305,7 @@ export function readToolCardOutcome(record) {
326
305
  return { kind: 'unreadable' };
327
306
  if (markerDesc.value !== TOOL_RESULT_DEGRADED_WIRE_NO_OUTPUT)
328
307
  return cardDegraded('unrecognised');
329
- return cardDegraded(cardOwnData(block, 'is_error') === true ? 'error-without-detail' : 'no-result');
308
+ return cardDegraded(ownDataField(block, 'is_error') === true ? 'error-without-detail' : 'no-result');
330
309
  }
331
310
  catch {
332
311
  return { kind: 'unreadable' };
@@ -356,7 +335,8 @@ const killedBySignalSentence = (killCauseOf) => {
356
335
  }
357
336
  return TOOL_KILL_TEXT[isToolKillCause(cause) ? cause : 'unknown'];
358
337
  };
359
- export function wireOutputToBody(toolName, output, isError, truncated, flatten, structured, leaderLedger = true, killCauseOf) {
338
+ export function wireOutputToBody(toolName, output, isError, truncated, flatten, structuredIn, leaderLedger = true, killCauseOf) {
339
+ const structured = ownSnapshotWhenTyped(structuredIn, 'task-output');
360
340
  const text = flatten(output);
361
341
  const name = (toolName || '').toLowerCase();
362
342
  const sType = structuredDetailType(structured);
@@ -473,9 +453,12 @@ export function wireOutputToBody(toolName, output, isError, truncated, flatten,
473
453
  return { content: truncated ? `${text}\n…(truncated)` : text, isError };
474
454
  }
475
455
  export function structuredToToolUseResult(structured, modelText, leaderLedger = true) {
476
- if (typeof structured !== 'object' || structured === null)
456
+ const sampled = ownSnapshotWhenTyped(structured, 'task-output');
457
+ if (typeof sampled !== 'object' || sampled === null)
477
458
  return null;
478
- const s = structured;
459
+ const s = sampled;
460
+ if (guardedRead(() => readOwnDataValue(s, 'type')) === 'web-search')
461
+ return webSearchToolUseResult(s);
479
462
  for (const k of ['originalFile', 'content', 'stdout', 'stderr']) {
480
463
  if (typeof s[k] === 'string' && s[k].length > MAX_STRUCTURED_FIELD_CHARS)
481
464
  return null;
@@ -748,6 +731,7 @@ export function structuredToToolUseResult(structured, modelText, leaderLedger =
748
731
  : (parsed?.status ?? (engineSaidNotReady ? 'running' : 'unknown'));
749
732
  const bodyText = hasContent ? s.content : parsed && parsed.kind !== 'unknown' ? parsed.output : undefined;
750
733
  const error = typeof s.error === 'string' ? s.error : undefined;
734
+ const completionId = terminalCardCompletionIdOf(s, engineSaidNotReady);
751
735
  if (taskType === 'background_bash') {
752
736
  const exitCode = typeof inner?.exitCode === 'number' ? inner.exitCode : undefined;
753
737
  return {
@@ -761,6 +745,7 @@ export function structuredToToolUseResult(structured, modelText, leaderLedger =
761
745
  output: bodyText ?? '',
762
746
  ...(exitCode !== undefined ? { exitCode } : {}),
763
747
  ...(error !== undefined ? { error } : {}),
748
+ ...(completionId !== undefined ? { _sema_completion_id: completionId } : {}),
764
749
  },
765
750
  },
766
751
  };
@@ -777,6 +762,7 @@ export function structuredToToolUseResult(structured, modelText, leaderLedger =
777
762
  output: bodyText ?? '',
778
763
  result: bodyText ?? '',
779
764
  ...(error !== undefined ? { error } : {}),
765
+ ...(completionId !== undefined ? { _sema_completion_id: completionId } : {}),
780
766
  },
781
767
  },
782
768
  };
@@ -801,6 +787,7 @@ export function structuredToToolUseResult(structured, modelText, leaderLedger =
801
787
  output,
802
788
  ...(error !== undefined ? { error } : {}),
803
789
  ...(runErrorCode !== undefined ? { _sema_error_code: runErrorCode } : {}),
790
+ ...(completionId !== undefined ? { _sema_completion_id: completionId } : {}),
804
791
  },
805
792
  },
806
793
  };
@@ -809,7 +796,143 @@ export function structuredToToolUseResult(structured, modelText, leaderLedger =
809
796
  return null;
810
797
  }
811
798
  }
812
- export function detectEngineBgShellReceipt(toolName, rawInput, outputText, structured) {
799
+ const WEB_SEARCH_ENTRIES_MAX = 1024;
800
+ const WEB_SEARCH_HITS_MAX = 4096;
801
+ const WEB_SEARCH_FIELD_CHARS_MAX = 8192;
802
+ function isArrayLength(n) {
803
+ return Number.isInteger(n) && n >= 0 && n <= 4_294_967_295;
804
+ }
805
+ function isWebSearchRecord(v) {
806
+ return typeof v === 'object' && v !== null && guardedRead(() => !Array.isArray(v)) === true;
807
+ }
808
+ function readWebSearchHit(raw) {
809
+ if (!isWebSearchRecord(raw))
810
+ return undefined;
811
+ const title = readOwnDataValue(raw, 'title');
812
+ const url = readOwnDataValue(raw, 'url');
813
+ if (typeof title !== 'string' || typeof url !== 'string' || url === '')
814
+ return undefined;
815
+ if (title.length > WEB_SEARCH_FIELD_CHARS_MAX || url.length > WEB_SEARCH_FIELD_CHARS_MAX)
816
+ return undefined;
817
+ return { title, url };
818
+ }
819
+ function readWebSearchEntry(raw, hitBudget) {
820
+ if (!isWebSearchRecord(raw))
821
+ return undefined;
822
+ const toolUseId = readOwnDataValue(raw, 'tool_use_id');
823
+ const content = readOwnDataValue(raw, 'content');
824
+ if (typeof toolUseId !== 'string' || typeof content !== 'object' || content === null || !Array.isArray(content))
825
+ return undefined;
826
+ const n = readOwnDataFiniteNumber(content, 'length');
827
+ if (n === undefined || !isArrayLength(n))
828
+ return undefined;
829
+ const limit = Math.min(n, Math.max(0, hitBudget));
830
+ const hits = [];
831
+ let dropped = n - limit;
832
+ for (let j = 0; j < limit; j++) {
833
+ const hit = guardedRead(() => readWebSearchHit(readOwnDataValue(content, String(j))));
834
+ if (hit === undefined)
835
+ dropped++;
836
+ else
837
+ hits.push(hit);
838
+ }
839
+ return { entry: { tool_use_id: toolUseId, content: hits }, visited: limit, dropped };
840
+ }
841
+ function readWebSearchEntries(card) {
842
+ const results = guardedRead(() => readOwnDataValue(card, 'results'));
843
+ if (typeof results !== 'object' || results === null || guardedRead(() => Array.isArray(results)) !== true)
844
+ return undefined;
845
+ const length = guardedRead(() => readOwnDataFiniteNumber(results, 'length'));
846
+ if (length === undefined || !isArrayLength(length))
847
+ return undefined;
848
+ const entries = [];
849
+ let dropped = Math.max(0, length - WEB_SEARCH_ENTRIES_MAX);
850
+ let hitsLeft = WEB_SEARCH_HITS_MAX;
851
+ for (let i = 0; i < Math.min(length, WEB_SEARCH_ENTRIES_MAX); i++) {
852
+ const raw = guardedRead(() => readOwnDataValue(results, String(i)));
853
+ if (typeof raw === 'string') {
854
+ entries.push(raw);
855
+ continue;
856
+ }
857
+ const one = guardedRead(() => readWebSearchEntry(raw, hitsLeft));
858
+ if (one === undefined) {
859
+ dropped++;
860
+ continue;
861
+ }
862
+ entries.push(one.entry);
863
+ hitsLeft -= one.visited;
864
+ dropped += one.dropped;
865
+ }
866
+ const usable = entries.some(e => typeof e !== 'string' && e.content.length > 0);
867
+ if (dropped > 0 && !usable)
868
+ return undefined;
869
+ return { entries, dropped };
870
+ }
871
+ function webSearchToolUseResult(card) {
872
+ try {
873
+ const query = readOwnDataValue(card, 'query');
874
+ const durationSeconds = readOwnDataFiniteNumber(card, 'durationSeconds');
875
+ if (typeof query !== 'string' || durationSeconds === undefined || durationSeconds < 0)
876
+ return null;
877
+ const read = readWebSearchEntries(card);
878
+ if (read === undefined)
879
+ return null;
880
+ const searchCount = readOwnDataFiniteNumber(card, 'searchCount');
881
+ return {
882
+ toolUseResult: {
883
+ query,
884
+ results: read.entries.map(e => (typeof e === 'string' ? e : { tool_use_id: e.tool_use_id, content: e.content.map(h => ({ title: h.title, url: h.url })) })),
885
+ durationSeconds,
886
+ ...(searchCount !== undefined && Number.isInteger(searchCount) && searchCount >= 0 ? { searchCount } : {}),
887
+ },
888
+ };
889
+ }
890
+ catch {
891
+ return null;
892
+ }
893
+ }
894
+ export function webSearchSourcesOf(toolEnd) {
895
+ try {
896
+ if (!isWebSearchRecord(toolEnd))
897
+ return undefined;
898
+ const structured = readOwnDataValue(toolEnd, 'structured');
899
+ if (!isWebSearchRecord(structured) || readOwnDataValue(structured, 'type') !== 'web-search')
900
+ return undefined;
901
+ const read = readWebSearchEntries(structured);
902
+ if (read === undefined)
903
+ return undefined;
904
+ let dropped = read.dropped;
905
+ const out = [];
906
+ for (const e of read.entries) {
907
+ if (typeof e === 'string')
908
+ continue;
909
+ for (const h of e.content) {
910
+ const url = guardedRead(() => displayUntrusted(h.url));
911
+ const title = guardedRead(() => displayUntrusted(h.title));
912
+ if (url === undefined || url === '' || title === undefined)
913
+ dropped++;
914
+ else
915
+ out.push(Object.freeze({ title, url }));
916
+ }
917
+ }
918
+ if (out.length === 0 && dropped > 0)
919
+ return undefined;
920
+ Object.defineProperty(out, 'droppedCount', { value: dropped, enumerable: false });
921
+ return Object.freeze(out);
922
+ }
923
+ catch {
924
+ return undefined;
925
+ }
926
+ }
927
+ function terminalCardCompletionIdOf(s, engineSaidNotReady) {
928
+ if (engineSaidNotReady)
929
+ return undefined;
930
+ const status = guardedRead(() => readOwnDataNonEmptyString(s, 'status'));
931
+ if (!isCoreSemaTaskTerminal(status))
932
+ return undefined;
933
+ return guardedRead(() => readOwnDataNonEmptyString(s, 'completionId'));
934
+ }
935
+ export function detectEngineBgShellReceipt(toolName, rawInput, outputText, structured, toolUseId) {
813
936
  if (typeof outputText !== 'string')
814
937
  return null;
815
938
  const input = (rawInput ?? {});
@@ -832,28 +955,30 @@ export function detectEngineBgShellReceipt(toolName, rawInput, outputText, struc
832
955
  }
833
956
  if (!m?.[1])
834
957
  return null;
835
- return engineBgShellRegistrationBody(m[1], input, outputText, source);
958
+ return engineBgShellRegistrationBody(m[1], input, outputText, source, toolUseId, undefined);
836
959
  }
837
- function engineBgShellRegistrationBody(taskId, rawInput, receipt, source) {
960
+ function engineBgShellRegistrationBody(taskId, rawInput, receipt, source, toolUseId, outputFile) {
838
961
  const input = (rawInput ?? {});
839
962
  const command = typeof input.command === 'string' ? input.command : '(engine bash)';
840
963
  const description = typeof input.description === 'string' ? input.description : undefined;
841
964
  return {
842
965
  kind: 'register',
843
966
  taskId,
967
+ ...(typeof toolUseId === 'string' && toolUseId.length > 0 ? { toolUseId } : {}),
844
968
  command,
845
969
  ...(description !== undefined ? { description } : {}),
846
970
  receipt,
971
+ ...(typeof outputFile === 'string' && outputFile.length > 0 ? { outputFile } : {}),
847
972
  source,
848
973
  };
849
974
  }
850
- export function detectEngineBgShellDetach(toolName, rawInput, structured, outputText) {
975
+ export function detectEngineBgShellDetach(toolName, rawInput, structured, outputText, toolUseId) {
851
976
  if (toolName !== 'Bash')
852
977
  return null;
853
978
  const view = readBashDetachView(structured);
854
979
  if (view === null || view.registerFailed || view.handoffTaskId === undefined)
855
980
  return null;
856
- return engineBgShellRegistrationBody(view.handoffTaskId, rawInput, typeof outputText === 'string' ? outputText : '', 'bash');
981
+ return engineBgShellRegistrationBody(view.handoffTaskId, rawInput, typeof outputText === 'string' ? outputText : '', 'bash', toolUseId, view.outputFile);
857
982
  }
858
983
  function readBashDetachView(structured) {
859
984
  if (typeof structured !== 'object' || structured === null)
@@ -865,9 +990,11 @@ function readBashDetachView(structured) {
865
990
  const detached = s.detached;
866
991
  const registerFailed = s.registerFailed;
867
992
  const taskId = s.task_id;
993
+ const outputFile = s.output_file;
868
994
  return {
869
995
  handoffTaskId: detached === true && typeof taskId === 'string' && taskId.length > 0 ? taskId : undefined,
870
996
  registerFailed: registerFailed === true,
997
+ outputFile: typeof outputFile === 'string' && outputFile.length > 0 ? outputFile : undefined,
871
998
  };
872
999
  }
873
1000
  export function todoWriteToolUseResult(rawInput, oldTodos, isError) {
@@ -1,2 +1,15 @@
1
+ import type { UiLanguage } from './env/uiLanguage.js';
2
+ export type ToolOutputMediaAbsence = {
3
+ readonly kind: 'descriptor';
4
+ readonly mediaType: 'image' | 'document';
5
+ readonly mimeType?: string;
6
+ readonly bytes: number;
7
+ } | {
8
+ readonly kind: 'omitted';
9
+ readonly blocks: number;
10
+ readonly bytes: number;
11
+ };
12
+ export declare function toolOutputMediaAbsenceOf(block: object | null | undefined): ToolOutputMediaAbsence | undefined;
13
+ export declare function toolOutputMediaAbsenceSentence(view: ToolOutputMediaAbsence | null | undefined, lang?: UiLanguage): string;
1
14
  export declare function toolResultBlocksOf(output: unknown, truncated: boolean): unknown[] | undefined;
2
15
  export declare function toolEndOutputText(output: unknown): string | undefined;
@@ -1,12 +1,78 @@
1
+ import { msg, renderMessage } from './i18n/translate.js';
2
+ import { readOwnDataValue } from './ownKey.js';
1
3
  const IMAGE_MEDIA_TYPES = Object.freeze(['image/jpeg', 'image/png', 'image/gif', 'image/webp']);
2
4
  const OMITTED_CONTENT_NOTE = '[unsupported content omitted]';
3
5
  const IMAGE_TEXT_PLACEHOLDER = '[image]';
6
+ const ECHOABLE_MIME_TYPE = /^[\x21-\x7e][\x20-\x7e]{0,254}$/;
7
+ function countOf(v, min) {
8
+ return typeof v === 'number' && Number.isSafeInteger(v) && v >= min ? (v === 0 ? 0 : v) : undefined;
9
+ }
10
+ function mimeTypeSlot(o) {
11
+ return Object.hasOwn(o, 'mimeType') ? (readOwnDataValue(o, 'mimeType') ?? null) : undefined;
12
+ }
13
+ function mintAbsence(kind, mediaType, mimeType, blocks, bytes) {
14
+ const size = countOf(bytes, 0);
15
+ if (size === undefined)
16
+ return undefined;
17
+ if (kind === 'omitted') {
18
+ const n = countOf(blocks, 1);
19
+ return n === undefined ? undefined : Object.freeze({ kind: 'omitted', blocks: n, bytes: size });
20
+ }
21
+ if (kind !== 'descriptor' || (mediaType !== 'image' && mediaType !== 'document'))
22
+ return undefined;
23
+ if (mimeType !== undefined && typeof mimeType !== 'string')
24
+ return undefined;
25
+ return Object.freeze(typeof mimeType === 'string' && ECHOABLE_MIME_TYPE.test(mimeType) ? { kind, mediaType, mimeType, bytes: size } : { kind, mediaType, bytes: size });
26
+ }
27
+ export function toolOutputMediaAbsenceOf(block) {
28
+ try {
29
+ if (typeof block !== 'object' || block === null || Array.isArray(block))
30
+ return undefined;
31
+ if (readOwnDataValue(block, 'truncated') !== true)
32
+ return undefined;
33
+ const type = readOwnDataValue(block, 'type');
34
+ const bytes = readOwnDataValue(block, 'bytes');
35
+ if (type === 'omitted')
36
+ return mintAbsence('omitted', undefined, undefined, readOwnDataValue(block, 'blocks'), bytes);
37
+ if (type !== 'image' && type !== 'document')
38
+ return undefined;
39
+ if ('data' in block)
40
+ return undefined;
41
+ return mintAbsence('descriptor', type, mimeTypeSlot(block), undefined, bytes);
42
+ }
43
+ catch {
44
+ return undefined;
45
+ }
46
+ }
47
+ function absenceRefOf(a) {
48
+ if (a.kind === 'omitted') {
49
+ return msg(a.blocks === 1 ? 'session.toolResult.media.notDelivered.omitted.one' : 'session.toolResult.media.notDelivered.omitted.other', { blocks: a.blocks, bytes: a.bytes });
50
+ }
51
+ const kind = msg(a.mediaType === 'image' ? 'session.toolResult.media.kind.image' : 'session.toolResult.media.kind.document');
52
+ return a.mimeType === undefined
53
+ ? msg('session.toolResult.media.notDelivered.descriptorNoMime', { kind, bytes: a.bytes })
54
+ : msg('session.toolResult.media.notDelivered.descriptor', { kind, mimeType: a.mimeType, bytes: a.bytes });
55
+ }
56
+ export function toolOutputMediaAbsenceSentence(view, lang) {
57
+ try {
58
+ if (typeof view !== 'object' || view === null || Array.isArray(view))
59
+ return '';
60
+ const a = mintAbsence(readOwnDataValue(view, 'kind'), readOwnDataValue(view, 'mediaType'), mimeTypeSlot(view), readOwnDataValue(view, 'blocks'), readOwnDataValue(view, 'bytes'));
61
+ return a === undefined ? '' : renderMessage(absenceRefOf(a), lang);
62
+ }
63
+ catch {
64
+ return '';
65
+ }
66
+ }
4
67
  function blockOf(raw) {
5
68
  if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
6
69
  return null;
7
70
  const b = raw;
8
71
  if (b.type === 'text')
9
- return typeof b.text === 'string' ? { type: 'text', text: b.text } : null;
72
+ return typeof b.text === 'string' ? { block: { type: 'text', text: b.text }, undelivered: false } : null;
73
+ const absence = toolOutputMediaAbsenceOf(b);
74
+ if (absence !== undefined)
75
+ return { block: { type: 'text', text: renderMessage(absenceRefOf(absence)) }, undelivered: true };
10
76
  if (b.type !== 'image')
11
77
  return null;
12
78
  const data = b.data;
@@ -15,7 +81,7 @@ function blockOf(raw) {
15
81
  return null;
16
82
  if (typeof mediaType !== 'string' || !IMAGE_MEDIA_TYPES.includes(mediaType))
17
83
  return null;
18
- return { type: 'image', source: { type: 'base64', media_type: mediaType, data } };
84
+ return { block: { type: 'image', source: { type: 'base64', media_type: mediaType, data } }, undelivered: false };
19
85
  }
20
86
  const TRUNCATED_NOTE = '…(truncated)';
21
87
  function toolResultContentOf(output) {
@@ -26,17 +92,26 @@ function toolResultContentOf(output) {
26
92
  const blocks = [];
27
93
  let omitted = 0;
28
94
  let images = 0;
95
+ let undelivered = 0;
29
96
  for (const raw of output) {
30
- const block = blockOf(raw);
31
- if (block === null)
97
+ let read = null;
98
+ try {
99
+ read = blockOf(raw);
100
+ }
101
+ catch {
102
+ read = null;
103
+ }
104
+ if (read === null)
32
105
  omitted++;
33
106
  else {
34
- if (block.type === 'image')
107
+ if (read.block.type === 'image')
35
108
  images++;
36
- blocks.push(block);
109
+ if (read.undelivered)
110
+ undelivered++;
111
+ blocks.push(read.block);
37
112
  }
38
113
  }
39
- if (images === 0 && omitted === 0)
114
+ if (images === 0 && omitted === 0 && undelivered === 0)
40
115
  return blocks.map((b) => b.text).join('');
41
116
  if (omitted > 0)
42
117
  blocks.push({ type: 'text', text: OMITTED_CONTENT_NOTE });
@@ -83,6 +83,7 @@ export declare function handsMountedDetail(reading: HandsMountedReading, lang?:
83
83
  export declare function toolRosterNames(roster: ToolRosterView | undefined): readonly string[];
84
84
  export interface ToolShim {
85
85
  name: string;
86
+ aliases?: readonly string[];
86
87
  source: string;
87
88
  family?: string;
88
89
  userFacingName?: string;
@@ -97,6 +98,23 @@ export interface ToolShim {
97
98
  capabilityId?: string;
98
99
  }
99
100
  export declare function toolShimFromRoster(entry: unknown): ToolShim | undefined;
101
+ export interface EngineRosterPeerTool {
102
+ name: string;
103
+ aliases?: readonly string[];
104
+ cardId?: string;
105
+ }
106
+ export interface EngineRosterPeerGroup {
107
+ peer: string;
108
+ declaredBy?: readonly string[];
109
+ tools: readonly EngineRosterPeerTool[];
110
+ count: number;
111
+ }
112
+ export interface EngineRosterPeersView {
113
+ groups: readonly EngineRosterPeerGroup[];
114
+ unattributed: readonly EngineRosterPeerTool[];
115
+ }
116
+ export declare function projectEngineRosterPeers(roster: ToolRosterView | undefined, source: string): EngineRosterPeersView | undefined;
117
+ export declare function projectEngineA2aPeers(roster: ToolRosterView | undefined): EngineRosterPeersView | undefined;
100
118
  export interface ToolRosterDeltaApplication {
101
119
  roster: ToolRosterView | undefined;
102
120
  applied: boolean;
@@ -205,6 +205,7 @@ export function toolShimFromRoster(entry) {
205
205
  return {
206
206
  name: e.name,
207
207
  source: e.source,
208
+ ...(e.aliases !== undefined ? { aliases: copyStrings(e.aliases) } : {}),
208
209
  ...(e.family !== undefined ? { family: e.family } : {}),
209
210
  ...(e.renderHints?.userFacingName !== undefined ? { userFacingName: e.renderHints.userFacingName } : {}),
210
211
  ...(e.renderHints?.activity !== undefined ? { activity: e.renderHints.activity } : {}),
@@ -218,6 +219,69 @@ export function toolShimFromRoster(entry) {
218
219
  ...(e.capabilityId !== undefined ? { capabilityId: e.capabilityId } : {}),
219
220
  };
220
221
  }
222
+ const compareCodeUnits = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
223
+ function copyStrings(src) {
224
+ const out = [];
225
+ const n = src.length;
226
+ for (let i = 0; i < n; i++) {
227
+ const v = src[i];
228
+ if (typeof v === 'string')
229
+ out.push(v);
230
+ }
231
+ return out;
232
+ }
233
+ function rosterPeerToolOf(e) {
234
+ return {
235
+ name: e.name,
236
+ ...(e.aliases !== undefined ? { aliases: copyStrings(e.aliases) } : {}),
237
+ ...(e.cardId !== undefined ? { cardId: e.cardId } : {}),
238
+ };
239
+ }
240
+ export function projectEngineRosterPeers(roster, source) {
241
+ if (typeof roster !== 'object' || roster === null)
242
+ return undefined;
243
+ if (typeof source !== 'string' || source.length === 0)
244
+ return undefined;
245
+ try {
246
+ const view = readRoster(roster);
247
+ if (view === undefined || view.entries.length !== view.count)
248
+ return undefined;
249
+ const slots = new Map();
250
+ const unattributed = [];
251
+ for (const e of view.entries) {
252
+ if (e.source !== source)
253
+ continue;
254
+ const peer = e.origin?.peer;
255
+ if (peer === undefined) {
256
+ unattributed.push(rosterPeerToolOf(e));
257
+ continue;
258
+ }
259
+ let slot = slots.get(peer);
260
+ if (slot === undefined) {
261
+ slot = { tools: [], declaredBy: new Set() };
262
+ slots.set(peer, slot);
263
+ }
264
+ slot.tools.push(rosterPeerToolOf(e));
265
+ if (e.origin?.declaredBy !== undefined)
266
+ slot.declaredBy.add(e.origin.declaredBy);
267
+ }
268
+ const groups = [...slots.entries()]
269
+ .sort((a, b) => compareCodeUnits(a[0], b[0]))
270
+ .map(([peer, slot]) => ({
271
+ peer,
272
+ ...(slot.declaredBy.size > 0 ? { declaredBy: [...slot.declaredBy].sort(compareCodeUnits) } : {}),
273
+ tools: slot.tools,
274
+ count: slot.tools.length,
275
+ }));
276
+ return { groups, unattributed };
277
+ }
278
+ catch {
279
+ return undefined;
280
+ }
281
+ }
282
+ export function projectEngineA2aPeers(roster) {
283
+ return projectEngineRosterPeers(roster, 'a2a');
284
+ }
221
285
  function readSummary(raw) {
222
286
  const o = obj(raw);
223
287
  if (o === undefined)