@theokit/sdk 2.3.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 +97 -0
- package/dist/a2a/index.cjs +103 -48
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +104 -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-B_H8rn-j.d.cts → cron-B656C3iq.d.cts} +8 -0
- package/dist/{cron-DX6HbHxd.d.ts → cron-CM2M9mhB.d.ts} +8 -0
- package/dist/cron.cjs +104 -57
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.d.cts +1 -1
- package/dist/cron.d.ts +1 -1
- package/dist/cron.js +104 -57
- package/dist/cron.js.map +1 -1
- package/dist/eval.cjs +104 -57
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +104 -57
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +104 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +104 -57
- 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/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/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 +8 -0
- package/package.json +63 -3
package/dist/eval.cjs
CHANGED
|
@@ -6499,6 +6499,8 @@ function parseSubagentMarkdown(raw, filename) {
|
|
|
6499
6499
|
if (fields.model !== void 0) {
|
|
6500
6500
|
definition.model = fields.model === "inherit" ? "inherit" : { id: fields.model };
|
|
6501
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;
|
|
6502
6504
|
return { name, definition };
|
|
6503
6505
|
}
|
|
6504
6506
|
function splitFrontmatter2(raw, filename) {
|
|
@@ -6662,21 +6664,24 @@ ${lines.join("\n")}
|
|
|
6662
6664
|
}
|
|
6663
6665
|
};
|
|
6664
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
|
+
|
|
6665
6678
|
// src/internal/runtime/system-prompt/sources/skills-provider.ts
|
|
6666
6679
|
var SkillsPromptProvider = class {
|
|
6667
6680
|
id = "skills";
|
|
6668
6681
|
priority = 20;
|
|
6669
6682
|
contribute(ctx) {
|
|
6670
6683
|
if (ctx.skillsAutoInject === false) return Promise.resolve(void 0);
|
|
6671
|
-
|
|
6672
|
-
const lines = ctx.skills.map((skill) => {
|
|
6673
|
-
const name = escapeBlockBody(skill.name);
|
|
6674
|
-
const description = escapeBlockBody(skill.description);
|
|
6675
|
-
return ` - ${name}: ${description}`;
|
|
6676
|
-
});
|
|
6677
|
-
return Promise.resolve(`<skills>
|
|
6678
|
-
${lines.join("\n")}
|
|
6679
|
-
</skills>`);
|
|
6684
|
+
return Promise.resolve(buildSkillsBlock(ctx.skills));
|
|
6680
6685
|
}
|
|
6681
6686
|
};
|
|
6682
6687
|
|
|
@@ -7784,7 +7789,7 @@ async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
|
|
|
7784
7789
|
return metadata;
|
|
7785
7790
|
}
|
|
7786
7791
|
|
|
7787
|
-
// src/internal/runtime/skills/skills
|
|
7792
|
+
// src/internal/runtime/skills/discover-skills.ts
|
|
7788
7793
|
init_errors();
|
|
7789
7794
|
|
|
7790
7795
|
// src/internal/runtime/skills/skill-frontmatter.ts
|
|
@@ -7856,6 +7861,61 @@ function hasContent(value) {
|
|
|
7856
7861
|
return value !== void 0 && value.trim().length > 0;
|
|
7857
7862
|
}
|
|
7858
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
|
+
|
|
7859
7919
|
// src/internal/runtime/skills/skills-manager.ts
|
|
7860
7920
|
var SkillsManager = class {
|
|
7861
7921
|
constructor(cwd, _enabled, settingSourcesIncludeProject) {
|
|
@@ -7873,56 +7933,20 @@ var SkillsManager = class {
|
|
|
7873
7933
|
await this.refresh();
|
|
7874
7934
|
}
|
|
7875
7935
|
async refresh() {
|
|
7876
|
-
this.skills = [];
|
|
7877
7936
|
const skillsRoot = path.join(this.cwd, ".theokit", "skills");
|
|
7878
|
-
|
|
7879
|
-
|
|
7880
|
-
|
|
7881
|
-
|
|
7882
|
-
|
|
7883
|
-
|
|
7884
|
-
assertNoSymlinkEscape(skillDir, skillsRoot);
|
|
7885
|
-
} catch {
|
|
7886
|
-
continue;
|
|
7887
|
-
}
|
|
7888
|
-
const skillPath = path.join(skillDir, "SKILL.md");
|
|
7889
|
-
let raw;
|
|
7890
|
-
try {
|
|
7891
|
-
raw = await promises.readFile(skillPath, "utf8");
|
|
7892
|
-
} catch {
|
|
7893
|
-
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
|
+
);
|
|
7894
7943
|
}
|
|
7895
|
-
|
|
7896
|
-
if (metadata !== void 0) this.skills.push(metadata);
|
|
7897
|
-
}
|
|
7944
|
+
});
|
|
7898
7945
|
}
|
|
7899
7946
|
list() {
|
|
7900
7947
|
return Promise.resolve(this.skills);
|
|
7901
7948
|
}
|
|
7902
7949
|
};
|
|
7903
|
-
function tryParseSkill(raw, fallbackName, source) {
|
|
7904
|
-
try {
|
|
7905
|
-
const frontmatter = parseSkillFrontmatter(raw, fallbackName);
|
|
7906
|
-
const metadata = {
|
|
7907
|
-
name: frontmatter.name,
|
|
7908
|
-
description: frontmatter.description,
|
|
7909
|
-
source
|
|
7910
|
-
};
|
|
7911
|
-
if (frontmatter.category !== void 0) metadata.category = frontmatter.category;
|
|
7912
|
-
if (frontmatter.dependencies !== void 0) metadata.dependencies = frontmatter.dependencies;
|
|
7913
|
-
return metadata;
|
|
7914
|
-
} catch (cause) {
|
|
7915
|
-
if (cause instanceof ConfigurationError) {
|
|
7916
|
-
const code = cause.code ?? "unknown";
|
|
7917
|
-
process.stderr.write(
|
|
7918
|
-
`[theokit-sdk] skill ${fallbackName} skipped (${code}): ${cause.message}
|
|
7919
|
-
`
|
|
7920
|
-
);
|
|
7921
|
-
return void 0;
|
|
7922
|
-
}
|
|
7923
|
-
throw cause;
|
|
7924
|
-
}
|
|
7925
|
-
}
|
|
7926
7950
|
|
|
7927
7951
|
// src/internal/runtime/local-agent/local-agent-bootstrap.ts
|
|
7928
7952
|
function registerLocalAgent(args) {
|
|
@@ -8335,6 +8359,7 @@ async function initLoopContext(inputs) {
|
|
|
8335
8359
|
finalStatus: "finished",
|
|
8336
8360
|
usage: new UsageAccumulator(),
|
|
8337
8361
|
nudgeAttempts: 0,
|
|
8362
|
+
stopFeedbackAttempts: 0,
|
|
8338
8363
|
...memoryProviderHandle !== void 0 ? { memoryProviderHandle } : {},
|
|
8339
8364
|
...memorySystemPromptAdditions !== void 0 ? { memorySystemPromptAdditions } : {}
|
|
8340
8365
|
};
|
|
@@ -8479,8 +8504,9 @@ function registerLoopError(ctx, cause) {
|
|
|
8479
8504
|
if (ctx.error !== void 0) return;
|
|
8480
8505
|
const rawMessage = cause?.message;
|
|
8481
8506
|
const message = typeof rawMessage === "string" ? rawMessage : cause instanceof Error ? cause.message : String(cause);
|
|
8507
|
+
const metaCode = cause?.metadata?.code;
|
|
8482
8508
|
const rawCode = cause?.code;
|
|
8483
|
-
const code = typeof rawCode === "string" ? rawCode : void 0;
|
|
8509
|
+
const code = typeof metaCode === "string" ? metaCode : typeof rawCode === "string" ? rawCode : void 0;
|
|
8484
8510
|
ctx.error = code !== void 0 ? { message, code, cause } : { message, cause };
|
|
8485
8511
|
}
|
|
8486
8512
|
async function runCollectorLoop(generator, inputs, ctx) {
|
|
@@ -9276,6 +9302,7 @@ function computeUsageCost(inputs, usage) {
|
|
|
9276
9302
|
|
|
9277
9303
|
// src/internal/agent-loop/loop.ts
|
|
9278
9304
|
var MAX_NUDGE_ATTEMPTS = 2;
|
|
9305
|
+
var MAX_STOP_FEEDBACK_ATTEMPTS = 2;
|
|
9279
9306
|
async function runAgentLoop(inputs) {
|
|
9280
9307
|
const sendSpan = inputs.telemetry?.startSpan("agent.send", {
|
|
9281
9308
|
agentId: inputs.agentId,
|
|
@@ -9433,6 +9460,28 @@ function shouldNudgeAndContinue(ctx, llmOutput) {
|
|
|
9433
9460
|
});
|
|
9434
9461
|
return true;
|
|
9435
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
|
+
}
|
|
9436
9485
|
async function runIteration(inputs, ctx) {
|
|
9437
9486
|
const llmOutput = await streamLlmTurn(inputs, ctx);
|
|
9438
9487
|
accumulateUsage(ctx.usage, llmOutput);
|
|
@@ -9466,9 +9515,7 @@ async function continueOrTerminate(inputs, ctx, llmOutput) {
|
|
|
9466
9515
|
await emitAssistantTextStep(inputs, ctx, llmOutput.text);
|
|
9467
9516
|
}
|
|
9468
9517
|
if (llmOutput.stopReason !== "tool_use" || llmOutput.toolCalls.length === 0) {
|
|
9469
|
-
|
|
9470
|
-
ctx.finalStatus = "finished";
|
|
9471
|
-
return "done";
|
|
9518
|
+
return finishOrReflect(inputs, ctx, llmOutput);
|
|
9472
9519
|
}
|
|
9473
9520
|
ctx.messages.push(buildAssistantTurn(llmOutput.text, llmOutput.toolCalls));
|
|
9474
9521
|
const toolResults = await dispatchTools(inputs, ctx.tools, llmOutput.toolCalls, ctx.events);
|