skybridge 0.0.0-dev.d8535f2 → 0.0.0-dev.d8b52a9
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 +125 -0
- package/dist/src/server/index.d.ts +2 -0
- package/dist/src/server/inferUtilityTypes.d.ts +44 -0
- package/dist/src/server/inferUtilityTypes.js +2 -0
- package/dist/src/server/inferUtilityTypes.js.map +1 -0
- package/dist/src/server/server.d.ts +13 -7
- package/dist/src/server/server.js +5 -1
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/test/utils.js +1 -1
- package/dist/src/test/utils.js.map +1 -1
- package/dist/src/web/hooks/index.d.ts +2 -1
- package/dist/src/web/hooks/index.js +2 -1
- package/dist/src/web/hooks/index.js.map +1 -1
- package/dist/src/web/hooks/use-call-tool.d.ts +30 -22
- package/dist/src/web/hooks/use-call-tool.js +28 -4
- package/dist/src/web/hooks/use-call-tool.js.map +1 -1
- package/dist/src/web/hooks/use-call-tool.test.js +99 -2
- package/dist/src/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/src/web/hooks/use-files.d.ts +10 -0
- package/dist/src/web/hooks/use-files.js +7 -0
- package/dist/src/web/hooks/use-files.js.map +1 -0
- package/dist/src/web/hooks/use-files.test.js +29 -0
- package/dist/src/web/hooks/use-files.test.js.map +1 -0
- package/dist/src/web/hooks/use-request-modal.d.ts +3 -2
- package/dist/src/web/hooks/use-request-modal.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.d.ts +19 -12
- package/dist/src/web/hooks/use-tool-info.js +3 -2
- package/dist/src/web/hooks/use-tool-info.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.test-d.d.ts +1 -0
- package/dist/src/web/hooks/use-tool-info.test-d.js +74 -0
- package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -0
- package/dist/src/web/hooks/use-tool-info.test.js +30 -29
- package/dist/src/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/src/web/hooks/use-widget-state.test.js +0 -1
- package/dist/src/web/hooks/use-widget-state.test.js.map +1 -1
- package/dist/src/web/index.d.ts +1 -0
- package/dist/src/web/index.js +1 -0
- package/dist/src/web/index.js.map +1 -1
- package/dist/src/web/mount-widget.js +5 -0
- package/dist/src/web/mount-widget.js.map +1 -1
- package/dist/src/web/proxy.d.ts +1 -0
- package/dist/src/web/proxy.js +48 -0
- package/dist/src/web/proxy.js.map +1 -0
- package/dist/src/web/typed-hooks.d.ts +107 -0
- package/dist/src/web/typed-hooks.js +111 -0
- package/dist/src/web/typed-hooks.js.map +1 -0
- package/dist/src/web/typed-hooks.test-d.d.ts +1 -0
- package/dist/src/web/typed-hooks.test-d.js +72 -0
- package/dist/src/web/typed-hooks.test-d.js.map +1 -0
- package/dist/src/web/typed-hooks.test.d.ts +1 -0
- package/dist/src/web/typed-hooks.test.js +10 -0
- package/dist/src/web/typed-hooks.test.js.map +1 -0
- package/dist/src/web/types.d.ts +24 -16
- package/dist/src/web/types.js.map +1 -1
- package/dist/vitest.config.js +0 -1
- package/dist/vitest.config.js.map +1 -1
- package/package.json +1 -1
- package/dist/src/test/setup.js +0 -9
- package/dist/src/test/setup.js.map +0 -1
- /package/dist/src/{test/setup.d.ts → web/hooks/use-files.test.d.ts} +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { useCallTool } from "./hooks/use-call-tool.js";
|
|
2
|
+
import { useToolInfo } from "./hooks/use-tool-info.js";
|
|
3
|
+
/**
|
|
4
|
+
* Creates typed versions of skybridge hooks with full type inference
|
|
5
|
+
* for tool names, inputs, and outputs.
|
|
6
|
+
*
|
|
7
|
+
* This is the recommended way to use skybridge hooks in your widgets.
|
|
8
|
+
* Set this up once in a dedicated file and export the typed hooks for use across your app.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam T - The type of your McpServer instance. Use `typeof server`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // server/src/index.ts
|
|
15
|
+
* const server = new McpServer({ name: "my-app", version: "1.0" }, {})
|
|
16
|
+
* .widget("search-voyage", {}, {
|
|
17
|
+
* inputSchema: { destination: z.string() },
|
|
18
|
+
* outputSchema: { results: z.array(z.string()) },
|
|
19
|
+
* }, async ({ destination }) => {
|
|
20
|
+
* return { content: [{ type: "text", text: `Found trips to ${destination}` }] };
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* export type AppType = typeof server;
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // web/src/skybridge.ts (one-time setup)
|
|
29
|
+
* import type { AppType } from "../server";
|
|
30
|
+
* import { createTypedHooks } from "skybridge/web";
|
|
31
|
+
*
|
|
32
|
+
* export const { useCallTool, useToolInfo } = createTypedHooks<AppType>();
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // web/src/widgets/search.tsx (usage)
|
|
38
|
+
* import { useCallTool, useToolInfo } from "../skybridge";
|
|
39
|
+
*
|
|
40
|
+
* export function SearchWidget() {
|
|
41
|
+
* const { callTool, data } = useCallTool("search-voyage");
|
|
42
|
+
* // ^ autocomplete for tool names
|
|
43
|
+
* callTool({ destination: "Spain" });
|
|
44
|
+
* // ^ autocomplete for input fields
|
|
45
|
+
*
|
|
46
|
+
* const toolInfo = useToolInfo<"search-voyage">();
|
|
47
|
+
* // ^ autocomplete for widget names
|
|
48
|
+
* // toolInfo.input is typed based on widget input schema
|
|
49
|
+
* // toolInfo.output is typed based on widget output schema
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function createTypedHooks() {
|
|
54
|
+
return {
|
|
55
|
+
/**
|
|
56
|
+
* Typed version of `useCallTool` that provides autocomplete for tool names
|
|
57
|
+
* and type inference for inputs and outputs.
|
|
58
|
+
*
|
|
59
|
+
* @param name - The name of the widget to call. Autocompletes based on your server's widget registry.
|
|
60
|
+
* @returns A hook with typed `callTool` function and `data` property.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const { callTool, data, isPending } = useCallTool("search-voyage");
|
|
65
|
+
* // TypeScript knows callTool expects { destination: string }
|
|
66
|
+
* callTool({ destination: "Spain" });
|
|
67
|
+
*
|
|
68
|
+
* // data.structuredContent is typed based on your outputSchema
|
|
69
|
+
* if (data) {
|
|
70
|
+
* console.log(data.structuredContent.results);
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
useCallTool: (name) => {
|
|
75
|
+
// Type assertion is safe here because the runtime types are compatible.
|
|
76
|
+
// The underlying hook accepts broader types, but we expose narrower, more specific types.
|
|
77
|
+
return useCallTool(name);
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* Typed version of `useToolInfo` that provides autocomplete for widget names
|
|
81
|
+
* and type inference for inputs, outputs, and responseMetadata.
|
|
82
|
+
*
|
|
83
|
+
* @typeParam K - The name of the widget. Autocompletes based on your server's widget registry.
|
|
84
|
+
* @returns A discriminated union with `status: "pending" | "success"` that narrows correctly.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const toolInfo = useToolInfo<"search-voyage">();
|
|
89
|
+
* // toolInfo.input is typed as { destination: string; ... }
|
|
90
|
+
* // toolInfo.output is typed as { results: Array<...>; ... } | undefined
|
|
91
|
+
* // toolInfo.status narrows correctly: "pending" | "success"
|
|
92
|
+
*
|
|
93
|
+
* if (toolInfo.isPending) {
|
|
94
|
+
* // TypeScript knows output is undefined here
|
|
95
|
+
* console.log(toolInfo.input.destination);
|
|
96
|
+
* }
|
|
97
|
+
*
|
|
98
|
+
* if (toolInfo.isSuccess) {
|
|
99
|
+
* // TypeScript knows output is defined here
|
|
100
|
+
* console.log(toolInfo.output.results);
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
useToolInfo: () => {
|
|
105
|
+
// Type assertion is safe here because the runtime types are compatible.
|
|
106
|
+
// The underlying hook accepts broader types, but we expose narrower, more specific types.
|
|
107
|
+
return useToolInfo();
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=typed-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-hooks.js","sourceRoot":"","sources":["../../../src/web/typed-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAgCvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,MAAM,UAAU,gBAAgB;IAI9B,OAAO;QACL;;;;;;;;;;;;;;;;;;WAkBG;QACH,WAAW,EAAE,CACX,IAAO,EAIP,EAAE;YACF,wEAAwE;YACxE,0FAA0F;YAC1F,OAAO,WAAW,CAGhB,IAAI,CAGL,CAAC;QACJ,CAAC;QACD;;;;;;;;;;;;;;;;;;;;;;;;WAwBG;QACH,WAAW,EAAE,GAIX,EAAE;YACF,wEAAwE;YACxE,0FAA0F;YAC1F,OAAO,WAAW,EAQjB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { expectTypeOf, test } from "vitest";
|
|
2
|
+
import { createTypedHooks } from "./typed-hooks.js";
|
|
3
|
+
test("InferWidgets extracts the widget registry type", () => {
|
|
4
|
+
expectTypeOf().toHaveProperty("search-voyage");
|
|
5
|
+
expectTypeOf().toHaveProperty("get-trip-details");
|
|
6
|
+
expectTypeOf().toHaveProperty("no-input-widget");
|
|
7
|
+
});
|
|
8
|
+
test("WidgetNames returns a union of widget name literals", () => {
|
|
9
|
+
expectTypeOf().toEqualTypeOf();
|
|
10
|
+
});
|
|
11
|
+
test("WidgetInput extracts the correct input type from Zod schema", () => {
|
|
12
|
+
expectTypeOf().toEqualTypeOf();
|
|
13
|
+
expectTypeOf().toEqualTypeOf();
|
|
14
|
+
});
|
|
15
|
+
test("WidgetOutput extracts the correct output type from Zod schema", () => {
|
|
16
|
+
expectTypeOf().toEqualTypeOf();
|
|
17
|
+
expectTypeOf().toEqualTypeOf();
|
|
18
|
+
});
|
|
19
|
+
test("createTypedHooks provides autocomplete for widget names", () => {
|
|
20
|
+
const { useCallTool } = createTypedHooks();
|
|
21
|
+
useCallTool("search-voyage");
|
|
22
|
+
useCallTool("get-trip-details");
|
|
23
|
+
useCallTool("no-input-widget");
|
|
24
|
+
// @ts-expect-error - "invalid-name" is not a valid widget name
|
|
25
|
+
useCallTool("invalid-name");
|
|
26
|
+
});
|
|
27
|
+
test("useCallTool returns correctly typed callTool function", () => {
|
|
28
|
+
const { useCallTool } = createTypedHooks();
|
|
29
|
+
const { callTool } = useCallTool("search-voyage");
|
|
30
|
+
callTool({ destination: "Spain" });
|
|
31
|
+
callTool({ destination: "France", departureDate: "2024-06-01" });
|
|
32
|
+
callTool({ destination: "Italy", maxPrice: 1000 });
|
|
33
|
+
});
|
|
34
|
+
test("useCallTool returns correctly typed data", () => {
|
|
35
|
+
const { useCallTool } = createTypedHooks();
|
|
36
|
+
const { data } = useCallTool("search-voyage");
|
|
37
|
+
if (data) {
|
|
38
|
+
expectTypeOf(data.structuredContent).toExtend();
|
|
39
|
+
expectTypeOf(data.structuredContent.results).toBeArray();
|
|
40
|
+
expectTypeOf(data.structuredContent.totalCount).toBeNumber();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
test("widgets with no outputSchema have empty object output type", () => {
|
|
44
|
+
expectTypeOf().toEqualTypeOf();
|
|
45
|
+
});
|
|
46
|
+
test("createTypedHooks provides autocomplete for widget names in useToolInfo", () => {
|
|
47
|
+
const { useToolInfo } = createTypedHooks();
|
|
48
|
+
useToolInfo();
|
|
49
|
+
useToolInfo();
|
|
50
|
+
useToolInfo();
|
|
51
|
+
// @ts-expect-error - "invalid-name" is not a valid widget name
|
|
52
|
+
useToolInfo();
|
|
53
|
+
});
|
|
54
|
+
test("useToolInfo infers input types from WidgetInput utility", () => {
|
|
55
|
+
const { useToolInfo } = createTypedHooks();
|
|
56
|
+
const toolInfo = useToolInfo();
|
|
57
|
+
expectTypeOf(toolInfo.input).toExtend();
|
|
58
|
+
const detailsInfo = useToolInfo();
|
|
59
|
+
expectTypeOf(detailsInfo.input).toExtend();
|
|
60
|
+
});
|
|
61
|
+
test("useToolInfo infers output types from WidgetOutput utility", () => {
|
|
62
|
+
const { useToolInfo } = createTypedHooks();
|
|
63
|
+
const toolInfo = useToolInfo();
|
|
64
|
+
if (toolInfo.status === "success") {
|
|
65
|
+
expectTypeOf(toolInfo.output).toExtend();
|
|
66
|
+
}
|
|
67
|
+
const detailsInfo = useToolInfo();
|
|
68
|
+
if (detailsInfo.status === "success") {
|
|
69
|
+
expectTypeOf(detailsInfo.output).toExtend();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
//# sourceMappingURL=typed-hooks.test-d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-hooks.test-d.js","sourceRoot":"","sources":["../../../src/web/typed-hooks.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAuCpD,IAAI,CAAC,gDAAgD,EAAE,GAAG,EAAE;IAG1D,YAAY,EAAW,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IACxD,YAAY,EAAW,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;IAC3D,YAAY,EAAW,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;AAC5D,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,qDAAqD,E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,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAClC,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAkB,CAAC;IAC3D,CAAC;IAED,MAAM,WAAW,GAAG,WAAW,EAAsB,CAAC;IAEtD,IAAI,WAAW,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACrC,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAyB,CAAC;IACrE,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { createTypedHooks } from "./typed-hooks.js";
|
|
3
|
+
describe("createTypedHooks", () => {
|
|
4
|
+
it("should return an object with useCallTool hook", () => {
|
|
5
|
+
const hooks = createTypedHooks();
|
|
6
|
+
expect(hooks).toHaveProperty("useCallTool");
|
|
7
|
+
expect(typeof hooks.useCallTool).toBe("function");
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=typed-hooks.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-hooks.test.js","sourceRoot":"","sources":["../../../src/web/typed-hooks.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAYpD,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,KAAK,GAAG,gBAAgB,EAAc,CAAC;QAC7C,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/src/web/types.d.ts
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
export type UnknownObject = Record<string, unknown>;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
prompt: string;
|
|
6
|
-
}) => Promise<void>;
|
|
7
|
-
export type RequestDisplayMode = (args: {
|
|
8
|
-
mode: DisplayMode;
|
|
9
|
-
}) => Promise<{
|
|
10
|
-
mode: DisplayMode;
|
|
11
|
-
}>;
|
|
12
|
-
export type RequestModal = (options: RequestModalOptions) => Promise<void>;
|
|
13
|
-
export type RequestModalOptions = {
|
|
14
|
-
title: string;
|
|
2
|
+
type WidgetState = UnknownObject;
|
|
3
|
+
type FileMetadata = {
|
|
4
|
+
fileId: string;
|
|
15
5
|
};
|
|
16
6
|
export declare const TOOL_RESPONSE_EVENT_TYPE = "openai:tool_response";
|
|
17
7
|
export declare class ToolResponseEvent extends CustomEvent<{
|
|
@@ -43,8 +33,6 @@ export type OpenAiGlobals<ToolInput extends UnknownObject = {}, ToolOutput exten
|
|
|
43
33
|
} | null;
|
|
44
34
|
toolResponseMetadata: ToolResponseMetadata | null;
|
|
45
35
|
widgetState: WidgetState | null;
|
|
46
|
-
requestDisplayMode: RequestDisplayMode;
|
|
47
|
-
requestModal: RequestModal;
|
|
48
36
|
};
|
|
49
37
|
export type CallToolArgs = Record<string, unknown> | null;
|
|
50
38
|
export type CallToolResponse = {
|
|
@@ -65,7 +53,7 @@ type API<WidgetState extends UnknownObject> = {
|
|
|
65
53
|
prompt: string;
|
|
66
54
|
}) => Promise<void>;
|
|
67
55
|
/** Opens an external link, redirects web page or mobile app */
|
|
68
|
-
openExternal(
|
|
56
|
+
openExternal(args: {
|
|
69
57
|
href: string;
|
|
70
58
|
}): void;
|
|
71
59
|
/** For transitioning an app from inline to fullscreen or pip */
|
|
@@ -78,7 +66,27 @@ type API<WidgetState extends UnknownObject> = {
|
|
|
78
66
|
*/
|
|
79
67
|
mode: DisplayMode;
|
|
80
68
|
}>;
|
|
69
|
+
/**
|
|
70
|
+
* Sets the widget state.
|
|
71
|
+
* This state is persisted across widget renders.
|
|
72
|
+
*/
|
|
81
73
|
setWidgetState: (state: WidgetState) => Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Opens a modal portaled outside of the widget iFrame.
|
|
76
|
+
* This ensures the modal is correctly displayed and not limited to the widget's area.
|
|
77
|
+
*/
|
|
78
|
+
requestModal: (args: {
|
|
79
|
+
title: string;
|
|
80
|
+
}) => Promise<void>;
|
|
81
|
+
/** Uploads a new file to the host */
|
|
82
|
+
uploadFile: (file: File) => Promise<FileMetadata>;
|
|
83
|
+
/**
|
|
84
|
+
* Downloads a file from the host that was previously uploaded.
|
|
85
|
+
* Only files uploaded by the same connector instance can be downloaded.
|
|
86
|
+
*/
|
|
87
|
+
downloadFile: (file: FileMetadata) => Promise<{
|
|
88
|
+
downloadUrl: string;
|
|
89
|
+
}>;
|
|
82
90
|
};
|
|
83
91
|
export declare const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
|
|
84
92
|
export declare class SetGlobalsEvent extends CustomEvent<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/types.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAC/D,MAAM,OAAO,iBAAkB,SAAQ,WAErC;IACkB,IAAI,GAAG,wBAAwB,CAAC;CACnD;AA8FD,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAC3D,MAAM,OAAO,eAAgB,SAAQ,WAEnC;IACkB,IAAI,GAAG,sBAAsB,CAAC;CACjD"}
|
package/dist/vitest.config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest.config.js","sourceRoot":"","sources":["../vitest.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,eAAe,YAAY,CAAC;IAC1B,IAAI,EAAE;QACJ,WAAW,EAAE,OAAO;QACpB,OAAO,EAAE,IAAI;
|
|
1
|
+
{"version":3,"file":"vitest.config.js","sourceRoot":"","sources":["../vitest.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,eAAe,YAAY,CAAC;IAC1B,IAAI,EAAE;QACJ,WAAW,EAAE,OAAO;QACpB,OAAO,EAAE,IAAI;KACd;CACF,CAAC,CAAC"}
|
package/package.json
CHANGED
package/dist/src/test/setup.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/test/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,+CAA+C;AAC/C,MAAM,CAAC,OAAO,GAAG;IACf,GAAG,OAAO;IACV,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;IACd,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE;IACb,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE;CACb,CAAC"}
|
|
File without changes
|