@apollo/client-ai-apps 0.7.2 → 0.7.4
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 +35 -0
- package/.github/workflows/prep-release.yml +4 -3
- package/.github/workflows/release.yaml +8 -5
- package/.github/workflows/verify-changeset.yml +4 -4
- package/CHANGELOG.md +16 -0
- package/dist/utilities/getToolNamesFromDocument.d.ts +1 -1
- package/dist/utilities/getToolNamesFromDocument.d.ts.map +1 -1
- package/dist/utilities/getToolNamesFromDocument.js +14 -5
- package/dist/utilities/getToolNamesFromDocument.js.map +1 -1
- package/dist/vite/apolloClientAiApps.d.ts.map +1 -1
- package/dist/vite/apolloClientAiApps.js +2 -1
- package/dist/vite/apolloClientAiApps.js.map +1 -1
- package/integration-tests/docker-compose.yml +30 -0
- package/integration-tests/global-teardown.js +9 -0
- package/integration-tests/graphql-server/Dockerfile +12 -0
- package/integration-tests/graphql-server/package.json +10 -0
- package/integration-tests/graphql-server/server.ts +22 -0
- package/integration-tests/mcp-config.yaml +29 -0
- package/integration-tests/mock-app/index.html +12 -0
- package/integration-tests/mock-app/package.json +24 -0
- package/integration-tests/mock-app/src/App.tsx +23 -0
- package/integration-tests/mock-app/src/main.tsx +22 -0
- package/integration-tests/mock-app/src/tools/Echo.tsx +33 -0
- package/integration-tests/mock-app/src/tools/Hello.tsx +19 -0
- package/integration-tests/mock-app/src/tools/Private.tsx +34 -0
- package/integration-tests/mock-app/src/tools/SemiPrivate.tsx +34 -0
- package/integration-tests/mock-app/tsconfig.json +25 -0
- package/integration-tests/mock-app/vite.config.ts +22 -0
- package/integration-tests/package-lock.json +5749 -0
- package/integration-tests/package.json +20 -0
- package/integration-tests/playwright.config.ts +23 -0
- package/integration-tests/schema.graphql +10 -0
- package/integration-tests/tests/hello.spec.ts +11 -0
- package/integration-tests/tests/privateDirective.spec.ts +73 -0
- package/integration-tests/tests/variables.spec.ts +24 -0
- package/package.json +5 -5
- package/src/react/__tests__/createHydrationUtils.test.tsx +62 -0
- package/src/utilities/getToolNamesFromDocument.ts +19 -7
- package/src/vite/__tests__/apolloClientAiApps.test.ts +161 -62
- package/src/vite/apolloClientAiApps.ts +2 -1
- package/vitest.config.ts +2 -1
|
@@ -80,6 +80,41 @@ jobs:
|
|
|
80
80
|
shell: bash
|
|
81
81
|
run: npm test -- --coverage
|
|
82
82
|
|
|
83
|
+
integration-tests:
|
|
84
|
+
runs-on: ubuntu-latest
|
|
85
|
+
|
|
86
|
+
steps:
|
|
87
|
+
- name: Checkout code
|
|
88
|
+
uses: actions/checkout@v4
|
|
89
|
+
|
|
90
|
+
- name: Set up Node.js
|
|
91
|
+
uses: actions/setup-node@v4
|
|
92
|
+
with:
|
|
93
|
+
node-version: 24.x
|
|
94
|
+
|
|
95
|
+
- name: Install root dependencies
|
|
96
|
+
run: npm ci
|
|
97
|
+
|
|
98
|
+
- name: Install integration tests dependencies
|
|
99
|
+
run: npm ci
|
|
100
|
+
working-directory: integration-tests
|
|
101
|
+
|
|
102
|
+
- name: Install Playwright browsers
|
|
103
|
+
run: npx playwright install --with-deps chromium
|
|
104
|
+
working-directory: integration-tests
|
|
105
|
+
|
|
106
|
+
- name: Run integration tests
|
|
107
|
+
run: npm test
|
|
108
|
+
working-directory: integration-tests
|
|
109
|
+
|
|
110
|
+
- name: Upload Playwright report
|
|
111
|
+
if: ${{ !cancelled() }}
|
|
112
|
+
uses: actions/upload-artifact@v4
|
|
113
|
+
with:
|
|
114
|
+
name: playwright-report
|
|
115
|
+
path: integration-tests/playwright-report
|
|
116
|
+
retention-days: 7
|
|
117
|
+
|
|
83
118
|
arethetypeswrong:
|
|
84
119
|
name: Are the types wrong
|
|
85
120
|
runs-on: ubuntu-latest
|
|
@@ -12,13 +12,14 @@ jobs:
|
|
|
12
12
|
prepare-release:
|
|
13
13
|
runs-on: ubuntu-latest
|
|
14
14
|
steps:
|
|
15
|
-
- uses: actions/checkout@v6
|
|
15
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
16
16
|
|
|
17
17
|
# We need to setup node because knope runs `npm run format` so we need to install prettier via npm
|
|
18
18
|
- name: Set up Node.js
|
|
19
|
-
uses: actions/setup-node@
|
|
19
|
+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
|
|
20
20
|
with:
|
|
21
21
|
node-version: 24.x
|
|
22
|
+
package-manager-cache: false
|
|
22
23
|
|
|
23
24
|
- name: Install dependencies
|
|
24
25
|
run: npm ci
|
|
@@ -28,7 +29,7 @@ jobs:
|
|
|
28
29
|
git config --global user.name GitHub Actions
|
|
29
30
|
git config user.email github-actions@github.com
|
|
30
31
|
|
|
31
|
-
- uses: knope-dev/action@v2.1.
|
|
32
|
+
- uses: knope-dev/action@19617851f9f13ab2f27a05989c55efb18aca3675 # v2.1.2
|
|
32
33
|
with:
|
|
33
34
|
version: 0.22.0
|
|
34
35
|
|
|
@@ -17,13 +17,16 @@ jobs:
|
|
|
17
17
|
if: github.repository == 'apollographql/apollo-client-ai-apps' && (github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/'))
|
|
18
18
|
runs-on: ubuntu-latest
|
|
19
19
|
steps:
|
|
20
|
-
- uses: actions/checkout@v6
|
|
20
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
21
|
+
|
|
22
|
+
- name: Set up Node.js
|
|
23
|
+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
|
|
21
24
|
|
|
22
|
-
- name: Setup Node.js 20.x
|
|
23
|
-
uses: actions/setup-node@v4
|
|
24
25
|
with:
|
|
25
|
-
node-version:
|
|
26
|
+
node-version: 24.x
|
|
26
27
|
registry-url: "https://registry.npmjs.org/"
|
|
28
|
+
package-manager-cache: false
|
|
29
|
+
|
|
27
30
|
env:
|
|
28
31
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
29
32
|
|
|
@@ -40,7 +43,7 @@ jobs:
|
|
|
40
43
|
git config --global user.name GitHub Actions
|
|
41
44
|
git config user.email github-actions@github.com
|
|
42
45
|
|
|
43
|
-
- uses: knope-dev/action@v2.1.
|
|
46
|
+
- uses: knope-dev/action@19617851f9f13ab2f27a05989c55efb18aca3675 # v2.1.2
|
|
44
47
|
with:
|
|
45
48
|
version: 0.22.0
|
|
46
49
|
|
|
@@ -18,7 +18,7 @@ jobs:
|
|
|
18
18
|
contents: read
|
|
19
19
|
steps:
|
|
20
20
|
- name: Verify changeset included
|
|
21
|
-
uses: actions/github-script@v7
|
|
21
|
+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
|
|
22
22
|
with:
|
|
23
23
|
script: |
|
|
24
24
|
const dir = '.changeset/';
|
|
@@ -38,7 +38,7 @@ jobs:
|
|
|
38
38
|
}
|
|
39
39
|
core.setOutput('ok', ok ? 'true' : 'false');
|
|
40
40
|
- name: Add or update changeset comment on failure
|
|
41
|
-
uses: actions/github-script@v7
|
|
41
|
+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
|
|
42
42
|
if: failure()
|
|
43
43
|
with:
|
|
44
44
|
script: |
|
|
@@ -75,7 +75,7 @@ jobs:
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
- name: Add or update changeset comment on success
|
|
78
|
-
uses: actions/github-script@v7
|
|
78
|
+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
|
|
79
79
|
if: success()
|
|
80
80
|
with:
|
|
81
81
|
script: |
|
|
@@ -116,7 +116,7 @@ jobs:
|
|
|
116
116
|
pull-requests: write
|
|
117
117
|
steps:
|
|
118
118
|
- name: Add or update comment to show skipped
|
|
119
|
-
uses: actions/github-script@v7
|
|
119
|
+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
|
|
120
120
|
with:
|
|
121
121
|
script: |
|
|
122
122
|
const pr = context.payload.pull_request;
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## 0.7.4 (2026-05-29)
|
|
2
|
+
|
|
3
|
+
### Fixes
|
|
4
|
+
|
|
5
|
+
#### Handle lowercase operation names
|
|
6
|
+
|
|
7
|
+
Fixes tool input type generation when the tool name is set from the operation name and the operation name is lowercase.
|
|
8
|
+
|
|
9
|
+
## 0.7.3 (2026-05-13)
|
|
10
|
+
|
|
11
|
+
### Fixes
|
|
12
|
+
|
|
13
|
+
#### Fix tool match when `@tool` doesn't use arguments
|
|
14
|
+
|
|
15
|
+
Fix an issue when using `@tool` without arguments where `useHydratedVariables` doesn't match against the tool correctly which causes mismatches in intended query result.
|
|
16
|
+
|
|
1
17
|
## 0.7.2 (2026-04-17)
|
|
2
18
|
|
|
3
19
|
### Fixes
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type DocumentNode } from "graphql";
|
|
2
|
-
export declare function getToolNamesFromDocument(document: DocumentNode): Set<string>;
|
|
2
|
+
export declare function getToolNamesFromDocument(document: DocumentNode): Set<string | undefined>;
|
|
3
3
|
//# sourceMappingURL=getToolNamesFromDocument.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getToolNamesFromDocument.d.ts","sourceRoot":"","sources":["../../src/utilities/getToolNamesFromDocument.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"getToolNamesFromDocument.d.ts","sourceRoot":"","sources":["../../src/utilities/getToolNamesFromDocument.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAEtE,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,YAAY,2BAkB9D"}
|
|
@@ -2,11 +2,20 @@ import { getOperationDefinition } from "@apollo/client/utilities/internal";
|
|
|
2
2
|
import { Kind } from "graphql";
|
|
3
3
|
export function getToolNamesFromDocument(document) {
|
|
4
4
|
const operationDef = getOperationDefinition(document);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const operationName = operationDef?.name?.value;
|
|
6
|
+
const toolDirectives = operationDef?.directives?.filter((d) => d.name.value === "tool") ?? [];
|
|
7
|
+
if (toolDirectives.length === 1) {
|
|
8
|
+
return new Set([
|
|
9
|
+
getToolNameFromDirective(toolDirectives[0]) ?? operationName,
|
|
10
|
+
]);
|
|
11
|
+
}
|
|
12
|
+
return new Set(toolDirectives.flatMap((d) => {
|
|
13
|
+
const name = getToolNameFromDirective(d);
|
|
14
|
+
return name ? [name] : [];
|
|
10
15
|
}));
|
|
11
16
|
}
|
|
17
|
+
function getToolNameFromDirective(directive) {
|
|
18
|
+
const nameArg = directive.arguments?.find((arg) => arg.name.value === "name");
|
|
19
|
+
return nameArg?.value.kind === Kind.STRING ? nameArg.value.value : undefined;
|
|
20
|
+
}
|
|
12
21
|
//# sourceMappingURL=getToolNamesFromDocument.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getToolNamesFromDocument.js","sourceRoot":"","sources":["../../src/utilities/getToolNamesFromDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"getToolNamesFromDocument.js","sourceRoot":"","sources":["../../src/utilities/getToolNamesFromDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,IAAI,EAAyC,MAAM,SAAS,CAAC;AAEtE,MAAM,UAAU,wBAAwB,CAAC,QAAsB;IAC7D,MAAM,YAAY,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IACtD,MAAM,aAAa,GAAG,YAAY,EAAE,IAAI,EAAE,KAAK,CAAC;IAChD,MAAM,cAAc,GAClB,YAAY,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC;IAEzE,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,IAAI,GAAG,CAAC;YACb,wBAAwB,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,aAAa;SAC7D,CAAC,CAAC;IACL,CAAC;IAED,OAAO,IAAI,GAAG,CACZ,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAC3B,MAAM,IAAI,GAAG,wBAAwB,CAAC,CAAC,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5B,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAED,SAAS,wBAAwB,CAAC,SAAwB;IACxD,MAAM,OAAO,GAAG,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC;IAC9E,OAAO,OAAO,EAAE,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/E,CAAC","sourcesContent":["import { getOperationDefinition } from \"@apollo/client/utilities/internal\";\nimport { Kind, type DirectiveNode, type DocumentNode } from \"graphql\";\n\nexport function getToolNamesFromDocument(document: DocumentNode) {\n const operationDef = getOperationDefinition(document);\n const operationName = operationDef?.name?.value;\n const toolDirectives =\n operationDef?.directives?.filter((d) => d.name.value === \"tool\") ?? [];\n\n if (toolDirectives.length === 1) {\n return new Set([\n getToolNameFromDirective(toolDirectives[0]) ?? operationName,\n ]);\n }\n\n return new Set(\n toolDirectives.flatMap((d) => {\n const name = getToolNameFromDirective(d);\n return name ? [name] : [];\n })\n );\n}\n\nfunction getToolNameFromDirective(directive: DirectiveNode) {\n const nameArg = directive.arguments?.find((arg) => arg.name.value === \"name\");\n return nameArg?.value.kind === Kind.STRING ? nameArg.value.value : undefined;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apolloClientAiApps.d.ts","sourceRoot":"","sources":["../../src/vite/apolloClientAiApps.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,MAAM,EAEZ,MAAM,MAAM,CAAC;AAMd,OAAO,EAA4B,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAqB7E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAenE,MAAM,CAAC,OAAO,WAAW,kBAAkB,CAAC;IAC1C,KAAY,MAAM,GAAG,wBAAwB,CAAC,SAAS,CAAC;IAExD,UAAiB,OAAO;QACtB,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KAC7B;CACF;AAgBD,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,gCAOnD;
|
|
1
|
+
{"version":3,"file":"apolloClientAiApps.d.ts","sourceRoot":"","sources":["../../src/vite/apolloClientAiApps.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,MAAM,EAEZ,MAAM,MAAM,CAAC;AAMd,OAAO,EAA4B,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAqB7E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAenE,MAAM,CAAC,OAAO,WAAW,kBAAkB,CAAC;IAC1C,KAAY,MAAM,GAAG,wBAAwB,CAAC,SAAS,CAAC;IAExD,UAAiB,OAAO;QACtB,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KAC7B;CACF;AAgBD,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,gCAOnD;AAgUD,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,kBAAkB,CAAC,OAAO,GAClC,MAAM,CAoZR;AAwHD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,YAAY,GAAG,YAAY,CA2CzE"}
|
|
@@ -165,10 +165,11 @@ async function generateOperationTypes(schema, documents) {
|
|
|
165
165
|
documents,
|
|
166
166
|
generates: {
|
|
167
167
|
"operation-types.d.ts": {
|
|
168
|
-
plugins: ["typescript
|
|
168
|
+
plugins: ["typescript-operations"],
|
|
169
169
|
config: {
|
|
170
170
|
nonOptionalTypename: true,
|
|
171
171
|
skipTypeNameForRoot: true,
|
|
172
|
+
namingConvention: "keep",
|
|
172
173
|
},
|
|
173
174
|
},
|
|
174
175
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apolloClientAiApps.js","sourceRoot":"","sources":["../../src/vite/apolloClientAiApps.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,GAGxB,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,UAAU,EAAqB,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,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ResolvedConfig,\n} from \"vite\";\nimport { createHash } from \"node:crypto\";\nimport path from \"node:path\";\nimport fs from \"node:fs\";\nimport * as recast from \"recast\";\nimport typescriptParser from \"recast/parsers/typescript.js\";\nimport { ApolloClient, ApolloLink, type DocumentNode } from \"@apollo/client\";\nimport { InMemoryCache } from \"@apollo/client\";\nimport { equal } from \"@wry/equality\";\nimport { gqlPluckFromCodeStringSync } from \"@graphql-tools/graphql-tag-pluck\";\nimport { glob } from \"glob\";\nimport { print } from \"@apollo/client/utilities\";\nimport { removeDirectivesFromDocument } from \"@apollo/client/utilities/internal\";\nimport { of } from \"rxjs\";\nimport { Kind, OperationTypeNode, parse, visit } from \"graphql\";\nimport {\n getArgumentValue,\n getDirectiveArgument,\n getTypeName,\n maybeGetArgumentValue,\n} from \"./utilities/graphql.js\";\nimport type {\n ApplicationManifest,\n ManifestOperation,\n} from \"../types/application-manifest\";\nimport { invariant } from \"../utilities/invariant.js\";\nimport { explorer } from \"./utilities/config.js\";\nimport type { ApolloClientAiAppsConfig } from \"../config/index.js\";\nimport { ApolloClientAiAppsConfigSchema } from \"../config/schema.js\";\nimport { z } from \"zod\";\nimport { createFragmentRegistry } from \"@apollo/client/cache\";\nimport {\n buildImportStatement,\n buildPropertySignature,\n buildKeywordLiteral,\n printRecast,\n type TSInterfaceBody,\n} from \"./utilities/recast.js\";\nimport type { TypeScriptDocumentsPluginConfig } from \"@graphql-codegen/typescript-operations\";\n\nconst b = recast.types.builders;\n\nexport declare namespace apolloClientAiApps {\n export type Target = ApolloClientAiAppsConfig.AppTarget;\n\n export interface Options {\n targets: Target[];\n devTarget?: Target | undefined;\n appsOutDir: string;\n schema?: string | undefined;\n }\n}\n\nconst root = process.cwd();\n\nconst VALID_TARGETS: apolloClientAiApps.Target[] = [\"openai\", \"mcp\"];\n\nfunction isValidTarget(target: unknown): target is apolloClientAiApps.Target {\n return VALID_TARGETS.includes(target as apolloClientAiApps.Target);\n}\n\nfunction buildExtensions(target: apolloClientAiApps.Target) {\n return [\".mjs\", \".js\", \".mts\", \".ts\", \".jsx\", \".tsx\", \".json\"].flatMap(\n (ext) => [`.${target}${ext}`, ext]\n );\n}\n\nexport function devTarget(target: string | undefined) {\n invariant(\n target === undefined || isValidTarget(target),\n `devTarget '${target}' is not a valid dev target. Must be one of ${VALID_TARGETS.join(\", \")}.`\n );\n\n return target;\n}\n\ninterface FileCache {\n hash: string;\n sources: DocumentNode[];\n}\n\nfunction md5(contents: string) {\n return createHash(\"md5\").update(contents).digest(\"hex\");\n}\n\n/**\n * Builds the AST for the comment used at the top of a generated file from this\n * plugin.\n *\n * @remarks\n * This comment informs users that generated files from this plugin should not\n * be edited since it is autogenerated by this plugin.\n */\nfunction buildHeaderComment() {\n return b.commentLine(\n \" This file is auto-generated by @apollo/client-ai-apps. Do not edit manually.\",\n true,\n false\n );\n}\n\n/**\n * Builds the `@apollo/client-ai-apps` ambient module declaration for the\n * `register.d.ts` file.\n *\n * @param registerInterfaceBody - The interface body for the `Register`\n * interface\n *\n * @example\n * ```ts\n * buildAmbientModuleDeclaration(interfaceBody);\n * // =>\n * // declare namespace \"@apollo/client-ai-apps\" {\n * // interface Register {\n * // // ...interfaceBody\n * // }\n * // }\n * ```\n */\nfunction buildAmbientModuleDeclaration(registerInterfaceBody: TSInterfaceBody) {\n const interfaceDeclaration = b.tsInterfaceDeclaration(\n b.identifier(\"Register\"),\n b.tsInterfaceBody(registerInterfaceBody)\n );\n\n const moduleDeclaration = b.tsModuleDeclaration(\n b.stringLiteral(\"@apollo/client-ai-apps\"),\n b.tsModuleBlock([interfaceDeclaration])\n );\n moduleDeclaration.declare = true;\n\n return moduleDeclaration;\n}\n\n/**\n * Gets the variables type name for an operation. GraphQL Codegen creates\n * variables types with the combination of operationName + operationType +\n * \"Variables\"\n *\n * @example\n * ```ts\n * getVariablesTypeName({ name: \"GetProduct\", type: \"query\" });\n * // => \"GetProductQueryVariables\"\n * ````\n */\nfunction getVariablesTypeName(operation: ManifestOperation) {\n const { name, type } = operation;\n\n return `${name}${type.charAt(0).toUpperCase()}${type.slice(1)}Variables`;\n}\n\n/**\n * Returns the code string written to the `.apollo-client-ai-apps/types/register.d.ts` files\n * for a given set of operations.\n */\nfunction getRegisteredTypeContents({\n operations,\n schema,\n flagSchemaBuildError = false,\n}: {\n operations: ManifestOperation[];\n schema: string | undefined;\n /**\n * Used during dev to avoid failing the build and instead output the error\n * to the console. When providing an error, the error message is generated as\n * a literal type value in the `register.d.ts` file so that users can see the\n * error message when hovering over the type.\n */\n flagSchemaBuildError?: false | Error;\n}) {\n if (flagSchemaBuildError) {\n const message = `[@apollo/client-ai-apps/vite]: There was an error building generated types. See the vite build output for more details.\\n\\n${flagSchemaBuildError.message}`;\n\n const importBaseStatement = buildImportStatement(\n [],\n \"@apollo/client-ai-apps\"\n );\n importBaseStatement.comments = [buildHeaderComment()];\n\n const typeAnnotation = b.tsLiteralType(b.stringLiteral(message));\n\n return printRecast(\n b.program([\n importBaseStatement,\n buildAmbientModuleDeclaration([\n buildPropertySignature(\"toolName\", typeAnnotation),\n buildPropertySignature(\n \"toolInputs\",\n b.tsTypeLiteral([buildPropertySignature(message, typeAnnotation)])\n ),\n ]),\n ])\n );\n }\n\n const toolNames = operations.flatMap((op) => op.tools.map((t) => t.name));\n\n if (toolNames.length === 0) {\n const emptyExport = b.exportNamedDeclaration(null);\n emptyExport.comments = [buildHeaderComment()];\n return printRecast(b.program([emptyExport]));\n }\n\n const importBaseStatement = buildImportStatement(\n [],\n \"@apollo/client-ai-apps\"\n );\n importBaseStatement.comments = [buildHeaderComment()];\n\n const toolNameProp = buildPropertySignature(\n \"toolName\",\n b.tsUnionType(toolNames.map((n) => b.tsLiteralType(b.stringLiteral(n))))\n );\n\n if (!schema) {\n return printRecast(\n b.program([\n importBaseStatement,\n buildAmbientModuleDeclaration([toolNameProp]),\n ])\n );\n }\n\n const importedVariableTypes = new Set<string>();\n const toolInputsValue: recast.types.namedTypes.TSPropertySignature[] = [];\n\n for (const operation of operations) {\n const variablesTypeName = getVariablesTypeName(operation);\n\n if (operation.tools.length) {\n importedVariableTypes.add(variablesTypeName);\n }\n\n for (const tool of operation.tools) {\n const variablesTypeRef = b.tsTypeReference(\n b.identifier(variablesTypeName)\n );\n let typeExpression:\n | recast.types.namedTypes.TSTypeReference\n | recast.types.namedTypes.TSIntersectionType = variablesTypeRef;\n\n if (tool.extraInputs?.length) {\n const extraInputsType = tool.extraInputs.map((ei) => {\n return buildPropertySignature(\n ei.name,\n buildKeywordLiteral(ei.type),\n true\n );\n });\n\n typeExpression = b.tsIntersectionType([\n variablesTypeRef,\n b.tsTypeLiteral(extraInputsType),\n ]);\n }\n\n toolInputsValue.push(buildPropertySignature(tool.name, typeExpression));\n }\n }\n\n return printRecast(\n b.program([\n importBaseStatement,\n buildImportStatement(\n Array.from(importedVariableTypes),\n \"./operation-types.js\",\n \"type\"\n ),\n buildAmbientModuleDeclaration([\n toolNameProp,\n buildPropertySignature(\"toolInputs\", b.tsTypeLiteral(toolInputsValue)),\n ]),\n ])\n );\n}\n\n/**\n * Generates and returns the code string written to the\n * `.apollo-client-ai-apps/types/operation-types.d.ts` file. Uses GraphQL\n * Codegen to introspect the given schema and extract variable types.\n */\nasync function generateOperationTypes(\n schema: string,\n documents: string[]\n): Promise<string> {\n const { generate } = await import(\"@graphql-codegen/cli\");\n\n if (documents.length === 0) {\n return `// Auto-generated by @apollo/client-ai-apps. Do not edit manually.\\nexport {};\\n`;\n }\n\n const output = await generate(\n {\n schema,\n documents,\n generates: {\n \"operation-types.d.ts\": {\n plugins: [\"typescript\", \"typescript-operations\"],\n config: {\n nonOptionalTypename: true,\n skipTypeNameForRoot: true,\n } satisfies TypeScriptDocumentsPluginConfig,\n },\n },\n silent: true,\n } as Parameters<typeof generate>[0],\n false\n );\n\n const content = (output as { filename: string; content: string }[])[0]\n .content;\n return `// Auto-generated by @apollo/client-ai-apps. Do not edit manually.\\n${content}`;\n}\n\n/**\n * Gets the name of an exported type (e.g. `export type x`) from a TypeScript\n * AST statement.\n */\nfunction getExportedTypeAliasName(\n statement: recast.types.namedTypes.Statement\n): string | undefined {\n if (statement.type !== \"ExportNamedDeclaration\") return;\n\n const declaration = (\n statement as recast.types.namedTypes.ExportNamedDeclaration\n ).declaration;\n\n if (!declaration || declaration.type !== \"TSTypeAliasDeclaration\") return;\n\n const alias = declaration as recast.types.namedTypes.TSTypeAliasDeclaration;\n return typeof alias.id.name === \"string\" ? alias.id.name : undefined;\n}\n\n/**\n * Removes all non-`*Variables` types from the `operation-types.d.ts` file.\n * The `typescript` and `typescript-operations` codegen plugins add full schema\n * types and operation types. This function ensures those unused types are\n * removed.\n */\nfunction filterOperationTypes(\n content: string,\n rootTypeNames: Set<string>\n): string {\n const ast = recast.parse(content, { parser: typescriptParser });\n const statements: recast.types.namedTypes.Statement[] = ast.program.body;\n const typeMap = new Map<\n string,\n recast.types.namedTypes.TSTypeAliasDeclaration\n >();\n\n for (const statement of statements) {\n const name = getExportedTypeAliasName(statement);\n\n if (name) {\n typeMap.set(\n name,\n (statement as recast.types.namedTypes.ExportNamedDeclaration)\n .declaration as recast.types.namedTypes.TSTypeAliasDeclaration\n );\n }\n }\n\n const reachable = new Set<string>(rootTypeNames);\n const queue = Array.from(rootTypeNames);\n\n while (queue.length > 0) {\n const name = queue.shift()!;\n const node = typeMap.get(name);\n\n if (!node) continue;\n\n recast.visit(node, {\n visitTSTypeReference(path) {\n const typeName = path.value.typeName?.name as string | undefined;\n\n if (typeName && !reachable.has(typeName)) {\n reachable.add(typeName);\n queue.push(typeName);\n }\n\n this.traverse(path);\n },\n });\n }\n\n ast.program.body = statements.filter((statement) => {\n const name = getExportedTypeAliasName(statement);\n return name === undefined || reachable.has(name);\n });\n\n return printRecast(ast);\n}\n\nexport function apolloClientAiApps(\n options: apolloClientAiApps.Options\n): Plugin {\n const targets = Array.from(new Set(options.targets));\n const {\n devTarget = targets.length === 1 ? targets[0] : undefined,\n appsOutDir,\n schema,\n } = options;\n let config!: ResolvedConfig;\n\n const fragments = createFragmentRegistry();\n\n invariant(\n Array.isArray(targets) && targets.length > 0,\n \"The `targets` option must be a non-empty array\"\n );\n\n invariant(\n targets.every(isValidTarget),\n `All targets must be one of: ${VALID_TARGETS.join(\", \")}`\n );\n\n invariant(\n path.basename(path.normalize(appsOutDir)) === \"apps\",\n \"`appsOutDir` must end with `apps` as the final path segment (e.g. `path/to/apps`).\"\n );\n\n const client = new ApolloClient({\n cache: new InMemoryCache({ fragments }),\n link: processQueryLink,\n });\n\n let sources: DocumentNode[] = [];\n\n function recomputeSources(cache: Map<string, FileCache>) {\n sources = Array.from(cache.values()).flatMap((entry) => entry.sources);\n }\n\n async function getManifestOperations() {\n if (sources === getManifestOperations.cache.sources) {\n return getManifestOperations.cache.manifestOperations;\n }\n\n const manifestOperations = [];\n for (const source of sources) {\n const operationDef = source.definitions.find(\n (d) => d.kind === Kind.OPERATION_DEFINITION\n );\n\n if (!operationDef) continue;\n\n switch (operationDef.operation) {\n case OperationTypeNode.QUERY: {\n const result = await client.query<ManifestOperation>({\n query: source,\n fetchPolicy: \"no-cache\",\n });\n const data = result.data!;\n\n if (data.tools.length > 0 || data.prefetch) {\n manifestOperations.push(data);\n }\n break;\n }\n case OperationTypeNode.MUTATION: {\n const result = await client.mutate<ManifestOperation>({\n mutation: source,\n fetchPolicy: \"no-cache\",\n });\n const data = result.data!;\n\n if (data.tools.length > 0 || data.prefetch) {\n manifestOperations.push(data);\n }\n break;\n }\n default:\n throw new Error(\n `Found unsupported operation type '${operationDef.operation}'. Only queries and mutations are supported.`\n );\n }\n }\n\n getManifestOperations.cache = { sources, manifestOperations };\n\n return manifestOperations;\n }\n\n getManifestOperations.cache = {\n sources,\n manifestOperations: [] as ManifestOperation[],\n };\n\n async function processFile(file: string) {\n const code = fs.readFileSync(file, \"utf-8\");\n\n if (!code.includes(\"gql\")) return;\n\n const fileHash = md5(code);\n if (processFile.cache.get(file)?.hash === fileHash) return;\n\n const sources = gqlPluckFromCodeStringSync(file, code, {\n modules: [\n { name: \"graphql-tag\", identifier: \"gql\" },\n { name: \"@apollo/client\", identifier: \"gql\" },\n ],\n }).map((source) => parse(source.body));\n\n const previousSources = processFile.cache.get(file)?.sources;\n\n if (previousSources && equal(sources, previousSources)) {\n processFile.cache.set(file, { hash: fileHash, sources: previousSources });\n return;\n }\n\n fragments.register(...sources);\n\n processFile.cache.set(file, { hash: fileHash, sources });\n recomputeSources(processFile.cache);\n }\n\n processFile.cache = new Map<string, FileCache>();\n\n async function generateManifest() {\n const appsConfig = await getAppsConfig();\n const operations = await getManifestOperations();\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 function getBuildResourceForTarget(target: apolloClientAiApps.Target) {\n const entryPoint = getResourceFromConfig(appsConfig, config.mode, target);\n\n if (entryPoint) {\n return entryPoint;\n }\n\n if (config.mode === \"production\") {\n return `${target}/index.html`;\n }\n\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 let resource: ApplicationManifest[\"resource\"];\n if (config.command === \"serve\") {\n // Dev mode: resource is a string (dev server URL)\n resource =\n getResourceFromConfig(appsConfig, config.mode, devTarget!) ??\n `http${config.server.https ? \"s\" : \"\"}://${config.server.host ?? \"localhost\"}:${config.server.port}`;\n } else {\n resource = Object.fromEntries(\n targets.map((target) => [target, getBuildResourceForTarget(target)])\n ) as { mcp?: string; openai?: string };\n }\n\n const packageJson = readPackageJson();\n const appName = appsConfig.name ?? packageJson.name;\n\n invariant(\n appName,\n \"Error generating application manifest. Could not determine app name. Set `name` in your apollo-client-ai-apps config or `package.json`.\"\n );\n\n const manifest: ApplicationManifest = {\n format: \"apollo-ai-app-manifest\",\n version: \"1\",\n appVersion: appsConfig.version ?? packageJson.version,\n name: appsConfig.name ?? packageJson.name,\n description: appsConfig.description ?? packageJson.description,\n hash: createHash(\"sha256\").update(Date.now().toString()).digest(\"hex\"),\n operations,\n resource,\n csp: {\n baseUriDomains: appsConfig.csp?.baseUriDomains ?? [],\n connectDomains: appsConfig.csp?.connectDomains ?? [],\n frameDomains: appsConfig.csp?.frameDomains ?? [],\n redirectDomains: appsConfig.csp?.redirectDomains ?? [],\n resourceDomains: appsConfig.csp?.resourceDomains ?? [],\n },\n };\n\n if (isNonEmptyObject(appsConfig.widgetSettings)) {\n manifest.widgetSettings = appsConfig.widgetSettings;\n }\n\n if (isNonEmptyObject(appsConfig.labels)) {\n manifest.labels = appsConfig.labels;\n }\n\n const manifestContents = JSON.stringify(manifest);\n\n // Always write to build directory so the MCP server picks it up\n writeFileSync(\n path.resolve(root, appsOutDir, appName, \".application-manifest.json\"),\n manifestContents\n );\n\n // Always write to the dev location so that the app can bundle the manifest content\n writeFileSync(\".application-manifest.json\", manifestContents);\n\n const manifestTypesFilepath = \".application-manifest.d.json.ts\";\n if (!fs.existsSync(manifestTypesFilepath)) {\n const manifestImport = b.importDeclaration(\n [b.importSpecifier(b.identifier(\"ApplicationManifest\"))],\n b.stringLiteral(\"@apollo/client-ai-apps\"),\n \"type\"\n );\n const manifestId = b.identifier(\"manifest\");\n manifestId.typeAnnotation = b.tsTypeAnnotation(\n b.tsTypeReference(b.identifier(\"ApplicationManifest\"), null)\n );\n const manifestDeclaration = b.variableDeclaration(\"const\", [\n b.variableDeclarator(manifestId, null),\n ]) as recast.types.namedTypes.VariableDeclaration & { declare: boolean };\n manifestDeclaration.declare = true;\n\n const exportDefault = b.exportDefaultDeclaration(\n b.identifier(\"manifest\")\n );\n\n const content = printRecast(\n b.program([manifestImport, manifestDeclaration, exportDefault])\n );\n\n writeFileSync(manifestTypesFilepath, content);\n }\n }\n\n async function generateTypesFiles() {\n let flagSchemaBuildError: false | Error = false;\n const operations = await getManifestOperations();\n\n if (operations === generateTypesFiles.cache) {\n return;\n }\n\n generateTypesFiles.cache = operations;\n\n if (schema) {\n try {\n const opTypesContent = await generateOperationTypes(\n schema,\n operations.map((op) => op.body)\n );\n\n const rootTypeNames = new Set(\n operations.flatMap((op) =>\n op.tools.length > 0 ? [getVariablesTypeName(op)] : []\n )\n );\n\n writeFileSync(\n path.resolve(\n root,\n \".apollo-client-ai-apps/types/operation-types.d.ts\"\n ),\n filterOperationTypes(opTypesContent, rootTypeNames),\n { cache: true }\n );\n } catch (e) {\n if (config.command === \"build\") {\n throw e;\n }\n\n flagSchemaBuildError = e as Error;\n console.error(\"[@apollo/client-ai-apps/vite]:\", e);\n }\n }\n\n const typesFileContents = getRegisteredTypeContents({\n operations,\n schema,\n flagSchemaBuildError,\n });\n\n writeFileSync(\n path.resolve(root, \".apollo-client-ai-apps/types/register.d.ts\"),\n typesFileContents,\n { cache: true }\n );\n }\n\n generateTypesFiles.cache = [] as ManifestOperation[] | undefined;\n\n return {\n name: \"@apollo/client-ai-apps/vite\",\n async buildStart() {\n // Scan all files on startup\n const files = await glob(\"./src/**/*.{ts,tsx,js,jsx}\", { fs });\n\n for (const file of files) {\n const fullPath = path.resolve(root, file);\n await processFile(fullPath);\n }\n\n await Promise.all([generateManifest(), generateTypesFiles()]);\n },\n configResolved(resolvedConfig) {\n config = resolvedConfig;\n },\n async configEnvironment(name) {\n if (!targets.includes(name as any)) return;\n\n const appsConfig = await getAppsConfig();\n const appName = appsConfig.name ?? readPackageJson().name;\n\n invariant(\n appName,\n \"Could not determine app name. Set `name` in your apollo-client-ai-apps config or `package.json`.\"\n );\n\n return {\n build: {\n outDir: path.join(appsOutDir, appName, name),\n },\n };\n },\n configureServer(server) {\n server.watcher.on(\"change\", async (file) => {\n if (file.endsWith(\"package.json\")) {\n readPackageJson.resetCache();\n await generateManifest();\n } else if (file.match(/\\.?apollo-client-ai-apps\\.config\\.\\w+$/)) {\n explorer.clearCaches();\n await generateManifest();\n } else if (file.match(/\\.(jsx?|tsx?)$/)) {\n await processFile(file);\n await Promise.all([generateManifest(), generateTypesFiles()]);\n }\n });\n },\n\n config(userConfig, { command }) {\n if (userConfig.build?.outDir) {\n console.warn(\n \"[@apollo/client-ai-apps/vite] `build.outDir` is set in your Vite config but will be \" +\n \"ignored. Use `appsOutDir` in the plugin options to control the output location.\"\n );\n }\n\n if (command === \"serve\") {\n invariant(\n isValidTarget(devTarget) || targets.length === 1,\n \"`devTarget` must be set for development when using multiple targets.\"\n );\n\n const target = devTarget ?? targets[0];\n\n return {\n resolve: {\n extensions: buildExtensions(target),\n conditions: [target, ...defaultClientConditions],\n },\n };\n }\n\n return {\n environments: Object.fromEntries(\n targets.map((target) => [\n target,\n {\n consumer: \"client\",\n webCompatible: true,\n resolve: {\n extensions: buildExtensions(target),\n conditions: [target, ...defaultClientConditions],\n },\n },\n ])\n ),\n builder: {\n buildApp: async (builder) => {\n await Promise.all(\n targets.map((target) =>\n builder.build(builder.environments[target])\n )\n );\n },\n },\n };\n },\n transformIndexHtml(html, ctx) {\n if (!ctx.server) return html;\n\n let baseUrl = (\n ctx.server.config?.server?.origin ??\n ctx.server.resolvedUrls?.local[0] ??\n \"\"\n ).replace(/\\/$/, \"\");\n baseUrl = baseUrl.replace(/\\/$/, \"\");\n\n return (\n html\n // import \"/@vite/...\" or \"/@react-refresh\"\n .replace(/(from\\s+[\"'])\\/([^\"']+)/g, `$1${baseUrl}/$2`)\n // src=\"/src/...\"\n .replace(/(src=[\"'])\\/([^\"']+)/gi, `$1${baseUrl}/$2`)\n );\n },\n } satisfies Plugin;\n}\n\nconst processQueryLink = new ApolloLink((operation) => {\n const body = print(\n removeOperationDescription(\n removeManifestDirectives(sortTopLevelDefinitions(operation.query))\n )\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 toolDirectives =\n directives?.filter((d) => d.name.value === \"tool\") ?? [];\n\n const tools = toolDirectives.map((directive) => {\n const nameArg = getDirectiveArgument(\"name\", directive);\n const descriptionArg = getDirectiveArgument(\"description\", directive);\n\n let name: string;\n if (nameArg) {\n name = getArgumentValue(nameArg, Kind.STRING);\n } else {\n invariant(\n toolDirectives.length === 1,\n `Operations with multiple @tool directives must provide a 'name' argument on each @tool`\n );\n invariant(\n definition.name?.value,\n `Anonymous operations cannot use @tool without providing a 'name' argument`\n );\n name = definition.name.value;\n }\n\n let description: string;\n if (descriptionArg) {\n description = getArgumentValue(descriptionArg, Kind.STRING);\n } else {\n invariant(\n toolDirectives.length === 1,\n `Operations with multiple @tool directives must provide a 'description' argument on each @tool`\n );\n invariant(\n definition.description?.value,\n `Operations using @tool without a 'description' argument must have a description on the operation definition`\n );\n description = definition.description.value;\n }\n\n const result = ToolDirectiveSchema.safeParse({\n name,\n description,\n extraInputs: maybeGetArgumentValue(\n getDirectiveArgument(\"extraInputs\", directive),\n Kind.LIST\n ),\n extraOutputs: maybeGetArgumentValue(\n getDirectiveArgument(\"extraOutputs\", directive),\n Kind.OBJECT\n ),\n labels: maybeGetArgumentValue(\n getDirectiveArgument(\"labels\", directive),\n Kind.OBJECT\n ),\n });\n\n if (result.error) {\n throw z.prettifyError(result.error);\n }\n\n return result.data;\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\nfunction removeOperationDescription(doc: DocumentNode): DocumentNode {\n return visit(doc, {\n OperationDefinition(node) {\n return { ...node, description: undefined };\n },\n });\n}\n\nfunction removeManifestDirectives(doc: DocumentNode) {\n return removeDirectivesFromDocument(\n [{ name: \"prefetch\" }, { name: \"tool\" }],\n doc\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\nfunction isNonEmptyObject<T extends object>(\n obj: T | null | undefined\n): obj is T {\n return !!obj && Object.keys(obj).length > 0;\n}\n\nasync function getAppsConfig() {\n const result = await explorer.search();\n const config = (result?.config ??\n {}) as Partial<ApolloClientAiAppsConfig.Config>;\n\n const parsed = ApolloClientAiAppsConfigSchema.safeParse(config);\n\n if (parsed.error) {\n throw z.prettifyError(parsed.error);\n }\n\n return parsed.data;\n}\n\nfunction getResourceFromConfig(\n appsConfig: z.infer<typeof ApolloClientAiAppsConfigSchema>,\n mode: string,\n target: apolloClientAiApps.Target\n) {\n if (!appsConfig.entry || !appsConfig.entry[mode]) {\n return;\n }\n\n const config = appsConfig.entry[mode];\n\n return typeof config === \"string\" ? config : config[target];\n}\n\nfunction readPackageJson(): Record<string, any> {\n if (readPackageJson.cache) {\n return readPackageJson.cache;\n }\n\n return (readPackageJson.cache = JSON.parse(\n fs.readFileSync(\"package.json\", \"utf-8\")\n ));\n}\n\nreadPackageJson.cache = undefined as Record<string, any> | undefined;\nreadPackageJson.resetCache = () => {\n readPackageJson.cache = undefined;\n};\n\nfunction writeFileSync(\n filepath: string,\n content: string,\n options: { cache?: boolean } = {}\n) {\n function writeFile() {\n fs.mkdirSync(path.dirname(filepath), { recursive: true });\n fs.writeFileSync(filepath, content, \"utf-8\");\n }\n\n if (!options.cache) {\n return writeFile();\n }\n\n const hash = md5(content);\n const cachedHash = writeFileSync.cache.get(filepath);\n\n if (hash !== cachedHash || !fs.existsSync(filepath)) {\n writeFileSync.cache.set(filepath, hash);\n writeFile();\n }\n}\n\nwriteFileSync.cache = new Map<string, string>();\n\nconst ToolDirectiveSchema = z.strictObject({\n name: z.stringFormat(\"toolName\", (value) => value.indexOf(\" \") === -1, {\n error: (iss) => `Tool with name \"${iss.input}\" must not contain spaces`,\n }),\n description: z.string(),\n extraInputs: z.optional(\n z.array(\n z.strictObject({\n name: z.string(),\n description: z.string(),\n type: z.literal([\"string\", \"boolean\", \"number\"]),\n })\n )\n ),\n extraOutputs: z.optional(z.record(z.string(), z.unknown())),\n labels: ApolloClientAiAppsConfigSchema.shape.labels.optional(),\n});\n"]}
|
|
1
|
+
{"version":3,"file":"apolloClientAiApps.js","sourceRoot":"","sources":["../../src/vite/apolloClientAiApps.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,GAGxB,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,gBAAgB,MAAM,8BAA8B,CAA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CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3D,MAAM,EAAE,8BAA8B,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE;CAC/D,CAAC,CAAC","sourcesContent":["import {\n defaultClientConditions,\n type Plugin,\n type ResolvedConfig,\n} from \"vite\";\nimport { createHash } from \"node:crypto\";\nimport path from \"node:path\";\nimport fs from \"node:fs\";\nimport * as recast from \"recast\";\nimport typescriptParser from \"recast/parsers/typescript.js\";\nimport { ApolloClient, ApolloLink, type DocumentNode } from \"@apollo/client\";\nimport { InMemoryCache } from \"@apollo/client\";\nimport { equal } from \"@wry/equality\";\nimport { gqlPluckFromCodeStringSync } from \"@graphql-tools/graphql-tag-pluck\";\nimport { glob } from \"glob\";\nimport { print } from \"@apollo/client/utilities\";\nimport { removeDirectivesFromDocument } from \"@apollo/client/utilities/internal\";\nimport { of } from \"rxjs\";\nimport { Kind, OperationTypeNode, parse, visit } from \"graphql\";\nimport {\n getArgumentValue,\n getDirectiveArgument,\n getTypeName,\n maybeGetArgumentValue,\n} from \"./utilities/graphql.js\";\nimport type {\n ApplicationManifest,\n ManifestOperation,\n} from \"../types/application-manifest\";\nimport { invariant } from \"../utilities/invariant.js\";\nimport { explorer } from \"./utilities/config.js\";\nimport type { ApolloClientAiAppsConfig } from \"../config/index.js\";\nimport { ApolloClientAiAppsConfigSchema } from \"../config/schema.js\";\nimport { z } from \"zod\";\nimport { createFragmentRegistry } from \"@apollo/client/cache\";\nimport {\n buildImportStatement,\n buildPropertySignature,\n buildKeywordLiteral,\n printRecast,\n type TSInterfaceBody,\n} from \"./utilities/recast.js\";\nimport type { TypeScriptDocumentsPluginConfig } from \"@graphql-codegen/typescript-operations\";\n\nconst b = recast.types.builders;\n\nexport declare namespace apolloClientAiApps {\n export type Target = ApolloClientAiAppsConfig.AppTarget;\n\n export interface Options {\n targets: Target[];\n devTarget?: Target | undefined;\n appsOutDir: string;\n schema?: string | undefined;\n }\n}\n\nconst root = process.cwd();\n\nconst VALID_TARGETS: apolloClientAiApps.Target[] = [\"openai\", \"mcp\"];\n\nfunction isValidTarget(target: unknown): target is apolloClientAiApps.Target {\n return VALID_TARGETS.includes(target as apolloClientAiApps.Target);\n}\n\nfunction buildExtensions(target: apolloClientAiApps.Target) {\n return [\".mjs\", \".js\", \".mts\", \".ts\", \".jsx\", \".tsx\", \".json\"].flatMap(\n (ext) => [`.${target}${ext}`, ext]\n );\n}\n\nexport function devTarget(target: string | undefined) {\n invariant(\n target === undefined || isValidTarget(target),\n `devTarget '${target}' is not a valid dev target. Must be one of ${VALID_TARGETS.join(\", \")}.`\n );\n\n return target;\n}\n\ninterface FileCache {\n hash: string;\n sources: DocumentNode[];\n}\n\nfunction md5(contents: string) {\n return createHash(\"md5\").update(contents).digest(\"hex\");\n}\n\n/**\n * Builds the AST for the comment used at the top of a generated file from this\n * plugin.\n *\n * @remarks\n * This comment informs users that generated files from this plugin should not\n * be edited since it is autogenerated by this plugin.\n */\nfunction buildHeaderComment() {\n return b.commentLine(\n \" This file is auto-generated by @apollo/client-ai-apps. Do not edit manually.\",\n true,\n false\n );\n}\n\n/**\n * Builds the `@apollo/client-ai-apps` ambient module declaration for the\n * `register.d.ts` file.\n *\n * @param registerInterfaceBody - The interface body for the `Register`\n * interface\n *\n * @example\n * ```ts\n * buildAmbientModuleDeclaration(interfaceBody);\n * // =>\n * // declare namespace \"@apollo/client-ai-apps\" {\n * // interface Register {\n * // // ...interfaceBody\n * // }\n * // }\n * ```\n */\nfunction buildAmbientModuleDeclaration(registerInterfaceBody: TSInterfaceBody) {\n const interfaceDeclaration = b.tsInterfaceDeclaration(\n b.identifier(\"Register\"),\n b.tsInterfaceBody(registerInterfaceBody)\n );\n\n const moduleDeclaration = b.tsModuleDeclaration(\n b.stringLiteral(\"@apollo/client-ai-apps\"),\n b.tsModuleBlock([interfaceDeclaration])\n );\n moduleDeclaration.declare = true;\n\n return moduleDeclaration;\n}\n\n/**\n * Gets the variables type name for an operation. GraphQL Codegen creates\n * variables types with the combination of operationName + operationType +\n * \"Variables\"\n *\n * @example\n * ```ts\n * getVariablesTypeName({ name: \"GetProduct\", type: \"query\" });\n * // => \"GetProductQueryVariables\"\n * ````\n */\nfunction getVariablesTypeName(operation: ManifestOperation) {\n const { name, type } = operation;\n\n return `${name}${type.charAt(0).toUpperCase()}${type.slice(1)}Variables`;\n}\n\n/**\n * Returns the code string written to the `.apollo-client-ai-apps/types/register.d.ts` files\n * for a given set of operations.\n */\nfunction getRegisteredTypeContents({\n operations,\n schema,\n flagSchemaBuildError = false,\n}: {\n operations: ManifestOperation[];\n schema: string | undefined;\n /**\n * Used during dev to avoid failing the build and instead output the error\n * to the console. When providing an error, the error message is generated as\n * a literal type value in the `register.d.ts` file so that users can see the\n * error message when hovering over the type.\n */\n flagSchemaBuildError?: false | Error;\n}) {\n if (flagSchemaBuildError) {\n const message = `[@apollo/client-ai-apps/vite]: There was an error building generated types. See the vite build output for more details.\\n\\n${flagSchemaBuildError.message}`;\n\n const importBaseStatement = buildImportStatement(\n [],\n \"@apollo/client-ai-apps\"\n );\n importBaseStatement.comments = [buildHeaderComment()];\n\n const typeAnnotation = b.tsLiteralType(b.stringLiteral(message));\n\n return printRecast(\n b.program([\n importBaseStatement,\n buildAmbientModuleDeclaration([\n buildPropertySignature(\"toolName\", typeAnnotation),\n buildPropertySignature(\n \"toolInputs\",\n b.tsTypeLiteral([buildPropertySignature(message, typeAnnotation)])\n ),\n ]),\n ])\n );\n }\n\n const toolNames = operations.flatMap((op) => op.tools.map((t) => t.name));\n\n if (toolNames.length === 0) {\n const emptyExport = b.exportNamedDeclaration(null);\n emptyExport.comments = [buildHeaderComment()];\n return printRecast(b.program([emptyExport]));\n }\n\n const importBaseStatement = buildImportStatement(\n [],\n \"@apollo/client-ai-apps\"\n );\n importBaseStatement.comments = [buildHeaderComment()];\n\n const toolNameProp = buildPropertySignature(\n \"toolName\",\n b.tsUnionType(toolNames.map((n) => b.tsLiteralType(b.stringLiteral(n))))\n );\n\n if (!schema) {\n return printRecast(\n b.program([\n importBaseStatement,\n buildAmbientModuleDeclaration([toolNameProp]),\n ])\n );\n }\n\n const importedVariableTypes = new Set<string>();\n const toolInputsValue: recast.types.namedTypes.TSPropertySignature[] = [];\n\n for (const operation of operations) {\n const variablesTypeName = getVariablesTypeName(operation);\n\n if (operation.tools.length) {\n importedVariableTypes.add(variablesTypeName);\n }\n\n for (const tool of operation.tools) {\n const variablesTypeRef = b.tsTypeReference(\n b.identifier(variablesTypeName)\n );\n let typeExpression:\n | recast.types.namedTypes.TSTypeReference\n | recast.types.namedTypes.TSIntersectionType = variablesTypeRef;\n\n if (tool.extraInputs?.length) {\n const extraInputsType = tool.extraInputs.map((ei) => {\n return buildPropertySignature(\n ei.name,\n buildKeywordLiteral(ei.type),\n true\n );\n });\n\n typeExpression = b.tsIntersectionType([\n variablesTypeRef,\n b.tsTypeLiteral(extraInputsType),\n ]);\n }\n\n toolInputsValue.push(buildPropertySignature(tool.name, typeExpression));\n }\n }\n\n return printRecast(\n b.program([\n importBaseStatement,\n buildImportStatement(\n Array.from(importedVariableTypes),\n \"./operation-types.js\",\n \"type\"\n ),\n buildAmbientModuleDeclaration([\n toolNameProp,\n buildPropertySignature(\"toolInputs\", b.tsTypeLiteral(toolInputsValue)),\n ]),\n ])\n );\n}\n\n/**\n * Generates and returns the code string written to the\n * `.apollo-client-ai-apps/types/operation-types.d.ts` file. Uses GraphQL\n * Codegen to introspect the given schema and extract variable types.\n */\nasync function generateOperationTypes(\n schema: string,\n documents: string[]\n): Promise<string> {\n const { generate } = await import(\"@graphql-codegen/cli\");\n\n if (documents.length === 0) {\n return `// Auto-generated by @apollo/client-ai-apps. Do not edit manually.\\nexport {};\\n`;\n }\n\n const output = await generate(\n {\n schema,\n documents,\n generates: {\n \"operation-types.d.ts\": {\n plugins: [\"typescript-operations\"],\n config: {\n nonOptionalTypename: true,\n skipTypeNameForRoot: true,\n namingConvention: \"keep\",\n } satisfies TypeScriptDocumentsPluginConfig,\n },\n },\n silent: true,\n } as Parameters<typeof generate>[0],\n false\n );\n\n const content = (output as { filename: string; content: string }[])[0]\n .content;\n return `// Auto-generated by @apollo/client-ai-apps. Do not edit manually.\\n${content}`;\n}\n\n/**\n * Gets the name of an exported type (e.g. `export type x`) from a TypeScript\n * AST statement.\n */\nfunction getExportedTypeAliasName(\n statement: recast.types.namedTypes.Statement\n): string | undefined {\n if (statement.type !== \"ExportNamedDeclaration\") return;\n\n const declaration = (\n statement as recast.types.namedTypes.ExportNamedDeclaration\n ).declaration;\n\n if (!declaration || declaration.type !== \"TSTypeAliasDeclaration\") return;\n\n const alias = declaration as recast.types.namedTypes.TSTypeAliasDeclaration;\n return typeof alias.id.name === \"string\" ? alias.id.name : undefined;\n}\n\n/**\n * Removes all non-`*Variables` types from the `operation-types.d.ts` file.\n * The `typescript` and `typescript-operations` codegen plugins add full schema\n * types and operation types. This function ensures those unused types are\n * removed.\n */\nfunction filterOperationTypes(\n content: string,\n rootTypeNames: Set<string>\n): string {\n const ast = recast.parse(content, { parser: typescriptParser });\n const statements: recast.types.namedTypes.Statement[] = ast.program.body;\n const typeMap = new Map<\n string,\n recast.types.namedTypes.TSTypeAliasDeclaration\n >();\n\n for (const statement of statements) {\n const name = getExportedTypeAliasName(statement);\n\n if (name) {\n typeMap.set(\n name,\n (statement as recast.types.namedTypes.ExportNamedDeclaration)\n .declaration as recast.types.namedTypes.TSTypeAliasDeclaration\n );\n }\n }\n\n const reachable = new Set<string>(rootTypeNames);\n const queue = Array.from(rootTypeNames);\n\n while (queue.length > 0) {\n const name = queue.shift()!;\n const node = typeMap.get(name);\n\n if (!node) continue;\n\n recast.visit(node, {\n visitTSTypeReference(path) {\n const typeName = path.value.typeName?.name as string | undefined;\n\n if (typeName && !reachable.has(typeName)) {\n reachable.add(typeName);\n queue.push(typeName);\n }\n\n this.traverse(path);\n },\n });\n }\n\n ast.program.body = statements.filter((statement) => {\n const name = getExportedTypeAliasName(statement);\n return name === undefined || reachable.has(name);\n });\n\n return printRecast(ast);\n}\n\nexport function apolloClientAiApps(\n options: apolloClientAiApps.Options\n): Plugin {\n const targets = Array.from(new Set(options.targets));\n const {\n devTarget = targets.length === 1 ? targets[0] : undefined,\n appsOutDir,\n schema,\n } = options;\n let config!: ResolvedConfig;\n\n const fragments = createFragmentRegistry();\n\n invariant(\n Array.isArray(targets) && targets.length > 0,\n \"The `targets` option must be a non-empty array\"\n );\n\n invariant(\n targets.every(isValidTarget),\n `All targets must be one of: ${VALID_TARGETS.join(\", \")}`\n );\n\n invariant(\n path.basename(path.normalize(appsOutDir)) === \"apps\",\n \"`appsOutDir` must end with `apps` as the final path segment (e.g. `path/to/apps`).\"\n );\n\n const client = new ApolloClient({\n cache: new InMemoryCache({ fragments }),\n link: processQueryLink,\n });\n\n let sources: DocumentNode[] = [];\n\n function recomputeSources(cache: Map<string, FileCache>) {\n sources = Array.from(cache.values()).flatMap((entry) => entry.sources);\n }\n\n async function getManifestOperations() {\n if (sources === getManifestOperations.cache.sources) {\n return getManifestOperations.cache.manifestOperations;\n }\n\n const manifestOperations = [];\n for (const source of sources) {\n const operationDef = source.definitions.find(\n (d) => d.kind === Kind.OPERATION_DEFINITION\n );\n\n if (!operationDef) continue;\n\n switch (operationDef.operation) {\n case OperationTypeNode.QUERY: {\n const result = await client.query<ManifestOperation>({\n query: source,\n fetchPolicy: \"no-cache\",\n });\n const data = result.data!;\n\n if (data.tools.length > 0 || data.prefetch) {\n manifestOperations.push(data);\n }\n break;\n }\n case OperationTypeNode.MUTATION: {\n const result = await client.mutate<ManifestOperation>({\n mutation: source,\n fetchPolicy: \"no-cache\",\n });\n const data = result.data!;\n\n if (data.tools.length > 0 || data.prefetch) {\n manifestOperations.push(data);\n }\n break;\n }\n default:\n throw new Error(\n `Found unsupported operation type '${operationDef.operation}'. Only queries and mutations are supported.`\n );\n }\n }\n\n getManifestOperations.cache = { sources, manifestOperations };\n\n return manifestOperations;\n }\n\n getManifestOperations.cache = {\n sources,\n manifestOperations: [] as ManifestOperation[],\n };\n\n async function processFile(file: string) {\n const code = fs.readFileSync(file, \"utf-8\");\n\n if (!code.includes(\"gql\")) return;\n\n const fileHash = md5(code);\n if (processFile.cache.get(file)?.hash === fileHash) return;\n\n const sources = gqlPluckFromCodeStringSync(file, code, {\n modules: [\n { name: \"graphql-tag\", identifier: \"gql\" },\n { name: \"@apollo/client\", identifier: \"gql\" },\n ],\n }).map((source) => parse(source.body));\n\n const previousSources = processFile.cache.get(file)?.sources;\n\n if (previousSources && equal(sources, previousSources)) {\n processFile.cache.set(file, { hash: fileHash, sources: previousSources });\n return;\n }\n\n fragments.register(...sources);\n\n processFile.cache.set(file, { hash: fileHash, sources });\n recomputeSources(processFile.cache);\n }\n\n processFile.cache = new Map<string, FileCache>();\n\n async function generateManifest() {\n const appsConfig = await getAppsConfig();\n const operations = await getManifestOperations();\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 function getBuildResourceForTarget(target: apolloClientAiApps.Target) {\n const entryPoint = getResourceFromConfig(appsConfig, config.mode, target);\n\n if (entryPoint) {\n return entryPoint;\n }\n\n if (config.mode === \"production\") {\n return `${target}/index.html`;\n }\n\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 let resource: ApplicationManifest[\"resource\"];\n if (config.command === \"serve\") {\n // Dev mode: resource is a string (dev server URL)\n resource =\n getResourceFromConfig(appsConfig, config.mode, devTarget!) ??\n `http${config.server.https ? \"s\" : \"\"}://${config.server.host ?? \"localhost\"}:${config.server.port}`;\n } else {\n resource = Object.fromEntries(\n targets.map((target) => [target, getBuildResourceForTarget(target)])\n ) as { mcp?: string; openai?: string };\n }\n\n const packageJson = readPackageJson();\n const appName = appsConfig.name ?? packageJson.name;\n\n invariant(\n appName,\n \"Error generating application manifest. Could not determine app name. Set `name` in your apollo-client-ai-apps config or `package.json`.\"\n );\n\n const manifest: ApplicationManifest = {\n format: \"apollo-ai-app-manifest\",\n version: \"1\",\n appVersion: appsConfig.version ?? packageJson.version,\n name: appsConfig.name ?? packageJson.name,\n description: appsConfig.description ?? packageJson.description,\n hash: createHash(\"sha256\").update(Date.now().toString()).digest(\"hex\"),\n operations,\n resource,\n csp: {\n baseUriDomains: appsConfig.csp?.baseUriDomains ?? [],\n connectDomains: appsConfig.csp?.connectDomains ?? [],\n frameDomains: appsConfig.csp?.frameDomains ?? [],\n redirectDomains: appsConfig.csp?.redirectDomains ?? [],\n resourceDomains: appsConfig.csp?.resourceDomains ?? [],\n },\n };\n\n if (isNonEmptyObject(appsConfig.widgetSettings)) {\n manifest.widgetSettings = appsConfig.widgetSettings;\n }\n\n if (isNonEmptyObject(appsConfig.labels)) {\n manifest.labels = appsConfig.labels;\n }\n\n const manifestContents = JSON.stringify(manifest);\n\n // Always write to build directory so the MCP server picks it up\n writeFileSync(\n path.resolve(root, appsOutDir, appName, \".application-manifest.json\"),\n manifestContents\n );\n\n // Always write to the dev location so that the app can bundle the manifest content\n writeFileSync(\".application-manifest.json\", manifestContents);\n\n const manifestTypesFilepath = \".application-manifest.d.json.ts\";\n if (!fs.existsSync(manifestTypesFilepath)) {\n const manifestImport = b.importDeclaration(\n [b.importSpecifier(b.identifier(\"ApplicationManifest\"))],\n b.stringLiteral(\"@apollo/client-ai-apps\"),\n \"type\"\n );\n const manifestId = b.identifier(\"manifest\");\n manifestId.typeAnnotation = b.tsTypeAnnotation(\n b.tsTypeReference(b.identifier(\"ApplicationManifest\"), null)\n );\n const manifestDeclaration = b.variableDeclaration(\"const\", [\n b.variableDeclarator(manifestId, null),\n ]) as recast.types.namedTypes.VariableDeclaration & { declare: boolean };\n manifestDeclaration.declare = true;\n\n const exportDefault = b.exportDefaultDeclaration(\n b.identifier(\"manifest\")\n );\n\n const content = printRecast(\n b.program([manifestImport, manifestDeclaration, exportDefault])\n );\n\n writeFileSync(manifestTypesFilepath, content);\n }\n }\n\n async function generateTypesFiles() {\n let flagSchemaBuildError: false | Error = false;\n const operations = await getManifestOperations();\n\n if (operations === generateTypesFiles.cache) {\n return;\n }\n\n generateTypesFiles.cache = operations;\n\n if (schema) {\n try {\n const opTypesContent = await generateOperationTypes(\n schema,\n operations.map((op) => op.body)\n );\n\n const rootTypeNames = new Set(\n operations.flatMap((op) =>\n op.tools.length > 0 ? [getVariablesTypeName(op)] : []\n )\n );\n\n writeFileSync(\n path.resolve(\n root,\n \".apollo-client-ai-apps/types/operation-types.d.ts\"\n ),\n filterOperationTypes(opTypesContent, rootTypeNames),\n { cache: true }\n );\n } catch (e) {\n if (config.command === \"build\") {\n throw e;\n }\n\n flagSchemaBuildError = e as Error;\n console.error(\"[@apollo/client-ai-apps/vite]:\", e);\n }\n }\n\n const typesFileContents = getRegisteredTypeContents({\n operations,\n schema,\n flagSchemaBuildError,\n });\n\n writeFileSync(\n path.resolve(root, \".apollo-client-ai-apps/types/register.d.ts\"),\n typesFileContents,\n { cache: true }\n );\n }\n\n generateTypesFiles.cache = [] as ManifestOperation[] | undefined;\n\n return {\n name: \"@apollo/client-ai-apps/vite\",\n async buildStart() {\n // Scan all files on startup\n const files = await glob(\"./src/**/*.{ts,tsx,js,jsx}\", { fs });\n\n for (const file of files) {\n const fullPath = path.resolve(root, file);\n await processFile(fullPath);\n }\n\n await Promise.all([generateManifest(), generateTypesFiles()]);\n },\n configResolved(resolvedConfig) {\n config = resolvedConfig;\n },\n async configEnvironment(name) {\n if (!targets.includes(name as any)) return;\n\n const appsConfig = await getAppsConfig();\n const appName = appsConfig.name ?? readPackageJson().name;\n\n invariant(\n appName,\n \"Could not determine app name. Set `name` in your apollo-client-ai-apps config or `package.json`.\"\n );\n\n return {\n build: {\n outDir: path.join(appsOutDir, appName, name),\n },\n };\n },\n configureServer(server) {\n server.watcher.on(\"change\", async (file) => {\n if (file.endsWith(\"package.json\")) {\n readPackageJson.resetCache();\n await generateManifest();\n } else if (file.match(/\\.?apollo-client-ai-apps\\.config\\.\\w+$/)) {\n explorer.clearCaches();\n await generateManifest();\n } else if (file.match(/\\.(jsx?|tsx?)$/)) {\n await processFile(file);\n await Promise.all([generateManifest(), generateTypesFiles()]);\n }\n });\n },\n\n config(userConfig, { command }) {\n if (userConfig.build?.outDir) {\n console.warn(\n \"[@apollo/client-ai-apps/vite] `build.outDir` is set in your Vite config but will be \" +\n \"ignored. Use `appsOutDir` in the plugin options to control the output location.\"\n );\n }\n\n if (command === \"serve\") {\n invariant(\n isValidTarget(devTarget) || targets.length === 1,\n \"`devTarget` must be set for development when using multiple targets.\"\n );\n\n const target = devTarget ?? targets[0];\n\n return {\n resolve: {\n extensions: buildExtensions(target),\n conditions: [target, ...defaultClientConditions],\n },\n };\n }\n\n return {\n environments: Object.fromEntries(\n targets.map((target) => [\n target,\n {\n consumer: \"client\",\n webCompatible: true,\n resolve: {\n extensions: buildExtensions(target),\n conditions: [target, ...defaultClientConditions],\n },\n },\n ])\n ),\n builder: {\n buildApp: async (builder) => {\n await Promise.all(\n targets.map((target) =>\n builder.build(builder.environments[target])\n )\n );\n },\n },\n };\n },\n transformIndexHtml(html, ctx) {\n if (!ctx.server) return html;\n\n let baseUrl = (\n ctx.server.config?.server?.origin ??\n ctx.server.resolvedUrls?.local[0] ??\n \"\"\n ).replace(/\\/$/, \"\");\n baseUrl = baseUrl.replace(/\\/$/, \"\");\n\n return (\n html\n // import \"/@vite/...\" or \"/@react-refresh\"\n .replace(/(from\\s+[\"'])\\/([^\"']+)/g, `$1${baseUrl}/$2`)\n // src=\"/src/...\"\n .replace(/(src=[\"'])\\/([^\"']+)/gi, `$1${baseUrl}/$2`)\n );\n },\n } satisfies Plugin;\n}\n\nconst processQueryLink = new ApolloLink((operation) => {\n const body = print(\n removeOperationDescription(\n removeManifestDirectives(sortTopLevelDefinitions(operation.query))\n )\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 toolDirectives =\n directives?.filter((d) => d.name.value === \"tool\") ?? [];\n\n const tools = toolDirectives.map((directive) => {\n const nameArg = getDirectiveArgument(\"name\", directive);\n const descriptionArg = getDirectiveArgument(\"description\", directive);\n\n let name: string;\n if (nameArg) {\n name = getArgumentValue(nameArg, Kind.STRING);\n } else {\n invariant(\n toolDirectives.length === 1,\n `Operations with multiple @tool directives must provide a 'name' argument on each @tool`\n );\n invariant(\n definition.name?.value,\n `Anonymous operations cannot use @tool without providing a 'name' argument`\n );\n name = definition.name.value;\n }\n\n let description: string;\n if (descriptionArg) {\n description = getArgumentValue(descriptionArg, Kind.STRING);\n } else {\n invariant(\n toolDirectives.length === 1,\n `Operations with multiple @tool directives must provide a 'description' argument on each @tool`\n );\n invariant(\n definition.description?.value,\n `Operations using @tool without a 'description' argument must have a description on the operation definition`\n );\n description = definition.description.value;\n }\n\n const result = ToolDirectiveSchema.safeParse({\n name,\n description,\n extraInputs: maybeGetArgumentValue(\n getDirectiveArgument(\"extraInputs\", directive),\n Kind.LIST\n ),\n extraOutputs: maybeGetArgumentValue(\n getDirectiveArgument(\"extraOutputs\", directive),\n Kind.OBJECT\n ),\n labels: maybeGetArgumentValue(\n getDirectiveArgument(\"labels\", directive),\n Kind.OBJECT\n ),\n });\n\n if (result.error) {\n throw z.prettifyError(result.error);\n }\n\n return result.data;\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\nfunction removeOperationDescription(doc: DocumentNode): DocumentNode {\n return visit(doc, {\n OperationDefinition(node) {\n return { ...node, description: undefined };\n },\n });\n}\n\nfunction removeManifestDirectives(doc: DocumentNode) {\n return removeDirectivesFromDocument(\n [{ name: \"prefetch\" }, { name: \"tool\" }],\n doc\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\nfunction isNonEmptyObject<T extends object>(\n obj: T | null | undefined\n): obj is T {\n return !!obj && Object.keys(obj).length > 0;\n}\n\nasync function getAppsConfig() {\n const result = await explorer.search();\n const config = (result?.config ??\n {}) as Partial<ApolloClientAiAppsConfig.Config>;\n\n const parsed = ApolloClientAiAppsConfigSchema.safeParse(config);\n\n if (parsed.error) {\n throw z.prettifyError(parsed.error);\n }\n\n return parsed.data;\n}\n\nfunction getResourceFromConfig(\n appsConfig: z.infer<typeof ApolloClientAiAppsConfigSchema>,\n mode: string,\n target: apolloClientAiApps.Target\n) {\n if (!appsConfig.entry || !appsConfig.entry[mode]) {\n return;\n }\n\n const config = appsConfig.entry[mode];\n\n return typeof config === \"string\" ? config : config[target];\n}\n\nfunction readPackageJson(): Record<string, any> {\n if (readPackageJson.cache) {\n return readPackageJson.cache;\n }\n\n return (readPackageJson.cache = JSON.parse(\n fs.readFileSync(\"package.json\", \"utf-8\")\n ));\n}\n\nreadPackageJson.cache = undefined as Record<string, any> | undefined;\nreadPackageJson.resetCache = () => {\n readPackageJson.cache = undefined;\n};\n\nfunction writeFileSync(\n filepath: string,\n content: string,\n options: { cache?: boolean } = {}\n) {\n function writeFile() {\n fs.mkdirSync(path.dirname(filepath), { recursive: true });\n fs.writeFileSync(filepath, content, \"utf-8\");\n }\n\n if (!options.cache) {\n return writeFile();\n }\n\n const hash = md5(content);\n const cachedHash = writeFileSync.cache.get(filepath);\n\n if (hash !== cachedHash || !fs.existsSync(filepath)) {\n writeFileSync.cache.set(filepath, hash);\n writeFile();\n }\n}\n\nwriteFileSync.cache = new Map<string, string>();\n\nconst ToolDirectiveSchema = z.strictObject({\n name: z.stringFormat(\"toolName\", (value) => value.indexOf(\" \") === -1, {\n error: (iss) => `Tool with name \"${iss.input}\" must not contain spaces`,\n }),\n description: z.string(),\n extraInputs: z.optional(\n z.array(\n z.strictObject({\n name: z.string(),\n description: z.string(),\n type: z.literal([\"string\", \"boolean\", \"number\"]),\n })\n )\n ),\n extraOutputs: z.optional(z.record(z.string(), z.unknown())),\n labels: ApolloClientAiAppsConfigSchema.shape.labels.optional(),\n});\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
services:
|
|
2
|
+
graphql:
|
|
3
|
+
build: ./graphql-server
|
|
4
|
+
ports:
|
|
5
|
+
- "4000:4000"
|
|
6
|
+
volumes:
|
|
7
|
+
- ./schema.graphql:/data/schema.graphql
|
|
8
|
+
healthcheck:
|
|
9
|
+
test:
|
|
10
|
+
[
|
|
11
|
+
"CMD-SHELL",
|
|
12
|
+
'node -e "fetch(''http://localhost:4000'', {method: ''POST'', headers: {''content-type'': ''application/json''}, body: JSON.stringify({query: ''{__typename}''})}).then(r => r.ok ? process.exit(0) : process.exit(1)).catch(() => process.exit(1))"',
|
|
13
|
+
]
|
|
14
|
+
interval: 5s
|
|
15
|
+
timeout: 3s
|
|
16
|
+
retries: 5
|
|
17
|
+
start_period: 10s
|
|
18
|
+
|
|
19
|
+
mcp-server:
|
|
20
|
+
image: ghcr.io/apollographql/apollo-mcp-server:latest
|
|
21
|
+
ports:
|
|
22
|
+
- "8000:8000"
|
|
23
|
+
volumes:
|
|
24
|
+
- ./mcp-config.yaml:/config.yaml
|
|
25
|
+
- ./schema.graphql:/data/schema.graphql
|
|
26
|
+
- ./apps:/data/apps
|
|
27
|
+
command: ["/config.yaml"]
|
|
28
|
+
depends_on:
|
|
29
|
+
graphql:
|
|
30
|
+
condition: service_healthy
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
import { dirname } from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
|
|
5
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
|
|
7
|
+
export default function globalTeardown() {
|
|
8
|
+
execSync("docker compose down", { cwd: __dirname });
|
|
9
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { ApolloServer } from "@apollo/server";
|
|
3
|
+
import { startStandaloneServer } from "@apollo/server/standalone";
|
|
4
|
+
|
|
5
|
+
const typeDefs = readFileSync("/data/schema.graphql", "utf-8");
|
|
6
|
+
|
|
7
|
+
const resolvers = {
|
|
8
|
+
Query: {
|
|
9
|
+
hello: () => "Hello, world!",
|
|
10
|
+
echo: (_: unknown, { message }: { message: string }) =>
|
|
11
|
+
`${message} (${message})`,
|
|
12
|
+
user: () => ({ address: "1234 Main St", fullName: "MCP User" }),
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const server = new ApolloServer({ typeDefs, resolvers });
|
|
17
|
+
|
|
18
|
+
const { url } = await startStandaloneServer(server, {
|
|
19
|
+
listen: { port: 4000, host: "0.0.0.0" },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
console.log(`GraphQL server ready at ${url}`);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
endpoint: http://graphql:4000/
|
|
2
|
+
|
|
3
|
+
schema:
|
|
4
|
+
source: local
|
|
5
|
+
path: /data/schema.graphql
|
|
6
|
+
|
|
7
|
+
introspection:
|
|
8
|
+
introspect:
|
|
9
|
+
enabled: true
|
|
10
|
+
execute:
|
|
11
|
+
enabled: true
|
|
12
|
+
|
|
13
|
+
transport:
|
|
14
|
+
type: streamable_http
|
|
15
|
+
port: 8000
|
|
16
|
+
|
|
17
|
+
health_check:
|
|
18
|
+
enabled: true
|
|
19
|
+
path: /health
|
|
20
|
+
|
|
21
|
+
cors:
|
|
22
|
+
enabled: true
|
|
23
|
+
allow_any_origin: true
|
|
24
|
+
|
|
25
|
+
logging:
|
|
26
|
+
level: info
|
|
27
|
+
|
|
28
|
+
overrides:
|
|
29
|
+
mutation_mode: all
|