@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.
Files changed (77) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/dist/a2a/index.cjs +103 -48
  3. package/dist/a2a/index.cjs.map +1 -1
  4. package/dist/a2a/index.js +104 -49
  5. package/dist/a2a/index.js.map +1 -1
  6. package/dist/compaction.cjs +78 -0
  7. package/dist/compaction.cjs.map +1 -0
  8. package/dist/compaction.d.cts +76 -0
  9. package/dist/compaction.d.ts +76 -0
  10. package/dist/compaction.js +70 -0
  11. package/dist/compaction.js.map +1 -0
  12. package/dist/{cron-B_H8rn-j.d.cts → cron-B656C3iq.d.cts} +8 -0
  13. package/dist/{cron-DX6HbHxd.d.ts → cron-CM2M9mhB.d.ts} +8 -0
  14. package/dist/cron.cjs +104 -57
  15. package/dist/cron.cjs.map +1 -1
  16. package/dist/cron.d.cts +1 -1
  17. package/dist/cron.d.ts +1 -1
  18. package/dist/cron.js +104 -57
  19. package/dist/cron.js.map +1 -1
  20. package/dist/eval.cjs +104 -57
  21. package/dist/eval.cjs.map +1 -1
  22. package/dist/eval.js +104 -57
  23. package/dist/eval.js.map +1 -1
  24. package/dist/index.cjs +104 -57
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +2 -2
  27. package/dist/index.d.ts +2 -2
  28. package/dist/index.js +104 -57
  29. package/dist/index.js.map +1 -1
  30. package/dist/internal/agent-loop/loop.d.ts +5 -0
  31. package/dist/internal/llm/model-capabilities.d.ts +40 -0
  32. package/dist/internal/llm/model-identifier.d.ts +9 -1
  33. package/dist/internal/llm/model-option.d.ts +38 -0
  34. package/dist/internal/runtime/compression/compression-attempt.d.ts +24 -0
  35. package/dist/internal/runtime/compression/compression-config.d.ts +33 -0
  36. package/dist/internal/runtime/compression/compression-decision.d.ts +10 -0
  37. package/dist/internal/runtime/compression/compression-helpers.d.ts +18 -0
  38. package/dist/internal/runtime/compression/compression-model-registry.d.ts +41 -0
  39. package/dist/internal/runtime/compression/compression-summarizer.d.ts +29 -0
  40. package/dist/internal/runtime/context/project-instructions.d.ts +66 -0
  41. package/dist/internal/runtime/context/replay-history.d.ts +43 -0
  42. package/dist/internal/runtime/hooks/hooks-frontmatter.d.ts +1 -1
  43. package/dist/internal/runtime/skills/discover-skills.d.ts +68 -0
  44. package/dist/internal/runtime/skills/skills-block.d.ts +18 -0
  45. package/dist/internal/runtime/skills/subagent-tool-scope.d.ts +25 -0
  46. package/dist/messages.cjs +24 -0
  47. package/dist/messages.cjs.map +1 -0
  48. package/dist/messages.d.cts +33 -0
  49. package/dist/messages.d.ts +33 -0
  50. package/dist/messages.js +20 -0
  51. package/dist/messages.js.map +1 -0
  52. package/dist/models.cjs +233 -0
  53. package/dist/models.cjs.map +1 -0
  54. package/dist/models.d.cts +16 -0
  55. package/dist/models.d.ts +16 -0
  56. package/dist/models.js +228 -0
  57. package/dist/models.js.map +1 -0
  58. package/dist/project.cjs +149 -0
  59. package/dist/project.cjs.map +1 -0
  60. package/dist/project.d.cts +14 -0
  61. package/dist/project.d.ts +14 -0
  62. package/dist/project.js +146 -0
  63. package/dist/project.js.map +1 -0
  64. package/dist/skills.cjs +282 -0
  65. package/dist/skills.cjs.map +1 -0
  66. package/dist/skills.d.cts +19 -0
  67. package/dist/skills.d.ts +19 -0
  68. package/dist/skills.js +279 -0
  69. package/dist/skills.js.map +1 -0
  70. package/dist/subagents.cjs +24 -0
  71. package/dist/subagents.cjs.map +1 -0
  72. package/dist/subagents.d.cts +14 -0
  73. package/dist/subagents.d.ts +14 -0
  74. package/dist/subagents.js +21 -0
  75. package/dist/subagents.js.map +1 -0
  76. package/dist/types/agent.d.ts +8 -0
  77. package/package.json +63 -3
