chattercatcher 0.2.2 → 0.2.4

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/index.js CHANGED
@@ -178,6 +178,28 @@ function resolveEmbeddingApiKey(input) {
178
178
  return explicit || input.llmApiKey;
179
179
  }
180
180
 
181
+ // src/time/beijing.ts
182
+ var BEIJING_TIME_ZONE = "Asia/Shanghai";
183
+ var BEIJING_DATE_TIME_FORMATTER = new Intl.DateTimeFormat("zh-CN", {
184
+ timeZone: BEIJING_TIME_ZONE,
185
+ year: "numeric",
186
+ month: "2-digit",
187
+ day: "2-digit",
188
+ hour: "2-digit",
189
+ minute: "2-digit",
190
+ second: "2-digit",
191
+ hour12: false
192
+ });
193
+ function formatOffsetTimeZone(date) {
194
+ const parts = Object.fromEntries(
195
+ BEIJING_DATE_TIME_FORMATTER.formatToParts(date).map((part) => [part.type, part.value])
196
+ );
197
+ return `${parts.year}-${parts.month}-${parts.day}T${parts.hour}:${parts.minute}:${parts.second}+08:00`;
198
+ }
199
+ function formatBeijingTimeForPrompt(date) {
200
+ return `${formatOffsetTimeZone(date)}\uFF08\u5317\u4EAC\u65F6\u95F4\uFF0CUTC+8\uFF0CAsia/Shanghai\uFF09`;
201
+ }
202
+
181
203
  // src/cron/generator.ts
182
204
  var SYSTEM_PROMPT = "\u4F60\u6B63\u5728\u4E3A\u98DE\u4E66\u7FA4\u751F\u6210\u4E00\u6761\u5B9A\u65F6\u6D88\u606F\u3002\u53EF\u4EE5\u5148\u8C03\u7528\u641C\u7D22\u5DE5\u5177\u68C0\u7D22\u672C\u5730\u7FA4\u804A\u77E5\u8BC6\u5E93\u3002\u6700\u7EC8\u8F93\u51FA\u5FC5\u987B\u662F\u53EF\u4EE5\u76F4\u63A5\u53D1\u5230\u7FA4\u91CC\u7684\u7EAF\u6587\u672C\uFF0C\u4E0D\u8981\u8F93\u51FA\u5DE5\u5177\u8C03\u7528\u8BF4\u660E\u3002";
183
205
  function evidenceToText(evidence) {
@@ -199,7 +221,7 @@ ${input.memberPrompt}
199
221
  \u751F\u6210\u6D88\u606F\u65F6\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` : SYSTEM_PROMPT;
200
222
  const messages = [
201
223
  { role: "system", content: systemPrompt },
202
- { role: "user", content: `\u5F53\u524D\u65F6\u95F4\uFF1A${input.now.toISOString()}
224
+ { role: "user", content: `\u5F53\u524D\u65F6\u95F4\uFF1A${formatBeijingTimeForPrompt(input.now)}
203
225
  \u4EFB\u52A1\u63D0\u793A\u8BCD\uFF1A${input.prompt}` }
204
226
  ];
205
227
  const toolsByName = new Map(input.tools.map((tool) => [tool.name, tool]));
@@ -219,7 +241,7 @@ ${input.memberPrompt}
219
241
  { role: "system", content: systemPrompt },
