@sentry/junior-memory 0.89.0 → 0.90.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/dist/index.js +105 -101
- package/dist/index.js.map +1 -1
- package/dist/tools.d.ts +119 -68
- package/package.json +2 -2
- package/src/tools.ts +154 -105
package/dist/index.js
CHANGED
|
@@ -667,9 +667,12 @@ function createMemoryCliCommand() {
|
|
|
667
667
|
import { Type } from "@sinclair/typebox";
|
|
668
668
|
import { Value } from "@sinclair/typebox/value";
|
|
669
669
|
import {
|
|
670
|
+
definePluginTool,
|
|
670
671
|
getSourceKey,
|
|
671
|
-
PluginToolInputError
|
|
672
|
+
PluginToolInputError,
|
|
673
|
+
pluginToolResultSchema
|
|
672
674
|
} from "@sentry/junior-plugin-api";
|
|
675
|
+
import { z as z4 } from "zod";
|
|
673
676
|
|
|
674
677
|
// src/store.ts
|
|
675
678
|
import { createHash, randomUUID } from "crypto";
|
|
@@ -1892,59 +1895,24 @@ function requireMemoryContent(value) {
|
|
|
1892
1895
|
}
|
|
1893
1896
|
return value;
|
|
1894
1897
|
}
|
|
1895
|
-
var createMemoryInputSchema2 =
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
)
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
id: Type.String({
|
|
1914
|
-
minLength: 1,
|
|
1915
|
-
description: "Memory id or unambiguous short id prefix to remove."
|
|
1916
|
-
})
|
|
1917
|
-
},
|
|
1918
|
-
{ additionalProperties: false }
|
|
1919
|
-
);
|
|
1920
|
-
var listMemoriesInputSchema2 = Type.Object(
|
|
1921
|
-
{
|
|
1922
|
-
limit: Type.Optional(
|
|
1923
|
-
Type.Number({
|
|
1924
|
-
minimum: 1,
|
|
1925
|
-
maximum: 50,
|
|
1926
|
-
description: "Maximum number of visible memories to return."
|
|
1927
|
-
})
|
|
1928
|
-
)
|
|
1929
|
-
},
|
|
1930
|
-
{ additionalProperties: false }
|
|
1931
|
-
);
|
|
1932
|
-
var searchMemoriesInputSchema2 = Type.Object(
|
|
1933
|
-
{
|
|
1934
|
-
query: Type.String({
|
|
1935
|
-
minLength: 1,
|
|
1936
|
-
description: "Search query for visible memory content."
|
|
1937
|
-
}),
|
|
1938
|
-
limit: Type.Optional(
|
|
1939
|
-
Type.Number({
|
|
1940
|
-
minimum: 1,
|
|
1941
|
-
maximum: 50,
|
|
1942
|
-
description: "Maximum number of matching memories to return."
|
|
1943
|
-
})
|
|
1944
|
-
)
|
|
1945
|
-
},
|
|
1946
|
-
{ additionalProperties: false }
|
|
1947
|
-
);
|
|
1898
|
+
var createMemoryInputSchema2 = z4.object({
|
|
1899
|
+
content: z4.string().min(1).max(MAX_TOOL_CONTENT_CHARS).describe(
|
|
1900
|
+
"Self-contained public/shareable memory candidate. Include the subject in natural language when it matters; do not rely on surrounding chat context."
|
|
1901
|
+
),
|
|
1902
|
+
expires_at: z4.string().min(1).describe(
|
|
1903
|
+
'Expiration selector. Omit or use "never" when the memory should not expire, or use an exact ISO timestamp such as "2027-06-21T00:00:00Z".'
|
|
1904
|
+
).optional()
|
|
1905
|
+
}).strict();
|
|
1906
|
+
var removeMemoryInputSchema = z4.object({
|
|
1907
|
+
id: z4.string().min(1).describe("Memory id or unambiguous short id prefix to remove.")
|
|
1908
|
+
}).strict();
|
|
1909
|
+
var listMemoriesInputSchema2 = z4.object({
|
|
1910
|
+
limit: z4.number().min(1).max(50).describe("Maximum number of visible memories to return.").optional()
|
|
1911
|
+
}).strict();
|
|
1912
|
+
var searchMemoriesInputSchema2 = z4.object({
|
|
1913
|
+
query: z4.string().min(1).describe("Search query for visible memory content."),
|
|
1914
|
+
limit: z4.number().min(1).max(50).describe("Maximum number of matching memories to return.").optional()
|
|
1915
|
+
}).strict();
|
|
1948
1916
|
var memoryToolProjectionSchema = Type.Object(
|
|
1949
1917
|
{
|
|
1950
1918
|
id: Type.String({ minLength: 1 }),
|
|
@@ -1955,17 +1923,53 @@ var memoryToolProjectionSchema = Type.Object(
|
|
|
1955
1923
|
},
|
|
1956
1924
|
{ additionalProperties: false }
|
|
1957
1925
|
);
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1926
|
+
var memoryProjectionOutputSchema = z4.object({
|
|
1927
|
+
id: z4.string(),
|
|
1928
|
+
content: z4.string(),
|
|
1929
|
+
createdAtMs: z4.number(),
|
|
1930
|
+
observedAtMs: z4.number(),
|
|
1931
|
+
expiresAtMs: z4.number().optional()
|
|
1932
|
+
});
|
|
1933
|
+
var memoryCreateDataOutputSchema = z4.object({
|
|
1934
|
+
created: z4.boolean(),
|
|
1935
|
+
memory: memoryProjectionOutputSchema
|
|
1936
|
+
});
|
|
1937
|
+
var memorySingleDataOutputSchema = z4.object({
|
|
1938
|
+
memory: memoryProjectionOutputSchema
|
|
1939
|
+
});
|
|
1940
|
+
var memoryManyDataOutputSchema = z4.object({
|
|
1941
|
+
memories: z4.array(memoryProjectionOutputSchema)
|
|
1942
|
+
});
|
|
1943
|
+
var memoryCreateOutputSchema = pluginToolResultSchema.extend({
|
|
1944
|
+
ok: z4.literal(true),
|
|
1945
|
+
status: z4.literal("success"),
|
|
1946
|
+
target: z4.string(),
|
|
1947
|
+
data: memoryCreateDataOutputSchema,
|
|
1948
|
+
created: z4.boolean(),
|
|
1949
|
+
memory: memoryProjectionOutputSchema
|
|
1950
|
+
});
|
|
1951
|
+
var memorySingleOutputSchema = pluginToolResultSchema.extend({
|
|
1952
|
+
ok: z4.literal(true),
|
|
1953
|
+
status: z4.literal("success"),
|
|
1954
|
+
target: z4.string(),
|
|
1955
|
+
data: memorySingleDataOutputSchema,
|
|
1956
|
+
memory: memoryProjectionOutputSchema
|
|
1957
|
+
});
|
|
1958
|
+
var memoryManyOutputSchema = pluginToolResultSchema.extend({
|
|
1959
|
+
ok: z4.literal(true),
|
|
1960
|
+
status: z4.literal("success"),
|
|
1961
|
+
target: z4.string(),
|
|
1962
|
+
data: memoryManyDataOutputSchema,
|
|
1963
|
+
memories: z4.array(memoryProjectionOutputSchema)
|
|
1964
|
+
});
|
|
1965
|
+
function parseMemoryToolInput(schema, input) {
|
|
1966
|
+
const result = schema.safeParse(input);
|
|
1967
|
+
if (!result.success) {
|
|
1965
1968
|
throw new PluginToolInputError("Invalid memory tool input.", {
|
|
1966
|
-
cause: error
|
|
1969
|
+
cause: result.error
|
|
1967
1970
|
});
|
|
1968
1971
|
}
|
|
1972
|
+
return result.data;
|
|
1969
1973
|
}
|
|
1970
1974
|
function sourceIdempotencyKey(context) {
|
|
1971
1975
|
const sourceKey2 = getSourceKey(context.source);
|
|
@@ -1997,16 +2001,23 @@ function compactMemory(memory) {
|
|
|
1997
2001
|
...memory.expiresAtMs !== void 0 ? { expiresAtMs: memory.expiresAtMs } : {}
|
|
1998
2002
|
});
|
|
1999
2003
|
}
|
|
2000
|
-
function
|
|
2004
|
+
function memoryToolResult(target, data) {
|
|
2001
2005
|
return {
|
|
2006
|
+
ok: true,
|
|
2007
|
+
status: "success",
|
|
2008
|
+
target,
|
|
2009
|
+
data,
|
|
2010
|
+
...data
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
function createMemoryCreateTool(context) {
|
|
2014
|
+
return definePluginTool({
|
|
2002
2015
|
description: "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.",
|
|
2003
2016
|
executionMode: "sequential",
|
|
2004
2017
|
inputSchema: createMemoryInputSchema2,
|
|
2018
|
+
outputSchema: memoryCreateOutputSchema,
|
|
2005
2019
|
execute: async (input, options) => {
|
|
2006
|
-
const parsedInput =
|
|
2007
|
-
createMemoryInputSchema2,
|
|
2008
|
-
input
|
|
2009
|
-
);
|
|
2020
|
+
const parsedInput = parseMemoryToolInput(createMemoryInputSchema2, input);
|
|
2010
2021
|
const toolCallId = requireToolCallId(options.toolCallId);
|
|
2011
2022
|
const requestedExpiresAtMs = parseExpiresAt(parsedInput.expires_at);
|
|
2012
2023
|
const runtimeContext = memoryRuntimeContext(context);
|
|
@@ -2064,24 +2075,21 @@ function createMemoryCreateTool(context) {
|
|
|
2064
2075
|
asToolInputError(error);
|
|
2065
2076
|
}
|
|
2066
2077
|
})();
|
|
2067
|
-
return {
|
|
2068
|
-
ok: true,
|
|
2078
|
+
return memoryToolResult("createMemory", {
|
|
2069
2079
|
created: result.created,
|
|
2070
2080
|
memory: compactMemory(result.memory)
|
|
2071
|
-
};
|
|
2081
|
+
});
|
|
2072
2082
|
}
|
|
2073
|
-
};
|
|
2083
|
+
});
|
|
2074
2084
|
}
|
|
2075
2085
|
function createMemoryRemoveTool(context) {
|
|
2076
|
-
return {
|
|
2086
|
+
return definePluginTool({
|
|
2077
2087
|
description: "Forget one memory visible in the active context. Use only ids or short id prefixes returned by listMemories or searchMemories. Never remove memories by hidden actor, Slack, scope, or subject identifiers.",
|
|
2078
2088
|
executionMode: "sequential",
|
|
2079
2089
|
inputSchema: removeMemoryInputSchema,
|
|
2090
|
+
outputSchema: memorySingleOutputSchema,
|
|
2080
2091
|
execute: async (input) => {
|
|
2081
|
-
const parsedInput =
|
|
2082
|
-
removeMemoryInputSchema,
|
|
2083
|
-
input
|
|
2084
|
-
);
|
|
2092
|
+
const parsedInput = parseMemoryToolInput(removeMemoryInputSchema, input);
|
|
2085
2093
|
const memory = await (async () => {
|
|
2086
2094
|
try {
|
|
2087
2095
|
return await memoryStore(context).archiveMemory({
|
|
@@ -2092,40 +2100,37 @@ function createMemoryRemoveTool(context) {
|
|
|
2092
2100
|
asToolInputError(error);
|
|
2093
2101
|
}
|
|
2094
2102
|
})();
|
|
2095
|
-
return {
|
|
2096
|
-
ok: true,
|
|
2103
|
+
return memoryToolResult("removeMemory", {
|
|
2097
2104
|
memory: compactMemory(memory)
|
|
2098
|
-
};
|
|
2105
|
+
});
|
|
2099
2106
|
}
|
|
2100
|
-
};
|
|
2107
|
+
});
|
|
2101
2108
|
}
|
|
2102
2109
|
function createMemoryListTool(context) {
|
|
2103
|
-
return {
|
|
2110
|
+
return definePluginTool({
|
|
2104
2111
|
description: "List active memories visible in the current context. Use when the user asks what Junior remembers or when memory ids are needed before removing a memory.",
|
|
2105
2112
|
annotations: { readOnlyHint: true, destructiveHint: false },
|
|
2106
2113
|
inputSchema: listMemoriesInputSchema2,
|
|
2114
|
+
outputSchema: memoryManyOutputSchema,
|
|
2107
2115
|
execute: async (input) => {
|
|
2108
|
-
const parsedInput =
|
|
2109
|
-
listMemoriesInputSchema2,
|
|
2110
|
-
input
|
|
2111
|
-
);
|
|
2116
|
+
const parsedInput = parseMemoryToolInput(listMemoriesInputSchema2, input);
|
|
2112
2117
|
const memories = await memoryStore(context).listMemories({
|
|
2113
2118
|
limit: boundedLimit2(parsedInput.limit, DEFAULT_RESULT_LIMIT)
|
|
2114
2119
|
});
|
|
2115
|
-
return {
|
|
2116
|
-
ok: true,
|
|
2120
|
+
return memoryToolResult("listMemories", {
|
|
2117
2121
|
memories: memories.map(compactMemory)
|
|
2118
|
-
};
|
|
2122
|
+
});
|
|
2119
2123
|
}
|
|
2120
|
-
};
|
|
2124
|
+
});
|
|
2121
2125
|
}
|
|
2122
2126
|
function createMemorySearchTool(context) {
|
|
2123
|
-
return {
|
|
2127
|
+
return definePluginTool({
|
|
2124
2128
|
description: "Search active memories visible in the current context. Use when the model needs targeted memory recall. The tool searches only the current requester and active conversation scopes.",
|
|
2125
2129
|
annotations: { readOnlyHint: true, destructiveHint: false },
|
|
2126
2130
|
inputSchema: searchMemoriesInputSchema2,
|
|
2131
|
+
outputSchema: memoryManyOutputSchema,
|
|
2127
2132
|
execute: async (input) => {
|
|
2128
|
-
const parsedInput =
|
|
2133
|
+
const parsedInput = parseMemoryToolInput(
|
|
2129
2134
|
searchMemoriesInputSchema2,
|
|
2130
2135
|
input
|
|
2131
2136
|
);
|
|
@@ -2133,12 +2138,11 @@ function createMemorySearchTool(context) {
|
|
|
2133
2138
|
query: parsedInput.query,
|
|
2134
2139
|
limit: boundedLimit2(parsedInput.limit, DEFAULT_SEARCH_LIMIT2)
|
|
2135
2140
|
});
|
|
2136
|
-
return {
|
|
2137
|
-
ok: true,
|
|
2141
|
+
return memoryToolResult("searchMemories", {
|
|
2138
2142
|
memories: memories.map(compactMemory)
|
|
2139
|
-
};
|
|
2143
|
+
});
|
|
2140
2144
|
}
|
|
2141
|
-
};
|
|
2145
|
+
});
|
|
2142
2146
|
}
|
|
2143
2147
|
|
|
2144
2148
|
// src/process-session.ts
|
|
@@ -2147,7 +2151,7 @@ import {
|
|
|
2147
2151
|
getSourceKey as getSourceKey2,
|
|
2148
2152
|
isPrivateSource as isPrivateSource2
|
|
2149
2153
|
} from "@sentry/junior-plugin-api";
|
|
2150
|
-
import { z as
|
|
2154
|
+
import { z as z5 } from "zod";
|
|
2151
2155
|
var MEMORY_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
2152
2156
|
"createMemory",
|
|
2153
2157
|
"listMemories",
|
|
@@ -2155,11 +2159,11 @@ var MEMORY_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
|
2155
2159
|
"searchMemories"
|
|
2156
2160
|
]);
|
|
2157
2161
|
var MEMORY_TASK_STATE_TTL_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
2158
|
-
var extractedMemoryCacheSchema =
|
|
2159
|
-
|
|
2160
|
-
content:
|
|
2161
|
-
expiresAtMs:
|
|
2162
|
-
kind:
|
|
2162
|
+
var extractedMemoryCacheSchema = z5.array(
|
|
2163
|
+
z5.object({
|
|
2164
|
+
content: z5.string().min(1),
|
|
2165
|
+
expiresAtMs: z5.number().finite().nullable(),
|
|
2166
|
+
kind: z5.enum(MEMORY_KINDS)
|
|
2163
2167
|
}).strict().transform(parseExtractedMemory)
|
|
2164
2168
|
);
|
|
2165
2169
|
function targetForKind2(kind) {
|