chattercatcher 0.1.29 → 0.1.30

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/cli.js CHANGED
@@ -8,7 +8,7 @@ import fs15 from "fs/promises";
8
8
  // package.json
9
9
  var package_default = {
10
10
  name: "chattercatcher",
11
- version: "0.1.29",
11
+ version: "0.1.30",
12
12
  description: "\u672C\u5730\u4F18\u5148\u7684\u98DE\u4E66/Lark \u5BB6\u5EAD\u7FA4\u77E5\u8BC6\u5E93\u673A\u5668\u4EBA",
13
13
  type: "module",
14
14
  main: "dist/index.js",
@@ -4019,6 +4019,20 @@ import crypto6 from "crypto";
4019
4019
  function clampLimit(limit) {
4020
4020
  return Math.max(1, Math.min(200, Math.trunc(limit)));
4021
4021
  }
4022
+ function mapQaLogRow(row) {
4023
+ return {
4024
+ id: row.id,
4025
+ chatId: row.chat_id,
4026
+ questionMessageId: row.question_message_id,
4027
+ question: row.question,
4028
+ answer: row.answer,
4029
+ citations: JSON.parse(row.citations_json),
4030
+ retrievalDebug: JSON.parse(row.retrieval_debug_json),
4031
+ status: row.status,
4032
+ error: row.error,
4033
+ createdAt: row.created_at
4034
+ };
4035
+ }
4022
4036
  var QaLogRepository = class {
4023
4037
  constructor(database) {
4024
4038
  this.database = database;
@@ -4097,18 +4111,29 @@ var QaLogRepository = class {
4097
4111
  LIMIT ?
4098
4112
  `
4099
4113
  ).all(clampLimit(limit));
4100
- return rows.map((row) => ({
4101
- id: row.id,
4102
- chatId: row.chat_id,
4103
- questionMessageId: row.question_message_id,
4104
- question: row.question,
4105
- answer: row.answer,
4106
- citations: JSON.parse(row.citations_json),
4107
- retrievalDebug: JSON.parse(row.retrieval_debug_json),
4108
- status: row.status,
4109
- error: row.error,
4110
- createdAt: row.created_at
4111
- }));
4114
+ return rows.map(mapQaLogRow);
4115
+ }
4116
+ listRecentByChat(chatId, limit) {
4117
+ const rows = this.database.prepare(
4118
+ `
4119
+ SELECT
4120
+ id,
4121
+ chat_id,
4122
+ question_message_id,
4123
+ question,
4124
+ answer,
4125
+ citations_json,
4126
+ retrieval_debug_json,
4127
+ status,
4128
+ error,
4129
+ created_at
4130
+ FROM qa_logs
4131
+ WHERE chat_id = ? AND status = 'answered'
4132
+ ORDER BY created_at DESC
4133
+ LIMIT ?
4134
+ `
4135
+ ).all(chatId, clampLimit(limit));
4136
+ return rows.map(mapQaLogRow);
4112
4137
  }
4113
4138
  getCount() {
4114
4139
  const row = this.database.prepare("SELECT COUNT(*) AS count FROM qa_logs").get();
@@ -4180,10 +4205,16 @@ async function runFeishuToolLoop(input2) {
4180
4205
  }
4181
4206
  const maxModelTurns = input2.maxModelTurns ?? DEFAULT_MAX_MODEL_TURNS;
4182
4207
  const maxToolCalls = input2.maxToolCalls ?? DEFAULT_MAX_TOOL_CALLS;
4183
- const systemPrompt = input2.memberPrompt ? `${FEISHU_TOOL_SYSTEM_PROMPT}
4184
-
4185
- ${input2.memberPrompt}
4186
- \u56DE\u7B54\u4E2D\u9047\u5230\u4E0A\u8FF0 ID \u65F6\u4F18\u5148\u4F7F\u7528\u5BF9\u5E94\u7FA4\u6635\u79F0\uFF1B\u6CA1\u6709\u6620\u5C04\u65F6\u4FDD\u7559\u539F ID\uFF0C\u4E0D\u8981\u7F16\u9020\u6635\u79F0\u3002` : FEISHU_TOOL_SYSTEM_PROMPT;
4208
+ const systemPromptParts = [FEISHU_TOOL_SYSTEM_PROMPT];
4209
+ if (input2.memberPrompt) {
4210
+ systemPromptParts.push(`${input2.memberPrompt}
4211
+ \u56DE\u7B54\u4E2D\u9047\u5230\u4E0A\u8FF0 ID \u65F6\u4F18\u5148\u4F7F\u7528\u5BF9\u5E94\u7FA4\u6635\u79F0\uFF1B\u6CA1\u6709\u6620\u5C04\u65F6\u4FDD\u7559\u539F ID\uFF0C\u4E0D\u8981\u7F16\u9020\u6635\u79F0\u3002`);
4212
+ }
4213
+ if (input2.conversationContext) {
4214
+ systemPromptParts.push(`${input2.conversationContext}
4215
+ \u8FD9\u4E9B\u662F\u5F53\u524D\u7FA4\u804A\u91CC\u6700\u8FD1\u51E0\u8F6E\u4F60\u548C\u7528\u6237\u7684\u95EE\u7B54\uFF0C\u53EA\u4F5C\u4E3A\u7406\u89E3\u7701\u7565\u6307\u4EE3\u548C\u8FDE\u7EED\u8FFD\u95EE\u7684\u4E0A\u4E0B\u6587\uFF1B\u5982\u679C\u4E0E\u68C0\u7D22\u8BC1\u636E\u51B2\u7A81\uFF0C\u4EE5\u68C0\u7D22\u8BC1\u636E\u4E3A\u51C6\u3002`);
4216
+ }
4217
+ const systemPrompt = systemPromptParts.join("\n\n");
4187
4218
  const messages = [
4188
4219
  { role: "system", content: systemPrompt },
4189
4220
  { role: "user", content: `\u5F53\u524D\u65F6\u95F4\uFF1A${input2.now.toISOString()}
@@ -4247,6 +4278,13 @@ ${input2.memberPrompt}
4247
4278
  return "\u62B1\u6B49\uFF0C\u56DE\u7B54\u751F\u6210\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002";
4248
4279
  }
4249
4280
  }
4281
+ function formatConversationContext(records) {
4282
+ const lines = records.slice().reverse().map((record, index2) => `\u7B2C ${index2 + 1} \u8F6E
4283
+ \u7528\u6237\uFF1A${record.question}
4284
+ \u52A9\u624B\uFF1A${record.answer}`);
4285
+ return lines.length ? `\u8FD1\u671F\u5BF9\u8BDD\u4E0A\u4E0B\u6587\uFF1A
4286
+ ${lines.join("\n\n")}` : "";
4287
+ }
4250
4288
  function isMentionForBot(mention, config) {
4251
4289
  if (!config.feishu.botOpenId) {
4252
4290
  return false;
@@ -4356,12 +4394,14 @@ var FeishuQuestionHandler = class {
4356
4394
  const allTools = [...tools, ...cronTools];
4357
4395
  const memberRepository = this.options.memberRepository ?? new FeishuMemberRepository(this.options.database);
4358
4396
  const memberPrompt = formatFeishuMemberPrompt(memberRepository.listByChat(decision.chatId));
4397
+ const conversationContext = formatConversationContext(qaLogs.listRecentByChat(decision.chatId, 6));
4359
4398
  const answer = await runFeishuToolLoop({
4360
4399
  question: decision.question,
4361
4400
  now,
4362
4401
  tools: allTools,
4363
4402
  model: this.options.model,
4364
- memberPrompt
4403
+ memberPrompt,
4404
+ conversationContext
4365
4405
  });
4366
4406
  qaLogs.create({
4367
4407
  chatId: decision.chatId,