ESM conversion:
- plugin/package.json: add "type": "module".
- plugin/tsconfig.json: switch module/moduleResolution to "nodenext"; bump
target to ES2022.
- All relative imports across plugin/ now carry .js extensions as required
by Node ESM (nodenext module resolution).
- plugin/index.ts: replace `require('./calendar/schedule-cache')` with a
proper top-level import; switch `from 'os'` to `from 'node:os'`.
Plugin SDK convention update:
- Wrap default export with definePluginEntry({ id, name, description,
register }) per the current openclaw plugin authoring contract.
- Modernize plugin/openclaw.plugin.json: drop entry/version, add
activation.onStartup so gateway_start fires for this plugin at boot,
declare contracts.tools listing the five harborforge_* tools.
- Add a local plugin/openclaw-sdk.d.ts with ambient declarations for the
focused subpaths (openclaw/plugin-sdk/plugin-entry,
openclaw/plugin-sdk/core). We deliberately do NOT add openclaw as an
npm devDependency: the installer's `npm install --omit=dev` step trips
over openclaw's own (deeply nested) dependency graph when listed via
file:.../openclaw, and the runtime contract is provided by the gateway
loader anyway.
- The local PluginAPI interface is preserved (broader than the standard
OpenClawPluginApi — it surfaces `version`/`runtime`/`spawn`); the
register function is cast at the definePluginEntry boundary.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { hostname } from 'os';
|
|
import { getPluginConfig } from '../core/config.js';
|
|
import { startManagedMonitor } from '../core/managed-monitor.js';
|
|
|
|
export function registerGatewayStartHook(api: any, deps: {
|
|
logger: any;
|
|
pushMetaToMonitor: () => Promise<void>;
|
|
startCalendarScheduler: () => void;
|
|
setMetaPushInterval: (handle: ReturnType<typeof setInterval>) => void;
|
|
}) {
|
|
const { logger, pushMetaToMonitor, startCalendarScheduler, setMetaPushInterval } = deps;
|
|
|
|
api.on('gateway_start', () => {
|
|
logger.info('HarborForge plugin active');
|
|
const live = getPluginConfig(api);
|
|
|
|
startManagedMonitor(logger, {
|
|
managedMonitor: live.managedMonitor,
|
|
backendUrl: live.backendUrl,
|
|
identifier: live.identifier,
|
|
apiKey: live.apiKey,
|
|
monitor_port: live.monitor_port,
|
|
reportIntervalSec: live.reportIntervalSec,
|
|
logLevel: live.logLevel,
|
|
});
|
|
|
|
const intervalSec = live.reportIntervalSec || 30;
|
|
setTimeout(() => void pushMetaToMonitor(), 2000);
|
|
setMetaPushInterval(setInterval(() => void pushMetaToMonitor(), intervalSec * 1000));
|
|
|
|
if (live.enabled !== false && live.calendarEnabled !== false) {
|
|
setTimeout(() => startCalendarScheduler(), 5000);
|
|
}
|
|
|
|
logger.info(`HarborForge startup config identifier=${live.identifier || hostname()} backend=${live.backendUrl}`);
|
|
});
|
|
}
|