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

Function formatPausedExecution

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

Source from the content-addressed store, hash-verified

196};
197
198export const formatPausedExecution = (
199 paused: PausedExecution,
200 options?: { readonly deadline?: PausedExecutionDeadline },
201): {
202 text: string;
203 structured: Record<string, unknown>;
204} => {
205 const req = paused.elicitationContext.request;
206 const lines: string[] = [`Execution paused: ${req.message}`];
207 const deadline = options?.deadline;
208 const isUrlElicitation = Predicate.isTagged(req, "UrlElicitation");
209 const isFormElicitation = Predicate.isTagged(req, "FormElicitation");
210 const requestedSchema = isFormElicitation ? req.requestedSchema : undefined;
211 const hasRequestedSchema =
212 requestedSchema !== undefined && Object.keys(requestedSchema).length > 0;
213 const baseInstructions = isUrlElicitation
214 ? `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".`
215 : hasRequestedSchema
216 ? `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".`
217 : `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".`;
218 const deadlineInstructions = deadline
219 ? ` Resume before ${deadline.expiresAt}; this approval window lasts ${formatTtlDuration(deadline.ttlMs)}.`
220 : "";
221 const instructions = `${baseInstructions}${deadlineInstructions}`;
222
223 if (isUrlElicitation) {
224 lines.push(`\nOpen this URL in a browser:\n${req.url}`);
225 lines.push('\nAfter the browser flow, call the resume tool with action "accept".');
226 } else if (hasRequestedSchema) {
227 lines.push(
228 "\nAsk the user for a response matching the requested schema, then call the resume tool.",
229 );
230 lines.push(`\nRequested schema:\n${JSON.stringify(requestedSchema, null, 2)}`);
231 } else {
232 lines.push(
233 '\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".',
234 );
235 }
236
237 // Terms the upstream attached to the approval. Stated plainly, because a
238 // prompt whose schema is empty ("Allow X to access Y?") can still be
239 // asking for a PERSISTENT grant, and the answer differs.
240 const meta = req.meta;
241 if (meta !== undefined && Object.keys(meta).length > 0) {
242 lines.push(`\nApproval terms:\n${JSON.stringify(meta, null, 2)}`);
243 }
244
245 lines.push(`\nexecutionId: ${paused.id}`);
246 if (deadline) {
247 lines.push(
248 `\nresumeDeadline: ${deadline.expiresAt} (${formatTtlDuration(deadline.ttlMs)} approval window)`,
249 );
250 }
251 lines.push(`\ninstructions: ${instructions}`);
252
253 return {
254 text: lines.join("\n"),
255 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