@jingyi0605/codingns4dsh 0.2.1-beta.8 → 0.2.1-beta.9
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.en.md +3 -3
- package/README.md +7 -3
- package/data/build/dist/bootstrap/dsh-peer-host-preboot-shim.d.ts.map +1 -1
- package/data/build/dist/bootstrap/dsh-peer-host-preboot-shim.js +26 -1
- package/data/build/dist/bootstrap/dsh-peer-host-preboot-shim.js.map +1 -1
- package/data/build/dist/client/account-bar.d.ts.map +1 -1
- package/data/build/dist/client/account-bar.js +33 -21
- package/data/build/dist/client/account-bar.js.map +1 -1
- package/data/build/dist/client/avatar/desktop-bridge.js +1 -1
- package/data/build/dist/client/avatar/desktop-bridge.js.map +1 -1
- package/data/build/dist/client/avatar/desktop-view.d.ts +3 -1
- package/data/build/dist/client/avatar/desktop-view.d.ts.map +1 -1
- package/data/build/dist/client/avatar/desktop-view.js +31 -12
- package/data/build/dist/client/avatar/desktop-view.js.map +1 -1
- package/data/build/dist/client/avatar/notification-bubble.d.ts +7 -1
- package/data/build/dist/client/avatar/notification-bubble.d.ts.map +1 -1
- package/data/build/dist/client/avatar/notification-bubble.js +68 -33
- package/data/build/dist/client/avatar/notification-bubble.js.map +1 -1
- package/data/build/dist/client/bundle.js +1626 -303
- package/data/build/dist/client/bundle.js.map +1 -1
- package/data/build/dist/client/cli-slots.d.ts.map +1 -1
- package/data/build/dist/client/cli-slots.js +26 -2
- package/data/build/dist/client/cli-slots.js.map +1 -1
- package/data/build/dist/client/client.assistant-notifications.js.map +1 -1
- package/data/build/dist/client/client.delegate-command.js +6 -6
- package/data/build/dist/client/client.delegate-command.js.map +1 -1
- package/data/build/dist/client/client.native-workspace-store.js +39 -3
- package/data/build/dist/client/client.native-workspace-store.js.map +1 -1
- package/data/build/dist/client/client.session-translation.js +54 -0
- package/data/build/dist/client/client.session-translation.js.map +1 -0
- package/data/build/dist/client/client.transport.js +86 -2
- package/data/build/dist/client/client.transport.js.map +1 -1
- package/data/build/dist/client/desktop-assistant.js +217 -61
- package/data/build/dist/client/features/assistant-notification-store.d.ts +1 -1
- package/data/build/dist/client/features/assistant-notification-store.d.ts.map +1 -1
- package/data/build/dist/client/features/assistant-notification-store.js +1 -1
- package/data/build/dist/client/features/assistant-notification-store.js.map +1 -1
- package/data/build/dist/client/features/global-voice-assistant.d.ts.map +1 -1
- package/data/build/dist/client/features/global-voice-assistant.js +12 -6
- package/data/build/dist/client/features/global-voice-assistant.js.map +1 -1
- package/data/build/dist/client/features/index.d.ts +1 -0
- package/data/build/dist/client/features/index.d.ts.map +1 -1
- package/data/build/dist/client/features/index.js +3 -0
- package/data/build/dist/client/features/index.js.map +1 -1
- package/data/build/dist/client/features/peer-host.d.ts.map +1 -1
- package/data/build/dist/client/features/peer-host.js +99 -17
- package/data/build/dist/client/features/peer-host.js.map +1 -1
- package/data/build/dist/client/features/session-translation.d.ts +3 -0
- package/data/build/dist/client/features/session-translation.d.ts.map +1 -0
- package/data/build/dist/client/features/session-translation.js +116 -0
- package/data/build/dist/client/features/session-translation.js.map +1 -0
- package/data/build/dist/client/index.d.ts.map +1 -1
- package/data/build/dist/client/index.js +6 -1
- package/data/build/dist/client/index.js.map +1 -1
- package/data/build/dist/client/locales/panels.d.ts.map +1 -1
- package/data/build/dist/client/locales/panels.js +62 -0
- package/data/build/dist/client/locales/panels.js.map +1 -1
- package/data/build/dist/client/session-file-links.d.ts +11 -0
- package/data/build/dist/client/session-file-links.d.ts.map +1 -0
- package/data/build/dist/client/{peer-host-file-links.js → session-file-links.js} +13 -3
- package/data/build/dist/client/session-file-links.js.map +1 -0
- package/data/build/dist/client/session-translation-chat.d.ts +6 -0
- package/data/build/dist/client/session-translation-chat.d.ts.map +1 -0
- package/data/build/dist/client/session-translation-chat.js +686 -0
- package/data/build/dist/client/session-translation-chat.js.map +1 -0
- package/data/build/dist/client/workspace-session-visibility-dom.d.ts.map +1 -1
- package/data/build/dist/client/workspace-session-visibility-dom.js +23 -7
- package/data/build/dist/client/workspace-session-visibility-dom.js.map +1 -1
- package/data/build/dist/dsh-capabilities/client/assistant-session-navigation-adapter.d.ts +1 -1
- package/data/build/dist/dsh-capabilities/client/assistant-session-navigation-adapter.d.ts.map +1 -1
- package/data/build/dist/dsh-capabilities/client/assistant-session-navigation-adapter.js +28 -2
- package/data/build/dist/dsh-capabilities/client/assistant-session-navigation-adapter.js.map +1 -1
- package/data/build/dist/host/cli-adapters/acp-cli-driver.d.ts +21 -0
- package/data/build/dist/host/cli-adapters/acp-cli-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/acp-cli-driver.js +100 -3
- package/data/build/dist/host/cli-adapters/acp-cli-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/codex-driver.d.ts +10 -1
- package/data/build/dist/host/cli-adapters/codex-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/codex-driver.js +73 -14
- package/data/build/dist/host/cli-adapters/codex-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/command-code-acp-loader.d.ts +8 -1
- package/data/build/dist/host/cli-adapters/command-code-acp-loader.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/command-code-acp-loader.js +45 -2
- package/data/build/dist/host/cli-adapters/command-code-acp-loader.js.map +1 -1
- package/data/build/dist/host/cli-adapters/command-code-driver.d.ts +8 -2
- package/data/build/dist/host/cli-adapters/command-code-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/command-code-driver.js +32 -3
- package/data/build/dist/host/cli-adapters/command-code-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/command-code-history.d.ts +27 -0
- package/data/build/dist/host/cli-adapters/command-code-history.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/command-code-history.js +131 -1
- package/data/build/dist/host/cli-adapters/command-code-history.js.map +1 -1
- package/data/build/dist/host/cli-adapters/delegation-mention-rewrite.js +9 -9
- package/data/build/dist/host/cli-adapters/delegation-mention-rewrite.js.map +1 -1
- package/data/build/dist/host/cli-adapters/dsh-message-projector.d.ts +11 -0
- package/data/build/dist/host/cli-adapters/dsh-message-projector.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/dsh-message-projector.js +79 -7
- package/data/build/dist/host/cli-adapters/dsh-message-projector.js.map +1 -1
- package/data/build/dist/host/cli-adapters/feature.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/feature.js +286 -19
- package/data/build/dist/host/cli-adapters/feature.js.map +1 -1
- package/data/build/dist/host/cli-adapters/grok-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/grok-driver.js +108 -47
- package/data/build/dist/host/cli-adapters/grok-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/legacy-session-settings.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/legacy-session-settings.js +7 -2
- package/data/build/dist/host/cli-adapters/legacy-session-settings.js.map +1 -1
- package/data/build/dist/host/cli-adapters/opencode-driver.d.ts +4 -2
- package/data/build/dist/host/cli-adapters/opencode-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/opencode-driver.js +78 -31
- package/data/build/dist/host/cli-adapters/opencode-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/opencode-v2-protocol.d.ts +1 -1
- package/data/build/dist/host/cli-adapters/opencode-v2-protocol.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/opencode-v2-protocol.js +63 -6
- package/data/build/dist/host/cli-adapters/opencode-v2-protocol.js.map +1 -1
- package/data/build/dist/host/cli-adapters/provider-subscription.d.ts +5 -1
- package/data/build/dist/host/cli-adapters/provider-subscription.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/provider-subscription.js +90 -25
- package/data/build/dist/host/cli-adapters/provider-subscription.js.map +1 -1
- package/data/build/dist/host/cli-adapters/registry.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/registry.js +22 -5
- package/data/build/dist/host/cli-adapters/registry.js.map +1 -1
- package/data/build/dist/host/cli-adapters/session-store.d.ts +1 -0
- package/data/build/dist/host/cli-adapters/session-store.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/session-store.js +3 -0
- package/data/build/dist/host/cli-adapters/session-store.js.map +1 -1
- package/data/build/dist/host/cli-bridge/bridge-server.js +2 -2
- package/data/build/dist/host/cli-bridge/bridge-server.js.map +1 -1
- package/data/build/dist/host/cli-bridge/command-code-mod.js +21 -21
- package/data/build/dist/host/cli-bridge/command-code-mod.js.map +1 -1
- package/data/build/dist/host/cli-bridge/dispatch.js +19 -19
- package/data/build/dist/host/cli-bridge/dispatch.js.map +1 -1
- package/data/build/dist/host/cli-bridge/injections.d.ts +32 -0
- package/data/build/dist/host/cli-bridge/injections.d.ts.map +1 -1
- package/data/build/dist/host/cli-bridge/injections.js +137 -1
- package/data/build/dist/host/cli-bridge/injections.js.map +1 -1
- package/data/build/dist/host/cli-bridge/mcp-stdio-entry.js +20 -20
- package/data/build/dist/host/cli-bridge/mcp-stdio-entry.js.map +1 -1
- package/data/build/dist/host/desktop-assistant/controller.d.ts +1 -0
- package/data/build/dist/host/desktop-assistant/controller.d.ts.map +1 -1
- package/data/build/dist/host/desktop-assistant/controller.js +21 -3
- package/data/build/dist/host/desktop-assistant/controller.js.map +1 -1
- package/data/build/dist/host/desktop-assistant/mac-agent.d.ts.map +1 -1
- package/data/build/dist/host/desktop-assistant/mac-agent.js +15 -3
- package/data/build/dist/host/desktop-assistant/mac-agent.js.map +1 -1
- package/data/build/dist/host/desktop-assistant/win-agent.d.ts.map +1 -1
- package/data/build/dist/host/desktop-assistant/win-agent.js +21 -3
- package/data/build/dist/host/desktop-assistant/win-agent.js.map +1 -1
- package/data/build/dist/host/features/assistant-notifications.d.ts.map +1 -1
- package/data/build/dist/host/features/assistant-notifications.js +12 -4
- package/data/build/dist/host/features/assistant-notifications.js.map +1 -1
- package/data/build/dist/host/features/index.d.ts +1 -0
- package/data/build/dist/host/features/index.d.ts.map +1 -1
- package/data/build/dist/host/features/index.js +3 -0
- package/data/build/dist/host/features/index.js.map +1 -1
- package/data/build/dist/host/features/peer-host.d.ts.map +1 -1
- package/data/build/dist/host/features/peer-host.js +11 -4
- package/data/build/dist/host/features/peer-host.js.map +1 -1
- package/data/build/dist/host/features/session-translation-service.d.ts +31 -0
- package/data/build/dist/host/features/session-translation-service.d.ts.map +1 -0
- package/data/build/dist/host/features/session-translation-service.js +451 -0
- package/data/build/dist/host/features/session-translation-service.js.map +1 -0
- package/data/build/dist/host/features/session-translation.d.ts +5 -0
- package/data/build/dist/host/features/session-translation.d.ts.map +1 -0
- package/data/build/dist/host/features/session-translation.js +37 -0
- package/data/build/dist/host/features/session-translation.js.map +1 -0
- package/data/build/dist/host/features/types.d.ts +3 -0
- package/data/build/dist/host/features/types.d.ts.map +1 -1
- package/data/build/dist/host/image-artifact-store.d.ts +21 -0
- package/data/build/dist/host/image-artifact-store.d.ts.map +1 -0
- package/data/build/dist/host/image-artifact-store.js +136 -0
- package/data/build/dist/host/image-artifact-store.js.map +1 -0
- package/data/build/dist/host/index.d.ts.map +1 -1
- package/data/build/dist/host/index.js +3 -0
- package/data/build/dist/host/index.js.map +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-native-protocol.d.ts +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-native-protocol.d.ts.map +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-native-protocol.js +2 -0
- package/data/build/dist/host/modules/peer-host/peer-host-native-protocol.js.map +1 -1
- package/data/build/dist/host/native-session-bridge.d.ts +16 -1
- package/data/build/dist/host/native-session-bridge.d.ts.map +1 -1
- package/data/build/dist/host/native-session-bridge.js +47 -0
- package/data/build/dist/host/native-session-bridge.js.map +1 -1
- package/data/build/dist/host/rpc.js +3 -3
- package/data/build/dist/host/rpc.js.map +1 -1
- package/data/build/dist/host/session-changes.d.ts.map +1 -1
- package/data/build/dist/host/session-changes.js +196 -13
- package/data/build/dist/host/session-changes.js.map +1 -1
- package/data/build/dist/host/settings.d.ts.map +1 -1
- package/data/build/dist/host/settings.js +8 -0
- package/data/build/dist/host/settings.js.map +1 -1
- package/data/build/dist/shared/assistant-notifications.d.ts +2 -2
- package/data/build/dist/shared/assistant-notifications.d.ts.map +1 -1
- package/data/build/dist/shared/contracts/cli-adapter.d.ts +25 -2
- package/data/build/dist/shared/contracts/cli-adapter.d.ts.map +1 -1
- package/data/build/dist/shared/contracts/config.d.ts +6 -0
- package/data/build/dist/shared/contracts/config.d.ts.map +1 -1
- package/data/build/dist/shared/contracts/config.js +3 -0
- package/data/build/dist/shared/contracts/config.js.map +1 -1
- package/data/build/dist/shared/contracts/session-translation.d.ts +58 -0
- package/data/build/dist/shared/contracts/session-translation.d.ts.map +1 -0
- package/data/build/dist/shared/contracts/session-translation.js +23 -0
- package/data/build/dist/shared/contracts/session-translation.js.map +1 -0
- package/data/build/dist/shared/contracts/version.d.ts +1 -1
- package/data/build/dist/shared/contracts/version.js +1 -1
- package/data/build/dist/shared/delegation-carrier.js +6 -6
- package/data/build/dist/shared/delegation-carrier.js.map +1 -1
- package/data/build/dist/shared/desktop-assistant.d.ts +10 -4
- package/data/build/dist/shared/desktop-assistant.d.ts.map +1 -1
- package/data/build/dist/shared/desktop-assistant.js +28 -8
- package/data/build/dist/shared/desktop-assistant.js.map +1 -1
- package/data/build/dist/shared/index.d.ts +2 -1
- package/data/build/dist/shared/index.d.ts.map +1 -1
- package/data/build/dist/shared/index.js +2 -1
- package/data/build/dist/shared/index.js.map +1 -1
- package/package.json +2 -2
- package/profile/README.md +2 -2
- package/profile/package.json +2 -2
- package/profile/version.json +1 -1
- package/version.json +1 -1
- package/data/build/dist/client/peer-host-file-links.d.ts +0 -8
- package/data/build/dist/client/peer-host-file-links.d.ts.map +0 -1
- package/data/build/dist/client/peer-host-file-links.js.map +0 -1
|
@@ -31,6 +31,7 @@ import { containsDelegationCarrier, delegationAdapterIds, rewriteDelegationMessa
|
|
|
31
31
|
import { clearDelegationAuthorization, setDelegationAuthorization } from './delegation-authorization.js';
|
|
32
32
|
import { debugInfo } from '../../shared/debug.js';
|
|
33
33
|
import { hasLegacySessionAdapterHint } from './legacy-session-adapter.js';
|
|
34
|
+
import {} from '../../shared/contracts/session-translation.js';
|
|
34
35
|
export function createCliAdaptersFeature(options = {}) {
|
|
35
36
|
return {
|
|
36
37
|
descriptor: {
|
|
@@ -53,6 +54,7 @@ export function createCliAdaptersFeature(options = {}) {
|
|
|
53
54
|
const sessionStore = options.registry?.sessionRecords
|
|
54
55
|
?? new CodingNsCliSessionStore(context.services.settings === undefined ? {} : { settings: context.services.settings });
|
|
55
56
|
const nativeSessions = context.services.nativeSessions;
|
|
57
|
+
const translation = context.services.sessionTranslation;
|
|
56
58
|
// 启动只恢复持久化索引;旧会话在打开时迁移,禁止在首屏扫描全部历史。
|
|
57
59
|
const registry = options.registry ?? new CodingNsCliAdapterRegistry([
|
|
58
60
|
new CommandCodeDriver({ enableAcp: true }),
|
|
@@ -60,7 +62,7 @@ export function createCliAdaptersFeature(options = {}) {
|
|
|
60
62
|
new KimiCliDriver(),
|
|
61
63
|
new GeminiCliDriver(),
|
|
62
64
|
new PiAgentDriver(),
|
|
63
|
-
new CodexAppServerDriver(),
|
|
65
|
+
new CodexAppServerDriver({ computerUse: 'auto' }),
|
|
64
66
|
new OpenCodeDriver(),
|
|
65
67
|
new GrokBuildDriver(),
|
|
66
68
|
new MiniMaxCodeDriver(),
|
|
@@ -128,7 +130,7 @@ export function createCliAdaptersFeature(options = {}) {
|
|
|
128
130
|
});
|
|
129
131
|
context.resources.add(disposeNativeEvents);
|
|
130
132
|
}
|
|
131
|
-
registerDelegationAgentHooks(context.services.dshContext, registry, context.resources, publishExternalStatus);
|
|
133
|
+
registerDelegationAgentHooks(context.services.dshContext, registry, context.resources, publishExternalStatus, translation);
|
|
132
134
|
context.resources.add(context.services.rpc.register('cli', (action, payload) => {
|
|
133
135
|
switch (action) {
|
|
134
136
|
case 'catalog': return registry.catalog();
|
|
@@ -140,6 +142,7 @@ export function createCliAdaptersFeature(options = {}) {
|
|
|
140
142
|
const adapterId = readAdapterId(payload);
|
|
141
143
|
return adapterId === 'dsh' ? readDshModelCatalog(context.services.dshContext) : registry.models(adapterId);
|
|
142
144
|
}
|
|
145
|
+
case 'translation/models': return context.services.sessionTranslation?.catalog() ?? { models: [], default: null, errors: ['翻译模型目录不可用'] };
|
|
143
146
|
case 'skills': {
|
|
144
147
|
const request = readSkillsRequest(payload);
|
|
145
148
|
const cwd = resolveSessionCwd(context.services.nativeSessions, request.sessionId, null);
|
|
@@ -163,8 +166,8 @@ export function createCliAdaptersFeature(options = {}) {
|
|
|
163
166
|
// 列表查询只返回持久化索引,不能触发会话加载或历史解析。
|
|
164
167
|
return sessionStore.adapterBindings();
|
|
165
168
|
case 'session/archive': return registry.archiveSession(readSessionId(payload));
|
|
166
|
-
case 'session/steer': return registry
|
|
167
|
-
case 'session/follow-up': return registry
|
|
169
|
+
case 'session/steer': return translateSteerPrompt(translation, registry, readSessionId(payload), readPrompt(payload), false);
|
|
170
|
+
case 'session/follow-up': return translateSteerPrompt(translation, registry, readSessionId(payload), readPrompt(payload), true);
|
|
168
171
|
case 'session/interrupt': return registry.interrupt(readSessionId(payload));
|
|
169
172
|
case 'team/status': return context.services.nativeTeam?.diagnostic() ?? registry.teamDiagnostic();
|
|
170
173
|
case 'team/members': return requireTeam(context).invoke('members', payload);
|
|
@@ -268,6 +271,12 @@ export function createCliAdaptersFeature(options = {}) {
|
|
|
268
271
|
if (events !== undefined) {
|
|
269
272
|
const dispose = events.on('llm/stream', async function* (options, next) {
|
|
270
273
|
const value = asRecord(options);
|
|
274
|
+
// 翻译服务也复用 DSH 原生 LLM,但它不是外部 Agent 回合;必须在这里
|
|
275
|
+
// 旁路 CLI Provider 接管,否则翻译请求会被再次当成 Grok/Codex 请求。
|
|
276
|
+
if (isSessionTranslationLlmRequest(value)) {
|
|
277
|
+
yield* next();
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
271
280
|
const sessionId = typeof value?.sessionId === 'string' ? value.sessionId : '';
|
|
272
281
|
if (value?.purpose === 'session-title' || value?.purpose === 'compaction') {
|
|
273
282
|
yield* next();
|
|
@@ -342,6 +351,20 @@ export function createCliAdaptersFeature(options = {}) {
|
|
|
342
351
|
const turnInput = extractTurnInput(messages, context.services.dshContext);
|
|
343
352
|
const turnOptions = readCliTurnOptions(value);
|
|
344
353
|
const runtimeEnv = readCliRuntimeEnv(value);
|
|
354
|
+
const requestSignal = isAbortSignal(value?.signal) ? value.signal : undefined;
|
|
355
|
+
let translatedPrompt = turnInput.translationPrompt;
|
|
356
|
+
if (turnInput.translatePrompt && translation !== undefined) {
|
|
357
|
+
try {
|
|
358
|
+
translatedPrompt = await translation.translateInput(config.adapterId, turnInput.translationPrompt, requestSignal, config.translationEnabled === true);
|
|
359
|
+
}
|
|
360
|
+
catch {
|
|
361
|
+
// 翻译服务异常不能阻断外部 Agent 主任务;本轮直接发送原文。
|
|
362
|
+
translatedPrompt = turnInput.translationPrompt;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
const prompt = turnInput.translatePrompt
|
|
366
|
+
? [translatedPrompt, turnInput.untranslatedPrompt].filter((part) => part.trim() !== '').join('\n\n')
|
|
367
|
+
: turnInput.prompt;
|
|
345
368
|
// 权限状态必须与 DSH 会话当前生效值同源。驱动不能自行假设“完全权限”,
|
|
346
369
|
// 也不能把缺省当成“已确认无限制”:解析失败时留空,由驱动沿用保守默认。
|
|
347
370
|
const permission = resolveSessionPermission(context.services.dshContext, sessionId);
|
|
@@ -352,7 +375,7 @@ export function createCliAdaptersFeature(options = {}) {
|
|
|
352
375
|
const input = {
|
|
353
376
|
sessionId,
|
|
354
377
|
messages: turnInput.messages,
|
|
355
|
-
prompt
|
|
378
|
+
prompt,
|
|
356
379
|
...(turnInput.attachments.length === 0 ? {} : { attachments: turnInput.attachments }),
|
|
357
380
|
...(permission === undefined ? {} : { permission }),
|
|
358
381
|
...(turnOptions.plan === true ? { plan: true } : {}),
|
|
@@ -362,10 +385,11 @@ export function createCliAdaptersFeature(options = {}) {
|
|
|
362
385
|
...(config.modelId ? { modelId: config.modelId } : {}),
|
|
363
386
|
...(config.effortId ? { effortId: config.effortId } : {}),
|
|
364
387
|
...(config.serviceTierId ? { serviceTierId: config.serviceTierId } : {}),
|
|
388
|
+
...(config.translationEnabled === undefined ? {} : { translationEnabled: config.translationEnabled }),
|
|
365
389
|
...(config.providerSessionId ? { providerSessionId: config.providerSessionId } : {}),
|
|
366
390
|
...(config.rawStoreRef ? { rawStoreRef: config.rawStoreRef } : {}),
|
|
367
391
|
...(cwd === undefined ? {} : { cwd }),
|
|
368
|
-
...(
|
|
392
|
+
...(requestSignal === undefined ? {} : { signal: requestSignal }),
|
|
369
393
|
...((registry.supportsSegmentedTurns(config.adapterId) || registry.supportsToolStepSplitting(config.adapterId))
|
|
370
394
|
// SessionStore/controller 可能是远端代理而未标记 available,但原生
|
|
371
395
|
// Agent 仍然提供 inject;用真实的 next-step 能力决定分段,不能让
|
|
@@ -385,6 +409,8 @@ export function createCliAdaptersFeature(options = {}) {
|
|
|
385
409
|
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
386
410
|
respondPermission: (response) => registry.respondPermission(sessionId, response),
|
|
387
411
|
respondQuestion: (response) => registry.respondQuestion(sessionId, response),
|
|
412
|
+
...(translation === undefined ? {} : { translation }),
|
|
413
|
+
...(translation === undefined ? {} : { translationEnabled: config.translationEnabled === true }),
|
|
388
414
|
});
|
|
389
415
|
const discardSuspendedTurn = () => registry.discardSegmentedTurn(sessionId);
|
|
390
416
|
input.signal?.addEventListener('abort', discardSuspendedTurn, { once: true });
|
|
@@ -394,6 +420,12 @@ export function createCliAdaptersFeature(options = {}) {
|
|
|
394
420
|
// 外部适配器绕过 DSH 原生 Agent Loop,必须在真正执行外部流前补发同一状态,
|
|
395
421
|
// 否则外部子会话完成后虽已写入历史,客户端目录仍不会得到 running -> idle。
|
|
396
422
|
publishExternalStatus(sessionId, true);
|
|
423
|
+
// 分步驱动(OpenCode、Claude、CodeBuddy 等)在工具完成处只结束一个 DSH
|
|
424
|
+
// step:Agent Loop 注入 next-step 后仍停留在同一个 turn 里继续下一步。
|
|
425
|
+
// 这种挂起不是回合结束,本段 llm/stream 返回时不能播报 idle,否则每个
|
|
426
|
+
// 工具完成都会先「已完成」再「进行中」,会话状态随工具调用反复闪烁。
|
|
427
|
+
// 真正的收尾由最后一段的 finish、原生 turn/end 与 agent/status idle 补齐。
|
|
428
|
+
let suspendedForNextStep = false;
|
|
397
429
|
try {
|
|
398
430
|
for await (const chunk of registry.execute({ ...input, adapterId: config.adapterId })) {
|
|
399
431
|
if (chunk.type === 'step-boundary') {
|
|
@@ -403,6 +435,8 @@ export function createCliAdaptersFeature(options = {}) {
|
|
|
403
435
|
const injected = nativeSessions?.injectNextStep?.(sessionId) ?? false;
|
|
404
436
|
if (!injected)
|
|
405
437
|
discardSuspendedTurn();
|
|
438
|
+
else
|
|
439
|
+
suspendedForNextStep = true;
|
|
406
440
|
for (const dshChunk of await projector.push(chunk))
|
|
407
441
|
yield dshChunk;
|
|
408
442
|
continue;
|
|
@@ -424,7 +458,11 @@ export function createCliAdaptersFeature(options = {}) {
|
|
|
424
458
|
}
|
|
425
459
|
finally {
|
|
426
460
|
input.signal?.removeEventListener('abort', discardSuspendedTurn);
|
|
427
|
-
|
|
461
|
+
// 挂起续段不是回合结束:这里不能播报 idle,否则每个工具完成都会让会话
|
|
462
|
+
// 状态在「已完成 / 进行中」之间来回闪烁。收尾由最后一段的 finish、
|
|
463
|
+
// 原生 turn/end 与 agent/status idle 补齐。
|
|
464
|
+
if (!suspendedForNextStep)
|
|
465
|
+
publishExternalStatus(sessionId, false);
|
|
428
466
|
}
|
|
429
467
|
});
|
|
430
468
|
if (typeof dispose === 'function')
|
|
@@ -485,10 +523,10 @@ function createExternalSessionStatusPublisher(events, registry, sessionStore) {
|
|
|
485
523
|
* 在 Agent Loop 的可变输入边界消费委派 carrier。
|
|
486
524
|
*
|
|
487
525
|
* `llm/stream` 收到的 LOOP 请求由 DSH 深冻结,监听器只能读取;如果在那里改写
|
|
488
|
-
* `messages`,会直接抛出只读属性异常。`agent/pre-step`
|
|
489
|
-
*
|
|
526
|
+
* `messages`,会直接抛出只读属性异常。`agent/pre-step` 返回的新消息保留用户原文,并把
|
|
527
|
+
* 译文写入 source 元数据;外部适配器再据此构造发给 Agent 的译文。
|
|
490
528
|
*/
|
|
491
|
-
function registerDelegationAgentHooks(dshContext, registry, resources, publishExternalStatus) {
|
|
529
|
+
function registerDelegationAgentHooks(dshContext, registry, resources, publishExternalStatus, translation) {
|
|
492
530
|
if (dshContext === undefined || typeof dshContext.on !== 'function')
|
|
493
531
|
return;
|
|
494
532
|
const disposers = [];
|
|
@@ -497,10 +535,44 @@ function registerDelegationAgentHooks(dshContext, registry, resources, publishEx
|
|
|
497
535
|
if (typeof disposer === 'function')
|
|
498
536
|
disposers.push(disposer);
|
|
499
537
|
};
|
|
538
|
+
// DSH Agent Loop 会用 agent/request 的 provider/model 生成 assistant/message.source。
|
|
539
|
+
// 外部流虽然在 llm/stream 旁路执行,但如果这里仍保留 DeepSeek 路由,回复历史
|
|
540
|
+
// 就会被错误归属为 DeepSeek。只改写已绑定的外部会话,不影响 DSH 原生会话。
|
|
541
|
+
register('agent/request', async (payload, next) => {
|
|
542
|
+
const resolved = await next();
|
|
543
|
+
const config = asRecord(resolved);
|
|
544
|
+
if (config === null)
|
|
545
|
+
return resolved;
|
|
546
|
+
const sessionId = readAgentSessionId(asRecord(payload)?.agent);
|
|
547
|
+
if (sessionId === '')
|
|
548
|
+
return config;
|
|
549
|
+
let session;
|
|
550
|
+
try {
|
|
551
|
+
session = registry.getSession(sessionId);
|
|
552
|
+
}
|
|
553
|
+
catch {
|
|
554
|
+
return config;
|
|
555
|
+
}
|
|
556
|
+
const configuredAdapter = session.adapterId !== 'dsh' && registry.isEnabled(session.adapterId)
|
|
557
|
+
? session.adapterId
|
|
558
|
+
: typeof config.provider === 'string' && registry.isEnabled(config.provider)
|
|
559
|
+
? config.provider
|
|
560
|
+
: undefined;
|
|
561
|
+
if (configuredAdapter === undefined)
|
|
562
|
+
return config;
|
|
563
|
+
if (session.adapterId === 'dsh') {
|
|
564
|
+
session = registry.setSession(sessionId, {
|
|
565
|
+
adapterId: configuredAdapter,
|
|
566
|
+
...(typeof config.model === 'string' && config.model.trim() !== '' ? { modelId: config.model.trim() } : {}),
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
const model = session.modelId?.trim() || (typeof config.model === 'string' && config.model.trim() !== '' ? config.model.trim() : configuredAdapter);
|
|
570
|
+
return { ...config, provider: configuredAdapter, model };
|
|
571
|
+
});
|
|
500
572
|
register('agent/pre-step', async (payload, next) => {
|
|
501
573
|
const record = asRecord(payload);
|
|
502
574
|
const sessionId = readAgentSessionId(record?.agent);
|
|
503
|
-
|
|
575
|
+
let messages = Array.isArray(record?.messages) ? record.messages.filter(isMessage) : [];
|
|
504
576
|
let delegation;
|
|
505
577
|
if (containsDelegationCarrier(messages)) {
|
|
506
578
|
delegation = rewriteDelegationMessages(messages, await registry.catalogForUse(delegationAdapterIds(messages)));
|
|
@@ -508,16 +580,22 @@ function registerDelegationAgentHooks(dshContext, registry, resources, publishEx
|
|
|
508
580
|
clearDelegationAuthorization(sessionId);
|
|
509
581
|
else if (delegation.kind === 'rewritten') {
|
|
510
582
|
setDelegationAuthorization(sessionId, delegation.value.targets);
|
|
583
|
+
messages = [...delegation.value.messages];
|
|
511
584
|
}
|
|
512
585
|
}
|
|
586
|
+
const translatedInput = await translatePreStepInput(translation, registry, sessionId, messages, dshContext, isAbortSignal(record?.signal) ? record.signal : undefined);
|
|
587
|
+
if (translatedInput !== undefined)
|
|
588
|
+
messages = [...translatedInput];
|
|
513
589
|
const decision = await next();
|
|
514
|
-
if (
|
|
590
|
+
if (!isEnterPreStepDecision(decision))
|
|
591
|
+
return decision;
|
|
592
|
+
if (delegation?.kind !== 'rewritten' && translatedInput === undefined)
|
|
515
593
|
return decision;
|
|
516
594
|
// `next()` 可能已经追加系统上下文或模型切换通知,只替换它前面的本轮用户消息。
|
|
517
595
|
const suffix = decision.messages.slice(messages.length);
|
|
518
596
|
return {
|
|
519
597
|
...decision,
|
|
520
|
-
messages: [...
|
|
598
|
+
messages: [...messages, ...suffix],
|
|
521
599
|
};
|
|
522
600
|
});
|
|
523
601
|
// 正常结束、异常结束和中断最终都会进入 idle;在此清理本轮授权,避免下一轮
|
|
@@ -548,6 +626,24 @@ function isEnterPreStepDecision(value) {
|
|
|
548
626
|
const record = asRecord(value);
|
|
549
627
|
return record?.kind === 'enter' && Array.isArray(record.messages);
|
|
550
628
|
}
|
|
629
|
+
/**
|
|
630
|
+
* 翻译调用优先使用显式字段;若 DSH 在进入 waterfall 前规范化请求并丢掉未知字段,
|
|
631
|
+
* 再用 system 提示里的稳定标记识别。否则翻译请求会被误当成当前外部 Agent 回合。
|
|
632
|
+
*/
|
|
633
|
+
function isSessionTranslationLlmRequest(value) {
|
|
634
|
+
if (value?.codingnsTranslation === true)
|
|
635
|
+
return true;
|
|
636
|
+
if (typeof value?.system === 'string' && value.system.includes('CODINGNS_SESSION_TRANSLATION_V1'))
|
|
637
|
+
return true;
|
|
638
|
+
if (!Array.isArray(value?.messages))
|
|
639
|
+
return false;
|
|
640
|
+
return value.messages.some((message) => {
|
|
641
|
+
const record = asRecord(message);
|
|
642
|
+
if (record?.role !== 'system' || !Array.isArray(record.content))
|
|
643
|
+
return false;
|
|
644
|
+
return record.content.some((part) => asRecord(part)?.text?.includes?.('CODINGNS_SESSION_TRANSLATION_V1') === true);
|
|
645
|
+
});
|
|
646
|
+
}
|
|
551
647
|
function readAgentSessionId(value) {
|
|
552
648
|
const record = asRecord(value);
|
|
553
649
|
if (typeof record?.id === 'string' && record.id.trim() !== '')
|
|
@@ -720,6 +816,7 @@ function readSessionConfig(value) {
|
|
|
720
816
|
// `default` 是显式的“标准速度”选择,不能当作空值丢弃,否则关掉 Fast 会被
|
|
721
817
|
// Registry 回退成上一次记住的加速档。
|
|
722
818
|
...(typeof record?.serviceTierId === 'string' && record.serviceTierId.trim() ? { serviceTierId: record.serviceTierId.trim() } : {}),
|
|
819
|
+
...(typeof record?.translationEnabled === 'boolean' ? { translationEnabled: record.translationEnabled } : {}),
|
|
723
820
|
...(typeof record?.providerId === 'string' && record.providerId.trim() ? { providerId: record.providerId.trim() } : {}),
|
|
724
821
|
...(typeof record?.providerSessionId === 'string' && record.providerSessionId.trim() ? { providerSessionId: record.providerSessionId.trim() } : {}),
|
|
725
822
|
...(typeof record?.rawStoreRef === 'string' && record.rawStoreRef.trim() ? { rawStoreRef: record.rawStoreRef.trim() } : {}),
|
|
@@ -876,11 +973,101 @@ async function setAdapterEnabled(settings, registry, value) {
|
|
|
876
973
|
await settings.update({ agentAdapters: registry.enabledSnapshot() });
|
|
877
974
|
return { adapterId, enabled };
|
|
878
975
|
}
|
|
976
|
+
/** 运行中的外部 Agent 插话也必须经过同一条输入翻译路径。 */
|
|
977
|
+
async function translateSteerPrompt(translation, registry, sessionId, prompt, followUp) {
|
|
978
|
+
const session = registry.getSession(sessionId);
|
|
979
|
+
let translated = prompt;
|
|
980
|
+
if (translation !== undefined) {
|
|
981
|
+
try {
|
|
982
|
+
translated = await translation.translateInput(session.adapterId, prompt, undefined, session.translationEnabled === true);
|
|
983
|
+
}
|
|
984
|
+
catch {
|
|
985
|
+
// 插话翻译失败时仍把用户原文交给外部 Agent。
|
|
986
|
+
translated = prompt;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
await registry.steer(sessionId, translated, followUp);
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* 在 Agent Loop 接受本轮输入时生成一次输入译文。
|
|
993
|
+
*
|
|
994
|
+
* DSH 随后会把返回的消息写入 `user/message`。正文只放实际发送的译文;原文和模型
|
|
995
|
+
* 记录在 source 元数据中供 Client 详情按钮读取。外部 CLI 边界也会移除该元数据。
|
|
996
|
+
*/
|
|
997
|
+
async function translatePreStepInput(translation, registry, sessionId, messages, dshContext, signal) {
|
|
998
|
+
if (translation === undefined || !translation.enabled || sessionId.trim() === '')
|
|
999
|
+
return undefined;
|
|
1000
|
+
let session;
|
|
1001
|
+
try {
|
|
1002
|
+
session = registry.getSession(sessionId);
|
|
1003
|
+
}
|
|
1004
|
+
catch {
|
|
1005
|
+
return undefined;
|
|
1006
|
+
}
|
|
1007
|
+
if (session.adapterId === 'dsh' || session.translationEnabled !== true)
|
|
1008
|
+
return undefined;
|
|
1009
|
+
const messageIndex = findLatestHumanMessage(messages);
|
|
1010
|
+
const current = messageIndex < 0 ? undefined : messages[messageIndex];
|
|
1011
|
+
if (current === undefined || readInputTranslation(current.source) !== undefined)
|
|
1012
|
+
return undefined;
|
|
1013
|
+
const input = extractTurnInput(messages, dshContext);
|
|
1014
|
+
if (input.translationPrompt.trim() === '')
|
|
1015
|
+
return undefined;
|
|
1016
|
+
let translatedNatural;
|
|
1017
|
+
let translationSourceLanguage = undefined;
|
|
1018
|
+
let alreadyTargetLanguage = false;
|
|
1019
|
+
let translationModel;
|
|
1020
|
+
let translationFailed = false;
|
|
1021
|
+
try {
|
|
1022
|
+
if (translation.translateInputDetailed !== undefined) {
|
|
1023
|
+
const detailed = await translation.translateInputDetailed(session.adapterId, input.translationPrompt, signal, true);
|
|
1024
|
+
translatedNatural = detailed.translated;
|
|
1025
|
+
translationSourceLanguage = detailed.sourceLanguage;
|
|
1026
|
+
alreadyTargetLanguage = detailed.alreadyTargetLanguage === true;
|
|
1027
|
+
translationModel = detailed.model;
|
|
1028
|
+
translationFailed = detailed.failed === true;
|
|
1029
|
+
}
|
|
1030
|
+
else {
|
|
1031
|
+
translatedNatural = await translation.translateInput(session.adapterId, input.translationPrompt, signal, true);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
catch {
|
|
1035
|
+
// 翻译只是增强能力;异常时保持现有外部 Agent 回合继续使用原文。
|
|
1036
|
+
translatedNatural = input.translationPrompt;
|
|
1037
|
+
translationFailed = true;
|
|
1038
|
+
}
|
|
1039
|
+
const translated = [translatedNatural, input.untranslatedPrompt]
|
|
1040
|
+
.filter((part) => part.trim() !== '')
|
|
1041
|
+
.join('\n\n')
|
|
1042
|
+
.trim();
|
|
1043
|
+
if (translated === '')
|
|
1044
|
+
return undefined;
|
|
1045
|
+
const record = {
|
|
1046
|
+
original: input.prompt,
|
|
1047
|
+
translated,
|
|
1048
|
+
...(translationSourceLanguage === undefined ? {} : { sourceLanguage: translationSourceLanguage }),
|
|
1049
|
+
targetLanguage: translation.inputLanguage ?? 'en',
|
|
1050
|
+
...(alreadyTargetLanguage ? { alreadyTargetLanguage: true } : {}),
|
|
1051
|
+
...(translationModel === undefined ? {} : { model: translationModel }),
|
|
1052
|
+
...(translationFailed ? { failed: true } : {}),
|
|
1053
|
+
};
|
|
1054
|
+
const next = [...messages];
|
|
1055
|
+
next[messageIndex] = {
|
|
1056
|
+
...current,
|
|
1057
|
+
source: {
|
|
1058
|
+
...(current.source ?? {}),
|
|
1059
|
+
kind: 'user',
|
|
1060
|
+
codingnsTranslationInput: record,
|
|
1061
|
+
},
|
|
1062
|
+
};
|
|
1063
|
+
return next;
|
|
1064
|
+
}
|
|
879
1065
|
function extractTurnInput(messages, dshContext) {
|
|
880
1066
|
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
881
1067
|
const message = messages[index];
|
|
882
1068
|
if (message !== undefined && isInjectedStepNotice(message)) {
|
|
883
|
-
|
|
1069
|
+
const prompt = extractText(message.content);
|
|
1070
|
+
return { prompt, translationPrompt: prompt, untranslatedPrompt: '', attachments: [], translatePrompt: false, messages };
|
|
884
1071
|
}
|
|
885
1072
|
if (message !== undefined && isHumanUserMessage(message)) {
|
|
886
1073
|
const direct = extractMessageInput(message.content, dshContext);
|
|
@@ -896,14 +1083,92 @@ function extractTurnInput(messages, dshContext) {
|
|
|
896
1083
|
const forwarded = referenceIndexes.length === 0
|
|
897
1084
|
? messages
|
|
898
1085
|
: messages.filter((_candidate, candidateIndex) => !referenceIndexes.includes(candidateIndex));
|
|
1086
|
+
const translatedInput = readInputTranslation(message.source);
|
|
1087
|
+
if (translatedInput !== undefined) {
|
|
1088
|
+
return {
|
|
1089
|
+
prompt: translatedInput.translated,
|
|
1090
|
+
translationPrompt: translatedInput.translated,
|
|
1091
|
+
untranslatedPrompt: '',
|
|
1092
|
+
attachments: direct.attachments,
|
|
1093
|
+
translatePrompt: false,
|
|
1094
|
+
messages: stripInputTranslationDisplay(forwarded),
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
899
1097
|
return {
|
|
900
1098
|
prompt: [direct.prompt, ...referenceText].filter(text => text.trim() !== '').join('\n\n').trim(),
|
|
1099
|
+
translationPrompt: [direct.translationPrompt, ...referenceText].filter(text => text.trim() !== '').join('\n\n').trim(),
|
|
1100
|
+
untranslatedPrompt: direct.untranslatedPrompt,
|
|
901
1101
|
attachments: direct.attachments,
|
|
902
|
-
|
|
1102
|
+
translatePrompt: true,
|
|
1103
|
+
messages: stripInputTranslationDisplay(forwarded),
|
|
903
1104
|
};
|
|
904
1105
|
}
|
|
905
1106
|
}
|
|
906
|
-
return { prompt: '', attachments: [], messages };
|
|
1107
|
+
return { prompt: '', translationPrompt: '', untranslatedPrompt: '', attachments: [], translatePrompt: false, messages: stripInputTranslationDisplay(messages) };
|
|
1108
|
+
}
|
|
1109
|
+
function findLatestHumanMessage(messages) {
|
|
1110
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
1111
|
+
const message = messages[index];
|
|
1112
|
+
if (message !== undefined && isHumanUserMessage(message))
|
|
1113
|
+
return index;
|
|
1114
|
+
}
|
|
1115
|
+
return -1;
|
|
1116
|
+
}
|
|
1117
|
+
function readInputTranslation(value) {
|
|
1118
|
+
const candidate = value?.codingnsTranslationInput;
|
|
1119
|
+
if (!isRecord(candidate) || typeof candidate.original !== 'string' || typeof candidate.translated !== 'string')
|
|
1120
|
+
return undefined;
|
|
1121
|
+
if (candidate.original.trim() === '' || candidate.translated.trim() === '')
|
|
1122
|
+
return undefined;
|
|
1123
|
+
const targetLanguage = candidate.targetLanguage === 'fr' || candidate.targetLanguage === 'de' || candidate.targetLanguage === 'ja'
|
|
1124
|
+
? candidate.targetLanguage
|
|
1125
|
+
: 'en';
|
|
1126
|
+
const sourceLanguage = candidate.sourceLanguage === 'zh' || candidate.sourceLanguage === 'en' || candidate.sourceLanguage === 'fr' || candidate.sourceLanguage === 'de' || candidate.sourceLanguage === 'ja'
|
|
1127
|
+
? candidate.sourceLanguage
|
|
1128
|
+
: undefined;
|
|
1129
|
+
return {
|
|
1130
|
+
original: candidate.original,
|
|
1131
|
+
translated: candidate.translated,
|
|
1132
|
+
...(sourceLanguage === undefined ? {} : { sourceLanguage }),
|
|
1133
|
+
targetLanguage,
|
|
1134
|
+
...(candidate.alreadyTargetLanguage === true ? { alreadyTargetLanguage: true } : {}),
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
/** 把历史消息还原为 Provider 可见的纯译文,并移除内部翻译元数据。 */
|
|
1138
|
+
function stripInputTranslationDisplay(messages) {
|
|
1139
|
+
return messages.map((message) => {
|
|
1140
|
+
const record = readInputTranslation(message.source);
|
|
1141
|
+
if (record === undefined)
|
|
1142
|
+
return message;
|
|
1143
|
+
const source = message.source;
|
|
1144
|
+
const cleanSource = source === undefined
|
|
1145
|
+
? undefined
|
|
1146
|
+
: (() => {
|
|
1147
|
+
const { codingnsTranslationInput: _translation, ...rest } = source;
|
|
1148
|
+
return rest;
|
|
1149
|
+
})();
|
|
1150
|
+
return {
|
|
1151
|
+
...message,
|
|
1152
|
+
content: replaceInputTranslationContent(message.content, record.translated),
|
|
1153
|
+
...(cleanSource === undefined ? {} : { source: cleanSource }),
|
|
1154
|
+
};
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
function replaceInputTranslationContent(content, text) {
|
|
1158
|
+
if (typeof content === 'string')
|
|
1159
|
+
return text;
|
|
1160
|
+
if (!Array.isArray(content))
|
|
1161
|
+
return [{ type: 'text', text }];
|
|
1162
|
+
let replaced = false;
|
|
1163
|
+
const blocks = content.flatMap((part) => {
|
|
1164
|
+
if (!isRecord(part) || part.type !== 'text')
|
|
1165
|
+
return [part];
|
|
1166
|
+
if (replaced)
|
|
1167
|
+
return [];
|
|
1168
|
+
replaced = true;
|
|
1169
|
+
return [{ ...part, text }];
|
|
1170
|
+
});
|
|
1171
|
+
return replaced ? blocks : [{ type: 'text', text }, ...content];
|
|
907
1172
|
}
|
|
908
1173
|
/** DSH 为工具分段注入的继续提示必须成为下一次 Provider 请求的 prompt。 */
|
|
909
1174
|
function isInjectedStepNotice(message) {
|
|
@@ -939,9 +1204,9 @@ function extractText(content) {
|
|
|
939
1204
|
}
|
|
940
1205
|
function extractMessageInput(content, dshContext) {
|
|
941
1206
|
if (typeof content === 'string')
|
|
942
|
-
return { prompt: content, attachments: [] };
|
|
1207
|
+
return { prompt: content, translationPrompt: content, untranslatedPrompt: '', attachments: [] };
|
|
943
1208
|
if (!Array.isArray(content))
|
|
944
|
-
return { prompt: '', attachments: [] };
|
|
1209
|
+
return { prompt: '', translationPrompt: '', untranslatedPrompt: '', attachments: [] };
|
|
945
1210
|
const text = [];
|
|
946
1211
|
const attachments = [];
|
|
947
1212
|
for (const part of content) {
|
|
@@ -961,7 +1226,9 @@ function extractMessageInput(content, dshContext) {
|
|
|
961
1226
|
attachments.push({ kind, path, ...(name === undefined ? {} : { name }), ...(mimeType === undefined ? {} : { mimeType }) });
|
|
962
1227
|
}
|
|
963
1228
|
const fileNotes = attachments.filter((attachment) => attachment.kind === 'file').map((attachment) => `附件文件${attachment.name === undefined ? '' : `「${attachment.name}」`}位于:${attachment.path}\n请使用工具读取该文件的内容。`);
|
|
964
|
-
|
|
1229
|
+
const translationPrompt = text.join('\n\n').trim();
|
|
1230
|
+
const untranslatedPrompt = fileNotes.join('\n\n').trim();
|
|
1231
|
+
return { prompt: [translationPrompt, untranslatedPrompt].filter(value => value !== '').join('\n\n'), translationPrompt, untranslatedPrompt, attachments };
|
|
965
1232
|
}
|
|
966
1233
|
function resolveDshAttachmentPath(dshContext, kind, reference) {
|
|
967
1234
|
if (dshContext === undefined || typeof reference.attachmentId !== 'string')
|