taugraph 0.2.0 → 0.4.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 +89 -0
- package/README.md +283 -22
- package/README.zh-CN.md +283 -22
- package/dist/agent/index.d.ts +74 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +254 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/state.d.ts +30 -0
- package/dist/agent/state.d.ts.map +1 -0
- package/dist/agent/state.js +135 -0
- package/dist/agent/state.js.map +1 -0
- package/dist/agent/util.d.ts +19 -0
- package/dist/agent/util.d.ts.map +1 -0
- package/dist/agent/util.js +59 -0
- package/dist/agent/util.js.map +1 -0
- package/dist/core/engine.d.ts +1 -1
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/core/engine.js +237 -35
- package/dist/core/engine.js.map +1 -1
- package/dist/core/errors.d.ts +2 -0
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js.map +1 -1
- package/dist/core/graph.d.ts.map +1 -1
- package/dist/core/graph.js +9 -1
- package/dist/core/graph.js.map +1 -1
- package/dist/core/node.d.ts +6 -1
- package/dist/core/node.d.ts.map +1 -1
- package/dist/core/node.js +55 -6
- package/dist/core/node.js.map +1 -1
- package/dist/core/patch.d.ts +26 -0
- package/dist/core/patch.d.ts.map +1 -0
- package/dist/core/patch.js +192 -0
- package/dist/core/patch.js.map +1 -0
- package/dist/core/retry.d.ts +20 -0
- package/dist/core/retry.d.ts.map +1 -0
- package/dist/core/retry.js +79 -0
- package/dist/core/retry.js.map +1 -0
- package/dist/core/trace.d.ts +39 -8
- package/dist/core/trace.d.ts.map +1 -1
- package/dist/core/trace.js +222 -29
- package/dist/core/trace.js.map +1 -1
- package/dist/core/types.d.ts +35 -4
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/util.d.ts +5 -1
- package/dist/core/util.d.ts.map +1 -1
- package/dist/core/util.js +41 -9
- package/dist/core/util.js.map +1 -1
- package/dist/file/index.d.ts +26 -0
- package/dist/file/index.d.ts.map +1 -0
- package/dist/file/index.js +373 -0
- package/dist/file/index.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/nodes/code.d.ts +5 -0
- package/dist/nodes/code.d.ts.map +1 -1
- package/dist/nodes/code.js.map +1 -1
- package/dist/nodes/content.d.ts +18 -0
- package/dist/nodes/content.d.ts.map +1 -0
- package/dist/nodes/content.js +88 -0
- package/dist/nodes/content.js.map +1 -0
- package/dist/nodes/index.d.ts +2 -1
- package/dist/nodes/index.d.ts.map +1 -1
- package/dist/nodes/index.js +1 -0
- package/dist/nodes/index.js.map +1 -1
- package/dist/nodes/llm.d.ts +100 -4
- package/dist/nodes/llm.d.ts.map +1 -1
- package/dist/nodes/llm.js +5 -1
- package/dist/nodes/llm.js.map +1 -1
- package/dist/openai/index.d.ts +55 -0
- package/dist/openai/index.d.ts.map +1 -0
- package/dist/openai/index.js +208 -0
- package/dist/openai/index.js.map +1 -0
- package/package.json +20 -4
- package/src/agent/index.ts +359 -0
- package/src/agent/state.ts +147 -0
- package/src/agent/util.ts +74 -0
- package/src/core/engine.ts +241 -34
- package/src/core/errors.ts +2 -0
- package/src/core/graph.ts +7 -1
- package/src/core/node.ts +55 -6
- package/src/core/patch.ts +173 -0
- package/src/core/retry.ts +89 -0
- package/src/core/trace.ts +222 -29
- package/src/core/types.ts +37 -4
- package/src/core/util.ts +43 -10
- package/src/file/index.ts +408 -0
- package/src/index.ts +5 -1
- package/src/nodes/code.ts +5 -0
- package/src/nodes/content.ts +100 -0
- package/src/nodes/index.ts +10 -0
- package/src/nodes/llm.ts +109 -7
- package/src/openai/index.ts +286 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Trace, type TraceEvent } from "../index.js";
|
|
2
|
+
/** When to fsync: around write steps, pauses and the end of a run (default), after every event, or never. */
|
|
3
|
+
export type Durability = "writes" | "every" | "none";
|
|
4
|
+
export interface FileStoreOptions {
|
|
5
|
+
readonly durability?: Durability | undefined;
|
|
6
|
+
}
|
|
7
|
+
/** `running`: a live process holds the run's lock. `interrupted`: no `run_end` and nobody is writing it. */
|
|
8
|
+
export type StoredRunStatus = "running" | "interrupted" | "paused" | "completed" | "failed";
|
|
9
|
+
export interface StoredRun {
|
|
10
|
+
readonly runId: string;
|
|
11
|
+
readonly status: StoredRunStatus;
|
|
12
|
+
readonly events: number;
|
|
13
|
+
/** Last change of the file, in ms since epoch. */
|
|
14
|
+
readonly updatedAt: number;
|
|
15
|
+
}
|
|
16
|
+
export interface FileStore {
|
|
17
|
+
readonly dir: string;
|
|
18
|
+
/** Pass as `onEvent`. Appends each event before the run continues. */
|
|
19
|
+
readonly sink: (event: TraceEvent) => void;
|
|
20
|
+
/** The stored trace without a half-written last line; undefined if there is no complete line. Never writes. */
|
|
21
|
+
load(runId: string): Trace | undefined;
|
|
22
|
+
/** Every run in the directory, oldest change first. Files that cannot be read are skipped. */
|
|
23
|
+
list(): StoredRun[];
|
|
24
|
+
}
|
|
25
|
+
export declare function fileStore(dir: string, options?: FileStoreOptions): FileStore;
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAmBA,OAAO,EAA4C,KAAK,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAEpG,6GAA6G;AAC7G,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAErD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;CAC9C;AAED,4GAA4G;AAC5G,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,aAAa,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE5F,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,kDAAkD;IAClD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IAC3C,+GAA+G;IAC/G,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAAC;IACvC,8FAA8F;IAC9F,IAAI,IAAI,SAAS,EAAE,CAAC;CACrB;AAsND,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,SAAS,CAkJhF"}
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
// taugraph/file: one append-only JSONL file per run (format v2), written before each step goes on, with a lock per
|
|
2
|
+
// run and a repair for the half-written last line a crash leaves. Uses node:fs, so it runs on Node, Bun and Deno;
|
|
3
|
+
// the kernel itself stays platform-free.
|
|
4
|
+
import { closeSync, existsSync, fsyncSync, ftruncateSync, linkSync, mkdirSync, openSync, readdirSync, readFileSync, statSync, unlinkSync, writeFileSync, writeSync, } from "node:fs";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
6
|
+
import { createTraceEncoder, fromJSONL, runStatus } from "../index.js";
|
|
7
|
+
const RUN_ID = /^[A-Za-z0-9_-][A-Za-z0-9._-]{0,127}$/;
|
|
8
|
+
function checkRunId(runId) {
|
|
9
|
+
if (!RUN_ID.test(runId))
|
|
10
|
+
throw new TypeError(`Invalid runId "${runId.slice(0, 40)}"`);
|
|
11
|
+
}
|
|
12
|
+
/** Whether a process with this id exists. EPERM means it does, under another user. */
|
|
13
|
+
function alive(pid) {
|
|
14
|
+
try {
|
|
15
|
+
process.kill(pid, 0);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
return error.code === "EPERM";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function codeOf(error) {
|
|
23
|
+
return error?.code;
|
|
24
|
+
}
|
|
25
|
+
/** The process id a lock file holds, if its content is one. */
|
|
26
|
+
function pidIn(content) {
|
|
27
|
+
const text = content.trim();
|
|
28
|
+
return /^\d+$/.test(text) && Number(text) > 0 ? Number(text) : undefined;
|
|
29
|
+
}
|
|
30
|
+
/** Lock files (absolute paths) this thread holds; released if the process exits while a run is still open. */
|
|
31
|
+
const held = new Set();
|
|
32
|
+
let releaseOnExit = false;
|
|
33
|
+
/** When this process started, in ms since epoch. Process-wide on Node; on Bun and Deno each thread computes its own. */
|
|
34
|
+
const started = Date.now() - process.uptime() * 1000;
|
|
35
|
+
/** Slack for the lock's mtime: FAT stores mtimes in 2-second steps. */
|
|
36
|
+
const MTIME_STEP = 2000;
|
|
37
|
+
/**
|
|
38
|
+
* Age after which a lock without a process id is stale. A lock is empty for a moment while it is created on a file
|
|
39
|
+
* system without hard links, and for good if a power cut came before its content reached the disk.
|
|
40
|
+
*/
|
|
41
|
+
const NO_PID_STALE = 10_000;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the process that wrote a lock is still writing the run. A lock with this process's id that this thread
|
|
44
|
+
* does not hold is live if it was written since this process started (another thread or store of this process),
|
|
45
|
+
* give or take one FAT mtime step; an older one was left by an earlier process that had the same id (e.g. a
|
|
46
|
+
* restarted container).
|
|
47
|
+
*/
|
|
48
|
+
function isLive(lock, pid) {
|
|
49
|
+
if (pid !== process.pid)
|
|
50
|
+
return alive(pid);
|
|
51
|
+
if (held.has(lock))
|
|
52
|
+
return true;
|
|
53
|
+
try {
|
|
54
|
+
return statSync(lock).mtimeMs >= started - MTIME_STEP;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return false; // gone
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Whether a lock with this content keeps its run from being written: a live holder, or no process id for under 10 s. */
|
|
61
|
+
function holds(lock, content) {
|
|
62
|
+
const pid = pidIn(content);
|
|
63
|
+
if (pid !== undefined)
|
|
64
|
+
return isLive(lock, pid);
|
|
65
|
+
try {
|
|
66
|
+
return statSync(lock).mtimeMs >= Date.now() - NO_PID_STALE;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return false; // gone
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** Whether a lock keeps its run from being written. */
|
|
73
|
+
function locked(lock) {
|
|
74
|
+
try {
|
|
75
|
+
return holds(lock, readFileSync(lock, "utf8"));
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return false; // no lock
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function hold(lock) {
|
|
82
|
+
held.add(lock);
|
|
83
|
+
if (releaseOnExit)
|
|
84
|
+
return;
|
|
85
|
+
releaseOnExit = true;
|
|
86
|
+
process.once("exit", () => {
|
|
87
|
+
for (const path of [...held])
|
|
88
|
+
releaseLock(path);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/** Removes a lock this thread holds, unless it no longer holds this process's id (another process took it over). */
|
|
92
|
+
function releaseLock(lock) {
|
|
93
|
+
if (!held.delete(lock))
|
|
94
|
+
return;
|
|
95
|
+
try {
|
|
96
|
+
if (readFileSync(lock, "utf8") === String(process.pid))
|
|
97
|
+
unlinkSync(lock);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// already gone
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function unlinkQuietly(path) {
|
|
104
|
+
try {
|
|
105
|
+
unlinkSync(path);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// already gone
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** A file's text, or undefined if it does not exist. */
|
|
112
|
+
function readIfExists(path) {
|
|
113
|
+
try {
|
|
114
|
+
return readFileSync(path, "utf8");
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
if (codeOf(error) === "ENOENT")
|
|
118
|
+
return undefined;
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const suffix = () => `${process.pid}.${Math.random().toString(36).slice(2, 10)}`;
|
|
123
|
+
/** What `linkSync` throws on a file system without hard links (FAT, exFAT, some SMB and FUSE mounts). */
|
|
124
|
+
const NO_HARD_LINKS = new Set(["ENOTSUP", "EOPNOTSUPP", "EPERM", "ENOSYS"]);
|
|
125
|
+
/**
|
|
126
|
+
* Creates the lock with this process's id in one step, so nobody can see it empty. Without hard links it is created
|
|
127
|
+
* and then written, and may be seen empty for a moment: an empty lock is refused until it is 10 s old. False if it
|
|
128
|
+
* exists.
|
|
129
|
+
*/
|
|
130
|
+
function link(lock) {
|
|
131
|
+
const temp = `${lock}.${suffix()}`;
|
|
132
|
+
try {
|
|
133
|
+
writeFileSync(temp, String(process.pid), { flag: "wx" });
|
|
134
|
+
try {
|
|
135
|
+
linkSync(temp, lock);
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
if (codeOf(error) === "EEXIST")
|
|
140
|
+
return false;
|
|
141
|
+
if (!NO_HARD_LINKS.has(codeOf(error) ?? ""))
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
unlinkQuietly(temp);
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
writeFileSync(lock, String(process.pid), { flag: "wx" });
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
if (codeOf(error) === "EEXIST")
|
|
154
|
+
return false;
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Removes a stale lock that holds `stale`. One process at a time does this, holding `<lock>.takeover`; it removes the
|
|
160
|
+
* lock only if it still holds that content and is still stale, so a lock another process created after it was judged
|
|
161
|
+
* is kept.
|
|
162
|
+
*/
|
|
163
|
+
function takeOver(runId, lock, stale) {
|
|
164
|
+
const mutex = `${lock}.takeover`;
|
|
165
|
+
try {
|
|
166
|
+
writeFileSync(mutex, String(process.pid), { flag: "wx" });
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
if (codeOf(error) !== "EEXIST")
|
|
170
|
+
throw error;
|
|
171
|
+
throw new Error(`Run "${runId}" is being taken over by another process (remove ${mutex} if none is)`);
|
|
172
|
+
}
|
|
173
|
+
try {
|
|
174
|
+
if (readIfExists(lock) === stale && !holds(lock, stale))
|
|
175
|
+
unlinkSync(lock);
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
unlinkQuietly(mutex);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/** The bytes up to and including the last newline. A line after it was cut short by a crash and never took effect. */
|
|
182
|
+
function completeLines(bytes) {
|
|
183
|
+
return bytes.subarray(0, bytes.lastIndexOf(10) + 1);
|
|
184
|
+
}
|
|
185
|
+
/** The trace in a file's complete lines, or undefined if there are none. */
|
|
186
|
+
function traceOf(complete) {
|
|
187
|
+
return complete.length === 0 ? undefined : fromJSONL(new TextDecoder().decode(complete));
|
|
188
|
+
}
|
|
189
|
+
const utf8 = new TextEncoder();
|
|
190
|
+
/** Writes every byte: `writeSync` may write fewer than it was given. */
|
|
191
|
+
function writeAll(fd, text) {
|
|
192
|
+
const bytes = utf8.encode(text);
|
|
193
|
+
let offset = 0;
|
|
194
|
+
while (offset < bytes.length) {
|
|
195
|
+
const written = writeSync(fd, bytes, offset);
|
|
196
|
+
if (written === 0)
|
|
197
|
+
throw new Error("write made no progress");
|
|
198
|
+
offset += written;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/** Makes a new file's directory entry durable. Not every system can fsync a directory. */
|
|
202
|
+
function syncDir(dir) {
|
|
203
|
+
try {
|
|
204
|
+
const fd = openSync(dir, "r");
|
|
205
|
+
try {
|
|
206
|
+
fsyncSync(fd);
|
|
207
|
+
}
|
|
208
|
+
finally {
|
|
209
|
+
closeSync(fd);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
// not supported here
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
export function fileStore(dir, options = {}) {
|
|
217
|
+
const durability = options.durability ?? "writes";
|
|
218
|
+
const writing = new Map();
|
|
219
|
+
const fileOf = (runId) => join(dir, `${runId}.jsonl`);
|
|
220
|
+
// Absolute, so every store for this directory, however it is written, agrees on which locks this thread holds.
|
|
221
|
+
const lockOf = (runId) => resolve(dir, `${runId}.lock`);
|
|
222
|
+
function acquire(runId) {
|
|
223
|
+
const lock = lockOf(runId);
|
|
224
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
225
|
+
if (link(lock)) {
|
|
226
|
+
hold(lock);
|
|
227
|
+
return lock;
|
|
228
|
+
}
|
|
229
|
+
const content = readIfExists(lock);
|
|
230
|
+
if (content === undefined)
|
|
231
|
+
continue; // released in the meantime
|
|
232
|
+
if (holds(lock, content)) {
|
|
233
|
+
const pid = pidIn(content);
|
|
234
|
+
if (pid === undefined) {
|
|
235
|
+
throw new Error(`Run "${runId}" has a lock file without a process id (${lock}); remove it if no process is writing the run`);
|
|
236
|
+
}
|
|
237
|
+
throw new Error(`Run "${runId}" is being written by process ${pid} (${lock})`);
|
|
238
|
+
}
|
|
239
|
+
takeOver(runId, lock, content);
|
|
240
|
+
}
|
|
241
|
+
throw new Error(`Run "${runId}" is being written by another process`);
|
|
242
|
+
}
|
|
243
|
+
function release(runId, w) {
|
|
244
|
+
writing.delete(runId);
|
|
245
|
+
try {
|
|
246
|
+
closeSync(w.fd);
|
|
247
|
+
}
|
|
248
|
+
finally {
|
|
249
|
+
releaseLock(w.lock);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/** Opens a new run's file. One with no complete line is what a crash right after creating it leaves: start over. */
|
|
253
|
+
function create(path, runId) {
|
|
254
|
+
try {
|
|
255
|
+
return openSync(path, "ax");
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
if (codeOf(error) !== "EEXIST")
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
if (completeLines(readFileSync(path)).length > 0)
|
|
262
|
+
throw new Error(`Run "${runId}" already exists in ${dir}`);
|
|
263
|
+
unlinkSync(path);
|
|
264
|
+
return openSync(path, "ax");
|
|
265
|
+
}
|
|
266
|
+
function open(event) {
|
|
267
|
+
checkRunId(event.runId);
|
|
268
|
+
mkdirSync(dir, { recursive: true });
|
|
269
|
+
const path = fileOf(event.runId);
|
|
270
|
+
const noFile = () => new Error(`Run "${event.runId}" has no file in ${dir} to continue`);
|
|
271
|
+
const lock = acquire(event.runId);
|
|
272
|
+
let fd;
|
|
273
|
+
try {
|
|
274
|
+
if (event.seq === 0) {
|
|
275
|
+
fd = create(path, event.runId);
|
|
276
|
+
if (durability !== "none")
|
|
277
|
+
syncDir(dir);
|
|
278
|
+
return { fd, lock, encoder: createTraceEncoder(), next: 0 };
|
|
279
|
+
}
|
|
280
|
+
if (!existsSync(path))
|
|
281
|
+
throw noFile();
|
|
282
|
+
fd = openSync(path, "a");
|
|
283
|
+
const bytes = readFileSync(path);
|
|
284
|
+
const complete = completeLines(bytes);
|
|
285
|
+
const prefix = traceOf(complete);
|
|
286
|
+
if (!prefix)
|
|
287
|
+
throw noFile();
|
|
288
|
+
const last = prefix[prefix.length - 1].seq;
|
|
289
|
+
if (last !== event.seq - 1) {
|
|
290
|
+
throw new Error(`Run "${event.runId}" on disk ends at seq ${last}, but the next event is seq ${event.seq}`);
|
|
291
|
+
}
|
|
292
|
+
// Cut the torn tail only after the checks, so a refused continuation leaves the file as it is.
|
|
293
|
+
if (complete.length < bytes.length)
|
|
294
|
+
ftruncateSync(fd, complete.length);
|
|
295
|
+
return { fd, lock, encoder: createTraceEncoder(prefix), next: event.seq };
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
try {
|
|
299
|
+
if (fd !== undefined)
|
|
300
|
+
closeSync(fd);
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
// keep the original error
|
|
304
|
+
}
|
|
305
|
+
releaseLock(lock);
|
|
306
|
+
throw error;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
const sink = (event) => {
|
|
310
|
+
let w = writing.get(event.runId);
|
|
311
|
+
if (!w) {
|
|
312
|
+
w = open(event);
|
|
313
|
+
writing.set(event.runId, w);
|
|
314
|
+
}
|
|
315
|
+
// Not released: the entry may belong to another run with the same id that is still going in this process.
|
|
316
|
+
if (event.seq !== w.next)
|
|
317
|
+
throw new Error(`Run "${event.runId}" expected seq ${w.next}, got ${event.seq}`);
|
|
318
|
+
try {
|
|
319
|
+
writeAll(w.fd, `${w.encoder.encode(event)}\n`);
|
|
320
|
+
w.next++;
|
|
321
|
+
const critical = event.type === "pause" ||
|
|
322
|
+
event.type === "run_end" ||
|
|
323
|
+
(event.type === "enter" && event.meta?.effect === "write");
|
|
324
|
+
if (durability === "every" || (durability === "writes" && critical))
|
|
325
|
+
fsyncSync(w.fd);
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
// ENOSPC, EIO: the run ends here and the kernel will not send its run_end. Free the run, so a resume opens the
|
|
329
|
+
// file again and cuts what was half written.
|
|
330
|
+
try {
|
|
331
|
+
release(event.runId, w);
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
// keep the original error
|
|
335
|
+
}
|
|
336
|
+
throw error;
|
|
337
|
+
}
|
|
338
|
+
if (event.type === "run_end")
|
|
339
|
+
release(event.runId, w);
|
|
340
|
+
};
|
|
341
|
+
return {
|
|
342
|
+
dir,
|
|
343
|
+
sink,
|
|
344
|
+
load(runId) {
|
|
345
|
+
checkRunId(runId);
|
|
346
|
+
const path = fileOf(runId);
|
|
347
|
+
return existsSync(path) ? traceOf(completeLines(readFileSync(path))) : undefined;
|
|
348
|
+
},
|
|
349
|
+
list() {
|
|
350
|
+
if (!existsSync(dir))
|
|
351
|
+
return [];
|
|
352
|
+
return readdirSync(dir)
|
|
353
|
+
.filter((name) => name.endsWith(".jsonl") && RUN_ID.test(name.slice(0, -".jsonl".length)))
|
|
354
|
+
.flatMap((name) => {
|
|
355
|
+
const runId = name.slice(0, -".jsonl".length);
|
|
356
|
+
const path = join(dir, name);
|
|
357
|
+
try {
|
|
358
|
+
const trace = traceOf(completeLines(readFileSync(path)));
|
|
359
|
+
if (!trace)
|
|
360
|
+
return [];
|
|
361
|
+
const status = runStatus(trace);
|
|
362
|
+
const stored = status !== "running" ? status : locked(lockOf(runId)) ? "running" : "interrupted";
|
|
363
|
+
return [{ runId, status: stored, events: trace.length, updatedAt: statSync(path).mtimeMs }];
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
366
|
+
return [];
|
|
367
|
+
}
|
|
368
|
+
})
|
|
369
|
+
.sort((a, b) => a.updatedAt - b.updatedAt);
|
|
370
|
+
},
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,kHAAkH;AAClH,yCAAyC;AACzC,OAAO,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,aAAa,EACb,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,aAAa,EACb,SAAS,GACV,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,SAAS,EAA+B,MAAM,aAAa,CAAC;AA8BpG,MAAM,MA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C,MAAM,CAAC,CAAC,CAAC;iBACzF,OAAO,CAAC,CAAC,IAAI,EAAe,EAAE;gBAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;gBAC9C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;gBAC7B,IAAI,CAAC;oBACH,MAAM,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;oBACzD,IAAI,CAAC,KAAK;wBAAE,OAAO,EAAE,CAAC;oBACtB,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;oBAChC,MAAM,MAAM,GACV,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC;oBACpF,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;gBAC9F,CAAC;gBAAC,MAAM,CAAC;oBACP,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC;iBACD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;QAC/C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ export type { TaugraphErrorCode, TaugraphErrorDetails } from "./core/errors.js";
|
|
|
2
2
|
export { isTaugraphError, TaugraphError } from "./core/errors.js";
|
|
3
3
|
export { createGraph } from "./core/graph.js";
|
|
4
4
|
export { defineNode } from "./core/node.js";
|
|
5
|
+
export { isRetryable } from "./core/retry.js";
|
|
5
6
|
export type { StandardSchemaV1 } from "./core/standard-schema.js";
|
|
6
|
-
export type { RecordedStep, TraceDiff } from "./core/trace.js";
|
|
7
|
-
export { assertTrace, diffTraces, fromJSONL, recordedSteps, TRACE_FORMAT, TRACE_VERSION, toJSONL, tracePath, } from "./core/trace.js";
|
|
8
|
-
export type { CompletedRun, ConditionalEdge, Edge, Effect, Graph, GraphDefinition, KernelEventType, MaybePromise, Node, NodeFn, NodeMeta, PausedRun, Pending, PluginEvent, PluginEventType, ReplayMode, ReplayOptions, ResumeOptions, RetryPolicy, RunContext, RunOptions, RunResult, Trace, TraceEvent, TraceEventType, } from "./core/types.js";
|
|
7
|
+
export type { RecordedStep, RunStatus, TraceDiff } from "./core/trace.js";
|
|
8
|
+
export { assertTrace, createTraceEncoder, diffTraces, fromJSONL, recordedSteps, runStatus, TRACE_FORMAT, TRACE_VERSION, toJSONL, tracePath, } from "./core/trace.js";
|
|
9
|
+
export type { CompletedRun, ConditionalEdge, Edge, Effect, Graph, GraphDefinition, KernelEventType, MaybePromise, Node, NodeFn, NodeMeta, PausedRun, Pending, PluginEvent, PluginEventType, ReplayMode, ReplayOptions, ResumeOptions, RetryBackoff, RetryPolicy, RunContext, RunOptions, RunResult, Trace, TraceEvent, TraceEventType, } from "./core/types.js";
|
|
9
10
|
//# 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":"AAGA,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,SAAS,EACT,aAAa,EACb,SAAS,EACT,YAAY,EACZ,aAAa,EACb,OAAO,EACP,SAAS,GACV,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,YAAY,EACZ,eAAe,EACf,IAAI,EACJ,MAAM,EACN,KAAK,EACL,eAAe,EACf,eAAe,EACf,YAAY,EACZ,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,SAAS,EACT,OAAO,EACP,WAAW,EACX,eAAe,EACf,UAAU,EACV,aAAa,EACb,aAAa,EACb,YAAY,EACZ,WAAW,EACX,UAAU,EACV,UAAU,EACV,SAAS,EACT,KAAK,EACL,UAAU,EACV,cAAc,GACf,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,5 +3,6 @@
|
|
|
3
3
|
export { isTaugraphError, TaugraphError } from "./core/errors.js";
|
|
4
4
|
export { createGraph } from "./core/graph.js";
|
|
5
5
|
export { defineNode } from "./core/node.js";
|
|
6
|
-
export {
|
|
6
|
+
export { isRetryable } from "./core/retry.js";
|
|
7
|
+
export { assertTrace, createTraceEncoder, diffTraces, fromJSONL, recordedSteps, runStatus, TRACE_FORMAT, TRACE_VERSION, toJSONL, tracePath, } from "./core/trace.js";
|
|
7
8
|
//# 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,8EAA8E;AAC9E,+FAA+F;AAG/F,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,+FAA+F;AAG/F,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,SAAS,EACT,aAAa,EACb,SAAS,EACT,YAAY,EACZ,aAAa,EACb,OAAO,EACP,SAAS,GACV,MAAM,iBAAiB,CAAC"}
|
package/dist/nodes/code.d.ts
CHANGED
|
@@ -3,6 +3,11 @@ export interface CodeNodeOptions {
|
|
|
3
3
|
readonly retry?: RetryPolicy;
|
|
4
4
|
/** Declare `"write"` for code that changes the outside world, so replay will not repeat it. */
|
|
5
5
|
readonly effect?: Effect;
|
|
6
|
+
/**
|
|
7
|
+
* Milliseconds an async node may take; then it fails with TIMEOUT and `ctx.signal` aborts. Synchronous code cannot
|
|
8
|
+
* be interrupted.
|
|
9
|
+
*/
|
|
10
|
+
readonly timeoutMs?: number;
|
|
6
11
|
}
|
|
7
12
|
/**
|
|
8
13
|
* Deterministic transformation from state to state. Labelled `kind: "code"` in the trace.
|
package/dist/nodes/code.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../../src/nodes/code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,MAAM,EAAE,KAAK,YAAY,EAAE,KAAK,IAAI,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAEvH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B,+FAA+F;IAC/F,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../../src/nodes/code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,MAAM,EAAE,KAAK,YAAY,EAAE,KAAK,IAAI,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAEvH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B,+FAA+F;IAC/F,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,UAAU,KAAK,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAC3D,OAAO,GAAE,eAAoB,GAC5B,IAAI,CAAC,CAAC,CAAC,CAET"}
|
package/dist/nodes/code.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code.js","sourceRoot":"","sources":["../../src/nodes/code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgF,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"code.js","sourceRoot":"","sources":["../../src/nodes/code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgF,MAAM,aAAa,CAAC;AAavH;;;GAGG;AACH,MAAM,UAAU,QAAQ,CACtB,EAA2D,EAC3D,OAAO,GAAoB,EAAE;IAE7B,OAAO,UAAU,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { MaybePromise } from "../index.js";
|
|
2
|
+
import type { ChatMessage, ImagePart, MessageContent } from "./llm.js";
|
|
3
|
+
export interface TextOfOptions {
|
|
4
|
+
/** Written in place of each image. Without it, an image is an error. */
|
|
5
|
+
readonly imagePlaceholder?: string;
|
|
6
|
+
}
|
|
7
|
+
/** The text of a message's content, for adapters that send text only. Images are an error unless replaced. */
|
|
8
|
+
export declare function textOf(content: MessageContent, options?: TextOfOptions): string;
|
|
9
|
+
/** Reads an image URL an adapter cannot send as it is, e.g. `media:abc` from your own store. */
|
|
10
|
+
export type ImageResolver = (url: string) => MaybePromise<ImagePart>;
|
|
11
|
+
/**
|
|
12
|
+
* Replaces each image given by URL in user and tool messages: every `data:` URL, including one `resolve` returns,
|
|
13
|
+
* becomes a base64 image; other URLs become what `resolve` returns (which may be another URL). URLs are read one after
|
|
14
|
+
* another, and the result is synchronous when `resolve` is. Messages without such images are returned as the same
|
|
15
|
+
* objects.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveImages(messages: readonly ChatMessage[], resolve?: ImageResolver): MaybePromise<ChatMessage[]>;
|
|
18
|
+
//# sourceMappingURL=content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../../src/nodes/content.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAe,SAAS,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAGpF,MAAM,WAAW,aAAa;IAC5B,wEAAwE;IACxE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED,8GAA8G;AAC9G,wBAAgB,MAAM,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAanF;AAED,gGAAgG;AAChG,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,YAAY,CAAC,SAAS,CAAC,CAAC;AAiDrE;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC,CAiBpH"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { andThen } from "./util.js";
|
|
2
|
+
/** The text of a message's content, for adapters that send text only. Images are an error unless replaced. */
|
|
3
|
+
export function textOf(content, options = {}) {
|
|
4
|
+
if (typeof content === "string")
|
|
5
|
+
return content;
|
|
6
|
+
let text = "";
|
|
7
|
+
for (const part of content) {
|
|
8
|
+
if (part.type === "text")
|
|
9
|
+
text += part.text;
|
|
10
|
+
else if (options.imagePlaceholder !== undefined)
|
|
11
|
+
text += options.imagePlaceholder;
|
|
12
|
+
else {
|
|
13
|
+
throw new TypeError("textOf: the content has images and this adapter sends text only; pass { imagePlaceholder } to replace them");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return text;
|
|
17
|
+
}
|
|
18
|
+
const DATA_URL = /^data:([\w.+-]+\/[\w.+-]+);base64,([A-Za-z0-9+/]*={0,2})$/i;
|
|
19
|
+
const shown = (url) => (url.length > 100 ? `${url.slice(0, 100)}…` : url);
|
|
20
|
+
const isURLImage = (part) => part.type === "image" && !("data" in part);
|
|
21
|
+
function isImagePart(value) {
|
|
22
|
+
if (typeof value !== "object" || value === null)
|
|
23
|
+
return false;
|
|
24
|
+
const v = value;
|
|
25
|
+
if (v.type !== "image")
|
|
26
|
+
return false;
|
|
27
|
+
if (typeof v.data === "string")
|
|
28
|
+
return typeof v.mimeType === "string";
|
|
29
|
+
return typeof v.url === "string" && (v.mimeType === undefined || typeof v.mimeType === "string");
|
|
30
|
+
}
|
|
31
|
+
function fromDataURL(url) {
|
|
32
|
+
const match = DATA_URL.exec(url);
|
|
33
|
+
if (!match)
|
|
34
|
+
throw new TypeError(`resolveImages: only base64 data: URLs are supported, got "${shown(url)}"`);
|
|
35
|
+
return { type: "image", mimeType: match[1], data: match[2] };
|
|
36
|
+
}
|
|
37
|
+
function resolveParts(parts, resolve) {
|
|
38
|
+
const out = [];
|
|
39
|
+
const from = (start) => {
|
|
40
|
+
for (let i = start; i < parts.length; i++) {
|
|
41
|
+
const part = parts[i];
|
|
42
|
+
if (part.type === "text" || "data" in part) {
|
|
43
|
+
out.push(part);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const { url } = part;
|
|
47
|
+
if (/^data:/i.test(url)) {
|
|
48
|
+
out.push(fromDataURL(url));
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (!resolve)
|
|
52
|
+
throw new TypeError(`resolveImages: no resolver for image URL "${shown(url)}"`);
|
|
53
|
+
return andThen(resolve(url), (image) => {
|
|
54
|
+
if (!isImagePart(image))
|
|
55
|
+
throw new TypeError(`resolveImages: the resolver did not return an image for "${shown(url)}"`);
|
|
56
|
+
out.push(!("data" in image) && /^data:/i.test(image.url) ? fromDataURL(image.url) : image);
|
|
57
|
+
return from(i + 1);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
};
|
|
62
|
+
return from(0);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Replaces each image given by URL in user and tool messages: every `data:` URL, including one `resolve` returns,
|
|
66
|
+
* becomes a base64 image; other URLs become what `resolve` returns (which may be another URL). URLs are read one after
|
|
67
|
+
* another, and the result is synchronous when `resolve` is. Messages without such images are returned as the same
|
|
68
|
+
* objects.
|
|
69
|
+
*/
|
|
70
|
+
export function resolveImages(messages, resolve) {
|
|
71
|
+
const out = [];
|
|
72
|
+
const from = (start) => {
|
|
73
|
+
for (let i = start; i < messages.length; i++) {
|
|
74
|
+
const m = messages[i];
|
|
75
|
+
if ((m.role !== "user" && m.role !== "tool") || typeof m.content === "string" || !m.content.some(isURLImage)) {
|
|
76
|
+
out.push(m);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
return andThen(resolveParts(m.content, resolve), (content) => {
|
|
80
|
+
out.push({ ...m, content });
|
|
81
|
+
return from(i + 1);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
};
|
|
86
|
+
return from(0);
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../../src/nodes/content.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,8GAA8G;AAC9G,MAAM,UAAU,MAAM,CAAC,OAAuB,EAAE,OAAO,GAAkB,EAAE;IACzE,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAC;IAChD,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;YAAE,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC;aACvC,IAAI,OAAO,CAAC,gBAAgB,KAAK,SAAS;YAAE,IAAI,IAAI,OAAO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HANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { CodeNode, type CodeNodeOptions } from "./code.js";
|
|
2
|
+
export { type ImageResolver, resolveImages, type TextOfOptions, textOf } from "./content.js";
|
|
2
3
|
export { HumanNode, type HumanNodeConfig } from "./human.js";
|
|
3
|
-
export { type ChatMessage, type LLMModel, LLMNode, LLMOutputError, type LLMRequest, type LLMResponse, type LLMStructuredNodeConfig, type LLMTextNodeConfig, } from "./llm.js";
|
|
4
|
+
export { type ChatMessage, type ContentPart, type ImagePart, type LLMModel, LLMNode, LLMOutputError, type LLMRequest, type LLMResponse, type LLMStructuredNodeConfig, type LLMTextNodeConfig, type MessageContent, type ReasoningLevel, type ReasoningPart, type TextPart, type ToolCall, type ToolChoice, type ToolSpec, } from "./llm.js";
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nodes/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,OAAO,EACP,cAAc,EACd,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nodes/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,KAAK,aAAa,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,OAAO,EACP,cAAc,EACd,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,QAAQ,GACd,MAAM,UAAU,CAAC"}
|
package/dist/nodes/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Plugin nodes. Not part of the kernel: everything here is built on the public
|
|
2
2
|
// `defineNode` + `ctx.trace.append` API, the same way third-party nodes are.
|
|
3
3
|
export { CodeNode } from "./code.js";
|
|
4
|
+
export { resolveImages, textOf } from "./content.js";
|
|
4
5
|
export { HumanNode } from "./human.js";
|
|
5
6
|
export { LLMNode, LLMOutputError, } from "./llm.js";
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
package/dist/nodes/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nodes/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,6EAA6E;AAE7E,OAAO,EAAE,QAAQ,EAAwB,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAwB,MAAM,YAAY,CAAC;AAC7D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nodes/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,6EAA6E;AAE7E,OAAO,EAAE,QAAQ,EAAwB,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAsB,aAAa,EAAsB,MAAM,EAAE,MAAM,cAAc,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAwB,MAAM,YAAY,CAAC;AAC7D,OAAO,EAKL,OAAO,EACP,cAAc,GAYf,MAAM,UAAU,CAAC"}
|