@theokit/sdk 4.18.0 → 4.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -7532,16 +7532,38 @@ async function* runUntilImpl(agent, goal, options, deps) {
7532
7532
  while (turn < maxTurns) {
7533
7533
  if (isAborted()) {
7534
7534
  yield { type: "status_change", status: "paused", reason: "aborted via AbortSignal" };
7535
- return { status: "paused", turnsUsed: turn, tokensUsed, finalResponse: lastResponse || void 0 };
7535
+ return {
7536
+ status: "paused",
7537
+ turnsUsed: turn,
7538
+ tokensUsed,
7539
+ finalResponse: lastResponse || void 0
7540
+ };
7536
7541
  }
7537
7542
  turn += 1;
7538
7543
  yield { type: "turn_start", turn, goal };
7539
7544
  const continuationPrompt = turn === 1 ? goal : composeContinuation(goal, lastResponse);
7540
7545
  const run = await agent.send(continuationPrompt);
7546
+ const cancelOnAbort = () => {
7547
+ void run.cancel?.();
7548
+ };
7549
+ if (signal !== void 0) {
7550
+ if (signal.aborted) cancelOnAbort();
7551
+ else signal.addEventListener("abort", cancelOnAbort, { once: true });
7552
+ }
7541
7553
  const result = await run.wait();
7554
+ if (signal !== void 0) signal.removeEventListener("abort", cancelOnAbort);
7542
7555
  lastResponse = result.result ?? "";
7543
7556
  const turnTokens = result.usage?.totalTokens;
7544
7557
  if (typeof turnTokens === "number") tokensUsed += turnTokens;
7558
+ if (isAborted()) {
7559
+ yield { type: "status_change", status: "paused", reason: "aborted via AbortSignal" };
7560
+ return {
7561
+ status: "paused",
7562
+ turnsUsed: turn,
7563
+ tokensUsed,
7564
+ finalResponse: lastResponse || void 0
7565
+ };
7566
+ }
7545
7567
  yield { type: "agent_response", turn, content: lastResponse };
7546
7568
  const judgeOpts = {};
7547
7569
  if (options?.judgeModel !== void 0) judgeOpts.judgeModel = options.judgeModel;
@@ -7576,7 +7598,12 @@ async function* runUntilImpl(agent, goal, options, deps) {
7576
7598
  }
7577
7599
  if (judgment.verdict === "done") {
7578
7600
  yield { type: "status_change", status: "completed", reason: judgment.reason };
7579
- return { status: "completed", turnsUsed: turn, tokensUsed, finalResponse: lastResponse || void 0 };
7601
+ return {
7602
+ status: "completed",
7603
+ turnsUsed: turn,
7604
+ tokensUsed,
7605
+ finalResponse: lastResponse || void 0
7606
+ };
7580
7607
  }
7581
7608
  if (judgment.verdict === "skipped") {
7582
7609
  yield {
@@ -7584,7 +7611,12 @@ async function* runUntilImpl(agent, goal, options, deps) {
7584
7611
  status: "completed",
7585
7612
  reason: `skipped: ${judgment.reason}`
7586
7613
  };
7587
- return { status: "completed", turnsUsed: turn, tokensUsed, finalResponse: lastResponse || void 0 };
7614
+ return {
7615
+ status: "completed",
7616
+ turnsUsed: turn,
7617
+ tokensUsed,
7618
+ finalResponse: lastResponse || void 0
7619
+ };
7588
7620
  }
7589
7621
  if (tokenBudget !== void 0 && tokensUsed >= tokenBudget) {
7590
7622
  yield {
@@ -7592,7 +7624,12 @@ async function* runUntilImpl(agent, goal, options, deps) {
7592
7624
  status: "budget_limited",
7593
7625
  reason: `token budget (${tokenBudget}) reached: ${tokensUsed} used`
7594
7626
  };
7595
- return { status: "budget_limited", turnsUsed: turn, tokensUsed, finalResponse: lastResponse || void 0 };
7627
+ return {
7628
+ status: "budget_limited",
7629
+ turnsUsed: turn,
7630
+ tokensUsed,
7631
+ finalResponse: lastResponse || void 0
7632
+ };
7596
7633
  }
7597
7634
  yield { type: "continuation", turn, prompt: continuationPrompt };
7598
7635
  }
@@ -7601,7 +7638,12 @@ async function* runUntilImpl(agent, goal, options, deps) {
7601
7638
  status: "failed",
7602
7639
  reason: `max turns (${maxTurns}) exhausted`
7603
7640
  };
7604
- return { status: "failed", turnsUsed: turn, tokensUsed, finalResponse: lastResponse || void 0 };
7641
+ return {
7642
+ status: "failed",
7643
+ turnsUsed: turn,
7644
+ tokensUsed,
7645
+ finalResponse: lastResponse || void 0
7646
+ };
7605
7647
  }
7606
7648
  function composeContinuation(goal, lastResponse) {
7607
7649
  return [
@@ -22628,6 +22670,23 @@ async function updateJobStatus(jobId, enabled) {
22628
22670
  return updated;
22629
22671
  }
22630
22672
 
22673
+ // src/goal-loop.ts
22674
+ function runGoalLoop(agent, goal, options, depsOverride) {
22675
+ async function* wrap() {
22676
+ const { runUntilImpl: runUntilImpl2 } = await Promise.resolve().then(() => (init_run_until(), run_until_exports));
22677
+ const deps = depsOverride ?? await (async () => {
22678
+ const { judgeCallImpl: judgeCallImpl2 } = await Promise.resolve().then(() => (init_judge_call(), judge_call_exports));
22679
+ const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
22680
+ const create = getAgentFacade2().create;
22681
+ return {
22682
+ judge: (ctx, opts) => judgeCallImpl2(ctx, opts, { create })
22683
+ };
22684
+ })();
22685
+ return yield* runUntilImpl2(agent, goal, options, deps);
22686
+ }
22687
+ return wrap();
22688
+ }
22689
+
22631
22690
  // src/define-provider.ts
22632
22691
  init_builtin();
22633
22692
  init_registry();
@@ -24502,6 +24561,7 @@ exports.mkMemoryId = mkMemoryId;
24502
24561
  exports.normalizeSchema = normalizeSchema;
24503
24562
  exports.normalizeUsage = normalizeUsage;
24504
24563
  exports.preflightCheck = preflightCheck;
24564
+ exports.runGoalLoop = runGoalLoop;
24505
24565
  exports.scopedConversationId = scopedConversationId;
24506
24566
  exports.sessionScopePrefix = sessionScopePrefix;
24507
24567
  exports.toShareGptTrajectory = toShareGptTrajectory;