@timbal-ai/timbal-react 0.5.5 → 0.6.1

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 (44) hide show
  1. package/README.md +128 -4
  2. package/dist/app.cjs +5311 -0
  3. package/dist/app.d.cts +29 -0
  4. package/dist/app.d.ts +29 -0
  5. package/dist/app.esm.js +81 -0
  6. package/dist/chart-artifact-C71dk4xI.d.ts +329 -0
  7. package/dist/chart-artifact-CPEpOmtV.d.cts +329 -0
  8. package/dist/chat-CWtQWDtJ.d.cts +650 -0
  9. package/dist/chat-CWtQWDtJ.d.ts +650 -0
  10. package/dist/chat.cjs +4162 -0
  11. package/dist/chat.d.cts +13 -0
  12. package/dist/chat.d.ts +13 -0
  13. package/dist/chat.esm.js +51 -0
  14. package/dist/chunk-4TCJQSIX.esm.js +565 -0
  15. package/dist/chunk-IYENDIRY.esm.js +119 -0
  16. package/dist/chunk-KC5QLVUG.esm.js +22 -0
  17. package/dist/chunk-M4V6Q6XO.esm.js +1082 -0
  18. package/dist/chunk-OFHLFNJH.esm.js +138 -0
  19. package/dist/chunk-OVHR7J3J.esm.js +1574 -0
  20. package/dist/chunk-WLTW56MC.esm.js +66 -0
  21. package/dist/chunk-YJQLLFKP.esm.js +3672 -0
  22. package/dist/index.cjs +1822 -358
  23. package/dist/index.d.cts +15 -931
  24. package/dist/index.d.ts +15 -931
  25. package/dist/index.esm.js +187 -5578
  26. package/dist/layout-B9VayJhZ.d.cts +75 -0
  27. package/dist/layout-CQWngNQ7.d.ts +75 -0
  28. package/dist/studio.cjs +5734 -0
  29. package/dist/studio.d.cts +15 -0
  30. package/dist/studio.d.ts +15 -0
  31. package/dist/studio.esm.js +27 -0
  32. package/dist/styles.css +46 -2
  33. package/dist/timbal-v2-button-F4-z7m33.d.cts +40 -0
  34. package/dist/timbal-v2-button-F4-z7m33.d.ts +40 -0
  35. package/dist/ui.cjs +720 -0
  36. package/dist/ui.d.cts +74 -0
  37. package/dist/ui.d.ts +74 -0
  38. package/dist/ui.esm.js +44 -0
  39. package/dist/welcome--80i_O0p.d.cts +190 -0
  40. package/dist/welcome-BOizSp5h.d.ts +190 -0
  41. package/package.json +35 -3
  42. package/scripts/dev-linked.mjs +66 -0
  43. package/vite/local-dev.d.ts +4 -0
  44. package/vite/local-dev.mjs +115 -0
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Run `bun run build:watch` in timbal-react, then a consumer dev server.
4
+ *
5
+ * Usage:
6
+ * node scripts/dev-linked.mjs [consumerDir] [devCommand ...]
7
+ *
8
+ * Examples:
9
+ * node scripts/dev-linked.mjs vite
10
+ * node scripts/dev-linked.mjs examples/app-kit vite
11
+ */
12
+ import { spawn } from "node:child_process";
13
+ import { existsSync } from "node:fs";
14
+ import path from "node:path";
15
+ import { fileURLToPath } from "node:url";
16
+
17
+ const timbalReactRoot = path.resolve(
18
+ path.dirname(fileURLToPath(import.meta.url)),
19
+ "..",
20
+ );
21
+
22
+ const args = process.argv.slice(2);
23
+ let consumerDir = process.cwd();
24
+ let devArgs = args;
25
+
26
+ if (args[0]) {
27
+ const candidate = path.resolve(timbalReactRoot, args[0]);
28
+ if (existsSync(path.join(candidate, "package.json"))) {
29
+ consumerDir = candidate;
30
+ devArgs = args.slice(1);
31
+ }
32
+ }
33
+
34
+ const devCmd = devArgs[0] ?? "vite";
35
+ const devCmdArgs = devArgs.slice(1);
36
+
37
+ function run(cmd, args, opts) {
38
+ return spawn(cmd, args, {
39
+ cwd: opts.cwd,
40
+ stdio: "inherit",
41
+ shell: process.platform === "win32",
42
+ env: process.env,
43
+ });
44
+ }
45
+
46
+ console.log("[timbal-react] building + watching dist…");
47
+ const watch = run("bun", ["run", "build:watch"], { cwd: timbalReactRoot });
48
+
49
+ console.log(`[consumer] (${consumerDir}) ${devCmd} ${devCmdArgs.join(" ")}`.trim());
50
+ const app = run(devCmd, devCmdArgs, { cwd: consumerDir });
51
+
52
+ let exiting = false;
53
+ function shutdown(code = 0) {
54
+ if (exiting) return;
55
+ exiting = true;
56
+ watch.kill("SIGTERM");
57
+ app.kill("SIGTERM");
58
+ process.exit(code);
59
+ }
60
+
61
+ process.on("SIGINT", () => shutdown(0));
62
+ process.on("SIGTERM", () => shutdown(0));
63
+ watch.on("exit", (code) => {
64
+ if (code) shutdown(code);
65
+ });
66
+ app.on("exit", (code) => shutdown(code ?? 0));
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from "vite";
2
+
3
+ /** Use in Vite apps that link `@timbal-ai/timbal-react` via `file:../timbal-react`. */
4
+ export function timbalReactLocalDev(): Plugin;
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Vite plugin for apps that depend on `@timbal-ai/timbal-react` via `file:../timbal-react`.
3
+ *
4
+ * - Skips pre-bundling so `dist/` updates are not stuck in `node_modules/.vite/deps`
5
+ * - Watches the linked package `dist/` and triggers a full reload when it changes
6
+ *
7
+ * IMPORTANT: this is a no-op for normal npm installs. Excluding the package from
8
+ * `optimizeDeps` only makes sense when it is `file:`-linked (a symlink in
9
+ * `node_modules`). For published installs Vite must pre-bundle the package so its
10
+ * CJS-only transitive deps (e.g. `use-sync-external-store/shim` reached via
11
+ * `radix-ui` -> `@radix-ui/react-use-is-hydrated`) are converted to ESM instead of
12
+ * leaking to the browser.
13
+ */
14
+ import { createRequire } from "node:module";
15
+ import fs from "node:fs";
16
+ import path from "node:path";
17
+
18
+ const TIMBAL_REACT_EXPORTS = [
19
+ "@timbal-ai/timbal-react",
20
+ "@timbal-ai/timbal-react/chat",
21
+ "@timbal-ai/timbal-react/studio",
22
+ "@timbal-ai/timbal-react/ui",
23
+ "@timbal-ai/timbal-react/app",
24
+ ];
25
+
26
+ /**
27
+ * CJS-only transitive deps that must be pre-bundled even when the package itself
28
+ * is excluded, so their `useSyncExternalStore` named imports resolve as ESM.
29
+ */
30
+ const CJS_INTEROP_DEPS = [
31
+ "radix-ui",
32
+ "@radix-ui/react-use-is-hydrated",
33
+ "use-sync-external-store/shim",
34
+ "use-sync-external-store/shim/with-selector",
35
+ "zustand",
36
+ ];
37
+
38
+ function resolveLinkedPackageRoot() {
39
+ try {
40
+ const require = createRequire(import.meta.url);
41
+ const pkgJson = require.resolve("@timbal-ai/timbal-react/package.json");
42
+ return path.dirname(pkgJson);
43
+ } catch {
44
+ return null;
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Only treat the install as "linked" when the `node_modules` entry is a symlink,
50
+ * i.e. installed via `file:../timbal-react` (or a workspace link). Normal npm
51
+ * installs are real directories and must be left to Vite's pre-bundler.
52
+ *
53
+ * @param {string} [root] consuming project root
54
+ */
55
+ function isLinkedInstall(root) {
56
+ const base = root || process.cwd();
57
+ const entry = path.join(
58
+ base,
59
+ "node_modules",
60
+ "@timbal-ai",
61
+ "timbal-react",
62
+ );
63
+ try {
64
+ return fs.lstatSync(entry).isSymbolicLink();
65
+ } catch {
66
+ return false;
67
+ }
68
+ }
69
+
70
+ /** @returns {import('vite').Plugin} */
71
+ export function timbalReactLocalDev() {
72
+ /** @type {string | null} */
73
+ let distDir = null;
74
+
75
+ return {
76
+ name: "timbal-react-local-dev",
77
+ enforce: "pre",
78
+ config(config) {
79
+ if (!isLinkedInstall(config.root)) return {};
80
+
81
+ const pkgRoot = resolveLinkedPackageRoot();
82
+ if (!pkgRoot) return {};
83
+
84
+ distDir = path.join(pkgRoot, "dist");
85
+ const distGlob = `${distDir.replace(/\\/g, "/")}/**`;
86
+
87
+ return {
88
+ optimizeDeps: {
89
+ exclude: TIMBAL_REACT_EXPORTS,
90
+ include: CJS_INTEROP_DEPS,
91
+ },
92
+ server: {
93
+ watch: {
94
+ ignored: ["**/.git/**", "**/node_modules/**", `!${distGlob}`],
95
+ },
96
+ },
97
+ };
98
+ },
99
+ handleHotUpdate({ file, server }) {
100
+ if (!distDir || !file.startsWith(distDir)) return;
101
+
102
+ for (const mod of server.moduleGraph.idToModuleMap.values()) {
103
+ if (
104
+ mod.id?.includes("@timbal-ai/timbal-react") ||
105
+ mod.id?.includes(`${path.sep}timbal-react${path.sep}dist`)
106
+ ) {
107
+ server.moduleGraph.invalidateModule(mod);
108
+ }
109
+ }
110
+
111
+ server.ws.send({ type: "full-reload" });
112
+ return [];
113
+ },
114
+ };
115
+ }