@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
@@ -0,0 +1,692 @@
1
+ import { SETTINGS_CLASSIFY_HOOKS_CONFIG } from './generated/settingsSchemaFns.js';
2
+ import { hooksWirePlanShapeOf } from './pluginHooksWire.js';
3
+ import { resolveWebSearchVerdict, webSearchVerdictMessage } from './webSearchWireCaps.js';
4
+ import { fileHistoryTightenVerdict, fileHistoryUnjudgedRefusal } from './fileHistoryCaptureCapability.js';
5
+ import { msg, renderMessage } from './i18n/translate.js';
6
+ export const HOST_SUPPLIED_KEYS = Object.freeze(['settings.hooks', 'settings.resolved', 'settings.webSearch', 'settings.outputStyle', 'memory', 'fileHistory']);
7
+ export const HOST_SETTING_CAUSES = Object.freeze([
8
+ 'carried',
9
+ 'entries_dropped',
10
+ 'source_rejected',
11
+ 'projection_failed',
12
+ 'source_unreadable',
13
+ 'empty',
14
+ 'no_source',
15
+ 'host_port_missing',
16
+ 'value_malformed',
17
+ ]);
18
+ export const HOST_SETTING_DISPOSITIONS = Object.freeze(['carry', 'carry_partial', 'withhold_notice', 'refuse_turn', 'unwired', 'nothing_to_carry']);
19
+ const HOST_SETTING_NOTICE_TEXT = {
20
+ 'HS-UNWIRED': (what) => `This app has not connected ${what} from your settings, so it is not sent with your requests.`,
21
+ 'HS-MANAGED-REJECTED': () => 'Managed settings: the hooks your administrator configured could not be loaded, so requests are not sent until the managed settings are fixed.',
22
+ 'HS-PROJECTION': () => 'The hooks for this request could not be checked before sending, so the request is not sent. Reload your settings and try again.',
23
+ 'HS-SOURCE-UNREADABLE': (what) => `This app could not read ${what} from your settings, so the request is not sent. Reload your settings and try again.`,
24
+ 'HS-WEBSEARCH-MALFORMED': (sentence) => sentence,
25
+ 'HS-SWITCH-MALFORMED': () => renderMessage(msg('session.hostSettings.memorySwitchMalformed')),
26
+ 'HS-FILEHISTORY-UNJUDGED': (sentence) => sentence,
27
+ };
28
+ const KEY_NOUN = {
29
+ 'settings.hooks': 'the hooks',
30
+ 'settings.resolved': 'the permission rules',
31
+ 'settings.webSearch': 'the web search setup',
32
+ 'settings.outputStyle': 'the output style',
33
+ memory: 'auto-memory',
34
+ fileHistory: 'file checkpoints',
35
+ };
36
+ const BASE_DISPOSITION = {
37
+ carried: 'carry',
38
+ entries_dropped: 'carry_partial',
39
+ source_rejected: 'withhold_notice',
40
+ projection_failed: 'refuse_turn',
41
+ source_unreadable: 'refuse_turn',
42
+ empty: 'nothing_to_carry',
43
+ no_source: 'nothing_to_carry',
44
+ host_port_missing: 'unwired',
45
+ value_malformed: 'refuse_turn',
46
+ };
47
+ const freeze = (o) => Object.freeze(o);
48
+ const mint = (o) => o;
49
+ const notice = (id, plane, what = '') => freeze({ id, plane, text: HOST_SETTING_NOTICE_TEXT[id](what) });
50
+ function readSource(sources, key) {
51
+ try {
52
+ if (typeof sources !== 'object' || sources === null || !Object.hasOwn(sources, key))
53
+ return { kind: 'missing' };
54
+ const v = sources[key];
55
+ return v === undefined ? { kind: 'missing' } : { kind: 'value', value: v };
56
+ }
57
+ catch {
58
+ return { kind: 'threw' };
59
+ }
60
+ }
61
+ function unwrap(v, field) {
62
+ if (v === 'none')
63
+ return { kind: 'none' };
64
+ try {
65
+ if (typeof v !== 'object' || v === null || Array.isArray(v) || !Object.hasOwn(v, field))
66
+ return { kind: 'bad' };
67
+ return { kind: 'value', value: v[field] };
68
+ }
69
+ catch {
70
+ return { kind: 'bad' };
71
+ }
72
+ }
73
+ const isRecordShape = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
74
+ function hooksPassJudge(wire) {
75
+ try {
76
+ return isRecordShape(wire) && SETTINGS_CLASSIFY_HOOKS_CONFIG({ hooks: wire }).outcome === 'loaded';
77
+ }
78
+ catch {
79
+ return false;
80
+ }
81
+ }
82
+ class HostSourceShapeError extends TypeError {
83
+ code = 'host_source_shape';
84
+ }
85
+ function badSource(key, want) {
86
+ return new HostSourceShapeError(`hostTurnSettings: sources.${key.replace(/^settings\./, '')} must be 'none' or ${want} — got something else (the value is not echoed).`);
87
+ }
88
+ const missingArm = (key) => ({
89
+ row: freeze({ key, cause: 'host_port_missing', disposition: BASE_DISPOSITION.host_port_missing }),
90
+ notices: [notice('HS-UNWIRED', 'session', KEY_NOUN[key])],
91
+ });
92
+ const unreadableArm = (key) => ({
93
+ row: freeze({ key, cause: 'source_unreadable', disposition: BASE_DISPOSITION.source_unreadable }),
94
+ notices: [notice('HS-SOURCE-UNREADABLE', 'turn', KEY_NOUN[key])],
95
+ });
96
+ const noSourceArm = (key) => ({ row: freeze({ key, cause: 'no_source', disposition: BASE_DISPOSITION.no_source }), notices: [] });
97
+ const carriedArm = (key, value) => ({ row: freeze({ key, cause: 'carried', disposition: BASE_DISPOSITION.carried }), notices: [], carried: value });
98
+ function hooksArm(src) {
99
+ const key = 'settings.hooks';
100
+ if (src.kind === 'missing')
101
+ return missingArm(key);
102
+ if (src.kind === 'threw')
103
+ return unreadableArm(key);
104
+ const u = unwrap(src.value, 'plan');
105
+ if (u.kind === 'none')
106
+ return noSourceArm(key);
107
+ if (u.kind === 'bad' || hooksWirePlanShapeOf(u.value) !== 'plan')
108
+ throw badSource(key, '{ plan } with the plan returned by hooksWirePlan() for this turn');
109
+ const plan = u.value;
110
+ let wire;
111
+ let salvageRows;
112
+ let closedBy;
113
+ try {
114
+ wire = plan.wire;
115
+ salvageRows = plan.settingsSalvage;
116
+ closedBy = plan.closedBy;
117
+ }
118
+ catch {
119
+ throw badSource(key, '{ plan } with a readable plan');
120
+ }
121
+ const rows = Array.isArray(salvageRows) ? salvageRows : [];
122
+ const layersOf = (outcome) => rows.filter((r) => isRecordShape(r) && r.outcome === outcome && typeof r.source === 'string').map((r) => r.source);
123
+ const managedRejected = layersOf('rejected').includes('policySettings');
124
+ if (managedRejected || layersOf('loaded-partial').includes('policySettings')) {
125
+ return {
126
+ row: freeze({ key, cause: managedRejected ? 'source_rejected' : 'entries_dropped', disposition: 'refuse_turn', layers: freeze(['policySettings']) }),
127
+ notices: [notice('HS-MANAGED-REJECTED', 'turn')],
128
+ plan,
129
+ };
130
+ }
131
+ if (closedBy === 'governance_unreadable')
132
+ return { ...unreadableArm(key), plan };
133
+ if (wire !== undefined && !hooksPassJudge(wire)) {
134
+ return { row: freeze({ key, cause: 'projection_failed', disposition: BASE_DISPOSITION.projection_failed }), notices: [notice('HS-PROJECTION', 'turn')], plan };
135
+ }
136
+ const carried = wire === undefined ? undefined : wire;
137
+ const rejected = layersOf('rejected');
138
+ const partial = layersOf('loaded-partial');
139
+ if (rejected.length > 0 || partial.length > 0) {
140
+ const cause = rejected.length > 0 ? 'source_rejected' : 'entries_dropped';
141
+ const layers = freeze([...new Set([...rejected, ...partial])]);
142
+ return { row: freeze({ key, cause, disposition: carried !== undefined ? 'carry_partial' : 'withhold_notice', layers }), notices: [], carried, plan };
143
+ }
144
+ if (carried === undefined)
145
+ return { row: freeze({ key, cause: 'empty', disposition: BASE_DISPOSITION.empty }), notices: [], plan };
146
+ return { ...carriedArm(key, carried), plan };
147
+ }
148
+ function webSearchArm(src) {
149
+ const key = 'settings.webSearch';
150
+ if (src.kind === 'missing')
151
+ return missingArm(key);
152
+ if (src.kind === 'threw')
153
+ return unreadableArm(key);
154
+ const v = src.value;
155
+ if (v === 'none')
156
+ return noSourceArm(key);
157
+ let section;
158
+ let env;
159
+ let apiKeyFor;
160
+ try {
161
+ if (!isRecordShape(v) || !Object.hasOwn(v, 'env') || Object.hasOwn(v, 'settings'))
162
+ throw badSource(key, "{ section, env } with the raw webSearch section of the settings and the environment (since 0.100.0 the entry judges it; do not pass the judged settings)");
163
+ section = v.section;
164
+ env = v.env;
165
+ apiKeyFor = v.apiKeyFor;
166
+ }
167
+ catch (e) {
168
+ if (e instanceof HostSourceShapeError)
169
+ throw e;
170
+ return unreadableArm(key);
171
+ }
172
+ if (!isRecordShape(env))
173
+ throw badSource(key, '{ section, env } where env is the environment record (pass {} where there is none)');
174
+ if (apiKeyFor !== undefined && typeof apiKeyFor !== 'function')
175
+ throw badSource(key, '{ section, env, apiKeyFor? } where apiKeyFor is a function');
176
+ const verdict = resolveWebSearchVerdict(env, section, apiKeyFor);
177
+ if (verdict.kind === 'absent')
178
+ return { row: freeze({ key, cause: 'empty', disposition: BASE_DISPOSITION.empty }), notices: [] };
179
+ if (verdict.kind === 'honored')
180
+ return carriedArm(key, freeze({ ...verdict.settings }));
181
+ return {
182
+ row: freeze({ key, cause: 'value_malformed', disposition: BASE_DISPOSITION.value_malformed }),
183
+ notices: [notice('HS-WEBSEARCH-MALFORMED', 'turn', webSearchVerdictMessage(verdict, 'submit') ?? '')],
184
+ };
185
+ }
186
+ function memoryArm(src, judge) {
187
+ const key = 'memory';
188
+ if (src.kind === 'missing')
189
+ return missingArm(key);
190
+ if (src.kind === 'threw')
191
+ return unreadableArm(key);
192
+ const v = src.value;
193
+ if (v === 'none')
194
+ return noSourceArm(key);
195
+ let flag;
196
+ let settingsMemory;
197
+ try {
198
+ if (!isRecordShape(v))
199
+ throw badSource(key, '{ flag?, settingsMemory? } with the --memory flag word and the memory section of the settings');
200
+ flag = v.flag;
201
+ settingsMemory = v.settingsMemory;
202
+ }
203
+ catch (e) {
204
+ if (e instanceof HostSourceShapeError)
205
+ throw e;
206
+ return unreadableArm(key);
207
+ }
208
+ if (judge({ flag }))
209
+ return carriedArm(key, 'off');
210
+ let bySettings;
211
+ try {
212
+ bySettings = judge({ settingsMemory });
213
+ }
214
+ catch {
215
+ return { row: freeze({ key, cause: 'value_malformed', disposition: 'withhold_notice' }), notices: [notice('HS-SWITCH-MALFORMED', 'session')] };
216
+ }
217
+ if (bySettings)
218
+ return carriedArm(key, 'off');
219
+ return { row: freeze({ key, cause: 'empty', disposition: BASE_DISPOSITION.empty }), notices: [] };
220
+ }
221
+ const UNOBSERVED_READING = Object.freeze({ kind: 'unobserved' });
222
+ function fileHistoryReadingSnapshot(reading) {
223
+ try {
224
+ if (typeof reading !== 'object' || reading === null)
225
+ return UNOBSERVED_READING;
226
+ const kind = reading.kind;
227
+ if (kind === 'present') {
228
+ const word = reading.word;
229
+ return Object.freeze({ kind, word });
230
+ }
231
+ return Object.freeze({ kind });
232
+ }
233
+ catch {
234
+ return UNOBSERVED_READING;
235
+ }
236
+ }
237
+ function fileHistoryArm(src) {
238
+ const key = 'fileHistory';
239
+ if (src.kind === 'missing')
240
+ return missingArm(key);
241
+ if (src.kind === 'threw')
242
+ return unreadableArm(key);
243
+ const v = src.value;
244
+ if (v === 'none')
245
+ return noSourceArm(key);
246
+ let reading;
247
+ let captureOff;
248
+ try {
249
+ if (!isRecordShape(v) || !Object.hasOwn(v, 'captureOff'))
250
+ throw badSource(key, '{ reading, captureOff } with the engine capability reading and the switch');
251
+ reading = v.reading;
252
+ captureOff = v.captureOff;
253
+ }
254
+ catch (e) {
255
+ if (e instanceof HostSourceShapeError)
256
+ throw e;
257
+ return unreadableArm(key);
258
+ }
259
+ if (typeof captureOff !== 'boolean')
260
+ throw badSource(key, '{ reading, captureOff } where captureOff is a boolean');
261
+ const snap = fileHistoryReadingSnapshot(reading);
262
+ const verdict = fileHistoryTightenVerdict(snap, captureOff);
263
+ if (verdict === 'declare')
264
+ return carriedArm(key, 'disabled');
265
+ if (verdict === 'unjudged') {
266
+ return {
267
+ row: freeze({ key, cause: 'value_malformed', disposition: 'refuse_turn' }),
268
+ notices: [notice('HS-FILEHISTORY-UNJUDGED', 'turn', fileHistoryUnjudgedRefusal(snap, true) ?? fileHistoryUnjudgedRefusal(UNOBSERVED_READING, true) ?? '')],
269
+ };
270
+ }
271
+ return { row: freeze({ key, cause: 'empty', disposition: BASE_DISPOSITION.empty }), notices: [] };
272
+ }
273
+ function passArm(key, field, src, want) {
274
+ if (src.kind === 'missing')
275
+ return missingArm(key);
276
+ if (src.kind === 'threw')
277
+ return unreadableArm(key);
278
+ const u = unwrap(src.value, field);
279
+ if (u.kind === 'none')
280
+ return noSourceArm(key);
281
+ if (u.kind === 'bad')
282
+ throw badSource(key, want);
283
+ if (u.value === undefined || u.value === null)
284
+ return { row: freeze({ key, cause: 'empty', disposition: BASE_DISPOSITION.empty }), notices: [] };
285
+ return carriedArm(key, u.value);
286
+ }
287
+ const RESOLVED_DEFERRED_ERROR = Symbol('hostTurnSettings.resolvedDeferredError');
288
+ export function rethrowHostResolvedDeferred(product) {
289
+ const rec = product;
290
+ if (!Object.hasOwn(rec, RESOLVED_DEFERRED_ERROR))
291
+ return;
292
+ const box = rec[RESOLVED_DEFERRED_ERROR];
293
+ if (box !== undefined)
294
+ throw box.error;
295
+ }
296
+ export function buildHostTurnSettings(input, judges) {
297
+ const materialize = judges.materialize;
298
+ let sources;
299
+ let sourcesThrew = false;
300
+ try {
301
+ sources = input?.sources;
302
+ }
303
+ catch {
304
+ sourcesThrew = true;
305
+ }
306
+ const read = (key) => (sourcesThrew ? { kind: 'threw' } : readSource(sources, key));
307
+ const resolved = passArm('settings.resolved', 'snapshot', read('resolved'), '{ snapshot } with the resolver snapshot');
308
+ let resolvedCarried = resolved.carried;
309
+ let resolvedError;
310
+ if (resolvedCarried !== undefined) {
311
+ try {
312
+ resolvedCarried = materialize(resolvedCarried);
313
+ }
314
+ catch (error) {
315
+ resolvedError = freeze({ error });
316
+ }
317
+ }
318
+ const hooks = hooksArm(read('hooks'));
319
+ const webSearch = webSearchArm(read('webSearch'));
320
+ const outputStyle = passArm('settings.outputStyle', 'name', read('outputStyle'), '{ name } with the output style name');
321
+ const memory = memoryArm(read('memory'), judges.memoryOffDeclared);
322
+ const fileHistory = fileHistoryArm(read('fileHistory'));
323
+ const arms = [hooks, resolved, webSearch, outputStyle, memory, fileHistory];
324
+ const rows = freeze(arms.map((a) => a.row));
325
+ const notices = freeze(arms.flatMap((a) => a.notices));
326
+ const refusal = arms.find((a) => a.row.disposition === 'refuse_turn');
327
+ const verdict = refusal === undefined ? freeze({ kind: 'send' }) : freeze({ kind: 'refuse', notice: refusal.notices[0] ?? notice('HS-PROJECTION', 'turn') });
328
+ const carried = freeze({
329
+ ...(hooks.carried !== undefined ? { hooks: hooks.carried } : {}),
330
+ ...(resolvedCarried !== undefined ? { resolved: resolvedCarried } : {}),
331
+ ...(webSearch.carried !== undefined ? { webSearch: webSearch.carried } : {}),
332
+ ...(outputStyle.carried !== undefined ? { outputStyle: outputStyle.carried } : {}),
333
+ ...(memory.carried !== undefined ? { memory: 'off' } : {}),
334
+ ...(fileHistory.carried !== undefined ? { fileHistory: 'disabled' } : {}),
335
+ });
336
+ const product = { verdict, rows, notices, hooks: hooks.plan, carried };
337
+ if (resolvedError !== undefined)
338
+ Object.defineProperty(product, RESOLVED_DEFERRED_ERROR, { value: resolvedError, enumerable: false });
339
+ return mint(freeze(product));
340
+ }
341
+ export function hostSettingsSelfCheck(product) {
342
+ try {
343
+ const rows = product.rows;
344
+ if (!Array.isArray(rows))
345
+ return HOST_SUPPLIED_KEYS;
346
+ const seen = new Set();
347
+ const out = [];
348
+ for (const r of rows) {
349
+ if (!isRecordShape(r) || typeof r.key !== 'string')
350
+ continue;
351
+ seen.add(r.key);
352
+ if (r.disposition === 'unwired' && HOST_SUPPLIED_KEYS.includes(r.key))
353
+ out.push(r.key);
354
+ }
355
+ for (const k of HOST_SUPPLIED_KEYS)
356
+ if (!seen.has(k) && !out.includes(k))
357
+ out.push(k);
358
+ return freeze(out);
359
+ }
360
+ catch {
361
+ return HOST_SUPPLIED_KEYS;
362
+ }
363
+ }
364
+ export const hostProjectionNotice = () => notice('HS-PROJECTION', 'turn');
365
+ export class HostSettingsRefused extends Error {
366
+ notice;
367
+ constructor(n) {
368
+ super(n.text);
369
+ this.name = 'HostSettingsRefused';
370
+ this.notice = n;
371
+ }
372
+ }
373
+ const CARRYING = new Set(['carry', 'carry_partial']);
374
+ function shapeOf(v) {
375
+ if (v === undefined || v === null)
376
+ return UNWIRED_HOST_TURN_SETTINGS;
377
+ try {
378
+ if (!isRecordShape(v))
379
+ return undefined;
380
+ for (const k of ['verdict', 'rows', 'notices', 'hooks', 'carried'])
381
+ if (!Object.hasOwn(v, k))
382
+ return undefined;
383
+ const rows = v.rows;
384
+ if (!Array.isArray(rows) || rows.length !== HOST_SUPPLIED_KEYS.length)
385
+ return undefined;
386
+ const keys = rows.map((r) => (isRecordShape(r) ? r.key : undefined));
387
+ if (!HOST_SUPPLIED_KEYS.every((k, i) => keys[i] === k))
388
+ return undefined;
389
+ if (!isRecordShape(v.carried) || !isRecordShape(v.verdict))
390
+ return undefined;
391
+ const product = v;
392
+ return product;
393
+ }
394
+ catch {
395
+ return undefined;
396
+ }
397
+ }
398
+ export function hostTurnSettingsOf(v, depth = 'full') {
399
+ const shaped = shapeOf(v);
400
+ if (depth === 'shape' || shaped === undefined || shaped === UNWIRED_HOST_TURN_SETTINGS)
401
+ return shaped;
402
+ try {
403
+ const view = shaped;
404
+ const p = view;
405
+ const rows = p.rows;
406
+ const carried = p.carried;
407
+ const subs = HOST_SUPPLIED_KEYS.map(carriedKeyOf);
408
+ if (Object.keys(carried).some((k) => !subs.includes(k)))
409
+ return undefined;
410
+ if (carried.memory !== undefined && carried.memory !== 'off')
411
+ return undefined;
412
+ if (carried.fileHistory !== undefined && carried.fileHistory !== 'disabled')
413
+ return undefined;
414
+ let refuses = false;
415
+ for (const [i, r] of rows.entries()) {
416
+ const disposition = r.disposition;
417
+ if (!HOST_SETTING_DISPOSITIONS.includes(disposition))
418
+ return undefined;
419
+ if (disposition === 'refuse_turn')
420
+ refuses = true;
421
+ const sub = subs[i] ?? '';
422
+ const has = Object.hasOwn(carried, sub) && carried[sub] !== undefined;
423
+ if (has !== CARRYING.has(disposition))
424
+ return undefined;
425
+ }
426
+ const verdict = p.verdict;
427
+ if (verdict.kind !== (refuses ? 'refuse' : 'send'))
428
+ return undefined;
429
+ if (refuses && !(isRecordShape(verdict.notice) && typeof verdict.notice.text === 'string'))
430
+ return undefined;
431
+ if (Object.hasOwn(carried, 'hooks') && carried.hooks !== undefined && !hooksPassJudge(carried.hooks))
432
+ return undefined;
433
+ return shaped;
434
+ }
435
+ catch {
436
+ return undefined;
437
+ }
438
+ }
439
+ function wireFormOf(v) {
440
+ const text = JSON.stringify(v);
441
+ return text === undefined ? undefined : JSON.parse(text);
442
+ }
443
+ function sameJson(a, b) {
444
+ if (a === b)
445
+ return true;
446
+ if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null)
447
+ return false;
448
+ if (Array.isArray(a) !== Array.isArray(b))
449
+ return false;
450
+ if (Array.isArray(a) && Array.isArray(b))
451
+ return a.length === b.length && a.every((x, i) => sameJson(x, b[i]));
452
+ const ra = a;
453
+ const rb = b;
454
+ const ka = Object.keys(ra);
455
+ if (ka.length !== Object.keys(rb).length)
456
+ return false;
457
+ return ka.every((k) => Object.hasOwn(rb, k) && sameJson(ra[k], rb[k]));
458
+ }
459
+ function groupHead(g) {
460
+ if (!isRecordShape(g))
461
+ return undefined;
462
+ const head = {};
463
+ for (const k of Object.keys(g))
464
+ if (k !== 'hooks')
465
+ head[k] = g[k];
466
+ return head;
467
+ }
468
+ export function intersectHostHooks(sent, now) {
469
+ try {
470
+ return intersectHostHooksUnguarded(sent, now);
471
+ }
472
+ catch {
473
+ return { hooks: undefined, dropped: 0, judged: false };
474
+ }
475
+ }
476
+ function intersectHostHooksUnguarded(sentIn, nowIn) {
477
+ const sent = wireFormOf(sentIn);
478
+ const now = nowIn === undefined ? undefined : wireFormOf(nowIn);
479
+ const entriesOf = (cfg) => {
480
+ if (!isRecordShape(cfg))
481
+ return 0;
482
+ let n = 0;
483
+ for (const ev of Object.keys(cfg)) {
484
+ const groups = cfg[ev];
485
+ if (!Array.isArray(groups))
486
+ continue;
487
+ for (const g of groups)
488
+ if (isRecordShape(g) && Array.isArray(g.hooks))
489
+ n += g.hooks.length;
490
+ }
491
+ return n;
492
+ };
493
+ const total = entriesOf(sent);
494
+ if (!isRecordShape(sent))
495
+ return { hooks: undefined, dropped: 0, judged: true };
496
+ if (!isRecordShape(now))
497
+ return { hooks: undefined, dropped: total, judged: true };
498
+ const out = {};
499
+ let kept = 0;
500
+ for (const ev of Object.keys(sent)) {
501
+ const groups = sent[ev];
502
+ const nowGroups = now[ev];
503
+ if (!Array.isArray(groups) || !Array.isArray(nowGroups))
504
+ continue;
505
+ const pool = nowGroups.map((g) => ({ head: groupHead(g), left: isRecordShape(g) && Array.isArray(g.hooks) ? [...g.hooks] : [] }));
506
+ const evOut = [];
507
+ for (const g of groups) {
508
+ const head = groupHead(g);
509
+ if (head === undefined || !isRecordShape(g) || !Array.isArray(g.hooks))
510
+ continue;
511
+ const keep = [];
512
+ for (const entry of g.hooks) {
513
+ for (const slot of pool) {
514
+ if (slot.head === undefined || !sameJson(slot.head, head))
515
+ continue;
516
+ const at = slot.left.findIndex((x) => sameJson(x, entry));
517
+ if (at < 0)
518
+ continue;
519
+ slot.left.splice(at, 1);
520
+ keep.push(entry);
521
+ break;
522
+ }
523
+ }
524
+ if (keep.length > 0)
525
+ evOut.push({ ...head, hooks: keep });
526
+ kept += keep.length;
527
+ }
528
+ if (evOut.length > 0)
529
+ out[ev] = evOut;
530
+ }
531
+ const hooks = Object.keys(out).length > 0 ? out : undefined;
532
+ return { hooks, dropped: total - kept, judged: hooks === undefined || hooksPassJudge(hooks) };
533
+ }
534
+ function ownDataOf(o, k) {
535
+ try {
536
+ if (typeof o !== 'object' || o === null)
537
+ return { ok: false };
538
+ const d = Object.getOwnPropertyDescriptor(o, k);
539
+ if (d === undefined)
540
+ return { ok: true, value: undefined };
541
+ if (!('value' in d))
542
+ return { ok: false };
543
+ return { ok: true, value: d.value };
544
+ }
545
+ catch {
546
+ return { ok: false };
547
+ }
548
+ }
549
+ function noticeCopyOf(n) {
550
+ const id = ownDataOf(n, 'id');
551
+ const plane = ownDataOf(n, 'plane');
552
+ const text = ownDataOf(n, 'text');
553
+ if (!id.ok || !plane.ok || !text.ok || typeof id.value !== 'string' || typeof plane.value !== 'string' || typeof text.value !== 'string')
554
+ return undefined;
555
+ return freeze({ id: id.value, plane: plane.value, text: text.value });
556
+ }
557
+ function turnNoticesOf(product) {
558
+ try {
559
+ return turnNoticesUnguarded(product);
560
+ }
561
+ catch {
562
+ return undefined;
563
+ }
564
+ }
565
+ function turnNoticesUnguarded(product) {
566
+ const ns = ownDataOf(product, 'notices');
567
+ if (!ns.ok || !Array.isArray(ns.value))
568
+ return undefined;
569
+ const len = ownDataOf(ns.value, 'length');
570
+ if (!len.ok || typeof len.value !== 'number')
571
+ return undefined;
572
+ const out = [];
573
+ for (let i = 0; i < len.value; i++) {
574
+ const e = ownDataOf(ns.value, String(i));
575
+ const copy = e.ok ? noticeCopyOf(e.value) : undefined;
576
+ if (copy === undefined)
577
+ return undefined;
578
+ if (copy.plane === 'turn')
579
+ out.push(copy);
580
+ }
581
+ return freeze(out);
582
+ }
583
+ function deepFreeze(v) {
584
+ if (typeof v === 'object' && v !== null) {
585
+ for (const x of Object.values(v))
586
+ deepFreeze(x);
587
+ Object.freeze(v);
588
+ }
589
+ return v;
590
+ }
591
+ export function hostIntakeSnapshotOf(product, onResolved) {
592
+ try {
593
+ return intakeSnapshotUnguarded(product, onResolved);
594
+ }
595
+ catch {
596
+ return undefined;
597
+ }
598
+ }
599
+ function intakeSnapshotUnguarded(product, onResolved) {
600
+ if (product === UNWIRED_HOST_TURN_SETTINGS) {
601
+ return freeze({
602
+ carried: freeze({}),
603
+ refuses: false,
604
+ dispositions: freeze(Object.fromEntries(HOST_SUPPLIED_KEYS.map((k) => [k, 'unwired']))),
605
+ refusingKeys: freeze([]),
606
+ turnNotices: freeze([]),
607
+ notice: undefined,
608
+ });
609
+ }
610
+ const c = ownDataOf(product, 'carried');
611
+ if (!c.ok || !isRecordShape(c.value))
612
+ return undefined;
613
+ const carriedIn = c.value;
614
+ const subs = HOST_SUPPLIED_KEYS.map(carriedKeyOf);
615
+ let keys;
616
+ try {
617
+ keys = Reflect.ownKeys(carriedIn);
618
+ }
619
+ catch {
620
+ return undefined;
621
+ }
622
+ if (keys.some((k) => typeof k !== 'string' || !subs.includes(k)))
623
+ return undefined;
624
+ const values = {};
625
+ const resolvedR = ownDataOf(carriedIn, 'resolved');
626
+ if (!resolvedR.ok)
627
+ return undefined;
628
+ onResolved?.(resolvedR.value);
629
+ if (resolvedR.value !== undefined)
630
+ values.resolved = resolvedR.value;
631
+ for (const sub of subs.filter((x) => x !== 'resolved')) {
632
+ const r = ownDataOf(carriedIn, sub);
633
+ if (!r.ok)
634
+ return undefined;
635
+ const copy = deepFreeze(wireFormOf(r.value));
636
+ if (copy !== undefined)
637
+ values[sub] = copy;
638
+ }
639
+ const rowsR = ownDataOf(product, 'rows');
640
+ if (!rowsR.ok || !Array.isArray(rowsR.value) || rowsR.value.length !== HOST_SUPPLIED_KEYS.length)
641
+ return undefined;
642
+ let refuses = false;
643
+ const refusingKeys = [];
644
+ const dispositions = {};
645
+ for (const [i, key] of HOST_SUPPLIED_KEYS.entries()) {
646
+ const rowR = ownDataOf(rowsR.value, String(i));
647
+ if (!rowR.ok)
648
+ return undefined;
649
+ const k = ownDataOf(rowR.value, 'key');
650
+ const d = ownDataOf(rowR.value, 'disposition');
651
+ if (!k.ok || !d.ok || k.value !== key || !HOST_SETTING_DISPOSITIONS.includes(d.value))
652
+ return undefined;
653
+ if (d.value === 'refuse_turn') {
654
+ refuses = true;
655
+ refusingKeys.push(key);
656
+ }
657
+ dispositions[key] = d.value;
658
+ if ((values[carriedKeyOf(key)] !== undefined) !== CARRYING.has(d.value))
659
+ return undefined;
660
+ }
661
+ if (values.memory !== undefined && values.memory !== 'off')
662
+ return undefined;
663
+ if (values.fileHistory !== undefined && values.fileHistory !== 'disabled')
664
+ return undefined;
665
+ if (values.hooks !== undefined && !hooksPassJudge(values.hooks))
666
+ return undefined;
667
+ const v = ownDataOf(product, 'verdict');
668
+ if (!v.ok)
669
+ return undefined;
670
+ const kind = ownDataOf(v.value, 'kind');
671
+ if (!kind.ok || kind.value !== (refuses ? 'refuse' : 'send'))
672
+ return undefined;
673
+ const noticeR = refuses ? ownDataOf(v.value, 'notice') : undefined;
674
+ const notice = noticeR === undefined ? undefined : ((noticeR.ok ? noticeCopyOf(noticeR.value) : undefined) ?? hostProjectionNotice());
675
+ return freeze({
676
+ carried: freeze(values),
677
+ refuses,
678
+ dispositions: freeze(dispositions),
679
+ refusingKeys: freeze(refusingKeys),
680
+ turnNotices: turnNoticesOf(product),
681
+ notice,
682
+ });
683
+ }
684
+ export const UNWIRED_HOST_TURN_SETTINGS = buildHostTurnSettings({ sources: {} }, {
685
+ materialize: (snapshot) => snapshot,
686
+ memoryOffDeclared: () => false,
687
+ });
688
+ function carriedKeyOf(k) {
689
+ return k.startsWith('settings.') ? k.slice('settings.'.length) : k;
690
+ }
691
+ const _armsPin = [true, true, true, true];
692
+ void _armsPin;