companionbot 0.16.1 → 0.16.2

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.
@@ -3,7 +3,7 @@ import { recordActivity, recordError } from "../../health/index.js";
3
3
  import { getHistory, getModel, getThinkingLevel, runWithChatId, trimHistoryByTokens, smartTrimHistory, detectImportantContext, pinContext, addMessage, } from "../../session/state.js";
4
4
  import * as persistence from "../../session/persistence.js";
5
5
  import { updateLastMessageTime } from "../../heartbeat/index.js";
6
- import { extractUrls, fetchWebContent, formatUrlContent, buildSystemPrompt, } from "../utils/index.js";
6
+ import { extractUrls, fetchWebContent, formatUrlContent, buildSystemPrompt, formatMessageTimestamp, } from "../utils/index.js";
7
7
  import { estimateMessagesTokens } from "../../utils/tokens.js";
8
8
  import { TOKENS, TELEGRAM } from "../../config/constants.js";
9
9
  import { toUserFriendlyError } from "../../utils/retry.js";
@@ -155,8 +155,9 @@ export function registerMessageHandlers(bot) {
155
155
  const response = await fetch(fileUrl);
156
156
  const buffer = await response.arrayBuffer();
157
157
  const base64 = Buffer.from(buffer).toString("base64");
158
- // 캡션이 있으면 사용, 없으면 기본 질문
159
- const caption = ctx.message.caption || "이 사진에 뭐가 있어?";
158
+ // 캡션이 있으면 사용, 없으면 기본 질문 (타임스탬프 포함)
159
+ const rawCaption = ctx.message.caption || "이 사진에 뭐가 있어?";
160
+ const caption = `${formatMessageTimestamp()} ${rawCaption}`;
160
161
  // 이미지와 텍스트를 함께 전송
161
162
  const imageContent = [
162
163
  {
@@ -174,7 +175,7 @@ export function registerMessageHandlers(bot) {
174
175
  ];
175
176
  // API용 메모리 히스토리에는 이미지 데이터 포함
176
177
  history.push({ role: "user", content: imageContent });
177
- // JSONL에는 캡션만 저장 (이미지 base64는 너무 큼)
178
+ // JSONL에는 캡션만 저장 (이미지 base64는 너무 큼) - caption에 이미 타임스탬프 포함
178
179
  persistence.appendMessage(chatId, "user", `[이미지] ${caption}`);
179
180
  try {
180
181
  const systemPrompt = await buildSystemPrompt(modelId, history);
@@ -267,8 +268,9 @@ export function registerMessageHandlers(bot) {
267
268
  messageForHistory = userMessage + "\n\n" + urlRefs.join("\n");
268
269
  }
269
270
  }
270
- // 히스토리에는 간략 버전 저장 + JSONL에 영구 저장
271
- addMessage(chatId, "user", messageForHistory);
271
+ // 히스토리에는 간략 버전 저장 + JSONL에 영구 저장 (타임스탬프 포함)
272
+ const timestampedMessage = formatMessageTimestamp() + " " + messageForHistory;
273
+ addMessage(chatId, "user", timestampedMessage);
272
274
  // Typing indicator 시작 (긴 작업 동안 유지)
273
275
  const typingIndicator = new TypingIndicator(ctx);
274
276
  typingIndicator.start();
@@ -4,3 +4,5 @@ export { extractUrls, fetchWebContent, isSafeUrl, formatUrlContent, clearUrlCach
4
4
  export { buildSystemPrompt, extractName } from "./prompt.js";
5
5
  // Cache utilities
6
6
  export { getWorkspace, invalidateWorkspaceCache, preloadWorkspace, isWorkspaceCached } from "./cache.js";
7
+ // Timestamp utilities
8
+ export { formatMessageTimestamp, addTimestampToMessage } from "./timestamp.js";
@@ -0,0 +1,43 @@
1
+ /**
2
+ * 메시지에 타임스탬프를 추가하는 유틸리티
3
+ * LLM이 시간 순서와 오늘/어제를 구분할 수 있도록 함
4
+ */
5
+ /**
6
+ * 현재 시간을 간결한 형식으로 반환
7
+ * 예: "[10:35]" 또는 "[어제 23:15]"
8
+ */
9
+ export function formatMessageTimestamp(date = new Date()) {
10
+ const now = new Date();
11
+ const isToday = date.toDateString() === now.toDateString();
12
+ const yesterday = new Date(now);
13
+ yesterday.setDate(yesterday.getDate() - 1);
14
+ const isYesterday = date.toDateString() === yesterday.toDateString();
15
+ const time = date.toLocaleTimeString("ko-KR", {
16
+ hour: "2-digit",
17
+ minute: "2-digit",
18
+ hour12: false,
19
+ timeZone: "Asia/Seoul",
20
+ });
21
+ if (isToday) {
22
+ return `[${time}]`;
23
+ }
24
+ else if (isYesterday) {
25
+ return `[어제 ${time}]`;
26
+ }
27
+ else {
28
+ // 더 오래된 경우 날짜도 포함
29
+ const dateStr = date.toLocaleDateString("ko-KR", {
30
+ month: "short",
31
+ day: "numeric",
32
+ timeZone: "Asia/Seoul",
33
+ });
34
+ return `[${dateStr} ${time}]`;
35
+ }
36
+ }
37
+ /**
38
+ * 메시지 내용에 타임스탬프 prefix 추가
39
+ */
40
+ export function addTimestampToMessage(content, date = new Date()) {
41
+ const timestamp = formatMessageTimestamp(date);
42
+ return `${timestamp} ${content}`;
43
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "companionbot",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
4
4
  "description": "AI 친구 텔레그램 봇 - Claude API 기반 개인화된 대화 상대",
5
5
  "keywords": [
6
6
  "telegram",