skybridge 0.0.0-dev.ef13340 → 0.0.0-dev.f232042

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.
Files changed (109) hide show
  1. package/README.md +74 -2
  2. package/dist/src/server/server.d.ts +1 -0
  3. package/dist/src/server/server.js +19 -7
  4. package/dist/src/server/server.js.map +1 -1
  5. package/dist/src/server/templateHelper.d.ts +9 -8
  6. package/dist/src/server/templateHelper.js +0 -8
  7. package/dist/src/server/templateHelper.js.map +1 -1
  8. package/dist/src/server/templates/production.hbs +2 -2
  9. package/dist/src/test/widget.test.js +23 -2
  10. package/dist/src/test/widget.test.js.map +1 -1
  11. package/dist/src/web/hooks/index.d.ts +14 -0
  12. package/dist/src/web/hooks/index.js +15 -0
  13. package/dist/src/web/hooks/index.js.map +1 -0
  14. package/dist/src/web/hooks/use-call-tool.d.ts +62 -0
  15. package/dist/src/web/hooks/use-call-tool.js +68 -0
  16. package/dist/src/web/hooks/use-call-tool.js.map +1 -0
  17. package/dist/src/web/hooks/use-call-tool.test.js +163 -0
  18. package/dist/src/web/hooks/use-call-tool.test.js.map +1 -0
  19. package/dist/src/web/hooks/use-display-mode.d.ts +4 -0
  20. package/dist/src/web/hooks/use-display-mode.js +7 -0
  21. package/dist/src/web/hooks/use-display-mode.js.map +1 -0
  22. package/dist/src/web/hooks/use-display-mode.test.d.ts +1 -0
  23. package/dist/src/web/hooks/use-display-mode.test.js +40 -0
  24. package/dist/src/web/hooks/use-display-mode.test.js.map +1 -0
  25. package/dist/src/web/hooks/use-files.d.ts +10 -0
  26. package/dist/src/web/hooks/use-files.js +7 -0
  27. package/dist/src/web/hooks/use-files.js.map +1 -0
  28. package/dist/src/web/hooks/use-files.test.d.ts +1 -0
  29. package/dist/src/web/hooks/use-files.test.js +29 -0
  30. package/dist/src/web/hooks/use-files.test.js.map +1 -0
  31. package/dist/src/web/hooks/use-locale.d.ts +1 -0
  32. package/dist/src/web/hooks/use-locale.js +5 -0
  33. package/dist/src/web/hooks/use-locale.js.map +1 -0
  34. package/dist/src/web/hooks/use-locale.test.d.ts +1 -0
  35. package/dist/src/web/hooks/use-locale.test.js +21 -0
  36. package/dist/src/web/hooks/use-locale.test.js.map +1 -0
  37. package/dist/src/web/hooks/use-open-external.d.ts +1 -0
  38. package/dist/src/web/hooks/use-open-external.js +6 -0
  39. package/dist/src/web/hooks/use-open-external.js.map +1 -0
  40. package/dist/src/web/hooks/use-open-external.test.d.ts +1 -0
  41. package/dist/src/web/hooks/use-open-external.test.js +24 -0
  42. package/dist/src/web/hooks/use-open-external.test.js.map +1 -0
  43. package/dist/src/web/{use-openai-global.d.ts → hooks/use-openai-global.d.ts} +1 -1
  44. package/dist/src/web/{use-openai-global.js → hooks/use-openai-global.js} +4 -2
  45. package/dist/src/web/hooks/use-openai-global.js.map +1 -0
  46. package/dist/src/web/hooks/use-request-modal.d.ts +6 -0
  47. package/dist/src/web/hooks/use-request-modal.js +9 -0
  48. package/dist/src/web/hooks/use-request-modal.js.map +1 -0
  49. package/dist/src/web/hooks/use-request-modal.test.d.ts +1 -0
  50. package/dist/src/web/hooks/use-request-modal.test.js +24 -0
  51. package/dist/src/web/hooks/use-request-modal.test.js.map +1 -0
  52. package/dist/src/web/hooks/use-send-follow-up-message.d.ts +1 -0
  53. package/dist/src/web/hooks/use-send-follow-up-message.js +11 -0
  54. package/dist/src/web/hooks/use-send-follow-up-message.js.map +1 -0
  55. package/dist/src/web/hooks/use-theme.d.ts +1 -0
  56. package/dist/src/web/hooks/use-theme.js +5 -0
  57. package/dist/src/web/hooks/use-theme.js.map +1 -0
  58. package/dist/src/web/hooks/use-theme.test.d.ts +1 -0
  59. package/dist/src/web/hooks/use-theme.test.js +26 -0
  60. package/dist/src/web/hooks/use-theme.test.js.map +1 -0
  61. package/dist/src/web/hooks/use-tool-info.d.ts +25 -0
  62. package/dist/src/web/hooks/use-tool-info.js +22 -0
  63. package/dist/src/web/hooks/use-tool-info.js.map +1 -0
  64. package/dist/src/web/hooks/use-tool-info.test-d.d.ts +1 -0
  65. package/dist/src/web/hooks/use-tool-info.test-d.js +74 -0
  66. package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -0
  67. package/dist/src/web/hooks/use-tool-info.test.d.ts +1 -0
  68. package/dist/src/web/hooks/use-tool-info.test.js +59 -0
  69. package/dist/src/web/hooks/use-tool-info.test.js.map +1 -0
  70. package/dist/src/web/hooks/use-tool-output.d.ts +4 -0
  71. package/dist/src/web/hooks/use-tool-output.js +9 -0
  72. package/dist/src/web/hooks/use-tool-output.js.map +1 -0
  73. package/dist/src/web/hooks/use-tool-response-metadata.d.ts +4 -0
  74. package/dist/src/web/hooks/use-tool-response-metadata.js +8 -0
  75. package/dist/src/web/hooks/use-tool-response-metadata.js.map +1 -0
  76. package/dist/src/web/hooks/use-user-agent.d.ts +1 -0
  77. package/dist/src/web/hooks/use-user-agent.js +5 -0
  78. package/dist/src/web/hooks/use-user-agent.js.map +1 -0
  79. package/dist/src/web/hooks/use-user-agent.test.d.ts +1 -0
  80. package/dist/src/web/hooks/use-user-agent.test.js +31 -0
  81. package/dist/src/web/hooks/use-user-agent.test.js.map +1 -0
  82. package/dist/src/web/hooks/use-widget-state.d.ts +4 -0
  83. package/dist/src/web/hooks/use-widget-state.js +30 -0
  84. package/dist/src/web/hooks/use-widget-state.js.map +1 -0
  85. package/dist/src/web/hooks/use-widget-state.test.d.ts +1 -0
  86. package/dist/src/web/hooks/use-widget-state.test.js +60 -0
  87. package/dist/src/web/hooks/use-widget-state.test.js.map +1 -0
  88. package/dist/src/web/index.d.ts +1 -2
  89. package/dist/src/web/index.js +1 -2
  90. package/dist/src/web/index.js.map +1 -1
  91. package/dist/src/web/mount-widget.js +5 -0
  92. package/dist/src/web/mount-widget.js.map +1 -1
  93. package/dist/src/web/plugin.js +2 -4
  94. package/dist/src/web/plugin.js.map +1 -1
  95. package/dist/src/web/proxy.d.ts +1 -0
  96. package/dist/src/web/proxy.js +45 -0
  97. package/dist/src/web/proxy.js.map +1 -0
  98. package/dist/src/web/types.d.ts +39 -15
  99. package/dist/src/web/types.js.map +1 -1
  100. package/dist/vitest.config.js +0 -1
  101. package/dist/vitest.config.js.map +1 -1
  102. package/package.json +9 -2
  103. package/dist/src/test/setup.js +0 -9
  104. package/dist/src/test/setup.js.map +0 -1
  105. package/dist/src/web/use-openai-global.js.map +0 -1
  106. package/dist/src/web/use-tool-output.d.ts +0 -3
  107. package/dist/src/web/use-tool-output.js +0 -5
  108. package/dist/src/web/use-tool-output.js.map +0 -1
  109. /package/dist/src/{test/setup.d.ts → web/hooks/use-call-tool.test.d.ts} +0 -0