package/dist/eval.js CHANGED
@@ -6496,6 +6496,8 @@ function parseSubagentMarkdown(raw, filename) {
6496
6496
  if (fields.model !== void 0) {
6497
6497
  definition.model = fields.model === "inherit" ? "inherit" : { id: fields.model };
6498
6498
  }
6499
+ const tools = fields.tools?.split(/[\s,]+/).map((t) => t.trim()).filter((t) => t.length > 0);
6500
+ if (tools !== void 0 && tools.length > 0) definition.tools = tools;
6499
6501
  return { name, definition };
6500
6502
  }
6501
6503
  function splitFrontmatter2(raw, filename) {
@@ -6659,21 +6661,24 @@ ${lines.join("\n")}
6659
6661
  }
6660
6662
  };
6661
6663
 
6664
+ // src/internal/runtime/skills/skills-block.ts
6665
+ function buildSkillsBlock(skills) {
6666
+ if (skills.length === 0) return void 0;
6667
+ const lines = skills.map(
6668
+ (skill) => ` - ${escapeBlockBody(skill.name)}: ${escapeBlockBody(skill.description)}`
6669
+ );
6670
+ return `<skills>
6671
+ ${lines.join("\n")}
6672
+ </skills>`;
6673
+ }
6674
+
6662
6675
  // src/internal/runtime/system-prompt/sources/skills-provider.ts
6663
6676
  var SkillsPromptProvider = class {
6664
6677
  id = "skills";
6665
6678
  priority = 20;
6666
6679
  contribute(ctx) {
6667
6680
  if (ctx.skillsAutoInject === false) return Promise.resolve(void 0);
6668
- if (ctx.skills.length === 0) return Promise.resolve(void 0);
6669
- const lines = ctx.skills.map((skill) => {
6670
- const name = escapeBlockBody(skill.name);
6671
- const description = escapeBlockBody(skill.description);
6672
- return ` - ${name}: ${description}`;
6673
- });
6674
- return Promise.resolve(`<skills>
6675
- ${lines.join("\n")}
6676
- </skills>`);
6681
+ return Promise.resolve(buildSkillsBlock(ctx.skills));
6677
6682
  }
6678
6683
  };
6679
6684
 
@@ -7781,7 +7786,7 @@ async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
7781
7786
  return metadata;
7782
7787
  }
7783
7788
 
7784
- // src/internal/runtime/skills/skills-manager.ts
7789
+ // src/internal/runtime/skills/discover-skills.ts
7785
7790
  init_errors();
7786
7791
 
7787
7792
  // src/internal/runtime/skills/skill-frontmatter.ts
@@ -7853,6 +7858,61 @@ function hasContent(value) {
7853
7858
  return value !== void 0 && value.trim().length > 0;
7854
7859
  }
7855
7860
 
