skybridge 0.0.0-dev.9bf6982 → 0.0.0-dev.9d20000

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 (69) hide show
  1. package/dist/src/server/server.js +1 -1
  2. package/dist/src/server/server.js.map +1 -1
  3. package/dist/src/server/widgetsDevServer.js +0 -1
  4. package/dist/src/server/widgetsDevServer.js.map +1 -1
  5. package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.d.ts +13 -0
  6. package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js +33 -0
  7. package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js.map +1 -0
  8. package/dist/src/web/bridges/adaptors/mcp-app-adaptor.d.ts +16 -0
  9. package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js +115 -0
  10. package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js.map +1 -0
  11. package/dist/src/web/bridges/apps-sdk-bridge.d.ts +4 -2
  12. package/dist/src/web/bridges/apps-sdk-bridge.js +19 -14
  13. package/dist/src/web/bridges/apps-sdk-bridge.js.map +1 -1
  14. package/dist/src/web/bridges/hooks/use-adaptor.d.ts +2 -0
  15. package/dist/src/web/bridges/hooks/use-adaptor.js +8 -0
  16. package/dist/src/web/bridges/hooks/use-adaptor.js.map +1 -0
  17. package/dist/src/web/bridges/hooks/use-bridge.js +3 -14
  18. package/dist/src/web/bridges/hooks/use-bridge.js.map +1 -1
  19. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.d.ts +3 -2
  20. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js.map +1 -1
  21. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js +9 -26
  22. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js.map +1 -1
  23. package/dist/src/web/bridges/index.d.ts +1 -1
  24. package/dist/src/web/bridges/index.js +1 -1
  25. package/dist/src/web/bridges/index.js.map +1 -1
  26. package/dist/src/web/bridges/mcp-app-bridge.d.ts +15 -7
  27. package/dist/src/web/bridges/mcp-app-bridge.js +41 -21
  28. package/dist/src/web/bridges/mcp-app-bridge.js.map +1 -1
  29. package/dist/src/web/bridges/types.d.ts +23 -9
  30. package/dist/src/web/generate-helpers.test-d.js +4 -1
  31. package/dist/src/web/generate-helpers.test-d.js.map +1 -1
  32. package/dist/src/web/hooks/test/utils.d.ts +10 -0
  33. package/dist/src/web/hooks/test/utils.js +40 -0
  34. package/dist/src/web/hooks/test/utils.js.map +1 -0
  35. package/dist/src/web/hooks/use-call-tool.js +3 -3
  36. package/dist/src/web/hooks/use-call-tool.js.map +1 -1
  37. package/dist/src/web/hooks/use-display-mode.d.ts +3 -3
  38. package/dist/src/web/hooks/use-display-mode.js +3 -3
  39. package/dist/src/web/hooks/use-display-mode.js.map +1 -1
  40. package/dist/src/web/hooks/use-layout.test.js +87 -38
  41. package/dist/src/web/hooks/use-layout.test.js.map +1 -1
  42. package/dist/src/web/hooks/use-open-external.js +5 -3
  43. package/dist/src/web/hooks/use-open-external.js.map +1 -1
  44. package/dist/src/web/hooks/use-open-external.test.js +41 -15
  45. package/dist/src/web/hooks/use-open-external.test.js.map +1 -1
  46. package/dist/src/web/hooks/use-send-follow-up-message.js +4 -2
  47. package/dist/src/web/hooks/use-send-follow-up-message.js.map +1 -1
  48. package/dist/src/web/hooks/use-tool-info.d.ts +12 -1
  49. package/dist/src/web/hooks/use-tool-info.js +15 -9
  50. package/dist/src/web/hooks/use-tool-info.js.map +1 -1
  51. package/dist/src/web/hooks/use-tool-info.test-d.js +40 -4
  52. package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -1
  53. package/dist/src/web/hooks/use-tool-info.test.js +117 -47
  54. package/dist/src/web/hooks/use-tool-info.test.js.map +1 -1
  55. package/dist/src/web/hooks/use-user.test.js +83 -34
  56. package/dist/src/web/hooks/use-user.test.js.map +1 -1
  57. package/package.json +4 -4
  58. package/dist/src/web/bridges/apps-sdk-adapter.d.ts +0 -4
  59. package/dist/src/web/bridges/apps-sdk-adapter.js +0 -10
  60. package/dist/src/web/bridges/apps-sdk-adapter.js.map +0 -1
  61. package/dist/src/web/bridges/get-bridge-methods.d.ts +0 -2
  62. package/dist/src/web/bridges/get-bridge-methods.js +0 -8
  63. package/dist/src/web/bridges/get-bridge-methods.js.map +0 -1
  64. package/dist/src/web/bridges/hooks/types.d.ts +0 -6
  65. package/dist/src/web/bridges/hooks/types.js +0 -2
  66. package/dist/src/web/bridges/hooks/types.js.map +0 -1
  67. package/dist/src/web/bridges/mcp-app-adapter.d.ts +0 -6
  68. package/dist/src/web/bridges/mcp-app-adapter.js +0 -77
  69. package/dist/src/web/bridges/mcp-app-adapter.js.map +0 -1
