@apia/ai 5.2.0 → 5.2.1
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/assistant/PanelAssistantTransport.js +2 -3
- package/dist/assistant/PanelAssistantTransport.js.map +1 -1
- package/dist/chat/ChatController/components/Message.js +4 -2
- package/dist/chat/ChatController/components/Message.js.map +1 -1
- package/dist/chat/ChatController/components/MessageBlocks.d.ts +5 -2
- package/dist/chat/ChatController/components/MessageBlocks.js +48 -6
- package/dist/chat/ChatController/components/MessageBlocks.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +8 -8
|
@@ -5,7 +5,6 @@ class PanelAssistantTransport {
|
|
|
5
5
|
async send(turn) {
|
|
6
6
|
const response = await this.dispatch({
|
|
7
7
|
action: "userMessage",
|
|
8
|
-
newAssistant: "true",
|
|
9
8
|
message: turn.message,
|
|
10
9
|
fileMessages: JSON.stringify(turn.files ?? [])
|
|
11
10
|
});
|
|
@@ -24,12 +23,12 @@ class PanelAssistantTransport {
|
|
|
24
23
|
await this.action("cancel");
|
|
25
24
|
}
|
|
26
25
|
async reportDispatchFailure(handoffId) {
|
|
27
|
-
const response = await this.dispatch({ action: "handoffFailed",
|
|
26
|
+
const response = await this.dispatch({ action: "handoffFailed", handoffId });
|
|
28
27
|
if (!response || response.hasError)
|
|
29
28
|
throw new Error("Could not report the handoff failure.");
|
|
30
29
|
}
|
|
31
30
|
async action(action) {
|
|
32
|
-
const response = await this.dispatch({ action
|
|
31
|
+
const response = await this.dispatch({ action });
|
|
33
32
|
if (!response || response.hasError)
|
|
34
33
|
throw new Error(`Assistant ${action} failed.`);
|
|
35
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PanelAssistantTransport.js","sources":["../../src/assistant/PanelAssistantTransport.ts"],"sourcesContent":["import type { AssistantTransport, AssistantTurn, AssistantResult } from './AssistantController';\r\n\r\n/** Minimal structural contract; no dependency on dashboard-controller. */\r\ntype PanelDispatcher = (request: { action: string } & Record<string, unknown>) => Promise<{\r\n hasError?: boolean;\r\n data?: { executionResult?: string; streamId?: string } | null;\r\n} | null>;\r\n\r\nexport class PanelAssistantTransport implements AssistantTransport {\r\n constructor(private readonly dispatch: PanelDispatcher) { }\r\n\r\n async send(turn: AssistantTurn) {\r\n const response = await this.dispatch({\r\n action: 'userMessage',\r\n
|
|
1
|
+
{"version":3,"file":"PanelAssistantTransport.js","sources":["../../src/assistant/PanelAssistantTransport.ts"],"sourcesContent":["import type { AssistantTransport, AssistantTurn, AssistantResult } from './AssistantController';\r\n\r\n/** Minimal structural contract; no dependency on dashboard-controller. */\r\ntype PanelDispatcher = (request: { action: string } & Record<string, unknown>) => Promise<{\r\n hasError?: boolean;\r\n data?: { executionResult?: string; streamId?: string } | null;\r\n} | null>;\r\n\r\nexport class PanelAssistantTransport implements AssistantTransport {\r\n constructor(private readonly dispatch: PanelDispatcher) { }\r\n\r\n async send(turn: AssistantTurn) {\r\n const response = await this.dispatch({\r\n action: 'userMessage',\r\n message: turn.message,\r\n fileMessages: JSON.stringify(turn.files ?? []),\r\n });\r\n if (response?.hasError || !response?.data?.executionResult) {\r\n throw new Error('The panel could not start the assistant turn.');\r\n }\r\n const result = JSON.parse(response.data.executionResult) as AssistantResult;\r\n if (!result || typeof result.type !== 'string') throw new Error('Invalid assistant result.');\r\n return { result, streamId: response.data.streamId };\r\n }\r\n\r\n async clearHistory() { await this.action('clearHistory'); }\r\n async cancel() { await this.action('cancel'); }\r\n\r\n async reportDispatchFailure(handoffId: string) {\r\n const response = await this.dispatch({ action: 'handoffFailed', handoffId });\r\n if (!response || response.hasError) throw new Error('Could not report the handoff failure.');\r\n }\r\n\r\n private async action(action: string) {\r\n const response = await this.dispatch({ action });\r\n if (!response || response.hasError) throw new Error(`Assistant ${action} failed.`);\r\n }\r\n}\r\n"],"names":[],"mappings":"AAQO,MAAM,uBAAA,CAAsD;AAAA,EACjE,YAA6B,QAA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,QAAA,CAAS,EAAE,QAAQ,CAAA;AAC/C,IAAA,IAAI,CAAC,YAAY,QAAA,CAAS,QAAA;AAAU,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,UAAA,EAAa,MAAM,CAAA,QAAA,CAAU,CAAA;AAAA;AAErF;;;;"}
|
|
@@ -2,7 +2,7 @@ import { jsxs, jsx } from '@apia/theme/jsx-runtime';
|
|
|
2
2
|
import { Box } from '@apia/theme';
|
|
3
3
|
import { observer } from 'mobx-react-lite';
|
|
4
4
|
import { Attachments } from './Attachments.js';
|
|
5
|
-
import { MessageBlocks } from './MessageBlocks.js';
|
|
5
|
+
import { hasResolvedAttachmentPlaceholder, MessageBlocks } from './MessageBlocks.js';
|
|
6
6
|
|
|
7
7
|
const Message = observer(
|
|
8
8
|
({
|
|
@@ -13,6 +13,7 @@ const Message = observer(
|
|
|
13
13
|
attachments,
|
|
14
14
|
reference
|
|
15
15
|
}) => {
|
|
16
|
+
const rendersAttachmentInline = typeof message === "string" && hasResolvedAttachmentPlaceholder(message, attachments);
|
|
16
17
|
return /* @__PURE__ */ jsxs(Box, { as: "pre", className: `history_message ${className || ""} ${type}`, children: [
|
|
17
18
|
/* @__PURE__ */ jsx(
|
|
18
19
|
Box,
|
|
@@ -22,13 +23,14 @@ const Message = observer(
|
|
|
22
23
|
children: /* @__PURE__ */ jsx(
|
|
23
24
|
MessageBlocks,
|
|
24
25
|
{
|
|
26
|
+
attachments,
|
|
25
27
|
streamParts: [{ blockType: "text", str: message }]
|
|
26
28
|
}
|
|
27
29
|
)
|
|
28
30
|
} : { children: message }
|
|
29
31
|
}
|
|
30
32
|
),
|
|
31
|
-
attachments.length > 0 && /* @__PURE__ */ jsx(Attachments, { attachments }),
|
|
33
|
+
attachments.length > 0 && !rendersAttachmentInline && /* @__PURE__ */ jsx(Attachments, { attachments }),
|
|
32
34
|
reference && /* @__PURE__ */ jsx(Box, { className: "history_message__references", children: reference })
|
|
33
35
|
] });
|
|
34
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Message.js","sources":["../../../../src/chat/ChatController/components/Message.tsx"],"sourcesContent":["import { Box } from '@apia/theme';\r\nimport { observer } from 'mobx-react-lite';\r\nimport { ReactNode } from 'react';\r\nimport { Attachments } from './Attachments';\r\nimport { IAttachment, TMessageType } from '../types';\r\nimport {
|
|
1
|
+
{"version":3,"file":"Message.js","sources":["../../../../src/chat/ChatController/components/Message.tsx"],"sourcesContent":["import { Box } from '@apia/theme';\r\nimport { observer } from 'mobx-react-lite';\r\nimport { ReactNode } from 'react';\r\nimport { Attachments } from './Attachments';\r\nimport { IAttachment, TMessageType } from '../types';\r\nimport {\r\n hasResolvedAttachmentPlaceholder,\r\n MessageBlocks,\r\n} from './MessageBlocks';\r\n\r\nexport const Message = observer(\r\n ({\r\n className,\r\n type,\r\n id,\r\n message,\r\n attachments,\r\n reference,\r\n }: {\r\n className?: string;\r\n type: TMessageType;\r\n id: string;\r\n message: ReactNode;\r\n attachments: IAttachment[];\r\n reference: ReactNode;\r\n }) => {\r\n const rendersAttachmentInline =\r\n typeof message === 'string' &&\r\n hasResolvedAttachmentPlaceholder(message, attachments);\r\n\r\n return (\r\n <Box as=\"pre\" className={`history_message ${className || ''} ${type}`}>\r\n <Box\r\n className=\"history_message__content\"\r\n {...(typeof message === 'string'\r\n ? {\r\n children: (\r\n <MessageBlocks\r\n attachments={attachments}\r\n streamParts={[{ blockType: 'text', str: message }]}\r\n ></MessageBlocks>\r\n ),\r\n }\r\n : { children: message as string })}\r\n />\r\n {attachments.length > 0 && !rendersAttachmentInline && (\r\n <Attachments attachments={attachments}></Attachments>\r\n )}\r\n {reference && (\r\n <Box className=\"history_message__references\">{reference}</Box>\r\n )}\r\n </Box>\r\n );\r\n },\r\n);\r\n"],"names":[],"mappings":";;;;;;AAUO,MAAM,OAAA,GAAU,QAAA;AAAA,EACrB,CAAC;AAAA,IACC,SAAA;AAAA,IACA,IAAA;AAAA,IACA,EAAA;AAAA,IACA,OAAA;AAAA,IACA,WAAA;AAAA,IACA;AAAA,GACF,KAOM;AACJ,IAAA,MAAM,0BACJ,OAAO,OAAA,KAAY,QAAA,IACnB,gCAAA,CAAiC,SAAS,WAAW,CAAA;AAEvD,IAAA,uBACE,IAAA,CAAC,GAAA,EAAA,EAAI,EAAA,EAAG,KAAA,EAAM,SAAA,EAAW,mBAAmB,SAAA,IAAa,EAAE,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA,EACjE,QAAA,EAAA;AAAA,sBAAA,GAAA;AAAA,QAAC,GAAA;AAAA,QAAA;AAAA,UACC,SAAA,EAAU,0BAAA;AAAA,UACT,GAAI,OAAO,OAAA,KAAY,QAAA,GACpB;AAAA,YACE,QAAA,kBACE,GAAA;AAAA,cAAC,aAAA;AAAA,cAAA;AAAA,gBACC,WAAA;AAAA,gBACA,aAAa,CAAC,EAAE,WAAW,MAAA,EAAQ,GAAA,EAAK,SAAS;AAAA;AAAA;AAClD,WAEL,GACA,EAAE,QAAA,EAAU,OAAA;AAAkB;AAAA,OACpC;AAAA,MACC,YAAY,MAAA,GAAS,CAAA,IAAK,CAAC,uBAAA,oBAC1B,GAAA,CAAC,eAAY,WAAA,EAA0B,CAAA;AAAA,MAExC,SAAA,oBACC,GAAA,CAAC,GAAA,EAAA,EAAI,SAAA,EAAU,+BAA+B,QAAA,EAAA,SAAA,EAAU;AAAA,KAAA,EAE5D,CAAA;AAAA;AAGN;;;;"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
+
import { IAttachment } from '../types.js';
|
|
2
3
|
import { TDescriberBlock, TQuestionBlock } from '../StreamMessage.js';
|
|
3
4
|
|
|
5
|
+
declare function hasResolvedAttachmentPlaceholder(text: string, attachments: IAttachment[]): boolean;
|
|
4
6
|
type TBlockType = 'text' | 'describer' | 'question';
|
|
5
7
|
type TBaseStreamBlock<T extends TBlockType = TBlockType> = {
|
|
6
8
|
blockType: T;
|
|
@@ -15,12 +17,13 @@ type TQuestionStreamBlock = TBaseStreamBlock<'question'> & {
|
|
|
15
17
|
question: TQuestionBlock;
|
|
16
18
|
};
|
|
17
19
|
type TStreamBlock = TTextStreamBlock | TDescriberStreamBlock | TQuestionStreamBlock;
|
|
18
|
-
declare const MessageBlocks: (({ streamParts, showThinkingSkeleton, }: {
|
|
20
|
+
declare const MessageBlocks: (({ attachments, streamParts, showThinkingSkeleton, }: {
|
|
21
|
+
attachments?: IAttachment[];
|
|
19
22
|
streamParts: TStreamBlock[];
|
|
20
23
|
showThinkingSkeleton?: boolean;
|
|
21
24
|
}) => react.JSX.Element[]) & {
|
|
22
25
|
displayName: string;
|
|
23
26
|
};
|
|
24
27
|
|
|
25
|
-
export { MessageBlocks, type TBaseStreamBlock, type TBlockType, type TDescriberStreamBlock, type TQuestionStreamBlock, type TStreamBlock, type TTextStreamBlock };
|
|
28
|
+
export { MessageBlocks, type TBaseStreamBlock, type TBlockType, type TDescriberStreamBlock, type TQuestionStreamBlock, type TStreamBlock, type TTextStreamBlock, hasResolvedAttachmentPlaceholder };
|
|
26
29
|
//# sourceMappingURL=MessageBlocks.d.ts.map
|
|
@@ -6,9 +6,53 @@ import { Box } from '@apia/theme';
|
|
|
6
6
|
import { observer } from 'mobx-react-lite';
|
|
7
7
|
import { ThinkingBlocks } from './ThinkingBlocks.js';
|
|
8
8
|
import { QuestionBlocks } from './QuestionBlocks.js';
|
|
9
|
+
import { FileAttachment } from './FileAttachment.js';
|
|
9
10
|
|
|
11
|
+
const ATTACHMENT_PLACEHOLDER_PATTERN = /\[\[attachment:([^\r\n]+?)\]\]/g;
|
|
12
|
+
function resolveAttachment(reference, attachments) {
|
|
13
|
+
const normalizedReference = reference.trim();
|
|
14
|
+
return attachments.find(
|
|
15
|
+
(attachment) => attachment.id === normalizedReference || attachment.name === normalizedReference
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
function hasResolvedAttachmentPlaceholder(text, attachments) {
|
|
19
|
+
ATTACHMENT_PLACEHOLDER_PATTERN.lastIndex = 0;
|
|
20
|
+
let match;
|
|
21
|
+
while (match = ATTACHMENT_PLACEHOLDER_PATTERN.exec(text)) {
|
|
22
|
+
if (resolveAttachment(match[1], attachments)) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
function renderTextWithAttachments(text, attachments, keyPrefix) {
|
|
29
|
+
return text.split(/(\[\[attachment:[^\r\n]+?\]\])/g).map((chunk, chunkIndex) => {
|
|
30
|
+
const match = chunk.match(/^\[\[attachment:([^\r\n]+?)\]\]$/);
|
|
31
|
+
if (!match) {
|
|
32
|
+
return /* @__PURE__ */ jsx(MDRenderer, { str: chunk }, `${keyPrefix}_${chunkIndex}`);
|
|
33
|
+
}
|
|
34
|
+
const attachment = resolveAttachment(match[1], attachments);
|
|
35
|
+
if (!attachment) {
|
|
36
|
+
return /* @__PURE__ */ jsx(
|
|
37
|
+
MDRenderer,
|
|
38
|
+
{
|
|
39
|
+
str: match[1].trim()
|
|
40
|
+
},
|
|
41
|
+
`${keyPrefix}_${chunkIndex}`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return /* @__PURE__ */ jsx(
|
|
45
|
+
FileAttachment,
|
|
46
|
+
{
|
|
47
|
+
attachment
|
|
48
|
+
},
|
|
49
|
+
`${keyPrefix}_${chunkIndex}`
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
10
53
|
const MessageBlocks = observer(
|
|
11
54
|
({
|
|
55
|
+
attachments = [],
|
|
12
56
|
streamParts,
|
|
13
57
|
showThinkingSkeleton = true
|
|
14
58
|
}) => {
|
|
@@ -69,11 +113,9 @@ const MessageBlocks = observer(
|
|
|
69
113
|
`text_content_${groupIndex}_${blockIndex}_${chunkIndex}`
|
|
70
114
|
);
|
|
71
115
|
}
|
|
72
|
-
return
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
str: chunk
|
|
76
|
-
},
|
|
116
|
+
return renderTextWithAttachments(
|
|
117
|
+
chunk,
|
|
118
|
+
attachments,
|
|
77
119
|
`text_content_${groupIndex}_${blockIndex}_${chunkIndex}`
|
|
78
120
|
);
|
|
79
121
|
});
|
|
@@ -83,5 +125,5 @@ const MessageBlocks = observer(
|
|
|
83
125
|
}
|
|
84
126
|
);
|
|
85
127
|
|
|
86
|
-
export { MessageBlocks };
|
|
128
|
+
export { MessageBlocks, hasResolvedAttachmentPlaceholder };
|
|
87
129
|
//# sourceMappingURL=MessageBlocks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageBlocks.js","sources":["../../../../src/chat/ChatController/components/MessageBlocks.tsx"],"sourcesContent":["import { decodeBase64ToUtf8 } from '@apia/util';\r\nimport { TComponentRender } from '../types';\r\nimport { MessageBlock } from './MessageBlock';\r\nimport { MDRenderer } from '@apia/components';\r\nimport { Box } from '@apia/theme';\r\nimport { TDescriberBlock, TQuestionBlock } from '../StreamMessage';\r\nimport { observer } from 'mobx-react-lite';\r\nimport { ThinkingBlocks } from './ThinkingBlocks';\r\nimport { QuestionBlocks } from './QuestionBlocks';\r\n\r\nexport type TBlockType = 'text' | 'describer' | 'question';\r\n\r\nexport type TBaseStreamBlock<T extends TBlockType = TBlockType> = {\r\n blockType: T;\r\n};\r\n\r\nexport type TTextStreamBlock = TBaseStreamBlock<'text'> & { str: string };\r\nexport type TDescriberStreamBlock = TBaseStreamBlock<'describer'> & {\r\n describer: TDescriberBlock;\r\n};\r\nexport type TQuestionStreamBlock = TBaseStreamBlock<'question'> & {\r\n question: TQuestionBlock;\r\n};\r\n\r\nexport type TStreamBlock =\r\n | TTextStreamBlock\r\n | TDescriberStreamBlock\r\n | TQuestionStreamBlock;\r\n\r\ntype TGroupedStreamBlock = {\r\n blockType: TBlockType;\r\n blocks: TStreamBlock[];\r\n};\r\n\r\nexport const MessageBlocks = observer(\r\n ({\r\n streamParts,\r\n showThinkingSkeleton = true,\r\n }: {\r\n streamParts: TStreamBlock[];\r\n showThinkingSkeleton?: boolean;\r\n }) => {\r\n const groupedParts = streamParts.reduce<TGroupedStreamBlock[]>(\r\n (groups, part) => {\r\n const currentGroup = groups[groups.length - 1];\r\n\r\n if (!currentGroup || currentGroup.blockType !== part.blockType) {\r\n groups.push({\r\n blockType: part.blockType,\r\n blocks: [part],\r\n });\r\n return groups;\r\n }\r\n\r\n currentGroup.blocks.push(part);\r\n return groups;\r\n },\r\n [],\r\n );\r\n\r\n const parts = groupedParts.map((group, groupIndex) => {\r\n const isLastGroup = !groupedParts[groupIndex + 1];\r\n\r\n if (group.blockType === 'describer') {\r\n return (\r\n <ThinkingBlocks\r\n key={`tool_calls_${groupIndex}`}\r\n blocks={group.blocks as TDescriberStreamBlock[]}\r\n groupIndex={groupIndex}\r\n isThinking={showThinkingSkeleton && isLastGroup}\r\n />\r\n );\r\n }\r\n\r\n if (group.blockType === 'question') {\r\n return (\r\n <QuestionBlocks\r\n key={`question_content_${groupIndex}`}\r\n blocks={group.blocks as TQuestionStreamBlock[]}\r\n />\r\n );\r\n }\r\n\r\n return (\r\n <Box className=\"text__content\" key={`text_content_${groupIndex}`}>\r\n {group.blocks.flatMap((block, blockIndex) => {\r\n const textBlock = block as TTextStreamBlock;\r\n\r\n return textBlock.str\r\n .split(/(!!\\[[^]+])/g)\r\n .map((chunk, chunkIndex) => {\r\n if (chunk.match(/^!!\\[[^]+]$/)) {\r\n const definition = JSON.parse(\r\n decodeBase64ToUtf8(\r\n (chunk.match(/^!!\\[([^]+)]$/) ?? [\r\n undefined,\r\n undefined,\r\n ])[1] ?? '',\r\n ),\r\n ) as TComponentRender;\r\n\r\n return (\r\n <MessageBlock\r\n key={`text_content_${groupIndex}_${blockIndex}_${chunkIndex}`}\r\n componentData={definition}\r\n ></MessageBlock>\r\n );\r\n }\r\n\r\n return (\r\n
|
|
1
|
+
{"version":3,"file":"MessageBlocks.js","sources":["../../../../src/chat/ChatController/components/MessageBlocks.tsx"],"sourcesContent":["import { decodeBase64ToUtf8 } from '@apia/util';\r\nimport type { IAttachment, TComponentRender } from '../types';\r\nimport { MessageBlock } from './MessageBlock';\r\nimport { MDRenderer } from '@apia/components';\r\nimport { Box } from '@apia/theme';\r\nimport { TDescriberBlock, TQuestionBlock } from '../StreamMessage';\r\nimport { observer } from 'mobx-react-lite';\r\nimport { ThinkingBlocks } from './ThinkingBlocks';\r\nimport { QuestionBlocks } from './QuestionBlocks';\r\nimport { FileAttachment } from './FileAttachment';\r\n\r\nconst ATTACHMENT_PLACEHOLDER_PATTERN =\r\n /\\[\\[attachment:([^\\r\\n]+?)\\]\\]/g;\r\n\r\nfunction resolveAttachment(\r\n reference: string,\r\n attachments: IAttachment[],\r\n) {\r\n const normalizedReference = reference.trim();\r\n return attachments.find(\r\n (attachment) =>\r\n attachment.id === normalizedReference ||\r\n attachment.name === normalizedReference,\r\n );\r\n}\r\n\r\nexport function hasResolvedAttachmentPlaceholder(\r\n text: string,\r\n attachments: IAttachment[],\r\n) {\r\n ATTACHMENT_PLACEHOLDER_PATTERN.lastIndex = 0;\r\n let match: RegExpExecArray | null;\r\n while ((match = ATTACHMENT_PLACEHOLDER_PATTERN.exec(text))) {\r\n if (resolveAttachment(match[1], attachments)) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\n\r\nfunction renderTextWithAttachments(\r\n text: string,\r\n attachments: IAttachment[],\r\n keyPrefix: string,\r\n) {\r\n return text\r\n .split(/(\\[\\[attachment:[^\\r\\n]+?\\]\\])/g)\r\n .map((chunk, chunkIndex) => {\r\n const match = chunk.match(/^\\[\\[attachment:([^\\r\\n]+?)\\]\\]$/);\r\n if (!match) {\r\n return <MDRenderer str={chunk} key={`${keyPrefix}_${chunkIndex}`} />;\r\n }\r\n\r\n const attachment = resolveAttachment(match[1], attachments);\r\n if (!attachment) {\r\n return (\r\n <MDRenderer\r\n str={match[1].trim()}\r\n key={`${keyPrefix}_${chunkIndex}`}\r\n />\r\n );\r\n }\r\n\r\n return (\r\n <FileAttachment\r\n attachment={attachment}\r\n key={`${keyPrefix}_${chunkIndex}`}\r\n />\r\n );\r\n });\r\n}\r\n\r\nexport type TBlockType = 'text' | 'describer' | 'question';\r\n\r\nexport type TBaseStreamBlock<T extends TBlockType = TBlockType> = {\r\n blockType: T;\r\n};\r\n\r\nexport type TTextStreamBlock = TBaseStreamBlock<'text'> & { str: string };\r\nexport type TDescriberStreamBlock = TBaseStreamBlock<'describer'> & {\r\n describer: TDescriberBlock;\r\n};\r\nexport type TQuestionStreamBlock = TBaseStreamBlock<'question'> & {\r\n question: TQuestionBlock;\r\n};\r\n\r\nexport type TStreamBlock =\r\n | TTextStreamBlock\r\n | TDescriberStreamBlock\r\n | TQuestionStreamBlock;\r\n\r\ntype TGroupedStreamBlock = {\r\n blockType: TBlockType;\r\n blocks: TStreamBlock[];\r\n};\r\n\r\nexport const MessageBlocks = observer(\r\n ({\r\n attachments = [],\r\n streamParts,\r\n showThinkingSkeleton = true,\r\n }: {\r\n attachments?: IAttachment[];\r\n streamParts: TStreamBlock[];\r\n showThinkingSkeleton?: boolean;\r\n }) => {\r\n const groupedParts = streamParts.reduce<TGroupedStreamBlock[]>(\r\n (groups, part) => {\r\n const currentGroup = groups[groups.length - 1];\r\n\r\n if (!currentGroup || currentGroup.blockType !== part.blockType) {\r\n groups.push({\r\n blockType: part.blockType,\r\n blocks: [part],\r\n });\r\n return groups;\r\n }\r\n\r\n currentGroup.blocks.push(part);\r\n return groups;\r\n },\r\n [],\r\n );\r\n\r\n const parts = groupedParts.map((group, groupIndex) => {\r\n const isLastGroup = !groupedParts[groupIndex + 1];\r\n\r\n if (group.blockType === 'describer') {\r\n return (\r\n <ThinkingBlocks\r\n key={`tool_calls_${groupIndex}`}\r\n blocks={group.blocks as TDescriberStreamBlock[]}\r\n groupIndex={groupIndex}\r\n isThinking={showThinkingSkeleton && isLastGroup}\r\n />\r\n );\r\n }\r\n\r\n if (group.blockType === 'question') {\r\n return (\r\n <QuestionBlocks\r\n key={`question_content_${groupIndex}`}\r\n blocks={group.blocks as TQuestionStreamBlock[]}\r\n />\r\n );\r\n }\r\n\r\n return (\r\n <Box className=\"text__content\" key={`text_content_${groupIndex}`}>\r\n {group.blocks.flatMap((block, blockIndex) => {\r\n const textBlock = block as TTextStreamBlock;\r\n\r\n return textBlock.str\r\n .split(/(!!\\[[^]+])/g)\r\n .map((chunk, chunkIndex) => {\r\n if (chunk.match(/^!!\\[[^]+]$/)) {\r\n const definition = JSON.parse(\r\n decodeBase64ToUtf8(\r\n (chunk.match(/^!!\\[([^]+)]$/) ?? [\r\n undefined,\r\n undefined,\r\n ])[1] ?? '',\r\n ),\r\n ) as TComponentRender;\r\n\r\n return (\r\n <MessageBlock\r\n key={`text_content_${groupIndex}_${blockIndex}_${chunkIndex}`}\r\n componentData={definition}\r\n ></MessageBlock>\r\n );\r\n }\r\n\r\n return renderTextWithAttachments(\r\n chunk,\r\n attachments,\r\n `text_content_${groupIndex}_${blockIndex}_${chunkIndex}`,\r\n );\r\n });\r\n })}\r\n </Box>\r\n );\r\n });\r\n\r\n return parts;\r\n },\r\n);\r\n"],"names":[],"mappings":";;;;;;;;;;AAWA,MAAM,8BAAA,GACJ,iCAAA;AAEF,SAAS,iBAAA,CACP,WACA,WAAA,EACA;AACA,EAAA,MAAM,mBAAA,GAAsB,UAAU,IAAA,EAAK;AAC3C,EAAA,OAAO,WAAA,CAAY,IAAA;AAAA,IACjB,CAAC,UAAA,KACC,UAAA,CAAW,EAAA,KAAO,mBAAA,IAClB,WAAW,IAAA,KAAS;AAAA,GACxB;AACF;AAEO,SAAS,gCAAA,CACd,MACA,WAAA,EACA;AACA,EAAA,8BAAA,CAA+B,SAAA,GAAY,CAAA;AAC3C,EAAA,IAAI,KAAA;AACJ,EAAA,OAAQ,KAAA,GAAQ,8BAAA,CAA+B,IAAA,CAAK,IAAI,CAAA,EAAI;AAC1D,IAAA,IAAI,iBAAA,CAAkB,KAAA,CAAM,CAAC,CAAA,EAAG,WAAW,CAAA,EAAG;AAC5C,MAAA,OAAO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AA,EAAG;AAC9B,YAAA,MAAM,aAAa,IAAA,CAAK,KAAA;AAAA,cACtB,kBAAA;AAAA,gBAAA,CACG,KAAA,CAAM,KAAA,CAAM,eAAe,CAAA,IAAK;AAAA,kBAC/B,MAAA;AAAA,kBACA;AAAA,iBACF,EAAG,CAAC,CAAA,IAAK;AAAA;AACX,aACF;AAEA,YAAA,uBACE,GAAA;AAAA,cAAC,YAAA;AAAA,cAAA;AAAA,gBAEC,aAAA,EAAe;AAAA,eAAA;AAAA,cADV,CAAA,aAAA,EAAgB,UAAU,CAAA,CAAA,EAAI,UAAU,IAAI,UAAU,CAAA;AAAA,aAE5D;AAAA;AAIL,UAAA,OAAO,yBAAA;AAAA,YACL,KAAA;AAAA,YACA,WAAA;AAAA,YACA,CAAA,aAAA,EAAgB,UAAU,CAAA,CAAA,EAAI,UAAU,IAAI,UAAU,CAAA;AAAA,WACxD;AAAA,SACD,CAAA;AAAA,OACJ,CAAA,EAAA,EA/BiC,CAAA,aAAA,EAAgB,UAAU,CAAA,CAgC9D,CAAA;AAAA,KAEH,CAAA;AAED,IAAA,OAAO,KAAA;AAAA;AAEX;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export { QuestionAnswerMessage } from './chat/ChatController/components/Question
|
|
|
30
30
|
export { rate } from './chat/ChatController/components/rate.js';
|
|
31
31
|
export { TTextAreaProps, TextArea } from './chat/ChatController/components/TextArea.js';
|
|
32
32
|
export { MessageBody } from './chat/ChatController/components/MessageBody.js';
|
|
33
|
-
export { MessageBlocks, TBaseStreamBlock, TBlockType, TDescriberStreamBlock, TQuestionStreamBlock, TStreamBlock, TTextStreamBlock } from './chat/ChatController/components/MessageBlocks.js';
|
|
33
|
+
export { MessageBlocks, TBaseStreamBlock, TBlockType, TDescriberStreamBlock, TQuestionStreamBlock, TStreamBlock, TTextStreamBlock, hasResolvedAttachmentPlaceholder } from './chat/ChatController/components/MessageBlocks.js';
|
|
34
34
|
export { openFloatingChatController } from './chat/ChatController/openFloatingChatController.js';
|
|
35
35
|
export { AssistantAttachment, AssistantController, AssistantResult, AssistantTransport, AssistantTurn } from './assistant/AssistantController.js';
|
|
36
36
|
export { PanelAssistantTransport } from './assistant/PanelAssistantTransport.js';
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,6 @@ export { QuestionAnswerMessage } from './chat/ChatController/components/Question
|
|
|
31
31
|
export { rate } from './chat/ChatController/components/rate.js';
|
|
32
32
|
export { TextArea } from './chat/ChatController/components/TextArea.js';
|
|
33
33
|
export { MessageBody } from './chat/ChatController/components/MessageBody.js';
|
|
34
|
-
export { MessageBlocks } from './chat/ChatController/components/MessageBlocks.js';
|
|
34
|
+
export { MessageBlocks, hasResolvedAttachmentPlaceholder } from './chat/ChatController/components/MessageBlocks.js';
|
|
35
35
|
export { openFloatingChatController } from './chat/ChatController/openFloatingChatController.js';
|
|
36
36
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apia/ai",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"author": "Alexis Leite <alexisleite@live.com>",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
"libWatchForDashboards": "rollup --watch --config ../../config/rollup.common.mjs --environment MODE:development,ENTRY:index.ts,WATCH:true,DEV_SERVER_MODULE:dashboards"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@apia/api": "^5.2.
|
|
19
|
-
"@apia/components": "^5.2.
|
|
20
|
-
"@apia/dashboard-controller": "^5.2.
|
|
21
|
-
"@apia/icons": "^5.2.
|
|
22
|
-
"@apia/theme": "^5.2.
|
|
23
|
-
"@apia/util": "^5.2.
|
|
18
|
+
"@apia/api": "^5.2.1",
|
|
19
|
+
"@apia/components": "^5.2.1",
|
|
20
|
+
"@apia/dashboard-controller": "^5.2.1",
|
|
21
|
+
"@apia/icons": "^5.2.1",
|
|
22
|
+
"@apia/theme": "^5.2.1",
|
|
23
|
+
"@apia/util": "^5.2.1",
|
|
24
24
|
"mobx": "6.12.3",
|
|
25
25
|
"mobx-react-lite": "3.4.3"
|
|
26
26
|
},
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"access": "public",
|
|
42
42
|
"registry": "https://registry.npmjs.org/"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "0f50f1b97ab48cd6fb2f47195cca1b9d93fa80fa"
|
|
45
45
|
}
|