actoviq-agent-sdk 0.4.7 → 0.4.8
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 +17 -1
- package/README-zh.md +8 -5
- package/README.md +9 -6
- package/assets/actoviq-icon.png +0 -0
- package/dist/src/browser/actoviqBrowserSession.d.ts +137 -0
- package/dist/src/browser/actoviqBrowserSession.d.ts.map +1 -0
- package/dist/src/browser/actoviqBrowserSession.js +623 -0
- package/dist/src/browser/actoviqBrowserSession.js.map +1 -0
- package/dist/src/browser/actoviqBrowserTools.d.ts +80 -0
- package/dist/src/browser/actoviqBrowserTools.d.ts.map +1 -0
- package/dist/src/browser/actoviqBrowserTools.js +177 -0
- package/dist/src/browser/actoviqBrowserTools.js.map +1 -0
- package/dist/src/browser/browserSettings.d.ts +8 -0
- package/dist/src/browser/browserSettings.d.ts.map +1 -0
- package/dist/src/browser/browserSettings.js +47 -0
- package/dist/src/browser/browserSettings.js.map +1 -0
- package/dist/src/cli/actoviq-react.js +144 -4
- package/dist/src/cli/actoviq-react.js.map +1 -1
- package/dist/src/computer/actoviqComputerUse.d.ts.map +1 -1
- package/dist/src/computer/actoviqComputerUse.js +226 -40
- package/dist/src/computer/actoviqComputerUse.js.map +1 -1
- package/dist/src/computer/e2bComputerUse.d.ts +57 -0
- package/dist/src/computer/e2bComputerUse.d.ts.map +1 -0
- package/dist/src/computer/e2bComputerUse.js +401 -0
- package/dist/src/computer/e2bComputerUse.js.map +1 -0
- package/dist/src/config/agentProfiles.d.ts +8 -1
- package/dist/src/config/agentProfiles.d.ts.map +1 -1
- package/dist/src/config/agentProfiles.js +86 -4
- package/dist/src/config/agentProfiles.js.map +1 -1
- package/dist/src/config/projectSessionDirectory.d.ts +22 -0
- package/dist/src/config/projectSessionDirectory.d.ts.map +1 -1
- package/dist/src/config/projectSessionDirectory.js +512 -46
- package/dist/src/config/projectSessionDirectory.js.map +1 -1
- package/dist/src/config/resolveRuntimeConfig.d.ts.map +1 -1
- package/dist/src/config/resolveRuntimeConfig.js +12 -7
- package/dist/src/config/resolveRuntimeConfig.js.map +1 -1
- package/dist/src/gui/actoviqGui.d.ts +3 -0
- package/dist/src/gui/actoviqGui.d.ts.map +1 -1
- package/dist/src/gui/actoviqGui.js +7247 -997
- package/dist/src/gui/actoviqGui.js.map +1 -1
- package/dist/src/gui/electronMain.js +21 -4
- package/dist/src/gui/electronMain.js.map +1 -1
- package/dist/src/gui/externalCliAgentMonitor.d.ts +15 -0
- package/dist/src/gui/externalCliAgentMonitor.d.ts.map +1 -0
- package/dist/src/gui/externalCliAgentMonitor.js +133 -0
- package/dist/src/gui/externalCliAgentMonitor.js.map +1 -0
- package/dist/src/gui/projectWorkbench.d.ts +2 -0
- package/dist/src/gui/projectWorkbench.d.ts.map +1 -1
- package/dist/src/gui/projectWorkbench.js +66 -1
- package/dist/src/gui/projectWorkbench.js.map +1 -1
- package/dist/src/gui/transcript/clientBundle.d.ts.map +1 -1
- package/dist/src/gui/transcript/clientBundle.js +157 -17
- package/dist/src/gui/transcript/clientBundle.js.map +1 -1
- package/dist/src/gui/transcript/parts.d.ts.map +1 -1
- package/dist/src/gui/transcript/parts.js +28 -0
- package/dist/src/gui/transcript/parts.js.map +1 -1
- package/dist/src/index.d.ts +36 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +22 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/parity/actoviqBridgeSdk.d.ts +13 -1
- package/dist/src/parity/actoviqBridgeSdk.d.ts.map +1 -1
- package/dist/src/parity/actoviqBridgeSdk.js +1022 -83
- package/dist/src/parity/actoviqBridgeSdk.js.map +1 -1
- package/dist/src/parity/bridgeConfigs.d.ts +15 -0
- package/dist/src/parity/bridgeConfigs.d.ts.map +1 -1
- package/dist/src/parity/bridgeConfigs.js +112 -3
- package/dist/src/parity/bridgeConfigs.js.map +1 -1
- package/dist/src/parity/bridgeEventAdapter.d.ts +5 -1
- package/dist/src/parity/bridgeEventAdapter.d.ts.map +1 -1
- package/dist/src/parity/bridgeEventAdapter.js +65 -12
- package/dist/src/parity/bridgeEventAdapter.js.map +1 -1
- package/dist/src/parity/bridgeExecResolver.d.ts +10 -11
- package/dist/src/parity/bridgeExecResolver.d.ts.map +1 -1
- package/dist/src/parity/bridgeExecResolver.js +40 -23
- package/dist/src/parity/bridgeExecResolver.js.map +1 -1
- package/dist/src/parity/bridgeProcessTree.d.ts +3 -0
- package/dist/src/parity/bridgeProcessTree.d.ts.map +1 -0
- package/dist/src/parity/bridgeProcessTree.js +83 -0
- package/dist/src/parity/bridgeProcessTree.js.map +1 -0
- package/dist/src/parity/bridgeProviders.d.ts +16 -2
- package/dist/src/parity/bridgeProviders.d.ts.map +1 -1
- package/dist/src/parity/bridgeProviders.js +482 -100
- package/dist/src/parity/bridgeProviders.js.map +1 -1
- package/dist/src/parity/codewhaleRuntimeAdapter.d.ts +18 -0
- package/dist/src/parity/codewhaleRuntimeAdapter.d.ts.map +1 -0
- package/dist/src/parity/codewhaleRuntimeAdapter.js +350 -0
- package/dist/src/parity/codewhaleRuntimeAdapter.js.map +1 -0
- package/dist/src/parity/crushManagedClient.d.ts +84 -0
- package/dist/src/parity/crushManagedClient.d.ts.map +1 -0
- package/dist/src/parity/crushManagedClient.js +978 -0
- package/dist/src/parity/crushManagedClient.js.map +1 -0
- package/dist/src/parity/crushSessionHistory.d.ts +53 -0
- package/dist/src/parity/crushSessionHistory.d.ts.map +1 -0
- package/dist/src/parity/crushSessionHistory.js +358 -0
- package/dist/src/parity/crushSessionHistory.js.map +1 -0
- package/dist/src/parity/externalCliAuth.d.ts +23 -0
- package/dist/src/parity/externalCliAuth.d.ts.map +1 -0
- package/dist/src/parity/externalCliAuth.js +268 -0
- package/dist/src/parity/externalCliAuth.js.map +1 -0
- package/dist/src/parity/externalCliRuntimeManager.d.ts +138 -0
- package/dist/src/parity/externalCliRuntimeManager.d.ts.map +1 -0
- package/dist/src/parity/externalCliRuntimeManager.js +527 -0
- package/dist/src/parity/externalCliRuntimeManager.js.map +1 -0
- package/dist/src/parity/externalCliSessions.d.ts +90 -0
- package/dist/src/parity/externalCliSessions.d.ts.map +1 -0
- package/dist/src/parity/externalCliSessions.js +1436 -0
- package/dist/src/parity/externalCliSessions.js.map +1 -0
- package/dist/src/parity/reasonixAcpSession.d.ts +35 -0
- package/dist/src/parity/reasonixAcpSession.d.ts.map +1 -0
- package/dist/src/parity/reasonixAcpSession.js +472 -0
- package/dist/src/parity/reasonixAcpSession.js.map +1 -0
- package/dist/src/parity/reasonixManagedClient.d.ts +56 -0
- package/dist/src/parity/reasonixManagedClient.d.ts.map +1 -0
- package/dist/src/parity/reasonixManagedClient.js +293 -0
- package/dist/src/parity/reasonixManagedClient.js.map +1 -0
- package/dist/src/parity/reasonixSessionParser.d.ts +50 -0
- package/dist/src/parity/reasonixSessionParser.d.ts.map +1 -0
- package/dist/src/parity/reasonixSessionParser.js +440 -0
- package/dist/src/parity/reasonixSessionParser.js.map +1 -0
- package/dist/src/plugins/githubPlugin.d.ts +64 -0
- package/dist/src/plugins/githubPlugin.d.ts.map +1 -0
- package/dist/src/plugins/githubPlugin.js +261 -0
- package/dist/src/plugins/githubPlugin.js.map +1 -0
- package/dist/src/plugins/kimiWebBridgePlugin.d.ts +32 -0
- package/dist/src/plugins/kimiWebBridgePlugin.d.ts.map +1 -0
- package/dist/src/plugins/kimiWebBridgePlugin.js +214 -0
- package/dist/src/plugins/kimiWebBridgePlugin.js.map +1 -0
- package/dist/src/plugins/managedPluginCatalog.d.ts +47 -0
- package/dist/src/plugins/managedPluginCatalog.d.ts.map +1 -0
- package/dist/src/plugins/managedPluginCatalog.js +399 -0
- package/dist/src/plugins/managedPluginCatalog.js.map +1 -0
- package/dist/src/plugins/managedPluginHealth.d.ts +9 -0
- package/dist/src/plugins/managedPluginHealth.d.ts.map +1 -0
- package/dist/src/plugins/managedPluginHealth.js +149 -0
- package/dist/src/plugins/managedPluginHealth.js.map +1 -0
- package/dist/src/plugins/managedPluginRuntime.d.ts +14 -0
- package/dist/src/plugins/managedPluginRuntime.d.ts.map +1 -0
- package/dist/src/plugins/managedPluginRuntime.js +331 -0
- package/dist/src/plugins/managedPluginRuntime.js.map +1 -0
- package/dist/src/plugins/ocrPlugin.d.ts +46 -0
- package/dist/src/plugins/ocrPlugin.d.ts.map +1 -0
- package/dist/src/plugins/ocrPlugin.js +464 -0
- package/dist/src/plugins/ocrPlugin.js.map +1 -0
- package/dist/src/provider/client.d.ts +7 -1
- package/dist/src/provider/client.d.ts.map +1 -1
- package/dist/src/provider/client.js +61 -6
- package/dist/src/provider/client.js.map +1 -1
- package/dist/src/provider/openai-client.d.ts.map +1 -1
- package/dist/src/provider/openai-client.js +49 -3
- package/dist/src/provider/openai-client.js.map +1 -1
- package/dist/src/runtime/actoviqAgentExecutions.d.ts +85 -0
- package/dist/src/runtime/actoviqAgentExecutions.d.ts.map +1 -0
- package/dist/src/runtime/actoviqAgentExecutions.js +479 -0
- package/dist/src/runtime/actoviqAgentExecutions.js.map +1 -0
- package/dist/src/runtime/actoviqAgents.d.ts +15 -12
- package/dist/src/runtime/actoviqAgents.d.ts.map +1 -1
- package/dist/src/runtime/actoviqAgents.js +15 -0
- package/dist/src/runtime/actoviqAgents.js.map +1 -1
- package/dist/src/runtime/actoviqBackgroundTasks.d.ts +17 -2
- package/dist/src/runtime/actoviqBackgroundTasks.d.ts.map +1 -1
- package/dist/src/runtime/actoviqBackgroundTasks.js +291 -104
- package/dist/src/runtime/actoviqBackgroundTasks.js.map +1 -1
- package/dist/src/runtime/actoviqCompact.d.ts.map +1 -1
- package/dist/src/runtime/actoviqCompact.js +10 -75
- package/dist/src/runtime/actoviqCompact.js.map +1 -1
- package/dist/src/runtime/actoviqSkills.d.ts +14 -1
- package/dist/src/runtime/actoviqSkills.d.ts.map +1 -1
- package/dist/src/runtime/actoviqSkills.js +27 -2
- package/dist/src/runtime/actoviqSkills.js.map +1 -1
- package/dist/src/runtime/agentClient.d.ts +16 -2
- package/dist/src/runtime/agentClient.d.ts.map +1 -1
- package/dist/src/runtime/agentClient.js +745 -207
- package/dist/src/runtime/agentClient.js.map +1 -1
- package/dist/src/runtime/agentExecution.d.ts +196 -0
- package/dist/src/runtime/agentExecution.d.ts.map +1 -0
- package/dist/src/runtime/agentExecution.js +360 -0
- package/dist/src/runtime/agentExecution.js.map +1 -0
- package/dist/src/runtime/agentRuntimeDiscovery.d.ts +8 -2
- package/dist/src/runtime/agentRuntimeDiscovery.d.ts.map +1 -1
- package/dist/src/runtime/agentRuntimeDiscovery.js +30 -18
- package/dist/src/runtime/agentRuntimeDiscovery.js.map +1 -1
- package/dist/src/runtime/conversationEngine.d.ts +2 -1
- package/dist/src/runtime/conversationEngine.d.ts.map +1 -1
- package/dist/src/runtime/conversationEngine.js +66 -50
- package/dist/src/runtime/conversationEngine.js.map +1 -1
- package/dist/src/runtime/externalSkillCatalog.d.ts +107 -0
- package/dist/src/runtime/externalSkillCatalog.d.ts.map +1 -0
- package/dist/src/runtime/externalSkillCatalog.js +895 -0
- package/dist/src/runtime/externalSkillCatalog.js.map +1 -0
- package/dist/src/runtime/externalSkillPreferences.d.ts +25 -0
- package/dist/src/runtime/externalSkillPreferences.d.ts.map +1 -0
- package/dist/src/runtime/externalSkillPreferences.js +132 -0
- package/dist/src/runtime/externalSkillPreferences.js.map +1 -0
- package/dist/src/runtime/externalSkillRuntime.d.ts +31 -0
- package/dist/src/runtime/externalSkillRuntime.d.ts.map +1 -0
- package/dist/src/runtime/externalSkillRuntime.js +129 -0
- package/dist/src/runtime/externalSkillRuntime.js.map +1 -0
- package/dist/src/runtime/sessionTurnCoordinator.d.ts +2 -2
- package/dist/src/runtime/sessionTurnCoordinator.js +2 -2
- package/dist/src/storage/agentExecutionStore.d.ts +31 -0
- package/dist/src/storage/agentExecutionStore.d.ts.map +1 -0
- package/dist/src/storage/agentExecutionStore.js +413 -0
- package/dist/src/storage/agentExecutionStore.js.map +1 -0
- package/dist/src/storage/backgroundTaskStore.d.ts +5 -0
- package/dist/src/storage/backgroundTaskStore.d.ts.map +1 -1
- package/dist/src/storage/backgroundTaskStore.js +79 -3
- package/dist/src/storage/backgroundTaskStore.js.map +1 -1
- package/dist/src/storage/sessionStore.d.ts +8 -0
- package/dist/src/storage/sessionStore.d.ts.map +1 -1
- package/dist/src/storage/sessionStore.js +134 -18
- package/dist/src/storage/sessionStore.js.map +1 -1
- package/dist/src/team/teamGraphLayout.d.ts +53 -1
- package/dist/src/team/teamGraphLayout.d.ts.map +1 -1
- package/dist/src/team/teamGraphLayout.js +127 -1
- package/dist/src/team/teamGraphLayout.js.map +1 -1
- package/dist/src/team/teamGraphScaffold.d.ts.map +1 -1
- package/dist/src/team/teamGraphScaffold.js +31 -0
- package/dist/src/team/teamGraphScaffold.js.map +1 -1
- package/dist/src/team/teamGraphV3.d.ts +1 -0
- package/dist/src/team/teamGraphV3.d.ts.map +1 -1
- package/dist/src/team/teamGraphV3.js +24 -5
- package/dist/src/team/teamGraphV3.js.map +1 -1
- package/dist/src/team/teamPropose.d.ts +19 -0
- package/dist/src/team/teamPropose.d.ts.map +1 -0
- package/dist/src/team/teamPropose.js +126 -0
- package/dist/src/team/teamPropose.js.map +1 -0
- package/dist/src/tools/actoviqCoreTools.d.ts.map +1 -1
- package/dist/src/tools/actoviqCoreTools.js +3 -1
- package/dist/src/tools/actoviqCoreTools.js.map +1 -1
- package/dist/src/tools/exaSearch.d.ts +56 -0
- package/dist/src/tools/exaSearch.d.ts.map +1 -0
- package/dist/src/tools/exaSearch.js +170 -0
- package/dist/src/tools/exaSearch.js.map +1 -0
- package/dist/src/tools/tavilySearch.d.ts +34 -1
- package/dist/src/tools/tavilySearch.d.ts.map +1 -1
- package/dist/src/tools/tavilySearch.js +69 -54
- package/dist/src/tools/tavilySearch.js.map +1 -1
- package/dist/src/tools/todo/TodoWriteTool.d.ts +1 -1
- package/dist/src/tui/actoviqTui.d.ts +3 -1
- package/dist/src/tui/actoviqTui.d.ts.map +1 -1
- package/dist/src/tui/actoviqTui.js +1208 -92
- package/dist/src/tui/actoviqTui.js.map +1 -1
- package/dist/src/types.d.ts +223 -14
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/ui/agentExecutionView.d.ts +111 -0
- package/dist/src/ui/agentExecutionView.d.ts.map +1 -0
- package/dist/src/ui/agentExecutionView.js +442 -0
- package/dist/src/ui/agentExecutionView.js.map +1 -0
- package/dist/src/ui/commandSurface.d.ts +2 -0
- package/dist/src/ui/commandSurface.d.ts.map +1 -1
- package/dist/src/ui/commandSurface.js +38 -3
- package/dist/src/ui/commandSurface.js.map +1 -1
- package/dist/src/workflow-v2/localIsolatedProcessExecutor.d.ts.map +1 -1
- package/dist/src/workflow-v2/localIsolatedProcessExecutor.js +6 -2
- package/dist/src/workflow-v2/localIsolatedProcessExecutor.js.map +1 -1
- package/package.json +35 -7
|
@@ -5,6 +5,7 @@ import { promisify } from 'node:util';
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { createActoviqBuddyApi } from '../buddy/actoviqBuddy.js';
|
|
7
7
|
import { createActoviqComputerUseMcpServer, createActoviqComputerUseTools, } from '../computer/actoviqComputerUse.js';
|
|
8
|
+
import { createActoviqBrowserUseMcpServer, createActoviqBrowserTools, } from '../browser/actoviqBrowserTools.js';
|
|
8
9
|
import { resolveRuntimeConfig } from '../config/resolveRuntimeConfig.js';
|
|
9
10
|
import { resolveActoviqModelReference } from '../config/modelTiers.js';
|
|
10
11
|
import { recordCompatUsage } from '../compat/diagnostics.js';
|
|
@@ -14,6 +15,8 @@ import { appendMessagesToTranscript } from '../memory/actoviqTranscriptLogger.js
|
|
|
14
15
|
import { createActoviqDreamApi, ensureActoviqDreamLayout, isActoviqDreamEligibleSession, rollbackActoviqConsolidationLock, } from '../memory/actoviqDream.js';
|
|
15
16
|
import { ACTOVIQ_SESSION_MEMORY_STATE_KEY, evaluateActoviqSessionMemoryProgress, filterActoviqMessagesForSessionMemory, parseActoviqSessionMemoryRuntimeState, sanitizeActoviqSessionMemoryOutput, serializeActoviqSessionMemoryRuntimeState, } from '../memory/actoviqSessionMemoryState.js';
|
|
16
17
|
import { McpConnectionManager } from '../mcp/connectionManager.js';
|
|
18
|
+
import { RunAbortedError } from '../errors.js';
|
|
19
|
+
import { AgentExecutionStore } from '../storage/agentExecutionStore.js';
|
|
17
20
|
import { BackgroundTaskStore } from '../storage/backgroundTaskStore.js';
|
|
18
21
|
import { MailboxStore } from '../storage/mailboxStore.js';
|
|
19
22
|
import { SessionStore } from '../storage/sessionStore.js';
|
|
@@ -25,7 +28,8 @@ import { createGitWorktreeWorkspace, } from '../workspace/actoviqWorkspace.js';
|
|
|
25
28
|
import { ACTOVIQ_RUN_STATE_KEY, ActoviqAgentsApi, createActoviqRunToolState, createActoviqTaskTool, summarizeActoviqAgentDefinition, } from './actoviqAgents.js';
|
|
26
29
|
import { getDefaultActoviqAgents } from './defaultActoviqAgents.js';
|
|
27
30
|
import { loadActoviqAgentDefinitions } from './actoviqAgentDefinitions.js';
|
|
28
|
-
import { ActoviqSkillsApi, loadActoviqSkillDefinitions, resolveActoviqSkillPrompt, skillPathsMatch, summarizeActoviqSkillDefinition, } from './actoviqSkills.js';
|
|
31
|
+
import { ActoviqSkillsApi, getDefaultActoviqBundledSkills, loadActoviqSkillDefinitions, resolveActoviqSkillPrompt, skillPathsMatch, summarizeActoviqSkillDefinition, } from './actoviqSkills.js';
|
|
32
|
+
import { loadActoviqExternalSkillDefinitions } from './externalSkillRuntime.js';
|
|
29
33
|
import { ActoviqBackgroundTaskManager, ActoviqBackgroundTasksApi, } from './actoviqBackgroundTasks.js';
|
|
30
34
|
import { ActoviqContextApi, ActoviqSlashCommandsApi, } from './actoviqSlashCommands.js';
|
|
31
35
|
import { compactActoviqSession, getPersistedActoviqCompactHistory, getPersistedActoviqCompactState, isActoviqPromptTooLongError, recordActoviqLoopCompactionsOnSession, trackRecentFile, trackRecentSkill, } from './actoviqCompact.js';
|
|
@@ -46,6 +50,18 @@ import { asError, createId, deepClone, isRecord, nowIso, truncateText } from './
|
|
|
46
50
|
import { tool } from './tools.js';
|
|
47
51
|
import { buildInvokedSkillMessages, buildRelevantMemoryMessages, extractTextFromContent, } from './messageUtils.js';
|
|
48
52
|
import { AgentSession } from './agentSession.js';
|
|
53
|
+
import { ACTOVIQ_EXECUTION_ID_KEY, ACTOVIQ_PARENT_EXECUTION_ID_KEY, ACTOVIQ_ROOT_EXECUTION_ID_KEY, ACTOVIQ_AGENT_PATH_KEY, ActoviqAgentExecutionsApi, createChildAgentExecutionIdentity, resolveAgentExecutionIdentity, serializeAgentExecutionIdentity, } from './actoviqAgentExecutions.js';
|
|
54
|
+
function withoutExecutionIdentityMetadata(metadata) {
|
|
55
|
+
if (!metadata)
|
|
56
|
+
return undefined;
|
|
57
|
+
const sanitized = { ...metadata };
|
|
58
|
+
delete sanitized[ACTOVIQ_EXECUTION_ID_KEY];
|
|
59
|
+
delete sanitized[ACTOVIQ_ROOT_EXECUTION_ID_KEY];
|
|
60
|
+
delete sanitized[ACTOVIQ_PARENT_EXECUTION_ID_KEY];
|
|
61
|
+
delete sanitized[ACTOVIQ_AGENT_PATH_KEY];
|
|
62
|
+
delete sanitized.__actoviqParentSessionId;
|
|
63
|
+
return sanitized;
|
|
64
|
+
}
|
|
49
65
|
const RELEVANT_MEMORY_SESSION_STATE_KEY = '__actoviqRelevantMemoryState';
|
|
50
66
|
const AGENT_CONTINUITY_STATE_KEY = '__actoviqAgentContinuityState';
|
|
51
67
|
const INVOKED_SKILLS_STATE_KEY = '__actoviqInvokedSkills';
|
|
@@ -373,6 +389,8 @@ export class ActoviqAgentClient {
|
|
|
373
389
|
context;
|
|
374
390
|
slashCommands;
|
|
375
391
|
workflow;
|
|
392
|
+
/** Persistent, project-scoped root/child Agent execution graph. */
|
|
393
|
+
executions;
|
|
376
394
|
sessionManager;
|
|
377
395
|
sessionTurnCoordinator = new SessionTurnCoordinator();
|
|
378
396
|
agentDefinitions;
|
|
@@ -381,14 +399,13 @@ export class ActoviqAgentClient {
|
|
|
381
399
|
activatedConditionalSkills = new Set();
|
|
382
400
|
pendingDelegations = new Map();
|
|
383
401
|
pendingRuntimeNotifications = new Map();
|
|
384
|
-
subagentInputQueues = new Map();
|
|
385
402
|
sessionRuntimeOverrides = new Map();
|
|
386
403
|
backgroundTaskManager;
|
|
387
404
|
defaultPermissionMode;
|
|
388
405
|
defaultPermissions;
|
|
389
406
|
defaultClassifier;
|
|
390
407
|
defaultApprover;
|
|
391
|
-
constructor(config, store, backgroundTaskStore, mailboxStore, teammateStore, modelApi, mcpManager, defaultTools, defaultMcpServers, hooks, agentDefinitions = [], skillDefinitions = [], defaultPermissionMode, defaultPermissions, defaultClassifier, defaultApprover, sessionManagerConfig, maxSubagentDepth = 1, maxSubagentFanout = 8) {
|
|
408
|
+
constructor(config, store, executionStore, backgroundTaskStore, mailboxStore, teammateStore, modelApi, mcpManager, defaultTools, defaultMcpServers, hooks, agentDefinitions = [], skillDefinitions = [], defaultPermissionMode, defaultPermissions, defaultClassifier, defaultApprover, sessionManagerConfig, maxSubagentDepth = 1, maxSubagentFanout = 8) {
|
|
392
409
|
this.config = config;
|
|
393
410
|
this.store = store;
|
|
394
411
|
this.backgroundTaskStore = backgroundTaskStore;
|
|
@@ -402,6 +419,7 @@ export class ActoviqAgentClient {
|
|
|
402
419
|
this.maxSubagentDepth = maxSubagentDepth;
|
|
403
420
|
this.maxSubagentFanout = maxSubagentFanout;
|
|
404
421
|
this.sessionManager = new SessionManager(this.store, sessionManagerConfig);
|
|
422
|
+
this.executions = new ActoviqAgentExecutionsApi(executionStore);
|
|
405
423
|
this.sessions = new AgentSessionsApi(this.store, (sessionId, options) => this.resumeSession(sessionId, options), this.sessionManager);
|
|
406
424
|
this.agentDefinitions = new Map(agentDefinitions.map(definition => [definition.name, cloneAgentDefinition(definition)]));
|
|
407
425
|
this.skillDefinitions = new Map(skillDefinitions.map(definition => [definition.name, cloneSkillDefinition(definition)]));
|
|
@@ -532,6 +550,7 @@ export class ActoviqAgentClient {
|
|
|
532
550
|
static async create(options = {}) {
|
|
533
551
|
const config = await resolveRuntimeConfig(options);
|
|
534
552
|
const store = new SessionStore(config.sessionDirectory);
|
|
553
|
+
const executionStore = new AgentExecutionStore(config.sessionDirectory);
|
|
535
554
|
const backgroundTaskStore = new BackgroundTaskStore(config.sessionDirectory);
|
|
536
555
|
const mailboxStore = new MailboxStore(config.sessionDirectory);
|
|
537
556
|
const teammateStore = new TeammateStore(config.sessionDirectory);
|
|
@@ -545,13 +564,34 @@ export class ActoviqAgentClient {
|
|
|
545
564
|
}, {
|
|
546
565
|
requestTimeoutMs: config.mcpTimeoutMs,
|
|
547
566
|
});
|
|
567
|
+
const externalSkills = options.externalSkills
|
|
568
|
+
? (await loadActoviqExternalSkillDefinitions({
|
|
569
|
+
actoviqHomeDir: config.homeDir,
|
|
570
|
+
workDir: config.workDir,
|
|
571
|
+
externalSkills: options.externalSkills,
|
|
572
|
+
})).definitions
|
|
573
|
+
: [];
|
|
574
|
+
const externalSkillCatalogEnabled = Boolean(options.externalSkills);
|
|
548
575
|
const loadedSkills = await loadActoviqSkillDefinitions({
|
|
549
576
|
homeDir: config.homeDir,
|
|
550
577
|
workDir: config.workDir,
|
|
551
578
|
skillDirectories: options.skillDirectories,
|
|
552
|
-
disableDefaultSkills: options.disableDefaultSkills,
|
|
553
|
-
loadDefaultSkillDirectories:
|
|
579
|
+
disableDefaultSkills: externalSkillCatalogEnabled ? true : options.disableDefaultSkills,
|
|
580
|
+
loadDefaultSkillDirectories: externalSkillCatalogEnabled
|
|
581
|
+
? false
|
|
582
|
+
: options.loadDefaultSkillDirectories,
|
|
554
583
|
});
|
|
584
|
+
const actoviqCatalogSkills = externalSkills.filter(definition => definition.metadata?.__actoviqExternalSkillProvider === 'actoviq');
|
|
585
|
+
const reusedRuntimeSkills = externalSkills.filter(definition => definition.metadata?.__actoviqExternalSkillProvider !== 'actoviq');
|
|
586
|
+
const skillDefinitions = externalSkillCatalogEnabled
|
|
587
|
+
? [
|
|
588
|
+
...reusedRuntimeSkills,
|
|
589
|
+
...(options.disableDefaultSkills ? [] : getDefaultActoviqBundledSkills()),
|
|
590
|
+
...actoviqCatalogSkills,
|
|
591
|
+
...loadedSkills,
|
|
592
|
+
...(options.skills ?? []),
|
|
593
|
+
]
|
|
594
|
+
: [...loadedSkills, ...(options.skills ?? [])];
|
|
555
595
|
const loadedAgents = await loadActoviqAgentDefinitions({
|
|
556
596
|
homeDir: config.homeDir,
|
|
557
597
|
workDir: config.workDir,
|
|
@@ -570,8 +610,18 @@ export class ActoviqAgentClient {
|
|
|
570
610
|
defaultTools.push(...createActoviqComputerUseTools(computerUseOptions));
|
|
571
611
|
}
|
|
572
612
|
}
|
|
573
|
-
|
|
574
|
-
|
|
613
|
+
if (options.browserUse) {
|
|
614
|
+
const browserUseOptions = typeof options.browserUse === 'object' ? options.browserUse : {};
|
|
615
|
+
if (browserUseOptions.asMcpServer) {
|
|
616
|
+
defaultMcpServers.push(createActoviqBrowserUseMcpServer(browserUseOptions));
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
defaultTools.push(...createActoviqBrowserTools(browserUseOptions));
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
const client = new ActoviqAgentClient(config, store, executionStore, backgroundTaskStore, mailboxStore, teammateStore, modelApi, mcpManager, defaultTools, defaultMcpServers, options.hooks, agentDefinitions, skillDefinitions, options.permissionMode, options.permissions, options.classifier, options.approver, options.sessionManager, options.maxSubagentDepth, options.maxSubagentFanout);
|
|
623
|
+
const interruptedTasks = await client.backgroundTaskManager.reconcileInterruptedTasks();
|
|
624
|
+
await client.reconcileInterruptedAgentExecutions(interruptedTasks);
|
|
575
625
|
return client;
|
|
576
626
|
}
|
|
577
627
|
async run(input, options = {}) {
|
|
@@ -591,6 +641,16 @@ export class ActoviqAgentClient {
|
|
|
591
641
|
stream(input, options = {}) {
|
|
592
642
|
const runId = createId();
|
|
593
643
|
return new AgentRunStream(async (controller) => {
|
|
644
|
+
const unsubscribeExecution = this.executions.subscribe(runId, ({ event, snapshot }) => {
|
|
645
|
+
controller.emit({
|
|
646
|
+
type: 'agent.execution',
|
|
647
|
+
runId,
|
|
648
|
+
rootExecutionId: runId,
|
|
649
|
+
event,
|
|
650
|
+
snapshot,
|
|
651
|
+
timestamp: event.occurredAt,
|
|
652
|
+
});
|
|
653
|
+
});
|
|
594
654
|
const runOptions = {
|
|
595
655
|
...options,
|
|
596
656
|
signal: combineAbortSignals(options.signal, controller.signal),
|
|
@@ -628,6 +688,9 @@ export class ActoviqAgentClient {
|
|
|
628
688
|
});
|
|
629
689
|
throw error;
|
|
630
690
|
}
|
|
691
|
+
finally {
|
|
692
|
+
unsubscribeExecution();
|
|
693
|
+
}
|
|
631
694
|
}, { signal: options.signal });
|
|
632
695
|
}
|
|
633
696
|
async parallel(tasks, options) {
|
|
@@ -644,6 +707,9 @@ export class ActoviqAgentClient {
|
|
|
644
707
|
systemPrompt: options.systemPrompt ?? this.config.systemPrompt,
|
|
645
708
|
model,
|
|
646
709
|
tags: options.tags,
|
|
710
|
+
kind: options.kind,
|
|
711
|
+
parentSessionId: options.parentSessionId,
|
|
712
|
+
originalWorkDir: options.originalWorkDir,
|
|
647
713
|
metadata: {
|
|
648
714
|
...(options.metadata ?? {}),
|
|
649
715
|
__actoviqWorkDir: this.config.workDir,
|
|
@@ -661,13 +727,39 @@ export class ActoviqAgentClient {
|
|
|
661
727
|
return this.hydrateSession(stored);
|
|
662
728
|
}
|
|
663
729
|
async resumeSession(sessionId, options = {}) {
|
|
664
|
-
|
|
665
|
-
|
|
730
|
+
if (!options.fork) {
|
|
731
|
+
if (!this.hasPersistedSessionResumeOverrides(options)) {
|
|
732
|
+
const loaded = await this.store.load(sessionId);
|
|
733
|
+
if (loaded.status === 'active') {
|
|
734
|
+
return this.hydrateSession(loaded);
|
|
735
|
+
}
|
|
736
|
+
const reactivated = await this.store.runExclusiveTurn(sessionId, () => this.store.mutate(sessionId, current => this.prepareResumedStoredSession(current, options, false)));
|
|
737
|
+
return this.hydrateSession(reactivated);
|
|
738
|
+
}
|
|
739
|
+
const stored = await this.store.runExclusiveTurn(sessionId, () => this.store.mutate(sessionId, loaded => this.prepareResumedStoredSession(loaded, options, true)));
|
|
740
|
+
return this.hydrateSession(stored);
|
|
741
|
+
}
|
|
742
|
+
const stored = await this.store.runExclusiveTurn(sessionId, async () => {
|
|
743
|
+
const forked = await this.store.fork(sessionId, {
|
|
666
744
|
title: options.title,
|
|
667
745
|
tags: options.tags,
|
|
668
746
|
metadata: options.metadata,
|
|
669
|
-
})
|
|
670
|
-
|
|
747
|
+
});
|
|
748
|
+
const prepared = this.prepareResumedStoredSession(forked, options, false);
|
|
749
|
+
await this.store.save(prepared);
|
|
750
|
+
return prepared;
|
|
751
|
+
});
|
|
752
|
+
return this.hydrateSession(stored);
|
|
753
|
+
}
|
|
754
|
+
hasPersistedSessionResumeOverrides(options) {
|
|
755
|
+
return Boolean(options.model ||
|
|
756
|
+
options.title?.trim() ||
|
|
757
|
+
options.tags ||
|
|
758
|
+
options.metadata ||
|
|
759
|
+
options.permissionMode !== undefined ||
|
|
760
|
+
options.permissions !== undefined);
|
|
761
|
+
}
|
|
762
|
+
prepareResumedStoredSession(loaded, options, applyNonForkOverrides) {
|
|
671
763
|
const stored = deepClone(loaded);
|
|
672
764
|
if (options.model) {
|
|
673
765
|
stored.model = this.resolveModel(options.model);
|
|
@@ -682,7 +774,7 @@ export class ActoviqAgentClient {
|
|
|
682
774
|
: currentPermissionState.permissions,
|
|
683
775
|
});
|
|
684
776
|
}
|
|
685
|
-
if (
|
|
777
|
+
if (applyNonForkOverrides) {
|
|
686
778
|
if (options.title?.trim()) {
|
|
687
779
|
stored.title = options.title.trim();
|
|
688
780
|
stored.titleSource = 'manual';
|
|
@@ -697,8 +789,7 @@ export class ActoviqAgentClient {
|
|
|
697
789
|
stored.status = 'active';
|
|
698
790
|
stored.lastActiveAt = nowIso();
|
|
699
791
|
stored.updatedAt = stored.lastActiveAt;
|
|
700
|
-
|
|
701
|
-
return this.hydrateSession(stored);
|
|
792
|
+
return stored;
|
|
702
793
|
}
|
|
703
794
|
resolveModel(model) {
|
|
704
795
|
return model
|
|
@@ -776,6 +867,7 @@ export class ActoviqAgentClient {
|
|
|
776
867
|
const definition = this.requireAgentDefinition(agent);
|
|
777
868
|
return this.createSession({
|
|
778
869
|
...options,
|
|
870
|
+
kind: options.kind ?? 'agent',
|
|
779
871
|
model: options.model ?? definition.model,
|
|
780
872
|
systemPrompt: joinPromptParts(definition.systemPrompt, options.systemPrompt),
|
|
781
873
|
metadata: {
|
|
@@ -906,8 +998,18 @@ export class ActoviqAgentClient {
|
|
|
906
998
|
? message
|
|
907
999
|
: JSON.stringify(message);
|
|
908
1000
|
const routed = await this.routeMessageToAgent(to.trim(), text, {
|
|
1001
|
+
callId: context.toolUseId ?? createId(),
|
|
909
1002
|
parentRunId: context.runId,
|
|
910
1003
|
parentSessionId: context.sessionId,
|
|
1004
|
+
parentExecutionId: typeof context.metadata?.[ACTOVIQ_EXECUTION_ID_KEY] === 'string'
|
|
1005
|
+
? context.metadata[ACTOVIQ_EXECUTION_ID_KEY]
|
|
1006
|
+
: undefined,
|
|
1007
|
+
rootExecutionId: typeof context.metadata?.[ACTOVIQ_ROOT_EXECUTION_ID_KEY] === 'string'
|
|
1008
|
+
? context.metadata[ACTOVIQ_ROOT_EXECUTION_ID_KEY]
|
|
1009
|
+
: undefined,
|
|
1010
|
+
parentAgentPath: typeof context.metadata?.[ACTOVIQ_AGENT_PATH_KEY] === 'string'
|
|
1011
|
+
? context.metadata[ACTOVIQ_AGENT_PATH_KEY]
|
|
1012
|
+
: undefined,
|
|
911
1013
|
runOptions: {
|
|
912
1014
|
permissionMode: context.permissionMode,
|
|
913
1015
|
permissions: context.permissions,
|
|
@@ -1366,7 +1468,7 @@ export class ActoviqAgentClient {
|
|
|
1366
1468
|
});
|
|
1367
1469
|
}
|
|
1368
1470
|
runOnSession(session, input, options = {}) {
|
|
1369
|
-
return this.sessionTurnCoordinator.runExclusive(session.id, () => this.runOnSessionExclusive(session, input, options));
|
|
1471
|
+
return this.sessionTurnCoordinator.runExclusive(session.id, () => this.store.runExclusiveTurn(session.id, () => this.runOnSessionExclusive(session, input, options), options.signal));
|
|
1370
1472
|
}
|
|
1371
1473
|
async runOnSessionExclusive(session, input, options) {
|
|
1372
1474
|
const runId = createId();
|
|
@@ -1396,59 +1498,91 @@ export class ActoviqAgentClient {
|
|
|
1396
1498
|
...options,
|
|
1397
1499
|
signal: combineAbortSignals(options.signal, controller.signal),
|
|
1398
1500
|
};
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1501
|
+
return this.store.runExclusiveTurn(session.id, async () => {
|
|
1502
|
+
let unsubscribeExecution = () => undefined;
|
|
1503
|
+
try {
|
|
1504
|
+
const initialSnapshot = await this.store.load(session.id);
|
|
1505
|
+
session.replace(initialSnapshot);
|
|
1506
|
+
const rootExecutionId = typeof initialSnapshot.metadata[ACTOVIQ_ROOT_EXECUTION_ID_KEY] === 'string'
|
|
1507
|
+
? initialSnapshot.metadata[ACTOVIQ_ROOT_EXECUTION_ID_KEY]
|
|
1508
|
+
: session.id;
|
|
1509
|
+
unsubscribeExecution = this.executions.subscribe(rootExecutionId, ({ event, snapshot }) => {
|
|
1510
|
+
controller.emit({
|
|
1511
|
+
type: 'agent.execution',
|
|
1512
|
+
runId,
|
|
1513
|
+
rootExecutionId,
|
|
1514
|
+
event,
|
|
1515
|
+
snapshot,
|
|
1516
|
+
timestamp: event.occurredAt,
|
|
1517
|
+
});
|
|
1518
|
+
});
|
|
1519
|
+
const resolvedOptions = this.applySessionRuntimeOverrides(session.id, this.resolveSessionAgentOptions(initialSnapshot, runOptions));
|
|
1520
|
+
const execution = await this.executeSessionRunWithReactiveCompact({
|
|
1521
|
+
runId,
|
|
1522
|
+
session,
|
|
1523
|
+
input,
|
|
1524
|
+
options: resolvedOptions,
|
|
1525
|
+
snapshot: initialSnapshot,
|
|
1526
|
+
streaming: true,
|
|
1527
|
+
emit: controller.emit,
|
|
1528
|
+
});
|
|
1529
|
+
const hookOutcome = await this.applyPostRunHooks(runId, input, resolvedOptions, execution.result, execution.snapshot);
|
|
1530
|
+
if (hookOutcome.sessionMetadata) {
|
|
1531
|
+
execution.result.sessionHookMetadata = hookOutcome.sessionMetadata;
|
|
1532
|
+
}
|
|
1533
|
+
await this.persistSessionAfterRun(session, execution.snapshot, input, execution.result, resolvedOptions, execution.augmentations.surfacedMemories, hookOutcome);
|
|
1534
|
+
await this.sessionManager.touch(session.id);
|
|
1535
|
+
session.replace(await this.store.load(session.id));
|
|
1536
|
+
controller.emit({
|
|
1537
|
+
type: 'response.completed',
|
|
1538
|
+
runId,
|
|
1539
|
+
result: execution.result,
|
|
1540
|
+
timestamp: execution.result.completedAt,
|
|
1541
|
+
});
|
|
1542
|
+
return execution.result;
|
|
1415
1543
|
}
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
code: normalized.code,
|
|
1435
|
-
stack: normalized.stack,
|
|
1436
|
-
},
|
|
1437
|
-
timestamp: nowIso(),
|
|
1438
|
-
});
|
|
1439
|
-
throw error;
|
|
1440
|
-
}
|
|
1544
|
+
catch (error) {
|
|
1545
|
+
const normalized = asError(error);
|
|
1546
|
+
controller.emit({
|
|
1547
|
+
type: 'error',
|
|
1548
|
+
runId,
|
|
1549
|
+
error: {
|
|
1550
|
+
message: normalized.message,
|
|
1551
|
+
code: normalized.code,
|
|
1552
|
+
stack: normalized.stack,
|
|
1553
|
+
},
|
|
1554
|
+
timestamp: nowIso(),
|
|
1555
|
+
});
|
|
1556
|
+
throw error;
|
|
1557
|
+
}
|
|
1558
|
+
finally {
|
|
1559
|
+
unsubscribeExecution();
|
|
1560
|
+
}
|
|
1561
|
+
}, runOptions.signal);
|
|
1441
1562
|
}), { signal: options.signal });
|
|
1442
1563
|
}
|
|
1443
|
-
async executeRun(runId, input, options, session, streaming = false, emit, augmentations, skipRunStartedEvent = false, liveSession) {
|
|
1564
|
+
async executeRun(runId, input, options, session, streaming = false, emit, augmentations, skipRunStartedEvent = false, liveSession, deferPromptTooLongSettlement = false, skipInitialInput = false, onInitialInputCheckpointed) {
|
|
1565
|
+
const workDir = this.resolveRunWorkDir(options);
|
|
1566
|
+
const model = this.resolveModel(options.model ?? session?.model);
|
|
1567
|
+
const executionIdentity = resolveAgentExecutionIdentity({
|
|
1568
|
+
runId,
|
|
1569
|
+
session,
|
|
1570
|
+
metadata: withoutExecutionIdentityMetadata(options.metadata),
|
|
1571
|
+
model,
|
|
1572
|
+
cwd: workDir,
|
|
1573
|
+
runtime: 'hadamard',
|
|
1574
|
+
});
|
|
1575
|
+
await this.executions.startTurn(executionIdentity, runId).catch((error) => {
|
|
1576
|
+
console.warn(`[AgentExecution] Failed to start ${runId}: ${asError(error).message}`);
|
|
1577
|
+
});
|
|
1444
1578
|
const metadata = {
|
|
1445
1579
|
...this.config.metadata,
|
|
1446
1580
|
...(session?.metadata ?? {}),
|
|
1447
1581
|
...(augmentations?.metadata ?? {}),
|
|
1448
1582
|
...(options.metadata ?? {}),
|
|
1583
|
+
...serializeAgentExecutionIdentity(executionIdentity),
|
|
1449
1584
|
[ACTOVIQ_RUN_STATE_KEY]: createActoviqRunToolState(),
|
|
1450
1585
|
};
|
|
1451
|
-
const workDir = this.resolveRunWorkDir(options);
|
|
1452
1586
|
const mergedTools = filterAgentTools(mergeUniqueByName(options.__actoviqUseDefaultTools === false ? [] : this.defaultTools, options.tools ?? []), options.__actoviqAllowedTools, options.__actoviqDisallowedTools);
|
|
1453
1587
|
// Collect tool prompts for system prompt assembly
|
|
1454
1588
|
const toolPromptParts = await collectToolPrompts(mergedTools, {
|
|
@@ -1467,9 +1601,9 @@ export class ActoviqAgentClient {
|
|
|
1467
1601
|
: this.config;
|
|
1468
1602
|
const notificationKey = session?.id ?? runId;
|
|
1469
1603
|
const drainQueuedInputs = notificationKey || options.drainQueuedInputs || liveSession
|
|
1470
|
-
? () => [
|
|
1604
|
+
? async () => [
|
|
1471
1605
|
...(liveSession?.drainSteeringInputs() ?? []),
|
|
1472
|
-
...(options.drainQueuedInputs?.() ?? []),
|
|
1606
|
+
...((await options.drainQueuedInputs?.()) ?? []),
|
|
1473
1607
|
...this.drainRuntimeNotifications(notificationKey),
|
|
1474
1608
|
]
|
|
1475
1609
|
: undefined;
|
|
@@ -1480,78 +1614,106 @@ export class ActoviqAgentClient {
|
|
|
1480
1614
|
]
|
|
1481
1615
|
: undefined;
|
|
1482
1616
|
let checkpointSession = session ? deepClone(session) : undefined;
|
|
1483
|
-
|
|
1484
|
-
runId,
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
:
|
|
1545
|
-
|
|
1617
|
+
try {
|
|
1618
|
+
const rawResult = await withDeadline(`Agent run ${runId}`, runtimeConfig.runTimeoutMs, options.signal, ({ signal }) => executeConversation({
|
|
1619
|
+
runId,
|
|
1620
|
+
input,
|
|
1621
|
+
messages: session?.messages,
|
|
1622
|
+
prefixedMessages: augmentations?.prefixedMessages,
|
|
1623
|
+
sessionId: session?.id,
|
|
1624
|
+
systemPrompt,
|
|
1625
|
+
tools: mergedTools,
|
|
1626
|
+
mcpServers: mergeUniqueByName(options.__actoviqUseDefaultMcpServers === false ? [] : this.defaultMcpServers, options.mcpServers ?? []),
|
|
1627
|
+
model,
|
|
1628
|
+
maxTokens: options.maxTokens,
|
|
1629
|
+
temperature: options.temperature,
|
|
1630
|
+
effort: options.effort,
|
|
1631
|
+
toolChoice: options.toolChoice,
|
|
1632
|
+
userId: options.userId ?? this.config.userId,
|
|
1633
|
+
metadata,
|
|
1634
|
+
signal,
|
|
1635
|
+
permissionMode: options.permissionMode ?? this.defaultPermissionMode,
|
|
1636
|
+
permissions: options.permissions ?? this.defaultPermissions,
|
|
1637
|
+
classifier: options.classifier ?? this.defaultClassifier,
|
|
1638
|
+
approver: options.approver ?? this.defaultApprover,
|
|
1639
|
+
canUseTool: options.canUseTool,
|
|
1640
|
+
hooks: augmentations?.hooks,
|
|
1641
|
+
drainQueuedInputs,
|
|
1642
|
+
drainFollowUpInputs,
|
|
1643
|
+
streaming,
|
|
1644
|
+
emit: (event) => {
|
|
1645
|
+
this.executions.recordRuntimeEvent(executionIdentity, event);
|
|
1646
|
+
this.activateConditionalSkillsFromEvent(event);
|
|
1647
|
+
emit?.(event);
|
|
1648
|
+
},
|
|
1649
|
+
onConversationCheckpoint: checkpointSession
|
|
1650
|
+
? async (messages) => {
|
|
1651
|
+
const snap = deepClone(checkpointSession);
|
|
1652
|
+
snap.messages = deepClone(messages);
|
|
1653
|
+
snap.updatedAt = nowIso();
|
|
1654
|
+
snap.metadata = {
|
|
1655
|
+
...snap.metadata,
|
|
1656
|
+
__actoviqWorkDir: workDir,
|
|
1657
|
+
...(options.metadata ?? {}),
|
|
1658
|
+
...serializeAgentExecutionIdentity(executionIdentity),
|
|
1659
|
+
};
|
|
1660
|
+
await this.store.save(snap);
|
|
1661
|
+
checkpointSession = snap;
|
|
1662
|
+
liveSession?.replace(snap);
|
|
1663
|
+
if (!skipInitialInput) {
|
|
1664
|
+
onInitialInputCheckpointed?.();
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
: undefined,
|
|
1668
|
+
skipRunStartedEvent,
|
|
1669
|
+
skipInitialInput,
|
|
1670
|
+
modelApi: options.modelApi ?? this.modelApi,
|
|
1671
|
+
config: runtimeConfig,
|
|
1672
|
+
mcpManager: this.mcpManager,
|
|
1673
|
+
}));
|
|
1674
|
+
const result = {
|
|
1675
|
+
...rawResult,
|
|
1676
|
+
executionId: executionIdentity.rootExecutionId,
|
|
1677
|
+
executionNodeId: executionIdentity.executionId,
|
|
1678
|
+
surfacedMemories: augmentations?.surfacedMemories.length
|
|
1679
|
+
? deepClone(augmentations.surfacedMemories)
|
|
1680
|
+
: undefined,
|
|
1681
|
+
invokedSkills: augmentations?.invokedSkills.length
|
|
1682
|
+
? deepClone(augmentations.invokedSkills)
|
|
1683
|
+
: undefined,
|
|
1684
|
+
};
|
|
1685
|
+
await this.executions.settleTurn(executionIdentity, runId, {
|
|
1686
|
+
outcome: 'completed',
|
|
1687
|
+
result,
|
|
1688
|
+
}).catch((error) => {
|
|
1689
|
+
console.warn(`[AgentExecution] Failed to complete ${runId}: ${asError(error).message}`);
|
|
1690
|
+
});
|
|
1691
|
+
return result;
|
|
1692
|
+
}
|
|
1693
|
+
catch (error) {
|
|
1694
|
+
if (!isActoviqPromptTooLongError(error) || !deferPromptTooLongSettlement) {
|
|
1695
|
+
const interrupted = options.signal?.aborted || error instanceof RunAbortedError;
|
|
1696
|
+
await this.executions.settleTurn(executionIdentity, runId, {
|
|
1697
|
+
outcome: interrupted ? 'interrupted' : 'errored',
|
|
1698
|
+
error: asError(error).message,
|
|
1699
|
+
}).catch((executionError) => {
|
|
1700
|
+
console.warn(`[AgentExecution] Failed to settle ${runId}: ${asError(executionError).message}`);
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
throw error;
|
|
1704
|
+
}
|
|
1546
1705
|
}
|
|
1547
1706
|
async executeSessionRunWithReactiveCompact(args) {
|
|
1548
1707
|
let currentSnapshot = args.snapshot;
|
|
1549
1708
|
let currentAugmentations = await this.prepareRunAugmentations(args.runId, args.input, args.options, currentSnapshot);
|
|
1550
1709
|
let lastReactiveCompact;
|
|
1551
1710
|
let attempts = 0;
|
|
1711
|
+
let initialInputCheckpointed = false;
|
|
1552
1712
|
while (true) {
|
|
1553
1713
|
try {
|
|
1554
|
-
const result = await this.executeRun(args.runId, args.input, args.options, currentSnapshot, args.streaming ?? false, args.emit, currentAugmentations, attempts > 0, args.session)
|
|
1714
|
+
const result = await this.executeRun(args.runId, args.input, args.options, currentSnapshot, args.streaming ?? false, args.emit, currentAugmentations, attempts > 0, args.session, true, initialInputCheckpointed, () => {
|
|
1715
|
+
initialInputCheckpointed = true;
|
|
1716
|
+
});
|
|
1555
1717
|
if (lastReactiveCompact) {
|
|
1556
1718
|
result.reactiveCompact = lastReactiveCompact;
|
|
1557
1719
|
}
|
|
@@ -1562,17 +1724,40 @@ export class ActoviqAgentClient {
|
|
|
1562
1724
|
};
|
|
1563
1725
|
}
|
|
1564
1726
|
catch (error) {
|
|
1565
|
-
if (!isActoviqPromptTooLongError(error)
|
|
1727
|
+
if (!isActoviqPromptTooLongError(error)) {
|
|
1566
1728
|
throw error;
|
|
1567
1729
|
}
|
|
1568
|
-
|
|
1730
|
+
currentSnapshot = args.session.snapshot();
|
|
1731
|
+
if (attempts >= MAX_REACTIVE_COMPACT_ATTEMPTS) {
|
|
1732
|
+
await this.settleTerminalPromptTooLong(args, currentSnapshot, error);
|
|
1733
|
+
throw error;
|
|
1734
|
+
}
|
|
1735
|
+
let reactiveCompact;
|
|
1736
|
+
try {
|
|
1737
|
+
reactiveCompact = await this.tryReactiveCompactSession(args.session, currentSnapshot, args.options, args.runId, args.emit);
|
|
1738
|
+
if (reactiveCompact) {
|
|
1739
|
+
attempts += 1;
|
|
1740
|
+
currentSnapshot = reactiveCompact.snapshot;
|
|
1741
|
+
currentAugmentations = await this.prepareRunAugmentations(args.runId, args.input, args.options, currentSnapshot);
|
|
1742
|
+
lastReactiveCompact = reactiveCompact.result;
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
catch (recoveryError) {
|
|
1746
|
+
if (recoveryError instanceof Error &&
|
|
1747
|
+
recoveryError !== error &&
|
|
1748
|
+
recoveryError.cause === undefined) {
|
|
1749
|
+
Object.defineProperty(recoveryError, 'cause', {
|
|
1750
|
+
value: error,
|
|
1751
|
+
configurable: true,
|
|
1752
|
+
});
|
|
1753
|
+
}
|
|
1754
|
+
await this.settleTerminalPromptTooLong(args, currentSnapshot, recoveryError);
|
|
1755
|
+
throw recoveryError;
|
|
1756
|
+
}
|
|
1569
1757
|
if (!reactiveCompact) {
|
|
1758
|
+
await this.settleTerminalPromptTooLong(args, currentSnapshot, error);
|
|
1570
1759
|
throw error;
|
|
1571
1760
|
}
|
|
1572
|
-
attempts += 1;
|
|
1573
|
-
currentSnapshot = reactiveCompact.snapshot;
|
|
1574
|
-
currentAugmentations = await this.prepareRunAugmentations(args.runId, args.input, args.options, currentSnapshot);
|
|
1575
|
-
lastReactiveCompact = reactiveCompact.result;
|
|
1576
1761
|
}
|
|
1577
1762
|
}
|
|
1578
1763
|
}
|
|
@@ -1934,21 +2119,142 @@ export class ActoviqAgentClient {
|
|
|
1934
2119
|
result: reactive.result,
|
|
1935
2120
|
};
|
|
1936
2121
|
}
|
|
2122
|
+
delegatedExecutionContext(definition, delegation, runOptions, workDir, sessionId, fallback) {
|
|
2123
|
+
const parentExecutionId = delegation.parentExecutionId
|
|
2124
|
+
?? fallback.parentSessionId
|
|
2125
|
+
?? fallback.parentRunId;
|
|
2126
|
+
const rootExecutionId = delegation.rootExecutionId ?? parentExecutionId;
|
|
2127
|
+
const parentSessionId = delegation.parentSessionId ?? fallback.parentSessionId;
|
|
2128
|
+
const parent = {
|
|
2129
|
+
executionId: parentExecutionId,
|
|
2130
|
+
sessionId: parentSessionId ?? parentExecutionId,
|
|
2131
|
+
rootExecutionId,
|
|
2132
|
+
parentExecutionId: null,
|
|
2133
|
+
parentSessionId: null,
|
|
2134
|
+
canonicalPath: delegation.parentAgentPath ?? '/root',
|
|
2135
|
+
agentName: typeof runOptions.metadata?.__actoviqAgentDefinition === 'string'
|
|
2136
|
+
? runOptions.metadata.__actoviqAgentDefinition
|
|
2137
|
+
: 'Hadamard',
|
|
2138
|
+
nickname: typeof runOptions.metadata?.__actoviqAgentName === 'string'
|
|
2139
|
+
? runOptions.metadata.__actoviqAgentName
|
|
2140
|
+
: null,
|
|
2141
|
+
role: null,
|
|
2142
|
+
kind: parentExecutionId === rootExecutionId ? 'root' : 'subagent',
|
|
2143
|
+
runtime: 'hadamard',
|
|
2144
|
+
model: runOptions.model ?? null,
|
|
2145
|
+
cwd: this.resolveRunWorkDir(runOptions),
|
|
2146
|
+
};
|
|
2147
|
+
const child = createChildAgentExecutionIdentity({
|
|
2148
|
+
sessionId,
|
|
2149
|
+
parent,
|
|
2150
|
+
agentName: definition.name,
|
|
2151
|
+
nickname: delegation.name,
|
|
2152
|
+
model: definition.model ?? runOptions.model,
|
|
2153
|
+
cwd: workDir,
|
|
2154
|
+
});
|
|
2155
|
+
return {
|
|
2156
|
+
parent,
|
|
2157
|
+
child,
|
|
2158
|
+
edge: {
|
|
2159
|
+
callId: delegation.callId ?? createId(),
|
|
2160
|
+
kind: 'delegate',
|
|
2161
|
+
source: parent,
|
|
2162
|
+
target: child,
|
|
2163
|
+
summary: delegation.description,
|
|
2164
|
+
},
|
|
2165
|
+
};
|
|
2166
|
+
}
|
|
2167
|
+
existingAgentExecutionContext(session, definition, delegation, runOptions, workDir, fallback, kind) {
|
|
2168
|
+
const snapshot = session instanceof AgentSession ? session.snapshot() : session;
|
|
2169
|
+
const base = this.delegatedExecutionContext(definition, delegation, runOptions, workDir, snapshot.id, fallback);
|
|
2170
|
+
const child = resolveAgentExecutionIdentity({
|
|
2171
|
+
runId: snapshot.id,
|
|
2172
|
+
session: snapshot,
|
|
2173
|
+
metadata: withoutExecutionIdentityMetadata(runOptions.metadata),
|
|
2174
|
+
model: definition.model ?? runOptions.model,
|
|
2175
|
+
cwd: workDir,
|
|
2176
|
+
});
|
|
2177
|
+
// A completed child keeps its original tree identity when resumed. This
|
|
2178
|
+
// mirrors Codex's stable ThreadId semantics and prevents duplicate nodes.
|
|
2179
|
+
const parent = child.rootExecutionId === base.parent.rootExecutionId
|
|
2180
|
+
? base.parent
|
|
2181
|
+
: {
|
|
2182
|
+
...base.parent,
|
|
2183
|
+
executionId: child.parentExecutionId ?? base.parent.executionId,
|
|
2184
|
+
sessionId: child.parentSessionId ?? base.parent.sessionId,
|
|
2185
|
+
rootExecutionId: child.rootExecutionId,
|
|
2186
|
+
canonicalPath: child.canonicalPath.split('/').slice(0, -1).join('/') || '/root',
|
|
2187
|
+
kind: child.parentExecutionId === child.rootExecutionId ? 'root' : 'subagent',
|
|
2188
|
+
};
|
|
2189
|
+
return {
|
|
2190
|
+
parent,
|
|
2191
|
+
child,
|
|
2192
|
+
edge: {
|
|
2193
|
+
callId: delegation.callId ?? createId(),
|
|
2194
|
+
kind,
|
|
2195
|
+
source: parent,
|
|
2196
|
+
target: child,
|
|
2197
|
+
summary: delegation.description,
|
|
2198
|
+
},
|
|
2199
|
+
};
|
|
2200
|
+
}
|
|
2201
|
+
async tryStartExecutionEdge(edge) {
|
|
2202
|
+
try {
|
|
2203
|
+
await this.executions.startEdge(edge);
|
|
2204
|
+
return true;
|
|
2205
|
+
}
|
|
2206
|
+
catch (error) {
|
|
2207
|
+
console.warn(`[AgentExecution] Failed to start ${edge.kind} edge ${edge.callId}: ${asError(error).message}`);
|
|
2208
|
+
return false;
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
async tryCompleteExecutionEdge(edge, result) {
|
|
2212
|
+
await this.executions.completeEdge(edge, result).catch((error) => {
|
|
2213
|
+
console.warn(`[AgentExecution] Failed to complete ${edge.kind} edge ${edge.callId}: ${asError(error).message}`);
|
|
2214
|
+
});
|
|
2215
|
+
}
|
|
2216
|
+
async tryFailExecutionEdge(edge, error) {
|
|
2217
|
+
await this.executions.failEdge(edge, error).catch((executionError) => {
|
|
2218
|
+
console.warn(`[AgentExecution] Failed to fail ${edge.kind} edge ${edge.callId}: ${asError(executionError).message}`);
|
|
2219
|
+
});
|
|
2220
|
+
}
|
|
2221
|
+
async tryCompleteExecutionEdgeByCallId(rootExecutionId, callId, result) {
|
|
2222
|
+
await this.executions.completeEdgeByCallId(rootExecutionId, callId, result).catch((error) => {
|
|
2223
|
+
console.warn(`[AgentExecution] Failed to complete edge ${callId}: ${asError(error).message}`);
|
|
2224
|
+
});
|
|
2225
|
+
}
|
|
2226
|
+
async tryFailExecutionEdgeByCallId(rootExecutionId, callId, error) {
|
|
2227
|
+
await this.executions.failEdgeByCallId(rootExecutionId, callId, error).catch((executionError) => {
|
|
2228
|
+
console.warn(`[AgentExecution] Failed to fail edge ${callId}: ${asError(executionError).message}`);
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
1937
2231
|
async runDelegatedAgentTask(agent, prompt, runOptions = {}, delegation = { description: prompt }) {
|
|
1938
2232
|
const definition = this.requireAgentDefinition(agent);
|
|
1939
2233
|
const prepared = await this.prepareDelegatedWorkspace(definition, delegation);
|
|
2234
|
+
const childSessionId = createId();
|
|
2235
|
+
const execution = this.delegatedExecutionContext(definition, delegation, runOptions, prepared.workDir, childSessionId, {
|
|
2236
|
+
parentRunId: delegation.parentRunId ?? delegation.parentExecutionId ?? createId(),
|
|
2237
|
+
parentSessionId: delegation.parentSessionId,
|
|
2238
|
+
});
|
|
2239
|
+
let edgeStarted = false;
|
|
1940
2240
|
try {
|
|
1941
2241
|
const session = await this.createAgentSession(agent, {
|
|
2242
|
+
id: childSessionId,
|
|
2243
|
+
kind: 'agent',
|
|
2244
|
+
parentSessionId: execution.child.parentSessionId ?? undefined,
|
|
1942
2245
|
title: `${delegation.name ?? definition.name}: ${truncateText(delegation.description, 80)}`,
|
|
1943
2246
|
metadata: {
|
|
1944
2247
|
__actoviqAgentName: delegation.name,
|
|
1945
2248
|
__actoviqAgentWorkDir: prepared.workDir,
|
|
1946
2249
|
__actoviqAgentWorktreePath: prepared.workspace?.path,
|
|
1947
2250
|
__actoviqAgentWorktreeBranch: prepared.workspace?.metadata.branch,
|
|
2251
|
+
...serializeAgentExecutionIdentity(execution.child),
|
|
1948
2252
|
},
|
|
1949
2253
|
});
|
|
1950
|
-
|
|
2254
|
+
edgeStarted = await this.tryStartExecutionEdge(execution.edge);
|
|
2255
|
+
const result = await session.send(prompt, this.prepareDelegatedRunOptions(runOptions, prepared.workDir, execution.child));
|
|
1951
2256
|
const retained = await this.finalizeDelegatedWorkspace(prepared.workspace);
|
|
2257
|
+
await this.tryCompleteExecutionEdge(execution.edge, result.text);
|
|
1952
2258
|
return {
|
|
1953
2259
|
result,
|
|
1954
2260
|
sessionId: session.id,
|
|
@@ -1957,6 +2263,9 @@ export class ActoviqAgentClient {
|
|
|
1957
2263
|
};
|
|
1958
2264
|
}
|
|
1959
2265
|
catch (error) {
|
|
2266
|
+
if (edgeStarted) {
|
|
2267
|
+
await this.tryFailExecutionEdge(execution.edge, asError(error).message);
|
|
2268
|
+
}
|
|
1960
2269
|
await this.finalizeDelegatedWorkspace(prepared.workspace);
|
|
1961
2270
|
throw error;
|
|
1962
2271
|
}
|
|
@@ -1966,22 +2275,78 @@ export class ActoviqAgentClient {
|
|
|
1966
2275
|
const task = tasks.find(candidate => candidate.id === address ||
|
|
1967
2276
|
candidate.sessionId === address ||
|
|
1968
2277
|
candidate.agentName === address);
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
this.
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
2278
|
+
let messageInput;
|
|
2279
|
+
let messageTask = task;
|
|
2280
|
+
if (task?.sessionId) {
|
|
2281
|
+
const session = await this.store.load(task.sessionId);
|
|
2282
|
+
const definition = this.requireAgentDefinition(task.subagentType);
|
|
2283
|
+
const workDir = typeof session.metadata.__actoviqAgentWorkDir === 'string'
|
|
2284
|
+
? session.metadata.__actoviqAgentWorkDir
|
|
2285
|
+
: task.workDir;
|
|
2286
|
+
const execution = this.existingAgentExecutionContext(session, definition, {
|
|
2287
|
+
callId: context.callId,
|
|
2288
|
+
description: `Message ${task.agentName ?? definition.name}`,
|
|
2289
|
+
name: task.agentName,
|
|
2290
|
+
parentRunId: context.parentRunId,
|
|
2291
|
+
parentSessionId: context.parentSessionId,
|
|
2292
|
+
parentExecutionId: context.parentExecutionId,
|
|
2293
|
+
rootExecutionId: context.rootExecutionId,
|
|
2294
|
+
parentAgentPath: context.parentAgentPath,
|
|
2295
|
+
}, context.runOptions, workDir, {
|
|
2296
|
+
parentRunId: context.parentRunId,
|
|
2297
|
+
parentSessionId: context.parentSessionId,
|
|
2298
|
+
}, 'message');
|
|
2299
|
+
const input = {
|
|
2300
|
+
id: context.callId,
|
|
2301
|
+
text: message,
|
|
2302
|
+
rootExecutionId: execution.edge.source.rootExecutionId,
|
|
2303
|
+
edgeCallId: execution.edge.callId,
|
|
1982
2304
|
};
|
|
2305
|
+
let edgeStarted = false;
|
|
2306
|
+
try {
|
|
2307
|
+
edgeStarted = await this.tryStartExecutionEdge(execution.edge);
|
|
2308
|
+
const reservation = await this.backgroundTaskManager.reserveInput(task.id, input);
|
|
2309
|
+
messageTask = reservation.task;
|
|
2310
|
+
if (reservation.rejected) {
|
|
2311
|
+
if (edgeStarted) {
|
|
2312
|
+
await this.tryFailExecutionEdge(execution.edge, reservation.rejected);
|
|
2313
|
+
}
|
|
2314
|
+
return {
|
|
2315
|
+
status: 'rejected',
|
|
2316
|
+
taskId: reservation.task.id,
|
|
2317
|
+
agentId: reservation.task.sessionId,
|
|
2318
|
+
agentName: reservation.task.agentName,
|
|
2319
|
+
error: reservation.rejected,
|
|
2320
|
+
};
|
|
2321
|
+
}
|
|
2322
|
+
if (!reservation.accepted) {
|
|
2323
|
+
return {
|
|
2324
|
+
status: 'duplicate',
|
|
2325
|
+
taskStatus: reservation.task.status,
|
|
2326
|
+
taskId: reservation.task.id,
|
|
2327
|
+
agentId: reservation.task.sessionId,
|
|
2328
|
+
agentName: reservation.task.agentName,
|
|
2329
|
+
replayed: true,
|
|
2330
|
+
};
|
|
2331
|
+
}
|
|
2332
|
+
messageInput = input;
|
|
2333
|
+
if (reservation.queued) {
|
|
2334
|
+
return {
|
|
2335
|
+
status: 'queued',
|
|
2336
|
+
taskId: reservation.task.id,
|
|
2337
|
+
agentId: reservation.task.sessionId,
|
|
2338
|
+
agentName: reservation.task.agentName,
|
|
2339
|
+
};
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
catch (error) {
|
|
2343
|
+
if (edgeStarted) {
|
|
2344
|
+
await this.tryFailExecutionEdge(execution.edge, asError(error).message);
|
|
2345
|
+
}
|
|
2346
|
+
throw error;
|
|
2347
|
+
}
|
|
1983
2348
|
}
|
|
1984
|
-
const sessionId =
|
|
2349
|
+
const sessionId = messageTask?.sessionId ?? address;
|
|
1985
2350
|
let session;
|
|
1986
2351
|
try {
|
|
1987
2352
|
session = await this.resumeSession(sessionId);
|
|
@@ -1995,21 +2360,36 @@ export class ActoviqAgentClient {
|
|
|
1995
2360
|
if (!agentName) {
|
|
1996
2361
|
throw new Error(`Session "${sessionId}" is not an agent session.`);
|
|
1997
2362
|
}
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
:
|
|
2007
|
-
|
|
2363
|
+
let resumed;
|
|
2364
|
+
try {
|
|
2365
|
+
resumed = await this.launchBackgroundOnSession(session, agentName, message, {
|
|
2366
|
+
parentRunId: context.parentRunId,
|
|
2367
|
+
parentSessionId: context.parentSessionId,
|
|
2368
|
+
}, context.runOptions, {
|
|
2369
|
+
callId: messageInput ? `${context.callId}:resume` : context.callId,
|
|
2370
|
+
description: `Continue ${messageTask?.agentName ?? agentName}`,
|
|
2371
|
+
name: messageTask?.agentName,
|
|
2372
|
+
parentRunId: context.parentRunId,
|
|
2373
|
+
parentSessionId: context.parentSessionId,
|
|
2374
|
+
parentExecutionId: context.parentExecutionId,
|
|
2375
|
+
rootExecutionId: context.rootExecutionId,
|
|
2376
|
+
parentAgentPath: context.parentAgentPath,
|
|
2377
|
+
cwd: typeof session.metadata.__actoviqAgentWorkDir === 'string'
|
|
2378
|
+
? session.metadata.__actoviqAgentWorkDir
|
|
2379
|
+
: undefined,
|
|
2380
|
+
}, messageTask?.id, messageInput ? [messageInput] : [], messageTask?.seenInputIds ?? []);
|
|
2381
|
+
}
|
|
2382
|
+
catch (error) {
|
|
2383
|
+
if (messageInput) {
|
|
2384
|
+
await this.tryFailExecutionEdgeByCallId(messageInput.rootExecutionId, messageInput.edgeCallId, asError(error).message);
|
|
2385
|
+
}
|
|
2386
|
+
throw error;
|
|
2387
|
+
}
|
|
2008
2388
|
return {
|
|
2009
2389
|
status: 'resumed',
|
|
2010
2390
|
taskId: resumed.id,
|
|
2011
2391
|
agentId: session.id,
|
|
2012
|
-
agentName:
|
|
2392
|
+
agentName: messageTask?.agentName,
|
|
2013
2393
|
};
|
|
2014
2394
|
}
|
|
2015
2395
|
async prepareDelegatedWorkspace(definition, delegation) {
|
|
@@ -2032,17 +2412,23 @@ export class ActoviqAgentClient {
|
|
|
2032
2412
|
});
|
|
2033
2413
|
return { workDir: workspace.path, workspace };
|
|
2034
2414
|
}
|
|
2035
|
-
prepareDelegatedRunOptions(runOptions, workDir,
|
|
2415
|
+
prepareDelegatedRunOptions(runOptions, workDir, executionIdentity, backgroundTaskId) {
|
|
2036
2416
|
return {
|
|
2037
2417
|
...runOptions,
|
|
2038
2418
|
workDir,
|
|
2419
|
+
metadata: {
|
|
2420
|
+
...(runOptions.metadata ?? {}),
|
|
2421
|
+
...(executionIdentity ? serializeAgentExecutionIdentity(executionIdentity) : {}),
|
|
2422
|
+
},
|
|
2039
2423
|
tools: [
|
|
2040
2424
|
...createActoviqFileTools({ cwd: workDir }),
|
|
2041
2425
|
...(runOptions.tools ?? []),
|
|
2042
2426
|
],
|
|
2043
|
-
drainQueuedInputs: () => [
|
|
2044
|
-
...(runOptions.drainQueuedInputs?.() ?? []),
|
|
2045
|
-
...
|
|
2427
|
+
drainQueuedInputs: async () => [
|
|
2428
|
+
...((await runOptions.drainQueuedInputs?.()) ?? []),
|
|
2429
|
+
...(backgroundTaskId
|
|
2430
|
+
? await this.drainBackgroundTaskInputs(backgroundTaskId)
|
|
2431
|
+
: []),
|
|
2046
2432
|
],
|
|
2047
2433
|
};
|
|
2048
2434
|
}
|
|
@@ -2057,10 +2443,10 @@ export class ActoviqAgentClient {
|
|
|
2057
2443
|
}
|
|
2058
2444
|
return true;
|
|
2059
2445
|
}
|
|
2060
|
-
|
|
2061
|
-
const queued = this.
|
|
2062
|
-
this.
|
|
2063
|
-
return queued;
|
|
2446
|
+
async drainBackgroundTaskInputs(taskId) {
|
|
2447
|
+
const queued = await this.backgroundTaskManager.drainInputs(taskId);
|
|
2448
|
+
await Promise.all(queued.map(input => this.tryCompleteExecutionEdgeByCallId(input.rootExecutionId, input.edgeCallId, 'Delivered at the next Agent tool boundary.')));
|
|
2449
|
+
return queued.map(input => input.text);
|
|
2064
2450
|
}
|
|
2065
2451
|
async collectPendingTaskNotifications(parentSessionId) {
|
|
2066
2452
|
this.pendingRuntimeNotifications.delete(parentSessionId);
|
|
@@ -2098,21 +2484,28 @@ export class ActoviqAgentClient {
|
|
|
2098
2484
|
return queued.map(entry => entry.text);
|
|
2099
2485
|
}
|
|
2100
2486
|
async markTaskNotificationDelivered(taskId) {
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2487
|
+
await this.backgroundTaskStore.mutate(taskId, task => {
|
|
2488
|
+
if (task.notificationDeliveredAt) {
|
|
2489
|
+
return task;
|
|
2490
|
+
}
|
|
2491
|
+
return {
|
|
2492
|
+
...task,
|
|
2493
|
+
notificationDeliveredAt: nowIso(),
|
|
2494
|
+
updatedAt: nowIso(),
|
|
2495
|
+
};
|
|
2109
2496
|
});
|
|
2110
2497
|
}
|
|
2111
2498
|
async launchBackgroundAgentTask(agent, prompt, options, runOptions = {}, delegation = { description: prompt }) {
|
|
2112
2499
|
const definition = this.requireAgentDefinition(agent);
|
|
2113
2500
|
const prepared = await this.prepareDelegatedWorkspace(definition, delegation);
|
|
2501
|
+
const childSessionId = createId();
|
|
2502
|
+
const execution = this.delegatedExecutionContext(definition, delegation, runOptions, prepared.workDir, childSessionId, options);
|
|
2503
|
+
let edgeStarted = false;
|
|
2114
2504
|
try {
|
|
2115
2505
|
const session = await this.createAgentSession(agent, {
|
|
2506
|
+
id: childSessionId,
|
|
2507
|
+
kind: 'agent',
|
|
2508
|
+
parentSessionId: execution.child.parentSessionId ?? undefined,
|
|
2116
2509
|
title: `${delegation.name ?? definition.name}: ${truncateText(delegation.description, 80)}`,
|
|
2117
2510
|
metadata: {
|
|
2118
2511
|
__actoviqBackgroundParentRunId: options.parentRunId,
|
|
@@ -2121,6 +2514,7 @@ export class ActoviqAgentClient {
|
|
|
2121
2514
|
__actoviqAgentWorkDir: prepared.workDir,
|
|
2122
2515
|
__actoviqAgentWorktreePath: prepared.workspace?.path,
|
|
2123
2516
|
__actoviqAgentWorktreeBranch: prepared.workspace?.metadata.branch,
|
|
2517
|
+
...serializeAgentExecutionIdentity(execution.child),
|
|
2124
2518
|
},
|
|
2125
2519
|
});
|
|
2126
2520
|
if (runOptions.hooks) {
|
|
@@ -2137,74 +2531,189 @@ export class ActoviqAgentClient {
|
|
|
2137
2531
|
approver: runOptions.approver,
|
|
2138
2532
|
});
|
|
2139
2533
|
}
|
|
2140
|
-
|
|
2534
|
+
edgeStarted = await this.tryStartExecutionEdge(execution.edge);
|
|
2535
|
+
return await this.backgroundTaskManager.launch({
|
|
2141
2536
|
subagentType: definition.name,
|
|
2142
2537
|
description: delegation.description,
|
|
2143
2538
|
workDir: prepared.workDir,
|
|
2144
2539
|
parentRunId: options.parentRunId,
|
|
2145
2540
|
parentSessionId: options.parentSessionId,
|
|
2146
2541
|
sessionId: session.id,
|
|
2542
|
+
executionId: execution.child.rootExecutionId,
|
|
2543
|
+
executionNodeId: execution.child.executionId,
|
|
2147
2544
|
agentName: delegation.name,
|
|
2148
2545
|
worktreePath: prepared.workspace?.path,
|
|
2149
2546
|
worktreeBranch: prepared.workspace?.metadata.branch,
|
|
2150
|
-
onRun: (signal, updateProgress) => this.runBackgroundAgentSession({
|
|
2547
|
+
onRun: (signal, updateProgress, task) => this.runBackgroundAgentSession({
|
|
2151
2548
|
session,
|
|
2152
2549
|
prompt,
|
|
2153
2550
|
signal,
|
|
2154
2551
|
updateProgress,
|
|
2155
|
-
runOptions: this.prepareDelegatedRunOptions(runOptions, prepared.workDir,
|
|
2552
|
+
runOptions: this.prepareDelegatedRunOptions(runOptions, prepared.workDir, execution.child, task.id),
|
|
2156
2553
|
workspace: prepared.workspace,
|
|
2157
2554
|
}),
|
|
2158
|
-
onSettled: task => {
|
|
2555
|
+
onSettled: async (task) => {
|
|
2159
2556
|
this.updatePendingDelegation(options.parentSessionId ?? options.parentRunId, task);
|
|
2160
2557
|
this.enqueueTaskNotification(task);
|
|
2558
|
+
if (task.status === 'completed') {
|
|
2559
|
+
await this.tryCompleteExecutionEdge(execution.edge, task.text);
|
|
2560
|
+
}
|
|
2561
|
+
else {
|
|
2562
|
+
await this.tryFailExecutionEdge(execution.edge, task.error ?? `Background agent ${task.status}.`);
|
|
2563
|
+
}
|
|
2564
|
+
await this.resumeLateSubagentInputs({
|
|
2565
|
+
session,
|
|
2566
|
+
definition,
|
|
2567
|
+
options,
|
|
2568
|
+
runOptions,
|
|
2569
|
+
delegation,
|
|
2570
|
+
settledTask: task,
|
|
2571
|
+
});
|
|
2161
2572
|
},
|
|
2162
2573
|
});
|
|
2163
2574
|
}
|
|
2164
2575
|
catch (error) {
|
|
2576
|
+
if (edgeStarted) {
|
|
2577
|
+
await this.tryFailExecutionEdge(execution.edge, asError(error).message);
|
|
2578
|
+
}
|
|
2165
2579
|
await this.finalizeDelegatedWorkspace(prepared.workspace);
|
|
2166
2580
|
throw error;
|
|
2167
2581
|
}
|
|
2168
2582
|
}
|
|
2169
|
-
async launchBackgroundOnSession(session, agent, prompt, options, runOptions = {}, delegation = { description: prompt }, resumedFromTaskId) {
|
|
2583
|
+
async launchBackgroundOnSession(session, agent, prompt, options, runOptions = {}, delegation = { description: prompt }, resumedFromTaskId, deliveredMessageInputs = [], inheritedSeenInputIds = []) {
|
|
2170
2584
|
const definition = this.requireAgentDefinition(agent);
|
|
2585
|
+
const workDir = delegation.cwd ?? this.config.workDir;
|
|
2586
|
+
const execution = this.existingAgentExecutionContext(session, definition, delegation, runOptions, workDir, options, 'resume');
|
|
2587
|
+
const hasCollaborationEdge = execution.parent.executionId !== execution.child.executionId;
|
|
2588
|
+
const parentSessionId = options.parentSessionId === session.id
|
|
2589
|
+
? execution.child.parentSessionId ?? undefined
|
|
2590
|
+
: options.parentSessionId ?? execution.child.parentSessionId ?? undefined;
|
|
2591
|
+
const notificationParent = parentSessionId ?? options.parentRunId;
|
|
2171
2592
|
if (runOptions.hooks) {
|
|
2172
2593
|
session.setHooks(runOptions.hooks);
|
|
2173
2594
|
}
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2595
|
+
let edgeStarted = false;
|
|
2596
|
+
try {
|
|
2597
|
+
if (hasCollaborationEdge) {
|
|
2598
|
+
edgeStarted = await this.tryStartExecutionEdge(execution.edge);
|
|
2599
|
+
}
|
|
2600
|
+
return await this.backgroundTaskManager.launch({
|
|
2601
|
+
subagentType: definition.name,
|
|
2602
|
+
description: delegation.description,
|
|
2603
|
+
workDir,
|
|
2604
|
+
parentRunId: options.parentRunId,
|
|
2605
|
+
parentSessionId,
|
|
2606
|
+
sessionId: session.id,
|
|
2607
|
+
executionId: execution.child.rootExecutionId,
|
|
2608
|
+
executionNodeId: execution.child.executionId,
|
|
2609
|
+
agentName: delegation.name,
|
|
2610
|
+
resumedFromTaskId,
|
|
2611
|
+
seenInputIds: [
|
|
2612
|
+
...new Set([
|
|
2613
|
+
...inheritedSeenInputIds,
|
|
2614
|
+
...deliveredMessageInputs.map(input => input.id),
|
|
2615
|
+
]),
|
|
2616
|
+
],
|
|
2617
|
+
onRun: async (signal, updateProgress, task) => {
|
|
2618
|
+
const result = await this.runBackgroundAgentSession({
|
|
2619
|
+
session,
|
|
2620
|
+
prompt,
|
|
2621
|
+
signal,
|
|
2622
|
+
updateProgress,
|
|
2623
|
+
runOptions: this.prepareDelegatedRunOptions(runOptions, workDir, execution.child, task.id),
|
|
2624
|
+
});
|
|
2625
|
+
await Promise.all(deliveredMessageInputs.map(input => this.tryCompleteExecutionEdgeByCallId(input.rootExecutionId, input.edgeCallId, 'Delivered in the resumed Agent turn.')));
|
|
2626
|
+
return result;
|
|
2627
|
+
},
|
|
2628
|
+
onSettled: async (task) => {
|
|
2629
|
+
this.updatePendingDelegation(notificationParent, task);
|
|
2630
|
+
this.enqueueTaskNotification(task);
|
|
2631
|
+
if (task.status === 'completed' && hasCollaborationEdge) {
|
|
2632
|
+
await this.tryCompleteExecutionEdge(execution.edge, task.text);
|
|
2633
|
+
}
|
|
2634
|
+
else if (task.status !== 'completed' && hasCollaborationEdge) {
|
|
2635
|
+
await this.tryFailExecutionEdge(execution.edge, task.error ?? `Background agent ${task.status}.`);
|
|
2636
|
+
}
|
|
2637
|
+
if (task.status !== 'completed') {
|
|
2638
|
+
await Promise.all(deliveredMessageInputs.map(input => this.tryFailExecutionEdgeByCallId(input.rootExecutionId, input.edgeCallId, task.error ?? `Resumed Agent ${task.status}.`)));
|
|
2639
|
+
}
|
|
2640
|
+
await this.resumeLateSubagentInputs({
|
|
2641
|
+
session,
|
|
2642
|
+
definition,
|
|
2643
|
+
options: { ...options, parentSessionId },
|
|
2644
|
+
runOptions,
|
|
2645
|
+
delegation,
|
|
2646
|
+
settledTask: task,
|
|
2647
|
+
});
|
|
2648
|
+
},
|
|
2183
2649
|
});
|
|
2184
2650
|
}
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2651
|
+
catch (error) {
|
|
2652
|
+
if (edgeStarted) {
|
|
2653
|
+
await this.tryFailExecutionEdge(execution.edge, asError(error).message);
|
|
2654
|
+
}
|
|
2655
|
+
throw error;
|
|
2656
|
+
}
|
|
2657
|
+
}
|
|
2658
|
+
async resumeLateSubagentInputs(args) {
|
|
2659
|
+
const queued = await this.backgroundTaskManager.drainInputs(args.settledTask.id);
|
|
2660
|
+
if (queued.length === 0)
|
|
2661
|
+
return;
|
|
2662
|
+
const latestTask = await this.backgroundTaskManager.get(args.settledTask.id) ?? args.settledTask;
|
|
2663
|
+
if (args.settledTask.status !== 'completed') {
|
|
2664
|
+
await Promise.all(queued.map(input => this.tryFailExecutionEdgeByCallId(input.rootExecutionId, input.edgeCallId, args.settledTask.error ?? `Agent ${args.settledTask.status} before accepting the message.`)));
|
|
2665
|
+
return;
|
|
2666
|
+
}
|
|
2667
|
+
const prompt = queued.map(input => input.text).join('\n\n');
|
|
2668
|
+
try {
|
|
2669
|
+
await this.launchBackgroundOnSession(args.session, args.definition.name, prompt, args.options, args.runOptions, {
|
|
2670
|
+
...args.delegation,
|
|
2671
|
+
callId: createId(),
|
|
2672
|
+
description: `Deliver queued follow-up to ${args.delegation.name ?? args.definition.name}`,
|
|
2673
|
+
}, args.settledTask.id, queued, latestTask.seenInputIds ?? queued.map(input => input.id));
|
|
2674
|
+
}
|
|
2675
|
+
catch (error) {
|
|
2676
|
+
await Promise.all(queued.map(input => this.tryFailExecutionEdgeByCallId(input.rootExecutionId, input.edgeCallId, asError(error).message)));
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
async settleTerminalPromptTooLong(args, snapshot, error) {
|
|
2680
|
+
const workDir = this.resolveRunWorkDir(args.options);
|
|
2681
|
+
const identity = resolveAgentExecutionIdentity({
|
|
2682
|
+
runId: args.runId,
|
|
2683
|
+
session: args.session.snapshot(),
|
|
2684
|
+
metadata: withoutExecutionIdentityMetadata(args.options.metadata),
|
|
2685
|
+
model: this.resolveModel(args.options.model ?? snapshot.model),
|
|
2686
|
+
cwd: workDir,
|
|
2687
|
+
runtime: 'hadamard',
|
|
2688
|
+
});
|
|
2689
|
+
await this.executions.settleTurn(identity, args.runId, {
|
|
2690
|
+
outcome: 'errored',
|
|
2691
|
+
error: asError(error).message,
|
|
2692
|
+
}).catch((executionError) => {
|
|
2693
|
+
console.warn(`[AgentExecution] Failed to settle terminal prompt error ${args.runId}: ${asError(executionError).message}`);
|
|
2205
2694
|
});
|
|
2206
2695
|
}
|
|
2207
2696
|
async runBackgroundAgentSession(args) {
|
|
2697
|
+
const sessionSnapshot = args.session.snapshot();
|
|
2698
|
+
const identity = resolveAgentExecutionIdentity({
|
|
2699
|
+
runId: args.session.id,
|
|
2700
|
+
session: sessionSnapshot,
|
|
2701
|
+
metadata: withoutExecutionIdentityMetadata(args.runOptions.metadata),
|
|
2702
|
+
model: args.runOptions.model,
|
|
2703
|
+
cwd: args.runOptions.workDir ?? this.config.workDir,
|
|
2704
|
+
});
|
|
2705
|
+
let progressWrite = Promise.resolve();
|
|
2706
|
+
const unsubscribeExecution = this.executions.subscribe(identity.rootExecutionId, ({ snapshot }) => {
|
|
2707
|
+
const node = snapshot.nodes.find(candidate => candidate.id === identity.executionId);
|
|
2708
|
+
if (!node?.currentActivity)
|
|
2709
|
+
return;
|
|
2710
|
+
progressWrite = progressWrite
|
|
2711
|
+
.then(() => args.updateProgress({
|
|
2712
|
+
currentToolName: node.currentActivity?.toolName,
|
|
2713
|
+
progressSummary: node.currentActivity?.summary,
|
|
2714
|
+
}))
|
|
2715
|
+
.catch(() => undefined);
|
|
2716
|
+
});
|
|
2208
2717
|
try {
|
|
2209
2718
|
await args.updateProgress({
|
|
2210
2719
|
progressSummary: 'Agent is running.',
|
|
@@ -2246,7 +2755,36 @@ export class ActoviqAgentClient {
|
|
|
2246
2755
|
throw error;
|
|
2247
2756
|
}
|
|
2248
2757
|
finally {
|
|
2249
|
-
|
|
2758
|
+
unsubscribeExecution();
|
|
2759
|
+
await progressWrite;
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
async reconcileInterruptedAgentExecutions(tasks) {
|
|
2763
|
+
for (const task of tasks) {
|
|
2764
|
+
if (!task.sessionId || !task.executionId || !task.executionNodeId)
|
|
2765
|
+
continue;
|
|
2766
|
+
try {
|
|
2767
|
+
const session = await this.resumeSession(task.sessionId);
|
|
2768
|
+
const snapshot = session.snapshot();
|
|
2769
|
+
const workDir = typeof snapshot.metadata.__actoviqAgentWorkDir === 'string'
|
|
2770
|
+
? snapshot.metadata.__actoviqAgentWorkDir
|
|
2771
|
+
: task.workDir;
|
|
2772
|
+
const identity = resolveAgentExecutionIdentity({
|
|
2773
|
+
runId: task.runId ?? `background:${task.id}`,
|
|
2774
|
+
session: snapshot,
|
|
2775
|
+
model: task.model,
|
|
2776
|
+
cwd: workDir,
|
|
2777
|
+
});
|
|
2778
|
+
await this.executions.ensureThread(identity);
|
|
2779
|
+
await this.executions.settleTurn(identity, task.runId ?? `background:${task.id}`, {
|
|
2780
|
+
outcome: 'interrupted',
|
|
2781
|
+
error: task.error ?? 'Background execution was interrupted by a runtime restart.',
|
|
2782
|
+
});
|
|
2783
|
+
await this.executions.failOpenEdgesForExecution(identity.rootExecutionId, identity.executionId, task.error ?? 'Background execution was interrupted by a runtime restart.');
|
|
2784
|
+
}
|
|
2785
|
+
catch {
|
|
2786
|
+
// Corrupt or removed sessions must not prevent the runtime from starting.
|
|
2787
|
+
}
|
|
2250
2788
|
}
|
|
2251
2789
|
}
|
|
2252
2790
|
async compactSessionForSession(session, options = {}) {
|