@swifty.js/swifty 0.0.32 → 0.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -0
- package/dist/acp-A4KRKOHD.js +14 -0
- package/dist/agent-VDWIGFIV.js +4 -0
- package/dist/anthropic-AR2Y4FBR.js +4 -0
- package/dist/bwrap-4KOC7P3X.js +4 -0
- package/dist/chunk-2U4IWZ6E.js +4 -0
- package/dist/{chunk-2EV72T5X.js → chunk-325L2ILZ.js} +1 -1
- package/dist/chunk-35X3GW25.js +4 -0
- package/dist/chunk-44LPRRYU.js +60 -0
- package/dist/chunk-4B4SGVJH.js +164 -0
- package/dist/chunk-5W2TCASL.js +4 -0
- package/dist/chunk-6I3HEMIE.js +4 -0
- package/dist/{chunk-TKQ5T5VO.js → chunk-7JQHFZRD.js} +2 -2
- package/dist/chunk-F4FOFPKL.js +611 -0
- package/dist/chunk-FZORZF22.js +16 -0
- package/dist/chunk-G2TE2QZM.js +4 -0
- package/dist/{chunk-JMF2DWGY.js → chunk-H56UQALW.js} +1 -1
- package/dist/chunk-IOLGXPUQ.js +6 -0
- package/dist/chunk-IXCJZNBB.js +5 -0
- package/dist/chunk-IZ7QOBSB.js +4 -0
- package/dist/chunk-JC44NVST.js +4 -0
- package/dist/chunk-LC7ZWLIH.js +4 -0
- package/dist/chunk-M4D66APS.js +67 -0
- package/dist/chunk-NCZR3AGA.js +65 -0
- package/dist/chunk-NDPYUGE5.js +5 -0
- package/dist/chunk-PH643I2P.js +4 -0
- package/dist/{chunk-FPQ2LBL4.js → chunk-QQVDL4QT.js} +1 -1
- package/dist/{chunk-TCQ4EB4G.js → chunk-TNF3EHFY.js} +1 -1
- package/dist/{server-QMMIYNXW.js → chunk-TOM34LJB.js} +16 -16
- package/dist/{chunk-NERVCUWE.js → chunk-UJGMTIYO.js} +1 -1
- package/dist/chunk-XGUH7SGV.js +4 -0
- package/dist/chunk-YBS5ATGZ.js +4 -0
- package/dist/chunk-YKWIZE5D.js +4 -0
- package/dist/{devtools-OJ75EP3T.js → devtools-WJM4UVVT.js} +1 -1
- package/dist/esm-46WSO26W.js +4 -0
- package/dist/esm-6EDGM6QS.js +4 -0
- package/dist/esm-D6BB3FBR.js +4 -0
- package/dist/esm-P2KEXEEK.js +4 -0
- package/dist/esm-VBV56AO5.js +229 -0
- package/dist/esm-XYKZYVLV.js +4 -0
- package/dist/esm-YJVVI2QX.js +4 -0
- package/dist/getMachineId-bsd-NBOQ3GRQ.js +4 -0
- package/dist/getMachineId-darwin-6VBNSUFR.js +5 -0
- package/dist/getMachineId-linux-RQ33NIOO.js +4 -0
- package/dist/getMachineId-unsupported-IWOYPUHZ.js +4 -0
- package/dist/getMachineId-win-ITT3WXP6.js +4 -0
- package/dist/lib/agent-TC4HSVMS.js +16 -0
- package/dist/lib/{anthropic-B33M2AVN.js → anthropic-FKIGL7NL.js} +6 -5
- package/dist/lib/bwrap-2OL7VPSO.js +7 -0
- package/dist/lib/{chunk-FODSMOWP.js → chunk-6V7RW6HA.js} +34 -16
- package/dist/lib/{chunk-TJLAJGG4.js → chunk-ALQHMYOZ.js} +14 -3
- package/dist/lib/{chunk-XT67KGWE.js → chunk-BQFVUVLI.js} +12 -2
- package/dist/lib/chunk-FFM2LB4C.js +132 -0
- package/dist/lib/{chunk-VUD72RTY.js → chunk-FLKB4BK7.js} +16 -5
- package/dist/lib/{chunk-3OFLDUAW.js → chunk-HQSYRTER.js} +96 -49
- package/dist/lib/{chunk-4BPKIIQD.js → chunk-LRN4MOQ3.js} +31 -5
- package/dist/lib/chunk-MLKGABMK.js +9 -0
- package/dist/lib/chunk-OJTISIYU.js +462 -0
- package/dist/lib/{chunk-BCBD34D2.js → chunk-OLFXCZVH.js} +25 -7
- package/dist/lib/{chunk-SOOSTGHI.js → chunk-RUDYC7OS.js} +32 -48
- package/dist/lib/{chunk-UH5M7FDP.js → chunk-S5VWPTME.js} +1189 -126
- package/dist/lib/chunk-YIWNQ7OA.js +47 -0
- package/dist/lib/{chunk-3XCGUKGJ.js → chunk-ZPIF7IJN.js} +219 -6
- package/dist/lib/index.d.ts +3267 -1143
- package/dist/lib/index.js +13214 -12207
- package/dist/lib/{openai-C2PZFGJ2.js → openai-ZWIYIBLC.js} +4 -3
- package/dist/lib/{checker-QNMXPZ7C.js → permissions-BW4QPZXV.js} +4 -3
- package/dist/lib/providers-ROWSB6ND.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-IMIU7CW2.js → tool-filter-QU4LOZII.js} +2 -1
- package/dist/main.js +231 -190
- package/dist/{node-GXMM4JG3.js → node-A6KBFKOV.js} +1 -1
- package/dist/{openai-M7B2TITO.js → openai-7LMX5HKW.js} +1 -1
- package/dist/permissions-74IHQW76.js +4 -0
- package/dist/providers-2J4JJYQD.js +4 -0
- package/dist/sandbox-runtime-RVW4BK3L.js +4 -0
- package/dist/seatbelt-GMQUP6SV.js +4 -0
- package/dist/server-ZYK4L22D.js +4 -0
- package/dist/src-3A5BCUSZ.js +4 -0
- package/dist/src-CRYFVH7Y.js +12 -0
- package/dist/src-Y77IB66J.js +4 -0
- package/dist/src-ZCW4GCG2.js +4 -0
- package/dist/{tool-filter-7LLVAHD5.js → tool-filter-U5SSL3LR.js} +1 -1
- package/dist/turndown.es-WNOSVZF6.js +83 -0
- package/package.json +34 -5
- package/dist/agent-2DUTUJFX.js +0 -4
- package/dist/anthropic-KR5MXB5I.js +0 -4
- package/dist/bwrap-TPE6G4BM.js +0 -4
- package/dist/checker-RKAWOOXC.js +0 -4
- package/dist/chunk-4YVJP2CO.js +0 -4
- package/dist/chunk-BWWNI2FK.js +0 -121
- package/dist/chunk-LTFPTWX4.js +0 -612
- package/dist/chunk-S35E7OYL.js +0 -5
- package/dist/chunk-TW7RHCDS.js +0 -150
- package/dist/chunk-X3UA5OZL.js +0 -4
- package/dist/lib/agent-3OEC4SOB.js +0 -10
- package/dist/lib/bwrap-QRGPUP4J.js +0 -6
- package/dist/lib/chunk-ORSYNBMM.js +0 -38
- package/dist/lib/seatbelt-FT5IY73W.js +0 -6
- package/dist/seatbelt-3GM2YGXV.js +0 -5
|
@@ -0,0 +1,462 @@
|
|
|
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 { SpanStatusCode } from "@opentelemetry/api";
|
|
17
|
+
import { SeverityNumber } from "@opentelemetry/api-logs";
|
|
18
|
+
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
19
|
+
import {
|
|
20
|
+
BatchLogRecordProcessor,
|
|
21
|
+
ConsoleLogRecordExporter,
|
|
22
|
+
LoggerProvider
|
|
23
|
+
} from "@opentelemetry/sdk-logs";
|
|
24
|
+
import {
|
|
25
|
+
ConsoleMetricExporter,
|
|
26
|
+
MeterProvider,
|
|
27
|
+
PeriodicExportingMetricReader
|
|
28
|
+
} from "@opentelemetry/sdk-metrics";
|
|
29
|
+
import {
|
|
30
|
+
BasicTracerProvider,
|
|
31
|
+
BatchSpanProcessor,
|
|
32
|
+
ConsoleSpanExporter
|
|
33
|
+
} from "@opentelemetry/sdk-trace-base";
|
|
34
|
+
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from "@opentelemetry/semantic-conventions";
|
|
35
|
+
|
|
36
|
+
// src/version.ts
|
|
37
|
+
var version_exports = {};
|
|
38
|
+
__export(version_exports, {
|
|
39
|
+
version: () => version
|
|
40
|
+
});
|
|
41
|
+
import { readFileSync } from "fs";
|
|
42
|
+
import path from "path";
|
|
43
|
+
import { fileURLToPath } from "url";
|
|
44
|
+
import { z } from "zod";
|
|
45
|
+
var PackageJsonSchema = z.object({
|
|
46
|
+
version: z.string()
|
|
47
|
+
});
|
|
48
|
+
function resolveVersion() {
|
|
49
|
+
if (true) {
|
|
50
|
+
return "0.0.35";
|
|
51
|
+
}
|
|
52
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
53
|
+
for (const levels of ["..", "../.."]) {
|
|
54
|
+
const candidate = path.resolve(here, levels, "package.json");
|
|
55
|
+
try {
|
|
56
|
+
const raw = JSON.parse(readFileSync(candidate, "utf-8"));
|
|
57
|
+
const parsed = PackageJsonSchema.safeParse(raw);
|
|
58
|
+
if (parsed.success) {
|
|
59
|
+
return parsed.data.version;
|
|
60
|
+
}
|
|
61
|
+
} catch {
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
throw new Error("Could not resolve package version");
|
|
65
|
+
}
|
|
66
|
+
var version = resolveVersion();
|
|
67
|
+
|
|
68
|
+
// src/telemetry/providers.ts
|
|
69
|
+
var DEFAULT_EXPORT_INTERVAL_MS = 6e4;
|
|
70
|
+
var SHUTDOWN_TIMEOUT_MS = 2e3;
|
|
71
|
+
function parseExporterTypes(value) {
|
|
72
|
+
return (value ?? "").split(",").map((item) => item.trim()).filter((item) => item.length > 0 && item !== "none");
|
|
73
|
+
}
|
|
74
|
+
function parsePositiveInteger(value, fallback) {
|
|
75
|
+
const parsed = Number.parseInt(value ?? "", 10);
|
|
76
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
77
|
+
}
|
|
78
|
+
function getProtocol(signal) {
|
|
79
|
+
const signalKey = `OTEL_EXPORTER_OTLP_${signal.toUpperCase()}_PROTOCOL`;
|
|
80
|
+
const configured = process.env[signalKey]?.trim() || process.env.OTEL_EXPORTER_OTLP_PROTOCOL?.trim();
|
|
81
|
+
const protocol = configured || "http/protobuf";
|
|
82
|
+
if (protocol === "grpc" || protocol === "http/json" || protocol === "http/protobuf") {
|
|
83
|
+
return protocol;
|
|
84
|
+
}
|
|
85
|
+
throw new Error(`Unsupported OpenTelemetry protocol: ${protocol}`);
|
|
86
|
+
}
|
|
87
|
+
function parseResourceAttributes(value) {
|
|
88
|
+
const attributes = {};
|
|
89
|
+
for (const entry of value?.split(",") ?? []) {
|
|
90
|
+
const separator = entry.indexOf("=");
|
|
91
|
+
if (separator <= 0) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const key = entry.slice(0, separator).trim();
|
|
95
|
+
const rawValue = entry.slice(separator + 1).trim();
|
|
96
|
+
if (key && rawValue) {
|
|
97
|
+
try {
|
|
98
|
+
attributes[decodeURIComponent(key)] = decodeURIComponent(rawValue);
|
|
99
|
+
} catch {
|
|
100
|
+
attributes[key] = rawValue;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return attributes;
|
|
105
|
+
}
|
|
106
|
+
function createResource() {
|
|
107
|
+
return resourceFromAttributes({
|
|
108
|
+
[ATTR_SERVICE_NAME]: "swifty",
|
|
109
|
+
[ATTR_SERVICE_VERSION]: version,
|
|
110
|
+
...parseResourceAttributes(process.env.OTEL_RESOURCE_ATTRIBUTES),
|
|
111
|
+
...process.env.OTEL_SERVICE_NAME ? { [ATTR_SERVICE_NAME]: process.env.OTEL_SERVICE_NAME } : {}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
async function createTraceExporter(protocol) {
|
|
115
|
+
switch (protocol) {
|
|
116
|
+
case "grpc": {
|
|
117
|
+
const { OTLPTraceExporter } = await import("@opentelemetry/exporter-trace-otlp-grpc");
|
|
118
|
+
return new OTLPTraceExporter();
|
|
119
|
+
}
|
|
120
|
+
case "http/json": {
|
|
121
|
+
const { OTLPTraceExporter } = await import("@opentelemetry/exporter-trace-otlp-http");
|
|
122
|
+
return new OTLPTraceExporter();
|
|
123
|
+
}
|
|
124
|
+
case "http/protobuf": {
|
|
125
|
+
const { OTLPTraceExporter } = await import("@opentelemetry/exporter-trace-otlp-proto");
|
|
126
|
+
return new OTLPTraceExporter();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async function createLogExporter(protocol) {
|
|
131
|
+
switch (protocol) {
|
|
132
|
+
case "grpc": {
|
|
133
|
+
const { OTLPLogExporter } = await import("@opentelemetry/exporter-logs-otlp-grpc");
|
|
134
|
+
return new OTLPLogExporter();
|
|
135
|
+
}
|
|
136
|
+
case "http/json": {
|
|
137
|
+
const { OTLPLogExporter } = await import("@opentelemetry/exporter-logs-otlp-http");
|
|
138
|
+
return new OTLPLogExporter();
|
|
139
|
+
}
|
|
140
|
+
case "http/protobuf": {
|
|
141
|
+
const { OTLPLogExporter } = await import("@opentelemetry/exporter-logs-otlp-proto");
|
|
142
|
+
return new OTLPLogExporter();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async function createMetricExporter(protocol) {
|
|
147
|
+
switch (protocol) {
|
|
148
|
+
case "grpc": {
|
|
149
|
+
const { OTLPMetricExporter } = await import("@opentelemetry/exporter-metrics-otlp-grpc");
|
|
150
|
+
return new OTLPMetricExporter();
|
|
151
|
+
}
|
|
152
|
+
case "http/json": {
|
|
153
|
+
const { OTLPMetricExporter } = await import("@opentelemetry/exporter-metrics-otlp-http");
|
|
154
|
+
return new OTLPMetricExporter();
|
|
155
|
+
}
|
|
156
|
+
case "http/protobuf": {
|
|
157
|
+
const { OTLPMetricExporter } = await import("@opentelemetry/exporter-metrics-otlp-proto");
|
|
158
|
+
return new OTLPMetricExporter();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async function createTracerProvider(resource) {
|
|
163
|
+
const processors = [];
|
|
164
|
+
const exporterTypes = parseExporterTypes(process.env.OTEL_TRACES_EXPORTER);
|
|
165
|
+
for (const exporterType of exporterTypes) {
|
|
166
|
+
if (exporterType === "console") {
|
|
167
|
+
processors.push(new BatchSpanProcessor(new ConsoleSpanExporter()));
|
|
168
|
+
} else if (exporterType === "otlp") {
|
|
169
|
+
processors.push(new BatchSpanProcessor(await createTraceExporter(getProtocol("traces"))));
|
|
170
|
+
} else {
|
|
171
|
+
throw new Error(`Unsupported trace exporter: ${exporterType}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (process.env.LANGFUSE_PUBLIC_KEY && process.env.LANGFUSE_SECRET_KEY) {
|
|
175
|
+
processors.push(
|
|
176
|
+
new LangfuseSpanProcessor({
|
|
177
|
+
mediaUploadEnabled: false,
|
|
178
|
+
release: process.env.LANGFUSE_RELEASE ?? version
|
|
179
|
+
})
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
if (processors.length === 0) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
const provider = new BasicTracerProvider({ resource, spanProcessors: processors });
|
|
186
|
+
setLangfuseTracerProvider(provider);
|
|
187
|
+
return provider;
|
|
188
|
+
}
|
|
189
|
+
async function createLoggerProvider(resource) {
|
|
190
|
+
const processors = [];
|
|
191
|
+
for (const exporterType of parseExporterTypes(process.env.OTEL_LOGS_EXPORTER)) {
|
|
192
|
+
let exporter;
|
|
193
|
+
if (exporterType === "console") {
|
|
194
|
+
exporter = new ConsoleLogRecordExporter();
|
|
195
|
+
} else if (exporterType === "otlp") {
|
|
196
|
+
exporter = await createLogExporter(getProtocol("logs"));
|
|
197
|
+
} else {
|
|
198
|
+
throw new Error(`Unsupported log exporter: ${exporterType}`);
|
|
199
|
+
}
|
|
200
|
+
processors.push(new BatchLogRecordProcessor({ exporter }));
|
|
201
|
+
}
|
|
202
|
+
return processors.length > 0 ? new LoggerProvider({ resource, processors }) : null;
|
|
203
|
+
}
|
|
204
|
+
async function createMetricReaders() {
|
|
205
|
+
const readers = [];
|
|
206
|
+
const exportIntervalMillis = parsePositiveInteger(
|
|
207
|
+
process.env.OTEL_METRIC_EXPORT_INTERVAL,
|
|
208
|
+
DEFAULT_EXPORT_INTERVAL_MS
|
|
209
|
+
);
|
|
210
|
+
for (const exporterType of parseExporterTypes(process.env.OTEL_METRICS_EXPORTER)) {
|
|
211
|
+
if (exporterType === "prometheus") {
|
|
212
|
+
const { PrometheusExporter } = await import("@opentelemetry/exporter-prometheus");
|
|
213
|
+
readers.push(new PrometheusExporter());
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
let exporter;
|
|
217
|
+
if (exporterType === "console") {
|
|
218
|
+
exporter = new ConsoleMetricExporter();
|
|
219
|
+
} else if (exporterType === "otlp") {
|
|
220
|
+
exporter = await createMetricExporter(getProtocol("metrics"));
|
|
221
|
+
} else {
|
|
222
|
+
throw new Error(`Unsupported metric exporter: ${exporterType}`);
|
|
223
|
+
}
|
|
224
|
+
readers.push(new PeriodicExportingMetricReader({ exporter, exportIntervalMillis }));
|
|
225
|
+
}
|
|
226
|
+
return readers;
|
|
227
|
+
}
|
|
228
|
+
async function initializeSentry() {
|
|
229
|
+
if (!process.env.SENTRY_DSN) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
const sentry = await import("@sentry/node");
|
|
233
|
+
sentry.init({
|
|
234
|
+
debug: process.env.SENTRY_DEBUG?.toLowerCase() === "true",
|
|
235
|
+
dsn: process.env.SENTRY_DSN,
|
|
236
|
+
environment: process.env.SENTRY_ENVIRONMENT,
|
|
237
|
+
includeLocalVariables: false,
|
|
238
|
+
integrations: (defaultIntegrations) => defaultIntegrations.filter(
|
|
239
|
+
(integration) => integration.name !== "OnUncaughtException" && integration.name !== "OnUnhandledRejection"
|
|
240
|
+
),
|
|
241
|
+
registerEsmLoaderHooks: false,
|
|
242
|
+
release: process.env.SENTRY_RELEASE ?? version,
|
|
243
|
+
sendDefaultPii: false,
|
|
244
|
+
skipOpenTelemetrySetup: true,
|
|
245
|
+
tracesSampleRate: 0
|
|
246
|
+
});
|
|
247
|
+
return sentry;
|
|
248
|
+
}
|
|
249
|
+
async function safely(operation) {
|
|
250
|
+
try {
|
|
251
|
+
return await operation();
|
|
252
|
+
} catch {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function withTimeout(operation) {
|
|
257
|
+
return new Promise((resolve) => {
|
|
258
|
+
const timer = setTimeout(resolve, SHUTDOWN_TIMEOUT_MS);
|
|
259
|
+
timer.unref();
|
|
260
|
+
void operation.then(
|
|
261
|
+
() => {
|
|
262
|
+
clearTimeout(timer);
|
|
263
|
+
resolve();
|
|
264
|
+
},
|
|
265
|
+
() => {
|
|
266
|
+
clearTimeout(timer);
|
|
267
|
+
resolve();
|
|
268
|
+
}
|
|
269
|
+
);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
function severityNumber(severity) {
|
|
273
|
+
switch (severity) {
|
|
274
|
+
case "error":
|
|
275
|
+
return SeverityNumber.ERROR;
|
|
276
|
+
case "info":
|
|
277
|
+
return SeverityNumber.INFO;
|
|
278
|
+
case "warn":
|
|
279
|
+
return SeverityNumber.WARN;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function createRootObservation(kind, name, attributes) {
|
|
283
|
+
switch (kind) {
|
|
284
|
+
case "agent":
|
|
285
|
+
return startObservation(name, { metadata: attributes }, { asType: "agent" });
|
|
286
|
+
case "generation": {
|
|
287
|
+
const model = typeof attributes.model === "string" ? attributes.model : void 0;
|
|
288
|
+
return startObservation(name, { metadata: attributes, model }, { asType: "generation" });
|
|
289
|
+
}
|
|
290
|
+
case "tool":
|
|
291
|
+
return startObservation(name, { metadata: attributes }, { asType: "tool" });
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function createChildObservation(parent, kind, name, attributes) {
|
|
295
|
+
switch (kind) {
|
|
296
|
+
case "agent":
|
|
297
|
+
return parent.startObservation(name, { metadata: attributes }, { asType: "agent" });
|
|
298
|
+
case "generation": {
|
|
299
|
+
const model = typeof attributes.model === "string" ? attributes.model : void 0;
|
|
300
|
+
return parent.startObservation(
|
|
301
|
+
name,
|
|
302
|
+
{ metadata: attributes, model },
|
|
303
|
+
{ asType: "generation" }
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
case "tool":
|
|
307
|
+
return parent.startObservation(name, { metadata: attributes }, { asType: "tool" });
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
var ProviderObservation = class _ProviderObservation {
|
|
311
|
+
constructor(observation) {
|
|
312
|
+
this.observation = observation;
|
|
313
|
+
}
|
|
314
|
+
observation;
|
|
315
|
+
end() {
|
|
316
|
+
this.observation.end();
|
|
317
|
+
}
|
|
318
|
+
recordException(error) {
|
|
319
|
+
const errorType = error instanceof Error ? error.name : typeof error;
|
|
320
|
+
this.observation.otelSpan.setAttribute("error.type", errorType);
|
|
321
|
+
this.observation.otelSpan.setStatus({ code: SpanStatusCode.ERROR });
|
|
322
|
+
this.observation.updateOtelSpanAttributes({
|
|
323
|
+
level: "ERROR",
|
|
324
|
+
statusMessage: errorType
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
startChild(kind, name, attributes = {}) {
|
|
328
|
+
return new _ProviderObservation(
|
|
329
|
+
createChildObservation(this.observation, kind, name, attributes)
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
update(update) {
|
|
333
|
+
this.observation.updateOtelSpanAttributes(update);
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
var ProviderRuntime = class {
|
|
337
|
+
constructor(tracerProvider, loggerProvider, meterProvider, meter, logger, sentry) {
|
|
338
|
+
this.tracerProvider = tracerProvider;
|
|
339
|
+
this.loggerProvider = loggerProvider;
|
|
340
|
+
this.meterProvider = meterProvider;
|
|
341
|
+
this.meter = meter;
|
|
342
|
+
this.logger = logger;
|
|
343
|
+
this.sentry = sentry;
|
|
344
|
+
}
|
|
345
|
+
tracerProvider;
|
|
346
|
+
loggerProvider;
|
|
347
|
+
meterProvider;
|
|
348
|
+
meter;
|
|
349
|
+
logger;
|
|
350
|
+
sentry;
|
|
351
|
+
counters = /* @__PURE__ */ new Map();
|
|
352
|
+
histograms = /* @__PURE__ */ new Map();
|
|
353
|
+
mode = "unknown";
|
|
354
|
+
captureError(error, context) {
|
|
355
|
+
this.sentry?.captureException(error, { tags: { context, mode: this.mode } });
|
|
356
|
+
this.emitLog("swifty.error", "error", {
|
|
357
|
+
context,
|
|
358
|
+
"error.type": error instanceof Error ? error.name : typeof error
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
emitLog(name, severity, attributes = {}) {
|
|
362
|
+
this.logger?.emit({
|
|
363
|
+
attributes: { ...attributes, "swifty.mode": this.mode },
|
|
364
|
+
body: name,
|
|
365
|
+
severityNumber: severityNumber(severity),
|
|
366
|
+
severityText: severity.toUpperCase()
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
async flush() {
|
|
370
|
+
const operations = [];
|
|
371
|
+
if (this.tracerProvider) {
|
|
372
|
+
operations.push(this.tracerProvider.forceFlush());
|
|
373
|
+
}
|
|
374
|
+
if (this.loggerProvider) {
|
|
375
|
+
operations.push(this.loggerProvider.forceFlush());
|
|
376
|
+
}
|
|
377
|
+
if (this.meterProvider) {
|
|
378
|
+
operations.push(this.meterProvider.forceFlush());
|
|
379
|
+
}
|
|
380
|
+
if (this.sentry) {
|
|
381
|
+
operations.push(this.sentry.flush(SHUTDOWN_TIMEOUT_MS));
|
|
382
|
+
}
|
|
383
|
+
await withTimeout(Promise.allSettled(operations).then(() => void 0));
|
|
384
|
+
}
|
|
385
|
+
recordMetric(name, kind, value, attributes = {}) {
|
|
386
|
+
if (!this.meter) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
const mergedAttributes = { ...attributes, "swifty.mode": this.mode };
|
|
390
|
+
if (kind === "counter") {
|
|
391
|
+
let counter = this.counters.get(name);
|
|
392
|
+
if (!counter) {
|
|
393
|
+
counter = this.meter.createCounter(name);
|
|
394
|
+
this.counters.set(name, counter);
|
|
395
|
+
}
|
|
396
|
+
counter.add(value, mergedAttributes);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
let histogram = this.histograms.get(name);
|
|
400
|
+
if (!histogram) {
|
|
401
|
+
histogram = this.meter.createHistogram(name, { unit: "ms" });
|
|
402
|
+
this.histograms.set(name, histogram);
|
|
403
|
+
}
|
|
404
|
+
histogram.record(value, mergedAttributes);
|
|
405
|
+
}
|
|
406
|
+
setMode(mode) {
|
|
407
|
+
this.mode = mode;
|
|
408
|
+
this.sentry?.setTag("swifty.mode", mode);
|
|
409
|
+
}
|
|
410
|
+
async shutdown() {
|
|
411
|
+
const operations = [];
|
|
412
|
+
if (this.tracerProvider) {
|
|
413
|
+
operations.push(this.tracerProvider.shutdown());
|
|
414
|
+
}
|
|
415
|
+
if (this.loggerProvider) {
|
|
416
|
+
operations.push(this.loggerProvider.shutdown());
|
|
417
|
+
}
|
|
418
|
+
if (this.meterProvider) {
|
|
419
|
+
operations.push(this.meterProvider.shutdown());
|
|
420
|
+
}
|
|
421
|
+
if (this.sentry) {
|
|
422
|
+
operations.push(this.sentry.close(SHUTDOWN_TIMEOUT_MS));
|
|
423
|
+
}
|
|
424
|
+
await withTimeout(Promise.allSettled(operations).then(() => void 0));
|
|
425
|
+
setLangfuseTracerProvider(null);
|
|
426
|
+
}
|
|
427
|
+
startObservation(kind, name, attributes = {}) {
|
|
428
|
+
if (!this.tracerProvider) {
|
|
429
|
+
return {
|
|
430
|
+
end: () => void 0,
|
|
431
|
+
recordException: () => void 0,
|
|
432
|
+
startChild: (childKind, childName, childAttributes) => this.startObservation(childKind, childName, childAttributes),
|
|
433
|
+
update: () => void 0
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
return new ProviderObservation(
|
|
437
|
+
createRootObservation(kind, name, { ...attributes, "swifty.mode": this.mode })
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
async function createTelemetryRuntime() {
|
|
442
|
+
const resource = createResource();
|
|
443
|
+
const otelEnabled = process.env.OTEL_SDK_DISABLED?.toLowerCase() !== "true";
|
|
444
|
+
const [tracerProvider, loggerProvider, metricReaders, sentry] = await Promise.all([
|
|
445
|
+
otelEnabled ? safely(() => createTracerProvider(resource)) : Promise.resolve(null),
|
|
446
|
+
otelEnabled ? safely(() => createLoggerProvider(resource)) : Promise.resolve(null),
|
|
447
|
+
otelEnabled ? safely(createMetricReaders) : Promise.resolve(null),
|
|
448
|
+
safely(initializeSentry)
|
|
449
|
+
]);
|
|
450
|
+
const meterProvider = metricReaders && metricReaders.length > 0 ? new MeterProvider({ readers: metricReaders, resource }) : null;
|
|
451
|
+
const meter = meterProvider?.getMeter("@swifty.js/swifty", version) ?? null;
|
|
452
|
+
const logger = loggerProvider?.getLogger("@swifty.js/swifty", version) ?? null;
|
|
453
|
+
return new ProviderRuntime(tracerProvider, loggerProvider, meterProvider, meter, logger, sentry);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
export {
|
|
457
|
+
version,
|
|
458
|
+
version_exports,
|
|
459
|
+
parseExporterTypes,
|
|
460
|
+
createTelemetryRuntime,
|
|
461
|
+
providers_exports
|
|
462
|
+
};
|
|
@@ -3,9 +3,30 @@ import {
|
|
|
3
3
|
asRecord,
|
|
4
4
|
createChildLogger,
|
|
5
5
|
strArg
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ZPIF7IJN.js";
|
|
7
|
+
import {
|
|
8
|
+
__export
|
|
9
|
+
} from "./chunk-MLKGABMK.js";
|
|
10
|
+
|
|
11
|
+
// src/tools/mcp-call.ts
|
|
12
|
+
var mcp_call_exports = {};
|
|
13
|
+
__export(mcp_call_exports, {
|
|
14
|
+
McpCallTool: () => McpCallTool,
|
|
15
|
+
coerceBySchema: () => coerceBySchema,
|
|
16
|
+
isMcpToolLike: () => isMcpToolLike,
|
|
17
|
+
mcpCallPermissionContent: () => mcpCallPermissionContent
|
|
18
|
+
});
|
|
7
19
|
|
|
8
20
|
// src/mcp/tool-wrapper.ts
|
|
21
|
+
var tool_wrapper_exports = {};
|
|
22
|
+
__export(tool_wrapper_exports, {
|
|
23
|
+
MCPToolWrapper: () => MCPToolWrapper,
|
|
24
|
+
MCP_NAME_SEP: () => MCP_NAME_SEP,
|
|
25
|
+
MCP_TOOL_PREFIX: () => MCP_TOOL_PREFIX,
|
|
26
|
+
buildMcpToolName: () => buildMcpToolName,
|
|
27
|
+
mcpToolNamePrefix: () => mcpToolNamePrefix,
|
|
28
|
+
sanitizeSegment: () => sanitizeSegment
|
|
29
|
+
});
|
|
9
30
|
var log = createChildLogger({ module: "mcp" });
|
|
10
31
|
var MCP_TOOL_PREFIX = "mcp__";
|
|
11
32
|
var MCP_NAME_SEP = "__";
|
|
@@ -225,13 +246,10 @@ var McpCallTool = class {
|
|
|
225
246
|
|
|
226
247
|
export {
|
|
227
248
|
MCP_TOOL_PREFIX,
|
|
228
|
-
MCP_NAME_SEP,
|
|
229
|
-
sanitizeSegment,
|
|
230
|
-
mcpToolNamePrefix,
|
|
231
|
-
buildMcpToolName,
|
|
232
249
|
MCPToolWrapper,
|
|
233
|
-
|
|
250
|
+
tool_wrapper_exports,
|
|
234
251
|
mcpCallPermissionContent,
|
|
235
252
|
isMcpToolLike,
|
|
236
|
-
McpCallTool
|
|
253
|
+
McpCallTool,
|
|
254
|
+
mcp_call_exports
|
|
237
255
|
};
|
|
@@ -1,47 +1,32 @@
|
|
|
1
1
|
import {
|
|
2
2
|
mcpCallPermissionContent
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-OLFXCZVH.js";
|
|
4
4
|
import {
|
|
5
|
+
canonicalPath,
|
|
5
6
|
createChildLogger,
|
|
7
|
+
isPathWithin,
|
|
6
8
|
isRecord,
|
|
7
9
|
strArg
|
|
8
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ZPIF7IJN.js";
|
|
11
|
+
import {
|
|
12
|
+
__export
|
|
13
|
+
} from "./chunk-MLKGABMK.js";
|
|
9
14
|
|
|
10
|
-
// src/permissions/
|
|
15
|
+
// src/permissions/index.ts
|
|
16
|
+
var permissions_exports = {};
|
|
17
|
+
__export(permissions_exports, {
|
|
18
|
+
PathSandbox: () => PathSandbox,
|
|
19
|
+
PermissionChecker: () => PermissionChecker,
|
|
20
|
+
RuleEngine: () => RuleEngine,
|
|
21
|
+
evaluateRules: () => evaluateRules,
|
|
22
|
+
extractContent: () => extractContent,
|
|
23
|
+
isSafeCommand: () => isSafeCommand
|
|
24
|
+
});
|
|
11
25
|
import { readFileSync, writeFileSync, mkdirSync, statSync } from "fs";
|
|
12
26
|
import { homedir, tmpdir } from "os";
|
|
13
|
-
import { join
|
|
27
|
+
import { join, resolve, dirname } from "path";
|
|
14
28
|
import yaml from "js-yaml";
|
|
15
29
|
import z, { parse } from "zod";
|
|
16
|
-
|
|
17
|
-
// src/utils/paths.ts
|
|
18
|
-
import { realpathSync } from "fs";
|
|
19
|
-
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "path";
|
|
20
|
-
function canonicalPath(path) {
|
|
21
|
-
let current = resolve(path);
|
|
22
|
-
const missing = [];
|
|
23
|
-
for (; ; ) {
|
|
24
|
-
try {
|
|
25
|
-
return join(realpathSync(current), ...missing);
|
|
26
|
-
} catch (error) {
|
|
27
|
-
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT" && error.code !== "ENOTDIR") {
|
|
28
|
-
throw error;
|
|
29
|
-
}
|
|
30
|
-
const parent = dirname(current);
|
|
31
|
-
if (parent === current) {
|
|
32
|
-
return resolve(path);
|
|
33
|
-
}
|
|
34
|
-
missing.unshift(basename(current));
|
|
35
|
-
current = parent;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function isPathWithin(root, path) {
|
|
40
|
-
const child = relative(root, path);
|
|
41
|
-
return child === "" || child !== ".." && !child.startsWith(`..${sep}`) && !isAbsolute(child);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// src/permissions/checker.ts
|
|
45
30
|
var log = createChildLogger({ module: "permissions" });
|
|
46
31
|
var DANGEROUS_PATTERNS = [];
|
|
47
32
|
var SAFE_PREFIXES = [
|
|
@@ -262,23 +247,23 @@ var PathSandbox = class {
|
|
|
262
247
|
denyWritePaths;
|
|
263
248
|
projectDir;
|
|
264
249
|
constructor(projectDir) {
|
|
265
|
-
this.projectDir =
|
|
250
|
+
this.projectDir = resolve(projectDir);
|
|
266
251
|
this.allowedRoots = [this.projectDir, tmpdir()];
|
|
267
|
-
this.denyWritePaths = DEFAULT_DENY_WRITE.map((p) =>
|
|
252
|
+
this.denyWritePaths = DEFAULT_DENY_WRITE.map((p) => join(this.projectDir, p));
|
|
268
253
|
}
|
|
269
254
|
addRoot(root) {
|
|
270
|
-
this.allowedRoots.push(
|
|
255
|
+
this.allowedRoots.push(resolve(root));
|
|
271
256
|
}
|
|
272
257
|
// Add custom deny-write paths
|
|
273
258
|
addDenyWrite(path) {
|
|
274
|
-
this.denyWritePaths.push(
|
|
259
|
+
this.denyWritePaths.push(resolve(path));
|
|
275
260
|
}
|
|
276
261
|
/**
|
|
277
262
|
* Check whether a path is in the deny-write list.
|
|
278
263
|
* denyWrite has the highest priority — even if the path is within an allowed root, writes are still denied.
|
|
279
264
|
*/
|
|
280
265
|
checkDenyWrite(filePath) {
|
|
281
|
-
const absolute =
|
|
266
|
+
const absolute = resolve(this.projectDir, filePath);
|
|
282
267
|
const canonical = canonicalPath(absolute);
|
|
283
268
|
for (const denied of this.denyWritePaths) {
|
|
284
269
|
if (isPathWithin(denied, absolute) || isPathWithin(canonicalPath(denied), canonical)) {
|
|
@@ -291,7 +276,7 @@ var PathSandbox = class {
|
|
|
291
276
|
return null;
|
|
292
277
|
}
|
|
293
278
|
check(filePath) {
|
|
294
|
-
const absolute = canonicalPath(
|
|
279
|
+
const absolute = canonicalPath(resolve(this.projectDir, filePath));
|
|
295
280
|
for (const root of this.allowedRoots) {
|
|
296
281
|
if (isPathWithin(canonicalPath(root), absolute)) {
|
|
297
282
|
return null;
|
|
@@ -373,8 +358,8 @@ var RuleEngine = class {
|
|
|
373
358
|
projectPath;
|
|
374
359
|
cache = /* @__PURE__ */ new Map();
|
|
375
360
|
constructor(workDir) {
|
|
376
|
-
this.userPath =
|
|
377
|
-
this.projectPath =
|
|
361
|
+
this.userPath = join(homedir(), ".swifty", "permissions.yaml");
|
|
362
|
+
this.projectPath = join(workDir, ".swifty", "permissions.yaml");
|
|
378
363
|
}
|
|
379
364
|
// Read a single rules file; skips disk I/O and parsing on cache hit.
|
|
380
365
|
rulesFor(path) {
|
|
@@ -411,7 +396,7 @@ var RuleEngine = class {
|
|
|
411
396
|
// Persists a rule to the project-level YAML file in the `Tool(pattern)`
|
|
412
397
|
// format so "allow always" survives a restart.
|
|
413
398
|
appendProjectRule(rule) {
|
|
414
|
-
mkdirSync(
|
|
399
|
+
mkdirSync(dirname(this.projectPath), { recursive: true });
|
|
415
400
|
const rules = loadRulesFile(this.projectPath);
|
|
416
401
|
const exists = rules.some(
|
|
417
402
|
(r) => r.tool === rule.tool && r.pattern === rule.pattern && r.effect === rule.effect
|
|
@@ -496,7 +481,7 @@ var PermissionChecker = class _PermissionChecker {
|
|
|
496
481
|
}
|
|
497
482
|
if (this.mode === "plan" && (toolName === "WriteFile" || toolName === "EditFile")) {
|
|
498
483
|
const path = strArg(args, "file_path", "");
|
|
499
|
-
if (this.planFilePath && canonicalPath(
|
|
484
|
+
if (this.planFilePath && canonicalPath(resolve(this.workDir, path)) === canonicalPath(resolve(this.workDir, this.planFilePath)) && !this.sandbox.checkDenyWrite(path)) {
|
|
500
485
|
return {
|
|
501
486
|
effect: "allow",
|
|
502
487
|
reason: "Plan file write allowed in plan mode"
|
|
@@ -579,13 +564,13 @@ var PermissionChecker = class _PermissionChecker {
|
|
|
579
564
|
const isFilePath = toolName === "ReadFile" || toolName === "WriteFile" || toolName === "EditFile";
|
|
580
565
|
let pattern;
|
|
581
566
|
if (isFilePath && content) {
|
|
582
|
-
const abs =
|
|
567
|
+
const abs = resolve(this.workDir, content);
|
|
583
568
|
let isDir = false;
|
|
584
569
|
try {
|
|
585
570
|
isDir = statSync(abs).isDirectory();
|
|
586
571
|
} catch {
|
|
587
572
|
}
|
|
588
|
-
pattern =
|
|
573
|
+
pattern = join(isDir ? abs : dirname(abs), "*");
|
|
589
574
|
} else {
|
|
590
575
|
const words = content.trim().split(/\s+/).slice(0, 2);
|
|
591
576
|
pattern = words.join(" ") + "*";
|
|
@@ -619,12 +604,11 @@ var PermissionChecker = class _PermissionChecker {
|
|
|
619
604
|
};
|
|
620
605
|
|
|
621
606
|
export {
|
|
622
|
-
canonicalPath,
|
|
623
|
-
isPathWithin,
|
|
624
607
|
extractContent,
|
|
625
608
|
PathSandbox,
|
|
626
609
|
evaluateRules,
|
|
627
610
|
RuleEngine,
|
|
628
611
|
isSafeCommand,
|
|
629
|
-
PermissionChecker
|
|
612
|
+
PermissionChecker,
|
|
613
|
+
permissions_exports
|
|
630
614
|
};
|