@apollo/client-ai-apps 0.3.2 → 0.3.3

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 (140) hide show
  1. package/.github/workflows/pr.yaml +52 -3
  2. package/.github/workflows/prep-release.yml +38 -0
  3. package/.github/workflows/release.yaml +8 -4
  4. package/.github/workflows/verify-changeset.yml +58 -0
  5. package/CHANGELOG.md +25 -0
  6. package/dist/core/ApolloClient.d.ts +3 -2
  7. package/dist/core/ApolloClient.d.ts.map +1 -0
  8. package/dist/core/ApolloClient.js +65 -0
  9. package/dist/core/ApolloClient.js.map +1 -0
  10. package/dist/index.d.ts +18 -17
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +16 -278
  13. package/dist/index.js.map +1 -0
  14. package/dist/link/ToolCallLink.d.ts +1 -0
  15. package/dist/link/ToolCallLink.d.ts.map +1 -0
  16. package/dist/link/ToolCallLink.js +39 -0
  17. package/dist/link/ToolCallLink.js.map +1 -0
  18. package/dist/react/ApolloProvider.d.ts +4 -3
  19. package/dist/react/ApolloProvider.d.ts.map +1 -0
  20. package/dist/react/ApolloProvider.js +30 -0
  21. package/dist/react/ApolloProvider.js.map +1 -0
  22. package/dist/react/context/ToolUseContext.d.ts +4 -3
  23. package/dist/react/context/ToolUseContext.d.ts.map +1 -0
  24. package/dist/react/context/ToolUseContext.js +11 -0
  25. package/dist/react/context/ToolUseContext.js.map +1 -0
  26. package/dist/react/hooks/useCallTool.d.ts +4 -0
  27. package/dist/react/hooks/useCallTool.d.ts.map +1 -0
  28. package/dist/react/hooks/useCallTool.js +5 -0
  29. package/dist/react/hooks/useCallTool.js.map +1 -0
  30. package/dist/react/hooks/useOpenAiGlobal.d.ts +2 -1
  31. package/dist/react/hooks/useOpenAiGlobal.d.ts.map +1 -0
  32. package/dist/react/hooks/useOpenAiGlobal.js +20 -0
  33. package/dist/react/hooks/useOpenAiGlobal.js.map +1 -0
  34. package/dist/react/hooks/useOpenExternal.d.ts +1 -0
  35. package/dist/react/hooks/useOpenExternal.d.ts.map +1 -0
  36. package/dist/react/hooks/useOpenExternal.js +5 -0
  37. package/dist/react/hooks/useOpenExternal.js.map +1 -0
  38. package/dist/react/hooks/useRequestDisplayMode.d.ts +2 -1
  39. package/dist/react/hooks/useRequestDisplayMode.d.ts.map +1 -0
  40. package/dist/react/hooks/useRequestDisplayMode.js +6 -0
  41. package/dist/react/hooks/useRequestDisplayMode.js.map +1 -0
  42. package/dist/react/hooks/useSendFollowUpMessage.d.ts +1 -0
  43. package/dist/react/hooks/useSendFollowUpMessage.d.ts.map +1 -0
  44. package/dist/react/hooks/useSendFollowUpMessage.js +8 -0
  45. package/dist/react/hooks/useSendFollowUpMessage.js.map +1 -0
  46. package/dist/react/hooks/useToolEffect.d.ts +1 -0
  47. package/dist/react/hooks/useToolEffect.d.ts.map +1 -0
  48. package/dist/react/hooks/useToolEffect.js +28 -0
  49. package/dist/react/hooks/useToolEffect.js.map +1 -0
  50. package/dist/react/hooks/useToolInput.d.ts +1 -0
  51. package/dist/react/hooks/useToolInput.d.ts.map +1 -0
  52. package/dist/react/hooks/useToolInput.js +6 -0
  53. package/dist/react/hooks/useToolInput.js.map +1 -0
  54. package/dist/react/hooks/useToolName.d.ts +1 -0
  55. package/dist/react/hooks/useToolName.d.ts.map +1 -0
  56. package/dist/react/hooks/useToolName.js +6 -0
  57. package/dist/react/hooks/useToolName.js.map +1 -0
  58. package/dist/react/hooks/useToolOutput.d.ts +2 -1
  59. package/dist/react/hooks/useToolOutput.d.ts.map +1 -0
  60. package/dist/react/hooks/useToolOutput.js +5 -0
  61. package/dist/react/hooks/useToolOutput.js.map +1 -0
  62. package/dist/react/hooks/useToolResponseMetadata.d.ts +2 -1
  63. package/dist/react/hooks/useToolResponseMetadata.d.ts.map +1 -0
  64. package/dist/react/hooks/useToolResponseMetadata.js +5 -0
  65. package/dist/react/hooks/useToolResponseMetadata.js.map +1 -0
  66. package/dist/react/hooks/useWidgetState.d.ts +3 -2
  67. package/dist/react/hooks/useWidgetState.d.ts.map +1 -0
  68. package/dist/react/hooks/useWidgetState.js +27 -0
  69. package/dist/react/hooks/useWidgetState.js.map +1 -0
  70. package/dist/types/application-manifest.d.ts +7 -0
  71. package/dist/types/application-manifest.d.ts.map +1 -0
  72. package/dist/types/application-manifest.js +2 -0
  73. package/dist/types/application-manifest.js.map +1 -0
  74. package/dist/types/openai.d.ts +1 -0
  75. package/dist/types/openai.d.ts.map +1 -0
  76. package/dist/types/openai.js +6 -0
  77. package/dist/types/openai.js.map +1 -0
  78. package/dist/vite/absolute_asset_imports_plugin.d.ts +1 -0
  79. package/dist/vite/absolute_asset_imports_plugin.d.ts.map +1 -0
  80. package/dist/vite/absolute_asset_imports_plugin.js +17 -0
  81. package/dist/vite/absolute_asset_imports_plugin.js.map +1 -0
  82. package/dist/vite/application_manifest_plugin.d.ts +2 -1
  83. package/dist/vite/application_manifest_plugin.d.ts.map +1 -0
  84. package/dist/vite/application_manifest_plugin.js +274 -0
  85. package/dist/vite/application_manifest_plugin.js.map +1 -0
  86. package/dist/vite/index.d.ts +3 -2
  87. package/dist/vite/index.d.ts.map +1 -0
  88. package/dist/vite/index.js +3 -307
  89. package/dist/vite/index.js.map +1 -0
  90. package/knope.toml +63 -0
  91. package/package.json +15 -8
  92. package/src/core/ApolloClient.ts +10 -5
  93. package/src/core/__tests__/ApolloClient.test.ts +12 -9
  94. package/src/index.ts +17 -17
  95. package/src/react/ApolloProvider.tsx +4 -3
  96. package/src/react/__tests__/ApolloProvider.test.tsx +3 -3
  97. package/src/react/context/ToolUseContext.tsx +2 -1
  98. package/src/react/hooks/__tests__/useCallTool.test.ts +1 -1
  99. package/src/react/hooks/__tests__/useOpenAiGlobal.test.ts +6 -6
  100. package/src/react/hooks/__tests__/useOpenExternal.test.tsx +2 -2
  101. package/src/react/hooks/__tests__/useRequestDisplayMode.test.ts +2 -2
  102. package/src/react/hooks/__tests__/useSendFollowUpMessage.test.ts +1 -1
  103. package/src/react/hooks/__tests__/useToolEffect.test.tsx +2 -2
  104. package/src/react/hooks/__tests__/useToolInput.test.ts +1 -1
  105. package/src/react/hooks/__tests__/useToolName.test.ts +1 -1
  106. package/src/react/hooks/__tests__/useToolOutput.test.tsx +2 -2
  107. package/src/react/hooks/__tests__/useToolResponseMetadata.test.tsx +2 -2
  108. package/src/react/hooks/__tests__/useWidgetState.test.tsx +2 -2
  109. package/src/react/hooks/useOpenAiGlobal.ts +2 -5
  110. package/src/react/hooks/useOpenExternal.ts +1 -1
  111. package/src/react/hooks/useRequestDisplayMode.ts +1 -1
  112. package/src/react/hooks/useToolEffect.tsx +3 -3
  113. package/src/react/hooks/useToolInput.ts +1 -1
  114. package/src/react/hooks/useToolName.ts +1 -1
  115. package/src/react/hooks/useToolOutput.ts +1 -1
  116. package/src/react/hooks/useToolResponseMetadata.ts +1 -1
  117. package/src/react/hooks/useWidgetState.ts +4 -3
  118. package/src/testing/internal/index.ts +2 -2
  119. package/src/testing/internal/matchers/index.ts +1 -1
  120. package/src/testing/internal/matchers/toRerender.ts +2 -2
  121. package/src/testing/internal/matchers/{index.d.ts → types.ts} +1 -1
  122. package/src/testing/internal/openai/dispatchStateChange.ts +1 -1
  123. package/src/testing/internal/openai/stubOpenAiGlobals.ts +6 -2
  124. package/src/types/application-manifest.ts +7 -0
  125. package/src/vite/__tests__/absolute_asset_imports_plugin.test.ts +2 -2
  126. package/src/vite/__tests__/application_manifest_plugin.test.ts +299 -240
  127. package/src/vite/application_manifest_plugin.ts +160 -96
  128. package/src/vite/index.ts +2 -2
  129. package/tsconfig.base.build.json +13 -0
  130. package/tsconfig.base.json +21 -0
  131. package/tsconfig.config.json +9 -0
  132. package/tsconfig.json +10 -0
  133. package/tsconfig.src.build.json +14 -0
  134. package/tsconfig.src.json +17 -0
  135. package/tsconfig.test.json +20 -0
  136. package/tsconfig.vite.build.json +6 -0
  137. package/tsconfig.vite.json +16 -0
  138. package/scripts/build-vite.mjs +0 -18
  139. package/scripts/build.mjs +0 -7
  140. package/scripts/shared.mjs +0 -9
package/knope.toml ADDED
@@ -0,0 +1,63 @@
1
+ [package]
2
+ versioned_files = ["package.json", "package-lock.json"]
3
+ changelog = "CHANGELOG.md"
4
+
5
+ [[workflows]]
6
+ name = "prepare-release"
7
+
8
+ [[workflows.steps]]
9
+ type = "Command"
10
+ command = "git switch -c release/$BASE_BRANCH"
11
+ shell = true
12
+
13
+ [[workflows.steps]]
14
+ type = "PrepareRelease"
15
+ ignore_conventional_commits = true
16
+
17
+ [[workflows.steps]]
18
+ type = "Command"
19
+ command = "npm run format && git add package.json package-lock.json"
20
+ shell = true
21
+
22
+ [[workflows.steps]]
23
+ type = "Command"
24
+ command = "git commit -m \"chore: prepare release $version\""
25
+
26
+ [[workflows.steps]]
27
+ type = "Command"
28
+ command = "git push --force --set-upstream origin release/$BASE_BRANCH"
29
+ shell = true
30
+
31
+ [[workflows.steps]]
32
+ type = "CreatePullRequest"
33
+ base = "main"
34
+
35
+ [workflows.steps.title]
36
+ template = "chore: prepare release $version"
37
+
38
+ [workflows.steps.body]
39
+ template = "This PR was created by Knope. Merging it will create a new release\n\n$changelog"
40
+
41
+ [[workflows]]
42
+ name = "release"
43
+
44
+ [[workflows.steps]]
45
+ type = "Release"
46
+
47
+ [[workflows]]
48
+ name = "document-change"
49
+
50
+ [[workflows.steps]]
51
+ type = "CreateChangeFile"
52
+
53
+ [[workflows]]
54
+ name = "get-version"
55
+ help_text = "Get the current version of the project"
56
+
57
+ [[workflows.steps]]
58
+ type = "Command"
59
+ command = 'echo "$version"'
60
+
61
+ [github]
62
+ owner = "apollographql"
63
+ repo = "apollo-ai-apps-client"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apollo/client-ai-apps",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -15,18 +15,24 @@
15
15
  ".": "./dist/index.js",
