overmux 0.0.8 → 0.0.10

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 (41) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/bin.js +59 -21
  3. package/dist/bin.js.map +1 -1
  4. package/dist/docs/100-introduction/300-why-i-built-overmux.md +1 -1
  5. package/dist/docs/200-getting-started/200-install-overmux-desktop.md +13 -0
  6. package/dist/docs/400-reference/500-server/100-resources.md +25 -0
  7. package/dist/docs/400-reference/500-server/500-api.md +4 -2
  8. package/dist/docs/400-reference/600-client/010-commands.md +0 -29
  9. package/dist/docs/400-reference/600-client/030-native-web-view.md +166 -0
  10. package/dist/docs/400-reference/600-client/300-tech-stack-recommendations.md +1 -0
  11. package/dist/docs/400-reference/700-cli/600-docs.md +1 -1
  12. package/dist/exports/client.d.ts +44 -8
  13. package/dist/exports/client.d.ts.map +1 -1
  14. package/dist/exports/client.js +212 -40
  15. package/dist/exports/client.js.map +1 -1
  16. package/dist/exports/{index-Cz3xkCa4.d.ts → index-Dk11nKIv.d.ts} +2 -2
  17. package/dist/exports/index-Dk11nKIv.d.ts.map +1 -0
  18. package/dist/exports/index.d.ts +1 -1
  19. package/dist/exports/index.js +1 -1
  20. package/dist/exports/index.js.map +1 -1
  21. package/dist/internal/server/coordinator/server-child.js +75 -22
  22. package/dist/internal/server/coordinator/server-child.js.map +1 -1
  23. package/docs/100-introduction/300-why-i-built-overmux.md +1 -1
  24. package/docs/200-getting-started/200-install-overmux-desktop.md +13 -0
  25. package/docs/400-reference/500-server/100-resources.md +25 -0
  26. package/docs/400-reference/500-server/500-api.md +4 -2
  27. package/docs/400-reference/600-client/010-commands.md +0 -29
  28. package/docs/400-reference/600-client/030-native-web-view.md +166 -0
  29. package/docs/400-reference/600-client/300-tech-stack-recommendations.md +1 -0
  30. package/docs/400-reference/700-cli/600-docs.md +1 -1
  31. package/package.json +2 -2
  32. package/src/internal/client/client-definition.ts +9 -13
  33. package/src/internal/client/host/desktop-host.ts +28 -2
  34. package/src/internal/client/native-web-view.tsx +158 -0
  35. package/src/internal/client/overmux-react.ts +121 -27
  36. package/src/internal/client/shortcuts.tsx +17 -31
  37. package/src/internal/server/runtime/runtime-resources.ts +99 -20
  38. package/src/internal/server/websocket-connection.ts +27 -2
  39. package/src/public/client.ts +5 -0
  40. package/src/public/config.ts +1 -1
  41. package/dist/exports/index-Cz3xkCa4.d.ts.map +0 -1
@@ -76,7 +76,7 @@ type SubscriptionResourceDefinition<TInput extends z.ZodType = z.ZodType, TOutpu
76
76
  contract: ResourceContract<TInput, TOutput>;
77
77
  kind: "subscription";
78
78
  read: QueryResourceDefinition<TInput, TOutput, TContext>["read"];
79
- subscribe: (input: z.output<TInput>, invalidate: () => void, context: TContext) => RuntimeDisposer;
79
+ subscribe: (input: z.output<TInput>, invalidate: () => void, context: TContext) => RuntimeDisposer | Promise<RuntimeDisposer>;
80
80
  };
81
81
  type DerivedResourceDefinition<TInput extends z.ZodType = z.ZodType, TOutput extends z.ZodType = z.ZodType, TDependencies extends Readonly<Record<string, string>> = Readonly<Record<string, string>>, TDependencyOutputs = Readonly<Record<string, unknown>>> = {
82
82
  combine: (dependencies: TDependencyOutputs) => z.input<NoInfer<TOutput>>;
@@ -178,4 +178,4 @@ declare const defineOvermuxServer: <const TContracts extends ResourceContracts =
178
178
  }) => ConfigDefinition<ConfiguredResources<TContracts, TDependencies>, TStreams, NormalizedOperations<TInputs, TOutputs, TContracts>>;
179
179
  declare const defineOvermuxConfig: <const TServer extends ConfigDefinition>(definition: OvermuxConfigDefinition<TServer>) => OvermuxConfigDefinition<TServer>;
180
180
  export { noInputSchema as A, InstanceIdentity as B, defineStreamHandler as C, defineResourceContract as D, StreamContract as E, AiContextSnippetDefinition as F, overmuxLogoutPath as G, createOvermuxSettingsPath as H, coreAiContextSnippets as I, overmuxSettingsPath as K, defaultAiContextSnippets as L, Notifications as M, composeAiContext as N, defineStreamContract as O, AiContextSnippet as P, packageSourceSnippet as R, defineOvermuxServer as S, ResourceContract as T, notificationLinkSchema as U, Notification as V, notificationSchema as W, StreamHandlerDefinition as _, HandlerContext as a, defineOperation as b, OperationDefinition as c, OvermuxServerResources as d, OvermuxServerStreams as f, ServerConfigDefinition as g, RuntimeDisposer as h, DerivedResourceDefinition as i, parseJsonValue as j, jsonValueSchema as k, OvermuxConfigDefinition as l, ResourceDefinition as m, AuthDuration as n, InstanceContext as o, QueryResourceDefinition as p, resolveOvermuxReturnTo as q, ConfigDefinition as r, OperationContext as s, AuthConfigDefinition as t, OvermuxServerOperations as u, StreamSession as v, ContractInputArguments as w, defineOvermuxConfig as x, SubscriptionResourceDefinition as y, techStackRecommendationsSnippet as z };
