@supacloud/cli 0.42.0 → 0.43.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/index.js +147 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -238837,7 +238837,7 @@ var ACTION_POLICY = {
|
|
|
238837
238837
|
write: ["send", "receive", "ack", "release", "fail", "retry", "delete_message", "update_settings"]
|
|
238838
238838
|
},
|
|
238839
238839
|
ai: { local: ["show_skill", "install_skill"] },
|
|
238840
|
-
app: { local: ["generate", "compile", "check", "graph", "explain"] },
|
|
238840
|
+
app: { local: ["generate", "compile", "check", "graph", "explain", "export-tools"] },
|
|
238841
238841
|
db: { local: ["lint", "explain"], read: ["module_check"] },
|
|
238842
238842
|
dev: { read: ["status"], write: ["sync", "watch", "migrate"] }
|
|
238843
238843
|
};
|
|
@@ -247665,6 +247665,120 @@ async function compileProject(options) {
|
|
|
247665
247665
|
return { diagnostics, graph, written };
|
|
247666
247666
|
}
|
|
247667
247667
|
|
|
247668
|
+
// src/shared/tools/app-tool-export.ts
|
|
247669
|
+
function sanitizeToolName(name) {
|
|
247670
|
+
const sanitized = name.replace(/[^a-zA-Z0-9_]/g, "_").slice(0, 64);
|
|
247671
|
+
return sanitized || "supacloud_command";
|
|
247672
|
+
}
|
|
247673
|
+
function uniqueToolName(name, moduleName, used) {
|
|
247674
|
+
const base = sanitizeToolName(name);
|
|
247675
|
+
if (!used.has(base)) {
|
|
247676
|
+
used.add(base);
|
|
247677
|
+
return base;
|
|
247678
|
+
}
|
|
247679
|
+
const prefix = sanitizeToolName(moduleName).slice(0, 32);
|
|
247680
|
+
const candidateBase = `${prefix}_${base}`.slice(0, 64);
|
|
247681
|
+
let candidate = candidateBase;
|
|
247682
|
+
let suffix = 2;
|
|
247683
|
+
while (used.has(candidate)) {
|
|
247684
|
+
candidate = `${candidateBase.slice(0, 64 - String(suffix).length - 1)}_${suffix}`;
|
|
247685
|
+
suffix += 1;
|
|
247686
|
+
}
|
|
247687
|
+
used.add(candidate);
|
|
247688
|
+
return candidate;
|
|
247689
|
+
}
|
|
247690
|
+
function findRouteForCommand(manifest, commandClassName) {
|
|
247691
|
+
for (const module of manifest.modules) {
|
|
247692
|
+
for (const controller of module.controllers) {
|
|
247693
|
+
for (const route of controller.routes) {
|
|
247694
|
+
if (route.command !== commandClassName)
|
|
247695
|
+
continue;
|
|
247696
|
+
return {
|
|
247697
|
+
httpMethod: route.method,
|
|
247698
|
+
path: `${controller.path}${route.path}`,
|
|
247699
|
+
bodySchema: route.body,
|
|
247700
|
+
paramsSchema: route.params,
|
|
247701
|
+
querySchema: route.query
|
|
247702
|
+
};
|
|
247703
|
+
}
|
|
247704
|
+
}
|
|
247705
|
+
}
|
|
247706
|
+
return;
|
|
247707
|
+
}
|
|
247708
|
+
function inputSchema(route) {
|
|
247709
|
+
const properties = {};
|
|
247710
|
+
if (route?.bodySchema) {
|
|
247711
|
+
properties.body = {
|
|
247712
|
+
type: "object",
|
|
247713
|
+
description: `Request body. Schema reference: ${route.bodySchema}`,
|
|
247714
|
+
additionalProperties: true
|
|
247715
|
+
};
|
|
247716
|
+
}
|
|
247717
|
+
if (route?.paramsSchema) {
|
|
247718
|
+
properties.params = {
|
|
247719
|
+
type: "object",
|
|
247720
|
+
description: `Path parameters. Schema reference: ${route.paramsSchema}`,
|
|
247721
|
+
additionalProperties: true
|
|
247722
|
+
};
|
|
247723
|
+
}
|
|
247724
|
+
if (route?.querySchema) {
|
|
247725
|
+
properties.query = {
|
|
247726
|
+
type: "object",
|
|
247727
|
+
description: `Query parameters. Schema reference: ${route.querySchema}`,
|
|
247728
|
+
additionalProperties: true
|
|
247729
|
+
};
|
|
247730
|
+
}
|
|
247731
|
+
return {
|
|
247732
|
+
type: "object",
|
|
247733
|
+
properties,
|
|
247734
|
+
required: [],
|
|
247735
|
+
additionalProperties: Object.keys(properties).length === 0
|
|
247736
|
+
};
|
|
247737
|
+
}
|
|
247738
|
+
function descriptionForCommand(command, route) {
|
|
247739
|
+
const parts = [`Command ${command.name}`, `permission ${command.permission}`];
|
|
247740
|
+
if (command.transaction === "required")
|
|
247741
|
+
parts.push("transaction required");
|
|
247742
|
+
if (command.idempotency === "required")
|
|
247743
|
+
parts.push("idempotent");
|
|
247744
|
+
if (command.audit)
|
|
247745
|
+
parts.push(`audit ${command.audit}`);
|
|
247746
|
+
if (route)
|
|
247747
|
+
parts.push(`HTTP ${route.httpMethod} ${route.path}`);
|
|
247748
|
+
return `${parts.join("; ")}.`;
|
|
247749
|
+
}
|
|
247750
|
+
function buildToolDefinitions(manifest) {
|
|
247751
|
+
const openai = [];
|
|
247752
|
+
const mcp = [];
|
|
247753
|
+
const usedNames = new Set;
|
|
247754
|
+
for (const module of manifest.modules) {
|
|
247755
|
+
for (const command of module.commands) {
|
|
247756
|
+
if (!command.permission)
|
|
247757
|
+
continue;
|
|
247758
|
+
const route = findRouteForCommand(manifest, command.className);
|
|
247759
|
+
const name = uniqueToolName(command.name, module.name, usedNames);
|
|
247760
|
+
const description = descriptionForCommand(command, route);
|
|
247761
|
+
const parameters = inputSchema(route);
|
|
247762
|
+
openai.push({
|
|
247763
|
+
type: "function",
|
|
247764
|
+
function: { name, description, parameters }
|
|
247765
|
+
});
|
|
247766
|
+
mcp.push({
|
|
247767
|
+
name,
|
|
247768
|
+
description,
|
|
247769
|
+
inputSchema: parameters,
|
|
247770
|
+
annotations: {
|
|
247771
|
+
readOnly: false,
|
|
247772
|
+
audited: !!command.audit,
|
|
247773
|
+
permission: command.permission,
|
|
247774
|
+
...route ? { httpPath: route.path, httpMethod: route.httpMethod } : {}
|
|
247775
|
+
}
|
|
247776
|
+
});
|
|
247777
|
+
}
|
|
247778
|
+
}
|
|
247779
|
+
return { openai, mcp };
|
|
247780
|
+
}
|
|
247781
|
+
|
|
247668
247782
|
// src/shared/tools/app-tools.ts
|
|
247669
247783
|
function textResult(text, isError = false) {
|
|
247670
247784
|
return { isError, content: [{ type: "text", text }] };
|
|
@@ -247969,19 +248083,43 @@ async function runExplain(args) {
|
|
|
247969
248083
|
}
|
|
247970
248084
|
return textResult(`未找到对象: ${target}`, true);
|
|
247971
248085
|
}
|
|
248086
|
+
async function runExportTools(args) {
|
|
248087
|
+
const root = resolve7(args.root || process.cwd());
|
|
248088
|
+
const manifest = await readManifest(root);
|
|
248089
|
+
const definitions = buildToolDefinitions(manifest);
|
|
248090
|
+
const outDir = resolve7(args.out_dir || join7(root, "generated"));
|
|
248091
|
+
await mkdir2(outDir, { recursive: true });
|
|
248092
|
+
if (args.format === "json") {
|
|
248093
|
+
return textResult(JSON.stringify(definitions, null, 2));
|
|
248094
|
+
}
|
|
248095
|
+
const openaiPath = join7(outDir, "tool-definitions.openai.json");
|
|
248096
|
+
const mcpPath = join7(outDir, "tool-definitions.mcp.json");
|
|
248097
|
+
await writeFile2(openaiPath, JSON.stringify(definitions.openai, null, 2), "utf8");
|
|
248098
|
+
await writeFile2(mcpPath, JSON.stringify(definitions.mcp, null, 2), "utf8");
|
|
248099
|
+
const summary = [
|
|
248100
|
+
`exported ${definitions.openai.length} tool(s):`,
|
|
248101
|
+
` openai → ${openaiPath}`,
|
|
248102
|
+
` mcp → ${mcpPath}`,
|
|
248103
|
+
"",
|
|
248104
|
+
definitions.openai.map((t) => ` ${t.function.name}`).join(`
|
|
248105
|
+
`)
|
|
248106
|
+
].join(`
|
|
248107
|
+
`);
|
|
248108
|
+
return textResult(summary);
|
|
248109
|
+
}
|
|
247972
248110
|
function registerAppTools(server2) {
|
|
247973
|
-
server2.tool("app", "Local @supacloud/app framework commands: scaffold, compile, check, graph and
|
|
247974
|
-
action: withDescription(stringEnum(["generate", "compile", "check", "graph", "explain"]), "App action"),
|
|
248111
|
+
server2.tool("app", "Local @supacloud/app framework commands: scaffold, compile, check, graph, explain and export-tools. Actions: generate, compile, check, graph, explain, export-tools", {
|
|
248112
|
+
action: withDescription(stringEnum(["generate", "compile", "check", "graph", "explain", "export-tools"]), "App action"),
|
|
247975
248113
|
kind: optional(stringEnum(["module", "command", "query", "controller"]), "[generate] Scaffold kind"),
|
|
247976
248114
|
name: optional(Type.String(), "[generate] Object name (module name / command / query name)"),
|
|
247977
248115
|
module: optional(Type.String(), "[generate] Target feature module (required for command/query/controller)"),
|
|
247978
248116
|
dir: optional(Type.String(), "[generate] Feature root directory (default: src/features)"),
|
|
247979
248117
|
force: optional(Type.Boolean(), "[generate] Overwrite existing files"),
|
|
247980
|
-
root: optional(Type.String(), "[generate/compile/check/graph/explain] Project root (default: current directory)"),
|
|
248118
|
+
root: optional(Type.String(), "[generate/compile/check/graph/explain/export-tools] Project root (default: current directory)"),
|
|
247981
248119
|
include: optional(Type.String(), "[compile/check] Comma-separated glob patterns for source files"),
|
|
247982
|
-
out_dir: optional(Type.String(), "[compile] Output directory (default: <root>/generated)"),
|
|
248120
|
+
out_dir: optional(Type.String(), "[compile/export-tools] Output directory (default: <root>/generated)"),
|
|
247983
248121
|
strict: optional(Type.Boolean(), "[compile/check] Promote warnings to errors"),
|
|
247984
|
-
format: optional(stringEnum(["text", "json"]), "[graph] Output format (default: text)"),
|
|
248122
|
+
format: optional(stringEnum(["text", "json"]), "[graph/export-tools] Output format (default: text)"),
|
|
247985
248123
|
target: optional(Type.String(), "[explain] Provider class name / token name / command name")
|
|
247986
248124
|
}, async (request) => {
|
|
247987
248125
|
switch (request.action) {
|
|
@@ -247995,6 +248133,8 @@ function registerAppTools(server2) {
|
|
|
247995
248133
|
return runGraph(request);
|
|
247996
248134
|
case "explain":
|
|
247997
248135
|
return runExplain(request);
|
|
248136
|
+
case "export-tools":
|
|
248137
|
+
return runExportTools(request);
|
|
247998
248138
|
default:
|
|
247999
248139
|
return textResult(`Unknown app action: ${String(request.action)}`, true);
|
|
248000
248140
|
}
|
|
@@ -251086,7 +251226,7 @@ function registerRemoteDevTools(server2, options = {}) {
|
|
|
251086
251226
|
// package.json
|
|
251087
251227
|
var package_default = {
|
|
251088
251228
|
name: "@supacloud/cli",
|
|
251089
|
-
version: "0.
|
|
251229
|
+
version: "0.43.0",
|
|
251090
251230
|
description: "Project-scoped CLI for SupaCloud users",
|
|
251091
251231
|
type: "module",
|
|
251092
251232
|
main: "./dist/index.js",
|