@radishbot/sdk 0.3.1 → 0.5.0

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 CHANGED
@@ -139,6 +139,34 @@ action.info("continuing from service B");
139
139
  await action.finish();
140
140
  ```
141
141
 
142
+ ## Run ID
143
+
144
+ Every `RL()` call auto-generates a **run ID** — a short random string that groups flows across processes. Pass it to subprocesses via env vars, CLI args, or message queues so all flows from one logical execution link together.
145
+
146
+ ```ts
147
+ const root = await RL(key);
148
+
149
+ // Pass to subprocess
150
+ spawn("worker.ts", { env: { ...process.env, RADISH_RUN_ID: root.runId } });
151
+
152
+ // In the subprocess — same run ID groups them together
153
+ const worker = await RL(key, { runId: process.env.RADISH_RUN_ID });
154
+ worker.info("processing");
155
+ await worker.finishAndDisconnect();
156
+ ```
157
+
158
+ You can also generate a run ID upfront:
159
+
160
+ ```ts
161
+ import { generateRunId } from "@radishbot/sdk";
162
+ const runId = generateRunId();
163
+ // pass to multiple services
164
+ const a = await RL(key, { runId });
165
+ const b = await RL(key, { runId });
166
+ ```
167
+
168
+ In the dashboard, click a run ID badge to filter all flows from that run.
169
+
142
170
  ## Release Tracking
143
171
 
144
172
  Tag every flow with a version or commit SHA. Errors are tracked per-release, and regressions (errors reappearing after being resolved) are detected automatically.
@@ -181,6 +209,7 @@ const root = await RL(key, {
181
209
  defaultTimeout: 100, // seconds, default 100
182
210
  release: "v1.0.0", // version or commit SHA
183
211
  retention: "30d", // data retention period
212
+ runId: "abc123", // optional, auto-generated if omitted
184
213
  });
185
214
  ```
186
215
 
@@ -204,12 +233,16 @@ Actions that exceed their timeout are automatically marked as timed out.
204
233
 
205
234
  ### `RL(secretKey, options?) → Promise<Flow>`
206
235
 
207
- Connect and create a root action. Options: `host`, `dbName`, `defaultTimeout`, `release`, `retention`.
236
+ Connect and create a root action. Options: `host`, `dbName`, `defaultTimeout`, `release`, `retention`, `runId`.
208
237
 
209
238
  ### `generateKey() → string`
210
239
 
211
240
  Generate a random secret key (prefix `rl_`).
212
241
 
242
+ ### `generateRunId() → string`
243
+
244
+ Generate a random run ID. Useful when you want to create the ID before calling `RL()`.
245
+
213
246
  ### `restoreFlow(secretKey, handle, options?) → Promise<Flow>`
214
247
 
215
248
  Restore an action from an exported handle string.
@@ -228,4 +261,5 @@ Restore an action from an exported handle string.
228
261
  | `.debug(msg, data?)` | Log at debug level. |
229
262
  | `.log(msg, data?, level?)` | Log at any level. |
230
263
  | `.exportID()` | Export handle for cross-context restore. |
264
+ | `.runId` | The run ID (read-only). Pass to subprocesses. |
231
265
  | `.getId()` | Get server-assigned action ID. |
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bun
2
+ export {};
@@ -0,0 +1,24 @@
1
+ /**
2
+ * SpacetimeDB connection wrapper for the Radish SDK.
3
+ * Uses the generated bindings + SpacetimeDB WebSocket client.
4
+ */
5
+ import { DbConnection as StdbConnection } from './module_bindings';
6
+ export declare class SdkConnection {
7
+ private _host;
8
+ private _dbName;
9
+ private _conn;
10
+ private _connectPromise;
11
+ private _timeoutInterval;
12
+ private _keyHash;
13
+ private _flowWaiters;
14
+ constructor(host: string, dbName: string);
15
+ setKeyHash(keyHash: string): void;
16
+ connect(): Promise<StdbConnection>;
17
+ get conn(): StdbConnection;
18
+ /**
19
+ * Call a reducer and wait for the flow to appear in the subscription.
20
+ * Returns the server-assigned flow ID.
21
+ */
22
+ createFlowAndResolveId(reducerCall: () => void, exportToken: string): Promise<bigint>;
23
+ disconnect(): void;
24
+ }
@@ -0,0 +1,34 @@
1
+ export type LogLevel = "info" | "warn" | "error" | "debug";
2
+
3
+ export declare class Flow {
4
+ readonly runId: string;
5
+ log(message: string, data?: unknown, level?: LogLevel): this;
6
+ info(message: string, data?: unknown): this;
7
+ warn(message: string, data?: unknown): this;
8
+ error(message: string, data?: unknown): this;
9
+ debug(message: string, data?: unknown): this;
10
+ action(name: string, timeoutSeconds?: number): Flow;
11
+ flow(name: string, timeoutSeconds?: number): Flow;
12
+ a<T>(name: string, fn: (action: Flow) => T | Promise<T>, timeoutSeconds?: number): Promise<T>;
13
+ finish(): Promise<void>;
14
+ finishWithError(err?: Error | string): Promise<void>;
15
+ exportID(): Promise<string>;
16
+ getId(): Promise<bigint>;
17
+ disconnect(): void;
18
+ finishAndDisconnect(): Promise<void>;
19
+ }
20
+
21
+ export interface RLOptions {
22
+ host?: string;
23
+ dbName?: string;
24
+ label?: string;
25
+ defaultTimeout?: number;
26
+ release?: string;
27
+ retention?: string;
28
+ runId?: string;
29
+ }
30
+
31
+ export declare function RL(secretKey: string, options?: RLOptions): Promise<Flow>;
32
+ export declare function restoreFlow(secretKey: string, exportedId: string, options?: RLOptions): Promise<Flow>;
33
+ export declare function generateKey(): string;
34
+ export declare function generateRunId(): string;