@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
@@ -1,4 +1,5 @@
1
- import { readBlockedBy, readErrorNumber, readErrorString } from './wireFailureShape.js';
1
+ import { msg, renderMessage } from './i18n/translate.js';
2
+ import { readBlockedBy, readErrorNumber, readErrorString, readThrownSlot } from './wireFailureShape.js';
2
3
  import { guardedRead, ownDataField, readOwnDataNonEmptyString, readOwnDataValue } from './ownKey.js';
3
4
  import { CORE_RESUME_STARTUP_CAUSES } from './generated/engineFactTables.js';
4
5
  import { RESUME_CONTEXT_UNAVAILABLE, RESUME_PLACEMENT_MISMATCH, RESUME_PREFLIGHT_REJECTED, RESUME_POLICY_FOLD_CODE, PARKED_RESUME_STARTUP_FAILED, isStatusDerivedCoarseCode, RESUME_SESSION_NOT_FOUND, REQUEST_FIELD_CONFLICT, CHECKPOINT_UNSUPPORTED_VERSION, CHECKPOINT_WALLTIME_AXIS_RETIRED, CHECKPOINT_CONFIG_REFUSED, isRefusedParkCode, refusalSaysStillPending, refusalRetriableReading, } from './engineErrorCodes.js';
@@ -27,51 +28,30 @@ export function resumeRefusalFromError(err) {
27
28
  ...(timed.retryAfterSec !== undefined ? { retryAfterSec: timed.retryAfterSec } : {}),
28
29
  };
29
30
  }
