@skybridge/vite-plugin 0.0.0-dev.7aada9d → 0.0.0-dev.8a4b6f5
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/README.md +22 -0
- package/dist/evals/global-setup.d.ts +4 -0
- package/dist/evals/global-setup.d.ts.map +1 -0
- package/dist/evals/global-setup.js +25 -0
- package/dist/evals/global-setup.js.map +1 -0
- package/dist/evals/index.d.ts +3 -0
- package/dist/evals/index.d.ts.map +1 -0
- package/dist/evals/index.js +2 -0
- package/dist/evals/index.js.map +1 -0
- package/dist/evals/matchers.d.ts +29 -0
- package/dist/evals/matchers.d.ts.map +1 -0
- package/dist/evals/matchers.js +102 -0
- package/dist/evals/matchers.js.map +1 -0
- package/dist/evals/server-harness.d.ts +18 -0
- package/dist/evals/server-harness.d.ts.map +1 -0
- package/dist/evals/server-harness.js +79 -0
- package/dist/evals/server-harness.js.map +1 -0
- package/dist/evals/types.d.ts +33 -0
- package/dist/evals/types.d.ts.map +1 -0
- package/dist/evals/types.js +2 -0
- package/dist/evals/types.js.map +1 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +10 -20
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +15 -28
- package/dist/plugin.js.map +1 -1
- package/package.json +15 -3
- package/dist/scan-views.d.ts +0 -17
- package/dist/scan-views.d.ts.map +0 -1
- package/dist/scan-views.js +0 -88
- package/dist/scan-views.js.map +0 -1
- package/dist/validate-view.d.ts +0 -2
- package/dist/validate-view.d.ts.map +0 -1
- package/dist/validate-view.js +0 -9
- package/dist/validate-view.js.map +0 -1
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 @@
|
|
|
1
|
+
{"version":3,"file":"global-setup.d.ts","sourceRoot":"","sources":["../../src/evals/global-setup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,YAAY,CAAC;AAEpB,wBAA8B,KAAK,CAAC,OAAO,EAAE,WAAW,8CAwBvD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { startServer } from "./server-harness.js";
|
|
2
|
+
import "./types.js";
|
|
3
|
+
export default async function setup(project) {
|
|
4
|
+
const options = project.config.provide?.skybridgeEvals;
|
|
5
|
+
if (options === undefined) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (options.server !== undefined) {
|
|
9
|
+
project.provide("skybridgeEvalsUrl", options.server);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (options.project === undefined) {
|
|
13
|
+
throw new Error("The evals plugin needs either `server` or `project`");
|
|
14
|
+
}
|
|
15
|
+
const server = await startServer(options.project);
|
|
16
|
+
project.provide("skybridgeEvalsUrl", server.url);
|
|
17
|
+
return async () => {
|
|
18
|
+
const output = server.output().trim();
|
|
19
|
+
await server.stop();
|
|
20
|
+
if (output !== "") {
|
|
21
|
+
console.log(`\n--- server output ---\n${output}\n---`);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=global-setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-setup.js","sourceRoot":"","sources":["../../src/evals/global-setup.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,YAAY,CAAC;AAEpB,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,KAAK,CAAC,OAAoB;IACtD,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC;IACvD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO;IACT,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO,CAAC,OAAO,CAAC,mBAAmB,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACrD,OAAO;IACT,CAAC;IACD,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAClD,OAAO,CAAC,OAAO,CAAC,mBAAmB,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAEjD,OAAO,KAAK,IAAI,EAAE;QAChB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC;QACtC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;YAClB,OAAO,CAAC,GAAG,CAAC,4BAA4B,MAAM,OAAO,CAAC,CAAC;QACzD,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/evals/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ToolInput, ToolNames } from "skybridge/server";
|
|
2
|
+
import type { ChatLike } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Assertions about the tool calls a conversation produced. Kept off vitest's
|
|
5
|
+
* global `Matchers` so they never appear on unrelated `expect()` calls, and so
|
|
6
|
+
* this stays the one place later tool-call helpers are added.
|
|
7
|
+
*/
|
|
8
|
+
export interface ChatMatchers<App> {
|
|
9
|
+
toHaveCalledToolOnce<Name extends ToolNames<App>>(name: Name, args?: Partial<ToolInput<App, Name>>): void;
|
|
10
|
+
toHaveCalledToolWith<Name extends ToolNames<App>>(name: Name, args: Partial<ToolInput<App, Name>>): void;
|
|
11
|
+
toNeverHaveCalledTool<Name extends ToolNames<App>>(name: Name): void;
|
|
12
|
+
toHaveFailedToolCall<Name extends ToolNames<App>>(name: Name): void;
|
|
13
|
+
/**
|
|
14
|
+
* Whether any assistant turn matches. A string matches case-insensitively as
|
|
15
|
+
* a substring, with runs of whitespace collapsed; a RegExp is used as
|
|
16
|
+
* written. Model prose varies between runs, so prefer asserting on tool
|
|
17
|
+
* calls where you can, and keep these assertions loose.
|
|
18
|
+
*/
|
|
19
|
+
toHaveSaid(text: string | RegExp): void;
|
|
20
|
+
}
|
|
21
|
+
export interface ChatAssertion<App> extends ChatMatchers<App> {
|
|
22
|
+
not: ChatMatchers<App>;
|
|
23
|
+
}
|
|
24
|
+
declare module "vitest" {
|
|
25
|
+
interface ExpectStatic {
|
|
26
|
+
chat<App>(chat: ChatLike<App>): ChatAssertion<App>;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# 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,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;;;;;OAKG;IACH,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,102 @@
|
|
|
1
|
+
import { expect } from "vitest";
|
|
2
|
+
function attemptedCalls(chat, name) {
|
|
3
|
+
return chat.toolCalls.filter((call) => String(call.name) === name);
|
|
4
|
+
}
|
|
5
|
+
function acceptedCalls(chat, name) {
|
|
6
|
+
return attemptedCalls(chat, name).filter((call) => call.failed === undefined);
|
|
7
|
+
}
|
|
8
|
+
function observed(chat) {
|
|
9
|
+
if (chat.toolCalls.length === 0) {
|
|
10
|
+
return " (no tool was called)";
|
|
11
|
+
}
|
|
12
|
+
return chat.toolCalls
|
|
13
|
+
.map((call, index) => ` ${index + 1}. ${call.name} ${JSON.stringify(call.arguments)}${call.failed === undefined ? "" : ` (failed: ${call.failed})`}`)
|
|
14
|
+
.join("\n");
|
|
15
|
+
}
|
|
16
|
+
function collapse(text) {
|
|
17
|
+
return text.replace(/\s+/g, " ").trim();
|
|
18
|
+
}
|
|
19
|
+
function said(chat, text) {
|
|
20
|
+
return chat.assistantTurns.some((turn) => typeof text === "string"
|
|
21
|
+
? collapse(turn).toLowerCase().includes(collapse(text).toLowerCase())
|
|
22
|
+
: text.test(turn));
|
|
23
|
+
}
|
|
24
|
+
function spoken(chat) {
|
|
25
|
+
if (chat.assistantTurns.length === 0) {
|
|
26
|
+
return " (the assistant said nothing)";
|
|
27
|
+
}
|
|
28
|
+
return chat.assistantTurns
|
|
29
|
+
.map((turn, index) => ` ${index + 1}. ${collapse(turn)}`)
|
|
30
|
+
.join("\n");
|
|
31
|
+
}
|
|
32
|
+
function report(chat, summary) {
|
|
33
|
+
return `${summary}
|
|
34
|
+
|
|
35
|
+
Calls the model actually made:
|
|
36
|
+
${observed(chat)}
|
|
37
|
+
|
|
38
|
+
Tool definitions the model was looking at:
|
|
39
|
+
${chat.describeTools()}`;
|
|
40
|
+
}
|
|
41
|
+
expect.extend({
|
|
42
|
+
toHaveCalledToolOnce(received, name, args) {
|
|
43
|
+
const matching = acceptedCalls(received, name);
|
|
44
|
+
const argsMatch = args === undefined ||
|
|
45
|
+
(matching.length === 1 &&
|
|
46
|
+
this.equals(matching[0]?.arguments, expect.objectContaining(args)));
|
|
47
|
+
const pass = matching.length === 1 && argsMatch;
|
|
48
|
+
return {
|
|
49
|
+
pass,
|
|
50
|
+
message: () => report(received, pass
|
|
51
|
+
? `Expected "${name}" not to be called exactly once.`
|
|
52
|
+
: matching.length === 1
|
|
53
|
+
? `Expected "${name}" to be called once with ${JSON.stringify(args)}, but it was called with ${JSON.stringify(matching[0]?.arguments)}.`
|
|
54
|
+
: `Expected "${name}" to be called exactly once by a call that succeeded, but ${matching.length} such calls were made.`),
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
toHaveCalledToolWith(received, name, args) {
|
|
58
|
+
const pass = acceptedCalls(received, name).some((call) => this.equals(call.arguments, expect.objectContaining(args)));
|
|
59
|
+
return {
|
|
60
|
+
pass,
|
|
61
|
+
message: () => report(received, pass
|
|
62
|
+
? `Expected no call to "${name}" with ${JSON.stringify(args)}.`
|
|
63
|
+
: `Expected "${name}" to be called with ${JSON.stringify(args)}.`),
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
toHaveFailedToolCall(received, name) {
|
|
67
|
+
const attempted = attemptedCalls(received, name);
|
|
68
|
+
const failed = attempted.filter((call) => call.failed !== undefined);
|
|
69
|
+
return {
|
|
70
|
+
pass: failed.length > 0,
|
|
71
|
+
message: () => report(received, failed.length > 0
|
|
72
|
+
? `Expected every call to "${name}" to succeed.`
|
|
73
|
+
: attempted.length === 0
|
|
74
|
+
? `Expected "${name}" to be called and fail, but it was never called.`
|
|
75
|
+
: `Expected "${name}" to fail, but all ${attempted.length} calls succeeded.`),
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
toHaveSaid(received, text) {
|
|
79
|
+
const pass = said(received, text);
|
|
80
|
+
const wanted = typeof text === "string" ? `"${text}"` : String(text);
|
|
81
|
+
return {
|
|
82
|
+
pass,
|
|
83
|
+
message: () => `${pass
|
|
84
|
+
? `Expected the assistant not to say ${wanted}.`
|
|
85
|
+
: `Expected the assistant to say ${wanted}.`}
|
|
86
|
+
|
|
87
|
+
What the assistant actually said:
|
|
88
|
+
${spoken(received)}`,
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
toNeverHaveCalledTool(received, name) {
|
|
92
|
+
const matching = attemptedCalls(received, name);
|
|
93
|
+
return {
|
|
94
|
+
pass: matching.length === 0,
|
|
95
|
+
message: () => report(received, matching.length === 0
|
|
96
|
+
? `Expected "${name}" to be called at least once.`
|
|
97
|
+
: `Expected "${name}" never to be called, but it was called ${matching.length} times.`),
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
expect.chat = (chat) => expect(chat);
|
|
102
|
+
//# sourceMappingURL=matchers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchers.js","sourceRoot":"","sources":["../../src/evals/matchers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAsChC,SAAS,cAAc,CACrB,IAAuB,EACvB,IAAY;IAEZ,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,aAAa,CACpB,IAAuB,EACvB,IAAY;IAEZ,OAAO,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,QAAQ,CAAC,IAAuB;IACvC,IAAI,IAAI,CAAC,SAAS,CAAC,M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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,18 @@
|
|
|
1
|
+
export interface RunningServer {
|
|
2
|
+
url: string;
|
|
3
|
+
/** Everything the server wrote to stdout/stderr, for failure reports. */
|
|
4
|
+
output: () => string;
|
|
5
|
+
stop: () => Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Spawns the project's server with `__PORT=0` and an IPC channel, and waits
|
|
9
|
+
* for the `skybridge:listening` message carrying the port the OS picked.
|
|
10
|
+
* Binding and reporting both happen in the child, so there is no window in
|
|
11
|
+
* which another process can steal the port.
|
|
12
|
+
*/
|
|
13
|
+
export declare function startServer({ cwd, command, env, }: {
|
|
14
|
+
cwd: string;
|
|
15
|
+
command: string[];
|
|
16
|
+
env?: Record<string, string>;
|
|
17
|
+
}): Promise<RunningServer>;
|
|
18
|
+
//# sourceMappingURL=server-harness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-harness.d.ts","sourceRoot":"","sources":["../../src/evals/server-harness.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,yEAAyE;IACzE,MAAM,EAAE,MAAM,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAiBD;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,EAChC,GAAG,EACH,OAAO,EACP,GAAQ,GACT,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B,GAAG,OAAO,CAAC,aAAa,CAAC,CA4EzB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
function hasExited(child) {
|
|
4
|
+
return child.exitCode !== null || child.signalCode !== null;
|
|
5
|
+
}
|
|
6
|
+
function isListeningMessage(message) {
|
|
7
|
+
return (typeof message === "object" &&
|
|
8
|
+
message !== null &&
|
|
9
|
+
message.type === "skybridge:listening" &&
|
|
10
|
+
typeof message.port === "number");
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Spawns the project's server with `__PORT=0` and an IPC channel, and waits
|
|
14
|
+
* for the `skybridge:listening` message carrying the port the OS picked.
|
|
15
|
+
* Binding and reporting both happen in the child, so there is no window in
|
|
16
|
+
* which another process can steal the port.
|
|
17
|
+
*/
|
|
18
|
+
export async function startServer({ cwd, command, env = {}, }) {
|
|
19
|
+
const timeoutMs = 60_000;
|
|
20
|
+
const [bin, ...args] = command;
|
|
21
|
+
if (bin === undefined) {
|
|
22
|
+
throw new Error("Empty server command");
|
|
23
|
+
}
|
|
24
|
+
const executable = bin.startsWith(".") ? resolve(cwd, bin) : bin;
|
|
25
|
+
const child = spawn(executable, args, {
|
|
26
|
+
cwd,
|
|
27
|
+
env: {
|
|
28
|
+
...process.env,
|
|
29
|
+
NODE_ENV: "production",
|
|
30
|
+
...env,
|
|
31
|
+
__PORT: "0",
|
|
32
|
+
},
|
|
33
|
+
stdio: ["ignore", "pipe", "pipe", "ipc"],
|
|
34
|
+
});
|
|
35
|
+
let captured = "";
|
|
36
|
+
const output = () => captured;
|
|
37
|
+
child.stdout?.on("data", (chunk) => {
|
|
38
|
+
captured += chunk;
|
|
39
|
+
});
|
|
40
|
+
child.stderr?.on("data", (chunk) => {
|
|
41
|
+
captured += chunk;
|
|
42
|
+
});
|
|
43
|
+
const stop = async () => {
|
|
44
|
+
if (hasExited(child)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const exited = new Promise((resolveExit) => {
|
|
48
|
+
child.once("exit", () => resolveExit());
|
|
49
|
+
});
|
|
50
|
+
child.kill("SIGTERM");
|
|
51
|
+
const forced = setTimeout(() => child.kill("SIGKILL"), 3_000);
|
|
52
|
+
await exited;
|
|
53
|
+
clearTimeout(forced);
|
|
54
|
+
};
|
|
55
|
+
const port = await new Promise((resolvePort, reject) => {
|
|
56
|
+
const timer = setTimeout(() => {
|
|
57
|
+
reject(new Error(`Server did not report a port in ${timeoutMs}ms. \`command\` must start the server process directly (node, tsx): wrappers such as \`pnpm run\` do not forward the IPC channel the readiness signal uses. It must also run a skybridge version that sends skybridge:listening.\n${output()}`));
|
|
58
|
+
}, timeoutMs);
|
|
59
|
+
child.on("message", (message) => {
|
|
60
|
+
if (isListeningMessage(message)) {
|
|
61
|
+
clearTimeout(timer);
|
|
62
|
+
resolvePort(message.port);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
child.on("error", (error) => {
|
|
66
|
+
clearTimeout(timer);
|
|
67
|
+
reject(new Error(`Failed to spawn ${command.join(" ")}: ${error.message}`));
|
|
68
|
+
});
|
|
69
|
+
child.on("exit", () => {
|
|
70
|
+
clearTimeout(timer);
|
|
71
|
+
reject(new Error(`Server exited with code ${child.exitCode} before reporting its port:\n${output()}`));
|
|
72
|
+
});
|
|
73
|
+
}).catch(async (error) => {
|
|
74
|
+
await stop();
|
|
75
|
+
throw error;
|
|
76
|
+
});
|
|
77
|
+
return { url: `http://127.0.0.1:${port}/mcp`, output, stop };
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=server-harness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-harness.js","sourceRoot":"","sources":["../../src/evals/server-harness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,SAAS,SAAS,CAAC,KAAmB;IACpC,OAAO,KAAK,CAAC,QAAQ,KAAK,IAAI,IAAI,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;AAC9D,CAAC;AAED,SAAS,kBAAkB,CACzB,OAAgB;IAEhB,OAAO,CACL,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,KAAK,IAAI;QACf,OAA8B,CAAC,IAAI,KAAK,qBAAqB;QAC9D,OAAQ,OAA8B,CAAC,IAAI,KAAK,QAAQ,CACzD,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,EAChC,GAAG,EACH,OAAO,EACP,GAAG,GAAG,EAAE,GAKT;IACC,MAAM,SAAS,GAAG,MAAM,CAAC;IACzB,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC;IAC/B,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO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 +1,33 @@
|
|
|
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
|
+
readonly toolCalls: ToolCall<App>[];
|
|
18
|
+
readonly assistantTurns: string[];
|
|
19
|
+
/**
|
|
20
|
+
* The tool definitions the model was looking at, rendered for failure
|
|
21
|
+
* reports. Deliberately a string: descriptions and schemas are prompt text
|
|
22
|
+
* that changes freely, so they are worth reading when an eval fails and not
|
|
23
|
+
* worth asserting on.
|
|
24
|
+
*/
|
|
25
|
+
describeTools(): string;
|
|
26
|
+
}
|
|
27
|
+
declare module "vitest" {
|
|
28
|
+
interface ProvidedContext {
|
|
29
|
+
skybridgeEvals: EvalsOptions | undefined;
|
|
30
|
+
skybridgeEvalsUrl: string | undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# 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,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;IACpC,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;IAClC;;;;;OAKG;IACH,aAAa,IAAI,MAAM,CAAC;CACzB;AAED,OAAO,QAAQ,QAAQ,CAAC;IACtB,UAAU,eAAe;QACvB,cAAc,EAAE,YAAY,GAAG,SAAS,CAAC;QACzC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;KACvC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/evals/types.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export { type
|
|
2
|
-
export { assertUniqueViewNames, type DiscoveredView, discoverViewsSync, scanAndWriteViewsDts, scanViewsSync, writeViewsDts, } from "./scan-views.js";
|
|
1
|
+
export { type EvalsOptions, type SkybridgePluginOptions, skybridge, } from "./plugin.js";
|
|
3
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,
|
|
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
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,GACV,MAAM,aAAa,CAAC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,GACV,MAAM,aAAa,CAAC"}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
2
|
/**
|
|
3
|
-
* Options for the eval runner wired in through the `evals` plugin option
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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
6
|
*/
|
|
7
|
-
export interface
|
|
8
|
-
model: {
|
|
9
|
-
provider: "anthropic";
|
|
10
|
-
name: string;
|
|
11
|
-
apiKeyEnv?: string;
|
|
12
|
-
} | {
|
|
13
|
-
file: string;
|
|
14
|
-
};
|
|
7
|
+
export interface EvalsOptions {
|
|
15
8
|
temperature?: number;
|
|
16
9
|
systemPrompt?: string;
|
|
17
10
|
maxSteps?: number;
|
|
@@ -33,14 +26,11 @@ export interface SkybridgePluginOptions {
|
|
|
33
26
|
*/
|
|
34
27
|
serverExternal?: string[];
|
|
35
28
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* vitest uses for evals; when omitted, no test config is contributed and
|
|
40
|
-
* ordinary unit tests are unaffected. Requires `@skybridge/test` as a dev
|
|
41
|
-
* dependency.
|
|
29
|
+
* Runs the app's eval scenarios against a real model: how to boot the server
|
|
30
|
+
* they talk to, plus defaults for the conversation. Point vitest at this
|
|
31
|
+
* config to run them. Requires `@skybridge/test` as a dev dependency.
|
|
42
32
|
*/
|
|
43
|
-
evals?:
|
|
33
|
+
evals?: EvalsOptions;
|
|
44
34
|
}
|
|
45
35
|
/**
|
|
46
36
|
* Vite plugin that wires a Skybridge project's view files into Vite.
|
|
@@ -68,5 +58,5 @@ export interface SkybridgePluginOptions {
|
|
|
68
58
|
* });
|
|
69
59
|
* ```
|
|
70
60
|
*/
|
|
71
|
-
export declare function skybridge(options?: SkybridgePluginOptions):
|
|
61
|
+
export declare function skybridge(options?: SkybridgePluginOptions): Plugin;
|
|
72
62
|
//# sourceMappingURL=plugin.d.ts.map
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAOlD;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAC9B,CAAC;CACH;AAED,qDAAqD;AACrD,MAAM,WAAW,sBAAsB;IACrC,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;OAIG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAmBD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM,CAElE"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
1
|
import { isAbsolute, relative, resolve } from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
import { assertUniqueViewNames, discoverViewsSync, scanViewsSync, writeViewsDts, } from "
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { assertUniqueViewNames, discoverViewsSync, hasDefaultExport, scanViewsSync, writeViewsDts, } from "skybridge/views";
|
|
5
4
|
import { transform as dataLlmTransform } from "./transform-data-llm.js";
|
|
6
|
-
import { hasDefaultExport } from "./validate-view.js";
|
|
7
5
|
const VIRTUAL_PREFIX = "/_skybridge/view/";
|
|
8
6
|
const VIRTUAL_MODULE_PREFIX = "\0skybridge:view:";
|
|
9
7
|
function buildVirtualEntry(viewFilePath) {
|
|
@@ -46,29 +44,10 @@ function getViewEntryPattern(viewsDir) {
|
|
|
46
44
|
* ```
|
|
47
45
|
*/
|
|
48
46
|
export function skybridge(options) {
|
|
49
|
-
|
|
50
|
-
const evals = options?.evals;
|
|
51
|
-
if (evals !== undefined) {
|
|
52
|
-
plugins.push(loadEvalsPlugin(evals));
|
|
53
|
-
}
|
|
54
|
-
return plugins;
|
|
47
|
+
return viewsPlugin(options);
|
|
55
48
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
* this package, which never depends on it: the eval runtime is an optional
|
|
59
|
-
* dev dependency of the app.
|
|
60
|
-
*/
|
|
61
|
-
async function loadEvalsPlugin(evals) {
|
|
62
|
-
const projectRequire = createRequire(resolve(process.cwd(), "package.json"));
|
|
63
|
-
let resolved;
|
|
64
|
-
try {
|
|
65
|
-
resolved = projectRequire.resolve("@skybridge/test/plugin");
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
throw new Error("The `evals` option requires the @skybridge/test package. Install it as a dev dependency.");
|
|
69
|
-
}
|
|
70
|
-
const module = (await import(pathToFileURL(resolved).href));
|
|
71
|
-
return module.evals(evals);
|
|
49
|
+
function here(file) {
|
|
50
|
+
return fileURLToPath(new URL(file, import.meta.url));
|
|
72
51
|
}
|
|
73
52
|
function viewsPlugin(options) {
|
|
74
53
|
const rawViewsDir = options?.viewsDir ?? "src/views";
|
|
@@ -95,7 +74,7 @@ function viewsPlugin(options) {
|
|
|
95
74
|
for (const view of views) {
|
|
96
75
|
input[view.name] = `${VIRTUAL_PREFIX}${view.name}`;
|
|
97
76
|
}
|
|
98
|
-
|
|
77
|
+
const base = {
|
|
99
78
|
base: "/assets",
|
|
100
79
|
// Fixes "Invalid hook call" on createStore by forcing a single
|
|
101
80
|
// copy of React. Under pnpm's isolated node_modules, zustand
|
|
@@ -146,6 +125,14 @@ function viewsPlugin(options) {
|
|
|
146
125
|
},
|
|
147
126
|
},
|
|
148
127
|
};
|
|
128
|
+
return {
|
|
129
|
+
...base,
|
|
130
|
+
test: {
|
|
131
|
+
setupFiles: [here("./evals/matchers.js")],
|
|
132
|
+
globalSetup: [here("./evals/global-setup.js")],
|
|
133
|
+
provide: { skybridgeEvals: options?.evals },
|
|
134
|
+
},
|
|
135
|
+
};
|
|
149
136
|
},
|
|
150
137
|
resolveId(id) {
|
|
151
138
|
if (id.startsWith(VIRTUAL_PREFIX)) {
|
|
@@ -217,7 +204,7 @@ function viewsPlugin(options) {
|
|
|
217
204
|
server.watcher.on("unlink", rescan);
|
|
218
205
|
},
|
|
219
206
|
async transform(code, id) {
|
|
220
|
-
if (viewEntryPattern?.test(id) && !hasDefaultExport(code
|
|
207
|
+
if (viewEntryPattern?.test(id) && !hasDefaultExport(code)) {
|
|
221
208
|
this.warn(`View file "${id.split("/").pop()}" is missing a default export.`);
|
|
222
209
|
}
|
|
223
210
|
return await dataLlmTransform(code, id);
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
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;AAGzB,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAExE,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAC3C,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AAqClD,SAAS,iBAAiB,CAAC,YAAoB;IAC7C,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACpD,OAAO;QACL,4CAA4C;QAC5C,0BAA0B,UAAU,IAAI;QACxC,wCAAwC;QACxC,sCAAsC;KACvC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED,SAAS,mBAAmB,CAAC,QAAgB;IAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;IAChE,OAAO,IAAI,MAAM,CACf,GAAG,OAAO,mEAAmE,CAC9E,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,SAAS,CAAC,OAAgC;IACxD,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,IAAI,CAAC,IAAY;IACxB,OAAO,aAAa,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC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AA6D;oBAC7D,+BAA+B;oBAC/B,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;oBACjE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CACxB,mCAAmC,OAAO,EAAE,CAC7C,CAAC;gBACJ,CAAC;YACH,CAAC,CAAC;YAEF,sEAAsE;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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skybridge/vite-plugin",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.8a4b6f5",
|
|
4
4
|
"description": "The Skybridge Vite plugin: view discovery, data-llm transforms, and eval wiring",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"type": "module",
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
".": {
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
14
|
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./evals": {
|
|
17
|
+
"types": "./dist/evals/index.d.ts",
|
|
18
|
+
"default": "./dist/evals/index.js"
|
|
15
19
|
}
|
|
16
20
|
},
|
|
17
21
|
"files": [
|
|
@@ -21,18 +25,26 @@
|
|
|
21
25
|
"@babel/core": "^7.29.7"
|
|
22
26
|
},
|
|
23
27
|
"peerDependencies": {
|
|
24
|
-
"
|
|
28
|
+
"skybridge": "^2.0.0",
|
|
29
|
+
"vite": ">=7.3.1",
|
|
30
|
+
"vitest": ">=4.1.0"
|
|
25
31
|
},
|
|
26
32
|
"devDependencies": {
|
|
27
33
|
"@types/babel__core": "^7.20.5",
|
|
28
34
|
"@types/node": "^24.13.3",
|
|
29
35
|
"typescript": "^5.9.3",
|
|
30
36
|
"vite": "^8.1.5",
|
|
31
|
-
"vitest": "^4.1.10"
|
|
37
|
+
"vitest": "^4.1.10",
|
|
38
|
+
"skybridge": "0.0.0-dev.8a4b6f5"
|
|
32
39
|
},
|
|
33
40
|
"engines": {
|
|
34
41
|
"node": ">=22.23.1"
|
|
35
42
|
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"vitest": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
47
|
+
},
|
|
36
48
|
"scripts": {
|
|
37
49
|
"build": "tsc -p tsconfig.json",
|
|
38
50
|
"format": "biome check --write --error-on-warnings",
|
package/dist/scan-views.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export interface DiscoveredView {
|
|
2
|
-
name: string;
|
|
3
|
-
filePath: string;
|
|
4
|
-
}
|
|
5
|
-
export interface InvalidView {
|
|
6
|
-
filePath: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function scanViewsSync(viewsDir: string): {
|
|
9
|
-
valid: DiscoveredView[];
|
|
10
|
-
invalid: InvalidView[];
|
|
11
|
-
};
|
|
12
|
-
export declare function assertUniqueViewNames(views: DiscoveredView[]): void;
|
|
13
|
-
export declare function discoverViewsSync(viewsDir: string): DiscoveredView[];
|
|
14
|
-
export declare function generateViewsDts(views: DiscoveredView[]): string;
|
|
15
|
-
export declare function writeViewsDts(projectRoot: string, views: DiscoveredView[]): void;
|
|
16
|
-
export declare function scanAndWriteViewsDts(projectRoot?: string, viewsDir?: string): void;
|
|
17
|
-
//# sourceMappingURL=scan-views.d.ts.map
|
package/dist/scan-views.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scan-views.d.ts","sourceRoot":"","sources":["../src/scan-views.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG;IAC/C,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,OAAO,EAAE,WAAW,EAAE,CAAC;CACxB,CAmCA;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,IAAI,CAenE;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,EAAE,CAIpE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,MAAM,CAYhE;AAED,wBAAgB,aAAa,CAC3B,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,cAAc,EAAE,GACtB,IAAI,CAiBN;AAED,wBAAgB,oBAAoB,CAClC,WAAW,CAAC,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,MAAM,GAChB,IAAI,CAON"}
|
package/dist/scan-views.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { globSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { basename, dirname, isAbsolute, join, parse, resolve } from "node:path";
|
|
3
|
-
import { hasDefaultExport } from "./validate-view.js";
|
|
4
|
-
export function scanViewsSync(viewsDir) {
|
|
5
|
-
const flatPattern = resolve(viewsDir, "*.{tsx,jsx}");
|
|
6
|
-
const dirPattern = resolve(viewsDir, "*/index.{tsx,jsx}");
|
|
7
|
-
const flatFiles = globSync(flatPattern).map((file) => ({
|
|
8
|
-
name: parse(file).name,
|
|
9
|
-
filePath: file,
|
|
10
|
-
}));
|
|
11
|
-
const dirFiles = globSync(dirPattern).map((file) => ({
|
|
12
|
-
name: basename(dirname(file)),
|
|
13
|
-
filePath: file,
|
|
14
|
-
}));
|
|
15
|
-
// A barrel file like `views/foo/index.tsx` (no default export) must not
|
|
16
|
-
// falsely collide with a sibling `views/foo.tsx`. Drop top-level `index`
|
|
17
|
-
// before splitting valid vs invalid.
|
|
18
|
-
const candidates = [...flatFiles, ...dirFiles].filter((v) => v.name !== "index");
|
|
19
|
-
const valid = [];
|
|
20
|
-
const invalid = [];
|
|
21
|
-
for (const candidate of candidates) {
|
|
22
|
-
const code = readFileSync(candidate.filePath, "utf-8");
|
|
23
|
-
if (hasDefaultExport(code, candidate.filePath)) {
|
|
24
|
-
valid.push(candidate);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
invalid.push({
|
|
28
|
-
filePath: candidate.filePath,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return { valid, invalid };
|
|
33
|
-
}
|
|
34
|
-
export function assertUniqueViewNames(views) {
|
|
35
|
-
const nameMap = new Map();
|
|
36
|
-
for (const view of views) {
|
|
37
|
-
const paths = nameMap.get(view.name) ?? [];
|
|
38
|
-
paths.push(view.filePath);
|
|
39
|
-
nameMap.set(view.name, paths);
|
|
40
|
-
}
|
|
41
|
-
for (const [name, paths] of nameMap) {
|
|
42
|
-
if (paths.length > 1) {
|
|
43
|
-
throw new Error(`skybridge: duplicate view name "${name}" resolved from:\n - ${paths.join("\n - ")}\nRename one of the files to avoid the conflict.`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export function discoverViewsSync(viewsDir) {
|
|
48
|
-
const { valid } = scanViewsSync(viewsDir);
|
|
49
|
-
assertUniqueViewNames(valid);
|
|
50
|
-
return valid;
|
|
51
|
-
}
|
|
52
|
-
export function generateViewsDts(views) {
|
|
53
|
-
const entries = views.map((v) => ` "${v.name}": true;`).join("\n");
|
|
54
|
-
return [
|
|
55
|
-
"export {};",
|
|
56
|
-
"",
|
|
57
|
-
'declare module "skybridge/server" {',
|
|
58
|
-
" interface ViewNameRegistry {",
|
|
59
|
-
entries,
|
|
60
|
-
" }",
|
|
61
|
-
"}",
|
|
62
|
-
"",
|
|
63
|
-
].join("\n");
|
|
64
|
-
}
|
|
65
|
-
export function writeViewsDts(projectRoot, views) {
|
|
66
|
-
const dir = join(projectRoot, ".skybridge");
|
|
67
|
-
mkdirSync(dir, { recursive: true });
|
|
68
|
-
const filePath = join(dir, "views.d.ts");
|
|
69
|
-
const content = generateViewsDts(views);
|
|
70
|
-
try {
|
|
71
|
-
const existing = readFileSync(filePath, "utf-8");
|
|
72
|
-
if (existing === content) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
// File doesn't exist yet
|
|
78
|
-
}
|
|
79
|
-
writeFileSync(filePath, content, "utf-8");
|
|
80
|
-
}
|
|
81
|
-
export function scanAndWriteViewsDts(projectRoot, viewsDir) {
|
|
82
|
-
const root = projectRoot ?? process.cwd();
|
|
83
|
-
const rawDir = viewsDir ?? "src/views";
|
|
84
|
-
const resolvedDir = isAbsolute(rawDir) ? rawDir : resolve(root, rawDir);
|
|
85
|
-
const views = discoverViewsSync(resolvedDir);
|
|
86
|
-
writeViewsDts(root, views);
|
|
87
|
-
}
|
|
88
|
-
//# sourceMappingURL=scan-views.js.map
|
package/dist/scan-views.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,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,CAAC;IAExE,MAAM,KAAK,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAC7C,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC7B,CAAC"}
|
package/dist/validate-view.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate-view.d.ts","sourceRoot":"","sources":["../src/validate-view.ts"],"names":[],"mappings":"AAIA,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAM1E"}
|
package/dist/validate-view.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
function stripComments(code) {
|
|
2
|
-
return code.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
3
|
-
}
|
|
4
|
-
export function hasDefaultExport(code, _filePath) {
|
|
5
|
-
const stripped = stripComments(code);
|
|
6
|
-
return (/export\s+default\s/.test(stripped) ||
|
|
7
|
-
/export\s*\{[^}]*\bas\s+default\b[^}]*}/.test(stripped));
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=validate-view.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate-view.js","sourceRoot":"","sources":["../src/validate-view.ts"],"names":[],"mappings":"AAAA,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,SAAkB;IAC/D,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACrC,OAAO,CACL,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC;QACnC,wCAAwC,CAAC,IAAI,CAAC,QAAQ,CAAC,CACxD,CAAC;AACJ,CAAC"}
|