220
242
  {
221
243
  role: "user",
222
- content: `\u5F53\u524D\u65F6\u95F4\uFF1A${input.now.toISOString()}
244
+ content: `\u5F53\u524D\u65F6\u95F4\uFF1A${formatBeijingTimeForPrompt(input.now)}
223
245
  \u4EFB\u52A1\u63D0\u793A\u8BCD\uFF1A${input.prompt}
224
246
 
225
247
  \u8BC1\u636E\uFF1A
@@ -247,7 +269,7 @@ ${evidenceToText(evidence)}`
247
269
  { role: "system", content: SYSTEM_PROMPT },
248
270
  {
249
271
  role: "user",
250
- content: `\u5F53\u524D\u65F6\u95F4\uFF1A${input.now.toISOString()}
272
+ content: `\u5F53\u524D\u65F6\u95F4\uFF1A${formatBeijingTimeForPrompt(input.now)}
251
273
  \u4EFB\u52A1\u63D0\u793A\u8BCD\uFF1A${input.prompt}
252
274
 
253
275
  \u8BC1\u636E\uFF1A
@@ -3202,7 +3224,7 @@ async function summarizeEpisodeWindow(window, model, now) {
3202
3224
  },
3203
3225
  {
3204
3226
  role: "user",
3205
- content: `\u5F53\u524D\u65F6\u95F4\uFF1A${now.toISOString()}
3227
+ content: `\u5F53\u524D\u65F6\u95F4\uFF1A${formatBeijingTimeForPrompt(now)}
3206
3228
  \u7FA4\u804A\uFF1A${window.chatName}
3207
3229
  \u65F6\u95F4\uFF1A${window.startedAt} - ${window.endedAt}
3208
3230
 
@@ -4072,7 +4094,7 @@ async function runFeishuToolLoop(input) {
4072
4094
  const systemPrompt = systemPromptParts.join("\n\n");
4073
4095
  const messages = [
4074
4096
  { role: "system", content: systemPrompt },
4075
- { role: "user", content: `\u5F53\u524D\u65F6\u95F4\uFF1A${input.now.toISOString()}
4097
+ { role: "user", content: `\u5F53\u524D\u65F6\u95F4\uFF1A${formatBeijingTimeForPrompt(input.now)}
4076
4098
  \u95EE\u9898\uFF1A${input.question}` }
4077
4099
  ];
4078
4100
  const toolsByName = new Map(input.tools.map((tool) => [tool.name, tool]));
@@ -4466,12 +4488,33 @@ function extractImageKey(response) {
4466
4488
  throw new Error("\u98DE\u4E66\u56FE\u7247\u4E0A\u4F20\u54CD\u5E94\u7F3A\u5C11 image_key\u3002");
4467
4489
  }
4468
4490
  function collectErrorFields(error) {
4469
- const fields = [error];
4470
- const value = error && typeof error === "object" ? error : {};
4471
- fields.push(value.code, value.errorCode, value.msg, value.message);
4472
- const response = value.response && typeof value.response === "object" ? value.response : {};
4473
- const data = response.data && typeof response.data === "object" ? response.data : {};
4474
- fields.push(data.code, data.errorCode, data.msg, data.message);
4491
+ const fields = [];
4492
+ const seen = /* @__PURE__ */ new Set();
4493
+ function visit(value) {
4494
+ if (value === void 0 || value === null || seen.has(value)) {
4495
+ return;
4496
+ }
4497
+ fields.push(value);
4498
+ if (typeof value !== "object") {
4499
+ return;
4500
+ }
4501
+ seen.add(value);
4502
+ if (Array.isArray(value)) {
4503
+ for (const item of value) {
4504
+ visit(item);
4505
+ }
4506
+ return;
4507
+ }
4508
+ const record = value;
4509
+ visit(record.code);
4510
+ visit(record.errorCode);
4511
+ visit(record.msg);
4512
+ visit(record.message);
4513
+ visit(record.error);
4514
+ visit(record.response);
4515
+ visit(record.data);
4516
+ }
4517
+ visit(error);
4475
4518
  return fields;
4476
4519
  }
4477
4520
  function isRichTextCompatibilityError(error) {
@@ -5402,7 +5445,7 @@ function buildEvidencePrompt(input, options = {}) {
5402
5445
  },
5403
5446
  {
5404
5447
  role: "user",
5405
- content: `\u5F53\u524D\u65F6\u95F4\uFF1A${now.toISOString()}
5448
+ content: `\u5F53\u524D\u65F6\u95F4\uFF1A${formatBeijingTimeForPrompt(now)}
5406
5449
  \u95EE\u9898\uFF1A${question}
5407
5450
 
5408
5451
  \u8BC1\u636E\u5904\u7406\u89C4\u5219\uFF1A