@yukino.js/yukino 0.0.8 → 0.0.9
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 +1 -1
- package/README.md +1 -1
- package/dist/{a2a-GBVNBDMY.js → a2a-C65LD3SC.js} +1 -1
- package/dist/acp-SNG4K2LG.js +14 -0
- package/dist/anthropic-E7KF3CEK.js +4 -0
- package/dist/chunk-4RUACBRP.js +5 -0
- package/dist/{chunk-MU6PSBZT.js → chunk-BQGLVWJ2.js} +30 -25
- package/dist/chunk-COBTQXCB.js +88 -0
- package/dist/chunk-GTWPLFAN.js +38 -0
- package/dist/chunk-HZFKNHPB.js +4 -0
- package/dist/chunk-PP5WWNTV.js +4 -0
- package/dist/chunk-QEUO5B7I.js +1033 -0
- package/dist/{chunk-L5C5JBLP.js → chunk-SQ26ASOB.js} +3 -3
- package/dist/fe/dist/static/index.js +36 -36
- package/dist/lib/{anthropic-K7VWTSFH.js → anthropic-XFZKSPOX.js} +3 -2
- package/dist/lib/{chunk-6NYUYSER.js → chunk-7EWMQYVH.js} +12 -3
- package/dist/lib/{chunk-E2DXHLHR.js → chunk-KUA7U27R.js} +8 -3
- package/dist/lib/{chunk-RJQT6B2O.js → chunk-LHIQSMGD.js} +12 -7
- package/dist/lib/{chunk-IIL5NGQF.js → chunk-MFEAVGDX.js} +56 -361
- package/dist/lib/chunk-Q3EV2REC.js +260 -0
- package/dist/lib/{chunk-2NA2RSV7.js → chunk-RY7EXVHD.js} +18 -7
- package/dist/lib/index.d.ts +82 -67
- package/dist/lib/index.js +1472 -791
- package/dist/lib/{openai-6MPSWGKN.js → openai-QSDLFAKO.js} +3 -2
- package/dist/lib/{providers-N52Y2QTJ.js → providers-TL72PZZD.js} +2 -1
- package/dist/lib/{seatbelt-VE3I3EGH.js → seatbelt-MRJ25UBQ.js} +1 -1
- package/dist/main.js +210 -210
- package/dist/{openai-VV2RYB77.js → openai-XNFC4DJ2.js} +13 -13
- package/dist/{providers-UD3DPALA.js → providers-XEORRTYK.js} +1 -1
- package/dist/{seatbelt-3YN3GMQO.js → seatbelt-FU3EQ42H.js} +1 -1
- package/dist/{server-FXK26WN2.js → server-35JMM5JU.js} +1 -1
- package/package.json +1 -1
- package/dist/acp-C6VUCEZ6.js +0 -14
- package/dist/anthropic-ZEQI4K52.js +0 -4
- package/dist/chunk-37IAJFPF.js +0 -4
- package/dist/chunk-3OULXPVI.js +0 -5
- package/dist/chunk-3P7BR7SO.js +0 -61
- package/dist/chunk-6XDMANXO.js +0 -4
- package/dist/chunk-IW5L5276.js +0 -65
- package/dist/chunk-YHE4BT76.js +0 -1031
|
@@ -4,8 +4,9 @@ import {
|
|
|
4
4
|
markLastUserTailForCache,
|
|
5
5
|
markToolsForCache,
|
|
6
6
|
needsToolSearchBeta
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-RY7EXVHD.js";
|
|
8
|
+
import "./chunk-MFEAVGDX.js";
|
|
9
|
+
import "./chunk-Q3EV2REC.js";
|
|
9
10
|
import "./chunk-MLKGABMK.js";
|
|
10
11
|
export {
|
|
11
12
|
AnthropicClient,
|
|
@@ -29,6 +29,12 @@ function pathVariants(path) {
|
|
|
29
29
|
}
|
|
30
30
|
return [...variants];
|
|
31
31
|
}
|
|
32
|
+
function quoteProfileString(value) {
|
|
33
|
+
if (/\0|[\r\n]/u.test(value)) {
|
|
34
|
+
throw new Error("Seatbelt paths cannot contain NUL or newline characters");
|
|
35
|
+
}
|
|
36
|
+
return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
37
|
+
}
|
|
32
38
|
function buildProfile(config) {
|
|
33
39
|
const lines = [];
|
|
34
40
|
lines.push("(version 1)");
|
|
@@ -39,13 +45,16 @@ function buildProfile(config) {
|
|
|
39
45
|
lines.push('(allow file-read* (subpath "/"))');
|
|
40
46
|
for (const path of config.allowWrite) {
|
|
41
47
|
for (const variant of pathVariants(path)) {
|
|
42
|
-
lines.push(
|
|
48
|
+
lines.push(
|
|
49
|
+
`(allow file-write* (subpath ${quoteProfileString(variant)}))`
|
|
50
|
+
);
|
|
43
51
|
}
|
|
44
52
|
}
|
|
45
53
|
for (const path of config.denyWrite) {
|
|
46
54
|
for (const variant of pathVariants(path)) {
|
|
47
|
-
|
|
48
|
-
lines.push(`(deny file-write* (
|
|
55
|
+
const quoted = quoteProfileString(variant);
|
|
56
|
+
lines.push(`(deny file-write* (literal ${quoted}))`);
|
|
57
|
+
lines.push(`(deny file-write* (subpath ${quoted}))`);
|
|
49
58
|
}
|
|
50
59
|
}
|
|
51
60
|
if (config.networkEnabled) {
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
clampThinkingLevel,
|
|
10
10
|
containsContextLengthError,
|
|
11
11
|
contentToText,
|
|
12
|
-
createChildLogger,
|
|
13
12
|
ensureToolPairing,
|
|
14
13
|
getMaxOutputTokens,
|
|
15
14
|
getSupportedThinkingLevels,
|
|
@@ -19,7 +18,10 @@ import {
|
|
|
19
18
|
resolveAPIKey,
|
|
20
19
|
strArg,
|
|
21
20
|
toReasoningEffort
|
|
22
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-MFEAVGDX.js";
|
|
22
|
+
import {
|
|
23
|
+
createChildLogger
|
|
24
|
+
} from "./chunk-Q3EV2REC.js";
|
|
23
25
|
import {
|
|
24
26
|
__export
|
|
25
27
|
} from "./chunk-MLKGABMK.js";
|
|
@@ -692,7 +694,7 @@ var OpenAICompatClient = class {
|
|
|
692
694
|
messages,
|
|
693
695
|
stream: true,
|
|
694
696
|
stream_options: { include_usage: true },
|
|
695
|
-
|
|
697
|
+
max_completion_tokens: this.maxOutputTokens,
|
|
696
698
|
...tools.length > 0 ? { tools } : {},
|
|
697
699
|
// Configured non-reasoning providers omit the field; off otherwise sends
|
|
698
700
|
// none explicitly so a server default cannot silently enable reasoning.
|
|
@@ -834,6 +836,9 @@ function classifyOpenAIError(err) {
|
|
|
834
836
|
if (err instanceof LLMError) {
|
|
835
837
|
return err;
|
|
836
838
|
}
|
|
839
|
+
if (err instanceof OpenAI.APIConnectionError || err instanceof OpenAI.APIUserAbortError) {
|
|
840
|
+
return new NetworkError(`Network error: ${err.message}`);
|
|
841
|
+
}
|
|
837
842
|
if (err instanceof OpenAI.APIError) {
|
|
838
843
|
if (err.status === 413 /* PromptTooLong */ || err.status === 400 /* BadRequest */ && containsContextLengthError(err.message)) {
|
|
839
844
|
return new ContextTooLongError(`Context Too Long: ${err.message}`);
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createChildLogger
|
|
3
|
+
} from "./chunk-Q3EV2REC.js";
|
|
1
4
|
import {
|
|
2
5
|
__export
|
|
3
6
|
} from "./chunk-MLKGABMK.js";
|
|
@@ -52,7 +55,7 @@ var PackageJsonSchema = z.object({
|
|
|
52
55
|
});
|
|
53
56
|
function resolveVersion() {
|
|
54
57
|
if (true) {
|
|
55
|
-
return "0.0.
|
|
58
|
+
return "0.0.9";
|
|
56
59
|
}
|
|
57
60
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
58
61
|
for (const levels of ["..", "../.."]) {
|
|
@@ -71,6 +74,7 @@ function resolveVersion() {
|
|
|
71
74
|
var version = resolveVersion();
|
|
72
75
|
|
|
73
76
|
// src/telemetry/providers.ts
|
|
77
|
+
var log = createChildLogger({ module: "telemetry" });
|
|
74
78
|
var DEFAULT_EXPORT_INTERVAL_MS = 6e4;
|
|
75
79
|
var SHUTDOWN_TIMEOUT_MS = 2e3;
|
|
76
80
|
function parseExporterTypes(value) {
|
|
@@ -264,10 +268,11 @@ async function initializeSentry() {
|
|
|
264
268
|
});
|
|
265
269
|
return sentry;
|
|
266
270
|
}
|
|
267
|
-
async function safely(operation) {
|
|
271
|
+
async function safely(label, operation) {
|
|
268
272
|
try {
|
|
269
273
|
return await operation();
|
|
270
|
-
} catch {
|
|
274
|
+
} catch (err) {
|
|
275
|
+
log.error({ err, label }, "telemetry initialization failed");
|
|
271
276
|
return null;
|
|
272
277
|
}
|
|
273
278
|
}
|
|
@@ -485,10 +490,10 @@ async function createTelemetryRuntime() {
|
|
|
485
490
|
const resource = createResource();
|
|
486
491
|
const otelEnabled = process.env.OTEL_SDK_DISABLED?.toLowerCase() !== "true";
|
|
487
492
|
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)
|
|
493
|
+
otelEnabled ? safely("traces", () => createTracerProvider(resource)) : Promise.resolve(null),
|
|
494
|
+
otelEnabled ? safely("logs", () => createLoggerProvider(resource)) : Promise.resolve(null),
|
|
495
|
+
otelEnabled ? safely("metrics", createMetricReaders) : Promise.resolve(null),
|
|
496
|
+
safely("sentry", initializeSentry)
|
|
492
497
|
]);
|
|
493
498
|
const meterProvider = metricReaders && metricReaders.length > 0 ? new MeterProvider({ readers: metricReaders, resource }) : null;
|
|
494
499
|
const meter = meterProvider?.getMeter("@yukino.js/yukino", version) ?? null;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createChildLogger
|
|
3
|
+
} from "./chunk-Q3EV2REC.js";
|
|
1
4
|
import {
|
|
2
5
|
__export
|
|
3
6
|
} from "./chunk-MLKGABMK.js";
|
|
@@ -188,246 +191,6 @@ function getMaxOutputTokens(provider) {
|
|
|
188
191
|
return Math.min(maxOutput, getContextWindow(provider));
|
|
189
192
|
}
|
|
190
193
|
|
|
191
|
-
// src/logger/index.ts
|
|
192
|
-
var logger_exports = {};
|
|
193
|
-
__export(logger_exports, {
|
|
194
|
-
closeLogger: () => closeLogger,
|
|
195
|
-
createChildLogger: () => createChildLogger,
|
|
196
|
-
initLogger: () => initLogger,
|
|
197
|
-
logger: () => logger,
|
|
198
|
-
sanitizeNameSegment: () => sanitizeNameSegment
|
|
199
|
-
});
|
|
200
|
-
import { openSync, closeSync, mkdirSync, writeFileSync } from "fs";
|
|
201
|
-
import { readdir, stat, unlink } from "fs/promises";
|
|
202
|
-
import { homedir as homedir2 } from "os";
|
|
203
|
-
import { join as join2, dirname, basename } from "path";
|
|
204
|
-
import pino from "pino";
|
|
205
|
-
var currentLogger = null;
|
|
206
|
-
var currentDest = null;
|
|
207
|
-
var currentFd = null;
|
|
208
|
-
function resolveLogPath(opts) {
|
|
209
|
-
const dir = opts.logDir ?? join2(opts.workDir ?? process.cwd(), ".yukino", "logs");
|
|
210
|
-
return join2(dir, `${opts.sessionId}.jsonl`);
|
|
211
|
-
}
|
|
212
|
-
function ensureYukinoGitignore(logPath) {
|
|
213
|
-
let dir = dirname(logPath);
|
|
214
|
-
while (basename(dir) !== ".yukino") {
|
|
215
|
-
const parent = dirname(dir);
|
|
216
|
-
if (parent === dir) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
dir = parent;
|
|
220
|
-
}
|
|
221
|
-
try {
|
|
222
|
-
writeFileSync(join2(dir, ".gitignore"), "*\n", { flag: "wx" });
|
|
223
|
-
} catch {
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
function sanitizeNameSegment(name) {
|
|
227
|
-
const cleaned = name.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
228
|
-
return cleaned || "unnamed";
|
|
229
|
-
}
|
|
230
|
-
function flushDestination(dest) {
|
|
231
|
-
if (typeof dest !== "object" || dest === null) {
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
const fn = Reflect.get(dest, "flushSync");
|
|
235
|
-
if (typeof fn === "function") {
|
|
236
|
-
fn.call(dest);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
var LOG_LEVEL = "warn";
|
|
240
|
-
function initLogger(opts) {
|
|
241
|
-
if (currentLogger) {
|
|
242
|
-
closeLogger();
|
|
243
|
-
}
|
|
244
|
-
const logPath = resolveLogPath(opts);
|
|
245
|
-
mkdirSync(dirname(logPath), { recursive: true });
|
|
246
|
-
ensureYukinoGitignore(logPath);
|
|
247
|
-
const fd = openSync(logPath, "a");
|
|
248
|
-
currentFd = fd;
|
|
249
|
-
currentDest = pino.destination(fd);
|
|
250
|
-
const pinoOpts = {
|
|
251
|
-
level: LOG_LEVEL,
|
|
252
|
-
base: { sessionId: opts.sessionId, mode: opts.mode },
|
|
253
|
-
serializers: { err: errSerializer }
|
|
254
|
-
};
|
|
255
|
-
if (opts.stdout) {
|
|
256
|
-
currentLogger = pino(
|
|
257
|
-
pinoOpts,
|
|
258
|
-
pino.multistream([
|
|
259
|
-
{ stream: currentDest, level: LOG_LEVEL },
|
|
260
|
-
{ stream: process.stdout, level: LOG_LEVEL }
|
|
261
|
-
])
|
|
262
|
-
);
|
|
263
|
-
} else {
|
|
264
|
-
currentLogger = pino(pinoOpts, currentDest);
|
|
265
|
-
}
|
|
266
|
-
if (!opts.skipCleanup) {
|
|
267
|
-
const workDir = opts.workDir ?? process.cwd();
|
|
268
|
-
void cleanExpiredLogs(workDir).catch(() => {
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
return currentLogger;
|
|
272
|
-
}
|
|
273
|
-
function getLogger() {
|
|
274
|
-
return currentLogger;
|
|
275
|
-
}
|
|
276
|
-
function closeLogger() {
|
|
277
|
-
if (currentLogger) {
|
|
278
|
-
try {
|
|
279
|
-
currentLogger.flush();
|
|
280
|
-
} catch {
|
|
281
|
-
}
|
|
282
|
-
currentLogger = null;
|
|
283
|
-
}
|
|
284
|
-
if (currentDest) {
|
|
285
|
-
flushDestination(currentDest);
|
|
286
|
-
currentDest = null;
|
|
287
|
-
}
|
|
288
|
-
if (currentFd !== null) {
|
|
289
|
-
try {
|
|
290
|
-
closeSync(currentFd);
|
|
291
|
-
} catch {
|
|
292
|
-
}
|
|
293
|
-
currentFd = null;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
var silentFallback = pino({ level: "silent" });
|
|
297
|
-
var logger = new Proxy(silentFallback, {
|
|
298
|
-
get(_target, prop, receiver) {
|
|
299
|
-
const current = getLogger();
|
|
300
|
-
const target = current ?? _target;
|
|
301
|
-
const value = Reflect.get(target, prop, receiver);
|
|
302
|
-
if (typeof value === "function") {
|
|
303
|
-
const bound = value.bind(target);
|
|
304
|
-
return bound;
|
|
305
|
-
}
|
|
306
|
-
return value;
|
|
307
|
-
},
|
|
308
|
-
set(_target, prop, value) {
|
|
309
|
-
return Reflect.set(getLogger() ?? _target, prop, value);
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
function createChildLogger(bindings) {
|
|
313
|
-
let cachedChild = null;
|
|
314
|
-
let cachedLogger = null;
|
|
315
|
-
const resolveChild = () => {
|
|
316
|
-
const current = getLogger();
|
|
317
|
-
if (!current) {
|
|
318
|
-
return null;
|
|
319
|
-
}
|
|
320
|
-
if (cachedChild === null || cachedLogger !== current) {
|
|
321
|
-
cachedChild = current.child(bindings);
|
|
322
|
-
cachedLogger = current;
|
|
323
|
-
}
|
|
324
|
-
return cachedChild;
|
|
325
|
-
};
|
|
326
|
-
return new Proxy(silentFallback, {
|
|
327
|
-
get(_target, prop, receiver) {
|
|
328
|
-
const target = resolveChild() ?? _target;
|
|
329
|
-
const value = Reflect.get(target, prop, receiver);
|
|
330
|
-
if (typeof value === "function") {
|
|
331
|
-
const bound = value.bind(target);
|
|
332
|
-
return bound;
|
|
333
|
-
}
|
|
334
|
-
return value;
|
|
335
|
-
},
|
|
336
|
-
set(_target, prop, value) {
|
|
337
|
-
return Reflect.set(resolveChild() ?? _target, prop, value);
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
async function cleanDir(dir) {
|
|
342
|
-
let files;
|
|
343
|
-
try {
|
|
344
|
-
files = (await readdir(dir)).filter((f) => f.endsWith(".jsonl"));
|
|
345
|
-
} catch {
|
|
346
|
-
return 0;
|
|
347
|
-
}
|
|
348
|
-
const now = Date.now();
|
|
349
|
-
let removed = 0;
|
|
350
|
-
for (const file of files) {
|
|
351
|
-
const filePath = join2(dir, file);
|
|
352
|
-
try {
|
|
353
|
-
const s = await stat(filePath);
|
|
354
|
-
if (now - s.mtimeMs > 30 * 24 * 60 * 60 * 1e3) {
|
|
355
|
-
await unlink(filePath);
|
|
356
|
-
removed++;
|
|
357
|
-
}
|
|
358
|
-
} catch {
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
return removed;
|
|
362
|
-
}
|
|
363
|
-
async function cleanExpiredLogs(workDir) {
|
|
364
|
-
let removed = 0;
|
|
365
|
-
removed += await cleanDir(join2(workDir, ".yukino", "logs"));
|
|
366
|
-
const teamsDir = join2(homedir2(), ".yukino", "teams");
|
|
367
|
-
let teams;
|
|
368
|
-
try {
|
|
369
|
-
teams = await readdir(teamsDir);
|
|
370
|
-
} catch {
|
|
371
|
-
return removed;
|
|
372
|
-
}
|
|
373
|
-
for (const team of teams) {
|
|
374
|
-
removed += await cleanDir(join2(teamsDir, team, "logs"));
|
|
375
|
-
}
|
|
376
|
-
return removed;
|
|
377
|
-
}
|
|
378
|
-
var CAUSE_MAX_DEPTH = 5;
|
|
379
|
-
var RESERVED_KEYS = /* @__PURE__ */ new Set(["name", "message", "stack", "cause"]);
|
|
380
|
-
function serializeErrorInstance(err, depth) {
|
|
381
|
-
const out = {
|
|
382
|
-
type: err.name,
|
|
383
|
-
message: err.message,
|
|
384
|
-
stack: err.stack
|
|
385
|
-
};
|
|
386
|
-
const causeDescriptor = Object.getOwnPropertyDescriptor(err, "cause");
|
|
387
|
-
if (causeDescriptor && depth < CAUSE_MAX_DEPTH) {
|
|
388
|
-
const cause = causeDescriptor.value;
|
|
389
|
-
if (cause instanceof Error) {
|
|
390
|
-
out.cause = serializeErrorInstance(cause, depth + 1);
|
|
391
|
-
} else if (cause !== void 0) {
|
|
392
|
-
out.cause = { message: safeStringify(cause) };
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
for (const key of Object.keys(err)) {
|
|
396
|
-
if (RESERVED_KEYS.has(key)) {
|
|
397
|
-
continue;
|
|
398
|
-
}
|
|
399
|
-
const descriptor = Object.getOwnPropertyDescriptor(err, key);
|
|
400
|
-
if (descriptor) {
|
|
401
|
-
const fieldValue = descriptor.value;
|
|
402
|
-
out[key] = fieldValue;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
return out;
|
|
406
|
-
}
|
|
407
|
-
function safeStringify(value) {
|
|
408
|
-
if (typeof value === "string") {
|
|
409
|
-
return value;
|
|
410
|
-
}
|
|
411
|
-
try {
|
|
412
|
-
const json = JSON.stringify(value);
|
|
413
|
-
if (json !== void 0) {
|
|
414
|
-
return json;
|
|
415
|
-
}
|
|
416
|
-
} catch {
|
|
417
|
-
}
|
|
418
|
-
try {
|
|
419
|
-
return String(value);
|
|
420
|
-
} catch {
|
|
421
|
-
return Object.prototype.toString.call(value);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
function errSerializer(err) {
|
|
425
|
-
if (err instanceof Error) {
|
|
426
|
-
return serializeErrorInstance(err, 0);
|
|
427
|
-
}
|
|
428
|
-
return { message: safeStringify(err), value: err };
|
|
429
|
-
}
|
|
430
|
-
|
|
431
194
|
// src/config/index.ts
|
|
432
195
|
var config_exports = {};
|
|
433
196
|
__export(config_exports, {
|
|
@@ -443,7 +206,7 @@ __export(config_exports, {
|
|
|
443
206
|
withProjectMcpServers: () => withProjectMcpServers
|
|
444
207
|
});
|
|
445
208
|
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
446
|
-
import { join as
|
|
209
|
+
import { join as join3 } from "path";
|
|
447
210
|
import {
|
|
448
211
|
getParseErrorMessage,
|
|
449
212
|
safeParse
|
|
@@ -463,13 +226,13 @@ __export(provider_login_exports, {
|
|
|
463
226
|
import { randomUUID } from "crypto";
|
|
464
227
|
import {
|
|
465
228
|
existsSync,
|
|
466
|
-
mkdirSync
|
|
229
|
+
mkdirSync,
|
|
467
230
|
readFileSync,
|
|
468
231
|
renameSync,
|
|
469
232
|
unlinkSync,
|
|
470
|
-
writeFileSync
|
|
233
|
+
writeFileSync
|
|
471
234
|
} from "fs";
|
|
472
|
-
import { dirname
|
|
235
|
+
import { dirname, join as join2 } from "path";
|
|
473
236
|
import yaml from "js-yaml";
|
|
474
237
|
import { z as z2 } from "zod";
|
|
475
238
|
var tokenLimit = (fallback, min, max) => z2.preprocess(
|
|
@@ -509,11 +272,11 @@ function readConfigRaw(path) {
|
|
|
509
272
|
return z2.record(z2.string(), z2.unknown()).parse(raw ?? {});
|
|
510
273
|
}
|
|
511
274
|
function writeConfigAtomic(path, raw) {
|
|
512
|
-
const directory =
|
|
513
|
-
|
|
514
|
-
const temporary =
|
|
275
|
+
const directory = dirname(path);
|
|
276
|
+
mkdirSync(directory, { recursive: true });
|
|
277
|
+
const temporary = join2(directory, `.config-${randomUUID()}.tmp`);
|
|
515
278
|
try {
|
|
516
|
-
|
|
279
|
+
writeFileSync(temporary, yaml.dump(raw, { lineWidth: -1, noRefs: true }), {
|
|
517
280
|
encoding: "utf-8",
|
|
518
281
|
mode: 384,
|
|
519
282
|
flag: "wx"
|
|
@@ -677,102 +440,19 @@ function forkEnabled(cfg) {
|
|
|
677
440
|
function memoryEnabled(cfg) {
|
|
678
441
|
return cfg.enable_memory !== false;
|
|
679
442
|
}
|
|
680
|
-
function isRecord(value) {
|
|
681
|
-
return typeof value === "object" && value !== null;
|
|
682
|
-
}
|
|
683
443
|
function loadSingleFile(path) {
|
|
684
444
|
const data = readFileSync2(path, "utf-8");
|
|
685
445
|
const raw = yaml2.load(data);
|
|
686
|
-
if (!isRecord(raw)) {
|
|
687
|
-
log.error({ path }, "invalid yaml");
|
|
688
|
-
return { default_provider: 0, providers: [], mcp_servers: [], hooks: [] };
|
|
689
|
-
}
|
|
690
446
|
const parsed = safeParse(AppConfigSchema, raw);
|
|
691
|
-
if (parsed.success) {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
providers: data2.providers.map(withProviderDefaults)
|
|
696
|
-
};
|
|
697
|
-
}
|
|
698
|
-
log.error({ error: parsed.error }, "config error");
|
|
699
|
-
let defaultProvider = 0;
|
|
700
|
-
let providers = [];
|
|
701
|
-
let permissionMode;
|
|
702
|
-
let mcpServers = [];
|
|
703
|
-
let hooks = [];
|
|
704
|
-
let sandbox = void 0;
|
|
705
|
-
let enableCoordinatorMode = false;
|
|
706
|
-
let enableFork = true;
|
|
707
|
-
let enableMemory = true;
|
|
708
|
-
if ("default_provider" in raw) {
|
|
709
|
-
const parsed2 = safeParse(z3.number(), raw.default_provider);
|
|
710
|
-
if (parsed2.success) {
|
|
711
|
-
defaultProvider = parsed2.data;
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
if ("providers" in raw) {
|
|
715
|
-
const parsed2 = safeParse(z3.array(ProviderConfigSchema), raw.providers);
|
|
716
|
-
if (parsed2.success) {
|
|
717
|
-
providers = parsed2.data.map(withProviderDefaults);
|
|
718
|
-
} else {
|
|
719
|
-
throw new ConfigError(
|
|
720
|
-
`Invalid provider configuration in ${path}: ${getParseErrorMessage(parsed2.error)}`
|
|
721
|
-
);
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
if ("permission_mode" in raw && typeof raw.permission_mode === "string") {
|
|
725
|
-
permissionMode = raw.permission_mode;
|
|
726
|
-
}
|
|
727
|
-
if ("mcp_servers" in raw) {
|
|
728
|
-
const parsed2 = safeParse(z3.array(MCPServerConfigSchema), raw.mcp_servers);
|
|
729
|
-
if (parsed2.success) {
|
|
730
|
-
mcpServers = parsed2.data;
|
|
731
|
-
} else {
|
|
732
|
-
throw new ConfigError(
|
|
733
|
-
`Invalid MCP server configuration in ${path}: ${getParseErrorMessage(parsed2.error)}`
|
|
734
|
-
);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
if ("hooks" in raw) {
|
|
738
|
-
const parsed2 = safeParse(z3.array(HookConfigSchema), raw.hooks);
|
|
739
|
-
if (parsed2.success) {
|
|
740
|
-
hooks = parsed2.data;
|
|
741
|
-
} else {
|
|
742
|
-
throw new ConfigError(
|
|
743
|
-
`Invalid hooks configuration in ${path}: ${getParseErrorMessage(parsed2.error)}`
|
|
744
|
-
);
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
if ("sandbox" in raw) {
|
|
748
|
-
const parsed2 = safeParse(SandboxYamlConfigSchema, raw.sandbox);
|
|
749
|
-
if (parsed2.success) {
|
|
750
|
-
sandbox = parsed2.data;
|
|
751
|
-
} else {
|
|
752
|
-
throw new ConfigError(
|
|
753
|
-
`Invalid sandbox configuration in ${path}: ${getParseErrorMessage(parsed2.error)}`
|
|
754
|
-
);
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
if ("enable_coordinator_mode" in raw) {
|
|
758
|
-
enableCoordinatorMode = Boolean(raw.enable_coordinator_mode);
|
|
759
|
-
}
|
|
760
|
-
if ("enable_fork" in raw) {
|
|
761
|
-
enableFork = Boolean(raw.enable_fork);
|
|
762
|
-
}
|
|
763
|
-
if ("enable_memory" in raw) {
|
|
764
|
-
enableMemory = Boolean(raw.enable_memory);
|
|
447
|
+
if (!parsed.success) {
|
|
448
|
+
throw new ConfigError(
|
|
449
|
+
`Invalid configuration in ${path}: ${getParseErrorMessage(parsed.error)}`
|
|
450
|
+
);
|
|
765
451
|
}
|
|
452
|
+
const config = parsed.data;
|
|
766
453
|
return {
|
|
767
|
-
|
|
768
|
-
providers
|
|
769
|
-
permission_mode: permissionMode,
|
|
770
|
-
mcp_servers: mcpServers,
|
|
771
|
-
hooks,
|
|
772
|
-
sandbox,
|
|
773
|
-
enable_coordinator_mode: enableCoordinatorMode,
|
|
774
|
-
enable_fork: enableFork,
|
|
775
|
-
enable_memory: enableMemory
|
|
454
|
+
...config,
|
|
455
|
+
providers: config.providers.map(withProviderDefaults)
|
|
776
456
|
};
|
|
777
457
|
}
|
|
778
458
|
function validateProviders(config) {
|
|
@@ -871,7 +551,7 @@ function mcpServerFromJsonEntry(name, entry) {
|
|
|
871
551
|
return { name, url: entry.url, transport, headers: entry.headers };
|
|
872
552
|
}
|
|
873
553
|
function loadProjectMcpServers(workDir) {
|
|
874
|
-
const path =
|
|
554
|
+
const path = join3(workDir, PROJECT_MCP_FILENAME);
|
|
875
555
|
if (!existsSync2(path)) {
|
|
876
556
|
return [];
|
|
877
557
|
}
|
|
@@ -962,7 +642,7 @@ __export(utils_exports, {
|
|
|
962
642
|
formatToolArgs: () => formatToolArgs,
|
|
963
643
|
intArg: () => intArg,
|
|
964
644
|
isObject: () => isObject,
|
|
965
|
-
isRecord: () =>
|
|
645
|
+
isRecord: () => isRecord,
|
|
966
646
|
safeJSONParse: () => safeJSONParse,
|
|
967
647
|
strArg: () => strArg,
|
|
968
648
|
strList: () => strList,
|
|
@@ -977,12 +657,12 @@ __export(paths_exports, {
|
|
|
977
657
|
isPathWithin: () => isPathWithin
|
|
978
658
|
});
|
|
979
659
|
import { realpathSync } from "fs";
|
|
980
|
-
import { homedir as
|
|
660
|
+
import { homedir as homedir2 } from "os";
|
|
981
661
|
import {
|
|
982
|
-
basename
|
|
983
|
-
dirname as
|
|
662
|
+
basename,
|
|
663
|
+
dirname as dirname2,
|
|
984
664
|
isAbsolute,
|
|
985
|
-
join as
|
|
665
|
+
join as join4,
|
|
986
666
|
relative,
|
|
987
667
|
resolve,
|
|
988
668
|
sep
|
|
@@ -992,16 +672,16 @@ function canonicalPath(path) {
|
|
|
992
672
|
const missing = [];
|
|
993
673
|
for (; ; ) {
|
|
994
674
|
try {
|
|
995
|
-
return
|
|
675
|
+
return join4(realpathSync(current), ...missing);
|
|
996
676
|
} catch (error) {
|
|
997
677
|
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT" && error.code !== "ENOTDIR") {
|
|
998
678
|
throw error;
|
|
999
679
|
}
|
|
1000
|
-
const parent =
|
|
680
|
+
const parent = dirname2(current);
|
|
1001
681
|
if (parent === current) {
|
|
1002
682
|
return resolve(path);
|
|
1003
683
|
}
|
|
1004
|
-
missing.unshift(
|
|
684
|
+
missing.unshift(basename(current));
|
|
1005
685
|
current = parent;
|
|
1006
686
|
}
|
|
1007
687
|
}
|
|
@@ -1011,8 +691,12 @@ function isPathWithin(root, path) {
|
|
|
1011
691
|
return child === "" || child !== ".." && !child.startsWith(`..${sep}`) && !isAbsolute(child);
|
|
1012
692
|
}
|
|
1013
693
|
function compactPath(path) {
|
|
1014
|
-
const home =
|
|
1015
|
-
|
|
694
|
+
const home = homedir2();
|
|
695
|
+
const homeRelative = relative(home, path);
|
|
696
|
+
if (homeRelative === "") {
|
|
697
|
+
return "~";
|
|
698
|
+
}
|
|
699
|
+
return !homeRelative.startsWith(`..${sep}`) && homeRelative !== ".." && !isAbsolute(homeRelative) ? join4("~", homeRelative) : path;
|
|
1016
700
|
}
|
|
1017
701
|
|
|
1018
702
|
// src/utils/slug.ts
|
|
@@ -1037,7 +721,7 @@ function contentToText(content) {
|
|
|
1037
721
|
for (const block of content) {
|
|
1038
722
|
if (block.type === "text" && typeof block.text === "string") {
|
|
1039
723
|
parts.push(block.text);
|
|
1040
|
-
} else if (block.type === "image" &&
|
|
724
|
+
} else if (block.type === "image" && isRecord(block.source)) {
|
|
1041
725
|
const mediaType = block.source.type === "base64" && typeof block.source.media_type === "string" ? block.source.media_type : "image";
|
|
1042
726
|
parts.push(`[Image: ${mediaType}]`);
|
|
1043
727
|
} else if (block.type === "tool_reference" && typeof block.tool_name === "string") {
|
|
@@ -1045,7 +729,7 @@ function contentToText(content) {
|
|
|
1045
729
|
} else if (block.type === "search_result") {
|
|
1046
730
|
const title = typeof block.title === "string" ? block.title : "search result";
|
|
1047
731
|
const source = typeof block.source === "string" ? ` (${block.source})` : "";
|
|
1048
|
-
const nested = Array.isArray(block.content) ? contentToText(block.content.filter(
|
|
732
|
+
const nested = Array.isArray(block.content) ? contentToText(block.content.filter(isRecord)) : "";
|
|
1049
733
|
parts.push(`${title}${source}${nested ? `
|
|
1050
734
|
${nested}` : ""}`);
|
|
1051
735
|
} else if (block.type === "document") {
|
|
@@ -1055,11 +739,11 @@ ${nested}` : ""}`);
|
|
|
1055
739
|
}
|
|
1056
740
|
return parts.join("\n");
|
|
1057
741
|
}
|
|
1058
|
-
function
|
|
742
|
+
function isRecord(value) {
|
|
1059
743
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1060
744
|
}
|
|
1061
745
|
function asRecord(value) {
|
|
1062
|
-
if (
|
|
746
|
+
if (isRecord(value)) {
|
|
1063
747
|
return value;
|
|
1064
748
|
}
|
|
1065
749
|
if (Array.isArray(value)) {
|
|
@@ -1133,7 +817,24 @@ function boolArg(args, key, fallback) {
|
|
|
1133
817
|
if (typeof v === "boolean") {
|
|
1134
818
|
return v;
|
|
1135
819
|
}
|
|
1136
|
-
|
|
820
|
+
if (typeof v === "string") {
|
|
821
|
+
const normalized = v.trim().toLowerCase();
|
|
822
|
+
if (normalized === "true" || normalized === "1") {
|
|
823
|
+
return true;
|
|
824
|
+
}
|
|
825
|
+
if (normalized === "false" || normalized === "0") {
|
|
826
|
+
return false;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
if (typeof v === "number") {
|
|
830
|
+
if (v === 1) {
|
|
831
|
+
return true;
|
|
832
|
+
}
|
|
833
|
+
if (v === 0) {
|
|
834
|
+
return false;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
return fallback ?? false;
|
|
1137
838
|
}
|
|
1138
839
|
function formatToolArgs(args) {
|
|
1139
840
|
if (args.command) {
|
|
@@ -1303,12 +1004,6 @@ export {
|
|
|
1303
1004
|
clampThinkingLevel,
|
|
1304
1005
|
getContextWindow,
|
|
1305
1006
|
getMaxOutputTokens,
|
|
1306
|
-
sanitizeNameSegment,
|
|
1307
|
-
initLogger,
|
|
1308
|
-
closeLogger,
|
|
1309
|
-
logger,
|
|
1310
|
-
createChildLogger,
|
|
1311
|
-
logger_exports,
|
|
1312
1007
|
persistThinkingLevel,
|
|
1313
1008
|
resolveAPIKey,
|
|
1314
1009
|
forkEnabled,
|
|
@@ -1320,7 +1015,7 @@ export {
|
|
|
1320
1015
|
isPathWithin,
|
|
1321
1016
|
generateSlug,
|
|
1322
1017
|
contentToText,
|
|
1323
|
-
|
|
1018
|
+
isRecord,
|
|
1324
1019
|
asRecord,
|
|
1325
1020
|
asString,
|
|
1326
1021
|
asErrorString,
|