@epam/ai-dial-chat-shared 1.2.0-dev.112 → 1.2.0-dev.115
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/hooks/useTextRefinement.js +66 -0
- package/index.d.ts +48 -0
- package/index.js +9 -8
- package/package.json +1 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { useCallback as e, useLayoutEffect as t, useRef as n, useState as r } from "react";
|
|
2
|
+
//#region src/hooks/useTextRefinement.ts
|
|
3
|
+
var i = /* @__PURE__ */ function(e) {
|
|
4
|
+
return e.Idle = "idle", e.Pending = "pending", e.Success = "success", e.Error = "error", e.Restored = "restored", e.Unchanged = "unchanged", e;
|
|
5
|
+
}({}), a = (i) => {
|
|
6
|
+
let [a, o] = r("idle"), [s, c] = r(!1), l = n(i), u = n(!1), d = n({
|
|
7
|
+
value: i.value,
|
|
8
|
+
resetKey: i.resetKey,
|
|
9
|
+
generation: 0,
|
|
10
|
+
controller: void 0,
|
|
11
|
+
baseline: void 0,
|
|
12
|
+
expected: void 0
|
|
13
|
+
}), f = e(() => {
|
|
14
|
+
let e = d.current;
|
|
15
|
+
e.generation++, e.controller?.abort(), e.controller = void 0, e.baseline = void 0, e.expected = void 0;
|
|
16
|
+
}, []), p = e(() => {
|
|
17
|
+
f(), u.current && (o("idle"), c(!1));
|
|
18
|
+
}, [f]);
|
|
19
|
+
t(() => (u.current = !0, () => {
|
|
20
|
+
u.current = !1, f();
|
|
21
|
+
}), [f]), t(() => {
|
|
22
|
+
let e = l.current, t = d.current;
|
|
23
|
+
l.current = i;
|
|
24
|
+
let n = t.value !== i.value, r = n && t.expected === i.value;
|
|
25
|
+
t.resetKey !== i.resetKey || e.onRefine && !i.onRefine || !e.disabled && i.disabled || n && !r ? p() : r && (t.expected = void 0), t.value = i.value, t.resetKey = i.resetKey;
|
|
26
|
+
});
|
|
27
|
+
let m = e(async () => {
|
|
28
|
+
let e = l.current, t = d.current;
|
|
29
|
+
if (!u.current || !e.onRefine || e.disabled || !e.value.trim() || t.controller || t.expected !== void 0) return;
|
|
30
|
+
let n = new AbortController();
|
|
31
|
+
t.controller = n;
|
|
32
|
+
let r = ++t.generation, i = e.value, a = () => u.current && r === t.generation && !n.signal.aborted && l.current.value === i;
|
|
33
|
+
o("pending");
|
|
34
|
+
try {
|
|
35
|
+
let r = await e.onRefine(i, n.signal);
|
|
36
|
+
if (!a()) return;
|
|
37
|
+
if (typeof r != "string" || !r.trim()) throw Error("Empty refinement");
|
|
38
|
+
if (r === i) {
|
|
39
|
+
o("unchanged");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
t.baseline ??= i, t.expected = r, c(!0), o("success"), l.current.onChange(r);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
if (!a()) return;
|
|
45
|
+
typeof e == "object" && e && "name" in e && e.name === "AbortError" ? o("idle") : o("error");
|
|
46
|
+
} finally {
|
|
47
|
+
r === t.generation && (t.controller = void 0);
|
|
48
|
+
}
|
|
49
|
+
}, []), h = e(() => {
|
|
50
|
+
let e = d.current;
|
|
51
|
+
if (!u.current || l.current.disabled || e.controller || e.baseline === void 0) return;
|
|
52
|
+
let t = e.baseline;
|
|
53
|
+
e.baseline = void 0, e.expected = t, c(!1), o("restored"), l.current.onChange(t);
|
|
54
|
+
}, []);
|
|
55
|
+
return {
|
|
56
|
+
state: a,
|
|
57
|
+
isPending: a === "pending",
|
|
58
|
+
canRefine: !!(i.onRefine && !i.disabled && i.value.trim() && a !== "pending"),
|
|
59
|
+
canUndo: s,
|
|
60
|
+
refine: m,
|
|
61
|
+
undo: h,
|
|
62
|
+
reset: p
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
//#endregion
|
|
66
|
+
export { i as TextRefinementState, a as useTextRefinement };
|
package/index.d.ts
CHANGED
|
@@ -2416,6 +2416,37 @@ export declare interface TextCharacterRangeSelector {
|
|
|
2416
2416
|
end: number;
|
|
2417
2417
|
}
|
|
2418
2418
|
|
|
2419
|
+
/** Asynchronous rewriting callback supplied by the consuming host. */
|
|
2420
|
+
export declare type TextRefinementCallback = (value: string, signal: AbortSignal) => Promise<string>;
|
|
2421
|
+
|
|
2422
|
+
/** Controls and feedback for a single field. */
|
|
2423
|
+
export declare interface TextRefinementResult {
|
|
2424
|
+
/** Current field-local feedback state. */
|
|
2425
|
+
state: TextRefinementState;
|
|
2426
|
+
/** Whether this field has a request in progress. */
|
|
2427
|
+
isPending: boolean;
|
|
2428
|
+
/** Whether the current value can be refined. */
|
|
2429
|
+
canRefine: boolean;
|
|
2430
|
+
/** Whether an original baseline can be restored. */
|
|
2431
|
+
canUndo: boolean;
|
|
2432
|
+
/** Refines the latest committed value; duplicate activation is ignored. */
|
|
2433
|
+
refine: () => Promise<void>;
|
|
2434
|
+
/** Restores the baseline from before the first successful refinement. */
|
|
2435
|
+
undo: () => void;
|
|
2436
|
+
/** Cancels work and clears feedback and Undo without modifying the value. */
|
|
2437
|
+
reset: () => void;
|
|
2438
|
+
}
|
|
2439
|
+
|
|
2440
|
+
/** Field-local refinement feedback state. */
|
|
2441
|
+
export declare enum TextRefinementState {
|
|
2442
|
+
Idle = "idle",
|
|
2443
|
+
Pending = "pending",
|
|
2444
|
+
Success = "success",
|
|
2445
|
+
Error = "error",
|
|
2446
|
+
Restored = "restored",
|
|
2447
|
+
Unchanged = "unchanged"
|
|
2448
|
+
}
|
|
2449
|
+
|
|
2419
2450
|
/** A single selectable UI theme. */
|
|
2420
2451
|
export declare interface Theme {
|
|
2421
2452
|
/** Unique theme identifier (e.g. `'dark'`, `'light'`). */
|
|
@@ -2653,4 +2684,21 @@ export declare interface UserProfile {
|
|
|
2653
2684
|
isAdmin: boolean;
|
|
2654
2685
|
}
|
|
2655
2686
|
|
|
2687
|
+
/** Preserves an author's draft and Undo baseline across asynchronous controlled updates. */
|
|
2688
|
+
export declare const useTextRefinement: (options: UseTextRefinementOptions) => TextRefinementResult;
|
|
2689
|
+
|
|
2690
|
+
/** Controlled value and lifecycle inputs for one refinable field. */
|
|
2691
|
+
export declare interface UseTextRefinementOptions {
|
|
2692
|
+
/** Current controlled field value. */
|
|
2693
|
+
value: string;
|
|
2694
|
+
/** Host rewriting callback. Omission disables refinement and clears its state. */
|
|
2695
|
+
onRefine?: TextRefinementCallback;
|
|
2696
|
+
/** Publishes a successful result or the original Undo baseline. */
|
|
2697
|
+
onChange: (value: string) => void;
|
|
2698
|
+
/** Disables refinement and cancels active work when true. Defaults to false. */
|
|
2699
|
+
disabled?: boolean;
|
|
2700
|
+
/** Draft identity; changing it resets state even when text is equal. */
|
|
2701
|
+
resetKey?: unknown;
|
|
2702
|
+
}
|
|
2703
|
+
|
|
2656
2704
|
export { }
|
package/index.js
CHANGED
|
@@ -56,11 +56,12 @@ import { MarkdownWithPlaceholders as et } from "./components/MarkdownWithPlaceho
|
|
|
56
56
|
import { useCollapsedText as tt } from "./hooks/useCollapsedText.js";
|
|
57
57
|
import { useAvailableHeightCap as nt } from "./hooks/useAvailableHeightCap.js";
|
|
58
58
|
import { useIsMobile as rt } from "./hooks/useIsMobile.js";
|
|
59
|
-
import {
|
|
60
|
-
import {
|
|
61
|
-
import {
|
|
62
|
-
import {
|
|
63
|
-
import {
|
|
64
|
-
import {
|
|
65
|
-
import {
|
|
66
|
-
|
|
59
|
+
import { TextRefinementState as it, useTextRefinement as at } from "./hooks/useTextRefinement.js";
|
|
60
|
+
import { DialFileManagerActionProfile as ot, DialFileManagerVariant as st } from "./file-manager/file-manager-variant.js";
|
|
61
|
+
import { getParentFolderPath as ct, isHiddenPath as lt } from "./file-manager/path.js";
|
|
62
|
+
import { FileUploadStatus as ut } from "./file-manager/upload-batch.js";
|
|
63
|
+
import { useGridEditingScroll as dt } from "./file-manager/useGridEditingScroll/useGridEditingScroll.js";
|
|
64
|
+
import { OperationLoaderModal as ft } from "./file-manager/OperationLoaderModal/OperationLoaderModal.js";
|
|
65
|
+
import { UploadProgressModal as pt } from "./file-manager/UploadProgressModal/UploadProgressModal.js";
|
|
66
|
+
import { isSkillSelectionUnsupported as mt } from "./utils/is-skill-selection-unsupported.js";
|
|
67
|
+
export { f as AttachmentErrorReason, p as AttachmentType, fe as BASE_LG_ICON_PROPS, pe as BASE_MD_ICON_PROPS, ze as CHAT_SHARED_CLASS, Xe as COMPACT_MARKDOWN_CLASS_NAMES, m as CatalogEntityType, _ as CodeBlockTheme, e as ConversationTransferErrorCode, t as ConversationTransferJobStatus, n as ConversationTransferSubjectKind, r as ConversationTransferUnitKind, i as ConversationTransferWarningCode, Ae as CopyButton, je as CopyIconButton, Ze as DEFAULT_MARKDOWN_CLASS_NAMES, Ue as DEFAULT_MARKDOWN_TABLE_DOWNLOAD_FILENAME, Se as DESKTOP_BREAKPOINT_PX, Ce as DESKTOP_MEDIA_QUERY, ke as DeploymentIcon, ot as DialFileManagerActionProfile, st as DialFileManagerVariant, ne as ENTITY_TYPE_BG_COLOR, re as ENTITY_TYPE_COLOR, Ie as EntityHeader, Pe as EntityTypeLabel, Fe as FeaturedChip, h as FileExtension, ut as FileUploadStatus, a as FilterTab, me as HIDDEN_FILE, Oe as InitialsAvatar, Ne as ItemHeader, ge as MARKDOWN_EDITOR_MAX_HEIGHT_CLASS_NAME, ye as MARKDOWN_EDITOR_PREVIEW_LIST_CLASS_NAME, We as MARKDOWN_TABLE_CSV_MIME_TYPE, $e as MDMessageViewer, g as MIMEType, v as MIME_TYPE_ALIASES, y as MIME_TYPE_AUDIO_PREFIX, b as MIME_TYPE_EXT_MAP, x as MIME_TYPE_WILDCARD, we as MOBILE_MAX_WIDTH_PX, Te as MOBILE_MEDIA_QUERY, He as MarkdownCodeBlock, Je as MarkdownRenderer, qe as MarkdownTable, Ge as MarkdownTableCopyFormat, et as MarkdownWithPlaceholders, o as MessageRating, s as MessageRole, ft as OperationLoaderModal, A as PROHIBITED_CONVERSATION_NAME_CHARS_RE, ie as PROMPT_PARAM_DEFAULT_SEPARATOR, ae as PROMPT_PARAM_PATTERN, oe as PROMPT_VARIABLE_CLASS_NAME, Me as PanelEmptyState, Qe as PlainTextRenderer, _e as RESIZABLE_FIELD_MAX_HEIGHT_CSS_VARIABLE, ve as RESIZABLE_TEXTAREA_CLASS_NAME, c as RequestStatus, Le as ResourceSummary, d as ResponseFormat, be as SELECT_LIST_MAX_HEIGHT_CLASS_NAME, xe as SELECT_LIST_MAX_HEIGHT_PX, l as StageStatus, u as StatusEvent, he as TAG_INPUT_TAG_CLASS_NAME, Re as TableHeader, it as TextRefinementState, pt as UploadProgressModal, Y as base64ToBlob, I as buildCssVars, se as buildPromptParamDefaults, V as copyMarkdownAsRichText, H as copyToClipboard, Ye as defaultMarkdownComponents, X as downloadTextFile, Z as ensureDownloadFilename, De as extractInitials, ce as extractPromptParams, K as formatCost, G as formatFileSize, W as formatLastUsed, q as formatPrice, J as formatUnitPrice, de as generateUUID, S as getAttachmentTypeFromMime, C as getBaseMimeType, Q as getFileExtensionForLanguage, ct as getParentFolderPath, j as getUtf8ByteLength, w as inferMimeTypeFromPath, D as isAnnotationSelector, B as isAudioTranscriptionSupported, lt as isHiddenPath, mt as isSkillSelectionUnsupported, L as isStatusMessage, U as markdownToRichTextHtml, F as mergeClasses, R as messageAttachmentToDisplayAttachment, z as messageAttachmentsToDisplayAttachments, T as normalizeMimeType, O as normalizePersistedHtmlTagAttachmentType, k as normalizeRawAnnotations, Ee as pickAvatarColor, le as rehypePromptVariables, ue as resolvePromptParams, Ve as restrainedSyntaxTheme, M as sanitizeConversationName, Ke as serializeMarkdownTableRows, N as stripTrailingDots, E as stripUrlQueryAndFragment, $ as triggerAnchorDownload, ee as triggerBlobDownload, P as truncateToUtf8Bytes, te as tryBase64ToBytes, nt as useAvailableHeightCap, Be as useCodeCopy, tt as useCollapsedText, dt as useGridEditingScroll, rt as useIsMobile, at as useTextRefinement };
|
package/package.json
CHANGED