@theokit/sdk 2.18.1 → 2.20.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 +14 -0
- package/dist/a2a/index.cjs +83 -15
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +83 -15
- package/dist/a2a/index.js.map +1 -1
- package/dist/create-skill.d.ts +29 -0
- package/dist/{cron-Bbg0mBOv.d.ts → cron-B8fqui49.d.cts} +59 -2
- package/dist/{cron-ZLSKbDbB.d.cts → cron-D2yLOrk2.d.ts} +59 -2
- package/dist/cron.cjs +83 -15
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.d.cts +2 -2
- package/dist/cron.d.ts +2 -2
- package/dist/cron.js +83 -15
- package/dist/cron.js.map +1 -1
- package/dist/define-tool.d.ts +1 -0
- package/dist/{errors-qyVYfk9H.d.ts → errors-5lj1EWgs.d.ts} +1 -1
- package/dist/{errors-1tVcX3Fq.d.cts → errors-CE-lMBi2.d.cts} +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/eval.cjs +83 -15
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +83 -15
- package/dist/eval.js.map +1 -1
- package/dist/generate-object.d.ts +27 -2
- package/dist/index.cjs +146 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -7
- package/dist/index.d.ts +35 -7
- package/dist/index.js +145 -16
- package/dist/index.js.map +1 -1
- package/dist/{run-pE-34AAo.d.cts → run-BgfBWX-z.d.cts} +13 -1
- package/dist/{run-pE-34AAo.d.ts → run-BgfBWX-z.d.ts} +13 -1
- package/dist/types/agent-prims.d.ts +4 -1
- package/dist/types/agent.d.ts +10 -0
- package/dist/types/run.d.ts +9 -0
- package/package.json +14 -14
package/dist/eval.js
CHANGED
|
@@ -2252,6 +2252,37 @@ __export(generate_object_exports, {
|
|
|
2252
2252
|
GenerateObjectError: () => GenerateObjectError,
|
|
2253
2253
|
generateObjectImpl: () => generateObjectImpl
|
|
2254
2254
|
});
|
|
2255
|
+
function salvagePartial(schema, raw) {
|
|
2256
|
+
if (typeof raw !== "object" || raw === null) return raw;
|
|
2257
|
+
const shape = schema.shape;
|
|
2258
|
+
if (shape === void 0 || typeof shape !== "object") return raw;
|
|
2259
|
+
const rawObj = raw;
|
|
2260
|
+
const out = {};
|
|
2261
|
+
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
2262
|
+
if (typeof fieldSchema?.safeParse !== "function") continue;
|
|
2263
|
+
const parsed = fieldSchema.safeParse(rawObj[key]);
|
|
2264
|
+
if (parsed.success) out[key] = parsed.data;
|
|
2265
|
+
}
|
|
2266
|
+
return out;
|
|
2267
|
+
}
|
|
2268
|
+
async function runReasoningPhase(options, deps) {
|
|
2269
|
+
const reasoningOptions = {
|
|
2270
|
+
model: options.model,
|
|
2271
|
+
local: options.local,
|
|
2272
|
+
...options.systemPrompt !== void 0 ? { systemPrompt: options.systemPrompt } : {},
|
|
2273
|
+
...options.apiKey !== void 0 ? { apiKey: options.apiKey } : {},
|
|
2274
|
+
...options.providers !== void 0 ? { providers: options.providers } : {}
|
|
2275
|
+
};
|
|
2276
|
+
const reasoningAgent = await deps.create(reasoningOptions);
|
|
2277
|
+
try {
|
|
2278
|
+
const run = await reasoningAgent.send(options.prompt);
|
|
2279
|
+
const result = await run.wait();
|
|
2280
|
+
const text = result.result;
|
|
2281
|
+
return typeof text === "string" ? text : options.prompt;
|
|
2282
|
+
} finally {
|
|
2283
|
+
await disposeAndDeleteTransient(reasoningAgent, deps.delete);
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2255
2286
|
async function generateObjectImpl(options, deps) {
|
|
2256
2287
|
const { jsonSchema, maxRetries, initialUsage } = setupStructuredOutput(
|
|
2257
2288
|
options.schema,
|
|
@@ -2274,8 +2305,11 @@ async function generateObjectImpl(options, deps) {
|
|
|
2274
2305
|
}
|
|
2275
2306
|
throw new CaptureSentinel(input);
|
|
2276
2307
|
});
|
|
2308
|
+
const reasoningText = options.structuringModel !== void 0 ? await runReasoningPhase(options, deps) : void 0;
|
|
2309
|
+
const structuringModel = options.structuringModel ?? options.model;
|
|
2310
|
+
const structuringPrompt = reasoningText ?? options.prompt;
|
|
2277
2311
|
const agentOptions = buildTransientAgentOptions({
|
|
2278
|
-
model:
|
|
2312
|
+
model: structuringModel,
|
|
2279
2313
|
local: options.local,
|
|
2280
2314
|
outputTool,
|
|
2281
2315
|
...options.systemPrompt !== void 0 ? { systemPrompt: options.systemPrompt } : {},
|
|
@@ -2284,7 +2318,7 @@ async function generateObjectImpl(options, deps) {
|
|
|
2284
2318
|
});
|
|
2285
2319
|
const agent = await deps.create(agentOptions);
|
|
2286
2320
|
try {
|
|
2287
|
-
const userMessage = buildToolPrompt(
|
|
2321
|
+
const userMessage = buildToolPrompt(structuringPrompt);
|
|
2288
2322
|
let lastParseError;
|
|
2289
2323
|
for (let attempt = 0; attempt <= maxRetries; attempt += 1) {
|
|
2290
2324
|
capturedRaw = void 0;
|
|
@@ -2318,6 +2352,22 @@ async function generateObjectImpl(options, deps) {
|
|
|
2318
2352
|
}
|
|
2319
2353
|
lastParseError = parsed.error;
|
|
2320
2354
|
}
|
|
2355
|
+
if (options.errorStrategy === "return-raw") {
|
|
2356
|
+
return {
|
|
2357
|
+
object: capturedRaw,
|
|
2358
|
+
raw: capturedRaw,
|
|
2359
|
+
usage: lastUsage,
|
|
2360
|
+
finishReason: "tool_use"
|
|
2361
|
+
};
|
|
2362
|
+
}
|
|
2363
|
+
if (options.errorStrategy === "return-partial") {
|
|
2364
|
+
return {
|
|
2365
|
+
object: salvagePartial(options.schema, capturedRaw),
|
|
2366
|
+
raw: capturedRaw,
|
|
2367
|
+
usage: lastUsage,
|
|
2368
|
+
finishReason: "tool_use"
|
|
2369
|
+
};
|
|
2370
|
+
}
|
|
2321
2371
|
throw new GenerateObjectError(
|
|
2322
2372
|
"parse_failed",
|
|
2323
2373
|
"Schema parse failed after all retries.",
|
|
@@ -8304,23 +8354,27 @@ function tryParseSkill(raw, fallbackName, source, options) {
|
|
|
8304
8354
|
|
|
8305
8355
|
// src/internal/runtime/skills/skills-manager.ts
|
|
8306
8356
|
var SkillsManager = class {
|
|
8307
|
-
constructor(cwd, _enabled, settingSourcesIncludeProject) {
|
|
8357
|
+
constructor(cwd, _enabled, settingSourcesIncludeProject, skillsDir, inline) {
|
|
8308
8358
|
this.cwd = cwd;
|
|
8309
8359
|
this.settingSourcesIncludeProject = settingSourcesIncludeProject;
|
|
8360
|
+
this.skillsDir = skillsDir;
|
|
8361
|
+
this.inline = inline;
|
|
8310
8362
|
}
|
|
8311
8363
|
cwd;
|
|
8312
8364
|
settingSourcesIncludeProject;
|
|
8365
|
+
skillsDir;
|
|
8366
|
+
inline;
|
|
8313
8367
|
skills = [];
|
|
8314
8368
|
async initialize() {
|
|
8315
8369
|
if (!this.settingSourcesIncludeProject) {
|
|
8316
|
-
this.skills = [];
|
|
8370
|
+
this.skills = this.mergeInline([]);
|
|
8317
8371
|
return;
|
|
8318
8372
|
}
|
|
8319
8373
|
await this.refresh();
|
|
8320
8374
|
}
|
|
8321
8375
|
async refresh() {
|
|
8322
|
-
const skillsRoot = join(this.cwd, ".theokit", "skills");
|
|
8323
|
-
|
|
8376
|
+
const skillsRoot = this.skillsDir ?? join(this.cwd, ".theokit", "skills");
|
|
8377
|
+
const discovered = await discoverSkills(skillsRoot, {
|
|
8324
8378
|
onInvalidSkill: (info) => {
|
|
8325
8379
|
process.stderr.write(
|
|
8326
8380
|
`[theokit-sdk] skill ${info.name} skipped (${info.code}): ${info.message}
|
|
@@ -8328,6 +8382,13 @@ var SkillsManager = class {
|
|
|
8328
8382
|
);
|
|
8329
8383
|
}
|
|
8330
8384
|
});
|
|
8385
|
+
this.skills = this.mergeInline(discovered);
|
|
8386
|
+
}
|
|
8387
|
+
/** M22 — merge inline skills over discovered ones; inline wins on a name conflict. */
|
|
8388
|
+
mergeInline(discovered) {
|
|
8389
|
+
if (this.inline === void 0 || this.inline.length === 0) return discovered;
|
|
8390
|
+
const inlineNames = new Set(this.inline.map((s) => s.name));
|
|
8391
|
+
return [...discovered.filter((s) => !inlineNames.has(s.name)), ...this.inline];
|
|
8331
8392
|
}
|
|
8332
8393
|
list() {
|
|
8333
8394
|
return Promise.resolve(this.skills);
|
|
@@ -8372,7 +8433,10 @@ function bootstrapSubmanagers(args) {
|
|
|
8372
8433
|
out.skillsManager = new SkillsManager(
|
|
8373
8434
|
args.workspaceCwd,
|
|
8374
8435
|
args.options.skills?.enabled,
|
|
8375
|
-
args.settingSourcesIncludeProject
|
|
8436
|
+
args.settingSourcesIncludeProject,
|
|
8437
|
+
// M22 — custom skills directory + inline (code-defined) skills.
|
|
8438
|
+
args.options.skills?.skillsDir,
|
|
8439
|
+
args.options.skills?.inline
|
|
8376
8440
|
);
|
|
8377
8441
|
const localSkills = out.skillsManager;
|
|
8378
8442
|
out.skills = { list: () => localSkills.list() };
|
|
@@ -9212,22 +9276,23 @@ async function executeTool(inputs, resolved, call) {
|
|
|
9212
9276
|
return { stdout: "", stderr: `Unknown tool ${call.name}`, exitCode: 127 };
|
|
9213
9277
|
}
|
|
9214
9278
|
if (resolved.origin === "shell") return runShellTool(inputs, call);
|
|
9215
|
-
if (resolved.origin === "memory") return runMemoryTool(resolved, call);
|
|
9216
|
-
if (resolved.origin === "custom")
|
|
9279
|
+
if (resolved.origin === "memory") return runMemoryTool(resolved, call, inputs.context);
|
|
9280
|
+
if (resolved.origin === "custom")
|
|
9281
|
+
return runCustomTool(resolved, call, inputs.signal, inputs.context);
|
|
9217
9282
|
return runMcpTool(inputs, resolved, call);
|
|
9218
9283
|
}
|
|
9219
|
-
async function runMemoryTool(resolved, call) {
|
|
9220
|
-
return runHandlerTool("memory", resolved.memoryHandler, call);
|
|
9284
|
+
async function runMemoryTool(resolved, call, context) {
|
|
9285
|
+
return runHandlerTool("memory", resolved.memoryHandler, call, void 0, context);
|
|
9221
9286
|
}
|
|
9222
|
-
async function runCustomTool(resolved, call, signal) {
|
|
9223
|
-
return runHandlerTool("custom", resolved.customHandler, call, signal);
|
|
9287
|
+
async function runCustomTool(resolved, call, signal, context) {
|
|
9288
|
+
return runHandlerTool("custom", resolved.customHandler, call, signal, context);
|
|
9224
9289
|
}
|
|
9225
|
-
async function runHandlerTool(kind, handler, call, signal) {
|
|
9290
|
+
async function runHandlerTool(kind, handler, call, signal, context) {
|
|
9226
9291
|
if (handler === void 0) {
|
|
9227
9292
|
return { stdout: "", stderr: `${kind} tool ${call.name} has no handler`, exitCode: 127 };
|
|
9228
9293
|
}
|
|
9229
9294
|
try {
|
|
9230
|
-
const stdout = await handler(call.input, { signal });
|
|
9295
|
+
const stdout = await handler(call.input, { signal, context });
|
|
9231
9296
|
return { stdout, stderr: "", exitCode: 0 };
|
|
9232
9297
|
} catch (cause) {
|
|
9233
9298
|
const message = cause instanceof Error ? cause.message : String(cause);
|
|
@@ -13110,6 +13175,9 @@ function buildLoopInputs(options, runId, userText) {
|
|
|
13110
13175
|
// D318 — forward SendOptions.signal to the agent loop so streamLlmTurn
|
|
13111
13176
|
// can attach it to the LLM `fetch({ signal })` call.
|
|
13112
13177
|
...options.sendOptions.signal !== void 0 ? { signal: options.sendOptions.signal } : {},
|
|
13178
|
+
// M7 — forward SendOptions.context to the loop so every tool handler receives
|
|
13179
|
+
// it on `ctx.context` (shared run config set once, e.g. projectRoot).
|
|
13180
|
+
...options.sendOptions.context !== void 0 ? { context: options.sendOptions.context } : {},
|
|
13113
13181
|
// #58 / #57 — forward the per-tool timeout + tool-result guard so a consumer
|
|
13114
13182
|
// can enable them via SendOptions (not only internal AgentLoopInputs).
|
|
13115
13183
|
...options.sendOptions.perToolTimeoutMs !== void 0 ? { perToolTimeoutMs: options.sendOptions.perToolTimeoutMs } : {},
|