@sema-agent/client-core 0.101.0 → 0.102.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 (49) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +12 -7
  3. package/dist/adapt/toolCards.d.ts +2 -1
  4. package/dist/adapt/toolCards.js +20 -6
  5. package/dist/adapt.d.ts +1 -1
  6. package/dist/adapt.js +1 -1
  7. package/dist/adapter/downstream/eventToSdkMessage.js +6 -68
  8. package/dist/adapter/downstream/wiringManifestView.d.ts +1 -0
  9. package/dist/adapter/downstream/wiringManifestView.js +138 -0
  10. package/dist/compensations.js +1 -1
  11. package/dist/displayUntrusted.d.ts +8 -4
  12. package/dist/displayUntrusted.js +769 -96
  13. package/dist/engineRowRef.js +1 -0
  14. package/dist/fleet/fleetProjection.js +1 -1
  15. package/dist/i18n/messages.en.d.ts +38 -0
  16. package/dist/i18n/messages.en.js +38 -0
  17. package/dist/i18n/messages.zh.js +40 -0
  18. package/dist/index.d.ts +8 -0
  19. package/dist/index.js +5 -0
  20. package/dist/interactiveHalt.d.ts +3 -1
  21. package/dist/interactiveHalt.js +2 -0
  22. package/dist/interactiveInterrupt.d.ts +2 -0
  23. package/dist/interactiveInterrupt.js +15 -0
  24. package/dist/modsFace.d.ts +8 -0
  25. package/dist/modsFace.js +59 -0
  26. package/dist/ownKey.d.ts +1 -0
  27. package/dist/ownKey.js +15 -0
  28. package/dist/printToolResultFrame.js +1 -1
  29. package/dist/request/printNotification.js +1 -1
  30. package/dist/request/taskRequest.d.ts +21 -0
  31. package/dist/request/taskRequest.js +123 -7
  32. package/dist/seam.js +1 -1
  33. package/dist/seatContract.d.ts +22 -6
  34. package/dist/seatContract.js +35 -6
  35. package/dist/sessionBackground.d.ts +165 -0
  36. package/dist/sessionBackground.js +781 -0
  37. package/dist/sessionBackgroundHandoff.d.ts +54 -0
  38. package/dist/sessionBackgroundHandoff.js +321 -0
  39. package/dist/sessionMap.js +4 -1
  40. package/dist/settingsCredentialKeyPaths.js +2 -17
  41. package/dist/thinkingLatch.d.ts +69 -0
  42. package/dist/thinkingLatch.js +255 -0
  43. package/dist/thinkingLatchWords.d.ts +7 -0
  44. package/dist/thinkingLatchWords.js +4 -0
  45. package/dist/toolResult.js +2 -24
  46. package/docs/INTEGRATION-CLIENTS.md +309 -10
  47. package/package.json +1 -1
  48. package/dist/argvFlagValue.d.ts +0 -8
  49. package/dist/argvFlagValue.js +0 -37
@@ -0,0 +1,255 @@
1
+ import { readOwnDataValue } from './ownKey.js';
2
+ import { msg, renderMessage } from './i18n/translate.js';
3
+ import { quoteUntrustedForSentence } from './displayUntrusted.js';
4
+ import { seatCapabilityUnavailableDetail } from './seatContract.js';
5
+ import { THINKING_LATCH_EVENTS, } from './thinkingLatchWords.js';
6
+ const UNSET_WHYS = Object.freeze(['no_port', 'never_set', 'unreadable', 'malformed']);
7
+ const THINKING_LATCH_TRANSITIONS = Object.freeze({
8
+ on: Object.freeze({ on: 'on', off: 'off', toggle: 'off', clear: 'unset' }),
9
+ off: Object.freeze({ on: 'on', off: 'off', toggle: 'on', clear: 'unset' }),
10
+ unset: Object.freeze({ on: 'on', off: 'off', toggle: 'off', clear: 'unset' }),
11
+ });
12
+ const storedOf = (state) => (state === 'on' ? true : state === 'off' ? false : undefined);
13
+ const setReading = (state) => Object.freeze({ state });
14
+ const unsetReading = (why) => Object.freeze({ state: 'unset', why });
15
+ function normalizedReading(v) {
16
+ try {
17
+ if (typeof v !== 'object' || v === null)
18
+ return unsetReading('malformed');
19
+ const state = readOwnDataValue(v, 'state');
20
+ if (state === 'on' || state === 'off')
21
+ return setReading(state);
22
+ if (state !== 'unset')
23
+ return unsetReading('malformed');
24
+ const why = readOwnDataValue(v, 'why');
25
+ return typeof why === 'string' && UNSET_WHYS.includes(why) ? unsetReading(why) : unsetReading('malformed');
26
+ }
27
+ catch {
28
+ return unsetReading('malformed');
29
+ }
30
+ }
31
+ export function readThinkingLatch(port) {
32
+ if (port === undefined || port === null)
33
+ return unsetReading('no_port');
34
+ let stored;
35
+ try {
36
+ const read = port.read;
37
+ if (typeof read !== 'function')
38
+ return unsetReading('unreadable');
39
+ stored = Reflect.apply(read, port, []);
40
+ }
41
+ catch {
42
+ return unsetReading('unreadable');
43
+ }
44
+ if (stored === true)
45
+ return setReading('on');
46
+ if (stored === false)
47
+ return setReading('off');
48
+ if (stored === undefined)
49
+ return unsetReading('never_set');
50
+ return unsetReading('malformed');
51
+ }
52
+ export function writeThinkingLatch(port, event) {
53
+ if (port === undefined || port === null)
54
+ return Object.freeze({ kind: 'not_saved', why: 'no_port', previous: unsetReading('no_port') });
55
+ const previous = readThinkingLatch(port);
56
+ const ev = event;
57
+ if (typeof ev !== 'string' || !THINKING_LATCH_EVENTS.includes(ev)) {
58
+ return Object.freeze({ kind: 'not_saved', why: 'bad_event', previous });
59
+ }
60
+ const target = THINKING_LATCH_TRANSITIONS[previous.state][ev];
61
+ const clean = previous.why === undefined || previous.why === 'never_set';
62
+ if (clean && target === previous.state)
63
+ return Object.freeze({ kind: 'unchanged', state: target });
64
+ let wrote = false;
65
+ try {
66
+ const write = port.write;
67
+ if (typeof write === 'function') {
68
+ Reflect.apply(write, port, [storedOf(target)]);
69
+ wrote = true;
70
+ }
71
+ }
72
+ catch {
73
+ wrote = false;
74
+ }
75
+ if (!wrote)
76
+ return Object.freeze({ kind: 'not_saved', why: 'write_failed', attempted: target, now: readThinkingLatch(port) });
77
+ return Object.freeze({ kind: 'saved', previous, state: target });
78
+ }
79
+ const ownSlotOf = (v, key) => {
80
+ try {
81
+ const d = Object.getOwnPropertyDescriptor(v, key);
82
+ if (d === undefined)
83
+ return { kind: 'absent' };
84
+ return Object.hasOwn(d, 'value') ? { kind: 'data', value: d.value } : { kind: 'unreadable' };
85
+ }
86
+ catch {
87
+ return { kind: 'unreadable' };
88
+ }
89
+ };
90
+ function capabilityReadingOf(capability) {
91
+ if (typeof capability !== 'object' || capability === null)
92
+ return Object.freeze({ kind: 'malformed' });
93
+ const kind = ownSlotOf(capability, 'kind');
94
+ if (kind.kind !== 'data')
95
+ return Object.freeze({ kind: 'malformed' });
96
+ if (kind.value === 'not_reported')
97
+ return Object.freeze({ kind: 'not_reported' });
98
+ if (kind.value === 'reported') {
99
+ const available = ownSlotOf(capability, 'available');
100
+ return available.kind === 'data' && typeof available.value === 'boolean'
101
+ ? Object.freeze({ kind: 'reported', available: available.value })
102
+ : Object.freeze({ kind: 'malformed' });
103
+ }
104
+ return Object.freeze({ kind: 'malformed' });
105
+ }
106
+ const seatCarries = (capability) => {
107
+ try {
108
+ return seatCapabilityUnavailableDetail('thinkingLatch', capabilityReadingOf(capability)) === undefined;
109
+ }
110
+ catch {
111
+ return false;
112
+ }
113
+ };
114
+ const carrierBlocks = (carrier) => {
115
+ if (carrier.kind === 'absent')
116
+ return false;
117
+ if (carrier.kind === 'unreadable')
118
+ return true;
119
+ const c = carrier.value;
120
+ if (c === undefined)
121
+ return false;
122
+ if (typeof c !== 'object' || c === null)
123
+ return true;
124
+ const kind = ownSlotOf(c, 'kind');
125
+ if (kind.kind !== 'data')
126
+ return true;
127
+ if (kind.value === 'engine')
128
+ return false;
129
+ if (kind.value === 'seat') {
130
+ const capability = ownSlotOf(c, 'capability');
131
+ return capability.kind !== 'data' || !seatCarries(capability.value);
132
+ }
133
+ return true;
134
+ };
135
+ export function thinkingLatchView(reading, ctx) {
136
+ const r = normalizedReading(reading);
137
+ let carrier = { kind: 'absent' };
138
+ let modelSaysNoThinking = false;
139
+ if (ctx !== undefined && ctx !== null) {
140
+ if (typeof ctx !== 'object')
141
+ carrier = { kind: 'unreadable' };
142
+ else {
143
+ carrier = ownSlotOf(ctx, 'carrier');
144
+ const model = ownSlotOf(ctx, 'model');
145
+ if (model.kind === 'data' && typeof model.value === 'object' && model.value !== null) {
146
+ const mk = ownSlotOf(model.value, 'kind');
147
+ modelSaysNoThinking = mk.kind === 'data' && mk.value === 'not_applicable';
148
+ }
149
+ }
150
+ }
151
+ const conflict = carrierBlocks(carrier) ? 'seat_cannot_carry' : r.state === 'on' && modelSaysNoThinking ? 'model_cannot_think' : undefined;
152
+ return Object.freeze({ state: r.state, ...(r.why !== undefined ? { why: r.why } : {}), ...(conflict !== undefined ? { conflict } : {}) });
153
+ }
154
+ const MODEL_NAME_MAX = 120;
155
+ const stateSentence = (state, lang) => state === 'on'
156
+ ? renderMessage(msg('session.thinking.state.on'), lang)
157
+ : state === 'off'
158
+ ? renderMessage(msg('session.thinking.state.off'), lang)
159
+ : state === 'unset'
160
+ ? renderMessage(msg('session.thinking.state.unset'), lang)
161
+ : undefined;
162
+ export function thinkingLatchSentence(subject, lang) {
163
+ try {
164
+ if (typeof subject !== 'object' || subject === null)
165
+ return undefined;
166
+ const kind = readOwnDataValue(subject, 'kind');
167
+ if (kind === 'state')
168
+ return stateSentence(readOwnDataValue(subject, 'state'), lang);
169
+ if (kind === 'turn') {
170
+ const p = readOwnDataValue(subject, 'projection');
171
+ if (typeof p !== 'object' || p === null)
172
+ return undefined;
173
+ return readOwnDataValue(p, 'verdict') === 'off' && readOwnDataValue(p, 'ultracodeStamped') === true
174
+ ? renderMessage(msg('session.thinking.offWithUltracodeOnBody'), lang)
175
+ : undefined;
176
+ }
177
+ if (kind === 'view') {
178
+ const view = readOwnDataValue(subject, 'view');
179
+ if (typeof view !== 'object' || view === null)
180
+ return undefined;
181
+ const conflict = readOwnDataValue(view, 'conflict');
182
+ if (conflict === 'seat_cannot_carry') {
183
+ const carrier = readOwnDataValue(subject, 'carrier');
184
+ const capability = typeof carrier === 'object' && carrier !== null && readOwnDataValue(carrier, 'kind') === 'seat'
185
+ ? readOwnDataValue(carrier, 'capability')
186
+ : undefined;
187
+ return seatCapabilityUnavailableDetail('thinkingLatch', capabilityReadingOf(capability));
188
+ }
189
+ if (conflict === 'model_cannot_think') {
190
+ const model = readOwnDataValue(subject, 'model');
191
+ const shown = typeof model === 'string' && model.length > 0 ? quoteUntrustedForSentence(model, MODEL_NAME_MAX) : undefined;
192
+ return shown === undefined ? undefined : renderMessage(msg('session.thinking.modelCannotThink', { model: shown }), lang);
193
+ }
194
+ if (conflict !== undefined)
195
+ return undefined;
196
+ const r = normalizedReading(view);
197
+ if (r.why === 'unreadable' || r.why === 'malformed')
198
+ return renderMessage(msg('session.thinking.storeUnreadable'), lang);
199
+ return stateSentence(r.state, lang);
200
+ }
201
+ if (kind === 'write') {
202
+ const outcome = readOwnDataValue(subject, 'outcome');
203
+ if (typeof outcome !== 'object' || outcome === null)
204
+ return undefined;
205
+ return readOwnDataValue(outcome, 'kind') === 'not_saved' ? renderMessage(msg('session.thinking.notSaved'), lang) : undefined;
206
+ }
207
+ if (kind === 'seat_ack') {
208
+ const ack = readOwnDataValue(subject, 'ack');
209
+ if (typeof ack !== 'object' || ack === null)
210
+ return undefined;
211
+ return readOwnDataValue(ack, 'ok') === false ? renderMessage(msg('session.thinking.notSaved'), lang) : undefined;
212
+ }
213
+ return undefined;
214
+ }
215
+ catch {
216
+ return undefined;
217
+ }
218
+ }
219
+ export function thinkingLatchRowWordOf(reading) {
220
+ const r = normalizedReading(reading);
221
+ if (r.state === 'on' || r.state === 'off')
222
+ return r.state;
223
+ if (r.why === 'unreadable')
224
+ return 'unreadable';
225
+ if (r.why === 'malformed')
226
+ return 'malformed';
227
+ return undefined;
228
+ }
229
+ export function readSeatThinkingLatch(record, capability) {
230
+ if (!seatCarries(capability))
231
+ return unsetReading('no_port');
232
+ const row = record;
233
+ if (row === undefined || row === null)
234
+ return unsetReading('no_port');
235
+ try {
236
+ if (typeof row !== 'object')
237
+ return unsetReading('malformed');
238
+ const d = Object.getOwnPropertyDescriptor(row, 'thinkingLatch');
239
+ if (d === undefined)
240
+ return unsetReading('never_set');
241
+ if (!Object.hasOwn(d, 'value'))
242
+ return unsetReading('malformed');
243
+ const w = d.value;
244
+ if (w === undefined)
245
+ return unsetReading('never_set');
246
+ if (w === 'on' || w === 'off')
247
+ return setReading(w);
248
+ if (w === 'unreadable')
249
+ return unsetReading('unreadable');
250
+ return unsetReading('malformed');
251
+ }
252
+ catch {
253
+ return unsetReading('unreadable');
254
+ }
255
+ }
@@ -0,0 +1,7 @@
1
+ export declare const THINKING_LATCH_STATES: readonly ["on", "off", "unset"];
2
+ export type ThinkingLatchState = (typeof THINKING_LATCH_STATES)[number];
3
+ export declare const THINKING_LATCH_SET_STATES: readonly ["on", "off"];
4
+ export declare const THINKING_LATCH_EVENTS: readonly ["on", "off", "toggle", "clear"];
5
+ export type ThinkingLatchEvent = (typeof THINKING_LATCH_EVENTS)[number];
6
+ export declare const THINKING_LATCH_ROW_WORDS: readonly ["on", "off", "unreadable", "malformed"];
7
+ export type ThinkingLatchRowWord = (typeof THINKING_LATCH_ROW_WORDS)[number];
@@ -0,0 +1,4 @@
1
+ export const THINKING_LATCH_STATES = Object.freeze(['on', 'off', 'unset']);
2
+ export const THINKING_LATCH_SET_STATES = Object.freeze(['on', 'off']);
3
+ export const THINKING_LATCH_EVENTS = Object.freeze(['on', 'off', 'toggle', 'clear']);
4
+ export const THINKING_LATCH_ROW_WORDS = Object.freeze(['on', 'off', 'unreadable', 'malformed']);
@@ -4,7 +4,7 @@ import { parseWorkflowPollEnvelope, projectWorkflowTaskOutput } from './workflow
4
4
  import { asModelFallbackReason } from './engineErrorCodes.js';
