@@ -22,7 +22,7 @@ import {
2222 ActionMessage as ActionMessageModel ,
2323 ToolCallResult as ToolCallResultModel ,
2424} from '@prisma/client' ;
25- import { ActionDetail , actionMessagePO2DTO } from '../action/action.dto' ;
25+ import { ActionDetail , actionMessagePO2DTO , sanitizeToolOutput } from '../action/action.dto' ;
2626import { PrismaService } from '../common/prisma.service' ;
2727import { providerItem2ModelInfo } from '../provider/provider.dto' ;
2828import { ProviderService } from '../provider/provider.service' ;
@@ -35,6 +35,7 @@ import { InvokeSkillJobData } from '../skill/skill.dto';
3535
3636type GetActionResultParams = GetActionResultData [ 'query' ] & {
3737 includeFiles ?: boolean ;
38+ sanitizeForDisplay ?: boolean ;
3839} ;
3940
4041@Injectable ( )
@@ -60,7 +61,7 @@ export class ActionService {
6061 ) { }
6162
6263 async getActionResult ( user : User , param : GetActionResultParams ) : Promise < ActionDetail > {
63- const { resultId, version, includeFiles = false } = param ;
64+ const { resultId, version, includeFiles = false , sanitizeForDisplay = false } = param ;
6465
6566 const result = await this . prisma . actionResult . findFirst ( {
6667 where : {
@@ -74,7 +75,9 @@ export class ActionService {
7475 throw new ActionResultNotFoundError ( ) ;
7576 }
7677
77- const enrichedResult = await this . enrichActionResultWithDetails ( user , result ) ;
78+ const enrichedResult = await this . enrichActionResultWithDetails ( user , result , {
79+ sanitizeForDisplay,
80+ } ) ;
7881
7982 if ( includeFiles ) {
8083 enrichedResult . files = await this . driveService . listAllDriveFiles ( user , {
@@ -92,6 +95,7 @@ export class ActionService {
9295 private async enrichActionResultWithDetails (
9396 user : User ,
9497 result : ActionResult ,
98+ options ?: { sanitizeForDisplay ?: boolean } ,
9599 ) : Promise < ActionDetail > {
96100 const item =
97101 ( result . providerItemId
@@ -131,6 +135,14 @@ export class ActionService {
131135 if ( message . type === 'tool' && message . toolCallId ) {
132136 const toolCallResult = toolCallResultMap . get ( message . toolCallId ) ;
133137 if ( toolCallResult ) {
138+ const rawOutput = safeParseJSON ( toolCallResult . output || '{}' ) ?? {
139+ rawOutput : toolCallResult . output ,
140+ } ;
141+ // Apply sanitization if needed
142+ const output = options ?. sanitizeForDisplay
143+ ? sanitizeToolOutput ( toolCallResult . toolName , rawOutput )
144+ : rawOutput ;
145+
134146 // Attach the tool call result to the message
135147 enrichedMessage . toolCallResult = {
136148 callId : toolCallResult . callId ,
@@ -139,9 +151,7 @@ export class ActionService {
139151 toolName : toolCallResult . toolName ,
140152 stepName : toolCallResult . stepName ,
141153 input : safeParseJSON ( toolCallResult . input || '{}' ) ?? { } ,
142- output : safeParseJSON ( toolCallResult . output || '{}' ) ?? {
143- rawOutput : toolCallResult . output ,
144- } ,
154+ output,
145155 error : toolCallResult . error || '' ,
146156 status : toolCallResult . status as 'executing' | 'completed' | 'failed' ,
147157 createdAt : toolCallResult . createdAt . getTime ( ) ,
0 commit comments