dsh-bagu 0.8.0 → 0.10.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/dsh-plugin.json CHANGED
@@ -3,9 +3,9 @@
3
3
  "manifestVersion": "0.15",
4
4
  "id": "dsh-bagu",
5
5
  "name": "dsh-bagu",
6
- "version": "0.8.0",
6
+ "version": "0.10.0",
7
7
  "license": "MIT",
8
- "description": "AI 对外说话前的一道门:像八股就打回,可选接梗。",
8
+ "description": "AI 对外说话两道门:八股打回,梗接住。",
9
9
  "facets": {
10
10
  "host": {
11
11
  "entry": "lib/index.js",
@@ -29,7 +29,7 @@
29
29
  "x-display": [
30
30
  {
31
31
  "title": "dsh-bagu",
32
- "description": "所有对外文本发出前过一遍,像八股就打回。可选接梗与 AI 补充。"
32
+ "description": "发出去的话像八股就打回;对方抛梗,模型看到消息前就已经把族查好了。"
33
33
  }
34
34
  ]
35
35
  }
package/lib/bridge.js CHANGED
@@ -42,8 +42,9 @@ export function bridge(text, memes, opts = {}) {
42
42
  }
43
43
 
44
44
  const hitWords = [];
45
+ const srcLow = src.toLowerCase();
45
46
  for (const k of idx.keys()) {
46
- if (src.toLowerCase().includes(k)) hitWords.push(k);
47
+ if (srcLow.includes(k)) hitWords.push(k);
47
48
  }
48
49
 
49
50
  // 2. 先算「真的提到了」—— 按 slug / title / alias 直接命中,不靠 keyword
@@ -71,8 +72,10 @@ export function bridge(text, memes, opts = {}) {
71
72
  for (const t of (m && m.tags) || []) tags.add(t);
72
73
  }
73
74
 
75
+ // 再兜一道:by 里不许出现 same 已提到的
76
+ const byClean = [...by].filter((x) => !same.has(x));
74
77
  return {
75
- by: [...by].slice(0, max),
78
+ by: byClean.slice(0, max),
76
79
  same: [...same].slice(0, max),
77
80
  tags: [...tags].slice(0, max),
78
81
  };
package/lib/config.js CHANGED
@@ -35,7 +35,9 @@ export const DEFAULTS = {
35
35
  * 养鱼那种要质量的场景可以开;日常聊天不值得。
36
36
  */
37
37
  aiBridge: false,
38
- /** AI 接梗用的 provider/baseUrl/model/key。留空就沿用宿主已配的那个。 */
38
+ /** 另配接口开关:默认走会话模型,这个开着才用下面三项 */
39
+ aiUseOwn: false,
40
+ /** AI 接梗用的 baseUrl/model/key。aiUseOwn 关着时不看这些。 */
39
41
  aiBaseUrl: '',
40
42
  aiModel: '',
41
43
  aiApiKey: '',
package/lib/index.js CHANGED
@@ -17,6 +17,7 @@ import { guard } from './guard.js';
17
17
  import { findMemes, lookup, loadMemes } from './memes.js';
18
18
  import { bridge, bridgeHint } from './bridge.js';
19
19
  import { aiBridge } from './ai-bridge.js';
20
+ import { captureRoute, sessionBridge } from './session-bridge.js';
20
21
  import { readConfig, writeConfig, CONFIG_FILE, DEFAULTS } from './config.js';
21
22
 
22
23
  export const name = 'dsh-bagu';
@@ -29,6 +30,16 @@ const syncers = new Set();
29
30
  /** 每次会话都注入,多一个字都是白烧。 */
30
31
  const PROMPT = `要发出去的话,先过 bagu_guard。被打回就改,别硬发。`;
31
32
 
33
+ /** 梗库开着时的追加。告诉 agent 有个查梗工具,遇到不认识的梗先查再答。 */
34
+ const PROMPT_MEME = `
35
+ 遇到网络梗(谐音、缩写、人名外号、视频台词)拿不准意思,先调 bagu_meme 查,别猜。
36
+ 要接梗就传 text(对方原话),它会给出同族能接的;要查单个词就传 q。
37
+ `;
38
+
39
+ /** AI 接梗开着时再加一句。 */
40
+ const PROMPT_AI = `
41
+ 接梗要给出具体那句话,调 bagu_meme 传 text,会自动调模型拼一句。`;
42
+
32
43
  /** 60 字。 */
33
44
  /** 一个工具,三种模式。描述只占一份。 */
34
45
  const TOOL_GUARD = `发出去之前过一遍。默认只回 OK 或一行改法。mode=report 给详细报告,mode=ask 给问句。`;
@@ -95,10 +106,38 @@ export function apply(root, config = {}) {
95
106
  const sync = () => {
96
107
  if (dispose) { dispose(); dispose = null; }
97
108
  if (!live.enabled || !live.prompt) return;
109
+ // ── 预查注入:用户消息一进来就先查梗,塞进上下文 ──────────
110
+ // 这是「会玩梗」和「能查梗」的分界:前者是模型还没开始想就已经知道,
111
+ // 后者要模型主动调工具(它经常不调)。
112
+ if (live.memes) {
113
+ try {
114
+ ctx.effect(() => ctx.systemPrompt.context({
115
+ name: 'bagu:prefetch',
116
+ order: 950,
117
+ text: (context) => {
118
+ try {
119
+ const text = lastUserText(context);
120
+ if (!text) return '';
121
+ const list = loadMemes();
122
+ const hint = bridgeHint(text, list);
123
+ if (!hint) return '';
124
+ return '[梗]\n' + hint + '\n照这个接,别解释梗是什么意思。';
125
+ } catch {
126
+ return '';
127
+ }
128
+ },
129
+ }), 'dsh-bagu: 预查注入');
130
+ } catch {
131
+ /* 宿主没有这个接口就算了 */
132
+ }
133
+ }
134
+
98
135
  dispose = ctx.systemPrompt.section({
99
136
  name: 'bagu:voice',
100
137
  order: live.order,
101
- text: PROMPT,
138
+ text: PROMPT +
139
+ (live.memes ? PROMPT_MEME : '') +
140
+ (live.aiBridge && live.memes ? PROMPT_AI : ''),
102
141
  });
103
142
  };
104
143
  sync();
@@ -109,6 +148,12 @@ export function apply(root, config = {}) {
109
148
  }, 'dsh-bagu: 说话的念头');
110
149
  });