7861
+ // src/internal/runtime/skills/discover-skills.ts
7862
+ async function discoverSkills(dir, options) {
7863
+ let entries;
7864
+ try {
7865
+ entries = await readWorkspaceDir(dir, "skills_read_error", "skills directory");
7866
+ } catch {
7867
+ return [];
7868
+ }
7869
+ const skills = [];
7870
+ for (const entry of entries) {
7871
+ if (!entry.isDirectory()) continue;
7872
+ let skillDir;
7873
+ try {
7874
+ skillDir = safePathJoin(dir, entry.name);
7875
+ assertNoSymlinkEscape(skillDir, dir);
7876
+ } catch {
7877
+ continue;
7878
+ }
7879
+ const skillPath = join(skillDir, "SKILL.md");
7880
+ let raw;
7881
+ try {
7882
+ raw = await readFile(skillPath, "utf8");
7883
+ } catch {
7884
+ continue;
7885
+ }
7886
+ const skill = tryParseSkill(raw, entry.name, skillPath, options);
7887
+ if (skill !== void 0) skills.push(skill);
7888
+ }
7889
+ return skills;
7890
+ }
7891
+ function tryParseSkill(raw, fallbackName, source, options) {
7892
+ try {
7893
+ const frontmatter = parseSkillFrontmatter(raw, fallbackName);
7894
+ const skill = {
7895
+ name: frontmatter.name,
7896
+ description: frontmatter.description,
7897
+ source
7898
+ };
7899
+ if (frontmatter.category !== void 0) skill.category = frontmatter.category;
7900
+ if (frontmatter.dependencies !== void 0) skill.dependencies = frontmatter.dependencies;
7901
+ return skill;
7902
+ } catch (cause) {
7903
+ if (cause instanceof ConfigurationError) {
7904
+ options?.onInvalidSkill?.({
7905
+ name: fallbackName,
7906
+ source,
7907
+ code: cause.code ?? "unknown",
7908
+ message: cause.message
7909
+ });
7910
+ return void 0;
7911
+ }
7912
+ throw cause;
7913
+ }
7914
+ }
7915
+
7856
7916
  // src/internal/runtime/skills/skills-manager.ts
