@introspection-ai/recipes 0.43.0 → 0.45.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/dist/agents.d.ts.map +1 -1
- package/dist/agents.js +11 -4
- package/dist/agents.js.map +1 -1
- package/dist/api/session.d.ts +2 -1
- package/dist/api/session.d.ts.map +1 -1
- package/dist/artifact-review-tui.d.ts +0 -2
- package/dist/artifact-review-tui.d.ts.map +1 -1
- package/dist/artifact-review-tui.js +1 -1
- package/dist/artifact-review-tui.js.map +1 -1
- package/dist/artifact-review.d.ts +30 -13
- package/dist/artifact-review.d.ts.map +1 -1
- package/dist/artifact-review.js +80 -12
- package/dist/artifact-review.js.map +1 -1
- package/dist/artifact-viewer-tui.d.ts.map +1 -1
- package/dist/artifact-viewer-tui.js.map +1 -1
- package/dist/artifact-viewer.d.ts +1 -63
- package/dist/artifact-viewer.d.ts.map +1 -1
- package/dist/artifact-viewer.js +6 -9
- package/dist/artifact-viewer.js.map +1 -1
- package/dist/ask-user-question.d.ts +0 -32
- package/dist/ask-user-question.d.ts.map +1 -1
- package/dist/ask-user-question.js +9 -5
- package/dist/ask-user-question.js.map +1 -1
- package/dist/channels/index.d.ts +1 -1
- package/dist/channels/index.d.ts.map +1 -1
- package/dist/channels/index.js +1 -1
- package/dist/channels/index.js.map +1 -1
- package/dist/channels/module.d.ts.map +1 -1
- package/dist/channels/module.js +15 -5
- package/dist/channels/module.js.map +1 -1
- package/dist/channels/refs.d.ts.map +1 -1
- package/dist/channels/refs.js +10 -2
- package/dist/channels/refs.js.map +1 -1
- package/dist/channels/tools.d.ts.map +1 -1
- package/dist/channels/tools.js +80 -36
- package/dist/channels/tools.js.map +1 -1
- package/dist/child/agent-completions.d.ts.map +1 -1
- package/dist/child/agent-completions.js +3 -1
- package/dist/child/agent-completions.js.map +1 -1
- package/dist/child/agent-store.d.ts +3 -2
- package/dist/child/agent-store.d.ts.map +1 -1
- package/dist/child/agent-store.js.map +1 -1
- package/dist/child/agent.d.ts.map +1 -1
- package/dist/child/agent.js +1 -3
- package/dist/child/agent.js.map +1 -1
- package/dist/child/session.d.ts +2 -2
- package/dist/child/session.d.ts.map +1 -1
- package/dist/child/session.js +1 -3
- package/dist/child/session.js.map +1 -1
- package/dist/connector-tools.d.ts +5 -4
- package/dist/connector-tools.d.ts.map +1 -1
- package/dist/connector-tools.js +19 -9
- package/dist/connector-tools.js.map +1 -1
- package/dist/documents/index.d.ts +3 -3
- package/dist/documents/index.d.ts.map +1 -1
- package/dist/documents/index.js +1 -1
- package/dist/documents/index.js.map +1 -1
- package/dist/documents/module.d.ts +0 -2
- package/dist/documents/module.d.ts.map +1 -1
- package/dist/documents/module.js +30 -11
- package/dist/documents/module.js.map +1 -1
- package/dist/documents/profile.d.ts.map +1 -1
- package/dist/documents/profile.js +10 -4
- package/dist/documents/profile.js.map +1 -1
- package/dist/documents/python.d.ts.map +1 -1
- package/dist/documents/python.js +12 -3
- package/dist/documents/python.js.map +1 -1
- package/dist/documents/tools.d.ts.map +1 -1
- package/dist/documents/tools.js +105 -29
- package/dist/documents/tools.js.map +1 -1
- package/dist/documents/types.d.ts.map +1 -1
- package/dist/extensions.d.ts.map +1 -1
- package/dist/extensions.js +6 -2
- package/dist/extensions.js.map +1 -1
- package/dist/genai-spans-file.d.ts +1 -14
- package/dist/genai-spans-file.d.ts.map +1 -1
- package/dist/genai-spans-file.js +5 -3
- package/dist/genai-spans-file.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/inspect.d.ts.map +1 -1
- package/dist/inspect.js +2 -3
- package/dist/inspect.js.map +1 -1
- package/dist/interaction-tui.d.ts +0 -2
- package/dist/interaction-tui.d.ts.map +1 -1
- package/dist/interaction-tui.js +9 -4
- package/dist/interaction-tui.js.map +1 -1
- package/dist/interactions.d.ts.map +1 -1
- package/dist/interactions.js +1 -3
- package/dist/interactions.js.map +1 -1
- package/dist/mcp/catalog.d.ts.map +1 -1
- package/dist/mcp/catalog.js.map +1 -1
- package/dist/mcp/cli/command-context.d.ts.map +1 -1
- package/dist/mcp/cli/command-context.js.map +1 -1
- package/dist/mcp/cli/core.d.ts +0 -41
- package/dist/mcp/cli/core.d.ts.map +1 -1
- package/dist/mcp/cli/core.js +79 -37
- package/dist/mcp/cli/core.js.map +1 -1
- package/dist/mcp/cli/help.js +3 -3
- package/dist/mcp/cli/help.js.map +1 -1
- package/dist/mcp/cli/index.js.map +1 -1
- package/dist/mcp/cli/policy.d.ts +2 -1
- package/dist/mcp/cli/policy.d.ts.map +1 -1
- package/dist/mcp/cli/policy.js +19 -11
- package/dist/mcp/cli/policy.js.map +1 -1
- package/dist/mcp/client-entry.js.map +1 -1
- package/dist/mcp/contract.d.ts.map +1 -1
- package/dist/mcp/contract.js +8 -3
- package/dist/mcp/contract.js.map +1 -1
- package/dist/mcp/daemon/client.d.ts +4 -0
- package/dist/mcp/daemon/client.d.ts.map +1 -1
- package/dist/mcp/daemon/client.js +4 -0
- package/dist/mcp/daemon/client.js.map +1 -1
- package/dist/mcp/daemon/index.js +9 -4
- package/dist/mcp/daemon/index.js.map +1 -1
- package/dist/mcp/daemon/protocol.d.ts +7 -6
- package/dist/mcp/daemon/protocol.d.ts.map +1 -1
- package/dist/mcp/index.d.ts +2 -6
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +36 -20
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/tools.d.ts +1 -14
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +9 -4
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp-chunks/{chunk-EZKOZO3F.js → chunk-3M4OCQR5.js} +179 -70
- package/dist/mcp-daemon.js +29 -19
- package/dist/mcp-run-worker.js +1 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +1 -1
- package/dist/memory.js.map +1 -1
- package/dist/model-binding.d.ts +4 -5
- package/dist/model-binding.d.ts.map +1 -1
- package/dist/model-binding.js +5 -5
- package/dist/model-binding.js.map +1 -1
- package/dist/pi-extension.d.ts.map +1 -1
- package/dist/pi-extension.js +39 -33
- package/dist/pi-extension.js.map +1 -1
- package/dist/python.d.ts.map +1 -1
- package/dist/python.js +5 -1
- package/dist/python.js.map +1 -1
- package/dist/recipe/agent.d.ts +9 -6
- package/dist/recipe/agent.d.ts.map +1 -1
- package/dist/recipe/agent.js +23 -28
- package/dist/recipe/agent.js.map +1 -1
- package/dist/recipe/companions.d.ts +3 -17
- package/dist/recipe/companions.d.ts.map +1 -1
- package/dist/recipe/companions.js +40 -34
- package/dist/recipe/companions.js.map +1 -1
- package/dist/recipe/extensions.d.ts.map +1 -1
- package/dist/recipe/extensions.js +23 -6
- package/dist/recipe/extensions.js.map +1 -1
- package/dist/recipe/manifest.generated.d.ts +16 -0
- package/dist/recipe/manifest.generated.d.ts.map +1 -0
- package/dist/recipe/manifest.generated.js +17 -0
- package/dist/recipe/manifest.generated.js.map +1 -0
- package/dist/recipe/mcp-config.d.ts +0 -12
- package/dist/recipe/mcp-config.d.ts.map +1 -1
- package/dist/recipe/mcp-config.js +1 -70
- package/dist/recipe/mcp-config.js.map +1 -1
- package/dist/recipe/model.d.ts +8 -7
- package/dist/recipe/model.d.ts.map +1 -1
- package/dist/recipe/model.js +2 -6
- package/dist/recipe/model.js.map +1 -1
- package/dist/recipe/package.d.ts +3 -16
- package/dist/recipe/package.d.ts.map +1 -1
- package/dist/recipe/package.js +105 -40
- package/dist/recipe/package.js.map +1 -1
- package/dist/recipe/python.d.ts +0 -8
- package/dist/recipe/python.d.ts.map +1 -1
- package/dist/recipe/python.js +40 -13
- package/dist/recipe/python.js.map +1 -1
- package/dist/recipe/resolve.d.ts.map +1 -1
- package/dist/recipe/resolve.js +4 -9
- package/dist/recipe/resolve.js.map +1 -1
- package/dist/recipe/session.d.ts +3 -2
- package/dist/recipe/session.d.ts.map +1 -1
- package/dist/recipe/session.js +4 -3
- package/dist/recipe/session.js.map +1 -1
- package/dist/recipe/skills-prompt.d.ts.map +1 -1
- package/dist/recipe/skills-prompt.js +6 -1
- package/dist/recipe/skills-prompt.js.map +1 -1
- package/dist/recipe/skills.d.ts +0 -6
- package/dist/recipe/skills.d.ts.map +1 -1
- package/dist/recipe/skills.js +8 -5
- package/dist/recipe/skills.js.map +1 -1
- package/dist/recipe/suggestions.d.ts.map +1 -1
- package/dist/recipe/suggestions.js +21 -8
- package/dist/recipe/suggestions.js.map +1 -1
- package/dist/run-controller.d.ts +0 -2
- package/dist/run-controller.d.ts.map +1 -1
- package/dist/run-controller.js +4 -2
- package/dist/run-controller.js.map +1 -1
- package/dist/session.d.ts +10 -4
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +30 -26
- package/dist/session.js.map +1 -1
- package/dist/skill-progress.d.ts +69 -20
- package/dist/skill-progress.d.ts.map +1 -1
- package/dist/skill-progress.js +153 -37
- package/dist/skill-progress.js.map +1 -1
- package/dist/suggestion-picker.d.ts +0 -3
- package/dist/suggestion-picker.d.ts.map +1 -1
- package/dist/suggestion-picker.js +4 -2
- package/dist/suggestion-picker.js.map +1 -1
- package/dist/test-utils.d.ts.map +1 -1
- package/dist/test-utils.js.map +1 -1
- package/docs/agent-composition.md +1 -0
- package/docs/pi-extension.md +41 -5
- package/docs/recipe-format.md +26 -2
- package/package.json +21 -8
package/dist/mcp/cli/core.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
-
import { mkdir, open, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import { mkdir, open, readFile, rename, rm, stat, writeFile, } from "node:fs/promises";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
import { setTimeout as delay } from "node:timers/promises";
|
|
6
6
|
import { stdin as input, stderr, stdout } from "node:process";
|
|
@@ -49,9 +49,9 @@ async function closeOwnedRuntime(runtime, owned) {
|
|
|
49
49
|
if (owned)
|
|
50
50
|
await runtime.close();
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
class McpRunUsageError extends Error {
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
class McpRunTimeoutError extends Error {
|
|
55
55
|
outcome = "unknown";
|
|
56
56
|
constructor(message) {
|
|
57
57
|
super(message);
|
|
@@ -66,7 +66,7 @@ class McpRemoteToolResultError extends Error {
|
|
|
66
66
|
this.name = "McpRemoteToolResultError";
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
class McpRunToolError extends Error {
|
|
70
70
|
server;
|
|
71
71
|
tool;
|
|
72
72
|
kind = "tool_execution";
|
|
@@ -117,7 +117,7 @@ function checkedCallResult(callResult) {
|
|
|
117
117
|
? parsedError
|
|
118
118
|
: typeof errorObject.message === "string"
|
|
119
119
|
? errorObject.message
|
|
120
|
-
: callResult.text() ?? "MCP tool call failed.";
|
|
120
|
+
: (callResult.text() ?? "MCP tool call failed.");
|
|
121
121
|
throw new McpRemoteToolResultError({ ...errorObject, message });
|
|
122
122
|
}
|
|
123
123
|
return callResult;
|
|
@@ -126,7 +126,9 @@ function decodeCallResult(callResult, format, ref) {
|
|
|
126
126
|
switch (format) {
|
|
127
127
|
case "json": {
|
|
128
128
|
const decoded = callResult.json();
|
|
129
|
-
if (decoded === null &&
|
|
129
|
+
if (decoded === null &&
|
|
130
|
+
callResult.structuredContent() == null &&
|
|
131
|
+
callResult.text() != null) {
|
|
130
132
|
// The text is usually the reason (not connected, an upstream error), so
|
|
131
133
|
// it travels with the error instead of being hidden behind a format hint.
|
|
132
134
|
const text = callResult.text().trim();
|
|
@@ -238,7 +240,9 @@ function scoreTool(opts) {
|
|
|
238
240
|
const description = opts.tool.description ?? "";
|
|
239
241
|
const properties = toolProperties(opts.tool);
|
|
240
242
|
const propertyNames = properties.map((property) => property.name).join(" ");
|
|
241
|
-
const propertyDescriptions = properties
|
|
243
|
+
const propertyDescriptions = properties
|
|
244
|
+
.map((property) => property.description)
|
|
245
|
+
.join(" ");
|
|
242
246
|
const searchable = [
|
|
243
247
|
ref,
|
|
244
248
|
opts.serverId,
|
|
@@ -298,7 +302,9 @@ function exampleValue(name) {
|
|
|
298
302
|
}
|
|
299
303
|
function callExample(serverId, tool) {
|
|
300
304
|
const required = toolRequired(tool);
|
|
301
|
-
const args = required
|
|
305
|
+
const args = required
|
|
306
|
+
.slice(0, 4)
|
|
307
|
+
.map((name) => `${name}${exampleValue(name)}`);
|
|
302
308
|
return ["mcp call", `${serverId}.${tool.name}`, ...args].join(" ");
|
|
303
309
|
}
|
|
304
310
|
export function searchMcpTools(session, query, opts = {}) {
|
|
@@ -421,7 +427,8 @@ async function catalogLockIsStale(path, timeoutMs) {
|
|
|
421
427
|
typeof owner.createdAt === "number" &&
|
|
422
428
|
Number.isFinite(owner.createdAt)) {
|
|
423
429
|
return (!processExists(owner.pid) ||
|
|
424
|
-
Date.now() - owner.createdAt >
|
|
430
|
+
Date.now() - owner.createdAt >
|
|
431
|
+
timeoutMs + CATALOG_LOCK_INCOMPLETE_GRACE_MS);
|
|
425
432
|
}
|
|
426
433
|
}
|
|
427
434
|
catch (error) {
|
|
@@ -558,16 +565,23 @@ function optionName(value) {
|
|
|
558
565
|
}
|
|
559
566
|
export function parseSearchArgs(args) {
|
|
560
567
|
if (args.some((arg) => optionName(arg) === "--json")) {
|
|
561
|
-
return {
|
|
568
|
+
return {
|
|
569
|
+
error: "mcp search metadata is compact text; JSON is reserved for tool results.",
|
|
570
|
+
};
|
|
562
571
|
}
|
|
563
572
|
let parsed;
|
|
564
573
|
try {
|
|
565
|
-
parsed = parseArgs({
|
|
574
|
+
parsed = parseArgs({
|
|
575
|
+
args,
|
|
576
|
+
options: SEARCH_OPTIONS,
|
|
577
|
+
allowPositionals: true,
|
|
578
|
+
});
|
|
566
579
|
}
|
|
567
580
|
catch (error) {
|
|
568
581
|
// An agent reads these and decides what to try next, so the wording stays
|
|
569
582
|
// ours rather than Node's.
|
|
570
|
-
if (error.code ===
|
|
583
|
+
if (error.code ===
|
|
584
|
+
"ERR_PARSE_ARGS_INVALID_OPTION_VALUE") {
|
|
571
585
|
// parseArgs rejects an option-shaped value (`--limit -1`) before it is
|
|
572
586
|
// read, so the value has to be recovered to name it back.
|
|
573
587
|
const index = args.findIndex((arg) => optionName(arg) === "--limit");
|
|
@@ -585,7 +599,9 @@ export function parseSearchArgs(args) {
|
|
|
585
599
|
if (values.limit !== undefined) {
|
|
586
600
|
const value = Number(values.limit);
|
|
587
601
|
if (!Number.isInteger(value) || value <= 0) {
|
|
588
|
-
return {
|
|
602
|
+
return {
|
|
603
|
+
error: `--limit expects a positive integer, got '${values.limit}'.`,
|
|
604
|
+
};
|
|
589
605
|
}
|
|
590
606
|
limit = value;
|
|
591
607
|
}
|
|
@@ -600,7 +616,9 @@ export function renderSearchResults(matches, catalogs) {
|
|
|
600
616
|
let budget = MAX_SEARCH_CONTRACT_CHARS;
|
|
601
617
|
let shortened = false;
|
|
602
618
|
const blocks = matches.map((match, index) => {
|
|
603
|
-
const entry = catalogs
|
|
619
|
+
const entry = catalogs
|
|
620
|
+
.get(match.server)
|
|
621
|
+
?.find((tool) => tool.name === match.tool);
|
|
604
622
|
if (!entry)
|
|
605
623
|
return `${match.ref}${match.description ? ` — ${match.description}` : ""}\n`;
|
|
606
624
|
const tool = {
|
|
@@ -631,7 +649,7 @@ async function searchCatalog(args) {
|
|
|
631
649
|
}
|
|
632
650
|
const { query, limit, regex } = parsed;
|
|
633
651
|
if (!query.trim()) {
|
|
634
|
-
stderr.write(
|
|
652
|
+
stderr.write('Usage: mcp search "what you need" [--limit N] [--regex]\n');
|
|
635
653
|
return 2;
|
|
636
654
|
}
|
|
637
655
|
let matches;
|
|
@@ -703,7 +721,9 @@ function toolCount(count) {
|
|
|
703
721
|
}
|
|
704
722
|
export function parseListTimeoutMs(args) {
|
|
705
723
|
const configured = process.env.MCPORTER_LIST_TIMEOUT;
|
|
706
|
-
let raw = configured && /^[1-9]\d*$/.test(configured)
|
|
724
|
+
let raw = configured && /^[1-9]\d*$/.test(configured)
|
|
725
|
+
? configured
|
|
726
|
+
: String(DEFAULT_LIST_TIMEOUT_MS);
|
|
707
727
|
// Non-strict: every other option on this line belongs to mcporter.
|
|
708
728
|
const { values } = parseArgs({
|
|
709
729
|
args: [...args.slice(1)],
|
|
@@ -726,7 +746,7 @@ export function parseListTimeoutMs(args) {
|
|
|
726
746
|
? timeout
|
|
727
747
|
: "mcp list: --timeout must be a positive integer (milliseconds).";
|
|
728
748
|
}
|
|
729
|
-
|
|
749
|
+
function withListTimeout(promise, timeoutMs) {
|
|
730
750
|
return new Promise((resolve, reject) => {
|
|
731
751
|
const timer = setTimeout(() => reject(new Error(`timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
732
752
|
promise.then((value) => {
|
|
@@ -738,14 +758,15 @@ export function withListTimeout(promise, timeoutMs) {
|
|
|
738
758
|
});
|
|
739
759
|
});
|
|
740
760
|
}
|
|
741
|
-
|
|
742
|
-
return hadFailure &&
|
|
761
|
+
function aggregateListExitCode(hadFailure, args) {
|
|
762
|
+
return hadFailure &&
|
|
763
|
+
(args.includes("--quiet") || args.includes("--exit-code"))
|
|
743
764
|
? 1
|
|
744
765
|
: 0;
|
|
745
766
|
}
|
|
746
767
|
function writeCompactListError(error) {
|
|
747
768
|
const filter = createDelegatedErrorFilter((text) => stderr.write(text));
|
|
748
|
-
const message = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
769
|
+
const message = error instanceof Error ? (error.stack ?? error.message) : String(error);
|
|
749
770
|
filter.push(`mcp list: ${message.endsWith("\n") ? message : `${message}\n`}`);
|
|
750
771
|
filter.flush();
|
|
751
772
|
}
|
|
@@ -876,7 +897,9 @@ async function compactList(args) {
|
|
|
876
897
|
stdout.write(`${server} ok — ${toolCount(tools.length)}\n`);
|
|
877
898
|
return 0;
|
|
878
899
|
}
|
|
879
|
-
const selected = exact
|
|
900
|
+
const selected = exact
|
|
901
|
+
? tools.filter((tool) => tool.name === exact.tool)
|
|
902
|
+
: tools;
|
|
880
903
|
if (exact && selected.length === 0) {
|
|
881
904
|
stderr.write(`Tool '${exact.tool}' is not available on server '${server}'.\n`);
|
|
882
905
|
return 1;
|
|
@@ -992,7 +1015,9 @@ function improveRunToolError(error, server, tool, knownTools) {
|
|
|
992
1015
|
}
|
|
993
1016
|
if (!RUN_TOOL_REJECTED_PATTERNS.some((pattern) => pattern.test(message)))
|
|
994
1017
|
return error;
|
|
995
|
-
return new Error(describeUnavailableRunTool(server, tool, knownTools), {
|
|
1018
|
+
return new Error(describeUnavailableRunTool(server, tool, knownTools), {
|
|
1019
|
+
cause: error,
|
|
1020
|
+
});
|
|
996
1021
|
}
|
|
997
1022
|
// A refused version probe means the connection never opened, so the tool did
|
|
998
1023
|
// not run and the call can be made again. Any later failure may follow a
|
|
@@ -1015,7 +1040,9 @@ export async function callToolWithHandshakeRetry(runtime, server, tool, options,
|
|
|
1015
1040
|
}
|
|
1016
1041
|
catch (error) {
|
|
1017
1042
|
const wait = HANDSHAKE_RETRY_DELAYS_MS[attempt];
|
|
1018
|
-
if (wait === undefined ||
|
|
1043
|
+
if (wait === undefined ||
|
|
1044
|
+
!refusedHandshake(error) ||
|
|
1045
|
+
Date.now() + wait >= deadlineMs) {
|
|
1019
1046
|
throw error;
|
|
1020
1047
|
}
|
|
1021
1048
|
await delay(wait);
|
|
@@ -1092,7 +1119,9 @@ async function createTools(opts) {
|
|
|
1092
1119
|
: `MCP tool call ${server}.${property} timed out.`,
|
|
1093
1120
|
retryable: true,
|
|
1094
1121
|
action: "inspect_state",
|
|
1095
|
-
outcome: improved instanceof McpRunTimeoutError
|
|
1122
|
+
outcome: improved instanceof McpRunTimeoutError
|
|
1123
|
+
? "not_started"
|
|
1124
|
+
: "unknown",
|
|
1096
1125
|
}
|
|
1097
1126
|
: undefined;
|
|
1098
1127
|
throw new McpRunToolError(server, property, remoteDetails?.message ?? timeoutDetails?.message ?? message, { cause: improved, details: remoteDetails ?? timeoutDetails });
|
|
@@ -1112,7 +1141,8 @@ async function createTools(opts) {
|
|
|
1112
1141
|
record.outcome = "succeeded";
|
|
1113
1142
|
}, (error) => {
|
|
1114
1143
|
record.outcome = "failed";
|
|
1115
|
-
record.error =
|
|
1144
|
+
record.error =
|
|
1145
|
+
error instanceof Error ? error.message : String(error);
|
|
1116
1146
|
});
|
|
1117
1147
|
// JSON.stringify(promise) is "{}" — the classic missing-await
|
|
1118
1148
|
// symptom. Make it print a diagnosis instead.
|
|
@@ -1170,7 +1200,9 @@ function createVars(vars) {
|
|
|
1170
1200
|
return target[property];
|
|
1171
1201
|
const defined = Object.keys(target);
|
|
1172
1202
|
throw new Error(`vars.${property} is not defined. Pass it with --var ${property}=value` +
|
|
1173
|
-
(defined.length > 0
|
|
1203
|
+
(defined.length > 0
|
|
1204
|
+
? ` (defined vars: ${defined.join(", ")}).`
|
|
1205
|
+
: " (no vars were passed).") +
|
|
1174
1206
|
` Use \`"${property}" in vars\` to test for optional vars.`);
|
|
1175
1207
|
},
|
|
1176
1208
|
});
|
|
@@ -1194,7 +1226,9 @@ function concurrentOutcomeError(error, calls) {
|
|
|
1194
1226
|
outcome: call.outcome,
|
|
1195
1227
|
...(call.error ? { error: call.error } : {}),
|
|
1196
1228
|
}));
|
|
1197
|
-
const summary = outcomes
|
|
1229
|
+
const summary = outcomes
|
|
1230
|
+
.map((call) => `${call.ref}=${call.outcome}`)
|
|
1231
|
+
.join(", ");
|
|
1198
1232
|
const message = `${error.message} Workflow call outcomes: ${summary}. Inspect state before retrying side-effecting calls.`;
|
|
1199
1233
|
return new McpRunToolError(error.server, error.tool, message, {
|
|
1200
1234
|
cause: error,
|
|
@@ -1208,7 +1242,7 @@ function positiveInteger(value, label, fallback) {
|
|
|
1208
1242
|
}
|
|
1209
1243
|
return parsed;
|
|
1210
1244
|
}
|
|
1211
|
-
|
|
1245
|
+
async function runMcpJavaScript(code, opts = {}) {
|
|
1212
1246
|
const timeoutMs = positiveInteger(opts.timeoutMs ?? process.env.PI_RECIPES_MCP_RUN_TIMEOUT_MS, "PI_RECIPES_MCP_RUN_TIMEOUT_MS", DEFAULT_RUN_TIMEOUT_MS);
|
|
1213
1247
|
const callTimeoutMs = positiveInteger(opts.callTimeoutMs ?? process.env.PI_RECIPES_MCP_RUN_CALL_TIMEOUT_MS, "PI_RECIPES_MCP_RUN_CALL_TIMEOUT_MS", Math.min(DEFAULT_TOOL_CALL_TIMEOUT_MS, timeoutMs));
|
|
1214
1248
|
const maxCalls = positiveInteger(opts.maxCalls ?? process.env.PI_RECIPES_MCP_RUN_MAX_CALLS, "PI_RECIPES_MCP_RUN_MAX_CALLS", DEFAULT_MAX_RUN_TOOL_CALLS);
|
|
@@ -1220,7 +1254,8 @@ export async function runMcpJavaScript(code, opts = {}) {
|
|
|
1220
1254
|
maxConcurrentCalls,
|
|
1221
1255
|
deadlineMs,
|
|
1222
1256
|
});
|
|
1223
|
-
const AsyncFunction = Object.getPrototypeOf(async function () { })
|
|
1257
|
+
const AsyncFunction = Object.getPrototypeOf(async function () { })
|
|
1258
|
+
.constructor;
|
|
1224
1259
|
const run = new AsyncFunction("tools", "vars", "process", code);
|
|
1225
1260
|
let timeout;
|
|
1226
1261
|
let primaryError;
|
|
@@ -1314,6 +1349,7 @@ export async function runMcpJavaScript(code, opts = {}) {
|
|
|
1314
1349
|
// Transport cleanup must not replace the typed tool/script error that
|
|
1315
1350
|
// tells the agent what actually failed. A close-only failure still
|
|
1316
1351
|
// surfaces normally.
|
|
1352
|
+
// eslint-disable-next-line no-unsafe-finally -- only when nothing else failed
|
|
1317
1353
|
if (primaryError === undefined)
|
|
1318
1354
|
throw closeError;
|
|
1319
1355
|
}
|
|
@@ -1350,7 +1386,9 @@ async function runCode(args) {
|
|
|
1350
1386
|
jsonErrors = true;
|
|
1351
1387
|
continue;
|
|
1352
1388
|
}
|
|
1353
|
-
const inline = arg.startsWith("--var=")
|
|
1389
|
+
const inline = arg.startsWith("--var=")
|
|
1390
|
+
? arg.slice("--var=".length)
|
|
1391
|
+
: undefined;
|
|
1354
1392
|
const value = inline ?? (arg === "--var" ? args[++index] : undefined);
|
|
1355
1393
|
if (arg === "--var" || inline !== undefined) {
|
|
1356
1394
|
const eq = value?.indexOf("=") ?? -1;
|
|
@@ -1396,7 +1434,9 @@ async function runCode(args) {
|
|
|
1396
1434
|
? error.message
|
|
1397
1435
|
: `${error.name}: ${error.message}`
|
|
1398
1436
|
: String(error);
|
|
1399
|
-
const prefixed = message.startsWith("mcp run")
|
|
1437
|
+
const prefixed = message.startsWith("mcp run")
|
|
1438
|
+
? message
|
|
1439
|
+
: `mcp run: ${message}`;
|
|
1400
1440
|
const code = error instanceof McpRunUsageError ? 2 : 1;
|
|
1401
1441
|
if (jsonErrors) {
|
|
1402
1442
|
const remoteDetails = error instanceof McpRunToolError ? error.details : undefined;
|
|
@@ -1438,7 +1478,7 @@ async function runCode(args) {
|
|
|
1438
1478
|
}
|
|
1439
1479
|
return 0;
|
|
1440
1480
|
}
|
|
1441
|
-
|
|
1481
|
+
function createDelegatedErrorFilter(write) {
|
|
1442
1482
|
let buffer = "";
|
|
1443
1483
|
let sawOAuthMetadataError = false;
|
|
1444
1484
|
const emit = (line) => {
|
|
@@ -1475,7 +1515,7 @@ export function createDelegatedErrorFilter(write) {
|
|
|
1475
1515
|
},
|
|
1476
1516
|
};
|
|
1477
1517
|
}
|
|
1478
|
-
|
|
1518
|
+
function duplicateCallArgumentKeys(args) {
|
|
1479
1519
|
const seen = new Set();
|
|
1480
1520
|
const duplicates = new Set();
|
|
1481
1521
|
for (const token of args.slice(1)) {
|
|
@@ -1506,7 +1546,7 @@ export function callJsonArgumentError(args) {
|
|
|
1506
1546
|
}
|
|
1507
1547
|
return null;
|
|
1508
1548
|
}
|
|
1509
|
-
|
|
1549
|
+
function malformedCallExpression(args) {
|
|
1510
1550
|
const ref = args.find((arg) => !arg.startsWith("-"));
|
|
1511
1551
|
if (!ref || !/[()]/.test(ref))
|
|
1512
1552
|
return null;
|
|
@@ -1573,7 +1613,8 @@ async function callWithSharedRuntime(runtime, args) {
|
|
|
1573
1613
|
break;
|
|
1574
1614
|
}
|
|
1575
1615
|
}
|
|
1576
|
-
if (normalizedArgs[index] === "--json" &&
|
|
1616
|
+
if (normalizedArgs[index] === "--json" &&
|
|
1617
|
+
normalizedArgs[index + 1] === "-") {
|
|
1577
1618
|
normalizedArgs[index + 1] = await readStdin();
|
|
1578
1619
|
}
|
|
1579
1620
|
}
|
|
@@ -1714,7 +1755,7 @@ function describeSharedCallError(error, server, tool) {
|
|
|
1714
1755
|
const signal = issue.stdioSignal ? ` (signal ${issue.stdioSignal})` : "";
|
|
1715
1756
|
return `MCP server '${server}' exited with ${exit}${signal}.`;
|
|
1716
1757
|
}
|
|
1717
|
-
return issue.rawMessage || (error instanceof Error ? error.message : String(error));
|
|
1758
|
+
return (issue.rawMessage || (error instanceof Error ? error.message : String(error)));
|
|
1718
1759
|
}
|
|
1719
1760
|
function schemaAllowsString(value) {
|
|
1720
1761
|
const schema = asRecord(value);
|
|
@@ -1761,7 +1802,8 @@ async function restoreSchemaStringArguments(runtime, server, tool, values, candi
|
|
|
1761
1802
|
return values;
|
|
1762
1803
|
let corrected;
|
|
1763
1804
|
for (const [key, rawValue] of Object.entries(candidates)) {
|
|
1764
|
-
if (typeof values[key] !== "number" ||
|
|
1805
|
+
if (typeof values[key] !== "number" ||
|
|
1806
|
+
!schemaAllowsString(properties[key])) {
|
|
1765
1807
|
continue;
|
|
1766
1808
|
}
|
|
1767
1809
|
corrected ??= { ...values };
|