ci: fix unhandled typescript exceptions and strict eslint errors caught by the pipeline
Some checks failed
Monorepo Pipeline / ⚡ Prioritize Release (push) Successful in 2s
Monorepo Pipeline / 🧹 Lint (push) Failing after 9s
Monorepo Pipeline / 🏗️ Build (push) Failing after 9s
Monorepo Pipeline / 🧪 Test (push) Failing after 9s
Monorepo Pipeline / 🚀 Release (push) Has been skipped
Monorepo Pipeline / 🐳 Build Gatekeeper (Product) (push) Has been skipped
Monorepo Pipeline / 🐳 Build Build-Base (push) Has been skipped
Monorepo Pipeline / 🐳 Build Production Runtime (push) Has been skipped
Some checks failed
Monorepo Pipeline / ⚡ Prioritize Release (push) Successful in 2s
Monorepo Pipeline / 🧹 Lint (push) Failing after 9s
Monorepo Pipeline / 🏗️ Build (push) Failing after 9s
Monorepo Pipeline / 🧪 Test (push) Failing after 9s
Monorepo Pipeline / 🚀 Release (push) Has been skipped
Monorepo Pipeline / 🐳 Build Gatekeeper (Product) (push) Has been skipped
Monorepo Pipeline / 🐳 Build Build-Base (push) Has been skipped
Monorepo Pipeline / 🐳 Build Production Runtime (push) Has been skipped
This commit is contained in:
@@ -15,6 +15,8 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./packages/gitea-mcp
|
context: ./packages/gitea-mcp
|
||||||
container_name: gitea-mcp
|
container_name: gitea-mcp
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
ports:
|
ports:
|
||||||
- "3001:3001"
|
- "3001:3001"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -25,6 +27,8 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./packages/memory-mcp
|
context: ./packages/memory-mcp
|
||||||
container_name: memory-mcp
|
container_name: memory-mcp
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
ports:
|
ports:
|
||||||
- "3002:3002"
|
- "3002:3002"
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -37,6 +41,8 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./packages/umami-mcp
|
context: ./packages/umami-mcp
|
||||||
container_name: umami-mcp
|
container_name: umami-mcp
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
ports:
|
ports:
|
||||||
- "3003:3003"
|
- "3003:3003"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -47,6 +53,8 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./packages/serpbear-mcp
|
context: ./packages/serpbear-mcp
|
||||||
container_name: serpbear-mcp
|
container_name: serpbear-mcp
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
ports:
|
ports:
|
||||||
- "3004:3004"
|
- "3004:3004"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -57,6 +65,8 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./packages/glitchtip-mcp
|
context: ./packages/glitchtip-mcp
|
||||||
container_name: glitchtip-mcp
|
container_name: glitchtip-mcp
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
ports:
|
ports:
|
||||||
- "3005:3005"
|
- "3005:3005"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -67,6 +77,8 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./packages/klz-payload-mcp
|
context: ./packages/klz-payload-mcp
|
||||||
container_name: klz-payload-mcp
|
container_name: klz-payload-mcp
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
ports:
|
ports:
|
||||||
- "3006:3006"
|
- "3006:3006"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
69
eslint-errors-2.txt
Normal file
69
eslint-errors-2.txt
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/gitea-mcp/src/index.ts[24m[0m
|
||||||
|
[0m [2m11:0[22m [31merror[39m Parsing error: Identifier expected[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/glitchtip-mcp/src/index.ts[24m[0m
|
||||||
|
[0m [2m124:19[22m [33mwarning[39m 'res' is assigned a value but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/klz-payload-mcp/src/index.ts[24m[0m
|
||||||
|
[0m [2m39:18[22m [33mwarning[39m 'e' is defined but never used. Allowed unused caught errors must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/memory-mcp/src/qdrant.test.ts[24m[0m
|
||||||
|
[0m [2m7:52[22m [33mwarning[39m 'text' is defined but never used. Allowed unused args must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/page-audit/src/report.ts[24m[0m
|
||||||
|
[0m [2m7:47[22m [33mwarning[39m 'PageAuditData' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m7:62[22m [33mwarning[39m 'AuditIssue' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/components/FieldGenerators/AiFieldButton.tsx[24m[0m
|
||||||
|
[0m [2m11:13[22m [33mwarning[39m 'value' is assigned a value but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/components/FieldGenerators/GenerateSlugButton.tsx[24m[0m
|
||||||
|
[0m [2m20:21[22m [33mwarning[39m 'replaceState' is assigned a value but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m21:13[22m [33mwarning[39m 'value' is assigned a value but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/components/FieldGenerators/GenerateThumbnailButton.tsx[24m[0m
|
||||||
|
[0m [2m21:13[22m [33mwarning[39m 'value' is assigned a value but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/components/OptimizeButton.tsx[24m[0m
|
||||||
|
[0m [2m5:10[22m [33mwarning[39m 'Button' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/tools/mcpAdapter.ts[24m[0m
|
||||||
|
[0m [2m44:15[22m [33mwarning[39m 'toolSchema' is assigned a value but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/tools/memoryDb.ts[24m[0m
|
||||||
|
[0m [2m89:31[22m [33mwarning[39m 'query' is defined but never used. Allowed unused args must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/tools/payloadLocal.ts[24m[0m
|
||||||
|
[0m [2m3:40[22m [33mwarning[39m 'User' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/types.ts[24m[0m
|
||||||
|
[0m [2m1:15[22m [33mwarning[39m 'Plugin' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/pdf-library/src/components/ConceptPDF.tsx[24m[0m
|
||||||
|
[0m [2m4:18[22m [33mwarning[39m 'PDFPage' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m5:10[22m [33mwarning[39m 'pdfStyles' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/pdf-library/src/components/EstimationPDF.tsx[24m[0m
|
||||||
|
[0m [2m4:18[22m [33mwarning[39m 'PDFPage' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m5:10[22m [33mwarning[39m 'pdfStyles' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m54:11[22m [33mwarning[39m 'getPageNum' is assigned a value but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/pdf-library/src/components/InfoPDF.tsx[24m[0m
|
||||||
|
[0m [2m5:13[22m [33mwarning[39m 'PDFPage' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m12:5[22m [33mwarning[39m 'pdfStyles' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/pdf-library/src/components/pdf/SharedUI.tsx[24m[0m
|
||||||
|
[0m [2m528:5[22m [33mwarning[39m 'bankData' is defined but never used. Allowed unused args must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/pdf-library/src/components/pdf/SimpleLayout.tsx[24m[0m
|
||||||
|
[0m [2m4:52[22m [33mwarning[39m 'PDFText' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m5:26[22m [33mwarning[39m 'pdfStyles' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/seo-engine/src/report.ts[24m[0m
|
||||||
|
[0m [2m5:3[22m [33mwarning[39m 'TopicCluster' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m6:3[22m [33mwarning[39m 'ContentGap' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m7:3[22m [33mwarning[39m 'CompetitorRanking' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[31m[1m✖ 28 problems (1 error, 27 warnings)[22m[39m[0m
|
||||||
|
[0m[31m[1m[22m[39m[0m
|
||||||
97
eslint-errors.txt
Normal file
97
eslint-errors.txt
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/gitea-mcp/src/index.ts[24m[0m
|
||||||
|
[0m [2m12:5[22m [33mwarning[39m 'Resource' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m14:10[22m [33mwarning[39m 'z' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m427:30[22m [33mwarning[39m 'e' is defined but never used. Allowed unused caught errors must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m745:50[22m [31merror[39m Unnecessary escape character: \/ [2mno-useless-escape[22m[0m
|
||||||
|
[0m [2m745:60[22m [31merror[39m Unnecessary escape character: \/ [2mno-useless-escape[22m[0m
|
||||||
|
[0m [2m799:54[22m [31merror[39m Unnecessary escape character: \/ [2mno-useless-escape[22m[0m
|
||||||
|
[0m [2m799:64[22m [31merror[39m Unnecessary escape character: \/ [2mno-useless-escape[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/glitchtip-mcp/src/index.ts[24m[0m
|
||||||
|
[0m [2m124:19[22m [33mwarning[39m 'res' is assigned a value but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/klz-payload-mcp/src/index.ts[24m[0m
|
||||||
|
[0m [2m39:18[22m [33mwarning[39m 'e' is defined but never used. Allowed unused caught errors must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/memory-mcp/src/qdrant.test.ts[24m[0m
|
||||||
|
[0m [2m7:52[22m [33mwarning[39m 'text' is defined but never used. Allowed unused args must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/page-audit/src/report.ts[24m[0m
|
||||||
|
[0m [2m7:47[22m [33mwarning[39m 'PageAuditData' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m7:62[22m [33mwarning[39m 'AuditIssue' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/chatPlugin.ts[24m[0m
|
||||||
|
[0m [2m1:15[22m [33mwarning[39m 'Config' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m10:17[22m [31merror[39m 'config' is never reassigned. Use 'const' instead [2mprefer-const[22m[0m
|
||||||
|
[0m [2m48:37[22m [33mwarning[39m 'req' is defined but never used. Allowed unused args must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/components/ChatWindow/index.tsx[24m[0m
|
||||||
|
[0m [2m43:5[22m [31merror[39m Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free [2m@typescript-eslint/ban-ts-comment[22m[0m
|
||||||
|
[0m [2m44:63[22m [33mwarning[39m 'setMessages' is assigned a value but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/components/FieldGenerators/AiFieldButton.tsx[24m[0m
|
||||||
|
[0m [2m11:13[22m [33mwarning[39m 'value' is assigned a value but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/components/FieldGenerators/GenerateSlugButton.tsx[24m[0m
|
||||||
|
[0m [2m20:21[22m [33mwarning[39m 'replaceState' is assigned a value but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m21:13[22m [33mwarning[39m 'value' is assigned a value but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/components/FieldGenerators/GenerateThumbnailButton.tsx[24m[0m
|
||||||
|
[0m [2m21:13[22m [33mwarning[39m 'value' is assigned a value but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/components/OptimizeButton.tsx[24m[0m
|
||||||
|
[0m [2m5:10[22m [33mwarning[39m 'Button' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/endpoints/chatEndpoint.ts[24m[0m
|
||||||
|
[0m [2m96:13[22m [31merror[39m Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free [2m@typescript-eslint/ban-ts-comment[22m[0m
|
||||||
|
[0m [2m100:13[22m [31merror[39m Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free [2m@typescript-eslint/ban-ts-comment[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/tools/mcpAdapter.ts[24m[0m
|
||||||
|
[0m [2m44:15[22m [33mwarning[39m 'toolSchema' is assigned a value but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m53:13[22m [31merror[39m Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free [2m@typescript-eslint/ban-ts-comment[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/tools/memoryDb.ts[24m[0m
|
||||||
|
[0m [2m50:13[22m [31merror[39m Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free [2m@typescript-eslint/ban-ts-comment[22m[0m
|
||||||
|
[0m [2m88:13[22m [31merror[39m Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free [2m@typescript-eslint/ban-ts-comment[22m[0m
|
||||||
|
[0m [2m89:31[22m [33mwarning[39m 'query' is defined but never used. Allowed unused args must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/tools/payloadLocal.ts[24m[0m
|
||||||
|
[0m [2m3:40[22m [33mwarning[39m 'User' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m25:13[22m [31merror[39m Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free [2m@typescript-eslint/ban-ts-comment[22m[0m
|
||||||
|
[0m [2m45:13[22m [31merror[39m Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free [2m@typescript-eslint/ban-ts-comment[22m[0m
|
||||||
|
[0m [2m61:13[22m [31merror[39m Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free [2m@typescript-eslint/ban-ts-comment[22m[0m
|
||||||
|
[0m [2m78:13[22m [31merror[39m Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free [2m@typescript-eslint/ban-ts-comment[22m[0m
|
||||||
|
[0m [2m95:13[22m [31merror[39m Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free [2m@typescript-eslint/ban-ts-comment[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/payload-ai/src/types.ts[24m[0m
|
||||||
|
[0m [2m1:15[22m [33mwarning[39m 'Plugin' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/pdf-library/src/components/ConceptPDF.tsx[24m[0m
|
||||||
|
[0m [2m4:18[22m [33mwarning[39m 'PDFPage' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m5:10[22m [33mwarning[39m 'pdfStyles' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/pdf-library/src/components/EstimationPDF.tsx[24m[0m
|
||||||
|
[0m [2m4:18[22m [33mwarning[39m 'PDFPage' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m5:10[22m [33mwarning[39m 'pdfStyles' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m54:11[22m [33mwarning[39m 'getPageNum' is assigned a value but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/pdf-library/src/components/InfoPDF.tsx[24m[0m
|
||||||
|
[0m [2m5:13[22m [33mwarning[39m 'PDFPage' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m12:5[22m [33mwarning[39m 'pdfStyles' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/pdf-library/src/components/pdf/SharedUI.tsx[24m[0m
|
||||||
|
[0m [2m528:5[22m [33mwarning[39m 'bankData' is defined but never used. Allowed unused args must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/pdf-library/src/components/pdf/SimpleLayout.tsx[24m[0m
|
||||||
|
[0m [2m4:52[22m [33mwarning[39m 'PDFText' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m5:26[22m [33mwarning[39m 'pdfStyles' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[4m/Users/marcmintel/Projects/at-mintel/packages/seo-engine/src/report.ts[24m[0m
|
||||||
|
[0m [2m5:3[22m [33mwarning[39m 'TopicCluster' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m6:3[22m [33mwarning[39m 'ContentGap' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m [2m7:3[22m [33mwarning[39m 'CompetitorRanking' is defined but never used. Allowed unused vars must match /^_/u [2m@typescript-eslint/no-unused-vars[22m[0m
|
||||||
|
[0m[0m
|
||||||
|
[0m[31m[1m✖ 49 problems (16 errors, 33 warnings)[22m[39m[0m
|
||||||
|
[0m[31m[1m[22m[39m[31m[1m 1 error and 0 warnings potentially fixable with the `--fix` option.[22m[39m[0m
|
||||||
|
[0m[31m[1m[22m[39m[0m
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,90 +1,98 @@
|
|||||||
import type { Config, Plugin } from 'payload'
|
import type { Plugin } from "payload";
|
||||||
import { AIChatPermissionsCollection } from './collections/AIChatPermissions.js'
|
import { AIChatPermissionsCollection } from "./collections/AIChatPermissions.js";
|
||||||
import type { PayloadChatPluginConfig } from './types.js'
|
import type { PayloadChatPluginConfig } from "./types.js";
|
||||||
import { optimizePostEndpoint } from './endpoints/optimizeEndpoint.js'
|
import { optimizePostEndpoint } from "./endpoints/optimizeEndpoint.js";
|
||||||
import { generateSlugEndpoint, generateThumbnailEndpoint, generateSingleFieldEndpoint } from './endpoints/generateEndpoints.js'
|
import {
|
||||||
|
generateSlugEndpoint,
|
||||||
|
generateThumbnailEndpoint,
|
||||||
|
generateSingleFieldEndpoint,
|
||||||
|
} from "./endpoints/generateEndpoints.js";
|
||||||
|
|
||||||
export const payloadChatPlugin =
|
export const payloadChatPlugin =
|
||||||
(pluginOptions: PayloadChatPluginConfig): Plugin =>
|
(pluginOptions: PayloadChatPluginConfig): Plugin =>
|
||||||
(incomingConfig) => {
|
(incomingConfig) => {
|
||||||
let config = { ...incomingConfig }
|
const config = { ...incomingConfig };
|
||||||
|
|
||||||
// If disabled, return config untouched
|
// If disabled, return config untouched
|
||||||
if (pluginOptions.enabled === false) {
|
if (pluginOptions.enabled === false) {
|
||||||
return config
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. Inject the Permissions Collection into the Schema
|
// 1. Inject the Permissions Collection into the Schema
|
||||||
const existingCollections = config.collections || []
|
const existingCollections = config.collections || [];
|
||||||
|
|
||||||
const mcpServers = pluginOptions.mcpServers || []
|
const mcpServers = pluginOptions.mcpServers || [];
|
||||||
|
|
||||||
// Dynamically populate the select options for Collections and MCP Servers
|
// Dynamically populate the select options for Collections and MCP Servers
|
||||||
const permissionCollection = { ...AIChatPermissionsCollection }
|
const permissionCollection = { ...AIChatPermissionsCollection };
|
||||||
const collectionField = permissionCollection.fields.find(f => 'name' in f && f.name === 'allowedCollections') as any
|
const collectionField = permissionCollection.fields.find(
|
||||||
if (collectionField) {
|
(f) => "name" in f && f.name === "allowedCollections",
|
||||||
collectionField.options = existingCollections.map(c => ({
|
) as any;
|
||||||
label: c.labels?.singular || c.slug,
|
if (collectionField) {
|
||||||
value: c.slug
|
collectionField.options = existingCollections.map((c) => ({
|
||||||
}))
|
label: c.labels?.singular || c.slug,
|
||||||
}
|
value: c.slug,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
const mcpField = permissionCollection.fields.find(f => 'name' in f && f.name === 'allowedMcpServers') as any
|
const mcpField = permissionCollection.fields.find(
|
||||||
if (mcpField) {
|
(f) => "name" in f && f.name === "allowedMcpServers",
|
||||||
mcpField.options = mcpServers.map(s => ({
|
) as any;
|
||||||
label: s.name,
|
if (mcpField) {
|
||||||
value: s.name
|
mcpField.options = mcpServers.map((s) => ({
|
||||||
}))
|
label: s.name,
|
||||||
}
|
value: s.name,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
config.collections = [...existingCollections, permissionCollection]
|
config.collections = [...existingCollections, permissionCollection];
|
||||||
|
|
||||||
// 2. Register Custom API Endpoint for the AI Chat
|
// 2. Register Custom API Endpoint for the AI Chat
|
||||||
config.endpoints = [
|
config.endpoints = [
|
||||||
...(config.endpoints || []),
|
...(config.endpoints || []),
|
||||||
{
|
{
|
||||||
path: '/api/mcp-chat',
|
path: "/api/mcp-chat",
|
||||||
method: 'post',
|
method: "post",
|
||||||
handler: async (req) => {
|
handler: async (_req) => {
|
||||||
// Fallback simple handler while developing endpoint logic
|
// Fallback simple handler while developing endpoint logic
|
||||||
return Response.json({ message: "Chat endpoint active" })
|
return Response.json({ message: "Chat endpoint active" });
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/api/mintel-ai/optimize',
|
path: "/api/mintel-ai/optimize",
|
||||||
method: 'post',
|
method: "post",
|
||||||
handler: optimizePostEndpoint,
|
handler: optimizePostEndpoint,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/api/mintel-ai/generate-slug',
|
path: "/api/mintel-ai/generate-slug",
|
||||||
method: 'post',
|
method: "post",
|
||||||
handler: generateSlugEndpoint,
|
handler: generateSlugEndpoint,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/api/mintel-ai/generate-thumbnail',
|
path: "/api/mintel-ai/generate-thumbnail",
|
||||||
method: 'post',
|
method: "post",
|
||||||
handler: generateThumbnailEndpoint,
|
handler: generateThumbnailEndpoint,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/api/mintel-ai/generate-single-field',
|
path: "/api/mintel-ai/generate-single-field",
|
||||||
method: 'post',
|
method: "post",
|
||||||
handler: generateSingleFieldEndpoint,
|
handler: generateSingleFieldEndpoint,
|
||||||
},
|
},
|
||||||
]
|
];
|
||||||
|
|
||||||
// 3. Inject Chat React Component into Admin UI
|
// 3. Inject Chat React Component into Admin UI
|
||||||
if (pluginOptions.renderChatBubble !== false) {
|
if (pluginOptions.renderChatBubble !== false) {
|
||||||
config.admin = {
|
config.admin = {
|
||||||
...(config.admin || {}),
|
...(config.admin || {}),
|
||||||
components: {
|
components: {
|
||||||
...(config.admin?.components || {}),
|
...(config.admin?.components || {}),
|
||||||
providers: [
|
providers: [
|
||||||
...(config.admin?.components?.providers || []),
|
...(config.admin?.components?.providers || []),
|
||||||
'@mintel/payload-ai/components/ChatWindow#ChatWindowProvider',
|
"@mintel/payload-ai/components/ChatWindow#ChatWindowProvider",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config;
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,136 +1,158 @@
|
|||||||
'use client'
|
"use client";
|
||||||
|
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from "react";
|
||||||
import { useChat } from '@ai-sdk/react'
|
import { useChat } from "@ai-sdk/react";
|
||||||
import './ChatWindow.scss'
|
import "./ChatWindow.scss";
|
||||||
|
|
||||||
export const ChatWindowProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
export const ChatWindowProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||||
return (
|
children,
|
||||||
<>
|
}) => {
|
||||||
{children}
|
return (
|
||||||
<ChatWindow />
|
<>
|
||||||
</>
|
{children}
|
||||||
)
|
<ChatWindow />
|
||||||
}
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const ChatWindow: React.FC = () => {
|
const ChatWindow: React.FC = () => {
|
||||||
const [isOpen, setIsOpen] = useState(false)
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [pageContext, setPageContext] = useState<any>({ url: '' })
|
const [pageContext, setPageContext] = useState<any>({ url: "" });
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== "undefined") {
|
||||||
const path = window.location.pathname;
|
const path = window.location.pathname;
|
||||||
let collectionSlug = null;
|
let collectionSlug = null;
|
||||||
let id = null;
|
let id = null;
|
||||||
// Payload admin URLs are usually /admin/collections/:slug/:id
|
// Payload admin URLs are usually /admin/collections/:slug/:id
|
||||||
const match = path.match(/\/collections\/([^/]+)(?:\/([^/]+))?/);
|
const match = path.match(/\/collections\/([^/]+)(?:\/([^/]+))?/);
|
||||||
if (match) {
|
if (match) {
|
||||||
collectionSlug = match[1];
|
collectionSlug = match[1];
|
||||||
if (match[2] && match[2] !== 'create') {
|
if (match[2] && match[2] !== "create") {
|
||||||
id = match[2];
|
id = match[2];
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setPageContext({
|
|
||||||
url: window.location.href,
|
|
||||||
title: document.title,
|
|
||||||
collectionSlug,
|
|
||||||
id
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}, [isOpen]) // Refresh context when chat is opened
|
}
|
||||||
|
|
||||||
// @ts-ignore - AI hook version mismatch between core and react packages
|
setPageContext({
|
||||||
const { messages, input, handleInputChange, handleSubmit, setMessages } = useChat({
|
url: window.location.href,
|
||||||
api: '/api/mcp-chat',
|
title: document.title,
|
||||||
initialMessages: [],
|
collectionSlug,
|
||||||
body: {
|
id,
|
||||||
pageContext
|
});
|
||||||
}
|
}
|
||||||
} as any)
|
}, [isOpen]); // Refresh context when chat is opened
|
||||||
|
|
||||||
// Basic implementation to toggle chat window and submit messages
|
// @ts-expect-error - AI hook version mismatch between core and react packages
|
||||||
return (
|
const { messages, input, handleInputChange, handleSubmit } = useChat({
|
||||||
<div className="payload-mcp-chat-container">
|
api: "/api/mcp-chat",
|
||||||
<button
|
initialMessages: [],
|
||||||
className="payload-mcp-chat-toggle"
|
body: {
|
||||||
onClick={() => setIsOpen(!isOpen)}
|
pageContext,
|
||||||
|
},
|
||||||
|
} as any);
|
||||||
|
|
||||||
|
// Basic implementation to toggle chat window and submit messages
|
||||||
|
return (
|
||||||
|
<div className="payload-mcp-chat-container">
|
||||||
|
<button
|
||||||
|
className="payload-mcp-chat-toggle"
|
||||||
|
onClick={() => setIsOpen(!isOpen)}
|
||||||
|
style={{
|
||||||
|
position: "fixed",
|
||||||
|
bottom: "20px",
|
||||||
|
right: "20px",
|
||||||
|
zIndex: 9999,
|
||||||
|
padding: "12px 24px",
|
||||||
|
backgroundColor: "#000",
|
||||||
|
color: "#fff",
|
||||||
|
borderRadius: "8px",
|
||||||
|
border: "none",
|
||||||
|
cursor: "pointer",
|
||||||
|
fontWeight: "bold",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{isOpen ? "Close AI Chat" : "Ask AI"}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{isOpen && (
|
||||||
|
<div
|
||||||
|
className="payload-mcp-chat-window"
|
||||||
|
style={{
|
||||||
|
position: "fixed",
|
||||||
|
bottom: "80px",
|
||||||
|
right: "20px",
|
||||||
|
width: "450px",
|
||||||
|
height: "650px",
|
||||||
|
backgroundColor: "#fff",
|
||||||
|
border: "1px solid #eaeaea",
|
||||||
|
borderRadius: "12px",
|
||||||
|
zIndex: 9999,
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
boxShadow: "0 10px 40px rgba(0,0,0,0.1)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="chat-header"
|
||||||
|
style={{
|
||||||
|
padding: "16px",
|
||||||
|
borderBottom: "1px solid #eaeaea",
|
||||||
|
backgroundColor: "#f9f9f9",
|
||||||
|
borderTopLeftRadius: "12px",
|
||||||
|
borderTopRightRadius: "12px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<h3 style={{ margin: 0, fontSize: "16px" }}>Payload MCP Chat</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
className="chat-messages"
|
||||||
|
style={{ flex: 1, padding: "16px", overflowY: "auto" }}
|
||||||
|
>
|
||||||
|
{messages.map((m: any) => (
|
||||||
|
<div
|
||||||
|
key={m.id}
|
||||||
style={{
|
style={{
|
||||||
position: 'fixed',
|
marginBottom: "12px",
|
||||||
bottom: '20px',
|
textAlign: m.role === "user" ? "right" : "left",
|
||||||
right: '20px',
|
|
||||||
zIndex: 9999,
|
|
||||||
padding: '12px 24px',
|
|
||||||
backgroundColor: '#000',
|
|
||||||
color: '#fff',
|
|
||||||
borderRadius: '8px',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
fontWeight: 'bold'
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{isOpen ? 'Close AI Chat' : 'Ask AI'}
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{isOpen && (
|
|
||||||
<div
|
<div
|
||||||
className="payload-mcp-chat-window"
|
style={{
|
||||||
style={{
|
display: "inline-block",
|
||||||
position: 'fixed',
|
padding: "8px 12px",
|
||||||
bottom: '80px',
|
borderRadius: "8px",
|
||||||
right: '20px',
|
backgroundColor: m.role === "user" ? "#000" : "#f0f0f0",
|
||||||
width: '450px',
|
color: m.role === "user" ? "#fff" : "#000",
|
||||||
height: '650px',
|
maxWidth: "80%",
|
||||||
backgroundColor: '#fff',
|
}}
|
||||||
border: '1px solid #eaeaea',
|
|
||||||
borderRadius: '12px',
|
|
||||||
zIndex: 9999,
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
boxShadow: '0 10px 40px rgba(0,0,0,0.1)'
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<div className="chat-header" style={{ padding: '16px', borderBottom: '1px solid #eaeaea', backgroundColor: '#f9f9f9', borderTopLeftRadius: '12px', borderTopRightRadius: '12px' }}>
|
{m.role === "user" ? "G: " : "AI: "}
|
||||||
<h3 style={{ margin: 0, fontSize: '16px' }}>Payload MCP Chat</h3>
|
{m.content}
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="chat-messages" style={{ flex: 1, padding: '16px', overflowY: 'auto' }}>
|
|
||||||
{messages.map((m: any) => (
|
|
||||||
<div key={m.id} style={{
|
|
||||||
marginBottom: '12px',
|
|
||||||
textAlign: m.role === 'user' ? 'right' : 'left'
|
|
||||||
}}>
|
|
||||||
<div style={{
|
|
||||||
display: 'inline-block',
|
|
||||||
padding: '8px 12px',
|
|
||||||
borderRadius: '8px',
|
|
||||||
backgroundColor: m.role === 'user' ? '#000' : '#f0f0f0',
|
|
||||||
color: m.role === 'user' ? '#fff' : '#000',
|
|
||||||
maxWidth: '80%'
|
|
||||||
}}>
|
|
||||||
{m.role === 'user' ? 'G: ' : 'AI: '}
|
|
||||||
{m.content}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<form onSubmit={handleSubmit} style={{ padding: '16px', borderTop: '1px solid #eaeaea' }}>
|
|
||||||
<input
|
|
||||||
value={input}
|
|
||||||
placeholder="Ask me anything or use /commands..."
|
|
||||||
onChange={handleInputChange}
|
|
||||||
style={{
|
|
||||||
width: '100%',
|
|
||||||
padding: '12px',
|
|
||||||
borderRadius: '8px',
|
|
||||||
border: '1px solid #eaeaea',
|
|
||||||
boxSizing: 'border-box'
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
style={{ padding: "16px", borderTop: "1px solid #eaeaea" }}
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
value={input}
|
||||||
|
placeholder="Ask me anything or use /commands..."
|
||||||
|
onChange={handleInputChange}
|
||||||
|
style={{
|
||||||
|
width: "100%",
|
||||||
|
padding: "12px",
|
||||||
|
borderRadius: "8px",
|
||||||
|
border: "1px solid #eaeaea",
|
||||||
|
boxSizing: "border-box",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
)
|
)}
|
||||||
}
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,115 +1,143 @@
|
|||||||
import { streamText } from 'ai'
|
import { streamText } from "ai";
|
||||||
import { createOpenAI } from '@ai-sdk/openai'
|
import { createOpenAI } from "@ai-sdk/openai";
|
||||||
import { generatePayloadLocalTools } from '../tools/payloadLocal.js'
|
import { generatePayloadLocalTools } from "../tools/payloadLocal.js";
|
||||||
import { createMcpTools } from '../tools/mcpAdapter.js'
|
import { createMcpTools } from "../tools/mcpAdapter.js";
|
||||||
import { generateMemoryTools } from '../tools/memoryDb.js'
|
import { generateMemoryTools } from "../tools/memoryDb.js";
|
||||||
import type { PayloadRequest } from 'payload'
|
import type { PayloadRequest } from "payload";
|
||||||
|
|
||||||
const openrouter = createOpenAI({
|
const openrouter = createOpenAI({
|
||||||
baseURL: 'https://openrouter.ai/api/v1',
|
baseURL: "https://openrouter.ai/api/v1",
|
||||||
apiKey: process.env.OPENROUTER_API_KEY || 'dummy_key',
|
apiKey: process.env.OPENROUTER_API_KEY || "dummy_key",
|
||||||
})
|
});
|
||||||
|
|
||||||
export const handleMcpChat = async (req: PayloadRequest) => {
|
export const handleMcpChat = async (req: PayloadRequest) => {
|
||||||
if (!req.user) {
|
if (!req.user) {
|
||||||
return Response.json({ error: 'Unauthorized. You must be logged in to use AI Chat.' }, { status: 401 })
|
return Response.json(
|
||||||
|
{ error: "Unauthorized. You must be logged in to use AI Chat." },
|
||||||
|
{ status: 401 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { messages, pageContext } = ((await req.json?.()) || {
|
||||||
|
messages: [],
|
||||||
|
}) as { messages: any[]; pageContext?: any };
|
||||||
|
|
||||||
|
// 1. Check AI Permissions for req.user
|
||||||
|
// Look up the collection for permissions
|
||||||
|
const permissionsQuery = await req.payload.find({
|
||||||
|
collection: "ai-chat-permissions" as any,
|
||||||
|
where: {
|
||||||
|
or: [
|
||||||
|
{ targetUser: { equals: req.user.id } },
|
||||||
|
{ targetRole: { equals: req.user.role || "admin" } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
limit: 10,
|
||||||
|
});
|
||||||
|
|
||||||
|
const allowedCollections = new Set<string>();
|
||||||
|
const allowedMcpServers = new Set<string>();
|
||||||
|
|
||||||
|
for (const perm of permissionsQuery.docs) {
|
||||||
|
if (perm.allowedCollections) {
|
||||||
|
perm.allowedCollections.forEach((c: string) => allowedCollections.add(c));
|
||||||
}
|
}
|
||||||
|
if (perm.allowedMcpServers) {
|
||||||
const { messages, pageContext } = (await req.json?.() || { messages: [] }) as { messages: any[], pageContext?: any }
|
perm.allowedMcpServers.forEach((s: string) => allowedMcpServers.add(s));
|
||||||
|
|
||||||
// 1. Check AI Permissions for req.user
|
|
||||||
// Look up the collection for permissions
|
|
||||||
const permissionsQuery = await req.payload.find({
|
|
||||||
collection: 'ai-chat-permissions' as any,
|
|
||||||
where: {
|
|
||||||
or: [
|
|
||||||
{ targetUser: { equals: req.user.id } },
|
|
||||||
{ targetRole: { equals: req.user.role || 'admin' } }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
limit: 10
|
|
||||||
})
|
|
||||||
|
|
||||||
const allowedCollections = new Set<string>()
|
|
||||||
const allowedMcpServers = new Set<string>()
|
|
||||||
|
|
||||||
for (const perm of permissionsQuery.docs) {
|
|
||||||
if (perm.allowedCollections) {
|
|
||||||
perm.allowedCollections.forEach((c: string) => allowedCollections.add(c))
|
|
||||||
}
|
|
||||||
if (perm.allowedMcpServers) {
|
|
||||||
perm.allowedMcpServers.forEach((s: string) => allowedMcpServers.add(s))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let accessCollections = Array.from(allowedCollections)
|
let accessCollections = Array.from(allowedCollections);
|
||||||
if (accessCollections.length === 0) {
|
if (accessCollections.length === 0) {
|
||||||
// Fallback or demo config if not configured yet
|
// Fallback or demo config if not configured yet
|
||||||
accessCollections = ['users', 'pages', 'posts', 'products', 'leads', 'media']
|
accessCollections = [
|
||||||
|
"users",
|
||||||
|
"pages",
|
||||||
|
"posts",
|
||||||
|
"products",
|
||||||
|
"leads",
|
||||||
|
"media",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
let activeTools: Record<string, any> = {};
|
||||||
|
|
||||||
|
// 2. Generate Payload Local Tools
|
||||||
|
if (accessCollections.length > 0) {
|
||||||
|
const payloadTools = generatePayloadLocalTools(
|
||||||
|
req.payload,
|
||||||
|
req,
|
||||||
|
accessCollections,
|
||||||
|
);
|
||||||
|
activeTools = { ...activeTools, ...payloadTools };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Connect External MCPs
|
||||||
|
if (Array.from(allowedMcpServers).includes("gitea")) {
|
||||||
|
try {
|
||||||
|
const { tools: giteaTools } = await createMcpTools({
|
||||||
|
name: "gitea",
|
||||||
|
command: "npx",
|
||||||
|
args: [
|
||||||
|
"-y",
|
||||||
|
"@modelcontextprotocol/server-gitea",
|
||||||
|
"--url",
|
||||||
|
"https://git.mintel.int",
|
||||||
|
"--token",
|
||||||
|
process.env.GITEA_TOKEN || "",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
activeTools = { ...activeTools, ...giteaTools };
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to connect to Gitea MCP", e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let activeTools: Record<string, any> = {}
|
// 4. Inject Memory Database Tools
|
||||||
|
// We provide the user ID so memory is partitioned per user
|
||||||
|
const memoryTools = generateMemoryTools(req.user.id);
|
||||||
|
activeTools = { ...activeTools, ...memoryTools };
|
||||||
|
|
||||||
// 2. Generate Payload Local Tools
|
// 5. Build prompt to ensure it asks before saving
|
||||||
if (accessCollections.length > 0) {
|
const memorySystemPrompt = `
|
||||||
const payloadTools = generatePayloadLocalTools(req.payload, req, accessCollections)
|
|
||||||
activeTools = { ...activeTools, ...payloadTools }
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Connect External MCPs
|
|
||||||
if (Array.from(allowedMcpServers).includes('gitea')) {
|
|
||||||
try {
|
|
||||||
const { tools: giteaTools } = await createMcpTools({
|
|
||||||
name: 'gitea',
|
|
||||||
command: 'npx',
|
|
||||||
args: ['-y', '@modelcontextprotocol/server-gitea', '--url', 'https://git.mintel.int', '--token', process.env.GITEA_TOKEN || '']
|
|
||||||
})
|
|
||||||
activeTools = { ...activeTools, ...giteaTools }
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to connect to Gitea MCP', e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Inject Memory Database Tools
|
|
||||||
// We provide the user ID so memory is partitioned per user
|
|
||||||
const memoryTools = generateMemoryTools(req.user.id)
|
|
||||||
activeTools = { ...activeTools, ...memoryTools }
|
|
||||||
|
|
||||||
// 5. Build prompt to ensure it asks before saving
|
|
||||||
const memorySystemPrompt = `
|
|
||||||
You have access to a long-term vector memory database (Qdrant).
|
You have access to a long-term vector memory database (Qdrant).
|
||||||
If the user says "speicher das", "merk dir das", "vergiss das nicht" etc., you MUST use the save_memory tool.
|
If the user says "speicher das", "merk dir das", "vergiss das nicht" etc., you MUST use the save_memory tool.
|
||||||
If the user shares important context but doesn't explicitly ask you to remember it, you should ask "Soll ich mir das für die Zukunft merken?" before saving it. Do not ask for trivial things.
|
If the user shares important context but doesn't explicitly ask you to remember it, you should ask "Soll ich mir das für die Zukunft merken?" before saving it. Do not ask for trivial things.
|
||||||
`
|
`;
|
||||||
|
|
||||||
const contextContextStr = pageContext ? `
|
const contextContextStr = pageContext
|
||||||
|
? `
|
||||||
Current User Context:
|
Current User Context:
|
||||||
URL: ${pageContext.url || 'Unknown'}
|
URL: ${pageContext.url || "Unknown"}
|
||||||
Title: ${pageContext.title || 'Unknown'}
|
Title: ${pageContext.title || "Unknown"}
|
||||||
Collection: ${pageContext.collectionSlug || 'None'}
|
Collection: ${pageContext.collectionSlug || "None"}
|
||||||
Document ID: ${pageContext.id || 'None'}
|
Document ID: ${pageContext.id || "None"}
|
||||||
You can use this to understand what the user is currently looking at.
|
You can use this to understand what the user is currently looking at.
|
||||||
` : ''
|
`
|
||||||
|
: "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = streamText({
|
const result = streamText({
|
||||||
// @ts-ignore - AI SDK type mismatch
|
// @ts-expect-error - AI SDK type mismatch
|
||||||
model: openrouter('google/gemini-3.0-flash'),
|
model: openrouter("google/gemini-3.0-flash"),
|
||||||
messages,
|
messages,
|
||||||
tools: activeTools,
|
tools: activeTools,
|
||||||
// @ts-ignore - AI SDK type mismatch with maxSteps
|
// @ts-expect-error - AI SDK type mismatch with maxSteps
|
||||||
maxSteps: 10,
|
maxSteps: 10,
|
||||||
system: `You are a helpful Payload CMS Agent orchestrating the local Mintel ecosystem.
|
system: `You are a helpful Payload CMS Agent orchestrating the local Mintel ecosystem.
|
||||||
You only have access to tools explicitly granted by the Admin.
|
You only have access to tools explicitly granted by the Admin.
|
||||||
You can completely control Payload CMS (read, create, update, delete documents).
|
You can completely control Payload CMS (read, create, update, delete documents).
|
||||||
If you need more details to fulfill a request (e.g. creating a blog post), you can ask the user.
|
If you need more details to fulfill a request (e.g. creating a blog post), you can ask the user.
|
||||||
${contextContextStr}
|
${contextContextStr}
|
||||||
${memorySystemPrompt}`
|
${memorySystemPrompt}`,
|
||||||
})
|
});
|
||||||
|
|
||||||
return result.toTextStreamResponse()
|
return result.toTextStreamResponse();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("AI Error:", error)
|
console.error("AI Error:", error);
|
||||||
return Response.json({ error: 'Failed to process AI request' }, { status: 500 })
|
return Response.json(
|
||||||
}
|
{ error: "Failed to process AI request" },
|
||||||
}
|
{ status: 500 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,65 +1,72 @@
|
|||||||
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||||
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'
|
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
||||||
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
||||||
import { tool } from 'ai'
|
import { tool } from "ai";
|
||||||
import { z } from 'zod'
|
import { z } from "zod";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connects to an external MCP Server and maps its tools to Vercel AI SDK Tools.
|
* Connects to an external MCP Server and maps its tools to Vercel AI SDK Tools.
|
||||||
*/
|
*/
|
||||||
export async function createMcpTools(mcpConfig: { name: string, url?: string, command?: string, args?: string[] }) {
|
export async function createMcpTools(mcpConfig: {
|
||||||
let transport
|
name: string;
|
||||||
|
url?: string;
|
||||||
|
command?: string;
|
||||||
|
args?: string[];
|
||||||
|
}) {
|
||||||
|
let transport;
|
||||||
|
|
||||||
// Support both HTTP/SSE and STDIO transports
|
// Support both HTTP/SSE and STDIO transports
|
||||||
if (mcpConfig.url) {
|
if (mcpConfig.url) {
|
||||||
transport = new SSEClientTransport(new URL(mcpConfig.url))
|
transport = new SSEClientTransport(new URL(mcpConfig.url));
|
||||||
} else if (mcpConfig.command) {
|
} else if (mcpConfig.command) {
|
||||||
transport = new StdioClientTransport({
|
transport = new StdioClientTransport({
|
||||||
command: mcpConfig.command,
|
command: mcpConfig.command,
|
||||||
args: mcpConfig.args || [],
|
args: mcpConfig.args || [],
|
||||||
})
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid MCP config: Must provide either URL or Command.')
|
throw new Error("Invalid MCP config: Must provide either URL or Command.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = new Client(
|
const client = new Client(
|
||||||
{ name: `payload-ai-client-${mcpConfig.name}`, version: '1.0.0' },
|
{ name: `payload-ai-client-${mcpConfig.name}`, version: "1.0.0" },
|
||||||
{ capabilities: {} }
|
{ capabilities: {} },
|
||||||
)
|
);
|
||||||
|
|
||||||
await client.connect(transport)
|
await client.connect(transport);
|
||||||
|
|
||||||
// Fetch available tools from the external MCP server
|
// Fetch available tools from the external MCP server
|
||||||
const toolListResult = await client.listTools()
|
const toolListResult = await client.listTools();
|
||||||
const externalTools = toolListResult.tools || []
|
const externalTools = toolListResult.tools || [];
|
||||||
|
|
||||||
const aiSdkTools: Record<string, any> = {}
|
const aiSdkTools: Record<string, any> = {};
|
||||||
|
|
||||||
// Map each external tool to a Vercel AI SDK Tool
|
// Map each external tool to a Vercel AI SDK Tool
|
||||||
for (const extTool of externalTools) {
|
for (const extTool of externalTools) {
|
||||||
// Basic conversion of JSON Schema to Zod for the AI SDK
|
// Basic conversion of JSON Schema to Zod for the AI SDK
|
||||||
// Note: For a production ready adapter, you might need a more robust jsonSchemaToZod converter
|
// Note: For a production ready adapter, you might need a more robust jsonSchemaToZod converter
|
||||||
// or use AI SDK's new experimental generateSchema feature if available.
|
// or use AI SDK's new experimental generateSchema feature if available.
|
||||||
// Here we use a generic `z.any()` as a fallback since AI SDK requires a Zod schema.
|
// Here we use a generic `z.any()` as a fallback since AI SDK requires a Zod schema.
|
||||||
const toolSchema = extTool.inputSchema as Record<string, any>
|
const toolSchema = extTool.inputSchema as Record<string, any>;
|
||||||
|
|
||||||
// We create a simplified parameter parser.
|
// We create a simplified parameter parser.
|
||||||
// An ideal approach uses `jsonSchemaToZod` library or native AI SDK JSON schema support
|
// An ideal approach uses `jsonSchemaToZod` library or native AI SDK JSON schema support
|
||||||
// (introduced recently in `ai` package).
|
// (introduced recently in `ai` package).
|
||||||
|
|
||||||
aiSdkTools[`${mcpConfig.name}_${extTool.name}`] = tool({
|
aiSdkTools[`${mcpConfig.name}_${extTool.name}`] = tool({
|
||||||
description: `[From ${mcpConfig.name}] ${extTool.description || extTool.name}`,
|
description: `[From ${mcpConfig.name}] ${extTool.description || extTool.name}`,
|
||||||
parameters: z.any().describe('JSON matching the original MCP input_schema'), // Simplify for prototype
|
parameters: z
|
||||||
// @ts-ignore - AI strict mode overload bug with implicit zod inferences
|
.any()
|
||||||
execute: async (args: any) => {
|
.describe("JSON matching the original MCP input_schema"), // Simplify for prototype
|
||||||
const result = await client.callTool({
|
// @ts-expect-error - AI strict mode overload bug with implicit zod inferences
|
||||||
name: extTool.name,
|
execute: async (args: any) => {
|
||||||
arguments: args
|
const result = await client.callTool({
|
||||||
})
|
name: extTool.name,
|
||||||
return result
|
arguments: args,
|
||||||
}
|
});
|
||||||
})
|
return result;
|
||||||
}
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return { tools: aiSdkTools, client }
|
return { tools: aiSdkTools, client };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +1,39 @@
|
|||||||
import { tool } from 'ai'
|
import { tool } from "ai";
|
||||||
import { z } from 'zod'
|
import { z } from "zod";
|
||||||
import { QdrantClient } from '@qdrant/js-client-rest'
|
import { QdrantClient } from "@qdrant/js-client-rest";
|
||||||
|
|
||||||
// Qdrant initialization
|
// Qdrant initialization
|
||||||
// This requires the user to have Qdrant running and QDRANT_URL/QDRANT_API_KEY environment variables set
|
// This requires the user to have Qdrant running and QDRANT_URL/QDRANT_API_KEY environment variables set
|
||||||
const qdrantClient = new QdrantClient({
|
const qdrantClient = new QdrantClient({
|
||||||
url: process.env.QDRANT_URL || 'http://localhost:6333',
|
url: process.env.QDRANT_URL || "http://localhost:6333",
|
||||||
apiKey: process.env.QDRANT_API_KEY,
|
apiKey: process.env.QDRANT_API_KEY,
|
||||||
})
|
});
|
||||||
|
|
||||||
const MEMORY_COLLECTION = 'mintel_ai_memory'
|
const MEMORY_COLLECTION = "mintel_ai_memory";
|
||||||
|
|
||||||
// Ensure collection exists on load
|
// Ensure collection exists on load
|
||||||
async function initQdrant() {
|
async function initQdrant() {
|
||||||
try {
|
try {
|
||||||
const res = await qdrantClient.getCollections()
|
const res = await qdrantClient.getCollections();
|
||||||
const exists = res.collections.find((c: any) => c.name === MEMORY_COLLECTION)
|
const exists = res.collections.find(
|
||||||
if (!exists) {
|
(c: any) => c.name === MEMORY_COLLECTION,
|
||||||
await qdrantClient.createCollection(MEMORY_COLLECTION, {
|
);
|
||||||
vectors: {
|
if (!exists) {
|
||||||
size: 1536, // typical embedding size, adjust based on the embedding model used
|
await qdrantClient.createCollection(MEMORY_COLLECTION, {
|
||||||
distance: 'Cosine',
|
vectors: {
|
||||||
},
|
size: 1536, // typical embedding size, adjust based on the embedding model used
|
||||||
})
|
distance: "Cosine",
|
||||||
console.log(`Qdrant collection '${MEMORY_COLLECTION}' created.`)
|
},
|
||||||
}
|
});
|
||||||
} catch (error) {
|
console.log(`Qdrant collection '${MEMORY_COLLECTION}' created.`);
|
||||||
console.error('Failed to initialize Qdrant memory collection:', error)
|
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to initialize Qdrant memory collection:", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call init, but don't block
|
// Call init, but don't block
|
||||||
initQdrant()
|
initQdrant();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns memory tools for the AI SDK.
|
* Returns memory tools for the AI SDK.
|
||||||
@@ -40,76 +42,99 @@ initQdrant()
|
|||||||
* by a utility function, or we use Qdrant's FastEmbed (if running their specialized container).
|
* by a utility function, or we use Qdrant's FastEmbed (if running their specialized container).
|
||||||
*/
|
*/
|
||||||
export const generateMemoryTools = (userId: string | number) => {
|
export const generateMemoryTools = (userId: string | number) => {
|
||||||
return {
|
return {
|
||||||
save_memory: tool({
|
save_memory: tool({
|
||||||
description: 'Save an important preference, fact, or instruction about the user to long-term memory. Only use this when explicitly asked or when it is clearly a long-term preference.',
|
description:
|
||||||
parameters: z.object({
|
"Save an important preference, fact, or instruction about the user to long-term memory. Only use this when explicitly asked or when it is clearly a long-term preference.",
|
||||||
fact: z.string().describe('The fact or instruction to remember.'),
|
parameters: z.object({
|
||||||
category: z.string().optional().describe('An optional category like "preference", "rule", or "project_detail".'),
|
fact: z.string().describe("The fact or instruction to remember."),
|
||||||
}),
|
category: z
|
||||||
// @ts-ignore - AI SDK strict mode bug
|
.string()
|
||||||
execute: async ({ fact, category }: { fact: string; category?: string }) => {
|
.optional()
|
||||||
// In a real scenario, you MUST generate embeddings for the 'fact' string here
|
.describe(
|
||||||
// using OpenAI or another embedding provider before inserting into Qdrant.
|
'An optional category like "preference", "rule", or "project_detail".',
|
||||||
// const embedding = await generateEmbedding(fact)
|
),
|
||||||
|
}),
|
||||||
|
// @ts-expect-error - AI SDK strict mode bug
|
||||||
|
execute: async ({
|
||||||
|
fact,
|
||||||
|
category,
|
||||||
|
}: {
|
||||||
|
fact: string;
|
||||||
|
category?: string;
|
||||||
|
}) => {
|
||||||
|
// In a real scenario, you MUST generate embeddings for the 'fact' string here
|
||||||
|
// using OpenAI or another embedding provider before inserting into Qdrant.
|
||||||
|
// const embedding = await generateEmbedding(fact)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Mock embedding payload for demonstration
|
// Mock embedding payload for demonstration
|
||||||
const mockEmbedding = new Array(1536).fill(0).map(() => Math.random())
|
const mockEmbedding = new Array(1536)
|
||||||
|
.fill(0)
|
||||||
|
.map(() => Math.random());
|
||||||
|
|
||||||
await qdrantClient.upsert(MEMORY_COLLECTION, {
|
await qdrantClient.upsert(MEMORY_COLLECTION, {
|
||||||
wait: true,
|
wait: true,
|
||||||
points: [
|
points: [
|
||||||
{
|
{
|
||||||
id: crypto.randomUUID(),
|
id: crypto.randomUUID(),
|
||||||
vector: mockEmbedding,
|
vector: mockEmbedding,
|
||||||
payload: {
|
payload: {
|
||||||
userId: String(userId), // Partition memory by user
|
userId: String(userId), // Partition memory by user
|
||||||
fact,
|
fact,
|
||||||
category,
|
category,
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
});
|
||||||
return { success: true, message: `Successfully remembered: "${fact}"` }
|
return {
|
||||||
} catch (error) {
|
success: true,
|
||||||
console.error("Qdrant save error:", error)
|
message: `Successfully remembered: "${fact}"`,
|
||||||
return { success: false, error: 'Failed to save to memory database.' }
|
};
|
||||||
}
|
} catch (error) {
|
||||||
|
console.error("Qdrant save error:", error);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: "Failed to save to memory database.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
|
||||||
|
search_memory: tool({
|
||||||
|
description:
|
||||||
|
"Search the user's long-term memory for past factual context, preferences, or rules.",
|
||||||
|
parameters: z.object({
|
||||||
|
query: z.string().describe("The search string to find in memory."),
|
||||||
|
}),
|
||||||
|
// @ts-expect-error - AI SDK strict mode bug
|
||||||
|
execute: async ({ query }: { query: string }) => {
|
||||||
|
// Generate embedding for query
|
||||||
|
const mockQueryEmbedding = new Array(1536)
|
||||||
|
.fill(0)
|
||||||
|
.map(() => Math.random());
|
||||||
|
|
||||||
|
try {
|
||||||
|
const results = await qdrantClient.search(MEMORY_COLLECTION, {
|
||||||
|
vector: mockQueryEmbedding,
|
||||||
|
limit: 5,
|
||||||
|
filter: {
|
||||||
|
must: [
|
||||||
|
{
|
||||||
|
key: "userId",
|
||||||
|
match: { value: String(userId) },
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
}),
|
});
|
||||||
|
|
||||||
search_memory: tool({
|
return results.map((r: any) => r.payload?.fact || "");
|
||||||
description: 'Search the user\'s long-term memory for past factual context, preferences, or rules.',
|
} catch (error) {
|
||||||
parameters: z.object({
|
console.error("Qdrant search error:", error);
|
||||||
query: z.string().describe('The search string to find in memory.'),
|
return [];
|
||||||
}),
|
}
|
||||||
// @ts-ignore - AI SDK strict mode bug
|
},
|
||||||
execute: async ({ query }: { query: string }) => {
|
}),
|
||||||
// Generate embedding for query
|
};
|
||||||
const mockQueryEmbedding = new Array(1536).fill(0).map(() => Math.random())
|
};
|
||||||
|
|
||||||
try {
|
|
||||||
const results = await qdrantClient.search(MEMORY_COLLECTION, {
|
|
||||||
vector: mockQueryEmbedding,
|
|
||||||
limit: 5,
|
|
||||||
filter: {
|
|
||||||
must: [
|
|
||||||
{
|
|
||||||
key: 'userId',
|
|
||||||
match: { value: String(userId) }
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return results.map((r: any) => r.payload?.fact || '')
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Qdrant search error:", error)
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,107 +1,137 @@
|
|||||||
import { tool } from 'ai'
|
import { tool } from "ai";
|
||||||
import { z } from 'zod'
|
import { z } from "zod";
|
||||||
import type { Payload, PayloadRequest, User } from 'payload'
|
import type { Payload, PayloadRequest, User } from "payload";
|
||||||
|
|
||||||
export const generatePayloadLocalTools = (
|
export const generatePayloadLocalTools = (
|
||||||
payload: Payload,
|
payload: Payload,
|
||||||
req: PayloadRequest,
|
req: PayloadRequest,
|
||||||
allowedCollections: string[]
|
allowedCollections: string[],
|
||||||
) => {
|
) => {
|
||||||
const tools: Record<string, any> = {}
|
const tools: Record<string, any> = {};
|
||||||
|
|
||||||
for (const collectionSlug of allowedCollections) {
|
for (const collectionSlug of allowedCollections) {
|
||||||
const slugKey = collectionSlug.replace(/-/g, '_')
|
const slugKey = collectionSlug.replace(/-/g, "_");
|
||||||
|
|
||||||
// 1. Read (Find) Tool
|
// 1. Read (Find) Tool
|
||||||
tools[`read_${slugKey}`] = tool({
|
tools[`read_${slugKey}`] = tool({
|
||||||
description: `Read/Find documents from the Payload CMS collection: ${collectionSlug}`,
|
description: `Read/Find documents from the Payload CMS collection: ${collectionSlug}`,
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
limit: z.number().optional().describe('Number of documents to return, max 100.'),
|
limit: z
|
||||||
page: z.number().optional().describe('Page number for pagination.'),
|
.number()
|
||||||
// Simple string-based query for demo purposes. For a robust implementation,
|
.optional()
|
||||||
// we'd map this to Payload's where query logic using a structured Zod schema.
|
.describe("Number of documents to return, max 100."),
|
||||||
query: z.string().optional().describe('Optional text to search within the collection.'),
|
page: z.number().optional().describe("Page number for pagination."),
|
||||||
}),
|
// Simple string-based query for demo purposes. For a robust implementation,
|
||||||
// @ts-ignore - AI SDK strict mode type inference bug
|
// we'd map this to Payload's where query logic using a structured Zod schema.
|
||||||
execute: async ({ limit = 10, page = 1, query }: { limit?: number; page?: number; query?: string }) => {
|
query: z
|
||||||
const where = query ? { id: { equals: query } } : undefined // Placeholder logic
|
.string()
|
||||||
|
.optional()
|
||||||
|
.describe("Optional text to search within the collection."),
|
||||||
|
}),
|
||||||
|
// @ts-expect-error - AI SDK strict mode type inference bug
|
||||||
|
execute: async ({
|
||||||
|
limit = 10,
|
||||||
|
page = 1,
|
||||||
|
query,
|
||||||
|
}: {
|
||||||
|
limit?: number;
|
||||||
|
page?: number;
|
||||||
|
query?: string;
|
||||||
|
}) => {
|
||||||
|
const where = query ? { id: { equals: query } } : undefined; // Placeholder logic
|
||||||
|
|
||||||
return await payload.find({
|
return await payload.find({
|
||||||
collection: collectionSlug as any,
|
collection: collectionSlug as any,
|
||||||
limit: Math.min(limit, 100),
|
limit: Math.min(limit, 100),
|
||||||
page,
|
page,
|
||||||
where,
|
where,
|
||||||
req, // Crucial for passing the user context and respecting access control!
|
req, // Crucial for passing the user context and respecting access control!
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
// 2. Read by ID Tool
|
// 2. Read by ID Tool
|
||||||
tools[`read_${slugKey}_by_id`] = tool({
|
tools[`read_${slugKey}_by_id`] = tool({
|
||||||
description: `Get a specific document by its ID from the ${collectionSlug} collection.`,
|
description: `Get a specific document by its ID from the ${collectionSlug} collection.`,
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
id: z.union([z.string(), z.number()]).describe('The ID of the document.'),
|
id: z
|
||||||
}),
|
.union([z.string(), z.number()])
|
||||||
// @ts-ignore - AI SDK strict mode type inference bug
|
.describe("The ID of the document."),
|
||||||
execute: async ({ id }: { id: string | number }) => {
|
}),
|
||||||
return await payload.findByID({
|
// @ts-expect-error - AI SDK strict mode type inference bug
|
||||||
collection: collectionSlug as any,
|
execute: async ({ id }: { id: string | number }) => {
|
||||||
id,
|
return await payload.findByID({
|
||||||
req, // Enforce access control
|
collection: collectionSlug as any,
|
||||||
})
|
id,
|
||||||
},
|
req, // Enforce access control
|
||||||
})
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// 3. Create Tool
|
// 3. Create Tool
|
||||||
tools[`create_${slugKey}`] = tool({
|
tools[`create_${slugKey}`] = tool({
|
||||||
description: `Create a new document in the ${collectionSlug} collection.`,
|
description: `Create a new document in the ${collectionSlug} collection.`,
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
data: z.record(z.any()).describe('A JSON object containing the data to insert.'),
|
data: z
|
||||||
}),
|
.record(z.any())
|
||||||
// @ts-ignore - AI SDK strict mode type inference bug
|
.describe("A JSON object containing the data to insert."),
|
||||||
execute: async ({ data }: { data: Record<string, any> }) => {
|
}),
|
||||||
return await payload.create({
|
// @ts-expect-error - AI SDK strict mode type inference bug
|
||||||
collection: collectionSlug as any,
|
execute: async ({ data }: { data: Record<string, any> }) => {
|
||||||
data,
|
return await payload.create({
|
||||||
req, // Enforce access control
|
collection: collectionSlug as any,
|
||||||
})
|
data,
|
||||||
},
|
req, // Enforce access control
|
||||||
})
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// 4. Update Tool
|
// 4. Update Tool
|
||||||
tools[`update_${slugKey}`] = tool({
|
tools[`update_${slugKey}`] = tool({
|
||||||
description: `Update an existing document in the ${collectionSlug} collection.`,
|
description: `Update an existing document in the ${collectionSlug} collection.`,
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
id: z.union([z.string(), z.number()]).describe('The ID of the document to update.'),
|
id: z
|
||||||
data: z.record(z.any()).describe('A JSON object containing the fields to update.'),
|
.union([z.string(), z.number()])
|
||||||
}),
|
.describe("The ID of the document to update."),
|
||||||
// @ts-ignore - AI SDK strict mode type inference bug
|
data: z
|
||||||
execute: async ({ id, data }: { id: string | number; data: Record<string, any> }) => {
|
.record(z.any())
|
||||||
return await payload.update({
|
.describe("A JSON object containing the fields to update."),
|
||||||
collection: collectionSlug as any,
|
}),
|
||||||
id,
|
// @ts-expect-error - AI SDK strict mode type inference bug
|
||||||
data,
|
execute: async ({
|
||||||
req, // Enforce access control
|
id,
|
||||||
})
|
data,
|
||||||
},
|
}: {
|
||||||
})
|
id: string | number;
|
||||||
|
data: Record<string, any>;
|
||||||
|
}) => {
|
||||||
|
return await payload.update({
|
||||||
|
collection: collectionSlug as any,
|
||||||
|
id,
|
||||||
|
data,
|
||||||
|
req, // Enforce access control
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// 5. Delete Tool
|
// 5. Delete Tool
|
||||||
tools[`delete_${slugKey}`] = tool({
|
tools[`delete_${slugKey}`] = tool({
|
||||||
description: `Delete a document from the ${collectionSlug} collection by ID.`,
|
description: `Delete a document from the ${collectionSlug} collection by ID.`,
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
id: z.union([z.string(), z.number()]).describe('The ID of the document to delete.'),
|
id: z
|
||||||
}),
|
.union([z.string(), z.number()])
|
||||||
// @ts-ignore - AI SDK strict mode type inference bug
|
.describe("The ID of the document to delete."),
|
||||||
execute: async ({ id }: { id: string | number }) => {
|
}),
|
||||||
return await payload.delete({
|
// @ts-expect-error - AI SDK strict mode type inference bug
|
||||||
collection: collectionSlug as any,
|
execute: async ({ id }: { id: string | number }) => {
|
||||||
id,
|
return await payload.delete({
|
||||||
req, // Enforce access control
|
collection: collectionSlug as any,
|
||||||
})
|
id,
|
||||||
},
|
req, // Enforce access control
|
||||||
})
|
});
|
||||||
}
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return tools
|
return tools;
|
||||||
}
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user