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

Function formatPausedExecution

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

Source from the content-addressed store, hash-verified

150};
151
152export const formatPausedExecution = (
153 paused: PausedExecution,
154 options?: { readonly deadline?: PausedExecutionDeadline },
155): {
156 text: string;
157 structured: Record<string, unknown>;
158} => {
159 const req = paused.elicitationContext.request;
160 const lines: string[] = [`Execution paused: ${req.message}`];
161 const deadline = options?.deadline;
162 const isUrlElicitation = Predicate.isTagged(req, "UrlElicitation");
163 const isFormElicitation = Predicate.isTagged(req, "FormElicitation");
164 const requestedSchema = isFormElicitation ? req.requestedSchema : undefined;
165 const hasRequestedSchema =
166 requestedSchema !== undefined && Object.keys(requestedSchema).length > 0;
167 const baseInstructions = isUrlElicitation
168 ? `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".`
169 : hasRequestedSchema
170 ? `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".`
171 : `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".`;
172 const deadlineInstructions = deadline
173 ? ` Resume before ${deadline.expiresAt}; this approval window lasts ${formatTtlDuration(deadline.ttlMs)}.`
174 : "";
175 const instructions = `${baseInstructions}${deadlineInstructions}`;
176
177 if (isUrlElicitation) {
178 lines.push(`\nOpen this URL in a browser:\n${req.url}`);
179 lines.push('\nAfter the browser flow, call the resume tool with action "accept".');
180 } else if (hasRequestedSchema) {
181 lines.push(
182 "\nAsk the user for a response matching the requested schema, then call the resume tool.",
183 );
184 lines.push(`\nRequested schema:\n${JSON.stringify(requestedSchema, null, 2)}`);
185 } else {
186 lines.push(
187 '\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".',
188 );
189 }
190
191 lines.push(`\nexecutionId: ${paused.id}`);
192 if (deadline) {
193 lines.push(
194 `\nresumeDeadline: ${deadline.expiresAt} (${formatTtlDuration(deadline.ttlMs)} approval window)`,
195 );
196 }
197 lines.push(`\ninstructions: ${instructions}`);
198
199 return {
200 text: lines.join("\n"),
201 structured: {
202 status: "waiting_for_interaction",
203 executionId: paused.id,
204 ...(deadline ? { expiresAt: deadline.expiresAt, ttlMs: deadline.ttlMs } : {}),
205 interaction: {
206 kind: isUrlElicitation ? "url" : "form",
207 message: req.message,
208 instructions,
209 address: String(paused.elicitationContext.address),

Callers 8

executions.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