MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / formatExecuteResult

Function formatExecuteResult

packages/core/execution/src/engine.ts:117–172  ·  view source on GitHub ↗
(
  result: ExecuteResult,
)

Source from the content-addressed store, hash-verified

115 : value;
116
117export const formatExecuteResult = (
118 result: ExecuteResult,
119): {
120 text: string;
121 structured: Record<string, unknown>;
122 isError: boolean;
123} => {
124 const resultText =
125 result.result != null
126 ? typeof result.result === "string"
127 ? result.result
128 : JSON.stringify(result.result, null, 2)
129 : null;
130
131 const logText = result.logs && result.logs.length > 0 ? result.logs.join("\n") : null;
132
133 // `emit()` output is shown to the user, not returned to the model, so a
134 // script that only emits comes back with a null result. Acknowledge the
135 // emitted items in the envelope so an emit-without-return reads as "output
136 // went to the user" rather than a silent void.
137 const emitted = result.output?.length ?? 0;
138 const emittedNote =
139 emitted > 0 ? `${emitted} item${emitted === 1 ? "" : "s"} emitted to the user` : null;
140 const emittedField = emitted > 0 ? { emitted } : {};
141
142 if (result.error) {
143 const parts = [`Error: ${result.error}`, ...(logText ? [`\nLogs:\n${logText}`] : [])];
144 return {
145 text: truncate(parts.join("\n"), MAX_PREVIEW_CHARS),
146 structured: {
147 status: "error",
148 error: result.error,
149 ...emittedField,
150 logs: result.logs ?? [],
151 },
152 isError: true,
153 };
154 }
155
156 const resultPart = resultText
157 ? truncate(resultText, MAX_PREVIEW_CHARS)
158 : emittedNote
159 ? `(no return value; ${emittedNote})`
160 : "(no result)";
161 const parts = [resultPart, ...(logText ? [`\nLogs:\n${logText}`] : [])];
162 return {
163 text: parts.join("\n"),
164 structured: {
165 status: "completed",
166 result: result.result ?? null,
167 ...emittedField,
168 logs: result.logs ?? [],
169 },
170 isError: false,
171 };
172};
173
174export const formatPausedExecution = (

Callers 4

executions.tsFile · 0.90
toMcpOutputResultFunction · 0.90
toMcpResultFunction · 0.90

Calls 1

truncateFunction · 0.70

Tested by

no test coverage detected