ambleloft

Hook events and registration API

Internal alpha.9 / M2 preview: declare completion events, register during activate and handle durable at-least-once delivery.

API REFERENCE

Browse contracts, signatures, fields and examples. Unspecified defaults are not inferred.

On this page

01Events and signature

Preview capability · SDK 0.1.0-alpha.9

Only these two events are supported. background.job.completed signals a terminal outcome, not necessarily success.

Code example
type TurnReference = { conversationId: string; turnId: string; version: number };
type HookEnvelope = { eventId: string; projectId: string; occurredAt: string } & (
  | (TurnReference & { type: 'conversation.turn.completed' })
  | { type: 'background.job.completed'; jobId: string; status: BackgroundJob['status'] }
);
// ExtensionContext
hooks.register(handler: string, callback: (event: HookEnvelope,
  context: { signal: AbortSignal; projectId: string; requestId: string }
) => void | Promise<void>): Disposable;

02Manifest and registration validation

The schema constrains event names and structure. CLI/host validation checks the main entry, project permissions, duplicate events and handler names. Hooks and operations share a unique handler namespace. Registration must match the declared name and happen synchronously during activate.

Field / APIContract
conversation.turn.completedProduced after the complete tool loop and final reply; not a token stream or tool fragment.
background.job.completedUse jobId with jobs.get for authoritative results and handle all terminal states.
DisposableAdd registration disposables to context.subscriptions for cleanup.

03ACK, retries and ordering

Successful handler return is the ACK. Delivery is at least once; eventId can repeat. Handlers have 30 seconds, with up to five host retries after the first failure. A conversation waits for its preceding pending/delivering attempt; dead letters do not block later events. There is no cross-conversation global ordering. Make business effects idempotent. ACK does not prove job or business success. These durable Hooks are separate from ordinary notification listeners.

04Retention and unsupported capabilities

Snapshots and unacknowledged events are retained for seven days, with a 1,000-event capacity per extension. Revocation, disabling and uninstalling clear corresponding events; reauthorization does not backfill history. Live message streams, arbitrary lifecycle events, chat interception and response editing are not exposed.

SDK / CLI 0.1.0-alpha.9 · Contract baseline Compatibility and preview notes · Sample source