181
- //# sourceMappingURL=index-Cz3xkCa4.d.ts.map
181
+ //# sourceMappingURL=index-Dk11nKIv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-Dk11nKIv.d.ts","names":[],"sources":["../../../shared/dist/index.d.ts","../../../ai-context/dist/index.d.ts","../../src/public/ai-context.ts","../../src/public/notifications.ts","../../src/public/contracts.ts","../../src/public/config.ts"],"mappings":";;;cAEc;cACA;cACA,yBAAyB;cACzB,4BAA4B;;;cAG5B,wBAAwB,EAAE,mBAAmB,EAAE,WAAW,EAAE;cAC5D,oBAAoB,EAAE;EAClC,MAAM,EAAE,YAAY,EAAE;EACtB,MAAM,EAAE,YAAY,EAAE;IACpB,MAAM,EAAE,mBAAmB,EAAE,WAAW,EAAE;KACzC,EAAE,KAAK;EACV,OAAO,EAAE;GACR,EAAE,KAAK;KACL,eAAe,EAAE,aAAa;KAa9B;EACH;EACA;;;;;cC9BY;cACA;cACA;KACT,2BAA2B;KAC3B,sCAAsC;cAC7B;cACA;;;cCOD,mBAAoB,UAAU;;;KCP/B;EACV,OAAO,cAAc,iBAAiB;;;;cCN3B,eAAa,EAAA;cAEb,iBAAiB,EAAE;cAWnB,iBAAkB,GAAG,OAAO,MAAI;KAGjC,uBAAuB,eAAe,EAAE,6BA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,EAAE;KAED,qBACH,gBAAgB,iBAChB,UACA,mBAAmB,wBAElB,aAAa;EACZ,OAAO,QAAQ;EACf,SAAS,sBAAsB,UAAU;EACzC,QAAQ,oBACN,QAAQ,MACR,sBAAsB,UAAU,MAChC,iBAAiB,eAAe;UAInC,aAAa,WAAW,SAAS,aAAa,EAAE;EAC3C,QAAQ,SAAS;;EACjB;;KAGH,qBACH,gBAAgB,iBAChB,UACA,mBAAmB,wBAElB,aAAa,UAAU,oBACtB,QAAQ,MACR,sBAAsB,UAAU,MAChC,iBAAiB,eAAe;KAuBxB,iBACV,mBAAmB,SAAS,2BAA2B,SACrD,eAAe,sBAEjB,iBAAiB,oBAAoB,mBACrC,oBAAoB,uBAAuB;EAE3C,aAAa;EACb,WAAW;EACX,UAAU;;KAGA,wBACV,gBAAgB,mBAAmB,oBACjC;EACF,oBAAoB;EACpB,MAAM;EACN;EACA,wBAAwB;IAAW;;EACnC,QAAQ;EACR;;KAGU,uBAAuB,WAAW;EAC5C,iBAAiB;IAEf;KAGQ,qBAAqB,WAAW;EAC1C,gBAAgB;IAEd,YAAY;KAGJ,wBAAwB,WAAW;EAC7C,mBAAmB;IAEjB,YAAY;cAGH,4BACL,mBAAmB,8BACnB,0BACA,iBAAiB,8BACjB,gBAAgB,4BAChB,eACN;EACA,aAAa,qBAAqB,SAAS,UAAU,QAAQ;EAC7D,WAAW,oBAAoB,YAAY;EAC3C,UAAU,WACR,kBAAkB,eAAe,eAAe,QAAQ;MACxD,iBACF,oBAAoB,YAAY,gBAChC,UACA,qBAAqB,SAAS,UAAU;cAM7B,4BAA6B,gBAAgB,kBACxD,YAAY,wBAAwB,aACnC,wBAAwB"}
@@ -1,2 +1,2 @@
1
- import { A as noInputSchema, B as InstanceIdentity, C as defineStreamHandler, D as defineResourceContract, E as StreamContract, F as AiContextSnippetDefinition, G as overmuxLogoutPath, H as createOvermuxSettingsPath, I as coreAiContextSnippets, K as overmuxSettingsPath, L as defaultAiContextSnippets, M as Notifications, N as composeAiContext, O as defineStreamContract, P as AiContextSnippet, R as packageSourceSnippet, S as defineOvermuxServer, T as ResourceContract, U as notificationLinkSchema, V as Notification, W as notificationSchema, _ as StreamHandlerDefinition, a as HandlerContext, b as defineOperation, c as OperationDefinition, d as OvermuxServerResources, f as OvermuxServerStreams, g as ServerConfigDefinition, h as RuntimeDisposer, i as DerivedResourceDefinition, j as parseJsonValue, k as jsonValueSchema, l as OvermuxConfigDefinition, m as ResourceDefinition, n as AuthDuration, o as InstanceContext, p as QueryResourceDefinition, q as resolveOvermuxReturnTo, r as ConfigDefinition, s as OperationContext, t as AuthConfigDefinition, u as OvermuxServerOperations, v as StreamSession, w as ContractInputArguments, x as defineOvermuxConfig, y as SubscriptionResourceDefinition, z as techStackRecommendationsSnippet } from "./index-Cz3xkCa4.js";
1
+ import { A as noInputSchema, B as InstanceIdentity, C as defineStreamHandler, D as defineResourceContract, E as StreamContract, F as AiContextSnippetDefinition, G as overmuxLogoutPath, H as createOvermuxSettingsPath, I as coreAiContextSnippets, K as overmuxSettingsPath, L as defaultAiContextSnippets, M as Notifications, N as composeAiContext, O as defineStreamContract, P as AiContextSnippet, R as packageSourceSnippet, S as defineOvermuxServer, T as ResourceContract, U as notificationLinkSchema, V as Notification, W as notificationSchema, _ as StreamHandlerDefinition, a as HandlerContext, b as defineOperation, c as OperationDefinition, d as OvermuxServerResources, f as OvermuxServerStreams, g as ServerConfigDefinition, h as RuntimeDisposer, i as DerivedResourceDefinition, j as parseJsonValue, k as jsonValueSchema, l as OvermuxConfigDefinition, m as ResourceDefinition, n as AuthDuration, o as InstanceContext, p as QueryResourceDefinition, q as resolveOvermuxReturnTo, r as ConfigDefinition, s as OperationContext, t as AuthConfigDefinition, u as OvermuxServerOperations, v as StreamSession, w as ContractInputArguments, x as defineOvermuxConfig, y as SubscriptionResourceDefinition, z as techStackRecommendationsSnippet } from "./index-Dk11nKIv.js";
2
2
  export { type AiContextSnippet, type AiContextSnippetDefinition, type AuthConfigDefinition, type AuthDuration, type ConfigDefinition, type ContractInputArguments, type DerivedResourceDefinition, type HandlerContext, type InstanceContext, type InstanceIdentity, type Notification, type Notifications, type OperationContext, type OperationDefinition, type OvermuxConfigDefinition, type OvermuxServerOperations, type OvermuxServerResources, type OvermuxServerStreams, type QueryResourceDefinition, type ResourceContract, type ResourceDefinition, type RuntimeDisposer, type ServerConfigDefinition, type StreamContract, type StreamHandlerDefinition, type StreamSession, type SubscriptionResourceDefinition, composeAiContext, coreAiContextSnippets, createOvermuxSettingsPath, defaultAiContextSnippets, defineOperation, defineOvermuxConfig, defineOvermuxServer, defineResourceContract, defineStreamContract, defineStreamHandler, jsonValueSchema, noInputSchema, notificationLinkSchema, notificationSchema, overmuxLogoutPath, overmuxSettingsPath, packageSourceSnippet, parseJsonValue, resolveOvermuxReturnTo, techStackRecommendationsSnippet };
@@ -12,7 +12,7 @@ Run \`overmux docs path\` to find the installed documentation directory for the
12
12
  Inspect TypeScript source in installed packages, e.g. \`node_modules/overmux/src\` and \`node_modules/@overmux/xterm/src\`.
13
13
 
14
14
  Inspect these files so guidance matches the versions used by the application.`;
