145
}
146
148
>
return output ? [{ type: ToolResultContentType.Text, text: output }] : undefined;
149
>
}
150
151
>
function shellToolCallPart(item: CommandExecutionItem, command: string): ToolCallResponsePart {
codexReplayMapper.ts
152
>
const success = item.status === 'completed' && (item.exitCode === 0 || item.exitCode === null);
153
>
const output = item.aggregatedOutput ?? '';
154
>
const exit = item.exitCode;
155
>
const pastTense = success
156
>
? `Ran \`${command}\``
157
: exit !== null
158
? `Ran \`${command}\` (exit ${exit})`
159
: `Ran \`${command}\` (failed)`;
161
>
kind: ResponsePartKind.ToolCall,
162
>
toolCall: {
163
>
status: ToolCallStatus.Completed,
164
>
toolCallId: generateUuid(),
165
>
toolName: 'shell',
166
>
displayName: 'Run shell command',
167
>
_meta: toToolCallMeta({ toolKind: 'terminal' }),
168
>
invocationMessage: command,
169
>
toolInput: command,
170
>
confirmed: ToolCallConfirmationReason.NotNeeded,
171
>
success,
172
>
pastTenseMessage: pastTense,
173
>
content: textContent(output),
174
>
error: success ? undefined : { message: exit !== null ? `Exit code ${exit}` : 'Command failed' },
175
>
},
176
>
};
177
>
}
178
179
function webSearchToolCallPart(item: Extract<ThreadItem, { type: 'webSearch' }>): ToolCallResponsePart {