@rivet-dev/vercel-world 0.0.0-http-body-streaming.064e07d
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/.turbo/turbo-build.log +4 -0
- package/README.md +31 -0
- package/dist/actors/coordinator.d.ts +114 -0
- package/dist/actors/coordinator.d.ts.map +1 -0
- package/dist/actors/coordinator.js +232 -0
- package/dist/actors/coordinator.js.map +1 -0
- package/dist/actors/db.d.ts +8 -0
- package/dist/actors/db.d.ts.map +1 -0
- package/dist/actors/db.js +282 -0
- package/dist/actors/db.js.map +1 -0
- package/dist/actors/dispatcher.d.ts +84 -0
- package/dist/actors/dispatcher.d.ts.map +1 -0
- package/dist/actors/dispatcher.js +498 -0
- package/dist/actors/dispatcher.js.map +1 -0
- package/dist/actors/hook-token.d.ts +26 -0
- package/dist/actors/hook-token.d.ts.map +1 -0
- package/dist/actors/hook-token.js +151 -0
- package/dist/actors/hook-token.js.map +1 -0
- package/dist/actors/shared.d.ts +366 -0
- package/dist/actors/shared.d.ts.map +1 -0
- package/dist/actors/shared.js +112 -0
- package/dist/actors/shared.js.map +1 -0
- package/dist/actors/streams.d.ts +26 -0
- package/dist/actors/streams.d.ts.map +1 -0
- package/dist/actors/streams.js +127 -0
- package/dist/actors/streams.js.map +1 -0
- package/dist/actors/workflow-run.d.ts +891 -0
- package/dist/actors/workflow-run.d.ts.map +1 -0
- package/dist/actors/workflow-run.js +872 -0
- package/dist/actors/workflow-run.js.map +1 -0
- package/dist/actors.d.ts +2244 -0
- package/dist/actors.d.ts.map +1 -0
- package/dist/actors.js +16 -0
- package/dist/actors.js.map +1 -0
- package/dist/codec.d.ts +4 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/codec.js +27 -0
- package/dist/codec.js.map +1 -0
- package/dist/index.d.ts +843 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +567 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +24 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +51 -0
- package/scripts/conformance/run.ts +278 -0
- package/scripts/integration/run.ts +935 -0
- package/src/actors/coordinator.ts +360 -0
- package/src/actors/db.ts +291 -0
- package/src/actors/dispatcher.ts +787 -0
- package/src/actors/hook-token.ts +239 -0
- package/src/actors/shared.ts +153 -0
- package/src/actors/streams.ts +215 -0
- package/src/actors/workflow-run.ts +1477 -0
- package/src/actors.ts +18 -0
- package/src/codec.ts +28 -0
- package/src/index.ts +788 -0
- package/src/runtime.ts +29 -0
- package/tests/conformance.test.ts +8 -0
- package/tests/helpers/db.ts +62 -0
- package/tests/helpers/dispatcher-driver.ts +71 -0
- package/tests/helpers/harness.ts +161 -0
- package/tests/integration/crash-restart.test.ts +145 -0
- package/tests/integration/dispatcher-loop.test.ts +144 -0
- package/tests/integration/hook-token.test.ts +160 -0
- package/tests/integration/hooks.test.ts +123 -0
- package/tests/integration/streams.test.ts +178 -0
- package/tests/integration/workflow-events.test.ts +326 -0
- package/tests/setup.ts +10 -0
- package/tests/unit/codec.test.ts +73 -0
- package/tests/unit/coordinator-record.test.ts +177 -0
- package/tests/unit/db-migrations.test.ts +65 -0
- package/tests/unit/dispatcher-queue.test.ts +274 -0
- package/tests/unit/logging.test.ts +49 -0
- package/tests/unit/readiness.test.ts +102 -0
- package/tests/unit/transaction.test.ts +76 -0
- package/tsconfig.build.json +13 -0
- package/tsconfig.json +12 -0
- package/vitest.config.ts +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# `@rivet-dev/vercel-world`
|
|
2
|
+
|
|
3
|
+
[Vercel Workflows](https://useworkflow.dev) backed by Rivet Actors.
|
|
4
|
+
|
|
5
|
+
This integration is in beta.
|
|
6
|
+
|
|
7
|
+
Set `WORKFLOW_TARGET_WORLD=@rivet-dev/vercel-world`, then set
|
|
8
|
+
`WORKFLOW_RUNTIME_URL` and the Rivet connection variables in the application
|
|
9
|
+
environment. The package exports the standard `createWorld()` factory expected
|
|
10
|
+
by Vercel Eve and Vercel Workflows. The first World operation starts the
|
|
11
|
+
registry lazily and waits until its envoy is ready.
|
|
12
|
+
|
|
13
|
+
Applications that need to add actors to the same process can compose the
|
|
14
|
+
package's actor aggregate instead:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { createWorld as createRivetWorld } from "@rivet-dev/vercel-world";
|
|
18
|
+
import { vercelWorldActors } from "@rivet-dev/vercel-world/registry";
|
|
19
|
+
import { setup } from "rivetkit";
|
|
20
|
+
|
|
21
|
+
import { myActor } from "./my-actor";
|
|
22
|
+
|
|
23
|
+
export const registry = setup({
|
|
24
|
+
use: { ...vercelWorldActors, myActor },
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const createWorld = () => createRivetWorld({ registry });
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
This package only implements orchestration. Sandbox selection, including
|
|
31
|
+
agentOS, stays in Vercel Eve's sandbox configuration.
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { type ListHooksParams, type ListWorkflowRunsParams, type WorkflowRun } from "@workflow/world";
|
|
2
|
+
import { type Ctx } from "./shared.js";
|
|
3
|
+
export type CoordinatorContext = Ctx;
|
|
4
|
+
type CorrelationKind = "step" | "hook" | "wait";
|
|
5
|
+
type Timestamp = Date | number | string;
|
|
6
|
+
export type CoordinatorIndexUpdate = {
|
|
7
|
+
type: "run.upsert";
|
|
8
|
+
run: WorkflowRun;
|
|
9
|
+
runRevision: number;
|
|
10
|
+
} | {
|
|
11
|
+
type: "correlation.put" | "correlation.delete";
|
|
12
|
+
correlationId: string;
|
|
13
|
+
runId: string;
|
|
14
|
+
kind: CorrelationKind;
|
|
15
|
+
runRevision: number;
|
|
16
|
+
} | {
|
|
17
|
+
type: "hook.upsert" | "hook.delete";
|
|
18
|
+
hookId: string;
|
|
19
|
+
runId: string;
|
|
20
|
+
token: string;
|
|
21
|
+
runRevision: number;
|
|
22
|
+
createdAt: Timestamp;
|
|
23
|
+
updatedAt: Timestamp;
|
|
24
|
+
};
|
|
25
|
+
/** Applies one derived index update. Canonical workflow progress never awaits this. */
|
|
26
|
+
export declare function applyCoordinatorUpdate(c: CoordinatorContext, input: CoordinatorIndexUpdate): Promise<void>;
|
|
27
|
+
export declare const coordinator: import("rivetkit").ActorDefinition<unknown, unknown, unknown, unknown, unknown, import("rivetkit/db").DatabaseProvider<import("rivetkit/db").RawAccess>, Record<never, never>, Record<never, never>, {
|
|
28
|
+
update: (c: import("rivetkit").ActionContext<unknown, unknown, unknown, unknown, unknown, import("rivetkit/db").DatabaseProvider<import("rivetkit/db").RawAccess>, Record<never, never>, Record<never, never>>, input: CoordinatorIndexUpdate) => Promise<void>;
|
|
29
|
+
getRunIdByCorrelation: (c: import("rivetkit").ActionContext<unknown, unknown, unknown, unknown, unknown, import("rivetkit/db").DatabaseProvider<import("rivetkit/db").RawAccess>, Record<never, never>, Record<never, never>>, correlationId: string) => Promise<string | null>;
|
|
30
|
+
getRunIdByHook: (c: import("rivetkit").ActionContext<unknown, unknown, unknown, unknown, unknown, import("rivetkit/db").DatabaseProvider<import("rivetkit/db").RawAccess>, Record<never, never>, Record<never, never>>, hookId: string) => Promise<string | null>;
|
|
31
|
+
listHookIndex: (c: import("rivetkit").ActionContext<unknown, unknown, unknown, unknown, unknown, import("rivetkit/db").DatabaseProvider<import("rivetkit/db").RawAccess>, Record<never, never>, Record<never, never>>, params?: ListHooksParams) => Promise<{
|
|
32
|
+
data: {
|
|
33
|
+
hookId: string;
|
|
34
|
+
runId: string;
|
|
35
|
+
}[];
|
|
36
|
+
cursor: string | null;
|
|
37
|
+
hasMore: boolean;
|
|
38
|
+
}>;
|
|
39
|
+
listRuns: (c: import("rivetkit").ActionContext<unknown, unknown, unknown, unknown, unknown, import("rivetkit/db").DatabaseProvider<import("rivetkit/db").RawAccess>, Record<never, never>, Record<never, never>>, params?: ListWorkflowRunsParams) => Promise<{
|
|
40
|
+
data: ({
|
|
41
|
+
runId: string;
|
|
42
|
+
deploymentId: string;
|
|
43
|
+
workflowName: string;
|
|
44
|
+
attributes: Record<string, string>;
|
|
45
|
+
createdAt: Date;
|
|
46
|
+
updatedAt: Date;
|
|
47
|
+
status: "pending" | "running";
|
|
48
|
+
specVersion?: number | undefined;
|
|
49
|
+
executionContext?: Record<string, any> | undefined;
|
|
50
|
+
input?: unknown;
|
|
51
|
+
errorCode?: string | undefined;
|
|
52
|
+
expiredAt?: Date | undefined;
|
|
53
|
+
startedAt?: Date | undefined;
|
|
54
|
+
output?: undefined;
|
|
55
|
+
error?: undefined;
|
|
56
|
+
completedAt?: undefined;
|
|
57
|
+
} | {
|
|
58
|
+
runId: string;
|
|
59
|
+
deploymentId: string;
|
|
60
|
+
workflowName: string;
|
|
61
|
+
attributes: Record<string, string>;
|
|
62
|
+
createdAt: Date;
|
|
63
|
+
updatedAt: Date;
|
|
64
|
+
status: "cancelled";
|
|
65
|
+
completedAt: Date;
|
|
66
|
+
specVersion?: number | undefined;
|
|
67
|
+
executionContext?: Record<string, any> | undefined;
|
|
68
|
+
input?: unknown;
|
|
69
|
+
errorCode?: string | undefined;
|
|
70
|
+
expiredAt?: Date | undefined;
|
|
71
|
+
startedAt?: Date | undefined;
|
|
72
|
+
output?: undefined;
|
|
73
|
+
error?: undefined;
|
|
74
|
+
} | {
|
|
75
|
+
runId: string;
|
|
76
|
+
deploymentId: string;
|
|
77
|
+
workflowName: string;
|
|
78
|
+
attributes: Record<string, string>;
|
|
79
|
+
createdAt: Date;
|
|
80
|
+
updatedAt: Date;
|
|
81
|
+
status: "completed";
|
|
82
|
+
output: unknown;
|
|
83
|
+
completedAt: Date;
|
|
84
|
+
specVersion?: number | undefined;
|
|
85
|
+
executionContext?: Record<string, any> | undefined;
|
|
86
|
+
input?: unknown;
|
|
87
|
+
errorCode?: string | undefined;
|
|
88
|
+
expiredAt?: Date | undefined;
|
|
89
|
+
startedAt?: Date | undefined;
|
|
90
|
+
error?: undefined;
|
|
91
|
+
} | {
|
|
92
|
+
runId: string;
|
|
93
|
+
deploymentId: string;
|
|
94
|
+
workflowName: string;
|
|
95
|
+
attributes: Record<string, string>;
|
|
96
|
+
createdAt: Date;
|
|
97
|
+
updatedAt: Date;
|
|
98
|
+
status: "failed";
|
|
99
|
+
error: unknown;
|
|
100
|
+
completedAt: Date;
|
|
101
|
+
specVersion?: number | undefined;
|
|
102
|
+
executionContext?: Record<string, any> | undefined;
|
|
103
|
+
input?: unknown;
|
|
104
|
+
errorCode?: string | undefined;
|
|
105
|
+
expiredAt?: Date | undefined;
|
|
106
|
+
startedAt?: Date | undefined;
|
|
107
|
+
output?: undefined;
|
|
108
|
+
})[];
|
|
109
|
+
cursor: string | null;
|
|
110
|
+
hasMore: boolean;
|
|
111
|
+
}>;
|
|
112
|
+
}>;
|
|
113
|
+
export {};
|
|
114
|
+
//# sourceMappingURL=coordinator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinator.d.ts","sourceRoot":"","sources":["../../src/actors/coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAChB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAMN,KAAK,GAAG,EACR,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAErC,KAAK,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAChD,KAAK,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;AAExC,MAAM,MAAM,sBAAsB,GAC/B;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,GAAG,EAAE,WAAW,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAC7D;IACA,IAAI,EAAE,iBAAiB,GAAG,oBAAoB,CAAC;IAC/C,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,eAAe,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACnB,GACD;IACA,IAAI,EAAE,aAAa,GAAG,aAAa,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,EAAE,SAAS,CAAC;CACpB,CAAC;AAgLL,uFAAuF;AACvF,wBAAsB,sBAAsB,CAC3C,CAAC,EAAE,kBAAkB,EACrB,KAAK,EAAE,sBAAsB,iBAkB7B;AA0BD,eAAO,MAAM,WAAW;2NAGG,sBAAsB;kPAIC,MAAM;oOAUpB,MAAM;oOASN,eAAe;;;;;;;;+NAgCpB,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuCnD,CAAC"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { actor } from "rivetkit";
|
|
2
|
+
import { encodeValue } from "../codec.js";
|
|
3
|
+
import { coordinatorDb } from "./db.js";
|
|
4
|
+
import { filterData, one, rowToRun, toMs, withActorTransaction, } from "./shared.js";
|
|
5
|
+
function assertCoordinatorKey(c) {
|
|
6
|
+
if (String(c.key[0] ?? "") !== "coordinator" || c.key.length !== 1) {
|
|
7
|
+
throw new Error('coordinator actor key must be ["coordinator"]');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function assertRevision(revision) {
|
|
11
|
+
if (!Number.isSafeInteger(revision) || revision < 0) {
|
|
12
|
+
throw new Error("coordinator update requires a non-negative run revision");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function timestamp(value) {
|
|
16
|
+
const result = toMs(value);
|
|
17
|
+
if (result == null || !Number.isFinite(result)) {
|
|
18
|
+
throw new Error("coordinator update requires a valid timestamp");
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
async function upsertRun(c, run, runRevision) {
|
|
23
|
+
await c.db.execute(`
|
|
24
|
+
INSERT INTO runs_index (
|
|
25
|
+
run_id, run_revision, status, deployment_id, workflow_name,
|
|
26
|
+
spec_version, execution_context, attributes, input, output, error,
|
|
27
|
+
expired_at, started_at, completed_at, created_at, updated_at
|
|
28
|
+
)
|
|
29
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
30
|
+
ON CONFLICT(run_id) DO UPDATE SET
|
|
31
|
+
run_revision = excluded.run_revision,
|
|
32
|
+
status = excluded.status,
|
|
33
|
+
deployment_id = excluded.deployment_id,
|
|
34
|
+
workflow_name = excluded.workflow_name,
|
|
35
|
+
spec_version = excluded.spec_version,
|
|
36
|
+
execution_context = excluded.execution_context,
|
|
37
|
+
attributes = excluded.attributes,
|
|
38
|
+
input = excluded.input,
|
|
39
|
+
output = excluded.output,
|
|
40
|
+
error = excluded.error,
|
|
41
|
+
expired_at = excluded.expired_at,
|
|
42
|
+
started_at = excluded.started_at,
|
|
43
|
+
completed_at = excluded.completed_at,
|
|
44
|
+
created_at = excluded.created_at,
|
|
45
|
+
updated_at = excluded.updated_at
|
|
46
|
+
WHERE excluded.run_revision >= runs_index.run_revision
|
|
47
|
+
`, run.runId, runRevision, run.status, run.deploymentId, run.workflowName, run.specVersion ?? null, encodeValue(run.executionContext), encodeValue(run.attributes), encodeValue(run.input), encodeValue(run.output), encodeValue(run.error), toMs(run.expiredAt), toMs(run.startedAt), toMs(run.completedAt), toMs(run.createdAt), toMs(run.updatedAt));
|
|
48
|
+
}
|
|
49
|
+
async function updateCorrelation(c, input) {
|
|
50
|
+
const existing = await one(c, "SELECT run_id, kind FROM correlation_index WHERE correlation_id = ?", input.correlationId);
|
|
51
|
+
if (existing &&
|
|
52
|
+
(String(existing.run_id) !== input.runId ||
|
|
53
|
+
String(existing.kind) !== input.kind)) {
|
|
54
|
+
throw new Error(`correlation "${input.correlationId}" is already owned by another workflow entity`);
|
|
55
|
+
}
|
|
56
|
+
const status = input.type === "correlation.put" ? "active" : "deleted";
|
|
57
|
+
await c.db.execute(`
|
|
58
|
+
INSERT INTO correlation_index (
|
|
59
|
+
correlation_id, run_id, kind, run_revision, status
|
|
60
|
+
)
|
|
61
|
+
VALUES (?, ?, ?, ?, ?)
|
|
62
|
+
ON CONFLICT(correlation_id) DO UPDATE SET
|
|
63
|
+
run_revision = excluded.run_revision,
|
|
64
|
+
status = excluded.status
|
|
65
|
+
WHERE
|
|
66
|
+
NOT (
|
|
67
|
+
correlation_index.status = 'deleted'
|
|
68
|
+
AND excluded.status = 'active'
|
|
69
|
+
)
|
|
70
|
+
AND (
|
|
71
|
+
excluded.run_revision > correlation_index.run_revision
|
|
72
|
+
OR (
|
|
73
|
+
excluded.run_revision = correlation_index.run_revision
|
|
74
|
+
AND (
|
|
75
|
+
excluded.status = 'deleted'
|
|
76
|
+
OR correlation_index.status = excluded.status
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
`, input.correlationId, input.runId, input.kind, input.runRevision, status);
|
|
81
|
+
}
|
|
82
|
+
async function updateHook(c, input) {
|
|
83
|
+
const existing = await one(c, "SELECT run_id FROM hooks_index WHERE hook_id = ?", input.hookId);
|
|
84
|
+
if (existing && String(existing.run_id) !== input.runId) {
|
|
85
|
+
throw new Error(`hook "${input.hookId}" is already owned by another workflow run`);
|
|
86
|
+
}
|
|
87
|
+
const status = input.type === "hook.upsert" ? "active" : "deleted";
|
|
88
|
+
await c.db.execute(`
|
|
89
|
+
INSERT INTO hooks_index (
|
|
90
|
+
hook_id, run_id, run_revision, token, status, created_at, updated_at
|
|
91
|
+
)
|
|
92
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
93
|
+
ON CONFLICT(hook_id) DO UPDATE SET
|
|
94
|
+
run_revision = excluded.run_revision,
|
|
95
|
+
token = excluded.token,
|
|
96
|
+
status = excluded.status,
|
|
97
|
+
created_at = excluded.created_at,
|
|
98
|
+
updated_at = excluded.updated_at
|
|
99
|
+
WHERE
|
|
100
|
+
NOT (hooks_index.status = 'deleted' AND excluded.status = 'active')
|
|
101
|
+
AND (
|
|
102
|
+
excluded.run_revision > hooks_index.run_revision
|
|
103
|
+
OR (
|
|
104
|
+
excluded.run_revision = hooks_index.run_revision
|
|
105
|
+
AND (
|
|
106
|
+
excluded.status = 'deleted'
|
|
107
|
+
OR hooks_index.status = excluded.status
|
|
108
|
+
)
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
`, input.hookId, input.runId, input.runRevision, input.token, status, timestamp(input.createdAt), timestamp(input.updatedAt));
|
|
112
|
+
}
|
|
113
|
+
/** Applies one derived index update. Canonical workflow progress never awaits this. */
|
|
114
|
+
export async function applyCoordinatorUpdate(c, input) {
|
|
115
|
+
assertRevision(input.runRevision);
|
|
116
|
+
await withActorTransaction(c, async (tx) => {
|
|
117
|
+
switch (input.type) {
|
|
118
|
+
case "run.upsert":
|
|
119
|
+
await upsertRun(tx, input.run, input.runRevision);
|
|
120
|
+
break;
|
|
121
|
+
case "correlation.put":
|
|
122
|
+
case "correlation.delete":
|
|
123
|
+
await updateCorrelation(tx, input);
|
|
124
|
+
break;
|
|
125
|
+
case "hook.upsert":
|
|
126
|
+
case "hook.delete":
|
|
127
|
+
await updateHook(tx, input);
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function encodeCursor(createdAt, id) {
|
|
133
|
+
return JSON.stringify([Number(createdAt), String(id)]);
|
|
134
|
+
}
|
|
135
|
+
function decodeCursor(cursor) {
|
|
136
|
+
if (cursor == null)
|
|
137
|
+
return undefined;
|
|
138
|
+
try {
|
|
139
|
+
const value = JSON.parse(cursor);
|
|
140
|
+
if (!Array.isArray(value) ||
|
|
141
|
+
value.length !== 2 ||
|
|
142
|
+
!Number.isFinite(value[0]) ||
|
|
143
|
+
typeof value[1] !== "string") {
|
|
144
|
+
throw new Error();
|
|
145
|
+
}
|
|
146
|
+
return [Number(value[0]), value[1]];
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
throw new Error("invalid coordinator pagination cursor");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
export const coordinator = actor({
|
|
153
|
+
db: coordinatorDb,
|
|
154
|
+
actions: {
|
|
155
|
+
update: async (c, input) => {
|
|
156
|
+
assertCoordinatorKey(c);
|
|
157
|
+
await applyCoordinatorUpdate(c, input);
|
|
158
|
+
},
|
|
159
|
+
getRunIdByCorrelation: async (c, correlationId) => {
|
|
160
|
+
assertCoordinatorKey(c);
|
|
161
|
+
const row = await one(c, `SELECT run_id FROM correlation_index
|
|
162
|
+
WHERE correlation_id = ? AND status = 'active'`, correlationId);
|
|
163
|
+
return row?.run_id == null ? null : String(row.run_id);
|
|
164
|
+
},
|
|
165
|
+
getRunIdByHook: async (c, hookId) => {
|
|
166
|
+
assertCoordinatorKey(c);
|
|
167
|
+
const row = await one(c, "SELECT run_id FROM hooks_index WHERE hook_id = ? AND status = 'active'", hookId);
|
|
168
|
+
return row?.run_id == null ? null : String(row.run_id);
|
|
169
|
+
},
|
|
170
|
+
listHookIndex: async (c, params) => {
|
|
171
|
+
assertCoordinatorKey(c);
|
|
172
|
+
const limit = params?.pagination?.limit ?? 100;
|
|
173
|
+
const cursor = decodeCursor(params?.pagination?.cursor);
|
|
174
|
+
const where = ["status = 'active'"];
|
|
175
|
+
const args = [];
|
|
176
|
+
if (cursor) {
|
|
177
|
+
where.push("(created_at, hook_id) < (?, ?)");
|
|
178
|
+
args.push(...cursor);
|
|
179
|
+
}
|
|
180
|
+
const rows = await c.db.execute(`
|
|
181
|
+
SELECT hook_id, run_id, created_at
|
|
182
|
+
FROM hooks_index
|
|
183
|
+
WHERE ${where.join(" AND ")}
|
|
184
|
+
ORDER BY created_at DESC, hook_id DESC
|
|
185
|
+
LIMIT ?
|
|
186
|
+
`, ...args, limit + 1);
|
|
187
|
+
const values = rows.slice(0, limit);
|
|
188
|
+
const last = values.at(-1);
|
|
189
|
+
return {
|
|
190
|
+
data: values.map((row) => ({
|
|
191
|
+
hookId: String(row.hook_id),
|
|
192
|
+
runId: String(row.run_id),
|
|
193
|
+
})),
|
|
194
|
+
cursor: last ? encodeCursor(last.created_at, last.hook_id) : null,
|
|
195
|
+
hasMore: rows.length > limit,
|
|
196
|
+
};
|
|
197
|
+
},
|
|
198
|
+
listRuns: async (c, params) => {
|
|
199
|
+
assertCoordinatorKey(c);
|
|
200
|
+
const limit = params?.pagination?.limit ?? 20;
|
|
201
|
+
const cursor = decodeCursor(params?.pagination?.cursor);
|
|
202
|
+
const where = [];
|
|
203
|
+
const args = [];
|
|
204
|
+
if (cursor) {
|
|
205
|
+
where.push("(created_at, run_id) < (?, ?)");
|
|
206
|
+
args.push(...cursor);
|
|
207
|
+
}
|
|
208
|
+
if (params?.workflowName) {
|
|
209
|
+
where.push("workflow_name = ?");
|
|
210
|
+
args.push(params.workflowName);
|
|
211
|
+
}
|
|
212
|
+
if (params?.status) {
|
|
213
|
+
where.push("status = ?");
|
|
214
|
+
args.push(params.status);
|
|
215
|
+
}
|
|
216
|
+
const rows = await c.db.execute(`
|
|
217
|
+
SELECT * FROM runs_index
|
|
218
|
+
${where.length > 0 ? `WHERE ${where.join(" AND ")}` : ""}
|
|
219
|
+
ORDER BY created_at DESC, run_id DESC
|
|
220
|
+
LIMIT ?
|
|
221
|
+
`, ...args, limit + 1);
|
|
222
|
+
const values = rows.slice(0, limit);
|
|
223
|
+
const last = values.at(-1);
|
|
224
|
+
return {
|
|
225
|
+
data: values.map((row) => filterData(rowToRun(row), params?.resolveData)),
|
|
226
|
+
cursor: last ? encodeCursor(last.created_at, last.run_id) : null,
|
|
227
|
+
hasMore: rows.length > limit,
|
|
228
|
+
};
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
//# sourceMappingURL=coordinator.js.map
|
|
@@ -0,0 +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AAC,CAAC;gBAChC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YAChC,CAAC;YACD,IAAI,MAAM,EAAE,MAAM,EAAE,CAAC;gBACpB,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBACzB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC1B,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,OAAO,CAC9B;;MAEE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;;;KAGvD,EACD,GAAG,IAAI,EACP,KAAK,GAAG,CAAC,CACT,CAAC;YACF,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YACpC,MAAM,IAAI,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3B,OAAO;gBACN,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CACxB,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAC9C;gBACD,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI;gBAChE,OAAO,EAAE,IAAI,CAAC,MAAM,GAAG,KAAK;aAC5B,CAAC;QACH,CAAC;KACD;CACD,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type MigrationDatabase } from "rivetkit/unstable/migrations";
|
|
2
|
+
export declare const migrateWorkflowDb: (db: MigrationDatabase) => Promise<void>;
|
|
3
|
+
export declare const migrateCoordinatorDb: (db: MigrationDatabase) => Promise<void>;
|
|
4
|
+
export declare const migrateHookTokenDb: (db: MigrationDatabase) => Promise<void>;
|
|
5
|
+
export declare const workflowDb: import("rivetkit/db").DatabaseProvider<import("rivetkit/db").RawAccess>;
|
|
6
|
+
export declare const coordinatorDb: import("rivetkit/db").DatabaseProvider<import("rivetkit/db").RawAccess>;
|
|
7
|
+
export declare const hookTokenDb: import("rivetkit/db").DatabaseProvider<import("rivetkit/db").RawAccess>;
|
|
8
|
+
//# sourceMappingURL=db.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/actors/db.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,iBAAiB,EACtB,MAAM,8BAA8B,CAAC;AAgRtC,eAAO,MAAM,iBAAiB,0CAG5B,CAAC;AACH,eAAO,MAAM,oBAAoB,0CAG/B,CAAC;AACH,eAAO,MAAM,kBAAkB,0CAG7B,CAAC;AACH,eAAO,MAAM,UAAU,yEAAuC,CAAC;AAC/D,eAAO,MAAM,aAAa,yEAA0C,CAAC;AACrE,eAAO,MAAM,WAAW,yEAAwC,CAAC"}
|