15
- const techStackRecommendationsSnippetContent = `Prefer pnpm as the package manager, TanStack Router for routing, shadcn/ui for UI components, and Zod for schemas and runtime validation. Follow the application's established stack when it already differs.`;
15
+ const techStackRecommendationsSnippetContent = `Prefer pnpm as the package manager, TanStack Router for routing, shadcn/ui for UI components, and Zod for schemas and runtime validation. For custom Git diff views, prefer @pierre/diffs (https://diffs.com/). Follow the application's established stack when it already differs.`;
16
16
  const aiContextContentBySnippet = {
17
17
  [packageSourceSnippet]: packageSourceSnippetContent,
18
18
  [techStackRecommendationsSnippet]: techStackRecommendationsSnippetContent
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../ai-context/dist/index.js","../../src/public/ai-context.ts","../../src/public/config.ts","../../src/public/contracts.ts"],"sourcesContent":["//#region src/index.ts\nconst packageSourceSnippet = \"package-source\";\nconst techStackRecommendationsSnippet = \"tech-stack-recommendations\";\nconst aiContextSnippets = [packageSourceSnippet, techStackRecommendationsSnippet];\nconst coreAiContextSnippets = [packageSourceSnippet];\nconst defaultAiContextSnippets = [...coreAiContextSnippets, techStackRecommendationsSnippet];\nconst packageSourceSnippetContent = `Overmux ships with documentation and TypeScript source.\n\nRun \\`overmux docs path\\` to find the installed documentation directory for the Overmux CLI. This prints a documentation directory, not source paths.\n\nInspect TypeScript source in installed packages, e.g. \\`node_modules/overmux/src\\` and \\`node_modules/@overmux/xterm/src\\`.\n\nInspect these files so guidance matches the versions used by the application.`;\nconst techStackRecommendationsSnippetContent = `Prefer pnpm as the package manager, TanStack Router for routing, shadcn/ui for UI components, and Zod for schemas and runtime validation. Follow the application's established stack when it already differs.`;\nconst aiContextContentBySnippet = {\n\t[packageSourceSnippet]: packageSourceSnippetContent,\n\t[techStackRecommendationsSnippet]: techStackRecommendationsSnippetContent\n};\n//#endregion\nexport { aiContextContentBySnippet, aiContextSnippets, coreAiContextSnippets, defaultAiContextSnippets, packageSourceSnippet, techStackRecommendationsSnippet };\n\n//# sourceMappingURL=index.js.map","import {\n aiContextContentBySnippet,\n type AiContextSnippetDefinition,\n} from \"@overmux/ai-context\";\n\nexport {\n coreAiContextSnippets,\n defaultAiContextSnippets,\n packageSourceSnippet,\n techStackRecommendationsSnippet,\n type AiContextSnippet,\n type AiContextSnippetDefinition,\n} from \"@overmux/ai-context\";\n\nexport const composeAiContext = (snippets: AiContextSnippetDefinition) =>\n snippets.length === 0\n ? \"\"\n : `${snippets\n .map(\n (snippet) => `## ${snippet}\\n\\n${aiContextContentBySnippet[snippet]}`,\n )\n .join(\"\\n\\n\")}\\n`;\n","import { z } from \"zod\";\n\nimport type { AiContextSnippetDefinition } from \"./ai-context\";\nimport type { Notifications } from \"./notifications\";\nimport type { ResourceContract, StreamContract } from \"./contracts\";\n\nexport type RuntimeDisposer = () => Promise<void> | void;\n\nexport type InstanceContext = {\n getInstanceId: () => string;\n getDeepLinkPrefix: () => string;\n};\n\ntype ResourceInputMap = Readonly<Record<string, unknown>>;\n\n// Keep IDs paired with their raw inputs when checking calls and reusable handlers.\ntype InvalidationArguments<TInputs extends ResourceInputMap> = {\n [TId in keyof TInputs & string]: [resourceId: TId, input?: TInputs[TId]];\n}[keyof TInputs & string];\n\nexport type HandlerContext<TInputs extends ResourceInputMap = {}> = {\n instance: InstanceContext;\n invalidate: (...args: InvalidationArguments<TInputs>) => void;\n signal: AbortSignal;\n};\n\nexport type OperationContext<TInputs extends ResourceInputMap = {}> =\n HandlerContext<TInputs> & {\n notifications: Notifications;\n };\n\nexport type OperationDefinition<\n TInput extends z.ZodType = z.ZodType,\n TOutput extends z.ZodType = z.ZodVoid,\n TContext = OperationContext,\n> = {\n handle: (\n input: z.output<TInput>,\n context: TContext,\n ) => Promise<z.input<NoInfer<TOutput>>> | z.input<NoInfer<TOutput>>;\n input: TInput;\n output: TOutput;\n};\n\n// Infer schemas from this definition, not a surrounding operation map's broad constraint.\nexport const defineOperation = <\n TInput extends z.ZodType,\n TOutput extends z.ZodType = z.ZodVoid,\n TContext = OperationContext,\n>({\n handle,\n input,\n output,\n}: {\n handle: OperationDefinition<TInput, TOutput, TContext>[\"handle\"];\n input: TInput;\n output?: TOutput;\n}): OperationDefinition<NoInfer<TInput>, NoInfer<TOutput>, TContext> => ({\n handle,\n input,\n output: (output ?? z.void()) as TOutput,\n});\n\nexport type QueryResourceDefinition<\n TInput extends z.ZodType = z.ZodType,\n TOutput extends z.ZodType = z.ZodType,\n TContext = HandlerContext,\n> = {\n contract: ResourceContract<TInput, TOutput>;\n kind: \"query\";\n read: (\n input: z.output<TInput>,\n context: TContext,\n ) => Promise<z.input<NoInfer<TOutput>>> | z.input<NoInfer<TOutput>>;\n};\n\nexport type SubscriptionResourceDefinition<\n TInput extends z.ZodType = z.ZodType,\n TOutput extends z.ZodType = z.ZodType,\n TContext = HandlerContext,\n> = {\n contract: ResourceContract<TInput, TOutput>;\n kind: \"subscription\";\n read: QueryResourceDefinition<TInput, TOutput, TContext>[\"read\"];\n subscribe: (\n input: z.output<TInput>,\n invalidate: () => void,\n context: TContext,\n ) => RuntimeDisposer;\n};\n\nexport type DerivedResourceDefinition<\n TInput extends z.ZodType = z.ZodType,\n TOutput extends z.ZodType = z.ZodType,\n TDependencies extends Readonly<Record<string, string>> = Readonly<\n Record<string, string>\n >,\n TDependencyOutputs = Readonly<Record<string, unknown>>,\n> = {\n combine: (dependencies: TDependencyOutputs) => z.input<NoInfer<TOutput>>;\n contract: ResourceContract<TInput, TOutput>;\n dependencies: TDependencies;\n kind: \"derived\";\n};\n\ntype AnyZodType = z.ZodType<any, any, any>;\n\nexport type ResourceDefinition =\n | QueryResourceDefinition<\n AnyZodType,\n AnyZodType,\n HandlerContext<ResourceInputMap>\n >\n | SubscriptionResourceDefinition<\n AnyZodType,\n AnyZodType,\n HandlerContext<ResourceInputMap>\n >\n | DerivedResourceDefinition<AnyZodType, AnyZodType, any, any>;\n\nexport type StreamSession<TClientMessage = unknown> = {\n dispose?: RuntimeDisposer;\n onMessage?: (message: TClientMessage) => Promise<void> | void;\n};\n\nexport type StreamHandlerDefinition<\n TInput extends z.ZodType = z.ZodType,\n TClientMessage extends z.ZodType = z.ZodType,\n TServerMessage extends z.ZodType = z.ZodType,\n TContext = HandlerContext,\n> = {\n contract: StreamContract<TInput, TClientMessage, TServerMessage>;\n open: (\n input: z.output<TInput>,\n context: TContext & {\n emit: (message: z.input<NoInfer<TServerMessage>>) => void;\n fail: (cause: unknown) => void;\n },\n ) =>\n | Promise<StreamSession<z.output<TClientMessage>>>\n | StreamSession<z.output<TClientMessage>>;\n};\n\nexport const defineStreamHandler = <\n TInput extends z.ZodType,\n TClientMessage extends z.ZodType,\n TServerMessage extends z.ZodType,\n TContext = HandlerContext,\n>(\n contract: StreamContract<TInput, TClientMessage, TServerMessage>,\n open: StreamHandlerDefinition<\n TInput,\n TClientMessage,\n TServerMessage,\n TContext\n >[\"open\"],\n): StreamHandlerDefinition<\n TInput,\n TClientMessage,\n TServerMessage,\n TContext\n> => ({\n contract,\n open,\n});\n\ntype ResourceContracts = Record<\n string,\n ResourceContract<AnyZodType, AnyZodType>\n>;\n\ntype ResourceInputs<TContracts extends ResourceContracts> = {\n [TId in keyof TContracts]: z.input<TContracts[TId][\"input\"]>;\n};\n\ntype DependencyOutputs<\n TContracts extends ResourceContracts,\n TDependencies extends Record<string, unknown>,\n> = {\n [TName in keyof TDependencies]: TDependencies[TName] extends keyof TContracts\n ? z.output<TContracts[TDependencies[TName]][\"output\"]>\n : never;\n};\n\ntype DependencySource<TDependencies> = {\n [TId in keyof TDependencies]: TDependencies[TId] extends Record<\n string,\n string\n >\n ? { dependencies: TDependencies[TId] }\n : { dependencies?: never };\n};\n\ntype QueryFor<\n TContract extends ResourceContract<AnyZodType, AnyZodType>,\n TContracts extends ResourceContracts,\n> = {\n contract: TContract;\n} & Omit<\n QueryResourceDefinition<\n TContract[\"input\"],\n TContract[\"output\"],\n HandlerContext<ResourceInputs<NoInfer<TContracts>>>\n >,\n \"contract\"\n>;\n\ntype SubscriptionFor<\n TContract extends ResourceContract<AnyZodType, AnyZodType>,\n TContracts extends ResourceContracts,\n> = { contract: TContract } & Omit<\n SubscriptionResourceDefinition<\n TContract[\"input\"],\n TContract[\"output\"],\n HandlerContext<ResourceInputs<NoInfer<TContracts>>>\n >,\n \"contract\"\n>;\n\ntype DerivedFor<\n TContract extends ResourceContract<AnyZodType, AnyZodType>,\n TDependencies extends Record<string, string>,\n TDependencyOutputs,\n> = {\n combine: (\n dependencies: TDependencyOutputs,\n ) => z.input<NoInfer<TContract[\"output\"]>>;\n contract: TContract;\n dependencies: TDependencies;\n kind: \"derived\";\n};\n\ntype ConfiguredResource<\n TContracts extends ResourceContracts,\n TDependencies,\n TId extends keyof TContracts,\n> =\n | QueryFor<TContracts[TId], TContracts>\n | SubscriptionFor<TContracts[TId], TContracts>\n | (TId extends keyof TDependencies\n ? TDependencies[TId] extends Record<\n string,\n Exclude<keyof TContracts, TId> & string\n >\n ? DerivedFor<\n TContracts[TId],\n TDependencies[TId],\n DependencyOutputs<TContracts, NoInfer<TDependencies[TId]>>\n >\n : never\n : never);\n\ntype ConfiguredResources<\n TContracts extends ResourceContracts,\n TDependencies,\n> = {\n [TId in keyof TContracts]: ConfiguredResource<TContracts, TDependencies, TId>;\n} & DependencySource<TDependencies>;\n\nexport type AuthDuration = `${number}${\"m\" | \"h\" | \"d\"}`;\n\nexport type AuthConfigDefinition = {\n mode: \"cli-login\";\n origins?: string[];\n sessionLifetime?: \"forever\" | AuthDuration;\n trustedProxyPeer?: string;\n};\n\nexport type ServerConfigDefinition = {\n host?: string;\n port?: number;\n productionWebAssetsDir?: string;\n watch?: boolean;\n};\n\ntype StreamDefinitions<TContext = HandlerContext<ResourceInputMap>> = Readonly<\n Record<\n string,\n StreamHandlerDefinition<AnyZodType, AnyZodType, AnyZodType, TContext>\n >\n>;\n\ntype OperationDefinitions = Readonly<\n Record<\n string,\n OperationDefinition<\n AnyZodType,\n AnyZodType,\n OperationContext<ResourceInputMap>\n >\n >\n>;\n\ntype OperationInputs = Record<string, AnyZodType>;\n\ntype OperationOutputSchema<\n TOutputs,\n TId extends PropertyKey,\n> = TId extends keyof TOutputs\n ? TOutputs[TId] extends z.ZodType\n ? TOutputs[TId]\n : z.ZodVoid\n : z.ZodVoid;\n\ntype ConfiguredOperations<\n TInputs extends OperationInputs,\n TOutputs,\n TContracts extends ResourceContracts,\n> = {\n [TId in keyof TInputs]: {\n input: TInputs[TId];\n output?: OperationOutputSchema<TOutputs, TId>;\n handle: OperationDefinition<\n TInputs[TId],\n OperationOutputSchema<TOutputs, TId>,\n OperationContext<ResourceInputs<TContracts>>\n >[\"handle\"];\n };\n} & {\n [TId in keyof TOutputs]: TOutputs[TId] extends z.ZodType\n ? { output: TOutputs[TId] }\n : { output?: never };\n};\n\ntype NormalizedOperations<\n TInputs extends OperationInputs,\n TOutputs,\n TContracts extends ResourceContracts,\n> = {\n [TId in keyof TInputs]: OperationDefinition<\n TInputs[TId],\n OperationOutputSchema<TOutputs, TId>,\n OperationContext<ResourceInputs<TContracts>>\n >;\n};\n\nconst normalizeOperations = <\n TInputs extends OperationInputs,\n TOutputs,\n TContracts extends ResourceContracts,\n>(\n operations: ConfiguredOperations<TInputs, TOutputs, TContracts> | undefined,\n): NormalizedOperations<TInputs, TOutputs, TContracts> | undefined => {\n if (operations === undefined) {\n return undefined;\n }\n // Preserve every key and handler; only absent output schemas become ZodVoid.\n return Object.fromEntries(\n Object.entries(operations).map(([id, definition]) => [\n id,\n { ...definition, output: definition.output ?? z.void() },\n ]),\n ) as NormalizedOperations<TInputs, TOutputs, TContracts>;\n};\n\nexport type ConfigDefinition<\n TResources extends Readonly<Record<string, unknown>> = Readonly<\n Record<string, ResourceDefinition>\n >,\n TStreams extends StreamDefinitions = StreamDefinitions,\n TOperations extends OperationDefinitions = OperationDefinitions,\n> = {\n operations?: TOperations;\n resources: TResources;\n streams?: TStreams;\n};\n\nexport type OvermuxConfigDefinition<\n TServer extends ConfigDefinition = ConfigDefinition,\n> = ServerConfigDefinition & {\n aiContextSnippets?: AiContextSnippetDefinition;\n auth: AuthConfigDefinition;\n debug?: boolean;\n instanceId?: string | ((context: { port: number }) => string);\n server: TServer;\n vite?: string;\n};\n\nexport type OvermuxServerResources<TServer> = TServer extends {\n resources: infer TResources;\n}\n ? TResources\n : never;\n\nexport type OvermuxServerStreams<TServer> = TServer extends {\n streams?: infer TStreams;\n}\n ? NonNullable<TStreams>\n : never;\n\nexport type OvermuxServerOperations<TServer> = TServer extends {\n operations?: infer TOperations;\n}\n ? NonNullable<TOperations>\n : never;\n\nexport const defineOvermuxServer = <\n const TContracts extends ResourceContracts = {},\n const TDependencies = {},\n const TStreams extends StreamDefinitions = {},\n const TInputs extends OperationInputs = {},\n const TOutputs = {},\n>(definition: {\n operations?: ConfiguredOperations<TInputs, TOutputs, NoInfer<TContracts>>;\n resources: ConfiguredResources<TContracts, TDependencies>;\n streams?: TStreams &\n StreamDefinitions<HandlerContext<ResourceInputs<NoInfer<TContracts>>>>;\n}): ConfigDefinition<\n ConfiguredResources<TContracts, TDependencies>,\n TStreams,\n NormalizedOperations<TInputs, TOutputs, TContracts>\n> => ({\n ...definition,\n operations: normalizeOperations(definition.operations),\n});\n\nexport const defineOvermuxConfig = <const TServer extends ConfigDefinition>(\n definition: OvermuxConfigDefinition<TServer>,\n): OvermuxConfigDefinition<TServer> => definition;\n","import { z } from \"zod\";\n\nexport const noInputSchema = z.void();\n\nexport const jsonValueSchema: z.ZodType<unknown> = z.lazy(() =>\n z.union([\n z.string(),\n z.number().finite(),\n z.boolean(),\n z.null(),\n z.array(jsonValueSchema),\n z.record(z.string(), jsonValueSchema),\n ]),\n);\n\nexport const parseJsonValue = <T>(value: T): T =>\n jsonValueSchema.parse(value) as T;\n\nexport type ContractInputArguments<TInput extends z.ZodType> =\n undefined extends z.input<TInput>\n ? [input?: Exclude<z.input<TInput>, undefined>]\n : [input: z.input<TInput>];\n\nexport type ResourceContract<\n TInput extends z.ZodType = z.ZodType,\n TOutput extends z.ZodType = z.ZodType,\n> = {\n input: TInput;\n output: TOutput;\n};\n\nexport const defineResourceContract = <\n TInput extends z.ZodType,\n TOutput extends z.ZodType,\n>(\n contract: ResourceContract<TInput, TOutput>,\n): ResourceContract<TInput, TOutput> => contract;\n\nexport type StreamContract<\n TInput extends z.ZodType = z.ZodType,\n TClientMessage extends z.ZodType = z.ZodType,\n TServerMessage extends z.ZodType = z.ZodType,\n> = {\n clientMessage: TClientMessage;\n input: TInput;\n serverMessage: TServerMessage;\n};\n\nexport const defineStreamContract = <\n TInput extends z.ZodType,\n TClientMessage extends z.ZodType,\n TServerMessage extends z.ZodType,\n>(\n contract: StreamContract<TInput, TClientMessage, TServerMessage>,\n): StreamContract<TInput, TClientMessage, TServerMessage> => contract;\n"],"mappings":";;;AACA,MAAM,uBAAuB;AAC7B,MAAM,kCAAkC;AAExC,MAAM,wBAAwB,CAAC,oBAAoB;AACnD,MAAM,2BAA2B,CAAC,GAAG,uBAAuB,+BAA+B;AAC3F,MAAM,8BAA8B;;;;;;;AAOpC,MAAM,yCAAyC;AAC/C,MAAM,4BAA4B;EAChC,uBAAuB;EACvB,kCAAkC;AACpC;;;ACHA,MAAa,oBAAoB,aAC/B,SAAS,WAAW,IAChB,KACA,GAAG,SACA,KACE,YAAY,MAAM,QAAQ,MAAM,0BAA0B,UAC7D,CAAC,CACA,KAAK,MAAM,EAAE;;;ACwBtB,MAAa,mBAIX,EACA,QACA,OACA,cAKuE;CACvE;CACA;CACA,QAAS,UAAU,EAAE,KAAK;AAC5B;AAkFA,MAAa,uBAMX,UACA,UAWI;CACJ;CACA;AACF;AA4KA,MAAM,uBAKJ,eACoE;CACpE,IAAI,eAAe,KAAA,GACjB;CAGF,OAAO,OAAO,YACZ,OAAO,QAAQ,UAAU,CAAC,CAAC,KAAK,CAAC,IAAI,gBAAgB,CACnD,IACA;EAAE,GAAG;EAAY,QAAQ,WAAW,UAAU,EAAE,KAAK;CAAE,CACzD,CAAC,CACH;AACF;AA2CA,MAAa,uBAMX,gBASI;CACJ,GAAG;CACH,YAAY,oBAAoB,WAAW,UAAU;AACvD;AAEA,MAAa,uBACX,eACqC;;;AChavC,MAAa,gBAAgB,EAAE,KAAK;AAEpC,MAAa,kBAAsC,EAAE,WACnD,EAAE,MAAM;CACN,EAAE,OAAO;CACT,EAAE,OAAO,CAAC,CAAC,OAAO;CAClB,EAAE,QAAQ;CACV,EAAE,KAAK;CACP,EAAE,MAAM,eAAe;CACvB,EAAE,OAAO,EAAE,OAAO,GAAG,eAAe;AACtC,CAAC,CACH;AAEA,MAAa,kBAAqB,UAChC,gBAAgB,MAAM,KAAK;AAe7B,MAAa,0BAIX,aACsC;AAYxC,MAAa,wBAKX,aAC2D"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../ai-context/dist/index.js","../../src/public/ai-context.ts","../../src/public/config.ts","../../src/public/contracts.ts"],"sourcesContent":["//#region src/index.ts\nconst packageSourceSnippet = \"package-source\";\nconst techStackRecommendationsSnippet = \"tech-stack-recommendations\";\nconst aiContextSnippets = [packageSourceSnippet, techStackRecommendationsSnippet];\nconst coreAiContextSnippets = [packageSourceSnippet];\nconst defaultAiContextSnippets = [...coreAiContextSnippets, techStackRecommendationsSnippet];\nconst packageSourceSnippetContent = `Overmux ships with documentation and TypeScript source.\n\nRun \\`overmux docs path\\` to find the installed documentation directory for the Overmux CLI. This prints a documentation directory, not source paths.\n\nInspect TypeScript source in installed packages, e.g. \\`node_modules/overmux/src\\` and \\`node_modules/@overmux/xterm/src\\`.\n\nInspect these files so guidance matches the versions used by the application.`;\nconst techStackRecommendationsSnippetContent = `Prefer pnpm as the package manager, TanStack Router for routing, shadcn/ui for UI components, and Zod for schemas and runtime validation. For custom Git diff views, prefer @pierre/diffs (https://diffs.com/). Follow the application's established stack when it already differs.`;\nconst aiContextContentBySnippet = {\n\t[packageSourceSnippet]: packageSourceSnippetContent,\n\t[techStackRecommendationsSnippet]: techStackRecommendationsSnippetContent\n};\n//#endregion\nexport { aiContextContentBySnippet, aiContextSnippets, coreAiContextSnippets, defaultAiContextSnippets, packageSourceSnippet, techStackRecommendationsSnippet };\n\n//# sourceMappingURL=index.js.map","import {\n aiContextContentBySnippet,\n type AiContextSnippetDefinition,\n} from \"@overmux/ai-context\";\n\nexport {\n coreAiContextSnippets,\n defaultAiContextSnippets,\n packageSourceSnippet,\n techStackRecommendationsSnippet,\n type AiContextSnippet,\n type AiContextSnippetDefinition,\n} from \"@overmux/ai-context\";\n\nexport const composeAiContext = (snippets: AiContextSnippetDefinition) =>\n snippets.length === 0\n ? \"\"\n : `${snippets\n .map(\n (snippet) => `## ${snippet}\\n\\n${aiContextContentBySnippet[snippet]}`,\n )\n .join(\"\\n\\n\")}\\n`;\n","import { z } from \"zod\";\n\nimport type { AiContextSnippetDefinition } from \"./ai-context\";\nimport type { Notifications } from \"./notifications\";\nimport type { ResourceContract, StreamContract } from \"./contracts\";\n\nexport type RuntimeDisposer = () => Promise<void> | void;\n\nexport type InstanceContext = {\n getInstanceId: () => string;\n getDeepLinkPrefix: () => string;\n};\n\ntype ResourceInputMap = Readonly<Record<string, unknown>>;\n\n// Keep IDs paired with their raw inputs when checking calls and reusable handlers.\ntype InvalidationArguments<TInputs extends ResourceInputMap> = {\n [TId in keyof TInputs & string]: [resourceId: TId, input?: TInputs[TId]];\n}[keyof TInputs & string];\n\nexport type HandlerContext<TInputs extends ResourceInputMap = {}> = {\n instance: InstanceContext;\n invalidate: (...args: InvalidationArguments<TInputs>) => void;\n signal: AbortSignal;\n};\n\nexport type OperationContext<TInputs extends ResourceInputMap = {}> =\n HandlerContext<TInputs> & {\n notifications: Notifications;\n };\n\nexport type OperationDefinition<\n TInput extends z.ZodType = z.ZodType,\n TOutput extends z.ZodType = z.ZodVoid,\n TContext = OperationContext,\n> = {\n handle: (\n input: z.output<TInput>,\n context: TContext,\n ) => Promise<z.input<NoInfer<TOutput>>> | z.input<NoInfer<TOutput>>;\n input: TInput;\n output: TOutput;\n};\n\n// Infer schemas from this definition, not a surrounding operation map's broad constraint.\nexport const defineOperation = <\n TInput extends z.ZodType,\n TOutput extends z.ZodType = z.ZodVoid,\n TContext = OperationContext,\n>({\n handle,\n input,\n output,\n}: {\n handle: OperationDefinition<TInput, TOutput, TContext>[\"handle\"];\n input: TInput;\n output?: TOutput;\n}): OperationDefinition<NoInfer<TInput>, NoInfer<TOutput>, TContext> => ({\n handle,\n input,\n output: (output ?? z.void()) as TOutput,\n});\n\nexport type QueryResourceDefinition<\n TInput extends z.ZodType = z.ZodType,\n TOutput extends z.ZodType = z.ZodType,\n TContext = HandlerContext,\n> = {\n contract: ResourceContract<TInput, TOutput>;\n kind: \"query\";\n read: (\n input: z.output<TInput>,\n context: TContext,\n ) => Promise<z.input<NoInfer<TOutput>>> | z.input<NoInfer<TOutput>>;\n};\n\nexport type SubscriptionResourceDefinition<\n TInput extends z.ZodType = z.ZodType,\n TOutput extends z.ZodType = z.ZodType,\n TContext = HandlerContext,\n> = {\n contract: ResourceContract<TInput, TOutput>;\n kind: \"subscription\";\n read: QueryResourceDefinition<TInput, TOutput, TContext>[\"read\"];\n subscribe: (\n input: z.output<TInput>,\n invalidate: () => void,\n context: TContext,\n ) => RuntimeDisposer | Promise<RuntimeDisposer>;\n};\n\nexport type DerivedResourceDefinition<\n TInput extends z.ZodType = z.ZodType,\n TOutput extends z.ZodType = z.ZodType,\n TDependencies extends Readonly<Record<string, string>> = Readonly<\n Record<string, string>\n >,\n TDependencyOutputs = Readonly<Record<string, unknown>>,\n> = {\n combine: (dependencies: TDependencyOutputs) => z.input<NoInfer<TOutput>>;\n contract: ResourceContract<TInput, TOutput>;\n dependencies: TDependencies;\n kind: \"derived\";\n};\n\ntype AnyZodType = z.ZodType<any, any, any>;\n\nexport type ResourceDefinition =\n | QueryResourceDefinition<\n AnyZodType,\n AnyZodType,\n HandlerContext<ResourceInputMap>\n >\n | SubscriptionResourceDefinition<\n AnyZodType,\n AnyZodType,\n HandlerContext<ResourceInputMap>\n >\n | DerivedResourceDefinition<AnyZodType, AnyZodType, any, any>;\n\nexport type StreamSession<TClientMessage = unknown> = {\n dispose?: RuntimeDisposer;\n onMessage?: (message: TClientMessage) => Promise<void> | void;\n};\n\nexport type StreamHandlerDefinition<\n TInput extends z.ZodType = z.ZodType,\n TClientMessage extends z.ZodType = z.ZodType,\n TServerMessage extends z.ZodType = z.ZodType,\n TContext = HandlerContext,\n> = {\n contract: StreamContract<TInput, TClientMessage, TServerMessage>;\n open: (\n input: z.output<TInput>,\n context: TContext & {\n emit: (message: z.input<NoInfer<TServerMessage>>) => void;\n fail: (cause: unknown) => void;\n },\n ) =>\n | Promise<StreamSession<z.output<TClientMessage>>>\n | StreamSession<z.output<TClientMessage>>;\n};\n\nexport const defineStreamHandler = <\n TInput extends z.ZodType,\n TClientMessage extends z.ZodType,\n TServerMessage extends z.ZodType,\n TContext = HandlerContext,\n>(\n contract: StreamContract<TInput, TClientMessage, TServerMessage>,\n open: StreamHandlerDefinition<\n TInput,\n TClientMessage,\n TServerMessage,\n TContext\n >[\"open\"],\n): StreamHandlerDefinition<\n TInput,\n TClientMessage,\n TServerMessage,\n TContext\n> => ({\n contract,\n open,\n});\n\ntype ResourceContracts = Record<\n string,\n ResourceContract<AnyZodType, AnyZodType>\n>;\n\ntype ResourceInputs<TContracts extends ResourceContracts> = {\n [TId in keyof TContracts]: z.input<TContracts[TId][\"input\"]>;\n};\n\ntype DependencyOutputs<\n TContracts extends ResourceContracts,\n TDependencies extends Record<string, unknown>,\n> = {\n [TName in keyof TDependencies]: TDependencies[TName] extends keyof TContracts\n ? z.output<TContracts[TDependencies[TName]][\"output\"]>\n : never;\n};\n\ntype DependencySource<TDependencies> = {\n [TId in keyof TDependencies]: TDependencies[TId] extends Record<\n string,\n string\n >\n ? { dependencies: TDependencies[TId] }\n : { dependencies?: never };\n};\n\ntype QueryFor<\n TContract extends ResourceContract<AnyZodType, AnyZodType>,\n TContracts extends ResourceContracts,\n> = {\n contract: TContract;\n} & Omit<\n QueryResourceDefinition<\n TContract[\"input\"],\n TContract[\"output\"],\n HandlerContext<ResourceInputs<NoInfer<TContracts>>>\n >,\n \"contract\"\n>;\n\ntype SubscriptionFor<\n TContract extends ResourceContract<AnyZodType, AnyZodType>,\n TContracts extends ResourceContracts,\n> = { contract: TContract } & Omit<\n SubscriptionResourceDefinition<\n TContract[\"input\"],\n TContract[\"output\"],\n HandlerContext<ResourceInputs<NoInfer<TContracts>>>\n >,\n \"contract\"\n>;\n\ntype DerivedFor<\n TContract extends ResourceContract<AnyZodType, AnyZodType>,\n TDependencies extends Record<string, string>,\n TDependencyOutputs,\n> = {\n combine: (\n dependencies: TDependencyOutputs,\n ) => z.input<NoInfer<TContract[\"output\"]>>;\n contract: TContract;\n dependencies: TDependencies;\n kind: \"derived\";\n};\n\ntype ConfiguredResource<\n TContracts extends ResourceContracts,\n TDependencies,\n TId extends keyof TContracts,\n> =\n | QueryFor<TContracts[TId], TContracts>\n | SubscriptionFor<TContracts[TId], TContracts>\n | (TId extends keyof TDependencies\n ? TDependencies[TId] extends Record<\n string,\n Exclude<keyof TContracts, TId> & string\n >\n ? DerivedFor<\n TContracts[TId],\n TDependencies[TId],\n DependencyOutputs<TContracts, NoInfer<TDependencies[TId]>>\n >\n : never\n : never);\n\ntype ConfiguredResources<\n TContracts extends ResourceContracts,\n TDependencies,\n> = {\n [TId in keyof TContracts]: ConfiguredResource<TContracts, TDependencies, TId>;\n} & DependencySource<TDependencies>;\n\nexport type AuthDuration = `${number}${\"m\" | \"h\" | \"d\"}`;\n\nexport type AuthConfigDefinition = {\n mode: \"cli-login\";\n origins?: string[];\n sessionLifetime?: \"forever\" | AuthDuration;\n trustedProxyPeer?: string;\n};\n\nexport type ServerConfigDefinition = {\n host?: string;\n port?: number;\n productionWebAssetsDir?: string;\n watch?: boolean;\n};\n\ntype StreamDefinitions<TContext = HandlerContext<ResourceInputMap>> = Readonly<\n Record<\n string,\n StreamHandlerDefinition<AnyZodType, AnyZodType, AnyZodType, TContext>\n >\n>;\n\ntype OperationDefinitions = Readonly<\n Record<\n string,\n OperationDefinition<\n AnyZodType,\n AnyZodType,\n OperationContext<ResourceInputMap>\n >\n >\n>;\n\ntype OperationInputs = Record<string, AnyZodType>;\n\ntype OperationOutputSchema<\n TOutputs,\n TId extends PropertyKey,\n> = TId extends keyof TOutputs\n ? TOutputs[TId] extends z.ZodType\n ? TOutputs[TId]\n : z.ZodVoid\n : z.ZodVoid;\n\ntype ConfiguredOperations<\n TInputs extends OperationInputs,\n TOutputs,\n TContracts extends ResourceContracts,\n> = {\n [TId in keyof TInputs]: {\n input: TInputs[TId];\n output?: OperationOutputSchema<TOutputs, TId>;\n handle: OperationDefinition<\n TInputs[TId],\n OperationOutputSchema<TOutputs, TId>,\n OperationContext<ResourceInputs<TContracts>>\n >[\"handle\"];\n };\n} & {\n [TId in keyof TOutputs]: TOutputs[TId] extends z.ZodType\n ? { output: TOutputs[TId] }\n : { output?: never };\n};\n\ntype NormalizedOperations<\n TInputs extends OperationInputs,\n TOutputs,\n TContracts extends ResourceContracts,\n> = {\n [TId in keyof TInputs]: OperationDefinition<\n TInputs[TId],\n OperationOutputSchema<TOutputs, TId>,\n OperationContext<ResourceInputs<TContracts>>\n >;\n};\n\nconst normalizeOperations = <\n TInputs extends OperationInputs,\n TOutputs,\n TContracts extends ResourceContracts,\n>(\n operations: ConfiguredOperations<TInputs, TOutputs, TContracts> | undefined,\n): NormalizedOperations<TInputs, TOutputs, TContracts> | undefined => {\n if (operations === undefined) {\n return undefined;\n }\n // Preserve every key and handler; only absent output schemas become ZodVoid.\n return Object.fromEntries(\n Object.entries(operations).map(([id, definition]) => [\n id,\n { ...definition, output: definition.output ?? z.void() },\n ]),\n ) as NormalizedOperations<TInputs, TOutputs, TContracts>;\n};\n\nexport type ConfigDefinition<\n TResources extends Readonly<Record<string, unknown>> = Readonly<\n Record<string, ResourceDefinition>\n >,\n TStreams extends StreamDefinitions = StreamDefinitions,\n TOperations extends OperationDefinitions = OperationDefinitions,\n> = {\n operations?: TOperations;\n resources: TResources;\n streams?: TStreams;\n};\n\nexport type OvermuxConfigDefinition<\n TServer extends ConfigDefinition = ConfigDefinition,\n> = ServerConfigDefinition & {\n aiContextSnippets?: AiContextSnippetDefinition;\n auth: AuthConfigDefinition;\n debug?: boolean;\n instanceId?: string | ((context: { port: number }) => string);\n server: TServer;\n vite?: string;\n};\n\nexport type OvermuxServerResources<TServer> = TServer extends {\n resources: infer TResources;\n}\n ? TResources\n : never;\n\nexport type OvermuxServerStreams<TServer> = TServer extends {\n streams?: infer TStreams;\n}\n ? NonNullable<TStreams>\n : never;\n\nexport type OvermuxServerOperations<TServer> = TServer extends {\n operations?: infer TOperations;\n}\n ? NonNullable<TOperations>\n : never;\n\nexport const defineOvermuxServer = <\n const TContracts extends ResourceContracts = {},\n const TDependencies = {},\n const TStreams extends StreamDefinitions = {},\n const TInputs extends OperationInputs = {},\n const TOutputs = {},\n>(definition: {\n operations?: ConfiguredOperations<TInputs, TOutputs, NoInfer<TContracts>>;\n resources: ConfiguredResources<TContracts, TDependencies>;\n streams?: TStreams &\n StreamDefinitions<HandlerContext<ResourceInputs<NoInfer<TContracts>>>>;\n}): ConfigDefinition<\n ConfiguredResources<TContracts, TDependencies>,\n TStreams,\n NormalizedOperations<TInputs, TOutputs, TContracts>\n> => ({\n ...definition,\n operations: normalizeOperations(definition.operations),\n});\n\nexport const defineOvermuxConfig = <const TServer extends ConfigDefinition>(\n definition: OvermuxConfigDefinition<TServer>,\n): OvermuxConfigDefinition<TServer> => definition;\n","import { z } from \"zod\";\n\nexport const noInputSchema = z.void();\n\nexport const jsonValueSchema: z.ZodType<unknown> = z.lazy(() =>\n z.union([\n z.string(),\n z.number().finite(),\n z.boolean(),\n z.null(),\n z.array(jsonValueSchema),\n z.record(z.string(), jsonValueSchema),\n ]),\n);\n\nexport const parseJsonValue = <T>(value: T): T =>\n jsonValueSchema.parse(value) as T;\n\nexport type ContractInputArguments<TInput extends z.ZodType> =\n undefined extends z.input<TInput>\n ? [input?: Exclude<z.input<TInput>, undefined>]\n : [input: z.input<TInput>];\n\nexport type ResourceContract<\n TInput extends z.ZodType = z.ZodType,\n TOutput extends z.ZodType = z.ZodType,\n> = {\n input: TInput;\n output: TOutput;\n};\n\nexport const defineResourceContract = <\n TInput extends z.ZodType,\n TOutput extends z.ZodType,\n>(\n contract: ResourceContract<TInput, TOutput>,\n): ResourceContract<TInput, TOutput> => contract;\n\nexport type StreamContract<\n TInput extends z.ZodType = z.ZodType,\n TClientMessage extends z.ZodType = z.ZodType,\n TServerMessage extends z.ZodType = z.ZodType,\n> = {\n clientMessage: TClientMessage;\n input: TInput;\n serverMessage: TServerMessage;\n};\n\nexport const defineStreamContract = <\n TInput extends z.ZodType,\n TClientMessage extends z.ZodType,\n TServerMessage extends z.ZodType,\n>(\n contract: StreamContract<TInput, TClientMessage, TServerMessage>,\n): StreamContract<TInput, TClientMessage, TServerMessage> => contract;\n"],"mappings":";;;AACA,MAAM,uBAAuB;AAC7B,MAAM,kCAAkC;AAExC,MAAM,wBAAwB,CAAC,oBAAoB;AACnD,MAAM,2BAA2B,CAAC,GAAG,uBAAuB,+BAA+B;AAC3F,MAAM,8BAA8B;;;;;;;AAOpC,MAAM,yCAAyC;AAC/C,MAAM,4BAA4B;EAChC,uBAAuB;EACvB,kCAAkC;AACpC;;;ACHA,MAAa,oBAAoB,aAC/B,SAAS,WAAW,IAChB,KACA,GAAG,SACA,KACE,YAAY,MAAM,QAAQ,MAAM,0BAA0B,UAC7D,CAAC,CACA,KAAK,MAAM,EAAE;;;ACwBtB,MAAa,mBAIX,EACA,QACA,OACA,cAKuE;CACvE;CACA;CACA,QAAS,UAAU,EAAE,KAAK;AAC5B;AAkFA,MAAa,uBAMX,UACA,UAWI;CACJ;CACA;AACF;AA4KA,MAAM,uBAKJ,eACoE;CACpE,IAAI,eAAe,KAAA,GACjB;CAGF,OAAO,OAAO,YACZ,OAAO,QAAQ,UAAU,CAAC,CAAC,KAAK,CAAC,IAAI,gBAAgB,CACnD,IACA;EAAE,GAAG;EAAY,QAAQ,WAAW,UAAU,EAAE,KAAK;CAAE,CACzD,CAAC,CACH;AACF;AA2CA,MAAa,uBAMX,gBASI;CACJ,GAAG;CACH,YAAY,oBAAoB,WAAW,UAAU;AACvD;AAEA,MAAa,uBACX,eACqC;;;AChavC,MAAa,gBAAgB,EAAE,KAAK;AAEpC,MAAa,kBAAsC,EAAE,WACnD,EAAE,MAAM;CACN,EAAE,OAAO;CACT,EAAE,OAAO,CAAC,CAAC,OAAO;CAClB,EAAE,QAAQ;CACV,EAAE,KAAK;CACP,EAAE,MAAM,eAAe;CACvB,EAAE,OAAO,EAAE,OAAO,GAAG,eAAe;AACtC,CAAC,CACH;AAEA,MAAa,kBAAqB,UAChC,gBAAgB,MAAM,KAAK;AAe7B,MAAa,0BAIX,aACsC;AAYxC,MAAa,wBAKX,aAC2D"}
@@ -1914,12 +1914,26 @@ const subscribeResource = (state, message) => {
1914
1914
  state.subscriptions.set(message.subscriptionId, entry);
1915
1915
  const signal = AbortSignal.any([operationSignal, controller.signal]);
1916
1916
  try {
1917
- entry.dispose = resource.subscribe(message.input, () => void send$1(state, {
1917
+ const dispose = await resource.subscribe(message.input, () => void send$1(state, {
1918
1918
  subscriptionId: message.subscriptionId,
1919
1919
  type: "resource-invalidated"
1920
1920
  }), signal);
1921
+ if (state.subscriptions.get(message.subscriptionId) === entry) entry.dispose = dispose;
1922
+ else await dispose();
1921
1923
  } catch (cause) {
1922
- await disposeSubscription(state, message.subscriptionId);
1924
+ if (signal.aborted) {
1925
+ if (cause !== signal.reason) state.serverLogger?.log({
1926
+ correlationId: identity.operationId,
1927
+ details: {
1928
+ ...identity,
1929
+ ...errorDetails$1(cause)
1930
+ },
1931
+ event: "resource-subscription-cancelled-error",
1932
+ level: "error"
1933
+ });
1934
+ return;
1935
+ }
1936
+ if (state.subscriptions.get(message.subscriptionId) === entry) await disposeSubscription(state, message.subscriptionId);
1923
1937
  throw cause;
1924
1938
  }
1925
1939
  });
@@ -2793,6 +2807,33 @@ const getInvalidatedResourceIds = (graph, resourceId) => {
2793
2807
  };
2794
2808
  //#endregion
2795
2809
  //#region src/internal/server/runtime/runtime-resources.ts
2810
+ const createSubscriptionLifetime = ({ entry, invalidationListeners, lifecycle, signal }) => {
2811
+ const controller = new AbortController();
2812
+ const subscriptionSignal = AbortSignal.any([lifecycle.requestSignal(signal), controller.signal]);
2813
+ subscriptionSignal.throwIfAborted();
2814
+ const registeredEntry = {
2815
+ ...entry,
2816
+ listener: () => {
2817
+ if (!subscriptionSignal.aborted) entry.listener();
2818
+ }
2819
+ };
2820
+ const disposers = [];
2821
+ const release = lifecycle.track(async () => {
2822
+ invalidationListeners.delete(registeredEntry);
2823
+ await lifecycle.disposeAll(disposers);
2824
+ }, subscriptionSignal);
2825
+ const dispose = () => {
2826
+ controller.abort(/* @__PURE__ */ new Error("Resource subscription closed"));
2827
+ return release();
2828
+ };
2829
+ invalidationListeners.add(registeredEntry);
2830
+ return {
2831
+ dispose,
2832
+ disposers,
2833
+ refresh: registeredEntry.listener,
2834
+ signal: subscriptionSignal
2835
+ };
2836
+ };
2796
2837
  const createRuntimeResources = ({ definitions, instance, lifecycle }) => {
2797
2838
  const graph = createResourceDependencyGraph(definitions);
2798
2839
  const invalidationListeners = /* @__PURE__ */ new Set();
@@ -2824,44 +2865,56 @@ const createRuntimeResources = ({ definitions, instance, lifecycle }) => {
2824
2865
  operationSignal.throwIfAborted();
2825
2866
  return definition.contract.output.parse(rawOutput);
2826
2867
  };
2827
- const activateWatchers = (id, rawInput, signal, activated, disposers) => {
2868
+ const activateSubscriptions = async (id, rawInput, signal, activated, disposers) => {
2869
+ signal.throwIfAborted();
2828
2870
  if (activated.has(id)) return;
2829
2871
  activated.add(id);
2830
2872
  const definition = definitions[id];
2831
2873
  const input = definition.contract.input.parse(rawInput);
2832
2874
  if (definition.kind === "subscription") {
2833
- const dispose = definition.subscribe(input, () => invalidateResource(id, input), context(signal));
2875
+ const dispose = await definition.subscribe(input, () => {
2876
+ if (!signal.aborted) invalidateResource(id, input);
2877
+ }, context(signal));
2834
2878
  if (typeof dispose !== "function") throw new Error(`Resource ${id} subscribe must return a disposer`);
2879
+ if (signal.aborted) {
2880
+ await dispose();
2881
+ signal.throwIfAborted();
2882
+ }
2835
2883
  disposers.push(dispose);
2836
2884
  return;
2837
2885
  }
2838
- if (definition.kind === "derived") graph.dependencies.get(id)?.forEach((dependencyId) => {
2839
- activateWatchers(dependencyId, rawInput, signal, activated, disposers);
2840
- });
2886
+ if (definition.kind === "derived") for (const dependencyId of graph.dependencies.get(id) ?? []) await activateSubscriptions(dependencyId, rawInput, signal, activated, disposers);
2841
2887
  };
2842
2888
  Object.keys(definitions).forEach((name) => {
2843
2889
  resources.set(name, {
2844
2890
  read: (input, signal) => read(name, input, signal),
2845
- subscribe: (rawInput, listener, signal) => {
2891
+ subscribe: async (rawInput, listener, signal) => {
2846
2892
  lifecycle.requestSignal(signal).throwIfAborted();
2847
- const entry = {
2848
- input: definitions[name].contract.input.parse(rawInput),
2849
- listener,
2850
- resourceId: name
2851
- };
2852
- const watcherDisposers = [];
2853
- invalidationListeners.add(entry);
2893
+ const input = definitions[name].contract.input.parse(rawInput);
2894
+ const subscription = createSubscriptionLifetime({
2895
+ entry: {
2896
+ input,
2897
+ listener,
2898
+ resourceId: name
2899
+ },
2900
+ invalidationListeners,
2901
+ lifecycle,
2902
+ signal
2903
+ });
2854
2904
  try {
2855
- activateWatchers(name, rawInput, signal, /* @__PURE__ */ new Set(), watcherDisposers);
2905
+ await activateSubscriptions(name, rawInput, subscription.signal, /* @__PURE__ */ new Set(), subscription.disposers);
2906
+ subscription.signal.throwIfAborted();
2907
+ subscription.refresh();
2908
+ subscription.signal.throwIfAborted();
2909
+ return subscription.dispose;
2856
2910
  } catch (cause) {
2857
- invalidationListeners.delete(entry);
2858
- lifecycle.disposeAll(watcherDisposers).catch(() => void 0);
2911
+ try {
2912
+ await subscription.dispose();
2913
+ } catch (cleanupError) {
2914
+ throw new AggregateError([cause, cleanupError], "Resource subscription setup and cleanup failed");
2915
+ }
2859
2916
  throw cause;
2860
2917
  }
2861
- return lifecycle.track(async () => {
2862
- invalidationListeners.delete(entry);
2863
- await lifecycle.disposeAll(watcherDisposers);
2864
- }, signal);
2865
2918
  }
2866
2919
  });
2867
2920
  });