@sema-agent/client-core 0.98.0 → 0.100.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 (236) hide show
  1. package/CHANGELOG.md +376 -0
  2. package/README.md +61 -35
  3. package/dist/adapt/arms.js +120 -55
  4. package/dist/adapt/panelTasks.d.ts +3 -2
  5. package/dist/adapt/panelTasks.js +34 -11
  6. package/dist/adapt/textStream.d.ts +1 -1
  7. package/dist/adapt/textStream.js +51 -28
  8. package/dist/adapter/activeRunSelfHeal.d.ts +11 -3
  9. package/dist/adapter/activeRunSelfHeal.js +210 -294
  10. package/dist/adapter/downstream/eventToSdkMessage.d.ts +25 -6
  11. package/dist/adapter/downstream/eventToSdkMessage.js +176 -12
  12. package/dist/adapter/downstream/terminalToSdkResult.js +10 -0
  13. package/dist/adapter/downstream/wiringManifestView.d.ts +3 -1
  14. package/dist/adapter/downstream/wiringManifestView.js +1 -0
  15. package/dist/adapter/runStream.js +82 -40
  16. package/dist/adapter/types.d.ts +2 -0
  17. package/dist/adapter/types.js +2 -1
  18. package/dist/agentSession/engineSessionBackgroundStop.js +16 -8
  19. package/dist/agentsWireCaps.d.ts +7 -3
  20. package/dist/agentsWireCaps.js +133 -39
  21. package/dist/cloudConfigWireCaps.d.ts +10 -1
  22. package/dist/cloudConfigWireCaps.js +181 -65
  23. package/dist/compactionStatus.d.ts +34 -0
  24. package/dist/compactionStatus.js +196 -0
  25. package/dist/controlRouter.d.ts +4 -2
  26. package/dist/controlRouter.js +39 -51
  27. package/dist/coreValuePorts.d.ts +26 -1
  28. package/dist/coreValuePorts.js +10 -0
  29. package/dist/corruptSessionCopy.d.ts +2 -1
  30. package/dist/corruptSessionCopy.js +3 -3
  31. package/dist/decideFailureNote.js +3 -3
  32. package/dist/declared/supportFloorDeclared.js +1 -1
  33. package/dist/detachWire.js +3 -2
  34. package/dist/devicesFace.d.ts +34 -0
  35. package/dist/devicesFace.js +90 -0
  36. package/dist/displayUntrusted.d.ts +1 -0
  37. package/dist/displayUntrusted.js +153 -5
  38. package/dist/engineAgentPanelStore.d.ts +14 -4
  39. package/dist/engineAgentPanelStore.js +14 -0
  40. package/dist/engineCapReader.d.ts +2 -1
  41. package/dist/engineCapReader.js +7 -5
  42. package/dist/engineCapsCache.d.ts +8 -0
  43. package/dist/engineCapsCache.js +59 -6
  44. package/dist/engineCapsChange.d.ts +2 -0
  45. package/dist/engineCapsChange.js +9 -0
  46. package/dist/engineErrorCodes.d.ts +11 -2
  47. package/dist/engineErrorCodes.js +11 -12
  48. package/dist/engineRowRef.js +4 -0
  49. package/dist/engineSessionMessages.d.ts +1 -0
  50. package/dist/engineSessionMessages.js +7 -1
  51. package/dist/engineTargetSeat.d.ts +27 -0
  52. package/dist/engineTargetSeat.js +199 -0
  53. package/dist/engineToolDirectory.d.ts +3 -0
  54. package/dist/engineToolDirectory.js +4 -2
  55. package/dist/engineWireFor.js +3 -8
  56. package/dist/env/uiLanguage.d.ts +2 -1
  57. package/dist/env/uiLanguage.js +3 -2
  58. package/dist/eventLeg.d.ts +7 -5
  59. package/dist/eventLeg.js +68 -49
  60. package/dist/fileHistoryCaptureCapability.d.ts +2 -4
  61. package/dist/fileHistoryCaptureCapability.js +12 -22
  62. package/dist/fileHistoryLegNotice.d.ts +2 -1
  63. package/dist/fileHistoryLegNotice.js +3 -3
  64. package/dist/frameBinding.d.ts +3 -0
  65. package/dist/frameBinding.js +12 -0
  66. package/dist/gateOutcome.js +16 -2
  67. package/dist/gateVocabulary.d.ts +8 -7
  68. package/dist/gateVocabulary.js +71 -73
  69. package/dist/generated/engineFactTables.d.ts +18 -1
  70. package/dist/generated/engineFactTables.js +56 -0
  71. package/dist/generated/engineNoticeTables.js +12 -3
  72. package/dist/generated/settingsSchemaFns.d.ts +18 -0
  73. package/dist/generated/settingsSchemaFns.js +70 -0
  74. package/dist/generated/settingsSchemaHooksClassifier.d.ts +2 -0
  75. package/dist/generated/settingsSchemaHooksClassifier.js +254 -0
  76. package/dist/generated/settingsSchemaMcpRequestEntry.d.ts +1 -0
  77. package/dist/generated/settingsSchemaMcpRequestEntry.js +162 -0
  78. package/dist/generated/settingsSchemaTables.d.ts +2 -0
  79. package/dist/generated/settingsSchemaTables.js +9 -0
  80. package/dist/generated/settingsSchemaTypes.d.ts +133 -0
  81. package/dist/generated/settingsSchemaTypes.js +1 -0
  82. package/dist/hitl/allowRuleShadow.d.ts +2 -1
  83. package/dist/hitl/allowRuleShadow.js +18 -15
  84. package/dist/hitl/approvalCardReasons.d.ts +3 -2
  85. package/dist/hitl/approvalCardReasons.js +29 -30
  86. package/dist/hitl/approvalHolds.d.ts +17 -0
  87. package/dist/hitl/approvalHolds.js +114 -29
  88. package/dist/hitl/askClassPair.d.ts +2 -2
  89. package/dist/hitl/askClassPair.js +16 -0
  90. package/dist/hitl/askGateWire.js +2 -1
  91. package/dist/hitl/askSettlementLine.d.ts +14 -4
  92. package/dist/hitl/askSettlementLine.js +67 -47
  93. package/dist/hitl/attributionLadder.d.ts +23 -0
  94. package/dist/hitl/attributionLadder.js +67 -0
  95. package/dist/hitl/automaticAnswerVerdict.d.ts +2 -1
  96. package/dist/hitl/automaticAnswerVerdict.js +8 -8
  97. package/dist/hitl/crashConvergedNotice.d.ts +5 -4
  98. package/dist/hitl/crashConvergedNotice.js +28 -41
  99. package/dist/hitl/decisionLedger.d.ts +55 -0
  100. package/dist/hitl/decisionLedger.js +156 -0
  101. package/dist/hitl/decisionRefusal.d.ts +1 -0
  102. package/dist/hitl/decisionRefusal.js +1 -1
  103. package/dist/hitl/decisionSend.d.ts +113 -0
  104. package/dist/hitl/decisionSend.js +579 -0
  105. package/dist/hitl/frameRouter.js +7 -8
  106. package/dist/hitl/hitlBridge.d.ts +1 -0
  107. package/dist/hitl/hitlBridge.js +21 -9
  108. package/dist/hitl/persistedRulesWire.d.ts +6 -5
  109. package/dist/hitl/persistedRulesWire.js +55 -73
  110. package/dist/hitl/planReviewWire.d.ts +5 -0
  111. package/dist/hitl/planReviewWire.js +53 -76
  112. package/dist/hitl/sessionPolicyDeliverable.d.ts +2 -0
  113. package/dist/hitl/sessionPolicyDeliverable.js +49 -9
  114. package/dist/hitl/sessionPolicyWire.d.ts +2 -1
  115. package/dist/hitl/sessionPolicyWire.js +23 -24
  116. package/dist/hitl/suspendedReopen.d.ts +2 -1
  117. package/dist/hitl/suspendedReopen.js +7 -10
  118. package/dist/hitl/toolApprovalWire.d.ts +17 -5
  119. package/dist/hitl/toolApprovalWire.js +120 -147
  120. package/dist/hooksWireCaps.js +145 -56
  121. package/dist/host.d.ts +21 -0
  122. package/dist/hostTurnSettings.d.ts +110 -0
  123. package/dist/hostTurnSettings.js +692 -0
  124. package/dist/humanTurn.d.ts +15 -1
  125. package/dist/humanTurn.js +100 -12
  126. package/dist/humanTurnRead.d.ts +2 -0
  127. package/dist/humanTurnRead.js +22 -1
  128. package/dist/i18n/messages.en.d.ts +713 -0
  129. package/dist/i18n/messages.en.js +713 -0
  130. package/dist/i18n/messages.zh.js +854 -1
  131. package/dist/index.d.ts +45 -13
  132. package/dist/index.js +27 -9
  133. package/dist/inheritEnvCapability.d.ts +4 -2
  134. package/dist/inheritEnvCapability.js +12 -5
  135. package/dist/inheritEnvWire.d.ts +3 -2
  136. package/dist/inheritEnvWire.js +14 -16
  137. package/dist/injectionLaneNotice.d.ts +5 -0
  138. package/dist/injectionLaneNotice.js +46 -0
  139. package/dist/interactiveHalt.js +17 -6
  140. package/dist/liveModelCatalog.d.ts +2 -1
  141. package/dist/liveModelCatalog.js +14 -8
  142. package/dist/mcpPanel.d.ts +10 -1
  143. package/dist/mcpPanel.js +42 -13
  144. package/dist/mcpProbeCapability.d.ts +2 -1
  145. package/dist/mcpProbeCapability.js +7 -11
  146. package/dist/mcpProbeWire.d.ts +3 -1
  147. package/dist/mcpProbeWire.js +5 -0
  148. package/dist/mcpReconnect.js +2 -2
  149. package/dist/mcpToolToggles.d.ts +6 -0
  150. package/dist/mcpToolToggles.js +46 -0
  151. package/dist/mcpWireCaps.d.ts +43 -3
  152. package/dist/mcpWireCaps.js +194 -59
  153. package/dist/mcpWireTransport.d.ts +4 -0
  154. package/dist/mcpWireTransport.js +18 -0
  155. package/dist/memoryEntriesWire.js +5 -10
  156. package/dist/model/onboardJudgement.d.ts +93 -0
  157. package/dist/model/onboardJudgement.js +415 -0
  158. package/dist/model/tierVocabulary.d.ts +2 -0
  159. package/dist/model/tierVocabulary.js +17 -5
  160. package/dist/modelCapabilityProbe.d.ts +65 -0
  161. package/dist/modelCapabilityProbe.js +601 -0
  162. package/dist/modelIdentityResolvability.d.ts +5 -0
  163. package/dist/modelIdentityResolvability.js +49 -22
  164. package/dist/ownKey.d.ts +33 -0
  165. package/dist/ownKey.js +109 -0
  166. package/dist/panelReduce.d.ts +11 -1
  167. package/dist/panelReduce.js +95 -16
  168. package/dist/panelStateHolder.d.ts +1 -0
  169. package/dist/panelStateHolder.js +10 -1
  170. package/dist/permissionRuleIssue.d.ts +2 -1
  171. package/dist/permissionRuleIssue.js +23 -20
  172. package/dist/permissionRulesWriteCapability.d.ts +2 -1
  173. package/dist/permissionRulesWriteCapability.js +8 -6
  174. package/dist/pluginHooksWire.d.ts +46 -3
  175. package/dist/pluginHooksWire.js +220 -12
  176. package/dist/prepareRefusal.d.ts +8 -0
  177. package/dist/prepareRefusal.js +72 -0
  178. package/dist/printModelStatus.d.ts +63 -0
  179. package/dist/printModelStatus.js +155 -0
  180. package/dist/request/taskRequest.d.ts +16 -10
  181. package/dist/request/taskRequest.js +195 -58
  182. package/dist/resumeRefusalCopy.d.ts +14 -9
  183. package/dist/resumeRefusalCopy.js +89 -144
  184. package/dist/retryStatus.d.ts +55 -0
  185. package/dist/retryStatus.js +155 -19
  186. package/dist/ruleRefusalSentence.d.ts +4 -0
  187. package/dist/ruleRefusalSentence.js +58 -0
  188. package/dist/sandboxWire.d.ts +2 -1
  189. package/dist/sandboxWire.js +55 -21
  190. package/dist/scenarioRefusal.d.ts +10 -0
  191. package/dist/scenarioRefusal.js +111 -0
  192. package/dist/seam.d.ts +48 -9
  193. package/dist/seam.js +54 -5
  194. package/dist/seatContract.d.ts +272 -14
  195. package/dist/seatContract.js +711 -23
  196. package/dist/selfOrchestrationDenial.js +7 -19
  197. package/dist/sessionIdSegment.d.ts +6 -0
  198. package/dist/sessionIdSegment.js +24 -0
  199. package/dist/sessionMemoryStatus.js +6 -11
  200. package/dist/sessionPolicyCapability.d.ts +2 -1
  201. package/dist/sessionPolicyCapability.js +8 -6
  202. package/dist/settingsCredentialKeyPaths.d.ts +8 -0
  203. package/dist/settingsCredentialKeyPaths.js +219 -0
  204. package/dist/settingsHooksSalvage.d.ts +44 -0
  205. package/dist/settingsHooksSalvage.js +211 -0
  206. package/dist/skillToolListsCapability.d.ts +2 -1
  207. package/dist/skillToolListsCapability.js +8 -6
  208. package/dist/skillsWireCaps.d.ts +0 -3
  209. package/dist/skillsWireCaps.js +1 -2
  210. package/dist/sseIdleTriage.js +3 -2
  211. package/dist/subagent/engineSubagentResume.js +15 -9
  212. package/dist/subagentContentStore.d.ts +4 -0
  213. package/dist/subagentContentStore.js +157 -27
  214. package/dist/toolHistoryMismatch.js +3 -2
  215. package/dist/toolRoster.d.ts +3 -2
  216. package/dist/toolRoster.js +21 -20
  217. package/dist/toolsFlagNames.d.ts +8 -0
  218. package/dist/toolsFlagNames.js +110 -0
  219. package/dist/turnFailurePresentation.d.ts +12 -1
  220. package/dist/turnFailurePresentation.js +220 -15
  221. package/dist/usageAnalytics.js +6 -11
  222. package/dist/userAttachmentEnvelope.d.ts +1 -0
  223. package/dist/userAttachmentEnvelope.js +37 -7
  224. package/dist/userAttachmentSeat.d.ts +21 -0
  225. package/dist/userAttachmentSeat.js +75 -0
  226. package/dist/userInvokedSkillsCapability.d.ts +11 -1
  227. package/dist/userInvokedSkillsCapability.js +31 -7
  228. package/dist/wireErrorTriage.d.ts +7 -0
  229. package/dist/wireErrorTriage.js +23 -1
  230. package/dist/wireFailureShape.js +2 -1
  231. package/dist/wireRefusalCopy.d.ts +62 -16
  232. package/dist/wireRefusalCopy.js +307 -148
  233. package/dist/workflowsJournalCapability.d.ts +2 -1
  234. package/dist/workflowsJournalCapability.js +8 -6
  235. package/docs/INTEGRATION-CLIENTS.md +951 -42
  236. package/package.json +5 -5
