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

Function formatPausedExecution

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

Source from the content-addressed store, hash-verified

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