@apollo/client-ai-apps 0.3.2 → 0.4.0
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/pr.yaml +52 -3
- package/.github/workflows/prep-release.yml +38 -0
- package/.github/workflows/release.yaml +8 -4
- package/.github/workflows/verify-changeset.yml +58 -0
- package/CHANGELOG.md +88 -0
- package/dist/core/ApolloClient.d.ts +3 -2
- package/dist/core/ApolloClient.d.ts.map +1 -0
- package/dist/core/ApolloClient.js +65 -0
- package/dist/core/ApolloClient.js.map +1 -0
- package/dist/index.d.ts +18 -18
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -279
- package/dist/index.js.map +1 -0
- package/dist/link/ToolCallLink.d.ts +1 -0
- package/dist/link/ToolCallLink.d.ts.map +1 -0
- package/dist/link/ToolCallLink.js +39 -0
- package/dist/link/ToolCallLink.js.map +1 -0
- package/dist/react/ApolloProvider.d.ts +4 -3
- package/dist/react/ApolloProvider.d.ts.map +1 -0
- package/dist/react/ApolloProvider.js +30 -0
- package/dist/react/ApolloProvider.js.map +1 -0
- package/dist/react/context/ToolUseContext.d.ts +4 -3
- package/dist/react/context/ToolUseContext.d.ts.map +1 -0
- package/dist/react/context/ToolUseContext.js +11 -0
- package/dist/react/context/ToolUseContext.js.map +1 -0
- package/dist/react/hooks/useCallTool.d.ts +4 -0
- package/dist/react/hooks/useCallTool.d.ts.map +1 -0
- package/dist/react/hooks/useCallTool.js +5 -0
- package/dist/react/hooks/useCallTool.js.map +1 -0
- package/dist/react/hooks/useOpenAiGlobal.d.ts +2 -1
- package/dist/react/hooks/useOpenAiGlobal.d.ts.map +1 -0
- package/dist/react/hooks/useOpenAiGlobal.js +20 -0
- package/dist/react/hooks/useOpenAiGlobal.js.map +1 -0
- package/dist/react/hooks/useOpenExternal.d.ts +1 -0
- package/dist/react/hooks/useOpenExternal.d.ts.map +1 -0
- package/dist/react/hooks/useOpenExternal.js +5 -0
- package/dist/react/hooks/useOpenExternal.js.map +1 -0
- package/dist/react/hooks/useRequestDisplayMode.d.ts +2 -1
- package/dist/react/hooks/useRequestDisplayMode.d.ts.map +1 -0
- package/dist/react/hooks/useRequestDisplayMode.js +6 -0
- package/dist/react/hooks/useRequestDisplayMode.js.map +1 -0
- package/dist/react/hooks/useSendFollowUpMessage.d.ts +1 -0
- package/dist/react/hooks/useSendFollowUpMessage.d.ts.map +1 -0
- package/dist/react/hooks/useSendFollowUpMessage.js +8 -0
- package/dist/react/hooks/useSendFollowUpMessage.js.map +1 -0
- package/dist/react/hooks/useToolEffect.d.ts +1 -0
- package/dist/react/hooks/useToolEffect.d.ts.map +1 -0
- package/dist/react/hooks/useToolEffect.js +28 -0
- package/dist/react/hooks/useToolEffect.js.map +1 -0
- package/dist/react/hooks/useToolInput.d.ts +1 -0
- package/dist/react/hooks/useToolInput.d.ts.map +1 -0
- package/dist/react/hooks/useToolInput.js +6 -0
- package/dist/react/hooks/useToolInput.js.map +1 -0
- package/dist/react/hooks/useToolName.d.ts +1 -0
- package/dist/react/hooks/useToolName.d.ts.map +1 -0
- package/dist/react/hooks/useToolName.js +6 -0
- package/dist/react/hooks/useToolName.js.map +1 -0
- package/dist/react/hooks/useToolOutput.d.ts +2 -1
- package/dist/react/hooks/useToolOutput.d.ts.map +1 -0
- package/dist/react/hooks/useToolOutput.js +5 -0
- package/dist/react/hooks/useToolOutput.js.map +1 -0
- package/dist/react/hooks/useToolResponseMetadata.d.ts +2 -1
- package/dist/react/hooks/useToolResponseMetadata.d.ts.map +1 -0
- package/dist/react/hooks/useToolResponseMetadata.js +5 -0
- package/dist/react/hooks/useToolResponseMetadata.js.map +1 -0
- package/dist/react/hooks/useWidgetState.d.ts +3 -2
- package/dist/react/hooks/useWidgetState.d.ts.map +1 -0
- package/dist/react/hooks/useWidgetState.js +27 -0
- package/dist/react/hooks/useWidgetState.js.map +1 -0
- package/dist/types/application-manifest.d.ts +15 -0
- package/dist/types/application-manifest.d.ts.map +1 -0
- package/dist/types/application-manifest.js +2 -0
- package/dist/types/application-manifest.js.map +1 -0
- package/dist/types/openai.d.ts +1 -0
- package/dist/types/openai.d.ts.map +1 -0
- package/dist/types/openai.js +6 -0
- package/dist/types/openai.js.map +1 -0
- package/dist/vite/absolute_asset_imports_plugin.d.ts +1 -0
- package/dist/vite/absolute_asset_imports_plugin.d.ts.map +1 -0
- package/dist/vite/absolute_asset_imports_plugin.js +17 -0
- package/dist/vite/absolute_asset_imports_plugin.js.map +1 -0
- package/dist/vite/application_manifest_plugin.d.ts +2 -1
- package/dist/vite/application_manifest_plugin.d.ts.map +1 -0
- package/dist/vite/application_manifest_plugin.js +317 -0
- package/dist/vite/application_manifest_plugin.js.map +1 -0
- package/dist/vite/index.d.ts +3 -2
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +3 -307
- package/dist/vite/index.js.map +1 -0
- package/knope.toml +63 -0
- package/package.json +19 -11
- package/src/core/ApolloClient.ts +10 -5
- package/src/core/__tests__/ApolloClient.test.ts +33 -10
- package/src/index.ts +19 -18
- package/src/react/ApolloProvider.tsx +4 -3
- package/src/react/__tests__/ApolloProvider.test.tsx +3 -3
- package/src/react/context/ToolUseContext.tsx +2 -1
- package/src/react/hooks/__tests__/useCallTool.test.ts +1 -1
- package/src/react/hooks/__tests__/useOpenAiGlobal.test.ts +6 -6
- package/src/react/hooks/__tests__/useOpenExternal.test.tsx +2 -2
- package/src/react/hooks/__tests__/useRequestDisplayMode.test.ts +2 -2
- package/src/react/hooks/__tests__/useSendFollowUpMessage.test.ts +1 -1
- package/src/react/hooks/__tests__/useToolEffect.test.tsx +2 -2
- package/src/react/hooks/__tests__/useToolInput.test.ts +1 -1
- package/src/react/hooks/__tests__/useToolName.test.ts +1 -1
- package/src/react/hooks/__tests__/useToolOutput.test.tsx +2 -2
- package/src/react/hooks/__tests__/useToolResponseMetadata.test.tsx +2 -2
- package/src/react/hooks/__tests__/useWidgetState.test.tsx +2 -2
- package/src/react/hooks/useOpenAiGlobal.ts +2 -5
- package/src/react/hooks/useOpenExternal.ts +1 -1
- package/src/react/hooks/useRequestDisplayMode.ts +1 -1
- package/src/react/hooks/useToolEffect.tsx +3 -3
- package/src/react/hooks/useToolInput.ts +1 -1
- package/src/react/hooks/useToolName.ts +1 -1
- package/src/react/hooks/useToolOutput.ts +1 -1
- package/src/react/hooks/useToolResponseMetadata.ts +1 -1
- package/src/react/hooks/useWidgetState.ts +4 -3
- package/src/testing/internal/index.ts +2 -2
- package/src/testing/internal/matchers/index.ts +1 -1
- package/src/testing/internal/matchers/toRerender.ts +2 -2
- package/src/testing/internal/matchers/{index.d.ts → types.ts} +1 -1
- package/src/testing/internal/openai/dispatchStateChange.ts +1 -1
- package/src/testing/internal/openai/stubOpenAiGlobals.ts +6 -2
- package/src/types/application-manifest.ts +16 -0
- package/src/vite/__tests__/absolute_asset_imports_plugin.test.ts +2 -2
- package/src/vite/__tests__/application_manifest_plugin.test.ts +460 -240
- package/src/vite/application_manifest_plugin.ts +253 -93
- package/src/vite/index.ts +2 -2
- package/tsconfig.base.build.json +13 -0
- package/tsconfig.base.json +21 -0
- package/tsconfig.config.json +9 -0
- package/tsconfig.json +10 -0
- package/tsconfig.src.build.json +14 -0
- package/tsconfig.src.json +17 -0
- package/tsconfig.test.json +20 -0
- package/tsconfig.vite.build.json +6 -0
- package/tsconfig.vite.json +16 -0
- package/scripts/build-vite.mjs +0 -18
- package/scripts/build.mjs +0 -7
- package/scripts/shared.mjs +0 -9
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application_manifest_plugin.js","sourceRoot":"","sources":["../../src/vite/application_manifest_plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,UAAU,E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AAC,MAAM,GAAG,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import { readFileSync, writeFileSync, mkdirSync } from \"fs\";\nimport { glob } from \"glob\";\nimport { gqlPluckFromCodeStringSync } from \"@graphql-tools/graphql-tag-pluck\";\nimport { createHash } from \"crypto\";\nimport type {\n ArgumentNode,\n ListTypeNode,\n NamedTypeNode,\n NonNullTypeNode,\n TypeNode,\n ValueNode,\n DocumentNode,\n OperationDefinitionNode,\n DirectiveNode,\n} from \"graphql\";\nimport { Kind, parse, print } from \"graphql\";\nimport { ApolloClient, ApolloLink, InMemoryCache } from \"@apollo/client\";\nimport { removeDirectivesFromDocument } from \"@apollo/client/utilities/internal\";\nimport { of } from \"rxjs\";\nimport path from \"path\";\nimport type {\n ApplicationManifest,\n ManifestExtraInput,\n ManifestLabels,\n ManifestTool,\n ManifestWidgetSettings,\n} from \"../types/application-manifest.js\";\n\nconst root = process.cwd();\n\nfunction getRawValue(node: ValueNode): unknown {\n switch (node.kind) {\n case Kind.STRING:\n case Kind.BOOLEAN:\n return node.value;\n case Kind.LIST:\n return node.values.map(getRawValue);\n case Kind.OBJECT:\n return node.fields.reduce<Record<string, any>>((acc, field) => {\n acc[field.name.value] = getRawValue(field.value);\n return acc;\n }, {});\n default:\n throw new Error(\n `Error when parsing directive values: unexpected type '${node.kind}'`\n );\n }\n}\n\nfunction getArgumentValue(\n argument: ArgumentNode,\n expectedType: Kind.STRING\n): string;\n\nfunction getArgumentValue(\n argument: ArgumentNode,\n expectedType: Kind.BOOLEAN\n): boolean;\n\nfunction getArgumentValue(\n argument: ArgumentNode,\n expectedType: Kind.LIST\n): unknown[];\n\nfunction getArgumentValue(\n argument: ArgumentNode,\n expectedType: Kind.OBJECT\n): Record<string, unknown>;\n\nfunction getArgumentValue(argument: ArgumentNode, expectedType: Kind) {\n const argumentType = argument.value.kind;\n\n invariant(\n argumentType === expectedType,\n `Expected argument '${argument.name.value}' to be of type '${expectedType}' but found '${argumentType}' instead.`\n );\n\n return getRawValue(argument.value);\n}\n\ninterface GetArgumentNodeOptions {\n required?: boolean;\n}\n\nfunction getDirectiveArgument(\n argumentName: string,\n directive: DirectiveNode,\n opts: GetArgumentNodeOptions & { required: true }\n): ArgumentNode;\n\nfunction getDirectiveArgument(\n argumentName: string,\n directive: DirectiveNode,\n opts?: GetArgumentNodeOptions\n): ArgumentNode | undefined;\n\nfunction getDirectiveArgument(\n argumentName: string,\n directive: DirectiveNode,\n { required = false }: { required?: boolean } = {}\n) {\n const argument = directive.arguments?.find(\n (directiveArgument) => directiveArgument.name.value === argumentName\n );\n\n invariant(\n argument || !required,\n `'${argumentName}' argument must be supplied for @tool`\n );\n\n return argument;\n}\n\nfunction getTypeName(type: TypeNode): string {\n let t = type;\n while (t.kind === \"NonNullType\" || t.kind === \"ListType\") {\n t = (t as NonNullTypeNode | ListTypeNode).type;\n }\n return (t as NamedTypeNode).name.value;\n}\n\nexport const ApplicationManifestPlugin = () => {\n const cache = new Map();\n let packageJson: any = null;\n let config: any = null;\n\n const clientCache = new InMemoryCache();\n const client = new ApolloClient({\n cache: clientCache,\n link: new ApolloLink((operation) => {\n const body = print(\n removeClientDirective(sortTopLevelDefinitions(operation.query))\n );\n const name = operation.operationName;\n const definition = operation.query.definitions.find(\n (d) => d.kind === \"OperationDefinition\"\n );\n\n // Use `operation.query` so that the error reflects the end-user defined\n // document, not our sorted one\n invariant(\n definition,\n `Document does not contain an operation:\\n${print(operation.query)}`\n );\n\n const { directives, operation: type } = definition;\n\n const variables = definition.variableDefinitions?.reduce(\n (obj, varDef) => ({\n ...obj,\n [varDef.variable.name.value]: getTypeName(varDef.type),\n }),\n {}\n );\n\n const prefetch = directives?.some((d) => d.name.value === \"prefetch\");\n const id = createHash(\"sha256\").update(body).digest(\"hex\");\n // TODO: For now, you can only have 1 operation marked as prefetch. In the future, we'll likely support more than 1, and the \"prefetchId\" will be defined on the `@prefetch` itself as an argument\n const prefetchID = prefetch ? \"__anonymous\" : undefined;\n\n const tools = directives\n ?.filter((d) => d.name.value === \"tool\")\n .map((directive) => {\n const name = getArgumentValue(\n getDirectiveArgument(\"name\", directive, { required: true }),\n Kind.STRING\n );\n\n invariant(\n name.indexOf(\" \") === -1,\n `Tool with name \"${name}\" contains spaces which is not allowed.`\n );\n\n const description = getArgumentValue(\n getDirectiveArgument(\"description\", directive, { required: true }),\n Kind.STRING\n );\n\n const extraInputsNode = getDirectiveArgument(\n \"extraInputs\",\n directive\n );\n\n const labelsNode = getDirectiveArgument(\"labels\", directive);\n\n const toolOptions: ManifestTool = {\n name,\n description,\n };\n\n if (extraInputsNode) {\n toolOptions.extraInputs = getArgumentValue(\n extraInputsNode,\n Kind.LIST\n ) as ManifestExtraInput[];\n }\n\n if (labelsNode) {\n const labels = getLabelsFromConfig(\n getArgumentValue(labelsNode, Kind.OBJECT)\n );\n\n if (labels) {\n toolOptions.labels = labels;\n }\n }\n\n return toolOptions;\n });\n\n // TODO: Make this object satisfy the `ManifestOperation` type. Currently\n // it errors because we need more validation on a few of these fields\n return of({\n data: { id, name, type, body, variables, prefetch, prefetchID, tools },\n });\n }),\n });\n\n const processFile = async (file: string) => {\n const code = readFileSync(file, \"utf-8\");\n\n if (!code.includes(\"gql\")) return;\n\n const fileHash = createHash(\"md5\").update(code).digest(\"hex\");\n if (cache.get(\"file\")?.hash === fileHash) return;\n const sources = gqlPluckFromCodeStringSync(file, code, {\n modules: [\n { name: \"graphql-tag\", identifier: \"gql\" },\n { name: \"@apollo/client\", identifier: \"gql\" },\n ],\n }).map((source) => ({\n node: parse(source.body),\n file,\n location: source.locationOffset,\n }));\n\n const operations = [];\n for (const source of sources) {\n const type = (\n source.node.definitions.find(\n (d) => d.kind === \"OperationDefinition\"\n ) as OperationDefinitionNode\n ).operation;\n\n let result;\n if (type === \"query\") {\n result = await client.query({\n query: source.node,\n fetchPolicy: \"no-cache\",\n });\n } else if (type === \"mutation\") {\n result = await client.mutate({\n mutation: source.node,\n fetchPolicy: \"no-cache\",\n });\n } else {\n throw new Error(\n \"Found an unsupported operation type. Only Query and Mutation are supported.\"\n );\n }\n operations.push(result.data);\n }\n\n cache.set(file, {\n file: file,\n hash: fileHash,\n operations,\n });\n };\n\n const generateManifest = async () => {\n const operations = Array.from(cache.values()).flatMap(\n (entry) => entry.operations\n );\n\n invariant(\n operations.filter((o) => o.prefetch).length <= 1,\n \"Found multiple operations marked as `@prefetch`. You can only mark 1 operation with `@prefetch`.\"\n );\n\n let resource = \"\";\n if (config.command === \"serve\") {\n resource =\n packageJson.entry?.[config.mode] ??\n `http${config.server.https ? \"s\" : \"\"}://${config.server.host ?? \"localhost\"}:${config.server.port}`;\n } else {\n let entryPoint = packageJson.entry?.[config.mode];\n if (entryPoint) {\n resource = entryPoint;\n } else if (config.mode === \"production\") {\n resource = \"index.html\";\n } else {\n throw new Error(\n `No entry point found for mode \"${config.mode}\". Entry points other than \"development\" and \"production\" must be defined in package.json file.`\n );\n }\n }\n\n const manifest: ApplicationManifest = {\n format: \"apollo-ai-app-manifest\",\n version: \"1\",\n name: packageJson.name,\n description: packageJson.description,\n hash: createHash(\"sha256\").update(Date.now().toString()).digest(\"hex\"),\n operations: Array.from(cache.values()).flatMap(\n (entry) => entry.operations\n ),\n resource,\n csp: {\n connectDomains: packageJson.csp?.connectDomains ?? [],\n frameDomains: packageJson.csp?.frameDomains ?? [],\n redirectDomains: packageJson.csp?.redirectDomains ?? [],\n resourceDomains: packageJson.csp?.resourceDomains ?? [],\n },\n };\n\n if (\n packageJson.widgetSettings &&\n isNonEmptyObject(packageJson.widgetSettings)\n ) {\n function validateWidgetSetting(\n key: keyof ManifestWidgetSettings,\n type: \"string\" | \"boolean\"\n ) {\n if (key in widgetSettings) {\n invariant(\n typeof widgetSettings[key] === type,\n `Expected 'widgetSettings.${key}' to be of type '${type}' but found '${typeof widgetSettings[key]}' instead.`\n );\n }\n }\n\n const widgetSettings =\n packageJson.widgetSettings as ManifestWidgetSettings;\n\n validateWidgetSetting(\"prefersBorder\", \"boolean\");\n validateWidgetSetting(\"description\", \"string\");\n validateWidgetSetting(\"domain\", \"string\");\n\n manifest.widgetSettings = packageJson.widgetSettings;\n }\n\n if (packageJson.labels) {\n const labels = getLabelsFromConfig(packageJson.labels);\n\n if (labels) {\n manifest.labels = labels;\n }\n }\n\n // Always write to build directory so the MCP server picks it up\n const dest = path.resolve(\n root,\n config.build.outDir,\n \".application-manifest.json\"\n );\n mkdirSync(path.dirname(dest), { recursive: true });\n writeFileSync(dest, JSON.stringify(manifest));\n\n // Always write to the dev location so that the app can bundle the manifest content\n writeFileSync(\".application-manifest.json\", JSON.stringify(manifest));\n };\n\n return {\n name: \"OperationManifest\",\n\n async configResolved(resolvedConfig: any) {\n config = resolvedConfig;\n },\n\n async buildStart() {\n // Read package.json on start\n packageJson = JSON.parse(readFileSync(\"package.json\", \"utf-8\"));\n\n // Scan all files on startup\n const files = await glob(\"src/**/*.{ts,tsx,js,jsx}\");\n\n for (const file of files) {\n const fullPath = path.resolve(root, file);\n await processFile(fullPath);\n }\n\n // We don't want to do this here on builds cause it just gets overwritten anyways. We'll call it on writeBundle instead.\n if (config.command === \"serve\") {\n await generateManifest();\n }\n },\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n configureServer(server: any) {\n server.watcher.on(\"change\", async (file: string) => {\n if (file.endsWith(\"package.json\")) {\n packageJson = JSON.parse(readFileSync(\"package.json\", \"utf-8\"));\n await generateManifest();\n } else if (file.match(/\\.(jsx?|tsx?)$/)) {\n await processFile(file);\n await generateManifest();\n }\n });\n },\n\n async writeBundle() {\n await generateManifest();\n },\n };\n};\n\n// Sort the definitions in this document so that operations come before fragments,\n// and so that each kind of definition is sorted by name.\nexport function sortTopLevelDefinitions(query: DocumentNode): DocumentNode {\n const definitions = [...query.definitions];\n // We want to avoid unnecessary dependencies, so write out a comparison\n // function instead of using _.orderBy.\n definitions.sort((a, b) => {\n // This is a reverse sort by kind, so that OperationDefinition precedes FragmentDefinition.\n if (a.kind > b.kind) {\n return -1;\n }\n if (a.kind < b.kind) {\n return 1;\n }\n\n // Extract the name from each definition. Jump through some hoops because\n // non-executable definitions don't have to have names (even though any\n // DocumentNode actually passed here should only have executable\n // definitions).\n const aName =\n a.kind === \"OperationDefinition\" || a.kind === \"FragmentDefinition\" ?\n (a.name?.value ?? \"\")\n : \"\";\n const bName =\n b.kind === \"OperationDefinition\" || b.kind === \"FragmentDefinition\" ?\n (b.name?.value ?? \"\")\n : \"\";\n\n // Sort by name ascending.\n if (aName < bName) {\n return -1;\n }\n if (aName > bName) {\n return 1;\n }\n\n // Assuming that the document is \"valid\", no operation or fragment name can appear\n // more than once, so we don't need to differentiate further to have a deterministic\n // sort.\n return 0;\n });\n return {\n ...query,\n definitions,\n };\n}\n\ninterface LabelConfig {\n toolInvocation?: {\n invoking?: string;\n invoked?: string;\n };\n}\n\nfunction getLabelsFromConfig(config: LabelConfig): ManifestLabels | undefined {\n if (!(\"toolInvocation\" in config)) {\n return;\n }\n\n const { toolInvocation } = config;\n const labels: ManifestLabels = {};\n\n if (Object.hasOwn(toolInvocation, \"invoking\")) {\n validateType(toolInvocation.invoking, \"string\", {\n propertyName: \"labels.toolInvocation.invoking\",\n });\n\n labels[\"toolInvocation/invoking\"] = toolInvocation.invoking;\n }\n\n if (Object.hasOwn(toolInvocation, \"invoked\")) {\n validateType(toolInvocation.invoked, \"string\", {\n propertyName: \"labels.toolInvocation.invoked\",\n });\n\n labels[\"toolInvocation/invoked\"] = toolInvocation.invoked;\n }\n\n if (isNonEmptyObject(labels)) {\n return labels;\n }\n}\n\nfunction removeClientDirective(doc: DocumentNode) {\n return removeDirectivesFromDocument(\n [{ name: \"prefetch\" }, { name: \"tool\" }],\n doc\n )!;\n}\n\nfunction invariant(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n\n// possible values of `typeof`\ntype TypeofResult =\n | \"string\"\n | \"number\"\n | \"bigint\"\n | \"boolean\"\n | \"symbol\"\n | \"undefined\"\n | \"object\"\n | \"function\";\n\ntype TypeofResultToConcreteType<T extends TypeofResult> =\n T extends \"string\" ? string\n : T extends \"number\" ? number\n : T extends \"bigint\" ? bigint\n : T extends \"boolean\" ? boolean\n : T extends \"symbol\" ? symbol\n : T extends \"undefined\" ? undefined\n : T extends \"object\" ? object\n : T extends \"function\" ? Function\n : never;\n\nfunction validateType<Typeof extends TypeofResult>(\n value: unknown,\n expectedType: Typeof,\n options: { propertyName: string }\n): asserts value is TypeofResultToConcreteType<Typeof> {\n invariant(\n typeof value === expectedType,\n `Expected '${options.propertyName}' to be of type '${expectedType}' but found '${typeof value}' instead.`\n );\n}\n\nfunction isNonEmptyObject(obj: object) {\n return Object.keys(obj).length > 0;\n}\n"]}
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export * from "./application_manifest_plugin";
|
|
2
|
-
export * from "./absolute_asset_imports_plugin";
|
|
1
|
+
export * from "./application_manifest_plugin.js";
|
|
2
|
+
export * from "./absolute_asset_imports_plugin.js";
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,oCAAoC,CAAC"}
|
package/dist/vite/index.js
CHANGED
|
@@ -1,307 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { gqlPluckFromCodeStringSync } from "@graphql-tools/graphql-tag-pluck";
|
|
5
|
-
import { createHash } from "crypto";
|
|
6
|
-
import {
|
|
7
|
-
Kind,
|
|
8
|
-
parse,
|
|
9
|
-
print,
|
|
10
|
-
visit
|
|
11
|
-
} from "graphql";
|
|
12
|
-
import { ApolloClient, ApolloLink, InMemoryCache } from "@apollo/client";
|
|
13
|
-
import Observable from "rxjs";
|
|
14
|
-
import path from "path";
|
|
15
|
-
var root = process.cwd();
|
|
16
|
-
var getRawValue = (node) => {
|
|
17
|
-
switch (node.kind) {
|
|
18
|
-
case Kind.STRING:
|
|
19
|
-
case Kind.BOOLEAN:
|
|
20
|
-
return node.value;
|
|
21
|
-
case Kind.LIST:
|
|
22
|
-
return node.values.map(getRawValue);
|
|
23
|
-
case Kind.OBJECT:
|
|
24
|
-
return node.fields.reduce((acc, field) => {
|
|
25
|
-
acc[field.name.value] = getRawValue(field.value);
|
|
26
|
-
return acc;
|
|
27
|
-
}, {});
|
|
28
|
-
default:
|
|
29
|
-
throw new Error(
|
|
30
|
-
`Error when parsing directive values: unexpected type '${node.kind}'`
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var getTypedDirectiveArgument = (argumentName, expectedType, directiveArguments) => {
|
|
35
|
-
if (!directiveArguments || directiveArguments.length === 0) {
|
|
36
|
-
return void 0;
|
|
37
|
-
}
|
|
38
|
-
let argument = directiveArguments.find(
|
|
39
|
-
(directiveArgument) => directiveArgument.name.value === argumentName
|
|
40
|
-
);
|
|
41
|
-
if (!argument) {
|
|
42
|
-
return void 0;
|
|
43
|
-
}
|
|
44
|
-
if (argument.value.kind != expectedType) {
|
|
45
|
-
throw new Error(
|
|
46
|
-
`Expected argument '${argumentName}' to be of type '${expectedType}' but found '${argument.value.kind}' instead.`
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
return getRawValue(argument.value);
|
|
50
|
-
};
|
|
51
|
-
function getTypeName(type) {
|
|
52
|
-
let t = type;
|
|
53
|
-
while (t.kind === "NonNullType" || t.kind === "ListType") {
|
|
54
|
-
t = t.type;
|
|
55
|
-
}
|
|
56
|
-
return t.name.value;
|
|
57
|
-
}
|
|
58
|
-
var ApplicationManifestPlugin = () => {
|
|
59
|
-
const cache = /* @__PURE__ */ new Map();
|
|
60
|
-
let packageJson = null;
|
|
61
|
-
let config = null;
|
|
62
|
-
const clientCache = new InMemoryCache();
|
|
63
|
-
const client = new ApolloClient({
|
|
64
|
-
cache: clientCache,
|
|
65
|
-
link: new ApolloLink((operation) => {
|
|
66
|
-
const body = print(
|
|
67
|
-
removeClientDirective(sortTopLevelDefinitions(operation.query))
|
|
68
|
-
);
|
|
69
|
-
const name = operation.operationName;
|
|
70
|
-
const variables = operation.query.definitions.find(
|
|
71
|
-
(d) => d.kind === "OperationDefinition"
|
|
72
|
-
).variableDefinitions?.reduce(
|
|
73
|
-
(obj, varDef) => ({
|
|
74
|
-
...obj,
|
|
75
|
-
[varDef.variable.name.value]: getTypeName(varDef.type)
|
|
76
|
-
}),
|
|
77
|
-
{}
|
|
78
|
-
);
|
|
79
|
-
const type = operation.query.definitions.find(
|
|
80
|
-
(d) => d.kind === "OperationDefinition"
|
|
81
|
-
).operation;
|
|
82
|
-
const prefetch = operation.query.definitions.find(
|
|
83
|
-
(d) => d.kind === "OperationDefinition"
|
|
84
|
-
).directives?.some((d) => d.name.value === "prefetch");
|
|
85
|
-
const id = createHash("sha256").update(body).digest("hex");
|
|
86
|
-
const prefetchID = prefetch ? "__anonymous" : void 0;
|
|
87
|
-
const tools = operation.query.definitions.find(
|
|
88
|
-
(d) => d.kind === "OperationDefinition"
|
|
89
|
-
).directives?.filter((d) => d.name.value === "tool").map((directive) => {
|
|
90
|
-
const name2 = getTypedDirectiveArgument(
|
|
91
|
-
"name",
|
|
92
|
-
Kind.STRING,
|
|
93
|
-
directive.arguments
|
|
94
|
-
);
|
|
95
|
-
const description = getTypedDirectiveArgument(
|
|
96
|
-
"description",
|
|
97
|
-
Kind.STRING,
|
|
98
|
-
directive.arguments
|
|
99
|
-
);
|
|
100
|
-
const extraInputs = getTypedDirectiveArgument(
|
|
101
|
-
"extraInputs",
|
|
102
|
-
Kind.LIST,
|
|
103
|
-
directive.arguments
|
|
104
|
-
);
|
|
105
|
-
if (!name2) {
|
|
106
|
-
throw new Error("'name' argument must be supplied for @tool");
|
|
107
|
-
}
|
|
108
|
-
if (name2.indexOf(" ") > -1) {
|
|
109
|
-
throw new Error(
|
|
110
|
-
`Tool with name "${name2}" contains spaces which is not allowed.`
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
if (!description) {
|
|
114
|
-
throw new Error(
|
|
115
|
-
"'description' argument must be supplied for @tool"
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
return {
|
|
119
|
-
name: name2,
|
|
120
|
-
description,
|
|
121
|
-
extraInputs
|
|
122
|
-
};
|
|
123
|
-
});
|
|
124
|
-
return Observable.of({
|
|
125
|
-
data: { id, name, type, body, variables, prefetch, prefetchID, tools }
|
|
126
|
-
});
|
|
127
|
-
})
|
|
128
|
-
});
|
|
129
|
-
const processFile = async (file) => {
|
|
130
|
-
const code = readFileSync(file, "utf-8");
|
|
131
|
-
if (!code.includes("gql")) return;
|
|
132
|
-
const fileHash = createHash("md5").update(code).digest("hex");
|
|
133
|
-
if (cache.get("file")?.hash === fileHash) return;
|
|
134
|
-
const sources = await gqlPluckFromCodeStringSync(file, code, {
|
|
135
|
-
modules: [
|
|
136
|
-
{ name: "graphql-tag", identifier: "gql" },
|
|
137
|
-
{ name: "@apollo/client", identifier: "gql" }
|
|
138
|
-
]
|
|
139
|
-
}).map((source) => ({
|
|
140
|
-
node: parse(source.body),
|
|
141
|
-
file,
|
|
142
|
-
location: source.locationOffset
|
|
143
|
-
}));
|
|
144
|
-
const operations = [];
|
|
145
|
-
for (const source of sources) {
|
|
146
|
-
const type = source.node.definitions.find(
|
|
147
|
-
(d) => d.kind === "OperationDefinition"
|
|
148
|
-
).operation;
|
|
149
|
-
let result;
|
|
150
|
-
if (type === "query") {
|
|
151
|
-
result = await client.query({
|
|
152
|
-
query: source.node,
|
|
153
|
-
fetchPolicy: "no-cache"
|
|
154
|
-
});
|
|
155
|
-
} else if (type === "mutation") {
|
|
156
|
-
result = await client.mutate({
|
|
157
|
-
mutation: source.node,
|
|
158
|
-
fetchPolicy: "no-cache"
|
|
159
|
-
});
|
|
160
|
-
} else {
|
|
161
|
-
throw new Error(
|
|
162
|
-
"Found an unsupported operation type. Only Query and Mutation are supported."
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
operations.push(result.data);
|
|
166
|
-
}
|
|
167
|
-
cache.set(file, {
|
|
168
|
-
file,
|
|
169
|
-
hash: fileHash,
|
|
170
|
-
operations
|
|
171
|
-
});
|
|
172
|
-
};
|
|
173
|
-
const generateManifest = async () => {
|
|
174
|
-
const operations = Array.from(cache.values()).flatMap(
|
|
175
|
-
(entry) => entry.operations
|
|
176
|
-
);
|
|
177
|
-
if (operations.filter((o) => o.prefetch).length > 1) {
|
|
178
|
-
throw new Error(
|
|
179
|
-
"Found multiple operations marked as `@prefetch`. You can only mark 1 operation with `@prefetch`."
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
let resource = "";
|
|
183
|
-
if (config.command === "serve") {
|
|
184
|
-
resource = packageJson.entry?.[config.mode] ?? `http${config.server.https ? "s" : ""}://${config.server.host ?? "localhost"}:${config.server.port}`;
|
|
185
|
-
} else {
|
|
186
|
-
let entryPoint = packageJson.entry?.[config.mode];
|
|
187
|
-
if (entryPoint) {
|
|
188
|
-
resource = entryPoint;
|
|
189
|
-
} else if (config.mode === "production") {
|
|
190
|
-
resource = "index.html";
|
|
191
|
-
} else {
|
|
192
|
-
throw new Error(
|
|
193
|
-
`No entry point found for mode "${config.mode}". Entry points other than "development" and "production" must be defined in package.json file.`
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
const manifest = {
|
|
198
|
-
format: "apollo-ai-app-manifest",
|
|
199
|
-
version: "1",
|
|
200
|
-
name: packageJson.name,
|
|
201
|
-
description: packageJson.description,
|
|
202
|
-
hash: createHash("sha256").update(Date.now().toString()).digest("hex"),
|
|
203
|
-
operations: Array.from(cache.values()).flatMap(
|
|
204
|
-
(entry) => entry.operations
|
|
205
|
-
),
|
|
206
|
-
resource,
|
|
207
|
-
csp: {
|
|
208
|
-
connectDomains: packageJson.csp?.connectDomains ?? [],
|
|
209
|
-
resourceDomains: packageJson.csp?.resourceDomains ?? []
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
const dest = path.resolve(
|
|
213
|
-
root,
|
|
214
|
-
config.build.outDir,
|
|
215
|
-
".application-manifest.json"
|
|
216
|
-
);
|
|
217
|
-
mkdirSync(path.dirname(dest), { recursive: true });
|
|
218
|
-
writeFileSync(dest, JSON.stringify(manifest));
|
|
219
|
-
writeFileSync(".application-manifest.json", JSON.stringify(manifest));
|
|
220
|
-
};
|
|
221
|
-
return {
|
|
222
|
-
name: "OperationManifest",
|
|
223
|
-
async configResolved(resolvedConfig) {
|
|
224
|
-
config = resolvedConfig;
|
|
225
|
-
},
|
|
226
|
-
async buildStart() {
|
|
227
|
-
packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
|
|
228
|
-
const files = await glob("src/**/*.{ts,tsx,js,jsx}");
|
|
229
|
-
for (const file of files) {
|
|
230
|
-
const fullPath = path.resolve(root, file);
|
|
231
|
-
await processFile(fullPath);
|
|
232
|
-
}
|
|
233
|
-
if (config.command === "serve") {
|
|
234
|
-
await generateManifest();
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
238
|
-
configureServer(server) {
|
|
239
|
-
server.watcher.on("change", async (file) => {
|
|
240
|
-
if (file.endsWith("package.json")) {
|
|
241
|
-
packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
|
|
242
|
-
await generateManifest();
|
|
243
|
-
} else if (file.match(/\.(jsx?|tsx?)$/)) {
|
|
244
|
-
await processFile(file);
|
|
245
|
-
await generateManifest();
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
},
|
|
249
|
-
async writeBundle() {
|
|
250
|
-
await generateManifest();
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
function sortTopLevelDefinitions(query) {
|
|
255
|
-
const definitions = [...query.definitions];
|
|
256
|
-
definitions.sort((a, b) => {
|
|
257
|
-
if (a.kind > b.kind) {
|
|
258
|
-
return -1;
|
|
259
|
-
}
|
|
260
|
-
if (a.kind < b.kind) {
|
|
261
|
-
return 1;
|
|
262
|
-
}
|
|
263
|
-
const aName = a.kind === "OperationDefinition" || a.kind === "FragmentDefinition" ? a.name?.value ?? "" : "";
|
|
264
|
-
const bName = b.kind === "OperationDefinition" || b.kind === "FragmentDefinition" ? b.name?.value ?? "" : "";
|
|
265
|
-
if (aName < bName) {
|
|
266
|
-
return -1;
|
|
267
|
-
}
|
|
268
|
-
if (aName > bName) {
|
|
269
|
-
return 1;
|
|
270
|
-
}
|
|
271
|
-
return 0;
|
|
272
|
-
});
|
|
273
|
-
return {
|
|
274
|
-
...query,
|
|
275
|
-
definitions
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
function removeClientDirective(doc) {
|
|
279
|
-
return visit(doc, {
|
|
280
|
-
OperationDefinition(node) {
|
|
281
|
-
return {
|
|
282
|
-
...node,
|
|
283
|
-
directives: node.directives?.filter(
|
|
284
|
-
(d) => d.name.value !== "prefetch" && d.name.value !== "tool"
|
|
285
|
-
)
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// src/vite/absolute_asset_imports_plugin.ts
|
|
292
|
-
var AbsoluteAssetImportsPlugin = () => {
|
|
293
|
-
return {
|
|
294
|
-
name: "absolute-asset-imports",
|
|
295
|
-
transformIndexHtml(html, ctx) {
|
|
296
|
-
if (!ctx.server) return html;
|
|
297
|
-
let baseUrl = (ctx.server.config?.server?.origin ?? ctx.server.resolvedUrls?.local[0]).replace(/\/$/, "");
|
|
298
|
-
baseUrl = baseUrl.replace(/\/$/, "");
|
|
299
|
-
return html.replace(/(from\s+["'])\/([^"']+)/g, `$1${baseUrl}/$2`).replace(/(src=["'])\/([^"']+)/gi, `$1${baseUrl}/$2`);
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
};
|
|
303
|
-
export {
|
|
304
|
-
AbsoluteAssetImportsPlugin,
|
|
305
|
-
ApplicationManifestPlugin,
|
|
306
|
-
sortTopLevelDefinitions
|
|
307
|
-
};
|
|
1
|
+
export * from "./application_manifest_plugin.js";
|
|
2
|
+
export * from "./absolute_asset_imports_plugin.js";
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,oCAAoC,CAAC","sourcesContent":["export * from \"./application_manifest_plugin.js\";\nexport * from \"./absolute_asset_imports_plugin.js\";\n"]}
|
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
|
+
"version": "0.4.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -15,28 +15,35 @@
|
|
|
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:
|
|
22
|
-
"build:
|
|
23
|
-
"build:vite": "
|
|
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": "",
|
|
33
39
|
"license": "ISC",
|
|
34
40
|
"description": "",
|
|
35
41
|
"devDependencies": {
|
|
42
|
+
"@apollo/client": "^4.0.12",
|
|
36
43
|
"@testing-library/jest-dom": "^6.9.1",
|
|
37
44
|
"@testing-library/react": "^16.3.0",
|
|
38
45
|
"@testing-library/react-render-stream": "^2.0.2",
|
|
39
|
-
"@types/node": "^24.10.
|
|
46
|
+
"@types/node": "^24.10.4",
|
|
40
47
|
"@types/react": "^19.2.2",
|
|
41
48
|
"@vitejs/plugin-react": "^5.1.1",
|
|
42
49
|
"@vitest/coverage-v8": "^4.0.13",
|
|
@@ -50,13 +57,14 @@
|
|
|
50
57
|
"vitest": "^4.0.13"
|
|
51
58
|
},
|
|
52
59
|
"peerDependencies": {
|
|
53
|
-
"
|
|
54
|
-
"react
|
|
60
|
+
"@apollo/client": "^4.0.0",
|
|
61
|
+
"react": "^19.0.0",
|
|
62
|
+
"react-dom": "^19.0.0"
|
|
55
63
|
},
|
|
56
64
|
"dependencies": {
|
|
57
|
-
"@apollo/client": "^4.0.9",
|
|
58
65
|
"@graphql-tools/graphql-tag-pluck": "^8.3.23",
|
|
59
66
|
"crypto-hash": "^4.0.0",
|
|
60
|
-
"glob": "^11.0.3"
|
|
67
|
+
"glob": "^11.0.3",
|
|
68
|
+
"tslib": "^2.8.1"
|
|
61
69
|
}
|
|
62
|
-
}
|
|
70
|
+
}
|
package/src/core/ApolloClient.ts
CHANGED
|
@@ -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
|
-
|
|
63
|
+
toolOutput?.prefetch?.[operation.prefetchID]
|
|
59
64
|
) {
|
|
60
65
|
this.writeQuery({
|
|
61
66
|
query: parse(operation.body),
|
|
62
|
-
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,17 @@ describe("Client Basics", () => {
|
|
|
56
56
|
},
|
|
57
57
|
],
|
|
58
58
|
resource: "index.html",
|
|
59
|
-
|
|
59
|
+
csp: {
|
|
60
|
+
connectDomains: [],
|
|
61
|
+
resourceDomains: [],
|
|
62
|
+
frameDomains: [],
|
|
63
|
+
redirectDomains: [],
|
|
64
|
+
},
|
|
65
|
+
} satisfies ApplicationManifest;
|
|
60
66
|
|
|
61
67
|
const client = new ApolloClient({
|
|
62
68
|
cache: new InMemoryCache(),
|
|
63
|
-
manifest
|
|
69
|
+
manifest,
|
|
64
70
|
});
|
|
65
71
|
|
|
66
72
|
const variables = { id: "1" };
|
|
@@ -145,11 +151,17 @@ describe("prefetchData", () => {
|
|
|
145
151
|
},
|
|
146
152
|
],
|
|
147
153
|
resource: "index.html",
|
|
148
|
-
|
|
154
|
+
csp: {
|
|
155
|
+
connectDomains: [],
|
|
156
|
+
resourceDomains: [],
|
|
157
|
+
frameDomains: [],
|
|
158
|
+
redirectDomains: [],
|
|
159
|
+
},
|
|
160
|
+
} satisfies ApplicationManifest;
|
|
149
161
|
|
|
150
162
|
const client = new ApolloClient({
|
|
151
163
|
cache: new InMemoryCache(),
|
|
152
|
-
manifest
|
|
164
|
+
manifest,
|
|
153
165
|
});
|
|
154
166
|
await client.prefetchData();
|
|
155
167
|
|
|
@@ -428,11 +440,17 @@ describe("prefetchData", () => {
|
|
|
428
440
|
},
|
|
429
441
|
],
|
|
430
442
|
resource: "index.html",
|
|
431
|
-
|
|
443
|
+
csp: {
|
|
444
|
+
connectDomains: [],
|
|
445
|
+
resourceDomains: [],
|
|
446
|
+
frameDomains: [],
|
|
447
|
+
redirectDomains: [],
|
|
448
|
+
},
|
|
449
|
+
} satisfies ApplicationManifest;
|
|
432
450
|
|
|
433
451
|
const client = new ApolloClient({
|
|
434
452
|
cache: new InMemoryCache(),
|
|
435
|
-
manifest
|
|
453
|
+
manifest,
|
|
436
454
|
});
|
|
437
455
|
await client.prefetchData();
|
|
438
456
|
|
|
@@ -617,7 +635,12 @@ function createManifest(
|
|
|
617
635
|
},
|
|
618
636
|
],
|
|
619
637
|
resource: "index.html",
|
|
620
|
-
csp: {
|
|
638
|
+
csp: {
|
|
639
|
+
resourceDomains: [],
|
|
640
|
+
connectDomains: [],
|
|
641
|
+
frameDomains: [],
|
|
642
|
+
redirectDomains: [],
|
|
643
|
+
},
|
|
621
644
|
...overrides,
|
|
622
645
|
};
|
|
623
646
|
}
|