mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-09 05:20:46 +08:00
feat: add agent preset chat commands
This commit is contained in:
parent
2ad6f1a44e
commit
eea29fe296
33 changed files with 1519 additions and 234 deletions
|
|
@ -321,11 +321,20 @@ test('DingTalk executes /compact for the bound Session without prompting the mod
|
|||
assert.equal(sent.at(-1).text, '暂无可压缩的历史记录。');
|
||||
});
|
||||
|
||||
test('DingTalk lists models without prompting and help advertises all four commands', async () => {
|
||||
test('DingTalk lists models and presets without prompting and advertises fast commands', async () => {
|
||||
const fixture = stateFixture();
|
||||
const sent = [];
|
||||
const presetUpdates = [];
|
||||
let agentPreset = null;
|
||||
let asks = 0;
|
||||
let creates = 0;
|
||||
const agentPresetCatalog = {
|
||||
defaultId: 'preset-001',
|
||||
items: Array.from({ length: 70 }, (_, index) => ({
|
||||
id: `preset-${String(index + 1).padStart(3, '0')}`,
|
||||
label: `DingTalk Preset ${index + 1} ${'x'.repeat(64)}`,
|
||||
})),
|
||||
};
|
||||
const bridge = new DingtalkHarnessBridge({
|
||||
api: { sendText: async (request) => sent.push(request) },
|
||||
clientId: 'ding-client',
|
||||
|
|
@ -339,6 +348,12 @@ test('DingTalk lists models without prompting and help advertises all four comma
|
|||
}],
|
||||
failures: [],
|
||||
}),
|
||||
agentPresetSettings: async () => ({ agentPreset, agentPresetCatalog }),
|
||||
updateAgentPreset: async (value) => {
|
||||
presetUpdates.push(value);
|
||||
agentPreset = value;
|
||||
return { agentPreset, agentPresetCatalog };
|
||||
},
|
||||
createSession: async () => { creates += 1; return 'dingtalk-session'; },
|
||||
ask: async () => { asks += 1; return 'unexpected model reply'; },
|
||||
},
|
||||
|
|
@ -351,12 +366,42 @@ test('DingTalk lists models without prompting and help advertises all four comma
|
|||
assert.equal(creates, 0);
|
||||
assert.equal(fixture.sessions.size, 0);
|
||||
|
||||
const presetReplyStart = sent.length;
|
||||
await bridge.accept(message('presets-dingtalk', '/presetlist'));
|
||||
const presetReplies = sent.slice(presetReplyStart).map((entry) => entry.text);
|
||||
assert.ok(presetReplies.length > 1);
|
||||
assert.match(presetReplies.join('\n'), /preset-070/);
|
||||
assert.equal(asks, 0);
|
||||
assert.equal(creates, 0);
|
||||
assert.equal(fixture.sessions.size, 0);
|
||||
|
||||
await bridge.accept(message('preset-current-dingtalk', '/preset'));
|
||||
assert.match(sent.at(-1).text, /跟随 Host 默认/);
|
||||
assert.equal(asks, 0);
|
||||
assert.equal(creates, 0);
|
||||
|
||||
const selectReplyStart = sent.length;
|
||||
await bridge.accept(message('preset-select-dingtalk', '/preset 2'));
|
||||
assert.deepEqual(presetUpdates, ['preset-002']);
|
||||
assert.equal(sent.length, selectReplyStart + 1);
|
||||
assert.match(sent.at(-1).text, /preset-002/);
|
||||
|
||||
const defaultReplyStart = sent.length;
|
||||
await bridge.accept(message('preset-default-dingtalk', '/preset --default'));
|
||||
assert.deepEqual(presetUpdates, ['preset-002', null]);
|
||||
assert.equal(sent.length, defaultReplyStart + 1);
|
||||
assert.match(sent.at(-1).text, /跟随 Host 默认/);
|
||||
assert.equal(asks, 0);
|
||||
assert.equal(creates, 0);
|
||||
assert.equal(fixture.sessions.size, 0);
|
||||
|
||||
await bridge.accept(message('help-models-dingtalk', '/help'));
|
||||
const help = sent.at(-1).text;
|
||||
for (const command of ['/models', '/model', '/stop', '/steer']) {
|
||||
for (const command of ['/models', '/model', '/presetlist', '/preset', '/preset --default', '/stop', '/steer']) {
|
||||
assert.equal(help.includes(command), true, command);
|
||||
}
|
||||
assert.match(help, /\/model 2/);
|
||||
assert.match(help, /\/preset id:<ID>/);
|
||||
});
|
||||
|
||||
test('bridge maps a DingTalk direct conversation to one persistent Harness session', async () => {
|
||||
|
|
|
|||
|
|
@ -164,11 +164,20 @@ test('Feishu executes /compact for the bound Session without prompting the model
|
|||
assert.deepEqual(sent, ['暂无可压缩的历史记录。']);
|
||||
});
|
||||
|
||||
test('Feishu lists models without prompting and help advertises all four commands', async () => {
|
||||
test('Feishu lists models and presets without prompting and advertises fast commands', async () => {
|
||||
const fixture = stateFixture();
|
||||
const sent = [];
|
||||
const presetUpdates = [];
|
||||
let agentPreset = null;
|
||||
let asks = 0;
|
||||
let creates = 0;
|
||||
const agentPresetCatalog = {
|
||||
defaultId: 'preset-001',
|
||||
items: Array.from({ length: 70 }, (_, index) => ({
|
||||
id: `preset-${String(index + 1).padStart(3, '0')}`,
|
||||
label: `Feishu Preset ${index + 1} ${'x'.repeat(64)}`,
|
||||
})),
|
||||
};
|
||||
const bridge = new FeishuHarnessBridge({
|
||||
client: textClient(async ({ text }) => sent.push(text)),
|
||||
channel: {},
|
||||
|
|
@ -181,6 +190,12 @@ test('Feishu lists models without prompting and help advertises all four command
|
|||
}],
|
||||
failures: [],
|
||||
}),
|
||||
agentPresetSettings: async () => ({ agentPreset, agentPresetCatalog }),
|
||||
updateAgentPreset: async (value) => {
|
||||
presetUpdates.push(value);
|
||||
agentPreset = value;
|
||||
return { agentPreset, agentPresetCatalog };
|
||||
},
|
||||
createSession: async () => { creates += 1; return 'feishu-session'; },
|
||||
ask: async () => { asks += 1; return 'unexpected model reply'; },
|
||||
},
|
||||
|
|
@ -196,13 +211,47 @@ test('Feishu lists models without prompting and help advertises all four command
|
|||
assert.equal(creates, 0);
|
||||
assert.equal(fixture.sessions.size, 0);
|
||||
|
||||
const presetReplyStart = sent.length;
|
||||
await bridge.accept(event('presets-feishu', '/presetlist'));
|
||||
await bridge.waitForIdle();
|
||||
const presetReplies = sent.slice(presetReplyStart);
|
||||
assert.ok(presetReplies.length > 1);
|
||||
assert.match(presetReplies.join('\n'), /preset-070/);
|
||||
assert.equal(asks, 0);
|
||||
assert.equal(creates, 0);
|
||||
assert.equal(fixture.sessions.size, 0);
|
||||
|
||||
await bridge.accept(event('preset-current-feishu', '/preset'));
|
||||
await bridge.waitForIdle();
|
||||
assert.match(sent.at(-1), /跟随 Host 默认/);
|
||||
assert.equal(asks, 0);
|
||||
assert.equal(creates, 0);
|
||||
|
||||
const selectReplyStart = sent.length;
|
||||
await bridge.accept(event('preset-select-feishu', '/preset 2'));
|
||||
await bridge.waitForIdle();
|
||||
assert.deepEqual(presetUpdates, ['preset-002']);
|
||||
assert.equal(sent.length, selectReplyStart + 1);
|
||||
assert.match(sent.at(-1), /preset-002/);
|
||||
|
||||
const defaultReplyStart = sent.length;
|
||||
await bridge.accept(event('preset-default-feishu', '/preset --default'));
|
||||
await bridge.waitForIdle();
|
||||
assert.deepEqual(presetUpdates, ['preset-002', null]);
|
||||
assert.equal(sent.length, defaultReplyStart + 1);
|
||||
assert.match(sent.at(-1), /跟随 Host 默认/);
|
||||
assert.equal(asks, 0);
|
||||
assert.equal(creates, 0);
|
||||
assert.equal(fixture.sessions.size, 0);
|
||||
|
||||
await bridge.accept(event('help-feishu', '/help'));
|
||||
await bridge.waitForIdle();
|
||||
const help = sent.at(-1);
|
||||
for (const command of ['/models', '/model', '/stop', '/steer']) {
|
||||
for (const command of ['/models', '/model', '/presetlist', '/preset', '/preset --default', '/stop', '/steer']) {
|
||||
assert.equal(help.includes(command), true, command);
|
||||
}
|
||||
assert.match(help, /\/model 2/);
|
||||
assert.match(help, /\/preset id:<ID>/);
|
||||
});
|
||||
|
||||
test('bridge maps a Feishu conversation to a persistent Harness session and replies', async () => {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import test from 'node:test';
|
|||
import {
|
||||
cardActionProbeCard,
|
||||
menuCard,
|
||||
menuHelpText,
|
||||
} from '../../../src/channels/feishu/feishu-cards.mjs';
|
||||
|
||||
function buttons(value, result = []) {
|
||||
|
|
@ -26,6 +27,14 @@ test('menu appends watchlist and keeps repair number-only', () => {
|
|||
assert.equal(actions.includes('repair'), false);
|
||||
});
|
||||
|
||||
test('menu help advertises Agent Preset commands', () => {
|
||||
const help = menuHelpText();
|
||||
assert.match(help, /\/presetlist/);
|
||||
assert.match(help, /\/preset \[序号或完整ID\]/);
|
||||
assert.match(help, /\/preset id:<ID>/);
|
||||
assert.match(help, /\/preset --default/);
|
||||
});
|
||||
|
||||
test('card-action probe carries only its action and opaque nonce', () => {
|
||||
const nonce = '0123456789abcdef0123456789abcdef';
|
||||
const card = JSON.parse(cardActionProbeCard(nonce));
|
||||
|
|
|
|||
|
|
@ -259,11 +259,20 @@ test('QQ executes /compact for the bound Session without prompting the model', a
|
|||
assert.equal(fixture.seen.has('compact-qq'), true);
|
||||
});
|
||||
|
||||
test('QQ lists models without prompting and help advertises all four commands', async () => {
|
||||
test('QQ lists models and presets without prompting and advertises fast commands', async () => {
|
||||
const fixture = stateFixture();
|
||||
const sent = [];
|
||||
const presetUpdates = [];
|
||||
let agentPreset = null;
|
||||
let asks = 0;
|
||||
let creates = 0;
|
||||
const agentPresetCatalog = {
|
||||
defaultId: 'preset-001',
|
||||
items: Array.from({ length: 70 }, (_, index) => ({
|
||||
id: `preset-${String(index + 1).padStart(3, '0')}`,
|
||||
label: `QQ Preset ${index + 1} ${'x'.repeat(64)}`,
|
||||
})),
|
||||
};
|
||||
const bridge = new QqHarnessBridge({
|
||||
bot: { sendText: async (_target, text) => sent.push(text) },
|
||||
ownerUserOpenid: 'owner-openid',
|
||||
|
|
@ -276,6 +285,12 @@ test('QQ lists models without prompting and help advertises all four commands',
|
|||
}],
|
||||
failures: [],
|
||||
}),
|
||||
agentPresetSettings: async () => ({ agentPreset, agentPresetCatalog }),
|
||||
updateAgentPreset: async (value) => {
|
||||
presetUpdates.push(value);
|
||||
agentPreset = value;
|
||||
return { agentPreset, agentPresetCatalog };
|
||||
},
|
||||
createSession: async () => { creates += 1; return 'qq-session'; },
|
||||
ask: async () => { asks += 1; return 'unexpected model reply'; },
|
||||
},
|
||||
|
|
@ -288,12 +303,42 @@ test('QQ lists models without prompting and help advertises all four commands',
|
|||
assert.equal(creates, 0);
|
||||
assert.equal(fixture.sessions.size, 0);
|
||||
|
||||
const presetReplyStart = sent.length;
|
||||
await bridge.accept(message({ messageId: 'presets-qq', content: '/presetlist' }));
|
||||
const presetReplies = sent.slice(presetReplyStart);
|
||||
assert.ok(presetReplies.length > 1);
|
||||
assert.match(presetReplies.join('\n'), /preset-070/);
|
||||
assert.equal(asks, 0);
|
||||
assert.equal(creates, 0);
|
||||
assert.equal(fixture.sessions.size, 0);
|
||||
|
||||
await bridge.accept(message({ messageId: 'preset-current-qq', content: '/preset' }));
|
||||
assert.match(sent.at(-1), /跟随 Host 默认/);
|
||||
assert.equal(asks, 0);
|
||||
assert.equal(creates, 0);
|
||||
|
||||
const selectReplyStart = sent.length;
|
||||
await bridge.accept(message({ messageId: 'preset-select-qq', content: '/preset 2' }));
|
||||
assert.deepEqual(presetUpdates, ['preset-002']);
|
||||
assert.equal(sent.length, selectReplyStart + 1);
|
||||
assert.match(sent.at(-1), /preset-002/);
|
||||
|
||||
const defaultReplyStart = sent.length;
|
||||
await bridge.accept(message({ messageId: 'preset-default-qq', content: '/preset --default' }));
|
||||
assert.deepEqual(presetUpdates, ['preset-002', null]);
|
||||
assert.equal(sent.length, defaultReplyStart + 1);
|
||||
assert.match(sent.at(-1), /跟随 Host 默认/);
|
||||
assert.equal(asks, 0);
|
||||
assert.equal(creates, 0);
|
||||
assert.equal(fixture.sessions.size, 0);
|
||||
|
||||
await bridge.accept(message({ messageId: 'help-models-qq', content: '/help' }));
|
||||
const help = sent.at(-1);
|
||||
for (const command of ['/models', '/model', '/stop', '/steer']) {
|
||||
for (const command of ['/models', '/model', '/presetlist', '/preset', '/preset --default', '/stop', '/steer']) {
|
||||
assert.equal(help.includes(command), true, command);
|
||||
}
|
||||
assert.match(help, /\/model 2/);
|
||||
assert.match(help, /\/preset id:<ID>/);
|
||||
});
|
||||
|
||||
test('QQ remembers any authorized private inbound as a connection-test target', async () => {
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ test('all four shared text channels execute /compact outside the model prompt pa
|
|||
}
|
||||
});
|
||||
|
||||
test('all four shared text channels list models locally and advertise all four commands', async () => {
|
||||
test('all four shared text channels list models and presets locally and advertise fast commands', async () => {
|
||||
for (const [name, Bridge] of [
|
||||
['slack', SlackHarnessBridge],
|
||||
['telegram', TelegramHarnessBridge],
|
||||
|
|
@ -173,8 +173,17 @@ test('all four shared text channels list models locally and advertise all four c
|
|||
]) {
|
||||
const fixture = stateFixture();
|
||||
const sent = [];
|
||||
const presetUpdates = [];
|
||||
let agentPreset = null;
|
||||
let asks = 0;
|
||||
let creates = 0;
|
||||
const agentPresetCatalog = {
|
||||
defaultId: 'preset-001',
|
||||
items: Array.from({ length: 70 }, (_, index) => ({
|
||||
id: `preset-${String(index + 1).padStart(3, '0')}`,
|
||||
label: `${name} Preset ${index + 1} ${'x'.repeat(64)}`,
|
||||
})),
|
||||
};
|
||||
const bridge = new Bridge({
|
||||
bot: { sendText: async (_target, text) => sent.push(text) },
|
||||
state: fixture.state,
|
||||
|
|
@ -187,6 +196,12 @@ test('all four shared text channels list models locally and advertise all four c
|
|||
}],
|
||||
failures: [],
|
||||
}),
|
||||
agentPresetSettings: async () => ({ agentPreset, agentPresetCatalog }),
|
||||
updateAgentPreset: async (value) => {
|
||||
presetUpdates.push(value);
|
||||
agentPreset = value;
|
||||
return { agentPreset, agentPresetCatalog };
|
||||
},
|
||||
createSession: async () => { creates += 1; return `${name}-session`; },
|
||||
ask: async () => { asks += 1; return 'unexpected model reply'; },
|
||||
},
|
||||
|
|
@ -198,12 +213,42 @@ test('all four shared text channels list models locally and advertise all four c
|
|||
assert.equal(creates, 0, `${name} create`);
|
||||
assert.equal(fixture.sessions.size, 0, `${name} session binding`);
|
||||
|
||||
const presetReplyStart = sent.length;
|
||||
await bridge.accept(message(`presets-${name}`, '/presetlist'));
|
||||
const presetReplies = sent.slice(presetReplyStart);
|
||||
assert.ok(presetReplies.length > 1, `${name} sends every preset-list chunk`);
|
||||
assert.match(presetReplies.join('\n'), /preset-070/, name);
|
||||
assert.equal(asks, 0, `${name} preset ask`);
|
||||
assert.equal(creates, 0, `${name} preset create`);
|
||||
assert.equal(fixture.sessions.size, 0, `${name} preset session binding`);
|
||||
|
||||
await bridge.accept(message(`preset-current-${name}`, '/preset'));
|
||||
assert.match(sent.at(-1), /跟随 Host 默认/, name);
|
||||
assert.equal(asks, 0, `${name} preset current ask`);
|
||||
assert.equal(creates, 0, `${name} preset current create`);
|
||||
|
||||
const selectReplyStart = sent.length;
|
||||
await bridge.accept(message(`preset-select-${name}`, '/preset 2'));
|
||||
assert.deepEqual(presetUpdates, ['preset-002'], `${name} scoped preset update`);
|
||||
assert.equal(sent.length, selectReplyStart + 1, `${name} sends the complete select reply`);
|
||||
assert.match(sent.at(-1), /preset-002/, name);
|
||||
|
||||
const defaultReplyStart = sent.length;
|
||||
await bridge.accept(message(`preset-default-${name}`, '/preset --default'));
|
||||
assert.deepEqual(presetUpdates, ['preset-002', null], `${name} scoped preset reset`);
|
||||
assert.equal(sent.length, defaultReplyStart + 1, `${name} sends the complete default reply`);
|
||||
assert.match(sent.at(-1), /跟随 Host 默认/, name);
|
||||
assert.equal(asks, 0, `${name} mutation ask`);
|
||||
assert.equal(creates, 0, `${name} mutation create`);
|
||||
assert.equal(fixture.sessions.size, 0, `${name} mutation session binding`);
|
||||
|
||||
await bridge.accept(message(`help-${name}`, '/help'));
|
||||
const help = sent.at(-1);
|
||||
for (const command of ['/models', '/model', '/stop', '/steer']) {
|
||||
for (const command of ['/models', '/model', '/presetlist', '/preset', '/preset --default', '/stop', '/steer']) {
|
||||
assert.match(help, new RegExp(`\\${command}`), `${name} ${command}`);
|
||||
}
|
||||
assert.match(help, /\/model 2/, `${name} numbered model selection`);
|
||||
assert.match(help, /\/preset id:<ID>/, `${name} numeric preset ID selection`);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -168,6 +168,13 @@ test('Telegram API registers the command menu and commands-type menu button', as
|
|||
await api.setMyCommands({ commands: TELEGRAM_COMMAND_MENU });
|
||||
await api.setChatMenuButton();
|
||||
assert.equal(calls.length, 2);
|
||||
assert.deepEqual(
|
||||
TELEGRAM_COMMAND_MENU.filter(({ command }) => command === 'presetlist' || command === 'preset'),
|
||||
[
|
||||
{ command: 'presetlist', description: '列出可用 Agent Preset' },
|
||||
{ command: 'preset', description: '查看或设置新会话 Agent Preset' },
|
||||
],
|
||||
);
|
||||
assert.match(calls[0].url.pathname, /setMyCommands$/);
|
||||
assert.deepEqual(calls[0].body, { commands: TELEGRAM_COMMAND_MENU });
|
||||
assert.match(calls[1].url.pathname, /setChatMenuButton$/);
|
||||
|
|
|
|||
|
|
@ -153,12 +153,21 @@ test('Enterprise WeChat executes /compact for the bound Session without promptin
|
|||
assert.deepEqual(transport.active, []);
|
||||
});
|
||||
|
||||
test('Enterprise WeChat lists models without prompting and help advertises all four commands', async () => {
|
||||
test('Enterprise WeChat lists models and presets without prompting and advertises fast commands', async () => {
|
||||
const store = state();
|
||||
store.sessionFor = () => null;
|
||||
const transport = testClient();
|
||||
const presetUpdates = [];
|
||||
let agentPreset = null;
|
||||
let asks = 0;
|
||||
let creates = 0;
|
||||
const agentPresetCatalog = {
|
||||
defaultId: 'preset-001',
|
||||
items: Array.from({ length: 70 }, (_, index) => ({
|
||||
id: `preset-${String(index + 1).padStart(3, '0')}`,
|
||||
label: `WeCom Preset ${index + 1} ${'x'.repeat(64)}`,
|
||||
})),
|
||||
};
|
||||
const bridge = new WecomHarnessBridge({
|
||||
client: transport.client,
|
||||
generateStreamId: () => 'models-stream',
|
||||
|
|
@ -171,6 +180,12 @@ test('Enterprise WeChat lists models without prompting and help advertises all f
|
|||
}],
|
||||
failures: [],
|
||||
}),
|
||||
agentPresetSettings: async () => ({ agentPreset, agentPresetCatalog }),
|
||||
updateAgentPreset: async (value) => {
|
||||
presetUpdates.push(value);
|
||||
agentPreset = value;
|
||||
return { agentPreset, agentPresetCatalog };
|
||||
},
|
||||
createSession: async () => { creates += 1; return 'wecom-session'; },
|
||||
ask: async () => { asks += 1; return 'unexpected model reply'; },
|
||||
},
|
||||
|
|
@ -182,12 +197,44 @@ test('Enterprise WeChat lists models without prompting and help advertises all f
|
|||
assert.equal(asks, 0);
|
||||
assert.equal(creates, 0);
|
||||
|
||||
const presetReplyStart = transport.streamed.length;
|
||||
await bridge.accept(frame({ msgid: 'presets-wecom', text: { content: '/presetlist' } }));
|
||||
const presetReplies = transport.streamed
|
||||
.slice(presetReplyStart)
|
||||
.map((entry) => entry.content);
|
||||
assert.ok(presetReplies.length > 1);
|
||||
assert.match(presetReplies.join('\n'), /preset-070/);
|
||||
assert.equal(asks, 0);
|
||||
assert.equal(creates, 0);
|
||||
|
||||
await bridge.accept(frame({ msgid: 'preset-current-wecom', text: { content: '/preset' } }));
|
||||
assert.match(transport.streamed.at(-1).content, /跟随 Host 默认/);
|
||||
assert.equal(asks, 0);
|
||||
assert.equal(creates, 0);
|
||||
|
||||
const selectReplyStart = transport.streamed.length;
|
||||
await bridge.accept(frame({ msgid: 'preset-select-wecom', text: { content: '/preset 2' } }));
|
||||
assert.deepEqual(presetUpdates, ['preset-002']);
|
||||
assert.equal(transport.streamed.length, selectReplyStart + 1);
|
||||
assert.match(transport.streamed.at(-1).content, /preset-002/);
|
||||
assert.equal(transport.streamed.at(-1).finish, true);
|
||||
|
||||
const defaultReplyStart = transport.streamed.length;
|
||||
await bridge.accept(frame({ msgid: 'preset-default-wecom', text: { content: '/preset --default' } }));
|
||||
assert.deepEqual(presetUpdates, ['preset-002', null]);
|
||||
assert.equal(transport.streamed.length, defaultReplyStart + 1);
|
||||
assert.match(transport.streamed.at(-1).content, /跟随 Host 默认/);
|
||||
assert.equal(transport.streamed.at(-1).finish, true);
|
||||
assert.equal(asks, 0);
|
||||
assert.equal(creates, 0);
|
||||
|
||||
await bridge.accept(frame({ msgid: 'help-models-wecom', text: { content: '/help' } }));
|
||||
const help = transport.streamed.at(-1).content;
|
||||
for (const command of ['/models', '/model', '/stop', '/steer']) {
|
||||
for (const command of ['/models', '/model', '/presetlist', '/preset', '/preset --default', '/stop', '/steer']) {
|
||||
assert.equal(help.includes(command), true, command);
|
||||
}
|
||||
assert.match(help, /\/model 2/);
|
||||
assert.match(help, /\/preset id:<ID>/);
|
||||
});
|
||||
|
||||
test('Enterprise WeChat messages stream Harness progress and finalize once', async () => {
|
||||
|
|
|
|||
|
|
@ -262,11 +262,20 @@ test('Weixin executes /compact for the bound Session without prompting the model
|
|||
assert.equal(fixture.seen.has('compact-weixin'), true);
|
||||
});
|
||||
|
||||
test('Weixin lists models without prompting and help advertises all four commands', async () => {
|
||||
test('Weixin lists models and presets without prompting and advertises fast commands', async () => {
|
||||
const fixture = stateFixture();
|
||||
const sent = [];
|
||||
const presetUpdates = [];
|
||||
let agentPreset = null;
|
||||
let asks = 0;
|
||||
let creates = 0;
|
||||
const agentPresetCatalog = {
|
||||
defaultId: 'preset-001',
|
||||
items: Array.from({ length: 70 }, (_, index) => ({
|
||||
id: `preset-${String(index + 1).padStart(3, '0')}`,
|
||||
label: `Weixin Preset ${index + 1} ${'x'.repeat(64)}`,
|
||||
})),
|
||||
};
|
||||
const bridge = new WeixinHarnessBridge({
|
||||
api: { sendText: async (request) => sent.push(request) },
|
||||
baseUrl: 'https://ilinkai.weixin.qq.com/',
|
||||
|
|
@ -281,6 +290,12 @@ test('Weixin lists models without prompting and help advertises all four command
|
|||
}],
|
||||
failures: [],
|
||||
}),
|
||||
agentPresetSettings: async () => ({ agentPreset, agentPresetCatalog }),
|
||||
updateAgentPreset: async (value) => {
|
||||
presetUpdates.push(value);
|
||||
agentPreset = value;
|
||||
return { agentPreset, agentPresetCatalog };
|
||||
},
|
||||
createSession: async () => { creates += 1; return 'weixin-session'; },
|
||||
ask: async () => { asks += 1; return 'unexpected model reply'; },
|
||||
},
|
||||
|
|
@ -293,12 +308,42 @@ test('Weixin lists models without prompting and help advertises all four command
|
|||
assert.equal(creates, 0);
|
||||
assert.equal(fixture.sessions.size, 0);
|
||||
|
||||
const presetReplyStart = sent.length;
|
||||
await bridge.accept(message('presets-weixin', '/presetlist'));
|
||||
const presetReplies = sent.slice(presetReplyStart).map((entry) => entry.text);
|
||||
assert.ok(presetReplies.length > 1);
|
||||
assert.match(presetReplies.join('\n'), /preset-070/);
|
||||
assert.equal(asks, 0);
|
||||
assert.equal(creates, 0);
|
||||
assert.equal(fixture.sessions.size, 0);
|
||||
|
||||
await bridge.accept(message('preset-current-weixin', '/preset'));
|
||||
assert.match(sent.at(-1).text, /跟随 Host 默认/);
|
||||
assert.equal(asks, 0);
|
||||
assert.equal(creates, 0);
|
||||
|
||||
const selectReplyStart = sent.length;
|
||||
await bridge.accept(message('preset-select-weixin', '/preset 2'));
|
||||
assert.deepEqual(presetUpdates, ['preset-002']);
|
||||
assert.equal(sent.length, selectReplyStart + 1);
|
||||
assert.match(sent.at(-1).text, /preset-002/);
|
||||
|
||||
const defaultReplyStart = sent.length;
|
||||
await bridge.accept(message('preset-default-weixin', '/preset --default'));
|
||||
assert.deepEqual(presetUpdates, ['preset-002', null]);
|
||||
assert.equal(sent.length, defaultReplyStart + 1);
|
||||
assert.match(sent.at(-1).text, /跟随 Host 默认/);
|
||||
assert.equal(asks, 0);
|
||||
assert.equal(creates, 0);
|
||||
assert.equal(fixture.sessions.size, 0);
|
||||
|
||||
await bridge.accept(message('help-models-weixin', '/help'));
|
||||
const help = sent.at(-1).text;
|
||||
for (const command of ['/models', '/model', '/stop', '/steer']) {
|
||||
for (const command of ['/models', '/model', '/presetlist', '/preset', '/preset --default', '/stop', '/steer']) {
|
||||
assert.equal(help.includes(command), true, command);
|
||||
}
|
||||
assert.match(help, /\/model 2/);
|
||||
assert.match(help, /\/preset id:<ID>/);
|
||||
});
|
||||
|
||||
test('bridge maps the scanning Weixin user to one persistent Harness session and echoes context_token', async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue