Files
openclaw/src/plugin-state/plugin-state-lease.types.ts
Peter Steinberger e873a7f955 refactor(memory): move QMD coordination to SQLite (#109636)
* refactor(memory): move QMD coordination to SQLite

* chore: keep release notes in PR body

* chore: annotate lease SQLite primitive
2026-07-16 22:01:34 -07:00

41 lines
1.3 KiB
TypeScript

// Public plugin lease contracts. Lease ownership stays host-managed; plugins
// receive cancellation plus an exact-owner checkpoint for the critical section.
export type PluginStateLeaseDatabase = { scope: "shared" } | { scope: "agent"; agentId: string };
export type PluginStateLeaseOptions = {
namespace: string;
key: string;
database: PluginStateLeaseDatabase;
leaseMs: number;
waitMs: number;
signal?: AbortSignal;
};
export type PluginStateLeaseContext = {
signal: AbortSignal;
/** Verify that this exact owner holds a non-expired lease at this instant. */
assertOwned(): void;
};
export type PluginStateLeaseRunner = <T>(
options: PluginStateLeaseOptions,
run: (lease: PluginStateLeaseContext) => Promise<T>,
) => Promise<T>;
export type PluginStateLeaseErrorCode =
| "PLUGIN_STATE_LEASE_INVALID_INPUT"
| "PLUGIN_STATE_LEASE_TIMEOUT"
| "PLUGIN_STATE_LEASE_ABORTED"
| "PLUGIN_STATE_LEASE_LOST"
| "PLUGIN_STATE_LEASE_STORAGE_FAILED";
export class PluginStateLeaseError extends Error {
readonly code: PluginStateLeaseErrorCode;
constructor(message: string, options: { code: PluginStateLeaseErrorCode; cause?: unknown }) {
super(message, { cause: options.cause });
this.name = "PluginStateLeaseError";
this.code = options.code;
}
}