@apollo/client-ai-apps 0.3.0 → 0.3.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/workflows/compare-build-output.yml +28 -0
- package/config/compare-build-output-to.sh +90 -0
- package/dist/core/ApolloClient.d.ts +14 -0
- package/dist/index.d.ts +17 -11
- package/dist/index.js +96 -44
- package/dist/react/ApolloProvider.d.ts +9 -0
- package/dist/react/context/ToolUseContext.d.ts +15 -0
- package/dist/{hooks → react/hooks}/useOpenAiGlobal.d.ts +1 -1
- package/dist/react/hooks/useOpenExternal.d.ts +3 -0
- package/dist/{hooks → react/hooks}/useRequestDisplayMode.d.ts +1 -1
- package/dist/{hooks → react/hooks}/useToolEffect.d.ts +0 -4
- package/dist/react/hooks/useToolOutput.d.ts +1 -0
- package/dist/react/hooks/useToolResponseMetadata.d.ts +1 -0
- package/dist/react/hooks/useWidgetState.d.ts +4 -0
- package/dist/types/openai.d.ts +1 -2
- package/package.json +5 -1
- package/src/{apollo_client/client.ts → core/ApolloClient.ts} +21 -17
- package/src/{apollo_client/client.test.ts → core/__tests__/ApolloClient.test.ts} +8 -9
- package/src/index.ts +36 -11
- package/src/{apollo_client/provider.tsx → react/ApolloProvider.tsx} +12 -8
- package/src/{apollo_client/provider.test.tsx → react/__tests__/ApolloProvider.test.tsx} +9 -9
- package/src/react/context/ToolUseContext.tsx +30 -0
- package/src/{hooks → react/hooks/__tests__}/useCallTool.test.ts +1 -1
- package/src/{hooks → react/hooks/__tests__}/useOpenAiGlobal.test.ts +2 -2
- package/src/react/hooks/__tests__/useOpenExternal.test.tsx +24 -0
- package/src/{hooks → react/hooks/__tests__}/useRequestDisplayMode.test.ts +2 -2
- package/src/{hooks → react/hooks/__tests__}/useSendFollowUpMessage.test.ts +1 -1
- package/src/{hooks → react/hooks/__tests__}/useToolEffect.test.tsx +2 -1
- package/src/{hooks → react/hooks/__tests__}/useToolInput.test.ts +1 -1
- package/src/{hooks → react/hooks/__tests__}/useToolName.test.ts +1 -1
- package/src/react/hooks/__tests__/useToolOutput.test.tsx +49 -0
- package/src/react/hooks/__tests__/useToolResponseMetadata.test.tsx +49 -0
- package/src/react/hooks/__tests__/useWidgetState.test.tsx +158 -0
- package/src/{hooks → react/hooks}/useOpenAiGlobal.ts +4 -4
- package/src/react/hooks/useOpenExternal.ts +11 -0
- package/src/{hooks → react/hooks}/useRequestDisplayMode.ts +1 -1
- package/src/{hooks → react/hooks}/useToolEffect.tsx +3 -26
- package/src/{hooks → react/hooks}/useToolName.ts +1 -1
- package/src/react/hooks/useToolOutput.ts +5 -0
- package/src/react/hooks/useToolResponseMetadata.ts +5 -0
- package/src/react/hooks/useWidgetState.ts +48 -0
- package/src/testing/internal/index.ts +2 -0
- package/src/testing/internal/matchers/index.d.ts +9 -0
- package/src/testing/internal/matchers/index.ts +1 -0
- package/src/testing/internal/matchers/toRerender.ts +49 -0
- package/src/testing/internal/openai/dispatchStateChange.ts +9 -0
- package/src/testing/internal/openai/stubOpenAiGlobals.ts +13 -0
- package/src/types/openai.ts +1 -1
- package/src/vite/{absolute_asset_imports_plugin.test.ts → __tests__/absolute_asset_imports_plugin.test.ts} +1 -1
- package/src/vite/{application_manifest_plugin.test.ts → __tests__/application_manifest_plugin.test.ts} +7 -7
- package/vitest-setup.ts +1 -0
- package/dist/apollo_client/client.d.ts +0 -13
- package/dist/apollo_client/provider.d.ts +0 -5
- /package/dist/{apollo_client/link → link}/ToolCallLink.d.ts +0 -0
- /package/dist/{hooks → react/hooks}/useSendFollowUpMessage.d.ts +0 -0
- /package/dist/{hooks → react/hooks}/useToolInput.d.ts +0 -0
- /package/dist/{hooks → react/hooks}/useToolName.d.ts +0 -0
- /package/src/{apollo_client/link → link}/ToolCallLink.ts +0 -0
- /package/src/{hooks → react/hooks}/useCallTool.ts +0 -0
- /package/src/{hooks → react/hooks}/useSendFollowUpMessage.ts +0 -0
- /package/src/{hooks → react/hooks}/useToolInput.ts +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NextRenderOptions } from "@testing-library/react-render-stream";
|
|
2
|
+
|
|
3
|
+
interface CustomMatchers<R = unknown> {
|
|
4
|
+
toRerender: (options?: NextRenderOptions) => Promise<R>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
declare module "vitest" {
|
|
8
|
+
interface Assertion<T = any> extends CustomMatchers<T> {}
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./toRerender";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Vitest port of toRerender from
|
|
2
|
+
// https://github.com/testing-library/react-render-stream-testing-library/blob/main/src/expect/renderStreamMatchers.ts
|
|
3
|
+
import {
|
|
4
|
+
Assertable,
|
|
5
|
+
NextRenderOptions,
|
|
6
|
+
RenderStream,
|
|
7
|
+
WaitForRenderTimeoutError,
|
|
8
|
+
} from "@testing-library/react-render-stream";
|
|
9
|
+
|
|
10
|
+
import { expect } from "vitest";
|
|
11
|
+
|
|
12
|
+
const assertableSymbol = Symbol.for(
|
|
13
|
+
"@testing-library/react-render-stream:assertable"
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
expect.extend({
|
|
17
|
+
async toRerender(actual, options: NextRenderOptions) {
|
|
18
|
+
const _stream = actual as RenderStream<any> | Assertable;
|
|
19
|
+
const stream = (
|
|
20
|
+
assertableSymbol in _stream ?
|
|
21
|
+
_stream[assertableSymbol]
|
|
22
|
+
: _stream) as RenderStream<any>;
|
|
23
|
+
const hint = this.utils.matcherHint("toRerender", undefined, undefined, {
|
|
24
|
+
isNot: this.isNot,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
let pass = true;
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
await stream.peekRender({ timeout: 100, ...options });
|
|
31
|
+
} catch (e) {
|
|
32
|
+
if (e instanceof WaitForRenderTimeoutError) {
|
|
33
|
+
pass = false;
|
|
34
|
+
} else {
|
|
35
|
+
throw e;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
pass,
|
|
41
|
+
message() {
|
|
42
|
+
return (
|
|
43
|
+
`${hint}\n\nExpected component to${pass ? " not" : ""} rerender, ` +
|
|
44
|
+
`but it did${pass ? "" : " not"}.`
|
|
45
|
+
);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { vi } from "vitest";
|
|
2
|
+
import { API, OpenAiGlobals, UnknownObject } from "../../../types/openai";
|
|
3
|
+
import { dispatchStateChange } from "./dispatchStateChange";
|
|
4
|
+
|
|
5
|
+
export function stubOpenAiGlobals(globals?: Partial<API<any> & OpenAiGlobals>) {
|
|
6
|
+
vi.stubGlobal("openai", {
|
|
7
|
+
setWidgetState: (state: UnknownObject) => {
|
|
8
|
+
window.openai.widgetState = state;
|
|
9
|
+
dispatchStateChange();
|
|
10
|
+
},
|
|
11
|
+
...globals,
|
|
12
|
+
});
|
|
13
|
+
}
|
package/src/types/openai.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect, test, vi, describe, beforeEach, Mock } from "vitest";
|
|
2
|
-
import { AbsoluteAssetImportsPlugin } from "
|
|
2
|
+
import { AbsoluteAssetImportsPlugin } from "../absolute_asset_imports_plugin";
|
|
3
3
|
|
|
4
4
|
test("Should replace root relative scripts with full url when origin is provided", () => {
|
|
5
5
|
const ctx = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect, test, vi, describe, beforeEach, Mock } from "vitest";
|
|
2
|
-
import { ApplicationManifestPlugin } from "
|
|
2
|
+
import { ApplicationManifestPlugin } from "../application_manifest_plugin";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import * as glob from "glob";
|
|
5
5
|
import path from "path";
|
|
@@ -675,16 +675,16 @@ describe("buildStart", () => {
|
|
|
675
675
|
} else if (path === root + "/my-component.tsx") {
|
|
676
676
|
return `
|
|
677
677
|
const MY_QUERY = gql\`
|
|
678
|
-
fragment A on User { firstName }
|
|
679
|
-
fragment B on User { lastName }
|
|
680
|
-
query HelloWorldQuery @tool(name: "hello-world", description: "This is an awesome tool!") {
|
|
678
|
+
fragment A on User { firstName }
|
|
679
|
+
fragment B on User { lastName }
|
|
680
|
+
query HelloWorldQuery @tool(name: "hello-world", description: "This is an awesome tool!") {
|
|
681
681
|
helloWorld {
|
|
682
682
|
...B
|
|
683
683
|
...A
|
|
684
684
|
...C
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
fragment C on User { middleName }
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
fragment C on User { middleName }
|
|
688
688
|
}\`;
|
|
689
689
|
`;
|
|
690
690
|
}
|
package/vitest-setup.ts
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ApolloClient } from "@apollo/client";
|
|
2
|
-
import "../types/openai";
|
|
3
|
-
import { ApplicationManifest } from "../types/application-manifest";
|
|
4
|
-
type ExtendedApolloClientOptions = Omit<ApolloClient.Options, "link"> & {
|
|
5
|
-
link?: ApolloClient.Options["link"];
|
|
6
|
-
manifest: ApplicationManifest;
|
|
7
|
-
};
|
|
8
|
-
export declare class ExtendedApolloClient extends ApolloClient {
|
|
9
|
-
manifest: ApplicationManifest;
|
|
10
|
-
constructor(options: ExtendedApolloClientOptions);
|
|
11
|
-
prefetchData(): Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|