@yukino.js/yukino 0.0.7 → 0.0.8
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 +130 -25
- package/dist/a2a-GBVNBDMY.js +14 -0
- package/dist/{acp-76S2XII3.js → acp-C6VUCEZ6.js} +7 -7
- package/dist/anthropic-ZEQI4K52.js +4 -0
- package/dist/chunk-37IAJFPF.js +4 -0
- package/dist/{chunk-NG62ISUV.js → chunk-3P7BR7SO.js} +8 -8
- package/dist/{chunk-7PPWFSIC.js → chunk-6XDMANXO.js} +1 -1
- package/dist/{chunk-HWDSXNX4.js → chunk-L5C5JBLP.js} +1 -1
- package/dist/chunk-MU6PSBZT.js +358 -0
- package/dist/chunk-WGFROGUC.js +8 -0
- package/dist/{chunk-QRO6H32L.js → chunk-YHE4BT76.js} +148 -148
- package/dist/esm-4KOJC56H.js +225 -0
- package/dist/fe/dist/index.html +21 -0
- package/dist/fe/dist/static/index.css +2 -0
- package/dist/fe/dist/static/index.js +203 -0
- package/dist/lib/{anthropic-CDPTNR5L.js → anthropic-K7VWTSFH.js} +2 -2
- package/dist/lib/{chunk-EO23VPDZ.js → chunk-2NA2RSV7.js} +1 -9
- package/dist/lib/{chunk-PEV5NGQ2.js → chunk-E2DXHLHR.js} +1 -1
- package/dist/lib/{chunk-HE4RUUZP.js → chunk-IIL5NGQF.js} +461 -457
- package/dist/lib/{chunk-OYQY3Q45.js → chunk-K532PPI6.js} +0 -2
- package/dist/lib/{chunk-TKCJSTWI.js → chunk-RJQT6B2O.js} +1 -1
- package/dist/lib/index.d.ts +402 -3616
- package/dist/lib/index.js +2733 -1893
- package/dist/lib/{openai-TEFKPV7T.js → openai-6MPSWGKN.js} +2 -2
- package/dist/lib/{providers-2X5JB2JX.js → providers-N52Y2QTJ.js} +1 -1
- package/dist/lib/{tool-filter-HUVHJN3O.js → tool-filter-F4S25GMJ.js} +1 -1
- package/dist/main.js +366 -237
- package/dist/{openai-RYXW7AKZ.js → openai-VV2RYB77.js} +1 -1
- package/dist/{providers-YG2HYIG6.js → providers-UD3DPALA.js} +1 -1
- package/dist/server-FXK26WN2.js +4 -0
- package/package.json +11 -12
- package/dist/anthropic-WK6EYMUE.js +0 -4
- package/dist/chunk-4GE22WHI.js +0 -4
- package/dist/chunk-7ZBAF7M4.js +0 -4
- package/dist/chunk-QQZCYWYI.js +0 -241
- package/dist/esm-5V3TYPZK.js +0 -229
- package/dist/lib/chunk-EFNPK4SJ.js +0 -137
- package/dist/lib/sandbox-runtime-QDN5SXPM.js +0 -9
- package/dist/sandbox-runtime-ELKAYRIL.js +0 -4
- package/dist/server-66HLMSUR.js +0 -4
|
@@ -2,6 +2,192 @@ import {
|
|
|
2
2
|
__export
|
|
3
3
|
} from "./chunk-MLKGABMK.js";
|
|
4
4
|
|
|
5
|
+
// src/config/provider-config.ts
|
|
6
|
+
var provider_config_exports = {};
|
|
7
|
+
__export(provider_config_exports, {
|
|
8
|
+
DEFAULT_CONTEXT_WINDOW: () => DEFAULT_CONTEXT_WINDOW,
|
|
9
|
+
DEFAULT_MAX_OUTPUT_TOKENS: () => DEFAULT_MAX_OUTPUT_TOKENS,
|
|
10
|
+
DEFAULT_THINKING_LEVEL: () => DEFAULT_THINKING_LEVEL,
|
|
11
|
+
MIN_THINKING_ANSWER_TOKENS: () => MIN_THINKING_ANSWER_TOKENS,
|
|
12
|
+
MIN_THINKING_BUDGET_TOKENS: () => MIN_THINKING_BUDGET_TOKENS,
|
|
13
|
+
ProviderConfigSchema: () => ProviderConfigSchema,
|
|
14
|
+
THINKING_BUDGETS: () => THINKING_BUDGETS,
|
|
15
|
+
THINKING_LEVELS: () => THINKING_LEVELS,
|
|
16
|
+
clampThinkingLevel: () => clampThinkingLevel,
|
|
17
|
+
getContextWindow: () => getContextWindow,
|
|
18
|
+
getMaxOutputTokens: () => getMaxOutputTokens,
|
|
19
|
+
getSupportedThinkingLevels: () => getSupportedThinkingLevels,
|
|
20
|
+
getThinkingLevel: () => getThinkingLevel,
|
|
21
|
+
globalConfigPath: () => globalConfigPath,
|
|
22
|
+
isValidThinkingLevel: () => isValidThinkingLevel,
|
|
23
|
+
resolveDefaultProvider: () => resolveDefaultProvider,
|
|
24
|
+
thinkingBudgetForLevel: () => thinkingBudgetForLevel,
|
|
25
|
+
toAnthropicThinkingEffort: () => toAnthropicThinkingEffort,
|
|
26
|
+
toReasoningEffort: () => toReasoningEffort,
|
|
27
|
+
withProviderDefaults: () => withProviderDefaults
|
|
28
|
+
});
|
|
29
|
+
import { homedir } from "os";
|
|
30
|
+
import { join } from "path";
|
|
31
|
+
import { z } from "zod";
|
|
32
|
+
function globalConfigPath() {
|
|
33
|
+
return join(homedir(), ".yukino", "config.yaml");
|
|
34
|
+
}
|
|
35
|
+
var THINKING_LEVELS = [
|
|
36
|
+
"off",
|
|
37
|
+
"minimal",
|
|
38
|
+
"low",
|
|
39
|
+
"medium",
|
|
40
|
+
"high",
|
|
41
|
+
"xhigh",
|
|
42
|
+
"max"
|
|
43
|
+
];
|
|
44
|
+
var ReasoningEffortSchema = z.enum([
|
|
45
|
+
"none",
|
|
46
|
+
"minimal",
|
|
47
|
+
"low",
|
|
48
|
+
"medium",
|
|
49
|
+
"high",
|
|
50
|
+
"xhigh",
|
|
51
|
+
"max"
|
|
52
|
+
]);
|
|
53
|
+
var AnthropicEffortSchema = z.enum(["low", "medium", "high", "xhigh", "max"]);
|
|
54
|
+
var ThinkingLevelMapSchema = z.strictObject({
|
|
55
|
+
off: z.literal("none").nullable().optional(),
|
|
56
|
+
minimal: ReasoningEffortSchema.nullable().optional(),
|
|
57
|
+
low: ReasoningEffortSchema.nullable().optional(),
|
|
58
|
+
medium: ReasoningEffortSchema.nullable().optional(),
|
|
59
|
+
high: ReasoningEffortSchema.nullable().optional(),
|
|
60
|
+
xhigh: ReasoningEffortSchema.nullable().optional(),
|
|
61
|
+
max: ReasoningEffortSchema.nullable().optional()
|
|
62
|
+
});
|
|
63
|
+
var ProviderConfigSchema = z.looseObject({
|
|
64
|
+
name: z.string(),
|
|
65
|
+
protocol: z.enum(["anthropic", "openai", "openai-compat"]),
|
|
66
|
+
base_url: z.string(),
|
|
67
|
+
model: z.string(),
|
|
68
|
+
api_key: z.string().optional(),
|
|
69
|
+
thinking: z.enum(THINKING_LEVELS).optional(),
|
|
70
|
+
/** Explicit capability metadata, never inferred from model names. */
|
|
71
|
+
reasoning: z.boolean().optional(),
|
|
72
|
+
thinking_level_map: ThinkingLevelMapSchema.optional(),
|
|
73
|
+
/** Only Anthropic uses this mode; existing configurations use budgets. */
|
|
74
|
+
thinking_mode: z.enum(["budget", "adaptive"]).optional(),
|
|
75
|
+
context_window: z.coerce.number().optional(),
|
|
76
|
+
/**
|
|
77
|
+
* The model's output ceiling (PI's `model.maxTokens`). Clamped to the
|
|
78
|
+
* context window; reasoning shares this ceiling instead of raising it.
|
|
79
|
+
*/
|
|
80
|
+
max_output_tokens: z.coerce.number().optional()
|
|
81
|
+
});
|
|
82
|
+
function resolveDefaultProvider(providers, defaultProvider) {
|
|
83
|
+
return providers[defaultProvider] ?? providers[0];
|
|
84
|
+
}
|
|
85
|
+
var DEFAULT_THINKING_LEVEL = "high";
|
|
86
|
+
var DEFAULT_CONTEXT_WINDOW = 1e6;
|
|
87
|
+
var DEFAULT_MAX_OUTPUT_TOKENS = 128e3;
|
|
88
|
+
var THINKING_BUDGETS = {
|
|
89
|
+
minimal: 1024,
|
|
90
|
+
low: 2048,
|
|
91
|
+
medium: 8192,
|
|
92
|
+
high: 16384,
|
|
93
|
+
xhigh: 32768,
|
|
94
|
+
max: 65536
|
|
95
|
+
};
|
|
96
|
+
var MIN_THINKING_BUDGET_TOKENS = 1024;
|
|
97
|
+
var MIN_THINKING_ANSWER_TOKENS = 1024;
|
|
98
|
+
function isValidThinkingLevel(value) {
|
|
99
|
+
return THINKING_LEVELS.some((level) => level === value);
|
|
100
|
+
}
|
|
101
|
+
function getThinkingLevel(provider) {
|
|
102
|
+
return clampThinkingLevel(
|
|
103
|
+
provider,
|
|
104
|
+
provider.thinking ?? DEFAULT_THINKING_LEVEL
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
function thinkingBudgetForLevel(level) {
|
|
108
|
+
return level === "off" ? 0 : THINKING_BUDGETS[level];
|
|
109
|
+
}
|
|
110
|
+
function toReasoningEffort(level, provider) {
|
|
111
|
+
if (provider?.reasoning === false) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
if (level === "off") {
|
|
115
|
+
return "none";
|
|
116
|
+
}
|
|
117
|
+
const mapped = provider?.thinking_level_map?.[level];
|
|
118
|
+
if (mapped !== void 0) {
|
|
119
|
+
return mapped;
|
|
120
|
+
}
|
|
121
|
+
if (provider?.protocol === "anthropic" && provider.thinking_mode === "adaptive") {
|
|
122
|
+
if (level === "minimal") {
|
|
123
|
+
return "low";
|
|
124
|
+
}
|
|
125
|
+
if (level === "xhigh") {
|
|
126
|
+
return "high";
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if ((provider?.protocol === "openai" || provider?.protocol === "openai-compat") && (level === "xhigh" || level === "max")) {
|
|
130
|
+
return "high";
|
|
131
|
+
}
|
|
132
|
+
return level;
|
|
133
|
+
}
|
|
134
|
+
function toAnthropicThinkingEffort(level, provider) {
|
|
135
|
+
const parsed = AnthropicEffortSchema.safeParse(
|
|
136
|
+
toReasoningEffort(level, provider)
|
|
137
|
+
);
|
|
138
|
+
return parsed.success ? parsed.data : null;
|
|
139
|
+
}
|
|
140
|
+
function getSupportedThinkingLevels(provider) {
|
|
141
|
+
if (provider.reasoning === false || provider.protocol === "anthropic" && provider.thinking_mode !== "adaptive" && getMaxOutputTokens(provider) < MIN_THINKING_BUDGET_TOKENS + MIN_THINKING_ANSWER_TOKENS) {
|
|
142
|
+
return ["off"];
|
|
143
|
+
}
|
|
144
|
+
return THINKING_LEVELS.filter((level) => {
|
|
145
|
+
if (level === "off") {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
if (provider.protocol === "anthropic" && provider.thinking_mode === "adaptive") {
|
|
149
|
+
return toAnthropicThinkingEffort(level, provider) !== null;
|
|
150
|
+
}
|
|
151
|
+
const effort = toReasoningEffort(level, provider);
|
|
152
|
+
if (effort === null || effort === "none") {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
if ((provider.protocol === "openai" || provider.protocol === "openai-compat") && (level === "xhigh" || level === "max") && provider.thinking_level_map?.[level] === void 0) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function clampThinkingLevel(provider, level) {
|
|
162
|
+
const supported = getSupportedThinkingLevels(provider);
|
|
163
|
+
let effective = "off";
|
|
164
|
+
for (const candidate of THINKING_LEVELS) {
|
|
165
|
+
if (supported.includes(candidate)) {
|
|
166
|
+
effective = candidate;
|
|
167
|
+
}
|
|
168
|
+
if (candidate === level) {
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return effective;
|
|
173
|
+
}
|
|
174
|
+
function withProviderDefaults(provider) {
|
|
175
|
+
return {
|
|
176
|
+
...provider,
|
|
177
|
+
thinking: getThinkingLevel(provider),
|
|
178
|
+
context_window: getContextWindow(provider),
|
|
179
|
+
max_output_tokens: getMaxOutputTokens(provider)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function getContextWindow(provider) {
|
|
183
|
+
return Number.isSafeInteger(provider.context_window) && (provider.context_window ?? 0) > 0 ? provider.context_window ?? DEFAULT_CONTEXT_WINDOW : DEFAULT_CONTEXT_WINDOW;
|
|
184
|
+
}
|
|
185
|
+
function getMaxOutputTokens(provider) {
|
|
186
|
+
const configured = provider.max_output_tokens;
|
|
187
|
+
const maxOutput = Number.isSafeInteger(configured) && (configured ?? 0) > 0 ? configured ?? DEFAULT_MAX_OUTPUT_TOKENS : DEFAULT_MAX_OUTPUT_TOKENS;
|
|
188
|
+
return Math.min(maxOutput, getContextWindow(provider));
|
|
189
|
+
}
|
|
190
|
+
|
|
5
191
|
// src/logger/index.ts
|
|
6
192
|
var logger_exports = {};
|
|
7
193
|
__export(logger_exports, {
|
|
@@ -13,15 +199,15 @@ __export(logger_exports, {
|
|
|
13
199
|
});
|
|
14
200
|
import { openSync, closeSync, mkdirSync, writeFileSync } from "fs";
|
|
15
201
|
import { readdir, stat, unlink } from "fs/promises";
|
|
16
|
-
import { homedir } from "os";
|
|
17
|
-
import { join, dirname, basename } from "path";
|
|
202
|
+
import { homedir as homedir2 } from "os";
|
|
203
|
+
import { join as join2, dirname, basename } from "path";
|
|
18
204
|
import pino from "pino";
|
|
19
205
|
var currentLogger = null;
|
|
20
206
|
var currentDest = null;
|
|
21
207
|
var currentFd = null;
|
|
22
208
|
function resolveLogPath(opts) {
|
|
23
|
-
const dir = opts.logDir ??
|
|
24
|
-
return
|
|
209
|
+
const dir = opts.logDir ?? join2(opts.workDir ?? process.cwd(), ".yukino", "logs");
|
|
210
|
+
return join2(dir, `${opts.sessionId}.jsonl`);
|
|
25
211
|
}
|
|
26
212
|
function ensureYukinoGitignore(logPath) {
|
|
27
213
|
let dir = dirname(logPath);
|
|
@@ -33,7 +219,7 @@ function ensureYukinoGitignore(logPath) {
|
|
|
33
219
|
dir = parent;
|
|
34
220
|
}
|
|
35
221
|
try {
|
|
36
|
-
writeFileSync(
|
|
222
|
+
writeFileSync(join2(dir, ".gitignore"), "*\n", { flag: "wx" });
|
|
37
223
|
} catch {
|
|
38
224
|
}
|
|
39
225
|
}
|
|
@@ -162,7 +348,7 @@ async function cleanDir(dir) {
|
|
|
162
348
|
const now = Date.now();
|
|
163
349
|
let removed = 0;
|
|
164
350
|
for (const file of files) {
|
|
165
|
-
const filePath =
|
|
351
|
+
const filePath = join2(dir, file);
|
|
166
352
|
try {
|
|
167
353
|
const s = await stat(filePath);
|
|
168
354
|
if (now - s.mtimeMs > 30 * 24 * 60 * 60 * 1e3) {
|
|
@@ -176,8 +362,8 @@ async function cleanDir(dir) {
|
|
|
176
362
|
}
|
|
177
363
|
async function cleanExpiredLogs(workDir) {
|
|
178
364
|
let removed = 0;
|
|
179
|
-
removed += await cleanDir(
|
|
180
|
-
const teamsDir =
|
|
365
|
+
removed += await cleanDir(join2(workDir, ".yukino", "logs"));
|
|
366
|
+
const teamsDir = join2(homedir2(), ".yukino", "teams");
|
|
181
367
|
let teams;
|
|
182
368
|
try {
|
|
183
369
|
teams = await readdir(teamsDir);
|
|
@@ -185,7 +371,7 @@ async function cleanExpiredLogs(workDir) {
|
|
|
185
371
|
return removed;
|
|
186
372
|
}
|
|
187
373
|
for (const team of teams) {
|
|
188
|
-
removed += await cleanDir(
|
|
374
|
+
removed += await cleanDir(join2(teamsDir, team, "logs"));
|
|
189
375
|
}
|
|
190
376
|
return removed;
|
|
191
377
|
}
|
|
@@ -224,410 +410,22 @@ function safeStringify(value) {
|
|
|
224
410
|
}
|
|
225
411
|
try {
|
|
226
412
|
const json = JSON.stringify(value);
|
|
227
|
-
if (json !== void 0) {
|
|
228
|
-
return json;
|
|
229
|
-
}
|
|
230
|
-
} catch {
|
|
231
|
-
}
|
|
232
|
-
try {
|
|
233
|
-
return String(value);
|
|
234
|
-
} catch {
|
|
235
|
-
return Object.prototype.toString.call(value);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
function errSerializer(err) {
|
|
239
|
-
if (err instanceof Error) {
|
|
240
|
-
return serializeErrorInstance(err, 0);
|
|
241
|
-
}
|
|
242
|
-
return { message: safeStringify(err), value: err };
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// src/utils/index.ts
|
|
246
|
-
var utils_exports = {};
|
|
247
|
-
__export(utils_exports, {
|
|
248
|
-
Paths: () => paths_exports,
|
|
249
|
-
Slug: () => slug_exports,
|
|
250
|
-
asError: () => asError,
|
|
251
|
-
asErrorString: () => asErrorString,
|
|
252
|
-
asRecord: () => asRecord,
|
|
253
|
-
asString: () => asString,
|
|
254
|
-
boolArg: () => boolArg,
|
|
255
|
-
contentToText: () => contentToText,
|
|
256
|
-
formatToolArgs: () => formatToolArgs,
|
|
257
|
-
intArg: () => intArg,
|
|
258
|
-
isObject: () => isObject,
|
|
259
|
-
isRecord: () => isRecord,
|
|
260
|
-
safeJSONParse: () => safeJSONParse,
|
|
261
|
-
strArg: () => strArg,
|
|
262
|
-
strList: () => strList,
|
|
263
|
-
toTry: () => toTry
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
// src/utils/paths.ts
|
|
267
|
-
var paths_exports = {};
|
|
268
|
-
__export(paths_exports, {
|
|
269
|
-
canonicalPath: () => canonicalPath,
|
|
270
|
-
compactPath: () => compactPath,
|
|
271
|
-
isPathWithin: () => isPathWithin
|
|
272
|
-
});
|
|
273
|
-
import { realpathSync } from "fs";
|
|
274
|
-
import { homedir as homedir2 } from "os";
|
|
275
|
-
import {
|
|
276
|
-
basename as basename2,
|
|
277
|
-
dirname as dirname2,
|
|
278
|
-
isAbsolute,
|
|
279
|
-
join as join2,
|
|
280
|
-
relative,
|
|
281
|
-
resolve,
|
|
282
|
-
sep
|
|
283
|
-
} from "path";
|
|
284
|
-
function canonicalPath(path) {
|
|
285
|
-
let current = resolve(path);
|
|
286
|
-
const missing = [];
|
|
287
|
-
for (; ; ) {
|
|
288
|
-
try {
|
|
289
|
-
return join2(realpathSync(current), ...missing);
|
|
290
|
-
} catch (error) {
|
|
291
|
-
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT" && error.code !== "ENOTDIR") {
|
|
292
|
-
throw error;
|
|
293
|
-
}
|
|
294
|
-
const parent = dirname2(current);
|
|
295
|
-
if (parent === current) {
|
|
296
|
-
return resolve(path);
|
|
297
|
-
}
|
|
298
|
-
missing.unshift(basename2(current));
|
|
299
|
-
current = parent;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
function isPathWithin(root, path) {
|
|
304
|
-
const child = relative(root, path);
|
|
305
|
-
return child === "" || child !== ".." && !child.startsWith(`..${sep}`) && !isAbsolute(child);
|
|
306
|
-
}
|
|
307
|
-
function compactPath(path) {
|
|
308
|
-
const home = homedir2();
|
|
309
|
-
return path === home ? "~" : path.startsWith(`${home}/`) ? `~/${path.slice(home.length + 1)}` : path;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// src/utils/slug.ts
|
|
313
|
-
var slug_exports = {};
|
|
314
|
-
__export(slug_exports, {
|
|
315
|
-
generateSlug: () => generateSlug
|
|
316
|
-
});
|
|
317
|
-
import { randomBytes } from "crypto";
|
|
318
|
-
function generateSlug() {
|
|
319
|
-
const timestamp = Date.now().toString(36);
|
|
320
|
-
const entropy = randomBytes(6).toString("hex");
|
|
321
|
-
return `${timestamp}-${entropy}`;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// src/utils/index.ts
|
|
325
|
-
var log = createChildLogger({ module: "utils" });
|
|
326
|
-
function contentToText(content) {
|
|
327
|
-
if (typeof content === "string") {
|
|
328
|
-
return content;
|
|
329
|
-
}
|
|
330
|
-
const parts = [];
|
|
331
|
-
for (const block of content) {
|
|
332
|
-
if (block.type === "text" && typeof block.text === "string") {
|
|
333
|
-
parts.push(block.text);
|
|
334
|
-
} else if (block.type === "image" && isRecord(block.source)) {
|
|
335
|
-
const mediaType = block.source.type === "base64" && typeof block.source.media_type === "string" ? block.source.media_type : "image";
|
|
336
|
-
parts.push(`[Image: ${mediaType}]`);
|
|
337
|
-
} else if (block.type === "tool_reference" && typeof block.tool_name === "string") {
|
|
338
|
-
parts.push(`[Tool reference: ${block.tool_name}]`);
|
|
339
|
-
} else if (block.type === "search_result") {
|
|
340
|
-
const title = typeof block.title === "string" ? block.title : "search result";
|
|
341
|
-
const source = typeof block.source === "string" ? ` (${block.source})` : "";
|
|
342
|
-
const nested = Array.isArray(block.content) ? contentToText(block.content.filter(isRecord)) : "";
|
|
343
|
-
parts.push(`${title}${source}${nested ? `
|
|
344
|
-
${nested}` : ""}`);
|
|
345
|
-
} else if (block.type === "document") {
|
|
346
|
-
const title = typeof block.title === "string" ? block.title : "document";
|
|
347
|
-
parts.push(`[Document: ${title}]`);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
return parts.join("\n");
|
|
351
|
-
}
|
|
352
|
-
function isRecord(value) {
|
|
353
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
354
|
-
}
|
|
355
|
-
function asRecord(value) {
|
|
356
|
-
if (isRecord(value)) {
|
|
357
|
-
return value;
|
|
358
|
-
}
|
|
359
|
-
if (Array.isArray(value)) {
|
|
360
|
-
return Object.fromEntries(value.entries());
|
|
361
|
-
}
|
|
362
|
-
return {};
|
|
363
|
-
}
|
|
364
|
-
function asString(value) {
|
|
365
|
-
if (typeof value === "string") {
|
|
366
|
-
return value;
|
|
367
|
-
}
|
|
368
|
-
return String(value);
|
|
369
|
-
}
|
|
370
|
-
function asErrorString(value) {
|
|
371
|
-
if (value instanceof Error) {
|
|
372
|
-
return value.message;
|
|
373
|
-
}
|
|
374
|
-
return asString(value);
|
|
375
|
-
}
|
|
376
|
-
function isObject(value) {
|
|
377
|
-
return typeof value === "object" && value !== null;
|
|
378
|
-
}
|
|
379
|
-
function toTry(fn, ctx) {
|
|
380
|
-
if (typeof fn !== "function") {
|
|
381
|
-
return fn;
|
|
382
|
-
}
|
|
383
|
-
return function(...args) {
|
|
384
|
-
let ret;
|
|
385
|
-
try {
|
|
386
|
-
ret = ctx ? fn.call(ctx, ...args) : fn.call(this, ...args);
|
|
387
|
-
} catch (err) {
|
|
388
|
-
log.error({ err }, "utils operation failed");
|
|
389
|
-
return void 0;
|
|
390
|
-
}
|
|
391
|
-
return ret;
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
var safeJSONParse = toTry(JSON.parse, JSON);
|
|
395
|
-
function asError(err) {
|
|
396
|
-
if (err instanceof Error) {
|
|
397
|
-
return err;
|
|
398
|
-
}
|
|
399
|
-
return new Error(String(err));
|
|
400
|
-
}
|
|
401
|
-
function intArg(args, key, fallback) {
|
|
402
|
-
const v = args[key];
|
|
403
|
-
if (typeof v === "number") {
|
|
404
|
-
return Math.floor(v);
|
|
405
|
-
}
|
|
406
|
-
if (typeof v === "string") {
|
|
407
|
-
const n = Number.parseInt(v, 10);
|
|
408
|
-
return Number.isNaN(n) ? fallback : n;
|
|
409
|
-
}
|
|
410
|
-
return fallback;
|
|
411
|
-
}
|
|
412
|
-
function strList(raw) {
|
|
413
|
-
if (Array.isArray(raw)) {
|
|
414
|
-
return raw.filter((v) => typeof v === "string");
|
|
415
|
-
}
|
|
416
|
-
return [];
|
|
417
|
-
}
|
|
418
|
-
function strArg(args, key, fallback) {
|
|
419
|
-
const v = args[key];
|
|
420
|
-
if (typeof v === "string") {
|
|
421
|
-
return v;
|
|
422
|
-
}
|
|
423
|
-
return fallback ?? "";
|
|
424
|
-
}
|
|
425
|
-
function boolArg(args, key, fallback) {
|
|
426
|
-
const v = args[key];
|
|
427
|
-
if (typeof v === "boolean") {
|
|
428
|
-
return v;
|
|
429
|
-
}
|
|
430
|
-
return fallback ?? Boolean(v);
|
|
431
|
-
}
|
|
432
|
-
function formatToolArgs(args) {
|
|
433
|
-
if (args.command) {
|
|
434
|
-
return truncate(strArg(args, "command"), 80);
|
|
435
|
-
}
|
|
436
|
-
if (args.file_path) {
|
|
437
|
-
return truncate(strArg(args, "file_path"), 80);
|
|
438
|
-
}
|
|
439
|
-
if (args.pattern) {
|
|
440
|
-
return truncate(strArg(args, "pattern"), 80);
|
|
441
|
-
}
|
|
442
|
-
if (args.description) {
|
|
443
|
-
return truncate(strArg(args, "description"), 80);
|
|
444
|
-
}
|
|
445
|
-
return "";
|
|
446
|
-
}
|
|
447
|
-
function truncate(value, max) {
|
|
448
|
-
return value.length > max ? `${value.slice(0, max)}\u2026` : value;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
// src/config/provider-config.ts
|
|
452
|
-
var provider_config_exports = {};
|
|
453
|
-
__export(provider_config_exports, {
|
|
454
|
-
DEFAULT_CONTEXT_WINDOW: () => DEFAULT_CONTEXT_WINDOW,
|
|
455
|
-
DEFAULT_MAX_OUTPUT_TOKENS: () => DEFAULT_MAX_OUTPUT_TOKENS,
|
|
456
|
-
DEFAULT_THINKING_LEVEL: () => DEFAULT_THINKING_LEVEL,
|
|
457
|
-
MIN_THINKING_ANSWER_TOKENS: () => MIN_THINKING_ANSWER_TOKENS,
|
|
458
|
-
MIN_THINKING_BUDGET_TOKENS: () => MIN_THINKING_BUDGET_TOKENS,
|
|
459
|
-
ProviderConfigSchema: () => ProviderConfigSchema,
|
|
460
|
-
THINKING_BUDGETS: () => THINKING_BUDGETS,
|
|
461
|
-
THINKING_LEVELS: () => THINKING_LEVELS,
|
|
462
|
-
clampThinkingLevel: () => clampThinkingLevel,
|
|
463
|
-
getContextWindow: () => getContextWindow,
|
|
464
|
-
getMaxOutputTokens: () => getMaxOutputTokens,
|
|
465
|
-
getSupportedThinkingLevels: () => getSupportedThinkingLevels,
|
|
466
|
-
getThinkingLevel: () => getThinkingLevel,
|
|
467
|
-
globalConfigPath: () => globalConfigPath,
|
|
468
|
-
isValidThinkingLevel: () => isValidThinkingLevel,
|
|
469
|
-
thinkingBudgetForLevel: () => thinkingBudgetForLevel,
|
|
470
|
-
toAnthropicThinkingEffort: () => toAnthropicThinkingEffort,
|
|
471
|
-
toReasoningEffort: () => toReasoningEffort,
|
|
472
|
-
withProviderDefaults: () => withProviderDefaults
|
|
473
|
-
});
|
|
474
|
-
import { homedir as homedir3 } from "os";
|
|
475
|
-
import { join as join3 } from "path";
|
|
476
|
-
import { z } from "zod";
|
|
477
|
-
function globalConfigPath() {
|
|
478
|
-
return join3(homedir3(), ".yukino", "config.yaml");
|
|
479
|
-
}
|
|
480
|
-
var THINKING_LEVELS = [
|
|
481
|
-
"off",
|
|
482
|
-
"minimal",
|
|
483
|
-
"low",
|
|
484
|
-
"medium",
|
|
485
|
-
"high",
|
|
486
|
-
"xhigh",
|
|
487
|
-
"max"
|
|
488
|
-
];
|
|
489
|
-
var ReasoningEffortSchema = z.enum([
|
|
490
|
-
"none",
|
|
491
|
-
"minimal",
|
|
492
|
-
"low",
|
|
493
|
-
"medium",
|
|
494
|
-
"high",
|
|
495
|
-
"xhigh",
|
|
496
|
-
"max"
|
|
497
|
-
]);
|
|
498
|
-
var AnthropicEffortSchema = z.enum(["low", "medium", "high", "xhigh", "max"]);
|
|
499
|
-
var ThinkingLevelMapSchema = z.strictObject({
|
|
500
|
-
off: z.literal("none").nullable().optional(),
|
|
501
|
-
minimal: ReasoningEffortSchema.nullable().optional(),
|
|
502
|
-
low: ReasoningEffortSchema.nullable().optional(),
|
|
503
|
-
medium: ReasoningEffortSchema.nullable().optional(),
|
|
504
|
-
high: ReasoningEffortSchema.nullable().optional(),
|
|
505
|
-
xhigh: ReasoningEffortSchema.nullable().optional(),
|
|
506
|
-
max: ReasoningEffortSchema.nullable().optional()
|
|
507
|
-
});
|
|
508
|
-
var ProviderConfigSchema = z.looseObject({
|
|
509
|
-
name: z.string(),
|
|
510
|
-
protocol: z.enum(["anthropic", "openai", "openai-compat"]),
|
|
511
|
-
base_url: z.string(),
|
|
512
|
-
model: z.string(),
|
|
513
|
-
api_key: z.string().optional(),
|
|
514
|
-
thinking: z.enum(THINKING_LEVELS).optional(),
|
|
515
|
-
/** Explicit capability metadata, never inferred from model names. */
|
|
516
|
-
reasoning: z.boolean().optional(),
|
|
517
|
-
thinking_level_map: ThinkingLevelMapSchema.optional(),
|
|
518
|
-
/** Only Anthropic uses this mode; existing configurations use budgets. */
|
|
519
|
-
thinking_mode: z.enum(["budget", "adaptive"]).optional(),
|
|
520
|
-
context_window: z.coerce.number().optional(),
|
|
521
|
-
/**
|
|
522
|
-
* The model's output ceiling (PI's `model.maxTokens`). Clamped to the
|
|
523
|
-
* context window; reasoning shares this ceiling instead of raising it.
|
|
524
|
-
*/
|
|
525
|
-
max_output_tokens: z.coerce.number().optional()
|
|
526
|
-
});
|
|
527
|
-
var DEFAULT_THINKING_LEVEL = "high";
|
|
528
|
-
var DEFAULT_CONTEXT_WINDOW = 1e6;
|
|
529
|
-
var DEFAULT_MAX_OUTPUT_TOKENS = 128e3;
|
|
530
|
-
var THINKING_BUDGETS = {
|
|
531
|
-
minimal: 1024,
|
|
532
|
-
low: 2048,
|
|
533
|
-
medium: 8192,
|
|
534
|
-
high: 16384,
|
|
535
|
-
xhigh: 32768,
|
|
536
|
-
max: 65536
|
|
537
|
-
};
|
|
538
|
-
var MIN_THINKING_BUDGET_TOKENS = 1024;
|
|
539
|
-
var MIN_THINKING_ANSWER_TOKENS = 1024;
|
|
540
|
-
function isValidThinkingLevel(value) {
|
|
541
|
-
return THINKING_LEVELS.some((level) => level === value);
|
|
542
|
-
}
|
|
543
|
-
function getThinkingLevel(provider) {
|
|
544
|
-
return clampThinkingLevel(
|
|
545
|
-
provider,
|
|
546
|
-
provider.thinking ?? DEFAULT_THINKING_LEVEL
|
|
547
|
-
);
|
|
548
|
-
}
|
|
549
|
-
function thinkingBudgetForLevel(level) {
|
|
550
|
-
return level === "off" ? 0 : THINKING_BUDGETS[level];
|
|
551
|
-
}
|
|
552
|
-
function toReasoningEffort(level, provider) {
|
|
553
|
-
if (provider?.reasoning === false) {
|
|
554
|
-
return null;
|
|
555
|
-
}
|
|
556
|
-
if (level === "off") {
|
|
557
|
-
return "none";
|
|
558
|
-
}
|
|
559
|
-
const mapped = provider?.thinking_level_map?.[level];
|
|
560
|
-
if (mapped !== void 0) {
|
|
561
|
-
return mapped;
|
|
562
|
-
}
|
|
563
|
-
if (provider?.protocol === "anthropic" && provider.thinking_mode === "adaptive") {
|
|
564
|
-
if (level === "minimal") {
|
|
565
|
-
return "low";
|
|
566
|
-
}
|
|
567
|
-
if (level === "xhigh") {
|
|
568
|
-
return "high";
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
if ((provider?.protocol === "openai" || provider?.protocol === "openai-compat") && (level === "xhigh" || level === "max")) {
|
|
572
|
-
return "high";
|
|
573
|
-
}
|
|
574
|
-
return level;
|
|
575
|
-
}
|
|
576
|
-
function toAnthropicThinkingEffort(level, provider) {
|
|
577
|
-
const parsed = AnthropicEffortSchema.safeParse(
|
|
578
|
-
toReasoningEffort(level, provider)
|
|
579
|
-
);
|
|
580
|
-
return parsed.success ? parsed.data : null;
|
|
581
|
-
}
|
|
582
|
-
function getSupportedThinkingLevels(provider) {
|
|
583
|
-
if (provider.reasoning === false || provider.protocol === "anthropic" && provider.thinking_mode !== "adaptive" && getMaxOutputTokens(provider) < MIN_THINKING_BUDGET_TOKENS + MIN_THINKING_ANSWER_TOKENS) {
|
|
584
|
-
return ["off"];
|
|
585
|
-
}
|
|
586
|
-
return THINKING_LEVELS.filter((level) => {
|
|
587
|
-
if (level === "off") {
|
|
588
|
-
return true;
|
|
589
|
-
}
|
|
590
|
-
if (provider.protocol === "anthropic" && provider.thinking_mode === "adaptive") {
|
|
591
|
-
return toAnthropicThinkingEffort(level, provider) !== null;
|
|
592
|
-
}
|
|
593
|
-
const effort = toReasoningEffort(level, provider);
|
|
594
|
-
if (effort === null || effort === "none") {
|
|
595
|
-
return false;
|
|
596
|
-
}
|
|
597
|
-
if ((provider.protocol === "openai" || provider.protocol === "openai-compat") && (level === "xhigh" || level === "max") && provider.thinking_level_map?.[level] === void 0) {
|
|
598
|
-
return false;
|
|
599
|
-
}
|
|
600
|
-
return true;
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
function clampThinkingLevel(provider, level) {
|
|
604
|
-
const supported = getSupportedThinkingLevels(provider);
|
|
605
|
-
let effective = "off";
|
|
606
|
-
for (const candidate of THINKING_LEVELS) {
|
|
607
|
-
if (supported.includes(candidate)) {
|
|
608
|
-
effective = candidate;
|
|
609
|
-
}
|
|
610
|
-
if (candidate === level) {
|
|
611
|
-
break;
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
return effective;
|
|
615
|
-
}
|
|
616
|
-
function withProviderDefaults(provider) {
|
|
617
|
-
return {
|
|
618
|
-
...provider,
|
|
619
|
-
thinking: getThinkingLevel(provider),
|
|
620
|
-
context_window: getContextWindow(provider),
|
|
621
|
-
max_output_tokens: getMaxOutputTokens(provider)
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
function getContextWindow(provider) {
|
|
625
|
-
return Number.isSafeInteger(provider.context_window) && (provider.context_window ?? 0) > 0 ? provider.context_window ?? DEFAULT_CONTEXT_WINDOW : DEFAULT_CONTEXT_WINDOW;
|
|
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
|
+
}
|
|
626
423
|
}
|
|
627
|
-
function
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
424
|
+
function errSerializer(err) {
|
|
425
|
+
if (err instanceof Error) {
|
|
426
|
+
return serializeErrorInstance(err, 0);
|
|
427
|
+
}
|
|
428
|
+
return { message: safeStringify(err), value: err };
|
|
631
429
|
}
|
|
632
430
|
|
|
633
431
|
// src/config/index.ts
|
|
@@ -645,7 +443,7 @@ __export(config_exports, {
|
|
|
645
443
|
withProjectMcpServers: () => withProjectMcpServers
|
|
646
444
|
});
|
|
647
445
|
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
648
|
-
import { join as
|
|
446
|
+
import { join as join4 } from "path";
|
|
649
447
|
import {
|
|
650
448
|
getParseErrorMessage,
|
|
651
449
|
safeParse
|
|
@@ -671,7 +469,7 @@ import {
|
|
|
671
469
|
unlinkSync,
|
|
672
470
|
writeFileSync as writeFileSync2
|
|
673
471
|
} from "fs";
|
|
674
|
-
import { dirname as
|
|
472
|
+
import { dirname as dirname2, join as join3 } from "path";
|
|
675
473
|
import yaml from "js-yaml";
|
|
676
474
|
import { z as z2 } from "zod";
|
|
677
475
|
var tokenLimit = (fallback, min, max) => z2.preprocess(
|
|
@@ -711,9 +509,9 @@ function readConfigRaw(path) {
|
|
|
711
509
|
return z2.record(z2.string(), z2.unknown()).parse(raw ?? {});
|
|
712
510
|
}
|
|
713
511
|
function writeConfigAtomic(path, raw) {
|
|
714
|
-
const directory =
|
|
512
|
+
const directory = dirname2(path);
|
|
715
513
|
mkdirSync2(directory, { recursive: true });
|
|
716
|
-
const temporary =
|
|
514
|
+
const temporary = join3(directory, `.config-${randomUUID()}.tmp`);
|
|
717
515
|
try {
|
|
718
516
|
writeFileSync2(temporary, yaml.dump(raw, { lineWidth: -1, noRefs: true }), {
|
|
719
517
|
encoding: "utf-8",
|
|
@@ -793,7 +591,7 @@ function persistDefaultProvider(index) {
|
|
|
793
591
|
}
|
|
794
592
|
|
|
795
593
|
// src/config/index.ts
|
|
796
|
-
var
|
|
594
|
+
var log = createChildLogger({ module: "config" });
|
|
797
595
|
var ENV_KEY_MAP = {
|
|
798
596
|
anthropic: "ANTHROPIC_API_KEY",
|
|
799
597
|
openai: "OPENAI_API_KEY",
|
|
@@ -846,7 +644,6 @@ var HookConfigSchema = z3.object({
|
|
|
846
644
|
});
|
|
847
645
|
var SandboxYamlConfigSchema = z3.object({
|
|
848
646
|
enabled: z3.boolean().optional(),
|
|
849
|
-
backend: z3.enum(["native", "sandbox-runtime"]).optional(),
|
|
850
647
|
auto_allow: z3.boolean().optional(),
|
|
851
648
|
network_enabled: z3.boolean().optional()
|
|
852
649
|
});
|
|
@@ -868,26 +665,26 @@ var AppConfigSchema = z3.looseObject({
|
|
|
868
665
|
* Whether auto memory is enabled: gates index injection, recall, and
|
|
869
666
|
* background extraction in the hosts that run them (interactive UI, remote,
|
|
870
667
|
* ACP), and consolidation, which currently runs only in remote mode.
|
|
871
|
-
* Defaults to enabled; `
|
|
872
|
-
* pipeline off. Left optional so "not set" and "explicitly false"
|
|
873
|
-
* distinguishable, mirroring enable_fork.
|
|
668
|
+
* Defaults to enabled; `enable_memory: false` turns the whole automatic
|
|
669
|
+
* memory pipeline off. Left optional so "not set" and "explicitly false"
|
|
670
|
+
* stay distinguishable, mirroring enable_fork.
|
|
874
671
|
*/
|
|
875
|
-
|
|
672
|
+
enable_memory: z3.boolean().optional()
|
|
876
673
|
});
|
|
877
674
|
function forkEnabled(cfg) {
|
|
878
675
|
return cfg.enable_fork !== false;
|
|
879
676
|
}
|
|
880
677
|
function memoryEnabled(cfg) {
|
|
881
|
-
return cfg.
|
|
678
|
+
return cfg.enable_memory !== false;
|
|
882
679
|
}
|
|
883
|
-
function
|
|
680
|
+
function isRecord(value) {
|
|
884
681
|
return typeof value === "object" && value !== null;
|
|
885
682
|
}
|
|
886
683
|
function loadSingleFile(path) {
|
|
887
684
|
const data = readFileSync2(path, "utf-8");
|
|
888
685
|
const raw = yaml2.load(data);
|
|
889
|
-
if (!
|
|
890
|
-
|
|
686
|
+
if (!isRecord(raw)) {
|
|
687
|
+
log.error({ path }, "invalid yaml");
|
|
891
688
|
return { default_provider: 0, providers: [], mcp_servers: [], hooks: [] };
|
|
892
689
|
}
|
|
893
690
|
const parsed = safeParse(AppConfigSchema, raw);
|
|
@@ -898,7 +695,7 @@ function loadSingleFile(path) {
|
|
|
898
695
|
providers: data2.providers.map(withProviderDefaults)
|
|
899
696
|
};
|
|
900
697
|
}
|
|
901
|
-
|
|
698
|
+
log.error({ error: parsed.error }, "config error");
|
|
902
699
|
let defaultProvider = 0;
|
|
903
700
|
let providers = [];
|
|
904
701
|
let permissionMode;
|
|
@@ -907,7 +704,7 @@ function loadSingleFile(path) {
|
|
|
907
704
|
let sandbox = void 0;
|
|
908
705
|
let enableCoordinatorMode = false;
|
|
909
706
|
let enableFork = true;
|
|
910
|
-
let
|
|
707
|
+
let enableMemory = true;
|
|
911
708
|
if ("default_provider" in raw) {
|
|
912
709
|
const parsed2 = safeParse(z3.number(), raw.default_provider);
|
|
913
710
|
if (parsed2.success) {
|
|
@@ -963,8 +760,8 @@ function loadSingleFile(path) {
|
|
|
963
760
|
if ("enable_fork" in raw) {
|
|
964
761
|
enableFork = Boolean(raw.enable_fork);
|
|
965
762
|
}
|
|
966
|
-
if ("
|
|
967
|
-
|
|
763
|
+
if ("enable_memory" in raw) {
|
|
764
|
+
enableMemory = Boolean(raw.enable_memory);
|
|
968
765
|
}
|
|
969
766
|
return {
|
|
970
767
|
default_provider: defaultProvider,
|
|
@@ -975,7 +772,7 @@ function loadSingleFile(path) {
|
|
|
975
772
|
sandbox,
|
|
976
773
|
enable_coordinator_mode: enableCoordinatorMode,
|
|
977
774
|
enable_fork: enableFork,
|
|
978
|
-
|
|
775
|
+
enable_memory: enableMemory
|
|
979
776
|
};
|
|
980
777
|
}
|
|
981
778
|
function validateProviders(config) {
|
|
@@ -1074,7 +871,7 @@ function mcpServerFromJsonEntry(name, entry) {
|
|
|
1074
871
|
return { name, url: entry.url, transport, headers: entry.headers };
|
|
1075
872
|
}
|
|
1076
873
|
function loadProjectMcpServers(workDir) {
|
|
1077
|
-
const path =
|
|
874
|
+
const path = join4(workDir, PROJECT_MCP_FILENAME);
|
|
1078
875
|
if (!existsSync2(path)) {
|
|
1079
876
|
return [];
|
|
1080
877
|
}
|
|
@@ -1082,19 +879,19 @@ function loadProjectMcpServers(workDir) {
|
|
|
1082
879
|
try {
|
|
1083
880
|
raw = JSON.parse(readFileSync2(path, "utf-8"));
|
|
1084
881
|
} catch (err) {
|
|
1085
|
-
|
|
882
|
+
log.error({ err, path }, "invalid .mcp.json");
|
|
1086
883
|
return [];
|
|
1087
884
|
}
|
|
1088
885
|
const parsed = safeParse(McpJsonFileSchema, raw);
|
|
1089
886
|
if (!parsed.success) {
|
|
1090
|
-
|
|
887
|
+
log.error({ error: parsed.error, path }, "invalid .mcp.json");
|
|
1091
888
|
return [];
|
|
1092
889
|
}
|
|
1093
890
|
const servers = [];
|
|
1094
891
|
for (const [name, rawEntry] of Object.entries(parsed.data.mcpServers)) {
|
|
1095
892
|
const parsedEntry = safeParse(McpJsonEntrySchema, rawEntry);
|
|
1096
893
|
if (!name.trim() || !parsedEntry.success) {
|
|
1097
|
-
|
|
894
|
+
log.warn(
|
|
1098
895
|
{
|
|
1099
896
|
name,
|
|
1100
897
|
path,
|
|
@@ -1108,7 +905,7 @@ function loadProjectMcpServers(workDir) {
|
|
|
1108
905
|
if (server) {
|
|
1109
906
|
servers.push(server);
|
|
1110
907
|
} else {
|
|
1111
|
-
|
|
908
|
+
log.warn({ name, path }, "skipping invalid .mcp.json server entry");
|
|
1112
909
|
}
|
|
1113
910
|
}
|
|
1114
911
|
return servers;
|
|
@@ -1151,6 +948,212 @@ function loadConfig(path, options = {}) {
|
|
|
1151
948
|
return config;
|
|
1152
949
|
}
|
|
1153
950
|
|
|
951
|
+
// src/utils/index.ts
|
|
952
|
+
var utils_exports = {};
|
|
953
|
+
__export(utils_exports, {
|
|
954
|
+
Paths: () => paths_exports,
|
|
955
|
+
Slug: () => slug_exports,
|
|
956
|
+
asError: () => asError,
|
|
957
|
+
asErrorString: () => asErrorString,
|
|
958
|
+
asRecord: () => asRecord,
|
|
959
|
+
asString: () => asString,
|
|
960
|
+
boolArg: () => boolArg,
|
|
961
|
+
contentToText: () => contentToText,
|
|
962
|
+
formatToolArgs: () => formatToolArgs,
|
|
963
|
+
intArg: () => intArg,
|
|
964
|
+
isObject: () => isObject,
|
|
965
|
+
isRecord: () => isRecord2,
|
|
966
|
+
safeJSONParse: () => safeJSONParse,
|
|
967
|
+
strArg: () => strArg,
|
|
968
|
+
strList: () => strList,
|
|
969
|
+
toTry: () => toTry
|
|
970
|
+
});
|
|
971
|
+
|
|
972
|
+
// src/utils/paths.ts
|
|
973
|
+
var paths_exports = {};
|
|
974
|
+
__export(paths_exports, {
|
|
975
|
+
canonicalPath: () => canonicalPath,
|
|
976
|
+
compactPath: () => compactPath,
|
|
977
|
+
isPathWithin: () => isPathWithin
|
|
978
|
+
});
|
|
979
|
+
import { realpathSync } from "fs";
|
|
980
|
+
import { homedir as homedir3 } from "os";
|
|
981
|
+
import {
|
|
982
|
+
basename as basename2,
|
|
983
|
+
dirname as dirname3,
|
|
984
|
+
isAbsolute,
|
|
985
|
+
join as join5,
|
|
986
|
+
relative,
|
|
987
|
+
resolve,
|
|
988
|
+
sep
|
|
989
|
+
} from "path";
|
|
990
|
+
function canonicalPath(path) {
|
|
991
|
+
let current = resolve(path);
|
|
992
|
+
const missing = [];
|
|
993
|
+
for (; ; ) {
|
|
994
|
+
try {
|
|
995
|
+
return join5(realpathSync(current), ...missing);
|
|
996
|
+
} catch (error) {
|
|
997
|
+
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT" && error.code !== "ENOTDIR") {
|
|
998
|
+
throw error;
|
|
999
|
+
}
|
|
1000
|
+
const parent = dirname3(current);
|
|
1001
|
+
if (parent === current) {
|
|
1002
|
+
return resolve(path);
|
|
1003
|
+
}
|
|
1004
|
+
missing.unshift(basename2(current));
|
|
1005
|
+
current = parent;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
function isPathWithin(root, path) {
|
|
1010
|
+
const child = relative(root, path);
|
|
1011
|
+
return child === "" || child !== ".." && !child.startsWith(`..${sep}`) && !isAbsolute(child);
|
|
1012
|
+
}
|
|
1013
|
+
function compactPath(path) {
|
|
1014
|
+
const home = homedir3();
|
|
1015
|
+
return path === home ? "~" : path.startsWith(`${home}/`) ? `~/${path.slice(home.length + 1)}` : path;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
// src/utils/slug.ts
|
|
1019
|
+
var slug_exports = {};
|
|
1020
|
+
__export(slug_exports, {
|
|
1021
|
+
generateSlug: () => generateSlug
|
|
1022
|
+
});
|
|
1023
|
+
import { randomBytes } from "crypto";
|
|
1024
|
+
function generateSlug() {
|
|
1025
|
+
const timestamp = Date.now().toString(36);
|
|
1026
|
+
const entropy = randomBytes(6).toString("hex");
|
|
1027
|
+
return `${timestamp}-${entropy}`;
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
// src/utils/index.ts
|
|
1031
|
+
var log2 = createChildLogger({ module: "utils" });
|
|
1032
|
+
function contentToText(content) {
|
|
1033
|
+
if (typeof content === "string") {
|
|
1034
|
+
return content;
|
|
1035
|
+
}
|
|
1036
|
+
const parts = [];
|
|
1037
|
+
for (const block of content) {
|
|
1038
|
+
if (block.type === "text" && typeof block.text === "string") {
|
|
1039
|
+
parts.push(block.text);
|
|
1040
|
+
} else if (block.type === "image" && isRecord2(block.source)) {
|
|
1041
|
+
const mediaType = block.source.type === "base64" && typeof block.source.media_type === "string" ? block.source.media_type : "image";
|
|
1042
|
+
parts.push(`[Image: ${mediaType}]`);
|
|
1043
|
+
} else if (block.type === "tool_reference" && typeof block.tool_name === "string") {
|
|
1044
|
+
parts.push(`[Tool reference: ${block.tool_name}]`);
|
|
1045
|
+
} else if (block.type === "search_result") {
|
|
1046
|
+
const title = typeof block.title === "string" ? block.title : "search result";
|
|
1047
|
+
const source = typeof block.source === "string" ? ` (${block.source})` : "";
|
|
1048
|
+
const nested = Array.isArray(block.content) ? contentToText(block.content.filter(isRecord2)) : "";
|
|
1049
|
+
parts.push(`${title}${source}${nested ? `
|
|
1050
|
+
${nested}` : ""}`);
|
|
1051
|
+
} else if (block.type === "document") {
|
|
1052
|
+
const title = typeof block.title === "string" ? block.title : "document";
|
|
1053
|
+
parts.push(`[Document: ${title}]`);
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
return parts.join("\n");
|
|
1057
|
+
}
|
|
1058
|
+
function isRecord2(value) {
|
|
1059
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1060
|
+
}
|
|
1061
|
+
function asRecord(value) {
|
|
1062
|
+
if (isRecord2(value)) {
|
|
1063
|
+
return value;
|
|
1064
|
+
}
|
|
1065
|
+
if (Array.isArray(value)) {
|
|
1066
|
+
return Object.fromEntries(value.entries());
|
|
1067
|
+
}
|
|
1068
|
+
return {};
|
|
1069
|
+
}
|
|
1070
|
+
function asString(value) {
|
|
1071
|
+
if (typeof value === "string") {
|
|
1072
|
+
return value;
|
|
1073
|
+
}
|
|
1074
|
+
return String(value);
|
|
1075
|
+
}
|
|
1076
|
+
function asErrorString(value) {
|
|
1077
|
+
if (value instanceof Error) {
|
|
1078
|
+
return value.message;
|
|
1079
|
+
}
|
|
1080
|
+
return asString(value);
|
|
1081
|
+
}
|
|
1082
|
+
function isObject(value) {
|
|
1083
|
+
return typeof value === "object" && value !== null;
|
|
1084
|
+
}
|
|
1085
|
+
function toTry(fn, ctx) {
|
|
1086
|
+
if (typeof fn !== "function") {
|
|
1087
|
+
return fn;
|
|
1088
|
+
}
|
|
1089
|
+
return function(...args) {
|
|
1090
|
+
let ret;
|
|
1091
|
+
try {
|
|
1092
|
+
ret = ctx ? fn.call(ctx, ...args) : fn.call(this, ...args);
|
|
1093
|
+
} catch (err) {
|
|
1094
|
+
log2.error({ err }, "utils operation failed");
|
|
1095
|
+
return void 0;
|
|
1096
|
+
}
|
|
1097
|
+
return ret;
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
var safeJSONParse = toTry(JSON.parse, JSON);
|
|
1101
|
+
function asError(err) {
|
|
1102
|
+
if (err instanceof Error) {
|
|
1103
|
+
return err;
|
|
1104
|
+
}
|
|
1105
|
+
return new Error(String(err));
|
|
1106
|
+
}
|
|
1107
|
+
function intArg(args, key, fallback) {
|
|
1108
|
+
const v = args[key];
|
|
1109
|
+
if (typeof v === "number") {
|
|
1110
|
+
return Math.floor(v);
|
|
1111
|
+
}
|
|
1112
|
+
if (typeof v === "string") {
|
|
1113
|
+
const n = Number.parseInt(v, 10);
|
|
1114
|
+
return Number.isNaN(n) ? fallback : n;
|
|
1115
|
+
}
|
|
1116
|
+
return fallback;
|
|
1117
|
+
}
|
|
1118
|
+
function strList(raw) {
|
|
1119
|
+
if (Array.isArray(raw)) {
|
|
1120
|
+
return raw.filter((v) => typeof v === "string");
|
|
1121
|
+
}
|
|
1122
|
+
return [];
|
|
1123
|
+
}
|
|
1124
|
+
function strArg(args, key, fallback) {
|
|
1125
|
+
const v = args[key];
|
|
1126
|
+
if (typeof v === "string") {
|
|
1127
|
+
return v;
|
|
1128
|
+
}
|
|
1129
|
+
return fallback ?? "";
|
|
1130
|
+
}
|
|
1131
|
+
function boolArg(args, key, fallback) {
|
|
1132
|
+
const v = args[key];
|
|
1133
|
+
if (typeof v === "boolean") {
|
|
1134
|
+
return v;
|
|
1135
|
+
}
|
|
1136
|
+
return fallback ?? Boolean(v);
|
|
1137
|
+
}
|
|
1138
|
+
function formatToolArgs(args) {
|
|
1139
|
+
if (args.command) {
|
|
1140
|
+
return truncate(strArg(args, "command"), 80);
|
|
1141
|
+
}
|
|
1142
|
+
if (args.file_path) {
|
|
1143
|
+
return truncate(strArg(args, "file_path"), 80);
|
|
1144
|
+
}
|
|
1145
|
+
if (args.pattern) {
|
|
1146
|
+
return truncate(strArg(args, "pattern"), 80);
|
|
1147
|
+
}
|
|
1148
|
+
if (args.description) {
|
|
1149
|
+
return truncate(strArg(args, "description"), 80);
|
|
1150
|
+
}
|
|
1151
|
+
return "";
|
|
1152
|
+
}
|
|
1153
|
+
function truncate(value, max) {
|
|
1154
|
+
return value.length > max ? `${value.slice(0, max)}\u2026` : value;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1154
1157
|
// src/conversation/pairing.ts
|
|
1155
1158
|
var pairing_exports = {};
|
|
1156
1159
|
__export(pairing_exports, {
|
|
@@ -1285,28 +1288,8 @@ function parseToolArguments(raw) {
|
|
|
1285
1288
|
}
|
|
1286
1289
|
|
|
1287
1290
|
export {
|
|
1288
|
-
sanitizeNameSegment,
|
|
1289
|
-
initLogger,
|
|
1290
|
-
closeLogger,
|
|
1291
|
-
logger,
|
|
1292
|
-
createChildLogger,
|
|
1293
|
-
logger_exports,
|
|
1294
|
-
canonicalPath,
|
|
1295
|
-
isPathWithin,
|
|
1296
|
-
generateSlug,
|
|
1297
|
-
contentToText,
|
|
1298
|
-
isRecord,
|
|
1299
|
-
asRecord,
|
|
1300
|
-
asString,
|
|
1301
|
-
asErrorString,
|
|
1302
|
-
isObject,
|
|
1303
|
-
safeJSONParse,
|
|
1304
|
-
intArg,
|
|
1305
|
-
strList,
|
|
1306
|
-
strArg,
|
|
1307
|
-
boolArg,
|
|
1308
|
-
utils_exports,
|
|
1309
1291
|
THINKING_LEVELS,
|
|
1292
|
+
resolveDefaultProvider,
|
|
1310
1293
|
DEFAULT_THINKING_LEVEL,
|
|
1311
1294
|
DEFAULT_CONTEXT_WINDOW,
|
|
1312
1295
|
DEFAULT_MAX_OUTPUT_TOKENS,
|
|
@@ -1320,6 +1303,12 @@ export {
|
|
|
1320
1303
|
clampThinkingLevel,
|
|
1321
1304
|
getContextWindow,
|
|
1322
1305
|
getMaxOutputTokens,
|
|
1306
|
+
sanitizeNameSegment,
|
|
1307
|
+
initLogger,
|
|
1308
|
+
closeLogger,
|
|
1309
|
+
logger,
|
|
1310
|
+
createChildLogger,
|
|
1311
|
+
logger_exports,
|
|
1323
1312
|
persistThinkingLevel,
|
|
1324
1313
|
resolveAPIKey,
|
|
1325
1314
|
forkEnabled,
|
|
@@ -1327,6 +1316,21 @@ export {
|
|
|
1327
1316
|
withProjectMcpServers,
|
|
1328
1317
|
loadConfig,
|
|
1329
1318
|
config_exports,
|
|
1319
|
+
canonicalPath,
|
|
1320
|
+
isPathWithin,
|
|
1321
|
+
generateSlug,
|
|
1322
|
+
contentToText,
|
|
1323
|
+
isRecord2 as isRecord,
|
|
1324
|
+
asRecord,
|
|
1325
|
+
asString,
|
|
1326
|
+
asErrorString,
|
|
1327
|
+
isObject,
|
|
1328
|
+
safeJSONParse,
|
|
1329
|
+
intArg,
|
|
1330
|
+
strList,
|
|
1331
|
+
strArg,
|
|
1332
|
+
boolArg,
|
|
1333
|
+
utils_exports,
|
|
1330
1334
|
REJECTED_TOOL_RESULT,
|
|
1331
1335
|
ensureToolPairing,
|
|
1332
1336
|
pairing_exports,
|