@bitbaum/chatkit 0.18.1 → 0.19.0
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 +161 -0
- package/dist/react/AttachMenu.d.ts +18 -1
- package/dist/react/AttachMenu.d.ts.map +1 -1
- package/dist/react/AttachMenu.js +8 -4
- package/dist/react/AttachMenu.js.map +1 -1
- package/dist/react/ChatApp.d.ts +79 -5
- package/dist/react/ChatApp.d.ts.map +1 -1
- package/dist/react/ChatApp.js +113 -7
- package/dist/react/ChatApp.js.map +1 -1
- package/dist/react/ChatHistory.d.ts +7 -1
- package/dist/react/ChatHistory.d.ts.map +1 -1
- package/dist/react/ChatHistory.js +2 -2
- package/dist/react/ChatHistory.js.map +1 -1
- package/dist/react/Composer.d.ts +20 -3
- package/dist/react/Composer.d.ts.map +1 -1
- package/dist/react/Composer.js +19 -4
- package/dist/react/Composer.js.map +1 -1
- package/dist/react/Thread.d.ts +48 -2
- package/dist/react/Thread.d.ts.map +1 -1
- package/dist/react/Thread.js +13 -6
- package/dist/react/Thread.js.map +1 -1
- package/dist/react/attach.d.ts +1 -1
- package/dist/react/attach.d.ts.map +1 -1
- package/dist/react/index.d.ts +10 -10
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +4 -4
- package/dist/react/index.js.map +1 -1
- package/dist/react/use-attachments.d.ts +17 -0
- package/dist/react/use-attachments.d.ts.map +1 -1
- package/dist/react/use-attachments.js +89 -72
- package/dist/react/use-attachments.js.map +1 -1
- package/dist/react/use-chat-app.d.ts +53 -3
- package/dist/react/use-chat-app.d.ts.map +1 -1
- package/dist/react/use-chat-app.js +126 -15
- package/dist/react/use-chat-app.js.map +1 -1
- package/package.json +1 -1
- package/styles.css +64 -1
package/dist/react/index.d.ts
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
* app's tokens through `--ck-*` variables (see styles.css).
|
|
9
9
|
*/
|
|
10
10
|
export { Composer, DEFAULT_COMPOSER_LABELS } from "./Composer.js";
|
|
11
|
-
export type { ComposerProps, ComposerLabels, ComposerLabelOverrides, ComposerVoice, } from "./Composer.js";
|
|
12
|
-
export { ChatThread, ChatMessage, ChatReplies, ChatStarters, ThinkingRow, formatThinkingDuration, DEFAULT_THREAD_LABELS, } from "./Thread.js";
|
|
13
|
-
export type { ChatMessageData, ChatSpeaker, LiveTurn, Starter, Thinking, ThinkingStep, ThreadLabels, } from "./Thread.js";
|
|
11
|
+
export type { ComposerProps, ComposerLabels, ComposerLabelOverrides, ComposerVoice, ComposerHandle, } from "./Composer.js";
|
|
12
|
+
export { ChatThread, ChatMessage, ChatReplies, ChatStarters, starterParts, ThinkingRow, formatThinkingDuration, DEFAULT_THREAD_LABELS, } from "./Thread.js";
|
|
13
|
+
export type { ChatMessageData, ChatFailure, FooterInfo, MessageChip, ChatSpeaker, LiveTurn, Starter, Thinking, ThinkingStep, ThreadLabels, } from "./Thread.js";
|
|
14
14
|
export { ChatScreen } from "./Screen.js";
|
|
15
15
|
export { Markdown, SourcesRow, defaultRenderLink, defaultRenderCitation } from "./Markdown.js";
|
|
16
16
|
export { AnswerActions, DEFAULT_ANSWER_ACTIONS_LABELS } from "./AnswerActions.js";
|
|
@@ -22,17 +22,17 @@ export type { CitationMap, RenderLink, RenderCitation, RenderSources } from "./M
|
|
|
22
22
|
export { useDictation } from "./use-dictation.js";
|
|
23
23
|
export type { DictationController, DictationStatus, UseDictationOptions } from "./use-dictation.js";
|
|
24
24
|
export { AttachMenu, DEFAULT_ATTACH_MENU_LABELS } from "./AttachMenu.js";
|
|
25
|
-
export type { AttachMenuLabels } from "./AttachMenu.js";
|
|
26
|
-
export { useAttachments } from "./use-attachments.js";
|
|
27
|
-
export type { AttachmentsController } from "./use-attachments.js";
|
|
25
|
+
export type { AttachExtra, AttachMenuLabels } from "./AttachMenu.js";
|
|
26
|
+
export { useAttachments, readAttachmentFile } from "./use-attachments.js";
|
|
27
|
+
export type { AttachmentsController, ReadAttachment } from "./use-attachments.js";
|
|
28
28
|
export { useClipboard, useStickToBottom, useViewportHeight, useAutoGrow } from "./hooks.js";
|
|
29
29
|
export { RichAnswerBlock, ChartTableFigure } from "./RichBlock.js";
|
|
30
30
|
export { RichRenderersContext, useRichRenderers } from "./renderers.js";
|
|
31
31
|
export type { RichRenderers } from "./renderers.js";
|
|
32
|
-
export { ChatApp, DEFAULT_CHAT_APP_LABELS } from "./ChatApp.js";
|
|
33
|
-
export type { ChatAppProps, ChatAppLabels } from "./ChatApp.js";
|
|
32
|
+
export { ChatApp, DEFAULT_CHAT_APP_LABELS, takeDeepLink } from "./ChatApp.js";
|
|
33
|
+
export type { ChatAppProps, ChatAppLabels, ChatAppHandle, ChatAppFooterInfo, InitialMessage, } from "./ChatApp.js";
|
|
34
34
|
export { ChatHistory } from "./ChatHistory.js";
|
|
35
35
|
export type { ChatHistoryProps } from "./ChatHistory.js";
|
|
36
|
-
export { useChatApp, isTemporaryId } from "./use-chat-app.js";
|
|
37
|
-
export type { ChatTransport, ChatTurn, ChatTurnResult, ChatAppController, ChatAppProblem, UseChatAppOptions, } from "./use-chat-app.js";
|
|
36
|
+
export { useChatApp, isTemporaryId, ChatTurnError, chatTurnFailure } from "./use-chat-app.js";
|
|
37
|
+
export type { ChatTransport, ChatTurn, ChatTurnResult, ChatAppController, ChatAppProblem, SendOptions, UseChatAppOptions, } from "./use-chat-app.js";
|
|
38
38
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAClE,YAAY,EACV,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH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AkB,EAAE,MAAM,sBAAsB,CAAC;AAC1E,YAAY,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACxE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC9E,YAAY,EACV,YAAY,EACZ,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,cAAc,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC9F,YAAY,EACV,aAAa,EACb,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,iBAAiB,GAClB,MAAM,mBAAmB,CAAC"}
|
package/dist/react/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* app's tokens through `--ck-*` variables (see styles.css).
|
|
9
9
|
*/
|
|
10
10
|
export { Composer, DEFAULT_COMPOSER_LABELS } from "./Composer.js";
|
|
11
|
-
export { ChatThread, ChatMessage, ChatReplies, ChatStarters, ThinkingRow, formatThinkingDuration, DEFAULT_THREAD_LABELS, } from "./Thread.js";
|
|
11
|
+
export { ChatThread, ChatMessage, ChatReplies, ChatStarters, starterParts, ThinkingRow, formatThinkingDuration, DEFAULT_THREAD_LABELS, } from "./Thread.js";
|
|
12
12
|
export { ChatScreen } from "./Screen.js";
|
|
13
13
|
export { Markdown, SourcesRow, defaultRenderLink, defaultRenderCitation } from "./Markdown.js";
|
|
14
14
|
export { AnswerActions, DEFAULT_ANSWER_ACTIONS_LABELS } from "./AnswerActions.js";
|
|
@@ -16,11 +16,11 @@ export { useSpeech } from "./use-speech.js";
|
|
|
16
16
|
export { Sheet, prefersSheet } from "./Sheet.js";
|
|
17
17
|
export { useDictation } from "./use-dictation.js";
|
|
18
18
|
export { AttachMenu, DEFAULT_ATTACH_MENU_LABELS } from "./AttachMenu.js";
|
|
19
|
-
export { useAttachments } from "./use-attachments.js";
|
|
19
|
+
export { useAttachments, readAttachmentFile } from "./use-attachments.js";
|
|
20
20
|
export { useClipboard, useStickToBottom, useViewportHeight, useAutoGrow } from "./hooks.js";
|
|
21
21
|
export { RichAnswerBlock, ChartTableFigure } from "./RichBlock.js";
|
|
22
22
|
export { RichRenderersContext, useRichRenderers } from "./renderers.js";
|
|
23
|
-
export { ChatApp, DEFAULT_CHAT_APP_LABELS } from "./ChatApp.js";
|
|
23
|
+
export { ChatApp, DEFAULT_CHAT_APP_LABELS, takeDeepLink } from "./ChatApp.js";
|
|
24
24
|
export { ChatHistory } from "./ChatHistory.js";
|
|
25
|
-
export { useChatApp, isTemporaryId } from "./use-chat-app.js";
|
|
25
|
+
export { useChatApp, isTemporaryId, ChatTurnError, chatTurnFailure } from "./use-chat-app.js";
|
|
26
26
|
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAQlE,OAAO,EACL,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAarB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AAElF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1E,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAExE,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQ9E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -23,4 +23,21 @@ export type AttachmentsController = {
|
|
|
23
23
|
* that survives every send). From loki `hooks/use-attachments.ts`.
|
|
24
24
|
*/
|
|
25
25
|
export declare function useAttachments(limits?: Partial<AttachmentLimits>, notes?: Partial<AttachmentNotes>): AttachmentsController;
|
|
26
|
+
export type ReadAttachment = {
|
|
27
|
+
attachment: StagedAttachment;
|
|
28
|
+
note?: undefined;
|
|
29
|
+
} | {
|
|
30
|
+
attachment?: undefined;
|
|
31
|
+
note: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* One file read the way the composer stages it: an image shrunk to
|
|
35
|
+
* `maxImageEdge` and judged by its size after that, a text file read up to
|
|
36
|
+
* `maxTextChars`, anything else refused — with the reason as a sentence from
|
|
37
|
+
* `notes`, never a throw. `preview: true` adds an object URL the caller must
|
|
38
|
+
* revoke. `useAttachments` and `ChatApp`'s `send` both read files through it.
|
|
39
|
+
*/
|
|
40
|
+
export declare function readAttachmentFile(file: File, limits?: Partial<AttachmentLimits>, notes?: Partial<AttachmentNotes>, { preview }?: {
|
|
41
|
+
preview?: boolean;
|
|
42
|
+
}): Promise<ReadAttachment>;
|
|
26
43
|
//# sourceMappingURL=use-attachments.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-attachments.d.ts","sourceRoot":"","sources":["../../src/react/use-attachments.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4C,KAAK,cAAc,EAAE,MAAM,OAAO,CAAC;AAEtF,OAAO,EAQL,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAChC;uEACmE;IACnE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,QAAQ,EAAE,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,EAAE,GAAG,IAAI,KAAK,IAAI,CAAC;IACpD,wDAAwD;IACxD,YAAY,EAAE,CAAC,CAAC,EAAE,cAAc,KAA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EAAE,OAAO,CAAC;IACd,MAAM,EAAE,gBAAgB,CAAC;CAC1B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,MAAM,GAAE,OAAO,CAAC,gBAAgB,CAAM,EACtC,KAAK,GAAE,OAAO,CAAC,eAAe,CAAM,GACnC,qBAAqB,CAsHvB;AAED,MAAM,MAAM,cAAc,GACxB;IAAE,UAAU,EAAE,gBAAgB,CAAC;IAAC,IAAI,CAAC,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,UAAU,CAAC,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhG;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,IAAI,EACV,MAAM,GAAE,OAAO,CAAC,gBAAgB,CAAM,EACtC,KAAK,GAAE,OAAO,CAAC,eAAe,CAAM,EACpC,EAAE,OAAe,EAAE,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO,GAC9C,OAAO,CAAC,cAAc,CAAC,CAkDzB"}
|
|
@@ -39,72 +39,18 @@ export function useAttachments(limits = {}, notes = {}) {
|
|
|
39
39
|
return prev;
|
|
40
40
|
return [...prev, item];
|
|
41
41
|
}), [maxFiles]);
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
shrink(file, maxImageEdge, maxImageBytes)
|
|
53
|
-
.then((dataUrl) => {
|
|
54
|
-
if (!dataUrl) {
|
|
55
|
-
tooLarge();
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const previewUrl = URL.createObjectURL(file);
|
|
59
|
-
previews.current.add(previewUrl);
|
|
60
|
-
add({
|
|
61
|
-
kind: "image",
|
|
62
|
-
name: name.replace(/\.(png|gif|webp|jpe?g)$/i, "") + ".jpg",
|
|
63
|
-
mimeType: "image/jpeg",
|
|
64
|
-
dataBase64: stripDataUrlBase64(dataUrl),
|
|
65
|
-
previewUrl,
|
|
66
|
-
});
|
|
67
|
-
})
|
|
68
|
-
.catch(() => setNote(say.current.unreadable(name)));
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
if (file.size > maxImageBytes) {
|
|
72
|
-
tooLarge();
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const reader = new FileReader();
|
|
76
|
-
reader.onload = () => {
|
|
77
|
-
const previewUrl = URL.createObjectURL(file);
|
|
78
|
-
previews.current.add(previewUrl);
|
|
79
|
-
add({
|
|
80
|
-
kind: "image",
|
|
81
|
-
name,
|
|
82
|
-
mimeType: file.type,
|
|
83
|
-
dataBase64: stripDataUrlBase64(String(reader.result ?? "")),
|
|
84
|
-
previewUrl,
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
reader.onerror = () => setNote(say.current.unreadable(name));
|
|
88
|
-
reader.readAsDataURL(file);
|
|
89
|
-
}, [add, maxImageBytes, maxImageEdge]);
|
|
90
|
-
const stageText = useCallback((file) => {
|
|
91
|
-
if (!isTextFile(file.name, file.type)) {
|
|
92
|
-
setNote(say.current.wrongType(file.name));
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
if (file.size > maxTextChars) {
|
|
96
|
-
setNote(say.current.textTooLarge(file.name, Math.round(maxTextChars / 1000)));
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
const reader = new FileReader();
|
|
100
|
-
reader.onload = () => add({
|
|
101
|
-
kind: "text",
|
|
102
|
-
name: file.name,
|
|
103
|
-
content: String(reader.result ?? "").slice(0, maxTextChars),
|
|
42
|
+
const stage = useCallback((file) => {
|
|
43
|
+
const limits = { maxFiles, maxImageBytes, maxImageEdge, maxTextChars };
|
|
44
|
+
void readAttachmentFile(file, limits, say.current, { preview: true }).then((read) => {
|
|
45
|
+
if (read.note !== undefined) {
|
|
46
|
+
setNote(read.note);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (read.attachment.previewUrl)
|
|
50
|
+
previews.current.add(read.attachment.previewUrl);
|
|
51
|
+
add(read.attachment);
|
|
104
52
|
});
|
|
105
|
-
|
|
106
|
-
reader.readAsText(file);
|
|
107
|
-
}, [add, maxTextChars]);
|
|
53
|
+
}, [add, maxFiles, maxImageBytes, maxImageEdge, maxTextChars]);
|
|
108
54
|
const addFiles = useCallback((files) => {
|
|
109
55
|
if (!files)
|
|
110
56
|
return;
|
|
@@ -115,12 +61,9 @@ export function useAttachments(limits = {}, notes = {}) {
|
|
|
115
61
|
return;
|
|
116
62
|
}
|
|
117
63
|
for (const file of Array.from(files).slice(0, room)) {
|
|
118
|
-
|
|
119
|
-
stageImage(file);
|
|
120
|
-
else
|
|
121
|
-
stageText(file);
|
|
64
|
+
stage(file);
|
|
122
65
|
}
|
|
123
|
-
}, [maxFiles,
|
|
66
|
+
}, [maxFiles, stage]);
|
|
124
67
|
const addFromPaste = useCallback((e) => {
|
|
125
68
|
const items = e.clipboardData?.items;
|
|
126
69
|
if (!items)
|
|
@@ -132,10 +75,10 @@ export function useAttachments(limits = {}, notes = {}) {
|
|
|
132
75
|
for (const item of images) {
|
|
133
76
|
const file = item.getAsFile();
|
|
134
77
|
if (file)
|
|
135
|
-
|
|
78
|
+
stage(file);
|
|
136
79
|
}
|
|
137
80
|
return true;
|
|
138
|
-
}, [
|
|
81
|
+
}, [stage]);
|
|
139
82
|
const revoke = (a) => {
|
|
140
83
|
if (!a.previewUrl)
|
|
141
84
|
return;
|
|
@@ -171,4 +114,78 @@ export function useAttachments(limits = {}, notes = {}) {
|
|
|
171
114
|
limits: lim,
|
|
172
115
|
};
|
|
173
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* One file read the way the composer stages it: an image shrunk to
|
|
119
|
+
* `maxImageEdge` and judged by its size after that, a text file read up to
|
|
120
|
+
* `maxTextChars`, anything else refused — with the reason as a sentence from
|
|
121
|
+
* `notes`, never a throw. `preview: true` adds an object URL the caller must
|
|
122
|
+
* revoke. `useAttachments` and `ChatApp`'s `send` both read files through it.
|
|
123
|
+
*/
|
|
124
|
+
export async function readAttachmentFile(file, limits = {}, notes = {}, { preview = false } = {}) {
|
|
125
|
+
const { maxImageBytes, maxTextChars, maxImageEdge } = { ...DEFAULT_ATTACHMENT_LIMITS, ...limits };
|
|
126
|
+
const say = { ...DEFAULT_ATTACHMENT_NOTES, ...notes };
|
|
127
|
+
const previewOf = () => (preview ? URL.createObjectURL(file) : undefined);
|
|
128
|
+
if (isImageMime(file.type)) {
|
|
129
|
+
const name = file.name || "screenshot.png";
|
|
130
|
+
const tooLarge = { note: say.imageTooLarge(name, Math.round(maxImageBytes / 1_000_000)) };
|
|
131
|
+
try {
|
|
132
|
+
if (maxImageEdge > 0) {
|
|
133
|
+
// Shrink first, then judge the size: a 4 MB screenshot is fine once it
|
|
134
|
+
// is the 300 KB it needed to be.
|
|
135
|
+
const dataUrl = await shrink(file, maxImageEdge, maxImageBytes);
|
|
136
|
+
if (!dataUrl)
|
|
137
|
+
return tooLarge;
|
|
138
|
+
return {
|
|
139
|
+
attachment: {
|
|
140
|
+
kind: "image",
|
|
141
|
+
name: name.replace(/\.(png|gif|webp|jpe?g)$/i, "") + ".jpg",
|
|
142
|
+
mimeType: "image/jpeg",
|
|
143
|
+
dataBase64: stripDataUrlBase64(dataUrl),
|
|
144
|
+
previewUrl: previewOf(),
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if (file.size > maxImageBytes)
|
|
149
|
+
return tooLarge;
|
|
150
|
+
const dataUrl = await readAs(file, "dataUrl");
|
|
151
|
+
return {
|
|
152
|
+
attachment: {
|
|
153
|
+
kind: "image",
|
|
154
|
+
name,
|
|
155
|
+
mimeType: file.type,
|
|
156
|
+
dataBase64: stripDataUrlBase64(dataUrl),
|
|
157
|
+
previewUrl: previewOf(),
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return { note: say.unreadable(name) };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (!isTextFile(file.name, file.type))
|
|
166
|
+
return { note: say.wrongType(file.name) };
|
|
167
|
+
if (file.size > maxTextChars) {
|
|
168
|
+
return { note: say.textTooLarge(file.name, Math.round(maxTextChars / 1000)) };
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
const content = await readAs(file, "text");
|
|
172
|
+
return {
|
|
173
|
+
attachment: { kind: "text", name: file.name, content: content.slice(0, maxTextChars) },
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return { note: say.unreadable(file.name) };
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function readAs(file, as) {
|
|
181
|
+
return new Promise((resolve, reject) => {
|
|
182
|
+
const reader = new FileReader();
|
|
183
|
+
reader.onload = () => resolve(String(reader.result ?? ""));
|
|
184
|
+
reader.onerror = () => reject(reader.error);
|
|
185
|
+
if (as === "text")
|
|
186
|
+
reader.readAsText(file);
|
|
187
|
+
else
|
|
188
|
+
reader.readAsDataURL(file);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
174
191
|
//# sourceMappingURL=use-attachments.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-attachments.js","sourceRoot":"","sources":["../../src/react/use-attachments.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAuB,MAAM,OAAO,CAAC;AACtF,OAAO,EAAE,WAAW,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,aAAa,EACb,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,MAAM,GAKP,MAAM,mBAAmB,CAAC;AAmB3B;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,SAAoC,EAAE,EACtC,QAAkC,EAAE;IA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from "../attachments.js";
|
|
2
2
|
import { type ConversationStore, type ConversationSummary } from "../conversations.js";
|
|
3
|
-
import type { ChatMessageData, LiveTurn } from "./Thread.js";
|
|
3
|
+
import type { ChatFailure, ChatMessageData, LiveTurn, MessageChip } from "./Thread.js";
|
|
4
4
|
/** One turn, as ChatApp hands it to the product. */
|
|
5
5
|
export type ChatTurn = {
|
|
6
6
|
/** The stored conversation, or null in a temporary chat (nothing is kept). */
|
|
7
7
|
conversationId: string | null;
|
|
8
|
+
/** This chat's id on the page: the stored id, or — in a temporary chat — a
|
|
9
|
+
* page-only id, the one `onTemporaryEnd` names when the chat ends. A
|
|
10
|
+
* product that keeps a hidden server row for a temporary chat keys it here. */
|
|
11
|
+
chatId: string;
|
|
8
12
|
temporary: boolean;
|
|
9
13
|
/** What the person wrote (or the composer's attachment-only words). */
|
|
10
14
|
text: string;
|
|
@@ -16,6 +20,38 @@ export type ChatTurn = {
|
|
|
16
20
|
/** What has arrived so far — the WHOLE text each time, a status line before
|
|
17
21
|
* the first word, the steps taken. Call it as often as you like. */
|
|
18
22
|
update: (live: LiveTurn) => void;
|
|
23
|
+
/** Whether Stop keeps what has arrived for THIS turn, overriding ChatApp's
|
|
24
|
+
* `stopKeepsPartial` — `false` while the text so far is unchecked (Heidi's
|
|
25
|
+
* variety gate), `true` once it is. Call it any time before the turn ends. */
|
|
26
|
+
stopKeepsPartial: (keep: boolean) => void;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Throw this from a transport to say why a turn failed in the reader's
|
|
30
|
+
* words: the failed bubble shows `message`, and `kind` (the product's own
|
|
31
|
+
* code, e.g. "quota" or "no-vision") travels with that message as
|
|
32
|
+
* `failure.kind` for a footer to link the fix. Any other error shows the
|
|
33
|
+
* thread's `failed` label — a raw `TypeError: Failed to fetch` is never
|
|
34
|
+
* shown to a reader — unless ChatApp's `failureMessage` maps it.
|
|
35
|
+
*/
|
|
36
|
+
export declare class ChatTurnError extends Error {
|
|
37
|
+
readonly kind?: string;
|
|
38
|
+
constructor(message: string, options?: {
|
|
39
|
+
kind?: string;
|
|
40
|
+
cause?: unknown;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* What a failed turn keeps: a `ChatTurnError`'s words and kind, a plain
|
|
45
|
+
* `{ message, kind }` object as thrown, or what `map` makes of anything
|
|
46
|
+
* else. Never an ordinary Error's message — that is for the console.
|
|
47
|
+
*/
|
|
48
|
+
export declare function chatTurnFailure(error: unknown, map?: (error: unknown) => string | null | undefined): ChatFailure;
|
|
49
|
+
/** How a page sends for the person (`ChatAppHandle.send`). */
|
|
50
|
+
export type SendOptions = {
|
|
51
|
+
/** Start a new chat for it instead of adding to the open one. */
|
|
52
|
+
newChat?: boolean;
|
|
53
|
+
/** The product's own things shown on the person's message (see `MessageChip`). */
|
|
54
|
+
chips?: readonly MessageChip[];
|
|
19
55
|
};
|
|
20
56
|
/** The answer: its words, or the whole message (replies, citations, thinking…). */
|
|
21
57
|
export type ChatTurnResult = string | (Omit<ChatMessageData, "id" | "role"> & {
|
|
@@ -32,6 +68,7 @@ type Queued = {
|
|
|
32
68
|
conversation: string;
|
|
33
69
|
text: string;
|
|
34
70
|
attachments: Attachment[];
|
|
71
|
+
chips?: readonly MessageChip[];
|
|
35
72
|
};
|
|
36
73
|
export declare const isTemporaryId: (id: string | null | undefined) => boolean;
|
|
37
74
|
export type UseChatAppOptions = {
|
|
@@ -44,15 +81,28 @@ export type UseChatAppOptions = {
|
|
|
44
81
|
conversationId?: string | null;
|
|
45
82
|
onConversationChange?: (id: string | null) => void;
|
|
46
83
|
rememberKey: string | null;
|
|
84
|
+
/** Stop keeps the half answer that had arrived. Default true. */
|
|
85
|
+
stopKeepsPartial?: boolean;
|
|
86
|
+
/** The words for a failed turn whose error is not a `ChatTurnError`. */
|
|
87
|
+
failureMessage?: (error: unknown) => string | null | undefined;
|
|
88
|
+
/** A temporary chat ended: left for a new or another chat, the page hidden
|
|
89
|
+
* or ChatApp unmounted. Called once per chat, with `turn.chatId`. */
|
|
90
|
+
onTemporaryEnd?: (chatId: string) => void;
|
|
91
|
+
/** Reopen the chat from before the reload. False when the page arrives
|
|
92
|
+
* with a message to send (it starts a new chat). Default true. */
|
|
93
|
+
restore?: boolean;
|
|
47
94
|
};
|
|
48
95
|
/**
|
|
49
96
|
* Everything ChatApp does that is not drawing: the list, the open chat, new
|
|
50
97
|
* and temporary chats, turns (one per conversation, each running on when the
|
|
51
98
|
* person opens another chat), the queue, titles and the reopen-on-reload.
|
|
52
99
|
*/
|
|
53
|
-
export declare function useChatApp({ store, transport, makeTitle, conversationId, onConversationChange, rememberKey, }: UseChatAppOptions): {
|
|
100
|
+
export declare function useChatApp({ store, transport, makeTitle, conversationId, onConversationChange, rememberKey, stopKeepsPartial, failureMessage, onTemporaryEnd, restore, }: UseChatAppOptions): {
|
|
54
101
|
list: ConversationSummary[];
|
|
55
102
|
listState: "error" | "loading" | "ready";
|
|
103
|
+
/** The list has loaded (or failed) and the reopened chat is chosen. */
|
|
104
|
+
ready: boolean;
|
|
105
|
+
whenReady: () => Promise<void>;
|
|
56
106
|
reloadList: () => void;
|
|
57
107
|
activeId: string | null;
|
|
58
108
|
stored: string | null;
|
|
@@ -67,7 +117,7 @@ export declare function useChatApp({ store, transport, makeTitle, conversationId
|
|
|
67
117
|
unqueue: (qid: string) => void;
|
|
68
118
|
problem: ChatAppProblem | null;
|
|
69
119
|
clearProblem: () => void;
|
|
70
|
-
send: (text: string, attachments?: Attachment[]) => Promise<boolean>;
|
|
120
|
+
send: (text: string, attachments?: Attachment[], options?: SendOptions) => Promise<boolean>;
|
|
71
121
|
stop: () => void;
|
|
72
122
|
retry: () => void;
|
|
73
123
|
open: (id: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-chat-app.d.ts","sourceRoot":"","sources":["../../src/react/use-chat-app.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAA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