@swifty.js/swifty 0.0.32 → 0.0.33

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.
Files changed (75) hide show
  1. package/README.md +64 -0
  2. package/dist/acp-5WRTN2LL.js +14 -0
  3. package/dist/agent-3CAPJCPD.js +4 -0
  4. package/dist/anthropic-FXRRA63E.js +4 -0
  5. package/dist/{bwrap-TPE6G4BM.js → bwrap-ZTS67W2K.js} +1 -1
  6. package/dist/checker-3O7QF7XV.js +4 -0
  7. package/dist/chunk-2U4IWZ6E.js +4 -0
  8. package/dist/chunk-35X3GW25.js +4 -0
  9. package/dist/{chunk-NERVCUWE.js → chunk-4C3KJLJV.js} +1 -1
  10. package/dist/chunk-4HSQBZBI.js +4 -0
  11. package/dist/{chunk-JMF2DWGY.js → chunk-4PQYUHSN.js} +1 -1
  12. package/dist/chunk-6I3HEMIE.js +4 -0
  13. package/dist/{chunk-TKQ5T5VO.js → chunk-7JQHFZRD.js} +2 -2
  14. package/dist/{chunk-S35E7OYL.js → chunk-C5WLP3DH.js} +1 -1
  15. package/dist/chunk-FUKVR3XO.js +608 -0
  16. package/dist/chunk-FZORZF22.js +16 -0
  17. package/dist/chunk-G2TE2QZM.js +4 -0
  18. package/dist/chunk-I7XJSLRI.js +4 -0
  19. package/dist/{chunk-2EV72T5X.js → chunk-IKQTIDRL.js} +1 -1
  20. package/dist/chunk-IZ7QOBSB.js +4 -0
  21. package/dist/chunk-LC7ZWLIH.js +4 -0
  22. package/dist/chunk-LHSUYZO5.js +4 -0
  23. package/dist/chunk-M4D66APS.js +67 -0
  24. package/dist/chunk-NAAAN2TD.js +60 -0
  25. package/dist/chunk-NCZR3AGA.js +65 -0
  26. package/dist/{server-QMMIYNXW.js → chunk-PXQD6GWP.js} +15 -15
  27. package/dist/{chunk-FPQ2LBL4.js → chunk-QQVDL4QT.js} +1 -1
  28. package/dist/{chunk-TCQ4EB4G.js → chunk-TNF3EHFY.js} +1 -1
  29. package/dist/chunk-XGUH7SGV.js +4 -0
  30. package/dist/chunk-YIKI3EPG.js +150 -0
  31. package/dist/chunk-YKWIZE5D.js +4 -0
  32. package/dist/{devtools-OJ75EP3T.js → devtools-WJM4UVVT.js} +1 -1
  33. package/dist/esm-46WSO26W.js +4 -0
  34. package/dist/esm-4DBD7ONK.js +229 -0
  35. package/dist/esm-6EDGM6QS.js +4 -0
  36. package/dist/esm-D6BB3FBR.js +4 -0
  37. package/dist/esm-P2KEXEEK.js +4 -0
  38. package/dist/esm-XYKZYVLV.js +4 -0
  39. package/dist/esm-YJVVI2QX.js +4 -0
  40. package/dist/getMachineId-bsd-NBOQ3GRQ.js +4 -0
  41. package/dist/getMachineId-darwin-6VBNSUFR.js +5 -0
  42. package/dist/getMachineId-linux-RQ33NIOO.js +4 -0
  43. package/dist/getMachineId-unsupported-IWOYPUHZ.js +4 -0
  44. package/dist/getMachineId-win-ITT3WXP6.js +4 -0
  45. package/dist/lib/{agent-3OEC4SOB.js → agent-NNYCUIOF.js} +1 -1
  46. package/dist/lib/{checker-QNMXPZ7C.js → checker-UPY4CXUL.js} +1 -1
  47. package/dist/lib/{chunk-UH5M7FDP.js → chunk-AFYPVA5C.js} +252 -20
  48. package/dist/lib/{chunk-SOOSTGHI.js → chunk-CFYAZWDA.js} +8 -2
  49. package/dist/lib/chunk-GTHYQZRL.js +31 -0
  50. package/dist/lib/{chunk-4BPKIIQD.js → chunk-LDWFI6MR.js} +6 -4
  51. package/dist/lib/index.d.ts +229 -152
  52. package/dist/lib/index.js +1096 -575
  53. package/dist/lib/providers-UJEWP7C7.js +419 -0
  54. package/dist/lib/{tool-filter-IMIU7CW2.js → tool-filter-BFEINZIA.js} +1 -1
  55. package/dist/main.js +189 -181
  56. package/dist/{node-GXMM4JG3.js → node-A6KBFKOV.js} +1 -1
  57. package/dist/{openai-M7B2TITO.js → openai-WPEICAZ4.js} +1 -1
  58. package/dist/providers-WNYZUMZ3.js +6 -0
  59. package/dist/{seatbelt-3GM2YGXV.js → seatbelt-PSPJ5LBR.js} +1 -1
  60. package/dist/server-YPBLBRDN.js +4 -0
  61. package/dist/src-3A5BCUSZ.js +4 -0
  62. package/dist/src-CRYFVH7Y.js +12 -0
  63. package/dist/src-Y77IB66J.js +4 -0
  64. package/dist/src-ZCW4GCG2.js +4 -0
  65. package/dist/{tool-filter-7LLVAHD5.js → tool-filter-X6IYME2K.js} +1 -1
  66. package/dist/turndown.es-WNOSVZF6.js +83 -0
  67. package/package.json +30 -4
  68. package/dist/agent-2DUTUJFX.js +0 -4
  69. package/dist/anthropic-KR5MXB5I.js +0 -4
  70. package/dist/checker-RKAWOOXC.js +0 -4
  71. package/dist/chunk-4YVJP2CO.js +0 -4
  72. package/dist/chunk-BWWNI2FK.js +0 -121
  73. package/dist/chunk-LTFPTWX4.js +0 -612
  74. package/dist/chunk-TW7RHCDS.js +0 -150
  75. package/dist/chunk-X3UA5OZL.js +0 -4
