wave-agent-sdk 0.0.5 → 0.0.7
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/dist/agent.d.ts +3 -6
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +24 -21
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/managers/aiManager.d.ts +4 -2
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +91 -53
- package/dist/managers/backgroundBashManager.d.ts +1 -1
- package/dist/managers/backgroundBashManager.d.ts.map +1 -1
- package/dist/{hooks/manager.d.ts → managers/hookManager.d.ts} +27 -16
- package/dist/managers/hookManager.d.ts.map +1 -0
- package/dist/{hooks/manager.js → managers/hookManager.js} +112 -17
- package/dist/managers/mcpManager.d.ts +1 -1
- package/dist/managers/mcpManager.d.ts.map +1 -1
- package/dist/managers/messageManager.d.ts +20 -15
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +19 -25
- package/dist/managers/skillManager.d.ts +1 -1
- package/dist/managers/skillManager.d.ts.map +1 -1
- package/dist/managers/slashCommandManager.d.ts +1 -1
- package/dist/managers/slashCommandManager.d.ts.map +1 -1
- package/dist/managers/slashCommandManager.js +5 -2
- package/dist/managers/subagentManager.d.ts +7 -12
- package/dist/managers/subagentManager.d.ts.map +1 -1
- package/dist/managers/subagentManager.js +40 -46
- package/dist/managers/toolManager.d.ts +1 -1
- package/dist/managers/toolManager.d.ts.map +1 -1
- package/dist/services/aiService.d.ts +1 -1
- package/dist/services/aiService.d.ts.map +1 -1
- package/dist/services/aiService.js +8 -1
- package/dist/services/hook.d.ts +56 -0
- package/dist/services/hook.d.ts.map +1 -0
- package/dist/services/hook.js +276 -0
- package/dist/services/session.d.ts +1 -1
- package/dist/services/session.d.ts.map +1 -1
- package/dist/services/session.js +5 -4
- package/dist/tools/taskTool.d.ts.map +1 -1
- package/dist/tools/taskTool.js +7 -3
- package/dist/tools/todoWriteTool.d.ts.map +1 -1
- package/dist/tools/todoWriteTool.js +3 -10
- package/dist/types/commands.d.ts +24 -0
- package/dist/types/commands.d.ts.map +1 -0
- package/dist/types/commands.js +5 -0
- package/dist/types/config.d.ts +13 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +5 -0
- package/dist/types/core.d.ts +38 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/{types.js → types/core.js} +4 -13
- package/dist/{hooks/types.d.ts → types/hooks.d.ts} +2 -1
- package/dist/types/hooks.d.ts.map +1 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +21 -0
- package/dist/types/mcp.d.ts +28 -0
- package/dist/types/mcp.d.ts.map +1 -0
- package/dist/types/mcp.js +5 -0
- package/dist/types/messaging.d.ts +80 -0
- package/dist/types/messaging.d.ts.map +1 -0
- package/dist/types/messaging.js +9 -0
- package/dist/types/processes.d.ts +17 -0
- package/dist/types/processes.d.ts.map +1 -0
- package/dist/types/processes.js +5 -0
- package/dist/types/skills.d.ts +78 -0
- package/dist/types/skills.d.ts.map +1 -0
- package/dist/types/skills.js +17 -0
- package/dist/utils/configResolver.d.ts +1 -1
- package/dist/utils/configResolver.d.ts.map +1 -1
- package/dist/utils/configResolver.js +1 -1
- package/dist/utils/configValidator.d.ts +1 -1
- package/dist/utils/configValidator.d.ts.map +1 -1
- package/dist/utils/configValidator.js +1 -1
- package/dist/utils/convertMessagesForAPI.d.ts +1 -1
- package/dist/utils/convertMessagesForAPI.d.ts.map +1 -1
- package/dist/utils/convertMessagesForAPI.js +1 -8
- package/dist/utils/customCommands.d.ts +1 -1
- package/dist/utils/customCommands.d.ts.map +1 -1
- package/dist/{hooks/matcher.d.ts → utils/hookMatcher.d.ts} +2 -7
- package/dist/utils/hookMatcher.d.ts.map +1 -0
- package/dist/utils/markdownParser.d.ts +1 -1
- package/dist/utils/markdownParser.d.ts.map +1 -1
- package/dist/utils/mcpUtils.d.ts +1 -1
- package/dist/utils/mcpUtils.d.ts.map +1 -1
- package/dist/utils/messageOperations.d.ts +14 -21
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +37 -20
- package/dist/utils/skillParser.d.ts +1 -1
- package/dist/utils/skillParser.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/agent.ts +49 -43
- package/src/index.ts +3 -4
- package/src/managers/aiManager.ts +241 -160
- package/src/managers/backgroundBashManager.ts +1 -1
- package/src/{hooks/manager.ts → managers/hookManager.ts} +168 -56
- package/src/managers/mcpManager.ts +1 -1
- package/src/managers/messageManager.ts +44 -44
- package/src/managers/skillManager.ts +1 -1
- package/src/managers/slashCommandManager.ts +10 -7
- package/src/managers/subagentManager.ts +47 -54
- package/src/managers/toolManager.ts +1 -1
- package/src/services/aiService.ts +9 -2
- package/src/services/hook.ts +360 -0
- package/src/services/session.ts +6 -7
- package/src/tools/taskTool.ts +13 -5
- package/src/tools/todoWriteTool.ts +3 -11
- package/src/types/commands.ts +26 -0
- package/src/types/config.ts +14 -0
- package/src/types/core.ts +49 -0
- package/src/{hooks/types.ts → types/hooks.ts} +1 -0
- package/src/types/index.ts +23 -0
- package/src/types/mcp.ts +31 -0
- package/src/types/messaging.ts +102 -0
- package/src/types/processes.ts +18 -0
- package/src/types/skills.ts +91 -0
- package/src/utils/configResolver.ts +1 -1
- package/src/utils/configValidator.ts +5 -1
- package/src/utils/convertMessagesForAPI.ts +2 -10
- package/src/utils/customCommands.ts +1 -1
- package/src/{hooks/matcher.ts → utils/hookMatcher.ts} +1 -12
- package/src/utils/markdownParser.ts +1 -1
- package/src/utils/mcpUtils.ts +1 -1
- package/src/utils/messageOperations.ts +56 -42
- package/src/utils/skillParser.ts +1 -1
- package/dist/hooks/executor.d.ts +0 -56
- package/dist/hooks/executor.d.ts.map +0 -1
- package/dist/hooks/executor.js +0 -312
- package/dist/hooks/index.d.ts +0 -17
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -14
- package/dist/hooks/manager.d.ts.map +0 -1
- package/dist/hooks/matcher.d.ts.map +0 -1
- package/dist/hooks/settings.d.ts +0 -46
- package/dist/hooks/settings.d.ts.map +0 -1
- package/dist/hooks/settings.js +0 -100
- package/dist/hooks/types.d.ts.map +0 -1
- package/dist/types.d.ts +0 -288
- package/dist/types.d.ts.map +0 -1
- package/src/hooks/executor.ts +0 -440
- package/src/hooks/index.ts +0 -52
- package/src/hooks/settings.ts +0 -129
- package/src/types.ts +0 -357
- /package/dist/{hooks/types.js → types/hooks.js} +0 -0
- /package/dist/{hooks/matcher.js → utils/hookMatcher.js} +0 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message and communication block types
|
|
3
|
+
* Dependencies: Core (Usage)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Usage } from "./core.js";
|
|
7
|
+
|
|
8
|
+
export enum MessageSource {
|
|
9
|
+
USER = "user",
|
|
10
|
+
HOOK = "hook",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Message {
|
|
14
|
+
role: "user" | "assistant";
|
|
15
|
+
blocks: MessageBlock[];
|
|
16
|
+
usage?: Usage; // Usage data for this message's AI operation (assistant messages only)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type MessageBlock =
|
|
20
|
+
| TextBlock
|
|
21
|
+
| ErrorBlock
|
|
22
|
+
| ToolBlock
|
|
23
|
+
| ImageBlock
|
|
24
|
+
| DiffBlock
|
|
25
|
+
| CommandOutputBlock
|
|
26
|
+
| CompressBlock
|
|
27
|
+
| MemoryBlock
|
|
28
|
+
| SubagentBlock;
|
|
29
|
+
|
|
30
|
+
export interface TextBlock {
|
|
31
|
+
type: "text";
|
|
32
|
+
content: string;
|
|
33
|
+
customCommandContent?: string;
|
|
34
|
+
source?: MessageSource;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface ErrorBlock {
|
|
38
|
+
type: "error";
|
|
39
|
+
content: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ToolBlock {
|
|
43
|
+
type: "tool";
|
|
44
|
+
parameters?: string;
|
|
45
|
+
result?: string;
|
|
46
|
+
shortResult?: string; // Add shortResult field
|
|
47
|
+
images?: Array<{
|
|
48
|
+
// Add image data support
|
|
49
|
+
data: string; // Base64 encoded image data
|
|
50
|
+
mediaType?: string; // Media type of the image
|
|
51
|
+
}>;
|
|
52
|
+
id?: string;
|
|
53
|
+
name?: string;
|
|
54
|
+
isRunning?: boolean; // Mark if tool is actually executing
|
|
55
|
+
success?: boolean;
|
|
56
|
+
error?: string | Error;
|
|
57
|
+
compactParams?: string; // Compact parameter display
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface ImageBlock {
|
|
61
|
+
type: "image";
|
|
62
|
+
imageUrls?: string[];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface DiffBlock {
|
|
66
|
+
type: "diff";
|
|
67
|
+
path: string;
|
|
68
|
+
diffResult: Array<{
|
|
69
|
+
value: string;
|
|
70
|
+
added?: boolean;
|
|
71
|
+
removed?: boolean;
|
|
72
|
+
}>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface CommandOutputBlock {
|
|
76
|
+
type: "command_output";
|
|
77
|
+
command: string;
|
|
78
|
+
output: string;
|
|
79
|
+
isRunning: boolean;
|
|
80
|
+
exitCode: number | null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface CompressBlock {
|
|
84
|
+
type: "compress";
|
|
85
|
+
content: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface MemoryBlock {
|
|
89
|
+
type: "memory";
|
|
90
|
+
content: string;
|
|
91
|
+
isSuccess: boolean;
|
|
92
|
+
memoryType?: "project" | "user"; // Memory type
|
|
93
|
+
storagePath?: string; // Storage path text
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface SubagentBlock {
|
|
97
|
+
type: "subagent";
|
|
98
|
+
subagentId: string;
|
|
99
|
+
subagentName: string;
|
|
100
|
+
status: "active" | "completed" | "error" | "aborted";
|
|
101
|
+
messages: Message[];
|
|
102
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Background process and shell management types
|
|
3
|
+
* Dependencies: None
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ChildProcess } from "child_process";
|
|
7
|
+
|
|
8
|
+
export interface BackgroundShell {
|
|
9
|
+
id: string;
|
|
10
|
+
process: ChildProcess;
|
|
11
|
+
command: string;
|
|
12
|
+
startTime: number;
|
|
13
|
+
status: "running" | "completed" | "killed";
|
|
14
|
+
stdout: string;
|
|
15
|
+
stderr: string;
|
|
16
|
+
exitCode?: number;
|
|
17
|
+
runtime?: number;
|
|
18
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill system types and constants
|
|
3
|
+
* Dependencies: Core (Logger)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Logger } from "./core.js";
|
|
7
|
+
|
|
8
|
+
export interface SkillMetadata {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
type: "personal" | "project";
|
|
12
|
+
skillPath: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface Skill extends SkillMetadata {
|
|
16
|
+
content: string;
|
|
17
|
+
frontmatter: SkillFrontmatter;
|
|
18
|
+
isValid: boolean;
|
|
19
|
+
errors: string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface SkillFrontmatter {
|
|
23
|
+
name: string;
|
|
24
|
+
description: string;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SkillCollection {
|
|
29
|
+
type: "personal" | "project";
|
|
30
|
+
basePath: string;
|
|
31
|
+
skills: Map<string, SkillMetadata>;
|
|
32
|
+
errors: SkillError[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SkillError {
|
|
36
|
+
skillPath: string;
|
|
37
|
+
message: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface SkillValidationResult {
|
|
41
|
+
isValid: boolean;
|
|
42
|
+
skill?: Skill;
|
|
43
|
+
errors: string[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface SkillDiscoveryResult {
|
|
47
|
+
personalSkills: Map<string, SkillMetadata>;
|
|
48
|
+
projectSkills: Map<string, SkillMetadata>;
|
|
49
|
+
errors: SkillError[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface SkillInvocationContext {
|
|
53
|
+
skillName: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface SkillToolArgs {
|
|
57
|
+
skill_name: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface SkillManagerOptions {
|
|
61
|
+
personalSkillsPath?: string;
|
|
62
|
+
scanTimeout?: number;
|
|
63
|
+
logger?: Logger;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface ParsedSkillFile {
|
|
67
|
+
frontmatter: SkillFrontmatter;
|
|
68
|
+
content: string;
|
|
69
|
+
skillMetadata: SkillMetadata;
|
|
70
|
+
validationErrors: string[];
|
|
71
|
+
isValid: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface SkillParseOptions {
|
|
75
|
+
validateMetadata?: boolean;
|
|
76
|
+
basePath?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const SKILL_DEFAULTS = {
|
|
80
|
+
PERSONAL_SKILLS_DIR: ".wave/skills",
|
|
81
|
+
PROJECT_SKILLS_DIR: ".wave/skills",
|
|
82
|
+
SKILL_FILE_NAME: "SKILL.md",
|
|
83
|
+
MAX_NAME_LENGTH: 64,
|
|
84
|
+
MAX_DESCRIPTION_LENGTH: 1024,
|
|
85
|
+
MIN_DESCRIPTION_LENGTH: 1,
|
|
86
|
+
NAME_PATTERN: /^[a-z0-9-]+$/,
|
|
87
|
+
MAX_METADATA_CACHE: 1000,
|
|
88
|
+
MAX_CONTENT_CACHE: 100,
|
|
89
|
+
SCAN_TIMEOUT: 5000,
|
|
90
|
+
LOAD_TIMEOUT: 2000,
|
|
91
|
+
} as const;
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
* Validates configuration values for correctness and security
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
GatewayConfig,
|
|
8
|
+
ConfigurationError,
|
|
9
|
+
CONFIG_ERRORS,
|
|
10
|
+
} from "../types/index.js";
|
|
7
11
|
|
|
8
12
|
export class ConfigValidator {
|
|
9
13
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Message } from "../types.js";
|
|
1
|
+
import type { Message } from "../types/index.js";
|
|
2
2
|
import { convertImageToBase64 } from "./messageOperations.js";
|
|
3
3
|
import { ChatCompletionMessageToolCall } from "openai/resources";
|
|
4
4
|
import { stripAnsiColors } from "./stringUtils.js";
|
|
@@ -176,15 +176,7 @@ export function convertMessagesForAPI(
|
|
|
176
176
|
if (block.type === "text" && block.content) {
|
|
177
177
|
contentParts.push({
|
|
178
178
|
type: "text",
|
|
179
|
-
text: block.content,
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Handle custom command blocks - pass full content as text to AI
|
|
184
|
-
if (block.type === "custom_command" && block.content) {
|
|
185
|
-
contentParts.push({
|
|
186
|
-
type: "text",
|
|
187
|
-
text: block.content,
|
|
179
|
+
text: block.customCommandContent || block.content,
|
|
188
180
|
});
|
|
189
181
|
}
|
|
190
182
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, readdirSync } from "fs";
|
|
2
2
|
import { join, extname, basename } from "path";
|
|
3
3
|
import { homedir } from "os";
|
|
4
|
-
import type { CustomSlashCommand } from "../types.js";
|
|
4
|
+
import type { CustomSlashCommand } from "../types/index.js";
|
|
5
5
|
import { parseMarkdownFile } from "./markdownParser.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -7,18 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import { minimatch } from "minimatch";
|
|
9
9
|
|
|
10
|
-
export
|
|
11
|
-
// Test if pattern matches tool name
|
|
12
|
-
matches(pattern: string, toolName: string): boolean;
|
|
13
|
-
|
|
14
|
-
// Validate pattern syntax
|
|
15
|
-
isValidPattern(pattern: string): boolean;
|
|
16
|
-
|
|
17
|
-
// Get pattern type for optimization
|
|
18
|
-
getPatternType(pattern: string): "exact" | "glob" | "regex" | "alternatives";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class HookMatcher implements IHookMatcher {
|
|
10
|
+
export class HookMatcher {
|
|
22
11
|
/**
|
|
23
12
|
* Test if pattern matches tool name
|
|
24
13
|
* Supports multiple matching strategies:
|
package/src/utils/mcpUtils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChatCompletionFunctionTool } from "openai/resources.js";
|
|
2
2
|
import type { ToolPlugin, ToolResult, ToolContext } from "../tools/types.js";
|
|
3
|
-
import type { McpTool, McpServerStatus } from "../types.js";
|
|
3
|
+
import type { McpTool, McpServerStatus } from "../types/index.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Convert MCP tool to OpenAI function tool format
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { Message, Usage } from "../types.js";
|
|
1
|
+
import type { Message, Usage, MessageSource } from "../types/index.js";
|
|
2
2
|
import { readFileSync } from "fs";
|
|
3
3
|
import { extname } from "path";
|
|
4
4
|
import { ChatCompletionMessageFunctionToolCall } from "openai/resources.js";
|
|
5
5
|
|
|
6
|
-
//
|
|
7
|
-
export interface
|
|
8
|
-
messages: Message[];
|
|
6
|
+
// Base user message parameters interface
|
|
7
|
+
export interface UserMessageParams {
|
|
9
8
|
content: string;
|
|
10
9
|
images?: Array<{ path: string; mimeType: string }>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
customCommandContent?: string;
|
|
11
|
+
source?: MessageSource;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Parameter interfaces for message operations
|
|
15
|
+
export interface AddUserMessageParams extends UserMessageParams {
|
|
16
|
+
messages: Message[];
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export interface UpdateToolBlockParams {
|
|
@@ -31,17 +31,10 @@ export interface UpdateToolBlockParams {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// Agent specific interfaces (without messages parameter)
|
|
34
|
-
export
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
success?: boolean;
|
|
39
|
-
error?: string;
|
|
40
|
-
isRunning?: boolean;
|
|
41
|
-
name?: string;
|
|
42
|
-
shortResult?: string;
|
|
43
|
-
compactParams?: string;
|
|
44
|
-
}
|
|
34
|
+
export type AgentToolBlockUpdateParams = Omit<
|
|
35
|
+
UpdateToolBlockParams,
|
|
36
|
+
"messages"
|
|
37
|
+
>;
|
|
45
38
|
|
|
46
39
|
export interface AddDiffBlockParams {
|
|
47
40
|
messages: Message[];
|
|
@@ -145,16 +138,19 @@ export const addUserMessageToMessages = ({
|
|
|
145
138
|
messages,
|
|
146
139
|
content,
|
|
147
140
|
images,
|
|
148
|
-
|
|
141
|
+
customCommandContent,
|
|
142
|
+
source,
|
|
149
143
|
}: AddUserMessageParams): Message[] => {
|
|
150
144
|
const blocks: Message["blocks"] = [];
|
|
151
145
|
|
|
152
|
-
//
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
146
|
+
// Create text block with optional customCommandContent and source
|
|
147
|
+
const textBlock = {
|
|
148
|
+
type: "text" as const,
|
|
149
|
+
content,
|
|
150
|
+
...(customCommandContent && { customCommandContent }),
|
|
151
|
+
...(source && { source }),
|
|
152
|
+
};
|
|
153
|
+
blocks.push(textBlock);
|
|
158
154
|
|
|
159
155
|
// If there are images, add image block
|
|
160
156
|
if (images && images.length > 0) {
|
|
@@ -294,24 +290,23 @@ export const addErrorBlockToMessage = ({
|
|
|
294
290
|
error,
|
|
295
291
|
}: AddErrorBlockParams): Message[] => {
|
|
296
292
|
const newMessages = [...messages];
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
293
|
+
|
|
294
|
+
// Check if the last message is an assistant message
|
|
295
|
+
const lastMessage = newMessages[newMessages.length - 1];
|
|
296
|
+
if (lastMessage && lastMessage.role === "assistant") {
|
|
297
|
+
// Create a new message object with the error block added
|
|
298
|
+
newMessages[newMessages.length - 1] = {
|
|
299
|
+
...lastMessage,
|
|
300
|
+
blocks: [
|
|
301
|
+
...lastMessage.blocks,
|
|
303
302
|
{
|
|
304
303
|
type: "error",
|
|
305
304
|
content: error,
|
|
306
305
|
},
|
|
307
|
-
]
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
// If no assistant message found, create a new assistant message with only error block
|
|
314
|
-
if (!assistantMessageFound) {
|
|
306
|
+
],
|
|
307
|
+
};
|
|
308
|
+
} else {
|
|
309
|
+
// If the last message is not an assistant message, create a new assistant message
|
|
315
310
|
newMessages.push({
|
|
316
311
|
role: "assistant",
|
|
317
312
|
blocks: [
|
|
@@ -586,3 +581,22 @@ export const updateSubagentBlockInMessage = (
|
|
|
586
581
|
|
|
587
582
|
return newMessages;
|
|
588
583
|
};
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Removes the last user message from the messages array
|
|
587
|
+
* Used for hook error handling when the user prompt needs to be erased
|
|
588
|
+
*/
|
|
589
|
+
export const removeLastUserMessage = (messages: Message[]): Message[] => {
|
|
590
|
+
const newMessages = [...messages];
|
|
591
|
+
|
|
592
|
+
// Find the index of the last user message
|
|
593
|
+
for (let i = newMessages.length - 1; i >= 0; i--) {
|
|
594
|
+
if (newMessages[i].role === "user") {
|
|
595
|
+
// Remove the user message at index i
|
|
596
|
+
newMessages.splice(i, 1);
|
|
597
|
+
break;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
return newMessages;
|
|
602
|
+
};
|
package/src/utils/skillParser.ts
CHANGED
package/dist/hooks/executor.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook Command Executor
|
|
3
|
-
*
|
|
4
|
-
* Handles the execution of hook commands in isolated processes with proper
|
|
5
|
-
* timeout handling, environment variable injection, and cross-platform support.
|
|
6
|
-
*/
|
|
7
|
-
import { type HookExecutionContext, type HookExecutionResult, type HookExecutionOptions, type ExtendedHookExecutionContext } from "./types.js";
|
|
8
|
-
import type { Logger } from "../types.js";
|
|
9
|
-
export interface IHookExecutor {
|
|
10
|
-
executeCommand(command: string, context: HookExecutionContext | ExtendedHookExecutionContext, options?: HookExecutionOptions): Promise<HookExecutionResult>;
|
|
11
|
-
executeCommands(commands: string[], context: HookExecutionContext | ExtendedHookExecutionContext, options?: HookExecutionOptions): Promise<HookExecutionResult[]>;
|
|
12
|
-
isCommandSafe(command: string): boolean;
|
|
13
|
-
}
|
|
14
|
-
export declare class HookExecutor implements IHookExecutor {
|
|
15
|
-
private readonly defaultTimeout;
|
|
16
|
-
private readonly maxTimeout;
|
|
17
|
-
private readonly logger?;
|
|
18
|
-
private readonly skipExecution;
|
|
19
|
-
constructor(logger?: Logger, options?: {
|
|
20
|
-
skipExecution?: boolean;
|
|
21
|
-
});
|
|
22
|
-
/**
|
|
23
|
-
* Execute a single hook command in an isolated process
|
|
24
|
-
*/
|
|
25
|
-
executeCommand(command: string, context: HookExecutionContext | ExtendedHookExecutionContext, options?: HookExecutionOptions): Promise<HookExecutionResult>;
|
|
26
|
-
/**
|
|
27
|
-
* Execute multiple commands in sequence
|
|
28
|
-
* Stops on first failure unless configured otherwise
|
|
29
|
-
*/
|
|
30
|
-
executeCommands(commands: string[], context: HookExecutionContext | ExtendedHookExecutionContext, options?: HookExecutionOptions): Promise<HookExecutionResult[]>;
|
|
31
|
-
/**
|
|
32
|
-
* Validate command safety to prevent injection attacks
|
|
33
|
-
*/
|
|
34
|
-
isCommandSafe(command: string): boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Build environment variables for hook execution
|
|
37
|
-
*/
|
|
38
|
-
private buildEnvironment;
|
|
39
|
-
/**
|
|
40
|
-
* Resolve environment variables in command string
|
|
41
|
-
*/
|
|
42
|
-
private resolveEnvironmentVariables;
|
|
43
|
-
/**
|
|
44
|
-
* Get process statistics for monitoring
|
|
45
|
-
*/
|
|
46
|
-
getExecutionStats(): {
|
|
47
|
-
platform: NodeJS.Platform;
|
|
48
|
-
defaultTimeout: number;
|
|
49
|
-
maxTimeout: number;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Test if the executor can run commands on this platform
|
|
53
|
-
*/
|
|
54
|
-
isSupported(): boolean;
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/hooks/executor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,4BAA4B,EAGlC,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAyC1C,MAAM,WAAW,aAAa;IAE5B,cAAc,CACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,oBAAoB,GAAG,4BAA4B,EAC5D,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAGhC,eAAe,CACb,QAAQ,EAAE,MAAM,EAAE,EAClB,OAAO,EAAE,oBAAoB,GAAG,4BAA4B,EAC5D,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC;IAGlC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;CACzC;AAED,qBAAa,YAAa,YAAW,aAAa;IAChD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAU;IACrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAU;gBAE5B,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,OAAO,CAAA;KAAE;IASlE;;OAEG;IACG,cAAc,CAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,oBAAoB,GAAG,4BAA4B,EAC5D,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,mBAAmB,CAAC;IAmM/B;;;OAGG;IACG,eAAe,CACnB,QAAQ,EAAE,MAAM,EAAE,EAClB,OAAO,EAAE,oBAAoB,GAAG,4BAA4B,EAC5D,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAmDjC;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAwBvC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAOxB;;OAEG;IACH,OAAO,CAAC,2BAA2B;IAqBnC;;OAEG;IACH,iBAAiB,IAAI;QACnB,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;QAC1B,cAAc,EAAE,MAAM,CAAC;QACvB,UAAU,EAAE,MAAM,CAAC;KACpB;IAQD;;OAEG;IACH,WAAW,IAAI,OAAO;CAQvB"}
|