@theokit/sdk 2.3.0 → 2.5.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 (101) hide show
  1. package/CHANGELOG.md +113 -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 +296 -73
  21. package/dist/eval.cjs.map +1 -1
  22. package/dist/eval.d.cts +2 -0
  23. package/dist/eval.d.ts +2 -0
  24. package/dist/eval.js +295 -75
  25. package/dist/eval.js.map +1 -1
  26. package/dist/index.cjs +135 -65
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +42 -7
  29. package/dist/index.d.ts +42 -7
  30. package/dist/index.js +135 -66
  31. package/dist/index.js.map +1 -1
  32. package/dist/internal/agent-loop/loop.d.ts +5 -0
  33. package/dist/internal/eval/code-runner.d.ts +28 -0
  34. package/dist/internal/llm/model-capabilities.d.ts +40 -0
  35. package/dist/internal/llm/model-identifier.d.ts +9 -1
  36. package/dist/internal/llm/model-option.d.ts +38 -0
  37. package/dist/internal/persistence/index.cjs +68 -0
  38. package/dist/internal/persistence/index.cjs.map +1 -1
  39. package/dist/internal/persistence/index.d.cts +1 -0
  40. package/dist/internal/persistence/index.d.ts +1 -0
  41. package/dist/internal/persistence/index.js +65 -1
  42. package/dist/internal/persistence/index.js.map +1 -1
  43. package/dist/internal/persistence/jsonl.d.cts +34 -0
  44. package/dist/internal/persistence/jsonl.d.ts +34 -0
  45. package/dist/internal/runtime/compression/compression-attempt.d.ts +24 -0
  46. package/dist/internal/runtime/compression/compression-config.d.ts +33 -0
  47. package/dist/internal/runtime/compression/compression-decision.d.ts +10 -0
  48. package/dist/internal/runtime/compression/compression-helpers.d.ts +18 -0
  49. package/dist/internal/runtime/compression/compression-model-registry.d.ts +41 -0
  50. package/dist/internal/runtime/compression/compression-summarizer.d.ts +29 -0
  51. package/dist/internal/runtime/context/project-instructions.d.ts +66 -0
  52. package/dist/internal/runtime/context/replay-history.d.ts +43 -0
  53. package/dist/internal/runtime/hooks/hooks-frontmatter.d.ts +1 -1
  54. package/dist/internal/runtime/skills/discover-skills.d.ts +68 -0
  55. package/dist/internal/runtime/skills/skills-block.d.ts +18 -0
  56. package/dist/internal/runtime/skills/subagent-tool-scope.d.ts +25 -0
  57. package/dist/messages.cjs +24 -0
  58. package/dist/messages.cjs.map +1 -0
  59. package/dist/messages.d.cts +33 -0
  60. package/dist/messages.d.ts +33 -0
  61. package/dist/messages.js +20 -0
  62. package/dist/messages.js.map +1 -0
  63. package/dist/models.cjs +233 -0
  64. package/dist/models.cjs.map +1 -0
  65. package/dist/models.d.cts +16 -0
  66. package/dist/models.d.ts +16 -0
  67. package/dist/models.js +228 -0
  68. package/dist/models.js.map +1 -0
  69. package/dist/permission-engine.d.ts +12 -4
  70. package/dist/project.cjs +149 -0
  71. package/dist/project.cjs.map +1 -0
  72. package/dist/project.d.cts +14 -0
  73. package/dist/project.d.ts +14 -0
  74. package/dist/project.js +146 -0
  75. package/dist/project.js.map +1 -0
  76. package/dist/sandbox/index.cjs +71 -1
  77. package/dist/sandbox/index.cjs.map +1 -1
  78. package/dist/sandbox/index.d.cts +1 -0
  79. package/dist/sandbox/index.d.ts +1 -0
  80. package/dist/sandbox/index.js +70 -2
  81. package/dist/sandbox/index.js.map +1 -1
  82. package/dist/sandbox/provision.d.cts +53 -0
  83. package/dist/sandbox/provision.d.ts +53 -0
  84. package/dist/sandbox/shell-escape.d.cts +8 -0
  85. package/dist/sandbox/shell-escape.d.ts +8 -0
  86. package/dist/scorers.d.ts +19 -1
  87. package/dist/skills.cjs +282 -0
  88. package/dist/skills.cjs.map +1 -0
  89. package/dist/skills.d.cts +19 -0
  90. package/dist/skills.d.ts +19 -0
  91. package/dist/skills.js +279 -0
  92. package/dist/skills.js.map +1 -0
  93. package/dist/subagents.cjs +24 -0
  94. package/dist/subagents.cjs.map +1 -0
  95. package/dist/subagents.d.cts +14 -0
  96. package/dist/subagents.d.ts +14 -0
  97. package/dist/subagents.js +21 -0
  98. package/dist/subagents.js.map +1 -0
  99. package/dist/types/agent.d.ts +8 -0
  100. package/dist/types/eval.d.ts +71 -0
  101. package/package.json +74 -14
