@@ -167,7 +167,6 @@ export function createRunManager({ agent, store, publish, logger, logDir, plugin
167167 startedAt : live . startedAt ,
168168 lastTool : live . lastTool ,
169169 textTail : live . textTail ,
170- autoAllow : live . autoAllow ,
171170 model : live . model ?? null ,
172171 permissions : [ ...live . permissions . values ( ) ] . map ( ( item ) => ( {
173172 requestId : item . requestId ,
@@ -195,7 +194,7 @@ export function createRunManager({ agent, store, publish, logger, logDir, plugin
195194
196195 /**
197196 * @param {string } figureId
198- * @param {{ kind: 'create' | 'edit', instruction?: string, example?: string | null, autoAllow?: boolean,
197+ * @param {{ kind: 'create' | 'edit', instruction?: string, example?: string | null,
199198 * model?: import('./miniapp-api.js').MiniAppAgentModelSelection | null }} input
200199 */
201200 async function start ( figureId , input ) {
@@ -214,7 +213,6 @@ export function createRunManager({ agent, store, publish, logger, logDir, plugin
214213 startedAt : Date . now ( ) ,
215214 sessionId : figure . sessionId ,
216215 controller : new AbortController ( ) ,
217- autoAllow : ! ! input . autoAllow ,
218216 permissions : new Map ( ) ,
219217 lastTool : '' ,
220218 textTail : '' ,
@@ -351,15 +349,14 @@ export function createRunManager({ agent, store, publish, logger, logDir, plugin
351349 }
352350 }
353351
354- /** @param {any } live @param {Extract<MiniAppAgentRunEvent, { type: 'permission.requested' }> } event */
352+ /**
353+ * Every request waits for the user: a click on the gallery card, or the Host's own card in the chat
354+ * side panel (where MCode offers its own "allow for this conversation"). The gallery never answers
355+ * on the user's behalf.
356+ * @param {any } live @param {Extract<MiniAppAgentRunEvent, { type: 'permission.requested' }> } event
357+ */
355358 function onPermission ( live , event ) {
356- log ( live , { type : 'permission' , toolName : cleanText ( event . toolName , 120 ) , reason : cleanText ( event . reason , 400 ) , auto : ! ! live . autoAllow } ) ;
357- if ( live . autoAllow ) {
358- void agent
359- ?. reply ( { sessionId : event . sessionId , requestId : event . requestId , decision : 'allowOnce' } )
360- . catch ( ( ) => { } ) ;
361- return ;
362- }
359+ log ( live , { type : 'permission' , toolName : cleanText ( event . toolName , 120 ) , reason : cleanText ( event . reason , 400 ) } ) ;
363360 live . permissions . set ( event . requestId , {
364361 requestId : event . requestId ,
365362 sessionId : event . sessionId ,
@@ -375,22 +372,17 @@ export function createRunManager({ agent, store, publish, logger, logDir, plugin
375372 const live = active . get ( figureId ) ;
376373 const request = live ?. permissions . get ( requestId ) ;
377374 if ( ! live || ! request ) throw new GalleryError ( 'not_found' , '这个确认请求已经结束' ) ;
375+ let settledElsewhere = false ;
378376 try {
379377 await /** @type {MiniAppAgentClient } */ ( agent ) . reply ( { sessionId : request . sessionId , requestId, decision } ) ;
380378 } catch ( error ) {
381379 if ( errorCode ( error ) !== 'REQUEST_NOT_FOUND' ) throw error ;
380+ settledElsewhere = true ; // decided on MCode's card in the side panel, or the run moved on
382381 }
383382 live . permissions . delete ( requestId ) ;
384- log ( live , { type : 'decision' , toolName : request . toolName , decision } ) ;
385- emitProgress ( live ) ;
386- }
387-
388- /** @param {string } figureId @param {boolean } value */
389- function setAutoAllow ( figureId , value ) {
390- const live = active . get ( figureId ) ;
391- if ( ! live ) throw new GalleryError ( 'not_found' , '当前没有进行中的运行' ) ;
392- live . autoAllow = value ;
383+ log ( live , { type : 'decision' , toolName : request . toolName , decision : settledElsewhere ? 'elsewhere' : decision } ) ;
393384 emitProgress ( live ) ;
385+ if ( settledElsewhere ) throw new GalleryError ( 'not_found' , '这个请求已经在对话里处理过了' ) ;
394386 }
395387
396388 /** @param {string } figureId */
@@ -404,7 +396,6 @@ export function createRunManager({ agent, store, publish, logger, logDir, plugin
404396 start,
405397 reply,
406398 cancel,
407- setAutoAllow,
408399 /** @param {string } figureId */
409400 live : ( figureId ) => {
410401 const run = active . get ( figureId ) ;
0 commit comments