@acid-cat/spec-ts 0.2.0 → 0.3.1
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.d.ts +10 -0
- package/dist/index.js +36 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -58,6 +58,16 @@ export declare const CLI_EXIT_CODES: {
|
|
|
58
58
|
readonly cancelled: 130;
|
|
59
59
|
};
|
|
60
60
|
export declare const cliExitCode: (outcome: Outcome<unknown, unknown>) => number;
|
|
61
|
+
/**
|
|
62
|
+
* The flags of a command, as `usage` writes them (spec/bindings/cli.md#commands): required flags first, each group in
|
|
63
|
+
* code point order of the names. `input` is the bundled input schema.
|
|
64
|
+
*/
|
|
65
|
+
export declare function cliFlags(input: JsonObject): string[];
|
|
66
|
+
/**
|
|
67
|
+
* The `usage` of a capability in `list` (spec/bindings/cli.md#commands). `input` is the bundled input schema, or
|
|
68
|
+
* `undefined` when the capability has no input.
|
|
69
|
+
*/
|
|
70
|
+
export declare function cliUsage(program: string, id: string, input: JsonObject | undefined): string;
|
|
61
71
|
export declare const HTTP_STATUS: {
|
|
62
72
|
readonly "unknown-capability": 404;
|
|
63
73
|
readonly "invalid-input": 422;
|
package/dist/index.js
CHANGED
|
@@ -60,6 +60,41 @@ const CLI_EXIT_CODES = {
|
|
|
60
60
|
cancelled: 130
|
|
61
61
|
};
|
|
62
62
|
const cliExitCode = (outcome) => isCallFailure(outcome) ? CLI_EXIT_CODES[outcome.kind] : outcome.ok ? CLI_EXIT_CODES.value : CLI_EXIT_CODES.failure;
|
|
63
|
+
/**
|
|
64
|
+
* The flags of a command, as `usage` writes them (spec/bindings/cli.md#commands): required flags first, each group in
|
|
65
|
+
* code point order of the names. `input` is the bundled input schema.
|
|
66
|
+
*/
|
|
67
|
+
function cliFlags(input) {
|
|
68
|
+
const properties = input.properties ?? {};
|
|
69
|
+
const definitions = input.$defs ?? {};
|
|
70
|
+
const required = new Set(input.required ?? []);
|
|
71
|
+
const byName = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
72
|
+
const names = Object.keys(properties).sort(byName);
|
|
73
|
+
return [...names.filter((name) => required.has(name)), ...names.filter((name) => !required.has(name))].map((name) => {
|
|
74
|
+
const reference = properties[name].$ref;
|
|
75
|
+
const target = typeof reference === "string" ? REFERENCE.exec(reference)?.[1] : void 0;
|
|
76
|
+
const property = (target === void 0 ? void 0 : definitions[target]) ?? properties[name];
|
|
77
|
+
const flag = property.type === "boolean" ? `--${name}` : `--${name} <${flagValue(property)}>`;
|
|
78
|
+
return required.has(name) ? flag : `[${flag}]`;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function flagValue(property) {
|
|
82
|
+
if (Array.isArray(property.enum) && property.enum.every((value) => typeof value === "string")) return property.enum.join("|");
|
|
83
|
+
if (property.type === "integer" || property.type === "number" || property.type === "string") return property.type;
|
|
84
|
+
return "json";
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The `usage` of a capability in `list` (spec/bindings/cli.md#commands). `input` is the bundled input schema, or
|
|
88
|
+
* `undefined` when the capability has no input.
|
|
89
|
+
*/
|
|
90
|
+
function cliUsage(program, id, input) {
|
|
91
|
+
if (input !== void 0 && input.properties === void 0) return `${program} call ${id} '<json>'`;
|
|
92
|
+
return [
|
|
93
|
+
program,
|
|
94
|
+
...commandPath(id),
|
|
95
|
+
...input === void 0 ? [] : cliFlags(input)
|
|
96
|
+
].join(" ");
|
|
97
|
+
}
|
|
63
98
|
const HTTP_STATUS = {
|
|
64
99
|
"unknown-capability": 404,
|
|
65
100
|
"invalid-input": 422,
|
|
@@ -211,4 +246,4 @@ function viewOf(catalog, target) {
|
|
|
211
246
|
};
|
|
212
247
|
}
|
|
213
248
|
//#endregion
|
|
214
|
-
export { AVAILABLE, CALL_FAILURE_KINDS, CLI_EXIT_CODES, CallFailureError, HTTP_STATUS, ID_PATTERN, MCP_PROTOCOL_VERSION, MCP_REJECTIONS, MCP_UNKNOWN_TOOL, REFERENCE, bundle, callFailure, cliExitCode, commandPath, fail, httpStatus, isCallFailure, isId, mcpToolResult, ok, readBounded, schemasOf, screenRequest, typesUsedBy, unavailable, viewOf, visitObjects };
|
|
249
|
+
export { AVAILABLE, CALL_FAILURE_KINDS, CLI_EXIT_CODES, CallFailureError, HTTP_STATUS, ID_PATTERN, MCP_PROTOCOL_VERSION, MCP_REJECTIONS, MCP_UNKNOWN_TOOL, REFERENCE, bundle, callFailure, cliExitCode, cliFlags, cliUsage, commandPath, fail, httpStatus, isCallFailure, isId, mcpToolResult, ok, readBounded, schemasOf, screenRequest, typesUsedBy, unavailable, viewOf, visitObjects };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acid-cat/spec-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "The fixed details of the AcidCat specification as TypeScript data and pure functions, with no dependencies. Part of the TypeScript reference implementation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"acidcat",
|