mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-11 15:53:17 +08:00
feat: support compact command across IM channels
This commit is contained in:
parent
4545cfe9c5
commit
1cc7a26f30
40 changed files with 728 additions and 136 deletions
|
|
@ -76,6 +76,31 @@ function stateFixture() {
|
|||
};
|
||||
}
|
||||
|
||||
test('DingTalk executes /compact for the bound Session without prompting the model', async () => {
|
||||
const fixture = stateFixture();
|
||||
fixture.sessions.set('p2p:staff-approved', 'session-compact');
|
||||
const sent = [];
|
||||
const executed = [];
|
||||
const bridge = new DingtalkHarnessBridge({
|
||||
api: { sendText: async (request) => sent.push(request) },
|
||||
clientId: 'ding-client',
|
||||
clientSecret: 'host-secret',
|
||||
harness: {
|
||||
executeCommand: async (sessionId, line) => {
|
||||
executed.push({ sessionId, line });
|
||||
return { commandId: 'compact-dingtalk', result: { kind: 'success', text: 'No compactable history yet.' } };
|
||||
},
|
||||
ask: async () => assert.fail('/compact must not be submitted to the model'),
|
||||
},
|
||||
state: fixture.state,
|
||||
});
|
||||
|
||||
await bridge.accept(message('compact-dingtalk', '/compact'));
|
||||
|
||||
assert.deepEqual(executed, [{ sessionId: 'session-compact', line: '/compact' }]);
|
||||
assert.equal(sent.at(-1).text, '暂无可压缩的历史记录。');
|
||||
});
|
||||
|
||||
test('bridge maps a DingTalk direct conversation to one persistent Harness session', async () => {
|
||||
const fixture = stateFixture();
|
||||
const sent = [];
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ function controller() {
|
|||
test('Host exports the DingTalk plugin identity and required services', () => {
|
||||
const plugin = createDingtalkHostPlugin({ controller: controller() });
|
||||
assert.equal(name, 'dsh-dingtalk-host');
|
||||
assert.deepEqual(inject, ['connection', 'credentials', 'webServer']);
|
||||
assert.deepEqual(inject, ['connection', 'credentials', 'webServer', 'typertGateway']);
|
||||
assert.equal(plugin.name, name);
|
||||
assert.deepEqual(plugin.inject, inject);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -79,6 +79,32 @@ function textClient(sendText) {
|
|||
};
|
||||
}
|
||||
|
||||
test('Feishu executes /compact for the bound Session without prompting the model', async () => {
|
||||
const fixture = stateFixture([['p2p:ou_user', 'session-compact']]);
|
||||
const sent = [];
|
||||
const executed = [];
|
||||
const bridge = new FeishuHarnessBridge({
|
||||
client: textClient(async ({ text }) => sent.push(text)),
|
||||
channel: {},
|
||||
harness: {
|
||||
executeCommand: async (sessionId, line) => {
|
||||
executed.push({ sessionId, line });
|
||||
return { commandId: 'compact-feishu', result: { kind: 'success', text: 'No compactable history yet.' } };
|
||||
},
|
||||
ask: async () => assert.fail('/compact must not be submitted to the model'),
|
||||
},
|
||||
state: fixture.state,
|
||||
status: bridgeStatus(),
|
||||
allowedSenderOpenIds: new Set(['ou_user']),
|
||||
});
|
||||
|
||||
await bridge.accept(event('compact-feishu', '/compact'));
|
||||
await bridge.waitForIdle();
|
||||
|
||||
assert.deepEqual(executed, [{ sessionId: 'session-compact', line: '/compact' }]);
|
||||
assert.deepEqual(sent, ['暂无可压缩的历史记录。']);
|
||||
});
|
||||
|
||||
test('bridge maps a Feishu conversation to a persistent Harness session and replies', async () => {
|
||||
const sent = [];
|
||||
const reactions = [];
|
||||
|
|
|
|||
|
|
@ -51,6 +51,30 @@ function message(overrides = {}) {
|
|||
};
|
||||
}
|
||||
|
||||
test('QQ executes /compact for the bound Session without prompting the model', async () => {
|
||||
const fixture = stateFixture([['c2c:owner-openid', 'session-compact']]);
|
||||
const sent = [];
|
||||
const executed = [];
|
||||
const bridge = new QqHarnessBridge({
|
||||
bot: { sendText: async (_target, text) => sent.push(text) },
|
||||
ownerUserOpenid: 'owner-openid',
|
||||
harness: {
|
||||
executeCommand: async (sessionId, line) => {
|
||||
executed.push({ sessionId, line });
|
||||
return { commandId: 'compact-qq', result: { kind: 'success', text: 'Compacted 3 history items (~900 tokens).' } };
|
||||
},
|
||||
ask: async () => assert.fail('/compact must not be submitted to the model'),
|
||||
},
|
||||
state: fixture.state,
|
||||
});
|
||||
|
||||
await bridge.accept(message({ messageId: 'compact-qq', content: '/compact' }));
|
||||
|
||||
assert.deepEqual(executed, [{ sessionId: 'session-compact', line: '/compact' }]);
|
||||
assert.deepEqual(sent, ['已压缩 3 条历史记录(约 900 个 token)。']);
|
||||
assert.equal(fixture.seen.has('compact-qq'), true);
|
||||
});
|
||||
|
||||
test('QQ private messages stream Harness snapshots and finalize once', async () => {
|
||||
const frames = [];
|
||||
const sent = [];
|
||||
|
|
|
|||
|
|
@ -117,6 +117,38 @@ function createBridge({ harness, state, bot, signal, logger } = {}) {
|
|||
});
|
||||
}
|
||||
|
||||
test('all four shared text channels execute /compact outside the model prompt path', async () => {
|
||||
for (const [name, Bridge] of [
|
||||
['slack', SlackHarnessBridge],
|
||||
['telegram', TelegramHarnessBridge],
|
||||
['discord', DiscordHarnessBridge],
|
||||
['whatsapp', WhatsappHarnessBridge],
|
||||
]) {
|
||||
const fixture = stateFixture({ 'direct:chat-a': `session-${name}` });
|
||||
const sent = [];
|
||||
const executed = [];
|
||||
const bridge = new Bridge({
|
||||
bot: { sendText: async (_target, text) => sent.push(text) },
|
||||
state: fixture.state,
|
||||
harness: {
|
||||
executeCommand: async (sessionId, line) => {
|
||||
executed.push({ sessionId, line });
|
||||
return {
|
||||
commandId: `command-${name}`,
|
||||
result: { kind: 'success', text: 'Compacted 12 history items (~3456 tokens).' },
|
||||
};
|
||||
},
|
||||
ask: async () => assert.fail('/compact must not be submitted to the model'),
|
||||
},
|
||||
});
|
||||
|
||||
await bridge.accept(message(`compact-${name}`, '/compact'));
|
||||
|
||||
assert.deepEqual(executed, [{ sessionId: `session-${name}`, line: '/compact' }]);
|
||||
assert.deepEqual(sent, ['已压缩 12 条历史记录(约 3456 个 token)。']);
|
||||
}
|
||||
});
|
||||
|
||||
test('answers a multi-question interaction on the fast lane with canonical values', async () => {
|
||||
const fixture = stateFixture();
|
||||
const sent = [];
|
||||
|
|
|
|||
|
|
@ -91,6 +91,31 @@ function questionInteraction({
|
|||
};
|
||||
}
|
||||
|
||||
test('Enterprise WeChat executes /compact for the bound Session without prompting the model', async () => {
|
||||
const store = state();
|
||||
const transport = testClient();
|
||||
const executed = [];
|
||||
const bridge = new WecomHarnessBridge({
|
||||
client: transport.client,
|
||||
generateStreamId: () => 'unused-stream',
|
||||
harness: {
|
||||
executeCommand: async (sessionId, line) => {
|
||||
executed.push({ sessionId, line });
|
||||
return { commandId: 'compact-wecom', result: { kind: 'success', text: 'No compactable history yet.' } };
|
||||
},
|
||||
ask: async () => assert.fail('/compact must not be submitted to the model'),
|
||||
},
|
||||
state: store,
|
||||
});
|
||||
|
||||
await bridge.accept(frame({ msgid: 'compact-wecom', text: { content: '/compact' } }));
|
||||
|
||||
assert.deepEqual(executed, [{ sessionId: 'session-existing', line: '/compact' }]);
|
||||
assert.equal(transport.streamed.at(-1).content, '暂无可压缩的历史记录。');
|
||||
assert.equal(transport.streamed.at(-1).finish, true);
|
||||
assert.deepEqual(transport.active, []);
|
||||
});
|
||||
|
||||
test('Enterprise WeChat messages stream Harness progress and finalize once', async () => {
|
||||
const replies = [];
|
||||
const active = [];
|
||||
|
|
|
|||
|
|
@ -63,6 +63,33 @@ function stateFixture() {
|
|||
};
|
||||
}
|
||||
|
||||
test('Weixin executes /compact for the bound Session without prompting the model', async () => {
|
||||
const fixture = stateFixture();
|
||||
fixture.sessions.set('p2p:owner-user', 'session-compact');
|
||||
const sent = [];
|
||||
const executed = [];
|
||||
const bridge = new WeixinHarnessBridge({
|
||||
api: { sendText: async (request) => sent.push(request) },
|
||||
baseUrl: 'https://ilinkai.weixin.qq.com/',
|
||||
token: 'host-token',
|
||||
ownerUserId: 'owner-user',
|
||||
harness: {
|
||||
executeCommand: async (sessionId, line) => {
|
||||
executed.push({ sessionId, line });
|
||||
return { commandId: 'compact-weixin', result: { kind: 'success', text: 'No compactable history yet.' } };
|
||||
},
|
||||
ask: async () => assert.fail('/compact must not be submitted to the model'),
|
||||
},
|
||||
state: fixture.state,
|
||||
});
|
||||
|
||||
await bridge.accept(message('compact-weixin', '/compact'));
|
||||
|
||||
assert.deepEqual(executed, [{ sessionId: 'session-compact', line: '/compact' }]);
|
||||
assert.equal(sent.at(-1).text, '暂无可压缩的历史记录。');
|
||||
assert.equal(fixture.seen.has('compact-weixin'), true);
|
||||
});
|
||||
|
||||
test('bridge maps the scanning Weixin user to one persistent Harness session and echoes context_token', async () => {
|
||||
const sent = [];
|
||||
const asked = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue