skybridge 0.0.0-dev.e4c9359 → 0.0.0-dev.e62daf3

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 (125) hide show
  1. package/LICENSE +21 -674
  2. package/README.md +70 -270
  3. package/dist/src/server/devtoolsStaticServer.d.ts +15 -0
  4. package/dist/src/server/devtoolsStaticServer.js +38 -0
  5. package/dist/src/server/devtoolsStaticServer.js.map +1 -0
  6. package/dist/src/server/index.d.ts +3 -2
  7. package/dist/src/server/index.js +1 -0
  8. package/dist/src/server/index.js.map +1 -1
  9. package/dist/src/server/inferUtilityTypes.d.ts +22 -6
  10. package/dist/src/server/server.d.ts +45 -16
  11. package/dist/src/server/server.js +15 -6
  12. package/dist/src/server/server.js.map +1 -1
  13. package/dist/src/server/templateHelper.js +5 -4
  14. package/dist/src/server/templateHelper.js.map +1 -1
  15. package/dist/src/server/templates/development.hbs +2 -2
  16. package/dist/src/server/widgetsDevServer.js +3 -3
  17. package/dist/src/server/widgetsDevServer.js.map +1 -1
  18. package/dist/src/test/utils.d.ts +44 -9
  19. package/dist/src/test/utils.js +66 -8
  20. package/dist/src/test/utils.js.map +1 -1
  21. package/dist/src/test/widget.test.js +43 -21
  22. package/dist/src/test/widget.test.js.map +1 -1
  23. package/dist/src/web/create-store.d.ts +3 -0
  24. package/dist/src/web/create-store.js +25 -0
  25. package/dist/src/web/create-store.js.map +1 -0
  26. package/dist/src/web/create-store.test.js +70 -0
  27. package/dist/src/web/create-store.test.js.map +1 -0
  28. package/dist/src/web/data-llm.d.ts +14 -0
  29. package/dist/src/web/data-llm.js +68 -0
  30. package/dist/src/web/data-llm.js.map +1 -0
  31. package/dist/src/web/data-llm.test.js +76 -0
  32. package/dist/src/web/data-llm.test.js.map +1 -0
  33. package/dist/src/web/{typed-hooks.d.ts → generate-helpers.d.ts} +23 -20
  34. package/dist/src/web/{typed-hooks.js → generate-helpers.js} +14 -10
  35. package/dist/src/web/generate-helpers.js.map +1 -0
  36. package/dist/src/web/generate-helpers.test-d.d.ts +1 -0
  37. package/dist/src/web/generate-helpers.test-d.js +180 -0
  38. package/dist/src/web/generate-helpers.test-d.js.map +1 -0
  39. package/dist/src/web/generate-helpers.test.d.ts +1 -0
  40. package/dist/src/web/{typed-hooks.test.js → generate-helpers.test.js} +5 -5
  41. package/dist/src/web/generate-helpers.test.js.map +1 -0
  42. package/dist/src/web/helpers/state.d.ts +7 -0
  43. package/dist/src/web/helpers/state.js +40 -0
  44. package/dist/src/web/helpers/state.js.map +1 -0
  45. package/dist/src/web/helpers/state.test.d.ts +1 -0
  46. package/dist/src/web/helpers/state.test.js +53 -0
  47. package/dist/src/web/helpers/state.test.js.map +1 -0
  48. package/dist/src/web/hooks/index.d.ts +2 -4
  49. package/dist/src/web/hooks/index.js +2 -4
  50. package/dist/src/web/hooks/index.js.map +1 -1
  51. package/dist/src/web/hooks/use-call-tool.d.ts +21 -20
  52. package/dist/src/web/hooks/use-call-tool.js +7 -15
  53. package/dist/src/web/hooks/use-call-tool.js.map +1 -1
  54. package/dist/src/web/hooks/use-call-tool.test-d.d.ts +1 -0
  55. package/dist/src/web/hooks/use-call-tool.test-d.js +104 -0
  56. package/dist/src/web/hooks/use-call-tool.test-d.js.map +1 -0
  57. package/dist/src/web/hooks/use-call-tool.test.js +14 -12
  58. package/dist/src/web/hooks/use-call-tool.test.js.map +1 -1
  59. package/dist/src/web/hooks/use-display-mode.js.map +1 -1
  60. package/dist/src/web/hooks/use-display-mode.test.js +2 -2
  61. package/dist/src/web/hooks/use-display-mode.test.js.map +1 -1
  62. package/dist/src/web/hooks/use-files.test.js +1 -1
  63. package/dist/src/web/hooks/use-files.test.js.map +1 -1
  64. package/dist/src/web/hooks/use-locale.js.map +1 -1
  65. package/dist/src/web/hooks/use-locale.test.js +2 -2
  66. package/dist/src/web/hooks/use-locale.test.js.map +1 -1
  67. package/dist/src/web/hooks/use-open-external.test.js +2 -2
  68. package/dist/src/web/hooks/use-open-external.test.js.map +1 -1
  69. package/dist/src/web/hooks/use-openai-global.d.ts +2 -2
  70. package/dist/src/web/hooks/use-openai-global.js +7 -5
  71. package/dist/src/web/hooks/use-openai-global.js.map +1 -1
  72. package/dist/src/web/hooks/use-request-modal.test.js +2 -2
  73. package/dist/src/web/hooks/use-request-modal.test.js.map +1 -1
  74. package/dist/src/web/hooks/use-theme.js.map +1 -1
  75. package/dist/src/web/hooks/use-theme.test.js +2 -2
  76. package/dist/src/web/hooks/use-theme.test.js.map +1 -1
  77. package/dist/src/web/hooks/use-tool-info.d.ts +1 -1
  78. package/dist/src/web/hooks/use-tool-info.js +4 -6
  79. package/dist/src/web/hooks/use-tool-info.js.map +1 -1
  80. package/dist/src/web/hooks/use-tool-info.test-d.js +0 -1
  81. package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -1
  82. package/dist/src/web/hooks/use-tool-info.test.js +2 -2
  83. package/dist/src/web/hooks/use-tool-info.test.js.map +1 -1
  84. package/dist/src/web/hooks/use-user-agent.js.map +1 -1
  85. package/dist/src/web/hooks/use-user-agent.test.js +2 -2
  86. package/dist/src/web/hooks/use-user-agent.test.js.map +1 -1
  87. package/dist/src/web/hooks/use-widget-state.js +9 -7
  88. package/dist/src/web/hooks/use-widget-state.js.map +1 -1
  89. package/dist/src/web/hooks/use-widget-state.test.js +2 -2
  90. package/dist/src/web/hooks/use-widget-state.test.js.map +1 -1
  91. package/dist/src/web/index.d.ts +6 -4
  92. package/dist/src/web/index.js +6 -4
  93. package/dist/src/web/index.js.map +1 -1
  94. package/dist/src/web/plugin/data-llm.test.d.ts +1 -0
  95. package/dist/src/web/plugin/data-llm.test.js +81 -0
  96. package/dist/src/web/plugin/data-llm.test.js.map +1 -0
  97. package/dist/src/web/plugin/plugin.js +39 -0
  98. package/dist/src/web/plugin/plugin.js.map +1 -0
  99. package/dist/src/web/plugin/transform-data-llm.d.ts +12 -0
  100. package/dist/src/web/plugin/transform-data-llm.js +93 -0
  101. package/dist/src/web/plugin/transform-data-llm.js.map +1 -0
  102. package/dist/src/web/plugin/transform-data-llm.test.d.ts +1 -0
  103. package/dist/src/web/plugin/transform-data-llm.test.js +81 -0
  104. package/dist/src/web/plugin/transform-data-llm.test.js.map +1 -0
  105. package/dist/src/web/proxy.js +1 -1
  106. package/dist/src/web/proxy.js.map +1 -1
  107. package/dist/src/web/types.d.ts +14 -4
  108. package/dist/src/web/types.js +1 -0
  109. package/dist/src/web/types.js.map +1 -1
  110. package/package.json +14 -6
  111. package/dist/src/web/hooks/use-tool-output.d.ts +0 -4
  112. package/dist/src/web/hooks/use-tool-output.js +0 -9
  113. package/dist/src/web/hooks/use-tool-output.js.map +0 -1
  114. package/dist/src/web/hooks/use-tool-response-metadata.d.ts +0 -4
  115. package/dist/src/web/hooks/use-tool-response-metadata.js +0 -8
  116. package/dist/src/web/hooks/use-tool-response-metadata.js.map +0 -1
  117. package/dist/src/web/plugin.js +0 -28
  118. package/dist/src/web/plugin.js.map +0 -1
  119. package/dist/src/web/typed-hooks.js.map +0 -1
  120. package/dist/src/web/typed-hooks.test-d.js +0 -90
  121. package/dist/src/web/typed-hooks.test-d.js.map +0 -1
  122. package/dist/src/web/typed-hooks.test.js.map +0 -1
  123. /package/dist/src/web/{typed-hooks.test-d.d.ts → create-store.test.d.ts} +0 -0
  124. /package/dist/src/web/{typed-hooks.test.d.ts → data-llm.test.d.ts} +0 -0
  125. /package/dist/src/web/{plugin.d.ts → plugin/plugin.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-store.test.js","sourceRoot":"","sources":["../../../src/web/create-store.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EAEF,EAAE,GACH,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,QAAQ,CAAC,aAAa,EAA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ACzC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;QAEzD,MAAM,YAAY,GAA+C,GAAG,EAAE,CAAC,CAAC;YACtE,KAAK,EAAE,CAAC;SACT,CAAC,CAAC;QACH,MAAM,WAAW,GAAG;YAClB,KAAK,EAAE,CAAC;YACR,CAAC,kBAAkB,CAAC,EAAE,eAAe;SACtC,CAAC;QACF,UAAU,CAAC,WAAW,GAAG,WAAW,CAAC;QAErC,MAAM,KAAK,GAAG,WAAW,CAAC,YAAY,CAAC,CAAC;QAExC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;QAC/C,MAAM,CACH,KAAK,CAAC,QAAQ,EAA8B,CAAC,kBAAkB,CAAC,CAClE,CAAC,aAAa,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { type ReactNode } from "react";
2
+ export type DataLLMContent = string;
3
+ export interface DataLLMNode {
4
+ id: string;
5
+ parentId: string | null;
6
+ content: string | null;
7
+ }
8
+ export declare const WIDGET_CONTEXT_KEY: "__widget_context";
9
+ interface DataLLMProps {
10
+ content: DataLLMContent | null | undefined;
11
+ children?: ReactNode;
12
+ }
13
+ export declare function DataLLM({ content, children }: DataLLMProps): import("react/jsx-runtime").JSX.Element;
14
+ export {};
@@ -0,0 +1,68 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useEffect, useId, } from "react";
3
+ export const WIDGET_CONTEXT_KEY = "__widget_context";
4
+ const nodes = new Map();
5
+ function setNode(node) {
6
+ nodes.set(node.id, node);
7
+ onChange();
8
+ }
9
+ function removeNode(id) {
10
+ nodes.delete(id);
11
+ onChange();
12
+ }
13
+ function onChange() {
14
+ const description = getLLMDescriptionString();
15
+ window.openai.setWidgetState({
16
+ ...window.openai.widgetState,
17
+ [WIDGET_CONTEXT_KEY]: description,
18
+ });
19
+ }
20
+ const ParentIdContext = createContext(null);
21
+ export function DataLLM({ content, children }) {
22
+ const parentId = useContext(ParentIdContext);
23
+ const id = useId();
24
+ useEffect(() => {
25
+ if (content) {
26
+ setNode({
27
+ id,
28
+ parentId,
29
+ content,
30
+ });
31
+ }
32
+ else {
33
+ removeNode(id);
34
+ }
35
+ return () => {
36
+ removeNode(id);
37
+ };
38
+ }, [id, parentId, content]);
39
+ return (_jsx(ParentIdContext.Provider, { value: id, children: children }));
40
+ }
41
+ function getLLMDescriptionString() {
42
+ const byParent = new Map();
43
+ for (const node of Array.from(nodes.values())) {
44
+ const key = node.parentId ?? null;
45
+ if (!byParent.has(key))
46
+ byParent.set(key, []);
47
+ byParent.get(key)?.push(node);
48
+ }
49
+ for (const list of byParent.values()) {
50
+ list.sort((a, b) => a.id.localeCompare(b.id));
51
+ }
52
+ const lines = [];
53
+ function traverseTree(parentId, depth) {
54
+ const children = byParent.get(parentId);
55
+ if (!children)
56
+ return;
57
+ for (const child of children) {
58
+ if (child.content?.trim()) {
59
+ const indent = " ".repeat(depth);
60
+ lines.push(`${indent}- ${child.content.trim()}`);
61
+ }
62
+ traverseTree(child.id, depth + 1);
63
+ }
64
+ }
65
+ traverseTree(null, 0);
66
+ return lines.join("\n");
67
+ }
68
+ //# sourceMappingURL=data-llm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-llm.js","sourceRoot":"","sources":["../../../src/web/data-llm.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EAEb,UAAU,EACV,SAAS,EACT,KAAK,GACN,MAAM,OAAO,CAAC;AAUf,MAAM,CAAC,MAAM,kBAAkB,GAAG,kBAA2B,CAAC;AAE9D,MAAM,KAAK,GAAG,IAAI,GAAG,EAAuB,CAAC;AAE7C,SAAS,OAAO,CAAC,IAAiB;IAChC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;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-runtime";
2
+ import { render } from "@testing-library/react";
3
+ import { afterEach, beforeEach, describe, expect, it, vi, } from "vitest";
4
+ import { DataLLM } from "./data-llm.js";
5
+ describe("DataLLM", () => {
6
+ let OpenaiMock;
7
+ beforeEach(() => {
8
+ OpenaiMock = {
9
+ widgetState: {},
10
+ setWidgetState: vi.fn(),
11
+ };
12
+ // Use Object.defineProperty to ensure it persists
13
+ Object.defineProperty(globalThis, "openai", {
14
+ value: OpenaiMock,
15
+ writable: true,
16
+ configurable: true,
17
+ });
18
+ // Also set on window for browser-like environment
19
+ if (typeof window !== "undefined") {
20
+ Object.defineProperty(window, "openai", {
21
+ value: OpenaiMock,
22
+ writable: true,
23
+ configurable: true,
24
+ });
25
+ }
26
+ vi.stubGlobal("openai", OpenaiMock);
27
+ });
28
+ afterEach(() => {
29
+ vi.resetAllMocks();
30
+ // Keep the mock available for React cleanup, but reset it
31
+ if (typeof window !== "undefined" && window.openai) {
32
+ window.openai.setWidgetState = vi.fn();
33
+ window.openai.widgetState = {};
34
+ }
35
+ });
36
+ it("should register a node with content and call setWidgetState", () => {
37
+ render(_jsx(DataLLM, { content: "Test content", children: _jsx("div", { children: "Child" }) }));
38
+ expect(OpenaiMock.setWidgetState).toHaveBeenCalled();
39
+ const callArgs = OpenaiMock.setWidgetState.mock.calls[0]?.[0];
40
+ expect(callArgs).toHaveProperty("__widget_context");
41
+ expect(callArgs?.__widget_context).toContain("- Test content");
42
+ });
43
+ it("should preserve existing widgetState when updating context", () => {
44
+ OpenaiMock.widgetState = { existingKey: "existingValue" };
45
+ render(_jsx(DataLLM, { content: "Test content", children: _jsx("div", { children: "Child" }) }));
46
+ const callArgs = OpenaiMock.setWidgetState.mock.calls[0]?.[0];
47
+ expect(callArgs).toHaveProperty("existingKey", "existingValue");
48
+ expect(callArgs).toHaveProperty("__widget_context");
49
+ });
50
+ it("should handle deeply nested DataLLM components", () => {
51
+ render(_jsxs(DataLLM, { content: "Level 1", children: [_jsx(DataLLM, { content: "Level 2A" }), _jsx(DataLLM, { content: "Level 2B", children: _jsx(DataLLM, { content: "Level 3", children: _jsx("div", { children: "Content" }) }) })] }));
52
+ const callArgs = OpenaiMock.setWidgetState.mock.calls[OpenaiMock.setWidgetState.mock.calls.length - 1]?.[0];
53
+ const context = callArgs?.__widget_context;
54
+ expect(context).toContain("- Level 1");
55
+ expect(context).toContain(" - Level 2A");
56
+ expect(context).toContain(" - Level 2B");
57
+ expect(context).toContain(" - Level 3");
58
+ });
59
+ it("should update context when content changes", () => {
60
+ const { rerender } = render(_jsx(DataLLM, { content: "Initial content", children: _jsx("div", { children: "Child" }) }));
61
+ const initialCalls = OpenaiMock.setWidgetState.mock.calls.length;
62
+ rerender(_jsx(DataLLM, { content: "Updated content", children: _jsx("div", { children: "Child" }) }));
63
+ expect(OpenaiMock.setWidgetState.mock.calls.length).toBeGreaterThan(initialCalls);
64
+ const lastCallArgs = OpenaiMock.setWidgetState.mock.calls[OpenaiMock.setWidgetState.mock.calls.length - 1]?.[0];
65
+ expect(lastCallArgs?.__widget_context).toContain("- Updated content");
66
+ });
67
+ it("should remove node and update context when component unmounts", () => {
68
+ const { unmount } = render(_jsx(DataLLM, { content: "Content to remove", children: _jsx("div", { children: "Child" }) }));
69
+ const callsBeforeUnmount = OpenaiMock.setWidgetState.mock.calls.length;
70
+ unmount();
71
+ expect(OpenaiMock.setWidgetState.mock.calls.length).toBeGreaterThan(callsBeforeUnmount);
72
+ const lastCallArgs = OpenaiMock.setWidgetState.mock.calls[OpenaiMock.setWidgetState.mock.calls.length - 1]?.[0];
73
+ expect(lastCallArgs?.__widget_context).not.toContain("Content to remove");
74
+ });
75
+ });
76
+ //# sourceMappingURL=data-llm.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-llm.test.js","sourceRoot":"","sources":["../../../src/web/data-llm.test.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EACL,SAAS,EACT,UAAU,EAC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AAO,EAAC,mBAAmB,YAClC,kCAAgB,GACR,CACX,CAAC;QAEF,MAAM,kBAAkB,GAAG,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;QAEvE,OAAO,EAAE,CAAC;QAEV,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,eAAe,CACjE,kBAAkB,CACnB,CAAC;QACF,MAAM,YAAY,GAChB,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAClC,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAChD,EAAE,CAAC,CAAC,CAAC,CAAC;QACT,MAAM,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,16 +1,15 @@
1
- import { type CallToolState } from "./hooks/use-call-tool.js";
1
+ import type { InferTools, ToolInput, ToolOutput, ToolResponseMetadata } from "../server/index.js";
2
+ import { type CallToolAsyncFn, type CallToolFn, type CallToolState } from "./hooks/use-call-tool.js";
2
3
  import { type ToolState } from "./hooks/use-tool-info.js";
3
- import type { McpServer, InferTools, AnyToolRegistry, ToolInput, ToolOutput } from "../server/index.js";
4
- import type { CallToolResponse, Prettify, Objectify } from "./types.js";
5
- type TypedCallToolReturn<TInput, TOutput> = Prettify<CallToolState<CallToolResponse & {
4
+ import type { CallToolResponse, Objectify, Prettify } from "./types.js";
5
+ type TypedCallToolResponse<TOutput> = CallToolResponse & {
6
6
  structuredContent: TOutput;
7
- }> & {
8
- callTool: (args: TInput) => void;
9
- callToolAsync: (args: TInput) => Promise<CallToolResponse & {
10
- structuredContent: TOutput;
11
- }>;
7
+ };
8
+ type TypedCallToolReturn<TInput, TOutput> = Prettify<CallToolState<TypedCallToolResponse<TOutput>> & {
9
+ callTool: CallToolFn<TInput, TypedCallToolResponse<TOutput>>;
10
+ callToolAsync: CallToolAsyncFn<TInput, TypedCallToolResponse<TOutput>>;
12
11
  }>;
13
- type TypedToolInfoReturn<TInput, TOutput> = ToolState<Objectify<TInput>, Objectify<TOutput>, Objectify<{}>>;
12
+ type TypedToolInfoReturn<TInput, TOutput, TResponseMetadata> = ToolState<Objectify<TInput>, Objectify<TOutput>, Objectify<TResponseMetadata>>;
14
13
  /**
15
14
  * Creates typed versions of skybridge hooks with full type inference
16
15
  * for tool names, inputs, and outputs.
@@ -18,7 +17,9 @@ type TypedToolInfoReturn<TInput, TOutput> = ToolState<Objectify<TInput>, Objecti
18
17
  * This is the recommended way to use skybridge hooks in your widgets.
19
18
  * Set this up once in a dedicated file and export the typed hooks for use across your app.
20
19
  *
21
- * @typeParam T - The type of your McpServer instance. Use `typeof server`.
20
+ * @typeParam ServerType - The type of your McpServer instance (use `typeof server`).
21
+ * Must be a server instance created with method chaining.
22
+ * TypeScript will validate that tools can be inferred from this type.
22
23
  *
23
24
  * @example
24
25
  * ```typescript
@@ -38,9 +39,9 @@ type TypedToolInfoReturn<TInput, TOutput> = ToolState<Objectify<TInput>, Objecti
38
39
  * ```typescript
39
40
  * // web/src/skybridge.ts (one-time setup)
40
41
  * import type { AppType } from "../server";
41
- * import { createTypedHooks } from "skybridge/web";
42
+ * import { generateHelpers } from "skybridge/web";
42
43
  *
43
- * export const { useCallTool, useToolInfo } = createTypedHooks<AppType>();
44
+ * export const { useCallTool, useToolInfo } = generateHelpers<AppType>();
44
45
  * ```
45
46
  *
46
47
  * @example
@@ -57,11 +58,11 @@ type TypedToolInfoReturn<TInput, TOutput> = ToolState<Objectify<TInput>, Objecti
57
58
  * const toolInfo = useToolInfo<"search-voyage">();
58
59
  * // ^ autocomplete for widget names
59
60
  * // toolInfo.input is typed based on widget input schema
60
- * // toolInfo.output is typed based on widget output schema
61
+ * // toolInfo.output.structuredContent is typed based on widget output schema
61
62
  * }
62
63
  * ```
63
64
  */
64
- export declare function createTypedHooks<T extends McpServer<AnyToolRegistry>>(): {
65
+ export declare function generateHelpers<ServerType = never>(): {
65
66
  /**
66
67
  * Typed version of `useCallTool` that provides autocomplete for tool names
67
68
  * and type inference for inputs and outputs.
@@ -81,7 +82,7 @@ export declare function createTypedHooks<T extends McpServer<AnyToolRegistry>>()
81
82
  * }
82
83
  * ```
83
84
  */
84
- useCallTool: <K extends keyof InferTools<T> & string>(name: K) => TypedCallToolReturn<InferTools<T>[K]["input"], InferTools<T>[K]["output"]>;
85
+ useCallTool: <ToolName extends keyof InferTools<ServerType> & string>(name: ToolName) => TypedCallToolReturn<ToolInput<ServerType, ToolName>, ToolOutput<ServerType, ToolName>>;
85
86
  /**
86
87
  * Typed version of `useToolInfo` that provides autocomplete for widget names
87
88
  * and type inference for inputs, outputs, and responseMetadata.
@@ -93,20 +94,22 @@ export declare function createTypedHooks<T extends McpServer<AnyToolRegistry>>()
93
94
  * ```typescript
94
95
  * const toolInfo = useToolInfo<"search-voyage">();
95
96
  * // toolInfo.input is typed as { destination: string; ... }
96
- * // toolInfo.output is typed as { results: Array<...>; ... } | undefined
97
+ * // toolInfo.output is typed as { results: Array<...>; ... }
98
+ * // toolInfo.responseMetadata is typed based on _meta in callback return
97
99
  * // toolInfo.status narrows correctly: "pending" | "success"
98
100
  *
99
101
  * if (toolInfo.isPending) {
100
- * // TypeScript knows output is undefined here
102
+ * // TypeScript knows output and responseMetadata are undefined here
101
103
  * console.log(toolInfo.input.destination);
102
104
  * }
103
105
  *
104
106
  * if (toolInfo.isSuccess) {
105
- * // TypeScript knows output is defined here
107
+ * // TypeScript knows output and responseMetadata are defined here
106
108
  * console.log(toolInfo.output.results);
109
+ * console.log(toolInfo.responseMetadata);
107
110
  * }
108
111
  * ```
109
112
  */
110
- useToolInfo: <K extends keyof InferTools<T> & string>() => TypedToolInfoReturn<ToolInput<T, K>, ToolOutput<T, K>>;
113
+ useToolInfo: <ToolName extends keyof InferTools<ServerType> & string>() => TypedToolInfoReturn<ToolInput<ServerType, ToolName>, ToolOutput<ServerType, ToolName>, ToolResponseMetadata<ServerType, ToolName>>;
111
114
  };
112
115
  export {};
@@ -1,4 +1,4 @@
1
- import { useCallTool } from "./hooks/use-call-tool.js";
1
+ import { useCallTool, } from "./hooks/use-call-tool.js";
2
2
  import { useToolInfo } from "./hooks/use-tool-info.js";
3
3
  /**
4
4
  * Creates typed versions of skybridge hooks with full type inference
@@ -7,7 +7,9 @@ import { useToolInfo } from "./hooks/use-tool-info.js";
7
7
  * This is the recommended way to use skybridge hooks in your widgets.
8
8
  * Set this up once in a dedicated file and export the typed hooks for use across your app.
9
9
  *
10
- * @typeParam T - The type of your McpServer instance. Use `typeof server`.
10
+ * @typeParam ServerType - The type of your McpServer instance (use `typeof server`).
11
+ * Must be a server instance created with method chaining.
12
+ * TypeScript will validate that tools can be inferred from this type.
11
13
  *
12
14
  * @example
13
15
  * ```typescript
@@ -27,9 +29,9 @@ import { useToolInfo } from "./hooks/use-tool-info.js";
27
29
  * ```typescript
28
30
  * // web/src/skybridge.ts (one-time setup)
29
31
  * import type { AppType } from "../server";
30
- * import { createTypedHooks } from "skybridge/web";
32
+ * import { generateHelpers } from "skybridge/web";
31
33
  *
32
- * export const { useCallTool, useToolInfo } = createTypedHooks<AppType>();
34
+ * export const { useCallTool, useToolInfo } = generateHelpers<AppType>();
33
35
  * ```
34
36
  *
35
37
  * @example
@@ -46,11 +48,11 @@ import { useToolInfo } from "./hooks/use-tool-info.js";
46
48
  * const toolInfo = useToolInfo<"search-voyage">();
47
49
  * // ^ autocomplete for widget names
48
50
  * // toolInfo.input is typed based on widget input schema
49
- * // toolInfo.output is typed based on widget output schema
51
+ * // toolInfo.output.structuredContent is typed based on widget output schema
50
52
  * }
51
53
  * ```
52
54
  */
53
- export function createTypedHooks() {
55
+ export function generateHelpers() {
54
56
  return {
55
57
  /**
56
58
  * Typed version of `useCallTool` that provides autocomplete for tool names
@@ -85,17 +87,19 @@ export function createTypedHooks() {
85
87
  * ```typescript
86
88
  * const toolInfo = useToolInfo<"search-voyage">();
87
89
  * // toolInfo.input is typed as { destination: string; ... }
88
- * // toolInfo.output is typed as { results: Array<...>; ... } | undefined
90
+ * // toolInfo.output is typed as { results: Array<...>; ... }
91
+ * // toolInfo.responseMetadata is typed based on _meta in callback return
89
92
  * // toolInfo.status narrows correctly: "pending" | "success"
90
93
  *
91
94
  * if (toolInfo.isPending) {
92
- * // TypeScript knows output is undefined here
95
+ * // TypeScript knows output and responseMetadata are undefined here
93
96
  * console.log(toolInfo.input.destination);
94
97
  * }
95
98
  *
96
99
  * if (toolInfo.isSuccess) {
97
- * // TypeScript knows output is defined here
100
+ * // TypeScript knows output and responseMetadata are defined here
98
101
  * console.log(toolInfo.output.results);
102
+ * console.log(toolInfo.responseMetadata);
99
103
  * }
100
104
  * ```
101
105
  */
@@ -104,4 +108,4 @@ export function createTypedHooks() {
104
108
  },
105
109
  };
106
110
  }
107
- //# sourceMappingURL=typed-hooks.js.map
111
+ //# sourceMappingURL=generate-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-helpers.js","sourceRoot":"","sources":["../../../src/web/generate-helpers.ts"],"names":[],"mappings":"AAMA,OAAO,EAIL,WAAW,GACZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAoBvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,MAAM,UAAU,eAAe;IAI7B,OAAO;QACL;;;;;;;;;;;;;;;;;;WAkBG;QACH,WAAW,EAAE,CACX,IAAc,EAId,EAAE;YACF,OAAO,WAAW,CAAC,IAAI,CAGtB,CAAC;QACJ,CAAC;QAED;;;;;;;;;;;;;;;;;;;;;;;;;;WA0BG;QACH,WAAW,EAAE,GAIX,EAAE;YACF,OAAO,WAAW,EAIjB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,180 @@
1
+ import { expectTypeOf, test } from "vitest";
2
+ import { createTestServer } from "../test/utils.js";
3
+ import { generateHelpers } from "./generate-helpers.js";
4
+ const server = createTestServer();
5
+ test("InferTools extracts the tool registry type (widgets + registerTool)", () => {
6
+ expectTypeOf().toHaveProperty("search-voyage");
7
+ expectTypeOf().toHaveProperty("get-trip-details");
8
+ expectTypeOf().toHaveProperty("no-input-widget");
9
+ expectTypeOf().toHaveProperty("calculate-price");
10
+ expectTypeOf().toHaveProperty("inferred-output-widget");
11
+ expectTypeOf().toHaveProperty("inferred-tool");
12
+ expectTypeOf().toHaveProperty("widget-with-metadata");
13
+ expectTypeOf().toHaveProperty("tool-with-metadata");
14
+ expectTypeOf().toHaveProperty("widget-with-mixed-returns");
15
+ });
16
+ test("ToolNames returns a union of tool name literals (widgets + registerTool)", () => {
17
+ expectTypeOf().toEqualTypeOf();
18
+ });
19
+ test("ToolInput extracts the correct input type from Zod schema", () => {
20
+ expectTypeOf().toEqualTypeOf();
21
+ expectTypeOf().toEqualTypeOf();
22
+ expectTypeOf().toEqualTypeOf();
23
+ });
24
+ test("ToolOutput extracts the correct output type from callback's structuredContent", () => {
25
+ expectTypeOf().toEqualTypeOf();
26
+ expectTypeOf().toEqualTypeOf();
27
+ expectTypeOf().toEqualTypeOf();
28
+ expectTypeOf().toEqualTypeOf();
29
+ });
30
+ test("ToolOutput extracts the correct output type from callback (inferred)", () => {
31
+ expectTypeOf().toEqualTypeOf();
32
+ expectTypeOf().toEqualTypeOf();
33
+ });
34
+ test("generateHelpers provides autocomplete for tool names (widgets + registerTool)", () => {
35
+ const { useCallTool } = generateHelpers();
36
+ useCallTool("search-voyage");
37
+ useCallTool("get-trip-details");
38
+ useCallTool("no-input-widget");
39
+ useCallTool("calculate-price");
40
+ useCallTool("inferred-output-widget");
41
+ useCallTool("inferred-tool");
42
+ useCallTool("widget-with-metadata");
43
+ useCallTool("tool-with-metadata");
44
+ useCallTool("widget-with-mixed-returns");
45
+ // @ts-expect-error - "invalid-name" is not a valid tool name
46
+ useCallTool("invalid-name");
47
+ });
48
+ test("useCallTool returns correctly typed callTool function", () => {
49
+ const { useCallTool } = generateHelpers();
50
+ const { callTool } = useCallTool("search-voyage");
51
+ callTool({ destination: "Spain" });
52
+ callTool({ destination: "France", departureDate: "2024-06-01" });
53
+ callTool({ destination: "Italy", maxPrice: 1000 });
54
+ const { callTool: calculateTool } = useCallTool("calculate-price");
55
+ calculateTool({ tripId: "123", passengers: 2 });
56
+ });
57
+ test("callTool can be called without args for tools with no required inputs", () => {
58
+ const { useCallTool } = generateHelpers();
59
+ const { callTool, callToolAsync } = useCallTool("no-input-widget");
60
+ callTool();
61
+ callTool({});
62
+ callToolAsync();
63
+ callToolAsync({});
64
+ });
65
+ test("callTool requires args for tools with required inputs", () => {
66
+ const { useCallTool } = generateHelpers();
67
+ const { callTool } = useCallTool("search-voyage");
68
+ // @ts-expect-error - "destination" is required
69
+ callTool();
70
+ // @ts-expect-error - "destination" is required
71
+ callTool({});
72
+ // This should work
73
+ callTool({ destination: "Spain" });
74
+ });
75
+ test("callTool supports sideEffects for tools with required inputs", () => {
76
+ const { useCallTool } = generateHelpers();
77
+ const { callTool } = useCallTool("search-voyage");
78
+ callTool({ destination: "Spain" }, {
79
+ onSuccess: (response, args) => {
80
+ expectTypeOf(response.structuredContent.results).toBeArray();
81
+ expectTypeOf(args.destination).toBeString();
82
+ },
83
+ onError: (error, args) => {
84
+ expectTypeOf(error).toBeUnknown();
85
+ expectTypeOf(args.destination).toBeString();
86
+ },
87
+ onSettled: (response, error, args) => {
88
+ if (response) {
89
+ expectTypeOf(response.structuredContent.totalCount).toBeNumber();
90
+ }
91
+ expectTypeOf(error).toBeUnknown();
92
+ expectTypeOf(args.destination).toBeString();
93
+ },
94
+ });
95
+ });
96
+ test("callTool supports sideEffects for tools with no required inputs", () => {
97
+ const { useCallTool } = generateHelpers();
98
+ const { callTool } = useCallTool("no-input-widget");
99
+ callTool({
100
+ onSuccess: (response) => {
101
+ expectTypeOf(response).toHaveProperty("structuredContent");
102
+ },
103
+ });
104
+ callTool({}, {
105
+ onSuccess: (response) => {
106
+ expectTypeOf(response).toHaveProperty("structuredContent");
107
+ },
108
+ });
109
+ });
110
+ test("callToolAsync returns correctly typed promise", () => {
111
+ const { useCallTool } = generateHelpers();
112
+ const { callToolAsync: searchAsync } = useCallTool("search-voyage");
113
+ const searchPromise = searchAsync({ destination: "Spain" });
114
+ expectTypeOf(searchPromise).resolves.toHaveProperty("structuredContent");
115
+ const { callToolAsync: noInputAsync } = useCallTool("no-input-widget");
116
+ const noInputPromise = noInputAsync();
117
+ expectTypeOf(noInputPromise).resolves.toHaveProperty("structuredContent");
118
+ });
119
+ test("useCallTool returns correctly typed data", () => {
120
+ const { useCallTool } = generateHelpers();
121
+ const { data } = useCallTool("search-voyage");
122
+ if (data) {
123
+ expectTypeOf(data.structuredContent).toExtend();
124
+ expectTypeOf(data.structuredContent.results).toBeArray();
125
+ expectTypeOf(data.structuredContent.totalCount).toBeNumber();
126
+ }
127
+ });
128
+ test("useCallTool returns correctly typed data for callback-inferred outputs", () => {
129
+ const { useCallTool } = generateHelpers();
130
+ const { data: widgetData } = useCallTool("inferred-output-widget");
131
+ if (widgetData) {
132
+ expectTypeOf(widgetData.structuredContent).toExtend();
133
+ }
134
+ const { data: toolData } = useCallTool("inferred-tool");
135
+ if (toolData) {
136
+ expectTypeOf(toolData.structuredContent).toExtend();
137
+ }
138
+ });
139
+ test("generateHelpers provides autocomplete for tool names in useToolInfo (widgets + registerTool)", () => {
140
+ const { useToolInfo } = generateHelpers();
141
+ useToolInfo();
142
+ useToolInfo();
143
+ useToolInfo();
144
+ useToolInfo();
145
+ useToolInfo();
146
+ useToolInfo();
147
+ useToolInfo();
148
+ useToolInfo();
149
+ useToolInfo();
150
+ // @ts-expect-error - "invalid-name" is not a valid tool name
151
+ useToolInfo();
152
+ });
153
+ test("useToolInfo infers input and output types", () => {
154
+ const { useToolInfo } = generateHelpers();
155
+ const toolInfo = useToolInfo();
156
+ expectTypeOf(toolInfo.input).toExtend();
157
+ if (toolInfo.status === "success") {
158
+ expectTypeOf(toolInfo.output).toExtend();
159
+ expectTypeOf(toolInfo.output.results).toBeArray();
160
+ expectTypeOf(toolInfo.output.totalCount).toBeNumber();
161
+ }
162
+ });
163
+ test("ToolResponseMetadata extracts _meta type from callback", () => {
164
+ expectTypeOf().toEqualTypeOf();
165
+ expectTypeOf().toEqualTypeOf();
166
+ expectTypeOf().toBeUnknown();
167
+ });
168
+ test("useToolInfo infers responseMetadata type from generateHelpers", () => {
169
+ const { useToolInfo } = generateHelpers();
170
+ const toolInfo = useToolInfo();
171
+ if (toolInfo.isSuccess) {
172
+ expectTypeOf(toolInfo.responseMetadata.requestId).toBeString();
173
+ expectTypeOf(toolInfo.responseMetadata.timestamp).toBeNumber();
174
+ expectTypeOf(toolInfo.responseMetadata.cached).toBeBoolean();
175
+ }
176
+ });
177
+ test("ToolResponseMetadata extracts _meta from mixed return paths", () => {
178
+ expectTypeOf().toEqualTypeOf();
179
+ });
180
+ //# sourceMappingURL=generate-helpers.test-d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-helpers.test-d.js","sourceRoot":"","sources":["../../../src/web/generate-helpers.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAQ5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC;AAGlC,IAAI,CAAC,qEAAqE,EAAE,GAAG,EAAE;IAG/E,YAAY,EAAS,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IACtD,YAAY,EAAS,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;IACzD,YAAY,EAAS,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAA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AAC,CAAC,UAAU,EAAE,CAAC;QAC/D,YAAY,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/D,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,6DAA6D,EAAE,GAAG,EAAE;IAOvE,YAAY,EAAa,CAAC,aAAa,EAGnC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -1,17 +1,17 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { createTypedHooks } from "./typed-hooks.js";
3
2
  import { createMinimalTestServer } from "../test/utils.js";
3
+ import { generateHelpers } from "./generate-helpers.js";
4
4
  const server = createMinimalTestServer();
5
- describe("createTypedHooks", () => {
5
+ describe("generateHelpers", () => {
6
6
  it("should return an object with useCallTool hook", () => {
7
- const hooks = createTypedHooks();
7
+ const hooks = generateHelpers();
8
8
  expect(hooks).toHaveProperty("useCallTool");
9
9
  expect(typeof hooks.useCallTool).toBe("function");
10
10
  });
11
11
  it("should return an object with useToolInfo hook", () => {
12
- const hooks = createTypedHooks();
12
+ const hooks = generateHelpers();
13
13
  expect(hooks).toHaveProperty("useToolInfo");
14
14
  expect(typeof hooks.useToolInfo).toBe("function");
15
15
  });
16
16
  });
17
- //# sourceMappingURL=typed-hooks.test.js.map
17
+ //# sourceMappingURL=generate-helpers.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-helpers.test.js","sourceRoot":"","sources":["../../../src/web/generate-helpers.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,MAAM,GAAG,uBAAuB,EAAE,CAAC;AAGzC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,KAAK,GAAG,eAAe,EAAc,CAAC;QAC5C,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,KAAK,GAAG,eAAe,EAAc,CAAC;QAC5C,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { type SuperJSONResult } from "superjson";
2
+ import type { UnknownObject } from "../types.js";
3
+ export declare function filterWidgetContext<T extends UnknownObject>(state?: T | null): T | null;
4
+ export declare function injectWidgetContext<T extends UnknownObject>(newState: T | null): T | null;
5
+ export declare function serializeState(value: UnknownObject): unknown;
6
+ export declare function deserializeState(value: SuperJSONResult): unknown;
7
+ export declare function getInitialState<State extends UnknownObject>(defaultState?: State | (() => State)): State | null;
@@ -0,0 +1,40 @@
1
+ import superjson, {} from "superjson";
2
+ import { WIDGET_CONTEXT_KEY } from "../data-llm.js";
3
+ export function filterWidgetContext(state) {
4
+ if (state === null || state === undefined) {
5
+ return null;
6
+ }
7
+ const { [WIDGET_CONTEXT_KEY]: _, ...filteredState } = state;
8
+ return filteredState;
9
+ }
10
+ export function injectWidgetContext(newState) {
11
+ if (newState === null) {
12
+ return null;
13
+ }
14
+ const currentWindowState = window.openai?.widgetState;
15
+ if (currentWindowState !== null &&
16
+ currentWindowState !== undefined &&
17
+ WIDGET_CONTEXT_KEY in currentWindowState) {
18
+ return {
19
+ ...newState,
20
+ [WIDGET_CONTEXT_KEY]: currentWindowState[WIDGET_CONTEXT_KEY],
21
+ };
22
+ }
23
+ return newState;
24
+ }
25
+ export function serializeState(value) {
26
+ return superjson.parse(superjson.stringify(value)); // Strips functions
27
+ }
28
+ export function deserializeState(value) {
29
+ return superjson.deserialize(value);
30
+ }
31
+ export function getInitialState(defaultState) {
32
+ const widgetStateFromWindow = window.openai?.widgetState;
33
+ if (widgetStateFromWindow !== null && widgetStateFromWindow !== undefined) {
34
+ return filterWidgetContext(widgetStateFromWindow);
35
+ }
36
+ return typeof defaultState === "function"
37
+ ? defaultState()
38
+ : (defaultState ?? null);
39
+ }
40
+ //# sourceMappingURL=state.js.map