dominds 1.6.4 → 1.6.5
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/dist/course-transition.js +200 -0
- package/dist/dialog.js +35 -0
- package/package.json +1 -1
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.buildClearedMindInvalidationNotice = buildClearedMindInvalidationNotice;
|
|
37
|
+
exports.notifyWaitingDialogsOfClearedMind = notifyWaitingDialogsOfClearedMind;
|
|
38
|
+
const dialog_global_registry_1 = require("./dialog-global-registry");
|
|
39
|
+
const dialog_instance_registry_1 = require("./dialog-instance-registry");
|
|
40
|
+
const log_1 = require("./log");
|
|
41
|
+
const persistence_1 = require("./persistence");
|
|
42
|
+
const runtime_language_1 = require("./shared/runtime-language");
|
|
43
|
+
const inter_dialog_format_1 = require("./shared/utils/inter-dialog-format");
|
|
44
|
+
const pending_tellask_reminder_1 = require("./tools/pending-tellask-reminder");
|
|
45
|
+
function buildClearedMindInvalidationNotice(language) {
|
|
46
|
+
if (language === 'zh') {
|
|
47
|
+
return '系统反馈:诉请对象已清理头脑并开启新一程对话;本轮诉请已失效,请基于最新完整上下文重新诉请祂。';
|
|
48
|
+
}
|
|
49
|
+
return 'System notice: the callee cleared its mind and started a new course; this tellask round is no longer valid. Re-tellask with the latest complete context.';
|
|
50
|
+
}
|
|
51
|
+
async function loadWaitingOwnerRecords(dialog) {
|
|
52
|
+
const allDialogIds = await persistence_1.DialogPersistence.listAllDialogIds('running');
|
|
53
|
+
const results = [];
|
|
54
|
+
for (const candidateId of allDialogIds) {
|
|
55
|
+
if (candidateId.rootId !== dialog.id.rootId) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const pending = await persistence_1.DialogPersistence.loadPendingSubdialogs(candidateId, 'running');
|
|
59
|
+
const matching = pending.filter((record) => record.subdialogId === dialog.id.selfId);
|
|
60
|
+
if (matching.length === 0) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
results.push({
|
|
64
|
+
ownerDialogId: candidateId,
|
|
65
|
+
pendingRecords: matching,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return results;
|
|
69
|
+
}
|
|
70
|
+
function resolveOwnerDialogFromCurrentTree(currentDialog, ownerDialogId) {
|
|
71
|
+
if (currentDialog.id.selfId === currentDialog.id.rootId) {
|
|
72
|
+
const rootDialog = currentDialog;
|
|
73
|
+
if (ownerDialogId === rootDialog.id.selfId) {
|
|
74
|
+
return rootDialog;
|
|
75
|
+
}
|
|
76
|
+
return rootDialog.lookupDialog(ownerDialogId);
|
|
77
|
+
}
|
|
78
|
+
// Rationale: in this code path, every non-root dialog is a SubDialog. Prefer the live
|
|
79
|
+
// in-memory root tree first so existing dialog objects receive state/message updates.
|
|
80
|
+
const rootDialog = currentDialog.rootDialog;
|
|
81
|
+
if (ownerDialogId === rootDialog.id.selfId) {
|
|
82
|
+
return rootDialog;
|
|
83
|
+
}
|
|
84
|
+
return rootDialog.lookupDialog(ownerDialogId);
|
|
85
|
+
}
|
|
86
|
+
async function resolveOwnerDialog(currentDialog, rootId, ownerDialogId) {
|
|
87
|
+
const live = resolveOwnerDialogFromCurrentTree(currentDialog, ownerDialogId.selfId);
|
|
88
|
+
if (live) {
|
|
89
|
+
return live;
|
|
90
|
+
}
|
|
91
|
+
const rootDialog = await (0, dialog_instance_registry_1.getOrRestoreRootDialog)(rootId, 'running');
|
|
92
|
+
if (!rootDialog) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
if (ownerDialogId.selfId === rootDialog.id.selfId) {
|
|
96
|
+
return rootDialog;
|
|
97
|
+
}
|
|
98
|
+
return await (0, dialog_instance_registry_1.ensureDialogLoaded)(rootDialog, ownerDialogId, 'running');
|
|
99
|
+
}
|
|
100
|
+
async function syncPendingTellaskReminderOrThrow(ownerDialog) {
|
|
101
|
+
const changed = await (0, pending_tellask_reminder_1.syncPendingTellaskReminderState)(ownerDialog);
|
|
102
|
+
if (!changed) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
await ownerDialog.processReminderUpdates();
|
|
106
|
+
}
|
|
107
|
+
async function reviveOwnerDialogIfReady(ownerDialog) {
|
|
108
|
+
const hasQ4H = await ownerDialog.hasPendingQ4H();
|
|
109
|
+
const hasPendingSubdialogs = await ownerDialog.hasPendingSubdialogs();
|
|
110
|
+
if (hasQ4H || hasPendingSubdialogs) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (ownerDialog.id.selfId === ownerDialog.id.rootId) {
|
|
114
|
+
const hasRegistryEntry = dialog_global_registry_1.globalDialogRegistry.get(ownerDialog.id.rootId) !== undefined;
|
|
115
|
+
await persistence_1.DialogPersistence.setNeedsDrive(ownerDialog.id, true, ownerDialog.status);
|
|
116
|
+
if (hasRegistryEntry) {
|
|
117
|
+
dialog_global_registry_1.globalDialogRegistry.markNeedsDrive(ownerDialog.id.rootId, {
|
|
118
|
+
source: 'kernel_driver_supply_response',
|
|
119
|
+
reason: 'callee_cleared_mind_invalidated_pending_waiters',
|
|
120
|
+
});
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const { driveDialogStream } = await Promise.resolve().then(() => __importStar(require('./llm/kernel-driver')));
|
|
125
|
+
void driveDialogStream(ownerDialog, undefined, true, {
|
|
126
|
+
suppressDiligencePush: ownerDialog.disableDiligencePush,
|
|
127
|
+
source: 'kernel_driver_supply_response_parent_revive',
|
|
128
|
+
reason: 'callee_cleared_mind_invalidated_pending_waiters',
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
async function notifyWaitingDialogsOfClearedMind(dialog) {
|
|
132
|
+
if (dialog.status !== 'running') {
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
const waitingOwners = await loadWaitingOwnerRecords(dialog);
|
|
136
|
+
if (waitingOwners.length === 0) {
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
const language = (0, runtime_language_1.getWorkLanguage)();
|
|
140
|
+
const responseBody = buildClearedMindInvalidationNotice(language);
|
|
141
|
+
let totalInvalidated = 0;
|
|
142
|
+
for (const owner of waitingOwners) {
|
|
143
|
+
const ownerDialog = await resolveOwnerDialog(dialog, dialog.id.rootId, owner.ownerDialogId);
|
|
144
|
+
if (!ownerDialog) {
|
|
145
|
+
throw new Error(`Failed to restore owner dialog while invalidating cleared-mind tellask waiters: root=${dialog.id.rootId} owner=${owner.ownerDialogId.valueOf()} callee=${dialog.id.valueOf()}`);
|
|
146
|
+
}
|
|
147
|
+
const pendingOutcome = await persistence_1.DialogPersistence.mutatePendingSubdialogs(ownerDialog.id, (previous) => {
|
|
148
|
+
const next = previous.filter((record) => record.subdialogId !== dialog.id.selfId);
|
|
149
|
+
return { kind: 'replace', records: next };
|
|
150
|
+
}, undefined, ownerDialog.status);
|
|
151
|
+
for (const pendingRecord of owner.pendingRecords) {
|
|
152
|
+
const requesterId = ownerDialog.agentId;
|
|
153
|
+
const response = (0, inter_dialog_format_1.formatTeammateResponseContent)({
|
|
154
|
+
callName: pendingRecord.callName,
|
|
155
|
+
responderId: dialog.agentId,
|
|
156
|
+
requesterId,
|
|
157
|
+
mentionList: pendingRecord.mentionList,
|
|
158
|
+
sessionSlug: pendingRecord.sessionSlug,
|
|
159
|
+
tellaskContent: pendingRecord.tellaskContent,
|
|
160
|
+
responseBody,
|
|
161
|
+
status: 'failed',
|
|
162
|
+
language,
|
|
163
|
+
});
|
|
164
|
+
await ownerDialog.receiveTeammateResponse(dialog.agentId, pendingRecord.callName, pendingRecord.mentionList, pendingRecord.tellaskContent, 'failed', dialog.id, {
|
|
165
|
+
response,
|
|
166
|
+
agentId: dialog.agentId,
|
|
167
|
+
callId: pendingRecord.callId,
|
|
168
|
+
originMemberId: requesterId,
|
|
169
|
+
sessionSlug: pendingRecord.sessionSlug,
|
|
170
|
+
});
|
|
171
|
+
const immediateMirror = {
|
|
172
|
+
type: 'tellask_result_msg',
|
|
173
|
+
role: 'tool',
|
|
174
|
+
responderId: dialog.agentId,
|
|
175
|
+
mentionList: pendingRecord.mentionList,
|
|
176
|
+
tellaskContent: pendingRecord.tellaskContent,
|
|
177
|
+
status: 'failed',
|
|
178
|
+
callId: pendingRecord.callId,
|
|
179
|
+
content: response,
|
|
180
|
+
};
|
|
181
|
+
await ownerDialog.addChatMessages(immediateMirror);
|
|
182
|
+
totalInvalidated += 1;
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
await syncPendingTellaskReminderOrThrow(ownerDialog);
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
log_1.log.error('Failed to sync pending-tellask reminder after cleared-mind invalidation', err, {
|
|
189
|
+
rootId: dialog.id.rootId,
|
|
190
|
+
calleeDialogId: dialog.id.selfId,
|
|
191
|
+
ownerDialogId: ownerDialog.id.selfId,
|
|
192
|
+
});
|
|
193
|
+
throw err;
|
|
194
|
+
}
|
|
195
|
+
if (pendingOutcome.records.length === 0) {
|
|
196
|
+
await reviveOwnerDialogIfReady(ownerDialog);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return totalInvalidated;
|
|
200
|
+
}
|
package/dist/dialog.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.DialogStore = exports.RootDialog = exports.SubDialog = exports.Dialog = exports.DialogID = void 0;
|
|
4
37
|
/**
|
|
@@ -663,6 +696,8 @@ class Dialog {
|
|
|
663
696
|
runControl: runControlSpec,
|
|
664
697
|
});
|
|
665
698
|
}
|
|
699
|
+
const { notifyWaitingDialogsOfClearedMind } = await Promise.resolve().then(() => __importStar(require('./course-transition')));
|
|
700
|
+
await notifyWaitingDialogsOfClearedMind(this);
|
|
666
701
|
}
|
|
667
702
|
// Proxy methods for DialogStore - route calls through dialog object instead of direct dlgStore access
|
|
668
703
|
async receiveFuncResult(result) {
|