5
5
  import { frozenSet } from './frozenSet.js';
6
6
  import { bashExitOf, bashExitReadingFailed } from './bashExitReading.js';
7
- import { guardedRead, ownSnapshotWhenTyped, readFrameTrueMark, readFrameTrueMarkReading, readOwnDataFiniteNumber, readOwnDataNonEmptyString, readOwnDataValue, } from './ownKey.js';
7
+ import { guardedRead, ownDataField, ownSnapshotWhenTyped, readFrameTrueMark, readFrameTrueMarkReading, readOwnDataFiniteNumber, readOwnDataNonEmptyString, readOwnDataValue, toolResultBlockOf, } from './ownKey.js';
8
8
  import { displayUntrusted } from './displayUntrusted.js';
9
9
  import { isCoreSemaTaskTerminal } from './terminalStatuses.js';
10
10
  import { CORE_ENGINE_CARD_TYPES } from './generated/engineFactTables.js';
@@ -285,29 +285,7 @@ const TOOL_CARD_DEGRADED_TEXT = {
285
285
  unrecognised: 'This tool call carries a result marker this client does not recognise, so no result is shown for it.',
286
286
  };
287
287
  const cardDegraded = (cause) => ({ kind: 'degraded', cause, text: TOOL_CARD_DEGRADED_TEXT[cause] });
