@theokit/sdk 2.25.0 → 2.26.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 +29 -0
- package/dist/a2a/index.cjs +208 -4
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +208 -4
- package/dist/a2a/index.js.map +1 -1
- package/dist/{cron-B44D-678.d.ts → cron-BR1NCSk1.d.cts} +11 -1
- package/dist/{cron-qI-dbG7c.d.cts → cron-DgEQCJ2i.d.ts} +11 -1
- package/dist/cron.cjs +187 -4
- 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 +187 -4
- package/dist/cron.js.map +1 -1
- package/dist/{errors-DRS-kqOK.d.ts → errors-CbY3pxY7.d.ts} +1 -1
- package/dist/{errors-DIKBXffg.d.cts → errors-DLMNb4Ka.d.cts} +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/eval.cjs +187 -4
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +187 -4
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +234 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +56 -7
- package/dist/index.d.ts +56 -7
- package/dist/index.js +232 -7
- package/dist/index.js.map +1 -1
- package/dist/internal/runtime/processors/run-processors.d.ts +10 -0
- package/dist/internal/runtime/processors/tripwire-run.d.ts +16 -0
- package/dist/internal/runtime/processors/wrap-output-run.d.ts +18 -0
- package/dist/{run-Cr0C6cOM.d.cts → run-CdWiihyU.d.cts} +109 -2
- package/dist/{run-Cr0C6cOM.d.ts → run-CdWiihyU.d.ts} +109 -2
- package/dist/types/agent.d.ts +10 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/processors.d.ts +84 -0
- package/dist/types/run-events.d.ts +11 -1
- package/dist/types/run.d.ts +12 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7737,8 +7737,18 @@ function validateCloudToolParity(options) {
|
|
|
7737
7737
|
if (options.cloud === void 0) return;
|
|
7738
7738
|
rejectFunctionSystemPrompt(options);
|
|
7739
7739
|
rejectFunctionSkills(options);
|
|
7740
|
+
rejectProcessors(options);
|
|
7740
7741
|
rejectStdioMcpLocalPaths(options);
|
|
7741
7742
|
}
|
|
7743
|
+
function rejectProcessors(options) {
|
|
7744
|
+
const hasProcessors = (options.inputProcessors?.length ?? 0) > 0 || (options.outputProcessors?.length ?? 0) > 0;
|
|
7745
|
+
if (hasProcessors) {
|
|
7746
|
+
throw new exports.ConfigurationError(
|
|
7747
|
+
"Cloud agents can't run guardrail processors \u2014 a Processor carries function handlers that don't survive serialization to PaaS. Run processors on a local agent, or move the guardrail into a server-side gateway in front of TheoCloud.",
|
|
7748
|
+
{ code: "cloud_incompatible_function_resolver" }
|
|
7749
|
+
);
|
|
7750
|
+
}
|
|
7751
|
+
}
|
|
7742
7752
|
function rejectFunctionSystemPrompt(options) {
|
|
7743
7753
|
if (typeof options.systemPrompt === "function") {
|
|
7744
7754
|
throw new exports.ConfigurationError(
|
|
@@ -17677,6 +17687,145 @@ function ponyfillAny(signals) {
|
|
|
17677
17687
|
return ctrl.signal;
|
|
17678
17688
|
}
|
|
17679
17689
|
|
|
17690
|
+
// src/internal/runtime/processors/run-processors.ts
|
|
17691
|
+
var ProcessorAbort = class {
|
|
17692
|
+
constructor(processorId, reason) {
|
|
17693
|
+
this.processorId = processorId;
|
|
17694
|
+
this.reason = reason;
|
|
17695
|
+
}
|
|
17696
|
+
processorId;
|
|
17697
|
+
reason;
|
|
17698
|
+
};
|
|
17699
|
+
function fireViolation(processor, violation) {
|
|
17700
|
+
try {
|
|
17701
|
+
processor.onViolation?.(violation);
|
|
17702
|
+
} catch {
|
|
17703
|
+
}
|
|
17704
|
+
}
|
|
17705
|
+
function controlsFor(processor) {
|
|
17706
|
+
return {
|
|
17707
|
+
abort(reason) {
|
|
17708
|
+
throw new ProcessorAbort(processor.id, reason);
|
|
17709
|
+
},
|
|
17710
|
+
warn(message, detail) {
|
|
17711
|
+
fireViolation(processor, {
|
|
17712
|
+
processorId: processor.id,
|
|
17713
|
+
message,
|
|
17714
|
+
...detail !== void 0 ? { detail } : {}
|
|
17715
|
+
});
|
|
17716
|
+
}
|
|
17717
|
+
};
|
|
17718
|
+
}
|
|
17719
|
+
function selectHandler(processor, phase) {
|
|
17720
|
+
if (phase === "input") {
|
|
17721
|
+
return processor.processInput ? { kind: "input", fn: processor.processInput } : void 0;
|
|
17722
|
+
}
|
|
17723
|
+
return processor.processOutput ? { kind: "output", fn: processor.processOutput } : void 0;
|
|
17724
|
+
}
|
|
17725
|
+
function invokeHandler(handler, value, agentId, controls) {
|
|
17726
|
+
return handler.kind === "input" ? handler.fn({ message: value, agentId, ...controls }) : handler.fn({ text: value, agentId, ...controls });
|
|
17727
|
+
}
|
|
17728
|
+
async function runOneProcessor(processor, value, agentId, phase) {
|
|
17729
|
+
const handler = selectHandler(processor, phase);
|
|
17730
|
+
if (handler === void 0) return { value };
|
|
17731
|
+
try {
|
|
17732
|
+
const out = await invokeHandler(handler, value, agentId, controlsFor(processor));
|
|
17733
|
+
return { value: typeof out === "string" ? out : value };
|
|
17734
|
+
} catch (err) {
|
|
17735
|
+
if (!(err instanceof ProcessorAbort)) throw err;
|
|
17736
|
+
fireViolation(processor, { processorId: err.processorId, message: err.reason });
|
|
17737
|
+
return { tripwire: { reason: err.reason, processorId: err.processorId } };
|
|
17738
|
+
}
|
|
17739
|
+
}
|
|
17740
|
+
async function runPipeline(processors, initial, agentId, phase) {
|
|
17741
|
+
let value = initial;
|
|
17742
|
+
for (const processor of processors) {
|
|
17743
|
+
const step = await runOneProcessor(processor, value, agentId, phase);
|
|
17744
|
+
if ("tripwire" in step) return { kind: "tripwire", tripwire: step.tripwire };
|
|
17745
|
+
value = step.value;
|
|
17746
|
+
}
|
|
17747
|
+
return { kind: "ok", value };
|
|
17748
|
+
}
|
|
17749
|
+
function runInputProcessors(processors, message, agentId) {
|
|
17750
|
+
return runPipeline(processors, message, agentId, "input");
|
|
17751
|
+
}
|
|
17752
|
+
function runOutputProcessors(processors, text, agentId) {
|
|
17753
|
+
return runPipeline(processors, text, agentId, "output");
|
|
17754
|
+
}
|
|
17755
|
+
|
|
17756
|
+
// src/internal/runtime/processors/tripwire-run.ts
|
|
17757
|
+
var SUPPORTED = /* @__PURE__ */ new Set([
|
|
17758
|
+
"stream",
|
|
17759
|
+
"wait",
|
|
17760
|
+
"cancel",
|
|
17761
|
+
"conversation"
|
|
17762
|
+
]);
|
|
17763
|
+
function emptyStream() {
|
|
17764
|
+
return {
|
|
17765
|
+
next: () => Promise.resolve({ done: true, value: void 0 }),
|
|
17766
|
+
return: () => Promise.resolve({ done: true, value: void 0 }),
|
|
17767
|
+
throw: (err) => Promise.reject(err),
|
|
17768
|
+
[Symbol.asyncIterator]() {
|
|
17769
|
+
return this;
|
|
17770
|
+
}
|
|
17771
|
+
};
|
|
17772
|
+
}
|
|
17773
|
+
function createTripwireRun(args) {
|
|
17774
|
+
const id = globalThis.crypto.randomUUID();
|
|
17775
|
+
const result = {
|
|
17776
|
+
id,
|
|
17777
|
+
status: "cancelled",
|
|
17778
|
+
tripwire: args.tripwire,
|
|
17779
|
+
...args.model !== void 0 ? { model: args.model } : {}
|
|
17780
|
+
};
|
|
17781
|
+
const run = {
|
|
17782
|
+
id,
|
|
17783
|
+
agentId: args.agentId,
|
|
17784
|
+
status: "cancelled",
|
|
17785
|
+
...args.model !== void 0 ? { model: args.model } : {},
|
|
17786
|
+
stream: () => emptyStream(),
|
|
17787
|
+
wait: () => Promise.resolve(result),
|
|
17788
|
+
cancel: () => Promise.resolve(),
|
|
17789
|
+
conversation: () => Promise.resolve([]),
|
|
17790
|
+
supports: (op) => SUPPORTED.has(op),
|
|
17791
|
+
unsupportedReason: (op) => SUPPORTED.has(op) ? void 0 : `operation "${op}" is not available on a tripwire run`,
|
|
17792
|
+
onDidChangeStatus: () => () => {
|
|
17793
|
+
}
|
|
17794
|
+
// already terminal — status never changes
|
|
17795
|
+
};
|
|
17796
|
+
registerRun(run);
|
|
17797
|
+
return run;
|
|
17798
|
+
}
|
|
17799
|
+
|
|
17800
|
+
// src/internal/runtime/processors/wrap-output-run.ts
|
|
17801
|
+
function wrapRunWithOutputProcessors(args) {
|
|
17802
|
+
if (args.processors.length === 0) return args.run;
|
|
17803
|
+
const compute = async () => {
|
|
17804
|
+
const result = await args.run.wait();
|
|
17805
|
+
if (result.status !== "finished" || result.result === void 0) return result;
|
|
17806
|
+
const res = await runOutputProcessors(args.processors, result.result, args.agentId);
|
|
17807
|
+
if (res.kind === "ok") return { ...result, result: res.value };
|
|
17808
|
+
emitRunEvent(args.onRunEvent, {
|
|
17809
|
+
type: "tripwire",
|
|
17810
|
+
reason: res.tripwire.reason,
|
|
17811
|
+
processorId: res.tripwire.processorId
|
|
17812
|
+
});
|
|
17813
|
+
const { result: _suppressed, ...metadata } = result;
|
|
17814
|
+
return { ...metadata, status: "cancelled", tripwire: res.tripwire };
|
|
17815
|
+
};
|
|
17816
|
+
let processed;
|
|
17817
|
+
const wrappedWait = () => {
|
|
17818
|
+
processed ??= compute();
|
|
17819
|
+
return processed;
|
|
17820
|
+
};
|
|
17821
|
+
return new Proxy(args.run, {
|
|
17822
|
+
get(target, prop, receiver) {
|
|
17823
|
+
if (prop === "wait") return wrappedWait;
|
|
17824
|
+
return Reflect.get(target, prop, receiver);
|
|
17825
|
+
}
|
|
17826
|
+
});
|
|
17827
|
+
}
|
|
17828
|
+
|
|
17680
17829
|
// src/internal/runtime/local-agent/local-agent-memory-hooks.ts
|
|
17681
17830
|
var DEFAULT_MAX_RECALL_BYTES = 16e3;
|
|
17682
17831
|
async function applyPreUserSendHook(args) {
|
|
@@ -17724,11 +17873,38 @@ function wrapRunWithPostReplyHook(args) {
|
|
|
17724
17873
|
}
|
|
17725
17874
|
|
|
17726
17875
|
// src/internal/runtime/local-agent/local-agent-send.ts
|
|
17876
|
+
async function applyInputProcessors(inputs, message, rawUserText, options, sendModel) {
|
|
17877
|
+
const processors = inputs.options.inputProcessors;
|
|
17878
|
+
if (processors === void 0 || processors.length === 0) {
|
|
17879
|
+
return { userText: rawUserText, effectiveMessage: message };
|
|
17880
|
+
}
|
|
17881
|
+
const res = await runInputProcessors(processors, rawUserText, inputs.agentId);
|
|
17882
|
+
if (res.kind === "tripwire") {
|
|
17883
|
+
emitRunEvent(options.onRunEvent, {
|
|
17884
|
+
type: "tripwire",
|
|
17885
|
+
reason: res.tripwire.reason,
|
|
17886
|
+
processorId: res.tripwire.processorId
|
|
17887
|
+
});
|
|
17888
|
+
return {
|
|
17889
|
+
tripwireRun: createTripwireRun({
|
|
17890
|
+
agentId: inputs.agentId,
|
|
17891
|
+
tripwire: res.tripwire,
|
|
17892
|
+
model: sendModel
|
|
17893
|
+
})
|
|
17894
|
+
};
|
|
17895
|
+
}
|
|
17896
|
+
const effectiveMessage = typeof message === "string" ? res.value : { ...message, text: res.value };
|
|
17897
|
+
return { userText: res.value, effectiveMessage };
|
|
17898
|
+
}
|
|
17727
17899
|
async function executeSendLocked(inputs, message, options) {
|
|
17728
17900
|
if (inputs.disposed) throw new exports.AgentDisposedError(inputs.agentId);
|
|
17729
17901
|
await consumePending(inputs.agentId, inputs.invalidationPending, inputs.clearInvalidation, inputs.reload);
|
|
17730
|
-
|
|
17731
|
-
|
|
17902
|
+
const sendModel = normalizeModel(options.model);
|
|
17903
|
+
inputs.applyModelOverride(sendModel);
|
|
17904
|
+
const rawUserText = typeof message === "string" ? message : message.text;
|
|
17905
|
+
const gated = await applyInputProcessors(inputs, message, rawUserText, options, sendModel);
|
|
17906
|
+
if ("tripwireRun" in gated) return gated.tripwireRun;
|
|
17907
|
+
const { userText, effectiveMessage } = gated;
|
|
17732
17908
|
if (inputs.options.onBeforeSend !== void 0) {
|
|
17733
17909
|
await inputs.options.onBeforeSend({
|
|
17734
17910
|
conversationId: inputs.agentId,
|
|
@@ -17740,7 +17916,7 @@ async function executeSendLocked(inputs, message, options) {
|
|
|
17740
17916
|
pluginManager: inputs.pluginManagerCode,
|
|
17741
17917
|
agentId: inputs.agentId,
|
|
17742
17918
|
options: inputs.options,
|
|
17743
|
-
original:
|
|
17919
|
+
original: effectiveMessage,
|
|
17744
17920
|
userText,
|
|
17745
17921
|
sendOptions: options
|
|
17746
17922
|
});
|
|
@@ -17778,11 +17954,18 @@ async function executeSendLocked(inputs, message, options) {
|
|
|
17778
17954
|
memoryTools,
|
|
17779
17955
|
effectiveMemoryProvider
|
|
17780
17956
|
);
|
|
17957
|
+
const outputProcessors = inputs.options.outputProcessors;
|
|
17958
|
+
const processedRun = outputProcessors !== void 0 && outputProcessors.length > 0 ? wrapRunWithOutputProcessors({
|
|
17959
|
+
run,
|
|
17960
|
+
processors: outputProcessors,
|
|
17961
|
+
agentId: inputs.agentId,
|
|
17962
|
+
onRunEvent: options.onRunEvent
|
|
17963
|
+
}) : run;
|
|
17781
17964
|
return wrapRunWithPostReplyHook({
|
|
17782
17965
|
pluginManager: inputs.pluginManagerCode,
|
|
17783
17966
|
agentId: inputs.agentId,
|
|
17784
17967
|
options: inputs.options,
|
|
17785
|
-
run,
|
|
17968
|
+
run: processedRun,
|
|
17786
17969
|
userText
|
|
17787
17970
|
});
|
|
17788
17971
|
}
|
|
@@ -19141,6 +19324,48 @@ var Budget = class {
|
|
|
19141
19324
|
}
|
|
19142
19325
|
};
|
|
19143
19326
|
|
|
19327
|
+
// src/built-in-processors.ts
|
|
19328
|
+
var CHARS_PER_TOKEN = 4;
|
|
19329
|
+
function estimateTokens(text) {
|
|
19330
|
+
return Math.ceil(text.length / CHARS_PER_TOKEN);
|
|
19331
|
+
}
|
|
19332
|
+
var CONTROL_CHARS = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g;
|
|
19333
|
+
function createUnicodeNormalizer(opts = {}) {
|
|
19334
|
+
const stripControlChars = opts.stripControlChars ?? false;
|
|
19335
|
+
const collapseWhitespace = opts.collapseWhitespace ?? false;
|
|
19336
|
+
return {
|
|
19337
|
+
id: "unicode-normalizer",
|
|
19338
|
+
processInput(ctx) {
|
|
19339
|
+
let s = ctx.message.normalize("NFC");
|
|
19340
|
+
if (stripControlChars) s = s.replace(CONTROL_CHARS, "");
|
|
19341
|
+
if (collapseWhitespace) {
|
|
19342
|
+
s = s.replace(/[^\S\n]+/g, " ").replace(/ *\n */g, "\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
19343
|
+
}
|
|
19344
|
+
return s;
|
|
19345
|
+
}
|
|
19346
|
+
};
|
|
19347
|
+
}
|
|
19348
|
+
function createTokenLimiter(opts) {
|
|
19349
|
+
if (!Number.isInteger(opts.limit) || opts.limit <= 0) {
|
|
19350
|
+
throw new Error("createTokenLimiter: `limit` must be a positive integer.");
|
|
19351
|
+
}
|
|
19352
|
+
const limit = opts.limit;
|
|
19353
|
+
const strategy = opts.strategy ?? "truncate";
|
|
19354
|
+
const cap2 = (text, controls) => {
|
|
19355
|
+
const estimated = estimateTokens(text);
|
|
19356
|
+
if (estimated <= limit) return text;
|
|
19357
|
+
if (strategy === "block") {
|
|
19358
|
+
controls.abort(`exceeds token limit ${limit} (~${estimated} estimated)`);
|
|
19359
|
+
}
|
|
19360
|
+
return [...text].slice(0, limit * CHARS_PER_TOKEN).join("");
|
|
19361
|
+
};
|
|
19362
|
+
return {
|
|
19363
|
+
id: "token-limiter",
|
|
19364
|
+
processInput: (ctx) => cap2(ctx.message, ctx),
|
|
19365
|
+
processOutput: (ctx) => cap2(ctx.text, ctx)
|
|
19366
|
+
};
|
|
19367
|
+
}
|
|
19368
|
+
|
|
19144
19369
|
// src/create-skill.ts
|
|
19145
19370
|
function createSkill(spec) {
|
|
19146
19371
|
if (!spec.name) throw new Error("createSkill: `name` is required.");
|
|
@@ -19822,7 +20047,7 @@ function createCounterBudgetTracker(options = {}) {
|
|
|
19822
20047
|
}
|
|
19823
20048
|
|
|
19824
20049
|
// src/internal/runtime/context/replay-history.ts
|
|
19825
|
-
var
|
|
20050
|
+
var CHARS_PER_TOKEN2 = 4;
|
|
19826
20051
|
var DEFAULT_RESERVE_TOKENS = 8e3;
|
|
19827
20052
|
function finiteOr(value, fallback) {
|
|
19828
20053
|
return Number.isFinite(value) ? value : fallback;
|
|
@@ -19830,7 +20055,7 @@ function finiteOr(value, fallback) {
|
|
|
19830
20055
|
function charBudget(options) {
|
|
19831
20056
|
const window = finiteOr(options.contextWindowTokens, 0);
|
|
19832
20057
|
const reserve = finiteOr(options.reserveTokens ?? DEFAULT_RESERVE_TOKENS, DEFAULT_RESERVE_TOKENS);
|
|
19833
|
-
return Math.max(0, window - reserve) *
|
|
20058
|
+
return Math.max(0, window - reserve) * CHARS_PER_TOKEN2;
|
|
19834
20059
|
}
|
|
19835
20060
|
function assistantText2(event) {
|
|
19836
20061
|
return event.message.content.filter((block) => block.type === "text").map((block) => block.text).join("");
|
|
@@ -21542,11 +21767,14 @@ exports.createPermissionPlugin = createPermissionPlugin;
|
|
|
21542
21767
|
exports.createSessionManager = createSessionManager;
|
|
21543
21768
|
exports.createSkill = createSkill;
|
|
21544
21769
|
exports.createSquad = createSquad;
|
|
21770
|
+
exports.createTokenLimiter = createTokenLimiter;
|
|
21771
|
+
exports.createUnicodeNormalizer = createUnicodeNormalizer;
|
|
21545
21772
|
exports.definePlugin = definePlugin;
|
|
21546
21773
|
exports.defineProvider = defineProvider;
|
|
21547
21774
|
exports.defineSkillReadTool = defineSkillReadTool;
|
|
21548
21775
|
exports.defineTool = defineTool;
|
|
21549
21776
|
exports.emitRunEvent = emitRunEvent;
|
|
21777
|
+
exports.estimateTokens = estimateTokens;
|
|
21550
21778
|
exports.extractRawId = extractRawId;
|
|
21551
21779
|
exports.getPricingEntry = getPricingEntry;
|
|
21552
21780
|
exports.inferApiMode = inferApiMode;
|