111
150
 
151
+ /** 会话自己的路由(provider/model),从 agent/request 抓。抓不到就 null。 */
152
+ let getRoute = () => null;
153
+ root.inject(['llm'], (ctx) => {
154
+ getRoute = captureRoute(ctx);
155
+ });
156
+
112
157
  root.inject(['tools'], (ctx) => {
113
158
  // 一个工具,三种模式。mode 缺省是守门(日常路径),另外两个是调试用。
114
159
  if (live.memes) {
@@ -140,14 +185,23 @@ export function apply(root, config = {}) {
140
185
  const list = loadMemes();
141
186
  const hint = bridgeHint(src, list);
142
187
 
143
- // aiBridge 开着就走模型拼一句具体的接话;失败退回本地提示
188
+ // aiBridge 开着就走模型拼一句。两条路,先试会话自己的,再试自己配的 key。
144
189
  if (live.aiBridge) {
145
190
  const r = bridge(src, list);
146
191
  if (r.same.length || r.by.length) {
147
- const line = await aiBridge(src, r, {
148
- baseUrl: live.aiBaseUrl, model: live.aiModel, apiKey: live.aiApiKey,
149
- });
150
- if (line) return { ok: true, text: line };
192
+ // 路子一:DSH 会话自己的模型(不用填 key)
193
+ const llm = ctx.llm || (typeof ctx.get === 'function' ? ctx.get('llm') : undefined);
194
+ if (llm) {
195
+ const viaSession = await sessionBridge(llm, getRoute(), src, r);
196
+ if (viaSession) return { ok: true, text: viaSession };
197
+ }
198
+ // 路子二:另配的 OpenAI 兼容端点(aiUseOwn 开着才走)
199
+ if (live.aiUseOwn && live.aiBaseUrl && live.aiModel && live.aiApiKey) {
200
+ const viaApi = await aiBridge(src, r, {
201
+ baseUrl: live.aiBaseUrl, model: live.aiModel, apiKey: live.aiApiKey,
202
+ });
203
+ if (viaApi) return { ok: true, text: viaApi };
204
+ }
151
205
  }
152
206
  }
153
207
  return { ok: true, text: hint || '没接的。' };
@@ -196,9 +250,26 @@ export function apply(root, config = {}) {
196
250
  const g = guard(src, { strict: args?.strict ?? live.strict });
197
251
  // 梗库是选装的,默认关。开着就在结果后面附一句,不改判定。
198
252
  if (live.memes) {
199
- // 接梗:不是「这段用了哪些梗」,是「顺着这些能接什么」
253
+ // 发现梗就直接把接梗答案带上 —— agent 不用再调一次 bagu_meme。
200
254
  const hint = bridgeHint(src, loadMemes());
201
- if (hint) return { ok: true, text: `${g.line}|${hint}` };
255
+ if (hint) {
256
+ // AI 接梗开着就拼具体那句,失败退回族提示
257
+ const r = bridge(src, loadMemes());
258
+ if (live.aiBridge && (r.same.length || r.by.length)) {
259
+ const llm = ctx.llm || (typeof ctx.get === 'function' ? ctx.get('llm') : undefined);
260
+ if (llm) {
261
+ const viaSession = await sessionBridge(llm, getRoute(), src, r);
262
+ if (viaSession) return { ok: true, text: `${g.line}|接:${viaSession}` };
263
+ }
264
+ if (live.aiUseOwn && live.aiBaseUrl && live.aiModel && live.aiApiKey) {
265
+ const viaApi = await aiBridge(src, r, {
266
+ baseUrl: live.aiBaseUrl, model: live.aiModel, apiKey: live.aiApiKey,
267
+ });
268
+ if (viaApi) return { ok: true, text: `${g.line}|接:${viaApi}` };
269
+ }
270
+ }
271
+ return { ok: true, text: `${g.line}|${hint}` };
272
+ }
202
273
  }
203
274
  return { ok: true, text: g.line };
204
275
  },
@@ -216,6 +287,7 @@ export function apply(root, config = {}) {
216
287
  config: live,
217
288
  defaults: DEFAULTS,
218
289
  promptActive: live.enabled && live.prompt,
290
+ route: getRoute(),
219
291
  configFile: CONFIG_FILE,
220
292
  });
221
293
  }
@@ -261,3 +333,41 @@ export function apply(root, config = {}) {
261
333
  } catch { /* headless 没有 webServer 正常 */ }
262
334
  });