@@ -0,0 +1,419 @@
1
+ import {
2
+ version
3
+ } from "./chunk-GTHYQZRL.js";
4
+
5
+ // src/telemetry/providers.ts
6
+ import { LangfuseSpanProcessor } from "@langfuse/otel";
7
+ import {
8
+ setLangfuseTracerProvider,
9
+ startObservation
10
+ } from "@langfuse/tracing";
11
+ import { SpanStatusCode } from "@opentelemetry/api";
12
+ import { SeverityNumber } from "@opentelemetry/api-logs";
13
+ import { resourceFromAttributes } from "@opentelemetry/resources";
14
+ import {
15
+ BatchLogRecordProcessor,
16
+ ConsoleLogRecordExporter,
17
+ LoggerProvider
18
+ } from "@opentelemetry/sdk-logs";
19
+ import {
20
+ ConsoleMetricExporter,
21
+ MeterProvider,
22
+ PeriodicExportingMetricReader
23
+ } from "@opentelemetry/sdk-metrics";
24
+ import {
25
+ BasicTracerProvider,
26
+ BatchSpanProcessor,
27
+ ConsoleSpanExporter
28
+ } from "@opentelemetry/sdk-trace-base";
29
+ import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from "@opentelemetry/semantic-conventions";
30
+ var DEFAULT_EXPORT_INTERVAL_MS = 6e4;
31
+ var SHUTDOWN_TIMEOUT_MS = 2e3;
32
+ function parseExporterTypes(value) {
33
+ return (value ?? "").split(",").map((item) => item.trim()).filter((item) => item.length > 0 && item !== "none");
34
+ }
35
+ function parsePositiveInteger(value, fallback) {
36
+ const parsed = Number.parseInt(value ?? "", 10);
37
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
38
+ }
39
+ function getProtocol(signal) {
40
+ const signalKey = `OTEL_EXPORTER_OTLP_${signal.toUpperCase()}_PROTOCOL`;
41
+ const configured = process.env[signalKey]?.trim() || process.env.OTEL_EXPORTER_OTLP_PROTOCOL?.trim();
42
+ const protocol = configured || "http/protobuf";
43
+ if (protocol === "grpc" || protocol === "http/json" || protocol === "http/protobuf") {
44
+ return protocol;
45
+ }
46
+ throw new Error(`Unsupported OpenTelemetry protocol: ${protocol}`);
47
+ }
48
+ function parseResourceAttributes(value) {
49
+ const attributes = {};
50
+ for (const entry of value?.split(",") ?? []) {
51
+ const separator = entry.indexOf("=");
52
+ if (separator <= 0) {
53
+ continue;
54
+ }
55
+ const key = entry.slice(0, separator).trim();
56
+ const rawValue = entry.slice(separator + 1).trim();
57
+ if (key && rawValue) {
58
+ try {
59
+ attributes[decodeURIComponent(key)] = decodeURIComponent(rawValue);
60
+ } catch {
61
+ attributes[key] = rawValue;
62
+ }
63
+ }
64
+ }
65
+ return attributes;
66
+ }
67
+ function createResource() {
68
+ return resourceFromAttributes({
69
+ [ATTR_SERVICE_NAME]: "swifty",
70
+ [ATTR_SERVICE_VERSION]: version,
71
+ ...parseResourceAttributes(process.env.OTEL_RESOURCE_ATTRIBUTES),
72
+ ...process.env.OTEL_SERVICE_NAME ? { [ATTR_SERVICE_NAME]: process.env.OTEL_SERVICE_NAME } : {}
73
+ });
74
+ }
75
+ async function createTraceExporter(protocol) {
76
+ switch (protocol) {
77
+ case "grpc": {
78
+ const { OTLPTraceExporter } = await import("@opentelemetry/exporter-trace-otlp-grpc");
79
+ return new OTLPTraceExporter();
80
+ }
81
+ case "http/json": {
82
+ const { OTLPTraceExporter } = await import("@opentelemetry/exporter-trace-otlp-http");
83
+ return new OTLPTraceExporter();
84
+ }
85
+ case "http/protobuf": {
86
+ const { OTLPTraceExporter } = await import("@opentelemetry/exporter-trace-otlp-proto");
87
+ return new OTLPTraceExporter();
88
+ }
89
+ }
90
+ }
91
+ async function createLogExporter(protocol) {
92
+ switch (protocol) {
93
+ case "grpc": {
94
+ const { OTLPLogExporter } = await import("@opentelemetry/exporter-logs-otlp-grpc");
95
+ return new OTLPLogExporter();
96
+ }
97
+ case "http/json": {
98
+ const { OTLPLogExporter } = await import("@opentelemetry/exporter-logs-otlp-http");
99
+ return new OTLPLogExporter();
100
+ }
101
+ case "http/protobuf": {
102
+ const { OTLPLogExporter } = await import("@opentelemetry/exporter-logs-otlp-proto");
103
+ return new OTLPLogExporter();
104
+ }
105
+ }
106
+ }
107
+ async function createMetricExporter(protocol) {
108
+ switch (protocol) {
109
+ case "grpc": {
110
+ const { OTLPMetricExporter } = await import("@opentelemetry/exporter-metrics-otlp-grpc");
111
+ return new OTLPMetricExporter();
112
+ }
113
+ case "http/json": {
114
+ const { OTLPMetricExporter } = await import("@opentelemetry/exporter-metrics-otlp-http");
115
+ return new OTLPMetricExporter();
116
+ }
117
+ case "http/protobuf": {
118
+ const { OTLPMetricExporter } = await import("@opentelemetry/exporter-metrics-otlp-proto");
119
+ return new OTLPMetricExporter();
120
+ }
121
+ }
122
+ }
123
+ async function createTracerProvider(resource) {
124
+ const processors = [];
125
+ const exporterTypes = parseExporterTypes(process.env.OTEL_TRACES_EXPORTER);
126
+ for (const exporterType of exporterTypes) {
127
+ if (exporterType === "console") {
128
+ processors.push(new BatchSpanProcessor(new ConsoleSpanExporter()));
129
+ } else if (exporterType === "otlp") {
130
+ processors.push(new BatchSpanProcessor(await createTraceExporter(getProtocol("traces"))));
131
+ } else {
132
+ throw new Error(`Unsupported trace exporter: ${exporterType}`);
133
+ }
134
+ }
135
+ if (process.env.LANGFUSE_PUBLIC_KEY && process.env.LANGFUSE_SECRET_KEY) {
136
+ processors.push(
137
+ new LangfuseSpanProcessor({
138
+ mediaUploadEnabled: false,
139
+ release: process.env.LANGFUSE_RELEASE ?? version
140
+ })
141
+ );
142
+ }
143
+ if (processors.length === 0) {
144
+ return null;
145
+ }
146
+ const provider = new BasicTracerProvider({ resource, spanProcessors: processors });
147
+ setLangfuseTracerProvider(provider);
148
+ return provider;
149
+ }
150
+ async function createLoggerProvider(resource) {
151
+ const processors = [];
152
+ for (const exporterType of parseExporterTypes(process.env.OTEL_LOGS_EXPORTER)) {
153
+ let exporter;
154
+ if (exporterType === "console") {
155
+ exporter = new ConsoleLogRecordExporter();
156
+ } else if (exporterType === "otlp") {
157
+ exporter = await createLogExporter(getProtocol("logs"));
158
+ } else {
159
+ throw new Error(`Unsupported log exporter: ${exporterType}`);
160
+ }
161
+ processors.push(new BatchLogRecordProcessor({ exporter }));
162
+ }
163
+ return processors.length > 0 ? new LoggerProvider({ resource, processors }) : null;
164
+ }
165
+ async function createMetricReaders() {
166
+ const readers = [];
167
+ const exportIntervalMillis = parsePositiveInteger(
168
+ process.env.OTEL_METRIC_EXPORT_INTERVAL,
169
+ DEFAULT_EXPORT_INTERVAL_MS
170
+ );
171
+ for (const exporterType of parseExporterTypes(process.env.OTEL_METRICS_EXPORTER)) {
172
+ if (exporterType === "prometheus") {
173
+ const { PrometheusExporter } = await import("@opentelemetry/exporter-prometheus");
174
+ readers.push(new PrometheusExporter());
175
+ continue;
176
+ }
177
+ let exporter;
178
+ if (exporterType === "console") {
179
+ exporter = new ConsoleMetricExporter();
180
+ } else if (exporterType === "otlp") {
181
+ exporter = await createMetricExporter(getProtocol("metrics"));
182
+ } else {
183
+ throw new Error(`Unsupported metric exporter: ${exporterType}`);
184
+ }
185
+ readers.push(new PeriodicExportingMetricReader({ exporter, exportIntervalMillis }));
186
+ }
187
+ return readers;
188
+ }
189
+ async function initializeSentry() {
190
+ if (!process.env.SENTRY_DSN) {
191
+ return null;
192
+ }
193
+ const sentry = await import("@sentry/node");
194
+ sentry.init({
195
+ debug: process.env.SENTRY_DEBUG?.toLowerCase() === "true",
196
+ dsn: process.env.SENTRY_DSN,
197
+ environment: process.env.SENTRY_ENVIRONMENT,
198
+ includeLocalVariables: false,
199
+ integrations: (defaultIntegrations) => defaultIntegrations.filter(
200
+ (integration) => integration.name !== "OnUncaughtException" && integration.name !== "OnUnhandledRejection"
201
+ ),
202
+ registerEsmLoaderHooks: false,
203
+ release: process.env.SENTRY_RELEASE ?? version,
204
+ sendDefaultPii: false,
205
+ skipOpenTelemetrySetup: true,
206
+ tracesSampleRate: 0
207
+ });
208
+ return sentry;
209
+ }
210
+ async function safely(operation) {
211
+ try {
212
+ return await operation();
213
+ } catch {
214
+ return null;
215
+ }
216
+ }
217
+ function withTimeout(operation) {
218
+ return new Promise((resolve) => {
219
+ const timer = setTimeout(resolve, SHUTDOWN_TIMEOUT_MS);
220
+ timer.unref();
221
+ void operation.then(
222
+ () => {
223
+ clearTimeout(timer);
224
+ resolve();
225
+ },
226
+ () => {
227
+ clearTimeout(timer);
228
+ resolve();
229
+ }
230
+ );
231
+ });
232
+ }
233
+ function severityNumber(severity) {
234
+ switch (severity) {
235
+ case "error":
236
+ return SeverityNumber.ERROR;
237
+ case "info":
238
+ return SeverityNumber.INFO;
239
+ case "warn":
240
+ return SeverityNumber.WARN;
241
+ }
242
+ }
243
+ function createRootObservation(kind, name, attributes) {
244
+ switch (kind) {
245
+ case "agent":
246
+ return startObservation(name, { metadata: attributes }, { asType: "agent" });
247
+ case "generation": {
248
+ const model = typeof attributes.model === "string" ? attributes.model : void 0;
249
+ return startObservation(name, { metadata: attributes, model }, { asType: "generation" });
250
+ }
251
+ case "tool":
252
+ return startObservation(name, { metadata: attributes }, { asType: "tool" });
253
+ }
254
+ }
255
+ function createChildObservation(parent, kind, name, attributes) {
256
+ switch (kind) {
257
+ case "agent":
258
+ return parent.startObservation(name, { metadata: attributes }, { asType: "agent" });
259
+ case "generation": {
260
+ const model = typeof attributes.model === "string" ? attributes.model : void 0;
261
+ return parent.startObservation(
262
+ name,
263
+ { metadata: attributes, model },
264
+ { asType: "generation" }
265
+ );
266
+ }
267
+ case "tool":
268
+ return parent.startObservation(name, { metadata: attributes }, { asType: "tool" });
269
+ }
270
+ }
271
+ var ProviderObservation = class _ProviderObservation {
272
+ constructor(observation) {
273
+ this.observation = observation;
274
+ }
275
+ observation;
276
+ end() {
277
+ this.observation.end();
278
+ }
279
+ recordException(error) {
280
+ const errorType = error instanceof Error ? error.name : typeof error;
281
+ this.observation.otelSpan.setAttribute("error.type", errorType);
282
+ this.observation.otelSpan.setStatus({ code: SpanStatusCode.ERROR });
283
+ this.observation.updateOtelSpanAttributes({
284
+ level: "ERROR",
285
+ statusMessage: errorType
286
+ });
287
+ }
288
+ startChild(kind, name, attributes = {}) {
289
+ return new _ProviderObservation(
290
+ createChildObservation(this.observation, kind, name, attributes)
291
+ );
292
+ }
293
+ update(update) {
294
+ this.observation.updateOtelSpanAttributes(update);
295
+ }
296
+ };
297
+ var ProviderRuntime = class {
298
+ constructor(tracerProvider, loggerProvider, meterProvider, meter, logger, sentry) {
299
+ this.tracerProvider = tracerProvider;
300
+ this.loggerProvider = loggerProvider;
301
+ this.meterProvider = meterProvider;
302
+ this.meter = meter;
303
+ this.logger = logger;
304
+ this.sentry = sentry;
305
+ }
306
+ tracerProvider;
307
+ loggerProvider;
308
+ meterProvider;
309
+ meter;
310
+ logger;
311
+ sentry;
312
+ counters = /* @__PURE__ */ new Map();
313
+ histograms = /* @__PURE__ */ new Map();
314
+ mode = "unknown";
315
+ captureError(error, context) {
316
+ this.sentry?.captureException(error, { tags: { context, mode: this.mode } });
317
+ this.emitLog("swifty.error", "error", {
318
+ context,
319
+ "error.type": error instanceof Error ? error.name : typeof error
320
+ });
321
+ }
322
+ emitLog(name, severity, attributes = {}) {
323
+ this.logger?.emit({
324
+ attributes: { ...attributes, "swifty.mode": this.mode },
325
+ body: name,
326
+ severityNumber: severityNumber(severity),
327
+ severityText: severity.toUpperCase()
328
+ });
329
+ }
330
+ async flush() {
331
+ const operations = [];
332
+ if (this.tracerProvider) {
333
+ operations.push(this.tracerProvider.forceFlush());
334
+ }
335
+ if (this.loggerProvider) {
336
+ operations.push(this.loggerProvider.forceFlush());
337
+ }
338
+ if (this.meterProvider) {
339
+ operations.push(this.meterProvider.forceFlush());
340
+ }
341
+ if (this.sentry) {
342
+ operations.push(this.sentry.flush(SHUTDOWN_TIMEOUT_MS));
343
+ }
344
+ await withTimeout(Promise.allSettled(operations).then(() => void 0));
345
+ }
346
+ recordMetric(name, kind, value, attributes = {}) {
347
+ if (!this.meter) {
348
+ return;
349
+ }
350
+ const mergedAttributes = { ...attributes, "swifty.mode": this.mode };
351
+ if (kind === "counter") {
352
+ let counter = this.counters.get(name);
353
+ if (!counter) {
354
+ counter = this.meter.createCounter(name);
355
+ this.counters.set(name, counter);
356
+ }
357
+ counter.add(value, mergedAttributes);
358
+ return;
359
+ }
360
+ let histogram = this.histograms.get(name);
361
+ if (!histogram) {
362
+ histogram = this.meter.createHistogram(name, { unit: "ms" });
363
+ this.histograms.set(name, histogram);
364
+ }
365
+ histogram.record(value, mergedAttributes);
366
+ }
367
+ setMode(mode) {
368
+ this.mode = mode;
369
+ this.sentry?.setTag("swifty.mode", mode);
370
+ }
371
+ async shutdown() {
372
+ const operations = [];
373
+ if (this.tracerProvider) {
374
+ operations.push(this.tracerProvider.shutdown());
375
+ }
376
+ if (this.loggerProvider) {
377
+ operations.push(this.loggerProvider.shutdown());
378
+ }
379
+ if (this.meterProvider) {
380
+ operations.push(this.meterProvider.shutdown());
381
+ }
382
+ if (this.sentry) {
383
+ operations.push(this.sentry.close(SHUTDOWN_TIMEOUT_MS));
384
+ }
385
+ await withTimeout(Promise.allSettled(operations).then(() => void 0));
386
+ setLangfuseTracerProvider(null);
387
+ }
388
+ startObservation(kind, name, attributes = {}) {
389
+ if (!this.tracerProvider) {
390
+ return {
391
+ end: () => void 0,
392
+ recordException: () => void 0,
393
+ startChild: (childKind, childName, childAttributes) => this.startObservation(childKind, childName, childAttributes),
394
+ update: () => void 0
395
+ };
396
+ }
397
+ return new ProviderObservation(
398
+ createRootObservation(kind, name, { ...attributes, "swifty.mode": this.mode })
399
+ );
400
+ }
401
+ };
402
+ async function createTelemetryRuntime() {
403
+ const resource = createResource();
404
+ const otelEnabled = process.env.OTEL_SDK_DISABLED?.toLowerCase() !== "true";
405
+ const [tracerProvider, loggerProvider, metricReaders, sentry] = await Promise.all([
406
+ otelEnabled ? safely(() => createTracerProvider(resource)) : Promise.resolve(null),
407
+ otelEnabled ? safely(() => createLoggerProvider(resource)) : Promise.resolve(null),
408
+ otelEnabled ? safely(createMetricReaders) : Promise.resolve(null),
409
+ safely(initializeSentry)
410
+ ]);
411
+ const meterProvider = metricReaders && metricReaders.length > 0 ? new MeterProvider({ readers: metricReaders, resource }) : null;
412
+ const meter = meterProvider?.getMeter("@swifty.js/swifty", version) ?? null;
413
+ const logger = loggerProvider?.getLogger("@swifty.js/swifty", version) ?? null;
414
+ return new ProviderRuntime(tracerProvider, loggerProvider, meterProvider, meter, logger, sentry);
415
+ }
416
+ export {
417
+ createTelemetryRuntime,
418
+ parseExporterTypes
419
+ };
@@ -7,7 +7,7 @@ import {
7
7
  TEAMMATE_DISALLOWED_TOOLS,
8
8
  cloneRegistryForFork,
9
9
  filterToolsForAgent
10
- } from "./chunk-4BPKIIQD.js";
10
+ } from "./chunk-LDWFI6MR.js";
11
11
  export {
12
12
  ASYNC_AGENT_ALLOWED_TOOLS,
13
13
  CUSTOM_AGENT_DISALLOWED_TOOLS,