Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { formatContextForPrompt } from "./services/context.js";
import { getTags } from "./services/tags.js";
import { stripPrivateContent, isFullyPrivate } from "./services/privacy.js";
import { createCompactionHook, type CompactionContext } from "./services/compaction.js";
import { generatePartId } from "./services/ids.js";

import { isConfigured, CONFIG } from "./config.js";
import { log } from "./services/logger.js";
Expand Down Expand Up @@ -112,7 +113,7 @@ export const SupermemoryPlugin: Plugin = async (ctx: PluginInput) => {
if (detectMemoryKeyword(userMessage)) {
log("chat.message: memory keyword detected");
const nudgePart: Part = {
id: `supermemory-nudge-${Date.now()}`,
id: generatePartId(),
sessionID: input.sessionID,
messageID: output.message.id,
type: "text",
Expand Down Expand Up @@ -157,7 +158,7 @@ export const SupermemoryPlugin: Plugin = async (ctx: PluginInput) => {

if (memoryContext) {
const contextPart: Part = {
id: `supermemory-context-${Date.now()}`,
id: generatePartId(),
sessionID: input.sessionID,
messageID: output.message.id,
type: "text",
Expand Down
13 changes: 1 addition & 12 deletions src/services/compaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { homedir } from "node:os";
import { supermemoryClient } from "./client.js";
import { log } from "./logger.js";
import { CONFIG } from "../config.js";
import { generatePartId, generateMessageId } from "./ids.js";

const MESSAGE_STORAGE = join(homedir(), ".opencode", "messages");
const PART_STORAGE = join(homedir(), ".opencode", "parts");
Expand Down Expand Up @@ -152,18 +153,6 @@ function findNearestMessageWithFields(messageDir: string): StoredMessage | null
return null;
}

function generateMessageId(): string {
const timestamp = Date.now().toString(16);
const random = Math.random().toString(36).substring(2, 14);
return `msg_${timestamp}${random}`;
}

function generatePartId(): string {
const timestamp = Date.now().toString(16);
const random = Math.random().toString(36).substring(2, 10);
return `prt_${timestamp}${random}`;
}

function injectHookMessage(
sessionID: string,
hookContent: string,
Expand Down
16 changes: 16 additions & 0 deletions src/services/ids.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Shared ID generation utilities.
* OpenCode v1.2.25+ requires all part IDs to start with "prt".
*/

export function generatePartId(): string {
const timestamp = Date.now().toString(16);
const random = Math.random().toString(36).substring(2, 10);
return `prt_${timestamp}${random}`;
}

export function generateMessageId(): string {
const timestamp = Date.now().toString(16);
const random = Math.random().toString(36).substring(2, 14);
return `msg_${timestamp}${random}`;
}