@mgamadeus/ddd-agents 0.1.1 → 0.1.2
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/README.md +100 -0
- package/dist/chat.js +132 -111
- package/dist/chat.js.map +1 -1
- package/dist/chunks/{ConversationMessageInputComposerWidgets-BO3jS0eZ.js → ConversationMessageInputComposerWidgets-r_RwCqr7.js} +11 -8
- package/dist/chunks/ConversationMessageInputComposerWidgets-r_RwCqr7.js.map +1 -0
- package/dist/chunks/{WebSearchResultsConversationWidget-H6cbTapV.js → WebSearchResultsConversationWidget-BXt98hGu.js} +161 -102
- package/dist/chunks/WebSearchResultsConversationWidget-BXt98hGu.js.map +1 -0
- package/dist/chunks/{canvas-behaviours-AvzKSYyv.js → canvas-behaviours-BpN_1xdZ.js} +2 -2
- package/dist/chunks/{canvas-behaviours-AvzKSYyv.js.map → canvas-behaviours-BpN_1xdZ.js.map} +1 -1
- package/dist/chunks/{canvas-reducers-Cdxt8yDF.js → canvas-reducers-CuX6L1zg.js} +3 -3
- package/dist/chunks/{canvas-reducers-Cdxt8yDF.js.map → canvas-reducers-CuX6L1zg.js.map} +1 -1
- package/dist/chunks/{canvasBodies-CsLrZ-M-.js → canvasBodies-Ds-cTn47.js} +9 -6
- package/dist/chunks/{canvasBodies-CsLrZ-M-.js.map → canvasBodies-Ds-cTn47.js.map} +1 -1
- package/dist/chunks/{canvasStorage-EvQsGdto.js → canvasStorage-DHNluopA.js} +2 -2
- package/dist/chunks/{canvasStorage-EvQsGdto.js.map → canvasStorage-DHNluopA.js.map} +1 -1
- package/dist/chunks/compose-attachment-message-text-FvVJbrge.js +8 -0
- package/dist/chunks/compose-attachment-message-text-FvVJbrge.js.map +1 -0
- package/dist/chunks/{contract-BxmMxYPF.js → contract-Z08LBOqt.js} +4 -3
- package/dist/chunks/contract-Z08LBOqt.js.map +1 -0
- package/dist/chunks/conversation-BEF0aesf.js.map +1 -1
- package/dist/chunks/host-color-scheme-Jhb7JZR7.js +30 -0
- package/dist/chunks/host-color-scheme-Jhb7JZR7.js.map +1 -0
- package/dist/chunks/{index-7Qc_3GbG.js → link-navigation-DyTApNeA.js} +156 -73
- package/dist/chunks/link-navigation-DyTApNeA.js.map +1 -0
- package/dist/chunks/text-key-DnoZ4lAk.js +6 -0
- package/dist/chunks/text-key-DnoZ4lAk.js.map +1 -0
- package/dist/chunks/{widget-click-signal-sources-1gIs1yiN.js → widget-click-signal-sources-Ch-y8gxw.js} +9 -5
- package/dist/chunks/{widget-click-signal-sources-1gIs1yiN.js.map → widget-click-signal-sources-Ch-y8gxw.js.map} +1 -1
- package/dist/chunks/{widget-image-readiness-signal-D3ci53xr.js → widget-image-readiness-signal-C5yaKpJJ.js} +2 -2
- package/dist/chunks/{widget-image-readiness-signal-D3ci53xr.js.map → widget-image-readiness-signal-C5yaKpJJ.js.map} +1 -1
- package/dist/chunks/{widget-name-resolver-D_ZzXy-Q.js → widget-name-resolver-DboFMAq2.js} +25 -25
- package/dist/chunks/widget-name-resolver-DboFMAq2.js.map +1 -0
- package/dist/chunks/{withPollingChangeSubscription-B16htQGd.js → withPollingChangeSubscription-CNXgt3Ri.js} +6 -2
- package/dist/chunks/withPollingChangeSubscription-CNXgt3Ri.js.map +1 -0
- package/dist/client-testing.js +6 -7
- package/dist/client-testing.js.map +1 -1
- package/dist/client.js +431 -2
- package/dist/client.js.map +1 -1
- package/dist/contract.js +1 -1
- package/dist/files/chat/Conversation.module.scss +1 -1
- package/dist/files/chat/ConversationViewBody/ConversationViewBody.module.scss +1 -1
- package/dist/files/i18n-keys.json +1617 -0
- package/dist/files/image-render/WidgetImageRender.module.scss +9 -3
- package/dist/files/styles/_surfaces.scss +6 -6
- package/dist/image-render.js +7 -7
- package/dist/index.js +64 -55
- package/dist/index.js.map +1 -1
- package/dist/kit.js +2 -2
- package/dist/preview.js +8 -8
- package/dist/provider.js +61 -52
- package/dist/provider.js.map +1 -1
- package/dist/renderer.js +16 -15
- package/dist/styles.css +170 -107
- package/dist/types/chat/AgentChat/AgentChat.d.ts +6 -0
- package/dist/types/chat/controller/AgentChatController.d.ts +28 -1
- package/dist/types/client/AgentsConversationClient.d.ts +7 -1
- package/dist/types/client/compose-attachment-message-text.d.ts +7 -0
- package/dist/types/client/http/agents-http-mappers.d.ts +23 -0
- package/dist/types/client/http/agents-http-wire.d.ts +188 -0
- package/dist/types/client/http/createAgentsHttpConversationClient.d.ts +55 -0
- package/dist/types/client/polling/createPollingConversationChangeSubscription.d.ts +7 -4
- package/dist/types/client/polling/withPollingChangeSubscription.d.ts +3 -2
- package/dist/types/contract/conversation.d.ts +8 -0
- package/dist/types/entries/chat.d.ts +2 -1
- package/dist/types/entries/client.d.ts +4 -0
- package/dist/types/entries/renderer.d.ts +1 -0
- package/dist/types/entries/widgets.d.ts +1 -1
- package/dist/types/provider/components/types.d.ts +5 -2
- package/dist/types/provider/environment.d.ts +13 -0
- package/dist/types/provider/host-color-scheme.d.ts +24 -0
- package/dist/types/provider/index.d.ts +4 -0
- package/dist/types/provider/link-navigation.d.ts +28 -0
- package/dist/types/provider/text-key.d.ts +6 -0
- package/dist/types/renderer/MarkdownLink.d.ts +8 -6
- package/dist/types/widgets/CanvasLauncherWidget/use-canvas-viable.d.ts +43 -9
- package/dist/types/widgets/EntityMentionConversationWidget/shared/entity-mention-presentation.d.ts +1 -1
- package/dist/types/widgets/_shared/modern/WidgetKpiValue.d.ts +2 -1
- package/dist/widgets.js +43 -40
- package/package.json +4 -2
- package/public-api.json +85 -18
- package/dist/chunks/ConversationMessageInputComposerWidgets-BO3jS0eZ.js.map +0 -1
- package/dist/chunks/WebSearchResultsConversationWidget-H6cbTapV.js.map +0 -1
- package/dist/chunks/contract-BxmMxYPF.js.map +0 -1
- package/dist/chunks/index-7Qc_3GbG.js.map +0 -1
- package/dist/chunks/widget-name-resolver-D_ZzXy-Q.js.map +0 -1
- package/dist/chunks/withPollingChangeSubscription-B16htQGd.js.map +0 -1
|
@@ -230,13 +230,17 @@ class PollingAgentsConversationClient {
|
|
|
230
230
|
this.getSelectableModels = binding.getSelectableModels?.bind(binding);
|
|
231
231
|
this.composeSentMessageText = binding.composeSentMessageText?.bind(binding);
|
|
232
232
|
this.getMessageSentPayload = binding.getMessageSentPayload?.bind(binding);
|
|
233
|
+
this.getConversationRunState = binding.getConversationRunState?.bind(binding);
|
|
233
234
|
}
|
|
234
235
|
}
|
|
235
236
|
const withPollingChangeSubscription = (client, options) => {
|
|
236
237
|
if (client.subscribeToConversationChanges) return client;
|
|
237
238
|
return new PollingAgentsConversationClient(
|
|
238
239
|
client,
|
|
239
|
-
createPollingConversationChangeSubscription(
|
|
240
|
+
createPollingConversationChangeSubscription(
|
|
241
|
+
client.getConversationRunState ? client.getConversationRunState.bind(client) : client.getConversationMetadata.bind(client),
|
|
242
|
+
options
|
|
243
|
+
)
|
|
240
244
|
);
|
|
241
245
|
};
|
|
242
246
|
export {
|
|
@@ -248,4 +252,4 @@ export {
|
|
|
248
252
|
readPolledRunStatus as r,
|
|
249
253
|
withPollingChangeSubscription as w
|
|
250
254
|
};
|
|
251
|
-
//# sourceMappingURL=withPollingChangeSubscription-
|
|
255
|
+
//# sourceMappingURL=withPollingChangeSubscription-CNXgt3Ri.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withPollingChangeSubscription-CNXgt3Ri.js","sources":["../../src/client/polling/createPollingConversationChangeSubscription.ts","../../src/client/polling/withPollingChangeSubscription.ts"],"sourcesContent":["import {\n type ConversationChangeSignal,\n type ConversationRunStateRead,\n type ConversationRunStatus,\n type ConversationSubscriptionEndReason,\n CONVERSATION_RUN_STATES_THAT_END_THE_CONVERSATION,\n isAgentsClientError,\n readConversationRunStatusOfRunState,\n} from \"../../contract/conversation\";\n\n/** Read interval while a turn runs (or right after a local send). */\nexport const POLLING_RUNNING_INTERVAL_MS = 2_000;\n/** Read interval while the conversation is idle or failed. */\nexport const POLLING_IDLE_INTERVAL_MS = 20_000;\n/** Ceiling of the exponential backoff after failed reads. */\nexport const POLLING_MAX_BACKOFF_MS = 60_000;\n/**\n * How long after a local send the poller keeps the running interval although the conversation still reads idle: the\n * server may store the owner's message before it marks the turn as running.\n */\nexport const POLLING_LOCAL_ACTIVITY_WINDOW_MS = 10_000;\n\n/**\n * Reads a conversation's run state — the port's `getConversationRunState`, or its `getConversationMetadata` (every\n * conversation carries the fields the poller reads).\n */\nexport type ConversationMetadataReader = (conversationId: number) => Promise<ConversationRunStateRead>;\n\n/** The timer functions the poller uses; a spec hands in fake ones. */\nexport interface PollingTimers {\n setTimeout: (callback: () => void, delayMs: number) => unknown;\n clearTimeout: (timerHandle: unknown) => void;\n now: () => number;\n}\n\n/** Whether the page is hidden, and a way to hear when that changes; a spec hands in its own. */\nexport interface PollingDocumentVisibility {\n isHidden: () => boolean;\n /** Calls `listener` on every visibility change; returns the function that stops it. */\n listen: (listener: () => void) => () => void;\n}\n\nexport interface PollingConversationChangeSubscriptionOptions {\n /** Default `POLLING_RUNNING_INTERVAL_MS` (2 s). */\n runningIntervalMs?: number;\n /** Default `POLLING_IDLE_INTERVAL_MS` (20 s). */\n idleIntervalMs?: number;\n /** Default `POLLING_MAX_BACKOFF_MS` (60 s). */\n maxBackoffMs?: number;\n /** Default `POLLING_LOCAL_ACTIVITY_WINDOW_MS` (10 s). */\n localActivityWindowMs?: number;\n /** Default: the global `setTimeout` / `clearTimeout` and `Date.now`. */\n timers?: PollingTimers;\n /** Default: the browser `document`; `null` = the page counts as always visible (no `document`, a worker). */\n documentVisibility?: PollingDocumentVisibility | null;\n}\n\n/**\n * The polling default of the live updates: the port's `subscribeToConversationChanges` plus\n * `notifyLocalActivity`, which `withPollingChangeSubscription` calls after every send the server accepted.\n */\nexport interface PollingConversationChangeSubscription {\n subscribeToConversationChanges: (\n conversationId: number,\n onSignal: (signal: ConversationChangeSignal) => void,\n onEnded: (reason: ConversationSubscriptionEndReason) => void,\n ) => () => void;\n /** Reads the conversation's metadata now and keeps the running interval for the local-activity window. */\n notifyLocalActivity: (conversationId: number) => void;\n}\n\ninterface ResolvedPollingOptions {\n runningIntervalMs: number;\n idleIntervalMs: number;\n maxBackoffMs: number;\n localActivityWindowMs: number;\n timers: PollingTimers;\n documentVisibility: PollingDocumentVisibility | null;\n}\n\n/** The global timer functions, looked up on each call (so a spec's fake timers installed later still apply). */\nclass GlobalPollingTimers implements PollingTimers {\n setTimeout = (callback: () => void, delayMs: number): unknown => globalThis.setTimeout(callback, delayMs);\n\n clearTimeout = (timerHandle: unknown): void => globalThis.clearTimeout(timerHandle as ReturnType<typeof setTimeout>);\n\n now = (): number => Date.now();\n}\n\n/** The browser document's `visibilityState` and `visibilitychange` event. */\nclass BrowserDocumentVisibility implements PollingDocumentVisibility {\n constructor(protected readonly browserDocument: Document) {}\n\n isHidden = (): boolean => this.browserDocument.visibilityState === \"hidden\";\n\n listen = (listener: () => void): (() => void) => {\n this.browserDocument.addEventListener(\"visibilitychange\", listener);\n return this.browserDocument.removeEventListener.bind(this.browserDocument, \"visibilitychange\", listener);\n };\n}\n\n/**\n * The three-value run status a polled read reports: the stored run state, and \"running\" for an idle conversation the\n * server owes a turn (`agentTurnOwedAt`), as the chat's own derivation does.\n */\nexport const readPolledRunStatus = (\n conversation: Pick<ConversationRunStateRead, \"runState\" | \"agentTurnOwedAt\">,\n): ConversationRunStatus | null => {\n const runStatus = readConversationRunStatusOfRunState(conversation.runState);\n return runStatus === \"idle\" && conversation.agentTurnOwedAt ? \"running\" : runStatus;\n};\n\n/** The end of a subscription a failed read means: a vanished conversation or lost access; null for a passing failure. */\nconst readSubscriptionEndReasonOfReadFailure = (failure: unknown): ConversationSubscriptionEndReason | null => {\n if (!isAgentsClientError(failure)) return null;\n if (failure.kind === \"notFound\") return \"gone\";\n if (failure.kind === \"forbidden\") return \"forbidden\";\n return null;\n};\n\n/**\n * One subscription: reads the conversation's metadata on a timer and turns each read into the change signal.\n *\n * Numbering (the signal leaves it open; the metadata carries no server change counter): the poller keeps its own counter. It\n * starts at 0 with the first read and advances by one whenever a read differs from the previous one in the run status,\n * `lastMessageId` or `updated` — so every polled signal is an ordinary change signal (no `isStatusCheck`) and the\n * package rules apply unchanged: an advance reads the changed tail (throttled), a terminal status reads at once,\n * re-reads the metadata and converges on `lastMessageId`. A status check would carry only the run status as news and\n * would miss a new message under an unchanged status. Without `lastMessageId` in the metadata every poll of a running\n * turn counts as a change (the changed tail is read every poll). `summaryUpdatedAt` is a second local counter that\n * advances when `title` or `summary` changed. A read with no change emits nothing.\n */\nclass ConversationMetadataPoller {\n protected isStopped = false;\n protected isReading = false;\n protected readAgainAfterCurrentRead = false;\n protected timerHandle: unknown = null;\n protected consecutiveFailedReads = 0;\n protected changeCounter = 0;\n protected summaryRevision = 0;\n protected previousChangeFingerprint: string | null = null;\n protected previousSummaryFingerprint: string | null = null;\n protected runStatus: ConversationRunStatus | null = null;\n protected hasConversationEnded = false;\n protected runningIntervalUntil = 0;\n protected stopListeningToVisibility: (() => void) | null = null;\n\n constructor(\n readonly conversationId: number,\n protected readonly readMetadata: ConversationMetadataReader,\n protected readonly onSignal: (signal: ConversationChangeSignal) => void,\n protected readonly onEnded: (reason: ConversationSubscriptionEndReason) => void,\n protected readonly options: ResolvedPollingOptions,\n protected readonly activePollers: Set<ConversationMetadataPoller>,\n ) {}\n\n start = (): void => {\n this.activePollers.add(this);\n this.stopListeningToVisibility = this.options.documentVisibility?.listen(this.receiveVisibilityChange) ?? null;\n this.readNow();\n };\n\n /** The unsubscribe: no read, no timer and no signal after it; a read in flight is dropped. */\n stop = (): void => {\n this.isStopped = true;\n this.activePollers.delete(this);\n this.clearTimer();\n this.stopListeningToVisibility?.();\n this.stopListeningToVisibility = null;\n };\n\n receiveLocalActivity = (): void => {\n this.runningIntervalUntil = this.options.timers.now() + this.options.localActivityWindowMs;\n this.readNow();\n };\n\n /** Reads now; a read already in flight is followed by one more read instead (two reads never overlap). */\n protected readNow = (): void => {\n if (this.isStopped) return;\n if (this.isReading) {\n this.readAgainAfterCurrentRead = true;\n return;\n }\n this.clearTimer();\n this.isReading = true;\n void this.readMetadataOnce();\n };\n\n protected async readMetadataOnce(): Promise<void> {\n let conversation: ConversationRunStateRead;\n try {\n conversation = await this.readMetadata(this.conversationId);\n } catch (failure) {\n this.isReading = false;\n this.receiveReadFailure(failure);\n return;\n }\n this.isReading = false;\n if (this.isStopped) return;\n this.consecutiveFailedReads = 0;\n this.receiveConversation(conversation);\n this.continueAfterRead(this.readIntervalMs());\n }\n\n protected receiveConversation(conversation: ConversationRunStateRead): void {\n const runStatus = readPolledRunStatus(conversation);\n const reportsLastMessageId = conversation.lastMessageId !== undefined;\n const changeFingerprint = JSON.stringify([runStatus, conversation.lastMessageId ?? null, conversation.updated]);\n const summaryFingerprint = JSON.stringify([conversation.title, conversation.summary]);\n const isFirstRead = this.previousChangeFingerprint === null;\n const hasChanged =\n changeFingerprint !== this.previousChangeFingerprint || (!reportsLastMessageId && runStatus === \"running\");\n const hasSummaryChanged = !isFirstRead && summaryFingerprint !== this.previousSummaryFingerprint;\n if (!isFirstRead && hasChanged) this.changeCounter += 1;\n if (hasSummaryChanged) this.summaryRevision += 1;\n this.previousChangeFingerprint = changeFingerprint;\n this.previousSummaryFingerprint = summaryFingerprint;\n this.runStatus = runStatus;\n this.hasConversationEnded =\n conversation.runState !== null && CONVERSATION_RUN_STATES_THAT_END_THE_CONVERSATION.includes(conversation.runState);\n if (!isFirstRead && !hasChanged && !hasSummaryChanged) return;\n this.onSignal({\n changeCounter: this.changeCounter,\n lastMessageId: conversation.lastMessageId ?? null,\n runStatus,\n summaryUpdatedAt: this.summaryRevision,\n });\n }\n\n protected receiveReadFailure(failure: unknown): void {\n if (this.isStopped) return;\n const endReason = readSubscriptionEndReasonOfReadFailure(failure);\n if (endReason !== null) {\n this.stop();\n this.onEnded(endReason);\n return;\n }\n this.consecutiveFailedReads += 1;\n const backoffMs = this.readIntervalMs() * 2 ** this.consecutiveFailedReads;\n this.continueAfterRead(Math.min(backoffMs, this.options.maxBackoffMs));\n }\n\n protected continueAfterRead(nextReadDelayMs: number): void {\n if (this.readAgainAfterCurrentRead) {\n this.readAgainAfterCurrentRead = false;\n this.readNow();\n return;\n }\n // A completed or cancelled conversation changes no more: only a local send or the page's return reads it again.\n if (this.hasConversationEnded) return;\n this.scheduleRead(nextReadDelayMs);\n }\n\n protected readIntervalMs(): number {\n const isShortIntervalDue = this.runStatus === \"running\" || this.options.timers.now() < this.runningIntervalUntil;\n return isShortIntervalDue ? this.options.runningIntervalMs : this.options.idleIntervalMs;\n }\n\n /** Arms the next read — not while the page is hidden; its return reads at once. */\n protected scheduleRead(delayMs: number): void {\n this.clearTimer();\n if (this.isStopped || this.options.documentVisibility?.isHidden()) return;\n this.timerHandle = this.options.timers.setTimeout(this.readOnTimer, delayMs);\n }\n\n protected readOnTimer = (): void => {\n this.timerHandle = null;\n this.readNow();\n };\n\n protected receiveVisibilityChange = (): void => {\n if (this.isStopped) return;\n if (this.options.documentVisibility?.isHidden()) {\n this.clearTimer();\n return;\n }\n this.readNow();\n };\n\n protected clearTimer(): void {\n if (this.timerHandle === null) return;\n this.options.timers.clearTimeout(this.timerHandle);\n this.timerHandle = null;\n }\n}\n\n/** Every subscription of one polling default; `notifyLocalActivity` reaches the subscriptions of a conversation. */\nclass PollingConversationChangeSubscriptions implements PollingConversationChangeSubscription {\n protected readonly activePollers = new Set<ConversationMetadataPoller>();\n\n constructor(\n protected readonly readMetadata: ConversationMetadataReader,\n protected readonly options: ResolvedPollingOptions,\n ) {}\n\n subscribeToConversationChanges = (\n conversationId: number,\n onSignal: (signal: ConversationChangeSignal) => void,\n onEnded: (reason: ConversationSubscriptionEndReason) => void,\n ): (() => void) => {\n const poller = new ConversationMetadataPoller(\n conversationId,\n this.readMetadata,\n onSignal,\n onEnded,\n this.options,\n this.activePollers,\n );\n poller.start();\n return poller.stop;\n };\n\n notifyLocalActivity = (conversationId: number): void => {\n for (const poller of [...this.activePollers]) {\n if (poller.conversationId === conversationId) poller.receiveLocalActivity();\n }\n };\n}\n\nconst readDefaultDocumentVisibility = (): PollingDocumentVisibility | null =>\n typeof document === \"undefined\" ? null : new BrowserDocumentVisibility(document);\n\n/**\n * The polling default of `subscribeToConversationChanges` over a metadata read: every 2 s while a turn\n * runs, every 20 s while idle, at once after `notifyLocalActivity`; paused while the page is hidden and read once when\n * it shows again; exponential backoff on failed reads up to 60 s; a `notFound` / `forbidden` read ends the subscription\n * with `gone` / `forbidden`. One poller per subscription; see `ConversationMetadataPoller` for how a read becomes a\n * signal.\n */\nexport const createPollingConversationChangeSubscription = (\n readMetadata: ConversationMetadataReader,\n options: PollingConversationChangeSubscriptionOptions = {},\n): PollingConversationChangeSubscription =>\n new PollingConversationChangeSubscriptions(readMetadata, {\n runningIntervalMs: options.runningIntervalMs ?? POLLING_RUNNING_INTERVAL_MS,\n idleIntervalMs: options.idleIntervalMs ?? POLLING_IDLE_INTERVAL_MS,\n maxBackoffMs: options.maxBackoffMs ?? POLLING_MAX_BACKOFF_MS,\n localActivityWindowMs: options.localActivityWindowMs ?? POLLING_LOCAL_ACTIVITY_WINDOW_MS,\n timers: options.timers ?? new GlobalPollingTimers(),\n documentVisibility: options.documentVisibility === undefined ? readDefaultDocumentVisibility() : options.documentVisibility,\n });\n","import type { AgentsConversationClient } from \"../AgentsConversationClient\";\nimport type {\n AgentsConversation,\n ChangedConversationMessages,\n ChangedMessagesRequest,\n ConversationActivity,\n ConversationAttachmentReference,\n ConversationChangeSignal,\n ConversationListQueryOptions,\n ConversationMessageSearchHit,\n ConversationMessageSentPayload,\n ConversationMessagesPage,\n ConversationRunStateRead,\n ConversationSearchGroup,\n ConversationSearchOptions,\n ConversationSignal,\n ConversationSubscriptionEndReason,\n PostedMessage,\n SelectableModel,\n StartedConversation,\n} from \"../../contract/conversation\";\nimport {\n createPollingConversationChangeSubscription,\n type PollingConversationChangeSubscription,\n type PollingConversationChangeSubscriptionOptions,\n} from \"./createPollingConversationChangeSubscription\";\n\n/** A conversation client whose `subscribeToConversationChanges` is present. */\nexport type AgentsConversationClientWithChangeSubscription = AgentsConversationClient &\n Required<Pick<AgentsConversationClient, \"subscribeToConversationChanges\">>;\n\n/**\n * A binding without push, with the polling default as its subscription. Every port function goes to the binding; the\n * three that make the server start a turn on an existing conversation (post, signal, retry) tell the poller once the\n * server accepted them, so the first read does not wait for the idle interval. A start needs no notice: the chat\n * subscribes to the new conversation afterwards, and a subscription reads at once.\n */\nclass PollingAgentsConversationClient implements AgentsConversationClientWithChangeSubscription {\n readonly getSelectableModels?: () => Promise<SelectableModel[]>;\n readonly composeSentMessageText?: (text: string, attachments: ConversationAttachmentReference[] | undefined) => string;\n readonly getMessageSentPayload?: (conversationId: number, messageId: number) => Promise<ConversationMessageSentPayload>;\n readonly getConversationRunState?: (conversationId: number) => Promise<ConversationRunStateRead>;\n\n constructor(\n protected readonly binding: AgentsConversationClient,\n protected readonly polling: PollingConversationChangeSubscription,\n ) {\n // The optional functions exist exactly when the binding has them (the chat reads their presence).\n this.getSelectableModels = binding.getSelectableModels?.bind(binding);\n this.composeSentMessageText = binding.composeSentMessageText?.bind(binding);\n this.getMessageSentPayload = binding.getMessageSentPayload?.bind(binding);\n this.getConversationRunState = binding.getConversationRunState?.bind(binding);\n }\n\n getConversationMetadata = (conversationId: number): Promise<AgentsConversation> =>\n this.binding.getConversationMetadata(conversationId);\n\n getNewestMessagesPage = (conversationId: number, pageSize: number): Promise<ConversationMessagesPage> =>\n this.binding.getNewestMessagesPage(conversationId, pageSize);\n\n getOlderMessagesPage = (conversationId: number, beforeIndex: number, pageSize: number): Promise<ConversationMessagesPage> =>\n this.binding.getOlderMessagesPage(conversationId, beforeIndex, pageSize);\n\n getChangedMessages = (conversationId: number, request: ChangedMessagesRequest): Promise<ChangedConversationMessages> =>\n this.binding.getChangedMessages(conversationId, request);\n\n startConversation = (request: Parameters<AgentsConversationClient[\"startConversation\"]>[0]): Promise<StartedConversation> =>\n this.binding.startConversation(request);\n\n postMessage = async (\n conversationId: number,\n message: { text: string; model?: string; attachments?: ConversationAttachmentReference[] },\n ): Promise<PostedMessage> => {\n const postedMessage = await this.binding.postMessage(conversationId, message);\n this.polling.notifyLocalActivity(conversationId);\n return postedMessage;\n };\n\n injectSignal = async (conversationId: number, signal: ConversationSignal): Promise<void> => {\n await this.binding.injectSignal(conversationId, signal);\n this.polling.notifyLocalActivity(conversationId);\n };\n\n retryConversation = async (conversationId: number): Promise<void> => {\n await this.binding.retryConversation(conversationId);\n this.polling.notifyLocalActivity(conversationId);\n };\n\n renameConversation = (conversationId: number, title: string): Promise<AgentsConversation> =>\n this.binding.renameConversation(conversationId, title);\n\n deleteConversation = (conversationId: number): Promise<void> => this.binding.deleteConversation(conversationId);\n\n listConversations = (agentSpaceKey: number, options?: ConversationListQueryOptions): Promise<AgentsConversation[]> =>\n this.binding.listConversations(agentSpaceKey, options);\n\n searchConversations = (text: string, options?: ConversationSearchOptions): Promise<ConversationSearchGroup[]> =>\n this.binding.searchConversations(text, options);\n\n searchConversationMessages = (\n conversationId: number,\n text: string,\n options?: ConversationSearchOptions,\n ): Promise<ConversationMessageSearchHit[]> => this.binding.searchConversationMessages(conversationId, text, options);\n\n getConversationActivity = (conversationId: number, turnMessageId?: number | null): Promise<ConversationActivity> =>\n this.binding.getConversationActivity(conversationId, turnMessageId);\n\n subscribeToConversationChanges = (\n conversationId: number,\n onSignal: (signal: ConversationChangeSignal) => void,\n onEnded: (reason: ConversationSubscriptionEndReason) => void,\n ): (() => void) => this.polling.subscribeToConversationChanges(conversationId, onSignal, onEnded);\n}\n\n/**\n * The client with live updates: a client that brings its own `subscribeToConversationChanges` (a push\n * transport — the host application's Firebase binding) is returned as it is; any other gets the polling default over its\n * `getConversationRunState` when it has one, else over its `getConversationMetadata`\n * (`createPollingConversationChangeSubscription`, `options` tune the intervals). A post, a signal or a retry the server\n * accepted reads at once. The default `AgentChat` calls this by itself.\n */\nexport const withPollingChangeSubscription = (\n client: AgentsConversationClient,\n options?: PollingConversationChangeSubscriptionOptions,\n): AgentsConversationClientWithChangeSubscription => {\n if (client.subscribeToConversationChanges) return client as AgentsConversationClientWithChangeSubscription;\n return new PollingAgentsConversationClient(\n client,\n createPollingConversationChangeSubscription(\n client.getConversationRunState ? client.getConversationRunState.bind(client) : client.getConversationMetadata.bind(client),\n options,\n ),\n );\n};\n"],"names":[],"mappings":";;AAWO,MAAM,8BAA8B;AAEpC,MAAM,2BAA2B;AAEjC,MAAM,yBAAyB;AAK/B,MAAM,mCAAmC;AA6DhD,MAAM,oBAA6C;AAAA,EAAnD,cAAA;AACE,SAAA,aAAa,CAAC,UAAsB,YAA6B,WAAW,WAAW,UAAU,OAAO;AAExG,SAAA,eAAe,CAAC,gBAA+B,WAAW,aAAa,WAA4C;AAEnH,SAAA,MAAM,MAAc,KAAK,IAAA;AAAA,EAAI;AAC/B;AAGA,MAAM,0BAA+D;AAAA,EACnE,YAA+B,iBAA2B;AAA3B,SAAA,kBAAA;AAE/B,SAAA,WAAW,MAAe,KAAK,gBAAgB,oBAAoB;AAEnE,SAAA,SAAS,CAAC,aAAuC;AAC/C,WAAK,gBAAgB,iBAAiB,oBAAoB,QAAQ;AAClE,aAAO,KAAK,gBAAgB,oBAAoB,KAAK,KAAK,iBAAiB,oBAAoB,QAAQ;AAAA,IACzG;AAAA,EAP2D;AAQ7D;AAMO,MAAM,sBAAsB,CACjC,iBACiC;AACjC,QAAM,YAAY,oCAAoC,aAAa,QAAQ;AAC3E,SAAO,cAAc,UAAU,aAAa,kBAAkB,YAAY;AAC5E;AAGA,MAAM,yCAAyC,CAAC,YAA+D;AAC7G,MAAI,CAAC,oBAAoB,OAAO,EAAG,QAAO;AAC1C,MAAI,QAAQ,SAAS,WAAY,QAAO;AACxC,MAAI,QAAQ,SAAS,YAAa,QAAO;AACzC,SAAO;AACT;AAcA,MAAM,2BAA2B;AAAA,EAe/B,YACW,gBACU,cACA,UACA,SACA,SACA,eACnB;AANS,SAAA,iBAAA;AACU,SAAA,eAAA;AACA,SAAA,WAAA;AACA,SAAA,UAAA;AACA,S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kB,cAAc;AACnD,WAAK,QAAQ,oBAAoB,cAAc;AAAA,IACjD;AAEA,SAAA,qBAAqB,CAAC,gBAAwB,UAC5C,KAAK,QAAQ,mBAAmB,gBAAgB,KAAK;AAEvD,SAAA,qBAAqB,CAAC,mBAA0C,KAAK,QAAQ,mBAAmB,cAAc;AAE9G,SAAA,oBAAoB,CAAC,eAAuB,YAC1C,KAAK,QAAQ,kBAAkB,eAAe,OAAO;AAEvD,SAAA,sBAAsB,CAAC,MAAc,YACnC,KAAK,QAAQ,oBAAoB,MAAM,OAAO;AAEhD,SAAA,6BAA6B,CAC3B,gBACA,MACA,YAC4C,KAAK,QAAQ,2BAA2B,gBAAgB,MAAM,OAAO;AAEnH,SAAA,0BAA0B,CAAC,gBAAwB,kBACjD,KAAK,QAAQ,wBAAwB,gBAAgB,aAAa;AAEpE,SAAA,iCAAiC,CAC/B,gBACA,UACA,YACiB,KAAK,QAAQ,+BAA+B,gBAAgB,UAAU,OAAO;AAhE9F,SAAK,sBAAsB,QAAQ,qBAAqB,KAAK,OAAO;AACpE,SAAK,yBAAyB,QAAQ,wBAAwB,KAAK,OAAO;AAC1E,SAAK,wBAAwB,QAAQ,uBAAuB,KAAK,OAAO;AACxE,SAAK,0BAA0B,QAAQ,yBAAyB,KAAK,OAAO;AAAA,EAC9E;AA6DF;AASO,MAAM,gCAAgC,CAC3C,QACA,YACmD;AACnD,MAAI,OAAO,+BAAgC,QAAO;AAClD,SAAO,IAAI;AAAA,IACT;AAAA,IACA;AAAA,MACE,OAAO,0BAA0B,OAAO,wBAAwB,KAAK,MAAM,IAAI,OAAO,wBAAwB,KAAK,MAAM;AAAA,MACzH;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
package/dist/client-testing.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { A as AgentsClientError, C as CONVERSATION_RUN_STATES_THAT_END_THE_CONVERSATION, r as readConversationRunStatusOfRunState } from "./chunks/conversation-BEF0aesf.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { c as composeAttachmentMessageText } from "./chunks/compose-attachment-message-text-FvVJbrge.js";
|
|
4
|
+
import { l as listWidgetHydratorTypes, g as getWidgetHydrator, b as registerWidgetHydrator, c as abandonWidgetHydrationReads, u as unregisterWidgetHydrator } from "./chunks/WebSearchResultsConversationWidget-BXt98hGu.js";
|
|
5
|
+
import { j as conversationWidgetRegistry, k as replaceConversationWidgetRegistryEntries } from "./chunks/widget-name-resolver-DboFMAq2.js";
|
|
6
|
+
import { l, s } from "./chunks/widget-name-resolver-DboFMAq2.js";
|
|
7
|
+
import { c, r, s as s2 } from "./chunks/canvasStorage-DHNluopA.js";
|
|
7
8
|
const DEFAULT_SCRIPTED_ASSISTANT_ANSWER = "Done.";
|
|
8
9
|
const DEFAULT_PAGE_SIZE = 50;
|
|
9
10
|
const copyOf = (value) => JSON.parse(JSON.stringify(value));
|
|
10
11
|
const sortByIndexAscending = (messages) => [...messages].sort((first, second) => (first.indexInConversation ?? 0) - (second.indexInConversation ?? 0));
|
|
11
12
|
const textContains = (text, searchText) => (text ?? "").toLowerCase().includes(searchText.trim().toLowerCase());
|
|
12
|
-
const buildStoredMessageText =
|
|
13
|
-
|
|
14
|
-
${attachments.map((attachment) => `[Attached file: ${attachment.fileName ?? "file"} — ${attachment.publicUrl ?? ""}]`).join("\n")}` : text;
|
|
13
|
+
const buildStoredMessageText = composeAttachmentMessageText;
|
|
15
14
|
class InMemoryAgentsConversationClient {
|
|
16
15
|
constructor(data) {
|
|
17
16
|
this.recordsByConversationId = /* @__PURE__ */ new Map();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-testing.js","sources":["../src/client/testing/createInMemoryAgentsConversationClient.ts","../src/client/testing/widget-hydration-stand-ins.ts","../src/client/testing/test-conversation-widgets.ts"],"sourcesContent":["import type { AgentsConversationClient, AgentsConversationOperation } from \"../AgentsConversationClient\";\nimport {\n AgentsClientError,\n type AgentsConversation,\n type AgentsConversationMessage,\n type ChangedConversationMessages,\n type ChangedMessagesRequest,\n type ConversationActivity,\n type ConversationAttachmentReference,\n type ConversationChangeSignal,\n type ConversationListQueryOptions,\n type ConversationMessageSearchHit,\n type ConversationMessageSentPayload,\n type ConversationMessagesPage,\n type ConversationRunStatus,\n CONVERSATION_RUN_STATES_THAT_END_THE_CONVERSATION,\n type ConversationSearchGroup,\n type ConversationSearchOptions,\n type ConversationSignal,\n type ConversationSubscriptionEndReason,\n type PostedMessage,\n readConversationRunStatusOfRunState,\n type SelectableModel,\n type StartedConversation,\n} from \"../../contract/conversation\";\n\n/** One recorded conversation handed to the in-memory client: plain data, as a fixture file holds it. */\nexport interface RecordedConversation {\n conversation: AgentsConversation;\n messages: AgentsConversationMessage[];\n /** What `getConversationActivity` answers for this conversation; an empty, finished turn when omitted. */\n activity?: ConversationActivity;\n}\n\nexport interface InMemoryAgentsConversationClientData {\n conversations: RecordedConversation[];\n /**\n * The assistant's answers to a post, an injected signal, a start or a retry, used in order; the last one repeats.\n * Default: one answer, \"Done.\".\n */\n scriptedAssistantAnswers?: string[];\n /** What `getSelectableModels` answers; the client has no `getSelectableModels` when omitted. */\n selectableModels?: SelectableModel[];\n /** The page size of `getChangedMessages` when the request names none. Default 50. */\n defaultPageSize?: number;\n /** What `getMessageSentPayload` answers, by message id; the client has no `getMessageSentPayload` when omitted. */\n sentPayloadsByMessageId?: Record<number, ConversationMessageSentPayload>;\n /**\n * The assistant answers this many milliseconds after the send, like a server's turn: the run state is RUNNING\n * meanwhile, then the answer is stored and the run state goes back to IDLE — no `emit()` involved, so a poller sees it.\n * Default 0: the answer is stored together with the send.\n */\n assistantAnswerDelayMs?: number;\n /**\n * The client has no `subscribeToConversationChanges` — a backend without push. The chat then follows the\n * conversation through the polling default (`withPollingChangeSubscription`). Default false.\n */\n withoutChangeSubscription?: boolean;\n}\n\n/** A subscriber of one conversation's live updates. */\ninterface ConversationChangeSubscriber {\n onChange: (signal: ConversationChangeSignal) => void;\n onEnded: (reason: ConversationSubscriptionEndReason) => void;\n}\n\n/** The live-update state of one conversation. */\ninterface ConversationSignalState {\n changeCounter: number;\n summaryUpdatedAt: number | null;\n}\n\nconst DEFAULT_SCRIPTED_ASSISTANT_ANSWER = \"Done.\";\nconst DEFAULT_PAGE_SIZE = 50;\n\n/** A deep copy, so a caller can never change the client's records through a returned object. */\nconst copyOf = <T>(value: T): T => JSON.parse(JSON.stringify(value)) as T;\n\nconst sortByIndexAscending = (messages: AgentsConversationMessage[]): AgentsConversationMessage[] =>\n [...messages].sort((first, second) => (first.indexInConversation ?? 0) - (second.indexInConversation ?? 0));\n\nconst textContains = (text: string | null | undefined, searchText: string): boolean =>\n (text ?? \"\").toLowerCase().includes(searchText.trim().toLowerCase());\n\n/** The message text a send stores: the typed text plus one reference line per attachment (as the host application's chat sends it). */\nconst buildStoredMessageText = (text: string, attachments: ConversationAttachmentReference[] | undefined): string =>\n attachments?.length\n ? `${text}\\n\\n${attachments\n .map((attachment) => `[Attached file: ${attachment.fileName ?? \"file\"} — ${attachment.publicUrl ?? \"\"}]`)\n .join(\"\\n\")}`\n : text;\n\n/**\n * The conversation client over recorded conversations, for specs, stories and the reference app\n * (`./testing`). Behaves like the server where the chat can see it: a post stores the owner's message and, at once,\n * the next scripted assistant answer — but live updates are driven by hand: `emit()` sends the conversation's next\n * signal to its subscribers (counter advanced, newest message id, the run status), `end()` ends the subscriptions.\n * With `assistantAnswerDelayMs` the answer is stored later, as a server turn would (RUNNING meanwhile); with\n * `withoutChangeSubscription` the client has no subscription at all and the chat polls it.\n */\nexport class InMemoryAgentsConversationClient implements AgentsConversationClient {\n protected readonly recordsByConversationId = new Map<number, RecordedConversation>();\n protected readonly subscribersByConversationId = new Map<number, Set<ConversationChangeSubscriber>>();\n protected readonly signalStateByConversationId = new Map<number, ConversationSignalState>();\n protected readonly scriptedAssistantAnswers: string[];\n protected readonly defaultPageSize: number;\n protected readonly selectableModels: SelectableModel[] | undefined;\n protected readonly sentPayloadsByMessageId: Record<number, ConversationMessageSentPayload> | undefined;\n protected readonly assistantAnswerDelayMs: number;\n protected readonly requestCountsByOperation = new Map<AgentsConversationOperation, number>();\n protected scriptedAssistantAnswersUsed = 0;\n protected nextMessageId: number;\n protected nextConversationId: number;\n\n /** Present only when the data names selectable models (the port function is optional). */\n readonly getSelectableModels?: () => Promise<SelectableModel[]>;\n /** Present only when the data names sent payloads (the port function is optional). */\n readonly getMessageSentPayload?: (conversationId: number, messageId: number) => Promise<ConversationMessageSentPayload>;\n /** Present unless the data asks for a client without push (`withoutChangeSubscription`). */\n readonly subscribeToConversationChanges?: (\n conversationId: number,\n onChange: (signal: ConversationChangeSignal) => void,\n onEnded: (reason: ConversationSubscriptionEndReason) => void,\n ) => () => void;\n\n constructor(data: InMemoryAgentsConversationClientData) {\n for (const recordedConversation of copyOf(data.conversations)) {\n this.recordsByConversationId.set(recordedConversation.conversation.id, recordedConversation);\n }\n const scriptedAssistantAnswers = data.scriptedAssistantAnswers ?? [];\n this.scriptedAssistantAnswers =\n scriptedAssistantAnswers.length > 0 ? [...scriptedAssistantAnswers] : [DEFAULT_SCRIPTED_ASSISTANT_ANSWER];\n this.defaultPageSize = data.defaultPageSize ?? DEFAULT_PAGE_SIZE;\n this.selectableModels = data.selectableModels ? copyOf(data.selectableModels) : undefined;\n if (this.selectableModels) {\n this.getSelectableModels = this.readSelectableModels;\n }\n this.sentPayloadsByMessageId = data.sentPayloadsByMessageId ? copyOf(data.sentPayloadsByMessageId) : undefined;\n if (this.sentPayloadsByMessageId) {\n this.getMessageSentPayload = this.readMessageSentPayload;\n }\n this.assistantAnswerDelayMs = data.assistantAnswerDelayMs ?? 0;\n if (!data.withoutChangeSubscription) {\n this.subscribeToConversationChanges = this.subscribeToRecordedConversationChanges;\n }\n const allMessageIds = data.conversations.flatMap((recorded) => recorded.messages.map((message) => message.id));\n const allConversationIds = data.conversations.map((recorded) => recorded.conversation.id);\n this.nextMessageId = Math.max(0, ...allMessageIds) + 1;\n this.nextConversationId = Math.max(0, ...allConversationIds) + 1;\n }\n\n // ── Port ──────────────────────────────────────────────────────────────────────────────────────────────────────\n\n listConversations = async (\n agentSpaceKey: number,\n options: ConversationListQueryOptions = {},\n ): Promise<AgentsConversation[]> => {\n this.countRequest(\"listConversations\");\n const { includeUnsummarized = false, paging = {} } = options;\n const { top, skip = 0 } = paging;\n const conversationsOfAgentSpace = [...this.recordsByConversationId.values()]\n .map((recorded) => recorded.conversation)\n .filter((conversation) => conversation.agentSpaceKey === agentSpaceKey)\n .filter((conversation) => includeUnsummarized || conversation.title !== null)\n .sort((first, second) => second.id - first.id);\n const end = top === undefined ? undefined : skip + top;\n return copyOf(conversationsOfAgentSpace.slice(skip, end));\n };\n\n /** Account-wide, like the server: every recorded conversation is searched. */\n searchConversations = async (text: string, options: ConversationSearchOptions = {}): Promise<ConversationSearchGroup[]> => {\n this.countRequest(\"searchConversations\");\n const searchGroups: ConversationSearchGroup[] = [];\n for (const recorded of this.recordsByConversationId.values()) {\n const hits = this.findMessageSearchHits(recorded, text);\n if (hits.length === 0) continue;\n searchGroups.push({\n conversationId: recorded.conversation.id,\n title: recorded.conversation.title,\n summary: null,\n created: recorded.messages[0]?.createdDate ?? null,\n updated: recorded.messages[recorded.messages.length - 1]?.createdDate ?? null,\n relevance: 1,\n hits,\n });\n }\n return copyOf(searchGroups.slice(0, options.limit));\n };\n\n /** The stored conversation with `lastMessageId` (the newest stored message), as a backend without push answers it. */\n getConversationMetadata = async (conversationId: number): Promise<AgentsConversation> => {\n this.countRequest(\"getConversationMetadata\");\n const recorded = this.readRecord(conversationId);\n return copyOf({ ...recorded.conversation, lastMessageId: sortByIndexAscending(recorded.messages).pop()?.id ?? null });\n };\n\n getNewestMessagesPage = async (conversationId: number, pageSize: number): Promise<ConversationMessagesPage> => {\n this.countRequest(\"getNewestMessagesPage\");\n const newestFirst = this.readMessagesNewestFirst(conversationId);\n return copyOf({ messages: newestFirst.slice(0, pageSize), hasMoreOlder: newestFirst.length > pageSize });\n };\n\n getOlderMessagesPage = async (\n conversationId: number,\n beforeIndex: number,\n pageSize: number,\n ): Promise<ConversationMessagesPage> => {\n this.countRequest(\"getOlderMessagesPage\");\n const olderMessages = this.readMessagesNewestFirst(conversationId).filter(\n (message) => (message.indexInConversation ?? Number.MAX_SAFE_INTEGER) < beforeIndex,\n );\n return copyOf({ messages: olderMessages.slice(0, pageSize), hasMoreOlder: olderMessages.length > pageSize });\n };\n\n getChangedMessages = async (\n conversationId: number,\n request: ChangedMessagesRequest,\n ): Promise<ChangedConversationMessages> => {\n this.countRequest(\"getChangedMessages\");\n const changedMessages = this.readMessagesNewestFirst(conversationId).filter(\n (message) => message.id > request.highestKnownId || (message.indexInConversation ?? -1) >= request.fromIndex,\n );\n return copyOf({ messages: changedMessages.slice(0, request.pageSize ?? this.defaultPageSize) });\n };\n\n searchConversationMessages = async (\n conversationId: number,\n text: string,\n options: ConversationSearchOptions = {},\n ): Promise<ConversationMessageSearchHit[]> => {\n this.countRequest(\"searchConversationMessages\");\n return copyOf(this.findMessageSearchHits(this.readRecord(conversationId), text).slice(0, options.limit));\n };\n\n getConversationActivity = async (conversationId: number): Promise<ConversationActivity> => {\n this.countRequest(\"getConversationActivity\");\n return copyOf(this.readRecord(conversationId).activity ?? { turnMessageId: null, turnRunning: false, elements: [] });\n };\n\n startConversation = async (request: {\n agentSpaceKey: number;\n text: string;\n startSignalText?: string;\n entryPointKey?: string;\n model?: string;\n attachments?: ConversationAttachmentReference[];\n }): Promise<StartedConversation> => {\n this.countRequest(\"startConversation\");\n if (request.text === \"\" && !request.startSignalText) {\n throw new AgentsClientError(\"other\", { httpStatus: 400, message: \"A start needs a message or a signal.\" });\n }\n const reopenedConversation = request.entryPointKey\n ? [...this.recordsByConversationId.values()].find(\n (recorded) =>\n recorded.conversation.agentSpaceKey === request.agentSpaceKey &&\n recorded.conversation.entryPointKey === request.entryPointKey,\n )\n : undefined;\n if (reopenedConversation) {\n return { conversation: copyOf(reopenedConversation.conversation), messages: [], reopenedExisting: true };\n }\n const recorded: RecordedConversation = {\n conversation: {\n id: this.nextConversationId,\n agentSpaceKey: request.agentSpaceKey,\n runState: \"IDLE\",\n agentTurnOwedAt: null,\n title: null,\n titleManuallyEdited: false,\n summary: null,\n created: null,\n updated: null,\n purposeName: null,\n initiatorType: null,\n scheduleId: null,\n entryPointKey: request.entryPointKey ?? null,\n progressSteps: [],\n },\n messages: [],\n };\n this.nextConversationId += 1;\n this.recordsByConversationId.set(recorded.conversation.id, recorded);\n if (request.startSignalText) {\n this.appendMessage(recorded, { role: \"USER\", messageType: \"SIGNAL\", authorType: \"USER\", message: request.startSignalText });\n }\n if (request.text !== \"\") {\n this.appendMessage(recorded, {\n role: \"USER\",\n messageType: \"TEXT\",\n authorType: \"USER\",\n message: buildStoredMessageText(request.text, request.attachments),\n });\n }\n const messagesBeforeTheAnswer = copyOf(recorded.messages);\n this.appendScriptedAssistantAnswer(recorded);\n return { conversation: copyOf(recorded.conversation), messages: messagesBeforeTheAnswer, reopenedExisting: false };\n };\n\n postMessage = async (\n conversationId: number,\n message: { text: string; model?: string; attachments?: ConversationAttachmentReference[] },\n ): Promise<PostedMessage> => {\n this.countRequest(\"postMessage\");\n const recorded = this.readOpenRecord(conversationId);\n this.appendMessage(recorded, {\n role: \"USER\",\n messageType: \"TEXT\",\n authorType: \"USER\",\n message: buildStoredMessageText(message.text, message.attachments),\n });\n const messagesBeforeTheAnswer = copyOf(recorded.messages);\n this.appendScriptedAssistantAnswer(recorded);\n return { messages: messagesBeforeTheAnswer };\n };\n\n injectSignal = async (conversationId: number, signal: ConversationSignal): Promise<void> => {\n this.countRequest(\"injectSignal\");\n const recorded = this.readOpenRecord(conversationId);\n this.appendMessage(recorded, {\n role: \"USER\",\n messageType: \"SIGNAL\",\n authorType: \"USER\",\n message: signal.text,\n signalSource: signal.source ?? \"FRONTEND_WIDGET_CLICK\",\n });\n this.appendScriptedAssistantAnswer(recorded);\n };\n\n retryConversation = async (conversationId: number): Promise<void> => {\n this.countRequest(\"retryConversation\");\n const recorded = this.readRecord(conversationId);\n const newestMessage = sortByIndexAscending(recorded.messages).pop();\n if (newestMessage === undefined || newestMessage.role === \"ASSISTANT\") {\n throw new AgentsClientError(\"other\", { httpStatus: 400, message: \"Nothing to retry.\" });\n }\n this.appendScriptedAssistantAnswer(recorded);\n };\n\n renameConversation = async (conversationId: number, title: string): Promise<AgentsConversation> => {\n this.countRequest(\"renameConversation\");\n const recorded = this.readRecord(conversationId);\n recorded.conversation.title = title;\n recorded.conversation.titleManuallyEdited = true;\n return copyOf(recorded.conversation);\n };\n\n deleteConversation = async (conversationId: number): Promise<void> => {\n this.countRequest(\"deleteConversation\");\n this.readRecord(conversationId);\n this.recordsByConversationId.delete(conversationId);\n };\n\n /** The port's `subscribeToConversationChanges` unless `withoutChangeSubscription`; signals come from `emit()`. */\n protected subscribeToRecordedConversationChanges = (\n conversationId: number,\n onChange: (signal: ConversationChangeSignal) => void,\n onEnded: (reason: ConversationSubscriptionEndReason) => void,\n ): (() => void) => {\n const subscriber: ConversationChangeSubscriber = { onChange, onEnded };\n const subscribers = this.subscribersByConversationId.get(conversationId) ?? new Set<ConversationChangeSubscriber>();\n subscribers.add(subscriber);\n this.subscribersByConversationId.set(conversationId, subscribers);\n // Like the realtime database: the current value arrives at once, before any change.\n const record = this.recordsByConversationId.get(conversationId);\n if (record) {\n onChange(this.buildSignal(record, this.readSignalState(conversationId), null));\n }\n return () => {\n subscribers.delete(subscriber);\n };\n };\n\n // ── Driving live updates by hand ──────────────────────────────────────────────────────────────────────────────\n\n /**\n * Sends the conversation's next signal to its subscribers: the counter advances, `lastMessageId` is the newest\n * stored message, the run status follows the stored run state unless `runStatus` is given. `summaryChanged` also\n * advances `summaryUpdatedAt`. Returns the sent signal.\n */\n emit = (\n conversationId: number,\n change: { runStatus?: ConversationRunStatus; summaryChanged?: boolean } = {},\n ): ConversationChangeSignal => {\n const record = this.readRecord(conversationId);\n const signalState = this.readSignalState(conversationId);\n signalState.changeCounter += 1;\n if (change.summaryChanged) {\n signalState.summaryUpdatedAt = (signalState.summaryUpdatedAt ?? 0) + 1;\n }\n const signal = this.buildSignal(record, signalState, change.runStatus ?? null);\n for (const subscriber of [...(this.subscribersByConversationId.get(conversationId) ?? [])]) {\n subscriber.onChange(copyOf(signal));\n }\n return signal;\n };\n\n /** Ends every subscription of the conversation with `reason`, as the server's deletion or a lost access would. */\n end = (conversationId: number, reason: ConversationSubscriptionEndReason): void => {\n const subscribers = [...(this.subscribersByConversationId.get(conversationId) ?? [])];\n this.subscribersByConversationId.delete(conversationId);\n for (const subscriber of subscribers) {\n subscriber.onEnded(reason);\n }\n };\n\n /** Sets a conversation's stored run state (a turn that runs, fails, or a conversation that closes). */\n setRunState = (conversationId: number, runState: AgentsConversation[\"runState\"]): void => {\n this.readRecord(conversationId).conversation.runState = runState;\n };\n\n /**\n * How many requests the client answered — of one port function, or of all when `operation` is omitted (the\n * subscription is no request). For assertions such as \"no read after the chat unmounted\".\n */\n readRequestCount = (operation?: AgentsConversationOperation): number => {\n if (operation !== undefined) return this.requestCountsByOperation.get(operation) ?? 0;\n let requestCount = 0;\n for (const operationRequestCount of this.requestCountsByOperation.values()) requestCount += operationRequestCount;\n return requestCount;\n };\n\n /** Every stored message of a conversation in index order — for assertions. */\n readStoredMessages = (conversationId: number): AgentsConversationMessage[] =>\n copyOf(sortByIndexAscending(this.readRecord(conversationId).messages));\n\n // ── Internals ─────────────────────────────────────────────────────────────────────────────────────────────────\n\n protected countRequest(operation: AgentsConversationOperation): void {\n this.requestCountsByOperation.set(operation, (this.requestCountsByOperation.get(operation) ?? 0) + 1);\n }\n\n protected readSelectableModels = async (): Promise<SelectableModel[]> => {\n this.countRequest(\"getSelectableModels\");\n return copyOf(this.selectableModels ?? []);\n };\n\n protected readMessageSentPayload = async (\n conversationId: number,\n messageId: number,\n ): Promise<ConversationMessageSentPayload> => {\n this.countRequest(\"getMessageSentPayload\");\n this.readRecord(conversationId);\n const sentPayload = this.sentPayloadsByMessageId?.[messageId];\n if (sentPayload === undefined) {\n throw new AgentsClientError(\"notFound\", { httpStatus: 404, message: `No sent payload for message ${messageId}.` });\n }\n return copyOf(sentPayload);\n };\n\n protected readMessagesNewestFirst(conversationId: number): AgentsConversationMessage[] {\n return sortByIndexAscending(this.readRecord(conversationId).messages).reverse();\n }\n\n protected readRecord(conversationId: number): RecordedConversation {\n const recorded = this.recordsByConversationId.get(conversationId);\n if (!recorded) {\n throw new AgentsClientError(\"notFound\", { httpStatus: 404, message: `Conversation ${conversationId} not found.` });\n }\n return recorded;\n }\n\n /** The record of a conversation that still takes input; a completed or cancelled one refuses like the server. */\n protected readOpenRecord(conversationId: number): RecordedConversation {\n const recorded = this.readRecord(conversationId);\n const runState = recorded.conversation.runState;\n if (runState !== null && CONVERSATION_RUN_STATES_THAT_END_THE_CONVERSATION.includes(runState)) {\n throw new AgentsClientError(\"closed\", { httpStatus: 400, code: \"CONVERSATION_CLOSED\" });\n }\n return recorded;\n }\n\n protected readSignalState(conversationId: number): ConversationSignalState {\n const existingSignalState = this.signalStateByConversationId.get(conversationId);\n if (existingSignalState) return existingSignalState;\n const signalState: ConversationSignalState = { changeCounter: 0, summaryUpdatedAt: null };\n this.signalStateByConversationId.set(conversationId, signalState);\n return signalState;\n }\n\n protected buildSignal(\n recorded: RecordedConversation,\n signalState: ConversationSignalState,\n runStatus: ConversationRunStatus | null,\n ): ConversationChangeSignal {\n const newestMessage = sortByIndexAscending(recorded.messages).pop();\n return {\n changeCounter: signalState.changeCounter,\n lastMessageId: newestMessage?.id ?? null,\n runStatus: runStatus ?? readConversationRunStatusOfRunState(recorded.conversation.runState),\n summaryUpdatedAt: signalState.summaryUpdatedAt,\n };\n }\n\n protected appendMessage(\n recorded: RecordedConversation,\n fields: Pick<AgentsConversationMessage, \"role\" | \"messageType\" | \"authorType\" | \"message\"> &\n Partial<Pick<AgentsConversationMessage, \"signalSource\">>,\n ): AgentsConversationMessage {\n const highestIndex = Math.max(-1, ...recorded.messages.map((message) => message.indexInConversation ?? -1));\n const storedMessage: AgentsConversationMessage = {\n id: this.nextMessageId,\n conversationId: recorded.conversation.id,\n indexInConversation: highestIndex + 1,\n status: \"COMPLETED\",\n signalSource: null,\n createdDate: null,\n toolCall: null,\n delegatedConversations: [],\n subAgent: null,\n ...fields,\n };\n this.nextMessageId += 1;\n recorded.messages.push(storedMessage);\n return storedMessage;\n }\n\n /** The next scripted answer: stored at once, or after `assistantAnswerDelayMs` with the run state RUNNING meanwhile. */\n protected appendScriptedAssistantAnswer(recorded: RecordedConversation): void {\n const answerIndex = Math.min(this.scriptedAssistantAnswersUsed, this.scriptedAssistantAnswers.length - 1);\n this.scriptedAssistantAnswersUsed += 1;\n const answerText = this.scriptedAssistantAnswers[answerIndex];\n if (this.assistantAnswerDelayMs <= 0) {\n this.storeAssistantAnswer(recorded, answerText);\n return;\n }\n recorded.conversation.runState = \"RUNNING\";\n setTimeout(this.storeAssistantAnswer, this.assistantAnswerDelayMs, recorded, answerText);\n }\n\n protected storeAssistantAnswer = (recorded: RecordedConversation, answerText: string): void => {\n this.appendMessage(recorded, {\n role: \"ASSISTANT\",\n messageType: \"TEXT\",\n authorType: \"ASSISTANT\",\n message: answerText,\n });\n recorded.conversation.runState = \"IDLE\";\n };\n\n protected findMessageSearchHits(recorded: RecordedConversation, text: string): ConversationMessageSearchHit[] {\n if (text.trim() === \"\") return [];\n return sortByIndexAscending(recorded.messages)\n .filter((message) => message.messageType === \"TEXT\" && textContains(message.message, text))\n .map((message) => ({\n messageId: message.id,\n conversationId: recorded.conversation.id,\n indexInConversation: message.indexInConversation,\n role: message.role,\n excerpt: message.message,\n relevance: 1,\n created: message.createdDate,\n updated: null,\n title: recorded.conversation.title,\n }));\n }\n}\n\n/** The in-memory conversation client over recorded conversations (plain data). */\nexport const createInMemoryAgentsConversationClient = (\n data: InMemoryAgentsConversationClientData,\n): InMemoryAgentsConversationClient => new InMemoryAgentsConversationClient(data);\n","import {\n getWidgetHydrator,\n listWidgetHydratorTypes,\n registerWidgetHydrator,\n unregisterWidgetHydrator,\n} from \"../../renderer/widget-hydration/widget-hydration.registry\";\nimport type { RegisteredWidget, WidgetHydratorContext } from \"../../renderer/widget-hydration/widget-hydration.types\";\nimport { abandonWidgetHydrationReads } from \"../../renderer/widget-hydration/use-widget-hydration\";\n\n/**\n * What a stand-in answers for one hydration: the data itself (a copy is handed out), `{ __status: <code> }` for a\n * failed read (the widget observes `error`), or `{ __pending: true }` for a read that never ends (`loading`). The same\n * shape as a preview fixture's `hydration` entry.\n */\nexport type WidgetHydrationStandInAnswer = unknown | { __status: number; __body?: unknown } | { __pending: true };\n\nconst isPendingAnswer = (answer: unknown): boolean =>\n typeof answer === \"object\" && answer !== null && (answer as { __pending?: unknown }).__pending === true;\n\nconst isStatusAnswer = (answer: unknown): answer is { __status: number } =>\n typeof answer === \"object\" && answer !== null && typeof (answer as { __status?: unknown }).__status === \"number\";\n\n/**\n * Hydration answered by a spec instead of mocking `useWidgetHydration`: every registered hydrator is replaced by one\n * that answers from `answers` — by the hydration's derived key first, then by its type — and otherwise runs the real\n * hydrator. A key that names no registered hydrator gets a stand-in hydrator of that type, so a widget hydrates even\n * when the spec did not import the app's hydrator module. The widget runs its live code path (`useWidgetHydration`\n * with the provider's state store); the answer arrives asynchronously, as a real read does. `restore()` puts the\n * real hydrators back, removes the added ones and abandons every read started through the stand-ins that has not\n * settled yet: the hydration hook keeps one in-flight read per key beyond a store and a mount, so a read left pending\n * would otherwise hold every later mount of the same key in loading.\n */\nexport class WidgetHydrationStandIns {\n protected readonly replacedHydrators = new Map<string, RegisteredWidget<unknown, unknown>>();\n\n protected readonly addedTypes: string[] = [];\n\n /** The hydration key of every read started through the stand-ins that has not settled yet, by its rejection. */\n protected readonly unsettledReadKeys = new Map<(reason: Error) => void, string>();\n\n constructor(protected readonly answers: Readonly<Record<string, WidgetHydrationStandInAnswer>>) {\n for (const type of listWidgetHydratorTypes()) {\n const registered = getWidgetHydrator<unknown, unknown>(type);\n if (registered) this.replaceHydrator(type, registered);\n }\n for (const key of Object.keys(answers)) {\n if (this.replacedHydrators.has(key)) continue;\n this.addedTypes.push(key);\n registerWidgetHydrator<unknown, unknown>(key, {\n hydrator: (payload, context) => this.answer(key, key, payload, context, undefined),\n });\n }\n }\n\n /**\n * Puts the real hydrators back, removes the stand-ins added for types nothing had registered, and aborts and\n * forgets the reads still pending, so the next mount of their keys reads anew.\n */\n restore(): void {\n abandonWidgetHydrationReads(new Set(this.unsettledReadKeys.values()));\n for (const rejectRead of this.unsettledReadKeys.keys()) rejectRead(new Error(\"hydration stand-ins restored\"));\n this.unsettledReadKeys.clear();\n for (const type of this.addedTypes) unregisterWidgetHydrator(type);\n for (const [type, registered] of this.replacedHydrators) {\n unregisterWidgetHydrator(type);\n registerWidgetHydrator(type, registered);\n }\n }\n\n protected replaceHydrator(type: string, registered: RegisteredWidget<unknown, unknown>): void {\n this.replacedHydrators.set(type, registered);\n unregisterWidgetHydrator(type);\n registerWidgetHydrator<unknown, unknown>(type, {\n ...registered,\n hydrator: (payload, context) => this.answer(type, registered.deriveKey(type, payload), payload, context, registered),\n });\n }\n\n /** One read, abandoned by `restore()` while it has not settled. */\n protected answer(\n type: string,\n derivedKey: string,\n payload: unknown,\n context: WidgetHydratorContext,\n registered: RegisteredWidget<unknown, unknown> | undefined,\n ): Promise<unknown> {\n const read = this.readAnswer(type, derivedKey, payload, context, registered);\n return new Promise<unknown>((resolve, reject) => {\n this.unsettledReadKeys.set(reject, derivedKey);\n read.then(resolve, reject).finally(() => this.unsettledReadKeys.delete(reject));\n });\n }\n\n /** The answer for one read: the derived key's entry, else the type's, else the real hydrator (none: a failed read). */\n protected readAnswer(\n type: string,\n derivedKey: string,\n payload: unknown,\n context: WidgetHydratorContext,\n registered: RegisteredWidget<unknown, unknown> | undefined,\n ): Promise<unknown> {\n const answerKey = Object.prototype.hasOwnProperty.call(this.answers, derivedKey)\n ? derivedKey\n : Object.prototype.hasOwnProperty.call(this.answers, type)\n ? type\n : undefined;\n if (answerKey === undefined) {\n return registered\n ? registered.hydrator(payload, context)\n : Promise.reject(new Error(`no hydration stand-in for ${derivedKey}`));\n }\n const answer = this.answers[answerKey];\n if (isPendingAnswer(answer)) return new Promise<never>(() => {});\n if (isStatusAnswer(answer)) return Promise.reject(new Error(`hydration stand-in ${answer.__status}`));\n return Promise.resolve(structuredClone(answer));\n }\n}\n\n/** Installs hydration stand-ins (`WidgetHydrationStandIns`); call `restore()` on the result after the spec. */\nexport const installWidgetHydrationStandIns = (\n answers: Readonly<Record<string, WidgetHydrationStandInAnswer>>,\n): WidgetHydrationStandIns => new WidgetHydrationStandIns(answers);\n","import {\n conversationWidgetRegistry,\n replaceConversationWidgetRegistryEntries,\n type ConversationWidgetEntry,\n} from \"../../renderer/conversationWidgetRegistry\";\n\nexport interface TestConversationWidgetsOptions {\n /**\n * Keeps the registered widgets beside the test widgets (a test widget replaces the registered one of its wire name).\n * Default false: the registry holds the test widgets only, so an app's registrations made with its environment land\n * nowhere while the installation lasts.\n */\n keepRegisteredWidgets?: boolean;\n}\n\n/**\n * The registry entries a spec renders against, and the way back: `restore()` puts the entries the registry held before\n * the installation. Everything that reads the registry — the widget host, the name resolver, the markdown renderer, an\n * embedded widget — sees the test widgets while it lasts.\n */\nexport class TestConversationWidgetsInstallation {\n protected readonly previousWidgets: ConversationWidgetEntry[];\n\n constructor(widgets: readonly ConversationWidgetEntry[], options: TestConversationWidgetsOptions = {}) {\n const testWidgetNames = new Set(widgets.map((widget) => widget.name));\n const keptWidgets = options.keepRegisteredWidgets\n ? conversationWidgetRegistry.widgets.filter((widget) => !testWidgetNames.has(widget.name))\n : [];\n this.previousWidgets = replaceConversationWidgetRegistryEntries([...keptWidgets, ...widgets]);\n }\n\n /** Puts the entries back that the registry held before the installation. */\n restore(): void {\n replaceConversationWidgetRegistryEntries(this.previousWidgets);\n }\n}\n\n/**\n * Renders a spec against widgets of its own instead of mocking the registry module: the test widgets take the\n * registry's place (or join it, `keepRegisteredWidgets`) until `restore()`.\n */\nexport const installTestConversationWidgets = (\n widgets: readonly ConversationWidgetEntry[],\n options: TestConversationWidgetsOptions = {},\n): TestConversationWidgetsInstallation => new TestConversationWidgetsInstallation(widgets, options);\n"],"names":["recorded"],"mappings":";;;;;;AAwEA,MAAM,oCAAoC;AAC1C,MAAM,oBAAoB;AAG1B,MAAM,SAAS,CAAI,UAAgB,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AAEnE,MAAM,uBAAuB,CAAC,aAC5B,CAAC,GAAG,QAAQ,EAAE,KAAK,CAAC,OAAO,YAAY,MAAM,uBAAuB,MAAM,OAAO,uBAAuB,EAAE;AAE5G,MAAM,eAAe,CAAC,MAAiC,gBACpD,QAAQ,IAAI,YAAA,EAAc,SAAS,WAAW,KAAA,EAAO,aAAa;AAGrE,MAAM,yBAAyB,CAAC,MAAc,gBAC5C,aAAa,SACT,GAAG,IAAI;AAAA;AAAA,EAAO,YACX,IAAI,CAAC,eAAe,mBAAmB,WAAW,YAAY,MAAM,MAAM,WAAW,aAAa,EAAE,GAAG,EACvG,KAAK,IAAI,CAAC,KACb;AAUC,MAAM,iCAAqE;AAAA,EAyBhF,YAAY,MAA4C;AAxBxD,SAAmB,8CAA8B,IAAA;AACjD,SAAmB,kDAAkC,IAAA;AACrD,SAAmB,kDAAkC,IAAA;AAMrD,SAAmB,+CAA+B,IAAA;AAClD,SAAU,+BAA+B;AA2CzC,SAAA,oBAAoB,OAClB,eACA,UAAwC,CAAA,MACN;AAClC,WAAK,aAAa,mBAAmB;AACrC,YAAM,EAAE,sBAAsB,OAAO,SAAS,CAAA,MAAO;AACrD,YAAM,EAAE,KAAK,OAAO,EAAA,IAAM;AAC1B,YAAM,4BAA4B,CAAC,GAAG,KAAK,wBAAwB,QAAQ,EACxE,IAAI,CAAC,aAAa,SAAS,YAAY,EACvC,OAAO,CAAC,iBAAiB,aAAa,kBAAkB,aAAa,EACrE,OAAO,CAAC,iBAAiB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AAG,QAAO,IAAI,QAAe,MAAM;AAAA,IAAC,CAAC;AAC/D,QAAI,eAAe,MAAM,EAAG,QAAO,QAAQ,OAAO,IAAI,MAAM,sBAAsB,OAAO,QAAQ,EAAE,CAAC;AACpG,WAAO,QAAQ,QAAQ,gBAAgB,MAAM,CAAC;AAAA,EAChD;AACF;AAGO,MAAM,iCAAiC,CAC5C,YAC4B,IAAI,wBAAwB,OAAO;ACrG1D,MAAM,oCAAoC;AAAA,EAG/C,YAAY,SAA6C,UAA0C,IAAI;AACrG,UAAM,kBAAkB,IAAI,IAAI,QAAQ,IAAI,CAAC,WAAW,OAAO,IAAI,CAAC;AACpE,UAAM,cAAc,QAAQ,wBACxB,2BAA2B,QAAQ,OAAO,CAAC,WAAW,CAAC,gBAAgB,IAAI,OAAO,IAAI,CAAC,IACvF,CAAA;AACJ,SAAK,kBAAkB,yCAAyC,CAAC,GAAG,aAAa,GAAG,OAAO,CAAC;AAAA,EAC9F;AAAA;AAAA,EAGA,UAAgB;AACd,6CAAyC,KAAK,eAAe;AAAA,EAC/D;AACF;AAMO,MAAM,iCAAiC,CAC5C,SACA,UAA0C,CAAA,MACF,IAAI,oCAAoC,SAAS,OAAO;"}
|
|
1
|
+
{"version":3,"file":"client-testing.js","sources":["../src/client/testing/createInMemoryAgentsConversationClient.ts","../src/client/testing/widget-hydration-stand-ins.ts","../src/client/testing/test-conversation-widgets.ts"],"sourcesContent":["import type { AgentsConversationClient, AgentsConversationOperation } from \"../AgentsConversationClient\";\nimport {\n AgentsClientError,\n type AgentsConversation,\n type AgentsConversationMessage,\n type ChangedConversationMessages,\n type ChangedMessagesRequest,\n type ConversationActivity,\n type ConversationAttachmentReference,\n type ConversationChangeSignal,\n type ConversationListQueryOptions,\n type ConversationMessageSearchHit,\n type ConversationMessageSentPayload,\n type ConversationMessagesPage,\n type ConversationRunStatus,\n CONVERSATION_RUN_STATES_THAT_END_THE_CONVERSATION,\n type ConversationSearchGroup,\n type ConversationSearchOptions,\n type ConversationSignal,\n type ConversationSubscriptionEndReason,\n type PostedMessage,\n readConversationRunStatusOfRunState,\n type SelectableModel,\n type StartedConversation,\n} from \"../../contract/conversation\";\nimport { composeAttachmentMessageText } from \"../compose-attachment-message-text\";\n\n/** One recorded conversation handed to the in-memory client: plain data, as a fixture file holds it. */\nexport interface RecordedConversation {\n conversation: AgentsConversation;\n messages: AgentsConversationMessage[];\n /** What `getConversationActivity` answers for this conversation; an empty, finished turn when omitted. */\n activity?: ConversationActivity;\n}\n\nexport interface InMemoryAgentsConversationClientData {\n conversations: RecordedConversation[];\n /**\n * The assistant's answers to a post, an injected signal, a start or a retry, used in order; the last one repeats.\n * Default: one answer, \"Done.\".\n */\n scriptedAssistantAnswers?: string[];\n /** What `getSelectableModels` answers; the client has no `getSelectableModels` when omitted. */\n selectableModels?: SelectableModel[];\n /** The page size of `getChangedMessages` when the request names none. Default 50. */\n defaultPageSize?: number;\n /** What `getMessageSentPayload` answers, by message id; the client has no `getMessageSentPayload` when omitted. */\n sentPayloadsByMessageId?: Record<number, ConversationMessageSentPayload>;\n /**\n * The assistant answers this many milliseconds after the send, like a server's turn: the run state is RUNNING\n * meanwhile, then the answer is stored and the run state goes back to IDLE — no `emit()` involved, so a poller sees it.\n * Default 0: the answer is stored together with the send.\n */\n assistantAnswerDelayMs?: number;\n /**\n * The client has no `subscribeToConversationChanges` — a backend without push. The chat then follows the\n * conversation through the polling default (`withPollingChangeSubscription`). Default false.\n */\n withoutChangeSubscription?: boolean;\n}\n\n/** A subscriber of one conversation's live updates. */\ninterface ConversationChangeSubscriber {\n onChange: (signal: ConversationChangeSignal) => void;\n onEnded: (reason: ConversationSubscriptionEndReason) => void;\n}\n\n/** The live-update state of one conversation. */\ninterface ConversationSignalState {\n changeCounter: number;\n summaryUpdatedAt: number | null;\n}\n\nconst DEFAULT_SCRIPTED_ASSISTANT_ANSWER = \"Done.\";\nconst DEFAULT_PAGE_SIZE = 50;\n\n/** A deep copy, so a caller can never change the client's records through a returned object. */\nconst copyOf = <T>(value: T): T => JSON.parse(JSON.stringify(value)) as T;\n\nconst sortByIndexAscending = (messages: AgentsConversationMessage[]): AgentsConversationMessage[] =>\n [...messages].sort((first, second) => (first.indexInConversation ?? 0) - (second.indexInConversation ?? 0));\n\nconst textContains = (text: string | null | undefined, searchText: string): boolean =>\n (text ?? \"\").toLowerCase().includes(searchText.trim().toLowerCase());\n\n/** The message text a send stores: the typed text plus one reference line per attachment (as the host application's chat sends it). */\nconst buildStoredMessageText = composeAttachmentMessageText;\n\n/**\n * The conversation client over recorded conversations, for specs, stories and the reference app\n * (`./testing`). Behaves like the server where the chat can see it: a post stores the owner's message and, at once,\n * the next scripted assistant answer — but live updates are driven by hand: `emit()` sends the conversation's next\n * signal to its subscribers (counter advanced, newest message id, the run status), `end()` ends the subscriptions.\n * With `assistantAnswerDelayMs` the answer is stored later, as a server turn would (RUNNING meanwhile); with\n * `withoutChangeSubscription` the client has no subscription at all and the chat polls it.\n */\nexport class InMemoryAgentsConversationClient implements AgentsConversationClient {\n protected readonly recordsByConversationId = new Map<number, RecordedConversation>();\n protected readonly subscribersByConversationId = new Map<number, Set<ConversationChangeSubscriber>>();\n protected readonly signalStateByConversationId = new Map<number, ConversationSignalState>();\n protected readonly scriptedAssistantAnswers: string[];\n protected readonly defaultPageSize: number;\n protected readonly selectableModels: SelectableModel[] | undefined;\n protected readonly sentPayloadsByMessageId: Record<number, ConversationMessageSentPayload> | undefined;\n protected readonly assistantAnswerDelayMs: number;\n protected readonly requestCountsByOperation = new Map<AgentsConversationOperation, number>();\n protected scriptedAssistantAnswersUsed = 0;\n protected nextMessageId: number;\n protected nextConversationId: number;\n\n /** Present only when the data names selectable models (the port function is optional). */\n readonly getSelectableModels?: () => Promise<SelectableModel[]>;\n /** Present only when the data names sent payloads (the port function is optional). */\n readonly getMessageSentPayload?: (conversationId: number, messageId: number) => Promise<ConversationMessageSentPayload>;\n /** Present unless the data asks for a client without push (`withoutChangeSubscription`). */\n readonly subscribeToConversationChanges?: (\n conversationId: number,\n onChange: (signal: ConversationChangeSignal) => void,\n onEnded: (reason: ConversationSubscriptionEndReason) => void,\n ) => () => void;\n\n constructor(data: InMemoryAgentsConversationClientData) {\n for (const recordedConversation of copyOf(data.conversations)) {\n this.recordsByConversationId.set(recordedConversation.conversation.id, recordedConversation);\n }\n const scriptedAssistantAnswers = data.scriptedAssistantAnswers ?? [];\n this.scriptedAssistantAnswers =\n scriptedAssistantAnswers.length > 0 ? [...scriptedAssistantAnswers] : [DEFAULT_SCRIPTED_ASSISTANT_ANSWER];\n this.defaultPageSize = data.defaultPageSize ?? DEFAULT_PAGE_SIZE;\n this.selectableModels = data.selectableModels ? copyOf(data.selectableModels) : undefined;\n if (this.selectableModels) {\n this.getSelectableModels = this.readSelectableModels;\n }\n this.sentPayloadsByMessageId = data.sentPayloadsByMessageId ? copyOf(data.sentPayloadsByMessageId) : undefined;\n if (this.sentPayloadsByMessageId) {\n this.getMessageSentPayload = this.readMessageSentPayload;\n }\n this.assistantAnswerDelayMs = data.assistantAnswerDelayMs ?? 0;\n if (!data.withoutChangeSubscription) {\n this.subscribeToConversationChanges = this.subscribeToRecordedConversationChanges;\n }\n const allMessageIds = data.conversations.flatMap((recorded) => recorded.messages.map((message) => message.id));\n const allConversationIds = data.conversations.map((recorded) => recorded.conversation.id);\n this.nextMessageId = Math.max(0, ...allMessageIds) + 1;\n this.nextConversationId = Math.max(0, ...allConversationIds) + 1;\n }\n\n // ── Port ──────────────────────────────────────────────────────────────────────────────────────────────────────\n\n listConversations = async (\n agentSpaceKey: number,\n options: ConversationListQueryOptions = {},\n ): Promise<AgentsConversation[]> => {\n this.countRequest(\"listConversations\");\n const { includeUnsummarized = false, paging = {} } = options;\n const { top, skip = 0 } = paging;\n const conversationsOfAgentSpace = [...this.recordsByConversationId.values()]\n .map((recorded) => recorded.conversation)\n .filter((conversation) => conversation.agentSpaceKey === agentSpaceKey)\n .filter((conversation) => includeUnsummarized || conversation.title !== null)\n .sort((first, second) => second.id - first.id);\n const end = top === undefined ? undefined : skip + top;\n return copyOf(conversationsOfAgentSpace.slice(skip, end));\n };\n\n /** Account-wide, like the server: every recorded conversation is searched. */\n searchConversations = async (text: string, options: ConversationSearchOptions = {}): Promise<ConversationSearchGroup[]> => {\n this.countRequest(\"searchConversations\");\n const searchGroups: ConversationSearchGroup[] = [];\n for (const recorded of this.recordsByConversationId.values()) {\n const hits = this.findMessageSearchHits(recorded, text);\n if (hits.length === 0) continue;\n searchGroups.push({\n conversationId: recorded.conversation.id,\n title: recorded.conversation.title,\n summary: null,\n created: recorded.messages[0]?.createdDate ?? null,\n updated: recorded.messages[recorded.messages.length - 1]?.createdDate ?? null,\n relevance: 1,\n hits,\n });\n }\n return copyOf(searchGroups.slice(0, options.limit));\n };\n\n /** The stored conversation with `lastMessageId` (the newest stored message), as a backend without push answers it. */\n getConversationMetadata = async (conversationId: number): Promise<AgentsConversation> => {\n this.countRequest(\"getConversationMetadata\");\n const recorded = this.readRecord(conversationId);\n return copyOf({ ...recorded.conversation, lastMessageId: sortByIndexAscending(recorded.messages).pop()?.id ?? null });\n };\n\n getNewestMessagesPage = async (conversationId: number, pageSize: number): Promise<ConversationMessagesPage> => {\n this.countRequest(\"getNewestMessagesPage\");\n const newestFirst = this.readMessagesNewestFirst(conversationId);\n return copyOf({ messages: newestFirst.slice(0, pageSize), hasMoreOlder: newestFirst.length > pageSize });\n };\n\n getOlderMessagesPage = async (\n conversationId: number,\n beforeIndex: number,\n pageSize: number,\n ): Promise<ConversationMessagesPage> => {\n this.countRequest(\"getOlderMessagesPage\");\n const olderMessages = this.readMessagesNewestFirst(conversationId).filter(\n (message) => (message.indexInConversation ?? Number.MAX_SAFE_INTEGER) < beforeIndex,\n );\n return copyOf({ messages: olderMessages.slice(0, pageSize), hasMoreOlder: olderMessages.length > pageSize });\n };\n\n getChangedMessages = async (\n conversationId: number,\n request: ChangedMessagesRequest,\n ): Promise<ChangedConversationMessages> => {\n this.countRequest(\"getChangedMessages\");\n const changedMessages = this.readMessagesNewestFirst(conversationId).filter(\n (message) => message.id > request.highestKnownId || (message.indexInConversation ?? -1) >= request.fromIndex,\n );\n return copyOf({ messages: changedMessages.slice(0, request.pageSize ?? this.defaultPageSize) });\n };\n\n searchConversationMessages = async (\n conversationId: number,\n text: string,\n options: ConversationSearchOptions = {},\n ): Promise<ConversationMessageSearchHit[]> => {\n this.countRequest(\"searchConversationMessages\");\n return copyOf(this.findMessageSearchHits(this.readRecord(conversationId), text).slice(0, options.limit));\n };\n\n getConversationActivity = async (conversationId: number): Promise<ConversationActivity> => {\n this.countRequest(\"getConversationActivity\");\n return copyOf(this.readRecord(conversationId).activity ?? { turnMessageId: null, turnRunning: false, elements: [] });\n };\n\n startConversation = async (request: {\n agentSpaceKey: number;\n text: string;\n startSignalText?: string;\n entryPointKey?: string;\n model?: string;\n attachments?: ConversationAttachmentReference[];\n }): Promise<StartedConversation> => {\n this.countRequest(\"startConversation\");\n if (request.text === \"\" && !request.startSignalText) {\n throw new AgentsClientError(\"other\", { httpStatus: 400, message: \"A start needs a message or a signal.\" });\n }\n const reopenedConversation = request.entryPointKey\n ? [...this.recordsByConversationId.values()].find(\n (recorded) =>\n recorded.conversation.agentSpaceKey === request.agentSpaceKey &&\n recorded.conversation.entryPointKey === request.entryPointKey,\n )\n : undefined;\n if (reopenedConversation) {\n return { conversation: copyOf(reopenedConversation.conversation), messages: [], reopenedExisting: true };\n }\n const recorded: RecordedConversation = {\n conversation: {\n id: this.nextConversationId,\n agentSpaceKey: request.agentSpaceKey,\n runState: \"IDLE\",\n agentTurnOwedAt: null,\n title: null,\n titleManuallyEdited: false,\n summary: null,\n created: null,\n updated: null,\n purposeName: null,\n initiatorType: null,\n scheduleId: null,\n entryPointKey: request.entryPointKey ?? null,\n progressSteps: [],\n },\n messages: [],\n };\n this.nextConversationId += 1;\n this.recordsByConversationId.set(recorded.conversation.id, recorded);\n if (request.startSignalText) {\n this.appendMessage(recorded, { role: \"USER\", messageType: \"SIGNAL\", authorType: \"USER\", message: request.startSignalText });\n }\n if (request.text !== \"\") {\n this.appendMessage(recorded, {\n role: \"USER\",\n messageType: \"TEXT\",\n authorType: \"USER\",\n message: buildStoredMessageText(request.text, request.attachments),\n });\n }\n const messagesBeforeTheAnswer = copyOf(recorded.messages);\n this.appendScriptedAssistantAnswer(recorded);\n return { conversation: copyOf(recorded.conversation), messages: messagesBeforeTheAnswer, reopenedExisting: false };\n };\n\n postMessage = async (\n conversationId: number,\n message: { text: string; model?: string; attachments?: ConversationAttachmentReference[] },\n ): Promise<PostedMessage> => {\n this.countRequest(\"postMessage\");\n const recorded = this.readOpenRecord(conversationId);\n this.appendMessage(recorded, {\n role: \"USER\",\n messageType: \"TEXT\",\n authorType: \"USER\",\n message: buildStoredMessageText(message.text, message.attachments),\n });\n const messagesBeforeTheAnswer = copyOf(recorded.messages);\n this.appendScriptedAssistantAnswer(recorded);\n return { messages: messagesBeforeTheAnswer };\n };\n\n injectSignal = async (conversationId: number, signal: ConversationSignal): Promise<void> => {\n this.countRequest(\"injectSignal\");\n const recorded = this.readOpenRecord(conversationId);\n this.appendMessage(recorded, {\n role: \"USER\",\n messageType: \"SIGNAL\",\n authorType: \"USER\",\n message: signal.text,\n signalSource: signal.source ?? \"FRONTEND_WIDGET_CLICK\",\n });\n this.appendScriptedAssistantAnswer(recorded);\n };\n\n retryConversation = async (conversationId: number): Promise<void> => {\n this.countRequest(\"retryConversation\");\n const recorded = this.readRecord(conversationId);\n const newestMessage = sortByIndexAscending(recorded.messages).pop();\n if (newestMessage === undefined || newestMessage.role === \"ASSISTANT\") {\n throw new AgentsClientError(\"other\", { httpStatus: 400, message: \"Nothing to retry.\" });\n }\n this.appendScriptedAssistantAnswer(recorded);\n };\n\n renameConversation = async (conversationId: number, title: string): Promise<AgentsConversation> => {\n this.countRequest(\"renameConversation\");\n const recorded = this.readRecord(conversationId);\n recorded.conversation.title = title;\n recorded.conversation.titleManuallyEdited = true;\n return copyOf(recorded.conversation);\n };\n\n deleteConversation = async (conversationId: number): Promise<void> => {\n this.countRequest(\"deleteConversation\");\n this.readRecord(conversationId);\n this.recordsByConversationId.delete(conversationId);\n };\n\n /** The port's `subscribeToConversationChanges` unless `withoutChangeSubscription`; signals come from `emit()`. */\n protected subscribeToRecordedConversationChanges = (\n conversationId: number,\n onChange: (signal: ConversationChangeSignal) => void,\n onEnded: (reason: ConversationSubscriptionEndReason) => void,\n ): (() => void) => {\n const subscriber: ConversationChangeSubscriber = { onChange, onEnded };\n const subscribers = this.subscribersByConversationId.get(conversationId) ?? new Set<ConversationChangeSubscriber>();\n subscribers.add(subscriber);\n this.subscribersByConversationId.set(conversationId, subscribers);\n // Like the realtime database: the current value arrives at once, before any change.\n const record = this.recordsByConversationId.get(conversationId);\n if (record) {\n onChange(this.buildSignal(record, this.readSignalState(conversationId), null));\n }\n return () => {\n subscribers.delete(subscriber);\n };\n };\n\n // ── Driving live updates by hand ──────────────────────────────────────────────────────────────────────────────\n\n /**\n * Sends the conversation's next signal to its subscribers: the counter advances, `lastMessageId` is the newest\n * stored message, the run status follows the stored run state unless `runStatus` is given. `summaryChanged` also\n * advances `summaryUpdatedAt`. Returns the sent signal.\n */\n emit = (\n conversationId: number,\n change: { runStatus?: ConversationRunStatus; summaryChanged?: boolean } = {},\n ): ConversationChangeSignal => {\n const record = this.readRecord(conversationId);\n const signalState = this.readSignalState(conversationId);\n signalState.changeCounter += 1;\n if (change.summaryChanged) {\n signalState.summaryUpdatedAt = (signalState.summaryUpdatedAt ?? 0) + 1;\n }\n const signal = this.buildSignal(record, signalState, change.runStatus ?? null);\n for (const subscriber of [...(this.subscribersByConversationId.get(conversationId) ?? [])]) {\n subscriber.onChange(copyOf(signal));\n }\n return signal;\n };\n\n /** Ends every subscription of the conversation with `reason`, as the server's deletion or a lost access would. */\n end = (conversationId: number, reason: ConversationSubscriptionEndReason): void => {\n const subscribers = [...(this.subscribersByConversationId.get(conversationId) ?? [])];\n this.subscribersByConversationId.delete(conversationId);\n for (const subscriber of subscribers) {\n subscriber.onEnded(reason);\n }\n };\n\n /** Sets a conversation's stored run state (a turn that runs, fails, or a conversation that closes). */\n setRunState = (conversationId: number, runState: AgentsConversation[\"runState\"]): void => {\n this.readRecord(conversationId).conversation.runState = runState;\n };\n\n /**\n * How many requests the client answered — of one port function, or of all when `operation` is omitted (the\n * subscription is no request). For assertions such as \"no read after the chat unmounted\".\n */\n readRequestCount = (operation?: AgentsConversationOperation): number => {\n if (operation !== undefined) return this.requestCountsByOperation.get(operation) ?? 0;\n let requestCount = 0;\n for (const operationRequestCount of this.requestCountsByOperation.values()) requestCount += operationRequestCount;\n return requestCount;\n };\n\n /** Every stored message of a conversation in index order — for assertions. */\n readStoredMessages = (conversationId: number): AgentsConversationMessage[] =>\n copyOf(sortByIndexAscending(this.readRecord(conversationId).messages));\n\n // ── Internals ─────────────────────────────────────────────────────────────────────────────────────────────────\n\n protected countRequest(operation: AgentsConversationOperation): void {\n this.requestCountsByOperation.set(operation, (this.requestCountsByOperation.get(operation) ?? 0) + 1);\n }\n\n protected readSelectableModels = async (): Promise<SelectableModel[]> => {\n this.countRequest(\"getSelectableModels\");\n return copyOf(this.selectableModels ?? []);\n };\n\n protected readMessageSentPayload = async (\n conversationId: number,\n messageId: number,\n ): Promise<ConversationMessageSentPayload> => {\n this.countRequest(\"getMessageSentPayload\");\n this.readRecord(conversationId);\n const sentPayload = this.sentPayloadsByMessageId?.[messageId];\n if (sentPayload === undefined) {\n throw new AgentsClientError(\"notFound\", { httpStatus: 404, message: `No sent payload for message ${messageId}.` });\n }\n return copyOf(sentPayload);\n };\n\n protected readMessagesNewestFirst(conversationId: number): AgentsConversationMessage[] {\n return sortByIndexAscending(this.readRecord(conversationId).messages).reverse();\n }\n\n protected readRecord(conversationId: number): RecordedConversation {\n const recorded = this.recordsByConversationId.get(conversationId);\n if (!recorded) {\n throw new AgentsClientError(\"notFound\", { httpStatus: 404, message: `Conversation ${conversationId} not found.` });\n }\n return recorded;\n }\n\n /** The record of a conversation that still takes input; a completed or cancelled one refuses like the server. */\n protected readOpenRecord(conversationId: number): RecordedConversation {\n const recorded = this.readRecord(conversationId);\n const runState = recorded.conversation.runState;\n if (runState !== null && CONVERSATION_RUN_STATES_THAT_END_THE_CONVERSATION.includes(runState)) {\n throw new AgentsClientError(\"closed\", { httpStatus: 400, code: \"CONVERSATION_CLOSED\" });\n }\n return recorded;\n }\n\n protected readSignalState(conversationId: number): ConversationSignalState {\n const existingSignalState = this.signalStateByConversationId.get(conversationId);\n if (existingSignalState) return existingSignalState;\n const signalState: ConversationSignalState = { changeCounter: 0, summaryUpdatedAt: null };\n this.signalStateByConversationId.set(conversationId, signalState);\n return signalState;\n }\n\n protected buildSignal(\n recorded: RecordedConversation,\n signalState: ConversationSignalState,\n runStatus: ConversationRunStatus | null,\n ): ConversationChangeSignal {\n const newestMessage = sortByIndexAscending(recorded.messages).pop();\n return {\n changeCounter: signalState.changeCounter,\n lastMessageId: newestMessage?.id ?? null,\n runStatus: runStatus ?? readConversationRunStatusOfRunState(recorded.conversation.runState),\n summaryUpdatedAt: signalState.summaryUpdatedAt,\n };\n }\n\n protected appendMessage(\n recorded: RecordedConversation,\n fields: Pick<AgentsConversationMessage, \"role\" | \"messageType\" | \"authorType\" | \"message\"> &\n Partial<Pick<AgentsConversationMessage, \"signalSource\">>,\n ): AgentsConversationMessage {\n const highestIndex = Math.max(-1, ...recorded.messages.map((message) => message.indexInConversation ?? -1));\n const storedMessage: AgentsConversationMessage = {\n id: this.nextMessageId,\n conversationId: recorded.conversation.id,\n indexInConversation: highestIndex + 1,\n status: \"COMPLETED\",\n signalSource: null,\n createdDate: null,\n toolCall: null,\n delegatedConversations: [],\n subAgent: null,\n ...fields,\n };\n this.nextMessageId += 1;\n recorded.messages.push(storedMessage);\n return storedMessage;\n }\n\n /** The next scripted answer: stored at once, or after `assistantAnswerDelayMs` with the run state RUNNING meanwhile. */\n protected appendScriptedAssistantAnswer(recorded: RecordedConversation): void {\n const answerIndex = Math.min(this.scriptedAssistantAnswersUsed, this.scriptedAssistantAnswers.length - 1);\n this.scriptedAssistantAnswersUsed += 1;\n const answerText = this.scriptedAssistantAnswers[answerIndex];\n if (this.assistantAnswerDelayMs <= 0) {\n this.storeAssistantAnswer(recorded, answerText);\n return;\n }\n recorded.conversation.runState = \"RUNNING\";\n setTimeout(this.storeAssistantAnswer, this.assistantAnswerDelayMs, recorded, answerText);\n }\n\n protected storeAssistantAnswer = (recorded: RecordedConversation, answerText: string): void => {\n this.appendMessage(recorded, {\n role: \"ASSISTANT\",\n messageType: \"TEXT\",\n authorType: \"ASSISTANT\",\n message: answerText,\n });\n recorded.conversation.runState = \"IDLE\";\n };\n\n protected findMessageSearchHits(recorded: RecordedConversation, text: string): ConversationMessageSearchHit[] {\n if (text.trim() === \"\") return [];\n return sortByIndexAscending(recorded.messages)\n .filter((message) => message.messageType === \"TEXT\" && textContains(message.message, text))\n .map((message) => ({\n messageId: message.id,\n conversationId: recorded.conversation.id,\n indexInConversation: message.indexInConversation,\n role: message.role,\n excerpt: message.message,\n relevance: 1,\n created: message.createdDate,\n updated: null,\n title: recorded.conversation.title,\n }));\n }\n}\n\n/** The in-memory conversation client over recorded conversations (plain data). */\nexport const createInMemoryAgentsConversationClient = (\n data: InMemoryAgentsConversationClientData,\n): InMemoryAgentsConversationClient => new InMemoryAgentsConversationClient(data);\n","import {\n getWidgetHydrator,\n listWidgetHydratorTypes,\n registerWidgetHydrator,\n unregisterWidgetHydrator,\n} from \"../../renderer/widget-hydration/widget-hydration.registry\";\nimport type { RegisteredWidget, WidgetHydratorContext } from \"../../renderer/widget-hydration/widget-hydration.types\";\nimport { abandonWidgetHydrationReads } from \"../../renderer/widget-hydration/use-widget-hydration\";\n\n/**\n * What a stand-in answers for one hydration: the data itself (a copy is handed out), `{ __status: <code> }` for a\n * failed read (the widget observes `error`), or `{ __pending: true }` for a read that never ends (`loading`). The same\n * shape as a preview fixture's `hydration` entry.\n */\nexport type WidgetHydrationStandInAnswer = unknown | { __status: number; __body?: unknown } | { __pending: true };\n\nconst isPendingAnswer = (answer: unknown): boolean =>\n typeof answer === \"object\" && answer !== null && (answer as { __pending?: unknown }).__pending === true;\n\nconst isStatusAnswer = (answer: unknown): answer is { __status: number } =>\n typeof answer === \"object\" && answer !== null && typeof (answer as { __status?: unknown }).__status === \"number\";\n\n/**\n * Hydration answered by a spec instead of mocking `useWidgetHydration`: every registered hydrator is replaced by one\n * that answers from `answers` — by the hydration's derived key first, then by its type — and otherwise runs the real\n * hydrator. A key that names no registered hydrator gets a stand-in hydrator of that type, so a widget hydrates even\n * when the spec did not import the app's hydrator module. The widget runs its live code path (`useWidgetHydration`\n * with the provider's state store); the answer arrives asynchronously, as a real read does. `restore()` puts the\n * real hydrators back, removes the added ones and abandons every read started through the stand-ins that has not\n * settled yet: the hydration hook keeps one in-flight read per key beyond a store and a mount, so a read left pending\n * would otherwise hold every later mount of the same key in loading.\n */\nexport class WidgetHydrationStandIns {\n protected readonly replacedHydrators = new Map<string, RegisteredWidget<unknown, unknown>>();\n\n protected readonly addedTypes: string[] = [];\n\n /** The hydration key of every read started through the stand-ins that has not settled yet, by its rejection. */\n protected readonly unsettledReadKeys = new Map<(reason: Error) => void, string>();\n\n constructor(protected readonly answers: Readonly<Record<string, WidgetHydrationStandInAnswer>>) {\n for (const type of listWidgetHydratorTypes()) {\n const registered = getWidgetHydrator<unknown, unknown>(type);\n if (registered) this.replaceHydrator(type, registered);\n }\n for (const key of Object.keys(answers)) {\n if (this.replacedHydrators.has(key)) continue;\n this.addedTypes.push(key);\n registerWidgetHydrator<unknown, unknown>(key, {\n hydrator: (payload, context) => this.answer(key, key, payload, context, undefined),\n });\n }\n }\n\n /**\n * Puts the real hydrators back, removes the stand-ins added for types nothing had registered, and aborts and\n * forgets the reads still pending, so the next mount of their keys reads anew.\n */\n restore(): void {\n abandonWidgetHydrationReads(new Set(this.unsettledReadKeys.values()));\n for (const rejectRead of this.unsettledReadKeys.keys()) rejectRead(new Error(\"hydration stand-ins restored\"));\n this.unsettledReadKeys.clear();\n for (const type of this.addedTypes) unregisterWidgetHydrator(type);\n for (const [type, registered] of this.replacedHydrators) {\n unregisterWidgetHydrator(type);\n registerWidgetHydrator(type, registered);\n }\n }\n\n protected replaceHydrator(type: string, registered: RegisteredWidget<unknown, unknown>): void {\n this.replacedHydrators.set(type, registered);\n unregisterWidgetHydrator(type);\n registerWidgetHydrator<unknown, unknown>(type, {\n ...registered,\n hydrator: (payload, context) => this.answer(type, registered.deriveKey(type, payload), payload, context, registered),\n });\n }\n\n /** One read, abandoned by `restore()` while it has not settled. */\n protected answer(\n type: string,\n derivedKey: string,\n payload: unknown,\n context: WidgetHydratorContext,\n registered: RegisteredWidget<unknown, unknown> | undefined,\n ): Promise<unknown> {\n const read = this.readAnswer(type, derivedKey, payload, context, registered);\n return new Promise<unknown>((resolve, reject) => {\n this.unsettledReadKeys.set(reject, derivedKey);\n read.then(resolve, reject).finally(() => this.unsettledReadKeys.delete(reject));\n });\n }\n\n /** The answer for one read: the derived key's entry, else the type's, else the real hydrator (none: a failed read). */\n protected readAnswer(\n type: string,\n derivedKey: string,\n payload: unknown,\n context: WidgetHydratorContext,\n registered: RegisteredWidget<unknown, unknown> | undefined,\n ): Promise<unknown> {\n const answerKey = Object.prototype.hasOwnProperty.call(this.answers, derivedKey)\n ? derivedKey\n : Object.prototype.hasOwnProperty.call(this.answers, type)\n ? type\n : undefined;\n if (answerKey === undefined) {\n return registered\n ? registered.hydrator(payload, context)\n : Promise.reject(new Error(`no hydration stand-in for ${derivedKey}`));\n }\n const answer = this.answers[answerKey];\n if (isPendingAnswer(answer)) return new Promise<never>(() => {});\n if (isStatusAnswer(answer)) return Promise.reject(new Error(`hydration stand-in ${answer.__status}`));\n return Promise.resolve(structuredClone(answer));\n }\n}\n\n/** Installs hydration stand-ins (`WidgetHydrationStandIns`); call `restore()` on the result after the spec. */\nexport const installWidgetHydrationStandIns = (\n answers: Readonly<Record<string, WidgetHydrationStandInAnswer>>,\n): WidgetHydrationStandIns => new WidgetHydrationStandIns(answers);\n","import {\n conversationWidgetRegistry,\n replaceConversationWidgetRegistryEntries,\n type ConversationWidgetEntry,\n} from \"../../renderer/conversationWidgetRegistry\";\n\nexport interface TestConversationWidgetsOptions {\n /**\n * Keeps the registered widgets beside the test widgets (a test widget replaces the registered one of its wire name).\n * Default false: the registry holds the test widgets only, so an app's registrations made with its environment land\n * nowhere while the installation lasts.\n */\n keepRegisteredWidgets?: boolean;\n}\n\n/**\n * The registry entries a spec renders against, and the way back: `restore()` puts the entries the registry held before\n * the installation. Everything that reads the registry — the widget host, the name resolver, the markdown renderer, an\n * embedded widget — sees the test widgets while it lasts.\n */\nexport class TestConversationWidgetsInstallation {\n protected readonly previousWidgets: ConversationWidgetEntry[];\n\n constructor(widgets: readonly ConversationWidgetEntry[], options: TestConversationWidgetsOptions = {}) {\n const testWidgetNames = new Set(widgets.map((widget) => widget.name));\n const keptWidgets = options.keepRegisteredWidgets\n ? conversationWidgetRegistry.widgets.filter((widget) => !testWidgetNames.has(widget.name))\n : [];\n this.previousWidgets = replaceConversationWidgetRegistryEntries([...keptWidgets, ...widgets]);\n }\n\n /** Puts the entries back that the registry held before the installation. */\n restore(): void {\n replaceConversationWidgetRegistryEntries(this.previousWidgets);\n }\n}\n\n/**\n * Renders a spec against widgets of its own instead of mocking the registry module: the test widgets take the\n * registry's place (or join it, `keepRegisteredWidgets`) until `restore()`.\n */\nexport const installTestConversationWidgets = (\n widgets: readonly ConversationWidgetEntry[],\n options: TestConversationWidgetsOptions = {},\n): TestConversationWidgetsInstallation => new TestConversationWidgetsInstallation(widgets, options);\n"],"names":["recorded"],"mappings":";;;;;;;AAyEA,MAAM,oCAAoC;AAC1C,MAAM,oBAAoB;AAG1B,MAAM,SAAS,CAAI,UAAgB,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AAEnE,MAAM,uBAAuB,CAAC,aAC5B,CAAC,GAAG,QAAQ,EAAE,KAAK,CAAC,OAAO,YAAY,MAAM,uBAAuB,MAAM,OAAO,u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