@dbos-inc/vercel-ai 0.1.5 → 0.3.7
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/README.md +111 -87
- package/dist/agent-tool.d.ts +42 -0
- package/dist/agent-tool.d.ts.map +1 -0
- package/dist/agent-tool.js +92 -0
- package/dist/agent-tool.js.map +1 -0
- package/dist/durable-stream.d.ts +112 -0
- package/dist/durable-stream.d.ts.map +1 -0
- package/dist/durable-stream.js +344 -0
- package/dist/durable-stream.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +2 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +15 -0
- package/dist/internal.js.map +1 -1
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +27 -26
- package/dist/mcp.js.map +1 -1
- package/dist/middleware.d.ts +6 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +95 -47
- package/dist/middleware.js.map +1 -1
- package/dist/tools.d.ts +15 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +78 -0
- package/dist/tools.js.map +1 -0
- package/package.json +3 -3
- package/src/agent-tool.ts +122 -0
- package/src/durable-stream.ts +388 -0
- package/src/index.ts +12 -1
- package/src/internal.ts +14 -0
- package/src/mcp.ts +28 -25
- package/src/middleware.ts +103 -50
- package/src/tools.ts +86 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelStreamWriter = void 0;
|
|
4
|
+
exports.resolveDurableStream = resolveDurableStream;
|
|
5
|
+
exports.writeToolRecord = writeToolRecord;
|
|
6
|
+
exports.writeDurableStream = writeDurableStream;
|
|
7
|
+
exports.closeDurableStream = closeDurableStream;
|
|
8
|
+
exports.readDurableStream = readDurableStream;
|
|
9
|
+
const node_crypto_1 = require("node:crypto");
|
|
10
|
+
const dbos_sdk_1 = require("@dbos-inc/dbos-sdk");
|
|
11
|
+
function resolveDurableStream(options) {
|
|
12
|
+
if (options === undefined)
|
|
13
|
+
return undefined;
|
|
14
|
+
const config = typeof options === 'string' ? { key: options } : options;
|
|
15
|
+
return { key: config.key, maxBatchParts: config.maxBatchParts ?? 20, maxBatchDelayMs: config.maxBatchDelayMs ?? 25 };
|
|
16
|
+
}
|
|
17
|
+
function stepInfo() {
|
|
18
|
+
return { step: dbos_sdk_1.DBOS.stepID ?? -1, attempt: dbos_sdk_1.DBOS.stepStatus?.currentAttempt ?? 1 };
|
|
19
|
+
}
|
|
20
|
+
// Parts the reader can render; framing, metadata and terminal parts are recorded elsewhere or not at all.
|
|
21
|
+
function isContentPart(part) {
|
|
22
|
+
switch (part.type) {
|
|
23
|
+
case 'stream-start':
|
|
24
|
+
case 'response-metadata':
|
|
25
|
+
case 'finish':
|
|
26
|
+
case 'error':
|
|
27
|
+
case 'raw':
|
|
28
|
+
return false;
|
|
29
|
+
default:
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Bytes become base64 so a file part stays compact in Postgres.
|
|
34
|
+
function encodePart(part) {
|
|
35
|
+
if (part.type === 'file' && part.data.type === 'data' && part.data.data instanceof Uint8Array) {
|
|
36
|
+
return { ...part, data: { type: 'data', data: Buffer.from(part.data.data).toString('base64') } };
|
|
37
|
+
}
|
|
38
|
+
return part;
|
|
39
|
+
}
|
|
40
|
+
// A transient write error (the SDK already retries offset conflicts) gets a few attempts before it fails the model call.
|
|
41
|
+
async function writeWithRetry(key, record) {
|
|
42
|
+
for (let attempt = 1;; attempt++) {
|
|
43
|
+
try {
|
|
44
|
+
return await dbos_sdk_1.DBOS.writeStream(key, record);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (attempt === 3)
|
|
48
|
+
throw error;
|
|
49
|
+
await new Promise((resolve) => setTimeout(resolve, 100 * attempt));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** Batches a live model step's parts into step-scope stream writes; nothing is written on replay because the step body does not run. */
|
|
54
|
+
class ModelStreamWriter {
|
|
55
|
+
config;
|
|
56
|
+
pending = [];
|
|
57
|
+
chain = Promise.resolve();
|
|
58
|
+
failure;
|
|
59
|
+
timer;
|
|
60
|
+
step = dbos_sdk_1.DBOS.stepID ?? -1;
|
|
61
|
+
// Unique per execution of the step, so a recovered run's re-execution is distinguishable from the crashed one.
|
|
62
|
+
attempt = (0, node_crypto_1.randomUUID)();
|
|
63
|
+
constructor(config) {
|
|
64
|
+
this.config = config;
|
|
65
|
+
}
|
|
66
|
+
push(part) {
|
|
67
|
+
if (!isContentPart(part))
|
|
68
|
+
return;
|
|
69
|
+
this.pending.push(encodePart(part));
|
|
70
|
+
if (this.pending.length >= this.config.maxBatchParts)
|
|
71
|
+
this.flush();
|
|
72
|
+
else
|
|
73
|
+
this.timer ??= setTimeout(() => this.flush(), this.config.maxBatchDelayMs);
|
|
74
|
+
}
|
|
75
|
+
/** Flushes, records how the call ended, and resolves once every write is durable; a write that failed after retries fails the call here. */
|
|
76
|
+
async end(outcome) {
|
|
77
|
+
this.flush();
|
|
78
|
+
this.write({ kind: 'model-end', step: this.step, attempt: this.attempt, ...outcome });
|
|
79
|
+
await this.chain;
|
|
80
|
+
if (this.failure !== undefined)
|
|
81
|
+
throw this.failure;
|
|
82
|
+
}
|
|
83
|
+
/** After a failure: flush what streamed so the record matches what the consumer saw; the stream's end then comes from the workflow's status. */
|
|
84
|
+
async abandon() {
|
|
85
|
+
this.flush();
|
|
86
|
+
await this.chain;
|
|
87
|
+
}
|
|
88
|
+
flush() {
|
|
89
|
+
if (this.timer !== undefined)
|
|
90
|
+
clearTimeout(this.timer);
|
|
91
|
+
this.timer = undefined;
|
|
92
|
+
if (this.pending.length === 0)
|
|
93
|
+
return;
|
|
94
|
+
const parts = this.pending;
|
|
95
|
+
this.pending = [];
|
|
96
|
+
this.write({ kind: 'model', step: this.step, attempt: this.attempt, parts });
|
|
97
|
+
}
|
|
98
|
+
// Every link has a handler, so a rejection can never sit unobserved; after one failure later writes are skipped.
|
|
99
|
+
write(record) {
|
|
100
|
+
this.chain = this.chain
|
|
101
|
+
.then(() => (this.failure === undefined ? writeWithRetry(this.config.key, record) : undefined))
|
|
102
|
+
.catch((error) => {
|
|
103
|
+
this.failure ??= error;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.ModelStreamWriter = ModelStreamWriter;
|
|
108
|
+
/** Records a tool call's outcome from inside its step. */
|
|
109
|
+
function writeToolRecord(key, toolCallId, outcome) {
|
|
110
|
+
const record = { kind: 'tool', ...stepInfo(), toolCallId, ...outcome };
|
|
111
|
+
return dbos_sdk_1.DBOS.writeStream(key, record);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Appends UI message chunks to a durable stream. From a step the write is cheap and at-least-once, so give data parts
|
|
115
|
+
* stable ids; from workflow code it is a checkpointed step, so the number of calls must be deterministic.
|
|
116
|
+
*/
|
|
117
|
+
function writeDurableStream(key, chunks) {
|
|
118
|
+
const status = dbos_sdk_1.DBOS.stepStatus;
|
|
119
|
+
const record = { kind: 'ui', step: status?.stepID, attempt: status?.currentAttempt, chunks };
|
|
120
|
+
return dbos_sdk_1.DBOS.writeStream(key, record);
|
|
121
|
+
}
|
|
122
|
+
/** Marks the end of the turn explicitly and closes the stream; without it the reader infers the end from the last model call or the workflow's status. */
|
|
123
|
+
async function closeDurableStream(key, finishReason = 'stop') {
|
|
124
|
+
const record = { kind: 'end', finishReason };
|
|
125
|
+
await dbos_sdk_1.DBOS.writeStream(key, record);
|
|
126
|
+
await dbos_sdk_1.DBOS.closeStream(key);
|
|
127
|
+
}
|
|
128
|
+
/** Reads a durable stream as AI SDK UI message chunks, live or after the fact, resuming from `offset`. */
|
|
129
|
+
function readDurableStream(options) {
|
|
130
|
+
const iterator = uiChunks(options);
|
|
131
|
+
return new ReadableStream({
|
|
132
|
+
async pull(controller) {
|
|
133
|
+
const { value, done } = await iterator.next();
|
|
134
|
+
if (done)
|
|
135
|
+
controller.close();
|
|
136
|
+
else
|
|
137
|
+
controller.enqueue(value);
|
|
138
|
+
},
|
|
139
|
+
async cancel() {
|
|
140
|
+
await iterator.return(undefined);
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
async function* uiChunks(options) {
|
|
145
|
+
const { workflowID, key, sendReasoning = true, sendSources = false, onError = () => 'An error occurred.' } = options;
|
|
146
|
+
const client = options.client ?? dbos_sdk_1.DBOS;
|
|
147
|
+
const state = {
|
|
148
|
+
offset: options.offset ?? 0,
|
|
149
|
+
resumed: (options.offset ?? 0) > 0,
|
|
150
|
+
openParts: new Map(),
|
|
151
|
+
ended: false,
|
|
152
|
+
};
|
|
153
|
+
if (state.offset === 0)
|
|
154
|
+
yield { type: 'start', messageId: options.messageId };
|
|
155
|
+
const emit = (record) => emitRecord(state, record, { sendReasoning, sendSources, onError });
|
|
156
|
+
// Phase 1: everything already stored, one value per query until an offset is empty; a superseded attempt is skipped whole.
|
|
157
|
+
const history = [];
|
|
158
|
+
for (;;) {
|
|
159
|
+
try {
|
|
160
|
+
history.push(await client.readStreamOffset(workflowID, key, state.offset + history.length, { timeoutSeconds: 0 }));
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
if (!dbos_sdk_1.Error.isStreamTimeoutError(error))
|
|
164
|
+
throw error;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const finalAttempt = new Map();
|
|
169
|
+
for (const record of history) {
|
|
170
|
+
if (record.kind === 'model' || record.kind === 'model-end')
|
|
171
|
+
finalAttempt.set(record.step, record.attempt);
|
|
172
|
+
}
|
|
173
|
+
for (const record of history) {
|
|
174
|
+
const stale = (record.kind === 'model' || record.kind === 'model-end') && finalAttempt.get(record.step) !== record.attempt;
|
|
175
|
+
yield* stale ? skipRecord(state) : emit(record);
|
|
176
|
+
if (state.ended)
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
// Phase 2: live; a re-executed step shows up as a new attempt and is handed off in place.
|
|
180
|
+
for await (const record of client.readStream(workflowID, key, { offset: state.offset })) {
|
|
181
|
+
yield* emit(record);
|
|
182
|
+
if (state.ended)
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
// No end record: the workflow's status decides how the turn ended (a stream closed while it still runs counts as finished).
|
|
186
|
+
const status = (await client.retrieveWorkflow(workflowID).getStatus())?.status;
|
|
187
|
+
yield* closeStep(state);
|
|
188
|
+
if (status === dbos_sdk_1.StatusString.CANCELLED) {
|
|
189
|
+
yield { type: 'abort' };
|
|
190
|
+
}
|
|
191
|
+
else if (status === undefined || status === dbos_sdk_1.StatusString.SUCCESS || status === dbos_sdk_1.StatusString.PENDING || status === dbos_sdk_1.StatusString.ENQUEUED) {
|
|
192
|
+
// The AI SDK's finish schema has no 'unknown'; a turn with no model call ends with the reason omitted.
|
|
193
|
+
yield state.finishReason === undefined ? { type: 'finish' } : { type: 'finish', finishReason: state.finishReason };
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
const error = (await client.retrieveWorkflow(workflowID).getStatus())?.error;
|
|
197
|
+
yield { type: 'error', errorText: onError(error ?? new Error('The workflow ended before the response completed.')) };
|
|
198
|
+
yield { type: 'finish', finishReason: 'error' };
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function offsetChunk(state) {
|
|
202
|
+
return { type: 'data-dbos-offset', data: { offset: state.offset }, transient: true };
|
|
203
|
+
}
|
|
204
|
+
function* skipRecord(state) {
|
|
205
|
+
state.offset += 1;
|
|
206
|
+
yield offsetChunk(state);
|
|
207
|
+
}
|
|
208
|
+
function* closeStep(state) {
|
|
209
|
+
if (state.openStep !== undefined)
|
|
210
|
+
yield { type: 'finish-step' };
|
|
211
|
+
state.openStep = undefined;
|
|
212
|
+
state.openAttempt = undefined;
|
|
213
|
+
state.openParts.clear();
|
|
214
|
+
}
|
|
215
|
+
// A live re-execution of the open step: end the stale attempt's parts and tell the client which ones to discard.
|
|
216
|
+
function* supersede(state, attempt) {
|
|
217
|
+
for (const [id, kind] of state.openParts)
|
|
218
|
+
yield { type: kind === 'text' ? 'text-end' : 'reasoning-end', id };
|
|
219
|
+
yield {
|
|
220
|
+
type: 'data-dbos-superseded',
|
|
221
|
+
data: { attempt: state.openAttempt, parts: [...state.openParts.keys()] },
|
|
222
|
+
transient: true,
|
|
223
|
+
};
|
|
224
|
+
state.openParts.clear();
|
|
225
|
+
state.openAttempt = attempt;
|
|
226
|
+
}
|
|
227
|
+
function* emitRecord(state, record, filter) {
|
|
228
|
+
state.offset += 1;
|
|
229
|
+
switch (record.kind) {
|
|
230
|
+
case 'model': {
|
|
231
|
+
if (state.openStep !== record.step) {
|
|
232
|
+
yield* closeStep(state);
|
|
233
|
+
if (!state.resumed)
|
|
234
|
+
yield { type: 'start-step' };
|
|
235
|
+
state.resumed = false;
|
|
236
|
+
state.openStep = record.step;
|
|
237
|
+
state.openAttempt = record.attempt;
|
|
238
|
+
}
|
|
239
|
+
else if (state.openAttempt !== record.attempt) {
|
|
240
|
+
yield* supersede(state, record.attempt);
|
|
241
|
+
}
|
|
242
|
+
for (const part of record.parts) {
|
|
243
|
+
if (!filter.sendReasoning && part.type.startsWith('reasoning-'))
|
|
244
|
+
continue;
|
|
245
|
+
if (!filter.sendSources && part.type === 'source')
|
|
246
|
+
continue;
|
|
247
|
+
const chunk = toUIChunk(part, record.attempt);
|
|
248
|
+
if (!chunk)
|
|
249
|
+
continue;
|
|
250
|
+
if (chunk.type === 'text-start' || chunk.type === 'reasoning-start')
|
|
251
|
+
state.openParts.set(chunk.id, chunk.type === 'text-start' ? 'text' : 'reasoning');
|
|
252
|
+
if (chunk.type === 'text-end' || chunk.type === 'reasoning-end')
|
|
253
|
+
state.openParts.delete(chunk.id);
|
|
254
|
+
yield chunk;
|
|
255
|
+
}
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
case 'model-end':
|
|
259
|
+
// The stream outlives the call: the workflow may run more calls, so only its end (or closeDurableStream) ends the turn.
|
|
260
|
+
if (record.attempt === state.openAttempt)
|
|
261
|
+
state.finishReason = record.aborted ? 'other' : record.finishReason?.unified;
|
|
262
|
+
break;
|
|
263
|
+
case 'tool':
|
|
264
|
+
// Local tool errors are masked like the AI SDK does; provider-executed ones (in model records) pass through verbatim.
|
|
265
|
+
yield record.errorText !== undefined
|
|
266
|
+
? { type: 'tool-output-error', toolCallId: record.toolCallId, errorText: filter.onError(new Error(record.errorText)) }
|
|
267
|
+
: { type: 'tool-output-available', toolCallId: record.toolCallId, output: record.output };
|
|
268
|
+
break;
|
|
269
|
+
case 'ui':
|
|
270
|
+
yield* record.chunks;
|
|
271
|
+
break;
|
|
272
|
+
case 'end':
|
|
273
|
+
// The terminal chunk comes last, so the offset goes out first.
|
|
274
|
+
yield offsetChunk(state);
|
|
275
|
+
yield* closeStep(state);
|
|
276
|
+
yield { type: 'finish', finishReason: record.finishReason };
|
|
277
|
+
state.ended = true;
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
yield offsetChunk(state);
|
|
281
|
+
}
|
|
282
|
+
function parseInput(input) {
|
|
283
|
+
try {
|
|
284
|
+
return JSON.parse(input);
|
|
285
|
+
}
|
|
286
|
+
catch {
|
|
287
|
+
return input;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
// Text and reasoning ids are only unique within one model call; the attempt id keeps calls, and re-executions, apart in one message.
|
|
291
|
+
function toUIChunk(part, attempt) {
|
|
292
|
+
const id = 'id' in part ? `${attempt}:${part.id}` : '';
|
|
293
|
+
switch (part.type) {
|
|
294
|
+
case 'text-start':
|
|
295
|
+
return { type: 'text-start', id, providerMetadata: part.providerMetadata };
|
|
296
|
+
case 'text-delta':
|
|
297
|
+
return { type: 'text-delta', id, delta: part.delta, providerMetadata: part.providerMetadata };
|
|
298
|
+
case 'text-end':
|
|
299
|
+
return { type: 'text-end', id, providerMetadata: part.providerMetadata };
|
|
300
|
+
case 'reasoning-start':
|
|
301
|
+
return { type: 'reasoning-start', id, providerMetadata: part.providerMetadata };
|
|
302
|
+
case 'reasoning-delta':
|
|
303
|
+
return { type: 'reasoning-delta', id, delta: part.delta, providerMetadata: part.providerMetadata };
|
|
304
|
+
case 'reasoning-end':
|
|
305
|
+
return { type: 'reasoning-end', id, providerMetadata: part.providerMetadata };
|
|
306
|
+
case 'tool-input-start':
|
|
307
|
+
return {
|
|
308
|
+
type: 'tool-input-start',
|
|
309
|
+
toolCallId: part.id,
|
|
310
|
+
toolName: part.toolName,
|
|
311
|
+
providerExecuted: part.providerExecuted,
|
|
312
|
+
dynamic: part.dynamic,
|
|
313
|
+
title: part.title,
|
|
314
|
+
providerMetadata: part.providerMetadata,
|
|
315
|
+
};
|
|
316
|
+
case 'tool-input-delta':
|
|
317
|
+
return { type: 'tool-input-delta', toolCallId: part.id, inputTextDelta: part.delta };
|
|
318
|
+
case 'tool-call':
|
|
319
|
+
return {
|
|
320
|
+
type: 'tool-input-available',
|
|
321
|
+
toolCallId: part.toolCallId,
|
|
322
|
+
toolName: part.toolName,
|
|
323
|
+
input: parseInput(part.input),
|
|
324
|
+
providerExecuted: part.providerExecuted,
|
|
325
|
+
dynamic: part.dynamic,
|
|
326
|
+
providerMetadata: part.providerMetadata,
|
|
327
|
+
};
|
|
328
|
+
case 'tool-result':
|
|
329
|
+
return part.isError
|
|
330
|
+
? { type: 'tool-output-error', toolCallId: part.toolCallId, errorText: JSON.stringify(part.result), providerExecuted: true, dynamic: part.dynamic }
|
|
331
|
+
: { type: 'tool-output-available', toolCallId: part.toolCallId, output: part.result, providerExecuted: true, dynamic: part.dynamic, preliminary: part.preliminary };
|
|
332
|
+
case 'source':
|
|
333
|
+
return part.sourceType === 'url'
|
|
334
|
+
? { type: 'source-url', sourceId: part.id, url: part.url, title: part.title, providerMetadata: part.providerMetadata }
|
|
335
|
+
: { type: 'source-document', sourceId: part.id, mediaType: part.mediaType, title: part.title, filename: part.filename, providerMetadata: part.providerMetadata };
|
|
336
|
+
case 'file': {
|
|
337
|
+
const url = part.data.type === 'url' ? String(part.data.url) : part.data.type === 'data' ? `data:${part.mediaType};base64,${String(part.data.data)}` : undefined;
|
|
338
|
+
return url === undefined ? undefined : { type: 'file', url, mediaType: part.mediaType, providerMetadata: part.providerMetadata };
|
|
339
|
+
}
|
|
340
|
+
default:
|
|
341
|
+
return undefined;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
//# sourceMappingURL=durable-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durable-stream.js","sourceRoot":"","sources":["../src/durable-stream.ts"],"names":[],"mappings":";;;AAsBA,oDAIC;AA6FD,0CAGC;AAMD,gDAIC;AAGD,gDAIC;AA2BD,8CAYC;AAlLD,6CAAyC;AACzC,iDAA6E;AAqB7E,SAAgB,oBAAoB,CAAC,OAAyC;IAC5E,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC5C,MAAM,MAAM,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IACxE,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,aAAa,EAAE,MAAM,CAAC,aAAa,IAAI,EAAE,EAAE,eAAe,EAAE,MAAM,CAAC,eAAe,IAAI,EAAE,EAAE,CAAC;AACvH,CAAC;AAED,SAAS,QAAQ;IACf,OAAO,EAAE,IAAI,EAAE,eAAI,CAAC,MAAM,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,eAAI,CAAC,UAAU,EAAE,cAAc,IAAI,CAAC,EAAE,CAAC;AACpF,CAAC;AAED,0GAA0G;AAC1G,SAAS,aAAa,CAAC,IAA+B;IACpD,QAAQ,IAAI,CAAC,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AM,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,SAAS,WAAW,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;YACjK,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACnI,CAAC;QACD;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export { durableCalls, durableEmbeddingCalls, durableImageCalls } from './middleware';
|
|
1
|
+
export { durableCalls, DurableCallsOptions, durableEmbeddingCalls, durableImageCalls } from './middleware';
|
|
2
2
|
export { durableMCPTools, DurableMCPToolsOptions, MCPClientLike } from './mcp';
|
|
3
|
+
export { durableTools, DurableToolsOptions } from './tools';
|
|
4
|
+
export { closeDurableStream, DurableStreamOptions, DurableStreamRecord, DurableStreamSource, ReadDurableStreamOptions, readDurableStream, writeDurableStream, } from './durable-stream';
|
|
5
|
+
export { agentTool, AgentTool, AgentToolOptions } from './agent-tool';
|
|
3
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC3G,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,EACxB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.durableMCPTools = exports.durableImageCalls = exports.durableEmbeddingCalls = exports.durableCalls = void 0;
|
|
3
|
+
exports.agentTool = exports.writeDurableStream = exports.readDurableStream = exports.closeDurableStream = exports.durableTools = exports.durableMCPTools = exports.durableImageCalls = exports.durableEmbeddingCalls = exports.durableCalls = void 0;
|
|
4
4
|
var middleware_1 = require("./middleware");
|
|
5
5
|
Object.defineProperty(exports, "durableCalls", { enumerable: true, get: function () { return middleware_1.durableCalls; } });
|
|
6
6
|
Object.defineProperty(exports, "durableEmbeddingCalls", { enumerable: true, get: function () { return middleware_1.durableEmbeddingCalls; } });
|
|
7
7
|
Object.defineProperty(exports, "durableImageCalls", { enumerable: true, get: function () { return middleware_1.durableImageCalls; } });
|
|
8
8
|
var mcp_1 = require("./mcp");
|
|
9
9
|
Object.defineProperty(exports, "durableMCPTools", { enumerable: true, get: function () { return mcp_1.durableMCPTools; } });
|
|
10
|
+
var tools_1 = require("./tools");
|
|
11
|
+
Object.defineProperty(exports, "durableTools", { enumerable: true, get: function () { return tools_1.durableTools; } });
|
|
12
|
+
var durable_stream_1 = require("./durable-stream");
|
|
13
|
+
Object.defineProperty(exports, "closeDurableStream", { enumerable: true, get: function () { return durable_stream_1.closeDurableStream; } });
|
|
14
|
+
Object.defineProperty(exports, "readDurableStream", { enumerable: true, get: function () { return durable_stream_1.readDurableStream; } });
|
|
15
|
+
Object.defineProperty(exports, "writeDurableStream", { enumerable: true, get: function () { return durable_stream_1.writeDurableStream; } });
|
|
16
|
+
var agent_tool_1 = require("./agent-tool");
|
|
17
|
+
Object.defineProperty(exports, "agentTool", { enumerable: true, get: function () { return agent_tool_1.agentTool; } });
|
|
10
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2CAA2G;AAAlG,0GAAA,YAAY,OAAA;AAAuB,mHAAA,qBAAqB,OAAA;AAAE,+GAAA,iBAAiB,OAAA;AACpF,6BAA+E;AAAtE,sGAAA,eAAe,OAAA;AACxB,iCAA4D;AAAnD,qGAAA,YAAY,OAAA;AACrB,mDAQ0B;AAPxB,oHAAA,kBAAkB,OAAA;AAKlB,mHAAA,iBAAiB,OAAA;AACjB,oHAAA,kBAAkB,OAAA;AAEpB,2CAAsE;AAA7D,uGAAA,SAAS,OAAA"}
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { StepConfig } from '@dbos-inc/dbos-sdk';
|
|
2
2
|
export declare function isInWorkflowFunction(): boolean;
|
|
3
3
|
export declare function assertNotInTransaction(operation: string): void;
|
|
4
|
+
export declare function runDurableStep<T>(name: string, fn: () => Promise<T>, config: StepConfig): Promise<T>;
|
|
5
|
+
export declare function isAsyncIterable(value: unknown): value is AsyncIterable<unknown>;
|
|
4
6
|
export declare function restoreAISDKErrorIdentity(error: unknown): unknown;
|
|
5
7
|
export declare function withErrorClassification(options: StepConfig): StepConfig;
|
|
6
8
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEtD,wBAAgB,oBAAoB,IAAI,OAAO,CAG9C;AAED,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAI9D;AA2BD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAejE;AAKD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,CAMvE"}
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEtD,wBAAgB,oBAAoB,IAAI,OAAO,CAG9C;AAED,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAI9D;AAGD,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC,CAOpG;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAAC,OAAO,CAAC,CAE/E;AA2BD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAejE;AAKD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,CAMvE"}
|
package/dist/internal.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isInWorkflowFunction = isInWorkflowFunction;
|
|
4
4
|
exports.assertNotInTransaction = assertNotInTransaction;
|
|
5
|
+
exports.runDurableStep = runDurableStep;
|
|
6
|
+
exports.isAsyncIterable = isAsyncIterable;
|
|
5
7
|
exports.restoreAISDKErrorIdentity = restoreAISDKErrorIdentity;
|
|
6
8
|
exports.withErrorClassification = withErrorClassification;
|
|
7
9
|
const dbos_sdk_1 = require("@dbos-inc/dbos-sdk");
|
|
@@ -14,6 +16,19 @@ function assertNotInTransaction(operation) {
|
|
|
14
16
|
throw new Error(`Cannot call ${operation} inside a DBOS transaction; run it in workflow or step code.`);
|
|
15
17
|
}
|
|
16
18
|
}
|
|
19
|
+
// Run fn as a durable step named `name` inside a workflow; elsewhere call it directly.
|
|
20
|
+
function runDurableStep(name, fn, config) {
|
|
21
|
+
assertNotInTransaction(name);
|
|
22
|
+
if (!isInWorkflowFunction())
|
|
23
|
+
return fn();
|
|
24
|
+
// Restore the AI SDK error identity a replay revival strips, so the SDK's retry/catch logic behaves the same.
|
|
25
|
+
return dbos_sdk_1.DBOS.runStep(fn, { ...config, name }).catch((error) => {
|
|
26
|
+
throw restoreAISDKErrorIdentity(error);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function isAsyncIterable(value) {
|
|
30
|
+
return typeof value?.[Symbol.asyncIterator] === 'function';
|
|
31
|
+
}
|
|
17
32
|
// Aborts/timeouts are deliberate cancellations, never transient; retrying just re-runs an already-cancelled call.
|
|
18
33
|
function isAbortError(error) {
|
|
19
34
|
const name = error?.name;
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":";;AAEA,oDAGC;AAED,wDAIC;AA2BD,8DAeC;AAKD,0DAMC;
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":";;AAEA,oDAGC;AAED,wDAIC;AAGD,wCAOC;AAED,0CAEC;AA2BD,8DAeC;AAKD,0DAMC;AA9ED,iDAAsD;AAEtD,SAAgB,oBAAoB;IAClC,kFAAkF;I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fig {
|
|
8
8
|
/** Forwarded to client.tools() on listing and on each call (e.g. { schemas } for subsetting and output schemas). */
|
|
9
9
|
toolOptions?: unknown;
|
|
10
|
+
/** Write each tool call's output (or error) to this durable stream from inside its step. */
|
|
11
|
+
durableStream?: string;
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
14
|
* Wraps an MCP client so its tool listing and each tool call run as durable DBOS steps: the tool
|
package/dist/mcp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC,OAAO,iBAAiB,EAAE,QAAQ,EAAE,CAAC;AAMvE,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3D,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAaD,MAAM,WAAW,sBAAuB,SAAQ,UAAU;IACxD,oHAAoH;IACpH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,4FAA4F;IAC5F,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAiCD;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAE,sBAA2B,GAAG,OAAO,CAAC,OAAO,CAAC,CA4EnH"}
|
package/dist/mcp.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.durableMCPTools = durableMCPTools;
|
|
4
|
-
const dbos_sdk_1 = require("@dbos-inc/dbos-sdk");
|
|
5
4
|
const internal_1 = require("./internal");
|
|
6
|
-
|
|
7
|
-
return typeof value?.[Symbol.asyncIterator] === 'function';
|
|
8
|
-
}
|
|
5
|
+
const durable_stream_1 = require("./durable-stream");
|
|
9
6
|
// Mirror of @ai-sdk/mcp's toModelOutput: MCP content becomes model content (text stays text, images become files).
|
|
10
7
|
function mcpToolOutput(output) {
|
|
11
8
|
const result = output;
|
|
@@ -31,18 +28,10 @@ function mcpToolOutput(output) {
|
|
|
31
28
|
* checkpointed so a recovered workflow replays results instead of re-invoking the tool.
|
|
32
29
|
*/
|
|
33
30
|
async function durableMCPTools(client, options = {}) {
|
|
34
|
-
const { toolOptions, ...stepOptions } = options;
|
|
31
|
+
const { toolOptions, durableStream, ...stepOptions } = options;
|
|
35
32
|
const stepConfig = (0, internal_1.withErrorClassification)(stepOptions);
|
|
36
33
|
const { asSchema, dynamicTool, jsonSchema } = await import('ai');
|
|
37
|
-
const run = (name, fn, config = stepConfig) =>
|
|
38
|
-
(0, internal_1.assertNotInTransaction)(name);
|
|
39
|
-
if (!(0, internal_1.isInWorkflowFunction)())
|
|
40
|
-
return fn();
|
|
41
|
-
// Restore the AI SDK error identity a replay revival strips, so the SDK's retry/catch logic behaves the same.
|
|
42
|
-
return dbos_sdk_1.DBOS.runStep(fn, { ...config, name }).catch((error) => {
|
|
43
|
-
throw (0, internal_1.restoreAISDKErrorIdentity)(error);
|
|
44
|
-
});
|
|
45
|
-
};
|
|
34
|
+
const run = (name, fn, config = stepConfig) => (0, internal_1.runDurableStep)(name, fn, config);
|
|
46
35
|
// Checkpoint the tool list as plain JSON schemas, so replay reconstructs tools without the live client.
|
|
47
36
|
const listed = await run('mcp.listTools', async () => {
|
|
48
37
|
const tools = await client.tools(toolOptions);
|
|
@@ -72,24 +61,36 @@ async function durableMCPTools(client, options = {}) {
|
|
|
72
61
|
toModelOutput: def.convertsOutput ? ({ output }) => mcpToolOutput(output) : undefined,
|
|
73
62
|
// Re-fetch the live tool inside the step (its execute closure can't be checkpointed); replay returns the recorded result.
|
|
74
63
|
execute: (input, execOptions) => {
|
|
75
|
-
const signal = execOptions
|
|
64
|
+
const { abortSignal: signal, toolCallId } = (execOptions ?? {});
|
|
76
65
|
// An aborted consumer is done with this call, whatever the failure looks like; a retry would re-run a cancelled side effect.
|
|
77
66
|
const callConfig = {
|
|
78
67
|
...stepConfig,
|
|
79
68
|
shouldRetry: async (error) => !signal?.aborted && (stepConfig.shouldRetry ? await stepConfig.shouldRetry(error) : true),
|
|
80
69
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
70
|
+
// The tool call id comes from the checkpointed model result, so a reordered parallel step fails replay instead of swapping results.
|
|
71
|
+
return run(`mcp.tool.${name}.${toolCallId ?? 'call'}`, async () => {
|
|
72
|
+
let output;
|
|
73
|
+
try {
|
|
74
|
+
const tool = (await client.tools(toolOptions))[name];
|
|
75
|
+
if (typeof tool?.execute !== 'function')
|
|
76
|
+
throw new Error(`MCP tool "${name}" is not executable.`);
|
|
77
|
+
output = await tool.execute(input, execOptions);
|
|
78
|
+
// A streaming execute can't checkpoint mid-flight; drain it and record the final value (the last yield).
|
|
79
|
+
if ((0, internal_1.isAsyncIterable)(output)) {
|
|
80
|
+
let last;
|
|
81
|
+
for await (last of output)
|
|
82
|
+
;
|
|
83
|
+
output = last;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (durableStream && toolCallId) {
|
|
88
|
+
await (0, durable_stream_1.writeToolRecord)(durableStream, toolCallId, { errorText: error instanceof Error ? error.message : String(error) });
|
|
89
|
+
}
|
|
90
|
+
throw error;
|
|
92
91
|
}
|
|
92
|
+
if (durableStream && toolCallId)
|
|
93
|
+
await (0, durable_stream_1.writeToolRecord)(durableStream, toolCallId, { output });
|
|
93
94
|
return output;
|
|
94
95
|
}, callConfig);
|
|
95
96
|
},
|
package/dist/mcp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":";;AAkEA,0CA4EC;AA5ID,yCAAsF;AACtF,qDAAmD;AAsCnD,mHAAmH;AACnH,SAAS,aAAa,CAAC,MAAe;IACpC,MAAM,MAAM,GAAG,MAA+B,CAAC;IAC/C,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACpF,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAqB,CAAC;IAC5D,CAAC;IACD,OAAO;QACL,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAwE,EAAE,EAAE;YACrG,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC1D,OAAO,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;YACpD,CAAC;YACD,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;gBACpF,OAAO,EAAE,IAAI,EAAE,MAAe,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;YAC/G,CAAC;YAC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K,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7G,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/middleware.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { StepConfig } from '@dbos-inc/dbos-sdk';
|
|
2
2
|
import type { EmbeddingModelMiddleware, ImageModelMiddleware, LanguageModelMiddleware } from 'ai' with { 'resolution-mode': 'import' };
|
|
3
|
+
import { type DurableStreamOptions } from './durable-stream';
|
|
4
|
+
export interface DurableCallsOptions extends StepConfig {
|
|
5
|
+
/** Write each streamed model call's parts to this durable stream from inside its step (see readDurableStream). */
|
|
6
|
+
durableStream?: DurableStreamOptions;
|
|
7
|
+
}
|
|
3
8
|
/** AI SDK language-model middleware that runs each model call as a durable, checkpointed DBOS step (replayed on recovery); outside a workflow it calls the model directly. */
|
|
4
|
-
export declare function durableCalls(options?:
|
|
9
|
+
export declare function durableCalls(options?: DurableCallsOptions): LanguageModelMiddleware;
|
|
5
10
|
/** AI SDK embedding-model middleware that runs each embedding call as a durable DBOS step, like {@link durableCalls}. */
|
|
6
11
|
export declare function durableEmbeddingCalls(options?: StepConfig): EmbeddingModelMiddleware;
|
|
7
12
|
/**
|
package/dist/middleware.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAItD,OAAO,KAAK,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,IAAI,CAAC,OAAO,iBAAiB,EAAE,QAAQ,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAItD,OAAO,KAAK,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,IAAI,CAAC,OAAO,iBAAiB,EAAE,QAAQ,EAAE,CAAC;AAkBvI,OAAO,EAAE,KAAK,oBAAoB,EAA2C,MAAM,kBAAkB,CAAC;AAEtG,MAAM,WAAW,mBAAoB,SAAQ,UAAU;IACrD,kHAAkH;IAClH,aAAa,CAAC,EAAE,oBAAoB,CAAC;CACtC;AA8BD,8KAA8K;AAC9K,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,uBAAuB,CA2MvF;AAED,yHAAyH;AACzH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,UAAe,GAAG,wBAAwB,CA2BxF;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,UAAe,GAAG,oBAAoB,CAmBhF"}
|