@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 +35 -1
- package/dist/cli.d.ts +2 -0
- package/dist/connection.d.ts +24 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +709 -0
- package/dist/module_bindings/action_table.d.ts +17 -0
- package/dist/module_bindings/add_log_reducer.d.ts +8 -0
- package/dist/module_bindings/add_logs_batch_reducer.d.ts +6 -0
- package/dist/module_bindings/api_key_table.d.ts +14 -0
- package/dist/module_bindings/check_timeouts_reducer.d.ts +4 -0
- package/dist/module_bindings/create_root_flow_reducer.d.ts +7 -0
- package/dist/module_bindings/create_sub_flow_reducer.d.ts +8 -0
- package/dist/module_bindings/error_group_table.d.ts +24 -0
- package/dist/module_bindings/finish_action_reducer.d.ts +6 -0
- package/dist/module_bindings/finish_flow_reducer.d.ts +7 -0
- package/dist/module_bindings/flow_table.d.ts +28 -0
- package/dist/module_bindings/log_entry_table.d.ts +15 -0
- package/dist/module_bindings/register_key_reducer.d.ts +6 -0
- package/dist/module_bindings/start_action_reducer.d.ts +6 -0
- package/dist/module_bindings/types/procedures.d.ts +1 -0
- package/dist/module_bindings/types/reducers.d.ts +21 -0
- package/dist/module_bindings/types.d.ts +59 -0
- package/dist/module_bindings/update_error_group_status_reducer.d.ts +6 -0
- package/package.json +11 -4
- package/src/cli.ts +26 -12
- package/src/index.ts +32 -4
- package/src/module_bindings/create_root_flow_reducer.ts +1 -0
- package/src/module_bindings/flow_table.ts +1 -0
- package/src/module_bindings/types.ts +1 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
keyHash: import("spacetimedb").StringBuilder;
|
|
3
|
+
flowId: import("spacetimedb").U64Builder;
|
|
4
|
+
level: import("spacetimedb").StringBuilder;
|
|
5
|
+
message: import("spacetimedb").StringBuilder;
|
|
6
|
+
data: import("spacetimedb").StringBuilder;
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const _default: import("spacetimedb").RowBuilder<{
|
|
2
|
+
keyHash: import("spacetimedb").StringColumnBuilder<{
|
|
3
|
+
isPrimaryKey: true;
|
|
4
|
+
name: "key_hash";
|
|
5
|
+
}>;
|
|
6
|
+
label: import("spacetimedb").StringBuilder;
|
|
7
|
+
retentionDays: import("spacetimedb").U64ColumnBuilder<{
|
|
8
|
+
name: "retention_days";
|
|
9
|
+
}>;
|
|
10
|
+
createdAt: import("spacetimedb").TimestampColumnBuilder<{
|
|
11
|
+
name: "created_at";
|
|
12
|
+
}>;
|
|
13
|
+
}>;
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
keyHash: import("spacetimedb").StringBuilder;
|
|
3
|
+
parentFlowId: import("spacetimedb").U64Builder;
|
|
4
|
+
name: import("spacetimedb").StringBuilder;
|
|
5
|
+
timeoutSeconds: import("spacetimedb").U64Builder;
|
|
6
|
+
exportToken: import("spacetimedb").StringBuilder;
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
declare const _default: import("spacetimedb").RowBuilder<{
|
|
2
|
+
id: import("spacetimedb").U64ColumnBuilder<{
|
|
3
|
+
isPrimaryKey: true;
|
|
4
|
+
}>;
|
|
5
|
+
keyHash: import("spacetimedb").StringColumnBuilder<{
|
|
6
|
+
name: "key_hash";
|
|
7
|
+
}>;
|
|
8
|
+
fingerprint: import("spacetimedb").StringBuilder;
|
|
9
|
+
message: import("spacetimedb").StringBuilder;
|
|
10
|
+
path: import("spacetimedb").StringBuilder;
|
|
11
|
+
release: import("spacetimedb").StringBuilder;
|
|
12
|
+
count: import("spacetimedb").U64Builder;
|
|
13
|
+
status: import("spacetimedb").StringBuilder;
|
|
14
|
+
firstSeenAt: import("spacetimedb").TimestampColumnBuilder<{
|
|
15
|
+
name: "first_seen_at";
|
|
16
|
+
}>;
|
|
17
|
+
lastSeenAt: import("spacetimedb").U64ColumnBuilder<{
|
|
18
|
+
name: "last_seen_at";
|
|
19
|
+
}>;
|
|
20
|
+
lastFlowId: import("spacetimedb").U64ColumnBuilder<{
|
|
21
|
+
name: "last_flow_id";
|
|
22
|
+
}>;
|
|
23
|
+
}>;
|
|
24
|
+
export default _default;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
declare const _default: import("spacetimedb").RowBuilder<{
|
|
2
|
+
id: import("spacetimedb").U64ColumnBuilder<{
|
|
3
|
+
isPrimaryKey: true;
|
|
4
|
+
}>;
|
|
5
|
+
keyHash: import("spacetimedb").StringColumnBuilder<{
|
|
6
|
+
name: "key_hash";
|
|
7
|
+
}>;
|
|
8
|
+
parentFlowId: import("spacetimedb").U64ColumnBuilder<{
|
|
9
|
+
name: "parent_flow_id";
|
|
10
|
+
}>;
|
|
11
|
+
name: import("spacetimedb").StringBuilder;
|
|
12
|
+
path: import("spacetimedb").StringBuilder;
|
|
13
|
+
status: import("spacetimedb").StringBuilder;
|
|
14
|
+
release: import("spacetimedb").StringBuilder;
|
|
15
|
+
timeoutSeconds: import("spacetimedb").U64ColumnBuilder<{
|
|
16
|
+
name: "timeout_seconds";
|
|
17
|
+
}>;
|
|
18
|
+
createdAt: import("spacetimedb").TimestampColumnBuilder<{
|
|
19
|
+
name: "created_at";
|
|
20
|
+
}>;
|
|
21
|
+
finishedAt: import("spacetimedb").U64ColumnBuilder<{
|
|
22
|
+
name: "finished_at";
|
|
23
|
+
}>;
|
|
24
|
+
exportToken: import("spacetimedb").StringColumnBuilder<{
|
|
25
|
+
name: "export_token";
|
|
26
|
+
}>;
|
|
27
|
+
}>;
|
|
28
|
+
export default _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const _default: import("spacetimedb").RowBuilder<{
|
|
2
|
+
id: import("spacetimedb").U64ColumnBuilder<{
|
|
3
|
+
isPrimaryKey: true;
|
|
4
|
+
}>;
|
|
5
|
+
flowId: import("spacetimedb").U64ColumnBuilder<{
|
|
6
|
+
name: "flow_id";
|
|
7
|
+
}>;
|
|
8
|
+
level: import("spacetimedb").StringBuilder;
|
|
9
|
+
message: import("spacetimedb").StringBuilder;
|
|
10
|
+
data: import("spacetimedb").StringBuilder;
|
|
11
|
+
createdAt: import("spacetimedb").TimestampColumnBuilder<{
|
|
12
|
+
name: "created_at";
|
|
13
|
+
}>;
|
|
14
|
+
}>;
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Infer as __Infer } from "spacetimedb";
|
|
2
|
+
import AddLogReducer from "../add_log_reducer";
|
|
3
|
+
import AddLogsBatchReducer from "../add_logs_batch_reducer";
|
|
4
|
+
import CheckTimeoutsReducer from "../check_timeouts_reducer";
|
|
5
|
+
import CreateRootFlowReducer from "../create_root_flow_reducer";
|
|
6
|
+
import CreateSubFlowReducer from "../create_sub_flow_reducer";
|
|
7
|
+
import FinishActionReducer from "../finish_action_reducer";
|
|
8
|
+
import FinishFlowReducer from "../finish_flow_reducer";
|
|
9
|
+
import RegisterKeyReducer from "../register_key_reducer";
|
|
10
|
+
import StartActionReducer from "../start_action_reducer";
|
|
11
|
+
import UpdateErrorGroupStatusReducer from "../update_error_group_status_reducer";
|
|
12
|
+
export type AddLogParams = __Infer<typeof AddLogReducer>;
|
|
13
|
+
export type AddLogsBatchParams = __Infer<typeof AddLogsBatchReducer>;
|
|
14
|
+
export type CheckTimeoutsParams = __Infer<typeof CheckTimeoutsReducer>;
|
|
15
|
+
export type CreateRootFlowParams = __Infer<typeof CreateRootFlowReducer>;
|
|
16
|
+
export type CreateSubFlowParams = __Infer<typeof CreateSubFlowReducer>;
|
|
17
|
+
export type FinishActionParams = __Infer<typeof FinishActionReducer>;
|
|
18
|
+
export type FinishFlowParams = __Infer<typeof FinishFlowReducer>;
|
|
19
|
+
export type RegisterKeyParams = __Infer<typeof RegisterKeyReducer>;
|
|
20
|
+
export type StartActionParams = __Infer<typeof StartActionReducer>;
|
|
21
|
+
export type UpdateErrorGroupStatusParams = __Infer<typeof UpdateErrorGroupStatusReducer>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type Infer as __Infer } from "spacetimedb";
|
|
2
|
+
export declare const Action: import("spacetimedb").ProductBuilder<{
|
|
3
|
+
id: import("spacetimedb").U64Builder;
|
|
4
|
+
flowId: import("spacetimedb").U64Builder;
|
|
5
|
+
name: import("spacetimedb").StringBuilder;
|
|
6
|
+
status: import("spacetimedb").StringBuilder;
|
|
7
|
+
createdAt: import("spacetimedb").TimestampBuilder;
|
|
8
|
+
finishedAt: import("spacetimedb").U64Builder;
|
|
9
|
+
}>;
|
|
10
|
+
export type Action = __Infer<typeof Action>;
|
|
11
|
+
export declare const ApiKey: import("spacetimedb").ProductBuilder<{
|
|
12
|
+
keyHash: import("spacetimedb").StringBuilder;
|
|
13
|
+
label: import("spacetimedb").StringBuilder;
|
|
14
|
+
retentionDays: import("spacetimedb").U64Builder;
|
|
15
|
+
createdAt: import("spacetimedb").TimestampBuilder;
|
|
16
|
+
}>;
|
|
17
|
+
export type ApiKey = __Infer<typeof ApiKey>;
|
|
18
|
+
export declare const ErrorGroup: import("spacetimedb").ProductBuilder<{
|
|
19
|
+
id: import("spacetimedb").U64Builder;
|
|
20
|
+
keyHash: import("spacetimedb").StringBuilder;
|
|
21
|
+
fingerprint: import("spacetimedb").StringBuilder;
|
|
22
|
+
message: import("spacetimedb").StringBuilder;
|
|
23
|
+
path: import("spacetimedb").StringBuilder;
|
|
24
|
+
release: import("spacetimedb").StringBuilder;
|
|
25
|
+
count: import("spacetimedb").U64Builder;
|
|
26
|
+
status: import("spacetimedb").StringBuilder;
|
|
27
|
+
firstSeenAt: import("spacetimedb").TimestampBuilder;
|
|
28
|
+
lastSeenAt: import("spacetimedb").U64Builder;
|
|
29
|
+
lastFlowId: import("spacetimedb").U64Builder;
|
|
30
|
+
}>;
|
|
31
|
+
export type ErrorGroup = __Infer<typeof ErrorGroup>;
|
|
32
|
+
export declare const Flow: import("spacetimedb").ProductBuilder<{
|
|
33
|
+
id: import("spacetimedb").U64Builder;
|
|
34
|
+
keyHash: import("spacetimedb").StringBuilder;
|
|
35
|
+
parentFlowId: import("spacetimedb").U64Builder;
|
|
36
|
+
name: import("spacetimedb").StringBuilder;
|
|
37
|
+
path: import("spacetimedb").StringBuilder;
|
|
38
|
+
status: import("spacetimedb").StringBuilder;
|
|
39
|
+
release: import("spacetimedb").StringBuilder;
|
|
40
|
+
timeoutSeconds: import("spacetimedb").U64Builder;
|
|
41
|
+
createdAt: import("spacetimedb").TimestampBuilder;
|
|
42
|
+
finishedAt: import("spacetimedb").U64Builder;
|
|
43
|
+
exportToken: import("spacetimedb").StringBuilder;
|
|
44
|
+
}>;
|
|
45
|
+
export type Flow = __Infer<typeof Flow>;
|
|
46
|
+
export declare const GcJob: import("spacetimedb").ProductBuilder<{
|
|
47
|
+
scheduledId: import("spacetimedb").U64Builder;
|
|
48
|
+
scheduledAt: import("spacetimedb").ScheduleAtBuilder;
|
|
49
|
+
}>;
|
|
50
|
+
export type GcJob = __Infer<typeof GcJob>;
|
|
51
|
+
export declare const LogEntry: import("spacetimedb").ProductBuilder<{
|
|
52
|
+
id: import("spacetimedb").U64Builder;
|
|
53
|
+
flowId: import("spacetimedb").U64Builder;
|
|
54
|
+
level: import("spacetimedb").StringBuilder;
|
|
55
|
+
message: import("spacetimedb").StringBuilder;
|
|
56
|
+
data: import("spacetimedb").StringBuilder;
|
|
57
|
+
createdAt: import("spacetimedb").TimestampBuilder;
|
|
58
|
+
}>;
|
|
59
|
+
export type LogEntry = __Infer<typeof LogEntry>;
|
package/package.json
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@radishbot/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
|
-
".":
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"bun": "./src/index.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
9
13
|
},
|
|
10
14
|
"bin": {
|
|
11
15
|
"radish": "./src/cli.ts"
|
|
12
16
|
},
|
|
13
17
|
"files": [
|
|
14
18
|
"src",
|
|
19
|
+
"dist",
|
|
15
20
|
"README.md"
|
|
16
21
|
],
|
|
17
22
|
"scripts": {
|
|
23
|
+
"build": "bun build ./src/index.ts --outdir dist --target node --format esm --external spacetimedb --external ws",
|
|
24
|
+
"prepublishOnly": "bun run build",
|
|
18
25
|
"cli": "bun run ./src/cli.ts"
|
|
19
26
|
},
|
|
20
27
|
"dependencies": {
|
package/src/cli.ts
CHANGED
|
@@ -185,19 +185,27 @@ function cmdList(flows: any[]) {
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
const hasRelease = roots.some((f) => f.release && f.release !== "");
|
|
188
|
+
const hasRunId = roots.some((f) => f.runId && f.runId !== "");
|
|
188
189
|
|
|
189
190
|
console.log(`${c.bold}Flows${c.reset} ${c.dim}(${roots.length} total)${c.reset}\n`);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
191
|
+
const cols = [
|
|
192
|
+
"ID".padEnd(8),
|
|
193
|
+
"STATUS".padEnd(10),
|
|
194
|
+
...(hasRunId ? ["RUN".padEnd(18)] : []),
|
|
195
|
+
...(hasRelease ? ["RELEASE".padEnd(10)] : []),
|
|
196
|
+
"DURATION".padEnd(10),
|
|
197
|
+
"CREATED",
|
|
198
|
+
];
|
|
199
|
+
const divs = [
|
|
200
|
+
"─".repeat(8),
|
|
201
|
+
"─".repeat(10),
|
|
202
|
+
...(hasRunId ? ["─".repeat(18)] : []),
|
|
203
|
+
...(hasRelease ? ["─".repeat(10)] : []),
|
|
204
|
+
"─".repeat(10),
|
|
205
|
+
"─".repeat(24),
|
|
206
|
+
];
|
|
207
|
+
console.log(`${c.dim} ${cols.join(" ")}${c.reset}`);
|
|
208
|
+
console.log(`${c.dim} ${divs.join(" ")}${c.reset}`);
|
|
201
209
|
|
|
202
210
|
for (const f of roots.slice(0, 30)) {
|
|
203
211
|
const id = f.id.toString().padEnd(8);
|
|
@@ -205,8 +213,11 @@ function cmdList(flows: any[]) {
|
|
|
205
213
|
const status = padRight(f.status, 10);
|
|
206
214
|
const dur = f.finishedAt !== 0n ? padRight(fmtDuration(f.createdAt, f.finishedAt), 10) : padRight("—", 10);
|
|
207
215
|
const time = fmtDateTime(f.createdAt);
|
|
216
|
+
const runIdCol = hasRunId ? padRight(f.runId ? f.runId.slice(0, 16) : "—", 18) : "";
|
|
208
217
|
const release = hasRelease ? padRight(f.release || "—", 10) + " " : "";
|
|
209
|
-
console.log(
|
|
218
|
+
console.log(
|
|
219
|
+
` ${c.dim}${id}${c.reset} ${sc}${status}${c.reset} ${hasRunId ? runIdCol + " " : ""}${release}${dur} ${c.dim}${time}${c.reset}`,
|
|
220
|
+
);
|
|
210
221
|
}
|
|
211
222
|
|
|
212
223
|
if (roots.length > 30) {
|
|
@@ -225,6 +236,9 @@ function cmdShow(flowId: bigint, allFlows: any[], allLogs: any[]) {
|
|
|
225
236
|
const sc = statusColor(flow.status);
|
|
226
237
|
const releaseTag = flow.release ? ` ${c.dim}(${flow.release})${c.reset}` : "";
|
|
227
238
|
console.log(`${c.bold}Flow #${flow.id}${c.reset} ${sc}${flow.status}${c.reset}${releaseTag}`);
|
|
239
|
+
if (flow.runId) {
|
|
240
|
+
console.log(`${c.dim}Run: ${flow.runId}${c.reset}`);
|
|
241
|
+
}
|
|
228
242
|
console.log(`${c.dim}Created: ${fmtDateTime(flow.createdAt)}${c.reset}`);
|
|
229
243
|
if (flow.finishedAt !== 0n) {
|
|
230
244
|
console.log(`${c.dim}Duration: ${fmtDuration(flow.createdAt, flow.finishedAt)}${c.reset}`);
|
package/src/index.ts
CHANGED
|
@@ -97,6 +97,7 @@ export class Flow {
|
|
|
97
97
|
private _name: string;
|
|
98
98
|
private _timeoutSeconds: bigint;
|
|
99
99
|
private _release: string;
|
|
100
|
+
private _runId: string;
|
|
100
101
|
|
|
101
102
|
/** @internal */
|
|
102
103
|
constructor(
|
|
@@ -106,6 +107,7 @@ export class Flow {
|
|
|
106
107
|
name: string,
|
|
107
108
|
timeoutSeconds: number,
|
|
108
109
|
release: string = "",
|
|
110
|
+
runId: string = "",
|
|
109
111
|
) {
|
|
110
112
|
this._sdk = sdk;
|
|
111
113
|
this._keyHash = keyHash;
|
|
@@ -113,6 +115,7 @@ export class Flow {
|
|
|
113
115
|
this._name = name;
|
|
114
116
|
this._timeoutSeconds = !timeoutSeconds || timeoutSeconds === Infinity ? 0n : BigInt(timeoutSeconds);
|
|
115
117
|
this._release = release;
|
|
118
|
+
this._runId = runId;
|
|
116
119
|
this._exportToken = generateToken();
|
|
117
120
|
this._ready = new Promise<void>((resolve) => {
|
|
118
121
|
this._resolveReady = resolve;
|
|
@@ -128,7 +131,14 @@ export class Flow {
|
|
|
128
131
|
|
|
129
132
|
if (this._parentId === 0n) {
|
|
130
133
|
const id = await this._sdk.createFlowAndResolveId(
|
|
131
|
-
() =>
|
|
134
|
+
() =>
|
|
135
|
+
conn.reducers.createRootFlow({
|
|
136
|
+
keyHash,
|
|
137
|
+
runId: this._runId,
|
|
138
|
+
timeoutSeconds,
|
|
139
|
+
exportToken,
|
|
140
|
+
release: this._release,
|
|
141
|
+
}),
|
|
132
142
|
exportToken,
|
|
133
143
|
);
|
|
134
144
|
this._id = id;
|
|
@@ -191,7 +201,7 @@ export class Flow {
|
|
|
191
201
|
|
|
192
202
|
/** Create a sub-action. Returns immediately — creation runs in background. */
|
|
193
203
|
action(name: string, timeoutSeconds = 100): Flow {
|
|
194
|
-
const child = new Flow(this._sdk, this._keyHash, 0n, name, timeoutSeconds, this._release);
|
|
204
|
+
const child = new Flow(this._sdk, this._keyHash, 0n, name, timeoutSeconds, this._release, this._runId);
|
|
195
205
|
this._ready.then(() => {
|
|
196
206
|
(child as any)._parentId = this._id!;
|
|
197
207
|
child._create();
|
|
@@ -252,6 +262,11 @@ export class Flow {
|
|
|
252
262
|
});
|
|
253
263
|
}
|
|
254
264
|
|
|
265
|
+
/** Get the run ID for this flow (pass to subprocesses via env, args, etc.) */
|
|
266
|
+
get runId(): string {
|
|
267
|
+
return this._runId;
|
|
268
|
+
}
|
|
269
|
+
|
|
255
270
|
/** Export this flow's handle for restoration in another context */
|
|
256
271
|
async exportID(): Promise<string> {
|
|
257
272
|
await this._ready;
|
|
@@ -259,6 +274,7 @@ export class Flow {
|
|
|
259
274
|
flowId: this._id!.toString(),
|
|
260
275
|
exportToken: this._exportToken,
|
|
261
276
|
keyHash: this._keyHash,
|
|
277
|
+
runId: this._runId,
|
|
262
278
|
});
|
|
263
279
|
}
|
|
264
280
|
|
|
@@ -323,6 +339,8 @@ export interface RLOptions {
|
|
|
323
339
|
defaultTimeout?: number;
|
|
324
340
|
release?: string;
|
|
325
341
|
retention?: string;
|
|
342
|
+
/** Run ID — groups flows across processes. Auto-generated if not provided. */
|
|
343
|
+
runId?: string;
|
|
326
344
|
}
|
|
327
345
|
|
|
328
346
|
function parseRetention(retention: string): number {
|
|
@@ -360,6 +378,7 @@ export async function RL(secretKey: string, options: RLOptions = {}): Promise<Fl
|
|
|
360
378
|
defaultTimeout = 100,
|
|
361
379
|
release = "",
|
|
362
380
|
retention = "30d",
|
|
381
|
+
runId = generateRunId(),
|
|
363
382
|
} = options;
|
|
364
383
|
|
|
365
384
|
const retentionDays = parseRetention(retention);
|
|
@@ -387,7 +406,7 @@ export async function RL(secretKey: string, options: RLOptions = {}): Promise<Fl
|
|
|
387
406
|
}
|
|
388
407
|
|
|
389
408
|
// Root flow — creation runs in background, logs queue until ready
|
|
390
|
-
const root = new Flow(sdk, keyHash, 0n, "/", 0, release);
|
|
409
|
+
const root = new Flow(sdk, keyHash, 0n, "/", 0, release, runId);
|
|
391
410
|
root._create(); // fire-and-forget — resolves _ready when server assigns ID
|
|
392
411
|
return root;
|
|
393
412
|
}
|
|
@@ -405,7 +424,7 @@ export async function restoreFlow(secretKey: string, exportedId: string, options
|
|
|
405
424
|
const sdk = new SdkConnection(host, dbName);
|
|
406
425
|
await sdk.connect();
|
|
407
426
|
|
|
408
|
-
const flow = new Flow(sdk, keyHash, 0n, "restored", 100);
|
|
427
|
+
const flow = new Flow(sdk, keyHash, 0n, "restored", 100, "", parsed.runId || "");
|
|
409
428
|
(flow as any)._id = BigInt(parsed.flowId);
|
|
410
429
|
(flow as any)._exportToken = parsed.exportToken;
|
|
411
430
|
(flow as any)._resolveReady();
|
|
@@ -423,3 +442,12 @@ export function generateKey(): string {
|
|
|
423
442
|
.join("")
|
|
424
443
|
);
|
|
425
444
|
}
|
|
445
|
+
|
|
446
|
+
/** Generate a random run ID (pass to subprocesses to link flows) */
|
|
447
|
+
export function generateRunId(): string {
|
|
448
|
+
const bytes = new Uint8Array(8);
|
|
449
|
+
crypto.getRandomValues(bytes);
|
|
450
|
+
return Array.from(bytes)
|
|
451
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
452
|
+
.join("");
|
|
453
|
+
}
|