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