mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-16 23:43:28 +08:00
feat(context-enhancement): 新增 chatId 与 threadId 来源字段 (#128)
Add chatId and threadId source fields across all nine IM channels, update UI/docs/tests, reconcile the latest main branch, and credit @Chan-0312 as a contributor.
This commit is contained in:
parent
3c71712962
commit
3562b9244e
19 changed files with 266 additions and 158 deletions
|
|
@ -185,16 +185,18 @@ test('group and direct messages use only their own fields and guidance', () => {
|
|||
assert.doesNotMatch(direct, /GROUP-ONLY-TOKEN|channel/);
|
||||
});
|
||||
|
||||
test('all 64 source-field subsets are projected in canonical order with no hidden fields', () => {
|
||||
test('all 256 source-field subsets are projected in canonical order with no hidden fields', () => {
|
||||
const expected = {
|
||||
channel: 'telegram', conversationType: 'group',
|
||||
senderId: '123', senderName: '张三', conversationTitle: '测试群', botId: 'bot_one',
|
||||
senderId: '123', senderName: '张三', conversationTitle: '测试群',
|
||||
chatId: 'chat-123', threadId: 'thread-9', botId: 'bot_one',
|
||||
};
|
||||
for (let mask = 0; mask < 64; mask += 1) {
|
||||
for (let mask = 0; mask < 256; mask += 1) {
|
||||
const fields = CONTEXT_ENHANCEMENT_FIELDS.filter((_field, index) => mask & (1 << index));
|
||||
const selected = snapshot(config({ fields: [...fields].reverse() }));
|
||||
const actual = enhanceContextContent(' original\n', selected, () => ({
|
||||
channel: 'telegram', senderId: 123, senderName: '张三', conversationTitle: '测试群',
|
||||
chatId: 'chat-123', threadId: 'thread-9',
|
||||
botId: 'platform-secret-not-used', conversationType: 'direct', token: 'never-sent',
|
||||
}));
|
||||
if (fields.length === 0) {
|
||||
|
|
@ -247,10 +249,13 @@ test('source strings are bounded, control-free and JSON-safe without invoking ex
|
|||
const name = '"\n</dsh_im_source>&\u0000\u202e' + '名'.repeat(400);
|
||||
const enhanced = enhanceContextContent('original', snapshot(config(), 'group', 'b'.repeat(300)), () => ({
|
||||
channel: 'discord', senderId: 'u'.repeat(400), senderName: name,
|
||||
chatId: 'c'.repeat(400), threadId: 't'.repeat(400),
|
||||
}));
|
||||
const source = sourceOf(enhanced);
|
||||
assert.equal(source.senderId.length, 256);
|
||||
assert.equal(source.senderName.length, 256);
|
||||
assert.equal(source.chatId.length, 256);
|
||||
assert.equal(source.threadId.length, 256);
|
||||
assert.equal(source.botId.length, 128);
|
||||
assert.doesNotMatch(source.senderName, /[\u0000-\u001f\u202e]/);
|
||||
assert.equal(enhanced.split('</dsh_im_source>').length, 2);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue