@sema-agent/client-core 0.86.0 → 0.87.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.
- package/CHANGELOG.md +55 -0
- package/README.md +6 -4
- package/dist/adapt/arms.js +9 -0
- package/dist/adapter/downstream/terminalToSdkResult.js +4 -1
- package/dist/adapter/runStream.js +75 -2
- package/dist/adapter/types.d.ts +3 -0
- package/dist/decideReceipt.d.ts +1 -1
- package/dist/decideReceipt.js +1 -1
- package/dist/detachWire.d.ts +6 -1
- package/dist/detachWire.js +22 -1
- package/dist/hitl/crashConverged.d.ts +1 -0
- package/dist/hitl/crashConverged.js +17 -2
- package/dist/hitl/hitlBridge.d.ts +4 -0
- package/dist/hitl/hitlBridge.js +6 -0
- package/dist/hitl/parkResolver.js +17 -12
- package/dist/hitl/suspendedReopen.d.ts +7 -0
- package/dist/hitl/suspendedReopen.js +38 -7
- package/dist/hitl/toolApprovalWire.js +4 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/resumeRefusalCopy.d.ts +2 -7
- package/dist/resumeRefusalCopy.js +2 -24
- package/dist/rewindArchiveCapability.js +5 -0
- package/dist/seam.d.ts +11 -1
- package/dist/seam.js +7 -0
- package/dist/toolHistoryMismatch.d.ts +63 -0
- package/dist/toolHistoryMismatch.js +425 -0
- package/dist/workflowClient.d.ts +3 -2
- package/dist/workflowClient.js +3 -3
- package/docs/INTEGRATION-CLIENTS.md +232 -8
- package/package.json +1 -1
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
export const TOOL_HISTORY_MISMATCH_KINDS = Object.freeze([
|
|
2
|
+
'tool_use_without_result',
|
|
3
|
+
'orphan_tool_result',
|
|
4
|
+
'duplicate_tool_use_id',
|
|
5
|
+
]);
|
|
6
|
+
const ID_AFTER_COLON = /^:\s*([^\s,;]+)/;
|
|
7
|
+
export const TOOL_HISTORY_MISMATCH_ANCHORS = Object.freeze([
|
|
8
|
+
Object.freeze({
|
|
9
|
+
kind: 'tool_use_without_result',
|
|
10
|
+
template: /^`?tool_use`? ids were found without `?tool_result`? blocks immediately after\b/,
|
|
11
|
+
idAfter: ID_AFTER_COLON,
|
|
12
|
+
}),
|
|
13
|
+
Object.freeze({
|
|
14
|
+
kind: 'orphan_tool_result',
|
|
15
|
+
template: /^unexpected `?tool_use_id`? found in `?tool_result`?(?: blocks?)?(?=[\s:,.]|$)/,
|
|
16
|
+
idAfter: ID_AFTER_COLON,
|
|
17
|
+
}),
|
|
18
|
+
Object.freeze({
|
|
19
|
+
kind: 'duplicate_tool_use_id',
|
|
20
|
+
template: /^`?tool_use`? ids must be unique\b/,
|
|
21
|
+
idAfter: null,
|
|
22
|
+
}),
|
|
23
|
+
]);
|
|
24
|
+
const ENGINE_HTTP_400_LEAD = /^(?:\[invalid_request\]\s*)?[^\n:]{0,60}?\bHTTP 400:\s*/;
|
|
25
|
+
const MESSAGES_LOCATOR = /^messages(?:\.[A-Za-z0-9_]+)+\s*:\s*/;
|
|
26
|
+
const PROVIDER_REJECTED_REQUEST_CODE = 'invalid_request';
|
|
27
|
+
function idOfToken(after, idAfter, endIsBoundary) {
|
|
28
|
+
const hit = idAfter.exec(after);
|
|
29
|
+
if (hit === null || hit[1] === undefined)
|
|
30
|
+
return undefined;
|
|
31
|
+
if (hit[0].length >= after.length && !endIsBoundary)
|
|
32
|
+
return undefined;
|
|
33
|
+
const next = after[hit[0].length];
|
|
34
|
+
let id = hit[1];
|
|
35
|
+
if (next !== ',' && next !== ';') {
|
|
36
|
+
if (id.endsWith('.'))
|
|
37
|
+
id = id.slice(0, -1);
|
|
38
|
+
if (id.endsWith('.') || id.endsWith(':'))
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
return ROW_KEY_ID.test(id) ? id : undefined;
|
|
42
|
+
}
|
|
43
|
+
function matchAnchoredSentence(sentence, endIsBoundary) {
|
|
44
|
+
const rest = sentence.replace(MESSAGES_LOCATOR, '');
|
|
45
|
+
for (const anchor of TOOL_HISTORY_MISMATCH_ANCHORS) {
|
|
46
|
+
const hit = anchor.template.exec(rest);
|
|
47
|
+
if (hit === null)
|
|
48
|
+
continue;
|
|
49
|
+
if (anchor.idAfter === null)
|
|
50
|
+
return { kind: anchor.kind };
|
|
51
|
+
const id = idOfToken(rest.slice(hit[0].length), anchor.idAfter, endIsBoundary);
|
|
52
|
+
return id !== undefined ? { kind: anchor.kind, toolUseId: id } : { kind: anchor.kind };
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
function envelopeMessages(body) {
|
|
57
|
+
const out = [];
|
|
58
|
+
const n = body.length;
|
|
59
|
+
let i = 0;
|
|
60
|
+
const skipWs = () => {
|
|
61
|
+
while (i < n && (body[i] === ' ' || body[i] === '\t' || body[i] === '\n' || body[i] === '\r'))
|
|
62
|
+
i++;
|
|
63
|
+
};
|
|
64
|
+
const readString = () => {
|
|
65
|
+
i++;
|
|
66
|
+
let text = '';
|
|
67
|
+
while (i < n) {
|
|
68
|
+
const c = body[i];
|
|
69
|
+
if (c === '"') {
|
|
70
|
+
i++;
|
|
71
|
+
return { text, closed: true };
|
|
72
|
+
}
|
|
73
|
+
if (c === '\\') {
|
|
74
|
+
const e = body[i + 1];
|
|
75
|
+
if (e === undefined) {
|
|
76
|
+
i = n;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
if (e === 'u') {
|
|
80
|
+
const hex = body.slice(i + 2, i + 6);
|
|
81
|
+
if (!/^[0-9A-Fa-f]{4}$/.test(hex)) {
|
|
82
|
+
i = n;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
text += String.fromCharCode(parseInt(hex, 16));
|
|
86
|
+
i += 6;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
text += e === 'n' ? '\n' : e === 't' ? '\t' : e === 'r' ? '\r' : e === 'b' ? '\b' : e === 'f' ? '\f' : e;
|
|
90
|
+
i += 2;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
text += c;
|
|
94
|
+
i++;
|
|
95
|
+
}
|
|
96
|
+
return { text, closed: false };
|
|
97
|
+
};
|
|
98
|
+
skipWs();
|
|
99
|
+
if (body[i] !== '{')
|
|
100
|
+
return out;
|
|
101
|
+
const path = [];
|
|
102
|
+
const want = [];
|
|
103
|
+
const onEnvelopePath = () => (path.length === 1 && path[0] === 'message') || (path.length === 2 && path[0] === 'error' && path[1] === 'message');
|
|
104
|
+
i++;
|
|
105
|
+
path.push(undefined);
|
|
106
|
+
want.push('key');
|
|
107
|
+
while (i < n && path.length > 0 && out.length < 4) {
|
|
108
|
+
skipWs();
|
|
109
|
+
if (i >= n)
|
|
110
|
+
break;
|
|
111
|
+
const c = body[i];
|
|
112
|
+
const top = want.length - 1;
|
|
113
|
+
const state = want[top];
|
|
114
|
+
const inArray = path[top] === null;
|
|
115
|
+
if (state === 'key') {
|
|
116
|
+
if (c === '}') {
|
|
117
|
+
i++;
|
|
118
|
+
path.pop();
|
|
119
|
+
want.pop();
|
|
120
|
+
if (want.length > 0)
|
|
121
|
+
want[want.length - 1] = 'next';
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (c !== '"')
|
|
125
|
+
break;
|
|
126
|
+
const key = readString();
|
|
127
|
+
if (!key.closed)
|
|
128
|
+
break;
|
|
129
|
+
path[top] = key.text;
|
|
130
|
+
want[top] = 'colon';
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (state === 'colon') {
|
|
134
|
+
if (c !== ':')
|
|
135
|
+
break;
|
|
136
|
+
i++;
|
|
137
|
+
want[top] = 'value';
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (state === 'next') {
|
|
141
|
+
if (c === ',') {
|
|
142
|
+
i++;
|
|
143
|
+
want[top] = inArray ? 'value' : 'key';
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (c === (inArray ? ']' : '}')) {
|
|
147
|
+
i++;
|
|
148
|
+
path.pop();
|
|
149
|
+
want.pop();
|
|
150
|
+
if (want.length > 0)
|
|
151
|
+
want[want.length - 1] = 'next';
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
if (inArray && c === ']') {
|
|
157
|
+
i++;
|
|
158
|
+
path.pop();
|
|
159
|
+
want.pop();
|
|
160
|
+
if (want.length > 0)
|
|
161
|
+
want[want.length - 1] = 'next';
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (c === '"') {
|
|
165
|
+
const value = readString();
|
|
166
|
+
if (!path.includes(null) && onEnvelopePath())
|
|
167
|
+
out.push(value);
|
|
168
|
+
want[top] = 'next';
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (c === '{' || c === '[') {
|
|
172
|
+
i++;
|
|
173
|
+
want[top] = 'next';
|
|
174
|
+
path.push(c === '{' ? undefined : null);
|
|
175
|
+
want.push(c === '{' ? 'key' : 'value');
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const lit = /^(?:true|false|null|-?[0-9][0-9.eE+-]*)/.exec(body.slice(i, i + 64));
|
|
179
|
+
if (lit === null)
|
|
180
|
+
break;
|
|
181
|
+
i += lit[0].length;
|
|
182
|
+
want[top] = 'next';
|
|
183
|
+
}
|
|
184
|
+
return out;
|
|
185
|
+
}
|
|
186
|
+
export function classifyToolHistoryMismatch(err) {
|
|
187
|
+
if (typeof err !== 'object' || err === null)
|
|
188
|
+
return null;
|
|
189
|
+
let code;
|
|
190
|
+
let status;
|
|
191
|
+
let rawMessage;
|
|
192
|
+
try {
|
|
193
|
+
code = err.code;
|
|
194
|
+
status = err.status;
|
|
195
|
+
rawMessage = err.message;
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
if (typeof rawMessage !== 'string' || rawMessage.length === 0)
|
|
201
|
+
return null;
|
|
202
|
+
if (typeof status === 'number' && status !== 400)
|
|
203
|
+
return null;
|
|
204
|
+
if (typeof code === 'string' && code.length > 0 && code !== PROVIDER_REJECTED_REQUEST_CODE)
|
|
205
|
+
return null;
|
|
206
|
+
let detail = rawMessage.trimStart();
|
|
207
|
+
const lead = ENGINE_HTTP_400_LEAD.exec(detail);
|
|
208
|
+
if (lead !== null)
|
|
209
|
+
detail = detail.slice(lead[0].length);
|
|
210
|
+
else if (status !== 400)
|
|
211
|
+
return null;
|
|
212
|
+
const body = detail.replace(/^400\s+/, '');
|
|
213
|
+
const direct = matchAnchoredSentence(body, false);
|
|
214
|
+
if (direct !== null)
|
|
215
|
+
return direct;
|
|
216
|
+
for (const value of envelopeMessages(body)) {
|
|
217
|
+
const hit = matchAnchoredSentence(value.text, value.closed);
|
|
218
|
+
if (hit !== null)
|
|
219
|
+
return hit;
|
|
220
|
+
}
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
export const TOOL_HISTORY_REWIND_SENTENCE = 'Run /rewind to recover the conversation.';
|
|
224
|
+
export function toolHistoryRepeatSentence(n) {
|
|
225
|
+
return `The same error has now happened ${n} times in a row; /rewind is the only way to recover this conversation.`;
|
|
226
|
+
}
|
|
227
|
+
let conversationRewindJudge;
|
|
228
|
+
export function _wireConversationRewindJudge(judge) {
|
|
229
|
+
conversationRewindJudge = judge;
|
|
230
|
+
}
|
|
231
|
+
export function toolHistoryRewindOffered(declared) {
|
|
232
|
+
const decl = declared;
|
|
233
|
+
if (decl === true)
|
|
234
|
+
return true;
|
|
235
|
+
if (typeof decl !== 'object' || decl === null)
|
|
236
|
+
return false;
|
|
237
|
+
try {
|
|
238
|
+
if (Array.isArray(decl))
|
|
239
|
+
return false;
|
|
240
|
+
const base = decl.engineBaseUrl;
|
|
241
|
+
const judge = conversationRewindJudge;
|
|
242
|
+
if (typeof base !== 'string' || base.length === 0 || judge === undefined)
|
|
243
|
+
return true;
|
|
244
|
+
return judge(base) !== 'unavailable';
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const isKind = (v) => typeof v === 'string' && TOOL_HISTORY_MISMATCH_KINDS.includes(v);
|
|
251
|
+
const ROW_KEY_ID = /^[A-Za-z0-9_.:-]{1,128}$/;
|
|
252
|
+
export function toolHistoryMismatchRowKey(m, consecutive) {
|
|
253
|
+
return {
|
|
254
|
+
kind: m.kind,
|
|
255
|
+
...(m.toolUseId !== undefined ? { toolUseId: m.toolUseId } : {}),
|
|
256
|
+
...(consecutive !== undefined && consecutive >= 2 ? { consecutive } : {}),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
export function readToolHistoryMismatchKey(v) {
|
|
260
|
+
if (typeof v !== 'object' || v === null || Array.isArray(v))
|
|
261
|
+
return undefined;
|
|
262
|
+
try {
|
|
263
|
+
const got = v;
|
|
264
|
+
const kind = got.kind;
|
|
265
|
+
if (!isKind(kind))
|
|
266
|
+
return undefined;
|
|
267
|
+
const id = got.toolUseId;
|
|
268
|
+
const n = got.consecutive;
|
|
269
|
+
return {
|
|
270
|
+
kind,
|
|
271
|
+
...(typeof id === 'string' && ROW_KEY_ID.test(id) ? { toolUseId: id } : {}),
|
|
272
|
+
...(typeof n === 'number' && Number.isSafeInteger(n) && n >= 2 ? { consecutive: n } : {}),
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
return undefined;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
export const TOOL_HISTORY_LEDGER_CAP = 64;
|
|
280
|
+
const PRIOR_RUN_IDS_CAP = 16;
|
|
281
|
+
const ECHOED_SESSION_IDS_CAP = TOOL_HISTORY_LEDGER_CAP * 4;
|
|
282
|
+
const toolHistoryLedger = new Map();
|
|
283
|
+
let toolHistoryGenerationSeq = 0;
|
|
284
|
+
const echoedSessionIds = new Set();
|
|
285
|
+
let unattributedTerminalSeq = 0;
|
|
286
|
+
function rememberEchoedSession(sessionId) {
|
|
287
|
+
echoedSessionIds.delete(sessionId);
|
|
288
|
+
echoedSessionIds.add(sessionId);
|
|
289
|
+
while (echoedSessionIds.size > ECHOED_SESSION_IDS_CAP) {
|
|
290
|
+
const oldest = echoedSessionIds.values().next();
|
|
291
|
+
if (oldest.done === true)
|
|
292
|
+
break;
|
|
293
|
+
echoedSessionIds.delete(oldest.value);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
export function openToolHistoryGeneration() {
|
|
297
|
+
toolHistoryGenerationSeq += 1;
|
|
298
|
+
return toolHistoryGenerationSeq;
|
|
299
|
+
}
|
|
300
|
+
const fingerprintOf = (m) => `${m.kind}\u0000${m.toolUseId ?? ''}`;
|
|
301
|
+
export function noteToolHistoryTerminal(note) {
|
|
302
|
+
const { sessionId, generation, runId, replay, mismatch } = note;
|
|
303
|
+
if (typeof sessionId !== 'string' || sessionId.length === 0) {
|
|
304
|
+
unattributedTerminalSeq += 1;
|
|
305
|
+
return undefined;
|
|
306
|
+
}
|
|
307
|
+
if (note.sessionEchoed === true)
|
|
308
|
+
rememberEchoedSession(sessionId);
|
|
309
|
+
else if (!echoedSessionIds.has(sessionId))
|
|
310
|
+
unattributedTerminalSeq += 1;
|
|
311
|
+
const row = toolHistoryLedger.get(sessionId);
|
|
312
|
+
const fingerprint = mismatch === null ? null : fingerprintOf(mismatch);
|
|
313
|
+
const run = !replay && typeof runId === 'string' && runId.length > 0 ? runId : undefined;
|
|
314
|
+
if (row !== undefined && generation < row.writtenGeneration) {
|
|
315
|
+
if (row.fingerprint !== fingerprint) {
|
|
316
|
+
touchLedgerRow(sessionId, {
|
|
317
|
+
fingerprint,
|
|
318
|
+
segmentRunIds: new Set(),
|
|
319
|
+
writtenGeneration: row.writtenGeneration,
|
|
320
|
+
unattributedMark: unattributedTerminalSeq,
|
|
321
|
+
lastRunId: undefined,
|
|
322
|
+
recentRunIds: run !== undefined ? [...row.recentRunIds, run].slice(-PRIOR_RUN_IDS_CAP) : row.recentRunIds,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
327
|
+
if (row !== undefined)
|
|
328
|
+
row.writtenGeneration = generation;
|
|
329
|
+
const interrupted = row !== undefined && row.unattributedMark < unattributedTerminalSeq;
|
|
330
|
+
if (run !== undefined && row !== undefined && (row.segmentRunIds.has(run) || row.recentRunIds.includes(run))) {
|
|
331
|
+
return !interrupted && row.lastRunId === run && fingerprint !== null && row.fingerprint === fingerprint ? row.segmentRunIds.size : undefined;
|
|
332
|
+
}
|
|
333
|
+
if (row !== undefined && row.fingerprint === fingerprint && !(interrupted && fingerprint !== null && run !== undefined)) {
|
|
334
|
+
if (run === undefined)
|
|
335
|
+
return undefined;
|
|
336
|
+
if (fingerprint !== null)
|
|
337
|
+
row.segmentRunIds.add(run);
|
|
338
|
+
row.lastRunId = run;
|
|
339
|
+
row.recentRunIds = [...row.recentRunIds, run].slice(-PRIOR_RUN_IDS_CAP);
|
|
340
|
+
touchLedgerRow(sessionId, row);
|
|
341
|
+
return fingerprint === null ? undefined : row.segmentRunIds.size;
|
|
342
|
+
}
|
|
343
|
+
touchLedgerRow(sessionId, {
|
|
344
|
+
fingerprint,
|
|
345
|
+
segmentRunIds: fingerprint !== null && run !== undefined ? new Set([run]) : new Set(),
|
|
346
|
+
writtenGeneration: generation,
|
|
347
|
+
unattributedMark: unattributedTerminalSeq,
|
|
348
|
+
lastRunId: run,
|
|
349
|
+
recentRunIds: run !== undefined ? [...(row?.recentRunIds ?? []), run].slice(-PRIOR_RUN_IDS_CAP) : [...(row?.recentRunIds ?? [])],
|
|
350
|
+
});
|
|
351
|
+
return fingerprint !== null && run !== undefined ? 1 : undefined;
|
|
352
|
+
}
|
|
353
|
+
function touchLedgerRow(sessionId, row) {
|
|
354
|
+
toolHistoryLedger.delete(sessionId);
|
|
355
|
+
toolHistoryLedger.set(sessionId, row);
|
|
356
|
+
while (toolHistoryLedger.size > TOOL_HISTORY_LEDGER_CAP) {
|
|
357
|
+
const oldest = toolHistoryLedger.keys().next();
|
|
358
|
+
if (oldest.done === true)
|
|
359
|
+
break;
|
|
360
|
+
toolHistoryLedger.delete(oldest.value);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
export function _resetToolHistoryLedgerForTest() {
|
|
364
|
+
toolHistoryLedger.clear();
|
|
365
|
+
echoedSessionIds.clear();
|
|
366
|
+
}
|
|
367
|
+
export const TOOL_HISTORY_UNDECIDABLE_REASONS = Object.freeze([
|
|
368
|
+
'no-mismatch',
|
|
369
|
+
'no-tool-use-id',
|
|
370
|
+
'id-not-found',
|
|
371
|
+
'prompt-not-found',
|
|
372
|
+
'prompt-without-handle',
|
|
373
|
+
'unreadable-rows',
|
|
374
|
+
]);
|
|
375
|
+
const listHas = (list, id) => Array.isArray(list) && list.includes(id);
|
|
376
|
+
export function resolveToolHistoryRewindTarget(rows, mismatch) {
|
|
377
|
+
let kind;
|
|
378
|
+
try {
|
|
379
|
+
if (typeof mismatch !== 'object' || mismatch === null)
|
|
380
|
+
return { undecidable: 'no-mismatch' };
|
|
381
|
+
kind = mismatch.kind;
|
|
382
|
+
}
|
|
383
|
+
catch {
|
|
384
|
+
return { undecidable: 'no-mismatch' };
|
|
385
|
+
}
|
|
386
|
+
if (!isKind(kind))
|
|
387
|
+
return { undecidable: 'no-mismatch' };
|
|
388
|
+
let id;
|
|
389
|
+
try {
|
|
390
|
+
id = mismatch.toolUseId;
|
|
391
|
+
}
|
|
392
|
+
catch {
|
|
393
|
+
return { undecidable: 'no-mismatch' };
|
|
394
|
+
}
|
|
395
|
+
if (typeof id !== 'string' || id.length === 0)
|
|
396
|
+
return { undecidable: 'no-tool-use-id' };
|
|
397
|
+
try {
|
|
398
|
+
if (!Array.isArray(rows))
|
|
399
|
+
return { undecidable: 'unreadable-rows' };
|
|
400
|
+
let hit = -1;
|
|
401
|
+
for (let i = 0; i < rows.length; i++) {
|
|
402
|
+
const r = rows[i];
|
|
403
|
+
if (typeof r !== 'object' || r === null || r.local === true)
|
|
404
|
+
continue;
|
|
405
|
+
if (listHas(r.toolUseIds, id) || listHas(r.toolResultIds, id)) {
|
|
406
|
+
hit = i;
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (hit < 0)
|
|
411
|
+
return { undecidable: 'id-not-found' };
|
|
412
|
+
for (let j = hit; j >= 0; j--) {
|
|
413
|
+
const r = rows[j];
|
|
414
|
+
if (typeof r !== 'object' || r === null || r.local === true || r.prompt !== true)
|
|
415
|
+
continue;
|
|
416
|
+
if (r.sessionRoot === true)
|
|
417
|
+
return { rootReopen: true };
|
|
418
|
+
return typeof r.engineHandle === 'string' && r.engineHandle.length > 0 ? { target: r } : { undecidable: 'prompt-without-handle' };
|
|
419
|
+
}
|
|
420
|
+
return { undecidable: 'prompt-not-found' };
|
|
421
|
+
}
|
|
422
|
+
catch {
|
|
423
|
+
return { undecidable: 'unreadable-rows' };
|
|
424
|
+
}
|
|
425
|
+
}
|
package/dist/workflowClient.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { WorkflowRun, WorkflowStreamEvent } from '@sema-agent/sdk';
|
|
2
|
+
import { type WireAuthTokenSource } from './engineWireSdk.js';
|
|
2
3
|
import type { WorkflowRunState, WorkflowToolCall } from './workflowMonitor.js';
|
|
3
4
|
export interface LiveWorkflowController {
|
|
4
5
|
snapshot(): WorkflowRunState | null;
|
|
@@ -40,7 +41,7 @@ export type WorkflowResolution = {
|
|
|
40
41
|
};
|
|
41
42
|
export interface LiveWorkflowConfig {
|
|
42
43
|
baseUrl: string;
|
|
43
|
-
authToken:
|
|
44
|
+
authToken: WireAuthTokenSource | {
|
|
44
45
|
mode: 'same-origin-relay';
|
|
45
46
|
};
|
|
46
47
|
principal: string | undefined;
|
|
@@ -78,7 +79,7 @@ export interface WorkflowActivityLedgerView {
|
|
|
78
79
|
}
|
|
79
80
|
export interface WorkflowActivityLedgerConfig {
|
|
80
81
|
baseUrl: string;
|
|
81
|
-
authToken:
|
|
82
|
+
authToken: WireAuthTokenSource | {
|
|
82
83
|
mode: 'same-origin-relay';
|
|
83
84
|
};
|
|
84
85
|
principal: string | undefined;
|
package/dist/workflowClient.js
CHANGED
|
@@ -347,9 +347,9 @@ function sameActivityScope(a, b) {
|
|
|
347
347
|
return false;
|
|
348
348
|
const at = a.authToken;
|
|
349
349
|
const bt = b.authToken;
|
|
350
|
-
if (typeof at === '
|
|
351
|
-
return at === bt;
|
|
352
|
-
return at
|
|
350
|
+
if (typeof at === 'object' && typeof bt === 'object')
|
|
351
|
+
return at.mode === bt.mode;
|
|
352
|
+
return at === bt;
|
|
353
353
|
}
|
|
354
354
|
function newActivityAcc(label) {
|
|
355
355
|
return { label, calls: new Map(), order: [], startCount: 0 };
|