@lunora/codegen 1.0.0-alpha.157 → 1.0.0-alpha.159

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.
@@ -15,27 +15,27 @@ import{agentComponent as dt}from"@lunora/agent/component";import{LunoraError as
15
15
  /**
16
16
  * R2 SQL over Apache Iceberg tables (window functions, DISTINCT, set operations). Non-deterministic — available only in actions. Reads here are NOT tracked by Lunora live queries.
17
17
  */
18
- readonly r2sql: import("@lunora/bindings/r2sql").R2SqlClient;`,tier:"action"}},{contextProperty:"scheduler",key:"scheduler",moduleSpecifier:"@lunora/scheduler"},{contextProperty:"storage",key:"storage",moduleSpecifier:"@lunora/storage"},{appMethod:{configKey:"vectors",doc:"Wire the Vectorize index map backing `ctx.vectors`.",method:"vectors"},contextProperty:"vectors",key:"vectors",moduleSpecifier:"@lunora/bindings/vectors"},{contextProperty:"workflows",key:"workflows",moduleSpecifier:"@lunora/workflow"}],Sn=ut,$n=new Map(Sn.flatMap(e=>e.serverCtxField?[[e.key,e.serverCtxField]]:[])),to=ut.flatMap(e=>"appMethod"in e?[{appMethod:e.appMethod,key:e.key}]:[]),pt=/^(?:"(?:[^"\\]|\\(?:["\\/bfnrt]|u[0-9A-Fa-f]{4}))*"|'[^'\\]*'|-?\d+(?:\.\d+)?|true|false|null)$/u,Tn=new Set(["any","bigint","boolean","date","id","null","number","storage","string","timestamp"]),ht=e=>e.column!==void 0,Nn=(e,t)=>{switch(e){case"bigint":return`if (typeof ${t} !== "bigint") return DEFER;
18
+ readonly r2sql: import("@lunora/bindings/r2sql").R2SqlClient;`,tier:"action"}},{contextProperty:"scheduler",key:"scheduler",moduleSpecifier:"@lunora/scheduler"},{contextProperty:"storage",key:"storage",moduleSpecifier:"@lunora/storage"},{appMethod:{configKey:"vectors",doc:"Wire the Vectorize index map backing `ctx.vectors`.",method:"vectors"},contextProperty:"vectors",key:"vectors",moduleSpecifier:"@lunora/bindings/vectors"},{contextProperty:"workflows",key:"workflows",moduleSpecifier:"@lunora/workflow"}],Sn=ut,$n=new Map(Sn.flatMap(e=>e.serverCtxField?[[e.key,e.serverCtxField]]:[])),to=ut.flatMap(e=>"appMethod"in e?[{appMethod:e.appMethod,key:e.key}]:[]),ht=/^(?:"(?:[^"\\]|\\(?:["\\/bfnrt]|u[0-9A-Fa-f]{4}))*"|'[^'\\]*'|-?\d+(?:\.\d+)?|true|false|null)$/u,Tn=new Set(["any","bigint","boolean","date","id","null","number","storage","string","timestamp"]),pt=e=>e.column!==void 0,Nn=(e,t)=>{switch(e){case"bigint":return`if (typeof ${t} !== "bigint") return DEFER;
19
19
  `;case"boolean":return`if (typeof ${t} !== "boolean") return DEFER;
20
20
  `;case"date":case"number":case"timestamp":return`if (typeof ${t} !== "number" || !Number.isFinite(${t})) return DEFER;
21
21
  `;case"null":return`if (${t} !== null) return DEFER;
22
22
  `;default:return`if (typeof ${t} !== "string") return DEFER;
23
23
  `}},An=(e,t)=>e.stringMaxLength===void 0?"":`if (${t}.length > ${String(e.stringMaxLength)}) return DEFER;
24
- `,On=(e,t)=>{const n=e.literalValue?.trim();if(!(n===void 0||!pt.test(n)))return{out:t,pre:`if (${t} !== ${n}) return DEFER;
25
- `}},Ge=(e,t,n)=>{if(!ht(e)&&!(e.unmodelledRefinement||e.sourceText!==void 0)){if(Tn.has(e.kind))return e.kind==="any"?{out:t,pre:""}:{out:t,pre:Nn(e.kind,t)+An(e,t)};switch(e.kind){case"array":return In(e,t,n);case"literal":return On(e,t);case"object":return En(e,t,n);default:return}}},In=(e,t,n)=>{const{inner:r}=e;if(!r)return;const o=n.next(),s=`__arr${String(o)}`,i=`__i${String(o)}`,a=`__e${String(o)}`,c=Ge(r,a,n);if(!c)return;const d=`if (!Array.isArray(${t})) return DEFER;
24
+ `,On=(e,t)=>{const n=e.literalValue?.trim();if(!(n===void 0||!ht.test(n)))return{out:t,pre:`if (${t} !== ${n}) return DEFER;
25
+ `}},Ge=(e,t,n)=>{if(!pt(e)&&!(e.unmodelledRefinement||e.sourceText!==void 0)){if(Tn.has(e.kind))return e.kind==="any"?{out:t,pre:""}:{out:t,pre:Nn(e.kind,t)+An(e,t)};switch(e.kind){case"array":return In(e,t,n);case"literal":return On(e,t);case"object":return En(e,t,n);default:return}}},In=(e,t,n)=>{const{inner:r}=e;if(!r)return;const o=n.next(),s=`__arr${String(o)}`,i=`__i${String(o)}`,a=`__e${String(o)}`,c=Ge(r,a,n);if(!c)return;const d=`if (!Array.isArray(${t})) return DEFER;
26
26
  const ${s} = new Array(${t}.length);
27
27
  for (let ${i} = 0; ${i} < ${t}.length; ${i}++) {
28
28
  const ${a} = ${t}[${i}];
29
29
  ${c.pre}${s}[${i}] = ${c.out};
30
30
  }
31
- `;return{out:s,pre:d}},Cn=(e,t,n,r)=>{const o=JSON.stringify(e);if(t.kind==="optional"){if(t.hasRefinement||t.sourceText!==void 0||ht(t))return;const{inner:i}=t;if(!i)return;const a=Ge(i,n,r);if(!a)return;const c=r.next(),d=`__has${String(c)}`,p=`__val${String(c)}`,m=`let ${d} = false;
32
- let ${p};
31
+ `;return{out:s,pre:d}},Cn=(e,t,n,r)=>{const o=JSON.stringify(e);if(t.kind==="optional"){if(t.hasRefinement||t.sourceText!==void 0||pt(t))return;const{inner:i}=t;if(!i)return;const a=Ge(i,n,r);if(!a)return;const c=r.next(),d=`__has${String(c)}`,h=`__val${String(c)}`,m=`let ${d} = false;
32
+ let ${h};
33
33
  if (${n} !== undefined) {
34
- ${a.pre}${p} = ${a.out};
34
+ ${a.pre}${h} = ${a.out};
35
35
  ${d} = true;
36
36
  }
37
- `;return{entry:`...(${d} ? { ${o}: ${p} } : {})`,pre:m}}const s=Ge(t,n,r);if(s)return{entry:`${o}: ${s.out}`,pre:s.pre}},Ln=new Set(Object.getOwnPropertyNames(Object.prototype)),mt=(e,t,n)=>{let r="";const o=[];for(const s of Object.keys(e)){const i=e[s];if(!i)return;const a=JSON.stringify(s);let c=`${t}[${a}]`;if(Ln.has(s)){const p=`__f${String(n.next())}`;r+=`const ${p} = Object.hasOwn(${t}, ${a}) ? ${t}[${a}] : undefined;
38
- `,c=p}const d=Cn(s,i,c,n);if(!d)return;r+=d.pre,o.push(d.entry)}return{entries:o.join(", "),pre:r}},gt=e=>{const t=`Object.getPrototypeOf(${e})`;return`if (${t} !== Object.prototype && ${t} !== null) return DEFER;
37
+ `;return{entry:`...(${d} ? { ${o}: ${h} } : {})`,pre:m}}const s=Ge(t,n,r);if(s)return{entry:`${o}: ${s.out}`,pre:s.pre}},Ln=new Set(Object.getOwnPropertyNames(Object.prototype)),mt=(e,t,n)=>{let r="";const o=[];for(const s of Object.keys(e)){const i=e[s];if(!i)return;const a=JSON.stringify(s);let c=`${t}[${a}]`;if(Ln.has(s)){const h=`__f${String(n.next())}`;r+=`const ${h} = Object.hasOwn(${t}, ${a}) ? ${t}[${a}] : undefined;
38
+ `,c=h}const d=Cn(s,i,c,n);if(!d)return;r+=d.pre,o.push(d.entry)}return{entries:o.join(", "),pre:r}},gt=e=>{const t=`Object.getPrototypeOf(${e})`;return`if (${t} !== Object.prototype && ${t} !== null) return DEFER;
39
39
  `},En=(e,t,n)=>{const r=e.shape??{},o=mt(r,t,n);if(!o)return;const s=n.next(),i=`__obj${String(s)}`,a=`if (typeof ${t} !== "object" || ${t} === null || Array.isArray(${t})) return DEFER;
40
40
  ${gt(t)}${o.pre}const ${i} = { ${o.entries} };
41
41
  `;return{out:i,pre:a}},_n=e=>{let t=0;const r=mt(e,"source",{next:()=>(t+=1,t)});if(r)return`(source) => {
@@ -44,7 +44,7 @@ ${gt("source")}${r.pre}return { ${r.entries} };
44
44
  }`},$=`// GENERATED by @lunora/codegen — do not edit.
45
45
  // Run \`lunora codegen\` to regenerate.
46
46
 
47
- `,ae=(e=!1)=>e?{client:"lunorash/client",do:"lunorash/do",flags:"lunorash/flags",server:"lunorash/server",serverDataModel:"lunorash/server/data-model",serverDrizzle:"lunorash/server/drizzle",serverTypes:"lunorash/server/types",values:"lunorash/values"}:{client:"@lunora/client",do:"@lunora/do",flags:"@lunora/flags",server:"@lunora/server",serverDataModel:"@lunora/server/data-model",serverDrizzle:"@lunora/server/drizzle",serverTypes:"@lunora/server/types",values:"@lunora/values"},ft=/^[A-Za-z_$][\w$]*$/u,Dn=/^[\w./-]+$/u,f=(e,t)=>{if(!ft.test(e))throw new X("INTERNAL",`@lunora/codegen: ${t} is not a valid JS identifier: ${JSON.stringify(e)}`)},He=e=>e.charAt(0).toUpperCase()+e.slice(1),q=e=>ft.test(e)?e:JSON.stringify(e),Y=e=>e==="__proto__"?`[${JSON.stringify(e)}]`:q(e),Pn={any:"unknown",bigint:"bigint",boolean:"boolean",bytes:"ArrayBuffer",date:"number",geoPoint:"{ lat: number; lng: number }",null:"null",number:"number",storage:"string",string:"string",timestamp:"number"},Mn=e=>{if(e===void 0)return"unknown";if(!pt.test(e))throw new X("INTERNAL",`@lunora/codegen: v.literal() argument is not a parseable string/number/boolean/null literal: ${JSON.stringify(e)}`);return e},O=e=>{const t=Pn[e.kind];if(t!==void 0)return t;switch(e.kind){case"array":return`Array<${e.inner?O(e.inner):"unknown"}>`;case"from":return e.tsType??"unknown";case"id":{const n=e.tableName??"_unknown_";return f(n,"v.id() table name"),`Id<"${n}">`}case"literal":return Mn(e.literalValue);case"object":return e.shape?`{ ${Object.entries(e.shape).map(([r,o])=>bt(r,o)).join("; ")} }`:"Record<string, unknown>";case"optional":return`${e.inner?O(e.inner):"unknown"} | undefined`;case"record":{const n=e.keyType?O(e.keyType):"string",r=e.valueType?O(e.valueType):"unknown";return`Record<${n}, ${r}>`}case"union":return e.members&&e.members.length>0?e.members.map(n=>O(n)).join(" | "):"never";default:return"unknown"}},bt=(e,t)=>{const n=q(e);if(t.kind==="optional"){const r=t.inner?O(t.inner):"unknown";return`${n}?: ${r}`}return`${n}: ${O(t)}`},xe=e=>{const t=Object.entries(e);return t.length===0?"{}":`{ ${t.map(([n,r])=>bt(n,r)).join("; ")} }`},yt=e=>e.kind==="optional"||!!e.column?.hasDefault,se=e=>e.kind==="optional"&&e.inner?e.inner:e,Fn=e=>{f(e.name,"table name");const t=Object.entries(e.shape).map(([r,o])=>{const s=se(o),i=O(s),a=q(r);return yt(o)?` ${a}?: ${i};`:` ${a}: ${i};`}).join(`
47
+ `,ae=(e=!1)=>e?{client:"lunorash/client",do:"lunorash/do",flags:"lunorash/flags",server:"lunorash/server",serverDataModel:"lunorash/server/data-model",serverDrizzle:"lunorash/server/drizzle",serverTypes:"lunorash/server/types",values:"lunorash/values"}:{client:"@lunora/client",do:"@lunora/do",flags:"@lunora/flags",server:"@lunora/server",serverDataModel:"@lunora/server/data-model",serverDrizzle:"@lunora/server/drizzle",serverTypes:"@lunora/server/types",values:"@lunora/values"},ft=/^[A-Za-z_$][\w$]*$/u,Dn=/^[\w./-]+$/u,f=(e,t)=>{if(!ft.test(e))throw new X("INTERNAL",`@lunora/codegen: ${t} is not a valid JS identifier: ${JSON.stringify(e)}`)},He=e=>e.charAt(0).toUpperCase()+e.slice(1),q=e=>ft.test(e)?e:JSON.stringify(e),Y=e=>e==="__proto__"?`[${JSON.stringify(e)}]`:q(e),Pn={any:"unknown",bigint:"bigint",boolean:"boolean",bytes:"ArrayBuffer",date:"number",geoPoint:"{ lat: number; lng: number }",null:"null",number:"number",storage:"string",string:"string",timestamp:"number"},Mn=e=>{if(e===void 0)return"unknown";if(!ht.test(e))throw new X("INTERNAL",`@lunora/codegen: v.literal() argument is not a parseable string/number/boolean/null literal: ${JSON.stringify(e)}`);return e},O=e=>{const t=Pn[e.kind];if(t!==void 0)return t;switch(e.kind){case"array":return`Array<${e.inner?O(e.inner):"unknown"}>`;case"from":return e.tsType??"unknown";case"id":{const n=e.tableName??"_unknown_";return f(n,"v.id() table name"),`Id<"${n}">`}case"literal":return Mn(e.literalValue);case"object":return e.shape?`{ ${Object.entries(e.shape).map(([r,o])=>bt(r,o)).join("; ")} }`:"Record<string, unknown>";case"optional":return`${e.inner?O(e.inner):"unknown"} | undefined`;case"record":{const n=e.keyType?O(e.keyType):"string",r=e.valueType?O(e.valueType):"unknown";return`Record<${n}, ${r}>`}case"union":return e.members&&e.members.length>0?e.members.map(n=>O(n)).join(" | "):"never";default:return"unknown"}},bt=(e,t)=>{const n=q(e);if(t.kind==="optional"){const r=t.inner?O(t.inner):"unknown";return`${n}?: ${r}`}return`${n}: ${O(t)}`},xe=e=>{const t=Object.entries(e);return t.length===0?"{}":`{ ${t.map(([n,r])=>bt(n,r)).join("; ")} }`},yt=e=>e.kind==="optional"||!!e.column?.hasDefault,se=e=>e.kind==="optional"&&e.inner?e.inner:e,Fn=e=>{f(e.name,"table name");const t=Object.entries(e.shape).map(([r,o])=>{const s=se(o),i=O(s),a=q(r);return yt(o)?` ${a}?: ${i};`:` ${a}: ${i};`}).join(`
48
48
  `),n=t?`
49
49
  ${t}
50
50
  `:"";return`export interface Insert_${e.name} {
@@ -62,7 +62,7 @@ ${l}
62
62
  `),i=e.tables.map(u=>{const l=u.searchIndexes.map(b=>JSON.stringify(b.name)).join(" | ");return` ${u.name}: ${l||"never"};`}).join(`
63
63
  `),a=e.tables.map(u=>{const l=u.rankIndexes.map(b=>JSON.stringify(b.name)).join(" | ");return` ${u.name}: ${l||"never"};`}).join(`
64
64
  `),c=e.tables.map(u=>{const l=u.shardMode==="global"?"":(u.geoIndexes??[]).map(b=>JSON.stringify(b.name)).join(" | ");return` ${u.name}: ${l||"never"};`}).join(`
65
- `),d=e.vectorIndexes.map(u=>JSON.stringify(u.name)).join(" | ")||"never",p=e.tables.map(u=>Fn(u)).join(`
65
+ `),d=e.vectorIndexes.map(u=>JSON.stringify(u.name)).join(" | ")||"never",h=e.tables.map(u=>Fn(u)).join(`
66
66
 
67
67
  `),m=e.tables.map(u=>` ${u.name}: Insert_${u.name};`).join(`
68
68
  `),y=e.tables.map(u=>{const l=u.relations.map(b=>(f(b.table,"relation target table"),` ${q(b.name)}: ${b.kind==="one"?"OneRelation":"ManyRelation"}<"${b.table}">;`)).join(`
@@ -132,7 +132,7 @@ export type GeoIndexName<T extends keyof DataModel> = GeoIndexNamesByTable[T];
132
132
  /** Union of declared vector index names. \`never\` when none are declared. */
133
133
  export type VectorIndexName = ${d};
134
134
 
135
- ${p}
135
+ ${h}
136
136
 
137
137
  /** Per-table insert shape, accepted by \`ctx.db.<table>.insert(...)\`. */
138
138
  export interface InsertModel {
@@ -207,7 +207,7 @@ ${i}
207
207
  */
208
208
  const lunoraAgentRuntimeFunctions = agentComponent().functions;
209
209
  `}},tr=(e,t)=>{if(!e)return{importLine:"",lines:"",prelude:""};const n=t.find(r=>T(r.filePath)==="sandbox"&&r.exportName==="invoke");if(n)throw new X("INTERNAL",`@lunora/codegen: "sandbox:invoke" is reserved for the batteries-included sandbox tool dispatcher (browserTool/containerTool) — rename the "invoke" export in ${n.filePath}`);return{importLine:`import { sandboxComponent } from "@lunora/agent/component";
210
- `,lines:' "sandbox:invoke": lunoraSandbox.invoke as unknown as RegisteredLunoraFunction,',prelude:"\n/**\n * The `@lunora/agent` sandbox dispatcher — auto-registered because `lunora/`\n * imports a sandbox tool (`browserTool`/`containerTool`). The batteries-included\n * tools dispatch to this internal action, which runs on an action ctx carrying\n * `ctx.browser` + `ctx.containers` (the durable tool step itself has neither).\n */\nconst lunoraSandbox = sandboxComponent();\n"}},nr=(e,t)=>{if(e.length===0)return[];const n=Rt(t),r=[{args:{key:{kind:"string"},limit:{inner:{kind:"number"},kind:"optional"}},exportName:"agentMessages",filePath:"agents",kind:"query",returnType:"Record<string, unknown>[]"},{args:{decision:{kind:"union",members:[{kind:"literal",literalValue:'"approve"'},{kind:"literal",literalValue:'"reject"'}]},instanceId:{kind:"string"},note:{inner:{kind:"string"},kind:"optional"},threadKey:{kind:"string"},toolCallId:{kind:"string"}},exportName:"agentResolveApproval",filePath:"agents",kind:"mutation",returnType:"{ resolved: boolean }"},{args:{agent:{kind:"string"},input:{kind:"string"},threadKey:{kind:"string"},title:{inner:{kind:"string"},kind:"optional"}},exportName:"agentRun",filePath:"agents",kind:"mutation",returnType:"{ id: string; threadKey: string }"},{args:{key:{kind:"string"}},exportName:"agentState",filePath:"agents",kind:"query",returnType:"Record<string, unknown> | undefined"},{args:{key:{kind:"string"}},exportName:"agentThread",filePath:"agents",kind:"query",returnType:"Record<string, unknown> | undefined"}];for(const o of e)o.voice&&r.push({args:{threadKey:{kind:"string"}},exportName:`${o.exportName}Voice`,filePath:"agents",kind:"stream",returnType:"Record<string, unknown>"});return r.filter(o=>!n.has(o.exportName))},rr=(e,t)=>{if(e.length===0)return[];const n=new Set(t.filter(r=>T(r.filePath)==="mutators").map(r=>r.exportName));return e.filter(r=>!n.has(r.exportName)).map(r=>({args:r.args,exportName:r.exportName,filePath:r.filePath,kind:"mutation",returnType:r.returnType}))},or=e=>{const t=e.filter(i=>i.stream);if(t.length===0)return{block:"",body:""};const n=Ye(t),r=n.map(([i,a])=>{const c=a.map(d=>{const p=E(d.chunkType??"unknown",d.filePath),m=E(xe(d.searchParams),d.filePath),y=E(xe(d.params),d.filePath);return` ${q(d.exportName)}: HttpStreamRef<${p}, ${m}, ${y}>;`}).join(`
210
+ `,lines:' "sandbox:invoke": lunoraSandbox.invoke as unknown as RegisteredLunoraFunction,',prelude:"\n/**\n * The `@lunora/agent` sandbox dispatcher — auto-registered because `lunora/`\n * imports a sandbox tool (`browserTool`/`containerTool`). The batteries-included\n * tools dispatch to this internal action, which runs on an action ctx carrying\n * `ctx.browser` + `ctx.containers` (the durable tool step itself has neither).\n */\nconst lunoraSandbox = sandboxComponent();\n"}},nr=(e,t)=>{if(e.length===0)return[];const n=Rt(t),r=[{args:{key:{kind:"string"},limit:{inner:{kind:"number"},kind:"optional"}},exportName:"agentMessages",filePath:"agents",kind:"query",returnType:"Record<string, unknown>[]"},{args:{decision:{kind:"union",members:[{kind:"literal",literalValue:'"approve"'},{kind:"literal",literalValue:'"reject"'}]},instanceId:{kind:"string"},note:{inner:{kind:"string"},kind:"optional"},threadKey:{kind:"string"},toolCallId:{kind:"string"}},exportName:"agentResolveApproval",filePath:"agents",kind:"mutation",returnType:"{ resolved: boolean }"},{args:{agent:{kind:"string"},input:{kind:"string"},threadKey:{kind:"string"},title:{inner:{kind:"string"},kind:"optional"}},exportName:"agentRun",filePath:"agents",kind:"mutation",returnType:"{ id: string; threadKey: string }"},{args:{key:{kind:"string"}},exportName:"agentState",filePath:"agents",kind:"query",returnType:"Record<string, unknown> | undefined"},{args:{key:{kind:"string"}},exportName:"agentThread",filePath:"agents",kind:"query",returnType:"Record<string, unknown> | undefined"}];for(const o of e)o.voice&&r.push({args:{threadKey:{kind:"string"}},exportName:`${o.exportName}Voice`,filePath:"agents",kind:"stream",returnType:"Record<string, unknown>"});return r.filter(o=>!n.has(o.exportName))},rr=(e,t)=>{if(e.length===0)return[];const n=new Set(t.filter(r=>T(r.filePath)==="mutators").map(r=>r.exportName));return e.filter(r=>!n.has(r.exportName)).map(r=>({args:r.args,exportName:r.exportName,filePath:r.filePath,kind:"mutation",returnType:r.returnType}))},or=e=>{const t=e.filter(i=>i.stream);if(t.length===0)return{block:"",body:""};const n=Ye(t),r=n.map(([i,a])=>{const c=a.map(d=>{const h=E(d.chunkType??"unknown",d.filePath),m=E(xe(d.searchParams),d.filePath),y=E(xe(d.params),d.filePath);return` ${q(d.exportName)}: HttpStreamRef<${h}, ${m}, ${y}>;`}).join(`
211
211
  `);return` ${q(T(i))}: {
212
212
  ${c}
213
213
  };`}).join(`
@@ -224,12 +224,12 @@ ${r}
224
224
  export const httpStreams: HttpStreamsRef = {
225
225
  ${o}
226
226
  };
227
- `,body:r}},ro=e=>{const{agents:t=[],functions:n,httpRoutes:r=[],mutators:o=[],useUmbrella:s=!1,workflows:i=[]}=e,a=ae(s),c=[...n.filter(A=>A.visibility!=="internal"),...nr(t,n),...rr(o,n)],d=n.filter(A=>A.visibility==="internal"),p=lt(c),m=lt(d),y=or(r),u=`${p}
227
+ `,body:r}},ro=e=>{const{agents:t=[],functions:n,httpRoutes:r=[],mutators:o=[],useUmbrella:s=!1,workflows:i=[]}=e,a=ae(s),c=[...n.filter(A=>A.visibility!=="internal"),...nr(t,n),...rr(o,n)],d=n.filter(A=>A.visibility==="internal"),h=lt(c),m=lt(d),y=or(r),u=`${h}
228
228
  ${m}
229
229
  ${y.body}`,l=ze(u),b=l.length>0?`
230
230
  import type { ${l.join(", ")} } from "./dataModel.js";
231
- `:"",R=p?`
232
- ${p}
231
+ `:"",R=h?`
232
+ ${h}
233
233
  `:"",x=m?`
234
234
  ${m}
235
235
  `:"",v=Yn(i,t),S=`export interface ApiTypes {${R}}
@@ -260,7 +260,7 @@ import type { InsertModel } from "./dataModel.js";
260
260
  * const { posts } = await seed.posts((x) => x([10, 20]));
261
261
  */
262
262
  export const createSeedClient = (options?: SeedClientOptions): SeedClient<InsertModel> => createSeedClientBase<InsertModel>(schema, options);
263
- `:"",ao=(e,t,n=!1)=>{if(e.length===0||!t)return"";const r=ae(n),o=c=>c.table===void 0?"Row":`Doc<${JSON.stringify(c.table)}> & Row`,s=e.map(c=>{f(c.exportName,"shape export name");const d=o(c),p=E(xe(c.args),c.filePath),m=Object.keys(c.args).length>0,y=m?` args: ${p};`:` args?: ${p};`,u=m?`(args: ${p}) => void`:`(args?: ${p}) => void`,l=`${c.exportName}CollectionOptions`;return`/** Options for the \`${c.exportName}\` shape binding. */
263
+ `:"",ao=(e,t,n=!1)=>{if(e.length===0||!t)return"";const r=ae(n),o=c=>c.table===void 0?"Row":`Doc<${JSON.stringify(c.table)}> & Row`,s=e.map(c=>{f(c.exportName,"shape export name");const d=o(c),h=E(xe(c.args),c.filePath),m=Object.keys(c.args).length>0,y=m?` args: ${h};`:` args?: ${h};`,u=m?`(args: ${h}) => void`:`(args?: ${h}) => void`,l=`${c.exportName}CollectionOptions`;return`/** Options for the \`${c.exportName}\` shape binding. */
264
264
  export interface ${He(l)} {
265
265
  ${y}
266
266
  /**
@@ -347,7 +347,7 @@ ${s}
347
347
  `),a=e.map(l=>` "${T(l.filePath)}:${l.exportName}": ${o.get(l.filePath)??""}.${l.exportName} as unknown as RegisteredLunoraFunction,`).join(`
348
348
  `),c=t.map(l=>` ${JSON.stringify(l.id)}: ${o.get(l.filePath)??""}.${l.exportName} as unknown as RegisteredDataMigration,`).join(`
349
349
  `),d=n.map(l=>` "${T(l.filePath)}:${l.exportName}": ${o.get(l.filePath)??""}.${l.exportName} as unknown as RegisteredLunoraFunction,`).join(`
350
- `),p=r.map(l=>` "${l.exportName}": ${o.get(l.filePath)??""}.${l.exportName} as unknown as RegisteredShape,`).join(`
350
+ `),h=r.map(l=>` "${l.exportName}": ${o.get(l.filePath)??""}.${l.exportName} as unknown as RegisteredShape,`).join(`
351
351
  `),m=n.map(l=>`${T(l.filePath)}:${l.exportName}`),y=[a,d].filter(l=>l.length>0).join(`
352
352
  `),u=e.map(l=>{if(l.lifecycle||Object.keys(l.args).length===0)return;const b=_n(l.args);return b===void 0?void 0:`installCompiledValidatorMap(${o.get(l.filePath)??""}.${l.exportName}.args, ${b});`}).filter(l=>l!==void 0).join(`
353
353
  `);return{dispatchBody:y.length>0?`
@@ -356,9 +356,9 @@ ${y}
356
356
 
357
357
  `:"",installBlock:u,migrationBody:c.length>0?`
358
358
  ${c}
359
- `:"",mutatorPaths:m,shapeBody:p.length>0?`
360
- ${p}
361
- `:""}},lr=e=>{const t=Ye(e),n=t.map(([o,s])=>{const i=s.map(a=>{const c=E(xe(a.args),a.filePath),d=c==="{}"?"?":"",p=E(vt(a),a.filePath);return a.kind==="stream"?` ${a.exportName}: (args${d}: ${c}) => Promise<AsyncIterable<${p}>>;`:` ${a.exportName}: (args${d}: ${c}) => Promise<${p}>;`}).join(`
359
+ `:"",mutatorPaths:m,shapeBody:h.length>0?`
360
+ ${h}
361
+ `:""}},lr=e=>{const t=Ye(e),n=t.map(([o,s])=>{const i=s.map(a=>{const c=E(xe(a.args),a.filePath),d=c==="{}"?"?":"",h=E(vt(a),a.filePath);return a.kind==="stream"?` ${a.exportName}: (args${d}: ${c}) => Promise<AsyncIterable<${h}>>;`:` ${a.exportName}: (args${d}: ${c}) => Promise<${h}>;`}).join(`
362
362
  `);return` ${q(T(o))}: {
363
363
  ${i}
364
364
  };`}).join(`
@@ -366,7 +366,7 @@ ${i}
366
366
  `);return` ${Y(i)}: {
367
367
  ${a}
368
368
  },`}).join(`
369
- `),types:n}},cr=(e,t=[])=>{const n=new Set;for(const r of e.tables)for(const o of Object.values(r.shape)){const s=se(o);s.kind==="storage"&&typeof s.bucket=="string"&&s.bucket!==""&&n.add(s.bucket)}for(const r of t)r!==""&&r!=="default"&&n.add(r);return["default",...[...n].toSorted((r,o)=>r.localeCompare(o))]},so=({agents:e=[],containers:t=[],env:n,hasAccessFacade:r=!1,hasAi:o=!1,hasAnalytics:s=!1,hasBrowser:i=!1,hasVectors:a=!0,hasFlags:c=!1,hasHyperdrive:d=!1,hasImages:p=!1,hasKv:m=!1,hasNotify:y=!1,hasPayments:u=!1,hasPipelines:l=!1,hasR2sql:b=!1,hasX402:R=!1,identity:x,queues:v=[],schema:S,storageRuleBuckets:N=[],useUmbrella:Q=!1,workflows:A=[]}={})=>{const C=ae(Q),w=cr(S??{tables:[]},N).map(h=>JSON.stringify(h)).join(" | "),P=o?`import type { LunoraAi } from "@lunora/ai";
369
+ `),types:n}},cr=(e,t=[])=>{const n=new Set;for(const r of e.tables)for(const o of Object.values(r.shape)){const s=se(o);s.kind==="storage"&&typeof s.bucket=="string"&&s.bucket!==""&&n.add(s.bucket)}for(const r of t)r!==""&&r!=="default"&&n.add(r);return["default",...[...n].toSorted((r,o)=>r.localeCompare(o))]},so=({agents:e=[],containers:t=[],env:n,hasAccessFacade:r=!1,hasAi:o=!1,hasAnalytics:s=!1,hasBrowser:i=!1,hasVectors:a=!0,hasFlags:c=!1,hasHyperdrive:d=!1,hasImages:h=!1,hasKv:m=!1,hasNotify:y=!1,hasPayments:u=!1,hasPipelines:l=!1,hasR2sql:b=!1,hasX402:R=!1,identity:x,queues:v=[],schema:S,storageRuleBuckets:N=[],useUmbrella:Q=!1,workflows:A=[]}={})=>{const C=ae(Q),w=cr(S??{tables:[]},N).map(p=>JSON.stringify(p)).join(" | "),P=o?`import type { LunoraAi } from "@lunora/ai";
370
370
  `:"",M=o?`
371
371
  readonly ai: LunoraAi;`:"",ie=u?`import type { LunoraPayment } from "@lunora/payment";
372
372
  `:"",le=u?`
@@ -374,13 +374,13 @@ ${a}
374
374
  `:"",V=R?`
375
375
  readonly x402: X402Pay;`:"",L=t.length>0?`import type { ContainerAccessor } from "@lunora/container";
376
376
  `:"",ee=t.length>0?`
377
- readonly containers: {${t.map(h=>`
378
- readonly ${h.exportName}: ContainerAccessor;`).join("")}
379
- };`:"",k=[...o?[" /** Workers AI binding (the conventional `env.AI`), narrowing `ctx.ai`. */\n readonly AI?: unknown;"]:[],...t.map(h=>(f(h.bindingName,`container binding "${h.bindingName}"`),` /** Durable Object namespace for the \`${h.exportName}\` container. */
380
- readonly ${h.bindingName}?: unknown;`)),...A.map(h=>(f(h.bindingName,`workflow binding "${h.bindingName}"`),` /** Workflow binding for the \`${h.exportName}\` workflow. */
381
- readonly ${h.bindingName}?: unknown;`)),...v.map(h=>(f(h.bindingName,`queue binding "${h.bindingName}"`),` /** Queue producer binding for the \`${h.exportName}\` queue. */
382
- readonly ${h.bindingName}?: unknown;`)),...e.map(h=>(f(h.bindingName,`agent binding "${h.bindingName}"`),` /** Workflow binding for the \`${h.exportName}\` agent. */
383
- readonly ${h.bindingName}?: unknown;`))].join(`
377
+ readonly containers: {${t.map(p=>`
378
+ readonly ${p.exportName}: ContainerAccessor;`).join("")}
379
+ };`:"",k=[...o?[" /** Workers AI binding (the conventional `env.AI`), narrowing `ctx.ai`. */\n readonly AI?: unknown;"]:[],...t.map(p=>(f(p.bindingName,`container binding "${p.bindingName}"`),` /** Durable Object namespace for the \`${p.exportName}\` container. */
380
+ readonly ${p.bindingName}?: unknown;`)),...A.map(p=>(f(p.bindingName,`workflow binding "${p.bindingName}"`),` /** Workflow binding for the \`${p.exportName}\` workflow. */
381
+ readonly ${p.bindingName}?: unknown;`)),...v.map(p=>(f(p.bindingName,`queue binding "${p.bindingName}"`),` /** Queue producer binding for the \`${p.exportName}\` queue. */
382
+ readonly ${p.bindingName}?: unknown;`)),...e.map(p=>(f(p.bindingName,`agent binding "${p.bindingName}"`),` /** Workflow binding for the \`${p.exportName}\` agent. */
383
+ readonly ${p.bindingName}?: unknown;`))].join(`
384
384
  `),Ae=`
385
385
 
386
386
  /**
@@ -399,8 +399,8 @@ ${k}`:""}
399
399
  }
400
400
 
401
401
  /** Alias for {@link CloudflareBindings} — the typed shape of \`env\`. */
402
- export type Env = CloudflareBindings;`,F=(h,We,Te)=>{const re=$n.get(h);if(re!==void 0&&re.tier!==Te)throw new X("INTERNAL",`@lunora/codegen: capability "${h}" declares tier "${re.tier}" in SERVER_CTX_FIELDS but is emitted onto the "${Te}" context — update whichever is wrong.`);return We?re?.field??"":""},ce=F("kv",m,"every"),de=F("analytics",s,"every"),Oe=F("hyperdrive",d,"action"),Ie=F("browser",i,"action"),Ce=F("images",p,"action"),ue=F("pipelines",l,"action"),H=F("r2sql",b,"action"),D=a&&(S?.vectorIndexes.length??0)>0,G=D?' | "vectors"':"",te=D?`
403
- readonly vectors: VectorSearch<VectorIndexName>;`:"",pe=D?`
402
+ export type Env = CloudflareBindings;`,F=(p,We,Te)=>{const re=$n.get(p);if(re!==void 0&&re.tier!==Te)throw new X("INTERNAL",`@lunora/codegen: capability "${p}" declares tier "${re.tier}" in SERVER_CTX_FIELDS but is emitted onto the "${Te}" context — update whichever is wrong.`);return We?re?.field??"":""},ce=F("kv",m,"every"),de=F("analytics",s,"every"),Oe=F("hyperdrive",d,"action"),Ie=F("browser",i,"action"),Ce=F("images",h,"action"),ue=F("pipelines",l,"action"),H=F("r2sql",b,"action"),D=a&&(S?.vectorIndexes.length??0)>0,G=D?' | "vectors"':"",te=D?`
403
+ readonly vectors: VectorSearch<VectorIndexName>;`:"",he=D?`
404
404
  readonly vectors: VectorSearchReader<VectorIndexName>;`:"",J=D?`import type { VectorSearch, VectorSearchReader } from "${C.server}";
405
405
  import type { VectorIndexName } from "./dataModel.js";
406
406
  `:"",j=r?`
@@ -424,27 +424,27 @@ type WorkflowParamsOf<Definition> = Definition extends { __params?: infer Params
424
424
 
425
425
  /** This project's declared workflows, addressable from \`ctx.workflows\` by their \`lunora/workflows.ts\` export name. */
426
426
  export interface LunoraWorkflows {
427
- ${A.map(h=>` get(name: ${JSON.stringify(h.exportName)}): WorkflowHandle<WorkflowParamsOf<typeof lunoraWorkflowDefinitions.${h.exportName}>>;`).join(`
427
+ ${A.map(p=>` get(name: ${JSON.stringify(p.exportName)}): WorkflowHandle<WorkflowParamsOf<typeof lunoraWorkflowDefinitions.${p.exportName}>>;`).join(`
428
428
  `)}
429
429
  }`:"",ve=B?' | "workflows"':"",Re=B?`
430
- readonly workflows: LunoraWorkflows;`:"",he=v.length>0,Ee=he?`import type { QueueProducer } from "@lunora/queue";
430
+ readonly workflows: LunoraWorkflows;`:"",pe=v.length>0,Ee=pe?`import type { QueueProducer } from "@lunora/queue";
431
431
  import type * as lunoraQueueDefinitions from "../queues.js";
432
- `:"",_e=he?`
432
+ `:"",_e=pe?`
433
433
 
434
434
  /** Message body type carried by a \`defineQueue\` definition (its phantom \`__lunoraBody\`). */
435
435
  type QueueBodyOf<Definition> = Definition extends { __lunoraBody?: infer Body } ? (unknown extends Body ? unknown : NonNullable<Body>) : unknown;
436
436
 
437
437
  /** This project's declared queues, addressable from \`ctx.queues\` by their \`lunora/queues.ts\` export name. */
438
438
  export interface LunoraQueues {
439
- ${v.map(h=>` readonly ${h.exportName}: QueueProducer<QueueBodyOf<typeof lunoraQueueDefinitions.${h.exportName}>>;`).join(`
439
+ ${v.map(p=>` readonly ${p.exportName}: QueueProducer<QueueBodyOf<typeof lunoraQueueDefinitions.${p.exportName}>>;`).join(`
440
440
  `)}
441
- }`:"",Se=he?`
441
+ }`:"",Se=pe?`
442
442
  readonly queues: LunoraQueues;`:"",me=e.length>0,De=me?`import type { AgentHandle } from "@lunora/agent";
443
443
  `:"",Pe=me?`
444
444
 
445
445
  /** This project's declared agents, addressable from \`ctx.agents\` by their \`lunora/agents.ts\` export name. */
446
446
  export interface LunoraAgents {
447
- ${e.map(h=>(f(h.exportName,`agent export "${h.exportName}"`),` readonly ${h.exportName}: AgentHandle;`)).join(`
447
+ ${e.map(p=>(f(p.exportName,`agent export "${p.exportName}"`),` readonly ${p.exportName}: AgentHandle;`)).join(`
448
448
  `)}
449
449
  }`:"",$e=me?`
450
450
  readonly agents: LunoraAgents;`:"",Me=x?`import type { InferIdentity } from "${C.server}";
@@ -643,7 +643,7 @@ type TypedAsId = <T extends string>(tableName: AsIdTable<T>, id: string) => IdOf
643
643
  export interface QueryCtx extends Omit<QueryCtxBase, "db" | "storage"${G}${ge}${be}> {
644
644
  readonly db: Omit<DatabaseReader, "asId" | "query" | "get"> & DatabaseReaderFacade & { asId: TypedAsId; query: TypedTableQuery; get: TypedTableGet };
645
645
  readonly orm: OrmReader;
646
- readonly storage: ReadOnlyStorage<StorageBucketName>;${pe}${j}${ce}${W}${U}${de}${ye}${fe}
646
+ readonly storage: ReadOnlyStorage<StorageBucketName>;${he}${j}${ce}${W}${U}${de}${ye}${fe}
647
647
  }
648
648
 
649
649
  export interface MutationCtx extends Omit<MutationCtxBase, "db" | "storage"${G}${ve}${ge}${be}> {
@@ -730,8 +730,8 @@ export const definePolicy = createPolicyDsl<DataModel, Relations${Be}>();
730
730
  export const v = vBase as unknown as Omit<typeof vBase, "id"> & {
731
731
  id: <T extends TableName>(table: T) => ColumnValidator<IdOfTable<T>, IdOfTable<T>>;
732
732
  };
733
- `},dr=e=>{const t={connect:[],disconnect:[],init:[],reactor:[]};for(const n of e)n.lifecycle&&t[n.lifecycle].push(`${T(n.filePath)}:${n.exportName}`);return t},io=e=>{const{agents:t=[],functions:n,migrations:r=[],mutators:o=[],shapes:s=[],useUmbrella:i=!1,usesSandbox:a=!1}=e,c=n.length>0,d=ae(i),{dispatchBody:p,importBlock:m,installBlock:y,migrationBody:u,mutatorPaths:l,shapeBody:b}=ir(n,r,o,s),R=er(t,n),x=tr(a,n),v=[R.lines,x.lines].filter(k=>k.length>0).join(`
734
- `);let S=p;v.length>0&&(S=p.length>0?`${p.trimEnd()}
733
+ `},dr=e=>{const t={connect:[],disconnect:[],init:[],reactor:[]};for(const n of e)n.lifecycle&&t[n.lifecycle].push(`${T(n.filePath)}:${n.exportName}`);return t},io=e=>{const{agents:t=[],functions:n,migrations:r=[],mutators:o=[],shapes:s=[],useUmbrella:i=!1,usesSandbox:a=!1}=e,c=n.length>0,d=ae(i),{dispatchBody:h,importBlock:m,installBlock:y,migrationBody:u,mutatorPaths:l,shapeBody:b}=ir(n,r,o,s),R=er(t,n),x=tr(a,n),v=[R.lines,x.lines].filter(k=>k.length>0).join(`
734
+ `);let S=h;v.length>0&&(S=h.length>0?`${h.trimEnd()}
735
735
  ${v}
736
736
  `:`
737
737
  ${v}
@@ -879,7 +879,7 @@ export interface RegisteredDataMigration {
879
879
  * shard DO's admin RPC and the CLI resolve migrations to run through this map.
880
880
  */
881
881
  export const LUNORA_MIGRATIONS: Record<string, RegisteredDataMigration> = {${u}};
882
- `,i)},ur=e=>{const t={};for(const n of e.tables){const r={};for(const[o,s]of Object.entries(n.shape)){const i=se(s);i.kind==="id"&&i.tableName!==void 0&&(r[o]=i.tableName)}Object.keys(r).length>0&&(t[n.name]=r)}return t},pr=e=>{const t={};for(const n of e.tables){const r=[];for(const[o,s]of Object.entries(n.shape))se(s).kind==="storage"&&r.push(o);r.length>0&&(t[n.name]=r)}return t},hr=e=>{const t={};for(const n of e.tables){const r=[...n.indexes.map(o=>({fields:[...o.fields],name:o.name,type:"index",...o.unique===!0?{unique:!0}:{}})),...n.searchIndexes.map(o=>({fields:[o.field,...o.filterFields??[]],name:o.name,type:"search"})),...(n.geoIndexes??[]).map(o=>({fields:[o.field],name:o.name,type:"geo"})),...n.rankIndexes.map(o=>({fields:o.sortBy.map(s=>s.field),name:o.name,type:"rank"})),...n.vectorIndexes.map(o=>({fields:o.field===void 0?[]:[o.field],name:o.name,type:"vector"}))];r.length>0&&(t[n.name]=r)}return t},mr=e=>{const t=[];for(const n of e.tables)!n.ttl||n.shardMode==="global"||t.push({...n.ttl.after===void 0?{}:{after:n.ttl.after},field:n.ttl.field,...n.softDelete?{softDeleteField:n.softDelete.field}:{},table:n.name});return t},gr=e=>{if(e.kind!=="union"||e.members===void 0||e.members.length===0)return;const t=[];for(const n of e.members){if(n.kind!=="literal"||n.literalValue===void 0)return;try{const r=JSON.parse(n.literalValue);if(typeof r!="string")return;t.push(r)}catch{return}}return t},fr=(e,t)=>{const n=se(t),r={name:e,optional:yt(t),type:n.kind};n.kind==="id"&&n.tableName!==void 0&&(r.ref=n.tableName),n.kind==="storage"&&(r.isStorage=!0,n.bucket!==void 0&&(r.bucket=n.bucket));const o=gr(n);return o!==void 0&&(r.enumValues=o),n.column?.notNull===!1&&(r.nullable=!0),r},br=e=>{const t={};for(const n of e.tables){const r=[{name:"_id",optional:!1,pk:!0,type:"id"},{name:"_creationTime",optional:!1,type:"number"},...n.commitOrdered===!0?[{name:"_commitSeq",optional:!1,type:"number"}]:[]];for(const[o,s]of Object.entries(n.shape))r.push(fr(o,s));t[n.name]=r}return t},yr=e=>e?{importFragment:"serveRelationFanout, ",override:`
882
+ `,i)},ur=e=>{const t={};for(const n of e.tables){const r={};for(const[o,s]of Object.entries(n.shape)){const i=se(s);i.kind==="id"&&i.tableName!==void 0&&(r[o]=i.tableName)}Object.keys(r).length>0&&(t[n.name]=r)}return t},hr=e=>{const t={};for(const n of e.tables){const r=[];for(const[o,s]of Object.entries(n.shape))se(s).kind==="storage"&&r.push(o);r.length>0&&(t[n.name]=r)}return t},pr=e=>{const t={};for(const n of e.tables){const r=[...n.indexes.map(o=>({fields:[...o.fields],name:o.name,type:"index",...o.unique===!0?{unique:!0}:{}})),...n.searchIndexes.map(o=>({fields:[o.field,...o.filterFields??[]],name:o.name,type:"search"})),...(n.geoIndexes??[]).map(o=>({fields:[o.field],name:o.name,type:"geo"})),...n.rankIndexes.map(o=>({fields:o.sortBy.map(s=>s.field),name:o.name,type:"rank"})),...n.vectorIndexes.map(o=>({fields:o.field===void 0?[]:[o.field],name:o.name,type:"vector"}))];r.length>0&&(t[n.name]=r)}return t},mr=e=>{const t=[];for(const n of e.tables)!n.ttl||n.shardMode==="global"||t.push({...n.ttl.after===void 0?{}:{after:n.ttl.after},field:n.ttl.field,...n.softDelete?{softDeleteField:n.softDelete.field}:{},table:n.name});return t},gr=e=>{if(e.kind!=="union"||e.members===void 0||e.members.length===0)return;const t=[];for(const n of e.members){if(n.kind!=="literal"||n.literalValue===void 0)return;try{const r=JSON.parse(n.literalValue);if(typeof r!="string")return;t.push(r)}catch{return}}return t},fr=(e,t)=>{const n=se(t),r={name:e,optional:yt(t),type:n.kind};n.kind==="id"&&n.tableName!==void 0&&(r.ref=n.tableName),n.kind==="storage"&&(r.isStorage=!0,n.bucket!==void 0&&(r.bucket=n.bucket));const o=gr(n);return o!==void 0&&(r.enumValues=o),n.column?.notNull===!1&&(r.nullable=!0),r},br=e=>{const t={};for(const n of e.tables){const r=[{name:"_id",optional:!1,pk:!0,type:"id"},{name:"_creationTime",optional:!1,type:"number"},...n.commitOrdered===!0?[{name:"_commitSeq",optional:!1,type:"number"}]:[]];for(const[o,s]of Object.entries(n.shape))r.push(fr(o,s));t[n.name]=r}return t},yr=e=>e?{importFragment:"serveRelationFanout, ",override:`
883
883
  protected override async runRelationFanoutRead(functionPath: string, args: Record<string, unknown>): Promise<unknown> {
884
884
  this.ensureMigrated();
885
885
 
@@ -1119,8 +1119,8 @@ export class ${a.className} extends LunoraWorkflow<AgentRunInput, AgentRunResult
1119
1119
  super(ctx, env, compileAgentWorkflow(${a.exportName}, "${a.exportName}"), "${a.exportName}");
1120
1120
  }
1121
1121
  }
1122
- `;if(!a.voice)return c;const d=a.voiceClassName??"",p=a.voiceBindingName??"";f(d,`agent voice class "${d}"`);const m=`
1123
- /** Voice-session Durable Object for the \`${a.exportName}\` agent (binding \`${p}\`). */
1122
+ `;if(!a.voice)return c;const d=a.voiceClassName??"",h=a.voiceBindingName??"";f(d,`agent voice class "${d}"`);const m=`
1123
+ /** Voice-session Durable Object for the \`${a.exportName}\` agent (binding \`${h}\`). */
1124
1124
  export class ${d} extends VoiceSessionDO {
1125
1125
  public constructor(ctx: ConstructorParameters<typeof VoiceSessionDO>[0], env: Record<string, unknown>) {
1126
1126
  super(ctx, env, ${a.exportName}, "${a.exportName}");
@@ -1141,7 +1141,7 @@ import type { AgentRunInput, AgentRunResult } from "@lunora/agent";
1141
1141
 
1142
1142
  import { ${o} } from "../agents.js";
1143
1143
 
1144
- ${r}`},po=e=>{const t=e.filter(o=>o.mode==="push");if(t.length===0)return"";for(const o of t)f(o.exportName,`queue export "${o.exportName}"`);const n=t.map(o=>o.exportName).join(", "),r=t.map(o=>` ${JSON.stringify(o.name)}: { definition: ${o.exportName}, exportName: ${JSON.stringify(o.exportName)} },`).join(`
1144
+ ${r}`},ho=e=>{const t=e.filter(o=>o.mode==="push");if(t.length===0)return"";for(const o of t)f(o.exportName,`queue export "${o.exportName}"`);const n=t.map(o=>o.exportName).join(", "),r=t.map(o=>` ${JSON.stringify(o.name)}: { definition: ${o.exportName}, exportName: ${JSON.stringify(o.exportName)} },`).join(`
1145
1145
  `);return`${$}/**
1146
1146
  * Push-consumer registry for the queues declared in \`lunora/queues.ts\`. The
1147
1147
  * composed worker's \`queue(batch, env, ctx)\` entry routes each delivered batch
@@ -1201,10 +1201,10 @@ const ${e}: ${t} = ${JSON.stringify(r,void 0,4)};
1201
1201
  ? lazyX402Pay(config.x402(env), { getSecret: (name: string) => secrets.get(name) })
1202
1202
  : x402Stub;
1203
1203
  `,configField:`
1204
- x402?: (env: Record<string, unknown>) => X402PayConfig;`,stub:I("x402Stub: X402Pay",'throw new Error("ctx.x402: no pay rail configured. Pass \\`x402\\` to createShardDO().");',["fetch"],{cast:" as unknown as X402Pay",sync:["fetch"]})}:{build:"",configField:"",imports:[],stub:""},qr=(e,t,n,r,o)=>["AdvisorProcedure","AdvisoryFinding","DatabaseWriterLike","DataMigrationLike","ExportRow",...r?["FlagsResult"]:[],"ImportShardResult","KeyRange","MaskPoliciesResult","MigrationRunResult","QueryReadScope",...n?["QueuesResult"]:[],"RunShardApplyCdcArgs","RunShardExportArgs","RunShardImportArgs","RunShardMigrationArgs","RlsPoliciesResult","RunShardRankBeforeArgs","RunShardRankPageArgs","RunShardWriteArgs","RunShardWriteResult","SchedulerLike",...o?["SearchBackfillProgress"]:[],"TransactionHeadroomTracker","SchemaLike","ShardDOState","ShardRankPageResult","SqlExec","StorageRulesResult","StudioFeaturesResult","SystemReaderStorageLike","TelemetrySink",...t?["WorkflowsResult"]:[],...e?["WriteHook"]:[]],ho=({advisories:e=[],advisorProcedures:t=[],agents:n=[],containers:r=[],env:o,flagKeys:s=[],hasAccessFacade:i=!1,hasAi:a=!1,hasAnalytics:c=!1,hasBrowser:d=!1,hasFlags:p=!1,hasHyperdrive:m=!1,hasImages:y=!1,hasKv:u=!1,hasNotify:l=!1,hasPayments:b=!1,hasPipelines:R=!1,hasR2sql:x=!1,hasVectors:v=!0,hasX402:S=!1,maskMetadata:N,mutators:Q=[],queues:A=[],rlsMetadata:C,schema:w,schemaSnapshot:P,shapes:M=[],storageRules:ie,studioFeatures:le,useUmbrella:Z=!1,workflows:V=[]})=>{const L=ae(Z),ee=Q.length>0,k=M.length>0,Ae=P===void 0?"":vn(P),F=P===void 0?"":`
1204
+ x402?: (env: Record<string, unknown>) => X402PayConfig;`,stub:I("x402Stub: X402Pay",'throw new Error("ctx.x402: no pay rail configured. Pass \\`x402\\` to createShardDO().");',["fetch"],{cast:" as unknown as X402Pay",sync:["fetch"]})}:{build:"",configField:"",imports:[],stub:""},qr=(e,t,n,r,o)=>["AdvisorProcedure","AdvisoryFinding","DatabaseWriterLike","DataMigrationLike","ExportRow",...r?["FlagsResult"]:[],"ImportShardResult","KeyRange","MaskPoliciesResult","MigrationRunResult","QueryReadScope",...n?["QueuesResult"]:[],"RunShardApplyCdcArgs","RunShardExportArgs","RunShardImportArgs","RunShardMigrationArgs","RlsPoliciesResult","RunShardRankBeforeArgs","RunShardRankPageArgs","RunShardWriteArgs","RunShardWriteResult","SchedulerLike",...o?["SearchBackfillProgress"]:[],"TransactionHeadroomTracker","SchemaLike","ShardDOState","ShardRankPageResult","SqlExec","StorageRulesResult","StudioFeaturesResult","SystemReaderStorageLike","TelemetrySink",...t?["WorkflowsResult"]:[],...e?["WriteHook"]:[]],po=({advisories:e=[],advisorProcedures:t=[],agents:n=[],containers:r=[],env:o,flagKeys:s=[],hasAccessFacade:i=!1,hasAi:a=!1,hasAnalytics:c=!1,hasBrowser:d=!1,hasFlags:h=!1,hasHyperdrive:m=!1,hasImages:y=!1,hasKv:u=!1,hasNotify:l=!1,hasPayments:b=!1,hasPipelines:R=!1,hasR2sql:x=!1,hasVectors:v=!0,hasX402:S=!1,maskMetadata:N,mutators:Q=[],queues:A=[],rlsMetadata:C,schema:w,schemaSnapshot:P,shapes:M=[],storageRules:ie,studioFeatures:le,useUmbrella:Z=!1,workflows:V=[]})=>{const L=ae(Z),ee=Q.length>0,k=M.length>0,Ae=P===void 0?"":vn(P),F=P===void 0?"":`
1205
1205
  /** Structural schema snapshot + its content hash, recorded in the shard's \`__lunora_schema_history\` ledger on cold start so the studio can show a schema-version timeline and diff any two versions. */
1206
1206
  const LUNORA_SCHEMA_SNAPSHOT: { hash: string; json: string } = { hash: ${JSON.stringify(Rn(P))}, json: ${JSON.stringify(Ae)} };
1207
- `,ce=P===void 0?"":", schemaSnapshot: LUNORA_SCHEMA_SNAPSHOT",{build:de,configField:Oe,contextField:Ie,stub:Ce}=wr(a),ue=Sr(i),H=kr(u),D=xr(p,L.flags),G=$r(s,p,L.flags),te=vr(l),pe=Rr(o),J=Tr(c),j=Nr(y),W=Ar(m),U=Or(d),B=Ir(x),ne=Cr(R),{build:Le,contextField:ve,importLines:Re,specs:he}=_r(A),{build:Ee,contextField:_e,importLines:Se,specs:me}=Lr(r,w.jurisdiction),{build:De,contextField:Pe,importLines:$e,specs:Me}=Er(V),{build:Fe,contextField:ge,importLines:fe,specs:Be}=Dr(n),{build:qe,configField:je,contextField:be,imports:ye,stub:Ze}=Fr(b),{build:h,configField:We,imports:Te,stub:re}=Br(S),Tt=e,Nt=t,At=C??{policies:[],roles:[]},Ot=N??{columns:[]},It=ie??{rules:[]},Ct=le??{analytics:!1,auth:!1,containers:!1,flags:!1,kv:!1,mail:!1,notifications:!1,payments:!1,queues:!1,scheduler:!1,storage:!1,vectors:!1,workflows:!1},{constant:Lt,override:Et}=Pr(V),{constant:_t,override:Dt}=Mr(A),K=v&&w.vectorIndexes.length>0,et=new Set(w.tables.filter(g=>typeof g.shardMode=="object"&&g.shardMode.kind==="shardBy").map(g=>g.name)),Ne=K&&w.vectorIndexes.some(g=>et.has(g.table)),we=w.tables.some(g=>g.shardMode==="global"),Ue=w.tables.some(g=>g.shardMode==="global"&&g.globalBackend==="hyperdrive"),tt=w.tables.some(g=>g.shardMode==="global"&&g.globalBackend!=="hyperdrive"),oe=w.tables.some(g=>g.externalSource!==void 0),nt=w.tables.some(g=>g.memory===!0),Ke=w.tables.some(g=>g.shardMode!=="global"&&g.searchIndexes.length>0);if(tt&&Ue)throw new X("INTERNAL",'lunora codegen: mixing `.global()` (D1) and `.global({ backend: "hyperdrive" })` tables in one app is not supported yet — use a single global backend.');const Qe=w.tables.length>0,Pt=ur(w),Mt=hr(w),Ft=br(w),Bt=pr(w),rt=mr(w),ot=qr(K,V.length>0,A.length>0,p,Ke);k&&ot.push("WhereInput");const at=yr(we),qt=k?`
1207
+ `,ce=P===void 0?"":", schemaSnapshot: LUNORA_SCHEMA_SNAPSHOT",{build:de,configField:Oe,contextField:Ie,stub:Ce}=wr(a),ue=Sr(i),H=kr(u),D=xr(h,L.flags),G=$r(s,h,L.flags),te=vr(l),he=Rr(o),J=Tr(c),j=Nr(y),W=Ar(m),U=Or(d),B=Ir(x),ne=Cr(R),{build:Le,contextField:ve,importLines:Re,specs:pe}=_r(A),{build:Ee,contextField:_e,importLines:Se,specs:me}=Lr(r,w.jurisdiction),{build:De,contextField:Pe,importLines:$e,specs:Me}=Er(V),{build:Fe,contextField:ge,importLines:fe,specs:Be}=Dr(n),{build:qe,configField:je,contextField:be,imports:ye,stub:Ze}=Fr(b),{build:p,configField:We,imports:Te,stub:re}=Br(S),Tt=e,Nt=t,At=C??{policies:[],roles:[]},Ot=N??{columns:[]},It=ie??{rules:[]},Ct=le??{analytics:!1,auth:!1,containers:!1,flags:!1,kv:!1,mail:!1,notifications:!1,payments:!1,queues:!1,scheduler:!1,storage:!1,vectors:!1,workflows:!1},{constant:Lt,override:Et}=Pr(V),{constant:_t,override:Dt}=Mr(A),K=v&&w.vectorIndexes.length>0,et=new Set(w.tables.filter(g=>typeof g.shardMode=="object"&&g.shardMode.kind==="shardBy").map(g=>g.name)),Ne=K&&w.vectorIndexes.some(g=>et.has(g.table)),we=w.tables.some(g=>g.shardMode==="global"),Ue=w.tables.some(g=>g.shardMode==="global"&&g.globalBackend==="hyperdrive"),tt=w.tables.some(g=>g.shardMode==="global"&&g.globalBackend!=="hyperdrive"),oe=w.tables.some(g=>g.externalSource!==void 0),nt=w.tables.some(g=>g.memory===!0),Ke=w.tables.some(g=>g.shardMode!=="global"&&g.searchIndexes.length>0);if(tt&&Ue)throw new X("INTERNAL",'lunora codegen: mixing `.global()` (D1) and `.global({ backend: "hyperdrive" })` tables in one app is not supported yet — use a single global backend.');const Qe=w.tables.length>0,Pt=ur(w),Mt=pr(w),Ft=br(w),Bt=hr(w),rt=mr(w),ot=qr(K,V.length>0,A.length>0,h,Ke);k&&ot.push("WhereInput");const at=yr(we),qt=k?`
1208
1208
  protected override resolveShape(name: string, args: Record<string, unknown>, identity?: { identity?: Record<string, unknown>; userId?: string }): { columns?: readonly string[]; effectiveWhere?: WhereInput; global?: boolean; table: string } | undefined {
1209
1209
  const shape = LUNORA_SHAPES[name];
1210
1210
 
@@ -1230,9 +1230,15 @@ const LUNORA_SCHEMA_SNAPSHOT: { hash: string; json: string } = { hash: ${JSON.st
1230
1230
  // procedure, so the \`.use(rls(...))\` middleware never fires; without
1231
1231
  // this merge its reads would bypass every read policy on the table
1232
1232
  // (rows the caller can't see would replicate). \`composeShapeReadWhere\`
1233
- // evaluates the table's read policies under this same trusted ctx —
1234
- // exactly the request-time path — and fails closed under a
1235
- // \`.rls("required")\` schema for a non-\`.public()\`, policy-less table.
1233
+ // evaluates the table's read policies under this same trusted ctx
1234
+ // and fails closed under a \`.rls("required")\` schema for a
1235
+ // non-\`.public()\`, policy-less table.
1236
+ //
1237
+ // It is NOT identical to the request-time path, and must not be
1238
+ // described as such: roles come from the identity's \`roles\` claim
1239
+ // only, because no middleware runs here to contribute
1240
+ // \`ctx.auth.roles\`. Derive roles at the identity if a policy gates
1241
+ // on them — see \`shape-read-base.ts\`.
1236
1242
  const effectiveWhere = composeShapeReadWhere(LUNORA_RLS_READ_REGISTRY, {
1237
1243
  ctx,
1238
1244
  identity: identity?.identity ?? null,
@@ -1260,7 +1266,7 @@ const LUNORA_SCHEMA_SNAPSHOT: { hash: string; json: string } = { hash: ${JSON.st
1260
1266
  protected override isCustomMutator(functionPath: string): boolean {
1261
1267
  return LUNORA_MUTATOR_PATHS.has(functionPath);
1262
1268
  }
1263
- `:"",Wt=k?"\n/** Per-table RLS read policies (hoisted from `.use(rls(...))` chains) the shape resolver AND-merges into each `defineShape` predicate so partial replication honours read policies. */\nconst LUNORA_RLS_READ_REGISTRY = buildRlsReadRegistry(Object.values(LUNORA_FUNCTIONS));\n":"",Ut=k?"assertShapeShardable, ":"",ke=[`import type { ${ot.join(", ")} } from "${L.do}";`,`import { applyCdcChanges, ${Ke?"backfillSearchIndexes, ":""}buildReprojectionMigration, ${nt?"clearMemoryTables, ":""}${Ut}createReadFootprint, createShardCtxDb, exportShardRows, importShardRows, ${oe?"isSourceDue, pullExternalSourceIncrementalTick, pullExternalSourceTick, ":""}markUnvouchableReads, ${Ne?"ROOT_SHARD_NAME, ":""}runDataMigration, runShardMigrations, ${at.importFragment}ShardDO as ShardDOBase } from "${L.do}";`,...oe?[`import type { ExternalSourceLike, SourceClientLike, TraceRefLike } from "${L.do}";`]:[],k?`import { asBucketStorage, beginDeferredSchedules, buildRlsReadRegistry, composeShapeReadWhere, createSecrets, flushDeferredDeletes, LunoraError, withDeferredDeletes, withDeferredSchedules } from "${L.server}";`:`import { asBucketStorage, beginDeferredSchedules, createSecrets, flushDeferredDeletes, LunoraError, withDeferredDeletes, withDeferredSchedules } from "${L.server}";`];Qe&&ke.push(`import { bindOrm, bindTableFacade } from "${L.server}";`),K&&ke.push('import type { SchemaLike as VectorSchemaLike, VectorizeIndexLike, VectorSearchLike } from "@lunora/bindings/vectors";','import { createContextVectors, createVectors, createVectorSyncHook } from "@lunora/bindings/vectors";'),a&&ke.push('import type { AiBindingLike, LunoraAi } from "@lunora/ai";','import { createAi } from "@lunora/ai";'),ke.push(...ue.importLines,...H.importLines,...D.importLines,...te.importLines,...pe.importLines,...J.importLines,...j.importLines,...W.importLines,...U.importLines,...B.importLines,...ne.importLines,...Se,...$e,...Re,...fe,...ye,...Te,"",'import schema from "../schema.js";',`import { ${["LUNORA_FUNCTIONS","LUNORA_LIFECYCLE_HOOKS","LUNORA_MIGRATIONS",...ee?["LUNORA_MUTATOR_PATHS"]:[],...k?["LUNORA_SHAPES"]:[]].join(", ")} } from "./functions.js";`);const Kt=K?`
1269
+ `:"",Wt=k?"\n/** Per-table RLS read policies (hoisted from `.use(rls(...))` chains) the shape resolver AND-merges into each `defineShape` predicate so partial replication honours read policies. */\nconst LUNORA_RLS_READ_REGISTRY = buildRlsReadRegistry(Object.values(LUNORA_FUNCTIONS));\n":"",Ut=k?"assertShapeShardable, ":"",ke=[`import type { ${ot.join(", ")} } from "${L.do}";`,`import { applyCdcChanges, ${Ke?"backfillSearchIndexes, ":""}buildReprojectionMigration, ${nt?"clearMemoryTables, ":""}${Ut}createReadFootprint, createShardCtxDb, exportShardRows, importShardRows, ${oe?"isSourceDue, pullExternalSourceIncrementalTick, pullExternalSourceTick, ":""}markUnvouchableReads, ${Ne?"ROOT_SHARD_NAME, ":""}runDataMigration, runShardMigrations, ${at.importFragment}ShardDO as ShardDOBase } from "${L.do}";`,...oe?[`import type { ExternalSourceLike, SourceClientLike, TraceRefLike } from "${L.do}";`]:[],k?`import { asBucketStorage, beginDeferredSchedules, buildRlsReadRegistry, composeShapeReadWhere, createSecrets, flushDeferredDeletes, LunoraError, withDeferredDeletes, withDeferredSchedules } from "${L.server}";`:`import { asBucketStorage, beginDeferredSchedules, createSecrets, flushDeferredDeletes, LunoraError, withDeferredDeletes, withDeferredSchedules } from "${L.server}";`];Qe&&ke.push(`import { bindOrm, bindTableFacade } from "${L.server}";`),K&&ke.push('import type { SchemaLike as VectorSchemaLike, VectorizeIndexLike, VectorSearchLike } from "@lunora/bindings/vectors";','import { createContextVectors, createVectors, createVectorSyncHook } from "@lunora/bindings/vectors";'),a&&ke.push('import type { AiBindingLike, LunoraAi } from "@lunora/ai";','import { createAi } from "@lunora/ai";'),ke.push(...ue.importLines,...H.importLines,...D.importLines,...te.importLines,...he.importLines,...J.importLines,...j.importLines,...W.importLines,...U.importLines,...B.importLines,...ne.importLines,...Se,...$e,...Re,...fe,...ye,...Te,"",'import schema from "../schema.js";',`import { ${["LUNORA_FUNCTIONS","LUNORA_LIFECYCLE_HOOKS","LUNORA_MIGRATIONS",...ee?["LUNORA_MUTATOR_PATHS"]:[],...k?["LUNORA_SHAPES"]:[]].join(", ")} } from "./functions.js";`);const Kt=K?`
1264
1270
  vectors?: (env: Record<string, unknown>) => Record<string, VectorizeIndexLike>;`:"",Qt=tt?`
1265
1271
  d1?: (env: Record<string, unknown>, request?: { bookmark?: string; cdc?: boolean; cdcRetentionMs?: number; identity?: Record<string, unknown>; onBookmark?: (bookmark: string | undefined) => void; userId?: string }) => DatabaseWriterLike | undefined;`:"",Vt=Ue?`
1266
1272
  hyperdriveGlobal?: (env: Record<string, unknown>, request?: { cdc?: boolean; cdcRetentionMs?: number; identity?: Record<string, unknown>; userId?: string }) => DatabaseWriterLike | undefined;`:"",Ht=oe?`
@@ -1408,14 +1414,14 @@ ${en}
1408
1414
  `:"",un=oe?`
1409
1415
  const sourceClientCache = new WeakMap<object, Map<string, SourceClientLike>>();
1410
1416
  const sourcePollAtCache = new WeakMap<object, Map<string, number>>();
1411
- `:"",pn=`
1417
+ `:"",hn=`
1412
1418
  protected override async runShardInit(): Promise<void> {
1413
1419
  this.ensureMigrated();
1414
1420
  ${nt?` clearMemoryTables(this.sql as SqlExec, schema as unknown as SchemaLike);
1415
1421
  `:""}
1416
1422
  await this.dispatchShardInit();
1417
1423
  }
1418
- `,hn=oe?`
1424
+ `,pn=oe?`
1419
1425
  protected override async pollExternalSources(trace?: TraceRefLike): Promise<number | undefined> {
1420
1426
  const env = (this.env ?? {}) as Record<string, unknown>;
1421
1427
  const sourced = Object.entries((schema as unknown as SchemaLike).tables)
@@ -1595,14 +1601,14 @@ ${oe?`
1595
1601
  const facade = db as unknown as Record<string, ReturnType<typeof bindTableFacade>>;
1596
1602
  ${w.tables.map(g=>` facade[${JSON.stringify(g.name)}] = bindTableFacade(db, ${JSON.stringify(g.name)});`).join(`
1597
1603
  `)}
1598
- `:"",bn=`${ue.build}${H.build}${D.build}${J.build}${pe.build}
1604
+ `:"",bn=`${ue.build}${H.build}${D.build}${J.build}${he.build}
1599
1605
  const secrets = createSecrets(env);
1600
- `,yn=`${ue.contextField}${H.contextField}${D.contextField}${te.contextField}${J.contextField}${pe.contextField}
1606
+ `,yn=`${ue.contextField}${H.contextField}${D.contextField}${te.contextField}${J.contextField}${he.contextField}
1601
1607
  secrets,`,wn=te.build,st=y||m||d||x||R||S,kn=st?`
1602
1608
  // ActionCtx-only helpers (external, non-deterministic I/O): constructed
1603
1609
  // and attached only for an \`action\` so query/mutation ctx never carry them.
1604
1610
  if (isAction) {
1605
- ${j.build}${W.build}${U.build}${B.build}${ne.build}${h}${[...y?[" ctx.images = images;"]:[],...m?[" ctx.sql = sql;"]:[],...d?[" ctx.browser = browser;"]:[],...x?[" ctx.r2sql = r2sql;"]:[],...R?[" ctx.pipelines = pipelines;"]:[],...S?[" ctx.x402 = x402;"]:[]].join(`
1611
+ ${j.build}${W.build}${U.build}${B.build}${ne.build}${p}${[...y?[" ctx.images = images;"]:[],...m?[" ctx.sql = sql;"]:[],...d?[" ctx.browser = browser;"]:[],...x?[" ctx.r2sql = r2sql;"]:[],...R?[" ctx.pipelines = pipelines;"]:[],...S?[" ctx.x402 = x402;"]:[]].join(`
1606
1612
  `)}
1607
1613
  }
1608
1614
  `:"",xn=st?` const isAction = LUNORA_FUNCTIONS[options.functionPath ?? ""]?.kind === "action";
@@ -1650,7 +1656,7 @@ const LUNORA_STORAGE_RULES: StorageRulesResult = ${JSON.stringify(It,void 0,4)};
1650
1656
 
1651
1657
  /** Which optional package-backed features this app wires up (discovered from imports / \`ctx.*\` reads / schema signals) served via \`__lunora_admin__:studioFeatures\` so the studio hides nav pages whose package isn't enabled. */
1652
1658
  const LUNORA_STUDIO_FEATURES: StudioFeaturesResult = ${JSON.stringify(Ct,void 0,4)};
1653
- ${F}${G.constant}${Wt}${Lt}${_t}${me}${Me}${he}${Be}
1659
+ ${F}${G.constant}${Wt}${Lt}${_t}${me}${Me}${pe}${Be}
1654
1660
  export interface ShardDOConfig {
1655
1661
  /** Opt into change-data-capture: records a post-image to \`__cdc_log\` on every write (backs streaming export + replay-PITR). */
1656
1662
  cdc?: boolean;
@@ -1932,11 +1938,11 @@ ${at.override}
1932
1938
  iterator: (signal) => (registered.handler as (context: unknown, args: Record<string, unknown>, signal: AbortSignal) => AsyncIterable<unknown>)(this.buildCtx({ functionPath, identity }), args, signal),
1933
1939
  };
1934
1940
  }
1935
- ${jt}${qt}${dn}${hn}
1941
+ ${jt}${qt}${dn}${pn}
1936
1942
  protected override lifecycleHookPaths(event: "connect" | "disconnect" | "init" | "reactor"): readonly string[] {
1937
1943
  return LUNORA_LIFECYCLE_HOOKS[event];
1938
1944
  }
1939
- ${pn}
1945
+ ${hn}
1940
1946
  // One \`onQueryChange\` dispatch. Mirrors \`executeSubscription\` — the
1941
1947
  // socket-terminated half of the same reactivity — and differs only in who
1942
1948
  // consumes the result: the base's \`dispatchReactors\` stores the digest as
@@ -2398,15 +2404,15 @@ ${n}
2398
2404
  }${r});`},Kr=e=>e.typeAnnotation?.includes('Id<"')??!1,Qr=(e,t)=>{const n=new Set(["integer","sqliteTable","text"]),r=new Set;let o=!1,s=!1;for(const i of e){for(const a of Object.values(i.shape)){const c=Xe(a);n.add(c.builder),s=s||Kr(c),o=o||$t(a,t)!==void 0}for(const a of i.indexes)r.add(a.unique?"uniqueIndex":"index")}return{columns:[...n].toSorted((i,a)=>i.localeCompare(a)),indexes:[...r].toSorted((i,a)=>i.localeCompare(a)),needsAnyColumn:o,needsId:s}},ct=(e,t=!1)=>{if(e.length===0)return`${$}export {};
2399
2405
  `;const n=ae(t),r=new Set(e.map(m=>m.name)),{columns:o,indexes:s,needsAnyColumn:i,needsId:a}=Qr(e,r),c=[...s,...o].toSorted((m,y)=>m.localeCompare(y)),d=e.map(m=>Ur(m,r)).join(`
2400
2406
 
2401
- `),p=[i?`import type { AnySQLiteColumn } from "${n.serverDrizzle}";
2407
+ `),h=[i?`import type { AnySQLiteColumn } from "${n.serverDrizzle}";
2402
2408
  `:"",a?`import type { Id } from "./dataModel.js";
2403
2409
  `:""].join("");return`${$}import { ${c.join(", ")} } from "${n.serverDrizzle}";
2404
- ${p}
2410
+ ${h}
2405
2411
  ${d}
2406
2412
  `},mo=(e,t=!1)=>{const n=e.tables.filter(o=>o.shardMode==="global"),r=e.tables.filter(o=>o.shardMode!=="global");return{global:E(ct(n,t),Je),shard:E(ct(r,t),Je)}},go=e=>{const t=new Map;for(const i of e){const a=t.get(i.cron);a?a.push(i):t.set(i.cron,[i])}const n=[...t.keys()].map(i=>` ${JSON.stringify(i)},`).join(`
2407
2413
  `),r=n.length>0?`
2408
2414
  ${n}
2409
- `:"",o=[...t.entries()].map(([i,a])=>{const c=a.map(d=>{const p=d.workflow?`workflow: ${JSON.stringify(d.workflow.binding)}`:`functionPath: ${JSON.stringify(d.functionPath)}`;return` { name: ${JSON.stringify(d.name)}, ${p}, args: ${JSON.stringify(d.args)} },`}).join(`
2415
+ `:"",o=[...t.entries()].map(([i,a])=>{const c=a.map(d=>{const h=d.workflow?`workflow: ${JSON.stringify(d.workflow.binding)}`:`functionPath: ${JSON.stringify(d.functionPath)}`;return` { name: ${JSON.stringify(d.name)}, ${h}, args: ${JSON.stringify(d.args)} },`}).join(`
2410
2416
  `);return` ${JSON.stringify(i)}: [
2411
2417
  ${c}
2412
2418
  ],`}).join(`
@@ -2461,4 +2467,4 @@ export interface LunoraVectorIndex {
2461
2467
  * \`createWorker({ vectorIntrospector })\` to back the studio's vector browser.
2462
2468
  */
2463
2469
  export const LUNORA_VECTOR_INDEXES: ReadonlyArray<LunoraVectorIndex> = [${n}];
2464
- `},bo=e=>[...new Set(e.map(t=>t.cron))];export{to as A,Sn as C,$ as G,Gn as U,ro as a,ao as b,lo as c,go as d,uo as e,no as f,mo as g,io as h,so as i,ho as j,fo as k,co as l,bo as m,pr as n,po as o,oo as p};
2470
+ `},bo=e=>[...new Set(e.map(t=>t.cron))];export{to as A,Sn as C,$ as G,Gn as U,ro as a,ao as b,lo as c,go as d,uo as e,no as f,mo as g,io as h,so as i,po as j,fo as k,co as l,bo as m,hr as n,ho as o,oo as p};