gencow 0.1.298 → 0.2.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.
Files changed (169) hide show
  1. package/bin/gencow.mjs +0 -6
  2. package/core/index.js +261 -1447
  3. package/core/package.json +1 -1
  4. package/dashboard/assets/{index-BnBn8uo4.js → index-DYqUzCmS.js} +3 -3
  5. package/dashboard/assets/index-OH2xW1ZG.css +2 -0
  6. package/dashboard/index.html +2 -2
  7. package/docs/packaging.md +14 -4
  8. package/lib/cli-artifact-guard.mjs +53 -3
  9. package/lib/cli-command-runner.d.mts +11 -0
  10. package/lib/cli-dev-runtime.mjs +1 -0
  11. package/lib/cli-project-runtime.mjs +26 -14
  12. package/lib/codegen-command.mjs +16 -0
  13. package/lib/coding-guardrails.mjs +2 -0
  14. package/lib/component-readme.mjs +4 -4
  15. package/lib/dashboard-artifact.mjs +65 -0
  16. package/lib/dashboard-assets.mjs +20 -0
  17. package/lib/db-command.mjs +121 -80
  18. package/lib/db-migration-command-steps.mjs +19 -16
  19. package/lib/db-push-command.mjs +1 -1
  20. package/lib/deploy-codegen-preflight.mjs +1 -0
  21. package/lib/deploy-cron-manifest-diagnostic.mjs +93 -0
  22. package/lib/deploy-failure-diagnostic.mjs +4 -43
  23. package/lib/deploy-route-target-rejection-diagnostic.mjs +43 -0
  24. package/lib/dev-cloud-command.mjs +1 -1
  25. package/lib/dev-local-command.mjs +19 -56
  26. package/lib/document-local-converter.mjs +11 -0
  27. package/lib/jobs-command.mjs +33 -1
  28. package/lib/local-dashboard-plan.mjs +60 -0
  29. package/lib/local-database-commands.mjs +127 -0
  30. package/lib/local-development-migrations.mjs +157 -0
  31. package/lib/local-drizzle-database.config.mjs +10 -0
  32. package/lib/local-runtime-features.mjs +12 -0
  33. package/lib/rag-selection.mjs +7 -0
  34. package/lib/readme-codegen.mjs +2 -2
  35. package/lib/runtime-local-worker.mjs +116 -0
  36. package/lib/runtime-mode.mjs +3 -0
  37. package/lib/standalone-codegen-adapter.mjs +91 -0
  38. package/lib/ts-codegen-import-extension.mjs +228 -19
  39. package/package.json +16 -9
  40. package/runtime/config.mjs +218 -2
  41. package/runtime/dependency-lock.mjs +5 -1
  42. package/runtime/engine/chunk-2HA4CUMS.mjs +90 -0
  43. package/runtime/engine/chunk-2JLO3KMM.mjs +305 -0
  44. package/runtime/engine/chunk-2SR2M7SR.mjs +1045 -0
  45. package/runtime/engine/chunk-3D7MHEUC.mjs +253 -0
  46. package/runtime/engine/chunk-3R7COBWG.mjs +309 -0
  47. package/runtime/engine/chunk-3ZKA54UW.mjs +1560 -0
  48. package/runtime/engine/chunk-45I4YR2J.mjs +9 -0
  49. package/runtime/engine/chunk-4MLRXO7F.mjs +74 -0
  50. package/runtime/engine/chunk-5575APCJ.mjs +215 -0
  51. package/runtime/engine/chunk-5GUJZQF3.mjs +114 -0
  52. package/runtime/engine/chunk-5MXY3T75.mjs +428 -0
  53. package/runtime/engine/chunk-5TACQ2US.mjs +44 -0
  54. package/runtime/engine/chunk-66G4YEDT.mjs +3104 -0
  55. package/runtime/engine/chunk-67YO53WW.mjs +1426 -0
  56. package/runtime/engine/chunk-6GQRM7XY.mjs +87 -0
  57. package/runtime/engine/chunk-6JO72SPP.mjs +68 -0
  58. package/runtime/engine/chunk-6W653LXI.mjs +13 -0
  59. package/runtime/engine/chunk-7ITSMI3S.mjs +69 -0
  60. package/runtime/engine/chunk-7KUJ2H2S.mjs +128 -0
  61. package/runtime/engine/chunk-A5BMQ5IC.mjs +45 -0
  62. package/runtime/engine/chunk-ADF3UR6L.mjs +428 -0
  63. package/runtime/engine/chunk-AEBW7XZJ.mjs +4510 -0
  64. package/runtime/engine/chunk-AGPQ5XIV.mjs +156 -0
  65. package/runtime/engine/chunk-CPU4OZSX.mjs +753 -0
  66. package/runtime/engine/chunk-CSWPPWBL.mjs +50 -0
  67. package/runtime/engine/chunk-DPWXSMWO.mjs +53 -0
  68. package/runtime/engine/chunk-EAIELFKU.mjs +151 -0
  69. package/runtime/engine/chunk-EDU5CBKT.mjs +10 -0
  70. package/runtime/engine/chunk-EQCTAET7.mjs +173 -0
  71. package/runtime/engine/chunk-EQCXDF2Z.mjs +70 -0
  72. package/runtime/engine/chunk-F3G4UGV4.mjs +330 -0
  73. package/runtime/engine/chunk-F62NUNOO.mjs +26 -0
  74. package/runtime/engine/chunk-FKPNIFRP.mjs +2492 -0
  75. package/runtime/engine/chunk-FM23RGVI.mjs +81 -0
  76. package/runtime/engine/chunk-FW5AK4YP.mjs +1041 -0
  77. package/runtime/engine/chunk-GDWYAGWV.mjs +23 -0
  78. package/runtime/engine/chunk-GO5PZUYW.mjs +53 -0
  79. package/runtime/engine/chunk-GOLP7OSG.mjs +340 -0
  80. package/runtime/engine/chunk-GSLM44EF.mjs +242 -0
  81. package/runtime/engine/chunk-GYAJ7OX2.mjs +125 -0
  82. package/runtime/engine/chunk-I3GWR43K.mjs +14 -0
  83. package/runtime/engine/chunk-IFMOTJNU.mjs +106 -0
  84. package/runtime/engine/chunk-IKQKBE2G.mjs +128 -0
  85. package/runtime/engine/chunk-ITH2NEKM.mjs +282 -0
  86. package/runtime/engine/chunk-J6SDRCG4.mjs +96 -0
  87. package/runtime/engine/chunk-JODRNM3S.mjs +29596 -0
  88. package/runtime/engine/chunk-JUDKX53X.mjs +137 -0
  89. package/runtime/engine/chunk-K2YZVPJ4.mjs +827 -0
  90. package/runtime/engine/chunk-KEZJUXEE.mjs +151 -0
  91. package/runtime/engine/chunk-KVLTJFCH.mjs +234 -0
  92. package/runtime/engine/chunk-KX2PRQPS.mjs +126 -0
  93. package/runtime/engine/chunk-LEW5ZMLR.mjs +76 -0
  94. package/runtime/engine/chunk-LINVSJEM.mjs +175 -0
  95. package/runtime/engine/chunk-M7K2ICSM.mjs +11 -0
  96. package/runtime/engine/chunk-MZXDXSDC.mjs +292 -0
  97. package/runtime/engine/chunk-N2TA2IK2.mjs +678 -0
  98. package/runtime/engine/chunk-N4LTCKJP.mjs +695 -0
  99. package/runtime/engine/chunk-N6GCLOUX.mjs +13 -0
  100. package/runtime/engine/chunk-NAG2OXS5.mjs +37 -0
  101. package/runtime/engine/chunk-NNZ2QJUG.mjs +381 -0
  102. package/runtime/engine/chunk-NZPPLDNW.mjs +15 -0
  103. package/runtime/engine/chunk-ODWM57W6.mjs +138 -0
  104. package/runtime/engine/chunk-P5IIXAIE.mjs +23 -0
  105. package/runtime/engine/chunk-PBOXB2BV.mjs +6 -0
  106. package/runtime/engine/chunk-PMOJLN2P.mjs +8 -0
  107. package/runtime/engine/chunk-PZFMKFHO.mjs +180 -0
  108. package/runtime/engine/chunk-QL2TQX2N.mjs +114 -0
  109. package/runtime/engine/chunk-RITT2RSJ.mjs +258 -0
  110. package/runtime/engine/chunk-RODBVJ5M.mjs +135 -0
  111. package/runtime/engine/chunk-RW65MPVY.mjs +261 -0
  112. package/runtime/engine/chunk-S67UYPB6.mjs +25 -0
  113. package/runtime/engine/chunk-SVJCOUI3.mjs +47 -0
  114. package/runtime/engine/chunk-TCN3ZASV.mjs +957 -0
  115. package/runtime/engine/chunk-U2NRG6KC.mjs +32 -0
  116. package/runtime/engine/chunk-UM3F7HUV.mjs +432 -0
  117. package/runtime/engine/chunk-VWU7JJ3P.mjs +146 -0
  118. package/runtime/engine/chunk-WDTKPPMU.mjs +310 -0
  119. package/runtime/engine/chunk-WJOO4XTB.mjs +31 -0
  120. package/runtime/engine/chunk-XNFVL2OY.mjs +63 -0
  121. package/runtime/engine/chunk-XPWJXP2J.mjs +58 -0
  122. package/runtime/engine/chunk-Y3HSBJ3I.mjs +1132 -0
  123. package/runtime/engine/chunk-YMH4RYSX.mjs +317 -0
  124. package/runtime/engine/chunk-YNOMPSGS.mjs +8 -0
  125. package/runtime/engine/chunk-YRBAYTEZ.mjs +251 -0
  126. package/runtime/engine/chunk-YRHM272W.mjs +528 -0
  127. package/runtime/engine/chunk-ZQUZAGIQ.mjs +149 -0
  128. package/runtime/engine/chunk-ZXMM7QFP.mjs +176 -0
  129. package/runtime/engine/chunk-ZZJSIPV2.mjs +262 -0
  130. package/runtime/engine/composition.mjs +325 -0
  131. package/runtime/engine/document-local.mjs +504 -0
  132. package/runtime/engine/graph.json +4134 -0
  133. package/runtime/engine/index.mjs +265 -0
  134. package/runtime/engine/local-postgres-support.mjs +69 -0
  135. package/runtime/engine/local.mjs +3275 -0
  136. package/runtime/engine/pglite-directory-lock.mjs +8 -0
  137. package/runtime/engine/rag.mjs +11 -0
  138. package/runtime/engine/search.mjs +18 -0
  139. package/runtime/framework-migrations/foundation-bootstrap/rag.sql +115 -0
  140. package/runtime/framework-migrations/foundation-bootstrap/workflow.sql +194 -0
  141. package/runtime/framework-migrations/journal-bootstrap/migration.sql +26 -0
  142. package/runtime/framework-migrations/manifest.json +56 -0
  143. package/runtime/framework-migrations/rag/20261006111509_mushy_warhawk/migration.sql +121 -0
  144. package/runtime/framework-migrations/rag/20261013234621_rag_v2_lifecycle_markers/migration.sql +6 -0
  145. package/runtime/framework-migrations/workflow/20261006111508_perpetual_star_brand/migration.sql +31 -0
  146. package/runtime/runtime-metadata.json +27 -0
  147. package/runtime/tooling.mjs +10549 -10543
  148. package/scripts/bundle-runtime-config.mjs +23 -0
  149. package/scripts/bundle-runtime.mjs +100 -0
  150. package/scripts/bundle-runtime.test.mjs +33 -0
  151. package/scripts/bundle-shared.mjs +3 -0
  152. package/scripts/copy-dashboard.mjs +16 -0
  153. package/scripts/pre-publish-check.mjs +23 -11
  154. package/templateFeature/ai/ai-embedding-result.ts +82 -0
  155. package/templateFeature/ai/ai-facade.ts +24 -7
  156. package/templateFeature/ai/ai-provider.ts +17 -1
  157. package/templateFeature/ai/ai.ts +1 -0
  158. package/templateFeature/ai/manifest.json +4 -3
  159. package/templateFeature/reranker/manifest.json +1 -1
  160. package/templateFeature/reranker/reranker.ts +4 -3
  161. package/templateFeature/sso/sso-auth-callback.tsx +37 -5
  162. package/templateFeature/tools/manifest.json +2 -1
  163. package/templateFeature/tools/tools.ts +3 -3
  164. package/dashboard/assets/index-C6-BpKKR.css +0 -2
  165. package/runtime/server.mjs +0 -14320
  166. package/scripts/bundle-server.mjs +0 -223
  167. package/server/config.js +0 -1
  168. package/server/index.js +0 -1
  169. package/server/package.json +0 -6
