swytchcode-runtime 0.1.1 → 0.1.2
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 +20 -2
- package/dist/exec.d.ts +6 -3
- package/dist/exec.js +4 -1
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +15 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,12 +20,30 @@ npm install @swytchcode/runtime
|
|
|
20
20
|
import { exec } from "@swytchcode/runtime";
|
|
21
21
|
|
|
22
22
|
const result = await exec("api.account.create", {
|
|
23
|
-
|
|
23
|
+
body: { name: "my-cluster" },
|
|
24
|
+
Authorization: "Bearer token123",
|
|
24
25
|
});
|
|
25
26
|
// result is parsed JSON (unknown)
|
|
26
27
|
```
|
|
27
28
|
|
|
28
|
-
Equivalent to: `swytchcode exec api.account.create --json` with
|
|
29
|
+
Equivalent to: `swytchcode exec api.account.create --json` with args on stdin.
|
|
30
|
+
|
|
31
|
+
**Request input (args):** The second argument is the kernel **args** object (sent as JSON on stdin). Use this shape so the kernel builds the request correctly:
|
|
32
|
+
- **`body`** — Request body (object).
|
|
33
|
+
- **`params`** — Query/path params (object, e.g. `{ id: "cluster-123" }`).
|
|
34
|
+
- **`Authorization`** — Auth header value (e.g. `"Bearer token123"`).
|
|
35
|
+
- **`headers`** — Additional request headers (e.g. `{ "X-Request-Id": "abc-123" }`).
|
|
36
|
+
- Other top-level keys are passed as query params.
|
|
37
|
+
|
|
38
|
+
Example with body, params, and headers:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
await exec("api.cluster.get", {
|
|
42
|
+
params: { id: "cluster-123" },
|
|
43
|
+
Authorization: "Bearer token123",
|
|
44
|
+
headers: { "X-Request-Id": "abc-123" },
|
|
45
|
+
});
|
|
46
|
+
```
|
|
29
47
|
|
|
30
48
|
### Raw mode
|
|
31
49
|
|
package/dist/exec.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { ExecOptions, ExecResult } from "./types.js";
|
|
1
|
+
import type { ExecArgs, ExecOptions, ExecResult } from "./types.js";
|
|
2
2
|
/**
|
|
3
|
-
* Run `swytchcode exec <canonicalId>` with optional JSON
|
|
3
|
+
* Run `swytchcode exec <canonicalId>` with optional JSON args on stdin.
|
|
4
4
|
* Default is JSON mode (stdout must be valid JSON; empty or parse failure throws).
|
|
5
5
|
* Use output: "raw" or raw: true for raw stdout string. Stream mode is not supported.
|
|
6
6
|
*
|
|
7
|
+
* The second argument (input) is the kernel args object sent on stdin: use body, params,
|
|
8
|
+
* Authorization, and headers so the kernel builds the request correctly. See ExecArgs.
|
|
9
|
+
*
|
|
7
10
|
* Enable logs: pass `{ debug: true }` or set env SWYTCHCODE_RUNTIME_DEBUG=1
|
|
8
11
|
*/
|
|
9
|
-
export declare function exec(canonicalId: string, input?: unknown, options?: ExecOptions): Promise<ExecResult>;
|
|
12
|
+
export declare function exec(canonicalId: string, input?: ExecArgs | unknown, options?: ExecOptions): Promise<ExecResult>;
|
package/dist/exec.js
CHANGED
|
@@ -16,10 +16,13 @@ function log(debug, msg, detail) {
|
|
|
16
16
|
process.stderr.write(line);
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* Run `swytchcode exec <canonicalId>` with optional JSON
|
|
19
|
+
* Run `swytchcode exec <canonicalId>` with optional JSON args on stdin.
|
|
20
20
|
* Default is JSON mode (stdout must be valid JSON; empty or parse failure throws).
|
|
21
21
|
* Use output: "raw" or raw: true for raw stdout string. Stream mode is not supported.
|
|
22
22
|
*
|
|
23
|
+
* The second argument (input) is the kernel args object sent on stdin: use body, params,
|
|
24
|
+
* Authorization, and headers so the kernel builds the request correctly. See ExecArgs.
|
|
25
|
+
*
|
|
23
26
|
* Enable logs: pass `{ debug: true }` or set env SWYTCHCODE_RUNTIME_DEBUG=1
|
|
24
27
|
*/
|
|
25
28
|
function exec(canonicalId, input, options = {}) {
|
package/dist/index.d.ts
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -21,3 +21,18 @@ export interface ExecOptions {
|
|
|
21
21
|
}
|
|
22
22
|
/** Result of `exec()` in JSON mode: parsed stdout. In raw mode the result is a string. */
|
|
23
23
|
export type ExecResult = unknown;
|
|
24
|
+
/**
|
|
25
|
+
* Tool arguments sent to the kernel on stdin (matches `swytchcode exec` JSON stdin).
|
|
26
|
+
* - `body`: Request body (object).
|
|
27
|
+
* - `params`: Query/path params (object).
|
|
28
|
+
* - `Authorization`: Auth header value (e.g. "Bearer token").
|
|
29
|
+
* - `headers`: Additional request headers (map of header name to value).
|
|
30
|
+
* - Other top-level keys are passed as query params.
|
|
31
|
+
*/
|
|
32
|
+
export interface ExecArgs {
|
|
33
|
+
body?: unknown;
|
|
34
|
+
params?: Record<string, string>;
|
|
35
|
+
Authorization?: string;
|
|
36
|
+
headers?: Record<string, string>;
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
}
|