package/dist/a2a/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { existsSync, realpathSync, lstatSync, readlinkSync, mkdirSync, readFileSync, readdirSync } from 'fs';
1
+ import { existsSync, realpathSync, mkdirSync, lstatSync, readlinkSync, readFileSync, readdirSync } from 'fs';
2
2
  import { randomUUID, createHash, randomBytes } from 'crypto';
3
3
  import { join, dirname, resolve, sep, relative, isAbsolute } from 'path';
4
4
  import { stat, mkdir, readFile, rename, rm, readdir, appendFile, open, unlink, statfs, access } from 'fs/promises';
@@ -4919,6 +4919,8 @@ function parseSubagentMarkdown(raw, filename) {
4919
4919
  if (fields.model !== void 0) {
4920
4920
  definition.model = fields.model === "inherit" ? "inherit" : { id: fields.model };
4921
4921
  }
4922
+ const tools = fields.tools?.split(/[\s,]+/).map((t) => t.trim()).filter((t) => t.length > 0);
4923
+ if (tools !== void 0 && tools.length > 0) definition.tools = tools;
4922
4924
  return { name, definition };
4923
4925
  }
4924
4926
  function splitFrontmatter2(raw, filename) {
@@ -5122,25 +5124,33 @@ ${lines.join("\n")}
5122
5124
  }
5123
5125
  });
5124
5126
 
5127
+ // src/internal/runtime/skills/skills-block.ts
5128
+ function buildSkillsBlock(skills) {
5129
+ if (skills.length === 0) return void 0;
5130
+ const lines = skills.map(
5131
+ (skill) => ` - ${escapeBlockBody(skill.name)}: ${escapeBlockBody(skill.description)}`
5132
+ );
5133
+ return `<skills>
5134
+ ${lines.join("\n")}
5135
+ </skills>`;
5136
+ }
5137
+ var init_skills_block = __esm({
5138
+ "src/internal/runtime/skills/skills-block.ts"() {
5139
+ init_escape();
5140
+ }
5141
+ });
5142
+
5125
5143
  // src/internal/runtime/system-prompt/sources/skills-provider.ts
5126
5144
  var SkillsPromptProvider;
