@nodetool-ai/runtime 0.7.0-rc.11
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/bridge-protocol.d.ts +39 -0
- package/dist/bridge-protocol.d.ts.map +1 -0
- package/dist/bridge-protocol.js +39 -0
- package/dist/bridge-protocol.js.map +1 -0
- package/dist/comfy-executor.d.ts +41 -0
- package/dist/comfy-executor.d.ts.map +1 -0
- package/dist/comfy-executor.js +305 -0
- package/dist/comfy-executor.js.map +1 -0
- package/dist/context-packer.d.ts +22 -0
- package/dist/context-packer.d.ts.map +1 -0
- package/dist/context-packer.js +66 -0
- package/dist/context-packer.js.map +1 -0
- package/dist/context.d.ts +405 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +1455 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/node-executor.d.ts +53 -0
- package/dist/node-executor.d.ts.map +1 -0
- package/dist/node-executor.js +9 -0
- package/dist/node-executor.js.map +1 -0
- package/dist/providers/aki-manifest.json +34 -0
- package/dist/providers/aki-provider.d.ts +65 -0
- package/dist/providers/aki-provider.d.ts.map +1 -0
- package/dist/providers/aki-provider.js +517 -0
- package/dist/providers/aki-provider.js.map +1 -0
- package/dist/providers/anthropic-provider.d.ts +55 -0
- package/dist/providers/anthropic-provider.d.ts.map +1 -0
- package/dist/providers/anthropic-provider.js +563 -0
- package/dist/providers/anthropic-provider.js.map +1 -0
- package/dist/providers/base-provider.d.ts +194 -0
- package/dist/providers/base-provider.d.ts.map +1 -0
- package/dist/providers/base-provider.js +515 -0
- package/dist/providers/base-provider.js.map +1 -0
- package/dist/providers/cerebras-provider.d.ts +20 -0
- package/dist/providers/cerebras-provider.d.ts.map +1 -0
- package/dist/providers/cerebras-provider.js +52 -0
- package/dist/providers/cerebras-provider.js.map +1 -0
- package/dist/providers/claude-agent-provider.d.ts +107 -0
- package/dist/providers/claude-agent-provider.d.ts.map +1 -0
- package/dist/providers/claude-agent-provider.js +586 -0
- package/dist/providers/claude-agent-provider.js.map +1 -0
- package/dist/providers/cohere-provider.d.ts +36 -0
- package/dist/providers/cohere-provider.d.ts.map +1 -0
- package/dist/providers/cohere-provider.js +116 -0
- package/dist/providers/cohere-provider.js.map +1 -0
- package/dist/providers/cost-calculator.d.ts +109 -0
- package/dist/providers/cost-calculator.d.ts.map +1 -0
- package/dist/providers/cost-calculator.js +475 -0
- package/dist/providers/cost-calculator.js.map +1 -0
- package/dist/providers/deepseek-provider.d.ts +25 -0
- package/dist/providers/deepseek-provider.d.ts.map +1 -0
- package/dist/providers/deepseek-provider.js +58 -0
- package/dist/providers/deepseek-provider.js.map +1 -0
- package/dist/providers/fake-provider.d.ts +52 -0
- package/dist/providers/fake-provider.d.ts.map +1 -0
- package/dist/providers/fake-provider.js +107 -0
- package/dist/providers/fake-provider.js.map +1 -0
- package/dist/providers/fal-provider.d.ts +32 -0
- package/dist/providers/fal-provider.d.ts.map +1 -0
- package/dist/providers/fal-provider.js +445 -0
- package/dist/providers/fal-provider.js.map +1 -0
- package/dist/providers/gemini-provider.d.ts +109 -0
- package/dist/providers/gemini-provider.d.ts.map +1 -0
- package/dist/providers/gemini-provider.js +943 -0
- package/dist/providers/gemini-provider.js.map +1 -0
- package/dist/providers/groq-provider.d.ts +20 -0
- package/dist/providers/groq-provider.d.ts.map +1 -0
- package/dist/providers/groq-provider.js +52 -0
- package/dist/providers/groq-provider.js.map +1 -0
- package/dist/providers/huggingface-provider.d.ts +59 -0
- package/dist/providers/huggingface-provider.d.ts.map +1 -0
- package/dist/providers/huggingface-provider.js +305 -0
- package/dist/providers/huggingface-provider.js.map +1 -0
- package/dist/providers/index.d.ts +69 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +137 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/jina-provider.d.ts +37 -0
- package/dist/providers/jina-provider.d.ts.map +1 -0
- package/dist/providers/jina-provider.js +118 -0
- package/dist/providers/jina-provider.js.map +1 -0
- package/dist/providers/kie-provider.d.ts +19 -0
- package/dist/providers/kie-provider.d.ts.map +1 -0
- package/dist/providers/kie-provider.js +118 -0
- package/dist/providers/kie-provider.js.map +1 -0
- package/dist/providers/llama-provider.d.ts +49 -0
- package/dist/providers/llama-provider.d.ts.map +1 -0
- package/dist/providers/llama-provider.js +381 -0
- package/dist/providers/llama-provider.js.map +1 -0
- package/dist/providers/lmstudio-provider.d.ts +22 -0
- package/dist/providers/lmstudio-provider.d.ts.map +1 -0
- package/dist/providers/lmstudio-provider.js +63 -0
- package/dist/providers/lmstudio-provider.js.map +1 -0
- package/dist/providers/manifest-models.d.ts +12 -0
- package/dist/providers/manifest-models.d.ts.map +1 -0
- package/dist/providers/manifest-models.js +96 -0
- package/dist/providers/manifest-models.js.map +1 -0
- package/dist/providers/meshy-provider.d.ts +53 -0
- package/dist/providers/meshy-provider.d.ts.map +1 -0
- package/dist/providers/meshy-provider.js +230 -0
- package/dist/providers/meshy-provider.js.map +1 -0
- package/dist/providers/minimax-provider.d.ts +66 -0
- package/dist/providers/minimax-provider.d.ts.map +1 -0
- package/dist/providers/minimax-provider.js +531 -0
- package/dist/providers/minimax-provider.js.map +1 -0
- package/dist/providers/mistral-provider.d.ts +26 -0
- package/dist/providers/mistral-provider.d.ts.map +1 -0
- package/dist/providers/mistral-provider.js +74 -0
- package/dist/providers/mistral-provider.js.map +1 -0
- package/dist/providers/moonshot-provider.d.ts +24 -0
- package/dist/providers/moonshot-provider.d.ts.map +1 -0
- package/dist/providers/moonshot-provider.js +43 -0
- package/dist/providers/moonshot-provider.js.map +1 -0
- package/dist/providers/ollama-provider.d.ts +71 -0
- package/dist/providers/ollama-provider.d.ts.map +1 -0
- package/dist/providers/ollama-provider.js +480 -0
- package/dist/providers/ollama-provider.js.map +1 -0
- package/dist/providers/openai-provider.d.ts +103 -0
- package/dist/providers/openai-provider.d.ts.map +1 -0
- package/dist/providers/openai-provider.js +917 -0
- package/dist/providers/openai-provider.js.map +1 -0
- package/dist/providers/openrouter-provider.d.ts +49 -0
- package/dist/providers/openrouter-provider.d.ts.map +1 -0
- package/dist/providers/openrouter-provider.js +147 -0
- package/dist/providers/openrouter-provider.js.map +1 -0
- package/dist/providers/provider-registry.d.ts +24 -0
- package/dist/providers/provider-registry.d.ts.map +1 -0
- package/dist/providers/provider-registry.js +124 -0
- package/dist/providers/provider-registry.js.map +1 -0
- package/dist/providers/python-provider.d.ts +75 -0
- package/dist/providers/python-provider.d.ts.map +1 -0
- package/dist/providers/python-provider.js +157 -0
- package/dist/providers/python-provider.js.map +1 -0
- package/dist/providers/replicate-provider.d.ts +73 -0
- package/dist/providers/replicate-provider.d.ts.map +1 -0
- package/dist/providers/replicate-provider.js +484 -0
- package/dist/providers/replicate-provider.js.map +1 -0
- package/dist/providers/rodin-provider.d.ts +41 -0
- package/dist/providers/rodin-provider.d.ts.map +1 -0
- package/dist/providers/rodin-provider.js +236 -0
- package/dist/providers/rodin-provider.js.map +1 -0
- package/dist/providers/scripted-provider.d.ts +141 -0
- package/dist/providers/scripted-provider.d.ts.map +1 -0
- package/dist/providers/scripted-provider.js +246 -0
- package/dist/providers/scripted-provider.js.map +1 -0
- package/dist/providers/together-provider.d.ts +20 -0
- package/dist/providers/together-provider.d.ts.map +1 -0
- package/dist/providers/together-provider.js +56 -0
- package/dist/providers/together-provider.js.map +1 -0
- package/dist/providers/types.d.ts +202 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +2 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/providers/vllm-provider.d.ts +22 -0
- package/dist/providers/vllm-provider.d.ts.map +1 -0
- package/dist/providers/vllm-provider.js +66 -0
- package/dist/providers/vllm-provider.js.map +1 -0
- package/dist/providers/voyage-provider.d.ts +37 -0
- package/dist/providers/voyage-provider.d.ts.map +1 -0
- package/dist/providers/voyage-provider.js +124 -0
- package/dist/providers/voyage-provider.js.map +1 -0
- package/dist/providers/xai-provider.d.ts +24 -0
- package/dist/providers/xai-provider.d.ts.map +1 -0
- package/dist/providers/xai-provider.js +57 -0
- package/dist/providers/xai-provider.js.map +1 -0
- package/dist/python-bridge-types.d.ts +70 -0
- package/dist/python-bridge-types.d.ts.map +1 -0
- package/dist/python-bridge-types.js +2 -0
- package/dist/python-bridge-types.js.map +1 -0
- package/dist/python-node-executor.d.ts +20 -0
- package/dist/python-node-executor.d.ts.map +1 -0
- package/dist/python-node-executor.js +219 -0
- package/dist/python-node-executor.js.map +1 -0
- package/dist/python-stdio-bridge.d.ts +67 -0
- package/dist/python-stdio-bridge.d.ts.map +1 -0
- package/dist/python-stdio-bridge.js +704 -0
- package/dist/python-stdio-bridge.js.map +1 -0
- package/dist/recommended-models.d.ts +17 -0
- package/dist/recommended-models.d.ts.map +1 -0
- package/dist/recommended-models.js +139 -0
- package/dist/recommended-models.js.map +1 -0
- package/dist/telemetry.d.ts +61 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +128 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/trace-exporters.d.ts +72 -0
- package/dist/trace-exporters.d.ts.map +1 -0
- package/dist/trace-exporters.js +216 -0
- package/dist/trace-exporters.js.map +1 -0
- package/dist/tracing-helpers.d.ts +99 -0
- package/dist/tracing-helpers.d.ts.map +1 -0
- package/dist/tracing-helpers.js +217 -0
- package/dist/tracing-helpers.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom OpenTelemetry span exporters for NodeTool.
|
|
3
|
+
*
|
|
4
|
+
* - {@link JsonlFileSpanExporter} — appends one JSON line per span to a file
|
|
5
|
+
* - {@link StdoutSpanExporter} — writes spans to stdout in `json` (JSONL)
|
|
6
|
+
* or `pretty` (human-readable) format
|
|
7
|
+
*
|
|
8
|
+
* Both produce the same structured shape, so an analyzer agent reading either
|
|
9
|
+
* file or stdout output gets identical fields.
|
|
10
|
+
*/
|
|
11
|
+
import { createWriteStream } from "node:fs";
|
|
12
|
+
import { mkdir } from "node:fs/promises";
|
|
13
|
+
import { dirname } from "node:path";
|
|
14
|
+
import { ExportResultCode } from "@opentelemetry/core";
|
|
15
|
+
const SPAN_KINDS = ["INTERNAL", "SERVER", "CLIENT", "PRODUCER", "CONSUMER"];
|
|
16
|
+
const STATUS_CODES = ["UNSET", "OK", "ERROR"];
|
|
17
|
+
/**
|
|
18
|
+
* Convert an OTel hrTime ([seconds, nanoseconds]) to integer unix-epoch ms.
|
|
19
|
+
*
|
|
20
|
+
* We round (rather than truncate) so a 0.6ms span doesn't read as 0ms, and
|
|
21
|
+
* we keep the schema integer-typed for downstream JSONL consumers that
|
|
22
|
+
* assume `start_time_ms`/`end_time_ms`/`duration_ms` are whole numbers.
|
|
23
|
+
*/
|
|
24
|
+
function hrTimeToMs(hrTime) {
|
|
25
|
+
return Math.round(hrTime[0] * 1000 + hrTime[1] / 1_000_000);
|
|
26
|
+
}
|
|
27
|
+
export function spanToRecord(span) {
|
|
28
|
+
const ctx = span.spanContext();
|
|
29
|
+
const startMs = hrTimeToMs(span.startTime);
|
|
30
|
+
const endMs = hrTimeToMs(span.endTime);
|
|
31
|
+
return {
|
|
32
|
+
trace_id: ctx.traceId,
|
|
33
|
+
span_id: ctx.spanId,
|
|
34
|
+
parent_span_id: span.parentSpanContext?.spanId ?? null,
|
|
35
|
+
name: span.name,
|
|
36
|
+
kind: SPAN_KINDS[span.kind] ?? "INTERNAL",
|
|
37
|
+
start_time_ms: startMs,
|
|
38
|
+
end_time_ms: endMs,
|
|
39
|
+
duration_ms: endMs - startMs,
|
|
40
|
+
status: {
|
|
41
|
+
code: STATUS_CODES[span.status.code] ?? "UNSET",
|
|
42
|
+
...(span.status.message ? { message: span.status.message } : {})
|
|
43
|
+
},
|
|
44
|
+
attributes: { ...span.attributes },
|
|
45
|
+
events: span.events.map((e) => ({
|
|
46
|
+
name: e.name,
|
|
47
|
+
time_ms: hrTimeToMs(e.time),
|
|
48
|
+
...(e.attributes ? { attributes: { ...e.attributes } } : {})
|
|
49
|
+
})),
|
|
50
|
+
resource: { ...span.resource.attributes }
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Append spans as JSONL to a file. Creates parent directories as needed.
|
|
55
|
+
*
|
|
56
|
+
* Spans are written as soon as `export()` is called (use a SimpleSpanProcessor
|
|
57
|
+
* for immediate flush, BatchSpanProcessor for buffered).
|
|
58
|
+
*
|
|
59
|
+
* Honors stream backpressure: each batch awaits the underlying `write`
|
|
60
|
+
* callback (and a `drain` event when the stream reports it's full) before
|
|
61
|
+
* reporting SUCCESS, so high trace volume can't accumulate unbounded.
|
|
62
|
+
*/
|
|
63
|
+
export class JsonlFileSpanExporter {
|
|
64
|
+
stream = null;
|
|
65
|
+
streamReady;
|
|
66
|
+
constructor(filePath) {
|
|
67
|
+
this.streamReady = (async () => {
|
|
68
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
69
|
+
this.stream = createWriteStream(filePath, { flags: "a" });
|
|
70
|
+
})();
|
|
71
|
+
}
|
|
72
|
+
export(spans, resultCallback) {
|
|
73
|
+
void this.streamReady
|
|
74
|
+
.then(async () => {
|
|
75
|
+
if (!this.stream)
|
|
76
|
+
throw new Error("trace stream not initialized");
|
|
77
|
+
for (const span of spans) {
|
|
78
|
+
await writeLine(this.stream, JSON.stringify(spanToRecord(span)) + "\n");
|
|
79
|
+
}
|
|
80
|
+
resultCallback({ code: ExportResultCode.SUCCESS });
|
|
81
|
+
})
|
|
82
|
+
.catch((err) => {
|
|
83
|
+
resultCallback({ code: ExportResultCode.FAILED, error: err });
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async shutdown() {
|
|
87
|
+
await this.streamReady;
|
|
88
|
+
await new Promise((resolve) => {
|
|
89
|
+
if (!this.stream)
|
|
90
|
+
return resolve();
|
|
91
|
+
this.stream.end(resolve);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async forceFlush() {
|
|
95
|
+
// WriteStream auto-flushes on write; nothing to do.
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Write a single line to a WriteStream, respecting backpressure.
|
|
100
|
+
*
|
|
101
|
+
* Resolves once the write callback has fired AND the stream has drained
|
|
102
|
+
* (if `write()` returned false). Rejects on any stream error during the
|
|
103
|
+
* write — caller is responsible for re-attaching listeners afterwards.
|
|
104
|
+
*/
|
|
105
|
+
function writeLine(stream, line) {
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
let written = false;
|
|
108
|
+
let drained = false;
|
|
109
|
+
let needsDrain = false;
|
|
110
|
+
const onError = (err) => {
|
|
111
|
+
stream.off("drain", onDrain);
|
|
112
|
+
reject(err);
|
|
113
|
+
};
|
|
114
|
+
const onDrain = () => {
|
|
115
|
+
drained = true;
|
|
116
|
+
maybeDone();
|
|
117
|
+
};
|
|
118
|
+
const maybeDone = () => {
|
|
119
|
+
if (written && (!needsDrain || drained)) {
|
|
120
|
+
stream.off("error", onError);
|
|
121
|
+
stream.off("drain", onDrain);
|
|
122
|
+
resolve();
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
stream.once("error", onError);
|
|
126
|
+
const ok = stream.write(line, (err) => {
|
|
127
|
+
if (err)
|
|
128
|
+
return onError(err);
|
|
129
|
+
written = true;
|
|
130
|
+
maybeDone();
|
|
131
|
+
});
|
|
132
|
+
if (!ok) {
|
|
133
|
+
needsDrain = true;
|
|
134
|
+
stream.once("drain", onDrain);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Write spans to stdout. `format: "json"` emits JSONL; `format: "pretty"`
|
|
140
|
+
* emits a human-readable single-line summary that's still grep-friendly.
|
|
141
|
+
*/
|
|
142
|
+
export class StdoutSpanExporter {
|
|
143
|
+
format;
|
|
144
|
+
constructor(format = "pretty") {
|
|
145
|
+
this.format = format;
|
|
146
|
+
}
|
|
147
|
+
export(spans, resultCallback) {
|
|
148
|
+
try {
|
|
149
|
+
for (const span of spans) {
|
|
150
|
+
const rec = spanToRecord(span);
|
|
151
|
+
if (this.format === "json") {
|
|
152
|
+
process.stdout.write(JSON.stringify(rec) + "\n");
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
process.stdout.write(formatPretty(rec) + "\n");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
resultCallback({ code: ExportResultCode.SUCCESS });
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
resultCallback({ code: ExportResultCode.FAILED, error: err });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async shutdown() {
|
|
165
|
+
// Nothing to clean up.
|
|
166
|
+
}
|
|
167
|
+
async forceFlush() {
|
|
168
|
+
// stdout writes are synchronous-ish; nothing to do.
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const COLOR = {
|
|
172
|
+
dim: "\x1b[2m",
|
|
173
|
+
red: "\x1b[31m",
|
|
174
|
+
yellow: "\x1b[33m",
|
|
175
|
+
green: "\x1b[32m",
|
|
176
|
+
cyan: "\x1b[36m",
|
|
177
|
+
bold: "\x1b[1m",
|
|
178
|
+
reset: "\x1b[0m"
|
|
179
|
+
};
|
|
180
|
+
function colorize(s, color) {
|
|
181
|
+
return process.stdout.isTTY ? `${COLOR[color]}${s}${COLOR.reset}` : s;
|
|
182
|
+
}
|
|
183
|
+
function formatPretty(r) {
|
|
184
|
+
const dur = `${r.duration_ms.toFixed(1)}ms`;
|
|
185
|
+
const statusColor = r.status.code === "ERROR"
|
|
186
|
+
? "red"
|
|
187
|
+
: r.status.code === "OK"
|
|
188
|
+
? "green"
|
|
189
|
+
: "dim";
|
|
190
|
+
const tags = [];
|
|
191
|
+
// Surface the most useful attributes inline, in priority order.
|
|
192
|
+
const inlineKeys = [
|
|
193
|
+
"llm.provider",
|
|
194
|
+
"llm.model",
|
|
195
|
+
"gen_ai.usage.input_tokens",
|
|
196
|
+
"gen_ai.usage.output_tokens",
|
|
197
|
+
"agent.objective",
|
|
198
|
+
"node.type",
|
|
199
|
+
"node.id",
|
|
200
|
+
"workflow.id"
|
|
201
|
+
];
|
|
202
|
+
for (const k of inlineKeys) {
|
|
203
|
+
const v = r.attributes[k];
|
|
204
|
+
if (v !== undefined && v !== null && v !== "") {
|
|
205
|
+
tags.push(`${colorize(k, "dim")}=${truncate(String(v), 60)}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const status = r.status.code === "ERROR"
|
|
209
|
+
? colorize(`[${r.status.code}${r.status.message ? `: ${r.status.message}` : ""}]`, statusColor)
|
|
210
|
+
: "";
|
|
211
|
+
return `${colorize(r.name, "cyan")} ${colorize(dur, "yellow")} ${tags.join(" ")} ${status}`.trimEnd();
|
|
212
|
+
}
|
|
213
|
+
function truncate(s, max) {
|
|
214
|
+
return s.length > max ? s.slice(0, max - 1) + "…" : s;
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=trace-exporters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-exporters.js","sourceRoot":"","sources":["../src/trace-exporters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,iBAAiB,EAAoB,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,OAAO,EAAE,gBAAgB,EAAqB,MAAM,qBAAqB,CAAC;AA4B1E,MAAM,UAAU,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AAC5E,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAE9C;;;;;;GAMG;AACH,SAAS,UAAU,CAAC,MAAwB;IAC1C,OAAO,IAAI,CA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AAE,KAAK,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IACD,MAAM,MAAM,GACV,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO;QACvB,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC;QAC/F,CAAC,CAAC,EAAE,CAAC;IACT,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC;AACxG,CAAC;AAED,SAAS,QAAQ,CAAC,CAAS,EAAE,GAAW;IACtC,OAAO,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for wrapping agent / workflow / node code in OpenTelemetry spans.
|
|
3
|
+
*
|
|
4
|
+
* All helpers degrade gracefully when telemetry is disabled (no tracer
|
|
5
|
+
* configured) — the wrapped function runs as if no span existed, with
|
|
6
|
+
* essentially zero overhead.
|
|
7
|
+
*
|
|
8
|
+
* # Span hierarchy
|
|
9
|
+
*
|
|
10
|
+
* workflow.run ← `withWorkflowSpan`
|
|
11
|
+
* node.process (per node) ← `withNodeSpan`
|
|
12
|
+
* llm.chat / llm.stream ← BaseProvider (existing)
|
|
13
|
+
*
|
|
14
|
+
* agent.execute ← `withAgentSpan({ kind: "execute" })`
|
|
15
|
+
* agent.plan ← `withAgentSpan({ kind: "plan" })`
|
|
16
|
+
* agent.step ← `withAgentSpan({ kind: "step" })`
|
|
17
|
+
* llm.chat / llm.stream ← BaseProvider (existing)
|
|
18
|
+
*
|
|
19
|
+
* Child spans nest automatically because OTel's `startActiveSpan` makes the
|
|
20
|
+
* span active in AsyncLocalStorage for the duration of the callback.
|
|
21
|
+
*/
|
|
22
|
+
import { type Span } from "@opentelemetry/api";
|
|
23
|
+
export type AgentSpanKind = "execute" | "plan" | "step";
|
|
24
|
+
/** Token counts and computed cost for one LLM call. */
|
|
25
|
+
export interface LlmUsage {
|
|
26
|
+
inputTokens: number;
|
|
27
|
+
outputTokens: number;
|
|
28
|
+
cachedInputTokens?: number;
|
|
29
|
+
/** In NodeTool credits (1 credit ≈ $0.01). */
|
|
30
|
+
cost?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Run `fn` inside a fresh usage slot. `consumeLastUsage()` afterwards returns
|
|
34
|
+
* whatever the deepest `setLastUsage()` call wrote.
|
|
35
|
+
*/
|
|
36
|
+
export declare function withUsageCapture<T>(fn: () => Promise<T>): Promise<T>;
|
|
37
|
+
/** Provider hook: record token usage for the in-flight LLM call. */
|
|
38
|
+
export declare function setLastUsage(usage: LlmUsage): void;
|
|
39
|
+
/** Read and clear the most recent usage recorded in this async context. */
|
|
40
|
+
export declare function consumeLastUsage(): LlmUsage | null;
|
|
41
|
+
/** Read (without clearing) the most recent usage in this async context. */
|
|
42
|
+
export declare function peekLastUsage(): LlmUsage | null;
|
|
43
|
+
/**
|
|
44
|
+
* Create a per-call usage slot that survives across async-generator yields.
|
|
45
|
+
*
|
|
46
|
+
* `AsyncLocalStorage.run()` only persists across awaits within its callback,
|
|
47
|
+
* so for streaming we explicitly wrap each `gen.next()` call in `runInSlot`.
|
|
48
|
+
* After the generator finishes, `getUsage()` returns whatever the deepest
|
|
49
|
+
* `setLastUsage()` call wrote.
|
|
50
|
+
*/
|
|
51
|
+
export declare function createUsageSlot(): {
|
|
52
|
+
runInSlot: <T>(fn: () => Promise<T>) => Promise<T>;
|
|
53
|
+
getUsage: () => LlmUsage | null;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Wrap an async generator in an OTel span. Each `next()` call runs in the
|
|
57
|
+
* span's context, so any spans created inside `genFactory` nest under it.
|
|
58
|
+
*
|
|
59
|
+
* Preserves the generator's `TReturn` so callers reading `.next().value`
|
|
60
|
+
* after `done` still get the underlying return value. If the consumer
|
|
61
|
+
* cancels (breaks out of `for await`, calls `return()`, or throws), the
|
|
62
|
+
* inner generator's `return()` is invoked so its `finally` blocks run.
|
|
63
|
+
*/
|
|
64
|
+
export declare function withSpanGen<T, TReturn = void>(name: string, attributes: Record<string, unknown>, genFactory: () => AsyncGenerator<T, TReturn>): AsyncGenerator<T, TReturn>;
|
|
65
|
+
/**
|
|
66
|
+
* Wrap an agent operation (execute / plan / step) in a span.
|
|
67
|
+
*
|
|
68
|
+
* @param kind — which agent stage this is (becomes part of span name)
|
|
69
|
+
* @param attributes — agent.* attributes (objective, model, provider, ...)
|
|
70
|
+
* @param fn — the body of the agent stage
|
|
71
|
+
*/
|
|
72
|
+
export declare function withAgentSpan<T>(kind: AgentSpanKind, attributes: {
|
|
73
|
+
objective?: string;
|
|
74
|
+
provider?: string;
|
|
75
|
+
model?: string;
|
|
76
|
+
/** For `step`: which task / sub-objective is being executed. */
|
|
77
|
+
task?: string;
|
|
78
|
+
/** For `plan`: number of skills / tools available. */
|
|
79
|
+
toolsCount?: number;
|
|
80
|
+
/** Any additional attributes to attach. */
|
|
81
|
+
extra?: Record<string, unknown>;
|
|
82
|
+
}, fn: (span: Span | null) => Promise<T>): Promise<T>;
|
|
83
|
+
/** Wrap a workflow run (kernel WorkflowRunner) in a span. */
|
|
84
|
+
export declare function withWorkflowSpan<T>(attributes: {
|
|
85
|
+
workflowId?: string;
|
|
86
|
+
workflowName?: string;
|
|
87
|
+
nodeCount?: number;
|
|
88
|
+
extra?: Record<string, unknown>;
|
|
89
|
+
}, fn: (span: Span | null) => Promise<T>): Promise<T>;
|
|
90
|
+
/** Async-generator variant of {@link withAgentSpan}. */
|
|
91
|
+
export declare function withAgentSpanGen<T, TReturn = void>(kind: AgentSpanKind, attributes: Parameters<typeof withAgentSpan>[1], genFactory: () => AsyncGenerator<T, TReturn>): AsyncGenerator<T, TReturn>;
|
|
92
|
+
/** Wrap a single node execution (kernel Actor) in a span. */
|
|
93
|
+
export declare function withNodeSpan<T>(attributes: {
|
|
94
|
+
nodeId: string;
|
|
95
|
+
nodeType: string;
|
|
96
|
+
workflowId?: string;
|
|
97
|
+
extra?: Record<string, unknown>;
|
|
98
|
+
}, fn: (span: Span | null) => Promise<T>): Promise<T>;
|
|
99
|
+
//# sourceMappingURL=tracing-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracing-helpers.d.ts","sourceRoot":"","sources":["../src/tracing-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAIL,KAAK,IAAI,EACV,MAAM,oBAAoB,CAAC;AAG5B,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAExD,uDAAuD;AACvD,MAAM,WAAW,QAAQ;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,8CAA8C;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAaD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAEpE;AAED,oEAAoE;AACpE,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,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AE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,EACD,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GACpC,OAAO,CAAC,CAAC,CAAC,CAaZ;AAED,wDAAwD;AACxD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,IAAI,EAChD,IAAI,EAAE,aAAa,EACnB,UAAU,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,EAC/C,UAAU,EAAE,MAAM,cAAc,CAAC,CAAC,EAAE,OAAO,CAAC,GAC3C,cAAc,CAAC,CAAC,EAAE,OAAO,CAAC,CAE5B;AAwBD,6DAA6D;AAC7D,wBAAgB,YAAY,CAAC,CAAC,EAC5B,UAAU,EAAE;IACV,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,EACD,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GACpC,OAAO,CAAC,CAAC,CAAC,CAUZ"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for wrapping agent / workflow / node code in OpenTelemetry spans.
|
|
3
|
+
*
|
|
4
|
+
* All helpers degrade gracefully when telemetry is disabled (no tracer
|
|
5
|
+
* configured) — the wrapped function runs as if no span existed, with
|
|
6
|
+
* essentially zero overhead.
|
|
7
|
+
*
|
|
8
|
+
* # Span hierarchy
|
|
9
|
+
*
|
|
10
|
+
* workflow.run ← `withWorkflowSpan`
|
|
11
|
+
* node.process (per node) ← `withNodeSpan`
|
|
12
|
+
* llm.chat / llm.stream ← BaseProvider (existing)
|
|
13
|
+
*
|
|
14
|
+
* agent.execute ← `withAgentSpan({ kind: "execute" })`
|
|
15
|
+
* agent.plan ← `withAgentSpan({ kind: "plan" })`
|
|
16
|
+
* agent.step ← `withAgentSpan({ kind: "step" })`
|
|
17
|
+
* llm.chat / llm.stream ← BaseProvider (existing)
|
|
18
|
+
*
|
|
19
|
+
* Child spans nest automatically because OTel's `startActiveSpan` makes the
|
|
20
|
+
* span active in AsyncLocalStorage for the duration of the callback.
|
|
21
|
+
*/
|
|
22
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
23
|
+
import { SpanStatusCode, context as otelContext, trace as otelTrace } from "@opentelemetry/api";
|
|
24
|
+
import { getTracer } from "./telemetry.js";
|
|
25
|
+
/**
|
|
26
|
+
* Per-call usage slot. Providers' `trackUsage` writes into the active slot
|
|
27
|
+
* via {@link setLastUsage}, and the traced wrapper reads it via
|
|
28
|
+
* {@link consumeLastUsage} so it can attach the numbers to its span and
|
|
29
|
+
* `llm_call` event.
|
|
30
|
+
*
|
|
31
|
+
* We use AsyncLocalStorage rather than an instance field so concurrent calls
|
|
32
|
+
* on the same provider instance don't clobber each other.
|
|
33
|
+
*/
|
|
34
|
+
const usageStore = new AsyncLocalStorage();
|
|
35
|
+
/**
|
|
36
|
+
* Run `fn` inside a fresh usage slot. `consumeLastUsage()` afterwards returns
|
|
37
|
+
* whatever the deepest `setLastUsage()` call wrote.
|
|
38
|
+
*/
|
|
39
|
+
export function withUsageCapture(fn) {
|
|
40
|
+
return usageStore.run({ usage: null }, fn);
|
|
41
|
+
}
|
|
42
|
+
/** Provider hook: record token usage for the in-flight LLM call. */
|
|
43
|
+
export function setLastUsage(usage) {
|
|
44
|
+
const slot = usageStore.getStore();
|
|
45
|
+
if (slot)
|
|
46
|
+
slot.usage = usage;
|
|
47
|
+
}
|
|
48
|
+
/** Read and clear the most recent usage recorded in this async context. */
|
|
49
|
+
export function consumeLastUsage() {
|
|
50
|
+
const slot = usageStore.getStore();
|
|
51
|
+
if (!slot)
|
|
52
|
+
return null;
|
|
53
|
+
const u = slot.usage;
|
|
54
|
+
slot.usage = null;
|
|
55
|
+
return u;
|
|
56
|
+
}
|
|
57
|
+
/** Read (without clearing) the most recent usage in this async context. */
|
|
58
|
+
export function peekLastUsage() {
|
|
59
|
+
return usageStore.getStore()?.usage ?? null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create a per-call usage slot that survives across async-generator yields.
|
|
63
|
+
*
|
|
64
|
+
* `AsyncLocalStorage.run()` only persists across awaits within its callback,
|
|
65
|
+
* so for streaming we explicitly wrap each `gen.next()` call in `runInSlot`.
|
|
66
|
+
* After the generator finishes, `getUsage()` returns whatever the deepest
|
|
67
|
+
* `setLastUsage()` call wrote.
|
|
68
|
+
*/
|
|
69
|
+
export function createUsageSlot() {
|
|
70
|
+
const slot = { usage: null };
|
|
71
|
+
return {
|
|
72
|
+
runInSlot: (fn) => usageStore.run(slot, fn),
|
|
73
|
+
getUsage: () => slot.usage
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Wrap a function in an OTel span; pass-through if telemetry is disabled. */
|
|
77
|
+
async function withSpan(name, attributes, fn) {
|
|
78
|
+
const tracer = getTracer();
|
|
79
|
+
if (!tracer)
|
|
80
|
+
return fn(null);
|
|
81
|
+
return tracer.startActiveSpan(name, async (span) => {
|
|
82
|
+
setAttributes(span, attributes);
|
|
83
|
+
try {
|
|
84
|
+
const result = await fn(span);
|
|
85
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: String(err) });
|
|
90
|
+
span.recordException(err);
|
|
91
|
+
throw err;
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
span.end();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Wrap an async generator in an OTel span. Each `next()` call runs in the
|
|
100
|
+
* span's context, so any spans created inside `genFactory` nest under it.
|
|
101
|
+
*
|
|
102
|
+
* Preserves the generator's `TReturn` so callers reading `.next().value`
|
|
103
|
+
* after `done` still get the underlying return value. If the consumer
|
|
104
|
+
* cancels (breaks out of `for await`, calls `return()`, or throws), the
|
|
105
|
+
* inner generator's `return()` is invoked so its `finally` blocks run.
|
|
106
|
+
*/
|
|
107
|
+
export async function* withSpanGen(name, attributes, genFactory) {
|
|
108
|
+
const tracer = getTracer();
|
|
109
|
+
if (!tracer) {
|
|
110
|
+
return yield* genFactory();
|
|
111
|
+
}
|
|
112
|
+
const span = tracer.startSpan(name);
|
|
113
|
+
setAttributes(span, attributes);
|
|
114
|
+
const ctx = otelTrace.setSpan(otelContext.active(), span);
|
|
115
|
+
const inner = otelContext.with(ctx, () => genFactory());
|
|
116
|
+
let exhausted = false;
|
|
117
|
+
try {
|
|
118
|
+
while (true) {
|
|
119
|
+
const result = await otelContext.with(ctx, () => inner.next());
|
|
120
|
+
if (result.done) {
|
|
121
|
+
exhausted = true;
|
|
122
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
123
|
+
return result.value;
|
|
124
|
+
}
|
|
125
|
+
yield result.value;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: String(err) });
|
|
130
|
+
span.recordException(err);
|
|
131
|
+
throw err;
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
if (!exhausted) {
|
|
135
|
+
// Consumer cancelled early — give the inner generator a chance to
|
|
136
|
+
// run its own finally blocks (close streams, end child spans, etc).
|
|
137
|
+
await otelContext
|
|
138
|
+
.with(ctx, () => inner.return?.(undefined))
|
|
139
|
+
?.catch(() => { });
|
|
140
|
+
}
|
|
141
|
+
span.end();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function setAttributes(span, attributes) {
|
|
145
|
+
for (const [k, v] of Object.entries(attributes)) {
|
|
146
|
+
if (v !== undefined && v !== null) {
|
|
147
|
+
span.setAttribute(k, v);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Wrap an agent operation (execute / plan / step) in a span.
|
|
153
|
+
*
|
|
154
|
+
* @param kind — which agent stage this is (becomes part of span name)
|
|
155
|
+
* @param attributes — agent.* attributes (objective, model, provider, ...)
|
|
156
|
+
* @param fn — the body of the agent stage
|
|
157
|
+
*/
|
|
158
|
+
export function withAgentSpan(kind, attributes, fn) {
|
|
159
|
+
return withSpan(`agent.${kind}`, agentAttrs(kind, attributes), fn);
|
|
160
|
+
}
|
|
161
|
+
/** Wrap a workflow run (kernel WorkflowRunner) in a span. */
|
|
162
|
+
export function withWorkflowSpan(attributes, fn) {
|
|
163
|
+
const attrs = {};
|
|
164
|
+
if (attributes.workflowId !== undefined) {
|
|
165
|
+
attrs["workflow.id"] = attributes.workflowId;
|
|
166
|
+
}
|
|
167
|
+
if (attributes.workflowName !== undefined) {
|
|
168
|
+
attrs["workflow.name"] = attributes.workflowName;
|
|
169
|
+
}
|
|
170
|
+
if (attributes.nodeCount !== undefined) {
|
|
171
|
+
attrs["workflow.node_count"] = attributes.nodeCount;
|
|
172
|
+
}
|
|
173
|
+
if (attributes.extra)
|
|
174
|
+
Object.assign(attrs, attributes.extra);
|
|
175
|
+
return withSpan("workflow.run", attrs, fn);
|
|
176
|
+
}
|
|
177
|
+
/** Async-generator variant of {@link withAgentSpan}. */
|
|
178
|
+
export function withAgentSpanGen(kind, attributes, genFactory) {
|
|
179
|
+
return withSpanGen(`agent.${kind}`, agentAttrs(kind, attributes), genFactory);
|
|
180
|
+
}
|
|
181
|
+
function agentAttrs(kind, attributes) {
|
|
182
|
+
const attrs = { "agent.kind": kind };
|
|
183
|
+
if (attributes.objective !== undefined) {
|
|
184
|
+
attrs["agent.objective"] = truncate(attributes.objective, 1000);
|
|
185
|
+
}
|
|
186
|
+
if (attributes.provider !== undefined) {
|
|
187
|
+
attrs["agent.provider"] = attributes.provider;
|
|
188
|
+
}
|
|
189
|
+
if (attributes.model !== undefined)
|
|
190
|
+
attrs["agent.model"] = attributes.model;
|
|
191
|
+
if (attributes.task !== undefined) {
|
|
192
|
+
attrs["agent.task"] = truncate(attributes.task, 1000);
|
|
193
|
+
}
|
|
194
|
+
if (attributes.toolsCount !== undefined) {
|
|
195
|
+
attrs["agent.tools_count"] = attributes.toolsCount;
|
|
196
|
+
}
|
|
197
|
+
if (attributes.extra)
|
|
198
|
+
Object.assign(attrs, attributes.extra);
|
|
199
|
+
return attrs;
|
|
200
|
+
}
|
|
201
|
+
/** Wrap a single node execution (kernel Actor) in a span. */
|
|
202
|
+
export function withNodeSpan(attributes, fn) {
|
|
203
|
+
const attrs = {
|
|
204
|
+
"node.id": attributes.nodeId,
|
|
205
|
+
"node.type": attributes.nodeType
|
|
206
|
+
};
|
|
207
|
+
if (attributes.workflowId !== undefined) {
|
|
208
|
+
attrs["workflow.id"] = attributes.workflowId;
|
|
209
|
+
}
|
|
210
|
+
if (attributes.extra)
|
|
211
|
+
Object.assign(attrs, attributes.extra);
|
|
212
|
+
return withSpan("node.process", attrs, fn);
|
|
213
|
+
}
|
|
214
|
+
function truncate(s, max) {
|
|
215
|
+
return s.length > max ? s.slice(0, max - 1) + "…" : s;
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=tracing-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracing-helpers.js","sourceRoot":"","sources":["../src/tracing-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EACL,cAAc,EACd,OAAO,IAAI,WAAW,EACtB,KAAK,IAAI,SAAS,EAEnB,MAAM,oBAAoB,CAA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AAU,CAAC;IAC/C,CAAC;IACD,IAAI,UAAU,CAAC,KAAK;QAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IAC7D,OAAO,QAAQ,CAAC,cAAc,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,QAAQ,CAAC,CAAS,EAAE,GAAW;IACtC,OAAO,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nodetool-ai/runtime",
|
|
3
|
+
"version": "0.7.0-rc.11",
|
|
4
|
+
"description": "Processing context, message queue, and output normalization",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "node ../../scripts/build-typescript-workspace.mjs && node -e \"require('node:fs').mkdirSync('dist/providers',{recursive:true}); require('node:fs').cpSync('src/providers/aki-manifest.json', 'dist/providers/aki-manifest.json')\"",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest",
|
|
12
|
+
"lint": "tsc --noEmit"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@aki-io/aki-io": "^1.0.1",
|
|
16
|
+
"@anthropic-ai/sdk": "^0.33.1",
|
|
17
|
+
"@msgpack/msgpack": "^3.1.3",
|
|
18
|
+
"@nodetool-ai/config": "^0.7.0-rc.11",
|
|
19
|
+
"@nodetool-ai/protocol": "^0.7.0-rc.11",
|
|
20
|
+
"@opentelemetry/api": "^1.9.0",
|
|
21
|
+
"@opentelemetry/exporter-trace-otlp-proto": "^0.203.0",
|
|
22
|
+
"@opentelemetry/resources": "^2.6.0",
|
|
23
|
+
"@opentelemetry/sdk-node": "^0.203.0",
|
|
24
|
+
"@opentelemetry/sdk-trace-base": "^2.6.0",
|
|
25
|
+
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
26
|
+
"openai": "^4.104.0",
|
|
27
|
+
"replicate": "^1.4.0",
|
|
28
|
+
"ws": "^8.19.0"
|
|
29
|
+
},
|
|
30
|
+
"optionalDependencies": {
|
|
31
|
+
"@anthropic-ai/claude-agent-sdk": "^0.2.101"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^22.0.0",
|
|
35
|
+
"@types/ws": "^8.18.1",
|
|
36
|
+
"typescript": "^5.7.2",
|
|
37
|
+
"vitest": "^4.1.2"
|
|
38
|
+
},
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"nodetool-dev": "./src/index.ts",
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"import": "./dist/index.js",
|
|
44
|
+
"default": "./dist/index.js"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "https://github.com/nodetool-ai/nodetool.git",
|
|
51
|
+
"directory": "packages/runtime"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://nodetool.ai",
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/nodetool-ai/nodetool/issues"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
},
|
|
60
|
+
"files": [
|
|
61
|
+
"dist",
|
|
62
|
+
"README.md"
|
|
63
|
+
]
|
|
64
|
+
}
|