wave-agent-sdk 0.17.1 → 0.17.3
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/builtin/skills/deep-research/SKILL.md +90 -0
- package/builtin/skills/settings/ENV.md +6 -3
- package/dist/agent.d.ts +28 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +128 -34
- package/dist/constants/goalPrompts.d.ts +2 -0
- package/dist/constants/goalPrompts.d.ts.map +1 -0
- package/dist/constants/goalPrompts.js +10 -0
- package/dist/constants/tools.d.ts +1 -0
- package/dist/constants/tools.d.ts.map +1 -1
- package/dist/constants/tools.js +1 -0
- package/dist/managers/aiManager.d.ts +7 -0
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +77 -41
- package/dist/managers/backgroundTaskManager.d.ts.map +1 -1
- package/dist/managers/backgroundTaskManager.js +10 -2
- package/dist/managers/goalManager.d.ts +43 -0
- package/dist/managers/goalManager.d.ts.map +1 -0
- package/dist/managers/goalManager.js +177 -0
- package/dist/managers/messageManager.d.ts +2 -2
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageQueue.d.ts +10 -0
- package/dist/managers/messageQueue.d.ts.map +1 -1
- package/dist/managers/messageQueue.js +53 -1
- package/dist/managers/pluginManager.d.ts.map +1 -1
- package/dist/managers/pluginManager.js +7 -1
- package/dist/managers/skillManager.d.ts +2 -0
- package/dist/managers/skillManager.d.ts.map +1 -1
- package/dist/managers/skillManager.js +19 -9
- package/dist/managers/slashCommandManager.d.ts +6 -0
- package/dist/managers/slashCommandManager.d.ts.map +1 -1
- package/dist/managers/slashCommandManager.js +105 -0
- package/dist/managers/toolManager.d.ts.map +1 -1
- package/dist/managers/toolManager.js +5 -0
- package/dist/managers/workflowManager.d.ts +65 -0
- package/dist/managers/workflowManager.d.ts.map +1 -0
- package/dist/managers/workflowManager.js +380 -0
- package/dist/prompts/index.d.ts +2 -1
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +3 -3
- package/dist/services/MarketplaceService.d.ts +2 -2
- package/dist/services/MarketplaceService.d.ts.map +1 -1
- package/dist/services/MarketplaceService.js +11 -32
- package/dist/services/aiService.d.ts +23 -0
- package/dist/services/aiService.d.ts.map +1 -1
- package/dist/services/aiService.js +102 -9
- package/dist/services/configurationService.d.ts +1 -1
- package/dist/services/configurationService.d.ts.map +1 -1
- package/dist/services/configurationService.js +3 -16
- package/dist/services/hook.d.ts.map +1 -1
- package/dist/services/hook.js +4 -0
- package/dist/services/session.d.ts +9 -1
- package/dist/services/session.d.ts.map +1 -1
- package/dist/services/session.js +28 -1
- package/dist/tools/bashTool.d.ts.map +1 -1
- package/dist/tools/bashTool.js +49 -7
- package/dist/tools/readTool.d.ts.map +1 -1
- package/dist/tools/readTool.js +1 -1
- package/dist/tools/taskManagementTools.d.ts.map +1 -1
- package/dist/tools/taskManagementTools.js +103 -157
- package/dist/tools/types.d.ts +2 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/webFetchTool.d.ts.map +1 -1
- package/dist/tools/webFetchTool.js +0 -9
- package/dist/tools/workflowTool.d.ts +11 -0
- package/dist/tools/workflowTool.d.ts.map +1 -0
- package/dist/tools/workflowTool.js +190 -0
- package/dist/types/agent.d.ts +2 -0
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/commands.d.ts +4 -0
- package/dist/types/commands.d.ts.map +1 -1
- package/dist/types/config.d.ts +2 -2
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/core.d.ts +1 -1
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/hooks.d.ts +2 -0
- package/dist/types/hooks.d.ts.map +1 -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 -2
- package/dist/types/messaging.d.ts.map +1 -1
- package/dist/types/processes.d.ts +6 -2
- package/dist/types/processes.d.ts.map +1 -1
- package/dist/types/workflow.d.ts +2 -0
- package/dist/types/workflow.d.ts.map +1 -0
- package/dist/types/workflow.js +1 -0
- package/dist/utils/cacheControlUtils.d.ts +13 -8
- package/dist/utils/cacheControlUtils.d.ts.map +1 -1
- package/dist/utils/cacheControlUtils.js +73 -102
- package/dist/utils/containerSetup.d.ts.map +1 -1
- package/dist/utils/containerSetup.js +7 -0
- package/dist/utils/markdownParser.d.ts.map +1 -1
- package/dist/utils/markdownParser.js +21 -6
- package/dist/utils/messageOperations.d.ts +2 -2
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/notificationXml.d.ts.map +1 -1
- package/dist/workflow/budgetTracker.d.ts +12 -0
- package/dist/workflow/budgetTracker.d.ts.map +1 -0
- package/dist/workflow/budgetTracker.js +30 -0
- package/dist/workflow/concurrencyLimiter.d.ts +14 -0
- package/dist/workflow/concurrencyLimiter.d.ts.map +1 -0
- package/dist/workflow/concurrencyLimiter.js +39 -0
- package/dist/workflow/journal.d.ts +19 -0
- package/dist/workflow/journal.d.ts.map +1 -0
- package/dist/workflow/journal.js +74 -0
- package/dist/workflow/progressReporter.d.ts +21 -0
- package/dist/workflow/progressReporter.d.ts.map +1 -0
- package/dist/workflow/progressReporter.js +118 -0
- package/dist/workflow/runState.d.ts +16 -0
- package/dist/workflow/runState.d.ts.map +1 -0
- package/dist/workflow/runState.js +57 -0
- package/dist/workflow/scriptRuntime.d.ts +35 -0
- package/dist/workflow/scriptRuntime.d.ts.map +1 -0
- package/dist/workflow/scriptRuntime.js +196 -0
- package/dist/workflow/structuredOutput.d.ts +27 -0
- package/dist/workflow/structuredOutput.d.ts.map +1 -0
- package/dist/workflow/structuredOutput.js +106 -0
- package/dist/workflow/types.d.ts +81 -0
- package/dist/workflow/types.d.ts.map +1 -0
- package/dist/workflow/types.js +1 -0
- package/dist/workflow/workflowApis.d.ts +46 -0
- package/dist/workflow/workflowApis.d.ts.map +1 -0
- package/dist/workflow/workflowApis.js +280 -0
- package/package.json +1 -1
- package/src/agent.ts +144 -34
- package/src/constants/goalPrompts.ts +10 -0
- package/src/constants/tools.ts +1 -0
- package/src/managers/aiManager.ts +91 -47
- package/src/managers/backgroundTaskManager.ts +16 -4
- package/src/managers/goalManager.ts +232 -0
- package/src/managers/messageManager.ts +2 -2
- package/src/managers/messageQueue.ts +59 -1
- package/src/managers/pluginManager.ts +8 -1
- package/src/managers/skillManager.ts +20 -9
- package/src/managers/slashCommandManager.ts +119 -0
- package/src/managers/toolManager.ts +7 -0
- package/src/managers/workflowManager.ts +491 -0
- package/src/prompts/index.ts +4 -2
- package/src/services/MarketplaceService.ts +14 -38
- package/src/services/aiService.ts +166 -12
- package/src/services/configurationService.ts +2 -22
- package/src/services/hook.ts +5 -0
- package/src/services/session.ts +42 -2
- package/src/tools/bashTool.ts +64 -9
- package/src/tools/readTool.ts +1 -2
- package/src/tools/taskManagementTools.ts +146 -195
- package/src/tools/types.ts +2 -0
- package/src/tools/webFetchTool.ts +0 -12
- package/src/tools/workflowTool.ts +205 -0
- package/src/types/agent.ts +6 -0
- package/src/types/commands.ts +4 -0
- package/src/types/config.ts +2 -2
- package/src/types/core.ts +3 -3
- package/src/types/hooks.ts +2 -0
- package/src/types/index.ts +1 -0
- package/src/types/messaging.ts +2 -2
- package/src/types/processes.ts +10 -2
- package/src/types/workflow.ts +5 -0
- package/src/utils/cacheControlUtils.ts +106 -131
- package/src/utils/containerSetup.ts +9 -0
- package/src/utils/markdownParser.ts +26 -8
- package/src/utils/messageOperations.ts +2 -2
- package/src/utils/notificationXml.ts +6 -1
- package/src/workflow/budgetTracker.ts +34 -0
- package/src/workflow/concurrencyLimiter.ts +47 -0
- package/src/workflow/journal.ts +95 -0
- package/src/workflow/progressReporter.ts +141 -0
- package/src/workflow/runState.ts +65 -0
- package/src/workflow/scriptRuntime.ts +274 -0
- package/src/workflow/structuredOutput.ts +123 -0
- package/src/workflow/types.ts +95 -0
- package/src/workflow/workflowApis.ts +412 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { randomUUID } from "crypto";
|
|
2
|
+
import * as os from "os";
|
|
3
|
+
import * as fs from "fs";
|
|
4
|
+
import * as path from "path";
|
|
5
|
+
import { taskNotificationToXml } from "../utils/notificationXml.js";
|
|
6
|
+
import { ConcurrencyLimiter } from "../workflow/concurrencyLimiter.js";
|
|
7
|
+
import { BudgetTracker } from "../workflow/budgetTracker.js";
|
|
8
|
+
import { ProgressReporter } from "../workflow/progressReporter.js";
|
|
9
|
+
import { Journal } from "../workflow/journal.js";
|
|
10
|
+
import { createWorkflowApis } from "../workflow/workflowApis.js";
|
|
11
|
+
import { validateScript, parseScript, executeScript, } from "../workflow/scriptRuntime.js";
|
|
12
|
+
import { RunStateStore } from "../workflow/runState.js";
|
|
13
|
+
import { logger } from "../utils/globalLogger.js";
|
|
14
|
+
const DEFAULT_CONCURRENCY = () => Math.max(1, Math.min(16, os.cpus().length - 2));
|
|
15
|
+
export class WorkflowManager {
|
|
16
|
+
constructor(container) {
|
|
17
|
+
this.runs = new Map();
|
|
18
|
+
this.abortControllers = new Map();
|
|
19
|
+
this.agentControllers = new Map();
|
|
20
|
+
this.runStateStore = null;
|
|
21
|
+
this.container = container;
|
|
22
|
+
// Initialize RunStateStore lazily (sessionDir depends on MessageManager)
|
|
23
|
+
}
|
|
24
|
+
get stateStore() {
|
|
25
|
+
if (!this.runStateStore) {
|
|
26
|
+
this.runStateStore = new RunStateStore(path.join(this.sessionDir, "workflows"));
|
|
27
|
+
}
|
|
28
|
+
return this.runStateStore;
|
|
29
|
+
}
|
|
30
|
+
get backgroundTaskManager() {
|
|
31
|
+
return this.container.get("BackgroundTaskManager");
|
|
32
|
+
}
|
|
33
|
+
get notificationQueue() {
|
|
34
|
+
return this.container.get("NotificationQueue");
|
|
35
|
+
}
|
|
36
|
+
get subagentManager() {
|
|
37
|
+
return this.container.get("SubagentManager");
|
|
38
|
+
}
|
|
39
|
+
get workdir() {
|
|
40
|
+
return this.container.get("workdir") || process.cwd();
|
|
41
|
+
}
|
|
42
|
+
get sessionDir() {
|
|
43
|
+
const messageManager = this.container.get("MessageManager");
|
|
44
|
+
return (messageManager?.getSessionDir() ||
|
|
45
|
+
path.join(os.homedir(), ".wave", "sessions"));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a new workflow run from a script string or file path.
|
|
49
|
+
* Persists the script to the session directory.
|
|
50
|
+
*/
|
|
51
|
+
async createRun(script, args, opts) {
|
|
52
|
+
// Validate script
|
|
53
|
+
const validation = validateScript(script);
|
|
54
|
+
if (!validation.valid) {
|
|
55
|
+
throw new Error(`Script validation failed:\n${validation.errors.join("\n")}`);
|
|
56
|
+
}
|
|
57
|
+
// Parse meta for the run object
|
|
58
|
+
const { meta } = parseScript(script);
|
|
59
|
+
// Validate resumeFromRunId if provided
|
|
60
|
+
if (opts?.resumeFromRunId) {
|
|
61
|
+
const prevRun = this.runs.get(opts.resumeFromRunId);
|
|
62
|
+
if (!prevRun) {
|
|
63
|
+
throw new Error(`Cannot resume: run ${opts.resumeFromRunId} not found`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Generate run ID and persist script
|
|
67
|
+
const runId = `wf_${randomUUID().slice(0, 8)}`;
|
|
68
|
+
const runDir = path.join(this.sessionDir, "workflows", runId);
|
|
69
|
+
await fs.promises.mkdir(path.join(runDir, "agents"), { recursive: true });
|
|
70
|
+
const scriptPath = path.join(runDir, "script.js");
|
|
71
|
+
await fs.promises.writeFile(scriptPath, script, "utf-8");
|
|
72
|
+
const run = {
|
|
73
|
+
runId,
|
|
74
|
+
meta,
|
|
75
|
+
status: "running",
|
|
76
|
+
scriptPath,
|
|
77
|
+
args,
|
|
78
|
+
startTime: Date.now(),
|
|
79
|
+
phases: [],
|
|
80
|
+
totalAgents: 0,
|
|
81
|
+
totalTokens: 0,
|
|
82
|
+
resumeFromRunId: opts?.resumeFromRunId,
|
|
83
|
+
};
|
|
84
|
+
this.runs.set(runId, run);
|
|
85
|
+
// Persist run state
|
|
86
|
+
this.stateStore.save(run).catch((err) => {
|
|
87
|
+
logger.warn(`[Workflow] Failed to persist run state: ${err instanceof Error ? err.message : String(err)}`);
|
|
88
|
+
});
|
|
89
|
+
return run;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Start executing a workflow run in the background.
|
|
93
|
+
* Returns immediately; the workflow runs asynchronously.
|
|
94
|
+
*/
|
|
95
|
+
async startRun(runId, opts) {
|
|
96
|
+
const run = this.runs.get(runId);
|
|
97
|
+
if (!run)
|
|
98
|
+
throw new Error(`Workflow run ${runId} not found`);
|
|
99
|
+
if (run.status !== "running")
|
|
100
|
+
throw new Error(`Workflow run ${runId} is not in running state`);
|
|
101
|
+
const abortController = new AbortController();
|
|
102
|
+
this.abortControllers.set(runId, abortController);
|
|
103
|
+
const runAgentControllers = new Map();
|
|
104
|
+
this.agentControllers.set(runId, runAgentControllers);
|
|
105
|
+
// Read script from file
|
|
106
|
+
const script = await fs.promises.readFile(run.scriptPath, "utf-8");
|
|
107
|
+
// Set up infrastructure
|
|
108
|
+
const concurrencyLimiter = new ConcurrencyLimiter(DEFAULT_CONCURRENCY());
|
|
109
|
+
const budgetTracker = new BudgetTracker(run.args &&
|
|
110
|
+
typeof run.args === "object" &&
|
|
111
|
+
"budget" in run.args
|
|
112
|
+
? run.args.budget
|
|
113
|
+
: null);
|
|
114
|
+
const progressReporter = new ProgressReporter(run.meta, runId);
|
|
115
|
+
// Forward progress events via onProgress callback
|
|
116
|
+
const onProgress = (event) => {
|
|
117
|
+
logger.debug(`[Workflow:${runId}] progress: ${event.type} phase=${event.phaseIndex} agent=${event.agentIndex}`);
|
|
118
|
+
};
|
|
119
|
+
progressReporter.onEvent(onProgress);
|
|
120
|
+
// Journal — load previous journal if resuming
|
|
121
|
+
let journal;
|
|
122
|
+
let initialAgentCount = 0;
|
|
123
|
+
if (run.resumeFromRunId || opts?.retryAgentIndex !== undefined) {
|
|
124
|
+
// Try new-format path first, fall back to old format
|
|
125
|
+
const sourceRunId = run.resumeFromRunId || runId;
|
|
126
|
+
const newJournalPath = path.join(this.sessionDir, "workflows", sourceRunId, "journal.jsonl");
|
|
127
|
+
const oldJournalPath = path.join(this.sessionDir, "workflows", `journal-${sourceRunId}.jsonl`);
|
|
128
|
+
const journalPath = (await fs.promises
|
|
129
|
+
.access(newJournalPath)
|
|
130
|
+
.then(() => true)
|
|
131
|
+
.catch(() => false))
|
|
132
|
+
? newJournalPath
|
|
133
|
+
: oldJournalPath;
|
|
134
|
+
journal = await Journal.load(journalPath);
|
|
135
|
+
// When retrying a specific agent, remove its failed entry
|
|
136
|
+
if (opts?.retryAgentIndex !== undefined) {
|
|
137
|
+
journal.removeFailedEntry(opts.retryAgentIndex);
|
|
138
|
+
}
|
|
139
|
+
// Count existing agent entries to offset the counter
|
|
140
|
+
initialAgentCount = journal.agentEntryCount;
|
|
141
|
+
// Re-open for appending (load() doesn't open the write stream)
|
|
142
|
+
await journal.init();
|
|
143
|
+
logger.info(`[Workflow] Resuming from ${sourceRunId} with ${initialAgentCount} cached agent results`);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
const journalPath = path.join(this.sessionDir, "workflows", runId, "journal.jsonl");
|
|
147
|
+
journal = new Journal(journalPath);
|
|
148
|
+
await journal.init();
|
|
149
|
+
}
|
|
150
|
+
// Register as background task
|
|
151
|
+
const taskId = this.backgroundTaskManager.generateId();
|
|
152
|
+
this.backgroundTaskManager.addTask({
|
|
153
|
+
id: taskId,
|
|
154
|
+
type: "workflow",
|
|
155
|
+
status: "running",
|
|
156
|
+
startTime: Date.now(),
|
|
157
|
+
stdout: "",
|
|
158
|
+
stderr: "",
|
|
159
|
+
description: `Workflow: ${run.meta.name}`,
|
|
160
|
+
runId,
|
|
161
|
+
onStop: () => {
|
|
162
|
+
abortController.abort();
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
// Create workflow APIs
|
|
166
|
+
const apis = createWorkflowApis({
|
|
167
|
+
subagentManager: this.subagentManager,
|
|
168
|
+
concurrencyLimiter,
|
|
169
|
+
budgetTracker,
|
|
170
|
+
progressReporter,
|
|
171
|
+
journal,
|
|
172
|
+
abortSignal: abortController.signal,
|
|
173
|
+
args: run.args,
|
|
174
|
+
initialAgentCount,
|
|
175
|
+
sessionDir: this.sessionDir,
|
|
176
|
+
runDir: path.join(this.sessionDir, "workflows", runId),
|
|
177
|
+
agentControllers: runAgentControllers,
|
|
178
|
+
onProgress: (event) => {
|
|
179
|
+
logger.debug(`[Workflow:${runId}] progress: ${event.type} phase=${event.phaseIndex} agent=${event.agentIndex}`);
|
|
180
|
+
},
|
|
181
|
+
onLog: (message) => {
|
|
182
|
+
logger.info(`[Workflow:${runId}] ${message}`);
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
// Execute in background
|
|
186
|
+
run.completionPromise = (async () => {
|
|
187
|
+
try {
|
|
188
|
+
const { result } = await executeScript(script, apis, abortController.signal);
|
|
189
|
+
// Update run state
|
|
190
|
+
run.status = "completed";
|
|
191
|
+
run.endTime = Date.now();
|
|
192
|
+
run.result = result;
|
|
193
|
+
run.phases = progressReporter.getPhaseStates();
|
|
194
|
+
run.totalAgents = progressReporter.totalAgents;
|
|
195
|
+
run.totalTokens = progressReporter.totalTokens;
|
|
196
|
+
// Persist final state
|
|
197
|
+
this.stateStore.save(run).catch(() => { });
|
|
198
|
+
// Close journal
|
|
199
|
+
await journal.close();
|
|
200
|
+
// Update background task status
|
|
201
|
+
const task = this.backgroundTaskManager.getTask(taskId);
|
|
202
|
+
if (task) {
|
|
203
|
+
task.status = "completed";
|
|
204
|
+
task.endTime = Date.now();
|
|
205
|
+
}
|
|
206
|
+
// Enqueue completion notification
|
|
207
|
+
const journalPath = journal.filePath;
|
|
208
|
+
this.notificationQueue.enqueue(taskNotificationToXml({
|
|
209
|
+
type: "task_notification",
|
|
210
|
+
taskId: runId,
|
|
211
|
+
taskType: "workflow",
|
|
212
|
+
status: "completed",
|
|
213
|
+
summary: `Workflow "${run.meta.name}" completed — ${run.totalAgents} agents, ${(run.totalTokens / 1000).toFixed(1)}k tokens`,
|
|
214
|
+
...(journalPath && { outputFile: journalPath }),
|
|
215
|
+
}));
|
|
216
|
+
logger.info(`[Workflow] Run ${runId} completed: ${run.totalAgents} agents, ${run.totalTokens} tokens`);
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
// Only update if stopRun hasn't already set the status
|
|
220
|
+
if (run.status === "running") {
|
|
221
|
+
if (abortController.signal.aborted) {
|
|
222
|
+
run.status = "aborted";
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
run.status = "failed";
|
|
226
|
+
run.error = error instanceof Error ? error.message : String(error);
|
|
227
|
+
}
|
|
228
|
+
run.endTime = Date.now();
|
|
229
|
+
}
|
|
230
|
+
run.phases = progressReporter.getPhaseStates();
|
|
231
|
+
run.totalAgents = progressReporter.totalAgents;
|
|
232
|
+
run.totalTokens = progressReporter.totalTokens;
|
|
233
|
+
// Persist failure/abort state
|
|
234
|
+
this.stateStore.save(run).catch(() => { });
|
|
235
|
+
await journal.close();
|
|
236
|
+
// Update background task status
|
|
237
|
+
const task = this.backgroundTaskManager.getTask(taskId);
|
|
238
|
+
if (task) {
|
|
239
|
+
task.status = abortController.signal.aborted ? "killed" : "failed";
|
|
240
|
+
task.stderr = run.error || "";
|
|
241
|
+
task.endTime = Date.now();
|
|
242
|
+
}
|
|
243
|
+
this.notificationQueue.enqueue(taskNotificationToXml({
|
|
244
|
+
type: "task_notification",
|
|
245
|
+
taskId: runId,
|
|
246
|
+
taskType: "workflow",
|
|
247
|
+
status: run.status === "aborted" ? "aborted" : "failed",
|
|
248
|
+
summary: `Workflow "${run.meta.name}" ${run.status}${run.error ? `: ${run.error}` : ""}`,
|
|
249
|
+
}));
|
|
250
|
+
logger.warn(`[Workflow] Run ${runId} ${run.status}: ${run.error || "aborted"}`);
|
|
251
|
+
}
|
|
252
|
+
finally {
|
|
253
|
+
this.abortControllers.delete(runId);
|
|
254
|
+
this.agentControllers.delete(runId);
|
|
255
|
+
}
|
|
256
|
+
})();
|
|
257
|
+
// Don't await — let it run in background
|
|
258
|
+
run.completionPromise.catch(() => { }); // Prevent unhandled rejection
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Resume a workflow run from its journal.
|
|
262
|
+
*/
|
|
263
|
+
async resumeRun(runId) {
|
|
264
|
+
const run = this.runs.get(runId);
|
|
265
|
+
if (!run)
|
|
266
|
+
throw new Error(`Workflow run ${runId} not found`);
|
|
267
|
+
run.status = "running";
|
|
268
|
+
await this.startRun(runId);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Stop a running workflow.
|
|
272
|
+
*/
|
|
273
|
+
stopRun(runId) {
|
|
274
|
+
const controller = this.abortControllers.get(runId);
|
|
275
|
+
if (controller) {
|
|
276
|
+
controller.abort();
|
|
277
|
+
}
|
|
278
|
+
const run = this.runs.get(runId);
|
|
279
|
+
if (run && run.status === "running") {
|
|
280
|
+
run.status = "aborted";
|
|
281
|
+
run.endTime = Date.now();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Skip a specific agent in a running workflow.
|
|
286
|
+
* Aborts the agent's controller and lets the workflow continue.
|
|
287
|
+
*/
|
|
288
|
+
skipAgent(runId, agentIndex) {
|
|
289
|
+
const run = this.runs.get(runId);
|
|
290
|
+
if (!run || run.status !== "running")
|
|
291
|
+
return;
|
|
292
|
+
const agentController = this.agentControllers.get(runId)?.get(agentIndex);
|
|
293
|
+
if (agentController) {
|
|
294
|
+
agentController.abort();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Retry a specific agent by removing its journal entry and resuming.
|
|
299
|
+
*/
|
|
300
|
+
async retryAgent(runId, agentIndex) {
|
|
301
|
+
const run = this.runs.get(runId);
|
|
302
|
+
if (!run)
|
|
303
|
+
throw new Error(`Workflow run ${runId} not found`);
|
|
304
|
+
// Stop the current execution
|
|
305
|
+
this.stopRun(runId);
|
|
306
|
+
// The journal will have cached results; when we resume,
|
|
307
|
+
// the agent_failed entry for this index will cause getCachedResult
|
|
308
|
+
// to return undefined, forcing re-execution
|
|
309
|
+
run.status = "running";
|
|
310
|
+
run.error = undefined;
|
|
311
|
+
run.failedAgentIndex = undefined;
|
|
312
|
+
run.failedAgentError = undefined;
|
|
313
|
+
await this.startRun(runId, { retryAgentIndex: agentIndex });
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Kill a running workflow — aborts all agent controllers plus the run controller.
|
|
317
|
+
*/
|
|
318
|
+
killRun(runId) {
|
|
319
|
+
// Abort all per-agent controllers
|
|
320
|
+
const agentControllers = this.agentControllers.get(runId);
|
|
321
|
+
if (agentControllers) {
|
|
322
|
+
for (const controller of agentControllers.values()) {
|
|
323
|
+
controller.abort();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
// Abort the run controller
|
|
327
|
+
const controller = this.abortControllers.get(runId);
|
|
328
|
+
if (controller) {
|
|
329
|
+
controller.abort();
|
|
330
|
+
}
|
|
331
|
+
const run = this.runs.get(runId);
|
|
332
|
+
if (run && run.status === "running") {
|
|
333
|
+
run.status = "aborted";
|
|
334
|
+
run.endTime = Date.now();
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* List all workflow runs (includes in-memory and persisted).
|
|
339
|
+
*/
|
|
340
|
+
async listRuns() {
|
|
341
|
+
// Load persisted runs that aren't already in memory
|
|
342
|
+
const persistedIds = await this.stateStore.listRuns();
|
|
343
|
+
for (const runId of persistedIds) {
|
|
344
|
+
if (!this.runs.has(runId)) {
|
|
345
|
+
const run = await this.stateStore.load(runId);
|
|
346
|
+
if (run) {
|
|
347
|
+
this.runs.set(runId, run);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return Array.from(this.runs.values());
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Get a specific workflow run.
|
|
355
|
+
*/
|
|
356
|
+
getRun(runId) {
|
|
357
|
+
return this.runs.get(runId);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Clean up all running workflows.
|
|
361
|
+
*/
|
|
362
|
+
cleanup() {
|
|
363
|
+
for (const controller of this.abortControllers.values()) {
|
|
364
|
+
controller.abort();
|
|
365
|
+
}
|
|
366
|
+
this.abortControllers.clear();
|
|
367
|
+
for (const agentMap of this.agentControllers.values()) {
|
|
368
|
+
for (const controller of agentMap.values()) {
|
|
369
|
+
controller.abort();
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
this.agentControllers.clear();
|
|
373
|
+
for (const run of this.runs.values()) {
|
|
374
|
+
if (run.status === "running") {
|
|
375
|
+
run.status = "aborted";
|
|
376
|
+
run.endTime = Date.now();
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
package/dist/prompts/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare const WEB_CONTENT_SYSTEM_PROMPT = "You are a helpful assistant th
|
|
|
16
16
|
export declare const BTW_SYSTEM_PROMPT = "You are a helpful assistant. Answer the user's side question based on the conversation history. \nDo NOT say things like \"Let me try...\", \"I'll now...\", \"Let me check...\", or promise to take any action. \nIf you don't know the answer, say so - do not offer to look it up or investigate. \nSimply answer the question with the information you have.";
|
|
17
17
|
export declare function buildSystemPrompt(basePrompt: string | undefined, tools: ToolPlugin[], options?: {
|
|
18
18
|
workdir?: string;
|
|
19
|
+
originalWorkdir?: string;
|
|
19
20
|
memory?: string;
|
|
20
21
|
language?: string;
|
|
21
22
|
isSubagent?: boolean;
|
|
@@ -25,5 +26,5 @@ export declare function buildSystemPrompt(basePrompt: string | undefined, tools:
|
|
|
25
26
|
};
|
|
26
27
|
permissionMode?: PermissionMode;
|
|
27
28
|
}): string;
|
|
28
|
-
export declare function enhanceSystemPromptWithEnvDetails(existingSystemPrompt: string, workdir: string): string;
|
|
29
|
+
export declare function enhanceSystemPromptWithEnvDetails(existingSystemPrompt: string, workdir: string, originalWorkdir?: string): string;
|
|
29
30
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prompts/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAiBzD,eAAO,MAAM,kBAAkB,oKAAoK,CAAC;AAEpM,eAAO,MAAM,kBAAkB,opIAcqQ,CAAC;AAErS,eAAO,MAAM,wBAAwB,25DASqmB,CAAC;AAE3oB,eAAO,MAAM,WAAW,ihDAWqH,CAAC;AAE9I;;GAEG;AACH,eAAO,MAAM,wBAAwB,+uBAWiH,CAAC;AAEvJ,eAAO,MAAM,qBAAqB,6sBAMuL,CAAC;AAE1N,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,OAAO,EACnB,UAAU,GAAE,OAAe,GAC1B,MAAM,CAmFR;AAED,eAAO,MAAM,qBAAqB,oKAAqB,CAAC;AAExD,eAAO,MAAM,8BAA8B,44DA8CI,CAAC;AAEhD,eAAO,MAAM,yBAAyB,wHAAwH,CAAC;AAC/J,eAAO,MAAM,iBAAiB,qWAG4B,CAAC;AAE3D,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,KAAK,EAAE,UAAU,EAAE,EACnB,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE;QACX,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,cAAc,CAAC,EAAE,cAAc,CAAC;CAC5B,GACL,MAAM,CA4DR;AAED,wB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MAAM,CA4DR;AAED,wBAAgB,iCAAiC,CAC/C,oBAAoB,EAAE,MAAM,EAC5B,OAAO,EAAE,MAAM,EACf,eAAe,CAAC,EAAE,MAAM,GACvB,MAAM,CAkCR"}
|
package/dist/prompts/index.js
CHANGED
|
@@ -230,7 +230,7 @@ export function buildSystemPrompt(basePrompt, tools, options = {}) {
|
|
|
230
230
|
|
|
231
231
|
Here is useful information about the environment you are running in:
|
|
232
232
|
<env>
|
|
233
|
-
|
|
233
|
+
Primary working directory: ${options.originalWorkdir ?? options.workdir}${worktreeSession ? `\nThis is a git worktree — an isolated copy of the repository. Run all commands from this directory. Do NOT \`cd\` to the original repository root at ${worktreeSession.originalCwd}.` : ""}
|
|
234
234
|
Is directory a git repo: ${isGitRepo}
|
|
235
235
|
Platform: ${platform}
|
|
236
236
|
Shell: ${shellName}
|
|
@@ -250,7 +250,7 @@ Today's date: ${today}
|
|
|
250
250
|
}
|
|
251
251
|
return prompt;
|
|
252
252
|
}
|
|
253
|
-
export function enhanceSystemPromptWithEnvDetails(existingSystemPrompt, workdir) {
|
|
253
|
+
export function enhanceSystemPromptWithEnvDetails(existingSystemPrompt, workdir, originalWorkdir) {
|
|
254
254
|
const isGitRepo = isGitRepository(workdir);
|
|
255
255
|
const platform = os.platform();
|
|
256
256
|
const osVersion = `${os.type()} ${os.release()}`;
|
|
@@ -273,7 +273,7 @@ ${notes}
|
|
|
273
273
|
|
|
274
274
|
Here is useful information about the environment you are running in:
|
|
275
275
|
<env>
|
|
276
|
-
|
|
276
|
+
Primary working directory: ${originalWorkdir ?? workdir}${worktreeSession ? `\nThis is a git worktree — an isolated copy of the repository. Run all commands from this directory. Do NOT \`cd\` to the original repository root at ${worktreeSession.originalCwd}.` : ""}
|
|
277
277
|
Is directory a git repo: ${isGitRepo}
|
|
278
278
|
Platform: ${platform}
|
|
279
279
|
Shell: ${shellName}
|
|
@@ -49,7 +49,7 @@ export declare class MarketplaceService {
|
|
|
49
49
|
*/
|
|
50
50
|
getCacheRegistry(): Promise<KnownMarketplacesRegistry | null>;
|
|
51
51
|
/**
|
|
52
|
-
* Legacy method: loads known marketplaces
|
|
52
|
+
* Legacy method: loads known marketplaces from cache.
|
|
53
53
|
* @deprecated Use listMarketplaces() instead, which combines scoped settings.
|
|
54
54
|
*/
|
|
55
55
|
getKnownMarketplaces(): Promise<KnownMarketplacesRegistry>;
|
|
@@ -90,7 +90,7 @@ export declare class MarketplaceService {
|
|
|
90
90
|
*/
|
|
91
91
|
addMarketplace(input: string, scope?: Scope): Promise<KnownMarketplace>;
|
|
92
92
|
/**
|
|
93
|
-
* Lists all registered marketplaces by combining scoped settings +
|
|
93
|
+
* Lists all registered marketplaces by combining scoped settings + cache
|
|
94
94
|
*/
|
|
95
95
|
listMarketplaces(): Promise<KnownMarketplace[]>;
|
|
96
96
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarketplaceService.d.ts","sourceRoot":"","sources":["../../src/services/MarketplaceService.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,eAAe,EACf,wBAAwB,EACxB,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,KAAK,EAAqB,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAG1E;;;;;;;;GAQG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAS;IACzC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,oBAAoB,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,oBAAoB,CAAuB;IACnD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AuBpC;;OAEG;IACG,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BrE;;OAEG;IACG,aAAa,CACjB,mBAAmB,EAAE,MAAM,EAC3B,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,eAAe,CAAC;IA8H3B;;OAEG;IACG,eAAe,CACnB,mBAAmB,EAAE,MAAM,EAC3B,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;IAoChB;;OAEG;IACG,YAAY,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;CAM1E"}
|
|
@@ -155,30 +155,19 @@ export class MarketplaceService {
|
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
/**
|
|
158
|
-
* Legacy method: loads known marketplaces
|
|
158
|
+
* Legacy method: loads known marketplaces from cache.
|
|
159
159
|
* @deprecated Use listMarketplaces() instead, which combines scoped settings.
|
|
160
160
|
*/
|
|
161
161
|
async getKnownMarketplaces() {
|
|
162
162
|
const cache = await this.getCacheRegistry();
|
|
163
|
-
// If cache is null (file doesn't exist or has no parseable content), inject builtin
|
|
164
163
|
if (cache === null) {
|
|
165
|
-
return {
|
|
166
|
-
marketplaces: [
|
|
167
|
-
{
|
|
168
|
-
...MarketplaceService.BUILTIN_MARKETPLACE,
|
|
169
|
-
isBuiltin: true,
|
|
170
|
-
declaredScope: "builtin",
|
|
171
|
-
},
|
|
172
|
-
],
|
|
173
|
-
};
|
|
164
|
+
return { marketplaces: [] };
|
|
174
165
|
}
|
|
175
|
-
// File has valid JSON - respect user's explicit choice even if empty
|
|
176
|
-
const hasBuiltin = cache.marketplaces.some((m) => m.name === MarketplaceService.BUILTIN_MARKETPLACE.name);
|
|
177
166
|
return {
|
|
178
167
|
marketplaces: cache.marketplaces.map((m) => ({
|
|
179
168
|
...m,
|
|
180
169
|
isBuiltin: m.isBuiltin || m.name === MarketplaceService.BUILTIN_MARKETPLACE.name,
|
|
181
|
-
declaredScope: m.declaredScope ??
|
|
170
|
+
declaredScope: m.declaredScope ?? "user",
|
|
182
171
|
})),
|
|
183
172
|
};
|
|
184
173
|
}
|
|
@@ -293,14 +282,14 @@ export class MarketplaceService {
|
|
|
293
282
|
* Finds which scope declared a marketplace (user, project, local, or builtin)
|
|
294
283
|
*/
|
|
295
284
|
getMarketplaceDeclaringSource(name) {
|
|
296
|
-
if (name === MarketplaceService.BUILTIN_MARKETPLACE.name)
|
|
297
|
-
return "builtin";
|
|
298
285
|
const scopes = ["local", "project", "user"];
|
|
299
286
|
for (const scope of scopes) {
|
|
300
287
|
const scoped = this.configurationService.getScopedMarketplaces(this.workdir, scope);
|
|
301
288
|
if (scoped[name])
|
|
302
289
|
return scope;
|
|
303
290
|
}
|
|
291
|
+
if (name === MarketplaceService.BUILTIN_MARKETPLACE.name)
|
|
292
|
+
return "builtin";
|
|
304
293
|
return null;
|
|
305
294
|
}
|
|
306
295
|
/**
|
|
@@ -381,37 +370,28 @@ export class MarketplaceService {
|
|
|
381
370
|
});
|
|
382
371
|
}
|
|
383
372
|
/**
|
|
384
|
-
* Lists all registered marketplaces by combining scoped settings +
|
|
373
|
+
* Lists all registered marketplaces by combining scoped settings + cache
|
|
385
374
|
*/
|
|
386
375
|
async listMarketplaces() {
|
|
387
376
|
const scopedMarketplaces = this.configurationService.getMergedMarketplaces(this.workdir);
|
|
388
377
|
const cacheRegistry = await this.getCacheRegistry();
|
|
389
378
|
const cacheMap = new Map((cacheRegistry?.marketplaces ?? []).map((m) => [m.name, m]));
|
|
390
379
|
const result = [];
|
|
391
|
-
// Add built-in marketplace
|
|
392
|
-
result.push({
|
|
393
|
-
...MarketplaceService.BUILTIN_MARKETPLACE,
|
|
394
|
-
isBuiltin: true,
|
|
395
|
-
declaredScope: "builtin",
|
|
396
|
-
});
|
|
397
380
|
// Add all scoped marketplaces (local overrides project overrides user)
|
|
398
381
|
for (const [name, config] of Object.entries(scopedMarketplaces)) {
|
|
399
|
-
if (name === MarketplaceService.BUILTIN_MARKETPLACE.name)
|
|
400
|
-
continue;
|
|
401
382
|
const cache = cacheMap.get(name);
|
|
402
383
|
const declaredScope = this.getMarketplaceDeclaringSource(name);
|
|
403
384
|
result.push(await this.buildMarketplaceEntry(name, config, cache, declaredScope));
|
|
404
385
|
}
|
|
405
386
|
// Add cache entries not yet in scoped settings (backwards compatibility)
|
|
406
387
|
for (const [name, cache] of cacheMap.entries()) {
|
|
407
|
-
if (name === MarketplaceService.BUILTIN_MARKETPLACE.name)
|
|
408
|
-
continue;
|
|
409
388
|
if (scopedMarketplaces[name])
|
|
410
389
|
continue;
|
|
390
|
+
const isBuiltin = name === MarketplaceService.BUILTIN_MARKETPLACE.name;
|
|
411
391
|
result.push({
|
|
412
392
|
...cache,
|
|
413
|
-
isBuiltin
|
|
414
|
-
declaredScope: cache.declaredScope ?? "user",
|
|
393
|
+
isBuiltin,
|
|
394
|
+
declaredScope: cache.declaredScope ?? (isBuiltin ? "builtin" : "user"),
|
|
415
395
|
});
|
|
416
396
|
}
|
|
417
397
|
return result;
|
|
@@ -422,10 +402,9 @@ export class MarketplaceService {
|
|
|
422
402
|
async removeMarketplace(name, scope) {
|
|
423
403
|
return this.withLock(async () => {
|
|
424
404
|
const targetScope = scope || this.getMarketplaceDeclaringSource(name) || "user";
|
|
425
|
-
if (targetScope
|
|
426
|
-
|
|
405
|
+
if (targetScope !== "builtin") {
|
|
406
|
+
await this.configurationService.removeMarketplaceFromScope(this.workdir, targetScope, name);
|
|
427
407
|
}
|
|
428
|
-
await this.configurationService.removeMarketplaceFromScope(this.workdir, targetScope, name);
|
|
429
408
|
// Also remove from cache
|
|
430
409
|
await this.removeFromCache(name);
|
|
431
410
|
});
|
|
@@ -17,6 +17,12 @@ export interface CallAgentOptions {
|
|
|
17
17
|
model?: string;
|
|
18
18
|
systemPrompt?: string;
|
|
19
19
|
maxTokens?: number;
|
|
20
|
+
toolChoice?: "auto" | "none" | "required" | {
|
|
21
|
+
type: "function";
|
|
22
|
+
function: {
|
|
23
|
+
name: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
20
26
|
onContentUpdate?: (content: string) => void;
|
|
21
27
|
onToolUpdate?: (toolCall: {
|
|
22
28
|
id: string;
|
|
@@ -88,4 +94,21 @@ export interface BtwResult {
|
|
|
88
94
|
};
|
|
89
95
|
}
|
|
90
96
|
export declare function btw(options: BtwOptions): Promise<BtwResult>;
|
|
97
|
+
export interface EvaluateGoalOptions {
|
|
98
|
+
gatewayConfig: GatewayConfig;
|
|
99
|
+
modelConfig: ModelConfig;
|
|
100
|
+
model: string;
|
|
101
|
+
goalCondition: string;
|
|
102
|
+
messages: ChatCompletionMessageParam[];
|
|
103
|
+
abortSignal?: AbortSignal;
|
|
104
|
+
}
|
|
105
|
+
export interface EvaluateGoalResult {
|
|
106
|
+
content: string;
|
|
107
|
+
usage?: {
|
|
108
|
+
prompt_tokens: number;
|
|
109
|
+
completion_tokens: number;
|
|
110
|
+
total_tokens: number;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export declare function evaluateGoal(options: EvaluateGoalOptions): Promise<EvaluateGoalResult>;
|
|
91
114
|
//# sourceMappingURL=aiService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiService.d.ts","sourceRoot":"","sources":["../../src/services/aiService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAGL,0BAA0B,EAC1B,0BAA0B,EAE3B,MAAM,qBAAqB,CAAC;AAI7B,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"aiService.d.ts","sourceRoot":"","sources":["../../src/services/aiService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAGL,0BAA0B,EAC1B,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