nolo-cli 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/agentRuntimeCommands.ts +3 -3
- package/ai/agent/_executeModel.ts +118 -0
- package/ai/agent/agentSlice.ts +525 -0
- package/ai/agent/appWorkingMemory.ts +126 -0
- package/ai/agent/avatarUtils.ts +24 -0
- package/ai/agent/buildEditingContext.ts +373 -0
- package/ai/agent/buildSystemPrompt.ts +532 -0
- package/ai/agent/cleanAgentMessages.ts +140 -0
- package/ai/agent/cliChatClient.ts +119 -0
- package/ai/agent/cliExecutor.ts +733 -0
- package/ai/agent/cliPrompt.ts +10 -0
- package/ai/agent/contextCompiler.ts +107 -0
- package/ai/agent/contextLayerContract.ts +44 -0
- package/ai/agent/createAgentSchema.ts +234 -0
- package/ai/agent/executeToolCall.ts +58 -0
- package/ai/agent/fetchAgentContexts.ts +42 -0
- package/ai/agent/generatePrompt.ts +3 -0
- package/ai/agent/getFullChatContextKeys.ts +168 -0
- package/ai/agent/hooks/fetchPublicAgents.ts +133 -0
- package/ai/agent/hooks/useAgentConfig.ts +61 -0
- package/ai/agent/hooks/useAgentDialog.ts +35 -0
- package/ai/agent/hooks/useAgentFormValidation.ts +202 -0
- package/ai/agent/hooks/usePublicAgents.ts +473 -0
- package/ai/agent/machineRunPermissions.ts +95 -0
- package/ai/agent/persistMessageWithFixedId.ts +37 -0
- package/ai/agent/planSlice.ts +259 -0
- package/ai/agent/referenceUtils.ts +229 -0
- package/ai/agent/runAgentBackground.ts +238 -0
- package/ai/agent/runAgentClientLoop.ts +138 -0
- package/ai/agent/runtimeGuidance.ts +97 -0
- package/ai/agent/runtimeServerBase.ts +37 -0
- package/ai/agent/server/fetchPublicAgents.ts +128 -0
- package/ai/agent/startParallelAgentStreams.ts +424 -0
- package/ai/agent/startupProtocol.ts +53 -0
- package/ai/agent/streamAgentChatTurn.ts +1278 -0
- package/ai/agent/streamAgentChatTurnUtils.ts +738 -0
- package/ai/agent/types.ts +71 -0
- package/ai/agent/utils/imageOutput.ts +33 -0
- package/ai/agent/utils/sortUtils.ts +250 -0
- package/ai/agent/web/referencePickerUtils.ts +146 -0
- package/ai/ai.locale.ts +1079 -0
- package/ai/chat/accumulateToolCallChunks.ts +95 -0
- package/ai/chat/fetchUtils.native.ts +276 -0
- package/ai/chat/fetchUtils.ts +153 -0
- package/ai/chat/parseApiError.ts +64 -0
- package/ai/chat/parseMultilineSSE.ts +95 -0
- package/ai/chat/sendOpenAICompletionsRequest.native.ts +682 -0
- package/ai/chat/sendOpenAICompletionsRequest.ts +703 -0
- package/ai/chat/sendOpenAIResponseRequest.ts +491 -0
- package/ai/chat/shouldUseServerProxy.ts +18 -0
- package/ai/chat/sseClient.native.ts +91 -0
- package/ai/chat/sseClient.ts +67 -0
- package/ai/chat/streamReader.native.ts +31 -0
- package/ai/chat/streamReader.ts +62 -0
- package/ai/chat/updateTotalUsage.ts +72 -0
- package/ai/context/buildReferenceContext.ts +437 -0
- package/ai/context/calculateContextUsage.ts +133 -0
- package/ai/context/retention.ts +165 -0
- package/ai/context/tokenUtils.ts +78 -0
- package/ai/index.ts +1 -0
- package/ai/llm/calculateGeminiImageTokens.ts +57 -0
- package/ai/llm/deepinfra.ts +28 -0
- package/ai/llm/fireworks.ts +50 -0
- package/ai/llm/generateRequestBody.ts +165 -0
- package/ai/llm/getModelContextWindow.ts +84 -0
- package/ai/llm/getNoloKey.ts +31 -0
- package/ai/llm/getPricing.ts +199 -0
- package/ai/llm/hooks/useModelPricing.ts +75 -0
- package/ai/llm/imagePricing.ts +40 -0
- package/ai/llm/isResponseAPIModel.ts +13 -0
- package/ai/llm/mimo.ts +71 -0
- package/ai/llm/mistral.ts +22 -0
- package/ai/llm/modelAvatar.ts +427 -0
- package/ai/llm/models.ts +45 -0
- package/ai/llm/openrouterModels.ts +269 -0
- package/ai/llm/providers.ts +306 -0
- package/ai/llm/reasoningModels.ts +28 -0
- package/ai/llm/types.ts +59 -0
- package/ai/llm/usageRequestOptions.ts +59 -0
- package/ai/memory/capture.ts +148 -0
- package/ai/memory/consolidate.ts +104 -0
- package/ai/memory/delete.ts +147 -0
- package/ai/memory/overlay.ts +84 -0
- package/ai/memory/query.ts +38 -0
- package/ai/memory/queryShared.ts +160 -0
- package/ai/memory/rank.ts +105 -0
- package/ai/memory/recentRelationshipRecap.ts +249 -0
- package/ai/memory/remember.ts +167 -0
- package/ai/memory/runtime.ts +76 -0
- package/ai/memory/store.ts +20 -0
- package/ai/memory/storeShared.ts +76 -0
- package/ai/memory/types.ts +46 -0
- package/ai/memory/understanding.ts +349 -0
- package/ai/memory/understandingGreeting.ts +264 -0
- package/ai/messages/type.ts +20 -0
- package/ai/policy/personalizationDialog.ts +333 -0
- package/ai/policy/runtimePolicy.ts +440 -0
- package/ai/policy/selfUpdateFields.ts +48 -0
- package/ai/policy/types.ts +64 -0
- package/ai/skills/referenceRuntime.ts +274 -0
- package/ai/skills/skillDiagnostics.ts +251 -0
- package/ai/skills/skillDocBuilder.ts +139 -0
- package/ai/skills/skillDocProtocol.ts +434 -0
- package/ai/skills/skillReferenceSummary.ts +63 -0
- package/ai/skills/skillSummaryMarker.ts +26 -0
- package/ai/token/calculatePrice.ts +544 -0
- package/ai/token/db.ts +98 -0
- package/ai/token/externalToolCost.ts +330 -0
- package/ai/token/hooks/useRecords.ts +65 -0
- package/ai/token/missingUsageEstimate.ts +42 -0
- package/ai/token/modelUsageQuery.ts +252 -0
- package/ai/token/normalizeUsage.ts +84 -0
- package/ai/token/openaiImageGenerationUsage.ts +56 -0
- package/ai/token/prepareTokenUsageData.ts +88 -0
- package/ai/token/query.ts +88 -0
- package/ai/token/queryUserTokens.ts +59 -0
- package/ai/token/resolveBillingTarget.ts +52 -0
- package/ai/token/saveTokenRecord.ts +53 -0
- package/ai/token/serverDialogProjection.ts +78 -0
- package/ai/token/serverTokenWriter.ts +143 -0
- package/ai/token/stats.ts +21 -0
- package/ai/token/tokenThunks.ts +24 -0
- package/ai/token/types.ts +93 -0
- package/ai/tools/agent/agentTools.ts +176 -0
- package/ai/tools/agent/agentUpdateShared.ts +311 -0
- package/ai/tools/agent/callAgentTool.ts +139 -0
- package/ai/tools/agent/createAgentTool.ts +512 -0
- package/ai/tools/agent/createDialogTool.ts +69 -0
- package/ai/tools/agent/createSkillAgentTool.ts +62 -0
- package/ai/tools/agent/parallelBudget.ts +221 -0
- package/ai/tools/agent/presets/appBuilderPreset.ts +145 -0
- package/ai/tools/agent/runLlmTool.ts +96 -0
- package/ai/tools/agent/runStreamingAgentTool.ts +73 -0
- package/ai/tools/agent/skillAgentArgs.ts +106 -0
- package/ai/tools/agent/skillAgentPreset.ts +89 -0
- package/ai/tools/agent/streamParallelAgentsTool.ts +122 -0
- package/ai/tools/agent/updateAgentTool.ts +96 -0
- package/ai/tools/agent/updateSelfTool.ts +113 -0
- package/ai/tools/amazonProductScraperTool.ts +86 -0
- package/ai/tools/apifyActorClient.ts +45 -0
- package/ai/tools/appEditGuard.ts +372 -0
- package/ai/tools/appReadSnapshot.ts +153 -0
- package/ai/tools/appTools.ts +1549 -0
- package/ai/tools/applyEditTool.ts +256 -0
- package/ai/tools/applyLineEditsTool.ts +312 -0
- package/ai/tools/browserTools/click.ts +33 -0
- package/ai/tools/browserTools/closeSession.ts +29 -0
- package/ai/tools/browserTools/common.ts +27 -0
- package/ai/tools/browserTools/openSession.ts +48 -0
- package/ai/tools/browserTools/readContent.ts +38 -0
- package/ai/tools/browserTools/selectOption.ts +46 -0
- package/ai/tools/browserTools/typeText.ts +42 -0
- package/ai/tools/category/createCategoryTool.ts +66 -0
- package/ai/tools/category/queryContentsByCategoryTool.ts +69 -0
- package/ai/tools/category/updateContentCategoryTool.ts +75 -0
- package/ai/tools/cfBrowserTools.ts +319 -0
- package/ai/tools/cfSpeechToTextTool.ts +49 -0
- package/ai/tools/checkEnvTool.ts +65 -0
- package/ai/tools/cloudflareCrawlTool.ts +289 -0
- package/ai/tools/codeSearchTool.ts +111 -0
- package/ai/tools/codeTools.ts +101 -0
- package/ai/tools/createDocTool.ts +132 -0
- package/ai/tools/createPlanTool.ts +999 -0
- package/ai/tools/createSkillDocTool.ts +155 -0
- package/ai/tools/createWorkflowTool.ts +154 -0
- package/ai/tools/deepseekOcrTool.ts +34 -0
- package/ai/tools/delayTool.ts +31 -0
- package/ai/tools/deleteSpacesTool.ts +325 -0
- package/ai/tools/deleteSpacesToolModel.ts +159 -0
- package/ai/tools/devReloadUtils.ts +29 -0
- package/ai/tools/dialogMessageSearch.ts +137 -0
- package/ai/tools/doctorSkillTool.ts +72 -0
- package/ai/tools/ecommerceScraperTool.ts +86 -0
- package/ai/tools/emailTools.ts +549 -0
- package/ai/tools/evalSkillTool.ts +92 -0
- package/ai/tools/exaSearchTool.ts +64 -0
- package/ai/tools/execBashTool.ts +379 -0
- package/ai/tools/executeSqlTool.ts +192 -0
- package/ai/tools/fetchWebpageSupport.ts +309 -0
- package/ai/tools/fetchWebpageTool.ts +84 -0
- package/ai/tools/geminiImagePreviewTool.ts +361 -0
- package/ai/tools/generateDocxTool.ts +215 -0
- package/ai/tools/googleSearchScraperTool.ts +106 -0
- package/ai/tools/importDataTool.ts +133 -0
- package/ai/tools/importSkillTool.ts +162 -0
- package/ai/tools/index.ts +1858 -0
- package/ai/tools/listFilesTool.ts +82 -0
- package/ai/tools/listUserSpacesTool.ts +113 -0
- package/ai/tools/modelUsageTools.ts +142 -0
- package/ai/tools/olmOcrTool.ts +34 -0
- package/ai/tools/openaiImageTool.ts +218 -0
- package/ai/tools/paddleOcrTool.ts +34 -0
- package/ai/tools/prepareTools.ts +23 -0
- package/ai/tools/readDocTool.ts +84 -0
- package/ai/tools/readFileTool.ts +211 -0
- package/ai/tools/readTool.ts +163 -0
- package/ai/tools/readXPostTool.ts +233 -0
- package/ai/tools/rememberMemoryTool.ts +84 -0
- package/ai/tools/remotionVideoTool.ts +151 -0
- package/ai/tools/searchDialogMessagesTool.ts +222 -0
- package/ai/tools/searchRepoTool.ts +115 -0
- package/ai/tools/searchWorkspaceTool.ts +259 -0
- package/ai/tools/skillFollowup.ts +86 -0
- package/ai/tools/surfWeatherTool.ts +169 -0
- package/ai/tools/table/addTableRowTool.ts +217 -0
- package/ai/tools/table/createTableTool.ts +315 -0
- package/ai/tools/table/rowTools.ts +366 -0
- package/ai/tools/table/schemaTools.ts +244 -0
- package/ai/tools/table/shareTableTool.ts +148 -0
- package/ai/tools/table/toolShared.ts +129 -0
- package/ai/tools/toolApiClient.ts +198 -0
- package/ai/tools/toolNameAliases.ts +57 -0
- package/ai/tools/toolResultError.ts +42 -0
- package/ai/tools/toolRunSlice.ts +303 -0
- package/ai/tools/toolSchemaCompatibility.ts +53 -0
- package/ai/tools/toolVisibility.ts +4 -0
- package/ai/tools/types.ts +20 -0
- package/ai/tools/uiAskChoiceTool.ts +104 -0
- package/ai/tools/updateContentTitleTool.ts +84 -0
- package/ai/tools/updateDocTool.ts +105 -0
- package/ai/tools/updateUserPreferenceProfileTool.ts +145 -0
- package/ai/tools/whisperTool.ts +77 -0
- package/ai/tools/writeFileTool.ts +210 -0
- package/ai/tools/youtubeScraperTool.ts +116 -0
- package/ai/tools/ziweiChartTool.ts +678 -0
- package/ai/types.ts +55 -0
- package/ai/workflow/workflowExecutor.ts +323 -0
- package/ai/workflow/workflowSlice.ts +73 -0
- package/ai/workflow/workflowTypes.ts +106 -0
- package/client/compactDialog.ts +222 -0
- package/connector-experimental/capabilities.ts +73 -0
- package/connector-experimental/codexBinary.ts +41 -0
- package/connector-experimental/heartbeatLoop.ts +22 -0
- package/connector-experimental/index.ts +5 -0
- package/connector-experimental/machineInfo.ts +46 -0
- package/connector-experimental/protocol.ts +54 -0
- package/machineCommands.ts +4 -4
- package/package.json +22 -6
|
@@ -0,0 +1,703 @@
|
|
|
1
|
+
// 文件路径: chat/sendOpenAICompletionsRequest.ts
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
addActiveController,
|
|
5
|
+
removeActiveController,
|
|
6
|
+
tokenUsageLiveUpdate,
|
|
7
|
+
} from "chat/dialog/dialogSlice";
|
|
8
|
+
import {
|
|
9
|
+
messageStreamEnd,
|
|
10
|
+
messageStreaming,
|
|
11
|
+
} from "chat/messages/messageSlice";
|
|
12
|
+
import { handleToolCalls } from "chat/messages/toolThunks";
|
|
13
|
+
import {
|
|
14
|
+
MessageContentPart,
|
|
15
|
+
Message,
|
|
16
|
+
OpenAITextContent,
|
|
17
|
+
} from "chat/messages/types";
|
|
18
|
+
import { selectCurrentServer } from "app/settings/settingSlice";
|
|
19
|
+
import { selectCurrentSpaceId } from "create/space/spaceSlice";
|
|
20
|
+
import { getApiEndpoint } from "ai/llm/providers";
|
|
21
|
+
import { createDialogMessageKeyAndId } from "database/keys";
|
|
22
|
+
import { selectCurrentToken } from "auth/authSlice";
|
|
23
|
+
import { extractCustomId } from "core/prefix";
|
|
24
|
+
|
|
25
|
+
import { performFetchRequest } from "./fetchUtils";
|
|
26
|
+
import { createSSEParser } from "./parseMultilineSSE";
|
|
27
|
+
import { parseApiError } from "./parseApiError";
|
|
28
|
+
import { updateTotalUsage } from "./updateTotalUsage";
|
|
29
|
+
import { accumulateToolCallChunks } from "./accumulateToolCallChunks";
|
|
30
|
+
import { prepareTools } from "../tools/prepareTools";
|
|
31
|
+
|
|
32
|
+
import { getModelInfo } from "ai/llm/getModelContextWindow";
|
|
33
|
+
|
|
34
|
+
import type { RootState } from "app/store";
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 追加文本 chunk 到 contentBuffer(不可变更新)
|
|
38
|
+
*/
|
|
39
|
+
function appendTextChunk(
|
|
40
|
+
currentContentBuffer: MessageContentPart[],
|
|
41
|
+
textChunk: string
|
|
42
|
+
): MessageContentPart[] {
|
|
43
|
+
if (!textChunk) return currentContentBuffer;
|
|
44
|
+
|
|
45
|
+
const updatedContentBuffer = [...currentContentBuffer];
|
|
46
|
+
const lastIndex = updatedContentBuffer.length - 1;
|
|
47
|
+
|
|
48
|
+
if (lastIndex >= 0 && updatedContentBuffer[lastIndex].type === "text") {
|
|
49
|
+
const last = updatedContentBuffer[lastIndex] as OpenAITextContent;
|
|
50
|
+
updatedContentBuffer[lastIndex] = {
|
|
51
|
+
...last,
|
|
52
|
+
text: (last.text || "") + textChunk,
|
|
53
|
+
};
|
|
54
|
+
} else {
|
|
55
|
+
updatedContentBuffer.push({ type: "text", text: textChunk });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return updatedContentBuffer;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** OpenAI 标准 tool_call 结构 */
|
|
62
|
+
type AssistantToolCall = {
|
|
63
|
+
id: string;
|
|
64
|
+
type: "function";
|
|
65
|
+
function: { name: string; arguments: string };
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
function getStreamErrorMessage(data: any): string {
|
|
69
|
+
const message =
|
|
70
|
+
typeof data?.error?.message === "string" && data.error.message.trim()
|
|
71
|
+
? data.error.message.trim()
|
|
72
|
+
: typeof data?.error?.msg === "string" && data.error.msg.trim()
|
|
73
|
+
? data.error.msg.trim()
|
|
74
|
+
: typeof data?.message === "string" && data.message.trim()
|
|
75
|
+
? data.message.trim()
|
|
76
|
+
: null;
|
|
77
|
+
if (message) return message;
|
|
78
|
+
|
|
79
|
+
const code =
|
|
80
|
+
typeof data?.error?.code === "string" && data.error.code.trim()
|
|
81
|
+
? data.error.code.trim()
|
|
82
|
+
: typeof data?.code === "string" && data.code.trim()
|
|
83
|
+
? data.code.trim()
|
|
84
|
+
: null;
|
|
85
|
+
if (code) return code;
|
|
86
|
+
|
|
87
|
+
const type =
|
|
88
|
+
typeof data?.error?.type === "string" && data.error.type.trim()
|
|
89
|
+
? data.error.type.trim()
|
|
90
|
+
: null;
|
|
91
|
+
if (type) return type;
|
|
92
|
+
|
|
93
|
+
return "Unknown error";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** 单次流式请求过程中的全部中间状态(显式 state) */
|
|
97
|
+
type StreamState = {
|
|
98
|
+
contentBuffer: MessageContentPart[];
|
|
99
|
+
totalUsage: any | null;
|
|
100
|
+
accumulatedToolCalls: any[];
|
|
101
|
+
reasoningBuffer: string;
|
|
102
|
+
assistantToolCalls?: AssistantToolCall[];
|
|
103
|
+
hasHandedOff: boolean;
|
|
104
|
+
hasProcessedToolCalls: boolean;
|
|
105
|
+
alreadyFinalized: boolean;
|
|
106
|
+
finishReason: string | null;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
type FinalizeContext = {
|
|
110
|
+
dispatch: any;
|
|
111
|
+
msgKey: string;
|
|
112
|
+
dialogId: string;
|
|
113
|
+
dialogKey: string;
|
|
114
|
+
messageId: string;
|
|
115
|
+
agentConfig: any;
|
|
116
|
+
spaceId?: string;
|
|
117
|
+
messageMetadata?: Partial<Message>;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
type ToolCallsContext = {
|
|
121
|
+
dispatch: any;
|
|
122
|
+
agentConfig: any;
|
|
123
|
+
dialogId: string;
|
|
124
|
+
dialogKey: string;
|
|
125
|
+
messageId: string;
|
|
126
|
+
messageMetadata?: Partial<Message>;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
type StreamCompletionContext = {
|
|
130
|
+
dispatch: any;
|
|
131
|
+
dialogId: string;
|
|
132
|
+
dialogKey: string;
|
|
133
|
+
messageId: string;
|
|
134
|
+
agentConfig: any;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/** 单轮调用后返回给 Agent Loop 的元信息 */
|
|
138
|
+
export type CompletionMeta = {
|
|
139
|
+
hasToolCalls: boolean;
|
|
140
|
+
hasPendingInteraction: boolean;
|
|
141
|
+
hasHandedOff: boolean;
|
|
142
|
+
finishReason: string | null;
|
|
143
|
+
messageId: string;
|
|
144
|
+
usage?: any;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 初始化流式状态
|
|
149
|
+
*/
|
|
150
|
+
function createInitialStreamState(): StreamState {
|
|
151
|
+
return {
|
|
152
|
+
contentBuffer: [],
|
|
153
|
+
totalUsage: null,
|
|
154
|
+
accumulatedToolCalls: [],
|
|
155
|
+
reasoningBuffer: "",
|
|
156
|
+
assistantToolCalls: undefined,
|
|
157
|
+
hasHandedOff: false,
|
|
158
|
+
hasProcessedToolCalls: false,
|
|
159
|
+
alreadyFinalized: false,
|
|
160
|
+
finishReason: null,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 根据 tools 配置生成本次请求体(不改动外部传入的 bodyData)
|
|
166
|
+
*/
|
|
167
|
+
function buildRequestBodyWithTools(
|
|
168
|
+
bodyData: any,
|
|
169
|
+
agentConfig: any,
|
|
170
|
+
disableToolsForThisRequest: boolean
|
|
171
|
+
): any {
|
|
172
|
+
if (disableToolsForThisRequest) return bodyData;
|
|
173
|
+
|
|
174
|
+
// 如果模型拥有图像输出能力,则不组装任何 tools
|
|
175
|
+
const modelInfo = getModelInfo(agentConfig.model);
|
|
176
|
+
if (modelInfo?.hasImageOutput) {
|
|
177
|
+
return bodyData;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const rawTools = agentConfig.tools;
|
|
181
|
+
if (!Array.isArray(rawTools) || rawTools.length === 0) return bodyData;
|
|
182
|
+
|
|
183
|
+
const tools = prepareTools(rawTools, { provider: agentConfig.provider });
|
|
184
|
+
if (!tools.length) return bodyData;
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
...bodyData,
|
|
188
|
+
tools,
|
|
189
|
+
tool_choice: bodyData.tool_choice ?? "auto",
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* 结束当前流式消息,派发 messageStreamEnd(带幂等保护)
|
|
195
|
+
*/
|
|
196
|
+
async function finalizeStream(
|
|
197
|
+
state: StreamState,
|
|
198
|
+
ctx: FinalizeContext
|
|
199
|
+
): Promise<StreamState> {
|
|
200
|
+
if (state.hasHandedOff || state.alreadyFinalized) return state;
|
|
201
|
+
|
|
202
|
+
await ctx.dispatch(
|
|
203
|
+
messageStreamEnd({
|
|
204
|
+
finalContentBuffer: state.contentBuffer,
|
|
205
|
+
totalUsage: state.totalUsage,
|
|
206
|
+
msgKey: ctx.msgKey,
|
|
207
|
+
agentConfig: ctx.agentConfig,
|
|
208
|
+
dialogId: ctx.dialogId,
|
|
209
|
+
dialogKey: ctx.dialogKey,
|
|
210
|
+
messageId: ctx.messageId,
|
|
211
|
+
reasoningBuffer: state.reasoningBuffer,
|
|
212
|
+
messageMetadata: ctx.messageMetadata,
|
|
213
|
+
toolCalls: state.assistantToolCalls,
|
|
214
|
+
spaceId: ctx.spaceId,
|
|
215
|
+
})
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
...state,
|
|
220
|
+
alreadyFinalized: true,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* 累积 usage
|
|
226
|
+
*/
|
|
227
|
+
function applyUsage(state: StreamState, data: any): StreamState {
|
|
228
|
+
if (!data.usage) return state;
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
...state,
|
|
232
|
+
totalUsage: updateTotalUsage(state.totalUsage, data.usage),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* 处理单个 delta(文本 / 推理 / tool_calls / 图片)
|
|
238
|
+
*/
|
|
239
|
+
function applyDelta(
|
|
240
|
+
state: StreamState,
|
|
241
|
+
delta: any
|
|
242
|
+
): { state: StreamState; hasNewVisibleContent: boolean } {
|
|
243
|
+
let hasNewVisibleContent = false;
|
|
244
|
+
let next: StreamState = { ...state };
|
|
245
|
+
|
|
246
|
+
// reasoning_content 增量(DeepSeek)/ reasoning 增量(Ollama/Qwen3)
|
|
247
|
+
const reasoningChunk: string = delta.reasoning_content ?? delta.reasoning ?? "";
|
|
248
|
+
if (reasoningChunk) {
|
|
249
|
+
next.reasoningBuffer = (next.reasoningBuffer || "") + reasoningChunk;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// tool_calls 累积 + 映射为 OpenAI 标准格式
|
|
253
|
+
if (Array.isArray(delta.tool_calls) && delta.tool_calls.length > 0) {
|
|
254
|
+
const accumulated = accumulateToolCallChunks(
|
|
255
|
+
next.accumulatedToolCalls,
|
|
256
|
+
delta.tool_calls
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
next = {
|
|
260
|
+
...next,
|
|
261
|
+
accumulatedToolCalls: accumulated,
|
|
262
|
+
assistantToolCalls: accumulated.map((call: any) => ({
|
|
263
|
+
id: call.id,
|
|
264
|
+
type: "function",
|
|
265
|
+
function: {
|
|
266
|
+
name: call.function?.name,
|
|
267
|
+
arguments:
|
|
268
|
+
typeof call.function?.arguments === "string"
|
|
269
|
+
? call.function.arguments
|
|
270
|
+
: JSON.stringify(call.function?.arguments ?? {}),
|
|
271
|
+
},
|
|
272
|
+
})),
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// 图片增量
|
|
277
|
+
const deltaAny = delta as any;
|
|
278
|
+
if (Array.isArray(deltaAny.images) && deltaAny.images.length > 0) {
|
|
279
|
+
next = {
|
|
280
|
+
...next,
|
|
281
|
+
contentBuffer: [...next.contentBuffer, ...deltaAny.images],
|
|
282
|
+
};
|
|
283
|
+
hasNewVisibleContent = true;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// 文本增量
|
|
287
|
+
const contentChunk = delta.content || "";
|
|
288
|
+
if (contentChunk) {
|
|
289
|
+
next = {
|
|
290
|
+
...next,
|
|
291
|
+
contentBuffer: appendTextChunk(next.contentBuffer, contentChunk),
|
|
292
|
+
};
|
|
293
|
+
hasNewVisibleContent = true;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return { state: next, hasNewVisibleContent };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* 如果有新可见内容,则派发一次 messageStreaming 更新前端
|
|
301
|
+
*/
|
|
302
|
+
function emitStreamingUpdate(
|
|
303
|
+
hasNewVisibleContent: boolean,
|
|
304
|
+
state: StreamState,
|
|
305
|
+
ctx: {
|
|
306
|
+
dispatch: any;
|
|
307
|
+
agentConfig: any;
|
|
308
|
+
messageId: string;
|
|
309
|
+
msgKey: string;
|
|
310
|
+
dialogId: string;
|
|
311
|
+
messageMetadata?: Partial<Message>;
|
|
312
|
+
}
|
|
313
|
+
) {
|
|
314
|
+
if (!hasNewVisibleContent) return;
|
|
315
|
+
|
|
316
|
+
ctx.dispatch(
|
|
317
|
+
messageStreaming({
|
|
318
|
+
id: ctx.messageId,
|
|
319
|
+
dialogId: ctx.dialogId,
|
|
320
|
+
dbKey: ctx.msgKey,
|
|
321
|
+
content: state.contentBuffer,
|
|
322
|
+
thinkContent: state.reasoningBuffer,
|
|
323
|
+
role: "assistant",
|
|
324
|
+
agentKey: ctx.agentConfig.dbKey,
|
|
325
|
+
cybotKey: ctx.agentConfig.dbKey,
|
|
326
|
+
...(typeof ctx.agentConfig?.name === "string" && ctx.agentConfig.name.trim()
|
|
327
|
+
? { agentName: ctx.agentConfig.name.trim() }
|
|
328
|
+
: {}),
|
|
329
|
+
...(ctx.messageMetadata ?? {}),
|
|
330
|
+
})
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* 处理已经累积好的 tool_calls
|
|
336
|
+
*/
|
|
337
|
+
async function processAccumulatedToolCalls(
|
|
338
|
+
state: StreamState,
|
|
339
|
+
ctx: ToolCallsContext
|
|
340
|
+
): Promise<{
|
|
341
|
+
state: StreamState;
|
|
342
|
+
hasHandedOff: boolean;
|
|
343
|
+
hasPendingInteraction: boolean;
|
|
344
|
+
}> {
|
|
345
|
+
if (!state.accumulatedToolCalls.length) {
|
|
346
|
+
return {
|
|
347
|
+
state,
|
|
348
|
+
hasHandedOff: false,
|
|
349
|
+
hasPendingInteraction: false,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const result = await ctx
|
|
354
|
+
.dispatch(
|
|
355
|
+
handleToolCalls({
|
|
356
|
+
accumulatedCalls: state.accumulatedToolCalls,
|
|
357
|
+
currentContentBuffer: state.contentBuffer,
|
|
358
|
+
agentConfig: ctx.agentConfig,
|
|
359
|
+
messageId: ctx.messageId,
|
|
360
|
+
dialogId: ctx.dialogId,
|
|
361
|
+
dialogKey: ctx.dialogKey,
|
|
362
|
+
parallelSessionId: ctx.messageMetadata?.parallelSessionId,
|
|
363
|
+
parallelBranchId: ctx.messageMetadata?.parallelBranchId,
|
|
364
|
+
parallelLabel: ctx.messageMetadata?.parallelLabel,
|
|
365
|
+
parallelIndex: ctx.messageMetadata?.parallelIndex,
|
|
366
|
+
})
|
|
367
|
+
)
|
|
368
|
+
.unwrap();
|
|
369
|
+
|
|
370
|
+
const nextState: StreamState = {
|
|
371
|
+
...state,
|
|
372
|
+
contentBuffer: result.finalContentBuffer,
|
|
373
|
+
accumulatedToolCalls: [],
|
|
374
|
+
hasProcessedToolCalls: true,
|
|
375
|
+
hasHandedOff: result.hasHandedOff,
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
return {
|
|
379
|
+
state: nextState,
|
|
380
|
+
hasHandedOff: result.hasHandedOff,
|
|
381
|
+
hasPendingInteraction: result.hasPendingInteraction,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* 处理「流结束」场景(done === true)
|
|
387
|
+
*/
|
|
388
|
+
async function handleStreamCompletion(
|
|
389
|
+
state: StreamState,
|
|
390
|
+
ctx: StreamCompletionContext,
|
|
391
|
+
finalizeCtx: FinalizeContext
|
|
392
|
+
): Promise<{
|
|
393
|
+
state: StreamState;
|
|
394
|
+
hasHandedOff: boolean;
|
|
395
|
+
hasPendingInteraction: boolean;
|
|
396
|
+
}> {
|
|
397
|
+
let hasHandedOff = false;
|
|
398
|
+
let hasPendingInteraction = false;
|
|
399
|
+
|
|
400
|
+
if (!state.hasProcessedToolCalls && state.accumulatedToolCalls.length > 0) {
|
|
401
|
+
// Tool 开始前先更新 TopBar token 显示
|
|
402
|
+
if (state.totalUsage) {
|
|
403
|
+
ctx.dispatch(tokenUsageLiveUpdate({
|
|
404
|
+
input_tokens: state.totalUsage.prompt_tokens ?? state.totalUsage.input_tokens,
|
|
405
|
+
output_tokens: state.totalUsage.completion_tokens ?? state.totalUsage.output_tokens,
|
|
406
|
+
cost: state.totalUsage.cost,
|
|
407
|
+
dialogKey: ctx.dialogKey,
|
|
408
|
+
}));
|
|
409
|
+
}
|
|
410
|
+
const toolResult = await processAccumulatedToolCalls(state, {
|
|
411
|
+
dispatch: ctx.dispatch,
|
|
412
|
+
agentConfig: ctx.agentConfig,
|
|
413
|
+
dialogId: ctx.dialogId,
|
|
414
|
+
dialogKey: ctx.dialogKey,
|
|
415
|
+
messageId: ctx.messageId,
|
|
416
|
+
messageMetadata: ctx.messageMetadata,
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
let next = toolResult.state;
|
|
420
|
+
hasHandedOff ||= toolResult.hasHandedOff;
|
|
421
|
+
hasPendingInteraction ||= toolResult.hasPendingInteraction;
|
|
422
|
+
|
|
423
|
+
next = await finalizeStream(next, finalizeCtx);
|
|
424
|
+
return { state: next, hasHandedOff, hasPendingInteraction };
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const finalized = await finalizeStream(state, finalizeCtx);
|
|
428
|
+
return { state: finalized, hasHandedOff, hasPendingInteraction };
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* 主流程:发送请求 + 处理流式 SSE + 工具调用
|
|
433
|
+
*/
|
|
434
|
+
export const sendOpenAICompletionsRequest = async ({
|
|
435
|
+
bodyData,
|
|
436
|
+
agentConfig,
|
|
437
|
+
thunkApi,
|
|
438
|
+
dialogKey,
|
|
439
|
+
parentMessageId,
|
|
440
|
+
messageMetadata,
|
|
441
|
+
disableToolsForThisRequest = false,
|
|
442
|
+
}: {
|
|
443
|
+
bodyData: any;
|
|
444
|
+
agentConfig: any;
|
|
445
|
+
thunkApi: any;
|
|
446
|
+
dialogKey: string;
|
|
447
|
+
parentMessageId?: string;
|
|
448
|
+
messageMetadata?: Partial<Message>;
|
|
449
|
+
disableToolsForThisRequest?: boolean;
|
|
450
|
+
}): Promise<CompletionMeta> => {
|
|
451
|
+
const { dispatch, getState, signal: thunkSignal } = thunkApi;
|
|
452
|
+
|
|
453
|
+
const dialogId = extractCustomId(dialogKey);
|
|
454
|
+
const controller = new AbortController();
|
|
455
|
+
thunkSignal.addEventListener("abort", () => controller.abort());
|
|
456
|
+
const signal = controller.signal;
|
|
457
|
+
const streamSpaceId = selectCurrentSpaceId(getState() as RootState) || undefined;
|
|
458
|
+
|
|
459
|
+
let messageId: string;
|
|
460
|
+
let msgKey: string;
|
|
461
|
+
|
|
462
|
+
if (parentMessageId) {
|
|
463
|
+
messageId = parentMessageId;
|
|
464
|
+
msgKey = `msg:${dialogId}:${messageId}`;
|
|
465
|
+
} else {
|
|
466
|
+
const newIds = createDialogMessageKeyAndId(dialogId);
|
|
467
|
+
messageId = newIds.messageId;
|
|
468
|
+
msgKey = newIds.key;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
dispatch(addActiveController({ messageId, controller, dialogKey }));
|
|
472
|
+
|
|
473
|
+
const requestBody = buildRequestBodyWithTools(
|
|
474
|
+
bodyData,
|
|
475
|
+
agentConfig,
|
|
476
|
+
disableToolsForThisRequest
|
|
477
|
+
);
|
|
478
|
+
|
|
479
|
+
let streamState: StreamState = createInitialStreamState();
|
|
480
|
+
const parseSSE = createSSEParser();
|
|
481
|
+
let reader: ReadableStreamDefaultReader<Uint8Array> | undefined;
|
|
482
|
+
|
|
483
|
+
const finalizeCtx: FinalizeContext = {
|
|
484
|
+
dispatch,
|
|
485
|
+
msgKey,
|
|
486
|
+
dialogId,
|
|
487
|
+
dialogKey,
|
|
488
|
+
messageId,
|
|
489
|
+
agentConfig,
|
|
490
|
+
spaceId: streamSpaceId,
|
|
491
|
+
messageMetadata,
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
let hasHandedOffOverall = false;
|
|
495
|
+
let hasPendingInteractionOverall = false;
|
|
496
|
+
let lastFinishReason: string | null = null;
|
|
497
|
+
|
|
498
|
+
const buildMeta = (): CompletionMeta => ({
|
|
499
|
+
hasToolCalls:
|
|
500
|
+
Array.isArray(streamState.assistantToolCalls) &&
|
|
501
|
+
streamState.assistantToolCalls.length > 0,
|
|
502
|
+
hasPendingInteraction: hasPendingInteractionOverall,
|
|
503
|
+
hasHandedOff: hasHandedOffOverall,
|
|
504
|
+
finishReason: lastFinishReason,
|
|
505
|
+
messageId,
|
|
506
|
+
usage: streamState.totalUsage ?? undefined,
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
try {
|
|
510
|
+
if (!parentMessageId) {
|
|
511
|
+
dispatch(
|
|
512
|
+
messageStreaming({
|
|
513
|
+
id: messageId,
|
|
514
|
+
dialogId,
|
|
515
|
+
dbKey: msgKey,
|
|
516
|
+
content: "",
|
|
517
|
+
role: "assistant",
|
|
518
|
+
agentKey: agentConfig.dbKey,
|
|
519
|
+
cybotKey: agentConfig.dbKey,
|
|
520
|
+
...(typeof agentConfig?.name === "string" && agentConfig.name.trim()
|
|
521
|
+
? { agentName: agentConfig.name.trim() }
|
|
522
|
+
: {}),
|
|
523
|
+
...(messageMetadata ?? {}),
|
|
524
|
+
isStreaming: true,
|
|
525
|
+
})
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const api = getApiEndpoint(agentConfig);
|
|
530
|
+
const token = selectCurrentToken(getState() as RootState);
|
|
531
|
+
const response = await performFetchRequest({
|
|
532
|
+
agentConfig,
|
|
533
|
+
api,
|
|
534
|
+
bodyData: requestBody,
|
|
535
|
+
currentServer: selectCurrentServer(getState() as RootState),
|
|
536
|
+
signal,
|
|
537
|
+
token,
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
if (!response.ok) {
|
|
541
|
+
const errorMessage = await parseApiError(response);
|
|
542
|
+
streamState = {
|
|
543
|
+
...streamState,
|
|
544
|
+
contentBuffer: appendTextChunk(
|
|
545
|
+
streamState.contentBuffer,
|
|
546
|
+
`[错误: ${errorMessage}]`
|
|
547
|
+
),
|
|
548
|
+
};
|
|
549
|
+
streamState = await finalizeStream(streamState, finalizeCtx);
|
|
550
|
+
return buildMeta();
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
reader = response.body?.getReader();
|
|
554
|
+
if (!reader) {
|
|
555
|
+
streamState = await finalizeStream(streamState, finalizeCtx);
|
|
556
|
+
return buildMeta();
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
const decoder = new TextDecoder();
|
|
560
|
+
|
|
561
|
+
while (true) {
|
|
562
|
+
const { done, value } = await reader.read();
|
|
563
|
+
|
|
564
|
+
if (done) {
|
|
565
|
+
const completion = await handleStreamCompletion(
|
|
566
|
+
streamState,
|
|
567
|
+
{
|
|
568
|
+
dispatch,
|
|
569
|
+
dialogId,
|
|
570
|
+
dialogKey: finalizeCtx.dialogKey,
|
|
571
|
+
messageId,
|
|
572
|
+
agentConfig,
|
|
573
|
+
},
|
|
574
|
+
finalizeCtx
|
|
575
|
+
);
|
|
576
|
+
|
|
577
|
+
streamState = completion.state;
|
|
578
|
+
hasHandedOffOverall ||= completion.hasHandedOff;
|
|
579
|
+
hasPendingInteractionOverall ||= completion.hasPendingInteraction;
|
|
580
|
+
|
|
581
|
+
break;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
585
|
+
const parsedResults = parseSSE(chunk);
|
|
586
|
+
|
|
587
|
+
for (const parsedData of parsedResults) {
|
|
588
|
+
const dataList = Array.isArray(parsedData) ? parsedData : [parsedData];
|
|
589
|
+
|
|
590
|
+
for (const data of dataList) {
|
|
591
|
+
streamState = applyUsage(streamState, data);
|
|
592
|
+
|
|
593
|
+
if (data === "[DONE]") {
|
|
594
|
+
// Web 端通常依赖 reader.read() 的 done 状态来结束,
|
|
595
|
+
// 但如果流中显式包含 [DONE],也可以直接 break。
|
|
596
|
+
// 这里我们选择忽略它,让 reader 自然结束。
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
if (data.error) {
|
|
601
|
+
const errorMsg = `Error: ${getStreamErrorMessage(data)}`;
|
|
602
|
+
streamState = {
|
|
603
|
+
...streamState,
|
|
604
|
+
contentBuffer: appendTextChunk(
|
|
605
|
+
streamState.contentBuffer,
|
|
606
|
+
`\n[API Error] ${errorMsg}`
|
|
607
|
+
),
|
|
608
|
+
};
|
|
609
|
+
await reader.cancel();
|
|
610
|
+
break;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
const choice = data.choices?.[0];
|
|
614
|
+
if (!choice) continue;
|
|
615
|
+
|
|
616
|
+
const delta = choice.delta || {};
|
|
617
|
+
|
|
618
|
+
const { state: updatedState, hasNewVisibleContent } = applyDelta(
|
|
619
|
+
streamState,
|
|
620
|
+
delta
|
|
621
|
+
);
|
|
622
|
+
streamState = updatedState;
|
|
623
|
+
|
|
624
|
+
emitStreamingUpdate(hasNewVisibleContent, streamState, {
|
|
625
|
+
dispatch,
|
|
626
|
+
agentConfig,
|
|
627
|
+
messageId,
|
|
628
|
+
msgKey,
|
|
629
|
+
dialogId,
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
const finishReason = choice.finish_reason;
|
|
633
|
+
if (finishReason) {
|
|
634
|
+
lastFinishReason = finishReason;
|
|
635
|
+
streamState.finishReason = finishReason;
|
|
636
|
+
|
|
637
|
+
if (finishReason === "tool_calls") {
|
|
638
|
+
// Tool 开始前先更新 TopBar token 显示
|
|
639
|
+
if (streamState.totalUsage) {
|
|
640
|
+
dispatch(tokenUsageLiveUpdate({
|
|
641
|
+
input_tokens: streamState.totalUsage.prompt_tokens ?? streamState.totalUsage.input_tokens,
|
|
642
|
+
output_tokens: streamState.totalUsage.completion_tokens ?? streamState.totalUsage.output_tokens,
|
|
643
|
+
cost: streamState.totalUsage.cost,
|
|
644
|
+
dialogKey,
|
|
645
|
+
}));
|
|
646
|
+
}
|
|
647
|
+
const toolResult = await processAccumulatedToolCalls(
|
|
648
|
+
streamState,
|
|
649
|
+
{
|
|
650
|
+
dispatch,
|
|
651
|
+
agentConfig,
|
|
652
|
+
dialogId,
|
|
653
|
+
dialogKey,
|
|
654
|
+
messageId,
|
|
655
|
+
messageMetadata,
|
|
656
|
+
}
|
|
657
|
+
);
|
|
658
|
+
|
|
659
|
+
streamState = toolResult.state;
|
|
660
|
+
hasHandedOffOverall ||= toolResult.hasHandedOff;
|
|
661
|
+
hasPendingInteractionOverall ||= toolResult.hasPendingInteraction;
|
|
662
|
+
|
|
663
|
+
// 无论是否 handoff,都 finalize 当前 assistant 消息(stub)
|
|
664
|
+
streamState = await finalizeStream(streamState, finalizeCtx);
|
|
665
|
+
} else if (finishReason !== "stop") {
|
|
666
|
+
streamState = {
|
|
667
|
+
...streamState,
|
|
668
|
+
contentBuffer: appendTextChunk(
|
|
669
|
+
streamState.contentBuffer,
|
|
670
|
+
`\n[流结束原因: ${finishReason}]`
|
|
671
|
+
),
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
} catch (error: any) {
|
|
679
|
+
let errorText: string;
|
|
680
|
+
if (error?.name === "AbortError") {
|
|
681
|
+
errorText = "\n[用户中断]";
|
|
682
|
+
} else {
|
|
683
|
+
errorText = `\n[错误: ${error?.message || String(error)}]`;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
console.error("[SSE] sendOpenAICompletionsRequest error:", error);
|
|
687
|
+
|
|
688
|
+
streamState = {
|
|
689
|
+
...streamState,
|
|
690
|
+
contentBuffer: appendTextChunk(streamState.contentBuffer, errorText),
|
|
691
|
+
};
|
|
692
|
+
streamState = await finalizeStream(streamState, finalizeCtx);
|
|
693
|
+
} finally {
|
|
694
|
+
dispatch(removeActiveController({ messageId, dialogKey }));
|
|
695
|
+
try {
|
|
696
|
+
await reader?.cancel();
|
|
697
|
+
} catch (_e) {
|
|
698
|
+
// ignore
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
return buildMeta();
|
|
703
|
+
};
|