fix: use dynamic import helper for ESM-only claude-agent-sdk
tsc with module=commonjs converts `await import()` to require(),
which breaks ESM-only packages. Use Function('return import()')
workaround to preserve native dynamic import at runtime.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b963b7d4da
commit
14e8d7019a
|
|
@ -26,6 +26,10 @@ import { AllowedToolsResolverService } from '../../../domain/services/allowed-to
|
|||
import { TenantContextService } from '@it0/common';
|
||||
import { ApprovalGate } from './approval-gate';
|
||||
|
||||
// Dynamic import helper that survives tsc commonjs compilation
|
||||
// (tsc converts `await import()` → require() which breaks ESM-only packages)
|
||||
const dynamicImport = new Function('specifier', 'return import(specifier)') as (specifier: string) => Promise<any>;
|
||||
|
||||
/** Tracks an active SDK session for cancellation and approval resolution. */
|
||||
interface ActiveSession {
|
||||
abort: AbortController;
|
||||
|
|
@ -92,7 +96,7 @@ export class ClaudeAgentSdkEngine implements AgentEnginePort {
|
|||
};
|
||||
|
||||
try {
|
||||
const { query } = await import('@anthropic-ai/claude-agent-sdk');
|
||||
const { query } = await dynamicImport('@anthropic-ai/claude-agent-sdk');
|
||||
|
||||
const sdkQuery = query({
|
||||
prompt: params.prompt,
|
||||
|
|
@ -259,7 +263,7 @@ export class ClaudeAgentSdkEngine implements AgentEnginePort {
|
|||
this.activeSessions.set(sessionId, { abort: abortController, gate, sdkSessionId });
|
||||
|
||||
try {
|
||||
const { query } = await import('@anthropic-ai/claude-agent-sdk');
|
||||
const { query } = await dynamicImport('@anthropic-ai/claude-agent-sdk');
|
||||
|
||||
const sdkQuery = query({
|
||||
prompt: message,
|
||||
|
|
@ -303,7 +307,7 @@ export class ClaudeAgentSdkEngine implements AgentEnginePort {
|
|||
|
||||
async healthCheck(): Promise<boolean> {
|
||||
try {
|
||||
await import('@anthropic-ai/claude-agent-sdk');
|
||||
await dynamicImport('@anthropic-ai/claude-agent-sdk');
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue