@apollo/client-ai-apps 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/CODEOWNERS +1 -0
- package/.github/workflows/pr.yaml +23 -1
- package/.github/workflows/release.yaml +1 -5
- package/.github/workflows/verify-changeset.yml +112 -21
- package/CHANGELOG.md +361 -0
- package/__mocks__/fs/promises.cjs +3 -0
- package/__mocks__/fs.cjs +3 -0
- package/dist/config/defineConfig.d.ts +28 -0
- package/dist/config/defineConfig.d.ts.map +1 -0
- package/dist/config/defineConfig.js +7 -0
- package/dist/config/defineConfig.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/schema.d.ts +29 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +51 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/types.d.ts +7 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +2 -0
- package/dist/config/types.js.map +1 -0
- package/dist/core/ApolloClient.d.ts +4 -3
- package/dist/core/ApolloClient.d.ts.map +1 -1
- package/dist/core/ApolloClient.js +6 -59
- package/dist/core/ApolloClient.js.map +1 -1
- package/dist/core/Platform.d.ts +8 -0
- package/dist/core/Platform.d.ts.map +1 -0
- package/dist/core/Platform.js +20 -0
- package/dist/core/Platform.js.map +1 -0
- package/dist/core/types.d.ts +13 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +1 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mcp.d.ts +5 -0
- package/dist/index.mcp.d.ts.map +1 -0
- package/dist/index.mcp.js +5 -0
- package/dist/index.mcp.js.map +1 -0
- package/dist/index.openai.d.ts +5 -0
- package/dist/index.openai.d.ts.map +1 -0
- package/dist/index.openai.js +5 -0
- package/dist/index.openai.js.map +1 -0
- package/dist/link/ToolCallLink.d.ts +3 -3
- package/dist/link/ToolCallLink.d.ts.map +1 -1
- package/dist/link/ToolCallLink.js +5 -14
- package/dist/link/ToolCallLink.js.map +1 -1
- package/dist/mcp/core/ApolloClient.d.ts +21 -0
- package/dist/mcp/core/ApolloClient.d.ts.map +1 -0
- package/dist/mcp/core/ApolloClient.js +65 -0
- package/dist/mcp/core/ApolloClient.js.map +1 -0
- package/dist/mcp/core/McpAppManager.d.ts +34 -0
- package/dist/mcp/core/McpAppManager.d.ts.map +1 -0
- package/dist/mcp/core/McpAppManager.js +63 -0
- package/dist/mcp/core/McpAppManager.js.map +1 -0
- package/dist/mcp/core/Platform.d.ts +8 -0
- package/dist/mcp/core/Platform.d.ts.map +1 -0
- package/dist/mcp/core/Platform.js +8 -0
- package/dist/mcp/core/Platform.js.map +1 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/link/ToolCallLink.d.ts +28 -0
- package/dist/mcp/link/ToolCallLink.d.ts.map +1 -0
- package/dist/mcp/link/ToolCallLink.js +35 -0
- package/dist/mcp/link/ToolCallLink.js.map +1 -0
- package/dist/mcp/react/hooks/useApolloClient.d.ts +3 -0
- package/dist/mcp/react/hooks/useApolloClient.d.ts.map +1 -0
- package/dist/mcp/react/hooks/useApolloClient.js +9 -0
- package/dist/mcp/react/hooks/useApolloClient.js.map +1 -0
- package/dist/mcp/react/hooks/useApp.d.ts +2 -0
- package/dist/mcp/react/hooks/useApp.d.ts.map +1 -0
- package/dist/mcp/react/hooks/useApp.js +5 -0
- package/dist/mcp/react/hooks/useApp.js.map +1 -0
- package/dist/mcp/react/hooks/useToolInput.d.ts +2 -0
- package/dist/mcp/react/hooks/useToolInput.d.ts.map +1 -0
- package/dist/mcp/react/hooks/useToolInput.js +5 -0
- package/dist/mcp/react/hooks/useToolInput.js.map +1 -0
- package/dist/mcp/react/hooks/useToolMetadata.d.ts +8 -0
- package/dist/mcp/react/hooks/useToolMetadata.d.ts.map +1 -0
- package/dist/mcp/react/hooks/useToolMetadata.js +5 -0
- package/dist/mcp/react/hooks/useToolMetadata.js.map +1 -0
- package/dist/mcp/react/hooks/useToolName.d.ts +2 -0
- package/dist/mcp/react/hooks/useToolName.d.ts.map +1 -0
- package/dist/mcp/react/hooks/useToolName.js +5 -0
- package/dist/mcp/react/hooks/useToolName.js.map +1 -0
- package/dist/mcp/react/index.d.ts +5 -0
- package/dist/mcp/react/index.d.ts.map +1 -0
- package/dist/mcp/react/index.js +5 -0
- package/dist/mcp/react/index.js.map +1 -0
- package/dist/openai/core/ApolloClient.d.ts +21 -0
- package/dist/openai/core/ApolloClient.d.ts.map +1 -0
- package/dist/openai/core/ApolloClient.js +66 -0
- package/dist/openai/core/ApolloClient.js.map +1 -0
- package/dist/openai/core/McpAppManager.d.ts +28 -0
- package/dist/openai/core/McpAppManager.d.ts.map +1 -0
- package/dist/openai/core/McpAppManager.js +73 -0
- package/dist/openai/core/McpAppManager.js.map +1 -0
- package/dist/openai/core/Platform.d.ts +8 -0
- package/dist/openai/core/Platform.d.ts.map +1 -0
- package/dist/openai/core/Platform.js +8 -0
- package/dist/openai/core/Platform.js.map +1 -0
- package/dist/openai/globals.d.ts +12 -0
- package/dist/openai/globals.d.ts.map +1 -0
- package/dist/openai/globals.js +2 -0
- package/dist/openai/globals.js.map +1 -0
- package/dist/openai/index.d.ts +3 -0
- package/dist/openai/index.d.ts.map +1 -0
- package/dist/openai/index.js +3 -0
- package/dist/openai/index.js.map +1 -0
- package/dist/openai/link/ToolCallLink.d.ts +28 -0
- package/dist/openai/link/ToolCallLink.d.ts.map +1 -0
- package/dist/openai/link/ToolCallLink.js +35 -0
- package/dist/openai/link/ToolCallLink.js.map +1 -0
- package/dist/openai/react/hooks/useApolloClient.d.ts +3 -0
- package/dist/openai/react/hooks/useApolloClient.d.ts.map +1 -0
- package/dist/openai/react/hooks/useApolloClient.js +9 -0
- package/dist/openai/react/hooks/useApolloClient.js.map +1 -0
- package/dist/openai/react/hooks/useApp.d.ts +2 -0
- package/dist/openai/react/hooks/useApp.d.ts.map +1 -0
- package/dist/openai/react/hooks/useApp.js +5 -0
- package/dist/openai/react/hooks/useApp.js.map +1 -0
- package/dist/openai/react/hooks/useOpenAiGlobal.d.ts +3 -0
- package/dist/openai/react/hooks/useOpenAiGlobal.d.ts.map +1 -0
- package/dist/{react → openai/react}/hooks/useOpenAiGlobal.js +1 -1
- package/dist/openai/react/hooks/useOpenAiGlobal.js.map +1 -0
- package/dist/openai/react/hooks/useToolInput.d.ts +2 -0
- package/dist/openai/react/hooks/useToolInput.d.ts.map +1 -0
- package/dist/openai/react/hooks/useToolInput.js +5 -0
- package/dist/openai/react/hooks/useToolInput.js.map +1 -0
- package/dist/openai/react/hooks/useToolMetadata.d.ts +2 -0
- package/dist/openai/react/hooks/useToolMetadata.d.ts.map +1 -0
- package/dist/openai/react/hooks/useToolMetadata.js +5 -0
- package/dist/openai/react/hooks/useToolMetadata.js.map +1 -0
- package/dist/openai/react/hooks/useToolName.d.ts.map +1 -0
- package/dist/openai/react/hooks/useToolName.js +5 -0
- package/dist/openai/react/hooks/useToolName.js.map +1 -0
- package/dist/{react → openai/react}/hooks/useWidgetState.d.ts +1 -1
- package/dist/openai/react/hooks/useWidgetState.d.ts.map +1 -0
- package/dist/openai/react/hooks/useWidgetState.js.map +1 -0
- package/dist/openai/react/index.d.ts +6 -0
- package/dist/openai/react/index.d.ts.map +1 -0
- package/dist/openai/react/index.js +6 -0
- package/dist/openai/react/index.js.map +1 -0
- package/dist/{types/openai.d.ts → openai/types.d.ts} +7 -11
- package/dist/openai/types.d.ts.map +1 -0
- package/dist/{types/openai.js → openai/types.js} +1 -1
- package/dist/openai/types.js.map +1 -0
- package/dist/react/ApolloProvider.d.ts +6 -2
- package/dist/react/ApolloProvider.d.ts.map +1 -1
- package/dist/react/ApolloProvider.js +12 -27
- package/dist/react/ApolloProvider.js.map +1 -1
- package/dist/react/index.d.ts +6 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +9 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mcp.d.ts +3 -0
- package/dist/react/index.mcp.d.ts.map +1 -0
- package/dist/react/index.mcp.js +3 -0
- package/dist/react/index.mcp.js.map +1 -0
- package/dist/react/index.openai.d.ts +3 -0
- package/dist/react/index.openai.d.ts.map +1 -0
- package/dist/react/index.openai.js +3 -0
- package/dist/react/index.openai.js.map +1 -0
- package/dist/react/missingHook.d.ts +2 -0
- package/dist/react/missingHook.d.ts.map +1 -0
- package/dist/react/missingHook.js +6 -0
- package/dist/react/missingHook.js.map +1 -0
- package/dist/tsconfig/core/tsconfig.json +5 -0
- package/dist/tsconfig/mcp/tsconfig.json +6 -0
- package/dist/tsconfig/openai/tsconfig.json +7 -0
- package/dist/types/application-manifest.d.ts +5 -1
- package/dist/types/application-manifest.d.ts.map +1 -1
- package/dist/types/application-manifest.js.map +1 -1
- package/dist/utilities/cacheAsync.d.ts +4 -0
- package/dist/utilities/cacheAsync.d.ts.map +1 -0
- package/dist/utilities/cacheAsync.js +19 -0
- package/dist/utilities/cacheAsync.js.map +1 -0
- package/dist/utilities/constants.d.ts +6 -0
- package/dist/utilities/constants.d.ts.map +1 -0
- package/dist/utilities/constants.js +6 -0
- package/dist/utilities/constants.js.map +1 -0
- package/dist/utilities/emptyModule.d.ts +2 -0
- package/dist/utilities/emptyModule.d.ts.map +1 -0
- package/dist/utilities/emptyModule.js +2 -0
- package/dist/utilities/emptyModule.js.map +1 -0
- package/dist/utilities/getVariablesForOperationFromToolInput.d.ts +5 -0
- package/dist/utilities/getVariablesForOperationFromToolInput.d.ts.map +1 -0
- package/dist/utilities/getVariablesForOperationFromToolInput.js +18 -0
- package/dist/utilities/getVariablesForOperationFromToolInput.js.map +1 -0
- package/dist/utilities/index.d.ts +6 -0
- package/dist/utilities/index.d.ts.map +1 -0
- package/dist/utilities/index.js +6 -0
- package/dist/utilities/index.js.map +1 -0
- package/dist/utilities/invariant.d.ts +2 -0
- package/dist/utilities/invariant.d.ts.map +1 -0
- package/dist/utilities/invariant.js +6 -0
- package/dist/utilities/invariant.js.map +1 -0
- package/dist/utilities/promiseWithResolvers.d.ts +7 -0
- package/dist/utilities/promiseWithResolvers.d.ts.map +1 -0
- package/dist/utilities/promiseWithResolvers.js +16 -0
- package/dist/utilities/promiseWithResolvers.js.map +1 -0
- package/dist/vite/__tests__/utilities/build.d.ts +41 -0
- package/dist/vite/__tests__/utilities/build.d.ts.map +1 -0
- package/dist/vite/__tests__/utilities/build.js +63 -0
- package/dist/vite/__tests__/utilities/build.js.map +1 -0
- package/dist/vite/apolloClientAiApps.d.ts +14 -0
- package/dist/vite/apolloClientAiApps.d.ts.map +1 -0
- package/dist/vite/apolloClientAiApps.js +350 -0
- package/dist/vite/apolloClientAiApps.js.map +1 -0
- package/dist/vite/index.d.ts +1 -2
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +1 -2
- package/dist/vite/index.js.map +1 -1
- package/dist/vite/utilities/config.d.ts +2 -0
- package/dist/vite/utilities/config.d.ts.map +1 -0
- package/dist/vite/utilities/config.js +11 -0
- package/dist/vite/utilities/config.js.map +1 -0
- package/dist/vite/utilities/graphql.d.ts +20 -0
- package/dist/vite/utilities/graphql.d.ts.map +1 -0
- package/dist/vite/utilities/graphql.js +42 -0
- package/dist/vite/utilities/graphql.js.map +1 -0
- package/knope.toml +1 -1
- package/package.json +105 -9
- package/src/config/defineConfig.ts +8 -0
- package/src/config/index.ts +2 -0
- package/src/config/schema.ts +73 -0
- package/src/config/types.ts +7 -0
- package/src/core/ApolloClient.ts +7 -95
- package/src/core/Platform.ts +27 -0
- package/src/core/types.ts +14 -0
- package/src/index.mcp.ts +5 -0
- package/src/index.openai.ts +5 -0
- package/src/index.ts +2 -27
- package/src/link/ToolCallLink.ts +6 -22
- package/src/mcp/core/ApolloClient.ts +102 -0
- package/src/mcp/core/McpAppManager.ts +98 -0
- package/src/mcp/core/Platform.ts +11 -0
- package/src/mcp/core/__tests__/ApolloClient.test.ts +464 -0
- package/src/mcp/index.ts +2 -0
- package/src/mcp/link/ToolCallLink.ts +40 -0
- package/src/mcp/link/__tests__/ToolCallLink.test.ts +53 -0
- package/src/mcp/react/hooks/__tests__/useApp.test.tsx +46 -0
- package/src/mcp/react/hooks/__tests__/useToolInput.test.tsx +50 -0
- package/src/mcp/react/hooks/__tests__/useToolMetadata.test.tsx +53 -0
- package/src/mcp/react/hooks/__tests__/useToolName.test.tsx +50 -0
- package/src/mcp/react/hooks/useApolloClient.ts +14 -0
- package/src/mcp/react/hooks/useApp.ts +5 -0
- package/src/mcp/react/hooks/useToolInput.ts +5 -0
- package/src/mcp/react/hooks/useToolMetadata.ts +5 -0
- package/src/mcp/react/hooks/useToolName.ts +5 -0
- package/src/mcp/react/index.ts +4 -0
- package/src/openai/core/ApolloClient.ts +100 -0
- package/src/openai/core/McpAppManager.ts +110 -0
- package/src/openai/core/Platform.ts +11 -0
- package/src/openai/core/__tests__/ApolloClient.test.ts +537 -0
- package/src/openai/globals.ts +14 -0
- package/src/openai/index.ts +2 -0
- package/src/openai/link/ToolCallLink.ts +40 -0
- package/src/{react → openai/react}/hooks/__tests__/useOpenAiGlobal.test.ts +1 -1
- package/src/openai/react/hooks/__tests__/useToolInput.test.tsx +85 -0
- package/src/openai/react/hooks/__tests__/useToolMetadata.test.tsx +86 -0
- package/src/openai/react/hooks/__tests__/useToolName.test.tsx +50 -0
- package/src/{react → openai/react}/hooks/__tests__/useWidgetState.test.tsx +1 -1
- package/src/openai/react/hooks/useApolloClient.ts +14 -0
- package/src/openai/react/hooks/useApp.ts +5 -0
- package/src/{react → openai/react}/hooks/useOpenAiGlobal.ts +2 -2
- package/src/openai/react/hooks/useToolInput.ts +5 -0
- package/src/openai/react/hooks/useToolMetadata.ts +5 -0
- package/src/openai/react/hooks/useToolName.ts +5 -0
- package/src/{react → openai/react}/hooks/useWidgetState.ts +1 -1
- package/src/openai/react/index.ts +5 -0
- package/src/{types/openai.ts → openai/types.ts} +9 -13
- package/src/react/ApolloProvider.tsx +23 -31
- package/src/react/__tests__/ApolloProvider/mcp.test.tsx +74 -0
- package/src/react/__tests__/ApolloProvider/openai.test.tsx +146 -0
- package/src/react/index.mcp.ts +7 -0
- package/src/react/index.openai.ts +7 -0
- package/src/react/index.ts +19 -0
- package/src/react/missingHook.ts +9 -0
- package/src/testing/internal/index.ts +8 -0
- package/src/testing/internal/matchers/index.ts +2 -0
- package/src/testing/internal/matchers/toComplete.ts +46 -0
- package/src/testing/internal/matchers/toEmitValue.ts +71 -0
- package/src/testing/internal/matchers/types.ts +3 -0
- package/src/testing/internal/mcp/graphqlToolResult.ts +31 -0
- package/src/testing/internal/mcp/minimalHostContextWithToolName.ts +9 -0
- package/src/testing/internal/mcp/mockMcpHost.ts +188 -0
- package/src/testing/internal/openai/dispatchStateChange.ts +1 -1
- package/src/testing/internal/openai/stubOpenAiGlobals.ts +22 -9
- package/src/testing/internal/react/renderAsync.ts +7 -0
- package/src/testing/internal/utilities/ObservableStream.ts +172 -0
- package/src/testing/internal/utilities/getSerializableProperties.ts +55 -0
- package/src/testing/internal/utilities/mockApplicationManifest.ts +39 -0
- package/src/testing/internal/utilities/spyOnConsole.ts +29 -0
- package/src/testing/internal/utilities/wait.ts +3 -0
- package/src/tsconfig/core/tsconfig.json +5 -0
- package/src/tsconfig/mcp/tsconfig.json +6 -0
- package/src/tsconfig/openai/tsconfig.json +7 -0
- package/src/types/application-manifest.ts +7 -1
- package/src/utilities/__tests__/cacheAsync.test.ts +64 -0
- package/src/utilities/cacheAsync.ts +25 -0
- package/src/utilities/constants.ts +5 -0
- package/src/utilities/emptyModule.ts +1 -0
- package/src/utilities/getVariablesForOperationFromToolInput.ts +27 -0
- package/src/utilities/index.ts +5 -0
- package/src/utilities/invariant.ts +5 -0
- package/src/utilities/promiseWithResolvers.ts +18 -0
- package/src/vite/__tests__/apolloClientAiApps.test.ts +1521 -0
- package/src/vite/__tests__/utilities/build.ts +72 -0
- package/src/vite/apolloClientAiApps.ts +515 -0
- package/src/vite/index.ts +1 -2
- package/src/vite/utilities/config.ts +13 -0
- package/src/vite/utilities/graphql.ts +123 -0
- package/tsconfig.base.json +2 -2
- package/tsconfig.vite.build.json +4 -1
- package/tsconfig.vite.json +8 -2
- package/vitest-setup.ts +28 -0
- package/dist/react/context/ToolUseContext.d.ts +0 -16
- package/dist/react/context/ToolUseContext.d.ts.map +0 -1
- package/dist/react/context/ToolUseContext.js +0 -11
- package/dist/react/context/ToolUseContext.js.map +0 -1
- package/dist/react/hooks/useCallTool.d.ts +0 -4
- package/dist/react/hooks/useCallTool.d.ts.map +0 -1
- package/dist/react/hooks/useCallTool.js +0 -5
- package/dist/react/hooks/useCallTool.js.map +0 -1
- package/dist/react/hooks/useOpenAiGlobal.d.ts +0 -3
- package/dist/react/hooks/useOpenAiGlobal.d.ts.map +0 -1
- package/dist/react/hooks/useOpenAiGlobal.js.map +0 -1
- package/dist/react/hooks/useOpenExternal.d.ts +0 -4
- package/dist/react/hooks/useOpenExternal.d.ts.map +0 -1
- package/dist/react/hooks/useOpenExternal.js +0 -5
- package/dist/react/hooks/useOpenExternal.js.map +0 -1
- package/dist/react/hooks/useRequestDisplayMode.d.ts +0 -7
- package/dist/react/hooks/useRequestDisplayMode.d.ts.map +0 -1
- package/dist/react/hooks/useRequestDisplayMode.js +0 -6
- package/dist/react/hooks/useRequestDisplayMode.js.map +0 -1
- package/dist/react/hooks/useSendFollowUpMessage.d.ts +0 -2
- package/dist/react/hooks/useSendFollowUpMessage.d.ts.map +0 -1
- package/dist/react/hooks/useSendFollowUpMessage.js +0 -8
- package/dist/react/hooks/useSendFollowUpMessage.js.map +0 -1
- package/dist/react/hooks/useToolEffect.d.ts +0 -3
- package/dist/react/hooks/useToolEffect.d.ts.map +0 -1
- package/dist/react/hooks/useToolEffect.js +0 -28
- package/dist/react/hooks/useToolEffect.js.map +0 -1
- package/dist/react/hooks/useToolInput.d.ts +0 -2
- package/dist/react/hooks/useToolInput.d.ts.map +0 -1
- package/dist/react/hooks/useToolInput.js +0 -6
- package/dist/react/hooks/useToolInput.js.map +0 -1
- package/dist/react/hooks/useToolName.d.ts.map +0 -1
- package/dist/react/hooks/useToolName.js +0 -6
- package/dist/react/hooks/useToolName.js.map +0 -1
- package/dist/react/hooks/useToolOutput.d.ts +0 -2
- package/dist/react/hooks/useToolOutput.d.ts.map +0 -1
- package/dist/react/hooks/useToolOutput.js +0 -5
- package/dist/react/hooks/useToolOutput.js.map +0 -1
- package/dist/react/hooks/useToolResponseMetadata.d.ts +0 -2
- package/dist/react/hooks/useToolResponseMetadata.d.ts.map +0 -1
- package/dist/react/hooks/useToolResponseMetadata.js +0 -5
- package/dist/react/hooks/useToolResponseMetadata.js.map +0 -1
- package/dist/react/hooks/useWidgetState.d.ts.map +0 -1
- package/dist/react/hooks/useWidgetState.js.map +0 -1
- package/dist/types/openai.d.ts.map +0 -1
- package/dist/types/openai.js.map +0 -1
- package/dist/vite/absolute_asset_imports_plugin.d.ts +0 -5
- package/dist/vite/absolute_asset_imports_plugin.d.ts.map +0 -1
- package/dist/vite/absolute_asset_imports_plugin.js +0 -17
- package/dist/vite/absolute_asset_imports_plugin.js.map +0 -1
- package/dist/vite/application_manifest_plugin.d.ts +0 -10
- package/dist/vite/application_manifest_plugin.d.ts.map +0 -1
- package/dist/vite/application_manifest_plugin.js +0 -317
- package/dist/vite/application_manifest_plugin.js.map +0 -1
- package/src/core/__tests__/ApolloClient.test.ts +0 -646
- package/src/react/__tests__/ApolloProvider.test.tsx +0 -41
- package/src/react/context/ToolUseContext.tsx +0 -31
- package/src/react/hooks/__tests__/useCallTool.test.ts +0 -46
- package/src/react/hooks/__tests__/useOpenExternal.test.tsx +0 -24
- package/src/react/hooks/__tests__/useRequestDisplayMode.test.ts +0 -17
- package/src/react/hooks/__tests__/useSendFollowUpMessage.test.ts +0 -15
- package/src/react/hooks/__tests__/useToolEffect.test.tsx +0 -67
- package/src/react/hooks/__tests__/useToolInput.test.ts +0 -13
- package/src/react/hooks/__tests__/useToolName.test.ts +0 -13
- package/src/react/hooks/__tests__/useToolOutput.test.tsx +0 -49
- package/src/react/hooks/__tests__/useToolResponseMetadata.test.tsx +0 -49
- package/src/react/hooks/useCallTool.ts +0 -13
- package/src/react/hooks/useOpenExternal.ts +0 -11
- package/src/react/hooks/useRequestDisplayMode.ts +0 -7
- package/src/react/hooks/useSendFollowUpMessage.ts +0 -7
- package/src/react/hooks/useToolEffect.tsx +0 -37
- package/src/react/hooks/useToolInput.ts +0 -7
- package/src/react/hooks/useToolName.ts +0 -7
- package/src/react/hooks/useToolOutput.ts +0 -5
- package/src/react/hooks/useToolResponseMetadata.ts +0 -5
- package/src/vite/__tests__/absolute_asset_imports_plugin.test.ts +0 -102
- package/src/vite/__tests__/application_manifest_plugin.test.ts +0 -1199
- package/src/vite/absolute_asset_imports_plugin.ts +0 -22
- package/src/vite/application_manifest_plugin.ts +0 -539
- /package/dist/{react → openai/react}/hooks/useToolName.d.ts +0 -0
- /package/dist/{react → openai/react}/hooks/useWidgetState.js +0 -0
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { expect, test, vi } from "vitest";
|
|
2
|
-
import { useCallTool } from "../useCallTool.js";
|
|
3
|
-
|
|
4
|
-
test("Should execute tool when returned function is called", async () => {
|
|
5
|
-
vi.stubGlobal("openai", {
|
|
6
|
-
callTool: vi.fn(async (name: string, args: Record<string, unknown>) => {
|
|
7
|
-
return {
|
|
8
|
-
structuredContent: {
|
|
9
|
-
data: {
|
|
10
|
-
product: {
|
|
11
|
-
id: "1",
|
|
12
|
-
title: "Pen",
|
|
13
|
-
rating: 5,
|
|
14
|
-
price: 1.0,
|
|
15
|
-
description: "Awesome pen",
|
|
16
|
-
images: [],
|
|
17
|
-
__typename: "Product",
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
}),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const callTool = useCallTool();
|
|
26
|
-
const result = await callTool("my-tool", { id: 1 });
|
|
27
|
-
|
|
28
|
-
expect(window.openai.callTool).toBeCalledWith("my-tool", { id: 1 });
|
|
29
|
-
expect(result).toMatchInlineSnapshot(`
|
|
30
|
-
{
|
|
31
|
-
"structuredContent": {
|
|
32
|
-
"data": {
|
|
33
|
-
"product": {
|
|
34
|
-
"__typename": "Product",
|
|
35
|
-
"description": "Awesome pen",
|
|
36
|
-
"id": "1",
|
|
37
|
-
"images": [],
|
|
38
|
-
"price": 1,
|
|
39
|
-
"rating": 5,
|
|
40
|
-
"title": "Pen",
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
}
|
|
45
|
-
`);
|
|
46
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { expect, test, vi } from "vitest";
|
|
2
|
-
import { renderHookToSnapshotStream } from "@testing-library/react-render-stream";
|
|
3
|
-
import { useOpenExternal } from "../useOpenExternal.js";
|
|
4
|
-
import { stubOpenAiGlobals } from "../../../testing/internal/index.js";
|
|
5
|
-
|
|
6
|
-
test("calls the global openExternal function", async () => {
|
|
7
|
-
const openExternalMock = vi.fn();
|
|
8
|
-
|
|
9
|
-
stubOpenAiGlobals({ openExternal: openExternalMock });
|
|
10
|
-
|
|
11
|
-
const { takeSnapshot } = await renderHookToSnapshotStream(() =>
|
|
12
|
-
useOpenExternal()
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
const openExternal = await takeSnapshot();
|
|
16
|
-
openExternal({ href: "https://example.com" });
|
|
17
|
-
|
|
18
|
-
expect(openExternalMock).toHaveBeenCalledTimes(1);
|
|
19
|
-
expect(openExternalMock).toHaveBeenCalledWith({
|
|
20
|
-
href: "https://example.com",
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
await expect(takeSnapshot).not.toRerender();
|
|
24
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { expect, test, vi } from "vitest";
|
|
2
|
-
import { useRequestDisplayMode } from "../useRequestDisplayMode.js";
|
|
3
|
-
import type { DisplayMode } from "../../../types/openai.js";
|
|
4
|
-
|
|
5
|
-
test("Should set display mode when returned function is called", async () => {
|
|
6
|
-
vi.stubGlobal("openai", {
|
|
7
|
-
requestDisplayMode: vi.fn(async (args: { mode: DisplayMode }) => {
|
|
8
|
-
return args;
|
|
9
|
-
}),
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
const requestDisplayMode = useRequestDisplayMode();
|
|
13
|
-
const result = await requestDisplayMode({ mode: "inline" });
|
|
14
|
-
|
|
15
|
-
expect(window.openai.requestDisplayMode).toBeCalledWith({ mode: "inline" });
|
|
16
|
-
expect(result).toEqual({ mode: "inline" });
|
|
17
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { expect, test, vi } from "vitest";
|
|
2
|
-
import { useSendFollowUpMessage } from "../useSendFollowUpMessage.js";
|
|
3
|
-
|
|
4
|
-
test("Should set display mode when returned function is called", async () => {
|
|
5
|
-
vi.stubGlobal("openai", {
|
|
6
|
-
sendFollowUpMessage: vi.fn(async (args: { prompt: string }) => {}),
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
const sendFollowUpMessage = useSendFollowUpMessage();
|
|
10
|
-
await sendFollowUpMessage("Do a cool thing!");
|
|
11
|
-
|
|
12
|
-
expect(window.openai.sendFollowUpMessage).toBeCalledWith({
|
|
13
|
-
prompt: "Do a cool thing!",
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { expect, test, vi } from "vitest";
|
|
2
|
-
import { useToolEffect } from "../useToolEffect.js";
|
|
3
|
-
import { renderHook } from "@testing-library/react";
|
|
4
|
-
import { ToolUseProvider } from "../../context/ToolUseContext.js";
|
|
5
|
-
|
|
6
|
-
test("Should trigger effect when tool name matches toolResponseMetadata", async () => {
|
|
7
|
-
vi.stubGlobal("openai", {
|
|
8
|
-
toolResponseMetadata: { toolName: "my-app--my-tool" },
|
|
9
|
-
});
|
|
10
|
-
const navigate = vi.fn();
|
|
11
|
-
const wrapper = ({ children }: { children: any }) => (
|
|
12
|
-
<ToolUseProvider appName="my-app">{children}</ToolUseProvider>
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
renderHook(() => useToolEffect("my-tool", () => navigate(), [navigate]), {
|
|
16
|
-
wrapper,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
expect(navigate).toBeCalled();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test("Should trigger effect when one of multiple tool name matches toolResponseMetadata", async () => {
|
|
23
|
-
vi.stubGlobal("openai", {
|
|
24
|
-
toolResponseMetadata: { toolName: "my-app--my-tool" },
|
|
25
|
-
});
|
|
26
|
-
const navigate = vi.fn();
|
|
27
|
-
const wrapper = ({ children }: { children: any }) => (
|
|
28
|
-
<ToolUseProvider appName="my-app">{children}</ToolUseProvider>
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
renderHook(
|
|
32
|
-
() =>
|
|
33
|
-
useToolEffect(["my-tool", "my-similar-tool"], () => navigate(), [
|
|
34
|
-
navigate,
|
|
35
|
-
]),
|
|
36
|
-
{ wrapper }
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
expect(navigate).toBeCalled();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test("Should not trigger effect when tool name does not match toolResponseMetadata", async () => {
|
|
43
|
-
vi.stubGlobal("openai", {
|
|
44
|
-
toolResponseMetadata: { toolName: "my-app--my-other-tool" },
|
|
45
|
-
});
|
|
46
|
-
const navigate = vi.fn();
|
|
47
|
-
const wrapper = ({ children }: { children: any }) => (
|
|
48
|
-
<ToolUseProvider appName="my-app">{children}</ToolUseProvider>
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
renderHook(() => useToolEffect("my-tool", () => navigate(), [navigate]), {
|
|
52
|
-
wrapper,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
expect(navigate).not.toBeCalled();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test("Should throw an error when used outside of a ToolUseProvider", async () => {
|
|
59
|
-
vi.stubGlobal("openai", {
|
|
60
|
-
toolResponseMetadata: { toolName: "my-app--my-other-tool" },
|
|
61
|
-
});
|
|
62
|
-
const navigate = vi.fn();
|
|
63
|
-
|
|
64
|
-
expect(() =>
|
|
65
|
-
renderHook(() => useToolEffect("my-tool", () => navigate(), [navigate]))
|
|
66
|
-
).toThrowError("useToolEffect must be used within ToolUseProvider");
|
|
67
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { expect, test, vi } from "vitest";
|
|
2
|
-
import { useToolInput } from "../useToolInput.js";
|
|
3
|
-
import { renderHook } from "@testing-library/react";
|
|
4
|
-
|
|
5
|
-
test("Should return tool input when called", async () => {
|
|
6
|
-
vi.stubGlobal("openai", {
|
|
7
|
-
toolInput: { name: "John" },
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const { result } = renderHook(() => useToolInput());
|
|
11
|
-
|
|
12
|
-
expect(result.current).toEqual({ name: "John" });
|
|
13
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { expect, test, vi } from "vitest";
|
|
2
|
-
import { useToolName } from "../useToolName.js";
|
|
3
|
-
import { renderHook } from "@testing-library/react";
|
|
4
|
-
|
|
5
|
-
test("Should return tool input when called", async () => {
|
|
6
|
-
vi.stubGlobal("openai", {
|
|
7
|
-
toolResponseMetadata: { toolName: "get-products" },
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const { result } = renderHook(() => useToolName());
|
|
11
|
-
|
|
12
|
-
expect(result.current).toBe("get-products");
|
|
13
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { afterEach, expect, test, vi } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
dispatchStateChange,
|
|
4
|
-
stubOpenAiGlobals,
|
|
5
|
-
} from "../../../testing/internal/index.js";
|
|
6
|
-
import { renderHookToSnapshotStream } from "@testing-library/react-render-stream";
|
|
7
|
-
import { useToolOutput } from "../useToolOutput.js";
|
|
8
|
-
|
|
9
|
-
afterEach(() => {
|
|
10
|
-
vi.unstubAllGlobals();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test("returns the tool output set in window", async () => {
|
|
14
|
-
stubOpenAiGlobals({ toolOutput: { test: true } });
|
|
15
|
-
|
|
16
|
-
const { takeSnapshot } = await renderHookToSnapshotStream(() =>
|
|
17
|
-
useToolOutput()
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
await expect(takeSnapshot()).resolves.toEqual({ test: true });
|
|
21
|
-
await expect(takeSnapshot).not.toRerender();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test("returns null when not set", async () => {
|
|
25
|
-
stubOpenAiGlobals();
|
|
26
|
-
|
|
27
|
-
const { takeSnapshot } = await renderHookToSnapshotStream(() =>
|
|
28
|
-
useToolOutput()
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
await expect(takeSnapshot()).resolves.toBeNull();
|
|
32
|
-
await expect(takeSnapshot).not.toRerender();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test("reacts to changes in globals", async () => {
|
|
36
|
-
stubOpenAiGlobals({ toolOutput: { initial: true } });
|
|
37
|
-
|
|
38
|
-
const { takeSnapshot } = await renderHookToSnapshotStream(() =>
|
|
39
|
-
useToolOutput()
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
await expect(takeSnapshot()).resolves.toEqual({ initial: true });
|
|
43
|
-
|
|
44
|
-
window.openai.toolOutput = { updated: true };
|
|
45
|
-
dispatchStateChange();
|
|
46
|
-
|
|
47
|
-
await expect(takeSnapshot()).resolves.toEqual({ updated: true });
|
|
48
|
-
await expect(takeSnapshot).not.toRerender();
|
|
49
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { afterEach, expect, test, vi } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
dispatchStateChange,
|
|
4
|
-
stubOpenAiGlobals,
|
|
5
|
-
} from "../../../testing/internal/index.js";
|
|
6
|
-
import { renderHookToSnapshotStream } from "@testing-library/react-render-stream";
|
|
7
|
-
import { useToolResponseMetadata } from "../useToolResponseMetadata.js";
|
|
8
|
-
|
|
9
|
-
afterEach(() => {
|
|
10
|
-
vi.unstubAllGlobals();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test("returns the tool output set in window", async () => {
|
|
14
|
-
stubOpenAiGlobals({ toolResponseMetadata: { test: true } });
|
|
15
|
-
|
|
16
|
-
const { takeSnapshot } = await renderHookToSnapshotStream(() =>
|
|
17
|
-
useToolResponseMetadata()
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
await expect(takeSnapshot()).resolves.toEqual({ test: true });
|
|
21
|
-
await expect(takeSnapshot).not.toRerender();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test("returns null when not set", async () => {
|
|
25
|
-
stubOpenAiGlobals();
|
|
26
|
-
|
|
27
|
-
const { takeSnapshot } = await renderHookToSnapshotStream(() =>
|
|
28
|
-
useToolResponseMetadata()
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
await expect(takeSnapshot()).resolves.toBeNull();
|
|
32
|
-
await expect(takeSnapshot).not.toRerender();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test("reacts to changes in globals", async () => {
|
|
36
|
-
stubOpenAiGlobals({ toolResponseMetadata: { initial: true } });
|
|
37
|
-
|
|
38
|
-
const { takeSnapshot } = await renderHookToSnapshotStream(() =>
|
|
39
|
-
useToolResponseMetadata()
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
await expect(takeSnapshot()).resolves.toEqual({ initial: true });
|
|
43
|
-
|
|
44
|
-
window.openai.toolResponseMetadata = { updated: true };
|
|
45
|
-
dispatchStateChange();
|
|
46
|
-
|
|
47
|
-
await expect(takeSnapshot()).resolves.toEqual({ updated: true });
|
|
48
|
-
await expect(takeSnapshot).not.toRerender();
|
|
49
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
type UseCallToolResult = <K>(
|
|
2
|
-
toolId: string,
|
|
3
|
-
variables?: Record<string, unknown> | undefined
|
|
4
|
-
) => Promise<K>;
|
|
5
|
-
|
|
6
|
-
export const useCallTool = (): UseCallToolResult => {
|
|
7
|
-
const callTool = async (
|
|
8
|
-
toolId: string,
|
|
9
|
-
variables: Record<string, unknown> | undefined = {}
|
|
10
|
-
) => await window.openai?.callTool(toolId, variables);
|
|
11
|
-
|
|
12
|
-
return callTool;
|
|
13
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
import type { API } from "../../types/openai.js";
|
|
3
|
-
|
|
4
|
-
type OpenExternalFn = API<any>["openExternal"];
|
|
5
|
-
|
|
6
|
-
export function useOpenExternal() {
|
|
7
|
-
return useCallback<OpenExternalFn>(
|
|
8
|
-
(...args) => window.openai.openExternal(...args),
|
|
9
|
-
[]
|
|
10
|
-
);
|
|
11
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from "react";
|
|
2
|
-
import { useToolName } from "./useToolName.js";
|
|
3
|
-
import { useToolInput } from "./useToolInput.js";
|
|
4
|
-
import { useToolUseState } from "../context/ToolUseContext.js";
|
|
5
|
-
|
|
6
|
-
export const useToolEffect = (
|
|
7
|
-
toolName: string | string[],
|
|
8
|
-
effect: (toolInput: any) => void,
|
|
9
|
-
deps: React.DependencyList = []
|
|
10
|
-
) => {
|
|
11
|
-
const ctx = useToolUseState();
|
|
12
|
-
const fullToolName = useToolName();
|
|
13
|
-
const toolInput = useToolInput();
|
|
14
|
-
if (!ctx)
|
|
15
|
-
throw new Error("useToolEffect must be used within ToolUseProvider");
|
|
16
|
-
|
|
17
|
-
const toolNames = Array.isArray(toolName) ? toolName : [toolName];
|
|
18
|
-
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
const matches = toolNames.some(
|
|
21
|
-
(name) => fullToolName === `${ctx.appName}--${name}`
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
if (!ctx.hasNavigated && matches) {
|
|
25
|
-
effect(toolInput);
|
|
26
|
-
ctx.setHasNavigated(true);
|
|
27
|
-
}
|
|
28
|
-
}, [
|
|
29
|
-
ctx.hasNavigated,
|
|
30
|
-
ctx.setHasNavigated,
|
|
31
|
-
ctx.appName,
|
|
32
|
-
toolNames,
|
|
33
|
-
fullToolName,
|
|
34
|
-
toolInput,
|
|
35
|
-
...deps,
|
|
36
|
-
]);
|
|
37
|
-
};
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
2
|
-
import { AbsoluteAssetImportsPlugin } from "../absolute_asset_imports_plugin.js";
|
|
3
|
-
|
|
4
|
-
test("Should replace root relative scripts with full url when origin is provided", () => {
|
|
5
|
-
const ctx = {
|
|
6
|
-
server: {
|
|
7
|
-
config: {
|
|
8
|
-
server: {
|
|
9
|
-
origin: "http://localhost:3000/",
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
const html = `<html><head><script type="module" src="/@vite/client"></script></head><body><script module src="/assets/main.ts?t=12345"></script></body></html>`;
|
|
15
|
-
const plugin = AbsoluteAssetImportsPlugin();
|
|
16
|
-
|
|
17
|
-
let result = plugin.transformIndexHtml(html, ctx);
|
|
18
|
-
|
|
19
|
-
expect(result).toMatchInlineSnapshot(
|
|
20
|
-
`"<html><head><script type="module" src="http://localhost:3000/@vite/client"></script></head><body><script module src="http://localhost:3000/assets/main.ts?t=12345"></script></body></html>"`
|
|
21
|
-
);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test("Should replace root relative scripts with full url when origin is not provided", () => {
|
|
25
|
-
const ctx = {
|
|
26
|
-
server: {
|
|
27
|
-
resolvedUrls: {
|
|
28
|
-
local: ["http://localhost:3000/"],
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
const html = `<html><head> <script type="module">import { injectIntoGlobalHook } from "/@react-refresh";
|
|
33
|
-
injectIntoGlobalHook(window);
|
|
34
|
-
window.$RefreshReg$ = () => {};
|
|
35
|
-
window.$RefreshSig$ = () => (type) => type;</script></head></html>`;
|
|
36
|
-
const plugin = AbsoluteAssetImportsPlugin();
|
|
37
|
-
|
|
38
|
-
let result = plugin.transformIndexHtml(html, ctx);
|
|
39
|
-
|
|
40
|
-
expect(result).toMatchInlineSnapshot(`
|
|
41
|
-
"<html><head> <script type="module">import { injectIntoGlobalHook } from "http://localhost:3000/@react-refresh";
|
|
42
|
-
injectIntoGlobalHook(window);
|
|
43
|
-
window.$RefreshReg$ = () => {};
|
|
44
|
-
window.$RefreshSig$ = () => (type) => type;</script></head></html>"
|
|
45
|
-
`);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test("Should replace root relative imports with full url when origin is provided", () => {
|
|
49
|
-
const ctx = {
|
|
50
|
-
server: {
|
|
51
|
-
config: {
|
|
52
|
-
server: {
|
|
53
|
-
origin: "http://localhost:3000/",
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
const html = `<html><head> <script type="module">import { injectIntoGlobalHook } from "/@react-refresh";
|
|
59
|
-
injectIntoGlobalHook(window);
|
|
60
|
-
window.$RefreshReg$ = () => {};
|
|
61
|
-
window.$RefreshSig$ = () => (type) => type;</script></head></html>`;
|
|
62
|
-
const plugin = AbsoluteAssetImportsPlugin();
|
|
63
|
-
|
|
64
|
-
let result = plugin.transformIndexHtml(html, ctx);
|
|
65
|
-
|
|
66
|
-
expect(result).toMatchInlineSnapshot(`
|
|
67
|
-
"<html><head> <script type="module">import { injectIntoGlobalHook } from "http://localhost:3000/@react-refresh";
|
|
68
|
-
injectIntoGlobalHook(window);
|
|
69
|
-
window.$RefreshReg$ = () => {};
|
|
70
|
-
window.$RefreshSig$ = () => (type) => type;</script></head></html>"
|
|
71
|
-
`);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test("Should replace root relative imports with full url when origin is not provided", () => {
|
|
75
|
-
const ctx = {
|
|
76
|
-
server: {
|
|
77
|
-
resolvedUrls: {
|
|
78
|
-
local: ["http://localhost:3000/"],
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
const html = `<html><body><script module src="/assets/main.ts?t=12345"></script></body></html>`;
|
|
83
|
-
const plugin = AbsoluteAssetImportsPlugin();
|
|
84
|
-
|
|
85
|
-
let result = plugin.transformIndexHtml(html, ctx);
|
|
86
|
-
|
|
87
|
-
expect(result).toMatchInlineSnapshot(
|
|
88
|
-
`"<html><body><script module src="http://localhost:3000/assets/main.ts?t=12345"></script></body></html>"`
|
|
89
|
-
);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test("Should not modify html when not running a local server", () => {
|
|
93
|
-
const ctx = {};
|
|
94
|
-
const html = `<html><head><script type="module" src="/@vite/client"></script></head><body><script module src="/assets/main.ts?t=12345"></script></body></html>`;
|
|
95
|
-
const plugin = AbsoluteAssetImportsPlugin();
|
|
96
|
-
|
|
97
|
-
let result = plugin.transformIndexHtml(html, ctx);
|
|
98
|
-
|
|
99
|
-
expect(result).toMatchInlineSnapshot(
|
|
100
|
-
`"<html><head><script type="module" src="/@vite/client"></script></head><body><script module src="/assets/main.ts?t=12345"></script></body></html>"`
|
|
101
|
-
);
|
|
102
|
-
});
|