16
16
  "./vite": "./dist/vite/index.js"
17
17
  },
18
+ "devEngines": {
19
+ "packageManager": {
20
+ "name": "npm"
21
+ }
22
+ },
18
23
  "scripts": {
19
24
  "dev": "node ./scripts/dev.mjs",
20
25
  "prebuild": "npm run clean",
21
- "build": "npm run build:react && npm run build:vite",
22
- "build:react": "node ./scripts/build.mjs && tsc src/index.ts --emitDeclarationOnly --declaration --outDir dist --skipLibCheck --lib ES2015,DOM --target ES2015 --moduleResolution bundler --jsx react",
23
- "build:vite": "node ./scripts/build-vite.mjs && tsc src/vite/index.ts --emitDeclarationOnly --declaration --outDir dist/vite --skipLibCheck --lib ES2015,DOM --target ES2020 --module esnext --moduleResolution node --allowSyntheticDefaultImports",
26
+ "build": "npm run build:src && npm run build:vite",
27
+ "build:src": "tsc --project tsconfig.src.build.json",
28
+ "build:vite": "tsc --project tsconfig.vite.build.json",
24
29
  "clean": "rimraf dist",
25
30
  "test": "vitest run --coverage",
26
31
  "test:watch": "vitest --coverage",
27
32
  "changeset": "knope document-change",
28
33
  "format": "prettier --write .",
29
- "format:check": "prettier --check ."
34
+ "format:check": "prettier --check .",
35
+ "typecheck": "tsc -b --emitDeclarationOnly"
30
36
  },
31
37
  "keywords": [],
32
38
  "author": "",
@@ -36,7 +42,7 @@
36
42
  "@testing-library/jest-dom": "^6.9.1",
37
43
  "@testing-library/react": "^16.3.0",
38
44
  "@testing-library/react-render-stream": "^2.0.2",
39
- "@types/node": "^24.10.0",
45
+ "@types/node": "^24.10.4",
40
46
  "@types/react": "^19.2.2",
41
47
  "@vitejs/plugin-react": "^5.1.1",