7857
7917
  var SkillsManager = class {
7858
7918
  constructor(cwd, _enabled, settingSourcesIncludeProject) {
@@ -7870,56 +7930,20 @@ var SkillsManager = class {
7870
7930
  await this.refresh();
7871
7931
  }
7872
7932
  async refresh() {
7873
- this.skills = [];
7874
7933
  const skillsRoot = join(this.cwd, ".theokit", "skills");
7875
- const entries = await readWorkspaceDir(skillsRoot, "skills_read_error", "skills directory");
7876
- for (const entry of entries) {
7877
- if (!entry.isDirectory()) continue;
7878
- let skillDir;
7879
- try {
7880
- skillDir = safePathJoin(skillsRoot, entry.name);
7881
- assertNoSymlinkEscape(skillDir, skillsRoot);
7882
- } catch {
7883
- continue;
7884
- }
7885
- const skillPath = join(skillDir, "SKILL.md");
7886
- let raw;
7887
- try {
7888
- raw = await readFile(skillPath, "utf8");
7889
- } catch {
7890
- continue;
7934
+ this.skills = await discoverSkills(skillsRoot, {
7935
+ onInvalidSkill: (info) => {
7936
+ process.stderr.write(
7937
+ `[theokit-sdk] skill ${info.name} skipped (${info.code}): ${info.message}
7938
+ `
7939
+ );
7891
7940
  }
7892
- const metadata = tryParseSkill(raw, entry.name, skillPath);
7893
- if (metadata !== void 0) this.skills.push(metadata);
7894
- }
7941
+ });
7895
7942
  }
7896
7943
  list() {
7897
7944
  return Promise.resolve(this.skills);
7898
7945
  }
7899
7946
  };
7900
- function tryParseSkill(raw, fallbackName, source) {
7901
- try {
7902
- const frontmatter = parseSkillFrontmatter(raw, fallbackName);
7903
- const metadata = {
7904
- name: frontmatter.name,
7905
- description: frontmatter.description,
7906
- source
7907
- };
7908
- if (frontmatter.category !== void 0) metadata.category = frontmatter.category;
7909
- if (frontmatter.dependencies !== void 0) metadata.dependencies = frontmatter.dependencies;
7910
- return metadata;
7911
- } catch (cause) {
7912
- if (cause instanceof ConfigurationError) {
7913
- const code = cause.code ?? "unknown";
7914
- process.stderr.write(
7915
- `[theokit-sdk] skill ${fallbackName} skipped (${code}): ${cause.message}
7916
- `
7917
- );
7918
- return void 0;
7919
- }
7920
- throw cause;
7921
- }
7922
- }
7923
7947
 
7924
7948
  // src/internal/runtime/local-agent/local-agent-bootstrap.ts
7925
7949
  function registerLocalAgent(args) {
@@ -8332,6 +8356,7 @@ async function initLoopContext(inputs) {
8332
8356
  finalStatus: "finished",
8333
8357
  usage: new UsageAccumulator(),
8334
8358
  nudgeAttempts: 0,
8359
+ stopFeedbackAttempts: 0,
8335
8360
  ...memoryProviderHandle !== void 0 ? { memoryProviderHandle } : {},
8336
8361
  ...memorySystemPromptAdditions !== void 0 ? { memorySystemPromptAdditions } : {}
8337
8362
  };
@@ -8476,8 +8501,9 @@ function registerLoopError(ctx, cause) {
8476
8501
  if (ctx.error !== void 0) return;
8477
8502
  const rawMessage = cause?.message;
8478
8503
  const message = typeof rawMessage === "string" ? rawMessage : cause instanceof Error ? cause.message : String(cause);
8504
+ const metaCode = cause?.metadata?.code;
8479
8505
  const rawCode = cause?.code;
8480
- const code = typeof rawCode === "string" ? rawCode : void 0;
8506
+ const code = typeof metaCode === "string" ? metaCode : typeof rawCode === "string" ? rawCode : void 0;
8481
8507
  ctx.error = code !== void 0 ? { message, code, cause } : { message, cause };
8482
8508
  }
8483
8509
  async function runCollectorLoop(generator, inputs, ctx) {
@@ -9273,6 +9299,7 @@ function computeUsageCost(inputs, usage) {
9273
9299
 
9274
9300
  // src/internal/agent-loop/loop.ts
9275
9301
  var MAX_NUDGE_ATTEMPTS = 2;
9302
+ var MAX_STOP_FEEDBACK_ATTEMPTS = 2;
9276
9303
  async function runAgentLoop(inputs) {
9277
9304
  const sendSpan = inputs.telemetry?.startSpan("agent.send", {
9278
9305
  agentId: inputs.agentId,
@@ -9430,6 +9457,28 @@ function shouldNudgeAndContinue(ctx, llmOutput) {
9430
9457
  });
9431
9458
  return true;
9432
9459
  }
9460
+ async function reflectAfterStop(inputs, ctx) {
9461
+ const result = await inputs.hooks.run({
9462
+ event: "stop",
9463
+ agentId: inputs.agentId,
9464
+ runId: inputs.runId
9465
+ });
9466
+ if (result.blocked) return false;
9467
+ if (ctx.stopFeedbackAttempts >= MAX_STOP_FEEDBACK_ATTEMPTS) return false;
9468
+ const feedback = result.decisions.find(
9469
+ (d) => d.decision === "feedback" && (d.feedback ?? "").length > 0
9470
+ )?.feedback;
9471
+ if (feedback === void 0) return false;
9472
+ ctx.stopFeedbackAttempts += 1;
9473
+ ctx.messages.push({ role: "user", content: [{ type: "text", text: feedback }] });
9474
+ return true;
9475
+ }
9476
+ async function finishOrReflect(inputs, ctx, llmOutput) {
9477
+ if (shouldNudgeAndContinue(ctx, llmOutput)) return "continue";
9478
+ if (await reflectAfterStop(inputs, ctx)) return "continue";
9479
+ ctx.finalStatus = "finished";
9480
+ return "done";
9481
+ }
9433
9482
  async function runIteration(inputs, ctx) {
9434
9483
  const llmOutput = await streamLlmTurn(inputs, ctx);
9435
9484
  accumulateUsage(ctx.usage, llmOutput);
@@ -9463,9 +9512,7 @@ async function continueOrTerminate(inputs, ctx, llmOutput) {
9463
9512
  await emitAssistantTextStep(inputs, ctx, llmOutput.text);
9464
9513
  }
9465
9514
  if (llmOutput.stopReason !== "tool_use" || llmOutput.toolCalls.length === 0) {
9466
- if (shouldNudgeAndContinue(ctx, llmOutput)) return "continue";
9467
- ctx.finalStatus = "finished";
9468
- return "done";
9515
+ return finishOrReflect(inputs, ctx, llmOutput);
9469
9516
  }
9470
9517
  ctx.messages.push(buildAssistantTurn(llmOutput.text, llmOutput.toolCalls));
9471
9518
  const toolResults = await dispatchTools(inputs, ctx.tools, llmOutput.toolCalls, ctx.events);