@@ -112,20 +112,21 @@ export interface SelectOption {
112112export const castSpellAsCharm = async (
113113 charmManager : CharmManager ,
114114 recipeKey : string ,
115- blobId : string ,
115+ argument : Cell < any > ,
116116) => {
117- if ( recipeKey && blobId ) {
117+ if ( recipeKey && argument ) {
118118 console . log ( "Syncing..." ) ;
119119 const recipeId = recipeKey . replace ( "spell-" , "" ) ;
120120 await charmManager . syncRecipeBlobby ( recipeId ) ;
121121
122122 const recipe = getRecipe ( recipeId ) ;
123123 if ( ! recipe ) return ;
124124
125- console . log ( "Syncing blob..." ) ;
126- const cell = await charmManager . getCellById ( { "/" : blobId } , [ "argument" ] ) ;
127125 console . log ( "Casting..." ) ;
128- const charm : Cell < Charm > = await charmManager . runPersistent ( recipe , cell ) ;
126+ const charm : Cell < Charm > = await charmManager . runPersistent (
127+ recipe ,
128+ argument ,
129+ ) ;
129130 charmManager . add ( [ charm ] ) ;
130131 return charm . entityId ;
131132 }
@@ -495,17 +496,17 @@ async function handleUseDataInSpell(deps: CommandContext) {
495496 }
496497
497498 const charm = await deps . charmManager . get ( deps . focusedCharmId ) ;
498- const sourceCell = charm ?. getSourceCell ( ) ;
499-
500- const sourceId = getEntityId ( sourceCell ) ?. [ "/" ] ;
501- if ( ! sourceId ) {
502- throw new Error ( "No source ID found" ) ;
499+ if ( ! charm ) throw new Error ( "No current charm found" ) ;
500+ const argument = deps . charmManager . getArgument ( charm ) ;
501+ if ( ! argument ) {
502+ throw new Error ( "No sourceCell/argument found for current charm" ) ;
503503 }
504+
504505 deps . setLoading ( true ) ;
505506 const newCharm = await castSpellAsCharm (
506507 deps . charmManager ,
507508 selectedSpell . id ,
508- sourceId ,
509+ argument ,
509510 ) ;
510511
511512 if ( ! newCharm ) {
@@ -578,10 +579,18 @@ async function handleUseSpellOnOtherData(deps: CommandContext) {
578579 }
579580
580581 deps . setLoading ( true ) ;
582+
583+ console . log ( "Syncing blob..." ) ;
584+ // TODO(ben,seefeld): We might want spellcaster to return docId/path
585+ // pairs and use those directly instead of hardcoding `argument` here.
586+ const argument = await deps . charmManager . getCellById ( {
587+ "/" : selectedCell . id ,
588+ } , [ "argument" ] ) ;
589+
581590 const newCharm = await castSpellAsCharm (
582591 deps . charmManager ,
583592 spellId ,
584- selectedCell . id ,
593+ argument ,
585594 ) ;
586595 if ( ! newCharm ) throw new Error ( "Failed to cast spell" ) ;
587596
0 commit comments