@xmanrui/dsh-im 5.10.0 → 5.11.0
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 +39 -5
- package/README.md +42 -5
- package/bin/dsh-im.mjs +65 -0
- package/docs/client-integration.md +4 -0
- package/lib/client.js +1202 -95
- package/lib/index.js +365 -339
- package/package.json +7 -6
- package/plugin-src/client/access-policy-settings.js +210 -12
- package/plugin-src/client/bot-general-settings.js +44 -3
- package/plugin-src/client/i18n-ru.js +85 -0
- package/plugin-src/client/i18n.js +83 -0
- package/plugin-src/client/im-channels.js +419 -0
- package/plugin-src/client/index.js +33 -1
- package/plugin-src/client/styles.js +7 -7
- package/plugin-src/client/update-panel.js +2 -1
- package/plugin-src/host/channel-list-rpc.mjs +280 -0
- package/plugin-src/host/channels/dingtalk/production.mjs +28 -10
- package/plugin-src/host/channels/dingtalk/rpc.mjs +10 -1
- package/plugin-src/host/channels/feishu/production.mjs +39 -10
- package/plugin-src/host/channels/feishu/rpc.mjs +10 -1
- package/plugin-src/host/channels/matrix/production.mjs +28 -10
- package/plugin-src/host/channels/matrix/rpc.mjs +10 -0
- package/plugin-src/host/channels/qq/production.mjs +30 -11
- package/plugin-src/host/channels/qq/rpc.mjs +10 -1
- package/plugin-src/host/channels/shared/access-policy-production.mjs +9 -0
- package/plugin-src/host/channels/shared/binding-events.mjs +109 -0
- package/plugin-src/host/channels/shared/production.mjs +14 -1
- package/plugin-src/host/channels/shared/reply-content-rpc.mjs +17 -0
- package/plugin-src/host/channels/shared/rpc.mjs +9 -0
- package/plugin-src/host/channels/slack/production.mjs +28 -10
- package/plugin-src/host/channels/slack/rpc.mjs +10 -0
- package/plugin-src/host/channels/telegram/production.mjs +5 -0
- package/plugin-src/host/channels/wecom/production.mjs +28 -10
- package/plugin-src/host/channels/wecom/rpc.mjs +10 -1
- package/plugin-src/host/channels/wecom-app/production.mjs +28 -10
- package/plugin-src/host/channels/wecom-app/rpc.mjs +9 -0
- package/plugin-src/host/channels/weixin/production.mjs +28 -10
- package/plugin-src/host/channels/weixin/rpc.mjs +10 -1
- package/plugin-src/host/channels/whatsapp/production.mjs +28 -10
- package/plugin-src/host/channels/whatsapp/rpc.mjs +10 -1
- package/plugin-src/host/delivery-service.mjs +3 -4
- package/plugin-src/host/delivery-suggestions.mjs +3 -1
- package/plugin-src/host/harness-connection.mjs +2 -1
- package/plugin-src/host/harness-peer.mjs +3 -1
- package/plugin-src/host/index.mjs +8 -1
- package/plugin-src/host/modern-harness-api.mjs +5 -1
- package/plugin-src/host/root-scope.mjs +32 -0
- package/plugin-src/host/session-sync-coordinator.mjs +2 -1
- package/plugin-src/management-rpc.mjs +18 -2
- package/scripts/verify-package.mjs +36 -7
- package/src/channels/dingtalk/dingtalk-bridge.mjs +50 -6
- package/src/channels/dingtalk/state-store.mjs +56 -0
- package/src/channels/discord/discord-api.mjs +2 -1
- package/src/channels/feishu/bridge.mjs +154 -58
- package/src/channels/feishu/feishu-cards.mjs +10 -4
- package/src/channels/feishu/feishu-runtime.mjs +11 -3
- package/src/channels/feishu/message-utils.mjs +106 -30
- package/src/channels/feishu/slash-command-panel.mjs +26 -0
- package/src/channels/feishu/state-store.mjs +14 -0
- package/src/channels/matrix/matrix-api.mjs +2 -1
- package/src/channels/qq/qq-bridge.mjs +105 -14
- package/src/channels/qq/state-store.mjs +13 -1
- package/src/channels/shared/access-policy.mjs +60 -7
- package/src/channels/shared/bot-workspace-store.mjs +155 -3
- package/src/channels/shared/busy-message-dispatcher.mjs +2 -2
- package/src/channels/shared/channel-capabilities.mjs +44 -0
- package/src/channels/shared/command-catalog.mjs +68 -3
- package/src/channels/shared/command-permission.mjs +6 -2
- package/src/channels/shared/conversation-state-store.mjs +16 -0
- package/src/channels/shared/deferred-delivery-coordinator.mjs +6 -1
- package/src/channels/shared/deferred-delivery.mjs +4 -0
- package/src/channels/shared/diagnostic-details.mjs +6 -1
- package/src/channels/shared/failure-log-file.mjs +79 -0
- package/src/channels/shared/harness-client.mjs +111 -6
- package/src/channels/shared/i18n-en/feishu.mjs +2 -2
- package/src/channels/shared/i18n-en/shared-a.mjs +13 -2
- package/src/channels/shared/i18n-en/shared-b.mjs +67 -4
- package/src/channels/shared/i18n-en/shared-d.mjs +144 -0
- package/src/channels/shared/i18n-en/weixin.mjs +4 -0
- package/src/channels/shared/i18n-en.mjs +2 -0
- package/src/channels/shared/i18n-ru/feishu.mjs +2 -2
- package/src/channels/shared/i18n-ru/shared-a.mjs +13 -2
- package/src/channels/shared/i18n-ru/shared-b.mjs +67 -4
- package/src/channels/shared/i18n-ru/shared-d.mjs +144 -0
- package/src/channels/shared/i18n-ru/weixin.mjs +4 -0
- package/src/channels/shared/i18n-ru.mjs +2 -0
- package/src/channels/shared/inbound-access.mjs +10 -0
- package/src/channels/shared/markdown-chunks.mjs +5 -0
- package/src/channels/shared/message-failure.mjs +22 -1
- package/src/channels/shared/new-command.mjs +158 -4
- package/src/channels/shared/plan-goal-command.mjs +132 -0
- package/src/channels/shared/qrcode.mjs +5 -0
- package/src/channels/shared/reply-content.mjs +102 -0
- package/src/channels/shared/reset-command.mjs +46 -0
- package/src/channels/shared/semantic/artifact.mjs +133 -29
- package/src/channels/shared/semantic/reply-reference.mjs +18 -3
- package/src/channels/shared/session-nav-command.mjs +999 -0
- package/src/channels/shared/session-ring-support.mjs +184 -0
- package/src/channels/shared/session-ring.mjs +202 -0
- package/src/channels/shared/session-title.mjs +11 -0
- package/src/channels/shared/status-command.mjs +2 -1
- package/src/channels/shared/text-harness-bridge.mjs +166 -7
- package/src/channels/shared/workspace-command.mjs +567 -31
- package/src/channels/shared/workspace-session.mjs +39 -3
- package/src/channels/slack/slack-api.mjs +2 -1
- package/src/channels/telegram/config-store.mjs +10 -2
- package/src/channels/telegram/telegram-rich-message.mjs +17 -5
- package/src/channels/telegram/telegram-runtime.mjs +14 -1
- package/src/channels/wecom/state-store.mjs +13 -1
- package/src/channels/wecom/wecom-bridge.mjs +183 -26
- package/src/channels/wecom-app/state-store.mjs +13 -1
- package/src/channels/wecom-app/wecom-app-bridge.mjs +44 -4
- package/src/channels/weixin/state-store.mjs +13 -1
- package/src/channels/weixin/weixin-bridge.mjs +71 -4
|
@@ -2,6 +2,7 @@ import { setTimeout as delay } from 'node:timers/promises';
|
|
|
2
2
|
import { ensurePresetWorkspace } from './preset-workspaces.mjs';
|
|
3
3
|
import { t } from './i18n.mjs';
|
|
4
4
|
import { normalizeBusyMessageMode, validateBusyMessageMode } from './message-mode.mjs';
|
|
5
|
+
import { isDefaultReplyContent, normalizeReplyContent, validateReplyContent } from './reply-content.mjs';
|
|
5
6
|
import { atConnectionStage, connectionStageError, extractConnectionEvidence } from './connection-error.mjs';
|
|
6
7
|
import { validateBotAlias, withBotAlias } from './bot-alias.mjs';
|
|
7
8
|
import { defaultImWorkspace, ensureImWorkspaceDirectory, sameWorkspacePath } from './default-workspace.mjs';
|
|
@@ -385,6 +386,17 @@ function normalizeDocument(value) {
|
|
|
385
386
|
if (Object.hasOwn(workspaces, id) && mode === 'steer') busyMessageModes[id] = mode;
|
|
386
387
|
}
|
|
387
388
|
}
|
|
389
|
+
// A damaged switch set must not take the bot's workspace or preset with it:
|
|
390
|
+
// every unreadable entry falls back to the full-content default.
|
|
391
|
+
const replyContents = Object.create(null);
|
|
392
|
+
if (value.replyContents && typeof value.replyContents === 'object'
|
|
393
|
+
&& !Array.isArray(value.replyContents)) {
|
|
394
|
+
for (const [id, content] of Object.entries(value.replyContents)) {
|
|
395
|
+
if (/^[A-Za-z0-9_-]{1,128}$/.test(id) && Object.hasOwn(workspaces, id)) {
|
|
396
|
+
replyContents[id] = normalizeReplyContent(content);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
388
400
|
const accessPolicies = normalizeAccessPolicies(value.accessPolicies, workspaces);
|
|
389
401
|
const conversationDirectory = normalizeConversationDirectory(value.conversationDirectory);
|
|
390
402
|
const conversationDirectories = normalizeConversationDirectoryOverrides(value.conversationDirectories);
|
|
@@ -410,6 +422,7 @@ function normalizeDocument(value) {
|
|
|
410
422
|
accessPolicies,
|
|
411
423
|
aliases,
|
|
412
424
|
busyMessageModes,
|
|
425
|
+
replyContents,
|
|
413
426
|
};
|
|
414
427
|
}
|
|
415
428
|
|
|
@@ -428,6 +441,7 @@ function storedDocument({
|
|
|
428
441
|
accessPolicies,
|
|
429
442
|
aliases,
|
|
430
443
|
busyMessageModes,
|
|
444
|
+
replyContents,
|
|
431
445
|
}) {
|
|
432
446
|
const document = { version, workspaces };
|
|
433
447
|
if (conversationDirectory) document.conversationDirectory = conversationDirectory;
|
|
@@ -435,6 +449,7 @@ function storedDocument({
|
|
|
435
449
|
if (Object.keys(sessionDirectories).length) document.sessionDirectories = sessionDirectories;
|
|
436
450
|
if (Object.keys(dsBotBindings).length > 0) document.dsBotBindings = dsBotBindings;
|
|
437
451
|
if (Object.keys(busyMessageModes).length > 0) document.busyMessageModes = busyMessageModes;
|
|
452
|
+
if (Object.keys(replyContents).length > 0) document.replyContents = replyContents;
|
|
438
453
|
if (Object.keys(aliases).length > 0) document.aliases = aliases;
|
|
439
454
|
if (Object.keys(conversationWorkspaces).length > 0) {
|
|
440
455
|
document.conversationWorkspaces = conversationWorkspaces;
|
|
@@ -498,6 +513,7 @@ export class BotWorkspaceStore {
|
|
|
498
513
|
#models = {};
|
|
499
514
|
#aliases = Object.create(null);
|
|
500
515
|
#busyMessageModes = Object.create(null);
|
|
516
|
+
#replyContents = Object.create(null);
|
|
501
517
|
#contextEnhancement = {};
|
|
502
518
|
#deliveryTargets = Object.create(null);
|
|
503
519
|
#dsBotBindings = Object.create(null);
|
|
@@ -535,6 +551,7 @@ export class BotWorkspaceStore {
|
|
|
535
551
|
this.#models = normalized.models;
|
|
536
552
|
this.#aliases = normalized.aliases;
|
|
537
553
|
this.#busyMessageModes = normalized.busyMessageModes;
|
|
554
|
+
this.#replyContents = normalized.replyContents;
|
|
538
555
|
this.#contextEnhancement = normalized.contextEnhancement;
|
|
539
556
|
this.#deliveryTargets = normalized.deliveryTargets;
|
|
540
557
|
this.#dsBotBindings = normalized.dsBotBindings;
|
|
@@ -551,6 +568,7 @@ export class BotWorkspaceStore {
|
|
|
551
568
|
this.#models = {};
|
|
552
569
|
this.#aliases = Object.create(null);
|
|
553
570
|
this.#busyMessageModes = Object.create(null);
|
|
571
|
+
this.#replyContents = Object.create(null);
|
|
554
572
|
this.#contextEnhancement = {};
|
|
555
573
|
this.#deliveryTargets = Object.create(null);
|
|
556
574
|
this.#dsBotBindings = Object.create(null);
|
|
@@ -747,6 +765,11 @@ export class BotWorkspaceStore {
|
|
|
747
765
|
return normalizeBusyMessageMode(this.has(id) ? this.#busyMessageModes[id] : undefined);
|
|
748
766
|
}
|
|
749
767
|
|
|
768
|
+
replyContentFor(botId) {
|
|
769
|
+
const id = botIdOf(botId);
|
|
770
|
+
return normalizeReplyContent(this.has(id) ? this.#replyContents[id] : undefined);
|
|
771
|
+
}
|
|
772
|
+
|
|
750
773
|
contextEnhancementFor(botId) {
|
|
751
774
|
const id = botIdOf(botId);
|
|
752
775
|
return this.has(id) && Object.hasOwn(this.#contextEnhancement, id)
|
|
@@ -1184,6 +1207,30 @@ export class BotWorkspaceStore {
|
|
|
1184
1207
|
});
|
|
1185
1208
|
}
|
|
1186
1209
|
|
|
1210
|
+
async setReplyContent(botId, value, { incarnation } = {}) {
|
|
1211
|
+
const id = botIdOf(botId);
|
|
1212
|
+
const expectedIncarnation = incarnation === undefined ? this.incarnationFor(id) : incarnation;
|
|
1213
|
+
const content = validateReplyContent(value);
|
|
1214
|
+
return this.#enqueue(id, async () => {
|
|
1215
|
+
if (!this.has(id) || expectedIncarnation !== this.incarnationFor(id)) {
|
|
1216
|
+
const error = new Error('找不到要修改的机器人。');
|
|
1217
|
+
error.code = 'workspace-bot-not-found';
|
|
1218
|
+
throw error;
|
|
1219
|
+
}
|
|
1220
|
+
const next = { ...this.#replyContents };
|
|
1221
|
+
// The all-on default is the absence of a record, so a bot that never
|
|
1222
|
+
// changed the switches leaves no field in the document.
|
|
1223
|
+
if (isDefaultReplyContent(content)) delete next[id];
|
|
1224
|
+
else next[id] = content;
|
|
1225
|
+
await this.#persist(this.#contextEnhancement, this.#deliveryTargets,
|
|
1226
|
+
this.#version, this.#accessPolicies, this.#aliases, this.#conversationWorkspaces,
|
|
1227
|
+
this.#busyMessageModes, this.#dsBotBindings, this.#conversationDirectory,
|
|
1228
|
+
this.#conversationDirectories, this.#sessionDirectories, next);
|
|
1229
|
+
this.#replyContents = next;
|
|
1230
|
+
return content;
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1187
1234
|
async setContextEnhancement(botId, value, { incarnation } = {}) {
|
|
1188
1235
|
const id = botIdOf(botId);
|
|
1189
1236
|
const expectedIncarnation = incarnation === undefined ? this.incarnationFor(id) : incarnation;
|
|
@@ -1567,6 +1614,7 @@ export class BotWorkspaceStore {
|
|
|
1567
1614
|
...Object.keys(this.#models),
|
|
1568
1615
|
...Object.keys(this.#aliases),
|
|
1569
1616
|
...Object.keys(this.#busyMessageModes),
|
|
1617
|
+
...Object.keys(this.#replyContents),
|
|
1570
1618
|
...Object.keys(this.#contextEnhancement),
|
|
1571
1619
|
...Object.keys(this.#deliveryTargets),
|
|
1572
1620
|
...Object.keys(this.#accessPolicies),
|
|
@@ -1596,6 +1644,7 @@ export class BotWorkspaceStore {
|
|
|
1596
1644
|
model: this.modelFor(bot.botId),
|
|
1597
1645
|
contextEnhancement: this.contextEnhancementFor(bot.botId),
|
|
1598
1646
|
busyMessageMode: this.busyMessageModeFor(bot.botId),
|
|
1647
|
+
replyContent: this.replyContentFor(bot.botId),
|
|
1599
1648
|
accessPolicy: this.accessPolicyFor(bot.botId),
|
|
1600
1649
|
}
|
|
1601
1650
|
: bot),
|
|
@@ -1635,6 +1684,7 @@ export class BotWorkspaceStore {
|
|
|
1635
1684
|
const hadModel = Object.hasOwn(this.#models, id);
|
|
1636
1685
|
const hadAlias = Object.hasOwn(this.#aliases, id);
|
|
1637
1686
|
const hadMessageMode = Object.hasOwn(this.#busyMessageModes, id);
|
|
1687
|
+
const hadReplyContent = Object.hasOwn(this.#replyContents, id);
|
|
1638
1688
|
const hadContextEnhancement = Object.hasOwn(this.#contextEnhancement, id);
|
|
1639
1689
|
const hadDeliveryTargets = Object.hasOwn(this.#deliveryTargets, id);
|
|
1640
1690
|
const hadDsBotBindings = Object.hasOwn(this.#dsBotBindings, id);
|
|
@@ -1643,6 +1693,7 @@ export class BotWorkspaceStore {
|
|
|
1643
1693
|
const hadDirectoryRecords = Object.hasOwn(this.#conversationDirectories, id) || Object.hasOwn(this.#sessionDirectories, id);
|
|
1644
1694
|
const needsCleanup = hadWorkspace || hadPreset || hadModel || hadAlias || hadContextEnhancement
|
|
1645
1695
|
|| hadDeliveryTargets || hadDsBotBindings || hadAccessPolicy || hadConversationWorkspaces || hadMessageMode
|
|
1696
|
+
|| hadReplyContent
|
|
1646
1697
|
|| hadDirectoryRecords
|
|
1647
1698
|
|| this.#dirtyRemovals.has(id);
|
|
1648
1699
|
delete this.#workspaces[id];
|
|
@@ -1650,6 +1701,7 @@ export class BotWorkspaceStore {
|
|
|
1650
1701
|
delete this.#models[id];
|
|
1651
1702
|
delete this.#aliases[id];
|
|
1652
1703
|
delete this.#busyMessageModes[id];
|
|
1704
|
+
delete this.#replyContents[id];
|
|
1653
1705
|
delete this.#contextEnhancement[id];
|
|
1654
1706
|
delete this.#deliveryTargets[id];
|
|
1655
1707
|
delete this.#dsBotBindings[id];
|
|
@@ -1698,6 +1750,7 @@ export class BotWorkspaceStore {
|
|
|
1698
1750
|
conversationDirectory = this.#conversationDirectory,
|
|
1699
1751
|
conversationDirectories = this.#conversationDirectories,
|
|
1700
1752
|
sessionDirectories = this.#sessionDirectories,
|
|
1753
|
+
replyContents = this.#replyContents,
|
|
1701
1754
|
) {
|
|
1702
1755
|
await writeStoredDocument(this.#path, storedDocument({
|
|
1703
1756
|
version,
|
|
@@ -1711,6 +1764,7 @@ export class BotWorkspaceStore {
|
|
|
1711
1764
|
accessPolicies,
|
|
1712
1765
|
aliases,
|
|
1713
1766
|
busyMessageModes,
|
|
1767
|
+
replyContents,
|
|
1714
1768
|
conversationDirectory,
|
|
1715
1769
|
conversationDirectories,
|
|
1716
1770
|
sessionDirectories,
|
|
@@ -1724,6 +1778,7 @@ export class BotWorkspaceStore {
|
|
|
1724
1778
|
|| Object.keys(this.#models).length > 0
|
|
1725
1779
|
|| Object.keys(this.#aliases).length > 0
|
|
1726
1780
|
|| Object.keys(this.#busyMessageModes).length > 0
|
|
1781
|
+
|| Object.keys(this.#replyContents).length > 0
|
|
1727
1782
|
|| Object.keys(this.#contextEnhancement).length > 0
|
|
1728
1783
|
|| Object.keys(this.#deliveryTargets).length > 0
|
|
1729
1784
|
|| Object.keys(this.#dsBotBindings).length > 0
|
|
@@ -1999,6 +2054,12 @@ export function createBotWorkspaceScope(
|
|
|
1999
2054
|
|
|
2000
2055
|
const scopedHarness = new Proxy(harness, {
|
|
2001
2056
|
get(target, property) {
|
|
2057
|
+
if (property === 'sessionFor') {
|
|
2058
|
+
// Read-only state lookup used by /sessionlist to mark the binding. The
|
|
2059
|
+
// state proxy owns the generation checks, so delegate instead of
|
|
2060
|
+
// exposing the raw mapping.
|
|
2061
|
+
return (key, ...args) => scopedState.sessionFor(key, ...args);
|
|
2062
|
+
}
|
|
2002
2063
|
if (property === 'resolveDsBotSession') {
|
|
2003
2064
|
return async (key) => {
|
|
2004
2065
|
assertCurrentBotScope(isCurrentScope);
|
|
@@ -2079,6 +2140,11 @@ export function createBotWorkspaceScope(
|
|
|
2079
2140
|
if (property === 'currentBusyMessageMode') {
|
|
2080
2141
|
return () => isCurrentScope() ? workspaces.busyMessageModeFor(botId) : 'queue';
|
|
2081
2142
|
}
|
|
2143
|
+
if (property === 'currentReplyContent') {
|
|
2144
|
+
return () => (isCurrentScope()
|
|
2145
|
+
? workspaces.replyContentFor(botId)
|
|
2146
|
+
: normalizeReplyContent(undefined));
|
|
2147
|
+
}
|
|
2082
2148
|
if (property === 'currentWorkspace') {
|
|
2083
2149
|
return () => {
|
|
2084
2150
|
if (!isCurrentScope()) {
|
|
@@ -2098,6 +2164,24 @@ export function createBotWorkspaceScope(
|
|
|
2098
2164
|
}
|
|
2099
2165
|
};
|
|
2100
2166
|
}
|
|
2167
|
+
if (property === 'archiveWorkspaceSession' && typeof target[property] === 'function') {
|
|
2168
|
+
// Archiving mutates Harness state, so it checks the bot scope on both
|
|
2169
|
+
// sides of the call like every other write this scope exposes.
|
|
2170
|
+
return async (...args) => {
|
|
2171
|
+
if (!isCurrentScope()) {
|
|
2172
|
+
const error = new Error('找不到要修改的机器人。');
|
|
2173
|
+
error.code = 'workspace-bot-not-found';
|
|
2174
|
+
throw error;
|
|
2175
|
+
}
|
|
2176
|
+
const result = await target.archiveWorkspaceSession(...args);
|
|
2177
|
+
if (!isCurrentScope()) {
|
|
2178
|
+
const error = new Error('找不到要修改的机器人。');
|
|
2179
|
+
error.code = 'workspace-bot-not-found';
|
|
2180
|
+
throw error;
|
|
2181
|
+
}
|
|
2182
|
+
return result;
|
|
2183
|
+
};
|
|
2184
|
+
}
|
|
2101
2185
|
if ((property === 'listWorkspaces'
|
|
2102
2186
|
|| property === 'listWorkspaceEntries'
|
|
2103
2187
|
|| property === 'listWorkspaceSessions'
|
|
@@ -2299,7 +2383,8 @@ export function createBotWorkspaceScope(
|
|
|
2299
2383
|
};
|
|
2300
2384
|
}
|
|
2301
2385
|
if (property === 'bindWorkspaceSession') {
|
|
2302
|
-
return async (conversationKey, sessionId) => {
|
|
2386
|
+
return async (conversationKey, sessionId, options = {}) => {
|
|
2387
|
+
const { expectedWorkspace } = options;
|
|
2303
2388
|
assertNoDsBinding(conversationKey);
|
|
2304
2389
|
if (typeof conversationKey !== 'string' || !conversationKey
|
|
2305
2390
|
|| typeof sessionId !== 'string' || !sessionId) {
|
|
@@ -2336,17 +2421,27 @@ export function createBotWorkspaceScope(
|
|
|
2336
2421
|
|| adopted.sessionId !== sessionId || typeof adopted.workspace !== 'string') {
|
|
2337
2422
|
throw new TypeError('Harness returned an invalid adopted workspace session');
|
|
2338
2423
|
}
|
|
2424
|
+
// Title selection is local to the Workspace observed by the search.
|
|
2425
|
+
// Recheck it here before committing; explicit IDs retain their
|
|
2426
|
+
// existing bot-wide switching behavior.
|
|
2427
|
+
const localBinding = expectedWorkspace !== undefined;
|
|
2428
|
+
if (localBinding
|
|
2429
|
+
&& (!(await sameWorkspacePath(adopted.workspace, expectedWorkspace))
|
|
2430
|
+
|| !(await sameWorkspacePath(adopted.workspace,
|
|
2431
|
+
await scopedHarness.resolveConversationWorkspace(conversationKey))))) {
|
|
2432
|
+
throw workspaceSessionStale('The conversation workspace changed during session selection.');
|
|
2433
|
+
}
|
|
2339
2434
|
// Selecting another session in the current automatic group must not
|
|
2340
2435
|
// turn that group into the bot's manual directory and clear every
|
|
2341
2436
|
// other conversation. Explicit cross-workspace selection keeps its
|
|
2342
2437
|
// existing bot-wide semantics.
|
|
2343
2438
|
const baseWorkspace = workspaces.workspaceFor(botId);
|
|
2344
|
-
const preserveBotWorkspace = !workspaces.hasConversationWorkspaceOverride(botId, conversationKey)
|
|
2439
|
+
const preserveBotWorkspace = localBinding || (!workspaces.hasConversationWorkspaceOverride(botId, conversationKey)
|
|
2345
2440
|
&& normalizeAgentPresetId(basename(adopted.workspace)) !== null
|
|
2346
2441
|
&& await target.isUngroupedWorkspace?.(baseWorkspace)
|
|
2347
2442
|
&& await sameWorkspacePath(dirname(adopted.workspace), join(baseWorkspace, 'presets'))
|
|
2348
2443
|
&& await sameWorkspacePath(adopted.workspace,
|
|
2349
|
-
await scopedHarness.resolveConversationWorkspace(conversationKey));
|
|
2444
|
+
await scopedHarness.resolveConversationWorkspace(conversationKey)));
|
|
2350
2445
|
const bound = await workspaces.bindWorkspaceSession(botId, adopted.workspace, {
|
|
2351
2446
|
conversationKey,
|
|
2352
2447
|
sessionId,
|
|
@@ -2377,6 +2472,22 @@ export function createBotWorkspaceScope(
|
|
|
2377
2472
|
conversationKey,
|
|
2378
2473
|
conversationGeneration: bound.conversationGeneration ?? 0,
|
|
2379
2474
|
});
|
|
2475
|
+
// /session, /go, /prev and /next all bind through this one path, so the
|
|
2476
|
+
// navigation ring records the bind here and stays in sync with the
|
|
2477
|
+
// Session binding itself. Best-effort: a ring write must not fail a bind.
|
|
2478
|
+
// A non-navigation bind (/session adopt) appends the Session as the
|
|
2479
|
+
// ring's current position; /go, /prev and /next manage the visit stack
|
|
2480
|
+
// themselves and pass { navigation: true } to skip this.
|
|
2481
|
+
try {
|
|
2482
|
+
const registered = await state.ensureSessionRing?.(conversationKey, sessionId, {
|
|
2483
|
+
title: typeof adopted.title === 'string' && adopted.title ? adopted.title : undefined,
|
|
2484
|
+
});
|
|
2485
|
+
if (options.navigation !== true && registered?.entry) {
|
|
2486
|
+
await state.appendRing?.(conversationKey, registered.entry.n);
|
|
2487
|
+
}
|
|
2488
|
+
} catch (error) {
|
|
2489
|
+
console.warn('[dsh-im] unable to record the session in the navigation ring:', error?.message ?? error);
|
|
2490
|
+
}
|
|
2380
2491
|
return {
|
|
2381
2492
|
...adopted,
|
|
2382
2493
|
workspace: bound.workspace,
|
|
@@ -2664,6 +2775,26 @@ export function createBotWorkspaceScope(
|
|
|
2664
2775
|
return target.sessionExists(sessionId, ...args);
|
|
2665
2776
|
};
|
|
2666
2777
|
}
|
|
2778
|
+
if (property === 'forkSession') {
|
|
2779
|
+
return async (sessionId, options = {}) => {
|
|
2780
|
+
if (!isCurrentScope()) {
|
|
2781
|
+
throw workspaceSessionStale('The bot workspace changed before the fork.');
|
|
2782
|
+
}
|
|
2783
|
+
if (generationIsStale(sessionGenerations.get(sessionId))) {
|
|
2784
|
+
throw workspaceSessionStale('The session is no longer in the current workspace.');
|
|
2785
|
+
}
|
|
2786
|
+
if (typeof target.forkSession !== 'function') {
|
|
2787
|
+
const error = new Error('The Host does not support forking sessions');
|
|
2788
|
+
error.code = 'harness-api-not-found';
|
|
2789
|
+
throw error;
|
|
2790
|
+
}
|
|
2791
|
+
const result = await target.forkSession(sessionId, options);
|
|
2792
|
+
if (!isCurrentScope()) {
|
|
2793
|
+
throw workspaceSessionStale('The bot workspace changed while the fork was running.');
|
|
2794
|
+
}
|
|
2795
|
+
return result;
|
|
2796
|
+
};
|
|
2797
|
+
}
|
|
2667
2798
|
if (property === 'ask') {
|
|
2668
2799
|
return (sessionId, ...args) => {
|
|
2669
2800
|
const entry = sessionGenerations.get(sessionId);
|
|
@@ -2876,6 +3007,26 @@ export function createWorkspaceAwareController(controller, {
|
|
|
2876
3007
|
return result;
|
|
2877
3008
|
});
|
|
2878
3009
|
};
|
|
3010
|
+
const updateReplyContent = (botId, value, projectStatus) => {
|
|
3011
|
+
const incarnation = workspaces.incarnationFor(botId);
|
|
3012
|
+
const content = validateReplyContent(value);
|
|
3013
|
+
return withBotTransition(botId, async () => {
|
|
3014
|
+
const snapshot = await decorate(await controller.status());
|
|
3015
|
+
if (!snapshot?.bots?.some((bot) => bot?.botId === botId)) {
|
|
3016
|
+
const error = new Error('找不到要修改的机器人。');
|
|
3017
|
+
error.code = 'workspace-bot-not-found';
|
|
3018
|
+
throw error;
|
|
3019
|
+
}
|
|
3020
|
+
const updated = {
|
|
3021
|
+
...snapshot,
|
|
3022
|
+
bots: snapshot.bots.map((bot) => (bot.botId === botId
|
|
3023
|
+
? { ...bot, replyContent: content } : bot)),
|
|
3024
|
+
};
|
|
3025
|
+
const result = projectStatus ? await projectStatus(updated) : updated;
|
|
3026
|
+
await workspaces.setReplyContent(botId, content, { incarnation });
|
|
3027
|
+
return result;
|
|
3028
|
+
});
|
|
3029
|
+
};
|
|
2879
3030
|
const updateBusyMessageMode = (botId, value, projectStatus) => {
|
|
2880
3031
|
const incarnation = workspaces.incarnationFor(botId);
|
|
2881
3032
|
const busyMessageMode = validateBusyMessageMode(value);
|
|
@@ -3021,6 +3172,7 @@ export function createWorkspaceAwareController(controller, {
|
|
|
3021
3172
|
if (property === 'updateModel') return updateModel;
|
|
3022
3173
|
if (property === 'updateAlias') return updateAlias;
|
|
3023
3174
|
if (property === 'updateBusyMessageMode') return updateBusyMessageMode;
|
|
3175
|
+
if (property === 'updateReplyContent') return updateReplyContent;
|
|
3024
3176
|
if (property === 'updateContextEnhancement') return updateContextEnhancement;
|
|
3025
3177
|
if (property === 'updateAccessPolicy') return updateAccessPolicy;
|
|
3026
3178
|
const value = Reflect.get(target, property, target);
|
|
@@ -23,7 +23,7 @@ export class BusyMessageDispatcher {
|
|
|
23
23
|
key, messageId, text, commandText = text, eligible, harness, state, status,
|
|
24
24
|
control, signal, enhancement, pendingInteraction, acceptedMessageIds,
|
|
25
25
|
mode = harness.currentBusyMessageMode?.(), onFailure,
|
|
26
|
-
enqueue, isQueued, send, logger = console, onSteered, onError,
|
|
26
|
+
enqueue, isQueued, send, logger = console, onSteered, onError, steerReceipt = true,
|
|
27
27
|
}) {
|
|
28
28
|
// Read once, before any await: a settings change cannot reinterpret this input.
|
|
29
29
|
const steer = normalizeBusyMessageMode(mode) === 'steer'
|
|
@@ -61,7 +61,7 @@ export class BusyMessageDispatcher {
|
|
|
61
61
|
});
|
|
62
62
|
if (!submitted) return queue(true);
|
|
63
63
|
// Submission is final even if its receipt fails.
|
|
64
|
-
await send(t('已提交补充指令,Agent 会在下一步读取。'));
|
|
64
|
+
if (steerReceipt) await send(t('已提交补充指令,Agent 会在下一步读取。'));
|
|
65
65
|
await onSteered?.();
|
|
66
66
|
status.lastError = null;
|
|
67
67
|
return {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declared channel capabilities for the session-navigation commands.
|
|
3
|
+
*
|
|
4
|
+
* Declared once here instead of probing the bot adapter per command, so the
|
|
5
|
+
* capability matrix (message buttons, document send) stays auditable in one
|
|
6
|
+
* place. The bridge still verifies the concrete bot method exists before it
|
|
7
|
+
* sends, because a declared capability is not a promise that this bot instance
|
|
8
|
+
* can currently deliver it.
|
|
9
|
+
*
|
|
10
|
+
* - buttons: the preview may carry a native "Hide" button.
|
|
11
|
+
* - fileSend: the /tail export can be delivered as a document attachment.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const NO_CAPABILITIES = Object.freeze({ buttons: false, fileSend: false });
|
|
15
|
+
|
|
16
|
+
export const CHANNEL_CAPABILITIES = Object.freeze({
|
|
17
|
+
telegram: Object.freeze({ buttons: true, fileSend: true }),
|
|
18
|
+
slack: Object.freeze({ buttons: false, fileSend: true }),
|
|
19
|
+
discord: Object.freeze({ buttons: false, fileSend: true }),
|
|
20
|
+
// Feishu and DingTalk have their own native card/button systems that are not
|
|
21
|
+
// wired through the shared sendInteractionCard seam, and their file send is
|
|
22
|
+
// not exposed through the shared sendFile seam either — so neither is
|
|
23
|
+
// advertised here until it is actually wired.
|
|
24
|
+
feishu: Object.freeze({ buttons: false, fileSend: false }),
|
|
25
|
+
dingtalk: Object.freeze({ buttons: false, fileSend: false }),
|
|
26
|
+
// whatsapp, matrix, email, office, qq, wecom, wecom-app, weixin, imessage:
|
|
27
|
+
// no native message buttons and no document attachment path today.
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export function channelCapabilities(channelKey) {
|
|
31
|
+
return CHANNEL_CAPABILITIES[channelKey] ?? NO_CAPABILITIES;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A document can be delivered only on a file-capable channel with a send method. */
|
|
35
|
+
export function documentSendSupported(channelKey, bot) {
|
|
36
|
+
return channelCapabilities(channelKey).fileSend === true
|
|
37
|
+
&& typeof bot?.sendFile === 'function';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A preview may carry a Hide button only on a button-capable channel with cards. */
|
|
41
|
+
export function buttonPreviewSupported(channelKey, bot) {
|
|
42
|
+
return channelCapabilities(channelKey).buttons === true
|
|
43
|
+
&& typeof bot?.sendInteractionCard === 'function';
|
|
44
|
+
}
|
|
@@ -23,8 +23,14 @@ function defineCatalogCommand(name, description, help, { aliases = [], ...option
|
|
|
23
23
|
// enabled: false removes a definition from both consumers; menuVisible: false
|
|
24
24
|
// hides a command (or alias) only from the native menu, leaving help available.
|
|
25
25
|
export const SHARED_COMMAND_CATALOG = Object.freeze([
|
|
26
|
-
defineCatalogCommand('new', '
|
|
27
|
-
'/new
|
|
26
|
+
defineCatalogCommand('new', '开启一个全新会话(可带标题)', [
|
|
27
|
+
'/new [标题] 开启一个全新会话(可指定标题)',
|
|
28
|
+
]),
|
|
29
|
+
defineCatalogCommand('fork', '从当前会话分支一个新会话', [
|
|
30
|
+
'/fork [标题] 从当前会话分支一个新会话(默认沿用父会话标题加“ (fork)”)',
|
|
31
|
+
], { requiresSessionFork: true }),
|
|
32
|
+
defineCatalogCommand('reset', '重置当前会话上下文(保留会话编号)', [
|
|
33
|
+
'/reset 重置当前会话上下文(保留会话编号,旧会话可 /session 找回)',
|
|
28
34
|
]),
|
|
29
35
|
defineCatalogCommand('compact', '压缩当前会话的较早上下文', [
|
|
30
36
|
'/compact 压缩当前会话的较早上下文',
|
|
@@ -67,11 +73,42 @@ export const SHARED_COMMAND_CATALOG = Object.freeze([
|
|
|
67
73
|
}),
|
|
68
74
|
defineCatalogCommand('sessionlist', '列出会话 ID 和标题', [
|
|
69
75
|
'/sessionlist 或 /sessions [工作区序号或绝对路径] 列出会话 ID 和标题',
|
|
76
|
+
'/sessionlist --all 跨工作区汇总会话(每个工作区默认显示 10 个,可用 --limit N 调整)',
|
|
70
77
|
'/sessionlist --limit N 仅列出当前工作区前 N 个会话',
|
|
71
78
|
], { aliases: [{ name: 'sessions', menuVisible: false }] }),
|
|
72
79
|
defineCatalogCommand('session', '将当前聊天绑定到指定会话', [
|
|
73
|
-
'/session Session ID
|
|
80
|
+
'/session Session ID、当前工作区序号或标题关键词 将当前聊天绑定到指定会话',
|
|
81
|
+
'/sess 同一命令的别名(/session 被客户端同名命令抢占时使用)',
|
|
82
|
+
], { aliases: [{ name: 'sess', menuVisible: false }] }),
|
|
83
|
+
defineCatalogCommand('sessionarchive', '归档指定会话(DSH 能力)', [
|
|
84
|
+
'/sessionarchive(或 /sessarchive)Session ID 归档一个会话;序号只做预览',
|
|
85
|
+
'/sessionarchive <Session ID> --stop 归档前先停止该会话正在运行的任务',
|
|
86
|
+
], { aliases: [{ name: 'sessarchive', menuVisible: false }] }),
|
|
87
|
+
defineCatalogCommand('ls', '列出本聊天使用过的会话(按聊天/话题隔离)', [
|
|
88
|
+
'/ls 或 /list 列出本聊天使用过的会话(● 当前,←/→ 可前后切换,✕ 已失效;列表按聊天隔离,论坛群按话题)',
|
|
89
|
+
], { aliases: [{ name: 'list', menuVisible: false }] }),
|
|
90
|
+
defineCatalogCommand('go', '切换到指定编号的会话', [
|
|
91
|
+
'/go 会话编号 切换到该会话(编号见 /ls)',
|
|
92
|
+
]),
|
|
93
|
+
defineCatalogCommand('prev', '回到上一个会话', [
|
|
94
|
+
'/prev 回到上一个会话',
|
|
95
|
+
]),
|
|
96
|
+
defineCatalogCommand('next', '前进到下一个会话', [
|
|
97
|
+
'/next 前进到下一个会话',
|
|
98
|
+
]),
|
|
99
|
+
defineCatalogCommand('drop', '从会话列表移除一条记录', [
|
|
100
|
+
'/drop 会话编号 从本聊天会话列表移除该条记录(不删除 Harness 会话)',
|
|
101
|
+
'/drop all 移除除当前会话外的全部记录(不删除 Harness 会话)',
|
|
102
|
+
]),
|
|
103
|
+
defineCatalogCommand('title', '查看或重命名会话标题', [
|
|
104
|
+
'/title 查看当前会话标题',
|
|
105
|
+
'/title 新标题 重命名当前会话',
|
|
106
|
+
'/title 会话编号 新标题 重命名指定会话',
|
|
74
107
|
]),
|
|
108
|
+
defineCatalogCommand('tail', '预览或导出会话内容', [
|
|
109
|
+
'/tail 或 /peek [编号] [条数] 预览最近消息(默认 5 条,仅提问与回答)',
|
|
110
|
+
'/tail 或 /peek [编号] file 导出整个会话为 Markdown 文件',
|
|
111
|
+
], { aliases: [{ name: 'peek', menuVisible: false }] }),
|
|
75
112
|
defineCatalogCommand('models', '按序号列出所有可用模型', [
|
|
76
113
|
'/models 按序号列出所有可用模型',
|
|
77
114
|
]),
|
|
@@ -123,6 +160,34 @@ export function commandsForChannel(channel, catalog = SHARED_COMMAND_CATALOG) {
|
|
|
123
160
|
return catalog.filter((item) => item.enabled !== false && item.channels.includes(channel));
|
|
124
161
|
}
|
|
125
162
|
|
|
163
|
+
/**
|
|
164
|
+
* Drop entries whose required Host capability is absent (e.g. /fork when the
|
|
165
|
+
* host facade exposes no sessions.fork member), so the menu and /help never
|
|
166
|
+
* promise a command that always refuses.
|
|
167
|
+
*/
|
|
168
|
+
export function availableCommandCatalog(catalog = SHARED_COMMAND_CATALOG, { supportsFork = true } = {}) {
|
|
169
|
+
return catalog.filter((item) => item.requiresSessionFork !== true || supportsFork);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* The session-navigation help lines every channel that handles them should
|
|
174
|
+
* list, without the file-export form of /tail (only file-capable channels
|
|
175
|
+
* document that). Kept here so the non-text bridges cannot drift from /ls.
|
|
176
|
+
*/
|
|
177
|
+
export const SESSION_NAV_HELP_LINES = Object.freeze([
|
|
178
|
+
'/ls 或 /list 列出本聊天使用过的会话(● 当前,←/→ 可前后切换,✕ 已失效;列表按聊天隔离,论坛群按话题)',
|
|
179
|
+
'/go 会话编号 切换到该会话(编号见 /ls)',
|
|
180
|
+
'/prev 回到上一个会话',
|
|
181
|
+
'/next 前进到下一个会话',
|
|
182
|
+
'/drop 会话编号 从本聊天会话列表移除该条记录(不删除 Harness 会话)',
|
|
183
|
+
'/title 查看当前会话标题',
|
|
184
|
+
'/title 新标题 重命名当前会话',
|
|
185
|
+
'/title 会话编号 新标题 重命名指定会话',
|
|
186
|
+
'/fork [标题] 从当前会话分支一个新会话(默认沿用父会话标题加“ (fork)”)',
|
|
187
|
+
'/reset 重置当前会话上下文(保留会话编号,旧会话可 /session 找回)',
|
|
188
|
+
'/tail 或 /peek [编号] [条数] 预览最近消息(默认 5 条,仅提问与回答)',
|
|
189
|
+
]);
|
|
190
|
+
|
|
126
191
|
export function commandHelpLines(channel, catalog = SHARED_COMMAND_CATALOG) {
|
|
127
192
|
return commandsForChannel(channel, catalog).flatMap((item) => item.help.map((line) => t(line)));
|
|
128
193
|
}
|
|
@@ -5,6 +5,8 @@ import { isControlCommand } from './control-command.mjs';
|
|
|
5
5
|
import { isHistoryCommand } from './history-command.mjs';
|
|
6
6
|
import { isModelCommand } from './model-command.mjs';
|
|
7
7
|
import { isPresetCommand } from './preset-command.mjs';
|
|
8
|
+
import { isPlanCommand, isGoalCommand } from './plan-goal-command.mjs';
|
|
9
|
+
import { isResetCommand } from './reset-command.mjs';
|
|
8
10
|
import { isWorkspaceCommand } from './workspace-command.mjs';
|
|
9
11
|
|
|
10
12
|
const SIMPLE_TEXT_COMMANDS = new Set(['/help', '/status', '/new']);
|
|
@@ -21,7 +23,7 @@ export function isSharedLocalCommand(text, {
|
|
|
21
23
|
const command = text.trim();
|
|
22
24
|
if (!command) return false;
|
|
23
25
|
if (isBatchInputCommand(command) || isHistoryCommand(command)) return true;
|
|
24
|
-
if (isClearCommand(command)) return true;
|
|
26
|
+
if (isClearCommand(command) || isResetCommand(command)) return true;
|
|
25
27
|
if (!hasFiles && (
|
|
26
28
|
isControlCommand(command)
|
|
27
29
|
|| isModelCommand(command)
|
|
@@ -30,5 +32,7 @@ export function isSharedLocalCommand(text, {
|
|
|
30
32
|
if (hasImages || hasFiles) return false;
|
|
31
33
|
return SIMPLE_TEXT_COMMANDS.has(command.toLowerCase())
|
|
32
34
|
|| isWorkspaceCommand(command)
|
|
33
|
-
|| isCompactCommand(command)
|
|
35
|
+
|| isCompactCommand(command)
|
|
36
|
+
|| isPlanCommand(command)
|
|
37
|
+
|| isGoalCommand(command);
|
|
34
38
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { deferredStateAccess, normalizeDeferredState } from './deferred-state.mjs';
|
|
2
2
|
import { mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { dirname } from 'node:path';
|
|
4
|
+
import {
|
|
5
|
+
createSessionRingSupport,
|
|
6
|
+
normalizePendingTitles,
|
|
7
|
+
normalizeSessionRings,
|
|
8
|
+
} from './session-ring-support.mjs';
|
|
4
9
|
|
|
5
10
|
/**
|
|
6
11
|
* Additional persisted keys a subclass may own. Kept intentionally small and
|
|
@@ -119,6 +124,10 @@ function normalizeState(value) {
|
|
|
119
124
|
: [],
|
|
120
125
|
cursor: Number.isSafeInteger(value.cursor) && value.cursor >= 0 ? value.cursor : null,
|
|
121
126
|
};
|
|
127
|
+
const rings = normalizeSessionRings(value.rings);
|
|
128
|
+
if (Object.keys(rings).length) normalized.rings = rings;
|
|
129
|
+
const pendingTitles = normalizePendingTitles(value.pendingTitles);
|
|
130
|
+
if (Object.keys(pendingTitles).length) normalized.pendingTitles = pendingTitles;
|
|
122
131
|
// Channel-specific extensions survive a reload; each is normalized by the
|
|
123
132
|
// subclass that owns it (see extensionKeys()).
|
|
124
133
|
for (const key of EXTENSION_KEYS) {
|
|
@@ -135,6 +144,13 @@ export class ConversationStateStore {
|
|
|
135
144
|
|
|
136
145
|
constructor(path) {
|
|
137
146
|
this.#path = path;
|
|
147
|
+
// The ring is not a store of its own: it is a view over this state object,
|
|
148
|
+
// shared with the channels that assemble their own store, so both sides
|
|
149
|
+
// cannot drift apart.
|
|
150
|
+
Object.assign(this, createSessionRingSupport({
|
|
151
|
+
state: () => this.#state,
|
|
152
|
+
persist: () => this.#persist(),
|
|
153
|
+
}));
|
|
138
154
|
}
|
|
139
155
|
|
|
140
156
|
async load() {
|
|
@@ -106,7 +106,12 @@ export function createDeferredDeliveryCoordinator({
|
|
|
106
106
|
}
|
|
107
107
|
const outcome = targetTurn === null
|
|
108
108
|
? { found: false, endSeq: -1, turn: null }
|
|
109
|
-
: extractCompletedTurnAnswer(ordered, {
|
|
109
|
+
: extractCompletedTurnAnswer(ordered, {
|
|
110
|
+
turn: targetTurn,
|
|
111
|
+
// A turn registered by a bot that hides process prose keeps that
|
|
112
|
+
// choice when it is delivered from the background.
|
|
113
|
+
finalAnswerOnly: entry.finalAnswerOnly === true || finalAnswerOnly,
|
|
114
|
+
});
|
|
110
115
|
const hasStart = ordered.some((event) => event.type === 'turn/start' && event.data?.turn === targetTurn);
|
|
111
116
|
if (!history.hasMore || hasStart) return { ...outcome, turn: targetTurn };
|
|
112
117
|
const oldest = batch[0]?.seq;
|
|
@@ -106,6 +106,7 @@ export function createDeferredDeliveryRegistry(store, {
|
|
|
106
106
|
deferredId,
|
|
107
107
|
async register({
|
|
108
108
|
key, chatId = null, target = null, replyToMessageId = null, sessionId, turn = null, afterSeq = -1, promptRpcId = null,
|
|
109
|
+
finalAnswerOnly = false,
|
|
109
110
|
}) {
|
|
110
111
|
if (typeof key !== 'string' || !key) throw new TypeError('key is required');
|
|
111
112
|
if ((!chatId || typeof chatId !== 'string') && (!target || typeof target !== 'object')) {
|
|
@@ -126,6 +127,9 @@ export function createDeferredDeliveryRegistry(store, {
|
|
|
126
127
|
attempts: 0,
|
|
127
128
|
status: 'pending',
|
|
128
129
|
createdAt: now(),
|
|
130
|
+
// Remembered per turn: the background path must keep delivering what
|
|
131
|
+
// the foreground turn would have delivered.
|
|
132
|
+
...(finalAnswerOnly === true ? { finalAnswerOnly: true } : {}),
|
|
129
133
|
};
|
|
130
134
|
const sameKey = (await store.listDeferred())
|
|
131
135
|
.filter((candidate) => candidate.key === key && candidate.status === 'pending');
|
|
@@ -134,7 +134,12 @@ export function normalizeDiagnosticDetails(value) {
|
|
|
134
134
|
if (Number.isInteger(value.httpStatus) && value.httpStatus >= 100 && value.httpStatus <= 599) result.httpStatus = value.httpStatus;
|
|
135
135
|
const provider = typeof value.providerCode === 'number' && Number.isSafeInteger(value.providerCode)
|
|
136
136
|
? String(value.providerCode) : value.providerCode;
|
|
137
|
-
|
|
137
|
+
// A provider code is either a numeric platform error code or an uppercase
|
|
138
|
+
// token such as PI_AI_ERROR. The token form used to be dropped here, so a
|
|
139
|
+
// turn failure that carried one reached the user as an unknown error with no
|
|
140
|
+
// service code at all, and the copied diagnostics named no cause either.
|
|
141
|
+
if (typeof provider === 'string'
|
|
142
|
+
&& (/^-?\d{1,12}$/u.test(provider) || /^[A-Z][A-Z0-9_]{1,63}$/u.test(provider))) result.providerCode = provider;
|
|
138
143
|
if (typeof value.pluginVersion === 'string' && /^\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?$/.test(value.pluginVersion)
|
|
139
144
|
&& value.pluginVersion.length <= 64) result.pluginVersion = value.pluginVersion;
|
|
140
145
|
if (['succeeded', 'failed', 'not-attempted', 'unknown'].includes(value.rollback)) result.rollback = value.rollback;
|