skybridge 0.0.0-dev.e3e0986 → 0.0.0-dev.e41a369

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 (123) hide show
  1. package/LICENSE +21 -674
  2. package/README.md +70 -267
  3. package/dist/src/server/emulatorStaticServer.d.ts +15 -0
  4. package/dist/src/server/emulatorStaticServer.js +38 -0
  5. package/dist/src/server/emulatorStaticServer.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 +46 -15
  10. package/dist/src/server/server.d.ts +54 -11
  11. package/dist/src/server/server.js +8 -4
  12. package/dist/src/server/server.js.map +1 -1
  13. package/dist/src/server/templateHelper.js +2 -2
  14. package/dist/src/server/templateHelper.js.map +1 -1
  15. package/dist/src/server/widgetsDevServer.js +3 -3
  16. package/dist/src/server/widgetsDevServer.js.map +1 -1
  17. package/dist/src/test/utils.d.ts +97 -1
  18. package/dist/src/test/utils.js +181 -2
  19. package/dist/src/test/utils.js.map +1 -1
  20. package/dist/src/test/widget.test.js +19 -20
  21. package/dist/src/test/widget.test.js.map +1 -1
  22. package/dist/src/web/create-store.d.ts +3 -0
  23. package/dist/src/web/create-store.js +25 -0
  24. package/dist/src/web/create-store.js.map +1 -0
  25. package/dist/src/web/create-store.test.js +70 -0
  26. package/dist/src/web/create-store.test.js.map +1 -0
  27. package/dist/src/web/data-llm.d.ts +14 -0
  28. package/dist/src/web/data-llm.js +68 -0
  29. package/dist/src/web/data-llm.js.map +1 -0
  30. package/dist/src/web/data-llm.test.js +76 -0
  31. package/dist/src/web/data-llm.test.js.map +1 -0
  32. package/dist/src/web/generate-helpers.d.ts +115 -0
  33. package/dist/src/web/generate-helpers.js +111 -0
  34. package/dist/src/web/generate-helpers.js.map +1 -0
  35. package/dist/src/web/generate-helpers.test-d.d.ts +1 -0
  36. package/dist/src/web/generate-helpers.test-d.js +180 -0
  37. package/dist/src/web/generate-helpers.test-d.js.map +1 -0
  38. package/dist/src/web/generate-helpers.test.d.ts +1 -0
  39. package/dist/src/web/generate-helpers.test.js +17 -0
  40. package/dist/src/web/generate-helpers.test.js.map +1 -0
  41. package/dist/src/web/helpers/state.d.ts +7 -0
  42. package/dist/src/web/helpers/state.js +40 -0
  43. package/dist/src/web/helpers/state.js.map +1 -0
  44. package/dist/src/web/helpers/state.test.d.ts +1 -0
  45. package/dist/src/web/helpers/state.test.js +53 -0
  46. package/dist/src/web/helpers/state.test.js.map +1 -0
  47. package/dist/src/web/hooks/index.d.ts +2 -4
  48. package/dist/src/web/hooks/index.js +2 -4
  49. package/dist/src/web/hooks/index.js.map +1 -1
  50. package/dist/src/web/hooks/use-call-tool.d.ts +57 -19
  51. package/dist/src/web/hooks/use-call-tool.js +7 -15
  52. package/dist/src/web/hooks/use-call-tool.js.map +1 -1
  53. package/dist/src/web/hooks/use-call-tool.test-d.d.ts +1 -0
  54. package/dist/src/web/hooks/use-call-tool.test-d.js +104 -0
  55. package/dist/src/web/hooks/use-call-tool.test-d.js.map +1 -0
  56. package/dist/src/web/hooks/use-call-tool.test.js +18 -10
  57. package/dist/src/web/hooks/use-call-tool.test.js.map +1 -1
  58. package/dist/src/web/hooks/use-display-mode.js.map +1 -1
  59. package/dist/src/web/hooks/use-display-mode.test.js +2 -2
  60. package/dist/src/web/hooks/use-display-mode.test.js.map +1 -1
  61. package/dist/src/web/hooks/use-files.test.js +1 -1
  62. package/dist/src/web/hooks/use-files.test.js.map +1 -1
  63. package/dist/src/web/hooks/use-locale.test.js +2 -2
  64. package/dist/src/web/hooks/use-locale.test.js.map +1 -1
  65. package/dist/src/web/hooks/use-open-external.test.js +2 -2
  66. package/dist/src/web/hooks/use-open-external.test.js.map +1 -1
  67. package/dist/src/web/hooks/use-openai-global.d.ts +2 -2
  68. package/dist/src/web/hooks/use-openai-global.js +1 -1
  69. package/dist/src/web/hooks/use-openai-global.js.map +1 -1
  70. package/dist/src/web/hooks/use-request-modal.test.js +2 -2
  71. package/dist/src/web/hooks/use-request-modal.test.js.map +1 -1
  72. package/dist/src/web/hooks/use-theme.test.js +2 -2
  73. package/dist/src/web/hooks/use-theme.test.js.map +1 -1
  74. package/dist/src/web/hooks/use-tool-info.d.ts +1 -1
  75. package/dist/src/web/hooks/use-tool-info.js +1 -1
  76. package/dist/src/web/hooks/use-tool-info.js.map +1 -1
  77. package/dist/src/web/hooks/use-tool-info.test-d.js +0 -1
  78. package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -1
  79. package/dist/src/web/hooks/use-tool-info.test.js +2 -2
  80. package/dist/src/web/hooks/use-tool-info.test.js.map +1 -1
  81. package/dist/src/web/hooks/use-user-agent.test.js +2 -2
  82. package/dist/src/web/hooks/use-user-agent.test.js.map +1 -1
  83. package/dist/src/web/hooks/use-widget-state.js +9 -7
  84. package/dist/src/web/hooks/use-widget-state.js.map +1 -1
  85. package/dist/src/web/hooks/use-widget-state.test.js +2 -2
  86. package/dist/src/web/hooks/use-widget-state.test.js.map +1 -1
  87. package/dist/src/web/index.d.ts +6 -4
  88. package/dist/src/web/index.js +6 -4
  89. package/dist/src/web/index.js.map +1 -1
  90. package/dist/src/web/plugin/data-llm.test.d.ts +1 -0
  91. package/dist/src/web/plugin/data-llm.test.js +81 -0
  92. package/dist/src/web/plugin/data-llm.test.js.map +1 -0
  93. package/dist/src/web/{plugin.js → plugin/plugin.js} +5 -0
  94. package/dist/src/web/plugin/plugin.js.map +1 -0
  95. package/dist/src/web/plugin/transform-data-llm.d.ts +12 -0
  96. package/dist/src/web/plugin/transform-data-llm.js +93 -0
  97. package/dist/src/web/plugin/transform-data-llm.js.map +1 -0
  98. package/dist/src/web/plugin/transform-data-llm.test.d.ts +1 -0
  99. package/dist/src/web/plugin/transform-data-llm.test.js +81 -0
  100. package/dist/src/web/plugin/transform-data-llm.test.js.map +1 -0
  101. package/dist/src/web/proxy.js +1 -1
  102. package/dist/src/web/proxy.js.map +1 -1
  103. package/dist/src/web/types.d.ts +18 -4
  104. package/dist/src/web/types.js +1 -0
  105. package/dist/src/web/types.js.map +1 -1
  106. package/package.json +14 -6
  107. package/dist/src/web/hooks/use-tool-output.d.ts +0 -4
  108. package/dist/src/web/hooks/use-tool-output.js +0 -9
  109. package/dist/src/web/hooks/use-tool-output.js.map +0 -1
  110. package/dist/src/web/hooks/use-tool-response-metadata.d.ts +0 -4
  111. package/dist/src/web/hooks/use-tool-response-metadata.js +0 -8
  112. package/dist/src/web/hooks/use-tool-response-metadata.js.map +0 -1
  113. package/dist/src/web/plugin.js.map +0 -1
  114. package/dist/src/web/typed-hooks.d.ts +0 -61
  115. package/dist/src/web/typed-hooks.js +0 -61
  116. package/dist/src/web/typed-hooks.js.map +0 -1
  117. package/dist/src/web/typed-hooks.test-d.js +0 -72
  118. package/dist/src/web/typed-hooks.test-d.js.map +0 -1
  119. package/dist/src/web/typed-hooks.test.js +0 -10
  120. package/dist/src/web/typed-hooks.test.js.map +0 -1
  121. /package/dist/src/web/{typed-hooks.test-d.d.ts → create-store.test.d.ts} +0 -0
  122. /package/dist/src/web/{typed-hooks.test.d.ts → data-llm.test.d.ts} +0 -0
  123. /package/dist/src/web/{plugin.d.ts → plugin/plugin.d.ts} +0 -0
@@ -1,4 +1,18 @@
1
+ import "react";
2
+ declare module "react" {
3
+ interface HTMLAttributes<T> {
4
+ "data-llm"?: string;
5
+ }
6
+ }
1
7
  export type UnknownObject = Record<string, unknown>;
8
+ export type Prettify<T> = {
9
+ [K in keyof T]: T[K];
10
+ } & {};
11
+ export type Objectify<T> = T & UnknownObject;
12
+ type RequiredKeys<T> = {
13
+ [K in keyof T]-?: {} extends Pick<T, K> ? never : K;
14
+ }[keyof T];
15
+ export type HasRequiredKeys<T> = RequiredKeys<T> extends never ? false : true;
2
16
  type WidgetState = UnknownObject;
3
17
  type FileMetadata = {
4
18
  fileId: string;
@@ -14,13 +28,13 @@ export declare class ToolResponseEvent extends CustomEvent<{
14
28
  }
15
29
  declare global {
16
30
  interface Window {
17
- openai: API<WidgetState> & OpenAiGlobals;
31
+ openai: OpenAiMethods<WidgetState> & OpenAiProperties;
18
32
  }
19
33
  interface WindowEventMap {
20
34
  [SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;
21
35
  }
22
36
  }
23
- export type OpenAiGlobals<ToolInput extends UnknownObject = {}, ToolOutput extends UnknownObject = UnknownObject, ToolResponseMetadata extends UnknownObject = UnknownObject, WidgetState extends UnknownObject = UnknownObject> = {
37
+ export type OpenAiProperties<ToolInput extends UnknownObject = {}, ToolOutput extends UnknownObject = UnknownObject, ToolResponseMetadata extends UnknownObject = UnknownObject, WidgetState extends UnknownObject = UnknownObject> = {
24
38
  theme: Theme;
25
39
  userAgent: UserAgent;
26
40
  locale: string;
@@ -45,7 +59,7 @@ export type CallToolResponse = {
45
59
  result: string;
46
60
  meta: Record<string, unknown>;
47
61
  };
48
- type API<WidgetState extends UnknownObject> = {
62
+ export type OpenAiMethods<WidgetState extends UnknownObject = UnknownObject> = {
49
63
  /** Calls a tool on your MCP. Returns the full response. */
50
64
  callTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
51
65
  /** Triggers a followup turn in the ChatGPT conversation */
@@ -90,7 +104,7 @@ type API<WidgetState extends UnknownObject> = {
90
104
  };
91
105
  export declare const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
92
106
  export declare class SetGlobalsEvent extends CustomEvent<{
93
- globals: Partial<OpenAiGlobals>;
107
+ globals: Partial<OpenAiProperties>;
94
108
  }> {
95
109
  readonly type = "openai:set_globals";
96
110
  }
@@ -1,3 +1,4 @@
1
+ import "react";
1
2
  export const TOOL_RESPONSE_EVENT_TYPE = "openai:tool_response";
2
3
  export class ToolResponseEvent extends CustomEvent {
3
4
  type = TOOL_RESPONSE_EVENT_TYPE;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/types.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAC/D,MAAM,OAAO,iBAAkB,SAAQ,WAErC;IACkB,IAAI,GAAG,wBAAwB,CAAC;CACnD;AA8FD,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAC3D,MAAM,OAAO,eAAgB,SAAQ,WAEnC;IACkB,IAAI,GAAG,sBAAsB,CAAC;CACjD"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/types.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,CAAC;AAuBf,MAAM,CAAC,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAC/D,MAAM,OAAO,iBAAkB,SAAQ,WAErC;IACkB,IAAI,GAAG,wBAAwB,CAAC;CACnD;AA8FD,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAC3D,MAAM,OAAO,eAAgB,SAAQ,WAEnC;IACkB,IAAI,GAAG,sBAAsB,CAAC;CACjD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skybridge",
3
- "version": "0.0.0-dev.e3e0986",
3
+ "version": "0.0.0-dev.e41a369",
4
4
  "description": "Skybridge is a framework for building ChatGPT apps",
5
5
  "type": "module",
6
6
  "files": [
@@ -19,9 +19,11 @@
19
19
  "scripts": {
20
20
  "build": "tsc && pnpm run build:templates",
21
21
  "build:templates": "cp -r src/server/templates dist/src/server/",
22
- "test": "pnpm run test:unit && pnpm run test:type",
23
- "test:unit": "vitest run --silent",
22
+ "format": "biome check --write",
23
+ "test": "pnpm run test:unit && pnpm run test:type && pnpm run test:format",
24
+ "test:unit": "vitest run",
24
25
  "test:type": "tsc --noEmit",
26
+ "test:format": "biome check",
25
27
  "docs:dev": "pnpm --filter @skybridge/docs start",
26
28
  "docs:build": "pnpm --filter @skybridge/docs build",
27
29
  "docs:serve": "pnpm --filter @skybridge/docs serve"
@@ -35,21 +37,26 @@
35
37
  "author": "Frédéric Barthelet",
36
38
  "license": "ISC",
37
39
  "peerDependencies": {
40
+ "@modelcontextprotocol/sdk": ">=1.0.0",
38
41
  "react": ">=18.0.0",
39
42
  "react-dom": ">=18.0.0"
40
43
  },
41
44
  "dependencies": {
42
- "@modelcontextprotocol/sdk": "^1.20.0",
45
+ "@babel/core": "^7.28.5",
43
46
  "cors": "^2.8.5",
44
47
  "express": "^5.1.0",
45
48
  "handlebars": "^4.7.8",
49
+ "superjson": "^2.2.6",
46
50
  "vite": "^7.1.11",
47
- "zod": "^3.25.51"
51
+ "zustand": "^5.0.9"
48
52
  },
49
53
  "devDependencies": {
54
+ "@biomejs/biome": "2.3.8",
55
+ "@modelcontextprotocol/sdk": "^1.24.3",
50
56
  "@testing-library/dom": "^10.4.1",
51
57
  "@testing-library/react": "^16.3.0",
52
58
  "@total-typescript/tsconfig": "^1.0.4",
59
+ "@types/babel__core": "^7.20.5",
53
60
  "@types/cors": "^2.8.19",
54
61
  "@types/express": "^5.0.3",
55
62
  "@types/jsdom": "^21.1.6",
@@ -59,7 +66,8 @@
59
66
  "@vitest/ui": "^2.1.8",
60
67
  "jsdom": "^25.0.1",
61
68
  "typescript": "^5.9.3",
62
- "vitest": "^2.1.8"
69
+ "vitest": "^2.1.8",
70
+ "zod": "^4.1.13"
63
71
  },
64
72
  "packageManager": "pnpm@10.17.1"
65
73
  }
@@ -1,4 +0,0 @@
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;
@@ -1,9 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-tool-output.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-tool-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;IAEjC,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,4 +0,0 @@
1
- /**
2
- * @deprecated This hook is deprecated. Use `useToolInfo()` instead and access the `responseMetadata` property.
3
- */
4
- export declare function useToolResponseMetadata(): import("../types.js").UnknownObject | null | undefined;
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/web/plugin.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,SAAS;IACvB,OAAO;QACL,IAAI,EAAE,WAAW;QAEjB,KAAK,CAAC,MAAM,CAAC,MAAM;YACjB,4EAA4E;YAC5E,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;YAC7C,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;YAE9C,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;YACjD,MAAM,cAAc,GAAG,OAAO,CAC5B,WAAW,EACX,oCAAoC,CACrC,CAAC;YAEF,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAC9B,QAAQ,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;gBACrC,IAAI,CAAC,KAAK,CAAC,0BAA0B,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC3C,IAAI;aACL,CAAC,CACH,CAAC;YAEF,OAAO;gBACL,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE;oBACL,QAAQ,EAAE,IAAI;oBACd,MAAM,EAAE,IAAI;oBACZ,YAAY,EAAE,KAAK;oBACnB,aAAa,EAAE;wBACb,KAAK;qBACN;iBACF;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,61 +0,0 @@
1
- import { useCallTool } from "./hooks/use-call-tool.js";
2
- import type { ToolPendingState, ToolSuccessState } from "./hooks/use-tool-info.js";
3
- import type { McpServer, InferWidgets, AnyWidgetRegistry, WidgetInput, WidgetOutput } from "../server/index.js";
4
- import type { CallToolArgs, UnknownObject } from "./types.js";
5
- type TypedCallToolReturn<TInput, TOutput> = ReturnType<typeof useCallTool<TInput & CallToolArgs, {
6
- structuredContent: TOutput & UnknownObject;
7
- }>>;
8
- type TypedToolInfoReturn<TInput extends UnknownObject, TOutput extends UnknownObject, TResponseMetadata extends UnknownObject> = ToolPendingState<TInput> | ToolSuccessState<TInput, TOutput, TResponseMetadata>;
9
- /**
10
- * Creates typed versions of skybridge hooks with full type inference
11
- * for tool names, inputs, and outputs.
12
- *
13
- * Set this up once in a dedicated file and export the typed hooks:
14
- *
15
- * @example
16
- * ```typescript
17
- * // web/src/skybridge.ts (one-time setup)
18
- * import type { AppType } from "../server";
19
- * import { createTypedHooks } from "skybridge/web";
20
- *
21
- * export const { useCallTool, useToolInfo } = createTypedHooks<AppType>();
22
- * ```
23
- *
24
- * ```typescript
25
- * // web/src/widgets/search.tsx (usage)
26
- * import { useCallTool, useToolInfo } from "../skybridge";
27
- *
28
- * export function SearchWidget() {
29
- * const { callTool, data } = useCallTool("search");
30
- * // ^ autocomplete for tool names
31
- * callTool({ query: "test" });
32
- * // ^ autocomplete for input fields
33
- *
34
- * const toolInfo = useToolInfo<"search">();
35
- * // ^ autocomplete for tool names
36
- * // toolInfo.input is typed based on widget input schema
37
- * // toolInfo.output is typed based on widget output schema
38
- * }
39
- * ```
40
- */
41
- export declare function createTypedHooks<T extends McpServer<AnyWidgetRegistry>>(): {
42
- /**
43
- * Typed version of useCallTool that provides autocomplete for tool names
44
- * and type inference for inputs and outputs.
45
- */
46
- useCallTool: <K extends keyof InferWidgets<T> & string>(name: K) => TypedCallToolReturn<InferWidgets<T>[K]["input"], InferWidgets<T>[K]["output"]>;
47
- /**
48
- * Typed version of useToolInfo that provides autocomplete for widget names
49
- * and type inference for inputs, outputs, and responseMetadata.
50
- *
51
- * @example
52
- * ```typescript
53
- * const toolInfo = useToolInfo<"search-voyage">();
54
- * // toolInfo.input is typed as { destination: string; ... }
55
- * // toolInfo.output is typed as { results: Array<...>; ... } | undefined
56
- * // toolInfo.status narrows correctly: "pending" | "success"
57
- * ```
58
- */
59
- useToolInfo: <K extends keyof InferWidgets<T> & string>() => TypedToolInfoReturn<WidgetInput<T, K> & UnknownObject, WidgetOutput<T, K> & UnknownObject, UnknownObject>;
60
- };
61
- export {};
@@ -1,61 +0,0 @@
1
- import { useCallTool } from "./hooks/use-call-tool.js";
2
- import { useToolInfo } from "./hooks/use-tool-info.js";
3
- /**
4
- * Creates typed versions of skybridge hooks with full type inference
5
- * for tool names, inputs, and outputs.
6
- *
7
- * Set this up once in a dedicated file and export the typed hooks:
8
- *
9
- * @example
10
- * ```typescript
11
- * // web/src/skybridge.ts (one-time setup)
12
- * import type { AppType } from "../server";
13
- * import { createTypedHooks } from "skybridge/web";
14
- *
15
- * export const { useCallTool, useToolInfo } = createTypedHooks<AppType>();
16
- * ```
17
- *
18
- * ```typescript
19
- * // web/src/widgets/search.tsx (usage)
20
- * import { useCallTool, useToolInfo } from "../skybridge";
21
- *
22
- * export function SearchWidget() {
23
- * const { callTool, data } = useCallTool("search");
24
- * // ^ autocomplete for tool names
25
- * callTool({ query: "test" });
26
- * // ^ autocomplete for input fields
27
- *
28
- * const toolInfo = useToolInfo<"search">();
29
- * // ^ autocomplete for tool names
30
- * // toolInfo.input is typed based on widget input schema
31
- * // toolInfo.output is typed based on widget output schema
32
- * }
33
- * ```
34
- */
35
- export function createTypedHooks() {
36
- return {
37
- /**
38
- * Typed version of useCallTool that provides autocomplete for tool names
39
- * and type inference for inputs and outputs.
40
- */
41
- useCallTool: (name) => {
42
- return useCallTool(name);
43
- },
44
- /**
45
- * Typed version of useToolInfo that provides autocomplete for widget names
46
- * and type inference for inputs, outputs, and responseMetadata.
47
- *
48
- * @example
49
- * ```typescript
50
- * const toolInfo = useToolInfo<"search-voyage">();
51
- * // toolInfo.input is typed as { destination: string; ... }
52
- * // toolInfo.output is typed as { results: Array<...>; ... } | undefined
53
- * // toolInfo.status narrows correctly: "pending" | "success"
54
- * ```
55
- */
56
- useToolInfo: () => {
57
- return useToolInfo();
58
- },
59
- };
60
- }
61
- //# sourceMappingURL=typed-hooks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"typed-hooks.js","sourceRoot":"","sources":["../../../src/web/typed-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAgCvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,gBAAgB;IAI9B,OAAO;QACL;;;WAGG;QACH,WAAW,EAAE,CACX,IAAO,EAIP,EAAE;YACF,OAAO,WAAW,CAGhB,IAAI,CAGL,CAAC;QACJ,CAAC;QACD;;;;;;;;;;;WAWG;QACH,WAAW,EAAE,GAIX,EAAE;YACF,OAAO,WAAW,EAQjB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,72 +0,0 @@
1
- import { expectTypeOf, test } from "vitest";
2
- import { createTypedHooks } from "./typed-hooks.js";
3
- test("InferWidgets extracts the widget registry type", () => {
4
- expectTypeOf().toHaveProperty("search-voyage");
5
- expectTypeOf().toHaveProperty("get-trip-details");
6
- expectTypeOf().toHaveProperty("no-input-widget");
7
- });
8
- test("WidgetNames returns a union of widget name literals", () => {
9
- expectTypeOf().toEqualTypeOf();
10
- });
11
- test("WidgetInput extracts the correct input type from Zod schema", () => {
12
- expectTypeOf().toEqualTypeOf();
13
- expectTypeOf().toEqualTypeOf();
14
- });
15
- test("WidgetOutput extracts the correct output type from Zod schema", () => {
16
- expectTypeOf().toEqualTypeOf();
17
- expectTypeOf().toEqualTypeOf();
18
- });
19
- test("createTypedHooks provides autocomplete for widget names", () => {
20
- const { useCallTool } = createTypedHooks();
21
- useCallTool("search-voyage");
22
- useCallTool("get-trip-details");
23
- useCallTool("no-input-widget");
24
- // @ts-expect-error - "invalid-name" is not a valid widget name
25
- useCallTool("invalid-name");
26
- });
27
- test("useCallTool returns correctly typed callTool function", () => {
28
- const { useCallTool } = createTypedHooks();
29
- const { callTool } = useCallTool("search-voyage");
30
- callTool({ destination: "Spain" });
31
- callTool({ destination: "France", departureDate: "2024-06-01" });
32
- callTool({ destination: "Italy", maxPrice: 1000 });
33
- });
34
- test("useCallTool returns correctly typed data", () => {
35
- const { useCallTool } = createTypedHooks();
36
- const { data } = useCallTool("search-voyage");
37
- if (data) {
38
- expectTypeOf(data.structuredContent).toExtend();
39
- expectTypeOf(data.structuredContent.results).toBeArray();
40
- expectTypeOf(data.structuredContent.totalCount).toBeNumber();
41
- }
42
- });
43
- test("widgets with no outputSchema have empty object output type", () => {
44
- expectTypeOf().toEqualTypeOf();
45
- });
46
- test("createTypedHooks provides autocomplete for widget names in useToolInfo", () => {
47
- const { useToolInfo } = createTypedHooks();
48
- useToolInfo();
49
- useToolInfo();
50
- useToolInfo();
51
- // @ts-expect-error - "invalid-name" is not a valid widget name
52
- useToolInfo();
53
- });
54
- test("useToolInfo infers input types from WidgetInput utility", () => {
55
- const { useToolInfo } = createTypedHooks();
56
- const toolInfo = useToolInfo();
57
- expectTypeOf(toolInfo.input).toExtend();
58
- const detailsInfo = useToolInfo();
59
- expectTypeOf(detailsInfo.input).toExtend();
60
- });
61
- test("useToolInfo infers output types from WidgetOutput utility", () => {
62
- const { useToolInfo } = createTypedHooks();
63
- const toolInfo = useToolInfo();
64
- if (toolInfo.status === "success") {
65
- expectTypeOf(toolInfo.output).toExtend();
66
- }
67
- const detailsInfo = useToolInfo();
68
- if (detailsInfo.status === "success") {
69
- expectTypeOf(detailsInfo.output).toExtend();
70
- }
71
- });
72
- //# sourceMappingURL=typed-hooks.test-d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"typed-hooks.test-d.js","sourceRoot":"","sources":["../../../src/web/typed-hooks.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAuCpD,IAAI,CAAC,gDAAgD,EAAE,GAAG,EAAE;IAG1D,YAAY,EAAW,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IACxD,YAAY,EAAW,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;IAC3D,YAAY,EAAW,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;AAC5D,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,qDAAqD,EAAE,GAAG,EAAE;IAG/D,YAAY,EAAS,CAAC,aAAa,EAEhC,CAAC;AACN,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,6DAA6D,EAAE,GAAG,EAAE;IAGvE,YAAY,EAAe,CA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AAsB,CAAC;IAEtD,IAAI,WAAW,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACrC,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAyB,CAAC;IACrE,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -1,10 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { createTypedHooks } from "./typed-hooks.js";
3
- describe("createTypedHooks", () => {
4
- it("should return an object with useCallTool hook", () => {
5
- const hooks = createTypedHooks();
6
- expect(hooks).toHaveProperty("useCallTool");
7
- expect(typeof hooks.useCallTool).toBe("function");
8
- });
9
- });
10
- //# sourceMappingURL=typed-hooks.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"typed-hooks.test.js","sourceRoot":"","sources":["../../../src/web/typed-hooks.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAYpD,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,KAAK,GAAG,gBAAgB,EAAc,CAAC;QAC7C,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"}