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