fix(plugin): real per-agent slot handle for multi-agent calendar tools
In multi-agent sync mode every harborforge_calendar_* tool was returning
`calendarScheduler.<method> is not a function`. The cause: index.ts replaced
`calendarScheduler` (typed `CalendarScheduler | null`) with a `{ stop() }`
stub right after wiring the runSync/runCheck intervals, so `isRunning()`,
`getCurrentSlot()`, `completeCurrentSlot()`, `abortCurrentSlot()`,
`pauseCurrentSlot()`, `resumeCurrentSlot()`, `getState()`,
`isRestartPending()` and `getStateFilePath()` all blew up at call time.
Replaces the stub with a `MultiAgentSchedulerHandle` that:
- tracks the last slot dispatched per agent (recorded by `wakeAgent`)
- exposes status/complete/abort/pause/resume taking the calling agentId
- resolves the implicit "current slot" via woken-cursor first then a
cache scan over not_started/deferred/ongoing slots
- PATCHes via `bridge.updateSlotAs(agentId, …)` so audit headers reflect
the real caller (bridge constructor agentId is 'unused' in multi-agent)
- mirrors the legacy `isRunning/isProcessing/getState/...` surface so
the single-agent fallback (`CalendarScheduler`) keeps working unchanged
Each calendar tool factory now takes `OpenClawPluginToolContext`, reads
`ctx.agentId`, and dispatches through the handle. Single-agent path
(when `calendarScheduler` is a real `CalendarScheduler`) is preserved
behind `instanceof` checks.
Drops the dead `trackSessionCompletion` poll loop (only definition, no
caller) which referenced the removed `completeCurrentSlot`. Bumps
plugin version 0.2.0 → 0.3.2.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -110,6 +110,23 @@ export class CalendarBridgeClient {
|
||||
return this.sendBoolean('PATCH', url, update);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link updateSlot} but overrides the `X-Agent-ID` header for a
|
||||
* single call. Used by the multi-agent scheduler handle where the bridge
|
||||
* client is shared across agents and the constructor agentId is `'unused'`.
|
||||
*
|
||||
* Backend identifies the slot purely by `slotId`; the header is informational
|
||||
* for audit. Passing the calling agent's id keeps audit/log lines correct.
|
||||
*/
|
||||
async updateSlotAs(
|
||||
agentId: string,
|
||||
slotId: number,
|
||||
update: SlotAgentUpdate
|
||||
): Promise<boolean> {
|
||||
const url = `${this.baseUrl}/calendar/slots/${slotId}/agent-update`;
|
||||
return this.sendBooleanAs(agentId, 'PATCH', url, update);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a virtual (plan-generated) slot's status after agent execution.
|
||||
*
|
||||
@@ -264,6 +281,15 @@ export class CalendarBridgeClient {
|
||||
}
|
||||
|
||||
private async sendBoolean(method: 'POST' | 'PATCH', url: string, body: unknown): Promise<boolean> {
|
||||
return this.sendBooleanAs(this.config.agentId, method, url, body);
|
||||
}
|
||||
|
||||
private async sendBooleanAs(
|
||||
agentId: string,
|
||||
method: 'POST' | 'PATCH',
|
||||
url: string,
|
||||
body: unknown
|
||||
): Promise<boolean> {
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
||||
|
||||
@@ -272,7 +298,7 @@ export class CalendarBridgeClient {
|
||||
method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Agent-ID': this.config.agentId,
|
||||
'X-Agent-ID': agentId,
|
||||
'X-Claw-Identifier': this.config.clawIdentifier,
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
|
||||
Reference in New Issue
Block a user