@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/cron.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import './run-
|
|
2
|
-
export { R as Cron } from './cron-
|
|
1
|
+
import './run-CdWiihyU.cjs';
|
|
2
|
+
export { R as Cron } from './cron-BR1NCSk1.cjs';
|
|
3
3
|
import 'zod';
|
package/dist/cron.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import './run-
|
|
2
|
-
export { R as Cron } from './cron-
|
|
1
|
+
import './run-CdWiihyU.js';
|
|
2
|
+
export { R as Cron } from './cron-DgEQCJ2i.js';
|
|
3
3
|
import 'zod';
|
package/dist/cron.js
CHANGED
|
@@ -5241,8 +5241,18 @@ function validateCloudToolParity(options) {
|
|
|
5241
5241
|
if (options.cloud === void 0) return;
|
|
5242
5242
|
rejectFunctionSystemPrompt(options);
|
|
5243
5243
|
rejectFunctionSkills(options);
|
|
5244
|
+
rejectProcessors(options);
|
|
5244
5245
|
rejectStdioMcpLocalPaths(options);
|
|
5245
5246
|
}
|
|
5247
|
+
function rejectProcessors(options) {
|
|
5248
|
+
const hasProcessors = (options.inputProcessors?.length ?? 0) > 0 || (options.outputProcessors?.length ?? 0) > 0;
|
|
5249
|
+
if (hasProcessors) {
|
|
5250
|
+
throw new ConfigurationError(
|
|
5251
|
+
"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.",
|
|
5252
|
+
{ code: "cloud_incompatible_function_resolver" }
|
|
5253
|
+
);
|
|
5254
|
+
}
|
|
5255
|
+
}
|
|
5246
5256
|
function rejectFunctionSystemPrompt(options) {
|
|
5247
5257
|
if (typeof options.systemPrompt === "function") {
|
|
5248
5258
|
throw new ConfigurationError(
|
|
@@ -16141,6 +16151,145 @@ function ponyfillAny(signals) {
|
|
|
16141
16151
|
return ctrl.signal;
|
|
16142
16152
|
}
|
|
16143
16153
|
|
|
16154
|
+
// src/internal/runtime/processors/run-processors.ts
|
|
16155
|
+
var ProcessorAbort = class {
|
|
16156
|
+
constructor(processorId, reason) {
|
|
16157
|
+
this.processorId = processorId;
|
|
16158
|
+
this.reason = reason;
|
|
16159
|
+
}
|
|
16160
|
+
processorId;
|
|
16161
|
+
reason;
|
|
16162
|
+
};
|
|
16163
|
+
function fireViolation(processor, violation) {
|
|
16164
|
+
try {
|
|
16165
|
+
processor.onViolation?.(violation);
|
|
16166
|
+
} catch {
|
|
16167
|
+
}
|
|
16168
|
+
}
|
|
16169
|
+
function controlsFor(processor) {
|
|
16170
|
+
return {
|
|
16171
|
+
abort(reason) {
|
|
16172
|
+
throw new ProcessorAbort(processor.id, reason);
|
|
16173
|
+
},
|
|
16174
|
+
warn(message, detail) {
|
|
16175
|
+
fireViolation(processor, {
|
|
16176
|
+
processorId: processor.id,
|
|
16177
|
+
message,
|
|
16178
|
+
...detail !== void 0 ? { detail } : {}
|
|
16179
|
+
});
|
|
16180
|
+
}
|
|
16181
|
+
};
|
|
16182
|
+
}
|
|
16183
|
+
function selectHandler(processor, phase) {
|
|
16184
|
+
if (phase === "input") {
|
|
16185
|
+
return processor.processInput ? { kind: "input", fn: processor.processInput } : void 0;
|
|
16186
|
+
}
|
|
16187
|
+
return processor.processOutput ? { kind: "output", fn: processor.processOutput } : void 0;
|
|
16188
|
+
}
|
|
16189
|
+
function invokeHandler(handler, value, agentId, controls) {
|
|
16190
|
+
return handler.kind === "input" ? handler.fn({ message: value, agentId, ...controls }) : handler.fn({ text: value, agentId, ...controls });
|
|
16191
|
+
}
|
|
16192
|
+
async function runOneProcessor(processor, value, agentId, phase) {
|
|
16193
|
+
const handler = selectHandler(processor, phase);
|
|
16194
|
+
if (handler === void 0) return { value };
|
|
16195
|
+
try {
|
|
16196
|
+
const out = await invokeHandler(handler, value, agentId, controlsFor(processor));
|
|
16197
|
+
return { value: typeof out === "string" ? out : value };
|
|
16198
|
+
} catch (err) {
|
|
16199
|
+
if (!(err instanceof ProcessorAbort)) throw err;
|
|
16200
|
+
fireViolation(processor, { processorId: err.processorId, message: err.reason });
|
|
16201
|
+
return { tripwire: { reason: err.reason, processorId: err.processorId } };
|
|
16202
|
+
}
|
|
16203
|
+
}
|
|
16204
|
+
async function runPipeline(processors, initial, agentId, phase) {
|
|
16205
|
+
let value = initial;
|
|
16206
|
+
for (const processor of processors) {
|
|
16207
|
+
const step = await runOneProcessor(processor, value, agentId, phase);
|
|
16208
|
+
if ("tripwire" in step) return { kind: "tripwire", tripwire: step.tripwire };
|
|
16209
|
+
value = step.value;
|
|
16210
|
+
}
|
|
16211
|
+
return { kind: "ok", value };
|
|
16212
|
+
}
|
|
16213
|
+
function runInputProcessors(processors, message, agentId) {
|
|
16214
|
+
return runPipeline(processors, message, agentId, "input");
|
|
16215
|
+
}
|
|
16216
|
+
function runOutputProcessors(processors, text, agentId) {
|
|
16217
|
+
return runPipeline(processors, text, agentId, "output");
|
|
16218
|
+
}
|
|
16219
|
+
|
|
16220
|
+
// src/internal/runtime/processors/tripwire-run.ts
|
|
16221
|
+
var SUPPORTED = /* @__PURE__ */ new Set([
|
|
16222
|
+
"stream",
|
|
16223
|
+
"wait",
|
|
16224
|
+
"cancel",
|
|
16225
|
+
"conversation"
|
|
16226
|
+
]);
|
|
16227
|
+
function emptyStream() {
|
|
16228
|
+
return {
|
|
16229
|
+
next: () => Promise.resolve({ done: true, value: void 0 }),
|
|
16230
|
+
return: () => Promise.resolve({ done: true, value: void 0 }),
|
|
16231
|
+
throw: (err) => Promise.reject(err),
|
|
16232
|
+
[Symbol.asyncIterator]() {
|
|
16233
|
+
return this;
|
|
16234
|
+
}
|
|
16235
|
+
};
|
|
16236
|
+
}
|
|
16237
|
+
function createTripwireRun(args) {
|
|
16238
|
+
const id = globalThis.crypto.randomUUID();
|
|
16239
|
+
const result = {
|
|
16240
|
+
id,
|
|
16241
|
+
status: "cancelled",
|
|
16242
|
+
tripwire: args.tripwire,
|
|
16243
|
+
...args.model !== void 0 ? { model: args.model } : {}
|
|
16244
|
+
};
|
|
16245
|
+
const run = {
|
|
16246
|
+
id,
|
|
16247
|
+
agentId: args.agentId,
|
|
16248
|
+
status: "cancelled",
|
|
16249
|
+
...args.model !== void 0 ? { model: args.model } : {},
|
|
16250
|
+
stream: () => emptyStream(),
|
|
16251
|
+
wait: () => Promise.resolve(result),
|
|
16252
|
+
cancel: () => Promise.resolve(),
|
|
16253
|
+
conversation: () => Promise.resolve([]),
|
|
16254
|
+
supports: (op) => SUPPORTED.has(op),
|
|
16255
|
+
unsupportedReason: (op) => SUPPORTED.has(op) ? void 0 : `operation "${op}" is not available on a tripwire run`,
|
|
16256
|
+
onDidChangeStatus: () => () => {
|
|
16257
|
+
}
|
|
16258
|
+
// already terminal — status never changes
|
|
16259
|
+
};
|
|
16260
|
+
registerRun(run);
|
|
16261
|
+
return run;
|
|
16262
|
+
}
|
|
16263
|
+
|
|
16264
|
+
// src/internal/runtime/processors/wrap-output-run.ts
|
|
16265
|
+
function wrapRunWithOutputProcessors(args) {
|
|
16266
|
+
if (args.processors.length === 0) return args.run;
|
|
16267
|
+
const compute = async () => {
|
|
16268
|
+
const result = await args.run.wait();
|
|
16269
|
+
if (result.status !== "finished" || result.result === void 0) return result;
|
|
16270
|
+
const res = await runOutputProcessors(args.processors, result.result, args.agentId);
|
|
16271
|
+
if (res.kind === "ok") return { ...result, result: res.value };
|
|
16272
|
+
emitRunEvent(args.onRunEvent, {
|
|
16273
|
+
type: "tripwire",
|
|
16274
|
+
reason: res.tripwire.reason,
|
|
16275
|
+
processorId: res.tripwire.processorId
|
|
16276
|
+
});
|
|
16277
|
+
const { result: _suppressed, ...metadata } = result;
|
|
16278
|
+
return { ...metadata, status: "cancelled", tripwire: res.tripwire };
|
|
16279
|
+
};
|
|
16280
|
+
let processed;
|
|
16281
|
+
const wrappedWait = () => {
|
|
16282
|
+
processed ??= compute();
|
|
16283
|
+
return processed;
|
|
16284
|
+
};
|
|
16285
|
+
return new Proxy(args.run, {
|
|
16286
|
+
get(target, prop, receiver) {
|
|
16287
|
+
if (prop === "wait") return wrappedWait;
|
|
16288
|
+
return Reflect.get(target, prop, receiver);
|
|
16289
|
+
}
|
|
16290
|
+
});
|
|
16291
|
+
}
|
|
16292
|
+
|
|
16144
16293
|
// src/internal/runtime/local-agent/local-agent-memory-hooks.ts
|
|
16145
16294
|
var DEFAULT_MAX_RECALL_BYTES = 16e3;
|
|
16146
16295
|
async function applyPreUserSendHook(args) {
|
|
@@ -16188,11 +16337,38 @@ function wrapRunWithPostReplyHook(args) {
|
|
|
16188
16337
|
}
|
|
16189
16338
|
|
|
16190
16339
|
// src/internal/runtime/local-agent/local-agent-send.ts
|
|
16340
|
+
async function applyInputProcessors(inputs, message, rawUserText, options, sendModel) {
|
|
16341
|
+
const processors = inputs.options.inputProcessors;
|
|
16342
|
+
if (processors === void 0 || processors.length === 0) {
|
|
16343
|
+
return { userText: rawUserText, effectiveMessage: message };
|
|
16344
|
+
}
|
|
16345
|
+
const res = await runInputProcessors(processors, rawUserText, inputs.agentId);
|
|
16346
|
+
if (res.kind === "tripwire") {
|
|
16347
|
+
emitRunEvent(options.onRunEvent, {
|
|
16348
|
+
type: "tripwire",
|
|
16349
|
+
reason: res.tripwire.reason,
|
|
16350
|
+
processorId: res.tripwire.processorId
|
|
16351
|
+
});
|
|
16352
|
+
return {
|
|
16353
|
+
tripwireRun: createTripwireRun({
|
|
16354
|
+
agentId: inputs.agentId,
|
|
16355
|
+
tripwire: res.tripwire,
|
|
16356
|
+
model: sendModel
|
|
16357
|
+
})
|
|
16358
|
+
};
|
|
16359
|
+
}
|
|
16360
|
+
const effectiveMessage = typeof message === "string" ? res.value : { ...message, text: res.value };
|
|
16361
|
+
return { userText: res.value, effectiveMessage };
|
|
16362
|
+
}
|
|
16191
16363
|
async function executeSendLocked(inputs, message, options) {
|
|
16192
16364
|
if (inputs.disposed) throw new AgentDisposedError(inputs.agentId);
|
|
16193
16365
|
await consumePending(inputs.agentId, inputs.invalidationPending, inputs.clearInvalidation, inputs.reload);
|
|
16194
|
-
|
|
16195
|
-
|
|
16366
|
+
const sendModel = normalizeModel(options.model);
|
|
16367
|
+
inputs.applyModelOverride(sendModel);
|
|
16368
|
+
const rawUserText = typeof message === "string" ? message : message.text;
|
|
16369
|
+
const gated = await applyInputProcessors(inputs, message, rawUserText, options, sendModel);
|
|
16370
|
+
if ("tripwireRun" in gated) return gated.tripwireRun;
|
|
16371
|
+
const { userText, effectiveMessage } = gated;
|
|
16196
16372
|
if (inputs.options.onBeforeSend !== void 0) {
|
|
16197
16373
|
await inputs.options.onBeforeSend({
|
|
16198
16374
|
conversationId: inputs.agentId,
|
|
@@ -16204,7 +16380,7 @@ async function executeSendLocked(inputs, message, options) {
|
|
|
16204
16380
|
pluginManager: inputs.pluginManagerCode,
|
|
16205
16381
|
agentId: inputs.agentId,
|
|
16206
16382
|
options: inputs.options,
|
|
16207
|
-
original:
|
|
16383
|
+
original: effectiveMessage,
|
|
16208
16384
|
userText,
|
|
16209
16385
|
sendOptions: options
|
|
16210
16386
|
});
|
|
@@ -16242,11 +16418,18 @@ async function executeSendLocked(inputs, message, options) {
|
|
|
16242
16418
|
memoryTools,
|
|
16243
16419
|
effectiveMemoryProvider
|
|
16244
16420
|
);
|
|
16421
|
+
const outputProcessors = inputs.options.outputProcessors;
|
|
16422
|
+
const processedRun = outputProcessors !== void 0 && outputProcessors.length > 0 ? wrapRunWithOutputProcessors({
|
|
16423
|
+
run,
|
|
16424
|
+
processors: outputProcessors,
|
|
16425
|
+
agentId: inputs.agentId,
|
|
16426
|
+
onRunEvent: options.onRunEvent
|
|
16427
|
+
}) : run;
|
|
16245
16428
|
return wrapRunWithPostReplyHook({
|
|
16246
16429
|
pluginManager: inputs.pluginManagerCode,
|
|
16247
16430
|
agentId: inputs.agentId,
|
|
16248
16431
|
options: inputs.options,
|
|
16249
|
-
run,
|
|
16432
|
+
run: processedRun,
|
|
16250
16433
|
userText
|
|
16251
16434
|
});
|
|
16252
16435
|
}
|