@theokit/sdk 2.2.0 → 2.4.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/CHANGELOG.md +122 -0
- package/dist/a2a/index.cjs +191 -48
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +192 -49
- package/dist/a2a/index.js.map +1 -1
- package/dist/compaction.cjs +78 -0
- package/dist/compaction.cjs.map +1 -0
- package/dist/compaction.d.cts +76 -0
- package/dist/compaction.d.ts +76 -0
- package/dist/compaction.js +70 -0
- package/dist/compaction.js.map +1 -0
- package/dist/{cron-JSPSFczQ.d.cts → cron-B656C3iq.d.cts} +28 -2
- package/dist/{cron-Aksw2Hy4.d.ts → cron-CM2M9mhB.d.ts} +28 -2
- package/dist/cron.cjs +192 -57
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.d.cts +2 -2
- package/dist/cron.d.ts +2 -2
- package/dist/cron.js +192 -57
- package/dist/cron.js.map +1 -1
- package/dist/{errors-Bcw_Pakm.d.ts → errors-DG_7CAUg.d.ts} +1 -1
- package/dist/{errors-Vhg6ZV4o.d.cts → errors-QDYUPABr.d.cts} +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/eval.cjs +192 -57
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +192 -57
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +275 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -7
- package/dist/index.d.ts +50 -7
- package/dist/index.js +275 -69
- package/dist/index.js.map +1 -1
- package/dist/internal/agent-loop/loop.d.ts +5 -0
- package/dist/internal/llm/model-capabilities.d.ts +40 -0
- package/dist/internal/llm/model-identifier.d.ts +9 -1
- package/dist/internal/llm/model-option.d.ts +38 -0
- package/dist/internal/runtime/compression/compression-attempt.d.ts +24 -0
- package/dist/internal/runtime/compression/compression-config.d.ts +33 -0
- package/dist/internal/runtime/compression/compression-decision.d.ts +10 -0
- package/dist/internal/runtime/compression/compression-helpers.d.ts +18 -0
- package/dist/internal/runtime/compression/compression-model-registry.d.ts +41 -0
- package/dist/internal/runtime/compression/compression-summarizer.d.ts +29 -0
- package/dist/internal/runtime/context/project-instructions.d.ts +66 -0
- package/dist/internal/runtime/context/replay-history.d.ts +43 -0
- package/dist/internal/runtime/hooks/hooks-frontmatter.d.ts +1 -1
- package/dist/internal/runtime/lifecycle/run-to-completion.d.ts +22 -0
- package/dist/internal/runtime/skills/discover-skills.d.ts +68 -0
- package/dist/internal/runtime/skills/skills-block.d.ts +18 -0
- package/dist/internal/runtime/skills/subagent-tool-scope.d.ts +25 -0
- package/dist/messages.cjs +24 -0
- package/dist/messages.cjs.map +1 -0
- package/dist/messages.d.cts +33 -0
- package/dist/messages.d.ts +33 -0
- package/dist/messages.js +20 -0
- package/dist/messages.js.map +1 -0
- package/dist/models.cjs +233 -0
- package/dist/models.cjs.map +1 -0
- package/dist/models.d.cts +16 -0
- package/dist/models.d.ts +16 -0
- package/dist/models.js +228 -0
- package/dist/models.js.map +1 -0
- package/dist/project.cjs +149 -0
- package/dist/project.cjs.map +1 -0
- package/dist/project.d.cts +14 -0
- package/dist/project.d.ts +14 -0
- package/dist/project.js +146 -0
- package/dist/project.js.map +1 -0
- package/dist/{run-ekGKZlmg.d.cts → run-BPRYG1Id.d.cts} +55 -2
- package/dist/{run-ekGKZlmg.d.ts → run-BPRYG1Id.d.ts} +55 -2
- package/dist/skills.cjs +282 -0
- package/dist/skills.cjs.map +1 -0
- package/dist/skills.d.cts +19 -0
- package/dist/skills.d.ts +19 -0
- package/dist/skills.js +279 -0
- package/dist/skills.js.map +1 -0
- package/dist/subagents.cjs +24 -0
- package/dist/subagents.cjs.map +1 -0
- package/dist/subagents.d.cts +14 -0
- package/dist/subagents.d.ts +14 -0
- package/dist/subagents.js +21 -0
- package/dist/subagents.js.map +1 -0
- package/dist/types/agent.d.ts +22 -0
- package/dist/types/conversation-storage.d.ts +5 -1
- package/dist/types/run.d.ts +54 -1
- package/package.json +62 -2
package/dist/errors.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, g as BudgetExceededError, C as ConfigurationError, u as CredentialPoolExhaustedError, E as ErrorCode, m as ErrorMetadata, I as IntegrationNotConnectedError, n as InvalidTaskIdError, K as KnownAgentRunErrorCode, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, T as TheokitAgentError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-
|
|
2
|
-
import './run-
|
|
1
|
+
export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, g as BudgetExceededError, C as ConfigurationError, u as CredentialPoolExhaustedError, E as ErrorCode, m as ErrorMetadata, I as IntegrationNotConnectedError, n as InvalidTaskIdError, K as KnownAgentRunErrorCode, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, T as TheokitAgentError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-QDYUPABr.cjs';
|
|
2
|
+
import './run-BPRYG1Id.cjs';
|
package/dist/eval.cjs
CHANGED
|
@@ -1439,6 +1439,71 @@ var init_agent_factory_registry = __esm({
|
|
|
1439
1439
|
}
|
|
1440
1440
|
});
|
|
1441
1441
|
|
|
1442
|
+
// src/internal/runtime/lifecycle/run-to-completion.ts
|
|
1443
|
+
var run_to_completion_exports = {};
|
|
1444
|
+
__export(run_to_completion_exports, {
|
|
1445
|
+
classifyRound: () => classifyRound,
|
|
1446
|
+
runToCompletionImpl: () => runToCompletionImpl
|
|
1447
|
+
});
|
|
1448
|
+
function isEmptyRound(result) {
|
|
1449
|
+
return (result.result ?? "").trim() === "";
|
|
1450
|
+
}
|
|
1451
|
+
function classifyRound(result, round, maxRounds, emptyStreak) {
|
|
1452
|
+
if (result.stoppedAtIterationLimit !== true) return "done";
|
|
1453
|
+
if (isEmptyRound(result) && emptyStreak >= 1) return "no_progress";
|
|
1454
|
+
if (round >= maxRounds) return "step_limit";
|
|
1455
|
+
return "continue";
|
|
1456
|
+
}
|
|
1457
|
+
function addUsage(acc, u) {
|
|
1458
|
+
if (u === void 0) return acc;
|
|
1459
|
+
const inputTokens = (acc?.inputTokens ?? 0) + u.inputTokens;
|
|
1460
|
+
const outputTokens = (acc?.outputTokens ?? 0) + u.outputTokens;
|
|
1461
|
+
const sumOpt = (a, b) => a === void 0 && b === void 0 ? void 0 : (a ?? 0) + (b ?? 0);
|
|
1462
|
+
return {
|
|
1463
|
+
inputTokens,
|
|
1464
|
+
outputTokens,
|
|
1465
|
+
totalTokens: inputTokens + outputTokens,
|
|
1466
|
+
cacheReadTokens: sumOpt(acc?.cacheReadTokens, u.cacheReadTokens),
|
|
1467
|
+
cacheWriteTokens: sumOpt(acc?.cacheWriteTokens, u.cacheWriteTokens),
|
|
1468
|
+
reasoningTokens: sumOpt(acc?.reasoningTokens, u.reasoningTokens)
|
|
1469
|
+
};
|
|
1470
|
+
}
|
|
1471
|
+
function buildResult(terminal, rounds, lastResult, usage) {
|
|
1472
|
+
return { terminal, rounds, lastResult, ...usage !== void 0 ? { usage } : {} };
|
|
1473
|
+
}
|
|
1474
|
+
async function stepRound(agent, prompt, sendOptions, round, maxRounds, state2) {
|
|
1475
|
+
const run = await agent.send(prompt, sendOptions);
|
|
1476
|
+
const result = await run.wait();
|
|
1477
|
+
const usage = addUsage(state2.usage, result.usage);
|
|
1478
|
+
const decision = classifyRound(result, round, maxRounds, state2.emptyStreak);
|
|
1479
|
+
if (decision !== "continue") return { terminal: buildResult(decision, round, result, usage) };
|
|
1480
|
+
const emptyStreak = isEmptyRound(result) ? state2.emptyStreak + 1 : 0;
|
|
1481
|
+
return { next: { usage, emptyStreak }, lastResult: result };
|
|
1482
|
+
}
|
|
1483
|
+
async function runToCompletionImpl(agent, message, options) {
|
|
1484
|
+
const maxRounds = options?.maxRounds ?? DEFAULT_MAX_ROUNDS;
|
|
1485
|
+
const continuationPrompt = options?.continuationPrompt ?? DEFAULT_CONTINUATION_PROMPT;
|
|
1486
|
+
const { onTruncated, signal, sendOptions } = options ?? {};
|
|
1487
|
+
let state2 = { usage: void 0, emptyStreak: 0 };
|
|
1488
|
+
for (let round = 0; ; round += 1) {
|
|
1489
|
+
const prompt = round === 0 ? message : continuationPrompt;
|
|
1490
|
+
const outcome = await stepRound(agent, prompt, sendOptions, round, maxRounds, state2);
|
|
1491
|
+
if ("terminal" in outcome) return outcome.terminal;
|
|
1492
|
+
state2 = outcome.next;
|
|
1493
|
+
await onTruncated?.({ round });
|
|
1494
|
+
if (signal?.aborted === true) {
|
|
1495
|
+
return buildResult("step_limit", round, outcome.lastResult, state2.usage);
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
var DEFAULT_MAX_ROUNDS, DEFAULT_CONTINUATION_PROMPT;
|
|
1500
|
+
var init_run_to_completion = __esm({
|
|
1501
|
+
"src/internal/runtime/lifecycle/run-to-completion.ts"() {
|
|
1502
|
+
DEFAULT_MAX_ROUNDS = 5;
|
|
1503
|
+
DEFAULT_CONTINUATION_PROMPT = "Continue from where you left off and finish the task. If it is already complete, give the final answer.";
|
|
1504
|
+
}
|
|
1505
|
+
});
|
|
1506
|
+
|
|
1442
1507
|
// src/internal/runtime/lifecycle/fork-agent.ts
|
|
1443
1508
|
var fork_agent_exports = {};
|
|
1444
1509
|
__export(fork_agent_exports, {
|
|
@@ -4862,6 +4927,18 @@ var CloudAgent = class {
|
|
|
4862
4927
|
"fork"
|
|
4863
4928
|
);
|
|
4864
4929
|
}
|
|
4930
|
+
/**
|
|
4931
|
+
* The continuation driver re-sends against a stateful local session; the
|
|
4932
|
+
* cloud runtime manages its own continuation policy server-side (M1 Phase 3).
|
|
4933
|
+
*
|
|
4934
|
+
* @public
|
|
4935
|
+
*/
|
|
4936
|
+
runToCompletion() {
|
|
4937
|
+
throw new UnsupportedRunOperationError(
|
|
4938
|
+
"Agent.runToCompletion() is not supported on cloud agents. Cloud runtime manages continuation server-side. Use a local agent.",
|
|
4939
|
+
"runToCompletion"
|
|
4940
|
+
);
|
|
4941
|
+
}
|
|
4865
4942
|
/**
|
|
4866
4943
|
* Personality presets require consistent server-side enforcement that
|
|
4867
4944
|
* the cloud runtime (pre-release) does not yet provide. Reject explicitly
|
|
@@ -6422,6 +6499,8 @@ function parseSubagentMarkdown(raw, filename) {
|
|
|
6422
6499
|
if (fields.model !== void 0) {
|
|
6423
6500
|
definition.model = fields.model === "inherit" ? "inherit" : { id: fields.model };
|
|
6424
6501
|
}
|
|
6502
|
+
const tools = fields.tools?.split(/[\s,]+/).map((t) => t.trim()).filter((t) => t.length > 0);
|
|
6503
|
+
if (tools !== void 0 && tools.length > 0) definition.tools = tools;
|
|
6425
6504
|
return { name, definition };
|
|
6426
6505
|
}
|
|
6427
6506
|
function splitFrontmatter2(raw, filename) {
|
|
@@ -6585,21 +6664,24 @@ ${lines.join("\n")}
|
|
|
6585
6664
|
}
|
|
6586
6665
|
};
|
|
6587
6666
|
|
|
6667
|
+
// src/internal/runtime/skills/skills-block.ts
|
|
6668
|
+
function buildSkillsBlock(skills) {
|
|
6669
|
+
if (skills.length === 0) return void 0;
|
|
6670
|
+
const lines = skills.map(
|
|
6671
|
+
(skill) => ` - ${escapeBlockBody(skill.name)}: ${escapeBlockBody(skill.description)}`
|
|
6672
|
+
);
|
|
6673
|
+
return `<skills>
|
|
6674
|
+
${lines.join("\n")}
|
|
6675
|
+
</skills>`;
|
|
6676
|
+
}
|
|
6677
|
+
|
|
6588
6678
|
// src/internal/runtime/system-prompt/sources/skills-provider.ts
|
|
6589
6679
|
var SkillsPromptProvider = class {
|
|
6590
6680
|
id = "skills";
|
|
6591
6681
|
priority = 20;
|
|
6592
6682
|
contribute(ctx) {
|
|
6593
6683
|
if (ctx.skillsAutoInject === false) return Promise.resolve(void 0);
|
|
6594
|
-
|
|
6595
|
-
const lines = ctx.skills.map((skill) => {
|
|
6596
|
-
const name = escapeBlockBody(skill.name);
|
|
6597
|
-
const description = escapeBlockBody(skill.description);
|
|
6598
|
-
return ` - ${name}: ${description}`;
|
|
6599
|
-
});
|
|
6600
|
-
return Promise.resolve(`<skills>
|
|
6601
|
-
${lines.join("\n")}
|
|
6602
|
-
</skills>`);
|
|
6684
|
+
return Promise.resolve(buildSkillsBlock(ctx.skills));
|
|
6603
6685
|
}
|
|
6604
6686
|
};
|
|
6605
6687
|
|
|
@@ -7707,7 +7789,7 @@ async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
|
|
|
7707
7789
|
return metadata;
|
|
7708
7790
|
}
|
|
7709
7791
|
|
|
7710
|
-
// src/internal/runtime/skills/skills
|
|
7792
|
+
// src/internal/runtime/skills/discover-skills.ts
|
|
7711
7793
|
init_errors();
|
|
7712
7794
|
|
|
7713
7795
|
// src/internal/runtime/skills/skill-frontmatter.ts
|
|
@@ -7779,6 +7861,61 @@ function hasContent(value) {
|
|
|
7779
7861
|
return value !== void 0 && value.trim().length > 0;
|
|
7780
7862
|
}
|
|
7781
7863
|
|
|
7864
|
+
// src/internal/runtime/skills/discover-skills.ts
|
|
7865
|
+
async function discoverSkills(dir, options) {
|
|
7866
|
+
let entries;
|
|
7867
|
+
try {
|
|
7868
|
+
entries = await readWorkspaceDir(dir, "skills_read_error", "skills directory");
|
|
7869
|
+
} catch {
|
|
7870
|
+
return [];
|
|
7871
|
+
}
|
|
7872
|
+
const skills = [];
|
|
7873
|
+
for (const entry of entries) {
|
|
7874
|
+
if (!entry.isDirectory()) continue;
|
|
7875
|
+
let skillDir;
|
|
7876
|
+
try {
|
|
7877
|
+
skillDir = safePathJoin(dir, entry.name);
|
|
7878
|
+
assertNoSymlinkEscape(skillDir, dir);
|
|
7879
|
+
} catch {
|
|
7880
|
+
continue;
|
|
7881
|
+
}
|
|
7882
|
+
const skillPath = path.join(skillDir, "SKILL.md");
|
|
7883
|
+
let raw;
|
|
7884
|
+
try {
|
|
7885
|
+
raw = await promises.readFile(skillPath, "utf8");
|
|
7886
|
+
} catch {
|
|
7887
|
+
continue;
|
|
7888
|
+
}
|
|
7889
|
+
const skill = tryParseSkill(raw, entry.name, skillPath, options);
|
|
7890
|
+
if (skill !== void 0) skills.push(skill);
|
|
7891
|
+
}
|
|
7892
|
+
return skills;
|
|
7893
|
+
}
|
|
7894
|
+
function tryParseSkill(raw, fallbackName, source, options) {
|
|
7895
|
+
try {
|
|
7896
|
+
const frontmatter = parseSkillFrontmatter(raw, fallbackName);
|
|
7897
|
+
const skill = {
|
|
7898
|
+
name: frontmatter.name,
|
|
7899
|
+
description: frontmatter.description,
|
|
7900
|
+
source
|
|
7901
|
+
};
|
|
7902
|
+
if (frontmatter.category !== void 0) skill.category = frontmatter.category;
|
|
7903
|
+
if (frontmatter.dependencies !== void 0) skill.dependencies = frontmatter.dependencies;
|
|
7904
|
+
return skill;
|
|
7905
|
+
} catch (cause) {
|
|
7906
|
+
if (cause instanceof ConfigurationError) {
|
|
7907
|
+
options?.onInvalidSkill?.({
|
|
7908
|
+
name: fallbackName,
|
|
7909
|
+
source,
|
|
7910
|
+
code: cause.code ?? "unknown",
|
|
7911
|
+
message: cause.message
|
|
7912
|
+
});
|
|
7913
|
+
return void 0;
|
|
7914
|
+
}
|
|
7915
|
+
throw cause;
|
|
7916
|
+
}
|
|
7917
|
+
}
|
|
7918
|
+
|
|
7782
7919
|
// src/internal/runtime/skills/skills-manager.ts
|
|
7783
7920
|
var SkillsManager = class {
|
|
7784
7921
|
constructor(cwd, _enabled, settingSourcesIncludeProject) {
|
|
@@ -7796,56 +7933,20 @@ var SkillsManager = class {
|
|
|
7796
7933
|
await this.refresh();
|
|
7797
7934
|
}
|
|
7798
7935
|
async refresh() {
|
|
7799
|
-
this.skills = [];
|
|
7800
7936
|
const skillsRoot = path.join(this.cwd, ".theokit", "skills");
|
|
7801
|
-
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
|
|
7807
|
-
assertNoSymlinkEscape(skillDir, skillsRoot);
|
|
7808
|
-
} catch {
|
|
7809
|
-
continue;
|
|
7810
|
-
}
|
|
7811
|
-
const skillPath = path.join(skillDir, "SKILL.md");
|
|
7812
|
-
let raw;
|
|
7813
|
-
try {
|
|
7814
|
-
raw = await promises.readFile(skillPath, "utf8");
|
|
7815
|
-
} catch {
|
|
7816
|
-
continue;
|
|
7937
|
+
this.skills = await discoverSkills(skillsRoot, {
|
|
7938
|
+
onInvalidSkill: (info) => {
|
|
7939
|
+
process.stderr.write(
|
|
7940
|
+
`[theokit-sdk] skill ${info.name} skipped (${info.code}): ${info.message}
|
|
7941
|
+
`
|
|
7942
|
+
);
|
|
7817
7943
|
}
|
|
7818
|
-
|
|
7819
|
-
if (metadata !== void 0) this.skills.push(metadata);
|
|
7820
|
-
}
|
|
7944
|
+
});
|
|
7821
7945
|
}
|
|
7822
7946
|
list() {
|
|
7823
7947
|
return Promise.resolve(this.skills);
|
|
7824
7948
|
}
|
|
7825
7949
|
};
|
|
7826
|
-
function tryParseSkill(raw, fallbackName, source) {
|
|
7827
|
-
try {
|
|
7828
|
-
const frontmatter = parseSkillFrontmatter(raw, fallbackName);
|
|
7829
|
-
const metadata = {
|
|
7830
|
-
name: frontmatter.name,
|
|
7831
|
-
description: frontmatter.description,
|
|
7832
|
-
source
|
|
7833
|
-
};
|
|
7834
|
-
if (frontmatter.category !== void 0) metadata.category = frontmatter.category;
|
|
7835
|
-
if (frontmatter.dependencies !== void 0) metadata.dependencies = frontmatter.dependencies;
|
|
7836
|
-
return metadata;
|
|
7837
|
-
} catch (cause) {
|
|
7838
|
-
if (cause instanceof ConfigurationError) {
|
|
7839
|
-
const code = cause.code ?? "unknown";
|
|
7840
|
-
process.stderr.write(
|
|
7841
|
-
`[theokit-sdk] skill ${fallbackName} skipped (${code}): ${cause.message}
|
|
7842
|
-
`
|
|
7843
|
-
);
|
|
7844
|
-
return void 0;
|
|
7845
|
-
}
|
|
7846
|
-
throw cause;
|
|
7847
|
-
}
|
|
7848
|
-
}
|
|
7849
7950
|
|
|
7850
7951
|
// src/internal/runtime/local-agent/local-agent-bootstrap.ts
|
|
7851
7952
|
function registerLocalAgent(args) {
|
|
@@ -8258,6 +8359,7 @@ async function initLoopContext(inputs) {
|
|
|
8258
8359
|
finalStatus: "finished",
|
|
8259
8360
|
usage: new UsageAccumulator(),
|
|
8260
8361
|
nudgeAttempts: 0,
|
|
8362
|
+
stopFeedbackAttempts: 0,
|
|
8261
8363
|
...memoryProviderHandle !== void 0 ? { memoryProviderHandle } : {},
|
|
8262
8364
|
...memorySystemPromptAdditions !== void 0 ? { memorySystemPromptAdditions } : {}
|
|
8263
8365
|
};
|
|
@@ -8402,8 +8504,9 @@ function registerLoopError(ctx, cause) {
|
|
|
8402
8504
|
if (ctx.error !== void 0) return;
|
|
8403
8505
|
const rawMessage = cause?.message;
|
|
8404
8506
|
const message = typeof rawMessage === "string" ? rawMessage : cause instanceof Error ? cause.message : String(cause);
|
|
8507
|
+
const metaCode = cause?.metadata?.code;
|
|
8405
8508
|
const rawCode = cause?.code;
|
|
8406
|
-
const code = typeof rawCode === "string" ? rawCode : void 0;
|
|
8509
|
+
const code = typeof metaCode === "string" ? metaCode : typeof rawCode === "string" ? rawCode : void 0;
|
|
8407
8510
|
ctx.error = code !== void 0 ? { message, code, cause } : { message, cause };
|
|
8408
8511
|
}
|
|
8409
8512
|
async function runCollectorLoop(generator, inputs, ctx) {
|
|
@@ -9199,6 +9302,7 @@ function computeUsageCost(inputs, usage) {
|
|
|
9199
9302
|
|
|
9200
9303
|
// src/internal/agent-loop/loop.ts
|
|
9201
9304
|
var MAX_NUDGE_ATTEMPTS = 2;
|
|
9305
|
+
var MAX_STOP_FEEDBACK_ATTEMPTS = 2;
|
|
9202
9306
|
async function runAgentLoop(inputs) {
|
|
9203
9307
|
const sendSpan = inputs.telemetry?.startSpan("agent.send", {
|
|
9204
9308
|
agentId: inputs.agentId,
|
|
@@ -9356,6 +9460,28 @@ function shouldNudgeAndContinue(ctx, llmOutput) {
|
|
|
9356
9460
|
});
|
|
9357
9461
|
return true;
|
|
9358
9462
|
}
|
|
9463
|
+
async function reflectAfterStop(inputs, ctx) {
|
|
9464
|
+
const result = await inputs.hooks.run({
|
|
9465
|
+
event: "stop",
|
|
9466
|
+
agentId: inputs.agentId,
|
|
9467
|
+
runId: inputs.runId
|
|
9468
|
+
});
|
|
9469
|
+
if (result.blocked) return false;
|
|
9470
|
+
if (ctx.stopFeedbackAttempts >= MAX_STOP_FEEDBACK_ATTEMPTS) return false;
|
|
9471
|
+
const feedback = result.decisions.find(
|
|
9472
|
+
(d) => d.decision === "feedback" && (d.feedback ?? "").length > 0
|
|
9473
|
+
)?.feedback;
|
|
9474
|
+
if (feedback === void 0) return false;
|
|
9475
|
+
ctx.stopFeedbackAttempts += 1;
|
|
9476
|
+
ctx.messages.push({ role: "user", content: [{ type: "text", text: feedback }] });
|
|
9477
|
+
return true;
|
|
9478
|
+
}
|
|
9479
|
+
async function finishOrReflect(inputs, ctx, llmOutput) {
|
|
9480
|
+
if (shouldNudgeAndContinue(ctx, llmOutput)) return "continue";
|
|
9481
|
+
if (await reflectAfterStop(inputs, ctx)) return "continue";
|
|
9482
|
+
ctx.finalStatus = "finished";
|
|
9483
|
+
return "done";
|
|
9484
|
+
}
|
|
9359
9485
|
async function runIteration(inputs, ctx) {
|
|
9360
9486
|
const llmOutput = await streamLlmTurn(inputs, ctx);
|
|
9361
9487
|
accumulateUsage(ctx.usage, llmOutput);
|
|
@@ -9389,9 +9515,7 @@ async function continueOrTerminate(inputs, ctx, llmOutput) {
|
|
|
9389
9515
|
await emitAssistantTextStep(inputs, ctx, llmOutput.text);
|
|
9390
9516
|
}
|
|
9391
9517
|
if (llmOutput.stopReason !== "tool_use" || llmOutput.toolCalls.length === 0) {
|
|
9392
|
-
|
|
9393
|
-
ctx.finalStatus = "finished";
|
|
9394
|
-
return "done";
|
|
9518
|
+
return finishOrReflect(inputs, ctx, llmOutput);
|
|
9395
9519
|
}
|
|
9396
9520
|
ctx.messages.push(buildAssistantTurn(llmOutput.text, llmOutput.toolCalls));
|
|
9397
9521
|
const toolResults = await dispatchTools(inputs, ctx.tools, llmOutput.toolCalls, ctx.events);
|
|
@@ -14342,6 +14466,13 @@ function localAgentRunUntil(agent, goal, options) {
|
|
|
14342
14466
|
}
|
|
14343
14467
|
return wrap();
|
|
14344
14468
|
}
|
|
14469
|
+
function localAgentRunToCompletion(agent, message, options) {
|
|
14470
|
+
async function run() {
|
|
14471
|
+
const { runToCompletionImpl: runToCompletionImpl2 } = await Promise.resolve().then(() => (init_run_to_completion(), run_to_completion_exports));
|
|
14472
|
+
return runToCompletionImpl2({ send: (m, o) => agent.send(m, o) }, message, options);
|
|
14473
|
+
}
|
|
14474
|
+
return run();
|
|
14475
|
+
}
|
|
14345
14476
|
async function localAgentFork(parent, options) {
|
|
14346
14477
|
const { forkAgentImpl: forkAgentImpl2 } = await Promise.resolve().then(() => (init_fork_agent(), fork_agent_exports));
|
|
14347
14478
|
const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
|
|
@@ -14882,6 +15013,10 @@ var LocalAgent = class {
|
|
|
14882
15013
|
fork(options) {
|
|
14883
15014
|
return localAgentFork({ agentId: this.agentId, options: this.options, personalitySlugSnapshot: this.personalityStore.active(this.agentId) }, options);
|
|
14884
15015
|
}
|
|
15016
|
+
// biome-ignore format: G8 budget — see runUntil comment above.
|
|
15017
|
+
runToCompletion(message, options) {
|
|
15018
|
+
return localAgentRunToCompletion(this, message, options);
|
|
15019
|
+
}
|
|
14885
15020
|
};
|
|
14886
15021
|
function resolveCwd(cwd) {
|
|
14887
15022
|
return (Array.isArray(cwd) ? cwd[0] : cwd) ?? process.cwd();
|