@evref-bl/plexus 0.15.2 → 0.17.0
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 +8 -12
- package/dist/answers/index.d.ts +97 -0
- package/dist/answers/index.d.ts.map +1 -0
- package/dist/answers/index.js +352 -0
- package/dist/answers/index.js.map +1 -0
- package/dist/answers/texts.d.ts +83 -0
- package/dist/answers/texts.d.ts.map +1 -0
- package/dist/answers/texts.js +216 -0
- package/dist/answers/texts.js.map +1 -0
- package/dist/cli.js +21 -182
- package/dist/cli.js.map +1 -1
- package/dist/commandLine.d.ts +13 -0
- package/dist/commandLine.d.ts.map +1 -0
- package/dist/commandLine.js +259 -0
- package/dist/commandLine.js.map +1 -0
- package/dist/config/pharoMcpVersion.d.ts +6 -7
- package/dist/config/pharoMcpVersion.d.ts.map +1 -1
- package/dist/config/pharoMcpVersion.js +6 -7
- package/dist/config/pharoMcpVersion.js.map +1 -1
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +17 -0
- package/dist/errors.js.map +1 -0
- package/dist/forward/endpointHandoffFormat.d.ts +23 -0
- package/dist/forward/endpointHandoffFormat.d.ts.map +1 -0
- package/dist/forward/endpointHandoffFormat.js.map +1 -0
- package/dist/forward/index.d.ts +61 -0
- package/dist/forward/index.d.ts.map +1 -0
- package/dist/forward/index.js +133 -0
- package/dist/forward/index.js.map +1 -0
- package/dist/forward/jsonRpc.d.ts +58 -0
- package/dist/forward/jsonRpc.d.ts.map +1 -0
- package/dist/forward/jsonRpc.js +259 -0
- package/dist/forward/jsonRpc.js.map +1 -0
- package/dist/home.d.ts +15 -0
- package/dist/home.d.ts.map +1 -0
- package/dist/home.js +30 -0
- package/dist/home.js.map +1 -0
- package/dist/images/bases.d.ts +41 -0
- package/dist/images/bases.d.ts.map +1 -0
- package/dist/images/bases.js +194 -0
- package/dist/images/bases.js.map +1 -0
- package/dist/images/claims.d.ts +34 -0
- package/dist/images/claims.d.ts.map +1 -0
- package/dist/images/claims.js +119 -0
- package/dist/images/claims.js.map +1 -0
- package/dist/images/context.d.ts +37 -0
- package/dist/images/context.d.ts.map +1 -0
- package/dist/images/context.js +40 -0
- package/dist/images/context.js.map +1 -0
- package/dist/images/create.d.ts +19 -0
- package/dist/images/create.d.ts.map +1 -0
- package/dist/images/create.js +122 -0
- package/dist/images/create.js.map +1 -0
- package/dist/images/delete.d.ts +10 -0
- package/dist/images/delete.d.ts.map +1 -0
- package/dist/images/delete.js +32 -0
- package/dist/images/delete.js.map +1 -0
- package/dist/images/endpoint.d.ts +29 -0
- package/dist/images/endpoint.d.ts.map +1 -0
- package/dist/images/endpoint.js +86 -0
- package/dist/images/endpoint.js.map +1 -0
- package/dist/images/index.d.ts +32 -0
- package/dist/images/index.d.ts.map +1 -0
- package/dist/images/index.js +56 -0
- package/dist/images/index.js.map +1 -0
- package/dist/images/leftovers.d.ts +9 -0
- package/dist/images/leftovers.d.ts.map +1 -0
- package/dist/images/leftovers.js +38 -0
- package/dist/images/leftovers.js.map +1 -0
- package/dist/images/list.d.ts +12 -0
- package/dist/images/list.d.ts.map +1 -0
- package/dist/images/list.js +74 -0
- package/dist/images/list.js.map +1 -0
- package/dist/images/names.d.ts +15 -0
- package/dist/images/names.d.ts.map +1 -0
- package/dist/images/names.js +53 -0
- package/dist/images/names.js.map +1 -0
- package/dist/images/prepare.d.ts +18 -0
- package/dist/images/prepare.d.ts.map +1 -0
- package/dist/images/prepare.js +58 -0
- package/dist/images/prepare.js.map +1 -0
- package/dist/images/processes.d.ts +21 -0
- package/dist/images/processes.d.ts.map +1 -0
- package/dist/images/processes.js +83 -0
- package/dist/images/processes.js.map +1 -0
- package/dist/images/scripts.d.ts +48 -0
- package/dist/images/scripts.d.ts.map +1 -0
- package/dist/images/scripts.js +149 -0
- package/dist/images/scripts.js.map +1 -0
- package/dist/images/start.d.ts +23 -0
- package/dist/images/start.d.ts.map +1 -0
- package/dist/images/start.js +179 -0
- package/dist/images/start.js.map +1 -0
- package/dist/images/stop.d.ts +17 -0
- package/dist/images/stop.d.ts.map +1 -0
- package/dist/images/stop.js +171 -0
- package/dist/images/stop.js.map +1 -0
- package/dist/images/store.d.ts +62 -0
- package/dist/images/store.d.ts.map +1 -0
- package/dist/images/store.js +181 -0
- package/dist/images/store.js.map +1 -0
- package/dist/images/templates.d.ts +14 -0
- package/dist/images/templates.d.ts.map +1 -0
- package/dist/images/templates.js +85 -0
- package/dist/images/templates.js.map +1 -0
- package/dist/index.d.ts +16 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -22
- package/dist/index.js.map +1 -1
- package/dist/launcher/pharoLauncherMcpClient.d.ts +22 -59
- package/dist/launcher/pharoLauncherMcpClient.d.ts.map +1 -1
- package/dist/launcher/pharoLauncherMcpClient.js +121 -98
- package/dist/launcher/pharoLauncherMcpClient.js.map +1 -1
- package/dist/launcher/pharoLauncherProfile.d.ts +5 -32
- package/dist/launcher/pharoLauncherProfile.d.ts.map +1 -1
- package/dist/launcher/pharoLauncherProfile.js +17 -115
- package/dist/launcher/pharoLauncherProfile.js.map +1 -1
- package/dist/mcp/server.d.ts +27 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +269 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/telemetry/reachability.d.ts +59 -0
- package/dist/telemetry/reachability.d.ts.map +1 -0
- package/dist/telemetry/reachability.js +183 -0
- package/dist/telemetry/reachability.js.map +1 -0
- package/dist/telemetry/sdk.d.ts +54 -0
- package/dist/telemetry/sdk.d.ts.map +1 -0
- package/dist/telemetry/sdk.js +167 -0
- package/dist/telemetry/sdk.js.map +1 -0
- package/dist/telemetry/settings.d.ts +16 -0
- package/dist/telemetry/settings.d.ts.map +1 -0
- package/dist/telemetry/settings.js +67 -0
- package/dist/telemetry/settings.js.map +1 -0
- package/dist/telemetry/trace.d.ts +32 -0
- package/dist/telemetry/trace.d.ts.map +1 -0
- package/dist/telemetry/trace.js +79 -0
- package/dist/telemetry/trace.js.map +1 -0
- package/dist/types.d.ts +82 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/package.json +15 -15
- package/dist/config/config.d.ts +0 -15
- package/dist/config/config.d.ts.map +0 -1
- package/dist/config/config.js +0 -74
- package/dist/config/config.js.map +0 -1
- package/dist/config/plexusHome.d.ts +0 -17
- package/dist/config/plexusHome.d.ts.map +0 -1
- package/dist/config/plexusHome.js +0 -30
- package/dist/config/plexusHome.js.map +0 -1
- package/dist/config/projectConfig.d.ts +0 -141
- package/dist/config/projectConfig.d.ts.map +0 -1
- package/dist/config/projectConfig.js +0 -722
- package/dist/config/projectConfig.js.map +0 -1
- package/dist/config/projectConfigAuthoring.d.ts +0 -53
- package/dist/config/projectConfigAuthoring.d.ts.map +0 -1
- package/dist/config/projectConfigAuthoring.js +0 -159
- package/dist/config/projectConfigAuthoring.js.map +0 -1
- package/dist/gateway/projectImageMcpEndpoint.d.ts +0 -23
- package/dist/gateway/projectImageMcpEndpoint.d.ts.map +0 -1
- package/dist/gateway/projectImageMcpEndpoint.js +0 -40
- package/dist/gateway/projectImageMcpEndpoint.js.map +0 -1
- package/dist/gateway/server/index.d.ts +0 -8
- package/dist/gateway/server/index.d.ts.map +0 -1
- package/dist/gateway/server/index.js +0 -34
- package/dist/gateway/server/index.js.map +0 -1
- package/dist/gateway/server/mcp/server.d.ts +0 -66
- package/dist/gateway/server/mcp/server.d.ts.map +0 -1
- package/dist/gateway/server/mcp/server.js +0 -458
- package/dist/gateway/server/mcp/server.js.map +0 -1
- package/dist/gateway/server/routing/endpointHandoffFormat.d.ts +0 -26
- package/dist/gateway/server/routing/endpointHandoffFormat.d.ts.map +0 -1
- package/dist/gateway/server/routing/endpointHandoffFormat.js.map +0 -1
- package/dist/gateway/server/routing/gateway.d.ts +0 -167
- package/dist/gateway/server/routing/gateway.d.ts.map +0 -1
- package/dist/gateway/server/routing/gateway.js +0 -863
- package/dist/gateway/server/routing/gateway.js.map +0 -1
- package/dist/gateway/server/routing/imageMcpRouter.d.ts +0 -59
- package/dist/gateway/server/routing/imageMcpRouter.d.ts.map +0 -1
- package/dist/gateway/server/routing/imageMcpRouter.js +0 -253
- package/dist/gateway/server/routing/imageMcpRouter.js.map +0 -1
- package/dist/gateway/server/routing/pharoFacade.d.ts +0 -12
- package/dist/gateway/server/routing/pharoFacade.d.ts.map +0 -1
- package/dist/gateway/server/routing/pharoFacade.js +0 -67
- package/dist/gateway/server/routing/pharoFacade.js.map +0 -1
- package/dist/gateway/server/routing/routeDiscovery.d.ts +0 -26
- package/dist/gateway/server/routing/routeDiscovery.d.ts.map +0 -1
- package/dist/gateway/server/routing/routeDiscovery.js +0 -46
- package/dist/gateway/server/routing/routeDiscovery.js.map +0 -1
- package/dist/gateway/server/routing/routingTable.d.ts +0 -120
- package/dist/gateway/server/routing/routingTable.d.ts.map +0 -1
- package/dist/gateway/server/routing/routingTable.js +0 -215
- package/dist/gateway/server/routing/routingTable.js.map +0 -1
- package/dist/gateway/server/support/processLiveness.d.ts +0 -10
- package/dist/gateway/server/support/processLiveness.d.ts.map +0 -1
- package/dist/gateway/server/support/processLiveness.js +0 -25
- package/dist/gateway/server/support/processLiveness.js.map +0 -1
- package/dist/gateway/server/support/sourceBuildPreflight.d.ts +0 -15
- package/dist/gateway/server/support/sourceBuildPreflight.d.ts.map +0 -1
- package/dist/gateway/server/support/sourceBuildPreflight.js +0 -88
- package/dist/gateway/server/support/sourceBuildPreflight.js.map +0 -1
- package/dist/gateway/server/support/toolResultFormatting.d.ts +0 -8
- package/dist/gateway/server/support/toolResultFormatting.d.ts.map +0 -1
- package/dist/gateway/server/support/toolResultFormatting.js +0 -74
- package/dist/gateway/server/support/toolResultFormatting.js.map +0 -1
- package/dist/images/homeImageCache.d.ts +0 -302
- package/dist/images/homeImageCache.d.ts.map +0 -1
- package/dist/images/homeImageCache.js +0 -1031
- package/dist/images/homeImageCache.js.map +0 -1
- package/dist/images/imageRescue.d.ts +0 -151
- package/dist/images/imageRescue.d.ts.map +0 -1
- package/dist/images/imageRescue.js +0 -748
- package/dist/images/imageRescue.js.map +0 -1
- package/dist/images/imageRuntime.d.ts +0 -60
- package/dist/images/imageRuntime.d.ts.map +0 -1
- package/dist/images/imageRuntime.js +0 -90
- package/dist/images/imageRuntime.js.map +0 -1
- package/dist/images/preparedImageCache.d.ts +0 -86
- package/dist/images/preparedImageCache.d.ts.map +0 -1
- package/dist/images/preparedImageCache.js +0 -229
- package/dist/images/preparedImageCache.js.map +0 -1
- package/dist/images/scopedTemplateCatalog.d.ts +0 -33
- package/dist/images/scopedTemplateCatalog.d.ts.map +0 -1
- package/dist/images/scopedTemplateCatalog.js +0 -363
- package/dist/images/scopedTemplateCatalog.js.map +0 -1
- package/dist/internal.d.ts +0 -20
- package/dist/internal.d.ts.map +0 -1
- package/dist/internal.js +0 -20
- package/dist/internal.js.map +0 -1
- package/dist/launcher/scopedPharoLauncherServer.d.ts +0 -349
- package/dist/launcher/scopedPharoLauncherServer.d.ts.map +0 -1
- package/dist/launcher/scopedPharoLauncherServer.js +0 -1307
- package/dist/launcher/scopedPharoLauncherServer.js.map +0 -1
- package/dist/lifecycle/startProjectImage.d.ts +0 -94
- package/dist/lifecycle/startProjectImage.d.ts.map +0 -1
- package/dist/lifecycle/startProjectImage.js +0 -1054
- package/dist/lifecycle/startProjectImage.js.map +0 -1
- package/dist/lifecycle/stopProjectImage.d.ts +0 -31
- package/dist/lifecycle/stopProjectImage.d.ts.map +0 -1
- package/dist/lifecycle/stopProjectImage.js +0 -201
- package/dist/lifecycle/stopProjectImage.js.map +0 -1
- package/dist/mcp/agentServer.d.ts +0 -15
- package/dist/mcp/agentServer.d.ts.map +0 -1
- package/dist/mcp/agentServer.js +0 -67
- package/dist/mcp/agentServer.js.map +0 -1
- package/dist/mcp/imageOperations.d.ts +0 -54
- package/dist/mcp/imageOperations.d.ts.map +0 -1
- package/dist/mcp/imageOperations.js +0 -223
- package/dist/mcp/imageOperations.js.map +0 -1
- package/dist/mcp/pharoMcpHealth.d.ts +0 -26
- package/dist/mcp/pharoMcpHealth.d.ts.map +0 -1
- package/dist/mcp/pharoMcpHealth.js +0 -97
- package/dist/mcp/pharoMcpHealth.js.map +0 -1
- package/dist/support/pathStyle.d.ts +0 -11
- package/dist/support/pathStyle.d.ts.map +0 -1
- package/dist/support/pathStyle.js +0 -61
- package/dist/support/pathStyle.js.map +0 -1
- package/dist/support/toolResultFormatting.d.ts +0 -8
- package/dist/support/toolResultFormatting.d.ts.map +0 -1
- package/dist/support/toolResultFormatting.js +0 -74
- package/dist/support/toolResultFormatting.js.map +0 -1
- package/dist/workspace/projectStartupScript.d.ts +0 -73
- package/dist/workspace/projectStartupScript.d.ts.map +0 -1
- package/dist/workspace/projectStartupScript.js +0 -607
- package/dist/workspace/projectStartupScript.js.map +0 -1
- package/dist/workspace/projectState.d.ts +0 -216
- package/dist/workspace/projectState.d.ts.map +0 -1
- package/dist/workspace/projectState.js +0 -172
- package/dist/workspace/projectState.js.map +0 -1
- /package/dist/{gateway/server/routing → forward}/endpointHandoffFormat.js +0 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `plexus` command: the image verbs over the library, and `plexus mcp`.
|
|
3
|
+
* Every result is JSON on stdout; a refusal is `{"ok":false,...}` there too,
|
|
4
|
+
* with exit status 1, and a command line it cannot read exits with 2.
|
|
5
|
+
*/
|
|
6
|
+
import { PlexusError } from "./errors.js";
|
|
7
|
+
import { plexusTelemetry } from "./images/context.js";
|
|
8
|
+
import { Images } from "./images/index.js";
|
|
9
|
+
import { imageTools, runPlexusMcpServer } from "./mcp/server.js";
|
|
10
|
+
const defaultDependencies = {
|
|
11
|
+
images: (options) => new Images(options),
|
|
12
|
+
serveMcp: (images) => runPlexusMcpServer({ images }),
|
|
13
|
+
};
|
|
14
|
+
const globalUsage = "[--home <dir>] [--scope <prefix>] [--telemetry]";
|
|
15
|
+
const imageCommands = {
|
|
16
|
+
templates: {
|
|
17
|
+
usage: "plexus image templates",
|
|
18
|
+
summary: "List the templates an image can be created from.",
|
|
19
|
+
values: [],
|
|
20
|
+
flags: [],
|
|
21
|
+
positionals: { min: 0, max: 0 },
|
|
22
|
+
},
|
|
23
|
+
create: {
|
|
24
|
+
usage: "plexus image create <name> --template <t> [--category <c>] [--script <file> [--every-start]]",
|
|
25
|
+
summary: "Create an image with MCP in it, not started. A script is filed in instead of loading the pinned MCP; --every-start files it in at every start too.",
|
|
26
|
+
values: ["template", "category", "script"],
|
|
27
|
+
flags: ["every-start"],
|
|
28
|
+
positionals: { min: 1, max: 1 },
|
|
29
|
+
},
|
|
30
|
+
start: {
|
|
31
|
+
usage: "plexus image start <name> [--display interactive] [--timeout <seconds>]",
|
|
32
|
+
summary: "Start an image and wait until its MCP server answers. Refused while it runs.",
|
|
33
|
+
values: ["display", "timeout"],
|
|
34
|
+
flags: [],
|
|
35
|
+
positionals: { min: 1, max: 1 },
|
|
36
|
+
},
|
|
37
|
+
stop: {
|
|
38
|
+
usage: "plexus image stop <name> [--save]",
|
|
39
|
+
summary: "Kill every VM running the image, without saving. With --save, the image saves itself and quits instead; one that does not in time is left running.",
|
|
40
|
+
values: [],
|
|
41
|
+
flags: ["save"],
|
|
42
|
+
positionals: { min: 1, max: 1 },
|
|
43
|
+
},
|
|
44
|
+
delete: {
|
|
45
|
+
usage: "plexus image delete <name>",
|
|
46
|
+
summary: "Delete the image's directory. Refused while it runs.",
|
|
47
|
+
values: [],
|
|
48
|
+
flags: [],
|
|
49
|
+
positionals: { min: 1, max: 1 },
|
|
50
|
+
},
|
|
51
|
+
list: {
|
|
52
|
+
usage: "plexus image list [<name>]",
|
|
53
|
+
summary: "List the images and whether each runs, or only the one named.",
|
|
54
|
+
values: [],
|
|
55
|
+
flags: [],
|
|
56
|
+
positionals: { min: 0, max: 1 },
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const mcpCommand = {
|
|
60
|
+
usage: "plexus mcp",
|
|
61
|
+
summary: "Serve the image tools and the running images' own tools over stdio, in the scope given at launch.",
|
|
62
|
+
values: [],
|
|
63
|
+
flags: [],
|
|
64
|
+
positionals: { min: 0, max: 0 },
|
|
65
|
+
};
|
|
66
|
+
class UsageError extends Error {
|
|
67
|
+
usage;
|
|
68
|
+
constructor(message, usage) {
|
|
69
|
+
super(message);
|
|
70
|
+
this.usage = usage;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function parse(args, spec) {
|
|
74
|
+
const values = new Map();
|
|
75
|
+
const flags = new Set();
|
|
76
|
+
const positionals = [];
|
|
77
|
+
let help = false;
|
|
78
|
+
const allowedValues = new Set(["home", "scope", ...spec.values]);
|
|
79
|
+
const allowedFlags = new Set(["telemetry", ...spec.flags]);
|
|
80
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
81
|
+
const arg = args[index];
|
|
82
|
+
if (arg === "--help" || arg === "-h") {
|
|
83
|
+
help = true;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (!arg.startsWith("--")) {
|
|
87
|
+
positionals.push(arg);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const [option, inline] = splitOption(arg.slice(2));
|
|
91
|
+
if (allowedFlags.has(option)) {
|
|
92
|
+
if (inline !== undefined) {
|
|
93
|
+
throw new UsageError(`--${option} takes no value`, spec.usage);
|
|
94
|
+
}
|
|
95
|
+
flags.add(option);
|
|
96
|
+
}
|
|
97
|
+
else if (allowedValues.has(option)) {
|
|
98
|
+
const value = inline ?? args[++index];
|
|
99
|
+
if (value === undefined || (inline === undefined && value.startsWith("--"))) {
|
|
100
|
+
throw new UsageError(`--${option} needs a value`, spec.usage);
|
|
101
|
+
}
|
|
102
|
+
values.set(option, value);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
throw new UsageError(`Unknown option --${option}`, spec.usage);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (!help) {
|
|
109
|
+
if (positionals.length < spec.positionals.min) {
|
|
110
|
+
throw new UsageError("Missing the image name", spec.usage);
|
|
111
|
+
}
|
|
112
|
+
if (positionals.length > spec.positionals.max) {
|
|
113
|
+
throw new UsageError(`Unexpected argument ${positionals[spec.positionals.max]}`, spec.usage);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return { positionals, values, flags, help };
|
|
117
|
+
}
|
|
118
|
+
function splitOption(option) {
|
|
119
|
+
const equals = option.indexOf("=");
|
|
120
|
+
return equals < 0 ? [option, undefined] : [option.slice(0, equals), option.slice(equals + 1)];
|
|
121
|
+
}
|
|
122
|
+
function imagesOptions(parsed, env) {
|
|
123
|
+
const home = parsed.values.get("home") ?? env.PLEXUS_HOME;
|
|
124
|
+
const scope = parsed.values.get("scope") ?? env.PLEXUS_SCOPE;
|
|
125
|
+
return {
|
|
126
|
+
...(home ? { home } : {}),
|
|
127
|
+
// An empty scope goes on to be refused: dropped, it would mean none, and
|
|
128
|
+
// none reaches every image in the store.
|
|
129
|
+
...(scope === undefined ? {} : { scope }),
|
|
130
|
+
...(parsed.flags.has("telemetry") || plexusTelemetry(env) ? { telemetry: true } : {}),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function startOptions(parsed, usage) {
|
|
134
|
+
const display = parsed.values.get("display");
|
|
135
|
+
if (display !== undefined && display !== "headless" && display !== "interactive") {
|
|
136
|
+
throw new UsageError("--display is headless or interactive", usage);
|
|
137
|
+
}
|
|
138
|
+
const timeout = parsed.values.get("timeout");
|
|
139
|
+
const seconds = timeout === undefined ? undefined : Number(timeout);
|
|
140
|
+
if (seconds !== undefined && !(Number.isFinite(seconds) && seconds > 0)) {
|
|
141
|
+
throw new UsageError("--timeout is a number of seconds", usage);
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
...(display === undefined ? {} : { display }),
|
|
145
|
+
...(seconds === undefined ? {} : { timeoutMs: Math.round(seconds * 1000) }),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function help() {
|
|
149
|
+
return [
|
|
150
|
+
"Usage:",
|
|
151
|
+
...Object.values(imageCommands).map((spec) => ` ${spec.usage}`),
|
|
152
|
+
` ${mcpCommand.usage}`,
|
|
153
|
+
"",
|
|
154
|
+
`Every command takes ${globalUsage}.`,
|
|
155
|
+
" --home where images, VMs and templates live (PLEXUS_HOME; ~/.plexus)",
|
|
156
|
+
" --scope a name prefix, without dashes: image dev is the directory <scope>-dev (PLEXUS_SCOPE)",
|
|
157
|
+
" --telemetry enroll images in OpenTelemetry: a create loads MCP's Telemetry group, and a",
|
|
158
|
+
" start switches the image's server to it, configured by the OTEL_* environment",
|
|
159
|
+
" (PLEXUS_TELEMETRY=1). With no OTEL_* in the environment, the settings file",
|
|
160
|
+
" ~/.config/pharo-agent/otel.env gives them, and turns this on unless",
|
|
161
|
+
" PLEXUS_TELEMETRY is set",
|
|
162
|
+
"",
|
|
163
|
+
"Results are JSON on stdout. A refusal is {\"ok\":false,\"code\":...,\"error\":...} and exits 1.",
|
|
164
|
+
].join("\n");
|
|
165
|
+
}
|
|
166
|
+
function commandHelp(spec) {
|
|
167
|
+
return [`Usage: ${spec.usage} ${globalUsage}`, "", spec.summary].join("\n");
|
|
168
|
+
}
|
|
169
|
+
export async function runCli(argv, io, dependencies = defaultDependencies) {
|
|
170
|
+
const print = (value) => io.stdout(`${JSON.stringify(value, null, 2)}\n`);
|
|
171
|
+
try {
|
|
172
|
+
const [noun, verb, ...rest] = argv;
|
|
173
|
+
if (noun === undefined || noun === "--help" || noun === "-h") {
|
|
174
|
+
(noun === undefined ? io.stderr : io.stdout)(`${help()}\n`);
|
|
175
|
+
return noun === undefined ? 2 : 0;
|
|
176
|
+
}
|
|
177
|
+
if (noun === "mcp") {
|
|
178
|
+
const parsed = parse(argv.slice(1), mcpCommand);
|
|
179
|
+
if (parsed.help) {
|
|
180
|
+
io.stdout(`${commandHelp(mcpCommand)}\n`);
|
|
181
|
+
return 0;
|
|
182
|
+
}
|
|
183
|
+
await dependencies.serveMcp(dependencies.images(imagesOptions(parsed, io.env)));
|
|
184
|
+
return 0;
|
|
185
|
+
}
|
|
186
|
+
// A refusal names the MCP tool that resolves it, which is a command here.
|
|
187
|
+
if (imageTools.some((tool) => tool.name === noun)) {
|
|
188
|
+
const command = noun.slice("image_".length);
|
|
189
|
+
throw new UsageError(`${noun} is plexus image ${command} here.`, imageCommands[command].usage);
|
|
190
|
+
}
|
|
191
|
+
if (noun !== "image") {
|
|
192
|
+
throw new UsageError(`Unknown command ${noun}`, help());
|
|
193
|
+
}
|
|
194
|
+
if (verb === undefined || verb === "--help" || verb === "-h") {
|
|
195
|
+
(verb === undefined ? io.stderr : io.stdout)(`${help()}\n`);
|
|
196
|
+
return verb === undefined ? 2 : 0;
|
|
197
|
+
}
|
|
198
|
+
if (!(verb in imageCommands)) {
|
|
199
|
+
throw new UsageError(`Unknown image command ${verb}`, help());
|
|
200
|
+
}
|
|
201
|
+
const spec = imageCommands[verb];
|
|
202
|
+
const parsed = parse(rest, spec);
|
|
203
|
+
if (parsed.help) {
|
|
204
|
+
io.stdout(`${commandHelp(spec)}\n`);
|
|
205
|
+
return 0;
|
|
206
|
+
}
|
|
207
|
+
const images = dependencies.images(imagesOptions(parsed, io.env));
|
|
208
|
+
const [name] = parsed.positionals;
|
|
209
|
+
switch (verb) {
|
|
210
|
+
case "templates":
|
|
211
|
+
print(await images.templates());
|
|
212
|
+
break;
|
|
213
|
+
case "create": {
|
|
214
|
+
const template = parsed.values.get("template");
|
|
215
|
+
if (template === undefined) {
|
|
216
|
+
throw new UsageError("create needs --template", spec.usage);
|
|
217
|
+
}
|
|
218
|
+
const category = parsed.values.get("category");
|
|
219
|
+
const script = parsed.values.get("script");
|
|
220
|
+
print(await images.create(name, {
|
|
221
|
+
template,
|
|
222
|
+
...(category === undefined ? {} : { category }),
|
|
223
|
+
...(script === undefined ? {} : { script }),
|
|
224
|
+
...(parsed.flags.has("every-start") ? { everyStart: true } : {}),
|
|
225
|
+
}));
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
case "start":
|
|
229
|
+
print(await images.start(name, startOptions(parsed, spec.usage)));
|
|
230
|
+
break;
|
|
231
|
+
case "stop":
|
|
232
|
+
print(await images.stop(name, parsed.flags.has("save") ? { save: true } : {}));
|
|
233
|
+
break;
|
|
234
|
+
case "delete":
|
|
235
|
+
print(await images.delete(name));
|
|
236
|
+
break;
|
|
237
|
+
case "list":
|
|
238
|
+
print(await images.list(name));
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
return 0;
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
if (error instanceof UsageError) {
|
|
245
|
+
io.stderr(`plexus: ${error.message}\n\n${error.usage}\n`);
|
|
246
|
+
return 2;
|
|
247
|
+
}
|
|
248
|
+
print(error instanceof PlexusError
|
|
249
|
+
? {
|
|
250
|
+
ok: false,
|
|
251
|
+
code: error.code,
|
|
252
|
+
error: error.message,
|
|
253
|
+
...(error.details ? { details: error.details } : {}),
|
|
254
|
+
}
|
|
255
|
+
: { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
256
|
+
return 1;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=commandLine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandLine.js","sourceRoot":"","sources":["../src/commandLine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAkB,MAAM,iBAAiB,CAAC;AAcjF,MAAM,mBAAmB,GAAoB;IAC3C,MAAM,EAAE,CAAC,OAA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AAO,CAAC,CAAC;QACX,CAAC;QACD,KAAK,CACH,KAAK,YAAY,WAAW;YAC1B,CAAC,CAAC;gBACE,EAAE,EAAE,KAAK;gBACT,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,KAAK,EAAE,KAAK,CAAC,OAAO;gBACpB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACrD;YACH,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACjF,CAAC;QACF,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
2
|
+
* The MCP release PLexus loads into an image that is created without a
|
|
3
|
+
* script.
|
|
4
4
|
*
|
|
5
|
-
* It
|
|
6
|
-
* checks across the package boundary
|
|
7
|
-
*
|
|
8
|
-
* internal, and nothing about publishing this should drag that along.
|
|
5
|
+
* It is a module of its own because `pharo-agent` pins the same version and
|
|
6
|
+
* checks across the package boundary that the two agree, and because the
|
|
7
|
+
* release workflows read and rewrite it here.
|
|
9
8
|
*/
|
|
10
|
-
export declare const defaultPharoMcpVersion = "
|
|
9
|
+
export declare const defaultPharoMcpVersion = "4.1.2";
|
|
11
10
|
//# sourceMappingURL=pharoMcpVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pharoMcpVersion.d.ts","sourceRoot":"","sources":["../../src/config/pharoMcpVersion.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"pharoMcpVersion.d.ts","sourceRoot":"","sources":["../../src/config/pharoMcpVersion.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,UAAU,CAAC"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
2
|
+
* The MCP release PLexus loads into an image that is created without a
|
|
3
|
+
* script.
|
|
4
4
|
*
|
|
5
|
-
* It
|
|
6
|
-
* checks across the package boundary
|
|
7
|
-
*
|
|
8
|
-
* internal, and nothing about publishing this should drag that along.
|
|
5
|
+
* It is a module of its own because `pharo-agent` pins the same version and
|
|
6
|
+
* checks across the package boundary that the two agree, and because the
|
|
7
|
+
* release workflows read and rewrite it here.
|
|
9
8
|
*/
|
|
10
|
-
export const defaultPharoMcpVersion = "
|
|
9
|
+
export const defaultPharoMcpVersion = "4.1.2";
|
|
11
10
|
//# sourceMappingURL=pharoMcpVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pharoMcpVersion.js","sourceRoot":"","sources":["../../src/config/pharoMcpVersion.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"pharoMcpVersion.js","sourceRoot":"","sources":["../../src/config/pharoMcpVersion.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAO,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type PlexusErrorCode = "invalid-name" | "no-such-image" | "image-exists" | "image-running" | "being-started" | "building" | "not-running" | "no-endpoint" | "unknown-template" | "ambiguous-template" | "script-not-found" | "create-failed" | "start-failed" | "stop-failed" | "save-failed" | "stopped-unsaved" | "launcher-failed";
|
|
2
|
+
/**
|
|
3
|
+
* Every refusal PLexus makes. The code is what a caller branches on; the
|
|
4
|
+
* message is what it shows, and says what to do where there is something.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PlexusError extends Error {
|
|
7
|
+
readonly code: PlexusErrorCode;
|
|
8
|
+
readonly details?: Record<string, unknown>;
|
|
9
|
+
constructor(code: PlexusErrorCode, message: string, details?: Record<string, unknown>);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GACvB,cAAc,GACd,eAAe,GACf,cAAc,GACd,eAAe,GACf,eAAe,GACf,UAAU,GACV,aAAa,GACb,aAAa,GACb,kBAAkB,GAClB,oBAAoB,GACpB,kBAAkB,GAClB,eAAe,GACf,cAAc,GACd,aAAa,GAGb,aAAa,GACb,iBAAiB,GACjB,iBAAiB,CAAC;AAEtB;;;GAGG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAGzC,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CASpC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every refusal PLexus makes. The code is what a caller branches on; the
|
|
3
|
+
* message is what it shows, and says what to do where there is something.
|
|
4
|
+
*/
|
|
5
|
+
export class PlexusError extends Error {
|
|
6
|
+
code;
|
|
7
|
+
details;
|
|
8
|
+
constructor(code, message, details) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "PlexusError";
|
|
11
|
+
this.code = code;
|
|
12
|
+
if (details !== undefined) {
|
|
13
|
+
this.details = details;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAqBA;;;GAGG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,IAAI,CAAkB;IACtB,OAAO,CAA2B;IAE3C,YACE,IAAqB,EACrB,OAAe,EACf,OAAiC;QAEjC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACzB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The endpoint handoff format: `plexus/endpoint.properties`, written by an
|
|
3
|
+
* image's VM once its MCP server has bound a port.
|
|
4
|
+
*
|
|
5
|
+
* Strict on purpose: a port of `08080` or `8080abc` is refused rather than
|
|
6
|
+
* read as something, because forwarding to a guess sends tool calls to
|
|
7
|
+
* whatever else holds that port.
|
|
8
|
+
*/
|
|
9
|
+
export interface EndpointHandoff {
|
|
10
|
+
transport: "http";
|
|
11
|
+
host: string;
|
|
12
|
+
port: number;
|
|
13
|
+
path: string;
|
|
14
|
+
/**
|
|
15
|
+
* The process that bound the port, when the image could tell. A port
|
|
16
|
+
* outlives the process that bound it, so this is what separates an endpoint
|
|
17
|
+
* from the memory of one. Images that cannot tell their own pid write no
|
|
18
|
+
* pid line, and a reader without one has only the port to go on.
|
|
19
|
+
*/
|
|
20
|
+
pid?: number;
|
|
21
|
+
}
|
|
22
|
+
export declare function parseEndpointHandoff(source: string): EndpointHandoff;
|
|
23
|
+
//# sourceMappingURL=endpointHandoffFormat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpointHandoffFormat.d.ts","sourceRoot":"","sources":["../../src/forward/endpointHandoffFormat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;I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CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forwarding: one JSON-RPC request to an image's endpoint per call. Nothing
|
|
3
|
+
* is cached, so nothing can name an image that has since stopped.
|
|
4
|
+
*/
|
|
5
|
+
import type { CallToolResult, Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import type { Endpoint } from "../types.js";
|
|
7
|
+
export declare function listTools(endpoint: Endpoint, options?: {
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
}): Promise<Tool[]>;
|
|
10
|
+
export interface CallToolOptions {
|
|
11
|
+
/**
|
|
12
|
+
* One wait for each of the two requests, in place of the waits below. A
|
|
13
|
+
* handshake that times out under it is passed over, and the call is still
|
|
14
|
+
* sent.
|
|
15
|
+
*/
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
/** The schema the image listed for the tool: its `timeoutSeconds` gives the call's limit and the most it may be. */
|
|
18
|
+
inputSchema?: Tool["inputSchema"];
|
|
19
|
+
/** What the handshake waits, and the least the call waits: 60000 unless given. */
|
|
20
|
+
minimumMs?: number;
|
|
21
|
+
/** Aborting it destroys the request in flight, and the call rejects as cancelled. */
|
|
22
|
+
signal?: AbortSignal;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* One call, answered by the tool's result as the image sent it. The call
|
|
26
|
+
* waits longer than any limit the image keeps itself, so that its own answer
|
|
27
|
+
* to a call it stopped arrives first: see `callWaitMs`. Unless `timeoutMs` is
|
|
28
|
+
* given, a handshake the image does not answer fails the call before it is
|
|
29
|
+
* sent.
|
|
30
|
+
*
|
|
31
|
+
* It rejects with a `ForwardError`, whose `kind` says whether the image
|
|
32
|
+
* answered, never got the call, or got it and gave no answer.
|
|
33
|
+
*/
|
|
34
|
+
export declare function callTool(endpoint: Endpoint, name: string, args?: Record<string, unknown>, options?: CallToolOptions): Promise<CallToolResult>;
|
|
35
|
+
/**
|
|
36
|
+
* How long a call waits for its answer: the larger of the minimum and the
|
|
37
|
+
* call's time limit plus 30 s. The limit is the call's own `timeoutSeconds`
|
|
38
|
+
* when it is a number of 0 or more, otherwise the default of `timeoutSeconds`
|
|
39
|
+
* in the schema the image listed; with neither, the call waits the minimum.
|
|
40
|
+
* The limit is never more than the `maximum` that schema lists, since the
|
|
41
|
+
* image does not work past it, and no wait is longer than Node's timers
|
|
42
|
+
* keep. Exported for tests only.
|
|
43
|
+
*/
|
|
44
|
+
export declare function callWaitMs(args: Record<string, unknown>, options?: Pick<CallToolOptions, "inputSchema" | "minimumMs">): number;
|
|
45
|
+
/**
|
|
46
|
+
* The tool an image runs Smalltalk with, as it lists it: `evaluate`, or
|
|
47
|
+
* `image_evaluate` in an image whose MCP predates the rename. An image that
|
|
48
|
+
* lists neither has an MCP older still, which held `image_evaluate` without
|
|
49
|
+
* listing it.
|
|
50
|
+
*/
|
|
51
|
+
export declare function evaluationTool(tools: ReadonlyArray<{
|
|
52
|
+
name: string;
|
|
53
|
+
}>): string;
|
|
54
|
+
/**
|
|
55
|
+
* Whether an MCP server answers there. Any JSON-RPC answer to `ping` counts,
|
|
56
|
+
* whatever its HTTP status: a server that wants a session first refuses the
|
|
57
|
+
* ping, and refusing it is answering. A server that does not speak JSON-RPC
|
|
58
|
+
* there may still answer `/health`.
|
|
59
|
+
*/
|
|
60
|
+
export declare function ping(endpoint: Endpoint, timeoutMs?: number): Promise<boolean>;
|
|
61
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/forward/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAA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s = 60_000;
|
|
3
|
+
/** What a call waits beyond its own time limit, so that the image's answer to a call it stopped arrives first. */
|
|
4
|
+
const beyondLimitMs = 30_000;
|
|
5
|
+
/** The longest wait Node's timers keep, about 24.8 days: a longer one is cut to it with a warning, and an infinite one throws. */
|
|
6
|
+
const longestWaitMs = 2 ** 31 - 1;
|
|
7
|
+
export async function listTools(endpoint, options = {}) {
|
|
8
|
+
const timeoutMs = options.timeoutMs ?? defaultTimeoutMs;
|
|
9
|
+
const session = await initialize(endpoint.url, timeoutMs);
|
|
10
|
+
const response = await request(endpoint.url, "tools/list", undefined, {
|
|
11
|
+
timeoutMs,
|
|
12
|
+
session,
|
|
13
|
+
});
|
|
14
|
+
const result = response.result;
|
|
15
|
+
if (!isRecord(result) || !Array.isArray(result.tools)) {
|
|
16
|
+
throw new Error("MCP tools/list response did not include result.tools");
|
|
17
|
+
}
|
|
18
|
+
return result.tools.map((tool, index) => checkedTool(tool, index));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* One call, answered by the tool's result as the image sent it. The call
|
|
22
|
+
* waits longer than any limit the image keeps itself, so that its own answer
|
|
23
|
+
* to a call it stopped arrives first: see `callWaitMs`. Unless `timeoutMs` is
|
|
24
|
+
* given, a handshake the image does not answer fails the call before it is
|
|
25
|
+
* sent.
|
|
26
|
+
*
|
|
27
|
+
* It rejects with a `ForwardError`, whose `kind` says whether the image
|
|
28
|
+
* answered, never got the call, or got it and gave no answer.
|
|
29
|
+
*/
|
|
30
|
+
export async function callTool(endpoint, name, args = {}, options = {}) {
|
|
31
|
+
const handshakeMs = options.timeoutMs ?? Math.min(options.minimumMs ?? defaultTimeoutMs, longestWaitMs);
|
|
32
|
+
const session = await initialize(endpoint.url, handshakeMs, {
|
|
33
|
+
failOnTimeout: options.timeoutMs === undefined,
|
|
34
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
35
|
+
});
|
|
36
|
+
const response = await request(endpoint.url, "tools/call", { name, arguments: args }, {
|
|
37
|
+
timeoutMs: options.timeoutMs ?? callWaitMs(args, options),
|
|
38
|
+
session,
|
|
39
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
40
|
+
});
|
|
41
|
+
return response.result;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* How long a call waits for its answer: the larger of the minimum and the
|
|
45
|
+
* call's time limit plus 30 s. The limit is the call's own `timeoutSeconds`
|
|
46
|
+
* when it is a number of 0 or more, otherwise the default of `timeoutSeconds`
|
|
47
|
+
* in the schema the image listed; with neither, the call waits the minimum.
|
|
48
|
+
* The limit is never more than the `maximum` that schema lists, since the
|
|
49
|
+
* image does not work past it, and no wait is longer than Node's timers
|
|
50
|
+
* keep. Exported for tests only.
|
|
51
|
+
*/
|
|
52
|
+
export function callWaitMs(args, options = {}) {
|
|
53
|
+
const minimumMs = options.minimumMs ?? defaultTimeoutMs;
|
|
54
|
+
const listed = listedTimeLimit(options.inputSchema);
|
|
55
|
+
const limitSeconds = timeLimit(args.timeoutSeconds) ?? timeLimit(listed.default);
|
|
56
|
+
const waitMs = limitSeconds === undefined
|
|
57
|
+
? minimumMs
|
|
58
|
+
: Math.max(minimumMs, Math.min(limitSeconds, timeLimit(listed.maximum) ?? Infinity) * 1000 + beyondLimitMs);
|
|
59
|
+
return Math.min(waitMs, longestWaitMs);
|
|
60
|
+
}
|
|
61
|
+
function timeLimit(value) {
|
|
62
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
63
|
+
}
|
|
64
|
+
function listedTimeLimit(inputSchema) {
|
|
65
|
+
const property = inputSchema?.properties?.timeoutSeconds;
|
|
66
|
+
return isRecord(property) ? property : {};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The tool an image runs Smalltalk with, as it lists it: `evaluate`, or
|
|
70
|
+
* `image_evaluate` in an image whose MCP predates the rename. An image that
|
|
71
|
+
* lists neither has an MCP older still, which held `image_evaluate` without
|
|
72
|
+
* listing it.
|
|
73
|
+
*/
|
|
74
|
+
export function evaluationTool(tools) {
|
|
75
|
+
return (tools.find((tool) => tool.name === "evaluate") ??
|
|
76
|
+
tools.find((tool) => tool.name === "image_evaluate"))?.name ?? "image_evaluate";
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Whether an MCP server answers there. Any JSON-RPC answer to `ping` counts,
|
|
80
|
+
* whatever its HTTP status: a server that wants a session first refuses the
|
|
81
|
+
* ping, and refusing it is answering. A server that does not speak JSON-RPC
|
|
82
|
+
* there may still answer `/health`.
|
|
83
|
+
*/
|
|
84
|
+
export async function ping(endpoint, timeoutMs = 1_000) {
|
|
85
|
+
try {
|
|
86
|
+
const answer = await fetchWithin(timeoutMs, endpoint.url, {
|
|
87
|
+
method: "POST",
|
|
88
|
+
headers: {
|
|
89
|
+
accept: "application/json, text/event-stream",
|
|
90
|
+
"content-type": "application/json",
|
|
91
|
+
},
|
|
92
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: "plexus-ping", method: "ping" }),
|
|
93
|
+
});
|
|
94
|
+
const payload = await answer.json().catch(() => undefined);
|
|
95
|
+
if (isRecord(payload) &&
|
|
96
|
+
payload.jsonrpc === "2.0" &&
|
|
97
|
+
("result" in payload || "error" in payload)) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// Not listening yet.
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
return (await fetchWithin(timeoutMs, new URL("/health", endpoint.url).href)).ok;
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function fetchWithin(timeoutMs, url, init = {}) {
|
|
112
|
+
const controller = new AbortController();
|
|
113
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
114
|
+
try {
|
|
115
|
+
return await fetch(url, { ...init, signal: controller.signal });
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
clearTimeout(timeout);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function checkedTool(value, index) {
|
|
122
|
+
if (!isRecord(value) || typeof value.name !== "string") {
|
|
123
|
+
throw new Error(`MCP tools/list returned an invalid tool at index ${index}`);
|
|
124
|
+
}
|
|
125
|
+
if (!isRecord(value.inputSchema)) {
|
|
126
|
+
throw new Error(`MCP tools/list returned tool ${value.name} without an inputSchema object`);
|
|
127
|
+
}
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
function isRecord(value) {
|
|
131
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/forward/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEnD,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,kHAAkH;AAClH,MAAM,aAAa,GAAG,MAAM,CAAC;AAE7B,kIAAkI;AAClI,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAElC,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,QAAkB,EAClB,UAAkC,EAAE;IAEpC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,gBAAgB,CAAC;IACxD,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAC1D,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE;QACpE,SAAS;QACT,OAAO;KACR,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC/B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,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