@@ -12,6 +12,8 @@ import {
1212 IOutlineResult ,
1313} from "../../interfaces/Outline.interface" ;
1414import { getErrorMessage , randomString } from "functools-kit" ;
15+ import { errorSubject } from "../../config/emitters" ;
16+ import { IModelMessage } from "../../model/ModelMessage.model" ;
1517
1618const METHOD_NAME = "function.target.json" ;
1719
@@ -79,6 +81,7 @@ const jsonInternal = beginContext(
7981 swarm . outlineValidationService . validate ( outlineName , METHOD_NAME ) ;
8082
8183 const resultId = randomString ( ) ;
84+ const clientId = `${ resultId } _outline` ;
8285
8386 const {
8487 getOutlineHistory,
@@ -146,12 +149,29 @@ const jsonInternal = beginContext(
146149 await getOutlineHistory ( inputArgs ) ;
147150 const messages = await history . list ( ) ;
148151 try {
149- const output = await getCompletion ( {
152+ let output : IModelMessage | IOutlineMessage ;
153+ let errorValue = null ;
154+
155+ const unError = errorSubject . once ( ( [ errorClientId , error ] ) => {
156+ if ( clientId === errorClientId ) {
157+ errorValue = error ;
158+ }
159+ } ) ;
160+
161+ output = await getCompletion ( {
162+ clientId,
150163 messages : await history . list ( ) ,
151164 mode : "tool" ,
152165 outlineName,
153166 format,
154167 } ) ;
168+
169+ unError ( ) ;
170+
171+ if ( errorValue ) {
172+ throw errorValue ;
173+ }
174+
155175 if ( completionCallbacks ?. onComplete ) {
156176 completionCallbacks . onComplete (
157177 {
@@ -189,11 +209,14 @@ const jsonInternal = beginContext(
189209 return result ;
190210 } catch ( error ) {
191211 errorMessage = getErrorMessage ( error ) ;
192- console . error ( `agent-swarm outline error outlineName=${ outlineName } attempt=${ attempt } ` , {
193- param,
194- lastData,
195- errorMessage,
196- } )
212+ console . error (
213+ `agent-swarm outline error outlineName=${ outlineName } attempt=${ attempt } ` ,
214+ {
215+ param,
216+ lastData,
217+ errorMessage,
218+ }
219+ ) ;
197220 }
198221 }
199222 const result = {
0 commit comments