@zds-ai/cli 0.1.8 → 0.1.10
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.md +387 -34
- package/dist/agent/context-manager.d.ts +70 -0
- package/dist/agent/context-manager.js +138 -0
- package/dist/agent/context-manager.js.map +1 -0
- package/dist/agent/hook-manager.d.ts +194 -0
- package/dist/agent/hook-manager.js +676 -0
- package/dist/agent/hook-manager.js.map +1 -0
- package/dist/agent/llm-agent.d.ts +469 -100
- package/dist/agent/llm-agent.js +781 -1580
- package/dist/agent/llm-agent.js.map +1 -1
- package/dist/agent/message-processor.d.ts +103 -0
- package/dist/agent/message-processor.js +225 -0
- package/dist/agent/message-processor.js.map +1 -0
- package/dist/agent/prompt-variables.d.ts +103 -40
- package/dist/agent/prompt-variables.js +250 -113
- package/dist/agent/prompt-variables.js.map +1 -1
- package/dist/agent/session-manager.d.ts +75 -0
- package/dist/agent/session-manager.js +194 -0
- package/dist/agent/session-manager.js.map +1 -0
- package/dist/agent/tool-executor.d.ts +111 -0
- package/dist/agent/tool-executor.js +397 -0
- package/dist/agent/tool-executor.js.map +1 -0
- package/dist/bin/generate_image_sd.sh +19 -12
- package/dist/bin/joycaption.sh +37 -0
- package/dist/grok/client.d.ts +52 -0
- package/dist/grok/client.js +127 -19
- package/dist/grok/client.js.map +1 -1
- package/dist/grok/tools.js +42 -8
- package/dist/grok/tools.js.map +1 -1
- package/dist/hooks/use-input-handler.d.ts +1 -1
- package/dist/hooks/use-input-handler.js +100 -13
- package/dist/hooks/use-input-handler.js.map +1 -1
- package/dist/index.js +25 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp/config.d.ts +1 -0
- package/dist/mcp/config.js +45 -7
- package/dist/mcp/config.js.map +1 -1
- package/dist/tools/character-tool.js +13 -1
- package/dist/tools/character-tool.js.map +1 -1
- package/dist/tools/image-tool.d.ts +11 -1
- package/dist/tools/image-tool.js +109 -2
- package/dist/tools/image-tool.js.map +1 -1
- package/dist/tools/introspect-tool.js +131 -30
- package/dist/tools/introspect-tool.js.map +1 -1
- package/dist/tools/morph-editor.d.ts +21 -9
- package/dist/tools/morph-editor.js +21 -9
- package/dist/tools/morph-editor.js.map +1 -1
- package/dist/ui/components/active-task-status.d.ts +1 -1
- package/dist/ui/components/api-key-input.d.ts +1 -1
- package/dist/ui/components/backend-status.d.ts +1 -1
- package/dist/ui/components/chat-history.d.ts +1 -1
- package/dist/ui/components/chat-interface.d.ts +1 -1
- package/dist/ui/components/chat-interface.js +1 -1
- package/dist/ui/components/chat-interface.js.map +1 -1
- package/dist/ui/components/context-status.d.ts +1 -1
- package/dist/ui/components/mood-status.d.ts +1 -1
- package/dist/ui/components/persona-status.d.ts +1 -1
- package/dist/utils/chat-history-manager.d.ts +12 -4
- package/dist/utils/chat-history-manager.js +26 -11
- package/dist/utils/chat-history-manager.js.map +1 -1
- package/dist/utils/hook-executor.d.ts +53 -2
- package/dist/utils/hook-executor.js +258 -36
- package/dist/utils/hook-executor.js.map +1 -1
- package/dist/utils/rephrase-handler.d.ts +1 -1
- package/dist/utils/settings-manager.d.ts +41 -11
- package/dist/utils/settings-manager.js +172 -40
- package/dist/utils/settings-manager.js.map +1 -1
- package/dist/utils/slash-commands.d.ts +3 -3
- package/dist/utils/slash-commands.js +11 -5
- package/dist/utils/slash-commands.js.map +1 -1
- package/dist/utils/startup-hook.js +9 -2
- package/dist/utils/startup-hook.js.map +1 -1
- package/package.json +10 -8
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ChatEntry } from "./llm-agent.js";
|
|
2
|
+
import { TokenCounter } from "../utils/token-counter.js";
|
|
3
|
+
import { LLMMessage } from "../grok/client.js";
|
|
4
|
+
/**
|
|
5
|
+
* Dependencies required by ContextManager for managing conversation context
|
|
6
|
+
*/
|
|
7
|
+
export interface ContextManagerDependencies {
|
|
8
|
+
/** Chat history entries for display */
|
|
9
|
+
chatHistory: ChatEntry[];
|
|
10
|
+
/** LLM API messages array */
|
|
11
|
+
messages: LLMMessage[];
|
|
12
|
+
/** Token counter instance */
|
|
13
|
+
tokenCounter: TokenCounter;
|
|
14
|
+
/** Get current token count */
|
|
15
|
+
getCurrentTokenCount: () => number;
|
|
16
|
+
/** Get maximum context size */
|
|
17
|
+
getMaxContextSize: () => number;
|
|
18
|
+
/** Emit events */
|
|
19
|
+
emit: (event: string, data: any) => void;
|
|
20
|
+
/** Clear cache when context limit reached */
|
|
21
|
+
clearCache: () => Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Manages conversation context size, warnings, and compaction
|
|
25
|
+
*
|
|
26
|
+
* Handles:
|
|
27
|
+
* - Context usage monitoring and warnings
|
|
28
|
+
* - Automatic cache clearing at 100% capacity
|
|
29
|
+
* - Context compaction when size limits exceeded
|
|
30
|
+
* - Event emission for context changes
|
|
31
|
+
*/
|
|
32
|
+
export declare class ContextManager {
|
|
33
|
+
private deps;
|
|
34
|
+
/** Warning flag for 80% context usage (one-time) */
|
|
35
|
+
private contextWarningAt80;
|
|
36
|
+
/** Warning flag for 90% context usage (one-time) */
|
|
37
|
+
private contextWarningAt90;
|
|
38
|
+
constructor(deps: ContextManagerDependencies);
|
|
39
|
+
/**
|
|
40
|
+
* Emit context change event and add warnings if needed
|
|
41
|
+
* Called after message additions to monitor context usage
|
|
42
|
+
*/
|
|
43
|
+
emitContextChange(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Add system warnings based on context usage percentage
|
|
46
|
+
* - 80%: Initial warning (one-time)
|
|
47
|
+
* - 90%: Urgent warning (one-time)
|
|
48
|
+
* - 95%: Critical warning (every time)
|
|
49
|
+
* - 100%: Auto-clear cache
|
|
50
|
+
*/
|
|
51
|
+
private addContextWarningIfNeeded;
|
|
52
|
+
/**
|
|
53
|
+
* Calculate current context usage as percentage
|
|
54
|
+
* @returns Percentage of context capacity used (0-100+)
|
|
55
|
+
*/
|
|
56
|
+
getContextUsagePercent(): number;
|
|
57
|
+
/**
|
|
58
|
+
* Compact context by keeping only the last N messages
|
|
59
|
+
* Used when context becomes too large for backend to handle
|
|
60
|
+
*
|
|
61
|
+
* @param keepLastMessages Number of recent messages to retain
|
|
62
|
+
* @returns Number of messages removed
|
|
63
|
+
*/
|
|
64
|
+
compactContext(keepLastMessages?: number): number;
|
|
65
|
+
/**
|
|
66
|
+
* Reset context warning flags
|
|
67
|
+
* Called when cache is cleared to allow warnings to trigger again
|
|
68
|
+
*/
|
|
69
|
+
resetContextWarnings(): void;
|
|
70
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages conversation context size, warnings, and compaction
|
|
3
|
+
*
|
|
4
|
+
* Handles:
|
|
5
|
+
* - Context usage monitoring and warnings
|
|
6
|
+
* - Automatic cache clearing at 100% capacity
|
|
7
|
+
* - Context compaction when size limits exceeded
|
|
8
|
+
* - Event emission for context changes
|
|
9
|
+
*/
|
|
10
|
+
export class ContextManager {
|
|
11
|
+
deps;
|
|
12
|
+
/** Warning flag for 80% context usage (one-time) */
|
|
13
|
+
contextWarningAt80 = false;
|
|
14
|
+
/** Warning flag for 90% context usage (one-time) */
|
|
15
|
+
contextWarningAt90 = false;
|
|
16
|
+
constructor(deps) {
|
|
17
|
+
this.deps = deps;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Emit context change event and add warnings if needed
|
|
21
|
+
* Called after message additions to monitor context usage
|
|
22
|
+
*/
|
|
23
|
+
async emitContextChange() {
|
|
24
|
+
const percent = this.getContextUsagePercent();
|
|
25
|
+
this.deps.emit('contextChange', {
|
|
26
|
+
current: this.deps.getCurrentTokenCount(),
|
|
27
|
+
max: this.deps.getMaxContextSize(),
|
|
28
|
+
percent
|
|
29
|
+
});
|
|
30
|
+
await this.addContextWarningIfNeeded(percent);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Add system warnings based on context usage percentage
|
|
34
|
+
* - 80%: Initial warning (one-time)
|
|
35
|
+
* - 90%: Urgent warning (one-time)
|
|
36
|
+
* - 95%: Critical warning (every time)
|
|
37
|
+
* - 100%: Auto-clear cache
|
|
38
|
+
*/
|
|
39
|
+
async addContextWarningIfNeeded(percent) {
|
|
40
|
+
let warning = null;
|
|
41
|
+
const roundedPercent = Math.round(percent);
|
|
42
|
+
if (percent >= 100) {
|
|
43
|
+
warning = `CONTEXT LIMIT REACHED: You are at ${roundedPercent}% context capacity! Automatically clearing cache to prevent context overflow...`;
|
|
44
|
+
this.deps.messages.push({
|
|
45
|
+
role: 'system',
|
|
46
|
+
content: warning
|
|
47
|
+
});
|
|
48
|
+
await this.deps.clearCache();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (percent >= 95) {
|
|
52
|
+
warning = `CRITICAL CONTEXT WARNING: You are at ${roundedPercent}% context capacity! You MUST immediately save any notes and lessons learned, then run the 'clearCache' tool to reset the conversation context. The conversation will fail if you do not take action now.`;
|
|
53
|
+
}
|
|
54
|
+
else if (percent >= 90 && !this.contextWarningAt90) {
|
|
55
|
+
this.contextWarningAt90 = true;
|
|
56
|
+
warning = `URGENT CONTEXT WARNING: You are at ${roundedPercent}% context capacity! Perform your final tasks or responses and prepare to be reset.`;
|
|
57
|
+
}
|
|
58
|
+
else if (percent >= 80 && !this.contextWarningAt80) {
|
|
59
|
+
this.contextWarningAt80 = true;
|
|
60
|
+
warning = `Context Warning: You are at ${roundedPercent}% context capacity! You are approaching the limit. Be concise and avoid lengthy outputs.`;
|
|
61
|
+
}
|
|
62
|
+
if (warning) {
|
|
63
|
+
this.deps.messages.push({
|
|
64
|
+
role: 'system',
|
|
65
|
+
content: warning
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Calculate current context usage as percentage
|
|
71
|
+
* @returns Percentage of context capacity used (0-100+)
|
|
72
|
+
*/
|
|
73
|
+
getContextUsagePercent() {
|
|
74
|
+
const current = this.deps.getCurrentTokenCount();
|
|
75
|
+
const max = this.deps.getMaxContextSize();
|
|
76
|
+
return (current / max) * 100;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Compact context by keeping only the last N messages
|
|
80
|
+
* Used when context becomes too large for backend to handle
|
|
81
|
+
*
|
|
82
|
+
* @param keepLastMessages Number of recent messages to retain
|
|
83
|
+
* @returns Number of messages removed
|
|
84
|
+
*/
|
|
85
|
+
compactContext(keepLastMessages = 20) {
|
|
86
|
+
if (this.deps.chatHistory.length <= keepLastMessages) {
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
const removedCount = this.deps.chatHistory.length - keepLastMessages;
|
|
90
|
+
const keptMessages = this.deps.chatHistory.slice(-keepLastMessages);
|
|
91
|
+
this.deps.chatHistory.length = 0;
|
|
92
|
+
this.deps.chatHistory.push(...keptMessages);
|
|
93
|
+
this.deps.messages.length = 0;
|
|
94
|
+
const compactionNote = {
|
|
95
|
+
type: 'system',
|
|
96
|
+
content: `Context compacted: removed ${removedCount} older messages, keeping last ${keepLastMessages} messages.`,
|
|
97
|
+
timestamp: new Date()
|
|
98
|
+
};
|
|
99
|
+
this.deps.chatHistory.push(compactionNote);
|
|
100
|
+
for (const entry of this.deps.chatHistory) {
|
|
101
|
+
if (entry.type === 'system') {
|
|
102
|
+
this.deps.messages.push({
|
|
103
|
+
role: 'system',
|
|
104
|
+
content: entry.content
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
else if (entry.type === 'user') {
|
|
108
|
+
this.deps.messages.push({
|
|
109
|
+
role: 'user',
|
|
110
|
+
content: entry.content
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else if (entry.type === 'assistant') {
|
|
114
|
+
this.deps.messages.push({
|
|
115
|
+
role: 'assistant',
|
|
116
|
+
content: entry.content
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
else if (entry.type === 'tool_result') {
|
|
120
|
+
this.deps.messages.push({
|
|
121
|
+
role: 'tool',
|
|
122
|
+
tool_call_id: entry.toolResult.output || '',
|
|
123
|
+
content: JSON.stringify(entry.toolResult)
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return removedCount;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Reset context warning flags
|
|
131
|
+
* Called when cache is cleared to allow warnings to trigger again
|
|
132
|
+
*/
|
|
133
|
+
resetContextWarnings() {
|
|
134
|
+
this.contextWarningAt80 = false;
|
|
135
|
+
this.contextWarningAt90 = false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=context-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-manager.js","sourceRoot":"","sources":["../../src/agent/context-manager.ts"],"names":[],"mappings":"AAwBA;;;;;;;;GAQG;AACH,MAAM,OAAO,cAAc;IAML;IALpB,oDAAoD;IAC5C,kBAAkB,GAAY,KAAK,CAAC;IAC5C,oDAAoD;IAC5C,kBAAkB,GAAY,KAAK,CAAC;IAE5C,YAAoB,IAAgC;QAAhC,SAAI,GAAJ,IAAI,CAA4B;IAAG,CAAC;IAExD;;;OAGG;IACH,KAAK,CAAC,iBAAiB;QACrB,MAAM,OAAO,GAAG,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAE9C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YAC9B,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE;YACzC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE;YAClC,OAAO;SACR,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAChD,CAAC;IAED;;;;;;OAMG;IACK,KAAK,CAAC,yBAAyB,CAAC,OAAe;QACrD,IAAI,OAAO,GAAkB,IAAI,CAAC;QAClC,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAE3C,IAAI,OAAO,IAAI,GAAG,EAAE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ACtC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;oBACtB,IAAI,EAAE,WAAW;oBACjB,OAAO,EAAE,KAAK,CAAC,OAAiB;iBACjC,CAAC,CAAC;YACL,CAAC;iBAAM,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;gBACxC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;oBACtB,IAAI,EAAE,MAAM;oBACZ,YAAY,EAAE,KAAK,CAAC,UAAW,CAAC,MAAM,IAAI,EAAE;oBAC5C,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC;iBAC1C,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,oBAAoB;QAClB,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC;QAChC,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { LLMClient } from "../grok/client.js";
|
|
2
|
+
import { TokenCounter } from "../utils/token-counter.js";
|
|
3
|
+
import { ChatEntry } from "./llm-agent.js";
|
|
4
|
+
/**
|
|
5
|
+
* Dependencies required by HookManager for hook execution and state management
|
|
6
|
+
*/
|
|
7
|
+
export interface HookManagerDependencies {
|
|
8
|
+
/** Get LLM client for API calls */
|
|
9
|
+
getLLMClient(): LLMClient;
|
|
10
|
+
/** Get token counter for model operations */
|
|
11
|
+
getTokenCounter(): TokenCounter;
|
|
12
|
+
/** API key environment variable name */
|
|
13
|
+
apiKeyEnvVar: string;
|
|
14
|
+
/** LLM messages array */
|
|
15
|
+
messages: any[];
|
|
16
|
+
/** Chat history for display */
|
|
17
|
+
chatHistory: ChatEntry[];
|
|
18
|
+
/** Temperature for API calls */
|
|
19
|
+
temperature: number;
|
|
20
|
+
/** Get current token count */
|
|
21
|
+
getCurrentTokenCount(): number;
|
|
22
|
+
/** Get maximum context size */
|
|
23
|
+
getMaxContextSize(): number;
|
|
24
|
+
/** Get current model name */
|
|
25
|
+
getCurrentModel(): string;
|
|
26
|
+
/** Emit events */
|
|
27
|
+
emit(event: string, data: any): void;
|
|
28
|
+
/** Set API key environment variable */
|
|
29
|
+
setApiKeyEnvVar(value: string): void;
|
|
30
|
+
/** Set token counter */
|
|
31
|
+
setTokenCounter(counter: TokenCounter): void;
|
|
32
|
+
/** Set LLM client */
|
|
33
|
+
setLLMClient(client: LLMClient): void;
|
|
34
|
+
/** Set persona values */
|
|
35
|
+
setPersona(persona: string, color: string): void;
|
|
36
|
+
/** Set mood values */
|
|
37
|
+
setMood(mood: string, color: string): void;
|
|
38
|
+
/** Set active task values */
|
|
39
|
+
setActiveTask(task: string, action: string, color: string): void;
|
|
40
|
+
/** Execute a tool by name with parameters (for CALL commands) */
|
|
41
|
+
executeToolByName?(toolName: string, parameters: Record<string, any>): Promise<{
|
|
42
|
+
success: boolean;
|
|
43
|
+
output?: string;
|
|
44
|
+
error?: string;
|
|
45
|
+
hookCommands?: any[];
|
|
46
|
+
}>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Manages hook execution for persona, mood, and task operations
|
|
50
|
+
*
|
|
51
|
+
* Handles:
|
|
52
|
+
* - Persona/mood/task hook execution with approval workflows
|
|
53
|
+
* - Backend and model switching with validation
|
|
54
|
+
* - Hook command processing and environment variable management
|
|
55
|
+
* - API testing for backend/model changes
|
|
56
|
+
* - System message generation for state changes
|
|
57
|
+
*/
|
|
58
|
+
export declare class HookManager {
|
|
59
|
+
private deps;
|
|
60
|
+
constructor(deps: HookManagerDependencies);
|
|
61
|
+
/**
|
|
62
|
+
* Set agent persona with optional hook execution
|
|
63
|
+
* Executes persona hook if configured and processes backend/model changes
|
|
64
|
+
*
|
|
65
|
+
* @param persona New persona name
|
|
66
|
+
* @param color Optional display color
|
|
67
|
+
* @returns Success status and error message if failed
|
|
68
|
+
*/
|
|
69
|
+
setPersona(persona: string, color?: string): Promise<{
|
|
70
|
+
success: boolean;
|
|
71
|
+
error?: string;
|
|
72
|
+
}>;
|
|
73
|
+
/**
|
|
74
|
+
* Set agent mood with optional hook execution
|
|
75
|
+
* Executes mood hook if configured and adds system message to chat
|
|
76
|
+
*
|
|
77
|
+
* @param mood New mood name
|
|
78
|
+
* @param color Optional display color
|
|
79
|
+
* @returns Success status and error message if failed
|
|
80
|
+
*/
|
|
81
|
+
setMood(mood: string, color?: string): Promise<{
|
|
82
|
+
success: boolean;
|
|
83
|
+
error?: string;
|
|
84
|
+
}>;
|
|
85
|
+
/**
|
|
86
|
+
* Start a new active task with approval hook
|
|
87
|
+
* Prevents starting if another task is already active
|
|
88
|
+
*
|
|
89
|
+
* @param activeTask Task name
|
|
90
|
+
* @param action Task action/status
|
|
91
|
+
* @param color Optional display color
|
|
92
|
+
* @returns Success status and error message if failed
|
|
93
|
+
*/
|
|
94
|
+
startActiveTask(activeTask: string, action: string, color?: string): Promise<{
|
|
95
|
+
success: boolean;
|
|
96
|
+
error?: string;
|
|
97
|
+
}>;
|
|
98
|
+
/**
|
|
99
|
+
* Transition active task status with approval hook
|
|
100
|
+
* Requires an active task to be running
|
|
101
|
+
*
|
|
102
|
+
* @param action New task action/status
|
|
103
|
+
* @param color Optional display color
|
|
104
|
+
* @returns Success status and error message if failed
|
|
105
|
+
*/
|
|
106
|
+
transitionActiveTaskStatus(action: string, color?: string): Promise<{
|
|
107
|
+
success: boolean;
|
|
108
|
+
error?: string;
|
|
109
|
+
}>;
|
|
110
|
+
/**
|
|
111
|
+
* Stop active task with approval hook and minimum delay
|
|
112
|
+
* Enforces 3-second minimum delay for task completion
|
|
113
|
+
*
|
|
114
|
+
* @param reason Reason for stopping task
|
|
115
|
+
* @param documentationFile Documentation file path
|
|
116
|
+
* @param color Optional display color
|
|
117
|
+
* @returns Success status and error message if failed
|
|
118
|
+
*/
|
|
119
|
+
stopActiveTask(reason: string, documentationFile: string, color?: string): Promise<{
|
|
120
|
+
success: boolean;
|
|
121
|
+
error?: string;
|
|
122
|
+
}>;
|
|
123
|
+
/**
|
|
124
|
+
* Process hook result commands and apply environment changes
|
|
125
|
+
* Handles backend/model changes, environment variables, and system messages
|
|
126
|
+
*
|
|
127
|
+
* @param hookResult Hook execution result with commands
|
|
128
|
+
* @param envKey Optional environment key to extract transformed value
|
|
129
|
+
* @returns Success status and transformed value if applicable
|
|
130
|
+
*/
|
|
131
|
+
processHookResult(hookResult: {
|
|
132
|
+
commands?: any[];
|
|
133
|
+
}, envKey?: string): Promise<{
|
|
134
|
+
success: boolean;
|
|
135
|
+
transformedValue?: string;
|
|
136
|
+
}>;
|
|
137
|
+
/**
|
|
138
|
+
* Process hook commands with backend/model testing
|
|
139
|
+
* Tests API connectivity before applying changes
|
|
140
|
+
*
|
|
141
|
+
* @param commands Processed hook commands
|
|
142
|
+
* @returns Success status of command processing
|
|
143
|
+
*/
|
|
144
|
+
private processHookCommands;
|
|
145
|
+
/**
|
|
146
|
+
* Render system message with current variable state
|
|
147
|
+
* Updates messages[0] with fresh system prompt from variables
|
|
148
|
+
*/
|
|
149
|
+
private renderSystemMessage;
|
|
150
|
+
/**
|
|
151
|
+
* Test model change by making API call
|
|
152
|
+
* Validates model compatibility before switching
|
|
153
|
+
*
|
|
154
|
+
* @param newModel Model name to test
|
|
155
|
+
* @returns Success status and error message if failed
|
|
156
|
+
*/
|
|
157
|
+
private testModel;
|
|
158
|
+
/**
|
|
159
|
+
* Test backend and model change by making API call
|
|
160
|
+
* Validates backend connectivity and model compatibility
|
|
161
|
+
*
|
|
162
|
+
* @param backend Backend name
|
|
163
|
+
* @param baseUrl API base URL
|
|
164
|
+
* @param apiKeyEnvVar Environment variable for API key
|
|
165
|
+
* @param model Optional model name
|
|
166
|
+
* @returns Success status and error message if failed
|
|
167
|
+
*/
|
|
168
|
+
private testBackendModelChange;
|
|
169
|
+
/**
|
|
170
|
+
* Strip in-progress tool calls from messages for API testing
|
|
171
|
+
* Removes incomplete tool call sequences to avoid API errors
|
|
172
|
+
*
|
|
173
|
+
* @param messages Message array to clean
|
|
174
|
+
* @returns Cleaned message array without incomplete tool calls
|
|
175
|
+
*/
|
|
176
|
+
private stripInProgressToolCalls;
|
|
177
|
+
/**
|
|
178
|
+
* Execute CALL commands asynchronously with recursion depth and duplicate tracking
|
|
179
|
+
* Fire-and-forget execution that processes hooks from called tools
|
|
180
|
+
*
|
|
181
|
+
* @param calls Array of CALL command strings
|
|
182
|
+
* @param context Call context for tracking recursion and duplicates
|
|
183
|
+
*/
|
|
184
|
+
private executeCalls;
|
|
185
|
+
/**
|
|
186
|
+
* Execute a single CALL asynchronously with hook processing
|
|
187
|
+
* Runs tool hooks which may generate more CALL commands
|
|
188
|
+
*
|
|
189
|
+
* @param toolName Tool to execute
|
|
190
|
+
* @param parameters Tool parameters
|
|
191
|
+
* @param context Call context for tracking recursion
|
|
192
|
+
*/
|
|
193
|
+
private executeCallAsync;
|
|
194
|
+
}
|