@@ -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,EACF,UAAU,EACV,SAAS,GAEV,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAGzD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,IAAI,UAGH,CAAC;IAEF,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,WAAW,EAAE,QAAQ;YACrB,kBAAkB,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;SAClE,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,uEAAuE,EAAE,GAAG,EAAE;QAC/E,UAAU,CAAC,WAAW,GAAG,QAAQ,CAAC;QAClC,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;QAEtD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8EAA8E,EAAE,GAAG,EAAE;QACtF,UAAU,CAAC,WAAW,GAAG,QAAQ,CAAC;QAClC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;QAEhE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEzC,UAAU,CAAC,WAAW,GAAG,YAAY,CAAC;QACtC,QAAQ,EAAE,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,10 @@
1
+ export declare function useFiles(): {
2
+ upload: (file: File) => Promise<{
3
+ fileId: string;
4
+ }>;
5
+ download: (file: {
6
+ fileId: string;
7
+ }) => Promise<{
8
+ downloadUrl: string;
9
+ }>;
10
+ };
@@ -0,0 +1,7 @@
1
+ export function useFiles() {
2
+ return {
3
+ upload: window.openai.uploadFile,
4
+ download: window.openai.downloadFile,
5
+ };
6
+ }
7
+ //# sourceMappingURL=use-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-files.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-files.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ;IACtB,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU;QAChC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY;KACrC,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -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;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() {
3
+ return useOpenAiGlobal("locale");
4
+ }
5
+ //# sourceMappingURL=use-locale.js.map
@@ -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,6 @@
1
+ export function useOpenExternal() {
2
+ return (href) => {
3
+ window.openai.openExternal({ href });
4
+ };
5
+ }
6
+ //# sourceMappingURL=use-open-external.js.map
@@ -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,2 +1,2 @@
1
- import { type OpenAiGlobals } from "./types.js";
1
+ import { type OpenAiGlobals } from "../types.js";
2
2
  export declare function useOpenAiGlobal<K extends keyof OpenAiGlobals>(key: K): OpenAiGlobals[K] | undefined;