288
- function cardOwnData(o, key) {
289
- const d = Object.getOwnPropertyDescriptor(o, key);
290
- if (d === undefined)
291
- return undefined;
292
- if (!Object.hasOwn(d, 'value'))
293
- throw new TypeError(`own property "${key}" is an accessor`);
294
- return d.value;
295
- }
296
288
  const isCardRecordObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
297
- function toolResultBlockOf(record) {
298
- const message = cardOwnData(record, 'message');
299
- if (!isCardRecordObject(message))
300
- return undefined;
301
- const content = cardOwnData(message, 'content');
302
- if (!Array.isArray(content))
303
- return undefined;
304
- for (let i = 0; i < content.length; i++) {
305
- const block = cardOwnData(content, String(i));
306
- if (isCardRecordObject(block) && cardOwnData(block, 'type') === 'tool_result')
307
- return block;
308
- }
309
- return undefined;
310
- }
311
289
  export function readToolCardOutcome(record) {
312
290
  try {
313
291
  if (!isCardRecordObject(record))
@@ -327,7 +305,7 @@ export function readToolCardOutcome(record) {
327
305
  return { kind: 'unreadable' };
328
306
  if (markerDesc.value !== TOOL_RESULT_DEGRADED_WIRE_NO_OUTPUT)
329
307
  return cardDegraded('unrecognised');
330
- return cardDegraded(cardOwnData(block, 'is_error') === true ? 'error-without-detail' : 'no-result');
308
+ return cardDegraded(ownDataField(block, 'is_error') === true ? 'error-without-detail' : 'no-result');
331
309
  }
332
310
  catch {
333
311
  return { kind: 'unreadable' };