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

Function formatPausedExecution

packages/core/execution/src/engine.ts:174–247  ·  view source on GitHub ↗
(
  paused: PausedExecution,
  options?: { readonly deadline?: PausedExecutionDeadline },
)

Source from the content-addressed store, hash-verified

172};
173
174export const formatPausedExecution = (
175 paused: PausedExecution,
176 options?: { readonly deadline?: PausedExecutionDeadline },
177): {
178 text: string;
179 structured: Record<string, unknown>;
180} => {
181 const req = paused.elicitationContext.request;
182 const lines: string[] = [`Execution paused: ${req.message}`];
183 const deadline = options?.deadline;
184 const isUrlElicitation = Predicate.isTagged(req, "UrlElicitation");
185 const isFormElicitation = Predicate.isTagged(req, "FormElicitation");
186 const requestedSchema = isFormElicitation ? req.requestedSchema : undefined;
187 const hasRequestedSchema =
188 requestedSchema !== undefined && Object.keys(requestedSchema).length > 0;
189 const baseInstructions = isUrlElicitation
190 ? `The user needs to open this URL in a browser and complete the flow. After the user finishes, call the resume tool with executionId "${paused.id}" and action "accept".`
191 : hasRequestedSchema
192 ? `Ask the user for values matching requestedSchema. Then call the resume tool with executionId "${paused.id}", action "accept", and content matching requestedSchema. If the user declines, call resume with action "decline" or "cancel".`
193 : `This is a model-side confirmation gate; there is no browser form to open. Ask the user whether to approve the paused tool call. If the user approves, call the resume tool with executionId "${paused.id}" and action "accept". If the user declines, call resume with action "decline" or "cancel".`;
194 const deadlineInstructions = deadline
195 ? ` Resume before ${deadline.expiresAt}; this approval window lasts ${formatTtlDuration(deadline.ttlMs)}.`
196 : "";
197 const instructions = `${baseInstructions}${deadlineInstructions}`;
198
199 if (isUrlElicitation) {
200 lines.push(`\nOpen this URL in a browser:\n${req.url}`);
201 lines.push('\nAfter the browser flow, call the resume tool with action "accept".');
202 } else if (hasRequestedSchema) {
203 lines.push(
204 "\nAsk the user for a response matching the requested schema, then call the resume tool.",
205 );
206 lines.push(`\nRequested schema:\n${JSON.stringify(requestedSchema, null, 2)}`);
207 } else {
208 lines.push(
209 '\nThis is a model-side confirmation gate; no browser form is waiting. Ask the user whether to approve, then call the resume tool with action "accept", "decline", or "cancel".',
210 );
211 }
212
213 // Terms the upstream attached to the approval. Stated plainly, because a
214 // prompt whose schema is empty ("Allow X to access Y?") can still be
215 // asking for a PERSISTENT grant, and the answer differs.
216 const meta = req.meta;
217 if (meta !== undefined && Object.keys(meta).length > 0) {
218 lines.push(`\nApproval terms:\n${JSON.stringify(meta, null, 2)}`);
219 }
220
221 lines.push(`\nexecutionId: ${paused.id}`);
222 if (deadline) {
223 lines.push(
224 `\nresumeDeadline: ${deadline.expiresAt} (${formatTtlDuration(deadline.ttlMs)} approval window)`,
225 );
226 }
227 lines.push(`\ninstructions: ${instructions}`);
228
229 return {
230 text: lines.join("\n"),
231 structured: {

Callers 9

executions.tsFile · 0.90
engine.test.tsFile · 0.90
pausedFromSessionFunction · 0.90
formatPausedModelResultFunction · 0.90
executeCodeFunction · 0.90
pausedDetailFunction · 0.90

Calls 2

formatTtlDurationFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected