@epam/ai-dial-chat-hooks 1.1.0-dev.252 → 1.1.0-dev.253
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/attachment/useAttachmentValidation/useAttachmentValidation.d.ts +44 -0
- package/attachment/useAttachmentValidation/useAttachmentValidation.d.ts.map +1 -0
- package/conversation/conversation-transfer/async.d.ts +10 -0
- package/conversation/conversation-transfer/async.d.ts.map +1 -0
- package/conversation/conversation-transfer/attachment-refs.d.ts +12 -0
- package/conversation/conversation-transfer/attachment-refs.d.ts.map +1 -0
- package/conversation/conversation-transfer/build-upload-path.d.ts +40 -0
- package/conversation/conversation-transfer/build-upload-path.d.ts.map +1 -0
- package/conversation/conversation-transfer/date.d.ts +5 -0
- package/conversation/conversation-transfer/date.d.ts.map +1 -0
- package/conversation/conversation-transfer/dial-file-resolve.d.ts +10 -0
- package/conversation/conversation-transfer/dial-file-resolve.d.ts.map +1 -0
- package/conversation/conversation-transfer/export-conversation.d.ts +8 -0
- package/conversation/conversation-transfer/export-conversation.d.ts.map +1 -0
- package/conversation/conversation-transfer/import-conversation.d.ts +82 -0
- package/conversation/conversation-transfer/import-conversation.d.ts.map +1 -0
- package/conversation/conversation-transfer/queue.d.ts +31 -0
- package/conversation/conversation-transfer/queue.d.ts.map +1 -0
- package/conversation/conversation-transfer/types.d.ts +73 -0
- package/conversation/conversation-transfer/types.d.ts.map +1 -0
- package/conversation/conversation-transfer/zip-export.d.ts +31 -0
- package/conversation/conversation-transfer/zip-export.d.ts.map +1 -0
- package/conversation/conversation-transfer/zip-import.d.ts +17 -0
- package/conversation/conversation-transfer/zip-import.d.ts.map +1 -0
- package/conversation/useConversationExport/useConversationExport.d.ts +50 -0
- package/conversation/useConversationExport/useConversationExport.d.ts.map +1 -0
- package/conversation/useConversationHandlers/attachment-to-dto.d.ts +7 -0
- package/conversation/useConversationHandlers/attachment-to-dto.d.ts.map +1 -0
- package/conversation/useConversationHandlers/message-factory.d.ts +9 -0
- package/conversation/useConversationHandlers/message-factory.d.ts.map +1 -0
- package/conversation/useConversationHandlers/message-utils.d.ts +14 -0
- package/conversation/useConversationHandlers/message-utils.d.ts.map +1 -0
- package/conversation/useConversationHandlers/starter-option.d.ts +14 -0
- package/conversation/useConversationHandlers/starter-option.d.ts.map +1 -0
- package/conversation/useConversationHandlers/useConversationHandlers.d.ts +66 -0
- package/conversation/useConversationHandlers/useConversationHandlers.d.ts.map +1 -0
- package/conversation/useConversationImport/useConversationImport.d.ts +50 -0
- package/conversation/useConversationImport/useConversationImport.d.ts.map +1 -0
- package/conversation/useConversationStream/apply-chunk.d.ts +20 -0
- package/conversation/useConversationStream/apply-chunk.d.ts.map +1 -0
- package/conversation/useConversationStream/conversation-path.d.ts +9 -0
- package/conversation/useConversationStream/conversation-path.d.ts.map +1 -0
- package/conversation/useConversationStream/generation-resume.d.ts +10 -0
- package/conversation/useConversationStream/generation-resume.d.ts.map +1 -0
- package/conversation/useConversationStream/useConversationStream.d.ts +78 -0
- package/conversation/useConversationStream/useConversationStream.d.ts.map +1 -0
- package/index.d.ts +15 -0
- package/index.d.ts.map +1 -1
- package/index.js +1272 -92
- package/package.json +10 -7
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ConversationsApi, FilesApi, RateApi, SendCompletionDtoModeEnum } from '@epam/ai-dial-chat-api-client';
|
|
2
|
+
import { Attachment, Conversation, DisplayAttachment, MessageCustomContent, MessageRating, StarterOption } from '@epam/ai-dial-chat-shared';
|
|
3
|
+
import { ConversationStateAccessor } from '../useConversationStream/useConversationStream';
|
|
4
|
+
/** The exact `startStream` shape `useConversationStream` returns. */
|
|
5
|
+
export type ConversationStreamStarter = (conversationPath: string, userContent: string, messageIndex: number, model: string, customContent?: MessageCustomContent, generationId?: string, mode?: SendCompletionDtoModeEnum) => void;
|
|
6
|
+
/** Parameters for {@link useConversationHandlers}. */
|
|
7
|
+
export interface UseConversationHandlersParams {
|
|
8
|
+
conversation: Conversation | null;
|
|
9
|
+
conversationId: string | undefined;
|
|
10
|
+
bucket: string | undefined;
|
|
11
|
+
isStreaming: boolean;
|
|
12
|
+
/** The `startStream` function returned by `useConversationStream`. */
|
|
13
|
+
startStream: ConversationStreamStarter;
|
|
14
|
+
/** Shared mutable channel for the displayed conversation — the same one passed to `useConversationStream`. */
|
|
15
|
+
state: ConversationStateAccessor;
|
|
16
|
+
/** Already-configured generated-client instance used to upload attachments. */
|
|
17
|
+
filesApi: Pick<FilesApi, 'uploadFile'>;
|
|
18
|
+
/** Already-configured generated-client instance used to save/delete the conversation. */
|
|
19
|
+
conversationsApi: Pick<ConversationsApi, 'saveConversation' | 'deleteConversation'>;
|
|
20
|
+
/** Already-configured generated-client instance used to rate a message. */
|
|
21
|
+
rateApi: Pick<RateApi, 'rateMessage'>;
|
|
22
|
+
/** Resolves the model id to send with the next completion. Re-evaluated on every call — never cached. */
|
|
23
|
+
resolveModelId: () => string;
|
|
24
|
+
/** Called when deleting the last message also deletes the whole conversation. */
|
|
25
|
+
onConversationDeleted?: () => void;
|
|
26
|
+
/** Called with batched filenames after a burst of network-error upload failures. */
|
|
27
|
+
showNetworkError?: (filenames: string[]) => void;
|
|
28
|
+
/** Tool toggle configuration values merged into every outgoing completion request. */
|
|
29
|
+
toolConfigurationValue?: Record<string, boolean>;
|
|
30
|
+
}
|
|
31
|
+
/** Return value of {@link useConversationHandlers}. */
|
|
32
|
+
export interface UseConversationHandlersResult {
|
|
33
|
+
handleSend: (message: string, attachments: Attachment[]) => Promise<void>;
|
|
34
|
+
handleUploadAttachment: (attachment: Attachment) => Promise<string>;
|
|
35
|
+
handleRegenerateMessage: (messageIndex: number) => void;
|
|
36
|
+
handleDeleteMessage: (messageIndex: number) => void;
|
|
37
|
+
handleConfirmDelete: () => void;
|
|
38
|
+
handleRateMessage: (messageIndex: number, rating: MessageRating | null, comment?: string) => Promise<boolean>;
|
|
39
|
+
handleButtonSelect: (starter: StarterOption, propertyKey?: string, description?: string) => void;
|
|
40
|
+
handleConfirmStarter: () => void;
|
|
41
|
+
handleStartEdit: (messageIndex: number) => void;
|
|
42
|
+
handleCancelEdit: (messageIndex: number) => void;
|
|
43
|
+
handleEditMessage: (messageIndex: number, text: string, keptDisplayAttachments: DisplayAttachment[], newAttachments: Attachment[]) => Promise<void>;
|
|
44
|
+
editingMessageIndexes: Set<number>;
|
|
45
|
+
pendingDeleteIndex: number | null;
|
|
46
|
+
setPendingDeleteIndex: (index: number | null) => void;
|
|
47
|
+
pendingStarterContext: {
|
|
48
|
+
starter: StarterOption;
|
|
49
|
+
propertyKey?: string;
|
|
50
|
+
description?: string;
|
|
51
|
+
} | null;
|
|
52
|
+
setPendingStarterContext: (context: {
|
|
53
|
+
starter: StarterOption;
|
|
54
|
+
propertyKey?: string;
|
|
55
|
+
description?: string;
|
|
56
|
+
} | null) => void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Composes send/regenerate/edit/delete/rate/starter-submission orchestration
|
|
60
|
+
* on top of the library's own `useAttachmentUpload` and the injected
|
|
61
|
+
* `startStream` (from `useConversationStream`). Optimistic message-pair
|
|
62
|
+
* insertion, delete confirmation, and rate revert-on-failure all mutate the
|
|
63
|
+
* shared `state` channel directly, in lockstep with the streaming hook.
|
|
64
|
+
*/
|
|
65
|
+
export declare const useConversationHandlers: ({ conversation, conversationId, bucket, isStreaming, startStream, state: { setConversation, conversationRef }, filesApi, conversationsApi, rateApi, resolveModelId, onConversationDeleted, showNetworkError, toolConfigurationValue, }: UseConversationHandlersParams) => UseConversationHandlersResult;
|
|
66
|
+
//# sourceMappingURL=useConversationHandlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConversationHandlers.d.ts","sourceRoot":"","sources":["../../../src/conversation/useConversationHandlers/useConversationHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,gBAAgB,EAChB,QAAQ,EACR,OAAO,EACP,yBAAyB,EAC1B,MAAM,+BAA+B,CAAC;AAEv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BAAqB,EAAE;QACrB,OAAO,EAAE,aAAa,CAAC;QACvB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,GAAG,IAAI,CAAC;IACT,wBAAwB,EAAE,CACxB,OAAO,EAAE;QACP,OAAO,EAAE,aAAa,CAAC;QACvB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,GAAG,IAAI,KACL,IAAI,CAAC;CACX;AAED;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,GAAI,wOAcrC,6BAA6B,KAAG,6BA8elC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ConversationsApi, FilesApi } from '@epam/ai-dial-chat-api-client';
|
|
2
|
+
import { ConversationTransferErrorEvent, ConversationTransferJob, ConversationTransferSuccessEvent, ConversationTransferWarningEvent } from '../conversation-transfer/types';
|
|
3
|
+
/** Parameters for {@link useConversationImport}. */
|
|
4
|
+
export interface UseConversationImportParams {
|
|
5
|
+
/** Already-configured generated-client instance used to persist imported conversations. */
|
|
6
|
+
conversationsApi: Pick<ConversationsApi, 'saveConversation'>;
|
|
7
|
+
/** Already-configured generated-client instance used to list/upload attachments. */
|
|
8
|
+
filesApi: Pick<FilesApi, 'listFiles' | 'uploadFile'>;
|
|
9
|
+
/** The current user's DIAL Core storage bucket. Import fails with `MissingBucket` when `undefined`. */
|
|
10
|
+
bucket: string | undefined;
|
|
11
|
+
/** Called after at least one conversation in a job was imported successfully. */
|
|
12
|
+
onImported?: () => Promise<void> | void;
|
|
13
|
+
/** Classifies a thrown error as unauthorized. Host-owned error taxonomy; defaults to never. */
|
|
14
|
+
classifyTransferError?: (error: unknown) => {
|
|
15
|
+
isUnauthorized?: boolean;
|
|
16
|
+
};
|
|
17
|
+
/** Resolves a trace id for a failing request, for display in an error notification. */
|
|
18
|
+
resolveErrorTraceId?: (error: unknown) => Promise<string | undefined>;
|
|
19
|
+
/** Called when a job completes with at least one successfully imported conversation. */
|
|
20
|
+
onSuccess?: (event: ConversationTransferSuccessEvent) => void;
|
|
21
|
+
/** Called when a job succeeds but had to skip an attachment. */
|
|
22
|
+
onWarning?: (event: ConversationTransferWarningEvent) => void;
|
|
23
|
+
/** Called when a job fails, or when some conversations within it failed. */
|
|
24
|
+
onError?: (event: ConversationTransferErrorEvent) => void;
|
|
25
|
+
}
|
|
26
|
+
/** Return value of {@link useConversationImport}. */
|
|
27
|
+
export interface UseConversationImportResult {
|
|
28
|
+
/** Import jobs, most recently added last. Multiple jobs can be in progress concurrently. */
|
|
29
|
+
jobs: ConversationTransferJob[];
|
|
30
|
+
/** Parses the given file and starts importing it as a new job. */
|
|
31
|
+
importConversations: (file: File) => Promise<void>;
|
|
32
|
+
/** Removes a job from the queue. If still in progress, aborts its underlying requests. */
|
|
33
|
+
dismissJob: (jobId: string) => void;
|
|
34
|
+
/** Re-attempts a failed job in place (same job id, reusing the already-parsed file). */
|
|
35
|
+
retryJob: (jobId: string) => void;
|
|
36
|
+
/** Aborts all in-progress jobs and clears the entire queue. */
|
|
37
|
+
dismissAll: () => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Owns the import job queue: parses a selected export file (`.json` or
|
|
41
|
+
* `.dial`/`.zip`, v5 envelope, old- or new-chat origin) once per file, then
|
|
42
|
+
* re-uploads any archive attachments to `uploads/<YYYY-MM>/` —
|
|
43
|
+
* disambiguating a name collision with a ` (n)` suffix instead of rejecting
|
|
44
|
+
* it — rewrites attachment references (and renamed titles), regenerates each
|
|
45
|
+
* conversation's id/path with a fresh UUID (collision-free save, no replace
|
|
46
|
+
* dialog), and persists every conversation through the injected
|
|
47
|
+
* `conversationsApi`. One job per imported file, not per conversation.
|
|
48
|
+
*/
|
|
49
|
+
export declare const useConversationImport: ({ conversationsApi, filesApi, bucket, onImported, classifyTransferError, resolveErrorTraceId, onSuccess, onWarning, onError, }: UseConversationImportParams) => UseConversationImportResult;
|
|
50
|
+
//# sourceMappingURL=useConversationImport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConversationImport.d.ts","sourceRoot":"","sources":["../../../src/conversation/useConversationImport/useConversationImport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,gBAAgB,EAChB,QAAQ,EACT,MAAM,+BAA+B,CAAC;AAmBvC,OAAO,EAKL,KAAK,8BAA8B,EACnC,KAAK,uBAAuB,EAC5B,KAAK,gCAAgC,EACrC,KAAK,gCAAgC,EACtC,MAAM,gCAAgC,CAAC;AAgExC,oDAAoD;AACpD,MAAM,WAAW,2BAA2B;IAC1C,2FAA2F;IAC3F,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;IAC7D,oFAAoF;IACpF,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,WAAW,GAAG,YAAY,CAAC,CAAC;IACrD,uGAAuG;IACvG,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,iFAAiF;IACjF,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACxC,+FAA+F;IAC/F,qBAAqB,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK;QAAE,cAAc,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IACzE,uFAAuF;IACvF,mBAAmB,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACtE,wFAAwF;IACxF,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,gCAAgC,KAAK,IAAI,CAAC;IAC9D,gEAAgE;IAChE,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,gCAAgC,KAAK,IAAI,CAAC;IAC9D,4EAA4E;IAC5E,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,8BAA8B,KAAK,IAAI,CAAC;CAC3D;AA2GD,qDAAqD;AACrD,MAAM,WAAW,2BAA2B;IAC1C,4FAA4F;IAC5F,IAAI,EAAE,uBAAuB,EAAE,CAAC;IAChC,kEAAkE;IAClE,mBAAmB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,0FAA0F;IAC1F,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,wFAAwF;IACxF,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,+DAA+D;IAC/D,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,GAAI,gIAUnC,2BAA2B,KAAG,2BAiPhC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Message, StreamChunk } from '@epam/ai-dial-chat-shared';
|
|
2
|
+
/**
|
|
3
|
+
* Applies a single SSE stream chunk to the message list.
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* Attachments are accumulated: each chunk's attachments are appended to the
|
|
7
|
+
* existing array rather than replacing it.
|
|
8
|
+
*
|
|
9
|
+
* Annotations are merged by `index`: partial `body.title` and `body.quote`
|
|
10
|
+
* strings are concatenated across chunks, matching the same delta-merge
|
|
11
|
+
* semantics used for stages.
|
|
12
|
+
*
|
|
13
|
+
* `state` is overwritten (not merged) by each chunk that carries one,
|
|
14
|
+
* matching the DIAL stateful-app contract.
|
|
15
|
+
*
|
|
16
|
+
* @returns Updated message array, or `null` when the chunk carries no
|
|
17
|
+
* actionable data (empty content, no form_schema, and no attachments).
|
|
18
|
+
*/
|
|
19
|
+
export declare const applyChunkToMessages: (messages: Message[], messageIndex: number, chunk: StreamChunk) => Message[] | null;
|
|
20
|
+
//# sourceMappingURL=apply-chunk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-chunk.d.ts","sourceRoot":"","sources":["../../../src/conversation/useConversationStream/apply-chunk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,OAAO,EAGP,WAAW,EACZ,MAAM,2BAA2B,CAAC;AA2FnC;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,oBAAoB,GAC/B,UAAU,OAAO,EAAE,EACnB,cAAc,MAAM,EACpB,OAAO,WAAW,KACjB,OAAO,EAAE,GAAG,IAqEd,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Decodes a percent-encoded path segment, leaving it unchanged if decoding fails. */
|
|
2
|
+
export declare const safeDecodeURI: (path: string) => string;
|
|
3
|
+
/**
|
|
4
|
+
* Strips the leading bucket segment from a conversation id and decodes any
|
|
5
|
+
* already-percent-encoded remainder back to raw, so callers that re-encode
|
|
6
|
+
* the result once (e.g. an API client) don't double-encode it on the wire.
|
|
7
|
+
*/
|
|
8
|
+
export declare const getConversationPath: (conversationId: string) => string;
|
|
9
|
+
//# sourceMappingURL=conversation-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversation-path.d.ts","sourceRoot":"","sources":["../../../src/conversation/useConversationStream/conversation-path.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,MAM5C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,gBAAgB,MAAM,KAAG,MAO5D,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Conversation } from '@epam/ai-dial-chat-shared';
|
|
2
|
+
/**
|
|
3
|
+
* True when the conversation's last message is an unresolved assistant
|
|
4
|
+
* placeholder: the backend only persists a conversation at generation start
|
|
5
|
+
* (empty placeholder) and at generation end (final content, or a partial
|
|
6
|
+
* flagged `streamErrorMessage`/`wasStoppedByUser`), so this shape means a
|
|
7
|
+
* generation was still active elsewhere when the conversation was loaded.
|
|
8
|
+
*/
|
|
9
|
+
export declare const isAwaitingGenerationResume: (conversation: Conversation) => boolean;
|
|
10
|
+
//# sourceMappingURL=generation-resume.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generation-resume.d.ts","sourceRoot":"","sources":["../../../src/conversation/useConversationStream/generation-resume.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE3E;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GACrC,cAAc,YAAY,KACzB,OASF,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { SendCompletionDtoModeEnum } from '@epam/ai-dial-chat-api-client';
|
|
2
|
+
import { Conversation, MessageCustomContent, StreamChunk } from '@epam/ai-dial-chat-shared';
|
|
3
|
+
import { Dispatch, MutableRefObject, SetStateAction } from 'react';
|
|
4
|
+
/** Options accepted by {@link ConversationStreamTransport.streamCompletion}. */
|
|
5
|
+
export interface StreamCompletionOptions {
|
|
6
|
+
onChunk: (chunk: StreamChunk) => void;
|
|
7
|
+
onComplete: () => void | Promise<void>;
|
|
8
|
+
onError: (error: Error) => void;
|
|
9
|
+
signal: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Host-owned transport for the DIAL Core completion protocol. Implemented at
|
|
13
|
+
* the app edge — never hardcodes an `/api` path, CSRF handling, or a
|
|
14
|
+
* `server-api` import; the library only depends on this interface's shape.
|
|
15
|
+
*/
|
|
16
|
+
export interface ConversationStreamTransport {
|
|
17
|
+
/** Starts a completion; delivers chunks/completion/error through `options`, aborted via `options.signal`. */
|
|
18
|
+
streamCompletion(path: string, message: string | undefined, model: string, options: StreamCompletionOptions, customContent?: MessageCustomContent, generationId?: string, mode?: SendCompletionDtoModeEnum, messageIndex?: number, clientChannelId?: string): void;
|
|
19
|
+
/** Requests the backend stop an active generation. */
|
|
20
|
+
stopCompletion(params: {
|
|
21
|
+
generationId: string;
|
|
22
|
+
path: string;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
/** Opens a stream of resource-update events for `path`, until aborted via `signal`. */
|
|
25
|
+
watchConversation(path: string, signal: AbortSignal): Promise<ReadableStream<Uint8Array>>;
|
|
26
|
+
/** Reloads the persisted conversation by its full (bucket-qualified) id. */
|
|
27
|
+
getConversation(conversationId: string, signal?: AbortSignal): Promise<Conversation>;
|
|
28
|
+
}
|
|
29
|
+
/** Host-owned generation lifecycle, backing cross-navigation `AbortController` ownership. */
|
|
30
|
+
export interface ConversationGenerationLifecycle {
|
|
31
|
+
/** Starts (or replaces) tracking for a generation on `path`, returning its `AbortController`. */
|
|
32
|
+
startGeneration: (path: string, generationId: string) => AbortController;
|
|
33
|
+
/** Marks the generation identified by `path`/`generationId` complete, if it is still the active one. */
|
|
34
|
+
completeGeneration: (path: string, generationId: string) => void;
|
|
35
|
+
}
|
|
36
|
+
/** Optional host-owned client-channel connection, used to nudge tool-signin delivery. */
|
|
37
|
+
export interface ConversationStreamChannel {
|
|
38
|
+
channelId: string | null;
|
|
39
|
+
ensureConnected: () => void;
|
|
40
|
+
}
|
|
41
|
+
/** Optional host-owned overlay generation-lifecycle notifications. Each method is independently optional. */
|
|
42
|
+
export interface ConversationStreamOverlayNotifier {
|
|
43
|
+
notifyGenerationStart?: () => void;
|
|
44
|
+
notifyGenerationEnd?: () => void;
|
|
45
|
+
notifyStopGenerating?: () => void;
|
|
46
|
+
}
|
|
47
|
+
/** Shared mutable channel through which the displayed conversation's state is read/written. */
|
|
48
|
+
export interface ConversationStateAccessor {
|
|
49
|
+
setConversation: Dispatch<SetStateAction<Conversation | null>>;
|
|
50
|
+
conversationRef: MutableRefObject<Conversation | null>;
|
|
51
|
+
}
|
|
52
|
+
/** Parameters for {@link useConversationStream}. */
|
|
53
|
+
export interface UseConversationStreamParams {
|
|
54
|
+
conversationId: string | undefined;
|
|
55
|
+
state: ConversationStateAccessor;
|
|
56
|
+
transport: ConversationStreamTransport;
|
|
57
|
+
generation: ConversationGenerationLifecycle;
|
|
58
|
+
channel?: ConversationStreamChannel;
|
|
59
|
+
overlay?: ConversationStreamOverlayNotifier;
|
|
60
|
+
onStopError?: (error: Error) => void;
|
|
61
|
+
}
|
|
62
|
+
/** Return value of {@link useConversationStream}. */
|
|
63
|
+
export interface UseConversationStreamResult {
|
|
64
|
+
startStream: (conversationId: string, userContent: string, messageIndex: number, model: string, customContent?: MessageCustomContent, generationId?: string, mode?: SendCompletionDtoModeEnum) => void;
|
|
65
|
+
handleStop: () => void;
|
|
66
|
+
resumeIfAwaitingGeneration: (currentConversationId: string, conversation: Conversation) => void;
|
|
67
|
+
isStreaming: boolean;
|
|
68
|
+
canStopStreaming: boolean;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Owns completion-streaming state: per-path streaming/stoppable tracking,
|
|
72
|
+
* stale-chunk rejection, reload-after-complete, backend-driven stop, and
|
|
73
|
+
* hard-refresh resume detection — all driven through the injected
|
|
74
|
+
* `transport`/`generation`/`channel`/`overlay` capabilities rather than any
|
|
75
|
+
* app context or `server-api` import.
|
|
76
|
+
*/
|
|
77
|
+
export declare const useConversationStream: ({ conversationId, state: { setConversation, conversationRef }, transport, generation: { startGeneration, completeGeneration }, channel, overlay, onStopError, }: UseConversationStreamParams) => UseConversationStreamResult;
|
|
78
|
+
//# sourceMappingURL=useConversationStream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConversationStream.d.ts","sourceRoot":"","sources":["../../../src/conversation/useConversationStream/useConversationStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,WAAW,EACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,cAAc,EAKpB,MAAM,OAAO,CAAC;AAaf,gFAAgF;AAChF,MAAM,WAAW,uBAAuB;IACtC,OAAO,EA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B,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAAI,iKAQnC,2BAA2B,KAAG,2BAqXhC,CAAC"}
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
export * from './attachment/useAttachmentAction/useAttachmentAction';
|
|
2
|
+
export * from './attachment/useAttachmentValidation/useAttachmentValidation';
|
|
3
|
+
export { EXPORT_APP_NAME } from './conversation/conversation-transfer/export-conversation';
|
|
4
|
+
export { formatDateYM, formatDateYMD, } from './conversation/conversation-transfer/date';
|
|
5
|
+
export { formatQuotedNameList } from './conversation/conversation-transfer/import-conversation';
|
|
6
|
+
export * from './conversation/conversation-transfer/types';
|
|
2
7
|
export * from './conversation/useAttachmentUpload/useAttachmentUpload';
|
|
8
|
+
export * from './conversation/useConversationExport/useConversationExport';
|
|
9
|
+
export { attachmentsToDtos, attachmentToDto, } from './conversation/useConversationHandlers/attachment-to-dto';
|
|
10
|
+
export { createMessagePair, type MessagePair, } from './conversation/useConversationHandlers/message-factory';
|
|
11
|
+
export { hasActiveToolConfig, isMessageChanged, } from './conversation/useConversationHandlers/message-utils';
|
|
12
|
+
export { getStarterConversationText, getStarterSubmitText, } from './conversation/useConversationHandlers/starter-option';
|
|
13
|
+
export * from './conversation/useConversationHandlers/useConversationHandlers';
|
|
14
|
+
export * from './conversation/useConversationImport/useConversationImport';
|
|
3
15
|
export * from './conversation/useConversationScroll/useConversationScroll';
|
|
16
|
+
export { getConversationPath } from './conversation/useConversationStream/conversation-path';
|
|
17
|
+
export { isAwaitingGenerationResume } from './conversation/useConversationStream/generation-resume';
|
|
18
|
+
export * from './conversation/useConversationStream/useConversationStream';
|
|
4
19
|
export * from './conversation-sources/useConversationSources/useConversationSources';
|
|
5
20
|
export * from './usePageFileDrag/usePageFileDrag';
|
|
6
21
|
export * from './usePanelMaxWidth/usePanelMaxWidth';
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sDAAsD,CAAC;AACrE,cAAc,wDAAwD,CAAC;AACvE,cAAc,4DAA4D,CAAC;AAC3E,cAAc,sEAAsE,CAAC;AACrF,cAAc,mCAAmC,CAAC;AAClD,cAAc,qCAAqC,CAAC;AACpD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mDAAmD,CAAC;AAClE,cAAc,qCAAqC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sDAAsD,CAAC;AACrE,cAAc,8DAA8D,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,0DAA0D,CAAC;AAC3F,OAAO,EACL,YAAY,EACZ,aAAa,GACd,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0DAA0D,CAAC;AAChG,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wDAAwD,CAAC;AACvE,cAAc,4DAA4D,CAAC;AAC3E,OAAO,EACL,iBAAiB,EACjB,eAAe,GAChB,MAAM,0DAA0D,CAAC;AAClE,OAAO,EACL,iBAAiB,EACjB,KAAK,WAAW,GACjB,MAAM,wDAAwD,CAAC;AAChE,OAAO,EACL,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,uDAAuD,CAAC;AAC/D,cAAc,gEAAgE,CAAC;AAC/E,cAAc,4DAA4D,CAAC;AAC3E,cAAc,4DAA4D,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,wDAAwD,CAAC;AAC7F,OAAO,EAAE,0BAA0B,EAAE,MAAM,wDAAwD,CAAC;AACpG,cAAc,4DAA4D,CAAC;AAC3E,cAAc,sEAAsE,CAAC;AACrF,cAAc,mCAAmC,CAAC;AA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