diff options
| author | Adam Malczewski <[email protected]> | 2026-06-27 01:09:39 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-27 01:09:39 +0900 |
| commit | 61e45e60d699ed1ca46f94a8f181c92a940317c6 (patch) | |
| tree | 2892d9773c5a8e367e1e58cdb1e88d9c6ad3fe6d /packages/message-queue/src/pure.ts | |
| parent | 63c7e64532e85e0bbdd6d9ac6825d8f86be98e7a (diff) | |
| parent | 727c98c9dae516a2070eb950410314380a20c974 (diff) | |
| download | dispatch-61e45e60d699ed1ca46f94a8f181c92a940317c6.tar.gz dispatch-61e45e60d699ed1ca46f94a8f181c92a940317c6.zip | |
Merge branch 'feature/indent-change' into dev
Diffstat (limited to 'packages/message-queue/src/pure.ts')
| -rw-r--r-- | packages/message-queue/src/pure.ts | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/packages/message-queue/src/pure.ts b/packages/message-queue/src/pure.ts index 834018b..981e005 100644 --- a/packages/message-queue/src/pure.ts +++ b/packages/message-queue/src/pure.ts @@ -17,10 +17,10 @@ export type MessageQueueState = Map<string, QueuedMessage[]>; /** Injected effectful factories kept out of the pure core. */ export interface QueueDeps { - /** Stable (client-visible) id factory for UI keying + dedup. */ - readonly id: () => string; - /** Clock returning epoch-ms for `queuedAt`. */ - readonly now: () => number; + /** Stable (client-visible) id factory for UI keying + dedup. */ + readonly id: () => string; + /** Clock returning epoch-ms for `queuedAt`. */ + readonly now: () => number; } /** Surface id this extension contributes (also the manifest + catalog id). */ @@ -34,19 +34,19 @@ export const MESSAGE_QUEUE_RENDERER_ID = "message-queue"; * live state through the returned value. */ export function enqueue( - state: MessageQueueState, - conversationId: string, - text: string, - deps: QueueDeps, + state: MessageQueueState, + conversationId: string, + text: string, + deps: QueueDeps, ): QueuedMessage[] { - const message: QueuedMessage = { id: deps.id(), text, queuedAt: deps.now() }; - const existing = state.get(conversationId); - if (existing === undefined) { - state.set(conversationId, [message]); - } else { - existing.push(message); - } - return getQueue(state, conversationId); + const message: QueuedMessage = { id: deps.id(), text, queuedAt: deps.now() }; + const existing = state.get(conversationId); + if (existing === undefined) { + state.set(conversationId, [message]); + } else { + existing.push(message); + } + return getQueue(state, conversationId); } /** @@ -54,9 +54,9 @@ export function enqueue( * if the conversation has no queue / is unknown. */ export function getQueue(state: MessageQueueState, conversationId: string): QueuedMessage[] { - const existing = state.get(conversationId); - if (existing === undefined) return []; - return [...existing]; + const existing = state.get(conversationId); + if (existing === undefined) return []; + return [...existing]; } /** @@ -67,11 +67,11 @@ export function getQueue(state: MessageQueueState, conversationId: string): Queu * ChatMessage. */ export function drain(state: MessageQueueState, conversationId: string): QueuedMessage[] { - const existing = state.get(conversationId); - if (existing === undefined || existing.length === 0) return []; - const drained = [...existing]; - state.delete(conversationId); - return drained; + const existing = state.get(conversationId); + if (existing === undefined || existing.length === 0) return []; + const drained = [...existing]; + state.delete(conversationId); + return drained; } /** @@ -80,7 +80,7 @@ export function drain(state: MessageQueueState, conversationId: string): QueuedM * ChatMessage from this. */ export function combine(messages: readonly QueuedMessage[]): string { - return messages.map((m) => m.text).join("\n\n"); + return messages.map((m) => m.text).join("\n\n"); } /** @@ -90,16 +90,16 @@ export function combine(messages: readonly QueuedMessage[]): string { * I/O; the surface-registry re-fetches this on every notify. */ export function buildQueueSpec(messages: readonly QueuedMessage[]): SurfaceSpec { - const payload: QueuePayload = { messages }; - const field: CustomField = { - kind: "custom", - rendererId: MESSAGE_QUEUE_RENDERER_ID, - payload, - }; - return { - id: MESSAGE_QUEUE_SURFACE_ID, - region: "side", - title: "Message Queue", - fields: [field], - }; + const payload: QueuePayload = { messages }; + const field: CustomField = { + kind: "custom", + rendererId: MESSAGE_QUEUE_RENDERER_ID, + payload, + }; + return { + id: MESSAGE_QUEUE_SURFACE_ID, + region: "side", + title: "Message Queue", + fields: [field], + }; } |
