@theokit/sdk 4.0.2 → 4.1.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 +6 -0
- package/dist/a2a/index.cjs +129 -97
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +129 -97
- package/dist/a2a/index.js.map +1 -1
- package/dist/{cron-L5QTlAtl.d.ts → cron-AzT5D0VP.d.ts} +89 -1
- package/dist/{cron-BfPhZjRJ.d.cts → cron-BlAjYOew.d.cts} +89 -1
- package/dist/cron.cjs +129 -97
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.d.cts +1 -1
- package/dist/cron.d.ts +1 -1
- package/dist/cron.js +129 -97
- package/dist/cron.js.map +1 -1
- package/dist/eval.cjs +129 -97
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +129 -97
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +129 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +129 -97
- package/dist/index.js.map +1 -1
- package/dist/internal/persistence/fs-session-store.d.cts +26 -0
- package/dist/internal/persistence/fs-session-store.d.ts +26 -0
- package/dist/internal/runtime/session/agent-session-store.d.ts +21 -13
- package/dist/types/agent.d.ts +10 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/session-store.d.ts +59 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { T as TheokitAgentError, B as BudgetOptions, a as BudgetHandle, b as BudgetSnapshot, E as ErrorMetadata } from './errors-CyC8jME3.cjs';
|
|
2
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-CyC8jME3.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, I as InlineSkill, B as BudgetTracker, n as MemoryProvider, o as MemoryId, p as PreToolCallDecision, q as StepResult, r as SDKProvider } from './cron-
|
|
4
|
-
export { s as ActiveMemoryPassArgs, t as ActiveMemoryPassResult, u as AgentMemory, v as BudgetCheck, w as BudgetTotal, x as BudgetUsageEvent, y as CloudEnv, z as CloudRepo, D as ContextBudget, E as ContextManagerKind, F as ContextSnapshot, H as ContextSource, J as ContextSourceStatus, K as CreateSkillSpec, N as Cron, O as CronCreateOptions, Q as CronGetOptions, R as CronJob, T as CronJobStatus, U as CronListOptions, V as CronOperationOptions, W as CronRunOptions, X as CronRuntime, Y as CronSchedulerStatus, Z as CronStartOptions, _ as GoalEvent, $ as GoalOptions, a0 as GoalResult, a1 as HookName, a2 as InvalidateCacheOptions, a3 as MemoryAdapter, a4 as MemoryAdapterCapabilities, a5 as MemoryContext, a6 as MemoryFact, a7 as MemoryProviderHandle, a8 as MemoryProviderInitOptions, a9 as MemoryRevision, aa as MemoryToolSchema, ab as MemoryTurnMessage, ac as PersonalityPreset, ad as PluginContext, ae as PostAssistantReplyContext, af as PreToolCallContext, ag as PreUserSendContext, ah as PreUserSendResult, ai as ProviderCapability, aj as ProviderRoute, ak as RecordSessionSummaryArgs, al as ResolvedProviderRoute, am as RunUntilIterator, an as SDKAgentPlugins, ao as SDKAgentSkillDetail, ap as SDKAgentSkills, aq as SDKArtifact, ar as SDKContextManager, as as SDKPluginMetadata, at as SDKProvidersManager, au as
|
|
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, I as InlineSkill, B as BudgetTracker, n as MemoryProvider, o as MemoryId, p as PreToolCallDecision, q as StepResult, r as SDKProvider } from './cron-BlAjYOew.cjs';
|
|
4
|
+
export { s as ActiveMemoryPassArgs, t as ActiveMemoryPassResult, u as AgentMemory, v as BudgetCheck, w as BudgetTotal, x as BudgetUsageEvent, y as CloudEnv, z as CloudRepo, D as ContextBudget, E as ContextManagerKind, F as ContextSnapshot, H as ContextSource, J as ContextSourceStatus, K as CreateSkillSpec, N as Cron, O as CronCreateOptions, Q as CronGetOptions, R as CronJob, T as CronJobStatus, U as CronListOptions, V as CronOperationOptions, W as CronRunOptions, X as CronRuntime, Y as CronSchedulerStatus, Z as CronStartOptions, _ as GoalEvent, $ as GoalOptions, a0 as GoalResult, a1 as HookName, a2 as InvalidateCacheOptions, a3 as MemoryAdapter, a4 as MemoryAdapterCapabilities, a5 as MemoryContext, a6 as MemoryFact, a7 as MemoryProviderHandle, a8 as MemoryProviderInitOptions, a9 as MemoryRevision, aa as MemoryToolSchema, ab as MemoryTurnMessage, ac as PersonalityPreset, ad as PluginContext, ae as PostAssistantReplyContext, af as PreToolCallContext, ag as PreUserSendContext, ah as PreUserSendResult, ai as ProviderCapability, aj as ProviderRoute, ak as RecordSessionSummaryArgs, al as ResolvedProviderRoute, am as RunUntilIterator, an as SDKAgentPlugins, ao as SDKAgentSkillDetail, ap as SDKAgentSkills, aq as SDKArtifact, ar as SDKContextManager, as as SDKPluginMetadata, at as SDKProvidersManager, au as SessionRecord, av as SessionStore, aw as SettingSource, ax as Skill, ay as SkillsResolver, az as SkillsResolverContext, aA as SystemPromptContext, aB as SystemPromptMemoryFact, aC as SystemPromptSkillRef, aD as TelemetrySettings } from './cron-BlAjYOew.cjs';
|
|
5
5
|
import { R as RunResult, M as ModelSelection, C as CustomTool, a as McpServerConfig, b as Run, P as Processor, T as ToolResultContentBlock, c as PermissionMode, d as PermissionEngine, e as RunEventSink, S as SDKMessage } from './run-BTvkk53K.cjs';
|
|
6
6
|
export { A as AgentConversationTurn, f as AssistantMessage, g as CompletionCheck, h as CompletionCheckResult, i as ConversationStep, j as ConversationTurn, k as CostBreakdown, l as CostSource, m as CostStatus, D as DoomLoopThresholds, G as GenerateOptions, n as GenerateRunResult, I as ImageBlock, o as InputProcessorContext, p as InteractionUpdate, q as McpAuthConfig, r as McpHttpServerConfig, s as McpOAuthConfig, t as McpStdioServerConfig, u as MessageOrigin, v as ModelParameterValue, O as OutputProcessorContext, w as PartialToolCallUpdate, x as PermissionAction, y as PermissionEngineOptions, z as PermissionRule, B as ProcessorControls, E as ProcessorTripwire, F as ProcessorViolation, H as RunCompactBoundaryEvent, J as RunCompletionCheckEvent, K as RunErrorDetail, L as RunEvent, N as RunGitInfo, Q as RunOperation, U as RunPermissionDeniedEvent, V as RunRateLimitEvent, W as RunStatus, X as RunTaskCompletedEvent, Y as RunTaskStartedEvent, Z as RunTaskUpdatedEvent, _ as RunToCompletionOptions, $ as RunToCompletionResult, a0 as RunToolProgressEvent, a1 as RunTripwireEvent, a2 as SDKAssistantMessage, a3 as SDKImage, a4 as SDKImageDimension, a5 as SDKObjectDelta, a6 as SDKRequestMessage, a7 as SDKStatusMessage, a8 as SDKSystemMessage, a9 as SDKTaskMessage, aa as SDKThinkingMessage, ab as SDKToolUseMessage, ac as SDKUserMessage, ad as SDKUserMessageEvent, ae as SendOptions, af as ShellCommand, ag as ShellConversationTurn, ah as ShellOutput, ai as ShellOutputDeltaUpdate, aj as StepCompletedUpdate, ak as StepStartedUpdate, al as StreamToCompletionResult, am as SummaryCompletedUpdate, an as SummaryStartedUpdate, ao as SummaryUpdate, ap as TextBlock, aq as TextDeltaUpdate, ar as ThinkingCompletedUpdate, as as ThinkingDeltaUpdate, at as ThinkingMessage, au as TokenDeltaUpdate, av as TokenUsage, aw as ToolCall, ax as ToolCallCompletedUpdate, ay as ToolCallStartedUpdate, az as ToolContextMessage, aA as ToolResult, aB as ToolResultGuardOptions, aC as ToolUseBlock, aD as TurnEndedUpdate, aE as UserMessage, aF as UserMessageAppendedUpdate, aG as applyMode, aH as emitRunEvent } from './run-BTvkk53K.cjs';
|
|
7
7
|
import * as zod from 'zod';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { T as TheokitAgentError, B as BudgetOptions, a as BudgetHandle, b as BudgetSnapshot, E as ErrorMetadata } from './errors-CLJtK0-A.js';
|
|
2
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-CLJtK0-A.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, I as InlineSkill, B as BudgetTracker, n as MemoryProvider, o as MemoryId, p as PreToolCallDecision, q as StepResult, r as SDKProvider } from './cron-
|
|
4
|
-
export { s as ActiveMemoryPassArgs, t as ActiveMemoryPassResult, u as AgentMemory, v as BudgetCheck, w as BudgetTotal, x as BudgetUsageEvent, y as CloudEnv, z as CloudRepo, D as ContextBudget, E as ContextManagerKind, F as ContextSnapshot, H as ContextSource, J as ContextSourceStatus, K as CreateSkillSpec, N as Cron, O as CronCreateOptions, Q as CronGetOptions, R as CronJob, T as CronJobStatus, U as CronListOptions, V as CronOperationOptions, W as CronRunOptions, X as CronRuntime, Y as CronSchedulerStatus, Z as CronStartOptions, _ as GoalEvent, $ as GoalOptions, a0 as GoalResult, a1 as HookName, a2 as InvalidateCacheOptions, a3 as MemoryAdapter, a4 as MemoryAdapterCapabilities, a5 as MemoryContext, a6 as MemoryFact, a7 as MemoryProviderHandle, a8 as MemoryProviderInitOptions, a9 as MemoryRevision, aa as MemoryToolSchema, ab as MemoryTurnMessage, ac as PersonalityPreset, ad as PluginContext, ae as PostAssistantReplyContext, af as PreToolCallContext, ag as PreUserSendContext, ah as PreUserSendResult, ai as ProviderCapability, aj as ProviderRoute, ak as RecordSessionSummaryArgs, al as ResolvedProviderRoute, am as RunUntilIterator, an as SDKAgentPlugins, ao as SDKAgentSkillDetail, ap as SDKAgentSkills, aq as SDKArtifact, ar as SDKContextManager, as as SDKPluginMetadata, at as SDKProvidersManager, au as
|
|
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, I as InlineSkill, B as BudgetTracker, n as MemoryProvider, o as MemoryId, p as PreToolCallDecision, q as StepResult, r as SDKProvider } from './cron-AzT5D0VP.js';
|
|
4
|
+
export { s as ActiveMemoryPassArgs, t as ActiveMemoryPassResult, u as AgentMemory, v as BudgetCheck, w as BudgetTotal, x as BudgetUsageEvent, y as CloudEnv, z as CloudRepo, D as ContextBudget, E as ContextManagerKind, F as ContextSnapshot, H as ContextSource, J as ContextSourceStatus, K as CreateSkillSpec, N as Cron, O as CronCreateOptions, Q as CronGetOptions, R as CronJob, T as CronJobStatus, U as CronListOptions, V as CronOperationOptions, W as CronRunOptions, X as CronRuntime, Y as CronSchedulerStatus, Z as CronStartOptions, _ as GoalEvent, $ as GoalOptions, a0 as GoalResult, a1 as HookName, a2 as InvalidateCacheOptions, a3 as MemoryAdapter, a4 as MemoryAdapterCapabilities, a5 as MemoryContext, a6 as MemoryFact, a7 as MemoryProviderHandle, a8 as MemoryProviderInitOptions, a9 as MemoryRevision, aa as MemoryToolSchema, ab as MemoryTurnMessage, ac as PersonalityPreset, ad as PluginContext, ae as PostAssistantReplyContext, af as PreToolCallContext, ag as PreUserSendContext, ah as PreUserSendResult, ai as ProviderCapability, aj as ProviderRoute, ak as RecordSessionSummaryArgs, al as ResolvedProviderRoute, am as RunUntilIterator, an as SDKAgentPlugins, ao as SDKAgentSkillDetail, ap as SDKAgentSkills, aq as SDKArtifact, ar as SDKContextManager, as as SDKPluginMetadata, at as SDKProvidersManager, au as SessionRecord, av as SessionStore, aw as SettingSource, ax as Skill, ay as SkillsResolver, az as SkillsResolverContext, aA as SystemPromptContext, aB as SystemPromptMemoryFact, aC as SystemPromptSkillRef, aD as TelemetrySettings } from './cron-AzT5D0VP.js';
|
|
5
5
|
import { R as RunResult, M as ModelSelection, C as CustomTool, a as McpServerConfig, b as Run, P as Processor, T as ToolResultContentBlock, c as PermissionMode, d as PermissionEngine, e as RunEventSink, S as SDKMessage } from './run-BTvkk53K.js';
|
|
6
6
|
export { A as AgentConversationTurn, f as AssistantMessage, g as CompletionCheck, h as CompletionCheckResult, i as ConversationStep, j as ConversationTurn, k as CostBreakdown, l as CostSource, m as CostStatus, D as DoomLoopThresholds, G as GenerateOptions, n as GenerateRunResult, I as ImageBlock, o as InputProcessorContext, p as InteractionUpdate, q as McpAuthConfig, r as McpHttpServerConfig, s as McpOAuthConfig, t as McpStdioServerConfig, u as MessageOrigin, v as ModelParameterValue, O as OutputProcessorContext, w as PartialToolCallUpdate, x as PermissionAction, y as PermissionEngineOptions, z as PermissionRule, B as ProcessorControls, E as ProcessorTripwire, F as ProcessorViolation, H as RunCompactBoundaryEvent, J as RunCompletionCheckEvent, K as RunErrorDetail, L as RunEvent, N as RunGitInfo, Q as RunOperation, U as RunPermissionDeniedEvent, V as RunRateLimitEvent, W as RunStatus, X as RunTaskCompletedEvent, Y as RunTaskStartedEvent, Z as RunTaskUpdatedEvent, _ as RunToCompletionOptions, $ as RunToCompletionResult, a0 as RunToolProgressEvent, a1 as RunTripwireEvent, a2 as SDKAssistantMessage, a3 as SDKImage, a4 as SDKImageDimension, a5 as SDKObjectDelta, a6 as SDKRequestMessage, a7 as SDKStatusMessage, a8 as SDKSystemMessage, a9 as SDKTaskMessage, aa as SDKThinkingMessage, ab as SDKToolUseMessage, ac as SDKUserMessage, ad as SDKUserMessageEvent, ae as SendOptions, af as ShellCommand, ag as ShellConversationTurn, ah as ShellOutput, ai as ShellOutputDeltaUpdate, aj as StepCompletedUpdate, ak as StepStartedUpdate, al as StreamToCompletionResult, am as SummaryCompletedUpdate, an as SummaryStartedUpdate, ao as SummaryUpdate, ap as TextBlock, aq as TextDeltaUpdate, ar as ThinkingCompletedUpdate, as as ThinkingDeltaUpdate, at as ThinkingMessage, au as TokenDeltaUpdate, av as TokenUsage, aw as ToolCall, ax as ToolCallCompletedUpdate, ay as ToolCallStartedUpdate, az as ToolContextMessage, aA as ToolResult, aB as ToolResultGuardOptions, aC as ToolUseBlock, aD as TurnEndedUpdate, aE as UserMessage, aF as UserMessageAppendedUpdate, aG as applyMode, aH as emitRunEvent } from './run-BTvkk53K.js';
|
|
7
7
|
import * as zod from 'zod';
|
package/dist/index.js
CHANGED
|
@@ -3517,6 +3517,72 @@ var init_cloud_tool_parity = __esm({
|
|
|
3517
3517
|
init_errors();
|
|
3518
3518
|
}
|
|
3519
3519
|
});
|
|
3520
|
+
|
|
3521
|
+
// src/internal/persistence/file-lock.ts
|
|
3522
|
+
async function getProperLockfile() {
|
|
3523
|
+
if (cached !== void 0) return cached;
|
|
3524
|
+
try {
|
|
3525
|
+
const mod = await import('proper-lockfile');
|
|
3526
|
+
if (!validateLockModule(mod)) {
|
|
3527
|
+
if (!warnedStructural) {
|
|
3528
|
+
warnedStructural = true;
|
|
3529
|
+
process.stderr.write(
|
|
3530
|
+
"[theokit-sdk] proper-lockfile: imported module does NOT expose the expected `lock`/`unlock` API surface. This may indicate a supply-chain compromise or an incompatible major version. Falling back to in-process mutex (no cross-process safety). Reinstall with: pnpm add proper-lockfile@^11\n"
|
|
3531
|
+
);
|
|
3532
|
+
}
|
|
3533
|
+
cached = null;
|
|
3534
|
+
return cached;
|
|
3535
|
+
}
|
|
3536
|
+
cached = mod;
|
|
3537
|
+
} catch {
|
|
3538
|
+
cached = null;
|
|
3539
|
+
}
|
|
3540
|
+
return cached;
|
|
3541
|
+
}
|
|
3542
|
+
function validateLockModule(mod) {
|
|
3543
|
+
if (mod === null || mod === void 0 || typeof mod !== "object") return false;
|
|
3544
|
+
const m = mod;
|
|
3545
|
+
return typeof m.lock === "function" && typeof m.unlock === "function";
|
|
3546
|
+
}
|
|
3547
|
+
async function withFileLock(path, fn, options) {
|
|
3548
|
+
const lib = await getProperLockfile();
|
|
3549
|
+
if (lib === null) {
|
|
3550
|
+
if (!warnedMissing) {
|
|
3551
|
+
warnedMissing = true;
|
|
3552
|
+
process.stderr.write(
|
|
3553
|
+
"[theokit-sdk] proper-lockfile not installed; cross-process file lock unavailable. Install with: pnpm add proper-lockfile\n"
|
|
3554
|
+
);
|
|
3555
|
+
}
|
|
3556
|
+
return withCwdMutex(`file-lock:${path}`, fn);
|
|
3557
|
+
}
|
|
3558
|
+
return withCwdMutex(`file-lock:${path}`, async () => {
|
|
3559
|
+
const release = await lib.lock(path, {
|
|
3560
|
+
// EC-1: companion lockfile, target path may not exist yet.
|
|
3561
|
+
lockfilePath: `${path}.lock`,
|
|
3562
|
+
realpath: false,
|
|
3563
|
+
stale: 3e4,
|
|
3564
|
+
retries: {
|
|
3565
|
+
retries: 5,
|
|
3566
|
+
factor: 1.5,
|
|
3567
|
+
minTimeout: 100,
|
|
3568
|
+
maxTimeout: 5e3
|
|
3569
|
+
}
|
|
3570
|
+
});
|
|
3571
|
+
try {
|
|
3572
|
+
return await fn();
|
|
3573
|
+
} finally {
|
|
3574
|
+
await release();
|
|
3575
|
+
}
|
|
3576
|
+
});
|
|
3577
|
+
}
|
|
3578
|
+
var cached, warnedMissing, warnedStructural;
|
|
3579
|
+
var init_file_lock = __esm({
|
|
3580
|
+
"src/internal/persistence/file-lock.ts"() {
|
|
3581
|
+
init_cwd_mutex();
|
|
3582
|
+
warnedMissing = false;
|
|
3583
|
+
warnedStructural = false;
|
|
3584
|
+
}
|
|
3585
|
+
});
|
|
3520
3586
|
function encodeProjectDir(cwd) {
|
|
3521
3587
|
return cwd.replace(/[^a-zA-Z0-9]/g, "-");
|
|
3522
3588
|
}
|
|
@@ -3743,70 +3809,31 @@ var init_session_transcript = __esm({
|
|
|
3743
3809
|
};
|
|
3744
3810
|
}
|
|
3745
3811
|
});
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
if (mod === null || mod === void 0 || typeof mod !== "object") return false;
|
|
3770
|
-
const m = mod;
|
|
3771
|
-
return typeof m.lock === "function" && typeof m.unlock === "function";
|
|
3772
|
-
}
|
|
3773
|
-
async function withFileLock(path, fn, options) {
|
|
3774
|
-
const lib = await getProperLockfile();
|
|
3775
|
-
if (lib === null) {
|
|
3776
|
-
if (!warnedMissing) {
|
|
3777
|
-
warnedMissing = true;
|
|
3778
|
-
process.stderr.write(
|
|
3779
|
-
"[theokit-sdk] proper-lockfile not installed; cross-process file lock unavailable. Install with: pnpm add proper-lockfile\n"
|
|
3780
|
-
);
|
|
3781
|
-
}
|
|
3782
|
-
return withCwdMutex(`file-lock:${path}`, fn);
|
|
3783
|
-
}
|
|
3784
|
-
return withCwdMutex(`file-lock:${path}`, async () => {
|
|
3785
|
-
const release = await lib.lock(path, {
|
|
3786
|
-
// EC-1: companion lockfile, target path may not exist yet.
|
|
3787
|
-
lockfilePath: `${path}.lock`,
|
|
3788
|
-
realpath: false,
|
|
3789
|
-
stale: 3e4,
|
|
3790
|
-
retries: {
|
|
3791
|
-
retries: 5,
|
|
3792
|
-
factor: 1.5,
|
|
3793
|
-
minTimeout: 100,
|
|
3794
|
-
maxTimeout: 5e3
|
|
3812
|
+
var FsSessionStore;
|
|
3813
|
+
var init_fs_session_store = __esm({
|
|
3814
|
+
"src/internal/persistence/fs-session-store.ts"() {
|
|
3815
|
+
init_file_lock();
|
|
3816
|
+
init_session_transcript();
|
|
3817
|
+
FsSessionStore = class {
|
|
3818
|
+
#baseDir;
|
|
3819
|
+
#cwd;
|
|
3820
|
+
constructor(options) {
|
|
3821
|
+
this.#baseDir = options.baseDir;
|
|
3822
|
+
this.#cwd = options.cwd;
|
|
3823
|
+
}
|
|
3824
|
+
async readRecords(agentId) {
|
|
3825
|
+
return readTranscript(transcriptPath(this.#baseDir, this.#cwd, agentId));
|
|
3826
|
+
}
|
|
3827
|
+
async appendRecords(agentId, records) {
|
|
3828
|
+
if (records.length === 0) return;
|
|
3829
|
+
const path = transcriptPath(this.#baseDir, this.#cwd, agentId);
|
|
3830
|
+
await mkdir(dirname(path), { recursive: true });
|
|
3831
|
+
await withFileLock(path, async () => {
|
|
3832
|
+
const prior = await readTranscript(path);
|
|
3833
|
+
await writeTranscript(path, [...prior, ...records]);
|
|
3834
|
+
});
|
|
3795
3835
|
}
|
|
3796
|
-
}
|
|
3797
|
-
try {
|
|
3798
|
-
return await fn();
|
|
3799
|
-
} finally {
|
|
3800
|
-
await release();
|
|
3801
|
-
}
|
|
3802
|
-
});
|
|
3803
|
-
}
|
|
3804
|
-
var cached, warnedMissing, warnedStructural;
|
|
3805
|
-
var init_file_lock = __esm({
|
|
3806
|
-
"src/internal/persistence/file-lock.ts"() {
|
|
3807
|
-
init_cwd_mutex();
|
|
3808
|
-
warnedMissing = false;
|
|
3809
|
-
warnedStructural = false;
|
|
3836
|
+
};
|
|
3810
3837
|
}
|
|
3811
3838
|
});
|
|
3812
3839
|
function getTheokitHome(cwd) {
|
|
@@ -5138,6 +5165,8 @@ var init_memory_path_selector = __esm({
|
|
|
5138
5165
|
PORT_MEMORY_PATH_ENV_VAR = "THEOKIT_PORT_MEMORY_PATH";
|
|
5139
5166
|
}
|
|
5140
5167
|
});
|
|
5168
|
+
|
|
5169
|
+
// src/internal/runtime/session/agent-session-store.ts
|
|
5141
5170
|
function seedTranscript(prior, opts) {
|
|
5142
5171
|
return SessionTranscript.fromRecords(prior, opts);
|
|
5143
5172
|
}
|
|
@@ -5175,8 +5204,8 @@ function appendConversation(transcript, conversation) {
|
|
|
5175
5204
|
if (toolResults.length > 0) transcript.appendToolResults(toolResults);
|
|
5176
5205
|
}
|
|
5177
5206
|
}
|
|
5178
|
-
async function readSessionMessages(
|
|
5179
|
-
const records = await
|
|
5207
|
+
async function readSessionMessages(store, agentId) {
|
|
5208
|
+
const records = await store.readRecords(agentId);
|
|
5180
5209
|
return reconstructMessages(records).map(narrowToSessionMessage);
|
|
5181
5210
|
}
|
|
5182
5211
|
function partToText(p) {
|
|
@@ -5193,37 +5222,31 @@ function narrowToSessionMessage(m) {
|
|
|
5193
5222
|
const text = m.content.map(partToText).filter((s) => s.length > 0).join("\n");
|
|
5194
5223
|
return { role, text };
|
|
5195
5224
|
}
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
await mkdir(dirname(path), { recursive: true });
|
|
5199
|
-
await withFileLock(path, async () => {
|
|
5200
|
-
const prior = await readTranscript(path);
|
|
5201
|
-
const transcript = seedTranscript(prior, { cwd: loc.cwd, sessionId, model: loc.model });
|
|
5202
|
-
transcript.appendUserTurn(turn.userText);
|
|
5203
|
-
appendConversation(transcript, turn.conversation);
|
|
5204
|
-
await writeTranscript(path, transcript.records());
|
|
5205
|
-
});
|
|
5225
|
+
function deltaRecords(transcript, priorLength) {
|
|
5226
|
+
return transcript.records().slice(priorLength);
|
|
5206
5227
|
}
|
|
5207
|
-
async function
|
|
5208
|
-
const
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5228
|
+
async function persistTurn(store, loc, sessionId, turn) {
|
|
5229
|
+
const prior = await store.readRecords(loc.agentId);
|
|
5230
|
+
const transcript = seedTranscript(prior, { cwd: loc.cwd, sessionId, model: loc.model });
|
|
5231
|
+
transcript.appendUserTurn(turn.userText);
|
|
5232
|
+
appendConversation(transcript, turn.conversation);
|
|
5233
|
+
await store.appendRecords(loc.agentId, deltaRecords(transcript, prior.length));
|
|
5234
|
+
}
|
|
5235
|
+
async function appendCompactBoundaryRecord(store, loc, sessionId, meta) {
|
|
5236
|
+
const prior = await store.readRecords(loc.agentId);
|
|
5237
|
+
const transcript = seedTranscript(prior, { cwd: loc.cwd, sessionId, model: loc.model });
|
|
5238
|
+
transcript.appendCompactBoundary(meta);
|
|
5239
|
+
await store.appendRecords(loc.agentId, deltaRecords(transcript, prior.length));
|
|
5216
5240
|
}
|
|
5217
5241
|
var init_agent_session_store = __esm({
|
|
5218
5242
|
"src/internal/runtime/session/agent-session-store.ts"() {
|
|
5219
|
-
init_file_lock();
|
|
5220
5243
|
init_session_transcript();
|
|
5221
5244
|
}
|
|
5222
5245
|
});
|
|
5223
5246
|
|
|
5224
5247
|
// src/internal/runtime/session/agent-session.ts
|
|
5225
|
-
function transcriptKey(
|
|
5226
|
-
return `${
|
|
5248
|
+
function transcriptKey(cwd, agentId) {
|
|
5249
|
+
return `${cwd}::${agentId}`;
|
|
5227
5250
|
}
|
|
5228
5251
|
function appendSessionMessage(agentId, message) {
|
|
5229
5252
|
const existing = sessions.get(agentId) ?? [];
|
|
@@ -5233,15 +5256,15 @@ function appendSessionMessage(agentId, message) {
|
|
|
5233
5256
|
function getSessionMessages(agentId) {
|
|
5234
5257
|
return sessions.get(agentId) ?? [];
|
|
5235
5258
|
}
|
|
5236
|
-
function persistTurnToTranscript(loc, sessionId, turn, onCompact) {
|
|
5237
|
-
const key2 = transcriptKey(loc.
|
|
5259
|
+
function persistTurnToTranscript(store, loc, sessionId, turn, onCompact) {
|
|
5260
|
+
const key2 = transcriptKey(loc.cwd, loc.agentId);
|
|
5238
5261
|
const chained = (pendingWrites.get(key2) ?? Promise.resolve()).then(async () => {
|
|
5239
5262
|
try {
|
|
5240
|
-
await persistTurn(loc, sessionId, turn);
|
|
5263
|
+
await persistTurn(store, loc, sessionId, turn);
|
|
5241
5264
|
const count = (recordCounts.get(key2) ?? 0) + 1;
|
|
5242
5265
|
recordCounts.set(key2, count);
|
|
5243
5266
|
if (count % COMPACTION_CHECK_INTERVAL === 0) {
|
|
5244
|
-
await appendCompactBoundaryRecord(loc, sessionId, {
|
|
5267
|
+
await appendCompactBoundaryRecord(store, loc, sessionId, {
|
|
5245
5268
|
preTokens: 0,
|
|
5246
5269
|
trigger: "auto"
|
|
5247
5270
|
});
|
|
@@ -5264,10 +5287,10 @@ function persistTurnToTranscript(loc, sessionId, turn, onCompact) {
|
|
|
5264
5287
|
);
|
|
5265
5288
|
}
|
|
5266
5289
|
async function hydrateSession(agentId, loc) {
|
|
5267
|
-
const key2 = transcriptKey(loc.
|
|
5290
|
+
const key2 = transcriptKey(loc.cwd, agentId);
|
|
5268
5291
|
if (hydratedKeys.has(key2)) return;
|
|
5269
5292
|
hydratedKeys.add(key2);
|
|
5270
|
-
const persisted = await readSessionMessages(loc.
|
|
5293
|
+
const persisted = await readSessionMessages(loc.store, agentId);
|
|
5271
5294
|
if (persisted.length === 0) return;
|
|
5272
5295
|
if (!sessions.has(agentId) || sessions.get(agentId)?.length === 0) {
|
|
5273
5296
|
sessions.set(agentId, persisted);
|
|
@@ -5302,7 +5325,7 @@ async function runPostRunLifecycle(inputs) {
|
|
|
5302
5325
|
userText,
|
|
5303
5326
|
agentId,
|
|
5304
5327
|
workspaceCwd,
|
|
5305
|
-
|
|
5328
|
+
sessionStore,
|
|
5306
5329
|
model,
|
|
5307
5330
|
onRunEvent,
|
|
5308
5331
|
hooksExecutor,
|
|
@@ -5321,7 +5344,8 @@ async function runPostRunLifecycle(inputs) {
|
|
|
5321
5344
|
}
|
|
5322
5345
|
const conversation = await safeConversation(run);
|
|
5323
5346
|
persistTurnToTranscript(
|
|
5324
|
-
|
|
5347
|
+
sessionStore,
|
|
5348
|
+
{ cwd: workspaceCwd, agentId, model },
|
|
5325
5349
|
agentId,
|
|
5326
5350
|
{ userText, conversation },
|
|
5327
5351
|
onRunEvent !== void 0 ? () => emitRunEvent(onRunEvent, { type: "compact_boundary", trigger: "auto" }) : void 0
|
|
@@ -18136,6 +18160,7 @@ var init_local_agent = __esm({
|
|
|
18136
18160
|
init_errors();
|
|
18137
18161
|
init_ids();
|
|
18138
18162
|
init_cwd_mutex();
|
|
18163
|
+
init_fs_session_store();
|
|
18139
18164
|
init_session_transcript();
|
|
18140
18165
|
init_store();
|
|
18141
18166
|
init_manager();
|
|
@@ -18179,6 +18204,12 @@ var init_local_agent = __esm({
|
|
|
18179
18204
|
* `~/.theokit`; set `local.baseDir: "~/.claude"` for Claude Code CLI interop.
|
|
18180
18205
|
*/
|
|
18181
18206
|
transcriptBaseDir;
|
|
18207
|
+
/**
|
|
18208
|
+
* SE41 — the session record store. Defaults to the FS transcript store (byte-
|
|
18209
|
+
* identical to SE40); `local.sessionStore` injects an external store (Postgres /
|
|
18210
|
+
* Redis / KV) so resume works on serverless (ephemeral FS) and multi-host.
|
|
18211
|
+
*/
|
|
18212
|
+
sessionStore;
|
|
18182
18213
|
/**
|
|
18183
18214
|
* D319: lifecycle AbortController fired on `dispose()`. Composed with the
|
|
18184
18215
|
* caller's `SendOptions.signal` via `anySignal` so the LLM `fetch()`
|
|
@@ -18221,6 +18252,7 @@ var init_local_agent = __esm({
|
|
|
18221
18252
|
this.options = options;
|
|
18222
18253
|
this.workspaceCwd = resolveCwd(options.local?.cwd);
|
|
18223
18254
|
this.transcriptBaseDir = resolveBaseDir(options.local?.baseDir);
|
|
18255
|
+
this.sessionStore = options.local?.sessionStore ?? new FsSessionStore({ baseDir: this.transcriptBaseDir, cwd: this.workspaceCwd });
|
|
18224
18256
|
this.settingSourcesIncludeProject = includesSetting(options, "project");
|
|
18225
18257
|
this.settingSourcesIncludePlugins = includesSetting(options, "plugins");
|
|
18226
18258
|
const sub = bootstrapSubmanagers({
|
|
@@ -18268,7 +18300,7 @@ var init_local_agent = __esm({
|
|
|
18268
18300
|
this.settingSourcesIncludeProject,
|
|
18269
18301
|
this.options.agents
|
|
18270
18302
|
);
|
|
18271
|
-
await hydrateSession(this.agentId, {
|
|
18303
|
+
await hydrateSession(this.agentId, { store: this.sessionStore, cwd: this.workspaceCwd });
|
|
18272
18304
|
await this.personalityStore.hydrate(this.agentId);
|
|
18273
18305
|
}
|
|
18274
18306
|
/** T4.2 — expose PluginManager so agent-loop can fire pre_tool_call hooks. @internal */
|
|
@@ -18324,7 +18356,7 @@ var init_local_agent = __esm({
|
|
|
18324
18356
|
userText,
|
|
18325
18357
|
agentId: this.agentId,
|
|
18326
18358
|
workspaceCwd: this.workspaceCwd,
|
|
18327
|
-
|
|
18359
|
+
sessionStore: this.sessionStore,
|
|
18328
18360
|
model: this.model?.id ?? "unknown",
|
|
18329
18361
|
...options.onRunEvent !== void 0 ? { onRunEvent: options.onRunEvent } : {},
|
|
18330
18362
|
hooksExecutor: this.hooksExecutor,
|