@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/a2a/index.js
CHANGED
|
@@ -3451,8 +3451,18 @@ function validateCloudToolParity(options) {
|
|
|
3451
3451
|
if (options.cloud === void 0) return;
|
|
3452
3452
|
rejectFunctionSystemPrompt(options);
|
|
3453
3453
|
rejectFunctionSkills(options);
|
|
3454
|
+
rejectProcessors(options);
|
|
3454
3455
|
rejectStdioMcpLocalPaths(options);
|
|
3455
3456
|
}
|
|
3457
|
+
function rejectProcessors(options) {
|
|
3458
|
+
const hasProcessors = (options.inputProcessors?.length ?? 0) > 0 || (options.outputProcessors?.length ?? 0) > 0;
|
|
3459
|
+
if (hasProcessors) {
|
|
3460
|
+
throw new ConfigurationError(
|
|
3461
|
+
"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.",
|
|
3462
|
+
{ code: "cloud_incompatible_function_resolver" }
|
|
3463
|
+
);
|
|
3464
|
+
}
|
|
3465
|
+
}
|
|
3456
3466
|
function rejectFunctionSystemPrompt(options) {
|
|
3457
3467
|
if (typeof options.systemPrompt === "function") {
|
|
3458
3468
|
throw new ConfigurationError(
|
|
@@ -16353,6 +16363,162 @@ var init_abort_utils = __esm({
|
|
|
16353
16363
|
}
|
|
16354
16364
|
});
|
|
16355
16365
|
|
|
16366
|
+
// src/internal/runtime/processors/run-processors.ts
|
|
16367
|
+
function fireViolation(processor, violation) {
|
|
16368
|
+
try {
|
|
16369
|
+
processor.onViolation?.(violation);
|
|
16370
|
+
} catch {
|
|
16371
|
+
}
|
|
16372
|
+
}
|
|
16373
|
+
function controlsFor(processor) {
|
|
16374
|
+
return {
|
|
16375
|
+
abort(reason) {
|
|
16376
|
+
throw new ProcessorAbort(processor.id, reason);
|
|
16377
|
+
},
|
|
16378
|
+
warn(message, detail) {
|
|
16379
|
+
fireViolation(processor, {
|
|
16380
|
+
processorId: processor.id,
|
|
16381
|
+
message,
|
|
16382
|
+
...detail !== void 0 ? { detail } : {}
|
|
16383
|
+
});
|
|
16384
|
+
}
|
|
16385
|
+
};
|
|
16386
|
+
}
|
|
16387
|
+
function selectHandler(processor, phase) {
|
|
16388
|
+
if (phase === "input") {
|
|
16389
|
+
return processor.processInput ? { kind: "input", fn: processor.processInput } : void 0;
|
|
16390
|
+
}
|
|
16391
|
+
return processor.processOutput ? { kind: "output", fn: processor.processOutput } : void 0;
|
|
16392
|
+
}
|
|
16393
|
+
function invokeHandler(handler, value, agentId, controls) {
|
|
16394
|
+
return handler.kind === "input" ? handler.fn({ message: value, agentId, ...controls }) : handler.fn({ text: value, agentId, ...controls });
|
|
16395
|
+
}
|
|
16396
|
+
async function runOneProcessor(processor, value, agentId, phase) {
|
|
16397
|
+
const handler = selectHandler(processor, phase);
|
|
16398
|
+
if (handler === void 0) return { value };
|
|
16399
|
+
try {
|
|
16400
|
+
const out = await invokeHandler(handler, value, agentId, controlsFor(processor));
|
|
16401
|
+
return { value: typeof out === "string" ? out : value };
|
|
16402
|
+
} catch (err) {
|
|
16403
|
+
if (!(err instanceof ProcessorAbort)) throw err;
|
|
16404
|
+
fireViolation(processor, { processorId: err.processorId, message: err.reason });
|
|
16405
|
+
return { tripwire: { reason: err.reason, processorId: err.processorId } };
|
|
16406
|
+
}
|
|
16407
|
+
}
|
|
16408
|
+
async function runPipeline(processors, initial, agentId, phase) {
|
|
16409
|
+
let value = initial;
|
|
16410
|
+
for (const processor of processors) {
|
|
16411
|
+
const step = await runOneProcessor(processor, value, agentId, phase);
|
|
16412
|
+
if ("tripwire" in step) return { kind: "tripwire", tripwire: step.tripwire };
|
|
16413
|
+
value = step.value;
|
|
16414
|
+
}
|
|
16415
|
+
return { kind: "ok", value };
|
|
16416
|
+
}
|
|
16417
|
+
function runInputProcessors(processors, message, agentId) {
|
|
16418
|
+
return runPipeline(processors, message, agentId, "input");
|
|
16419
|
+
}
|
|
16420
|
+
function runOutputProcessors(processors, text, agentId) {
|
|
16421
|
+
return runPipeline(processors, text, agentId, "output");
|
|
16422
|
+
}
|
|
16423
|
+
var ProcessorAbort;
|
|
16424
|
+
var init_run_processors = __esm({
|
|
16425
|
+
"src/internal/runtime/processors/run-processors.ts"() {
|
|
16426
|
+
ProcessorAbort = class {
|
|
16427
|
+
constructor(processorId, reason) {
|
|
16428
|
+
this.processorId = processorId;
|
|
16429
|
+
this.reason = reason;
|
|
16430
|
+
}
|
|
16431
|
+
processorId;
|
|
16432
|
+
reason;
|
|
16433
|
+
};
|
|
16434
|
+
}
|
|
16435
|
+
});
|
|
16436
|
+
|
|
16437
|
+
// src/internal/runtime/processors/tripwire-run.ts
|
|
16438
|
+
function emptyStream() {
|
|
16439
|
+
return {
|
|
16440
|
+
next: () => Promise.resolve({ done: true, value: void 0 }),
|
|
16441
|
+
return: () => Promise.resolve({ done: true, value: void 0 }),
|
|
16442
|
+
throw: (err) => Promise.reject(err),
|
|
16443
|
+
[Symbol.asyncIterator]() {
|
|
16444
|
+
return this;
|
|
16445
|
+
}
|
|
16446
|
+
};
|
|
16447
|
+
}
|
|
16448
|
+
function createTripwireRun(args) {
|
|
16449
|
+
const id = globalThis.crypto.randomUUID();
|
|
16450
|
+
const result = {
|
|
16451
|
+
id,
|
|
16452
|
+
status: "cancelled",
|
|
16453
|
+
tripwire: args.tripwire,
|
|
16454
|
+
...args.model !== void 0 ? { model: args.model } : {}
|
|
16455
|
+
};
|
|
16456
|
+
const run = {
|
|
16457
|
+
id,
|
|
16458
|
+
agentId: args.agentId,
|
|
16459
|
+
status: "cancelled",
|
|
16460
|
+
...args.model !== void 0 ? { model: args.model } : {},
|
|
16461
|
+
stream: () => emptyStream(),
|
|
16462
|
+
wait: () => Promise.resolve(result),
|
|
16463
|
+
cancel: () => Promise.resolve(),
|
|
16464
|
+
conversation: () => Promise.resolve([]),
|
|
16465
|
+
supports: (op) => SUPPORTED.has(op),
|
|
16466
|
+
unsupportedReason: (op) => SUPPORTED.has(op) ? void 0 : `operation "${op}" is not available on a tripwire run`,
|
|
16467
|
+
onDidChangeStatus: () => () => {
|
|
16468
|
+
}
|
|
16469
|
+
// already terminal — status never changes
|
|
16470
|
+
};
|
|
16471
|
+
registerRun(run);
|
|
16472
|
+
return run;
|
|
16473
|
+
}
|
|
16474
|
+
var SUPPORTED;
|
|
16475
|
+
var init_tripwire_run = __esm({
|
|
16476
|
+
"src/internal/runtime/processors/tripwire-run.ts"() {
|
|
16477
|
+
init_run_registry();
|
|
16478
|
+
SUPPORTED = /* @__PURE__ */ new Set([
|
|
16479
|
+
"stream",
|
|
16480
|
+
"wait",
|
|
16481
|
+
"cancel",
|
|
16482
|
+
"conversation"
|
|
16483
|
+
]);
|
|
16484
|
+
}
|
|
16485
|
+
});
|
|
16486
|
+
|
|
16487
|
+
// src/internal/runtime/processors/wrap-output-run.ts
|
|
16488
|
+
function wrapRunWithOutputProcessors(args) {
|
|
16489
|
+
if (args.processors.length === 0) return args.run;
|
|
16490
|
+
const compute = async () => {
|
|
16491
|
+
const result = await args.run.wait();
|
|
16492
|
+
if (result.status !== "finished" || result.result === void 0) return result;
|
|
16493
|
+
const res = await runOutputProcessors(args.processors, result.result, args.agentId);
|
|
16494
|
+
if (res.kind === "ok") return { ...result, result: res.value };
|
|
16495
|
+
emitRunEvent(args.onRunEvent, {
|
|
16496
|
+
type: "tripwire",
|
|
16497
|
+
reason: res.tripwire.reason,
|
|
16498
|
+
processorId: res.tripwire.processorId
|
|
16499
|
+
});
|
|
16500
|
+
const { result: _suppressed, ...metadata } = result;
|
|
16501
|
+
return { ...metadata, status: "cancelled", tripwire: res.tripwire };
|
|
16502
|
+
};
|
|
16503
|
+
let processed;
|
|
16504
|
+
const wrappedWait = () => {
|
|
16505
|
+
processed ??= compute();
|
|
16506
|
+
return processed;
|
|
16507
|
+
};
|
|
16508
|
+
return new Proxy(args.run, {
|
|
16509
|
+
get(target, prop, receiver) {
|
|
16510
|
+
if (prop === "wait") return wrappedWait;
|
|
16511
|
+
return Reflect.get(target, prop, receiver);
|
|
16512
|
+
}
|
|
16513
|
+
});
|
|
16514
|
+
}
|
|
16515
|
+
var init_wrap_output_run = __esm({
|
|
16516
|
+
"src/internal/runtime/processors/wrap-output-run.ts"() {
|
|
16517
|
+
init_run_events();
|
|
16518
|
+
init_run_processors();
|
|
16519
|
+
}
|
|
16520
|
+
});
|
|
16521
|
+
|
|
16356
16522
|
// src/internal/runtime/local-agent/local-agent-memory-hooks.ts
|
|
16357
16523
|
async function applyPreUserSendHook(args) {
|
|
16358
16524
|
const handlers = args.pluginManager.hooksFor("pre_user_send");
|
|
@@ -16405,11 +16571,38 @@ var init_local_agent_memory_hooks = __esm({
|
|
|
16405
16571
|
});
|
|
16406
16572
|
|
|
16407
16573
|
// src/internal/runtime/local-agent/local-agent-send.ts
|
|
16574
|
+
async function applyInputProcessors(inputs, message, rawUserText, options, sendModel) {
|
|
16575
|
+
const processors = inputs.options.inputProcessors;
|
|
16576
|
+
if (processors === void 0 || processors.length === 0) {
|
|
16577
|
+
return { userText: rawUserText, effectiveMessage: message };
|
|
16578
|
+
}
|
|
16579
|
+
const res = await runInputProcessors(processors, rawUserText, inputs.agentId);
|
|
16580
|
+
if (res.kind === "tripwire") {
|
|
16581
|
+
emitRunEvent(options.onRunEvent, {
|
|
16582
|
+
type: "tripwire",
|
|
16583
|
+
reason: res.tripwire.reason,
|
|
16584
|
+
processorId: res.tripwire.processorId
|
|
16585
|
+
});
|
|
16586
|
+
return {
|
|
16587
|
+
tripwireRun: createTripwireRun({
|
|
16588
|
+
agentId: inputs.agentId,
|
|
16589
|
+
tripwire: res.tripwire,
|
|
16590
|
+
model: sendModel
|
|
16591
|
+
})
|
|
16592
|
+
};
|
|
16593
|
+
}
|
|
16594
|
+
const effectiveMessage = typeof message === "string" ? res.value : { ...message, text: res.value };
|
|
16595
|
+
return { userText: res.value, effectiveMessage };
|
|
16596
|
+
}
|
|
16408
16597
|
async function executeSendLocked(inputs, message, options) {
|
|
16409
16598
|
if (inputs.disposed) throw new AgentDisposedError(inputs.agentId);
|
|
16410
16599
|
await consumePending(inputs.agentId, inputs.invalidationPending, inputs.clearInvalidation, inputs.reload);
|
|
16411
|
-
|
|
16412
|
-
|
|
16600
|
+
const sendModel = normalizeModel(options.model);
|
|
16601
|
+
inputs.applyModelOverride(sendModel);
|
|
16602
|
+
const rawUserText = typeof message === "string" ? message : message.text;
|
|
16603
|
+
const gated = await applyInputProcessors(inputs, message, rawUserText, options, sendModel);
|
|
16604
|
+
if ("tripwireRun" in gated) return gated.tripwireRun;
|
|
16605
|
+
const { userText, effectiveMessage } = gated;
|
|
16413
16606
|
if (inputs.options.onBeforeSend !== void 0) {
|
|
16414
16607
|
await inputs.options.onBeforeSend({
|
|
16415
16608
|
conversationId: inputs.agentId,
|
|
@@ -16421,7 +16614,7 @@ async function executeSendLocked(inputs, message, options) {
|
|
|
16421
16614
|
pluginManager: inputs.pluginManagerCode,
|
|
16422
16615
|
agentId: inputs.agentId,
|
|
16423
16616
|
options: inputs.options,
|
|
16424
|
-
original:
|
|
16617
|
+
original: effectiveMessage,
|
|
16425
16618
|
userText,
|
|
16426
16619
|
sendOptions: options
|
|
16427
16620
|
});
|
|
@@ -16459,11 +16652,18 @@ async function executeSendLocked(inputs, message, options) {
|
|
|
16459
16652
|
memoryTools,
|
|
16460
16653
|
effectiveMemoryProvider
|
|
16461
16654
|
);
|
|
16655
|
+
const outputProcessors = inputs.options.outputProcessors;
|
|
16656
|
+
const processedRun = outputProcessors !== void 0 && outputProcessors.length > 0 ? wrapRunWithOutputProcessors({
|
|
16657
|
+
run,
|
|
16658
|
+
processors: outputProcessors,
|
|
16659
|
+
agentId: inputs.agentId,
|
|
16660
|
+
onRunEvent: options.onRunEvent
|
|
16661
|
+
}) : run;
|
|
16462
16662
|
return wrapRunWithPostReplyHook({
|
|
16463
16663
|
pluginManager: inputs.pluginManagerCode,
|
|
16464
16664
|
agentId: inputs.agentId,
|
|
16465
16665
|
options: inputs.options,
|
|
16466
|
-
run,
|
|
16666
|
+
run: processedRun,
|
|
16467
16667
|
userText
|
|
16468
16668
|
});
|
|
16469
16669
|
}
|
|
@@ -16474,10 +16674,14 @@ function readMemoryForSend(workspaceCwd, memoryConfig) {
|
|
|
16474
16674
|
var init_local_agent_send = __esm({
|
|
16475
16675
|
"src/internal/runtime/local-agent/local-agent-send.ts"() {
|
|
16476
16676
|
init_errors();
|
|
16677
|
+
init_run_events();
|
|
16477
16678
|
init_abort_utils();
|
|
16478
16679
|
init_memory_path_selector();
|
|
16479
16680
|
init_memory_store();
|
|
16480
16681
|
init_model_selection();
|
|
16682
|
+
init_run_processors();
|
|
16683
|
+
init_tripwire_run();
|
|
16684
|
+
init_wrap_output_run();
|
|
16481
16685
|
init_agent_session();
|
|
16482
16686
|
init_safe_call();
|
|
16483
16687
|
init_local_agent_invalidate();
|