@lunora/codegen 1.0.0-alpha.335 → 1.0.0-alpha.337

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 (91) hide show
  1. package/dist/index.d.mts +26 -1
  2. package/dist/index.d.ts +26 -1
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/{AGENTS_FILENAME-8zoeGNsB.mjs → AGENTS_FILENAME-isdHqPIt.mjs} +1 -1
  5. package/dist/packem_shared/CONTAINERS_FILENAME-mK4cZpcz.mjs +1 -0
  6. package/dist/packem_shared/{DEFAULT_TARGET-CDksdcYc.mjs → DEFAULT_TARGET-3OLdJhTj.mjs} +1 -1
  7. package/dist/packem_shared/{FLAGS_FILENAME-Cwq0B2Nl.mjs → FLAGS_FILENAME-BQk3SX8D.mjs} +1 -1
  8. package/dist/packem_shared/GENERATED_HEADER-BXK9A_wP.mjs +1 -0
  9. package/dist/packem_shared/LUNORA_ERROR_CODES-CIAJQeKB.mjs +1 -0
  10. package/dist/packem_shared/{MUTATORS_FILENAME-DZFH7a9G.mjs → MUTATORS_FILENAME-Cy9h3EVW.mjs} +1 -1
  11. package/dist/packem_shared/{NOTIFY_FILENAME-DZIt-rb0.mjs → NOTIFY_FILENAME-9to_l_Kh.mjs} +1 -1
  12. package/dist/packem_shared/{OPENRPC_VERSION-CeEGdAZ9.mjs → OPENRPC_VERSION-l4HD4osw.mjs} +1 -1
  13. package/dist/packem_shared/{QUEUES_FILENAME-EvfCmmv6.mjs → QUEUES_FILENAME-Civ-7SiI.mjs} +1 -1
  14. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-6cfIWExE.mjs +31 -0
  15. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-C7Um0EnM.mjs +2 -0
  16. package/dist/packem_shared/{SHAPES_FILENAME-Ciu5tx7B.mjs → SHAPES_FILENAME-DVJbfDZ8.mjs} +1 -1
  17. package/dist/packem_shared/SchemaSnapshotParseError-H9eQX4ui.mjs +18 -0
  18. package/dist/packem_shared/{WORKFLOWS_FILENAME-C5tz9gMh.mjs → WORKFLOWS_FILENAME-kXq07aGl.mjs} +1 -1
  19. package/dist/packem_shared/{attribution-RI-H1KPm.mjs → attribution-CG8-kUcl.mjs} +1 -1
  20. package/dist/packem_shared/{buildOpenApiDocument-BBao-3vL.mjs → buildOpenApiDocument-DWdj2jvW.mjs} +1 -1
  21. package/dist/packem_shared/capabilitiesUsedBy-C-7D7vlH.mjs +1 -0
  22. package/dist/packem_shared/chain-74gjwZMP.mjs +1 -0
  23. package/dist/packem_shared/{classify-procedure-call-C5JY2w5V.mjs → classify-procedure-call-BkaeM9Ej.mjs} +1 -1
  24. package/dist/packem_shared/{context-property-calls-M6Oo1xQT.mjs → context-property-calls-dFjpeIlP.mjs} +1 -1
  25. package/dist/packem_shared/{context-root-DQd48e1F.mjs → context-root-CNR6TAsP.mjs} +1 -1
  26. package/dist/packem_shared/{createCodegenProject-C-fKC9h4.mjs → createCodegenProject-R4so-yTU.mjs} +1 -1
  27. package/dist/packem_shared/{database-calls-BNoSJRFy.mjs → database-calls-UPlhi3Ks.mjs} +1 -1
  28. package/dist/packem_shared/discoverAuthApiCalls-CScPrUD-.mjs +1 -0
  29. package/dist/packem_shared/discoverCrons-B1_NUt19.mjs +1 -0
  30. package/dist/packem_shared/{discoverFunctions-CJu5EH_G.mjs → discoverFunctions-DkPOc8b9.mjs} +1 -1
  31. package/dist/packem_shared/{discoverHttpRoutes-MrMxIY66.mjs → discoverHttpRoutes-DCDgDIYv.mjs} +1 -1
  32. package/dist/packem_shared/discoverHyperdriveCalls-CL-d0IVo.mjs +1 -0
  33. package/dist/packem_shared/{discoverInserts-Boh6WAYw.mjs → discoverInserts-BcoTjXqI.mjs} +1 -1
  34. package/dist/packem_shared/discoverMaskProcedures-Bw-BOIbA.mjs +1 -0
  35. package/dist/packem_shared/{discoverMigrations-BMdGxHeq.mjs → discoverMigrations-BWxx8Wv9.mjs} +1 -1
  36. package/dist/packem_shared/{discoverNondeterministicCalls-c9xenrIN.mjs → discoverNondeterministicCalls-3INW8oqs.mjs} +1 -1
  37. package/dist/packem_shared/{discoverQueries-o_00HnBB.mjs → discoverQueries-CxQRVuIV.mjs} +1 -1
  38. package/dist/packem_shared/discoverR2sqlCalls-B4oeTYEM.mjs +1 -0
  39. package/dist/packem_shared/{discoverRlsMetadata-C7J8dgVz.mjs → discoverRlsMetadata-D0B4nCmG.mjs} +1 -1
  40. package/dist/packem_shared/{discoverRlsProcedures-Di3VEk-D.mjs → discoverRlsProcedures-Cl6UKT7L.mjs} +1 -1
  41. package/dist/packem_shared/{discoverSandboxUsage-CrhZZJZS.mjs → discoverSandboxUsage--Z1vx7GM.mjs} +1 -1
  42. package/dist/packem_shared/discoverSchema-Cwt-DQgh.mjs +1 -0
  43. package/dist/packem_shared/{discoverStorageRulesMetadata-BFCmbsIN.mjs → discoverStorageRulesMetadata-CitX6ziW.mjs} +1 -1
  44. package/dist/packem_shared/{emitAgents-CR2_X_ov.mjs → emitAgents--VDKoet4.mjs} +1 -1
  45. package/dist/packem_shared/{emitApi-CDgIPAG2.mjs → emitApi-c14__tie.mjs} +24 -24
  46. package/dist/packem_shared/{emitApp-DuJW6LKD.mjs → emitApp-BL16wvE9.mjs} +1 -1
  47. package/dist/packem_shared/{emitCrons-BQW2lviZ.mjs → emitCrons-lc-hnJYn.mjs} +1 -1
  48. package/dist/packem_shared/{emitDataModel-BskFt9Wv.mjs → emitDataModel-CuFqq97x.mjs} +1 -1
  49. package/dist/packem_shared/{emitDrizzleSchema-DitcRZ1a.mjs → emitDrizzleSchema-bct1OuH5.mjs} +1 -1
  50. package/dist/packem_shared/{emitFunctions-Cd0Tuw73.mjs → emitFunctions-CkBPtGDF.mjs} +71 -65
  51. package/dist/packem_shared/{emitServer-D1vA5_X1.mjs → emitServer-CGUhLmlG.mjs} +1 -1
  52. package/dist/packem_shared/emitShard-fpKA7Svs.mjs +1 -0
  53. package/dist/packem_shared/{exported-procedure-chains-Bol_VtzO.mjs → exported-procedure-chains-D1WlRfqJ.mjs} +1 -1
  54. package/dist/packem_shared/{fingerprintSchemaSources-BdFj8vPc.mjs → fingerprintSchemaSources-BKXkgkj4.mjs} +1 -1
  55. package/dist/packem_shared/{handler-reference-8w_VU4XY.mjs → handler-reference-CClSR4bi.mjs} +1 -1
  56. package/dist/packem_shared/index-CN8FVvr-.mjs +1 -0
  57. package/dist/packem_shared/{isTestPath-Cdv_LoVU.mjs → isTestPath-C3QumE88.mjs} +1 -1
  58. package/dist/packem_shared/loadProjectConfig-B7RmxIeD.mjs +1 -0
  59. package/dist/packem_shared/{modules-DDIIcM7P.mjs → modules-l-Db0C4S.mjs} +1 -1
  60. package/dist/packem_shared/parse-validator-iVTounLK.mjs +1 -0
  61. package/dist/packem_shared/property-name-7cBlgK_O.mjs +1 -0
  62. package/dist/packem_shared/{qualifiers-DEdXn5wP.mjs → qualifiers-Bl5fSmav.mjs} +1 -1
  63. package/dist/packem_shared/readServiceBindings-BA49C6aN.mjs +1 -0
  64. package/dist/packem_shared/{server-DAvi_bv_.mjs → server-B6VhYK7m.mjs} +1 -1
  65. package/dist/packem_shared/{shard-CsfiXxV0.mjs → shard-BCqz_05A.mjs} +267 -142
  66. package/dist/packem_shared/{shard-runtime-BpoCV-aM.mjs → shard-runtime-ByYXjCKY.mjs} +10 -8
  67. package/dist/packem_shared/shared-8vTRkL2-.mjs +13 -0
  68. package/dist/packem_shared/{unwrap-handler-return-Bfz7lH0C.mjs → unwrap-handler-return-CGdJGvGh.mjs} +1 -1
  69. package/dist/sdk/index.mjs +15 -15
  70. package/package.json +9 -9
  71. package/dist/packem_shared/CONTAINERS_FILENAME-QiNt84QA.mjs +0 -1
  72. package/dist/packem_shared/GENERATED_HEADER-Ck_WOHzE.mjs +0 -1
  73. package/dist/packem_shared/LUNORA_ERROR_CODES-C2s0xWQD.mjs +0 -1
  74. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-V7LYutDl.mjs +0 -31
  75. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs +0 -2
  76. package/dist/packem_shared/SchemaSnapshotParseError-BRJT7c2k.mjs +0 -18
  77. package/dist/packem_shared/capabilitiesUsedBy-BC7ldWJI.mjs +0 -1
  78. package/dist/packem_shared/chain-C9qZxjM_.mjs +0 -1
  79. package/dist/packem_shared/discoverAuthApiCalls-GPzUN_-_.mjs +0 -1
  80. package/dist/packem_shared/discoverCrons-C1fKEf4g.mjs +0 -1
  81. package/dist/packem_shared/discoverHyperdriveCalls-VVJGsgxj.mjs +0 -1
  82. package/dist/packem_shared/discoverMaskProcedures-D3Tu8Q8Y.mjs +0 -1
  83. package/dist/packem_shared/discoverR2sqlCalls-D_H1v-UD.mjs +0 -1
  84. package/dist/packem_shared/discoverSchema-Bdmw34_P.mjs +0 -1
  85. package/dist/packem_shared/emitShard-DtfjUgjj.mjs +0 -1
  86. package/dist/packem_shared/index-BMMBKqsT.mjs +0 -1
  87. package/dist/packem_shared/loadProjectConfig-B0uxUGF-.mjs +0 -1
  88. package/dist/packem_shared/parse-validator-BqDQLzDZ.mjs +0 -1
  89. package/dist/packem_shared/project-config-file-CBY6llht.mjs +0 -1
  90. package/dist/packem_shared/readServiceBindings-4xlUucKw.mjs +0 -1
  91. package/dist/packem_shared/shared-DnCokNcE.mjs +0 -13
