@nanocollective/nanocoder 1.22.5 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -30
- package/assets/nanocoder-vscode.vsix +0 -0
- package/dist/ai-sdk-client/chat/chat-handler.js +1 -1
- package/dist/ai-sdk-client/chat/chat-handler.js.map +1 -1
- package/dist/ai-sdk-client/chat/tool-processor.d.ts +1 -1
- package/dist/ai-sdk-client/chat/tool-processor.d.ts.map +1 -1
- package/dist/ai-sdk-client/chat/tool-processor.js +8 -3
- package/dist/ai-sdk-client/chat/tool-processor.js.map +1 -1
- package/dist/ai-sdk-client/error-handling/error-parser.d.ts.map +1 -1
- package/dist/ai-sdk-client/error-handling/error-parser.js +4 -1
- package/dist/ai-sdk-client/error-handling/error-parser.js.map +1 -1
- package/dist/app/App.d.ts.map +1 -1
- package/dist/app/App.js +106 -11
- package/dist/app/App.js.map +1 -1
- package/dist/app/components/chat-input.d.ts +6 -1
- package/dist/app/components/chat-input.d.ts.map +1 -1
- package/dist/app/components/chat-input.js +9 -7
- package/dist/app/components/chat-input.js.map +1 -1
- package/dist/app/utils/app-util.d.ts +5 -0
- package/dist/app/utils/app-util.d.ts.map +1 -1
- package/dist/app/utils/app-util.js +265 -0
- package/dist/app/utils/app-util.js.map +1 -1
- package/dist/client-factory.d.ts.map +1 -1
- package/dist/client-factory.js +3 -2
- package/dist/client-factory.js.map +1 -1
- package/dist/commands/context-max.d.ts +15 -0
- package/dist/commands/context-max.d.ts.map +1 -0
- package/dist/commands/context-max.js +22 -0
- package/dist/commands/context-max.js.map +1 -0
- package/dist/commands/custom-commands.d.ts.map +1 -1
- package/dist/commands/custom-commands.js +88 -4
- package/dist/commands/custom-commands.js.map +1 -1
- package/dist/commands/exit.d.ts.map +1 -1
- package/dist/commands/exit.js +5 -8
- package/dist/commands/exit.js.map +1 -1
- package/dist/commands/ide.d.ts +3 -0
- package/dist/commands/ide.d.ts.map +1 -0
- package/dist/commands/ide.js +10 -0
- package/dist/commands/ide.js.map +1 -0
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/schedule.d.ts +3 -0
- package/dist/commands/schedule.d.ts.map +1 -0
- package/dist/commands/schedule.js +177 -0
- package/dist/commands/schedule.js.map +1 -0
- package/dist/commands/usage.d.ts.map +1 -1
- package/dist/commands/usage.js +4 -3
- package/dist/commands/usage.js.map +1 -1
- package/dist/components/development-mode-indicator.d.ts +3 -2
- package/dist/components/development-mode-indicator.d.ts.map +1 -1
- package/dist/components/development-mode-indicator.js +23 -9
- package/dist/components/development-mode-indicator.js.map +1 -1
- package/dist/components/ide-selector.d.ts +7 -0
- package/dist/components/ide-selector.d.ts.map +1 -0
- package/dist/components/ide-selector.js +17 -0
- package/dist/components/ide-selector.js.map +1 -0
- package/dist/components/question-prompt.d.ts +8 -0
- package/dist/components/question-prompt.d.ts.map +1 -0
- package/dist/components/question-prompt.js +58 -0
- package/dist/components/question-prompt.js.map +1 -0
- package/dist/components/scheduler-view.d.ts +14 -0
- package/dist/components/scheduler-view.d.ts.map +1 -0
- package/dist/components/scheduler-view.js +17 -0
- package/dist/components/scheduler-view.js.map +1 -0
- package/dist/components/text-input.d.ts +13 -0
- package/dist/components/text-input.d.ts.map +1 -0
- package/dist/components/text-input.js +175 -0
- package/dist/components/text-input.js.map +1 -0
- package/dist/components/user-input.d.ts +2 -1
- package/dist/components/user-input.d.ts.map +1 -1
- package/dist/components/user-input.js +8 -15
- package/dist/components/user-input.js.map +1 -1
- package/dist/config/themes.d.ts.map +1 -1
- package/dist/config/themes.js +20 -0
- package/dist/config/themes.js.map +1 -1
- package/dist/custom-commands/command-integration.d.ts +24 -0
- package/dist/custom-commands/command-integration.d.ts.map +1 -0
- package/dist/custom-commands/command-integration.js +68 -0
- package/dist/custom-commands/command-integration.js.map +1 -0
- package/dist/custom-commands/executor.d.ts.map +1 -1
- package/dist/custom-commands/executor.js +12 -2
- package/dist/custom-commands/executor.js.map +1 -1
- package/dist/custom-commands/loader.d.ts +33 -5
- package/dist/custom-commands/loader.d.ts.map +1 -1
- package/dist/custom-commands/loader.js +191 -18
- package/dist/custom-commands/loader.js.map +1 -1
- package/dist/custom-commands/parser.d.ts.map +1 -1
- package/dist/custom-commands/parser.js +115 -48
- package/dist/custom-commands/parser.js.map +1 -1
- package/dist/hooks/chat-handler/conversation/conversation-loop.d.ts +1 -1
- package/dist/hooks/chat-handler/conversation/conversation-loop.d.ts.map +1 -1
- package/dist/hooks/chat-handler/conversation/conversation-loop.js +37 -5
- package/dist/hooks/chat-handler/conversation/conversation-loop.js.map +1 -1
- package/dist/hooks/chat-handler/types.d.ts +3 -1
- package/dist/hooks/chat-handler/types.d.ts.map +1 -1
- package/dist/hooks/chat-handler/useChatHandler.d.ts +1 -1
- package/dist/hooks/chat-handler/useChatHandler.d.ts.map +1 -1
- package/dist/hooks/chat-handler/useChatHandler.js +13 -5
- package/dist/hooks/chat-handler/useChatHandler.js.map +1 -1
- package/dist/hooks/useAppHandlers.d.ts +2 -0
- package/dist/hooks/useAppHandlers.d.ts.map +1 -1
- package/dist/hooks/useAppHandlers.js +5 -0
- package/dist/hooks/useAppHandlers.js.map +1 -1
- package/dist/hooks/useAppInitialization.d.ts.map +1 -1
- package/dist/hooks/useAppInitialization.js +4 -1
- package/dist/hooks/useAppInitialization.js.map +1 -1
- package/dist/hooks/useAppState.d.ts +15 -0
- package/dist/hooks/useAppState.d.ts.map +1 -1
- package/dist/hooks/useAppState.js +23 -0
- package/dist/hooks/useAppState.js.map +1 -1
- package/dist/hooks/useContextPercentage.d.ts +17 -0
- package/dist/hooks/useContextPercentage.d.ts.map +1 -0
- package/dist/hooks/useContextPercentage.js +71 -0
- package/dist/hooks/useContextPercentage.js.map +1 -0
- package/dist/hooks/useModeHandlers.d.ts +4 -1
- package/dist/hooks/useModeHandlers.d.ts.map +1 -1
- package/dist/hooks/useModeHandlers.js +11 -1
- package/dist/hooks/useModeHandlers.js.map +1 -1
- package/dist/hooks/useNonInteractiveMode.d.ts.map +1 -1
- package/dist/hooks/useNonInteractiveMode.js +3 -1
- package/dist/hooks/useNonInteractiveMode.js.map +1 -1
- package/dist/hooks/useSchedulerMode.d.ts +30 -0
- package/dist/hooks/useSchedulerMode.d.ts.map +1 -0
- package/dist/hooks/useSchedulerMode.js +99 -0
- package/dist/hooks/useSchedulerMode.js.map +1 -0
- package/dist/lsp/lsp-manager.d.ts.map +1 -1
- package/dist/lsp/lsp-manager.js +10 -0
- package/dist/lsp/lsp-manager.js.map +1 -1
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js +20 -1
- package/dist/mcp/mcp-client.js.map +1 -1
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +1 -1
- package/dist/models/index.js.map +1 -1
- package/dist/models/models-dev-client.d.ts +8 -1
- package/dist/models/models-dev-client.d.ts.map +1 -1
- package/dist/models/models-dev-client.js +50 -1
- package/dist/models/models-dev-client.js.map +1 -1
- package/dist/schedule/cron.d.ts +14 -0
- package/dist/schedule/cron.d.ts.map +1 -0
- package/dist/schedule/cron.js +107 -0
- package/dist/schedule/cron.js.map +1 -0
- package/dist/schedule/index.d.ts +4 -0
- package/dist/schedule/index.d.ts.map +1 -0
- package/dist/schedule/index.js +4 -0
- package/dist/schedule/index.js.map +1 -0
- package/dist/schedule/runner.d.ts +42 -0
- package/dist/schedule/runner.d.ts.map +1 -0
- package/dist/schedule/runner.js +136 -0
- package/dist/schedule/runner.js.map +1 -0
- package/dist/schedule/storage.d.ts +9 -0
- package/dist/schedule/storage.d.ts.map +1 -0
- package/dist/schedule/storage.js +68 -0
- package/dist/schedule/storage.js.map +1 -0
- package/dist/schedule/types.d.ts +24 -0
- package/dist/schedule/types.d.ts.map +1 -0
- package/dist/schedule/types.js +2 -0
- package/dist/schedule/types.js.map +1 -0
- package/dist/services/bash-executor.d.ts.map +1 -1
- package/dist/services/bash-executor.js +5 -0
- package/dist/services/bash-executor.js.map +1 -1
- package/dist/tool-calling/json-parser.d.ts +7 -3
- package/dist/tool-calling/json-parser.d.ts.map +1 -1
- package/dist/tool-calling/json-parser.js +30 -13
- package/dist/tool-calling/json-parser.js.map +1 -1
- package/dist/tool-calling/tool-parser.d.ts +2 -2
- package/dist/tool-calling/tool-parser.d.ts.map +1 -1
- package/dist/tool-calling/tool-parser.js +27 -23
- package/dist/tool-calling/tool-parser.js.map +1 -1
- package/dist/tool-calling/xml-parser.d.ts +8 -4
- package/dist/tool-calling/xml-parser.d.ts.map +1 -1
- package/dist/tool-calling/xml-parser.js +15 -5
- package/dist/tool-calling/xml-parser.js.map +1 -1
- package/dist/tools/ask-question.d.ts +3 -0
- package/dist/tools/ask-question.d.ts.map +1 -0
- package/dist/tools/ask-question.js +66 -0
- package/dist/tools/ask-question.js.map +1 -0
- package/dist/tools/execute-bash.js +1 -1
- package/dist/tools/execute-bash.js.map +1 -1
- package/dist/tools/file-ops/copy-file.d.ts +3 -0
- package/dist/tools/file-ops/copy-file.d.ts.map +1 -0
- package/dist/tools/file-ops/copy-file.js +126 -0
- package/dist/tools/file-ops/copy-file.js.map +1 -0
- package/dist/tools/file-ops/create-directory.d.ts +3 -0
- package/dist/tools/file-ops/create-directory.d.ts.map +1 -0
- package/dist/tools/file-ops/create-directory.js +76 -0
- package/dist/tools/file-ops/create-directory.js.map +1 -0
- package/dist/tools/file-ops/delete-file.d.ts +3 -0
- package/dist/tools/file-ops/delete-file.d.ts.map +1 -0
- package/dist/tools/file-ops/delete-file.js +88 -0
- package/dist/tools/file-ops/delete-file.js.map +1 -0
- package/dist/tools/file-ops/index.d.ts +3 -0
- package/dist/tools/file-ops/index.d.ts.map +1 -0
- package/dist/tools/file-ops/index.js +8 -0
- package/dist/tools/file-ops/index.js.map +1 -0
- package/dist/tools/file-ops/move-file.d.ts +3 -0
- package/dist/tools/file-ops/move-file.d.ts.map +1 -0
- package/dist/tools/file-ops/move-file.js +126 -0
- package/dist/tools/file-ops/move-file.js.map +1 -0
- package/dist/tools/file-ops/string-replace.d.ts +3 -0
- package/dist/tools/file-ops/string-replace.d.ts.map +1 -0
- package/dist/tools/{string-replace.js → file-ops/string-replace.js} +13 -13
- package/dist/tools/file-ops/string-replace.js.map +1 -0
- package/dist/tools/file-ops/write-file.d.ts +3 -0
- package/dist/tools/file-ops/write-file.d.ts.map +1 -0
- package/dist/tools/{write-file.js → file-ops/write-file.js} +31 -17
- package/dist/tools/file-ops/write-file.js.map +1 -0
- package/dist/tools/git/git-reset.js +1 -1
- package/dist/tools/git/git-reset.js.map +1 -1
- package/dist/tools/git/index.js +3 -3
- package/dist/tools/git/index.js.map +1 -1
- package/dist/tools/git/utils.d.ts +4 -0
- package/dist/tools/git/utils.d.ts.map +1 -1
- package/dist/tools/git/utils.js +12 -0
- package/dist/tools/git/utils.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +8 -2
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/search-file-contents.d.ts.map +1 -1
- package/dist/tools/search-file-contents.js +59 -10
- package/dist/tools/search-file-contents.js.map +1 -1
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +9 -0
- package/dist/tools/tool-manager.js.map +1 -1
- package/dist/types/app.d.ts +2 -0
- package/dist/types/app.d.ts.map +1 -1
- package/dist/types/commands.d.ts +20 -0
- package/dist/types/commands.d.ts.map +1 -1
- package/dist/types/core.d.ts +2 -1
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/core.js +7 -0
- package/dist/types/core.js.map +1 -1
- package/dist/types/ui.d.ts +1 -1
- package/dist/types/ui.d.ts.map +1 -1
- package/dist/utils/auto-compact.d.ts.map +1 -1
- package/dist/utils/auto-compact.js +13 -7
- package/dist/utils/auto-compact.js.map +1 -1
- package/dist/utils/logging/index.d.ts.map +1 -1
- package/dist/utils/logging/index.js +18 -30
- package/dist/utils/logging/index.js.map +1 -1
- package/dist/utils/question-queue.d.ts +15 -0
- package/dist/utils/question-queue.d.ts.map +1 -0
- package/dist/utils/question-queue.js +25 -0
- package/dist/utils/question-queue.js.map +1 -0
- package/dist/utils/response-formatter.d.ts +108 -0
- package/dist/utils/response-formatter.d.ts.map +1 -0
- package/dist/utils/response-formatter.js +387 -0
- package/dist/utils/response-formatter.js.map +1 -0
- package/dist/utils/shutdown/index.d.ts +7 -0
- package/dist/utils/shutdown/index.d.ts.map +1 -0
- package/dist/utils/shutdown/index.js +6 -0
- package/dist/utils/shutdown/index.js.map +1 -0
- package/dist/utils/shutdown/shutdown-manager.d.ts +19 -0
- package/dist/utils/shutdown/shutdown-manager.d.ts.map +1 -0
- package/dist/utils/shutdown/shutdown-manager.js +100 -0
- package/dist/utils/shutdown/shutdown-manager.js.map +1 -0
- package/dist/utils/shutdown/types.d.ts +9 -0
- package/dist/utils/shutdown/types.d.ts.map +1 -0
- package/dist/utils/shutdown/types.js +2 -0
- package/dist/utils/shutdown/types.js.map +1 -0
- package/dist/utils/type-helpers.d.ts +140 -0
- package/dist/utils/type-helpers.d.ts.map +1 -0
- package/dist/utils/type-helpers.js +220 -0
- package/dist/utils/type-helpers.js.map +1 -0
- package/dist/utils/url-utils.d.ts +6 -0
- package/dist/utils/url-utils.d.ts.map +1 -0
- package/dist/utils/url-utils.js +22 -0
- package/dist/utils/url-utils.js.map +1 -0
- package/dist/vscode/vscode-server.d.ts.map +1 -1
- package/dist/vscode/vscode-server.js +10 -0
- package/dist/vscode/vscode-server.js.map +1 -1
- package/dist/wizards/steps/mcp-step.js +1 -1
- package/dist/wizards/steps/mcp-step.js.map +1 -1
- package/dist/wizards/steps/provider-step.js +1 -1
- package/dist/wizards/steps/provider-step.js.map +1 -1
- package/dist/wizards/templates/mcp-templates.d.ts.map +1 -1
- package/dist/wizards/templates/mcp-templates.js +8 -6
- package/dist/wizards/templates/mcp-templates.js.map +1 -1
- package/dist/wizards/validation.d.ts.map +1 -1
- package/dist/wizards/validation.js +2 -3
- package/dist/wizards/validation.js.map +1 -1
- package/package.json +8 -17
- package/source/app/prompts/main-prompt.md +21 -3
- package/dist/hooks/chat-handler/utils/context-checker.d.ts +0 -15
- package/dist/hooks/chat-handler/utils/context-checker.d.ts.map +0 -1
- package/dist/hooks/chat-handler/utils/context-checker.js +0 -68
- package/dist/hooks/chat-handler/utils/context-checker.js.map +0 -1
- package/dist/tools/string-replace.d.ts +0 -3
- package/dist/tools/string-replace.d.ts.map +0 -1
- package/dist/tools/string-replace.js.map +0 -1
- package/dist/tools/write-file.d.ts +0 -3
- package/dist/tools/write-file.d.ts.map +0 -1
- package/dist/tools/write-file.js.map +0 -1
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { Cron } from 'croner';
|
|
4
|
+
import { parseCommandFile } from '../custom-commands/parser.js';
|
|
5
|
+
import { addScheduleRun, generateScheduleId, loadSchedules, saveSchedules, updateScheduleRun, } from './storage.js';
|
|
6
|
+
export class ScheduleRunner {
|
|
7
|
+
cronJobs = new Map();
|
|
8
|
+
queue = [];
|
|
9
|
+
isRunning = false;
|
|
10
|
+
isProcessing = false;
|
|
11
|
+
callbacks;
|
|
12
|
+
constructor(callbacks) {
|
|
13
|
+
this.callbacks = callbacks;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Start all scheduled cron jobs
|
|
17
|
+
*/
|
|
18
|
+
async start() {
|
|
19
|
+
if (this.isRunning)
|
|
20
|
+
return;
|
|
21
|
+
this.isRunning = true;
|
|
22
|
+
const schedules = await loadSchedules();
|
|
23
|
+
const enabledSchedules = schedules.filter(s => s.enabled);
|
|
24
|
+
for (const schedule of enabledSchedules) {
|
|
25
|
+
this.registerCronJob(schedule);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Stop all cron jobs and clear the queue
|
|
30
|
+
*/
|
|
31
|
+
stop() {
|
|
32
|
+
this.isRunning = false;
|
|
33
|
+
for (const [, job] of this.cronJobs) {
|
|
34
|
+
job.stop();
|
|
35
|
+
}
|
|
36
|
+
this.cronJobs.clear();
|
|
37
|
+
this.queue = [];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get the number of active cron jobs
|
|
41
|
+
*/
|
|
42
|
+
getActiveJobCount() {
|
|
43
|
+
return this.cronJobs.size;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get the current queue length
|
|
47
|
+
*/
|
|
48
|
+
getQueueLength() {
|
|
49
|
+
return this.queue.length;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Check if currently processing a job
|
|
53
|
+
*/
|
|
54
|
+
getIsProcessing() {
|
|
55
|
+
return this.isProcessing;
|
|
56
|
+
}
|
|
57
|
+
registerCronJob(schedule) {
|
|
58
|
+
const job = new Cron(schedule.cron, () => {
|
|
59
|
+
this.enqueueJob(schedule);
|
|
60
|
+
});
|
|
61
|
+
this.cronJobs.set(schedule.id, job);
|
|
62
|
+
}
|
|
63
|
+
enqueueJob(schedule) {
|
|
64
|
+
// Don't duplicate — if this schedule is already queued, skip
|
|
65
|
+
if (this.queue.some(s => s.id === schedule.id))
|
|
66
|
+
return;
|
|
67
|
+
this.queue.push(schedule);
|
|
68
|
+
void this.processQueue();
|
|
69
|
+
}
|
|
70
|
+
async processQueue() {
|
|
71
|
+
if (this.isProcessing || this.queue.length === 0)
|
|
72
|
+
return;
|
|
73
|
+
this.isProcessing = true;
|
|
74
|
+
while (this.queue.length > 0 && this.isRunning) {
|
|
75
|
+
const schedule = this.queue.shift();
|
|
76
|
+
if (schedule) {
|
|
77
|
+
await this.executeJob(schedule);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
this.isProcessing = false;
|
|
81
|
+
}
|
|
82
|
+
async executeJob(schedule) {
|
|
83
|
+
const run = {
|
|
84
|
+
id: `run-${generateScheduleId()}`,
|
|
85
|
+
scheduleId: schedule.id,
|
|
86
|
+
command: schedule.command,
|
|
87
|
+
startedAt: new Date().toISOString(),
|
|
88
|
+
completedAt: null,
|
|
89
|
+
status: 'running',
|
|
90
|
+
};
|
|
91
|
+
await addScheduleRun(run);
|
|
92
|
+
this.callbacks.onJobStart(schedule);
|
|
93
|
+
try {
|
|
94
|
+
// Clear messages for fresh context
|
|
95
|
+
await this.callbacks.clearMessages();
|
|
96
|
+
// Load the schedule file from .nanocoder/schedules/
|
|
97
|
+
const filePath = join(process.cwd(), '.nanocoder', 'schedules', schedule.command);
|
|
98
|
+
if (!existsSync(filePath)) {
|
|
99
|
+
throw new Error(`Schedule file not found: ${schedule.command}. Ensure it exists in .nanocoder/schedules/`);
|
|
100
|
+
}
|
|
101
|
+
const parsed = parseCommandFile(filePath);
|
|
102
|
+
const prompt = `[Executing scheduled command: ${schedule.command}]\n\n${parsed.content}`;
|
|
103
|
+
await this.callbacks.handleMessageSubmit(prompt);
|
|
104
|
+
// Wait for the conversation to complete
|
|
105
|
+
await this.callbacks.waitForConversationComplete();
|
|
106
|
+
// Update run status
|
|
107
|
+
run.completedAt = new Date().toISOString();
|
|
108
|
+
run.status = 'success';
|
|
109
|
+
await updateScheduleRun(run.id, {
|
|
110
|
+
completedAt: run.completedAt,
|
|
111
|
+
status: 'success',
|
|
112
|
+
});
|
|
113
|
+
// Update lastRunAt on the schedule
|
|
114
|
+
const schedules = await loadSchedules();
|
|
115
|
+
const idx = schedules.findIndex(s => s.id === schedule.id);
|
|
116
|
+
if (idx !== -1 && schedules[idx]) {
|
|
117
|
+
schedules[idx].lastRunAt = run.completedAt;
|
|
118
|
+
await saveSchedules(schedules);
|
|
119
|
+
}
|
|
120
|
+
this.callbacks.onJobComplete(schedule, run);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
124
|
+
run.completedAt = new Date().toISOString();
|
|
125
|
+
run.status = 'error';
|
|
126
|
+
run.error = errorMsg;
|
|
127
|
+
await updateScheduleRun(run.id, {
|
|
128
|
+
completedAt: run.completedAt,
|
|
129
|
+
status: 'error',
|
|
130
|
+
error: errorMsg,
|
|
131
|
+
});
|
|
132
|
+
this.callbacks.onJobError(schedule, errorMsg);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../source/schedule/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,SAAS,CAAC;AACnC,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EACN,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,iBAAiB,GACjB,MAAM,WAAW,CAAC;AAYnB,MAAM,OAAO,cAAc;IAClB,QAAQ,GAAsB,IAAI,GAAG,EAAE,CAAC;IACxC,KAAK,GAAe,EAAE,CAAC;IACvB,SAAS,GAAG,KAAK,CAAC;IAClB,YAAY,GAAG,KAAK,CAAC;IACrB,SAAS,CAA0B;IAE3C,YAAY,SAAkC;QAC7C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACV,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO;QAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAEtB,MAAM,SAAS,GAAG,MAAM,aAAa,EAAE,CAAC;QACxC,MAAM,gBAAgB,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAE1D,KAAK,MAAM,QAAQ,IAAI,gBAAgB,EAAE,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C;YAC3C,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC;YACrB,GAAG,CAAC,KAAK,GAAG,QAAQ,CAAC;YACrB,MAAM,iBAAiB,CAAC,GAAG,CAAC,EAAE,EAAE;gBAC/B,WAAW,EAAE,GAAG,CAAC,WAAW;gBAC5B,MAAM,EAAE,OAAO;gBACf,KAAK,EAAE,QAAQ;aACf,CAAC,CAAC;YAEH,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC/C,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Schedule, ScheduleRun } from './types.js';
|
|
2
|
+
export declare function generateScheduleId(): string;
|
|
3
|
+
export declare function loadSchedules(): Promise<Schedule[]>;
|
|
4
|
+
export declare function saveSchedules(schedules: Schedule[]): Promise<void>;
|
|
5
|
+
export declare function loadScheduleRuns(): Promise<ScheduleRun[]>;
|
|
6
|
+
export declare function saveScheduleRuns(runs: ScheduleRun[]): Promise<void>;
|
|
7
|
+
export declare function addScheduleRun(run: ScheduleRun): Promise<void>;
|
|
8
|
+
export declare function updateScheduleRun(runId: string, updates: Partial<Pick<ScheduleRun, 'completedAt' | 'status' | 'error'>>): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../source/schedule/storage.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,QAAQ,EACR,WAAW,EAGX,MAAM,SAAS,CAAC;AAejB,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,wBAAsB,aAAa,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CASzD;AAED,wBAAsB,aAAa,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAMxE;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAS/D;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAQzE;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAIpE;AAED,wBAAsB,iBAAiB,CACtC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,aAAa,GAAG,QAAQ,GAAG,OAAO,CAAC,CAAC,GACrE,OAAO,CAAC,IAAI,CAAC,CAOf"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
const SCHEDULES_DIR = '.nanocoder';
|
|
5
|
+
const SCHEDULES_FILE = 'schedules.json';
|
|
6
|
+
const SCHEDULE_RUNS_FILE = 'schedule-runs.json';
|
|
7
|
+
const MAX_RUNS = 100;
|
|
8
|
+
function getSchedulesPath() {
|
|
9
|
+
return join(process.cwd(), SCHEDULES_DIR, SCHEDULES_FILE);
|
|
10
|
+
}
|
|
11
|
+
function getScheduleRunsPath() {
|
|
12
|
+
return join(process.cwd(), SCHEDULES_DIR, SCHEDULE_RUNS_FILE);
|
|
13
|
+
}
|
|
14
|
+
export function generateScheduleId() {
|
|
15
|
+
return randomUUID().slice(0, 8);
|
|
16
|
+
}
|
|
17
|
+
export async function loadSchedules() {
|
|
18
|
+
try {
|
|
19
|
+
const path = getSchedulesPath();
|
|
20
|
+
const content = await readFile(path, 'utf-8');
|
|
21
|
+
const data = JSON.parse(content);
|
|
22
|
+
return data.schedules ?? [];
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export async function saveSchedules(schedules) {
|
|
29
|
+
const dirPath = join(process.cwd(), SCHEDULES_DIR);
|
|
30
|
+
await mkdir(dirPath, { recursive: true });
|
|
31
|
+
const path = getSchedulesPath();
|
|
32
|
+
const data = { schedules };
|
|
33
|
+
await writeFile(path, JSON.stringify(data, null, 2), 'utf-8');
|
|
34
|
+
}
|
|
35
|
+
export async function loadScheduleRuns() {
|
|
36
|
+
try {
|
|
37
|
+
const path = getScheduleRunsPath();
|
|
38
|
+
const content = await readFile(path, 'utf-8');
|
|
39
|
+
const data = JSON.parse(content);
|
|
40
|
+
return data.runs ?? [];
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export async function saveScheduleRuns(runs) {
|
|
47
|
+
const dirPath = join(process.cwd(), SCHEDULES_DIR);
|
|
48
|
+
await mkdir(dirPath, { recursive: true });
|
|
49
|
+
const path = getScheduleRunsPath();
|
|
50
|
+
// Cap at MAX_RUNS entries
|
|
51
|
+
const cappedRuns = runs.slice(-MAX_RUNS);
|
|
52
|
+
const data = { runs: cappedRuns };
|
|
53
|
+
await writeFile(path, JSON.stringify(data, null, 2), 'utf-8');
|
|
54
|
+
}
|
|
55
|
+
export async function addScheduleRun(run) {
|
|
56
|
+
const runs = await loadScheduleRuns();
|
|
57
|
+
runs.push(run);
|
|
58
|
+
await saveScheduleRuns(runs);
|
|
59
|
+
}
|
|
60
|
+
export async function updateScheduleRun(runId, updates) {
|
|
61
|
+
const runs = await loadScheduleRuns();
|
|
62
|
+
const index = runs.findIndex(r => r.id === runId);
|
|
63
|
+
if (index !== -1) {
|
|
64
|
+
runs[index] = { ...runs[index], ...updates };
|
|
65
|
+
await saveScheduleRuns(runs);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../source/schedule/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CA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AC,GAAG,CAAC,CAAC;IACf,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACtC,KAAa,EACb,OAAuE;IAEvE,MAAM,IAAI,GAAG,MAAM,gBAAgB,EAAE,CAAC;IACtC,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC;IAClD,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,KAAK,CAAC,GAAG,EAAC,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,OAAO,EAAC,CAAC;QAC3C,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface Schedule {
|
|
2
|
+
id: string;
|
|
3
|
+
cron: string;
|
|
4
|
+
command: string;
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
createdAt: string;
|
|
7
|
+
lastRunAt: string | null;
|
|
8
|
+
}
|
|
9
|
+
export interface ScheduleRun {
|
|
10
|
+
id: string;
|
|
11
|
+
scheduleId: string;
|
|
12
|
+
command: string;
|
|
13
|
+
startedAt: string;
|
|
14
|
+
completedAt: string | null;
|
|
15
|
+
status: 'running' | 'success' | 'error';
|
|
16
|
+
error?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface SchedulesData {
|
|
19
|
+
schedules: Schedule[];
|
|
20
|
+
}
|
|
21
|
+
export interface ScheduleRunsData {
|
|
22
|
+
runs: ScheduleRun[];
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../source/schedule/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC7B,SAAS,EAAE,QAAQ,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,WAAW,EAAE,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../source/schedule/types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash-executor.d.ts","sourceRoot":"","sources":["../../source/services/bash-executor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAUzC,MAAM,WAAW,kBAAkB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AASD,qBAAa,YAAa,SAAQ,YAAY;IAC7C,OAAO,CAAC,UAAU,CAAqC;IAEvD,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG;QACzB,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;KACrC;
|
|
1
|
+
{"version":3,"file":"bash-executor.d.ts","sourceRoot":"","sources":["../../source/services/bash-executor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAUzC,MAAM,WAAW,kBAAkB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AASD,qBAAa,YAAa,SAAQ,YAAY;IAC7C,OAAO,CAAC,UAAU,CAAqC;IAEvD,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG;QACzB,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;KACrC;IAiFD,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAuBpC,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAK7D,mBAAmB,IAAI,OAAO;IAI9B,qBAAqB,IAAI,MAAM,EAAE;CAGjC;AAGD,eAAO,MAAM,YAAY,cAAqB,CAAC"}
|
|
@@ -25,9 +25,14 @@ export class BashExecutor extends EventEmitter {
|
|
|
25
25
|
proc.stdout.on('data', (data) => {
|
|
26
26
|
state.fullOutput += data.toString();
|
|
27
27
|
state.outputPreview = state.fullOutput.slice(-BASH_OUTPUT_PREVIEW_LENGTH);
|
|
28
|
+
// Emit progress immediately when output is received
|
|
29
|
+
// This ensures fast commands still show streaming output
|
|
30
|
+
this.emit('progress', { ...state });
|
|
28
31
|
});
|
|
29
32
|
proc.stderr.on('data', (data) => {
|
|
30
33
|
state.stderr += data.toString();
|
|
34
|
+
// Emit progress immediately when stderr is received
|
|
35
|
+
this.emit('progress', { ...state });
|
|
31
36
|
});
|
|
32
37
|
// Progress interval - emit updates every 500ms
|
|
33
38
|
// Using unref() so this interval doesn't prevent Node.js from exiting
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash-executor.js","sourceRoot":"","sources":["../../source/services/bash-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,EAAC,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AACvC,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AACzC,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AAEtC,OAAO,EACN,0BAA0B,EAC1B,yBAAyB,GACzB,MAAM,aAAa,CAAC;AAErB,MAAM,SAAS,GAAG,QAAQ,KAAK,OAAO,CAAC;AAoBvC,MAAM,OAAO,YAAa,SAAQ,YAAY;IACrC,UAAU,GAAG,IAAI,GAAG,EAA0B,CAAC;IAEvD,OAAO,CAAC,OAAe;QAItB,MAAM,WAAW,GAAG,UAAU,EAAE,CAAC;QAEjC,MAAM,KAAK,GAAuB;YACjC,WAAW;YACX,OAAO;YACP,aAAa,EAAE,EAAE;YACjB,UAAU,EAAE,EAAE;YACd,MAAM,EAAE,EAAE;YACV,UAAU,EAAE,KAAK;YACjB,QAAQ,EAAE,IAAI;YACd,KAAK,EAAE,IAAI;SACX,CAAC;QAEF,MAAM,IAAI,GAAG,SAAS;YACrB,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC/B,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;QAEhC,iBAAiB;QACjB,IAAI,CAAC,MAAM,CAAC,EA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4
|
* Note: This is now an internal utility. Use tool-parser.ts for public API.
|
|
5
|
+
* Type-preserving: Preserves object types in memory while converting to string for processing
|
|
5
6
|
*/
|
|
6
7
|
/**
|
|
7
8
|
* Detects malformed JSON tool call attempts and returns error details
|
|
8
9
|
* Returns null if no malformed tool calls detected
|
|
10
|
+
* Type-preserving: Accepts unknown type, converts to string for processing
|
|
9
11
|
*/
|
|
10
|
-
export declare function detectMalformedJSONToolCall(content:
|
|
12
|
+
export declare function detectMalformedJSONToolCall(content: unknown): {
|
|
11
13
|
error: string;
|
|
12
14
|
examples: string;
|
|
13
15
|
} | null;
|
|
14
16
|
/**
|
|
15
17
|
* Parses JSON-formatted tool calls from content
|
|
18
|
+
* Type-preserving: Preserves object types in memory while converting to string for processing
|
|
16
19
|
* This is an internal function - use tool-parser.ts for public API
|
|
17
20
|
*/
|
|
18
|
-
export declare function parseJSONToolCalls(content:
|
|
21
|
+
export declare function parseJSONToolCalls(content: unknown): ToolCall[];
|
|
19
22
|
/**
|
|
20
23
|
* Cleans content by removing tool call JSON blocks
|
|
24
|
+
* Type-preserving: Accepts unknown type, converts to string for processing
|
|
21
25
|
* This is an internal function - use tool-parser.ts for public API
|
|
22
26
|
*/
|
|
23
|
-
export declare function cleanJSONToolCalls(content:
|
|
27
|
+
export declare function cleanJSONToolCalls(content: unknown, toolCalls: ToolCall[]): string;
|
|
24
28
|
//# sourceMappingURL=json-parser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-parser.d.ts","sourceRoot":"","sources":["../../source/tool-calling/json-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"json-parser.d.ts","sourceRoot":"","sources":["../../source/tool-calling/json-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AAG5C;;;;GAIG;AAEH;;;;GAIG;AACH,wBAAgB,2BAA2B,CAC1C,OAAO,EAAE,OAAO,GACd;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAC,GAAG,IAAI,CA2C1C;AASD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,QAAQ,EAAE,CA6H/D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,QAAQ,EAAE,GACnB,MAAM,CA0DR"}
|
|
@@ -1,35 +1,45 @@
|
|
|
1
|
+
import { ensureString } from '../utils/type-helpers.js';
|
|
1
2
|
/**
|
|
2
3
|
* Internal JSON tool call parser
|
|
3
4
|
* Note: This is now an internal utility. Use tool-parser.ts for public API.
|
|
5
|
+
* Type-preserving: Preserves object types in memory while converting to string for processing
|
|
4
6
|
*/
|
|
5
7
|
/**
|
|
6
8
|
* Detects malformed JSON tool call attempts and returns error details
|
|
7
9
|
* Returns null if no malformed tool calls detected
|
|
10
|
+
* Type-preserving: Accepts unknown type, converts to string for processing
|
|
8
11
|
*/
|
|
9
12
|
export function detectMalformedJSONToolCall(content) {
|
|
13
|
+
// Type guard: ensure content is string for processing operations
|
|
14
|
+
// BUT original type is preserved in memory via the ToolCall structure
|
|
15
|
+
const contentStr = ensureString(content);
|
|
10
16
|
// Check for incomplete JSON structures
|
|
17
|
+
// FIX: Anchor to line start (?:^|\n) to avoid matching inline text like "I tried {"name":...}"
|
|
11
18
|
const patterns = [
|
|
12
19
|
{
|
|
13
20
|
// Incomplete JSON with name but missing arguments
|
|
14
|
-
|
|
21
|
+
// Anchored to line start or after newline
|
|
22
|
+
regex: /(?:^|\n)\s*\{\s*"name"\s*:\s*"[^"]+"\s*,?\s*\}/,
|
|
15
23
|
error: 'Incomplete tool call: missing "arguments" field',
|
|
16
24
|
hint: 'Tool calls must include both "name" and "arguments" fields',
|
|
17
25
|
},
|
|
18
26
|
{
|
|
19
27
|
// Incomplete JSON with arguments but missing name
|
|
20
|
-
|
|
28
|
+
// Anchored to line start or after newline
|
|
29
|
+
regex: /(?:^|\n)\s*\{\s*"arguments"\s*:\s*\{[^}]*\}\s*\}/,
|
|
21
30
|
error: 'Incomplete tool call: missing "name" field',
|
|
22
31
|
hint: 'Tool calls must include both "name" and "arguments" fields',
|
|
23
32
|
},
|
|
24
33
|
{
|
|
25
34
|
// Malformed arguments (not an object)
|
|
26
|
-
|
|
35
|
+
// Anchored to line start or after newline
|
|
36
|
+
regex: /(?:^|\n)\s*\{\s*"name"\s*:\s*"[^"]+"\s*,\s*"arguments"\s*:\s*"[^"]*"\s*\}/,
|
|
27
37
|
error: 'Invalid tool call: "arguments" must be an object, not a string',
|
|
28
38
|
hint: 'Use {"name": "tool_name", "arguments": {...}} format',
|
|
29
39
|
},
|
|
30
40
|
];
|
|
31
41
|
for (const pattern of patterns) {
|
|
32
|
-
const match =
|
|
42
|
+
const match = contentStr.match(pattern.regex);
|
|
33
43
|
if (match) {
|
|
34
44
|
return {
|
|
35
45
|
error: pattern.error,
|
|
@@ -47,11 +57,14 @@ function getCorrectJSONFormatExamples(_specificHint) {
|
|
|
47
57
|
}
|
|
48
58
|
/**
|
|
49
59
|
* Parses JSON-formatted tool calls from content
|
|
60
|
+
* Type-preserving: Preserves object types in memory while converting to string for processing
|
|
50
61
|
* This is an internal function - use tool-parser.ts for public API
|
|
51
62
|
*/
|
|
52
63
|
export function parseJSONToolCalls(content) {
|
|
64
|
+
// Convert to string for processing (this is done by the Formatter before calling this)
|
|
65
|
+
const contentStr = ensureString(content);
|
|
53
66
|
const extractedCalls = [];
|
|
54
|
-
let trimmedContent =
|
|
67
|
+
let trimmedContent = contentStr.trim();
|
|
55
68
|
// Handle markdown code blocks
|
|
56
69
|
const codeBlockMatch = trimmedContent.match(/^```(?:json)?\s*\n?([\s\S]*?)\n?```$/);
|
|
57
70
|
if (codeBlockMatch && codeBlockMatch[1]) {
|
|
@@ -76,7 +89,7 @@ export function parseJSONToolCalls(content) {
|
|
|
76
89
|
id: `call_${Date.now()}`,
|
|
77
90
|
function: {
|
|
78
91
|
name: parsed.name || '',
|
|
79
|
-
arguments: parsed.arguments,
|
|
92
|
+
arguments: parsed.arguments, // Type preserved in memory!
|
|
80
93
|
},
|
|
81
94
|
};
|
|
82
95
|
extractedCalls.push(toolCall);
|
|
@@ -90,7 +103,7 @@ export function parseJSONToolCalls(content) {
|
|
|
90
103
|
// Look for standalone JSON blocks in the content (multiline without code blocks)
|
|
91
104
|
const jsonBlockRegex = /\{\s*\n\s*"name":\s*"([^"]+)",\s*\n\s*"arguments":\s*\{[\s\S]*?\}\s*\n\s*\}/g;
|
|
92
105
|
let jsonMatch;
|
|
93
|
-
while ((jsonMatch = jsonBlockRegex.exec(
|
|
106
|
+
while ((jsonMatch = jsonBlockRegex.exec(contentStr)) !== null) {
|
|
94
107
|
try {
|
|
95
108
|
const parsed = JSON.parse(jsonMatch[0]);
|
|
96
109
|
if (parsed.name && parsed.arguments !== undefined) {
|
|
@@ -104,7 +117,7 @@ export function parseJSONToolCalls(content) {
|
|
|
104
117
|
id: `call_${Date.now()}_${extractedCalls.length}`,
|
|
105
118
|
function: {
|
|
106
119
|
name: parsed.name || '',
|
|
107
|
-
arguments: parsed.arguments,
|
|
120
|
+
arguments: parsed.arguments, // Type preserved in memory!
|
|
108
121
|
},
|
|
109
122
|
};
|
|
110
123
|
extractedCalls.push(toolCall);
|
|
@@ -120,7 +133,7 @@ export function parseJSONToolCalls(content) {
|
|
|
120
133
|
];
|
|
121
134
|
for (const pattern of toolCallPatterns) {
|
|
122
135
|
let match;
|
|
123
|
-
while ((match = pattern.exec(
|
|
136
|
+
while ((match = pattern.exec(contentStr)) !== null) {
|
|
124
137
|
const [, name, argsStr] = match;
|
|
125
138
|
try {
|
|
126
139
|
let args = null;
|
|
@@ -131,7 +144,7 @@ export function parseJSONToolCalls(content) {
|
|
|
131
144
|
if (parsed !== null &&
|
|
132
145
|
typeof parsed === 'object' &&
|
|
133
146
|
!Array.isArray(parsed)) {
|
|
134
|
-
args = parsed;
|
|
147
|
+
args = parsed; // Type preserved in memory!
|
|
135
148
|
}
|
|
136
149
|
}
|
|
137
150
|
// Only add tool call if we have a valid object
|
|
@@ -140,7 +153,7 @@ export function parseJSONToolCalls(content) {
|
|
|
140
153
|
id: `call_${Date.now()}_${extractedCalls.length}`,
|
|
141
154
|
function: {
|
|
142
155
|
name: name || '',
|
|
143
|
-
arguments: args,
|
|
156
|
+
arguments: args, // Type preserved in memory!
|
|
144
157
|
},
|
|
145
158
|
});
|
|
146
159
|
}
|
|
@@ -154,12 +167,16 @@ export function parseJSONToolCalls(content) {
|
|
|
154
167
|
}
|
|
155
168
|
/**
|
|
156
169
|
* Cleans content by removing tool call JSON blocks
|
|
170
|
+
* Type-preserving: Accepts unknown type, converts to string for processing
|
|
157
171
|
* This is an internal function - use tool-parser.ts for public API
|
|
158
172
|
*/
|
|
159
173
|
export function cleanJSONToolCalls(content, toolCalls) {
|
|
174
|
+
// Type guard: ensure content is string for processing operations
|
|
175
|
+
// BUT original type is preserved in memory via the ToolCall structure
|
|
176
|
+
const contentStr = ensureString(content);
|
|
160
177
|
if (toolCalls.length === 0)
|
|
161
|
-
return
|
|
162
|
-
let cleanedContent =
|
|
178
|
+
return contentStr;
|
|
179
|
+
let cleanedContent = contentStr;
|
|
163
180
|
// Handle markdown code blocks that contain only tool calls
|
|
164
181
|
const codeBlockRegex = /```(?:json)?\s*\n?([\s\S]*?)\n?```/g;
|
|
165
182
|
cleanedContent = cleanedContent.replace(codeBlockRegex, (match, blockContent) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-parser.js","sourceRoot":"","sources":["../../source/tool-calling/json-parser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"json-parser.js","sourceRoot":"","sources":["../../source/tool-calling/json-parser.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAElD;;;;GA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AAE;QAC/B,MAAM,YAAY,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC;QAEzC,0DAA0D;QAC1D,IAAI,CAAC;YACJ,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAGrC,CAAC;YACF,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;gBACnD,qEAAqE;gBACrE,OAAO,EAAE,CAAC;YACX,CAAC;QACF,CAAC;QAAC,MAAM,CAAC;YACR,sCAAsC;QACvC,CAAC;QAED,8DAA8D;QAC9D,OAAO,KAAK,CAAC;IACd,CAAC,CACD,CAAC;IAEF,+EAA+E;IAC/E,MAAM,gBAAgB,GAAG;QACxB,8EAA8E,EAAE,wBAAwB;QACxG,2DAA2D,EAAE,8BAA8B;KAC3F,CAAC;IAEF,KAAK,MAAM,OAAO,IAAI,gBAAgB,EAAE,CAAC;QACxC,cAAc,GAAG,cAAc,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACtD,CAAC;IAED,2DAA2D;IAC3D,cAAc,GAAG,cAAc;QAC9B,4CAA4C;SAC3C,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;QACzB,sEAAsE;SACrE,OAAO,CAAC,kBAAkB,EAAE,KAAK,CAAC;QACnC,wCAAwC;SACvC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;QAC1B,6DAA6D;SAC5D,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC;SAC1B,IAAI,EAAE,CAAC;IAET,OAAO,cAAc,CAAC;AACvB,CAAC"}
|
|
@@ -13,8 +13,8 @@ type ParseResult = {
|
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* Unified tool call parser that tries XML first, then falls back to JSON
|
|
16
|
-
*
|
|
16
|
+
* Type-preserving: Accepts unknown type, converts to string for processing
|
|
17
17
|
*/
|
|
18
|
-
export declare function parseToolCalls(content:
|
|
18
|
+
export declare function parseToolCalls(content: unknown): ParseResult;
|
|
19
19
|
export {};
|
|
20
20
|
//# sourceMappingURL=tool-parser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-parser.d.ts","sourceRoot":"","sources":["../../source/tool-calling/tool-parser.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-parser.d.ts","sourceRoot":"","sources":["../../source/tool-calling/tool-parser.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AAmC5C;;GAEG;AACH,KAAK,WAAW,GACb;IACA,OAAO,EAAE,IAAI,CAAC;IACd,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;CACtB,GACD;IACA,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAChB,CAAC;AAEL;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,CAgE5D"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { cleanJSONToolCalls, detectMalformedJSONToolCall, parseJSONToolCalls, } from '../tool-calling/json-parser.js';
|
|
2
2
|
import { XMLToolCallParser } from '../tool-calling/xml-parser.js';
|
|
3
|
+
import { ensureString } from '../utils/type-helpers.js';
|
|
3
4
|
/**
|
|
4
|
-
* Strip
|
|
5
|
+
* Strip tags from content (some models output thinking that shouldn't be shown)
|
|
5
6
|
*/
|
|
6
7
|
function stripThinkTags(content) {
|
|
7
8
|
return (content
|
|
8
|
-
// Strip complete
|
|
9
|
+
// Strip complete blocks
|
|
9
10
|
.replace(/<think>[\s\S]*?<\/think>/gi, '')
|
|
10
11
|
// Strip orphaned/incomplete think tags
|
|
11
12
|
.replace(/<think>[\s\S]*$/gi, '')
|
|
@@ -28,21 +29,14 @@ function normalizeWhitespace(content) {
|
|
|
28
29
|
}
|
|
29
30
|
/**
|
|
30
31
|
* Unified tool call parser that tries XML first, then falls back to JSON
|
|
31
|
-
*
|
|
32
|
+
* Type-preserving: Accepts unknown type, converts to string for processing
|
|
32
33
|
*/
|
|
33
34
|
export function parseToolCalls(content) {
|
|
34
|
-
//
|
|
35
|
-
const
|
|
36
|
-
//
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
success: false,
|
|
41
|
-
error: xmlMalformed.error,
|
|
42
|
-
examples: xmlMalformed.examples,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
// 2. Try XML parser for valid tool calls
|
|
35
|
+
// 1. Safety Coercion
|
|
36
|
+
const contentStr = ensureString(content);
|
|
37
|
+
// Strip tags first - some models (like GLM-4) emit these for chain-of-thought
|
|
38
|
+
const strippedContent = stripThinkTags(contentStr);
|
|
39
|
+
// 1. Try XML parser for valid tool calls (OPTIMISTIC: Success first!)
|
|
46
40
|
if (XMLToolCallParser.hasToolCalls(strippedContent)) {
|
|
47
41
|
// Parse valid XML tool calls
|
|
48
42
|
const parsedCalls = XMLToolCallParser.parseToolCalls(strippedContent);
|
|
@@ -56,17 +50,18 @@ export function parseToolCalls(content) {
|
|
|
56
50
|
};
|
|
57
51
|
}
|
|
58
52
|
}
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (jsonMalformed) {
|
|
53
|
+
// 2. Check for malformed XML patterns (DEFENSIVE: Error second!)
|
|
54
|
+
const xmlMalformed = XMLToolCallParser.detectMalformedToolCall(strippedContent);
|
|
55
|
+
if (xmlMalformed) {
|
|
63
56
|
return {
|
|
64
57
|
success: false,
|
|
65
|
-
error:
|
|
66
|
-
examples:
|
|
58
|
+
error: xmlMalformed.error,
|
|
59
|
+
examples: xmlMalformed.examples,
|
|
67
60
|
};
|
|
68
61
|
}
|
|
69
|
-
//
|
|
62
|
+
// 3. Fall back to JSON parser
|
|
63
|
+
// FIX: Check for valid JSON tool calls FIRST (optimistic approach)
|
|
64
|
+
// This prevents malformed detection from catching text that's NOT a tool call attempt
|
|
70
65
|
const jsonCalls = parseJSONToolCalls(strippedContent);
|
|
71
66
|
if (jsonCalls.length > 0) {
|
|
72
67
|
const cleanedContent = cleanJSONToolCalls(strippedContent, jsonCalls);
|
|
@@ -76,7 +71,16 @@ export function parseToolCalls(content) {
|
|
|
76
71
|
cleanedContent,
|
|
77
72
|
};
|
|
78
73
|
}
|
|
79
|
-
// 4.
|
|
74
|
+
// 4. If no valid tools found, check for malformed patterns
|
|
75
|
+
const jsonMalformed = detectMalformedJSONToolCall(strippedContent);
|
|
76
|
+
if (jsonMalformed) {
|
|
77
|
+
return {
|
|
78
|
+
success: false,
|
|
79
|
+
error: jsonMalformed.error,
|
|
80
|
+
examples: jsonMalformed.examples,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// 5. No tool calls found - still normalize whitespace in content
|
|
80
84
|
return {
|
|
81
85
|
success: true,
|
|
82
86
|
toolCalls: [],
|