skybridge 0.0.0-dev.e7d5814 → 0.0.0-dev.e9c6623
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/dist/src/web/hooks/index.d.ts +9 -3
- package/dist/src/web/hooks/index.js +9 -3
- package/dist/src/web/hooks/index.js.map +1 -1
- package/dist/src/web/hooks/use-display-mode.d.ts +4 -5
- package/dist/src/web/hooks/use-display-mode.js +1 -1
- package/dist/src/web/hooks/use-display-mode.js.map +1 -1
- package/dist/src/web/hooks/use-display-mode.test.d.ts +1 -0
- package/dist/src/web/hooks/use-display-mode.test.js +40 -0
- package/dist/src/web/hooks/use-display-mode.test.js.map +1 -0
- package/dist/src/web/hooks/use-locale.d.ts +1 -0
- package/dist/src/web/hooks/use-locale.js +5 -0
- package/dist/src/web/hooks/use-locale.js.map +1 -0
- package/dist/src/web/hooks/use-locale.test.d.ts +1 -0
- package/dist/src/web/hooks/use-locale.test.js +21 -0
- package/dist/src/web/hooks/use-locale.test.js.map +1 -0
- package/dist/src/web/hooks/use-open-external.d.ts +1 -0
- package/dist/src/web/hooks/use-open-external.js +6 -0
- package/dist/src/web/hooks/use-open-external.js.map +1 -0
- package/dist/src/web/hooks/use-open-external.test.d.ts +1 -0
- package/dist/src/web/hooks/use-open-external.test.js +24 -0
- package/dist/src/web/hooks/use-open-external.test.js.map +1 -0
- package/dist/src/web/hooks/use-openai-global.js +3 -1
- package/dist/src/web/hooks/use-openai-global.js.map +1 -1
- package/dist/src/web/hooks/use-request-modal.d.ts +5 -0
- package/dist/src/web/hooks/use-request-modal.js +9 -0
- package/dist/src/web/hooks/use-request-modal.js.map +1 -0
- package/dist/src/web/hooks/use-request-modal.test.d.ts +1 -0
- package/dist/src/web/hooks/use-request-modal.test.js +24 -0
- package/dist/src/web/hooks/use-request-modal.test.js.map +1 -0
- package/dist/src/web/hooks/use-send-follow-up-message.d.ts +1 -0
- package/dist/src/web/hooks/use-send-follow-up-message.js +11 -0
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +1 -0
- package/dist/src/web/hooks/use-theme.d.ts +1 -0
- package/dist/src/web/hooks/use-theme.js +5 -0
- package/dist/src/web/hooks/use-theme.js.map +1 -0
- package/dist/src/web/hooks/use-theme.test.d.ts +1 -0
- package/dist/src/web/hooks/use-theme.test.js +26 -0
- package/dist/src/web/hooks/use-theme.test.js.map +1 -0
- package/dist/src/web/hooks/use-tool-info.d.ts +14 -0
- package/dist/src/web/hooks/use-tool-info.js +21 -0
- package/dist/src/web/hooks/use-tool-info.js.map +1 -0
- package/dist/src/web/hooks/use-tool-info.test.d.ts +1 -0
- package/dist/src/web/hooks/use-tool-info.test.js +58 -0
- package/dist/src/web/hooks/use-tool-info.test.js.map +1 -0
- package/dist/src/web/hooks/use-tool-output.d.ts +2 -4
- package/dist/src/web/hooks/use-tool-output.js +3 -3
- package/dist/src/web/hooks/use-tool-output.js.map +1 -1
- package/dist/src/web/hooks/use-tool-response-metadata.d.ts +4 -3
- package/dist/src/web/hooks/use-tool-response-metadata.js +3 -0
- package/dist/src/web/hooks/use-tool-response-metadata.js.map +1 -1
- package/dist/src/web/hooks/use-user-agent.d.ts +1 -0
- package/dist/src/web/hooks/use-user-agent.js +5 -0
- package/dist/src/web/hooks/use-user-agent.js.map +1 -0
- package/dist/src/web/hooks/use-user-agent.test.d.ts +1 -0
- package/dist/src/web/hooks/use-user-agent.test.js +31 -0
- package/dist/src/web/hooks/use-user-agent.test.js.map +1 -0
- package/dist/src/web/hooks/use-widget-state.d.ts +1 -2
- package/dist/src/web/hooks/use-widget-state.js +3 -3
- package/dist/src/web/hooks/use-widget-state.js.map +1 -1
- package/dist/src/web/hooks/use-widget-state.test.d.ts +1 -0
- package/dist/src/web/hooks/use-widget-state.test.js +61 -0
- package/dist/src/web/hooks/use-widget-state.test.js.map +1 -0
- package/dist/src/web/types.d.ts +10 -3
- package/dist/src/web/types.js.map +1 -1
- package/package.json +4 -2
- package/dist/src/web/hooks/use-tool.d.ts +0 -8
- package/dist/src/web/hooks/use-tool.js +0 -5
- package/dist/src/web/hooks/use-tool.js.map +0 -1
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
export { useCallTool } from "./use-call-tool.js";
|
|
2
|
+
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
|
+
export { useLocale } from "./use-locale.js";
|
|
4
|
+
export { useOpenExternal } from "./use-open-external.js";
|
|
1
5
|
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
6
|
+
export { useRequestModal } from "./use-request-modal.js";
|
|
7
|
+
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
8
|
+
export { useTheme } from "./use-theme.js";
|
|
9
|
+
export { useToolInfo } from "./use-tool-info.js";
|
|
2
10
|
export { useToolOutput } from "./use-tool-output.js";
|
|
3
11
|
export { useToolResponseMetadata } from "./use-tool-response-metadata.js";
|
|
4
|
-
export {
|
|
12
|
+
export { useUserAgent } from "./use-user-agent.js";
|
|
5
13
|
export { useWidgetState } from "./use-widget-state.js";
|
|
6
|
-
export { useTool } from "./use-tool.js";
|
|
7
|
-
export { useDisplayMode } from "./use-display-mode.js";
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
export { useCallTool } from "./use-call-tool.js";
|
|
2
|
+
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
|
+
export { useLocale } from "./use-locale.js";
|
|
4
|
+
export { useOpenExternal } from "./use-open-external.js";
|
|
1
5
|
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
6
|
+
export { useRequestModal } from "./use-request-modal.js";
|
|
7
|
+
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
8
|
+
export { useTheme } from "./use-theme.js";
|
|
9
|
+
export { useToolInfo } from "./use-tool-info.js";
|
|
2
10
|
export { useToolOutput } from "./use-tool-output.js";
|
|
3
11
|
export { useToolResponseMetadata } from "./use-tool-response-metadata.js";
|
|
4
|
-
export {
|
|
12
|
+
export { useUserAgent } from "./use-user-agent.js";
|
|
5
13
|
export { useWidgetState } from "./use-widget-state.js";
|
|
6
|
-
export { useTool } from "./use-tool.js";
|
|
7
|
-
export { useDisplayMode } from "./use-display-mode.js";
|
|
8
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}>) & import("../types.js").RequestDisplayMode];
|
|
1
|
+
import type { DisplayMode } from "../types.js";
|
|
2
|
+
export declare function useDisplayMode(): readonly [DisplayMode, (mode: DisplayMode) => Promise<{
|
|
3
|
+
mode: DisplayMode;
|
|
4
|
+
}>];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useOpenAiGlobal } from "./use-openai-global.js";
|
|
2
2
|
export function useDisplayMode() {
|
|
3
3
|
const displayMode = useOpenAiGlobal("displayMode");
|
|
4
|
-
const setDisplayMode = window.openai.requestDisplayMode;
|
|
4
|
+
const setDisplayMode = (mode) => window.openai.requestDisplayMode({ mode });
|
|
5
5
|
return [displayMode, setDisplayMode];
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=use-display-mode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-display-mode.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-display-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-display-mode.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-display-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGzD,MAAM,UAAU,cAAc;IAC5B,MAAM,WAAW,GAAG,eAAe,CAAC,aAAa,CAAE,CAAC;IACpD,MAAM,cAAc,GAAG,CAAC,IAAiB,EAAE,EAAE,CAC3C,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IAE7C,OAAO,CAAC,WAAW,EAAE,cAAc,CAAU,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useDisplayMode } from "./use-display-mode.js";
|
|
2
|
+
import { describe, it, expect, vi, beforeEach, afterEach, } from "vitest";
|
|
3
|
+
import { renderHook, act } from "@testing-library/react";
|
|
4
|
+
describe("useDisplayMode", () => {
|
|
5
|
+
let OpenaiMock;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
OpenaiMock = {
|
|
8
|
+
displayMode: "inline",
|
|
9
|
+
requestDisplayMode: vi.fn().mockResolvedValue({ mode: "inline" }),
|
|
10
|
+
};
|
|
11
|
+
vi.stubGlobal("openai", OpenaiMock);
|
|
12
|
+
});
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
vi.unstubAllGlobals();
|
|
15
|
+
vi.resetAllMocks();
|
|
16
|
+
});
|
|
17
|
+
it("should return the current display mode from window.openai.displayMode", () => {
|
|
18
|
+
OpenaiMock.displayMode = "inline";
|
|
19
|
+
const { result } = renderHook(() => useDisplayMode());
|
|
20
|
+
expect(result.current[0]).toBe("inline");
|
|
21
|
+
});
|
|
22
|
+
it("should return different display modes when window.openai.displayMode changes", () => {
|
|
23
|
+
OpenaiMock.displayMode = "inline";
|
|
24
|
+
const { result, rerender } = renderHook(() => useDisplayMode());
|
|
25
|
+
expect(result.current[0]).toBe("inline");
|
|
26
|
+
OpenaiMock.displayMode = "fullscreen";
|
|
27
|
+
rerender();
|
|
28
|
+
expect(result.current[0]).toBe("fullscreen");
|
|
29
|
+
});
|
|
30
|
+
it("should call window.openai.requestDisplayMode with correct mode when setDisplayMode is called", async () => {
|
|
31
|
+
const { result } = renderHook(() => useDisplayMode());
|
|
32
|
+
await act(async () => {
|
|
33
|
+
await result.current[1]("fullscreen");
|
|
34
|
+
});
|
|
35
|
+
expect(OpenaiMock.requestDisplayMode).toHaveBeenCalledWith({
|
|
36
|
+
mode: "fullscreen",
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=use-display-mode.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-display-mode.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-display-mode.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EACL,QAAQ,EACR,EAAE,EACF,MAAM,EACN,EAAE,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E,CAAC;QAEX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8FAA8F,EAAE,KAAK,IAAI,EAAE;QAC5G,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;QAEtD,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACnB,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,oBAAoB,CAAC;YACzD,IAAI,EAAE,YAAY;SACnB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useLocale(): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-locale.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-locale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,UAAU,SAAS;IACvB,OAAO,eAAe,CAAC,QAAQ,CAAE,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useLocale } from "./use-locale.js";
|
|
2
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
3
|
+
import { renderHook } from "@testing-library/react";
|
|
4
|
+
describe("useLocale", () => {
|
|
5
|
+
let OpenaiMock;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
OpenaiMock = {
|
|
8
|
+
locale: "en-US",
|
|
9
|
+
};
|
|
10
|
+
vi.stubGlobal("openai", OpenaiMock);
|
|
11
|
+
});
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
vi.unstubAllGlobals();
|
|
14
|
+
vi.resetAllMocks();
|
|
15
|
+
});
|
|
16
|
+
it("should return the current locale from window.openai.locale", () => {
|
|
17
|
+
const { result } = renderHook(() => useLocale());
|
|
18
|
+
expect(result.current).toBe("en-US");
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=use-locale.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-locale.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-locale.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,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;AAEpD,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAI,UAEH,CAAC;IAEF,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,MAAM,EAAE,OAAO;SAChB,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,4DAA4D,EAAE,GAAG,EAAE;QACpE,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC;QAEjD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useOpenExternal(): (href: string) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-open-external.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-open-external.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,eAAe;IAC7B,OAAO,CAAC,IAAY,EAAE,EAAE;QACtB,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useOpenExternal } from "./use-open-external.js";
|
|
2
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
3
|
+
import { renderHook } from "@testing-library/react";
|
|
4
|
+
describe("useOpenExternal", () => {
|
|
5
|
+
let openExternalMock;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
openExternalMock = vi.fn();
|
|
8
|
+
vi.stubGlobal("openai", {
|
|
9
|
+
openExternal: openExternalMock,
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
vi.unstubAllGlobals();
|
|
14
|
+
vi.resetAllMocks();
|
|
15
|
+
});
|
|
16
|
+
it("should return a function that calls window.openai.openExternal with the href", () => {
|
|
17
|
+
const { result } = renderHook(() => useOpenExternal());
|
|
18
|
+
const href = "https://example.com";
|
|
19
|
+
result.current(href);
|
|
20
|
+
expect(openExternalMock).toHaveBeenCalledTimes(1);
|
|
21
|
+
expect(openExternalMock).toHaveBeenCalledWith({ href });
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
//# sourceMappingURL=use-open-external.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-open-external.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-open-external.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,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;AAEpD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,gBAA0C,CAAC;IAE/C,UAAU,CAAC,GAAG,EAAE;QACd,gBAAgB,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;YACtB,YAAY,EAAE,gBAAgB;SAC/B,CAAC,CAAC;IACL,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,8EAA8E,EAAE,GAAG,EAAE;QACtF,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC;QAEvD,MAAM,IAAI,GAAG,qBAAqB,CAAC;QACnC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAErB,MAAM,CAAC,gBAAgB,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,CAAC,gBAAgB,CAAC,CAAC,oBAAoB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { useSyncExternalStore } from "react";
|
|
2
2
|
import { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent, } from "../types.js";
|
|
3
3
|
export function useOpenAiGlobal(key) {
|
|
4
|
+
if (!window.openai) {
|
|
5
|
+
console.warn("openai is not defined on window. Please make sure to only call this hook inside the OpenAI iFrame skybridge runtime.");
|
|
6
|
+
}
|
|
4
7
|
return useSyncExternalStore((onChange) => {
|
|
5
8
|
const handleSetGlobal = (event) => {
|
|
6
9
|
const value = event.detail.globals[key];
|
|
7
10
|
if (value === undefined) {
|
|
8
11
|
return;
|
|
9
12
|
}
|
|
10
|
-
console.dir(event.detail.globals, { depth: Infinity });
|
|
11
13
|
onChange();
|
|
12
14
|
};
|
|
13
15
|
window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-openai-global.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-openai-global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EACL,sBAAsB,EACtB,eAAe,GAEhB,MAAM,aAAa,CAAC;AAErB,MAAM,UAAU,eAAe,CAC7B,GAAM;IAEN,OAAO,oBAAoB,CACzB,CAAC,QAAQ,EAAE,EAAE;QACX,MAAM,eAAe,GAAG,CAAC,KAAsB,EAAE,EAAE;YACjD,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACxC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO;YACT,CAAC;YAED,
|
|
1
|
+
{"version":3,"file":"use-openai-global.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-openai-global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EACL,sBAAsB,EACtB,eAAe,GAEhB,MAAM,aAAa,CAAC;AAErB,MAAM,UAAU,eAAe,CAC7B,GAAM;IAEN,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO,CAAC,IAAI,CACV,sHAAsH,CACvH,CAAC;IACJ,CAAC;IAED,OAAO,oBAAoB,CACzB,CAAC,QAAQ,EAAE,EAAE;QACX,MAAM,eAAe,GAAG,CAAC,KAAsB,EAAE,EAAE;YACjD,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACxC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO;YACT,CAAC;YAED,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,sBAAsB,EAAE,eAAe,EAAE;YAC/D,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,eAAe,CAAC,CAAC;QACtE,CAAC,CAAC;IACJ,CAAC,EACD,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAC3B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-request-modal.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-request-modal.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,CAAC,OAA4B,EAAE,EAAE;QACtC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useRequestModal } from "./use-request-modal.js";
|
|
2
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
3
|
+
import { renderHook } from "@testing-library/react";
|
|
4
|
+
describe("useRequestModal", () => {
|
|
5
|
+
let requestModalMock;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
requestModalMock = vi.fn();
|
|
8
|
+
vi.stubGlobal("openai", {
|
|
9
|
+
requestModal: requestModalMock,
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
vi.unstubAllGlobals();
|
|
14
|
+
vi.resetAllMocks();
|
|
15
|
+
});
|
|
16
|
+
it("should return a function that calls window.openai.requestModal with the options", () => {
|
|
17
|
+
const { result } = renderHook(() => useRequestModal());
|
|
18
|
+
const options = { title: "Test Modal" };
|
|
19
|
+
result.current(options);
|
|
20
|
+
expect(requestModalMock).toHaveBeenCalledTimes(1);
|
|
21
|
+
expect(requestModalMock).toHaveBeenCalledWith(options);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
//# sourceMappingURL=use-request-modal.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-request-modal.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-request-modal.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,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;AAEpD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,gBAA0C,CAAC;IAE/C,UAAU,CAAC,GAAG,EAAE;QACd,gBAAgB,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;YACtB,YAAY,EAAE,gBAAgB;SAC/B,CAAC,CAAC;IACL,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,iFAAiF,EAAE,GAAG,EAAE;QACzF,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC;QAEvD,MAAM,OAAO,GAAG,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;QACxC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAExB,MAAM,CAAC,gBAAgB,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,CAAC,gBAAgB,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useSendFollowUpMessage(): (prompt: string) => Promise<void>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
export function useSendFollowUpMessage() {
|
|
3
|
+
const sendFollowUpMessage = useCallback(async (prompt) => {
|
|
4
|
+
if (!window.openai?.sendFollowUpMessage) {
|
|
5
|
+
throw new Error("window.openai.sendFollowUpMessage is not available");
|
|
6
|
+
}
|
|
7
|
+
return window.openai.sendFollowUpMessage({ prompt });
|
|
8
|
+
}, []);
|
|
9
|
+
return sendFollowUpMessage;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=use-send-follow-up-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-send-follow-up-message.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-send-follow-up-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEpC,MAAM,UAAU,sBAAsB;IACpC,MAAM,mBAAmB,GAAG,WAAW,CACrC,KAAK,EAAE,MAAc,EAAiB,EAAE;QACtC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,mBAAmB,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE,CAAC;QACD,OAAO,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACvD,CAAC,EACD,EAAE,CACH,CAAC;IAEF,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useTheme(): import("../types.js").Theme;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-theme.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-theme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,UAAU,QAAQ;IACtB,OAAO,eAAe,CAAC,OAAO,CAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useTheme } from "./use-theme.js";
|
|
2
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
3
|
+
import { renderHook } from "@testing-library/react";
|
|
4
|
+
describe("useTheme", () => {
|
|
5
|
+
let OpenaiMock;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
OpenaiMock = {
|
|
8
|
+
theme: "light",
|
|
9
|
+
};
|
|
10
|
+
vi.stubGlobal("openai", OpenaiMock);
|
|
11
|
+
});
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
vi.unstubAllGlobals();
|
|
14
|
+
vi.resetAllMocks();
|
|
15
|
+
});
|
|
16
|
+
it("should return the current theme from window.openai.theme", () => {
|
|
17
|
+
const { result } = renderHook(() => useTheme());
|
|
18
|
+
expect(result.current).toBe("light");
|
|
19
|
+
});
|
|
20
|
+
it("should return dark theme when set to dark", () => {
|
|
21
|
+
OpenaiMock.theme = "dark";
|
|
22
|
+
const { result } = renderHook(() => useTheme());
|
|
23
|
+
expect(result.current).toBe("dark");
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=use-theme.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-theme.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-theme.test.ts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ending" | "success", ToolInput extends UnknownObject, ToolOutput extends UnknownObject = UnknownObject, ToolResponseMetadata extends UnknownObject = UnknownObject> = {
|
|
3
|
+
status: TStatus;
|
|
4
|
+
isPending: TStatus extends "pending" ? true : false;
|
|
5
|
+
isSuccess: TStatus extends "success" ? true : false;
|
|
6
|
+
input: ToolInput;
|
|
7
|
+
output: TStatus extends "success" ? ToolOutput : undefined;
|
|
8
|
+
responseMetadata: TStatus extends "success" ? ToolResponseMetadata : undefined;
|
|
9
|
+
};
|
|
10
|
+
type PendingToolState<ToolInput extends UnknownObject> = BaseToolState<"pending", ToolInput>;
|
|
11
|
+
type SuccessToolState<ToolInput extends UnknownObject, ToolOutput extends UnknownObject, ToolResponseMetadata extends UnknownObject> = BaseToolState<"success", ToolInput, ToolOutput, ToolResponseMetadata>;
|
|
12
|
+
type ToolState<ToolInput extends UnknownObject, ToolOutput extends UnknownObject, ToolResponseMetadata extends UnknownObject> = PendingToolState<ToolInput> | SuccessToolState<ToolInput, ToolOutput, ToolResponseMetadata>;
|
|
13
|
+
export declare function useToolInfo<ToolInput extends UnknownObject = UnknownObject, ToolOutput extends UnknownObject = UnknownObject, ToolResponseMetadata extends UnknownObject = UnknownObject>(): ToolState<ToolInput, ToolOutput, ToolResponseMetadata>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { useOpenAiGlobal } from "skybridge/web";
|
|
3
|
+
export function useToolInfo() {
|
|
4
|
+
const [status, setStatus] = useState("pending");
|
|
5
|
+
const output = useOpenAiGlobal("toolOutput") ?? undefined;
|
|
6
|
+
const responseMetadata = useOpenAiGlobal("toolResponseMetadata") ?? undefined;
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
setStatus(output === undefined && responseMetadata === undefined
|
|
9
|
+
? "pending"
|
|
10
|
+
: "success");
|
|
11
|
+
}, [output, responseMetadata]);
|
|
12
|
+
return {
|
|
13
|
+
input: useOpenAiGlobal("toolInput"),
|
|
14
|
+
status,
|
|
15
|
+
isPending: status === "pending",
|
|
16
|
+
isSuccess: status === "success",
|
|
17
|
+
output,
|
|
18
|
+
responseMetadata,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=use-tool-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-tool-info.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-tool-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAsB,MAAM,eAAe,CAAC;AAoCpE,MAAM,UAAU,WAAW;IAKzB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAwB,SAAS,CAAC,CAAC;IACvE,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;IAE/B,OAAO;QACL,KAAK,EAAE,eAAe,CAAC,WAAW,CAAE;QACpC,MAAM;QACN,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,MAAM;QACN,gBAAgB;KACyC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { fireEvent, renderHook, waitFor } from "@testing-library/react";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { useToolInfo } from "./use-tool-info.js";
|
|
4
|
+
import { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent, } from "../types.js";
|
|
5
|
+
describe("useToolInfo", () => {
|
|
6
|
+
let OpenaiMock;
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
OpenaiMock = {
|
|
9
|
+
toolInput: { name: "pokemon", args: { name: "pikachu" } },
|
|
10
|
+
toolOutput: null,
|
|
11
|
+
toolResponseMetadata: null,
|
|
12
|
+
};
|
|
13
|
+
vi.stubGlobal("openai", OpenaiMock);
|
|
14
|
+
});
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
vi.unstubAllGlobals();
|
|
17
|
+
vi.resetAllMocks();
|
|
18
|
+
});
|
|
19
|
+
it("should return toolInput on initial mount window.openai", () => {
|
|
20
|
+
const { result } = renderHook(() => useToolInfo());
|
|
21
|
+
expect(result.current.input).toEqual({
|
|
22
|
+
name: "pokemon",
|
|
23
|
+
args: { name: "pikachu" },
|
|
24
|
+
});
|
|
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
|
+
});
|
|
31
|
+
it("should eventually return tool output and response metadata once tool call completes", () => {
|
|
32
|
+
const { result } = renderHook(() => useToolInfo());
|
|
33
|
+
fireEvent(window, new SetGlobalsEvent(SET_GLOBALS_EVENT_TYPE, {
|
|
34
|
+
detail: {
|
|
35
|
+
globals: {
|
|
36
|
+
toolOutput: {
|
|
37
|
+
name: "pikachu",
|
|
38
|
+
color: "yellow",
|
|
39
|
+
description: "When several of these POKéMON gather, their\felectricity could build and cause lightning storms.",
|
|
40
|
+
},
|
|
41
|
+
toolResponseMetadata: { id: 12 },
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
}));
|
|
45
|
+
waitFor(() => {
|
|
46
|
+
expect(result.current.status).toEqual("success");
|
|
47
|
+
expect(result.current.isPending).toEqual(false);
|
|
48
|
+
expect(result.current.isSuccess).toEqual(true);
|
|
49
|
+
expect(result.current.output).toEqual({
|
|
50
|
+
name: "pikachu",
|
|
51
|
+
color: "yellow",
|
|
52
|
+
description: "When several of these POKéMON gather, their\felectricity could build and cause lightning storms.",
|
|
53
|
+
});
|
|
54
|
+
expect(result.current.responseMetadata).toEqual({ id: 12 });
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=use-tool-info.test.js.map
|
|
@@ -0,0 +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;AACxE,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,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CAAC;QAEF,OAAO,CAAC,GAAG,EAAE;YACX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACjD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAChD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC/C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;gBACpC,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,QAAQ;gBACf,WAAW,EACT,kGAAkG;aACrG,CAAC,CAAC;YACH,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @deprecated This hook is deprecated. Use `
|
|
2
|
+
* @deprecated This hook is deprecated. Use `useToolInfo()` instead and access the `output` property.
|
|
3
3
|
*/
|
|
4
|
-
export declare function useToolOutput():
|
|
5
|
-
[x: string]: unknown;
|
|
6
|
-
} | null | undefined;
|
|
4
|
+
export declare function useToolOutput(): import("../types.js").UnknownObject | undefined;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useToolInfo } from "./use-tool-info.js";
|
|
2
2
|
/**
|
|
3
|
-
* @deprecated This hook is deprecated. Use `
|
|
3
|
+
* @deprecated This hook is deprecated. Use `useToolInfo()` instead and access the `output` property.
|
|
4
4
|
*/
|
|
5
5
|
export function useToolOutput() {
|
|
6
|
-
const { output } =
|
|
6
|
+
const { output } = useToolInfo();
|
|
7
7
|
return output;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=use-tool-output.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tool-output.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-tool-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"use-tool-output.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-tool-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;IAEjC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated This hook is deprecated. Use `useToolInfo()` instead and access the `responseMetadata` property.
|
|
3
|
+
*/
|
|
4
|
+
export declare function useToolResponseMetadata(): import("../types.js").UnknownObject | null | undefined;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { useOpenAiGlobal } from "./use-openai-global.js";
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated This hook is deprecated. Use `useToolInfo()` instead and access the `responseMetadata` property.
|
|
4
|
+
*/
|
|
2
5
|
export function useToolResponseMetadata() {
|
|
3
6
|
return useOpenAiGlobal("toolResponseMetadata");
|
|
4
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tool-response-metadata.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-tool-response-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,UAAU,uBAAuB;IACrC,OAAO,eAAe,CAAC,sBAAsB,CAAC,CAAC;AACjD,CAAC"}
|
|
1
|
+
{"version":3,"file":"use-tool-response-metadata.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-tool-response-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;GAEG;AACH,MAAM,UAAU,uBAAuB;IACrC,OAAO,eAAe,CAAC,sBAAsB,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useUserAgent(): import("../types.js").UserAgent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-user-agent.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-user-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,UAAU,YAAY;IAC1B,OAAO,eAAe,CAAC,WAAW,CAAE,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useUserAgent } from "./use-user-agent.js";
|
|
2
|
+
import { describe, it, expect, vi, beforeEach, afterEach, } from "vitest";
|
|
3
|
+
import { renderHook } from "@testing-library/react";
|
|
4
|
+
describe("useUserAgent", () => {
|
|
5
|
+
let OpenaiMock;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
OpenaiMock = {
|
|
8
|
+
userAgent: {
|
|
9
|
+
device: { type: "mobile" },
|
|
10
|
+
capabilities: { hover: false, touch: true },
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
vi.stubGlobal("openai", OpenaiMock);
|
|
14
|
+
});
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
vi.unstubAllGlobals();
|
|
17
|
+
vi.resetAllMocks();
|
|
18
|
+
});
|
|
19
|
+
it("should return the current user agent from window.openai.userAgent", () => {
|
|
20
|
+
OpenaiMock.userAgent = {
|
|
21
|
+
device: { type: "mobile" },
|
|
22
|
+
capabilities: { hover: false, touch: true },
|
|
23
|
+
};
|
|
24
|
+
const { result } = renderHook(() => useUserAgent());
|
|
25
|
+
expect(result.current).toEqual({
|
|
26
|
+
device: { type: "mobile" },
|
|
27
|
+
capabilities: { hover: false, touch: true },
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=use-user-agent.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-user-agent.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-user-agent.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EACL,QAAQ,EACR,EAAE,EACF,MAAM,EACN,EAAE,EACF,UAAU,EACV,SAAS,GAEV,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,UAEH,CAAC;IAEF,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,SAAS,EAAE;gBACT,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBAC1B,YAAY,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE;aAC5C;SACF,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,mEAAmE,EAAE,GAAG,EAAE;QAC3E,UAAU,CAAC,SAAS,GAAG;YACrB,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC1B,YAAY,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE;SAC5C,CAAC;QACF,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC;QAEpD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;YAC7B,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC1B,YAAY,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type SetStateAction } from "react";
|
|
2
|
-
type UnknownObject
|
|
2
|
+
import type { UnknownObject } from "../types.js";
|
|
3
3
|
export declare function useWidgetState<T extends UnknownObject>(defaultState: T | (() => T)): readonly [T, (state: SetStateAction<T>) => void];
|
|
4
4
|
export declare function useWidgetState<T extends UnknownObject>(defaultState?: T | (() => T | null) | null): readonly [T | null, (state: SetStateAction<T | null>) => void];
|
|
5
|
-
export {};
|
|
@@ -3,7 +3,7 @@ import { useOpenAiGlobal } from "./use-openai-global.js";
|
|
|
3
3
|
export function useWidgetState(defaultState) {
|
|
4
4
|
const widgetStateFromWindow = useOpenAiGlobal("widgetState");
|
|
5
5
|
const [widgetState, _setWidgetState] = useState(() => {
|
|
6
|
-
if (widgetStateFromWindow
|
|
6
|
+
if (widgetStateFromWindow !== null) {
|
|
7
7
|
return widgetStateFromWindow;
|
|
8
8
|
}
|
|
9
9
|
return typeof defaultState === "function"
|
|
@@ -12,14 +12,14 @@ export function useWidgetState(defaultState) {
|
|
|
12
12
|
});
|
|
13
13
|
useEffect(() => {
|
|
14
14
|
// Fixes openai implementation bug
|
|
15
|
-
if (widgetStateFromWindow
|
|
15
|
+
if (widgetStateFromWindow !== null) {
|
|
16
16
|
_setWidgetState(widgetStateFromWindow);
|
|
17
17
|
}
|
|
18
18
|
}, [widgetStateFromWindow]);
|
|
19
19
|
const setWidgetState = useCallback((state) => {
|
|
20
20
|
_setWidgetState((prevState) => {
|
|
21
21
|
const newState = typeof state === "function" ? state(prevState) : state;
|
|
22
|
-
if (newState
|
|
22
|
+
if (newState !== null) {
|
|
23
23
|
window.openai.setWidgetState(newState);
|
|
24
24
|
}
|
|
25
25
|
return newState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-widget-state.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-widget-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAuB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"use-widget-state.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-widget-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAuB,MAAM,OAAO,CAAC;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAQzD,MAAM,UAAU,cAAc,CAC5B,YAA0C;IAE1C,MAAM,qBAAqB,GAAG,eAAe,CAAC,aAAa,CAAM,CAAC;IAElE,MAAM,CAAC,WAAW,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAW,GAAG,EAAE;QAC7D,IAAI,qBAAqB,KAAK,IAAI,EAAE,CAAC;YACnC,OAAO,qBAAqB,CAAC;QAC/B,CAAC;QAED,OAAO,OAAO,YAAY,KAAK,UAAU;YACvC,CAAC,CAAC,YAAY,EAAE;YAChB,CAAC,CAAC,YAAY,IAAI,IAAI,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,kCAAkC;QAClC,IAAI,qBAAqB,KAAK,IAAI,EAAE,CAAC;YACnC,eAAe,CAAC,qBAAqB,CAAC,CAAC;QACzC,CAAC;IACH,CAAC,EAAE,CAAC,qBAAqB,CAAC,CAAC,CAAC;IAE5B,MAAM,cAAc,GAAG,WAAW,CAChC,CAAC,KAA+B,EAAE,EAAE;QAClC,eAAe,CAAC,CAAC,SAAS,EAAE,EAAE;YAC5B,MAAM,QAAQ,GAAG,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YAExE,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;gBACtB,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;YACzC,CAAC;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,EACD,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAC/B,CAAC;IAEF,OAAO,CAAC,WAAW,EAAE,cAAc,CAAU,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useWidgetState } from "./use-widget-state.js";
|
|
2
|
+
import { describe, it, expect, vi, beforeEach, afterEach, } from "vitest";
|
|
3
|
+
import { renderHook, act } from "@testing-library/react";
|
|
4
|
+
describe("useWidgetState", () => {
|
|
5
|
+
let OpenaiMock;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
OpenaiMock = {
|
|
8
|
+
widgetState: null,
|
|
9
|
+
setWidgetState: vi.fn().mockResolvedValue(undefined),
|
|
10
|
+
};
|
|
11
|
+
vi.stubGlobal("openai", OpenaiMock);
|
|
12
|
+
});
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
vi.unstubAllGlobals();
|
|
15
|
+
vi.resetAllMocks();
|
|
16
|
+
});
|
|
17
|
+
const defaultState = { count: 0, name: "test" };
|
|
18
|
+
const windowState = { count: 5, name: "window" };
|
|
19
|
+
it("should initialize with default state when window.openai.widgetState is null", () => {
|
|
20
|
+
OpenaiMock.widgetState = null;
|
|
21
|
+
const { result } = renderHook(() => useWidgetState(defaultState));
|
|
22
|
+
expect(result.current[0]).toEqual(defaultState);
|
|
23
|
+
});
|
|
24
|
+
it("should initialize with window.openai.widgetState when available", () => {
|
|
25
|
+
OpenaiMock.widgetState = windowState;
|
|
26
|
+
const { result } = renderHook(() => useWidgetState(defaultState));
|
|
27
|
+
expect(result.current[0]).toEqual(windowState);
|
|
28
|
+
});
|
|
29
|
+
it("should call window.openai.setWidgetState when setWidgetState is called with a new state", async () => {
|
|
30
|
+
const { result } = renderHook(() => useWidgetState(defaultState));
|
|
31
|
+
const newState = { count: 10, name: "updated" };
|
|
32
|
+
act(() => {
|
|
33
|
+
result.current[1](newState);
|
|
34
|
+
});
|
|
35
|
+
expect(OpenaiMock.setWidgetState).toHaveBeenCalledWith(newState);
|
|
36
|
+
expect(result.current[0]).toEqual(newState);
|
|
37
|
+
});
|
|
38
|
+
it("should call window.openai.setWidgetState when setWidgetState is called with a function updater", async () => {
|
|
39
|
+
const { result } = renderHook(() => useWidgetState(defaultState));
|
|
40
|
+
act(() => {
|
|
41
|
+
result.current[1]((prev) => ({ ...prev, count: prev.count + 1 }));
|
|
42
|
+
});
|
|
43
|
+
expect(OpenaiMock.setWidgetState).toHaveBeenCalledWith({
|
|
44
|
+
count: 1,
|
|
45
|
+
name: "test",
|
|
46
|
+
});
|
|
47
|
+
console.log("widgetState", result.current[0]);
|
|
48
|
+
expect(result.current[0]).toEqual({ count: 1, name: "test" });
|
|
49
|
+
});
|
|
50
|
+
it("should update state when window.openai.widgetState changes", () => {
|
|
51
|
+
OpenaiMock.widgetState = defaultState;
|
|
52
|
+
const { result, rerender } = renderHook(() => useWidgetState(defaultState));
|
|
53
|
+
expect(result.current[0]).toEqual(defaultState);
|
|
54
|
+
// Simulate window.openai.widgetState changing
|
|
55
|
+
OpenaiMock.widgetState = windowState;
|
|
56
|
+
// Trigger re-render to simulate the useEffect running
|
|
57
|
+
rerender();
|
|
58
|
+
expect(result.current[0]).toEqual(windowState);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=use-widget-state.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-widget-state.test.js","sour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,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,oBAAoB,CAAC;YACrD,KAAK,EAAE,CAAC;YACR,IAAI,EAAE,MAAM;SACb,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4DAA4D,EAAE,GAAG,EAAE;QACpE,UAAU,CAAC,WAAW,GAAG,YAAY,CAAC;QACtC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC;QAE5E,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAEhD,8CAA8C;QAC9C,UAAU,CAAC,WAAW,GAAG,WAAW,CAAC;QACrC,sDAAsD;QACtD,QAAQ,EAAE,CAAC;QAEX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/src/web/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type UnknownObject = Record<string, unknown>;
|
|
1
|
+
export type UnknownObject = Record<string, unknown>;
|
|
2
2
|
export type WidgetState = UnknownObject;
|
|
3
3
|
export type SetWidgetState = (state: WidgetState) => Promise<void>;
|
|
4
4
|
export type SendFollowUpMessage = (args: {
|
|
@@ -9,6 +9,10 @@ export type RequestDisplayMode = (args: {
|
|
|
9
9
|
}) => Promise<{
|
|
10
10
|
mode: DisplayMode;
|
|
11
11
|
}>;
|
|
12
|
+
export type RequestModal = (options: RequestModalOptions) => Promise<void>;
|
|
13
|
+
export type RequestModalOptions = {
|
|
14
|
+
title: string;
|
|
15
|
+
};
|
|
12
16
|
export declare const TOOL_RESPONSE_EVENT_TYPE = "openai:tool_response";
|
|
13
17
|
export declare class ToolResponseEvent extends CustomEvent<{
|
|
14
18
|
tool: {
|
|
@@ -26,7 +30,7 @@ declare global {
|
|
|
26
30
|
[SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
|
-
export type OpenAiGlobals<ToolInput extends UnknownObject =
|
|
33
|
+
export type OpenAiGlobals<ToolInput extends UnknownObject = {}, ToolOutput extends UnknownObject = UnknownObject, ToolResponseMetadata extends UnknownObject = UnknownObject, WidgetState extends UnknownObject = UnknownObject> = {
|
|
30
34
|
theme: Theme;
|
|
31
35
|
userAgent: UserAgent;
|
|
32
36
|
locale: string;
|
|
@@ -34,10 +38,13 @@ export type OpenAiGlobals<ToolInput extends UnknownObject = UnknownObject, ToolO
|
|
|
34
38
|
displayMode: DisplayMode;
|
|
35
39
|
safeArea: SafeArea;
|
|
36
40
|
toolInput: ToolInput;
|
|
37
|
-
toolOutput: ToolOutput |
|
|
41
|
+
toolOutput: ToolOutput | {
|
|
42
|
+
text: string;
|
|
43
|
+
} | null;
|
|
38
44
|
toolResponseMetadata: ToolResponseMetadata | null;
|
|
39
45
|
widgetState: WidgetState | null;
|
|
40
46
|
requestDisplayMode: RequestDisplayMode;
|
|
47
|
+
requestModal: RequestModal;
|
|
41
48
|
};
|
|
42
49
|
export type CallToolArgs = Record<string, unknown> | null;
|
|
43
50
|
export type CallToolResponse = {
|
|
@@ -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":"AAkBA,MAAM,CAAC,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAC/D,MAAM,OAAO,iBAAkB,SAAQ,WAErC;IACkB,IAAI,GAAG,wBAAwB,CAAC;CACnD;AA6ED,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAC3D,MAAM,OAAO,eAAgB,SAAQ,WAEnC;IACkB,IAAI,GAAG,sBAAsB,CAAC;CACjD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skybridge",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.e9c6623",
|
|
4
4
|
"description": "Skybridge is a framework for building ChatGPT apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "tsc && pnpm run build:templates",
|
|
21
21
|
"build:templates": "cp -r src/server/templates dist/src/server/",
|
|
22
|
-
"test": "
|
|
22
|
+
"test": "pnpm run test:unit && pnpm run test:type",
|
|
23
|
+
"test:unit": "vitest run --silent",
|
|
24
|
+
"test:type": "tsc --noEmit",
|
|
23
25
|
"docs:dev": "pnpm --filter @skybridge/docs start",
|
|
24
26
|
"docs:build": "pnpm --filter @skybridge/docs build",
|
|
25
27
|
"docs:serve": "pnpm --filter @skybridge/docs serve"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-tool.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,UAAU,OAAO;IACrB,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,WAAW,CAAC,EAAE,CAAC;AACxF,CAAC"}
|