@agent-native/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dist/adapters/firestore/config.d.ts +20 -0
  2. package/dist/adapters/firestore/config.d.ts.map +1 -0
  3. package/dist/adapters/firestore/config.js +50 -0
  4. package/dist/adapters/firestore/config.js.map +1 -0
  5. package/dist/adapters/firestore/index.d.ts +4 -0
  6. package/dist/adapters/firestore/index.d.ts.map +1 -0
  7. package/dist/adapters/firestore/index.js +4 -0
  8. package/dist/adapters/firestore/index.js.map +1 -0
  9. package/dist/adapters/firestore/merge.d.ts +21 -0
  10. package/dist/adapters/firestore/merge.d.ts.map +1 -0
  11. package/dist/adapters/firestore/merge.js +132 -0
  12. package/dist/adapters/firestore/merge.js.map +1 -0
  13. package/dist/adapters/firestore/sync.d.ts +91 -0
  14. package/dist/adapters/firestore/sync.d.ts.map +1 -0
  15. package/dist/adapters/firestore/sync.js +340 -0
  16. package/dist/adapters/firestore/sync.js.map +1 -0
  17. package/dist/cli/create.d.ts +5 -0
  18. package/dist/cli/create.d.ts.map +1 -0
  19. package/dist/cli/create.js +87 -0
  20. package/dist/cli/create.js.map +1 -0
  21. package/dist/cli/index.d.ts +3 -0
  22. package/dist/cli/index.d.ts.map +1 -0
  23. package/dist/cli/index.js +27 -0
  24. package/dist/cli/index.js.map +1 -0
  25. package/dist/client/fusion-chat.d.ts +27 -0
  26. package/dist/client/fusion-chat.d.ts.map +1 -0
  27. package/dist/client/fusion-chat.js +19 -0
  28. package/dist/client/fusion-chat.js.map +1 -0
  29. package/dist/client/index.d.ts +5 -0
  30. package/dist/client/index.d.ts.map +1 -0
  31. package/dist/client/index.js +5 -0
  32. package/dist/client/index.js.map +1 -0
  33. package/dist/client/use-file-watcher.d.ts +23 -0
  34. package/dist/client/use-file-watcher.d.ts.map +1 -0
  35. package/dist/client/use-file-watcher.js +40 -0
  36. package/dist/client/use-file-watcher.js.map +1 -0
  37. package/dist/client/use-fusion-chat.d.ts +14 -0
  38. package/dist/client/use-fusion-chat.d.ts.map +1 -0
  39. package/dist/client/use-fusion-chat.js +29 -0
  40. package/dist/client/use-fusion-chat.js.map +1 -0
  41. package/dist/client/utils.d.ts +4 -0
  42. package/dist/client/utils.d.ts.map +1 -0
  43. package/dist/client/utils.js +7 -0
  44. package/dist/client/utils.js.map +1 -0
  45. package/dist/index.d.ts +5 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +8 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/scripts/index.d.ts +3 -0
  50. package/dist/scripts/index.d.ts.map +1 -0
  51. package/dist/scripts/index.js +3 -0
  52. package/dist/scripts/index.js.map +1 -0
  53. package/dist/scripts/runner.d.ts +16 -0
  54. package/dist/scripts/runner.d.ts.map +1 -0
  55. package/dist/scripts/runner.js +42 -0
  56. package/dist/scripts/runner.js.map +1 -0
  57. package/dist/scripts/utils.d.ts +30 -0
  58. package/dist/scripts/utils.d.ts.map +1 -0
  59. package/dist/scripts/utils.js +88 -0
  60. package/dist/scripts/utils.js.map +1 -0
  61. package/dist/server/create-server.d.ts +21 -0
  62. package/dist/server/create-server.d.ts.map +1 -0
  63. package/dist/server/create-server.js +27 -0
  64. package/dist/server/create-server.js.map +1 -0
  65. package/dist/server/index.d.ts +4 -0
  66. package/dist/server/index.d.ts.map +1 -0
  67. package/dist/server/index.js +4 -0
  68. package/dist/server/index.js.map +1 -0
  69. package/dist/server/production.d.ts +18 -0
  70. package/dist/server/production.d.ts.map +1 -0
  71. package/dist/server/production.js +37 -0
  72. package/dist/server/production.js.map +1 -0
  73. package/dist/server/sse.d.ts +30 -0
  74. package/dist/server/sse.d.ts.map +1 -0
  75. package/dist/server/sse.js +44 -0
  76. package/dist/server/sse.js.map +1 -0
  77. package/dist/shared/fusion-chat.d.ts +39 -0
  78. package/dist/shared/fusion-chat.d.ts.map +1 -0
  79. package/dist/shared/fusion-chat.js +52 -0
  80. package/dist/shared/fusion-chat.js.map +1 -0
  81. package/dist/shared/index.d.ts +2 -0
  82. package/dist/shared/index.d.ts.map +1 -0
  83. package/dist/shared/index.js +2 -0
  84. package/dist/shared/index.js.map +1 -0
  85. package/dist/tailwind.preset.d.ts +13 -0
  86. package/dist/tailwind.preset.d.ts.map +1 -0
  87. package/dist/tailwind.preset.js +92 -0
  88. package/dist/tailwind.preset.js.map +1 -0
  89. package/dist/vite/client.d.ts +24 -0
  90. package/dist/vite/client.d.ts.map +1 -0
  91. package/dist/vite/client.js +52 -0
  92. package/dist/vite/client.js.map +1 -0
  93. package/dist/vite/express-plugin.d.ts +11 -0
  94. package/dist/vite/express-plugin.d.ts.map +1 -0
  95. package/dist/vite/express-plugin.js +22 -0
  96. package/dist/vite/express-plugin.js.map +1 -0
  97. package/dist/vite/index.d.ts +4 -0
  98. package/dist/vite/index.d.ts.map +1 -0
  99. package/dist/vite/index.js +4 -0
  100. package/dist/vite/index.js.map +1 -0
  101. package/dist/vite/server.d.ts +21 -0
  102. package/dist/vite/server.d.ts.map +1 -0
  103. package/dist/vite/server.js +68 -0
  104. package/dist/vite/server.js.map +1 -0
  105. package/package.json +82 -0
  106. package/src/templates/default/.env.example +5 -0
  107. package/src/templates/default/.prettierrc +5 -0
  108. package/src/templates/default/AGENTS.md +65 -0
  109. package/src/templates/default/_gitignore +29 -0
  110. package/src/templates/default/client/App.tsx +54 -0
  111. package/src/templates/default/client/global.css +72 -0
  112. package/src/templates/default/client/lib/utils.ts +1 -0
  113. package/src/templates/default/client/vite-env.d.ts +1 -0
  114. package/src/templates/default/components.json +20 -0
  115. package/src/templates/default/index.html +14 -0
  116. package/src/templates/default/package.json +46 -0
  117. package/src/templates/default/postcss.config.js +6 -0
  118. package/src/templates/default/scripts/hello.ts +20 -0
  119. package/src/templates/default/scripts/run.ts +9 -0
  120. package/src/templates/default/server/index.ts +18 -0
  121. package/src/templates/default/server/node-build.ts +4 -0
  122. package/src/templates/default/shared/api.ts +6 -0
  123. package/src/templates/default/tailwind.config.ts +7 -0
  124. package/src/templates/default/tsconfig.json +3 -0
  125. package/src/templates/default/vite.config.server.ts +3 -0
  126. package/src/templates/default/vite.config.ts +3 -0
  127. package/tsconfig.base.json +41 -0
