lastlight-core 0.26.0 → 0.28.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/config/default.yaml +302 -5
- package/dist/admin/docker.js.map +1 -1
- package/dist/admin/sessions.js.map +1 -1
- package/dist/admin/tail.js.map +1 -1
- package/dist/config/config.d.ts +18 -4
- package/dist/config/config.js +122 -9
- package/dist/config/config.js.map +1 -1
- package/dist/config/repo-config.js.map +1 -1
- package/dist/connectors/messaging/session-manager.js.map +1 -1
- package/dist/connectors/slack/connector.js.map +1 -1
- package/dist/cron/dependabot-discovery.js.map +1 -1
- package/dist/cron/review-discovery.js.map +1 -1
- package/dist/engine/agent-executor.d.ts +25 -1
- package/dist/engine/agent-executor.js +41 -1
- package/dist/engine/agent-executor.js.map +1 -1
- package/dist/engine/chat/chat-prompt.js.map +1 -1
- package/dist/engine/chat/chat-runner.js.map +1 -1
- package/dist/engine/dispatcher.js +17 -0
- package/dist/engine/dispatcher.js.map +1 -1
- package/dist/engine/event-shim.d.ts +18 -0
- package/dist/engine/event-shim.js +2 -0
- package/dist/engine/event-shim.js.map +1 -1
- package/dist/engine/executors/orchestrator.d.ts +92 -1
- package/dist/engine/executors/orchestrator.js +144 -46
- package/dist/engine/executors/orchestrator.js.map +1 -1
- package/dist/engine/executors/shared.js.map +1 -1
- package/dist/engine/fix-harvest.js.map +1 -1
- package/dist/engine/github/github.d.ts +59 -0
- package/dist/engine/github/github.js +72 -0
- package/dist/engine/github/github.js.map +1 -1
- package/dist/engine/github/installations.js.map +1 -1
- package/dist/engine/github/review-poster.d.ts +403 -9
- package/dist/engine/github/review-poster.js +619 -52
- package/dist/engine/github/review-poster.js.map +1 -1
- package/dist/engine/github/team-visibility.js.map +1 -1
- package/dist/engine/llm.js.map +1 -1
- package/dist/engine/pr-decisions.d.ts +85 -5
- package/dist/engine/pr-decisions.js +331 -5
- package/dist/engine/pr-decisions.js.map +1 -1
- package/dist/engine/pr-state.d.ts +82 -0
- package/dist/engine/pr-state.js +71 -1
- package/dist/engine/pr-state.js.map +1 -1
- package/dist/engine/review-spec.d.ts +264 -0
- package/dist/engine/review-spec.js +723 -0
- package/dist/engine/review-spec.js.map +1 -0
- package/dist/engine/router.js.map +1 -1
- package/dist/engine/screen/classifier.js.map +1 -1
- package/dist/engine/screen/screen.js.map +1 -1
- package/dist/evals-api.d.ts +3 -0
- package/dist/evals-api.js +20 -0
- package/dist/evals-api.js.map +1 -1
- package/dist/index.js +76 -11
- package/dist/index.js.map +1 -1
- package/dist/notify/digest-blocks.js.map +1 -1
- package/dist/notify/model.js.map +1 -1
- package/dist/notify/transports/github.js.map +1 -1
- package/dist/notify/transports/slack.js.map +1 -1
- package/dist/sandbox/artifact-backend.js.map +1 -1
- package/dist/sandbox/artifact-store.js.map +1 -1
- package/dist/sandbox/docker.d.ts +23 -4
- package/dist/sandbox/docker.js +1 -1
- package/dist/sandbox/docker.js.map +1 -1
- package/dist/sandbox/egress-allowlist.js.map +1 -1
- package/dist/sandbox/k8s/agent-context-registry.js.map +1 -1
- package/dist/sandbox/k8s/client.js.map +1 -1
- package/dist/sandbox/k8s/kubernetes-sandbox.js.map +1 -1
- package/dist/sandbox/k8s/resource-name.js.map +1 -1
- package/dist/sandbox/k8s/run-id.js.map +1 -1
- package/dist/sandbox/k8s/run-secrets.js.map +1 -1
- package/dist/sandbox/k8s/skill-bundle.js.map +1 -1
- package/dist/sandbox/k8s/workspace-provisioner.js +10 -2
- package/dist/sandbox/k8s/workspace-provisioner.js.map +1 -1
- package/dist/sandbox/sandbox.d.ts +20 -0
- package/dist/sandbox/sandbox.js +27 -6
- package/dist/sandbox/sandbox.js.map +1 -1
- package/dist/session-log.js.map +1 -1
- package/dist/state/approval-store.js.map +1 -1
- package/dist/state/build-assets.js.map +1 -1
- package/dist/state/cron-run-store.js.map +1 -1
- package/dist/state/data-migrate.d.ts +135 -0
- package/dist/state/data-migrate.js +309 -0
- package/dist/state/data-migrate.js.map +1 -0
- package/dist/state/db.d.ts +24 -3
- package/dist/state/db.js +41 -11
- package/dist/state/db.js.map +1 -1
- package/dist/state/execution-store.js.map +1 -1
- package/dist/state/feedback-store.js.map +1 -1
- package/dist/state/pg-client.d.ts +44 -0
- package/dist/state/pg-client.js +81 -0
- package/dist/state/pg-client.js.map +1 -0
- package/dist/state/schema/pg.d.ts +15 -15
- package/dist/state/schema/sqlite.d.ts +15 -15
- package/dist/state/state-cli.d.ts +8 -0
- package/dist/state/state-cli.js +247 -0
- package/dist/state/state-cli.js.map +1 -0
- package/dist/state/team-store.js.map +1 -1
- package/dist/state/user-store.js.map +1 -1
- package/dist/state/workflow-run-store.js.map +1 -1
- package/dist/telemetry/index.js.map +1 -1
- package/dist/workflows/handlers/fanout.d.ts +157 -0
- package/dist/workflows/handlers/fanout.js +663 -0
- package/dist/workflows/handlers/fanout.js.map +1 -0
- package/dist/workflows/handlers/post-review.d.ts +111 -10
- package/dist/workflows/handlers/post-review.js +531 -39
- package/dist/workflows/handlers/post-review.js.map +1 -1
- package/dist/workflows/runner.js +33 -0
- package/dist/workflows/runner.js.map +1 -1
- package/dist/workflows/simple.js.map +1 -1
- package/docker-compose.yml +50 -0
- package/package.json +22 -12
- package/sandbox.Dockerfile +54 -0
- package/skills/adjudicate-pass/SKILL.md +117 -0
- package/skills/code-review/SKILL.md +114 -15
- package/skills/pr-review/SKILL.md +113 -24
- package/skills/pr-review/references/findings-schema.md +38 -7
- package/skills/survey-pass/SKILL.md +148 -0
- package/workflows/pr-review.yaml +626 -0
- package/workflows/prompts/dependabot-pr-merge.md +22 -2
- package/workflows/prompts/review-adjudicate.md +340 -0
- package/workflows/prompts/review-falsify.md +167 -0
- package/workflows/prompts/review.md +80 -0
- package/workflows/prompts/survey-contract.md +121 -0
- package/workflows/prompts/survey-enforcement.md +137 -0
- package/workflows/prompts/survey-security.md +165 -0
- package/workflows/prompts/survey-spec.md +116 -0
- package/workflows/prompts/survey-state.md +151 -0
- package/workflows/prompts/survey-tests.md +99 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { StateDb } from "./db.js";
|
|
2
|
+
import { type StateTables } from "./client.js";
|
|
3
|
+
import { type PgDriver } from "lastlight-shared/database-url";
|
|
4
|
+
/** The schema export names, in an order no foreign key can object to. */
|
|
5
|
+
type TableKey = keyof StateTables;
|
|
6
|
+
interface TableSpec {
|
|
7
|
+
key: TableKey;
|
|
8
|
+
/** Property names forming a stable total order, so batched reads cannot skip or repeat a row. */
|
|
9
|
+
orderBy: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Columns the TARGET generates and an insert must not supply. Only
|
|
12
|
+
* `messaging_messages.id`, which is `AUTOINCREMENT` on SQLite and
|
|
13
|
+
* `GENERATED ALWAYS AS IDENTITY` on Postgres — the latter rejects an explicit
|
|
14
|
+
* value outright. Nothing references that id, so letting Postgres re-assign
|
|
15
|
+
* it loses nothing; reading in id order keeps the message sequence intact.
|
|
16
|
+
*/
|
|
17
|
+
omit?: string[];
|
|
18
|
+
}
|
|
19
|
+
export declare const TABLE_ORDER: readonly TableSpec[];
|
|
20
|
+
export interface MigrateStateDataOptions {
|
|
21
|
+
/** Source: a SQLite path, `file:` URL or `:memory:` — anything `StateDb.open` takes. */
|
|
22
|
+
from: string;
|
|
23
|
+
/** Target: a `postgres://` URL. */
|
|
24
|
+
to: string;
|
|
25
|
+
/** Postgres driver override; unset auto-detects from the target host. */
|
|
26
|
+
driver?: PgDriver;
|
|
27
|
+
/** Rows per read/insert round trip. */
|
|
28
|
+
batchSize?: number;
|
|
29
|
+
/** Count and report without writing anything. */
|
|
30
|
+
dryRun?: boolean;
|
|
31
|
+
/** Delete existing target rows first. Without it a non-empty target aborts. */
|
|
32
|
+
truncate?: boolean;
|
|
33
|
+
/** Progress sink. The CLI renders these; callers that don't care omit it. */
|
|
34
|
+
onProgress?: (event: MigrateProgress) => void;
|
|
35
|
+
}
|
|
36
|
+
export type MigrateProgress = {
|
|
37
|
+
type: "start";
|
|
38
|
+
tables: number;
|
|
39
|
+
} | {
|
|
40
|
+
type: "table-start";
|
|
41
|
+
table: string;
|
|
42
|
+
rows: number;
|
|
43
|
+
} | {
|
|
44
|
+
type: "batch";
|
|
45
|
+
table: string;
|
|
46
|
+
copied: number;
|
|
47
|
+
rows: number;
|
|
48
|
+
} | {
|
|
49
|
+
type: "table-done";
|
|
50
|
+
table: string;
|
|
51
|
+
copied: number;
|
|
52
|
+
} | {
|
|
53
|
+
type: "done";
|
|
54
|
+
totalRows: number;
|
|
55
|
+
durationMs: number;
|
|
56
|
+
};
|
|
57
|
+
export interface TableResult {
|
|
58
|
+
table: string;
|
|
59
|
+
/** Rows read from the source. */
|
|
60
|
+
source: number;
|
|
61
|
+
/** Rows inserted into the target. */
|
|
62
|
+
copied: number;
|
|
63
|
+
/** Rows counted in the target afterwards — the verification pass. */
|
|
64
|
+
target: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A migration failure that knows whether anything was written yet.
|
|
68
|
+
*
|
|
69
|
+
* The distinction is the whole difference between two operator actions: a
|
|
70
|
+
* refusal *before* the first insert (wrong direction, occupied target) leaves
|
|
71
|
+
* the target exactly as it was and wants the input fixed; a failure *after*
|
|
72
|
+
* leaves a partially-filled database that must be truncated before a retry.
|
|
73
|
+
* Telling someone to truncate a database this run never touched is how they
|
|
74
|
+
* end up deleting the wrong one.
|
|
75
|
+
*/
|
|
76
|
+
export declare class StateMigrationError extends Error {
|
|
77
|
+
/** True if at least one row may have been inserted before the failure. */
|
|
78
|
+
readonly wrote: boolean;
|
|
79
|
+
constructor(message: string,
|
|
80
|
+
/** True if at least one row may have been inserted before the failure. */
|
|
81
|
+
wrote: boolean, options?: {
|
|
82
|
+
cause?: unknown;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
export interface MigrateStateDataResult {
|
|
86
|
+
tables: TableResult[];
|
|
87
|
+
totalRows: number;
|
|
88
|
+
durationMs: number;
|
|
89
|
+
dryRun: boolean;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Copy every row from a SQLite state database into a Postgres one.
|
|
93
|
+
*
|
|
94
|
+
* Not transactional as a whole, and cannot be: 15 tables and potentially
|
|
95
|
+
* hundreds of thousands of rows in one Postgres transaction is a recipe for a
|
|
96
|
+
* bloated WAL and a lock held for minutes. The design point that makes that
|
|
97
|
+
* acceptable is the empty-target precondition — a failed run leaves a
|
|
98
|
+
* partially-filled database that is safe to `--truncate` and retry, and the
|
|
99
|
+
* verification pass names exactly where it stopped.
|
|
100
|
+
*
|
|
101
|
+
* **Take a snapshot of the source first.** Opening it runs the source's own
|
|
102
|
+
* migrations (that is the point — both ends must be at the same schema
|
|
103
|
+
* version), which is a write. The harness should be stopped, or the source
|
|
104
|
+
* should be a copy: never point this at a database a running Last Light is
|
|
105
|
+
* writing to.
|
|
106
|
+
*/
|
|
107
|
+
export declare function migrateStateData(opts: MigrateStateDataOptions): Promise<MigrateStateDataResult>;
|
|
108
|
+
/**
|
|
109
|
+
* The copy itself, over two already-open databases.
|
|
110
|
+
*
|
|
111
|
+
* Separate from {@link migrateStateData} so it can be driven against a PGlite
|
|
112
|
+
* target in the hermetic test suite: PGlite has no URL, so a function that owns
|
|
113
|
+
* its own `open()` calls could only ever be tested against a real server, and
|
|
114
|
+
* the whole value-mapping contract would go unexercised in CI.
|
|
115
|
+
*/
|
|
116
|
+
export declare function copyStateData(source: StateDb, target: StateDb, opts: Omit<MigrateStateDataOptions, "from" | "to" | "driver">): Promise<MigrateStateDataResult>;
|
|
117
|
+
/**
|
|
118
|
+
* A hand-maintained table list silently skips whatever is added after it was
|
|
119
|
+
* written, and a state migration that skips a table destroys data without
|
|
120
|
+
* erroring. So the list is checked against the schema's own exports on every
|
|
121
|
+
* run — `schema/sqlite.ts` is the source of truth, and adding a table there
|
|
122
|
+
* fails this loudly until it is placed in {@link TABLE_ORDER} at an
|
|
123
|
+
* FK-respecting position.
|
|
124
|
+
*/
|
|
125
|
+
export declare function assertCoversEveryTable(): void;
|
|
126
|
+
/**
|
|
127
|
+
* The message a human can act on, from anywhere in the cause chain.
|
|
128
|
+
*
|
|
129
|
+
* Drizzle wraps every driver error in a `DrizzleQueryError` whose message is
|
|
130
|
+
* just the SQL it was running, so the actual reason — "password authentication
|
|
131
|
+
* failed", "no such table" — is one or two levels down. Reporting only the top
|
|
132
|
+
* of the chain turns every failure into "Failed query: select 1".
|
|
133
|
+
*/
|
|
134
|
+
export declare function describeError(error: unknown): string;
|
|
135
|
+
export {};
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite → Postgres state migration.
|
|
3
|
+
*
|
|
4
|
+
* The move that makes "choose your database" true for an EXISTING deployment
|
|
5
|
+
* rather than only a fresh one: it copies every row of a live `lastlight.db`
|
|
6
|
+
* into a Postgres server, table by table, through the two Drizzle schemas.
|
|
7
|
+
*
|
|
8
|
+
* **Why this is a read-and-insert loop and not a dump/restore.** Both schemas
|
|
9
|
+
* carry the same `$type<T>()` on every column, and Drizzle maps values at the
|
|
10
|
+
* driver boundary in both directions — so a `boolean` column arrives from
|
|
11
|
+
* SQLite as a JS `true` and goes into Postgres as a real `true`, and a
|
|
12
|
+
* `text({mode:'json'})` column arrives as a parsed object and goes into `jsonb`
|
|
13
|
+
* as one. The JS value in the middle is dialect-neutral, which is exactly what
|
|
14
|
+
* `pg_dump`-style text transport is not: it would have to know that `success`
|
|
15
|
+
* is `0/1` here and `false` there, and that `context` is a string here and a
|
|
16
|
+
* document there.
|
|
17
|
+
*
|
|
18
|
+
* Direction is deliberately one-way. Postgres → SQLite is not supported and is
|
|
19
|
+
* not a symmetric problem (identity columns, jsonb key order, wider integers).
|
|
20
|
+
*
|
|
21
|
+
* ## Invariants
|
|
22
|
+
*
|
|
23
|
+
* - **Both ends are migrated first.** Each side is opened through
|
|
24
|
+
* `StateDb.open()`, so the source gets the legacy-compat pre-step + its
|
|
25
|
+
* journalled migrations and the target gets `drizzle/pg`. Copying between two
|
|
26
|
+
* different schema versions is the failure this prevents.
|
|
27
|
+
* - **FK order is load-bearing** for exactly one pair —
|
|
28
|
+
* `messaging_sessions` → `messaging_messages`, the only declared foreign key
|
|
29
|
+
* in the 15-table schema. {@link TABLE_ORDER} encodes it.
|
|
30
|
+
* - **The target must be empty**, unless `truncate` is passed. Copying into a
|
|
31
|
+
* populated database would half-succeed on primary-key collisions and leave
|
|
32
|
+
* an interleaved mess that is worse than either input.
|
|
33
|
+
* - **Every table is covered or the migration refuses to start.** The coverage
|
|
34
|
+
* check against the schema's own exports is what stops a 16th table added
|
|
35
|
+
* later from being silently left behind — the failure mode of a hand-kept
|
|
36
|
+
* list, and one nobody would notice until the data was already gone.
|
|
37
|
+
*/
|
|
38
|
+
import { is, Table, asc, sql } from "drizzle-orm";
|
|
39
|
+
import { StateDb } from "./db.js";
|
|
40
|
+
import { tablesOf } from "./client.js";
|
|
41
|
+
import * as sqliteSchema from "./schema/sqlite.js";
|
|
42
|
+
export const TABLE_ORDER = [
|
|
43
|
+
{ key: "executions", orderBy: ["id"] },
|
|
44
|
+
{ key: "workflowRuns", orderBy: ["id"] },
|
|
45
|
+
{ key: "workflowApprovals", orderBy: ["id"] },
|
|
46
|
+
{ key: "cronOverrides", orderBy: ["name"] },
|
|
47
|
+
{ key: "cronRuns", orderBy: ["id"] },
|
|
48
|
+
{ key: "workflowOverrides", orderBy: ["name"] },
|
|
49
|
+
{ key: "users", orderBy: ["id"] },
|
|
50
|
+
{ key: "feedbackAnchors", orderBy: ["id"] },
|
|
51
|
+
{ key: "feedbackSignals", orderBy: ["id"] },
|
|
52
|
+
{ key: "githubTeams", orderBy: ["org", "slug"] },
|
|
53
|
+
{ key: "githubTeamRepos", orderBy: ["org", "teamSlug", "repo"] },
|
|
54
|
+
{ key: "githubTeamMembers", orderBy: ["org", "teamSlug", "login"] },
|
|
55
|
+
{ key: "githubVisibilitySync", orderBy: ["login"] },
|
|
56
|
+
// ── The one foreign key in the schema: sessions before their messages. ──
|
|
57
|
+
{ key: "messagingSessions", orderBy: ["id"] },
|
|
58
|
+
{ key: "messagingMessages", orderBy: ["id"], omit: ["id"] },
|
|
59
|
+
];
|
|
60
|
+
/**
|
|
61
|
+
* A migration failure that knows whether anything was written yet.
|
|
62
|
+
*
|
|
63
|
+
* The distinction is the whole difference between two operator actions: a
|
|
64
|
+
* refusal *before* the first insert (wrong direction, occupied target) leaves
|
|
65
|
+
* the target exactly as it was and wants the input fixed; a failure *after*
|
|
66
|
+
* leaves a partially-filled database that must be truncated before a retry.
|
|
67
|
+
* Telling someone to truncate a database this run never touched is how they
|
|
68
|
+
* end up deleting the wrong one.
|
|
69
|
+
*/
|
|
70
|
+
export class StateMigrationError extends Error {
|
|
71
|
+
wrote;
|
|
72
|
+
constructor(message,
|
|
73
|
+
/** True if at least one row may have been inserted before the failure. */
|
|
74
|
+
wrote, options) {
|
|
75
|
+
super(message, options);
|
|
76
|
+
this.wrote = wrote;
|
|
77
|
+
this.name = "StateMigrationError";
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Copy every row from a SQLite state database into a Postgres one.
|
|
82
|
+
*
|
|
83
|
+
* Not transactional as a whole, and cannot be: 15 tables and potentially
|
|
84
|
+
* hundreds of thousands of rows in one Postgres transaction is a recipe for a
|
|
85
|
+
* bloated WAL and a lock held for minutes. The design point that makes that
|
|
86
|
+
* acceptable is the empty-target precondition — a failed run leaves a
|
|
87
|
+
* partially-filled database that is safe to `--truncate` and retry, and the
|
|
88
|
+
* verification pass names exactly where it stopped.
|
|
89
|
+
*
|
|
90
|
+
* **Take a snapshot of the source first.** Opening it runs the source's own
|
|
91
|
+
* migrations (that is the point — both ends must be at the same schema
|
|
92
|
+
* version), which is a write. The harness should be stopped, or the source
|
|
93
|
+
* should be a copy: never point this at a database a running Last Light is
|
|
94
|
+
* writing to.
|
|
95
|
+
*/
|
|
96
|
+
export async function migrateStateData(opts) {
|
|
97
|
+
const source = await StateDb.open(opts.from);
|
|
98
|
+
let target;
|
|
99
|
+
try {
|
|
100
|
+
target = await StateDb.open(opts.to, { driver: opts.driver });
|
|
101
|
+
return await copyStateData(source, target, opts);
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
await source.close();
|
|
105
|
+
await target?.close();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The copy itself, over two already-open databases.
|
|
110
|
+
*
|
|
111
|
+
* Separate from {@link migrateStateData} so it can be driven against a PGlite
|
|
112
|
+
* target in the hermetic test suite: PGlite has no URL, so a function that owns
|
|
113
|
+
* its own `open()` calls could only ever be tested against a real server, and
|
|
114
|
+
* the whole value-mapping contract would go unexercised in CI.
|
|
115
|
+
*/
|
|
116
|
+
export async function copyStateData(source, target, opts) {
|
|
117
|
+
const batchSize = opts.batchSize && opts.batchSize > 0 ? Math.floor(opts.batchSize) : 500;
|
|
118
|
+
const started = Date.now();
|
|
119
|
+
const report = opts.onProgress ?? (() => { });
|
|
120
|
+
assertCoversEveryTable();
|
|
121
|
+
if (source.dialect !== "sqlite") {
|
|
122
|
+
throw new StateMigrationError(`Source must be a SQLite database (got dialect "${source.dialect}"). ` +
|
|
123
|
+
"Postgres → SQLite is not supported.", false);
|
|
124
|
+
}
|
|
125
|
+
if (target.dialect !== "postgres") {
|
|
126
|
+
throw new StateMigrationError(`Target must be a Postgres database (got dialect "${target.dialect}").`, false);
|
|
127
|
+
}
|
|
128
|
+
const srcTables = tablesOf(source.client);
|
|
129
|
+
const dstTables = tablesOf(target.client);
|
|
130
|
+
// Preflight EVERY table before writing any of them: discovering table 12 is
|
|
131
|
+
// occupied after 11 have been copied is the worst possible time to find out.
|
|
132
|
+
await preflightTarget(target.client, dstTables, opts);
|
|
133
|
+
report({ type: "start", tables: TABLE_ORDER.length });
|
|
134
|
+
const results = [];
|
|
135
|
+
for (const spec of TABLE_ORDER) {
|
|
136
|
+
try {
|
|
137
|
+
results.push(await copyTable(spec, source.client, target.client, srcTables, dstTables, {
|
|
138
|
+
batchSize,
|
|
139
|
+
dryRun: !!opts.dryRun,
|
|
140
|
+
report,
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
// Past the preflight, so earlier tables are already in the target.
|
|
145
|
+
throw new StateMigrationError(`Copying ${String(spec.key)} failed: ${describeError(err)}`, !opts.dryRun, { cause: err });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const totalRows = results.reduce((n, r) => n + r.copied, 0);
|
|
149
|
+
const durationMs = Date.now() - started;
|
|
150
|
+
report({ type: "done", totalRows, durationMs });
|
|
151
|
+
// The verification pass is not decoration: an insert that silently dropped
|
|
152
|
+
// rows (a partial batch, a swallowed conflict) is invisible otherwise.
|
|
153
|
+
const mismatched = results.filter((r) => !opts.dryRun && r.target !== r.source);
|
|
154
|
+
if (mismatched.length) {
|
|
155
|
+
throw new StateMigrationError("Row-count verification failed after copying — the target does not match the source: " +
|
|
156
|
+
mismatched.map((r) => `${r.table} (${r.source} → ${r.target})`).join(", "), true);
|
|
157
|
+
}
|
|
158
|
+
return { tables: results, totalRows, durationMs, dryRun: !!opts.dryRun };
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* A hand-maintained table list silently skips whatever is added after it was
|
|
162
|
+
* written, and a state migration that skips a table destroys data without
|
|
163
|
+
* erroring. So the list is checked against the schema's own exports on every
|
|
164
|
+
* run — `schema/sqlite.ts` is the source of truth, and adding a table there
|
|
165
|
+
* fails this loudly until it is placed in {@link TABLE_ORDER} at an
|
|
166
|
+
* FK-respecting position.
|
|
167
|
+
*/
|
|
168
|
+
export function assertCoversEveryTable() {
|
|
169
|
+
const declared = new Set(TABLE_ORDER.map((s) => s.key));
|
|
170
|
+
const actual = Object.entries(sqliteSchema)
|
|
171
|
+
.filter(([, value]) => is(value, Table))
|
|
172
|
+
.map(([name]) => name);
|
|
173
|
+
const missing = actual.filter((name) => !declared.has(name));
|
|
174
|
+
const stale = [...declared].filter((name) => !actual.includes(name));
|
|
175
|
+
if (missing.length || stale.length) {
|
|
176
|
+
throw new Error("data-migrate's TABLE_ORDER is out of sync with schema/sqlite.ts" +
|
|
177
|
+
(missing.length ? ` — not copied: ${missing.join(", ")}` : "") +
|
|
178
|
+
(stale.length ? ` — no longer in the schema: ${stale.join(", ")}` : "") +
|
|
179
|
+
". Add each new table in an order its foreign keys allow.");
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The empty-target rule (or the `--truncate` escape hatch).
|
|
184
|
+
*
|
|
185
|
+
* Deletes in REVERSE {@link TABLE_ORDER}, so `messaging_messages` goes before
|
|
186
|
+
* the `messaging_sessions` rows it references.
|
|
187
|
+
*/
|
|
188
|
+
async function preflightTarget(client, dstTables, opts) {
|
|
189
|
+
if (opts.dryRun)
|
|
190
|
+
return;
|
|
191
|
+
if (opts.truncate) {
|
|
192
|
+
for (const spec of [...TABLE_ORDER].reverse()) {
|
|
193
|
+
await client.delete(tableOf(dstTables, spec.key));
|
|
194
|
+
}
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const occupied = [];
|
|
198
|
+
for (const spec of TABLE_ORDER) {
|
|
199
|
+
const table = tableOf(dstTables, spec.key);
|
|
200
|
+
if ((await countRows(client, table)) > 0)
|
|
201
|
+
occupied.push(tableName(table));
|
|
202
|
+
}
|
|
203
|
+
if (occupied.length) {
|
|
204
|
+
throw new StateMigrationError(`Target database is not empty (${occupied.join(", ")}). ` +
|
|
205
|
+
"Migrate into a fresh database, or pass --truncate to delete the existing rows first.", false);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async function copyTable(spec, srcClient, dstClient, srcTables, dstTables, { batchSize, dryRun, report }) {
|
|
209
|
+
const srcTable = tableOf(srcTables, spec.key);
|
|
210
|
+
const dstTable = tableOf(dstTables, spec.key);
|
|
211
|
+
const name = tableName(srcTable);
|
|
212
|
+
const sourceRows = await countRows(srcClient, srcTable);
|
|
213
|
+
report({ type: "table-start", table: name, rows: sourceRows });
|
|
214
|
+
let copied = 0;
|
|
215
|
+
if (!dryRun && sourceRows > 0) {
|
|
216
|
+
const order = spec.orderBy.map((prop) => asc(columnOf(srcTable, prop)));
|
|
217
|
+
for (let offset = 0; offset < sourceRows; offset += batchSize) {
|
|
218
|
+
// Keyset pagination would be faster, but the order columns differ per
|
|
219
|
+
// table (three of them are composite) and these are one-shot migrations
|
|
220
|
+
// over tens of thousands of rows. LIMIT/OFFSET over a stable total order
|
|
221
|
+
// is correct, and correctness is what matters here.
|
|
222
|
+
const batch = (await srcClient
|
|
223
|
+
.select()
|
|
224
|
+
.from(srcTable)
|
|
225
|
+
.orderBy(...order)
|
|
226
|
+
.limit(batchSize)
|
|
227
|
+
.offset(offset));
|
|
228
|
+
if (!batch.length)
|
|
229
|
+
break;
|
|
230
|
+
const values = spec.omit
|
|
231
|
+
? batch.map((row) => omitKeys(row, spec.omit))
|
|
232
|
+
: batch;
|
|
233
|
+
await dstClient.insert(dstTable).values(values);
|
|
234
|
+
copied += batch.length;
|
|
235
|
+
report({ type: "batch", table: name, copied, rows: sourceRows });
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
report({ type: "table-done", table: name, copied });
|
|
239
|
+
return {
|
|
240
|
+
table: name,
|
|
241
|
+
source: sourceRows,
|
|
242
|
+
copied,
|
|
243
|
+
target: dryRun ? 0 : await countRows(dstClient, dstTable),
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* The message a human can act on, from anywhere in the cause chain.
|
|
248
|
+
*
|
|
249
|
+
* Drizzle wraps every driver error in a `DrizzleQueryError` whose message is
|
|
250
|
+
* just the SQL it was running, so the actual reason — "password authentication
|
|
251
|
+
* failed", "no such table" — is one or two levels down. Reporting only the top
|
|
252
|
+
* of the chain turns every failure into "Failed query: select 1".
|
|
253
|
+
*/
|
|
254
|
+
export function describeError(error) {
|
|
255
|
+
const parts = [];
|
|
256
|
+
for (let e = error, depth = 0; e != null && depth < 6; depth++) {
|
|
257
|
+
const message = e.message;
|
|
258
|
+
if (message && !parts.includes(message))
|
|
259
|
+
parts.push(message);
|
|
260
|
+
e = e.cause;
|
|
261
|
+
}
|
|
262
|
+
if (!parts.length)
|
|
263
|
+
return String(error);
|
|
264
|
+
if (parts.length === 1)
|
|
265
|
+
return parts[0];
|
|
266
|
+
// The innermost cause is the reason; the outermost is which query was
|
|
267
|
+
// running, worth keeping but only its first line — Drizzle appends the full
|
|
268
|
+
// statement and a `params:` dump, which buries the reason it wraps.
|
|
269
|
+
return `${parts.at(-1)} (while running: ${parts[0].split("\n")[0]})`;
|
|
270
|
+
}
|
|
271
|
+
function omitKeys(row, keys) {
|
|
272
|
+
const out = {};
|
|
273
|
+
for (const [k, v] of Object.entries(row))
|
|
274
|
+
if (!keys.includes(k))
|
|
275
|
+
out[k] = v;
|
|
276
|
+
return out;
|
|
277
|
+
}
|
|
278
|
+
async function countRows(client, table) {
|
|
279
|
+
const [row] = (await client
|
|
280
|
+
.select({ n: sql `count(*)` })
|
|
281
|
+
.from(table));
|
|
282
|
+
// int8 arrives as a string from a real pg driver without the OID-20 parser;
|
|
283
|
+
// `makePgClient` registers it, but this must not depend on that to be right.
|
|
284
|
+
return Number(row?.n ?? 0);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* The schema objects are resolved per dialect off the client (`tablesOf`), so
|
|
288
|
+
* they are only weakly typed at this level — the two schemas mirror each other
|
|
289
|
+
* export-for-export (`schema-parity.test.ts` is the guard), which is what makes
|
|
290
|
+
* indexing one with the other's key sound.
|
|
291
|
+
*/
|
|
292
|
+
function tableOf(tables, key) {
|
|
293
|
+
const table = tables[key];
|
|
294
|
+
if (!table || !is(table, Table)) {
|
|
295
|
+
throw new Error(`Schema has no table export "${String(key)}" — schemas out of sync.`);
|
|
296
|
+
}
|
|
297
|
+
return table;
|
|
298
|
+
}
|
|
299
|
+
function columnOf(table, prop) {
|
|
300
|
+
const column = table[prop];
|
|
301
|
+
if (!column) {
|
|
302
|
+
throw new Error(`Table ${tableName(table)} has no column property "${prop}".`);
|
|
303
|
+
}
|
|
304
|
+
return column;
|
|
305
|
+
}
|
|
306
|
+
function tableName(table) {
|
|
307
|
+
return table[Table.Symbol.Name];
|
|
308
|
+
}
|
|
309
|
+
//# sourceMappingURL=data-migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-migrate.js","sourceRoot":"","sources":["../../src/state/data-migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAe,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAsC,MAAM,aAAa,CAAC;AAC3E,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AAoBnD,MAAM,CAAC,MAAM,WAAW,GAAyB;IAC/C,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE;IACtC,EAAE,GAAG,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE;IACxC,EAAE,GAAG,EAAE,mBAAmB,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE;IAC7C,EAAE,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE;IAC3C,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE;IACpC,EAAE,GAAG,EAAE,mBAAmB,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE;IAC/C,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE;IACjC,EAAE,GAAG,EAAE,iBAAiB,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE;IAC3C,EAAE,GAAG,EAAE,iBAAiB,EAAE,OAAO,EA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I,KAA2C,CAAC,IAAI,CAAC,CAAC;IAClE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,SAAS,SAAS,CAAC,KAAK,CAAC,4BAA4B,IAAI,IAAI,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,SAAS,CAAC,KAAY;IAC7B,OAAQ,KAA6C,CAClD,KAAiD,CAAC,MAAM,CAAC,IAAI,CACrD,CAAC;AACd,CAAC"}
|
package/dist/state/db.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PgDriver } from "lastlight-shared/database-url";
|
|
1
2
|
import { type Dialect, type StateClient } from "./client.js";
|
|
2
3
|
import { ExecutionStore } from "./execution-store.js";
|
|
3
4
|
import { CronRunStore } from "./cron-run-store.js";
|
|
@@ -20,6 +21,15 @@ export { UserStore, TRIGGER_ACTOR_TYPES, isTriggerActorType } from "./user-store
|
|
|
20
21
|
export { TeamStore } from "./team-store.js";
|
|
21
22
|
export { FeedbackStore } from "./feedback-store.js";
|
|
22
23
|
export { CronRunStore } from "./cron-run-store.js";
|
|
24
|
+
/**
|
|
25
|
+
* Postgres-only knobs for {@link StateDb.open}. Both are ignored on the sqlite
|
|
26
|
+
* path, and both are absent by default: `driver` unset falls back to the
|
|
27
|
+
* host heuristic in `resolvePgDriver`, `poolMax` to `DEFAULT_POOL_MAX`.
|
|
28
|
+
*/
|
|
29
|
+
export interface StateDbOpenOptions {
|
|
30
|
+
driver?: PgDriver;
|
|
31
|
+
poolMax?: number;
|
|
32
|
+
}
|
|
23
33
|
export interface CronOverride {
|
|
24
34
|
name: string;
|
|
25
35
|
enabled: boolean;
|
|
@@ -105,7 +115,17 @@ export declare class StateDb {
|
|
|
105
115
|
* touches `WorkflowRunStore`'s named ops or any `TeamStore` write must use a
|
|
106
116
|
* temp FILE instead.
|
|
107
117
|
*/
|
|
108
|
-
static open(pathOrUrl?: string): Promise<StateDb>;
|
|
118
|
+
static open(pathOrUrl?: string, opts?: StateDbOpenOptions): Promise<StateDb>;
|
|
119
|
+
/**
|
|
120
|
+
* The Postgres half of {@link StateDb.open}.
|
|
121
|
+
*
|
|
122
|
+
* Every driver-bearing module here is loaded through a dynamic `import()`,
|
|
123
|
+
* which is the ONLY thing keeping `pg` and `@neondatabase/serverless` out of
|
|
124
|
+
* a SQLite deployment's runtime graph — a top-level import of any of them
|
|
125
|
+
* (including the migrator) re-couples every install to a driver it may never
|
|
126
|
+
* use.
|
|
127
|
+
*/
|
|
128
|
+
private static openPostgres;
|
|
109
129
|
/**
|
|
110
130
|
* Test / Phase-4 entry: adopt an existing Drizzle instance. Runs no
|
|
111
131
|
* migrations — the caller owns the schema.
|
|
@@ -140,8 +160,9 @@ export declare class StateDb {
|
|
|
140
160
|
getAllWorkflowOverrides(): Promise<Map<string, WorkflowOverride>>;
|
|
141
161
|
setWorkflowEnabled(name: string, enabled: boolean, updatedBy?: string): Promise<void>;
|
|
142
162
|
/**
|
|
143
|
-
* Async by contract: libsql's `close()` is synchronous
|
|
144
|
-
* pool
|
|
163
|
+
* Async by contract: libsql's `close()` is synchronous, but a Postgres pool's
|
|
164
|
+
* is not — `pool.end()` is what drains the connections, and not awaiting it
|
|
165
|
+
* leaves sockets open (a vitest run that never exits, a deploy that hangs).
|
|
145
166
|
*/
|
|
146
167
|
close(): Promise<void>;
|
|
147
168
|
}
|
package/dist/state/db.js
CHANGED
|
@@ -6,6 +6,7 @@ import { fileURLToPath } from "node:url";
|
|
|
6
6
|
import { resolve } from "node:path";
|
|
7
7
|
import * as sqliteSchema from "./schema/sqlite.js";
|
|
8
8
|
import { applyLegacySqliteCompat } from "./legacy-sqlite.js";
|
|
9
|
+
import { isPostgresUrl } from "lastlight-shared/database-url";
|
|
9
10
|
import { makeOpSerializer, tablesOf, } from "./client.js";
|
|
10
11
|
import { ExecutionStore } from "./execution-store.js";
|
|
11
12
|
import { CronRunStore } from "./cron-run-store.js";
|
|
@@ -23,10 +24,12 @@ export { FeedbackStore } from "./feedback-store.js";
|
|
|
23
24
|
export { CronRunStore } from "./cron-run-store.js";
|
|
24
25
|
const DEFAULT_DB_PATH = "lastlight.db";
|
|
25
26
|
/**
|
|
26
|
-
* The generated migrations live at the `apps/server/` package root, so
|
|
27
|
-
* must resolve from BOTH `src/state/` (tsx dev) and `dist/state/` (compiled)
|
|
27
|
+
* The generated migrations live at the `apps/server/` package root, so these
|
|
28
|
+
* must resolve from BOTH `src/state/` (tsx dev) and `dist/state/` (compiled) —
|
|
29
|
+
* and from the installed npm package, where `drizzle/` ships via `files`.
|
|
28
30
|
*/
|
|
29
31
|
const MIGRATIONS_DIR = fileURLToPath(new URL("../../drizzle/sqlite", import.meta.url));
|
|
32
|
+
const PG_MIGRATIONS_DIR = fileURLToPath(new URL("../../drizzle/pg", import.meta.url));
|
|
30
33
|
/**
|
|
31
34
|
* Lightweight SQLite state for operational tracking.
|
|
32
35
|
* NOT for conversation history — only execution logs and rate limits.
|
|
@@ -108,14 +111,12 @@ export class StateDb {
|
|
|
108
111
|
* touches `WorkflowRunStore`'s named ops or any `TeamStore` write must use a
|
|
109
112
|
* temp FILE instead.
|
|
110
113
|
*/
|
|
111
|
-
static async open(pathOrUrl) {
|
|
114
|
+
static async open(pathOrUrl, opts) {
|
|
112
115
|
const input = pathOrUrl || DEFAULT_DB_PATH;
|
|
113
116
|
// Case-insensitive: URL schemes are, and `POSTGRES://…` reaching the libsql
|
|
114
|
-
// client produces an opaque ConnectionFailed instead of
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
`The Postgres dialect is test-only for now — construct it with StateDb.fromClient().`);
|
|
118
|
-
}
|
|
117
|
+
// client produces an opaque ConnectionFailed instead of the pg branch.
|
|
118
|
+
if (isPostgresUrl(input))
|
|
119
|
+
return StateDb.openPostgres(input, opts);
|
|
119
120
|
const url = input === ":memory:" || input.startsWith("file:") ? input : `file:${resolve(input)}`;
|
|
120
121
|
const raw = createClient({ url });
|
|
121
122
|
await raw.execute("PRAGMA journal_mode = WAL");
|
|
@@ -128,6 +129,34 @@ export class StateDb {
|
|
|
128
129
|
await migrate(client, { migrationsFolder: MIGRATIONS_DIR });
|
|
129
130
|
return new StateDb(client, "sqlite", () => raw.close());
|
|
130
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* The Postgres half of {@link StateDb.open}.
|
|
134
|
+
*
|
|
135
|
+
* Every driver-bearing module here is loaded through a dynamic `import()`,
|
|
136
|
+
* which is the ONLY thing keeping `pg` and `@neondatabase/serverless` out of
|
|
137
|
+
* a SQLite deployment's runtime graph — a top-level import of any of them
|
|
138
|
+
* (including the migrator) re-couples every install to a driver it may never
|
|
139
|
+
* use.
|
|
140
|
+
*/
|
|
141
|
+
static async openPostgres(url, opts) {
|
|
142
|
+
const { makePgClient, resolvePgDriver } = await import("./pg-client.js");
|
|
143
|
+
const driver = resolvePgDriver(url, opts?.driver);
|
|
144
|
+
// Per-driver migrator, both fed the same generated `drizzle/pg` baseline.
|
|
145
|
+
const { migrate } = driver === "neon"
|
|
146
|
+
? await import("drizzle-orm/neon-serverless/migrator")
|
|
147
|
+
: await import("drizzle-orm/node-postgres/migrator");
|
|
148
|
+
const handle = await makePgClient(url, driver, { poolMax: opts?.poolMax });
|
|
149
|
+
try {
|
|
150
|
+
await migrate(handle.client, { migrationsFolder: PG_MIGRATIONS_DIR });
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
// A failed migration leaves a live pool behind, and the process may well
|
|
154
|
+
// be about to retry or exit cleanly — neither should leak connections.
|
|
155
|
+
await handle.close().catch(() => { });
|
|
156
|
+
throw err;
|
|
157
|
+
}
|
|
158
|
+
return new StateDb(handle.client, "postgres", handle.close);
|
|
159
|
+
}
|
|
131
160
|
/**
|
|
132
161
|
* Test / Phase-4 entry: adopt an existing Drizzle instance. Runs no
|
|
133
162
|
* migrations — the caller owns the schema.
|
|
@@ -239,11 +268,12 @@ export class StateDb {
|
|
|
239
268
|
});
|
|
240
269
|
}
|
|
241
270
|
/**
|
|
242
|
-
* Async by contract: libsql's `close()` is synchronous
|
|
243
|
-
* pool
|
|
271
|
+
* Async by contract: libsql's `close()` is synchronous, but a Postgres pool's
|
|
272
|
+
* is not — `pool.end()` is what drains the connections, and not awaiting it
|
|
273
|
+
* leaves sockets open (a vitest run that never exits, a deploy that hangs).
|
|
244
274
|
*/
|
|
245
275
|
async close() {
|
|
246
|
-
this.closer?.();
|
|
276
|
+
await this.closer?.();
|
|
247
277
|
}
|
|
248
278
|
}
|
|
249
279
|
//# sourceMappingURL=db.js.map
|
package/dist/state/db.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/state/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EACL,gBAAgB,EAChB,QAAQ,GAIT,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB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