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,528 @@
1
+ import {
2
+ RuntimeCapabilityUnavailableError,
3
+ RuntimeDiagnosticError,
4
+ markOwnedPostgresLoginRejection,
5
+ withRetry
6
+ } from "./chunk-AEBW7XZJ.mjs";
7
+
8
+ // ../runtime/dist/app/scoped-application-reads.js
9
+ import { AsyncLocalStorage } from "node:async_hooks";
10
+ var runtimeScopedApplicationReads = /* @__PURE__ */ Symbol("runtime.scoped-application-reads");
11
+ function createRuntimeScopedApplicationReads(database, binding, identity, rls, assertCurrent, assertLive, assertTransactionActive = assertCurrent) {
12
+ const active = new AsyncLocalStorage();
13
+ const assertLiveOutsideTransaction = async () => {
14
+ assertCurrent();
15
+ if (!active.getStore())
16
+ await assertLive?.();
17
+ assertCurrent();
18
+ };
19
+ const transactionBoundary = Object.freeze({
20
+ run(operation) {
21
+ assertTransactionActive();
22
+ if (active.getStore())
23
+ return operation();
24
+ if (!assertLive)
25
+ return operation();
26
+ return (async () => {
27
+ await assertLiveOutsideTransaction();
28
+ const result = operation();
29
+ if (result && typeof result.then === "function") {
30
+ let value;
31
+ try {
32
+ value = await result;
33
+ } catch (error) {
34
+ await assertLiveOutsideTransaction().catch(() => {
35
+ });
36
+ throw error;
37
+ }
38
+ await assertLiveOutsideTransaction();
39
+ return value;
40
+ }
41
+ await assertLiveOutsideTransaction();
42
+ return result;
43
+ })();
44
+ },
45
+ withTransaction(transaction, operation) {
46
+ assertTransactionActive();
47
+ const execute = Reflect.get(transaction, "execute");
48
+ if (typeof execute !== "function")
49
+ throw new Error("Scoped transaction execute unavailable");
50
+ return active.run({ execute: (statement) => Reflect.apply(execute, transaction, [statement]) }, operation);
51
+ }
52
+ });
53
+ return Object.freeze({
54
+ binding,
55
+ identity,
56
+ rls,
57
+ async execute(statement) {
58
+ assertCurrent();
59
+ try {
60
+ const tx = active.getStore();
61
+ const result = tx ? await tx.execute(statement) : await database.execute(statement);
62
+ assertCurrent();
63
+ return result;
64
+ } catch (error) {
65
+ assertCurrent();
66
+ throw error;
67
+ }
68
+ },
69
+ assertLive: assertLiveOutsideTransaction,
70
+ transactionBoundary
71
+ });
72
+ }
73
+ function sameRuntimeScopedRls(left, right) {
74
+ const leftKeys = Object.keys(left).sort();
75
+ const rightKeys = Object.keys(right).sort();
76
+ return leftKeys.length === rightKeys.length && leftKeys.every((key, index) => key === rightKeys[index] && left[key] === right[key]);
77
+ }
78
+ function sameRuntimeScopedApplicationOwner(reads, owner) {
79
+ return reads.binding.appId === owner.binding.appId && reads.binding.generationId === owner.binding.generationId && (reads.identity === null && owner.identity === null || reads.identity !== null && owner.identity !== null && reads.identity.id === owner.identity.id && reads.identity.email === owner.identity.email);
80
+ }
81
+
82
+ // ../runtime/dist/adapters/database/postgres-recovery-owner.js
83
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
84
+ var DEFAULT_POSTGRES_RECOVERY_POLICY = Object.freeze({
85
+ readAttemptTimeoutMs: 8e3,
86
+ readTotalTimeoutMs: 12500,
87
+ replacementProbeTimeoutMs: 2e3,
88
+ maxRetiredPairs: 2
89
+ });
90
+ var MAX_POLICY_MILLISECONDS = 6e5;
91
+ var MAX_RETIRED_PAIRS = 16;
92
+ var databaseFailureRecords = /* @__PURE__ */ new WeakMap();
93
+ function runtimeDatabaseFailureRecord(error) {
94
+ return error instanceof RuntimeDatabaseUnavailableError ? databaseFailureRecords.get(error) : void 0;
95
+ }
96
+ function capturePostgresRecoveryPolicy(input = DEFAULT_POSTGRES_RECOVERY_POLICY) {
97
+ const captured = {
98
+ readAttemptTimeoutMs: input.readAttemptTimeoutMs,
99
+ readTotalTimeoutMs: input.readTotalTimeoutMs,
100
+ replacementProbeTimeoutMs: input.replacementProbeTimeoutMs,
101
+ maxRetiredPairs: input.maxRetiredPairs
102
+ };
103
+ if (!Number.isSafeInteger(captured.readAttemptTimeoutMs) || captured.readAttemptTimeoutMs < 1 || captured.readAttemptTimeoutMs > MAX_POLICY_MILLISECONDS || !Number.isSafeInteger(captured.readTotalTimeoutMs) || captured.readTotalTimeoutMs < captured.readAttemptTimeoutMs || captured.readTotalTimeoutMs > MAX_POLICY_MILLISECONDS || !Number.isSafeInteger(captured.replacementProbeTimeoutMs) || captured.replacementProbeTimeoutMs < 1 || captured.replacementProbeTimeoutMs > MAX_POLICY_MILLISECONDS || !Number.isSafeInteger(captured.maxRetiredPairs) || captured.maxRetiredPairs < 0 || captured.maxRetiredPairs > MAX_RETIRED_PAIRS)
104
+ throw new TypeError("Runtime PostgreSQL recovery policy is invalid");
105
+ return Object.freeze(captured);
106
+ }
107
+ var runtimeVettedAuthRead = /* @__PURE__ */ Symbol("runtime.vetted-auth-read");
108
+ var RuntimeDatabaseUnavailableError = class extends RuntimeDiagnosticError {
109
+ code = "RUNTIME_DATABASE_UNAVAILABLE";
110
+ constructor(reason, settlement) {
111
+ const guidance = reason === "settled_transient_exhausted" ? {
112
+ retryable: true,
113
+ retryPrecondition: "Retry only this non-effectful database read after the selected database connection has recovered; do not repeat a mutation or whole operation.",
114
+ nextAction: "Wait for the selected database connection to recover, then retry only the eligible read. Verify mutation outcomes before taking any further action."
115
+ } : reason === "observation_timeout" ? {
116
+ retryable: false,
117
+ retryPrecondition: "Do not retry while the original database query is still unsettled; its connection and result remain owned by this Runtime generation.",
118
+ nextAction: "Wait for the in-flight database read to settle before making another request; do not start an overlapping retry."
119
+ } : reason === "budget_exhausted" ? {
120
+ retryable: false,
121
+ retryPrecondition: "This logical read's captured time budget has expired; use a fresh eligible read scope only after prior database work has settled.",
122
+ nextAction: "Allow any in-flight database work to settle, then begin a new request if the operation is still needed; do not extend or repeat this expired operation."
123
+ } : reason === "owner_closing" ? {
124
+ retryable: false,
125
+ retryPrecondition: "Retry only after a replacement Runtime generation is ready and its database admission is open.",
126
+ nextAction: "Wait for the Runtime generation to finish draining and for its replacement to become ready; do not retry against the closing database owner."
127
+ } : {
128
+ retryable: false,
129
+ retryPrecondition: "Retry only after the selected database connection is known to be ready and the operation's outcome is safe to repeat.",
130
+ nextAction: "Verify any operation outcome, then use a fresh request after database readiness is restored; do not blindly repeat a mutation."
131
+ };
132
+ super({
133
+ code: "RUNTIME_DATABASE_UNAVAILABLE",
134
+ stage: "request",
135
+ servingStarted: "unchanged",
136
+ dataImpact: "none",
137
+ ...guidance,
138
+ capability: "database"
139
+ });
140
+ this.name = "RuntimeDatabaseUnavailableError";
141
+ if (reason)
142
+ databaseFailureRecords.set(this, Object.freeze({ reason, ...settlement ? { settlement } : {} }));
143
+ }
144
+ };
145
+ var runtimeVettedAuthReadScope = /* @__PURE__ */ Symbol("runtime.vetted-auth-read-scope");
146
+ function isTransientConnectionFailure(error) {
147
+ const visited = /* @__PURE__ */ new Set();
148
+ let candidate = error;
149
+ for (let depth = 0; depth < 8; depth++) {
150
+ if (!candidate || typeof candidate !== "object" || visited.has(candidate))
151
+ return false;
152
+ visited.add(candidate);
153
+ try {
154
+ const state = Reflect.get(candidate, "code") ?? Reflect.get(candidate, "errno");
155
+ const driverCode = Reflect.get(candidate, "driverCode");
156
+ if (state === "08006" || // Replay remains limited to settled vetted reads and unentered BEGINs.
157
+ state === "57P01" || driverCode === "ERR_POSTGRES_CONNECTION_CLOSED" || driverCode === "ERR_POSTGRES_CONNECTION_TIMEOUT" || driverCode === "ERR_POSTGRES_CONNECTION_LOST")
158
+ return true;
159
+ candidate = Reflect.get(candidate, "cause");
160
+ } catch {
161
+ return false;
162
+ }
163
+ }
164
+ return false;
165
+ }
166
+ function createPostgresRecoveryOwner(input, retainGenerationWork) {
167
+ const policy = capturePostgresRecoveryPolicy(input);
168
+ const scopes = new AsyncLocalStorage2();
169
+ const executionFences = new AsyncLocalStorage2();
170
+ const active = /* @__PURE__ */ new Set();
171
+ let closing = false;
172
+ let recoveryFenced = false;
173
+ let closed;
174
+ function track(start) {
175
+ let operation;
176
+ let resolveOperation;
177
+ let rejectOperation;
178
+ operation = new Promise((resolve, reject) => {
179
+ resolveOperation = resolve;
180
+ rejectOperation = reject;
181
+ });
182
+ if (closing) {
183
+ rejectOperation(new RuntimeDatabaseUnavailableError("owner_closing"));
184
+ return operation;
185
+ }
186
+ try {
187
+ retainGenerationWork?.(operation);
188
+ } catch (error) {
189
+ rejectOperation(error);
190
+ return operation;
191
+ }
192
+ active.add(operation);
193
+ const release = () => active.delete(operation);
194
+ void operation.then(release, release);
195
+ try {
196
+ void Promise.resolve(start()).then(resolveOperation, rejectOperation);
197
+ } catch (error) {
198
+ rejectOperation(error);
199
+ }
200
+ return operation;
201
+ }
202
+ function trackEager(start) {
203
+ let settle;
204
+ let fail;
205
+ const lease = new Promise((resolve, reject) => {
206
+ settle = resolve;
207
+ fail = reject;
208
+ });
209
+ if (closing)
210
+ throw new RuntimeDatabaseUnavailableError("owner_closing");
211
+ try {
212
+ retainGenerationWork?.(lease);
213
+ } catch (error) {
214
+ throw error;
215
+ }
216
+ active.add(lease);
217
+ const release = () => active.delete(lease);
218
+ void lease.then(release, release);
219
+ try {
220
+ const started = start();
221
+ void Promise.resolve(started.settlement).then(settle, fail);
222
+ return started.result;
223
+ } catch (error) {
224
+ fail(error);
225
+ throw error;
226
+ }
227
+ }
228
+ function createCallbackAdmission(fence, scope) {
229
+ const assertActive = () => {
230
+ if (typeof fence === "function")
231
+ fence();
232
+ scope?.assertActive();
233
+ if (closing || recoveryFenced && fence !== null)
234
+ throw new RuntimeDatabaseUnavailableError("owner_closing");
235
+ if (scope?.logicalRead?.observationExpired)
236
+ throw new RuntimeDatabaseUnavailableError("observation_timeout");
237
+ if (scope && performance.now() >= scope.deadlineAt)
238
+ throw new RuntimeDatabaseUnavailableError("budget_exhausted");
239
+ };
240
+ return Object.freeze({
241
+ scope,
242
+ assertActive,
243
+ run(operation) {
244
+ return scopes.run(scope, () => executionFences.run(fence, operation));
245
+ },
246
+ withScope(nextScope) {
247
+ return createCallbackAdmission(fence, nextScope);
248
+ }
249
+ });
250
+ }
251
+ function captureCallbackAdmission() {
252
+ return createCallbackAdmission(executionFences.getStore(), scopes.getStore() ?? null);
253
+ }
254
+ function consume(scope, admission) {
255
+ try {
256
+ admission.assertActive();
257
+ } catch (error) {
258
+ return { kind: "scope_ended", error };
259
+ }
260
+ if (closing || recoveryFenced)
261
+ return { kind: "owner_closing" };
262
+ if (performance.now() >= scope.deadlineAt)
263
+ return { kind: "budget_exhausted" };
264
+ if (scope.logicalRead?.observationExpired)
265
+ return { kind: "budget_exhausted" };
266
+ if (scope.permit.remainingReplay !== 1)
267
+ return { kind: "permit_exhausted" };
268
+ scope.permit.remainingReplay = 0;
269
+ return { kind: "granted" };
270
+ }
271
+ function withExecutionFence(assertActive, operation) {
272
+ const parent = executionFences.getStore();
273
+ const combined = () => {
274
+ parent?.();
275
+ assertActive();
276
+ };
277
+ combined();
278
+ return executionFences.run(combined, operation);
279
+ }
280
+ function withNeutralExecutionFence(operation) {
281
+ return executionFences.run(null, operation);
282
+ }
283
+ function createReadScope(inherited, sourceFence, deadlineAt, logicalRead = inherited?.logicalRead) {
284
+ const startedAt = performance.now();
285
+ const permit = inherited?.permit ?? { remainingReplay: 1 };
286
+ return {
287
+ permit,
288
+ logicalRead,
289
+ deadlineAt: Math.min(inherited?.deadlineAt ?? Number.POSITIVE_INFINITY, startedAt + policy.readTotalTimeoutMs, deadlineAt ?? Number.POSITIVE_INFINITY),
290
+ assertActive: () => {
291
+ if (typeof sourceFence === "function")
292
+ sourceFence();
293
+ inherited?.assertActive();
294
+ if (logicalRead?.observationExpired)
295
+ throw new RuntimeDatabaseUnavailableError("observation_timeout");
296
+ }
297
+ };
298
+ }
299
+ function withVettedReadScope(options, operation) {
300
+ if (options.deadlineAt !== void 0 && (!Number.isFinite(options.deadlineAt) || options.deadlineAt < 0))
301
+ throw new TypeError("Runtime vetted database read scope options are invalid");
302
+ if (closing || recoveryFenced)
303
+ throw new RuntimeDatabaseUnavailableError("owner_closing");
304
+ const inherited = scopes.getStore();
305
+ const sourceFence = executionFences.getStore();
306
+ const scope = createReadScope(inherited, sourceFence, options.deadlineAt, { observationExpired: false });
307
+ scope.assertActive();
308
+ if (performance.now() >= scope.deadlineAt)
309
+ throw new RuntimeDatabaseUnavailableError("budget_exhausted");
310
+ return scopes.run(scope, () => executionFences.run(sourceFence, operation));
311
+ }
312
+ async function begin(operation, callbackEntered, admission = captureCallbackAdmission()) {
313
+ const run = async (scope2, callbackAdmission) => {
314
+ try {
315
+ return await track(() => operation(callbackAdmission));
316
+ } catch (error) {
317
+ if (callbackEntered())
318
+ throw error;
319
+ if (!isTransientConnectionFailure(error)) {
320
+ markOwnedPostgresLoginRejection(error);
321
+ throw error;
322
+ }
323
+ if (consume(scope2, callbackAdmission).kind !== "granted")
324
+ throw error;
325
+ try {
326
+ return await track(() => operation(callbackAdmission));
327
+ } catch (retryError) {
328
+ if (!callbackEntered())
329
+ markOwnedPostgresLoginRejection(retryError);
330
+ throw retryError;
331
+ }
332
+ }
333
+ };
334
+ const inherited = admission.scope;
335
+ const scope = inherited ?? {
336
+ permit: { remainingReplay: 1 },
337
+ deadlineAt: Number.POSITIVE_INFINITY,
338
+ assertActive: () => {
339
+ if (closing)
340
+ throw new RuntimeDatabaseUnavailableError("owner_closing");
341
+ }
342
+ };
343
+ const operationAdmission = inherited ? admission : admission.withScope(scope);
344
+ operationAdmission.assertActive();
345
+ return operationAdmission.run(() => run(scope, operationAdmission));
346
+ }
347
+ function observe(operation, timeoutMs) {
348
+ return new Promise((resolve, reject) => {
349
+ let settled = false;
350
+ const timer = setTimeout(() => {
351
+ if (settled)
352
+ return;
353
+ settled = true;
354
+ const settlement = operation.then(() => "success", (error) => isTransientConnectionFailure(error) ? "transient" : "other");
355
+ const failure = new RuntimeDatabaseUnavailableError("observation_timeout", settlement);
356
+ reject(failure);
357
+ }, timeoutMs);
358
+ void operation.then((value) => {
359
+ if (settled)
360
+ return;
361
+ settled = true;
362
+ clearTimeout(timer);
363
+ resolve(value);
364
+ }, (error) => {
365
+ if (settled)
366
+ return;
367
+ settled = true;
368
+ clearTimeout(timer);
369
+ reject(error);
370
+ });
371
+ });
372
+ }
373
+ async function runVettedRead(method, operation, options = {}) {
374
+ if (method !== "findOne" && method !== "findMany" && method !== "count")
375
+ throw new TypeError("Runtime database read method is not vetted");
376
+ const retryDelayMs = options.retryDelayMs ?? 0;
377
+ const retryAttemptTimeoutMs = options.retryAttemptTimeoutMs ?? policy.readAttemptTimeoutMs;
378
+ if (!Number.isSafeInteger(retryDelayMs) || retryDelayMs < 0 || retryDelayMs > policy.readTotalTimeoutMs || !Number.isSafeInteger(retryAttemptTimeoutMs) || retryAttemptTimeoutMs < 1 || retryAttemptTimeoutMs > policy.readAttemptTimeoutMs || options.deadlineAt !== void 0 && (!Number.isFinite(options.deadlineAt) || options.deadlineAt < 0))
379
+ throw new TypeError("Runtime vetted database read options are invalid");
380
+ if (closing || recoveryFenced)
381
+ throw new RuntimeDatabaseUnavailableError("owner_closing");
382
+ const inherited = scopes.getStore();
383
+ const sourceFence = executionFences.getStore();
384
+ const scope = createReadScope(inherited, sourceFence, options.deadlineAt, inherited?.logicalRead ?? { observationExpired: false });
385
+ const admission = createCallbackAdmission(sourceFence, scope);
386
+ return scopes.run(scope, () => executionFences.run(sourceFence, async () => {
387
+ let attemptNumber = 0;
388
+ for (; ; ) {
389
+ let remaining = scope.deadlineAt - performance.now();
390
+ if (remaining <= 0)
391
+ throw new RuntimeDatabaseUnavailableError("budget_exhausted");
392
+ scope.assertActive();
393
+ if (closing || attemptNumber > 0 && recoveryFenced)
394
+ throw new RuntimeDatabaseUnavailableError("owner_closing");
395
+ if (attemptNumber > 0 && retryDelayMs > 0) {
396
+ if (remaining <= retryDelayMs)
397
+ throw new RuntimeDatabaseUnavailableError("budget_exhausted");
398
+ const delay = Math.min(retryDelayMs, remaining);
399
+ await new Promise((resolve) => setTimeout(resolve, delay));
400
+ remaining = scope.deadlineAt - performance.now();
401
+ if (remaining <= 0)
402
+ throw new RuntimeDatabaseUnavailableError("budget_exhausted");
403
+ scope.assertActive();
404
+ if (closing || recoveryFenced)
405
+ throw new RuntimeDatabaseUnavailableError("owner_closing");
406
+ }
407
+ const attempt = track(() => Promise.resolve().then(operation));
408
+ attemptNumber++;
409
+ try {
410
+ const attemptLimit = attemptNumber === 1 ? policy.readAttemptTimeoutMs : retryAttemptTimeoutMs;
411
+ return await observe(attempt, Math.min(attemptLimit, remaining));
412
+ } catch (error) {
413
+ if (runtimeDatabaseFailureRecord(error)?.reason === "observation_timeout") {
414
+ if (scope.logicalRead)
415
+ scope.logicalRead.observationExpired = true;
416
+ throw error;
417
+ }
418
+ if (error instanceof RuntimeDatabaseUnavailableError)
419
+ throw error;
420
+ if (!isTransientConnectionFailure(error))
421
+ throw error;
422
+ const decision = consume(scope, admission);
423
+ if (decision.kind === "scope_ended")
424
+ throw decision.error;
425
+ if (decision.kind === "owner_closing")
426
+ throw new RuntimeDatabaseUnavailableError("owner_closing");
427
+ if (decision.kind === "budget_exhausted")
428
+ throw new RuntimeDatabaseUnavailableError("budget_exhausted");
429
+ if (decision.kind === "permit_exhausted")
430
+ throw new RuntimeDatabaseUnavailableError("settled_transient_exhausted");
431
+ }
432
+ }
433
+ }));
434
+ }
435
+ async function close() {
436
+ if (closed)
437
+ return closed;
438
+ closing = true;
439
+ closed = (async () => {
440
+ while (active.size > 0)
441
+ await Promise.allSettled([...active]);
442
+ })();
443
+ return closed;
444
+ }
445
+ function fenceRecovery() {
446
+ recoveryFenced = true;
447
+ }
448
+ return Object.freeze({
449
+ policy,
450
+ track,
451
+ trackEager,
452
+ begin,
453
+ captureCallbackAdmission,
454
+ runVettedRead,
455
+ withVettedReadScope,
456
+ withExecutionFence,
457
+ withNeutralExecutionFence,
458
+ fenceRecovery,
459
+ close,
460
+ get closing() {
461
+ return closing;
462
+ },
463
+ get recoveryFenced() {
464
+ return recoveryFenced;
465
+ },
466
+ get activeCount() {
467
+ return active.size;
468
+ }
469
+ });
470
+ }
471
+
472
+ // ../runtime/dist/app/capability-adapters.js
473
+ var runtimeGenerationBackedApplicationDatabase = /* @__PURE__ */ Symbol("runtime.generation-backed-application-database");
474
+ var runtimeDatabaseExecutionScope = /* @__PURE__ */ Symbol("runtime.database-execution-scope");
475
+ var runtimeDatabaseStopAdmissions = /* @__PURE__ */ Symbol("runtime.database-stop-admissions");
476
+ function unavailableCapability(capability) {
477
+ return new Proxy({}, {
478
+ get() {
479
+ throw new RuntimeCapabilityUnavailableError(capability);
480
+ }
481
+ });
482
+ }
483
+ var defaultUnavailableGrounding = Object.freeze(unavailableCapability("grounding"));
484
+ function isDefaultUnavailableGrounding(value) {
485
+ return value === defaultUnavailableGrounding;
486
+ }
487
+ function unavailableFunction(capability) {
488
+ return () => {
489
+ throw new RuntimeCapabilityUnavailableError(capability);
490
+ };
491
+ }
492
+ function createEmptyCapabilityContext() {
493
+ return {
494
+ db: unavailableCapability("database"),
495
+ unsafeDb: unavailableCapability("system database"),
496
+ auth: {
497
+ getUserIdentity: () => null,
498
+ requireAuth: () => {
499
+ throw new Error("Authentication required");
500
+ }
501
+ },
502
+ storage: unavailableCapability("storage"),
503
+ scheduler: unavailableCapability("scheduler"),
504
+ realtime: unavailableCapability("realtime"),
505
+ retry: withRetry,
506
+ services: unavailableCapability("services"),
507
+ search: unavailableFunction("search"),
508
+ vectorSearch: unavailableFunction("vector search"),
509
+ hybridSearch: unavailableFunction("hybrid search"),
510
+ grounding: defaultUnavailableGrounding
511
+ };
512
+ }
513
+
514
+ export {
515
+ runtimeScopedApplicationReads,
516
+ createRuntimeScopedApplicationReads,
517
+ sameRuntimeScopedRls,
518
+ sameRuntimeScopedApplicationOwner,
519
+ runtimeDatabaseFailureRecord,
520
+ runtimeVettedAuthRead,
521
+ runtimeVettedAuthReadScope,
522
+ createPostgresRecoveryOwner,
523
+ runtimeGenerationBackedApplicationDatabase,
524
+ runtimeDatabaseExecutionScope,
525
+ runtimeDatabaseStopAdmissions,
526
+ isDefaultUnavailableGrounding,
527
+ createEmptyCapabilityContext
528
+ };
@@ -0,0 +1,149 @@
1
+ import {
2
+ assertSearchScope,
3
+ snapshotSearchOptions
4
+ } from "./chunk-QL2TQX2N.mjs";
5
+ import {
6
+ RuntimeSearchError,
7
+ RuntimeSearchUnavailableError,
8
+ snapshotSearchRls
9
+ } from "./chunk-LEW5ZMLR.mjs";
10
+ import {
11
+ runtimeStartupError
12
+ } from "./chunk-IFMOTJNU.mjs";
13
+
14
+ // ../runtime/dist/search/config.js
15
+ var searchCapabilityEnvironmentNames = Object.freeze([
16
+ "__GENCOW_SEARCH_CAPABILITY_CONFIG",
17
+ "__GENCOW_SEARCH_TIER_CONFIG"
18
+ ]);
19
+ function captureRuntimeSearchSelection(input) {
20
+ if (input === void 0 || input === false)
21
+ return void 0;
22
+ if (input === true)
23
+ return Object.freeze({ adapter: "postgres" });
24
+ if (!input || typeof input !== "object" || Array.isArray(input) || Object.keys(input).some((key) => key !== "adapter") || input.adapter !== void 0 && input.adapter !== "postgres")
25
+ throw runtimeStartupError("RUNTIME_PROVIDER_SELECTION_INVALID", "In CLI projects, select localFeatures.search as true, {} or { adapter: 'postgres' }, or disable it. Direct local Runtime startup uses localFeatures.search; direct composition uses its Search provider selection. Regenerate the matching artifact before restarting.");
26
+ return Object.freeze({ adapter: "postgres" });
27
+ }
28
+
29
+ // ../runtime/dist/search/managed-observation.js
30
+ var observers = /* @__PURE__ */ new WeakMap();
31
+ function bindManagedSearchObserver(scope, observer) {
32
+ const captured = Object.freeze({ ...scope });
33
+ observers.set(captured, observer);
34
+ return captured;
35
+ }
36
+ var managedSearchObserverFor = (scope) => observers.get(scope);
37
+
38
+ // ../runtime/dist/search/provider.js
39
+ function createRuntimeSearchProvider(input) {
40
+ const modes = Object.freeze({ ...input.modes }), general = input.general;
41
+ const admitManaged = input.managed?.assertReady.bind(input.managed);
42
+ const unavailableGeneral = input.unavailableGeneral;
43
+ const observe = input.observe;
44
+ return Object.freeze({
45
+ createScope(owner) {
46
+ const observeManaged = managedSearchObserverFor(owner);
47
+ const scope = Object.freeze({
48
+ ...owner,
49
+ ...owner.rls === void 0 ? {} : { rls: snapshotSearchRls(owner) },
50
+ binding: Object.freeze({ ...owner.binding }),
51
+ identity: owner.identity ? Object.freeze({ ...owner.identity }) : null
52
+ });
53
+ const ended = () => new RuntimeSearchError("SEARCH_SCOPE_ENDED", scope.correlationId, scope.stage);
54
+ function active() {
55
+ try {
56
+ scope.assertActive();
57
+ } catch {
58
+ throw ended();
59
+ }
60
+ }
61
+ async function live() {
62
+ active();
63
+ try {
64
+ await scope.assertLive?.();
65
+ } catch {
66
+ throw ended();
67
+ }
68
+ active();
69
+ }
70
+ async function run(table, query, options, mode) {
71
+ active();
72
+ const startedAt = Date.now();
73
+ const managed = table === "rag_chunks" && Boolean(admitManaged);
74
+ const captured = snapshotSearchOptions(options, mode, scope);
75
+ assertSearchScope(scope, captured.scope);
76
+ const execution = Object.freeze({
77
+ ...scope,
78
+ ownership: managed ? "managed" : "general",
79
+ assertActive: active,
80
+ assertLive: live
81
+ });
82
+ await live();
83
+ if (managed) {
84
+ await admitManaged(execution);
85
+ await live();
86
+ }
87
+ const unsupported = () => {
88
+ throw new RuntimeSearchError("SEARCH_CAPABILITY_DEGRADED", scope.correlationId, scope.stage, "binding");
89
+ };
90
+ const response = mode === "lexical" ? await (modes.lexical ?? unsupported)(execution, table, query, captured) : mode === "vector" ? await (modes.vector ?? unsupported)(execution, table, captured) : await (modes.hybrid ?? unsupported)(execution, table, query, captured);
91
+ await live();
92
+ if (observe || managed && observeManaged) {
93
+ const event = Object.freeze({
94
+ binding: scope.binding,
95
+ corpus: captured.scope.corpus.trim(),
96
+ visibility: captured.scope.visibility,
97
+ ownerUserId: captured.scope.ownerUserId ?? (captured.scope.visibility === "private" ? scope.identity?.id ?? null : null),
98
+ mode,
99
+ latencyMs: Math.max(0, Date.now() - startedAt),
100
+ resultCount: response.items.length
101
+ });
102
+ if (managed && observeManaged) {
103
+ try {
104
+ observeManaged(Object.freeze({ ...event, lexicalStrategies: response.meta.lexicalStrategies }), execution);
105
+ } catch {
106
+ }
107
+ }
108
+ if (observe) {
109
+ try {
110
+ await observe(event);
111
+ } catch {
112
+ }
113
+ await live();
114
+ }
115
+ }
116
+ return response;
117
+ }
118
+ function selected(table, mode) {
119
+ if (!(table === "rag_chunks" && admitManaged) && !general) {
120
+ active();
121
+ if (unavailableGeneral)
122
+ unavailableGeneral();
123
+ throw new RuntimeSearchUnavailableError(scope.correlationId, mode);
124
+ }
125
+ }
126
+ return Object.freeze({
127
+ search: (table, query, options) => {
128
+ selected(table, "lexical");
129
+ return run(table, query, options, "lexical");
130
+ },
131
+ vectorSearch: (table, options) => {
132
+ selected(table, "vector");
133
+ return run(table, "", options, "vector");
134
+ },
135
+ hybridSearch: (table, query, options) => {
136
+ selected(table, "hybrid");
137
+ return run(table, query, options, "hybrid");
138
+ }
139
+ });
140
+ }
141
+ });
142
+ }
143
+
144
+ export {
145
+ searchCapabilityEnvironmentNames,
146
+ captureRuntimeSearchSelection,
147
+ bindManagedSearchObserver,
148
+ createRuntimeSearchProvider
149
+ };