wave-agent-sdk 0.0.2 → 0.0.4

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.
Files changed (66) hide show
  1. package/dist/agent.d.ts +5 -1
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +48 -4
  4. package/dist/index.d.ts +0 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +0 -1
  7. package/dist/managers/aiManager.d.ts.map +1 -1
  8. package/dist/managers/aiManager.js +4 -7
  9. package/dist/managers/messageManager.d.ts +8 -0
  10. package/dist/managers/messageManager.d.ts.map +1 -1
  11. package/dist/managers/messageManager.js +26 -2
  12. package/dist/managers/skillManager.d.ts +4 -5
  13. package/dist/managers/skillManager.d.ts.map +1 -1
  14. package/dist/managers/skillManager.js +6 -82
  15. package/dist/managers/subagentManager.d.ts +96 -0
  16. package/dist/managers/subagentManager.d.ts.map +1 -0
  17. package/dist/managers/subagentManager.js +261 -0
  18. package/dist/managers/toolManager.d.ts +33 -1
  19. package/dist/managers/toolManager.d.ts.map +1 -1
  20. package/dist/managers/toolManager.js +43 -5
  21. package/dist/services/aiService.d.ts.map +1 -1
  22. package/dist/services/aiService.js +40 -14
  23. package/dist/services/memory.js +2 -2
  24. package/dist/tools/grepTool.d.ts.map +1 -1
  25. package/dist/tools/grepTool.js +8 -6
  26. package/dist/tools/readTool.d.ts.map +1 -1
  27. package/dist/tools/readTool.js +36 -6
  28. package/dist/tools/skillTool.d.ts +8 -0
  29. package/dist/tools/skillTool.d.ts.map +1 -0
  30. package/dist/tools/skillTool.js +72 -0
  31. package/dist/tools/taskTool.d.ts +8 -0
  32. package/dist/tools/taskTool.d.ts.map +1 -0
  33. package/dist/tools/taskTool.js +109 -0
  34. package/dist/tools/todoWriteTool.d.ts +6 -0
  35. package/dist/tools/todoWriteTool.d.ts.map +1 -0
  36. package/dist/tools/todoWriteTool.js +203 -0
  37. package/dist/types.d.ts +8 -1
  38. package/dist/types.d.ts.map +1 -1
  39. package/dist/utils/fileFormat.d.ts +17 -0
  40. package/dist/utils/fileFormat.d.ts.map +1 -0
  41. package/dist/utils/fileFormat.js +35 -0
  42. package/dist/utils/messageOperations.d.ts +18 -0
  43. package/dist/utils/messageOperations.d.ts.map +1 -1
  44. package/dist/utils/messageOperations.js +43 -0
  45. package/dist/utils/subagentParser.d.ts +19 -0
  46. package/dist/utils/subagentParser.d.ts.map +1 -0
  47. package/dist/utils/subagentParser.js +159 -0
  48. package/package.json +1 -1
  49. package/src/agent.ts +55 -5
  50. package/src/index.ts +0 -1
  51. package/src/managers/aiManager.ts +5 -8
  52. package/src/managers/messageManager.ts +55 -1
  53. package/src/managers/skillManager.ts +7 -96
  54. package/src/managers/subagentManager.ts +368 -0
  55. package/src/managers/toolManager.ts +50 -5
  56. package/src/services/aiService.ts +44 -16
  57. package/src/services/memory.ts +2 -2
  58. package/src/tools/grepTool.ts +9 -6
  59. package/src/tools/readTool.ts +40 -6
  60. package/src/tools/skillTool.ts +82 -0
  61. package/src/tools/taskTool.ts +128 -0
  62. package/src/tools/todoWriteTool.ts +232 -0
  63. package/src/types.ts +10 -1
  64. package/src/utils/fileFormat.ts +40 -0
  65. package/src/utils/messageOperations.ts +80 -0
  66. package/src/utils/subagentParser.ts +223 -0
