get-convex / get-convex/agent

Improve error when Node-only deps are used in tool handlers (“dynamic module import unsupported” shows from unrelated query)

Open
#112 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
349
Forks
92
Avg merge
3d 10h
Merged PRs (30d)
24

Description

I keep on getting the same error and I have no clue why:

```
Q - ai:listThreadMessages - error

Error getting version:' [TypeError: dynamic module import unsupported]"
```

listThreadMessages function:
```
export const listThreadMessages = query({
args: {
// These arguments are required:
threadId: v.string(),
paginationOpts: paginationOptsValidator, // Used to paginate the messages.
streamArgs: vStreamArgs, // Used to stream messages.
},
handler: async (ctx, args) => {
const { threadId, paginationOpts, streamArgs } = args;
await authorizeThreadAccess(ctx, threadId);

const paginated = await listMessages(ctx, components.agent, {
threadId,
paginationOpts,
});

const streams = await syncStreams(ctx, components.agent, {
threadId,
streamArgs,
includeStatuses: ["aborted", "streaming", "finished"],
});

return {
...paginated,
streams,

// ... you can return other metadata here too.
// note: this function will be called with various permutations of delta
// and message args, so returning derived data .
};
},
});
```

### Problem
Using a Node-only lib (e.g., `@mendable/firecrawl-js`) inside a `createTool` handler throws a generic “dynamic module import unsupported” that surfaces from an unrelated function like `ai.listThreadMessages`, hiding the real cause.

### Repro
1) Import a Node-only lib in a `createTool` handler.
2) Use the agent with `ai.listThreadMessages`.
4) See: “Error getting version: [TypeError: dynamic module import unsupported]”.

### Expected
Error should point to the offending tool (name + file) and say Node-only code must run in an action file with `"use node"` and be invoked via `ctx.runAction(...)`.

### Workaround
Move Node-only usage to an `internalAction` file with `"use node"` and call it from the tool via `ctx.runAction(...)`.

### VERSION
"@convex-dev/agent": "^0.1.17",

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.