@nextclaw/ui 0.14.1 → 0.14.2
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/CHANGELOG.md +29 -0
- package/dist/assets/{api-DPcvCLfa.js → api-a14tR_z1.js} +7 -7
- package/dist/assets/channels-list-page-CFGkm4DT.js +8 -0
- package/dist/assets/chat-page-CEdavJXc.js +105 -0
- package/dist/assets/{config-split-page-BCJhqdK9.js → config-split-page-B5b9B0uE.js} +1 -1
- package/dist/assets/{confirm-dialog-CWh5FfK2.js → confirm-dialog-ClH_Ec7n.js} +1 -1
- package/dist/assets/{desktop-update-config-DsRhBizi.js → desktop-update-config-DPNDnVpk.js} +1 -1
- package/dist/assets/{dist-DPrgcEC0.js → dist-BtCS2Ucq.js} +1 -1
- package/dist/assets/{dist-DsE4OsSS.js → dist-CLGGLm8b.js} +1 -1
- package/dist/assets/doc-browser-5nMWYKBD.js +1 -0
- package/dist/assets/doc-browser-BJRLhztv.js +1 -0
- package/dist/assets/doc-browser-context-D4JwMMxK.js +1 -0
- package/dist/assets/{ellipsis-B81FStLm.js → ellipsis-CtJXjIol.js} +1 -1
- package/dist/assets/{external-link-C_dmG-WJ.js → external-link-CdJiG13p.js} +1 -1
- package/dist/assets/index-BDN1zzMQ.js +105 -0
- package/dist/assets/index-g3uSZXoc.css +1 -0
- package/dist/assets/mcp-marketplace-page-BU0kIjhR.js +40 -0
- package/dist/assets/mcp-marketplace-page-sMNFSq_T.js +1 -0
- package/dist/assets/middleware-CkFT3R4v.js +1 -0
- package/dist/assets/model-config-page-D6hYXROd.js +1 -0
- package/dist/assets/plus-DPjb0piO.js +1 -0
- package/dist/assets/provider-scoped-model-input-DAX2HgmR.js +1 -0
- package/dist/assets/providers-config-page-BzAeaACA.js +1 -0
- package/dist/assets/{react-sZz5HSCm.js → react-C6cZgP44.js} +1 -1
- package/dist/assets/remote-B0G80uPr.js +1 -0
- package/dist/assets/rotate-cw-DnEB1Rju.js +1 -0
- package/dist/assets/runtime-config-page-C5xKaV3i.js +1 -0
- package/dist/assets/{save-MzjoiHri.js → save-DKA0x4zk.js} +1 -1
- package/dist/assets/{search-B29dE4GN.js → search-BNlcoj5c.js} +1 -1
- package/dist/assets/{search-config-page-Dl5sZzob.js → search-config-page-Cq9uJ-N8.js} +1 -1
- package/dist/assets/{secrets-config-page-C_l-IFCK.js → secrets-config-page-CxSbZLBo.js} +2 -2
- package/dist/assets/{select-BKmh05hd.js → select-CvTlDZTQ.js} +1 -1
- package/dist/assets/{tag-chip-BS_7Ueom.js → tag-chip-8ffF2y2C.js} +1 -1
- package/dist/assets/use-config-DmT0o1gv.js +1 -0
- package/dist/assets/x-BiSSpgqB.js +1 -0
- package/dist/index.html +15 -14
- package/package.json +9 -9
- package/src/app/components/app-presenter-provider.tsx +11 -2
- package/src/app/components/layout/__tests__/app-layout.test.tsx +11 -2
- package/src/app/components/layout/__tests__/sidebar.layout.test.tsx +110 -79
- package/src/app/components/layout/app-layout.tsx +18 -4
- package/src/app/components/layout/sidebar-items.tsx +194 -71
- package/src/app/components/layout/sidebar-rail.styles.ts +15 -0
- package/src/app/components/layout/sidebar.tsx +340 -83
- package/src/app/managers/viewport-layout.manager.ts +10 -0
- package/src/app/stores/viewport-layout.store.ts +39 -3
- package/src/features/agents/components/__tests__/agents-page.test.tsx +62 -39
- package/src/features/agents/components/agents-page.tsx +10 -6
- package/src/features/chat/components/conversation/__tests__/chat-conversation-header-section.test.tsx +145 -0
- package/src/features/chat/components/conversation/__tests__/chat-conversation-panel.test.tsx +69 -762
- package/src/features/chat/components/conversation/__tests__/chat-conversation-workspace-section.test.tsx +132 -0
- package/src/features/chat/components/conversation/chat-conversation-content.tsx +22 -15
- package/src/features/chat/components/conversation/chat-conversation-header-section.tsx +14 -15
- package/src/features/chat/components/conversation/chat-conversation-panel.tsx +18 -18
- package/src/features/chat/components/conversation/chat-conversation-workspace-section.tsx +10 -4
- package/src/features/chat/components/layout/__tests__/chat-sidebar-read-state.test.tsx +52 -11
- package/src/features/chat/components/layout/__tests__/chat-sidebar.test.tsx +16 -14
- package/src/features/chat/components/layout/chat-sidebar-desktop-layout.tsx +247 -0
- package/src/features/chat/components/layout/chat-sidebar-toolbar.tsx +80 -7
- package/src/features/chat/components/layout/chat-sidebar-utility-menu.tsx +82 -25
- package/src/features/chat/components/layout/chat-sidebar.tsx +59 -92
- package/src/features/chat/components/providers/chat-presenter.provider.tsx +0 -6
- package/src/features/chat/features/conversation/components/session-conversation-area.tsx +289 -0
- package/src/features/chat/features/conversation/components/session-conversation-input.tsx +427 -0
- package/src/features/chat/features/conversation/hooks/use-session-conversation-controller.ts +204 -0
- package/src/features/chat/features/conversation/hooks/use-session-conversation-input-attachments.ts +66 -0
- package/src/features/chat/features/{input/hooks/use-chat-input-bar-query-state.ts → conversation/hooks/use-session-conversation-input-query.ts} +32 -17
- package/src/features/chat/features/conversation/hooks/use-session-conversation-input-state.ts +281 -0
- package/src/features/chat/features/conversation/utils/session-conversation-input-toolbar.utils.ts +158 -0
- package/src/features/chat/features/input/hooks/__tests__/use-chat-input-surface-state.test.tsx +56 -0
- package/src/features/chat/features/input/hooks/use-chat-input-surface-state.ts +117 -0
- package/src/features/chat/features/input/input-surface-plugins/__tests__/panel-app-reference-plugin.test.ts +77 -0
- package/src/features/chat/features/input/input-surface-plugins/__tests__/slash-command-plugin.test.ts +108 -0
- package/src/features/chat/features/input/input-surface-plugins/chat-input-product-plugin-adapters.types.ts +10 -0
- package/src/features/chat/features/input/input-surface-plugins/input-surface-search.utils.ts +108 -0
- package/src/features/chat/features/input/input-surface-plugins/panel-app-reference-plugin.utils.ts +108 -0
- package/src/features/chat/features/input/input-surface-plugins/slash-command-plugin.utils.ts +161 -0
- package/src/features/chat/features/input/utils/__tests__/chat-composer-state.utils.test.ts +22 -1
- package/src/features/chat/features/input/utils/__tests__/chat-inline-token.utils.test.ts +26 -13
- package/src/features/chat/features/input/utils/__tests__/ncp-chat-input-availability.utils.test.ts +7 -28
- package/src/features/chat/features/input/utils/chat-composer-state.utils.ts +6 -0
- package/src/features/chat/features/input/utils/chat-inline-token.utils.ts +26 -51
- package/src/features/chat/features/input/utils/chat-input-bar.utils.ts +2 -0
- package/src/features/chat/features/input/utils/ncp-chat-input-availability.utils.ts +5 -6
- package/src/features/chat/features/message/components/__tests__/chat-message-list.container.test.tsx +47 -12
- package/src/features/chat/features/message/components/chat-message-list.container.tsx +93 -12
- package/src/features/chat/features/message/utils/__tests__/chat-message.utils.test.ts +31 -12
- package/src/features/chat/features/message/utils/chat-message-markdown-part.utils.ts +38 -0
- package/src/features/chat/features/message/utils/chat-message-part.utils.ts +1 -1
- package/src/features/chat/features/session/components/chat-sidebar-project-groups.tsx +2 -2
- package/src/features/chat/features/session/components/chat-sidebar-session-list.tsx +2 -2
- package/src/features/chat/features/session/hooks/__tests__/use-chat-session-project.test.tsx +3 -30
- package/src/features/chat/features/session/hooks/use-chat-session-project.ts +0 -5
- package/src/features/chat/features/session/utils/chat-run-metadata.utils.ts +8 -0
- package/src/features/chat/features/session-type/components/__tests__/chat-session-type-menu.test.tsx +2 -2
- package/src/features/chat/features/session-type/components/__tests__/chat-session-type-option-item.test.tsx +2 -0
- package/src/features/chat/features/session-type/components/chat-session-type-menu.tsx +2 -2
- package/src/features/chat/features/session-type/components/chat-session-type-option-item.tsx +2 -2
- package/src/features/chat/features/welcome/components/__tests__/chat-conversation-welcome.test.tsx +49 -31
- package/src/features/chat/features/welcome/components/__tests__/chat-welcome.test.tsx +2 -2
- package/src/features/chat/features/welcome/components/chat-conversation-welcome.tsx +21 -10
- package/src/features/chat/features/welcome/components/chat-welcome-session-type-picker.tsx +2 -2
- package/src/features/chat/features/welcome/components/chat-welcome.tsx +2 -2
- package/src/features/chat/features/workspace/components/__tests__/chat-session-workspace-panel-content.test.tsx +54 -0
- package/src/features/chat/features/workspace/components/chat-session-workspace-panel-content.tsx +44 -76
- package/src/features/chat/features/workspace/components/chat-session-workspace-panel-nav.tsx +5 -1
- package/src/features/chat/features/workspace/components/chat-session-workspace-panel.tsx +7 -1
- package/src/features/chat/features/workspace/hooks/use-chat-conversation-workspace-state.ts +40 -31
- package/src/features/chat/features/workspace/utils/__tests__/chat-workspace-panel-view-model.utils.test.ts +59 -1
- package/src/features/chat/features/workspace/utils/chat-thread-workspace-session.utils.ts +109 -0
- package/src/features/chat/features/workspace/utils/chat-workspace-panel-view-model.utils.ts +44 -4
- package/src/features/chat/index.ts +0 -1
- package/src/features/chat/managers/__tests__/chat-session-list.manager.test.ts +51 -99
- package/src/features/chat/managers/__tests__/chat-thread.manager.test.ts +135 -21
- package/src/features/chat/managers/chat-session-list.manager.ts +12 -43
- package/src/features/chat/managers/chat-thread.manager.ts +108 -34
- package/src/features/chat/pages/__tests__/ncp-chat-page.test.ts +48 -1
- package/src/features/chat/pages/__tests__/ncp-chat-page.test.tsx +72 -0
- package/src/features/chat/pages/ncp-chat-page.tsx +0 -122
- package/src/features/chat/presenters/chat.presenter.ts +2 -19
- package/src/features/chat/stores/__tests__/chat-thread.store.test.ts +31 -0
- package/src/features/chat/stores/chat-thread.store.ts +42 -26
- package/src/features/panel-apps/hooks/use-panel-apps.ts +2 -1
- package/src/platforms/desktop/components/__tests__/desktop-app-shell.test.tsx +50 -10
- package/src/platforms/desktop/components/desktop-app-shell.tsx +34 -10
- package/src/platforms/desktop/components/desktop-window-chrome.tsx +41 -16
- package/src/shared/components/ui/tab-strip/__tests__/compact-tab-strip.test.tsx +24 -1
- package/src/shared/components/ui/tab-strip/compact-tab-strip.tsx +8 -4
- package/src/shared/lib/i18n/locales/en-US/chat.json +20 -2
- package/src/shared/lib/i18n/locales/en-US/core.json +2 -0
- package/src/shared/lib/i18n/locales/zh-CN/chat.json +20 -2
- package/src/shared/lib/i18n/locales/zh-CN/core.json +2 -0
- package/src/shared/lib/ui-document-title/__tests__/ui-document-title.test.ts +49 -0
- package/src/shared/lib/ui-document-title/index.ts +50 -21
- package/dist/assets/channels-list-page-D6jtziu4.js +0 -8
- package/dist/assets/chat-page-BBnNJoKG.js +0 -105
- package/dist/assets/doc-browser-C8xOF_9F.js +0 -1
- package/dist/assets/doc-browser-DgQedeAn.js +0 -1
- package/dist/assets/doc-browser-context-B46tQGmO.js +0 -1
- package/dist/assets/index-7o1WdUbU.js +0 -103
- package/dist/assets/index-DQWmEWzk.css +0 -1
- package/dist/assets/mcp-marketplace-page-CWZN7ohK.js +0 -1
- package/dist/assets/mcp-marketplace-page-Dzull_4-.js +0 -40
- package/dist/assets/model-config-page-Cv0O3BIj.js +0 -1
- package/dist/assets/plus-Bnt56oqG.js +0 -1
- package/dist/assets/provider-scoped-model-input-Duuh7i3h.js +0 -1
- package/dist/assets/providers-config-page-CPDz0Lxc.js +0 -1
- package/dist/assets/remote-B0LMs8u7.js +0 -1
- package/dist/assets/rotate-cw-BfyG_KEF.js +0 -1
- package/dist/assets/runtime-config-page-q0fvv8ME.js +0 -1
- package/dist/assets/use-config-DZkBWIdL.js +0 -1
- package/dist/assets/x-CW2KO-Hz.js +0 -1
- package/src/features/chat/components/conversation/chat-conversation-alerts.tsx +0 -37
- package/src/features/chat/features/input/components/__tests__/chat-attachment-upload-limit.test.ts +0 -38
- package/src/features/chat/features/input/components/chat-input-bar.container.tsx +0 -496
- package/src/features/chat/features/message/utils/chat-message-inline-content.utils.ts +0 -95
- package/src/features/chat/managers/__tests__/chat-input.manager.test.ts +0 -448
- package/src/features/chat/managers/__tests__/chat-run-snapshot.manager.test.ts +0 -129
- package/src/features/chat/managers/__tests__/chat-run.manager.test.ts +0 -236
- package/src/features/chat/managers/__tests__/chat-session-preference-sync.manager.test.ts +0 -219
- package/src/features/chat/managers/chat-input.manager.ts +0 -430
- package/src/features/chat/managers/chat-run.manager.ts +0 -110
- package/src/features/chat/managers/chat-session-preference-sync.manager.ts +0 -142
- package/src/features/chat/stores/chat-input.store.ts +0 -104
- /package/dist/assets/{config-hints-CTqBnCDp.js → config-hints-BkYBc7z0.js} +0 -0
|
@@ -1,496 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo, useRef, useState, type ChangeEvent, type RefObject } from 'react';
|
|
2
|
-
import { ChatInputBar, type ChatInputBarHandle } from '@nextclaw/agent-chat-ui';
|
|
3
|
-
import { DEFAULT_NCP_ATTACHMENT_MAX_BYTES, uploadFilesAsNcpDraftAttachments } from '@nextclaw/ncp-react';
|
|
4
|
-
import { uploadNcpAssets } from '@/shared/lib/api';
|
|
5
|
-
import type { SessionSkillEntryView } from '@/shared/lib/api';
|
|
6
|
-
import { buildChatSlashItems, buildModelStateHint, buildModelToolbarSelect, buildSkillPickerModel, buildThinkingToolbarSelect, type ChatModelRecord, type ChatSkillRecord, type ChatThinkingLevel } from '@/features/chat/features/input/utils/chat-input-bar.utils';
|
|
7
|
-
import { usePresenter } from '@/features/chat/components/providers/chat-presenter.provider';
|
|
8
|
-
import { useI18n } from '@/app/components/i18n-provider';
|
|
9
|
-
import { useViewportLayout } from '@/app/hooks/use-viewport-layout';
|
|
10
|
-
import { useChatInputStore } from '@/features/chat/stores/chat-input.store';
|
|
11
|
-
import { chatRecentModelsManager, CHAT_RECENT_MODELS_MIN_OPTIONS } from '@/features/chat/managers/chat-recent-models.manager';
|
|
12
|
-
import { chatRecentSkillsManager, CHAT_RECENT_SKILLS_MIN_OPTIONS } from '@/features/chat/managers/chat-recent-skills.manager';
|
|
13
|
-
import { deriveSelectedSkillsFromComposer } from '@/features/chat/features/input/utils/chat-composer-state.utils';
|
|
14
|
-
import { hasNcpChatModelOptions, isNcpChatComposerDisabled, isNcpChatModelOptionsEmpty, isNcpChatModelOptionsLoading, isNcpChatSendDisabled } from '@/features/chat/features/input/utils/ncp-chat-input-availability.utils';
|
|
15
|
-
import { useChatInputBarQueryState } from '@/features/chat/features/input/hooks/use-chat-input-bar-query-state';
|
|
16
|
-
import { useChatModelFavorites } from '@/features/chat/features/input/hooks/use-chat-model-favorites';
|
|
17
|
-
import { useSelectedSessionContextWindowIndicator } from '@/features/chat/features/session/hooks/use-selected-session-context-window-indicator';
|
|
18
|
-
import { useSystemStatus } from '@/features/system-status';
|
|
19
|
-
import { isNcpChatRuntimeBlocked } from '@/features/chat/features/runtime/utils/ncp-chat-runtime-availability.utils';
|
|
20
|
-
import { t } from '@/shared/lib/i18n';
|
|
21
|
-
import { toast } from 'sonner';
|
|
22
|
-
|
|
23
|
-
type ChatInputStoreSnapshot = ReturnType<typeof useChatInputStore.getState>['snapshot'];
|
|
24
|
-
|
|
25
|
-
function buildThinkingLabels(): Record<ChatThinkingLevel, string> {
|
|
26
|
-
return {
|
|
27
|
-
off: t('chatThinkingLevelOff'),
|
|
28
|
-
minimal: t('chatThinkingLevelMinimal'),
|
|
29
|
-
low: t('chatThinkingLevelLow'),
|
|
30
|
-
medium: t('chatThinkingLevelMedium'),
|
|
31
|
-
high: t('chatThinkingLevelHigh'),
|
|
32
|
-
adaptive: t('chatThinkingLevelAdaptive'),
|
|
33
|
-
xhigh: t('chatThinkingLevelXhigh')
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function toSkillRecords(
|
|
37
|
-
snapshotRecords: SessionSkillEntryView[],
|
|
38
|
-
scopeLabels: Record<SessionSkillEntryView['scope'], string>
|
|
39
|
-
): ChatSkillRecord[] {
|
|
40
|
-
return snapshotRecords.map((record) => ({
|
|
41
|
-
key: record.ref,
|
|
42
|
-
label: record.name,
|
|
43
|
-
scopeLabel: scopeLabels[record.scope],
|
|
44
|
-
description: record.description,
|
|
45
|
-
descriptionZh: record.descriptionZh,
|
|
46
|
-
badgeLabel: scopeLabels[record.scope]
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
function toModelRecords(snapshotModels: Array<{
|
|
50
|
-
value: string;
|
|
51
|
-
modelLabel: string;
|
|
52
|
-
providerLabel: string;
|
|
53
|
-
thinkingCapability?: {
|
|
54
|
-
supported: string[];
|
|
55
|
-
default?: string | null;
|
|
56
|
-
} | null;
|
|
57
|
-
}>): ChatModelRecord[] {
|
|
58
|
-
return snapshotModels.map((model) => ({
|
|
59
|
-
value: model.value,
|
|
60
|
-
modelLabel: model.modelLabel,
|
|
61
|
-
providerLabel: model.providerLabel,
|
|
62
|
-
thinkingCapability: model.thinkingCapability
|
|
63
|
-
? {
|
|
64
|
-
supported: model.thinkingCapability.supported as ChatThinkingLevel[],
|
|
65
|
-
default: (model.thinkingCapability.default as ChatThinkingLevel | null | undefined) ?? null
|
|
66
|
-
}
|
|
67
|
-
: null
|
|
68
|
-
}));
|
|
69
|
-
}
|
|
70
|
-
function useChatInputBarLabels(language: string) {
|
|
71
|
-
const skillScopeLabels = useMemo<Record<'builtin' | 'project' | 'workspace', string>>(() => {
|
|
72
|
-
void language;
|
|
73
|
-
return {
|
|
74
|
-
builtin: t('chatSkillScopeBuiltin'),
|
|
75
|
-
project: t('chatSkillScopeProject'),
|
|
76
|
-
workspace: t('chatSkillScopeWorkspace')
|
|
77
|
-
};
|
|
78
|
-
}, [language]);
|
|
79
|
-
const slashTexts = useMemo(() => {
|
|
80
|
-
void language;
|
|
81
|
-
return {
|
|
82
|
-
slashSkillSubtitle: t('chatSlashTypeSkill'),
|
|
83
|
-
slashSkillSpecLabel: t('chatSlashSkillSpec'),
|
|
84
|
-
slashSkillScopeLabel: t('chatSlashSkillScope'),
|
|
85
|
-
noSkillDescription: t('chatSkillsPickerNoDescription')
|
|
86
|
-
};
|
|
87
|
-
}, [language]);
|
|
88
|
-
return {
|
|
89
|
-
skillScopeLabels,
|
|
90
|
-
slashTexts,
|
|
91
|
-
recentModelsLabel: t('chatPickerRecentModels'),
|
|
92
|
-
allModelsLabel: t('chatPickerAllModels'),
|
|
93
|
-
favoriteModelsLabel: t('chatPickerFavoriteModels'),
|
|
94
|
-
modelSearchPlaceholder: t('chatModelSearchPlaceholder'),
|
|
95
|
-
modelSearchEmptyLabel: t('chatModelSearchEmpty'),
|
|
96
|
-
favoriteModelLabel: t('chatFavoriteModel'),
|
|
97
|
-
unfavoriteModelLabel: t('chatUnfavoriteModel'),
|
|
98
|
-
recentSkillsLabel: t('chatPickerRecent'),
|
|
99
|
-
allSkillsLabel: t('chatPickerAllSkills')
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
function useChatInputBarCollections(params: {
|
|
103
|
-
modelOptions: ChatInputStoreSnapshot['modelOptions'];
|
|
104
|
-
skillRecords: SessionSkillEntryView[];
|
|
105
|
-
skillScopeLabels: Record<'builtin' | 'project' | 'workspace', string>;
|
|
106
|
-
}) {
|
|
107
|
-
const skillRecords = useMemo(
|
|
108
|
-
() => toSkillRecords(params.skillRecords, params.skillScopeLabels),
|
|
109
|
-
[params.skillRecords, params.skillScopeLabels]
|
|
110
|
-
);
|
|
111
|
-
const modelRecords = useMemo(() => toModelRecords(params.modelOptions), [params.modelOptions]);
|
|
112
|
-
return {
|
|
113
|
-
skillRecords,
|
|
114
|
-
modelRecords,
|
|
115
|
-
recentModelValues: chatRecentModelsManager.resolveVisible({
|
|
116
|
-
availableValues: modelRecords.map((option) => option.value),
|
|
117
|
-
minAvailableCount: CHAT_RECENT_MODELS_MIN_OPTIONS
|
|
118
|
-
}),
|
|
119
|
-
recentSkillValues: chatRecentSkillsManager.resolveVisible({
|
|
120
|
-
availableValues: skillRecords.map((record) => record.key),
|
|
121
|
-
minAvailableCount: 0
|
|
122
|
-
}),
|
|
123
|
-
recentSkillGroupValues: chatRecentSkillsManager.resolveVisible({
|
|
124
|
-
availableValues: skillRecords.map((record) => record.key),
|
|
125
|
-
minAvailableCount: CHAT_RECENT_SKILLS_MIN_OPTIONS
|
|
126
|
-
})
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
function useChatInputBarAttachments(params: { attachmentSupported: boolean; inputBarRef: RefObject<ChatInputBarHandle | null>; }) {
|
|
130
|
-
const { attachmentSupported, inputBarRef } = params;
|
|
131
|
-
const presenter = usePresenter();
|
|
132
|
-
const showAttachmentError = useCallback((reason: 'unsupported-type' | 'too-large' | 'read-failed') => {
|
|
133
|
-
if (reason === 'unsupported-type') {
|
|
134
|
-
toast.error(t('chatInputAttachmentUnsupported'));
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if (reason === 'too-large') {
|
|
138
|
-
toast.error(
|
|
139
|
-
t('chatInputAttachmentTooLarge').replace('{maxMb}', String(DEFAULT_NCP_ATTACHMENT_MAX_BYTES / (1024 * 1024)))
|
|
140
|
-
);
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
toast.error(t('chatInputAttachmentReadFailed'));
|
|
144
|
-
}, []);
|
|
145
|
-
const handleFilesAdd = useCallback(async (files: File[]) => {
|
|
146
|
-
if (!attachmentSupported || files.length === 0) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const result = await uploadFilesAsNcpDraftAttachments(files, { uploadBatch: uploadNcpAssets });
|
|
150
|
-
if (result.attachments.length > 0) {
|
|
151
|
-
const insertedAttachments = presenter.chatInputManager.addAttachments?.(result.attachments) ?? [];
|
|
152
|
-
if (insertedAttachments.length > 0) {
|
|
153
|
-
inputBarRef.current?.insertFileTokens(
|
|
154
|
-
insertedAttachments.map((attachment) => ({ tokenKey: attachment.id, label: attachment.name }))
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (result.rejected.length > 0) {
|
|
159
|
-
showAttachmentError(result.rejected[0].reason);
|
|
160
|
-
}
|
|
161
|
-
}, [attachmentSupported, inputBarRef, presenter.chatInputManager, showAttachmentError]);
|
|
162
|
-
return {
|
|
163
|
-
handleFilesAdd,
|
|
164
|
-
handleFileInputChange: useCallback(async (event: ChangeEvent<HTMLInputElement>) => {
|
|
165
|
-
const files = Array.from(event.target.files ?? []);
|
|
166
|
-
event.currentTarget.value = '';
|
|
167
|
-
await handleFilesAdd(files);
|
|
168
|
-
}, [handleFilesAdd])
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
type ToolbarSelectBuildParams = {
|
|
173
|
-
allModelsLabel: string;
|
|
174
|
-
favoriteModelLabel: string;
|
|
175
|
-
favoriteModelValues: string[];
|
|
176
|
-
favoriteModelsLabel: string;
|
|
177
|
-
hasModelOptions: boolean;
|
|
178
|
-
isModelOptionsLoading: boolean;
|
|
179
|
-
modelRecords: ChatModelRecord[];
|
|
180
|
-
modelSearchEmptyLabel: string;
|
|
181
|
-
modelSearchPlaceholder: string;
|
|
182
|
-
onFavoriteModelToggle: (value: string, favorite: boolean) => void;
|
|
183
|
-
onModelChange: (value: string) => void;
|
|
184
|
-
onThinkingChange: (value: ChatThinkingLevel | null) => void;
|
|
185
|
-
recentModelValues: string[];
|
|
186
|
-
recentModelsLabel: string;
|
|
187
|
-
selectedModel: string;
|
|
188
|
-
selectedThinkingLevel: ChatThinkingLevel | null;
|
|
189
|
-
thinkingDefaultLevel: ChatThinkingLevel | null;
|
|
190
|
-
thinkingSupportedLevels: ChatThinkingLevel[];
|
|
191
|
-
unfavoriteModelLabel: string;
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
function buildToolbarSelects(params: ToolbarSelectBuildParams) {
|
|
195
|
-
const {
|
|
196
|
-
allModelsLabel,
|
|
197
|
-
favoriteModelLabel,
|
|
198
|
-
favoriteModelValues,
|
|
199
|
-
favoriteModelsLabel,
|
|
200
|
-
hasModelOptions,
|
|
201
|
-
isModelOptionsLoading,
|
|
202
|
-
modelRecords,
|
|
203
|
-
modelSearchEmptyLabel,
|
|
204
|
-
modelSearchPlaceholder,
|
|
205
|
-
onFavoriteModelToggle,
|
|
206
|
-
onModelChange,
|
|
207
|
-
onThinkingChange,
|
|
208
|
-
recentModelValues,
|
|
209
|
-
recentModelsLabel,
|
|
210
|
-
selectedModel,
|
|
211
|
-
selectedThinkingLevel,
|
|
212
|
-
thinkingDefaultLevel,
|
|
213
|
-
thinkingSupportedLevels,
|
|
214
|
-
unfavoriteModelLabel
|
|
215
|
-
} = params;
|
|
216
|
-
return [
|
|
217
|
-
buildModelToolbarSelect({
|
|
218
|
-
modelOptions: modelRecords,
|
|
219
|
-
favoriteModelValues,
|
|
220
|
-
recentModelValues,
|
|
221
|
-
selectedModel,
|
|
222
|
-
isModelOptionsLoading,
|
|
223
|
-
hasModelOptions,
|
|
224
|
-
onFavoriteToggle: onFavoriteModelToggle,
|
|
225
|
-
onValueChange: onModelChange,
|
|
226
|
-
texts: {
|
|
227
|
-
modelSelectPlaceholder: t('chatSelectModel'),
|
|
228
|
-
modelNoOptionsLabel: t('chatModelNoOptions'),
|
|
229
|
-
modelSearchPlaceholder,
|
|
230
|
-
modelSearchEmptyLabel,
|
|
231
|
-
favoriteModelsLabel,
|
|
232
|
-
favoriteModelLabel,
|
|
233
|
-
unfavoriteModelLabel,
|
|
234
|
-
recentModelsLabel,
|
|
235
|
-
allModelsLabel
|
|
236
|
-
}
|
|
237
|
-
}),
|
|
238
|
-
buildThinkingToolbarSelect({
|
|
239
|
-
supportedLevels: thinkingSupportedLevels,
|
|
240
|
-
selectedThinkingLevel,
|
|
241
|
-
defaultThinkingLevel: thinkingDefaultLevel,
|
|
242
|
-
onValueChange: onThinkingChange,
|
|
243
|
-
texts: {
|
|
244
|
-
thinkingLabels: buildThinkingLabels()
|
|
245
|
-
}
|
|
246
|
-
})
|
|
247
|
-
].filter((item): item is NonNullable<typeof item> => item !== null);
|
|
248
|
-
}
|
|
249
|
-
function buildSkillPicker(params: { allSkillsLabel: string; isSkillsLoading: boolean; onSelectedKeysChange: (keys: string[]) => void; recentSkillGroupValues: string[]; recentSkillValues: string[]; recentSkillsLabel: string; skillRecords: ChatSkillRecord[]; snapshot: ChatInputStoreSnapshot; }) {
|
|
250
|
-
const { allSkillsLabel, isSkillsLoading, onSelectedKeysChange, recentSkillGroupValues, recentSkillValues, recentSkillsLabel, skillRecords, snapshot } = params;
|
|
251
|
-
return buildSkillPickerModel({
|
|
252
|
-
skillRecords,
|
|
253
|
-
recentSkillValues,
|
|
254
|
-
groupedRecentSkillValues: recentSkillGroupValues,
|
|
255
|
-
selectedSkills: snapshot.selectedSkills,
|
|
256
|
-
isLoading: isSkillsLoading,
|
|
257
|
-
onSelectedKeysChange,
|
|
258
|
-
texts: {
|
|
259
|
-
title: t('chatSkillsPickerTitle'),
|
|
260
|
-
searchPlaceholder: t('chatSkillsPickerSearchPlaceholder'),
|
|
261
|
-
emptyLabel: t('chatSkillsPickerEmpty'),
|
|
262
|
-
loadingLabel: t('sessionsLoading'),
|
|
263
|
-
manageLabel: t('chatSkillsPickerManage'),
|
|
264
|
-
recentSkillsLabel,
|
|
265
|
-
allSkillsLabel
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
type ChatInputBarContainerProps = {
|
|
271
|
-
surface?: 'default' | 'embedded';
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
export function ChatInputBarContainer({ surface = 'default' }: ChatInputBarContainerProps) {
|
|
275
|
-
const presenter = usePresenter();
|
|
276
|
-
const { language } = useI18n();
|
|
277
|
-
const { isMobile } = useViewportLayout();
|
|
278
|
-
const snapshot = useChatInputStore((state) => state.snapshot);
|
|
279
|
-
const inputQueryState = useChatInputBarQueryState(snapshot);
|
|
280
|
-
const isRuntimeBlocked = isNcpChatRuntimeBlocked(useSystemStatus());
|
|
281
|
-
const [slashQuery, setSlashQuery] = useState<string | null>(null);
|
|
282
|
-
const inputBarRef = useRef<ChatInputBarHandle | null>(null);
|
|
283
|
-
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
|
284
|
-
const labels = useChatInputBarLabels(language);
|
|
285
|
-
const { skillRecords, modelRecords, recentModelValues, recentSkillValues, recentSkillGroupValues } = useChatInputBarCollections({
|
|
286
|
-
modelOptions: inputQueryState.modelOptions,
|
|
287
|
-
skillRecords: inputQueryState.skillRecords,
|
|
288
|
-
skillScopeLabels: labels.skillScopeLabels
|
|
289
|
-
});
|
|
290
|
-
const modelRecordValues = useMemo(
|
|
291
|
-
() => modelRecords.map((option) => option.value),
|
|
292
|
-
[modelRecords]
|
|
293
|
-
);
|
|
294
|
-
const {
|
|
295
|
-
favoriteModelValues,
|
|
296
|
-
setModelFavorite,
|
|
297
|
-
} = useChatModelFavorites(modelRecordValues);
|
|
298
|
-
const availabilitySnapshot = {
|
|
299
|
-
...snapshot,
|
|
300
|
-
isProviderStateResolved: inputQueryState.isProviderStateResolved,
|
|
301
|
-
modelOptions: inputQueryState.modelOptions
|
|
302
|
-
};
|
|
303
|
-
const hasModelOptions = hasNcpChatModelOptions(availabilitySnapshot);
|
|
304
|
-
const isModelOptionsLoading = isNcpChatModelOptionsLoading(availabilitySnapshot);
|
|
305
|
-
const isModelOptionsEmpty = isNcpChatModelOptionsEmpty(availabilitySnapshot);
|
|
306
|
-
const inputDisabled = isNcpChatComposerDisabled(availabilitySnapshot);
|
|
307
|
-
const attachmentSupported = typeof presenter.chatInputManager.addAttachments === 'function';
|
|
308
|
-
const textareaPlaceholder = isModelOptionsEmpty
|
|
309
|
-
? t('chatModelNoOptions')
|
|
310
|
-
: t(isMobile ? 'chatInputPlaceholderCompact' : 'chatInputPlaceholder');
|
|
311
|
-
const slashItems = useMemo(
|
|
312
|
-
() => buildChatSlashItems(skillRecords, slashQuery ?? '', labels.slashTexts, recentSkillValues),
|
|
313
|
-
[labels.slashTexts, recentSkillValues, skillRecords, slashQuery]
|
|
314
|
-
);
|
|
315
|
-
const contextWindowIndicator = useSelectedSessionContextWindowIndicator();
|
|
316
|
-
const selectedModelOption = modelRecords.find((option) => option.value === snapshot.selectedModel);
|
|
317
|
-
const thinkingSupportedLevels = selectedModelOption?.thinkingCapability?.supported ?? [];
|
|
318
|
-
const resolvedStopHint = snapshot.stopDisabledReason === '__preparing__'
|
|
319
|
-
? t('chatStopPreparing')
|
|
320
|
-
: snapshot.stopDisabledReason?.trim() || t('chatStopUnavailable');
|
|
321
|
-
const { handleFilesAdd, handleFileInputChange } = useChatInputBarAttachments({ attachmentSupported, inputBarRef });
|
|
322
|
-
useEffect(() => {
|
|
323
|
-
presenter.chatInputManager.syncSnapshot({
|
|
324
|
-
isProviderStateResolved: inputQueryState.isProviderStateResolved,
|
|
325
|
-
modelOptions: inputQueryState.modelOptions,
|
|
326
|
-
skillRecords: inputQueryState.skillRecords,
|
|
327
|
-
defaultSessionType: inputQueryState.sessionTypeState.defaultSessionType,
|
|
328
|
-
defaultProjectRoot: inputQueryState.defaultProjectRoot,
|
|
329
|
-
sessionTypeOptions: inputQueryState.sessionTypeState.sessionTypeOptions,
|
|
330
|
-
selectedSessionType: inputQueryState.sessionTypeState.selectedSessionType,
|
|
331
|
-
canEditSessionType: inputQueryState.sessionTypeState.canEditSessionType,
|
|
332
|
-
sessionTypeUnavailable: inputQueryState.sessionTypeState.sessionTypeUnavailable,
|
|
333
|
-
sessionTypeUnavailableMessage: inputQueryState.sessionTypeState.sessionTypeUnavailableMessage,
|
|
334
|
-
});
|
|
335
|
-
presenter.chatInputManager.syncSessionPreferences({
|
|
336
|
-
selectedSessionKey: inputQueryState.selectedSessionKey,
|
|
337
|
-
selectedSessionExists: Boolean(inputQueryState.selectedSession),
|
|
338
|
-
selectedSessionPreferredModel: inputQueryState.selectedSession?.preferredModel,
|
|
339
|
-
selectedSessionPreferredThinking: inputQueryState.selectedSession?.preferredThinking ?? null,
|
|
340
|
-
fallbackPreferredModel: inputQueryState.fallbackPreferredModel,
|
|
341
|
-
fallbackPreferredThinking: inputQueryState.fallbackPreferredThinking,
|
|
342
|
-
defaultModel: inputQueryState.defaultModel,
|
|
343
|
-
});
|
|
344
|
-
}, [
|
|
345
|
-
inputQueryState.defaultModel,
|
|
346
|
-
inputQueryState.defaultProjectRoot,
|
|
347
|
-
inputQueryState.fallbackPreferredModel,
|
|
348
|
-
inputQueryState.fallbackPreferredThinking,
|
|
349
|
-
inputQueryState.isProviderStateResolved,
|
|
350
|
-
inputQueryState.modelOptions,
|
|
351
|
-
inputQueryState.selectedSession,
|
|
352
|
-
inputQueryState.selectedSessionKey,
|
|
353
|
-
inputQueryState.sessionTypeState.canEditSessionType,
|
|
354
|
-
inputQueryState.sessionTypeState.defaultSessionType,
|
|
355
|
-
inputQueryState.sessionTypeState.selectedSessionType,
|
|
356
|
-
inputQueryState.sessionTypeState.sessionTypeOptions,
|
|
357
|
-
inputQueryState.sessionTypeState.sessionTypeUnavailable,
|
|
358
|
-
inputQueryState.sessionTypeState.sessionTypeUnavailableMessage,
|
|
359
|
-
inputQueryState.skillRecords,
|
|
360
|
-
presenter.chatInputManager,
|
|
361
|
-
]);
|
|
362
|
-
useEffect(() => {
|
|
363
|
-
const request = snapshot.composerFocusRequest;
|
|
364
|
-
if (!request) {
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
if (request.placement === 'end') {
|
|
368
|
-
inputBarRef.current?.focusComposerAtEnd(snapshot.composerNodes);
|
|
369
|
-
}
|
|
370
|
-
presenter.chatInputManager.consumeComposerFocusRequest(request.id);
|
|
371
|
-
}, [presenter.chatInputManager, snapshot.composerFocusRequest, snapshot.composerNodes]);
|
|
372
|
-
const toolbarSelects = buildToolbarSelects({
|
|
373
|
-
allModelsLabel: labels.allModelsLabel,
|
|
374
|
-
favoriteModelLabel: labels.favoriteModelLabel,
|
|
375
|
-
favoriteModelValues,
|
|
376
|
-
favoriteModelsLabel: labels.favoriteModelsLabel,
|
|
377
|
-
hasModelOptions,
|
|
378
|
-
isModelOptionsLoading,
|
|
379
|
-
modelRecords,
|
|
380
|
-
modelSearchEmptyLabel: labels.modelSearchEmptyLabel,
|
|
381
|
-
modelSearchPlaceholder: labels.modelSearchPlaceholder,
|
|
382
|
-
onFavoriteModelToggle: setModelFavorite,
|
|
383
|
-
onModelChange: presenter.chatInputManager.selectModel,
|
|
384
|
-
onThinkingChange: (value) => {
|
|
385
|
-
if (value) {
|
|
386
|
-
presenter.chatInputManager.selectThinkingLevel(value);
|
|
387
|
-
}
|
|
388
|
-
},
|
|
389
|
-
recentModelValues,
|
|
390
|
-
recentModelsLabel: labels.recentModelsLabel,
|
|
391
|
-
selectedModel: snapshot.selectedModel,
|
|
392
|
-
selectedThinkingLevel: snapshot.selectedThinkingLevel as ChatThinkingLevel | null,
|
|
393
|
-
thinkingSupportedLevels,
|
|
394
|
-
thinkingDefaultLevel: selectedModelOption?.thinkingCapability?.default ?? null,
|
|
395
|
-
unfavoriteModelLabel: labels.unfavoriteModelLabel
|
|
396
|
-
});
|
|
397
|
-
const skillPicker = buildSkillPicker({
|
|
398
|
-
allSkillsLabel: labels.allSkillsLabel,
|
|
399
|
-
onSelectedKeysChange: presenter.chatInputManager.selectSkills,
|
|
400
|
-
recentSkillGroupValues,
|
|
401
|
-
recentSkillValues,
|
|
402
|
-
recentSkillsLabel: labels.recentSkillsLabel,
|
|
403
|
-
isSkillsLoading: inputQueryState.isSkillsLoading,
|
|
404
|
-
skillRecords,
|
|
405
|
-
snapshot
|
|
406
|
-
});
|
|
407
|
-
const hasSendableDraft = snapshot.draft.trim().length > 0 || snapshot.attachments.length > 0 || deriveSelectedSkillsFromComposer(snapshot.composerNodes).length > 0;
|
|
408
|
-
|
|
409
|
-
return (
|
|
410
|
-
<>
|
|
411
|
-
<ChatInputBar
|
|
412
|
-
ref={inputBarRef}
|
|
413
|
-
surface={surface}
|
|
414
|
-
composer={{
|
|
415
|
-
nodes: snapshot.composerNodes,
|
|
416
|
-
placeholder: textareaPlaceholder,
|
|
417
|
-
disabled: inputDisabled,
|
|
418
|
-
onNodesChange: presenter.chatInputManager.setComposerNodes,
|
|
419
|
-
...(attachmentSupported ? { onFilesAdd: handleFilesAdd } : {}),
|
|
420
|
-
onSlashQueryChange: setSlashQuery
|
|
421
|
-
}}
|
|
422
|
-
slashMenu={{
|
|
423
|
-
isLoading: inputQueryState.isSkillsLoading,
|
|
424
|
-
items: slashItems,
|
|
425
|
-
onSelectItem: (item: { value?: string }) => {
|
|
426
|
-
if (item.value) {
|
|
427
|
-
presenter.chatInputManager.rememberSkillSelection(item.value);
|
|
428
|
-
}
|
|
429
|
-
},
|
|
430
|
-
texts: {
|
|
431
|
-
slashLoadingLabel: t('chatSlashLoading'),
|
|
432
|
-
slashSectionLabel: t('chatSlashSectionSkills'),
|
|
433
|
-
slashEmptyLabel: t('chatSlashNoResult'),
|
|
434
|
-
slashHintLabel: t('chatSlashHint'),
|
|
435
|
-
slashSkillHintLabel: t('chatSlashSkillHint')
|
|
436
|
-
}
|
|
437
|
-
}}
|
|
438
|
-
hint={buildModelStateHint({
|
|
439
|
-
isModelOptionsLoading,
|
|
440
|
-
isModelOptionsEmpty,
|
|
441
|
-
onGoToProviders: presenter.chatUiManager.goToProviders,
|
|
442
|
-
texts: {
|
|
443
|
-
noModelOptionsLabel: t('chatModelNoOptions'),
|
|
444
|
-
configureProviderLabel: t('chatGoConfigureProvider')
|
|
445
|
-
}
|
|
446
|
-
})}
|
|
447
|
-
toolbar={{
|
|
448
|
-
selects: toolbarSelects,
|
|
449
|
-
accessories: [
|
|
450
|
-
{
|
|
451
|
-
key: 'attach',
|
|
452
|
-
label: t('chatInputAttach'),
|
|
453
|
-
icon: 'paperclip' as const,
|
|
454
|
-
iconOnly: true,
|
|
455
|
-
disabled: !attachmentSupported || inputDisabled || snapshot.isSending,
|
|
456
|
-
...(attachmentSupported
|
|
457
|
-
? {
|
|
458
|
-
onClick: () => fileInputRef.current?.click()
|
|
459
|
-
}
|
|
460
|
-
: {
|
|
461
|
-
tooltip: t('chatInputAttachComingSoon')
|
|
462
|
-
})
|
|
463
|
-
}
|
|
464
|
-
],
|
|
465
|
-
skillPicker,
|
|
466
|
-
actions: {
|
|
467
|
-
sendError: isRuntimeBlocked ? null : snapshot.sendError,
|
|
468
|
-
isSending: snapshot.isSending,
|
|
469
|
-
canStopGeneration: snapshot.canStopGeneration,
|
|
470
|
-
sendDisabled: isNcpChatSendDisabled({
|
|
471
|
-
snapshot: availabilitySnapshot,
|
|
472
|
-
hasSendableDraft,
|
|
473
|
-
isRuntimeBlocked
|
|
474
|
-
}),
|
|
475
|
-
stopDisabled: !snapshot.canStopGeneration,
|
|
476
|
-
stopHint: resolvedStopHint,
|
|
477
|
-
sendButtonLabel: t('chatSend'),
|
|
478
|
-
stopButtonLabel: t('chatStop'),
|
|
479
|
-
contextWindow: contextWindowIndicator,
|
|
480
|
-
onSend: presenter.chatInputManager.send,
|
|
481
|
-
onStop: presenter.chatInputManager.stop
|
|
482
|
-
}
|
|
483
|
-
}}
|
|
484
|
-
/>
|
|
485
|
-
{attachmentSupported ? (
|
|
486
|
-
<input
|
|
487
|
-
ref={fileInputRef}
|
|
488
|
-
type="file"
|
|
489
|
-
multiple
|
|
490
|
-
className="hidden"
|
|
491
|
-
onChange={handleFileInputChange}
|
|
492
|
-
/>
|
|
493
|
-
) : null}
|
|
494
|
-
</>
|
|
495
|
-
);
|
|
496
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
splitTextByInlineTokens,
|
|
3
|
-
type ChatInlineTokenSource,
|
|
4
|
-
} from "@/features/chat/features/input/utils/chat-inline-token.utils";
|
|
5
|
-
import type {
|
|
6
|
-
ChatInlineContentSegmentViewModel,
|
|
7
|
-
ChatMessagePartViewModel,
|
|
8
|
-
} from "@nextclaw/agent-chat-ui";
|
|
9
|
-
import type { ChatMessagePartSource } from "./chat-message-part.utils";
|
|
10
|
-
|
|
11
|
-
const INVISIBLE_ONLY_TEXT_PATTERN = /\u200B|\u200C|\u200D|\u2060|\uFEFF/g;
|
|
12
|
-
|
|
13
|
-
function toRenderableText(value: string): string | null {
|
|
14
|
-
const trimmed = value.trim();
|
|
15
|
-
if (!trimmed) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
const visible = trimmed.replace(INVISIBLE_ONLY_TEXT_PATTERN, "").trim();
|
|
19
|
-
return visible ? trimmed : null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function hasVisibleText(value: string): boolean {
|
|
23
|
-
return value.replace(INVISIBLE_ONLY_TEXT_PATTERN, "").trim().length > 0;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function buildInlineContentSegments(
|
|
27
|
-
text: string,
|
|
28
|
-
inlineTokens: readonly ChatInlineTokenSource[],
|
|
29
|
-
): ChatInlineContentSegmentViewModel[] | null {
|
|
30
|
-
const fragments = splitTextByInlineTokens(text, inlineTokens);
|
|
31
|
-
if (fragments.length === 0) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const segments: ChatInlineContentSegmentViewModel[] = [];
|
|
36
|
-
let hasVisibleContent = false;
|
|
37
|
-
|
|
38
|
-
for (const fragment of fragments) {
|
|
39
|
-
if (fragment.type === "token") {
|
|
40
|
-
hasVisibleContent = true;
|
|
41
|
-
segments.push({
|
|
42
|
-
type: "token",
|
|
43
|
-
token: {
|
|
44
|
-
kind: fragment.token.kind,
|
|
45
|
-
key: fragment.token.key,
|
|
46
|
-
label: fragment.token.label,
|
|
47
|
-
rawText: fragment.token.rawText,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (fragment.text.length === 0) {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
if (hasVisibleText(fragment.text)) {
|
|
57
|
-
hasVisibleContent = true;
|
|
58
|
-
}
|
|
59
|
-
segments.push({
|
|
60
|
-
type: "markdown",
|
|
61
|
-
text: fragment.text,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return hasVisibleContent ? segments : null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function buildTextPart(
|
|
69
|
-
part: Extract<ChatMessagePartSource, { type: "text" }>,
|
|
70
|
-
inlineTokens: readonly ChatInlineTokenSource[],
|
|
71
|
-
): Extract<
|
|
72
|
-
ChatMessagePartViewModel,
|
|
73
|
-
{ type: "markdown" | "inline-content" }
|
|
74
|
-
> | null {
|
|
75
|
-
const inlineContent = buildInlineContentSegments(part.text, inlineTokens);
|
|
76
|
-
if (inlineContent && inlineContent.some((segment) => segment.type === "token")) {
|
|
77
|
-
return {
|
|
78
|
-
type: "inline-content",
|
|
79
|
-
segments: inlineContent,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const text = toRenderableText(part.text);
|
|
84
|
-
if (!text) {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
type: "markdown",
|
|
89
|
-
text,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function buildRenderableText(value: string): string | null {
|
|
94
|
-
return toRenderableText(value);
|
|
95
|
-
}
|