263
335
  }
336
+
337
+ /** 从 context 里取最后一条用户消息。抄 thawline/dsh-memewiki 的做法。 */
338
+ function lastUserText(context) {
339
+ try {
340
+ const session = context && context.agent && context.agent.session;
341
+ if (!session || typeof session.snapshotEvents !== 'function') return '';
342
+ const events = session.snapshotEvents() || [];
343
+ for (let i = events.length - 1; i >= 0; i--) {
344
+ const e = events[i];
345
+ const kind = e && (e.type || e.kind);
346
+ if (kind !== 'user/message') continue;
347
+ const payload = e.payload !== undefined ? e.payload : e.data;
348
+ const src = payload && payload.source && payload.source.kind ? String(payload.source.kind) : '';
349
+ if (src && src !== 'user') continue;
350
+ const txt = payloadText(payload);
351
+ if (txt) return txt;
352
+ }
353
+ } catch { /* 取不到就算了 */ }
354
+ return '';
355
+ }
356
+
357
+ /** 从消息 payload 里抠文本。 */
358
+ function payloadText(payload) {
359
+ if (!payload) return '';
360
+ if (typeof payload === 'string') return payload;
361
+ const parts = payload.parts || payload.content || payload.message;
362
+ if (typeof parts === 'string') return parts;
363
+ if (Array.isArray(parts)) {
364
+ return parts
365
+ .map((p) => {
366
+ if (typeof p === 'string') return p;
367
+ if (p && typeof p.text === 'string') return p.text;
368
+ return '';
369
+ })
370
+ .join('\n');
371
+ }
372
+ return '';
373
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * AI 接梗 —— 用 DSH 会话自己的模型,不填 key。
3
+ *
4
+ * 插件在 ctx 里能拿到 llm 服务,用它调模型,走的是宿主已经配好的 provider/model/套餐。
5
+ * 所以不用 API key,也不用另填接口地址。
6
+ *
7
+ * 但要拿到「当前用哪个 provider/model」,得从 agent/request 这个 waterfall 里取。
8
+ * 拿不到就退回纯本地的族提示 —— 不因为链路不通让消息发不出去。
9
+ */
10
+
11
+ /** 从 agent/request 拿到当前路由。拿不到就返回 null。 */
12
+ export function captureRoute(ctx) {
13
+ let route = null;
14
+ try {
15
+ ctx.on('agent/request', async (payload, next) => {
16
+ const resolved = await next();
17
+ if (resolved && resolved.provider && resolved.model) {
18
+ route = { provider: resolved.provider, model: resolved.model };
19
+ }
20
+ return resolved;
21
+ });
22
+ } catch {
23
+ /* 没有这个事件就算了 */
24
+ }
25
+ return () => route;
26
+ }
27
+
28
+ /**
29
+ * 调会话自己的模型拼一句接话。
30
+ *
31
+ * @param {object} llm DSH 的 llm 服务
32
+ * @param {{provider:string, model:string}|null} route
33
+ * @param {string} text 对方说的话
34
+ * @param {{same:string[], by:string[], tags:string[]}} hint
35
+ * @param {{timeoutMs?: number}} opts
36
+ * @returns {Promise<string|null>}
37
+ */
38
+ export async function sessionBridge(llm, route, text, hint, opts = {}) {
39
+ if (!llm || typeof llm.stream !== 'function') return null;
40
+ if (!route || !route.provider || !route.model) return null;
41
+ if (!hint || (!hint.same.length && !hint.by.length)) return null;
42
+
43
+ const fam = hint.by.length ? hint.by : hint.same;
44
+ const prompt = [
45
+ '你在中文互联网的评论区里接话。',
46
+ '',
47
+ `对方说:${text}`,
48
+ `这段话涉及这些梗:${hint.same.join('、') || '(没点名)'}`,
49
+ `同族还可以提到:${fam.join('、')}`,
50
+ hint.tags.length ? `这一类是:${hint.tags.join('/')}` : '',
51
+ '',
52
+ '写一句接话:',
53
+ '- 一句话,25 字以内',
54
+ '- 顺着对方的梗往下接,别解释梗是什么意思',
55
+ '- 不要用「学到了」「受益匪浅」这类套话',
56
+ '- 直接输出那句话,不要引号,不要说明',
57
+ ].filter(Boolean).join('\n');
58
+
59
+ try {
60
+ const request = {
61
+ provider: route.provider,
62
+ model: route.model,
63
+ messages: [{ role: 'user', content: prompt }],
64
+ maxTokens: 80,
65
+ temperature: 0.7,
66
+ stream: true,
67
+ };
68
+
69
+ // 有 prepareCall 就先准备,没有就直接 stream
70
+ const call = typeof llm.prepareCall === 'function'
71
+ ? await llm.prepareCall(request, AbortSignal.timeout(opts.timeoutMs || 20000))
72
+ : null;
73
+
74
+ const stream = call && typeof call.stream === 'function'
75
+ ? call.stream(request)
76
+ : llm.stream(request);
77
+
78
+ let out = '';
79
+ for await (const chunk of stream) {
80
+ const d = chunk && (chunk.delta || (chunk.content && chunk.content.text));
81
+ if (typeof d === 'string') out += d;
82
+ if (out.length > 200) break;
83
+ }
84
+
85
+ const line = out.trim().replace(/^[「"'`]+|[」"'`]+$/g, '').replace(/^(接话|回复)[::]\s*/, '').trim();
86
+ return line && line.length <= 80 ? line : null;
87
+ } catch {
88
+ return null;
89
+ }
90
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-bagu",
3
- "version": "0.8.0",
4
- "description": "给 AI 对外说话的一道门:聊天、评论、邮件、commit、PR、文档、注释都管,像八股就打回。可选接梗与 AI 补充。",
3
+ "version": "0.10.0",
4
+ "description": "两道门:发出去的话像八股就打回,对方抛梗就接住。接梗在模型看到消息前就查好。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -0,0 +1,141 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { readFileSync } from 'node:fs';
4
+
5
+ // 预查注入是「会玩梗」的关键:用户消息一进来就先查好塞进上下文,
6
+ // 不等模型主动调工具。这里测的是「注册了、能算出来、没梗不算」。
7
+ //
8
+ // lastUserText / payloadText 是 index.js 里的内部函数,不导出。
9
+ // 所以这里用搭假宿主 + 读注册出来的 context 函数来测。
10
+
11
+ const SRC = readFileSync('lib/index.js', 'utf8');
12
+
13
+ test('lastUserText 和 payloadText 都有定义', () => {
14
+ // 曾经踩过的坑:函数被引用但没定义,抛 ReferenceError 被 try/catch 吞成空,
15
+ // 外面看不出来,预查永远不命中。
16
+ assert.match(SRC, /function lastUserText\(/, 'lastUserText 没定义');
17
+ assert.match(SRC, /function payloadText\(/, 'payloadText 没定义');
18
+ const refs = (SRC.match(/lastUserText\(/g) || []).length;
19
+ const defs = (SRC.match(/function lastUserText\(/g) || []).length;
20
+ assert.ok(defs >= 1, '有引用 ' + refs + ' 处,定义 ' + defs + ' 处');
21
+ });
22
+
23
+ test('注册了 bagu:prefetch', async () => {
24
+ const { apply } = await import('../lib/index.js');
25
+ const ctxs = [];
26
+ const root = {
27
+ inject(deps, fn) {
28
+ if (deps.includes('llm')) return;
29
+ fn({
30
+ systemPrompt: {
31
+ section() { return () => {} },
32
+ context(o) { ctxs.push(o); return () => {} },
33
+ },
34
+ tools: { register() {} },
35
+ webServer: { register() { return () => {} } },
36
+ effect(fn) { return fn() },
37
+ });
38
+ },
39
+ };
40
+ // memes 默认关,先开
41
+ const fs = await import('node:fs');
42
+ const had = fs.existsSync('./config.json');
43
+ const bak = had ? fs.readFileSync('./config.json', 'utf8') : null;
44
+ fs.writeFileSync('./config.json', JSON.stringify({ enabled: true, memes: true }));
45
+ try {
46
+ apply(root, {});
47
+ } finally {
48
+ if (bak !== null) fs.writeFileSync('./config.json', bak);
49
+ else fs.unlinkSync('./config.json');
50
+ }
51
+ assert.ok(ctxs.length > 0, '没注册 context');
52
+ const c = ctxs[0];
53
+ assert.equal(c.name, 'bagu:prefetch');
54
+ assert.equal(typeof c.text, 'function', 'text 得是函数,才能每轮现算');
55
+ });
56
+
57
+ test('有梗的消息能算出注入文本', async () => {
58
+ const { apply } = await import('../lib/index.js');
59
+ const ctxs = [];
60
+ const root = {
61
+ inject(deps, fn) {
62
+ if (deps.includes('llm')) return;
63
+ fn({
64
+ systemPrompt: {
65
+ section() { return () => {} },
66
+ context(o) { ctxs.push(o); return () => {} },
67
+ },
68
+ tools: { register() {} },
69
+ webServer: { register() { return () => {} } },
70
+ effect(fn) { return fn() },
71
+ });
72
+ },
73
+ };
74
+ const fs = await import('node:fs');
75
+ const bak = fs.existsSync('./config.json') ? fs.readFileSync('./config.json', 'utf8') : null;
76
+ fs.writeFileSync('./config.json', JSON.stringify({ enabled: true, memes: true }));
77
+ try {
78
+ apply(root, {});
79
+ const c = ctxs[0];
80
+ const fake = {
81
+ agent: {
82
+ session: {
83
+ snapshotEvents: () => [
84
+ { type: 'user/message', payload: { content: '这不就是瞎问虾猜那个系列吗' } },
85
+ ],
86
+ },
87
+ },
88
+ };
89
+ const out = c.text(fake);
90
+ assert.ok(out.length > 0, '含梗的消息该算出注入文本');
91
+ assert.match(out, /瞎猜/, '该提到摸到的梗');
92
+
93
+ // 不含梗的不注入
94
+ const fake2 = {
95
+ agent: {
96
+ session: {
97
+ snapshotEvents: () => [
98
+ { type: 'user/message', payload: { content: '帮我看看这个报错' } },
99
+ ],
100
+ },
101
+ },
102
+ };
103
+ assert.equal(c.text(fake2), '', '不含梗不该注入');
104
+ } finally {
105
+ if (bak !== null) fs.writeFileSync('./config.json', bak);
106
+ else if (fs.existsSync('./config.json')) fs.unlinkSync('./config.json');
107
+ }
108
+ });
109
+
110
+ test('取不到 session 时返回空,不崩', async () => {
111
+ const { apply } = await import('../lib/index.js');
112
+ const ctxs = [];
113
+ const root = {
114
+ inject(deps, fn) {
115
+ if (deps.includes('llm')) return;
116
+ fn({
117
+ systemPrompt: {
118
+ section() { return () => {} },
119
+ context(o) { ctxs.push(o); return () => {} },
120
+ },
121
+ tools: { register() {} },
122
+ webServer: { register() { return () => {} } },
123
+ effect(fn) { return fn() },
124
+ });
125
+ },
126
+ };
127
+ const fs = await import('node:fs');
128
+ const bak = fs.existsSync('./config.json') ? fs.readFileSync('./config.json', 'utf8') : null;
129
+ fs.writeFileSync('./config.json', JSON.stringify({ enabled: true, memes: true }));
130
+ try {
131
+ apply(root, {});
132
+ const c = ctxs[0];
133
+ for (const bad of [null, {}, { agent: {} }, { agent: { session: {} } }]) {
134
+ assert.doesNotThrow(() => c.text(bad), '崩在 ' + JSON.stringify(bad));
135
+ assert.equal(c.text(bad), '');
136
+ }
137
+ } finally {
138
+ if (bak !== null) fs.writeFileSync('./config.json', bak);
139
+ else if (fs.existsSync('./config.json')) fs.unlinkSync('./config.json');
140
+ }
141
+ });
@@ -0,0 +1,74 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { captureRoute, sessionBridge } from '../lib/session-bridge.js';
4
+
5
+ test('captureRoute:没事件系统时不崩', () => {
6
+ const get = captureRoute({});
7
+ assert.equal(get(), null);
8
+ });
9
+
10
+ test('captureRoute:注册后能拿到 provider/model', async () => {
11
+ let handler = null;
12
+ const ctx = { on(evt, fn) { if (evt === 'agent/request') handler = fn; } };
13
+ const get = captureRoute(ctx);
14
+ assert.equal(get(), null);
15
+ // 模拟一次 agent/request
16
+ await handler({}, async () => ({ provider: 'deepseek', model: 'deepseek-chat' }));
17
+ assert.deepEqual(get(), { provider: 'deepseek', model: 'deepseek-chat' });
18
+ });
19
+
20
+ test('sessionBridge:没有 llm 返回 null', async () => {
21
+ const r = await sessionBridge(null, { provider: 'a', model: 'b' }, 'x', { same: ['y'], by: [], tags: [] });
22
+ assert.equal(r, null);
23
+ });
24
+
25
+ test('sessionBridge:没有 route 返回 null', async () => {
26
+ const llm = { stream() {} };
27
+ const r = await sessionBridge(llm, null, 'x', { same: ['y'], by: [], tags: [] });
28
+ assert.equal(r, null);
29
+ });
30
+
31
+ test('sessionBridge:没梗可接返回 null', async () => {
32
+ const llm = { stream() {} };
33
+ const r = await sessionBridge(llm, { provider: 'a', model: 'b' }, 'x', { same: [], by: [], tags: [] });
34
+ assert.equal(r, null);
35
+ });
36
+
37
+ test('sessionBridge:stream 抛错返回 null,不抛', async () => {
38
+ const llm = { stream() { throw new Error('boom'); } };
39
+ const r = await sessionBridge(llm, { provider: 'a', model: 'b' }, 'x', { same: ['y'], by: [], tags: [] });
40
+ assert.equal(r, null);
41
+ });
42
+
43
+ test('sessionBridge:stream 返回空返回 null', async () => {
44
+ const llm = { stream() { return (async function* () {})(); } };
45
+ const r = await sessionBridge(llm, { provider: 'a', model: 'b' }, 'x', { same: ['y'], by: [], tags: [] });
46
+ assert.equal(r, null);
47
+ });
48
+
49
+ test('sessionBridge:能拼出接话', async () => {
50
+ const llm = {
51
+ stream() {
52
+ return (async function* () {
53
+ yield { delta: '这不就是' };
54
+ yield { delta: '反向空耳那期嘛' };
55
+ })();
56
+ },
57
+ };
58
+ const r = await sessionBridge(llm, { provider: 'a', model: 'b' }, 'x',
59
+ { same: ['瞎问虾猜'], by: ['反向空耳'], tags: [] });
60
+ assert.equal(r, '这不就是反向空耳那期嘛');
61
+ });
62
+
63
+ test('sessionBridge:模型加了引号要剥掉', async () => {
64
+ const llm = {
65
+ stream() {
66
+ return (async function* () {
67
+ yield { delta: '「反向空耳那期」' };
68
+ })();
69
+ },
70
+ };
71
+ const r = await sessionBridge(llm, { provider: 'a', model: 'b' }, 'x',
72
+ { same: ['瞎问虾猜'], by: ['反向空耳'], tags: [] });
73
+ assert.equal(r, '反向空耳那期');
74
+ });