@sema-agent/client-core 0.94.0 → 0.96.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 (332) hide show
  1. package/CHANGELOG.md +521 -0
  2. package/README.md +104 -57
  3. package/dist/adapt/arms.js +12 -7
  4. package/dist/adapt/panelTasks.js +4 -10
  5. package/dist/adapt/toolCards.d.ts +1 -0
  6. package/dist/adapt/toolCards.js +18 -5
  7. package/dist/adapt/wireShapes.js +5 -24
  8. package/dist/adapter/activeRunSelfHeal.d.ts +12 -3
  9. package/dist/adapter/activeRunSelfHeal.js +50 -16
  10. package/dist/adapter/downstream/eventToSdkMessage.js +33 -18
  11. package/dist/adapter/downstream/terminalToSdkResult.js +19 -12
  12. package/dist/adapter/runStream.js +30 -46
  13. package/dist/adapter/types.d.ts +7 -0
  14. package/dist/adapter/types.js +15 -0
  15. package/dist/agentSession/backgroundView.js +5 -1
  16. package/dist/agentSession/engineAgentRegistryRead.js +7 -5
  17. package/dist/agentSession/engineSessionBackgroundStop.js +25 -17
  18. package/dist/agentsWireCaps.d.ts +2 -0
  19. package/dist/agentsWireCaps.js +13 -2
  20. package/dist/approvalDecidedByCapability.d.ts +0 -1
  21. package/dist/approvalDecidedByCapability.js +2 -7
  22. package/dist/approvalsStreamLiveCapability.d.ts +0 -1
  23. package/dist/approvalsStreamLiveCapability.js +2 -6
  24. package/dist/atMostOnce.d.ts +8 -0
  25. package/dist/atMostOnce.js +36 -0
  26. package/dist/attachmentSeatCapability.d.ts +0 -1
  27. package/dist/attachmentSeatCapability.js +0 -3
  28. package/dist/attachmentsWireCaps.js +11 -6
  29. package/dist/bashExitReading.d.ts +10 -0
  30. package/dist/bashExitReading.js +12 -0
  31. package/dist/callerCwdCapability.d.ts +0 -5
  32. package/dist/callerCwdCapability.js +2 -13
  33. package/dist/centerWiringCapability.d.ts +1 -7
  34. package/dist/centerWiringCapability.js +18 -27
  35. package/dist/classifierStatus.js +4 -4
  36. package/dist/classifierVerdictWire.js +4 -16
  37. package/dist/clientSlice.js +1 -1
  38. package/dist/cloudConfigWireCaps.d.ts +3 -3
  39. package/dist/cloudConfigWireCaps.js +85 -43
  40. package/dist/compensations.js +1 -1
  41. package/dist/coreValuePorts.d.ts +11 -7
  42. package/dist/coreValuePorts.js +5 -8
  43. package/dist/credentialProvenance.d.ts +28 -0
  44. package/dist/credentialProvenance.js +76 -0
  45. package/dist/cycleOrder.d.ts +15 -0
  46. package/dist/cycleOrder.js +45 -0
  47. package/dist/decideFailureNote.js +7 -2
  48. package/dist/decideReceipt.d.ts +2 -1
  49. package/dist/decideReceipt.js +39 -14
  50. package/dist/declared/supportFloorDeclared.d.ts +1 -0
  51. package/dist/declared/supportFloorDeclared.js +5 -0
  52. package/dist/deviceExecutorManagementCapability.d.ts +0 -1
  53. package/dist/deviceExecutorManagementCapability.js +7 -16
  54. package/dist/deviceRebind.d.ts +88 -0
  55. package/dist/deviceRebind.js +242 -0
  56. package/dist/displayUntrusted.d.ts +8 -3
  57. package/dist/displayUntrusted.js +661 -63
  58. package/dist/engineAgentAbsence.d.ts +2 -2
  59. package/dist/engineAgentPanelStore.d.ts +8 -18
  60. package/dist/engineAgentPanelStore.js +19 -537
  61. package/dist/engineCapReader.d.ts +6 -6
  62. package/dist/engineCapReader.js +30 -43
  63. package/dist/engineCapsCache.d.ts +13 -2
  64. package/dist/engineCapsCache.js +276 -44
  65. package/dist/engineCredentialRequirement.d.ts +9 -0
  66. package/dist/engineCredentialRequirement.js +23 -0
  67. package/dist/engineDirectory.d.ts +79 -0
  68. package/dist/engineDirectory.js +186 -0
  69. package/dist/engineEnvSourcing.d.ts +53 -0
  70. package/dist/engineEnvSourcing.js +81 -0
  71. package/dist/engineErrorCodes.d.ts +28 -4
  72. package/dist/engineErrorCodes.js +68 -25
  73. package/dist/engineIdentity.js +2 -0
  74. package/dist/engineNoticeCodes.d.ts +17 -0
  75. package/dist/engineNoticeCodes.js +57 -3
  76. package/dist/engineWireSdk.js +2 -2
  77. package/dist/engineWordRenames.d.ts +8 -0
  78. package/dist/engineWordRenames.js +13 -0
  79. package/dist/executionLaneCapability.d.ts +2 -3
  80. package/dist/executionLaneCapability.js +18 -23
  81. package/dist/fileHistoryCaptureCapability.d.ts +14 -1
  82. package/dist/fileHistoryCaptureCapability.js +72 -6
  83. package/dist/fileHistoryLegNotice.d.ts +3 -2
  84. package/dist/fileHistoryLegNotice.js +51 -2
  85. package/dist/fleet/bgSubagentRow.d.ts +15 -0
  86. package/dist/fleet/bgSubagentRow.js +67 -0
  87. package/dist/fleet/fleetLedger.d.ts +3 -0
  88. package/dist/fleet/fleetLedger.js +153 -122
  89. package/dist/fleet/fleetProjection.d.ts +1 -3
  90. package/dist/fleet/fleetProjection.js +19 -19
  91. package/dist/fleetAgentPanelProjection.d.ts +4 -17
  92. package/dist/fleetAgentPanelProjection.js +7 -197
  93. package/dist/fleetAgentRowLike.d.ts +16 -0
  94. package/dist/fleetAgentRowLike.js +1 -0
  95. package/dist/fleetTaskDesc.js +4 -17
  96. package/dist/gateOutcome.d.ts +12 -1
  97. package/dist/gateOutcome.js +87 -18
  98. package/dist/gateVocabulary.d.ts +7 -2
  99. package/dist/gateVocabulary.js +5 -1
  100. package/dist/generated/engineAskFaceTables.js +1 -1
  101. package/dist/generated/engineFactTables.d.ts +5 -3
  102. package/dist/generated/engineFactTables.js +17 -4
  103. package/dist/generated/engineNoticeTables.js +12 -3
  104. package/dist/generated/sdkFactTables.d.ts +2 -0
  105. package/dist/generated/sdkFactTables.js +17 -0
  106. package/dist/generated/settingsSchemaFns.d.ts +13 -0
  107. package/dist/generated/settingsSchemaFns.js +75 -0
  108. package/dist/generated/toolNameTables.d.ts +1 -0
  109. package/dist/generated/toolNameTables.js +1 -0
  110. package/dist/headlessPermissionModeWire.d.ts +1 -1
  111. package/dist/headlessPermissionModeWire.js +1 -1
  112. package/dist/headlessReconnectWire.js +49 -20
  113. package/dist/hitl/allowRuleShadow.d.ts +1 -1
  114. package/dist/hitl/allowRuleShadow.js +49 -8
  115. package/dist/hitl/approvalCompleteParked.d.ts +1 -0
  116. package/dist/hitl/approvalCompleteParked.js +14 -0
  117. package/dist/hitl/approvalEndingCause.d.ts +7 -0
  118. package/dist/hitl/approvalEndingCause.js +71 -0
  119. package/dist/hitl/approvalHolds.d.ts +12 -2
  120. package/dist/hitl/approvalHolds.js +53 -2
  121. package/dist/hitl/approvalsFeed.js +23 -11
  122. package/dist/hitl/askGateWire.d.ts +2 -1
  123. package/dist/hitl/askGateWire.js +26 -1
  124. package/dist/hitl/askParkRowRouting.js +1 -1
  125. package/dist/hitl/automaticAnswerVerdict.d.ts +1 -1
  126. package/dist/hitl/automaticAnswerVerdict.js +15 -10
  127. package/dist/hitl/crashConverged.js +2 -0
  128. package/dist/hitl/decisionConflict.d.ts +3 -0
  129. package/dist/hitl/decisionConflict.js +41 -0
  130. package/dist/hitl/decisionRefusal.d.ts +12 -0
  131. package/dist/hitl/decisionRefusal.js +63 -4
  132. package/dist/hitl/frameRouter.d.ts +0 -1
  133. package/dist/hitl/frameRouter.js +32 -57
  134. package/dist/hitl/gateLedger.d.ts +5 -0
  135. package/dist/hitl/gateLedger.js +21 -0
  136. package/dist/hitl/hitlBridge.d.ts +17 -2
  137. package/dist/hitl/hitlBridge.js +91 -55
  138. package/dist/hitl/hitlHostSurface.js +3 -11
  139. package/dist/hitl/livePendingAsk.d.ts +16 -6
  140. package/dist/hitl/livePendingAsk.js +36 -4
  141. package/dist/hitl/localAllowRule.d.ts +1 -0
  142. package/dist/hitl/localAllowRule.js +2 -2
  143. package/dist/hitl/noAllowCause.d.ts +2 -1
  144. package/dist/hitl/noAllowCause.js +3 -2
  145. package/dist/hitl/parkExpiryJudgements.d.ts +19 -0
  146. package/dist/hitl/parkExpiryJudgements.js +46 -0
  147. package/dist/hitl/parkResolver.d.ts +4 -7
  148. package/dist/hitl/parkResolver.js +12 -34
  149. package/dist/hitl/parkRowBirthWait.d.ts +1 -0
  150. package/dist/hitl/parkRowBirthWait.js +2 -2
  151. package/dist/hitl/persistedRulesWire.js +5 -1
  152. package/dist/hitl/planReviewWire.d.ts +3 -2
  153. package/dist/hitl/planReviewWire.js +154 -50
  154. package/dist/hitl/replayedApproval.d.ts +9 -0
  155. package/dist/hitl/replayedApproval.js +139 -10
  156. package/dist/hitl/resumeRunningCard.d.ts +2 -0
  157. package/dist/hitl/resumeRunningCard.js +15 -4
  158. package/dist/hitl/sessionPolicyDeliverable.js +8 -6
  159. package/dist/hitl/standingRows.d.ts +18 -0
  160. package/dist/hitl/standingRows.js +127 -0
  161. package/dist/hitl/toolApprovalWire.d.ts +39 -7
  162. package/dist/hitl/toolApprovalWire.js +351 -61
  163. package/dist/hookMatcherVerdict.d.ts +1 -9
  164. package/dist/hookMatcherVerdict.js +21 -61
  165. package/dist/hooksWireCaps.js +40 -8
  166. package/dist/host.d.ts +5 -0
  167. package/dist/host.js +3 -1
  168. package/dist/hostCallbackGuard.d.ts +2 -0
  169. package/dist/hostCallbackGuard.js +31 -0
  170. package/dist/index.d.ts +48 -17
  171. package/dist/index.js +36 -15
  172. package/dist/interactiveInterrupt.d.ts +8 -0
  173. package/dist/interactiveInterrupt.js +54 -0
  174. package/dist/limitsWire.d.ts +5 -0
  175. package/dist/limitsWire.js +49 -3
  176. package/dist/liveModelCatalog.d.ts +95 -0
  177. package/dist/liveModelCatalog.js +297 -32
  178. package/dist/mcpEngineLeg.d.ts +25 -0
  179. package/dist/mcpEngineLeg.js +71 -15
  180. package/dist/mcpPanel.js +2 -1
  181. package/dist/mcpProbeCapability.d.ts +0 -5
  182. package/dist/mcpProbeCapability.js +2 -12
  183. package/dist/mcpReconnect.d.ts +1 -3
  184. package/dist/mcpReconnect.js +10 -5
  185. package/dist/memoryComplianceCapability.d.ts +0 -5
  186. package/dist/memoryComplianceCapability.js +2 -12
  187. package/dist/memoryOriginCapability.d.ts +0 -5
  188. package/dist/memoryOriginCapability.js +2 -12
  189. package/dist/memorySpecWire.js +2 -2
  190. package/dist/memoryVerbsWire.d.ts +1 -1
  191. package/dist/memoryVerbsWire.js +4 -0
  192. package/dist/model/liveCatalogShape.d.ts +14 -0
  193. package/dist/model/liveCatalogShape.js +71 -0
  194. package/dist/model/modelSupplyRules.d.ts +1 -0
  195. package/dist/model/modelSupplyRules.js +30 -9
  196. package/dist/model/modelsPolicy.d.ts +21 -0
  197. package/dist/model/modelsPolicy.js +90 -0
  198. package/dist/modelIdentityResolvability.d.ts +2 -2
  199. package/dist/modelIdentityResolvability.js +14 -12
  200. package/dist/modelSwitchFallback.d.ts +69 -0
  201. package/dist/modelSwitchFallback.js +206 -0
  202. package/dist/noticePresentation.d.ts +68 -0
  203. package/dist/noticePresentation.js +247 -0
  204. package/dist/notifications.js +12 -11
  205. package/dist/outputStyleSeatCapability.d.ts +0 -2
  206. package/dist/outputStyleSeatCapability.js +2 -10
  207. package/dist/ownKey.d.ts +8 -0
  208. package/dist/ownKey.js +66 -0
  209. package/dist/panelReduce.d.ts +114 -0
  210. package/dist/panelReduce.js +1135 -0
  211. package/dist/panelStateHolder.d.ts +17 -0
  212. package/dist/panelStateHolder.js +201 -0
  213. package/dist/peerFrames.js +13 -9
  214. package/dist/peerLaneCapability.d.ts +0 -1
  215. package/dist/peerLaneCapability.js +2 -6
  216. package/dist/permissionModesCapability.d.ts +0 -5
  217. package/dist/permissionModesCapability.js +5 -16
  218. package/dist/permissionRuleIssue.js +0 -3
  219. package/dist/permissionRulesWriteCapability.d.ts +0 -1
  220. package/dist/permissionRulesWriteCapability.js +2 -6
  221. package/dist/permissionsAllowGrantCapability.d.ts +0 -1
  222. package/dist/permissionsAllowGrantCapability.js +3 -9
  223. package/dist/permissionsDeclaration.d.ts +8 -0
  224. package/dist/permissionsDeclaration.js +101 -41
  225. package/dist/printPermissionOutcome.d.ts +12 -0
  226. package/dist/printPermissionOutcome.js +50 -0
  227. package/dist/printToolResultFrame.d.ts +1 -0
  228. package/dist/printToolResultFrame.js +5 -17
  229. package/dist/promptBlockedCopy.d.ts +5 -0
  230. package/dist/promptBlockedCopy.js +35 -0
  231. package/dist/promptDelivery.js +0 -8
  232. package/dist/protocolSegment.d.ts +9 -6
  233. package/dist/protocolSegment.js +31 -21
  234. package/dist/providerRejection.d.ts +4 -0
  235. package/dist/providerRejection.js +75 -14
  236. package/dist/replayBody.d.ts +12 -0
  237. package/dist/replayBody.js +25 -0
  238. package/dist/resumeRefusalCopy.d.ts +18 -1
  239. package/dist/resumeRefusalCopy.js +127 -32
  240. package/dist/retryStatus.d.ts +9 -1
  241. package/dist/retryStatus.js +9 -2
  242. package/dist/rewindArchiveCapability.d.ts +5 -14
  243. package/dist/rewindArchiveCapability.js +18 -61
  244. package/dist/rewindArchiveReading.d.ts +15 -0
  245. package/dist/rewindArchiveReading.js +56 -0
  246. package/dist/rewindEngineAction.d.ts +21 -0
  247. package/dist/rewindEngineAction.js +36 -0
  248. package/dist/rewindWireCaps.d.ts +2 -1
  249. package/dist/rewindWireCaps.js +1 -0
  250. package/dist/ruleCompileVerdict.d.ts +9 -1
  251. package/dist/ruleCompileVerdict.js +29 -4
  252. package/dist/runTerminal.d.ts +15 -12
  253. package/dist/runTerminal.js +60 -35
  254. package/dist/sandboxWire.js +13 -0
  255. package/dist/sdkRegistryTransit.d.ts +2 -1
  256. package/dist/sdkRegistryTransit.js +1 -0
  257. package/dist/sealedKeyCapability.d.ts +0 -5
  258. package/dist/sealedKeyCapability.js +3 -15
  259. package/dist/seam.js +4 -2
  260. package/dist/seatContract.d.ts +125 -34
  261. package/dist/seatContract.js +583 -179
  262. package/dist/sessionIdSegment.d.ts +1 -0
  263. package/dist/sessionIdSegment.js +11 -0
  264. package/dist/sessionMemoryErase.d.ts +1 -1
  265. package/dist/sessionMemoryErase.js +6 -1
  266. package/dist/sessionMemoryStatus.js +3 -2
  267. package/dist/sessionPolicyCapability.d.ts +0 -1
  268. package/dist/sessionPolicyCapability.js +2 -6
  269. package/dist/sessionReadRedactionCapability.d.ts +0 -5
  270. package/dist/sessionReadRedactionCapability.js +2 -13
  271. package/dist/sessionSyncFileHistory.d.ts +4 -0
  272. package/dist/sessionSyncFileHistory.js +66 -0
  273. package/dist/sessionSyncFileHistoryCapability.d.ts +0 -2
  274. package/dist/sessionSyncFileHistoryCapability.js +2 -9
  275. package/dist/skillToolListsCapability.d.ts +0 -2
  276. package/dist/skillToolListsCapability.js +2 -9
  277. package/dist/skillsWireCaps.d.ts +4 -0
  278. package/dist/skillsWireCaps.js +66 -1
  279. package/dist/sqlEngineCapability.d.ts +0 -1
  280. package/dist/sqlEngineCapability.js +9 -14
  281. package/dist/steerPriorityCapability.d.ts +0 -2
  282. package/dist/steerPriorityCapability.js +3 -12
  283. package/dist/storePostureCapability.d.ts +1 -5
  284. package/dist/storePostureCapability.js +16 -22
  285. package/dist/streamDrainingLegs.d.ts +6 -0
  286. package/dist/streamDrainingLegs.js +23 -0
  287. package/dist/subagent/engineCompactWire.js +13 -38
  288. package/dist/subagent/engineDelegatedPrompt.js +10 -6
  289. package/dist/subagent/engineSubagentOutput.d.ts +0 -1
  290. package/dist/subagent/engineSubagentOutput.js +5 -20
  291. package/dist/subagent/engineSubagentSteer.js +7 -5
  292. package/dist/subagent/engineSubagentTail.d.ts +0 -1
  293. package/dist/subagent/engineSubagentTail.js +7 -32
  294. package/dist/subagentContentStore.js +7 -18
  295. package/dist/supportFloor.d.ts +1 -0
  296. package/dist/supportFloor.js +15 -14
  297. package/dist/systemReminderTag.d.ts +1 -0
  298. package/dist/systemReminderTag.js +8 -0
  299. package/dist/terminalStatuses.d.ts +30 -0
  300. package/dist/terminalStatuses.js +67 -0
  301. package/dist/toolHistoryMismatch.d.ts +0 -3
  302. package/dist/toolHistoryMismatch.js +3 -7
  303. package/dist/toolResult.d.ts +6 -1
  304. package/dist/toolResult.js +90 -37
  305. package/dist/toolResultContent.d.ts +2 -0
  306. package/dist/toolResultContent.js +63 -0
  307. package/dist/types/engineState.d.ts +2 -1
  308. package/dist/usageAnalytics.d.ts +146 -0
  309. package/dist/usageAnalytics.js +335 -0
  310. package/dist/userInvokedSkillsCapability.d.ts +0 -2
  311. package/dist/userInvokedSkillsCapability.js +2 -9
  312. package/dist/webSearchBackendCapability.d.ts +0 -1
  313. package/dist/webSearchBackendCapability.js +3 -7
  314. package/dist/webSearchWireCaps.js +3 -11
  315. package/dist/wireErrorTriage.d.ts +2 -0
  316. package/dist/wireErrorTriage.js +34 -5
  317. package/dist/wireFailureShape.d.ts +23 -2
  318. package/dist/wireFailureShape.js +88 -43
  319. package/dist/wireRefusalCopy.js +2 -18
  320. package/dist/workflowClient.js +7 -11
  321. package/dist/workflowsJournalCapability.d.ts +0 -1
  322. package/dist/workflowsJournalCapability.js +2 -6
  323. package/dist/writeProtectionCapability.d.ts +0 -1
  324. package/dist/writeProtectionCapability.js +5 -10
  325. package/docs/INTEGRATION-CLIENTS.md +2279 -27
  326. package/package.json +5 -5
  327. package/dist/engineCapsGenerationGuard.d.ts +0 -4
  328. package/dist/engineCapsGenerationGuard.js +0 -19
  329. package/dist/panelRunningHistory.d.ts +0 -22
  330. package/dist/panelRunningHistory.js +0 -82
  331. package/dist/registryConflict.d.ts +0 -3
  332. package/dist/registryConflict.js +0 -44
@@ -1,5 +1,5 @@
1
- import { snapshotCapsGeneration, capsGenerationStillCurrent } from './engineCapsGenerationGuard.js';
2
- import { capsGenerationMarkOf, retainCapsGenerationMark } from './engineCapsCache.js';
1
+ import { engineCapsLandingOf } from './engineCapsCache.js';
2
+ import { ownDataField } from './ownKey.js';
3
3
  function freezeReading(reading, seen = new Set()) {
4
4
  if (reading === null || typeof reading !== 'object' || seen.has(reading))
5
5
  return reading;
@@ -11,67 +11,54 @@ function freezeReading(reading, seen = new Set()) {
11
11
  }
12
12
  return reading;
13
13
  }
14
+ const PROJECTING = Symbol('projecting');
14
15
  export function createEngineCapReader(spec) {
15
- const cellByBase = new Map();
16
+ let memo = new WeakMap();
16
17
  return {
17
- note(baseUrl, caps, opts) {
18
+ note(_baseUrl, _caps, _opts) { },
19
+ observed(baseUrl) {
18
20
  if (typeof baseUrl !== 'string' || baseUrl === '')
19
- return;
20
- const gen = snapshotCapsGeneration(opts);
21
- if (gen === null)
22
- return;
23
- if (!capsGenerationStillCurrent(baseUrl, gen))
24
- return;
25
- const mark = retainCapsGenerationMark(baseUrl);
21
+ return spec.makeUnobserved();
22
+ const landing = engineCapsLandingOf(baseUrl);
23
+ if (landing === undefined)
24
+ return spec.makeUnobserved();
25
+ const hit = memo.get(landing);
26
+ if (hit === PROJECTING)
27
+ return spec.makeUnobserved();
28
+ if (hit !== undefined)
29
+ return hit.reading === undefined ? spec.makeUnobserved() : hit.reading;
30
+ const mine = memo;
31
+ mine.set(landing, PROJECTING);
26
32
  let reading;
27
33
  try {
28
- reading = spec.project(caps);
34
+ reading = spec.project(landing.caps);
29
35
  }
30
36
  catch {
31
37
  reading = undefined;
32
38
  }
33
- if (capsGenerationMarkOf(baseUrl) !== mark)
34
- return;
35
- if (reading === undefined) {
36
- cellByBase.delete(baseUrl);
37
- return;
38
- }
39
- cellByBase.set(baseUrl, { reading: freezeReading(reading), mark });
40
- },
41
- observed(baseUrl) {
42
- if (typeof baseUrl !== 'string' || baseUrl === '')
43
- return spec.makeUnobserved();
44
- const cell = cellByBase.get(baseUrl);
45
- if (cell === undefined)
46
- return spec.makeUnobserved();
47
- if (cell.mark !== capsGenerationMarkOf(baseUrl)) {
48
- cellByBase.delete(baseUrl);
39
+ if (engineCapsLandingOf(baseUrl) !== landing) {
40
+ mine.delete(landing);
49
41
  return spec.makeUnobserved();
50
42
  }
51
- return cell.reading;
52
- },
53
- forget(baseUrl) {
54
- if (typeof baseUrl !== 'string' || baseUrl === '')
55
- return;
56
- cellByBase.delete(baseUrl);
43
+ const done = { reading: reading === undefined ? undefined : freezeReading(reading) };
44
+ mine.set(landing, done);
45
+ return done.reading === undefined ? spec.makeUnobserved() : done.reading;
57
46
  },
58
47
  __resetForTests() {
59
- cellByBase.clear();
48
+ memo = new WeakMap();
60
49
  },
61
50
  };
62
51
  }
63
- export function capsGenerationOf(caps) {
52
+ export function storeSeatOf(caps) {
64
53
  try {
65
- if (!Object.hasOwn(caps, 'store'))
66
- return { generation: 'old', store: 'absent' };
67
- const store = caps.store;
54
+ const store = ownDataField(caps, 'store');
68
55
  if (store === undefined)
69
- return { generation: 'old', store: 'absent' };
56
+ return { kind: 'absent' };
70
57
  if (typeof store !== 'object' || store === null || Array.isArray(store))
71
- return { generation: 'old', store: 'malformed' };
72
- return { generation: 'new', store };
58
+ return { kind: 'malformed' };
59
+ return { kind: 'object', store };
73
60
  }
74
61
  catch {
75
- return { generation: 'old', store: 'malformed' };
62
+ return { kind: 'malformed' };
76
63
  }
77
64
  }
@@ -1,18 +1,26 @@
1
1
  export declare function engineCapsGeneration(baseUrl: string): number;
2
- export declare function capsGenerationMarkOf(baseUrl: string): object | undefined;
3
- export declare function retainCapsGenerationMark(baseUrl: string): object;
2
+ export declare function engineCapsLandingOf(baseUrl: string): {
3
+ readonly caps: object;
4
+ } | undefined;
4
5
  export declare function kickEngineCapsProbe(baseUrl: string, probe: () => Promise<unknown>): void;
5
6
  export declare function engineCapsSettled(baseUrl: string | undefined, opts?: {
6
7
  withinMs?: number;
7
8
  }): Promise<'settled' | 'timed_out'>;
8
9
  export type EngineCapState = 'true' | 'false' | 'unprobed' | 'absent' | 'non_boolean';
9
10
  export declare function engineCapState(baseUrl: string | undefined, key: string): EngineCapState;
11
+ export declare function engineCapStateVia(baseUrl: string | undefined, key: string, probe: (signal?: AbortSignal) => Promise<unknown>, opts?: {
12
+ withinMs?: number;
13
+ signal?: AbortSignal;
14
+ }): Promise<EngineCapState>;
10
15
  export declare function engineCapTrue(baseUrl: string | undefined, key: string): boolean;
11
16
  export declare function engineCapNestedTrue(baseUrl: string | undefined, parentKey: string, key: string): boolean;
17
+ export declare function engineCapNestedValue(baseUrl: string | undefined, parentKey: string, key: string): EngineCapValueState;
12
18
  export type EngineCapValueState = {
13
19
  kind: 'unobserved';
14
20
  } | {
15
21
  kind: 'not_reported';
22
+ } | {
23
+ kind: 'unreadable';
16
24
  } | {
17
25
  kind: 'null';
18
26
  } | {
@@ -22,4 +30,7 @@ export type EngineCapValueState = {
22
30
  export declare function engineCapValue(baseUrl: string | undefined, key: string): EngineCapValueState;
23
31
  export declare function engineCapString(baseUrl: string | undefined, key: string): string | undefined;
24
32
  export declare function invalidateEngineCaps(baseUrl: string | undefined, probe?: () => Promise<unknown>): void;
33
+ export declare function refreshEngineCapsOnce(baseUrl: string | undefined, opts?: {
34
+ withinMs?: number;
35
+ }): Promise<'settled' | 'timed_out' | 'no_probe'>;
25
36
  export declare function __resetEngineCapsCacheForTests(): void;
@@ -1,27 +1,24 @@
1
+ import { settleWithinDeadline } from './abortableSleep.js';
2
+ import { ownDataField } from './ownKey.js';
1
3
  const capsByBase = new Map();
2
4
  const inFlight = new Set();
3
5
  const settleByBase = new Map();
4
6
  const genByBase = new Map();
7
+ const probeByBase = new Map();
8
+ const refreshByBase = new Map();
5
9
  function capsGeneration(baseUrl) {
6
- return genByBase.get(baseUrl)?.n ?? 0;
10
+ return genByBase.get(baseUrl) ?? 0;
7
11
  }
8
12
  export function engineCapsGeneration(baseUrl) {
9
13
  return capsGeneration(baseUrl);
10
14
  }
11
- export function capsGenerationMarkOf(baseUrl) {
12
- return genByBase.get(baseUrl);
13
- }
14
- export function retainCapsGenerationMark(baseUrl) {
15
- let mark = genByBase.get(baseUrl);
16
- if (mark === undefined) {
17
- mark = Object.freeze({ n: 0 });
18
- genByBase.set(baseUrl, mark);
19
- }
20
- return mark;
15
+ export function engineCapsLandingOf(baseUrl) {
16
+ return capsByBase.get(baseUrl);
21
17
  }
22
18
  export function kickEngineCapsProbe(baseUrl, probe) {
23
19
  if (!baseUrl || capsByBase.has(baseUrl) || inFlight.has(baseUrl))
24
20
  return;
21
+ probeByBase.set(baseUrl, probe);
25
22
  const gen = capsGeneration(baseUrl);
26
23
  inFlight.add(baseUrl);
27
24
  let wake = () => { };
@@ -38,9 +35,8 @@ export function kickEngineCapsProbe(baseUrl, probe) {
38
35
  const caps = await probe();
39
36
  if (gen !== capsGeneration(baseUrl))
40
37
  return;
41
- if (caps && typeof caps === 'object') {
42
- capsByBase.set(baseUrl, caps);
43
- }
38
+ if (caps && typeof caps === 'object')
39
+ landCapsSnapshot(baseUrl, gen, caps);
44
40
  }
45
41
  catch {
46
42
  }
@@ -124,59 +120,227 @@ export async function engineCapsSettled(baseUrl, opts) {
124
120
  export function engineCapState(baseUrl, key) {
125
121
  if (!baseUrl)
126
122
  return 'unprobed';
127
- const caps = capsByBase.get(baseUrl);
128
- if (caps === undefined)
129
- return 'unprobed';
130
- if (!(key in caps))
131
- return 'absent';
132
- const v = caps[key];
133
- if (v === true)
134
- return 'true';
135
- if (v === false)
136
- return 'false';
137
- return 'non_boolean';
123
+ return capStateIn(capsByBase.get(baseUrl)?.caps, key);
124
+ }
125
+ const SNAPSHOT_MAX_DEPTH = 64;
126
+ const SNAPSHOT_MAX_NODES = 100_000;
127
+ const SNAPSHOT_PROBE_KEY = '\u0000capabilities-snapshot-probe\u0000';
128
+ const FOREIGN_PROTOTYPE = Object.freeze(Object.create(null));
129
+ function unreadableError() {
130
+ return new TypeError('capabilities body position is not readable (accessor or throwing proxy)');
131
+ }
132
+ const UNREADABLE_NODE = new Proxy(Object.freeze({}), {
133
+ getOwnPropertyDescriptor: () => {
134
+ throw unreadableError();
135
+ },
136
+ ownKeys: () => {
137
+ throw unreadableError();
138
+ },
139
+ has: () => {
140
+ throw unreadableError();
141
+ },
142
+ get: () => {
143
+ throw unreadableError();
144
+ },
145
+ getPrototypeOf: () => {
146
+ throw unreadableError();
147
+ },
148
+ });
149
+ function throwingAccessor() {
150
+ return {
151
+ get: () => {
152
+ throw unreadableError();
153
+ },
154
+ enumerable: true,
155
+ configurable: false,
156
+ };
157
+ }
158
+ function landCapsSnapshot(baseUrl, gen, caps) {
159
+ const snapshot = snapshotCapsBody(caps);
160
+ if (gen !== capsGeneration(baseUrl))
161
+ return;
162
+ capsByBase.set(baseUrl, Object.freeze({ caps: snapshot }));
163
+ }
164
+ function snapshotCapsBody(body) {
165
+ if (body === null || typeof body !== 'object')
166
+ return body;
167
+ const seen = new WeakMap();
168
+ let nodes = 0;
169
+ const copy = (src, depth) => {
170
+ const known = seen.get(src);
171
+ if (known !== undefined)
172
+ return known;
173
+ if (depth > SNAPSHOT_MAX_DEPTH || ++nodes > SNAPSHOT_MAX_NODES)
174
+ return UNREADABLE_NODE;
175
+ let keys;
176
+ let out;
177
+ let isArray;
178
+ try {
179
+ isArray = Array.isArray(src);
180
+ keys = Object.getOwnPropertyNames(src);
181
+ Object.getOwnPropertyDescriptor(src, SNAPSHOT_PROBE_KEY);
182
+ let length = 0;
183
+ if (isArray) {
184
+ const ld = Object.getOwnPropertyDescriptor(src, 'length');
185
+ if (ld === undefined || !Object.hasOwn(ld, 'value') || typeof ld.value !== 'number')
186
+ return UNREADABLE_NODE;
187
+ length = ld.value;
188
+ }
189
+ const proto = isArray ? null : Object.getPrototypeOf(src);
190
+ out = isArray ? new Array(length) : proto === Object.prototype || proto === null ? {} : Object.create(FOREIGN_PROTOTYPE);
191
+ }
192
+ catch {
193
+ return UNREADABLE_NODE;
194
+ }
195
+ seen.set(src, out);
196
+ for (const k of keys) {
197
+ if (isArray && k === 'length')
198
+ continue;
199
+ let d;
200
+ try {
201
+ d = Object.getOwnPropertyDescriptor(src, k);
202
+ }
203
+ catch {
204
+ Object.defineProperty(out, k, throwingAccessor());
205
+ continue;
206
+ }
207
+ if (d === undefined)
208
+ continue;
209
+ if (!Object.hasOwn(d, 'value')) {
210
+ Object.defineProperty(out, k, throwingAccessor());
211
+ continue;
212
+ }
213
+ const v = d.value;
214
+ Object.defineProperty(out, k, {
215
+ value: v !== null && typeof v === 'object' ? copy(v, depth + 1) : v,
216
+ enumerable: d.enumerable === true,
217
+ writable: false,
218
+ configurable: false,
219
+ });
220
+ }
221
+ Object.freeze(out);
222
+ return out;
223
+ };
224
+ return copy(body, 0);
225
+ }
226
+ const SLOT_UNOBSERVED = Object.freeze({ kind: 'unobserved' });
227
+ const SLOT_ABSENT = Object.freeze({ kind: 'absent' });
228
+ const SLOT_UNREADABLE = Object.freeze({ kind: 'unreadable' });
229
+ function capSlotIn(caps, key) {
230
+ if (caps === undefined || caps === null || typeof caps !== 'object')
231
+ return SLOT_UNOBSERVED;
232
+ try {
233
+ const v = ownDataField(caps, key);
234
+ return v === undefined ? SLOT_ABSENT : { kind: 'present', value: v };
235
+ }
236
+ catch {
237
+ return SLOT_UNREADABLE;
238
+ }
239
+ }
240
+ function capStateIn(caps, key) {
241
+ const slot = capSlotIn(caps, key);
242
+ switch (slot.kind) {
243
+ case 'unobserved':
244
+ return 'unprobed';
245
+ case 'absent':
246
+ return 'absent';
247
+ case 'unreadable':
248
+ return 'non_boolean';
249
+ case 'present':
250
+ return slot.value === true ? 'true' : slot.value === false ? 'false' : 'non_boolean';
251
+ }
252
+ }
253
+ async function untilSettledOrAborted(p, signal) {
254
+ if (signal === undefined) {
255
+ await p.catch(() => undefined);
256
+ return;
257
+ }
258
+ if (signal.aborted)
259
+ return;
260
+ let onAbort;
261
+ const aborted = new Promise((resolve) => {
262
+ onAbort = () => resolve();
263
+ signal.addEventListener('abort', onAbort, { once: true });
264
+ });
265
+ try {
266
+ await Promise.race([p.then(() => undefined, () => undefined), aborted]);
267
+ }
268
+ finally {
269
+ if (onAbort !== undefined)
270
+ signal.removeEventListener('abort', onAbort);
271
+ }
272
+ }
273
+ export async function engineCapStateVia(baseUrl, key, probe, opts) {
274
+ const signal = opts?.signal;
275
+ if (!baseUrl) {
276
+ try {
277
+ if (signal?.aborted)
278
+ return 'unprobed';
279
+ return capStateIn(await probe(signal), key);
280
+ }
281
+ catch {
282
+ return 'unprobed';
283
+ }
284
+ }
285
+ const now = engineCapState(baseUrl, key);
286
+ if (now !== 'unprobed')
287
+ return now;
288
+ kickEngineCapsProbe(baseUrl, () => probe());
289
+ await untilSettledOrAborted(engineCapsSettled(baseUrl, opts?.withinMs !== undefined ? { withinMs: opts.withinMs } : undefined), signal);
290
+ return engineCapState(baseUrl, key);
138
291
  }
139
292
  export function engineCapTrue(baseUrl, key) {
140
293
  return engineCapState(baseUrl, key) === 'true';
141
294
  }
142
295
  export function engineCapNestedTrue(baseUrl, parentKey, key) {
296
+ const state = engineCapNestedValue(baseUrl, parentKey, key);
297
+ return state.kind === 'value' && state.value === true;
298
+ }
299
+ export function engineCapNestedValue(baseUrl, parentKey, key) {
143
300
  if (!baseUrl)
144
- return false;
145
- const parent = capsByBase.get(baseUrl)?.[parentKey];
146
- if (parent === null || typeof parent !== 'object')
147
- return false;
148
- return parent[key] === true;
301
+ return { kind: 'unobserved' };
302
+ const parent = capSlotIn(capsByBase.get(baseUrl)?.caps, parentKey);
303
+ if (parent.kind !== 'present')
304
+ return valueStateOfSlot(parent);
305
+ const group = parent.value;
306
+ if (group === null || typeof group !== 'object')
307
+ return { kind: 'not_reported' };
308
+ return valueStateOfSlot(capSlotIn(group, key));
149
309
  }
150
310
  export function engineCapValue(baseUrl, key) {
151
311
  if (!baseUrl)
152
312
  return { kind: 'unobserved' };
153
- const caps = capsByBase.get(baseUrl);
154
- if (caps === undefined)
155
- return { kind: 'unobserved' };
156
- if (!(key in caps))
157
- return { kind: 'not_reported' };
158
- const v = caps[key];
159
- if (v === undefined)
160
- return { kind: 'not_reported' };
161
- if (v === null)
162
- return { kind: 'null' };
163
- return { kind: 'value', value: v };
313
+ return valueStateOfSlot(capSlotIn(capsByBase.get(baseUrl)?.caps, key));
314
+ }
315
+ function valueStateOfSlot(slot) {
316
+ switch (slot.kind) {
317
+ case 'unobserved':
318
+ return { kind: 'unobserved' };
319
+ case 'absent':
320
+ return { kind: 'not_reported' };
321
+ case 'unreadable':
322
+ return { kind: 'unreadable' };
323
+ case 'present':
324
+ return slot.value === null ? { kind: 'null' } : { kind: 'value', value: slot.value };
325
+ }
164
326
  }
165
327
  export function engineCapString(baseUrl, key) {
166
328
  if (!baseUrl)
167
329
  return undefined;
168
- const v = capsByBase.get(baseUrl)?.[key];
169
- return typeof v === 'string' && v.length > 0 ? v : undefined;
330
+ const slot = capSlotIn(capsByBase.get(baseUrl)?.caps, key);
331
+ return slot.kind === 'present' && typeof slot.value === 'string' && slot.value.length > 0 ? slot.value : undefined;
170
332
  }
171
333
  export function invalidateEngineCaps(baseUrl, probe) {
172
334
  if (!baseUrl)
173
335
  return;
336
+ if (probe === undefined)
337
+ probeByBase.delete(baseUrl);
174
338
  const hadState = capsByBase.has(baseUrl) ||
175
339
  inFlight.has(baseUrl) ||
176
340
  settleByBase.has(baseUrl) ||
177
341
  genByBase.has(baseUrl);
178
342
  if (hadState) {
179
- genByBase.set(baseUrl, Object.freeze({ n: capsGeneration(baseUrl) + 1 }));
343
+ genByBase.set(baseUrl, capsGeneration(baseUrl) + 1);
180
344
  capsByBase.delete(baseUrl);
181
345
  inFlight.delete(baseUrl);
182
346
  settleByBase.get(baseUrl)?.wake();
@@ -184,9 +348,77 @@ export function invalidateEngineCaps(baseUrl, probe) {
184
348
  if (probe !== undefined)
185
349
  kickEngineCapsProbe(baseUrl, probe);
186
350
  }
351
+ export async function refreshEngineCapsOnce(baseUrl, opts) {
352
+ try {
353
+ if (typeof baseUrl !== 'string' || baseUrl === '')
354
+ return 'no_probe';
355
+ const budget = waitBudgetOf(opts);
356
+ const probe = probeByBase.get(baseUrl);
357
+ if (probe === undefined)
358
+ return 'no_probe';
359
+ const flying = refreshByBase.get(baseUrl);
360
+ if (flying !== undefined && flying.gen === capsGeneration(baseUrl))
361
+ return await awaitRefreshWithin(flying, budget);
362
+ if (!capsByBase.has(baseUrl)) {
363
+ kickEngineCapsProbe(baseUrl, probe);
364
+ return await engineCapsSettled(baseUrl, budget === undefined ? undefined : { withinMs: budget });
365
+ }
366
+ const gen = capsGeneration(baseUrl);
367
+ let finish = () => { };
368
+ const entry = { gen, promise: new Promise((resolve) => { finish = resolve; }) };
369
+ refreshByBase.set(baseUrl, entry);
370
+ void (async () => {
371
+ try {
372
+ const caps = await probe();
373
+ if (gen !== capsGeneration(baseUrl) || !capsByBase.has(baseUrl) || !isPlainCapsBody(caps))
374
+ return false;
375
+ landCapsSnapshot(baseUrl, gen, caps);
376
+ return gen === capsGeneration(baseUrl);
377
+ }
378
+ catch {
379
+ return false;
380
+ }
381
+ finally {
382
+ if (refreshByBase.get(baseUrl) === entry)
383
+ refreshByBase.delete(baseUrl);
384
+ }
385
+ })().then(finish);
386
+ return await awaitRefreshWithin(entry, budget);
387
+ }
388
+ catch {
389
+ return 'timed_out';
390
+ }
391
+ }
392
+ function isPlainCapsBody(caps) {
393
+ try {
394
+ if (typeof caps !== 'object' || caps === null)
395
+ return false;
396
+ const proto = Object.getPrototypeOf(caps);
397
+ if (proto !== null && Object.getPrototypeOf(proto) !== null)
398
+ return false;
399
+ for (const key of Reflect.ownKeys(caps))
400
+ Object.getOwnPropertyDescriptor(caps, key);
401
+ return true;
402
+ }
403
+ catch {
404
+ return false;
405
+ }
406
+ }
407
+ async function awaitRefreshWithin(entry, budget) {
408
+ if (budget === undefined) {
409
+ await entry.promise;
410
+ return 'settled';
411
+ }
412
+ if (budget === 0)
413
+ return 'timed_out';
414
+ const out = await settleWithinDeadline(budget, () => entry.promise);
415
+ return out.kind === 'deadline' ? 'timed_out' : 'settled';
416
+ }
187
417
  export function __resetEngineCapsCacheForTests() {
188
418
  capsByBase.clear();
189
419
  inFlight.clear();
190
420
  settleByBase.clear();
191
421
  genByBase.clear();
422
+ probeByBase.clear();
423
+ refreshByBase.clear();
192
424
  }
@@ -0,0 +1,9 @@
1
+ export type EngineProbeAnswer = {
2
+ readonly ok: true;
3
+ } | {
4
+ readonly status: number;
5
+ } | {
6
+ readonly transport: true;
7
+ };
8
+ export type EngineCredentialNeed = 'open' | 'requires' | 'undetermined';
9
+ export declare function engineCredentialRequirementOf(answer: EngineProbeAnswer): EngineCredentialNeed;
@@ -0,0 +1,23 @@
1
+ export function engineCredentialRequirementOf(answer) {
2
+ try {
3
+ const a = answer;
4
+ if (typeof a !== 'object' || a === null || Array.isArray(a))
5
+ return 'undetermined';
6
+ const ok = Object.getOwnPropertyDescriptor(a, 'ok');
7
+ const status = Object.getOwnPropertyDescriptor(a, 'status');
8
+ const transport = Object.getOwnPropertyDescriptor(a, 'transport');
9
+ const arms = (ok !== undefined ? 1 : 0) + (status !== undefined ? 1 : 0) + (transport !== undefined ? 1 : 0);
10
+ if (arms !== 1)
11
+ return 'undetermined';
12
+ if (ok !== undefined)
13
+ return Object.hasOwn(ok, 'value') && ok.value === true ? 'open' : 'undetermined';
14
+ if (status !== undefined) {
15
+ const value = Object.hasOwn(status, 'value') ? status.value : undefined;
16
+ return value === 401 || value === 403 ? 'requires' : 'undetermined';
17
+ }
18
+ return 'undetermined';
19
+ }
20
+ catch {
21
+ return 'undetermined';
22
+ }
23
+ }
@@ -0,0 +1,79 @@
1
+ declare const KIND_WORDS: readonly ["managed"];
2
+ declare const POSTURE_WORDS: readonly ["single", "multi"];
3
+ declare const RULE_WORDS: readonly ["only-one", "none", "ambiguous"];
4
+ export type EngineKindWord = (typeof KIND_WORDS)[number];
5
+ export type EnginePostureWord = (typeof POSTURE_WORDS)[number];
6
+ export type MeEngineRuleWord = (typeof RULE_WORDS)[number];
7
+ export type OpenWordReading<K extends string> = {
8
+ readonly kind: 'listed';
9
+ readonly word: K;
10
+ } | {
11
+ readonly kind: 'unlisted';
12
+ readonly word: string;
13
+ } | {
14
+ readonly kind: 'unreadable';
15
+ };
16
+ export interface EngineRowReading {
17
+ readonly name: string;
18
+ readonly kind: OpenWordReading<EngineKindWord>;
19
+ readonly scope: string | undefined;
20
+ readonly online: boolean | undefined;
21
+ readonly posture: OpenWordReading<EnginePostureWord>;
22
+ readonly viaCenter: string;
23
+ }
24
+ export interface EngineRowSet {
25
+ readonly rows: readonly EngineRowReading[];
26
+ readonly unreadableRows: number;
27
+ readonly unreadableNames: readonly string[];
28
+ }
29
+ export type MeEngineTargetReading = {
30
+ readonly kind: 'row';
31
+ readonly row: EngineRowReading;
32
+ } | {
33
+ readonly kind: 'null';
34
+ } | {
35
+ readonly kind: 'unreadable';
36
+ };
37
+ export interface MeEngineReading {
38
+ readonly rule: OpenWordReading<MeEngineRuleWord>;
39
+ readonly target: MeEngineTargetReading;
40
+ readonly candidates: EngineRowSet | undefined;
41
+ }
42
+ export type MeEngineUnresolvedReason = 'body' | 'rule' | 'rule-unlisted' | 'target' | 'candidates' | 'conflict';
43
+ export type MeEngineDecision = {
44
+ readonly kind: 'connect';
45
+ readonly engine: EngineRowReading;
46
+ readonly rule: OpenWordReading<MeEngineRuleWord>;
47
+ } | {
48
+ readonly kind: 'no-engine';
49
+ } | {
50
+ readonly kind: 'choose';
51
+ readonly candidates: EngineRowSet;
52
+ } | {
53
+ readonly kind: 'unresolved';
54
+ readonly reason: MeEngineUnresolvedReason;
55
+ readonly rule: OpenWordReading<MeEngineRuleWord>;
56
+ readonly candidates: EngineRowSet | undefined;
57
+ };
58
+ export type EngineOverrideDecision = {
59
+ readonly kind: 'select';
60
+ readonly engine: EngineRowReading;
61
+ } | {
62
+ readonly kind: 'not-listed';
63
+ readonly candidates: EngineRowSet;
64
+ } | {
65
+ readonly kind: 'duplicate';
66
+ readonly name: string;
67
+ } | {
68
+ readonly kind: 'row-unreadable';
69
+ readonly name: string;
70
+ } | {
71
+ readonly kind: 'unreadable';
72
+ } | {
73
+ readonly kind: 'invalid';
74
+ };
75
+ export declare function projectEngineDirectory(body: unknown): EngineRowSet | undefined;
76
+ export declare function projectMeEngine(body: unknown): MeEngineReading | undefined;
77
+ export declare function decideMeEngine(reading: MeEngineReading | undefined): MeEngineDecision;
78
+ export declare function engineOverrideOf(set: EngineRowSet | undefined, requested: unknown): EngineOverrideDecision;
79
+ export {};