diff --git a/.gitignore b/.gitignore index 116166563..0d68cdd76 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ local-dev-toolshed.log local-dev-shell.log tools/ralph/logs/ tools/ralph/smoketest/ +.worktrees diff --git a/packages/patterns/note.tsx b/packages/patterns/note.tsx index 62607197e..bf271f246 100644 --- a/packages/patterns/note.tsx +++ b/packages/patterns/note.tsx @@ -5,12 +5,14 @@ import { Default, derive, handler, + llm, NAME, navigateTo, Opaque, OpaqueRef, patternTool, recipe, + str, UI, wish, } from "commontools"; @@ -27,6 +29,7 @@ type Output = { /** The content of the note */ content: Default; grep: OpaqueRef<{ query: string }>; + translate: OpaqueRef<{ language: string }>; editContent: OpaqueRef<{ detail: { value: string } }>; }; @@ -164,6 +167,31 @@ const Note = recipe( }, { content }, ), + translate: patternTool( + ( + { language, content }: { + language: string; + content: string; + }, + ) => { + const result = llm({ + system: str`Translate the content to ${language}.`, + messages: derive(content, (c) => [ + { + role: "user", + content: c, + }, + ]), + }); + + return derive(result, ({ pending, result }) => { + if (pending) return undefined; + if (result == null) return "Error occured"; + return result; + }); + }, + { content }, + ), editContent: handleEditContent({ content }), }; }, diff --git a/packages/runner/src/builtins/llm-dialog.ts b/packages/runner/src/builtins/llm-dialog.ts index 8a86a288a..609bc5b60 100644 --- a/packages/runner/src/builtins/llm-dialog.ts +++ b/packages/runner/src/builtins/llm-dialog.ts @@ -832,7 +832,7 @@ async function invokeToolCall( const cancel = result.sink((r) => { r !== undefined && resolve(r); }); - const resultValue = await promise; + let resultValue = await promise; cancel(); if (pattern) { @@ -842,7 +842,10 @@ async function invokeToolCall( await runtime.idle(); // maybe pointless } - return { type: "json", value: resultValue ?? "OK" }; // if there was no return value, just tell the LLM it worked + // Prevent links being returned + resultValue = JSON.parse(JSON.stringify(resultValue ?? "OK")); + + return { type: "json", value: resultValue }; } /**