File tree Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -24,3 +24,4 @@ local-dev-toolshed.log
2424local-dev-shell.log
2525tools /ralph /logs /
2626tools /ralph /smoketest /
27+ .worktrees
Original file line number Diff line number Diff line change @@ -5,12 +5,14 @@ import {
55 Default ,
66 derive ,
77 handler ,
8+ llm ,
89 NAME ,
910 navigateTo ,
1011 Opaque ,
1112 OpaqueRef ,
1213 patternTool ,
1314 recipe ,
15+ str ,
1416 UI ,
1517 wish ,
1618} from "commontools" ;
@@ -27,6 +29,7 @@ type Output = {
2729 /** The content of the note */
2830 content : Default < string , "" > ;
2931 grep : OpaqueRef < { query : string } > ;
32+ translate : OpaqueRef < { language : string } > ;
3033 editContent : OpaqueRef < { detail : { value : string } } > ;
3134} ;
3235
@@ -164,6 +167,31 @@ const Note = recipe<Input, Output>(
164167 } ,
165168 { content } ,
166169 ) ,
170+ translate : patternTool (
171+ (
172+ { language, content } : {
173+ language : string ;
174+ content : string ;
175+ } ,
176+ ) => {
177+ const result = llm ( {
178+ system : str `Translate the content to ${ language } .` ,
179+ messages : derive ( content , ( c ) => [
180+ {
181+ role : "user" ,
182+ content : c ,
183+ } ,
184+ ] ) ,
185+ } ) ;
186+
187+ return derive ( result , ( { pending, result } ) => {
188+ if ( pending ) return undefined ;
189+ if ( result == null ) return "Error occured" ;
190+ return result ;
191+ } ) ;
192+ } ,
193+ { content } ,
194+ ) ,
167195 editContent : handleEditContent ( { content } ) ,
168196 } ;
169197 } ,
Original file line number Diff line number Diff line change @@ -832,7 +832,7 @@ async function invokeToolCall(
832832 const cancel = result . sink ( ( r ) => {
833833 r !== undefined && resolve ( r ) ;
834834 } ) ;
835- const resultValue = await promise ;
835+ let resultValue = await promise ;
836836 cancel ( ) ;
837837
838838 if ( pattern ) {
@@ -842,7 +842,10 @@ async function invokeToolCall(
842842 await runtime . idle ( ) ; // maybe pointless
843843 }
844844
845- return { type : "json" , value : resultValue ?? "OK" } ; // if there was no return value, just tell the LLM it worked
845+ // Prevent links being returned
846+ resultValue = JSON . parse ( JSON . stringify ( resultValue ?? "OK" ) ) ;
847+
848+ return { type : "json" , value : resultValue } ;
846849}
847850
848851/**
You can’t perform that action at this time.
0 commit comments