@@ -1,13 +1,15 @@
1
1
  import { useSyncExternalStore } from "react";
2
- import { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from "./types.js";
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, {
@@ -0,0 +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,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,6 @@
1
+ /**
2
+ * Triggers a modal containing the widget rendered in display mode "modal"
3
+ */
4
+ export declare function useRequestModal(): (options: {
5
+ title: string;
6
+ }) => void;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Triggers a modal containing the widget rendered in display mode "modal"
3
+ */
4
+ export function useRequestModal() {
5
+ return (options) => {
6
+ window.openai.requestModal(options);
7
+ };
8
+ }
9
+ //# sourceMappingURL=use-request-modal.js.map
@@ -0,0 +1 @@
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"}
@@ -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,5 @@
1
+ import { useOpenAiGlobal } from "./use-openai-global.js";
2
+ export function useTheme() {
3
+ return useOpenAiGlobal("theme");
4
+ }
5
+ //# sourceMappingURL=use-theme.js.map
@@ -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"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,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,UAAU,EAAE,GAAG,EAAE;IACxB,IAAI,UAEH,CAAC;IAEF,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,KAAK,EAAE,OAAO;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,0DAA0D,EAAE,GAAG,EAAE;QAClE,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEhD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,UAAU,CAAC,KAAK,GAAG,MAAM,CAAC;QAC1B,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEhD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { UnknownObject } from "../types.js";
2
+ type ToolPendingState<ToolInput extends UnknownObject> = {
3
+ status: "pending";
4
+ isPending: true;
5
+ isSuccess: false;
6
+ input: ToolInput;
7
+ output: undefined;
8
+ responseMetadata: undefined;
9
+ };
10
+ 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 = {
20
+ input: UnknownObject;
21
+ output: UnknownObject;
22
+ responseMetadata: UnknownObject;
23
+ };
24
+ export declare function useToolInfo<TS extends Partial<ToolSignature> = {}>(): ToolState<UnknownObject & TS["input"], UnknownObject & TS["output"], UnknownObject & TS["responseMetadata"]>;
25
+ export {};
@@ -0,0 +1,22 @@
1
+ import { useOpenAiGlobal } from "./use-openai-global.js";
2
+ import { useEffect, useState } from "react";
3
+ export function useToolInfo() {
4
+ const [status, setStatus] = useState("pending");
5
+ const input = useOpenAiGlobal("toolInput");
6
+ const output = useOpenAiGlobal("toolOutput") ?? undefined;
7
+ const responseMetadata = useOpenAiGlobal("toolResponseMetadata") ?? undefined;
8
+ useEffect(() => {
9
+ setStatus(output === undefined && responseMetadata === undefined
10
+ ? "pending"
11
+ : "success");
12
+ }, [output, responseMetadata]);
13
+ return {
14
+ input,
15
+ status,
16
+ isPending: status === "pending",
17
+ isSuccess: status === "success",
18
+ output,
19
+ responseMetadata,
20
+ };
21
+ }
22
+ //# 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,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":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,IAAI,CAAC,iCAAiC,EAAE,GAAG,EAAE;IAC3C,IAAI,CAAC,iEAAiE,EAAE,GAAG,EAAE;QAC3E,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;QAE7B,YAAY,CAAwB,MAAM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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"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,59 @@
1
+ import { fireEvent, renderHook, waitFor, act } 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).toMatchObject({
22
+ input: { name: "pokemon", args: { name: "pikachu" } },
23
+ status: "pending",
24
+ isPending: true,
25
+ isSuccess: false,
26
+ });
27
+ });
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 };
35
+ const { result } = renderHook(() => useToolInfo());
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,
44
+ },
45
+ },
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,
55
+ });
56
+ });
57
+ });
58
+ });
59
+ //# 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,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,EAAE,GAAG,UAAU,CAAC,GA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AC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @deprecated This hook is deprecated. Use `useToolInfo()` instead and access the `output` property.
3
+ */
4
+ export declare function useToolOutput(): import("../types.js").UnknownObject | undefined;
@@ -0,0 +1,9 @@
1
+ import { useToolInfo } from "./use-tool-info.js";
2
+ /**
3
+ * @deprecated This hook is deprecated. Use `useToolInfo()` instead and access the `output` property.
4
+ */
5
+ export function useToolOutput() {
6
+ const { output } = useToolInfo();
7
+ return output;
8
+ }
9
+ //# sourceMappingURL=use-tool-output.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,4 @@
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;
@@ -0,0 +1,8 @@
1
+ import { useOpenAiGlobal } from "./use-openai-global.js";
2
+ /**
3
+ * @deprecated This hook is deprecated. Use `useToolInfo()` instead and access the `responseMetadata` property.
4
+ */
5
+ export function useToolResponseMetadata() {
6
+ return useOpenAiGlobal("toolResponseMetadata");
7
+ }
8
+ //# sourceMappingURL=use-tool-response-metadata.js.map
@@ -0,0 +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;;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,5 @@
1
+ import { useOpenAiGlobal } from "./use-openai-global.js";
2
+ export function useUserAgent() {
3
+ return useOpenAiGlobal("userAgent");
4
+ }
5
+ //# sourceMappingURL=use-user-agent.js.map
@@ -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"}