@@ -0,0 +1,82 @@
1
+ import type { ToolPlugin, ToolResult } from "./types.js";
2
+ import type { SkillManager } from "../managers/skillManager.js";
3
+
4
+ /**
5
+ * Create a skill tool plugin that uses the provided SkillManager
6
+ * Note: SkillManager should be initialized before calling this function
7
+ */
8
+ export function createSkillTool(skillManager: SkillManager): ToolPlugin {
9
+ const getToolDescription = (): string => {
10
+ const availableSkills = skillManager.getAvailableSkills();
11
+
12
+ if (availableSkills.length === 0) {
13
+ return "Invoke a Wave skill by name. Skills are user-defined automation templates that can be personal or project-specific. No skills are currently available.";
14
+ }
15
+
16
+ const skillList = availableSkills
17
+ .map(
18
+ (skill) => `• **${skill.name}** (${skill.type}): ${skill.description}`,
19
+ )
20
+ .join("\n");
21
+
22
+ return `Invoke a Wave skill by name. Skills are user-defined automation templates that can be personal or project-specific.\n\nAvailable skills:\n${skillList}`;
23
+ };
24
+
25
+ return {
26
+ name: "skill",
27
+ config: {
28
+ type: "function",
29
+ function: {
30
+ name: "skill",
31
+ description: getToolDescription(),
32
+ parameters: {
33
+ type: "object",
34
+ properties: {
35
+ skill_name: {
36
+ type: "string",
37
+ description: "Name of the skill to invoke",
38
+ enum: skillManager
39
+ .getAvailableSkills()
40
+ .map((skill) => skill.name),
41
+ },
42
+ },
43
+ required: ["skill_name"],
44
+ },
45
+ },
46
+ },
47
+ execute: async (args: Record<string, unknown>): Promise<ToolResult> => {
48
+ try {
49
+ // Validate arguments
50
+ const skillName = args.skill_name as string;
51
+ if (!skillName || typeof skillName !== "string") {
52
+ return {
53
+ success: false,
54
+ content: "",
55
+ error: "skill_name parameter is required and must be a string",
56
+ };
57
+ }
58
+
59
+ // Execute the skill
60
+ const result = await skillManager.executeSkill({
61
+ skill_name: skillName,
62
+ });
63
+
64
+ return {
65
+ success: true,
66
+ content: result.content,
67
+ shortResult: `Invoked skill: ${skillName}`,
68
+ };
69
+ } catch (error) {
70
+ return {
71
+ success: false,
72
+ content: "",
73
+ error: error instanceof Error ? error.message : String(error),
74
+ };
75
+ }
76
+ },
77
+ formatCompactParams: (params: Record<string, unknown>) => {
78
+ const skillName = params.skill_name as string;
79
+ return skillName || "unknown-skill";
80
+ },
81
+ };
82
+ }
@@ -0,0 +1,128 @@
1
+ import type { ToolPlugin, ToolResult } from "./types.js";
2
+ import type { SubagentManager } from "../managers/subagentManager.js";
3
+
4
+ /**
5
+ * Create a task tool plugin that uses the provided SubagentManager
6
+ * Note: SubagentManager should be initialized before calling this function
7
+ */
8
+ export function createTaskTool(subagentManager: SubagentManager): ToolPlugin {
9
+ // Get available subagents from the initialized subagent manager
10
+ const availableSubagents = subagentManager.getConfigurations();
11
+ const subagentList = availableSubagents
12
+ .map((config) => `- ${config.name}: ${config.description}`)
13
+ .join("\n");
14
+
15
+ const description = `Delegate a task to a specialized subagent. Use this when you need specialized expertise or want to break down complex work into focused subtasks.
16
+
17
+ Available subagents:
18
+ ${subagentList || "No subagents configured"}`;
19
+
20
+ return {
21
+ name: "Task",
22
+ config: {
23
+ type: "function",
24
+ function: {
25
+ name: "Task",
26
+ description,
27
+ parameters: {
28
+ type: "object",
29
+ properties: {
30
+ description: {
31
+ type: "string",
32
+ description:
33
+ "A clear, concise description of what needs to be accomplished",
34
+ },
35
+ prompt: {
36
+ type: "string",
37
+ description:
38
+ "The specific instructions or prompt to send to the subagent",
39
+ },
40
+ subagent_type: {
41
+ type: "string",
42
+ description: `The type or name of subagent to use. Available options: ${availableSubagents.map((c) => c.name).join(", ") || "none"}`,
43
+ },
44
+ },
45
+ required: ["description", "prompt", "subagent_type"],
46
+ },
47
+ },
48
+ },
49
+
50
+ execute: async (args: Record<string, unknown>): Promise<ToolResult> => {
51
+ // Input validation
52
+ const description = args.description as string;
53
+ const prompt = args.prompt as string;
54
+ const subagent_type = args.subagent_type as string;
55
+
56
+ if (!description || typeof description !== "string") {
57
+ return {
58
+ success: false,
59
+ content: "",
60
+ error: "description parameter is required and must be a string",
61
+ shortResult: "Task delegation failed",
62
+ };
63
+ }
64
+
65
+ if (!prompt || typeof prompt !== "string") {
66
+ return {
67
+ success: false,
68
+ content: "",
69
+ error: "prompt parameter is required and must be a string",
70
+ shortResult: "Task delegation failed",
71
+ };
72
+ }
73
+
74
+ if (!subagent_type || typeof subagent_type !== "string") {
75
+ return {
76
+ success: false,
77
+ content: "",
78
+ error: "subagent_type parameter is required and must be a string",
79
+ shortResult: "Task delegation failed",
80
+ };
81
+ }
82
+
83
+ try {
84
+ // Subagent selection logic with explicit name matching only
85
+ const configuration = await subagentManager.findSubagent(subagent_type);
86
+
87
+ if (!configuration) {
88
+ // Error handling for nonexistent subagents with available subagents listing
89
+ const allConfigs = subagentManager.getConfigurations();
90
+ const availableNames = allConfigs.map((c) => c.name).join(", ");
91
+
92
+ return {
93
+ success: false,
94
+ content: "",
95
+ error: `No subagent found matching "${subagent_type}". Available subagents: ${availableNames || "none"}`,
96
+ shortResult: "Subagent not found",
97
+ };
98
+ }
99
+
100
+ // Create subagent instance and execute task
101
+ const instance = await subagentManager.createInstance(
102
+ configuration,
103
+ description,
104
+ );
105
+ const response = await subagentManager.executeTask(instance, prompt);
106
+
107
+ return {
108
+ success: true,
109
+ content: response,
110
+ shortResult: `Task completed by ${configuration.name}`,
111
+ };
112
+ } catch (error) {
113
+ return {
114
+ success: false,
115
+ content: "",
116
+ error: `Task delegation failed: ${error instanceof Error ? error.message : String(error)}`,
117
+ shortResult: "Delegation error",
118
+ };
119
+ }
120
+ },
121
+
122
+ formatCompactParams: (params: Record<string, unknown>) => {
123
+ const subagent_type = params.subagent_type as string;
124
+ const description = params.description as string;
125
+ return `${subagent_type || "unknown"}: ${description || "no description"}`;
126
+ },
127
+ };
128
+ }
@@ -0,0 +1,232 @@
1
+ import type { ToolPlugin, ToolResult } from "./types.js";
2
+
3
+ interface TodoItem {
4
+ content: string;
5
+ status: "pending" | "in_progress" | "completed";
6
+ id: string;
7
+ }
8
+
9
+ /**
10
+ * TodoWrite tool for creating and managing structured task lists
11
+ */
12
+ export const todoWriteTool: ToolPlugin = {
13
+ name: "TodoWrite",
14
+ config: {
15
+ type: "function",
16
+ function: {
17
+ name: "TodoWrite",
18
+ description: `Use this tool to create and manage a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
19
+ It also helps the user understand the progress of the task and overall progress of their requests.
20
+
21
+ ## When to Use This Tool
22
+ Use this tool proactively in these scenarios:
23
+
24
+ 1. Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
25
+ 2. Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
26
+ 3. User explicitly requests todo list - When the user directly asks you to use the todo list
27
+ 4. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
28
+ 5. After receiving new instructions - Immediately capture user requirements as todos
29
+ 6. When you start working on a task - Mark it as in_progress BEFORE beginning work. Ideally you should only have one todo as in_progress at a time
30
+ 7. After completing a task - Mark it as completed and add any new follow-up tasks discovered during implementation
31
+
32
+ ## When NOT to Use This Tool
33
+
34
+ Skip using this tool when:
35
+ 1. There is only a single, straightforward task
36
+ 2. The task is trivial and tracking it provides no organizational benefit
37
+ 3. The task can be completed in less than 3 trivial steps
38
+ 4. The task is purely conversational or informational
39
+
40
+ NOTE that you should not use this tool if there is only one trivial task to do. In this case you are better off just doing the task directly.
41
+
42
+ ## Task States and Management
43
+
44
+ 1. **Task States**: Use these states to track progress:
45
+ - pending: Task not yet started
46
+ - in_progress: Currently working on (limit to ONE task at a time)
47
+ - completed: Task finished successfully
48
+
49
+ 2. **Task Management**:
50
+ - Update task status in real-time as you work
51
+ - Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
52
+ - Only have ONE task in_progress at any time
53
+ - Complete current tasks before starting new ones
54
+ - Remove tasks that are no longer relevant from the list entirely
55
+
56
+ 3. **Task Completion Requirements**:
57
+ - ONLY mark a task as completed when you have FULLY accomplished it
58
+ - If you encounter errors, blockers, or cannot finish, keep the task as in_progress
59
+ - When blocked, create a new task describing what needs to be resolved
60
+ - Never mark a task as completed if:
61
+ - Tests are failing
62
+ - Implementation is partial
63
+ - You encountered unresolved errors
64
+ - You couldn't find necessary files or dependencies
65
+
66
+ 4. **Task Breakdown**:
67
+ - Create specific, actionable items
68
+ - Break complex tasks into smaller, manageable steps
69
+ - Use clear, descriptive task names
70
+
71
+ When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.`,
72
+ parameters: {
73
+ type: "object",
74
+ properties: {
75
+ todos: {
76
+ type: "array",
77
+ items: {
78
+ type: "object",
79
+ properties: {
80
+ content: {
81
+ type: "string",
82
+ minLength: 1,
83
+ },
84
+ status: {
85
+ type: "string",
86
+ enum: ["pending", "in_progress", "completed"],
87
+ },
88
+ id: {
89
+ type: "string",
90
+ },
91
+ },
92
+ required: ["content", "status", "id"],
93
+ additionalProperties: false,
94
+ },
95
+ description: "The updated todo list",
96
+ },
97
+ },
98
+ required: ["todos"],
99
+ additionalProperties: false,
100
+ },
101
+ },
102
+ },
103
+
104
+ execute: async (args: Record<string, unknown>): Promise<ToolResult> => {
105
+ try {
106
+ // Validate arguments
107
+ const { todos } = args as { todos?: TodoItem[] };
108
+
109
+ if (!todos || !Array.isArray(todos)) {
110
+ return {
111
+ success: false,
112
+ content: "",
113
+ error: "todos parameter must be an array",
114
+ shortResult: "Invalid todos format",
115
+ };
116
+ }
117
+
118
+ // Validate each task item
119
+ for (const [index, todo] of todos.entries()) {
120
+ if (!todo || typeof todo !== "object") {
121
+ return {
122
+ success: false,
123
+ content: "",
124
+ error: `Todo item at index ${index} must be an object`,
125
+ shortResult: "Invalid todo item",
126
+ };
127
+ }
128
+
129
+ if (
130
+ !todo.content ||
131
+ typeof todo.content !== "string" ||
132
+ todo.content.trim().length === 0
133
+ ) {
134
+ return {
135
+ success: false,
136
+ content: "",
137
+ error: `Todo item at index ${index} must have non-empty content`,
138
+ shortResult: "Invalid todo content",
139
+ };
140
+ }
141
+
142
+ if (!["pending", "in_progress", "completed"].includes(todo.status)) {
143
+ return {
144
+ success: false,
145
+ content: "",
146
+ error: `Todo item at index ${index} has invalid status: ${todo.status}`,
147
+ shortResult: "Invalid todo status",
148
+ };
149
+ }
150
+
151
+ if (
152
+ !todo.id ||
153
+ typeof todo.id !== "string" ||
154
+ todo.id.trim().length === 0
155
+ ) {
156
+ return {
157
+ success: false,
158
+ content: "",
159
+ error: `Todo item at index ${index} must have a non-empty id`,
160
+ shortResult: "Invalid todo id",
161
+ };
162
+ }
163
+ }
164
+
165
+ // Check for duplicate IDs
166
+ const ids = todos.map((todo) => todo.id);
167
+ const duplicateIds = ids.filter((id, index) => ids.indexOf(id) !== index);
168
+ if (duplicateIds.length > 0) {
169
+ return {
170
+ success: false,
171
+ content: "",
172
+ error: `Duplicate todo IDs found: ${duplicateIds.join(", ")}`,
173
+ shortResult: "Duplicate todo IDs",
174
+ };
175
+ }
176
+
177
+ // Check that only one task is in_progress
178
+ const inProgressTodos = todos.filter(
179
+ (todo) => todo.status === "in_progress",
180
+ );
181
+ if (inProgressTodos.length > 1) {
182
+ return {
183
+ success: false,
184
+ content: "",
185
+ error: `Only one todo can be in_progress at a time. Found ${inProgressTodos.length} in_progress todos`,
186
+ shortResult: "Multiple in_progress todos",
187
+ };
188
+ }
189
+
190
+ const completedCount = todos.filter(
191
+ (t) => t.status === "completed",
192
+ ).length;
193
+ const totalCount = todos.length;
194
+
195
+ let shortResult = `${completedCount}/${totalCount} done`;
196
+
197
+ if (totalCount > 0) {
198
+ const symbols = {
199
+ pending: "[ ]",
200
+ in_progress: "[>]",
201
+ completed: "[x]",
202
+ };
203
+ const inProgress = todos.filter((t) => t.status === "in_progress");
204
+ const pending = todos.filter((t) => t.status === "pending");
205
+
206
+ if (inProgress.length > 0) {
207
+ shortResult += `\n${symbols.in_progress} ${inProgress[0].content}`;
208
+ }
209
+
210
+ if (pending.length > 0) {
211
+ shortResult += `\n${symbols.pending} ${pending[0].content}`;
212
+ if (pending.length > 1) {
213
+ shortResult += ` +${pending.length - 1}`;
214
+ }
215
+ }
216
+ }
217
+
218
+ return {
219
+ success: true,
220
+ content: `Todo list updated: ${completedCount}/${totalCount} completed`,
221
+ shortResult: shortResult,
222
+ };
223
+ } catch (error) {
224
+ return {
225
+ success: false,
226
+ content: "",
227
+ error: error instanceof Error ? error.message : String(error),
228
+ shortResult: "Todo list update failed",
229
+ };
230
+ }
231
+ },
232
+ };
package/src/types.ts CHANGED
@@ -25,7 +25,8 @@ export type MessageBlock =
25
25
  | CommandOutputBlock