@@ -35,18 +35,20 @@ export function engineToolDirectoryOf(source) {
35
35
  const deployment = readHalf(ownDataField(source, 'deploymentMcpServers'));
36
36
  if (request === 'unreadable' || deployment === 'unreadable')
37
37
  return unreadable();
38
- if (request === 'absent' || deployment === 'absent')
38
+ if (request === 'absent')
39
39
  return notLanded();
40
40
  const ns = namingPorts();
41
41
  if (ns === undefined)
42
42
  return unreadable();
43
43
  const prefixes = [];
44
- for (const name of [...request, ...deployment]) {
44
+ for (const name of deployment === 'absent' ? request : [...request, ...deployment]) {
45
45
  const prefix = mintNamespacePrefix(ns, name);
46
46
  if (typeof prefix !== 'string' || prefix.length === 0)
47
47
  return unreadable();
48
48
  prefixes.push(prefix);
49
49
  }
50
+ if (deployment === 'absent')
51
+ return Object.freeze({ state: 'request_only', requestMcpServerPrefixes: frozenSet(prefixes) });
50
52
  return Object.freeze({ state: 'directory', mcpServerPrefixes: frozenSet(prefixes) });
51
53
  }
52
54
  catch {
@@ -1,6 +1,7 @@
1
1
  import { settleWithinDeadline } from './abortableSleep.js';
2
2
  import { makeEngineWireClient } from './engineWireSdk.js';
3
3
  import { engineWireTargetFor } from './engineWireTarget.js';
4
+ import { readThrownSlot } from './wireFailureShape.js';
4
5
  export const INJECTED_WIRE_SETTLE_MS = 60_000;
5
6
  export function engineWireFor(wire, sessionKey, usable) {
6
7
  if (wire !== undefined) {
@@ -285,15 +286,9 @@ function abortedBeforeSendError() {
285
286
  return e;
286
287
  }
287
288
  function answeredByEngine(e) {
288
- try {
289
- if (e === null || typeof e !== 'object')
290
- return false;
291
- const o = e;
292
- return typeof o.status === 'number' || typeof o.errorCode === 'string';
293
- }
294
- catch {
289
+ if (e === null || typeof e !== 'object')
295
290
  return false;
296
- }
291
+ return typeof readThrownSlot(e, 'status', 'data') === 'number' || typeof readThrownSlot(e, 'errorCode', 'data') === 'string';
297
292
  }
298
293
  const SETTLED_BY_PACKAGE_BRAND = Symbol.for('@sema-agent/client-core:engine-wire-settled');
299
294
  function settledByPackage(value) {
@@ -1,4 +1,5 @@
1
- export type UiLanguage = 'en' | 'zh';
1
+ import { SETTINGS_UI_LANGUAGE_VALUES } from '../generated/settingsSchemaTables.js';
2
+ export type UiLanguage = (typeof SETTINGS_UI_LANGUAGE_VALUES)[number];
2
3
  export declare const UI_LANGUAGES: readonly UiLanguage[];
3
4
  export declare const UI_LANGUAGE_ENDONYMS: Record<UiLanguage, string>;
4
5
  export declare function isUiLanguage(v: unknown): v is UiLanguage;
@@ -1,11 +1,12 @@
1
1
  import { parseLocaleTag } from './localeTag.js';
2
- export const UI_LANGUAGES = ['en', 'zh'];
2
+ import { SETTINGS_UI_LANGUAGE_VALUES } from '../generated/settingsSchemaTables.js';
3
+ export const UI_LANGUAGES = SETTINGS_UI_LANGUAGE_VALUES;
3
4
  export const UI_LANGUAGE_ENDONYMS = {
4
5
  en: 'English',
5
6
  zh: '中文',
6
7
  };
7
8
  export function isUiLanguage(v) {
8
- return v === 'en' || v === 'zh';
9
+ return typeof v === 'string' && UI_LANGUAGES.includes(v);
9
10
  }
10
11
  export function pickUiLanguage(localeTag) {
11
12
  return parseLocaleTag(localeTag).language === 'zh' ? 'zh' : 'en';
@@ -2,6 +2,7 @@ import type { AgentEvent } from '@sema-agent/sdk';
2
2
  import type { EngineBoundRun } from './engineRowRef.js';
3
3
  import { type AskGateWireDeps } from './hitl/askGateWire.js';
4
4
  import { type ActiveRunBusySignal } from './adapter/runStream.js';
5
+ import type { ApprovalRequestChromeEvent, ApprovalRevokeChromeEvent } from './seam.js';
5
6
  export declare const EVENT_LEG_KINDS: readonly ["live", "durable", "continuation"];
6
7
  export type EventLegKind = (typeof EVENT_LEG_KINDS)[number];
7
8
  export type EventLegStage = 'bindRun' | 'stampOwner' | 'hitlFrames' | 'askBridge' | 'idleTriage';
@@ -64,11 +65,13 @@ export interface EventLegIdleTriagePorts {
64
65
  readonly baseUrl: string;
65
66
  }
66
67
  export type EventLegTap = (frame: AgentEvent) => void;
67
- export type EventLegStreamDecorator = (stream: AsyncGenerator<AgentEvent>, ctx: EventLegStreamContext) => AsyncGenerator<AgentEvent>;
68
- export interface EventLegStreamContext {
68
+ export interface ApprovalFrameContext {
69
69
  readonly leg: EventLegKind;
70
- readonly runId: string | undefined;
70
+ readonly windowIsCurrent: boolean;
71
+ readonly receivedAtMs: number;
72
+ readonly streamEnded: AbortSignal;
71
73
  }
74
+ export declare function approvalFrameContextOf(arm: ApprovalRequestChromeEvent | ApprovalRevokeChromeEvent): ApprovalFrameContext | undefined;
72
75
  export interface EventLegPorts {
73
76
  readonly run?: EventLegRunPorts;
74
77
  readonly owner?: EventLegOwnerPorts;
@@ -77,9 +80,8 @@ export interface EventLegPorts {
77
80
  readonly idleTriage?: EventLegIdleTriagePorts;
78
81
  readonly signal?: AbortSignal;
79
82
  readonly taps?: readonly EventLegTap[];
80
- readonly perStream?: readonly EventLegStreamDecorator[];
81
83
  }
82
- export type EventLegPortName = 'run.headerRunId' | 'run.onBound' | 'run.onRefused' | 'run.onTerminal' | 'run.isCurrent' | 'hitl.question' | 'hitl.elicitation' | 'hitl.toolApproval' | 'askBridge.respondToolApproval' | 'taps' | 'perStream';
84
+ export type EventLegPortName = 'run.headerRunId' | 'run.onBound' | 'run.onRefused' | 'run.onTerminal' | 'run.isCurrent' | 'hitl.question' | 'hitl.elicitation' | 'hitl.toolApproval' | 'askBridge.respondToolApproval' | 'taps';
83
85
  export interface EventLegReport {
84
86
  readonly missingPorts: readonly EventLegPortName[];
85
87
  readonly portFaults: Readonly<Partial<Record<EventLegPortName, number>>>;
package/dist/eventLeg.js CHANGED
@@ -1,4 +1,4 @@
1
- import { frameBindingOf, registerFrameBinding } from './frameBinding.js';
1
+ import { approvalFrameContextOfFrame, frameBindingOf, registerApprovalFrameContext, registerFrameBinding } from './frameBinding.js';
2
2
  import { bridgeAskUserQuestionGates } from './hitl/askGateWire.js';
3
3
  import { diagnoseSseIdleTear } from './sseIdleTriage.js';
4
4
  import { recordSubagentOwnerFromProgress } from './subagentContentStore.js';
@@ -6,6 +6,8 @@ import { activeRunBusySignal } from './adapter/runStream.js';
6
6
  import { invokeHostCallbackIsolated } from './hostCallbackGuard.js';
7
7
  import { hostLog } from './host.js';
8
8
  import { guardedRead, readOwnDataNonEmptyString, readOwnDataValue } from './ownKey.js';
9
+ import { settleEngineClosedApproval } from './hitl/approvalHolds.js';
10
+ import { approvalCompleteParked } from './hitl/approvalCompleteParked.js';
9
11
  export const EVENT_LEG_KINDS = Object.freeze(['live', 'durable', 'continuation']);
10
12
  export const EVENT_LEG_TABLE = Object.freeze({
11
13
  live: Object.freeze({ stages: Object.freeze(['bindRun', 'stampOwner', 'hitlFrames', 'askBridge', 'idleTriage']), windowIsCurrent: true }),
@@ -18,8 +20,14 @@ function makeFrameStageDomains(domains) {
18
20
  const FRAME_STAGE_DOMAINS = makeFrameStageDomains({
19
21
  bindRun: Object.freeze(['meta', 'done', 'failed']),
20
22
  stampOwner: Object.freeze(['task_progress']),
21
- hitlFrames: Object.freeze(['question', 'question_complete', 'elicitation', 'elicitation_complete', 'tool_approval', 'tool_approval_complete']),
23
+ hitlFrames: Object.freeze(['question', 'question_complete', 'elicitation', 'elicitation_complete', 'tool_approval', 'tool_approval_complete', 'approval_request', 'approval_revoke']),
22
24
  });
25
+ const HITL_FRAMES_PROJECTED = Object.freeze(['human_input']);
26
+ const _hitlFrameTypesPin = [true, true];
27
+ const _hitlProjectedDisjointPin = true;
28
+ void _hitlFrameTypesPin;
29
+ void _hitlProjectedDisjointPin;
30
+ void HITL_FRAMES_PROJECTED;
23
31
  const HITL_PORT_OF = Object.freeze({
24
32
  question: 'question',
25
33
  question_complete: 'question',
@@ -27,8 +35,14 @@ const HITL_PORT_OF = Object.freeze({
27
35
  elicitation_complete: 'elicitation',
28
36
  tool_approval: 'toolApproval',
29
37
  tool_approval_complete: 'toolApproval',
38
+ approval_request: 'register',
39
+ approval_revoke: 'register',
30
40
  });
31
41
  const inDomain = (stage, frameType) => FRAME_STAGE_DOMAINS[stage].includes(frameType);
42
+ export function approvalFrameContextOf(arm) {
43
+ const frame = guardedRead(() => readOwnDataValue(arm, 'frame'));
44
+ return typeof frame === 'object' && frame !== null ? approvalFrameContextOfFrame(frame) : undefined;
45
+ }
32
46
  const HOST_PORT_MISSING = 'host_port_missing';
33
47
  export function composeEventLeg(source, leg, ports) {
34
48
  const kind = leg.kind;
@@ -122,7 +136,6 @@ export function composeEventLeg(source, leg, ports) {
122
136
  };
123
137
  const sessionKey = typeof ports.owner?.sessionKey === 'string' && ports.owner.sessionKey !== '' ? ports.owner.sessionKey : undefined;
124
138
  const taps = (ports.taps ?? []).filter((t) => typeof t === 'function');
125
- const decorators = (ports.perStream ?? []).filter((d) => typeof d === 'function');
126
139
  const info = Object.freeze({ leg: kind });
127
140
  const runSessions = new Map();
128
141
  let lastBound;
@@ -136,12 +149,18 @@ export function composeEventLeg(source, leg, ports) {
136
149
  const boundInfo = Object.freeze({ cause, leg: kind });
137
150
  callPort('run.onBound', () => runPorts.onBound?.(binding, boundInfo));
138
151
  };
139
- const deliverHitl = (ev, env) => {
152
+ const deliverHitl = (ev, env, streamEnded) => {
140
153
  if (!inDomain('hitlFrames', ev.type))
141
154
  return false;
142
155
  const port = HITL_PORT_OF[ev.type];
156
+ if (port === 'register') {
157
+ registerApprovalFrameContext(ev, Object.freeze({ leg: env.leg, windowIsCurrent: env.windowIsCurrent, receivedAtMs: Date.now(), streamEnded }));
158
+ return false;
159
+ }
143
160
  if (port === 'toolApproval' && hostBridge !== undefined)
144
161
  return false;
162
+ if (ev.type === 'tool_approval_complete')
163
+ settleEngineClosedApproval(ev, approvalCompleteParked(ev));
145
164
  const threw = callPort(`hitl.${port}`, () => hitl?.[port]?.call(hitl, ev, env));
146
165
  if (threw)
147
166
  hitlUndelivered++;
@@ -153,58 +172,58 @@ export function composeEventLeg(source, leg, ports) {
153
172
  let binding;
154
173
  let runEvidence = false;
155
174
  const env = Object.freeze({ windowIsCurrent: EVENT_LEG_TABLE[streamKind].windowIsCurrent, leg: streamKind });
156
- for await (const ev of stream) {
157
- if (taskId === undefined && streamKind === 'live')
158
- taskId = readHeaderRunId();
159
- const refusal = streamKind === 'live' && !runEvidence && inDomain('bindRun', ev.type) ? refusalOf(ev, taskId) : undefined;
160
- if (!inDomain('bindRun', ev.type))
161
- runEvidence = true;
162
- if (refusal !== undefined) {
163
- if (runPorts !== undefined && typeof runPorts.onRefused === 'function' && isCurrentNow())
164
- callPort('run.onRefused', () => runPorts.onRefused?.(refusal, info));
165
- }
166
- else {
167
- if (ev.type === 'meta' || ev.type === 'done') {
168
- const carrier = ev.type === 'meta' ? ev : ev.result;
169
- const tid = typeof carrier === 'object' && carrier !== null ? guardedRead(() => readOwnDataNonEmptyString(carrier, 'taskId')) : undefined;
170
- const sid = typeof carrier === 'object' && carrier !== null ? guardedRead(() => readOwnDataNonEmptyString(carrier, 'sessionId')) : undefined;
171
- const runId = ev.type === 'done' && tid !== undefined && tid === sid ? undefined : tid;
172
- if (streamKind === 'live' && runId !== undefined && runId !== taskId) {
173
- taskId = runId;
174
- sessionId = sid;
175
+ const ended = new AbortController();
176
+ try {
177
+ for await (const ev of stream) {
178
+ if (taskId === undefined && streamKind === 'live')
179
+ taskId = readHeaderRunId();
180
+ const refusal = streamKind === 'live' && !runEvidence && inDomain('bindRun', ev.type) ? refusalOf(ev, taskId) : undefined;
181
+ if (!inDomain('bindRun', ev.type))
182
+ runEvidence = true;
183
+ if (refusal !== undefined) {
184
+ if (runPorts !== undefined && typeof runPorts.onRefused === 'function' && isCurrentNow())
185
+ callPort('run.onRefused', () => runPorts.onRefused?.(refusal, info));
186
+ }
187
+ else {
188
+ if (ev.type === 'meta' || ev.type === 'done') {
189
+ const carrier = ev.type === 'meta' ? ev : ev.result;
190
+ const tid = typeof carrier === 'object' && carrier !== null ? guardedRead(() => readOwnDataNonEmptyString(carrier, 'taskId')) : undefined;
191
+ const sid = typeof carrier === 'object' && carrier !== null ? guardedRead(() => readOwnDataNonEmptyString(carrier, 'sessionId')) : undefined;
192
+ const runId = ev.type === 'done' && tid !== undefined && tid === sid ? undefined : tid;
193
+ if (streamKind === 'live' && runId !== undefined && runId !== taskId) {
194
+ taskId = runId;
195
+ sessionId = sid;
196
+ }
197
+ else if (sid !== undefined && taskId !== undefined && (runId === undefined || runId === taskId)) {
198
+ sessionId = sid;
199
+ }
175
200
  }
176
- else if (sid !== undefined && taskId !== undefined && (runId === undefined || runId === taskId)) {
177
- sessionId = sid;
201
+ if (taskId !== undefined) {
202
+ if (binding === undefined || binding.taskId !== taskId || binding.sessionId !== sessionId) {
203
+ binding = Object.freeze({ taskId, ...(sessionId !== undefined ? { sessionId } : {}) });
204
+ }
205
+ if (sessionId !== undefined)
206
+ runSessions.set(taskId, sessionId);
207
+ registerFrameBinding(ev, binding);
208
+ noteBound(binding);
178
209
  }
179
210
  }
180
- if (taskId !== undefined) {
181
- if (binding === undefined || binding.taskId !== taskId || binding.sessionId !== sessionId) {
182
- binding = Object.freeze({ taskId, ...(sessionId !== undefined ? { sessionId } : {}) });
183
- }
184
- if (sessionId !== undefined)
185
- runSessions.set(taskId, sessionId);
186
- registerFrameBinding(ev, binding);
187
- noteBound(binding);
211
+ if (inDomain('stampOwner', ev.type)) {
212
+ const b = frameBindingOf(ev);
213
+ recordSubagentOwnerFromProgress(ev, b?.taskId, b?.sessionId, sessionKey);
188
214
  }
215
+ if (deliverHitl(ev, env, ended.signal))
216
+ continue;
217
+ for (const tap of taps)
218
+ callPort('taps', () => tap(ev));
219
+ yield ev;
189
220
  }
190
- if (inDomain('stampOwner', ev.type)) {
191
- const b = frameBindingOf(ev);
192
- recordSubagentOwnerFromProgress(ev, b?.taskId, b?.sessionId, sessionKey);
193
- }
194
- if (deliverHitl(ev, env))
195
- continue;
196
- for (const tap of taps)
197
- callPort('taps', () => tap(ev));
198
- yield ev;
221
+ }
222
+ finally {
223
+ ended.abort();
199
224
  }
200
225
  }
201
- const streamOf = (raw, streamKind, streamRunId) => {
202
- let s = generatorOf(raw);
203
- const ctx = Object.freeze({ leg: streamKind, runId: streamRunId });
204
- for (const d of decorators)
205
- s = d(s, ctx);
206
- return frameLevel(s, streamKind, streamRunId);
207
- };
226
+ const streamOf = (raw, streamKind, streamRunId) => frameLevel(generatorOf(raw), streamKind, streamRunId);
208
227
  let inner = streamOf(source, kind, legRunId);
209
228
  if (hostBridge !== undefined) {
210
229
  let windowOpen = row.windowIsCurrent;
@@ -1,3 +1,4 @@
1
+ import type { UiLanguage } from './env/uiLanguage.js';
1
2
  export type FileHistoryCaptureReading = {
2
3
  kind: 'unobserved';
3
4
  } | {
@@ -12,13 +13,10 @@ export type FileHistoryCaptureMode = 'off' | 'on-optional' | 'unknown';
12
13
  export declare function projectFileHistoryCaptureCapability(caps: unknown): FileHistoryCaptureReading | undefined;
13
14
  export declare function observedFileHistoryCapture(baseUrl?: string | undefined): FileHistoryCaptureReading;
14
15
  export declare function fileHistoryCaptureMode(reading: FileHistoryCaptureReading): FileHistoryCaptureMode;
15
- export declare function fileHistoryDeclarationField(reading: FileHistoryCaptureReading, captureOff: boolean): {
16
- fileHistory: 'disabled';
17
- } | Record<string, never>;
18
16
  export declare const FILE_HISTORY_TIGHTEN_VERDICTS: readonly ["not_requested", "declare", "already_off", "unjudged"];
19
17
  export type FileHistoryTightenVerdict = (typeof FILE_HISTORY_TIGHTEN_VERDICTS)[number];
20
18
  export declare function fileHistoryTightenVerdict(reading: FileHistoryCaptureReading, captureOffByUser: boolean): FileHistoryTightenVerdict;
21
- export declare function fileHistoryUnjudgedRefusal(reading: FileHistoryCaptureReading, captureOffByUser: boolean): string | undefined;
19
+ export declare function fileHistoryUnjudgedRefusal(reading: FileHistoryCaptureReading, captureOffByUser: boolean, lang?: UiLanguage): string | undefined;
22
20
  export interface FileHistoryTightenJudgement {
23
21
  readonly verdict: FileHistoryTightenVerdict;
24
22
  readonly reading: FileHistoryCaptureReading;
@@ -1,9 +1,9 @@
1
+ import { msg, renderMessage } from './i18n/translate.js';
1
2
  import { capForDisplay } from './fleetTaskDesc.js';
2
3
  import { engineWireTarget } from './engineWireTarget.js';
3
4
  import { createEngineCapReader, unreadableReadingDetail } from './engineCapReader.js';
4
5
  import { refreshEngineCapsOnce } from './engineCapsCache.js';
5
6
  import { ownDataField } from './ownKey.js';
6
- import { FILE_HISTORY_DISABLED } from './request/taskRequest.js';
7
7
  export function projectFileHistoryCaptureCapability(caps) {
8
8
  try {
9
9
  if (caps === null || typeof caps !== 'object' || Array.isArray(caps))
@@ -46,9 +46,6 @@ export function fileHistoryCaptureMode(reading) {
46
46
  return 'on-optional';
47
47
  return 'unknown';
48
48
  }
49
- export function fileHistoryDeclarationField(reading, captureOff) {
50
- return captureOff === true && fileHistoryCaptureMode(reading) === 'on-optional' ? { fileHistory: FILE_HISTORY_DISABLED } : {};
51
- }
52
49
  export const FILE_HISTORY_TIGHTEN_VERDICTS = Object.freeze(['not_requested', 'declare', 'already_off', 'unjudged']);
53
50
  export function fileHistoryTightenVerdict(reading, captureOffByUser) {
54
51
  if (captureOffByUser !== true)
@@ -60,21 +57,11 @@ export function fileHistoryTightenVerdict(reading, captureOffByUser) {
60
57
  return 'already_off';
61
58
  return 'unjudged';
62
59
  }
63
- const FILE_HISTORY_REFUSAL_NOT_YET = "Nothing was sent: file checkpointing is turned off in your settings, but this engine's capabilities have not been read " +
64
- 'yet, so whether it can stop recording file history for a session is unknown and sending now could record it anyway. ' +
65
- 'Try again in a moment; to send regardless and let file history be recorded this time, turn file checkpointing back on in your settings.';
66
- const FILE_HISTORY_REFUSAL_NOT_SAID = 'Nothing was sent: file checkpointing is turned off in your settings, but this engine did not report whether it can ' +
67
- 'stop recording file history for a session, so sending now could record it anyway. Trying again will not change that ' +
68
- 'while this engine reports the same; to send and let file history be recorded this time, turn file checkpointing back on in your settings.';
69
- const FILE_HISTORY_REFUSAL_UNRECOGNIZED = 'Nothing was sent: file checkpointing is turned off in your settings, but this engine reported a file-history capture mode ' +
70
- 'this client does not recognize, so whether it can stop recording file history for a session is unknown and sending now could ' +
71
- 'record it anyway. Trying again will not change that while this engine reports the same; to send and let file history be ' +
72
- 'recorded this time, turn file checkpointing back on in your settings.';
73
- const FILE_HISTORY_REFUSAL_UNREADABLE = "Nothing was sent: file checkpointing is turned off in your settings, but this engine's report on whether it can stop " +
74
- 'recording file history for a session could not be read by this client, so sending now could record it anyway. Trying ' +
75
- 'again will not change that while this engine reports the same; to send and let file history be recorded this time, ' +
76
- 'turn file checkpointing back on in your settings.';
77
- function unjudgedRefusalOf(reading) {
60
+ const FILE_HISTORY_REFUSAL_NOT_YET = 'session.fileHistoryRefusal.notYet';
61
+ const FILE_HISTORY_REFUSAL_NOT_SAID = 'session.fileHistoryRefusal.notSaid';
62
+ const FILE_HISTORY_REFUSAL_UNRECOGNIZED = 'session.fileHistoryRefusal.unrecognized';
63
+ const FILE_HISTORY_REFUSAL_UNREADABLE = 'session.fileHistoryRefusal.unreadable';
64
+ function unjudgedRefusalKeyOf(reading) {
78
65
  let kind;
79
66
  let word;
80
67
  try {
@@ -92,8 +79,11 @@ function unjudgedRefusalOf(reading) {
92
79
  return FILE_HISTORY_REFUSAL_UNRECOGNIZED;
93
80
  return FILE_HISTORY_REFUSAL_NOT_YET;
94
81
  }
95
- export function fileHistoryUnjudgedRefusal(reading, captureOffByUser) {
96
- return fileHistoryTightenVerdict(reading, captureOffByUser) === 'unjudged' ? unjudgedRefusalOf(reading) : undefined;
82
+ function unjudgedRefusalOf(reading, lang) {
83
+ return renderMessage(msg(unjudgedRefusalKeyOf(reading)), lang);
84
+ }
85
+ export function fileHistoryUnjudgedRefusal(reading, captureOffByUser, lang) {
86
+ return fileHistoryTightenVerdict(reading, captureOffByUser) === 'unjudged' ? unjudgedRefusalOf(reading, lang) : undefined;
97
87
  }
98
88
  const FILE_HISTORY_REFRESH_WITHIN_MS = 3000;
99
89
  export async function judgeFileHistoryTighten(captureOffByUser, opts) {
@@ -101,7 +91,7 @@ export async function judgeFileHistoryTighten(captureOffByUser, opts) {
101
91
  const failClosed = () => {
102
92
  const reading = { kind: 'unobserved' };
103
93
  return closed
104
- ? { verdict: 'unjudged', reading, refreshed: false, refusal: FILE_HISTORY_REFUSAL_NOT_YET }
94
+ ? { verdict: 'unjudged', reading, refreshed: false, refusal: renderMessage(msg(FILE_HISTORY_REFUSAL_NOT_YET)) }
105
95
  : { verdict: 'not_requested', reading, refreshed: false, refusal: undefined };
106
96
  };
107
97
  try {
@@ -1,4 +1,5 @@
1
1
  import type { AgentEvent } from '@sema-agent/sdk';
2
+ import type { UiLanguage } from './env/uiLanguage.js';
2
3
  import { type FileHistoryCaptureReading } from './fileHistoryCaptureCapability.js';
3
4
  export type FileHistoryDeclarationFact = 'sent' | 'not_sent' | 'unknown';
4
5
  export declare const FILE_HISTORY_LEG_VERDICTS: readonly ["not_honored", "honored", "not_declared", "unknown"];
@@ -10,7 +11,7 @@ export interface FileHistoryLegNoticeInput {
10
11
  readonly legWord: string | undefined;
11
12
  }
12
13
  export declare function fileHistoryLegNoticeVerdict(input: FileHistoryLegNoticeInput): FileHistoryLegNoticeVerdict;
13
- export declare function fileHistoryLegNoticeSentence(verdict: FileHistoryLegNoticeVerdict): string | null;
14
+ export declare function fileHistoryLegNoticeSentence(verdict: FileHistoryLegNoticeVerdict, lang?: UiLanguage): string | null;
14
15
  export declare function fileHistoryDeclarationOfBody(body: object | null | undefined): FileHistoryDeclarationFact;
15
16
  export type OutboundBodyField = {
16
17
  kind: 'absent';
@@ -1,4 +1,5 @@
1
1
  import { fileHistoryCaptureMode } from './fileHistoryCaptureCapability.js';
2
+ import { msg, renderMessage } from './i18n/translate.js';
2
3
  import { frameProvesDelivery } from './promptDelivery.js';
3
4
  import { FILE_HISTORY_DISABLED } from './request/taskRequest.js';
4
5
  export const FILE_HISTORY_LEG_VERDICTS = Object.freeze(['not_honored', 'honored', 'not_declared', 'unknown']);
@@ -35,10 +36,9 @@ export function fileHistoryLegNoticeVerdict(input) {
35
36
  return 'not_declared';
36
37
  return 'unknown';
37
38
  }
38
- const NOT_HONORED_SENTENCE = 'The engine is still capturing file history for this session, though your settings asked it not to.';
39
- export function fileHistoryLegNoticeSentence(verdict) {
39
+ export function fileHistoryLegNoticeSentence(verdict, lang) {
40
40
  if (verdict === 'not_honored')
41
- return NOT_HONORED_SENTENCE;
41
+ return renderMessage(msg('session.fileHistoryLeg.notHonored'), lang);
42
42
  return null;
43
43
  }
44
44
  export function fileHistoryDeclarationOfBody(body) {
@@ -1,5 +1,8 @@
1
1
  import type { AgentEvent } from '@sema-agent/sdk';
2
2
  import type { EngineBoundRun } from './engineRowRef.js';
3
+ import type { ApprovalFrameContext } from './eventLeg.js';
4
+ export declare function registerApprovalFrameContext(frame: AgentEvent, ctx: ApprovalFrameContext): void;
5
+ export declare function approvalFrameContextOfFrame(frame: object | null | undefined): ApprovalFrameContext | undefined;
3
6
  export declare function registerFrameBinding(frame: AgentEvent, binding: EngineBoundRun): void;
4
7
  export declare function frameBindingOf(frame: AgentEvent): EngineBoundRun | undefined;
5
8
  export declare function inheritFrameBinding<T extends AgentEvent>(from: AgentEvent, to: T): T;
@@ -1,4 +1,13 @@
1
1
  const frameBindings = new WeakMap();
2
+ const approvalFrameContexts = new WeakMap();
3
+ export function registerApprovalFrameContext(frame, ctx) {
4
+ if (typeof frame !== 'object' || frame === null || approvalFrameContexts.has(frame))
5
+ return;
6
+ approvalFrameContexts.set(frame, ctx);
7
+ }
8
+ export function approvalFrameContextOfFrame(frame) {
9
+ return typeof frame === 'object' && frame !== null ? approvalFrameContexts.get(frame) : undefined;
10
+ }
2
11
  export function registerFrameBinding(frame, binding) {
3
12
  if (typeof frame !== 'object' || frame === null)
4
13
  return;
@@ -19,5 +28,8 @@ export function inheritFrameBinding(from, to) {
19
28
  const binding = frameBindings.get(from);
20
29
  if (binding !== undefined && !frameBindings.has(to))
21
30
  frameBindings.set(to, binding);
31
+ const ctx = approvalFrameContexts.get(from);
32
+ if (ctx !== undefined && !approvalFrameContexts.has(to))
33
+ approvalFrameContexts.set(to, ctx);
22
34
  return to;
23
35
  }
@@ -237,9 +237,23 @@ export function gateOutcomeOf(frame) {
237
237
  return readGateRecord(frame)?.view;
238
238
  }
239
239
  export function isGateParkedToolEnd(frame) {
240
- if (typeof frame !== 'object' || frame === null || Array.isArray(frame))
240
+ if (typeof frame !== 'object' || frame === null)
241
+ return false;
242
+ try {
243
+ if (Array.isArray(frame))
244
+ return false;
245
+ if (readOwnDataValue(frame, 'errorCode') === GATE_PARKED_ERROR_CODE)
246
+ return true;
247
+ if (readOwnDataValue(frame, 'role') !== 'toolResult')
248
+ return false;
249
+ const details = readOwnDataValue(frame, 'details');
250
+ if (typeof details !== 'object' || details === null || Array.isArray(details))
251
+ return false;
252
+ return readOwnDataValue(details, 'code') === GATE_PARKED_ERROR_CODE;
253
+ }
254
+ catch {
241
255
  return false;
242
- return frame.errorCode === GATE_PARKED_ERROR_CODE;
256
+ }
243
257
  }
244
258
  export function gateModeRelease(g) {
245
259
  return g?.disposition.kind === 'allowed' ? g.disposition.released : undefined;
@@ -1,4 +1,5 @@
1
1
  import { CORE_DENIED_BY_VALUES, CORE_PERSISTED_RULE_MANDATES } from './generated/engineFactTables.js';
2
+ import type { UiLanguage } from './env/uiLanguage.js';
2
3
  export declare const CC_TOOL_DENIAL_KINDS: readonly ["user-rejected", "permission-rule", "automode-blocked", "automode-unavailable", "automode-parsing-error", "interrupted", "cancelled"];
3
4
  export type CcToolDenialKind = (typeof CC_TOOL_DENIAL_KINDS)[number];
4
5
  export declare function isCcToolDenialKind(v: unknown): v is CcToolDenialKind;
@@ -7,15 +8,15 @@ export declare function ccToolDenialKindForSettledBy(settledBy: unknown): CcTool
7
8
  export type GateDeniedByWord = (typeof CORE_DENIED_BY_VALUES)[number];
8
9
  export declare const GATE_DENIED_BY_WORDS: readonly GateDeniedByWord[];
9
10
  export declare function isGateDeniedByWord(v: unknown): v is GateDeniedByWord;
10
- export declare function gateDeniedByDetail(deniedBy: unknown): string;
11
- export declare function askOriginDetail(origin: unknown): string;
12
- export declare function askOriginNoteOf(origin: string | undefined): string | undefined;
11
+ export declare function gateDeniedByDetail(deniedBy: unknown, lang?: UiLanguage): string;
12
+ export declare function askOriginDetail(origin: unknown, lang?: UiLanguage): string;
13
+ export declare function askOriginNoteOf(origin: string | undefined, lang?: UiLanguage): string | undefined;
13
14
  export declare function ruleOffersAbsenceDetail(reason: string | undefined, opts?: {
14
15
  readonly deploymentListSessionRow?: boolean;
15
- }): string | undefined;
16
- export declare function ruleOfferUncoveredDetail(reason: string | undefined): string;
17
- export declare function mandatedApprovalDetail(): string;
16
+ }, lang?: UiLanguage): string | undefined;
17
+ export declare function ruleOfferUncoveredDetail(reason: string | undefined, lang?: UiLanguage): string;
18
+ export declare function mandatedApprovalDetail(lang?: UiLanguage): string;
18
19
  export declare const APPROVAL_MANDATE_WORDS: readonly (typeof CORE_PERSISTED_RULE_MANDATES)[number][];
19
20
  export type ApprovalMandateWord = (typeof APPROVAL_MANDATE_WORDS)[number];
20
21
  export declare function isApprovalMandateWord(v: unknown): v is ApprovalMandateWord;
21
- export declare function approvalMandateDetail(word: ApprovalMandateWord): string;
22
+ export declare function approvalMandateDetail(word: ApprovalMandateWord, lang?: UiLanguage): string;