actoviq-agent-sdk 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-zh.md +19 -3
- package/README.md +19 -3
- package/bin/actoviq-interactive-agent.js +5 -0
- package/bin/actoviq-link-runtime.js +74 -0
- package/bin/actoviq-react.js +5 -0
- package/dist/src/cli/actoviq-react.d.ts +3 -0
- package/dist/src/cli/actoviq-react.d.ts.map +1 -0
- package/dist/src/cli/actoviq-react.js +286 -0
- package/dist/src/cli/actoviq-react.js.map +1 -0
- package/dist/src/cli/bridge-interactive-agent.d.ts +2 -0
- package/dist/src/cli/bridge-interactive-agent.d.ts.map +1 -0
- package/dist/src/cli/bridge-interactive-agent.js +147 -0
- package/dist/src/cli/bridge-interactive-agent.js.map +1 -0
- package/dist/src/config/anthropicEnvMapping.d.ts +18 -0
- package/dist/src/config/anthropicEnvMapping.d.ts.map +1 -0
- package/dist/src/config/anthropicEnvMapping.js +40 -0
- package/dist/src/config/anthropicEnvMapping.js.map +1 -0
- package/dist/src/config/resolveRuntimeConfig.d.ts.map +1 -1
- package/dist/src/config/resolveRuntimeConfig.js +44 -23
- package/dist/src/config/resolveRuntimeConfig.js.map +1 -1
- package/dist/src/errors.d.ts +9 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +9 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/index.d.ts +23 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +21 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/memory/actoviqMemory.d.ts.map +1 -1
- package/dist/src/memory/actoviqMemory.js +10 -6
- package/dist/src/memory/actoviqMemory.js.map +1 -1
- package/dist/src/memory/actoviqTranscriptLogger.d.ts.map +1 -1
- package/dist/src/memory/actoviqTranscriptLogger.js +2 -2
- package/dist/src/memory/actoviqTranscriptLogger.js.map +1 -1
- package/dist/src/parity/actoviqBridgeEvents.d.ts +7 -0
- package/dist/src/parity/actoviqBridgeEvents.d.ts.map +1 -0
- package/dist/src/parity/actoviqBridgeEvents.js +135 -0
- package/dist/src/parity/actoviqBridgeEvents.js.map +1 -0
- package/dist/src/parity/actoviqBridgeSdk.d.ts +179 -0
- package/dist/src/parity/actoviqBridgeSdk.d.ts.map +1 -0
- package/dist/src/parity/actoviqBridgeSdk.js +1275 -0
- package/dist/src/parity/actoviqBridgeSdk.js.map +1 -0
- package/dist/src/parity/actoviqCleanBridgeCompatSdk.d.ts +277 -0
- package/dist/src/parity/actoviqCleanBridgeCompatSdk.d.ts.map +1 -0
- package/dist/src/parity/actoviqCleanBridgeCompatSdk.js +1391 -0
- package/dist/src/parity/actoviqCleanBridgeCompatSdk.js.map +1 -0
- package/dist/src/parity/actoviqTranscripts.d.ts +44 -0
- package/dist/src/parity/actoviqTranscripts.d.ts.map +1 -0
- package/dist/src/parity/actoviqTranscripts.js +282 -0
- package/dist/src/parity/actoviqTranscripts.js.map +1 -0
- package/dist/src/parity/portableSessions.d.ts +35 -0
- package/dist/src/parity/portableSessions.d.ts.map +1 -0
- package/dist/src/parity/portableSessions.js +237 -0
- package/dist/src/parity/portableSessions.js.map +1 -0
- package/dist/src/prompts/systemPrompt.d.ts +15 -0
- package/dist/src/prompts/systemPrompt.d.ts.map +1 -0
- package/dist/src/prompts/systemPrompt.js +73 -0
- package/dist/src/prompts/systemPrompt.js.map +1 -0
- package/dist/src/provider/client.d.ts +4 -0
- package/dist/src/provider/client.d.ts.map +1 -1
- package/dist/src/provider/client.js +82 -10
- package/dist/src/provider/client.js.map +1 -1
- package/dist/src/provider/json-parse.d.ts +7 -0
- package/dist/src/provider/json-parse.d.ts.map +1 -0
- package/dist/src/provider/json-parse.js +69 -0
- package/dist/src/provider/json-parse.js.map +1 -0
- package/dist/src/provider/openai-client.d.ts.map +1 -1
- package/dist/src/provider/openai-client.js +45 -5
- package/dist/src/provider/openai-client.js.map +1 -1
- package/dist/src/provider/openai-model-api.d.ts.map +1 -1
- package/dist/src/provider/openai-model-api.js +2 -7
- package/dist/src/provider/openai-model-api.js.map +1 -1
- package/dist/src/runtime/actoviqAgents.d.ts +6 -0
- package/dist/src/runtime/actoviqAgents.d.ts.map +1 -1
- package/dist/src/runtime/actoviqAgents.js +110 -14
- package/dist/src/runtime/actoviqAgents.js.map +1 -1
- package/dist/src/runtime/actoviqApiMicrocompact.d.ts +14 -0
- package/dist/src/runtime/actoviqApiMicrocompact.d.ts.map +1 -1
- package/dist/src/runtime/actoviqApiMicrocompact.js +111 -16
- package/dist/src/runtime/actoviqApiMicrocompact.js.map +1 -1
- package/dist/src/runtime/actoviqBackgroundTasks.d.ts +1 -0
- package/dist/src/runtime/actoviqBackgroundTasks.d.ts.map +1 -1
- package/dist/src/runtime/actoviqBackgroundTasks.js +1 -0
- package/dist/src/runtime/actoviqBackgroundTasks.js.map +1 -1
- package/dist/src/runtime/actoviqCompact.d.ts +43 -0
- package/dist/src/runtime/actoviqCompact.d.ts.map +1 -1
- package/dist/src/runtime/actoviqCompact.js +290 -8
- package/dist/src/runtime/actoviqCompact.js.map +1 -1
- package/dist/src/runtime/actoviqPermissions.d.ts.map +1 -1
- package/dist/src/runtime/actoviqPermissions.js +121 -55
- package/dist/src/runtime/actoviqPermissions.js.map +1 -1
- package/dist/src/runtime/agentClient.d.ts +11 -0
- package/dist/src/runtime/agentClient.d.ts.map +1 -1
- package/dist/src/runtime/agentClient.js +332 -6
- package/dist/src/runtime/agentClient.js.map +1 -1
- package/dist/src/runtime/conversationEngine.d.ts.map +1 -1
- package/dist/src/runtime/conversationEngine.js +585 -33
- package/dist/src/runtime/conversationEngine.js.map +1 -1
- package/dist/src/runtime/defaultActoviqAgents.d.ts +3 -0
- package/dist/src/runtime/defaultActoviqAgents.d.ts.map +1 -0
- package/dist/src/runtime/defaultActoviqAgents.js +44 -0
- package/dist/src/runtime/defaultActoviqAgents.js.map +1 -0
- package/dist/src/runtime/denialTracking.d.ts +10 -0
- package/dist/src/runtime/denialTracking.d.ts.map +1 -0
- package/dist/src/runtime/denialTracking.js +27 -0
- package/dist/src/runtime/denialTracking.js.map +1 -0
- package/dist/src/runtime/safetyChecks.d.ts +12 -0
- package/dist/src/runtime/safetyChecks.d.ts.map +1 -0
- package/dist/src/runtime/safetyChecks.js +68 -0
- package/dist/src/runtime/safetyChecks.js.map +1 -0
- package/dist/src/runtime/sessionManager.d.ts.map +1 -1
- package/dist/src/runtime/sessionManager.js +10 -5
- package/dist/src/runtime/sessionManager.js.map +1 -1
- package/dist/src/runtime/tools.d.ts.map +1 -1
- package/dist/src/runtime/tools.js +62 -3
- package/dist/src/runtime/tools.js.map +1 -1
- package/dist/src/scheduling/cron.d.ts +14 -0
- package/dist/src/scheduling/cron.d.ts.map +1 -0
- package/dist/src/scheduling/cron.js +159 -0
- package/dist/src/scheduling/cron.js.map +1 -0
- package/dist/src/scheduling/index.d.ts +3 -0
- package/dist/src/scheduling/index.d.ts.map +1 -0
- package/dist/src/scheduling/index.js +3 -0
- package/dist/src/scheduling/index.js.map +1 -0
- package/dist/src/scheduling/scheduler.d.ts +32 -0
- package/dist/src/scheduling/scheduler.d.ts.map +1 -0
- package/dist/src/scheduling/scheduler.js +196 -0
- package/dist/src/scheduling/scheduler.js.map +1 -0
- package/dist/src/storage/backgroundTaskStore.d.ts.map +1 -1
- package/dist/src/storage/backgroundTaskStore.js +3 -2
- package/dist/src/storage/backgroundTaskStore.js.map +1 -1
- package/dist/src/storage/mailboxStore.d.ts.map +1 -1
- package/dist/src/storage/mailboxStore.js +3 -3
- package/dist/src/storage/mailboxStore.js.map +1 -1
- package/dist/src/storage/pathSafety.d.ts +4 -0
- package/dist/src/storage/pathSafety.d.ts.map +1 -0
- package/dist/src/storage/pathSafety.js +28 -0
- package/dist/src/storage/pathSafety.js.map +1 -0
- package/dist/src/storage/sessionStore.d.ts +2 -2
- package/dist/src/storage/sessionStore.d.ts.map +1 -1
- package/dist/src/storage/sessionStore.js +23 -8
- package/dist/src/storage/sessionStore.js.map +1 -1
- package/dist/src/storage/teammateStore.d.ts.map +1 -1
- package/dist/src/storage/teammateStore.js +3 -2
- package/dist/src/storage/teammateStore.js.map +1 -1
- package/dist/src/tools/actoviqCoreTools.d.ts +28 -0
- package/dist/src/tools/actoviqCoreTools.d.ts.map +1 -0
- package/dist/src/tools/actoviqCoreTools.js +32 -0
- package/dist/src/tools/actoviqCoreTools.js.map +1 -0
- package/dist/src/tools/actoviqFileTools.d.ts.map +1 -1
- package/dist/src/tools/actoviqFileTools.js +349 -373
- package/dist/src/tools/actoviqFileTools.js.map +1 -1
- package/dist/src/tools/actoviqMiscTools.d.ts +11 -0
- package/dist/src/tools/actoviqMiscTools.d.ts.map +1 -0
- package/dist/src/tools/actoviqMiscTools.js +89 -0
- package/dist/src/tools/actoviqMiscTools.js.map +1 -0
- package/dist/src/tools/actoviqNotebookEdit.d.ts +4 -0
- package/dist/src/tools/actoviqNotebookEdit.d.ts.map +1 -0
- package/dist/src/tools/actoviqNotebookEdit.js +140 -0
- package/dist/src/tools/actoviqNotebookEdit.js.map +1 -0
- package/dist/src/tools/actoviqShellTools.d.ts +5 -0
- package/dist/src/tools/actoviqShellTools.d.ts.map +1 -0
- package/dist/src/tools/actoviqShellTools.js +64 -0
- package/dist/src/tools/actoviqShellTools.js.map +1 -0
- package/dist/src/tools/actoviqTaskTools.d.ts +12 -0
- package/dist/src/tools/actoviqTaskTools.d.ts.map +1 -0
- package/dist/src/tools/actoviqTaskTools.js +108 -0
- package/dist/src/tools/actoviqTaskTools.js.map +1 -0
- package/dist/src/tools/actoviqWebTools.d.ts +15 -0
- package/dist/src/tools/actoviqWebTools.d.ts.map +1 -0
- package/dist/src/tools/actoviqWebTools.js +427 -0
- package/dist/src/tools/actoviqWebTools.js.map +1 -0
- package/dist/src/tools/askUserQuestion/AskUserQuestionTool.d.ts +6 -0
- package/dist/src/tools/askUserQuestion/AskUserQuestionTool.d.ts.map +1 -0
- package/dist/src/tools/askUserQuestion/AskUserQuestionTool.js +43 -0
- package/dist/src/tools/askUserQuestion/AskUserQuestionTool.js.map +1 -0
- package/dist/src/tools/bash/BashTool.d.ts +14 -0
- package/dist/src/tools/bash/BashTool.d.ts.map +1 -0
- package/dist/src/tools/bash/BashTool.js +60 -0
- package/dist/src/tools/bash/BashTool.js.map +1 -0
- package/dist/src/tools/bash/prompt.d.ts +3 -0
- package/dist/src/tools/bash/prompt.d.ts.map +1 -0
- package/dist/src/tools/bash/prompt.js +63 -0
- package/dist/src/tools/bash/prompt.js.map +1 -0
- package/dist/src/tools/prompts/fileEditPrompt.d.ts +3 -0
- package/dist/src/tools/prompts/fileEditPrompt.d.ts.map +1 -0
- package/dist/src/tools/prompts/fileEditPrompt.js +14 -0
- package/dist/src/tools/prompts/fileEditPrompt.js.map +1 -0
- package/dist/src/tools/prompts/fileReadPrompt.d.ts +3 -0
- package/dist/src/tools/prompts/fileReadPrompt.d.ts.map +1 -0
- package/dist/src/tools/prompts/fileReadPrompt.js +18 -0
- package/dist/src/tools/prompts/fileReadPrompt.js.map +1 -0
- package/dist/src/tools/prompts/fileSearchPrompt.d.ts +2 -0
- package/dist/src/tools/prompts/fileSearchPrompt.d.ts.map +1 -0
- package/dist/src/tools/prompts/fileSearchPrompt.js +21 -0
- package/dist/src/tools/prompts/fileSearchPrompt.js.map +1 -0
- package/dist/src/tools/prompts/fileWritePrompt.d.ts +3 -0
- package/dist/src/tools/prompts/fileWritePrompt.d.ts.map +1 -0
- package/dist/src/tools/prompts/fileWritePrompt.js +13 -0
- package/dist/src/tools/prompts/fileWritePrompt.js.map +1 -0
- package/dist/src/tools/prompts/webFetchPrompt.d.ts +3 -0
- package/dist/src/tools/prompts/webFetchPrompt.d.ts.map +1 -0
- package/dist/src/tools/prompts/webFetchPrompt.js +13 -0
- package/dist/src/tools/prompts/webFetchPrompt.js.map +1 -0
- package/dist/src/tools/prompts/webSearchPrompt.d.ts +3 -0
- package/dist/src/tools/prompts/webSearchPrompt.d.ts.map +1 -0
- package/dist/src/tools/prompts/webSearchPrompt.js +17 -0
- package/dist/src/tools/prompts/webSearchPrompt.js.map +1 -0
- package/dist/src/tools/todo/TodoWriteTool.d.ts +20 -0
- package/dist/src/tools/todo/TodoWriteTool.d.ts.map +1 -0
- package/dist/src/tools/todo/TodoWriteTool.js +105 -0
- package/dist/src/tools/todo/TodoWriteTool.js.map +1 -0
- package/dist/src/types.d.ts +425 -3
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/workflow/workflowEngine.js +26 -3
- package/dist/src/workflow/workflowEngine.js.map +1 -1
- package/dist/src/workspace/actoviqWorkspace.d.ts.map +1 -1
- package/dist/src/workspace/actoviqWorkspace.js +25 -2
- package/dist/src/workspace/actoviqWorkspace.js.map +1 -1
- package/package.json +59 -11
- package/vendor/actoviq-runtime/cli.js +54 -0
|
@@ -0,0 +1,1391 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { createAgentSdk } from '../runtime/agentClient.js';
|
|
3
|
+
import { AsyncQueue } from '../runtime/asyncQueue.js';
|
|
4
|
+
import { extractTextFromContent } from '../runtime/messageUtils.js';
|
|
5
|
+
import { asError, isRecord, nowIso } from '../runtime/helpers.js';
|
|
6
|
+
import { mergeActoviqHooks } from '../hooks/actoviqHooks.js';
|
|
7
|
+
const BRIDGE_OPTION_MATRIX = [
|
|
8
|
+
{ option: 'executable', status: 'unsupported', notes: 'CLI executable selection has no clean runtime equivalent.' },
|
|
9
|
+
{ option: 'cliPath', status: 'unsupported', notes: 'CLI path selection is bridge-only.' },
|
|
10
|
+
{ option: 'homeDir', status: 'mapped', cleanTarget: 'CreateAgentSdkOptions.homeDir', notes: 'Mapped at client creation.' },
|
|
11
|
+
{ option: 'workDir', status: 'mapped', cleanTarget: 'CreateAgentSdkOptions.workDir', notes: 'Mapped at client creation; per-run changes are reported as unsupported.' },
|
|
12
|
+
{ option: 'model', status: 'exact', cleanTarget: 'AgentRunOptions.model', notes: 'Passed through to clean runs.' },
|
|
13
|
+
{ option: 'fallbackModel', status: 'unsupported', notes: 'Clean model API does not expose fallback model selection.' },
|
|
14
|
+
{ option: 'effort', status: 'unsupported', notes: 'Clean model API has no reasoning-effort field.' },
|
|
15
|
+
{ option: 'systemPrompt', status: 'exact', cleanTarget: 'AgentRunOptions.systemPrompt', notes: 'Passed through to clean runs.' },
|
|
16
|
+
{ option: 'appendSystemPrompt', status: 'mapped', cleanTarget: 'AgentRunOptions.systemPrompt', notes: 'Appended to systemPrompt text before the clean run.' },
|
|
17
|
+
{ option: 'permissionMode', status: 'mapped', cleanTarget: 'AgentRunOptions.permissionMode', notes: 'Bridge modes are translated to the closest clean permission mode.' },
|
|
18
|
+
{ option: 'dangerouslySkipPermissions', status: 'mapped', cleanTarget: 'AgentRunOptions.permissionMode', notes: 'true maps to bypassPermissions; bridge-compatible default is bypassPermissions.' },
|
|
19
|
+
{ option: 'maxTurns', status: 'simulated', cleanTarget: 'CreateAgentSdkOptions.maxToolIterations', notes: 'Bridge defaults can map at client creation; per-run maxTurns is reported as unsupported.' },
|
|
20
|
+
{ option: 'maxBudgetUsd', status: 'unsupported', notes: 'Clean runtime does not meter or stop by USD budget.' },
|
|
21
|
+
{ option: 'agent', status: 'exact', cleanTarget: 'runWithAgent/createAgentSession', notes: 'Passed to clean agent helpers.' },
|
|
22
|
+
{ option: 'agents', status: 'unsupported', notes: 'Bridge accepts raw CLI agent config; clean requires typed ActoviqAgentDefinition values at creation.' },
|
|
23
|
+
{ option: 'tools', status: 'mapped', cleanTarget: 'AgentRunOptions.tools / __actoviqUseDefaultTools', notes: 'none disables defaults; string arrays filter known clean default tools.' },
|
|
24
|
+
{ option: 'allowedTools', status: 'mapped', cleanTarget: 'AgentRunOptions.canUseTool', notes: 'Converted to a clean canUseTool allowlist.' },
|
|
25
|
+
{ option: 'disallowedTools', status: 'mapped', cleanTarget: 'AgentRunOptions.canUseTool', notes: 'Converted to a clean canUseTool denylist.' },
|
|
26
|
+
{ option: 'addDirs', status: 'unsupported', notes: 'Clean tools use their configured cwd; bridge add-dir is CLI-only.' },
|
|
27
|
+
{ option: 'mcpConfigs', status: 'mapped', cleanTarget: 'AgentRunOptions.mcpServers', notes: 'JSON MCP config objects are converted when they match supported clean MCP shapes.' },
|
|
28
|
+
{ option: 'strictMcpConfig', status: 'simulated', cleanTarget: 'mcpConfigs converter', notes: 'Unsupported MCP entries throw only when strictMcpConfig is true.' },
|
|
29
|
+
{ option: 'settings', status: 'unsupported', notes: 'Bridge runtime settings JSON is not consumed by clean runs.' },
|
|
30
|
+
{ option: 'settingSources', status: 'unsupported', notes: 'Bridge setting-source selection is CLI-only.' },
|
|
31
|
+
{ option: 'jsonSchema', status: 'unsupported', notes: 'Clean model request has no structured output schema field.' },
|
|
32
|
+
{ option: 'files', status: 'unsupported', notes: 'Bridge file attachment flags are CLI-only in this facade.' },
|
|
33
|
+
{ option: 'bare', status: 'unsupported', notes: 'Bridge bare prompt mode is CLI-only.' },
|
|
34
|
+
{ option: 'disableSlashCommands', status: 'simulated', notes: 'The facade avoids slash-command shortcuts when this is true.' },
|
|
35
|
+
{ option: 'includePartialMessages', status: 'exact', cleanTarget: 'bridge-compatible event adapter', notes: 'Controls text-delta event emission.' },
|
|
36
|
+
{ option: 'includeHookEvents', status: 'mapped', cleanTarget: 'bridge-compatible event adapter', notes: 'Includes permission, compact, and error hook-like events.' },
|
|
37
|
+
{ option: 'verbose', status: 'simulated', notes: 'Bridge always invokes verbose stream JSON; clean event detail is controlled by include* flags.' },
|
|
38
|
+
{ option: 'pluginDirs', status: 'unsupported', notes: 'Clean skills/plugins are loaded through typed skill directories, not bridge plugin dirs.' },
|
|
39
|
+
{ option: 'env', status: 'unsupported', notes: 'There is no child process environment in clean runs.' },
|
|
40
|
+
{ option: 'cliArgs', status: 'unsupported', notes: 'Raw CLI args are bridge-only.' },
|
|
41
|
+
{ option: 'sessionId', status: 'exact', cleanTarget: 'createSession/resumeSession', notes: 'Used for clean session creation and resume paths.' },
|
|
42
|
+
{ option: 'resume', status: 'mapped', cleanTarget: 'resumeSession', notes: 'String resumes a clean session; true resumes the most recent clean session.' },
|
|
43
|
+
{ option: 'continueMostRecent', status: 'mapped', cleanTarget: 'sessions.list()[0]', notes: 'Resumes the most recent clean session by last activity.' },
|
|
44
|
+
{ option: 'forkSession', status: 'mapped', cleanTarget: 'AgentSession.fork()', notes: 'Forks a clean session before running.' },
|
|
45
|
+
{ option: 'name', status: 'mapped', cleanTarget: 'SessionCreateOptions.title', notes: 'Used as a clean session title when a new session is created.' },
|
|
46
|
+
{ option: 'signal', status: 'exact', cleanTarget: 'AgentRunOptions.signal', notes: 'Passed through to clean runs.' },
|
|
47
|
+
];
|
|
48
|
+
const BRIDGE_ONLY_OPTIONS = new Set([
|
|
49
|
+
'executable',
|
|
50
|
+
'cliPath',
|
|
51
|
+
'fallbackModel',
|
|
52
|
+
'effort',
|
|
53
|
+
'maxBudgetUsd',
|
|
54
|
+
'agents',
|
|
55
|
+
'addDirs',
|
|
56
|
+
'settings',
|
|
57
|
+
'settingSources',
|
|
58
|
+
'jsonSchema',
|
|
59
|
+
'files',
|
|
60
|
+
'bare',
|
|
61
|
+
'pluginDirs',
|
|
62
|
+
'env',
|
|
63
|
+
'cliArgs',
|
|
64
|
+
]);
|
|
65
|
+
const CLEAN_SLASH_COMMANDS = new Set(['context', 'compact', 'memory', 'dream', 'tools', 'skills', 'agents']);
|
|
66
|
+
export function getActoviqCleanBridgeParityMatrix() {
|
|
67
|
+
return BRIDGE_OPTION_MATRIX.map(entry => ({ ...entry }));
|
|
68
|
+
}
|
|
69
|
+
export class ActoviqCleanBridgeRunStream {
|
|
70
|
+
queue = new AsyncQueue();
|
|
71
|
+
result;
|
|
72
|
+
constructor(executor) {
|
|
73
|
+
this.result = (async () => {
|
|
74
|
+
try {
|
|
75
|
+
return await executor({
|
|
76
|
+
emit: event => this.queue.push(event),
|
|
77
|
+
fail: error => this.queue.fail(error),
|
|
78
|
+
close: () => this.queue.close(),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
this.queue.fail(error);
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
this.queue.close();
|
|
87
|
+
}
|
|
88
|
+
})();
|
|
89
|
+
}
|
|
90
|
+
[Symbol.asyncIterator]() {
|
|
91
|
+
return this.queue[Symbol.asyncIterator]();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export class ActoviqCleanBridgeSession {
|
|
95
|
+
client;
|
|
96
|
+
session;
|
|
97
|
+
title;
|
|
98
|
+
defaults;
|
|
99
|
+
constructor(client, session, title, defaults) {
|
|
100
|
+
this.client = client;
|
|
101
|
+
this.session = session;
|
|
102
|
+
this.title = title;
|
|
103
|
+
this.defaults = defaults;
|
|
104
|
+
}
|
|
105
|
+
get id() {
|
|
106
|
+
return this.session.id;
|
|
107
|
+
}
|
|
108
|
+
async send(prompt, options = {}) {
|
|
109
|
+
return this.client.runInCleanSession(this.session, prompt, {
|
|
110
|
+
...this.defaults,
|
|
111
|
+
...options,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
stream(prompt, options = {}) {
|
|
115
|
+
return this.client.streamInCleanSession(this.session, prompt, {
|
|
116
|
+
...this.defaults,
|
|
117
|
+
...options,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
runSlashCommand(commandName, args = '', options = {}) {
|
|
121
|
+
return this.client.runSlashCommand(commandName, args, {
|
|
122
|
+
...this.defaults,
|
|
123
|
+
...options,
|
|
124
|
+
sessionId: this.id,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
runSkill(skill, args = '', options = {}) {
|
|
128
|
+
return this.client.runSkillInCleanSession(this.session, skill, args, {
|
|
129
|
+
...this.defaults,
|
|
130
|
+
...options,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
streamSlashCommand(commandName, args = '', options = {}) {
|
|
134
|
+
return this.client.streamSlashCommand(commandName, args, {
|
|
135
|
+
...this.defaults,
|
|
136
|
+
...options,
|
|
137
|
+
sessionId: this.id,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
streamSkill(skill, args = '', options = {}) {
|
|
141
|
+
return this.client.streamSkillInCleanSession(this.session, skill, args, {
|
|
142
|
+
...this.defaults,
|
|
143
|
+
...options,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
compact(args = '', options = {}) {
|
|
147
|
+
return this.client.compactContext(args, {
|
|
148
|
+
...this.defaults,
|
|
149
|
+
...options,
|
|
150
|
+
sessionId: this.id,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
info() {
|
|
154
|
+
return this.client.getCleanBridgeSessionInfo(this.id);
|
|
155
|
+
}
|
|
156
|
+
messages(options = {}) {
|
|
157
|
+
return this.client.getCleanBridgeSessionMessages(this.id, options);
|
|
158
|
+
}
|
|
159
|
+
compactBoundaries(options = {}) {
|
|
160
|
+
return this.client.getCleanBridgeCompactBoundaries(this.id, options);
|
|
161
|
+
}
|
|
162
|
+
latestCompactBoundary(options = {}) {
|
|
163
|
+
return this.client.getCleanBridgeLatestCompactBoundary(this.id, options);
|
|
164
|
+
}
|
|
165
|
+
compactState(options = {}) {
|
|
166
|
+
return this.session.compactState(options);
|
|
167
|
+
}
|
|
168
|
+
async fork(prompt, options = {}) {
|
|
169
|
+
const forked = await this.session.fork({ title: options.name ?? this.title });
|
|
170
|
+
return this.client.runInCleanSession(forked, prompt, {
|
|
171
|
+
...this.defaults,
|
|
172
|
+
...options,
|
|
173
|
+
forkSession: true,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
forkStream(prompt, options = {}) {
|
|
177
|
+
return new ActoviqCleanBridgeRunStream(async () => {
|
|
178
|
+
const forked = await this.session.fork({ title: options.name ?? this.title });
|
|
179
|
+
return this.client.streamInCleanSession(forked, prompt, {
|
|
180
|
+
...this.defaults,
|
|
181
|
+
...options,
|
|
182
|
+
forkSession: true,
|
|
183
|
+
}).result;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
export class ActoviqCleanBridgeAgentHandle {
|
|
188
|
+
client;
|
|
189
|
+
agent;
|
|
190
|
+
defaults;
|
|
191
|
+
constructor(client, agent, defaults = {}) {
|
|
192
|
+
this.client = client;
|
|
193
|
+
this.agent = agent;
|
|
194
|
+
this.defaults = defaults;
|
|
195
|
+
}
|
|
196
|
+
run(prompt, options = {}) {
|
|
197
|
+
return this.client.runWithAgent(this.agent, prompt, { ...this.defaults, ...options });
|
|
198
|
+
}
|
|
199
|
+
stream(prompt, options = {}) {
|
|
200
|
+
return this.client.streamWithAgent(this.agent, prompt, { ...this.defaults, ...options });
|
|
201
|
+
}
|
|
202
|
+
createSession(options = {}) {
|
|
203
|
+
return this.client.createAgentSession(this.agent, { ...this.defaults, ...options });
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
export class ActoviqCleanBridgeSkillHandle {
|
|
207
|
+
client;
|
|
208
|
+
skill;
|
|
209
|
+
defaults;
|
|
210
|
+
constructor(client, skill, defaults = {}) {
|
|
211
|
+
this.client = client;
|
|
212
|
+
this.skill = skill;
|
|
213
|
+
this.defaults = defaults;
|
|
214
|
+
}
|
|
215
|
+
run(args = '', options = {}) {
|
|
216
|
+
return this.client.runSkill(this.skill, args, { ...this.defaults, ...options });
|
|
217
|
+
}
|
|
218
|
+
stream(args = '', options = {}) {
|
|
219
|
+
return this.client.streamSkill(this.skill, args, { ...this.defaults, ...options });
|
|
220
|
+
}
|
|
221
|
+
runInSession(session, args = '', options = {}) {
|
|
222
|
+
return session.runSkill(this.skill, args, options);
|
|
223
|
+
}
|
|
224
|
+
streamInSession(session, args = '', options = {}) {
|
|
225
|
+
return session.streamSkill(this.skill, args, options);
|
|
226
|
+
}
|
|
227
|
+
metadata(options) {
|
|
228
|
+
return this.client.getSkillMetadata(this.skill, options);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
export class ActoviqCleanBridgeAgentsApi {
|
|
232
|
+
client;
|
|
233
|
+
constructor(client) {
|
|
234
|
+
this.client = client;
|
|
235
|
+
}
|
|
236
|
+
list() {
|
|
237
|
+
return this.client.listAgents();
|
|
238
|
+
}
|
|
239
|
+
use(agent, defaults = {}) {
|
|
240
|
+
return new ActoviqCleanBridgeAgentHandle(this.client, agent, defaults);
|
|
241
|
+
}
|
|
242
|
+
run(agent, prompt, options = {}) {
|
|
243
|
+
return this.client.runWithAgent(agent, prompt, options);
|
|
244
|
+
}
|
|
245
|
+
stream(agent, prompt, options = {}) {
|
|
246
|
+
return this.client.streamWithAgent(agent, prompt, options);
|
|
247
|
+
}
|
|
248
|
+
createSession(agent, options = {}) {
|
|
249
|
+
return this.client.createAgentSession(agent, options);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
export class ActoviqCleanBridgeSkillsApi {
|
|
253
|
+
client;
|
|
254
|
+
constructor(client) {
|
|
255
|
+
this.client = client;
|
|
256
|
+
}
|
|
257
|
+
list() {
|
|
258
|
+
return this.client.listSkills();
|
|
259
|
+
}
|
|
260
|
+
use(skill, defaults = {}) {
|
|
261
|
+
return new ActoviqCleanBridgeSkillHandle(this.client, skill, defaults);
|
|
262
|
+
}
|
|
263
|
+
run(skill, args = '', options = {}) {
|
|
264
|
+
return this.client.runSkill(skill, args, options);
|
|
265
|
+
}
|
|
266
|
+
stream(skill, args = '', options = {}) {
|
|
267
|
+
return this.client.streamSkill(skill, args, options);
|
|
268
|
+
}
|
|
269
|
+
listMetadata(options) {
|
|
270
|
+
return this.client.listSkillMetadata(options);
|
|
271
|
+
}
|
|
272
|
+
getMetadata(skill, options) {
|
|
273
|
+
return this.client.getSkillMetadata(skill, options);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
export class ActoviqCleanBridgeToolsApi {
|
|
277
|
+
client;
|
|
278
|
+
constructor(client) {
|
|
279
|
+
this.client = client;
|
|
280
|
+
}
|
|
281
|
+
list(options) {
|
|
282
|
+
return this.client.listTools(options);
|
|
283
|
+
}
|
|
284
|
+
listMetadata(options) {
|
|
285
|
+
return this.client.listToolMetadata(options);
|
|
286
|
+
}
|
|
287
|
+
getMetadata(toolName, options) {
|
|
288
|
+
return this.client.getToolMetadata(toolName, options);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
export class ActoviqCleanBridgeSlashCommandsApi {
|
|
292
|
+
client;
|
|
293
|
+
constructor(client) {
|
|
294
|
+
this.client = client;
|
|
295
|
+
}
|
|
296
|
+
list(options) {
|
|
297
|
+
return this.client.listSlashCommands(options);
|
|
298
|
+
}
|
|
299
|
+
listMetadata(options) {
|
|
300
|
+
return this.client.listSlashCommandMetadata(options);
|
|
301
|
+
}
|
|
302
|
+
getMetadata(commandName, options) {
|
|
303
|
+
return this.client.getSlashCommandMetadata(commandName, options);
|
|
304
|
+
}
|
|
305
|
+
run(commandName, args = '', options = {}) {
|
|
306
|
+
return this.client.runSlashCommand(commandName, args, options);
|
|
307
|
+
}
|
|
308
|
+
stream(commandName, args = '', options = {}) {
|
|
309
|
+
return this.client.streamSlashCommand(commandName, args, options);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
export class ActoviqCleanBridgeContextApi {
|
|
313
|
+
client;
|
|
314
|
+
constructor(client) {
|
|
315
|
+
this.client = client;
|
|
316
|
+
}
|
|
317
|
+
usage(options) {
|
|
318
|
+
return this.client.getContextUsage(options);
|
|
319
|
+
}
|
|
320
|
+
compact(args = '', options = {}) {
|
|
321
|
+
return this.client.compactContext(args, options);
|
|
322
|
+
}
|
|
323
|
+
streamCompact(args = '', options = {}) {
|
|
324
|
+
return this.client.streamSlashCommand('compact', args, options);
|
|
325
|
+
}
|
|
326
|
+
compactBoundaries(sessionId, options = {}) {
|
|
327
|
+
return this.client.getCleanBridgeCompactBoundaries(sessionId, options);
|
|
328
|
+
}
|
|
329
|
+
latestCompactBoundary(sessionId, options = {}) {
|
|
330
|
+
return this.client.getCleanBridgeLatestCompactBoundary(sessionId, options);
|
|
331
|
+
}
|
|
332
|
+
compactState(sessionId, options = {}) {
|
|
333
|
+
return this.client.clean.sessions.get(sessionId).then(session => session.compactState(options));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
export class ActoviqCleanBridgeSessionsApi {
|
|
337
|
+
client;
|
|
338
|
+
constructor(client) {
|
|
339
|
+
this.client = client;
|
|
340
|
+
}
|
|
341
|
+
list() {
|
|
342
|
+
return this.client.listCleanBridgeSessions();
|
|
343
|
+
}
|
|
344
|
+
getInfo(sessionId) {
|
|
345
|
+
return this.client.getCleanBridgeSessionInfo(sessionId);
|
|
346
|
+
}
|
|
347
|
+
getMessages(sessionId, options = {}) {
|
|
348
|
+
return this.client.getCleanBridgeSessionMessages(sessionId, options);
|
|
349
|
+
}
|
|
350
|
+
getCompactBoundaries(sessionId, options = {}) {
|
|
351
|
+
return this.client.getCleanBridgeCompactBoundaries(sessionId, options);
|
|
352
|
+
}
|
|
353
|
+
getLatestCompactBoundary(sessionId, options = {}) {
|
|
354
|
+
return this.client.getCleanBridgeLatestCompactBoundary(sessionId, options);
|
|
355
|
+
}
|
|
356
|
+
getCompactState(sessionId, options = {}) {
|
|
357
|
+
return this.client.clean.sessions.get(sessionId).then(session => session.compactState(options));
|
|
358
|
+
}
|
|
359
|
+
resume(sessionId, options = {}) {
|
|
360
|
+
return this.client.resumeSession(sessionId, options);
|
|
361
|
+
}
|
|
362
|
+
continueMostRecent(prompt, options = {}) {
|
|
363
|
+
return this.client.continueMostRecent(prompt, options);
|
|
364
|
+
}
|
|
365
|
+
streamContinueMostRecent(prompt, options = {}) {
|
|
366
|
+
return this.client.streamContinueMostRecent(prompt, options);
|
|
367
|
+
}
|
|
368
|
+
fork(sessionId, prompt, options = {}) {
|
|
369
|
+
return this.client.forkSession(sessionId, prompt, options);
|
|
370
|
+
}
|
|
371
|
+
streamFork(sessionId, prompt, options = {}) {
|
|
372
|
+
return this.client.streamForkSession(sessionId, prompt, options);
|
|
373
|
+
}
|
|
374
|
+
getRuntimeInfo(options) {
|
|
375
|
+
return this.client.getRuntimeInfo(options);
|
|
376
|
+
}
|
|
377
|
+
listAgents() {
|
|
378
|
+
return this.client.listAgents();
|
|
379
|
+
}
|
|
380
|
+
listSkills(options) {
|
|
381
|
+
return this.client.listSkills(options);
|
|
382
|
+
}
|
|
383
|
+
listSlashCommands(options) {
|
|
384
|
+
return this.client.listSlashCommands(options);
|
|
385
|
+
}
|
|
386
|
+
listTools(options) {
|
|
387
|
+
return this.client.listTools(options);
|
|
388
|
+
}
|
|
389
|
+
getRuntimeCatalog(options) {
|
|
390
|
+
return this.client.getRuntimeCatalog(options);
|
|
391
|
+
}
|
|
392
|
+
listSkillMetadata(options) {
|
|
393
|
+
return this.client.listSkillMetadata(options);
|
|
394
|
+
}
|
|
395
|
+
listSlashCommandMetadata(options) {
|
|
396
|
+
return this.client.listSlashCommandMetadata(options);
|
|
397
|
+
}
|
|
398
|
+
listToolMetadata(options) {
|
|
399
|
+
return this.client.listToolMetadata(options);
|
|
400
|
+
}
|
|
401
|
+
getContextUsage(options) {
|
|
402
|
+
return this.client.getContextUsage(options);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
export class ActoviqCleanBridgeSdkClient {
|
|
406
|
+
clean;
|
|
407
|
+
cleanDefaults;
|
|
408
|
+
bridgeDefaults;
|
|
409
|
+
unsupportedOptionPolicy;
|
|
410
|
+
sessions;
|
|
411
|
+
agents;
|
|
412
|
+
skills;
|
|
413
|
+
tools;
|
|
414
|
+
slashCommands;
|
|
415
|
+
context;
|
|
416
|
+
buddy;
|
|
417
|
+
memory;
|
|
418
|
+
constructor(clean, cleanDefaults, bridgeDefaults, unsupportedOptionPolicy) {
|
|
419
|
+
this.clean = clean;
|
|
420
|
+
this.cleanDefaults = cleanDefaults;
|
|
421
|
+
this.bridgeDefaults = bridgeDefaults;
|
|
422
|
+
this.unsupportedOptionPolicy = unsupportedOptionPolicy;
|
|
423
|
+
this.sessions = new ActoviqCleanBridgeSessionsApi(this);
|
|
424
|
+
this.agents = new ActoviqCleanBridgeAgentsApi(this);
|
|
425
|
+
this.skills = new ActoviqCleanBridgeSkillsApi(this);
|
|
426
|
+
this.tools = new ActoviqCleanBridgeToolsApi(this);
|
|
427
|
+
this.slashCommands = new ActoviqCleanBridgeSlashCommandsApi(this);
|
|
428
|
+
this.context = new ActoviqCleanBridgeContextApi(this);
|
|
429
|
+
this.buddy = clean.buddy;
|
|
430
|
+
this.memory = clean.memory;
|
|
431
|
+
}
|
|
432
|
+
static async create(options = {}) {
|
|
433
|
+
const { bridgeDefaults = {}, unsupportedOptionPolicy = 'metadata', ...cleanOptions } = options;
|
|
434
|
+
const resolvedCleanOptions = {
|
|
435
|
+
...cleanOptions,
|
|
436
|
+
maxToolIterations: cleanOptions.maxToolIterations ?? bridgeDefaults.maxTurns,
|
|
437
|
+
permissionMode: cleanOptions.permissionMode ?? mapBridgePermissionMode(bridgeDefaults.permissionMode, bridgeDefaults),
|
|
438
|
+
};
|
|
439
|
+
const clean = await createAgentSdk(resolvedCleanOptions);
|
|
440
|
+
return new ActoviqCleanBridgeSdkClient(clean, options, bridgeDefaults, unsupportedOptionPolicy);
|
|
441
|
+
}
|
|
442
|
+
parityMatrix() {
|
|
443
|
+
return getActoviqCleanBridgeParityMatrix();
|
|
444
|
+
}
|
|
445
|
+
explainOptions(options = {}) {
|
|
446
|
+
return this.buildRunPlan(options).report;
|
|
447
|
+
}
|
|
448
|
+
async run(prompt, options = {}) {
|
|
449
|
+
return this.executeCleanRun(prompt, options, plan => this.clean.run(prompt, plan.cleanOptions));
|
|
450
|
+
}
|
|
451
|
+
stream(prompt, options = {}) {
|
|
452
|
+
return this.streamCleanRun(prompt, options, plan => this.clean.stream(prompt, plan.cleanOptions));
|
|
453
|
+
}
|
|
454
|
+
runSlashCommand(commandName, args = '', options = {}) {
|
|
455
|
+
const normalized = normalizeCommandName(commandName);
|
|
456
|
+
if (options.disableSlashCommands) {
|
|
457
|
+
return this.run(formatSlashCommand(normalized, args), options);
|
|
458
|
+
}
|
|
459
|
+
if (normalized === 'compact') {
|
|
460
|
+
return this.compactContext(args, options);
|
|
461
|
+
}
|
|
462
|
+
if (CLEAN_SLASH_COMMANDS.has(normalized)) {
|
|
463
|
+
return this.executeCleanSlashCommand(normalized, args, options);
|
|
464
|
+
}
|
|
465
|
+
if (this.clean.getSkillDefinition(normalized)) {
|
|
466
|
+
return this.runSkill(normalized, args, options);
|
|
467
|
+
}
|
|
468
|
+
return this.run(formatSlashCommand(normalized, args), options);
|
|
469
|
+
}
|
|
470
|
+
streamSlashCommand(commandName, args = '', options = {}) {
|
|
471
|
+
const normalized = normalizeCommandName(commandName);
|
|
472
|
+
if (!options.disableSlashCommands && normalized === 'compact') {
|
|
473
|
+
return this.streamSyntheticRun(() => this.compactContext(args, options));
|
|
474
|
+
}
|
|
475
|
+
if (!options.disableSlashCommands && CLEAN_SLASH_COMMANDS.has(normalized)) {
|
|
476
|
+
return this.streamSyntheticRun(() => this.executeCleanSlashCommand(normalized, args, options));
|
|
477
|
+
}
|
|
478
|
+
if (!options.disableSlashCommands && this.clean.getSkillDefinition(normalized)) {
|
|
479
|
+
return this.streamSkill(normalized, args, options);
|
|
480
|
+
}
|
|
481
|
+
return this.stream(formatSlashCommand(normalized, args), options);
|
|
482
|
+
}
|
|
483
|
+
runWithAgent(agent, prompt, options = {}) {
|
|
484
|
+
return this.executeCleanRun(prompt, { ...options, agent }, plan => this.clean.runWithAgent(agent, prompt, plan.cleanOptions));
|
|
485
|
+
}
|
|
486
|
+
streamWithAgent(agent, prompt, options = {}) {
|
|
487
|
+
return this.streamCleanRun(prompt, { ...options, agent }, plan => this.clean.stream(prompt, mergeCleanAgentRunOptions(this.requireCleanAgentDefinition(agent), plan.cleanOptions)));
|
|
488
|
+
}
|
|
489
|
+
runSkill(skill, args = '', options = {}) {
|
|
490
|
+
return this.executeCleanRun(formatSlashCommand(skill, args), options, plan => this.clean.runSkill(skill, args, plan.cleanOptions));
|
|
491
|
+
}
|
|
492
|
+
streamSkill(skill, args = '', options = {}) {
|
|
493
|
+
return this.streamCleanRun(formatSlashCommand(skill, args), options, plan => this.clean.streamSkill(skill, args, plan.cleanOptions));
|
|
494
|
+
}
|
|
495
|
+
async continueMostRecent(prompt, options = {}) {
|
|
496
|
+
const session = await this.resolveMostRecentSession();
|
|
497
|
+
return this.runInCleanSession(session, prompt, {
|
|
498
|
+
...options,
|
|
499
|
+
continueMostRecent: true,
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
streamContinueMostRecent(prompt, options = {}) {
|
|
503
|
+
return new ActoviqCleanBridgeRunStream(async () => {
|
|
504
|
+
const session = await this.resolveMostRecentSession();
|
|
505
|
+
return this.streamInCleanSession(session, prompt, {
|
|
506
|
+
...options,
|
|
507
|
+
continueMostRecent: true,
|
|
508
|
+
}).result;
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
async forkSession(sessionId, prompt, options = {}) {
|
|
512
|
+
const session = await this.clean.resumeSession(sessionId);
|
|
513
|
+
const forked = await session.fork({ title: options.name });
|
|
514
|
+
return this.runInCleanSession(forked, prompt, {
|
|
515
|
+
...options,
|
|
516
|
+
forkSession: true,
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
streamForkSession(sessionId, prompt, options = {}) {
|
|
520
|
+
return new ActoviqCleanBridgeRunStream(async () => {
|
|
521
|
+
const session = await this.clean.resumeSession(sessionId);
|
|
522
|
+
const forked = await session.fork({ title: options.name });
|
|
523
|
+
return this.streamInCleanSession(forked, prompt, {
|
|
524
|
+
...options,
|
|
525
|
+
forkSession: true,
|
|
526
|
+
}).result;
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
async createSession(options = {}) {
|
|
530
|
+
if (options.sessionId) {
|
|
531
|
+
const existing = await this.clean.resumeSession(options.sessionId).catch(() => undefined);
|
|
532
|
+
if (existing) {
|
|
533
|
+
return new ActoviqCleanBridgeSession(this, existing, options.title, options);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
const cleanSession = await this.clean.createSession(this.toCleanSessionOptions(options, options.sessionId));
|
|
537
|
+
return new ActoviqCleanBridgeSession(this, cleanSession, options.title, options);
|
|
538
|
+
}
|
|
539
|
+
createAgentSession(agent, options = {}) {
|
|
540
|
+
return this.createSession({ ...options, agent });
|
|
541
|
+
}
|
|
542
|
+
useAgent(agent, defaults = {}) {
|
|
543
|
+
return this.agents.use(agent, defaults);
|
|
544
|
+
}
|
|
545
|
+
useSkill(skill, defaults = {}) {
|
|
546
|
+
return this.skills.use(skill, defaults);
|
|
547
|
+
}
|
|
548
|
+
async resumeSession(sessionId, options = {}) {
|
|
549
|
+
const session = await this.clean.resumeSession(sessionId);
|
|
550
|
+
return new ActoviqCleanBridgeSession(this, session, options.title, options);
|
|
551
|
+
}
|
|
552
|
+
close() {
|
|
553
|
+
return this.clean.close();
|
|
554
|
+
}
|
|
555
|
+
async getRuntimeInfo(options = {}) {
|
|
556
|
+
const catalog = await this.getRuntimeCatalog({ ...options, includeContext: false });
|
|
557
|
+
return catalog.runtime;
|
|
558
|
+
}
|
|
559
|
+
async listSkills(_options = {}) {
|
|
560
|
+
return this.clean.skills.listMetadata().map(skill => skill.name);
|
|
561
|
+
}
|
|
562
|
+
async listTools(options = {}) {
|
|
563
|
+
return (await this.listToolMetadata(options)).map(tool => tool.name);
|
|
564
|
+
}
|
|
565
|
+
async listSlashCommands(_options = {}) {
|
|
566
|
+
return (await this.listSlashCommandMetadata()).map(command => command.name);
|
|
567
|
+
}
|
|
568
|
+
async listAgents(_options = {}) {
|
|
569
|
+
return this.clean.agents.list().map(summary => ({
|
|
570
|
+
name: summary.name,
|
|
571
|
+
sourceGroup: 'clean',
|
|
572
|
+
active: true,
|
|
573
|
+
rawLine: summary.name,
|
|
574
|
+
model: summary.model,
|
|
575
|
+
}));
|
|
576
|
+
}
|
|
577
|
+
async getContextUsage(options = {}) {
|
|
578
|
+
const markdown = await this.clean.context.describe({
|
|
579
|
+
includeTools: true,
|
|
580
|
+
includeCompactState: false,
|
|
581
|
+
});
|
|
582
|
+
const rawResult = makeSyntheticBridgeResult(markdown, {
|
|
583
|
+
bridgeOptions: options,
|
|
584
|
+
report: this.buildRunPlan(options).report,
|
|
585
|
+
});
|
|
586
|
+
return {
|
|
587
|
+
markdown,
|
|
588
|
+
categories: [],
|
|
589
|
+
skills: this.clean.skills.listMetadata().map(skill => ({
|
|
590
|
+
name: skill.name,
|
|
591
|
+
source: skill.source,
|
|
592
|
+
tokens: 'unknown',
|
|
593
|
+
})),
|
|
594
|
+
agents: this.clean.agents.list().map(agent => ({
|
|
595
|
+
agentType: agent.name,
|
|
596
|
+
source: 'clean',
|
|
597
|
+
tokens: 'unknown',
|
|
598
|
+
})),
|
|
599
|
+
mcpTools: (await this.clean.tools.listMetadata()).filter(tool => tool.provider === 'mcp').map(tool => ({
|
|
600
|
+
tool: tool.name,
|
|
601
|
+
server: tool.server ?? 'mcp',
|
|
602
|
+
tokens: 'unknown',
|
|
603
|
+
})),
|
|
604
|
+
rawResult,
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
async getRuntimeCatalog(options = {}) {
|
|
608
|
+
const [agents, tools, skills, slashCommands] = await Promise.all([
|
|
609
|
+
this.listAgents(options),
|
|
610
|
+
this.listToolMetadata(options),
|
|
611
|
+
this.listSkillMetadata(options),
|
|
612
|
+
this.listSlashCommandMetadata(options),
|
|
613
|
+
]);
|
|
614
|
+
const runtime = {
|
|
615
|
+
sessionId: randomUUID(),
|
|
616
|
+
cwd: this.cleanDefaults.workDir,
|
|
617
|
+
model: options.model ?? this.cleanDefaults.model,
|
|
618
|
+
permissionMode: options.permissionMode ?? this.bridgeDefaults.permissionMode ?? this.cleanDefaults.permissionMode,
|
|
619
|
+
tools: tools.map(tool => tool.name),
|
|
620
|
+
mcpServers: tools
|
|
621
|
+
.filter(tool => tool.kind === 'mcp' && tool.server)
|
|
622
|
+
.map(tool => ({ name: tool.server, status: 'connected' })),
|
|
623
|
+
slashCommands: slashCommands.map(command => command.name),
|
|
624
|
+
agents: agents.map(agent => agent.name),
|
|
625
|
+
skills: skills.map(skill => skill.name),
|
|
626
|
+
plugins: [],
|
|
627
|
+
rawInitEvent: this.makeInitEvent({
|
|
628
|
+
sessionId: undefined,
|
|
629
|
+
options,
|
|
630
|
+
}),
|
|
631
|
+
};
|
|
632
|
+
return {
|
|
633
|
+
runtime,
|
|
634
|
+
agents: agents.map(agent => ({ ...agent, contextSource: 'clean' })),
|
|
635
|
+
tools,
|
|
636
|
+
skills,
|
|
637
|
+
slashCommands,
|
|
638
|
+
context: options.includeContext === false ? undefined : await this.getContextUsage(options),
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
async listSkillMetadata(_options = {}) {
|
|
642
|
+
return this.clean.skills.listMetadata().map(skill => ({
|
|
643
|
+
name: skill.name,
|
|
644
|
+
slashCommand: `/${skill.name}`,
|
|
645
|
+
source: skill.source,
|
|
646
|
+
tokens: 'unknown',
|
|
647
|
+
}));
|
|
648
|
+
}
|
|
649
|
+
async getSkillMetadata(skillName, options = {}) {
|
|
650
|
+
const normalized = normalizeCommandName(skillName);
|
|
651
|
+
return (await this.listSkillMetadata(options)).find(skill => skill.name === normalized);
|
|
652
|
+
}
|
|
653
|
+
async listToolMetadata(options = {}) {
|
|
654
|
+
const metadata = await this.clean.tools.listMetadata({
|
|
655
|
+
tools: this.filterToolsOption(options.tools),
|
|
656
|
+
mcpServers: convertMcpConfigs(options.mcpConfigs, options.strictMcpConfig).servers,
|
|
657
|
+
});
|
|
658
|
+
return metadata.map(tool => ({
|
|
659
|
+
name: tool.name,
|
|
660
|
+
kind: tool.provider === 'mcp' ? 'mcp' : 'builtin',
|
|
661
|
+
server: tool.server,
|
|
662
|
+
tokens: 'unknown',
|
|
663
|
+
}));
|
|
664
|
+
}
|
|
665
|
+
async getToolMetadata(toolName, options = {}) {
|
|
666
|
+
return (await this.listToolMetadata(options)).find(tool => tool.name === toolName);
|
|
667
|
+
}
|
|
668
|
+
async listSlashCommandMetadata(_options = {}) {
|
|
669
|
+
const cleanCommands = this.clean.slashCommands.listMetadata().map(command => ({
|
|
670
|
+
name: command.name,
|
|
671
|
+
kind: 'builtin',
|
|
672
|
+
}));
|
|
673
|
+
const skillCommands = this.clean.skills.listMetadata().map(skill => ({
|
|
674
|
+
name: skill.name,
|
|
675
|
+
kind: 'skill',
|
|
676
|
+
skillName: skill.name,
|
|
677
|
+
}));
|
|
678
|
+
const deduped = new Map();
|
|
679
|
+
for (const command of [...cleanCommands, ...skillCommands]) {
|
|
680
|
+
deduped.set(command.name, command);
|
|
681
|
+
}
|
|
682
|
+
return [...deduped.values()];
|
|
683
|
+
}
|
|
684
|
+
async getSlashCommandMetadata(commandName, options = {}) {
|
|
685
|
+
const normalized = normalizeCommandName(commandName);
|
|
686
|
+
return (await this.listSlashCommandMetadata(options)).find(command => command.name === normalized);
|
|
687
|
+
}
|
|
688
|
+
async compactContext(args = '', options = {}) {
|
|
689
|
+
const session = await this.resolveSessionFromOptions(options);
|
|
690
|
+
const compact = await session.compact({
|
|
691
|
+
force: true,
|
|
692
|
+
summaryInstructions: args || undefined,
|
|
693
|
+
});
|
|
694
|
+
return makeSyntheticBridgeResult([
|
|
695
|
+
'# Compact Result',
|
|
696
|
+
`Compacted: ${compact.compacted ? 'yes' : 'no'}`,
|
|
697
|
+
compact.summaryMessage ? '' : undefined,
|
|
698
|
+
compact.summaryMessage,
|
|
699
|
+
].filter(Boolean).join('\n'), {
|
|
700
|
+
sessionId: session.id,
|
|
701
|
+
bridgeOptions: options,
|
|
702
|
+
report: this.buildRunPlan(options).report,
|
|
703
|
+
subtype: 'success',
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
async runInCleanSession(session, prompt, options = {}) {
|
|
707
|
+
return this.executeCleanRun(prompt, { ...options, sessionId: session.id }, plan => session.send(prompt, plan.cleanOptions));
|
|
708
|
+
}
|
|
709
|
+
streamInCleanSession(session, prompt, options = {}) {
|
|
710
|
+
return this.streamCleanRun(prompt, { ...options, sessionId: session.id }, plan => session.stream(prompt, plan.cleanOptions));
|
|
711
|
+
}
|
|
712
|
+
runSkillInCleanSession(session, skill, args = '', options = {}) {
|
|
713
|
+
return this.executeCleanRun(formatSlashCommand(skill, args), { ...options, sessionId: session.id }, plan => session.runSkill(skill, args, plan.cleanOptions));
|
|
714
|
+
}
|
|
715
|
+
streamSkillInCleanSession(session, skill, args = '', options = {}) {
|
|
716
|
+
return this.streamCleanRun(formatSlashCommand(skill, args), { ...options, sessionId: session.id }, plan => session.streamSkill(skill, args, plan.cleanOptions));
|
|
717
|
+
}
|
|
718
|
+
async listCleanBridgeSessions() {
|
|
719
|
+
return this.clean.sessions.list();
|
|
720
|
+
}
|
|
721
|
+
async getCleanBridgeSessionInfo(sessionId) {
|
|
722
|
+
const session = await this.clean.resumeSession(sessionId);
|
|
723
|
+
const snapshot = session.snapshot();
|
|
724
|
+
return {
|
|
725
|
+
id: snapshot.id,
|
|
726
|
+
name: snapshot.title,
|
|
727
|
+
cwd: this.cleanDefaults.workDir,
|
|
728
|
+
createdAt: snapshot.createdAt,
|
|
729
|
+
updatedAt: snapshot.updatedAt,
|
|
730
|
+
lastActivityAt: snapshot.lastActiveAt ?? snapshot.lastRunAt ?? snapshot.updatedAt,
|
|
731
|
+
model: snapshot.model,
|
|
732
|
+
messageCount: snapshot.messages.length,
|
|
733
|
+
raw: snapshot,
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
async getCleanBridgeSessionMessages(sessionId, options = {}) {
|
|
737
|
+
const session = await this.clean.resumeSession(sessionId);
|
|
738
|
+
return session.messages
|
|
739
|
+
.map((message, index) => {
|
|
740
|
+
const type = message.role === 'assistant' ? 'assistant' : 'user';
|
|
741
|
+
return {
|
|
742
|
+
uuid: `${sessionId}-${index}`,
|
|
743
|
+
parentUuid: index > 0 ? `${sessionId}-${index - 1}` : null,
|
|
744
|
+
logicalParentUuid: index > 0 ? `${sessionId}-${index - 1}` : null,
|
|
745
|
+
type,
|
|
746
|
+
timestamp: session.snapshot().updatedAt,
|
|
747
|
+
sessionId,
|
|
748
|
+
cwd: this.cleanDefaults.workDir,
|
|
749
|
+
isSidechain: false,
|
|
750
|
+
message,
|
|
751
|
+
raw: {
|
|
752
|
+
type,
|
|
753
|
+
message,
|
|
754
|
+
},
|
|
755
|
+
};
|
|
756
|
+
})
|
|
757
|
+
.filter(message => options.includeSystemMessages || message.type !== 'system');
|
|
758
|
+
}
|
|
759
|
+
async getCleanBridgeCompactBoundaries(sessionId, options = {}) {
|
|
760
|
+
const session = await this.clean.resumeSession(sessionId);
|
|
761
|
+
const state = await session.compactState({
|
|
762
|
+
...options,
|
|
763
|
+
includeBoundaries: true,
|
|
764
|
+
});
|
|
765
|
+
return state.boundaries ?? [];
|
|
766
|
+
}
|
|
767
|
+
async getCleanBridgeLatestCompactBoundary(sessionId, options = {}) {
|
|
768
|
+
const session = await this.clean.resumeSession(sessionId);
|
|
769
|
+
const state = await session.compactState({
|
|
770
|
+
...options,
|
|
771
|
+
includeBoundaries: true,
|
|
772
|
+
});
|
|
773
|
+
return state.latestBoundary;
|
|
774
|
+
}
|
|
775
|
+
async executeCleanSlashCommand(commandName, args, options) {
|
|
776
|
+
const result = await this.clean.slashCommands.run(commandName, {
|
|
777
|
+
args,
|
|
778
|
+
sessionId: options.resume && typeof options.resume === 'string' ? options.resume : options.sessionId,
|
|
779
|
+
});
|
|
780
|
+
return makeSyntheticBridgeResult(result.text, {
|
|
781
|
+
sessionId: options.sessionId,
|
|
782
|
+
bridgeOptions: options,
|
|
783
|
+
report: this.buildRunPlan(options).report,
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
streamSyntheticRun(run) {
|
|
787
|
+
return new ActoviqCleanBridgeRunStream(async (controller) => {
|
|
788
|
+
const result = await run();
|
|
789
|
+
for (const event of result.events) {
|
|
790
|
+
controller.emit(event);
|
|
791
|
+
}
|
|
792
|
+
return result;
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
async executeCleanRun(prompt, options, runner) {
|
|
796
|
+
const plan = this.buildRunPlan(options);
|
|
797
|
+
this.handleUnsupportedOptions(plan.report.unsupported);
|
|
798
|
+
const startedAt = nowIso();
|
|
799
|
+
const cleanResult = await runner(plan);
|
|
800
|
+
return cleanResultToBridgeResult(cleanResult, {
|
|
801
|
+
prompt,
|
|
802
|
+
bridgeOptions: plan.bridgeOptions,
|
|
803
|
+
report: plan.report,
|
|
804
|
+
startedAt,
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
streamCleanRun(prompt, options, runner) {
|
|
808
|
+
return new ActoviqCleanBridgeRunStream(async (controller) => {
|
|
809
|
+
const plan = this.buildRunPlan(options);
|
|
810
|
+
this.handleUnsupportedOptions(plan.report.unsupported);
|
|
811
|
+
const startedAt = nowIso();
|
|
812
|
+
const bridgeEvents = [];
|
|
813
|
+
const cleanStream = runner(plan);
|
|
814
|
+
for await (const cleanEvent of cleanStream) {
|
|
815
|
+
for (const bridgeEvent of cleanEventToBridgeEvents(cleanEvent, plan.bridgeOptions)) {
|
|
816
|
+
bridgeEvents.push(structuredClone(bridgeEvent));
|
|
817
|
+
controller.emit(bridgeEvent);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
const cleanResult = await cleanStream.result;
|
|
821
|
+
return cleanResultToBridgeResult(cleanResult, {
|
|
822
|
+
prompt,
|
|
823
|
+
bridgeOptions: plan.bridgeOptions,
|
|
824
|
+
report: plan.report,
|
|
825
|
+
events: bridgeEvents,
|
|
826
|
+
startedAt,
|
|
827
|
+
});
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
buildRunPlan(options = {}) {
|
|
831
|
+
const bridgeOptions = {
|
|
832
|
+
...this.bridgeDefaults,
|
|
833
|
+
...options,
|
|
834
|
+
};
|
|
835
|
+
const report = {
|
|
836
|
+
mapped: [],
|
|
837
|
+
unsupported: [],
|
|
838
|
+
};
|
|
839
|
+
const cleanOptions = {
|
|
840
|
+
model: bridgeOptions.model,
|
|
841
|
+
signal: bridgeOptions.signal,
|
|
842
|
+
metadata: {
|
|
843
|
+
__actoviqBridgeCompatibility: report,
|
|
844
|
+
},
|
|
845
|
+
};
|
|
846
|
+
const systemPrompt = joinPromptParts(bridgeOptions.systemPrompt, bridgeOptions.appendSystemPrompt);
|
|
847
|
+
if (systemPrompt) {
|
|
848
|
+
cleanOptions.systemPrompt = systemPrompt;
|
|
849
|
+
report.mapped.push({ option: 'systemPrompt', cleanTarget: 'systemPrompt', status: 'exact' });
|
|
850
|
+
if (bridgeOptions.appendSystemPrompt) {
|
|
851
|
+
report.mapped.push({ option: 'appendSystemPrompt', cleanTarget: 'systemPrompt', status: 'mapped' });
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
if (bridgeOptions.model) {
|
|
855
|
+
report.mapped.push({ option: 'model', cleanTarget: 'model', status: 'exact' });
|
|
856
|
+
}
|
|
857
|
+
cleanOptions.permissionMode = mapBridgePermissionMode(bridgeOptions.permissionMode, bridgeOptions);
|
|
858
|
+
report.mapped.push({
|
|
859
|
+
option: 'permissionMode',
|
|
860
|
+
cleanTarget: 'permissionMode',
|
|
861
|
+
status: bridgeOptions.permissionMode === 'dontAsk' ? 'mapped' : 'exact',
|
|
862
|
+
note: bridgeOptions.permissionMode === 'dontAsk' ? 'dontAsk maps to default in clean mode.' : undefined,
|
|
863
|
+
});
|
|
864
|
+
if (bridgeOptions.dangerouslySkipPermissions !== undefined) {
|
|
865
|
+
report.mapped.push({
|
|
866
|
+
option: 'dangerouslySkipPermissions',
|
|
867
|
+
cleanTarget: 'permissionMode',
|
|
868
|
+
status: 'mapped',
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
const toolMapping = this.mapToolsOption(bridgeOptions.tools, report);
|
|
872
|
+
if (toolMapping.useDefaultTools !== undefined) {
|
|
873
|
+
cleanOptions.__actoviqUseDefaultTools = toolMapping.useDefaultTools;
|
|
874
|
+
}
|
|
875
|
+
if (toolMapping.tools) {
|
|
876
|
+
cleanOptions.tools = toolMapping.tools;
|
|
877
|
+
}
|
|
878
|
+
const mcpMapping = convertMcpConfigs(bridgeOptions.mcpConfigs, bridgeOptions.strictMcpConfig);
|
|
879
|
+
if (mcpMapping.servers.length > 0) {
|
|
880
|
+
cleanOptions.mcpServers = mcpMapping.servers;
|
|
881
|
+
report.mapped.push({ option: 'mcpConfigs', cleanTarget: 'mcpServers', status: 'mapped' });
|
|
882
|
+
}
|
|
883
|
+
for (const unsupported of mcpMapping.unsupported) {
|
|
884
|
+
report.unsupported.push(unsupported);
|
|
885
|
+
}
|
|
886
|
+
const canUseTool = createToolFilter(bridgeOptions.allowedTools, bridgeOptions.disallowedTools);
|
|
887
|
+
if (canUseTool) {
|
|
888
|
+
cleanOptions.canUseTool = canUseTool;
|
|
889
|
+
report.mapped.push({
|
|
890
|
+
option: 'allowedTools/disallowedTools',
|
|
891
|
+
cleanTarget: 'canUseTool',
|
|
892
|
+
status: 'mapped',
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
for (const option of Object.keys(bridgeOptions)) {
|
|
896
|
+
if (!BRIDGE_ONLY_OPTIONS.has(option)) {
|
|
897
|
+
continue;
|
|
898
|
+
}
|
|
899
|
+
const value = bridgeOptions[option];
|
|
900
|
+
if (value !== undefined) {
|
|
901
|
+
report.unsupported.push({
|
|
902
|
+
option,
|
|
903
|
+
value,
|
|
904
|
+
reason: BRIDGE_OPTION_MATRIX.find(entry => entry.option === option)?.notes ?? 'No clean runtime equivalent.',
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
if (bridgeOptions.maxTurns !== undefined && bridgeOptions.maxTurns !== this.bridgeDefaults.maxTurns) {
|
|
909
|
+
report.unsupported.push({
|
|
910
|
+
option: 'maxTurns',
|
|
911
|
+
value: bridgeOptions.maxTurns,
|
|
912
|
+
reason: 'Per-run maxTurns cannot override clean maxToolIterations after client creation.',
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
if (bridgeOptions.workDir !== undefined && bridgeOptions.workDir !== this.cleanDefaults.workDir) {
|
|
916
|
+
report.unsupported.push({
|
|
917
|
+
option: 'workDir',
|
|
918
|
+
value: bridgeOptions.workDir,
|
|
919
|
+
reason: 'Per-run workDir cannot override the clean client workDir.',
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
return {
|
|
923
|
+
bridgeOptions,
|
|
924
|
+
cleanOptions,
|
|
925
|
+
report,
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
handleUnsupportedOptions(unsupported) {
|
|
929
|
+
if (unsupported.length === 0 || this.unsupportedOptionPolicy === 'metadata') {
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
const message = unsupported
|
|
933
|
+
.map(entry => `${entry.option}: ${entry.reason}`)
|
|
934
|
+
.join('; ');
|
|
935
|
+
if (this.unsupportedOptionPolicy === 'throw') {
|
|
936
|
+
throw new Error(`Unsupported bridge option(s) in clean compatibility mode: ${message}`);
|
|
937
|
+
}
|
|
938
|
+
console.warn(`Unsupported bridge option(s) in clean compatibility mode: ${message}`);
|
|
939
|
+
}
|
|
940
|
+
mapToolsOption(tools, report) {
|
|
941
|
+
if (tools === undefined || tools === 'default') {
|
|
942
|
+
return {};
|
|
943
|
+
}
|
|
944
|
+
if (tools === 'none') {
|
|
945
|
+
report.mapped.push({ option: 'tools', cleanTarget: '__actoviqUseDefaultTools', status: 'mapped' });
|
|
946
|
+
return {
|
|
947
|
+
useDefaultTools: false,
|
|
948
|
+
tools: [],
|
|
949
|
+
};
|
|
950
|
+
}
|
|
951
|
+
const filtered = this.filterDefaultTools(tools);
|
|
952
|
+
report.mapped.push({ option: 'tools', cleanTarget: 'tools', status: 'mapped' });
|
|
953
|
+
return {
|
|
954
|
+
useDefaultTools: false,
|
|
955
|
+
tools: filtered,
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
filterToolsOption(tools) {
|
|
959
|
+
if (!Array.isArray(tools)) {
|
|
960
|
+
return undefined;
|
|
961
|
+
}
|
|
962
|
+
return this.filterDefaultTools(tools);
|
|
963
|
+
}
|
|
964
|
+
filterDefaultTools(toolNames) {
|
|
965
|
+
const desired = new Set(toolNames);
|
|
966
|
+
return [...(this.cleanDefaults.tools ?? [])].filter(tool => desired.has(tool.name) ||
|
|
967
|
+
(tool.aliases ?? []).some(alias => desired.has(alias)) ||
|
|
968
|
+
desired.has(tool.userFacingName?.() ?? ''));
|
|
969
|
+
}
|
|
970
|
+
toCleanSessionOptions(options, requestedSessionId) {
|
|
971
|
+
const definition = options.agent ? this.clean.getAgentDefinition(options.agent) : undefined;
|
|
972
|
+
return {
|
|
973
|
+
id: requestedSessionId,
|
|
974
|
+
title: options.title ?? requestedSessionId ?? options.agent,
|
|
975
|
+
systemPrompt: joinPromptParts(definition?.systemPrompt, options.systemPrompt, options.appendSystemPrompt),
|
|
976
|
+
model: options.model ?? definition?.model,
|
|
977
|
+
metadata: {
|
|
978
|
+
__actoviqBridgeSession: true,
|
|
979
|
+
__actoviqBridgeRequestedSessionId: requestedSessionId,
|
|
980
|
+
__actoviqBridgeAgent: options.agent,
|
|
981
|
+
},
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
requireCleanAgentDefinition(agent) {
|
|
985
|
+
const definition = this.clean.getAgentDefinition(agent);
|
|
986
|
+
if (!definition) {
|
|
987
|
+
throw new Error(`Unknown clean agent definition: ${agent}`);
|
|
988
|
+
}
|
|
989
|
+
return definition;
|
|
990
|
+
}
|
|
991
|
+
async resolveMostRecentSession() {
|
|
992
|
+
const [summary] = await this.clean.sessions.list();
|
|
993
|
+
if (summary) {
|
|
994
|
+
return this.clean.resumeSession(summary.id);
|
|
995
|
+
}
|
|
996
|
+
return this.clean.createSession({ title: 'Bridge-compatible session' });
|
|
997
|
+
}
|
|
998
|
+
async resolveSessionFromOptions(options) {
|
|
999
|
+
if (typeof options.resume === 'string') {
|
|
1000
|
+
return this.clean.resumeSession(options.resume);
|
|
1001
|
+
}
|
|
1002
|
+
if (options.sessionId) {
|
|
1003
|
+
return this.clean.resumeSession(options.sessionId).catch(() => this.clean.createSession({ title: options.name ?? options.sessionId }));
|
|
1004
|
+
}
|
|
1005
|
+
if (options.resume === true || options.continueMostRecent) {
|
|
1006
|
+
return this.resolveMostRecentSession();
|
|
1007
|
+
}
|
|
1008
|
+
return this.clean.createSession({ title: options.name ?? 'Bridge-compatible session' });
|
|
1009
|
+
}
|
|
1010
|
+
makeInitEvent(args) {
|
|
1011
|
+
return {
|
|
1012
|
+
type: 'system',
|
|
1013
|
+
subtype: 'init',
|
|
1014
|
+
session_id: args.sessionId ?? '',
|
|
1015
|
+
cwd: this.cleanDefaults.workDir,
|
|
1016
|
+
model: args.options.model ?? this.cleanDefaults.model,
|
|
1017
|
+
permissionMode: args.options.permissionMode ?? this.bridgeDefaults.permissionMode ?? this.cleanDefaults.permissionMode,
|
|
1018
|
+
tools: [],
|
|
1019
|
+
mcp_servers: [],
|
|
1020
|
+
slash_commands: this.clean.slashCommands.listMetadata().map(command => command.name),
|
|
1021
|
+
agents: this.clean.agents.list().map(agent => agent.name),
|
|
1022
|
+
skills: this.clean.skills.listMetadata().map(skill => skill.name),
|
|
1023
|
+
plugins: [],
|
|
1024
|
+
bridge_compat: true,
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
export async function createActoviqCleanBridgeSdk(options = {}) {
|
|
1029
|
+
return ActoviqCleanBridgeSdkClient.create(options);
|
|
1030
|
+
}
|
|
1031
|
+
function cleanResultToBridgeResult(result, context) {
|
|
1032
|
+
const events = context.events?.length
|
|
1033
|
+
? [...context.events]
|
|
1034
|
+
: synthesizeBridgeEvents(result, context);
|
|
1035
|
+
const assistantMessages = events.filter(event => event.type === 'assistant');
|
|
1036
|
+
const resultEvent = [...events].reverse().find(event => event.type === 'result') ??
|
|
1037
|
+
makeResultEvent(result, context.bridgeOptions);
|
|
1038
|
+
const initEvent = events.find(event => event.type === 'system' && event.subtype === 'init') ??
|
|
1039
|
+
makeInitEventFromResult(result, context.bridgeOptions);
|
|
1040
|
+
return {
|
|
1041
|
+
text: result.text,
|
|
1042
|
+
sessionId: result.sessionId ?? context.sessionId ?? '',
|
|
1043
|
+
isError: false,
|
|
1044
|
+
subtype: getStringValue(resultEvent, 'subtype') ?? 'success',
|
|
1045
|
+
stopReason: result.stopReason ?? undefined,
|
|
1046
|
+
durationMs: Math.max(0, new Date(result.completedAt).getTime() - new Date(result.startedAt).getTime()),
|
|
1047
|
+
totalCostUsd: undefined,
|
|
1048
|
+
numTurns: result.requests.length,
|
|
1049
|
+
exitCode: 0,
|
|
1050
|
+
stderr: '',
|
|
1051
|
+
initEvent,
|
|
1052
|
+
resultEvent,
|
|
1053
|
+
assistantMessages,
|
|
1054
|
+
events,
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
function makeSyntheticBridgeResult(text, context) {
|
|
1058
|
+
const sessionId = context.sessionId ?? context.bridgeOptions.sessionId ?? '';
|
|
1059
|
+
const timestamp = nowIso();
|
|
1060
|
+
const initEvent = {
|
|
1061
|
+
type: 'system',
|
|
1062
|
+
subtype: 'init',
|
|
1063
|
+
session_id: sessionId,
|
|
1064
|
+
bridge_compat: true,
|
|
1065
|
+
};
|
|
1066
|
+
const assistant = {
|
|
1067
|
+
type: 'assistant',
|
|
1068
|
+
session_id: sessionId,
|
|
1069
|
+
message: {
|
|
1070
|
+
role: 'assistant',
|
|
1071
|
+
content: [{ type: 'text', text }],
|
|
1072
|
+
},
|
|
1073
|
+
timestamp,
|
|
1074
|
+
};
|
|
1075
|
+
const resultEvent = {
|
|
1076
|
+
type: 'result',
|
|
1077
|
+
subtype: context.subtype ?? 'success',
|
|
1078
|
+
session_id: sessionId,
|
|
1079
|
+
is_error: false,
|
|
1080
|
+
result: text,
|
|
1081
|
+
stop_reason: 'end_turn',
|
|
1082
|
+
duration_ms: 0,
|
|
1083
|
+
num_turns: 1,
|
|
1084
|
+
bridge_compatibility: context.report,
|
|
1085
|
+
timestamp,
|
|
1086
|
+
};
|
|
1087
|
+
return {
|
|
1088
|
+
text,
|
|
1089
|
+
sessionId,
|
|
1090
|
+
isError: false,
|
|
1091
|
+
subtype: context.subtype ?? 'success',
|
|
1092
|
+
stopReason: 'end_turn',
|
|
1093
|
+
durationMs: 0,
|
|
1094
|
+
numTurns: 1,
|
|
1095
|
+
exitCode: 0,
|
|
1096
|
+
stderr: '',
|
|
1097
|
+
initEvent,
|
|
1098
|
+
resultEvent,
|
|
1099
|
+
assistantMessages: [assistant],
|
|
1100
|
+
events: [initEvent, assistant, resultEvent],
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
function synthesizeBridgeEvents(result, context) {
|
|
1104
|
+
const initEvent = makeInitEventFromResult(result, context.bridgeOptions);
|
|
1105
|
+
const assistant = {
|
|
1106
|
+
type: 'assistant',
|
|
1107
|
+
session_id: result.sessionId ?? context.sessionId,
|
|
1108
|
+
uuid: result.message.id,
|
|
1109
|
+
message: result.message,
|
|
1110
|
+
};
|
|
1111
|
+
const resultEvent = makeResultEvent(result, context.bridgeOptions, context.report);
|
|
1112
|
+
return [initEvent, assistant, resultEvent];
|
|
1113
|
+
}
|
|
1114
|
+
function cleanEventToBridgeEvents(event, options) {
|
|
1115
|
+
switch (event.type) {
|
|
1116
|
+
case 'run.started':
|
|
1117
|
+
return [{
|
|
1118
|
+
type: 'system',
|
|
1119
|
+
subtype: 'init',
|
|
1120
|
+
session_id: event.sessionId,
|
|
1121
|
+
model: event.model,
|
|
1122
|
+
permissionMode: options.permissionMode,
|
|
1123
|
+
bridge_compat: true,
|
|
1124
|
+
uuid: event.runId,
|
|
1125
|
+
timestamp: event.timestamp,
|
|
1126
|
+
}];
|
|
1127
|
+
case 'response.text.delta':
|
|
1128
|
+
if (options.includePartialMessages === false) {
|
|
1129
|
+
return [];
|
|
1130
|
+
}
|
|
1131
|
+
return [{
|
|
1132
|
+
type: 'assistant',
|
|
1133
|
+
subtype: 'text_delta',
|
|
1134
|
+
delta: event.delta,
|
|
1135
|
+
text: event.snapshot,
|
|
1136
|
+
uuid: event.runId,
|
|
1137
|
+
timestamp: event.timestamp,
|
|
1138
|
+
}];
|
|
1139
|
+
case 'response.content':
|
|
1140
|
+
return [{
|
|
1141
|
+
type: 'assistant',
|
|
1142
|
+
subtype: 'content',
|
|
1143
|
+
content: event.content,
|
|
1144
|
+
uuid: event.runId,
|
|
1145
|
+
timestamp: event.timestamp,
|
|
1146
|
+
}];
|
|
1147
|
+
case 'response.message':
|
|
1148
|
+
return [{
|
|
1149
|
+
type: 'assistant',
|
|
1150
|
+
subtype: 'message',
|
|
1151
|
+
message: event.message,
|
|
1152
|
+
uuid: event.message.id,
|
|
1153
|
+
timestamp: event.timestamp,
|
|
1154
|
+
}];
|
|
1155
|
+
case 'tool.call':
|
|
1156
|
+
return [{
|
|
1157
|
+
type: 'assistant',
|
|
1158
|
+
subtype: 'tool_use',
|
|
1159
|
+
tool_use: event.call,
|
|
1160
|
+
uuid: event.call.id,
|
|
1161
|
+
timestamp: event.timestamp,
|
|
1162
|
+
}];
|
|
1163
|
+
case 'tool.result':
|
|
1164
|
+
return [{
|
|
1165
|
+
type: 'user',
|
|
1166
|
+
subtype: 'tool_result',
|
|
1167
|
+
tool_result: event.result,
|
|
1168
|
+
uuid: event.result.id,
|
|
1169
|
+
timestamp: event.timestamp,
|
|
1170
|
+
}];
|
|
1171
|
+
case 'tool.permission':
|
|
1172
|
+
return options.includeHookEvents
|
|
1173
|
+
? [{
|
|
1174
|
+
type: 'hook',
|
|
1175
|
+
subtype: 'tool_permission',
|
|
1176
|
+
decision: event.decision,
|
|
1177
|
+
timestamp: event.timestamp,
|
|
1178
|
+
}]
|
|
1179
|
+
: [];
|
|
1180
|
+
case 'tool.progress':
|
|
1181
|
+
return options.includeHookEvents
|
|
1182
|
+
? [{
|
|
1183
|
+
type: 'hook',
|
|
1184
|
+
subtype: 'tool_progress',
|
|
1185
|
+
tool_use_id: event.toolUseId,
|
|
1186
|
+
data: event.data,
|
|
1187
|
+
timestamp: event.timestamp,
|
|
1188
|
+
}]
|
|
1189
|
+
: [];
|
|
1190
|
+
case 'session.compacted':
|
|
1191
|
+
return [{
|
|
1192
|
+
type: 'system',
|
|
1193
|
+
subtype: 'compact_boundary',
|
|
1194
|
+
session_id: event.sessionId,
|
|
1195
|
+
compactMetadata: event.result,
|
|
1196
|
+
timestamp: event.timestamp,
|
|
1197
|
+
}];
|
|
1198
|
+
case 'response.completed':
|
|
1199
|
+
return [makeResultEvent(event.result, options)];
|
|
1200
|
+
case 'error':
|
|
1201
|
+
return [{
|
|
1202
|
+
type: 'result',
|
|
1203
|
+
subtype: 'error',
|
|
1204
|
+
is_error: true,
|
|
1205
|
+
error: event.error,
|
|
1206
|
+
duration_ms: 0,
|
|
1207
|
+
timestamp: event.timestamp,
|
|
1208
|
+
}];
|
|
1209
|
+
default:
|
|
1210
|
+
if ('workflowName' in event && options.includeHookEvents) {
|
|
1211
|
+
return [{
|
|
1212
|
+
type: 'hook',
|
|
1213
|
+
subtype: event.type,
|
|
1214
|
+
event,
|
|
1215
|
+
timestamp: event.timestamp,
|
|
1216
|
+
}];
|
|
1217
|
+
}
|
|
1218
|
+
return [];
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
function makeInitEventFromResult(result, options) {
|
|
1222
|
+
return {
|
|
1223
|
+
type: 'system',
|
|
1224
|
+
subtype: 'init',
|
|
1225
|
+
session_id: result.sessionId,
|
|
1226
|
+
model: result.model,
|
|
1227
|
+
permissionMode: options.permissionMode,
|
|
1228
|
+
bridge_compat: true,
|
|
1229
|
+
uuid: result.runId,
|
|
1230
|
+
timestamp: result.startedAt,
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
function makeResultEvent(result, _options, report) {
|
|
1234
|
+
return {
|
|
1235
|
+
type: 'result',
|
|
1236
|
+
subtype: 'success',
|
|
1237
|
+
session_id: result.sessionId,
|
|
1238
|
+
is_error: false,
|
|
1239
|
+
result: result.text,
|
|
1240
|
+
stop_reason: result.stopReason ?? undefined,
|
|
1241
|
+
duration_ms: Math.max(0, new Date(result.completedAt).getTime() - new Date(result.startedAt).getTime()),
|
|
1242
|
+
num_turns: result.requests.length,
|
|
1243
|
+
bridge_compatibility: report,
|
|
1244
|
+
uuid: result.runId,
|
|
1245
|
+
timestamp: result.completedAt,
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
function mapBridgePermissionMode(mode, options = {}) {
|
|
1249
|
+
if (options.dangerouslySkipPermissions === true) {
|
|
1250
|
+
return 'bypassPermissions';
|
|
1251
|
+
}
|
|
1252
|
+
if (options.dangerouslySkipPermissions === false && mode === undefined) {
|
|
1253
|
+
return 'default';
|
|
1254
|
+
}
|
|
1255
|
+
if (mode === undefined) {
|
|
1256
|
+
return 'bypassPermissions';
|
|
1257
|
+
}
|
|
1258
|
+
if (mode === 'dontAsk') {
|
|
1259
|
+
return 'default';
|
|
1260
|
+
}
|
|
1261
|
+
return mode;
|
|
1262
|
+
}
|
|
1263
|
+
function mergeCleanAgentRunOptions(definition, options) {
|
|
1264
|
+
return {
|
|
1265
|
+
...options,
|
|
1266
|
+
systemPrompt: joinPromptParts(definition.systemPrompt, options.systemPrompt),
|
|
1267
|
+
model: options.model ?? definition.model,
|
|
1268
|
+
metadata: {
|
|
1269
|
+
...(definition.metadata ?? {}),
|
|
1270
|
+
...(options.metadata ?? {}),
|
|
1271
|
+
__actoviqAgentDefinition: definition.name,
|
|
1272
|
+
},
|
|
1273
|
+
hooks: mergeActoviqHooks(definition.hooks, options.hooks),
|
|
1274
|
+
tools: [...(definition.tools ?? []), ...(options.tools ?? [])],
|
|
1275
|
+
mcpServers: [...(definition.mcpServers ?? []), ...(options.mcpServers ?? [])],
|
|
1276
|
+
__actoviqUseDefaultTools: definition.inheritDefaultTools !== false,
|
|
1277
|
+
__actoviqUseDefaultMcpServers: definition.inheritDefaultMcpServers !== false,
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
function createToolFilter(allowedTools, disallowedTools) {
|
|
1281
|
+
const allowed = allowedTools?.length ? new Set(allowedTools) : undefined;
|
|
1282
|
+
const disallowed = disallowedTools?.length ? new Set(disallowedTools) : undefined;
|
|
1283
|
+
if (!allowed && !disallowed) {
|
|
1284
|
+
return undefined;
|
|
1285
|
+
}
|
|
1286
|
+
return (context) => {
|
|
1287
|
+
const names = [context.publicName, context.toolName];
|
|
1288
|
+
if (disallowed && names.some(name => disallowed.has(name))) {
|
|
1289
|
+
return { behavior: 'deny', reason: 'Denied by bridge disallowedTools.' };
|
|
1290
|
+
}
|
|
1291
|
+
if (allowed && !names.some(name => allowed.has(name))) {
|
|
1292
|
+
return { behavior: 'deny', reason: 'Denied because bridge allowedTools did not include this tool.' };
|
|
1293
|
+
}
|
|
1294
|
+
return { behavior: 'allow', reason: 'Allowed by bridge tool filter.' };
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
function convertMcpConfigs(configs, strict = false) {
|
|
1298
|
+
const servers = [];
|
|
1299
|
+
const unsupported = [];
|
|
1300
|
+
for (const config of configs ?? []) {
|
|
1301
|
+
const parsed = typeof config === 'string' ? parseJsonMaybe(config) : config;
|
|
1302
|
+
if (!isRecord(parsed)) {
|
|
1303
|
+
const entry = {
|
|
1304
|
+
option: 'mcpConfigs',
|
|
1305
|
+
value: config,
|
|
1306
|
+
reason: 'String MCP configs must contain JSON to be converted by clean compatibility mode.',
|
|
1307
|
+
};
|
|
1308
|
+
if (strict)
|
|
1309
|
+
throw new Error(entry.reason);
|
|
1310
|
+
unsupported.push(entry);
|
|
1311
|
+
continue;
|
|
1312
|
+
}
|
|
1313
|
+
const root = isRecord(parsed.mcpServers) ? parsed.mcpServers : parsed;
|
|
1314
|
+
for (const [name, value] of Object.entries(root)) {
|
|
1315
|
+
if (!isRecord(value)) {
|
|
1316
|
+
continue;
|
|
1317
|
+
}
|
|
1318
|
+
const command = typeof value.command === 'string' ? value.command : undefined;
|
|
1319
|
+
const url = typeof value.url === 'string' ? value.url : undefined;
|
|
1320
|
+
if (command) {
|
|
1321
|
+
servers.push({
|
|
1322
|
+
kind: 'stdio',
|
|
1323
|
+
name,
|
|
1324
|
+
command,
|
|
1325
|
+
args: Array.isArray(value.args) ? value.args.filter((entry) => typeof entry === 'string') : undefined,
|
|
1326
|
+
env: isStringRecord(value.env) ? value.env : undefined,
|
|
1327
|
+
cwd: typeof value.cwd === 'string' ? value.cwd : undefined,
|
|
1328
|
+
});
|
|
1329
|
+
continue;
|
|
1330
|
+
}
|
|
1331
|
+
if (url) {
|
|
1332
|
+
servers.push({
|
|
1333
|
+
kind: 'streamable_http',
|
|
1334
|
+
name,
|
|
1335
|
+
url,
|
|
1336
|
+
headers: isStringRecord(value.headers) ? value.headers : undefined,
|
|
1337
|
+
});
|
|
1338
|
+
continue;
|
|
1339
|
+
}
|
|
1340
|
+
const entry = {
|
|
1341
|
+
option: 'mcpConfigs',
|
|
1342
|
+
value,
|
|
1343
|
+
reason: `MCP server "${name}" is not a supported clean stdio or streamable_http shape.`,
|
|
1344
|
+
};
|
|
1345
|
+
if (strict)
|
|
1346
|
+
throw new Error(entry.reason);
|
|
1347
|
+
unsupported.push(entry);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
return { servers, unsupported };
|
|
1351
|
+
}
|
|
1352
|
+
function parseJsonMaybe(input) {
|
|
1353
|
+
try {
|
|
1354
|
+
return JSON.parse(input);
|
|
1355
|
+
}
|
|
1356
|
+
catch {
|
|
1357
|
+
return input;
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
function isStringRecord(value) {
|
|
1361
|
+
return isRecord(value) && Object.values(value).every(entry => typeof entry === 'string');
|
|
1362
|
+
}
|
|
1363
|
+
function formatSlashCommand(commandName, args = '') {
|
|
1364
|
+
const normalized = normalizeCommandName(commandName);
|
|
1365
|
+
const trimmed = args.trim();
|
|
1366
|
+
return trimmed ? `/${normalized} ${trimmed}` : `/${normalized}`;
|
|
1367
|
+
}
|
|
1368
|
+
function normalizeCommandName(commandName) {
|
|
1369
|
+
return commandName.trim().replace(/^\/+/u, '');
|
|
1370
|
+
}
|
|
1371
|
+
function joinPromptParts(...parts) {
|
|
1372
|
+
const text = parts
|
|
1373
|
+
.map(part => part?.trim())
|
|
1374
|
+
.filter((part) => Boolean(part))
|
|
1375
|
+
.join('\n\n');
|
|
1376
|
+
return text || undefined;
|
|
1377
|
+
}
|
|
1378
|
+
function getStringValue(record, key) {
|
|
1379
|
+
if (!isRecord(record)) {
|
|
1380
|
+
return undefined;
|
|
1381
|
+
}
|
|
1382
|
+
const value = record[key];
|
|
1383
|
+
return typeof value === 'string' ? value : undefined;
|
|
1384
|
+
}
|
|
1385
|
+
export function bridgePromptFromMessageContent(input) {
|
|
1386
|
+
return typeof input === 'string' ? input : extractTextFromContent(input);
|
|
1387
|
+
}
|
|
1388
|
+
export function normalizeCleanBridgeError(error) {
|
|
1389
|
+
return asError(error);
|
|
1390
|
+
}
|
|
1391
|
+
//# sourceMappingURL=actoviqCleanBridgeCompatSdk.js.map
|