42
48
  "@vitest/coverage-v8": "^4.0.13",
@@ -57,6 +63,7 @@
57
63
  "@apollo/client": "^4.0.9",
58
64
  "@graphql-tools/graphql-tag-pluck": "^8.3.23",
59
65
  "crypto-hash": "^4.0.0",
60
- "glob": "^11.0.3"
66
+ "glob": "^11.0.3",
67
+ "tslib": "^2.8.1"
61
68
  }
62
- }
69
+ }
@@ -4,9 +4,10 @@ import { DocumentTransform } from "@apollo/client";
4
4
  import { removeDirectivesFromDocument } from "@apollo/client/utilities/internal";
5
5
  import { parse } from "graphql";
6
6
  import { __DEV__ } from "@apollo/client/utilities/environment";
7
- import "../types/openai";
8
- import { ApplicationManifest } from "../types/application-manifest";
9
- import { ToolCallLink } from "../link/ToolCallLink";
7
+ import "../types/openai.js";
8
+ import type { ApplicationManifest } from "../types/application-manifest.js";
9
+ import { ToolCallLink } from "../link/ToolCallLink.js";
10
+ import type { FetchResult } from "@apollo/client";
10
11
 
11
12
  // TODO: In the future if/when we support PQs again, do pqLink.concat(toolCallLink)
12
13
  // Commenting this out for now.
@@ -50,16 +51,20 @@ export class ApolloClient extends BaseApolloClient {
50
51
  }
51
52
 
