@astram/frontend-core 0.11.0 → 0.12.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/dist/agent/agentReducer.d.ts +27 -0
- package/dist/agent/agentReducer.d.ts.map +1 -0
- package/dist/agent/agentReducer.js +286 -0
- package/dist/agent/agentReducer.js.map +1 -0
- package/dist/agent/agentService.d.ts +136 -0
- package/dist/agent/agentService.d.ts.map +1 -0
- package/dist/agent/agentService.js +308 -0
- package/dist/agent/agentService.js.map +1 -0
- package/dist/agent/index.d.ts +14 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +10 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/scriptedTransport.d.ts +20 -0
- package/dist/agent/scriptedTransport.d.ts.map +1 -0
- package/dist/agent/scriptedTransport.js +122 -0
- package/dist/agent/scriptedTransport.js.map +1 -0
- package/dist/agent/sseParser.d.ts +45 -0
- package/dist/agent/sseParser.d.ts.map +1 -0
- package/dist/agent/sseParser.js +216 -0
- package/dist/agent/sseParser.js.map +1 -0
- package/dist/agent/types.d.ts +201 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +5 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/http/refreshingHttp.d.ts +28 -1
- package/dist/http/refreshingHttp.d.ts.map +1 -1
- package/dist/http/refreshingHttp.js +19 -0
- package/dist/http/refreshingHttp.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { INITIAL_AGENT_STATE, agentErrorText, agentReducer } from './agentReducer.js';
|
|
2
|
+
import { parseSseFrames } from './sseParser.js';
|
|
3
|
+
import { AGENT_STREAM_STALL_MS, } from './types.js';
|
|
4
|
+
/** A native AbortController when there is one; else a minimal stand-in with the same shape. */
|
|
5
|
+
function newAbort() {
|
|
6
|
+
const Ctor = globalThis.AbortController;
|
|
7
|
+
if (typeof Ctor === 'function') {
|
|
8
|
+
const c = new Ctor();
|
|
9
|
+
return { signal: c.signal, abort: () => c.abort() };
|
|
10
|
+
}
|
|
11
|
+
const listeners = new Set();
|
|
12
|
+
const signal = {
|
|
13
|
+
aborted: false,
|
|
14
|
+
addEventListener: (_t, l) => void listeners.add(l),
|
|
15
|
+
removeEventListener: (_t, l) => void listeners.delete(l),
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
signal,
|
|
19
|
+
abort: () => {
|
|
20
|
+
if (signal.aborted)
|
|
21
|
+
return;
|
|
22
|
+
signal.aborted = true;
|
|
23
|
+
for (const l of [...listeners])
|
|
24
|
+
l();
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function safely(fn) {
|
|
29
|
+
try {
|
|
30
|
+
fn();
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
/* app callbacks are best-effort */
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function refusalBody(v) {
|
|
37
|
+
if (v === null || typeof v !== 'object' || Array.isArray(v))
|
|
38
|
+
return null;
|
|
39
|
+
const b = v;
|
|
40
|
+
return typeof b.code === 'string' && b.code !== '' && typeof b.retryable === 'boolean'
|
|
41
|
+
? { code: b.code, retryable: b.retryable }
|
|
42
|
+
: null;
|
|
43
|
+
}
|
|
44
|
+
function failure(status, body) {
|
|
45
|
+
const code = body?.code ?? null;
|
|
46
|
+
return {
|
|
47
|
+
ok: false,
|
|
48
|
+
status,
|
|
49
|
+
code,
|
|
50
|
+
retryable: body?.retryable ?? false,
|
|
51
|
+
error: agentErrorText(code, status),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const isStr = (v) => typeof v === 'string';
|
|
55
|
+
const isStrOrNull = (v) => v === null || typeof v === 'string';
|
|
56
|
+
const isCount = (v) => Number.isSafeInteger(v) && v >= 0;
|
|
57
|
+
function readPartial(v) {
|
|
58
|
+
if (v === null || typeof v !== 'object')
|
|
59
|
+
return null;
|
|
60
|
+
const p = v;
|
|
61
|
+
if (!isCount(p.shown) || (p.total !== null && !isCount(p.total)))
|
|
62
|
+
return null;
|
|
63
|
+
return { shown: p.shown, total: p.total };
|
|
64
|
+
}
|
|
65
|
+
function readAction(v) {
|
|
66
|
+
if (v === null || typeof v !== 'object')
|
|
67
|
+
return null;
|
|
68
|
+
const a = v;
|
|
69
|
+
if (!isStr(a.callId) ||
|
|
70
|
+
!isStr(a.capability) ||
|
|
71
|
+
!isStr(a.title) ||
|
|
72
|
+
!isStr(a.status) ||
|
|
73
|
+
!isStrOrNull(a.code ?? null) ||
|
|
74
|
+
!isStrOrNull(a.startedAt ?? null)) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
callId: a.callId,
|
|
79
|
+
capability: a.capability,
|
|
80
|
+
title: a.title,
|
|
81
|
+
status: a.status,
|
|
82
|
+
code: (a.code ?? null),
|
|
83
|
+
startedAt: (a.startedAt ?? null),
|
|
84
|
+
durationMs: isCount(a.durationMs) ? a.durationMs : null,
|
|
85
|
+
partial: readPartial(a.partial),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function readView(v) {
|
|
89
|
+
if (v === null || typeof v !== 'object')
|
|
90
|
+
return null;
|
|
91
|
+
const t = v;
|
|
92
|
+
const u = (t.usage ?? null);
|
|
93
|
+
if (!isStr(t.taskId) ||
|
|
94
|
+
!isStr(t.state) ||
|
|
95
|
+
!isCount(t.runs) ||
|
|
96
|
+
!isStrOrNull(t.createdAt ?? null) ||
|
|
97
|
+
!isStrOrNull(t.closedAt ?? null) ||
|
|
98
|
+
!isStrOrNull(t.endReason ?? null) ||
|
|
99
|
+
u === null ||
|
|
100
|
+
typeof u !== 'object' ||
|
|
101
|
+
!Array.isArray(t.actions)) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
const n = (x) => (isCount(x) ? x : 0);
|
|
105
|
+
return {
|
|
106
|
+
taskId: t.taskId,
|
|
107
|
+
state: t.state,
|
|
108
|
+
runs: t.runs,
|
|
109
|
+
createdAt: (t.createdAt ?? null),
|
|
110
|
+
closedAt: (t.closedAt ?? null),
|
|
111
|
+
endReason: (t.endReason ?? null),
|
|
112
|
+
usage: {
|
|
113
|
+
modelCalls: n(u.modelCalls),
|
|
114
|
+
toolCalls: n(u.toolCalls),
|
|
115
|
+
inputTokens: n(u.inputTokens),
|
|
116
|
+
outputTokens: n(u.outputTokens),
|
|
117
|
+
},
|
|
118
|
+
actions: t.actions.map(readAction).filter((a) => a !== null),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
const taskPath = (taskId) => `/agent/tasks/${encodeURIComponent(taskId)}`;
|
|
122
|
+
/** Only the fields of the chosen continue variant are sent. */
|
|
123
|
+
function continueBody(input) {
|
|
124
|
+
if ('answers' in input)
|
|
125
|
+
return { answers: input.answers };
|
|
126
|
+
if ('retry' in input)
|
|
127
|
+
return { retry: true };
|
|
128
|
+
return { message: input.message };
|
|
129
|
+
}
|
|
130
|
+
export function createAgentService(http, stream, options = {}) {
|
|
131
|
+
const stallMs = typeof options.stallMs === 'number' && Number.isFinite(options.stallMs) && options.stallMs > 0
|
|
132
|
+
? options.stallMs
|
|
133
|
+
: AGENT_STREAM_STALL_MS;
|
|
134
|
+
const runStream = async (req, live, opts) => {
|
|
135
|
+
let state = opts.state ?? INITIAL_AGENT_STATE;
|
|
136
|
+
const apply = (event) => {
|
|
137
|
+
const next = agentReducer(state, event);
|
|
138
|
+
if (next === state)
|
|
139
|
+
return;
|
|
140
|
+
state = next;
|
|
141
|
+
safely(() => opts.onState?.(next));
|
|
142
|
+
};
|
|
143
|
+
const ctl = newAbort();
|
|
144
|
+
let abortedByCaller = false;
|
|
145
|
+
let wakeOnAbort = null;
|
|
146
|
+
const onCallerAbort = () => {
|
|
147
|
+
abortedByCaller = true;
|
|
148
|
+
ctl.abort();
|
|
149
|
+
wakeOnAbort?.();
|
|
150
|
+
};
|
|
151
|
+
if (opts.signal?.aborted)
|
|
152
|
+
onCallerAbort();
|
|
153
|
+
else
|
|
154
|
+
opts.signal?.addEventListener('abort', onCallerAbort);
|
|
155
|
+
const detach = () => opts.signal?.removeEventListener('abort', onCallerAbort);
|
|
156
|
+
let res = null;
|
|
157
|
+
try {
|
|
158
|
+
res = abortedByCaller ? null : await stream.open({ ...req, signal: ctl.signal });
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
res = null;
|
|
162
|
+
}
|
|
163
|
+
if (res === null || res.status !== 200 || res.chunks === null || abortedByCaller) {
|
|
164
|
+
if (res !== null)
|
|
165
|
+
safely(() => res.close());
|
|
166
|
+
detach();
|
|
167
|
+
const raw = res === null ? 0 : res.status;
|
|
168
|
+
// A 200 without a stream, or a caller abort, is a broken connection (status 0).
|
|
169
|
+
const status = Number.isInteger(raw) && raw !== 200 && !abortedByCaller ? raw : 0;
|
|
170
|
+
const body = status === 0 ? null : refusalBody(res?.error ?? null);
|
|
171
|
+
const f = failure(status, body);
|
|
172
|
+
apply({ type: 'local.refused', status, code: f.code, retryable: f.retryable });
|
|
173
|
+
return { ...f, state };
|
|
174
|
+
}
|
|
175
|
+
const opened = res;
|
|
176
|
+
const parser = parseSseFrames();
|
|
177
|
+
apply({ type: 'local.opened', live });
|
|
178
|
+
let complete = false;
|
|
179
|
+
const host = globalThis;
|
|
180
|
+
let iterator = null;
|
|
181
|
+
try {
|
|
182
|
+
iterator = opened.chunks[Symbol.asyncIterator]();
|
|
183
|
+
const stopped = new Promise((resolve) => {
|
|
184
|
+
wakeOnAbort = () => resolve('stopped');
|
|
185
|
+
if (abortedByCaller)
|
|
186
|
+
resolve('stopped');
|
|
187
|
+
});
|
|
188
|
+
for (;;) {
|
|
189
|
+
let timer;
|
|
190
|
+
const stall = new Promise((resolve) => {
|
|
191
|
+
if (typeof host.setTimeout === 'function') {
|
|
192
|
+
timer = host.setTimeout(() => resolve('stall'), stallMs);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
let step;
|
|
196
|
+
try {
|
|
197
|
+
step = await Promise.race([iterator.next(), stall, stopped]);
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
step = 'failed';
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
host.clearTimeout?.(timer);
|
|
204
|
+
}
|
|
205
|
+
if (typeof step === 'string')
|
|
206
|
+
break; // stalled, aborted or the transport failed
|
|
207
|
+
if (step.done) {
|
|
208
|
+
complete = true;
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
if (typeof step.value !== 'string')
|
|
212
|
+
continue;
|
|
213
|
+
for (const event of parser.push(step.value)) {
|
|
214
|
+
safely(() => opts.onEvent?.(event));
|
|
215
|
+
apply(event);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
complete = false;
|
|
221
|
+
}
|
|
222
|
+
finally {
|
|
223
|
+
parser.end();
|
|
224
|
+
if (!complete && iterator?.return) {
|
|
225
|
+
try {
|
|
226
|
+
void Promise.resolve(iterator.return()).catch(() => undefined);
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
/* closing is best-effort */
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
safely(() => opened.close());
|
|
233
|
+
ctl.abort();
|
|
234
|
+
detach();
|
|
235
|
+
}
|
|
236
|
+
if (live && (!complete || state.status === 'streaming')) {
|
|
237
|
+
apply({ type: 'local.connection_lost' });
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
apply({ type: 'local.closed' });
|
|
241
|
+
}
|
|
242
|
+
return { ok: true, state, dropped: parser.dropped, complete };
|
|
243
|
+
};
|
|
244
|
+
const guard = async (fn, fallback) => {
|
|
245
|
+
try {
|
|
246
|
+
return await fn();
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
return fallback();
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
const streamFailure = (opts) => ({
|
|
253
|
+
...failure(0, null),
|
|
254
|
+
state: agentReducer(opts.state ?? INITIAL_AGENT_STATE, {
|
|
255
|
+
type: 'local.refused',
|
|
256
|
+
status: 0,
|
|
257
|
+
code: null,
|
|
258
|
+
retryable: false,
|
|
259
|
+
}),
|
|
260
|
+
});
|
|
261
|
+
return {
|
|
262
|
+
openTask(input, opts = {}) {
|
|
263
|
+
return guard(() => {
|
|
264
|
+
const body = { message: input.message };
|
|
265
|
+
if (input.modelProfile !== undefined)
|
|
266
|
+
body.modelProfile = input.modelProfile;
|
|
267
|
+
if (input.locale !== undefined)
|
|
268
|
+
body.locale = input.locale;
|
|
269
|
+
return runStream({ method: 'POST', path: '/agent/tasks', body }, true, opts);
|
|
270
|
+
}, () => streamFailure(opts));
|
|
271
|
+
},
|
|
272
|
+
continueTask(taskId, input, opts = {}) {
|
|
273
|
+
return guard(() => runStream({ method: 'POST', path: `${taskPath(taskId)}/continue`, body: continueBody(input) }, true, opts), () => streamFailure(opts));
|
|
274
|
+
},
|
|
275
|
+
replay(taskId, lastSeq, opts = {}) {
|
|
276
|
+
return guard(() => {
|
|
277
|
+
const after = Number.isSafeInteger(lastSeq) && lastSeq > 0 ? lastSeq : undefined;
|
|
278
|
+
const req = after === undefined
|
|
279
|
+
? { method: 'GET', path: `${taskPath(taskId)}/events`, body: null }
|
|
280
|
+
: {
|
|
281
|
+
method: 'GET',
|
|
282
|
+
path: `${taskPath(taskId)}/events`,
|
|
283
|
+
body: null,
|
|
284
|
+
lastEventId: after,
|
|
285
|
+
};
|
|
286
|
+
return runStream(req, false, opts);
|
|
287
|
+
}, () => streamFailure(opts));
|
|
288
|
+
},
|
|
289
|
+
cancelTask(accessToken, taskId) {
|
|
290
|
+
return guard(async () => {
|
|
291
|
+
const r = await http.post(`${taskPath(taskId)}/cancel`, {}, {
|
|
292
|
+
bearerToken: accessToken,
|
|
293
|
+
});
|
|
294
|
+
return r.ok ? { ok: true } : failure(r.status, refusalBody(r.data));
|
|
295
|
+
}, () => failure(0, null));
|
|
296
|
+
},
|
|
297
|
+
getTask(accessToken, taskId, signal) {
|
|
298
|
+
return guard(async () => {
|
|
299
|
+
const r = await http.get(taskPath(taskId), signal ? { bearerToken: accessToken, signal } : { bearerToken: accessToken });
|
|
300
|
+
if (!r.ok)
|
|
301
|
+
return failure(r.status, refusalBody(r.data));
|
|
302
|
+
const task = readView(r.data);
|
|
303
|
+
return task ? { ok: true, task } : failure(r.status, null);
|
|
304
|
+
}, () => failure(0, null));
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
//# sourceMappingURL=agentService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentService.js","sourceRoot":"","sources":["../../src/agent/agentService.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EACL,qBAAqB,GAUtB,MAAM,YAAY,CAAC;AA+HpB,+FAA+F;AAC/F,SAAS,QAAQ;IACf,MAAM,IAAI,GAAI,UAAmB,CAAC,eAAe,CAAC;IAClD,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;QAC/B,MAAM,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;QACrB,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;IACtD,CAAC;IACD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc,CAAC;IACxC,MAAM,MAAM,GAAG;QACb,OAAO,EAAE,KAAK;QACd,gBAAgB,EAAE,CAAC,EAAW,EAAE,CAAa,EAAE,EAAE,CAAC,KAAK,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;QACvE,mBAAmB,EAAE,CAAC,EAAW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, stream parser, reducer and a scripted transport.
|
|
3
|
+
* DOM-free; the web stream transport lives in the scaffolded app (`platform/agentStreamTransport.js`).
|
|
4
|
+
*/
|
|
5
|
+
export { createAgentService } from './agentService.js';
|
|
6
|
+
export type { AgentService, AgentServiceOptions, AgentOpenInput, AgentAnswerInput, AgentContinueInput, AgentStreamOptions, AgentStreamResult, AgentFailure, AgentTaskView, AgentTaskAction, CancelAgentTaskResult, GetAgentTaskResult, } from './agentService.js';
|
|
7
|
+
export { parseSseFrames, toSseFrame, SSE_HEARTBEAT } from './sseParser.js';
|
|
8
|
+
export type { SseFrameParser, SseParserOptions } from './sseParser.js';
|
|
9
|
+
export { agentReducer, agentErrorText, isAgentTerminal, INITIAL_AGENT_STATE, } from './agentReducer.js';
|
|
10
|
+
export { createScriptedAgentTransport } from './scriptedTransport.js';
|
|
11
|
+
export type { AgentScript, ScriptedTransportOptions, ScriptedAgentTransport, } from './scriptedTransport.js';
|
|
12
|
+
export { AGENT_STREAM_VERSION, AGENT_STREAM_STALL_MS } from './types.js';
|
|
13
|
+
export type { AgentEventType, AgentStreamEvent, SseDrop, SseDropReason, EvidenceNum, MetricEvidence, TableEvidence, SeriesEvidence, AgentEvidence, AgentPartial, AgentToolStatus, AgentToolState, AgentStep, AgentClaim, AgentAnswer, AgentQuestion, AgentQuestionOption, AgentTaskError, AgentUsage, AgentTaskStatus, AgentTaskState, AgentLocalEvent, AgentRefusalBody, AgentStreamRequest, AgentStreamResponse, AgentStreamTransport, } from './types.js';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,YAAY,EACV,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,eAAe,EACf,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC3E,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EACL,YAAY,EACZ,cAAc,EACd,eAAe,EACf,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AACtE,YAAY,EACV,WAAW,EACX,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACzE,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,OAAO,EACP,aAAa,EACb,WAAW,EACX,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,EACb,YAAY,EACZ,eAAe,EACf,cAAc,EACd,SAAS,EACT,UAAU,EACV,WAAW,EACX,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent client (G-036 M1): service, stream parser, reducer and a scripted transport.
|
|
3
|
+
* DOM-free; the web stream transport lives in the scaffolded app (`platform/agentStreamTransport.js`).
|
|
4
|
+
*/
|
|
5
|
+
export { createAgentService } from './agentService.js';
|
|
6
|
+
export { parseSseFrames, toSseFrame, SSE_HEARTBEAT } from './sseParser.js';
|
|
7
|
+
export { agentReducer, agentErrorText, isAgentTerminal, INITIAL_AGENT_STATE, } from './agentReducer.js';
|
|
8
|
+
export { createScriptedAgentTransport } from './scriptedTransport.js';
|
|
9
|
+
export { AGENT_STREAM_VERSION, AGENT_STREAM_STALL_MS } from './types.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAevD,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EACL,YAAY,EACZ,cAAc,EACd,eAAe,EACf,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAMtE,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AgentStreamEvent, AgentStreamRequest, AgentStreamTransport } from './types.js';
|
|
2
|
+
/** One scripted answer: a stream of envelopes or a refusal before the stream. */
|
|
3
|
+
export type AgentScript = {
|
|
4
|
+
readonly events: readonly AgentStreamEvent[];
|
|
5
|
+
} | {
|
|
6
|
+
readonly refusal: {
|
|
7
|
+
readonly status: number;
|
|
8
|
+
readonly body: unknown;
|
|
9
|
+
};
|
|
10
|
+
} | readonly AgentStreamEvent[];
|
|
11
|
+
export interface ScriptedTransportOptions {
|
|
12
|
+
/** Replay speed multiplier for the `ts` gaps (default 1; `Infinity` = no delay). */
|
|
13
|
+
readonly speed?: number;
|
|
14
|
+
}
|
|
15
|
+
/** The scripted transport, plus the requests it was given (for tests). */
|
|
16
|
+
export interface ScriptedAgentTransport extends AgentStreamTransport {
|
|
17
|
+
readonly requests: readonly Omit<AgentStreamRequest, 'signal'>[];
|
|
18
|
+
}
|
|
19
|
+
export declare function createScriptedAgentTransport(script: AgentScript | readonly AgentScript[], options?: ScriptedTransportOptions): ScriptedAgentTransport;
|
|
20
|
+
//# sourceMappingURL=scriptedTransport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scriptedTransport.d.ts","sourceRoot":"","sources":["../../src/agent/scriptedTransport.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAEV,gBAAgB,EAChB,kBAAkB,EAElB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAEpB,iFAAiF;AACjF,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,gBAAgB,EAAE,CAAA;CAAE,GAChD;IAAE,QAAQ,CAAC,OAAO,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,GACzE,SAAS,gBAAgB,EAAE,CAAC;AAEhC,MAAM,WAAW,wBAAwB;IACvC,oFAAoF;IACpF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,0EAA0E;AAC1E,MAAM,WAAW,sBAAuB,SAAQ,oBAAoB;IAClE,QAAQ,CAAC,QAAQ,EAAE,SAAS,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC,EAAE,CAAC;CAClE;AA2CD,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,WAAW,GAAG,SAAS,WAAW,EAAE,EAC5C,OAAO,GAAE,wBAA6B,GACrC,sBAAsB,CAqExB"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* createScriptedAgentTransport — an {@link AgentStreamTransport} that replays recorded envelopes
|
|
3
|
+
* (the same JSON as `@astram/agent-protocol` `fixtures/v0/sse/*.json`) as §3 B frames, with
|
|
4
|
+
* delays, for frontend work and tests without a backend (SPEC
|
|
5
|
+
* `docs/features/agent-read-capabilities/SPEC.md` §5 frontend-core).
|
|
6
|
+
*
|
|
7
|
+
* Each `open()` consumes the next script: a stream (`{ events }`, or a bare envelope list) answers
|
|
8
|
+
* `200` and yields one frame per event; a refusal (`{ refusal: { status, body } }`) answers that
|
|
9
|
+
* status with the parsed §3 D body and no stream. When the scripts run out, `open()` answers
|
|
10
|
+
* `status: 0` (as if the server were unreachable). A request with `lastEventId` (replay) gets only
|
|
11
|
+
* the events after it, plus a leading `replay.truncated` when the script has one.
|
|
12
|
+
*
|
|
13
|
+
* Delays follow the envelopes' `ts` gaps divided by `speed` (default 1), each capped at 2 s;
|
|
14
|
+
* `speed: Infinity` replays at once. `close()` or the request's abort signal ends the stream.
|
|
15
|
+
*/
|
|
16
|
+
import { toSseFrame } from './sseParser.js';
|
|
17
|
+
const MAX_DELAY_MS = 2_000;
|
|
18
|
+
function refusalBody(v) {
|
|
19
|
+
if (v === null || typeof v !== 'object')
|
|
20
|
+
return null;
|
|
21
|
+
const b = v;
|
|
22
|
+
return typeof b.code === 'string' && typeof b.retryable === 'boolean'
|
|
23
|
+
? { code: b.code, retryable: b.retryable }
|
|
24
|
+
: null;
|
|
25
|
+
}
|
|
26
|
+
function eventsOf(script) {
|
|
27
|
+
if (Array.isArray(script))
|
|
28
|
+
return script;
|
|
29
|
+
const s = script;
|
|
30
|
+
return Array.isArray(s.events) ? s.events : null;
|
|
31
|
+
}
|
|
32
|
+
function gapMs(prev, next, speed) {
|
|
33
|
+
if (!prev || !Number.isFinite(speed))
|
|
34
|
+
return 0;
|
|
35
|
+
const d = Date.parse(next.ts) - Date.parse(prev.ts);
|
|
36
|
+
if (!Number.isFinite(d) || d <= 0)
|
|
37
|
+
return 0;
|
|
38
|
+
return Math.min(MAX_DELAY_MS, d / speed);
|
|
39
|
+
}
|
|
40
|
+
/** Resolves after `ms`, or at once when the stream stops (`onStop` registers the wake-up). */
|
|
41
|
+
function sleep(ms, onStop) {
|
|
42
|
+
const host = globalThis;
|
|
43
|
+
if (ms <= 0 || typeof host.setTimeout !== 'function')
|
|
44
|
+
return Promise.resolve();
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
const id = host.setTimeout(resolve, ms);
|
|
47
|
+
onStop(() => {
|
|
48
|
+
host.clearTimeout?.(id);
|
|
49
|
+
resolve();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export function createScriptedAgentTransport(script, options = {}) {
|
|
54
|
+
// A single script, or a list of them (one per open()). A bare envelope list is one script.
|
|
55
|
+
const isList = Array.isArray(script) &&
|
|
56
|
+
script.length > 0 &&
|
|
57
|
+
script.every((s) => Array.isArray(s) || (s !== null && typeof s === 'object' && !('seq' in s)));
|
|
58
|
+
const scripts = isList
|
|
59
|
+
? script
|
|
60
|
+
: [script];
|
|
61
|
+
const speed = typeof options.speed === 'number' && options.speed > 0 ? options.speed : 1;
|
|
62
|
+
const requests = [];
|
|
63
|
+
let next = 0;
|
|
64
|
+
return {
|
|
65
|
+
requests,
|
|
66
|
+
open(req) {
|
|
67
|
+
const { signal, ...seen } = req;
|
|
68
|
+
requests.push(seen);
|
|
69
|
+
const current = scripts[next];
|
|
70
|
+
next += 1;
|
|
71
|
+
if (current === undefined || signal.aborted) {
|
|
72
|
+
return Promise.resolve({ status: 0, error: null, chunks: null, close: () => undefined });
|
|
73
|
+
}
|
|
74
|
+
const events = eventsOf(current);
|
|
75
|
+
if (events === null) {
|
|
76
|
+
const r = current.refusal;
|
|
77
|
+
return Promise.resolve({
|
|
78
|
+
status: r.status,
|
|
79
|
+
error: refusalBody(r.body),
|
|
80
|
+
chunks: null,
|
|
81
|
+
close: () => undefined,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const after = req.lastEventId;
|
|
85
|
+
const selected = typeof after === 'number'
|
|
86
|
+
? events.filter((e) => e.type === 'replay.truncated' || e.seq > after)
|
|
87
|
+
: events;
|
|
88
|
+
let stopped = false;
|
|
89
|
+
const wakers = new Set();
|
|
90
|
+
const stop = () => {
|
|
91
|
+
stopped = true;
|
|
92
|
+
for (const w of wakers)
|
|
93
|
+
w();
|
|
94
|
+
wakers.clear();
|
|
95
|
+
};
|
|
96
|
+
const onAbort = () => stop();
|
|
97
|
+
signal.addEventListener('abort', onAbort);
|
|
98
|
+
async function* frames() {
|
|
99
|
+
try {
|
|
100
|
+
let prev;
|
|
101
|
+
for (const e of selected) {
|
|
102
|
+
await sleep(gapMs(prev, e, speed), (wake) => {
|
|
103
|
+
if (stopped)
|
|
104
|
+
wake();
|
|
105
|
+
else
|
|
106
|
+
wakers.add(wake);
|
|
107
|
+
});
|
|
108
|
+
if (stopped)
|
|
109
|
+
return;
|
|
110
|
+
prev = e;
|
|
111
|
+
yield toSseFrame(e);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
signal.removeEventListener('abort', onAbort);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return Promise.resolve({ status: 200, error: null, chunks: frames(), close: stop });
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=scriptedTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scriptedTransport.js","sourceRoot":"","sources":["../../src/agent/scriptedTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAyB5C,MAAM,YAAY,GAAG,KAAK,CAAC;AAO3B,SAAS,WAAW,CAAC,CAAU;IAC7B,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACrD,MAAM,CAAC,GAAG,CAA4B,CAAC;IACvC,OAAO,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,SAAS,KAAK,SAAS;QACnE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE;QAC1C,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AAED,SAAS,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C,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE;4BAC1C,IAAI,OAAO;gCAAE,IAAI,EAAE,CAAC;;gCACf,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;wBACxB,CAAC,CAAC,CAAC;wBACH,IAAI,OAAO;4BAAE,OAAO;wBACpB,IAAI,GAAG,CAAC,CAAC;wBACT,MAAM,UAAU,CAAC,CAAC,CAAC,CAAC;oBACtB,CAAC;gBACH,CAAC;wBAAS,CAAC;oBACT,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC/C,CAAC;YACH,CAAC;YAED,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACtF,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent stream parser (SPEC `docs/features/agent-read-capabilities/SPEC.md` §3 B, §5
|
|
3
|
+
* frontend-core). Pure and DOM-free: the transport decodes bytes to text (`TextDecoder` with
|
|
4
|
+
* `stream: true`) and pushes the text in whatever chunks arrive; frames, lines and even a CRLF
|
|
5
|
+
* pair may be split anywhere.
|
|
6
|
+
*
|
|
7
|
+
* Framing (§3 B): `id: <seq>\nevent: <type>\ndata: <json>\n\n` per event; `: hb\n\n` heartbeat
|
|
8
|
+
* comments; `replay.truncated` (replay only, first event) has no `id:` line and its envelope
|
|
9
|
+
* `seq` is `firstRetainedSeq − 1`. Lines end with LF, CRLF or CR (the SSE rule); comments and
|
|
10
|
+
* unknown fields are ignored; an unterminated frame at the end of the stream is discarded.
|
|
11
|
+
*
|
|
12
|
+
* Checks per frame (a failing frame is dropped and reported, never applied):
|
|
13
|
+
* - the data is the §3 B envelope (`v: 0`, integer `seq`, `task_…` id, `type`, `ts`, object
|
|
14
|
+
* `payload`) and the `event:` line names the same type;
|
|
15
|
+
* - the `id:` line equals the envelope `seq` (absent only on `replay.truncated`);
|
|
16
|
+
* - the first accepted event sets the stream's `taskId` and base `seq`; every later event has
|
|
17
|
+
* the same `taskId` and the next `seq`; `replay.truncated` is accepted only as the first.
|
|
18
|
+
*/
|
|
19
|
+
import type { AgentStreamEvent, SseDrop } from './types.js';
|
|
20
|
+
/** The heartbeat comment the gateway writes every 15 s (§3 B). */
|
|
21
|
+
export declare const SSE_HEARTBEAT = ": hb\n\n";
|
|
22
|
+
/**
|
|
23
|
+
* The §3 B frame for one envelope, exactly as the gateway writes it (the SSE fixtures are stored
|
|
24
|
+
* as envelopes; their frames are derived with this rule). Used by the scripted transport.
|
|
25
|
+
*/
|
|
26
|
+
export declare function toSseFrame(event: AgentStreamEvent): string;
|
|
27
|
+
export interface SseFrameParser {
|
|
28
|
+
/** Feed the next decoded text chunk; returns the events completed by it, in order. */
|
|
29
|
+
push(text: string): AgentStreamEvent[];
|
|
30
|
+
/** The stream ended: an unterminated frame is discarded (SSE rule). Returns no events. */
|
|
31
|
+
end(): AgentStreamEvent[];
|
|
32
|
+
/** Every refused frame so far, in order. */
|
|
33
|
+
readonly dropped: readonly SseDrop[];
|
|
34
|
+
/** The stream's task id (from the first accepted event), else null. */
|
|
35
|
+
readonly taskId: string | null;
|
|
36
|
+
/** The `seq` of the last accepted event, else null. */
|
|
37
|
+
readonly lastSeq: number | null;
|
|
38
|
+
}
|
|
39
|
+
export interface SseParserOptions {
|
|
40
|
+
/** Called once per refused frame (in addition to `dropped`). Must not throw. */
|
|
41
|
+
readonly onDrop?: (drop: SseDrop) => void;
|
|
42
|
+
}
|
|
43
|
+
/** Create a parser for ONE stream (open, continue or replay). */
|
|
44
|
+
export declare function parseSseFrames(options?: SseParserOptions): SseFrameParser;
|
|
45
|
+
//# sourceMappingURL=sseParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sseParser.d.ts","sourceRoot":"","sources":["../../src/agent/sseParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAiB,MAAM,YAAY,CAAC;AAK3E,kEAAkE;AAClE,eAAO,MAAM,aAAa,aAAa,CAAC;AAExC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAG1D;AAED,MAAM,WAAW,cAAc;IAC7B,sFAAsF;IACtF,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAC;IACvC,0FAA0F;IAC1F,GAAG,IAAI,gBAAgB,EAAE,CAAC;IAC1B,4CAA4C;IAC5C,QAAQ,CAAC,OAAO,EAAE,SAAS,OAAO,EAAE,CAAC;IACrC,uEAAuE;IACvE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,uDAAuD;IACvD,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED,MAAM,WAAW,gBAAgB;IAC/B,gFAAgF;IAChF,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CAC3C;AAMD,iEAAiE;AACjE,wBAAgB,cAAc,CAAC,OAAO,GAAE,gBAAqB,GAAG,cAAc,CAiM7E"}
|