@skybridge/vite-plugin 0.0.0 → 2.0.0-beta.5e34c1e

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Alpic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # @skybridge/vite-plugin
2
+
3
+ The Vite plugin behind [Skybridge](https://skybridge.tech): it discovers view
4
+ modules, serves them as virtual entries, applies the `data-llm` transform, and
5
+ tells `skybridge build` which packages to leave unbundled.
6
+
7
+ Its `evals` option wires up [`@skybridge/test`](https://www.npmjs.com/package/@skybridge/test),
8
+ which boots the server and extends vitest's assertions with chat-oriented
9
+ matchers for checking that a prompt reaches the right tool.
10
+
11
+ Projects created with `npm create skybridge` already have it wired up.
12
+
13
+ ```ts
14
+ import { defineConfig } from "vite";
15
+ import { skybridge } from "@skybridge/vite-plugin";
16
+
17
+ export default defineConfig({
18
+ plugins: [skybridge()],
19
+ });
20
+ ```
21
+
22
+ See the [documentation](https://docs.skybridge.tech) for the options it accepts.
@@ -0,0 +1,3 @@
1
+ export type { ChatAssertion, ChatMatchers } from "./matchers.js";
2
+ export type { ChatLike, ToolCall } from "./types.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/evals/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACjE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/evals/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ import "vitest";
2
+ import type { ToolInput, ToolNames } from "skybridge/server";
3
+ import type { ChatLike } from "./types.js";
4
+ /**
5
+ * Assertions about the tool calls a conversation produced. Kept off vitest's
6
+ * global `Matchers` so they never appear on unrelated `expect()` calls, and so
7
+ * this stays the one place later tool-call helpers are added.
8
+ */
9
+ export interface ChatMatchers<App> {
10
+ toHaveCalledToolOnce<Name extends ToolNames<App>>(name: Name, args?: Partial<ToolInput<App, Name>>): void;
11
+ toHaveCalledToolWith<Name extends ToolNames<App>>(name: Name, args: Partial<ToolInput<App, Name>>): void;
12
+ toNeverHaveCalledTool<Name extends ToolNames<App>>(name: Name): void;
13
+ toHaveFailedToolCall<Name extends ToolNames<App>>(name: Name): void;
14
+ toHaveSaid(text: string | RegExp): void;
15
+ }
16
+ export interface ChatAssertion<App> extends ChatMatchers<App> {
17
+ not: ChatMatchers<App>;
18
+ }
19
+ declare module "vitest" {
20
+ interface ExpectStatic {
21
+ chat<App>(chat: ChatLike<App>): ChatAssertion<App>;
22
+ }
23
+ }
24
+ //# sourceMappingURL=matchers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchers.d.ts","sourceRoot":"","sources":["../../src/evals/matchers.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,CAAC;AAChB,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7D,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,YAAY,CAAC;AAErD;;;;GAIG;AACH,MAAM,WAAW,YAAY,CAAC,GAAG;IAC/B,oBAAoB,CAAC,IAAI,SAAS,SAAS,CAAC,GAAG,CAAC,EAC9C,IAAI,EAAE,IAAI,EACV,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,GACnC,IAAI,CAAC;IACR,oBAAoB,CAAC,IAAI,SAAS,SAAS,CAAC,GAAG,CAAC,EAC9C,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,GAClC,IAAI,CAAC;IACR,qBAAqB,CAAC,IAAI,SAAS,SAAS,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IACrE,oBAAoB,CAAC,IAAI,SAAS,SAAS,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IACpE,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CACzC;AAED,MAAM,WAAW,aAAa,CAAC,GAAG,CAAE,SAAQ,YAAY,CAAC,GAAG,CAAC;IAC3D,GAAG,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;CACxB;AAED,OAAO,QAAQ,QAAQ,CAAC;IACtB,UAAU,YAAY;QACpB,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;KACpD;CACF"}
@@ -0,0 +1,100 @@
1
+ import "vitest";
2
+ import { expect } from "vitest";
3
+ function attemptedCalls(chat, name) {
4
+ return chat.toolCalls.filter((call) => String(call.name) === name);
5
+ }
6
+ function acceptedCalls(chat, name) {
7
+ return attemptedCalls(chat, name).filter((call) => call.failed === undefined);
8
+ }
9
+ function observed(chat) {
10
+ if (chat.toolCalls.length === 0) {
11
+ return " (no tool was called)";
12
+ }
13
+ return chat.toolCalls
14
+ .map((call, index) => ` ${index + 1}. ${call.name} ${JSON.stringify(call.arguments)}${call.failed === undefined ? "" : ` (failed: ${call.failed})`}`)
15
+ .join("\n");
16
+ }
17
+ function collapse(text) {
18
+ return text.replace(/\s+/g, " ").trim();
19
+ }
20
+ function said(chat, text) {
21
+ return chat.assistantTurns.some((turn) => typeof text === "string"
22
+ ? collapse(turn).toLowerCase().includes(collapse(text).toLowerCase())
23
+ : text.test(turn));
24
+ }
25
+ function spoken(chat) {
26
+ if (chat.assistantTurns.length === 0) {
27
+ return " (the assistant said nothing)";
28
+ }
29
+ return chat.assistantTurns
30
+ .map((turn, index) => ` ${index + 1}. ${collapse(turn)}`)
31
+ .join("\n");
32
+ }
33
+ function report(chat, summary) {
34
+ return `${summary}
35
+
36
+ Calls the model actually made:
37
+ ${observed(chat)}`;
38
+ }
39
+ expect.extend({
40
+ toHaveCalledToolOnce(received, name, args) {
41
+ const matching = acceptedCalls(received, name);
42
+ const argsMatch = args === undefined ||
43
+ (matching.length === 1 &&
44
+ this.equals(matching[0]?.arguments, expect.objectContaining(args)));
45
+ const pass = matching.length === 1 && argsMatch;
46
+ return {
47
+ pass,
48
+ message: () => report(received, pass
49
+ ? `Expected "${name}" not to be called exactly once.`
50
+ : matching.length === 1
51
+ ? `Expected "${name}" to be called once with ${JSON.stringify(args)}, but it was called with ${JSON.stringify(matching[0]?.arguments)}.`
52
+ : `Expected "${name}" to be called exactly once by a call that succeeded, but ${matching.length} such calls were made.`),
53
+ };
54
+ },
55
+ toHaveCalledToolWith(received, name, args) {
56
+ const pass = acceptedCalls(received, name).some((call) => this.equals(call.arguments, expect.objectContaining(args)));
57
+ return {
58
+ pass,
59
+ message: () => report(received, pass
60
+ ? `Expected no call to "${name}" with ${JSON.stringify(args)}.`
61
+ : `Expected "${name}" to be called with ${JSON.stringify(args)}.`),
62
+ };
63
+ },
64
+ toHaveFailedToolCall(received, name) {
65
+ const attempted = attemptedCalls(received, name);
66
+ const failed = attempted.filter((call) => call.failed !== undefined);
67
+ return {
68
+ pass: failed.length > 0,
69
+ message: () => report(received, failed.length > 0
70
+ ? `Expected every call to "${name}" to succeed.`
71
+ : attempted.length === 0
72
+ ? `Expected "${name}" to be called and fail, but it was never called.`
73
+ : `Expected "${name}" to fail, but all ${attempted.length} calls succeeded.`),
74
+ };
75
+ },
76
+ toHaveSaid(received, text) {
77
+ const pass = said(received, text);
78
+ const wanted = typeof text === "string" ? `"${text}"` : String(text);
79
+ return {
80
+ pass,
81
+ message: () => `${pass
82
+ ? `Expected the assistant not to say ${wanted}.`
83
+ : `Expected the assistant to say ${wanted}.`}
84
+
85
+ What the assistant actually said:
86
+ ${spoken(received)}`,
87
+ };
88
+ },
89
+ toNeverHaveCalledTool(received, name) {
90
+ const matching = attemptedCalls(received, name);
91
+ return {
92
+ pass: matching.length === 0,
93
+ message: () => report(received, matching.length === 0
94
+ ? `Expected "${name}" to be called at least once.`
95
+ : `Expected "${name}" never to be called, but it was called ${matching.length} times.`),
96
+ };
97
+ },
98
+ });
99
+ expect.chat = (chat) => expect(chat);
100
+ //# sourceMappingURL=matchers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchers.js","sourceRoot":"","sources":["../../src/evals/matchers.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,CAAC;AAEhB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAgChC,SAAS,cAAc,CACrB,IAAuB,EACvB,IAAY;IAEZ,OAAO,IAAI,CAAC,SAA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oBACtE,CAAC,CAAC,aAAa,IAAI,sBAAsB,SAAS,CAAC,MAAM,mBAAmB,CACjF;SACJ,CAAC;IACJ,CAAC;IAED,UAAU,CAAC,QAA2B,EAAE,IAAqB;QAC3D,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAErE,OAAO;YACL,IAAI;YACJ,OAAO,EAAE,GAAG,EAAE,CACZ,GACE,IAAI;gBACF,CAAC,CAAC,qCAAqC,MAAM,GAAG;gBAChD,CAAC,CAAC,iCAAiC,MAAM,GAC7C;;;EAGN,MAAM,CAAC,QAAQ,CAAC,EAAE;SACf,CAAC;IACJ,CAAC;IAED,qBAAqB,CAAC,QAA2B,EAAE,IAAY;QAC7D,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAEhD,OAAO;YACL,IAAI,EAAE,QAAQ,CAAC,MAAM,KAAK,CAAC;YAC3B,OAAO,EAAE,GAAG,EAAE,CACZ,MAAM,CACJ,QAAQ,EACR,QAAQ,CAAC,MAAM,KAAK,CAAC;gBACnB,CAAC,CAAC,aAAa,IAAI,+BAA+B;gBAClD,CAAC,CAAC,aAAa,IAAI,2CAA2C,QAAQ,CAAC,MAAM,SAAS,CACzF;SACJ,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,IAAI,GAAG,CAAM,IAAmB,EAAsB,EAAE,CAC7D,MAAM,CAAC,IAAI,CAAkC,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { ToolInput, ToolNames } from "skybridge/server";
2
+ import type { EvalsOptions } from "../plugin.js";
3
+ /**
4
+ * One recorded call, typed against the project's own registry: `name` is a
5
+ * union of the project's tool names and `arguments` is discriminated on it.
6
+ * `failed` carries the server's reason when the call did not go through.
7
+ */
8
+ export type ToolCall<App> = {
9
+ [Name in ToolNames<App>]: {
10
+ name: Name;
11
+ arguments: ToolInput<App, Name>;
12
+ failed?: string;
13
+ };
14
+ }[ToolNames<App>];
15
+ /** The part of a conversation the matchers assert on. */
16
+ export interface ChatLike<App> {
17
+ /** Type-only anchor so `expect.chat` infers `App` from the conversation. */
18
+ readonly $app?: App;
19
+ readonly toolCalls: ToolCall<App>[];
20
+ readonly assistantTurns: string[];
21
+ }
22
+ declare module "vitest" {
23
+ interface ProvidedContext {
24
+ skybridgeEvals: EvalsOptions | undefined;
25
+ }
26
+ }
27
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/evals/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD;;;;GAIG;AACH,MAAM,MAAM,QAAQ,CAAC,GAAG,IAAI;KACzB,IAAI,IAAI,SAAS,CAAC,GAAG,CAAC,GAAG;QACxB,IAAI,EAAE,IAAI,CAAC;QACX,SAAS,EAAE,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAChC,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;CACF,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;AAElB,yDAAyD;AACzD,MAAM,WAAW,QAAQ,CAAC,GAAG;IAC3B,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC;IACpB,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;IACpC,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;CACnC;AAED,OAAO,QAAQ,QAAQ,CAAC;IACtB,UAAU,eAAe;QACvB,cAAc,EAAE,YAAY,GAAG,SAAS,CAAC;KAC1C;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/evals/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export { type EvalsOptions, type SkybridgePluginOptions, skybridge, } from "./plugin.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,SAAS,GACV,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { skybridge, } from "./plugin.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,GACV,MAAM,aAAa,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { type Plugin } from "vite";
2
+ /**
3
+ * Options for the eval runner, wired in through the `evals` plugin option and
4
+ * consumed by `@skybridge/test`. Defined here so the runtime package can
5
+ * import the shape while this package keeps no dependency on it.
6
+ */
7
+ export interface EvalsOptions {
8
+ temperature?: number;
9
+ systemPrompt?: string;
10
+ maxSteps?: number;
11
+ /**
12
+ * Per-scenario timeout in milliseconds. Defaults to two minutes, because
13
+ * every turn in a scenario is a live model call and vitest's own 5s default
14
+ * expires mid-conversation.
15
+ */
16
+ timeout?: number;
17
+ }
18
+ /** Options for the {@link skybridge} Vite plugin. */
19
+ export interface SkybridgePluginOptions {
20
+ /** Directory scanned for view modules. Defaults to `"src/views"`. */
21
+ viewsDir?: string;
22
+ /**
23
+ * Package names to leave unbundled when `skybridge build` bundles the server
24
+ * for deployment. Use it for dependencies esbuild can't resolve or load —
25
+ * typically optional native modules pulled in by a transitive dependency.
26
+ */
27
+ serverExternal?: string[];
28
+ /**
29
+ * Registers the `expect.chat` matchers and, optionally, the defaults every
30
+ * conversation starts from (`temperature`, `systemPrompt`, `maxSteps`).
31
+ * Point vitest at this config to run the scenarios. Requires
32
+ * `@skybridge/test` as a dev dependency.
33
+ *
34
+ * Scenarios always run the app in-process via `start({ app })`, so
35
+ * `evals: {}` is enough to wire the matchers up.
36
+ */
37
+ evals?: EvalsOptions;
38
+ }
39
+ /**
40
+ * Vite plugin that wires a Skybridge project's view files into Vite.
41
+ *
42
+ * For each `.tsx` / `.jsx` file in `viewsDir` with a default export, the
43
+ * plugin:
44
+ * - exposes a virtual entry that calls {@link mountView} with the view's
45
+ * default export,
46
+ * - generates `.skybridge/views.d.ts` to augment {@link ViewNameRegistry} so
47
+ * {@link ViewName} narrows to the actual view names,
48
+ * - rewrites `<DataLLM>` JSX so the host can extract its content,
49
+ * - warns in dev if a view file is missing a default export.
50
+ *
51
+ * Add it to your `vite.config.ts` alongside `@vitejs/plugin-react`.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * // vite.config.ts
56
+ * import { defineConfig } from "vite";
57
+ * import react from "@vitejs/plugin-react";
58
+ * import { skybridge } from "@skybridge/vite-plugin";
59
+ *
60
+ * export default defineConfig({
61
+ * plugins: [react(), skybridge({ viewsDir: "src/views" })],
62
+ * });
63
+ * ```
64
+ */
65
+ export declare function skybridge(options?: SkybridgePluginOptions): Plugin;
66
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAUA,OAAO,EAAW,KAAK,MAAM,EAAsB,MAAM,MAAM,CAAC;AAOhE;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qDAAqD;AACrD,MAAM,WAAW,sBAAsB;IACrC,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAmBD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM,CAElE"}
package/dist/plugin.js ADDED
@@ -0,0 +1,225 @@
1
+ import { isAbsolute, relative, resolve } from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ import { assertUniqueViewNames, discoverViewsSync, hasDefaultExport, scanViewsSync, writeViewsDts, } from "skybridge/views";
4
+ import { loadEnv } from "vite";
5
+ import { transform as dataLlmTransform } from "./transform-data-llm.js";
6
+ const VIRTUAL_PREFIX = "/_skybridge/view/";
7
+ const VIRTUAL_MODULE_PREFIX = "\0skybridge:view:";
8
+ function buildVirtualEntry(viewFilePath) {
9
+ const normalized = viewFilePath.replace(/\\/g, "/");
10
+ return [
11
+ `import { mountView } from "skybridge/web";`,
12
+ `import Component from "${normalized}";`,
13
+ `import { createElement } from "react";`,
14
+ `mountView(createElement(Component));`,
15
+ ].join("\n");
16
+ }
17
+ function getViewEntryPattern(viewsDir) {
18
+ const escaped = viewsDir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
19
+ return new RegExp(`${escaped}\\/(?:[^/]+\\.(?:jsx|tsx)|[^/]+\\/index\\.(?:tsx|jsx))(?:\\?.*)?$`);
20
+ }
21
+ /**
22
+ * Vite plugin that wires a Skybridge project's view files into Vite.
23
+ *
24
+ * For each `.tsx` / `.jsx` file in `viewsDir` with a default export, the
25
+ * plugin:
26
+ * - exposes a virtual entry that calls {@link mountView} with the view's
27
+ * default export,
28
+ * - generates `.skybridge/views.d.ts` to augment {@link ViewNameRegistry} so
29
+ * {@link ViewName} narrows to the actual view names,
30
+ * - rewrites `<DataLLM>` JSX so the host can extract its content,
31
+ * - warns in dev if a view file is missing a default export.
32
+ *
33
+ * Add it to your `vite.config.ts` alongside `@vitejs/plugin-react`.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * // vite.config.ts
38
+ * import { defineConfig } from "vite";
39
+ * import react from "@vitejs/plugin-react";
40
+ * import { skybridge } from "@skybridge/vite-plugin";
41
+ *
42
+ * export default defineConfig({
43
+ * plugins: [react(), skybridge({ viewsDir: "src/views" })],
44
+ * });
45
+ * ```
46
+ */
47
+ export function skybridge(options) {
48
+ return viewsPlugin(options);
49
+ }
50
+ const EVALS_DIR = "evals";
51
+ const DEFAULT_EVAL_TIMEOUT_MS = 120_000;
52
+ function here(file) {
53
+ return fileURLToPath(new URL(file, import.meta.url));
54
+ }
55
+ function viewsPlugin(options) {
56
+ const rawViewsDir = options?.viewsDir ?? "src/views";
57
+ let resolvedViewsDir;
58
+ let projectRoot;
59
+ let viewMap = new Map();
60
+ let viewEntryPattern;
61
+ return {
62
+ name: "skybridge",
63
+ enforce: "pre",
64
+ // Read by `skybridge build` to resolve viewsDir before `tsc -b` runs, and
65
+ // to feed esbuild's external list when bundling the server.
66
+ api: { viewsDir: rawViewsDir, serverExternal: options?.serverExternal },
67
+ config(config, { mode }) {
68
+ projectRoot = config.root || process.cwd();
69
+ resolvedViewsDir = isAbsolute(rawViewsDir)
70
+ ? rawViewsDir
71
+ : resolve(projectRoot, rawViewsDir);
72
+ viewEntryPattern = getViewEntryPattern(resolvedViewsDir);
73
+ const views = discoverViewsSync(resolvedViewsDir);
74
+ viewMap = new Map(views.map((v) => [v.name, v]));
75
+ writeViewsDts(projectRoot, views);
76
+ const input = {};
77
+ for (const view of views) {
78
+ input[view.name] = `${VIRTUAL_PREFIX}${view.name}`;
79
+ }
80
+ const base = {
81
+ base: "/assets",
82
+ // Fixes "Invalid hook call" on createStore by forcing a single
83
+ // copy of React. Under pnpm's isolated node_modules, zustand
84
+ // inside `skybridge` resolves React from skybridge's own
85
+ // dependencies while the host app loads its own copy
86
+ resolve: {
87
+ dedupe: ["react", "react-dom"],
88
+ },
89
+ build: {
90
+ outDir: "dist/assets",
91
+ emptyOutDir: true,
92
+ manifest: true,
93
+ minify: true,
94
+ cssCodeSplit: false,
95
+ rollupOptions: {
96
+ input,
97
+ },
98
+ },
99
+ // Pre-bundle view deps at startup so the first tool invocation
100
+ // doesn't hit Vite's on-demand re-optimization path (which sends
101
+ // `full-reload` over HMR — in our iframe flow the parent host
102
+ // can't honour a reload, and the view silently never mounts).
103
+ optimizeDeps: {
104
+ // Scan view files so transitive user deps (zod, tailwind, etc.)
105
+ // get pre-bundled at startup.
106
+ entries: [
107
+ `${resolvedViewsDir}/*.{tsx,jsx}`,
108
+ `${resolvedViewsDir}/*/index.{tsx,jsx}`,
109
+ ],
110
+ include: ["react", "react-dom/client", "react/jsx-runtime"],
111
+ },
112
+ experimental: {
113
+ renderBuiltUrl: (filename, { hostType }) => {
114
+ // Views render inside a host sandbox iframe, so `import.meta.url`
115
+ // points at the sandbox domain rather than the Skybridge server.
116
+ // JS asset references have to be resolved at runtime against
117
+ // `window.skybridge.serverUrl` so they follow tunnels too.
118
+ if (hostType === "js") {
119
+ return {
120
+ runtime: `window.skybridge.serverUrl + "/assets/${filename}"`,
121
+ };
122
+ }
123
+ // CSS has nowhere to evaluate a runtime expression — `vite:css-post`
124
+ // throws on one. It doesn't need it either: the stylesheet is served
125
+ // from `${serverUrl}/assets/…` and a relative `url()` resolves
126
+ // against the stylesheet's own URL, tunnel origin included.
127
+ return { relative: true };
128
+ },
129
+ },
130
+ };
131
+ if (!options?.evals) {
132
+ return base;
133
+ }
134
+ return {
135
+ ...base,
136
+ test: {
137
+ setupFiles: [here("./evals/matchers.js")],
138
+ provide: { skybridgeEvals: options.evals },
139
+ include: [
140
+ "**/*.{test,spec}.?(c|m)[jt]s?(x)",
141
+ `${EVALS_DIR}/**/*.eval.?(c|m)ts`,
142
+ ],
143
+ testTimeout: options.evals.timeout ?? DEFAULT_EVAL_TIMEOUT_MS,
144
+ env: loadEnv(mode, projectRoot, ""),
145
+ },
146
+ };
147
+ },
148
+ resolveId(id) {
149
+ if (id.startsWith(VIRTUAL_PREFIX)) {
150
+ const name = id.slice(VIRTUAL_PREFIX.length);
151
+ if (viewMap.has(name)) {
152
+ return `${VIRTUAL_MODULE_PREFIX}${name}`;
153
+ }
154
+ }
155
+ return null;
156
+ },
157
+ load(id) {
158
+ if (id.startsWith(VIRTUAL_MODULE_PREFIX)) {
159
+ const name = id.slice(VIRTUAL_MODULE_PREFIX.length);
160
+ const view = viewMap.get(name);
161
+ if (view) {
162
+ return buildVirtualEntry(view.filePath);
163
+ }
164
+ }
165
+ return null;
166
+ },
167
+ configureServer(server) {
168
+ if (!resolvedViewsDir) {
169
+ const root = server.config.root || process.cwd();
170
+ resolvedViewsDir = isAbsolute(rawViewsDir)
171
+ ? rawViewsDir
172
+ : resolve(root, rawViewsDir);
173
+ projectRoot = root;
174
+ viewEntryPattern = getViewEntryPattern(resolvedViewsDir);
175
+ }
176
+ server.watcher.add(resolvedViewsDir);
177
+ // Track which view files we've already warned about so a rescan
178
+ // triggered by an unrelated edit doesn't re-emit the same warning.
179
+ let knownInvalid = new Set();
180
+ const rescan = () => {
181
+ try {
182
+ // Surface broken view files. Without this, files lacking a
183
+ // default export are silently dropped from the input and the
184
+ // user has no idea why their widget never mounts.
185
+ const { valid, invalid } = scanViewsSync(resolvedViewsDir);
186
+ const nextInvalid = new Set(invalid.map((v) => v.filePath));
187
+ for (const filePath of nextInvalid) {
188
+ if (!knownInvalid.has(filePath)) {
189
+ server.config.logger.warn(`[skybridge] view file "${relative(projectRoot, filePath)}" is missing a default export — it won't be served until fixed.`);
190
+ }
191
+ }
192
+ for (const filePath of knownInvalid) {
193
+ if (!nextInvalid.has(filePath)) {
194
+ server.config.logger.info(`[skybridge] view file "${relative(projectRoot, filePath)}" resolved.`);
195
+ }
196
+ }
197
+ knownInvalid = nextInvalid;
198
+ assertUniqueViewNames(valid);
199
+ viewMap = new Map(valid.map((v) => [v.name, v]));
200
+ writeViewsDts(projectRoot, valid);
201
+ }
202
+ catch (err) {
203
+ // assertUniqueViewNames throws on duplicate view names. Catch so
204
+ // chokidar's listener chain doesn't surface it as unhandled and
205
+ // crash the dev server — previous viewMap stays active until
206
+ // the user fixes the conflict.
207
+ const message = err instanceof Error ? err.message : String(err);
208
+ server.config.logger.error(`[skybridge] view rescan failed: ${message}`);
209
+ }
210
+ };
211
+ // Initial scan emits warnings for broken files that exist at startup.
212
+ rescan();
213
+ server.watcher.on("add", rescan);
214
+ server.watcher.on("change", rescan);
215
+ server.watcher.on("unlink", rescan);
216
+ },
217
+ async transform(code, id) {
218
+ if (viewEntryPattern?.test(id) && !hasDefaultExport(code)) {
219
+ this.warn(`View file "${id.split("/").pop()}" is missing a default export.`);
220
+ }
221
+ return await dataLlmTransform(code, id);
222
+ },
223
+ };
224
+ }
225
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EACL,qBAAqB,EAErB,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,aAAa,GACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,EAAmC,MAAM,MAAM,CAAC;AAEhE,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAExE,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAC3C,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AAyClD,SAAS,iBAAiB,CAAC,YAAoB;IAC7C,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAA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;YACtE,MAAM,EAAE,CAAC;YACT,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YACjC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YACpC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACtC,CAAC;QAED,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE;YACtB,IAAI,gBAAgB,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC1D,IAAI,CAAC,IAAI,CACP,cAAc,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,gCAAgC,CAClE,CAAC;YACJ,CAAC;YAED,OAAO,MAAM,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ export declare const transform: (code: string, id: string) => Promise<{
2
+ code: string;
3
+ map: {
4
+ version: number;
5
+ sources: string[];
6
+ names: string[];
7
+ sourceRoot?: string | undefined;
8
+ sourcesContent?: string[] | undefined;
9
+ mappings: string;
10
+ file: string;
11
+ } | null;
12
+ } | null>;
13
+ //# sourceMappingURL=transform-data-llm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-data-llm.d.ts","sourceRoot":"","sources":["../src/transform-data-llm.ts"],"names":[],"mappings":"AA+HA,eAAO,MAAM,SAAS,GAAU,MAAM,MAAM,EAAE,IAAI,MAAM;;;;;;;;;;;SA+BvD,CAAC"}
@@ -0,0 +1,96 @@
1
+ const LLM_IMPORT_SOURCE = "skybridge/web";
2
+ function createBabelPlugin(t) {
3
+ return {
4
+ name: "data-llm-babel",
5
+ visitor: {
6
+ Program: {
7
+ enter(path, state) {
8
+ state.hasDataLLMImport = false;
9
+ state.needsDataLLMImport = false;
10
+ for (const node of path.node.body) {
11
+ if (!t.isImportDeclaration(node)) {
12
+ continue;
13
+ }
14
+ if (node.source.value !== LLM_IMPORT_SOURCE) {
15
+ continue;
16
+ }
17
+ const hasSpecifier = node.specifiers.some((s) => t.isImportSpecifier(s) &&
18
+ t.isIdentifier(s.imported, { name: "DataLLM" }));
19
+ if (hasSpecifier) {
20
+ state.hasDataLLMImport = true;
21
+ break;
22
+ }
23
+ }
24
+ },
25
+ exit(path, state) {
26
+ if (state.needsDataLLMImport && !state.hasDataLLMImport) {
27
+ const importDecl = t.importDeclaration([
28
+ t.importSpecifier(t.identifier("DataLLM"), t.identifier("DataLLM")),
29
+ ], t.stringLiteral(LLM_IMPORT_SOURCE));
30
+ path.node.body.unshift(importDecl);
31
+ }
32
+ },
33
+ },
34
+ JSXElement(path, state) {
35
+ const opening = path.node.openingElement;
36
+ const attributes = opening.attributes;
37
+ const llmAttributeIndex = attributes.findIndex((attribute) => t.isJSXAttribute(attribute) &&
38
+ t.isJSXIdentifier(attribute.name, { name: "data-llm" }));
39
+ if (llmAttributeIndex === -1) {
40
+ return;
41
+ }
42
+ const llmAttribute = attributes[llmAttributeIndex];
43
+ let contentExpression;
44
+ if (t.isStringLiteral(llmAttribute.value)) {
45
+ contentExpression = llmAttribute.value;
46
+ }
47
+ else if (t.isJSXExpressionContainer(llmAttribute.value)) {
48
+ contentExpression = llmAttribute.value.expression;
49
+ }
50
+ else {
51
+ return;
52
+ }
53
+ const contentAttr = t.jsxAttribute(t.jsxIdentifier("content"), t.isStringLiteral(contentExpression)
54
+ ? contentExpression
55
+ : t.jsxExpressionContainer(contentExpression));
56
+ const filteredAttributes = attributes.filter((_, index) => index !== llmAttributeIndex);
57
+ const newOpening = t.jsxOpeningElement(opening.name, filteredAttributes, opening.selfClosing);
58
+ const elementWithoutLlm = t.jsxElement(newOpening, path.node.closingElement, path.node.children, path.node.selfClosing);
59
+ const llmOpening = t.jsxOpeningElement(t.jsxIdentifier("DataLLM"), [
60
+ contentAttr,
61
+ ]);
62
+ const llmClosing = t.jsxClosingElement(t.jsxIdentifier("DataLLM"));
63
+ const wrapped = t.jsxElement(llmOpening, llmClosing, [elementWithoutLlm], false);
64
+ state.needsDataLLMImport = true;
65
+ path.replaceWith(wrapped);
66
+ },
67
+ },
68
+ };
69
+ }
70
+ export const transform = async (code, id) => {
71
+ if (!/\.(jsx|tsx)$/.test(id)) {
72
+ return null;
73
+ }
74
+ if (id.includes("node_modules")) {
75
+ return null;
76
+ }
77
+ // Dynamic import to ensure @babel/core is only loaded in Node.js context
78
+ const { types: t, transformSync } = await import("@babel/core");
79
+ const babelOptions = {
80
+ plugins: [createBabelPlugin(t)],
81
+ parserOpts: {
82
+ plugins: ["jsx", "typescript"],
83
+ },
84
+ filename: id,
85
+ sourceFileName: id,
86
+ };
87
+ const result = transformSync(code, babelOptions);
88
+ if (!result?.code) {
89
+ return null;
90
+ }
91
+ return {
92
+ code: result.code,
93
+ map: result.map || null,
94
+ };
95
+ };
96
+ //# sourceMappingURL=transform-data-llm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-data-llm.js","sourceRoot":"","sources":["../src/transform-data-llm.ts"],"names":[],"mappings":"AAEA,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAO1C,SAAS,iBAAiB,CAAC,CAAe;IACxC,OAAO;QACL,IAAI,EAAE,gBAAgB;QAEtB,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,KAAK,CAAC,IAAI,EAAE,KAAK;oBACf,KAAK,CAAC,gBAAgB,GAAG,KAAK,CAAC;oBAC/B,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC;oBAEjC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;wBAClC,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;4BACjC,SAAS;wBACX,CAAC;wBACD,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,KA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AC;AACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,56 @@
1
1
  {
2
2
  "name": "@skybridge/vite-plugin",
3
- "version": "0.0.0",
4
- "publishConfig": {
5
- "access": "public"
3
+ "version": "2.0.0-beta.5e34c1e",
4
+ "description": "The Skybridge Vite plugin: view discovery, data-llm transforms, and eval wiring",
5
+ "license": "ISC",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/alpic-ai/skybridge.git"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "./evals": {
17
+ "types": "./dist/evals/index.d.ts",
18
+ "default": "./dist/evals/index.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "dependencies": {
25
+ "@babel/core": "^7.29.7"
26
+ },
27
+ "peerDependencies": {
28
+ "skybridge": "^2.0.0-beta.0",
29
+ "vite": ">=7.3.1",
30
+ "vitest": ">=4.1.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/babel__core": "^7.20.5",
34
+ "@types/node": "^24.13.3",
35
+ "typescript": "^5.9.3",
36
+ "vite": "^8.1.5",
37
+ "vitest": "^4.1.10",
38
+ "skybridge": "2.0.0-beta.5e34c1e"
39
+ },
40
+ "engines": {
41
+ "node": ">=22.23.1"
42
+ },
43
+ "peerDependenciesMeta": {
44
+ "vitest": {
45
+ "optional": true
46
+ }
47
+ },
48
+ "scripts": {
49
+ "build": "tsc -p tsconfig.json",
50
+ "format": "biome check --write --error-on-warnings",
51
+ "test": "pnpm run test:format && pnpm run test:types && pnpm run test:unit",
52
+ "test:format": "biome ci",
53
+ "test:types": "tsc --noEmit -p tsconfig.test.json",
54
+ "test:unit": "vitest run"
6
55
  }
7
- }
56
+ }