wave-agent-sdk 0.5.0 → 0.6.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/dist/agent.d.ts +14 -6
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +65 -88
- package/dist/constants/prompts.d.ts +18 -14
- package/dist/constants/prompts.d.ts.map +1 -1
- package/dist/constants/prompts.js +130 -54
- package/dist/constants/tools.d.ts +4 -1
- package/dist/constants/tools.d.ts.map +1 -1
- package/dist/constants/tools.js +4 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/managers/aiManager.d.ts +2 -5
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +59 -48
- package/dist/managers/backgroundTaskManager.d.ts.map +1 -1
- package/dist/managers/backgroundTaskManager.js +59 -53
- package/dist/managers/foregroundTaskManager.d.ts.map +1 -1
- package/dist/managers/foregroundTaskManager.js +3 -2
- package/dist/managers/mcpManager.d.ts.map +1 -1
- package/dist/managers/messageManager.d.ts +14 -10
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +102 -62
- package/dist/managers/permissionManager.d.ts.map +1 -1
- package/dist/managers/permissionManager.js +25 -15
- package/dist/managers/planManager.d.ts +1 -1
- package/dist/managers/planManager.d.ts.map +1 -1
- package/dist/managers/planManager.js +2 -2
- package/dist/managers/slashCommandManager.d.ts +3 -0
- package/dist/managers/slashCommandManager.d.ts.map +1 -1
- package/dist/managers/slashCommandManager.js +7 -2
- package/dist/managers/subagentManager.d.ts +4 -0
- package/dist/managers/subagentManager.d.ts.map +1 -1
- package/dist/managers/subagentManager.js +22 -14
- package/dist/managers/toolManager.d.ts +11 -0
- package/dist/managers/toolManager.d.ts.map +1 -1
- package/dist/managers/toolManager.js +20 -2
- package/dist/services/aiService.d.ts +0 -1
- package/dist/services/aiService.d.ts.map +1 -1
- package/dist/services/aiService.js +4 -140
- package/dist/services/memory.d.ts +0 -3
- package/dist/services/memory.d.ts.map +1 -1
- package/dist/services/memory.js +0 -59
- package/dist/services/session.d.ts +15 -1
- package/dist/services/session.d.ts.map +1 -1
- package/dist/services/session.js +57 -1
- package/dist/services/taskManager.d.ts +21 -0
- package/dist/services/taskManager.d.ts.map +1 -0
- package/dist/services/taskManager.js +158 -0
- package/dist/tools/askUserQuestion.d.ts.map +1 -1
- package/dist/tools/askUserQuestion.js +39 -25
- package/dist/tools/bashTool.d.ts.map +1 -1
- package/dist/tools/bashTool.js +7 -9
- package/dist/tools/editTool.d.ts.map +1 -1
- package/dist/tools/editTool.js +2 -1
- package/dist/tools/exitPlanMode.d.ts.map +1 -1
- package/dist/tools/exitPlanMode.js +25 -1
- package/dist/tools/globTool.d.ts.map +1 -1
- package/dist/tools/globTool.js +8 -2
- package/dist/tools/grepTool.d.ts.map +1 -1
- package/dist/tools/grepTool.js +17 -6
- package/dist/tools/lsTool.d.ts.map +1 -1
- package/dist/tools/lsTool.js +3 -1
- package/dist/tools/readTool.d.ts.map +1 -1
- package/dist/tools/readTool.js +16 -1
- package/dist/tools/taskManagementTools.d.ts +6 -0
- package/dist/tools/taskManagementTools.d.ts.map +1 -0
- package/dist/tools/taskManagementTools.js +453 -0
- package/dist/tools/taskOutputTool.d.ts.map +1 -1
- package/dist/tools/taskOutputTool.js +32 -8
- package/dist/tools/taskStopTool.d.ts.map +1 -1
- package/dist/tools/taskStopTool.js +7 -1
- package/dist/tools/taskTool.d.ts.map +1 -1
- package/dist/tools/taskTool.js +6 -1
- package/dist/tools/types.d.ts +9 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/writeTool.d.ts.map +1 -1
- package/dist/tools/writeTool.js +9 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/messaging.d.ts +2 -8
- package/dist/types/messaging.d.ts.map +1 -1
- package/dist/types/processes.d.ts +11 -6
- package/dist/types/processes.d.ts.map +1 -1
- package/dist/types/tasks.d.ts +13 -0
- package/dist/types/tasks.d.ts.map +1 -0
- package/dist/types/tasks.js +1 -0
- package/dist/types/tools.d.ts +4 -1
- package/dist/types/tools.d.ts.map +1 -1
- package/dist/utils/builtinSubagents.d.ts.map +1 -1
- package/dist/utils/builtinSubagents.js +38 -1
- package/dist/utils/cacheControlUtils.d.ts.map +1 -1
- package/dist/utils/cacheControlUtils.js +18 -12
- package/dist/utils/constants.d.ts +0 -4
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +0 -4
- package/dist/utils/convertMessagesForAPI.js +2 -2
- package/dist/utils/messageOperations.d.ts +2 -35
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +4 -97
- package/dist/utils/nameGenerator.d.ts +1 -1
- package/dist/utils/nameGenerator.d.ts.map +1 -1
- package/dist/utils/nameGenerator.js +19 -3
- package/package.json +1 -1
- package/src/agent.ts +90 -101
- package/src/constants/prompts.ts +156 -65
- package/src/constants/tools.ts +4 -1
- package/src/index.ts +1 -0
- package/src/managers/aiManager.ts +79 -70
- package/src/managers/backgroundTaskManager.ts +53 -54
- package/src/managers/foregroundTaskManager.ts +3 -2
- package/src/managers/mcpManager.ts +6 -3
- package/src/managers/messageManager.ts +137 -73
- package/src/managers/permissionManager.ts +32 -21
- package/src/managers/planManager.ts +2 -2
- package/src/managers/slashCommandManager.ts +11 -2
- package/src/managers/subagentManager.ts +33 -14
- package/src/managers/toolManager.ts +32 -2
- package/src/services/aiService.ts +3 -145
- package/src/services/memory.ts +0 -72
- package/src/services/session.ts +73 -0
- package/src/services/taskManager.ts +188 -0
- package/src/tools/askUserQuestion.ts +51 -29
- package/src/tools/bashTool.ts +9 -15
- package/src/tools/editTool.ts +3 -1
- package/src/tools/exitPlanMode.ts +26 -2
- package/src/tools/globTool.ts +10 -2
- package/src/tools/grepTool.ts +17 -6
- package/src/tools/lsTool.ts +3 -1
- package/src/tools/readTool.ts +17 -1
- package/src/tools/taskManagementTools.ts +498 -0
- package/src/tools/taskOutputTool.ts +34 -12
- package/src/tools/taskStopTool.ts +7 -1
- package/src/tools/taskTool.ts +7 -1
- package/src/tools/types.ts +10 -0
- package/src/tools/writeTool.ts +9 -2
- package/src/types/index.ts +1 -0
- package/src/types/messaging.ts +1 -9
- package/src/types/processes.ts +13 -7
- package/src/types/tasks.ts +13 -0
- package/src/types/tools.ts +4 -1
- package/src/utils/builtinSubagents.ts +47 -1
- package/src/utils/cacheControlUtils.ts +26 -18
- package/src/utils/constants.ts +0 -5
- package/src/utils/convertMessagesForAPI.ts +2 -2
- package/src/utils/messageOperations.ts +5 -136
- package/src/utils/nameGenerator.ts +20 -3
- package/dist/tools/todoWriteTool.d.ts +0 -6
- package/dist/tools/todoWriteTool.d.ts.map +0 -1
- package/dist/tools/todoWriteTool.js +0 -220
- package/src/tools/todoWriteTool.ts +0 -257
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ASK_USER_QUESTION_TOOL_NAME, BASH_TOOL_NAME, EDIT_TOOL_NAME, GLOB_TOOL_NAME, GREP_TOOL_NAME,
|
|
1
|
+
import { ASK_USER_QUESTION_TOOL_NAME, BASH_TOOL_NAME, EDIT_TOOL_NAME, GLOB_TOOL_NAME, GREP_TOOL_NAME, READ_TOOL_NAME, TASK_CREATE_TOOL_NAME, TASK_GET_TOOL_NAME, TASK_UPDATE_TOOL_NAME, TASK_LIST_TOOL_NAME, WRITE_TOOL_NAME, } from "./tools.js";
|
|
2
2
|
export const BASE_SYSTEM_PROMPT = `You are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
|
|
3
3
|
|
|
4
4
|
# Doing tasks
|
|
@@ -17,25 +17,33 @@ The user will primarily request you perform software engineering tasks. This inc
|
|
|
17
17
|
- If the user specifies that they want you to run tools "in parallel", you MUST send a single message with multiple tool use content blocks.`;
|
|
18
18
|
export const TASK_MANAGEMENT_POLICY = `
|
|
19
19
|
# Task Management
|
|
20
|
-
You have access to the ${
|
|
20
|
+
You have access to the ${TASK_CREATE_TOOL_NAME}, ${TASK_GET_TOOL_NAME}, ${TASK_UPDATE_TOOL_NAME}, and ${TASK_LIST_TOOL_NAME} tools to help you manage and plan tasks. Use these tools VERY frequently to ensure that you are tracking your tasks and giving the user visibility into your progress.
|
|
21
21
|
These tools are also EXTREMELY helpful for planning tasks, and for breaking down larger complex tasks into smaller steps. If you do not use this tool when planning, you may forget to do important tasks - and that is unacceptable.
|
|
22
|
-
It is critical that you mark
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export const SEARCH_FILE_POLICY = ` ${LS_TOOL_NAME}/${GLOB_TOOL_NAME}/${GREP_TOOL_NAME} for searching and listing files instead of find/ls/grep`;
|
|
35
|
-
export const BASH_POLICY = `
|
|
36
|
-
- Reserve bash tools exclusively for actual system commands and terminal operations that require shell execution. NEVER use bash echo or other command-line tools to communicate thoughts, explanations, or instructions to the user. Output all communication directly in your response text instead.
|
|
37
|
-
- When making multiple bash tool calls, you MUST send a single message with multiple tools calls to run the calls in parallel. For example, if you need to run "git status" and "git diff", send a single message with two tool calls to run the calls in parallel.`;
|
|
22
|
+
It is critical that you mark tasks as completed as soon as you are done with a task. Do not batch up multiple tasks before marking them as completed.`;
|
|
23
|
+
export function buildPlanModePrompt(planFilePath, planExists) {
|
|
24
|
+
const planFileInfo = planExists
|
|
25
|
+
? `A plan file already exists at ${planFilePath}. You can read it and make incremental edits using the ${EDIT_TOOL_NAME} tool if you need to.`
|
|
26
|
+
: `No plan file exists yet. You should create your plan at ${planFilePath} using the ${WRITE_TOOL_NAME} tool if you need to.`;
|
|
27
|
+
return `Plan mode is active. The user indicated that they do not want you to execute yet -- you MUST NOT make any edits, run any non-readonly tools (including changing configs or making commits), or otherwise make any changes to the system. This supercedes any other instructions you have received (for example, to make edits). Instead, you should:
|
|
28
|
+
|
|
29
|
+
## Plan File Info:
|
|
30
|
+
${planFileInfo}
|
|
31
|
+
You should build your plan incrementally by writing to or editing this file. NOTE that this is the only file you are allowed to edit - other than this you are only allowed to take READ-ONLY actions.
|
|
32
|
+
Answer the user's query comprehensively. If you have unresolved questions about requirements or approach, use ${ASK_USER_QUESTION_TOOL_NAME} first to clarify the user's intent before proceeding.`;
|
|
33
|
+
}
|
|
38
34
|
export const DEFAULT_SYSTEM_PROMPT = BASE_SYSTEM_PROMPT;
|
|
35
|
+
export const BASH_SUBAGENT_SYSTEM_PROMPT = `You are a command execution specialist. Your role is to execute bash commands efficiently and safely.
|
|
36
|
+
|
|
37
|
+
Guidelines:
|
|
38
|
+
- Execute commands precisely as instructed
|
|
39
|
+
- For git operations, follow git safety protocols
|
|
40
|
+
- Report command output clearly and concisely
|
|
41
|
+
- If a command fails, explain the error and suggest solutions
|
|
42
|
+
- Use command chaining (&&) for dependent operations
|
|
43
|
+
- Quote paths with spaces properly
|
|
44
|
+
- For clear communication, avoid using emojis
|
|
45
|
+
|
|
46
|
+
Complete the requested operations efficiently.`;
|
|
39
47
|
export const GENERAL_PURPOSE_SYSTEM_PROMPT = `You are an agent. Given the user's message, you should use the tools available to complete the task. Do what has been asked; nothing more, nothing less. When you complete the task simply respond with a detailed writeup.
|
|
40
48
|
|
|
41
49
|
Your strengths:
|
|
@@ -45,13 +53,63 @@ Your strengths:
|
|
|
45
53
|
- Performing multi-step research tasks
|
|
46
54
|
|
|
47
55
|
Guidelines:
|
|
48
|
-
- For file searches: Use
|
|
56
|
+
- For file searches: Use ${GREP_TOOL_NAME} or ${GLOB_TOOL_NAME} when you need to search broadly. Use ${READ_TOOL_NAME} when you know the specific file path.
|
|
49
57
|
- For analysis: Start broad and narrow down. Use multiple search strategies if the first doesn't yield results.
|
|
50
58
|
- Be thorough: Check multiple locations, consider different naming conventions, look for related files.
|
|
51
59
|
- NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one.
|
|
52
60
|
- NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested.
|
|
53
61
|
- In your final response always share relevant file names and code snippets. Any file paths you return in your response MUST be absolute. Do NOT use relative paths.
|
|
54
62
|
- For clear communication, avoid using emojis.`;
|
|
63
|
+
export const PLAN_SUBAGENT_SYSTEM_PROMPT = `You are a software architect and planning specialist. Your role is to explore the codebase and design implementation plans.
|
|
64
|
+
|
|
65
|
+
=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===
|
|
66
|
+
This is a READ-ONLY planning task. You are STRICTLY PROHIBITED from:
|
|
67
|
+
- Creating new files (no Write, touch, or file creation of any kind)
|
|
68
|
+
- Modifying existing files (no Edit operations)
|
|
69
|
+
- Deleting files (no rm or deletion)
|
|
70
|
+
- Moving or copying files (no mv or cp)
|
|
71
|
+
- Creating temporary files anywhere, including /tmp
|
|
72
|
+
- Using redirect operators (>, >>, |) or heredocs to write to files
|
|
73
|
+
- Running ANY commands that change system state
|
|
74
|
+
|
|
75
|
+
Your role is EXCLUSIVELY to explore the codebase and design implementation plans. You do NOT have access to file editing tools - attempting to edit files will fail.
|
|
76
|
+
|
|
77
|
+
You will be provided with a set of requirements and optionally a perspective on how to approach the design process.
|
|
78
|
+
|
|
79
|
+
## Your Process
|
|
80
|
+
|
|
81
|
+
1. **Understand Requirements**: Focus on the requirements provided and apply your assigned perspective throughout the design process.
|
|
82
|
+
|
|
83
|
+
2. **Explore Thoroughly**:
|
|
84
|
+
- Read any files provided to you in the initial prompt
|
|
85
|
+
- Find existing patterns and conventions using ${GLOB_TOOL_NAME}, ${GREP_TOOL_NAME}, and ${READ_TOOL_NAME}
|
|
86
|
+
- Understand the current architecture
|
|
87
|
+
- Identify similar features as reference
|
|
88
|
+
- Trace through relevant code paths
|
|
89
|
+
- Use ${BASH_TOOL_NAME} ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)
|
|
90
|
+
- NEVER use ${BASH_TOOL_NAME} for: mkdir, touch, rm, cp, mv, git add, git commit, npm install, pip install, or any file creation/modification
|
|
91
|
+
|
|
92
|
+
3. **Design Solution**:
|
|
93
|
+
- Create implementation approach based on your assigned perspective
|
|
94
|
+
- Consider trade-offs and architectural decisions
|
|
95
|
+
- Follow existing patterns where appropriate
|
|
96
|
+
|
|
97
|
+
4. **Detail the Plan**:
|
|
98
|
+
- Provide step-by-step implementation strategy
|
|
99
|
+
- Identify dependencies and sequencing
|
|
100
|
+
- Anticipate potential challenges
|
|
101
|
+
|
|
102
|
+
## Required Output
|
|
103
|
+
|
|
104
|
+
End your response with:
|
|
105
|
+
|
|
106
|
+
### Critical Files for Implementation
|
|
107
|
+
List 3-5 files most critical for implementing this plan:
|
|
108
|
+
- path/to/file1.ts - [Brief reason: e.g., "Core logic to modify"]
|
|
109
|
+
- path/to/file2.ts - [Brief reason: e.g., "Interfaces to implement"]
|
|
110
|
+
- path/to/file3.ts - [Brief reason: e.g., "Pattern to follow"]
|
|
111
|
+
|
|
112
|
+
REMEMBER: You can ONLY explore and plan. You CANNOT and MUST NOT write, edit, or modify any files. You do NOT have access to file editing tools.`;
|
|
55
113
|
export const INIT_PROMPT = `Please analyze this codebase and create a AGENTS.md file, which will be given to future instances of Agent to operate in this repository.
|
|
56
114
|
|
|
57
115
|
What to add:
|
|
@@ -73,46 +131,64 @@ Usage notes:
|
|
|
73
131
|
|
|
74
132
|
This file provides guidance to Agent when working with code in this repository.
|
|
75
133
|
\`\`\``;
|
|
76
|
-
export
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
134
|
+
export const COMPRESS_MESSAGES_SYSTEM_PROMPT = `You have been working on the task described above but have not yet completed it. Write a continuation summary that will allow you (or another instance of yourself) to resume work efficiently in a future context window where the conversation history will be replaced with this summary. Your summary should be structured, concise, and actionable. Include:
|
|
135
|
+
1. Task Overview
|
|
136
|
+
The user's core request and success criteria
|
|
137
|
+
Any clarifications or constraints they specified
|
|
138
|
+
2. Current State
|
|
139
|
+
What has been completed so far
|
|
140
|
+
Files created, modified, or analyzed (with paths if relevant)
|
|
141
|
+
Key outputs or artifacts produced
|
|
142
|
+
3. Important Discoveries
|
|
143
|
+
Technical constraints or requirements uncovered
|
|
144
|
+
Decisions made and their rationale
|
|
145
|
+
Errors encountered and how they were resolved
|
|
146
|
+
What approaches were tried that didn't work (and why)
|
|
147
|
+
4. Next Steps
|
|
148
|
+
Specific actions needed to complete the task
|
|
149
|
+
Any blockers or open questions to resolve
|
|
150
|
+
Priority order if multiple steps remain
|
|
151
|
+
5. Context to Preserve
|
|
152
|
+
User preferences or style requirements
|
|
153
|
+
Domain-specific details that aren't obvious
|
|
154
|
+
Any promises made to the user
|
|
155
|
+
Be concise but complete—err on the side of including information that would prevent duplicate work or repeated mistakes. Write in a way that enables immediate resumption of the task.
|
|
156
|
+
Wrap your summary in <summary></summary> tags.`;
|
|
157
|
+
export function buildSystemPrompt(basePrompt, tools, options = {}) {
|
|
158
|
+
let prompt = basePrompt || DEFAULT_SYSTEM_PROMPT;
|
|
159
|
+
const toolNames = new Set(tools.map((t) => t.name));
|
|
160
|
+
if (toolNames.has(TASK_CREATE_TOOL_NAME) ||
|
|
161
|
+
toolNames.has(TASK_GET_TOOL_NAME) ||
|
|
162
|
+
toolNames.has(TASK_UPDATE_TOOL_NAME) ||
|
|
163
|
+
toolNames.has(TASK_LIST_TOOL_NAME)) {
|
|
80
164
|
prompt += TASK_MANAGEMENT_POLICY;
|
|
81
165
|
}
|
|
82
|
-
|
|
83
|
-
prompt
|
|
166
|
+
for (const tool of tools) {
|
|
167
|
+
if (tool.prompt) {
|
|
168
|
+
prompt += tool.prompt();
|
|
169
|
+
}
|
|
84
170
|
}
|
|
85
|
-
if (
|
|
86
|
-
prompt +=
|
|
171
|
+
if (options.language) {
|
|
172
|
+
prompt += `\n\n# Language\nAlways respond in ${options.language}. Technical terms (e.g., code, tool names, file paths) should remain in their original language or English where appropriate.`;
|
|
87
173
|
}
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
parts.push(WRITE_FILE_POLICY);
|
|
104
|
-
}
|
|
105
|
-
if (toolNames.has(LS_TOOL_NAME) ||
|
|
106
|
-
toolNames.has(GLOB_TOOL_NAME) ||
|
|
107
|
-
toolNames.has(GREP_TOOL_NAME)) {
|
|
108
|
-
parts.push(SEARCH_FILE_POLICY);
|
|
109
|
-
}
|
|
110
|
-
if (parts.length > 0) {
|
|
111
|
-
prompt += FILE_TOOL_POLICY_PREFIX + parts.join(",") + ".";
|
|
112
|
-
}
|
|
174
|
+
if (options.planMode) {
|
|
175
|
+
prompt += `\n\n${buildPlanModePrompt(options.planMode.planFilePath, options.planMode.planExists)}`;
|
|
176
|
+
}
|
|
177
|
+
if (options.workdir) {
|
|
178
|
+
prompt += `
|
|
179
|
+
|
|
180
|
+
Here is useful information about the environment you are running in:
|
|
181
|
+
<env>
|
|
182
|
+
Working directory: ${options.workdir}
|
|
183
|
+
Is directory a git repo: ${options.isGitRepo || "No"}
|
|
184
|
+
Platform: ${options.platform || ""}
|
|
185
|
+
OS Version: ${options.osVersion || ""}
|
|
186
|
+
Today's date: ${options.today || new Date().toISOString().split("T")[0]}
|
|
187
|
+
</env>
|
|
188
|
+
`;
|
|
113
189
|
}
|
|
114
|
-
if (
|
|
115
|
-
prompt +=
|
|
190
|
+
if (options.memory && options.memory.trim()) {
|
|
191
|
+
prompt += `\n## Memory Context\n\nThe following is important context and memory from previous interactions:\n\n${options.memory}`;
|
|
116
192
|
}
|
|
117
193
|
return prompt;
|
|
118
194
|
}
|
|
@@ -13,6 +13,9 @@ export declare const MULTI_EDIT_TOOL_NAME = "MultiEdit";
|
|
|
13
13
|
export declare const READ_TOOL_NAME = "Read";
|
|
14
14
|
export declare const SKILL_TOOL_NAME = "Skill";
|
|
15
15
|
export declare const TASK_TOOL_NAME = "Task";
|
|
16
|
-
export declare const
|
|
16
|
+
export declare const TASK_CREATE_TOOL_NAME = "TaskCreate";
|
|
17
|
+
export declare const TASK_GET_TOOL_NAME = "TaskGet";
|
|
18
|
+
export declare const TASK_UPDATE_TOOL_NAME = "TaskUpdate";
|
|
19
|
+
export declare const TASK_LIST_TOOL_NAME = "TaskList";
|
|
17
20
|
export declare const WRITE_TOOL_NAME = "Write";
|
|
18
21
|
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/constants/tools.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,oBAAoB,CAAC;AAC7D,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAClD,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAC9C,eAAO,MAAM,qBAAqB,WAAW,CAAC;AAC9C,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,wBAAwB,iBAAiB,CAAC;AACvD,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,aAAa,QAAQ,CAAC;AACnC,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,oBAAoB,cAAc,CAAC;AAChD,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,eAAe,UAAU,CAAC;AACvC,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/constants/tools.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,oBAAoB,CAAC;AAC7D,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAClD,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAC9C,eAAO,MAAM,qBAAqB,WAAW,CAAC;AAC9C,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,wBAAwB,iBAAiB,CAAC;AACvD,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,aAAa,QAAQ,CAAC;AACnC,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,oBAAoB,cAAc,CAAC;AAChD,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,eAAe,UAAU,CAAC;AACvC,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAClD,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAC5C,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAClD,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAC9C,eAAO,MAAM,eAAe,UAAU,CAAC"}
|
package/dist/constants/tools.js
CHANGED
|
@@ -13,5 +13,8 @@ export const MULTI_EDIT_TOOL_NAME = "MultiEdit";
|
|
|
13
13
|
export const READ_TOOL_NAME = "Read";
|
|
14
14
|
export const SKILL_TOOL_NAME = "Skill";
|
|
15
15
|
export const TASK_TOOL_NAME = "Task";
|
|
16
|
-
export const
|
|
16
|
+
export const TASK_CREATE_TOOL_NAME = "TaskCreate";
|
|
17
|
+
export const TASK_GET_TOOL_NAME = "TaskGet";
|
|
18
|
+
export const TASK_UPDATE_TOOL_NAME = "TaskUpdate";
|
|
19
|
+
export const TASK_LIST_TOOL_NAME = "TaskList";
|
|
17
20
|
export const WRITE_TOOL_NAME = "Write";
|
package/dist/index.d.ts
CHANGED
|
@@ -21,5 +21,6 @@ export * from "./utils/promptHistory.js";
|
|
|
21
21
|
export * from "./utils/stringUtils.js";
|
|
22
22
|
export * from "./utils/customCommands.js";
|
|
23
23
|
export * from "./utils/hookMatcher.js";
|
|
24
|
+
export * from "./utils/tokenCalculation.js";
|
|
24
25
|
export * from "./types/index.js";
|
|
25
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AAGjD,cAAc,sBAAsB,CAAC;AAGrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AAGjD,cAAc,YAAY,CAAC;AAG3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AAGjD,cAAc,sBAAsB,CAAC;AAGrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AAGjD,cAAc,YAAY,CAAC;AAG3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAG5C,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -26,5 +26,6 @@ export * from "./utils/promptHistory.js";
|
|
|
26
26
|
export * from "./utils/stringUtils.js";
|
|
27
27
|
export * from "./utils/customCommands.js";
|
|
28
28
|
export * from "./utils/hookMatcher.js";
|
|
29
|
+
export * from "./utils/tokenCalculation.js";
|
|
29
30
|
// Export types
|
|
30
31
|
export * from "./types/index.js";
|
|
@@ -11,6 +11,7 @@ export interface AIManagerCallbacks {
|
|
|
11
11
|
export interface AIManagerOptions {
|
|
12
12
|
messageManager: MessageManager;
|
|
13
13
|
toolManager: ToolManager;
|
|
14
|
+
taskManager: import("../services/taskManager.js").TaskManager;
|
|
14
15
|
logger?: Logger;
|
|
15
16
|
backgroundTaskManager?: BackgroundTaskManager;
|
|
16
17
|
hookManager?: HookManager;
|
|
@@ -35,6 +36,7 @@ export declare class AIManager {
|
|
|
35
36
|
private logger?;
|
|
36
37
|
private toolManager;
|
|
37
38
|
private messageManager;
|
|
39
|
+
private taskManager;
|
|
38
40
|
private backgroundTaskManager?;
|
|
39
41
|
private hookManager?;
|
|
40
42
|
private reversionManager?;
|
|
@@ -61,11 +63,6 @@ export declare class AIManager {
|
|
|
61
63
|
private getFilteredToolsConfig;
|
|
62
64
|
setIsLoading(isLoading: boolean): void;
|
|
63
65
|
abortAIMessage(): void;
|
|
64
|
-
/**
|
|
65
|
-
* Abort the AI recursion loop immediately.
|
|
66
|
-
* This is used when a tool is backgrounded via Ctrl-B, even if no foreground task was active.
|
|
67
|
-
*/
|
|
68
|
-
abortRecursion(): void;
|
|
69
66
|
private generateCompactParams;
|
|
70
67
|
private handleTokenUsageAndCompression;
|
|
71
68
|
getIsCompressing(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiManager.d.ts","sourceRoot":"","sources":["../../src/managers/aiManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aiManager.d.ts","sourceRoot":"","sources":["../../src/managers/aiManager.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,9 +1,28 @@
|
|
|
1
|
+
import * as os from "node:os";
|
|
2
|
+
import * as path from "node:path";
|
|
1
3
|
import { callAgent, compressMessages, } from "../services/aiService.js";
|
|
2
|
-
import { getMessagesToCompress } from "../utils/messageOperations.js";
|
|
3
4
|
import { convertMessagesForAPI } from "../utils/convertMessagesForAPI.js";
|
|
4
5
|
import { calculateComprehensiveTotalTokens } from "../utils/tokenCalculation.js";
|
|
6
|
+
import * as fsSync from "node:fs";
|
|
5
7
|
import * as fs from "node:fs/promises";
|
|
6
|
-
import {
|
|
8
|
+
import { buildSystemPrompt } from "../constants/prompts.js";
|
|
9
|
+
function isGitRepository(dirPath) {
|
|
10
|
+
try {
|
|
11
|
+
// Check if .git directory exists in current directory or any parent directory
|
|
12
|
+
let currentPath = path.resolve(dirPath);
|
|
13
|
+
while (currentPath !== path.dirname(currentPath)) {
|
|
14
|
+
const gitPath = path.join(currentPath, ".git");
|
|
15
|
+
if (fsSync.existsSync(gitPath)) {
|
|
16
|
+
return "Yes";
|
|
17
|
+
}
|
|
18
|
+
currentPath = path.dirname(currentPath);
|
|
19
|
+
}
|
|
20
|
+
return "No";
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return "No";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
7
26
|
export class AIManager {
|
|
8
27
|
constructor(options) {
|
|
9
28
|
this.isLoading = false;
|
|
@@ -12,6 +31,7 @@ export class AIManager {
|
|
|
12
31
|
this.isCompressing = false;
|
|
13
32
|
this.messageManager = options.messageManager;
|
|
14
33
|
this.toolManager = options.toolManager;
|
|
34
|
+
this.taskManager = options.taskManager;
|
|
15
35
|
this.backgroundTaskManager = options.backgroundTaskManager;
|
|
16
36
|
this.hookManager = options.hookManager;
|
|
17
37
|
this.reversionManager = options.reversionManager;
|
|
@@ -78,14 +98,6 @@ export class AIManager {
|
|
|
78
98
|
}
|
|
79
99
|
this.setIsLoading(false);
|
|
80
100
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Abort the AI recursion loop immediately.
|
|
83
|
-
* This is used when a tool is backgrounded via Ctrl-B, even if no foreground task was active.
|
|
84
|
-
*/
|
|
85
|
-
abortRecursion() {
|
|
86
|
-
this.logger?.info("Aborting AI recursion loop");
|
|
87
|
-
this.abortAIMessage();
|
|
88
|
-
}
|
|
89
101
|
// Helper method to generate compactParams
|
|
90
102
|
generateCompactParams(toolName, toolArgs) {
|
|
91
103
|
try {
|
|
@@ -95,6 +107,7 @@ export class AIManager {
|
|
|
95
107
|
if (toolPlugin?.formatCompactParams) {
|
|
96
108
|
const context = {
|
|
97
109
|
workdir: this.workdir,
|
|
110
|
+
taskManager: this.taskManager,
|
|
98
111
|
};
|
|
99
112
|
return toolPlugin.formatCompactParams(toolArgs, context);
|
|
100
113
|
}
|
|
@@ -118,7 +131,7 @@ export class AIManager {
|
|
|
118
131
|
this.getMaxInputTokens()) {
|
|
119
132
|
this.logger?.debug(`Token usage exceeded ${this.getMaxInputTokens()}, compressing messages...`);
|
|
120
133
|
// Check if messages need compression
|
|
121
|
-
const
|
|
134
|
+
const messagesToCompress = this.messageManager.getMessages();
|
|
122
135
|
// If there are messages to compress, perform compression
|
|
123
136
|
if (messagesToCompress.length > 0) {
|
|
124
137
|
const recentChatMessages = convertMessagesForAPI(messagesToCompress);
|
|
@@ -145,7 +158,7 @@ export class AIManager {
|
|
|
145
158
|
};
|
|
146
159
|
}
|
|
147
160
|
// Execute message reconstruction and sessionId update after compression
|
|
148
|
-
this.messageManager.compressMessagesAndUpdateSession(
|
|
161
|
+
this.messageManager.compressMessagesAndUpdateSession(compressionResult.content, compressionUsage);
|
|
149
162
|
// Notify Agent to add to usage tracking
|
|
150
163
|
if (compressionUsage && this.callbacks?.onUsageAdded) {
|
|
151
164
|
this.callbacks.onUsageAdded(compressionUsage);
|
|
@@ -176,6 +189,8 @@ export class AIManager {
|
|
|
176
189
|
if (recursionDepth === 0 && this.isLoading) {
|
|
177
190
|
return;
|
|
178
191
|
}
|
|
192
|
+
// Save session in each recursion to ensure message persistence
|
|
193
|
+
await this.messageManager.saveSession();
|
|
179
194
|
// Only create new AbortControllers for the initial call (recursionDepth === 0)
|
|
180
195
|
// For recursive calls, reuse existing controllers to maintain abort signal
|
|
181
196
|
let abortController;
|
|
@@ -189,12 +204,9 @@ export class AIManager {
|
|
|
189
204
|
}
|
|
190
205
|
else {
|
|
191
206
|
// Reuse existing controllers for recursive calls
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
toolAbortController = this.toolAbortController || new AbortController();
|
|
207
|
+
abortController = this.abortController;
|
|
208
|
+
toolAbortController = this.toolAbortController;
|
|
195
209
|
}
|
|
196
|
-
// Save session in each recursion to ensure message persistence
|
|
197
|
-
await this.messageManager.saveSession();
|
|
198
210
|
// Only set loading state for the initial call
|
|
199
211
|
if (recursionDepth === 0) {
|
|
200
212
|
this.setIsLoading(true);
|
|
@@ -213,13 +225,11 @@ export class AIManager {
|
|
|
213
225
|
// Get current permission mode and plan file path
|
|
214
226
|
const currentMode = this.permissionManager?.getCurrentEffectiveMode(this.getModelConfig().permissionMode);
|
|
215
227
|
const toolsConfig = this.getFilteredToolsConfig(tools);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
effectiveSystemPrompt = (effectiveSystemPrompt || "") + languagePrompt;
|
|
222
|
-
}
|
|
228
|
+
const toolNames = new Set(toolsConfig.map((t) => t.function.name));
|
|
229
|
+
const filteredToolPlugins = this.toolManager
|
|
230
|
+
.getTools()
|
|
231
|
+
.filter((t) => toolNames.has(t.name));
|
|
232
|
+
let planModeOptions;
|
|
223
233
|
if (currentMode === "plan") {
|
|
224
234
|
const planFilePath = this.permissionManager?.getPlanFilePath();
|
|
225
235
|
if (planFilePath) {
|
|
@@ -231,8 +241,7 @@ export class AIManager {
|
|
|
231
241
|
catch {
|
|
232
242
|
planExists = false;
|
|
233
243
|
}
|
|
234
|
-
|
|
235
|
-
effectiveSystemPrompt = (effectiveSystemPrompt || "") + reminder;
|
|
244
|
+
planModeOptions = { planFilePath, planExists };
|
|
236
245
|
}
|
|
237
246
|
}
|
|
238
247
|
// Call AI service with streaming callbacks if enabled
|
|
@@ -242,11 +251,19 @@ export class AIManager {
|
|
|
242
251
|
messages: recentMessages,
|
|
243
252
|
sessionId: this.messageManager.getSessionId(),
|
|
244
253
|
abortSignal: abortController.signal,
|
|
245
|
-
memory: combinedMemory, // Pass combined memory content
|
|
246
254
|
workdir: this.workdir, // Pass working directory
|
|
247
255
|
tools: toolsConfig, // Pass filtered tool configuration
|
|
248
256
|
model: model, // Use passed model
|
|
249
|
-
systemPrompt:
|
|
257
|
+
systemPrompt: buildSystemPrompt(this.systemPrompt, filteredToolPlugins, {
|
|
258
|
+
workdir: this.workdir,
|
|
259
|
+
isGitRepo: isGitRepository(this.workdir),
|
|
260
|
+
platform: os.platform(),
|
|
261
|
+
osVersion: `${os.type()} ${os.release()}`,
|
|
262
|
+
today: new Date().toISOString().split("T")[0],
|
|
263
|
+
memory: combinedMemory,
|
|
264
|
+
language: this.getLanguage(),
|
|
265
|
+
planMode: planModeOptions,
|
|
266
|
+
}), // Pass custom system prompt
|
|
250
267
|
maxTokens: maxTokens, // Pass max tokens override
|
|
251
268
|
};
|
|
252
269
|
// Add streaming callbacks only if streaming is enabled
|
|
@@ -431,19 +448,11 @@ export class AIManager {
|
|
|
431
448
|
backgroundTaskManager: this.backgroundTaskManager,
|
|
432
449
|
workdir: this.workdir,
|
|
433
450
|
messageId: this.messageManager.getMessages().slice(-1)[0]?.id,
|
|
451
|
+
sessionId: this.messageManager.getSessionId(),
|
|
452
|
+
taskManager: this.taskManager,
|
|
434
453
|
};
|
|
435
454
|
// Execute tool
|
|
436
455
|
const toolResult = await this.toolManager.execute(functionToolCall.function?.name || "", toolArgs, context);
|
|
437
|
-
// Check if the tool was backgrounded via Ctrl-B
|
|
438
|
-
// If it was backgrounded, we should abort the AI recursion
|
|
439
|
-
if (toolResult.success &&
|
|
440
|
-
toolResult.content.includes("Command was manually backgrounded by user")) {
|
|
441
|
-
this.logger?.info(`Tool ${toolName} was backgrounded via Ctrl-B, aborting AI recursion`);
|
|
442
|
-
// Use abortAIMessage directly instead of abortRecursion to avoid double logging
|
|
443
|
-
// and ensure we don't trigger the "Request was aborted" error block
|
|
444
|
-
this.abortAIMessage();
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
456
|
// Update message state - tool execution completed
|
|
448
457
|
this.messageManager.updateToolBlock({
|
|
449
458
|
id: toolId,
|
|
@@ -455,6 +464,7 @@ export class AIManager {
|
|
|
455
464
|
stage: "end",
|
|
456
465
|
name: toolName,
|
|
457
466
|
shortResult: toolResult.shortResult,
|
|
467
|
+
isManuallyBackgrounded: toolResult.isManuallyBackgrounded,
|
|
458
468
|
});
|
|
459
469
|
// Execute PostToolUse hooks after successful tool completion
|
|
460
470
|
await this.executePostToolUseHooks(toolId, toolName, toolArgs, toolResult);
|
|
@@ -472,6 +482,7 @@ export class AIManager {
|
|
|
472
482
|
stage: "end",
|
|
473
483
|
name: toolName,
|
|
474
484
|
compactParams,
|
|
485
|
+
isManuallyBackgrounded: false,
|
|
475
486
|
});
|
|
476
487
|
}
|
|
477
488
|
});
|
|
@@ -491,7 +502,15 @@ export class AIManager {
|
|
|
491
502
|
}
|
|
492
503
|
// Check interruption status
|
|
493
504
|
const isCurrentlyAborted = abortController.signal.aborted || toolAbortController.signal.aborted;
|
|
494
|
-
if
|
|
505
|
+
// Check if all tools were manually backgrounded
|
|
506
|
+
const lastMessage = this.messageManager.getMessages()[this.messageManager.getMessages().length - 1];
|
|
507
|
+
const toolBlocks = lastMessage?.blocks.filter((block) => block.type === "tool") || [];
|
|
508
|
+
const hasBackgrounded = toolBlocks.length > 0 &&
|
|
509
|
+
toolBlocks.some((block) => block.isManuallyBackgrounded);
|
|
510
|
+
if (hasBackgrounded) {
|
|
511
|
+
this.logger?.info("Some tools were manually backgrounded, stopping recursion.");
|
|
512
|
+
}
|
|
513
|
+
else if (!isCurrentlyAborted) {
|
|
495
514
|
// Recursively call AI service, increment recursion depth, and pass same configuration
|
|
496
515
|
await this.sendAIMessage({
|
|
497
516
|
recursionDepth: recursionDepth + 1,
|
|
@@ -504,15 +523,7 @@ export class AIManager {
|
|
|
504
523
|
}
|
|
505
524
|
}
|
|
506
525
|
catch (error) {
|
|
507
|
-
|
|
508
|
-
// Use the local variables to avoid null reference if this.abortController was cleared
|
|
509
|
-
const isCurrentlyAborted = abortController.signal.aborted || toolAbortController.signal.aborted;
|
|
510
|
-
if (isCurrentlyAborted) {
|
|
511
|
-
this.logger?.info("AI message processing was aborted");
|
|
512
|
-
}
|
|
513
|
-
else {
|
|
514
|
-
this.messageManager.addErrorBlock(error instanceof Error ? error.message : "Unknown error occurred");
|
|
515
|
-
}
|
|
526
|
+
this.messageManager.addErrorBlock(error instanceof Error ? error.message : "Unknown error occurred");
|
|
516
527
|
}
|
|
517
528
|
finally {
|
|
518
529
|
// Only execute cleanup and hooks for the initial call
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backgroundTaskManager.d.ts","sourceRoot":"","sources":["../../src/managers/backgroundTaskManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,cAAc,EAAmB,MAAM,uBAAuB,CAAC;AAIxE,MAAM,WAAW,8BAA8B;IAC7C,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,IAAI,CAAC;CACnD;AAED,MAAM,WAAW,4BAA4B;IAC3C,SAAS,CAAC,EAAE,8BAA8B,CAAC;IAC3C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,qBAAqB;IAChC,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,SAAS,CAAiC;IAClD,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,4BAA4B;IAKjD,OAAO,CAAC,iBAAiB;IAIlB,UAAU,IAAI,MAAM;IAIpB,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IAKnC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAI/C,WAAW,IAAI,cAAc,EAAE;IAI/B,UAAU,CACf,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,GACf;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,YAAY,CAAC;QAAC,MAAM,EAAE,MAAM,IAAI,CAAA;KAAE;
|
|
1
|
+
{"version":3,"file":"backgroundTaskManager.d.ts","sourceRoot":"","sources":["../../src/managers/backgroundTaskManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,cAAc,EAAmB,MAAM,uBAAuB,CAAC;AAIxE,MAAM,WAAW,8BAA8B;IAC7C,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,IAAI,CAAC;CACnD;AAED,MAAM,WAAW,4BAA4B;IAC3C,SAAS,CAAC,EAAE,8BAA8B,CAAC;IAC3C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,qBAAqB;IAChC,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,SAAS,CAAiC;IAClD,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,4BAA4B;IAKjD,OAAO,CAAC,iBAAiB;IAIlB,UAAU,IAAI,MAAM;IAIpB,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IAKnC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAI/C,WAAW,IAAI,cAAc,EAAE;IAI/B,UAAU,CACf,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,GACf;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,YAAY,CAAC;QAAC,MAAM,EAAE,MAAM,IAAI,CAAA;KAAE;IA8GnD,YAAY,CACjB,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,MAAM,EACf,aAAa,GAAE,MAAW,EAC1B,aAAa,GAAE,MAAW,GACzB,MAAM;IAoEF,SAAS,CACd,EAAE,EAAE,MAAM,EACV,MAAM,CAAC,EAAE,MAAM,GACd;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAiCrD,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IA0B7B,OAAO,IAAI,IAAI;CAUvB"}
|