@@ -0,0 +1,40 @@
1
+ import { useEffect } from "react";
2
+ /**
3
+ * Hook that opens an EventSource connection to /api/events and invalidates
4
+ * react-query caches when file changes are detected.
5
+ *
6
+ * @param options.queryClient - The react-query QueryClient instance (from useQueryClient())
7
+ * @param options.queryKeys - Array of query key prefixes to invalidate on change.
8
+ * Default: ["file", "fileTree"]
9
+ * @param options.eventsUrl - SSE endpoint URL. Default: "/api/events"
10
+ * @param options.onEvent - Optional callback for each SSE event
11
+ */
12
+ export function useFileWatcher(options = {}) {
13
+ const { queryClient, onEvent } = options;
14
+ const keys = options.queryKeys ?? ["file", "fileTree"];
15
+ const url = options.eventsUrl ?? "/api/events";
16
+ useEffect(() => {
17
+ const eventSource = new EventSource(url);
18
+ eventSource.onmessage = (event) => {
19
+ try {
20
+ const data = JSON.parse(event.data);
21
+ if (queryClient) {
22
+ for (const key of keys) {
23
+ queryClient.invalidateQueries({ queryKey: [key] });
24
+ }
25
+ }
26
+ onEvent?.(data);
27
+ }
28
+ catch (err) {
29
+ console.error("[useFileWatcher] error parsing event data", err);
30
+ }
31
+ };
32
+ eventSource.onerror = (err) => {
33
+ console.error("[useFileWatcher] SSE connection error", err);
34
+ };
35
+ return () => {
36
+ eventSource.close();
37
+ };
38
+ }, [url, queryClient, onEvent, ...keys]);
39
+ }
40
+ //# sourceMappingURL=use-file-watcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-file-watcher.js","sourceRoot":"","sources":["../../src/client/use-file-watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMlC;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAAC,UAK3B,EAAE;IACJ,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IACzC,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACvD,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,IAAI,aAAa,CAAC;IAE/C,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,GAAG,CAAC,CAAC;QAEzC,WAAW,CAAC,SAAS,GAAG,CAAC,KAAK,EAAE,EAAE;YAChC,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAEpC,IAAI,WAAW,EAAE,CAAC;oBAChB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;wBACvB,WAAW,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;oBACrD,CAAC;gBACH,CAAC;gBAED,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;YAClB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,2CAA2C,EAAE,GAAG,CAAC,CAAC;YAClE,CAAC;QACH,CAAC,CAAC;QAEF,WAAW,CAAC,OAAO,GAAG,CAAC,GAAG,EAAE,EAAE;YAC5B,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,GAAG,CAAC,CAAC;QAC9D,CAAC,CAAC;QAEF,OAAO,GAAG,EAAE;YACV,WAAW,CAAC,KAAK,EAAE,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { type FusionChatMessage } from "./fusion-chat.js";
2
+ /**
3
+ * Hook that wraps sendToFusionChat with a loading state.
4
+ *
5
+ * Returns [isGenerating, send] where:
6
+ * - isGenerating: true after send() is called, false when the
7
+ * builder.fusion.chatRunning event fires with detail.isRunning === false
8
+ * - send: wrapper around sendToFusionChat that sets isGenerating to true
9
+ */
10
+ export declare function useFusionChatGenerating(): [
11
+ boolean,
12
+ (opts: FusionChatMessage) => void
13
+ ];
14
+ //# sourceMappingURL=use-fusion-chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-fusion-chat.d.ts","sourceRoot":"","sources":["../../src/client/use-fusion-chat.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE5E;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,IAAI;IACzC,OAAO;IACP,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI;CAClC,CAqBA"}
@@ -0,0 +1,29 @@
1
+ import { useState, useEffect, useCallback } from "react";
2
+ import { sendToFusionChat } from "./fusion-chat.js";
3
+ /**
4
+ * Hook that wraps sendToFusionChat with a loading state.
5
+ *
6
+ * Returns [isGenerating, send] where:
7
+ * - isGenerating: true after send() is called, false when the
8
+ * builder.fusion.chatRunning event fires with detail.isRunning === false
9
+ * - send: wrapper around sendToFusionChat that sets isGenerating to true
10
+ */
11
+ export function useFusionChatGenerating() {
12
+ const [isGenerating, setIsGenerating] = useState(false);
13
+ useEffect(() => {
14
+ const handler = (e) => {
15
+ const detail = e.detail;
16
+ if (detail?.isRunning === false) {
17
+ setIsGenerating(false);
18
+ }
19
+ };
20
+ window.addEventListener("builder.fusion.chatRunning", handler);
21
+ return () => window.removeEventListener("builder.fusion.chatRunning", handler);
22
+ }, []);
23
+ const send = useCallback((opts) => {
24
+ setIsGenerating(true);
25
+ sendToFusionChat(opts);
26
+ }, []);
27
+ return [isGenerating, send];
28
+ }
29
+ //# sourceMappingURL=use-fusion-chat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-fusion-chat.js","sourceRoot":"","sources":["../../src/client/use-fusion-chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAA0B,MAAM,kBAAkB,CAAC;AAE5E;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB;IAIrC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAExD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,CAAC,CAAQ,EAAE,EAAE;YAC3B,MAAM,MAAM,GAAI,CAAiB,CAAC,MAAM,CAAC;YACzC,IAAI,MAAM,EAAE,SAAS,KAAK,KAAK,EAAE,CAAC;gBAChC,eAAe,CAAC,KAAK,CAAC,CAAC;YACzB,CAAC;QACH,CAAC,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAC;QAC/D,OAAO,GAAG,EAAE,CACV,MAAM,CAAC,mBAAmB,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,IAAI,GAAG,WAAW,CAAC,CAAC,IAAuB,EAAE,EAAE;QACnD,eAAe,CAAC,IAAI,CAAC,CAAC;QACtB,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type ClassValue } from "clsx";
2
+ /** Merge class names with clsx + tailwind-merge. */
3
+ export declare function cn(...inputs: ClassValue[]): string;
4
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/client/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,MAAM,CAAC;AAG7C,oDAAoD;AACpD,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC"}
@@ -0,0 +1,7 @@
1
+ import { clsx } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+ /** Merge class names with clsx + tailwind-merge. */
4
+ export function cn(...inputs) {
5
+ return twMerge(clsx(inputs));
6
+ }
7
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/client/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,MAAM,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,oDAAoD;AACpD,MAAM,UAAU,EAAE,CAAC,GAAG,MAAoB;IACxC,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { createServer, createFileWatcher, createSSEHandler, createProductionServer, } from "./server/index.js";
2
+ export { sendToFusionChat, useFusionChatGenerating, useFileWatcher, cn } from "./client/index.js";
3
+ export { fusionChat } from "./shared/index.js";
4
+ export { runScript, loadEnv, parseArgs, camelCaseArgs, isValidPath, isValidProjectPath, ensureDir, fail, } from "./scripts/index.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAElG,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EACL,SAAS,EACT,OAAO,EACP,SAAS,EACT,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,IAAI,GACL,MAAM,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // Main entry point — re-exports from all subpackages for convenience.
2
+ // Prefer importing from specific subpaths (e.g. "@agent-native/core/server")
3
+ // for better tree-shaking and to avoid pulling in unnecessary dependencies.
4
+ export { createServer, createFileWatcher, createSSEHandler, createProductionServer, } from "./server/index.js";
5
+ export { sendToFusionChat, useFusionChatGenerating, useFileWatcher, cn } from "./client/index.js";
6
+ export { fusionChat } from "./shared/index.js";
7
+ export { runScript, loadEnv, parseArgs, camelCaseArgs, isValidPath, isValidProjectPath, ensureDir, fail, } from "./scripts/index.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,6EAA6E;AAC7E,4EAA4E;AAE5E,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAElG,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EACL,SAAS,EACT,OAAO,EACP,SAAS,EACT,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,IAAI,GACL,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { runScript } from "./runner.js";
2
+ export { loadEnv, parseArgs, camelCaseArgs, isValidPath, isValidProjectPath, ensureDir, fail, } from "./utils.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACL,OAAO,EACP,SAAS,EACT,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,IAAI,GACL,MAAM,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { runScript } from "./runner.js";
2
+ export { loadEnv, parseArgs, camelCaseArgs, isValidPath, isValidProjectPath, ensureDir, fail, } from "./utils.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACL,OAAO,EACP,SAAS,EACT,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,IAAI,GACL,MAAM,YAAY,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Generic script dispatcher for @agent-native/core apps.
3
+ *
4
+ * Dynamically imports and runs scripts from the app's scripts/ directory.
5
+ * Scripts must export a default function: (args: string[]) => Promise<void>
6
+ *
7
+ * Usage: pnpm script <script-name> [--args]
8
+ */
9
+ /**
10
+ * Run the script dispatcher. Call this from your app's scripts/run.ts:
11
+ *
12
+ * import { runScript } from "@agent-native/core/scripts";
13
+ * runScript();
14
+ */
15
+ export declare function runScript(): Promise<void>;
16
+ //# sourceMappingURL=runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/scripts/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,wBAAsB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CA8B/C"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Generic script dispatcher for @agent-native/core apps.
3
+ *
4
+ * Dynamically imports and runs scripts from the app's scripts/ directory.
5
+ * Scripts must export a default function: (args: string[]) => Promise<void>
6
+ *
7
+ * Usage: pnpm script <script-name> [--args]
8
+ */
9
+ /**
10
+ * Run the script dispatcher. Call this from your app's scripts/run.ts:
11
+ *
12
+ * import { runScript } from "@agent-native/core/scripts";
13
+ * runScript();
14
+ */
15
+ export async function runScript() {
16
+ const scriptName = process.argv[2];
17
+ if (!scriptName || scriptName === "--help") {
18
+ console.log(`Usage: pnpm script <script-name> [--arg value ...]`);
19
+ console.log(`\nRun any script with --help for usage details.`);
20
+ process.exit(0);
21
+ }
22
+ // Validate script name (only allow alphanumeric + hyphens)
23
+ if (!/^[a-z][a-z0-9-]*$/.test(scriptName)) {
24
+ console.error(`Error: Invalid script name "${scriptName}"`);
25
+ process.exit(1);
26
+ }
27
+ // Dynamically import and run the script
28
+ try {
29
+ const mod = await import(`./${scriptName}.js`);
30
+ const args = process.argv.slice(3);
31
+ await mod.default(args);
32
+ }
33
+ catch (err) {
34
+ if (err.code === "ERR_MODULE_NOT_FOUND") {
35
+ console.error(`Error: Script "${scriptName}" not found. Run "pnpm script --help" for usage.`);
36
+ process.exit(1);
37
+ }
38
+ console.error(`Script "${scriptName}" failed:`, err.message || err);
39
+ process.exit(1);
40
+ }
41
+ }
42
+ //# sourceMappingURL=runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/scripts/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAEnC,IAAI,CAAC,UAAU,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,oDAAoD,CAAC,CAAC;QAClE,OAAO,CAAC,GAAG,CAAC,iDAAiD,CAAC,CAAC;QAC/D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,2DAA2D;IAC3D,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1C,OAAO,CAAC,KAAK,CAAC,+BAA+B,UAAU,GAAG,CAAC,CAAC;QAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,wCAAwC;IACxC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,CAAC;QAC/C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACnC,MAAM,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,IAAI,GAAG,CAAC,IAAI,KAAK,sBAAsB,EAAE,CAAC;YACxC,OAAO,CAAC,KAAK,CACX,kBAAkB,UAAU,kDAAkD,CAC/E,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,WAAW,UAAU,WAAW,EAAE,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,CAAC;QACpE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Load .env from project root (cwd).
3
+ */
4
+ export declare function loadEnv(envPath?: string): void;
5
+ /**
6
+ * Parse CLI args in --key value format.
7
+ * Supports: --key value, --key=value, --flag (boolean true)
8
+ */
9
+ export declare function parseArgs(args: string[]): Record<string, string>;
10
+ /**
11
+ * Convert kebab-case keys to camelCase.
12
+ */
13
+ export declare function camelCaseArgs(args: Record<string, string>): Record<string, string>;
14
+ /**
15
+ * Validate a relative file path (no traversal, no absolute).
16
+ */
17
+ export declare function isValidPath(p: string): boolean;
18
+ /**
19
+ * Validate a project slug (e.g. "my-project" or "group/my-project").
20
+ */
21
+ export declare function isValidProjectPath(project: string): boolean;
22
+ /**
23
+ * mkdir -p helper.
24
+ */
25
+ export declare function ensureDir(dir: string): void;
26
+ /**
27
+ * Print error to stderr and exit with code 1.
28
+ */
29
+ export declare function fail(message: string): never;
30
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/scripts/utils.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAE9C;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAsBhE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAK9C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAQ3D;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAI3C;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAG3C"}
@@ -0,0 +1,88 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import dotenv from "dotenv";
4
+ /**
5
+ * Load .env from project root (cwd).
6
+ */
7
+ export function loadEnv(envPath) {
8
+ dotenv.config({ path: envPath ?? path.join(process.cwd(), ".env") });
9
+ }
10
+ /**
11
+ * Parse CLI args in --key value format.
12
+ * Supports: --key value, --key=value, --flag (boolean true)
13
+ */
14
+ export function parseArgs(args) {
15
+ const result = {};
16
+ for (let i = 0; i < args.length; i++) {
17
+ const arg = args[i];
18
+ if (!arg.startsWith("--"))
19
+ continue;
20
+ const eqIndex = arg.indexOf("=");
21
+ if (eqIndex !== -1) {
22
+ const key = arg.slice(2, eqIndex);
23
+ result[key] = arg.slice(eqIndex + 1);
24
+ }
25
+ else {
26
+ const key = arg.slice(2);
27
+ const next = args[i + 1];
28
+ if (next && !next.startsWith("--")) {
29
+ result[key] = next;
30
+ i++;
31
+ }
32
+ else {
33
+ result[key] = "true";
34
+ }
35
+ }
36
+ }
37
+ return result;
38
+ }
39
+ /**
40
+ * Convert kebab-case keys to camelCase.
41
+ */
42
+ export function camelCaseArgs(args) {
43
+ const result = {};
44
+ for (const [key, value] of Object.entries(args)) {
45
+ const camel = key.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
46
+ result[camel] = value;
47
+ }
48
+ return result;
49
+ }
50
+ /**
51
+ * Validate a relative file path (no traversal, no absolute).
52
+ */
53
+ export function isValidPath(p) {
54
+ const normalized = path.normalize(p);
55
+ return (!normalized.startsWith("..") && !path.isAbsolute(normalized) && !p.includes("\0"));
56
+ }
57
+ /**
58
+ * Validate a project slug (e.g. "my-project" or "group/my-project").
59
+ */
60
+ export function isValidProjectPath(project) {
61
+ if (!project)
62
+ return false;
63
+ const normalized = path.posix.normalize(project);
64
+ if (normalized.startsWith("..") || path.isAbsolute(normalized))
65
+ return false;
66
+ if (normalized.includes("\0"))
67
+ return false;
68
+ const segments = normalized.split("/").filter(Boolean);
69
+ if (!segments.length)
70
+ return false;
71
+ return segments.every((s) => /^[a-z0-9][a-z0-9-]*$/.test(s));
72
+ }
73
+ /**
74
+ * mkdir -p helper.
75
+ */
76
+ export function ensureDir(dir) {
77
+ if (!fs.existsSync(dir)) {
78
+ fs.mkdirSync(dir, { recursive: true });
79
+ }
80
+ }
81
+ /**
82
+ * Print error to stderr and exit with code 1.
83
+ */
84
+ export function fail(message) {
85
+ console.error(`Error: ${message}`);
86
+ process.exit(1);
87
+ }
88
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/scripts/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,O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AC,MAAM,CAAC,OAAO,CAAC,CAAC;IACvD,IAAI,CAAC,QAAQ,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACnC,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,IAAI,CAAC,OAAe;IAClC,OAAO,CAAC,KAAK,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC;IACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
@@ -0,0 +1,21 @@
1
+ import express from "express";
2
+ import cors from "cors";
3
+ export interface CreateServerOptions {
4
+ /** CORS options. Pass false to disable. Default: enabled with defaults. */
5
+ cors?: cors.CorsOptions | false;
6
+ /** JSON body parser limit. Default: "50mb" */
7
+ jsonLimit?: string;
8
+ /** Custom ping message. Default: reads PING_MESSAGE env var, falls back to "pong" */
9
+ pingMessage?: string;
10
+ /** Disable the /api/ping health check. Default: false */
11
+ disablePing?: boolean;
12
+ }
13
+ /**
14
+ * Create a pre-configured Express app with standard agent-native middleware:
15
+ * - CORS
16
+ * - JSON body parser (50mb limit)
17
+ * - URL-encoded body parser
18
+ * - /api/ping health check
19
+ */
20
+ export declare function createServer(options?: CreateServerOptions): express.Express;
21
+ //# sourceMappingURL=create-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-server.d.ts","sourceRoot":"","sources":["../../src/server/create-server.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,WAAW,mBAAmB;IAClC,2EAA2E;IAC3E,IAAI,CAAC,EAAE,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAChC,8CAA8C;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qFAAqF;IACrF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yDAAyD;IACzD,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,OAAO,CAmB/E"}
@@ -0,0 +1,27 @@
1
+ import express from "express";
2
+ import cors from "cors";
3
+ /**
4
+ * Create a pre-configured Express app with standard agent-native middleware:
5
+ * - CORS
6
+ * - JSON body parser (50mb limit)
7
+ * - URL-encoded body parser
8
+ * - /api/ping health check
9
+ */
10
+ export function createServer(options = {}) {
11
+ const app = express();
12
+ // Middleware
13
+ if (options.cors !== false) {
14
+ app.use(cors(options.cors));
15
+ }
16
+ app.use(express.json({ limit: options.jsonLimit ?? "50mb" }));
17
+ app.use(express.urlencoded({ extended: true }));
18
+ // Health check
19
+ if (!options.disablePing) {
20
+ app.get("/api/ping", (_req, res) => {
21
+ const message = options.pingMessage ?? process.env.PING_MESSAGE ?? "pong";
22
+ res.json({ message });
23
+ });
24
+ }
25
+ return app;
26
+ }
27
+ //# sourceMappingURL=create-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-server.js","sourceRoot":"","sources":["../../src/server/create-server.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AAaxB;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,UAA+B,EAAE;IAC5D,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;IAEtB,aAAa;IACb,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QAC3B,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9B,CAAC;IACD,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC;IAC9D,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAEhD,eAAe;IACf,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QACzB,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;YACjC,MAAM,OAAO,GAAG,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,MAAM,CAAC;YAC1E,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { createServer, type CreateServerOptions } from "./create-server.js";
2
+ export { createFileWatcher, createSSEHandler, type FileWatcherOptions, type SSEHandlerOptions, } from "./sse.js";
3
+ export { createProductionServer, type ProductionServerOptions, } from "./production.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,GACvB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,sBAAsB,EACtB,KAAK,uBAAuB,GAC7B,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { createServer } from "./create-server.js";
2
+ export { createFileWatcher, createSSEHandler, } from "./sse.js";
3
+ export { createProductionServer, } from "./production.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA4B,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EACL,iBAAiB,EACjB,gBAAgB,GAGjB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,sBAAsB,GAEvB,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { Express } from "express";
2
+ export interface ProductionServerOptions {
3
+ /** Port to listen on. Default: process.env.PORT || 3000 */
4
+ port?: number | string;
5
+ /** Path to the built SPA directory. Default: inferred from import.meta or "dist/spa" */
6
+ spaDir?: string;
7
+ /** App name for log messages. Default: "Agent-Native" */
8
+ appName?: string;
9
+ }
10
+ /**
11
+ * Start a production server that:
12
+ * 1. Serves the built SPA static files
13
+ * 2. Falls back to index.html for client-side routing (SPA fallback)
14
+ * 3. Returns 404 JSON for unknown API routes
15
+ * 4. Handles graceful shutdown on SIGTERM/SIGINT
16
+ */
17
+ export declare function createProductionServer(app: Express, options?: ProductionServerOptions): void;
18
+ //# sourceMappingURL=production.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"production.d.ts","sourceRoot":"","sources":["../../src/server/production.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGvC,MAAM,WAAW,uBAAuB;IACtC,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,wFAAwF;IACxF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,OAAO,EACZ,OAAO,GAAE,uBAA4B,GACpC,IAAI,CAgCN"}
@@ -0,0 +1,37 @@
1
+ import path from "path";
2
+ import express from "express";
3
+ /**
4
+ * Start a production server that:
5
+ * 1. Serves the built SPA static files
6
+ * 2. Falls back to index.html for client-side routing (SPA fallback)
7
+ * 3. Returns 404 JSON for unknown API routes
8
+ * 4. Handles graceful shutdown on SIGTERM/SIGINT
9
+ */
10
+ export function createProductionServer(app, options = {}) {
11
+ const port = options.port ?? process.env.PORT ?? 3000;
12
+ const appName = options.appName ?? "Agent-Native";
13
+ // Resolve SPA directory
14
+ const spaDir = options.spaDir ?? path.resolve(process.cwd(), "dist/spa");
15
+ // Serve static files
16
+ app.use(express.static(spaDir));
17
+ // SPA fallback — serve index.html for all non-API routes
18
+ app.get("*", (req, res) => {
19
+ if (req.path.startsWith("/api/") || req.path.startsWith("/health")) {
20
+ return res.status(404).json({ error: "API endpoint not found" });
21
+ }
22
+ res.sendFile(path.join(spaDir, "index.html"));
23
+ });
24
+ app.listen(port, () => {
25
+ console.log(`${appName} server running on port ${port}`);
26
+ console.log(` Frontend: http://localhost:${port}`);
27
+ console.log(` API: http://localhost:${port}/api`);
28
+ });
29
+ // Graceful shutdown
30
+ const shutdown = (signal) => {
31
+ console.log(`Received ${signal}, shutting down gracefully`);
32
+ process.exit(0);
33
+ };
34
+ process.on("SIGTERM", () => shutdown("SIGTERM"));
35
+ process.on("SIGINT", () => shutdown("SIGINT"));
36
+ }
37
+ //# sourceMappingURL=production.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"production.js","sourceRoot":"","sources":["../../src/server/production.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,OAAO,MAAM,SAAS,CAAC;AAW9B;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CACpC,GAAY,EACZ,UAAmC,EAAE;IAErC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,I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,CAAC;IACF,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;IACjD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { type FSWatcher } from "chokidar";
2
+ import { EventEmitter } from "events";
3
+ import type { Request, Response } from "express";
4
+ export type { FSWatcher } from "chokidar";
5
+ export interface FileWatcherOptions {
6
+ /** Glob patterns or regex to ignore. */
7
+ ignored?: any;
8
+ /** Whether to emit events for the initial file scan. Default: false (ignoreInitial: true) */
9
+ emitInitial?: boolean;
10
+ }
11
+ /**
12
+ * Create a chokidar file watcher for the given directory.
13
+ * Returns a chokidar.FSWatcher that emits "all" events on file changes.
14
+ */
15
+ export declare function createFileWatcher(dir: string, options?: FileWatcherOptions): FSWatcher;
16
+ export interface SSEHandlerOptions {
17
+ /** Additional EventEmitters to stream events from (e.g. sync events). */
18
+ extraEmitters?: Array<{
19
+ emitter: EventEmitter;
20
+ event: string;
21
+ }>;
22
+ }
23
+ /**
24
+ * Create an Express route handler that streams Server-Sent Events for file changes.
25
+ *
26
+ * Usage:
27
+ * app.get("/api/events", createSSEHandler(watcher));
28
+ */
29
+ export declare function createSSEHandler(watcher: FSWatcher, options?: SSEHandlerOptions): (req: Request, res: Response) => void;
30
+ //# sourceMappingURL=sse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/server/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEjD,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,WAAW,kBAAkB;IACjC,wCAAwC;IACxC,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,6FAA6F;IAC7F,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,kBAAuB,GAC/B,SAAS,CAKX;AAED,MAAM,WAAW,iBAAiB;IAChC,yEAAyE;IACzE,aAAa,CAAC,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,YAAY,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,SAAS,EAClB,OAAO,GAAE,iBAAsB,GAC9B,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,KAAK,IAAI,CA8BvC"}
@@ -0,0 +1,44 @@
1
+ import { watch } from "chokidar";
2
+ /**
3
+ * Create a chokidar file watcher for the given directory.
4
+ * Returns a chokidar.FSWatcher that emits "all" events on file changes.
5
+ */
6
+ export function createFileWatcher(dir, options = {}) {
7
+ return watch(dir, {
8
+ ignoreInitial: !options.emitInitial,
9
+ ignored: options.ignored,
10
+ });
11
+ }
12
+ /**
13
+ * Create an Express route handler that streams Server-Sent Events for file changes.
14
+ *
15
+ * Usage:
16
+ * app.get("/api/events", createSSEHandler(watcher));
17
+ */
18
+ export function createSSEHandler(watcher, options = {}) {
19
+ return (req, res) => {
20
+ res.setHeader("Content-Type", "text/event-stream");
21
+ res.setHeader("Cache-Control", "no-cache");
22
+ res.setHeader("Connection", "keep-alive");
23
+ res.flushHeaders();
24
+ const onChange = (eventName, filePath) => {
25
+ res.write(`data: ${JSON.stringify({ type: eventName, path: filePath })}\n\n`);
26
+ };
27
+ watcher.on("all", onChange);
28
+ // Subscribe to extra emitters
29
+ const cleanups = [];
30
+ for (const { emitter, event } of options.extraEmitters ?? []) {
31
+ const handler = (data) => {
32
+ res.write(`data: ${JSON.stringify(data)}\n\n`);
33
+ };
34
+ emitter.on(event, handler);
35
+ cleanups.push(() => emitter.off(event, handler));
36
+ }
37
+ req.on("close", () => {
38
+ watcher.off("all", onChange);
39
+ for (const cleanup of cleanups)
40
+ cleanup();
41
+ });
42
+ };
43
+ }
44
+ //# sourceMappingURL=sse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.js","sourceRoot":"","sources":["../../src/server/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAkB,MAAM,UAAU,CAAC;AAajD;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,GAAW,EACX,UAA8B,EAAE;IAEhC,OAAO,KAAK,CAAC,GAAG,EAAE;QAChB,aAAa,EAAE,CAAC,OAAO,CAAC,WAAW;QACnC,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC,CAAC;AACL,CAAC;AAOD;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAAkB,EAClB,UAA6B,EAAE;IAE/B,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE;QACrC,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,mBAAmB,CAAC,CAAC;QACnD,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;QAC3C,GAAG,CAAC,SAAS,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;QAC1C,GAAG,CAAC,YAAY,EAAE,CAAC;QAEnB,MAAM,QAAQ,GAAG,CAAC,SAAiB,EAAE,QAAgB,EAAE,EAAE;YACvD,GAAG,CAAC,KAAK,CACP,SAAS,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,MAAM,CACnE,CAAC;QACJ,CAAC,CAAC;QAEF,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAE5B,8BAA8B;QA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