caplets 0.17.6 → 0.17.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/dist/index.js +337 -46
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -4709,7 +4709,7 @@ function generatedToolInputJsonSchema() {
|
|
|
4709
4709
|
return generatedToolInputJsonSchemaForCaplet({ backend: "tool" });
|
|
4710
4710
|
}
|
|
4711
4711
|
//#endregion
|
|
4712
|
-
//#region ../core/dist/options-
|
|
4712
|
+
//#region ../core/dist/options-CY6p-C9L.js
|
|
4713
4713
|
var __create = Object.create;
|
|
4714
4714
|
var __defProp = Object.defineProperty;
|
|
4715
4715
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -4805,13 +4805,26 @@ function toSafeError(error, fallback = "INTERNAL_ERROR") {
|
|
|
4805
4805
|
}
|
|
4806
4806
|
function errorResult(error, fallback) {
|
|
4807
4807
|
const safe = toSafeError(error, fallback);
|
|
4808
|
+
const structuredContent = { error: safe };
|
|
4808
4809
|
return {
|
|
4809
4810
|
isError: true,
|
|
4810
4811
|
content: [{
|
|
4811
4812
|
type: "text",
|
|
4812
|
-
text:
|
|
4813
|
+
text: [
|
|
4814
|
+
"# Error",
|
|
4815
|
+
"",
|
|
4816
|
+
`## ${safe.code}`,
|
|
4817
|
+
"",
|
|
4818
|
+
safe.message,
|
|
4819
|
+
"",
|
|
4820
|
+
"## Details",
|
|
4821
|
+
"",
|
|
4822
|
+
"```json",
|
|
4823
|
+
JSON.stringify(safe, null, 2),
|
|
4824
|
+
"```"
|
|
4825
|
+
].join("\n")
|
|
4813
4826
|
}],
|
|
4814
|
-
structuredContent
|
|
4827
|
+
structuredContent
|
|
4815
4828
|
};
|
|
4816
4829
|
}
|
|
4817
4830
|
function textContent(text) {
|
|
@@ -4820,33 +4833,277 @@ function textContent(text) {
|
|
|
4820
4833
|
text
|
|
4821
4834
|
}] : [];
|
|
4822
4835
|
}
|
|
4823
|
-
function
|
|
4824
|
-
return
|
|
4836
|
+
function markdownStructuredContent(value, context = {}) {
|
|
4837
|
+
return textContent(renderStructuredMarkdown(value, context));
|
|
4825
4838
|
}
|
|
4826
|
-
function
|
|
4827
|
-
const
|
|
4828
|
-
|
|
4839
|
+
function markdownCallToolResultContent(result, context = {}) {
|
|
4840
|
+
const downstreamText = textBlocksToString(result.content);
|
|
4841
|
+
const structuredContent = result.structuredContent;
|
|
4842
|
+
const hasStructured = hasRenderableStructuredContent(structuredContent);
|
|
4843
|
+
if (context.backend === "mcp" && hasStructured) {
|
|
4844
|
+
const renderedStructured = markdownStructuredContent(structuredContent, context)[0]?.text;
|
|
4845
|
+
if (downstreamText && downstreamText === renderedStructured) return textContent(downstreamText);
|
|
4846
|
+
return [...result.content ?? [], {
|
|
4847
|
+
type: "text",
|
|
4848
|
+
text: [
|
|
4849
|
+
"## Structured Content",
|
|
4850
|
+
"",
|
|
4851
|
+
jsonFence(structuredContent)
|
|
4852
|
+
].join("\n")
|
|
4853
|
+
}];
|
|
4854
|
+
}
|
|
4855
|
+
if (hasStructured) return markdownStructuredContent(structuredContent, {
|
|
4856
|
+
...context,
|
|
4857
|
+
isError: context.isError ?? result.isError
|
|
4858
|
+
});
|
|
4859
|
+
if (downstreamText) return textContent(downstreamText);
|
|
4860
|
+
return textContent(renderStructuredMarkdown(result, context));
|
|
4829
4861
|
}
|
|
4830
|
-
function
|
|
4831
|
-
if (!
|
|
4832
|
-
|
|
4833
|
-
return keys.length > 0 ? `structured keys: ${keys.join(", ")}` : "empty structured result";
|
|
4862
|
+
function hasRenderableStructuredContent(value) {
|
|
4863
|
+
if (!isRecord$1(value)) return false;
|
|
4864
|
+
return Object.keys(value).some((key) => key !== "caplets" && key !== "elapsedMs");
|
|
4834
4865
|
}
|
|
4835
|
-
function
|
|
4836
|
-
|
|
4837
|
-
|
|
4866
|
+
function renderStructuredMarkdown(value, context) {
|
|
4867
|
+
const title = markdownTitle(context);
|
|
4868
|
+
if (isDiscoveryWrapper(value)) return renderDiscoveryWrapper(value, context, title);
|
|
4869
|
+
if (context.isError || isErrorStructuredContent(value)) return renderErrorMarkdown(value, title);
|
|
4870
|
+
if (context.backend === "cli" || isCliResult(value)) return renderCliMarkdown(value, title);
|
|
4871
|
+
if (context.backend === "graphql" && isHttpLikeResult(value) || isGraphQlHttpResult(value)) return renderGraphQlMarkdown(value, title);
|
|
4872
|
+
if (isHttpLikeResult(value)) return renderHttpMarkdown(value, title);
|
|
4838
4873
|
return [
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
"
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
}
|
|
4848
|
-
|
|
4849
|
-
return
|
|
4874
|
+
title,
|
|
4875
|
+
"",
|
|
4876
|
+
"## Result",
|
|
4877
|
+
"",
|
|
4878
|
+
jsonFence(value)
|
|
4879
|
+
].join("\n");
|
|
4880
|
+
}
|
|
4881
|
+
function markdownTitle(context) {
|
|
4882
|
+
if (context.title) return `# ${context.title}`;
|
|
4883
|
+
const parts = [context.operation, context.tool ?? context.uri ?? context.prompt].filter((part) => Boolean(part));
|
|
4884
|
+
return parts.length > 0 ? `# ${parts.join(" ")}` : "# Result";
|
|
4885
|
+
}
|
|
4886
|
+
function renderHttpMarkdown(value, title) {
|
|
4887
|
+
const record = asRecord$2(value) ?? {};
|
|
4888
|
+
const lines = [
|
|
4889
|
+
title,
|
|
4890
|
+
"",
|
|
4891
|
+
"## Response",
|
|
4892
|
+
""
|
|
4893
|
+
];
|
|
4894
|
+
const status = typeof record.status === "number" ? record.status : void 0;
|
|
4895
|
+
const statusText = typeof record.statusText === "string" ? record.statusText : void 0;
|
|
4896
|
+
if (status !== void 0 || statusText) lines.push(`- **Status:** \`${[status, statusText].filter(Boolean).join(" ")}\``);
|
|
4897
|
+
if (typeof record.elapsedMs === "number") lines.push(`- **Elapsed:** \`${record.elapsedMs} ms\``);
|
|
4898
|
+
lines.push("", "## Headers", "", jsonFence(record.headers ?? {}), "", "## Body", "", renderBodyValue(record.body));
|
|
4899
|
+
const additional = omitKeys(record, [
|
|
4900
|
+
"status",
|
|
4901
|
+
"statusText",
|
|
4902
|
+
"headers",
|
|
4903
|
+
"body",
|
|
4904
|
+
"elapsedMs"
|
|
4905
|
+
]);
|
|
4906
|
+
if (Object.keys(additional).length > 0) lines.push("", "## Additional Fields", "", jsonFence(additional));
|
|
4907
|
+
return lines.join("\n");
|
|
4908
|
+
}
|
|
4909
|
+
function renderGraphQlMarkdown(value, title) {
|
|
4910
|
+
const record = asRecord$2(value) ?? {};
|
|
4911
|
+
const body = asRecord$2(record.body);
|
|
4912
|
+
if (!body || !("data" in body) && !("errors" in body)) return renderHttpMarkdown(value, title);
|
|
4913
|
+
const lines = [
|
|
4914
|
+
title,
|
|
4915
|
+
"",
|
|
4916
|
+
"## Response",
|
|
4917
|
+
""
|
|
4918
|
+
];
|
|
4919
|
+
const status = typeof record.status === "number" ? record.status : void 0;
|
|
4920
|
+
const statusText = typeof record.statusText === "string" ? record.statusText : void 0;
|
|
4921
|
+
if (status !== void 0 || statusText) lines.push(`- **Status:** \`${[status, statusText].filter(Boolean).join(" ")}\``);
|
|
4922
|
+
if (typeof record.elapsedMs === "number") lines.push(`- **Elapsed:** \`${record.elapsedMs} ms\``);
|
|
4923
|
+
if ("data" in body) lines.push("", "## Data", "", jsonFence(body.data));
|
|
4924
|
+
if ("errors" in body) lines.push("", "## Errors", "", jsonFence(body.errors));
|
|
4925
|
+
lines.push("", "## Headers", "", jsonFence(record.headers ?? {}), "", "## Full Body", "", jsonFence(record.body));
|
|
4926
|
+
const additional = omitKeys(record, [
|
|
4927
|
+
"status",
|
|
4928
|
+
"statusText",
|
|
4929
|
+
"headers",
|
|
4930
|
+
"body",
|
|
4931
|
+
"elapsedMs"
|
|
4932
|
+
]);
|
|
4933
|
+
if (Object.keys(additional).length > 0) lines.push("", "## Additional Fields", "", jsonFence(additional));
|
|
4934
|
+
return lines.join("\n");
|
|
4935
|
+
}
|
|
4936
|
+
function renderCliMarkdown(value, title) {
|
|
4937
|
+
const record = asRecord$2(value) ?? {};
|
|
4938
|
+
const lines = [
|
|
4939
|
+
title,
|
|
4940
|
+
"",
|
|
4941
|
+
"## Command Result",
|
|
4942
|
+
""
|
|
4943
|
+
];
|
|
4944
|
+
if ("exitCode" in record) lines.push(`- **Exit code:** \`${String(record.exitCode)}\``);
|
|
4945
|
+
if ("signal" in record) lines.push(`- **Signal:** \`${String(record.signal)}\``);
|
|
4946
|
+
if (typeof record.elapsedMs === "number") lines.push(`- **Elapsed:** \`${record.elapsedMs} ms\``);
|
|
4947
|
+
lines.push("", "## stdout", "", textFenceOrEmpty(record.stdout, "No stdout."));
|
|
4948
|
+
lines.push("", "## stderr", "", textFenceOrEmpty(record.stderr, "No stderr."));
|
|
4949
|
+
if ("json" in record) lines.push("", "## Parsed JSON", "", jsonFence(record.json));
|
|
4950
|
+
if ("jsonParseError" in record) lines.push("", "## JSON Parse Error", "", jsonFence(record.jsonParseError));
|
|
4951
|
+
const additional = omitKeys(record, [
|
|
4952
|
+
"exitCode",
|
|
4953
|
+
"signal",
|
|
4954
|
+
"stdout",
|
|
4955
|
+
"stderr",
|
|
4956
|
+
"elapsedMs",
|
|
4957
|
+
"json",
|
|
4958
|
+
"jsonParseError"
|
|
4959
|
+
]);
|
|
4960
|
+
if (Object.keys(additional).length > 0) lines.push("", "## Additional Fields", "", jsonFence(additional));
|
|
4961
|
+
return lines.join("\n");
|
|
4962
|
+
}
|
|
4963
|
+
function renderDiscoveryWrapper(value, context, title) {
|
|
4964
|
+
const result = asRecord$2(value.result);
|
|
4965
|
+
const lines = [title, ""];
|
|
4966
|
+
if (context.operation === "list_tools" || context.operation === "search_tools") lines.push("## Tools", "", renderNamedList(arrayValue(result?.tools), "tool"), "");
|
|
4967
|
+
else if (context.operation === "list_resources" || context.operation === "search_resources") lines.push("## Resources", "", renderNamedList(arrayValue(result?.resources ?? result?.matches), "uri"), "");
|
|
4968
|
+
else if (context.operation === "list_resource_templates") lines.push("## Resource Templates", "", renderNamedList(arrayValue(result?.resourceTemplates), "uriTemplate"), "");
|
|
4969
|
+
else if (context.operation === "list_prompts" || context.operation === "search_prompts") lines.push("## Prompts", "", renderNamedList(arrayValue(result?.prompts), "prompt"), "");
|
|
4970
|
+
else if (context.operation === "get_tool") lines.push("## Tool", "", renderToolSummary(asRecord$2(result?.tool)), "");
|
|
4971
|
+
else if (context.operation === "check_backend") lines.push("## Backend Status", "", renderBackendStatus(result), "");
|
|
4972
|
+
else if (context.operation === "get_caplet") lines.push("## Caplet", "", renderCapletSummary(result), "");
|
|
4973
|
+
lines.push("## Full Result", "", jsonFence(value.result));
|
|
4974
|
+
if (value.caplets !== void 0) lines.push("", "## Caplets Metadata", "", jsonFence(value.caplets));
|
|
4975
|
+
return lines.join("\n");
|
|
4976
|
+
}
|
|
4977
|
+
function renderErrorMarkdown(value, title) {
|
|
4978
|
+
const error = asRecord$2(asRecord$2(value)?.error) ?? asRecord$2(value);
|
|
4979
|
+
const code = typeof error?.code === "string" ? error.code : "Error";
|
|
4980
|
+
const message = typeof error?.message === "string" ? error.message : "Tool call failed.";
|
|
4981
|
+
return [
|
|
4982
|
+
title === "# Result" || title === "# Error" ? "# Error" : title,
|
|
4983
|
+
"",
|
|
4984
|
+
`## ${code}`,
|
|
4985
|
+
"",
|
|
4986
|
+
message,
|
|
4987
|
+
"",
|
|
4988
|
+
"## Details",
|
|
4989
|
+
"",
|
|
4990
|
+
jsonFence(error ?? value)
|
|
4991
|
+
].join("\n");
|
|
4992
|
+
}
|
|
4993
|
+
function isDiscoveryWrapper(value) {
|
|
4994
|
+
return isRecord$1(value) && "result" in value;
|
|
4995
|
+
}
|
|
4996
|
+
function isErrorStructuredContent(value) {
|
|
4997
|
+
return isRecord$1(value) && "error" in value;
|
|
4998
|
+
}
|
|
4999
|
+
function isHttpLikeResult(value) {
|
|
5000
|
+
return isRecord$1(value) && ("status" in value || "statusText" in value || "body" in value);
|
|
5001
|
+
}
|
|
5002
|
+
function isGraphQlHttpResult(value) {
|
|
5003
|
+
if (!isHttpLikeResult(value)) return false;
|
|
5004
|
+
const body = asRecord$2(value.body);
|
|
5005
|
+
return Boolean(body && ("data" in body || "errors" in body));
|
|
5006
|
+
}
|
|
5007
|
+
function isCliResult(value) {
|
|
5008
|
+
return isRecord$1(value) && ("exitCode" in value || "stdout" in value || "stderr" in value);
|
|
5009
|
+
}
|
|
5010
|
+
function renderBodyValue(value) {
|
|
5011
|
+
if (value === void 0) return "_No response body._";
|
|
5012
|
+
if (typeof value === "string") return textFenceOrEmpty(value, "No response body.");
|
|
5013
|
+
return jsonFence(value);
|
|
5014
|
+
}
|
|
5015
|
+
function textFenceOrEmpty(value, emptyMessage) {
|
|
5016
|
+
if (typeof value !== "string" || value.length === 0) return `_${emptyMessage}_`;
|
|
5017
|
+
return [
|
|
5018
|
+
"```text",
|
|
5019
|
+
escapeCodeFence(value),
|
|
5020
|
+
"```"
|
|
5021
|
+
].join("\n");
|
|
5022
|
+
}
|
|
5023
|
+
function jsonFence(value) {
|
|
5024
|
+
return [
|
|
5025
|
+
"```json",
|
|
5026
|
+
escapeCodeFence(JSON.stringify(value, null, 2) ?? "null"),
|
|
5027
|
+
"```"
|
|
5028
|
+
].join("\n");
|
|
5029
|
+
}
|
|
5030
|
+
function escapeCodeFence(value) {
|
|
5031
|
+
return value.replace(/```/gu, "```");
|
|
5032
|
+
}
|
|
5033
|
+
function textBlocksToString(content) {
|
|
5034
|
+
if (!Array.isArray(content)) return "";
|
|
5035
|
+
return content.filter((item) => Boolean(item && typeof item === "object" && item.type === "text" && typeof item.text === "string")).map((item) => item.text).filter(Boolean).join("\n");
|
|
5036
|
+
}
|
|
5037
|
+
function renderNamedList(items, nameKey) {
|
|
5038
|
+
if (items.length === 0) return "_No items._";
|
|
5039
|
+
return items.map((item, index) => {
|
|
5040
|
+
const record = asRecord$2(item);
|
|
5041
|
+
const name = stringValue(record?.[nameKey]) ?? stringValue(record?.name) ?? `Item ${index + 1}`;
|
|
5042
|
+
const description = stringValue(record?.description);
|
|
5043
|
+
return description ? `${index + 1}. \`${name}\` — ${description}` : `${index + 1}. \`${name}\``;
|
|
5044
|
+
}).join("\n");
|
|
5045
|
+
}
|
|
5046
|
+
function renderToolSummary(tool) {
|
|
5047
|
+
if (!tool) return "_Tool details unavailable._";
|
|
5048
|
+
const lines = [];
|
|
5049
|
+
const name = stringValue(tool.name);
|
|
5050
|
+
const description = stringValue(tool.description);
|
|
5051
|
+
if (name) lines.push(`- **Name:** \`${name}\``);
|
|
5052
|
+
if (description) lines.push(`- **Description:** ${description}`);
|
|
5053
|
+
if (tool.inputSchema !== void 0) lines.push("", "### Input Schema", "", jsonFence(tool.inputSchema));
|
|
5054
|
+
if (tool.outputSchema !== void 0) lines.push("", "### Output Schema", "", jsonFence(tool.outputSchema));
|
|
5055
|
+
if (tool.annotations !== void 0) lines.push("", "### Annotations", "", jsonFence(tool.annotations));
|
|
5056
|
+
return lines.length > 0 ? lines.join("\n") : jsonFence(tool);
|
|
5057
|
+
}
|
|
5058
|
+
function renderBackendStatus(result) {
|
|
5059
|
+
if (!result) return "_Backend status unavailable._";
|
|
5060
|
+
const lines = [];
|
|
5061
|
+
for (const key of [
|
|
5062
|
+
"id",
|
|
5063
|
+
"status",
|
|
5064
|
+
"toolCount",
|
|
5065
|
+
"resourceCount",
|
|
5066
|
+
"resourceTemplateCount",
|
|
5067
|
+
"promptCount",
|
|
5068
|
+
"elapsedMs"
|
|
5069
|
+
]) if (result[key] !== void 0) {
|
|
5070
|
+
const label = key === "elapsedMs" ? "Elapsed" : humanizeKey(key);
|
|
5071
|
+
const suffix = key === "elapsedMs" ? " ms" : "";
|
|
5072
|
+
lines.push(`- **${label}:** \`${String(result[key])}${suffix}\``);
|
|
5073
|
+
}
|
|
5074
|
+
if (result.error !== void 0) lines.push("", "### Error", "", jsonFence(result.error));
|
|
5075
|
+
return lines.length > 0 ? lines.join("\n") : jsonFence(result);
|
|
5076
|
+
}
|
|
5077
|
+
function renderCapletSummary(result) {
|
|
5078
|
+
if (!result) return "_Caplet details unavailable._";
|
|
5079
|
+
const lines = [];
|
|
5080
|
+
for (const key of [
|
|
5081
|
+
"id",
|
|
5082
|
+
"name",
|
|
5083
|
+
"description"
|
|
5084
|
+
]) if (result[key] !== void 0) lines.push(`- **${humanizeKey(key)}:** ${String(result[key])}`);
|
|
5085
|
+
const backend = asRecord$2(result.backend);
|
|
5086
|
+
if (backend?.type !== void 0) lines.push(`- **Backend:** \`${String(backend.type)}\``);
|
|
5087
|
+
return lines.length > 0 ? lines.join("\n") : jsonFence(result);
|
|
5088
|
+
}
|
|
5089
|
+
function omitKeys(record, keys) {
|
|
5090
|
+
const omitted = new Set(keys);
|
|
5091
|
+
return Object.fromEntries(Object.entries(record).filter(([key]) => !omitted.has(key)));
|
|
5092
|
+
}
|
|
5093
|
+
function arrayValue(value) {
|
|
5094
|
+
return Array.isArray(value) ? value : [];
|
|
5095
|
+
}
|
|
5096
|
+
function stringValue(value) {
|
|
5097
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
5098
|
+
}
|
|
5099
|
+
function humanizeKey(key) {
|
|
5100
|
+
return key.replace(/([A-Z])/gu, " $1").replace(/^./u, (char) => char.toUpperCase());
|
|
5101
|
+
}
|
|
5102
|
+
function asRecord$2(value) {
|
|
5103
|
+
return isRecord$1(value) ? value : void 0;
|
|
5104
|
+
}
|
|
5105
|
+
function isRecord$1(value) {
|
|
5106
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
4850
5107
|
}
|
|
4851
5108
|
function searchToolList(tools, query, limit, compact) {
|
|
4852
5109
|
const tokens = query.toLocaleLowerCase().split(/\s+/).filter(Boolean);
|
|
@@ -4913,7 +5170,12 @@ var CliToolsManager = class {
|
|
|
4913
5170
|
const result = await spawnCommand(execution, controller.signal, () => Date.now() - startedAt);
|
|
4914
5171
|
const structured = parseStructuredResult(action, result, result.exitCode !== 0);
|
|
4915
5172
|
return {
|
|
4916
|
-
content:
|
|
5173
|
+
content: markdownStructuredContent(structured, {
|
|
5174
|
+
title: `${config.name} call_tool ${toolName}`,
|
|
5175
|
+
backend: "cli",
|
|
5176
|
+
operation: "call_tool",
|
|
5177
|
+
tool: toolName
|
|
5178
|
+
}),
|
|
4917
5179
|
structuredContent: structured,
|
|
4918
5180
|
isError: result.exitCode !== 0
|
|
4919
5181
|
};
|
|
@@ -46622,7 +46884,12 @@ var GraphQLManager = class {
|
|
|
46622
46884
|
body
|
|
46623
46885
|
};
|
|
46624
46886
|
return {
|
|
46625
|
-
content:
|
|
46887
|
+
content: markdownStructuredContent(result, {
|
|
46888
|
+
title: `${endpoint.name} call_tool ${toolName}`,
|
|
46889
|
+
backend: "graphql",
|
|
46890
|
+
operation: "call_tool",
|
|
46891
|
+
tool: toolName
|
|
46892
|
+
}),
|
|
46626
46893
|
structuredContent: result,
|
|
46627
46894
|
isError: !response.ok || Boolean(body && typeof body === "object" && "errors" in body && body.errors)
|
|
46628
46895
|
};
|
|
@@ -47014,7 +47281,12 @@ var HttpActionManager = class {
|
|
|
47014
47281
|
});
|
|
47015
47282
|
const parsed = await readResponse$1(response, api, Date.now() - startedAt);
|
|
47016
47283
|
return {
|
|
47017
|
-
content:
|
|
47284
|
+
content: markdownStructuredContent(parsed, {
|
|
47285
|
+
title: `${api.name} call_tool ${toolName}`,
|
|
47286
|
+
backend: "http",
|
|
47287
|
+
operation: "call_tool",
|
|
47288
|
+
tool: toolName
|
|
47289
|
+
}),
|
|
47018
47290
|
structuredContent: parsed,
|
|
47019
47291
|
isError: !response.ok
|
|
47020
47292
|
};
|
|
@@ -56623,7 +56895,12 @@ var OpenApiManager = class {
|
|
|
56623
56895
|
});
|
|
56624
56896
|
const parsed = await readResponse(response);
|
|
56625
56897
|
return {
|
|
56626
|
-
content:
|
|
56898
|
+
content: markdownStructuredContent(parsed, {
|
|
56899
|
+
title: `${endpoint.name} call_tool ${toolName}`,
|
|
56900
|
+
backend: "openapi",
|
|
56901
|
+
operation: "call_tool",
|
|
56902
|
+
tool: toolName
|
|
56903
|
+
}),
|
|
56627
56904
|
structuredContent: parsed,
|
|
56628
56905
|
isError: response.ok ? false : true
|
|
56629
56906
|
};
|
|
@@ -57252,7 +57529,8 @@ async function handleServerTool(server, request, registry, downstream, openapi,
|
|
|
57252
57529
|
const tool = await backend.getTool(server, parsed.tool);
|
|
57253
57530
|
if (!tool.outputSchema) throw new CapletsError("REQUEST_INVALID", "Field selection requires an output schema");
|
|
57254
57531
|
validateFieldSelection(tool.outputSchema, parsed.fields);
|
|
57255
|
-
|
|
57532
|
+
const metadata = metadataFor(server, "call_tool", parsed.tool, startedAt);
|
|
57533
|
+
return annotateCallToolResult(projectCallToolResult(await backend.callTool(server, parsed.tool, parsed.arguments), tool.outputSchema, parsed.fields, markdownContextFor(metadata)), metadata);
|
|
57256
57534
|
}
|
|
57257
57535
|
case "list_resources": {
|
|
57258
57536
|
const backend = mcpBackendFor(server, downstream);
|
|
@@ -57456,16 +57734,28 @@ function annotateMcpResult(result, metadata) {
|
|
|
57456
57734
|
}
|
|
57457
57735
|
};
|
|
57458
57736
|
}
|
|
57737
|
+
function markdownContextFor(metadata) {
|
|
57738
|
+
return {
|
|
57739
|
+
title: [
|
|
57740
|
+
metadata.name,
|
|
57741
|
+
metadata.operation,
|
|
57742
|
+
metadata.tool ?? metadata.uri ?? metadata.prompt
|
|
57743
|
+
].filter(Boolean).join(" "),
|
|
57744
|
+
backend: metadata.backend,
|
|
57745
|
+
operation: metadata.operation,
|
|
57746
|
+
...metadata.tool ? { tool: metadata.tool } : {},
|
|
57747
|
+
...metadata.uri ? { uri: metadata.uri } : {},
|
|
57748
|
+
...metadata.prompt ? { prompt: metadata.prompt } : {}
|
|
57749
|
+
};
|
|
57750
|
+
}
|
|
57459
57751
|
function jsonResult(value, metadata) {
|
|
57752
|
+
const structuredContent = {
|
|
57753
|
+
...metadata === void 0 ? {} : { caplets: metadata },
|
|
57754
|
+
result: value
|
|
57755
|
+
};
|
|
57460
57756
|
return {
|
|
57461
|
-
content:
|
|
57462
|
-
|
|
57463
|
-
text: JSON.stringify(value, null, 2)
|
|
57464
|
-
}],
|
|
57465
|
-
structuredContent: {
|
|
57466
|
-
...metadata === void 0 ? {} : { caplets: metadata },
|
|
57467
|
-
result: value
|
|
57468
|
-
}
|
|
57757
|
+
content: markdownStructuredContent(structuredContent, metadata ? markdownContextFor(metadata) : { title: "Result" }),
|
|
57758
|
+
structuredContent
|
|
57469
57759
|
};
|
|
57470
57760
|
}
|
|
57471
57761
|
function annotateCallToolResult(result, metadata) {
|
|
@@ -57478,20 +57768,21 @@ function annotateCallToolResult(result, metadata) {
|
|
|
57478
57768
|
};
|
|
57479
57769
|
return {
|
|
57480
57770
|
...result,
|
|
57771
|
+
content: markdownCallToolResultContent(result, markdownContextFor(annotatedMetadata)),
|
|
57481
57772
|
_meta: {
|
|
57482
57773
|
...isPlainObject$7(existingMeta) ? existingMeta : {},
|
|
57483
57774
|
caplets: annotatedMetadata
|
|
57484
57775
|
}
|
|
57485
57776
|
};
|
|
57486
57777
|
}
|
|
57487
|
-
function projectCallToolResult(result, outputSchema, fields) {
|
|
57778
|
+
function projectCallToolResult(result, outputSchema, fields, context = {}) {
|
|
57488
57779
|
if (result.isError === true) return result;
|
|
57489
57780
|
const structuredContent = result.structuredContent;
|
|
57490
57781
|
if (!isPlainObject$7(structuredContent)) throw new CapletsError("DOWNSTREAM_PROTOCOL_ERROR", "Field selection requires the downstream tool to return object structuredContent");
|
|
57491
57782
|
const projected = projectStructuredContent(structuredContent, outputSchema, fields);
|
|
57492
57783
|
return {
|
|
57493
57784
|
...result,
|
|
57494
|
-
content:
|
|
57785
|
+
content: markdownStructuredContent(projected, context),
|
|
57495
57786
|
structuredContent: projected
|
|
57496
57787
|
};
|
|
57497
57788
|
}
|
|
@@ -57926,7 +58217,7 @@ var CapletsEngine = class {
|
|
|
57926
58217
|
}
|
|
57927
58218
|
}
|
|
57928
58219
|
async completeCliWords(words) {
|
|
57929
|
-
const { completeCliWords } = await Promise.resolve().then(() =>
|
|
58220
|
+
const { completeCliWords } = await Promise.resolve().then(() => completion_B9niw4HY_exports).then((n) => n.r);
|
|
57930
58221
|
return await completeCliWords(words, {
|
|
57931
58222
|
config: this.registry.config,
|
|
57932
58223
|
managers: {
|
|
@@ -58264,8 +58555,8 @@ function hasEnv$1(value) {
|
|
|
58264
58555
|
return value !== void 0 && value.trim() !== "";
|
|
58265
58556
|
}
|
|
58266
58557
|
//#endregion
|
|
58267
|
-
//#region ../core/dist/completion-
|
|
58268
|
-
var
|
|
58558
|
+
//#region ../core/dist/completion-B9niw4HY.js
|
|
58559
|
+
var completion_B9niw4HY_exports = /* @__PURE__ */ __exportAll$1({
|
|
58269
58560
|
a: () => formatCapletList,
|
|
58270
58561
|
c: () => resolveCliConfigPaths,
|
|
58271
58562
|
i: () => trailingSpaceCompletionToken,
|
|
@@ -60129,7 +60420,7 @@ const EMPTY_COMPLETION_RESULT = { completion: {
|
|
|
60129
60420
|
values: [],
|
|
60130
60421
|
hasMore: false
|
|
60131
60422
|
} };
|
|
60132
|
-
var version$1 = "0.18.
|
|
60423
|
+
var version$1 = "0.18.7";
|
|
60133
60424
|
var CapletsMcpSession = class {
|
|
60134
60425
|
engine;
|
|
60135
60426
|
server;
|
|
@@ -69403,7 +69694,7 @@ function writeAddResult(writeOut, label, result) {
|
|
|
69403
69694
|
}
|
|
69404
69695
|
//#endregion
|
|
69405
69696
|
//#region package.json
|
|
69406
|
-
var version = "0.17.
|
|
69697
|
+
var version = "0.17.7";
|
|
69407
69698
|
//#endregion
|
|
69408
69699
|
//#region src/index.ts
|
|
69409
69700
|
async function main() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "caplets",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.7",
|
|
4
4
|
"description": "Progressive disclosure gateway CLI for MCP servers and native Caplets adapters.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"caplets",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
37
|
-
"@caplets/core": "0.18.
|
|
37
|
+
"@caplets/core": "0.18.7"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node": "^25.9.1",
|