@@ -1,4 +1,4 @@
1
- import{agentComponent as N}from"@lunora/agent/component";import{LunoraError as R}from"@lunora/errors";import{r as d,a as w,b as v,c as L}from"./qualifiers-DEdXn5wP.mjs";import{a as P,r as y,p as $,G as x,b,c as m,d as S,e as j}from"./shared-DnCokNcE.mjs";import{s as h}from"./dispatch-namespace-DwTjD7BU.mjs";const O=t=>b(t,e=>{const r=d(y(e.args),e.filePath),n=d(L(e),e.filePath);return`${e.exportName}: FunctionReference<"${e.kind}", ${r}, ${n}>;`},"type"),A=(t,e)=>{if(t.length===0&&e.length===0)return{block:"",importLine:""};const r=[];let n="";if(t.length>0&&(n+="\n/** Params type carried by a `defineWorkflow` definition (its phantom `__params`). */\ntype WorkflowParamsOf<Definition> = Definition extends { __params?: infer Params } ? (unknown extends Params ? Record<string, unknown> : Params) : Record<string, unknown>;\n"),n+=`
1
+ import{agentComponent as N}from"@lunora/agent/component";import{LunoraError as R}from"@lunora/errors";import{r as d,a as w,b as P,c as L}from"./qualifiers-Bl5fSmav.mjs";import{a as A,r as y,p as $,G as x,b as k,c as m,d as S,e as j,i as v}from"./shared-8vTRkL2-.mjs";import{s as g}from"./dispatch-namespace-DwTjD7BU.mjs";const O=t=>k(t,e=>{const s=d(y(e.args),e.filePath),n=d(L(e),e.filePath),r=`FunctionReference<"${e.kind}", ${s}, ${n}>`;return`${e.exportName}: ${v(e)?`${r} & { readonly sensitive: true }`:r};`},"type"),I=(t,e)=>{if(t.length===0&&e.length===0)return{block:"",importLine:""};const s=[];let n="";if(t.length>0&&(n+="\n/** Params type carried by a `defineWorkflow` definition (its phantom `__params`). */\ntype WorkflowParamsOf<Definition> = Definition extends { __params?: infer Params } ? (unknown extends Params ? Record<string, unknown> : Params) : Record<string, unknown>;\n"),n+=`
2
2
  /** A typed reference to a durable workflow, addressable for \`cronJobs()\` targets. Mirrors \`@lunora/scheduler\`'s \`WorkflowReference\` structurally. */
3
3
  export interface WorkflowReference<Params = Record<string, unknown>> {
4
4
  readonly isLunoraWorkflow: true;
@@ -6,8 +6,8 @@ export interface WorkflowReference<Params = Record<string, unknown>> {
6
6
  readonly className: string;
7
7
  readonly name: string;
8
8
  }
9
- `,t.length>0){const s=[...t].toSorted((o,i)=>o.exportName.localeCompare(i.exportName)),a=s.map(o=>` ${o.exportName}: WorkflowReference<WorkflowParamsOf<typeof lunoraWorkflowDefinitions.${o.exportName}>>;`).join(`
10
- `),l=s.map(o=>` ${m(o.exportName)}: { isLunoraWorkflow: true, className: ${JSON.stringify(o.className)}, name: ${JSON.stringify(o.exportName)} },`).join(`
9
+ `,t.length>0){const r=[...t].toSorted((o,i)=>o.exportName.localeCompare(i.exportName)),a=r.map(o=>` ${o.exportName}: WorkflowReference<WorkflowParamsOf<typeof lunoraWorkflowDefinitions.${o.exportName}>>;`).join(`
10
+ `),l=r.map(o=>` ${m(o.exportName)}: { isLunoraWorkflow: true, className: ${JSON.stringify(o.className)}, name: ${JSON.stringify(o.exportName)} },`).join(`
11
11
  `);n+=`
12
12
  /** This project's durable workflows, addressable as typed references (e.g. \`crons.daily("digest", …, workflows.digestPipeline, params)\`). */
13
13
  export interface WorkflowsRef {
@@ -17,9 +17,9 @@ ${a}
17
17
  export const workflows: WorkflowsRef = {
18
18
  ${l}
19
19
  };
20
- `,r.push(`import type * as lunoraWorkflowDefinitions from "../workflows.js";
21
- `)}if(e.length>0){const s=[...e].toSorted((o,i)=>o.exportName.localeCompare(i.exportName)),a=s.map(o=>` ${o.exportName}: WorkflowReference<AgentRunInput>;`).join(`
22
- `),l=s.map(o=>` ${m(o.exportName)}: { isLunoraWorkflow: true, className: ${JSON.stringify(o.className)}, name: ${JSON.stringify(o.name)} },`).join(`
20
+ `,s.push(`import type * as lunoraWorkflowDefinitions from "../workflows.js";
21
+ `)}if(e.length>0){const r=[...e].toSorted((o,i)=>o.exportName.localeCompare(i.exportName)),a=r.map(o=>` ${o.exportName}: WorkflowReference<AgentRunInput>;`).join(`
22
+ `),l=r.map(o=>` ${m(o.exportName)}: { isLunoraWorkflow: true, className: ${JSON.stringify(o.className)}, name: ${JSON.stringify(o.name)} },`).join(`
23
23
  `);n+=`
24
24
  /** This project's durable agents, addressable as typed references for \`cronJobs()\` — each fire starts a fresh agent run (e.g. \`crons.daily("sweep", …, agents.support, { input, threadKey })\`). */
25
25
  export interface AgentsRef {
@@ -29,8 +29,8 @@ ${a}
29
29
  export const agents: AgentsRef = {
30
30
  ${l}
31
31
  };
32
- `,r.push(`import type { AgentRunInput } from "@lunora/agent";
33
- `)}return{block:n,importLine:r.join("")}},M=()=>Object.keys(N().functions).toSorted((t,e)=>t.localeCompare(e)),C=t=>new Set(t.filter(e=>h(e.filePath)==="agents").map(e=>e.exportName)),I=()=>new Set(Object.entries(N().functions).filter(([,t])=>t.visibility==="internal").map(([t])=>t)),U=(t,e)=>{const r={importLine:"",lines:"",prelude:""};if(t.length===0)return r;const n=C(e),s=I(),a=e.find(o=>h(o.filePath)==="agents"&&s.has(o.exportName));if(a)throw new R("INTERNAL",`@lunora/codegen: "agents:${a.exportName}" is reserved for the durable agent loop's internal dispatch — rename the "${a.exportName}" export in ${a.filePath}`);const l=M().filter(o=>!n.has(o));return l.length===0?r:{importLine:`import { agentComponent } from "@lunora/agent/component";
32
+ `,s.push(`import type { AgentRunInput } from "@lunora/agent";
33
+ `)}return{block:n,importLine:s.join("")}},M=()=>Object.keys(N().functions).toSorted((t,e)=>t.localeCompare(e)),T=t=>new Set(t.filter(e=>g(e.filePath)==="agents").map(e=>e.exportName)),K=()=>new Set(Object.entries(N().functions).filter(([,t])=>t.visibility==="internal").map(([t])=>t)),G=(t,e)=>{const s={importLine:"",lines:"",prelude:""};if(t.length===0)return s;const n=T(e),r=K(),a=e.find(o=>g(o.filePath)==="agents"&&r.has(o.exportName));if(a)throw new R("INTERNAL",`@lunora/codegen: "agents:${a.exportName}" is reserved for the durable agent loop's internal dispatch — rename the "${a.exportName}" export in ${a.filePath}`);const l=M().filter(o=>!n.has(o));return l.length===0?s:{importLine:`import { agentComponent } from "@lunora/agent/component";
34
34
  `,lines:l.map(o=>` "agents:${o}": lunoraAgentRuntimeFunctions.${o} as unknown as RegisteredLunoraFunction,`).join(`
35
35
  `),prelude:`
36
36
  /**
@@ -39,41 +39,41 @@ ${l}
39
39
  * subscribe to the public queries (\`agents:agentMessages\` is the live thread view).
40
40
  */
41
41
  const lunoraAgentRuntimeFunctions = agentComponent().functions;
42
- `}},V=(t,e)=>{if(!t)return{importLine:"",lines:"",prelude:""};const r=e.find(n=>h(n.filePath)==="sandbox"&&n.exportName==="invoke");if(r)throw new R("INTERNAL",`@lunora/codegen: "sandbox:invoke" is reserved for the batteries-included sandbox tool dispatcher (browserTool/containerTool) — rename the "invoke" export in ${r.filePath}`);return{importLine:`import { sandboxComponent } from "@lunora/agent/component";
43
- `,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"}},K=(t,e)=>{if(t.length===0)return[];const r=C(e),n=[{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 s of t)s.voice&&n.push({args:{threadKey:{kind:"string"}},exportName:`${s.exportName}Voice`,filePath:"agents",kind:"stream",returnType:"Record<string, unknown>"});return n.filter(s=>!r.has(s.exportName))},E=(t,e)=>{if(t.length===0)return[];const r=new Set(e.filter(n=>h(n.filePath)==="mutators").map(n=>n.exportName));return t.filter(n=>!r.has(n.exportName)).map(n=>({args:n.args,exportName:n.exportName,filePath:n.filePath,kind:"mutation",returnType:n.returnType}))},F=t=>{const e=t.flatMap(s=>s.channel?.kind==="room"?[s.channel.name]:[]);if(e.length===0)return{block:"",importLine:""};const r=e.map(s=>` ${m(s)}: RoomRef<LunoraRoomMessages[${JSON.stringify(s)}]>;`).join(`
44
- `),n=e.map(s=>` ${m(s)}: { name: ${JSON.stringify(s)} },`).join(`
42
+ `}},U=(t,e)=>{if(!t)return{importLine:"",lines:"",prelude:""};const s=e.find(n=>g(n.filePath)==="sandbox"&&n.exportName==="invoke");if(s)throw new R("INTERNAL",`@lunora/codegen: "sandbox:invoke" is reserved for the batteries-included sandbox tool dispatcher (browserTool/containerTool) — rename the "invoke" export in ${s.filePath}`);return{importLine:`import { sandboxComponent } from "@lunora/agent/component";
43
+ `,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"}},F=(t,e)=>{if(t.length===0)return[];const s=T(e),n=[{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:'"approve_for_thread"'},{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:{secret:{kind:"string",sensitive:!0},threadKey:{kind:"string"},toolCallId:{kind:"string"}},exportName:"agentSupplySecret",filePath:"agents",kind:"mutation",returnType:"{ resolved: boolean }"},{args:{threadKey:{kind:"string"},toolCallId:{kind:"string"}},exportName:"agentDeclineSecret",filePath:"agents",kind:"mutation",returnType:"{ resolved: boolean }"},{args:{threadKey:{kind:"string"}},exportName:"agentSecretRequests",filePath:"agents",kind:"query",returnType:'{ createdAt: number; expiresAt: number; label?: string; status: "consumed" | "declined" | "expired" | "pending" | "supplied"; toolCallId: string; toolName: string }[]'},{args:{key:{kind:"string"}},exportName:"agentApprovalGrants",filePath:"agents",kind:"query",returnType:"{ createdAt: number; toolName: string }[]"},{args:{threadKey:{kind:"string"},toolName:{kind:"string"}},exportName:"agentRevokeApprovalGrant",filePath:"agents",kind:"mutation",returnType:"{ revoked: 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 r of t)r.voice&&n.push({args:{threadKey:{kind:"string"}},exportName:`${r.exportName}Voice`,filePath:"agents",kind:"stream",returnType:"Record<string, unknown>"});return n.filter(r=>!s.has(r.exportName))},E=(t,e)=>{if(t.length===0)return[];const s=new Set(e.filter(n=>g(n.filePath)==="mutators").map(n=>n.exportName));return t.filter(n=>!s.has(n.exportName)).map(n=>({args:n.args,exportName:n.exportName,filePath:n.filePath,kind:"mutation",returnType:n.returnType}))},W=t=>{const e=t.flatMap(r=>r.channel?.kind==="room"?[r.channel.name]:[]);if(e.length===0)return{block:"",importLine:""};const s=e.map(r=>` ${m(r)}: RoomRef<LunoraRoomMessages[${JSON.stringify(r)}]>;`).join(`
44
+ `),n=e.map(r=>` ${m(r)}: { name: ${JSON.stringify(r)} },`).join(`
45
45
  `);return{block:`
46
46
  /** This project's \`defineRoom\` rooms, addressable as typed references for \`client.connectRoom\`. */
47
47
  export interface RoomsRef {
48
- ${r}
48
+ ${s}
49
49
  }
50
50
 
51
51
  export const rooms: RoomsRef = {
52
52
  ${n}
53
53
  };
54
54
  `,importLine:`import type { LunoraRoomMessages } from "./functions.js";
55
- `}},W=t=>{const e=t.filter(a=>a.stream);if(e.length===0)return{block:"",body:""};const r=b(e,a=>{const l=d(a.chunkType??"unknown",a.filePath),o=d(y(a.searchParams),a.filePath),i=d(y(a.params),a.filePath);return`${j(a.exportName)}: HttpStreamRef<${l}, ${o}, ${i}>;`},"type"),n=b(e,a=>`${m(a.exportName)}: { method: ${JSON.stringify(a.method)}, path: ${JSON.stringify(a.path)} },`,"value");return{block:`
55
+ `}},J=t=>{const e=t.filter(a=>a.stream);if(e.length===0)return{block:"",body:""};const s=k(e,a=>{const l=d(a.chunkType??"unknown",a.filePath),o=d(y(a.searchParams),a.filePath),i=d(y(a.params),a.filePath);return`${j(a.exportName)}: HttpStreamRef<${l}, ${o}, ${i}>;`},"type"),n=k(e,a=>`${m(a.exportName)}: { method: ${JSON.stringify(a.method)}, path: ${JSON.stringify(a.path)} },`,"value");return{block:`
56
56
  /** This project's HTTP-SSE stream routes (\`httpRoute.<verb>(path).stream()\`), addressable as typed references for \`client.httpStream\` / \`useHttpStream\`. */
57
57
  export interface HttpStreamsRef {
58
- ${r}
58
+ ${s}
59
59
  }
60
60
 
61
61
  export const httpStreams: HttpStreamsRef = {
62
62
  ${n}
63
63
  };
64
- `,body:r}},J=t=>b(t,e=>`${m(e.exportName)}: { __lunoraRef: ${JSON.stringify(`${h(e.filePath)}:${e.exportName}`)} },`,"value"),T=t=>{const{block:e="",constName:r,docComment:n="",functions:s,importLine:a="",typeName:l,typesBody:o="",useUmbrella:i}=t,c=O(s),p=J(s),u=w(`${c}
65
- ${o}`),k=u.length>0?`
64
+ `,body:s}},_=t=>k(t,e=>`${m(e.exportName)}: { __lunoraRef: ${JSON.stringify(`${g(e.filePath)}:${e.exportName}`)}${v(e)?", sensitive: true":""} },`,"value"),C=t=>{const{block:e="",constName:s,docComment:n="",functions:r,importLine:a="",typeName:l,typesBody:o="",useUmbrella:i}=t,c=O(r),p=_(r),u=w(`${c}
65
+ ${o}`),b=u.length>0?`
66
66
  import type { ${u.join(", ")} } from "./dataModel.js";
67
- `:"",g=[...c===""?[]:["FunctionReference"],...t.clientImports??[]],f=g.length>0?`import type { ${g.join(", ")} } from "${S(i).client}";
68
- `:"";return v(`${x}${f}${a}${k}
67
+ `:"",h=[...c===""?[]:["FunctionReference"],...t.clientImports??[]],f=h.length>0?`import type { ${h.join(", ")} } from "${S(i).client}";
68
+ `:"";return P(`${x}${f}${a}${b}
69
69
  ${n}export interface ${l} {${c?`
70
70
  ${c}
71
71
  `:""}}
72
72
 
73
- export const ${r}: ${l} = {${p?`
73
+ export const ${s}: ${l} = {${p?`
74
74
  ${p}
75
75
  `:""}};
76
- ${e}`,i)},z=t=>{const{agents:e=[],functions:r,httpRoutes:n=[],mutators:s=[],useUmbrella:a=!1,workflows:l=[]}=t,o=W(n),i=F(r),c=A(l,e);return T({block:`${c.block}${o.block}${i.block}`,clientImports:[...o.block===""?[]:["HttpStreamRef"],...i.block===""?[]:["RoomRef"]],constName:"api",functions:[...r.filter(p=>p.visibility!=="internal"),...K(e,r),...E(s,r)],importLine:`${c.importLine}${i.importLine}`,typeName:"ApiTypes",typesBody:o.body,useUmbrella:a})},G=t=>T({constName:"internal",docComment:"/** Internal functions — callable only server-side via `ctx.run*`, never from a client. */\n",functions:t.functions.filter(e=>e.visibility==="internal"),typeName:"InternalApiTypes",useUmbrella:t.useUmbrella??!1}),Q=t=>t?`${x}import { createSeedClient as createSeedClientBase } from "@lunora/seed";
76
+ ${e}`,i)},z=t=>{const{agents:e=[],functions:s,httpRoutes:n=[],mutators:r=[],useUmbrella:a=!1,workflows:l=[]}=t,o=J(n),i=W(s),c=I(l,e);return C({block:`${c.block}${o.block}${i.block}`,clientImports:[...o.block===""?[]:["HttpStreamRef"],...i.block===""?[]:["RoomRef"]],constName:"api",functions:[...s.filter(p=>p.visibility!=="internal"),...F(e,s),...E(r,s)],importLine:`${c.importLine}${i.importLine}`,typeName:"ApiTypes",typesBody:o.body,useUmbrella:a})},Q=t=>C({constName:"internal",docComment:"/** Internal functions — callable only server-side via `ctx.run*`, never from a client. */\n",functions:t.functions.filter(e=>e.visibility==="internal"),typeName:"InternalApiTypes",useUmbrella:t.useUmbrella??!1}),X=t=>t?`${x}import { createSeedClient as createSeedClientBase } from "@lunora/seed";
77
77
  import type { SeedClient, SeedClientOptions } from "@lunora/seed";
78
78
 
79
79
  import schema from "../schema.js";
@@ -90,9 +90,9 @@ import type { InsertModel } from "./dataModel.js";
90
90
  * const { posts } = await seed.posts((x) => x([10, 20]));
91
91
  */
92
92
  export const createSeedClient = (options?: SeedClientOptions): SeedClient<InsertModel> => createSeedClientBase<InsertModel>(schema, options);
93
- `:"",X=(t,e,r=!1)=>{if(t.length===0||!e)return"";const n=S(r),s=i=>i.table===void 0?"Row":`Doc<${JSON.stringify(i.table)}> & Row`,a=t.map(i=>{P(i.exportName,"shape export name");const c=s(i),p=d(y(i.args),i.filePath),u=Object.keys(i.args).length>0,k=u?` args: ${p};`:` args?: ${p};`,g=u?`(args: ${p}) => void`:`(args?: ${p}) => void`,f=`${i.exportName}CollectionOptions`;return`/** Options for the \`${i.exportName}\` shape binding. */
93
+ `:"",Y=(t,e,s=!1)=>{if(t.length===0||!e)return"";const n=S(s),r=i=>i.table===void 0?"Row":`Doc<${JSON.stringify(i.table)}> & Row`,a=t.map(i=>{A(i.exportName,"shape export name");const c=r(i),p=d(y(i.args),i.filePath),u=Object.keys(i.args).length>0,b=u?` args: ${p};`:` args?: ${p};`,h=u?`(args: ${p}) => void`:`(args?: ${p}) => void`,f=`${i.exportName}CollectionOptions`;return`/** Options for the \`${i.exportName}\` shape binding. */
94
94
  export interface ${$(f)} {
95
- ${k}
95
+ ${b}
96
96
  /**
97
97
  * Share the optimistic-overlay gate with other collections + mutators on this
98
98
  * shard. Defaults to the shared per-shard registry, which is almost always what
@@ -130,7 +130,7 @@ export const ${i.exportName}CollectionOptions = (options: ${$(f)}): LunoraCollec
130
130
  /** Live collection for the \`${i.exportName}\` shape, with its sync controls. */
131
131
  export const ${i.exportName}Collection = (
132
132
  options: ${$(f)},
133
- ): { checkpoints: CheckpointRegistry; collection: Collection<${c}, string>; scope: ${g} } => {
133
+ ): { checkpoints: CheckpointRegistry; collection: Collection<${c}, string>; scope: ${h} } => {
134
134
  const { checkpoints, config, scope } = ${i.exportName}CollectionOptions(options);
135
135
 
136
136
  return { checkpoints, collection: createCollection(config), scope };
@@ -144,4 +144,4 @@ import type { Collection } from "@tanstack/db";
144
144
  import { createCollection } from "@tanstack/db";
145
145
  ${o}
146
146
  ${a}
147
- `};export{z as emitApi,X as emitCollections,G as emitInternalApi,Q as emitSeed,U as renderAgentFunctionRegistry,V as renderSandboxFunctionRegistry};
147
+ `};export{z as emitApi,Y as emitCollections,Q as emitInternalApi,X as emitSeed,G as renderAgentFunctionRegistry,U as renderSandboxFunctionRegistry};
@@ -1,4 +1,4 @@
1
- import{APP_METHOD_CAPABILITIES as k}from"./CAPABILITY_PROBES-brcmKenl.mjs";import{i as S}from"./schema-BgM8A3XV.mjs";import{G as E}from"./shared-DnCokNcE.mjs";const D={configKey:"vectors",doc:"Wire the Vectorize index map backing `ctx.vectors`.",method:"vectors"},m=e=>[...k.filter(({key:r})=>e.capabilities.has(r)).map(({appMethod:r})=>r),...e.hasVectors?[D]:[]],g=e=>m(e).length>0,v=e=>(e.emailAgents?.length??0)>0,d=e=>e.tables.some(r=>S(r)),R=e=>e.hasScheduler?`
1
+ import{APP_METHOD_CAPABILITIES as k}from"./CAPABILITY_PROBES-brcmKenl.mjs";import{i as S}from"./schema-BgM8A3XV.mjs";import{G as E}from"./shared-8vTRkL2-.mjs";const D={configKey:"vectors",doc:"Wire the Vectorize index map backing `ctx.vectors`.",method:"vectors"},m=e=>[...k.filter(({key:r})=>e.capabilities.has(r)).map(({appMethod:r})=>r),...e.hasVectors?[D]:[]],g=e=>m(e).length>0,v=e=>(e.emailAgents?.length??0)>0,d=e=>e.tables.some(r=>S(r)),R=e=>e.hasScheduler?`
2
2
  /** Resolve the \`SchedulerDO\`-backed scheduler for this env; \`undefined\` until the namespace is wired. */
3
3
  private resolveScheduler(env: Env): ReturnType<typeof createScheduler> | undefined {
4
4
  const namespace = this.schedulerDeclaration?.namespace(env);
@@ -1,4 +1,4 @@
1
- import{G as i,d as c}from"./shared-DnCokNcE.mjs";import{i as m}from"./schema-BgM8A3XV.mjs";const u=r=>r?`${i}/**
1
+ import{G as i,d as c}from"./shared-8vTRkL2-.mjs";import{i as m}from"./schema-BgM8A3XV.mjs";const u=r=>r?`${i}/**
2
2
  * The \`SchedulerDO\` Durable Object class, re-exported so a worker entry can
3
3
  * forward it — wrangler binds only what the entry exports:
4
4
  *
@@ -1,4 +1,4 @@
1
- import{r as k}from"./qualifiers-DEdXn5wP.mjs";import{a as i,e as o,v as d,f as v,G as M}from"./shared-DnCokNcE.mjs";const _="schema",w=a=>{for(const e of a.tables)i(e.name,"table name");const l=a.tables.map(e=>`"${e.name}"`).join(" | ")||"never",m=a.tables.filter(e=>e.extensionKey===void 0).map(e=>`"${e.name}"`).join(" | ")||"never",p=a.tables.map(e=>{const t=Object.entries(e.shape).map(([g,r])=>{const s=o(g);if(r.kind==="optional"){const h=r.inner?d(r.inner):"unknown";return` ${s}?: ${h};`}return` ${s}: ${d(r)};`}).join(`
1
+ import{r as k}from"./qualifiers-Bl5fSmav.mjs";import{a as i,e as o,v as d,f as v,G as M}from"./shared-8vTRkL2-.mjs";const _="schema",w=a=>{for(const e of a.tables)i(e.name,"table name");const l=a.tables.map(e=>`"${e.name}"`).join(" | ")||"never",m=a.tables.filter(e=>e.extensionKey===void 0).map(e=>`"${e.name}"`).join(" | ")||"never",p=a.tables.map(e=>{const t=Object.entries(e.shape).map(([g,r])=>{const s=o(g);if(r.kind==="optional"){const h=r.inner?d(r.inner):"unknown";return` ${s}?: ${h};`}return` ${s}: ${d(r)};`}).join(`
2
2
  `),n=t?`
3
3
  ${t}
4
4
  `:"",N=e.commitOrdered===!0?`
@@ -1,4 +1,4 @@
1
- import{SCHEMA_MODULE_PATH as c}from"./emitDataModel-BskFt9Wv.mjs";import{r as m}from"./qualifiers-DEdXn5wP.mjs";import{G as b,a as z,d as T,v as f,u as A,g as x,c as h}from"./shared-DnCokNcE.mjs";const d=e=>{switch(e.kind){case"array":case"object":case"record":case"union":return{builder:"text",mode:"json",notNull:!0,typeAnnotation:f(e)};case"bigint":return{builder:"blob",mode:"bigint",notNull:!0};case"boolean":return{builder:"integer",mode:"boolean",notNull:!0};case"bytes":return{builder:"blob",mode:"buffer",notNull:!0};case"date":case"timestamp":return{builder:"integer",notNull:!0};case"from":return{builder:"text",notNull:!0,typeAnnotation:f(e)};case"id":return{builder:"text",notNull:!0};case"literal":{const t=e.literalValue??"";return t.startsWith('"')||t.startsWith("'")?{builder:"text",notNull:!0}:t==="true"||t==="false"?{builder:"integer",mode:"boolean",notNull:!0}:t==="null"?{builder:"text",notNull:!0}:{builder:"real",notNull:!0}}case"null":return{builder:"text",notNull:!0};case"number":return{builder:"real",notNull:!0};case"optional":return{...e.inner?d(e.inner):{builder:"text",notNull:!1},notNull:!1};case"storage":case"string":return{builder:"text",notNull:!0};default:return{builder:"text",notNull:!0}}},N=(e,t)=>{const r=A(e);return r.kind==="id"&&r.tableName!==void 0&&t.has(r.tableName)?r.tableName:void 0},j=(e,t,r)=>{x(e,"drizzle column name");const n=d(t),o=n.mode?`, { mode: "${n.mode}" }`:"";let l=`${n.builder}("${e}"${o})`;n.typeAnnotation&&(l+=`.$type<${n.typeAnnotation}>()`);const s=N(t,r);return s!==void 0&&(l+=`.references((): AnySQLiteColumn => ${s}._id)`),n.notNull&&t.column?.notNull!==!1&&(l+=".notNull()"),l},I=e=>{const t=e.unique?"uniqueIndex":"index",r=e.fields.map(n=>(x(n,"drizzle index field"),`t.${n}`)).join(", ");return` ${h(e.name)}: ${t}(${JSON.stringify(e.name)}).on(${r}),`},S=(e,t)=>{z(e.name,"table name");const r=[' _id: text("_id").primaryKey(),',' _creationTime: integer("_creationTime").notNull(),',...Object.entries(e.shape).map(([o,l])=>` ${o}: ${j(o,l,t)},`)].join(`
1
+ import{SCHEMA_MODULE_PATH as c}from"./emitDataModel-CuFqq97x.mjs";import{r as m}from"./qualifiers-Bl5fSmav.mjs";import{G as b,a as z,d as T,v as f,u as A,g as x,c as h}from"./shared-8vTRkL2-.mjs";const d=e=>{switch(e.kind){case"array":case"object":case"record":case"union":return{builder:"text",mode:"json",notNull:!0,typeAnnotation:f(e)};case"bigint":return{builder:"blob",mode:"bigint",notNull:!0};case"boolean":return{builder:"integer",mode:"boolean",notNull:!0};case"bytes":return{builder:"blob",mode:"buffer",notNull:!0};case"date":case"timestamp":return{builder:"integer",notNull:!0};case"from":return{builder:"text",notNull:!0,typeAnnotation:f(e)};case"id":return{builder:"text",notNull:!0};case"literal":{const t=e.literalValue??"";return t.startsWith('"')||t.startsWith("'")?{builder:"text",notNull:!0}:t==="true"||t==="false"?{builder:"integer",mode:"boolean",notNull:!0}:t==="null"?{builder:"text",notNull:!0}:{builder:"real",notNull:!0}}case"null":return{builder:"text",notNull:!0};case"number":return{builder:"real",notNull:!0};case"optional":return{...e.inner?d(e.inner):{builder:"text",notNull:!1},notNull:!1};case"storage":case"string":return{builder:"text",notNull:!0};default:return{builder:"text",notNull:!0}}},N=(e,t)=>{const r=A(e);return r.kind==="id"&&r.tableName!==void 0&&t.has(r.tableName)?r.tableName:void 0},j=(e,t,r)=>{x(e,"drizzle column name");const n=d(t),o=n.mode?`, { mode: "${n.mode}" }`:"";let l=`${n.builder}("${e}"${o})`;n.typeAnnotation&&(l+=`.$type<${n.typeAnnotation}>()`);const s=N(t,r);return s!==void 0&&(l+=`.references((): AnySQLiteColumn => ${s}._id)`),n.notNull&&t.column?.notNull!==!1&&(l+=".notNull()"),l},I=e=>{const t=e.unique?"uniqueIndex":"index",r=e.fields.map(n=>(x(n,"drizzle index field"),`t.${n}`)).join(", ");return` ${h(e.name)}: ${t}(${JSON.stringify(e.name)}).on(${r}),`},S=(e,t)=>{z(e.name,"table name");const r=[' _id: text("_id").primaryKey(),',' _creationTime: integer("_creationTime").notNull(),',...Object.entries(e.shape).map(([o,l])=>` ${o}: ${j(o,l,t)},`)].join(`
2
2
  `),n=e.indexes.length>0?`, (t) => ({
3
3
  ${e.indexes.map(o=>I(o)).join(`
4
4
  `)}
@@ -1,30 +1,30 @@
1
- import{LunoraError as P}from"@lunora/errors";import{L as ce,G as j,d as D,I as T,b as M,r as le,c as ue}from"./shared-DnCokNcE.mjs";import{renderAgentFunctionRegistry as de,renderSandboxFunctionRegistry as he}from"./emitApi-CDgIPAG2.mjs";import{b as pe,a as me,r as I,c as ge}from"./qualifiers-DEdXn5wP.mjs";import{s as g}from"./dispatch-namespace-DwTjD7BU.mjs";const fe=new Set(["any","bigint","boolean","date","id","null","number","storage","string","timestamp"]),U=r=>r.column!==void 0,ye=(r,t)=>{switch(r){case"bigint":return`if (typeof ${t} !== "bigint") return DEFER;
1
+ import{LunoraError as A}from"@lunora/errors";import{L as de,s as j,G as D,d as U,I as T,b as M,r as he,c as me}from"./shared-8vTRkL2-.mjs";import{v as pe}from"./parse-validator-iVTounLK.mjs";import{renderAgentFunctionRegistry as ge,renderSandboxFunctionRegistry as fe}from"./emitApi-c14__tie.mjs";import{b as ye,a as $e,r as I,c as we}from"./qualifiers-Bl5fSmav.mjs";import{s as g}from"./dispatch-namespace-DwTjD7BU.mjs";const ke=new Set(["any","bigint","boolean","date","id","null","number","storage","string","timestamp"]),J=r=>r.column!==void 0,Re=(r,t)=>{switch(r){case"bigint":return`if (typeof ${t} !== "bigint") return DEFER;
2
2
  `;case"boolean":return`if (typeof ${t} !== "boolean") return DEFER;
3
3
  `;case"date":case"number":case"timestamp":return`if (typeof ${t} !== "number" || !Number.isFinite(${t})) return DEFER;
4
4
  `;case"null":return`if (${t} !== null) return DEFER;
5
5
  `;default:return`if (typeof ${t} !== "string") return DEFER;
6
- `}},$e=(r,t)=>r.stringMaxLength===void 0?"":`if (${t}.length > ${String(r.stringMaxLength)}) return DEFER;
7
- `,we=(r,t)=>{const n=r.literalValue?.trim();if(!(n===void 0||!ce.test(n)))return{out:t,pre:`if (${t} !== ${n}) return DEFER;
8
- `}},E=(r,t,n)=>{if(!U(r)&&!(r.unmodelledRefinement||r.sourceText!==void 0)){if(fe.has(r.kind))return r.kind==="any"?{out:t,pre:""}:{out:t,pre:ye(r.kind,t)+$e(r,t)};switch(r.kind){case"array":return Re(r,t,n);case"literal":return we(r,t);case"object":return Ne(r,t,n);default:return}}},Re=(r,t,n)=>{const{inner:o}=r;if(!o)return;const a=n.next(),i=`__arr${String(a)}`,s=`__i${String(a)}`,c=`__e${String(a)}`,d=E(o,c,n);if(!d)return;const l=`if (!Array.isArray(${t})) return DEFER;
6
+ `}},be=(r,t)=>r.stringMaxLength===void 0?"":`if (${t}.length > ${String(r.stringMaxLength)}) return DEFER;
7
+ `,ve=(r,t)=>{const n=r.literalValue?.trim();if(!(n===void 0||!de.test(n)))return{out:t,pre:`if (${t} !== ${n}) return DEFER;
8
+ `}},F=(r,t,n)=>{if(!J(r)&&!(r.unmodelledRefinement||r.sourceText!==void 0)){if(ke.has(r.kind))return r.kind==="any"?{out:t,pre:""}:{out:t,pre:Re(r.kind,t)+be(r,t)};switch(r.kind){case"array":return Ne(r,t,n);case"literal":return ve(r,t);case"object":return Pe(r,t,n);default:return}}},Ne=(r,t,n)=>{const{inner:o}=r;if(!o)return;const a=n.next(),i=`__arr${String(a)}`,s=`__i${String(a)}`,c=`__e${String(a)}`,d=F(o,c,n);if(!d)return;const l=`if (!Array.isArray(${t})) return DEFER;
9
9
  const ${i} = new Array(${t}.length);
10
10
  for (let ${s} = 0; ${s} < ${t}.length; ${s}++) {
11
11
  const ${c} = ${t}[${s}];
12
12
  ${d.pre}${i}[${s}] = ${d.out};
13
13
  }
14
- `;return{out:i,pre:l}},ke=(r,t,n,o)=>{const a=JSON.stringify(r);if(t.kind==="optional"){if(t.hasRefinement||t.sourceText!==void 0||U(t))return;const{inner:s}=t;if(!s)return;const c=E(s,n,o);if(!c)return;const d=o.next(),l=`__has${String(d)}`,u=`__val${String(d)}`,f=`let ${l} = false;
14
+ `;return{out:i,pre:l}},Oe=(r,t,n,o)=>{const a=JSON.stringify(r);if(t.kind==="optional"){if(t.hasRefinement||t.sourceText!==void 0||J(t))return;const{inner:s}=t;if(!s)return;const c=F(s,n,o);if(!c)return;const d=o.next(),l=`__has${String(d)}`,u=`__val${String(d)}`,f=`let ${l} = false;
15
15
  let ${u};
16
16
  if (${n} !== undefined) {
17
17
  ${c.pre}${u} = ${c.out};
18
18
  ${l} = true;
19
19
  }
20
- `;return{entry:`...(${l} ? { ${a}: ${u} } : {})`,pre:f}}const i=E(t,n,o);if(i)return{entry:`${a}: ${i.out}`,pre:i.pre}},be=new Set(Object.getOwnPropertyNames(Object.prototype)),J=(r,t,n)=>{let o="";const a=[];for(const i of Object.keys(r)){const s=r[i];if(!s)return;const c=JSON.stringify(i);let d=`${t}[${c}]`;if(be.has(i)){const u=`__f${String(n.next())}`;o+=`const ${u} = Object.hasOwn(${t}, ${c}) ? ${t}[${c}] : undefined;
21
- `,d=u}const l=ke(i,s,d,n);if(!l)return;o+=l.pre,a.push(l.entry)}return{entries:a.join(", "),pre:o}},B=r=>{const t=`Object.getPrototypeOf(${r})`;return`if (${t} !== Object.prototype && ${t} !== null) return DEFER;
22
- `},Ne=(r,t,n)=>{const o=r.shape??{},a=J(o,t,n);if(!a)return;const i=n.next(),s=`__obj${String(i)}`,c=`if (typeof ${t} !== "object" || ${t} === null || Array.isArray(${t})) return DEFER;
23
- ${B(t)}${a.pre}const ${s} = { ${a.entries} };
24
- `;return{out:s,pre:c}},q=r=>{let t=0;const o=J(r,"source",{next:()=>(t+=1,t)});if(o)return`(source) => {
20
+ `;return{entry:`...(${l} ? { ${a}: ${u} } : {})`,pre:f}}const i=F(t,n,o);if(i)return{entry:`${a}: ${i.out}`,pre:i.pre}},Se=new Set(Object.getOwnPropertyNames(Object.prototype)),B=(r,t,n)=>{let o="";const a=[];for(const i of Object.keys(r)){const s=r[i];if(!s)return;const c=JSON.stringify(i);let d=`${t}[${c}]`;if(Se.has(i)){const u=`__f${String(n.next())}`;o+=`const ${u} = Object.hasOwn(${t}, ${c}) ? ${t}[${c}] : undefined;
21
+ `,d=u}const l=Oe(i,s,d,n);if(!l)return;o+=l.pre,a.push(l.entry)}return{entries:a.join(", "),pre:o}},q=r=>{const t=`Object.getPrototypeOf(${r})`;return`if (${t} !== Object.prototype && ${t} !== null) return DEFER;
22
+ `},Pe=(r,t,n)=>{const o=r.shape??{},a=B(o,t,n);if(!a)return;const i=n.next(),s=`__obj${String(i)}`,c=`if (typeof ${t} !== "object" || ${t} === null || Array.isArray(${t})) return DEFER;
23
+ ${q(t)}${a.pre}const ${s} = { ${a.entries} };
24
+ `;return{out:s,pre:c}},H=r=>{let t=0;const o=B(r,"source",{next:()=>(t+=1,t)});if(o)return`(source) => {
25
25
  if (typeof source !== "object" || source === null || Array.isArray(source)) return DEFER;
26
- ${B("source")}${o.pre}return { ${o.entries} };
27
- }`},ve=(r,t)=>`lunora_${g(r)}_${String(t)}`,C=r=>JSON.stringify(Object.entries(r).toSorted(([t],[n])=>t.localeCompare(n)).map(([t,n])=>{const o=n.kind==="optional",a=o?n.inner??{kind:"unknown"}:n,i=a.kind==="array"?a.inner?.kind:void 0,s=a.kind==="id"?a.tableName:void 0;return{kind:a.kind,name:t,optional:o,...s===void 0?{}:{table:s},...i===void 0||i==="unknown"?{}:{element:i}}})),H=(r,t,n,o)=>{const a=new Map,i=s=>{a.has(s)||a.set(s,ve(s,a.size))};for(const s of r)i(s.filePath);for(const s of t)i(s.filePath);for(const s of n)i(s.filePath);for(const s of o)i(s.filePath);return a},z=(r,t,n)=>new Set([...r.map(o=>o.filePath),...t.map(o=>o.filePath),...n.map(o=>o.filePath)]),N=r=>`${r}[functionPath]`,Oe=`const callRegistered = async <R>(context: CallerCtx, functionPath: string, args: Record<string, unknown> | undefined): Promise<R> => {
26
+ ${q("source")}${o.pre}return { ${o.entries} };
27
+ }`},xe=(r,t)=>`lunora_${g(r)}_${String(t)}`,C=r=>JSON.stringify(Object.entries(r).toSorted(([t],[n])=>t.localeCompare(n)).map(([t,n])=>{const o=n.kind==="optional",a=o?n.inner??{kind:"unknown"}:n,i=a.kind==="array"?a.inner?.kind:void 0,s=a.kind==="id"?a.tableName:void 0;return{kind:a.kind,name:t,optional:o,...pe(n)?{sensitive:!0}:{},...s===void 0?{}:{table:s},...i===void 0||i==="unknown"?{}:{element:i}}})),z=(r,t,n,o)=>{const a=new Map,i=s=>{a.has(s)||a.set(s,xe(s,a.size))};for(const s of r)i(s.filePath);for(const s of t)i(s.filePath);for(const s of n)i(s.filePath);for(const s of o)i(s.filePath);return a},W=(r,t,n)=>new Set([...r.map(o=>o.filePath),...t.map(o=>o.filePath),...n.map(o=>o.filePath)]),N=r=>`${r}[functionPath]`,Ae=`const callRegistered = async <R>(context: CallerCtx, functionPath: string, args: Record<string, unknown> | undefined): Promise<R> => {
28
28
  const registered = await loadFunction(functionPath);
29
29
 
30
30
  if (!registered) {
@@ -57,29 +57,29 @@ ${B("source")}${o.pre}return { ${o.entries} };
57
57
  }
58
58
 
59
59
  return (await registered.handler(context, args ?? {})) as R;
60
- };`,Se=(r,t,n=[],o=[],a=!1)=>{const i=H(r,t,n,o),s=z(t,n,o),c=[...i.entries()].filter(([e])=>!a||s.has(e)?!0:r.some(p=>p.filePath===e&&p.channel?.kind==="room")).map(([e,p])=>{if(!T.test(e))throw new P("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(e)}`);return`import ${a&&!s.has(e)?"type ":""}* as ${p} from "../${e}.js";`}).join(`
61
- `),d=r.map(e=>!a||s.has(e.filePath)?` "${g(e.filePath)}:${e.exportName}": ${i.get(e.filePath)??""}.${e.exportName} as unknown as RegisteredLunoraFunction,`:` "${g(e.filePath)}:${e.exportName}": { args: {}, handler: unloadedFunctionHandler, ...${JSON.stringify({argumentDescriptors:JSON.parse(C(e.args)),kind:e.kind,...e.channel?{channel:e.channel}:{},...e.expose?{expose:e.expose}:{},...e.lifecycle?{lifecycle:e.lifecycle}:{},...e.visibility?{visibility:e.visibility}:{},...e.x402?.price===void 0?{}:{x402:{price:e.x402.price}},...e.socket===void 0?{}:{auth:e.socket.auth,socketPath:e.socket.path}})} } satisfies RegisteredLunoraFunction & Pick<FunctionManifestEntry, "argumentDescriptors" | "channel" | "expose">,`).join(`
60
+ };`,Le=(r,t,n=[],o=[],a=!1)=>{const i=z(r,t,n,o),s=W(t,n,o),c=[...i.entries()].filter(([e])=>!a||s.has(e)?!0:r.some(m=>m.filePath===e&&m.channel?.kind==="room")).map(([e,m])=>{if(!T.test(e))throw new A("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(e)}`);return`import ${a&&!s.has(e)?"type ":""}* as ${m} from "../${e}.js";`}).join(`
61
+ `),d=r.map(e=>{if(!a||s.has(e.filePath))return` "${g(e.filePath)}:${e.exportName}": ${i.get(e.filePath)??""}.${e.exportName} as unknown as RegisteredLunoraFunction,`;const m=j(e.args);return` "${g(e.filePath)}:${e.exportName}": { args: {}, handler: unloadedFunctionHandler, ...${JSON.stringify({argumentDescriptors:JSON.parse(C(e.args)),kind:e.kind,...m.length===0?{}:{sensitiveArgs:m},...e.channel?{channel:e.channel}:{},...e.expose?{expose:e.expose}:{},...e.lifecycle?{lifecycle:e.lifecycle}:{},...e.visibility?{visibility:e.visibility}:{},...e.x402?.price===void 0?{}:{x402:{price:e.x402.price}},...e.socket===void 0?{}:{auth:e.socket.auth,socketPath:e.socket.path}})} } satisfies RegisteredLunoraFunction & Pick<FunctionManifestEntry, "argumentDescriptors" | "channel" | "expose">,`}).join(`
62
62
  `),l=t.map(e=>` ${JSON.stringify(e.id)}: ${i.get(e.filePath)??""}.${e.exportName} as unknown as RegisteredDataMigration,`).join(`
63
63
  `),u=n.map(e=>` "${g(e.filePath)}:${e.exportName}": ${i.get(e.filePath)??""}.${e.exportName} as unknown as RegisteredLunoraFunction,`).join(`
64
64
  `),f=o.map(e=>` "${e.exportName}": ${i.get(e.filePath)??""}.${e.exportName} as unknown as RegisteredShape,`).join(`
65
65
  `),$=n.map(e=>`${g(e.filePath)}:${e.exportName}`),y=[d,u].filter(e=>e.length>0).join(`
66
- `),v=r.filter(e=>!a||s.has(e.filePath)).map(e=>{if(e.lifecycle||Object.keys(e.args).length===0)return;const p=q(e.args);return p===void 0?void 0:`installCompiledValidatorMap(${i.get(e.filePath)??""}.${e.exportName}.args, ${p});`}).filter(e=>e!==void 0).join(`
67
- `),O=r.filter(e=>e.channel?.kind==="room").map(e=>` ${JSON.stringify(e.channel?.name??"")}: RoomMessageOf<typeof ${i.get(e.filePath)??""}[${JSON.stringify(e.exportName)}]>;`).join(`
68
- `),k=[...r.map(e=>({args:e.args,definition:e,path:`${g(e.filePath)}:${e.exportName}`})),...n.map(e=>({args:e.args,definition:{...e,expose:void 0,kind:"mutation",lifecycle:void 0,visibility:void 0,x402:void 0},path:`${g(e.filePath)}:${e.exportName}`}))],S=a?k.filter(({definition:e})=>!s.has(e.filePath)):[];for(const{definition:e}of k)if(a&&e.x402&&e.x402.price===void 0)throw new P("INTERNAL",`@lunora/codegen: lazy function registry needs a literal \`.x402({ price })\` value in ${e.filePath}:${e.exportName}`);const b=a?S.map(({definition:e,path:p})=>{const R=i.get(e.filePath)??"",x="channel"in e?e.channel:void 0,A={argumentDescriptors:JSON.parse(C(e.args)),exportName:e.exportName,kind:e.kind,moduleId:R,...x?{channel:x}:{},...e.expose?{expose:e.expose}:{},...e.lifecycle?{lifecycle:e.lifecycle}:{},...e.visibility?{visibility:e.visibility}:{},...e.x402?.price===void 0?{}:{x402:{price:e.x402.price}}};return` ${JSON.stringify(p)}: ${JSON.stringify(A)},`}).join(`
69
- `):"",h=[...new Set(S.map(({definition:e})=>e.filePath))],w=a?h.map(e=>{if(!T.test(e))throw new P("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(e)}`);const p=i.get(e)??"";return` ${JSON.stringify(p)}: () => import(${JSON.stringify(`./fn/${p}.js`)}),`}).join(`
66
+ `),O=r.filter(e=>!a||s.has(e.filePath)).map(e=>{if(e.lifecycle||Object.keys(e.args).length===0)return;const m=H(e.args);return m===void 0?void 0:`installCompiledValidatorMap(${i.get(e.filePath)??""}.${e.exportName}.args, ${m});`}).filter(e=>e!==void 0).join(`
67
+ `),S=r.filter(e=>e.channel?.kind==="room").map(e=>` ${JSON.stringify(e.channel?.name??"")}: RoomMessageOf<typeof ${i.get(e.filePath)??""}[${JSON.stringify(e.exportName)}]>;`).join(`
68
+ `),k=[...r.map(e=>({args:e.args,definition:e,path:`${g(e.filePath)}:${e.exportName}`})),...n.map(e=>({args:e.args,definition:{...e,expose:void 0,kind:"mutation",lifecycle:void 0,visibility:void 0,x402:void 0},path:`${g(e.filePath)}:${e.exportName}`}))],P=a?k.filter(({definition:e})=>!s.has(e.filePath)):[];for(const{definition:e}of k)if(a&&e.x402&&e.x402.price===void 0)throw new A("INTERNAL",`@lunora/codegen: lazy function registry needs a literal \`.x402({ price })\` value in ${e.filePath}:${e.exportName}`);const v=a?P.map(({definition:e,path:m})=>{const R=i.get(e.filePath)??"",x="channel"in e?e.channel:void 0,b={argumentDescriptors:JSON.parse(C(e.args)),exportName:e.exportName,kind:e.kind,moduleId:R,...x?{channel:x}:{},...e.expose?{expose:e.expose}:{},...e.lifecycle?{lifecycle:e.lifecycle}:{},...e.visibility?{visibility:e.visibility}:{},...e.x402?.price===void 0?{}:{x402:{price:e.x402.price}}};return` ${JSON.stringify(m)}: ${JSON.stringify(b)},`}).join(`
69
+ `):"",h=[...new Set(P.map(({definition:e})=>e.filePath))],w=a?h.map(e=>{if(!T.test(e))throw new A("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(e)}`);const m=i.get(e)??"";return` ${JSON.stringify(m)}: () => import(${JSON.stringify(`./fn/${m}.js`)}),`}).join(`
70
70
  `):"";return{dispatchBody:y.length>0?`
71
71
  ${y}
72
72
  `:"",importBlock:c.length>0?`${c}
73
73
 
74
- `:"",installBlock:v,manifestBody:b.length>0?`
75
- ${b}
74
+ `:"",installBlock:O,manifestBody:v.length>0?`
75
+ ${v}
76
76
  `:"",migrationBody:l.length>0?`
77
77
  ${l}
78
78
  `:"",moduleLoaders:w.length>0?`
79
79
  ${w}
80
- `:"",mutatorPaths:$,roomMessagesBody:O,shapeBody:f.length>0?`
80
+ `:"",mutatorPaths:$,roomMessagesBody:S,shapeBody:f.length>0?`
81
81
  ${f}
82
- `:""}},Pe=r=>{const t=M(r,o=>{const a=I(le(o.args),o.filePath),i=a==="{}"?"?":"",s=I(ge(o),o.filePath);return o.kind==="stream"?`${o.exportName}: (args${i}: ${a}) => Promise<AsyncIterable<${s}>>;`:`${o.exportName}: (args${i}: ${a}) => Promise<${s}>;`},"type");return{implementation:M(r,o=>`${ue(o.exportName)}: (args) => callRegistered(context, "${g(o.filePath)}:${o.exportName}", args),`,"value"),types:t}},xe=r=>{const t={connect:[],disconnect:[],init:[],reactor:[],whisper:[]};for(const n of r)!n.lifecycle||n.lifecycle==="socket"||t[n.lifecycle].push(`${g(n.filePath)}:${n.exportName}`);return t},Ae=r=>{const t=new Map,n=[];for(const o of r){if(o.lifecycle!=="socket"||o.socket===void 0)continue;const{auth:a,origin:i,path:s}=o.socket,c=`${g(o.filePath)}:${o.exportName}`,d=t.get(s);if(!(d?.origin!==void 0&&d.origin===i)){if(d!==void 0)throw new P("DUPLICATE_SOCKET_PATH",`two defineWebSocket routes serve "${s}" (${d.functionPath} and ${c}); socket paths must be unique.`);t.set(s,{functionPath:c,origin:i}),n.push(` ${JSON.stringify(s)}: { auth: ${String(a)}, functionPath: ${JSON.stringify(c)} },`)}}return`
82
+ `:""}},Te=r=>{const t=M(r,o=>{const a=I(he(o.args),o.filePath),i=a==="{}"?"?":"",s=I(we(o),o.filePath);return o.kind==="stream"?`${o.exportName}: (args${i}: ${a}) => Promise<AsyncIterable<${s}>>;`:`${o.exportName}: (args${i}: ${a}) => Promise<${s}>;`},"type");return{implementation:M(r,o=>`${me(o.exportName)}: (args) => callRegistered(context, "${g(o.filePath)}:${o.exportName}", args),`,"value"),types:t}},Fe=r=>{const t={connect:[],disconnect:[],init:[],reactor:[],whisper:[]};for(const n of r)!n.lifecycle||n.lifecycle==="socket"||t[n.lifecycle].push(`${g(n.filePath)}:${n.exportName}`);return t},Ee=r=>{const t=new Map,n=[];for(const o of r){if(o.lifecycle!=="socket"||o.socket===void 0)continue;const{auth:a,origin:i,path:s}=o.socket,c=`${g(o.filePath)}:${o.exportName}`,d=t.get(s);if(!(d?.origin!==void 0&&d.origin===i)){if(d!==void 0)throw new A("DUPLICATE_SOCKET_PATH",`two defineWebSocket routes serve "${s}" (${d.functionPath} and ${c}); socket paths must be unique.`);t.set(s,{functionPath:c,origin:i}),n.push(` ${JSON.stringify(s)}: { auth: ${String(a)}, functionPath: ${JSON.stringify(c)} },`)}}return`
83
83
  /**
84
84
  * Socket registry: the URL path of each \`defineWebSocket\` route → its function path + auth requirement.
85
85
  * Static, so building the worker never evaluates a route's module. The generated ShardDO's \`socketRoute\` override
@@ -89,7 +89,7 @@ export const LUNORA_SOCKETS: Readonly<Record<string, { auth: boolean; functionPa
89
89
  ${n.join(`
90
90
  `)}
91
91
  };
92
- `},Le=(r,t)=>{const n=r.some(c=>c.lifecycle==="socket"),a=n&&t?Ae(r):n&&!t?`
92
+ `},_e=(r,t)=>{const n=r.some(c=>c.lifecycle==="socket"),a=n&&t?Ee(r):n&&!t?`
93
93
  /**
94
94
  * Socket registry: the URL path of each \`defineWebSocket\` route → its function
95
95
  * path + auth requirement. The generated ShardDO's \`socketRoute\` override
@@ -133,7 +133,7 @@ export const LUNORA_SOCKETS: Readonly<Record<string, { auth: boolean; functionPa
133
133
  * Set on a \`defineWebSocket\` registration: whether the route refuses an
134
134
  * anonymous upgrade. Read into \`LUNORA_SOCKETS\` alongside \`socketPath\`.
135
135
  */
136
- auth?: boolean;`:"",lifecycleMember:n?' | "socket"':"",registry:a}},Te=(r,t,n)=>r?{channelField:` /**
136
+ auth?: boolean;`:"",lifecycleMember:n?' | "socket"':"",registry:a}},Me=(r,t,n)=>r?{channelField:` /**
137
137
  * Set on a \`defineRoom\` registration: the room's name (without the \`room:\`
138
138
  * topic prefix). The generated \`LUNORA_ROOMS\` map keys it on the room's
139
139
  * \`room:<name>\` whisper topic so the ShardDO resolves a room topic to this
@@ -148,7 +148,7 @@ export type LunoraRoomMessages = {
148
148
  ${n}
149
149
  };
150
150
  `,typeImport:`import type { RoomMessageOf } from "${t}";
151
- `}:{channelField:"",messagesBlock:"",typeImport:""},Ee=(r,t,n)=>r?t?`
151
+ `}:{channelField:"",messagesBlock:"",typeImport:""},Ie=(r,t,n)=>r?t?`
152
152
  /**
153
153
  * Room routes are static metadata so building the worker never evaluates user handlers.
154
154
  */
@@ -208,47 +208,53 @@ export const LUNORA_ROOMS: Readonly<Record<string, string>> = (() => {
208
208
 
209
209
  return registry;
210
210
  })();
211
- `:"",Fe=(r,t)=>{const n=Pe(r),o=n.types?`
211
+ `:"",Ce=(r,t)=>{const n=Te(r),o=n.types?`
212
212
  ${n.types}
213
213
  `:"",a=n.implementation?`
214
214
  ${n.implementation}
215
- `:"",i=me(n.types),s=i.length>0?`import type { ${i.join(", ")} } from "./dataModel.js";
216
- `:"",c=r.length>0?"context":"_context";let d="";if(r.length>0){let l=Oe;t||(l=l.replace("await loadFunction(functionPath)",N("LUNORA_FUNCTIONS"))),d=`${l}
215
+ `:"",i=$e(n.types),s=i.length>0?`import type { ${i.join(", ")} } from "./dataModel.js";
216
+ `:"",c=r.length>0?"context":"_context";let d="";if(r.length>0){let l=Ae;t||(l=l.replace("await loadFunction(functionPath)",N("LUNORA_FUNCTIONS"))),d=`${l}
217
217
 
218
- `}return{callRegisteredHelper:d,dataModelImport:s,implementation:a,parameter:c,types:o}},De=r=>{const{agents:t=[],functions:n,lazyFunctions:o=!1,migrations:a=[],mutators:i=[],shapes:s=[],useUmbrella:c=!1,usesSandbox:d=!1}=r,l=D(c),{dispatchBody:u,importBlock:f,installBlock:$,manifestBody:y,migrationBody:v,moduleLoaders:O,mutatorPaths:k,roomMessagesBody:S,shapeBody:b}=Se(n,a,i,s,o),h=de(t,n),w=he(d,n),e=[h.lines,w.lines].filter(m=>m.length>0).join(`
219
- `);let p=u;e.length>0&&(p=u.length>0?`${u.trimEnd()}
220
- ${e}
218
+ `}return{callRegisteredHelper:d,dataModelImport:s,implementation:a,parameter:c,types:o}},He=r=>{const{agents:t=[],functions:n,lazyFunctions:o=!1,migrations:a=[],mutators:i=[],shapes:s=[],useUmbrella:c=!1,usesSandbox:d=!1}=r,l=U(c),{dispatchBody:u,importBlock:f,installBlock:$,manifestBody:y,migrationBody:O,moduleLoaders:S,mutatorPaths:k,roomMessagesBody:P,shapeBody:v}=Le(n,a,i,s,o),h=ge(t,n),w=fe(d,n),m=t.length>0||n.some(p=>j(p.args).length>0)?` /**
219
+ * Names of the arguments whose validators carry a \`v.sensitive\` marker. Read by the
220
+ * shard before any validator is loaded, so a lazy function's secret args are
221
+ * masked even on a dispatch that fails before its module evaluates.
222
+ */
223
+ sensitiveArgs?: readonly string[];
224
+ `:"",R=[h.lines,w.lines].filter(p=>p.length>0).join(`
225
+ `);let x=u;R.length>0&&(x=u.length>0?`${u.trimEnd()}
226
+ ${R}
221
227
  `:`
222
- ${e}
223
- `);const R=xe(n),x=o?"await loadFunction(functionPath)":N("LUNORA_FUNCTIONS"),A=o?` if (${N("LUNORA_FUNCTION_MANIFEST")}?.visibility === "internal") {
228
+ ${R}
229
+ `);const b=Fe(n),Q=o?"await loadFunction(functionPath)":N("LUNORA_FUNCTIONS"),G=o?` if (${N("LUNORA_FUNCTION_MANIFEST")}?.visibility === "internal") {
224
230
  throw new LunoraError("FUNCTION_NOT_FOUND", \`function not registered: \${functionPath}\`);
225
231
  }
226
232
 
227
- `:"",W=s.length>0?`import type { RegisteredShape } from "${l.server}";
228
- `:"",F=n.some(m=>m.channel?.kind==="room"),L=Te(F,l.server,S),Q=s.length>0?`
233
+ `:"",V=s.length>0?`import type { RegisteredShape } from "${l.server}";
234
+ `:"",E=n.some(p=>p.channel?.kind==="room"),L=Me(E,l.server,P),K=s.length>0?`
229
235
  /**
230
236
  * Replication-shape registry — one entry per \`defineShape\` in \`lunora/shapes.ts\`.
231
237
  * The generated ShardDO's \`resolveShape\` override looks a shape up by name and
232
238
  * evaluates its trusted \`compileWhere(ctx, args)\` to authorize + scope a
233
239
  * \`shape_subscribe\` (reads-as-permissions).
234
240
  */
235
- export const LUNORA_SHAPES: Record<string, RegisteredShape> = {${b}};
236
- `:"",G=k.length>0?`
241
+ export const LUNORA_SHAPES: Record<string, RegisteredShape> = {${v}};
242
+ `:"",Y=k.length>0?`
237
243
  /**
238
244
  * Custom-mutator function paths — the \`LUNORA_FUNCTIONS\` keys the generated
239
245
  * ShardDO's \`isCustomMutator\` override routes through the client-watermark push
240
246
  * protocol (\`x-lunora-client-id\`/\`x-lunora-client-seq\` ordering).
241
247
  */
242
- export const LUNORA_MUTATOR_PATHS: ReadonlySet<string> = new Set([${k.map(m=>JSON.stringify(m)).join(", ")}]);
243
- `:"",V=Ee(F,o,n),{fields:K,lifecycleMember:_,registry:Y}=Le(n,o),Z=$.length>0?`import { DEFER_VALIDATION as DEFER, installCompiledValidatorMap } from "${l.values}";
244
- `:"",X=$.length>0?`
248
+ export const LUNORA_MUTATOR_PATHS: ReadonlySet<string> = new Set([${k.map(p=>JSON.stringify(p)).join(", ")}]);
249
+ `:"",Z=Ie(E,o,n),{fields:X,lifecycleMember:_,registry:ee}=_e(n,o),te=$.length>0?`import { DEFER_VALIDATION as DEFER, installCompiledValidatorMap } from "${l.values}";
250
+ `:"",re=$.length>0?`
245
251
  /**
246
252
  * AOT-compiled argument validators (Worker-safe, no \`eval\`). Each is installed
247
253
  * onto its function's live \`.args\` object and consulted by the interpreted
248
254
  * parser as a zero-allocation fast path; anything it can't model is deferred.
249
255
  */
250
256
  ${$}
251
- `:"",ee=Fe(n,o),{callRegisteredHelper:te,dataModelImport:re,implementation:ne,parameter:oe,types:se}=ee,ae=o?`
257
+ `:"",ne=Ce(n,o),{callRegisteredHelper:oe,dataModelImport:se,implementation:ae,parameter:ie,types:ce}=ne,le=o?`
252
258
  export interface FunctionManifestEntry {
253
259
  argumentDescriptors: ReadonlyArray<{ element?: string; kind: string; name: string; optional: boolean; table?: string }>;
254
260
  channel?: { kind: "room"; name: string };
@@ -264,7 +270,7 @@ export interface FunctionManifestEntry {
264
270
  /** Static, codegen-derived facts. Request gates can inspect these without evaluating a user module. */
265
271
  export const LUNORA_FUNCTION_MANIFEST: Readonly<Record<string, FunctionManifestEntry>> = {${y}};
266
272
 
267
- const MODULE_LOADERS: Record<string, () => Promise<Record<string, unknown>>> = {${O}};
273
+ const MODULE_LOADERS: Record<string, () => Promise<Record<string, unknown>>> = {${S}};
268
274
  const loadedModules = new Map<string, Promise<Record<string, unknown>>>();
269
275
  const resolvedModules = new Map<string, Record<string, unknown>>();
270
276
  const boundFunctions = new Set<string>();
@@ -333,7 +339,7 @@ export const loadFunction = async (functionPath: string): Promise<RegisteredLuno
333
339
  return getLoadedFunction(functionPath);
334
340
  };
335
341
 
336
- `:"",ie=o&&y!==""?`
342
+ `:"",ue=o&&y!==""?`
337
343
  /**
338
344
  * Evaluate every lazy module now and report the ones that fail, keyed by function path. A lazy
339
345
  * registry defers a broken module's error to its first call; \`lunora build\` and \`deploy\` run this
@@ -359,9 +365,9 @@ export const loadAllFunctions = async (): Promise<{ checked: number; failures: R
359
365
 
360
366
  return { checked: functionPaths.length, failures };
361
367
  };
362
- `:"";return pe(`${j}${f}${h.importLine}${w.importLine}${Z}${W}${L.typeImport}import { LunoraError } from "${l.server}";
368
+ `:"";return ye(`${D}${f}${h.importLine}${w.importLine}${te}${V}${L.typeImport}import { LunoraError } from "${l.server}";
363
369
  import type { ActionCtx, MutationCtx, QueryCtx } from "./server.js";
364
- ${re}
370
+ ${se}
365
371
  /**
366
372
  * Single registered function, narrowed to the shape \`handleRpc\` needs.
367
373
  * The real argument validators / return types are checked elsewhere — at
@@ -390,7 +396,7 @@ export interface RegisteredLunoraFunction {
390
396
  * \`init\` and \`reactor\` have no caller identity, so RLS has no user to scope
391
397
  * to. \`whisper\` does have one — it runs under the asking socket's identity.
392
398
  */
393
- lifecycle?: "connect" | "disconnect" | "init" | "reactor" | "whisper"${_};${K}
399
+ lifecycle?: "connect" | "disconnect" | "init" | "reactor" | "whisper"${_};${X}
394
400
  ${L.channelField} /**
395
401
  * Hoisted by the builder when the \`.use()\` chain carries a step with a
396
402
  * per-dispatch effect — \`rateLimit(...)\` consuming budget, a single-use
@@ -406,14 +412,14 @@ ${L.channelField} /**
406
412
  * paywalls it; the shard refuses to subscribe it (\`isPaidFunction\`).
407
413
  */
408
414
  x402?: { readonly price: number | string };
409
- }
410
- ${h.prelude}${w.prelude}${ae}${ie}
415
+ ${m}}
416
+ ${h.prelude}${w.prelude}${le}${ue}
411
417
  /**
412
418
  * Static dispatch table. The key matches the \`__lunoraRef\` the client
413
419
  * emits (\`api[namespace][fn].__lunoraRef === "namespace:fn"\`).
414
420
  */
415
- export const LUNORA_FUNCTIONS: Record<string, RegisteredLunoraFunction> = {${p}};
416
- ${X}${Q}${G}${V}${L.messagesBlock}${Y}
421
+ export const LUNORA_FUNCTIONS: Record<string, RegisteredLunoraFunction> = {${x}};
422
+ ${re}${K}${Y}${Z}${L.messagesBlock}${ee}
417
423
  /**
418
424
  * Lifecycle manifest: the function paths the generated ShardDO dispatches when a
419
425
  * client's WebSocket connects (\`connect\`) or disconnects (\`disconnect\`), once
@@ -431,11 +437,11 @@ export const LUNORA_LIFECYCLE_HOOKS: {
431
437
  reactor: readonly string[];
432
438
  whisper: readonly string[];
433
439
  } = {
434
- connect: [${R.connect.map(m=>JSON.stringify(m)).join(", ")}],
435
- disconnect: [${R.disconnect.map(m=>JSON.stringify(m)).join(", ")}],
436
- init: [${R.init.map(m=>JSON.stringify(m)).join(", ")}],
437
- reactor: [${R.reactor.map(m=>JSON.stringify(m)).join(", ")}],
438
- whisper: [${R.whisper.map(m=>JSON.stringify(m)).join(", ")}],
440
+ connect: [${b.connect.map(p=>JSON.stringify(p)).join(", ")}],
441
+ disconnect: [${b.disconnect.map(p=>JSON.stringify(p)).join(", ")}],
442
+ init: [${b.init.map(p=>JSON.stringify(p)).join(", ")}],
443
+ reactor: [${b.reactor.map(p=>JSON.stringify(p)).join(", ")}],
444
+ whisper: [${b.whisper.map(p=>JSON.stringify(p)).join(", ")}],
439
445
  };
440
446
 
441
447
  /**
@@ -445,7 +451,7 @@ export const LUNORA_LIFECYCLE_HOOKS: {
445
451
  * functions are treated as not-found so their existence never leaks to clients.
446
452
  */
447
453
  export const dispatchLunoraFunction = async (functionPath: string, context: unknown, args: Record<string, unknown>): Promise<unknown> => {
448
- ${A} const registered = ${x};
454
+ ${G} const registered = ${Q};
449
455
 
450
456
  if (!registered || registered.visibility === "internal") {
451
457
  throw new LunoraError("FUNCTION_NOT_FOUND", \`function not registered: \${functionPath}\`);
@@ -466,10 +472,10 @@ export type CallerCtx = ActionCtx | MutationCtx | QueryCtx;
466
472
  * with the supplied \`context\`, exactly like \`ctx.runQuery\`/\`runMutation\`/
467
473
  * \`runAction\` but without re-stating the function path.
468
474
  */
469
- export interface Caller {${se}}
475
+ export interface Caller {${ce}}
470
476
 
471
- ${te}/** Build a {@link Caller} bound to \`context\` (typically a handler's \`ctx\`). */
472
- export const createCaller = (${oe}: CallerCtx): Caller => ({${ne}});
477
+ ${oe}/** Build a {@link Caller} bound to \`context\` (typically a handler's \`ctx\`). */
478
+ export const createCaller = (${ie}: CallerCtx): Caller => ({${ae}});
473
479
 
474
480
  /**
475
481
  * Single registered data migration, narrowed to the shape the per-shard runner
@@ -488,13 +494,13 @@ export interface RegisteredDataMigration {
488
494
  * Registry of online data migrations keyed by \`defineMigration\`'s \`id\`. The
489
495
  * shard DO's admin RPC and the CLI resolve migrations to run through this map.
490
496
  */
491
- export const LUNORA_MIGRATIONS: Record<string, RegisteredDataMigration> = {${v}};
492
- `,c)},Ue="fn",Je=r=>{if(r.lazyFunctions!==!0)return{};const{functions:t}=r,n=r.migrations??[],o=r.mutators??[],a=r.shapes??[],i=H(t,n,o,a),s=z(n,o,a),c=[...new Set(t.filter(u=>!s.has(u.filePath)).map(u=>u.filePath))],d=D(r.useUmbrella??!1),l={};for(const u of c){if(!T.test(u))throw new P("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(u)}`);const f=i.get(u)??"",$=`../../${u}.js`,y=t.filter(h=>h.filePath===u&&!h.lifecycle&&Object.keys(h.args).length>0).flatMap(h=>{const w=q(h.args);return w===void 0?[]:[`installCompiledValidatorMap(${f}.${h.exportName}.args, ${w});`]}),v=y.length>0?`import { DEFER_VALIDATION as DEFER, installCompiledValidatorMap } from "${d.values}";
493
- `:"",O=y.length>0?`import * as ${f} from "${$}";
497
+ export const LUNORA_MIGRATIONS: Record<string, RegisteredDataMigration> = {${O}};
498
+ `,c)},ze="fn",We=r=>{if(r.lazyFunctions!==!0)return{};const{functions:t}=r,n=r.migrations??[],o=r.mutators??[],a=r.shapes??[],i=z(t,n,o,a),s=W(n,o,a),c=[...new Set(t.filter(u=>!s.has(u.filePath)).map(u=>u.filePath))],d=U(r.useUmbrella??!1),l={};for(const u of c){if(!T.test(u))throw new A("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(u)}`);const f=i.get(u)??"",$=`../../${u}.js`,y=t.filter(h=>h.filePath===u&&!h.lifecycle&&Object.keys(h.args).length>0).flatMap(h=>{const w=H(h.args);return w===void 0?[]:[`installCompiledValidatorMap(${f}.${h.exportName}.args, ${w});`]}),O=y.length>0?`import { DEFER_VALIDATION as DEFER, installCompiledValidatorMap } from "${d.values}";
499
+ `:"",S=y.length>0?`import * as ${f} from "${$}";
494
500
  `:"",k=y.length>0?`
495
501
  /** Install the precompiled argument parsers before the module is dispatched. */
496
502
  ${y.join(`
497
503
  `)}
498
- `:"",b=t.some(h=>h.filePath===u&&h.exportName==="default")||n.some(h=>h.filePath===u&&h.exportName==="default")?`export { default } from "${$}";
499
- `:"";l[`${f}.ts`]=`${j}${v}${O}${k}export * from "${$}";
500
- ${b}`}return l};export{Ue as LAZY_FUNCTION_DIRECTORY,De as emitFunctions,Je as emitLazyFunctionModules};
504
+ `:"",v=t.some(h=>h.filePath===u&&h.exportName==="default")||n.some(h=>h.filePath===u&&h.exportName==="default")?`export { default } from "${$}";
505
+ `:"";l[`${f}.ts`]=`${D}${O}${S}${k}export * from "${$}";
506
+ ${v}`}return l};export{ze as LAZY_FUNCTION_DIRECTORY,He as emitFunctions,We as emitLazyFunctionModules};
@@ -1 +1 @@
1
- import"./CAPABILITY_PROBES-brcmKenl.mjs";import{e}from"./server-DAvi_bv_.mjs";import"./shared-DnCokNcE.mjs";import"./platform-8oj7iXQy.mjs";export{e as default};
1
+ import"./CAPABILITY_PROBES-brcmKenl.mjs";import{e}from"./server-B6VhYK7m.mjs";import"./shared-8vTRkL2-.mjs";import"./platform-8oj7iXQy.mjs";export{e as default};
@@ -0,0 +1 @@
1
+ import"./SCHEMA_SNAPSHOT_VERSION-C7Um0EnM.mjs";import"./isD1GlobalTable-udvHAAzD.mjs";import"./json-data-Chfs2Cz5.mjs";import{e as d}from"./shard-BCqz_05A.mjs";import"./shard-runtime-ByYXjCKY.mjs";import"./shared-8vTRkL2-.mjs";import"./platform-8oj7iXQy.mjs";import"./schema-BgM8A3XV.mjs";export{d as default};
@@ -1 +1 @@
1
- import{Node as s}from"ts-morph";import{b as t,d as c}from"./attribution-RI-H1KPm.mjs";import{c as n}from"./classify-procedure-call-C5JY2w5V.mjs";const m=a=>{const i=[];for(const e of t(a)){const r=e.getInitializer(),o=r&&s.isCallExpression(r)?n(r):void 0;o?.receiver&&i.push({name:c(e)??e.getName(),receiver:o.receiver})}return i};export{m as e};
1
+ import{Node as s}from"ts-morph";import{b as t,d as c}from"./attribution-CG8-kUcl.mjs";import{c as n}from"./classify-procedure-call-BkaeM9Ej.mjs";const m=a=>{const i=[];for(const e of t(a)){const r=e.getInitializer(),o=r&&s.isCallExpression(r)?n(r):void 0;o?.receiver&&i.push({name:c(e)??e.getName(),receiver:o.receiver})}return i};export{m as e};
@@ -1 +1 @@
1
- import{createHash as i}from"node:crypto";import{existsSync as s,readFileSync as c}from"node:fs";import{join as u}from"node:path";import{listLunoraSourceFiles as h}from"./isTestPath-Cdv_LoVU.mjs";const S=t=>{if(!s(t))return"unreadable";const e=h(t,{includeSkipped:!0}),o=u(t,"schema.ts");s(o)&&e.push(o);const r=i("sha256");for(const a of e.toSorted((n,p)=>n.localeCompare(p)))try{r.update(a).update("\0").update(c(a))}catch{}return r.digest("hex")};export{S as default};
1
+ import{createHash as i}from"node:crypto";import{existsSync as s,readFileSync as c}from"node:fs";import{join as u}from"node:path";import{listLunoraSourceFiles as h}from"./isTestPath-C3QumE88.mjs";const S=t=>{if(!s(t))return"unreadable";const e=h(t,{includeSkipped:!0}),o=u(t,"schema.ts");s(o)&&e.push(o);const r=i("sha256");for(const a of e.toSorted((n,p)=>n.localeCompare(p)))try{r.update(a).update("\0").update(c(a))}catch{}return r.digest("hex")};export{S as default};
@@ -1 +1 @@
1
- import{dirname as F}from"node:path";import{Node as e}from"ts-morph";import{unwrapExpression as m,lunoraRelativePath as u}from"./isTestPath-Cdv_LoVU.mjs";import{r as v,d as b}from"./attribution-RI-H1KPm.mjs";const h=i=>e.isPropertyAssignment(i)?m(i.getInitializer()):e.isShorthandPropertyAssignment(i)?i.getNameNode():void 0,A=(i,s)=>{const o=i===void 0?void 0:h(i);if(o===void 0||!e.isIdentifier(o))return;const a=v(o),g=a?.getAliasedSymbol()??a;for(const t of g?.getDeclarations()??[]){const n=e.isVariableDeclaration(t)?m(t.getInitializer()):t;if(!(e.isFunctionDeclaration(n)||e.isArrowFunction(n)||e.isFunctionExpression(n))||!(e.isFunctionDeclaration(t)||e.isVariableDeclaration(t)))continue;const r=t.getSourceFile(),c=u(s,r.getFilePath()),l=!c.startsWith("../"),d=l?c:u(F(s),r.getFilePath()),f=b(t);return{body:n,...r===o.getSourceFile()?{}:{file:d},...l&&f!==void 0?{site:{exportName:f,file:d}}:{}}}};export{A as r};
1
+ import{dirname as F}from"node:path";import{Node as e}from"ts-morph";import{unwrapExpression as m,lunoraRelativePath as u}from"./isTestPath-C3QumE88.mjs";import{r as v,d as b}from"./attribution-CG8-kUcl.mjs";const h=i=>e.isPropertyAssignment(i)?m(i.getInitializer()):e.isShorthandPropertyAssignment(i)?i.getNameNode():void 0,A=(i,s)=>{const o=i===void 0?void 0:h(i);if(o===void 0||!e.isIdentifier(o))return;const a=v(o),g=a?.getAliasedSymbol()??a;for(const t of g?.getDeclarations()??[]){const n=e.isVariableDeclaration(t)?m(t.getInitializer()):t;if(!(e.isFunctionDeclaration(n)||e.isArrowFunction(n)||e.isFunctionExpression(n))||!(e.isFunctionDeclaration(t)||e.isVariableDeclaration(t)))continue;const r=t.getSourceFile(),c=u(s,r.getFilePath()),l=!c.startsWith("../"),d=l?c:u(F(s),r.getFilePath()),f=b(t);return{body:n,...r===o.getSourceFile()?{}:{file:d},...l&&f!==void 0?{site:{exportName:f,file:d}}:{}}}};export{A as r};
@@ -0,0 +1 @@
1
+ import{Node as r}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as f}from"./isTestPath-C3QumE88.mjs";import{b as m,d as p}from"./attribution-CG8-kUcl.mjs";import{t as d}from"./database-calls-UPlhi3Ks.mjs";import{w as g,c as h}from"./classify-procedure-call-BkaeM9Ej.mjs";import{a as k}from"./property-name-7cBlgK_O.mjs";const l=e=>{if(!(!r.isPropertyAssignment(e)&&!r.isShorthandPropertyAssignment(e)&&!r.isMethodDeclaration(e)&&!r.isGetAccessorDeclaration(e)))return k(e)},v=e=>g(e,"use","mask"),D=e=>{if(r.isPropertyAssignment(e)){const s=e.getInitializer();if(s&&r.isStringLiteral(s)){const t=s.getLiteralText();if(t==="redact"||t==="hash")return t}}return"custom"},P=e=>{const s=e.getArguments()[0];if(!s||!r.isObjectLiteralExpression(s))return[];const t=[];for(const i of s.getProperties()){const o=l(i);if(o===void 0||!r.isPropertyAssignment(i))continue;const n=i.getInitializer();if(!(!n||!r.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=l(a);c!==void 0&&t.push({column:c,table:o})}}return t},y=e=>{const s=v(e);return{maskColumns:s.flatMap(t=>P(t)),usesMask:s.length>0}},C=new Set(["explain","findFirst","findFirstOrThrow","findMany","get","query"]),M=new Set(["delete","insert","patch","replace"]),x=(e,s)=>{if(!r.isVariableDeclaration(e))return;const t=e.getInitializer();if(!t||!r.isCallExpression(t))return;const i=h(t);if(!i)return;const o=i.receiver?y(i.receiver):{maskColumns:[],usesMask:!1},{tablesRead:n,tablesWritten:a}=d(e,C,M);return{exportName:p(e)??e.getName(),file:s,maskColumns:o.maskColumns,tablesRead:n,tablesWritten:a,usesMask:o.usesMask,visibility:i.visibility}},E=(e,s)=>{const t=[];for(const i of u(s)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i),n=f(s,i);for(const a of m(o)){const c=x(a,n);c&&t.push(c)}}return t};export{l as a,E as d,v as m,D as s};