fix(skill): patch up skill diffing code (#758)
Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import type { CreateBlock } from "@letta-ai/letta-client/resources/blocks/blocks";
|
||||
import { READ_ONLY_BLOCK_LABELS } from "./memoryConstants";
|
||||
import { MEMORY_PROMPTS } from "./promptAssets";
|
||||
|
||||
/**
|
||||
@@ -33,11 +34,7 @@ export type MemoryBlockLabel = (typeof MEMORY_BLOCK_LABELS)[number];
|
||||
* Block labels that should be read-only (agent cannot modify via memory tools).
|
||||
* These blocks are managed by specific tools (e.g., Skill tool for skills/loaded_skills).
|
||||
*/
|
||||
export const READ_ONLY_BLOCK_LABELS = [
|
||||
"skills",
|
||||
"loaded_skills",
|
||||
"memory_filesystem",
|
||||
] as const;
|
||||
export { READ_ONLY_BLOCK_LABELS };
|
||||
|
||||
/**
|
||||
* Block labels that should be isolated per-conversation.
|
||||
|
||||
5
src/agent/memoryConstants.ts
Normal file
5
src/agent/memoryConstants.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export const READ_ONLY_BLOCK_LABELS = [
|
||||
"skills",
|
||||
"loaded_skills",
|
||||
"memory_filesystem",
|
||||
] as const;
|
||||
@@ -673,6 +673,10 @@ export async function syncMemoryFilesystem(
|
||||
const fileInSystem = !!systemFile;
|
||||
const blockEntry = attachedBlock || detachedBlock;
|
||||
const isAttached = !!attachedBlock;
|
||||
const isReadOnlyLabel = (
|
||||
READ_ONLY_BLOCK_LABELS as readonly string[]
|
||||
).includes(label);
|
||||
const effectiveReadOnly = !!blockEntry?.read_only || isReadOnlyLabel;
|
||||
|
||||
// Get directory for file operations
|
||||
const fileDir = fileInSystem ? systemDir : detachedDir;
|
||||
@@ -742,7 +746,7 @@ export async function syncMemoryFilesystem(
|
||||
// Case 2: Block exists, no file
|
||||
if (!fileEntry && blockEntry) {
|
||||
// Read-only blocks: never delete/un-tag. Always recreate file instead.
|
||||
if (blockEntry.read_only) {
|
||||
if (effectiveReadOnly) {
|
||||
const targetDir = isAttached ? systemDir : detachedDir;
|
||||
const fileContent = renderBlockToFileContent(blockEntry);
|
||||
await writeMemoryFile(targetDir, label, fileContent);
|
||||
@@ -818,7 +822,7 @@ export async function syncMemoryFilesystem(
|
||||
// Frontmatter-only change: update metadata even when body matches
|
||||
if (fileChanged) {
|
||||
// Read-only blocks: ignore local changes, overwrite file with API content
|
||||
if (blockEntry.read_only) {
|
||||
if (effectiveReadOnly) {
|
||||
const fileContent = renderBlockToFileContent(blockEntry);
|
||||
await writeMemoryFile(fileDir, label, fileContent);
|
||||
updatedFiles.push(label);
|
||||
@@ -910,7 +914,7 @@ export async function syncMemoryFilesystem(
|
||||
// Also sync attachment status to match file location
|
||||
if (fileChanged) {
|
||||
// Read-only blocks: ignore local changes, overwrite file with API content
|
||||
if (blockEntry.read_only) {
|
||||
if (effectiveReadOnly) {
|
||||
const fileContent = renderBlockToFileContent(blockEntry);
|
||||
await writeMemoryFile(fileDir, label, fileContent);
|
||||
updatedFiles.push(label);
|
||||
@@ -1215,7 +1219,8 @@ export async function checkMemoryFilesystemStatus(
|
||||
const fileContent = systemFile?.content ?? detachedFile?.content ?? null;
|
||||
const blockValue = attachedBlock?.value ?? detachedBlock?.value ?? null;
|
||||
const blockReadOnly =
|
||||
attachedBlock?.read_only ?? detachedBlock?.read_only ?? false;
|
||||
(attachedBlock?.read_only ?? detachedBlock?.read_only ?? false) ||
|
||||
(READ_ONLY_BLOCK_LABELS as readonly string[]).includes(label);
|
||||
|
||||
const fileInSystem = !!systemFile;
|
||||
const isAttached = !!attachedBlock;
|
||||
@@ -1301,6 +1306,11 @@ function classifyLabel(
|
||||
}
|
||||
|
||||
if (fileContent === null && blockValue !== null) {
|
||||
if (blockReadOnly) {
|
||||
// Read-only blocks: missing file should be recreated
|
||||
pendingFromFile.push(label);
|
||||
return;
|
||||
}
|
||||
if (lastFileHash && !blockChanged) {
|
||||
// File was deleted, block unchanged — would delete block
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user