feat(Truefoundry Chat Model Node): Add Truefoundry AI Gateway integration#21739
feat(Truefoundry Chat Model Node): Add Truefoundry AI Gateway integration#21739venkat1924 wants to merge 5 commits inton8n-io:masterfrom
Conversation
|
Hey @venkat1924, Thank you for your contribution. We appreciate the time and effort you’ve taken to submit this pull request. Before we can proceed, please ensure the following: Regarding new nodes: If your node integrates with an AI service that you own or represent, please email nodes@n8n.io and we will be happy to discuss the best approach. About review timelines: Thank you again for contributing to n8n. |
There was a problem hiding this comment.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
4 issues found across 6 files
Prompt for AI agents (all 4 issues)
Understand the root cause of the following 4 issues and fix them.
<file name="packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.ts">
<violation number="1" location="packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.ts:18">
Rule violated: **Tests**
This new Truefoundry chat model node adds production functionality without any accompanying tests, violating the Community PR Guidelines that require unit/workflow tests for node changes. Please add the appropriate tests covering the node's core behavior before merging.</violation>
<violation number="2" location="packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.ts:239">
Rule violated: **Prefer Typeguards over Type casting**
`credentials.url` and `credentials.apiKey` are being narrowed with `as string`, which violates the Prefer Typeguards over Type casting rule and bypasses TypeScript safety. Please validate these credential fields (or tighten their typings) before using them so the compiler enforces the invariant instead of relying on assertions.</violation>
<violation number="3" location="packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.ts:251">
`evaluateExpression` already returns the resolved JSON string (e.g. `{"x-n8n-user":"..."}`) without a leading `=`, so this guard is always false and the X-TFY-METADATA header is never sent.</violation>
</file>
<file name="packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/methods/loadModels.ts">
<violation number="1" location="packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/methods/loadModels.ts:11">
Rule violated: **Prefer Typeguards over Type casting**
Casting the credential fields to `string` with `as` sidesteps the required type guard/annotation and can hide missing or malformed credential values. Please narrow these values with runtime checks (or adjust typings) before using them instead of relying on assertions.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Ask questions if you need clarification on any suggestion
Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR
packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.ts
Outdated
Show resolved
Hide resolved
packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.ts
Show resolved
Hide resolved
packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/methods/loadModels.ts
Show resolved
Hide resolved
packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.ts
Show resolved
Hide resolved
d1ba935 to
0afd828
Compare
packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.ts
Outdated
Show resolved
Hide resolved
packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.ts
Show resolved
Hide resolved
d21574a to
d4ebd6f
Compare
packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.ts
Outdated
Show resolved
Hide resolved
…tion Add new Truefoundry Chat Model node for n8n's LangChain integration: - Add TruefoundryApi credentials with custom header support - Implement LmChatTruefoundry node with OpenAI-compatible API - Add dynamic model loading via Truefoundry AI Gateway - Support all standard chat model options (temperature, maxTokens, etc.) - Include response format options (text/JSON) with appropriate warnings - Include SVG icons for light and dark themes The node uses ChatOpenAI from @langchain/openai to communicate with Truefoundry's AI Gateway, which provides a unified interface to multiple LLM providers.
…odel node - Add 18 unit tests for LmChatTruefoundry node covering: - Node description and configuration - Credentials handling (API key, URL, custom headers) - X-TFY-METADATA header with user email evaluation - All available options (frequency penalty, max tokens, temperature, etc.) - Response format and reasoning effort options - N8nLlmTracing callback and failed attempt handler - Edge cases and default values - Add 13 unit tests for searchModels method covering: - OpenAI client initialization - Model listing and filtering - Custom headers support - Case-insensitive search - Alphabetical sorting - Edge cases - Fix evaluateExpression call in node (remove `=` prefix) All 31 tests pass. Tests follow n8n conventions and match patterns from other langchain nodes (OpenAI, Anthropic).
d4ebd6f to
864806e
Compare
Summary
Add new Truefoundry Chat Model node for n8n's LangChain integration:
The node uses ChatOpenAI from @langchain/openai to communicate with Truefoundry's AI Gateway, which provides a unified interface to multiple LLM providers.
https://www.loom.com/share/3952360f80cb4031ad82c9493ba14306
Related Linear tickets, Github issues, and Community forum posts
Review / Merge checklist
release/backport(if the PR is an urgent fix that needs to be backported)Note
Introduces a Truefoundry Chat Model node with dynamic model listing, custom headers/metadata, and full chat options, plus new Truefoundry credentials and tests/assets.
nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.tsusingChatOpenAIagainst Truefoundry AI Gateway.modellist/ID, penalties (frequencyPenalty,presencePenalty),temperature,topP,maxTokens,timeout,maxRetries,responseFormat(text/JSON), andreasoningEffort.configuration.defaultHeaders, includingX-TFY-METADATA(user email) and optional custom credential header; uses proxy agent; tracing and retry handler wired.methods/loadModels.tsto list all models fromopenai.models.list()against TruefoundrybaseURL, with filtering, sorting, proxy, and optional custom headers.credentials/TruefoundryApi.credentials.tswith API key, base URL override, and optional custom header injection; includes/modelstest request.truefoundry.svgandtruefoundry.dark.svg.package.jsonexports.Written by Cursor Bugbot for commit 87756b7. This will update automatically on new commits. Configure here.