Skip to content

Commit b29e349

Browse files
Zie619claude
andcommitted
fix(n8n): handle array model return from getInputConnectionData
n8n may return array of connected models. Take last element like the native agent's getChatModel does (reverse indexing). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 747f32d commit b29e349

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

n8n-node/nodes/TruseraAgent/TruseraAgent.node.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,21 @@ export class TruseraAgent implements INodeType {
166166

167167
const reporter = new SidecarReporter(platformUrl, credentials.apiKey, agentName);
168168

169-
// Get connected LLM — it's already a ChatModel instance from the sub-node
170-
const model = (await this.getInputConnectionData(
171-
NodeConnectionTypes.AiLanguageModel,
172-
0,
173-
)) as any;
169+
// Get connected LLM
170+
let connectedModel: any;
171+
try {
172+
connectedModel = await this.getInputConnectionData(
173+
NodeConnectionTypes.AiLanguageModel,
174+
0,
175+
);
176+
} catch (err: any) {
177+
throw new NodeOperationError(this.getNode(), `Failed to get Chat Model: ${err.message}`);
178+
}
179+
180+
// Handle array (n8n may return array of connected models)
181+
const model = Array.isArray(connectedModel)
182+
? connectedModel[connectedModel.length - 1]
183+
: connectedModel;
174184

175185
if (!model) {
176186
throw new NodeOperationError(this.getNode(), 'No Chat Model connected');

0 commit comments

Comments
 (0)