@@ -13,7 +13,7 @@ import { Ref, UiFragment } from "../sugar/zod.js";
1313import { tsToExports } from "../localBuild.js" ;
1414import { sendMessage } from "./stickers/chat.jsx" ;
1515import { llm , RESPONSE } from "../effects/fetch.jsx" ;
16- import { log } from "../sugar/activity.js" ;
16+ import { log , logEntries } from "../sugar/activity.js" ;
1717
1818const adjectives = [
1919 "indigo" ,
@@ -176,6 +176,14 @@ export const charmViewer = typedService(CharmWithSpell, {
176176 } ) ,
177177} ) ;
178178
179+ const logEntries = select ( {
180+ self : $ . self ,
181+ log : [ { self : $ . log , message : $ . message , modified : $ . modified } ] ,
182+ } )
183+ . match ( $ . self , "common/activity" , $ . log )
184+ . match ( $ . log , "message" , $ . message )
185+ . match ( $ . log , "modified" , $ . modified ) ;
186+
179187const spellEditor = typedBehavior ( Spell , {
180188 render : ( { self, name, sourceCode, notes } ) => (
181189 < div entity = { self } >
@@ -204,15 +212,31 @@ const spellEditor = typedBehavior(Spell, {
204212 cmd . add ( ...tagWithSchema ( self , Spell ) ) ;
205213 } ) ,
206214
215+ // listLogEntries: select({
216+ // self: $.self,
217+ // log: [{ self: $.log, message: $.message, modified: $.modified }],
218+ // })
219+ // .match($.self, "common/activity", $.log)
220+ // .match($.log, "message", $.message)
221+ // .match($.log, "modified", $.modified)
222+ // .transact(({ self, log }, cmd) => {
223+ // debugger;
224+ // }),
225+
207226 onModifyWithAI : event ( "~/on/modify-with-ai" )
208227 . with ( resolve ( Spell . pick ( { sourceCode : true , notes : true } ) ) )
209- . transact ( ( { self, event, sourceCode, notes } , cmd ) => {
228+ . with ( logEntries )
229+ . transact ( ( { self, event, sourceCode, notes, log : logEntries } , cmd ) => {
210230 const ev =
211231 Session . resolve <
212232 SubmitEvent < z . infer < typeof SourceModificationPrompt > >
213233 > ( event ) ;
234+
235+ cmd . add ( ...log ( self , "AI modification: " + ev . detail . value . prompt ) ) ;
236+
214237 const message = `Modify the attached source code based on the following prompt:
215238 <context>${ notes } </context>
239+ <change-history>${ JSON . stringify ( logEntries ) } </change-history>
216240 <modification>${ ev . detail . value . prompt } </modification>
217241
218242 \`\`\`js\n${ sourceCode } \n\`\`\`` ;
@@ -968,31 +992,28 @@ export const spellManager = typedBehavior(
968992 self = { focusedCharm }
969993 spell = { charmViewer as any }
970994 />
971- { editingSpell && (
972- < details style = { detailsStyle } open >
973- < summary style = { summaryStyle } >
974- Edit Spell
975- < button
976- style = { buttonStyle }
977- onclick = "~/on/close-spell-editor"
978- >
979- Close
980- </ button >
981- </ summary >
982- < div style = { formContainerStyle } >
983- < CharmComponent
984- self = { editingSpell }
985- spell = { spellEditor as any }
986- />
987- </ div >
988- </ details >
989- ) }
990995 </ div >
991996 ) : (
992- < div style = "display: flex; align-items: center; justify-content: center; height: 100 %; color: #666;" >
997+ < div style = "display: flex; align-items: center; justify-content: center; height: 33 %; color: #666;" >
993998 < h2 > Select a charm to focus</ h2 >
994999 </ div >
9951000 ) }
1001+ { editingSpell && (
1002+ < details style = { detailsStyle } open >
1003+ < summary style = { summaryStyle } >
1004+ Edit Spell
1005+ < button style = { buttonStyle } onclick = "~/on/close-spell-editor" >
1006+ Close
1007+ </ button >
1008+ </ summary >
1009+ < div style = { formContainerStyle } >
1010+ < CharmComponent
1011+ self = { editingSpell }
1012+ spell = { spellEditor as any }
1013+ />
1014+ </ div >
1015+ </ details >
1016+ ) }
9961017 </ div >
9971018 </ div >
9981019 ) ;
0 commit comments