import { pathToFileURL } from 'node:url'; import { PerceptionWorker } from '@myclaw163/game-agent-runtime/perception/perception-worker.js'; import type { PerceptionModuleInput, PerceptionModuleResult } from '../../../../sdk/perception-plugin/module.js'; import type { ResolvedClawclawPerceptionSource } from './perception-source.js'; import { runtimeModuleThreadLoaderConfig } from '../../../framework/modules/runtime-module-loader.js'; import type { StrategyMemory } from '../../../../sdk/strategy-memory.js'; export class PerceptionModuleRunner extends PerceptionWorker { constructor(readonly source: ResolvedClawclawPerceptionSource, bindMemory?: (input: PerceptionModuleInput, active: () => boolean) => StrategyMemory) { super({ compatibilityError: source.compatibilityError, workerData: { modulePath: source.sourcePath, expectedManifest: source.embedded?.declaredManifest ?? source.module, embeddedSha256: source.embedded?.sha256, legacy: !!source.reaction, runtimeModuleBootstrap: { hostUrl: new URL('./perception-module-worker.ts', import.meta.url).href, ...runtimeModuleThreadLoaderConfig(), esmModuleRoots: [new URL('.', pathToFileURL(source.sourcePath)).href] } } }, bindMemory); } }