@fromsko/chat-ui 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +100 -2
- package/lib/adapters/event-bus.d.ts +80 -0
- package/lib/adapters/event-bus.js +73 -0
- package/lib/adapters/index.d.ts +3 -0
- package/lib/adapters/index.js +3 -0
- package/lib/adapters/labels.d.ts +6 -0
- package/lib/adapters/labels.js +17 -0
- package/lib/adapters/stream-bridge.d.ts +9 -0
- package/lib/adapters/stream-bridge.js +7 -0
- package/lib/blocks/cards/AskCard.d.ts +8 -0
- package/lib/blocks/cards/AskCard.js +97 -0
- package/lib/blocks/cards/CompactionCard.d.ts +5 -0
- package/lib/blocks/cards/CompactionCard.js +5 -0
- package/lib/blocks/cards/ContextUsage.d.ts +14 -0
- package/lib/blocks/cards/ContextUsage.js +136 -0
- package/lib/blocks/cards/DisplayCard.d.ts +7 -0
- package/lib/blocks/cards/DisplayCard.js +27 -0
- package/lib/blocks/cards/MemoryPill.d.ts +5 -0
- package/lib/blocks/cards/MemoryPill.js +5 -0
- package/lib/blocks/cards/OutputCard.d.ts +5 -0
- package/lib/blocks/cards/OutputCard.js +13 -0
- package/lib/blocks/cards/PermissionCard.d.ts +21 -0
- package/lib/blocks/cards/PermissionCard.js +26 -0
- package/lib/blocks/cards/SpringCheck.d.ts +9 -0
- package/lib/blocks/cards/SpringCheck.js +17 -0
- package/lib/blocks/cards/TodoCard.d.ts +19 -0
- package/lib/blocks/cards/TodoCard.js +28 -0
- package/lib/blocks/cards/index.d.ts +10 -0
- package/lib/blocks/cards/index.js +10 -0
- package/lib/blocks/composer/Composer.d.ts +66 -0
- package/lib/blocks/composer/Composer.js +73 -0
- package/lib/blocks/composer/ComposerAttachments.d.ts +17 -0
- package/lib/blocks/composer/ComposerAttachments.js +10 -0
- package/lib/blocks/composer/ComposerGrip.d.ts +1 -0
- package/lib/blocks/composer/ComposerGrip.js +39 -0
- package/lib/blocks/composer/ComposerInput.d.ts +18 -0
- package/lib/blocks/composer/ComposerInput.js +60 -0
- package/lib/blocks/composer/ComposerMenus.d.ts +10 -0
- package/lib/blocks/composer/ComposerMenus.js +78 -0
- package/lib/blocks/composer/ComposerToolbar.d.ts +27 -0
- package/lib/blocks/composer/ComposerToolbar.js +16 -0
- package/lib/blocks/composer/MentionPicker.d.ts +13 -0
- package/lib/blocks/composer/MentionPicker.js +71 -0
- package/lib/blocks/composer/PromptPop.d.ts +7 -0
- package/lib/blocks/composer/PromptPop.js +40 -0
- package/lib/blocks/composer/QueuedPrompts.d.ts +14 -0
- package/lib/blocks/composer/QueuedPrompts.js +21 -0
- package/lib/blocks/composer/SlingButton.d.ts +10 -0
- package/lib/blocks/composer/SlingButton.js +112 -0
- package/lib/blocks/composer/index.d.ts +7 -0
- package/lib/blocks/composer/index.js +1 -0
- package/lib/blocks/conversation/ChatEmptyScene.d.ts +4 -0
- package/lib/blocks/conversation/ChatEmptyScene.js +21 -0
- package/lib/blocks/conversation/ChatHeader.d.ts +13 -0
- package/lib/blocks/conversation/ChatHeader.js +20 -0
- package/lib/blocks/conversation/ChatPane.d.ts +90 -0
- package/lib/blocks/conversation/ChatPane.js +60 -0
- package/lib/blocks/conversation/Conversation.d.ts +11 -0
- package/lib/blocks/conversation/Conversation.js +41 -0
- package/lib/blocks/conversation/LineSidebar.d.ts +14 -0
- package/lib/blocks/conversation/LineSidebar.js +42 -0
- package/lib/blocks/conversation/index.d.ts +5 -0
- package/lib/blocks/conversation/index.js +5 -0
- package/lib/blocks/index.d.ts +9 -0
- package/lib/blocks/index.js +9 -0
- package/lib/blocks/message/DayDivider.d.ts +10 -0
- package/lib/blocks/message/DayDivider.js +29 -0
- package/lib/blocks/message/DiffView.d.ts +5 -0
- package/lib/blocks/message/DiffView.js +18 -0
- package/lib/blocks/message/MermaidDiagram.d.ts +4 -0
- package/lib/blocks/message/MermaidDiagram.js +43 -0
- package/lib/blocks/message/Message.d.ts +17 -0
- package/lib/blocks/message/Message.js +45 -0
- package/lib/blocks/message/MessageActionBar.d.ts +18 -0
- package/lib/blocks/message/MessageActionBar.js +15 -0
- package/lib/blocks/message/MessageArtifacts.d.ts +13 -0
- package/lib/blocks/message/MessageArtifacts.js +9 -0
- package/lib/blocks/message/MessageAttachments.d.ts +5 -0
- package/lib/blocks/message/MessageAttachments.js +28 -0
- package/lib/blocks/message/MessageBubble.d.ts +11 -0
- package/lib/blocks/message/MessageBubble.js +31 -0
- package/lib/blocks/message/MessageRow.d.ts +20 -0
- package/lib/blocks/message/MessageRow.js +49 -0
- package/lib/blocks/message/MessageStream.d.ts +23 -0
- package/lib/blocks/message/MessageStream.js +80 -0
- package/lib/blocks/message/MessageTrace.d.ts +16 -0
- package/lib/blocks/message/MessageTrace.js +39 -0
- package/lib/blocks/message/PartView.d.ts +10 -0
- package/lib/blocks/message/PartView.js +29 -0
- package/lib/blocks/message/code-text.d.ts +15 -0
- package/lib/blocks/message/code-text.js +17 -0
- package/lib/blocks/message/index.d.ts +12 -0
- package/lib/blocks/message/index.js +12 -0
- package/lib/blocks/reasoning/Reasoning.d.ts +7 -0
- package/lib/blocks/reasoning/Reasoning.js +26 -0
- package/lib/blocks/reasoning/ReasoningBlock.d.ts +6 -0
- package/lib/blocks/reasoning/ReasoningBlock.js +5 -0
- package/lib/blocks/reasoning/index.d.ts +2 -0
- package/lib/blocks/reasoning/index.js +2 -0
- package/lib/blocks/selection/SelectionActions.d.ts +12 -0
- package/lib/blocks/selection/SelectionActions.js +29 -0
- package/lib/blocks/selection/SelectionBar.d.ts +10 -0
- package/lib/blocks/selection/SelectionBar.js +6 -0
- package/lib/blocks/selection/index.d.ts +2 -0
- package/lib/blocks/selection/index.js +2 -0
- package/lib/blocks/settings/DisplaySettingsPanel.d.ts +5 -0
- package/lib/blocks/settings/DisplaySettingsPanel.js +33 -0
- package/lib/blocks/settings/SquishSwitch.d.ts +8 -0
- package/lib/blocks/settings/SquishSwitch.js +21 -0
- package/lib/blocks/settings/index.d.ts +2 -0
- package/lib/blocks/settings/index.js +2 -0
- package/lib/blocks/status/LatticeLoader.d.ts +12 -0
- package/lib/blocks/status/LatticeLoader.js +22 -0
- package/lib/blocks/status/TypingIndicator.d.ts +5 -0
- package/lib/blocks/status/TypingIndicator.js +5 -0
- package/lib/blocks/status/index.d.ts +2 -0
- package/lib/blocks/status/index.js +2 -0
- package/lib/blocks/tool/SandboxCard.d.ts +5 -0
- package/lib/blocks/tool/SandboxCard.js +10 -0
- package/lib/blocks/tool/ToolCard.d.ts +10 -0
- package/lib/blocks/tool/ToolCard.js +32 -0
- package/lib/blocks/tool/ToolGroup.d.ts +6 -0
- package/lib/blocks/tool/ToolGroup.js +23 -0
- package/lib/blocks/tool/exec-envelope.d.ts +7 -0
- package/lib/blocks/tool/exec-envelope.js +43 -0
- package/lib/blocks/tool/index.d.ts +4 -0
- package/lib/blocks/tool/index.js +4 -0
- package/lib/domain/ask.d.ts +14 -0
- package/lib/domain/ask.js +50 -0
- package/lib/domain/attachments.d.ts +16 -0
- package/lib/domain/attachments.js +126 -0
- package/lib/domain/attribution.d.ts +4 -0
- package/lib/domain/attribution.js +11 -0
- package/lib/domain/composer-palette.d.ts +15 -0
- package/lib/domain/composer-palette.js +131 -0
- package/lib/domain/index.d.ts +12 -0
- package/lib/domain/index.js +12 -0
- package/lib/domain/mention.d.ts +17 -0
- package/lib/domain/mention.js +95 -0
- package/lib/domain/message-blocks.d.ts +29 -0
- package/lib/domain/message-blocks.js +63 -0
- package/lib/domain/message-menu.d.ts +4 -0
- package/lib/domain/message-menu.js +46 -0
- package/lib/domain/queue.d.ts +23 -0
- package/lib/domain/queue.js +52 -0
- package/lib/domain/reducer.d.ts +137 -0
- package/lib/domain/reducer.js +442 -0
- package/lib/domain/selection-actions.d.ts +13 -0
- package/lib/domain/selection-actions.js +56 -0
- package/lib/domain/selection-gates.d.ts +6 -0
- package/lib/domain/selection-gates.js +36 -0
- package/lib/domain/slash-commands.d.ts +16 -0
- package/lib/domain/slash-commands.js +142 -0
- package/lib/hooks/index.d.ts +8 -0
- package/lib/hooks/index.js +8 -0
- package/lib/hooks/useComposerPalette.d.ts +35 -0
- package/lib/hooks/useComposerPalette.js +120 -0
- package/lib/hooks/useComposerSubmit.d.ts +31 -0
- package/lib/hooks/useComposerSubmit.js +135 -0
- package/lib/hooks/useInputHistory.d.ts +14 -0
- package/lib/hooks/useInputHistory.js +52 -0
- package/lib/hooks/usePendingAsk.d.ts +11 -0
- package/lib/hooks/usePendingAsk.js +33 -0
- package/lib/hooks/usePendingPermissions.d.ts +10 -0
- package/lib/hooks/usePendingPermissions.js +26 -0
- package/lib/hooks/useQueuedPrompts.d.ts +12 -0
- package/lib/hooks/useQueuedPrompts.js +91 -0
- package/lib/hooks/useSelectionPop.d.ts +13 -0
- package/lib/hooks/useSelectionPop.js +130 -0
- package/lib/hooks/useStreamBridge.d.ts +1 -0
- package/lib/hooks/useStreamBridge.js +23 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +10 -0
- package/lib/primitives/Badge.d.ts +7 -0
- package/lib/primitives/Badge.js +13 -0
- package/lib/primitives/Button.d.ts +9 -0
- package/lib/primitives/Button.js +21 -0
- package/lib/primitives/Collapsible.d.ts +12 -0
- package/lib/primitives/Collapsible.js +14 -0
- package/lib/primitives/Dialog.d.ts +10 -0
- package/lib/primitives/Dialog.js +19 -0
- package/lib/primitives/DropdownMenu.d.ts +28 -0
- package/lib/primitives/DropdownMenu.js +37 -0
- package/lib/primitives/Empty.d.ts +8 -0
- package/lib/primitives/Empty.js +6 -0
- package/lib/primitives/Input.d.ts +3 -0
- package/lib/primitives/Input.js +6 -0
- package/lib/primitives/Kbd.d.ts +2 -0
- package/lib/primitives/Kbd.js +5 -0
- package/lib/primitives/Popover.d.ts +15 -0
- package/lib/primitives/Popover.js +32 -0
- package/lib/primitives/ScrollArea.d.ts +5 -0
- package/lib/primitives/ScrollArea.js +5 -0
- package/lib/primitives/Separator.d.ts +5 -0
- package/lib/primitives/Separator.js +5 -0
- package/lib/primitives/Spinner.d.ts +5 -0
- package/lib/primitives/Spinner.js +5 -0
- package/lib/primitives/Textarea.d.ts +3 -0
- package/lib/primitives/Textarea.js +6 -0
- package/lib/primitives/Tooltip.d.ts +8 -0
- package/lib/primitives/Tooltip.js +7 -0
- package/lib/primitives/index.d.ts +14 -0
- package/lib/primitives/index.js +14 -0
- package/lib/reactbits/Motion.d.ts +24 -0
- package/lib/reactbits/Motion.js +52 -0
- package/lib/reactbits/index.d.ts +1 -0
- package/lib/reactbits/index.js +1 -0
- package/lib/stores/chat-store.d.ts +33 -0
- package/lib/stores/chat-store.js +93 -0
- package/lib/stores/display-store.d.ts +15 -0
- package/lib/stores/display-store.js +116 -0
- package/lib/stores/index.d.ts +3 -0
- package/lib/stores/index.js +3 -0
- package/lib/stores/theme-store.d.ts +8 -0
- package/lib/stores/theme-store.js +29 -0
- package/lib/tokens/index.d.ts +21 -0
- package/lib/tokens/index.js +66 -0
- package/lib/types/agent.d.ts +62 -0
- package/lib/types/agent.js +1 -0
- package/lib/types/callbacks.d.ts +55 -0
- package/lib/types/callbacks.js +1 -0
- package/lib/types/composer.d.ts +116 -0
- package/lib/types/composer.js +1 -0
- package/lib/types/conversation.d.ts +54 -0
- package/lib/types/conversation.js +1 -0
- package/lib/types/display.d.ts +25 -0
- package/lib/types/display.js +40 -0
- package/lib/types/index.d.ts +8 -0
- package/lib/types/index.js +8 -0
- package/lib/types/message.d.ts +100 -0
- package/lib/types/message.js +1 -0
- package/lib/types/selection.d.ts +60 -0
- package/lib/types/selection.js +1 -0
- package/lib/types/theme.d.ts +100 -0
- package/lib/types/theme.js +1 -0
- package/lib/utils/clipboard.d.ts +4 -0
- package/lib/utils/clipboard.js +41 -0
- package/lib/utils/cn.d.ts +2 -0
- package/lib/utils/cn.js +14 -0
- package/lib/utils/index.d.ts +3 -0
- package/lib/utils/index.js +3 -0
- package/lib/utils/storage.d.ts +11 -0
- package/lib/utils/storage.js +48 -0
- package/package.json +93 -4
- package/src/styles/blocks.css +2439 -0
- package/src/styles/index.css +3 -0
- package/src/tokens/theme.css +464 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export const TOOL_GROUP_MIN = 2;
|
|
2
|
+
export function isToolGroupPart(part) {
|
|
3
|
+
return part.kind === "tool" || part.kind === "sandbox";
|
|
4
|
+
}
|
|
5
|
+
export function toolGroupLabel(part) {
|
|
6
|
+
return part.kind === "tool" ? part.tool : part.title;
|
|
7
|
+
}
|
|
8
|
+
export function keyMessageParts(message) {
|
|
9
|
+
const counters = {};
|
|
10
|
+
return (message.parts ?? []).map((part) => {
|
|
11
|
+
const n = (counters[part.kind] = (counters[part.kind] ?? 0) + 1);
|
|
12
|
+
return { key: `${message.id}-${part.kind}-${n}`, part };
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export function orderMessageBlocks(message, showBubble) {
|
|
16
|
+
const keyed = keyMessageParts(message);
|
|
17
|
+
const blocks = [];
|
|
18
|
+
let run = [];
|
|
19
|
+
const flush = () => {
|
|
20
|
+
if (run.length === 0)
|
|
21
|
+
return;
|
|
22
|
+
if (run.length >= TOOL_GROUP_MIN) {
|
|
23
|
+
blocks.push({
|
|
24
|
+
type: "tool-group",
|
|
25
|
+
key: `${message.id}-toolgroup-${run[0].key}`,
|
|
26
|
+
parts: run,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
for (const item of run) {
|
|
31
|
+
blocks.push({ type: "part", key: item.key, part: item.part });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
run = [];
|
|
35
|
+
};
|
|
36
|
+
for (const item of keyed) {
|
|
37
|
+
if (isToolGroupPart(item.part)) {
|
|
38
|
+
run.push({ key: item.key, part: item.part });
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
flush();
|
|
42
|
+
blocks.push({ type: "part", key: item.key, part: item.part });
|
|
43
|
+
}
|
|
44
|
+
flush();
|
|
45
|
+
if (showBubble) {
|
|
46
|
+
blocks.push({ type: "text", key: `${message.id}-text` });
|
|
47
|
+
}
|
|
48
|
+
return blocks;
|
|
49
|
+
}
|
|
50
|
+
export function promoteMemoryFirst(blocks) {
|
|
51
|
+
const memory = [];
|
|
52
|
+
const rest = [];
|
|
53
|
+
for (const b of blocks) {
|
|
54
|
+
if (b.type === "part" && b.part.kind === "memory")
|
|
55
|
+
memory.push(b);
|
|
56
|
+
else
|
|
57
|
+
rest.push(b);
|
|
58
|
+
}
|
|
59
|
+
return [...memory, ...rest];
|
|
60
|
+
}
|
|
61
|
+
export function blockKind(block) {
|
|
62
|
+
return block.type === "part" ? block.part.kind : block.type;
|
|
63
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MessageMenuInput, MessageMenuItem } from "../types/selection";
|
|
2
|
+
export declare function messageTextOf(element: HTMLElement): string;
|
|
3
|
+
export declare function formatQuote(text: string): string;
|
|
4
|
+
export declare function messageMenuItems(input: MessageMenuInput): MessageMenuItem[];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export function messageTextOf(element) {
|
|
2
|
+
const bubble = element.matches('[data-cmp="ac/bubble"]')
|
|
3
|
+
? element
|
|
4
|
+
: element.querySelector('[data-cmp="ac/bubble"]');
|
|
5
|
+
if (!bubble)
|
|
6
|
+
return "";
|
|
7
|
+
const text = bubble.innerText ?? bubble.textContent ?? "";
|
|
8
|
+
return text.trim();
|
|
9
|
+
}
|
|
10
|
+
export function formatQuote(text) {
|
|
11
|
+
return text
|
|
12
|
+
.split("\n")
|
|
13
|
+
.map((l) => l.trim())
|
|
14
|
+
.filter((l) => l.length > 0)
|
|
15
|
+
.slice(0, 3)
|
|
16
|
+
.map((l) => `> ${l}`)
|
|
17
|
+
.join("\n");
|
|
18
|
+
}
|
|
19
|
+
export function messageMenuItems(input) {
|
|
20
|
+
const { role, text, selection, id } = input;
|
|
21
|
+
const items = [];
|
|
22
|
+
const hasText = text.trim().length > 0;
|
|
23
|
+
const hasSelection = selection.trim().length > 0;
|
|
24
|
+
items.push({
|
|
25
|
+
id: "copy-text",
|
|
26
|
+
label: "复制消息",
|
|
27
|
+
disabled: !hasText,
|
|
28
|
+
...(hasText ? {} : {}),
|
|
29
|
+
});
|
|
30
|
+
if (role === "assistant" && hasText) {
|
|
31
|
+
items.push({ id: "quote", label: "引用到输入框" });
|
|
32
|
+
}
|
|
33
|
+
items.push({ id: "multi-select", label: "多选" });
|
|
34
|
+
if (hasSelection) {
|
|
35
|
+
items.push({
|
|
36
|
+
id: "copy-selection",
|
|
37
|
+
label: "复制选中片段",
|
|
38
|
+
separatorBefore: true,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (id) {
|
|
42
|
+
items.push({ id: "trace", label: "溯源", separatorBefore: true });
|
|
43
|
+
items.push({ id: "delete-message", label: "删除消息", danger: true });
|
|
44
|
+
}
|
|
45
|
+
return items;
|
|
46
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { QueuedPrompt } from "../types/conversation";
|
|
2
|
+
import type { EnqueueOutcome, SubmitDecision } from "../types/composer";
|
|
3
|
+
export declare const MAX_QUEUED_PROMPTS = 8;
|
|
4
|
+
export declare const QUEUED_FULL_NOTICE = "\u5F85\u53D1\u961F\u5217\u5DF2\u6EE1\uFF088 \u6761\uFF09\uFF0C\u8BF7\u5148\u5904\u7406";
|
|
5
|
+
export declare function nextQueuedId(): string;
|
|
6
|
+
export declare function decideSubmit(streaming: boolean, full: boolean): SubmitDecision;
|
|
7
|
+
export declare function enqueuePrompt(items: readonly QueuedPrompt[], prompt: QueuedPrompt): QueuedPrompt[] | null;
|
|
8
|
+
export declare function removePrompt(items: readonly QueuedPrompt[], id: string): QueuedPrompt[];
|
|
9
|
+
export declare function movePrompt(items: readonly QueuedPrompt[], id: string, delta: -1 | 1): QueuedPrompt[];
|
|
10
|
+
export declare function takeHeadPrompt(items: readonly QueuedPrompt[]): {
|
|
11
|
+
rest: QueuedPrompt[];
|
|
12
|
+
taken: QueuedPrompt | null;
|
|
13
|
+
};
|
|
14
|
+
export declare function prependPrompt(items: readonly QueuedPrompt[], prompt: QueuedPrompt): QueuedPrompt[];
|
|
15
|
+
export interface QueueEdge {
|
|
16
|
+
conversationId: string;
|
|
17
|
+
status: "idle" | "loading" | "streaming" | "error";
|
|
18
|
+
}
|
|
19
|
+
export declare function flushEdge(prev: QueueEdge, next: QueueEdge, pending: readonly QueuedPrompt[]): {
|
|
20
|
+
rest: QueuedPrompt[];
|
|
21
|
+
taken: QueuedPrompt | null;
|
|
22
|
+
};
|
|
23
|
+
export type { EnqueueOutcome, SubmitDecision };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export const MAX_QUEUED_PROMPTS = 8;
|
|
2
|
+
export const QUEUED_FULL_NOTICE = `待发队列已满(${MAX_QUEUED_PROMPTS} 条),请先处理`;
|
|
3
|
+
let seq = 0;
|
|
4
|
+
export function nextQueuedId() {
|
|
5
|
+
seq += 1;
|
|
6
|
+
return `q-${Date.now()}-${seq}`;
|
|
7
|
+
}
|
|
8
|
+
export function decideSubmit(streaming, full) {
|
|
9
|
+
if (!streaming)
|
|
10
|
+
return "send";
|
|
11
|
+
return full ? "reject-full" : "enqueue";
|
|
12
|
+
}
|
|
13
|
+
export function enqueuePrompt(items, prompt) {
|
|
14
|
+
if (items.length >= MAX_QUEUED_PROMPTS)
|
|
15
|
+
return null;
|
|
16
|
+
return [...items, prompt];
|
|
17
|
+
}
|
|
18
|
+
export function removePrompt(items, id) {
|
|
19
|
+
return items.filter((p) => p.id !== id);
|
|
20
|
+
}
|
|
21
|
+
export function movePrompt(items, id, delta) {
|
|
22
|
+
const index = items.findIndex((p) => p.id === id);
|
|
23
|
+
if (index < 0)
|
|
24
|
+
return [...items];
|
|
25
|
+
const target = index + delta;
|
|
26
|
+
if (target < 0 || target >= items.length)
|
|
27
|
+
return [...items];
|
|
28
|
+
const next = [...items];
|
|
29
|
+
const [item] = next.splice(index, 1);
|
|
30
|
+
next.splice(target, 0, item);
|
|
31
|
+
return next;
|
|
32
|
+
}
|
|
33
|
+
export function takeHeadPrompt(items) {
|
|
34
|
+
if (items.length === 0)
|
|
35
|
+
return { rest: [], taken: null };
|
|
36
|
+
return { rest: items.slice(1), taken: items[0] };
|
|
37
|
+
}
|
|
38
|
+
export function prependPrompt(items, prompt) {
|
|
39
|
+
return [prompt, ...items];
|
|
40
|
+
}
|
|
41
|
+
export function flushEdge(prev, next, pending) {
|
|
42
|
+
if (pending.length === 0)
|
|
43
|
+
return { rest: [], taken: null };
|
|
44
|
+
const sameConversation = prev.conversationId === next.conversationId;
|
|
45
|
+
const settledSame = sameConversation &&
|
|
46
|
+
prev.status === "streaming" &&
|
|
47
|
+
next.status !== "streaming";
|
|
48
|
+
const switchedIdle = !sameConversation && next.status !== "streaming";
|
|
49
|
+
if (settledSame || switchedIdle)
|
|
50
|
+
return takeHeadPrompt(pending);
|
|
51
|
+
return { rest: [...pending], taken: null };
|
|
52
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { Agent } from "../types/agent";
|
|
2
|
+
import type { Conversation, ConversationId, ConversationStatus } from "../types/conversation";
|
|
3
|
+
import type { ChatMessage } from "../types/message";
|
|
4
|
+
export interface ConversationState {
|
|
5
|
+
agents: Record<string, Agent>;
|
|
6
|
+
conversations: Conversation[];
|
|
7
|
+
messages: Record<ConversationId, ChatMessage[]>;
|
|
8
|
+
drafts: Record<ConversationId, string>;
|
|
9
|
+
activeId: ConversationId | null;
|
|
10
|
+
query: string;
|
|
11
|
+
persistError: string | null;
|
|
12
|
+
}
|
|
13
|
+
export type ConversationAction = {
|
|
14
|
+
type: "select";
|
|
15
|
+
id: ConversationId;
|
|
16
|
+
} | {
|
|
17
|
+
type: "query";
|
|
18
|
+
value: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: "draft";
|
|
21
|
+
id: ConversationId;
|
|
22
|
+
value: string;
|
|
23
|
+
} | {
|
|
24
|
+
type: "append";
|
|
25
|
+
id: ConversationId;
|
|
26
|
+
message: ChatMessage;
|
|
27
|
+
} | {
|
|
28
|
+
type: "hydrateMessages";
|
|
29
|
+
id: ConversationId;
|
|
30
|
+
messages: ChatMessage[];
|
|
31
|
+
} | {
|
|
32
|
+
type: "deleteMessage";
|
|
33
|
+
id: ConversationId;
|
|
34
|
+
messageId: string;
|
|
35
|
+
} | {
|
|
36
|
+
type: "insertMessageAt";
|
|
37
|
+
id: ConversationId;
|
|
38
|
+
index: number;
|
|
39
|
+
message: ChatMessage;
|
|
40
|
+
} | {
|
|
41
|
+
type: "bindRequest";
|
|
42
|
+
requestId: string;
|
|
43
|
+
} | {
|
|
44
|
+
type: "streamDelta";
|
|
45
|
+
requestId: string;
|
|
46
|
+
text: string;
|
|
47
|
+
} | {
|
|
48
|
+
type: "streamEnd";
|
|
49
|
+
requestId: string;
|
|
50
|
+
outcome: "done" | "error";
|
|
51
|
+
error?: string;
|
|
52
|
+
} | {
|
|
53
|
+
type: "streamToolCall";
|
|
54
|
+
requestId: string;
|
|
55
|
+
toolCallId: string;
|
|
56
|
+
name: string;
|
|
57
|
+
args: unknown;
|
|
58
|
+
} | {
|
|
59
|
+
type: "streamToolResult";
|
|
60
|
+
requestId: string;
|
|
61
|
+
toolCallId: string;
|
|
62
|
+
result: string;
|
|
63
|
+
isError: boolean;
|
|
64
|
+
} | {
|
|
65
|
+
type: "streamReasoning";
|
|
66
|
+
requestId: string;
|
|
67
|
+
text: string;
|
|
68
|
+
} | {
|
|
69
|
+
type: "streamContextUsage";
|
|
70
|
+
requestId: string;
|
|
71
|
+
inputTokens: number;
|
|
72
|
+
outputTokens: number;
|
|
73
|
+
window: number;
|
|
74
|
+
} | {
|
|
75
|
+
type: "streamMemory";
|
|
76
|
+
requestId: string;
|
|
77
|
+
count: number;
|
|
78
|
+
excerpt: string;
|
|
79
|
+
} | {
|
|
80
|
+
type: "streamCompaction";
|
|
81
|
+
requestId: string | null;
|
|
82
|
+
beforeTokens: number;
|
|
83
|
+
afterTokens: number;
|
|
84
|
+
reason: string;
|
|
85
|
+
} | {
|
|
86
|
+
type: "streamDisplay";
|
|
87
|
+
requestId: string;
|
|
88
|
+
view: string;
|
|
89
|
+
title?: string;
|
|
90
|
+
payload?: unknown;
|
|
91
|
+
} | {
|
|
92
|
+
type: "streamOutput";
|
|
93
|
+
requestId: string;
|
|
94
|
+
outputKind: "text" | "file" | "link" | "json";
|
|
95
|
+
label?: string;
|
|
96
|
+
value: string;
|
|
97
|
+
} | {
|
|
98
|
+
type: "addConversation";
|
|
99
|
+
conversation: Conversation;
|
|
100
|
+
} | {
|
|
101
|
+
type: "dropConversation";
|
|
102
|
+
id: ConversationId;
|
|
103
|
+
} | {
|
|
104
|
+
type: "persistError";
|
|
105
|
+
value: string | null;
|
|
106
|
+
} | {
|
|
107
|
+
type: "togglePin";
|
|
108
|
+
id: ConversationId;
|
|
109
|
+
} | {
|
|
110
|
+
type: "toggleMute";
|
|
111
|
+
id: ConversationId;
|
|
112
|
+
} | {
|
|
113
|
+
type: "renameConversation";
|
|
114
|
+
id: ConversationId;
|
|
115
|
+
title: string;
|
|
116
|
+
} | {
|
|
117
|
+
type: "setMembers";
|
|
118
|
+
id: ConversationId;
|
|
119
|
+
memberIds: string[];
|
|
120
|
+
} | {
|
|
121
|
+
type: "setAutoRespond";
|
|
122
|
+
id: ConversationId;
|
|
123
|
+
value: boolean;
|
|
124
|
+
} | {
|
|
125
|
+
type: "createGroup";
|
|
126
|
+
members: string[];
|
|
127
|
+
title: string;
|
|
128
|
+
id: ConversationId;
|
|
129
|
+
} | {
|
|
130
|
+
type: "replaceAgents";
|
|
131
|
+
agents: Record<string, Agent>;
|
|
132
|
+
};
|
|
133
|
+
export declare function conversationReducer(state: ConversationState, action: ConversationAction): ConversationState;
|
|
134
|
+
export declare function createConversationState(partial?: Partial<ConversationState>): ConversationState;
|
|
135
|
+
export declare function isConversationStreaming(state: ConversationState, id: ConversationId): boolean;
|
|
136
|
+
export declare function inFlightRequestIds(state: ConversationState, id: ConversationId): string[];
|
|
137
|
+
export type { ConversationStatus };
|