5127
5145
  var init_skills_provider = __esm({
5128
5146
  "src/internal/runtime/system-prompt/sources/skills-provider.ts"() {
5129
- init_escape();
5147
+ init_skills_block();
5130
5148
  SkillsPromptProvider = class {
5131
5149
  id = "skills";
5132
5150
  priority = 20;
5133
5151
  contribute(ctx) {
5134
5152
  if (ctx.skillsAutoInject === false) return Promise.resolve(void 0);
5135
- if (ctx.skills.length === 0) return Promise.resolve(void 0);
5136
- const lines = ctx.skills.map((skill) => {
5137
- const name = escapeBlockBody(skill.name);
5138
- const description = escapeBlockBody(skill.description);
5139
- return ` - ${name}: ${description}`;
5140
- });
5141
- return Promise.resolve(`<skills>
5142
- ${lines.join("\n")}
5143
- </skills>`);
5153
+ return Promise.resolve(buildSkillsBlock(ctx.skills));
5144
5154
  }
5145
5155
  };
5146
5156
  }
@@ -6396,36 +6406,71 @@ var init_skill_frontmatter = __esm({
6396
6406
  init_yaml_frontmatter();
6397
6407
  }
6398
6408
  });
6399
- function tryParseSkill(raw, fallbackName, source) {
6409
+ async function discoverSkills(dir, options) {
6410
+ let entries;
6411
+ try {
6412
+ entries = await readWorkspaceDir(dir, "skills_read_error", "skills directory");
6413
+ } catch {
6414
+ return [];
6415
+ }
6416
+ const skills = [];
6417
+ for (const entry of entries) {
6418
+ if (!entry.isDirectory()) continue;
6419
+ let skillDir;
6420
+ try {
6421
+ skillDir = safePathJoin(dir, entry.name);
6422
+ assertNoSymlinkEscape(skillDir, dir);
6423
+ } catch {
6424
+ continue;
6425
+ }
6426
+ const skillPath = join(skillDir, "SKILL.md");
6427
+ let raw;
6428
+ try {
6429
+ raw = await readFile(skillPath, "utf8");
6430
+ } catch {
6431
+ continue;
6432
+ }
6433
+ const skill = tryParseSkill(raw, entry.name, skillPath, options);
6434
+ if (skill !== void 0) skills.push(skill);
6435
+ }
6436
+ return skills;
6437
+ }
6438
+ function tryParseSkill(raw, fallbackName, source, options) {
6400
6439
  try {
6401
6440
  const frontmatter = parseSkillFrontmatter(raw, fallbackName);
6402
- const metadata = {
6441
+ const skill = {
6403
6442
  name: frontmatter.name,
6404
6443
  description: frontmatter.description,
6405
6444
  source
6406
6445
  };
6407
- if (frontmatter.category !== void 0) metadata.category = frontmatter.category;
6408
- if (frontmatter.dependencies !== void 0) metadata.dependencies = frontmatter.dependencies;
6409
- return metadata;
6446
+ if (frontmatter.category !== void 0) skill.category = frontmatter.category;
6447
+ if (frontmatter.dependencies !== void 0) skill.dependencies = frontmatter.dependencies;
6448
+ return skill;
6410
6449
  } catch (cause) {
6411
6450
  if (cause instanceof ConfigurationError) {
6412
- const code = cause.code ?? "unknown";
6413
- process.stderr.write(
6414
- `[theokit-sdk] skill ${fallbackName} skipped (${code}): ${cause.message}
6415
- `
6416
- );
6451
+ options?.onInvalidSkill?.({
6452
+ name: fallbackName,
6453
+ source,
6454
+ code: cause.code ?? "unknown",
6455
+ message: cause.message
6456
+ });
6417
6457
  return void 0;
6418
6458
  }
6419
6459
  throw cause;
6420
6460
  }
6421
6461
  }
6422
- var SkillsManager;
6423
- var init_skills_manager = __esm({
6424
- "src/internal/runtime/skills/skills-manager.ts"() {
6462
+ var init_discover_skills = __esm({
6463
+ "src/internal/runtime/skills/discover-skills.ts"() {
6425
6464
  init_errors();
6426
6465
  init_path_guard();
6427
6466
  init_workspace_dir();
6428
6467
  init_skill_frontmatter();
6468
+ }
6469
+ });
6470
+ var SkillsManager;
6471
+ var init_skills_manager = __esm({
6472
+ "src/internal/runtime/skills/skills-manager.ts"() {
6473
+ init_discover_skills();
6429
6474
  SkillsManager = class {
6430
6475
  constructor(cwd, _enabled, settingSourcesIncludeProject) {
6431
6476
  this.cwd = cwd;
@@ -6442,28 +6487,15 @@ var init_skills_manager = __esm({
6442
6487
  await this.refresh();
6443
6488
  }
6444
6489
  async refresh() {
6445
- this.skills = [];
6446
6490
  const skillsRoot = join(this.cwd, ".theokit", "skills");
6447
- const entries = await readWorkspaceDir(skillsRoot, "skills_read_error", "skills directory");
6448
- for (const entry of entries) {
6449
- if (!entry.isDirectory()) continue;
6450
- let skillDir;
6451
- try {
6452
- skillDir = safePathJoin(skillsRoot, entry.name);
6453
- assertNoSymlinkEscape(skillDir, skillsRoot);
6454
- } catch {
6455
- continue;
6456
- }
6457
- const skillPath = join(skillDir, "SKILL.md");
6458
- let raw;
6459
- try {
6460
- raw = await readFile(skillPath, "utf8");
6461
- } catch {
6462
- continue;
6491
+ this.skills = await discoverSkills(skillsRoot, {
6492
+ onInvalidSkill: (info) => {
6493
+ process.stderr.write(
6494
+ `[theokit-sdk] skill ${info.name} skipped (${info.code}): ${info.message}
6495
+ `
6496
+ );
6463
6497
  }
6464
- const metadata = tryParseSkill(raw, entry.name, skillPath);
6465
- if (metadata !== void 0) this.skills.push(metadata);
6466
- }
6498
+ });
6467
6499
  }
6468
6500
  list() {
6469
6501
  return Promise.resolve(this.skills);
@@ -6925,6 +6957,7 @@ async function initLoopContext(inputs) {
6925
6957
  finalStatus: "finished",
6926
6958
  usage: new UsageAccumulator(),
6927
6959
  nudgeAttempts: 0,
6960
+ stopFeedbackAttempts: 0,
6928
6961
  ...memoryProviderHandle !== void 0 ? { memoryProviderHandle } : {},
6929
6962
  ...memorySystemPromptAdditions !== void 0 ? { memorySystemPromptAdditions } : {}
6930
6963
  };
@@ -7080,8 +7113,9 @@ function registerLoopError(ctx, cause) {
7080
7113
  if (ctx.error !== void 0) return;
7081
7114
  const rawMessage = cause?.message;
7082
7115
  const message = typeof rawMessage === "string" ? rawMessage : cause instanceof Error ? cause.message : String(cause);
7116
+ const metaCode = cause?.metadata?.code;
7083
7117
  const rawCode = cause?.code;
7084
- const code = typeof rawCode === "string" ? rawCode : void 0;
7118
+ const code = typeof metaCode === "string" ? metaCode : typeof rawCode === "string" ? rawCode : void 0;
7085
7119
  ctx.error = code !== void 0 ? { message, code, cause } : { message, cause };
7086
7120
  }
7087
7121
  async function runCollectorLoop(generator, inputs, ctx) {
@@ -8164,6 +8198,28 @@ function shouldNudgeAndContinue(ctx, llmOutput) {
8164
8198
  });
8165
8199
  return true;
8166
8200
  }
8201
+ async function reflectAfterStop(inputs, ctx) {
8202
+ const result = await inputs.hooks.run({
8203
+ event: "stop",
8204
+ agentId: inputs.agentId,
8205
+ runId: inputs.runId
8206
+ });
8207
+ if (result.blocked) return false;
8208
+ if (ctx.stopFeedbackAttempts >= MAX_STOP_FEEDBACK_ATTEMPTS) return false;
8209
+ const feedback = result.decisions.find(
8210
+ (d) => d.decision === "feedback" && (d.feedback ?? "").length > 0
8211
+ )?.feedback;
8212
+ if (feedback === void 0) return false;
8213
+ ctx.stopFeedbackAttempts += 1;
8214
+ ctx.messages.push({ role: "user", content: [{ type: "text", text: feedback }] });
8215
+ return true;
8216
+ }
8217
+ async function finishOrReflect(inputs, ctx, llmOutput) {
8218
+ if (shouldNudgeAndContinue(ctx, llmOutput)) return "continue";
8219
+ if (await reflectAfterStop(inputs, ctx)) return "continue";
8220
+ ctx.finalStatus = "finished";
8221
+ return "done";
8222
+ }
8167
8223
  async function runIteration(inputs, ctx) {
8168
8224
  const llmOutput = await streamLlmTurn(inputs, ctx);
8169
8225
  accumulateUsage(ctx.usage, llmOutput);
@@ -8197,9 +8253,7 @@ async function continueOrTerminate(inputs, ctx, llmOutput) {
8197
8253
  await emitAssistantTextStep(inputs, ctx, llmOutput.text);
8198
8254
  }
8199
8255
  if (llmOutput.stopReason !== "tool_use" || llmOutput.toolCalls.length === 0) {
8200
- if (shouldNudgeAndContinue(ctx, llmOutput)) return "continue";
8201
- ctx.finalStatus = "finished";
8202
- return "done";
8256
+ return finishOrReflect(inputs, ctx, llmOutput);
8203
8257
  }
8204
8258
  ctx.messages.push(buildAssistantTurn(llmOutput.text, llmOutput.toolCalls));
8205
8259
  const toolResults = await dispatchTools(inputs, ctx.tools, llmOutput.toolCalls, ctx.events);
@@ -8222,7 +8276,7 @@ async function continueOrTerminate(inputs, ctx, llmOutput) {
8222
8276
  pushToolConversationSteps(ctx, llmOutput.toolCalls, toolResults);
8223
8277
  return handleToolErrorContinuation(inputs, ctx, toolResults);
8224
8278
  }
8225
- var MAX_NUDGE_ATTEMPTS;
8279
+ var MAX_NUDGE_ATTEMPTS, MAX_STOP_FEEDBACK_ATTEMPTS;
8226
8280
  var init_loop = __esm({
8227
8281
  "src/internal/agent-loop/loop.ts"() {
8228
8282
  init_budget();
@@ -8235,6 +8289,7 @@ var init_loop = __esm({
8235
8289
  init_tool_dispatch();
8236
8290
  init_usage_and_cost();
8237
8291
  MAX_NUDGE_ATTEMPTS = 2;
8292
+ MAX_STOP_FEEDBACK_ATTEMPTS = 2;
8238
8293
  }
8239
8294
  });
8240
8295