specli 0.0.11 → 0.0.13
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 +216 -325
- package/bin/cli.sh +27 -0
- package/dist/{src/ai → ai}/tools.d.ts +0 -1
- package/dist/ai/tools.js +161 -0
- package/dist/ai/tools.test.d.ts +1 -0
- package/dist/ai/tools.test.js +56 -0
- package/dist/{src/cli → cli}/auth-requirements.d.ts +0 -1
- package/dist/cli/auth-requirements.js +65 -0
- package/dist/cli/auth-requirements.test.d.ts +1 -0
- package/dist/cli/auth-requirements.test.js +16 -0
- package/dist/{src/cli → cli}/auth-schemes.d.ts +0 -1
- package/dist/cli/auth-schemes.js +112 -0
- package/dist/cli/auth-schemes.test.d.ts +1 -0
- package/dist/cli/auth-schemes.test.js +56 -0
- package/dist/{src/cli → cli}/capabilities.d.ts +0 -1
- package/dist/cli/capabilities.js +41 -0
- package/dist/cli/capabilities.test.d.ts +1 -0
- package/dist/cli/capabilities.test.js +84 -0
- package/dist/{src/cli → cli}/command-id.d.ts +0 -1
- package/dist/cli/command-id.js +8 -0
- package/dist/cli/command-id.test.d.ts +1 -0
- package/dist/cli/command-id.test.js +27 -0
- package/dist/{src/cli → cli}/command-index.d.ts +0 -1
- package/dist/cli/command-index.js +9 -0
- package/dist/{src/cli → cli}/command-model.d.ts +0 -1
- package/dist/cli/command-model.js +53 -0
- package/dist/cli/command-model.test.d.ts +1 -0
- package/dist/cli/command-model.test.js +40 -0
- package/dist/{src/cli → cli}/compile.d.ts +0 -1
- package/dist/cli/compile.js +79 -0
- package/dist/{src/cli → cli}/crypto.d.ts +0 -1
- package/dist/cli/crypto.js +9 -0
- package/dist/{src/cli → cli}/derive-name.d.ts +0 -1
- package/dist/cli/derive-name.js +96 -0
- package/dist/{src/cli → cli}/exec.d.ts +0 -1
- package/dist/cli/exec.js +50 -0
- package/dist/{src/cli → cli}/main.d.ts +0 -1
- package/dist/cli/main.js +177 -0
- package/dist/{src/cli → cli}/naming.d.ts +0 -1
- package/dist/cli/naming.js +191 -0
- package/dist/cli/naming.test.d.ts +1 -0
- package/dist/cli/naming.test.js +75 -0
- package/dist/{src/cli → cli}/operations.d.ts +0 -1
- package/dist/cli/operations.js +100 -0
- package/dist/cli/operations.test.d.ts +1 -0
- package/dist/cli/operations.test.js +51 -0
- package/dist/{src/cli → cli}/params.d.ts +0 -1
- package/dist/cli/params.js +36 -0
- package/dist/cli/params.test.d.ts +1 -0
- package/dist/cli/params.test.js +62 -0
- package/dist/{src/cli → cli}/pluralize.d.ts +0 -1
- package/dist/cli/pluralize.js +38 -0
- package/dist/{src/cli → cli}/positional.d.ts +0 -1
- package/dist/cli/positional.js +35 -0
- package/dist/cli/positional.test.d.ts +1 -0
- package/dist/cli/positional.test.js +60 -0
- package/dist/{src/cli → cli}/request-body.d.ts +0 -1
- package/dist/cli/request-body.js +44 -0
- package/dist/cli/request-body.test.d.ts +1 -0
- package/dist/cli/request-body.test.js +31 -0
- package/dist/{src/cli → cli}/runtime/argv.d.ts +0 -1
- package/dist/cli/runtime/argv.js +15 -0
- package/dist/{src/cli → cli}/runtime/auth/resolve.d.ts +0 -1
- package/dist/cli/runtime/auth/resolve.js +39 -0
- package/dist/{src/cli → cli}/runtime/body-flags.d.ts +0 -1
- package/dist/cli/runtime/body-flags.js +117 -0
- package/dist/cli/runtime/body-flags.test.d.ts +1 -0
- package/dist/cli/runtime/body-flags.test.js +192 -0
- package/dist/{src/cli → cli}/runtime/body.d.ts +0 -1
- package/dist/cli/runtime/body.js +16 -0
- package/dist/{src/cli → cli}/runtime/collect.d.ts +0 -1
- package/dist/cli/runtime/collect.js +3 -0
- package/dist/{src/cli → cli}/runtime/compat.d.ts +0 -1
- package/dist/cli/runtime/compat.js +78 -0
- package/dist/{src/cli → cli}/runtime/context.d.ts +0 -1
- package/dist/cli/runtime/context.js +44 -0
- package/dist/{src/cli → cli}/runtime/execute.d.ts +0 -1
- package/dist/cli/runtime/execute.js +106 -0
- package/dist/{src/cli → cli}/runtime/generated.d.ts +0 -1
- package/dist/cli/runtime/generated.js +168 -0
- package/dist/{src/cli → cli}/runtime/headers.d.ts +0 -1
- package/dist/cli/runtime/headers.js +30 -0
- package/dist/{src/cli → cli}/runtime/index.d.ts +0 -1
- package/dist/cli/runtime/index.js +3 -0
- package/dist/{src/cli → cli}/runtime/profile/secrets.d.ts +0 -1
- package/dist/cli/runtime/profile/secrets.js +53 -0
- package/dist/{src/cli → cli}/runtime/profile/store.d.ts +0 -1
- package/dist/cli/runtime/profile/store.js +63 -0
- package/dist/{src/cli → cli}/runtime/request.d.ts +0 -1
- package/dist/cli/runtime/request.js +283 -0
- package/dist/cli/runtime/request.test.d.ts +1 -0
- package/dist/cli/runtime/request.test.js +332 -0
- package/dist/{src/cli → cli}/runtime/server-url.d.ts +0 -1
- package/dist/cli/runtime/server-url.js +28 -0
- package/dist/{src/cli → cli}/runtime/template.d.ts +0 -1
- package/dist/cli/runtime/template.js +22 -0
- package/dist/cli/runtime/validate/ajv.d.ts +2 -0
- package/dist/cli/runtime/validate/ajv.js +11 -0
- package/dist/{src/cli → cli}/runtime/validate/coerce.d.ts +0 -1
- package/dist/cli/runtime/validate/coerce.js +63 -0
- package/dist/cli/runtime/validate/coerce.test.d.ts +1 -0
- package/dist/cli/runtime/validate/coerce.test.js +75 -0
- package/dist/{src/cli → cli}/runtime/validate/error.d.ts +0 -1
- package/dist/cli/runtime/validate/error.js +19 -0
- package/dist/{src/cli → cli}/runtime/validate/index.d.ts +0 -1
- package/dist/cli/runtime/validate/index.js +4 -0
- package/dist/{src/cli → cli}/runtime/validate/schema.d.ts +0 -1
- package/dist/cli/runtime/validate/schema.js +38 -0
- package/dist/{src/cli → cli}/schema-shape.d.ts +0 -1
- package/dist/cli/schema-shape.js +34 -0
- package/dist/{src/cli → cli}/schema.d.ts +0 -1
- package/dist/cli/schema.js +31 -0
- package/dist/{src/cli → cli}/server.d.ts +0 -1
- package/dist/cli/server.js +130 -0
- package/dist/cli/server.test.d.ts +1 -0
- package/dist/cli/server.test.js +49 -0
- package/dist/{src/cli → cli}/spec-id.d.ts +0 -1
- package/dist/cli/spec-id.js +8 -0
- package/dist/{src/cli → cli}/spec-loader.d.ts +0 -1
- package/dist/cli/spec-loader.js +40 -0
- package/dist/{src/cli → cli}/stable-json.d.ts +0 -1
- package/dist/cli/stable-json.js +29 -0
- package/dist/{src/cli → cli}/strings.d.ts +0 -1
- package/dist/cli/strings.js +20 -0
- package/dist/{src/cli → cli}/types.d.ts +0 -1
- package/dist/cli/types.js +3 -0
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +51 -2324
- package/dist/compiled.d.ts +2 -0
- package/{src/compiled.ts → dist/compiled.js} +8 -11
- package/dist/macros/env.d.ts +10 -0
- package/dist/macros/env.js +22 -0
- package/dist/macros/spec.d.ts +5 -0
- package/dist/macros/spec.js +16 -0
- package/package.json +17 -25
- package/bin/specli.js +0 -26
- package/cli.ts +0 -77
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -53
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -2032
- package/dist/index.js.map +0 -48
- package/dist/src/ai/tools.d.ts.map +0 -1
- package/dist/src/ai/tools.js +0 -1656
- package/dist/src/ai/tools.js.map +0 -45
- package/dist/src/cli/auth-requirements.d.ts.map +0 -1
- package/dist/src/cli/auth-requirements.js +0 -66
- package/dist/src/cli/auth-requirements.js.map +0 -10
- package/dist/src/cli/auth-schemes.d.ts.map +0 -1
- package/dist/src/cli/auth-schemes.js +0 -116
- package/dist/src/cli/auth-schemes.js.map +0 -11
- package/dist/src/cli/capabilities.d.ts.map +0 -1
- package/dist/src/cli/capabilities.js +0 -45
- package/dist/src/cli/capabilities.js.map +0 -10
- package/dist/src/cli/command-id.d.ts.map +0 -1
- package/dist/src/cli/command-id.js +0 -18
- package/dist/src/cli/command-id.js.map +0 -11
- package/dist/src/cli/command-index.d.ts.map +0 -1
- package/dist/src/cli/command-index.js +0 -15
- package/dist/src/cli/command-index.js.map +0 -10
- package/dist/src/cli/command-model.d.ts.map +0 -1
- package/dist/src/cli/command-model.js +0 -274
- package/dist/src/cli/command-model.js.map +0 -18
- package/dist/src/cli/compile.d.ts.map +0 -1
- package/dist/src/cli/compile.js +0 -146
- package/dist/src/cli/compile.js.map +0 -11
- package/dist/src/cli/crypto.d.ts.map +0 -1
- package/dist/src/cli/crypto.js +0 -15
- package/dist/src/cli/crypto.js.map +0 -10
- package/dist/src/cli/derive-name.d.ts.map +0 -1
- package/dist/src/cli/derive-name.js +0 -70
- package/dist/src/cli/derive-name.js.map +0 -10
- package/dist/src/cli/exec.d.ts.map +0 -1
- package/dist/src/cli/exec.js +0 -2077
- package/dist/src/cli/exec.js.map +0 -49
- package/dist/src/cli/main.d.ts.map +0 -1
- package/dist/src/cli/main.js +0 -2032
- package/dist/src/cli/main.js.map +0 -48
- package/dist/src/cli/naming.d.ts.map +0 -1
- package/dist/src/cli/naming.js +0 -216
- package/dist/src/cli/naming.js.map +0 -12
- package/dist/src/cli/operations.d.ts.map +0 -1
- package/dist/src/cli/operations.js +0 -103
- package/dist/src/cli/operations.js.map +0 -10
- package/dist/src/cli/params.d.ts.map +0 -1
- package/dist/src/cli/params.js +0 -79
- package/dist/src/cli/params.js.map +0 -12
- package/dist/src/cli/pluralize.d.ts.map +0 -1
- package/dist/src/cli/pluralize.js +0 -43
- package/dist/src/cli/pluralize.js.map +0 -10
- package/dist/src/cli/positional.d.ts.map +0 -1
- package/dist/src/cli/positional.js +0 -39
- package/dist/src/cli/positional.js.map +0 -10
- package/dist/src/cli/request-body.d.ts.map +0 -1
- package/dist/src/cli/request-body.js +0 -82
- package/dist/src/cli/request-body.js.map +0 -12
- package/dist/src/cli/runtime/argv.d.ts.map +0 -1
- package/dist/src/cli/runtime/argv.js +0 -22
- package/dist/src/cli/runtime/argv.js.map +0 -10
- package/dist/src/cli/runtime/auth/resolve.d.ts.map +0 -1
- package/dist/src/cli/runtime/auth/resolve.js +0 -38
- package/dist/src/cli/runtime/auth/resolve.js.map +0 -10
- package/dist/src/cli/runtime/body-flags.d.ts.map +0 -1
- package/dist/src/cli/runtime/body-flags.js +0 -86
- package/dist/src/cli/runtime/body-flags.js.map +0 -10
- package/dist/src/cli/runtime/body.d.ts.map +0 -1
- package/dist/src/cli/runtime/body.js +0 -40
- package/dist/src/cli/runtime/body.js.map +0 -11
- package/dist/src/cli/runtime/collect.d.ts.map +0 -1
- package/dist/src/cli/runtime/collect.js +0 -9
- package/dist/src/cli/runtime/collect.js.map +0 -10
- package/dist/src/cli/runtime/compat.d.ts.map +0 -1
- package/dist/src/cli/runtime/compat.js +0 -62
- package/dist/src/cli/runtime/compat.js.map +0 -10
- package/dist/src/cli/runtime/context.d.ts.map +0 -1
- package/dist/src/cli/runtime/context.js +0 -936
- package/dist/src/cli/runtime/context.js.map +0 -32
- package/dist/src/cli/runtime/execute.d.ts.map +0 -1
- package/dist/src/cli/runtime/execute.js +0 -670
- package/dist/src/cli/runtime/execute.js.map +0 -22
- package/dist/src/cli/runtime/generated.d.ts.map +0 -1
- package/dist/src/cli/runtime/generated.js +0 -869
- package/dist/src/cli/runtime/generated.js.map +0 -23
- package/dist/src/cli/runtime/headers.d.ts.map +0 -1
- package/dist/src/cli/runtime/headers.js +0 -36
- package/dist/src/cli/runtime/headers.js.map +0 -10
- package/dist/src/cli/runtime/index.d.ts.map +0 -1
- package/dist/src/cli/runtime/index.js +0 -1808
- package/dist/src/cli/runtime/index.js.map +0 -46
- package/dist/src/cli/runtime/profile/secrets.d.ts.map +0 -1
- package/dist/src/cli/runtime/profile/secrets.js +0 -51
- package/dist/src/cli/runtime/profile/secrets.js.map +0 -11
- package/dist/src/cli/runtime/profile/store.d.ts.map +0 -1
- package/dist/src/cli/runtime/profile/store.js +0 -102
- package/dist/src/cli/runtime/profile/store.js.map +0 -11
- package/dist/src/cli/runtime/request.d.ts.map +0 -1
- package/dist/src/cli/runtime/request.js +0 -571
- package/dist/src/cli/runtime/request.js.map +0 -21
- package/dist/src/cli/runtime/server-url.d.ts.map +0 -1
- package/dist/src/cli/runtime/server-url.js +0 -55
- package/dist/src/cli/runtime/server-url.js.map +0 -11
- package/dist/src/cli/runtime/template.d.ts.map +0 -1
- package/dist/src/cli/runtime/template.js +0 -29
- package/dist/src/cli/runtime/template.js.map +0 -10
- package/dist/src/cli/runtime/validate/ajv.d.ts +0 -3
- package/dist/src/cli/runtime/validate/ajv.d.ts.map +0 -1
- package/dist/src/cli/runtime/validate/ajv.js +0 -17
- package/dist/src/cli/runtime/validate/ajv.js.map +0 -10
- package/dist/src/cli/runtime/validate/coerce.d.ts.map +0 -1
- package/dist/src/cli/runtime/validate/coerce.js +0 -60
- package/dist/src/cli/runtime/validate/coerce.js.map +0 -10
- package/dist/src/cli/runtime/validate/error.d.ts.map +0 -1
- package/dist/src/cli/runtime/validate/error.js +0 -21
- package/dist/src/cli/runtime/validate/error.js.map +0 -10
- package/dist/src/cli/runtime/validate/index.d.ts.map +0 -1
- package/dist/src/cli/runtime/validate/index.js +0 -122
- package/dist/src/cli/runtime/validate/index.js.map +0 -13
- package/dist/src/cli/runtime/validate/schema.d.ts.map +0 -1
- package/dist/src/cli/runtime/validate/schema.js +0 -36
- package/dist/src/cli/runtime/validate/schema.js.map +0 -10
- package/dist/src/cli/schema-shape.d.ts.map +0 -1
- package/dist/src/cli/schema-shape.js +0 -41
- package/dist/src/cli/schema-shape.js.map +0 -10
- package/dist/src/cli/schema.d.ts.map +0 -1
- package/dist/src/cli/schema.js +0 -38
- package/dist/src/cli/schema.js.map +0 -10
- package/dist/src/cli/server.d.ts.map +0 -1
- package/dist/src/cli/server.js +0 -64
- package/dist/src/cli/server.js.map +0 -11
- package/dist/src/cli/spec-id.d.ts.map +0 -1
- package/dist/src/cli/spec-id.js +0 -21
- package/dist/src/cli/spec-id.js.map +0 -11
- package/dist/src/cli/spec-loader.d.ts.map +0 -1
- package/dist/src/cli/spec-loader.js +0 -110
- package/dist/src/cli/spec-loader.js.map +0 -15
- package/dist/src/cli/stable-json.d.ts.map +0 -1
- package/dist/src/cli/stable-json.js +0 -35
- package/dist/src/cli/stable-json.js.map +0 -10
- package/dist/src/cli/strings.d.ts.map +0 -1
- package/dist/src/cli/strings.js +0 -16
- package/dist/src/cli/strings.js.map +0 -10
- package/dist/src/cli/types.d.ts.map +0 -1
- package/dist/src/cli/types.js +0 -9
- package/dist/src/cli/types.js.map +0 -10
- package/index.ts +0 -1
- package/src/ai/tools.ts +0 -211
- package/src/cli/auth-requirements.ts +0 -91
- package/src/cli/auth-schemes.ts +0 -187
- package/src/cli/capabilities.ts +0 -88
- package/src/cli/command-id.ts +0 -16
- package/src/cli/command-index.ts +0 -19
- package/src/cli/command-model.ts +0 -128
- package/src/cli/compile.ts +0 -101
- package/src/cli/crypto.ts +0 -9
- package/src/cli/derive-name.ts +0 -101
- package/src/cli/exec.ts +0 -72
- package/src/cli/main.ts +0 -231
- package/src/cli/naming.ts +0 -224
- package/src/cli/operations.ts +0 -152
- package/src/cli/params.ts +0 -71
- package/src/cli/pluralize.ts +0 -41
- package/src/cli/positional.ts +0 -75
- package/src/cli/request-body.ts +0 -94
- package/src/cli/runtime/argv.ts +0 -14
- package/src/cli/runtime/auth/resolve.ts +0 -59
- package/src/cli/runtime/body-flags.ts +0 -176
- package/src/cli/runtime/body.ts +0 -24
- package/src/cli/runtime/collect.ts +0 -6
- package/src/cli/runtime/compat.ts +0 -89
- package/src/cli/runtime/context.ts +0 -62
- package/src/cli/runtime/execute.ts +0 -147
- package/src/cli/runtime/generated.ts +0 -242
- package/src/cli/runtime/headers.ts +0 -37
- package/src/cli/runtime/index.ts +0 -3
- package/src/cli/runtime/profile/secrets.ts +0 -83
- package/src/cli/runtime/profile/store.ts +0 -100
- package/src/cli/runtime/request.ts +0 -390
- package/src/cli/runtime/server-url.ts +0 -45
- package/src/cli/runtime/template.ts +0 -26
- package/src/cli/runtime/validate/ajv.ts +0 -13
- package/src/cli/runtime/validate/coerce.ts +0 -71
- package/src/cli/runtime/validate/error.ts +0 -29
- package/src/cli/runtime/validate/index.ts +0 -4
- package/src/cli/runtime/validate/schema.ts +0 -54
- package/src/cli/schema-shape.ts +0 -36
- package/src/cli/schema.ts +0 -76
- package/src/cli/server.ts +0 -88
- package/src/cli/spec-id.ts +0 -12
- package/src/cli/spec-loader.ts +0 -58
- package/src/cli/stable-json.ts +0 -35
- package/src/cli/strings.ts +0 -21
- package/src/cli/types.ts +0 -59
- package/src/macros/env.ts +0 -21
- package/src/macros/spec.ts +0 -17
package/src/ai/tools.ts
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AI SDK tools for specli
|
|
3
|
-
*
|
|
4
|
-
* Provides tools for AI agents to explore and execute OpenAPI specs.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* import { specli } from "specli/ai";
|
|
9
|
-
* import { generateText } from "ai";
|
|
10
|
-
*
|
|
11
|
-
* const result = await generateText({
|
|
12
|
-
* model: yourModel,
|
|
13
|
-
* tools: {
|
|
14
|
-
* api: specli({ spec: "https://api.example.com/openapi.json" }),
|
|
15
|
-
* },
|
|
16
|
-
* prompt: "List all users",
|
|
17
|
-
* });
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import { tool } from "ai";
|
|
22
|
-
import { z } from "zod";
|
|
23
|
-
|
|
24
|
-
import type { CommandAction } from "../cli/command-model.ts";
|
|
25
|
-
import { buildRuntimeContext } from "../cli/runtime/context.ts";
|
|
26
|
-
import { execute } from "../cli/runtime/execute.ts";
|
|
27
|
-
import type { RuntimeGlobals } from "../cli/runtime/request.ts";
|
|
28
|
-
|
|
29
|
-
export type SpecliToolOptions = {
|
|
30
|
-
/** The OpenAPI spec URL or file path */
|
|
31
|
-
spec: string;
|
|
32
|
-
/** Override the server/base URL */
|
|
33
|
-
server?: string;
|
|
34
|
-
/** Server URL template variables */
|
|
35
|
-
serverVars?: Record<string, string>;
|
|
36
|
-
/** Bearer token for authentication */
|
|
37
|
-
bearerToken?: string;
|
|
38
|
-
/** API key for authentication */
|
|
39
|
-
apiKey?: string;
|
|
40
|
-
/** Basic auth credentials */
|
|
41
|
-
basicAuth?: { username: string; password: string };
|
|
42
|
-
/** Auth scheme to use (if multiple are available) */
|
|
43
|
-
authScheme?: string;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// Cache contexts to avoid reloading spec on every call
|
|
47
|
-
const contextCache = new Map<
|
|
48
|
-
string,
|
|
49
|
-
Awaited<ReturnType<typeof buildRuntimeContext>>
|
|
50
|
-
>();
|
|
51
|
-
|
|
52
|
-
async function getContext(spec: string) {
|
|
53
|
-
let ctx = contextCache.get(spec);
|
|
54
|
-
if (!ctx) {
|
|
55
|
-
ctx = await buildRuntimeContext({ spec });
|
|
56
|
-
contextCache.set(spec, ctx);
|
|
57
|
-
}
|
|
58
|
-
return ctx;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function findAction(
|
|
62
|
-
ctx: Awaited<ReturnType<typeof buildRuntimeContext>>,
|
|
63
|
-
resource: string,
|
|
64
|
-
action: string,
|
|
65
|
-
): CommandAction | undefined {
|
|
66
|
-
const r = ctx.commands.resources.find(
|
|
67
|
-
(r) => r.resource.toLowerCase() === resource.toLowerCase(),
|
|
68
|
-
);
|
|
69
|
-
return r?.actions.find(
|
|
70
|
-
(a) => a.action.toLowerCase() === action.toLowerCase(),
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Create an AI SDK tool for interacting with an OpenAPI spec.
|
|
76
|
-
*/
|
|
77
|
-
export function specli(options: SpecliToolOptions) {
|
|
78
|
-
const {
|
|
79
|
-
spec,
|
|
80
|
-
server,
|
|
81
|
-
serverVars,
|
|
82
|
-
bearerToken,
|
|
83
|
-
apiKey,
|
|
84
|
-
basicAuth,
|
|
85
|
-
authScheme,
|
|
86
|
-
} = options;
|
|
87
|
-
|
|
88
|
-
return tool({
|
|
89
|
-
description: `Execute API operations. Commands: "list" (show resources/actions), "help" (action details), "exec" (call API).`,
|
|
90
|
-
inputSchema: z.object({
|
|
91
|
-
command: z.enum(["list", "help", "exec"]).describe("Command to run"),
|
|
92
|
-
resource: z.string().optional().describe("Resource name (e.g. users)"),
|
|
93
|
-
action: z
|
|
94
|
-
.string()
|
|
95
|
-
.optional()
|
|
96
|
-
.describe("Action name (e.g. list, get, create)"),
|
|
97
|
-
args: z.array(z.string()).optional().describe("Positional arguments"),
|
|
98
|
-
flags: z
|
|
99
|
-
.record(z.string(), z.unknown())
|
|
100
|
-
.optional()
|
|
101
|
-
.describe("Named flags"),
|
|
102
|
-
}),
|
|
103
|
-
execute: async ({ command, resource, action, args, flags }) => {
|
|
104
|
-
const ctx = await getContext(spec);
|
|
105
|
-
|
|
106
|
-
if (command === "list") {
|
|
107
|
-
return {
|
|
108
|
-
resources: ctx.commands.resources.map((r) => ({
|
|
109
|
-
name: r.resource,
|
|
110
|
-
actions: r.actions.map((a) => ({
|
|
111
|
-
name: a.action,
|
|
112
|
-
summary: a.summary,
|
|
113
|
-
method: a.method,
|
|
114
|
-
path: a.path,
|
|
115
|
-
args: a.positionals.map((p) => p.name),
|
|
116
|
-
requiredFlags: a.flags
|
|
117
|
-
.filter((f) => f.required)
|
|
118
|
-
.map((f) => f.flag),
|
|
119
|
-
})),
|
|
120
|
-
})),
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (command === "help") {
|
|
125
|
-
if (!resource) return { error: "Missing resource" };
|
|
126
|
-
const r = ctx.commands.resources.find(
|
|
127
|
-
(r) => r.resource.toLowerCase() === resource.toLowerCase(),
|
|
128
|
-
);
|
|
129
|
-
if (!r) return { error: `Unknown resource: ${resource}` };
|
|
130
|
-
if (!action) {
|
|
131
|
-
return {
|
|
132
|
-
resource: r.resource,
|
|
133
|
-
actions: r.actions.map((a) => a.action),
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
const a = r.actions.find(
|
|
137
|
-
(a) => a.action.toLowerCase() === action.toLowerCase(),
|
|
138
|
-
);
|
|
139
|
-
if (!a) return { error: `Unknown action: ${action}` };
|
|
140
|
-
return {
|
|
141
|
-
action: a.action,
|
|
142
|
-
method: a.method,
|
|
143
|
-
path: a.path,
|
|
144
|
-
summary: a.summary,
|
|
145
|
-
args: a.positionals.map((p) => ({
|
|
146
|
-
name: p.name,
|
|
147
|
-
description: p.description,
|
|
148
|
-
})),
|
|
149
|
-
flags: a.flags.map((f) => ({
|
|
150
|
-
name: f.flag,
|
|
151
|
-
type: f.type,
|
|
152
|
-
required: f.required,
|
|
153
|
-
description: f.description,
|
|
154
|
-
})),
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (command === "exec") {
|
|
159
|
-
if (!resource || !action)
|
|
160
|
-
return { error: "Missing resource or action" };
|
|
161
|
-
const actionDef = findAction(ctx, resource, action);
|
|
162
|
-
if (!actionDef) return { error: `Unknown: ${resource} ${action}` };
|
|
163
|
-
|
|
164
|
-
const positionalValues = args ?? [];
|
|
165
|
-
if (positionalValues.length < actionDef.positionals.length) {
|
|
166
|
-
return {
|
|
167
|
-
error: `Missing args: ${actionDef.positionals
|
|
168
|
-
.slice(positionalValues.length)
|
|
169
|
-
.map((p) => p.name)
|
|
170
|
-
.join(", ")}`,
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const globals: RuntimeGlobals = {
|
|
175
|
-
server,
|
|
176
|
-
serverVar: serverVars
|
|
177
|
-
? Object.entries(serverVars).map(([k, v]) => `${k}=${v}`)
|
|
178
|
-
: undefined,
|
|
179
|
-
auth: authScheme,
|
|
180
|
-
bearerToken,
|
|
181
|
-
apiKey,
|
|
182
|
-
username: basicAuth?.username,
|
|
183
|
-
password: basicAuth?.password,
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
try {
|
|
187
|
-
const result = await execute({
|
|
188
|
-
specId: ctx.loaded.id,
|
|
189
|
-
action: actionDef,
|
|
190
|
-
positionalValues,
|
|
191
|
-
flagValues: flags ?? {},
|
|
192
|
-
globals,
|
|
193
|
-
servers: ctx.servers,
|
|
194
|
-
authSchemes: ctx.authSchemes,
|
|
195
|
-
});
|
|
196
|
-
return { status: result.status, ok: result.ok, body: result.body };
|
|
197
|
-
} catch (err) {
|
|
198
|
-
return { error: err instanceof Error ? err.message : String(err) };
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return { error: `Unknown command: ${command}` };
|
|
203
|
-
},
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/** Clear cached spec context */
|
|
208
|
-
export function clearSpecliCache(spec?: string): void {
|
|
209
|
-
if (spec) contextCache.delete(spec);
|
|
210
|
-
else contextCache.clear();
|
|
211
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import type { AuthScheme } from "./auth-schemes.ts";
|
|
2
|
-
import type { SecurityRequirement } from "./types.ts";
|
|
3
|
-
|
|
4
|
-
export type AuthRequirement = {
|
|
5
|
-
key: string;
|
|
6
|
-
scopes: string[];
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export type AuthSummary = {
|
|
10
|
-
// Alternatives: any one of these sets is sufficient.
|
|
11
|
-
alternatives: AuthRequirement[][];
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
function isSecurityRequirement(value: unknown): value is SecurityRequirement {
|
|
15
|
-
if (!value || typeof value !== "object") return false;
|
|
16
|
-
if (Array.isArray(value)) return false;
|
|
17
|
-
|
|
18
|
-
for (const [k, v] of Object.entries(value)) {
|
|
19
|
-
if (typeof k !== "string") return false;
|
|
20
|
-
if (!Array.isArray(v)) return false;
|
|
21
|
-
if (!v.every((s) => typeof s === "string")) return false;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function normalizeSecurity(value: unknown): {
|
|
28
|
-
requirements: SecurityRequirement[];
|
|
29
|
-
source: "none" | "empty" | "non-empty";
|
|
30
|
-
} {
|
|
31
|
-
if (value == null) return { requirements: [], source: "none" };
|
|
32
|
-
if (!Array.isArray(value)) return { requirements: [], source: "none" };
|
|
33
|
-
|
|
34
|
-
const reqs = value.filter(isSecurityRequirement);
|
|
35
|
-
if (reqs.length === 0) return { requirements: [], source: "empty" };
|
|
36
|
-
return { requirements: reqs, source: "non-empty" };
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function summarizeAuth(
|
|
40
|
-
operationSecurity: unknown,
|
|
41
|
-
globalSecurity: unknown,
|
|
42
|
-
knownSchemes: AuthScheme[],
|
|
43
|
-
): AuthSummary {
|
|
44
|
-
// Per spec:
|
|
45
|
-
// - operation security overrides root
|
|
46
|
-
// - empty array [] means "no auth"
|
|
47
|
-
const op = normalizeSecurity(operationSecurity);
|
|
48
|
-
if (op.source === "non-empty") {
|
|
49
|
-
return { alternatives: toAlternatives(op.requirements, knownSchemes) };
|
|
50
|
-
}
|
|
51
|
-
if (op.source === "empty") {
|
|
52
|
-
return { alternatives: [] };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const global = normalizeSecurity(globalSecurity);
|
|
56
|
-
if (global.source === "non-empty") {
|
|
57
|
-
return { alternatives: toAlternatives(global.requirements, knownSchemes) };
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return { alternatives: [] };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function toAlternatives(
|
|
64
|
-
requirements: SecurityRequirement[],
|
|
65
|
-
knownSchemes: AuthScheme[],
|
|
66
|
-
): AuthRequirement[][] {
|
|
67
|
-
const known = new Set(knownSchemes.map((s) => s.key));
|
|
68
|
-
|
|
69
|
-
return requirements.map((req) => {
|
|
70
|
-
const out: AuthRequirement[] = [];
|
|
71
|
-
for (const [key, scopes] of Object.entries(req)) {
|
|
72
|
-
out.push({
|
|
73
|
-
key,
|
|
74
|
-
scopes: Array.isArray(scopes) ? scopes : [],
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Stable order.
|
|
79
|
-
out.sort((a, b) => a.key.localeCompare(b.key));
|
|
80
|
-
|
|
81
|
-
// Prefer known schemes first.
|
|
82
|
-
out.sort((a, b) => {
|
|
83
|
-
const ak = known.has(a.key) ? 0 : 1;
|
|
84
|
-
const bk = known.has(b.key) ? 0 : 1;
|
|
85
|
-
if (ak !== bk) return ak - bk;
|
|
86
|
-
return a.key.localeCompare(b.key);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
return out;
|
|
90
|
-
});
|
|
91
|
-
}
|
package/src/cli/auth-schemes.ts
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { kebabCase } from "./strings.ts";
|
|
2
|
-
import type { OpenApiDoc } from "./types.ts";
|
|
3
|
-
|
|
4
|
-
export type AuthSchemeKind =
|
|
5
|
-
| "http-bearer"
|
|
6
|
-
| "http-basic"
|
|
7
|
-
| "api-key"
|
|
8
|
-
| "oauth2"
|
|
9
|
-
| "openIdConnect"
|
|
10
|
-
| "unknown";
|
|
11
|
-
|
|
12
|
-
export type AuthScheme = {
|
|
13
|
-
key: string;
|
|
14
|
-
kind: AuthSchemeKind;
|
|
15
|
-
name?: string;
|
|
16
|
-
in?: "header" | "query" | "cookie";
|
|
17
|
-
scheme?: string;
|
|
18
|
-
bearerFormat?: string;
|
|
19
|
-
description?: string;
|
|
20
|
-
|
|
21
|
-
// oauth2/openid only (subset of spec, enough to derive flags + docs)
|
|
22
|
-
oauthFlows?: OAuthFlows;
|
|
23
|
-
openIdConnectUrl?: string;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type OAuthFlow = {
|
|
27
|
-
authorizationUrl?: string;
|
|
28
|
-
tokenUrl?: string;
|
|
29
|
-
refreshUrl?: string;
|
|
30
|
-
scopes: string[];
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type OAuthFlows = Partial<
|
|
34
|
-
Record<
|
|
35
|
-
"implicit" | "password" | "clientCredentials" | "authorizationCode",
|
|
36
|
-
OAuthFlow
|
|
37
|
-
>
|
|
38
|
-
>;
|
|
39
|
-
|
|
40
|
-
type RawOAuthFlow = {
|
|
41
|
-
authorizationUrl?: unknown;
|
|
42
|
-
tokenUrl?: unknown;
|
|
43
|
-
refreshUrl?: unknown;
|
|
44
|
-
scopes?: unknown;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
type RawOAuthFlows = {
|
|
48
|
-
implicit?: RawOAuthFlow;
|
|
49
|
-
password?: RawOAuthFlow;
|
|
50
|
-
clientCredentials?: RawOAuthFlow;
|
|
51
|
-
authorizationCode?: RawOAuthFlow;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
type RawSecurityScheme = {
|
|
55
|
-
type?: string;
|
|
56
|
-
description?: string;
|
|
57
|
-
name?: string;
|
|
58
|
-
in?: string;
|
|
59
|
-
scheme?: string;
|
|
60
|
-
bearerFormat?: string;
|
|
61
|
-
flows?: RawOAuthFlows;
|
|
62
|
-
openIdConnectUrl?: string;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
function parseOAuthFlow(flow: RawOAuthFlow | undefined): OAuthFlow | undefined {
|
|
66
|
-
if (!flow) return undefined;
|
|
67
|
-
const scopesObj = flow.scopes;
|
|
68
|
-
const scopes =
|
|
69
|
-
scopesObj && typeof scopesObj === "object" && !Array.isArray(scopesObj)
|
|
70
|
-
? Object.keys(scopesObj as Record<string, unknown>)
|
|
71
|
-
: [];
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
authorizationUrl:
|
|
75
|
-
typeof flow.authorizationUrl === "string"
|
|
76
|
-
? flow.authorizationUrl
|
|
77
|
-
: undefined,
|
|
78
|
-
tokenUrl: typeof flow.tokenUrl === "string" ? flow.tokenUrl : undefined,
|
|
79
|
-
refreshUrl:
|
|
80
|
-
typeof flow.refreshUrl === "string" ? flow.refreshUrl : undefined,
|
|
81
|
-
scopes: scopes.sort(),
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function parseOAuthFlows(
|
|
86
|
-
flows: RawOAuthFlows | undefined,
|
|
87
|
-
): OAuthFlows | undefined {
|
|
88
|
-
if (!flows) return undefined;
|
|
89
|
-
const out: OAuthFlows = {};
|
|
90
|
-
|
|
91
|
-
const implicit = parseOAuthFlow(flows.implicit);
|
|
92
|
-
if (implicit) out.implicit = implicit;
|
|
93
|
-
|
|
94
|
-
const password = parseOAuthFlow(flows.password);
|
|
95
|
-
if (password) out.password = password;
|
|
96
|
-
|
|
97
|
-
const clientCredentials = parseOAuthFlow(flows.clientCredentials);
|
|
98
|
-
if (clientCredentials) out.clientCredentials = clientCredentials;
|
|
99
|
-
|
|
100
|
-
const authorizationCode = parseOAuthFlow(flows.authorizationCode);
|
|
101
|
-
if (authorizationCode) out.authorizationCode = authorizationCode;
|
|
102
|
-
|
|
103
|
-
return Object.keys(out).length ? out : undefined;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function listAuthSchemes(doc: OpenApiDoc): AuthScheme[] {
|
|
107
|
-
const schemes = doc.components?.securitySchemes;
|
|
108
|
-
if (!schemes || typeof schemes !== "object") return [];
|
|
109
|
-
|
|
110
|
-
const out: AuthScheme[] = [];
|
|
111
|
-
|
|
112
|
-
for (const [key, raw] of Object.entries(schemes)) {
|
|
113
|
-
if (!raw || typeof raw !== "object") continue;
|
|
114
|
-
const s = raw as RawSecurityScheme;
|
|
115
|
-
|
|
116
|
-
const type = s.type;
|
|
117
|
-
if (type === "http") {
|
|
118
|
-
const scheme = (s.scheme ?? "").toLowerCase();
|
|
119
|
-
if (scheme === "bearer") {
|
|
120
|
-
out.push({
|
|
121
|
-
key,
|
|
122
|
-
kind: "http-bearer",
|
|
123
|
-
scheme: scheme,
|
|
124
|
-
bearerFormat: s.bearerFormat,
|
|
125
|
-
description: s.description,
|
|
126
|
-
});
|
|
127
|
-
} else if (scheme === "basic") {
|
|
128
|
-
out.push({
|
|
129
|
-
key,
|
|
130
|
-
kind: "http-basic",
|
|
131
|
-
scheme: scheme,
|
|
132
|
-
description: s.description,
|
|
133
|
-
});
|
|
134
|
-
} else {
|
|
135
|
-
out.push({
|
|
136
|
-
key,
|
|
137
|
-
kind: "unknown",
|
|
138
|
-
scheme: s.scheme,
|
|
139
|
-
description: s.description,
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
continue;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (type === "apiKey") {
|
|
146
|
-
const where = s.in;
|
|
147
|
-
const loc =
|
|
148
|
-
where === "header" || where === "query" || where === "cookie"
|
|
149
|
-
? where
|
|
150
|
-
: undefined;
|
|
151
|
-
out.push({
|
|
152
|
-
key,
|
|
153
|
-
kind: "api-key",
|
|
154
|
-
name: s.name,
|
|
155
|
-
in: loc,
|
|
156
|
-
description: s.description,
|
|
157
|
-
});
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (type === "oauth2") {
|
|
162
|
-
out.push({
|
|
163
|
-
key,
|
|
164
|
-
kind: "oauth2",
|
|
165
|
-
description: s.description,
|
|
166
|
-
oauthFlows: parseOAuthFlows(s.flows),
|
|
167
|
-
});
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (type === "openIdConnect") {
|
|
172
|
-
out.push({
|
|
173
|
-
key,
|
|
174
|
-
kind: "openIdConnect",
|
|
175
|
-
description: s.description,
|
|
176
|
-
openIdConnectUrl: s.openIdConnectUrl,
|
|
177
|
-
});
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
out.push({ key, kind: "unknown", description: s.description });
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Stable order.
|
|
185
|
-
out.sort((a, b) => kebabCase(a.key).localeCompare(kebabCase(b.key)));
|
|
186
|
-
return out;
|
|
187
|
-
}
|
package/src/cli/capabilities.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { AuthScheme, AuthSchemeKind } from "./auth-schemes.ts";
|
|
2
|
-
import type { CommandModel } from "./command-model.ts";
|
|
3
|
-
import type { ServerInfo } from "./server.ts";
|
|
4
|
-
import type {
|
|
5
|
-
NormalizedOperation,
|
|
6
|
-
OpenApiDoc,
|
|
7
|
-
SecurityRequirement,
|
|
8
|
-
} from "./types.ts";
|
|
9
|
-
|
|
10
|
-
export type Capabilities = {
|
|
11
|
-
servers: {
|
|
12
|
-
count: number;
|
|
13
|
-
hasVariables: boolean;
|
|
14
|
-
};
|
|
15
|
-
auth: {
|
|
16
|
-
count: number;
|
|
17
|
-
kinds: AuthSchemeKind[];
|
|
18
|
-
hasSecurityRequirements: boolean;
|
|
19
|
-
};
|
|
20
|
-
operations: {
|
|
21
|
-
count: number;
|
|
22
|
-
hasRequestBodies: boolean;
|
|
23
|
-
};
|
|
24
|
-
commands: {
|
|
25
|
-
countResources: number;
|
|
26
|
-
countActions: number;
|
|
27
|
-
hasRequestBodies: boolean;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
function uniqueSorted<T>(items: T[], compare: (a: T, b: T) => number): T[] {
|
|
32
|
-
const out = [...items];
|
|
33
|
-
out.sort(compare);
|
|
34
|
-
return out.filter((v, i) => i === 0 || compare(out[i - 1] as T, v) !== 0);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function hasSecurity(requirements: SecurityRequirement[] | undefined): boolean {
|
|
38
|
-
if (!requirements?.length) return false;
|
|
39
|
-
|
|
40
|
-
// Treat any non-empty array as "auth exists", even if it contains `{}` to mean optional.
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function deriveCapabilities(input: {
|
|
45
|
-
doc: OpenApiDoc;
|
|
46
|
-
servers: ServerInfo[];
|
|
47
|
-
authSchemes: AuthScheme[];
|
|
48
|
-
operations: NormalizedOperation[];
|
|
49
|
-
commands?: CommandModel;
|
|
50
|
-
}): Capabilities {
|
|
51
|
-
const serverHasVars = input.servers.some((s) => s.variableNames.length > 0);
|
|
52
|
-
|
|
53
|
-
const authKinds = uniqueSorted(
|
|
54
|
-
input.authSchemes.map((s) => s.kind),
|
|
55
|
-
(a, b) => a.localeCompare(b),
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
const hasSecurityRequirements =
|
|
59
|
-
hasSecurity(input.doc.security) ||
|
|
60
|
-
input.operations.some((op) => hasSecurity(op.security));
|
|
61
|
-
|
|
62
|
-
const opHasBodies = input.operations.some((op) => Boolean(op.requestBody));
|
|
63
|
-
|
|
64
|
-
const cmdResources = input.commands?.resources ?? [];
|
|
65
|
-
const cmdActions = cmdResources.flatMap((r) => r.actions);
|
|
66
|
-
const cmdHasBodies = cmdActions.some((a) => Boolean(a.requestBody));
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
servers: {
|
|
70
|
-
count: input.servers.length,
|
|
71
|
-
hasVariables: serverHasVars,
|
|
72
|
-
},
|
|
73
|
-
auth: {
|
|
74
|
-
count: input.authSchemes.length,
|
|
75
|
-
kinds: authKinds,
|
|
76
|
-
hasSecurityRequirements,
|
|
77
|
-
},
|
|
78
|
-
operations: {
|
|
79
|
-
count: input.operations.length,
|
|
80
|
-
hasRequestBodies: opHasBodies,
|
|
81
|
-
},
|
|
82
|
-
commands: {
|
|
83
|
-
countResources: cmdResources.length,
|
|
84
|
-
countActions: cmdActions.length,
|
|
85
|
-
hasRequestBodies: cmdHasBodies,
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
}
|
package/src/cli/command-id.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { kebabCase } from "./strings.ts";
|
|
2
|
-
|
|
3
|
-
export type CommandIdParts = {
|
|
4
|
-
specId: string;
|
|
5
|
-
resource: string;
|
|
6
|
-
action: string;
|
|
7
|
-
operationKey: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export function buildCommandId(parts: CommandIdParts): string {
|
|
11
|
-
// operationKey is the ultimate disambiguator, but we keep the id readable.
|
|
12
|
-
// Example:
|
|
13
|
-
// contacts-api:contacts:get:GET-/contacts/{id}
|
|
14
|
-
const op = kebabCase(parts.operationKey.replace(/\s+/g, "-"));
|
|
15
|
-
return `${parts.specId}:${kebabCase(parts.resource)}:${kebabCase(parts.action)}:${op}`;
|
|
16
|
-
}
|
package/src/cli/command-index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { CommandAction, CommandModel } from "./command-model.ts";
|
|
2
|
-
|
|
3
|
-
export type CommandsIndex = {
|
|
4
|
-
byId: Record<string, CommandAction>;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export function buildCommandsIndex(
|
|
8
|
-
commands: CommandModel | undefined,
|
|
9
|
-
): CommandsIndex {
|
|
10
|
-
const byId: Record<string, CommandAction> = {};
|
|
11
|
-
|
|
12
|
-
for (const resource of commands?.resources ?? []) {
|
|
13
|
-
for (const action of resource.actions) {
|
|
14
|
-
byId[action.id] = action;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return { byId };
|
|
19
|
-
}
|