@ai-matrx/summon 0.1.16 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -1
- package/dist/handles.cjs +63 -50
- package/dist/handles.cjs.map +1 -1
- package/dist/handles.d.cts +2 -5
- package/dist/handles.d.ts +2 -5
- package/dist/handles.js +63 -50
- package/dist/handles.js.map +1 -1
- package/dist/{helpers-2NY1ha0V.d.cts → ids-83h05Ed-.d.cts} +4 -1
- package/dist/{helpers-2NY1ha0V.d.ts → ids-83h05Ed-.d.ts} +4 -1
- package/dist/index.cjs +63 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +63 -50
- package/dist/index.js.map +1 -1
- package/dist/open.cjs +86 -2
- package/dist/open.cjs.map +1 -1
- package/dist/open.d.cts +22 -2
- package/dist/open.d.ts +22 -2
- package/dist/open.js +86 -2
- package/dist/open.js.map +1 -1
- package/package.json +4 -4
package/dist/handles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handles/callbackManager.ts","../src/handles/ids.ts","../src/handles/slot.ts","../src/handles/helpers.ts"],"sourcesContent":["/**\n * The handles registry — everything that cannot travel through Redux (callbacks, event channels,\n * one-shot requests, imperative object handles) lives here under a string id; only the id goes\n * into overlay open data.\n *\n * Successor of `@ai-matrx/chat` `utils/callbackManager.ts` with the SAME public verbs and types, so\n * moving a caller is an import-path swap. Changes (CHANGELOG 0.1.0):\n * 1. State lives in the global slot \"ai-matrx.summon.handles\", never in module scope: a\n * duplicated module graph (ESM + CJS, unsplit bundles, two packages) sees one registry.\n * 2. Removal bug fixed: `trigger` / `triggerWithContext` / `remove` deleted the entry BEFORE\n * `removeFromGroups` read it, so group membership never shrank and emptied groups were never\n * dropped. Removal now reads the entry first, in one place (`deleteEntry`).\n * 3. Owner scoping: `registerWithContext(cb, { owner })` (an InstanceKey `overlayId:instanceId`)\n * ties the entry to an open overlay instance; `disposeOwner(owner)` removes everything it\n * owns. The overlays close middleware calls it, so no opener disposes by hand.\n * 4. The object slot is handle-agnostic: `registerWidgetHandle<H extends object>(handle)` stores\n * any object (no chat `WidgetHandle` import).\n * 5. Ids come from `crypto.randomUUID` (no `uuid` dependency), with a fallback for insecure\n * contexts where `randomUUID` is absent.\n *\n * Framework-free: no React, no Redux.\n */\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\nimport { newHandleId } from \"./ids\";\nimport { HANDLES_SLOT } from \"./slot\";\n\nexport type CallbackContext = Record<string, unknown>;\n\nexport interface ProgressInfo {\n progress?: number;\n status?: \"pending\" | \"running\" | \"completed\" | \"error\";\n error?: Error;\n}\n\nexport type Callback<T = unknown, C extends CallbackContext = CallbackContext> = (\n data: T,\n context?: C,\n) => void | Promise<void>;\n\n/** What an entry's slot holds: a callback, or an object handle retrieved with `get`. */\nexport type HandleSlot = Callback<never, never> | object;\n\nexport interface RegisterOptions<C extends CallbackContext = CallbackContext> {\n context?: C;\n groupId?: string;\n /** The InstanceKey (`overlayId:instanceId`) that owns this entry; disposed when it closes. */\n owner?: string;\n}\n\nexport interface TriggerOptions<C extends CallbackContext = CallbackContext> {\n context?: C;\n progress?: ProgressInfo;\n removeAfterTrigger?: boolean;\n}\n\n/** A registry entry. `callback` is the heterogeneous slot (function or object handle). */\ninterface CallbackEntry {\n callback: HandleSlot;\n context?: CallbackContext;\n groupId?: string;\n owner?: string;\n listeners?: Array<Callback<never, never>>;\n /** Runs once when the entry leaves the registry for any reason (requests reject here). */\n onRemove?: () => void;\n}\n\ninterface HandlesState {\n readonly callbacks: Map<string, CallbackEntry>;\n readonly groups: Map<string, Set<string>>;\n readonly owners: Map<string, Set<string>>;\n readonly registryListeners: Set<() => void>;\n}\n\nexport { HANDLES_SLOT };\n\nconst handlesState = (): HandlesState =>\n globalSlot<HandlesState>(HANDLES_SLOT, () => ({\n callbacks: new Map(),\n groups: new Map(),\n owners: new Map(),\n registryListeners: new Set(),\n }));\n\n/** Invoke a slot as a callback (a function slot only; object handles are never invoked). */\nfunction invoke(slot: HandleSlot, data: unknown, context?: CallbackContext): void | Promise<void> {\n if (typeof slot !== \"function\") return undefined;\n return (slot as Callback<unknown, CallbackContext>)(data, context);\n}\n\nfunction invokeListener(listener: Callback<never, never>, data: unknown, context?: CallbackContext): void | Promise<void> {\n return (listener as Callback<unknown, CallbackContext>)(data, context);\n}\n\n/** Internal registration options beyond the public ones (used by the typed helpers). */\nexport interface InternalRegisterOptions extends RegisterOptions {\n id?: string;\n onRemove?: () => void;\n}\n\nexport class CallbackManager {\n private get s(): HandlesState {\n return handlesState();\n }\n\n /**\n * Observe the registry itself: `listener` runs after any entry is added or removed. This lets a\n * view that resolves ids with `get` re-render when an id goes away (`useSyncExternalStore`).\n */\n subscribeToRegistry(listener: () => void): () => void {\n const listeners = this.s.registryListeners;\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n }\n\n private notifyRegistry(): void {\n for (const listener of [...this.s.registryListeners]) listener();\n }\n\n /** Register a callback; returns its id. */\n register<T>(callback: Callback<T>): string {\n return this.registerEntry(callback as HandleSlot, {});\n }\n\n /** Register with optional context, group and owner. */\n registerWithContext<T, C extends CallbackContext = CallbackContext>(\n callback: Callback<T, C>,\n options: RegisterOptions<C> = {},\n ): string {\n return this.registerEntry(callback as HandleSlot, options);\n }\n\n /** @internal The one insertion path (typed helpers pass a fixed id and a removal hook). */\n registerEntry(slot: HandleSlot, options: InternalRegisterOptions): string {\n const s = this.s;\n const callbackId = options.id ?? newHandleId();\n if (s.callbacks.has(callbackId)) this.deleteEntry(callbackId, false);\n const entry: CallbackEntry = { callback: slot };\n if (options.context !== undefined) entry.context = options.context;\n if (options.groupId !== undefined) entry.groupId = options.groupId;\n if (options.owner !== undefined) entry.owner = options.owner;\n if (options.onRemove !== undefined) entry.onRemove = options.onRemove;\n s.callbacks.set(callbackId, entry);\n\n if (options.groupId !== undefined) {\n const group = s.groups.get(options.groupId) ?? new Set<string>();\n group.add(callbackId);\n s.groups.set(options.groupId, group);\n }\n if (options.owner !== undefined) {\n const owned = s.owners.get(options.owner) ?? new Set<string>();\n owned.add(callbackId);\n s.owners.set(options.owner, owned);\n }\n this.notifyRegistry();\n return callbackId;\n }\n\n /** Subscribe to results for a callback id. */\n subscribe<T, C extends CallbackContext = CallbackContext>(callbackId: string, listener: Callback<T, C>): boolean {\n const entry = this.s.callbacks.get(callbackId);\n if (!entry) return false;\n (entry.listeners ??= []).push(listener as Callback<never, never>);\n return true;\n }\n\n /** Unsubscribe a listener from a callback id. */\n unsubscribe<T, C extends CallbackContext = CallbackContext>(callbackId: string, listener: Callback<T, C>): boolean {\n const entry = this.s.callbacks.get(callbackId);\n if (!entry || !entry.listeners) return false;\n const index = entry.listeners.indexOf(listener as Callback<never, never>);\n if (index === -1) return false;\n entry.listeners.splice(index, 1);\n return true;\n }\n\n /** Run a callback once, notify its listeners, then remove it. */\n trigger<T>(callbackId: string, data: T): void {\n const entry = this.s.callbacks.get(callbackId);\n if (!entry) return;\n void invoke(entry.callback, data);\n if (entry.listeners && entry.listeners.length > 0) {\n for (const listener of [...entry.listeners]) void invokeListener(listener, data);\n }\n this.deleteEntry(callbackId, true);\n }\n\n /** Trigger with merged context and progress; removes unless `removeAfterTrigger: false`. */\n triggerWithContext<T, C extends CallbackContext = CallbackContext>(\n callbackId: string,\n data: T,\n options?: TriggerOptions<C>,\n ): void {\n const entry = this.s.callbacks.get(callbackId);\n if (!entry) return;\n const mergedContext: CallbackContext = {\n ...entry.context,\n ...options?.context,\n ...(options?.progress && { progress: options.progress }),\n };\n void invoke(entry.callback, data, mergedContext);\n if (entry.listeners && entry.listeners.length > 0) {\n for (const listener of [...entry.listeners]) void invokeListener(listener, data, mergedContext);\n }\n if (options?.removeAfterTrigger !== false) this.deleteEntry(callbackId, true);\n }\n\n /** Trigger every callback in a group. */\n triggerGroup<T, C extends CallbackContext = CallbackContext>(groupId: string, data: T, options?: TriggerOptions<C>): void {\n const group = this.s.groups.get(groupId);\n if (!group) return;\n for (const callbackId of [...group]) this.triggerWithContext(callbackId, data, options);\n if (options?.removeAfterTrigger !== false) this.s.groups.delete(groupId);\n }\n\n /**\n * Run the one durable command registered for a group. A command is retained on rejection so its\n * caller can retry, and is removed only after its promise settles successfully.\n */\n async triggerGroupCommand<T, C extends CallbackContext = CallbackContext>(\n groupId: string,\n data: T,\n options?: { context?: C; removeAfterSuccess?: boolean },\n ): Promise<void> {\n const group = this.s.groups.get(groupId);\n const callbackIds = group ? [...group] : [];\n const callbackId = callbackIds[0];\n if (callbackIds.length !== 1 || callbackId === undefined) {\n throw new Error(`Expected exactly one command callback for group \"${groupId}\", found ${callbackIds.length}`);\n }\n const entry = this.s.callbacks.get(callbackId);\n if (!entry) throw new Error(`Command callback \"${callbackId}\" is no longer available`);\n\n const mergedContext: CallbackContext = { ...entry.context, ...options?.context };\n await invoke(entry.callback, data, mergedContext);\n\n // Observers never control command settlement: the command already acknowledged.\n for (const listener of entry.listeners ?? []) {\n try {\n await invokeListener(listener, data, mergedContext);\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(\"[overlays/handles] command observer failed\", error);\n }\n }\n\n if (options?.removeAfterSuccess !== false) {\n this.deleteEntry(callbackId, true);\n this.s.groups.delete(groupId);\n }\n }\n\n /** Report progress to a callback (or every callback of a group) without removing it. */\n updateProgress(\n id: string,\n progress: number,\n options?: { status?: ProgressInfo[\"status\"]; error?: Error; groupId?: boolean },\n ): void {\n const progressInfo: ProgressInfo = { progress, status: options?.status || \"running\" };\n if (options?.error !== undefined) progressInfo.error = options.error;\n if (options?.groupId) {\n this.triggerGroup(id, null, { progress: progressInfo, removeAfterTrigger: false });\n } else {\n this.triggerWithContext(id, null, { progress: progressInfo, removeAfterTrigger: false });\n }\n }\n\n /** Create a new, empty group and return its id. */\n createGroup(): string {\n const groupId = newHandleId();\n this.s.groups.set(groupId, new Set());\n return groupId;\n }\n\n /** Remove one entry (and its group/owner membership). */\n remove(callbackId: string): void {\n this.deleteEntry(callbackId, true);\n }\n\n /** Alias of `remove` — the preferred name when unregistering a handle on unmount. */\n unregister(callbackId: string): void {\n this.remove(callbackId);\n }\n\n /** The stored callback or object handle for an id, without invoking it. */\n get<T = unknown>(callbackId: string): T | undefined {\n return this.s.callbacks.get(callbackId)?.callback as T | undefined;\n }\n\n /** True when the id is registered. */\n has(callbackId: string): boolean {\n return this.s.callbacks.has(callbackId);\n }\n\n /**\n * Register an object handle (a widget handle, an editor API, …). The object occupies the slot;\n * it is never invoked by `trigger`, only retrieved with `get`.\n */\n registerWidgetHandle<H extends object>(handle: H, options: { owner?: string } = {}): string {\n return this.registerEntry(handle, options.owner === undefined ? {} : { owner: options.owner });\n }\n\n /** Remove a group and all its callbacks. */\n removeGroup(groupId: string): void {\n const s = this.s;\n const group = s.groups.get(groupId);\n if (!group) return;\n s.groups.delete(groupId);\n for (const callbackId of [...group]) this.deleteEntry(callbackId, false);\n this.notifyRegistry();\n }\n\n /** Remove everything registered with `owner` (an InstanceKey). Returns how many were removed. */\n disposeOwner(owner: string): number {\n const s = this.s;\n const owned = s.owners.get(owner);\n if (!owned) return 0;\n s.owners.delete(owner);\n const ids = [...owned];\n for (const callbackId of ids) this.deleteEntry(callbackId, false);\n if (ids.length > 0) this.notifyRegistry();\n return ids.length;\n }\n\n /** Ids currently owned by `owner`. */\n ownedBy(owner: string): readonly string[] {\n return [...(this.s.owners.get(owner) ?? [])];\n }\n\n /** The member ids of a group (empty when unknown). */\n groupMembers(groupId: string): readonly string[] {\n return [...(this.s.groups.get(groupId) ?? [])];\n }\n\n /** Total registered entries (diagnostics, leak tests). */\n size(): number {\n return this.s.callbacks.size;\n }\n\n /**\n * The one removal path. Reads the entry BEFORE deleting it so group and owner membership shrink\n * (the old `removeFromGroups`-after-delete bug), then runs the entry's removal hook.\n */\n private deleteEntry(callbackId: string, notify: boolean): void {\n const s = this.s;\n const entry = s.callbacks.get(callbackId);\n if (!entry) return;\n s.callbacks.delete(callbackId);\n if (entry.groupId !== undefined) {\n const group = s.groups.get(entry.groupId);\n group?.delete(callbackId);\n if (group?.size === 0) s.groups.delete(entry.groupId);\n }\n if (entry.owner !== undefined) {\n const owned = s.owners.get(entry.owner);\n owned?.delete(callbackId);\n if (owned?.size === 0) s.owners.delete(entry.owner);\n }\n if (notify) this.notifyRegistry();\n entry.onRemove?.();\n }\n}\n\n/** The process-wide handles registry (state in the global slot; every instance shares it). */\nexport const callbackManager = new CallbackManager();\n\n/** Remove everything owned by an open instance (`overlayId:instanceId`). */\nexport function disposeOwner(owner: string): number {\n return callbackManager.disposeOwner(owner);\n}\n","/** A fresh handle id: `crypto.randomUUID` when present, else a v4 UUID from `getRandomValues`. */\nexport function newHandleId(): string {\n const c: Crypto | undefined = typeof globalThis.crypto === \"undefined\" ? undefined : globalThis.crypto;\n if (c && typeof c.randomUUID === \"function\") return c.randomUUID();\n const bytes = new Uint8Array(16);\n if (c && typeof c.getRandomValues === \"function\") {\n c.getRandomValues(bytes);\n } else {\n for (let i = 0; i < 16; i += 1) bytes[i] = Math.floor(Math.random() * 256);\n }\n bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x40;\n bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80;\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n","/** The global slot that holds the handles registry (one registry per realm, whatever the bundling). */\nexport const HANDLES_SLOT = \"ai-matrx.summon.handles\";\n","/**\n * Typed helpers over the handles registry: imperative object handles, event channels and one-shot\n * requests. Each is stored in the same registry (so its id can ride overlay open data and `get`\n * still resolves it) and accepts an `owner` InstanceKey so closing the owning overlay disposes it.\n */\nimport { callbackManager } from \"./callbackManager\";\n\nexport interface OwnerOption {\n /** The InstanceKey (`overlayId:instanceId`) that owns this handle; disposed when it closes. */\n owner?: string;\n}\n\n/** Thrown into a request's promise when it is disposed before being answered. */\nexport class HandleDisposedError extends Error {\n readonly handleId: string;\n constructor(handleId: string, message = `[overlays/handles] \"${handleId}\" was disposed before it settled`) {\n super(message);\n this.name = \"HandleDisposedError\";\n this.handleId = handleId;\n }\n}\n\nfunction ownerOptions(options: OwnerOption | undefined): { owner?: string } {\n return options?.owner === undefined ? {} : { owner: options.owner };\n}\n\n// ── Imperative object handles ────────────────────────────────────────────────────────────────\n\n/**\n * Register an imperative object handle under a caller-chosen id (an editor API, a widget handle,\n * a ref's methods). Re-registering an id replaces the previous handle. Returns a disposer that\n * removes the handle only if it is still the one registered (safe for React effect cleanup).\n */\nexport function registerHandle<T extends object>(id: string, handle: T, options?: OwnerOption): () => void {\n callbackManager.registerEntry(handle, { id, ...ownerOptions(options) });\n return () => {\n if (callbackManager.get<T>(id) === handle) callbackManager.remove(id);\n };\n}\n\n/** The object handle registered under `id`, or undefined. */\nexport function getHandle<T extends object>(id: string): T | undefined {\n const value = callbackManager.get<unknown>(id);\n return typeof value === \"object\" && value !== null ? (value as T) : undefined;\n}\n\n/** Remove the handle registered under `id`. */\nexport function removeHandle(id: string): void {\n callbackManager.remove(id);\n}\n\n// ── Event channels ───────────────────────────────────────────────────────────────────────────\n\nexport interface EventChannel<Events> {\n readonly id: string;\n /** Deliver an event to every subscriber (no-op after dispose). */\n emit(event: Events): void;\n /** Listen; returns the unsubscribe. */\n subscribe(listener: (event: Events) => void): () => void;\n /** Remove the channel and drop every subscriber. */\n dispose(): void;\n readonly disposed: boolean;\n}\n\n/**\n * A many-shot event stream between an opener and an overlay. Pass `channel.id` in open data; the\n * overlay resolves it with `getEventChannel(id)`.\n */\nexport function createEventChannel<Events>(options?: OwnerOption & { readonly id?: string }): EventChannel<Events> {\n const listeners = new Set<(event: Events) => void>();\n let disposed = false;\n let id = \"\";\n const channel: EventChannel<Events> = {\n get id() {\n return id;\n },\n get disposed() {\n return disposed;\n },\n emit(event) {\n if (disposed) return;\n for (const listener of [...listeners]) listener(event);\n },\n subscribe(listener) {\n if (disposed) return () => {};\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n dispose() {\n if (disposed) return;\n callbackManager.remove(id);\n },\n };\n id = callbackManager.registerEntry(channel, {\n ...(options?.id === undefined ? {} : { id: options.id }),\n ...ownerOptions(options),\n onRemove: () => {\n disposed = true;\n listeners.clear();\n },\n });\n return channel;\n}\n\n/** The channel registered under `id`, or undefined once disposed. */\nexport function getEventChannel<Events>(id: string): EventChannel<Events> | undefined {\n return getHandle<EventChannel<Events>>(id);\n}\n\n// ── One-shot requests ────────────────────────────────────────────────────────────────────────\n\nexport interface PendingRequest<Req, Res> {\n readonly id: string;\n /** What the asker sent. */\n readonly request: Req;\n /** Answer the request (first answer wins; later calls are ignored). */\n resolve(response: Res): void;\n /** Fail the request. */\n reject(reason: unknown): void;\n readonly settled: boolean;\n}\n\nexport interface RequestHandle<Req, Res> extends PendingRequest<Req, Res> {\n /** Settles with the answer; rejects with `HandleDisposedError` when disposed unanswered. */\n readonly promise: Promise<Res>;\n /** Remove the request; an unanswered one rejects. */\n dispose(): void;\n}\n\n/**\n * A one-shot promise bridge: the asker awaits `promise`, the overlay answers through\n * `getRequest(id).resolve(…)`. Disposing it unanswered (or closing its owner) rejects.\n */\nexport function createRequest<Req, Res>(request: Req, options?: OwnerOption): RequestHandle<Req, Res> {\n let settle!: (response: Res) => void;\n let fail!: (reason: unknown) => void;\n const promise = new Promise<Res>((resolve, reject) => {\n settle = resolve;\n fail = reject;\n });\n // A disposed request nobody awaited must not surface as an unhandled rejection.\n promise.catch(() => {});\n let settled = false;\n let id = \"\";\n const handle: RequestHandle<Req, Res> = {\n get id() {\n return id;\n },\n request,\n promise,\n get settled() {\n return settled;\n },\n resolve(response) {\n if (settled) return;\n settled = true;\n settle(response);\n callbackManager.remove(id);\n },\n reject(reason) {\n if (settled) return;\n settled = true;\n fail(reason);\n callbackManager.remove(id);\n },\n dispose() {\n callbackManager.remove(id);\n },\n };\n id = callbackManager.registerEntry(handle, {\n ...ownerOptions(options),\n onRemove: () => {\n if (settled) return;\n settled = true;\n fail(new HandleDisposedError(id));\n },\n });\n return handle;\n}\n\n/** The pending request registered under `id`, or undefined once answered or disposed. */\nexport function getRequest<Req, Res>(id: string): PendingRequest<Req, Res> | undefined {\n return getHandle<RequestHandle<Req, Res>>(id);\n}\n"],"mappings":";AAsBA,SAAS,kBAAkB;;;ACrBpB,SAAS,cAAsB;AACpC,QAAM,IAAwB,OAAO,WAAW,WAAW,cAAc,SAAY,WAAW;AAChG,MAAI,KAAK,OAAO,EAAE,eAAe,WAAY,QAAO,EAAE,WAAW;AACjE,QAAM,QAAQ,IAAI,WAAW,EAAE;AAC/B,MAAI,KAAK,OAAO,EAAE,oBAAoB,YAAY;AAChD,MAAE,gBAAgB,KAAK;AAAA,EACzB,OAAO;AACL,aAAS,IAAI,GAAG,IAAI,IAAI,KAAK,EAAG,OAAM,CAAC,IAAI,KAAK,MAAM,KAAK,OAAO,IAAI,GAAG;AAAA,EAC3E;AACA,QAAM,CAAC,KAAM,MAAM,CAAC,KAAK,KAAK,KAAQ;AACtC,QAAM,CAAC,KAAM,MAAM,CAAC,KAAK,KAAK,KAAQ;AACtC,QAAM,MAAM,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AAC7E,SAAO,GAAG,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,MAAM,GAAG,EAAE,CAAC,IAAI,IAAI,MAAM,IAAI,EAAE,CAAC,IAAI,IAAI,MAAM,IAAI,EAAE,CAAC,IAAI,IAAI,MAAM,EAAE,CAAC;AAC1G;;;ACbO,IAAM,eAAe;;;AF0E5B,IAAM,eAAe,MACnB,WAAyB,cAAc,OAAO;AAAA,EAC5C,WAAW,oBAAI,IAAI;AAAA,EACnB,QAAQ,oBAAI,IAAI;AAAA,EAChB,QAAQ,oBAAI,IAAI;AAAA,EAChB,mBAAmB,oBAAI,IAAI;AAC7B,EAAE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B,OAAO,EAAE;AAAA,IAC3B;AAAA,EACF;AACA,OAAK,gBAAgB,cAAc,QAAQ;AAAA,IACzC,GAAG,aAAa,OAAO;AAAA,IACvB,UAAU,MAAM;AACd,UAAI,QAAS;AACb,gBAAU;AACV,WAAK,IAAI,oBAAoB,EAAE,CAAC;AAAA,IAClC;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAGO,SAAS,WAAqB,IAAkD;AACrF,SAAO,UAAmC,EAAE;AAC9C;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/open/ids.ts","../src/handles/slot.ts","../src/open/handleEntries.ts","../src/handles/callbackManager.ts","../src/handles/helpers.ts"],"sourcesContent":["/** A fresh handle id: `crypto.randomUUID` when present, else a v4 UUID from `getRandomValues`. */\nexport function newHandleId(): string {\n const c: Crypto | undefined = typeof globalThis.crypto === \"undefined\" ? undefined : globalThis.crypto;\n if (c && typeof c.randomUUID === \"function\") return c.randomUUID();\n const bytes = new Uint8Array(16);\n if (c && typeof c.getRandomValues === \"function\") {\n c.getRandomValues(bytes);\n } else {\n for (let i = 0; i < 16; i += 1) bytes[i] = Math.floor(Math.random() * 256);\n }\n bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x40;\n bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80;\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n","/** The global slot that holds the handles registry (one registry per realm, whatever the bundling). */\nexport const HANDLES_SLOT = \"ai-matrx.summon.handles\";\n","// The handles registry's STATE and its insert/remove path, without the registry's verbs (trigger,\n// subscribe, requests, channels). A boot-time opener that only needs an id NOW — register a\n// callback, a payload group, an object handle; drop it on close — writes through here and never\n// puts `@ai-matrx/summon/handles` in first load; whoever later triggers or reads loads the full\n// registry, which works on the same global slot through these same functions (one removal path).\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\nimport { HANDLES_SLOT } from \"../handles/slot\";\nimport { newHandleId } from \"./ids\";\n\n/** A registry slot: a callback (invoked by triggers) or an object handle (only ever read). */\nexport type HandleEntrySlot = ((...args: never[]) => unknown) | object;\n\n/** @internal A registry entry (the handles section adds `listeners`). */\nexport interface HandleEntry {\n callback: HandleEntrySlot;\n context?: Record<string, unknown>;\n groupId?: string;\n owner?: string;\n listeners?: Array<(...args: never[]) => unknown>;\n /** Runs once when the entry leaves the registry for any reason (requests reject here). */\n onRemove?: () => void;\n}\n\n/** @internal The registry state in its global slot (one per realm, whatever the bundling). */\nexport interface HandlesState {\n readonly callbacks: Map<string, HandleEntry>;\n readonly groups: Map<string, Set<string>>;\n readonly owners: Map<string, Set<string>>;\n readonly registryListeners: Set<() => void>;\n}\n\nexport interface HandleEntryOptions {\n /** A fixed id (default: a fresh `newHandleId()`); an existing entry with it is replaced. */\n id?: string;\n context?: Record<string, unknown>;\n /** Join (or start) this group; `removeHandleGroup` drops every member. */\n groupId?: string;\n /** The InstanceKey (`overlayId:instanceId`) that owns this entry; disposed when it closes. */\n owner?: string;\n onRemove?: () => void;\n}\n\n/** @internal */\nexport const handlesState = (): HandlesState =>\n globalSlot<HandlesState>(HANDLES_SLOT, () => ({\n callbacks: new Map(),\n groups: new Map(),\n owners: new Map(),\n registryListeners: new Set(),\n }));\n\n/** @internal */\nexport function notifyHandlesRegistry(): void {\n for (const listener of [...handlesState().registryListeners]) listener();\n}\n\n/**\n * The one removal path. Reads the entry BEFORE deleting it so group and owner membership shrink,\n * then runs the entry's removal hook.\n */\nexport function deleteHandleEntry(id: string, notify = true): void {\n const s = handlesState();\n const entry = s.callbacks.get(id);\n if (!entry) return;\n s.callbacks.delete(id);\n if (entry.groupId !== undefined) {\n const group = s.groups.get(entry.groupId);\n group?.delete(id);\n if (group?.size === 0) s.groups.delete(entry.groupId);\n }\n if (entry.owner !== undefined) {\n const owned = s.owners.get(entry.owner);\n owned?.delete(id);\n if (owned?.size === 0) s.owners.delete(entry.owner);\n }\n if (notify) notifyHandlesRegistry();\n entry.onRemove?.();\n}\n\n/** Register a callback or object handle NOW (no registry load); returns its id. */\nexport function registerHandleEntry(slot: HandleEntrySlot, options: HandleEntryOptions = {}): string {\n const s = handlesState();\n const id = options.id ?? newHandleId();\n if (s.callbacks.has(id)) deleteHandleEntry(id, false);\n const entry: HandleEntry = { callback: slot };\n if (options.context !== undefined) entry.context = options.context;\n if (options.groupId !== undefined) entry.groupId = options.groupId;\n if (options.owner !== undefined) entry.owner = options.owner;\n if (options.onRemove !== undefined) entry.onRemove = options.onRemove;\n s.callbacks.set(id, entry);\n if (options.groupId !== undefined) {\n const group = s.groups.get(options.groupId) ?? new Set<string>();\n group.add(id);\n s.groups.set(options.groupId, group);\n }\n if (options.owner !== undefined) {\n const owned = s.owners.get(options.owner) ?? new Set<string>();\n owned.add(id);\n s.owners.set(options.owner, owned);\n }\n notifyHandlesRegistry();\n return id;\n}\n\n/** `callbackManager.unregister(id)` without loading the registry. */\nexport function unregisterHandleEntry(id: string): void {\n deleteHandleEntry(id, true);\n}\n\n/** `callbackManager.removeGroup(groupId)` without loading the registry. */\nexport function removeHandleGroup(groupId: string): void {\n const s = handlesState();\n const group = s.groups.get(groupId);\n if (!group) return;\n s.groups.delete(groupId);\n for (const id of [...group]) deleteHandleEntry(id, false);\n notifyHandlesRegistry();\n}\n","/**\n * The handles registry — everything that cannot travel through Redux (callbacks, event channels,\n * one-shot requests, imperative object handles) lives here under a string id; only the id goes\n * into overlay open data.\n *\n * Successor of `@ai-matrx/chat` `utils/callbackManager.ts` with the SAME public verbs and types, so\n * moving a caller is an import-path swap. Changes (CHANGELOG 0.1.0):\n * 1. State lives in the global slot \"ai-matrx.summon.handles\", never in module scope: a\n * duplicated module graph (ESM + CJS, unsplit bundles, two packages) sees one registry.\n * 2. Removal bug fixed: `trigger` / `triggerWithContext` / `remove` deleted the entry BEFORE\n * `removeFromGroups` read it, so group membership never shrank and emptied groups were never\n * dropped. Removal now reads the entry first, in one place (`deleteEntry`).\n * 3. Owner scoping: `registerWithContext(cb, { owner })` (an InstanceKey `overlayId:instanceId`)\n * ties the entry to an open overlay instance; `disposeOwner(owner)` removes everything it\n * owns. The overlays close middleware calls it, so no opener disposes by hand.\n * 4. The object slot is handle-agnostic: `registerWidgetHandle<H extends object>(handle)` stores\n * any object (no chat `WidgetHandle` import).\n * 5. Ids come from `crypto.randomUUID` (no `uuid` dependency), with a fallback for insecure\n * contexts where `randomUUID` is absent.\n *\n * Framework-free: no React, no Redux.\n */\nimport { newHandleId } from \"./ids\";\nimport { HANDLES_SLOT } from \"./slot\";\nimport {\n deleteHandleEntry,\n handlesState as sharedHandlesState,\n notifyHandlesRegistry,\n registerHandleEntry,\n removeHandleGroup,\n type HandlesState as SharedHandlesState,\n} from \"../open/handleEntries\";\n\nexport type CallbackContext = Record<string, unknown>;\n\nexport interface ProgressInfo {\n progress?: number;\n status?: \"pending\" | \"running\" | \"completed\" | \"error\";\n error?: Error;\n}\n\nexport type Callback<T = unknown, C extends CallbackContext = CallbackContext> = (\n data: T,\n context?: C,\n) => void | Promise<void>;\n\n/** What an entry's slot holds: a callback, or an object handle retrieved with `get`. */\nexport type HandleSlot = Callback<never, never> | object;\n\nexport interface RegisterOptions<C extends CallbackContext = CallbackContext> {\n context?: C;\n groupId?: string;\n /** The InstanceKey (`overlayId:instanceId`) that owns this entry; disposed when it closes. */\n owner?: string;\n}\n\nexport interface TriggerOptions<C extends CallbackContext = CallbackContext> {\n context?: C;\n progress?: ProgressInfo;\n removeAfterTrigger?: boolean;\n}\n\n/** A registry entry. `callback` is the heterogeneous slot (function or object handle). */\ninterface CallbackEntry {\n callback: HandleSlot;\n context?: CallbackContext;\n groupId?: string;\n owner?: string;\n listeners?: Array<Callback<never, never>>;\n /** Runs once when the entry leaves the registry for any reason (requests reject here). */\n onRemove?: () => void;\n}\n\ninterface HandlesState {\n readonly callbacks: Map<string, CallbackEntry>;\n readonly groups: Map<string, Set<string>>;\n readonly owners: Map<string, Set<string>>;\n readonly registryListeners: Set<() => void>;\n}\n\nexport { HANDLES_SLOT };\n\n// State, insertion and removal are the light path on `./open` (`open/handleEntries.ts`), so a\n// boot-time registrant and this registry share one slot and one removal path.\nconst handlesState = (): HandlesState => sharedHandlesState() as SharedHandlesState as HandlesState;\n\n/** Invoke a slot as a callback (a function slot only; object handles are never invoked). */\nfunction invoke(slot: HandleSlot, data: unknown, context?: CallbackContext): void | Promise<void> {\n if (typeof slot !== \"function\") return undefined;\n return (slot as Callback<unknown, CallbackContext>)(data, context);\n}\n\nfunction invokeListener(listener: Callback<never, never>, data: unknown, context?: CallbackContext): void | Promise<void> {\n return (listener as Callback<unknown, CallbackContext>)(data, context);\n}\n\n/** Internal registration options beyond the public ones (used by the typed helpers). */\nexport interface InternalRegisterOptions extends RegisterOptions {\n id?: string;\n onRemove?: () => void;\n}\n\nexport class CallbackManager {\n private get s(): HandlesState {\n return handlesState();\n }\n\n /**\n * Observe the registry itself: `listener` runs after any entry is added or removed. This lets a\n * view that resolves ids with `get` re-render when an id goes away (`useSyncExternalStore`).\n */\n subscribeToRegistry(listener: () => void): () => void {\n const listeners = this.s.registryListeners;\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n }\n\n private notifyRegistry(): void {\n notifyHandlesRegistry();\n }\n\n /** Register a callback; returns its id. */\n register<T>(callback: Callback<T>): string {\n return this.registerEntry(callback as HandleSlot, {});\n }\n\n /** Register with optional context, group and owner. */\n registerWithContext<T, C extends CallbackContext = CallbackContext>(\n callback: Callback<T, C>,\n options: RegisterOptions<C> = {},\n ): string {\n return this.registerEntry(callback as HandleSlot, options);\n }\n\n /** @internal The one insertion path (typed helpers pass a fixed id and a removal hook). */\n registerEntry(slot: HandleSlot, options: InternalRegisterOptions): string {\n return registerHandleEntry(slot, options);\n }\n\n /** Subscribe to results for a callback id. */\n subscribe<T, C extends CallbackContext = CallbackContext>(callbackId: string, listener: Callback<T, C>): boolean {\n const entry = this.s.callbacks.get(callbackId);\n if (!entry) return false;\n (entry.listeners ??= []).push(listener as Callback<never, never>);\n return true;\n }\n\n /** Unsubscribe a listener from a callback id. */\n unsubscribe<T, C extends CallbackContext = CallbackContext>(callbackId: string, listener: Callback<T, C>): boolean {\n const entry = this.s.callbacks.get(callbackId);\n if (!entry || !entry.listeners) return false;\n const index = entry.listeners.indexOf(listener as Callback<never, never>);\n if (index === -1) return false;\n entry.listeners.splice(index, 1);\n return true;\n }\n\n /** Run a callback once, notify its listeners, then remove it. */\n trigger<T>(callbackId: string, data: T): void {\n const entry = this.s.callbacks.get(callbackId);\n if (!entry) return;\n void invoke(entry.callback, data);\n if (entry.listeners && entry.listeners.length > 0) {\n for (const listener of [...entry.listeners]) void invokeListener(listener, data);\n }\n this.deleteEntry(callbackId, true);\n }\n\n /** Trigger with merged context and progress; removes unless `removeAfterTrigger: false`. */\n triggerWithContext<T, C extends CallbackContext = CallbackContext>(\n callbackId: string,\n data: T,\n options?: TriggerOptions<C>,\n ): void {\n const entry = this.s.callbacks.get(callbackId);\n if (!entry) return;\n const mergedContext: CallbackContext = {\n ...entry.context,\n ...options?.context,\n ...(options?.progress && { progress: options.progress }),\n };\n void invoke(entry.callback, data, mergedContext);\n if (entry.listeners && entry.listeners.length > 0) {\n for (const listener of [...entry.listeners]) void invokeListener(listener, data, mergedContext);\n }\n if (options?.removeAfterTrigger !== false) this.deleteEntry(callbackId, true);\n }\n\n /** Trigger every callback in a group. */\n triggerGroup<T, C extends CallbackContext = CallbackContext>(groupId: string, data: T, options?: TriggerOptions<C>): void {\n const group = this.s.groups.get(groupId);\n if (!group) return;\n for (const callbackId of [...group]) this.triggerWithContext(callbackId, data, options);\n if (options?.removeAfterTrigger !== false) this.s.groups.delete(groupId);\n }\n\n /**\n * Run the one durable command registered for a group. A command is retained on rejection so its\n * caller can retry, and is removed only after its promise settles successfully.\n */\n async triggerGroupCommand<T, C extends CallbackContext = CallbackContext>(\n groupId: string,\n data: T,\n options?: { context?: C; removeAfterSuccess?: boolean },\n ): Promise<void> {\n const group = this.s.groups.get(groupId);\n const callbackIds = group ? [...group] : [];\n const callbackId = callbackIds[0];\n if (callbackIds.length !== 1 || callbackId === undefined) {\n throw new Error(`Expected exactly one command callback for group \"${groupId}\", found ${callbackIds.length}`);\n }\n const entry = this.s.callbacks.get(callbackId);\n if (!entry) throw new Error(`Command callback \"${callbackId}\" is no longer available`);\n\n const mergedContext: CallbackContext = { ...entry.context, ...options?.context };\n await invoke(entry.callback, data, mergedContext);\n\n // Observers never control command settlement: the command already acknowledged.\n for (const listener of entry.listeners ?? []) {\n try {\n await invokeListener(listener, data, mergedContext);\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(\"[overlays/handles] command observer failed\", error);\n }\n }\n\n if (options?.removeAfterSuccess !== false) {\n this.deleteEntry(callbackId, true);\n this.s.groups.delete(groupId);\n }\n }\n\n /** Report progress to a callback (or every callback of a group) without removing it. */\n updateProgress(\n id: string,\n progress: number,\n options?: { status?: ProgressInfo[\"status\"]; error?: Error; groupId?: boolean },\n ): void {\n const progressInfo: ProgressInfo = { progress, status: options?.status || \"running\" };\n if (options?.error !== undefined) progressInfo.error = options.error;\n if (options?.groupId) {\n this.triggerGroup(id, null, { progress: progressInfo, removeAfterTrigger: false });\n } else {\n this.triggerWithContext(id, null, { progress: progressInfo, removeAfterTrigger: false });\n }\n }\n\n /** Create a new, empty group and return its id. */\n createGroup(): string {\n const groupId = newHandleId();\n this.s.groups.set(groupId, new Set());\n return groupId;\n }\n\n /** Remove one entry (and its group/owner membership). */\n remove(callbackId: string): void {\n this.deleteEntry(callbackId, true);\n }\n\n /** Alias of `remove` — the preferred name when unregistering a handle on unmount. */\n unregister(callbackId: string): void {\n this.remove(callbackId);\n }\n\n /** The stored callback or object handle for an id, without invoking it. */\n get<T = unknown>(callbackId: string): T | undefined {\n return this.s.callbacks.get(callbackId)?.callback as T | undefined;\n }\n\n /** True when the id is registered. */\n has(callbackId: string): boolean {\n return this.s.callbacks.has(callbackId);\n }\n\n /**\n * Register an object handle (a widget handle, an editor API, …). The object occupies the slot;\n * it is never invoked by `trigger`, only retrieved with `get`.\n */\n registerWidgetHandle<H extends object>(handle: H, options: { owner?: string } = {}): string {\n return this.registerEntry(handle, options.owner === undefined ? {} : { owner: options.owner });\n }\n\n /** Remove a group and all its callbacks. */\n removeGroup(groupId: string): void {\n removeHandleGroup(groupId);\n }\n\n /** Remove everything registered with `owner` (an InstanceKey). Returns how many were removed. */\n disposeOwner(owner: string): number {\n const s = this.s;\n const owned = s.owners.get(owner);\n if (!owned) return 0;\n s.owners.delete(owner);\n const ids = [...owned];\n for (const callbackId of ids) this.deleteEntry(callbackId, false);\n if (ids.length > 0) this.notifyRegistry();\n return ids.length;\n }\n\n /** Ids currently owned by `owner`. */\n ownedBy(owner: string): readonly string[] {\n return [...(this.s.owners.get(owner) ?? [])];\n }\n\n /** The member ids of a group (empty when unknown). */\n groupMembers(groupId: string): readonly string[] {\n return [...(this.s.groups.get(groupId) ?? [])];\n }\n\n /** Total registered entries (diagnostics, leak tests). */\n size(): number {\n return this.s.callbacks.size;\n }\n\n /**\n * The one removal path. Reads the entry BEFORE deleting it so group and owner membership shrink\n * (the old `removeFromGroups`-after-delete bug), then runs the entry's removal hook.\n */\n private deleteEntry(callbackId: string, notify: boolean): void {\n deleteHandleEntry(callbackId, notify);\n }\n}\n\n/** The process-wide handles registry (state in the global slot; every instance shares it). */\nexport const callbackManager = new CallbackManager();\n\n/** Remove everything owned by an open instance (`overlayId:instanceId`). */\nexport function disposeOwner(owner: string): number {\n return callbackManager.disposeOwner(owner);\n}\n","/**\n * Typed helpers over the handles registry: imperative object handles, event channels and one-shot\n * requests. Each is stored in the same registry (so its id can ride overlay open data and `get`\n * still resolves it) and accepts an `owner` InstanceKey so closing the owning overlay disposes it.\n */\nimport { callbackManager } from \"./callbackManager\";\n\nexport interface OwnerOption {\n /** The InstanceKey (`overlayId:instanceId`) that owns this handle; disposed when it closes. */\n owner?: string;\n}\n\n/** Thrown into a request's promise when it is disposed before being answered. */\nexport class HandleDisposedError extends Error {\n readonly handleId: string;\n constructor(handleId: string, message = `[overlays/handles] \"${handleId}\" was disposed before it settled`) {\n super(message);\n this.name = \"HandleDisposedError\";\n this.handleId = handleId;\n }\n}\n\nfunction ownerOptions(options: OwnerOption | undefined): { owner?: string } {\n return options?.owner === undefined ? {} : { owner: options.owner };\n}\n\n// ── Imperative object handles ────────────────────────────────────────────────────────────────\n\n/**\n * Register an imperative object handle under a caller-chosen id (an editor API, a widget handle,\n * a ref's methods). Re-registering an id replaces the previous handle. Returns a disposer that\n * removes the handle only if it is still the one registered (safe for React effect cleanup).\n */\nexport function registerHandle<T extends object>(id: string, handle: T, options?: OwnerOption): () => void {\n callbackManager.registerEntry(handle, { id, ...ownerOptions(options) });\n return () => {\n if (callbackManager.get<T>(id) === handle) callbackManager.remove(id);\n };\n}\n\n/** The object handle registered under `id`, or undefined. */\nexport function getHandle<T extends object>(id: string): T | undefined {\n const value = callbackManager.get<unknown>(id);\n return typeof value === \"object\" && value !== null ? (value as T) : undefined;\n}\n\n/** Remove the handle registered under `id`. */\nexport function removeHandle(id: string): void {\n callbackManager.remove(id);\n}\n\n// ── Event channels ───────────────────────────────────────────────────────────────────────────\n\nexport interface EventChannel<Events> {\n readonly id: string;\n /** Deliver an event to every subscriber (no-op after dispose). */\n emit(event: Events): void;\n /** Listen; returns the unsubscribe. */\n subscribe(listener: (event: Events) => void): () => void;\n /** Remove the channel and drop every subscriber. */\n dispose(): void;\n readonly disposed: boolean;\n}\n\n/**\n * A many-shot event stream between an opener and an overlay. Pass `channel.id` in open data; the\n * overlay resolves it with `getEventChannel(id)`.\n */\nexport function createEventChannel<Events>(options?: OwnerOption & { readonly id?: string }): EventChannel<Events> {\n const listeners = new Set<(event: Events) => void>();\n let disposed = false;\n let id = \"\";\n const channel: EventChannel<Events> = {\n get id() {\n return id;\n },\n get disposed() {\n return disposed;\n },\n emit(event) {\n if (disposed) return;\n for (const listener of [...listeners]) listener(event);\n },\n subscribe(listener) {\n if (disposed) return () => {};\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n dispose() {\n if (disposed) return;\n callbackManager.remove(id);\n },\n };\n id = callbackManager.registerEntry(channel, {\n ...(options?.id === undefined ? {} : { id: options.id }),\n ...ownerOptions(options),\n onRemove: () => {\n disposed = true;\n listeners.clear();\n },\n });\n return channel;\n}\n\n/** The channel registered under `id`, or undefined once disposed. */\nexport function getEventChannel<Events>(id: string): EventChannel<Events> | undefined {\n return getHandle<EventChannel<Events>>(id);\n}\n\n// ── One-shot requests ────────────────────────────────────────────────────────────────────────\n\nexport interface PendingRequest<Req, Res> {\n readonly id: string;\n /** What the asker sent. */\n readonly request: Req;\n /** Answer the request (first answer wins; later calls are ignored). */\n resolve(response: Res): void;\n /** Fail the request. */\n reject(reason: unknown): void;\n readonly settled: boolean;\n}\n\nexport interface RequestHandle<Req, Res> extends PendingRequest<Req, Res> {\n /** Settles with the answer; rejects with `HandleDisposedError` when disposed unanswered. */\n readonly promise: Promise<Res>;\n /** Remove the request; an unanswered one rejects. */\n dispose(): void;\n}\n\n/**\n * A one-shot promise bridge: the asker awaits `promise`, the overlay answers through\n * `getRequest(id).resolve(…)`. Disposing it unanswered (or closing its owner) rejects.\n */\nexport function createRequest<Req, Res>(request: Req, options?: OwnerOption): RequestHandle<Req, Res> {\n let settle!: (response: Res) => void;\n let fail!: (reason: unknown) => void;\n const promise = new Promise<Res>((resolve, reject) => {\n settle = resolve;\n fail = reject;\n });\n // A disposed request nobody awaited must not surface as an unhandled rejection.\n promise.catch(() => {});\n let settled = false;\n let id = \"\";\n const handle: RequestHandle<Req, Res> = {\n get id() {\n return id;\n },\n request,\n promise,\n get settled() {\n return settled;\n },\n resolve(response) {\n if (settled) return;\n settled = true;\n settle(response);\n callbackManager.remove(id);\n },\n reject(reason) {\n if (settled) return;\n settled = true;\n fail(reason);\n callbackManager.remove(id);\n },\n dispose() {\n callbackManager.remove(id);\n },\n };\n id = callbackManager.registerEntry(handle, {\n ...ownerOptions(options),\n onRemove: () => {\n if (settled) return;\n settled = true;\n fail(new HandleDisposedError(id));\n },\n });\n return handle;\n}\n\n/** The pending request registered under `id`, or undefined once answered or disposed. */\nexport function getRequest<Req, Res>(id: string): PendingRequest<Req, Res> | undefined {\n return getHandle<RequestHandle<Req, Res>>(id);\n}\n"],"mappings":";AACO,SAAS,cAAsB;AACpC,QAAM,IAAwB,OAAO,WAAW,WAAW,cAAc,SAAY,WAAW;AAChG,MAAI,KAAK,OAAO,EAAE,eAAe,WAAY,QAAO,EAAE,WAAW;AACjE,QAAM,QAAQ,IAAI,WAAW,EAAE;AAC/B,MAAI,KAAK,OAAO,EAAE,oBAAoB,YAAY;AAChD,MAAE,gBAAgB,KAAK;AAAA,EACzB,OAAO;AACL,aAAS,IAAI,GAAG,IAAI,IAAI,KAAK,EAAG,OAAM,CAAC,IAAI,KAAK,MAAM,KAAK,OAAO,IAAI,GAAG;AAAA,EAC3E;AACA,QAAM,CAAC,KAAM,MAAM,CAAC,KAAK,KAAK,KAAQ;AACtC,QAAM,CAAC,KAAM,MAAM,CAAC,KAAK,KAAK,KAAQ;AACtC,QAAM,MAAM,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AAC7E,SAAO,GAAG,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,MAAM,GAAG,EAAE,CAAC,IAAI,IAAI,MAAM,IAAI,EAAE,CAAC,IAAI,IAAI,MAAM,IAAI,EAAE,CAAC,IAAI,IAAI,MAAM,EAAE,CAAC;AAC1G;;;ACbO,IAAM,eAAe;;;ACI5B,SAAS,kBAAkB;AAsCpB,IAAM,eAAe,MAC1B,WAAyB,cAAc,OAAO;AAAA,EAC5C,WAAW,oBAAI,IAAI;AAAA,EACnB,QAAQ,oBAAI,IAAI;AAAA,EAChB,QAAQ,oBAAI,IAAI;AAAA,EAChB,mBAAmB,oBA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,IACA;AAAA,IACA,IAAI,UAAU;AACZ,aAAO;AAAA,IACT;AAAA,IACA,QAAQ,UAAU;AAChB,UAAI,QAAS;AACb,gBAAU;AACV,aAAO,QAAQ;AACf,sBAAgB,OAAO,EAAE;AAAA,IAC3B;AAAA,IACA,OAAO,QAAQ;AACb,UAAI,QAAS;AACb,gBAAU;AACV,WAAK,MAAM;AACX,sBAAgB,OAAO,EAAE;AAAA,IAC3B;AAAA,IACA,UAAU;AACR,sBAAgB,OAAO,EAAE;AAAA,IAC3B;AAAA,EACF;AACA,OAAK,gBAAgB,cAAc,QAAQ;AAAA,IACzC,GAAG,aAAa,OAAO;AAAA,IACvB,UAAU,MAAM;AACd,UAAI,QAAS;AACb,gBAAU;AACV,WAAK,IAAI,oBAAoB,EAAE,CAAC;AAAA,IAClC;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAGO,SAAS,WAAqB,IAAkD;AACrF,SAAO,UAAmC,EAAE;AAC9C;","names":["handlesState"]}
|
|
@@ -60,4 +60,7 @@ declare function createRequest<Req, Res>(request: Req, options?: OwnerOption): R
|
|
|
60
60
|
/** The pending request registered under `id`, or undefined once answered or disposed. */
|
|
61
61
|
declare function getRequest<Req, Res>(id: string): PendingRequest<Req, Res> | undefined;
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
/** A fresh handle id: `crypto.randomUUID` when present, else a v4 UUID from `getRandomValues`. */
|
|
64
|
+
declare function newHandleId(): string;
|
|
65
|
+
|
|
66
|
+
export { type EventChannel as E, HandleDisposedError as H, type OwnerOption as O, type PendingRequest as P, type RequestHandle as R, createRequest as a, getHandle as b, createEventChannel as c, getRequest as d, removeHandle as e, getEventChannel as g, newHandleId as n, registerHandle as r };
|
|
@@ -60,4 +60,7 @@ declare function createRequest<Req, Res>(request: Req, options?: OwnerOption): R
|
|
|
60
60
|
/** The pending request registered under `id`, or undefined once answered or disposed. */
|
|
61
61
|
declare function getRequest<Req, Res>(id: string): PendingRequest<Req, Res> | undefined;
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
/** A fresh handle id: `crypto.randomUUID` when present, else a v4 UUID from `getRandomValues`. */
|
|
64
|
+
declare function newHandleId(): string;
|
|
65
|
+
|
|
66
|
+
export { type EventChannel as E, HandleDisposedError as H, type OwnerOption as O, type PendingRequest as P, type RequestHandle as R, createRequest as a, getHandle as b, createEventChannel as c, getRequest as d, removeHandle as e, getEventChannel as g, newHandleId as n, registerHandle as r };
|
package/dist/index.cjs
CHANGED
|
@@ -1754,10 +1754,7 @@ var import_toolkit5 = require("@reduxjs/toolkit");
|
|
|
1754
1754
|
// src/core/middleware/closeLifecycle.ts
|
|
1755
1755
|
var import_global_slot5 = require("@ai-matrx/kit/global-slot");
|
|
1756
1756
|
|
|
1757
|
-
// src/
|
|
1758
|
-
var import_global_slot3 = require("@ai-matrx/kit/global-slot");
|
|
1759
|
-
|
|
1760
|
-
// src/handles/ids.ts
|
|
1757
|
+
// src/open/ids.ts
|
|
1761
1758
|
function newHandleId() {
|
|
1762
1759
|
const c = typeof globalThis.crypto === "undefined" ? void 0 : globalThis.crypto;
|
|
1763
1760
|
if (c && typeof c.randomUUID === "function") return c.randomUUID();
|
|
@@ -1776,13 +1773,69 @@ function newHandleId() {
|
|
|
1776
1773
|
// src/handles/slot.ts
|
|
1777
1774
|
var HANDLES_SLOT = "ai-matrx.summon.handles";
|
|
1778
1775
|
|
|
1779
|
-
// src/
|
|
1776
|
+
// src/open/handleEntries.ts
|
|
1777
|
+
var import_global_slot3 = require("@ai-matrx/kit/global-slot");
|
|
1780
1778
|
var handlesState = () => (0, import_global_slot3.globalSlot)(HANDLES_SLOT, () => ({
|
|
1781
1779
|
callbacks: /* @__PURE__ */ new Map(),
|
|
1782
1780
|
groups: /* @__PURE__ */ new Map(),
|
|
1783
1781
|
owners: /* @__PURE__ */ new Map(),
|
|
1784
1782
|
registryListeners: /* @__PURE__ */ new Set()
|
|
1785
1783
|
}));
|
|
1784
|
+
function notifyHandlesRegistry() {
|
|
1785
|
+
for (const listener of [...handlesState().registryListeners]) listener();
|
|
1786
|
+
}
|
|
1787
|
+
function deleteHandleEntry(id, notify = true) {
|
|
1788
|
+
const s = handlesState();
|
|
1789
|
+
const entry = s.callbacks.get(id);
|
|
1790
|
+
if (!entry) return;
|
|
1791
|
+
s.callbacks.delete(id);
|
|
1792
|
+
if (entry.groupId !== void 0) {
|
|
1793
|
+
const group = s.groups.get(entry.groupId);
|
|
1794
|
+
group?.delete(id);
|
|
1795
|
+
if (group?.size === 0) s.groups.delete(entry.groupId);
|
|
1796
|
+
}
|
|
1797
|
+
if (entry.owner !== void 0) {
|
|
1798
|
+
const owned = s.owners.get(entry.owner);
|
|
1799
|
+
owned?.delete(id);
|
|
1800
|
+
if (owned?.size === 0) s.owners.delete(entry.owner);
|
|
1801
|
+
}
|
|
1802
|
+
if (notify) notifyHandlesRegistry();
|
|
1803
|
+
entry.onRemove?.();
|
|
1804
|
+
}
|
|
1805
|
+
function registerHandleEntry(slot2, options = {}) {
|
|
1806
|
+
const s = handlesState();
|
|
1807
|
+
const id = options.id ?? newHandleId();
|
|
1808
|
+
if (s.callbacks.has(id)) deleteHandleEntry(id, false);
|
|
1809
|
+
const entry = { callback: slot2 };
|
|
1810
|
+
if (options.context !== void 0) entry.context = options.context;
|
|
1811
|
+
if (options.groupId !== void 0) entry.groupId = options.groupId;
|
|
1812
|
+
if (options.owner !== void 0) entry.owner = options.owner;
|
|
1813
|
+
if (options.onRemove !== void 0) entry.onRemove = options.onRemove;
|
|
1814
|
+
s.callbacks.set(id, entry);
|
|
1815
|
+
if (options.groupId !== void 0) {
|
|
1816
|
+
const group = s.groups.get(options.groupId) ?? /* @__PURE__ */ new Set();
|
|
1817
|
+
group.add(id);
|
|
1818
|
+
s.groups.set(options.groupId, group);
|
|
1819
|
+
}
|
|
1820
|
+
if (options.owner !== void 0) {
|
|
1821
|
+
const owned = s.owners.get(options.owner) ?? /* @__PURE__ */ new Set();
|
|
1822
|
+
owned.add(id);
|
|
1823
|
+
s.owners.set(options.owner, owned);
|
|
1824
|
+
}
|
|
1825
|
+
notifyHandlesRegistry();
|
|
1826
|
+
return id;
|
|
1827
|
+
}
|
|
1828
|
+
function removeHandleGroup(groupId) {
|
|
1829
|
+
const s = handlesState();
|
|
1830
|
+
const group = s.groups.get(groupId);
|
|
1831
|
+
if (!group) return;
|
|
1832
|
+
s.groups.delete(groupId);
|
|
1833
|
+
for (const id of [...group]) deleteHandleEntry(id, false);
|
|
1834
|
+
notifyHandlesRegistry();
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
// src/handles/callbackManager.ts
|
|
1838
|
+
var handlesState2 = () => handlesState();
|
|
1786
1839
|
function invoke(slot2, data, context) {
|
|
1787
1840
|
if (typeof slot2 !== "function") return void 0;
|
|
1788
1841
|
return slot2(data, context);
|
|
@@ -1792,7 +1845,7 @@ function invokeListener(listener, data, context) {
|
|
|
1792
1845
|
}
|
|
1793
1846
|
var CallbackManager = class {
|
|
1794
1847
|
get s() {
|
|
1795
|
-
return
|
|
1848
|
+
return handlesState2();
|
|
1796
1849
|
}
|
|
1797
1850
|
/**
|
|
1798
1851
|
* Observe the registry itself: `listener` runs after any entry is added or removed. This lets a
|
|
@@ -1806,7 +1859,7 @@ var CallbackManager = class {
|
|
|
1806
1859
|
};
|
|
1807
1860
|
}
|
|
1808
1861
|
notifyRegistry() {
|
|
1809
|
-
|
|
1862
|
+
notifyHandlesRegistry();
|
|
1810
1863
|
}
|
|
1811
1864
|
/** Register a callback; returns its id. */
|
|
1812
1865
|
register(callback) {
|
|
@@ -1818,27 +1871,7 @@ var CallbackManager = class {
|
|
|
1818
1871
|
}
|
|
1819
1872
|
/** @internal The one insertion path (typed helpers pass a fixed id and a removal hook). */
|
|
1820
1873
|
registerEntry(slot2, options) {
|
|
1821
|
-
|
|
1822
|
-
const callbackId = options.id ?? newHandleId();
|
|
1823
|
-
if (s.callbacks.has(callbackId)) this.deleteEntry(callbackId, false);
|
|
1824
|
-
const entry = { callback: slot2 };
|
|
1825
|
-
if (options.context !== void 0) entry.context = options.context;
|
|
1826
|
-
if (options.groupId !== void 0) entry.groupId = options.groupId;
|
|
1827
|
-
if (options.owner !== void 0) entry.owner = options.owner;
|
|
1828
|
-
if (options.onRemove !== void 0) entry.onRemove = options.onRemove;
|
|
1829
|
-
s.callbacks.set(callbackId, entry);
|
|
1830
|
-
if (options.groupId !== void 0) {
|
|
1831
|
-
const group = s.groups.get(options.groupId) ?? /* @__PURE__ */ new Set();
|
|
1832
|
-
group.add(callbackId);
|
|
1833
|
-
s.groups.set(options.groupId, group);
|
|
1834
|
-
}
|
|
1835
|
-
if (options.owner !== void 0) {
|
|
1836
|
-
const owned = s.owners.get(options.owner) ?? /* @__PURE__ */ new Set();
|
|
1837
|
-
owned.add(callbackId);
|
|
1838
|
-
s.owners.set(options.owner, owned);
|
|
1839
|
-
}
|
|
1840
|
-
this.notifyRegistry();
|
|
1841
|
-
return callbackId;
|
|
1874
|
+
return registerHandleEntry(slot2, options);
|
|
1842
1875
|
}
|
|
1843
1876
|
/** Subscribe to results for a callback id. */
|
|
1844
1877
|
subscribe(callbackId, listener) {
|
|
@@ -1956,12 +1989,7 @@ var CallbackManager = class {
|
|
|
1956
1989
|
}
|
|
1957
1990
|
/** Remove a group and all its callbacks. */
|
|
1958
1991
|
removeGroup(groupId) {
|
|
1959
|
-
|
|
1960
|
-
const group = s.groups.get(groupId);
|
|
1961
|
-
if (!group) return;
|
|
1962
|
-
s.groups.delete(groupId);
|
|
1963
|
-
for (const callbackId of [...group]) this.deleteEntry(callbackId, false);
|
|
1964
|
-
this.notifyRegistry();
|
|
1992
|
+
removeHandleGroup(groupId);
|
|
1965
1993
|
}
|
|
1966
1994
|
/** Remove everything registered with `owner` (an InstanceKey). Returns how many were removed. */
|
|
1967
1995
|
disposeOwner(owner) {
|
|
@@ -1991,22 +2019,7 @@ var CallbackManager = class {
|
|
|
1991
2019
|
* (the old `removeFromGroups`-after-delete bug), then runs the entry's removal hook.
|
|
1992
2020
|
*/
|
|
1993
2021
|
deleteEntry(callbackId, notify) {
|
|
1994
|
-
|
|
1995
|
-
const entry = s.callbacks.get(callbackId);
|
|
1996
|
-
if (!entry) return;
|
|
1997
|
-
s.callbacks.delete(callbackId);
|
|
1998
|
-
if (entry.groupId !== void 0) {
|
|
1999
|
-
const group = s.groups.get(entry.groupId);
|
|
2000
|
-
group?.delete(callbackId);
|
|
2001
|
-
if (group?.size === 0) s.groups.delete(entry.groupId);
|
|
2002
|
-
}
|
|
2003
|
-
if (entry.owner !== void 0) {
|
|
2004
|
-
const owned = s.owners.get(entry.owner);
|
|
2005
|
-
owned?.delete(callbackId);
|
|
2006
|
-
if (owned?.size === 0) s.owners.delete(entry.owner);
|
|
2007
|
-
}
|
|
2008
|
-
if (notify) this.notifyRegistry();
|
|
2009
|
-
entry.onRemove?.();
|
|
2022
|
+
deleteHandleEntry(callbackId, notify);
|
|
2010
2023
|
}
|
|
2011
2024
|
};
|
|
2012
2025
|
var callbackManager = new CallbackManager();
|