@downcity/plugins 1.0.174 → 1.0.194
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/bin/BuiltinPlugins.d.ts +4 -9
- package/bin/BuiltinPlugins.d.ts.map +1 -1
- package/bin/BuiltinPlugins.js +4 -8
- package/bin/BuiltinPlugins.js.map +1 -1
- package/bin/chat/Action.d.ts +8 -2
- package/bin/chat/Action.d.ts.map +1 -1
- package/bin/chat/Action.js +9 -5
- package/bin/chat/Action.js.map +1 -1
- package/bin/chat/ChatPlugin.d.ts +2 -22
- package/bin/chat/ChatPlugin.d.ts.map +1 -1
- package/bin/chat/ChatPlugin.js +2 -21
- package/bin/chat/ChatPlugin.js.map +1 -1
- package/bin/chat/Index.d.ts +1 -1
- package/bin/chat/Index.d.ts.map +1 -1
- package/bin/chat/channels/BaseChatChannel.js +1 -1
- package/bin/chat/channels/BaseChatChannel.js.map +1 -1
- package/bin/chat/channels/Configuration.d.ts +1 -1
- package/bin/chat/channels/Configuration.js +1 -1
- package/bin/chat/channels/RuntimeChannel.d.ts +2 -3
- package/bin/chat/channels/RuntimeChannel.d.ts.map +1 -1
- package/bin/chat/channels/RuntimeChannel.js +0 -8
- package/bin/chat/channels/RuntimeChannel.js.map +1 -1
- package/bin/chat/channels/feishu/Feishu.d.ts.map +1 -1
- package/bin/chat/channels/feishu/Feishu.js +2 -1
- package/bin/chat/channels/feishu/Feishu.js.map +1 -1
- package/bin/chat/runtime/ChannelContextStore.d.ts.map +1 -1
- package/bin/chat/runtime/ChannelContextStore.js +13 -12
- package/bin/chat/runtime/ChannelContextStore.js.map +1 -1
- package/bin/chat/runtime/ChatActionExecution.d.ts +26 -1
- package/bin/chat/runtime/ChatActionExecution.d.ts.map +1 -1
- package/bin/chat/runtime/ChatActionExecution.js +31 -3
- package/bin/chat/runtime/ChatActionExecution.js.map +1 -1
- package/bin/chat/runtime/ChatActionInput.d.ts +1 -2
- package/bin/chat/runtime/ChatActionInput.d.ts.map +1 -1
- package/bin/chat/runtime/ChatActionInput.js +1 -27
- package/bin/chat/runtime/ChatActionInput.js.map +1 -1
- package/bin/chat/runtime/ChatChannelActions.d.ts +2 -66
- package/bin/chat/runtime/ChatChannelActions.d.ts.map +1 -1
- package/bin/chat/runtime/ChatChannelActions.js +3 -195
- package/bin/chat/runtime/ChatChannelActions.js.map +1 -1
- package/bin/chat/runtime/ChatChannelConfig.d.ts +2 -23
- package/bin/chat/runtime/ChatChannelConfig.d.ts.map +1 -1
- package/bin/chat/runtime/ChatChannelConfig.js +3 -116
- package/bin/chat/runtime/ChatChannelConfig.js.map +1 -1
- package/bin/chat/runtime/ChatChannelCore.d.ts +0 -14
- package/bin/chat/runtime/ChatChannelCore.d.ts.map +1 -1
- package/bin/chat/runtime/ChatChannelCore.js +1 -1
- package/bin/chat/runtime/ChatChannelCore.js.map +1 -1
- package/bin/chat/runtime/ChatChannelFacade.d.ts +1 -1
- package/bin/chat/runtime/ChatChannelFacade.d.ts.map +1 -1
- package/bin/chat/runtime/ChatChannelFacade.js +1 -1
- package/bin/chat/runtime/ChatChannelFacade.js.map +1 -1
- package/bin/chat/runtime/ChatHistoryStore.d.ts.map +1 -1
- package/bin/chat/runtime/ChatHistoryStore.js +4 -3
- package/bin/chat/runtime/ChatHistoryStore.js.map +1 -1
- package/bin/chat/runtime/ChatPluginActionRegistry.d.ts.map +1 -1
- package/bin/chat/runtime/ChatPluginActionRegistry.js +27 -89
- package/bin/chat/runtime/ChatPluginActionRegistry.js.map +1 -1
- package/bin/chat/runtime/ChatPluginSystem.d.ts +3 -2
- package/bin/chat/runtime/ChatPluginSystem.d.ts.map +1 -1
- package/bin/chat/runtime/ChatPluginSystem.js +5 -5
- package/bin/chat/runtime/ChatPluginSystem.js.map +1 -1
- package/bin/chat/runtime/ChatQueueStore.d.ts +1 -1
- package/bin/chat/runtime/ChatQueueStore.js +2 -2
- package/bin/chat/runtime/ChatQueueStore.js.map +1 -1
- package/bin/chat/runtime/ChatQueueWorker.js +1 -1
- package/bin/chat/runtime/ChatQueueWorker.js.map +1 -1
- package/bin/chat/runtime/ChatSessionDelete.d.ts.map +1 -1
- package/bin/chat/runtime/ChatSessionDelete.js +11 -20
- package/bin/chat/runtime/ChatSessionDelete.js.map +1 -1
- package/bin/chat/runtime/ChatStorage.d.ts +32 -0
- package/bin/chat/runtime/ChatStorage.d.ts.map +1 -0
- package/bin/chat/runtime/ChatStorage.js +158 -0
- package/bin/chat/runtime/ChatStorage.js.map +1 -0
- package/bin/chat/runtime/SystemPrompt.d.ts +3 -2
- package/bin/chat/runtime/SystemPrompt.d.ts.map +1 -1
- package/bin/chat/runtime/SystemPrompt.js +4 -5
- package/bin/chat/runtime/SystemPrompt.js.map +1 -1
- package/bin/chat/types/ChannelConfiguration.d.ts +2 -2
- package/bin/chat/types/ChatPluginActionPayload.d.ts +7 -45
- package/bin/chat/types/ChatPluginActionPayload.d.ts.map +1 -1
- package/bin/chat/types/ChatPluginOptions.d.ts +0 -21
- package/bin/chat/types/ChatPluginOptions.d.ts.map +1 -1
- package/bin/chat/types/ChatStorage.d.ts +36 -0
- package/bin/chat/types/ChatStorage.d.ts.map +1 -0
- package/bin/chat/types/ChatStorage.js +9 -0
- package/bin/chat/types/ChatStorage.js.map +1 -0
- package/bin/contact/Action.d.ts +3 -2
- package/bin/contact/Action.d.ts.map +1 -1
- package/bin/contact/Action.js +2 -2
- package/bin/contact/Action.js.map +1 -1
- package/bin/contact/ContactPlugin.d.ts.map +1 -1
- package/bin/contact/ContactPlugin.js +17 -14
- package/bin/contact/ContactPlugin.js.map +1 -1
- package/bin/contact/runtime/ChatRuntime.js +1 -1
- package/bin/contact/runtime/ChatRuntime.js.map +1 -1
- package/bin/contact/types/ContactPluginOptions.d.ts +4 -0
- package/bin/contact/types/ContactPluginOptions.d.ts.map +1 -1
- package/bin/index.d.ts +5 -5
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +2 -2
- package/bin/index.js.map +1 -1
- package/bin/memory/Action.d.ts.map +1 -1
- package/bin/memory/Action.js +16 -4
- package/bin/memory/Action.js.map +1 -1
- package/bin/memory/runtime/Store.d.ts.map +1 -1
- package/bin/memory/runtime/Store.js +0 -22
- package/bin/memory/runtime/Store.js.map +1 -1
- package/bin/memory/runtime/Writer.d.ts +1 -1
- package/bin/memory/runtime/Writer.d.ts.map +1 -1
- package/bin/memory/runtime/Writer.js +2 -4
- package/bin/memory/runtime/Writer.js.map +1 -1
- package/bin/skill/Command.d.ts +3 -11
- package/bin/skill/Command.d.ts.map +1 -1
- package/bin/skill/Command.js +3 -31
- package/bin/skill/Command.js.map +1 -1
- package/bin/skill/PROMPT.d.ts +1 -1
- package/bin/skill/PROMPT.d.ts.map +1 -1
- package/bin/skill/PROMPT.js +1 -1
- package/bin/skill/PROMPT.js.map +1 -1
- package/bin/skill/Plugin.d.ts +3 -2
- package/bin/skill/Plugin.d.ts.map +1 -1
- package/bin/skill/Plugin.js +37 -129
- package/bin/skill/Plugin.js.map +1 -1
- package/bin/skill/runtime/Prompt.d.ts +11 -2
- package/bin/skill/runtime/Prompt.d.ts.map +1 -1
- package/bin/skill/runtime/Prompt.js +93 -8
- package/bin/skill/runtime/Prompt.js.map +1 -1
- package/bin/skill/runtime/SystemProvider.d.ts +2 -1
- package/bin/skill/runtime/SystemProvider.d.ts.map +1 -1
- package/bin/skill/runtime/SystemProvider.js +4 -9
- package/bin/skill/runtime/SystemProvider.js.map +1 -1
- package/bin/skill/types/SkillPlugin.d.ts +6 -18
- package/bin/skill/types/SkillPlugin.d.ts.map +1 -1
- package/bin/skill/types/SkillPlugin.js +2 -2
- package/bin/sound/Plugin.d.ts +69 -0
- package/bin/sound/Plugin.d.ts.map +1 -0
- package/bin/sound/Plugin.js +623 -0
- package/bin/sound/Plugin.js.map +1 -0
- package/bin/sound/types/SoundPlugin.d.ts +150 -0
- package/bin/sound/types/SoundPlugin.d.ts.map +1 -0
- package/bin/sound/types/SoundPlugin.js +10 -0
- package/bin/sound/types/SoundPlugin.js.map +1 -0
- package/bin/task/Action.d.ts +2 -0
- package/bin/task/Action.d.ts.map +1 -1
- package/bin/task/Action.js +6 -0
- package/bin/task/Action.js.map +1 -1
- package/bin/task/runtime/Runner.d.ts +4 -0
- package/bin/task/runtime/Runner.d.ts.map +1 -1
- package/bin/task/runtime/Runner.js +15 -11
- package/bin/task/runtime/Runner.js.map +1 -1
- package/bin/task/runtime/TaskActionExecution.d.ts +2 -0
- package/bin/task/runtime/TaskActionExecution.d.ts.map +1 -1
- package/bin/task/runtime/TaskActionExecution.js +1 -0
- package/bin/task/runtime/TaskActionExecution.js.map +1 -1
- package/bin/task/runtime/TaskPluginActionRegistry.d.ts.map +1 -1
- package/bin/task/runtime/TaskPluginActionRegistry.js +1 -0
- package/bin/task/runtime/TaskPluginActionRegistry.js.map +1 -1
- package/bin/task/runtime/TaskRunChatDispatch.js +1 -1
- package/bin/task/runtime/TaskRunChatDispatch.js.map +1 -1
- package/bin/task/runtime/TaskRunnerRound.d.ts.map +1 -1
- package/bin/task/runtime/TaskRunnerRound.js +19 -26
- package/bin/task/runtime/TaskRunnerRound.js.map +1 -1
- package/bin/task/runtime/TaskRunnerSession.d.ts +6 -2
- package/bin/task/runtime/TaskRunnerSession.d.ts.map +1 -1
- package/bin/task/runtime/TaskRunnerSession.js +93 -72
- package/bin/task/runtime/TaskRunnerSession.js.map +1 -1
- package/bin/task/runtime/TaskRunnerTypes.d.ts +4 -4
- package/bin/task/runtime/TaskRunnerTypes.d.ts.map +1 -1
- package/bin/task/types/TaskPluginOptions.d.ts.map +1 -1
- package/bin/web/PROMPT.d.ts +1 -1
- package/bin/web/PROMPT.d.ts.map +1 -1
- package/bin/web/PROMPT.js +2 -2
- package/bin/web/PROMPT.js.map +1 -1
- package/bin/web/Plugin.d.ts +1 -21
- package/bin/web/Plugin.d.ts.map +1 -1
- package/bin/web/Plugin.js +14 -79
- package/bin/web/Plugin.js.map +1 -1
- package/bin/web/runtime/Prompt.d.ts +14 -0
- package/bin/web/runtime/Prompt.d.ts.map +1 -0
- package/bin/web/runtime/Prompt.js +77 -0
- package/bin/web/runtime/Prompt.js.map +1 -0
- package/bin/web/types/WebPlugin.d.ts +40 -29
- package/bin/web/types/WebPlugin.d.ts.map +1 -1
- package/bin/web/types/WebPlugin.js +11 -3
- package/bin/web/types/WebPlugin.js.map +1 -1
- package/bin/workboard/runtime/Collector.js +1 -1
- package/bin/workboard/runtime/Collector.js.map +1 -1
- package/bin/workboard/runtime/Normalizer.js +1 -1
- package/bin/workboard/runtime/Normalizer.js.map +1 -1
- package/bin/workboard/runtime/SessionSummary.d.ts.map +1 -1
- package/bin/workboard/runtime/SessionSummary.js +11 -38
- package/bin/workboard/runtime/SessionSummary.js.map +1 -1
- package/package.json +8 -4
- package/scripts/chat-access.test.mjs +1 -1
- package/scripts/chat-channel-config.test.mjs +15 -64
- package/scripts/chat-storage.test.mjs +92 -0
- package/scripts/skill-plugin.test.mjs +93 -0
- package/scripts/sound-plugin.test.mjs +250 -0
- package/scripts/web-plugin.test.mjs +85 -0
- package/src/BuiltinPlugins.ts +7 -17
- package/src/chat/Action.ts +16 -5
- package/src/chat/ChatPlugin.ts +6 -35
- package/src/chat/Index.ts +0 -1
- package/src/chat/channels/BaseChatChannel.ts +1 -1
- package/src/chat/channels/Configuration.ts +1 -1
- package/src/chat/channels/RuntimeChannel.ts +2 -14
- package/src/chat/channels/feishu/Feishu.ts +2 -1
- package/src/chat/runtime/ChannelContextStore.ts +16 -12
- package/src/chat/runtime/ChatActionExecution.ts +48 -3
- package/src/chat/runtime/ChatActionInput.ts +0 -31
- package/src/chat/runtime/ChatChannelActions.ts +3 -254
- package/src/chat/runtime/ChatChannelConfig.ts +4 -133
- package/src/chat/runtime/ChatChannelCore.ts +1 -15
- package/src/chat/runtime/ChatChannelFacade.ts +0 -4
- package/src/chat/runtime/ChatHistoryStore.ts +4 -3
- package/src/chat/runtime/ChatPluginActionRegistry.ts +26 -98
- package/src/chat/runtime/ChatPluginSystem.ts +9 -3
- package/src/chat/runtime/ChatQueueStore.ts +2 -2
- package/src/chat/runtime/ChatQueueWorker.ts +1 -1
- package/src/chat/runtime/ChatSessionDelete.ts +11 -21
- package/src/chat/runtime/ChatStorage.ts +203 -0
- package/src/chat/runtime/SystemPrompt.ts +8 -3
- package/src/chat/types/ChannelConfiguration.ts +2 -2
- package/src/chat/types/ChatPluginActionPayload.ts +8 -49
- package/src/chat/types/ChatPluginOptions.ts +0 -22
- package/src/chat/types/ChatStorage.ts +37 -0
- package/src/contact/Action.ts +9 -1
- package/src/contact/ContactPlugin.ts +38 -14
- package/src/contact/runtime/ChatRuntime.ts +1 -1
- package/src/contact/types/ContactPluginOptions.ts +6 -0
- package/src/index.ts +16 -14
- package/src/memory/Action.ts +19 -4
- package/src/memory/runtime/Store.ts +0 -27
- package/src/memory/runtime/Writer.ts +2 -5
- package/src/skill/Command.ts +3 -33
- package/src/skill/PROMPT.ts +1 -1
- package/src/skill/PROMPT.ts.txt +5 -1
- package/src/skill/Plugin.ts +49 -156
- package/src/skill/runtime/Prompt.ts +109 -9
- package/src/skill/runtime/SystemProvider.ts +5 -9
- package/src/skill/types/SkillPlugin.ts +6 -18
- package/src/sound/Plugin.ts +699 -0
- package/src/sound/types/SoundPlugin.ts +163 -0
- package/src/task/Action.ts +8 -0
- package/src/task/runtime/Runner.ts +19 -13
- package/src/task/runtime/TaskActionExecution.ts +3 -0
- package/src/task/runtime/TaskPluginActionRegistry.ts +1 -0
- package/src/task/runtime/TaskRunChatDispatch.ts +1 -1
- package/src/task/runtime/TaskRunnerRound.ts +20 -38
- package/src/task/runtime/TaskRunnerSession.ts +108 -72
- package/src/task/runtime/TaskRunnerTypes.ts +4 -4
- package/src/task/types/TaskPluginOptions.ts +1 -0
- package/src/web/PROMPT.ts +2 -2
- package/src/web/PROMPT.ts.txt +4 -2
- package/src/web/Plugin.ts +20 -90
- package/src/web/runtime/Prompt.ts +99 -0
- package/src/web/types/WebPlugin.ts +42 -29
- package/src/workboard/runtime/Collector.ts +1 -1
- package/src/workboard/runtime/Normalizer.ts +1 -1
- package/src/workboard/runtime/SessionSummary.ts +11 -42
- package/bin/asr/Plugin.d.ts +0 -63
- package/bin/asr/Plugin.d.ts.map +0 -1
- package/bin/asr/Plugin.js +0 -280
- package/bin/asr/Plugin.js.map +0 -1
- package/bin/asr/types/AsrPlugin.d.ts +0 -114
- package/bin/asr/types/AsrPlugin.d.ts.map +0 -1
- package/bin/asr/types/AsrPlugin.js +0 -10
- package/bin/asr/types/AsrPlugin.js.map +0 -1
- package/bin/chat/runtime/ChatSession.d.ts +0 -97
- package/bin/chat/runtime/ChatSession.d.ts.map +0 -1
- package/bin/chat/runtime/ChatSession.js +0 -91
- package/bin/chat/runtime/ChatSession.js.map +0 -1
- package/bin/chat/runtime/ChatSessionContextComposer.d.ts +0 -45
- package/bin/chat/runtime/ChatSessionContextComposer.d.ts.map +0 -1
- package/bin/chat/runtime/ChatSessionContextComposer.js +0 -60
- package/bin/chat/runtime/ChatSessionContextComposer.js.map +0 -1
- package/bin/chat/runtime/ChatSessionTypes.d.ts +0 -30
- package/bin/chat/runtime/ChatSessionTypes.d.ts.map +0 -1
- package/bin/chat/runtime/ChatSessionTypes.js +0 -9
- package/bin/chat/runtime/ChatSessionTypes.js.map +0 -1
- package/bin/tts/Plugin.d.ts +0 -49
- package/bin/tts/Plugin.d.ts.map +0 -1
- package/bin/tts/Plugin.js +0 -247
- package/bin/tts/Plugin.js.map +0 -1
- package/bin/tts/types/TtsPlugin.d.ts +0 -122
- package/bin/tts/types/TtsPlugin.d.ts.map +0 -1
- package/bin/tts/types/TtsPlugin.js +0 -10
- package/bin/tts/types/TtsPlugin.js.map +0 -1
- package/bin/web/runtime/Install.d.ts +0 -19
- package/bin/web/runtime/Install.d.ts.map +0 -1
- package/bin/web/runtime/Install.js +0 -178
- package/bin/web/runtime/Install.js.map +0 -1
- package/src/asr/Plugin.ts +0 -322
- package/src/asr/types/AsrPlugin.ts +0 -118
- package/src/chat/runtime/ChatSession.ts +0 -168
- package/src/chat/runtime/ChatSessionContextComposer.ts +0 -106
- package/src/chat/runtime/ChatSessionTypes.ts +0 -32
- package/src/tts/Plugin.ts +0 -284
- package/src/tts/types/TtsPlugin.ts +0 -129
- package/src/web/runtime/Install.ts +0 -241
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SoundPlugin 类型定义。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - SoundPlugin 统一承载 ASR 与 TTS,不绑定本地模型、Python 或具体 provider。
|
|
6
|
+
* - ASR 结果字段与 AI SDK `TranscriptionResult` 的可序列化核心字段保持一致。
|
|
7
|
+
* - TTS 结果直接使用 AI SDK `UIMessage`,由 agent 统一处理音频 file part。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { UIMessage } from "ai";
|
|
11
|
+
import type { JsonObject, JsonValue } from "@downcity/agent";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* SoundPlugin 支持的语音能力。
|
|
15
|
+
*/
|
|
16
|
+
export type SoundPluginCapability = "asr" | "tts";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* SoundPlugin 可见的 FED 模型信息。
|
|
20
|
+
*/
|
|
21
|
+
export interface SoundPluginModel {
|
|
22
|
+
/** FED 模型唯一 ID,同时也是调用 ASR/TTS 时传入的模型引用。 */
|
|
23
|
+
id: string;
|
|
24
|
+
/** 面向用户和 Agent 展示的模型名称。 */
|
|
25
|
+
name: string;
|
|
26
|
+
/** 模型用途、语言或质量说明。 */
|
|
27
|
+
description?: string;
|
|
28
|
+
/** 模型支持的能力列表,至少包含 `asr` 或 `tts`。 */
|
|
29
|
+
modalities: string[];
|
|
30
|
+
/** FED 为模型提供的筛选标签。 */
|
|
31
|
+
tags?: string[];
|
|
32
|
+
/** FED 返回的 JSON 可序列化扩展元数据。 */
|
|
33
|
+
meta?: JsonObject;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* SoundPlugin 模型列表结果。
|
|
38
|
+
*/
|
|
39
|
+
export interface SoundPluginModelsResult {
|
|
40
|
+
/** 满足当前能力筛选条件的模型列表。 */
|
|
41
|
+
items: SoundPluginModel[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* ASR 转写分段。
|
|
46
|
+
*
|
|
47
|
+
* 字段命名与 AI SDK `TranscriptionResult.segments` 保持一致。
|
|
48
|
+
*/
|
|
49
|
+
export interface SoundPluginAsrSegment {
|
|
50
|
+
/** 当前时间片段识别得到的文本。 */
|
|
51
|
+
text: string;
|
|
52
|
+
/** 当前片段在音频中的开始时间,单位为秒。 */
|
|
53
|
+
startSecond: number;
|
|
54
|
+
/** 当前片段在音频中的结束时间,单位为秒。 */
|
|
55
|
+
endSecond: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* ASR 输入。
|
|
60
|
+
*/
|
|
61
|
+
export interface SoundPluginAsrInput {
|
|
62
|
+
/** 支持 ASR 的 FED 模型 ID;未提供时使用 `default_asr_model`。 */
|
|
63
|
+
model?: string;
|
|
64
|
+
/** 本地音频文件的绝对路径或相对 Agent 项目根目录的路径。 */
|
|
65
|
+
audio_path?: string;
|
|
66
|
+
/** 可由 FED 直接读取的远程音频 URL。 */
|
|
67
|
+
url?: string;
|
|
68
|
+
/** data URL 形式的音频内容。 */
|
|
69
|
+
data_url?: string;
|
|
70
|
+
/** 语言提示,例如 `auto`、`zh` 或 `en`。 */
|
|
71
|
+
language?: string;
|
|
72
|
+
/** 音频 MIME 类型,例如 `audio/ogg`。 */
|
|
73
|
+
media_type?: string;
|
|
74
|
+
/** 原始文件名,供 provider 推断音频格式。 */
|
|
75
|
+
filename?: string;
|
|
76
|
+
/** Provider 私有参数,例如 `{ openai: {...}, groq: {...} }`。 */
|
|
77
|
+
provider_options?: JsonObject;
|
|
78
|
+
/** 允许 FED ASR action 接收其他 JSON 可序列化参数。 */
|
|
79
|
+
[key: string]: JsonValue | undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* ASR 输出。
|
|
84
|
+
*
|
|
85
|
+
* 说明(中文)
|
|
86
|
+
* - 只保留 AI SDK `TranscriptionResult` 中适合 JSON 传输的核心字段。
|
|
87
|
+
* - warnings、responses 与 providerMetadata 属于运行期诊断信息,不进入 plugin action 协议。
|
|
88
|
+
*/
|
|
89
|
+
export interface SoundPluginAsrResult {
|
|
90
|
+
/** 完整转写文本。 */
|
|
91
|
+
text: string;
|
|
92
|
+
/** 带开始和结束时间的转写分段。 */
|
|
93
|
+
segments?: SoundPluginAsrSegment[];
|
|
94
|
+
/** 检测到的 ISO-639-1 语言代码。 */
|
|
95
|
+
language?: string;
|
|
96
|
+
/** 音频总时长,单位为秒。 */
|
|
97
|
+
durationInSeconds?: number;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* TTS 输入。
|
|
102
|
+
*/
|
|
103
|
+
export interface SoundPluginTtsInput {
|
|
104
|
+
/** 支持 TTS 的 FED 模型 ID;未提供时使用 `default_tts_model`。 */
|
|
105
|
+
model?: string;
|
|
106
|
+
/** 需要合成为语音的文本。 */
|
|
107
|
+
text: string;
|
|
108
|
+
/** 语言提示,例如 `auto`、`zh` 或 `en`。 */
|
|
109
|
+
language?: string;
|
|
110
|
+
/** 音色名称或上游 provider 的 voice ID。 */
|
|
111
|
+
voice?: string;
|
|
112
|
+
/** 输出音频格式,例如 `mp3`、`wav` 或 `opus`。 */
|
|
113
|
+
format?: string;
|
|
114
|
+
/** 语速倍率。 */
|
|
115
|
+
speed?: number;
|
|
116
|
+
/** 对语气、风格或发音方式的额外说明。 */
|
|
117
|
+
instructions?: string;
|
|
118
|
+
/** Provider 私有参数,例如 `{ openai: {...}, elevenlabs: {...} }`。 */
|
|
119
|
+
provider_options?: JsonObject;
|
|
120
|
+
/** 允许 FED TTS action 接收其他 JSON 可序列化参数。 */
|
|
121
|
+
[key: string]: JsonValue | undefined;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* TTS 输出。
|
|
126
|
+
*
|
|
127
|
+
* 音频通过 AI SDK `UIMessage` 的 file part 返回。
|
|
128
|
+
*/
|
|
129
|
+
export type SoundPluginTtsResult = UIMessage;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* SoundPlugin 构造参数。
|
|
133
|
+
*/
|
|
134
|
+
export interface SoundPluginOptions {
|
|
135
|
+
/** Plugin 稳定名称,默认 `sound`。 */
|
|
136
|
+
name?: string;
|
|
137
|
+
/** Plugin 展示标题,默认 `Sound`。 */
|
|
138
|
+
title?: string;
|
|
139
|
+
/** Plugin 用途说明。 */
|
|
140
|
+
description?: string;
|
|
141
|
+
/** 未显式传入 ASR 模型时使用的 FED 模型 ID。 */
|
|
142
|
+
default_asr_model?: string;
|
|
143
|
+
/** 未显式传入 TTS 模型时使用的 FED 模型 ID。 */
|
|
144
|
+
default_tts_model?: string;
|
|
145
|
+
/** 是否自动转写 chat 入站的 voice/audio 附件,默认 `false`。 */
|
|
146
|
+
auto_asr?: boolean;
|
|
147
|
+
/** ASR 与 TTS 共用的默认语言提示。 */
|
|
148
|
+
language?: string;
|
|
149
|
+
/** TTS 默认音色。 */
|
|
150
|
+
voice?: string;
|
|
151
|
+
/** TTS 默认输出格式。 */
|
|
152
|
+
format?: string;
|
|
153
|
+
/** 调用 FED ASR action 的函数,通常传入 `(input) => city.ai.asr(input)`。 */
|
|
154
|
+
asr: (
|
|
155
|
+
input: SoundPluginAsrInput,
|
|
156
|
+
) => Promise<SoundPluginAsrResult> | SoundPluginAsrResult;
|
|
157
|
+
/** 调用 FED TTS action 的函数,通常传入 `(input) => city.ai.tts(input)`。 */
|
|
158
|
+
tts: (
|
|
159
|
+
input: SoundPluginTtsInput,
|
|
160
|
+
) => Promise<SoundPluginTtsResult> | SoundPluginTtsResult;
|
|
161
|
+
/** 列出 FED 中支持 ASR 或 TTS 的模型。 */
|
|
162
|
+
list_models?: () => Promise<SoundPluginModel[]> | SoundPluginModel[];
|
|
163
|
+
}
|
package/src/task/Action.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import type { ShipTaskStatus } from "./types/Task.js";
|
|
11
11
|
import type { AgentContext } from "@downcity/agent";
|
|
12
|
+
import type { PluginRunContext } from "@downcity/agent";
|
|
12
13
|
import type { JsonValue } from "@downcity/agent";
|
|
13
14
|
import {
|
|
14
15
|
deriveTaskIdFromTitle,
|
|
@@ -322,6 +323,7 @@ export async function runTaskDefinition(params: {
|
|
|
322
323
|
context: AgentContext;
|
|
323
324
|
projectRoot: string;
|
|
324
325
|
request: TaskRunRequest;
|
|
326
|
+
run_context?: PluginRunContext;
|
|
325
327
|
}): Promise<TaskRunResponse> {
|
|
326
328
|
const root = path.resolve(params.projectRoot);
|
|
327
329
|
const title = String(params.request.title || "").trim();
|
|
@@ -360,6 +362,12 @@ export async function runTaskDefinition(params: {
|
|
|
360
362
|
taskId,
|
|
361
363
|
trigger,
|
|
362
364
|
executionId,
|
|
365
|
+
...(params.run_context?.agentEnv
|
|
366
|
+
? { agent_env: { ...params.run_context.agentEnv } }
|
|
367
|
+
: {}),
|
|
368
|
+
...(params.run_context?.agentSystems
|
|
369
|
+
? { agent_systems: [...params.run_context.agentSystems] }
|
|
370
|
+
: {}),
|
|
363
371
|
})
|
|
364
372
|
.then((result) => {
|
|
365
373
|
params.context.logger.info(
|
|
@@ -80,6 +80,10 @@ export async function runTaskNow(params: {
|
|
|
80
80
|
trigger: ShipTaskRunTriggerV1;
|
|
81
81
|
executionId?: string;
|
|
82
82
|
projectRoot?: string;
|
|
83
|
+
/** 发起该任务的 Session step 已提交生效的 env 快照。 */
|
|
84
|
+
agent_env?: Readonly<Record<string, string>>;
|
|
85
|
+
/** 发起该任务的 Session step 已提交生效的 instruction 快照。 */
|
|
86
|
+
agent_systems?: readonly string[];
|
|
83
87
|
}): Promise<{
|
|
84
88
|
ok: boolean;
|
|
85
89
|
status: ShipTaskRunStatusV1;
|
|
@@ -148,19 +152,6 @@ export async function runTaskNow(params: {
|
|
|
148
152
|
|
|
149
153
|
const runSessionId = createTaskRunSessionId(task.taskId, timestamp);
|
|
150
154
|
const userSimulatorSessionId = `task-user-sim:${task.taskId}:${timestamp}`;
|
|
151
|
-
const taskModel = await context.session.resolveModel(task.frontmatter.sessionId);
|
|
152
|
-
if (!taskModel) {
|
|
153
|
-
throw new Error(
|
|
154
|
-
`Task "${task.taskId}" requires a configured model on session "${task.frontmatter.sessionId}"`,
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
const taskSessionRuntime = createTaskSessionRuntimePort({
|
|
158
|
-
context,
|
|
159
|
-
model: taskModel,
|
|
160
|
-
runDirAbs,
|
|
161
|
-
runSessionId,
|
|
162
|
-
userSimulatorSessionId,
|
|
163
|
-
});
|
|
164
155
|
|
|
165
156
|
let ok = false;
|
|
166
157
|
let status: ShipTaskRunStatusV1 = "failure";
|
|
@@ -194,6 +185,21 @@ export async function runTaskNow(params: {
|
|
|
194
185
|
outputText = scriptResult.outputText;
|
|
195
186
|
errorText = scriptResult.errorText;
|
|
196
187
|
} else {
|
|
188
|
+
const task_model = context.sessions
|
|
189
|
+
.runtime(task.frontmatter.sessionId)
|
|
190
|
+
.getModel();
|
|
191
|
+
if (!task_model) {
|
|
192
|
+
throw new Error(`Task "${task.taskId}" requires a configured model`);
|
|
193
|
+
}
|
|
194
|
+
const taskSessionRuntime = createTaskSessionRuntimePort({
|
|
195
|
+
context,
|
|
196
|
+
model: task_model,
|
|
197
|
+
runDirAbs,
|
|
198
|
+
runSessionId,
|
|
199
|
+
userSimulatorSessionId,
|
|
200
|
+
...(params.agent_env ? { agent_env: params.agent_env } : {}),
|
|
201
|
+
...(params.agent_systems ? { agent_systems: params.agent_systems } : {}),
|
|
202
|
+
});
|
|
197
203
|
let lastRoundRuleErrors: string[] = [];
|
|
198
204
|
let lastRoundDecision: UserSimulatorDecision | null = null;
|
|
199
205
|
let lastFeedback = "";
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { AgentContext } from "@downcity/agent";
|
|
10
|
+
import type { PluginRunContext } from "@downcity/agent";
|
|
10
11
|
import type {
|
|
11
12
|
TaskCronRegisterResult,
|
|
12
13
|
TaskListActionPayload,
|
|
@@ -158,11 +159,13 @@ export async function executeTaskCreateAction(params: {
|
|
|
158
159
|
export async function executeTaskRunAction(params: {
|
|
159
160
|
context: AgentContext;
|
|
160
161
|
payload: TaskRunRequest;
|
|
162
|
+
run_context?: PluginRunContext;
|
|
161
163
|
}) {
|
|
162
164
|
const result = await runTaskDefinition({
|
|
163
165
|
context: params.context,
|
|
164
166
|
projectRoot: params.context.rootPath,
|
|
165
167
|
request: params.payload,
|
|
168
|
+
run_context: params.run_context,
|
|
166
169
|
});
|
|
167
170
|
if (!result.success) {
|
|
168
171
|
return {
|
|
@@ -53,7 +53,7 @@ export async function dispatchTaskRunCompletionToChat(params: {
|
|
|
53
53
|
if (!finalText) return;
|
|
54
54
|
|
|
55
55
|
try {
|
|
56
|
-
const sent = await params.context.
|
|
56
|
+
const sent = await params.context.plugins.runAction({
|
|
57
57
|
plugin: "chat",
|
|
58
58
|
action: "send",
|
|
59
59
|
payload: {
|
|
@@ -11,7 +11,6 @@ import fs from "fs-extra";
|
|
|
11
11
|
import type { AgentContext } from "@downcity/agent";
|
|
12
12
|
import { runSandboxCommand } from "@downcity/shell/sandbox/SandboxRunner.js";
|
|
13
13
|
import type { ShellHostContext } from "@downcity/shell/types/ShellHostContext.js";
|
|
14
|
-
import { withShellRunScope } from "@downcity/shell";
|
|
15
14
|
import type { SessionRunResult } from "@downcity/agent";
|
|
16
15
|
import type { SessionRunContext } from "@downcity/agent";
|
|
17
16
|
import type { JsonObject } from "@downcity/agent";
|
|
@@ -22,7 +21,6 @@ import type {
|
|
|
22
21
|
TaskSessionRuntimePort,
|
|
23
22
|
UserSimulatorDecision,
|
|
24
23
|
} from "@/task/runtime/TaskRunnerTypes.js";
|
|
25
|
-
import { withSessionRunScope } from "@downcity/agent";
|
|
26
24
|
import { appendTaskRoundUserMessage } from "./TaskRunnerSession.js";
|
|
27
25
|
|
|
28
26
|
function stripTaskSecretEnv(env: NodeJS.ProcessEnv): void {
|
|
@@ -246,23 +244,12 @@ export async function runAgentRound(params: {
|
|
|
246
244
|
// ignore
|
|
247
245
|
}
|
|
248
246
|
|
|
249
|
-
const result = await
|
|
250
|
-
|
|
247
|
+
const result = await params.taskSessionRuntime
|
|
248
|
+
.getExecutor(params.sessionId)
|
|
249
|
+
.run({
|
|
250
|
+
query: params.query,
|
|
251
251
|
runContext: create_task_run_context(params.sessionId),
|
|
252
|
-
}
|
|
253
|
-
() =>
|
|
254
|
-
withShellRunScope(
|
|
255
|
-
{
|
|
256
|
-
run_context: {
|
|
257
|
-
session_id: params.sessionId,
|
|
258
|
-
},
|
|
259
|
-
},
|
|
260
|
-
() =>
|
|
261
|
-
params.taskSessionRuntime.getExecutor(params.sessionId).run({
|
|
262
|
-
query: params.query,
|
|
263
|
-
}),
|
|
264
|
-
),
|
|
265
|
-
);
|
|
252
|
+
});
|
|
266
253
|
const outputPick = pickAgentOutput(result.assistantMessage);
|
|
267
254
|
|
|
268
255
|
if (!result.success) {
|
|
@@ -296,26 +283,21 @@ export async function runScriptTask(params: {
|
|
|
296
283
|
const scriptAbs = path.join(params.runDirAbs, "task-script.sh");
|
|
297
284
|
await fs.writeFile(scriptAbs, body.endsWith("\n") ? body : `${body}\n`, "utf-8");
|
|
298
285
|
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
login: false,
|
|
315
|
-
baseEnv: childEnv,
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
);
|
|
286
|
+
const childEnv: NodeJS.ProcessEnv = {
|
|
287
|
+
...process.env,
|
|
288
|
+
DC_SESSION_ID: params.sessionId,
|
|
289
|
+
};
|
|
290
|
+
stripTaskSecretEnv(childEnv);
|
|
291
|
+
const execResult = await runSandboxCommand({
|
|
292
|
+
context: params.context as unknown as ShellHostContext,
|
|
293
|
+
executionId: `task-script:${params.sessionId}`,
|
|
294
|
+
executionDir: params.runDirAbs,
|
|
295
|
+
cmd: `sh "${scriptAbs.replace(/(["\\$`])/g, "\\$1")}"`,
|
|
296
|
+
cwd: params.runDirAbs,
|
|
297
|
+
shellPath: "/bin/sh",
|
|
298
|
+
login: false,
|
|
299
|
+
baseEnv: childEnv,
|
|
300
|
+
});
|
|
319
301
|
|
|
320
302
|
const stdout = String(execResult.stdout || "").trim();
|
|
321
303
|
const stderr = String(execResult.stderr || "").trim();
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* TaskRunnerSession:task runner 的 session 装配模块。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* - 负责构建 task 专用 Executor /
|
|
6
|
-
* - 负责把每轮 user/assistant 消息写入 run 目录对应的
|
|
5
|
+
* - 负责构建 task 专用 Executor / SessionMessages 运行时。
|
|
6
|
+
* - 负责把每轮 user/assistant 消息写入 run 目录对应的 canonical Message Store。
|
|
7
7
|
* - 这些能力与任务编排逻辑解耦后,task 主流程会更聚焦于状态流转。
|
|
8
8
|
* - 当前只有 api 执行模式。
|
|
9
9
|
*/
|
|
@@ -14,14 +14,18 @@ import type { AgentContext } from "@downcity/agent";
|
|
|
14
14
|
import { Executor } from "@downcity/agent";
|
|
15
15
|
import type { SessionRunResult } from "@downcity/agent";
|
|
16
16
|
import type { TaskSessionRuntimePort } from "@/task/runtime/TaskRunnerTypes.js";
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
import {
|
|
18
|
+
DefaultSessionComposer,
|
|
19
|
+
JsonlSessionMessageStore,
|
|
20
|
+
SessionMessages,
|
|
21
|
+
} from "@downcity/agent";
|
|
22
22
|
import { DefaultSessionSystemComposer } from "@downcity/agent";
|
|
23
23
|
import { Shell } from "@downcity/shell";
|
|
24
24
|
import type { SessionExecutor } from "@downcity/agent";
|
|
25
|
+
import type {
|
|
26
|
+
SessionComposeInput,
|
|
27
|
+
SessionStepInput,
|
|
28
|
+
} from "@downcity/agent";
|
|
25
29
|
|
|
26
30
|
/**
|
|
27
31
|
* 把 task round 的 user query 落盘到对应 run context。
|
|
@@ -36,20 +40,18 @@ export async function appendTaskRoundUserMessage(params: {
|
|
|
36
40
|
}): Promise<void> {
|
|
37
41
|
const text = String(params.query || "").trim();
|
|
38
42
|
if (!text) return;
|
|
39
|
-
const
|
|
40
|
-
await
|
|
41
|
-
|
|
43
|
+
const messages = params.taskSessionRuntime.get_messages(params.sessionId);
|
|
44
|
+
await messages.append_user_message({
|
|
45
|
+
turn_id:
|
|
46
|
+
`task:${params.taskId}:${params.actorId}:${Date.now()}`,
|
|
47
|
+
input_type: "prompt",
|
|
48
|
+
parts: [{
|
|
49
|
+
part_id: `task-user:${Date.now()}`,
|
|
50
|
+
type: "text",
|
|
42
51
|
text,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
taskId: params.taskId,
|
|
47
|
-
actorId: params.actorId,
|
|
48
|
-
actorName: params.actorName,
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
}),
|
|
52
|
-
);
|
|
52
|
+
state: "done",
|
|
53
|
+
}],
|
|
54
|
+
});
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
/**
|
|
@@ -65,6 +67,10 @@ export function createTaskSessionRuntimePort(params: {
|
|
|
65
67
|
runDirAbs: string;
|
|
66
68
|
runSessionId: string;
|
|
67
69
|
userSimulatorSessionId: string;
|
|
70
|
+
/** 当前 task 显式继承的 Agent env 快照。 */
|
|
71
|
+
agent_env?: Readonly<Record<string, string>>;
|
|
72
|
+
/** 当前 task 显式继承的 Agent instruction 快照。 */
|
|
73
|
+
agent_systems?: readonly string[];
|
|
68
74
|
}): TaskSessionRuntimePort {
|
|
69
75
|
const {
|
|
70
76
|
context,
|
|
@@ -73,28 +79,33 @@ export function createTaskSessionRuntimePort(params: {
|
|
|
73
79
|
runSessionId,
|
|
74
80
|
userSimulatorSessionId,
|
|
75
81
|
} = params;
|
|
76
|
-
const
|
|
82
|
+
const effective_env = params.agent_env
|
|
83
|
+
? { ...params.agent_env }
|
|
84
|
+
: { ...context.env };
|
|
85
|
+
const effective_systems = params.agent_systems
|
|
86
|
+
? [...params.agent_systems]
|
|
87
|
+
: [...context.systems];
|
|
77
88
|
const systemComposer = new DefaultSessionSystemComposer({
|
|
78
89
|
projectRoot: context.rootPath,
|
|
79
|
-
getStaticSystemPrompts: () =>
|
|
90
|
+
getStaticSystemPrompts: () => [...effective_systems],
|
|
80
91
|
getContext: () => context,
|
|
81
92
|
profile: "task",
|
|
82
93
|
});
|
|
83
|
-
const
|
|
84
|
-
const
|
|
94
|
+
const messages_by_session_id = new Map<string, SessionMessages>();
|
|
95
|
+
const created_at_by_session_id = new Map<string, number>();
|
|
85
96
|
const runtimesBySessionId = new Map<string, SessionExecutor>();
|
|
86
97
|
const shell = new Shell({
|
|
87
98
|
root_path: context.rootPath,
|
|
88
|
-
env:
|
|
99
|
+
env: effective_env,
|
|
89
100
|
logger: context.logger,
|
|
90
101
|
});
|
|
91
102
|
const shell_tools = shell.tools as unknown as Record<string, Tool>;
|
|
92
103
|
|
|
93
|
-
const
|
|
94
|
-
const existing =
|
|
104
|
+
const resolve_task_messages = (session_id: string): SessionMessages => {
|
|
105
|
+
const existing = messages_by_session_id.get(session_id);
|
|
95
106
|
if (existing) return existing;
|
|
96
107
|
|
|
97
|
-
const key = String(
|
|
108
|
+
const key = String(session_id || "").trim();
|
|
98
109
|
if (!key) {
|
|
99
110
|
throw new Error("TaskSessionRuntimePort requires a non-empty sessionId");
|
|
100
111
|
}
|
|
@@ -105,39 +116,45 @@ export function createTaskSessionRuntimePort(params: {
|
|
|
105
116
|
? path.join(runDirAbs, "user-simulator")
|
|
106
117
|
: undefined;
|
|
107
118
|
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
: {}),
|
|
119
|
+
const messages_dir_path = runMessagesDirPath || path.join(runDirAbs, key);
|
|
120
|
+
const created = new SessionMessages({
|
|
121
|
+
session_id: key,
|
|
122
|
+
store: new JsonlSessionMessageStore({
|
|
123
|
+
session_id: key,
|
|
124
|
+
file_path: path.join(messages_dir_path, "active.jsonl"),
|
|
125
|
+
assistant_message_file_path: path.join(
|
|
126
|
+
messages_dir_path,
|
|
127
|
+
"assistant_message.json",
|
|
128
|
+
),
|
|
129
|
+
}),
|
|
130
|
+
publish: () => {},
|
|
122
131
|
});
|
|
123
|
-
|
|
132
|
+
messages_by_session_id.set(key, created);
|
|
133
|
+
created_at_by_session_id.set(key, Date.now());
|
|
124
134
|
return created;
|
|
125
135
|
};
|
|
126
136
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
+
class TaskSessionComposer extends DefaultSessionComposer {
|
|
138
|
+
override async compose(input: SessionComposeInput): Promise<SessionStepInput> {
|
|
139
|
+
const composed = await super.compose(input);
|
|
140
|
+
return {
|
|
141
|
+
...composed,
|
|
142
|
+
system: await systemComposer.resolve({
|
|
143
|
+
sessionId: input.session.session_id,
|
|
144
|
+
agentEnv: input.state.env,
|
|
145
|
+
agentSystems: input.state.systems,
|
|
146
|
+
injectedUserMessages: [],
|
|
147
|
+
deferredPersistedUserMessages: [],
|
|
148
|
+
pendingAssistantFileParts: [],
|
|
149
|
+
}),
|
|
150
|
+
system_blocks: undefined,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
137
154
|
|
|
138
155
|
return {
|
|
139
|
-
|
|
140
|
-
return
|
|
156
|
+
get_messages(session_id: string): SessionMessages {
|
|
157
|
+
return resolve_task_messages(session_id);
|
|
141
158
|
},
|
|
142
159
|
getExecutor(sessionId: string): SessionExecutor {
|
|
143
160
|
const key = String(sessionId || "").trim();
|
|
@@ -147,23 +164,42 @@ export function createTaskSessionRuntimePort(params: {
|
|
|
147
164
|
const existing = runtimesBySessionId.get(key);
|
|
148
165
|
if (existing) return existing;
|
|
149
166
|
|
|
150
|
-
const
|
|
151
|
-
const
|
|
152
|
-
const contextComposer = new LocalSessionContextComposer({
|
|
153
|
-
sessionId: key,
|
|
154
|
-
getTools: () => shell_tools,
|
|
155
|
-
});
|
|
167
|
+
const messages = resolve_task_messages(key);
|
|
168
|
+
const composer = new TaskSessionComposer();
|
|
156
169
|
const created = new Executor({
|
|
157
170
|
sessionId: key,
|
|
171
|
+
composer,
|
|
172
|
+
get_compose_input: async (run_context, retry_count) => ({
|
|
173
|
+
session: {
|
|
174
|
+
agent_id: "task",
|
|
175
|
+
session_id: key,
|
|
176
|
+
project_root: context.rootPath,
|
|
177
|
+
created_at: created_at_by_session_id.get(key) || Date.now(),
|
|
178
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC",
|
|
179
|
+
},
|
|
180
|
+
state: {
|
|
181
|
+
model,
|
|
182
|
+
env: effective_env,
|
|
183
|
+
systems: effective_systems,
|
|
184
|
+
tools: shell_tools,
|
|
185
|
+
instruction_system_blocks: [],
|
|
186
|
+
managed_plugin_system_blocks: [],
|
|
187
|
+
plugin_system_blocks: [],
|
|
188
|
+
},
|
|
189
|
+
history: await messages.context_snapshot(),
|
|
190
|
+
turn: {
|
|
191
|
+
...(run_context.turnId ? { turn_id: run_context.turnId } : {}),
|
|
192
|
+
retry_count,
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
195
|
+
commit_compaction: async (plan) => {
|
|
196
|
+
await messages.compact_active({
|
|
197
|
+
through_sequence: plan.through_sequence,
|
|
198
|
+
summary: plan.summary,
|
|
199
|
+
});
|
|
200
|
+
},
|
|
158
201
|
getModel: () => model,
|
|
159
202
|
logger: context.logger,
|
|
160
|
-
historyStore,
|
|
161
|
-
historyComposer,
|
|
162
|
-
compactionComposer,
|
|
163
|
-
contextComposer,
|
|
164
|
-
systemComposer,
|
|
165
|
-
getTools: () => shell_tools,
|
|
166
|
-
getEnv: () => ({ ...context.env }),
|
|
167
203
|
});
|
|
168
204
|
runtimesBySessionId.set(key, created);
|
|
169
205
|
return created;
|
|
@@ -181,12 +217,12 @@ export async function appendTaskAssistantMessage(params: {
|
|
|
181
217
|
rawResult: SessionRunResult;
|
|
182
218
|
}): Promise<void> {
|
|
183
219
|
const { taskSessionRuntime, sessionId, rawResult } = params;
|
|
184
|
-
const
|
|
220
|
+
const messages = taskSessionRuntime.get_messages(sessionId);
|
|
185
221
|
if (rawResult.assistantMessage) {
|
|
186
|
-
await
|
|
222
|
+
await messages.append_record(rawResult.assistantMessage);
|
|
187
223
|
}
|
|
188
|
-
const deferredUserMessages =
|
|
224
|
+
const deferredUserMessages = rawResult.deferredPersistedUserMessages || [];
|
|
189
225
|
for (const deferred of deferredUserMessages) {
|
|
190
|
-
await
|
|
226
|
+
await messages.append_record(deferred);
|
|
191
227
|
}
|
|
192
228
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* - 这些类型服务于 task 运行链路,统一归档到 `src/types/task/`。
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type { SessionMessages } from "@downcity/agent";
|
|
10
10
|
import type { SessionExecutor } from "@downcity/agent";
|
|
11
11
|
import type {
|
|
12
12
|
ShipTaskRunExecutionStatusV1,
|
|
@@ -171,7 +171,7 @@ export type ScriptExecutionResult = {
|
|
|
171
171
|
*
|
|
172
172
|
* 关键点(中文)
|
|
173
173
|
* - task runner 不直接依赖具体 SDK `Session` 实现。
|
|
174
|
-
* - 这里暴露的是 task 场景最小可用端口:执行器 +
|
|
174
|
+
* - 这里暴露的是 task 场景最小可用端口:执行器 + canonical Messages。
|
|
175
175
|
*/
|
|
176
176
|
export type TaskSessionRuntimePort = {
|
|
177
177
|
/**
|
|
@@ -179,9 +179,9 @@ export type TaskSessionRuntimePort = {
|
|
|
179
179
|
*/
|
|
180
180
|
getExecutor(sessionId: string): SessionExecutor;
|
|
181
181
|
/**
|
|
182
|
-
* 获取指定 sessionId 对应的
|
|
182
|
+
* 获取指定 sessionId 对应的 canonical Session Messages。
|
|
183
183
|
*/
|
|
184
|
-
|
|
184
|
+
get_messages(session_id: string): SessionMessages;
|
|
185
185
|
};
|
|
186
186
|
|
|
187
187
|
/**
|