@@ -6,27 +6,46 @@ test("useToolInfo - TypeScript typing", () => {
6
6
  expectTypeOf(result.status);
7
7
  expectTypeOf(result.isPending);
8
8
  expectTypeOf(result.isSuccess);
9
+ expectTypeOf(result.isIdle);
9
10
  expectTypeOf(result.input);
10
11
  });
11
12
  test("should correctly type input, output, and responseMetadata with explicit ToolSignature", () => {
12
13
  const result = useToolInfo();
13
- expectTypeOf(result.input);
14
+ // When idle, input should be undefined
15
+ if (result.status === "idle") {
16
+ expectTypeOf(result.input);
17
+ expectTypeOf(result.output);
18
+ expectTypeOf(result.responseMetadata);
19
+ }
14
20
  // When pending, output and responseMetadata should be undefined
15
21
  if (result.status === "pending") {
22
+ expectTypeOf(result.input);
16
23
  expectTypeOf(result.output);
17
24
  expectTypeOf(result.responseMetadata);
18
25
  }
19
26
  // When success, output and responseMetadata should be defined
20
27
  if (result.status === "success") {
28
+ expectTypeOf(result.input);
21
29
  expectTypeOf(result.output);
22
30
  expectTypeOf(result.responseMetadata);
23
31
  }
24
32
  });
