MCPcopy Create free account
hub / github.com/cortexkit/magic-context / run

Method run

packages/pi-plugin/src/subagent-runner.ts:389–412  ·  view source on GitHub ↗
(options: SubagentRunOptions)

Source from the content-addressed store, hash-verified

387 }
388
389 async run(options: SubagentRunOptions): Promise<SubagentRunResult> {
390 const models = [options.model, ...(options.fallbackModels ?? [])].filter(
391 (model): model is string => typeof model === "string" && model.length > 0,
392 );
393 const attempts = models.length > 0 ? models : [undefined];
394 let lastResult: SubagentRunResult | null = null;
395 for (let index = 0; index < attempts.length; index += 1) {
396 const model = attempts[index];
397 const attemptOptions = {
398 ...options,
399 model,
400 fallbackModels: undefined,
401 };
402 const result = await this.runOnce(attemptOptions);
403 if (result.ok) return result;
404 lastResult = result;
405 if (index >= attempts.length - 1 || !isFallbackEligible(result.reason)) {
406 return result;
407 }
408 }
409 return (
410 lastResult ?? this.runOnce({ ...options, fallbackModels: undefined })
411 );
412 }
413
414 private async runOnce(
415 options: SubagentRunOptions,

Callers 1

registerCtxAugCommandFunction · 0.95

Calls 2

runOnceMethod · 0.95
isFallbackEligibleFunction · 0.85

Tested by

no test coverage detected