@reasonlayer/sdk 0.0.1-rc.3
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/LICENSE +201 -0
- package/README.md +35 -0
- package/bin/rl.mjs +75 -0
- package/dist/builder.d.ts +38 -0
- package/dist/builder.js +41 -0
- package/dist/bundler/index.d.ts +32 -0
- package/dist/bundler/index.js +143 -0
- package/dist/bundler/node.d.ts +10 -0
- package/dist/bundler/node.js +55 -0
- package/dist/cli/args.d.ts +9 -0
- package/dist/cli/args.js +71 -0
- package/dist/cli/config.d.ts +38 -0
- package/dist/cli/config.js +94 -0
- package/dist/cli/convex.d.ts +9 -0
- package/dist/cli/convex.js +25 -0
- package/dist/cli/format.d.ts +11 -0
- package/dist/cli/format.js +140 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +721 -0
- package/dist/cli/keychain.d.ts +21 -0
- package/dist/cli/keychain.js +100 -0
- package/dist/cli/operations.d.ts +106 -0
- package/dist/cli/operations.js +623 -0
- package/dist/cli/sdk-package.d.ts +18 -0
- package/dist/cli/sdk-package.js +45 -0
- package/dist/cli/storage-upload.d.ts +9 -0
- package/dist/cli/storage-upload.js +21 -0
- package/dist/cli/watcher-compile.d.ts +1 -0
- package/dist/cli/watcher-compile.js +20 -0
- package/dist/cli/watcher-process.d.ts +1 -0
- package/dist/cli/watcher-process.js +312 -0
- package/dist/cli/workspace-files.d.ts +12 -0
- package/dist/cli/workspace-files.js +91 -0
- package/dist/cli/workspace-local.d.ts +27 -0
- package/dist/cli/workspace-local.js +310 -0
- package/dist/cli/workspace-session.d.ts +13 -0
- package/dist/cli/workspace-session.js +12 -0
- package/dist/compile.d.ts +27 -0
- package/dist/compile.js +834 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +5 -0
- package/dist/schedule-validation.d.ts +1 -0
- package/dist/schedule-validation.js +16 -0
- package/dist/selector-schema.d.ts +26 -0
- package/dist/selector-schema.js +780 -0
- package/dist/selectors.d.ts +25 -0
- package/dist/selectors.js +99 -0
- package/dist/testkit.d.ts +32 -0
- package/dist/testkit.js +161 -0
- package/dist/types.d.ts +184 -0
- package/dist/types.js +110 -0
- package/node_modules/@reasonlayer/integrations/dist/catalog.d.ts +4937 -0
- package/node_modules/@reasonlayer/integrations/dist/catalog.js +20 -0
- package/node_modules/@reasonlayer/integrations/dist/generated/slack.d.ts +3014 -0
- package/node_modules/@reasonlayer/integrations/dist/generated/slack.js +3101 -0
- package/node_modules/@reasonlayer/integrations/dist/index.d.ts +2 -0
- package/node_modules/@reasonlayer/integrations/dist/index.js +1 -0
- package/node_modules/@reasonlayer/integrations/dist/internal/definitions.d.ts +44 -0
- package/node_modules/@reasonlayer/integrations/dist/internal/definitions.js +52 -0
- package/node_modules/@reasonlayer/integrations/dist/internal/transport.d.ts +7 -0
- package/node_modules/@reasonlayer/integrations/dist/internal/transport.js +48 -0
- package/node_modules/@reasonlayer/integrations/dist/testkit.d.ts +1 -0
- package/node_modules/@reasonlayer/integrations/dist/testkit.js +1 -0
- package/node_modules/@reasonlayer/integrations/package.json +26 -0
- package/node_modules/@reasonlayer/protocol/dist/environments.d.ts +7 -0
- package/node_modules/@reasonlayer/protocol/dist/environments.js +7 -0
- package/node_modules/@reasonlayer/protocol/dist/events.d.ts +313 -0
- package/node_modules/@reasonlayer/protocol/dist/events.js +20 -0
- package/node_modules/@reasonlayer/protocol/dist/index.d.ts +18 -0
- package/node_modules/@reasonlayer/protocol/dist/index.js +9 -0
- package/node_modules/@reasonlayer/protocol/dist/ir.d.ts +252 -0
- package/node_modules/@reasonlayer/protocol/dist/ir.js +116 -0
- package/node_modules/@reasonlayer/protocol/dist/permissions.d.ts +5 -0
- package/node_modules/@reasonlayer/protocol/dist/permissions.js +30 -0
- package/node_modules/@reasonlayer/protocol/dist/readmodels.d.ts +617 -0
- package/node_modules/@reasonlayer/protocol/dist/readmodels.js +36 -0
- package/node_modules/@reasonlayer/protocol/dist/runtime.d.ts +67 -0
- package/node_modules/@reasonlayer/protocol/dist/runtime.js +66 -0
- package/node_modules/@reasonlayer/protocol/dist/scheduling.d.ts +69 -0
- package/node_modules/@reasonlayer/protocol/dist/scheduling.js +126 -0
- package/node_modules/@reasonlayer/protocol/dist/selector.d.ts +23 -0
- package/node_modules/@reasonlayer/protocol/dist/selector.js +77 -0
- package/node_modules/@reasonlayer/protocol/dist/tasks.d.ts +69 -0
- package/node_modules/@reasonlayer/protocol/dist/tasks.js +6 -0
- package/node_modules/@reasonlayer/protocol/dist/validate.d.ts +6 -0
- package/node_modules/@reasonlayer/protocol/dist/validate.js +18 -0
- package/node_modules/@reasonlayer/protocol/package.json +21 -0
- package/node_modules/@reasonlayer/runner/dist/environment-materializer.d.ts +13 -0
- package/node_modules/@reasonlayer/runner/dist/environment-materializer.js +92 -0
- package/node_modules/@reasonlayer/runner/dist/flue-transcript.d.ts +17 -0
- package/node_modules/@reasonlayer/runner/dist/flue-transcript.js +182 -0
- package/node_modules/@reasonlayer/runner/dist/index.d.ts +184 -0
- package/node_modules/@reasonlayer/runner/dist/index.js +884 -0
- package/node_modules/@reasonlayer/runner/dist/mcp-supervisor.d.ts +15 -0
- package/node_modules/@reasonlayer/runner/dist/mcp-supervisor.js +142 -0
- package/node_modules/@reasonlayer/runner/dist/sandbox-env.d.ts +36 -0
- package/node_modules/@reasonlayer/runner/dist/sandbox-env.js +171 -0
- package/node_modules/@reasonlayer/runner/dist/task-child.d.ts +1 -0
- package/node_modules/@reasonlayer/runner/dist/task-child.js +72 -0
- package/node_modules/@reasonlayer/runner/package.json +21 -0
- package/package.json +65 -0
package/dist/cli/args.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const BOOLEAN_FLAGS = new Set([
|
|
2
|
+
"bootstrap",
|
|
3
|
+
"disable",
|
|
4
|
+
"enable",
|
|
5
|
+
"help",
|
|
6
|
+
"json",
|
|
7
|
+
"local",
|
|
8
|
+
"no-wait",
|
|
9
|
+
"once",
|
|
10
|
+
"value-stdin",
|
|
11
|
+
"version",
|
|
12
|
+
"watch",
|
|
13
|
+
"wait",
|
|
14
|
+
]);
|
|
15
|
+
export function parseCliArgs(argv) {
|
|
16
|
+
let command;
|
|
17
|
+
const positionals = [];
|
|
18
|
+
const flags = {};
|
|
19
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
20
|
+
const arg = argv[i];
|
|
21
|
+
if (!command && !arg.startsWith("-")) {
|
|
22
|
+
command = arg;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (arg === "--") {
|
|
26
|
+
positionals.push(...argv.slice(i + 1));
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
if (!arg.startsWith("--")) {
|
|
30
|
+
positionals.push(arg);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const raw = arg.slice(2);
|
|
34
|
+
const eq = raw.indexOf("=");
|
|
35
|
+
if (eq !== -1) {
|
|
36
|
+
flags[raw.slice(0, eq)] = raw.slice(eq + 1);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (BOOLEAN_FLAGS.has(raw)) {
|
|
40
|
+
flags[raw] = true;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const next = argv[i + 1];
|
|
44
|
+
if (next !== undefined && !next.startsWith("--")) {
|
|
45
|
+
flags[raw] = next;
|
|
46
|
+
i += 1;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
flags[raw] = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return { command, positionals, flags };
|
|
53
|
+
}
|
|
54
|
+
export function hasFlag(parsed, name) {
|
|
55
|
+
return parsed.flags[name] === true;
|
|
56
|
+
}
|
|
57
|
+
export function stringFlag(parsed, name) {
|
|
58
|
+
const value = parsed.flags[name];
|
|
59
|
+
if (typeof value === "string")
|
|
60
|
+
return value;
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
export function numberFlag(parsed, name) {
|
|
64
|
+
const value = stringFlag(parsed, name);
|
|
65
|
+
if (value === undefined)
|
|
66
|
+
return undefined;
|
|
67
|
+
const n = Number(value);
|
|
68
|
+
if (!Number.isFinite(n))
|
|
69
|
+
throw new Error(`--${name} must be a number`);
|
|
70
|
+
return n;
|
|
71
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare const TOKEN_ONBOARDING_HINT: string;
|
|
2
|
+
/** What operations consume: a deployment URL plus a bearer token. */
|
|
3
|
+
export interface RlConfig {
|
|
4
|
+
convexUrl: string;
|
|
5
|
+
token: string;
|
|
6
|
+
}
|
|
7
|
+
/** Non-secret account metadata persisted for user-facing diagnostics. */
|
|
8
|
+
export interface RlAccount {
|
|
9
|
+
email?: string;
|
|
10
|
+
orgId?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Global (per-user) config lives in `$HOME/.rl/config.json`. `RL_HOME`
|
|
14
|
+
* overrides the directory — production override and test isolation seam.
|
|
15
|
+
*/
|
|
16
|
+
export declare function globalConfigPath(): string;
|
|
17
|
+
export declare function resolvedConvexUrl(): string;
|
|
18
|
+
export declare function resolvedTargetLabel(): "production" | "dev override";
|
|
19
|
+
export declare function loadConfig(options?: {
|
|
20
|
+
optional?: false;
|
|
21
|
+
}): Promise<RlConfig>;
|
|
22
|
+
export declare function loadConfig(options: {
|
|
23
|
+
optional: true;
|
|
24
|
+
}): Promise<RlConfig | undefined>;
|
|
25
|
+
export interface SavedLogin {
|
|
26
|
+
configPath: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Persist a successful login: token to the OS keychain, non-secret account
|
|
30
|
+
* metadata to the global config file. There is deliberately no plaintext-file
|
|
31
|
+
* fallback (spec §11) — if the keychain is unavailable we fail with guidance to
|
|
32
|
+
* use RL_TOKEN with a scoped `rl_pt_` token, which is the headless/CI path.
|
|
33
|
+
*/
|
|
34
|
+
export declare function saveLogin(convexUrl: string, token: string, account?: RlAccount): Promise<SavedLogin>;
|
|
35
|
+
/** Remove the stored token for the currently resolved deployment. */
|
|
36
|
+
export declare function clearLogin(convexUrl?: string): Promise<{
|
|
37
|
+
convexUrl: string;
|
|
38
|
+
}>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { PRODUCTION_CONVEX_URL } from "@reasonlayer/protocol";
|
|
5
|
+
import * as keychain from "./keychain.js";
|
|
6
|
+
import { KeychainAccessError, KeychainUnavailableError } from "./keychain.js";
|
|
7
|
+
export const TOKEN_ONBOARDING_HINT = "Create a platform token in the Reasonlayer console under Capabilities > Tokens, then " +
|
|
8
|
+
'run "rl login --token <token>". Inside the repo, run "pnpm rl login --token <token>" ' +
|
|
9
|
+
"to log in to the local dev deployment.";
|
|
10
|
+
/**
|
|
11
|
+
* Global (per-user) config lives in `$HOME/.rl/config.json`. `RL_HOME`
|
|
12
|
+
* overrides the directory — production override and test isolation seam.
|
|
13
|
+
*/
|
|
14
|
+
export function globalConfigPath() {
|
|
15
|
+
const home = process.env["RL_HOME"];
|
|
16
|
+
return home ? join(resolve(home), "config.json") : join(homedir(), ".rl", "config.json");
|
|
17
|
+
}
|
|
18
|
+
async function writeConfigFile(path, file) {
|
|
19
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
20
|
+
await writeFile(path, `${JSON.stringify(file, null, 2)}\n`, { mode: 0o600 });
|
|
21
|
+
}
|
|
22
|
+
function isKeychainError(err) {
|
|
23
|
+
return err instanceof KeychainUnavailableError || err instanceof KeychainAccessError;
|
|
24
|
+
}
|
|
25
|
+
export function resolvedConvexUrl() {
|
|
26
|
+
return process.env["RL_CONVEX_URL"] ?? PRODUCTION_CONVEX_URL;
|
|
27
|
+
}
|
|
28
|
+
export function resolvedTargetLabel() {
|
|
29
|
+
return process.env["RL_CONVEX_URL"] === undefined ? "production" : "dev override";
|
|
30
|
+
}
|
|
31
|
+
export async function loadConfig(options = {}) {
|
|
32
|
+
const convexUrl = resolvedConvexUrl();
|
|
33
|
+
const envToken = process.env["RL_TOKEN"];
|
|
34
|
+
if (envToken !== undefined)
|
|
35
|
+
return { convexUrl, token: envToken };
|
|
36
|
+
let token;
|
|
37
|
+
let keychainError;
|
|
38
|
+
try {
|
|
39
|
+
token = (await keychain.getToken(convexUrl)) ?? undefined;
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (err instanceof KeychainAccessError)
|
|
43
|
+
keychainError = err;
|
|
44
|
+
else if (!(err instanceof KeychainUnavailableError))
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
if (token !== undefined)
|
|
48
|
+
return { convexUrl, token };
|
|
49
|
+
if (options.optional)
|
|
50
|
+
return undefined;
|
|
51
|
+
// A keychain that holds the token but refused to read it is a distinct
|
|
52
|
+
// failure from "no login" — surface it rather than a misleading prompt.
|
|
53
|
+
if (keychainError) {
|
|
54
|
+
throw new Error(`${keychainError.message}. Your keychain may be locked or the access prompt was denied — ` +
|
|
55
|
+
"re-run and approve it, or set RL_TOKEN with a scoped token.");
|
|
56
|
+
}
|
|
57
|
+
throw notLoggedIn();
|
|
58
|
+
}
|
|
59
|
+
function notLoggedIn() {
|
|
60
|
+
return new Error(`not logged in: ${TOKEN_ONBOARDING_HINT}`);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Persist a successful login: token to the OS keychain, non-secret account
|
|
64
|
+
* metadata to the global config file. There is deliberately no plaintext-file
|
|
65
|
+
* fallback (spec §11) — if the keychain is unavailable we fail with guidance to
|
|
66
|
+
* use RL_TOKEN with a scoped `rl_pt_` token, which is the headless/CI path.
|
|
67
|
+
*/
|
|
68
|
+
export async function saveLogin(convexUrl, token, account = {}) {
|
|
69
|
+
try {
|
|
70
|
+
await keychain.setToken(convexUrl, token);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
if (isKeychainError(err)) {
|
|
74
|
+
throw new Error(`${err.message}. Unlock your keychain and retry, or for headless/CI use ` +
|
|
75
|
+
"RL_TOKEN with a scoped token instead of an interactive login.");
|
|
76
|
+
}
|
|
77
|
+
throw err;
|
|
78
|
+
}
|
|
79
|
+
const path = globalConfigPath();
|
|
80
|
+
const hasAccount = account.email !== undefined || account.orgId !== undefined;
|
|
81
|
+
await writeConfigFile(path, hasAccount ? { account } : {});
|
|
82
|
+
return { configPath: path };
|
|
83
|
+
}
|
|
84
|
+
/** Remove the stored token for the currently resolved deployment. */
|
|
85
|
+
export async function clearLogin(convexUrl = resolvedConvexUrl()) {
|
|
86
|
+
try {
|
|
87
|
+
await keychain.deleteToken(convexUrl);
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
if (!isKeychainError(err))
|
|
91
|
+
throw err;
|
|
92
|
+
}
|
|
93
|
+
return { convexUrl };
|
|
94
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RlConfig } from "./config.js";
|
|
2
|
+
export declare class RlConvexClient {
|
|
3
|
+
readonly config: RlConfig;
|
|
4
|
+
private readonly client;
|
|
5
|
+
constructor(config: RlConfig);
|
|
6
|
+
query<T>(name: string, args: Record<string, unknown>): Promise<T>;
|
|
7
|
+
mutation<T>(name: string, args: Record<string, unknown>): Promise<T>;
|
|
8
|
+
action<T>(name: string, args: Record<string, unknown>): Promise<T>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ConvexHttpClient } from "convex/browser";
|
|
2
|
+
import { makeFunctionReference } from "convex/server";
|
|
3
|
+
function fn(kind, name) {
|
|
4
|
+
return makeFunctionReference(name);
|
|
5
|
+
}
|
|
6
|
+
export class RlConvexClient {
|
|
7
|
+
config;
|
|
8
|
+
client;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.client = new ConvexHttpClient(config.convexUrl, {
|
|
12
|
+
logger: false,
|
|
13
|
+
skipConvexDeploymentUrlCheck: true,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
query(name, args) {
|
|
17
|
+
return this.client.query(fn("query", name), args);
|
|
18
|
+
}
|
|
19
|
+
mutation(name, args) {
|
|
20
|
+
return this.client.mutation(fn("mutation", name), args, { skipQueue: true });
|
|
21
|
+
}
|
|
22
|
+
action(name, args) {
|
|
23
|
+
return this.client.action(fn("action", name), args);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function serializeCliValue(value: unknown, key?: string): unknown;
|
|
2
|
+
export declare function jsonText(value: unknown): string;
|
|
3
|
+
export declare function parseVariableValue(raw: string): unknown;
|
|
4
|
+
export declare function formatVariableList(value: unknown): string;
|
|
5
|
+
export declare function formatCompileErrors(result: {
|
|
6
|
+
errors: {
|
|
7
|
+
stepId?: string;
|
|
8
|
+
message: string;
|
|
9
|
+
}[];
|
|
10
|
+
}): string;
|
|
11
|
+
export declare function formatInspect(value: unknown): string;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
const OPAQUE_VALUE_KEYS = new Set([
|
|
2
|
+
"buildInfo",
|
|
3
|
+
"content",
|
|
4
|
+
"data",
|
|
5
|
+
"decision",
|
|
6
|
+
"input",
|
|
7
|
+
"inputSchema",
|
|
8
|
+
"ir",
|
|
9
|
+
"output",
|
|
10
|
+
"outputSchema",
|
|
11
|
+
"schema",
|
|
12
|
+
"schemaJson",
|
|
13
|
+
"settings",
|
|
14
|
+
"variables",
|
|
15
|
+
"value",
|
|
16
|
+
"defaultJson",
|
|
17
|
+
]);
|
|
18
|
+
const TIMESTAMP_KEYS = new Set([
|
|
19
|
+
"at",
|
|
20
|
+
"checkedAt",
|
|
21
|
+
"connectStartedAt",
|
|
22
|
+
"connectedAt",
|
|
23
|
+
"createdAt",
|
|
24
|
+
"deadlineAt",
|
|
25
|
+
"deletedAt",
|
|
26
|
+
"draftUpdatedAt",
|
|
27
|
+
"endedAt",
|
|
28
|
+
"expiresAt",
|
|
29
|
+
"finishedAt",
|
|
30
|
+
"lastCheckedAt",
|
|
31
|
+
"lastFiredAt",
|
|
32
|
+
"lastHealthyAt",
|
|
33
|
+
"lastHeartbeatAt",
|
|
34
|
+
"lastRefreshedAt",
|
|
35
|
+
"lastSeenAt",
|
|
36
|
+
"lastUsedAt",
|
|
37
|
+
"leaseExpiresAt",
|
|
38
|
+
"loginCompletedAt",
|
|
39
|
+
"loginRequestedAt",
|
|
40
|
+
"nextFireAt",
|
|
41
|
+
"nextRunAt",
|
|
42
|
+
"resolvedAt",
|
|
43
|
+
"revokedAt",
|
|
44
|
+
"scheduledFor",
|
|
45
|
+
"startedAt",
|
|
46
|
+
"ts",
|
|
47
|
+
"updatedAt",
|
|
48
|
+
"workosUpdatedAt",
|
|
49
|
+
]);
|
|
50
|
+
function isTimestampKey(key) {
|
|
51
|
+
return TIMESTAMP_KEYS.has(key);
|
|
52
|
+
}
|
|
53
|
+
function isoTimestamp(value) {
|
|
54
|
+
if (!Number.isFinite(value))
|
|
55
|
+
return value;
|
|
56
|
+
const date = new Date(value);
|
|
57
|
+
return Number.isNaN(date.getTime()) ? value : date.toISOString();
|
|
58
|
+
}
|
|
59
|
+
export function serializeCliValue(value, key) {
|
|
60
|
+
if (key !== undefined && OPAQUE_VALUE_KEYS.has(key))
|
|
61
|
+
return value;
|
|
62
|
+
if (typeof value === "number" && key !== undefined && isTimestampKey(key)) {
|
|
63
|
+
return isoTimestamp(value);
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(value)) {
|
|
66
|
+
return value.map((item) => serializeCliValue(item));
|
|
67
|
+
}
|
|
68
|
+
if (value !== null && typeof value === "object") {
|
|
69
|
+
return Object.fromEntries(Object.entries(value).map(([entryKey, entryValue]) => [
|
|
70
|
+
entryKey,
|
|
71
|
+
serializeCliValue(entryValue, entryKey),
|
|
72
|
+
]));
|
|
73
|
+
}
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
export function jsonText(value) {
|
|
77
|
+
return `${JSON.stringify(serializeCliValue(value), null, 2)}\n`;
|
|
78
|
+
}
|
|
79
|
+
export function parseVariableValue(raw) {
|
|
80
|
+
try {
|
|
81
|
+
return JSON.parse(raw);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return raw;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function inlineJson(value) {
|
|
88
|
+
return JSON.stringify(value) ?? String(value);
|
|
89
|
+
}
|
|
90
|
+
export function formatVariableList(value) {
|
|
91
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
92
|
+
return "No variables declared.\n";
|
|
93
|
+
const lines = value.map((item) => {
|
|
94
|
+
const variable = item;
|
|
95
|
+
const hasOverride = Object.hasOwn(variable, "value");
|
|
96
|
+
const current = hasOverride ? variable.value : variable.defaultJson;
|
|
97
|
+
return `${variable.name}: ${inlineJson(current)}${hasOverride ? "" : " (default)"}`;
|
|
98
|
+
});
|
|
99
|
+
return `${lines.join("\n")}\n`;
|
|
100
|
+
}
|
|
101
|
+
export function formatCompileErrors(result) {
|
|
102
|
+
return result.errors
|
|
103
|
+
.map((error) => `${error.stepId ? `${error.stepId}: ` : ""}${error.message}`)
|
|
104
|
+
.join("\n");
|
|
105
|
+
}
|
|
106
|
+
export function formatInspect(value) {
|
|
107
|
+
const inspected = value;
|
|
108
|
+
if (!inspected.run)
|
|
109
|
+
return jsonText(value);
|
|
110
|
+
const lines = [
|
|
111
|
+
`Run ${inspected.run.runId}`,
|
|
112
|
+
`Workflow: ${inspected.run.workflowId}`,
|
|
113
|
+
`Status: ${inspected.run.status}`,
|
|
114
|
+
];
|
|
115
|
+
if (inspected.run.error)
|
|
116
|
+
lines.push(`Error: ${inspected.run.error}`);
|
|
117
|
+
if (inspected.run.output !== undefined) {
|
|
118
|
+
lines.push(`Output: ${JSON.stringify(inspected.run.output)}`);
|
|
119
|
+
}
|
|
120
|
+
if (inspected.steps && inspected.steps.length > 0) {
|
|
121
|
+
lines.push("Steps:");
|
|
122
|
+
for (const step of inspected.steps) {
|
|
123
|
+
const key = step.invocationKey ? ` key=${step.invocationKey}` : "";
|
|
124
|
+
const error = step.error ? ` error=${JSON.stringify(step.error)}` : "";
|
|
125
|
+
lines.push(`- ${step.stepId}${key} attempt=${step.attempt} status=${step.status}${error}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (inspected.usage) {
|
|
129
|
+
const u = inspected.usage.totals;
|
|
130
|
+
lines.push(`Usage: input=${u.inputTokens} output=${u.outputTokens} cost=$${u.costUsd.toFixed(6)}`);
|
|
131
|
+
}
|
|
132
|
+
if (inspected.transcript && inspected.transcript.length > 0) {
|
|
133
|
+
lines.push("Transcript:");
|
|
134
|
+
for (const event of inspected.transcript) {
|
|
135
|
+
const key = event.invocationKey ? ` key=${event.invocationKey}` : "";
|
|
136
|
+
lines.push(`- ${event.stepId}${key} attempt=${event.attempt} seq=${event.seq} ${event.level} ${event.type} ${JSON.stringify(event.data)}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return `${lines.join("\n")}\n`;
|
|
140
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function main(argv: readonly string[]): Promise<number>;
|