specli 0.0.22 → 0.0.23
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 +58 -0
- package/dist/index.d.ts +106 -0
- package/dist/index.js +114 -0
- package/package.json +20 -15
package/README.md
CHANGED
|
@@ -310,6 +310,64 @@ Prints equivalent curl command without sending the request.
|
|
|
310
310
|
|
|
311
311
|
Prints method, URL, headers, and body without sending.
|
|
312
312
|
|
|
313
|
+
## Programmatic API
|
|
314
|
+
|
|
315
|
+
Use specli as a library to execute OpenAPI operations programmatically:
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
import { specli } from "specli";
|
|
319
|
+
|
|
320
|
+
const api = await specli({
|
|
321
|
+
spec: "https://api.example.com/openapi.json",
|
|
322
|
+
bearerToken: process.env.API_TOKEN,
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
// List available resources and actions
|
|
326
|
+
const resources = api.list();
|
|
327
|
+
|
|
328
|
+
// Get help for a specific action
|
|
329
|
+
const help = api.help("users", "get");
|
|
330
|
+
|
|
331
|
+
// Execute an API call
|
|
332
|
+
const result = await api.exec("users", "get", ["123"], { include: "profile" });
|
|
333
|
+
if (result.ok) {
|
|
334
|
+
console.log(result.body);
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Options
|
|
339
|
+
|
|
340
|
+
| Option | Description |
|
|
341
|
+
|--------|-------------|
|
|
342
|
+
| `spec` | OpenAPI spec URL or file path (required) |
|
|
343
|
+
| `server` | Override server/base URL |
|
|
344
|
+
| `serverVars` | Server URL template variables (`Record<string, string>`) |
|
|
345
|
+
| `bearerToken` | Bearer token for authentication |
|
|
346
|
+
| `apiKey` | API key for authentication |
|
|
347
|
+
| `basicAuth` | Basic auth credentials (`{ username, password }`) |
|
|
348
|
+
| `authScheme` | Auth scheme to use (if multiple are available) |
|
|
349
|
+
|
|
350
|
+
### Methods
|
|
351
|
+
|
|
352
|
+
| Method | Description |
|
|
353
|
+
|--------|-------------|
|
|
354
|
+
| `list()` | Returns all resources and their actions |
|
|
355
|
+
| `help(resource, action)` | Get detailed info about an action |
|
|
356
|
+
| `exec(resource, action, args?, flags?)` | Execute an API call |
|
|
357
|
+
|
|
358
|
+
### ExecuteResult
|
|
359
|
+
|
|
360
|
+
The `exec()` method returns:
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
{
|
|
364
|
+
ok: boolean; // true if status 2xx
|
|
365
|
+
status: number; // HTTP status code
|
|
366
|
+
body: unknown; // Parsed response body
|
|
367
|
+
curl: string; // Equivalent curl command
|
|
368
|
+
}
|
|
369
|
+
```
|
|
370
|
+
|
|
313
371
|
## AI SDK Integration
|
|
314
372
|
|
|
315
373
|
specli exports an AI SDK tool for use with LLM agents:
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Specli - Convert OpenAPI specs to executables, built to be agent-first
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { specli } from "specli";
|
|
7
|
+
*
|
|
8
|
+
* const api = await specli({ spec: "https://api.example.com/openapi.json" });
|
|
9
|
+
*
|
|
10
|
+
* // List available resources and actions
|
|
11
|
+
* const resources = api.list();
|
|
12
|
+
*
|
|
13
|
+
* // Execute an API call
|
|
14
|
+
* const result = await api.exec("users", "get", ["123"]);
|
|
15
|
+
* console.log(result.body);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import type { AuthScheme } from "./cli/parse/auth-schemes.js";
|
|
19
|
+
import type { ServerInfo } from "./cli/parse/servers.js";
|
|
20
|
+
import { type ExecuteResult } from "./cli/runtime/execute.js";
|
|
21
|
+
export type SpecliOptions = {
|
|
22
|
+
/** The OpenAPI spec URL or file path */
|
|
23
|
+
spec: string;
|
|
24
|
+
/** Override the server/base URL */
|
|
25
|
+
server?: string;
|
|
26
|
+
/** Server URL template variables */
|
|
27
|
+
serverVars?: Record<string, string>;
|
|
28
|
+
/** Bearer token for authentication */
|
|
29
|
+
bearerToken?: string;
|
|
30
|
+
/** API key for authentication */
|
|
31
|
+
apiKey?: string;
|
|
32
|
+
/** Basic auth credentials */
|
|
33
|
+
basicAuth?: {
|
|
34
|
+
username: string;
|
|
35
|
+
password: string;
|
|
36
|
+
};
|
|
37
|
+
/** Auth scheme to use (if multiple are available) */
|
|
38
|
+
authScheme?: string;
|
|
39
|
+
};
|
|
40
|
+
export type ResourceInfo = {
|
|
41
|
+
name: string;
|
|
42
|
+
actions: ActionInfo[];
|
|
43
|
+
};
|
|
44
|
+
export type ActionInfo = {
|
|
45
|
+
name: string;
|
|
46
|
+
summary?: string;
|
|
47
|
+
method: string;
|
|
48
|
+
path: string;
|
|
49
|
+
args: string[];
|
|
50
|
+
requiredFlags: string[];
|
|
51
|
+
optionalFlags: string[];
|
|
52
|
+
};
|
|
53
|
+
export type ActionDetail = {
|
|
54
|
+
action: string;
|
|
55
|
+
method: string;
|
|
56
|
+
path: string;
|
|
57
|
+
summary?: string;
|
|
58
|
+
args: Array<{
|
|
59
|
+
name: string;
|
|
60
|
+
description?: string;
|
|
61
|
+
}>;
|
|
62
|
+
flags: Array<{
|
|
63
|
+
name: string;
|
|
64
|
+
type: string;
|
|
65
|
+
required: boolean;
|
|
66
|
+
description?: string;
|
|
67
|
+
}>;
|
|
68
|
+
};
|
|
69
|
+
export type SpecliClient = {
|
|
70
|
+
/** List all available resources and their actions */
|
|
71
|
+
list(): ResourceInfo[];
|
|
72
|
+
/** Get detailed help for a specific action */
|
|
73
|
+
help(resource: string, action: string): ActionDetail | undefined;
|
|
74
|
+
/** Execute an API action */
|
|
75
|
+
exec(resource: string, action: string, args?: string[], flags?: Record<string, unknown>): Promise<ExecuteResult>;
|
|
76
|
+
/** Get server information */
|
|
77
|
+
servers: ServerInfo[];
|
|
78
|
+
/** Get authentication schemes */
|
|
79
|
+
authSchemes: AuthScheme[];
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Create a specli client for interacting with an OpenAPI spec.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { specli } from "specli";
|
|
87
|
+
*
|
|
88
|
+
* const api = await specli({
|
|
89
|
+
* spec: "https://api.example.com/openapi.json",
|
|
90
|
+
* bearerToken: process.env.API_TOKEN,
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* // List resources
|
|
94
|
+
* const resources = api.list();
|
|
95
|
+
*
|
|
96
|
+
* // Execute a call
|
|
97
|
+
* const result = await api.exec("users", "list");
|
|
98
|
+
* if (result.ok) {
|
|
99
|
+
* console.log(result.body);
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function specli(options: SpecliOptions): Promise<SpecliClient>;
|
|
104
|
+
export type { AuthScheme } from "./cli/parse/auth-schemes.js";
|
|
105
|
+
export type { ServerInfo } from "./cli/parse/servers.js";
|
|
106
|
+
export type { ExecuteResult } from "./cli/runtime/execute.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Specli - Convert OpenAPI specs to executables, built to be agent-first
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { specli } from "specli";
|
|
7
|
+
*
|
|
8
|
+
* const api = await specli({ spec: "https://api.example.com/openapi.json" });
|
|
9
|
+
*
|
|
10
|
+
* // List available resources and actions
|
|
11
|
+
* const resources = api.list();
|
|
12
|
+
*
|
|
13
|
+
* // Execute an API call
|
|
14
|
+
* const result = await api.exec("users", "get", ["123"]);
|
|
15
|
+
* console.log(result.body);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import { buildRuntimeContext } from "./cli/runtime/context.js";
|
|
19
|
+
import { execute } from "./cli/runtime/execute.js";
|
|
20
|
+
function findAction(ctx, resource, action) {
|
|
21
|
+
const r = ctx.commands.resources.find((r) => r.resource.toLowerCase() === resource.toLowerCase());
|
|
22
|
+
return r?.actions.find((a) => a.action.toLowerCase() === action.toLowerCase());
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a specli client for interacting with an OpenAPI spec.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { specli } from "specli";
|
|
30
|
+
*
|
|
31
|
+
* const api = await specli({
|
|
32
|
+
* spec: "https://api.example.com/openapi.json",
|
|
33
|
+
* bearerToken: process.env.API_TOKEN,
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* // List resources
|
|
37
|
+
* const resources = api.list();
|
|
38
|
+
*
|
|
39
|
+
* // Execute a call
|
|
40
|
+
* const result = await api.exec("users", "list");
|
|
41
|
+
* if (result.ok) {
|
|
42
|
+
* console.log(result.body);
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export async function specli(options) {
|
|
47
|
+
const { spec, server, serverVars, bearerToken, apiKey, basicAuth, authScheme, } = options;
|
|
48
|
+
const ctx = await buildRuntimeContext({ spec });
|
|
49
|
+
const globals = {
|
|
50
|
+
server,
|
|
51
|
+
serverVar: serverVars
|
|
52
|
+
? Object.entries(serverVars).map(([k, v]) => `${k}=${v}`)
|
|
53
|
+
: undefined,
|
|
54
|
+
auth: authScheme,
|
|
55
|
+
bearerToken,
|
|
56
|
+
apiKey,
|
|
57
|
+
username: basicAuth?.username,
|
|
58
|
+
password: basicAuth?.password,
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
list() {
|
|
62
|
+
return ctx.commands.resources.map((r) => ({
|
|
63
|
+
name: r.resource,
|
|
64
|
+
actions: r.actions.map((a) => ({
|
|
65
|
+
name: a.action,
|
|
66
|
+
summary: a.summary,
|
|
67
|
+
method: a.method,
|
|
68
|
+
path: a.path,
|
|
69
|
+
args: a.positionals.map((p) => p.name),
|
|
70
|
+
requiredFlags: a.flags.filter((f) => f.required).map((f) => f.flag),
|
|
71
|
+
optionalFlags: a.flags.filter((f) => !f.required).map((f) => f.flag),
|
|
72
|
+
})),
|
|
73
|
+
}));
|
|
74
|
+
},
|
|
75
|
+
help(resource, action) {
|
|
76
|
+
const actionDef = findAction(ctx, resource, action);
|
|
77
|
+
if (!actionDef)
|
|
78
|
+
return undefined;
|
|
79
|
+
return {
|
|
80
|
+
action: actionDef.action,
|
|
81
|
+
method: actionDef.method,
|
|
82
|
+
path: actionDef.path,
|
|
83
|
+
summary: actionDef.summary,
|
|
84
|
+
args: actionDef.positionals.map((p) => ({
|
|
85
|
+
name: p.name,
|
|
86
|
+
description: p.description,
|
|
87
|
+
})),
|
|
88
|
+
flags: actionDef.flags.map((f) => ({
|
|
89
|
+
name: f.flag,
|
|
90
|
+
type: f.type,
|
|
91
|
+
required: f.required,
|
|
92
|
+
description: f.description,
|
|
93
|
+
})),
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
async exec(resource, action, args = [], flags = {}) {
|
|
97
|
+
const actionDef = findAction(ctx, resource, action);
|
|
98
|
+
if (!actionDef) {
|
|
99
|
+
throw new Error(`Unknown action: ${resource} ${action}`);
|
|
100
|
+
}
|
|
101
|
+
return execute({
|
|
102
|
+
specId: ctx.loaded.id,
|
|
103
|
+
action: actionDef,
|
|
104
|
+
positionalValues: args,
|
|
105
|
+
flagValues: flags,
|
|
106
|
+
globals,
|
|
107
|
+
servers: ctx.servers,
|
|
108
|
+
authSchemes: ctx.authSchemes,
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
servers: ctx.servers,
|
|
112
|
+
authSchemes: ctx.authSchemes,
|
|
113
|
+
};
|
|
114
|
+
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "specli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
|
+
"description": "Run any OpenAPI spec as a CLI. Built for Agents.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/AndrewBarba/specli.git"
|
|
8
|
+
},
|
|
4
9
|
"type": "module",
|
|
5
10
|
"module": "./dist/index.js",
|
|
6
11
|
"types": "./dist/index.d.ts",
|
|
7
|
-
"bin": {
|
|
8
|
-
"specli": "./bin/cli.sh"
|
|
9
|
-
},
|
|
10
12
|
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
},
|
|
11
17
|
"./ai/tools": {
|
|
12
18
|
"import": "./dist/ai/tools.js",
|
|
13
19
|
"types": "./dist/ai/tools.d.ts"
|
|
14
20
|
}
|
|
15
21
|
},
|
|
22
|
+
"bin": {
|
|
23
|
+
"specli": "./bin/cli.sh"
|
|
24
|
+
},
|
|
16
25
|
"files": [
|
|
17
26
|
"bin",
|
|
18
27
|
"dist",
|
|
@@ -28,14 +37,6 @@
|
|
|
28
37
|
"lint:format": "biome format --write",
|
|
29
38
|
"typecheck": "tsgo"
|
|
30
39
|
},
|
|
31
|
-
"devDependencies": {
|
|
32
|
-
"@biomejs/biome": "^2.3.11",
|
|
33
|
-
"@tsconfig/node22": "^22.0.5",
|
|
34
|
-
"@types/bun": "^1.3.6",
|
|
35
|
-
"@types/node": "^22.19.7",
|
|
36
|
-
"@typescript/native-preview": "^7.0.0-dev.20260122.3",
|
|
37
|
-
"typescript": "^5.9.3"
|
|
38
|
-
},
|
|
39
40
|
"dependencies": {
|
|
40
41
|
"@apidevtools/swagger-parser": "^12.1.0",
|
|
41
42
|
"ajv": "^8.17.1",
|
|
@@ -48,8 +49,12 @@
|
|
|
48
49
|
"ai": "^6.0.0",
|
|
49
50
|
"zod": "^4.0.0"
|
|
50
51
|
},
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@biomejs/biome": "^2.3.11",
|
|
54
|
+
"@tsconfig/node22": "^22.0.5",
|
|
55
|
+
"@types/bun": "^1.3.6",
|
|
56
|
+
"@types/node": "^22.19.7",
|
|
57
|
+
"@typescript/native-preview": "^7.0.0-dev.20260122.3",
|
|
58
|
+
"typescript": "^5.9.3"
|
|
54
59
|
}
|
|
55
60
|
}
|