@@ -0,0 +1,13 @@
1
+ // ../runtime/dist/adapters/rag/pgvector/schema-identities.js
2
+ var ragManagedTableNames = Object.freeze([
3
+ "rag_corpora",
4
+ "rag_sources",
5
+ "rag_sections",
6
+ "rag_chunks",
7
+ "rag_ingest_jobs",
8
+ "rag_operation_metrics"
9
+ ]);
10
+
11
+ export {
12
+ ragManagedTableNames
13
+ };
@@ -0,0 +1,37 @@
1
+ import {
2
+ RuntimeDiagnosticError
3
+ } from "./chunk-AEBW7XZJ.mjs";
4
+
5
+ // ../runtime/dist/scheduler/diagnostics.js
6
+ import { randomUUID } from "node:crypto";
7
+ function schedulerFailure(code, nextAction, stage = "request", correlationId = randomUUID()) {
8
+ return new RuntimeDiagnosticError({
9
+ code,
10
+ stage,
11
+ capability: "scheduler",
12
+ correlationId,
13
+ servingStarted: stage === "declaration" || stage === "startup" ? false : "unchanged",
14
+ dataImpact: "none",
15
+ retryable: false,
16
+ retryPrecondition: "Correct the diagnosed condition before a deliberate new scheduling operation.",
17
+ nextAction
18
+ });
19
+ }
20
+ function invalidCronDeclaration(nextAction = "Correct cron names, patterns and registered internal targets, then restart or redeploy the generation. Earlier import effects may remain.") {
21
+ return new RuntimeDiagnosticError({
22
+ code: "RUNTIME_CRON_DECLARATION_INVALID",
23
+ stage: "declaration",
24
+ capability: "scheduler",
25
+ correlationId: randomUUID(),
26
+ servingStarted: false,
27
+ dataImpact: "unknown",
28
+ retryable: false,
29
+ retryPrecondition: "Correct the cron declarations and inspect earlier application initialization effects before restarting.",
30
+ nextAction
31
+ });
32
+ }
33
+
34
+ export {
35
+ schedulerFailure,
36
+ invalidCronDeclaration
37
+ };
@@ -0,0 +1,381 @@
1
+ import {
2
+ azureDescendingListUnsupported,
3
+ decodeStorageCursor,
4
+ encodeStorageCursor,
5
+ invalidStorageCursor,
6
+ storageListOptions
7
+ } from "./chunk-7ITSMI3S.mjs";
8
+ import {
9
+ administrationMetadata,
10
+ assertAdministrationStorageId,
11
+ assertAdministrationUpload,
12
+ assertAdministrationVisibility,
13
+ azureMetadataInvalid,
14
+ azureNamespaceResolver,
15
+ azureObjectNotFound,
16
+ azureStorageCall,
17
+ captureAzureNamespaceOption,
18
+ isAzureObjectAbsent,
19
+ isAzureObjectHeadAbsent,
20
+ resolveRuntimeUploadLimits,
21
+ storageAdministrationInputInvalid,
22
+ storageAdministrationMetadataInvalid,
23
+ storageAdministrationReadLimit,
24
+ storageAdministrationWrite
25
+ } from "./chunk-N4LTCKJP.mjs";
26
+ import {
27
+ assertRuntimeFileSize
28
+ } from "./chunk-GDWYAGWV.mjs";
29
+ import "./chunk-IFMOTJNU.mjs";
30
+ import {
31
+ RuntimeDiagnosticError
32
+ } from "./chunk-AEBW7XZJ.mjs";
33
+
34
+ // ../runtime/dist/adapters/storage/azure-filename.js
35
+ var ENCODING = "utf16le-base64url-v1";
36
+ function azureFilenameMetadata(name) {
37
+ return {
38
+ name: `u16:${Buffer.from(name, "utf16le").toString("base64url")}`,
39
+ gencow_name_encoding: ENCODING
40
+ };
41
+ }
42
+ function azureFilename(metadata, fallback) {
43
+ if (metadata?.gencow_name_encoding === void 0)
44
+ return metadata?.name ?? fallback;
45
+ const name = metadata.name;
46
+ if (name === void 0 || metadata.gencow_name_encoding !== ENCODING || !name.startsWith("u16:") || !/^[A-Za-z0-9_-]*$/u.test(name.slice(4)))
47
+ throw azureMetadataInvalid();
48
+ const encoded = name.slice(4);
49
+ const bytes = Buffer.from(encoded, "base64url");
50
+ if (bytes.length % 2 || bytes.toString("base64url") !== encoded)
51
+ throw azureMetadataInvalid();
52
+ return bytes.toString("utf16le");
53
+ }
54
+
55
+ // ../runtime/dist/adapters/storage/azure-listing.js
56
+ function azureFileMetadata(id, value) {
57
+ return {
58
+ id,
59
+ name: azureFilename(value.metadata, id),
60
+ size: value.contentLength ?? 0,
61
+ type: value.contentType ?? "application/octet-stream",
62
+ visibility: value.metadata?.visibility === "public" ? "public" : "private"
63
+ };
64
+ }
65
+ async function listAzureMetadata(container, catalog, input, targets) {
66
+ const { order, limit } = storageListOptions(input);
67
+ if (order !== "asc")
68
+ throw azureDescendingListUnsupported();
69
+ const cursor = input?.cursor ? decodeStorageCursor(input.cursor, catalog, order) : null;
70
+ if (cursor && (typeof cursor.marker !== "string" || !cursor.marker))
71
+ invalidStorageCursor();
72
+ let marker = cursor?.marker;
73
+ const items = [];
74
+ return azureStorageCall(false, async () => {
75
+ do {
76
+ const result = await container.listBlobsFlat({
77
+ includeMetadata: true,
78
+ ...targets?.prefix !== void 0 ? { prefix: targets.prefix } : {}
79
+ }).byPage({ continuationToken: marker, maxPageSize: limit - items.length }).next();
80
+ if (result.done) {
81
+ marker = void 0;
82
+ break;
83
+ }
84
+ const page = result.value;
85
+ const next = page.continuationToken || void 0;
86
+ if (next && next === marker)
87
+ throw new Error("Provider continuation did not advance");
88
+ const blobs = page.segment.blobItems;
89
+ if (blobs.length > limit - items.length)
90
+ throw new Error("Provider exceeded bounded page size");
91
+ items.push(...blobs.map((blob) => azureFileMetadata(targets ? targets.publicId(blob.name) : blob.name, {
92
+ ...blob.properties,
93
+ metadata: blob.metadata
94
+ })));
95
+ marker = next;
96
+ } while (marker && items.length < limit);
97
+ return { items, nextCursor: marker ? encodeStorageCursor({ catalog, order, marker }) : null };
98
+ });
99
+ }
100
+
101
+ // ../runtime/dist/adapters/storage/azure-administration.js
102
+ function changed() {
103
+ return new RuntimeDiagnosticError({
104
+ code: "RUNTIME_STORAGE_OBJECT_CHANGED",
105
+ stage: "request",
106
+ capability: "storage",
107
+ servingStarted: "unchanged",
108
+ dataImpact: "none",
109
+ retryable: false,
110
+ retryPrecondition: "Refresh Files and revalidate the intended current object/selection before a deliberate new action.",
111
+ nextAction: "The selected object changed before this conditional operation; no file was changed by this request. Refresh Files and confirm the current targets before acting again."
112
+ });
113
+ }
114
+ function conditionalConflict(error) {
115
+ if (!error || typeof error !== "object")
116
+ return false;
117
+ const value = error;
118
+ const code = value.code ?? value.details?.errorCode;
119
+ return value.statusCode === 412 && (code === "ConditionNotMet" || code === "TargetConditionNotMet");
120
+ }
121
+ async function conditionalWrite(write, verify) {
122
+ let wrote;
123
+ try {
124
+ wrote = await write();
125
+ } catch (error) {
126
+ if (conditionalConflict(error))
127
+ throw changed();
128
+ return storageAdministrationWrite(() => azureStorageCall(true, async () => {
129
+ throw error;
130
+ }));
131
+ }
132
+ if (wrote === false)
133
+ throw azureObjectNotFound();
134
+ return storageAdministrationWrite(verify);
135
+ }
136
+ function project(id, value) {
137
+ if (!Number.isSafeInteger(value.contentLength) || value.contentLength < 0)
138
+ throw storageAdministrationMetadataInvalid();
139
+ const capturedTime = value.metadata?.gencow_created_at;
140
+ const createdAt = value.createdOn ?? (capturedTime === void 0 ? void 0 : new Date(capturedTime));
141
+ return administrationMetadata(azureFileMetadata(id, value), createdAt, value.metadata?.gencow_source);
142
+ }
143
+ function etag(properties) {
144
+ if (typeof properties.etag !== "string" || !properties.etag)
145
+ throw storageAdministrationMetadataInvalid();
146
+ return properties.etag;
147
+ }
148
+ function createAzureAdministration(input) {
149
+ const readProperties = (id) => input.readProperties(id, { abortSignal: AbortSignal.timeout(1e4) });
150
+ const inspect = async (id) => {
151
+ assertAdministrationStorageId(id);
152
+ const value = await readProperties(id);
153
+ return value && project(id, value);
154
+ };
155
+ return Object.freeze({
156
+ limits: input.limits,
157
+ order: "storage-id-asc",
158
+ inspect,
159
+ async scan(query) {
160
+ if (!Number.isSafeInteger(query.limit) || query.limit < 1 || query.limit > 1e3)
161
+ throw storageAdministrationInputInvalid();
162
+ const cursor = query.cursor ? decodeStorageCursor(query.cursor, input.catalog, "asc") : void 0;
163
+ if (cursor && (typeof cursor.marker !== "string" || !cursor.marker))
164
+ invalidStorageCursor();
165
+ const marker = cursor?.marker;
166
+ return azureStorageCall(false, async () => {
167
+ const result = await input.container.listBlobsFlat({
168
+ includeMetadata: true,
169
+ abortSignal: AbortSignal.timeout(1e4),
170
+ ...input.targets.prefix !== void 0 ? { prefix: input.targets.prefix } : {}
171
+ }).byPage({ continuationToken: marker, maxPageSize: query.limit }).next();
172
+ if (result.done)
173
+ return { items: [], scanned: 0, nextCursor: null };
174
+ const page = result.value;
175
+ const next = page.continuationToken || void 0;
176
+ if (next && next === marker)
177
+ throw storageAdministrationMetadataInvalid();
178
+ const blobs = page.segment.blobItems;
179
+ if (blobs.length > query.limit)
180
+ throw storageAdministrationMetadataInvalid();
181
+ return {
182
+ items: blobs.map((blob) => project(input.targets.publicId(blob.name), { ...blob.properties, metadata: blob.metadata })),
183
+ scanned: blobs.length,
184
+ nextCursor: next ? encodeStorageCursor({ catalog: input.catalog, order: "asc", marker: next }) : null
185
+ };
186
+ });
187
+ },
188
+ async upload(value) {
189
+ const captured = Object.freeze({ name: value.name, type: value.type, visibility: value.visibility });
190
+ assertAdministrationUpload(captured);
191
+ if (!(value.bytes instanceof Uint8Array))
192
+ throw storageAdministrationInputInvalid();
193
+ assertRuntimeFileSize(value.bytes.byteLength, input.limits.maxFileSizeBytes);
194
+ const data = Buffer.from(value.bytes);
195
+ let id;
196
+ return conditionalWrite(async () => {
197
+ id = await input.put(data, captured.name, captured.type, captured.visibility, "dashboard");
198
+ }, async () => {
199
+ const uploaded = await inspect(id);
200
+ if (!uploaded || uploaded.source !== "dashboard" || uploaded.size !== data.length || uploaded.name !== captured.name || uploaded.visibility !== captured.visibility)
201
+ throw storageAdministrationMetadataInvalid();
202
+ return uploaded;
203
+ });
204
+ },
205
+ async content(id) {
206
+ assertAdministrationStorageId(id);
207
+ const properties = await readProperties(id);
208
+ if (!properties)
209
+ return null;
210
+ const metadata = project(id, properties);
211
+ if (metadata.size > input.limits.maxFileSizeBytes)
212
+ throw storageAdministrationReadLimit(input.limits.maxFileSizeBytes);
213
+ const version = etag(properties);
214
+ const bytes = metadata.size === 0 ? Buffer.alloc(0) : await azureStorageCall(false, async () => {
215
+ try {
216
+ return await input.container.getBlockBlobClient(input.targets.key(id)).downloadToBuffer(0, metadata.size, {
217
+ conditions: { ifMatch: version },
218
+ abortSignal: AbortSignal.timeout(1e4)
219
+ });
220
+ } catch (error) {
221
+ if (conditionalConflict(error))
222
+ throw changed();
223
+ throw error;
224
+ }
225
+ });
226
+ if (bytes.length !== metadata.size)
227
+ throw storageAdministrationMetadataInvalid();
228
+ return { metadata, bytes };
229
+ },
230
+ async setVisibility(id, visibility) {
231
+ assertAdministrationStorageId(id);
232
+ assertAdministrationVisibility(visibility);
233
+ const properties = await readProperties(id);
234
+ if (!properties)
235
+ throw azureObjectNotFound();
236
+ project(id, properties);
237
+ const version = etag(properties);
238
+ return conditionalWrite(async () => {
239
+ await input.container.getBlockBlobClient(input.targets.key(id)).setMetadata({ ...properties.metadata, visibility }, { conditions: { ifMatch: version }, abortSignal: AbortSignal.timeout(1e4) });
240
+ }, async () => {
241
+ const updated = await inspect(id);
242
+ if (!updated || updated.visibility !== visibility)
243
+ throw storageAdministrationMetadataInvalid();
244
+ return updated;
245
+ });
246
+ },
247
+ async delete(id) {
248
+ assertAdministrationStorageId(id);
249
+ const properties = await readProperties(id);
250
+ if (!properties)
251
+ throw azureObjectNotFound();
252
+ project(id, properties);
253
+ const version = etag(properties);
254
+ return conditionalWrite(async () => {
255
+ const response = await input.container.getBlockBlobClient(input.targets.key(id)).deleteIfExists({ conditions: { ifMatch: version }, abortSignal: AbortSignal.timeout(1e4) });
256
+ return response.succeeded;
257
+ }, async () => {
258
+ if (await inspect(id))
259
+ throw storageAdministrationMetadataInvalid();
260
+ });
261
+ }
262
+ });
263
+ }
264
+
265
+ // ../runtime/dist/adapters/storage/azure-sdk-clients.js
266
+ import { createHash } from "node:crypto";
267
+ import { ClientSecretCredential } from "@azure/identity";
268
+ import { BlobServiceClient } from "@azure/storage-blob";
269
+ var clients = /* @__PURE__ */ new WeakMap();
270
+ function azureContainerClient(input) {
271
+ const authorityHost = "https://login.microsoftonline.com";
272
+ const endpoint = new URL(input.accountUrl).href;
273
+ const { tenantId, clientId, clientSecret } = input.credential;
274
+ const fingerprint = createHash("sha256").update(JSON.stringify([endpoint, input.container, authorityHost, tenantId, clientId, clientSecret])).digest("hex");
275
+ const existing = clients.get(input.credential);
276
+ if (existing?.fingerprint === fingerprint)
277
+ return existing.container;
278
+ const credential = new ClientSecretCredential(tenantId, clientId, clientSecret, { authorityHost });
279
+ const container = new BlobServiceClient(endpoint, credential).getContainerClient(input.container);
280
+ clients.set(input.credential, { fingerprint, container });
281
+ return container;
282
+ }
283
+
284
+ // ../runtime/dist/adapters/storage/azure-blob.js
285
+ function storageOptions(input) {
286
+ return typeof input === "string" ? { filename: input, visibility: "private" } : { filename: input?.filename, visibility: input?.visibility ?? "private" };
287
+ }
288
+ async function createAzureBlobStorage(input) {
289
+ const targets = azureNamespaceResolver(input.accountUrl, input.container, captureAzureNamespaceOption(input));
290
+ const limits = resolveRuntimeUploadLimits(input);
291
+ const container = azureContainerClient(input);
292
+ await container.createIfNotExists({ abortSignal: AbortSignal.timeout(1e4) });
293
+ const metadata = (id) => container.getBlockBlobClient(targets.key(id));
294
+ const catalog = targets.catalog;
295
+ const readProperties = (id, options) => azureStorageCall(false, async () => {
296
+ try {
297
+ return await metadata(id).getProperties(options);
298
+ } catch (error) {
299
+ if (isAzureObjectHeadAbsent(error))
300
+ return null;
301
+ throw error;
302
+ }
303
+ });
304
+ const toMeta = async (id) => {
305
+ const properties = await readProperties(id);
306
+ return properties && azureFileMetadata(id, properties);
307
+ };
308
+ const put = async (data, name, type, visibility, source) => {
309
+ assertRuntimeFileSize(data.length, limits.maxFileSizeBytes);
310
+ const id = crypto.randomUUID();
311
+ const upload = () => metadata(id).uploadData(data, {
312
+ blobHTTPHeaders: { blobContentType: type },
313
+ metadata: {
314
+ ...azureFilenameMetadata(name),
315
+ visibility,
316
+ ...source ? { gencow_source: source, gencow_created_at: (/* @__PURE__ */ new Date()).toISOString() } : {}
317
+ },
318
+ ...source ? { conditions: { ifNoneMatch: "*" }, abortSignal: AbortSignal.timeout(1e4) } : {}
319
+ });
320
+ if (source)
321
+ await upload();
322
+ else
323
+ await azureStorageCall(true, upload);
324
+ return id;
325
+ };
326
+ const storage = {
327
+ async store(file, inputOptions) {
328
+ assertRuntimeFileSize(file.size, limits.maxFileSizeBytes);
329
+ const value = storageOptions(inputOptions);
330
+ return put(Buffer.from(await file.arrayBuffer()), value.filename ?? (file instanceof File ? file.name : "upload.bin"), file.type || "application/octet-stream", value.visibility);
331
+ },
332
+ async storeBuffer(buffer, filename, type = "application/octet-stream", inputOptions) {
333
+ assertRuntimeFileSize(buffer.length, limits.maxFileSizeBytes);
334
+ return put(buffer, filename, type, inputOptions?.visibility ?? "private");
335
+ },
336
+ async get(id) {
337
+ const meta = await toMeta(id);
338
+ if (!meta)
339
+ return null;
340
+ return azureStorageCall(false, async () => {
341
+ try {
342
+ return { ...meta, buffer: await metadata(id).downloadToBuffer() };
343
+ } catch (error) {
344
+ if (isAzureObjectAbsent(error))
345
+ return null;
346
+ throw error;
347
+ }
348
+ });
349
+ },
350
+ getUrl(id) {
351
+ return metadata(id).url;
352
+ },
353
+ getPublicUrl(id) {
354
+ return metadata(id).url;
355
+ },
356
+ async createReadGrant(id) {
357
+ return { url: metadata(id).url, expiresAt: new Date(Date.now() + 6e4).toISOString() };
358
+ },
359
+ getMeta: toMeta,
360
+ async setVisibility(id, visibility) {
361
+ const properties = await readProperties(id);
362
+ if (!properties)
363
+ throw azureObjectNotFound();
364
+ azureFilename(properties.metadata, id);
365
+ await azureStorageCall(true, () => metadata(id).setMetadata({ ...properties.metadata, visibility }));
366
+ },
367
+ listMeta(listInput) {
368
+ return listAzureMetadata(container, catalog, listInput, targets);
369
+ },
370
+ async delete(id) {
371
+ await azureStorageCall(true, () => metadata(id).deleteIfExists());
372
+ }
373
+ };
374
+ return {
375
+ storage,
376
+ administration: createAzureAdministration({ container, catalog, limits, readProperties, put, targets })
377
+ };
378
+ }
379
+ export {
380
+ createAzureBlobStorage
381
+ };
@@ -0,0 +1,15 @@
1
+ import {
2
+ createRagJobStore
3
+ } from "./chunk-Y3HSBJ3I.mjs";
4
+ import "./chunk-GYAJ7OX2.mjs";
5
+ import "./chunk-GDWYAGWV.mjs";
6
+ import "./chunk-JUDKX53X.mjs";
7
+ import "./chunk-LEW5ZMLR.mjs";
8
+ import "./chunk-4MLRXO7F.mjs";
9
+ import "./chunk-NAG2OXS5.mjs";
10
+ import "./chunk-IKQKBE2G.mjs";
11
+ import "./chunk-6JO72SPP.mjs";
12
+ import "./chunk-AEBW7XZJ.mjs";
13
+ export {
14
+ createRagJobStore
15
+ };
@@ -0,0 +1,138 @@
1
+ import {
2
+ validateRuntimeRagSchema
3
+ } from "./chunk-J6SDRCG4.mjs";
4
+ import {
5
+ ragManagedTableNames
6
+ } from "./chunk-N6GCLOUX.mjs";
7
+ import {
8
+ loadRuntimePostgresSql
9
+ } from "./chunk-PMOJLN2P.mjs";
10
+ import {
11
+ ragRows,
12
+ ragSchemaStatements
13
+ } from "./chunk-RW65MPVY.mjs";
14
+ import {
15
+ ragSchemaError
16
+ } from "./chunk-P5IIXAIE.mjs";
17
+ import {
18
+ runtimePostgresClient,
19
+ runtimePostgresCodecs
20
+ } from "./chunk-F3G4UGV4.mjs";
21
+ import {
22
+ resolveRuntimePostgresDriverConfig
23
+ } from "./chunk-EAIELFKU.mjs";
24
+ import "./chunk-KX2PRQPS.mjs";
25
+ import "./chunk-IFMOTJNU.mjs";
26
+ import {
27
+ runtimeDiagnostic
28
+ } from "./chunk-AEBW7XZJ.mjs";
29
+
30
+ // ../runtime/dist/adapters/database/postgres-rag-setup.js
31
+ import { sql } from "drizzle-orm";
32
+ async function target(client) {
33
+ const rows = await client`SELECT current_database() AS database,
34
+ (SELECT oid FROM pg_database WHERE datname=current_database()) AS database_oid,
35
+ inet_server_addr()::text AS address, inet_server_port() AS port,
36
+ extract(epoch FROM pg_postmaster_start_time())::text AS started`;
37
+ if (!rows[0])
38
+ throw ragSchemaError("RAG_SCHEMA_AUTHORITY_UNAVAILABLE");
39
+ return rows[0];
40
+ }
41
+ async function assertOwner(database, binding, roles) {
42
+ const actors = sql.join(roles.map((role) => sql`${role}`), sql`, `);
43
+ const rows = ragRows(await database.execute(sql`
44
+ SELECT current_user = ${binding.expectedRole} AND current_database() = ${binding.expectedDatabase}
45
+ AND NOT owner.rolsuper AND NOT owner.rolbypassrls AND NOT owner.rolcreaterole
46
+ AND NOT EXISTS (SELECT 1 FROM pg_roles inherited
47
+ WHERE (inherited.rolsuper OR inherited.rolbypassrls)
48
+ AND pg_has_role(owner.oid,inherited.oid,'MEMBER'))
49
+ AND NOT EXISTS (SELECT 1 FROM pg_roles actor WHERE actor.rolname IN (${actors})
50
+ AND (actor.oid=owner.oid OR actor.rolcreaterole OR pg_has_role(actor.oid,owner.oid,'MEMBER')
51
+ OR NOT has_schema_privilege(actor.oid,'public','USAGE')))
52
+ AND has_schema_privilege('public','USAGE') AND has_schema_privilege('public','CREATE') AS permitted
53
+ FROM pg_roles owner WHERE owner.rolname=current_user
54
+ `));
55
+ if (rows[0]?.permitted !== true)
56
+ throw ragSchemaError("RAG_SCHEMA_AUTHORITY_UNAVAILABLE");
57
+ }
58
+ async function assertOperationalGrants(database, roles) {
59
+ const actors = sql.join(roles.map((role) => sql`${role}`), sql`, `);
60
+ const tables = sql.join(ragManagedTableNames.map((name) => sql`${name}`), sql`, `);
61
+ const rows = ragRows(await database.execute(sql`
62
+ SELECT count(*) = ${roles.length * ragManagedTableNames.length}
63
+ AND bool_and(has_table_privilege(actor.oid,relation.oid,'SELECT')
64
+ AND has_table_privilege(actor.oid,relation.oid,'INSERT')
65
+ AND has_table_privilege(actor.oid,relation.oid,'UPDATE')
66
+ AND has_table_privilege(actor.oid,relation.oid,'DELETE')) AS permitted
67
+ FROM pg_class relation JOIN pg_namespace namespace ON namespace.oid=relation.relnamespace
68
+ CROSS JOIN pg_roles actor WHERE namespace.nspname='public'
69
+ AND relation.relname IN (${tables}) AND actor.rolname IN (${actors})
70
+ `));
71
+ if (rows[0]?.permitted !== true)
72
+ throw ragSchemaError("RAG_SCHEMA_INCOMPATIBLE");
73
+ }
74
+ async function assertExtensions(database) {
75
+ const rows = ragRows(await database.execute(sql`
76
+ SELECT extension.extname AS name, namespace.nspname AS namespace FROM pg_extension extension
77
+ JOIN pg_namespace namespace ON namespace.oid=extension.extnamespace
78
+ WHERE extension.extname IN ('vector','pg_trgm')
79
+ `));
80
+ for (const name of ["vector", "pg_trgm"])
81
+ if (!rows.some((row) => row.name === name && row.namespace === "public"))
82
+ throw ragSchemaError(name === "vector" ? "RAG_VECTOR_UNAVAILABLE" : "RAG_TRIGRAM_UNAVAILABLE");
83
+ }
84
+ function createPostgresRagSetup(binding, operational, roles) {
85
+ const config = resolveRuntimePostgresDriverConfig(binding.databaseUrl);
86
+ return async () => {
87
+ const [SQL, { drizzle }, { bunSqlPgCodecs }] = await Promise.all([
88
+ loadRuntimePostgresSql(),
89
+ import("drizzle-orm/bun-sql"),
90
+ import("drizzle-orm/bun-sql/postgres/codecs")
91
+ ]);
92
+ const client = runtimePostgresClient(new SQL(config.url, { ...config.options, max: 1, connectionTimeout: 10 }));
93
+ let writesPossible = false;
94
+ try {
95
+ const [setupTarget, servingTarget] = await Promise.all([target(client), target(operational)]);
96
+ if (setupTarget.database !== binding.expectedDatabase || Object.keys(setupTarget).some((key) => setupTarget[key] !== servingTarget[key]))
97
+ throw ragSchemaError("RAG_SCHEMA_AUTHORITY_UNAVAILABLE");
98
+ await drizzle({ client, codecs: runtimePostgresCodecs(bunSqlPgCodecs) }).transaction(async (transaction) => {
99
+ await transaction.execute(sql`SET LOCAL search_path = pg_catalog, public`);
100
+ await transaction.execute(sql`SET LOCAL statement_timeout = '30s'`);
101
+ await transaction.execute(sql`SET LOCAL lock_timeout = '10s'`);
102
+ await assertOwner(transaction, binding, roles);
103
+ await transaction.execute(sql`SELECT pg_advisory_xact_lock(hashtextextended('gencow:managed-schema:rag:v1',0))`);
104
+ await assertExtensions(transaction);
105
+ const ready = await validateRuntimeRagSchema(transaction, {
106
+ setupOwner: true,
107
+ allowCompatibleMissing: true,
108
+ operationalRoles: roles
109
+ });
110
+ if (!ready) {
111
+ writesPossible = true;
112
+ for (const statement of ragSchemaStatements)
113
+ await transaction.execute(sql.raw(statement));
114
+ await validateRuntimeRagSchema(transaction, { setupOwner: true, operationalRoles: roles });
115
+ }
116
+ if (!roles.length)
117
+ throw ragSchemaError("RAG_SCHEMA_AUTHORITY_UNAVAILABLE");
118
+ const actors = roles.map((role) => `"${role.replaceAll('"', '""')}"`).join(", ");
119
+ writesPossible = true;
120
+ await transaction.execute(sql.raw(`GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE ${ragManagedTableNames.map((name) => `public.${name}`).join(", ")} TO ${actors}`));
121
+ await assertOperationalGrants(transaction, roles);
122
+ });
123
+ } catch (error) {
124
+ if (runtimeDiagnostic(error)?.code.startsWith("RAG_"))
125
+ throw error;
126
+ throw ragSchemaError(writesPossible ? "RAG_SCHEMA_INCOMPATIBLE" : "RAG_SCHEMA_AUTHORITY_UNAVAILABLE", writesPossible ? "unknown" : "none");
127
+ } finally {
128
+ try {
129
+ await client.close({ timeout: 5 });
130
+ } catch {
131
+ throw ragSchemaError("RAG_SCHEMA_INCOMPATIBLE", writesPossible ? "unknown" : "none");
132
+ }
133
+ }
134
+ };
135
+ }
136
+ export {
137
+ createPostgresRagSetup
138
+ };
@@ -0,0 +1,23 @@
1
+ import {
2
+ RuntimeCompositionError
3
+ } from "./chunk-IFMOTJNU.mjs";
4
+
5
+ // ../runtime/dist/adapters/rag/pgvector/schema-errors.js
6
+ function ragSchemaError(code = "RAG_SCHEMA_INCOMPATIBLE", dataImpact = "none") {
7
+ const action = code === "RAG_DATABASE_REQUIRED" ? "Select an app-bound operational database before enabling database RAG. No RAG work was admitted." : code === "RAG_VECTOR_UNAVAILABLE" || code === "RAG_TRIGRAM_UNAVAILABLE" ? `Restore the selected database's ${code === "RAG_VECTOR_UNAVAILABLE" ? "vector(1536)" : "pg_trgm"} capability through its trusted managed-setup owner, then restart. Do not change tenant migrations or serving grants.` : code === "RAG_SCHEMA_AUTHORITY_UNAVAILABLE" ? "RAG schema is incomplete and this binding has operational access only. Restore authorized app-scoped managed setup through the trusted host owner before restarting. Do not grant serving DDL or edit tenant migrations." : "Managed RAG schema is incompatible or closed. Preserve existing data and restore compatible managed setup through its trusted host owner before restarting. Do not edit tenant migrations, internal tables or grants.";
8
+ return new RuntimeCompositionError({
9
+ code,
10
+ stage: "startup",
11
+ capability: "database",
12
+ servingStarted: false,
13
+ dataImpact,
14
+ retryable: false,
15
+ retryPrecondition: "Restart only after the trusted owner inspects prior setup effects and verifies compatible RAG schema, required capabilities and operational access.",
16
+ nextAction: `${action}${dataImpact === "unknown" ? " Setup may already have committed; inspect the same database's managed setup before restarting. Do not delete or blindly recreate it." : ""}`,
17
+ correlationId: crypto.randomUUID()
18
+ });
19
+ }
20
+
21
+ export {
22
+ ragSchemaError
23
+ };
@@ -0,0 +1,6 @@
1
+ import {
2
+ loadBetterAuthSdk
3
+ } from "./chunk-WJOO4XTB.mjs";
4
+ export {
5
+ loadBetterAuthSdk
6
+ };
@@ -0,0 +1,8 @@
1
+ // ../runtime/dist/adapters/database/postgres-client-driver.js
2
+ async function loadRuntimePostgresSql() {
3
+ return (await import("bun")).SQL;
4
+ }
5
+
6
+ export {
7
+ loadRuntimePostgresSql
8
+ };