@epam/ai-dial-chat-hooks 1.1.6 → 1.1.8
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/catalog/catalog-derivations.js +1 -1
- package/catalog/deployment-id.js +8 -2
- package/catalog/map-deployment-limits-to-input.js +81 -9
- package/catalog.d.ts +67 -14
- package/catalog.js +22 -22
- package/conversation/create-chat-stream-api.js +85 -49
- package/conversation/message-utils.js +44 -2
- package/conversation/useConversationStream/generation-resume.js +104 -63
- package/conversation/useConversationStream/useConversationStream.js +181 -110
- package/conversation.d.ts +85 -3
- package/conversation.js +29 -29
- package/index.d.ts +254 -18
- package/index.js +124 -122
- package/package.json +24 -15
- package/usage/map-usage-data-to-dashboard.js +66 -0
- package/usage/map-user-usage-to-model-limits.js +202 -0
- package/usage.d.ts +125 -0
- package/usage.js +3 -0
package/conversation.d.ts
CHANGED
|
@@ -327,6 +327,12 @@ export declare interface CreateChatStreamApiDeps {
|
|
|
327
327
|
getTimezone?: () => string | undefined;
|
|
328
328
|
/** `fetch` implementation to issue requests through. Defaults to the global `fetch`. */
|
|
329
329
|
fetchImpl?: typeof fetch;
|
|
330
|
+
/**
|
|
331
|
+
* How long an open completion stream may go without receiving a byte
|
|
332
|
+
* (keepalive comments included) before it is reported as a
|
|
333
|
+
* {@link StreamInterruptedError}. Defaults to {@link DEFAULT_STREAM_IDLE_TIMEOUT_MS}.
|
|
334
|
+
*/
|
|
335
|
+
idleTimeoutMs?: number;
|
|
330
336
|
}
|
|
331
337
|
|
|
332
338
|
/**
|
|
@@ -341,6 +347,11 @@ export declare const createMessagePair: (content: string, customContent?: Messag
|
|
|
341
347
|
/** Fallback text of a {@link GenerationConflictError} when no message is supplied. */
|
|
342
348
|
export declare const DEFAULT_GENERATION_CONFLICT_MESSAGE = "A response is already being generated in this conversation. Wait for it to finish or stop it before sending another message.";
|
|
343
349
|
|
|
350
|
+
/** Safe fallback for hosts that do not supply a translated persistence warning. */
|
|
351
|
+
export declare const DEFAULT_GENERATION_PERSISTENCE_ERROR_MESSAGE = "The response could not be saved. It is still shown here, but may be lost if you reload or leave this page. Copy it before continuing.";
|
|
352
|
+
|
|
353
|
+
export declare const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 45000;
|
|
354
|
+
|
|
344
355
|
/**
|
|
345
356
|
* Derives the row-action visibility state for a single conversation item.
|
|
346
357
|
*
|
|
@@ -375,6 +386,12 @@ export declare class GenerationConflictError extends Error {
|
|
|
375
386
|
constructor(message?: string);
|
|
376
387
|
}
|
|
377
388
|
|
|
389
|
+
/** Identifies a failed terminal save independently of the model's generation outcome. */
|
|
390
|
+
export declare class GenerationPersistenceError extends Error {
|
|
391
|
+
static readonly type = "conversation_save_failed";
|
|
392
|
+
constructor();
|
|
393
|
+
}
|
|
394
|
+
|
|
378
395
|
/**
|
|
379
396
|
* Strips the leading bucket segment from a conversation id and decodes any
|
|
380
397
|
* already-percent-encoded remainder back to raw, so callers that re-encode
|
|
@@ -387,6 +404,21 @@ export declare const getConversationPath: (conversationId: string) => string;
|
|
|
387
404
|
*/
|
|
388
405
|
export declare const getConversationSource: (item: Pick<ConversationListItemDto, "sharedWithMe" | "publishedWithMe">) => FilterTab;
|
|
389
406
|
|
|
407
|
+
/**
|
|
408
|
+
* Returns the tool values the conversation's last message sets through its
|
|
409
|
+
* `form_schema`, restricted to `toolIds`, plus a key identifying that exact
|
|
410
|
+
* application. `undefined` when the last message is not an assistant message
|
|
411
|
+
* or sets no known tool.
|
|
412
|
+
*
|
|
413
|
+
* Streamed chunks and reloads re-create an identical `form_schema`; comparing
|
|
414
|
+
* keys rather than object identity applies an app's value once and leaves a
|
|
415
|
+
* later user toggle alone until the app sends a different value.
|
|
416
|
+
*/
|
|
417
|
+
export declare const getFormSchemaToolSyncKey: (conversationId: string, messages: Message[], toolIds: readonly string[]) => {
|
|
418
|
+
key: string;
|
|
419
|
+
values: Record<string, boolean>;
|
|
420
|
+
} | undefined;
|
|
421
|
+
|
|
390
422
|
/**
|
|
391
423
|
* Returns the deployment the conversation was last running on: scanning
|
|
392
424
|
* backwards, the `new_deployment_id` of a `model_changed` status message or
|
|
@@ -410,6 +442,15 @@ export declare const getLastDeploymentId: (messages: Message[]) => string | null
|
|
|
410
442
|
*/
|
|
411
443
|
export declare const getLastUserMessageToolConfiguration: (messages: Message[]) => Record<string, unknown> | undefined;
|
|
412
444
|
|
|
445
|
+
/**
|
|
446
|
+
* Returns the tool configuration a (re-)loaded conversation should show: the
|
|
447
|
+
* last user message's `configuration_value`, overlaid in order by the
|
|
448
|
+
* `form_schema` values of the assistant messages after it. An app that turned
|
|
449
|
+
* a toggle off in its final response must not see it re-armed on reload just
|
|
450
|
+
* because the user message that started the run had it on.
|
|
451
|
+
*/
|
|
452
|
+
export declare const getLatestToolConfiguration: (messages: Message[]) => Record<string, unknown> | undefined;
|
|
453
|
+
|
|
413
454
|
/**
|
|
414
455
|
* Extracts the deployment/model ID from a DIAL Core conversation ID.
|
|
415
456
|
*
|
|
@@ -493,6 +534,15 @@ export declare const getStarterSubmitText: (starter: StarterOption, description?
|
|
|
493
534
|
*/
|
|
494
535
|
export declare const getTimeOfDayGreeting: (hour: number, translations: GreetingTranslations, firstName?: string) => string;
|
|
495
536
|
|
|
537
|
+
/**
|
|
538
|
+
* Returns the boolean values an assistant message's `form_schema` sets, keyed
|
|
539
|
+
* by property name, or `undefined` when no property resolves to a boolean.
|
|
540
|
+
* Lets a DIAL app switch a tools-menu toggle (e.g. `deep_research`) per
|
|
541
|
+
* message — on while a run is in progress, off once its result is delivered.
|
|
542
|
+
* Not filtered by tool id: `restoreToolConfiguration` ignores unknown ids.
|
|
543
|
+
*/
|
|
544
|
+
export declare const getToolConfigurationFromFormSchema: (formSchema: DeploymentConfigurationSchema | undefined) => Record<string, boolean> | undefined;
|
|
545
|
+
|
|
496
546
|
/** Pre-translated greeting phrase strings for each time-of-day period. */
|
|
497
547
|
export declare interface GreetingTranslations {
|
|
498
548
|
morningWithName: string;
|
|
@@ -529,8 +579,8 @@ export declare const isAnswerIncomplete: (answer: Message | undefined) => boolea
|
|
|
529
579
|
* True when the conversation's last message is an unresolved assistant
|
|
530
580
|
* placeholder: the backend only persists a conversation at generation start
|
|
531
581
|
* (empty placeholder) and at generation end (final content, or a partial
|
|
532
|
-
* flagged `streamErrorMessage`/`wasStoppedByUser`)
|
|
533
|
-
*
|
|
582
|
+
* flagged `streamErrorMessage`/`wasStoppedByUser`). This can mean generation
|
|
583
|
+
* is still active elsewhere, or that its terminal save failed.
|
|
534
584
|
*/
|
|
535
585
|
export declare const isAwaitingGenerationResume: (conversation: Conversation) => boolean;
|
|
536
586
|
|
|
@@ -661,6 +711,29 @@ export declare interface StreamCompletionOptions {
|
|
|
661
711
|
signal: AbortSignal;
|
|
662
712
|
}
|
|
663
713
|
|
|
714
|
+
/**
|
|
715
|
+
* Reported through `onError` when the network connection carrying a
|
|
716
|
+
* completion stream is lost (a rejected `fetch`, or a read that fails after a
|
|
717
|
+
* 2xx response) or goes silent past the idle timeout — what a laptop sleep or
|
|
718
|
+
* a phone lock mid-generation produces. The backend-owned generation may
|
|
719
|
+
* still be running, so the caller can recover it rather than treat the
|
|
720
|
+
* response as failed. `cause` holds the original error, when there is one.
|
|
721
|
+
*/
|
|
722
|
+
export declare class StreamInterruptedError extends Error {
|
|
723
|
+
constructor(cause?: unknown);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Reported through `onError` when DIAL Core itself signals a failure with an
|
|
728
|
+
* in-band `{ error: { message } }` SSE chunk. Its `message` is upstream text
|
|
729
|
+
* intended for the user, unlike a transport failure (failed `fetch`, non-OK
|
|
730
|
+
* status, broken stream), whose message is technical detail. A custom
|
|
731
|
+
* transport raises this for any user-facing upstream error text.
|
|
732
|
+
*/
|
|
733
|
+
export declare class StreamUpstreamError extends Error {
|
|
734
|
+
constructor(message: string);
|
|
735
|
+
}
|
|
736
|
+
|
|
664
737
|
/** Request shape the host's selected-deployment recognition call accepts. */
|
|
665
738
|
export declare interface TranscribeWithDeploymentParams {
|
|
666
739
|
audioUrl: string;
|
|
@@ -934,7 +1007,7 @@ export declare interface UseConversationPanelItemsResolvers {
|
|
|
934
1007
|
* `transport`/`generation`/`channel`/`overlay` capabilities rather than any
|
|
935
1008
|
* app context or `server-api` import.
|
|
936
1009
|
*/
|
|
937
|
-
export declare const useConversationStream: ({ conversationId, state: { setConversation, conversationRef }, transport, generation: { startGeneration, completeGeneration }, channel, overlay, onStopError, generationConflictMessage, }: UseConversationStreamParams) => UseConversationStreamResult;
|
|
1010
|
+
export declare const useConversationStream: ({ conversationId, state: { setConversation, conversationRef }, transport, generation: { startGeneration, completeGeneration }, channel, overlay, onStopError, generationConflictMessage, generationPersistenceErrorMessage, onStreamError, }: UseConversationStreamParams) => UseConversationStreamResult;
|
|
938
1011
|
|
|
939
1012
|
/** Parameters for {@link useConversationStream}. */
|
|
940
1013
|
export declare interface UseConversationStreamParams {
|
|
@@ -952,6 +1025,15 @@ export declare interface UseConversationStreamParams {
|
|
|
952
1025
|
* {@link DEFAULT_GENERATION_CONFLICT_MESSAGE}.
|
|
953
1026
|
*/
|
|
954
1027
|
generationConflictMessage?: string;
|
|
1028
|
+
/** Host-translated warning shown when the received answer could not be saved. */
|
|
1029
|
+
generationPersistenceErrorMessage?: string;
|
|
1030
|
+
/**
|
|
1031
|
+
* Receives the original error of every failed stream. The hook shows only
|
|
1032
|
+
* host-supplied or upstream-supplied text on the message bubble and hides
|
|
1033
|
+
* transport detail (e.g. `Failed to fetch`), so this is where the host can
|
|
1034
|
+
* still log or report the raw error.
|
|
1035
|
+
*/
|
|
1036
|
+
onStreamError?: (error: Error) => void;
|
|
955
1037
|
}
|
|
956
1038
|
|
|
957
1039
|
/** Return value of {@link useConversationStream}. */
|
package/conversation.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import { buildAnnouncementSignature as e, hasAnnouncementContent as t, hasStructuredAnnouncement as n, sanitizeAnnouncementHtml as r, sanitizeAnnouncementMessageHtml as i } from "./conversation/announcement-message.js";
|
|
2
|
-
import { DEFAULT_GENERATION_CONFLICT_MESSAGE as a,
|
|
3
|
-
import { shouldWatchForDisplayNameUpdate as
|
|
4
|
-
import { formatAppVersion as
|
|
5
|
-
import { getModelIdFromConversationId as
|
|
6
|
-
import { getTimeOfDayGreeting as
|
|
7
|
-
import { createDeploymentChangedMessage as
|
|
8
|
-
import { getLastDeploymentId as
|
|
9
|
-
import { getQuickAppConversationStarters as
|
|
10
|
-
import { getStarterPopulateText as
|
|
11
|
-
import { deriveConversationRowActionState as
|
|
12
|
-
import { useActiveConversationSync as
|
|
13
|
-
import { useAsyncConfirmDialog as
|
|
14
|
-
import { useConversationLookupMaps as
|
|
15
|
-
import { getConversationSource as
|
|
16
|
-
import { useImportFilePicker as
|
|
17
|
-
import { useAttachmentUpload as
|
|
18
|
-
import { AudioTranscriptionError as
|
|
19
|
-
import { useTranscribeAudio as
|
|
20
|
-
import { attachmentToDto as
|
|
21
|
-
import { createMessagePair as
|
|
22
|
-
import { hasActiveToolConfig as
|
|
23
|
-
import { getStarterConversationText as
|
|
24
|
-
import { getConversationPath as
|
|
25
|
-
import { useConversationHandlers as
|
|
26
|
-
import { isAwaitingGenerationResume as
|
|
27
|
-
import { useConversationStream as
|
|
28
|
-
import { useChatSettingsFormConfig as
|
|
29
|
-
import { useToolsMenu as
|
|
30
|
-
export {
|
|
2
|
+
import { DEFAULT_GENERATION_CONFLICT_MESSAGE as a, DEFAULT_GENERATION_PERSISTENCE_ERROR_MESSAGE as o, DEFAULT_STREAM_IDLE_TIMEOUT_MS as s, GenerationConflictError as c, GenerationPersistenceError as l, StreamInterruptedError as u, StreamUpstreamError as d, createChatStreamApi as f } from "./conversation/create-chat-stream-api.js";
|
|
3
|
+
import { shouldWatchForDisplayNameUpdate as p } from "./conversation/display-name-watch.js";
|
|
4
|
+
import { formatAppVersion as m, sanitizeFooterHtml as h } from "./conversation/footer-message.js";
|
|
5
|
+
import { getModelIdFromConversationId as g } from "./conversation/get-model-id-from-conversation-id.js";
|
|
6
|
+
import { getTimeOfDayGreeting as _ } from "./conversation/greeting.js";
|
|
7
|
+
import { createDeploymentChangedMessage as v } from "./conversation/message-factory.js";
|
|
8
|
+
import { getFormSchemaToolSyncKey as y, getLastDeploymentId as b, getLastUserMessageToolConfiguration as x, getLatestToolConfiguration as S, getToolConfigurationFromFormSchema as C, isMessageStreaming as w, messageHasStages as T, normalizeResponseFormat as E } from "./conversation/message-utils.js";
|
|
9
|
+
import { getQuickAppConversationStarters as D } from "./conversation/quick-app-conversation-starters.js";
|
|
10
|
+
import { getStarterPopulateText as O, getStartersFromSchema as k } from "./conversation/starter-option.js";
|
|
11
|
+
import { deriveConversationRowActionState as A } from "./conversation/deriveConversationRowActionState/deriveConversationRowActionState.js";
|
|
12
|
+
import { useActiveConversationSync as j } from "./conversation/useActiveConversationSync/useActiveConversationSync.js";
|
|
13
|
+
import { useAsyncConfirmDialog as M } from "./conversation/useAsyncConfirmDialog/useAsyncConfirmDialog.js";
|
|
14
|
+
import { useConversationLookupMaps as N } from "./conversation/useConversationLookupMaps/useConversationLookupMaps.js";
|
|
15
|
+
import { getConversationSource as P, useConversationPanelItems as F } from "./conversation/useConversationPanelItems/useConversationPanelItems.js";
|
|
16
|
+
import { useImportFilePicker as I } from "./conversation/useImportFilePicker/useImportFilePicker.js";
|
|
17
|
+
import { useAttachmentUpload as L } from "./conversation/useAttachmentUpload/useAttachmentUpload.js";
|
|
18
|
+
import { AudioTranscriptionError as R, AudioTranscriptionErrorReason as z } from "./conversation/useTranscribeAudio/audio-transcription-error.js";
|
|
19
|
+
import { useTranscribeAudio as B } from "./conversation/useTranscribeAudio/useTranscribeAudio.js";
|
|
20
|
+
import { attachmentToDto as V, attachmentsToDtos as H } from "./conversation/useConversationHandlers/attachment-to-dto.js";
|
|
21
|
+
import { createMessagePair as U } from "./conversation/useConversationHandlers/message-factory.js";
|
|
22
|
+
import { hasActiveToolConfig as W, isAnswerIncomplete as G, isMessageChanged as K, shouldRerunGenerationOnEdit as q } from "./conversation/useConversationHandlers/message-utils.js";
|
|
23
|
+
import { getStarterConversationText as J, getStarterDisplayText as Y, getStarterSubmitText as X } from "./conversation/useConversationHandlers/starter-option.js";
|
|
24
|
+
import { getConversationPath as Z } from "./conversation/useConversationStream/conversation-path.js";
|
|
25
|
+
import { useConversationHandlers as Q } from "./conversation/useConversationHandlers/useConversationHandlers.js";
|
|
26
|
+
import { isAwaitingGenerationResume as $ } from "./conversation/useConversationStream/generation-resume.js";
|
|
27
|
+
import { useConversationStream as ee } from "./conversation/useConversationStream/useConversationStream.js";
|
|
28
|
+
import { useChatSettingsFormConfig as te } from "./useChatSettingsFormConfig/useChatSettingsFormConfig.js";
|
|
29
|
+
import { useToolsMenu as ne } from "./useToolsMenu/useToolsMenu.js";
|
|
30
|
+
export { R as AudioTranscriptionError, z as AudioTranscriptionErrorReason, a as DEFAULT_GENERATION_CONFLICT_MESSAGE, o as DEFAULT_GENERATION_PERSISTENCE_ERROR_MESSAGE, s as DEFAULT_STREAM_IDLE_TIMEOUT_MS, c as GenerationConflictError, l as GenerationPersistenceError, u as StreamInterruptedError, d as StreamUpstreamError, V as attachmentToDto, H as attachmentsToDtos, e as buildAnnouncementSignature, f as createChatStreamApi, v as createDeploymentChangedMessage, U as createMessagePair, A as deriveConversationRowActionState, m as formatAppVersion, Z as getConversationPath, P as getConversationSource, y as getFormSchemaToolSyncKey, b as getLastDeploymentId, x as getLastUserMessageToolConfiguration, S as getLatestToolConfiguration, g as getModelIdFromConversationId, D as getQuickAppConversationStarters, J as getStarterConversationText, Y as getStarterDisplayText, O as getStarterPopulateText, X as getStarterSubmitText, k as getStartersFromSchema, _ as getTimeOfDayGreeting, C as getToolConfigurationFromFormSchema, W as hasActiveToolConfig, t as hasAnnouncementContent, n as hasStructuredAnnouncement, G as isAnswerIncomplete, $ as isAwaitingGenerationResume, K as isMessageChanged, w as isMessageStreaming, T as messageHasStages, E as normalizeResponseFormat, r as sanitizeAnnouncementHtml, i as sanitizeAnnouncementMessageHtml, h as sanitizeFooterHtml, q as shouldRerunGenerationOnEdit, p as shouldWatchForDisplayNameUpdate, j as useActiveConversationSync, M as useAsyncConfirmDialog, L as useAttachmentUpload, te as useChatSettingsFormConfig, Q as useConversationHandlers, N as useConversationLookupMaps, F as useConversationPanelItems, ee as useConversationStream, I as useImportFilePicker, ne as useToolsMenu, B as useTranscribeAudio };
|