@yukino.js/yukino 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +320 -0
- package/dist/acp-IVY5HZR4.js +14 -0
- package/dist/agent-QANDY7FO.js +4 -0
- package/dist/anthropic-6YLT4JZR.js +4 -0
- package/dist/bwrap-MLSZLWHD.js +4 -0
- package/dist/chunk-2LHY3FND.js +67 -0
- package/dist/chunk-3KKA6537.js +4 -0
- package/dist/chunk-3QL446GD.js +4 -0
- package/dist/chunk-4GE22WHI.js +4 -0
- package/dist/chunk-5VOCXSSX.js +5 -0
- package/dist/chunk-77W2UPS2.js +4 -0
- package/dist/chunk-7MKA3SHV.js +4 -0
- package/dist/chunk-AGSYLE4E.js +16 -0
- package/dist/chunk-CU3IISCC.js +4 -0
- package/dist/chunk-GYBJR2RB.js +65 -0
- package/dist/chunk-HLE7243Q.js +4 -0
- package/dist/chunk-HMZQYFYG.js +4 -0
- package/dist/chunk-JFKC4VCA.js +4 -0
- package/dist/chunk-K4BYVVW7.js +5 -0
- package/dist/chunk-KCMBAHWU.js +4 -0
- package/dist/chunk-L2BWSPCF.js +10 -0
- package/dist/chunk-MDPSQ6L7.js +44 -0
- package/dist/chunk-OFC2GD5K.js +4 -0
- package/dist/chunk-RAS3ORX3.js +164 -0
- package/dist/chunk-RCXKUD3Y.js +4 -0
- package/dist/chunk-SAJCBGHL.js +4 -0
- package/dist/chunk-SOO5OXX2.js +237 -0
- package/dist/chunk-T4O4GQVL.js +607 -0
- package/dist/chunk-UPNNYP7M.js +60 -0
- package/dist/chunk-VCIRD267.js +4 -0
- package/dist/chunk-VU3JWAJR.js +4 -0
- package/dist/chunk-VWUGGYUP.js +6 -0
- package/dist/chunk-XO7ITAWR.js +4 -0
- package/dist/devtools-YWVUN4HX.js +7 -0
- package/dist/esm-57CJEGGK.js +4 -0
- package/dist/esm-6L5BJ5GT.js +4 -0
- package/dist/esm-DIYJ5HX6.js +4 -0
- package/dist/esm-HW2JMFYC.js +4 -0
- package/dist/esm-RPR2GBJ2.js +4 -0
- package/dist/esm-YKAO4ES6.js +4 -0
- package/dist/esm-ZTIYTMTS.js +229 -0
- package/dist/getMachineId-bsd-E27XJQLX.js +4 -0
- package/dist/getMachineId-darwin-35UPAIXP.js +5 -0
- package/dist/getMachineId-linux-MKXIYT6A.js +4 -0
- package/dist/getMachineId-unsupported-ZXVGGFX2.js +4 -0
- package/dist/getMachineId-win-RNVIYJG5.js +4 -0
- package/dist/lib/agent-6FZX4P2Y.js +16 -0
- package/dist/lib/anthropic-IP23YZ3P.js +21 -0
- package/dist/lib/bwrap-2OL7VPSO.js +7 -0
- package/dist/lib/chunk-2VF3XTGH.js +3382 -0
- package/dist/lib/chunk-5DVQ64YL.js +619 -0
- package/dist/lib/chunk-5TGXH7BX.js +624 -0
- package/dist/lib/chunk-6OMQD7MK.js +591 -0
- package/dist/lib/chunk-AZRC67RW.js +512 -0
- package/dist/lib/chunk-F2YJG72O.js +150 -0
- package/dist/lib/chunk-FFM2LB4C.js +132 -0
- package/dist/lib/chunk-FLKB4BK7.js +50 -0
- package/dist/lib/chunk-I34MAQRE.js +255 -0
- package/dist/lib/chunk-KA6POJKI.js +889 -0
- package/dist/lib/chunk-MLKGABMK.js +9 -0
- package/dist/lib/chunk-O7ELJUEK.js +262 -0
- package/dist/lib/chunk-QYBQT2DM.js +655 -0
- package/dist/lib/chunk-YIWNQ7OA.js +47 -0
- package/dist/lib/index.d.ts +8581 -0
- package/dist/lib/index.js +15905 -0
- package/dist/lib/openai-EMJ6U4FW.js +15 -0
- package/dist/lib/permissions-KZ5ACZAX.js +19 -0
- package/dist/lib/providers-2CGZPBFI.js +9 -0
- package/dist/lib/sandbox-runtime-CCQ3X3SM.js +9 -0
- package/dist/lib/seatbelt-WO7YWKLR.js +7 -0
- package/dist/lib/tool-filter-CKHZUUBQ.js +21 -0
- package/dist/main.js +332 -0
- package/dist/node-634LOHDX.js +15 -0
- package/dist/openai-YXYO5OW6.js +34 -0
- package/dist/permissions-VCDMNX3L.js +4 -0
- package/dist/providers-HNMBGGW6.js +4 -0
- package/dist/sandbox-runtime-ELKAYRIL.js +4 -0
- package/dist/seatbelt-JOCANLYS.js +4 -0
- package/dist/server-ZHQILOBP.js +4 -0
- package/dist/src-43CPCEK2.js +12 -0
- package/dist/src-JBRNH4FA.js +4 -0
- package/dist/src-R4BSSIJJ.js +4 -0
- package/dist/src-X6JWWHHT.js +4 -0
- package/dist/tool-filter-BQZDV3TF.js +4 -0
- package/dist/turndown.es-NQ3KDXM7.js +83 -0
- package/package.json +146 -0
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-MLKGABMK.js";
|
|
4
|
+
|
|
5
|
+
// src/logger/index.ts
|
|
6
|
+
var logger_exports = {};
|
|
7
|
+
__export(logger_exports, {
|
|
8
|
+
closeLogger: () => closeLogger,
|
|
9
|
+
createChildLogger: () => createChildLogger,
|
|
10
|
+
initLogger: () => initLogger,
|
|
11
|
+
logger: () => logger,
|
|
12
|
+
sanitizeNameSegment: () => sanitizeNameSegment
|
|
13
|
+
});
|
|
14
|
+
import { openSync, closeSync, mkdirSync, writeFileSync } from "fs";
|
|
15
|
+
import { readdir, stat, unlink } from "fs/promises";
|
|
16
|
+
import { homedir } from "os";
|
|
17
|
+
import { join, dirname, basename } from "path";
|
|
18
|
+
import pino from "pino";
|
|
19
|
+
var currentLogger = null;
|
|
20
|
+
var currentDest = null;
|
|
21
|
+
var currentFd = null;
|
|
22
|
+
function resolveLogPath(opts) {
|
|
23
|
+
const dir = opts.logDir ?? join(opts.workDir ?? process.cwd(), ".yukino", "logs");
|
|
24
|
+
return join(dir, `${opts.sessionId}.jsonl`);
|
|
25
|
+
}
|
|
26
|
+
function ensureYukinoGitignore(logPath) {
|
|
27
|
+
let dir = dirname(logPath);
|
|
28
|
+
while (basename(dir) !== ".yukino") {
|
|
29
|
+
const parent = dirname(dir);
|
|
30
|
+
if (parent === dir) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
dir = parent;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
writeFileSync(join(dir, ".gitignore"), "*\n", { flag: "wx" });
|
|
37
|
+
} catch {
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function sanitizeNameSegment(name) {
|
|
41
|
+
const cleaned = name.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
42
|
+
return cleaned || "unnamed";
|
|
43
|
+
}
|
|
44
|
+
function flushDestination(dest) {
|
|
45
|
+
if (typeof dest !== "object" || dest === null) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const fn = Reflect.get(dest, "flushSync");
|
|
49
|
+
if (typeof fn === "function") {
|
|
50
|
+
fn.call(dest);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
var LOG_LEVEL = "warn";
|
|
54
|
+
function initLogger(opts) {
|
|
55
|
+
if (currentLogger) {
|
|
56
|
+
closeLogger();
|
|
57
|
+
}
|
|
58
|
+
const logPath = resolveLogPath(opts);
|
|
59
|
+
mkdirSync(dirname(logPath), { recursive: true });
|
|
60
|
+
ensureYukinoGitignore(logPath);
|
|
61
|
+
const fd = openSync(logPath, "a");
|
|
62
|
+
currentFd = fd;
|
|
63
|
+
currentDest = pino.destination(fd);
|
|
64
|
+
const pinoOpts = {
|
|
65
|
+
level: LOG_LEVEL,
|
|
66
|
+
base: { sessionId: opts.sessionId, mode: opts.mode },
|
|
67
|
+
serializers: { err: errSerializer }
|
|
68
|
+
};
|
|
69
|
+
if (opts.stdout) {
|
|
70
|
+
currentLogger = pino(
|
|
71
|
+
pinoOpts,
|
|
72
|
+
pino.multistream([
|
|
73
|
+
{ stream: currentDest, level: LOG_LEVEL },
|
|
74
|
+
{ stream: process.stdout, level: LOG_LEVEL }
|
|
75
|
+
])
|
|
76
|
+
);
|
|
77
|
+
} else {
|
|
78
|
+
currentLogger = pino(pinoOpts, currentDest);
|
|
79
|
+
}
|
|
80
|
+
if (!opts.skipCleanup) {
|
|
81
|
+
const workDir = opts.workDir ?? process.cwd();
|
|
82
|
+
void cleanExpiredLogs(workDir).catch(() => {
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return currentLogger;
|
|
86
|
+
}
|
|
87
|
+
function getLogger() {
|
|
88
|
+
return currentLogger;
|
|
89
|
+
}
|
|
90
|
+
function closeLogger() {
|
|
91
|
+
if (currentLogger) {
|
|
92
|
+
try {
|
|
93
|
+
currentLogger.flush();
|
|
94
|
+
} catch {
|
|
95
|
+
}
|
|
96
|
+
currentLogger = null;
|
|
97
|
+
}
|
|
98
|
+
if (currentDest) {
|
|
99
|
+
flushDestination(currentDest);
|
|
100
|
+
currentDest = null;
|
|
101
|
+
}
|
|
102
|
+
if (currentFd !== null) {
|
|
103
|
+
try {
|
|
104
|
+
closeSync(currentFd);
|
|
105
|
+
} catch {
|
|
106
|
+
}
|
|
107
|
+
currentFd = null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
var silentFallback = pino({ level: "silent" });
|
|
111
|
+
var logger = new Proxy(silentFallback, {
|
|
112
|
+
get(_target, prop, receiver) {
|
|
113
|
+
const current = getLogger();
|
|
114
|
+
const target = current ?? _target;
|
|
115
|
+
const value = Reflect.get(target, prop, receiver);
|
|
116
|
+
if (typeof value === "function") {
|
|
117
|
+
return value.bind(target);
|
|
118
|
+
}
|
|
119
|
+
return value;
|
|
120
|
+
},
|
|
121
|
+
set(_target, prop, value) {
|
|
122
|
+
return Reflect.set(getLogger() ?? _target, prop, value);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
function createChildLogger(bindings) {
|
|
126
|
+
let cachedChild = null;
|
|
127
|
+
let cachedLogger = null;
|
|
128
|
+
const resolveChild = () => {
|
|
129
|
+
const current = getLogger();
|
|
130
|
+
if (!current) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
if (cachedChild === null || cachedLogger !== current) {
|
|
134
|
+
cachedChild = current.child(bindings);
|
|
135
|
+
cachedLogger = current;
|
|
136
|
+
}
|
|
137
|
+
return cachedChild;
|
|
138
|
+
};
|
|
139
|
+
return new Proxy(silentFallback, {
|
|
140
|
+
get(_target, prop, receiver) {
|
|
141
|
+
const target = resolveChild() ?? _target;
|
|
142
|
+
const value = Reflect.get(target, prop, receiver);
|
|
143
|
+
if (typeof value === "function") {
|
|
144
|
+
return value.bind(target);
|
|
145
|
+
}
|
|
146
|
+
return value;
|
|
147
|
+
},
|
|
148
|
+
set(_target, prop, value) {
|
|
149
|
+
return Reflect.set(resolveChild() ?? _target, prop, value);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async function cleanDir(dir) {
|
|
154
|
+
let files;
|
|
155
|
+
try {
|
|
156
|
+
files = (await readdir(dir)).filter((f) => f.endsWith(".jsonl"));
|
|
157
|
+
} catch {
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
const now = Date.now();
|
|
161
|
+
let removed = 0;
|
|
162
|
+
for (const file of files) {
|
|
163
|
+
const filePath = join(dir, file);
|
|
164
|
+
try {
|
|
165
|
+
const s = await stat(filePath);
|
|
166
|
+
if (now - s.mtimeMs > 30 * 24 * 60 * 60 * 1e3) {
|
|
167
|
+
await unlink(filePath);
|
|
168
|
+
removed++;
|
|
169
|
+
}
|
|
170
|
+
} catch {
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return removed;
|
|
174
|
+
}
|
|
175
|
+
async function cleanExpiredLogs(workDir) {
|
|
176
|
+
let removed = 0;
|
|
177
|
+
removed += await cleanDir(join(workDir, ".yukino", "logs"));
|
|
178
|
+
const teamsDir = join(homedir(), ".yukino", "teams");
|
|
179
|
+
let teams;
|
|
180
|
+
try {
|
|
181
|
+
teams = await readdir(teamsDir);
|
|
182
|
+
} catch {
|
|
183
|
+
return removed;
|
|
184
|
+
}
|
|
185
|
+
for (const team of teams) {
|
|
186
|
+
removed += await cleanDir(join(teamsDir, team, "logs"));
|
|
187
|
+
}
|
|
188
|
+
return removed;
|
|
189
|
+
}
|
|
190
|
+
var CAUSE_MAX_DEPTH = 5;
|
|
191
|
+
var RESERVED_KEYS = /* @__PURE__ */ new Set(["name", "message", "stack", "cause"]);
|
|
192
|
+
function serializeErrorInstance(err, depth) {
|
|
193
|
+
const out = {
|
|
194
|
+
type: err.name,
|
|
195
|
+
message: err.message,
|
|
196
|
+
stack: err.stack
|
|
197
|
+
};
|
|
198
|
+
const causeDescriptor = Object.getOwnPropertyDescriptor(err, "cause");
|
|
199
|
+
if (causeDescriptor && depth < CAUSE_MAX_DEPTH) {
|
|
200
|
+
const cause = causeDescriptor.value;
|
|
201
|
+
if (cause instanceof Error) {
|
|
202
|
+
out.cause = serializeErrorInstance(cause, depth + 1);
|
|
203
|
+
} else if (cause !== void 0) {
|
|
204
|
+
out.cause = { message: safeStringify(cause) };
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
for (const key of Object.keys(err)) {
|
|
208
|
+
if (RESERVED_KEYS.has(key)) {
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
const descriptor = Object.getOwnPropertyDescriptor(err, key);
|
|
212
|
+
if (descriptor) {
|
|
213
|
+
const fieldValue = descriptor.value;
|
|
214
|
+
out[key] = fieldValue;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
function safeStringify(value) {
|
|
220
|
+
if (typeof value === "string") {
|
|
221
|
+
return value;
|
|
222
|
+
}
|
|
223
|
+
try {
|
|
224
|
+
const json = JSON.stringify(value);
|
|
225
|
+
if (json !== void 0) {
|
|
226
|
+
return json;
|
|
227
|
+
}
|
|
228
|
+
} catch {
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
return String(value);
|
|
232
|
+
} catch {
|
|
233
|
+
return Object.prototype.toString.call(value);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function errSerializer(err) {
|
|
237
|
+
if (err instanceof Error) {
|
|
238
|
+
return serializeErrorInstance(err, 0);
|
|
239
|
+
}
|
|
240
|
+
return { message: safeStringify(err), value: err };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// src/utils/paths.ts
|
|
244
|
+
var paths_exports = {};
|
|
245
|
+
__export(paths_exports, {
|
|
246
|
+
canonicalPath: () => canonicalPath,
|
|
247
|
+
compactPath: () => compactPath,
|
|
248
|
+
isPathWithin: () => isPathWithin
|
|
249
|
+
});
|
|
250
|
+
import { realpathSync } from "fs";
|
|
251
|
+
import { homedir as homedir2 } from "os";
|
|
252
|
+
import { basename as basename2, dirname as dirname2, isAbsolute, join as join2, relative, resolve, sep } from "path";
|
|
253
|
+
function canonicalPath(path) {
|
|
254
|
+
let current = resolve(path);
|
|
255
|
+
const missing = [];
|
|
256
|
+
for (; ; ) {
|
|
257
|
+
try {
|
|
258
|
+
return join2(realpathSync(current), ...missing);
|
|
259
|
+
} catch (error) {
|
|
260
|
+
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT" && error.code !== "ENOTDIR") {
|
|
261
|
+
throw error;
|
|
262
|
+
}
|
|
263
|
+
const parent = dirname2(current);
|
|
264
|
+
if (parent === current) {
|
|
265
|
+
return resolve(path);
|
|
266
|
+
}
|
|
267
|
+
missing.unshift(basename2(current));
|
|
268
|
+
current = parent;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function isPathWithin(root, path) {
|
|
273
|
+
const child = relative(root, path);
|
|
274
|
+
return child === "" || child !== ".." && !child.startsWith(`..${sep}`) && !isAbsolute(child);
|
|
275
|
+
}
|
|
276
|
+
function compactPath(path) {
|
|
277
|
+
const home = homedir2();
|
|
278
|
+
return path === home ? "~" : path.startsWith(`${home}/`) ? `~/${path.slice(home.length + 1)}` : path;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/utils/index.ts
|
|
282
|
+
var utils_exports = {};
|
|
283
|
+
__export(utils_exports, {
|
|
284
|
+
Paths: () => paths_exports,
|
|
285
|
+
Verbs: () => verbs_exports,
|
|
286
|
+
asError: () => asError,
|
|
287
|
+
asErrorString: () => asErrorString,
|
|
288
|
+
asRecord: () => asRecord,
|
|
289
|
+
asString: () => asString,
|
|
290
|
+
boolArg: () => boolArg,
|
|
291
|
+
contentToText: () => contentToText,
|
|
292
|
+
formatToolArgs: () => formatToolArgs,
|
|
293
|
+
intArg: () => intArg,
|
|
294
|
+
isObject: () => isObject,
|
|
295
|
+
isRecord: () => isRecord,
|
|
296
|
+
safeJSONParse: () => safeJSONParse,
|
|
297
|
+
strArg: () => strArg,
|
|
298
|
+
strList: () => strList,
|
|
299
|
+
toTry: () => toTry
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
// src/utils/verbs.ts
|
|
303
|
+
var verbs_exports = {};
|
|
304
|
+
__export(verbs_exports, {
|
|
305
|
+
randomCompletionVerb: () => randomCompletionVerb,
|
|
306
|
+
randomVerb: () => randomVerb
|
|
307
|
+
});
|
|
308
|
+
var spinnerVerbs = [
|
|
309
|
+
"Accomplishing",
|
|
310
|
+
"Architecting",
|
|
311
|
+
"Baking",
|
|
312
|
+
"Barking",
|
|
313
|
+
"Woofing",
|
|
314
|
+
"Howling",
|
|
315
|
+
"Be-bopping'",
|
|
316
|
+
"Befuddling",
|
|
317
|
+
"Boogieing",
|
|
318
|
+
"Boondoggling",
|
|
319
|
+
"Bootstrapping",
|
|
320
|
+
"Brewing",
|
|
321
|
+
"Calculating",
|
|
322
|
+
"Canoodling",
|
|
323
|
+
"Caramelizing",
|
|
324
|
+
"Cascading",
|
|
325
|
+
"Cerebrating",
|
|
326
|
+
"Choreographing",
|
|
327
|
+
"Churning",
|
|
328
|
+
"Coalescing",
|
|
329
|
+
"Cogitating",
|
|
330
|
+
"Combobulating",
|
|
331
|
+
"Composing",
|
|
332
|
+
"Computing",
|
|
333
|
+
"Concocting",
|
|
334
|
+
"Considering",
|
|
335
|
+
"Contemplating",
|
|
336
|
+
"Cooking",
|
|
337
|
+
"Crafting",
|
|
338
|
+
"Creating",
|
|
339
|
+
"Crunching",
|
|
340
|
+
"Crystallizing",
|
|
341
|
+
"Cultivating",
|
|
342
|
+
"Deciphering",
|
|
343
|
+
"Deliberating",
|
|
344
|
+
"Dilly-dallying",
|
|
345
|
+
"Discombobulating",
|
|
346
|
+
"Doodling",
|
|
347
|
+
"Elucidating",
|
|
348
|
+
"Enchanting",
|
|
349
|
+
"Envisioning",
|
|
350
|
+
"Fermenting",
|
|
351
|
+
"Finagling",
|
|
352
|
+
"Flamb\xE9ing",
|
|
353
|
+
"Flummoxing",
|
|
354
|
+
"Forging",
|
|
355
|
+
"Frolicking",
|
|
356
|
+
"Gallivanting",
|
|
357
|
+
"Garnishing",
|
|
358
|
+
"Generating",
|
|
359
|
+
"Germinating",
|
|
360
|
+
"Grooving",
|
|
361
|
+
"Harmonizing",
|
|
362
|
+
"Hatching",
|
|
363
|
+
"Honking",
|
|
364
|
+
"Ideating",
|
|
365
|
+
"Imagining",
|
|
366
|
+
"Improvising",
|
|
367
|
+
"Incubating",
|
|
368
|
+
"Inferring",
|
|
369
|
+
"Infusing",
|
|
370
|
+
"Kneading",
|
|
371
|
+
"Lollygagging",
|
|
372
|
+
"Manifesting",
|
|
373
|
+
"Marinating",
|
|
374
|
+
"Meandering",
|
|
375
|
+
"Metamorphosing",
|
|
376
|
+
"Mewing",
|
|
377
|
+
"Moonwalking",
|
|
378
|
+
"Moseying",
|
|
379
|
+
"Mulling",
|
|
380
|
+
"Musing",
|
|
381
|
+
"Noodling",
|
|
382
|
+
"Orbiting",
|
|
383
|
+
"Orchestrating",
|
|
384
|
+
"Percolating",
|
|
385
|
+
"Philosophizing",
|
|
386
|
+
"Pondering",
|
|
387
|
+
"Pontificating",
|
|
388
|
+
"Pouncing",
|
|
389
|
+
"Purring",
|
|
390
|
+
"Puzzling",
|
|
391
|
+
"Razzle-dazzling",
|
|
392
|
+
"Ruminating",
|
|
393
|
+
"Scampering",
|
|
394
|
+
"Simmering",
|
|
395
|
+
"Sketching",
|
|
396
|
+
"Spelunking",
|
|
397
|
+
"Spinning",
|
|
398
|
+
"Sprouting",
|
|
399
|
+
"Synthesizing",
|
|
400
|
+
"Thinking",
|
|
401
|
+
"Tinkering",
|
|
402
|
+
"Transfiguring",
|
|
403
|
+
"Transmuting",
|
|
404
|
+
"Undulating",
|
|
405
|
+
"Unfurling",
|
|
406
|
+
"Unravelling",
|
|
407
|
+
"Vibing",
|
|
408
|
+
"Wandering",
|
|
409
|
+
"Whisking",
|
|
410
|
+
"Working",
|
|
411
|
+
"Wrangling",
|
|
412
|
+
"Zigzagging"
|
|
413
|
+
];
|
|
414
|
+
function randomVerb() {
|
|
415
|
+
return spinnerVerbs[Math.floor(Math.random() * spinnerVerbs.length)];
|
|
416
|
+
}
|
|
417
|
+
var completionVerbs = [
|
|
418
|
+
"Accomplished",
|
|
419
|
+
"Baked",
|
|
420
|
+
"Brewed",
|
|
421
|
+
"Cooked",
|
|
422
|
+
"Crafted",
|
|
423
|
+
"Crunched",
|
|
424
|
+
"Forged",
|
|
425
|
+
"Hatched",
|
|
426
|
+
"Pondered",
|
|
427
|
+
"Synthesized",
|
|
428
|
+
"Tinkered",
|
|
429
|
+
"Worked",
|
|
430
|
+
"Wrangled",
|
|
431
|
+
"Computed",
|
|
432
|
+
"Created",
|
|
433
|
+
"Composed",
|
|
434
|
+
"Conjured",
|
|
435
|
+
"Concocted",
|
|
436
|
+
"Cultivated",
|
|
437
|
+
"Deciphered"
|
|
438
|
+
];
|
|
439
|
+
function randomCompletionVerb() {
|
|
440
|
+
return completionVerbs[Math.floor(Math.random() * completionVerbs.length)];
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// src/utils/index.ts
|
|
444
|
+
var log = createChildLogger({ module: "utils" });
|
|
445
|
+
function contentToText(content) {
|
|
446
|
+
if (typeof content === "string") {
|
|
447
|
+
return content;
|
|
448
|
+
}
|
|
449
|
+
const parts = [];
|
|
450
|
+
for (const block of content) {
|
|
451
|
+
if (block.type === "text" && typeof block.text === "string") {
|
|
452
|
+
parts.push(block.text);
|
|
453
|
+
} else if (block.type === "image" && isRecord(block.source)) {
|
|
454
|
+
const mediaType = block.source.type === "base64" && typeof block.source.media_type === "string" ? block.source.media_type : "image";
|
|
455
|
+
parts.push(`[Image: ${mediaType}]`);
|
|
456
|
+
} else if (block.type === "tool_reference" && typeof block.tool_name === "string") {
|
|
457
|
+
parts.push(`[Tool reference: ${block.tool_name}]`);
|
|
458
|
+
} else if (block.type === "search_result") {
|
|
459
|
+
const title = typeof block.title === "string" ? block.title : "search result";
|
|
460
|
+
const source = typeof block.source === "string" ? ` (${block.source})` : "";
|
|
461
|
+
const nested = Array.isArray(block.content) ? contentToText(block.content.filter(isRecord)) : "";
|
|
462
|
+
parts.push(`${title}${source}${nested ? `
|
|
463
|
+
${nested}` : ""}`);
|
|
464
|
+
} else if (block.type === "document") {
|
|
465
|
+
const title = typeof block.title === "string" ? block.title : "document";
|
|
466
|
+
parts.push(`[Document: ${title}]`);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return parts.join("\n");
|
|
470
|
+
}
|
|
471
|
+
function isRecord(value) {
|
|
472
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
473
|
+
}
|
|
474
|
+
function asRecord(value) {
|
|
475
|
+
if (isRecord(value)) {
|
|
476
|
+
return value;
|
|
477
|
+
}
|
|
478
|
+
if (Array.isArray(value)) {
|
|
479
|
+
return Object.fromEntries(value.entries());
|
|
480
|
+
}
|
|
481
|
+
return {};
|
|
482
|
+
}
|
|
483
|
+
function asString(value) {
|
|
484
|
+
if (typeof value === "string") {
|
|
485
|
+
return value;
|
|
486
|
+
}
|
|
487
|
+
return String(value);
|
|
488
|
+
}
|
|
489
|
+
function asErrorString(value) {
|
|
490
|
+
if (value instanceof Error) {
|
|
491
|
+
return value.message;
|
|
492
|
+
}
|
|
493
|
+
return asString(value);
|
|
494
|
+
}
|
|
495
|
+
function isObject(value) {
|
|
496
|
+
return typeof value === "object" && value !== null;
|
|
497
|
+
}
|
|
498
|
+
function toTry(fn, ctx) {
|
|
499
|
+
if (typeof fn !== "function") {
|
|
500
|
+
return fn;
|
|
501
|
+
}
|
|
502
|
+
return function(...args) {
|
|
503
|
+
let ret;
|
|
504
|
+
try {
|
|
505
|
+
ret = ctx ? fn.call(ctx, ...args) : fn.call(this, ...args);
|
|
506
|
+
} catch (err) {
|
|
507
|
+
log.error({ err }, "utils operation failed");
|
|
508
|
+
return void 0;
|
|
509
|
+
}
|
|
510
|
+
return ret;
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
var safeJSONParse = toTry(JSON.parse, JSON);
|
|
514
|
+
function asError(err) {
|
|
515
|
+
if (err instanceof Error) {
|
|
516
|
+
return err;
|
|
517
|
+
}
|
|
518
|
+
return new Error(String(err));
|
|
519
|
+
}
|
|
520
|
+
function intArg(args, key, fallback) {
|
|
521
|
+
const v = args[key];
|
|
522
|
+
if (typeof v === "number") {
|
|
523
|
+
return Math.floor(v);
|
|
524
|
+
}
|
|
525
|
+
if (typeof v === "string") {
|
|
526
|
+
const n = Number.parseInt(v, 10);
|
|
527
|
+
return Number.isNaN(n) ? fallback : n;
|
|
528
|
+
}
|
|
529
|
+
return fallback;
|
|
530
|
+
}
|
|
531
|
+
function strList(raw) {
|
|
532
|
+
if (Array.isArray(raw)) {
|
|
533
|
+
return raw.filter((v) => typeof v === "string");
|
|
534
|
+
}
|
|
535
|
+
return [];
|
|
536
|
+
}
|
|
537
|
+
function strArg(args, key, fallback) {
|
|
538
|
+
const v = args[key];
|
|
539
|
+
if (typeof v === "string") {
|
|
540
|
+
return v;
|
|
541
|
+
}
|
|
542
|
+
return fallback ?? "";
|
|
543
|
+
}
|
|
544
|
+
function boolArg(args, key, fallback) {
|
|
545
|
+
const v = args[key];
|
|
546
|
+
if (typeof v === "boolean") {
|
|
547
|
+
return v;
|
|
548
|
+
}
|
|
549
|
+
return fallback ?? Boolean(v);
|
|
550
|
+
}
|
|
551
|
+
function formatToolArgs(args) {
|
|
552
|
+
if (args.command) {
|
|
553
|
+
return truncate(strArg(args, "command"), 80);
|
|
554
|
+
}
|
|
555
|
+
if (args.file_path) {
|
|
556
|
+
return truncate(strArg(args, "file_path"), 80);
|
|
557
|
+
}
|
|
558
|
+
if (args.pattern) {
|
|
559
|
+
return truncate(strArg(args, "pattern"), 80);
|
|
560
|
+
}
|
|
561
|
+
if (args.description) {
|
|
562
|
+
return truncate(strArg(args, "description"), 80);
|
|
563
|
+
}
|
|
564
|
+
return "";
|
|
565
|
+
}
|
|
566
|
+
function truncate(value, max) {
|
|
567
|
+
return value.length > max ? `${value.slice(0, max)}\u2026` : value;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
export {
|
|
571
|
+
sanitizeNameSegment,
|
|
572
|
+
initLogger,
|
|
573
|
+
closeLogger,
|
|
574
|
+
logger,
|
|
575
|
+
createChildLogger,
|
|
576
|
+
logger_exports,
|
|
577
|
+
canonicalPath,
|
|
578
|
+
isPathWithin,
|
|
579
|
+
randomVerb,
|
|
580
|
+
contentToText,
|
|
581
|
+
isRecord,
|
|
582
|
+
asRecord,
|
|
583
|
+
asString,
|
|
584
|
+
asErrorString,
|
|
585
|
+
isObject,
|
|
586
|
+
intArg,
|
|
587
|
+
strList,
|
|
588
|
+
strArg,
|
|
589
|
+
boolArg,
|
|
590
|
+
utils_exports
|
|
591
|
+
};
|