stitchkit 0.123.6 → 0.123.7
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/CHANGELOG.md +51 -0
- package/dist/entrypoints/application/diagnostic-journal.js +1 -1
- package/dist/entrypoints/application/directory-inbox.js +3 -3
- package/dist/entrypoints/cli/publish.js +2 -2
- package/dist/entrypoints/cli.js +2 -1
- package/dist/entrypoints/files.js +2 -2
- package/dist/entrypoints/node.js +2 -2
- package/dist/entrypoints/server.js +5 -5
- package/dist/entrypoints/telegram.js +1 -1
- package/dist/entrypoints/tools/contract.js +4 -2
- package/dist/entrypoints/tools/toolkit.js +2 -1
- package/dist/entrypoints/tools.js +33 -27
- package/dist/{index-xjb131sc.js → index-1a741dpf.js} +188 -51
- package/dist/{index-yfpt7sxr.js → index-6qrspvxp.js} +5 -3
- package/dist/index-81t0bf0f.js +18 -0
- package/dist/{index-d9cg0gen.js → index-8yky60kq.js} +1 -1
- package/dist/{index-bph35vpy.js → index-9cxxfkhb.js} +21 -1
- package/dist/index-bknzva6n.js +39 -0
- package/dist/{index-73dappvg.js → index-ezwvsqx9.js} +1 -1
- package/dist/{index-chz7c830.js → index-mqttte96.js} +39 -6
- package/dist/{index-eabx6qjh.js → index-tnnmekgb.js} +1 -6
- package/dist/index-zs8cze4j.js +6 -0
- package/dist/internal/exclusive-lock.d.ts.map +1 -1
- package/dist/internal/media-extension.d.ts +3 -0
- package/dist/internal/media-extension.d.ts.map +1 -0
- package/dist/tools/cli/args.d.ts +1 -1
- package/dist/tools/cli/args.d.ts.map +1 -1
- package/dist/tools/cli/command.d.ts +7 -1
- package/dist/tools/cli/command.d.ts.map +1 -1
- package/dist/tools/cli/config.d.ts +5 -2
- package/dist/tools/cli/config.d.ts.map +1 -1
- package/dist/tools/cli/download.d.ts +25 -4
- package/dist/tools/cli/download.d.ts.map +1 -1
- package/dist/tools/cli/inline-files.d.ts +70 -0
- package/dist/tools/cli/inline-files.d.ts.map +1 -0
- package/dist/tools/cli/session.d.ts.map +1 -1
- package/dist/tools/transfer/download-core.d.ts +2 -0
- package/dist/tools/transfer/download-core.d.ts.map +1 -1
- package/dist/tools/transfer/view-file-contract.d.ts +34 -4
- package/dist/tools/transfer/view-file-contract.d.ts.map +1 -1
- package/dist/tools/transfer/view-file.d.ts.map +1 -1
- package/llms/cli.txt +63 -3
- package/llms/tools.2.txt +5 -0
- package/llms-full.txt +68 -3
- package/llms.txt +2 -2
- package/package.json +1 -1
- package/dist/index-sba3e6m4.js +0 -52
|
@@ -30,6 +30,10 @@ import {
|
|
|
30
30
|
import {
|
|
31
31
|
isRepeatableRead
|
|
32
32
|
} from "./index-332d0m9g.js";
|
|
33
|
+
import {
|
|
34
|
+
McpImageContentSchema,
|
|
35
|
+
McpAudioContentSchema
|
|
36
|
+
} from "./index-bknzva6n.js";
|
|
33
37
|
import {
|
|
34
38
|
readContractStreamItems,
|
|
35
39
|
contractStreamLifetimeExceeded
|
|
@@ -43,8 +47,9 @@ import {
|
|
|
43
47
|
containedEntryMetadata
|
|
44
48
|
} from "./index-ww3gss55.js";
|
|
45
49
|
import {
|
|
46
|
-
pollUntil
|
|
47
|
-
|
|
50
|
+
pollUntil,
|
|
51
|
+
mediaExtension
|
|
52
|
+
} from "./index-9cxxfkhb.js";
|
|
48
53
|
import {
|
|
49
54
|
collectToolSurface
|
|
50
55
|
} from "./index-993vtv1w.js";
|
|
@@ -59,6 +64,9 @@ import {
|
|
|
59
64
|
isUnsafeKey,
|
|
60
65
|
safeJsonParse
|
|
61
66
|
} from "./index-zsarb5xp.js";
|
|
67
|
+
import {
|
|
68
|
+
assertPositiveSafeInteger
|
|
69
|
+
} from "./index-0s4xebbg.js";
|
|
62
70
|
import {
|
|
63
71
|
formatZodError2
|
|
64
72
|
} from "./index-1eeqpadm.js";
|
|
@@ -189,17 +197,20 @@ function prepareCliCommandEmission(policy, result, options) {
|
|
|
189
197
|
};
|
|
190
198
|
}
|
|
191
199
|
}
|
|
192
|
-
function emitCliCommandResult(policy, result, options, writers, emit) {
|
|
200
|
+
function emitCliCommandResult(policy, result, options, writers, emit, shown) {
|
|
193
201
|
const emission = prepareCliCommandEmission(policy, result, options);
|
|
194
|
-
if (emission.result.ok
|
|
195
|
-
return
|
|
196
|
-
|
|
197
|
-
if (emission.result.ok && emission.presentation !== undefined) {
|
|
202
|
+
if (!emission.result.ok)
|
|
203
|
+
return emitResult2(emission.result, writers, emit);
|
|
204
|
+
if (emission.presentation !== undefined) {
|
|
198
205
|
writers.stdout(emission.presentation);
|
|
199
206
|
return emission.successExitCode;
|
|
200
207
|
}
|
|
201
|
-
const
|
|
202
|
-
|
|
208
|
+
const printed = shown ?? emission.result;
|
|
209
|
+
if (emission.presentationFailure !== undefined) {
|
|
210
|
+
return emitPresentationFailure(printed, emission.presentationFailure, writers, emit);
|
|
211
|
+
}
|
|
212
|
+
emitResult2(printed, writers, emit);
|
|
213
|
+
return emission.successExitCode;
|
|
203
214
|
}
|
|
204
215
|
function cliCommandPresentationSchema(definition) {
|
|
205
216
|
return buildToolPresentationSchema({
|
|
@@ -931,7 +942,8 @@ function createCliIo(config) {
|
|
|
931
942
|
}
|
|
932
943
|
|
|
933
944
|
// src/tools/cli/download.ts
|
|
934
|
-
import {
|
|
945
|
+
import { createHash } from "node:crypto";
|
|
946
|
+
import { basename as basename2, resolve } from "node:path";
|
|
935
947
|
|
|
936
948
|
// src/internal/write-download.ts
|
|
937
949
|
import path from "node:path";
|
|
@@ -949,39 +961,145 @@ async function writeDownload(root, name, data) {
|
|
|
949
961
|
});
|
|
950
962
|
}
|
|
951
963
|
|
|
964
|
+
// src/tools/cli/inline-files.ts
|
|
965
|
+
import { basename } from "node:path";
|
|
966
|
+
import { pathToFileURL } from "node:url";
|
|
967
|
+
import { z as z2 } from "zod";
|
|
968
|
+
var EmbeddedResourceSchema = z2.object({
|
|
969
|
+
type: z2.literal("resource"),
|
|
970
|
+
resource: z2.union([
|
|
971
|
+
z2.object({ uri: z2.string(), mimeType: z2.string().optional(), blob: z2.string() }),
|
|
972
|
+
z2.object({ uri: z2.string(), mimeType: z2.string().optional(), text: z2.string() })
|
|
973
|
+
])
|
|
974
|
+
});
|
|
975
|
+
var InlineFileSchema = z2.discriminatedUnion("type", [
|
|
976
|
+
McpImageContentSchema,
|
|
977
|
+
McpAudioContentSchema,
|
|
978
|
+
EmbeddedResourceSchema
|
|
979
|
+
]);
|
|
980
|
+
function inlineFileBlocks(data) {
|
|
981
|
+
if (!isRecord(data) || !Array.isArray(data.content))
|
|
982
|
+
return [];
|
|
983
|
+
return data.content.flatMap((part, index) => {
|
|
984
|
+
const parsed = InlineFileSchema.safeParse(part);
|
|
985
|
+
return parsed.success ? [{ index, file: parsed.data }] : [];
|
|
986
|
+
});
|
|
987
|
+
}
|
|
988
|
+
function decodeBase64(data, maxBytes) {
|
|
989
|
+
const padding = data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0;
|
|
990
|
+
const decodedLength = Math.floor((data.length - padding) * 3 / 4);
|
|
991
|
+
if (data.length > Math.ceil(maxBytes / 3) * 4 || decodedLength > maxBytes) {
|
|
992
|
+
throw new Error(`file exceeds the ${maxBytes}-byte cap`);
|
|
993
|
+
}
|
|
994
|
+
if (data.length % 4 === 1 || padding > 0 && data.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(data)) {
|
|
995
|
+
throw new Error("invalid base64");
|
|
996
|
+
}
|
|
997
|
+
const bytes = Buffer.from(data, "base64");
|
|
998
|
+
if (!bytes.toString("base64").startsWith(data))
|
|
999
|
+
throw new Error("invalid base64");
|
|
1000
|
+
return bytes;
|
|
1001
|
+
}
|
|
1002
|
+
function encodeText(text, maxBytes) {
|
|
1003
|
+
const bytes = text.length > maxBytes ? undefined : Buffer.from(text, "utf8");
|
|
1004
|
+
if (!bytes || bytes.length > maxBytes) {
|
|
1005
|
+
throw new Error(`file exceeds the ${maxBytes}-byte cap`);
|
|
1006
|
+
}
|
|
1007
|
+
return bytes;
|
|
1008
|
+
}
|
|
1009
|
+
function inlineFileBytes(file, maxBytes) {
|
|
1010
|
+
if (file.type !== "resource")
|
|
1011
|
+
return decodeBase64(file.data, maxBytes);
|
|
1012
|
+
return "blob" in file.resource ? decodeBase64(file.resource.blob, maxBytes) : encodeText(file.resource.text, maxBytes);
|
|
1013
|
+
}
|
|
1014
|
+
function uriFileName(uri) {
|
|
1015
|
+
try {
|
|
1016
|
+
return basename(new URL(uri).pathname);
|
|
1017
|
+
} catch {
|
|
1018
|
+
return "";
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
function inlineFileMimeType(file) {
|
|
1022
|
+
return file.type === "resource" ? file.resource.mimeType : file.mimeType;
|
|
1023
|
+
}
|
|
1024
|
+
function inlineFileName(file, digest) {
|
|
1025
|
+
const own = file.type === "resource" ? uriFileName(file.resource.uri) || undefined : file.name;
|
|
1026
|
+
return own ?? `${file.type}-${digest}${mediaExtension(inlineFileMimeType(file) ?? "") ?? ".bin"}`;
|
|
1027
|
+
}
|
|
1028
|
+
function linkSavedFiles(data, blocks, saved) {
|
|
1029
|
+
if (!isRecord(data) || !Array.isArray(data.content))
|
|
1030
|
+
return data;
|
|
1031
|
+
const links = new Map;
|
|
1032
|
+
for (const block of blocks) {
|
|
1033
|
+
const file = saved(block);
|
|
1034
|
+
if (!file)
|
|
1035
|
+
continue;
|
|
1036
|
+
const mimeType = inlineFileMimeType(block.file);
|
|
1037
|
+
links.set(block.index, {
|
|
1038
|
+
type: "resource_link",
|
|
1039
|
+
uri: pathToFileURL(file.path).href,
|
|
1040
|
+
name: file.name,
|
|
1041
|
+
...mimeType !== undefined && { mimeType },
|
|
1042
|
+
size: file.size
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
if (links.size === 0)
|
|
1046
|
+
return data;
|
|
1047
|
+
return { ...data, content: data.content.map((part, index) => links.get(index) ?? part) };
|
|
1048
|
+
}
|
|
1049
|
+
|
|
952
1050
|
// src/tools/cli/download.ts
|
|
953
1051
|
var DEFAULT_DOWNLOAD_MAX_BYTES = 100 * 1024 * 1024;
|
|
954
|
-
async function
|
|
1052
|
+
async function saveResultMedia(data, options) {
|
|
1053
|
+
const blocks = inlineFileBlocks(data);
|
|
1054
|
+
const sources = [...options.download?.(data) ?? [], ...blocks];
|
|
1055
|
+
if (sources.length === 0) {
|
|
1056
|
+
if (!options.quiet)
|
|
1057
|
+
options.stderr(`--output-dir: the result carries no files to save
|
|
1058
|
+
`);
|
|
1059
|
+
return { ok: true, data };
|
|
1060
|
+
}
|
|
1061
|
+
const batch = await saveBatch(sources, options);
|
|
1062
|
+
return {
|
|
1063
|
+
ok: batch.ok,
|
|
1064
|
+
data: linkSavedFiles(data, blocks, (block) => batch.files.get(block))
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
async function saveBatch(sources, { dir, allowPrivateHosts, maxBytes, timeoutMs, quiet, stderr }) {
|
|
955
1068
|
const root = resolve(dir);
|
|
956
|
-
|
|
957
|
-
return true;
|
|
1069
|
+
const files = new Map;
|
|
958
1070
|
let directory;
|
|
959
1071
|
try {
|
|
960
1072
|
directory = await openPinnedDirectory(root, { create: true, readable: false });
|
|
961
1073
|
} catch (error) {
|
|
962
1074
|
stderr(`failed to prepare download directory: ${error instanceof Error ? error.message : String(error)}
|
|
963
1075
|
`);
|
|
964
|
-
return false;
|
|
1076
|
+
return { ok: false, files };
|
|
965
1077
|
}
|
|
966
|
-
let
|
|
1078
|
+
let ok = true;
|
|
1079
|
+
const digests = new Map;
|
|
967
1080
|
try {
|
|
968
|
-
for (const
|
|
1081
|
+
for (const source of sources) {
|
|
969
1082
|
try {
|
|
970
|
-
const
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
const
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1083
|
+
const bytes = "url" in source ? await fetchDownload(source.url, allowPrivateHosts, maxBytes, timeoutMs) : inlineFileBytes(source.file, maxBytes);
|
|
1084
|
+
const digest = createHash("sha256").update(bytes).digest("hex");
|
|
1085
|
+
const name = basename2("url" in source ? source.name : inlineFileName(source.file, digest));
|
|
1086
|
+
const path = resolve(root, name);
|
|
1087
|
+
const written = digests.get(name);
|
|
1088
|
+
if (written === undefined) {
|
|
1089
|
+
await writeDownload(directory, name, bytes);
|
|
1090
|
+
digests.set(name, digest);
|
|
1091
|
+
if (!quiet)
|
|
1092
|
+
stderr(`saved ${path} (${(bytes.length / 1024).toFixed(0)}KB)
|
|
980
1093
|
`);
|
|
1094
|
+
} else if (written !== digest) {
|
|
1095
|
+
throw new Error(`another file of this batch is already saved as ${JSON.stringify(name)}`);
|
|
1096
|
+
}
|
|
1097
|
+
files.set(source, { path, name, size: bytes.length });
|
|
981
1098
|
} catch (err) {
|
|
982
|
-
|
|
1099
|
+
ok = false;
|
|
983
1100
|
const reason = errnoOf(err) ?? (err instanceof Error ? err.message : String(err));
|
|
984
|
-
|
|
1101
|
+
const subject = "url" in source ? `failed to download ${source.url}` : `failed to save content[${source.index}]`;
|
|
1102
|
+
stderr(`${subject}: ${reason}
|
|
985
1103
|
`);
|
|
986
1104
|
}
|
|
987
1105
|
}
|
|
@@ -989,12 +1107,21 @@ async function downloadResults(files, dir, stderr, quiet, allowPrivate, maxBytes
|
|
|
989
1107
|
try {
|
|
990
1108
|
await directory.close();
|
|
991
1109
|
} catch (error) {
|
|
992
|
-
|
|
1110
|
+
ok = false;
|
|
993
1111
|
stderr(`failed to close download directory: ${error instanceof Error ? error.message : String(error)}
|
|
994
1112
|
`);
|
|
995
1113
|
}
|
|
996
1114
|
}
|
|
997
|
-
return
|
|
1115
|
+
return { ok, files };
|
|
1116
|
+
}
|
|
1117
|
+
async function fetchDownload(url, allowPrivateHosts, maxBytes, timeoutMs) {
|
|
1118
|
+
const res = await fetchGuarded(new URL(url), allowPrivateHosts, { timeoutMs });
|
|
1119
|
+
if (!res.ok)
|
|
1120
|
+
throw new Error(`HTTP ${res.status}`);
|
|
1121
|
+
const bytes = await readCapped(res, maxBytes);
|
|
1122
|
+
if (!bytes)
|
|
1123
|
+
throw new Error(`file exceeds the ${maxBytes}-byte cap`);
|
|
1124
|
+
return bytes;
|
|
998
1125
|
}
|
|
999
1126
|
|
|
1000
1127
|
// src/tools/cli/help.ts
|
|
@@ -1002,7 +1129,7 @@ var GLOBAL_OPTIONS = [
|
|
|
1002
1129
|
["--json", "Emit compact success/error JSON records (for scripts)"],
|
|
1003
1130
|
["--wait", "Block-poll an async result to a terminal state"],
|
|
1004
1131
|
["--wait-timeout <s>", "Override the --wait timeout in seconds"],
|
|
1005
|
-
["--output-dir <dir>", "
|
|
1132
|
+
["--output-dir <dir>", "Save the files a result names or carries into a directory"],
|
|
1006
1133
|
["--quiet", "Suppress non-essential stderr output"],
|
|
1007
1134
|
["--dry-run", "Print the resolved call without executing it"],
|
|
1008
1135
|
["--schema", "Print the JSON Schema of a command input and output"],
|
|
@@ -1410,7 +1537,7 @@ async function buildManagedSurface(session, typedGlobals, forExecution) {
|
|
|
1410
1537
|
}
|
|
1411
1538
|
|
|
1412
1539
|
// src/tools/cli/args.ts
|
|
1413
|
-
import { z as
|
|
1540
|
+
import { z as z3 } from "zod";
|
|
1414
1541
|
|
|
1415
1542
|
// src/tools/cli/args-json.ts
|
|
1416
1543
|
function cliFieldOption(option, fields) {
|
|
@@ -1818,7 +1945,7 @@ function extractCliGlobalOptions2(argv, schema) {
|
|
|
1818
1945
|
try {
|
|
1819
1946
|
coerced = coerceJsonArgs2(args, schema);
|
|
1820
1947
|
} catch (error) {
|
|
1821
|
-
if (error instanceof
|
|
1948
|
+
if (error instanceof z3.ZodError)
|
|
1822
1949
|
refuseGlobalOption(error.issues[0]);
|
|
1823
1950
|
throw error;
|
|
1824
1951
|
}
|
|
@@ -1914,6 +2041,7 @@ function createCliSession(config, io) {
|
|
|
1914
2041
|
if (config.auth !== undefined && config.resolveAuth !== undefined) {
|
|
1915
2042
|
throw new Error("[stitchkit] createCli: use either auth or resolveAuth, not both");
|
|
1916
2043
|
}
|
|
2044
|
+
assertPositiveSafeInteger("createCli maxDownloadBytes", config.maxDownloadBytes);
|
|
1917
2045
|
const applicationOptions = config.globalOptions ? jsonSchemaFields(buildToolPresentationSchema({
|
|
1918
2046
|
inputSchema: config.globalOptions,
|
|
1919
2047
|
unrepresentable: "any"
|
|
@@ -2451,11 +2579,6 @@ async function runManagedCommand(session, route, command, managed) {
|
|
|
2451
2579
|
}
|
|
2452
2580
|
if (options.waitTimeout !== undefined && !options.wait) {
|
|
2453
2581
|
stderr(`--wait-timeout requires --wait
|
|
2454
|
-
`);
|
|
2455
|
-
return exit(2);
|
|
2456
|
-
}
|
|
2457
|
-
if (options.outputDir !== undefined && !config.download) {
|
|
2458
|
-
stderr(`--output-dir is not configured for this CLI
|
|
2459
2582
|
`);
|
|
2460
2583
|
return exit(2);
|
|
2461
2584
|
}
|
|
@@ -2525,40 +2648,54 @@ async function executeManagedTool(session, route, command, managed, tool, { tool
|
|
|
2525
2648
|
}
|
|
2526
2649
|
return result;
|
|
2527
2650
|
}
|
|
2528
|
-
async function emitManagedResult(session, command,
|
|
2651
|
+
async function emitManagedResult(session, command, result, options, repeatable) {
|
|
2529
2652
|
const { config } = session;
|
|
2530
2653
|
const { stdout, stderr, exit } = session.io;
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2654
|
+
const emit = { ...emitOptionsFor(config, options.json, command), repeatable };
|
|
2655
|
+
if (!result.ok)
|
|
2656
|
+
return exit(emitResult2(result, { stdout, stderr }, emit));
|
|
2657
|
+
let shown = result;
|
|
2658
|
+
let mediaExitCode = 0;
|
|
2659
|
+
if (options.outputDir !== undefined) {
|
|
2660
|
+
const saved = await saveResultMedia(result.data, {
|
|
2661
|
+
dir: options.outputDir,
|
|
2662
|
+
download: config.download,
|
|
2663
|
+
allowPrivateHosts: config.allowPrivateDownloadHosts ?? false,
|
|
2664
|
+
maxBytes: config.maxDownloadBytes ?? DEFAULT_DOWNLOAD_MAX_BYTES,
|
|
2665
|
+
timeoutMs: config.downloadTimeoutMs,
|
|
2666
|
+
quiet: options.quiet,
|
|
2667
|
+
stderr
|
|
2668
|
+
});
|
|
2669
|
+
shown = { ...result, data: saved.data };
|
|
2670
|
+
if (!saved.ok)
|
|
2671
|
+
mediaExitCode = 1;
|
|
2535
2672
|
}
|
|
2536
|
-
if (options.view
|
|
2673
|
+
if (options.view) {
|
|
2537
2674
|
let viewed;
|
|
2538
2675
|
try {
|
|
2539
|
-
viewed = renderCliView2(
|
|
2676
|
+
viewed = renderCliView2(shown.data, options.view);
|
|
2540
2677
|
} catch (error) {
|
|
2541
2678
|
const failure = error instanceof CliArgumentError2 ? {
|
|
2542
2679
|
ok: false,
|
|
2543
2680
|
code: "BAD_REQUEST",
|
|
2544
2681
|
details: { message: error.message }
|
|
2545
2682
|
} : toolResultFromError(error);
|
|
2546
|
-
return exit(emitPresentationFailure(
|
|
2683
|
+
return exit(emitPresentationFailure(shown, failure, { stdout, stderr }, emit));
|
|
2547
2684
|
}
|
|
2548
2685
|
if (viewed.kind === "text") {
|
|
2549
2686
|
stdout(viewed.text);
|
|
2550
|
-
return exit(
|
|
2687
|
+
return exit(mediaExitCode);
|
|
2551
2688
|
}
|
|
2552
2689
|
if (viewed.order) {
|
|
2553
2690
|
stdout(`${stringifyGroups(viewed.data, viewed.order, options.json === true)}
|
|
2554
2691
|
`);
|
|
2555
|
-
return exit(
|
|
2692
|
+
return exit(mediaExitCode);
|
|
2556
2693
|
}
|
|
2557
|
-
|
|
2694
|
+
shown = { ...shown, data: viewed.data };
|
|
2558
2695
|
}
|
|
2559
2696
|
const policy = options.view === undefined && !options.wait ? cliResultPolicy(config, command) : undefined;
|
|
2560
|
-
const exitCode = emitCliCommandResult(policy, result, options, { stdout, stderr },
|
|
2561
|
-
return exit(
|
|
2697
|
+
const exitCode = emitCliCommandResult(policy, result, options, { stdout, stderr }, emit, shown);
|
|
2698
|
+
return exit(mediaExitCode || exitCode);
|
|
2562
2699
|
}
|
|
2563
2700
|
|
|
2564
2701
|
// src/tools/cli/run-native.ts
|
|
@@ -32,9 +32,8 @@ import {
|
|
|
32
32
|
isModuleNotFound
|
|
33
33
|
} from "./index-srs8hj9c.js";
|
|
34
34
|
import {
|
|
35
|
-
bindContract
|
|
36
|
-
|
|
37
|
-
} from "./index-eabx6qjh.js";
|
|
35
|
+
bindContract
|
|
36
|
+
} from "./index-tnnmekgb.js";
|
|
38
37
|
import {
|
|
39
38
|
assertCorsConfig,
|
|
40
39
|
isOriginAllowed,
|
|
@@ -42,6 +41,9 @@ import {
|
|
|
42
41
|
requestCorsHeaders,
|
|
43
42
|
applyCors
|
|
44
43
|
} from "./index-pq7rkwkk.js";
|
|
44
|
+
import {
|
|
45
|
+
mediaTypeEssence
|
|
46
|
+
} from "./index-zs8cze4j.js";
|
|
45
47
|
import {
|
|
46
48
|
runWithRequestContext2,
|
|
47
49
|
getRequestContext2,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/tools/operations/async-operation-contract.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var AsyncOperationCancelResultSchema2 = z.discriminatedUnion("outcome", [
|
|
4
|
+
z.object({ outcome: z.literal("accepted") }),
|
|
5
|
+
z.object({ outcome: z.literal("already_terminal") }),
|
|
6
|
+
z.object({ outcome: z.literal("rejected"), reason: z.string().min(1) })
|
|
7
|
+
]);
|
|
8
|
+
function createAsyncOperationSnapshotSchema2(config) {
|
|
9
|
+
const progress = config.progress ? { progress: config.progress.optional() } : {};
|
|
10
|
+
return z.discriminatedUnion("phase", [
|
|
11
|
+
z.object({ phase: z.literal("pending"), ...progress }),
|
|
12
|
+
z.object({ phase: z.literal("running"), ...progress }),
|
|
13
|
+
z.object({ phase: z.literal("succeeded"), ...progress }),
|
|
14
|
+
z.object({ phase: z.literal("failed"), failure: config.failure, ...progress }),
|
|
15
|
+
z.object({ phase: z.literal("cancelled"), ...progress })
|
|
16
|
+
]);
|
|
17
|
+
}
|
|
18
|
+
export { AsyncOperationCancelResultSchema2, createAsyncOperationSnapshotSchema2 };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mediaTypeEssence
|
|
3
|
+
} from "./index-zs8cze4j.js";
|
|
1
4
|
import {
|
|
2
5
|
sleep
|
|
3
6
|
} from "./index-eemvahkc.js";
|
|
@@ -74,4 +77,21 @@ function runWaitOperation(params) {
|
|
|
74
77
|
});
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
|
|
80
|
+
// src/internal/media-extension.ts
|
|
81
|
+
var MIME_EXT = new Map([
|
|
82
|
+
["image/png", ".png"],
|
|
83
|
+
["image/jpeg", ".jpg"],
|
|
84
|
+
["image/webp", ".webp"],
|
|
85
|
+
["image/gif", ".gif"],
|
|
86
|
+
["video/mp4", ".mp4"],
|
|
87
|
+
["video/webm", ".webm"],
|
|
88
|
+
["audio/mpeg", ".mp3"],
|
|
89
|
+
["audio/wav", ".wav"],
|
|
90
|
+
["audio/ogg", ".ogg"],
|
|
91
|
+
["audio/mp4", ".m4a"]
|
|
92
|
+
]);
|
|
93
|
+
function mediaExtension(contentType) {
|
|
94
|
+
return MIME_EXT.get(mediaTypeEssence(contentType));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { WaitTimeoutError, pollUntil, runWaitOperation, mediaExtension };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/tools/transfer/view-file-contract.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var MAX_VIEW_FILES = 20;
|
|
4
|
+
var McpAnnotationsSchema2 = z.object({
|
|
5
|
+
audience: z.array(z.enum(["user", "assistant"])).optional(),
|
|
6
|
+
priority: z.number().optional()
|
|
7
|
+
});
|
|
8
|
+
var inlineMediaShape = {
|
|
9
|
+
data: z.string(),
|
|
10
|
+
mimeType: z.string(),
|
|
11
|
+
name: z.string().optional(),
|
|
12
|
+
annotations: McpAnnotationsSchema2.optional()
|
|
13
|
+
};
|
|
14
|
+
var McpImageContentSchema = z.object({
|
|
15
|
+
type: z.literal("image"),
|
|
16
|
+
...inlineMediaShape
|
|
17
|
+
});
|
|
18
|
+
var McpAudioContentSchema = z.object({
|
|
19
|
+
type: z.literal("audio"),
|
|
20
|
+
...inlineMediaShape
|
|
21
|
+
});
|
|
22
|
+
var McpMediaContentSchema2 = z.discriminatedUnion("type", [
|
|
23
|
+
z.object({ type: z.literal("text"), text: z.string() }),
|
|
24
|
+
McpImageContentSchema,
|
|
25
|
+
McpAudioContentSchema
|
|
26
|
+
]);
|
|
27
|
+
var ViewFileErrorSchema2 = z.object({
|
|
28
|
+
path: z.string(),
|
|
29
|
+
message: z.string()
|
|
30
|
+
});
|
|
31
|
+
var ViewFileOutputSchema2 = z.object({
|
|
32
|
+
content: z.array(McpMediaContentSchema2),
|
|
33
|
+
errors: z.array(ViewFileErrorSchema2)
|
|
34
|
+
});
|
|
35
|
+
var ViewFileInputSchema2 = z.object({
|
|
36
|
+
paths: z.union([z.string(), z.array(z.string()).max(MAX_VIEW_FILES)]).describe("One media URL or file path, or an array of them. Pass the array itself, not JSON written as text.")
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export { McpAnnotationsSchema2, McpImageContentSchema, McpAudioContentSchema, McpMediaContentSchema2, ViewFileErrorSchema2, ViewFileOutputSchema2, ViewFileInputSchema2 };
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
|
|
19
19
|
// src/internal/exclusive-lock.ts
|
|
20
20
|
import { randomUUID } from "node:crypto";
|
|
21
|
+
import { constants as constants2 } from "node:fs";
|
|
21
22
|
import { lstat, open as open2, readdir as readdir2, unlink } from "node:fs/promises";
|
|
22
23
|
import { hostname as hostname2 } from "node:os";
|
|
23
24
|
import { dirname, join } from "node:path";
|
|
@@ -179,6 +180,7 @@ async function readLockFile(path, onFailure, signal) {
|
|
|
179
180
|
}
|
|
180
181
|
return {
|
|
181
182
|
path,
|
|
183
|
+
record: record.text,
|
|
182
184
|
...readOwner(record.text),
|
|
183
185
|
ino: record.info.ino,
|
|
184
186
|
dev: record.info.dev,
|
|
@@ -288,6 +290,38 @@ async function createOwned(path, options, reclaimed) {
|
|
|
288
290
|
}
|
|
289
291
|
};
|
|
290
292
|
}
|
|
293
|
+
async function removeJudgedLock(state) {
|
|
294
|
+
const pin = await open2(state.path, constants2.O_RDONLY | constants2.O_NOFOLLOW | constants2.O_NONBLOCK).catch((error) => {
|
|
295
|
+
if (isCode(error, "ENOENT"))
|
|
296
|
+
return null;
|
|
297
|
+
throw error;
|
|
298
|
+
});
|
|
299
|
+
if (!pin)
|
|
300
|
+
return "absent";
|
|
301
|
+
try {
|
|
302
|
+
const pinned = await pin.stat();
|
|
303
|
+
if (pinned.ino !== state.ino || pinned.dev !== state.dev)
|
|
304
|
+
return "changed";
|
|
305
|
+
const current = await readLockRecord(state.path, {
|
|
306
|
+
singleLink: state.stagedName === undefined
|
|
307
|
+
}).catch((error) => {
|
|
308
|
+
if (error instanceof LockRecordError || isCode(error, "ENOENT"))
|
|
309
|
+
return null;
|
|
310
|
+
throw error;
|
|
311
|
+
});
|
|
312
|
+
if (current?.info.ino !== state.ino || current.info.dev !== state.dev || current.text !== state.record)
|
|
313
|
+
return "changed";
|
|
314
|
+
if (state.stagedName !== undefined)
|
|
315
|
+
await unlink(state.stagedName).catch((error) => {
|
|
316
|
+
if (!isCode(error, "ENOENT"))
|
|
317
|
+
throw error;
|
|
318
|
+
});
|
|
319
|
+
await unlinkIfSame(state.path, state.ino, state.dev);
|
|
320
|
+
return "removed";
|
|
321
|
+
} finally {
|
|
322
|
+
await pin.close();
|
|
323
|
+
}
|
|
324
|
+
}
|
|
291
325
|
function reclaimable(state, diagnosis, graceMs) {
|
|
292
326
|
if (state.owner)
|
|
293
327
|
return diagnosis.liveness === "gone";
|
|
@@ -327,12 +361,11 @@ async function reclaimUnderGuard(path, options, depth) {
|
|
|
327
361
|
return { refused: true };
|
|
328
362
|
if (!reclaimable(state, diagnosis, options.ownerlessGraceMs))
|
|
329
363
|
return { refused: true, cause: diagnosis.cause };
|
|
330
|
-
if (state
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
await unlinkIfSame(path, state.ino, state.dev);
|
|
364
|
+
if (await removeJudgedLock(state) === "changed")
|
|
365
|
+
return {
|
|
366
|
+
refused: true,
|
|
367
|
+
cause: new LockRecordError("LOCK_RECORD_CHANGED", "The judged lock was replaced before it could be reclaimed")
|
|
368
|
+
};
|
|
336
369
|
}
|
|
337
370
|
await sweepStagedLocks(dirname(path), options.machineIdentity, options.signal);
|
|
338
371
|
return await createOwned(path, options, state !== undefined).catch((error) => {
|
|
@@ -129,9 +129,4 @@ function createScopedImplement2() {
|
|
|
129
129
|
return Object.assign(implementScoped, { stream, declare });
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
function mediaTypeEssence(contentType) {
|
|
134
|
-
return (contentType ?? "").split(";", 1)[0]?.trim().toLowerCase() ?? "";
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export { defineMultipartStream2, createMultipartStream2, contractOnlyService, bindContract, implement2, createImplement2, createScopedImplement2, mediaTypeEssence };
|
|
132
|
+
export { defineMultipartStream2, createMultipartStream2, contractOnlyService, bindContract, implement2, createImplement2, createScopedImplement2 };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exclusive-lock.d.ts","sourceRoot":"","sources":["../../src/internal/exclusive-lock.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"exclusive-lock.d.ts","sourceRoot":"","sources":["../../src/internal/exclusive-lock.ts"],"names":[],"mappings":"AA8BA,OAAO,EAEL,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EAGxB,MAAM,wBAAwB,CAAC;AAMhC,iCAAiC;AACjC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC;IACnC,kFAAkF;IAClF,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,yEAAyE;IACzE,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,uFAAuF;IACvF,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,oFAAoF;IACpF,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3C;AAED,MAAM,MAAM,oBAAoB,GAC5B;IAAE,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAA;CAAE,GACpC;IACE,0FAA0F;IAC1F,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,6CAA6C;IAC7C,QAAQ,CAAC,SAAS,CAAC,EAAE,sBAAsB,CAAC;CAC7C,CAAC;AAoWN;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,2BAA2B,EACpC,KAAK,SAAI,GACR,OAAO,CAAC,oBAAoB,CAAC,CAkC/B;AAED,gFAAgF;AAChF,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAEpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-extension.d.ts","sourceRoot":"","sources":["../../src/internal/media-extension.ts"],"names":[],"mappings":"AAeA,oFAAoF;AACpF,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEtE"}
|
package/dist/tools/cli/args.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface CliRunOptions {
|
|
|
27
27
|
wait: boolean;
|
|
28
28
|
/** `--wait-timeout <seconds>` — override the poll timeout. */
|
|
29
29
|
waitTimeout?: number;
|
|
30
|
-
/** `--output-dir <dir>` —
|
|
30
|
+
/** `--output-dir <dir>` — save the files a result names or carries into this directory. */
|
|
31
31
|
outputDir?: string;
|
|
32
32
|
/** `--quiet` — suppress non-essential stderr chatter. */
|
|
33
33
|
quiet: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/args.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAcxB,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,aAAa,CAAC;AAMjE,yEAAyE;AACzE,MAAM,WAAW,aAAa;IAC5B,sEAAsE;IACtE,IAAI,EAAE,OAAO,CAAC;IACd,iEAAiE;IACjE,IAAI,EAAE,OAAO,CAAC;IACd,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/args.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAcxB,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,aAAa,CAAC;AAMjE,yEAAyE;AACzE,MAAM,WAAW,aAAa;IAC5B,sEAAsE;IACtE,IAAI,EAAE,OAAO,CAAC;IACd,iEAAiE;IACjE,IAAI,EAAE,OAAO,CAAC;IACd,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2FAA2F;IAC3F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,KAAK,EAAE,OAAO,CAAC;IACf,qEAAqE;IACrE,MAAM,EAAE,OAAO,CAAC;IAChB,qDAAqD;IACrD,IAAI,EAAE,OAAO,CAAC;IACd,0FAA0F;IAC1F,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,+BAA+B;IAC/B,OAAO,EAAE,aAAa,CAAC;CACxB;AAwHD;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,SAAS,EAC7B,MAAM,GAAE;IACN,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5B,GACL,aAAa,CAsBf;AAED,iFAAiF;AACjF,MAAM,WAAW,qBAAqB;IACpC,0EAA0E;IAC1E,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AASD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,MAAM,EAAE,CAAC,CAAC,SAAS,GAAG,SAAS,GAC9B,qBAAqB,CAyDvB"}
|
|
@@ -82,10 +82,16 @@ export declare function cliCommandResultPolicy(definition: CliCommandDefinition)
|
|
|
82
82
|
* The single place a policy meets the terminal: a native command and a managed
|
|
83
83
|
* one answer through it, so `present`, `exitCode` and a failed presentation
|
|
84
84
|
* behave identically on both.
|
|
85
|
+
*
|
|
86
|
+
* The policy judges `result`, the operation's own answer. `shown` is what stdout
|
|
87
|
+
* prints when the policy brings no presenter: the same answer, unless the caller
|
|
88
|
+
* has already moved part of it elsewhere (a view, media saved to files).
|
|
85
89
|
*/
|
|
86
90
|
export declare function emitCliCommandResult(policy: CliResultPolicy<unknown> | undefined, result: ToolResult, options: Readonly<CliRunOptions>, writers: CliWriters, emit: EmitOptions & {
|
|
87
91
|
repeatable: boolean;
|
|
88
|
-
}
|
|
92
|
+
}, shown?: Extract<ToolResult, {
|
|
93
|
+
ok: true;
|
|
94
|
+
}>): number;
|
|
89
95
|
export declare function cliCommandPresentationSchema(definition: CliCommandDefinition): Record<string, unknown>;
|
|
90
96
|
/** Execute a CLI-only definition without inventing a tool operation identity. */
|
|
91
97
|
export declare function executeCliCommand(definition: CliCommandDefinition, rawArgs: Record<string, unknown>, options: CliRunOptions, writers: CliWriters, coerceJson: boolean, globals?: Readonly<Record<string, unknown>>): Promise<ToolResult>;
|