52
53
  async prefetchData() {
54
+ const toolOutput = window.openai.toolOutput as {
55
+ prefetch?: Record<string, FetchResult<any>>;
56
+ } | null;
57
+
53
58
  // Write prefetched data to the cache
54
59
  this.manifest.operations.forEach((operation) => {
55
60
  if (
56
61
  operation.prefetch &&
57
62
  operation.prefetchID &&
58
- window.openai.toolOutput?.prefetch?.[operation.prefetchID]
63
+ toolOutput?.prefetch?.[operation.prefetchID]
59
64
  ) {
60
65
  this.writeQuery({
61
66
  query: parse(operation.body),
62
- data: window.openai.toolOutput.prefetch[operation.prefetchID].data,
67
+ data: toolOutput.prefetch[operation.prefetchID].data,
63
68
  });
64
69
  }
65
70
 
@@ -1,9 +1,9 @@
1
1
  import { expect, test, describe, vi } from "vitest";
2
- import { ApolloClient } from "../ApolloClient";
3
- import { ApplicationManifest } from "../../types/application-manifest";
2
+ import { ApolloClient } from "../ApolloClient.js";
3
+ import type { ApplicationManifest } from "../../types/application-manifest.js";
4
4
  import { parse } from "graphql";
5
5
  import { ApolloLink, HttpLink, InMemoryCache } from "@apollo/client";
6
- import { ToolCallLink } from "../../link/ToolCallLink";
6
+ import { ToolCallLink } from "../../link/ToolCallLink.js";
7
7
 
8
8
  describe("Client Basics", () => {
9
9
  test("Should execute tool call when client.query is called", async () => {
@@ -56,11 +56,12 @@ describe("Client Basics", () => {
56
56
  },
57
57
  ],
58
58
  resource: "index.html",
59
- };
59
+ csp: { connectDomains: [], resourceDomains: [] },
60
+ } satisfies ApplicationManifest;
60
61
 
61
62
  const client = new ApolloClient({
62
63
  cache: new InMemoryCache(),
63
- manifest: manifest as ApplicationManifest,
64
+ manifest,
64
65
  });
65
66
 
66
67
  const variables = { id: "1" };
@@ -145,11 +146,12 @@ describe("prefetchData", () => {
145
146
  },
146
147
  ],
147
148
  resource: "index.html",
148
- };
149
+ csp: { connectDomains: [], resourceDomains: [] },
150
+ } satisfies ApplicationManifest;
149
151
 
150
152
  const client = new ApolloClient({
151
153
  cache: new InMemoryCache(),
152
- manifest: manifest as ApplicationManifest,
154
+ manifest,
153
155
  });
154
156
  await client.prefetchData();
155
157
 
@@ -428,11 +430,12 @@ describe("prefetchData", () => {
428
430
  },
429
431
  ],
430
432
  resource: "index.html",
431
- };
433
+ csp: { connectDomains: [], resourceDomains: [] },
434
+ } satisfies ApplicationManifest;
432
435
 
433
436
  const client = new ApolloClient({
434
437
  cache: new InMemoryCache(),
435
- manifest: manifest as ApplicationManifest,
438
+ manifest,
436
439
  });
437
440
  await client.prefetchData();
438
441
 
package/src/index.ts CHANGED
@@ -9,8 +9,8 @@ export type {
9
9
  Theme,
10
10
  UserAgent,
11
11
  UnknownObject,
12
- } from "./types/openai";
13
- export { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from "./types/openai";
12
+ } from "./types/openai.js";
13
+ export { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from "./types/openai.js";
14
14
 
15
15
  export type {
16
16
  ApplicationManifest,
@@ -18,21 +18,21 @@ export type {
18
18
  ManifestTool,
19
19
  ManifestExtraInput,
20
20
  ManifestCsp,
21
- } from "./types/application-manifest";
21
+ } from "./types/application-manifest.js";
22
22
 
23
- export { ToolUseProvider } from "./react/context/ToolUseContext";
24
- export { useOpenAiGlobal } from "./react/hooks/useOpenAiGlobal";
25
- export { useToolName } from "./react/hooks/useToolName";
26
- export { useToolInput } from "./react/hooks/useToolInput";
27
- export { useSendFollowUpMessage } from "./react/hooks/useSendFollowUpMessage";
28
- export { useRequestDisplayMode } from "./react/hooks/useRequestDisplayMode";
29
- export { useToolEffect } from "./react/hooks/useToolEffect";
30
- export { useOpenExternal } from "./react/hooks/useOpenExternal";
31
- export { useToolOutput } from "./react/hooks/useToolOutput";
32
- export { useToolResponseMetadata } from "./react/hooks/useToolResponseMetadata";
33
- export { useWidgetState } from "./react/hooks/useWidgetState";
23
+ export { ToolUseProvider } from "./react/context/ToolUseContext.js";
24
+ export { useOpenAiGlobal } from "./react/hooks/useOpenAiGlobal.js";
25
+ export { useToolName } from "./react/hooks/useToolName.js";
26
+ export { useToolInput } from "./react/hooks/useToolInput.js";
27
+ export { useSendFollowUpMessage } from "./react/hooks/useSendFollowUpMessage.js";
28
+ export { useRequestDisplayMode } from "./react/hooks/useRequestDisplayMode.js";
29
+ export { useToolEffect } from "./react/hooks/useToolEffect.js";
30
+ export { useOpenExternal } from "./react/hooks/useOpenExternal.js";
31
+ export { useToolOutput } from "./react/hooks/useToolOutput.js";
32
+ export { useToolResponseMetadata } from "./react/hooks/useToolResponseMetadata.js";
33
+ export { useWidgetState } from "./react/hooks/useWidgetState.js";
34
34
 
35
35
  export * from "@apollo/client";
36
- export { ApolloClient } from "./core/ApolloClient";
37
- export { ApolloProvider } from "./react/ApolloProvider";
38
- export { ToolCallLink } from "./link/ToolCallLink";
36
+ export { ApolloClient } from "./core/ApolloClient.js";
37
+ export { ApolloProvider } from "./react/ApolloProvider.js";
38
+ export { ToolCallLink } from "./link/ToolCallLink.js";
@@ -1,7 +1,8 @@
1
- import React, { ReactNode, useEffect, useState } from "react";
1
+ import type { ReactNode } from "react";
2
+ import { useEffect, useState } from "react";
2
3
  import { ApolloProvider as BaseApolloProvider } from "@apollo/client/react";
3
- import { ApolloClient } from "../core/ApolloClient";
4
- import { SET_GLOBALS_EVENT_TYPE } from "../types/openai";
4
+ import type { ApolloClient } from "../core/ApolloClient.js";
5
+ import { SET_GLOBALS_EVENT_TYPE } from "../types/openai.js";
5
6
 
6
7
  export declare namespace ApolloProvider {
7
8
  export interface Props {
@@ -1,8 +1,8 @@
1
1
  import { expect, test, vi } from "vitest";
2
- import { ApolloProvider } from "../ApolloProvider";
2
+ import { ApolloProvider } from "../ApolloProvider.js";
3
3
  import { render } from "@testing-library/react";
4
- import { ApolloClient } from "../../core/ApolloClient";
5
- import { SET_GLOBALS_EVENT_TYPE } from "../../types/openai";
4
+ import { ApolloClient } from "../../core/ApolloClient.js";
5
+ import { SET_GLOBALS_EVENT_TYPE } from "../../types/openai.js";
6
6
 
7
7
  test("Should call prefetch data when window.open is immediately available", () => {
8
8
  vi.stubGlobal("openai", {
@@ -1,4 +1,5 @@
1
- import React, { createContext, ReactNode, useContext, useState } from "react";
1
+ import type { ReactNode } from "react";
2
+ import { createContext, useContext, useState } from "react";
2
3
 
3
4
  interface ToolUseState {
4
5
  appName: string;
@@ -1,5 +1,5 @@
1
1
  import { expect, test, vi } from "vitest";
2
- import { useCallTool } from "../useCallTool";
2
+ import { useCallTool } from "../useCallTool.js";
3
3
 
4
4
  test("Should execute tool when returned function is called", async () => {
5
5
  vi.stubGlobal("openai", {
@@ -1,7 +1,7 @@
1
1
  import { expect, test, vi } from "vitest";
2
- import { useOpenAiGlobal } from "../useOpenAiGlobal";
2
+ import { useOpenAiGlobal } from "../useOpenAiGlobal.js";
3
3
  import { renderHook, act } from "@testing-library/react";
4
- import { SET_GLOBALS_EVENT_TYPE } from "../../../types/openai";
4
+ import { SET_GLOBALS_EVENT_TYPE } from "../../../types/openai.js";
5
5
 
6
6
  test("Should update value when globals are updated and event it triggered", async () => {
7
7
  vi.stubGlobal("openai", {
@@ -9,7 +9,7 @@ test("Should update value when globals are updated and event it triggered", asyn
9
9
  });
10
10
 
11
11
  const { result } = renderHook(() => useOpenAiGlobal("toolResponseMetadata"));
12
- const beforeValue = result.current.toolName;
12
+ const beforeValue = result.current?.toolName;
13
13
 
14
14
  act(() => {
15
15
  vi.stubGlobal("openai", {
@@ -24,7 +24,7 @@ test("Should update value when globals are updated and event it triggered", asyn
24
24
  );
25
25
  });
26
26
 
27
- const afterValue = result.current.toolName;
27
+ const afterValue = result.current?.toolName;
28
28
 
29
29
  expect(beforeValue).toBe("my-tool");
30
30
  expect(afterValue).toBe("my-other-tool");
@@ -36,7 +36,7 @@ test("Should not update value when event key does not match the provided key", a
36
36
  });
37
37
 
38
38
  const { result } = renderHook(() => useOpenAiGlobal("toolResponseMetadata"));
39
- const beforeValue = result.current.toolName;
39
+ const beforeValue = result.current?.toolName;
40
40
 
41
41
  act(() => {
42
42
  vi.stubGlobal("openai", {
@@ -49,7 +49,7 @@ test("Should not update value when event key does not match the provided key", a
49
49
  );
50
50
  });
51
51
 
52
- const afterValue = result.current.toolName;
52
+ const afterValue = result.current?.toolName;
53
53
 
54
54
  expect(beforeValue).toBe("my-tool");
55
55
  expect(afterValue).toBe("my-tool");
@@ -1,7 +1,7 @@
1
1
  import { expect, test, vi } from "vitest";
2
2
  import { renderHookToSnapshotStream } from "@testing-library/react-render-stream";
3
- import { useOpenExternal } from "../useOpenExternal";
4
- import { stubOpenAiGlobals } from "../../../testing/internal";
3
+ import { useOpenExternal } from "../useOpenExternal.js";
4
+ import { stubOpenAiGlobals } from "../../../testing/internal/index.js";
5
5
 
6
6
  test("calls the global openExternal function", async () => {
7
7
  const openExternalMock = vi.fn();
@@ -1,6 +1,6 @@
1
1
  import { expect, test, vi } from "vitest";
2
- import { useRequestDisplayMode } from "../useRequestDisplayMode";
3
- import { DisplayMode } from "../../../types/openai";
2
+ import { useRequestDisplayMode } from "../useRequestDisplayMode.js";
3
+ import type { DisplayMode } from "../../../types/openai.js";
4
4
 
5
5
  test("Should set display mode when returned function is called", async () => {
6
6
  vi.stubGlobal("openai", {
@@ -1,5 +1,5 @@
1
1
  import { expect, test, vi } from "vitest";
2
- import { useSendFollowUpMessage } from "../useSendFollowUpMessage";
2
+ import { useSendFollowUpMessage } from "../useSendFollowUpMessage.js";
3
3
 
4
4
  test("Should set display mode when returned function is called", async () => {
5
5
  vi.stubGlobal("openai", {
@@ -1,7 +1,7 @@
1
1
  import { expect, test, vi } from "vitest";
2
- import { useToolEffect } from "../useToolEffect";
2
+ import { useToolEffect } from "../useToolEffect.js";
3
3
  import { renderHook } from "@testing-library/react";
4
- import { ToolUseProvider } from "../../context/ToolUseContext";
4
+ import { ToolUseProvider } from "../../context/ToolUseContext.js";
5
5
 
6
6
  test("Should trigger effect when tool name matches toolResponseMetadata", async () => {
7
7
  vi.stubGlobal("openai", {
@@ -1,5 +1,5 @@
1
1
  import { expect, test, vi } from "vitest";
2
- import { useToolInput } from "../useToolInput";
2
+ import { useToolInput } from "../useToolInput.js";
3
3
  import { renderHook } from "@testing-library/react";
4
4
 
5
5
  test("Should return tool input when called", async () => {
@@ -1,5 +1,5 @@
1
1
  import { expect, test, vi } from "vitest";
2
- import { useToolName } from "../useToolName";
2
+ import { useToolName } from "../useToolName.js";
3
3
  import { renderHook } from "@testing-library/react";
4
4
 
5
5
  test("Should return tool input when called", async () => {
@@ -2,9 +2,9 @@ import { afterEach, expect, test, vi } from "vitest";
2
2
  import {
3
3
  dispatchStateChange,
4
4
  stubOpenAiGlobals,
5
- } from "../../../testing/internal";
5
+ } from "../../../testing/internal/index.js";
6
6
  import { renderHookToSnapshotStream } from "@testing-library/react-render-stream";
7
- import { useToolOutput } from "../useToolOutput";
7
+ import { useToolOutput } from "../useToolOutput.js";
8
8
 
9
9
  afterEach(() => {
10
10
  vi.unstubAllGlobals();
@@ -2,9 +2,9 @@ import { afterEach, expect, test, vi } from "vitest";
2
2
  import {
3
3
  dispatchStateChange,
4
4
  stubOpenAiGlobals,
5
- } from "../../../testing/internal";
5
+ } from "../../../testing/internal/index.js";
6
6
  import { renderHookToSnapshotStream } from "@testing-library/react-render-stream";
7
- import { useToolResponseMetadata } from "../useToolResponseMetadata";
7
+ import { useToolResponseMetadata } from "../useToolResponseMetadata.js";
8
8
 
9
9
  afterEach(() => {
10
10
  vi.unstubAllGlobals();
@@ -3,8 +3,8 @@ import {
3
3
  disableActEnvironment,
4
4
  renderHookToSnapshotStream,
5
5
  } from "@testing-library/react-render-stream";
6
- import { useWidgetState } from "../useWidgetState";
7
- import { stubOpenAiGlobals } from "../../../testing/internal";
6
+ import { useWidgetState } from "../useWidgetState.js";
7
+ import { stubOpenAiGlobals } from "../../../testing/internal/index.js";
8
8
 
9
9
  afterEach(() => {
10
10
  vi.unstubAllGlobals();
@@ -1,9 +1,6 @@
1
1
  import { useSyncExternalStore, useCallback } from "react";
2
- import {
3
- SET_GLOBALS_EVENT_TYPE,
4
- SetGlobalsEvent,
5
- OpenAiGlobals,
6
- } from "../../types/openai";
2
+ import type { SetGlobalsEvent, OpenAiGlobals } from "../../types/openai.js";
3
+ import { SET_GLOBALS_EVENT_TYPE } from "../../types/openai.js";
7
4
 
8
5
  export function useOpenAiGlobal<K extends keyof OpenAiGlobals>(
9
6
  key: K
@@ -1,5 +1,5 @@
1
1
  import { useCallback } from "react";
2
- import { API } from "../../types/openai";
2
+ import type { API } from "../../types/openai.js";
3
3
 
4
4
  type OpenExternalFn = API<any>["openExternal"];
5
5
 
@@ -1,4 +1,4 @@
1
- import { DisplayMode } from "../../types/openai";
1
+ import type { DisplayMode } from "../../types/openai.js";
2
2
 
3
3
  export const useRequestDisplayMode = () => {
4
4
  return async (args: { mode: DisplayMode }) => {
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect } from "react";
2
- import { useToolName } from "./useToolName";
3
- import { useToolInput } from "./useToolInput";
4
- import { useToolUseState } from "../context/ToolUseContext";
2
+ import { useToolName } from "./useToolName.js";
3
+ import { useToolInput } from "./useToolInput.js";
4
+ import { useToolUseState } from "../context/ToolUseContext.js";
5
5
 
6
6
  export const useToolEffect = (
7
7
  toolName: string | string[],
@@ -1,4 +1,4 @@
1
- import { useOpenAiGlobal } from "./useOpenAiGlobal";
1
+ import { useOpenAiGlobal } from "./useOpenAiGlobal.js";
2
2
 
3
3
  export const useToolInput = (): any => {
4
4
  const toolInput = useOpenAiGlobal("toolInput");
@@ -1,4 +1,4 @@
1
- import { useOpenAiGlobal } from "./useOpenAiGlobal";
1
+ import { useOpenAiGlobal } from "./useOpenAiGlobal.js";
2
2
 
3
3
  export const useToolName = (): string | undefined => {
4
4
  const toolResponseMetadata = useOpenAiGlobal("toolResponseMetadata");
@@ -1,4 +1,4 @@
1
- import { useOpenAiGlobal } from "./useOpenAiGlobal";
1
+ import { useOpenAiGlobal } from "./useOpenAiGlobal.js";
2
2
 
3
3
  export function useToolOutput() {
4
4
  return useOpenAiGlobal("toolOutput") ?? null;
@@ -1,4 +1,4 @@
1
- import { useOpenAiGlobal } from "./useOpenAiGlobal";
1
+ import { useOpenAiGlobal } from "./useOpenAiGlobal.js";
2
2
 
3
3
  export function useToolResponseMetadata() {
4
4
  return useOpenAiGlobal("toolResponseMetadata") ?? null;
@@ -1,6 +1,7 @@
1
- import { SetStateAction, useCallback, useState } from "react";
2
- import { UnknownObject } from "../../types/openai";
3
- import { useOpenAiGlobal } from "./useOpenAiGlobal";
1
+ import type { SetStateAction } from "react";
2
+ import { useCallback, useState } from "react";
3
+ import type { UnknownObject } from "../../types/openai.js";
4
+ import { useOpenAiGlobal } from "./useOpenAiGlobal.js";
4
5
 
5
6
  export function useWidgetState<T extends UnknownObject>(
6
7
  defaultState: T | (() => T)
@@ -1,2 +1,2 @@
1
- export { dispatchStateChange } from "./openai/dispatchStateChange";
2
- export { stubOpenAiGlobals } from "./openai/stubOpenAiGlobals";
1
+ export { dispatchStateChange } from "./openai/dispatchStateChange.js";
2
+ export { stubOpenAiGlobals } from "./openai/stubOpenAiGlobals.js";
@@ -1 +1 @@
1
- import "./toRerender";
1
+ import "./toRerender.js";
@@ -1,11 +1,11 @@
1
1
  // Vitest port of toRerender from
2
2
  // https://github.com/testing-library/react-render-stream-testing-library/blob/main/src/expect/renderStreamMatchers.ts
3
- import {
3
+ import type {
4
4
  Assertable,
5
5
  NextRenderOptions,
6
6
  RenderStream,
7
- WaitForRenderTimeoutError,
8
7
  } from "@testing-library/react-render-stream";
8
+ import { WaitForRenderTimeoutError } from "@testing-library/react-render-stream";
9
9
 
10
10
  import { expect } from "vitest";
11
11
 
@@ -1,4 +1,4 @@
1
- import { NextRenderOptions } from "@testing-library/react-render-stream";
1
+ import type { NextRenderOptions } from "@testing-library/react-render-stream";
2
2
 
3
3
  interface CustomMatchers<R = unknown> {
4
4
  toRerender: (options?: NextRenderOptions) => Promise<R>;
@@ -1,4 +1,4 @@
1
- import { SET_GLOBALS_EVENT_TYPE } from "../../../types/openai";
1
+ import { SET_GLOBALS_EVENT_TYPE } from "../../../types/openai.js";
2
2
 
3
3
  export function dispatchStateChange() {
4
4
  window.dispatchEvent(
@@ -1,6 +1,10 @@
1
1
  import { vi } from "vitest";
2
- import { API, OpenAiGlobals, UnknownObject } from "../../../types/openai";
3
- import { dispatchStateChange } from "./dispatchStateChange";
2
+ import type {
3
+ API,
4
+ OpenAiGlobals,
5
+ UnknownObject,
6
+ } from "../../../types/openai.js";
7
+ import { dispatchStateChange } from "./dispatchStateChange.js";
4
8
 
5
9
  export function stubOpenAiGlobals(globals?: Partial<API<any> & OpenAiGlobals>) {
6
10
  vi.stubGlobal("openai", {
@@ -7,6 +7,7 @@ export type ApplicationManifest = {
7
7
  resource: string;
8
8
  operations: ManifestOperation[];
9
9
  csp: ManifestCsp;
10
+ widgetSettings?: ManifestWidgetSettings;
10
11
  };
11
12
 
12
13
  export type ManifestOperation = {
@@ -26,6 +27,12 @@ export type ManifestTool = {
26
27
  extraInputs?: ManifestExtraInput[];
27
28
  };
28
29
 
30
+ export type ManifestWidgetSettings = {
31
+ description?: string;
32
+ domain?: string;
33
+ prefersBorder?: boolean;
34
+ };
35
+
29
36
  export type ManifestExtraInput = {
30
37
  name: string;
31
38
  description: string;
@@ -1,5 +1,5 @@
1
- import { expect, test, vi, describe, beforeEach, Mock } from "vitest";
2
- import { AbsoluteAssetImportsPlugin } from "../absolute_asset_imports_plugin";
1
+ import { expect, test } from "vitest";
2
+ import { AbsoluteAssetImportsPlugin } from "../absolute_asset_imports_plugin.js";
3
3
 
4
4
  test("Should replace root relative scripts with full url when origin is provided", () => {
5
5
  const ctx = {