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