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,29 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { renderHook } from "@testing-library/react";
|
|
3
|
+
import { useFiles } from "./use-files.js";
|
|
4
|
+
describe("useLocale", () => {
|
|
5
|
+
const OpenaiMock = {
|
|
6
|
+
uploadFile: vi.fn(),
|
|
7
|
+
downloadFile: vi.fn(),
|
|
8
|
+
};
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
vi.stubGlobal("openai", OpenaiMock);
|
|
11
|
+
});
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
vi.unstubAllGlobals();
|
|
14
|
+
vi.resetAllMocks();
|
|
15
|
+
});
|
|
16
|
+
const dummyFile = new File([], "test.txt");
|
|
17
|
+
it("should upload a file to ChatGPT", () => {
|
|
18
|
+
const { result } = renderHook(() => useFiles());
|
|
19
|
+
result.current.upload(dummyFile);
|
|
20
|
+
expect(OpenaiMock.uploadFile).toHaveBeenCalledWith(dummyFile);
|
|
21
|
+
});
|
|
22
|
+
it("should download a file from ChatGPT", () => {
|
|
23
|
+
const fileId = "123";
|
|
24
|
+
const { result } = renderHook(() => useFiles());
|
|
25
|
+
result.current.download({ fileId });
|
|
26
|
+
expect(OpenaiMock.downloadFile).toHaveBeenCalledWith({ fileId });
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=use-files.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-files.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-files.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,MAAM,UAAU,GAAG;QACjB,UAAU,EAAE,EAAE,CAAC,EAAE,EAAE;QACnB,YAAY,EAAE,EAAE,CAAC,EAAE,EAAE;KACtB,CAAC;IAEF,UAAU,CAAC,GAAG,EAAE;QACd,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;IAE3C,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEhD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACjC,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,MAAM,GAAG,KAAK,CAAC;QACrB,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEhD,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACpC,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { RequestModalOptions } from "../types.js";
|
|
2
1
|
/**
|
|
3
2
|
* Triggers a modal containing the widget rendered in display mode "modal"
|
|
4
3
|
*/
|
|
5
|
-
export declare function useRequestModal(): (options:
|
|
4
|
+
export declare function useRequestModal(): (options: {
|
|
5
|
+
title: string;
|
|
6
|
+
}) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-request-modal.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-request-modal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-request-modal.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-request-modal.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,CAAC,OAA0B,EAAE,EAAE;QACpC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type
|
|
3
|
-
status:
|
|
4
|
-
isPending:
|
|
5
|
-
isSuccess:
|
|
1
|
+
import type { UnknownObject } from "../types.js";
|
|
2
|
+
export type ToolPendingState<ToolInput extends UnknownObject> = {
|
|
3
|
+
status: "pending";
|
|
4
|
+
isPending: true;
|
|
5
|
+
isSuccess: false;
|
|
6
6
|
input: ToolInput;
|
|
7
|
-
output:
|
|
8
|
-
responseMetadata:
|
|
7
|
+
output: undefined;
|
|
8
|
+
responseMetadata: undefined;
|
|
9
9
|
};
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
export type ToolSuccessState<ToolInput extends UnknownObject, ToolOutput extends UnknownObject, ToolResponseMetadata extends UnknownObject> = {
|
|
11
|
+
status: "success";
|
|
12
|
+
isPending: false;
|
|
13
|
+
isSuccess: true;
|
|
14
|
+
input: ToolInput;
|
|
15
|
+
output: ToolOutput;
|
|
16
|
+
responseMetadata: ToolResponseMetadata;
|
|
17
|
+
};
|
|
18
|
+
type ToolState<ToolInput extends UnknownObject, ToolOutput extends UnknownObject, ToolResponseMetadata extends UnknownObject> = ToolPendingState<ToolInput> | ToolSuccessState<ToolInput, ToolOutput, ToolResponseMetadata>;
|
|
19
|
+
type ToolSignature = {
|
|
14
20
|
input: UnknownObject;
|
|
15
21
|
output: UnknownObject;
|
|
16
22
|
responseMetadata: UnknownObject;
|
|
17
|
-
}
|
|
23
|
+
};
|
|
24
|
+
export declare function useToolInfo<TS extends Partial<ToolSignature> = {}>(): ToolState<UnknownObject & TS["input"], UnknownObject & TS["output"], UnknownObject & TS["responseMetadata"]>;
|
|
18
25
|
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { useOpenAiGlobal } from "./use-openai-global.js";
|
|
1
2
|
import { useEffect, useState } from "react";
|
|
2
|
-
import { useOpenAiGlobal } from "skybridge/web";
|
|
3
3
|
export function useToolInfo() {
|
|
4
4
|
const [status, setStatus] = useState("pending");
|
|
5
|
+
const input = useOpenAiGlobal("toolInput");
|
|
5
6
|
const output = useOpenAiGlobal("toolOutput") ?? undefined;
|
|
6
7
|
const responseMetadata = useOpenAiGlobal("toolResponseMetadata") ?? undefined;
|
|
7
8
|
useEffect(() => {
|
|
@@ -10,7 +11,7 @@ export function useToolInfo() {
|
|
|
10
11
|
: "success");
|
|
11
12
|
}, [output, responseMetadata]);
|
|
12
13
|
return {
|
|
13
|
-
input
|
|
14
|
+
input,
|
|
14
15
|
status,
|
|
15
16
|
isPending: status === "pending",
|
|
16
17
|
isSuccess: status === "success",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tool-info.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-tool-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"use-tool-info.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-tool-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAuC5C,MAAM,UAAU,WAAW;IACzB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAwB,SAAS,CAAC,CAAC;IACvE,MAAM,KAAK,GAAG,eAAe,CAAC,WAAW,CAAE,CAAC;IAC5C,MAAM,MAAM,GAAG,eAAe,CAAC,YAAY,CAAC,IAAI,SAAS,CAAC;IAC1D,MAAM,gBAAgB,GAAG,eAAe,CAAC,sBAAsB,CAAC,IAAI,SAAS,CAAC;IAE9E,SAAS,CAAC,GAAG,EAAE;QACb,SAAS,CACP,MAAM,KAAK,SAAS,IAAI,gBAAgB,KAAK,SAAS;YACpD,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,SAAS,CACd,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAM/B,OAAO;QACL,KAAK;QACL,MAAM;QACN,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,MAAM;QACN,gBAAgB;KACqB,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { expectTypeOf, test } from "vitest";
|
|
2
|
+
import { renderHook } from "@testing-library/react";
|
|
3
|
+
import { useToolInfo } from "./use-tool-info.js";
|
|
4
|
+
test("useToolInfo - TypeScript typing", () => {
|
|
5
|
+
test("should have correct types when no generic parameter is provided", () => {
|
|
6
|
+
const result = useToolInfo();
|
|
7
|
+
expectTypeOf(result.status);
|
|
8
|
+
expectTypeOf(result.isPending);
|
|
9
|
+
expectTypeOf(result.isSuccess);
|
|
10
|
+
expectTypeOf(result.input);
|
|
11
|
+
});
|
|
12
|
+
test("should correctly type input, output, and responseMetadata with explicit ToolSignature", () => {
|
|
13
|
+
const result = useToolInfo();
|
|
14
|
+
expectTypeOf(result.input);
|
|
15
|
+
// When pending, output and responseMetadata should be undefined
|
|
16
|
+
if (result.status === "pending") {
|
|
17
|
+
expectTypeOf(result.output);
|
|
18
|
+
expectTypeOf(result.responseMetadata);
|
|
19
|
+
}
|
|
20
|
+
// When success, output and responseMetadata should be defined
|
|
21
|
+
if (result.status === "success") {
|
|
22
|
+
expectTypeOf(result.output);
|
|
23
|
+
expectTypeOf(result.responseMetadata);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
test("should correctly narrow types based on status discriminated union", () => {
|
|
27
|
+
const result = useToolInfo();
|
|
28
|
+
// Test type narrowing
|
|
29
|
+
if (result.isPending) {
|
|
30
|
+
expectTypeOf(result.status);
|
|
31
|
+
expectTypeOf(result.isPending);
|
|
32
|
+
expectTypeOf(result.isSuccess);
|
|
33
|
+
expectTypeOf(result.output);
|
|
34
|
+
expectTypeOf(result.responseMetadata);
|
|
35
|
+
}
|
|
36
|
+
if (result.isSuccess) {
|
|
37
|
+
expectTypeOf(result.status);
|
|
38
|
+
expectTypeOf(result.isPending);
|
|
39
|
+
expectTypeOf(result.isSuccess);
|
|
40
|
+
expectTypeOf(result.output);
|
|
41
|
+
expectTypeOf(result.responseMetadata);
|
|
42
|
+
}
|
|
43
|
+
if (result.status === "pending") {
|
|
44
|
+
expectTypeOf(result.input);
|
|
45
|
+
expectTypeOf(result.isPending);
|
|
46
|
+
expectTypeOf(result.isSuccess);
|
|
47
|
+
expectTypeOf(result.output);
|
|
48
|
+
expectTypeOf(result.responseMetadata);
|
|
49
|
+
}
|
|
50
|
+
if (result.status === "success") {
|
|
51
|
+
expectTypeOf(result.input);
|
|
52
|
+
expectTypeOf(result.isPending);
|
|
53
|
+
expectTypeOf(result.isSuccess);
|
|
54
|
+
expectTypeOf(result.output);
|
|
55
|
+
expectTypeOf(result.responseMetadata);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
test("should handle partial ToolSignature with only input specified", () => {
|
|
59
|
+
const result = useToolInfo();
|
|
60
|
+
expectTypeOf(result.input);
|
|
61
|
+
if (result.status === "success") {
|
|
62
|
+
expectTypeOf(result.output);
|
|
63
|
+
expectTypeOf(result.responseMetadata);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
test("should handle ToolSignature with only output specified", () => {
|
|
67
|
+
const result = useToolInfo();
|
|
68
|
+
expectTypeOf(result.input);
|
|
69
|
+
if (result.status === "success") {
|
|
70
|
+
expectTypeOf(result.output);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=use-tool-info.test-d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-tool-info.test-d.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-tool-info.test-d.ts"],"names":[],"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,CAAC;QAEL,YAAY,CAAY,MAAM,CAAC,KAAK,CAAC,CAAC;QAEtC,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAA0B,MAAM,CAAC,MAAM,CAAC,CAAC;YACrD,YAAY,CAA0B,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACjE,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,wDAAwD,EAAE,GAAG,EAAE;QAGlE,MAAM,MAAM,GAAG,WAAW,EAEtB,CAAC;QAEL,YAAY,CAA0B,MAAM,CAAC,KAAK,CAAC,CAAC;QAEpD,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAAa,MAAM,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fireEvent, renderHook, waitFor } from "@testing-library/react";
|
|
1
|
+
import { fireEvent, renderHook, waitFor, act } from "@testing-library/react";
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
3
|
import { useToolInfo } from "./use-tool-info.js";
|
|
4
4
|
import { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent, } from "../types.js";
|
|
@@ -18,40 +18,41 @@ describe("useToolInfo", () => {
|
|
|
18
18
|
});
|
|
19
19
|
it("should return toolInput on initial mount window.openai", () => {
|
|
20
20
|
const { result } = renderHook(() => useToolInfo());
|
|
21
|
-
expect(result.current
|
|
22
|
-
name: "pokemon",
|
|
23
|
-
|
|
21
|
+
expect(result.current).toMatchObject({
|
|
22
|
+
input: { name: "pokemon", args: { name: "pikachu" } },
|
|
23
|
+
status: "pending",
|
|
24
|
+
isPending: true,
|
|
25
|
+
isSuccess: false,
|
|
24
26
|
});
|
|
25
|
-
expect(result.current.status).toEqual("pending");
|
|
26
|
-
expect(result.current.isPending).toEqual(true);
|
|
27
|
-
expect(result.current.isSuccess).toEqual(false);
|
|
28
|
-
expect(result.current.output).toEqual(undefined);
|
|
29
|
-
expect(result.current.responseMetadata).toEqual(undefined);
|
|
30
27
|
});
|
|
31
|
-
it("should eventually return tool output and response metadata once tool call completes", () => {
|
|
28
|
+
it("should eventually return tool output and response metadata once tool call completes", async () => {
|
|
29
|
+
const toolOutput = {
|
|
30
|
+
name: "pikachu",
|
|
31
|
+
color: "yellow",
|
|
32
|
+
description: "When several of these POKéMON gather, their\felectricity could build and cause lightning storms.",
|
|
33
|
+
};
|
|
34
|
+
const toolResponseMetadata = { id: 12 };
|
|
32
35
|
const { result } = renderHook(() => useToolInfo());
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
act(() => {
|
|
37
|
+
OpenaiMock.toolOutput = toolOutput;
|
|
38
|
+
OpenaiMock.toolResponseMetadata = toolResponseMetadata;
|
|
39
|
+
fireEvent(window, new SetGlobalsEvent(SET_GLOBALS_EVENT_TYPE, {
|
|
40
|
+
detail: {
|
|
41
|
+
globals: {
|
|
42
|
+
toolOutput,
|
|
43
|
+
toolResponseMetadata,
|
|
40
44
|
},
|
|
41
|
-
toolResponseMetadata: { id: 12 },
|
|
42
45
|
},
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
waitFor(() => {
|
|
46
|
-
expect(result.current
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
description: "When several of these POKéMON gather, their\felectricity could build and cause lightning storms.",
|
|
46
|
+
}));
|
|
47
|
+
});
|
|
48
|
+
await waitFor(() => {
|
|
49
|
+
expect(result.current).toMatchObject({
|
|
50
|
+
status: "success",
|
|
51
|
+
isPending: false,
|
|
52
|
+
isSuccess: true,
|
|
53
|
+
output: toolOutput,
|
|
54
|
+
responseMetadata: toolResponseMetadata,
|
|
53
55
|
});
|
|
54
|
-
expect(result.current.responseMetadata).toEqual({ id: 12 });
|
|
55
56
|
});
|
|
56
57
|
});
|
|
57
58
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tool-info.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-tool-info.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-tool-info.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-tool-info.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EACL,sBAAsB,EACtB,eAAe,GAEhB,MAAM,aAAa,CAAC;AAErB,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,IAAI,UAGH,CAAC;IAEF,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,SAAS,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE;YACzD,UAAU,EAAE,IAAI;YAChB,oBAAoB,EAAE,IAAI;SAC3B,CAAC;QACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;QAChE,MAAM,EAAE,MAAM,EAA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AC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -44,7 +44,6 @@ describe("useWidgetState", () => {
|
|
|
44
44
|
count: 1,
|
|
45
45
|
name: "test",
|
|
46
46
|
});
|
|
47
|
-
console.log("widgetState", result.current[0]);
|
|
48
47
|
expect(result.current[0]).toEqual({ count: 1, name: "test" });
|
|
49
48
|
});
|
|
50
49
|
it("should update state when window.openai.widgetState changes", () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-widget-state.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-widget-state.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EACL,QAAQ,EACR,EAAE,EACF,MAAM,EACN,EAAE,EACF,UAAU,EACV,SAAS,GAEV,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAEzD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,IAAI,UAA0D,CAAC;IAE/D,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,WAAW,EAAE,IAAI;YACjB,cAAc,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC;SACrD,CAAC;QACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAChD,MAAM,WAAW,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAEjD,EAAE,CAAC,6EAA6E,E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CAAC,WAAW,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/src/web/index.d.ts
CHANGED
package/dist/src/web/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
1
2
|
import { createElement, StrictMode } from "react";
|
|
2
3
|
import { createRoot } from "react-dom/client";
|
|
4
|
+
import { installOpenAILoggingProxy } from "./proxy.js";
|
|
3
5
|
let rootInstance = null;
|
|
4
6
|
export const mountWidget = (component) => {
|
|
5
7
|
const rootElement = document.getElementById("root");
|
|
@@ -9,6 +11,9 @@ export const mountWidget = (component) => {
|
|
|
9
11
|
if (!rootInstance) {
|
|
10
12
|
rootInstance = createRoot(rootElement);
|
|
11
13
|
}
|
|
14
|
+
if (import.meta.env.DEV) {
|
|
15
|
+
installOpenAILoggingProxy();
|
|
16
|
+
}
|
|
12
17
|
rootInstance.render(createElement(StrictMode, null, component));
|
|
13
18
|
};
|
|
14
19
|
//# sourceMappingURL=mount-widget.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount-widget.js","sourceRoot":"","sources":["../../../src/web/mount-widget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,UAAU,EAAa,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"mount-widget.js","sourceRoot":"","sources":["../../../src/web/mount-widget.ts"],"names":[],"mappings":"AAAA,qCAAqC;AAErC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,UAAU,EAAa,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD,IAAI,YAAY,GAAgB,IAAI,CAAC;AAErC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,SAA0B,EAAE,EAAE;IACxD,MAAM,WAAW,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACpD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACxB,yBAAyB,EAAE,CAAC;IAC9B,CAAC;IAED,YAAY,CAAC,MAAM,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;AAClE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function installOpenAILoggingProxy(): void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const colors = {
|
|
2
|
+
brand: "#6366f1",
|
|
3
|
+
info: "#22223b",
|
|
4
|
+
success: "#22c55e",
|
|
5
|
+
error: "#ef4444",
|
|
6
|
+
};
|
|
7
|
+
export function installOpenAILoggingProxy() {
|
|
8
|
+
if (typeof window === "undefined" || !window.openai) {
|
|
9
|
+
console.warn("[openai-proxy] window.openai not found, skipping proxy installation");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const originalOpenAI = window.openai;
|
|
13
|
+
const handler = {
|
|
14
|
+
get(target, prop, receiver) {
|
|
15
|
+
const value = Reflect.get(target, prop, receiver);
|
|
16
|
+
if (typeof value !== "function") {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
return function (...args) {
|
|
20
|
+
const methodName = String(prop);
|
|
21
|
+
console.group(`%c[openai] %cmethod %c${methodName}`, `color: ${colors.brand}; font-weight: normal`, `color: ${colors.info}; font-weight: normal`, `color: ${colors.success}`);
|
|
22
|
+
console.log("%c← args:", `color: ${colors.info}`, args);
|
|
23
|
+
const result = value.apply(target, args);
|
|
24
|
+
if (result && typeof result.then === "function") {
|
|
25
|
+
return result.then((resolved) => {
|
|
26
|
+
console.log("%c→ resolved:", `color: ${colors.success}`, resolved);
|
|
27
|
+
console.groupEnd();
|
|
28
|
+
return resolved;
|
|
29
|
+
}, (error) => {
|
|
30
|
+
console.error("%c→ rejected:", `color: ${colors.error}`, error);
|
|
31
|
+
console.groupEnd();
|
|
32
|
+
throw error;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
console.log("%c→ returned:", `color: ${colors.success}`, result);
|
|
36
|
+
console.groupEnd();
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
set(target, prop, value, receiver) {
|
|
41
|
+
console.log(`%c[openai] %cupdate %c${String(prop)}`, `color: ${colors.brand}`, `color: ${colors.info}`, `color: ${colors.success}; font-weight: bold`, "←", value);
|
|
42
|
+
return Reflect.set(target, prop, value, receiver);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
window.openai = new Proxy(originalOpenAI, handler);
|
|
46
|
+
console.log("%c[openai-proxy] %cInstalled logging proxy for window.openai", `color: ${colors.brand}`, `color: ${colors.info}`);
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../src/web/proxy.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG;IACb,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,SAAS;CACR,CAAC;AAEX,MAAM,UAAU,yBAAyB;IACvC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACpD,OAAO,CAAC,IAAI,CACV,qEAAqE,CACtE,CAAC;QACF,OAAO;IACT,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;IAErC,MAAM,OAAO,GAAwC;QACnD,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;YACxB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAElD,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;gBAChC,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO,UAAU,GAAG,IAAe;gBACjC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;gBAEhC,OAAO,CAAC,KAAK,CACX,yBAAyB,UAAU,EAAE,EACrC,UAAU,MAAM,CAAC,KAAK,uBAAuB,EAC7C,UAAU,MAAM,CAAC,IAAI,uBAAuB,EAC5C,UAAU,MAAM,CAAC,OAAO,EAAE,CAC3B,CAAC;gBACF,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,UAAU,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;gBAExD,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAEzC,IAAI,MAAM,IAAI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,KAAK,EAAE,EACxB,UAAU,MAAM,CAAC,IAAI,EAAE,CACxB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { useCallTool } from "./hooks/use-call-tool.js";
|
|
2
|
+
import type { ToolPendingState, ToolSuccessState } from "./hooks/use-tool-info.js";
|
|
3
|
+
import type { McpServer, InferWidgets, AnyWidgetRegistry, WidgetInput, WidgetOutput } from "../server/index.js";
|
|
4
|
+
import type { CallToolArgs, UnknownObject } from "./types.js";
|
|
5
|
+
type TypedCallToolReturn<TInput, TOutput> = ReturnType<typeof useCallTool<TInput & CallToolArgs, {
|
|
6
|
+
structuredContent: TOutput & UnknownObject;
|
|
7
|
+
}>>;
|
|
8
|
+
type TypedToolInfoReturn<TInput extends UnknownObject, TOutput extends UnknownObject, TResponseMetadata extends UnknownObject> = ToolPendingState<TInput> | ToolSuccessState<TInput, TOutput, TResponseMetadata>;
|
|
9
|
+
/**
|
|
10
|
+
* Creates typed versions of skybridge hooks with full type inference
|
|
11
|
+
* for tool names, inputs, and outputs.
|
|
12
|
+
*
|
|
13
|
+
* This is the recommended way to use skybridge hooks in your widgets.
|
|
14
|
+
* Set this up once in a dedicated file and export the typed hooks for use across your app.
|
|
15
|
+
*
|
|
16
|
+
* @typeParam T - The type of your McpServer instance. Use `typeof server`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // server/src/index.ts
|
|
21
|
+
* const server = new McpServer({ name: "my-app", version: "1.0" }, {})
|
|
22
|
+
* .widget("search-voyage", {}, {
|
|
23
|
+
* inputSchema: { destination: z.string() },
|
|
24
|
+
* outputSchema: { results: z.array(z.string()) },
|
|
25
|
+
* }, async ({ destination }) => {
|
|
26
|
+
* return { content: [{ type: "text", text: `Found trips to ${destination}` }] };
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* export type AppType = typeof server;
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // web/src/skybridge.ts (one-time setup)
|
|
35
|
+
* import type { AppType } from "../server";
|
|
36
|
+
* import { createTypedHooks } from "skybridge/web";
|
|
37
|
+
*
|
|
38
|
+
* export const { useCallTool, useToolInfo } = createTypedHooks<AppType>();
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* // web/src/widgets/search.tsx (usage)
|
|
44
|
+
* import { useCallTool, useToolInfo } from "../skybridge";
|
|
45
|
+
*
|
|
46
|
+
* export function SearchWidget() {
|
|
47
|
+
* const { callTool, data } = useCallTool("search-voyage");
|
|
48
|
+
* // ^ autocomplete for tool names
|
|
49
|
+
* callTool({ destination: "Spain" });
|
|
50
|
+
* // ^ autocomplete for input fields
|
|
51
|
+
*
|
|
52
|
+
* const toolInfo = useToolInfo<"search-voyage">();
|
|
53
|
+
* // ^ autocomplete for widget names
|
|
54
|
+
* // toolInfo.input is typed based on widget input schema
|
|
55
|
+
* // toolInfo.output is typed based on widget output schema
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function createTypedHooks<T extends McpServer<AnyWidgetRegistry>>(): {
|
|
60
|
+
/**
|
|
61
|
+
* Typed version of `useCallTool` that provides autocomplete for tool names
|
|
62
|
+
* and type inference for inputs and outputs.
|
|
63
|
+
*
|
|
64
|
+
* @param name - The name of the widget to call. Autocompletes based on your server's widget registry.
|
|
65
|
+
* @returns A hook with typed `callTool` function and `data` property.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const { callTool, data, isPending } = useCallTool("search-voyage");
|
|
70
|
+
* // TypeScript knows callTool expects { destination: string }
|
|
71
|
+
* callTool({ destination: "Spain" });
|
|
72
|
+
*
|
|
73
|
+
* // data.structuredContent is typed based on your outputSchema
|
|
74
|
+
* if (data) {
|
|
75
|
+
* console.log(data.structuredContent.results);
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
useCallTool: <K extends keyof InferWidgets<T> & string>(name: K) => TypedCallToolReturn<InferWidgets<T>[K]["input"], InferWidgets<T>[K]["output"]>;
|
|
80
|
+
/**
|
|
81
|
+
* Typed version of `useToolInfo` that provides autocomplete for widget names
|
|
82
|
+
* and type inference for inputs, outputs, and responseMetadata.
|
|
83
|
+
*
|
|
84
|
+
* @typeParam K - The name of the widget. Autocompletes based on your server's widget registry.
|
|
85
|
+
* @returns A discriminated union with `status: "pending" | "success"` that narrows correctly.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const toolInfo = useToolInfo<"search-voyage">();
|
|
90
|
+
* // toolInfo.input is typed as { destination: string; ... }
|
|
91
|
+
* // toolInfo.output is typed as { results: Array<...>; ... } | undefined
|
|
92
|
+
* // toolInfo.status narrows correctly: "pending" | "success"
|
|
93
|
+
*
|
|
94
|
+
* if (toolInfo.isPending) {
|
|
95
|
+
* // TypeScript knows output is undefined here
|
|
96
|
+
* console.log(toolInfo.input.destination);
|
|
97
|
+
* }
|
|
98
|
+
*
|
|
99
|
+
* if (toolInfo.isSuccess) {
|
|
100
|
+
* // TypeScript knows output is defined here
|
|
101
|
+
* console.log(toolInfo.output.results);
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
useToolInfo: <K extends keyof InferWidgets<T> & string>() => TypedToolInfoReturn<WidgetInput<T, K> & UnknownObject, WidgetOutput<T, K> & UnknownObject, UnknownObject>;
|
|
106
|
+
};
|
|
107
|
+
export {};
|