30
- export function resumeRefusalContent(detail) {
31
- const parts = [];
32
- if (detail.code === RESUME_PLACEMENT_MISMATCH) {
33
- parts.push('This resume named a different placement root than the one recorded when the work was parked');
34
- parts.push('The engine refused it before consuming anything — the parked work is untouched');
35
- parts.push('Retry with the recorded root, or omit the placement root to inherit it');
36
- return parts.join(' · ');
37
- }
38
- parts.push("The deployment's resume preflight refused this attempt");
39
- parts.push('The refusal happened before the commit — your decision was not consumed');
40
- parts.push(detail.waitable
41
- ? 'The engine supplied a wait, so this token stays redeemable once the obstacle clears'
42
- :
43
- 'The engine supplied no wait, so this refusal does not say whether the token stays redeemable');
44
- return parts.join(' · ');
31
+ export function resumeRefusalContent(detail, lang) {
32
+ if (detail.code === RESUME_PLACEMENT_MISMATCH)
33
+ return renderMessage(msg('resume.refusal.placementMismatch'), lang);
34
+ return renderMessage(msg(detail.waitable ? 'resume.refusal.preflightWaitable' : 'resume.refusal.preflightNoWait'), lang);
45
35
  }
46
36
  export function resumePolicyBlockFromError(err) {
47
37
  if (typeof err !== 'object' || err === null)
48
38
  return null;
49
39
  const o = err;
50
- let outer;
51
- try {
52
- outer = o['errorCode'];
53
- }
54
- catch {
55
- return null;
56
- }
40
+ const outer = guardedRead(() => ownDataField(err, 'errorCode'));
57
41
  if (outer !== RESUME_POLICY_FOLD_CODE)
58
42
  return null;
59
43
  return { blockedBy: readBlockedBy(o) };
60
44
  }
61
- export function resumePolicyBlockContent(detail) {
45
+ export function resumePolicyBlockContent(detail, lang) {
62
46
  const b = detail.blockedBy;
63
47
  const reason = b.kind === 'named'
64
48
  ? isStatusDerivedCoarseCode(b.code)
65
- ? `The refusal did not name a more specific check (it carried only the generic code for its HTTP status: ${b.code})`
66
- : `The check that refused it: ${capForDisplay(b.code, 80)}`
49
+ ? msg('resume.refusal.policyBlockReason.coarse', { code: b.code })
50
+ : msg('resume.refusal.policyBlockReason.named', { code: capForDisplay(b.code, 80) })
67
51
  : b.kind === 'absent'
68
- ? 'The refusal did not name a more specific check'
69
- : 'The refusal carried a more specific reason that could not be read';
70
- return [
71
- 'The engine refused to resume this parked work at its admission check (the engine reports that its admission policy changed since the work was first accepted)',
72
- reason,
73
- "This refusal does not say whether anything was consumed before it or whether a retry would pass — check the task's current state before deciding again, and ask whoever operates this deployment if it keeps happening",
74
- ].join(' · ');
52
+ ? msg('resume.refusal.policyBlockReason.absent')
53
+ : msg('resume.refusal.policyBlockReason.unreadable');
54
+ return renderMessage(msg('resume.refusal.policyBlock', { reason }), lang);
75
55
  }
76
56
  export { resumeReopenFromError, resumeReopenContent } from './hitl/suspendedReopen.js';
77
57
  const REQUIRE_EXISTING_BY_STATUS = new Map([
@@ -82,27 +62,29 @@ export function requireExistingSessionRefusalFromError(err) {
82
62
  if (typeof err !== 'object' || err === null)
83
63
  return null;
84
64
  try {
85
- const o = err;
86
- const status = o['status'];
65
+ const status = readThrownSlot(err, 'status', 'data');
87
66
  const byStatus = typeof status === 'number' ? REQUIRE_EXISTING_BY_STATUS.get(status) : undefined;
88
67
  if (byStatus === undefined)
89
68
  return null;
90
- return o['errorCode'] === byStatus.code ? Object.freeze({ code: RESUME_SESSION_NOT_FOUND, form: byStatus.form }) : null;
69
+ return readThrownSlot(err, 'errorCode', 'data') === byStatus.code ? Object.freeze({ code: RESUME_SESSION_NOT_FOUND, form: byStatus.form }) : null;
91
70
  }
92
71
  catch {
93
72
  return null;
94
73
  }
95
74
  }
96
- const REQUIRE_EXISTING_SESSION_SENTENCES = Object.freeze({
97
- session_not_found: 'The engine did not continue this conversation: the conversation it was asked to continue does not exist there (it may have expired, been removed, or never been created on that engine; this client cannot tell which), and this request asked to continue only an existing one, so no new conversation was started · Start a new conversation, or pick another one to continue',
98
- session_id_missing: 'The engine did not continue this conversation: this request asked to continue only an existing conversation but named none, so there was nothing to continue and no new conversation was started · Name the conversation to continue, or start a new one',
75
+ const REQUIRE_EXISTING_SESSION_KEYS = Object.freeze({
76
+ session_not_found: 'resume.refusal.requireExisting.sessionNotFound',
77
+ session_id_missing: 'resume.refusal.requireExisting.sessionIdMissing',
99
78
  });
100
- const REQUIRE_EXISTING_SESSION_GENERIC = 'The engine did not continue this conversation: this request asked to continue only an existing conversation and there was none it could continue, so no new conversation was started · Start a new conversation, or pick another one to continue';
101
- export function requireExistingSessionRefusalContent(detail) {
79
+ const REQUIRE_EXISTING_SESSION_GENERIC = 'resume.refusal.requireExisting.generic';
80
+ export function requireExistingSessionRefusalContent(detail, lang) {
81
+ return renderMessage(msg(requireExistingSessionKey(detail)), lang);
82
+ }
83
+ function requireExistingSessionKey(detail) {
102
84
  try {
103
85
  const form = detail?.form;
104
- return typeof form === 'string' && Object.hasOwn(REQUIRE_EXISTING_SESSION_SENTENCES, form)
105
- ? REQUIRE_EXISTING_SESSION_SENTENCES[form]
86
+ return typeof form === 'string' && Object.hasOwn(REQUIRE_EXISTING_SESSION_KEYS, form)
87
+ ? REQUIRE_EXISTING_SESSION_KEYS[form]
106
88
  : REQUIRE_EXISTING_SESSION_GENERIC;
107
89
  }
108
90
  catch {
@@ -112,8 +94,7 @@ export function requireExistingSessionRefusalContent(detail) {
112
94
  export function resumeContextUnavailableFromError(err) {
113
95
  if (typeof err !== 'object' || err === null)
114
96
  return null;
115
- const e = err;
116
- if (e.errorCode !== RESUME_CONTEXT_UNAVAILABLE)
97
+ if (readThrownSlot(err, 'errorCode', 'data') !== RESUME_CONTEXT_UNAVAILABLE)
117
98
  return null;
118
99
  const sec = readErrorNumber(err, 'staleAfterSec');
119
100
  const staleSec = sec !== undefined && Number.isInteger(sec) && sec >= 1 ? sec : undefined;
@@ -125,17 +106,11 @@ export function resumeContextUnavailableFromError(err) {
125
106
  ...(runId !== undefined ? { runId } : {}),
126
107
  };
127
108
  }
128
- export function resumeContextUnavailableContent(d) {
109
+ export function resumeContextUnavailableContent(d, lang) {
129
110
  const sec = d.staleAfterSec;
130
- const retention = typeof sec === 'number' && Number.isSafeInteger(sec) && sec >= 1 ? ` (this deployment keeps conversations for ${sec} seconds)` : '';
131
- const third = (d.runId !== undefined
132
- ? "The error carries this run's id: use it to recover the run yourself, then decide again; raising the conversation retention time only prevents this from happening again and cannot rescue this one"
133
- : 'The error carries no run id: go back to the run list, find this run and recover it yourself, then decide again; raising the conversation retention time only prevents this from happening again and cannot rescue this one') + retention;
134
- return [
135
- 'This approval has nowhere to be delivered: the conversation that started this run has no usable context to continue it right now',
136
- 'Nothing was decided and your decision was not consumed; this card is still waiting',
137
- third,
138
- ].join(' · ');
111
+ const retention = typeof sec === 'number' && Number.isSafeInteger(sec) && sec >= 1 ? msg('resume.refusal.contextRetention', { sec }) : '';
112
+ const third = msg(d.runId !== undefined ? 'resume.refusal.contextThird.withRun' : 'resume.refusal.contextThird.noRun', { retention });
113
+ return renderMessage(msg('resume.refusal.contextUnavailable', { third }), lang);
139
114
  }
140
115
  function parkedResumeStartupCauseWord(err) {
141
116
  let named;
@@ -150,6 +125,7 @@ function parkedResumeStartupCauseWord(err) {
150
125
  function isResumeStartupCause(v) {
151
126
  return typeof v === 'string' && CORE_RESUME_STARTUP_CAUSES.includes(v);
152
127
  }
128
+ const RESUME_CAUSE_CORE_AHEAD = Object.freeze(['transcript_corrupt']);
153
129
  const _startupCausePin = true;
154
130
  void _startupCausePin;
155
131
  export function parkedResumeStartupFromError(err, decision) {
@@ -176,62 +152,28 @@ export function parkedResumeStartupFromError(err, decision) {
176
152
  denyStaysOpen: true,
177
153
  };
178
154
  }
179
- const PARKED_RESUME_STARTUP_STATE = 'This refusal does not say whether the card is still waiting — re-fetch the pending approvals';
180
- const PARKED_RESUME_STARTUP_SENTENCES = Object.freeze({
181
- resume_rejected: [
182
- 'The engine could not start the parked work to apply this decision (its session may be gone, or the engine rejected the decision itself; this client cannot tell which)',
183
- PARKED_RESUME_STARTUP_STATE,
184
- 'If the card is still there, decide it again from the fresh list',
185
- ].join(' · '),
186
- undetermined: [
187
- 'The engine could not start the parked work to apply this decision',
188
- PARKED_RESUME_STARTUP_STATE,
189
- 'If the card is still there: when the engine rejected the decision itself (for example an answer given to the wrong question), correct it and decide again; when the approved tool is one the agent inherits from the task that started it, approving it again will not work on this server — deny the card, or wait for a server upgrade',
190
- ].join(' · '),
155
+ const PARKED_RESUME_STARTUP_KEYS = Object.freeze({
156
+ resume_rejected: 'resume.refusal.startup.resumeRejected',
157
+ undetermined: 'resume.refusal.startup.undetermined',
191
158
  });
192
- const PARKED_RESUME_STARTUP_CAUSE_SENTENCES = Object.freeze({
193
- environment: [
194
- 'The engine could not start the parked work to apply this decision: the environment it runs in failed to come up (for example the workspace could not be restored); the decision itself was not rejected',
195
- PARKED_RESUME_STARTUP_STATE,
196
- 'If the card is still there, deciding it again replays the same decision',
197
- ].join(' · '),
198
- session_gone: [
199
- 'The engine could not start the parked work to apply this decision: the session of the agent it would resume is gone',
200
- PARKED_RESUME_STARTUP_STATE,
201
- 'If the card is still there, deny it to close it; the work it was waiting on cannot be resumed',
202
- ].join(' · '),
203
- tool_unavailable: [
204
- 'The engine could not start the parked work to apply this decision: the approved tool is not available to the resumed work (it is gone, or a different tool now has its name)',
205
- PARKED_RESUME_STARTUP_STATE,
206
- 'This approval cannot run as decided — if the card is still there, decide it afresh (denying it settles it)',
207
- ].join(' · '),
208
- configuration: [
209
- "The engine could not start the parked work to apply this decision: this deployment's configuration refuses the resumed work",
210
- PARKED_RESUME_STARTUP_STATE,
211
- 'Deciding again under the same configuration fails the same way — the configuration has to change first; denying the card settles it',
212
- ].join(' · '),
213
- decision_rejected: [
214
- 'The engine could not start the parked work to apply this decision: the engine rejected the decision itself (for example an answer given to the wrong question, or an edited input the constraints refuse)',
215
- PARKED_RESUME_STARTUP_STATE,
216
- 'If the card is still there, correct the decision and decide it again from the fresh list',
217
- ].join(' · '),
159
+ const PARKED_RESUME_STARTUP_CAUSE_KEYS = Object.freeze({
160
+ environment: 'resume.refusal.startup.cause.environment',
161
+ session_gone: 'resume.refusal.startup.cause.sessionGone',
162
+ tool_unavailable: 'resume.refusal.startup.cause.toolUnavailable',
163
+ configuration: 'resume.refusal.startup.cause.configuration',
164
+ decision_rejected: 'resume.refusal.startup.cause.decisionRejected',
165
+ transcript_corrupt: 'resume.refusal.startup.cause.transcriptCorrupt',
218
166
  });
219
- export function parkedResumeStartupContent(detail) {
167
+ export function parkedResumeStartupContent(detail, lang) {
220
168
  const word = guardedRead(() => readOwnDataValue(detail, 'startupCause'));
221
169
  if (isResumeStartupCause(word))
222
- return PARKED_RESUME_STARTUP_CAUSE_SENTENCES[word];
223
- return detail.cause === 'resume_rejected' ? PARKED_RESUME_STARTUP_SENTENCES.resume_rejected : PARKED_RESUME_STARTUP_SENTENCES.undetermined;
170
+ return renderMessage(msg(PARKED_RESUME_STARTUP_CAUSE_KEYS[word]), lang);
171
+ return renderMessage(msg(detail.cause === 'resume_rejected' ? PARKED_RESUME_STARTUP_KEYS.resume_rejected : PARKED_RESUME_STARTUP_KEYS.undetermined), lang);
224
172
  }
225
173
  export function checkpointUnsupportedVersionFromError(err) {
226
174
  if (typeof err !== 'object' || err === null)
227
175
  return null;
228
- let code;
229
- try {
230
- code = err.errorCode;
231
- }
232
- catch {
233
- return null;
234
- }
176
+ const code = guardedRead(() => ownDataField(err, 'errorCode'));
235
177
  if (code !== CHECKPOINT_UNSUPPORTED_VERSION || !refusalSaysStillPending(err))
236
178
  return null;
237
179
  const writerVersion = readErrorString(err, 'writerVersion');
@@ -257,10 +199,7 @@ function checkpointUnsupportedHasRun(kind) {
257
199
  return undefined;
258
200
  }
259
201
  }
260
- const CHECKPOINT_UNSUPPORTED_WHAT = 'This server cannot continue this parked work in the form it was stored in';
261
- const CHECKPOINT_UNSUPPORTED_STILL_WAITING = 'Nothing was decided or resumed and the parked work is still waiting, but sending the same request again will not by itself continue it';
262
- const CHECKPOINT_UNSUPPORTED_DRAIN = " — whoever operates this deployment can find such parked work before an upgrade with the server's pre-upgrade drain check";
263
- export function checkpointUnsupportedVersionContent(detail, ctx) {
202
+ export function checkpointUnsupportedVersionContent(detail, ctx, lang) {
264
203
  let writer;
265
204
  let reader;
266
205
  try {
@@ -272,11 +211,7 @@ export function checkpointUnsupportedVersionContent(detail, ctx) {
272
211
  reader = undefined;
273
212
  }
274
213
  if (writerEngineIsNewer(writer, reader)) {
275
- return [
276
- `This parked work was stored by a newer engine version (${String(writer)}) than this engine (${String(reader)})`,
277
- CHECKPOINT_UNSUPPORTED_STILL_WAITING,
278
- `Continue it on an engine at version ${String(writer)} or newer`,
279
- ].join(' · ');
214
+ return renderMessage(msg('resume.refusal.checkpoint.newerEngine', { writer: String(writer), reader: String(reader) }), lang);
280
215
  }
281
216
  let kind;
282
217
  let runId;
@@ -291,19 +226,19 @@ export function checkpointUnsupportedVersionContent(detail, ctx) {
291
226
  const hasRun = checkpointUnsupportedHasRun(kind);
292
227
  let outlet;
293
228
  if (hasRun === true) {
294
- const named = typeof runId === 'string' && runId.length > 0 ? ` (${capForDisplay(runId, 80)})` : '';
295
- outlet = `If it was parked before this server was upgraded, cancel its run${named} first, then submit the work again as a new task`;
229
+ const named = typeof runId === 'string' && runId.length > 0 ? msg('resume.refusal.checkpoint.runNamed', { runId: capForDisplay(runId, 80) }) : '';
230
+ outlet = msg('resume.refusal.checkpoint.outletWithRun', { named });
296
231
  }
297
232
  else if (hasRun === false) {
298
- outlet = 'If it was parked before this server was upgraded, there is no run to cancel: start a new task in that conversation';
233
+ outlet = msg('resume.refusal.checkpoint.outletNoRun');
299
234
  }
300
235
  else {
301
- outlet =
302
- 'If it was parked before this server was upgraded, submit the work again as a new task (this client cannot tell which kind of parked work this is, so both ways out are given): when it still has a run waiting on it (a tool approval, a plan review or a paused resource), cancel that run first; when it was waiting to be woken up, or was a workflow step continuing its host conversation, there is no run to cancel, so start a new task in that conversation';
236
+ outlet = msg('resume.refusal.checkpoint.outletUnknownKind');
303
237
  }
304
- return [CHECKPOINT_UNSUPPORTED_WHAT, CHECKPOINT_UNSUPPORTED_STILL_WAITING, outlet + CHECKPOINT_UNSUPPORTED_DRAIN].join(' · ');
238
+ return renderMessage(msg('resume.refusal.checkpoint.content', { outlet }), lang);
305
239
  }
306
240
  const REFUSED_PARK_FIELD_TOKEN = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
241
+ const REFUSED_PARK_CODE_TOKEN = /^(?=.{1,128}$)[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z0-9_]+)*$/;
307
242
  export function refusedParkFromError(failure) {
308
243
  if (typeof failure !== 'object' || failure === null)
309
244
  return null;
@@ -324,10 +259,22 @@ export function refusedParkFromError(failure) {
324
259
  const stillPending = reading === true ? true : status === 409 && reading === false ? false : undefined;
325
260
  const rawField = code === CHECKPOINT_CONFIG_REFUSED ? readErrorString(failure, 'field') : undefined;
326
261
  const field = rawField !== undefined && REFUSED_PARK_FIELD_TOKEN.test(rawField) ? rawField : undefined;
262
+ let blockedBy;
263
+ try {
264
+ const b = readBlockedBy(failure);
265
+ blockedBy = b.kind === 'named' && REFUSED_PARK_CODE_TOKEN.test(b.code) ? b.code : undefined;
266
+ }
267
+ catch {
268
+ blockedBy = undefined;
269
+ }
270
+ const rawReason = readErrorString(failure, 'reason');
271
+ const reason = rawReason !== undefined && REFUSED_PARK_FIELD_TOKEN.test(rawReason) ? rawReason : undefined;
327
272
  return Object.freeze({
328
273
  code,
329
274
  ...(field !== undefined ? { field } : {}),
330
275
  ...(stillPending !== undefined ? { stillPending } : {}),
276
+ ...(blockedBy !== undefined ? { blockedBy } : {}),
277
+ ...(reason !== undefined ? { reason } : {}),
331
278
  });
332
279
  }
333
280
  function refusedParkShownRunId(runId) {
@@ -336,22 +283,23 @@ function refusedParkShownRunId(runId) {
336
283
  function refusedParkWhy(code, field) {
337
284
  switch (code) {
338
285
  case CHECKPOINT_WALLTIME_AXIS_RETIRED:
339
- return 'its run carries a wall-clock time allowance, which this engine version no longer enforces';
286
+ return msg('resume.refusal.park.whyWalltime');
340
287
  case CHECKPOINT_CONFIG_REFUSED:
341
- return field === 'inheritedGate'
342
- ? 'the permission-mode setting it was parked with can no longer be read'
343
- : 'the engine refuses the task configuration it was parked with';
288
+ if (field === 'deps')
289
+ return msg('resume.refusal.park.whyDeps');
290
+ return msg(field === 'inheritedGate' ? 'resume.refusal.park.whyInheritedGate' : 'resume.refusal.park.whyConfigRefused');
344
291
  default:
345
- return 'it was parked under conditions this engine version does not support (for example, by an earlier engine version)';
292
+ return msg('resume.refusal.park.whyUnsupported');
346
293
  }
347
294
  }
348
- export function refusedParkContent(input) {
295
+ export function refusedParkContent(input, lang) {
349
296
  let what;
350
297
  let lane;
351
298
  let runId;
352
299
  let rawCode;
353
300
  let field;
354
301
  let stillPending;
302
+ let blockedBy;
355
303
  try {
356
304
  what = input.what;
357
305
  lane = input.lane;
@@ -365,35 +313,32 @@ export function refusedParkContent(input) {
365
313
  rawCode = facts.code;
366
314
  field = facts.field;
367
315
  stillPending = facts.stillPending;
316
+ blockedBy = facts.blockedBy;
368
317
  }
369
318
  catch {
370
- rawCode = field = stillPending = undefined;
319
+ rawCode = field = stillPending = blockedBy = undefined;
371
320
  }
372
321
  const code = rawCode === CHECKPOINT_WALLTIME_AXIS_RETIRED || rawCode === CHECKPOINT_CONFIG_REFUSED ? rawCode : CHECKPOINT_UNSUPPORTED_VERSION;
373
- const shownWhat = typeof what === 'string' && what !== '' ? capForDisplay(what, 40) : 'parked step';
322
+ const shownWhat = typeof what === 'string' && what !== '' ? capForDisplay(what, 40) : msg('resume.refusal.park.whatDefault');
374
323
  const why = refusedParkWhy(code, typeof field === 'string' ? field : undefined);
375
324
  const shownRun = refusedParkShownRunId(runId);
376
- const head = `This ${shownWhat} cannot be resumed by this engine version: ${why}. The same refusal comes back every time, so ` +
377
- `answering it again will not help (nothing was decided and nothing was resumed).`;
378
- const configMayReturn = code === CHECKPOINT_CONFIG_REFUSED && field !== 'inheritedGate' ? ' If that configuration is restored, the same answer can go through again.' : '';
325
+ const head = msg('resume.refusal.park.head', { what: shownWhat, why });
326
+ const configMayReturn = code === CHECKPOINT_CONFIG_REFUSED && field !== 'inheritedGate' ? msg(field === 'deps' ? 'resume.refusal.park.depsMayReturn' : 'resume.refusal.park.configMayReturn') : '';
379
327
  if (lane === 'print') {
380
- if (stillPending === false) {
381
- return `${head} The engine ended that run (${code}); submit the work again as a new task.`;
382
- }
328
+ const blocked = typeof blockedBy === 'string' && REFUSED_PARK_CODE_TOKEN.test(blockedBy) ? msg('resume.refusal.park.blockedByTail', { blockedBy }) : '';
329
+ if (stillPending === false)
330
+ return renderMessage(msg('resume.refusal.park.printEnded', { head, code, blocked }), lang);
383
331
  const cancel = `POST /v1/runs/${shownRun ?? '<run id>'}/cancel`;
384
- return `${head}${configMayReturn} The parked run still holds this session (${code}): cancel it (${cancel}), then submit the work again as a new task.`;
385
- }
386
- if (stillPending === false) {
387
- return `${head} The engine ended that parked run, so this conversation is free: send the work again as a new message.`;
332
+ return renderMessage(msg('resume.refusal.park.printHolds', { head, configMayReturn, code, cancel, blocked }), lang);
388
333
  }
389
- return `${head}${configMayReturn} The parked run keeps this conversation busy until it is cancelled.`;
334
+ if (stillPending === false)
335
+ return renderMessage(msg('resume.refusal.park.interactiveEnded', { head }), lang);
336
+ return renderMessage(msg('resume.refusal.park.interactiveBusy', { head, configMayReturn }), lang);
390
337
  }
391
- export function refusedParkBlockedContent(taskId, lane = 'interactive') {
338
+ export function refusedParkBlockedContent(taskId, lane = 'interactive', lang) {
392
339
  const runId = refusedParkShownRunId(taskId);
393
- const head = `sema will not put the card for run ${runId ?? '<unknown>'} back on screen by itself: this engine version refuses to resume it.`;
394
- if (lane === 'print') {
395
- return `${head} Cancel the run (POST /v1/runs/${runId ?? '<run id>'}/cancel) and submit the work again as a new task.`;
396
- }
397
- return (`${head} To free this conversation, send a message to bring the card back and answer it — sema then offers to cancel ` +
398
- `that run, after which you can send the work again as a new message.`);
340
+ const run = runId ?? '<unknown>';
341
+ if (lane === 'print')
342
+ return renderMessage(msg('resume.refusal.park.blockedPrint', { run, cancel: `POST /v1/runs/${runId ?? '<run id>'}/cancel` }), lang);
343
+ return renderMessage(msg('resume.refusal.park.blockedInteractive', { run }), lang);
399
344
  }
@@ -71,12 +71,67 @@ export interface BrainStatusPayload {
71
71
  }
72
72
  export declare const BRAIN_STATUS_PAYLOAD_KEYS: readonly ["phase", "detail", "retryInSec", "retryInMs", "attempt", "maxRetries", "errClass", "retryAtMs", "errorStatus", "elapsedMs", "timeoutMs", "providerCondition", "providerConditionSource"];
73
73
  export declare function mapBrainStatusToRetry(p: BrainStatusPayload, nowMs: number): RetryStatus | null;
74
+ export interface RetryStatusArmLike {
75
+ readonly phase?: string;
76
+ readonly detail?: string;
77
+ readonly retryInSec?: number;
78
+ readonly retryInMs?: number;
79
+ readonly attempt?: number;
80
+ readonly maxRetries?: number;
81
+ readonly errClass?: string;
82
+ readonly retryAtMs?: number;
83
+ readonly errorStatus?: number;
84
+ readonly elapsedMs?: number;
85
+ readonly timeoutMs?: number;
86
+ readonly providerCondition?: string;
87
+ readonly providerConditionSource?: string;
88
+ readonly parentToolCallId?: string;
89
+ }
90
+ export declare function retryStatusFromArm(arm: RetryStatusArmLike | null | undefined, nowMs: number): RetryStatus | null | undefined;
74
91
  export interface RetryStatusNotice {
75
92
  readonly line: string;
76
93
  readonly recourse?: 'switch_model' | 'wait' | 'fix_request';
77
94
  readonly phase: 'retrying' | 'reconnecting' | 'waiting_first_token' | 'gave_up' | 'cleared';
78
95
  }
96
+ export interface RetryStatusParts {
97
+ readonly phase: RetryStatusNotice['phase'];
98
+ readonly model?: string;
99
+ readonly condition?: string;
100
+ readonly resendNote?: string;
101
+ readonly httpStatus?: number;
102
+ readonly source?: string;
103
+ readonly attempt?: number;
104
+ readonly maxAttempts?: number;
105
+ readonly elapsedMs?: number;
106
+ readonly timeoutMs?: number;
107
+ readonly retryAtMs?: number;
108
+ readonly detail?: string;
109
+ readonly recourse?: RetryStatusNotice['recourse'];
110
+ }
111
+ export declare function retryStatusParts(status: RetryStatus | null, ctx?: {
112
+ readonly modelName?: string;
113
+ }): RetryStatusParts;
79
114
  export declare function retryStatusNotice(status: RetryStatus | null, ctx?: {
80
115
  readonly modelName?: string;
81
116
  }): RetryStatusNotice;
117
+ export interface ApiErrorRowLike {
118
+ readonly _sema_api_error_status?: number;
119
+ readonly _sema_provider_condition?: string;
120
+ readonly _sema_api_error_code?: string;
121
+ }
122
+ export interface ApiErrorRowFacts {
123
+ readonly status?: number;
124
+ readonly providerCondition?: string;
125
+ readonly errorCode?: string;
126
+ }
127
+ export interface ApiErrorNotice {
128
+ readonly line: string;
129
+ readonly recourse?: NonNullable<RetryStatusNotice['recourse']> | 'check_credentials';
130
+ }
131
+ export interface ApiErrorNoticeCtx {
132
+ readonly modelName?: string;
133
+ readonly providerText?: string;
134
+ }
135
+ export declare function apiErrorFactsOfRow(row: ApiErrorRowLike | null | undefined): ApiErrorRowFacts;
136
+ export declare function apiErrorNotice(facts: ApiErrorRowFacts | null | undefined, ctx?: ApiErrorNoticeCtx): ApiErrorNotice | undefined;
82
137
  export {};