@theokit/sdk 2.22.0 → 2.24.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 +52 -0
- package/dist/a2a/index.cjs +43 -15
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +43 -15
- package/dist/a2a/index.js.map +1 -1
- package/dist/a2a/subagent.d.cts +27 -2
- package/dist/a2a/subagent.d.ts +27 -2
- package/dist/{cron-Bpt_1khA.d.cts → cron-Bd2oRD7A.d.cts} +1 -1
- package/dist/{cron-7CruUd_0.d.ts → cron-vjod0qVQ.d.ts} +1 -1
- package/dist/cron.cjs +3 -1
- 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 +3 -1
- package/dist/cron.js.map +1 -1
- package/dist/define-tool.d.ts +33 -20
- package/dist/{errors-CkCaIqVP.d.cts → errors-DIKBXffg.d.cts} +1 -1
- package/dist/{errors-BuwwkrAk.d.ts → errors-DRS-kqOK.d.ts} +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/eval.cjs +3 -1
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +3 -1
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +10 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -26
- package/dist/index.d.ts +37 -26
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/{run-CrIulPF7.d.cts → run-Cr0C6cOM.d.cts} +17 -0
- package/dist/{run-CrIulPF7.d.ts → run-Cr0C6cOM.d.ts} +17 -0
- package/dist/types/run.d.ts +17 -0
- package/dist/workflow.cjs +37 -0
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +47 -1
- package/dist/workflow.d.ts +47 -1
- package/dist/workflow.js +37 -2
- package/dist/workflow.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { T as TheokitAgentError, B as BudgetOptions, a as BudgetHandle, b as BudgetSnapshot, E as ErrorMetadata } from './errors-
|
|
2
|
-
export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, f as BudgetExceedEvent, g as BudgetExceededError, h as BudgetLimit, i as BudgetMode, j as BudgetScope, k as BudgetThresholdEvent, l as BudgetWindow, C as ConfigurationError, m as ErrorCode, I as IntegrationNotConnectedError, n as InvalidTaskIdError, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-
|
|
3
|
-
import { A as AgentOptions, L as LocalOptions, P as ProviderRoutingSettings, S as SystemPromptResolver, C as CloudOptions, M as MemorySettings, a as AgentDefinition, b as ContextSettings, c as PluginsSettings, d as SkillsSettings, e as SDKAgent, f as ListAgentsOptions, g as ListResult, h as SDKAgentInfo, G as GetAgentOptions, i as ListRunsOptions, j as GetRunOptions, k as AgentOperationOptions, l as ProviderProfile, m as Plugin, n as ConversationStorageAdapter, o as StoredMessage, p as SessionMeta, q as SessionMetaPatch, B as BudgetTracker, r as MemoryProvider, s as MemoryId, t as PreToolCallDecision, u as SDKProvider } from './cron-
|
|
4
|
-
export { v as ActiveMemoryPassArgs, w as ActiveMemoryPassResult, x as AgentMemory, y as BudgetCheck, z as BudgetTotal, D as BudgetUsageEvent, E as CloudEnv, F as CloudRepo, H as ContextBudget, I as ContextManagerKind, J as ContextSnapshot, K as ContextSource, N as ContextSourceStatus, O as CreateSkillSpec, Q as Cron, R as CronCreateOptions, T as CronGetOptions, U as CronJob, V as CronJobStatus, W as CronListOptions, X as CronOperationOptions, Y as CronRunOptions, Z as CronRuntime, _ as CronSchedulerStatus, $ as CronStartOptions, a0 as GoalEvent, a1 as GoalOptions, a2 as GoalResult, a3 as HookName, a4 as InlineSkill, a5 as InvalidateCacheOptions, a6 as MemoryAdapter, a7 as MemoryAdapterCapabilities, a8 as MemoryContext, a9 as MemoryFact, aa as MemoryProviderHandle, ab as MemoryProviderInitOptions, ac as MemoryRevision, ad as MemoryToolSchema, ae as MemoryTurnMessage, af as PersonalityPreset, ag as PluginContext, ah as PostAssistantReplyContext, ai as PreToolCallContext, aj as PreUserSendContext, ak as PreUserSendResult, al as ProviderCapability, am as ProviderRoute, an as RecordSessionSummaryArgs, ao as ResolvedProviderRoute, ap as RunUntilIterator, aq as SDKAgentPlugins, ar as SDKAgentSkills, as as SDKArtifact, at as SDKContextManager, au as SDKPluginMetadata, av as SDKProvidersManager, aw as SettingSource, ax as SystemPromptContext, ay as SystemPromptMemoryFact, az as SystemPromptSkillRef, aA as TelemetrySettings, aB as createSkill, aC as definePlugin } from './cron-
|
|
5
|
-
import { R as RunResult, M as ModelSelection, C as CustomTool, a as McpServerConfig, b as Run,
|
|
6
|
-
export { A as AgentConversationTurn, d as AssistantMessage, e as ConversationStep, f as ConversationTurn, g as CostBreakdown, h as CostSource, i as CostStatus, D as DoomLoopThresholds, G as GenerateOptions, j as GenerateRunResult, I as ImageBlock, k as InteractionUpdate, l as McpAuthConfig, m as McpHttpServerConfig, n as McpOAuthConfig, o as McpStdioServerConfig, p as ModelParameterValue, P as PartialToolCallUpdate, q as RunCompactBoundaryEvent, r as RunErrorDetail, s as RunEvent, t as RunEventSink, u as RunGitInfo, v as RunOperation, w as RunPermissionDeniedEvent, x as RunRateLimitEvent, y as RunStatus, z as RunTaskCompletedEvent, B as RunTaskStartedEvent, E as RunTaskUpdatedEvent, F as RunToCompletionOptions, H as RunToCompletionResult, J as RunToolProgressEvent, K as SDKAssistantMessage, L as SDKImage, N as SDKImageDimension, O as SDKObjectDelta, Q as SDKRequestMessage, U as SDKStatusMessage, V as SDKSystemMessage, W as SDKTaskMessage, X as SDKThinkingMessage, Y as SDKToolUseMessage, Z as SDKUserMessage, _ as SDKUserMessageEvent, $ as SendOptions, a0 as ShellCommand, a1 as ShellConversationTurn, a2 as ShellOutput, a3 as ShellOutputDeltaUpdate, a4 as StepCompletedUpdate, a5 as StepStartedUpdate, a6 as StreamToCompletionResult, a7 as SummaryCompletedUpdate, a8 as SummaryStartedUpdate, a9 as SummaryUpdate, aa as TextBlock, ab as TextDeltaUpdate, ac as ThinkingCompletedUpdate, ad as ThinkingDeltaUpdate, ae as ThinkingMessage, af as TokenDeltaUpdate, ag as TokenUsage, ah as ToolCall, ai as ToolCallCompletedUpdate, aj as ToolCallStartedUpdate, ak as ToolContextMessage, al as ToolResult, am as ToolResultGuardOptions, an as ToolUseBlock, ao as TurnEndedUpdate, ap as UserMessage, aq as UserMessageAppendedUpdate, ar as emitRunEvent } from './run-
|
|
1
|
+
import { T as TheokitAgentError, B as BudgetOptions, a as BudgetHandle, b as BudgetSnapshot, E as ErrorMetadata } from './errors-DIKBXffg.cjs';
|
|
2
|
+
export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, f as BudgetExceedEvent, g as BudgetExceededError, h as BudgetLimit, i as BudgetMode, j as BudgetScope, k as BudgetThresholdEvent, l as BudgetWindow, C as ConfigurationError, m as ErrorCode, I as IntegrationNotConnectedError, n as InvalidTaskIdError, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-DIKBXffg.cjs';
|
|
3
|
+
import { A as AgentOptions, L as LocalOptions, P as ProviderRoutingSettings, S as SystemPromptResolver, C as CloudOptions, M as MemorySettings, a as AgentDefinition, b as ContextSettings, c as PluginsSettings, d as SkillsSettings, e as SDKAgent, f as ListAgentsOptions, g as ListResult, h as SDKAgentInfo, G as GetAgentOptions, i as ListRunsOptions, j as GetRunOptions, k as AgentOperationOptions, l as ProviderProfile, m as Plugin, n as ConversationStorageAdapter, o as StoredMessage, p as SessionMeta, q as SessionMetaPatch, B as BudgetTracker, r as MemoryProvider, s as MemoryId, t as PreToolCallDecision, u as SDKProvider } from './cron-Bd2oRD7A.cjs';
|
|
4
|
+
export { v as ActiveMemoryPassArgs, w as ActiveMemoryPassResult, x as AgentMemory, y as BudgetCheck, z as BudgetTotal, D as BudgetUsageEvent, E as CloudEnv, F as CloudRepo, H as ContextBudget, I as ContextManagerKind, J as ContextSnapshot, K as ContextSource, N as ContextSourceStatus, O as CreateSkillSpec, Q as Cron, R as CronCreateOptions, T as CronGetOptions, U as CronJob, V as CronJobStatus, W as CronListOptions, X as CronOperationOptions, Y as CronRunOptions, Z as CronRuntime, _ as CronSchedulerStatus, $ as CronStartOptions, a0 as GoalEvent, a1 as GoalOptions, a2 as GoalResult, a3 as HookName, a4 as InlineSkill, a5 as InvalidateCacheOptions, a6 as MemoryAdapter, a7 as MemoryAdapterCapabilities, a8 as MemoryContext, a9 as MemoryFact, aa as MemoryProviderHandle, ab as MemoryProviderInitOptions, ac as MemoryRevision, ad as MemoryToolSchema, ae as MemoryTurnMessage, af as PersonalityPreset, ag as PluginContext, ah as PostAssistantReplyContext, ai as PreToolCallContext, aj as PreUserSendContext, ak as PreUserSendResult, al as ProviderCapability, am as ProviderRoute, an as RecordSessionSummaryArgs, ao as ResolvedProviderRoute, ap as RunUntilIterator, aq as SDKAgentPlugins, ar as SDKAgentSkills, as as SDKArtifact, at as SDKContextManager, au as SDKPluginMetadata, av as SDKProvidersManager, aw as SettingSource, ax as SystemPromptContext, ay as SystemPromptMemoryFact, az as SystemPromptSkillRef, aA as TelemetrySettings, aB as createSkill, aC as definePlugin } from './cron-Bd2oRD7A.cjs';
|
|
5
|
+
import { R as RunResult, M as ModelSelection, C as CustomTool, a as McpServerConfig, b as Run, T as ToolResultContentBlock, S as SDKMessage, c as MessageOrigin } from './run-Cr0C6cOM.cjs';
|
|
6
|
+
export { A as AgentConversationTurn, d as AssistantMessage, e as ConversationStep, f as ConversationTurn, g as CostBreakdown, h as CostSource, i as CostStatus, D as DoomLoopThresholds, G as GenerateOptions, j as GenerateRunResult, I as ImageBlock, k as InteractionUpdate, l as McpAuthConfig, m as McpHttpServerConfig, n as McpOAuthConfig, o as McpStdioServerConfig, p as ModelParameterValue, P as PartialToolCallUpdate, q as RunCompactBoundaryEvent, r as RunErrorDetail, s as RunEvent, t as RunEventSink, u as RunGitInfo, v as RunOperation, w as RunPermissionDeniedEvent, x as RunRateLimitEvent, y as RunStatus, z as RunTaskCompletedEvent, B as RunTaskStartedEvent, E as RunTaskUpdatedEvent, F as RunToCompletionOptions, H as RunToCompletionResult, J as RunToolProgressEvent, K as SDKAssistantMessage, L as SDKImage, N as SDKImageDimension, O as SDKObjectDelta, Q as SDKRequestMessage, U as SDKStatusMessage, V as SDKSystemMessage, W as SDKTaskMessage, X as SDKThinkingMessage, Y as SDKToolUseMessage, Z as SDKUserMessage, _ as SDKUserMessageEvent, $ as SendOptions, a0 as ShellCommand, a1 as ShellConversationTurn, a2 as ShellOutput, a3 as ShellOutputDeltaUpdate, a4 as StepCompletedUpdate, a5 as StepStartedUpdate, a6 as StreamToCompletionResult, a7 as SummaryCompletedUpdate, a8 as SummaryStartedUpdate, a9 as SummaryUpdate, aa as TextBlock, ab as TextDeltaUpdate, ac as ThinkingCompletedUpdate, ad as ThinkingDeltaUpdate, ae as ThinkingMessage, af as TokenDeltaUpdate, ag as TokenUsage, ah as ToolCall, ai as ToolCallCompletedUpdate, aj as ToolCallStartedUpdate, ak as ToolContextMessage, al as ToolResult, am as ToolResultGuardOptions, an as ToolUseBlock, ao as TurnEndedUpdate, ap as UserMessage, aq as UserMessageAppendedUpdate, ar as emitRunEvent } from './run-Cr0C6cOM.cjs';
|
|
7
7
|
import * as zod from 'zod';
|
|
8
8
|
import { ZodType, z } from 'zod';
|
|
9
9
|
|
|
@@ -918,7 +918,14 @@ interface SanitizeOptions {
|
|
|
918
918
|
*
|
|
919
919
|
* @public
|
|
920
920
|
*/
|
|
921
|
-
|
|
921
|
+
/**
|
|
922
|
+
* SE16 — the handler's return type. With no `outputSchema` the tool returns a
|
|
923
|
+
* plain `string` (pre-SE16 shape). With an `outputSchema` the handler returns the
|
|
924
|
+
* STRUCTURED output inferred from it (validated + serialized to the tool result).
|
|
925
|
+
* The `[O]` tuple wrap prevents distribution so `never` maps cleanly to `string`.
|
|
926
|
+
*/
|
|
927
|
+
type ToolHandlerReturn<O extends ZodType> = [O] extends [never] ? string : z.infer<O>;
|
|
928
|
+
interface DefineToolSpec<T extends ZodType, O extends ZodType = never> {
|
|
922
929
|
/** Tool name surfaced to the LLM. Same constraints as {@link CustomTool.name}. */
|
|
923
930
|
name: string;
|
|
924
931
|
/** Description surfaced to the LLM. */
|
|
@@ -926,7 +933,16 @@ interface DefineToolSpec<T extends ZodType> {
|
|
|
926
933
|
/** Zod schema describing the input. Must be `z.object(...)` at the root for the LLM tool contract. */
|
|
927
934
|
inputSchema: T;
|
|
928
935
|
/**
|
|
929
|
-
*
|
|
936
|
+
* SE16 — optional Zod schema describing the OUTPUT. When set, the handler
|
|
937
|
+
* returns the structured value inferred from it; the value is validated against
|
|
938
|
+
* this schema and serialized to the tool result (a string stays as-is, an object
|
|
939
|
+
* is JSON-stringified). A validation failure raises `ZodError`, converted to a
|
|
940
|
+
* `tool_result(isError)`. Absent ⇒ the handler returns a plain string (unchanged).
|
|
941
|
+
*/
|
|
942
|
+
outputSchema?: O;
|
|
943
|
+
/**
|
|
944
|
+
* Handler invoked with the parsed input. Type is inferred via `z.infer<T>`; the
|
|
945
|
+
* return type is `z.infer<O>` when `outputSchema` is set, else `string`.
|
|
930
946
|
* #65 — an optional 2nd `ToolContext` argument carries the run's `AbortSignal`,
|
|
931
947
|
* so a cooperative handler can stop early when the run is cancelled. Existing
|
|
932
948
|
* single-argument handlers are unaffected.
|
|
@@ -934,7 +950,18 @@ interface DefineToolSpec<T extends ZodType> {
|
|
|
934
950
|
handler: (input: z.infer<T>, ctx?: {
|
|
935
951
|
signal?: AbortSignal;
|
|
936
952
|
context?: unknown;
|
|
937
|
-
}) =>
|
|
953
|
+
}) => ToolHandlerReturn<O> | Promise<ToolHandlerReturn<O>>;
|
|
954
|
+
/**
|
|
955
|
+
* SE17 — map the handler's (validated) output to the compact / multimodal
|
|
956
|
+
* representation the MODEL sees in the tool_result. The handler keeps returning
|
|
957
|
+
* the FULL result (validated by `outputSchema`); `toModelOutput` shapes only what
|
|
958
|
+
* reaches the model, so app-facing detail is not forced into model context.
|
|
959
|
+
* Returns a string OR SE7 `ToolResultContentBlock[]` (text + image). Absent ⇒
|
|
960
|
+
* the tool_result is the serialized handler output (SE16 / pre-SE17 behavior).
|
|
961
|
+
* Note: observability (`onToolEnd`) sees the model-facing result this returns,
|
|
962
|
+
* not the raw handler output — the full result lives in the handler's own scope.
|
|
963
|
+
*/
|
|
964
|
+
toModelOutput?: (output: ToolHandlerReturn<O>) => string | ToolResultContentBlock[];
|
|
938
965
|
/**
|
|
939
966
|
* Sanitize the raw model-emitted args BEFORE schema validation (`@theokit/sdk/sanitize`).
|
|
940
967
|
* `true` trims whitespace; an object opts into coercion / JSON-repair. Coercion is schema-aware
|
|
@@ -943,23 +970,7 @@ interface DefineToolSpec<T extends ZodType> {
|
|
|
943
970
|
*/
|
|
944
971
|
sanitize?: boolean | SanitizeOptions;
|
|
945
972
|
}
|
|
946
|
-
|
|
947
|
-
* Type-safe builder for {@link CustomTool}. Converts a Zod schema to JSON
|
|
948
|
-
* Schema (for the LLM-facing `inputSchema` field), wraps the handler with a
|
|
949
|
-
* runtime `schema.parse` step, and preserves type inference.
|
|
950
|
-
*
|
|
951
|
-
* Behaviour (ADR D24):
|
|
952
|
-
* - JSON Schema conversion uses Zod 4's native `z.toJSONSchema` with
|
|
953
|
-
* `unrepresentable: "any"` so transforms/refinements round-trip.
|
|
954
|
-
* - Runtime parse failures throw `ZodError`; the SDK's tool-dispatch converts
|
|
955
|
-
* them to `tool_result(isError)` with the Zod message.
|
|
956
|
-
* - Handler signature is `(input: z.infer<T>)`, not `Record<string, unknown>`.
|
|
957
|
-
* - `zod` loads lazily via `createRequire` — consumers who don't call
|
|
958
|
-
* `defineTool` don't need `zod` installed.
|
|
959
|
-
*
|
|
960
|
-
* @public
|
|
961
|
-
*/
|
|
962
|
-
declare function defineTool<T extends ZodType>(spec: DefineToolSpec<T>): CustomTool;
|
|
973
|
+
declare function defineTool<T extends ZodType, O extends ZodType = never>(spec: DefineToolSpec<T, O>): CustomTool;
|
|
963
974
|
|
|
964
975
|
/**
|
|
965
976
|
* `EventBus` — typed EventEmitter wrapper.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { T as TheokitAgentError, B as BudgetOptions, a as BudgetHandle, b as BudgetSnapshot, E as ErrorMetadata } from './errors-
|
|
2
|
-
export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, f as BudgetExceedEvent, g as BudgetExceededError, h as BudgetLimit, i as BudgetMode, j as BudgetScope, k as BudgetThresholdEvent, l as BudgetWindow, C as ConfigurationError, m as ErrorCode, I as IntegrationNotConnectedError, n as InvalidTaskIdError, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-
|
|
3
|
-
import { A as AgentOptions, L as LocalOptions, P as ProviderRoutingSettings, S as SystemPromptResolver, C as CloudOptions, M as MemorySettings, a as AgentDefinition, b as ContextSettings, c as PluginsSettings, d as SkillsSettings, e as SDKAgent, f as ListAgentsOptions, g as ListResult, h as SDKAgentInfo, G as GetAgentOptions, i as ListRunsOptions, j as GetRunOptions, k as AgentOperationOptions, l as ProviderProfile, m as Plugin, n as ConversationStorageAdapter, o as StoredMessage, p as SessionMeta, q as SessionMetaPatch, B as BudgetTracker, r as MemoryProvider, s as MemoryId, t as PreToolCallDecision, u as SDKProvider } from './cron-
|
|
4
|
-
export { v as ActiveMemoryPassArgs, w as ActiveMemoryPassResult, x as AgentMemory, y as BudgetCheck, z as BudgetTotal, D as BudgetUsageEvent, E as CloudEnv, F as CloudRepo, H as ContextBudget, I as ContextManagerKind, J as ContextSnapshot, K as ContextSource, N as ContextSourceStatus, O as CreateSkillSpec, Q as Cron, R as CronCreateOptions, T as CronGetOptions, U as CronJob, V as CronJobStatus, W as CronListOptions, X as CronOperationOptions, Y as CronRunOptions, Z as CronRuntime, _ as CronSchedulerStatus, $ as CronStartOptions, a0 as GoalEvent, a1 as GoalOptions, a2 as GoalResult, a3 as HookName, a4 as InlineSkill, a5 as InvalidateCacheOptions, a6 as MemoryAdapter, a7 as MemoryAdapterCapabilities, a8 as MemoryContext, a9 as MemoryFact, aa as MemoryProviderHandle, ab as MemoryProviderInitOptions, ac as MemoryRevision, ad as MemoryToolSchema, ae as MemoryTurnMessage, af as PersonalityPreset, ag as PluginContext, ah as PostAssistantReplyContext, ai as PreToolCallContext, aj as PreUserSendContext, ak as PreUserSendResult, al as ProviderCapability, am as ProviderRoute, an as RecordSessionSummaryArgs, ao as ResolvedProviderRoute, ap as RunUntilIterator, aq as SDKAgentPlugins, ar as SDKAgentSkills, as as SDKArtifact, at as SDKContextManager, au as SDKPluginMetadata, av as SDKProvidersManager, aw as SettingSource, ax as SystemPromptContext, ay as SystemPromptMemoryFact, az as SystemPromptSkillRef, aA as TelemetrySettings, aB as createSkill, aC as definePlugin } from './cron-
|
|
5
|
-
import { R as RunResult, M as ModelSelection, C as CustomTool, a as McpServerConfig, b as Run,
|
|
6
|
-
export { A as AgentConversationTurn, d as AssistantMessage, e as ConversationStep, f as ConversationTurn, g as CostBreakdown, h as CostSource, i as CostStatus, D as DoomLoopThresholds, G as GenerateOptions, j as GenerateRunResult, I as ImageBlock, k as InteractionUpdate, l as McpAuthConfig, m as McpHttpServerConfig, n as McpOAuthConfig, o as McpStdioServerConfig, p as ModelParameterValue, P as PartialToolCallUpdate, q as RunCompactBoundaryEvent, r as RunErrorDetail, s as RunEvent, t as RunEventSink, u as RunGitInfo, v as RunOperation, w as RunPermissionDeniedEvent, x as RunRateLimitEvent, y as RunStatus, z as RunTaskCompletedEvent, B as RunTaskStartedEvent, E as RunTaskUpdatedEvent, F as RunToCompletionOptions, H as RunToCompletionResult, J as RunToolProgressEvent, K as SDKAssistantMessage, L as SDKImage, N as SDKImageDimension, O as SDKObjectDelta, Q as SDKRequestMessage, U as SDKStatusMessage, V as SDKSystemMessage, W as SDKTaskMessage, X as SDKThinkingMessage, Y as SDKToolUseMessage, Z as SDKUserMessage, _ as SDKUserMessageEvent, $ as SendOptions, a0 as ShellCommand, a1 as ShellConversationTurn, a2 as ShellOutput, a3 as ShellOutputDeltaUpdate, a4 as StepCompletedUpdate, a5 as StepStartedUpdate, a6 as StreamToCompletionResult, a7 as SummaryCompletedUpdate, a8 as SummaryStartedUpdate, a9 as SummaryUpdate, aa as TextBlock, ab as TextDeltaUpdate, ac as ThinkingCompletedUpdate, ad as ThinkingDeltaUpdate, ae as ThinkingMessage, af as TokenDeltaUpdate, ag as TokenUsage, ah as ToolCall, ai as ToolCallCompletedUpdate, aj as ToolCallStartedUpdate, ak as ToolContextMessage, al as ToolResult, am as ToolResultGuardOptions, an as ToolUseBlock, ao as TurnEndedUpdate, ap as UserMessage, aq as UserMessageAppendedUpdate, ar as emitRunEvent } from './run-
|
|
1
|
+
import { T as TheokitAgentError, B as BudgetOptions, a as BudgetHandle, b as BudgetSnapshot, E as ErrorMetadata } from './errors-DRS-kqOK.js';
|
|
2
|
+
export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, f as BudgetExceedEvent, g as BudgetExceededError, h as BudgetLimit, i as BudgetMode, j as BudgetScope, k as BudgetThresholdEvent, l as BudgetWindow, C as ConfigurationError, m as ErrorCode, I as IntegrationNotConnectedError, n as InvalidTaskIdError, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-DRS-kqOK.js';
|
|
3
|
+
import { A as AgentOptions, L as LocalOptions, P as ProviderRoutingSettings, S as SystemPromptResolver, C as CloudOptions, M as MemorySettings, a as AgentDefinition, b as ContextSettings, c as PluginsSettings, d as SkillsSettings, e as SDKAgent, f as ListAgentsOptions, g as ListResult, h as SDKAgentInfo, G as GetAgentOptions, i as ListRunsOptions, j as GetRunOptions, k as AgentOperationOptions, l as ProviderProfile, m as Plugin, n as ConversationStorageAdapter, o as StoredMessage, p as SessionMeta, q as SessionMetaPatch, B as BudgetTracker, r as MemoryProvider, s as MemoryId, t as PreToolCallDecision, u as SDKProvider } from './cron-vjod0qVQ.js';
|
|
4
|
+
export { v as ActiveMemoryPassArgs, w as ActiveMemoryPassResult, x as AgentMemory, y as BudgetCheck, z as BudgetTotal, D as BudgetUsageEvent, E as CloudEnv, F as CloudRepo, H as ContextBudget, I as ContextManagerKind, J as ContextSnapshot, K as ContextSource, N as ContextSourceStatus, O as CreateSkillSpec, Q as Cron, R as CronCreateOptions, T as CronGetOptions, U as CronJob, V as CronJobStatus, W as CronListOptions, X as CronOperationOptions, Y as CronRunOptions, Z as CronRuntime, _ as CronSchedulerStatus, $ as CronStartOptions, a0 as GoalEvent, a1 as GoalOptions, a2 as GoalResult, a3 as HookName, a4 as InlineSkill, a5 as InvalidateCacheOptions, a6 as MemoryAdapter, a7 as MemoryAdapterCapabilities, a8 as MemoryContext, a9 as MemoryFact, aa as MemoryProviderHandle, ab as MemoryProviderInitOptions, ac as MemoryRevision, ad as MemoryToolSchema, ae as MemoryTurnMessage, af as PersonalityPreset, ag as PluginContext, ah as PostAssistantReplyContext, ai as PreToolCallContext, aj as PreUserSendContext, ak as PreUserSendResult, al as ProviderCapability, am as ProviderRoute, an as RecordSessionSummaryArgs, ao as ResolvedProviderRoute, ap as RunUntilIterator, aq as SDKAgentPlugins, ar as SDKAgentSkills, as as SDKArtifact, at as SDKContextManager, au as SDKPluginMetadata, av as SDKProvidersManager, aw as SettingSource, ax as SystemPromptContext, ay as SystemPromptMemoryFact, az as SystemPromptSkillRef, aA as TelemetrySettings, aB as createSkill, aC as definePlugin } from './cron-vjod0qVQ.js';
|
|
5
|
+
import { R as RunResult, M as ModelSelection, C as CustomTool, a as McpServerConfig, b as Run, T as ToolResultContentBlock, S as SDKMessage, c as MessageOrigin } from './run-Cr0C6cOM.js';
|
|
6
|
+
export { A as AgentConversationTurn, d as AssistantMessage, e as ConversationStep, f as ConversationTurn, g as CostBreakdown, h as CostSource, i as CostStatus, D as DoomLoopThresholds, G as GenerateOptions, j as GenerateRunResult, I as ImageBlock, k as InteractionUpdate, l as McpAuthConfig, m as McpHttpServerConfig, n as McpOAuthConfig, o as McpStdioServerConfig, p as ModelParameterValue, P as PartialToolCallUpdate, q as RunCompactBoundaryEvent, r as RunErrorDetail, s as RunEvent, t as RunEventSink, u as RunGitInfo, v as RunOperation, w as RunPermissionDeniedEvent, x as RunRateLimitEvent, y as RunStatus, z as RunTaskCompletedEvent, B as RunTaskStartedEvent, E as RunTaskUpdatedEvent, F as RunToCompletionOptions, H as RunToCompletionResult, J as RunToolProgressEvent, K as SDKAssistantMessage, L as SDKImage, N as SDKImageDimension, O as SDKObjectDelta, Q as SDKRequestMessage, U as SDKStatusMessage, V as SDKSystemMessage, W as SDKTaskMessage, X as SDKThinkingMessage, Y as SDKToolUseMessage, Z as SDKUserMessage, _ as SDKUserMessageEvent, $ as SendOptions, a0 as ShellCommand, a1 as ShellConversationTurn, a2 as ShellOutput, a3 as ShellOutputDeltaUpdate, a4 as StepCompletedUpdate, a5 as StepStartedUpdate, a6 as StreamToCompletionResult, a7 as SummaryCompletedUpdate, a8 as SummaryStartedUpdate, a9 as SummaryUpdate, aa as TextBlock, ab as TextDeltaUpdate, ac as ThinkingCompletedUpdate, ad as ThinkingDeltaUpdate, ae as ThinkingMessage, af as TokenDeltaUpdate, ag as TokenUsage, ah as ToolCall, ai as ToolCallCompletedUpdate, aj as ToolCallStartedUpdate, ak as ToolContextMessage, al as ToolResult, am as ToolResultGuardOptions, an as ToolUseBlock, ao as TurnEndedUpdate, ap as UserMessage, aq as UserMessageAppendedUpdate, ar as emitRunEvent } from './run-Cr0C6cOM.js';
|
|
7
7
|
import * as zod from 'zod';
|
|
8
8
|
import { ZodType, z } from 'zod';
|
|
9
9
|
|
|
@@ -918,7 +918,14 @@ interface SanitizeOptions {
|
|
|
918
918
|
*
|
|
919
919
|
* @public
|
|
920
920
|
*/
|
|
921
|
-
|
|
921
|
+
/**
|
|
922
|
+
* SE16 — the handler's return type. With no `outputSchema` the tool returns a
|
|
923
|
+
* plain `string` (pre-SE16 shape). With an `outputSchema` the handler returns the
|
|
924
|
+
* STRUCTURED output inferred from it (validated + serialized to the tool result).
|
|
925
|
+
* The `[O]` tuple wrap prevents distribution so `never` maps cleanly to `string`.
|
|
926
|
+
*/
|
|
927
|
+
type ToolHandlerReturn<O extends ZodType> = [O] extends [never] ? string : z.infer<O>;
|
|
928
|
+
interface DefineToolSpec<T extends ZodType, O extends ZodType = never> {
|
|
922
929
|
/** Tool name surfaced to the LLM. Same constraints as {@link CustomTool.name}. */
|
|
923
930
|
name: string;
|
|
924
931
|
/** Description surfaced to the LLM. */
|
|
@@ -926,7 +933,16 @@ interface DefineToolSpec<T extends ZodType> {
|
|
|
926
933
|
/** Zod schema describing the input. Must be `z.object(...)` at the root for the LLM tool contract. */
|
|
927
934
|
inputSchema: T;
|
|
928
935
|
/**
|
|
929
|
-
*
|
|
936
|
+
* SE16 — optional Zod schema describing the OUTPUT. When set, the handler
|
|
937
|
+
* returns the structured value inferred from it; the value is validated against
|
|
938
|
+
* this schema and serialized to the tool result (a string stays as-is, an object
|
|
939
|
+
* is JSON-stringified). A validation failure raises `ZodError`, converted to a
|
|
940
|
+
* `tool_result(isError)`. Absent ⇒ the handler returns a plain string (unchanged).
|
|
941
|
+
*/
|
|
942
|
+
outputSchema?: O;
|
|
943
|
+
/**
|
|
944
|
+
* Handler invoked with the parsed input. Type is inferred via `z.infer<T>`; the
|
|
945
|
+
* return type is `z.infer<O>` when `outputSchema` is set, else `string`.
|
|
930
946
|
* #65 — an optional 2nd `ToolContext` argument carries the run's `AbortSignal`,
|
|
931
947
|
* so a cooperative handler can stop early when the run is cancelled. Existing
|
|
932
948
|
* single-argument handlers are unaffected.
|
|
@@ -934,7 +950,18 @@ interface DefineToolSpec<T extends ZodType> {
|
|
|
934
950
|
handler: (input: z.infer<T>, ctx?: {
|
|
935
951
|
signal?: AbortSignal;
|
|
936
952
|
context?: unknown;
|
|
937
|
-
}) =>
|
|
953
|
+
}) => ToolHandlerReturn<O> | Promise<ToolHandlerReturn<O>>;
|
|
954
|
+
/**
|
|
955
|
+
* SE17 — map the handler's (validated) output to the compact / multimodal
|
|
956
|
+
* representation the MODEL sees in the tool_result. The handler keeps returning
|
|
957
|
+
* the FULL result (validated by `outputSchema`); `toModelOutput` shapes only what
|
|
958
|
+
* reaches the model, so app-facing detail is not forced into model context.
|
|
959
|
+
* Returns a string OR SE7 `ToolResultContentBlock[]` (text + image). Absent ⇒
|
|
960
|
+
* the tool_result is the serialized handler output (SE16 / pre-SE17 behavior).
|
|
961
|
+
* Note: observability (`onToolEnd`) sees the model-facing result this returns,
|
|
962
|
+
* not the raw handler output — the full result lives in the handler's own scope.
|
|
963
|
+
*/
|
|
964
|
+
toModelOutput?: (output: ToolHandlerReturn<O>) => string | ToolResultContentBlock[];
|
|
938
965
|
/**
|
|
939
966
|
* Sanitize the raw model-emitted args BEFORE schema validation (`@theokit/sdk/sanitize`).
|
|
940
967
|
* `true` trims whitespace; an object opts into coercion / JSON-repair. Coercion is schema-aware
|
|
@@ -943,23 +970,7 @@ interface DefineToolSpec<T extends ZodType> {
|
|
|
943
970
|
*/
|
|
944
971
|
sanitize?: boolean | SanitizeOptions;
|
|
945
972
|
}
|
|
946
|
-
|
|
947
|
-
* Type-safe builder for {@link CustomTool}. Converts a Zod schema to JSON
|
|
948
|
-
* Schema (for the LLM-facing `inputSchema` field), wraps the handler with a
|
|
949
|
-
* runtime `schema.parse` step, and preserves type inference.
|
|
950
|
-
*
|
|
951
|
-
* Behaviour (ADR D24):
|
|
952
|
-
* - JSON Schema conversion uses Zod 4's native `z.toJSONSchema` with
|
|
953
|
-
* `unrepresentable: "any"` so transforms/refinements round-trip.
|
|
954
|
-
* - Runtime parse failures throw `ZodError`; the SDK's tool-dispatch converts
|
|
955
|
-
* them to `tool_result(isError)` with the Zod message.
|
|
956
|
-
* - Handler signature is `(input: z.infer<T>)`, not `Record<string, unknown>`.
|
|
957
|
-
* - `zod` loads lazily via `createRequire` — consumers who don't call
|
|
958
|
-
* `defineTool` don't need `zod` installed.
|
|
959
|
-
*
|
|
960
|
-
* @public
|
|
961
|
-
*/
|
|
962
|
-
declare function defineTool<T extends ZodType>(spec: DefineToolSpec<T>): CustomTool;
|
|
973
|
+
declare function defineTool<T extends ZodType, O extends ZodType = never>(spec: DefineToolSpec<T, O>): CustomTool;
|
|
963
974
|
|
|
964
975
|
/**
|
|
965
976
|
* `EventBus` — typed EventEmitter wrapper.
|
package/dist/index.js
CHANGED
|
@@ -15785,6 +15785,7 @@ function levenshtein(a, b) {
|
|
|
15785
15785
|
}
|
|
15786
15786
|
|
|
15787
15787
|
// src/internal/runtime/local-agent/real-local-run.ts
|
|
15788
|
+
init_async_local_storage();
|
|
15788
15789
|
function createRealLocalRun(options) {
|
|
15789
15790
|
const { userText, id, startTime } = prepareRunContext(options.message);
|
|
15790
15791
|
const supported = /* @__PURE__ */ new Set(["stream", "wait", "cancel", "conversation"]);
|
|
@@ -15896,6 +15897,7 @@ function buildLoopInputs(options, runId, userText) {
|
|
|
15896
15897
|
...options.onStep !== void 0 ? { onStep: options.onStep } : {},
|
|
15897
15898
|
...options.onDelta !== void 0 ? { onDelta: options.onDelta } : {},
|
|
15898
15899
|
...options.sendOptions.toolChoice !== void 0 ? { toolChoice: options.sendOptions.toolChoice } : {},
|
|
15900
|
+
...options.sendOptions.activeTools !== void 0 ? { activeTools: options.sendOptions.activeTools } : {},
|
|
15899
15901
|
...options.priorMessages !== void 0 ? { priorMessages: options.priorMessages } : {},
|
|
15900
15902
|
...options.memoryTools !== void 0 && options.memoryTools.length > 0 ? { memoryTools: options.memoryTools } : {},
|
|
15901
15903
|
...buildCustomToolsInput(
|
|
@@ -16026,7 +16028,7 @@ var RealLocalRun = class extends FixtureRunBase {
|
|
|
16026
16028
|
}
|
|
16027
16029
|
async executeAgentLoop(inputs) {
|
|
16028
16030
|
try {
|
|
16029
|
-
const output = await runAgentLoop(inputs);
|
|
16031
|
+
const output = inputs.activeTools !== void 0 ? await withToolWhitelist(new Set(inputs.activeTools), () => runAgentLoop(inputs)) : await runAgentLoop(inputs);
|
|
16030
16032
|
this.applyAgentLoopOutput(output);
|
|
16031
16033
|
this.transitionTo(output.finalStatus);
|
|
16032
16034
|
} catch (cause) {
|
|
@@ -19512,6 +19514,11 @@ function defineProvider(profile, opts) {
|
|
|
19512
19514
|
|
|
19513
19515
|
// src/define-tool.ts
|
|
19514
19516
|
init_to_json_schema();
|
|
19517
|
+
function shapeToolResult(spec, out) {
|
|
19518
|
+
const validated = spec.outputSchema === void 0 ? out : spec.outputSchema.parse(out);
|
|
19519
|
+
if (spec.toModelOutput !== void 0) return spec.toModelOutput(validated);
|
|
19520
|
+
return typeof validated === "string" ? validated : JSON.stringify(validated);
|
|
19521
|
+
}
|
|
19515
19522
|
function defineTool(spec) {
|
|
19516
19523
|
const inputSchema = toJsonSchema(spec.inputSchema, {
|
|
19517
19524
|
unrepresentable: "any"
|
|
@@ -19526,7 +19533,8 @@ function defineTool(spec) {
|
|
|
19526
19533
|
schema: spec.inputSchema
|
|
19527
19534
|
}).value : input;
|
|
19528
19535
|
const parsed = spec.inputSchema.parse(raw);
|
|
19529
|
-
|
|
19536
|
+
const out = await spec.handler(parsed, ctx);
|
|
19537
|
+
return shapeToolResult(spec, out);
|
|
19530
19538
|
}
|
|
19531
19539
|
};
|
|
19532
19540
|
}
|