25
33
  test("should correctly narrow types based on status discriminated union", () => {
26
34
  const result = useToolInfo();
27
- // Test type narrowing
35
+ // Test type narrowing for idle
36
+ if (result.isIdle) {
37
+ expectTypeOf(result.status);
38
+ expectTypeOf(result.isIdle);
39
+ expectTypeOf(result.isPending);
40
+ expectTypeOf(result.isSuccess);
41
+ expectTypeOf(result.input);
42
+ expectTypeOf(result.output);
43
+ expectTypeOf(result.responseMetadata);
44
+ }
45
+ // Test type narrowing for pending
28
46
  if (result.isPending) {
29
47
  expectTypeOf(result.status);
48
+ expectTypeOf(result.isIdle);
30
49
  expectTypeOf(result.isPending);
31
50
  expectTypeOf(result.isSuccess);
32
51
  expectTypeOf(result.output);
@@ -34,13 +53,23 @@ test("useToolInfo - TypeScript typing", () => {
34
53
  }
35
54
  if (result.isSuccess) {
36
55
  expectTypeOf(result.status);
56
+ expectTypeOf(result.isIdle);
37
57
  expectTypeOf(result.isPending);
38
58
  expectTypeOf(result.isSuccess);
39
59
  expectTypeOf(result.output);
40
60
  expectTypeOf(result.responseMetadata);
41
61
  }
62
+ if (result.status === "idle") {
63
+ expectTypeOf(result.isIdle);
64
+ expectTypeOf(result.isPending);
65
+ expectTypeOf(result.isSuccess);
66
+ expectTypeOf(result.input);
67
+ expectTypeOf(result.output);
68
+ expectTypeOf(result.responseMetadata);
69
+ }
42
70
  if (result.status === "pending") {
43
71
  expectTypeOf(result.input);
72
+ expectTypeOf(result.isIdle);
44
73
  expectTypeOf(result.isPending);
45
74
  expectTypeOf(result.isSuccess);
46
75
  expectTypeOf(result.output);
@@ -48,6 +77,7 @@ test("useToolInfo - TypeScript typing", () => {
48
77
  }
49
78
  if (result.status === "success") {
50
79
  expectTypeOf(result.input);
80
+ expectTypeOf(result.isIdle);
51
81
  expectTypeOf(result.isPending);
52
82
  expectTypeOf(result.isSuccess);
53
83
  expectTypeOf(result.output);
@@ -56,7 +86,10 @@ test("useToolInfo - TypeScript typing", () => {
56
86
  });
57
87
  test("should handle partial ToolSignature with only input specified", () => {
58
88
  const result = useToolInfo();
59
- expectTypeOf(result.input);
89
+ // Input can be TestInput or undefined (when idle)
90
+ if (result.status === "pending" || result.status === "success") {
91
+ expectTypeOf(result.input);
92
+ }
60
93
  if (result.status === "success") {
61
94
  expectTypeOf(result.output);
62
95
  expectTypeOf(result.responseMetadata);
@@ -64,7 +97,10 @@ test("useToolInfo - TypeScript typing", () => {
64
97
  });
65
98
  test("should handle ToolSignature with only output specified", () => {
66
99
  const result = useToolInfo();
67
- expectTypeOf(result.input);
100
+ // Input can be Record<string, unknown> or undefined (when idle)
101
+ if (result.status === "pending" || result.status === "success") {
102
+ expectTypeOf(result.input);
103
+ }
68
104
  if (result.status === "success") {
69
105
  expectTypeOf(result.output);
70
106
  }
@@ -1 +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,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,CAAC,MAAM,CAAC,CAAC;QACnD,YAAY,CAAU,MAAM,CAAC,SAAS,CAAC,CAAC;QACxC,YAAY,CAAU,MAAM,CAAC,SAAS,CAAC,CAAC;QACxC,YAAY,CAA0B,MAAM,CAAC,KAAK,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,uFAAuF,EAAE,GAAG,EAAE;QAKjG,MAAM,MAAM,GAAG,WAAW,EAItB,CAAC;QAEL,YAAY,CAAY,MAAM,CAAC,KAAK,CAAC,CAAC;QAEtC,gEAAgE;QAChE,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAAY,MAAM,CAAC,MAAM,CAAC,CAAC;YACvC,YAAY,CAAY,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACnD,CAAC;QAED,8DAA8D;QAC9D,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CA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AM,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,gEAAgE;QAChE,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC/D,YAAY,CAA0B,MAAM,CAAC,KAAK,CAAC,CAAC;QACtD,CAAC;QAED,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,58 +1,128 @@
1
1
  import { act, fireEvent, renderHook, waitFor } from "@testing-library/react";
2
2
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { McpAppAdaptor } from "../bridges/adaptors/mcp-app-adaptor.js";
4
+ import { McpAppBridge } from "../bridges/mcp-app-bridge.js";
3
5
  import { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent, } from "../types.js";
6
+ import { fireToolInputNotification, fireToolResultNotification, getMcpAppHostPostMessageMock, } from "./test/utils.js";
4
7
  import { useToolInfo } from "./use-tool-info.js";
5
8
  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
- vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
15
- });
16
- afterEach(() => {
17
- vi.unstubAllGlobals();
18
- vi.resetAllMocks();
19
- });
20
- it("should return toolInput on initial mount window.openai", () => {
21
- const { result } = renderHook(() => useToolInfo());
22
- expect(result.current).toMatchObject({
23
- input: { name: "pokemon", args: { name: "pikachu" } },
24
- status: "pending",
25
- isPending: true,
26
- isSuccess: false,
9
+ describe("apps-sdk host", () => {
10
+ let OpenaiMock;
11
+ beforeEach(() => {
12
+ OpenaiMock = {
13
+ toolInput: { name: "pokemon", args: { name: "pikachu" } },
14
+ toolOutput: null,
15
+ toolResponseMetadata: null,
16
+ };
17
+ vi.stubGlobal("openai", OpenaiMock);
18
+ vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
27
19
  });
28
- });
29
- it("should eventually return tool output and response metadata once tool call completes", async () => {
30
- const toolOutput = {
31
- name: "pikachu",
32
- color: "yellow",
33
- description: "When several of these POKéMON gather, their\felectricity could build and cause lightning storms.",
34
- };
35
- const toolResponseMetadata = { id: 12 };
36
- const { result } = renderHook(() => useToolInfo());
37
- act(() => {
38
- OpenaiMock.toolOutput = toolOutput;
39
- OpenaiMock.toolResponseMetadata = toolResponseMetadata;
40
- fireEvent(window, new SetGlobalsEvent(SET_GLOBALS_EVENT_TYPE, {
41
- detail: {
42
- globals: {
43
- toolOutput,
44
- toolResponseMetadata,
45
- },
46
- },
47
- }));
20
+ afterEach(() => {
21
+ vi.unstubAllGlobals();
22
+ vi.resetAllMocks();
48
23
  });
49
- await waitFor(() => {
24
+ it("should return toolInput on initial mount window.openai", () => {
25
+ const { result } = renderHook(() => useToolInfo());
50
26
  expect(result.current).toMatchObject({
51
- status: "success",
52
- isPending: false,
53
- isSuccess: true,
54
- output: toolOutput,
55
- responseMetadata: toolResponseMetadata,
27
+ input: { name: "pokemon", args: { name: "pikachu" } },
28
+ status: "pending",
29
+ isIdle: false,
30
+ isPending: true,
31
+ isSuccess: false,
32
+ });
33
+ });
34
+ it("should eventually return tool output and response metadata once tool call completes", async () => {
35
+ const toolOutput = {
36
+ name: "pikachu",
37
+ color: "yellow",
38
+ description: "When several of these POKéMON gather, their\felectricity could build and cause lightning storms.",
39
+ };
40
+ const toolResponseMetadata = { id: 12 };
41
+ const { result } = renderHook(() => useToolInfo());
42
+ act(() => {
43
+ OpenaiMock.toolOutput = toolOutput;
44
+ OpenaiMock.toolResponseMetadata = toolResponseMetadata;
45
+ fireEvent(window, new SetGlobalsEvent(SET_GLOBALS_EVENT_TYPE, {
46
+ detail: {
47
+ globals: {
48
+ toolOutput,
49
+ toolResponseMetadata,
50
+ },
51
+ },
52
+ }));
53
+ });
54
+ await waitFor(() => {
55
+ expect(result.current).toMatchObject({
56
+ status: "success",
57
+ isIdle: false,
58
+ isPending: false,
59
+ isSuccess: true,
60
+ output: toolOutput,
61
+ responseMetadata: toolResponseMetadata,
62
+ });
63
+ });
64
+ });
65
+ });
66
+ describe("mcp-app host", () => {
67
+ beforeEach(() => {
68
+ vi.stubGlobal("parent", { postMessage: getMcpAppHostPostMessageMock() });
69
+ vi.stubGlobal("skybridge", { hostType: "mcp-app" });
70
+ });
71
+ afterEach(() => {
72
+ vi.unstubAllGlobals();
73
+ vi.resetAllMocks();
74
+ McpAppBridge.resetInstance();
75
+ McpAppAdaptor.resetInstance();
76
+ });
77
+ it("should return idle state initially when tool input is not yet set", async () => {
78
+ const { result } = renderHook(() => useToolInfo());
79
+ await waitFor(() => {
80
+ expect(result.current).toMatchObject({
81
+ status: "idle",
82
+ isIdle: true,
83
+ isPending: false,
84
+ isSuccess: false,
85
+ input: null,
86
+ output: null,
87
+ responseMetadata: null,
88
+ });
89
+ });
90
+ });
91
+ it("should return pending state with tool input from tool-input notification", async () => {
92
+ const { result } = renderHook(() => useToolInfo());
93
+ act(() => {
94
+ fireToolInputNotification({ name: "pokemon", query: "pikachu" });
95
+ });
96
+ await waitFor(() => {
97
+ expect(result.current).toMatchObject({
98
+ status: "pending",
99
+ isIdle: false,
100
+ isPending: true,
101
+ isSuccess: false,
102
+ input: { name: "pokemon", query: "pikachu" },
103
+ });
104
+ });
105
+ });
106
+ it("should return success state with output from tool-result notification", async () => {
107
+ const { result } = renderHook(() => useToolInfo());
108
+ act(() => {
109
+ fireToolInputNotification({ name: "pokemon", query: "pikachu" });
110
+ fireToolResultNotification({
111
+ content: [{ type: "text", text: "Pikachu data" }],
112
+ structuredContent: { name: "pikachu", color: "yellow" },
113
+ _meta: { requestId: "123" },
114
+ });
115
+ });
116
+ await waitFor(() => {
117
+ expect(result.current).toMatchObject({
118
+ status: "success",
119
+ isIdle: false,
120
+ isPending: false,
121
+ isSuccess: true,
122
+ input: { name: "pokemon", query: "pikachu" },
123
+ output: { name: "pikachu", color: "yellow" },
124
+ responseMetadata: { requestId: "123" },
125
+ });
56
126
  });
57
127
  });
58
128
  });
@@ -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,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAEL,sBAAsB,EACtB,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,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;QACpC,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,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AC,GAAG,EAAE;gBACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC;oBACnC,MAAM,EAAE,SAAS;oBACjB,MAAM,EAAE,KAAK;oBACb,SAAS,EAAE,KAAK;oBAChB,SAAS,EAAE,IAAI;oBACf,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE;oBAC5C,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE;oBAC5C,gBAAgB,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;iBACvC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,44 +1,93 @@
1
- import { renderHook } from "@testing-library/react";
1
+ import { renderHook, waitFor } from "@testing-library/react";
2
2
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { McpAppAdaptor } from "../bridges/adaptors/mcp-app-adaptor.js";
4
+ import { McpAppBridge } from "../bridges/mcp-app-bridge.js";
5
+ import { getMcpAppHostPostMessageMock } from "./test/utils.js";
3
6
  import { useUser } from "./use-user.js";
4
7
  describe("useUser", () => {
5
- let OpenaiMock;
6
- beforeEach(() => {
7
- OpenaiMock = {
8
- locale: "en-US",
9
- userAgent: {
8
+ describe("apps-sdk host type", () => {
9
+ let OpenaiMock;
10
+ beforeEach(() => {
11
+ OpenaiMock = {
12
+ locale: "en-US",
13
+ userAgent: {
14
+ device: { type: "desktop" },
15
+ capabilities: { hover: true, touch: false },
16
+ },
17
+ };
18
+ vi.stubGlobal("openai", OpenaiMock);
19
+ vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
20
+ });
21
+ afterEach(() => {
22
+ vi.unstubAllGlobals();
23
+ vi.resetAllMocks();
24
+ });
25
+ it("should return locale and userAgent from window.openai", () => {
26
+ const { result } = renderHook(() => useUser());
27
+ expect(result.current.locale).toBe("en-US");
28
+ expect(result.current.userAgent).toEqual({
10
29
  device: { type: "desktop" },
11
30
  capabilities: { hover: true, touch: false },
12
- },
13
- };
14
- vi.stubGlobal("openai", OpenaiMock);
15
- vi.stubGlobal("skybridge", { hostType: "apps-sdk" });
16
- });
17
- afterEach(() => {
18
- vi.unstubAllGlobals();
19
- vi.resetAllMocks();
20
- });
21
- it("should return locale and userAgent from window.openai", () => {
22
- const { result } = renderHook(() => useUser());
23
- expect(result.current.locale).toBe("en-US");
24
- expect(result.current.userAgent).toEqual({
25
- device: { type: "desktop" },
26
- capabilities: { hover: true, touch: false },
31
+ });
32
+ });
33
+ it("should return mobile userAgent when set to mobile", () => {
34
+ OpenaiMock.userAgent = {
35
+ device: { type: "mobile" },
36
+ capabilities: { hover: false, touch: true },
37
+ };
38
+ const { result } = renderHook(() => useUser());
39
+ expect(result.current.userAgent.device.type).toBe("mobile");
40
+ expect(result.current.userAgent.capabilities.touch).toBe(true);
41
+ });
42
+ it("should return different locale when set", () => {
43
+ OpenaiMock.locale = "es-ES";
44
+ const { result } = renderHook(() => useUser());
45
+ expect(result.current.locale).toBe("es-ES");
27
46
  });
28
47
  });
29
- it("should return mobile userAgent when set to mobile", () => {
30
- OpenaiMock.userAgent = {
31
- device: { type: "mobile" },
32
- capabilities: { hover: false, touch: true },
33
- };
34
- const { result } = renderHook(() => useUser());
35
- expect(result.current.userAgent.device.type).toBe("mobile");
36
- expect(result.current.userAgent.capabilities.touch).toBe(true);
37
- });
38
- it("should return different locale when set", () => {
39
- OpenaiMock.locale = "es-ES";
40
- const { result } = renderHook(() => useUser());
41
- expect(result.current.locale).toBe("es-ES");
48
+ describe("mcp-app host type", () => {
49
+ beforeEach(() => {
50
+ vi.stubGlobal("skybridge", { hostType: "mcp-app" });
51
+ });
52
+ afterEach(() => {
53
+ vi.unstubAllGlobals();
54
+ vi.resetAllMocks();
55
+ McpAppBridge.resetInstance();
56
+ McpAppAdaptor.resetInstance();
57
+ });
58
+ it("should return locale and userAgent from mcp host context", async () => {
59
+ vi.stubGlobal("parent", {
60
+ postMessage: getMcpAppHostPostMessageMock({
61
+ locale: "fr-FR",
62
+ platform: "web",
63
+ deviceCapabilities: { hover: true, touch: false },
64
+ }),
65
+ });
66
+ const { result } = renderHook(() => useUser());
67
+ await waitFor(() => {
68
+ expect(result.current.locale).toBe("fr-FR");
69
+ expect(result.current.userAgent).toEqual({
70
+ device: { type: "desktop" },
71
+ capabilities: { hover: true, touch: false },
72
+ });
73
+ });
74
+ });
75
+ it("should maintain userAgent referential stability when data has not changed", async () => {
76
+ vi.stubGlobal("parent", {
77
+ postMessage: getMcpAppHostPostMessageMock({
78
+ locale: "en-US",
79
+ platform: "web",
80
+ deviceCapabilities: { hover: true, touch: false },
81
+ }),
82
+ });
83
+ const { result, rerender } = renderHook(() => useUser());
84
+ await waitFor(() => {
85
+ expect(result.current.userAgent).toBeDefined();
86
+ });
87
+ const initialUserAgent = result.current.userAgent;
88
+ rerender();
89
+ expect(result.current.userAgent).toBe(initialUserAgent);
90
+ });
42
91
  });
43
92
  });
44
93
  //# sourceMappingURL=use-user.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-user.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-user.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAEzE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,IAAI,UAGH,CAAC;IAEF,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,MAAM,EAAE,OAAO;YACf,SAAS,EAAE;gBACT,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;gBAC3B,YAAY,EAAE,EAAE,K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f6982",
3
+ "version": "0.0.0-dev.9d20000",
4
4
  "description": "Skybridge is a framework for building ChatGPT apps",
5
5
  "repository": {
6
6
  "type": "git",
@@ -45,6 +45,7 @@
45
45
  "dependencies": {
46
46
  "@babel/core": "^7.28.5",
47
47
  "cors": "^2.8.5",
48
+ "dequal": "^2.0.3",
48
49
  "express": "^5.1.0",
49
50
  "handlebars": "^4.7.8",
50
51
  "superjson": "^2.2.6",
@@ -52,16 +53,15 @@
52
53
  "zustand": "^5.0.9"
53
54
  },
54
55
  "devDependencies": {
55
- "@biomejs/biome": "2.3.8",
56
56
  "@modelcontextprotocol/ext-apps": "^0.2.2",
57
57
  "@modelcontextprotocol/sdk": "^1.24.3",
58
58
  "@testing-library/dom": "^10.4.1",
59
- "@testing-library/react": "^16.3.0",
59
+ "@testing-library/react": "^16.3.1",
60
60
  "@total-typescript/tsconfig": "^1.0.4",
61
61
  "@types/babel__core": "^7.20.5",
62
62
  "@types/cors": "^2.8.19",
63
63
  "@types/express": "^5.0.3",
64
- "@types/jsdom": "^21.1.6",
64
+ "@types/jsdom": "^21.1.7",
65
65
  "@types/node": "^22.15.30",
66
66
  "@types/react": "^19.2.2",
67
67
  "@types/react-dom": "^19.2.2",
@@ -1,4 +0,0 @@
1
- import type { CallToolResponse, Methods } from "./types.js";
2
- export declare const callTool: <ToolArgs extends Record<string, unknown> | null = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
3
- export declare const requestDisplayMode: Methods["requestDisplayMode"];
4
- export declare const sendFollowUpMessage: Methods["sendFollowUpMessage"];
@@ -1,10 +0,0 @@
1
- export const callTool = async (name, args) => {
2
- return window.openai.callTool(name, args);
3
- };
4
- export const requestDisplayMode = ({ mode }) => {
5
- return window.openai.requestDisplayMode({ mode });
6
- };
7
- export const sendFollowUpMessage = (prompt) => {
8
- return window.openai.sendFollowUpMessage({ prompt });
9
- };
10
- //# sourceMappingURL=apps-sdk-adapter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"apps-sdk-adapter.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk-adapter.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAI3B,IAAY,EACZ,IAAc,EACS,EAAE;IACzB,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAyB,IAAI,EAAE,IAAI,CAAC,CAAC;AACpE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAkC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;IAC5E,OAAO,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AACpD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAmC,CAAC,MAAM,EAAE,EAAE;IAC5E,OAAO,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AACvD,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- import type { Methods } from "./types.js";
2
- export declare const getBridgeMethods: () => Methods;
@@ -1,8 +0,0 @@
1
- import * as AppsSdkAdapter from "./apps-sdk-adapter.js";
2
- import * as McpAppAdapter from "./mcp-app-adapter.js";
3
- export const getBridgeMethods = () => {
4
- return window.skybridge.hostType === "apps-sdk"
5
- ? AppsSdkAdapter
6
- : McpAppAdapter;
7
- };
8
- //# sourceMappingURL=get-bridge-methods.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-bridge-methods.js","sourceRoot":"","sources":["../../../../src/web/bridges/get-bridge-methods.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,cAAc,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,aAAa,MAAM,sBAAsB,CAAC;AAGtD,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAY,EAAE;IAC5C,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,KAAK,UAAU;QAC7C,CAAC,CAAC,cAAc;QAChB,CAAC,CAAC,aAAa,CAAC;AACpB,CAAC,CAAC"}
@@ -1,6 +0,0 @@
1
- import type { BridgeInterface } from "../types.js";
2
- export type BridgeSubscribe = (onChange: () => void) => () => void;
3
- export type BridgeExternalStore<K extends keyof BridgeInterface> = {
4
- subscribe: BridgeSubscribe;
5
- getSnapshot: () => BridgeInterface[K];
6
- };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/web/bridges/hooks/types.ts"],"names":[],"mappings":""}
@@ -1,6 +0,0 @@
1
- import type { BridgeExternalStore } from "./hooks/types.js";
2
- import type { BridgeInterface, CallToolResponse, Methods } from "./types.js";
3
- export declare const callTool: <ToolArgs extends Record<string, unknown> | null = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
4
- export declare const requestDisplayMode: Methods["requestDisplayMode"];
5
- export declare const sendFollowUpMessage: Methods["sendFollowUpMessage"];
6
- export declare const getMcpAppAdapter: () => { [K in keyof BridgeInterface]: BridgeExternalStore<K>; };
@@ -1,77 +0,0 @@
1
- import { McpAppBridge } from "./mcp-app-bridge.js";
2
- export const callTool = async (name, args) => {
3
- const bridge = McpAppBridge.getInstance();
4
- const response = await bridge.request({
5
- method: "tools/call",
6
- params: {
7
- name,
8
- arguments: args ?? undefined,
9
- },
10
- });
11
- const result = response.content
12
- .filter((content) => content.type === "text")
13
- .map(({ text }) => text)
14
- .join("\n");
15
- return {
16
- content: response.content,
17
- structuredContent: response.structuredContent ?? {},
18
- isError: response.isError ?? false,
19
- result,
20
- meta: response._meta ?? {},
21
- };
22
- };
23
- export const requestDisplayMode = ({ mode }) => {
24
- const bridge = McpAppBridge.getInstance();
25
- if (mode !== "modal") {
26
- return bridge.request({
27
- method: "ui/request-display-mode",
28
- params: { mode },
29
- });
30
- }
31
- throw new Error("Modal display mode is not accessible in MCP App.");
32
- };
33
- export const sendFollowUpMessage = async (prompt) => {
34
- const bridge = McpAppBridge.getInstance();
35
- await bridge.request({
36
- method: "ui/message",
37
- params: {
38
- role: "user",
39
- content: [
40
- {
41
- type: "text",
42
- text: prompt,
43
- },
44
- ],
45
- },
46
- });
47
- };
48
- const createExternalStore = (keys, getSnapshot) => {
49
- const bridge = McpAppBridge.getInstance();
50
- return {
51
- subscribe: bridge.subscribe(keys),
52
- getSnapshot: () => {
53
- const context = Object.fromEntries(keys.map((k) => [k, bridge.getSnapshot(k)]));
54
- return getSnapshot(context);
55
- },
56
- };
57
- };
58
- export const getMcpAppAdapter = () => ({
59
- theme: createExternalStore(["theme"], ({ theme }) => theme ?? "light"),
60
- locale: createExternalStore(["locale"], ({ locale }) => locale ?? "en-US"),
61
- safeArea: createExternalStore(["safeAreaInsets"], ({ safeAreaInsets }) => ({
62
- insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },
63
- })),
64
- displayMode: createExternalStore(["displayMode"], ({ displayMode }) => displayMode ?? "inline"),
65
- maxHeight: createExternalStore(["viewport"], ({ viewport }) => viewport?.maxHeight ?? window.innerHeight),
66
- userAgent: createExternalStore(["platform", "deviceCapabilities"], ({ platform, deviceCapabilities }) => ({
67
- device: {
68
- type: platform === "web" ? "desktop" : (platform ?? "unknown"),
69
- },
70
- capabilities: {
71
- hover: true,
72
- touch: true,
73
- ...deviceCapabilities,
74
- },
75
- })),
76
- });
77
- //# sourceMappingURL=mcp-app-adapter.js.map