@sema-agent/client-core 0.97.1 → 0.99.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (353) hide show
  1. package/CHANGELOG.md +607 -0
  2. package/README.md +96 -46
  3. package/dist/adapt/arms.d.ts +1 -0
  4. package/dist/adapt/arms.js +188 -53
  5. package/dist/adapt/ids.d.ts +12 -1
  6. package/dist/adapt/ids.js +59 -8
  7. package/dist/adapt/instanceLedger.d.ts +50 -0
  8. package/dist/adapt/instanceLedger.js +147 -0
  9. package/dist/adapt/panelTasks.d.ts +1 -1
  10. package/dist/adapt/panelTasks.js +2 -2
  11. package/dist/adapt/textStream.d.ts +1 -0
  12. package/dist/adapt/textStream.js +24 -7
  13. package/dist/adapt/toolCards.d.ts +27 -5
  14. package/dist/adapt/toolCards.js +39 -6
  15. package/dist/adapt/wireShapes.js +6 -2
  16. package/dist/adapt.d.ts +2 -0
  17. package/dist/adapt.js +8 -3
  18. package/dist/adapter/activeRunSelfHeal.d.ts +9 -3
  19. package/dist/adapter/activeRunSelfHeal.js +205 -313
  20. package/dist/adapter/downstream/eventToSdkMessage.d.ts +2 -5
  21. package/dist/adapter/downstream/eventToSdkMessage.js +77 -36
  22. package/dist/adapter/downstream/terminalToSdkResult.js +11 -4
  23. package/dist/adapter/downstream/turnUsageToModelUsage.d.ts +5 -2
  24. package/dist/adapter/downstream/turnUsageToModelUsage.js +2 -0
  25. package/dist/adapter/runStream.js +79 -48
  26. package/dist/adapter/types.d.ts +4 -4
  27. package/dist/adapter/types.js +2 -1
  28. package/dist/agentSession/backgroundView.js +2 -1
  29. package/dist/agentSession/engineAgentRegistryRead.d.ts +2 -2
  30. package/dist/agentSession/engineAgentRegistryRead.js +12 -13
  31. package/dist/agentSession/engineSessionBackgroundStop.js +16 -8
  32. package/dist/agentsWireCaps.d.ts +8 -11
  33. package/dist/agentsWireCaps.js +196 -194
  34. package/dist/approvalDecidedByCapability.d.ts +0 -4
  35. package/dist/approvalDecidedByCapability.js +0 -6
  36. package/dist/approvalsStreamLiveCapability.d.ts +0 -4
  37. package/dist/approvalsStreamLiveCapability.js +0 -6
  38. package/dist/assistantInbox.d.ts +34 -0
  39. package/dist/assistantInbox.js +118 -0
  40. package/dist/centerWiringCapability.js +9 -1
  41. package/dist/clientSlice.d.ts +0 -9
  42. package/dist/clientSlice.js +0 -3
  43. package/dist/cloudConfigWireCaps.d.ts +5 -3
  44. package/dist/cloudConfigWireCaps.js +106 -64
  45. package/dist/compensations.js +1 -1
  46. package/dist/connectorStatus.d.ts +21 -0
  47. package/dist/connectorStatus.js +112 -0
  48. package/dist/controlRouter.d.ts +18 -3
  49. package/dist/controlRouter.js +106 -67
  50. package/dist/coreValuePorts.d.ts +29 -4
  51. package/dist/coreValuePorts.js +10 -0
  52. package/dist/corruptSessionCopy.d.ts +2 -1
  53. package/dist/corruptSessionCopy.js +3 -3
  54. package/dist/decideReceipt.d.ts +2 -2
  55. package/dist/decideReceipt.js +5 -2
  56. package/dist/declared/supportFloorDeclared.js +3 -3
  57. package/dist/detachWire.js +3 -2
  58. package/dist/deviceExecutorManagementCapability.d.ts +0 -4
  59. package/dist/deviceExecutorManagementCapability.js +0 -6
  60. package/dist/deviceRebind.d.ts +49 -1
  61. package/dist/deviceRebind.js +221 -3
  62. package/dist/devicesFace.d.ts +34 -0
  63. package/dist/devicesFace.js +90 -0
  64. package/dist/displayUntrusted.d.ts +2 -0
  65. package/dist/displayUntrusted.js +253 -76
  66. package/dist/engineAgentAbsence.d.ts +1 -1
  67. package/dist/engineAgentPanelStore.d.ts +12 -4
  68. package/dist/engineAgentPanelStore.js +16 -11
  69. package/dist/engineCapReader.d.ts +2 -5
  70. package/dist/engineCapReader.js +8 -10
  71. package/dist/engineCapsCache.d.ts +12 -0
  72. package/dist/engineCapsCache.js +76 -18
  73. package/dist/engineCapsChange.d.ts +2 -0
  74. package/dist/engineCapsChange.js +9 -0
  75. package/dist/engineClosedSets.d.ts +1 -0
  76. package/dist/engineClosedSets.js +4 -1
  77. package/dist/engineErrorCodes.d.ts +11 -3
  78. package/dist/engineErrorCodes.js +11 -8
  79. package/dist/engineIdentity.d.ts +1 -0
  80. package/dist/engineIdentity.js +8 -0
  81. package/dist/engineRowRef.d.ts +28 -0
  82. package/dist/engineRowRef.js +114 -0
  83. package/dist/engineSessionMessages.d.ts +68 -0
  84. package/dist/engineSessionMessages.js +370 -0
  85. package/dist/engineTargetSeat.d.ts +27 -0
  86. package/dist/engineTargetSeat.js +199 -0
  87. package/dist/engineToolDirectory.d.ts +0 -9
  88. package/dist/engineToolDirectory.js +1 -94
  89. package/dist/engineUrl.d.ts +18 -0
  90. package/dist/engineUrl.js +52 -0
  91. package/dist/engineWireFor.js +3 -8
  92. package/dist/env/uiLanguage.d.ts +11 -1
  93. package/dist/env/uiLanguage.js +38 -2
  94. package/dist/eventLeg.d.ts +100 -0
  95. package/dist/eventLeg.js +305 -0
  96. package/dist/executionLaneCapability.d.ts +0 -4
  97. package/dist/executionLaneCapability.js +3 -16
  98. package/dist/fileHistoryCaptureCapability.d.ts +2 -5
  99. package/dist/fileHistoryCaptureCapability.js +13 -21
  100. package/dist/fileHistoryLegNotice.d.ts +2 -1
  101. package/dist/fileHistoryLegNotice.js +3 -3
  102. package/dist/fleet/fleetLedger.d.ts +0 -3
  103. package/dist/fleet/fleetLedger.js +21 -36
  104. package/dist/fleet/fleetProjection.d.ts +2 -2
  105. package/dist/fleet/fleetProjection.js +10 -8
  106. package/dist/frameBinding.d.ts +8 -0
  107. package/dist/frameBinding.js +35 -0
  108. package/dist/gateFailureCodes.d.ts +2 -0
  109. package/dist/gateFailureCodes.js +15 -0
  110. package/dist/gateOutcome.d.ts +3 -1
  111. package/dist/gateOutcome.js +41 -8
  112. package/dist/gateVocabulary.d.ts +10 -4
  113. package/dist/gateVocabulary.js +107 -47
  114. package/dist/generated/engineAskFaceTables.js +2 -2
  115. package/dist/generated/engineFactTables.d.ts +22 -3
  116. package/dist/generated/engineFactTables.js +51 -4
  117. package/dist/generated/engineNoticeTables.js +18 -3
  118. package/dist/generated/settingsSchemaFns.d.ts +6 -0
  119. package/dist/generated/settingsSchemaFns.js +57 -0
  120. package/dist/generated/settingsSchemaHooksClassifier.d.ts +2 -0
  121. package/dist/generated/settingsSchemaHooksClassifier.js +254 -0
  122. package/dist/generated/settingsSchemaTables.d.ts +1 -0
  123. package/dist/generated/settingsSchemaTables.js +4 -0
  124. package/dist/generated/settingsSchemaTypes.d.ts +105 -0
  125. package/dist/generated/settingsSchemaTypes.js +1 -0
  126. package/dist/generated/toolNameTables.d.ts +1 -0
  127. package/dist/generated/toolNameTables.js +1 -0
  128. package/dist/hitl/allowRuleShadow.d.ts +8 -2
  129. package/dist/hitl/allowRuleShadow.js +36 -29
  130. package/dist/hitl/approvalCardReading.d.ts +15 -0
  131. package/dist/hitl/approvalCardReading.js +154 -0
  132. package/dist/hitl/approvalCardReasons.d.ts +14 -0
  133. package/dist/hitl/approvalCardReasons.js +119 -0
  134. package/dist/hitl/approvalHolds.d.ts +50 -15
  135. package/dist/hitl/approvalHolds.js +177 -27
  136. package/dist/hitl/approvalResolution.d.ts +51 -26
  137. package/dist/hitl/approvalResolution.js +86 -122
  138. package/dist/hitl/approvalsFeed.js +6 -18
  139. package/dist/hitl/askClassPair.d.ts +2 -0
  140. package/dist/hitl/askClassPair.js +17 -0
  141. package/dist/hitl/askGateWire.d.ts +20 -2
  142. package/dist/hitl/askGateWire.js +50 -1
  143. package/dist/hitl/askParkRowRouting.d.ts +5 -0
  144. package/dist/hitl/askParkRowRouting.js +32 -1
  145. package/dist/hitl/askSettlementLine.d.ts +28 -0
  146. package/dist/hitl/askSettlementLine.js +99 -0
  147. package/dist/hitl/automaticAnswerVerdict.d.ts +3 -2
  148. package/dist/hitl/automaticAnswerVerdict.js +29 -13
  149. package/dist/hitl/crashConverged.d.ts +11 -20
  150. package/dist/hitl/crashConverged.js +56 -0
  151. package/dist/hitl/crashConvergedNotice.d.ts +6 -3
  152. package/dist/hitl/crashConvergedNotice.js +48 -24
  153. package/dist/hitl/decisionConflict.js +3 -10
  154. package/dist/hitl/decisionRefusal.d.ts +40 -1
  155. package/dist/hitl/decisionRefusal.js +199 -42
  156. package/dist/hitl/frameRouter.d.ts +5 -2
  157. package/dist/hitl/frameRouter.js +27 -24
  158. package/dist/hitl/gateLedger.d.ts +2 -0
  159. package/dist/hitl/gateLedger.js +50 -13
  160. package/dist/hitl/hitlBridge.d.ts +2 -2
  161. package/dist/hitl/hitlBridge.js +13 -10
  162. package/dist/hitl/livePendingAsk.d.ts +3 -3
  163. package/dist/hitl/livePendingAsk.js +7 -18
  164. package/dist/hitl/parkResolver.d.ts +2 -24
  165. package/dist/hitl/parkResolver.js +61 -97
  166. package/dist/hitl/persistedRulesWire.d.ts +25 -0
  167. package/dist/hitl/persistedRulesWire.js +104 -2
  168. package/dist/hitl/planReviewWire.d.ts +31 -13
  169. package/dist/hitl/planReviewWire.js +120 -78
  170. package/dist/hitl/refusedToolNameProse.d.ts +0 -1
  171. package/dist/hitl/refusedToolNameProse.js +0 -3
  172. package/dist/hitl/replayedApproval.d.ts +4 -3
  173. package/dist/hitl/replayedApproval.js +7 -4
  174. package/dist/hitl/sessionPolicyDeliverable.d.ts +2 -0
  175. package/dist/hitl/sessionPolicyDeliverable.js +48 -7
  176. package/dist/hitl/sessionPolicyWire.d.ts +34 -21
  177. package/dist/hitl/sessionPolicyWire.js +179 -70
  178. package/dist/hitl/standingRows.d.ts +20 -2
  179. package/dist/hitl/standingRows.js +69 -8
  180. package/dist/hitl/suspendedReopen.d.ts +2 -1
  181. package/dist/hitl/suspendedReopen.js +7 -10
  182. package/dist/hitl/toolApprovalWire.d.ts +103 -156
  183. package/dist/hitl/toolApprovalWire.js +661 -411
  184. package/dist/hookMatcherVerdict.d.ts +6 -1
  185. package/dist/hookMatcherVerdict.js +14 -7
  186. package/dist/hooksWireCaps.d.ts +2 -2
  187. package/dist/hooksWireCaps.js +174 -81
  188. package/dist/host.d.ts +21 -0
  189. package/dist/hostTurnSettings.d.ts +71 -0
  190. package/dist/hostTurnSettings.js +291 -0
  191. package/dist/humanTurn.d.ts +14 -1
  192. package/dist/humanTurn.js +100 -12
  193. package/dist/humanTurnRead.d.ts +2 -0
  194. package/dist/humanTurnRead.js +22 -1
  195. package/dist/i18n/messages.en.d.ts +703 -0
  196. package/dist/i18n/messages.en.js +701 -0
  197. package/dist/i18n/messages.zh.d.ts +3 -0
  198. package/dist/i18n/messages.zh.js +837 -0
  199. package/dist/i18n/translate.d.ts +25 -0
  200. package/dist/i18n/translate.js +127 -0
  201. package/dist/index.d.ts +78 -29
  202. package/dist/index.js +54 -18
  203. package/dist/inheritEnvCapability.d.ts +32 -0
  204. package/dist/inheritEnvCapability.js +104 -0
  205. package/dist/inheritEnvWire.d.ts +3 -2
  206. package/dist/inheritEnvWire.js +12 -14
  207. package/dist/interactiveHalt.js +17 -6
  208. package/dist/liveModelCatalog.d.ts +3 -3
  209. package/dist/liveModelCatalog.js +15 -13
  210. package/dist/liveQuestionStore.d.ts +2 -21
  211. package/dist/mcpLiveness.d.ts +2 -1
  212. package/dist/mcpPanel.d.ts +10 -1
  213. package/dist/mcpPanel.js +40 -13
  214. package/dist/mcpProbeCapability.d.ts +2 -1
  215. package/dist/mcpProbeCapability.js +7 -11
  216. package/dist/mcpProbeWire.d.ts +9 -2
  217. package/dist/mcpProbeWire.js +6 -1
  218. package/dist/mcpWireCaps.d.ts +47 -2
  219. package/dist/mcpWireCaps.js +164 -16
  220. package/dist/memoryEntriesWire.d.ts +4 -9
  221. package/dist/memoryEntriesWire.js +5 -10
  222. package/dist/model/modelSupplyRules.d.ts +0 -2
  223. package/dist/model/modelSupplyRules.js +3 -12
  224. package/dist/model/modelsPolicy.d.ts +0 -5
  225. package/dist/model/modelsPolicy.js +6 -36
  226. package/dist/model/onboardJudgement.d.ts +93 -0
  227. package/dist/model/onboardJudgement.js +415 -0
  228. package/dist/model/subagentModelWord.d.ts +31 -0
  229. package/dist/model/subagentModelWord.js +261 -0
  230. package/dist/model/tierVocabulary.d.ts +2 -0
  231. package/dist/model/tierVocabulary.js +17 -5
  232. package/dist/modelCapabilityProbe.d.ts +64 -0
  233. package/dist/modelCapabilityProbe.js +600 -0
  234. package/dist/modelIdentityResolvability.d.ts +3 -0
  235. package/dist/modelIdentityResolvability.js +26 -17
  236. package/dist/notifications.d.ts +6 -0
  237. package/dist/notifications.js +71 -23
  238. package/dist/outputStyleSeatCapability.d.ts +0 -3
  239. package/dist/outputStyleSeatCapability.js +0 -3
  240. package/dist/ownKey.d.ts +22 -0
  241. package/dist/ownKey.js +94 -3
  242. package/dist/panelReduce.d.ts +21 -10
  243. package/dist/panelReduce.js +728 -550
  244. package/dist/panelStateHolder.d.ts +3 -7
  245. package/dist/panelStateHolder.js +14 -130
  246. package/dist/peerLaneCapability.d.ts +0 -4
  247. package/dist/peerLaneCapability.js +0 -6
  248. package/dist/permissionRuleIssue.js +2 -0
  249. package/dist/permissionRulesWriteCapability.d.ts +2 -5
  250. package/dist/permissionRulesWriteCapability.js +8 -12
  251. package/dist/permissionWireCaps.d.ts +2 -2
  252. package/dist/permissionWireCaps.js +2 -0
  253. package/dist/permissionsAllowGrantCapability.d.ts +0 -4
  254. package/dist/permissionsAllowGrantCapability.js +0 -6
  255. package/dist/permissionsDeclaration.d.ts +0 -11
  256. package/dist/permissionsDeclaration.js +60 -53
  257. package/dist/pluginHooksWire.d.ts +46 -3
  258. package/dist/pluginHooksWire.js +219 -16
  259. package/dist/preemptWire.d.ts +44 -0
  260. package/dist/preemptWire.js +83 -0
  261. package/dist/printModelStatus.d.ts +63 -0
  262. package/dist/printModelStatus.js +155 -0
  263. package/dist/printToolResultFrame.js +15 -4
  264. package/dist/replayBody.d.ts +3 -0
  265. package/dist/replayBody.js +14 -0
  266. package/dist/request/taskRequest.d.ts +11 -6
  267. package/dist/request/taskRequest.js +112 -19
  268. package/dist/resumeRefusalCopy.d.ts +13 -9
  269. package/dist/resumeRefusalCopy.js +81 -118
  270. package/dist/retryStatus.d.ts +45 -0
  271. package/dist/retryStatus.js +185 -1
  272. package/dist/rewindArchiveCapability.d.ts +0 -4
  273. package/dist/rewindArchiveCapability.js +2 -10
  274. package/dist/rewindArchiveReading.d.ts +0 -1
  275. package/dist/rewindArchiveReading.js +0 -3
  276. package/dist/runCancelContext.d.ts +2 -1
  277. package/dist/runCancelContext.js +4 -2
  278. package/dist/runReattachPolicy.d.ts +31 -0
  279. package/dist/runReattachPolicy.js +46 -0
  280. package/dist/runTerminal.d.ts +3 -6
  281. package/dist/runTerminal.js +8 -9
  282. package/dist/sandboxWire.d.ts +3 -1
  283. package/dist/sandboxWire.js +76 -27
  284. package/dist/scenarioRefusal.d.ts +9 -0
  285. package/dist/scenarioRefusal.js +111 -0
  286. package/dist/scenarioWire.js +1 -1
  287. package/dist/seam.d.ts +48 -2
  288. package/dist/seam.js +25 -4
  289. package/dist/seatContract.d.ts +311 -18
  290. package/dist/seatContract.js +824 -100
  291. package/dist/selfOrchestrationDenial.js +7 -19
  292. package/dist/sessionIdSegment.d.ts +6 -0
  293. package/dist/sessionIdSegment.js +24 -0
  294. package/dist/sessionMemoryStatus.js +6 -11
  295. package/dist/sessionPolicyCapability.d.ts +2 -5
  296. package/dist/sessionPolicyCapability.js +8 -12
  297. package/dist/sessionSyncFileHistoryCapability.d.ts +0 -3
  298. package/dist/sessionSyncFileHistoryCapability.js +0 -3
  299. package/dist/settingsHooksSalvage.d.ts +44 -0
  300. package/dist/settingsHooksSalvage.js +211 -0
  301. package/dist/skillToolListsCapability.d.ts +2 -4
  302. package/dist/skillToolListsCapability.js +8 -9
  303. package/dist/sqlEngineCapability.d.ts +0 -4
  304. package/dist/sqlEngineCapability.js +0 -6
  305. package/dist/sseIdleTriage.js +3 -2
  306. package/dist/steerPriorityCapability.d.ts +0 -3
  307. package/dist/steerPriorityCapability.js +0 -3
  308. package/dist/streamDrainingLegs.d.ts +4 -0
  309. package/dist/streamDrainingLegs.js +6 -1
  310. package/dist/subagent/engineCompactWire.d.ts +0 -1
  311. package/dist/subagent/engineCompactWire.js +7 -5
  312. package/dist/subagent/engineSubagentResume.js +15 -9
  313. package/dist/subagent/engineTaskHandleWire.js +4 -7
  314. package/dist/subagentContentStore.d.ts +3 -0
  315. package/dist/subagentContentStore.js +22 -10
  316. package/dist/submitReopen.d.ts +24 -0
  317. package/dist/submitReopen.js +75 -0
  318. package/dist/terminalStatuses.d.ts +3 -0
  319. package/dist/terminalStatuses.js +10 -2
  320. package/dist/toolHistoryMismatch.js +3 -2
  321. package/dist/toolResult.d.ts +10 -1
  322. package/dist/toolResult.js +34 -6
  323. package/dist/toolRoster.d.ts +3 -4
  324. package/dist/toolRoster.js +21 -22
  325. package/dist/turnFailurePresentation.d.ts +39 -0
  326. package/dist/turnFailurePresentation.js +402 -0
  327. package/dist/usageAnalytics.js +6 -11
  328. package/dist/userAttachmentEnvelope.d.ts +1 -0
  329. package/dist/userAttachmentEnvelope.js +37 -7
  330. package/dist/userAttachmentSeat.d.ts +21 -0
  331. package/dist/userAttachmentSeat.js +75 -0
  332. package/dist/userInvokedSkillsCapability.d.ts +11 -4
  333. package/dist/userInvokedSkillsCapability.js +31 -10
  334. package/dist/webSearchBackendCapability.d.ts +0 -4
  335. package/dist/webSearchBackendCapability.js +0 -6
  336. package/dist/wireErrorTriage.d.ts +7 -0
  337. package/dist/wireErrorTriage.js +26 -23
  338. package/dist/wireFailureShape.d.ts +62 -5
  339. package/dist/wireFailureShape.js +106 -5
  340. package/dist/wireRefusalCopy.d.ts +25 -3
  341. package/dist/wireRefusalCopy.js +74 -80
  342. package/dist/workflowsJournalCapability.d.ts +2 -5
  343. package/dist/workflowsJournalCapability.js +8 -12
  344. package/dist/writeProtectionCapability.d.ts +0 -4
  345. package/dist/writeProtectionCapability.js +0 -6
  346. package/docs/INTEGRATION-CLIENTS.md +1775 -56
  347. package/package.json +6 -5
  348. package/dist/attachmentSeatCapability.d.ts +0 -12
  349. package/dist/attachmentSeatCapability.js +0 -23
  350. package/dist/hitl/approvalOutcomeNote.d.ts +0 -10
  351. package/dist/hitl/approvalOutcomeNote.js +0 -29
  352. package/dist/sessionReadRedactionCapability.d.ts +0 -13
  353. package/dist/sessionReadRedactionCapability.js +0 -35
