@sentry/junior-memory 0.80.0 → 0.81.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/src/tools.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Type, type TSchema } from "@sinclair/typebox";
1
+ import { Type, type Static, type TSchema } from "@sinclair/typebox";
2
2
  import { Value } from "@sinclair/typebox/value";
3
3
  import {
4
4
  getSourceKey,
@@ -13,6 +13,7 @@ import {
13
13
  type MemoryEmbeddingProvider,
14
14
  type MemoryDb,
15
15
  type MemoryRecord,
16
+ type MemorySupersessionDecider,
16
17
  } from "./store";
17
18
  import {
18
19
  parseCreateMemoryRequest,
@@ -54,6 +55,10 @@ export interface MemoryToolContext {
54
55
  userText?: string;
55
56
  }
56
57
 
58
+ export interface MemoryCreateToolContext extends MemoryToolContext {
59
+ supersessionDecider?: MemorySupersessionDecider;
60
+ }
61
+
57
62
  function throwToolInputError(message: string): never {
58
63
  throw new PluginToolInputError(message);
59
64
  }
@@ -83,9 +88,15 @@ function memoryRuntimeContext(
83
88
  });
84
89
  }
85
90
 
86
- function memoryStore(context: MemoryToolContext) {
91
+ function memoryStore(
92
+ context: MemoryToolContext,
93
+ options: { supersessionDecider?: MemorySupersessionDecider } = {},
94
+ ) {
87
95
  return createMemoryStore(context.db, memoryRuntimeContext(context), {
88
96
  embedder: context.embedder,
97
+ ...(options.supersessionDecider
98
+ ? { supersessionDecider: options.supersessionDecider }
99
+ : {}),
89
100
  });
90
101
  }
91
102
 
@@ -280,6 +291,18 @@ const searchMemoriesInputSchema = Type.Object(
280
291
  { additionalProperties: false },
281
292
  );
282
293
 
294
+ const memoryToolProjectionSchema = Type.Object(
295
+ {
296
+ id: Type.String({ minLength: 1 }),
297
+ content: Type.String({ minLength: 1 }),
298
+ createdAtMs: Type.Number(),
299
+ observedAtMs: Type.Number(),
300
+ expiresAtMs: Type.Optional(Type.Number()),
301
+ },
302
+ { additionalProperties: false },
303
+ );
304
+ type MemoryToolProjection = Static<typeof memoryToolProjectionSchema>;
305
+
283
306
  function parseToolInput<T>(schema: TSchema, input: unknown): T {
284
307
  try {
285
308
  if (!Value.Check(schema, input)) {
@@ -324,19 +347,20 @@ function targetForKind(kind: MemoryKind): "requester" | "conversation" {
324
347
  }
325
348
 
326
349
  /** Return the model-visible projection without hidden ownership/source fields. */
327
- function compactMemory(memory: MemoryRecord) {
328
- return {
350
+ function compactMemory(memory: MemoryRecord): MemoryToolProjection {
351
+ return Value.Parse(memoryToolProjectionSchema, {
329
352
  id: memory.id,
330
353
  content: memory.content,
331
354
  createdAtMs: memory.createdAtMs,
355
+ observedAtMs: memory.observedAtMs,
332
356
  ...(memory.expiresAtMs !== undefined
333
357
  ? { expiresAtMs: memory.expiresAtMs }
334
358
  : {}),
335
- };
359
+ });
336
360
  }
337
361
 
338
362
  /** Create a tool that submits an explicit memory candidate for storage. */
339
- export function createMemoryCreateTool(context: MemoryToolContext) {
363
+ export function createMemoryCreateTool(context: MemoryCreateToolContext) {
340
364
  return {
341
365
  description:
342
366
  "Explicit memory-write tool. Use only when the latest user message directly asks Junior to remember, store, save, or forget-and-replace a public/shareable fact. Do not use for ordinary statements like 'I prefer X', 'I use Y', or 'X goes before Y' unless the user also asks you to remember/store/save it; passive memory learning handles those after the visible reply. Pass one self-contained natural-language candidate preserving the user's explicit memory intent. Do not ask the user to rephrase ordinary first-person facts, and do not rewrite them into display-name or third-person wording. Do not include secrets, private personal details, medical/legal/financial/sensitive facts, or another person's personal preference, opinion, habit, identity, relationship, workflow, or private life. Runtime context derives actor, scope, source, and subject ids; the memory agent decides canonical stored content and memory kind, then the plugin derives storage target from kind.",
@@ -350,7 +374,9 @@ export function createMemoryCreateTool(context: MemoryToolContext) {
350
374
  const toolCallId = requireToolCallId(options.toolCallId);
351
375
  const requestedExpiresAtMs = parseExpiresAt(parsedInput.expires_at);
352
376
  const runtimeContext = memoryRuntimeContext(context);
353
- const store = memoryStore(context);
377
+ const store = memoryStore(context, {
378
+ supersessionDecider: context.supersessionDecider,
379
+ });
354
380
  const review = await (async () => {
355
381
  try {
356
382
  return parseMemoryReview(