@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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ZodType } from "zod";
|
|
2
|
-
import type { LocalOptions, ModelSelection } from "./types/agent.js";
|
|
1
|
+
import type { z as ZodNamespace, ZodType } from "zod";
|
|
2
|
+
import type { AgentOptions, LocalOptions, ModelSelection, SDKAgent } from "./types/agent.js";
|
|
3
3
|
import type { ProviderRoutingSettings } from "./types/providers.js";
|
|
4
4
|
/**
|
|
5
5
|
* Options accepted by {@link Agent.generateObject}. Returns a typed object
|
|
@@ -16,6 +16,13 @@ export interface GenerateObjectOptions<T extends ZodType> {
|
|
|
16
16
|
systemPrompt?: string;
|
|
17
17
|
/** Model selection. Required (transient agents need a model). */
|
|
18
18
|
model: ModelSelection;
|
|
19
|
+
/**
|
|
20
|
+
* M21 — optional separate model for the STRUCTURING step. When set, `model` first produces a
|
|
21
|
+
* free-text reasoned answer to the prompt (phase 1), then `structuringModel` extracts the
|
|
22
|
+
* schema-matched object by calling the `output` tool over that answer (phase 2). Lets a large
|
|
23
|
+
* model reason while a cheap fast model does the extraction. Absent ⇒ today's single-model flow.
|
|
24
|
+
*/
|
|
25
|
+
structuringModel?: ModelSelection;
|
|
19
26
|
/** API key. Falls back to env (THEOKIT_API_KEY etc). */
|
|
20
27
|
apiKey?: string;
|
|
21
28
|
/** Local runtime config (cwd, sandbox). Required to keep the transient agent local-only. */
|
|
@@ -34,6 +41,17 @@ export interface GenerateObjectOptions<T extends ZodType> {
|
|
|
34
41
|
* when the right env key is set under a different provider name.
|
|
35
42
|
*/
|
|
36
43
|
providers?: ProviderRoutingSettings;
|
|
44
|
+
/**
|
|
45
|
+
* What to do when the model's output fails schema validation after all
|
|
46
|
+
* retries are exhausted (M14):
|
|
47
|
+
* - `'throw'` (default) — throw {@link GenerateObjectError} `parse_failed`.
|
|
48
|
+
* - `'return-raw'` — resolve with the raw, UNVALIDATED input the model sent
|
|
49
|
+
* (`object` may not match the schema; inspect `raw` too).
|
|
50
|
+
* - `'return-partial'` — for object schemas, resolve with only the fields that
|
|
51
|
+
* individually validate (best-effort salvage); non-object schemas fall back
|
|
52
|
+
* to raw.
|
|
53
|
+
*/
|
|
54
|
+
errorStrategy?: "throw" | "return-partial" | "return-raw";
|
|
37
55
|
}
|
|
38
56
|
/**
|
|
39
57
|
* Successful return from {@link Agent.generateObject}.
|
|
@@ -65,3 +83,10 @@ export declare class GenerateObjectError extends Error {
|
|
|
65
83
|
readonly cause?: unknown;
|
|
66
84
|
constructor(code: "no_tool_call" | "parse_failed", message: string, cause?: unknown);
|
|
67
85
|
}
|
|
86
|
+
interface GenerateObjectDeps {
|
|
87
|
+
create: (options: AgentOptions) => Promise<SDKAgent>;
|
|
88
|
+
/** Hard-delete the transient agent from the registry after dispose. */
|
|
89
|
+
delete: (agentId: string) => Promise<void>;
|
|
90
|
+
}
|
|
91
|
+
export declare function generateObjectImpl<T extends ZodType>(options: GenerateObjectOptions<T>, deps: GenerateObjectDeps): Promise<GenerateObjectResult<ZodNamespace.infer<T>>>;
|
|
92
|
+
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -3800,6 +3800,37 @@ __export(generate_object_exports, {
|
|
|
3800
3800
|
GenerateObjectError: () => exports.GenerateObjectError,
|
|
3801
3801
|
generateObjectImpl: () => generateObjectImpl
|
|
3802
3802
|
});
|
|
3803
|
+
function salvagePartial(schema, raw) {
|
|
3804
|
+
if (typeof raw !== "object" || raw === null) return raw;
|
|
3805
|
+
const shape = schema.shape;
|
|
3806
|
+
if (shape === void 0 || typeof shape !== "object") return raw;
|
|
3807
|
+
const rawObj = raw;
|
|
3808
|
+
const out = {};
|
|
3809
|
+
for (const [key2, fieldSchema] of Object.entries(shape)) {
|
|
3810
|
+
if (typeof fieldSchema?.safeParse !== "function") continue;
|
|
3811
|
+
const parsed = fieldSchema.safeParse(rawObj[key2]);
|
|
3812
|
+
if (parsed.success) out[key2] = parsed.data;
|
|
3813
|
+
}
|
|
3814
|
+
return out;
|
|
3815
|
+
}
|
|
3816
|
+
async function runReasoningPhase(options, deps) {
|
|
3817
|
+
const reasoningOptions = {
|
|
3818
|
+
model: options.model,
|
|
3819
|
+
local: options.local,
|
|
3820
|
+
...options.systemPrompt !== void 0 ? { systemPrompt: options.systemPrompt } : {},
|
|
3821
|
+
...options.apiKey !== void 0 ? { apiKey: options.apiKey } : {},
|
|
3822
|
+
...options.providers !== void 0 ? { providers: options.providers } : {}
|
|
3823
|
+
};
|
|
3824
|
+
const reasoningAgent = await deps.create(reasoningOptions);
|
|
3825
|
+
try {
|
|
3826
|
+
const run = await reasoningAgent.send(options.prompt);
|
|
3827
|
+
const result = await run.wait();
|
|
3828
|
+
const text = result.result;
|
|
3829
|
+
return typeof text === "string" ? text : options.prompt;
|
|
3830
|
+
} finally {
|
|
3831
|
+
await disposeAndDeleteTransient(reasoningAgent, deps.delete);
|
|
3832
|
+
}
|
|
3833
|
+
}
|
|
3803
3834
|
async function generateObjectImpl(options, deps) {
|
|
3804
3835
|
const { jsonSchema, maxRetries, initialUsage } = setupStructuredOutput(
|
|
3805
3836
|
options.schema,
|
|
@@ -3822,8 +3853,11 @@ async function generateObjectImpl(options, deps) {
|
|
|
3822
3853
|
}
|
|
3823
3854
|
throw new CaptureSentinel(input);
|
|
3824
3855
|
});
|
|
3856
|
+
const reasoningText = options.structuringModel !== void 0 ? await runReasoningPhase(options, deps) : void 0;
|
|
3857
|
+
const structuringModel = options.structuringModel ?? options.model;
|
|
3858
|
+
const structuringPrompt = reasoningText ?? options.prompt;
|
|
3825
3859
|
const agentOptions = buildTransientAgentOptions({
|
|
3826
|
-
model:
|
|
3860
|
+
model: structuringModel,
|
|
3827
3861
|
local: options.local,
|
|
3828
3862
|
outputTool,
|
|
3829
3863
|
...options.systemPrompt !== void 0 ? { systemPrompt: options.systemPrompt } : {},
|
|
@@ -3832,7 +3866,7 @@ async function generateObjectImpl(options, deps) {
|
|
|
3832
3866
|
});
|
|
3833
3867
|
const agent = await deps.create(agentOptions);
|
|
3834
3868
|
try {
|
|
3835
|
-
const userMessage = buildToolPrompt(
|
|
3869
|
+
const userMessage = buildToolPrompt(structuringPrompt);
|
|
3836
3870
|
let lastParseError;
|
|
3837
3871
|
for (let attempt = 0; attempt <= maxRetries; attempt += 1) {
|
|
3838
3872
|
capturedRaw = void 0;
|
|
@@ -3866,6 +3900,22 @@ async function generateObjectImpl(options, deps) {
|
|
|
3866
3900
|
}
|
|
3867
3901
|
lastParseError = parsed.error;
|
|
3868
3902
|
}
|
|
3903
|
+
if (options.errorStrategy === "return-raw") {
|
|
3904
|
+
return {
|
|
3905
|
+
object: capturedRaw,
|
|
3906
|
+
raw: capturedRaw,
|
|
3907
|
+
usage: lastUsage,
|
|
3908
|
+
finishReason: "tool_use"
|
|
3909
|
+
};
|
|
3910
|
+
}
|
|
3911
|
+
if (options.errorStrategy === "return-partial") {
|
|
3912
|
+
return {
|
|
3913
|
+
object: salvagePartial(options.schema, capturedRaw),
|
|
3914
|
+
raw: capturedRaw,
|
|
3915
|
+
usage: lastUsage,
|
|
3916
|
+
finishReason: "tool_use"
|
|
3917
|
+
};
|
|
3918
|
+
}
|
|
3869
3919
|
throw new exports.GenerateObjectError(
|
|
3870
3920
|
"parse_failed",
|
|
3871
3921
|
"Schema parse failed after all retries.",
|
|
@@ -10774,23 +10824,27 @@ function tryParseSkill(raw, fallbackName, source, options) {
|
|
|
10774
10824
|
|
|
10775
10825
|
// src/internal/runtime/skills/skills-manager.ts
|
|
10776
10826
|
var SkillsManager = class {
|
|
10777
|
-
constructor(cwd, _enabled, settingSourcesIncludeProject) {
|
|
10827
|
+
constructor(cwd, _enabled, settingSourcesIncludeProject, skillsDir, inline) {
|
|
10778
10828
|
this.cwd = cwd;
|
|
10779
10829
|
this.settingSourcesIncludeProject = settingSourcesIncludeProject;
|
|
10830
|
+
this.skillsDir = skillsDir;
|
|
10831
|
+
this.inline = inline;
|
|
10780
10832
|
}
|
|
10781
10833
|
cwd;
|
|
10782
10834
|
settingSourcesIncludeProject;
|
|
10835
|
+
skillsDir;
|
|
10836
|
+
inline;
|
|
10783
10837
|
skills = [];
|
|
10784
10838
|
async initialize() {
|
|
10785
10839
|
if (!this.settingSourcesIncludeProject) {
|
|
10786
|
-
this.skills = [];
|
|
10840
|
+
this.skills = this.mergeInline([]);
|
|
10787
10841
|
return;
|
|
10788
10842
|
}
|
|
10789
10843
|
await this.refresh();
|
|
10790
10844
|
}
|
|
10791
10845
|
async refresh() {
|
|
10792
|
-
const skillsRoot = path.join(this.cwd, ".theokit", "skills");
|
|
10793
|
-
|
|
10846
|
+
const skillsRoot = this.skillsDir ?? path.join(this.cwd, ".theokit", "skills");
|
|
10847
|
+
const discovered = await discoverSkills(skillsRoot, {
|
|
10794
10848
|
onInvalidSkill: (info) => {
|
|
10795
10849
|
process.stderr.write(
|
|
10796
10850
|
`[theokit-sdk] skill ${info.name} skipped (${info.code}): ${info.message}
|
|
@@ -10798,6 +10852,13 @@ var SkillsManager = class {
|
|
|
10798
10852
|
);
|
|
10799
10853
|
}
|
|
10800
10854
|
});
|
|
10855
|
+
this.skills = this.mergeInline(discovered);
|
|
10856
|
+
}
|
|
10857
|
+
/** M22 — merge inline skills over discovered ones; inline wins on a name conflict. */
|
|
10858
|
+
mergeInline(discovered) {
|
|
10859
|
+
if (this.inline === void 0 || this.inline.length === 0) return discovered;
|
|
10860
|
+
const inlineNames = new Set(this.inline.map((s) => s.name));
|
|
10861
|
+
return [...discovered.filter((s) => !inlineNames.has(s.name)), ...this.inline];
|
|
10801
10862
|
}
|
|
10802
10863
|
list() {
|
|
10803
10864
|
return Promise.resolve(this.skills);
|
|
@@ -10842,7 +10903,10 @@ function bootstrapSubmanagers(args) {
|
|
|
10842
10903
|
out.skillsManager = new SkillsManager(
|
|
10843
10904
|
args.workspaceCwd,
|
|
10844
10905
|
args.options.skills?.enabled,
|
|
10845
|
-
args.settingSourcesIncludeProject
|
|
10906
|
+
args.settingSourcesIncludeProject,
|
|
10907
|
+
// M22 — custom skills directory + inline (code-defined) skills.
|
|
10908
|
+
args.options.skills?.skillsDir,
|
|
10909
|
+
args.options.skills?.inline
|
|
10846
10910
|
);
|
|
10847
10911
|
const localSkills = out.skillsManager;
|
|
10848
10912
|
out.skills = { list: () => localSkills.list() };
|
|
@@ -11682,22 +11746,23 @@ async function executeTool(inputs, resolved, call) {
|
|
|
11682
11746
|
return { stdout: "", stderr: `Unknown tool ${call.name}`, exitCode: 127 };
|
|
11683
11747
|
}
|
|
11684
11748
|
if (resolved.origin === "shell") return runShellTool(inputs, call);
|
|
11685
|
-
if (resolved.origin === "memory") return runMemoryTool(resolved, call);
|
|
11686
|
-
if (resolved.origin === "custom")
|
|
11749
|
+
if (resolved.origin === "memory") return runMemoryTool(resolved, call, inputs.context);
|
|
11750
|
+
if (resolved.origin === "custom")
|
|
11751
|
+
return runCustomTool(resolved, call, inputs.signal, inputs.context);
|
|
11687
11752
|
return runMcpTool(inputs, resolved, call);
|
|
11688
11753
|
}
|
|
11689
|
-
async function runMemoryTool(resolved, call) {
|
|
11690
|
-
return runHandlerTool("memory", resolved.memoryHandler, call);
|
|
11754
|
+
async function runMemoryTool(resolved, call, context) {
|
|
11755
|
+
return runHandlerTool("memory", resolved.memoryHandler, call, void 0, context);
|
|
11691
11756
|
}
|
|
11692
|
-
async function runCustomTool(resolved, call, signal) {
|
|
11693
|
-
return runHandlerTool("custom", resolved.customHandler, call, signal);
|
|
11757
|
+
async function runCustomTool(resolved, call, signal, context) {
|
|
11758
|
+
return runHandlerTool("custom", resolved.customHandler, call, signal, context);
|
|
11694
11759
|
}
|
|
11695
|
-
async function runHandlerTool(kind, handler, call, signal) {
|
|
11760
|
+
async function runHandlerTool(kind, handler, call, signal, context) {
|
|
11696
11761
|
if (handler === void 0) {
|
|
11697
11762
|
return { stdout: "", stderr: `${kind} tool ${call.name} has no handler`, exitCode: 127 };
|
|
11698
11763
|
}
|
|
11699
11764
|
try {
|
|
11700
|
-
const stdout = await handler(call.input, { signal });
|
|
11765
|
+
const stdout = await handler(call.input, { signal, context });
|
|
11701
11766
|
return { stdout, stderr: "", exitCode: 0 };
|
|
11702
11767
|
} catch (cause) {
|
|
11703
11768
|
const message = cause instanceof Error ? cause.message : String(cause);
|
|
@@ -15596,6 +15661,9 @@ function buildLoopInputs(options, runId, userText) {
|
|
|
15596
15661
|
// D318 — forward SendOptions.signal to the agent loop so streamLlmTurn
|
|
15597
15662
|
// can attach it to the LLM `fetch({ signal })` call.
|
|
15598
15663
|
...options.sendOptions.signal !== void 0 ? { signal: options.sendOptions.signal } : {},
|
|
15664
|
+
// M7 — forward SendOptions.context to the loop so every tool handler receives
|
|
15665
|
+
// it on `ctx.context` (shared run config set once, e.g. projectRoot).
|
|
15666
|
+
...options.sendOptions.context !== void 0 ? { context: options.sendOptions.context } : {},
|
|
15599
15667
|
// #58 / #57 — forward the per-tool timeout + tool-result guard so a consumer
|
|
15600
15668
|
// can enable them via SendOptions (not only internal AgentLoopInputs).
|
|
15601
15669
|
...options.sendOptions.perToolTimeoutMs !== void 0 ? { perToolTimeoutMs: options.sendOptions.perToolTimeoutMs } : {},
|
|
@@ -18740,6 +18808,20 @@ var Budget = class {
|
|
|
18740
18808
|
}
|
|
18741
18809
|
};
|
|
18742
18810
|
|
|
18811
|
+
// src/create-skill.ts
|
|
18812
|
+
function createSkill(spec) {
|
|
18813
|
+
if (!spec.name) throw new Error("createSkill: `name` is required.");
|
|
18814
|
+
if (!spec.description) throw new Error("createSkill: `description` is required.");
|
|
18815
|
+
return {
|
|
18816
|
+
name: spec.name,
|
|
18817
|
+
description: spec.description,
|
|
18818
|
+
source: `inline://${spec.name}`,
|
|
18819
|
+
instructions: spec.instructions,
|
|
18820
|
+
...spec.category !== void 0 ? { category: spec.category } : {},
|
|
18821
|
+
...spec.dependencies !== void 0 ? { dependencies: spec.dependencies } : {}
|
|
18822
|
+
};
|
|
18823
|
+
}
|
|
18824
|
+
|
|
18743
18825
|
// src/cron.ts
|
|
18744
18826
|
init_errors();
|
|
18745
18827
|
|
|
@@ -20094,6 +20176,53 @@ function createPermissionPlugin(engine, opts = {}) {
|
|
|
20094
20176
|
});
|
|
20095
20177
|
}
|
|
20096
20178
|
|
|
20179
|
+
// src/schema-normalizer.ts
|
|
20180
|
+
init_to_json_schema();
|
|
20181
|
+
function isJsonSchemaObject(s) {
|
|
20182
|
+
if (typeof s !== "object" || s === null) return false;
|
|
20183
|
+
const o = s;
|
|
20184
|
+
if ("$schema" in o) return true;
|
|
20185
|
+
return o.type === "object" && typeof o.properties === "object" && o.properties !== null;
|
|
20186
|
+
}
|
|
20187
|
+
function hasToJsonSchemaMethod(s) {
|
|
20188
|
+
return typeof s === "object" && s !== null && typeof s.toJsonSchema === "function";
|
|
20189
|
+
}
|
|
20190
|
+
function isZodSchema(s) {
|
|
20191
|
+
if (typeof s !== "object" || s === null) return false;
|
|
20192
|
+
const o = s;
|
|
20193
|
+
return typeof o.safeParse === "function" && ("_def" in o || "def" in o);
|
|
20194
|
+
}
|
|
20195
|
+
function isValibotSchema(s) {
|
|
20196
|
+
if (typeof s !== "object" || s === null) return false;
|
|
20197
|
+
const o = s;
|
|
20198
|
+
return o.kind === "schema" && "type" in o && typeof o.toJsonSchema !== "function";
|
|
20199
|
+
}
|
|
20200
|
+
async function normalizeSchema(schema) {
|
|
20201
|
+
if (isJsonSchemaObject(schema)) return schema;
|
|
20202
|
+
if (isValibotSchema(schema)) {
|
|
20203
|
+
const specifier = "@valibot/to-json-schema";
|
|
20204
|
+
try {
|
|
20205
|
+
const mod = await import(specifier);
|
|
20206
|
+
return mod.toJsonSchema(schema);
|
|
20207
|
+
} catch (err) {
|
|
20208
|
+
const missing = err instanceof Error && /Cannot find|Cannot resolve|ERR_MODULE_NOT_FOUND/.test(err.message);
|
|
20209
|
+
if (missing) {
|
|
20210
|
+
throw new Error(
|
|
20211
|
+
"normalizeSchema: a Valibot schema requires the optional '@valibot/to-json-schema' package. Install it, or use a Zod schema (the default recommendation)."
|
|
20212
|
+
);
|
|
20213
|
+
}
|
|
20214
|
+
throw err;
|
|
20215
|
+
}
|
|
20216
|
+
}
|
|
20217
|
+
if (isZodSchema(schema)) {
|
|
20218
|
+
return toJsonSchema(schema, { unrepresentable: "any" });
|
|
20219
|
+
}
|
|
20220
|
+
if (hasToJsonSchemaMethod(schema)) return schema.toJsonSchema();
|
|
20221
|
+
throw new Error(
|
|
20222
|
+
"normalizeSchema: unsupported schema. Supported: Zod (default), JSON Schema, ArkType (.toJsonSchema()), Valibot (with @valibot/to-json-schema)."
|
|
20223
|
+
);
|
|
20224
|
+
}
|
|
20225
|
+
|
|
20097
20226
|
// src/security.ts
|
|
20098
20227
|
init_security();
|
|
20099
20228
|
var Security = class {
|
|
@@ -20892,6 +21021,7 @@ exports.createAgentFactory = createAgentFactory;
|
|
|
20892
21021
|
exports.createCounterBudgetTracker = createCounterBudgetTracker;
|
|
20893
21022
|
exports.createNoopMemoryProvider = createNoopMemoryProvider;
|
|
20894
21023
|
exports.createPermissionPlugin = createPermissionPlugin;
|
|
21024
|
+
exports.createSkill = createSkill;
|
|
20895
21025
|
exports.createSquad = createSquad;
|
|
20896
21026
|
exports.definePlugin = definePlugin;
|
|
20897
21027
|
exports.defineProvider = defineProvider;
|
|
@@ -20902,6 +21032,7 @@ exports.inferApiMode = inferApiMode;
|
|
|
20902
21032
|
exports.isTransientError = isTransientError;
|
|
20903
21033
|
exports.migrateSqliteToLance = migrateSqliteToLance2;
|
|
20904
21034
|
exports.mkMemoryId = mkMemoryId;
|
|
21035
|
+
exports.normalizeSchema = normalizeSchema;
|
|
20905
21036
|
exports.normalizeUsage = normalizeUsage;
|
|
20906
21037
|
exports.preflightCheck = preflightCheck;
|
|
20907
21038
|
exports.scopedConversationId = scopedConversationId;
|