gencow 0.1.299 → 0.2.1
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/bin/gencow.mjs +0 -6
- package/core/package.json +1 -1
- package/docs/packaging.md +14 -4
- package/lib/cli-artifact-guard.mjs +53 -3
- package/lib/cli-dev-runtime.mjs +1 -0
- package/lib/cli-project-runtime.mjs +26 -14
- package/lib/codegen-command.mjs +16 -0
- package/lib/coding-guardrails.mjs +2 -0
- package/lib/dashboard-artifact.mjs +65 -0
- package/lib/dashboard-assets.mjs +20 -0
- package/lib/db-command.mjs +121 -80
- package/lib/db-migration-command-steps.mjs +19 -16
- package/lib/db-push-command.mjs +1 -1
- package/lib/deploy-codegen-preflight.mjs +1 -0
- package/lib/dev-cloud-command.mjs +1 -1
- package/lib/dev-local-command.mjs +19 -56
- package/lib/document-local-converter.mjs +11 -0
- package/lib/local-dashboard-plan.mjs +60 -0
- package/lib/local-database-commands.mjs +127 -0
- package/lib/local-development-migrations.mjs +157 -0
- package/lib/local-drizzle-database.config.mjs +10 -0
- package/lib/local-runtime-features.mjs +12 -0
- package/lib/rag-selection.mjs +7 -0
- package/lib/runtime-local-worker.mjs +116 -0
- package/lib/runtime-mode.mjs +3 -0
- package/lib/standalone-codegen-adapter.mjs +91 -0
- package/lib/ts-codegen-import-extension.mjs +228 -19
- package/package.json +15 -8
- package/runtime/config.mjs +218 -2
- package/runtime/engine/chunk-2HA4CUMS.mjs +90 -0
- package/runtime/engine/chunk-2JLO3KMM.mjs +305 -0
- package/runtime/engine/chunk-2SR2M7SR.mjs +1045 -0
- package/runtime/engine/chunk-3D7MHEUC.mjs +253 -0
- package/runtime/engine/chunk-3R7COBWG.mjs +309 -0
- package/runtime/engine/chunk-3ZKA54UW.mjs +1560 -0
- package/runtime/engine/chunk-45I4YR2J.mjs +9 -0
- package/runtime/engine/chunk-4MLRXO7F.mjs +74 -0
- package/runtime/engine/chunk-5575APCJ.mjs +215 -0
- package/runtime/engine/chunk-5GUJZQF3.mjs +114 -0
- package/runtime/engine/chunk-5MXY3T75.mjs +428 -0
- package/runtime/engine/chunk-5TACQ2US.mjs +44 -0
- package/runtime/engine/chunk-66G4YEDT.mjs +3104 -0
- package/runtime/engine/chunk-67YO53WW.mjs +1426 -0
- package/runtime/engine/chunk-6GQRM7XY.mjs +87 -0
- package/runtime/engine/chunk-6JO72SPP.mjs +68 -0
- package/runtime/engine/chunk-6W653LXI.mjs +13 -0
- package/runtime/engine/chunk-7ITSMI3S.mjs +69 -0
- package/runtime/engine/chunk-7KUJ2H2S.mjs +128 -0
- package/runtime/engine/chunk-A5BMQ5IC.mjs +45 -0
- package/runtime/engine/chunk-ADF3UR6L.mjs +428 -0
- package/runtime/engine/chunk-AEBW7XZJ.mjs +4510 -0
- package/runtime/engine/chunk-AGPQ5XIV.mjs +156 -0
- package/runtime/engine/chunk-CPU4OZSX.mjs +753 -0
- package/runtime/engine/chunk-CSWPPWBL.mjs +50 -0
- package/runtime/engine/chunk-DPWXSMWO.mjs +53 -0
- package/runtime/engine/chunk-EAIELFKU.mjs +151 -0
- package/runtime/engine/chunk-EDU5CBKT.mjs +10 -0
- package/runtime/engine/chunk-EQCTAET7.mjs +173 -0
- package/runtime/engine/chunk-EQCXDF2Z.mjs +70 -0
- package/runtime/engine/chunk-F3G4UGV4.mjs +330 -0
- package/runtime/engine/chunk-F62NUNOO.mjs +26 -0
- package/runtime/engine/chunk-FKPNIFRP.mjs +2492 -0
- package/runtime/engine/chunk-FM23RGVI.mjs +81 -0
- package/runtime/engine/chunk-FW5AK4YP.mjs +1041 -0
- package/runtime/engine/chunk-GDWYAGWV.mjs +23 -0
- package/runtime/engine/chunk-GO5PZUYW.mjs +53 -0
- package/runtime/engine/chunk-GOLP7OSG.mjs +340 -0
- package/runtime/engine/chunk-GSLM44EF.mjs +242 -0
- package/runtime/engine/chunk-GYAJ7OX2.mjs +125 -0
- package/runtime/engine/chunk-I3GWR43K.mjs +14 -0
- package/runtime/engine/chunk-IFMOTJNU.mjs +106 -0
- package/runtime/engine/chunk-IKQKBE2G.mjs +128 -0
- package/runtime/engine/chunk-ITH2NEKM.mjs +282 -0
- package/runtime/engine/chunk-J6SDRCG4.mjs +96 -0
- package/runtime/engine/chunk-JODRNM3S.mjs +29596 -0
- package/runtime/engine/chunk-JUDKX53X.mjs +137 -0
- package/runtime/engine/chunk-K2YZVPJ4.mjs +827 -0
- package/runtime/engine/chunk-KEZJUXEE.mjs +151 -0
- package/runtime/engine/chunk-KVLTJFCH.mjs +234 -0
- package/runtime/engine/chunk-KX2PRQPS.mjs +126 -0
- package/runtime/engine/chunk-LEW5ZMLR.mjs +76 -0
- package/runtime/engine/chunk-LINVSJEM.mjs +175 -0
- package/runtime/engine/chunk-M7K2ICSM.mjs +11 -0
- package/runtime/engine/chunk-MZXDXSDC.mjs +292 -0
- package/runtime/engine/chunk-N2TA2IK2.mjs +678 -0
- package/runtime/engine/chunk-N4LTCKJP.mjs +695 -0
- package/runtime/engine/chunk-N6GCLOUX.mjs +13 -0
- package/runtime/engine/chunk-NAG2OXS5.mjs +37 -0
- package/runtime/engine/chunk-NNZ2QJUG.mjs +381 -0
- package/runtime/engine/chunk-NZPPLDNW.mjs +15 -0
- package/runtime/engine/chunk-ODWM57W6.mjs +138 -0
- package/runtime/engine/chunk-P5IIXAIE.mjs +23 -0
- package/runtime/engine/chunk-PBOXB2BV.mjs +6 -0
- package/runtime/engine/chunk-PMOJLN2P.mjs +8 -0
- package/runtime/engine/chunk-PZFMKFHO.mjs +180 -0
- package/runtime/engine/chunk-QL2TQX2N.mjs +114 -0
- package/runtime/engine/chunk-RITT2RSJ.mjs +258 -0
- package/runtime/engine/chunk-RODBVJ5M.mjs +135 -0
- package/runtime/engine/chunk-RW65MPVY.mjs +261 -0
- package/runtime/engine/chunk-S67UYPB6.mjs +25 -0
- package/runtime/engine/chunk-SVJCOUI3.mjs +47 -0
- package/runtime/engine/chunk-TCN3ZASV.mjs +957 -0
- package/runtime/engine/chunk-U2NRG6KC.mjs +32 -0
- package/runtime/engine/chunk-UM3F7HUV.mjs +432 -0
- package/runtime/engine/chunk-VWU7JJ3P.mjs +146 -0
- package/runtime/engine/chunk-WDTKPPMU.mjs +310 -0
- package/runtime/engine/chunk-WJOO4XTB.mjs +31 -0
- package/runtime/engine/chunk-XNFVL2OY.mjs +63 -0
- package/runtime/engine/chunk-XPWJXP2J.mjs +58 -0
- package/runtime/engine/chunk-Y3HSBJ3I.mjs +1132 -0
- package/runtime/engine/chunk-YMH4RYSX.mjs +317 -0
- package/runtime/engine/chunk-YNOMPSGS.mjs +8 -0
- package/runtime/engine/chunk-YRBAYTEZ.mjs +251 -0
- package/runtime/engine/chunk-YRHM272W.mjs +528 -0
- package/runtime/engine/chunk-ZQUZAGIQ.mjs +149 -0
- package/runtime/engine/chunk-ZXMM7QFP.mjs +176 -0
- package/runtime/engine/chunk-ZZJSIPV2.mjs +262 -0
- package/runtime/engine/composition.mjs +325 -0
- package/runtime/engine/document-local.mjs +504 -0
- package/runtime/engine/graph.json +4134 -0
- package/runtime/engine/index.mjs +265 -0
- package/runtime/engine/local-postgres-support.mjs +69 -0
- package/runtime/engine/local.mjs +3275 -0
- package/runtime/engine/pglite-directory-lock.mjs +8 -0
- package/runtime/engine/rag.mjs +11 -0
- package/runtime/engine/search.mjs +18 -0
- package/runtime/framework-migrations/foundation-bootstrap/rag.sql +115 -0
- package/runtime/framework-migrations/foundation-bootstrap/workflow.sql +194 -0
- package/runtime/framework-migrations/journal-bootstrap/migration.sql +26 -0
- package/runtime/framework-migrations/manifest.json +56 -0
- package/runtime/framework-migrations/rag/20261006111509_mushy_warhawk/migration.sql +121 -0
- package/runtime/framework-migrations/rag/20261013234621_rag_v2_lifecycle_markers/migration.sql +6 -0
- package/runtime/framework-migrations/workflow/20261006111508_perpetual_star_brand/migration.sql +31 -0
- package/runtime/runtime-metadata.json +27 -0
- package/runtime/tooling.mjs +10399 -8951
- package/scripts/bundle-runtime-config.mjs +23 -0
- package/scripts/bundle-runtime.mjs +100 -0
- package/scripts/bundle-runtime.test.mjs +33 -0
- package/scripts/bundle-shared.mjs +3 -0
- package/scripts/copy-dashboard.mjs +16 -0
- package/scripts/pre-publish-check.mjs +23 -11
- package/templateFeature/ai/ai-facade.ts +38 -15
- package/templateFeature/ai/manifest.json +1 -0
- package/templateFeature/sso/sso-auth-callback.tsx +37 -5
- package/templateFeature/tools/manifest.json +5 -2
- package/templateFeature/tools/tools.ts +3 -3
- package/runtime/server.mjs +0 -14389
- package/scripts/bundle-server.mjs +0 -223
- package/server/config.js +0 -1
- package/server/index.js +0 -1
- package/server/package.json +0 -6
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createRagOperationsScope,
|
|
3
|
+
ragMetricKinds,
|
|
4
|
+
ragOperationsError,
|
|
5
|
+
ragOperationsPredicate,
|
|
6
|
+
validRagMetric
|
|
7
|
+
} from "./chunk-2HA4CUMS.mjs";
|
|
8
|
+
import "./chunk-5TACQ2US.mjs";
|
|
9
|
+
import {
|
|
10
|
+
ragJobRows,
|
|
11
|
+
ragObservedJobProjection
|
|
12
|
+
} from "./chunk-JUDKX53X.mjs";
|
|
13
|
+
import {
|
|
14
|
+
runtimeDiagnostic
|
|
15
|
+
} from "./chunk-AEBW7XZJ.mjs";
|
|
16
|
+
|
|
17
|
+
// ../runtime/dist/adapters/rag/pgvector/operations-store.js
|
|
18
|
+
import { sql as sql2 } from "drizzle-orm";
|
|
19
|
+
|
|
20
|
+
// ../runtime/dist/adapters/rag/pgvector/operations-summary.js
|
|
21
|
+
import { sql } from "drizzle-orm";
|
|
22
|
+
function scopeOf(alias) {
|
|
23
|
+
const prefix = sql.raw(alias);
|
|
24
|
+
return sql`${prefix}.corpus=c.corpus AND ${prefix}.visibility_scope=c.visibility_scope AND ${prefix}.owner_user_id IS NOT DISTINCT FROM c.owner_user_id`;
|
|
25
|
+
}
|
|
26
|
+
async function readRagOperationsSummary(database, user, corpus, active) {
|
|
27
|
+
const jobs = await ragObservedJobProjection(database, user, { corpus }, active);
|
|
28
|
+
const data = ragJobRows(await database.execute(sql`${jobs}, scopes AS (
|
|
29
|
+
SELECT id,corpus,visibility_scope,owner_user_id,updated_at FROM rag_corpora
|
|
30
|
+
WHERE visibility_scope IN ('private','shared','public') AND (owner_user_id=${user} OR (owner_user_id IS NULL AND visibility_scope IN ('shared','public')))
|
|
31
|
+
${corpus ? sql`AND corpus=${corpus}` : sql``} ORDER BY updated_at DESC,id ASC LIMIT 1025
|
|
32
|
+
) SELECT c.corpus,c.visibility_scope AS visibility,c.owner_user_id AS "ownerUserId",
|
|
33
|
+
(SELECT count(*)::double precision FROM rag_sources s WHERE ${scopeOf("s")}) AS "sourceCount",
|
|
34
|
+
(SELECT count(*)::double precision FROM rag_sections sec WHERE ${scopeOf("sec")}) AS "sectionCount",
|
|
35
|
+
(SELECT count(*)::double precision FROM rag_chunks ch WHERE ${scopeOf("ch")}) AS "chunkCount",
|
|
36
|
+
COALESCE((SELECT jsonb_object_agg(status,count) FROM (SELECT j.observed_status AS status,count(*) FROM observed j
|
|
37
|
+
WHERE j.valid AND ${scopeOf("j")} GROUP BY j.observed_status) counts),'{}'::jsonb) AS "jobCounts",
|
|
38
|
+
(SELECT jsonb_build_object('id',j.id,'status',j.observed_status,'stage',CASE WHEN j.terminal THEN j.observed_status
|
|
39
|
+
WHEN j.stage IS NOT NULL AND j.stage NOT IN ('completed','failed','canceled') THEN j.stage ELSE j.observed_status END,'updatedAt',j.updated_at)
|
|
40
|
+
FROM observed j WHERE j.valid AND ${scopeOf("j")} ORDER BY j.updated_at DESC,j.id ASC LIMIT 1) AS "latestJob",
|
|
41
|
+
COALESCE((SELECT jsonb_object_agg(operation,count) FROM (SELECT m.operation,count(*) FROM rag_operation_metrics m
|
|
42
|
+
WHERE ${validRagMetric} AND ${scopeOf("m")} GROUP BY m.operation) counts),'{}'::jsonb) AS "recentMetricCounts",
|
|
43
|
+
(SELECT avg(m.metric_value) FROM rag_operation_metrics m WHERE ${validRagMetric} AND ${scopeOf("m")} AND m.metric_name='latency_ms') AS "averageLatencyMs"
|
|
44
|
+
FROM scopes c ORDER BY c.updated_at DESC,c.id ASC`));
|
|
45
|
+
if (data.length > 1024)
|
|
46
|
+
throw ragOperationsError("RAG_OPERATIONS_SIZE_LIMIT_EXCEEDED");
|
|
47
|
+
return data.map((row) => {
|
|
48
|
+
const activeJobs = ["queued", "converting", "chunking", "embedding", "upserting"].some((status) => (row.jobCounts[status] ?? 0) > 0);
|
|
49
|
+
return {
|
|
50
|
+
...row,
|
|
51
|
+
latestJob: row.latestJob && {
|
|
52
|
+
...row.latestJob,
|
|
53
|
+
updatedAt: new Date(row.latestJob.updatedAt).toISOString()
|
|
54
|
+
},
|
|
55
|
+
indexHealth: (row.jobCounts.failed ?? 0) > 0 ? "failed" : !row.sourceCount || !row.chunkCount ? "empty" : activeJobs ? "degraded" : "ready"
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ../runtime/dist/adapters/rag/pgvector/operations-store.js
|
|
61
|
+
function createRagOperationsStore(database) {
|
|
62
|
+
return Object.freeze({
|
|
63
|
+
scope(requireIdentity) {
|
|
64
|
+
const auth = createRagOperationsScope(requireIdentity);
|
|
65
|
+
async function read(run) {
|
|
66
|
+
try {
|
|
67
|
+
const result = await run(auth.active());
|
|
68
|
+
auth.active();
|
|
69
|
+
return result;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (runtimeDiagnostic(error))
|
|
72
|
+
throw error;
|
|
73
|
+
throw ragOperationsError("RAG_OPERATIONS_OBSERVATION_UNAVAILABLE");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function corpus(value) {
|
|
77
|
+
if (value === void 0 || value === "")
|
|
78
|
+
return void 0;
|
|
79
|
+
if (typeof value !== "string" || value.length > 256)
|
|
80
|
+
throw ragOperationsError("RAG_OPERATIONS_INPUT_INVALID");
|
|
81
|
+
return value.trim() || void 0;
|
|
82
|
+
}
|
|
83
|
+
async function metrics(input) {
|
|
84
|
+
const selected = corpus(input?.corpus);
|
|
85
|
+
if (!input || input.operation !== void 0 && input.operation !== "" && !ragMetricKinds.includes(input.operation) || input.limit !== void 0 && (typeof input.limit !== "number" || !Number.isFinite(input.limit)))
|
|
86
|
+
throw ragOperationsError("RAG_OPERATIONS_INPUT_INVALID");
|
|
87
|
+
const limit = Math.max(1, Math.min(200, Math.floor(input.limit ?? 50)));
|
|
88
|
+
return read(async (user) => ragJobRows(await database.execute(sql2`SELECT m.id,m.app_id AS "appId",m.corpus,m.visibility_scope AS visibility,m.owner_user_id AS "ownerUserId",
|
|
89
|
+
m.operation,m.job_id AS "jobId",m.workflow_id AS "workflowId",m.source_id AS "sourceId",m.metric_name AS "metricName",m.metric_value AS "metricValue",m.unit,
|
|
90
|
+
CASE WHEN jsonb_typeof(m.metadata)='object' THEN m.metadata ELSE '{}'::jsonb END AS metadata,m.recorded_at AS "recordedAt"
|
|
91
|
+
FROM rag_operation_metrics m WHERE ${validRagMetric} AND (m.owner_user_id=${user} OR m.owner_user_id IS NULL)
|
|
92
|
+
${selected ? sql2`AND m.corpus=${selected}` : sql2``} ${input.operation ? sql2`AND m.operation=${input.operation}` : sql2``}
|
|
93
|
+
ORDER BY m.recorded_at DESC,m.id ASC LIMIT ${limit}`)).map((row) => ({
|
|
94
|
+
...row,
|
|
95
|
+
metricValue: Number(row.metricValue),
|
|
96
|
+
recordedAt: new Date(row.recordedAt).toISOString()
|
|
97
|
+
})));
|
|
98
|
+
}
|
|
99
|
+
async function summary(input) {
|
|
100
|
+
if (!input)
|
|
101
|
+
throw ragOperationsError("RAG_OPERATIONS_INPUT_INVALID");
|
|
102
|
+
const selected = corpus(input.corpus);
|
|
103
|
+
return read((user) => readRagOperationsSummary(database, user, selected, auth.active));
|
|
104
|
+
}
|
|
105
|
+
async function reindexPlan(input) {
|
|
106
|
+
const scope = auth.scope(input);
|
|
107
|
+
if (!["source-changed", "section-changed", "corpus-policy-changed", "full-rebuild"].includes(input.mode) || typeof input.reason !== "string" || input.reason.length > 4096 || input.mode === "full-rebuild" && input.confirmFullRebuild !== true || ["source-changed", "section-changed"].includes(input.mode) && !input.sourceIds?.length || input.sourceIds !== void 0 && (!Array.isArray(input.sourceIds) || input.sourceIds.some((id) => typeof id !== "string" || !id || id.length > 128)))
|
|
108
|
+
throw ragOperationsError("RAG_OPERATIONS_INPUT_INVALID");
|
|
109
|
+
if ((input.sourceIds?.length ?? 0) > 8192)
|
|
110
|
+
throw ragOperationsError("RAG_OPERATIONS_SIZE_LIMIT_EXCEEDED");
|
|
111
|
+
const ids = input.sourceIds && [...new Set(input.sourceIds)], mode = input.mode, reason = input.reason;
|
|
112
|
+
return read(async () => {
|
|
113
|
+
const sources = ragJobRows(await database.execute(sql2`SELECT s.id,(SELECT count(*)::double precision FROM rag_chunks ch
|
|
114
|
+
WHERE ch.source_id=s.id AND ${ragOperationsPredicate("ch", scope)}) AS count FROM rag_sources s WHERE ${ragOperationsPredicate("s", scope)}
|
|
115
|
+
${ids?.length ? sql2`AND s.id IN (${sql2.join(ids.map((id) => sql2`${id}`), sql2`,`)})` : sql2``} ORDER BY s.id LIMIT 8193`));
|
|
116
|
+
if (sources.length > 8192)
|
|
117
|
+
throw ragOperationsError("RAG_OPERATIONS_SIZE_LIMIT_EXCEEDED");
|
|
118
|
+
return {
|
|
119
|
+
...scope,
|
|
120
|
+
mode,
|
|
121
|
+
reason,
|
|
122
|
+
sourceIds: sources.map((row) => row.id),
|
|
123
|
+
sourceCount: sources.length,
|
|
124
|
+
estimatedChunkCount: sources.reduce((sum, row) => sum + Number(row.count), 0),
|
|
125
|
+
requiresConfirmation: mode === "full-rebuild"
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return Object.freeze({ metrics, summary, reindexPlan });
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
export {
|
|
134
|
+
createRagOperationsStore
|
|
135
|
+
};
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ragSchemaError
|
|
3
|
+
} from "./chunk-P5IIXAIE.mjs";
|
|
4
|
+
import {
|
|
5
|
+
buildSearchIndexNames
|
|
6
|
+
} from "./chunk-AEBW7XZJ.mjs";
|
|
7
|
+
|
|
8
|
+
// ../runtime/dist/adapters/rag/pgvector/schema-contract.js
|
|
9
|
+
var scope = [
|
|
10
|
+
["id", "text", false],
|
|
11
|
+
["corpus", "text", false],
|
|
12
|
+
["visibility_scope", "text", false],
|
|
13
|
+
["owner_user_id", "text", true],
|
|
14
|
+
["created_at", "timestamptz", false, "now()"],
|
|
15
|
+
["updated_at", "timestamptz", false, "now()"]
|
|
16
|
+
];
|
|
17
|
+
var ragSchemaTables = [
|
|
18
|
+
{
|
|
19
|
+
name: "rag_corpora",
|
|
20
|
+
columns: [
|
|
21
|
+
...scope,
|
|
22
|
+
["title", "text", false],
|
|
23
|
+
["description", "text", true],
|
|
24
|
+
["allow_external_providers", "bool", false, "false"],
|
|
25
|
+
["retention_days", "int4", true],
|
|
26
|
+
["metadata", "jsonb", false, "'{}'::jsonb"]
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "rag_sources",
|
|
31
|
+
columns: [
|
|
32
|
+
...scope,
|
|
33
|
+
["storage_id", "text", false],
|
|
34
|
+
["source_key", "text", false],
|
|
35
|
+
["source_title", "text", false],
|
|
36
|
+
["mime_type", "text", false],
|
|
37
|
+
["byte_size", "int8", false],
|
|
38
|
+
["source_checksum", "text", false],
|
|
39
|
+
["convert_provider", "text", false],
|
|
40
|
+
["convert_status", "text", false],
|
|
41
|
+
["active_ingest_workflow_id", "text", true],
|
|
42
|
+
["markdown", "text", false, "''::text"],
|
|
43
|
+
["text", "text", false, "''::text"],
|
|
44
|
+
["warnings", "jsonb", false, "'[]'::jsonb"],
|
|
45
|
+
["metadata", "jsonb", false, "'{}'::jsonb"]
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "rag_sections",
|
|
50
|
+
columns: [
|
|
51
|
+
...scope,
|
|
52
|
+
["source_id", "text", false],
|
|
53
|
+
["section_index", "int4", false],
|
|
54
|
+
["section_path", "jsonb", false, "'[]'::jsonb"],
|
|
55
|
+
["title", "text", true],
|
|
56
|
+
["depth", "int4", false],
|
|
57
|
+
["page_start", "int4", true],
|
|
58
|
+
["page_end", "int4", true],
|
|
59
|
+
["char_start", "int4", false],
|
|
60
|
+
["char_end", "int4", false]
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "rag_chunks",
|
|
65
|
+
columns: [
|
|
66
|
+
...scope,
|
|
67
|
+
["source_id", "text", false],
|
|
68
|
+
["section_id", "text", true],
|
|
69
|
+
["chunk_index", "int4", false],
|
|
70
|
+
["chunk_text", "text", false],
|
|
71
|
+
["lexical_text", "text", false],
|
|
72
|
+
["embedding", "vector", true],
|
|
73
|
+
["page_start", "int4", true],
|
|
74
|
+
["page_end", "int4", true],
|
|
75
|
+
["chunk_checksum", "text", false],
|
|
76
|
+
["metadata", "jsonb", false, "'{}'::jsonb"]
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: "rag_ingest_jobs",
|
|
81
|
+
columns: [
|
|
82
|
+
...scope,
|
|
83
|
+
["workflow_id", "text", false],
|
|
84
|
+
["source_id", "text", false],
|
|
85
|
+
["status", "text", false],
|
|
86
|
+
["stage", "text", false],
|
|
87
|
+
["provider_trace", "jsonb", false, "'{}'::jsonb"],
|
|
88
|
+
["metrics", "jsonb", false, "'{}'::jsonb"],
|
|
89
|
+
["error", "text", true],
|
|
90
|
+
["retry_revision", "int4", false, "0"],
|
|
91
|
+
["writer_fenced_at", "timestamptz", true],
|
|
92
|
+
["finalization_retry_after", "timestamptz", true],
|
|
93
|
+
["finalized_revision", "int4", true],
|
|
94
|
+
["retired_at", "timestamptz", true],
|
|
95
|
+
["started_at", "timestamptz", false, "now()"],
|
|
96
|
+
["completed_at", "timestamptz", true]
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "rag_operation_metrics",
|
|
101
|
+
columns: [
|
|
102
|
+
["id", "text", false],
|
|
103
|
+
["app_id", "text", false],
|
|
104
|
+
["corpus", "text", false],
|
|
105
|
+
["visibility_scope", "text", false],
|
|
106
|
+
["owner_user_id", "text", true],
|
|
107
|
+
["operation", "text", false],
|
|
108
|
+
["job_id", "text", true],
|
|
109
|
+
["workflow_id", "text", true],
|
|
110
|
+
["source_id", "text", true],
|
|
111
|
+
["metric_name", "text", false],
|
|
112
|
+
["metric_value", "float8", false],
|
|
113
|
+
["unit", "text", true],
|
|
114
|
+
["metadata", "jsonb", false, "'{}'::jsonb"],
|
|
115
|
+
["recorded_at", "timestamptz", false, "now()"]
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
];
|
|
119
|
+
var ownerScope = ["corpus", "visibility_scope", "COALESCE(owner_user_id, ''::text)"];
|
|
120
|
+
var ragSchemaIndexes = [
|
|
121
|
+
{ name: "idx_rag_corpora_scope", table: "rag_corpora", keys: ownerScope, unique: true },
|
|
122
|
+
{
|
|
123
|
+
name: "idx_rag_sources_scope_key",
|
|
124
|
+
table: "rag_sources",
|
|
125
|
+
keys: [...ownerScope, "source_key"],
|
|
126
|
+
unique: true
|
|
127
|
+
},
|
|
128
|
+
{ name: "idx_rag_sources_checksum", table: "rag_sources", keys: ["corpus", "source_checksum"] },
|
|
129
|
+
{ name: "idx_rag_sections_source", table: "rag_sections", keys: ["source_id", "section_index"] },
|
|
130
|
+
{ name: "idx_rag_chunks_scope", table: "rag_chunks", keys: ownerScope },
|
|
131
|
+
{ name: "idx_rag_chunks_source", table: "rag_chunks", keys: ["source_id", "chunk_index"] },
|
|
132
|
+
...["chunk_text", "lexical_text"].flatMap((column) => {
|
|
133
|
+
const names = buildSearchIndexNames("rag_chunks", column);
|
|
134
|
+
const normalized = `lower(normalize(regexp_replace(COALESCE(${column}::text, ''), '[[:space:]]+', ' ', 'g'), NFC))`;
|
|
135
|
+
return [
|
|
136
|
+
{
|
|
137
|
+
name: names.fts,
|
|
138
|
+
table: "rag_chunks",
|
|
139
|
+
keys: [`to_tsvector('simple', ${normalized})`],
|
|
140
|
+
method: "gin"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: names.trigram,
|
|
144
|
+
table: "rag_chunks",
|
|
145
|
+
keys: [`${normalized} gin_trgm_ops`],
|
|
146
|
+
method: "gin"
|
|
147
|
+
}
|
|
148
|
+
];
|
|
149
|
+
}),
|
|
150
|
+
{ name: "idx_rag_ingest_jobs_workflow", table: "rag_ingest_jobs", keys: ["workflow_id"], unique: true },
|
|
151
|
+
{
|
|
152
|
+
name: "idx_rag_ingest_jobs_source",
|
|
153
|
+
table: "rag_ingest_jobs",
|
|
154
|
+
keys: ["source_id", "started_at"],
|
|
155
|
+
descending: true
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: "idx_rag_operation_metrics_scope",
|
|
159
|
+
table: "rag_operation_metrics",
|
|
160
|
+
keys: [...ownerScope, "recorded_at"],
|
|
161
|
+
descending: true
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: "idx_rag_operation_metrics_operation",
|
|
165
|
+
table: "rag_operation_metrics",
|
|
166
|
+
keys: ["operation", "metric_name", "recorded_at"],
|
|
167
|
+
descending: true
|
|
168
|
+
}
|
|
169
|
+
];
|
|
170
|
+
var ragSchemaStatements = [
|
|
171
|
+
...ragSchemaTables.map((table) => `CREATE TABLE IF NOT EXISTS public.${table.name} (${table.columns.map(([name, type, nullable, defaultValue]) => `${name} ${type === "vector" ? "vector(1536)" : type}${name === "id" ? " PRIMARY KEY" : nullable ? "" : " NOT NULL"}${defaultValue === void 0 ? "" : ` DEFAULT ${defaultValue}`}`).join(", ")})`),
|
|
172
|
+
`ALTER TABLE public.rag_sources ADD COLUMN IF NOT EXISTS active_ingest_workflow_id text`,
|
|
173
|
+
`ALTER TABLE public.rag_ingest_jobs ADD COLUMN IF NOT EXISTS retry_revision integer NOT NULL DEFAULT 0`,
|
|
174
|
+
`ALTER TABLE public.rag_ingest_jobs ADD COLUMN IF NOT EXISTS writer_fenced_at timestamptz`,
|
|
175
|
+
`ALTER TABLE public.rag_ingest_jobs ADD COLUMN IF NOT EXISTS finalization_retry_after timestamptz`,
|
|
176
|
+
`ALTER TABLE public.rag_ingest_jobs ADD COLUMN IF NOT EXISTS finalized_revision integer`,
|
|
177
|
+
`ALTER TABLE public.rag_ingest_jobs ADD COLUMN IF NOT EXISTS retired_at timestamptz`,
|
|
178
|
+
...ragSchemaIndexes.map((index) => `CREATE ${index.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${index.name} ON public.${index.table} USING ${index.method ?? "btree"} (${index.keys.map((key, position) => `${key}${index.descending && position === index.keys.length - 1 ? " DESC" : ""}`).join(", ")})`)
|
|
179
|
+
];
|
|
180
|
+
|
|
181
|
+
// ../runtime/dist/adapters/rag/pgvector/schema-catalog.js
|
|
182
|
+
import { sql } from "drizzle-orm";
|
|
183
|
+
function ragRows(result) {
|
|
184
|
+
if (Array.isArray(result))
|
|
185
|
+
return result;
|
|
186
|
+
if (result && typeof result === "object" && "rows" in result && Array.isArray(result.rows))
|
|
187
|
+
return result.rows;
|
|
188
|
+
throw ragSchemaError();
|
|
189
|
+
}
|
|
190
|
+
async function readRagSchemaCatalog(database, operationalRoles = []) {
|
|
191
|
+
const names = sql.join(ragSchemaTables.map((table) => sql`${table.name}`), sql`, `);
|
|
192
|
+
const actors = operationalRoles.length ? sql.join(operationalRoles.map((role) => sql`${role}`), sql`, `) : sql`NULL`;
|
|
193
|
+
const columns = ragRows(await database.execute(sql`
|
|
194
|
+
SELECT relation.relname AS table_name, attribute.attname AS name,
|
|
195
|
+
type.typname AS type, type_namespace.nspname AS type_namespace, attribute.atttypmod AS modifier,
|
|
196
|
+
NOT attribute.attnotnull AS nullable, pg_get_expr(defaults.adbin, defaults.adrelid) AS default_value,
|
|
197
|
+
attribute.attidentity AS identity, attribute.attgenerated AS generated, relation.relkind AS kind,
|
|
198
|
+
relation.relowner = current_user::regrole AS owner_current,
|
|
199
|
+
pg_has_role(current_user, relation.relowner, 'USAGE') AS owner_privilege,
|
|
200
|
+
EXISTS (SELECT 1 FROM pg_roles actor WHERE actor.rolname IN (${actors})
|
|
201
|
+
AND (actor.oid = relation.relowner OR pg_has_role(actor.oid, relation.relowner, 'MEMBER'))) AS owner_operational
|
|
202
|
+
FROM pg_class relation JOIN pg_namespace namespace ON namespace.oid = relation.relnamespace
|
|
203
|
+
JOIN pg_attribute attribute ON attribute.attrelid = relation.oid AND attribute.attnum > 0 AND NOT attribute.attisdropped
|
|
204
|
+
JOIN pg_type type ON type.oid = attribute.atttypid
|
|
205
|
+
JOIN pg_namespace type_namespace ON type_namespace.oid = type.typnamespace
|
|
206
|
+
LEFT JOIN pg_attrdef defaults ON defaults.adrelid = relation.oid AND defaults.adnum = attribute.attnum
|
|
207
|
+
WHERE namespace.nspname = 'public' AND relation.relname IN (${names})
|
|
208
|
+
`));
|
|
209
|
+
const constraints = ragRows(await database.execute(sql`
|
|
210
|
+
SELECT relation.relname AS table_name, constraint_row.contype AS kind,
|
|
211
|
+
constraint_row.convalidated AS validated, constraint_row.condeferrable AS deferred,
|
|
212
|
+
ARRAY(SELECT attribute.attname::text FROM unnest(constraint_row.conkey) WITH ORDINALITY key(number, position)
|
|
213
|
+
JOIN pg_attribute attribute ON attribute.attrelid = relation.oid AND attribute.attnum = key.number ORDER BY key.position) AS columns
|
|
214
|
+
FROM pg_constraint constraint_row JOIN pg_class relation ON relation.oid = constraint_row.conrelid
|
|
215
|
+
JOIN pg_namespace namespace ON namespace.oid = relation.relnamespace
|
|
216
|
+
WHERE namespace.nspname = 'public' AND relation.relname IN (${names})
|
|
217
|
+
`));
|
|
218
|
+
const indexes = await readRagSchemaIndexes(database, ragSchemaTables.map((table) => table.name));
|
|
219
|
+
return { columns, constraints, indexes, names };
|
|
220
|
+
}
|
|
221
|
+
async function readRagSchemaIndexes(database, tables) {
|
|
222
|
+
const names = sql.join(tables.map((name) => sql`${name}`), sql`, `);
|
|
223
|
+
return ragRows(await database.execute(sql`
|
|
224
|
+
SELECT index_relation.relname AS name, table_relation.relname AS table_name, method.amname AS method,
|
|
225
|
+
index_row.indisvalid AS valid, index_row.indisready AS ready, index_row.indisunique AS unique,
|
|
226
|
+
index_row.indisprimary AS primary, index_row.indnkeyatts AS key_count, index_row.indnatts AS attribute_count,
|
|
227
|
+
ARRAY(SELECT pg_get_indexdef(index_row.indexrelid, key.position, true)
|
|
228
|
+
FROM generate_series(1, index_row.indnkeyatts) key(position) ORDER BY key.position) AS keys,
|
|
229
|
+
ARRAY(SELECT index_row.indoption[key.position - 1]::int
|
|
230
|
+
FROM generate_series(1, index_row.indnkeyatts) key(position) ORDER BY key.position) AS options,
|
|
231
|
+
ARRAY(SELECT opclass.opcname::text FROM unnest(index_row.indclass) WITH ORDINALITY key(class_oid, position)
|
|
232
|
+
JOIN pg_opclass opclass ON opclass.oid = key.class_oid ORDER BY key.position) AS opclasses,
|
|
233
|
+
ARRAY(SELECT op_namespace.nspname::text FROM unnest(index_row.indclass) WITH ORDINALITY key(class_oid, position)
|
|
234
|
+
JOIN pg_opclass opclass ON opclass.oid = key.class_oid JOIN pg_namespace op_namespace ON op_namespace.oid = opclass.opcnamespace ORDER BY key.position) AS opclass_namespaces,
|
|
235
|
+
pg_get_expr(index_row.indpred, index_row.indrelid, true) AS predicate
|
|
236
|
+
FROM pg_class index_relation JOIN pg_index index_row ON index_row.indexrelid = index_relation.oid
|
|
237
|
+
JOIN pg_class table_relation ON table_relation.oid = index_row.indrelid
|
|
238
|
+
JOIN pg_namespace namespace ON namespace.oid = table_relation.relnamespace
|
|
239
|
+
JOIN pg_am method ON method.oid = index_relation.relam
|
|
240
|
+
WHERE namespace.nspname = 'public' AND table_relation.relname IN (${names})
|
|
241
|
+
`));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// ../runtime/dist/adapters/rag/pgvector/schema-index.js
|
|
245
|
+
function normalizeRagSchemaExpression(value) {
|
|
246
|
+
return value.replace(/'(?:''|[^'])*'|"(?:""|[^"])*"|([^'"]+)/g, (part, unquoted) => unquoted === void 0 ? part : unquoted.toLowerCase().replace(/::(?:text|regconfig)\b/g, "").replace(/\s+/g, " ")).trim();
|
|
247
|
+
}
|
|
248
|
+
function matchesRagSchemaIndex(actual, expected) {
|
|
249
|
+
return actual.table_name === expected.table && actual.method === (expected.method ?? "btree") && actual.valid && actual.ready && actual.unique === Boolean(expected.unique) && !actual.primary && actual.predicate === null && actual.key_count === expected.keys.length && actual.attribute_count === expected.keys.length && actual.keys.length === expected.keys.length && actual.options.length === expected.keys.length && actual.opclasses.length === expected.keys.length && actual.opclass_namespaces.length === expected.keys.length && actual.keys.every((key, position) => normalizeRagSchemaExpression(key) === normalizeRagSchemaExpression(expected.keys[position].replace(/ gin_trgm_ops$/, ""))) && actual.opclasses.every((name, position) => name === (expected.method === "gin" ? expected.keys[position].endsWith(" gin_trgm_ops") ? "gin_trgm_ops" : "tsvector_ops" : expected.keys[position] === "started_at" || expected.keys[position] === "recorded_at" ? "timestamptz_ops" : expected.keys[position] === "section_index" || expected.keys[position] === "chunk_index" ? "int4_ops" : "text_ops")) && actual.opclass_namespaces.every((name, position) => name === (expected.keys[position].endsWith(" gin_trgm_ops") ? "public" : "pg_catalog")) && actual.options.every((option, position) => option === (expected.descending && position === expected.keys.length - 1 ? 3 : 0));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export {
|
|
253
|
+
ragSchemaTables,
|
|
254
|
+
ragSchemaIndexes,
|
|
255
|
+
ragSchemaStatements,
|
|
256
|
+
ragRows,
|
|
257
|
+
readRagSchemaCatalog,
|
|
258
|
+
readRagSchemaIndexes,
|
|
259
|
+
normalizeRagSchemaExpression,
|
|
260
|
+
matchesRagSchemaIndex
|
|
261
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WorkflowTerminalFenceUnavailable,
|
|
3
|
+
enqueuePostgresCompletionFence,
|
|
4
|
+
postgresCompletionFenceExpired,
|
|
5
|
+
postgresCompletionFenceUnavailable,
|
|
6
|
+
validatePostgresCompletionFence
|
|
7
|
+
} from "./chunk-EQCXDF2Z.mjs";
|
|
8
|
+
import "./chunk-YMH4RYSX.mjs";
|
|
9
|
+
import "./chunk-KVLTJFCH.mjs";
|
|
10
|
+
import "./chunk-7KUJ2H2S.mjs";
|
|
11
|
+
import "./chunk-ZXMM7QFP.mjs";
|
|
12
|
+
import "./chunk-PZFMKFHO.mjs";
|
|
13
|
+
import "./chunk-LINVSJEM.mjs";
|
|
14
|
+
import "./chunk-GOLP7OSG.mjs";
|
|
15
|
+
import "./chunk-3D7MHEUC.mjs";
|
|
16
|
+
import "./chunk-SVJCOUI3.mjs";
|
|
17
|
+
import "./chunk-IFMOTJNU.mjs";
|
|
18
|
+
import "./chunk-AEBW7XZJ.mjs";
|
|
19
|
+
export {
|
|
20
|
+
WorkflowTerminalFenceUnavailable,
|
|
21
|
+
enqueuePostgresCompletionFence,
|
|
22
|
+
postgresCompletionFenceExpired,
|
|
23
|
+
postgresCompletionFenceUnavailable,
|
|
24
|
+
validatePostgresCompletionFence
|
|
25
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RuntimeDiagnosticError
|
|
3
|
+
} from "./chunk-AEBW7XZJ.mjs";
|
|
4
|
+
|
|
5
|
+
// ../runtime/dist/database-setup/errors.js
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
7
|
+
var runtimeDatabaseSetupDeadlineReason = /* @__PURE__ */ Symbol("runtime-database-setup-deadline");
|
|
8
|
+
var actions = {
|
|
9
|
+
RUNTIME_DATABASE_SETUP_COMPONENT_INVALID: "Correct trusted adapter schema declarations and selected dependencies, then restart. No database setup was applied.",
|
|
10
|
+
RUNTIME_DATABASE_SETUP_TARGET_MISMATCH: "Configure the application, maintenance and setup URLs to target the same application database, then restart.",
|
|
11
|
+
RUNTIME_DATABASE_SETUP_AUTHORITY_INVALID: "Configure GENCOW_SETUP_DATABASE_URL with authority for the exact selected setup objects, then restart. Existing ownership is unchanged.",
|
|
12
|
+
RUNTIME_DATABASE_SETUP_LOCK_TIMEOUT: "Wait for concurrent database setup to finish, then restart.",
|
|
13
|
+
RUNTIME_DATABASE_SETUP_SCHEMA_INCOMPATIBLE: "Preserve database data and history. Use a compatible Runtime version or a reviewed forward repair before restarting; do not edit applied migrations or internal journals.",
|
|
14
|
+
RUNTIME_DATABASE_SETUP_MAINTENANCE_REQUIRED: "Preserve database data and framework history. Use the separately approved maintenance workflow, or install a compatible reviewed Runtime artifact bundle before restarting. Do not edit the internal journal or replay migration SQL.",
|
|
15
|
+
RUNTIME_FRAMEWORK_SCHEMA_HISTORY_INVALID: "Preserve database data and framework history. Install the matching reviewed Runtime artifact bundle or use an authorized owner recovery before restarting; do not edit the internal journal or replay applied SQL.",
|
|
16
|
+
RUNTIME_DATABASE_SETUP_DEPENDENCY_UNSATISFIED: "Use a reviewed local Runtime recipe and artifact bundle that include the required selected framework dependency, then restart; dependencies never enable omitted features automatically.",
|
|
17
|
+
RUNTIME_DATABASE_SETUP_ACCESS_UNAVAILABLE: "Configure GENCOW_SETUP_DATABASE_URL with authority for the exact required object grants, then restart. Do not change applied migration history.",
|
|
18
|
+
RUNTIME_DATABASE_SETUP_FAILED: "Restore database connectivity and required setup permissions before restarting; inspect any reported committed or unknown effects first.",
|
|
19
|
+
RUNTIME_DATABASE_SETUP_OUTCOME_UNKNOWN: "Restore database connectivity. The next startup must inspect catalog and access before any setup replay; do not blindly rerun schema SQL."
|
|
20
|
+
};
|
|
21
|
+
function runtimeDatabaseSetupError(code, dataImpact = "none", correlationId = randomUUID()) {
|
|
22
|
+
return new RuntimeDiagnosticError({
|
|
23
|
+
code,
|
|
24
|
+
stage: "startup",
|
|
25
|
+
capability: "database",
|
|
26
|
+
servingStarted: false,
|
|
27
|
+
dataImpact,
|
|
28
|
+
retryable: code === "RUNTIME_DATABASE_SETUP_LOCK_TIMEOUT",
|
|
29
|
+
retryPrecondition: code === "RUNTIME_DATABASE_SETUP_LOCK_TIMEOUT" ? "Concurrent setup has finished and the original database is reachable." : code === "RUNTIME_DATABASE_SETUP_MAINTENANCE_REQUIRED" ? "A compatible reviewed Runtime artifact bundle is selected, or the separately approved maintenance workflow has completed." : "Resolve the classified setup precondition and inspect any uncertain effects before restarting.",
|
|
30
|
+
nextAction: actions[code],
|
|
31
|
+
correlationId
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function runtimeDatabaseSetupInterrupted(signal, dataImpact = "none", correlationId = randomUUID()) {
|
|
35
|
+
const deadline = signal.reason === runtimeDatabaseSetupDeadlineReason;
|
|
36
|
+
return new RuntimeDiagnosticError({
|
|
37
|
+
...runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_FAILED", dataImpact, correlationId).diagnostic,
|
|
38
|
+
retryPrecondition: "Owned startup cleanup has finished, cancellation has cleared and the original database is reachable without conflicting setup.",
|
|
39
|
+
nextAction: deadline ? "Framework setup deadline expired. Inspect database availability and wait for concurrent setup to finish. After owned cleanup, restart only when the database is responsive; preserve data and inspect any reported committed or unknown effects first." : "Framework setup was cancelled. Wait for owned cleanup to finish and cancellation to clear before restarting; preserve data and inspect any reported committed or unknown effects first."
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
runtimeDatabaseSetupDeadlineReason,
|
|
45
|
+
runtimeDatabaseSetupError,
|
|
46
|
+
runtimeDatabaseSetupInterrupted
|
|
47
|
+
};
|