@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/index.cjs
CHANGED
|
@@ -8959,6 +8959,8 @@ function parseSubagentMarkdown(raw, filename) {
|
|
|
8959
8959
|
if (fields.model !== void 0) {
|
|
8960
8960
|
definition.model = fields.model === "inherit" ? "inherit" : { id: fields.model };
|
|
8961
8961
|
}
|
|
8962
|
+
const tools = fields.tools?.split(/[\s,]+/).map((t) => t.trim()).filter((t) => t.length > 0);
|
|
8963
|
+
if (tools !== void 0 && tools.length > 0) definition.tools = tools;
|
|
8962
8964
|
return { name, definition };
|
|
8963
8965
|
}
|
|
8964
8966
|
function splitFrontmatter2(raw, filename) {
|
|
@@ -9122,21 +9124,24 @@ ${lines.join("\n")}
|
|
|
9122
9124
|
}
|
|
9123
9125
|
};
|
|
9124
9126
|
|
|
9127
|
+
// src/internal/runtime/skills/skills-block.ts
|
|
9128
|
+
function buildSkillsBlock(skills) {
|
|
9129
|
+
if (skills.length === 0) return void 0;
|
|
9130
|
+
const lines = skills.map(
|
|
9131
|
+
(skill) => ` - ${escapeBlockBody(skill.name)}: ${escapeBlockBody(skill.description)}`
|
|
9132
|
+
);
|
|
9133
|
+
return `<skills>
|
|
9134
|
+
${lines.join("\n")}
|
|
9135
|
+
</skills>`;
|
|
9136
|
+
}
|
|
9137
|
+
|
|
9125
9138
|
// src/internal/runtime/system-prompt/sources/skills-provider.ts
|
|
9126
9139
|
var SkillsPromptProvider = class {
|
|
9127
9140
|
id = "skills";
|
|
9128
9141
|
priority = 20;
|
|
9129
9142
|
contribute(ctx) {
|
|
9130
9143
|
if (ctx.skillsAutoInject === false) return Promise.resolve(void 0);
|
|
9131
|
-
|
|
9132
|
-
const lines = ctx.skills.map((skill) => {
|
|
9133
|
-
const name = escapeBlockBody(skill.name);
|
|
9134
|
-
const description = escapeBlockBody(skill.description);
|
|
9135
|
-
return ` - ${name}: ${description}`;
|
|
9136
|
-
});
|
|
9137
|
-
return Promise.resolve(`<skills>
|
|
9138
|
-
${lines.join("\n")}
|
|
9139
|
-
</skills>`);
|
|
9144
|
+
return Promise.resolve(buildSkillsBlock(ctx.skills));
|
|
9140
9145
|
}
|
|
9141
9146
|
};
|
|
9142
9147
|
|
|
@@ -10245,7 +10250,7 @@ async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
|
|
|
10245
10250
|
return metadata;
|
|
10246
10251
|
}
|
|
10247
10252
|
|
|
10248
|
-
// src/internal/runtime/skills/skills
|
|
10253
|
+
// src/internal/runtime/skills/discover-skills.ts
|
|
10249
10254
|
init_errors();
|
|
10250
10255
|
init_path_guard();
|
|
10251
10256
|
|
|
@@ -10318,6 +10323,61 @@ function hasContent(value) {
|
|
|
10318
10323
|
return value !== void 0 && value.trim().length > 0;
|
|
10319
10324
|
}
|
|
10320
10325
|
|
|
10326
|
+
// src/internal/runtime/skills/discover-skills.ts
|
|
10327
|
+
async function discoverSkills(dir, options) {
|
|
10328
|
+
let entries;
|
|
10329
|
+
try {
|
|
10330
|
+
entries = await readWorkspaceDir(dir, "skills_read_error", "skills directory");
|
|
10331
|
+
} catch {
|
|
10332
|
+
return [];
|
|
10333
|
+
}
|
|
10334
|
+
const skills = [];
|
|
10335
|
+
for (const entry of entries) {
|
|
10336
|
+
if (!entry.isDirectory()) continue;
|
|
10337
|
+
let skillDir;
|
|
10338
|
+
try {
|
|
10339
|
+
skillDir = safePathJoin(dir, entry.name);
|
|
10340
|
+
assertNoSymlinkEscape(skillDir, dir);
|
|
10341
|
+
} catch {
|
|
10342
|
+
continue;
|
|
10343
|
+
}
|
|
10344
|
+
const skillPath = path.join(skillDir, "SKILL.md");
|
|
10345
|
+
let raw;
|
|
10346
|
+
try {
|
|
10347
|
+
raw = await promises.readFile(skillPath, "utf8");
|
|
10348
|
+
} catch {
|
|
10349
|
+
continue;
|
|
10350
|
+
}
|
|
10351
|
+
const skill = tryParseSkill(raw, entry.name, skillPath, options);
|
|
10352
|
+
if (skill !== void 0) skills.push(skill);
|
|
10353
|
+
}
|
|
10354
|
+
return skills;
|
|
10355
|
+
}
|
|
10356
|
+
function tryParseSkill(raw, fallbackName, source, options) {
|
|
10357
|
+
try {
|
|
10358
|
+
const frontmatter = parseSkillFrontmatter(raw, fallbackName);
|
|
10359
|
+
const skill = {
|
|
10360
|
+
name: frontmatter.name,
|
|
10361
|
+
description: frontmatter.description,
|
|
10362
|
+
source
|
|
10363
|
+
};
|
|
10364
|
+
if (frontmatter.category !== void 0) skill.category = frontmatter.category;
|
|
10365
|
+
if (frontmatter.dependencies !== void 0) skill.dependencies = frontmatter.dependencies;
|
|
10366
|
+
return skill;
|
|
10367
|
+
} catch (cause) {
|
|
10368
|
+
if (cause instanceof exports.ConfigurationError) {
|
|
10369
|
+
options?.onInvalidSkill?.({
|
|
10370
|
+
name: fallbackName,
|
|
10371
|
+
source,
|
|
10372
|
+
code: cause.code ?? "unknown",
|
|
10373
|
+
message: cause.message
|
|
10374
|
+
});
|
|
10375
|
+
return void 0;
|
|
10376
|
+
}
|
|
10377
|
+
throw cause;
|
|
10378
|
+
}
|
|
10379
|
+
}
|
|
10380
|
+
|
|
10321
10381
|
// src/internal/runtime/skills/skills-manager.ts
|
|
10322
10382
|
var SkillsManager = class {
|
|
10323
10383
|
constructor(cwd, _enabled, settingSourcesIncludeProject) {
|
|
@@ -10335,56 +10395,20 @@ var SkillsManager = class {
|
|
|
10335
10395
|
await this.refresh();
|
|
10336
10396
|
}
|
|
10337
10397
|
async refresh() {
|
|
10338
|
-
this.skills = [];
|
|
10339
10398
|
const skillsRoot = path.join(this.cwd, ".theokit", "skills");
|
|
10340
|
-
|
|
10341
|
-
|
|
10342
|
-
|
|
10343
|
-
|
|
10344
|
-
|
|
10345
|
-
|
|
10346
|
-
assertNoSymlinkEscape(skillDir, skillsRoot);
|
|
10347
|
-
} catch {
|
|
10348
|
-
continue;
|
|
10349
|
-
}
|
|
10350
|
-
const skillPath = path.join(skillDir, "SKILL.md");
|
|
10351
|
-
let raw;
|
|
10352
|
-
try {
|
|
10353
|
-
raw = await promises.readFile(skillPath, "utf8");
|
|
10354
|
-
} catch {
|
|
10355
|
-
continue;
|
|
10399
|
+
this.skills = await discoverSkills(skillsRoot, {
|
|
10400
|
+
onInvalidSkill: (info) => {
|
|
10401
|
+
process.stderr.write(
|
|
10402
|
+
`[theokit-sdk] skill ${info.name} skipped (${info.code}): ${info.message}
|
|
10403
|
+
`
|
|
10404
|
+
);
|
|
10356
10405
|
}
|
|
10357
|
-
|
|
10358
|
-
if (metadata !== void 0) this.skills.push(metadata);
|
|
10359
|
-
}
|
|
10406
|
+
});
|
|
10360
10407
|
}
|
|
10361
10408
|
list() {
|
|
10362
10409
|
return Promise.resolve(this.skills);
|
|
10363
10410
|
}
|
|
10364
10411
|
};
|
|
10365
|
-
function tryParseSkill(raw, fallbackName, source) {
|
|
10366
|
-
try {
|
|
10367
|
-
const frontmatter = parseSkillFrontmatter(raw, fallbackName);
|
|
10368
|
-
const metadata = {
|
|
10369
|
-
name: frontmatter.name,
|
|
10370
|
-
description: frontmatter.description,
|
|
10371
|
-
source
|
|
10372
|
-
};
|
|
10373
|
-
if (frontmatter.category !== void 0) metadata.category = frontmatter.category;
|
|
10374
|
-
if (frontmatter.dependencies !== void 0) metadata.dependencies = frontmatter.dependencies;
|
|
10375
|
-
return metadata;
|
|
10376
|
-
} catch (cause) {
|
|
10377
|
-
if (cause instanceof exports.ConfigurationError) {
|
|
10378
|
-
const code = cause.code ?? "unknown";
|
|
10379
|
-
process.stderr.write(
|
|
10380
|
-
`[theokit-sdk] skill ${fallbackName} skipped (${code}): ${cause.message}
|
|
10381
|
-
`
|
|
10382
|
-
);
|
|
10383
|
-
return void 0;
|
|
10384
|
-
}
|
|
10385
|
-
throw cause;
|
|
10386
|
-
}
|
|
10387
|
-
}
|
|
10388
10412
|
|
|
10389
10413
|
// src/internal/runtime/local-agent/local-agent-bootstrap.ts
|
|
10390
10414
|
function registerLocalAgent(args) {
|
|
@@ -10797,6 +10821,7 @@ async function initLoopContext(inputs) {
|
|
|
10797
10821
|
finalStatus: "finished",
|
|
10798
10822
|
usage: new UsageAccumulator(),
|
|
10799
10823
|
nudgeAttempts: 0,
|
|
10824
|
+
stopFeedbackAttempts: 0,
|
|
10800
10825
|
...memoryProviderHandle !== void 0 ? { memoryProviderHandle } : {},
|
|
10801
10826
|
...memorySystemPromptAdditions !== void 0 ? { memorySystemPromptAdditions } : {}
|
|
10802
10827
|
};
|
|
@@ -10941,8 +10966,9 @@ function registerLoopError(ctx, cause) {
|
|
|
10941
10966
|
if (ctx.error !== void 0) return;
|
|
10942
10967
|
const rawMessage = cause?.message;
|
|
10943
10968
|
const message = typeof rawMessage === "string" ? rawMessage : cause instanceof Error ? cause.message : String(cause);
|
|
10969
|
+
const metaCode = cause?.metadata?.code;
|
|
10944
10970
|
const rawCode = cause?.code;
|
|
10945
|
-
const code = typeof rawCode === "string" ? rawCode : void 0;
|
|
10971
|
+
const code = typeof metaCode === "string" ? metaCode : typeof rawCode === "string" ? rawCode : void 0;
|
|
10946
10972
|
ctx.error = code !== void 0 ? { message, code, cause } : { message, cause };
|
|
10947
10973
|
}
|
|
10948
10974
|
async function runCollectorLoop(generator, inputs, ctx) {
|
|
@@ -11738,6 +11764,7 @@ function computeUsageCost(inputs, usage) {
|
|
|
11738
11764
|
|
|
11739
11765
|
// src/internal/agent-loop/loop.ts
|
|
11740
11766
|
var MAX_NUDGE_ATTEMPTS = 2;
|
|
11767
|
+
var MAX_STOP_FEEDBACK_ATTEMPTS = 2;
|
|
11741
11768
|
async function runAgentLoop(inputs) {
|
|
11742
11769
|
const sendSpan = inputs.telemetry?.startSpan("agent.send", {
|
|
11743
11770
|
agentId: inputs.agentId,
|
|
@@ -11895,6 +11922,28 @@ function shouldNudgeAndContinue(ctx, llmOutput) {
|
|
|
11895
11922
|
});
|
|
11896
11923
|
return true;
|
|
11897
11924
|
}
|
|
11925
|
+
async function reflectAfterStop(inputs, ctx) {
|
|
11926
|
+
const result = await inputs.hooks.run({
|
|
11927
|
+
event: "stop",
|
|
11928
|
+
agentId: inputs.agentId,
|
|
11929
|
+
runId: inputs.runId
|
|
11930
|
+
});
|
|
11931
|
+
if (result.blocked) return false;
|
|
11932
|
+
if (ctx.stopFeedbackAttempts >= MAX_STOP_FEEDBACK_ATTEMPTS) return false;
|
|
11933
|
+
const feedback = result.decisions.find(
|
|
11934
|
+
(d) => d.decision === "feedback" && (d.feedback ?? "").length > 0
|
|
11935
|
+
)?.feedback;
|
|
11936
|
+
if (feedback === void 0) return false;
|
|
11937
|
+
ctx.stopFeedbackAttempts += 1;
|
|
11938
|
+
ctx.messages.push({ role: "user", content: [{ type: "text", text: feedback }] });
|
|
11939
|
+
return true;
|
|
11940
|
+
}
|
|
11941
|
+
async function finishOrReflect(inputs, ctx, llmOutput) {
|
|
11942
|
+
if (shouldNudgeAndContinue(ctx, llmOutput)) return "continue";
|
|
11943
|
+
if (await reflectAfterStop(inputs, ctx)) return "continue";
|
|
11944
|
+
ctx.finalStatus = "finished";
|
|
11945
|
+
return "done";
|
|
11946
|
+
}
|
|
11898
11947
|
async function runIteration(inputs, ctx) {
|
|
11899
11948
|
const llmOutput = await streamLlmTurn(inputs, ctx);
|
|
11900
11949
|
accumulateUsage(ctx.usage, llmOutput);
|
|
@@ -11928,9 +11977,7 @@ async function continueOrTerminate(inputs, ctx, llmOutput) {
|
|
|
11928
11977
|
await emitAssistantTextStep(inputs, ctx, llmOutput.text);
|
|
11929
11978
|
}
|
|
11930
11979
|
if (llmOutput.stopReason !== "tool_use" || llmOutput.toolCalls.length === 0) {
|
|
11931
|
-
|
|
11932
|
-
ctx.finalStatus = "finished";
|
|
11933
|
-
return "done";
|
|
11980
|
+
return finishOrReflect(inputs, ctx, llmOutput);
|
|
11934
11981
|
}
|
|
11935
11982
|
ctx.messages.push(buildAssistantTurn(llmOutput.text, llmOutput.toolCalls));
|
|
11936
11983
|
const toolResults = await dispatchTools(inputs, ctx.tools, llmOutput.toolCalls, ctx.events);
|