@apia/ai 5.0.3 → 5.0.6
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/dist/chat/ChatController/CameraController.js.map +1 -1
- package/dist/chat/ChatController/ChatController.d.ts +64 -4
- package/dist/chat/ChatController/ChatController.js +292 -16
- package/dist/chat/ChatController/ChatController.js.map +1 -1
- package/dist/chat/ChatController/TChatFeedbackForm.d.ts +7 -0
- package/dist/chat/ChatController/TChatFeedbackForm.d.ts.map +1 -0
- package/dist/chat/ChatController/components/AssistantTurnMessage.d.ts +83 -0
- package/dist/chat/ChatController/components/AssistantTurnMessage.d.ts.map +1 -0
- package/dist/chat/ChatController/components/AssistantTurnMessage.js +516 -0
- package/dist/chat/ChatController/components/AssistantTurnMessage.js.map +1 -0
- package/dist/chat/ChatController/components/Attachments.js.map +1 -1
- package/dist/chat/ChatController/components/Ellipsis.js.map +1 -1
- package/dist/chat/ChatController/components/FileAttachment.js +247 -54
- package/dist/chat/ChatController/components/FileAttachment.js.map +1 -1
- package/dist/chat/ChatController/components/Header.js.map +1 -1
- package/dist/chat/ChatController/components/History.d.ts +2 -1
- package/dist/chat/ChatController/components/History.js +35 -24
- package/dist/chat/ChatController/components/History.js.map +1 -1
- package/dist/chat/ChatController/components/MessageBlock.js.map +1 -1
- package/dist/chat/ChatController/components/PendingMessagesPanel.d.ts +17 -0
- package/dist/chat/ChatController/components/PendingMessagesPanel.d.ts.map +1 -0
- package/dist/chat/ChatController/components/PendingMessagesPanel.js +255 -0
- package/dist/chat/ChatController/components/PendingMessagesPanel.js.map +1 -0
- package/dist/chat/ChatController/components/TextArea/QuestionComposer.js +123 -0
- package/dist/chat/ChatController/components/TextArea/QuestionComposer.js.map +1 -0
- package/dist/chat/ChatController/components/TextArea.d.ts +17 -2
- package/dist/chat/ChatController/components/TextArea.js +268 -251
- package/dist/chat/ChatController/components/TextArea.js.map +1 -1
- package/dist/chat/ChatController/components/rate.js.map +1 -1
- package/dist/chat/ChatController/openFloatingChatController.d.ts +13 -0
- package/dist/chat/ChatController/openFloatingChatController.d.ts.map +1 -0
- package/dist/chat/ChatController/openFloatingChatController.js +24 -0
- package/dist/chat/ChatController/openFloatingChatController.js.map +1 -0
- package/dist/chat/ChatController/types.d.ts +56 -1
- package/dist/chat/ChatController/util.js.map +1 -1
- package/dist/chat/FloatingChatController.d.ts +15 -0
- package/dist/chat/FloatingChatController.js +15 -12
- package/dist/chat/FloatingChatController.js.map +1 -1
- package/dist/components/chat/messages/MultipleChoiceMessage.js.map +1 -1
- package/dist/components/documents/UploadModal/ImageIcon.js.map +1 -1
- package/dist/components/documents/UploadModal/getImagesWithDescription.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/routines/DashboardRoutinesGeneration.js.map +1 -1
- package/dist/routines/RoutinesGeneration.d.ts +17 -1
- package/dist/routines/RoutinesGeneration.js +18 -2
- package/dist/routines/RoutinesGeneration.js.map +1 -1
- package/dist/semanticSearch/SearchController/index.js.map +1 -1
- package/dist/semanticSearch/SearchController/objects/SemanticSearchReference/Component.js.map +1 -1
- package/dist/semanticSearch/SearchController/objects/SemanticSearchReference/index.js.map +1 -1
- package/dist/semanticSearch/ViewController/types.d.ts +5 -0
- package/dist/semanticSearch/ViewController/types.js.map +1 -1
- package/dist/stream/ResponseStream.d.ts +60 -14
- package/dist/stream/ResponseStream.js +216 -73
- package/dist/stream/ResponseStream.js.map +1 -1
- package/dist/stream/StreamServicePoller.d.ts +10 -1
- package/dist/stream/StreamServicePoller.js +10 -1
- package/dist/stream/StreamServicePoller.js.map +1 -1
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CameraController.js","sources":["../../../src/chat/ChatController/CameraController.tsx"],"sourcesContent":["import { ApiaUtil } from '@apia/components';\nimport { makeObservable, observable, action } from 'mobx';\n\nexport class CameraController {\n state: {\n videoStream: MediaStream | null;\n isOpen: boolean;\n } = {\n videoStream: null,\n isOpen: false,\n };\n private currentCapture: File | null = null;\n\n private videoElement: HTMLVideoElement;\n\n constructor() {\n makeObservable(this, {\n state: observable,\n openCamera: action,\n closeCamera: action,\n });\n\n this.videoElement = document.createElement('video');\n this.videoElement.autoplay = true;\n this.videoElement.playsInline = true;\n }\n\n async openCamera() {\n try {\n const stream = await navigator.mediaDevices.getUserMedia({ video: true });\n this.state.videoStream = stream;\n this.videoElement.srcObject = stream;\n this.state.isOpen = true;\n ApiaUtil.instance.modals.open({\n children: <this.Component></this.Component>,\n onConfirm: () => {\n this.closeCamera();\n },\n onClose: () => {\n this.closeCamera();\n },\n });\n } catch (error) {\n console.error('Error while accessing the camera:', error);\n this.state.isOpen = false;\n this.closeCamera();\n }\n }\n\n async closeCamera() {\n if (!this.videoElement.srcObject) return;\n\n const canvas = document.createElement('canvas');\n canvas.width = this.videoElement.videoWidth;\n canvas.height = this.videoElement.videoHeight;\n const ctx = canvas.getContext('2d');\n if (ctx)\n ctx.drawImage(this.videoElement, 0, 0, canvas.width, canvas.height);\n\n this.currentCapture = await new Promise<File | null>((resolve) => {\n canvas.toBlob((blob: Blob | null) => {\n if (blob) {\n const file = new File([blob], 'captured_image.jpg', {\n type: 'image/jpeg',\n });\n resolve(file);\n } else {\n this.closeCamera();\n }\n }, 'image/jpeg');\n }).finally(() => {\n this.state.videoStream?.getTracks().forEach((track) => track.stop());\n this.state.videoStream = null;\n this.videoElement.srcObject = null;\n this.state.isOpen = false;\n });\n }\n\n pop() {\n const returnFile = this.currentCapture;\n this.currentCapture = null;\n return returnFile;\n }\n\n Component = () => {\n return (\n <video\n ref={(el) => {\n if (el) {\n el.srcObject = this.videoElement.srcObject;\n el.autoplay = true;\n el.playsInline = true;\n }\n }}\n style={{ width: '100%', height: 'auto' }}\n />\n );\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;AAGO,MAAM,gBAAA,CAAiB;AAAA,EAY5B,WAAA,GAAc;AAXd,IAAA,aAAA,CAAA,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CAAA;AACD,UAAA,OAAA,CAAQ,IAAI,CAAA;AAAA,SACd,MAAO;AACL,UAAA,IAAA,CAAK,WAAA,EAAY;AAAA;AACnB,SACC,YAAY,CAAA;AAAA,KAChB,CAAA,CAAE,OAAA,CAAQ,MAAM;AACf,MAAA,IAAA,CAAK,KAAA,CAAM,aAAa,SAAA,EAAU,CAAE,QAAQ,CAAC,KAAA,KAAU,KAAA,CAAM,IAAA,EAAM,CAAA;AACnE,MAAA,IAAA,CAAK,MAAM,WAAA,GAAc,IAAA;AACzB,MAAA,IAAA,CAAK,aAAa,SAAA,GAAY,IAAA;AAC9B,MAAA,IAAA,CAAK,MAAM,MAAA,GAAS,KAAA;AAAA,KACrB,CAAA;AAAA;AACH,EAEA,GAAA,GAAM;AACJ,IAAA,MAAM,aAAa,IAAA,CAAK,cAAA;AACxB,IAAA,IAAA,CAAK,cAAA,GAAiB,IAAA;AACtB,IAAA,OAAO,UAAA;AAAA;AAiBX;;;;"}
|
|
1
|
+
{"version":3,"file":"CameraController.js","sources":["../../../src/chat/ChatController/CameraController.tsx"],"sourcesContent":["import { ApiaUtil } from '@apia/components';\r\nimport { makeObservable, observable, action } from 'mobx';\r\n\r\nexport class CameraController {\r\n state: {\r\n videoStream: MediaStream | null;\r\n isOpen: boolean;\r\n } = {\r\n videoStream: null,\r\n isOpen: false,\r\n };\r\n private currentCapture: File | null = null;\r\n\r\n private videoElement: HTMLVideoElement;\r\n\r\n constructor() {\r\n makeObservable(this, {\r\n state: observable,\r\n openCamera: action,\r\n closeCamera: action,\r\n });\r\n\r\n this.videoElement = document.createElement('video');\r\n this.videoElement.autoplay = true;\r\n this.videoElement.playsInline = true;\r\n }\r\n\r\n async openCamera() {\r\n try {\r\n const stream = await navigator.mediaDevices.getUserMedia({ video: true });\r\n this.state.videoStream = stream;\r\n this.videoElement.srcObject = stream;\r\n this.state.isOpen = true;\r\n ApiaUtil.instance.modals.open({\r\n children: <this.Component></this.Component>,\r\n onConfirm: () => {\r\n this.closeCamera();\r\n },\r\n onClose: () => {\r\n this.closeCamera();\r\n },\r\n });\r\n } catch (error) {\r\n console.error('Error while accessing the camera:', error);\r\n this.state.isOpen = false;\r\n this.closeCamera();\r\n }\r\n }\r\n\r\n async closeCamera() {\r\n if (!this.videoElement.srcObject) return;\r\n\r\n const canvas = document.createElement('canvas');\r\n canvas.width = this.videoElement.videoWidth;\r\n canvas.height = this.videoElement.videoHeight;\r\n const ctx = canvas.getContext('2d');\r\n if (ctx)\r\n ctx.drawImage(this.videoElement, 0, 0, canvas.width, canvas.height);\r\n\r\n this.currentCapture = await new Promise<File | null>((resolve) => {\r\n canvas.toBlob((blob: Blob | null) => {\r\n if (blob) {\r\n const file = new File([blob], 'captured_image.jpg', {\r\n type: 'image/jpeg',\r\n });\r\n resolve(file);\r\n } else {\r\n this.closeCamera();\r\n }\r\n }, 'image/jpeg');\r\n }).finally(() => {\r\n this.state.videoStream?.getTracks().forEach((track) => track.stop());\r\n this.state.videoStream = null;\r\n this.videoElement.srcObject = null;\r\n this.state.isOpen = false;\r\n });\r\n }\r\n\r\n pop() {\r\n const returnFile = this.currentCapture;\r\n this.currentCapture = null;\r\n return returnFile;\r\n }\r\n\r\n Component = () => {\r\n return (\r\n <video\r\n ref={(el) => {\r\n if (el) {\r\n el.srcObject = this.videoElement.srcObject;\r\n el.autoplay = true;\r\n el.playsInline = true;\r\n }\r\n }}\r\n style={{ width: '100%', height: 'auto' }}\r\n />\r\n );\r\n };\r\n}\r\n"],"names":[],"mappings":";;;;;;;;;;AAGO,MAAM,gBAAA,CAAiB;AAAA,EAY5B,WAAA,GAAc;AAXd,IAAA,aAAA,CAAA,IAAA,EAAA,OAAA,EAGI;AAAA,MACF,WAAA,EAAa,IAAA;AAAA,MACb,MAAA,EAAQ;AAAA,KACV,CAAA;AACA,IAAA,aAAA,CAAA,IAAA,EAAQ,gBAAA,EAA8B,IAAA,CAAA;AAEtC,IAAA,aAAA,CAAA,IAAA,EAAQ,cAAA,CAAA;AAuER,IA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AU,CAAE,QAAQ,CAAC,KAAA,KAAU,KAAA,CAAM,IAAA,EAAM,CAAA;AACnE,MAAA,IAAA,CAAK,MAAM,WAAA,GAAc,IAAA;AACzB,MAAA,IAAA,CAAK,aAAa,SAAA,GAAY,IAAA;AAC9B,MAAA,IAAA,CAAK,MAAM,MAAA,GAAS,KAAA;AAAA,KACrB,CAAA;AAAA;AACH,EAEA,GAAA,GAAM;AACJ,IAAA,MAAM,aAAa,IAAA,CAAK,cAAA;AACxB,IAAA,IAAA,CAAK,cAAA,GAAiB,IAAA;AACtB,IAAA,OAAO,UAAA;AAAA;AAiBX;;;;"}
|
|
@@ -1,19 +1,58 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
2
3
|
import * as _apia_util from '@apia/util';
|
|
3
4
|
import { ChatMessage } from './components/ChatMessage.js';
|
|
4
5
|
import { TTextAreaProps } from './components/TextArea.js';
|
|
5
|
-
import {
|
|
6
|
+
import { ChatAssistantTurn } from './components/AssistantTurnMessage.js';
|
|
7
|
+
import { TChatControllerState, MessageSubmitCallback, ClearHistoryCallback, IAttachment, TMessageType, TChatAssistantPanelConfig, TChatAssistantTurnSnapshot, MessageCallbackProps, TChatModelOption } from './types.js';
|
|
6
8
|
import { TMenuItem } from '@apia/components';
|
|
9
|
+
import { TChatFeedbackForm } from './TChatFeedbackForm.js';
|
|
7
10
|
|
|
11
|
+
type TCreateAssistantTurnMessageProps = {
|
|
12
|
+
attachments?: IAttachment[];
|
|
13
|
+
feedbackForm?: TChatFeedbackForm;
|
|
14
|
+
messageType?: TMessageType;
|
|
15
|
+
panels?: TChatAssistantPanelConfig[];
|
|
16
|
+
reference?: ReactNode;
|
|
17
|
+
snapshot?: TChatAssistantTurnSnapshot;
|
|
18
|
+
};
|
|
19
|
+
type TChatControllerOptions = {
|
|
20
|
+
feedbackForm: TChatFeedbackForm;
|
|
21
|
+
};
|
|
22
|
+
type TChangeModelCallback = (model: string) => boolean | Promise<boolean>;
|
|
23
|
+
type TChatPlanItem = {
|
|
24
|
+
description?: string;
|
|
25
|
+
id: string;
|
|
26
|
+
intent?: string;
|
|
27
|
+
status: string;
|
|
28
|
+
text: string;
|
|
29
|
+
title?: string;
|
|
30
|
+
};
|
|
31
|
+
type TChatPlanState = {
|
|
32
|
+
items: TChatPlanItem[];
|
|
33
|
+
title?: string;
|
|
34
|
+
};
|
|
35
|
+
type TChatPlanStreamBlock = {
|
|
36
|
+
description?: string;
|
|
37
|
+
type?: string;
|
|
38
|
+
};
|
|
39
|
+
type TChatControllerInternalState<T extends Record<string, unknown>> = TChatControllerState & T & {
|
|
40
|
+
feedbackForm: TChatFeedbackForm;
|
|
41
|
+
plan: TChatPlanState | null;
|
|
42
|
+
};
|
|
8
43
|
declare class ChatController<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
9
44
|
private onMessageSubmit;
|
|
10
45
|
private onClearHistory;
|
|
11
46
|
private additionalOptions?;
|
|
12
47
|
private classNames?;
|
|
48
|
+
private onStop?;
|
|
49
|
+
private onChangeModel?;
|
|
13
50
|
currentIndex: number;
|
|
14
|
-
state:
|
|
51
|
+
state: TChatControllerInternalState<T>;
|
|
15
52
|
private internalAudioRecorder;
|
|
16
53
|
private internalCameraRecorder;
|
|
54
|
+
private isSubmitting;
|
|
55
|
+
private stopPromise?;
|
|
17
56
|
private maxId;
|
|
18
57
|
audioRecorder: {
|
|
19
58
|
cancelOnStop: boolean;
|
|
@@ -22,16 +61,31 @@ declare class ChatController<T extends Record<string, unknown> = Record<string,
|
|
|
22
61
|
record: number;
|
|
23
62
|
state: _apia_util.AudioRecorderState;
|
|
24
63
|
};
|
|
25
|
-
constructor(props: Partial<TChatControllerState & T>, onMessageSubmit: MessageSubmitCallback, onClearHistory: ClearHistoryCallback, additionalOptions?: TMenuItem[] | undefined, classNames?: {
|
|
64
|
+
constructor(props: Partial<TChatControllerState & T & TChatControllerOptions>, onMessageSubmit: MessageSubmitCallback, onClearHistory: ClearHistoryCallback, additionalOptions?: TMenuItem[] | undefined, classNames?: {
|
|
26
65
|
history?: string;
|
|
27
66
|
textarea?: string;
|
|
28
67
|
attachments?: string;
|
|
29
|
-
} | undefined);
|
|
68
|
+
} | undefined, onStop?: (() => Promise<unknown> | unknown) | undefined, onChangeModel?: TChangeModelCallback | undefined);
|
|
30
69
|
removeMessage(idx: number): void;
|
|
31
70
|
addMessage(message: ChatMessage): void;
|
|
71
|
+
createAssistantTurnMessage({ feedbackForm, panels, snapshot, }?: TCreateAssistantTurnMessageProps): {
|
|
72
|
+
message: ChatMessage;
|
|
73
|
+
turn: ChatAssistantTurn;
|
|
74
|
+
};
|
|
75
|
+
startAssistantTurn(props?: TCreateAssistantTurnMessageProps): {
|
|
76
|
+
message: ChatMessage;
|
|
77
|
+
turn: ChatAssistantTurn;
|
|
78
|
+
};
|
|
32
79
|
clearHistory(): void;
|
|
33
80
|
clearMessage(): void;
|
|
34
81
|
removeAttachment(attachment: IAttachment): void;
|
|
82
|
+
stop(): Promise<void>;
|
|
83
|
+
removePendingMessage(message: ChatMessage): void;
|
|
84
|
+
updatePendingMessage(message: ChatMessage, value: string): void;
|
|
85
|
+
private hasMessageContent;
|
|
86
|
+
private queuePendingMessage;
|
|
87
|
+
private shiftPendingMessage;
|
|
88
|
+
private submitMessage;
|
|
35
89
|
private handleSubmit;
|
|
36
90
|
private isForHistory;
|
|
37
91
|
private canGoNext;
|
|
@@ -40,6 +94,9 @@ declare class ChatController<T extends Record<string, unknown> = Record<string,
|
|
|
40
94
|
prevMessage(): void;
|
|
41
95
|
protected getAdditionalProps(): Partial<MessageCallbackProps>;
|
|
42
96
|
protected getTextAreaProps(): Partial<TTextAreaProps>;
|
|
97
|
+
applyPlanStreamBlock(block: TChatPlanStreamBlock): boolean;
|
|
98
|
+
setModelOptions(modelOptions: TChatModelOption[], selectedModel?: string): void;
|
|
99
|
+
changeModel(model: string): Promise<void>;
|
|
43
100
|
setState<K extends keyof ChatController<T>['state']>(k: K, v: this['state'][K]): void;
|
|
44
101
|
History: (() => react.JSX.Element) & {
|
|
45
102
|
displayName: string;
|
|
@@ -47,6 +104,9 @@ declare class ChatController<T extends Record<string, unknown> = Record<string,
|
|
|
47
104
|
Attachments: (() => react.JSX.Element) & {
|
|
48
105
|
displayName: string;
|
|
49
106
|
};
|
|
107
|
+
Plan: (() => react.JSX.Element) & {
|
|
108
|
+
displayName: string;
|
|
109
|
+
};
|
|
50
110
|
TextArea: (() => react.JSX.Element) & {
|
|
51
111
|
displayName: string;
|
|
52
112
|
};
|
|
@@ -9,6 +9,7 @@ import { Box, getVariant } from '@apia/theme';
|
|
|
9
9
|
import { AudioRecorder, getLabel } from '@apia/util';
|
|
10
10
|
import { CameraController } from './CameraController.js';
|
|
11
11
|
import { getBase64FromFile, getBase64FromBlob } from './util.js';
|
|
12
|
+
import { ChatAssistantTurn } from './components/AssistantTurnMessage.js';
|
|
12
13
|
|
|
13
14
|
var __defProp = Object.defineProperty;
|
|
14
15
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -16,22 +17,101 @@ var __publicField = (obj, key, value) => {
|
|
|
16
17
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
17
18
|
return value;
|
|
18
19
|
};
|
|
20
|
+
const CHAT_PLAN_BLOCK_TYPE = "ai.plan";
|
|
21
|
+
function parseChatPlanPayload(content) {
|
|
22
|
+
if (!content?.trim()) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(content);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.warn("Cannot parse chat plan payload", error);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function cleanChatPlanItem(item) {
|
|
33
|
+
const id = String(item?.id ?? "").trim();
|
|
34
|
+
const title = String(item?.title ?? "").trim();
|
|
35
|
+
const intent = String(item?.intent ?? "").trim();
|
|
36
|
+
const description = String(item?.description ?? "").trim();
|
|
37
|
+
const fallbackText = title || intent || description;
|
|
38
|
+
const text = String(item?.text ?? fallbackText).trim();
|
|
39
|
+
const status = String(item?.status ?? "").trim();
|
|
40
|
+
if (!id || !text) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return { description, id, intent, status, text, title };
|
|
44
|
+
}
|
|
45
|
+
const ChatPlanPanel = observer(({ plan }) => {
|
|
46
|
+
if (!plan?.items.length) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return /* @__PURE__ */ jsx(Box, { className: "chatPlan", children: /* @__PURE__ */ jsx(Box, { className: "chatPlan__items", children: plan.items.map((item) => {
|
|
50
|
+
const done = item.status === "done";
|
|
51
|
+
const tooltip = item.title || item.intent || item.description || item.text;
|
|
52
|
+
return /* @__PURE__ */ jsxs(
|
|
53
|
+
Box,
|
|
54
|
+
{
|
|
55
|
+
className: `chatPlanItem ${done ? "chatPlanItem--done" : "chatPlanItem--pending"}`,
|
|
56
|
+
title: tooltip,
|
|
57
|
+
children: [
|
|
58
|
+
/* @__PURE__ */ jsx(Box, { "aria-hidden": true, className: "chatPlanItem__check" }),
|
|
59
|
+
/* @__PURE__ */ jsx(Box, { className: "chatPlanItem__text", title: tooltip, children: item.text })
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
item.id
|
|
63
|
+
);
|
|
64
|
+
}) }) });
|
|
65
|
+
});
|
|
66
|
+
function audioFileExtensionForMimeType(mimeType) {
|
|
67
|
+
const cleanMimeType = mimeType?.split(";")[0]?.toLowerCase();
|
|
68
|
+
switch (cleanMimeType) {
|
|
69
|
+
case "audio/webm":
|
|
70
|
+
return "webm";
|
|
71
|
+
case "audio/ogg":
|
|
72
|
+
return "ogg";
|
|
73
|
+
case "audio/mp4":
|
|
74
|
+
return "mp4";
|
|
75
|
+
case "audio/mpeg":
|
|
76
|
+
return "mp3";
|
|
77
|
+
case "audio/wav":
|
|
78
|
+
case "audio/wave":
|
|
79
|
+
case "audio/x-wav":
|
|
80
|
+
return "wav";
|
|
81
|
+
default:
|
|
82
|
+
return "webm";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
19
85
|
class ChatController {
|
|
20
|
-
constructor(props, onMessageSubmit, onClearHistory, additionalOptions, classNames) {
|
|
86
|
+
constructor(props, onMessageSubmit, onClearHistory, additionalOptions, classNames, onStop, onChangeModel) {
|
|
21
87
|
this.onMessageSubmit = onMessageSubmit;
|
|
22
88
|
this.onClearHistory = onClearHistory;
|
|
23
89
|
this.additionalOptions = additionalOptions;
|
|
24
90
|
this.classNames = classNames;
|
|
91
|
+
this.onStop = onStop;
|
|
92
|
+
this.onChangeModel = onChangeModel;
|
|
25
93
|
__publicField(this, "currentIndex", 0);
|
|
26
94
|
__publicField(this, "state", {
|
|
27
95
|
isLoading: false,
|
|
96
|
+
isStopping: false,
|
|
97
|
+
isModelSelectionLoading: false,
|
|
98
|
+
allowModelSelection: false,
|
|
28
99
|
canRecord: true,
|
|
29
100
|
canAttach: true,
|
|
101
|
+
canOpenCamera: true,
|
|
102
|
+
canNavigateHistory: true,
|
|
103
|
+
feedbackForm: "stack",
|
|
30
104
|
messages: [],
|
|
31
|
-
currentMessage: new ChatMessage("", "user")
|
|
105
|
+
currentMessage: new ChatMessage("", "user"),
|
|
106
|
+
modelOptions: [],
|
|
107
|
+
pendingMessages: [],
|
|
108
|
+
pendingMessagesHeight: 0,
|
|
109
|
+
plan: null
|
|
32
110
|
});
|
|
33
111
|
__publicField(this, "internalAudioRecorder", new AudioRecorder());
|
|
34
112
|
__publicField(this, "internalCameraRecorder", new CameraController());
|
|
113
|
+
__publicField(this, "isSubmitting", false);
|
|
114
|
+
__publicField(this, "stopPromise");
|
|
35
115
|
__publicField(this, "maxId", 0);
|
|
36
116
|
__publicField(this, "audioRecorder", {
|
|
37
117
|
cancelOnStop: false,
|
|
@@ -42,9 +122,10 @@ class ChatController {
|
|
|
42
122
|
this.audioRecorder.cancelOnStop = false;
|
|
43
123
|
return;
|
|
44
124
|
}
|
|
125
|
+
const extension = audioFileExtensionForMimeType(blob.type);
|
|
45
126
|
this.state.currentMessage.attachments.push({
|
|
46
127
|
id: String(this.maxId++),
|
|
47
|
-
name: `userRecord_${this.audioRecorder.record++}
|
|
128
|
+
name: `userRecord_${this.audioRecorder.record++}.${extension}`,
|
|
48
129
|
base64: await getBase64FromBlob(blob)
|
|
49
130
|
});
|
|
50
131
|
const currentMessage = new ChatMessage(
|
|
@@ -69,25 +150,26 @@ class ChatController {
|
|
|
69
150
|
state: this.internalAudioRecorder.state
|
|
70
151
|
});
|
|
71
152
|
__publicField(this, "handleSubmit", async (props) => {
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
this.setState("isLoading", false);
|
|
153
|
+
if (this.audioRecorder.state.recording) {
|
|
154
|
+
await this.audioRecorder.stop();
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (this.state.isModelSelectionLoading) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const currentMessage = props?.message || this.state.currentMessage;
|
|
161
|
+
if (this.hasMessageContent(currentMessage)) {
|
|
162
|
+
if (props?.eraseCurrentMessage !== false) {
|
|
163
|
+
this.setState("currentMessage", new ChatMessage("", "user"));
|
|
84
164
|
}
|
|
165
|
+
await this.submitMessage(currentMessage);
|
|
85
166
|
}
|
|
86
167
|
});
|
|
87
168
|
__publicField(this, "History", observer(() => /* @__PURE__ */ jsx(
|
|
88
169
|
History,
|
|
89
170
|
{
|
|
90
171
|
messages: this.state.messages,
|
|
172
|
+
bottomInset: this.state.pendingMessagesHeight,
|
|
91
173
|
className: this.classNames?.history
|
|
92
174
|
}
|
|
93
175
|
)));
|
|
@@ -102,23 +184,52 @@ class ChatController {
|
|
|
102
184
|
onAddDescription: (a, ev) => this.state.currentMessage.addAttachmentDescription(a, ev)
|
|
103
185
|
}
|
|
104
186
|
)));
|
|
187
|
+
__publicField(this, "Plan", observer(() => /* @__PURE__ */ jsx(ChatPlanPanel, { plan: this.state.plan })));
|
|
105
188
|
__publicField(this, "TextArea", observer(() => /* @__PURE__ */ jsx(
|
|
106
189
|
TextArea,
|
|
107
190
|
{
|
|
108
191
|
additionalOptions: this.additionalOptions,
|
|
192
|
+
allowModelSelection: this.state.allowModelSelection === true,
|
|
193
|
+
canAttach: this.state.canAttach !== false,
|
|
194
|
+
canCancelRequest: Boolean(this.onStop),
|
|
195
|
+
canNavigateHistory: this.state.canNavigateHistory !== false,
|
|
196
|
+
canOpenCamera: this.state.canOpenCamera !== false,
|
|
197
|
+
canRecord: this.state.canRecord !== false,
|
|
109
198
|
className: this.classNames?.textarea,
|
|
110
199
|
value: this.state.currentMessage.message,
|
|
111
200
|
isLoading: this.state.isLoading,
|
|
201
|
+
isCancellingRequest: this.state.isStopping,
|
|
202
|
+
isModelSelectionLoading: this.state.isModelSelectionLoading,
|
|
112
203
|
isRecording: this.internalAudioRecorder.state.recording,
|
|
113
204
|
disablePrevButton: !this.canGoPrev(),
|
|
114
205
|
disableNextButton: !this.canGoNext(),
|
|
206
|
+
modelOptions: this.state.modelOptions,
|
|
207
|
+
selectedModel: this.state.selectedModel,
|
|
115
208
|
onChange: (ev) => {
|
|
116
209
|
this.state.currentMessage.message = ev;
|
|
117
210
|
},
|
|
211
|
+
onChangeModel: (model) => {
|
|
212
|
+
void this.changeModel(model);
|
|
213
|
+
},
|
|
214
|
+
onStop: this.onStop ? () => this.stop() : void 0,
|
|
215
|
+
onCancelRequest: () => {
|
|
216
|
+
void this.stop();
|
|
217
|
+
},
|
|
118
218
|
onSubmit: () => this.handleSubmit(),
|
|
119
219
|
onClearHistory: () => {
|
|
120
220
|
this.clearHistory();
|
|
121
221
|
},
|
|
222
|
+
onPendingMessagesHeightChange: (height) => {
|
|
223
|
+
if (this.state.pendingMessagesHeight !== height) {
|
|
224
|
+
this.setState("pendingMessagesHeight", height);
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
onRemovePendingMessage: (message) => {
|
|
228
|
+
this.removePendingMessage(message);
|
|
229
|
+
},
|
|
230
|
+
onUpdatePendingMessage: (message, value) => {
|
|
231
|
+
this.updatePendingMessage(message, value);
|
|
232
|
+
},
|
|
122
233
|
onAttach: async (ev) => {
|
|
123
234
|
if (ev) {
|
|
124
235
|
if (!this.state.maxAttachmentsSize || this.computeBase64Size(ev.base64) <= this.state.maxAttachmentsSize) {
|
|
@@ -176,6 +287,7 @@ class ChatController {
|
|
|
176
287
|
this.nextMessage();
|
|
177
288
|
},
|
|
178
289
|
attachments: this.state.currentMessage.attachments,
|
|
290
|
+
pendingMessages: this.state.pendingMessages,
|
|
179
291
|
...this.getTextAreaProps()
|
|
180
292
|
}
|
|
181
293
|
)));
|
|
@@ -186,6 +298,7 @@ class ChatController {
|
|
|
186
298
|
className: "chat_controller",
|
|
187
299
|
children: [
|
|
188
300
|
/* @__PURE__ */ jsx(this.History, {}),
|
|
301
|
+
/* @__PURE__ */ jsx(this.Plan, {}),
|
|
189
302
|
/* @__PURE__ */ jsx(this.Attachments, {}),
|
|
190
303
|
/* @__PURE__ */ jsx(this.TextArea, {})
|
|
191
304
|
]
|
|
@@ -201,7 +314,11 @@ class ChatController {
|
|
|
201
314
|
removeAttachment: action,
|
|
202
315
|
nextMessage: action,
|
|
203
316
|
prevMessage: action,
|
|
204
|
-
setState: action
|
|
317
|
+
setState: action,
|
|
318
|
+
setModelOptions: action,
|
|
319
|
+
changeModel: action,
|
|
320
|
+
removePendingMessage: action,
|
|
321
|
+
updatePendingMessage: action
|
|
205
322
|
});
|
|
206
323
|
}
|
|
207
324
|
removeMessage(idx) {
|
|
@@ -214,8 +331,44 @@ class ChatController {
|
|
|
214
331
|
this.state.messages.push(message);
|
|
215
332
|
this.currentIndex = this.state.messages.length;
|
|
216
333
|
}
|
|
334
|
+
createAssistantTurnMessage({
|
|
335
|
+
feedbackForm,
|
|
336
|
+
panels = [],
|
|
337
|
+
snapshot
|
|
338
|
+
} = {}) {
|
|
339
|
+
const turn = new ChatAssistantTurn({
|
|
340
|
+
feedbackForm: feedbackForm ?? this.state.feedbackForm,
|
|
341
|
+
panels,
|
|
342
|
+
snapshot
|
|
343
|
+
});
|
|
344
|
+
const message = turn.createPanelMessage();
|
|
345
|
+
message.messageType = "customMessage";
|
|
346
|
+
return { message, turn };
|
|
347
|
+
}
|
|
348
|
+
startAssistantTurn(props = {}) {
|
|
349
|
+
const finalMessage = new ChatMessage(
|
|
350
|
+
"",
|
|
351
|
+
props.messageType ?? "system",
|
|
352
|
+
props.attachments ?? [],
|
|
353
|
+
props.reference ?? null
|
|
354
|
+
);
|
|
355
|
+
const result = {
|
|
356
|
+
message: finalMessage,
|
|
357
|
+
turn: new ChatAssistantTurn({
|
|
358
|
+
controller: this,
|
|
359
|
+
feedbackForm: props.feedbackForm ?? this.state.feedbackForm,
|
|
360
|
+
finalMessage,
|
|
361
|
+
panels: props.panels ?? [],
|
|
362
|
+
snapshot: props.snapshot
|
|
363
|
+
})
|
|
364
|
+
};
|
|
365
|
+
return result;
|
|
366
|
+
}
|
|
217
367
|
clearHistory() {
|
|
218
368
|
this.setState("messages", []);
|
|
369
|
+
this.setState("pendingMessages", []);
|
|
370
|
+
this.setState("pendingMessagesHeight", 0);
|
|
371
|
+
this.state.plan = null;
|
|
219
372
|
this.onClearHistory && this.onClearHistory();
|
|
220
373
|
}
|
|
221
374
|
clearMessage() {
|
|
@@ -224,6 +377,89 @@ class ChatController {
|
|
|
224
377
|
removeAttachment(attachment) {
|
|
225
378
|
this.state.currentMessage.removeAttachment(attachment);
|
|
226
379
|
}
|
|
380
|
+
async stop() {
|
|
381
|
+
if (!this.state.isLoading) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (this.stopPromise) {
|
|
385
|
+
await this.stopPromise;
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
this.setState("isStopping", true);
|
|
389
|
+
this.stopPromise = Promise.resolve(this.onStop?.()).catch(() => {
|
|
390
|
+
this.setState("isStopping", false);
|
|
391
|
+
}).finally(() => {
|
|
392
|
+
this.stopPromise = void 0;
|
|
393
|
+
});
|
|
394
|
+
await this.stopPromise;
|
|
395
|
+
}
|
|
396
|
+
removePendingMessage(message) {
|
|
397
|
+
this.setState(
|
|
398
|
+
"pendingMessages",
|
|
399
|
+
this.state.pendingMessages.filter((current) => current !== message)
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
updatePendingMessage(message, value) {
|
|
403
|
+
const pendingMessage = this.state.pendingMessages.find(
|
|
404
|
+
(current) => current === message
|
|
405
|
+
);
|
|
406
|
+
if (pendingMessage) {
|
|
407
|
+
pendingMessage.message = value;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
hasMessageContent(message) {
|
|
411
|
+
return Boolean(message.message || message.attachments.length > 0);
|
|
412
|
+
}
|
|
413
|
+
queuePendingMessage(message) {
|
|
414
|
+
if (!this.hasMessageContent(message)) {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
this.state.pendingMessages.push(message);
|
|
418
|
+
}
|
|
419
|
+
shiftPendingMessage() {
|
|
420
|
+
let nextMessage;
|
|
421
|
+
let remainingMessages = this.state.pendingMessages;
|
|
422
|
+
while (remainingMessages.length > 0 && !nextMessage) {
|
|
423
|
+
const [candidate, ...rest] = remainingMessages;
|
|
424
|
+
remainingMessages = rest;
|
|
425
|
+
if (this.hasMessageContent(candidate)) {
|
|
426
|
+
nextMessage = candidate;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
this.setState("pendingMessages", remainingMessages);
|
|
430
|
+
return nextMessage;
|
|
431
|
+
}
|
|
432
|
+
async submitMessage(message) {
|
|
433
|
+
if (!this.hasMessageContent(message)) {
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
if (this.isSubmitting) {
|
|
437
|
+
this.queuePendingMessage(message);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
this.isSubmitting = true;
|
|
441
|
+
this.setState("isLoading", true);
|
|
442
|
+
document.dispatchEvent(new Event("enableAutoScroll"));
|
|
443
|
+
try {
|
|
444
|
+
await this.onMessageSubmit({
|
|
445
|
+
message,
|
|
446
|
+
model: this.state.selectedModel,
|
|
447
|
+
...this.getAdditionalProps()
|
|
448
|
+
});
|
|
449
|
+
} finally {
|
|
450
|
+
if (this.stopPromise) {
|
|
451
|
+
await this.stopPromise;
|
|
452
|
+
}
|
|
453
|
+
this.isSubmitting = false;
|
|
454
|
+
const nextMessage = this.shiftPendingMessage();
|
|
455
|
+
if (nextMessage) {
|
|
456
|
+
await this.submitMessage(nextMessage);
|
|
457
|
+
} else {
|
|
458
|
+
this.setState("isLoading", false);
|
|
459
|
+
this.setState("isStopping", false);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
227
463
|
isForHistory(message) {
|
|
228
464
|
return message && message.messageType === "user";
|
|
229
465
|
}
|
|
@@ -304,6 +540,46 @@ class ChatController {
|
|
|
304
540
|
getTextAreaProps() {
|
|
305
541
|
return {};
|
|
306
542
|
}
|
|
543
|
+
applyPlanStreamBlock(block) {
|
|
544
|
+
if (block.type !== CHAT_PLAN_BLOCK_TYPE) {
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
const payload = parseChatPlanPayload(block.description);
|
|
548
|
+
if (!payload || payload.action === "close") {
|
|
549
|
+
this.state.plan = null;
|
|
550
|
+
return true;
|
|
551
|
+
}
|
|
552
|
+
const items = (payload.items ?? []).map(cleanChatPlanItem).filter((item) => item !== null);
|
|
553
|
+
this.state.plan = {
|
|
554
|
+
items,
|
|
555
|
+
title: payload.title
|
|
556
|
+
};
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
setModelOptions(modelOptions, selectedModel) {
|
|
560
|
+
this.state.modelOptions = modelOptions;
|
|
561
|
+
if (selectedModel !== void 0) {
|
|
562
|
+
this.state.selectedModel = selectedModel;
|
|
563
|
+
} else if (this.state.selectedModel && !modelOptions.some((model) => model.id === this.state.selectedModel)) {
|
|
564
|
+
this.state.selectedModel = modelOptions[0]?.id;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
async changeModel(model) {
|
|
568
|
+
if (!model || model === this.state.selectedModel || this.state.isModelSelectionLoading) {
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
this.state.isModelSelectionLoading = true;
|
|
572
|
+
try {
|
|
573
|
+
const changed = await Promise.resolve(this.onChangeModel?.(model) ?? true);
|
|
574
|
+
if (changed) {
|
|
575
|
+
this.state.selectedModel = model;
|
|
576
|
+
}
|
|
577
|
+
} catch (error) {
|
|
578
|
+
console.error(error);
|
|
579
|
+
} finally {
|
|
580
|
+
this.state.isModelSelectionLoading = false;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
307
583
|
setState(k, v) {
|
|
308
584
|
this.state[k] = v;
|
|
309
585
|
}
|