@easynet/agent-tool 1.0.72 → 1.0.74
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 +5 -5
- package/dist/api/adapters/LangChainToolsHub.d.ts +1 -1
- package/dist/api/createAgentTools.d.ts +4 -0
- package/dist/api/createAgentTools.d.ts.map +1 -1
- package/dist/api/expose/index.d.ts +1 -1
- package/dist/api/expose/openapi.d.ts.map +1 -1
- package/dist/api/expose/openapiHttp.d.ts.map +1 -1
- package/dist/api/main.cjs +23 -19
- package/dist/api/main.d.ts +4 -3
- package/dist/api/main.d.ts.map +1 -1
- package/dist/api/main.js +4 -4
- package/dist/api/runtimeFromConfig.d.ts.map +1 -1
- package/dist/build.cjs +8 -8
- package/dist/build.js +3 -3
- package/dist/{chunk-OG5ZSXQ5.cjs → chunk-33N4Y6IS.cjs} +13 -13
- package/dist/{chunk-OG5ZSXQ5.cjs.map → chunk-33N4Y6IS.cjs.map} +1 -1
- package/dist/{chunk-J5EPH2QO.js → chunk-ECHW6AWF.js} +37 -8
- package/dist/chunk-ECHW6AWF.js.map +1 -0
- package/dist/{chunk-YPGF5Y2Y.js → chunk-GSOJCOKN.js} +3 -3
- package/dist/{chunk-YPGF5Y2Y.js.map → chunk-GSOJCOKN.js.map} +1 -1
- package/dist/{chunk-45S2HPVU.js → chunk-HEVWKBBQ.js} +87 -60
- package/dist/chunk-HEVWKBBQ.js.map +1 -0
- package/dist/{chunk-VSFIF3WJ.js → chunk-JYADGZQP.js} +254 -261
- package/dist/chunk-JYADGZQP.js.map +1 -0
- package/dist/{chunk-DTLALP7X.cjs → chunk-KTQTDKWU.cjs} +57 -27
- package/dist/chunk-KTQTDKWU.cjs.map +1 -0
- package/dist/{chunk-JNIWNSCQ.cjs → chunk-LHKEJNKL.cjs} +87 -60
- package/dist/chunk-LHKEJNKL.cjs.map +1 -0
- package/dist/{chunk-WO4LZKPQ.cjs → chunk-OKKBKZWK.cjs} +4 -4
- package/dist/{chunk-WO4LZKPQ.cjs.map → chunk-OKKBKZWK.cjs.map} +1 -1
- package/dist/{chunk-YRFUGA3C.js → chunk-Q6W32HAP.js} +3 -3
- package/dist/{chunk-YRFUGA3C.js.map → chunk-Q6W32HAP.js.map} +1 -1
- package/dist/{chunk-3AM4SGUY.cjs → chunk-SE6IMOIE.cjs} +258 -265
- package/dist/chunk-SE6IMOIE.cjs.map +1 -0
- package/dist/{chunk-NMZ4IMEW.cjs → chunk-TBDSFXNG.cjs} +14 -14
- package/dist/{chunk-NMZ4IMEW.cjs.map → chunk-TBDSFXNG.cjs.map} +1 -1
- package/dist/{chunk-5J27MF7S.js → chunk-VYULM6NC.js} +4 -4
- package/dist/{chunk-5J27MF7S.js.map → chunk-VYULM6NC.js.map} +1 -1
- package/dist/core/runtime/PTCRuntime.d.ts +3 -0
- package/dist/core/runtime/PTCRuntime.d.ts.map +1 -1
- package/dist/extension.cjs +14 -14
- package/dist/extension.js +2 -2
- package/dist/index.cjs +41 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/tools/function/scanner.d.ts.map +1 -1
- package/dist/utils/cli/index.cjs +18 -18
- package/dist/utils/cli/index.js +4 -4
- package/package.json +1 -1
- package/dist/chunk-3AM4SGUY.cjs.map +0 -1
- package/dist/chunk-45S2HPVU.js.map +0 -1
- package/dist/chunk-DTLALP7X.cjs.map +0 -1
- package/dist/chunk-J5EPH2QO.js.map +0 -1
- package/dist/chunk-JNIWNSCQ.cjs.map +0 -1
- package/dist/chunk-VSFIF3WJ.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkUUNG3GL3_cjs = require('./chunk-UUNG3GL3.cjs');
|
|
4
|
-
var
|
|
4
|
+
var chunk33N4Y6IS_cjs = require('./chunk-33N4Y6IS.cjs');
|
|
5
5
|
var chunkZDSZHEQU_cjs = require('./chunk-ZDSZHEQU.cjs');
|
|
6
6
|
var chunkPYCCJF7C_cjs = require('./chunk-PYCCJF7C.cjs');
|
|
7
7
|
var chunkXPGHS4W7_cjs = require('./chunk-XPGHS4W7.cjs');
|
|
@@ -1543,101 +1543,18 @@ var PTCRuntime = class {
|
|
|
1543
1543
|
*/
|
|
1544
1544
|
async invoke(intent, ctx) {
|
|
1545
1545
|
const startTime = Date.now();
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
requestId: ctx.requestId,
|
|
1550
|
-
taskId: ctx.taskId,
|
|
1551
|
-
traceId: ctx.traceId,
|
|
1552
|
-
purpose: intent.purpose,
|
|
1553
|
-
args: this.logger.options.includeArgs ? sanitizeForLog(intent.args) : void 0
|
|
1554
|
-
});
|
|
1555
|
-
}
|
|
1556
|
-
const span = this.tracing.startSpan({
|
|
1557
|
-
name: `tool:${intent.tool}`,
|
|
1558
|
-
traceId: ctx.traceId,
|
|
1559
|
-
attributes: {
|
|
1560
|
-
"tool.name": intent.tool,
|
|
1561
|
-
"tool.purpose": intent.purpose,
|
|
1562
|
-
requestId: ctx.requestId,
|
|
1563
|
-
taskId: ctx.taskId
|
|
1564
|
-
}
|
|
1565
|
-
});
|
|
1566
|
-
emitToolCalled(intent, ctx, this.getObservabilityDeps());
|
|
1546
|
+
const span = this.beginInvokeSpan(intent, ctx);
|
|
1547
|
+
const observability = this.getObservabilityDeps();
|
|
1548
|
+
emitToolCalled(intent, ctx, observability);
|
|
1567
1549
|
try {
|
|
1568
|
-
const
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
version: spec.version
|
|
1572
|
-
});
|
|
1573
|
-
const normalizedArgs = normalizeInputAliases(spec, intent.args);
|
|
1574
|
-
const validatedArgs = validateInput(spec, normalizedArgs, this.validator);
|
|
1575
|
-
const enrichedArgs = enrichDefaults(spec, validatedArgs, this.validator);
|
|
1576
|
-
enforcePolicy(spec, enrichedArgs, ctx, {
|
|
1577
|
-
policy: this.policy,
|
|
1578
|
-
eventLog: this.eventLog,
|
|
1579
|
-
metrics: this.metrics,
|
|
1580
|
-
tracing: this.tracing
|
|
1581
|
-
});
|
|
1582
|
-
if (!this.budget.checkRateLimit(spec.name)) {
|
|
1583
|
-
throw chunkXPGHS4W7_cjs.createTaggedError(
|
|
1584
|
-
"BUDGET_EXCEEDED",
|
|
1585
|
-
`Rate limit exceeded for tool: ${spec.name}`
|
|
1586
|
-
);
|
|
1587
|
-
}
|
|
1588
|
-
await requireHumanApproval(spec, enrichedArgs, ctx, {
|
|
1589
|
-
onApprovalRequired: this.config.onApprovalRequired,
|
|
1590
|
-
eventLog: this.eventLog,
|
|
1591
|
-
logger: this.logger
|
|
1592
|
-
});
|
|
1593
|
-
if (ctx.dryRun) {
|
|
1594
|
-
return this.buildDryRunResult(spec, enrichedArgs, ctx, startTime, span.spanId);
|
|
1595
|
-
}
|
|
1596
|
-
const { result, raw } = await executeWithBudget(
|
|
1597
|
-
spec,
|
|
1598
|
-
enrichedArgs,
|
|
1599
|
-
ctx,
|
|
1600
|
-
span.spanId,
|
|
1601
|
-
this.getPipelineDeps()
|
|
1602
|
-
);
|
|
1603
|
-
const toolError = asToolReturnedError(result);
|
|
1604
|
-
if (toolError) {
|
|
1605
|
-
const hint = buildInputSchemaHint(spec.inputSchema);
|
|
1606
|
-
throw chunkXPGHS4W7_cjs.createTaggedError("UPSTREAM_ERROR", toolError.message, {
|
|
1607
|
-
...toolError.details && typeof toolError.details === "object" && !Array.isArray(toolError.details) ? toolError.details : {},
|
|
1608
|
-
hint: hint ?? "Check the tool's input schema for required property names."
|
|
1609
|
-
});
|
|
1550
|
+
const pipeline = await this.runInvokePipeline(intent, ctx, span.spanId);
|
|
1551
|
+
if (pipeline.dryRun) {
|
|
1552
|
+
return this.buildDryRunResult(pipeline.spec, pipeline.enrichedArgs, ctx, startTime, span.spanId);
|
|
1610
1553
|
}
|
|
1611
|
-
|
|
1612
|
-
const durationMs = Date.now() - startTime;
|
|
1613
|
-
const builtEvidence = buildEvidence({
|
|
1614
|
-
spec,
|
|
1615
|
-
args: enrichedArgs,
|
|
1616
|
-
result: validatedOutput,
|
|
1617
|
-
raw,
|
|
1618
|
-
ctx,
|
|
1619
|
-
durationMs
|
|
1620
|
-
});
|
|
1621
|
-
const adapterEvidence = raw && typeof raw === "object" && Array.isArray(raw.evidence) ? raw.evidence : [];
|
|
1622
|
-
const evidence = [...adapterEvidence, ...builtEvidence];
|
|
1623
|
-
recordSuccess(spec, durationMs, evidence, span.spanId, this.getObservabilityDeps());
|
|
1624
|
-
if (this.logger.isEnabled("debug")) {
|
|
1625
|
-
this.logger.debug("invoke.ok", {
|
|
1626
|
-
tool: spec.name,
|
|
1627
|
-
durationMs,
|
|
1628
|
-
result: this.logger.options.includeResults ? summarizeForLog(validatedOutput) : void 0,
|
|
1629
|
-
raw: this.logger.options.includeRaw ? summarizeForLog(raw) : void 0
|
|
1630
|
-
});
|
|
1631
|
-
}
|
|
1632
|
-
return {
|
|
1633
|
-
ok: true,
|
|
1634
|
-
result: validatedOutput,
|
|
1635
|
-
evidence,
|
|
1636
|
-
raw: this.config.includeRaw !== false ? raw : void 0
|
|
1637
|
-
};
|
|
1554
|
+
return this.buildInvokeSuccessResult(pipeline, ctx, startTime, span.spanId, observability);
|
|
1638
1555
|
} catch (error) {
|
|
1639
1556
|
const durationMs = Date.now() - startTime;
|
|
1640
|
-
return handleError(error, intent, ctx, durationMs, span.spanId,
|
|
1557
|
+
return handleError(error, intent, ctx, durationMs, span.spanId, observability);
|
|
1641
1558
|
}
|
|
1642
1559
|
}
|
|
1643
1560
|
/**
|
|
@@ -1684,6 +1601,84 @@ var PTCRuntime = class {
|
|
|
1684
1601
|
logger: this.logger
|
|
1685
1602
|
};
|
|
1686
1603
|
}
|
|
1604
|
+
beginInvokeSpan(intent, ctx) {
|
|
1605
|
+
if (this.logger.isEnabled("debug")) {
|
|
1606
|
+
this.logger.debug("invoke.start", {
|
|
1607
|
+
tool: intent.tool,
|
|
1608
|
+
requestId: ctx.requestId,
|
|
1609
|
+
taskId: ctx.taskId,
|
|
1610
|
+
traceId: ctx.traceId,
|
|
1611
|
+
purpose: intent.purpose,
|
|
1612
|
+
args: this.logger.options.includeArgs ? sanitizeForLog(intent.args) : void 0
|
|
1613
|
+
});
|
|
1614
|
+
}
|
|
1615
|
+
return this.tracing.startSpan({
|
|
1616
|
+
name: `tool:${intent.tool}`,
|
|
1617
|
+
traceId: ctx.traceId,
|
|
1618
|
+
attributes: {
|
|
1619
|
+
"tool.name": intent.tool,
|
|
1620
|
+
"tool.purpose": intent.purpose,
|
|
1621
|
+
requestId: ctx.requestId,
|
|
1622
|
+
taskId: ctx.taskId
|
|
1623
|
+
}
|
|
1624
|
+
});
|
|
1625
|
+
}
|
|
1626
|
+
async runInvokePipeline(intent, ctx, spanId) {
|
|
1627
|
+
const spec = resolveTool(intent.tool, this.registry);
|
|
1628
|
+
this.tracing.addEvent(spanId, "resolved", { kind: spec.kind, version: spec.version });
|
|
1629
|
+
const normalizedArgs = normalizeInputAliases(spec, intent.args);
|
|
1630
|
+
const validatedArgs = validateInput(spec, normalizedArgs, this.validator);
|
|
1631
|
+
const enrichedArgs = enrichDefaults(spec, validatedArgs, this.validator);
|
|
1632
|
+
enforcePolicy(spec, enrichedArgs, ctx, this.getPipelineDeps());
|
|
1633
|
+
if (!this.budget.checkRateLimit(spec.name)) {
|
|
1634
|
+
throw chunkXPGHS4W7_cjs.createTaggedError("BUDGET_EXCEEDED", `Rate limit exceeded for tool: ${spec.name}`);
|
|
1635
|
+
}
|
|
1636
|
+
await requireHumanApproval(spec, enrichedArgs, ctx, {
|
|
1637
|
+
onApprovalRequired: this.config.onApprovalRequired,
|
|
1638
|
+
eventLog: this.eventLog,
|
|
1639
|
+
logger: this.logger
|
|
1640
|
+
});
|
|
1641
|
+
if (ctx.dryRun) return { spec, enrichedArgs, dryRun: true };
|
|
1642
|
+
const execution = await executeWithBudget(spec, enrichedArgs, ctx, spanId, this.getPipelineDeps());
|
|
1643
|
+
return { spec, enrichedArgs, dryRun: false, result: execution.result, raw: execution.raw };
|
|
1644
|
+
}
|
|
1645
|
+
buildInvokeSuccessResult(pipeline, ctx, startTime, spanId, observability) {
|
|
1646
|
+
const toolError = asToolReturnedError(pipeline.result);
|
|
1647
|
+
if (toolError) {
|
|
1648
|
+
const hint = buildInputSchemaHint(pipeline.spec.inputSchema);
|
|
1649
|
+
throw chunkXPGHS4W7_cjs.createTaggedError("UPSTREAM_ERROR", toolError.message, {
|
|
1650
|
+
...toolError.details && typeof toolError.details === "object" && !Array.isArray(toolError.details) ? toolError.details : {},
|
|
1651
|
+
hint: hint ?? "Check the tool's input schema for required property names."
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
const validatedOutput = validateOutput(pipeline.spec, pipeline.result, this.validator);
|
|
1655
|
+
const durationMs = Date.now() - startTime;
|
|
1656
|
+
const builtEvidence = buildEvidence({
|
|
1657
|
+
spec: pipeline.spec,
|
|
1658
|
+
args: pipeline.enrichedArgs,
|
|
1659
|
+
result: validatedOutput,
|
|
1660
|
+
raw: pipeline.raw,
|
|
1661
|
+
ctx,
|
|
1662
|
+
durationMs
|
|
1663
|
+
});
|
|
1664
|
+
const adapterEvidence = getAdapterEvidence(pipeline.raw);
|
|
1665
|
+
const evidence = [...adapterEvidence, ...builtEvidence];
|
|
1666
|
+
recordSuccess(pipeline.spec, durationMs, evidence, spanId, observability);
|
|
1667
|
+
if (this.logger.isEnabled("debug")) {
|
|
1668
|
+
this.logger.debug("invoke.ok", {
|
|
1669
|
+
tool: pipeline.spec.name,
|
|
1670
|
+
durationMs,
|
|
1671
|
+
result: this.logger.options.includeResults ? summarizeForLog(validatedOutput) : void 0,
|
|
1672
|
+
raw: this.logger.options.includeRaw ? summarizeForLog(pipeline.raw) : void 0
|
|
1673
|
+
});
|
|
1674
|
+
}
|
|
1675
|
+
return {
|
|
1676
|
+
ok: true,
|
|
1677
|
+
result: validatedOutput,
|
|
1678
|
+
evidence,
|
|
1679
|
+
raw: this.config.includeRaw !== false ? pipeline.raw : void 0
|
|
1680
|
+
};
|
|
1681
|
+
}
|
|
1687
1682
|
buildDryRunResult(spec, args, _ctx, startTime, spanId) {
|
|
1688
1683
|
this.tracing.endSpan(spanId, "ok");
|
|
1689
1684
|
return {
|
|
@@ -1706,6 +1701,11 @@ var PTCRuntime = class {
|
|
|
1706
1701
|
};
|
|
1707
1702
|
}
|
|
1708
1703
|
};
|
|
1704
|
+
function getAdapterEvidence(raw) {
|
|
1705
|
+
if (!raw || typeof raw !== "object") return [];
|
|
1706
|
+
const value = raw.evidence;
|
|
1707
|
+
return Array.isArray(value) ? value : [];
|
|
1708
|
+
}
|
|
1709
1709
|
function asToolReturnedError(result) {
|
|
1710
1710
|
if (result == null || typeof result !== "object" || Array.isArray(result)) {
|
|
1711
1711
|
return null;
|
|
@@ -1727,7 +1727,7 @@ function buildInputSchemaHint(inputSchema) {
|
|
|
1727
1727
|
if (names.length === 0) return null;
|
|
1728
1728
|
return `This tool expects input property ${names.length === 1 ? `'${names[0]}'` : `one of [${names.map((n) => `'${n}'`).join(", ")}]`}. Use the exact property names from the tool schema.`;
|
|
1729
1729
|
}
|
|
1730
|
-
var requireFromPackage = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
1730
|
+
var requireFromPackage = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-SE6IMOIE.cjs', document.baseURI).href)));
|
|
1731
1731
|
function getProjectRequire() {
|
|
1732
1732
|
const cwd = process.cwd();
|
|
1733
1733
|
if (fs.existsSync(path.join(cwd, "package.json"))) return module$1.createRequire(path.join(cwd, "package.json"));
|
|
@@ -1893,7 +1893,7 @@ function parseNpmDescriptor(entry) {
|
|
|
1893
1893
|
}
|
|
1894
1894
|
|
|
1895
1895
|
// src/api/runtimeFromConfig.ts
|
|
1896
|
-
var requireFromPackage2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
1896
|
+
var requireFromPackage2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-SE6IMOIE.cjs', document.baseURI).href)));
|
|
1897
1897
|
var DEFAULT_EXTENSION_PACKAGES = [];
|
|
1898
1898
|
function resolveFileDescriptorPath(descriptor, configFilePath) {
|
|
1899
1899
|
const parsed = parseToolPath(descriptor.trim());
|
|
@@ -1960,7 +1960,7 @@ function loadExtensionForDescriptorSync(descriptor, configFilePath, stepLog) {
|
|
|
1960
1960
|
if (typeof fn === "function") {
|
|
1961
1961
|
const installed = getInstalledPackageVersionFromRequire(parsed.packageName, configRequire);
|
|
1962
1962
|
const requested = parsed.version === "latest" || !parsed.version?.trim() ? null : parsed.version;
|
|
1963
|
-
const resolvedVersion = requested
|
|
1963
|
+
const resolvedVersion = requested ?? installed ?? npm.resolveLatestVersionFromRegistry(parsed.packageName, { cwd: npmCwd });
|
|
1964
1964
|
if (installed === resolvedVersion) {
|
|
1965
1965
|
if (stepLog) stepLog(`Loaded ${parsed.packageName}@${resolvedVersion} from node_modules`);
|
|
1966
1966
|
return { register: fn, descriptor: entryStr, resolvedVersion };
|
|
@@ -2036,7 +2036,7 @@ async function loadExtensionForDescriptorAsync(descriptor, configFilePath, stepL
|
|
|
2036
2036
|
try {
|
|
2037
2037
|
const installed = getInstalledPackageVersionFromRequire(parsed.packageName, configRequire);
|
|
2038
2038
|
const requested = parsed.version === "latest" || !parsed.version?.trim() ? null : parsed.version;
|
|
2039
|
-
const resolvedVersion = requested
|
|
2039
|
+
const resolvedVersion = requested ?? installed ?? npm.resolveLatestVersionFromRegistry(parsed.packageName, { cwd: npmCwd });
|
|
2040
2040
|
if (installed === resolvedVersion) {
|
|
2041
2041
|
const pkgJsonResolved = configRequire.resolve(`${parsed.packageName}/package.json`);
|
|
2042
2042
|
const packageRoot = path.dirname(pkgJsonResolved);
|
|
@@ -2076,7 +2076,7 @@ async function loadLocalDirectoryForFileDescriptor(descriptor, configFilePath, s
|
|
|
2076
2076
|
if (!resolvedPath || !fs.existsSync(resolvedPath) || !fs.statSync(resolvedPath).isDirectory()) return null;
|
|
2077
2077
|
if (fs.existsSync(path.join(resolvedPath, "package.json"))) return null;
|
|
2078
2078
|
const scanErrors = [];
|
|
2079
|
-
const scanner = new
|
|
2079
|
+
const scanner = new chunk33N4Y6IS_cjs.DirectoryScanner({
|
|
2080
2080
|
roots: [{ path: resolvedPath, namespace: "local" }],
|
|
2081
2081
|
onError: (toolDir, error) => scanErrors.push(`${toolDir}: ${error.message}`)
|
|
2082
2082
|
});
|
|
@@ -2233,7 +2233,20 @@ function toolsToOpenAPISpec(registry, options = {}) {
|
|
|
2233
2233
|
const version = options.version ?? "1.0.0";
|
|
2234
2234
|
const basePath = (options.basePath ?? "").replace(/\/$/, "");
|
|
2235
2235
|
const specs = registry.snapshot().map(chunkUUNG3GL3_cjs.enrichSpecWithCanonicalSchema);
|
|
2236
|
-
const
|
|
2236
|
+
const prefix = basePath ? `${basePath}/` : "/";
|
|
2237
|
+
const paths = createBasePaths(prefix);
|
|
2238
|
+
const schemaEntries = addPerToolPaths(specs, prefix, paths);
|
|
2239
|
+
return {
|
|
2240
|
+
openapi: "3.0.3",
|
|
2241
|
+
info: { title, version },
|
|
2242
|
+
paths,
|
|
2243
|
+
components: {
|
|
2244
|
+
schemas: Object.fromEntries(schemaEntries)
|
|
2245
|
+
}
|
|
2246
|
+
};
|
|
2247
|
+
}
|
|
2248
|
+
function createToolNamesSchema() {
|
|
2249
|
+
return {
|
|
2237
2250
|
type: "object",
|
|
2238
2251
|
required: ["tools"],
|
|
2239
2252
|
properties: {
|
|
@@ -2250,7 +2263,9 @@ function toolsToOpenAPISpec(registry, options = {}) {
|
|
|
2250
2263
|
}
|
|
2251
2264
|
}
|
|
2252
2265
|
};
|
|
2253
|
-
|
|
2266
|
+
}
|
|
2267
|
+
function createInvokeRequestBodySchema() {
|
|
2268
|
+
return {
|
|
2254
2269
|
type: "object",
|
|
2255
2270
|
required: ["tool", "args"],
|
|
2256
2271
|
properties: {
|
|
@@ -2262,8 +2277,9 @@ function toolsToOpenAPISpec(registry, options = {}) {
|
|
|
2262
2277
|
}
|
|
2263
2278
|
}
|
|
2264
2279
|
};
|
|
2265
|
-
|
|
2266
|
-
|
|
2280
|
+
}
|
|
2281
|
+
function createBasePaths(prefix) {
|
|
2282
|
+
return {
|
|
2267
2283
|
[`${prefix}tools`]: {
|
|
2268
2284
|
get: {
|
|
2269
2285
|
summary: "List tools",
|
|
@@ -2272,11 +2288,7 @@ function toolsToOpenAPISpec(registry, options = {}) {
|
|
|
2272
2288
|
responses: {
|
|
2273
2289
|
"200": {
|
|
2274
2290
|
description: "List of tools",
|
|
2275
|
-
content: {
|
|
2276
|
-
"application/json": {
|
|
2277
|
-
schema: toolNamesSchema
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2291
|
+
content: { "application/json": { schema: createToolNamesSchema() } }
|
|
2280
2292
|
}
|
|
2281
2293
|
}
|
|
2282
2294
|
}
|
|
@@ -2288,62 +2300,42 @@ function toolsToOpenAPISpec(registry, options = {}) {
|
|
|
2288
2300
|
operationId: "invokeTool",
|
|
2289
2301
|
requestBody: {
|
|
2290
2302
|
required: true,
|
|
2291
|
-
content: {
|
|
2292
|
-
"application/json": {
|
|
2293
|
-
schema: invokeRequestBody
|
|
2294
|
-
}
|
|
2295
|
-
}
|
|
2303
|
+
content: { "application/json": { schema: createInvokeRequestBodySchema() } }
|
|
2296
2304
|
},
|
|
2297
2305
|
responses: {
|
|
2298
|
-
"200": {
|
|
2299
|
-
|
|
2300
|
-
content: { "application/json": { schema: resultSchema } }
|
|
2301
|
-
},
|
|
2302
|
-
"400": {
|
|
2303
|
-
description: "Bad request",
|
|
2304
|
-
content: { "application/json": { schema: errorSchema } }
|
|
2305
|
-
}
|
|
2306
|
+
"200": { description: "Tool result", content: { "application/json": { schema: resultSchema } } },
|
|
2307
|
+
"400": { description: "Bad request", content: { "application/json": { schema: errorSchema } } }
|
|
2306
2308
|
}
|
|
2307
2309
|
}
|
|
2308
2310
|
}
|
|
2309
2311
|
};
|
|
2312
|
+
}
|
|
2313
|
+
function addPerToolPaths(specs, prefix, paths) {
|
|
2310
2314
|
const schemaEntries = [];
|
|
2311
|
-
for (const
|
|
2312
|
-
const key = toolSchemaKey(
|
|
2313
|
-
schemaEntries.push([key,
|
|
2314
|
-
|
|
2315
|
-
paths[`${prefix}invoke/${slug}`] = {
|
|
2316
|
-
post: {
|
|
2317
|
-
summary: s.description ?? s.name,
|
|
2318
|
-
description: `Invoke tool \`${s.name}\`. Request body is the tool's arguments (JSON Schema below).`,
|
|
2319
|
-
operationId: `invoke_${key}`,
|
|
2320
|
-
requestBody: {
|
|
2321
|
-
required: true,
|
|
2322
|
-
content: {
|
|
2323
|
-
"application/json": {
|
|
2324
|
-
schema: { $ref: `#/components/schemas/${key}` }
|
|
2325
|
-
}
|
|
2326
|
-
}
|
|
2327
|
-
},
|
|
2328
|
-
responses: {
|
|
2329
|
-
"200": {
|
|
2330
|
-
description: "Tool result",
|
|
2331
|
-
content: { "application/json": { schema: resultSchema } }
|
|
2332
|
-
},
|
|
2333
|
-
"400": {
|
|
2334
|
-
description: "Bad request (invalid args or tool error)",
|
|
2335
|
-
content: { "application/json": { schema: errorSchema } }
|
|
2336
|
-
}
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
};
|
|
2315
|
+
for (const spec of specs) {
|
|
2316
|
+
const key = toolSchemaKey(spec.name);
|
|
2317
|
+
schemaEntries.push([key, spec.inputSchema]);
|
|
2318
|
+
paths[`${prefix}invoke/${toolNameToSlug(spec.name)}`] = createPerToolPathSpec(spec, key);
|
|
2340
2319
|
}
|
|
2320
|
+
return schemaEntries;
|
|
2321
|
+
}
|
|
2322
|
+
function createPerToolPathSpec(spec, key) {
|
|
2341
2323
|
return {
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2324
|
+
post: {
|
|
2325
|
+
summary: spec.description ?? spec.name,
|
|
2326
|
+
description: `Invoke tool \`${spec.name}\`. Request body is the tool's arguments (JSON Schema below).`,
|
|
2327
|
+
operationId: `invoke_${key}`,
|
|
2328
|
+
requestBody: {
|
|
2329
|
+
required: true,
|
|
2330
|
+
content: { "application/json": { schema: { $ref: `#/components/schemas/${key}` } } }
|
|
2331
|
+
},
|
|
2332
|
+
responses: {
|
|
2333
|
+
"200": { description: "Tool result", content: { "application/json": { schema: resultSchema } } },
|
|
2334
|
+
"400": {
|
|
2335
|
+
description: "Bad request (invalid args or tool error)",
|
|
2336
|
+
content: { "application/json": { schema: errorSchema } }
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2347
2339
|
}
|
|
2348
2340
|
};
|
|
2349
2341
|
}
|
|
@@ -2452,117 +2444,118 @@ function swaggerUiHtml(specUrl) {
|
|
|
2452
2444
|
function createOpenAPIHttpServer(runtime, options = {}) {
|
|
2453
2445
|
const basePath = (options.basePath ?? "").replace(/\/$/, "");
|
|
2454
2446
|
const ctxFactory = options.execContextFactory ?? (() => ({ ...DEFAULT_CTX }));
|
|
2455
|
-
const server = http.createServer(
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
const norm = basePath ? path === basePath ? "" : path.replace(basePath, "") || "/" : path;
|
|
2459
|
-
try {
|
|
2460
|
-
if (req.method === "GET" && (norm === "/" || norm === "/swagger")) {
|
|
2461
|
-
const specPath = basePath ? `${basePath}/openapi.json` : "/openapi.json";
|
|
2462
|
-
const html = swaggerUiHtml(specPath);
|
|
2463
|
-
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
2464
|
-
res.end(html);
|
|
2465
|
-
return;
|
|
2466
|
-
}
|
|
2467
|
-
if (req.method === "GET" && (norm === "/openapi.json" || norm === "/spec")) {
|
|
2468
|
-
const spec = toolsToOpenAPISpec(runtime.getRegistry(), {
|
|
2469
|
-
title: "Tool API",
|
|
2470
|
-
version: "1.0.0",
|
|
2471
|
-
basePath: basePath || void 0
|
|
2472
|
-
});
|
|
2473
|
-
sendJson(res, 200, spec);
|
|
2474
|
-
return;
|
|
2475
|
-
}
|
|
2476
|
-
if (req.method === "GET" && norm === "/tools") {
|
|
2477
|
-
const { enrichSpecWithCanonicalSchema: enrichSpecWithCanonicalSchema2 } = await import('./canonicalCoreSchemas-TY7NCWCC.cjs');
|
|
2478
|
-
const specs = runtime.getRegistry().snapshot().map(enrichSpecWithCanonicalSchema2);
|
|
2479
|
-
const tools = specs.map((s) => ({
|
|
2480
|
-
name: s.name,
|
|
2481
|
-
description: s.description,
|
|
2482
|
-
kind: s.kind,
|
|
2483
|
-
inputSchema: s.inputSchema
|
|
2484
|
-
}));
|
|
2485
|
-
sendJson(res, 200, { tools });
|
|
2486
|
-
return;
|
|
2487
|
-
}
|
|
2488
|
-
if (req.method === "POST" && norm === "/invoke") {
|
|
2489
|
-
let body;
|
|
2490
|
-
try {
|
|
2491
|
-
body = await parseBody(req);
|
|
2492
|
-
} catch (err) {
|
|
2493
|
-
const hint = err instanceof BodyParseError ? err.hint : void 0;
|
|
2494
|
-
sendJson(res, 400, {
|
|
2495
|
-
ok: false,
|
|
2496
|
-
error: "Invalid JSON body",
|
|
2497
|
-
kind: "BAD_REQUEST",
|
|
2498
|
-
...hint ? { hint } : {}
|
|
2499
|
-
});
|
|
2500
|
-
return;
|
|
2501
|
-
}
|
|
2502
|
-
const tool = body?.tool;
|
|
2503
|
-
const args = body?.args ?? {};
|
|
2504
|
-
if (typeof tool !== "string" || !tool.trim()) {
|
|
2505
|
-
sendJson(res, 400, { error: "Missing or invalid 'tool' in body", kind: "BAD_REQUEST" });
|
|
2506
|
-
return;
|
|
2507
|
-
}
|
|
2508
|
-
const ctx = ctxFactory(req);
|
|
2509
|
-
const result = await runtime.invoke(
|
|
2510
|
-
{ tool: tool.trim(), args, purpose: "openapi" },
|
|
2511
|
-
ctx
|
|
2512
|
-
);
|
|
2513
|
-
if (result.ok) {
|
|
2514
|
-
sendJson(res, 200, { result: result.result });
|
|
2515
|
-
return;
|
|
2516
|
-
}
|
|
2517
|
-
sendJson(res, 400, {
|
|
2518
|
-
error: result.error?.message ?? "Tool failed",
|
|
2519
|
-
kind: result.error?.kind,
|
|
2520
|
-
details: result.error?.details
|
|
2521
|
-
});
|
|
2522
|
-
return;
|
|
2523
|
-
}
|
|
2524
|
-
if (req.method === "POST" && norm.startsWith("/invoke/") && norm.length > "/invoke/".length) {
|
|
2525
|
-
const slug = norm.slice("/invoke/".length);
|
|
2526
|
-
const toolName = slugToToolName(slug);
|
|
2527
|
-
let args;
|
|
2528
|
-
let hint;
|
|
2529
|
-
try {
|
|
2530
|
-
args = await parseBody(req);
|
|
2531
|
-
} catch (err) {
|
|
2532
|
-
hint = err instanceof BodyParseError ? err.hint : void 0;
|
|
2533
|
-
sendJson(res, 400, {
|
|
2534
|
-
ok: false,
|
|
2535
|
-
error: "Invalid JSON body",
|
|
2536
|
-
kind: "BAD_REQUEST",
|
|
2537
|
-
...hint ? { hint } : {}
|
|
2538
|
-
});
|
|
2539
|
-
return;
|
|
2540
|
-
}
|
|
2541
|
-
const ctx = ctxFactory(req);
|
|
2542
|
-
const result = await runtime.invoke(
|
|
2543
|
-
{ tool: toolName, args: args ?? {}, purpose: "openapi" },
|
|
2544
|
-
ctx
|
|
2545
|
-
);
|
|
2546
|
-
if (result.ok) {
|
|
2547
|
-
sendJson(res, 200, { result: result.result });
|
|
2548
|
-
return;
|
|
2549
|
-
}
|
|
2550
|
-
sendJson(res, 400, {
|
|
2551
|
-
error: result.error?.message ?? "Tool failed",
|
|
2552
|
-
kind: result.error?.kind,
|
|
2553
|
-
details: result.error?.details
|
|
2554
|
-
});
|
|
2555
|
-
return;
|
|
2556
|
-
}
|
|
2557
|
-
res.writeHead(404, { "Content-Type": "application/json" });
|
|
2558
|
-
res.end(JSON.stringify({ error: "Not found", path: norm }));
|
|
2559
|
-
} catch (err) {
|
|
2560
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
2561
|
-
sendJson(res, 500, { error: message, kind: "INTERNAL_ERROR" });
|
|
2562
|
-
}
|
|
2563
|
-
});
|
|
2447
|
+
const server = http.createServer(
|
|
2448
|
+
(req, res) => handleOpenApiHttpRequest({ runtime, req, res, basePath, ctxFactory })
|
|
2449
|
+
);
|
|
2564
2450
|
return server;
|
|
2565
2451
|
}
|
|
2452
|
+
async function handleOpenApiHttpRequest(input) {
|
|
2453
|
+
const norm = normalizePath(input.req.url, input.basePath);
|
|
2454
|
+
try {
|
|
2455
|
+
if (await maybeHandleDocsRoute(input, norm)) return;
|
|
2456
|
+
if (await maybeHandleToolsRoute(input, norm)) return;
|
|
2457
|
+
if (await maybeHandleInvokeRoute(input, norm)) return;
|
|
2458
|
+
sendJson(input.res, 404, { error: "Not found", path: norm });
|
|
2459
|
+
} catch (err) {
|
|
2460
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
2461
|
+
sendJson(input.res, 500, { error: message, kind: "INTERNAL_ERROR" });
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
function normalizePath(url, basePath) {
|
|
2465
|
+
const path = (url ?? "/").split("?")[0] ?? "/";
|
|
2466
|
+
return basePath ? path === basePath ? "" : path.replace(basePath, "") || "/" : path;
|
|
2467
|
+
}
|
|
2468
|
+
async function maybeHandleDocsRoute(input, norm) {
|
|
2469
|
+
if (input.req.method === "GET" && (norm === "/" || norm === "/swagger")) {
|
|
2470
|
+
const specPath = input.basePath ? `${input.basePath}/openapi.json` : "/openapi.json";
|
|
2471
|
+
input.res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
2472
|
+
input.res.end(swaggerUiHtml(specPath));
|
|
2473
|
+
return true;
|
|
2474
|
+
}
|
|
2475
|
+
if (input.req.method === "GET" && (norm === "/openapi.json" || norm === "/spec")) {
|
|
2476
|
+
sendJson(
|
|
2477
|
+
input.res,
|
|
2478
|
+
200,
|
|
2479
|
+
toolsToOpenAPISpec(input.runtime.getRegistry(), {
|
|
2480
|
+
title: "Tool API",
|
|
2481
|
+
version: "1.0.0",
|
|
2482
|
+
basePath: input.basePath || void 0
|
|
2483
|
+
})
|
|
2484
|
+
);
|
|
2485
|
+
return true;
|
|
2486
|
+
}
|
|
2487
|
+
return false;
|
|
2488
|
+
}
|
|
2489
|
+
async function maybeHandleToolsRoute(input, norm) {
|
|
2490
|
+
if (input.req.method !== "GET" || norm !== "/tools") return false;
|
|
2491
|
+
const { enrichSpecWithCanonicalSchema: enrichSpecWithCanonicalSchema2 } = await import('./canonicalCoreSchemas-TY7NCWCC.cjs');
|
|
2492
|
+
const tools = input.runtime.getRegistry().snapshot().map(enrichSpecWithCanonicalSchema2).map((s) => ({
|
|
2493
|
+
name: s.name,
|
|
2494
|
+
description: s.description,
|
|
2495
|
+
kind: s.kind,
|
|
2496
|
+
inputSchema: s.inputSchema
|
|
2497
|
+
}));
|
|
2498
|
+
sendJson(input.res, 200, { tools });
|
|
2499
|
+
return true;
|
|
2500
|
+
}
|
|
2501
|
+
async function maybeHandleInvokeRoute(input, norm) {
|
|
2502
|
+
if (input.req.method !== "POST") return false;
|
|
2503
|
+
if (norm === "/invoke") {
|
|
2504
|
+
const body = await parseBodyOrSendError(input.req, input.res);
|
|
2505
|
+
if (!body) return true;
|
|
2506
|
+
const tool = body.tool;
|
|
2507
|
+
if (typeof tool !== "string" || !tool.trim()) {
|
|
2508
|
+
sendJson(input.res, 400, { error: "Missing or invalid 'tool' in body", kind: "BAD_REQUEST" });
|
|
2509
|
+
return true;
|
|
2510
|
+
}
|
|
2511
|
+
await invokeAndSend(input.runtime, input.ctxFactory(input.req), input.res, tool.trim(), body.args ?? {});
|
|
2512
|
+
return true;
|
|
2513
|
+
}
|
|
2514
|
+
if (norm.startsWith("/invoke/") && norm.length > "/invoke/".length) {
|
|
2515
|
+
const args = await parseArgsOrSendError(input.req, input.res);
|
|
2516
|
+
if (args === void 0) return true;
|
|
2517
|
+
await invokeAndSend(input.runtime, input.ctxFactory(input.req), input.res, slugToToolName(norm.slice(8)), args);
|
|
2518
|
+
return true;
|
|
2519
|
+
}
|
|
2520
|
+
return false;
|
|
2521
|
+
}
|
|
2522
|
+
async function parseBodyOrSendError(req, res) {
|
|
2523
|
+
try {
|
|
2524
|
+
return await parseBody(req);
|
|
2525
|
+
} catch (err) {
|
|
2526
|
+
sendBadJsonBody(res, err);
|
|
2527
|
+
return null;
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
async function parseArgsOrSendError(req, res) {
|
|
2531
|
+
try {
|
|
2532
|
+
return await parseBody(req) ?? {};
|
|
2533
|
+
} catch (err) {
|
|
2534
|
+
sendBadJsonBody(res, err);
|
|
2535
|
+
return void 0;
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
function sendBadJsonBody(res, err) {
|
|
2539
|
+
const hint = err instanceof BodyParseError ? err.hint : void 0;
|
|
2540
|
+
sendJson(res, 400, {
|
|
2541
|
+
ok: false,
|
|
2542
|
+
error: "Invalid JSON body",
|
|
2543
|
+
kind: "BAD_REQUEST",
|
|
2544
|
+
...hint ? { hint } : {}
|
|
2545
|
+
});
|
|
2546
|
+
}
|
|
2547
|
+
async function invokeAndSend(runtime, ctx, res, tool, args) {
|
|
2548
|
+
const result = await runtime.invoke({ tool, args, purpose: "openapi" }, ctx);
|
|
2549
|
+
if (result.ok) {
|
|
2550
|
+
sendJson(res, 200, { result: result.result });
|
|
2551
|
+
return;
|
|
2552
|
+
}
|
|
2553
|
+
sendJson(res, 400, {
|
|
2554
|
+
error: result.error?.message ?? "Tool failed",
|
|
2555
|
+
kind: result.error?.kind,
|
|
2556
|
+
details: result.error?.details
|
|
2557
|
+
});
|
|
2558
|
+
}
|
|
2566
2559
|
function listenOpenAPIHttpServer(server, options = {}) {
|
|
2567
2560
|
return new Promise((resolve4, reject) => {
|
|
2568
2561
|
const port = options.port ?? 0;
|
|
@@ -2628,7 +2621,7 @@ async function createMcpServerWithTools(runtime, options) {
|
|
|
2628
2621
|
async (args) => {
|
|
2629
2622
|
const ctx = ctxFactory();
|
|
2630
2623
|
const result = await runtime.invoke(
|
|
2631
|
-
{ tool: spec.name, args: args ?? {}, purpose:
|
|
2624
|
+
{ tool: spec.name, args: args ?? {}, purpose: chunk33N4Y6IS_cjs.MCP_KIND },
|
|
2632
2625
|
ctx
|
|
2633
2626
|
);
|
|
2634
2627
|
if (result.ok) {
|
|
@@ -2738,5 +2731,5 @@ exports.npmDescriptorToPackagePrefixWithVersion = npmDescriptorToPackagePrefixWi
|
|
|
2738
2731
|
exports.resolveSandboxedPath = resolveSandboxedPath;
|
|
2739
2732
|
exports.resolveToolDescriptor = resolveToolDescriptor;
|
|
2740
2733
|
exports.runMCPServerOverStdio = runMCPServerOverStdio;
|
|
2741
|
-
//# sourceMappingURL=chunk-
|
|
2742
|
-
//# sourceMappingURL=chunk-
|
|
2734
|
+
//# sourceMappingURL=chunk-SE6IMOIE.cjs.map
|
|
2735
|
+
//# sourceMappingURL=chunk-SE6IMOIE.cjs.map
|