@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/cron.cjs
CHANGED
|
@@ -6504,6 +6504,8 @@ function parseSubagentMarkdown(raw, filename) {
|
|
|
6504
6504
|
if (fields.model !== void 0) {
|
|
6505
6505
|
definition.model = fields.model === "inherit" ? "inherit" : { id: fields.model };
|
|
6506
6506
|
}
|
|
6507
|
+
const tools = fields.tools?.split(/[\s,]+/).map((t) => t.trim()).filter((t) => t.length > 0);
|
|
6508
|
+
if (tools !== void 0 && tools.length > 0) definition.tools = tools;
|
|
6507
6509
|
return { name, definition };
|
|
6508
6510
|
}
|
|
6509
6511
|
function splitFrontmatter2(raw, filename) {
|
|
@@ -6667,21 +6669,24 @@ ${lines.join("\n")}
|
|
|
6667
6669
|
}
|
|
6668
6670
|
};
|
|
6669
6671
|
|
|
6672
|
+
// src/internal/runtime/skills/skills-block.ts
|
|
6673
|
+
function buildSkillsBlock(skills) {
|
|
6674
|
+
if (skills.length === 0) return void 0;
|
|
6675
|
+
const lines = skills.map(
|
|
6676
|
+
(skill) => ` - ${escapeBlockBody(skill.name)}: ${escapeBlockBody(skill.description)}`
|
|
6677
|
+
);
|
|
6678
|
+
return `<skills>
|
|
6679
|
+
${lines.join("\n")}
|
|
6680
|
+
</skills>`;
|
|
6681
|
+
}
|
|
6682
|
+
|
|
6670
6683
|
// src/internal/runtime/system-prompt/sources/skills-provider.ts
|
|
6671
6684
|
var SkillsPromptProvider = class {
|
|
6672
6685
|
id = "skills";
|
|
6673
6686
|
priority = 20;
|
|
6674
6687
|
contribute(ctx) {
|
|
6675
6688
|
if (ctx.skillsAutoInject === false) return Promise.resolve(void 0);
|
|
6676
|
-
|
|
6677
|
-
const lines = ctx.skills.map((skill) => {
|
|
6678
|
-
const name = escapeBlockBody(skill.name);
|
|
6679
|
-
const description = escapeBlockBody(skill.description);
|
|
6680
|
-
return ` - ${name}: ${description}`;
|
|
6681
|
-
});
|
|
6682
|
-
return Promise.resolve(`<skills>
|
|
6683
|
-
${lines.join("\n")}
|
|
6684
|
-
</skills>`);
|
|
6689
|
+
return Promise.resolve(buildSkillsBlock(ctx.skills));
|
|
6685
6690
|
}
|
|
6686
6691
|
};
|
|
6687
6692
|
|
|
@@ -7789,7 +7794,7 @@ async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
|
|
|
7789
7794
|
return metadata;
|
|
7790
7795
|
}
|
|
7791
7796
|
|
|
7792
|
-
// src/internal/runtime/skills/skills
|
|
7797
|
+
// src/internal/runtime/skills/discover-skills.ts
|
|
7793
7798
|
init_errors();
|
|
7794
7799
|
|
|
7795
7800
|
// src/internal/runtime/skills/skill-frontmatter.ts
|
|
@@ -7861,6 +7866,61 @@ function hasContent(value) {
|
|
|
7861
7866
|
return value !== void 0 && value.trim().length > 0;
|
|
7862
7867
|
}
|
|
7863
7868
|
|
|
7869
|
+
// src/internal/runtime/skills/discover-skills.ts
|
|
7870
|
+
async function discoverSkills(dir, options) {
|
|
7871
|
+
let entries;
|
|
7872
|
+
try {
|
|
7873
|
+
entries = await readWorkspaceDir(dir, "skills_read_error", "skills directory");
|
|
7874
|
+
} catch {
|
|
7875
|
+
return [];
|
|
7876
|
+
}
|
|
7877
|
+
const skills = [];
|
|
7878
|
+
for (const entry of entries) {
|
|
7879
|
+
if (!entry.isDirectory()) continue;
|
|
7880
|
+
let skillDir;
|
|
7881
|
+
try {
|
|
7882
|
+
skillDir = safePathJoin(dir, entry.name);
|
|
7883
|
+
assertNoSymlinkEscape(skillDir, dir);
|
|
7884
|
+
} catch {
|
|
7885
|
+
continue;
|
|
7886
|
+
}
|
|
7887
|
+
const skillPath = path.join(skillDir, "SKILL.md");
|
|
7888
|
+
let raw;
|
|
7889
|
+
try {
|
|
7890
|
+
raw = await promises.readFile(skillPath, "utf8");
|
|
7891
|
+
} catch {
|
|
7892
|
+
continue;
|
|
7893
|
+
}
|
|
7894
|
+
const skill = tryParseSkill(raw, entry.name, skillPath, options);
|
|
7895
|
+
if (skill !== void 0) skills.push(skill);
|
|
7896
|
+
}
|
|
7897
|
+
return skills;
|
|
7898
|
+
}
|
|
7899
|
+
function tryParseSkill(raw, fallbackName, source, options) {
|
|
7900
|
+
try {
|
|
7901
|
+
const frontmatter = parseSkillFrontmatter(raw, fallbackName);
|
|
7902
|
+
const skill = {
|
|
7903
|
+
name: frontmatter.name,
|
|
7904
|
+
description: frontmatter.description,
|
|
7905
|
+
source
|
|
7906
|
+
};
|
|
7907
|
+
if (frontmatter.category !== void 0) skill.category = frontmatter.category;
|
|
7908
|
+
if (frontmatter.dependencies !== void 0) skill.dependencies = frontmatter.dependencies;
|
|
7909
|
+
return skill;
|
|
7910
|
+
} catch (cause) {
|
|
7911
|
+
if (cause instanceof ConfigurationError) {
|
|
7912
|
+
options?.onInvalidSkill?.({
|
|
7913
|
+
name: fallbackName,
|
|
7914
|
+
source,
|
|
7915
|
+
code: cause.code ?? "unknown",
|
|
7916
|
+
message: cause.message
|
|
7917
|
+
});
|
|
7918
|
+
return void 0;
|
|
7919
|
+
}
|
|
7920
|
+
throw cause;
|
|
7921
|
+
}
|
|
7922
|
+
}
|
|
7923
|
+
|
|
7864
7924
|
// src/internal/runtime/skills/skills-manager.ts
|
|
7865
7925
|
var SkillsManager = class {
|
|
7866
7926
|
constructor(cwd, _enabled, settingSourcesIncludeProject) {
|
|
@@ -7878,56 +7938,20 @@ var SkillsManager = class {
|
|
|
7878
7938
|
await this.refresh();
|
|
7879
7939
|
}
|
|
7880
7940
|
async refresh() {
|
|
7881
|
-
this.skills = [];
|
|
7882
7941
|
const skillsRoot = path.join(this.cwd, ".theokit", "skills");
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
assertNoSymlinkEscape(skillDir, skillsRoot);
|
|
7890
|
-
} catch {
|
|
7891
|
-
continue;
|
|
7892
|
-
}
|
|
7893
|
-
const skillPath = path.join(skillDir, "SKILL.md");
|
|
7894
|
-
let raw;
|
|
7895
|
-
try {
|
|
7896
|
-
raw = await promises.readFile(skillPath, "utf8");
|
|
7897
|
-
} catch {
|
|
7898
|
-
continue;
|
|
7942
|
+
this.skills = await discoverSkills(skillsRoot, {
|
|
7943
|
+
onInvalidSkill: (info) => {
|
|
7944
|
+
process.stderr.write(
|
|
7945
|
+
`[theokit-sdk] skill ${info.name} skipped (${info.code}): ${info.message}
|
|
7946
|
+
`
|
|
7947
|
+
);
|
|
7899
7948
|
}
|
|
7900
|
-
|
|
7901
|
-
if (metadata !== void 0) this.skills.push(metadata);
|
|
7902
|
-
}
|
|
7949
|
+
});
|
|
7903
7950
|
}
|
|
7904
7951
|
list() {
|
|
7905
7952
|
return Promise.resolve(this.skills);
|
|
7906
7953
|
}
|
|
7907
7954
|
};
|
|
7908
|
-
function tryParseSkill(raw, fallbackName, source) {
|
|
7909
|
-
try {
|
|
7910
|
-
const frontmatter = parseSkillFrontmatter(raw, fallbackName);
|
|
7911
|
-
const metadata = {
|
|
7912
|
-
name: frontmatter.name,
|
|
7913
|
-
description: frontmatter.description,
|
|
7914
|
-
source
|
|
7915
|
-
};
|
|
7916
|
-
if (frontmatter.category !== void 0) metadata.category = frontmatter.category;
|
|
7917
|
-
if (frontmatter.dependencies !== void 0) metadata.dependencies = frontmatter.dependencies;
|
|
7918
|
-
return metadata;
|
|
7919
|
-
} catch (cause) {
|
|
7920
|
-
if (cause instanceof ConfigurationError) {
|
|
7921
|
-
const code = cause.code ?? "unknown";
|
|
7922
|
-
process.stderr.write(
|
|
7923
|
-
`[theokit-sdk] skill ${fallbackName} skipped (${code}): ${cause.message}
|
|
7924
|
-
`
|
|
7925
|
-
);
|
|
7926
|
-
return void 0;
|
|
7927
|
-
}
|
|
7928
|
-
throw cause;
|
|
7929
|
-
}
|
|
7930
|
-
}
|
|
7931
7955
|
|
|
7932
7956
|
// src/internal/runtime/local-agent/local-agent-bootstrap.ts
|
|
7933
7957
|
function registerLocalAgent(args) {
|
|
@@ -8340,6 +8364,7 @@ async function initLoopContext(inputs) {
|
|
|
8340
8364
|
finalStatus: "finished",
|
|
8341
8365
|
usage: new UsageAccumulator(),
|
|
8342
8366
|
nudgeAttempts: 0,
|
|
8367
|
+
stopFeedbackAttempts: 0,
|
|
8343
8368
|
...memoryProviderHandle !== void 0 ? { memoryProviderHandle } : {},
|
|
8344
8369
|
...memorySystemPromptAdditions !== void 0 ? { memorySystemPromptAdditions } : {}
|
|
8345
8370
|
};
|
|
@@ -8484,8 +8509,9 @@ function registerLoopError(ctx, cause) {
|
|
|
8484
8509
|
if (ctx.error !== void 0) return;
|
|
8485
8510
|
const rawMessage = cause?.message;
|
|
8486
8511
|
const message = typeof rawMessage === "string" ? rawMessage : cause instanceof Error ? cause.message : String(cause);
|
|
8512
|
+
const metaCode = cause?.metadata?.code;
|
|
8487
8513
|
const rawCode = cause?.code;
|
|
8488
|
-
const code = typeof rawCode === "string" ? rawCode : void 0;
|
|
8514
|
+
const code = typeof metaCode === "string" ? metaCode : typeof rawCode === "string" ? rawCode : void 0;
|
|
8489
8515
|
ctx.error = code !== void 0 ? { message, code, cause } : { message, cause };
|
|
8490
8516
|
}
|
|
8491
8517
|
async function runCollectorLoop(generator, inputs, ctx) {
|
|
@@ -9281,6 +9307,7 @@ function computeUsageCost(inputs, usage) {
|
|
|
9281
9307
|
|
|
9282
9308
|
// src/internal/agent-loop/loop.ts
|
|
9283
9309
|
var MAX_NUDGE_ATTEMPTS = 2;
|
|
9310
|
+
var MAX_STOP_FEEDBACK_ATTEMPTS = 2;
|
|
9284
9311
|
async function runAgentLoop(inputs) {
|
|
9285
9312
|
const sendSpan = inputs.telemetry?.startSpan("agent.send", {
|
|
9286
9313
|
agentId: inputs.agentId,
|
|
@@ -9438,6 +9465,28 @@ function shouldNudgeAndContinue(ctx, llmOutput) {
|
|
|
9438
9465
|
});
|
|
9439
9466
|
return true;
|
|
9440
9467
|
}
|
|
9468
|
+
async function reflectAfterStop(inputs, ctx) {
|
|
9469
|
+
const result = await inputs.hooks.run({
|
|
9470
|
+
event: "stop",
|
|
9471
|
+
agentId: inputs.agentId,
|
|
9472
|
+
runId: inputs.runId
|
|
9473
|
+
});
|
|
9474
|
+
if (result.blocked) return false;
|
|
9475
|
+
if (ctx.stopFeedbackAttempts >= MAX_STOP_FEEDBACK_ATTEMPTS) return false;
|
|
9476
|
+
const feedback = result.decisions.find(
|
|
9477
|
+
(d) => d.decision === "feedback" && (d.feedback ?? "").length > 0
|
|
9478
|
+
)?.feedback;
|
|
9479
|
+
if (feedback === void 0) return false;
|
|
9480
|
+
ctx.stopFeedbackAttempts += 1;
|
|
9481
|
+
ctx.messages.push({ role: "user", content: [{ type: "text", text: feedback }] });
|
|
9482
|
+
return true;
|
|
9483
|
+
}
|
|
9484
|
+
async function finishOrReflect(inputs, ctx, llmOutput) {
|
|
9485
|
+
if (shouldNudgeAndContinue(ctx, llmOutput)) return "continue";
|
|
9486
|
+
if (await reflectAfterStop(inputs, ctx)) return "continue";
|
|
9487
|
+
ctx.finalStatus = "finished";
|
|
9488
|
+
return "done";
|
|
9489
|
+
}
|
|
9441
9490
|
async function runIteration(inputs, ctx) {
|
|
9442
9491
|
const llmOutput = await streamLlmTurn(inputs, ctx);
|
|
9443
9492
|
accumulateUsage(ctx.usage, llmOutput);
|
|
@@ -9471,9 +9520,7 @@ async function continueOrTerminate(inputs, ctx, llmOutput) {
|
|
|
9471
9520
|
await emitAssistantTextStep(inputs, ctx, llmOutput.text);
|
|
9472
9521
|
}
|
|
9473
9522
|
if (llmOutput.stopReason !== "tool_use" || llmOutput.toolCalls.length === 0) {
|
|
9474
|
-
|
|
9475
|
-
ctx.finalStatus = "finished";
|
|
9476
|
-
return "done";
|
|
9523
|
+
return finishOrReflect(inputs, ctx, llmOutput);
|
|
9477
9524
|
}
|
|
9478
9525
|
ctx.messages.push(buildAssistantTurn(llmOutput.text, llmOutput.toolCalls));
|
|
9479
9526
|
const toolResults = await dispatchTools(inputs, ctx.tools, llmOutput.toolCalls, ctx.events);
|