@@ -0,0 +1,402 @@
1
+ import { msg, renderMessage } from './i18n/translate.js';
2
+ import { classifyTurnWireError, effectiveWireErrorCode, isPreStreamDrainingReject } from './wireErrorTriage.js';
3
+ import { isSseIdleError } from './sseIdleTriage.js';
4
+ import { isCodeClassifiedGateFailure } from './gateFailureCodes.js';
5
+ import { CORRUPT_ROW_ERROR_CODE, CORRUPT_SESSION_ERROR_CODE, MEMORY_CONTROL_PLANE_CORRUPT, SCENARIO_ASSIGNMENT_UNKNOWN_ERROR_CODE } from './engineErrorCodes.js';
6
+ import { bodyShapeRefusalFromError, bodyShapeRefusalTouchesSettings, fleetLeaseUnavailableContent, fleetLeaseUnavailableFromError, hostPostureRefusalContent, hostPostureRefusalFromError, settingsPermissionBucketRefusalContent, settingsPermissionBucketRefusalFromError, toolDeclarationRefusalContent, toolDeclarationRefusalFromError, usageWindowExhaustedContent, usageWindowExhaustedFromError, } from './wireRefusalCopy.js';
7
+ import { THROWN_SLOT_UNREADABLE, readErrorNumber, readThrownSlot, wireFailureTextsOf } from './wireFailureShape.js';
8
+ import { provablyNotSent } from './engineWireFor.js';
9
+ import { corruptStoredRowContent, scenarioDenyFromError, scenarioNotAllowedContent } from './wireErrorTriage.js';
10
+ import { checkpointUnsupportedVersionContent, checkpointUnsupportedVersionFromError, requireExistingSessionRefusalContent, requireExistingSessionRefusalFromError, resumeContextUnavailableContent, resumeContextUnavailableFromError, resumePolicyBlockContent, resumePolicyBlockFromError, resumeRefusalContent, resumeRefusalFromError, } from './resumeRefusalCopy.js';
11
+ import { resumeReopenContent, resumeReopenFromError } from './hitl/suspendedReopen.js';
12
+ import { isCorruptSessionError } from './corruptSession.js';
13
+ import { corruptSessionContent } from './corruptSessionCopy.js';
14
+ import { inheritEnvRefusalContent, inheritEnvRefusalFromError } from './inheritEnvWire.js';
15
+ import { modelCandidateRejectedContent, modelCandidateRejectedOf } from './liveModelCatalog.js';
16
+ const CATEGORY_TABLE = Object.freeze({
17
+ auth: true,
18
+ billing: true,
19
+ rate_limited: true,
20
+ invalid_request: true,
21
+ capability_unavailable: true,
22
+ timeout: true,
23
+ server_error: true,
24
+ connection_lost: true,
25
+ parked: true,
26
+ internal: true,
27
+ });
28
+ export const TURN_FAILURE_CATEGORIES = Object.freeze(Object.keys(CATEGORY_TABLE));
29
+ const TURN_FAILURE_HEADLINE_KEYS = Object.freeze({
30
+ connection_lost_not_sent: 'notice.failure.headline.connectionLostNotSent',
31
+ connection_lost: 'notice.failure.headline.connectionLost',
32
+ timeout: 'notice.failure.headline.timeout',
33
+ parked: 'notice.failure.headline.parked',
34
+ internal: 'notice.failure.headline.internal',
35
+ });
36
+ function waitSecOf(err) {
37
+ const ms = readThrownSlot(err, 'retryAfterMs', 'data');
38
+ if (typeof ms === 'number' && Number.isFinite(ms) && ms > 0)
39
+ return Math.max(1, Math.ceil(ms / 1000));
40
+ if (typeof err === 'object' && err !== null) {
41
+ const bodySec = readErrorNumber(err, 'retryAfterSec');
42
+ if (typeof bodySec === 'number' && Number.isFinite(bodySec) && bodySec > 0)
43
+ return Math.max(1, Math.ceil(bodySec));
44
+ const detail = readThrownSlot(err, 'detail', 'data');
45
+ if (typeof detail === 'object' && detail !== null) {
46
+ const sec = readThrownSlot(detail, 'retryAfterSec', 'data');
47
+ if (typeof sec === 'number' && Number.isFinite(sec) && sec > 0)
48
+ return Math.max(1, Math.ceil(sec));
49
+ }
50
+ }
51
+ return undefined;
52
+ }
53
+ function isIdleWatchdog(err) {
54
+ try {
55
+ return isSseIdleError(err);
56
+ }
57
+ catch {
58
+ return false;
59
+ }
60
+ }
61
+ const DETERMINISTIC_SERVER_CODES = new Set([CORRUPT_SESSION_ERROR_CODE, CORRUPT_ROW_ERROR_CODE, SCENARIO_ASSIGNMENT_UNKNOWN_ERROR_CODE, MEMORY_CONTROL_PLANE_CORRUPT]);
62
+ const BROWSER_FETCH_FAILURE = /\bfailed to fetch\b|\bnetworkerror\b|\bnetwork error\b|\bload failed\b/i;
63
+ function httpShapeOf(err, verdict) {
64
+ const status = verdict.status;
65
+ const code = effectiveWireErrorCode(err) ?? verdict.errorCode;
66
+ if (verdict.sessionUnreadable === true || verdict.storedRowWhere !== undefined)
67
+ return { category: 'server_error', offer: false };
68
+ if (toolDeclarationRefusalFromError(err) !== null)
69
+ return { category: 'invalid_request', offer: false };
70
+ if (code !== undefined && DETERMINISTIC_SERVER_CODES.has(code))
71
+ return { category: 'server_error', offer: false };
72
+ if (code === 'quota_exhausted')
73
+ return { category: 'rate_limited', offer: false };
74
+ if (code === 'budget.precall' || code === 'budget.exceeded')
75
+ return { category: 'billing', offer: false };
76
+ if (code === 'draining' || verdict.leaseUnavailable === true || isPreStreamDrainingReject(err))
77
+ return { category: 'server_error', offer: true };
78
+ if (status === 501 || (code !== undefined && code.startsWith('capability.')))
79
+ return { category: 'capability_unavailable', offer: false };
80
+ if (status === 401 || status === 403)
81
+ return { category: 'auth', offer: false };
82
+ if (status === 402)
83
+ return { category: 'billing', offer: false };
84
+ if (status === 408)
85
+ return { category: 'timeout', offer: true };
86
+ if (status === 429)
87
+ return { category: 'rate_limited', offer: true };
88
+ if (status >= 500)
89
+ return { category: 'server_error', offer: true };
90
+ if (status >= 400)
91
+ return { category: 'invalid_request', offer: false };
92
+ return { category: 'internal', offer: false };
93
+ }
94
+ function connectionLostBeforeSend(err, evidence) {
95
+ if (readThrownSlot(evidence, 'bound', 'data') === true || readThrownSlot(evidence, 'reopened', 'data') === true)
96
+ return false;
97
+ return typeof err === 'object' && err !== null && provablyNotSent(err);
98
+ }
99
+ export function turnFailurePresentation(err, evidence, notesCtx, lang) {
100
+ const verdict = classifyTurnWireError(err);
101
+ let shape;
102
+ let headlineKey;
103
+ let detail;
104
+ let name;
105
+ if (verdict.kind === 'http') {
106
+ shape = httpShapeOf(err, verdict);
107
+ detail = verdict.message;
108
+ if (shape.category === 'internal')
109
+ headlineKey = TURN_FAILURE_HEADLINE_KEYS.internal;
110
+ }
111
+ else if (verdict.kind === 'stream-ended-without-terminal') {
112
+ shape = { category: 'parked', offer: false };
113
+ headlineKey = TURN_FAILURE_HEADLINE_KEYS.parked;
114
+ detail = wireFailureTextsOf(err).reason;
115
+ }
116
+ else if (verdict.kind === 'transport') {
117
+ const notSent = connectionLostBeforeSend(err, evidence);
118
+ shape = { category: 'connection_lost', offer: notSent };
119
+ headlineKey = notSent ? TURN_FAILURE_HEADLINE_KEYS.connection_lost_not_sent : TURN_FAILURE_HEADLINE_KEYS.connection_lost;
120
+ detail = verdict.detail;
121
+ }
122
+ else if (isIdleWatchdog(err)) {
123
+ shape = { category: 'timeout', offer: true };
124
+ headlineKey = TURN_FAILURE_HEADLINE_KEYS.timeout;
125
+ detail = verdict.detail;
126
+ }
127
+ else if (BROWSER_FETCH_FAILURE.test(verdict.detail)) {
128
+ const notSent = connectionLostBeforeSend(err, evidence);
129
+ shape = { category: 'connection_lost', offer: notSent };
130
+ headlineKey = notSent ? TURN_FAILURE_HEADLINE_KEYS.connection_lost_not_sent : TURN_FAILURE_HEADLINE_KEYS.connection_lost;
131
+ detail = verdict.detail;
132
+ }
133
+ else {
134
+ shape = { category: 'internal', offer: false };
135
+ headlineKey = TURN_FAILURE_HEADLINE_KEYS.internal;
136
+ detail = verdict.detail;
137
+ name = verdict.name;
138
+ }
139
+ const status = verdict.kind === 'http' ? verdict.status : undefined;
140
+ const errorCode = verdict.kind === 'http' ? (effectiveWireErrorCode(err) ?? verdict.errorCode) : undefined;
141
+ const wireRetriable = readThrownSlot(err, 'retriable', 'data') === true && !isCodeClassifiedGateFailure(errorCode, true);
142
+ const retry = wireRetriable && shape.category !== 'parked' ? { offer: true, basis: 'wire' } : { offer: shape.offer, basis: 'category' };
143
+ const waitSec = waitSecOf(err);
144
+ const chain = turnFailureNotesOf(err, verdict, notesCtx, waitSec, lang);
145
+ const headline = headlineKey !== undefined ? renderMessage(msg(headlineKey), lang) : undefined;
146
+ return Object.freeze({
147
+ category: shape.category,
148
+ kind: verdict.kind,
149
+ ...(status !== undefined ? { status } : {}),
150
+ ...(errorCode !== undefined ? { errorCode } : {}),
151
+ detail,
152
+ ...(headline !== undefined ? { headline } : {}),
153
+ ...(name !== undefined ? { name } : {}),
154
+ retry: Object.freeze(retry),
155
+ ...(waitSec !== undefined ? { waitSec } : {}),
156
+ notes: chain.notes,
157
+ ...(chain.waitNote !== undefined ? { waitNote: chain.waitNote } : {}),
158
+ });
159
+ }
160
+ function quotaDetailOf(err) {
161
+ if (readThrownSlot(err, 'status', 'data') !== 429 || readThrownSlot(err, 'errorCode', 'data') !== 'quota_exhausted')
162
+ return null;
163
+ const detail = readThrownSlot(err, 'detail', 'data');
164
+ const slot = (key) => (typeof detail === 'object' && detail !== null ? readThrownSlot(detail, key, 'data') : undefined);
165
+ const windowType = slot('windowType');
166
+ const remaining = slot('remaining');
167
+ const resetAt = slot('resetAt');
168
+ const isEstimate = slot('isEstimate');
169
+ const pool = slot('pool');
170
+ return {
171
+ ...(windowType === 'fiveHour' || windowType === 'weekly' || windowType === 'budget' ? { windowType } : {}),
172
+ ...(typeof remaining === 'number' && Number.isFinite(remaining) ? { remaining } : {}),
173
+ ...(typeof resetAt === 'string' || resetAt === null ? { resetAt } : {}),
174
+ ...(typeof isEstimate === 'boolean' ? { isEstimate } : {}),
175
+ ...(typeof pool === 'string' && pool.length > 0 ? { pool } : {}),
176
+ };
177
+ }
178
+ const MONTH_KEYS = [
179
+ 'notice.failure.month.jan',
180
+ 'notice.failure.month.feb',
181
+ 'notice.failure.month.mar',
182
+ 'notice.failure.month.apr',
183
+ 'notice.failure.month.may',
184
+ 'notice.failure.month.jun',
185
+ 'notice.failure.month.jul',
186
+ 'notice.failure.month.aug',
187
+ 'notice.failure.month.sep',
188
+ 'notice.failure.month.oct',
189
+ 'notice.failure.month.nov',
190
+ 'notice.failure.month.dec',
191
+ ];
192
+ function quotaResetInstant(resetAtIso, nowMs, lang) {
193
+ const t = Date.parse(resetAtIso);
194
+ if (!Number.isFinite(t))
195
+ return undefined;
196
+ const d = new Date(t);
197
+ const now = new Date(nowMs);
198
+ const hm = `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
199
+ const sameDay = d.getFullYear() === now.getFullYear() && d.getMonth() === now.getMonth() && d.getDate() === now.getDate();
200
+ if (sameDay)
201
+ return hm;
202
+ const monthKey = MONTH_KEYS[d.getMonth()];
203
+ return renderMessage(msg('notice.failure.quota.instantOtherDay', { month: monthKey === undefined ? '' : msg(monthKey), day: d.getDate(), time: hm }), lang);
204
+ }
205
+ function quotaExhaustedLine(detail, nowMs, lang) {
206
+ const part = (key, params) => renderMessage(msg(key, params), lang);
207
+ const parts = [];
208
+ if (detail.windowType === 'fiveHour')
209
+ parts.push(part('notice.failure.quota.fiveHour'));
210
+ else if (detail.windowType === 'weekly')
211
+ parts.push(part('notice.failure.quota.weekly'));
212
+ else if (detail.windowType === 'budget') {
213
+ if (detail.pool === 'personal')
214
+ parts.push(part('notice.failure.quota.budgetPersonal'));
215
+ else if (detail.pool)
216
+ parts.push(part('notice.failure.quota.budgetPool', { pool: detail.pool }));
217
+ else
218
+ parts.push(part('notice.failure.quota.budget'));
219
+ }
220
+ else
221
+ parts.push(part('notice.failure.quota.usage'));
222
+ if (typeof detail.remaining === 'number' && Number.isFinite(detail.remaining)) {
223
+ parts.push(detail.windowType === 'budget'
224
+ ? part('notice.failure.quota.remainingBudget', { amount: `$${(detail.remaining / 1_000_000).toFixed(2)}` })
225
+ : part('notice.failure.quota.remainingTokens', { count: detail.remaining.toLocaleString('en-US') }));
226
+ }
227
+ const resetText = typeof detail.resetAt === 'string' ? quotaResetInstant(detail.resetAt, nowMs, lang) : undefined;
228
+ if (resetText)
229
+ parts.push(detail.isEstimate === false ? part('notice.failure.quota.resetAt', { time: resetText }) : part('notice.failure.quota.resetAround', { time: resetText }));
230
+ parts.push(part('notice.failure.quota.refresh'));
231
+ parts.push(part('notice.failure.quota.noBypass'));
232
+ return parts.join(part('notice.failure.quota.join'));
233
+ }
234
+ function protectiveSettingsAtRisk(sent, lang) {
235
+ const out = [];
236
+ const permsRaw = sent.permissions;
237
+ const perms = typeof permsRaw === 'object' && permsRaw !== null ? permsRaw : {};
238
+ const deny = Array.isArray(perms.deny) ? perms.deny.length : 0;
239
+ const ask = Array.isArray(perms.ask) ? perms.ask.length : 0;
240
+ if (deny > 0)
241
+ out.push(renderMessage(msg(deny === 1 ? 'notice.failure.settings.denyRules.one' : 'notice.failure.settings.denyRules.other', { count: deny }), lang));
242
+ if (ask > 0)
243
+ out.push(renderMessage(msg(ask === 1 ? 'notice.failure.settings.askRules.one' : 'notice.failure.settings.askRules.other', { count: ask }), lang));
244
+ if (perms.disableBypassPermissionsMode !== undefined)
245
+ out.push('permissions.disableBypassPermissionsMode');
246
+ if (perms.disableAutoMode !== undefined)
247
+ out.push('permissions.disableAutoMode');
248
+ if (typeof perms.defaultMode === 'string')
249
+ out.push('permissions.defaultMode');
250
+ return out;
251
+ }
252
+ function settingsBodyShapeNote(err, sentRequest, lang) {
253
+ if (readThrownSlot(err, 'status', 'data') !== 400 || readThrownSlot(err, 'errorCode', 'data') !== 'request.body_shape')
254
+ return undefined;
255
+ const touches = bodyShapeRefusalTouchesSettings(bodyShapeRefusalFromError(err), sentRequest);
256
+ if (touches === false)
257
+ return undefined;
258
+ const rawSettings = sentRequest === undefined ? undefined : readThrownSlot(sentRequest, 'settings', 'data');
259
+ if (typeof rawSettings !== 'object' || rawSettings === null || Array.isArray(rawSettings))
260
+ return undefined;
261
+ const sentSettings = rawSettings;
262
+ if (Object.keys(sentSettings).length === 0)
263
+ return undefined;
264
+ const lines = [renderMessage(msg('notice.failure.settings.lead'), lang)];
265
+ const atRisk = protectiveSettingsAtRisk(sentSettings, lang);
266
+ if (atRisk.length > 0) {
267
+ lines.push(renderMessage(msg('notice.failure.settings.safety', { risks: atRisk.join(renderMessage(msg('notice.failure.settings.riskJoin'), lang)) }), lang));
268
+ lines.push(renderMessage(msg('notice.failure.settings.stillLocal'), lang));
269
+ }
270
+ return lines.join('\n');
271
+ }
272
+ function isRefusedRequest(err) {
273
+ const status = readThrownSlot(err, 'status', 'data');
274
+ return typeof status === 'number' && status >= 400 && status < 500;
275
+ }
276
+ function waitSentence(sec, lang) {
277
+ return renderMessage(sec === 1 ? msg('notice.failure.wait.one') : msg('notice.failure.wait.other', { seconds: sec }), lang);
278
+ }
279
+ function turnFailureNotesOf(err, verdict, ctx, waitSec, lang) {
280
+ const lines = [];
281
+ try {
282
+ const sentRequest = ctx === undefined ? undefined : ctx.sentRequest;
283
+ const nowMs = ctx !== undefined && typeof ctx.nowMs === 'number' && Number.isFinite(ctx.nowMs) ? ctx.nowMs : Date.now();
284
+ const quota = quotaDetailOf(err);
285
+ if (quota)
286
+ lines.push(quotaExhaustedLine(quota, nowMs, lang));
287
+ const scenarioDeny = quota ? null : scenarioDenyFromError(err);
288
+ if (scenarioDeny)
289
+ lines.push(scenarioNotAllowedContent(scenarioDeny, ctx?.requestedScenario));
290
+ const resumeRefusal = quota || scenarioDeny ? null : resumeRefusalFromError(err);
291
+ if (resumeRefusal)
292
+ lines.push(resumeRefusalContent(resumeRefusal, lang));
293
+ const requireExisting = quota || scenarioDeny || resumeRefusal ? null : requireExistingSessionRefusalFromError(err);
294
+ if (requireExisting)
295
+ lines.push(requireExistingSessionRefusalContent(requireExisting, lang));
296
+ const resumeReopen = quota || scenarioDeny || resumeRefusal || requireExisting ? null : resumeReopenFromError(err);
297
+ if (resumeReopen)
298
+ lines.push(resumeReopenContent(resumeReopen, lang));
299
+ const resumeGone = quota || scenarioDeny || resumeRefusal || requireExisting || resumeReopen ? null : resumeContextUnavailableFromError(err);
300
+ if (resumeGone)
301
+ lines.push(resumeContextUnavailableContent(resumeGone, lang));
302
+ const checkpointUnsupported = quota || scenarioDeny || resumeRefusal || requireExisting || resumeReopen || resumeGone ? null : checkpointUnsupportedVersionFromError(err);
303
+ if (checkpointUnsupported)
304
+ lines.push(checkpointUnsupportedVersionContent(checkpointUnsupported, undefined, lang));
305
+ const storedRowWhere = quota || scenarioDeny || resumeRefusal || resumeReopen || resumeGone ? undefined : verdict.kind === 'http' ? verdict.storedRowWhere : undefined;
306
+ if (storedRowWhere !== undefined)
307
+ lines.push(corruptStoredRowContent(storedRowWhere));
308
+ if (storedRowWhere === undefined && isCorruptSessionError(err))
309
+ lines.push(corruptSessionContent(lang));
310
+ const usageWindow = quota || scenarioDeny || resumeRefusal || resumeReopen || resumeGone ? null : usageWindowExhaustedFromError(err);
311
+ if (usageWindow)
312
+ lines.push(usageWindowExhaustedContent(usageWindow));
313
+ const hostPosture = quota || scenarioDeny || resumeRefusal || resumeReopen || resumeGone || storedRowWhere !== undefined ? null : hostPostureRefusalFromError(err, sentRequest);
314
+ if (hostPosture)
315
+ lines.push(hostPostureRefusalContent(hostPosture));
316
+ const inheritEnv = hostPosture ? null : inheritEnvRefusalFromError(err, sentRequest);
317
+ if (inheritEnv)
318
+ lines.push(inheritEnvRefusalContent(inheritEnv, lang));
319
+ const bucket = inheritEnv ? null : settingsPermissionBucketRefusalFromError(err);
320
+ const toolDecl = toolDeclarationRefusalFromError(err);
321
+ if (toolDecl)
322
+ lines.push(toolDeclarationRefusalContent(toolDecl));
323
+ const lease = fleetLeaseUnavailableFromError(err);
324
+ if (lease)
325
+ lines.push(fleetLeaseUnavailableContent(lease));
326
+ const policyBlock = quota || scenarioDeny || resumeRefusal || resumeReopen || resumeGone || usageWindow || hostPosture ? null : resumePolicyBlockFromError(err);
327
+ if (policyBlock)
328
+ lines.push(resumePolicyBlockContent(policyBlock, lang));
329
+ if (bucket)
330
+ lines.push(settingsPermissionBucketRefusalContent(bucket));
331
+ const settingsRefusal = settingsBodyShapeNote(err, sentRequest, lang);
332
+ if (settingsRefusal !== undefined)
333
+ lines.push(settingsRefusal);
334
+ if (isRefusedRequest(err) && ctx !== undefined && ctx.modelCatalog !== undefined) {
335
+ const rejected = modelCandidateRejectedContent(modelCandidateRejectedOf(ctx.modelCatalog), lang);
336
+ if (rejected !== undefined)
337
+ lines.push(rejected);
338
+ }
339
+ return Object.freeze({ notes: Object.freeze(lines), ...(waitSec !== undefined && !lease && !usageWindow ? { waitNote: waitSentence(waitSec, lang) } : {}) });
340
+ }
341
+ catch {
342
+ return Object.freeze({ notes: Object.freeze(lines) });
343
+ }
344
+ }
345
+ export function seatTurnFailureOf(err, evidence) {
346
+ const p = turnFailurePresentation(err, evidence);
347
+ return {
348
+ category: p.category,
349
+ retry: { offer: p.retry.offer, basis: p.retry.basis },
350
+ ...(p.waitSec !== undefined ? { waitSec: p.waitSec } : {}),
351
+ ...(p.headline !== undefined ? { headline: p.headline } : {}),
352
+ ...(p.errorCode !== undefined ? { errorCode: p.errorCode } : {}),
353
+ };
354
+ }
355
+ function seatDataField(o, key) {
356
+ const v = readThrownSlot(o, key, 'data');
357
+ return v === THROWN_SLOT_UNREADABLE ? SEAT_UNREADABLE : v;
358
+ }
359
+ const SEAT_UNREADABLE = Symbol('seat-unreadable');
360
+ export function readSeatTurnFailure(event) {
361
+ try {
362
+ return seatTurnFailureShapeOf(event);
363
+ }
364
+ catch {
365
+ return undefined;
366
+ }
367
+ }
368
+ function seatTurnFailureShapeOf(event) {
369
+ if (event === null || event === undefined || typeof event !== 'object' || Array.isArray(event))
370
+ return undefined;
371
+ if (seatDataField(event, 'type') !== 'error')
372
+ return undefined;
373
+ const raw = seatDataField(event, '_sema_turnFailure');
374
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
375
+ return undefined;
376
+ const category = seatDataField(raw, 'category');
377
+ if (!TURN_FAILURE_CATEGORIES.includes(category))
378
+ return undefined;
379
+ const retry = seatDataField(raw, 'retry');
380
+ if (retry === null || typeof retry !== 'object' || Array.isArray(retry))
381
+ return undefined;
382
+ const offer = seatDataField(retry, 'offer');
383
+ const basis = seatDataField(retry, 'basis');
384
+ if (typeof offer !== 'boolean' || (basis !== 'wire' && basis !== 'category'))
385
+ return undefined;
386
+ const waitSec = seatDataField(raw, 'waitSec');
387
+ if (waitSec !== undefined && !(typeof waitSec === 'number' && Number.isInteger(waitSec) && waitSec >= 1))
388
+ return undefined;
389
+ const headline = seatDataField(raw, 'headline');
390
+ if (headline !== undefined && !(typeof headline === 'string' && headline.length > 0))
391
+ return undefined;
392
+ const errorCode = seatDataField(raw, 'errorCode');
393
+ if (errorCode !== undefined && !(typeof errorCode === 'string' && errorCode.length > 0))
394
+ return undefined;
395
+ return Object.freeze({
396
+ category: category,
397
+ retry: Object.freeze({ offer, basis }),
398
+ ...(waitSec !== undefined ? { waitSec } : {}),
399
+ ...(headline !== undefined ? { headline } : {}),
400
+ ...(errorCode !== undefined ? { errorCode } : {}),
401
+ });
402
+ }
@@ -1,3 +1,4 @@
1
+ import { readThrownSlot, THROWN_SLOT_UNREADABLE } from './wireFailureShape.js';
1
2
  export const USAGE_SENTENCES = Object.freeze({
2
3
  analyticsUnavailable: 'Usage analytics aren’t available on this backend.',
3
4
  analyticsUnread: 'Usage analytics couldn’t be read just now.',
@@ -10,18 +11,12 @@ const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v)
10
11
  const nonNeg = (v) => typeof v === 'number' && Number.isFinite(v) && v >= 0;
11
12
  const nonEmpty = (v) => typeof v === 'string' && v.length > 0;
12
13
  export function classifyUsageFailure(e) {
13
- let code;
14
- let status;
15
- try {
16
- const o = e;
17
- const rawCode = o?.errorCode;
18
- const rawStatus = o?.status;
19
- code = typeof rawCode === 'string' ? rawCode : undefined;
20
- status = typeof rawStatus === 'number' ? rawStatus : undefined;
21
- }
22
- catch {
14
+ const rawCode = readThrownSlot(e, 'errorCode', 'data');
15
+ const rawStatus = readThrownSlot(e, 'status', 'data');
16
+ if (rawCode === THROWN_SLOT_UNREADABLE || rawStatus === THROWN_SLOT_UNREADABLE)
23
17
  return { kind: 'failed', error: e };
24
- }
18
+ const code = typeof rawCode === 'string' ? rawCode : undefined;
19
+ const status = typeof rawStatus === 'number' ? rawStatus : undefined;
25
20
  if (code !== undefined) {
26
21
  if (code.startsWith('capability.'))
27
22
  return { kind: 'unavailable', why: 'capability' };
@@ -78,5 +78,6 @@ export type UserAttachmentDescriptor = {
78
78
  };
79
79
  export declare function showAttachmentName(s: string): string;
80
80
  export declare function mintEnvelopeOf(d: DescriptorView, imageDelivery: 'attached' | 'not-attached'): string;
81
+ export declare function seatTextOf(d: DescriptorView): string | undefined;
81
82
  export declare function mintReferenceOf(d: DescriptorView): string;
82
83
  export declare function mintUserAttachmentEnvelope(descriptor: UserAttachmentDescriptor): string;
@@ -83,11 +83,7 @@ function mintText(d) {
83
83
  : `Full path: ${path} (lines ${d.startLine}–${d.startLine + n - 1} of ${d.totalLines}; the other lines are not included). The client read it from disk and copied those lines between the two fence lines below. ${dataNote(d.source, "the file's contents")}`;
84
84
  return fenced(anyEscaped ? [l1, l2, ESCAPE_NOTE] : [l1, l2], body);
85
85
  }
86
- function mintNotebook(d) {
87
- const path = showAttachmentName(d.path);
88
- const l1 = firstLine(d.source, 'a Jupyter notebook', d.name);
89
- if (d.cells.length === 0)
90
- return `${l1}\nFull path: ${path} (0 cells). The client read it from disk; it has no cells.`;
86
+ function notebookBody(d) {
91
87
  let cellsWithImages = 0;
92
88
  let cellsWithOversized = 0;
93
89
  const parts = [];
@@ -113,9 +109,16 @@ function mintNotebook(d) {
113
109
  if (hasImage)
114
110
  cellsWithImages++;
115
111
  }
112
+ return { text: parts.join('\n'), cellsWithImages, cellsWithOversized };
113
+ }
114
+ function mintNotebook(d) {
115
+ const path = showAttachmentName(d.path);
116
+ const l1 = firstLine(d.source, 'a Jupyter notebook', d.name);
117
+ if (d.cells.length === 0)
118
+ return `${l1}\nFull path: ${path} (0 cells). The client read it from disk; it has no cells.`;
119
+ const { text, cellsWithImages, cellsWithOversized } = notebookBody(d);
116
120
  let anyEscaped = false;
117
- const body = parts
118
- .join('\n')
121
+ const body = text
119
122
  .split('\n')
120
123
  .map((line, i) => {
121
124
  const shown = showBodyLine(line);
@@ -281,6 +284,33 @@ function referenceSentence(d) {
281
284
  }
282
285
  return `The user mentioned the ${what} ${name} (${path}) in this message; its contents are not included here.`;
283
286
  }
287
+ export function seatTextOf(d) {
288
+ let text;
289
+ switch (d.kind) {
290
+ case 'text':
291
+ if (d.source !== 'at-mention' || !d.complete || d.lines.length === 0)
292
+ return undefined;
293
+ text = d.lines.join('\n');
294
+ break;
295
+ case 'notebook': {
296
+ if (d.source !== 'at-mention' || d.cells.length === 0)
297
+ return undefined;
298
+ const body = notebookBody(d);
299
+ if (body.cellsWithImages > 0 || body.cellsWithOversized > 0)
300
+ return undefined;
301
+ text = body.text;
302
+ break;
303
+ }
304
+ case 'directory':
305
+ if (d.entries.length === 0 || d.totalEntries > d.entries.length)
306
+ return undefined;
307
+ text = d.entries.map(showAttachmentName).join('\n');
308
+ break;
309
+ default:
310
+ return undefined;
311
+ }
312
+ return text.length > 0 ? text : undefined;
313
+ }
284
314
  export function mintReferenceOf(d) {
285
315
  return `${TAG_OPEN}${tagAttributes(d)} />\n${referenceSentence(d)}`;
286
316
  }
@@ -0,0 +1,21 @@
1
+ export interface UserAttachmentSeatLimits {
2
+ readonly maxEntries: number;
3
+ readonly maxRenderedTextChars: number;
4
+ }
5
+ export interface UserAttachmentSeatPresent {
6
+ readonly kind: 'present';
7
+ readonly entries: readonly string[];
8
+ readonly kinds: readonly string[];
9
+ readonly supplies: readonly string[];
10
+ readonly limits: UserAttachmentSeatLimits;
11
+ }
12
+ export type UserAttachmentSeatReading = {
13
+ kind: 'unobserved';
14
+ } | {
15
+ kind: 'unreadable';
16
+ } | {
17
+ kind: 'not_reported';
18
+ } | UserAttachmentSeatPresent;
19
+ export declare function projectUserAttachmentSeatCapability(caps: {} | null | undefined): UserAttachmentSeatReading | undefined;
20
+ export declare function observedUserAttachmentSeat(baseUrl?: string | undefined): UserAttachmentSeatReading;
21
+ export declare function userAttachmentSeatAdmits(reading: UserAttachmentSeatReading | undefined): 'yes' | 'no' | 'unknown';
@@ -0,0 +1,75 @@
1
+ import { engineWireTarget } from './engineWireTarget.js';
2
+ import { createEngineCapReader } from './engineCapReader.js';
3
+ import { ownDataField, readOwnDataValue } from './ownKey.js';
4
+ const _seatPin = [true, true];
5
+ void _seatPin;
6
+ function stringList(v) {
7
+ if (!Array.isArray(v))
8
+ return undefined;
9
+ const n = ownDataField(v, 'length');
10
+ if (typeof n !== 'number' || !Number.isSafeInteger(n) || n < 0)
11
+ return undefined;
12
+ const out = [];
13
+ for (let i = 0; i < n; i += 1) {
14
+ const d = Object.getOwnPropertyDescriptor(v, i);
15
+ if (d === undefined || !('value' in d) || typeof d.value !== 'string')
16
+ return undefined;
17
+ out.push(d.value);
18
+ }
19
+ return out;
20
+ }
21
+ const positiveInt = (v) => (typeof v === 'number' && Number.isSafeInteger(v) && v >= 1 ? v : undefined);
22
+ const isPlainRecord = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
23
+ export function projectUserAttachmentSeatCapability(caps) {
24
+ try {
25
+ if (!isPlainRecord(caps))
26
+ return undefined;
27
+ const seat = ownDataField(caps, 'userAttachments');
28
+ if (seat === undefined)
29
+ return { kind: 'not_reported' };
30
+ if (!isPlainRecord(seat))
31
+ return undefined;
32
+ const entries = stringList(ownDataField(seat, 'entries'));
33
+ const kinds = stringList(ownDataField(seat, 'kinds'));
34
+ const supplies = stringList(ownDataField(seat, 'supplies'));
35
+ const limits = ownDataField(seat, 'limits');
36
+ if (entries === undefined || kinds === undefined || supplies === undefined || !isPlainRecord(limits))
37
+ return undefined;
38
+ const maxEntries = positiveInt(ownDataField(limits, 'maxEntries'));
39
+ const maxRenderedTextChars = positiveInt(ownDataField(limits, 'maxRenderedTextChars'));
40
+ if (maxEntries === undefined || maxRenderedTextChars === undefined)
41
+ return undefined;
42
+ return { kind: 'present', entries, kinds, supplies, limits: { maxEntries, maxRenderedTextChars } };
43
+ }
44
+ catch {
45
+ return undefined;
46
+ }
47
+ }
48
+ const reader = createEngineCapReader({ name: 'userAttachments', project: projectUserAttachmentSeatCapability });
49
+ export function observedUserAttachmentSeat(baseUrl = engineWireTarget()?.baseUrl) {
50
+ return reader.observed(baseUrl);
51
+ }
52
+ export function userAttachmentSeatAdmits(reading) {
53
+ try {
54
+ if (!isPlainRecord(reading))
55
+ return 'unknown';
56
+ const kind = readOwnDataValue(reading, 'kind');
57
+ if (kind === 'not_reported')
58
+ return 'no';
59
+ if (kind !== 'present')
60
+ return 'unknown';
61
+ const has = (key, word) => {
62
+ const list = stringList(readOwnDataValue(reading, key));
63
+ return list === undefined ? undefined : list.includes(word);
64
+ };
65
+ const objective = has('entries', 'objective');
66
+ const text = has('supplies', 'content_text');
67
+ const client = has('kinds', 'client_text');
68
+ if (objective === undefined || text === undefined || client === undefined)
69
+ return 'unknown';
70
+ return objective && text && client ? 'yes' : 'no';
71
+ }
72
+ catch {
73
+ return 'unknown';
74
+ }
75
+ }
@@ -1,3 +1,4 @@
1
+ import type { UiLanguage } from './env/uiLanguage.js';
1
2
  export type UserInvokedSkillsReading = {
2
3
  kind: 'unobserved';
3
4
  } | {
@@ -10,9 +11,15 @@ export type UserInvokedSkillsReading = {
10
11
  kind: 'present';
11
12
  };
12
13
  export declare function projectUserInvokedSkillsCapability(caps: unknown): UserInvokedSkillsReading | undefined;
13
- export declare function noteEngineCapsForUserInvokedSkills(baseUrl: string, caps: unknown, opts?: {
14
- generation?: number;
15
- }): void;
16
14
  export declare function observedUserInvokedSkills(baseUrl?: string | undefined): UserInvokedSkillsReading;
17
15
  export declare function userInvokedSkillsAvailable(reading: UserInvokedSkillsReading): 'yes' | 'no' | 'unknown';
18
- export declare function userInvokedSkillsDoctorDetail(reading: UserInvokedSkillsReading): string;
16
+ export declare function userInvokedSkillsDoctorDetail(reading: UserInvokedSkillsReading, lang?: UiLanguage): string;
17
+ export interface UserInvokedSkillsDeclaration {
18
+ readonly field: {
19
+ readonly userInvokedSkills?: readonly string[];
20
+ };
21
+ readonly withheld?: {
22
+ readonly cause: Exclude<UserInvokedSkillsReading['kind'], 'present'>;
23
+ };
24
+ }
25
+ export declare function userInvokedSkillsDeclaration(names: readonly string[] | null | undefined, reading: UserInvokedSkillsReading): UserInvokedSkillsDeclaration;