@theokit/sdk 2.14.0 → 2.15.1
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 +12 -0
- package/dist/a2a/index.cjs +151 -8
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +151 -8
- package/dist/a2a/index.js.map +1 -1
- package/dist/{cron-CpxLdAXc.d.cts → cron-BxLSz1UH.d.cts} +1 -1
- package/dist/{cron-CL_9nfhQ.d.ts → cron-DcaoP7aW.d.ts} +1 -1
- package/dist/cron.cjs +144 -8
- 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 +144 -8
- package/dist/cron.js.map +1 -1
- package/dist/{errors-9yw4UQwX.d.cts → errors-Bart0ptP.d.cts} +1 -1
- package/dist/{errors-DFiY-NHK.d.ts → errors-DJuuubJK.d.ts} +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/eval.cjs +144 -8
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +144 -8
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +144 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +144 -8
- package/dist/index.js.map +1 -1
- package/dist/internal/agent-loop/doom-loop-tracker.d.ts +22 -0
- package/dist/internal/agent-loop/loop-types.d.ts +6 -0
- package/dist/internal/llm/hermes-tool-extract.d.ts +5 -1
- package/dist/internal/llm/openai.d.ts +5 -1
- package/dist/{run-TMdc7gmo.d.cts → run-DXy_MVwz.d.cts} +29 -1
- package/dist/{run-TMdc7gmo.d.ts → run-DXy_MVwz.d.ts} +29 -1
- package/dist/types/run.d.ts +28 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { T as TheokitAgentError, B as BudgetOptions, a as BudgetHandle, b as BudgetSnapshot } 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, E as ErrorCode, m as ErrorMetadata, 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, B as BudgetTracker, p as MemoryProvider, q as MemoryId, r as PreToolCallDecision, s as SDKProvider } from './cron-
|
|
4
|
-
export { t as ActiveMemoryPassArgs, u as ActiveMemoryPassResult, v as AgentMemory, w as BudgetCheck, x as BudgetTotal, y as BudgetUsageEvent, z as CloudEnv, D as CloudRepo, E as ContextBudget, F as ContextManagerKind, H as ContextSnapshot, I as ContextSource, J as ContextSourceStatus, K as Cron, N as CronCreateOptions, O as CronGetOptions, Q as CronJob, R as CronJobStatus, T as CronListOptions, U as CronOperationOptions, V as CronRunOptions, W as CronRuntime, X as CronSchedulerStatus, Y as CronStartOptions, Z as GoalEvent, _ as GoalOptions, $ as GoalResult, a0 as HookName, a1 as InvalidateCacheOptions, a2 as MemoryAdapter, a3 as MemoryAdapterCapabilities, a4 as MemoryContext, a5 as MemoryFact, a6 as MemoryProviderHandle, a7 as MemoryProviderInitOptions, a8 as MemoryRevision, a9 as MemoryToolSchema, aa as MemoryTurnMessage, ab as PersonalityPreset, ac as PluginContext, ad as PostAssistantReplyContext, ae as PreToolCallContext, af as PreUserSendContext, ag as PreUserSendResult, ah as ProviderCapability, ai as ProviderRoute, aj as RecordSessionSummaryArgs, ak as ResolvedProviderRoute, al as RunUntilIterator, am as SDKAgentPlugins, an as SDKAgentSkills, ao as SDKArtifact, ap as SDKContextManager, aq as SDKPluginMetadata, ar as SDKProvidersManager, as as SettingSource, at as SystemPromptContext, au as SystemPromptMemoryFact, av as SystemPromptSkillRef, aw as TelemetrySettings, ax as definePlugin } from './cron-
|
|
5
|
-
import { R as RunResult, M as ModelSelection, C as CustomTool, a as McpServerConfig, b as Run, S as SDKMessage } from './run-
|
|
6
|
-
export { A as AgentConversationTurn, c as AssistantMessage, d as ConversationStep, e as ConversationTurn, f as CostBreakdown, g as CostSource, h as CostStatus, I as InteractionUpdate, i as McpAuthConfig, j as McpHttpServerConfig, k as McpOAuthConfig, l as McpStdioServerConfig, m as ModelParameterValue, P as PartialToolCallUpdate, n as RunErrorDetail, o as RunGitInfo, p as RunOperation, q as RunStatus, r as RunToCompletionOptions, s as RunToCompletionResult, t as SDKAssistantMessage, u as SDKImage, v as SDKImageDimension, w as SDKObjectDelta, x as SDKRequestMessage, y as SDKStatusMessage, z as SDKSystemMessage, B as SDKTaskMessage,
|
|
1
|
+
import { T as TheokitAgentError, B as BudgetOptions, a as BudgetHandle, b as BudgetSnapshot } from './errors-Bart0ptP.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, E as ErrorCode, m as ErrorMetadata, 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-Bart0ptP.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, B as BudgetTracker, p as MemoryProvider, q as MemoryId, r as PreToolCallDecision, s as SDKProvider } from './cron-BxLSz1UH.cjs';
|
|
4
|
+
export { t as ActiveMemoryPassArgs, u as ActiveMemoryPassResult, v as AgentMemory, w as BudgetCheck, x as BudgetTotal, y as BudgetUsageEvent, z as CloudEnv, D as CloudRepo, E as ContextBudget, F as ContextManagerKind, H as ContextSnapshot, I as ContextSource, J as ContextSourceStatus, K as Cron, N as CronCreateOptions, O as CronGetOptions, Q as CronJob, R as CronJobStatus, T as CronListOptions, U as CronOperationOptions, V as CronRunOptions, W as CronRuntime, X as CronSchedulerStatus, Y as CronStartOptions, Z as GoalEvent, _ as GoalOptions, $ as GoalResult, a0 as HookName, a1 as InvalidateCacheOptions, a2 as MemoryAdapter, a3 as MemoryAdapterCapabilities, a4 as MemoryContext, a5 as MemoryFact, a6 as MemoryProviderHandle, a7 as MemoryProviderInitOptions, a8 as MemoryRevision, a9 as MemoryToolSchema, aa as MemoryTurnMessage, ab as PersonalityPreset, ac as PluginContext, ad as PostAssistantReplyContext, ae as PreToolCallContext, af as PreUserSendContext, ag as PreUserSendResult, ah as ProviderCapability, ai as ProviderRoute, aj as RecordSessionSummaryArgs, ak as ResolvedProviderRoute, al as RunUntilIterator, am as SDKAgentPlugins, an as SDKAgentSkills, ao as SDKArtifact, ap as SDKContextManager, aq as SDKPluginMetadata, ar as SDKProvidersManager, as as SettingSource, at as SystemPromptContext, au as SystemPromptMemoryFact, av as SystemPromptSkillRef, aw as TelemetrySettings, ax as definePlugin } from './cron-BxLSz1UH.cjs';
|
|
5
|
+
import { R as RunResult, M as ModelSelection, C as CustomTool, a as McpServerConfig, b as Run, S as SDKMessage } from './run-DXy_MVwz.cjs';
|
|
6
|
+
export { A as AgentConversationTurn, c as AssistantMessage, d as ConversationStep, e as ConversationTurn, f as CostBreakdown, g as CostSource, h as CostStatus, D as DoomLoopThresholds, I as InteractionUpdate, i as McpAuthConfig, j as McpHttpServerConfig, k as McpOAuthConfig, l as McpStdioServerConfig, m as ModelParameterValue, P as PartialToolCallUpdate, n as RunErrorDetail, o as RunGitInfo, p as RunOperation, q as RunStatus, r as RunToCompletionOptions, s as RunToCompletionResult, t as SDKAssistantMessage, u as SDKImage, v as SDKImageDimension, w as SDKObjectDelta, x as SDKRequestMessage, y as SDKStatusMessage, z as SDKSystemMessage, B as SDKTaskMessage, E as SDKThinkingMessage, F as SDKToolUseMessage, G as SDKUserMessage, H as SDKUserMessageEvent, J as SendOptions, K as ShellCommand, L as ShellConversationTurn, N as ShellOutput, O as ShellOutputDeltaUpdate, Q as StepCompletedUpdate, T as StepStartedUpdate, U as StreamToCompletionResult, V as SummaryCompletedUpdate, W as SummaryStartedUpdate, X as SummaryUpdate, Y as TextBlock, Z as TextDeltaUpdate, _ as ThinkingCompletedUpdate, $ as ThinkingDeltaUpdate, a0 as ThinkingMessage, a1 as TokenDeltaUpdate, a2 as TokenUsage, a3 as ToolCall, a4 as ToolCallCompletedUpdate, a5 as ToolCallStartedUpdate, a6 as ToolResult, a7 as ToolUseBlock, a8 as TurnEndedUpdate, a9 as UserMessage, aa as UserMessageAppendedUpdate } from './run-DXy_MVwz.cjs';
|
|
7
7
|
import * as zod from 'zod';
|
|
8
8
|
import { ZodType, z } from 'zod';
|
|
9
9
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { T as TheokitAgentError, B as BudgetOptions, a as BudgetHandle, b as BudgetSnapshot } 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, E as ErrorCode, m as ErrorMetadata, 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, B as BudgetTracker, p as MemoryProvider, q as MemoryId, r as PreToolCallDecision, s as SDKProvider } from './cron-
|
|
4
|
-
export { t as ActiveMemoryPassArgs, u as ActiveMemoryPassResult, v as AgentMemory, w as BudgetCheck, x as BudgetTotal, y as BudgetUsageEvent, z as CloudEnv, D as CloudRepo, E as ContextBudget, F as ContextManagerKind, H as ContextSnapshot, I as ContextSource, J as ContextSourceStatus, K as Cron, N as CronCreateOptions, O as CronGetOptions, Q as CronJob, R as CronJobStatus, T as CronListOptions, U as CronOperationOptions, V as CronRunOptions, W as CronRuntime, X as CronSchedulerStatus, Y as CronStartOptions, Z as GoalEvent, _ as GoalOptions, $ as GoalResult, a0 as HookName, a1 as InvalidateCacheOptions, a2 as MemoryAdapter, a3 as MemoryAdapterCapabilities, a4 as MemoryContext, a5 as MemoryFact, a6 as MemoryProviderHandle, a7 as MemoryProviderInitOptions, a8 as MemoryRevision, a9 as MemoryToolSchema, aa as MemoryTurnMessage, ab as PersonalityPreset, ac as PluginContext, ad as PostAssistantReplyContext, ae as PreToolCallContext, af as PreUserSendContext, ag as PreUserSendResult, ah as ProviderCapability, ai as ProviderRoute, aj as RecordSessionSummaryArgs, ak as ResolvedProviderRoute, al as RunUntilIterator, am as SDKAgentPlugins, an as SDKAgentSkills, ao as SDKArtifact, ap as SDKContextManager, aq as SDKPluginMetadata, ar as SDKProvidersManager, as as SettingSource, at as SystemPromptContext, au as SystemPromptMemoryFact, av as SystemPromptSkillRef, aw as TelemetrySettings, ax as definePlugin } from './cron-
|
|
5
|
-
import { R as RunResult, M as ModelSelection, C as CustomTool, a as McpServerConfig, b as Run, S as SDKMessage } from './run-
|
|
6
|
-
export { A as AgentConversationTurn, c as AssistantMessage, d as ConversationStep, e as ConversationTurn, f as CostBreakdown, g as CostSource, h as CostStatus, I as InteractionUpdate, i as McpAuthConfig, j as McpHttpServerConfig, k as McpOAuthConfig, l as McpStdioServerConfig, m as ModelParameterValue, P as PartialToolCallUpdate, n as RunErrorDetail, o as RunGitInfo, p as RunOperation, q as RunStatus, r as RunToCompletionOptions, s as RunToCompletionResult, t as SDKAssistantMessage, u as SDKImage, v as SDKImageDimension, w as SDKObjectDelta, x as SDKRequestMessage, y as SDKStatusMessage, z as SDKSystemMessage, B as SDKTaskMessage,
|
|
1
|
+
import { T as TheokitAgentError, B as BudgetOptions, a as BudgetHandle, b as BudgetSnapshot } from './errors-DJuuubJK.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, E as ErrorCode, m as ErrorMetadata, 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-DJuuubJK.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, B as BudgetTracker, p as MemoryProvider, q as MemoryId, r as PreToolCallDecision, s as SDKProvider } from './cron-DcaoP7aW.js';
|
|
4
|
+
export { t as ActiveMemoryPassArgs, u as ActiveMemoryPassResult, v as AgentMemory, w as BudgetCheck, x as BudgetTotal, y as BudgetUsageEvent, z as CloudEnv, D as CloudRepo, E as ContextBudget, F as ContextManagerKind, H as ContextSnapshot, I as ContextSource, J as ContextSourceStatus, K as Cron, N as CronCreateOptions, O as CronGetOptions, Q as CronJob, R as CronJobStatus, T as CronListOptions, U as CronOperationOptions, V as CronRunOptions, W as CronRuntime, X as CronSchedulerStatus, Y as CronStartOptions, Z as GoalEvent, _ as GoalOptions, $ as GoalResult, a0 as HookName, a1 as InvalidateCacheOptions, a2 as MemoryAdapter, a3 as MemoryAdapterCapabilities, a4 as MemoryContext, a5 as MemoryFact, a6 as MemoryProviderHandle, a7 as MemoryProviderInitOptions, a8 as MemoryRevision, a9 as MemoryToolSchema, aa as MemoryTurnMessage, ab as PersonalityPreset, ac as PluginContext, ad as PostAssistantReplyContext, ae as PreToolCallContext, af as PreUserSendContext, ag as PreUserSendResult, ah as ProviderCapability, ai as ProviderRoute, aj as RecordSessionSummaryArgs, ak as ResolvedProviderRoute, al as RunUntilIterator, am as SDKAgentPlugins, an as SDKAgentSkills, ao as SDKArtifact, ap as SDKContextManager, aq as SDKPluginMetadata, ar as SDKProvidersManager, as as SettingSource, at as SystemPromptContext, au as SystemPromptMemoryFact, av as SystemPromptSkillRef, aw as TelemetrySettings, ax as definePlugin } from './cron-DcaoP7aW.js';
|
|
5
|
+
import { R as RunResult, M as ModelSelection, C as CustomTool, a as McpServerConfig, b as Run, S as SDKMessage } from './run-DXy_MVwz.js';
|
|
6
|
+
export { A as AgentConversationTurn, c as AssistantMessage, d as ConversationStep, e as ConversationTurn, f as CostBreakdown, g as CostSource, h as CostStatus, D as DoomLoopThresholds, I as InteractionUpdate, i as McpAuthConfig, j as McpHttpServerConfig, k as McpOAuthConfig, l as McpStdioServerConfig, m as ModelParameterValue, P as PartialToolCallUpdate, n as RunErrorDetail, o as RunGitInfo, p as RunOperation, q as RunStatus, r as RunToCompletionOptions, s as RunToCompletionResult, t as SDKAssistantMessage, u as SDKImage, v as SDKImageDimension, w as SDKObjectDelta, x as SDKRequestMessage, y as SDKStatusMessage, z as SDKSystemMessage, B as SDKTaskMessage, E as SDKThinkingMessage, F as SDKToolUseMessage, G as SDKUserMessage, H as SDKUserMessageEvent, J as SendOptions, K as ShellCommand, L as ShellConversationTurn, N as ShellOutput, O as ShellOutputDeltaUpdate, Q as StepCompletedUpdate, T as StepStartedUpdate, U as StreamToCompletionResult, V as SummaryCompletedUpdate, W as SummaryStartedUpdate, X as SummaryUpdate, Y as TextBlock, Z as TextDeltaUpdate, _ as ThinkingCompletedUpdate, $ as ThinkingDeltaUpdate, a0 as ThinkingMessage, a1 as TokenDeltaUpdate, a2 as TokenUsage, a3 as ToolCall, a4 as ToolCallCompletedUpdate, a5 as ToolCallStartedUpdate, a6 as ToolResult, a7 as ToolUseBlock, a8 as TurnEndedUpdate, a9 as UserMessage, aa as UserMessageAppendedUpdate } from './run-DXy_MVwz.js';
|
|
7
7
|
import * as zod from 'zod';
|
|
8
8
|
import { ZodType, z } from 'zod';
|
|
9
9
|
|
package/dist/index.js
CHANGED
|
@@ -2814,6 +2814,7 @@ function isEmptyRound(result) {
|
|
|
2814
2814
|
return (result.result ?? "").trim() === "";
|
|
2815
2815
|
}
|
|
2816
2816
|
function classifyRound(result, round, maxRounds, emptyStreak) {
|
|
2817
|
+
if (result.stoppedByDoomLoop === true) return "no_progress";
|
|
2817
2818
|
if (result.stoppedAtIterationLimit !== true) return "done";
|
|
2818
2819
|
if (isEmptyRound(result) && emptyStreak >= 1) return "no_progress";
|
|
2819
2820
|
if (round >= maxRounds) return "step_limit";
|
|
@@ -6979,6 +6980,7 @@ function applyScriptMetrics(base, script) {
|
|
|
6979
6980
|
if (script.usage !== void 0) base.usage = script.usage;
|
|
6980
6981
|
if (script.cost !== void 0) base.cost = script.cost;
|
|
6981
6982
|
if (script.stoppedAtIterationLimit === true) base.stoppedAtIterationLimit = true;
|
|
6983
|
+
if (script.stoppedByDoomLoop === true) base.stoppedByDoomLoop = true;
|
|
6982
6984
|
}
|
|
6983
6985
|
|
|
6984
6986
|
// src/internal/runtime/cloud/cloud-run.ts
|
|
@@ -10730,6 +10732,93 @@ function evaluateBudgetGate(tracker) {
|
|
|
10730
10732
|
}
|
|
10731
10733
|
}
|
|
10732
10734
|
|
|
10735
|
+
// src/internal/agent-loop/doom-loop-tracker.ts
|
|
10736
|
+
init_errors();
|
|
10737
|
+
function createDoomLoopTracker(option) {
|
|
10738
|
+
if (option === false) return void 0;
|
|
10739
|
+
return new DoomLoopTracker(option);
|
|
10740
|
+
}
|
|
10741
|
+
var DEFAULT_CONFIG = { softThreshold: 3, hardThreshold: 5 };
|
|
10742
|
+
function assertValidThresholds(soft, hard) {
|
|
10743
|
+
for (const [label, value] of [
|
|
10744
|
+
["softThreshold", soft],
|
|
10745
|
+
["hardThreshold", hard]
|
|
10746
|
+
]) {
|
|
10747
|
+
if (!Number.isInteger(value) || value < 1) {
|
|
10748
|
+
throw new ConfigurationError(
|
|
10749
|
+
`doomLoop.${label} must be a positive integer (received ${value}).`,
|
|
10750
|
+
{ code: "invalid_doom_loop_threshold" }
|
|
10751
|
+
);
|
|
10752
|
+
}
|
|
10753
|
+
}
|
|
10754
|
+
}
|
|
10755
|
+
function sortKeys(value) {
|
|
10756
|
+
if (value === null || typeof value !== "object") return value;
|
|
10757
|
+
if (Array.isArray(value)) return value.map(sortKeys);
|
|
10758
|
+
const out = {};
|
|
10759
|
+
for (const key2 of Object.keys(value).sort()) {
|
|
10760
|
+
out[key2] = sortKeys(value[key2]);
|
|
10761
|
+
}
|
|
10762
|
+
return out;
|
|
10763
|
+
}
|
|
10764
|
+
function signatureOf(call) {
|
|
10765
|
+
const { input } = call;
|
|
10766
|
+
let inputSig;
|
|
10767
|
+
if (input === null || input === void 0) inputSig = "null";
|
|
10768
|
+
else if (typeof input !== "object") inputSig = String(input);
|
|
10769
|
+
else {
|
|
10770
|
+
try {
|
|
10771
|
+
inputSig = JSON.stringify(sortKeys(input)) ?? "null";
|
|
10772
|
+
} catch {
|
|
10773
|
+
inputSig = String(input);
|
|
10774
|
+
}
|
|
10775
|
+
}
|
|
10776
|
+
return `${call.name}\0${inputSig}`;
|
|
10777
|
+
}
|
|
10778
|
+
var DoomLoopTracker = class {
|
|
10779
|
+
#config;
|
|
10780
|
+
#lastSignature = "";
|
|
10781
|
+
#count = 0;
|
|
10782
|
+
constructor(config) {
|
|
10783
|
+
const softThreshold = config?.softThreshold ?? DEFAULT_CONFIG.softThreshold;
|
|
10784
|
+
const hardThreshold = config?.hardThreshold ?? DEFAULT_CONFIG.hardThreshold;
|
|
10785
|
+
assertValidThresholds(softThreshold, hardThreshold);
|
|
10786
|
+
this.#config = { softThreshold, hardThreshold };
|
|
10787
|
+
}
|
|
10788
|
+
inspect(call) {
|
|
10789
|
+
const signature = signatureOf(call);
|
|
10790
|
+
this.#count = signature === this.#lastSignature ? this.#count + 1 : 1;
|
|
10791
|
+
this.#lastSignature = signature;
|
|
10792
|
+
const count = this.#count;
|
|
10793
|
+
if (count >= this.#config.hardThreshold) {
|
|
10794
|
+
return {
|
|
10795
|
+
kind: "hard",
|
|
10796
|
+
message: `Detected ${count} consecutive identical calls to \`${call.name}\`; stopping to avoid a loop.`
|
|
10797
|
+
};
|
|
10798
|
+
}
|
|
10799
|
+
if (count === this.#config.softThreshold) {
|
|
10800
|
+
return {
|
|
10801
|
+
kind: "soft",
|
|
10802
|
+
message: `Detected ${count} consecutive identical calls to \`${call.name}\`; try a different approach.`
|
|
10803
|
+
};
|
|
10804
|
+
}
|
|
10805
|
+
return { kind: "ok" };
|
|
10806
|
+
}
|
|
10807
|
+
reset() {
|
|
10808
|
+
this.#lastSignature = "";
|
|
10809
|
+
this.#count = 0;
|
|
10810
|
+
}
|
|
10811
|
+
};
|
|
10812
|
+
function firstDoomLoopVerdict(tracker, calls) {
|
|
10813
|
+
let escalation = { kind: "ok" };
|
|
10814
|
+
for (const call of calls) {
|
|
10815
|
+
const v = tracker.inspect(call);
|
|
10816
|
+
if (v.kind === "hard") return v;
|
|
10817
|
+
if (v.kind === "soft" && escalation.kind === "ok") escalation = v;
|
|
10818
|
+
}
|
|
10819
|
+
return escalation;
|
|
10820
|
+
}
|
|
10821
|
+
|
|
10733
10822
|
// src/internal/budget/usage-accumulator.ts
|
|
10734
10823
|
var UsageAccumulator = class {
|
|
10735
10824
|
input = 0;
|
|
@@ -10910,6 +10999,7 @@ async function initLoopContext(inputs) {
|
|
|
10910
10999
|
tools,
|
|
10911
11000
|
finalText: "",
|
|
10912
11001
|
finalStatus: "finished",
|
|
11002
|
+
doomLoop: createDoomLoopTracker(inputs.doomLoop),
|
|
10913
11003
|
usage: new UsageAccumulator(),
|
|
10914
11004
|
nudgeAttempts: 0,
|
|
10915
11005
|
stopFeedbackAttempts: 0,
|
|
@@ -11934,6 +12024,7 @@ async function runAgentLoop(inputs) {
|
|
|
11934
12024
|
ctx.finalStatus = "error";
|
|
11935
12025
|
}
|
|
11936
12026
|
sendSpan?.setAttribute("status", ctx.finalStatus);
|
|
12027
|
+
if (ctx.stoppedByDoomLoop === true) sendSpan?.setAttribute("stoppedByDoomLoop", true);
|
|
11937
12028
|
if (inputs.telemetry?.includeContent === true && ctx.finalText.length > 0) {
|
|
11938
12029
|
sendSpan?.addEvent("response", { content: ctx.finalText });
|
|
11939
12030
|
}
|
|
@@ -11960,7 +12051,8 @@ async function runAgentLoop(inputs) {
|
|
|
11960
12051
|
...usage !== void 0 ? { usage } : {},
|
|
11961
12052
|
...cost !== void 0 ? { cost } : {},
|
|
11962
12053
|
...ctx.error !== void 0 ? { error: ctx.error } : {},
|
|
11963
|
-
...ctx.stoppedAtIterationLimit === true ? { stoppedAtIterationLimit: true } : {}
|
|
12054
|
+
...ctx.stoppedAtIterationLimit === true ? { stoppedAtIterationLimit: true } : {},
|
|
12055
|
+
...ctx.stoppedByDoomLoop === true ? { stoppedByDoomLoop: true } : {}
|
|
11964
12056
|
};
|
|
11965
12057
|
} finally {
|
|
11966
12058
|
if (ctxRef !== void 0 && ctxRef.memoryProviderHandle !== void 0 && inputs.memoryProvider !== void 0) {
|
|
@@ -12119,8 +12211,26 @@ async function continueOrTerminate(inputs, ctx, llmOutput) {
|
|
|
12119
12211
|
}
|
|
12120
12212
|
}
|
|
12121
12213
|
pushToolConversationSteps(ctx, llmOutput.toolCalls, toolResults);
|
|
12214
|
+
if (await inspectDoomLoop(inputs, ctx, llmOutput.toolCalls) === "stop") return "done";
|
|
12122
12215
|
return handleToolErrorContinuation(inputs, ctx, toolResults);
|
|
12123
12216
|
}
|
|
12217
|
+
async function inspectDoomLoop(inputs, ctx, toolCalls) {
|
|
12218
|
+
if (ctx.doomLoop === void 0) return "continue";
|
|
12219
|
+
const verdict = firstDoomLoopVerdict(ctx.doomLoop, toolCalls);
|
|
12220
|
+
if (verdict.kind === "hard") {
|
|
12221
|
+
ctx.stoppedByDoomLoop = true;
|
|
12222
|
+
await emitAssistantTextStep(
|
|
12223
|
+
inputs,
|
|
12224
|
+
ctx,
|
|
12225
|
+
verdict.message ?? "Stopped: repeated identical tool calls made no progress."
|
|
12226
|
+
);
|
|
12227
|
+
return "stop";
|
|
12228
|
+
}
|
|
12229
|
+
if (verdict.kind === "soft") {
|
|
12230
|
+
ctx.messages.push({ role: "user", content: [{ type: "text", text: verdict.message ?? "" }] });
|
|
12231
|
+
}
|
|
12232
|
+
return "continue";
|
|
12233
|
+
}
|
|
12124
12234
|
|
|
12125
12235
|
// src/internal/llm/fallback-client.ts
|
|
12126
12236
|
init_errors();
|
|
@@ -13537,11 +13647,16 @@ function sanitizeToolInput(input, options) {
|
|
|
13537
13647
|
// src/internal/llm/hermes-tool-extract.ts
|
|
13538
13648
|
var HERMES_BLOCK = /<function=\s*([^>\s]+)\s*>([\s\S]*?)<\/tool_call>/g;
|
|
13539
13649
|
var HERMES_PARAM = /<parameter=\s*([^>\s]+)\s*>([\s\S]*?)<\/parameter>/g;
|
|
13540
|
-
function extractHermesToolCalls(content, makeId) {
|
|
13650
|
+
function extractHermesToolCalls(content, makeId, allowedToolNames) {
|
|
13651
|
+
const isPromoted = (name) => name.length > 0 && (allowedToolNames === void 0 || allowedToolNames.has(name));
|
|
13541
13652
|
const toolCalls = [];
|
|
13653
|
+
const droppedNames = [];
|
|
13542
13654
|
for (const block of content.matchAll(HERMES_BLOCK)) {
|
|
13543
13655
|
const name = (block[1] ?? "").trim();
|
|
13544
|
-
if (name
|
|
13656
|
+
if (!isPromoted(name)) {
|
|
13657
|
+
if (name.length > 0 && allowedToolNames !== void 0) droppedNames.push(name);
|
|
13658
|
+
continue;
|
|
13659
|
+
}
|
|
13545
13660
|
toolCalls.push({
|
|
13546
13661
|
type: "tool_use",
|
|
13547
13662
|
id: makeId(),
|
|
@@ -13549,8 +13664,11 @@ function extractHermesToolCalls(content, makeId) {
|
|
|
13549
13664
|
input: parseHermesParams(block[2] ?? "")
|
|
13550
13665
|
});
|
|
13551
13666
|
}
|
|
13552
|
-
const residualText = toolCalls.length === 0 ? content : content.replace(
|
|
13553
|
-
|
|
13667
|
+
const residualText = toolCalls.length === 0 ? content : content.replace(
|
|
13668
|
+
HERMES_BLOCK,
|
|
13669
|
+
(full, rawName) => isPromoted((rawName ?? "").trim()) ? "" : full
|
|
13670
|
+
).trim();
|
|
13671
|
+
return { toolCalls, residualText, droppedNames };
|
|
13554
13672
|
}
|
|
13555
13673
|
function parseHermesParams(inner) {
|
|
13556
13674
|
const input = {};
|
|
@@ -13634,7 +13752,10 @@ var OpenAIClient = class {
|
|
|
13634
13752
|
}
|
|
13635
13753
|
const accumulator = new OpenAIStreamAccumulator(
|
|
13636
13754
|
this.options.extractToolCallsFromContent ?? false,
|
|
13637
|
-
providerId
|
|
13755
|
+
providerId,
|
|
13756
|
+
// R5: request-scoped allowlist — leaked recovery only promotes a block whose name is a tool the
|
|
13757
|
+
// model was actually given. Empty set (no tools) recovers nothing.
|
|
13758
|
+
new Set(request.tools?.map((tool) => tool.name) ?? [])
|
|
13638
13759
|
);
|
|
13639
13760
|
for await (const record of parseSseStream(response.body, signal)) {
|
|
13640
13761
|
if (record.data === "[DONE]") break;
|
|
@@ -13664,13 +13785,18 @@ var OpenAIStreamAccumulator = class {
|
|
|
13664
13785
|
/**
|
|
13665
13786
|
* @param extractFromContent opt-in leaked-dialect safe-parse (theokit#58). Default false.
|
|
13666
13787
|
* @param providerName provider id, used only to label the recovery log line.
|
|
13788
|
+
* @param allowedToolNames R5 request-scoped allowlist — built from `request.tools` at `stream()`;
|
|
13789
|
+
* leaked recovery in `finish()` only promotes a block whose name is in this set. `undefined`
|
|
13790
|
+
* (direct construction) recovers all (back-compat); an empty set recovers nothing.
|
|
13667
13791
|
*/
|
|
13668
|
-
constructor(extractFromContent = false, providerName = "openai") {
|
|
13792
|
+
constructor(extractFromContent = false, providerName = "openai", allowedToolNames) {
|
|
13669
13793
|
this.extractFromContent = extractFromContent;
|
|
13670
13794
|
this.providerName = providerName;
|
|
13795
|
+
this.allowedToolNames = allowedToolNames;
|
|
13671
13796
|
}
|
|
13672
13797
|
extractFromContent;
|
|
13673
13798
|
providerName;
|
|
13799
|
+
allowedToolNames;
|
|
13674
13800
|
text = "";
|
|
13675
13801
|
stopReason = "end_turn";
|
|
13676
13802
|
inputTokens;
|
|
@@ -13741,7 +13867,8 @@ var OpenAIStreamAccumulator = class {
|
|
|
13741
13867
|
if (this.extractFromContent && toolCalls.length === 0) {
|
|
13742
13868
|
const recovered = extractHermesToolCalls(
|
|
13743
13869
|
this.text,
|
|
13744
|
-
() => `hermes-${globalThis.crypto.randomUUID()}
|
|
13870
|
+
() => `hermes-${globalThis.crypto.randomUUID()}`,
|
|
13871
|
+
this.allowedToolNames
|
|
13745
13872
|
);
|
|
13746
13873
|
if (recovered.toolCalls.length > 0) {
|
|
13747
13874
|
toolCalls.push(...recovered.toolCalls);
|
|
@@ -13749,6 +13876,12 @@ var OpenAIStreamAccumulator = class {
|
|
|
13749
13876
|
stopReason = "tool_use";
|
|
13750
13877
|
process.stderr.write(
|
|
13751
13878
|
`[theokit-sdk] recovered ${recovered.toolCalls.length} leaked tool call(s) from assistant content (provider="${this.providerName}", names=${recovered.toolCalls.map((c) => c.name).join(",")})
|
|
13879
|
+
`
|
|
13880
|
+
);
|
|
13881
|
+
}
|
|
13882
|
+
if (recovered.droppedNames.length > 0) {
|
|
13883
|
+
process.stderr.write(
|
|
13884
|
+
`[theokit-sdk] dropped ${recovered.droppedNames.length} leaked block(s) whose name is not a tool in the request (provider="${this.providerName}", names=${recovered.droppedNames.join(",")})
|
|
13752
13885
|
`
|
|
13753
13886
|
);
|
|
13754
13887
|
}
|
|
@@ -14681,6 +14814,8 @@ function buildLoopInputs(options, runId, userText) {
|
|
|
14681
14814
|
// M1-2: per-send iteration ceiling (validated above). The loop reads
|
|
14682
14815
|
// inputs.maxIterations (default 8 when unset).
|
|
14683
14816
|
...maxIterations !== void 0 ? { maxIterations } : {},
|
|
14817
|
+
// Doom-loop guard config (default on; `false` disables, object tunes thresholds).
|
|
14818
|
+
...options.sendOptions.doomLoop !== void 0 ? { doomLoop: options.sendOptions.doomLoop } : {},
|
|
14684
14819
|
// D315-D317 — tool lifecycle hooks (cost tracking + audit + retry/alert)
|
|
14685
14820
|
...options.agentOptions.onToolStart !== void 0 ? { onToolStart: options.agentOptions.onToolStart } : {},
|
|
14686
14821
|
...options.agentOptions.onToolEnd !== void 0 ? { onToolEnd: options.agentOptions.onToolEnd } : {},
|
|
@@ -14813,6 +14948,7 @@ var RealLocalRun = class extends FixtureRunBase {
|
|
|
14813
14948
|
if (output.usage !== void 0) this.script.usage = output.usage;
|
|
14814
14949
|
if (output.cost !== void 0) this.script.cost = output.cost;
|
|
14815
14950
|
if (output.stoppedAtIterationLimit === true) this.script.stoppedAtIterationLimit = true;
|
|
14951
|
+
if (output.stoppedByDoomLoop === true) this.script.stoppedByDoomLoop = true;
|
|
14816
14952
|
if (output.error !== void 0 && this.script.errorDetail === void 0) {
|
|
14817
14953
|
this.script.errorDetail = {
|
|
14818
14954
|
message: output.error.message,
|