@yukino.js/yukino 0.0.1
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/LICENSE +21 -0
- package/README.md +320 -0
- package/dist/acp-IVY5HZR4.js +14 -0
- package/dist/agent-QANDY7FO.js +4 -0
- package/dist/anthropic-6YLT4JZR.js +4 -0
- package/dist/bwrap-MLSZLWHD.js +4 -0
- package/dist/chunk-2LHY3FND.js +67 -0
- package/dist/chunk-3KKA6537.js +4 -0
- package/dist/chunk-3QL446GD.js +4 -0
- package/dist/chunk-4GE22WHI.js +4 -0
- package/dist/chunk-5VOCXSSX.js +5 -0
- package/dist/chunk-77W2UPS2.js +4 -0
- package/dist/chunk-7MKA3SHV.js +4 -0
- package/dist/chunk-AGSYLE4E.js +16 -0
- package/dist/chunk-CU3IISCC.js +4 -0
- package/dist/chunk-GYBJR2RB.js +65 -0
- package/dist/chunk-HLE7243Q.js +4 -0
- package/dist/chunk-HMZQYFYG.js +4 -0
- package/dist/chunk-JFKC4VCA.js +4 -0
- package/dist/chunk-K4BYVVW7.js +5 -0
- package/dist/chunk-KCMBAHWU.js +4 -0
- package/dist/chunk-L2BWSPCF.js +10 -0
- package/dist/chunk-MDPSQ6L7.js +44 -0
- package/dist/chunk-OFC2GD5K.js +4 -0
- package/dist/chunk-RAS3ORX3.js +164 -0
- package/dist/chunk-RCXKUD3Y.js +4 -0
- package/dist/chunk-SAJCBGHL.js +4 -0
- package/dist/chunk-SOO5OXX2.js +237 -0
- package/dist/chunk-T4O4GQVL.js +607 -0
- package/dist/chunk-UPNNYP7M.js +60 -0
- package/dist/chunk-VCIRD267.js +4 -0
- package/dist/chunk-VU3JWAJR.js +4 -0
- package/dist/chunk-VWUGGYUP.js +6 -0
- package/dist/chunk-XO7ITAWR.js +4 -0
- package/dist/devtools-YWVUN4HX.js +7 -0
- package/dist/esm-57CJEGGK.js +4 -0
- package/dist/esm-6L5BJ5GT.js +4 -0
- package/dist/esm-DIYJ5HX6.js +4 -0
- package/dist/esm-HW2JMFYC.js +4 -0
- package/dist/esm-RPR2GBJ2.js +4 -0
- package/dist/esm-YKAO4ES6.js +4 -0
- package/dist/esm-ZTIYTMTS.js +229 -0
- package/dist/getMachineId-bsd-E27XJQLX.js +4 -0
- package/dist/getMachineId-darwin-35UPAIXP.js +5 -0
- package/dist/getMachineId-linux-MKXIYT6A.js +4 -0
- package/dist/getMachineId-unsupported-ZXVGGFX2.js +4 -0
- package/dist/getMachineId-win-RNVIYJG5.js +4 -0
- package/dist/lib/agent-6FZX4P2Y.js +16 -0
- package/dist/lib/anthropic-IP23YZ3P.js +21 -0
- package/dist/lib/bwrap-2OL7VPSO.js +7 -0
- package/dist/lib/chunk-2VF3XTGH.js +3382 -0
- package/dist/lib/chunk-5DVQ64YL.js +619 -0
- package/dist/lib/chunk-5TGXH7BX.js +624 -0
- package/dist/lib/chunk-6OMQD7MK.js +591 -0
- package/dist/lib/chunk-AZRC67RW.js +512 -0
- package/dist/lib/chunk-F2YJG72O.js +150 -0
- package/dist/lib/chunk-FFM2LB4C.js +132 -0
- package/dist/lib/chunk-FLKB4BK7.js +50 -0
- package/dist/lib/chunk-I34MAQRE.js +255 -0
- package/dist/lib/chunk-KA6POJKI.js +889 -0
- package/dist/lib/chunk-MLKGABMK.js +9 -0
- package/dist/lib/chunk-O7ELJUEK.js +262 -0
- package/dist/lib/chunk-QYBQT2DM.js +655 -0
- package/dist/lib/chunk-YIWNQ7OA.js +47 -0
- package/dist/lib/index.d.ts +8581 -0
- package/dist/lib/index.js +15905 -0
- package/dist/lib/openai-EMJ6U4FW.js +15 -0
- package/dist/lib/permissions-KZ5ACZAX.js +19 -0
- package/dist/lib/providers-2CGZPBFI.js +9 -0
- package/dist/lib/sandbox-runtime-CCQ3X3SM.js +9 -0
- package/dist/lib/seatbelt-WO7YWKLR.js +7 -0
- package/dist/lib/tool-filter-CKHZUUBQ.js +21 -0
- package/dist/main.js +332 -0
- package/dist/node-634LOHDX.js +15 -0
- package/dist/openai-YXYO5OW6.js +34 -0
- package/dist/permissions-VCDMNX3L.js +4 -0
- package/dist/providers-HNMBGGW6.js +4 -0
- package/dist/sandbox-runtime-ELKAYRIL.js +4 -0
- package/dist/seatbelt-JOCANLYS.js +4 -0
- package/dist/server-ZHQILOBP.js +4 -0
- package/dist/src-43CPCEK2.js +12 -0
- package/dist/src-JBRNH4FA.js +4 -0
- package/dist/src-R4BSSIJJ.js +4 -0
- package/dist/src-X6JWWHHT.js +4 -0
- package/dist/tool-filter-BQZDV3TF.js +4 -0
- package/dist/turndown.es-NQ3KDXM7.js +83 -0
- package/package.json +146 -0
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-MLKGABMK.js";
|
|
4
|
+
|
|
5
|
+
// src/telemetry/providers.ts
|
|
6
|
+
var providers_exports = {};
|
|
7
|
+
__export(providers_exports, {
|
|
8
|
+
createTelemetryRuntime: () => createTelemetryRuntime,
|
|
9
|
+
parseExporterTypes: () => parseExporterTypes
|
|
10
|
+
});
|
|
11
|
+
import { LangfuseSpanProcessor } from "@langfuse/otel";
|
|
12
|
+
import {
|
|
13
|
+
setLangfuseTracerProvider,
|
|
14
|
+
startObservation
|
|
15
|
+
} from "@langfuse/tracing";
|
|
16
|
+
import {
|
|
17
|
+
SpanStatusCode
|
|
18
|
+
} from "@opentelemetry/api";
|
|
19
|
+
import { SeverityNumber } from "@opentelemetry/api-logs";
|
|
20
|
+
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
21
|
+
import {
|
|
22
|
+
BatchLogRecordProcessor,
|
|
23
|
+
ConsoleLogRecordExporter,
|
|
24
|
+
LoggerProvider
|
|
25
|
+
} from "@opentelemetry/sdk-logs";
|
|
26
|
+
import {
|
|
27
|
+
ConsoleMetricExporter,
|
|
28
|
+
MeterProvider,
|
|
29
|
+
PeriodicExportingMetricReader
|
|
30
|
+
} from "@opentelemetry/sdk-metrics";
|
|
31
|
+
import {
|
|
32
|
+
BasicTracerProvider,
|
|
33
|
+
BatchSpanProcessor,
|
|
34
|
+
ConsoleSpanExporter
|
|
35
|
+
} from "@opentelemetry/sdk-trace-base";
|
|
36
|
+
import {
|
|
37
|
+
ATTR_SERVICE_NAME,
|
|
38
|
+
ATTR_SERVICE_VERSION
|
|
39
|
+
} from "@opentelemetry/semantic-conventions";
|
|
40
|
+
|
|
41
|
+
// src/version.ts
|
|
42
|
+
var version_exports = {};
|
|
43
|
+
__export(version_exports, {
|
|
44
|
+
version: () => version
|
|
45
|
+
});
|
|
46
|
+
import { readFileSync } from "fs";
|
|
47
|
+
import path from "path";
|
|
48
|
+
import { fileURLToPath } from "url";
|
|
49
|
+
import { z } from "zod";
|
|
50
|
+
var PackageJsonSchema = z.object({
|
|
51
|
+
version: z.string()
|
|
52
|
+
});
|
|
53
|
+
function resolveVersion() {
|
|
54
|
+
if (true) {
|
|
55
|
+
return "0.0.1";
|
|
56
|
+
}
|
|
57
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
58
|
+
for (const levels of ["..", "../.."]) {
|
|
59
|
+
const candidate = path.resolve(here, levels, "package.json");
|
|
60
|
+
try {
|
|
61
|
+
const raw = JSON.parse(readFileSync(candidate, "utf-8"));
|
|
62
|
+
const parsed = PackageJsonSchema.safeParse(raw);
|
|
63
|
+
if (parsed.success) {
|
|
64
|
+
return parsed.data.version;
|
|
65
|
+
}
|
|
66
|
+
} catch {
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
throw new Error("Could not resolve package version");
|
|
70
|
+
}
|
|
71
|
+
var version = resolveVersion();
|
|
72
|
+
|
|
73
|
+
// src/telemetry/providers.ts
|
|
74
|
+
var DEFAULT_EXPORT_INTERVAL_MS = 6e4;
|
|
75
|
+
var SHUTDOWN_TIMEOUT_MS = 2e3;
|
|
76
|
+
function parseExporterTypes(value) {
|
|
77
|
+
return (value ?? "").split(",").map((item) => item.trim()).filter((item) => item.length > 0 && item !== "none");
|
|
78
|
+
}
|
|
79
|
+
function parsePositiveInteger(value, fallback) {
|
|
80
|
+
const parsed = Number.parseInt(value ?? "", 10);
|
|
81
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
82
|
+
}
|
|
83
|
+
function getProtocol(signal) {
|
|
84
|
+
const signalKey = `OTEL_EXPORTER_OTLP_${signal.toUpperCase()}_PROTOCOL`;
|
|
85
|
+
const configured = process.env[signalKey]?.trim() || process.env.OTEL_EXPORTER_OTLP_PROTOCOL?.trim();
|
|
86
|
+
const protocol = configured || "http/protobuf";
|
|
87
|
+
if (protocol === "grpc" || protocol === "http/json" || protocol === "http/protobuf") {
|
|
88
|
+
return protocol;
|
|
89
|
+
}
|
|
90
|
+
throw new Error(`Unsupported OpenTelemetry protocol: ${protocol}`);
|
|
91
|
+
}
|
|
92
|
+
function parseResourceAttributes(value) {
|
|
93
|
+
const attributes = {};
|
|
94
|
+
for (const entry of value?.split(",") ?? []) {
|
|
95
|
+
const separator = entry.indexOf("=");
|
|
96
|
+
if (separator <= 0) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const key = entry.slice(0, separator).trim();
|
|
100
|
+
const rawValue = entry.slice(separator + 1).trim();
|
|
101
|
+
if (key && rawValue) {
|
|
102
|
+
try {
|
|
103
|
+
attributes[decodeURIComponent(key)] = decodeURIComponent(rawValue);
|
|
104
|
+
} catch {
|
|
105
|
+
attributes[key] = rawValue;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return attributes;
|
|
110
|
+
}
|
|
111
|
+
function createResource() {
|
|
112
|
+
return resourceFromAttributes({
|
|
113
|
+
[ATTR_SERVICE_NAME]: "yukino",
|
|
114
|
+
[ATTR_SERVICE_VERSION]: version,
|
|
115
|
+
...parseResourceAttributes(process.env.OTEL_RESOURCE_ATTRIBUTES),
|
|
116
|
+
...process.env.OTEL_SERVICE_NAME ? { [ATTR_SERVICE_NAME]: process.env.OTEL_SERVICE_NAME } : {}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async function createTraceExporter(protocol) {
|
|
120
|
+
switch (protocol) {
|
|
121
|
+
case "grpc": {
|
|
122
|
+
const { OTLPTraceExporter } = await import("@opentelemetry/exporter-trace-otlp-grpc");
|
|
123
|
+
return new OTLPTraceExporter();
|
|
124
|
+
}
|
|
125
|
+
case "http/json": {
|
|
126
|
+
const { OTLPTraceExporter } = await import("@opentelemetry/exporter-trace-otlp-http");
|
|
127
|
+
return new OTLPTraceExporter();
|
|
128
|
+
}
|
|
129
|
+
case "http/protobuf": {
|
|
130
|
+
const { OTLPTraceExporter } = await import("@opentelemetry/exporter-trace-otlp-proto");
|
|
131
|
+
return new OTLPTraceExporter();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async function createLogExporter(protocol) {
|
|
136
|
+
switch (protocol) {
|
|
137
|
+
case "grpc": {
|
|
138
|
+
const { OTLPLogExporter } = await import("@opentelemetry/exporter-logs-otlp-grpc");
|
|
139
|
+
return new OTLPLogExporter();
|
|
140
|
+
}
|
|
141
|
+
case "http/json": {
|
|
142
|
+
const { OTLPLogExporter } = await import("@opentelemetry/exporter-logs-otlp-http");
|
|
143
|
+
return new OTLPLogExporter();
|
|
144
|
+
}
|
|
145
|
+
case "http/protobuf": {
|
|
146
|
+
const { OTLPLogExporter } = await import("@opentelemetry/exporter-logs-otlp-proto");
|
|
147
|
+
return new OTLPLogExporter();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async function createMetricExporter(protocol) {
|
|
152
|
+
switch (protocol) {
|
|
153
|
+
case "grpc": {
|
|
154
|
+
const { OTLPMetricExporter } = await import("@opentelemetry/exporter-metrics-otlp-grpc");
|
|
155
|
+
return new OTLPMetricExporter();
|
|
156
|
+
}
|
|
157
|
+
case "http/json": {
|
|
158
|
+
const { OTLPMetricExporter } = await import("@opentelemetry/exporter-metrics-otlp-http");
|
|
159
|
+
return new OTLPMetricExporter();
|
|
160
|
+
}
|
|
161
|
+
case "http/protobuf": {
|
|
162
|
+
const { OTLPMetricExporter } = await import("@opentelemetry/exporter-metrics-otlp-proto");
|
|
163
|
+
return new OTLPMetricExporter();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async function createTracerProvider(resource) {
|
|
168
|
+
const processors = [];
|
|
169
|
+
const exporterTypes = parseExporterTypes(process.env.OTEL_TRACES_EXPORTER);
|
|
170
|
+
for (const exporterType of exporterTypes) {
|
|
171
|
+
if (exporterType === "console") {
|
|
172
|
+
processors.push(new BatchSpanProcessor(new ConsoleSpanExporter()));
|
|
173
|
+
} else if (exporterType === "otlp") {
|
|
174
|
+
processors.push(
|
|
175
|
+
new BatchSpanProcessor(
|
|
176
|
+
await createTraceExporter(getProtocol("traces"))
|
|
177
|
+
)
|
|
178
|
+
);
|
|
179
|
+
} else {
|
|
180
|
+
throw new Error(`Unsupported trace exporter: ${exporterType}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (process.env.LANGFUSE_PUBLIC_KEY && process.env.LANGFUSE_SECRET_KEY) {
|
|
184
|
+
processors.push(
|
|
185
|
+
new LangfuseSpanProcessor({
|
|
186
|
+
mediaUploadEnabled: false,
|
|
187
|
+
release: process.env.LANGFUSE_RELEASE ?? version
|
|
188
|
+
})
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
if (processors.length === 0) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
const provider = new BasicTracerProvider({
|
|
195
|
+
resource,
|
|
196
|
+
spanProcessors: processors
|
|
197
|
+
});
|
|
198
|
+
setLangfuseTracerProvider(provider);
|
|
199
|
+
return provider;
|
|
200
|
+
}
|
|
201
|
+
async function createLoggerProvider(resource) {
|
|
202
|
+
const processors = [];
|
|
203
|
+
for (const exporterType of parseExporterTypes(
|
|
204
|
+
process.env.OTEL_LOGS_EXPORTER
|
|
205
|
+
)) {
|
|
206
|
+
let exporter;
|
|
207
|
+
if (exporterType === "console") {
|
|
208
|
+
exporter = new ConsoleLogRecordExporter();
|
|
209
|
+
} else if (exporterType === "otlp") {
|
|
210
|
+
exporter = await createLogExporter(getProtocol("logs"));
|
|
211
|
+
} else {
|
|
212
|
+
throw new Error(`Unsupported log exporter: ${exporterType}`);
|
|
213
|
+
}
|
|
214
|
+
processors.push(new BatchLogRecordProcessor({ exporter }));
|
|
215
|
+
}
|
|
216
|
+
return processors.length > 0 ? new LoggerProvider({ resource, processors }) : null;
|
|
217
|
+
}
|
|
218
|
+
async function createMetricReaders() {
|
|
219
|
+
const readers = [];
|
|
220
|
+
const exportIntervalMillis = parsePositiveInteger(
|
|
221
|
+
process.env.OTEL_METRIC_EXPORT_INTERVAL,
|
|
222
|
+
DEFAULT_EXPORT_INTERVAL_MS
|
|
223
|
+
);
|
|
224
|
+
for (const exporterType of parseExporterTypes(
|
|
225
|
+
process.env.OTEL_METRICS_EXPORTER
|
|
226
|
+
)) {
|
|
227
|
+
if (exporterType === "prometheus") {
|
|
228
|
+
const { PrometheusExporter } = await import("@opentelemetry/exporter-prometheus");
|
|
229
|
+
readers.push(new PrometheusExporter());
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
let exporter;
|
|
233
|
+
if (exporterType === "console") {
|
|
234
|
+
exporter = new ConsoleMetricExporter();
|
|
235
|
+
} else if (exporterType === "otlp") {
|
|
236
|
+
exporter = await createMetricExporter(getProtocol("metrics"));
|
|
237
|
+
} else {
|
|
238
|
+
throw new Error(`Unsupported metric exporter: ${exporterType}`);
|
|
239
|
+
}
|
|
240
|
+
readers.push(
|
|
241
|
+
new PeriodicExportingMetricReader({ exporter, exportIntervalMillis })
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
return readers;
|
|
245
|
+
}
|
|
246
|
+
async function initializeSentry() {
|
|
247
|
+
if (!process.env.SENTRY_DSN) {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
const sentry = await import("@sentry/node");
|
|
251
|
+
sentry.init({
|
|
252
|
+
debug: process.env.SENTRY_DEBUG?.toLowerCase() === "true",
|
|
253
|
+
dsn: process.env.SENTRY_DSN,
|
|
254
|
+
environment: process.env.SENTRY_ENVIRONMENT,
|
|
255
|
+
includeLocalVariables: false,
|
|
256
|
+
integrations: (defaultIntegrations) => defaultIntegrations.filter(
|
|
257
|
+
(integration) => integration.name !== "OnUncaughtException" && integration.name !== "OnUnhandledRejection"
|
|
258
|
+
),
|
|
259
|
+
registerEsmLoaderHooks: false,
|
|
260
|
+
release: process.env.SENTRY_RELEASE ?? version,
|
|
261
|
+
sendDefaultPii: false,
|
|
262
|
+
skipOpenTelemetrySetup: true,
|
|
263
|
+
tracesSampleRate: 0
|
|
264
|
+
});
|
|
265
|
+
return sentry;
|
|
266
|
+
}
|
|
267
|
+
async function safely(operation) {
|
|
268
|
+
try {
|
|
269
|
+
return await operation();
|
|
270
|
+
} catch {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function withTimeout(operation) {
|
|
275
|
+
return new Promise((resolve) => {
|
|
276
|
+
const timer = setTimeout(resolve, SHUTDOWN_TIMEOUT_MS);
|
|
277
|
+
timer.unref();
|
|
278
|
+
void operation.then(
|
|
279
|
+
() => {
|
|
280
|
+
clearTimeout(timer);
|
|
281
|
+
resolve();
|
|
282
|
+
},
|
|
283
|
+
() => {
|
|
284
|
+
clearTimeout(timer);
|
|
285
|
+
resolve();
|
|
286
|
+
}
|
|
287
|
+
);
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
function severityNumber(severity) {
|
|
291
|
+
switch (severity) {
|
|
292
|
+
case "error":
|
|
293
|
+
return SeverityNumber.ERROR;
|
|
294
|
+
case "info":
|
|
295
|
+
return SeverityNumber.INFO;
|
|
296
|
+
case "warn":
|
|
297
|
+
return SeverityNumber.WARN;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function createRootObservation(kind, name, attributes) {
|
|
301
|
+
switch (kind) {
|
|
302
|
+
case "agent":
|
|
303
|
+
return startObservation(
|
|
304
|
+
name,
|
|
305
|
+
{ metadata: attributes },
|
|
306
|
+
{ asType: "agent" }
|
|
307
|
+
);
|
|
308
|
+
case "generation": {
|
|
309
|
+
const model = typeof attributes.model === "string" ? attributes.model : void 0;
|
|
310
|
+
return startObservation(
|
|
311
|
+
name,
|
|
312
|
+
{ metadata: attributes, model },
|
|
313
|
+
{ asType: "generation" }
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
case "tool":
|
|
317
|
+
return startObservation(
|
|
318
|
+
name,
|
|
319
|
+
{ metadata: attributes },
|
|
320
|
+
{ asType: "tool" }
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function createChildObservation(parent, kind, name, attributes) {
|
|
325
|
+
switch (kind) {
|
|
326
|
+
case "agent":
|
|
327
|
+
return parent.startObservation(
|
|
328
|
+
name,
|
|
329
|
+
{ metadata: attributes },
|
|
330
|
+
{ asType: "agent" }
|
|
331
|
+
);
|
|
332
|
+
case "generation": {
|
|
333
|
+
const model = typeof attributes.model === "string" ? attributes.model : void 0;
|
|
334
|
+
return parent.startObservation(
|
|
335
|
+
name,
|
|
336
|
+
{ metadata: attributes, model },
|
|
337
|
+
{ asType: "generation" }
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
case "tool":
|
|
341
|
+
return parent.startObservation(
|
|
342
|
+
name,
|
|
343
|
+
{ metadata: attributes },
|
|
344
|
+
{ asType: "tool" }
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
var ProviderObservation = class _ProviderObservation {
|
|
349
|
+
constructor(observation) {
|
|
350
|
+
this.observation = observation;
|
|
351
|
+
}
|
|
352
|
+
observation;
|
|
353
|
+
end() {
|
|
354
|
+
this.observation.end();
|
|
355
|
+
}
|
|
356
|
+
recordException(error) {
|
|
357
|
+
const errorType = error instanceof Error ? error.name : typeof error;
|
|
358
|
+
this.observation.otelSpan.setAttribute("error.type", errorType);
|
|
359
|
+
this.observation.otelSpan.setStatus({ code: SpanStatusCode.ERROR });
|
|
360
|
+
this.observation.updateOtelSpanAttributes({
|
|
361
|
+
level: "ERROR",
|
|
362
|
+
statusMessage: errorType
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
startChild(kind, name, attributes = {}) {
|
|
366
|
+
return new _ProviderObservation(
|
|
367
|
+
createChildObservation(this.observation, kind, name, attributes)
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
update(update) {
|
|
371
|
+
this.observation.updateOtelSpanAttributes(update);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
var ProviderRuntime = class {
|
|
375
|
+
constructor(tracerProvider, loggerProvider, meterProvider, meter, logger, sentry) {
|
|
376
|
+
this.tracerProvider = tracerProvider;
|
|
377
|
+
this.loggerProvider = loggerProvider;
|
|
378
|
+
this.meterProvider = meterProvider;
|
|
379
|
+
this.meter = meter;
|
|
380
|
+
this.logger = logger;
|
|
381
|
+
this.sentry = sentry;
|
|
382
|
+
}
|
|
383
|
+
tracerProvider;
|
|
384
|
+
loggerProvider;
|
|
385
|
+
meterProvider;
|
|
386
|
+
meter;
|
|
387
|
+
logger;
|
|
388
|
+
sentry;
|
|
389
|
+
counters = /* @__PURE__ */ new Map();
|
|
390
|
+
histograms = /* @__PURE__ */ new Map();
|
|
391
|
+
mode = "unknown";
|
|
392
|
+
captureError(error, context) {
|
|
393
|
+
this.sentry?.captureException(error, {
|
|
394
|
+
tags: { context, mode: this.mode }
|
|
395
|
+
});
|
|
396
|
+
this.emitLog("yukino.error", "error", {
|
|
397
|
+
context,
|
|
398
|
+
"error.type": error instanceof Error ? error.name : typeof error
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
emitLog(name, severity, attributes = {}) {
|
|
402
|
+
this.logger?.emit({
|
|
403
|
+
attributes: { ...attributes, "yukino.mode": this.mode },
|
|
404
|
+
body: name,
|
|
405
|
+
severityNumber: severityNumber(severity),
|
|
406
|
+
severityText: severity.toUpperCase()
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
async flush() {
|
|
410
|
+
const operations = [];
|
|
411
|
+
if (this.tracerProvider) {
|
|
412
|
+
operations.push(this.tracerProvider.forceFlush());
|
|
413
|
+
}
|
|
414
|
+
if (this.loggerProvider) {
|
|
415
|
+
operations.push(this.loggerProvider.forceFlush());
|
|
416
|
+
}
|
|
417
|
+
if (this.meterProvider) {
|
|
418
|
+
operations.push(this.meterProvider.forceFlush());
|
|
419
|
+
}
|
|
420
|
+
if (this.sentry) {
|
|
421
|
+
operations.push(this.sentry.flush(SHUTDOWN_TIMEOUT_MS));
|
|
422
|
+
}
|
|
423
|
+
await withTimeout(Promise.allSettled(operations).then(() => void 0));
|
|
424
|
+
}
|
|
425
|
+
recordMetric(name, kind, value, attributes = {}) {
|
|
426
|
+
if (!this.meter) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const mergedAttributes = { ...attributes, "yukino.mode": this.mode };
|
|
430
|
+
if (kind === "counter") {
|
|
431
|
+
let counter = this.counters.get(name);
|
|
432
|
+
if (!counter) {
|
|
433
|
+
counter = this.meter.createCounter(name);
|
|
434
|
+
this.counters.set(name, counter);
|
|
435
|
+
}
|
|
436
|
+
counter.add(value, mergedAttributes);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
let histogram = this.histograms.get(name);
|
|
440
|
+
if (!histogram) {
|
|
441
|
+
histogram = this.meter.createHistogram(name, { unit: "ms" });
|
|
442
|
+
this.histograms.set(name, histogram);
|
|
443
|
+
}
|
|
444
|
+
histogram.record(value, mergedAttributes);
|
|
445
|
+
}
|
|
446
|
+
setMode(mode) {
|
|
447
|
+
this.mode = mode;
|
|
448
|
+
this.sentry?.setTag("yukino.mode", mode);
|
|
449
|
+
}
|
|
450
|
+
async shutdown() {
|
|
451
|
+
const operations = [];
|
|
452
|
+
if (this.tracerProvider) {
|
|
453
|
+
operations.push(this.tracerProvider.shutdown());
|
|
454
|
+
}
|
|
455
|
+
if (this.loggerProvider) {
|
|
456
|
+
operations.push(this.loggerProvider.shutdown());
|
|
457
|
+
}
|
|
458
|
+
if (this.meterProvider) {
|
|
459
|
+
operations.push(this.meterProvider.shutdown());
|
|
460
|
+
}
|
|
461
|
+
if (this.sentry) {
|
|
462
|
+
operations.push(this.sentry.close(SHUTDOWN_TIMEOUT_MS));
|
|
463
|
+
}
|
|
464
|
+
await withTimeout(Promise.allSettled(operations).then(() => void 0));
|
|
465
|
+
setLangfuseTracerProvider(null);
|
|
466
|
+
}
|
|
467
|
+
startObservation(kind, name, attributes = {}) {
|
|
468
|
+
if (!this.tracerProvider) {
|
|
469
|
+
return {
|
|
470
|
+
end: () => void 0,
|
|
471
|
+
recordException: () => void 0,
|
|
472
|
+
startChild: (childKind, childName, childAttributes) => this.startObservation(childKind, childName, childAttributes),
|
|
473
|
+
update: () => void 0
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
return new ProviderObservation(
|
|
477
|
+
createRootObservation(kind, name, {
|
|
478
|
+
...attributes,
|
|
479
|
+
"yukino.mode": this.mode
|
|
480
|
+
})
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
async function createTelemetryRuntime() {
|
|
485
|
+
const resource = createResource();
|
|
486
|
+
const otelEnabled = process.env.OTEL_SDK_DISABLED?.toLowerCase() !== "true";
|
|
487
|
+
const [tracerProvider, loggerProvider, metricReaders, sentry] = await Promise.all([
|
|
488
|
+
otelEnabled ? safely(() => createTracerProvider(resource)) : Promise.resolve(null),
|
|
489
|
+
otelEnabled ? safely(() => createLoggerProvider(resource)) : Promise.resolve(null),
|
|
490
|
+
otelEnabled ? safely(createMetricReaders) : Promise.resolve(null),
|
|
491
|
+
safely(initializeSentry)
|
|
492
|
+
]);
|
|
493
|
+
const meterProvider = metricReaders && metricReaders.length > 0 ? new MeterProvider({ readers: metricReaders, resource }) : null;
|
|
494
|
+
const meter = meterProvider?.getMeter("@yukino.js/yukino", version) ?? null;
|
|
495
|
+
const logger = loggerProvider?.getLogger("@yukino.js/yukino", version) ?? null;
|
|
496
|
+
return new ProviderRuntime(
|
|
497
|
+
tracerProvider,
|
|
498
|
+
loggerProvider,
|
|
499
|
+
meterProvider,
|
|
500
|
+
meter,
|
|
501
|
+
logger,
|
|
502
|
+
sentry
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
export {
|
|
507
|
+
version,
|
|
508
|
+
version_exports,
|
|
509
|
+
parseExporterTypes,
|
|
510
|
+
createTelemetryRuntime,
|
|
511
|
+
providers_exports
|
|
512
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-MLKGABMK.js";
|
|
4
|
+
|
|
5
|
+
// src/tools/types.ts
|
|
6
|
+
var types_exports = {};
|
|
7
|
+
__export(types_exports, {
|
|
8
|
+
SKIP_DIRS: () => SKIP_DIRS,
|
|
9
|
+
isToolResultContentBlock: () => isToolResultContentBlock,
|
|
10
|
+
normalizeToolResultContentBlock: () => normalizeToolResultContentBlock
|
|
11
|
+
});
|
|
12
|
+
function isRecord(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
var IMAGE_MEDIA_TYPES = /* @__PURE__ */ new Set([
|
|
16
|
+
"image/jpeg",
|
|
17
|
+
"image/png",
|
|
18
|
+
"image/gif",
|
|
19
|
+
"image/webp"
|
|
20
|
+
]);
|
|
21
|
+
function isImageMediaType(value) {
|
|
22
|
+
return IMAGE_MEDIA_TYPES.has(value);
|
|
23
|
+
}
|
|
24
|
+
function normalizeTextBlock(value) {
|
|
25
|
+
return isRecord(value) && value.type === "text" && typeof value.text === "string" ? { type: "text", text: value.text } : null;
|
|
26
|
+
}
|
|
27
|
+
function normalizeImageBlock(value) {
|
|
28
|
+
if (!isRecord(value) || value.type !== "image" || !isRecord(value.source)) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (value.source.type === "url" && typeof value.source.url === "string") {
|
|
32
|
+
return { type: "image", source: { type: "url", url: value.source.url } };
|
|
33
|
+
}
|
|
34
|
+
if (value.source.type === "base64" && typeof value.source.media_type === "string" && isImageMediaType(value.source.media_type) && typeof value.source.data === "string") {
|
|
35
|
+
return {
|
|
36
|
+
type: "image",
|
|
37
|
+
source: {
|
|
38
|
+
type: "base64",
|
|
39
|
+
media_type: value.source.media_type,
|
|
40
|
+
data: value.source.data
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function normalizeDocumentBlock(value) {
|
|
47
|
+
if (value.type !== "document" || !isRecord(value.source)) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
let source = null;
|
|
51
|
+
if (value.source.type === "url" && typeof value.source.url === "string") {
|
|
52
|
+
source = { type: "url", url: value.source.url };
|
|
53
|
+
} else if (value.source.type === "base64" && value.source.media_type === "application/pdf" && typeof value.source.data === "string") {
|
|
54
|
+
source = {
|
|
55
|
+
type: "base64",
|
|
56
|
+
media_type: "application/pdf",
|
|
57
|
+
data: value.source.data
|
|
58
|
+
};
|
|
59
|
+
} else if (value.source.type === "text" && value.source.media_type === "text/plain" && typeof value.source.data === "string") {
|
|
60
|
+
source = {
|
|
61
|
+
type: "text",
|
|
62
|
+
media_type: "text/plain",
|
|
63
|
+
data: value.source.data
|
|
64
|
+
};
|
|
65
|
+
} else if (value.source.type === "content") {
|
|
66
|
+
if (typeof value.source.content === "string") {
|
|
67
|
+
source = { type: "content", content: value.source.content };
|
|
68
|
+
} else if (Array.isArray(value.source.content)) {
|
|
69
|
+
const content = [];
|
|
70
|
+
for (const raw of value.source.content) {
|
|
71
|
+
const block = normalizeTextBlock(raw) ?? normalizeImageBlock(raw);
|
|
72
|
+
if (!block) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
content.push(block);
|
|
76
|
+
}
|
|
77
|
+
source = { type: "content", content };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!source) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
type: "document",
|
|
85
|
+
source,
|
|
86
|
+
...typeof value.title === "string" || value.title === null ? { title: value.title } : {},
|
|
87
|
+
...typeof value.context === "string" || value.context === null ? { context: value.context } : {}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function normalizeToolResultContentBlock(value) {
|
|
91
|
+
const text = normalizeTextBlock(value);
|
|
92
|
+
if (text) {
|
|
93
|
+
return text;
|
|
94
|
+
}
|
|
95
|
+
const image = normalizeImageBlock(value);
|
|
96
|
+
if (image) {
|
|
97
|
+
return image;
|
|
98
|
+
}
|
|
99
|
+
if (!isRecord(value)) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
if (value.type === "tool_reference" && typeof value.tool_name === "string") {
|
|
103
|
+
return { type: "tool_reference", tool_name: value.tool_name };
|
|
104
|
+
}
|
|
105
|
+
if (value.type === "search_result" && typeof value.source === "string" && typeof value.title === "string" && Array.isArray(value.content)) {
|
|
106
|
+
const content = [];
|
|
107
|
+
for (const raw of value.content) {
|
|
108
|
+
const block = normalizeTextBlock(raw);
|
|
109
|
+
if (!block) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
content.push(block);
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
type: "search_result",
|
|
116
|
+
source: value.source,
|
|
117
|
+
title: value.title,
|
|
118
|
+
content
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return normalizeDocumentBlock(value);
|
|
122
|
+
}
|
|
123
|
+
function isToolResultContentBlock(value) {
|
|
124
|
+
return normalizeToolResultContentBlock(value) !== null;
|
|
125
|
+
}
|
|
126
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
127
|
+
".agents",
|
|
128
|
+
".git",
|
|
129
|
+
// Git
|
|
130
|
+
".yukino",
|
|
131
|
+
// Yukino
|
|
132
|
+
".next",
|
|
133
|
+
// Next.js
|
|
134
|
+
".venv",
|
|
135
|
+
// Python venv
|
|
136
|
+
".mypy_cache",
|
|
137
|
+
// Python mypy
|
|
138
|
+
"__pycache__",
|
|
139
|
+
// Python
|
|
140
|
+
"dist",
|
|
141
|
+
// Webpack, Vite
|
|
142
|
+
"node_modules"
|
|
143
|
+
// Node.js
|
|
144
|
+
]);
|
|
145
|
+
|
|
146
|
+
export {
|
|
147
|
+
normalizeToolResultContentBlock,
|
|
148
|
+
SKIP_DIRS,
|
|
149
|
+
types_exports
|
|
150
|
+
};
|