26
26
  | CompressBlock
27
27
  | MemoryBlock
28
- | CustomCommandBlock;
28
+ | CustomCommandBlock
29
+ | SubagentBlock;
29
30
 
30
31
  export interface TextBlock {
31
32
  type: "text";
@@ -98,6 +99,14 @@ export interface CustomCommandBlock {
98
99
  originalInput?: string; // Original user input, used for UI display (e.g., "/fix-issue 123 high")
99
100
  }
100
101
 
102
+ export interface SubagentBlock {
103
+ type: "subagent";
104
+ subagentId: string;
105
+ subagentName: string;
106
+ status: "active" | "completed" | "error" | "aborted";
107
+ messages: Message[];
108
+ }
109
+
101
110
  export interface AIRequest {
102
111
  content: string;
103
112
  files: unknown[];
@@ -0,0 +1,40 @@
1
+ import { extname } from "path";
2
+
3
+ /**
4
+ * List of binary document file extensions that should not be read as text
5
+ */
6
+ export const BINARY_DOCUMENT_EXTENSIONS = [
7
+ ".pdf",
8
+ ".doc",
9
+ ".docx",
10
+ ".xls",
11
+ ".xlsx",
12
+ ".ppt",
13
+ ".pptx",
14
+ ".odt",
15
+ ".ods",
16
+ ".odp",
17
+ ".rtf",
18
+ ] as const;
19
+
20
+ /**
21
+ * Check if a file is a binary document format based on its extension
22
+ * @param filePath - The path to the file
23
+ * @returns true if the file is a binary document format, false otherwise
24
+ */
25
+ export function isBinaryDocument(filePath: string): boolean {
26
+ const fileExtension = extname(filePath).toLowerCase();
27
+ return (BINARY_DOCUMENT_EXTENSIONS as readonly string[]).includes(
28
+ fileExtension,
29
+ );
30
+ }
31
+
32
+ /**
33
+ * Get a human-readable error message for unsupported binary document formats
34
+ * @param filePath - The path to the file
35
+ * @returns Error message string
36
+ */
37
+ export function getBinaryDocumentError(filePath: string): string {
38
+ const fileExtension = extname(filePath).toLowerCase();
39
+ return `Reading binary document files with extension '${fileExtension}' is not supported. Supported formats include text files, code files, images, and Jupyter notebooks.`;
40
+ }
@@ -504,3 +504,83 @@ export const completeCommandInMessage = ({
504
504
  }
505
505
  return newMessages;
506
506
  };
507
+
508
+ // Subagent block message operations
509
+ export interface AddSubagentBlockParams {
510
+ messages: Message[];
511
+ subagentId: string;
512
+ subagentName: string;
513
+ status: "active" | "completed" | "error" | "aborted";
514
+ subagentMessages?: Message[];
515
+ }
516
+
517
+ export interface UpdateSubagentBlockParams {
518
+ messages: Message[];
519
+ subagentId: string;
520
+ status: "active" | "completed" | "error" | "aborted";
521
+ subagentMessages: Message[];
522
+ }
523
+
524
+ export const addSubagentBlockToMessage = ({
525
+ messages,
526
+ subagentId,
527
+ subagentName,
528
+ status,
529
+ subagentMessages = [],
530
+ }: AddSubagentBlockParams): Message[] => {
531
+ const newMessages = [...messages];
532
+
533
+ // Find the last assistant message or create one
534
+ let lastAssistantMessage = newMessages[newMessages.length - 1];
535
+
536
+ if (!lastAssistantMessage || lastAssistantMessage.role !== "assistant") {
537
+ // Create new assistant message if the last message is not from assistant
538
+ lastAssistantMessage = {
539
+ role: "assistant",
540
+ blocks: [],
541
+ };
542
+ newMessages.push(lastAssistantMessage);
543
+ }
544
+
545
+ // Add subagent block
546
+ lastAssistantMessage.blocks.push({
547
+ type: "subagent",
548
+ subagentId,
549
+ subagentName,
550
+ status,
551
+ messages: subagentMessages,
552
+ });
553
+
554
+ return newMessages;
555
+ };
556
+
557
+ export const updateSubagentBlockInMessage = (
558
+ messages: Message[],
559
+ subagentId: string,
560
+ updates: Partial<{
561
+ status: "active" | "completed" | "error" | "aborted";
562
+ messages: Message[];
563
+ }>,
564
+ ): Message[] => {
565
+ const newMessages = [...messages];
566
+
567
+ // Find and update the subagent block
568
+ for (let i = newMessages.length - 1; i >= 0; i--) {
569
+ const message = newMessages[i];
570
+ if (message.role === "assistant") {
571
+ for (const block of message.blocks) {
572
+ if (block.type === "subagent" && block.subagentId === subagentId) {
573
+ if (updates.status !== undefined) {
574
+ block.status = updates.status;
575
+ }
576
+ if (updates.messages !== undefined) {
577
+ block.messages = updates.messages;
578
+ }
579
+ return newMessages;
580
+ }
581
+ }
582
+ }
583
+ }
584
+
585
+ return newMessages;
586
+ };