@probelabs/probe-chat 0.6.0-rc100

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/tools.js ADDED
@@ -0,0 +1,186 @@
1
+ // This file might become obsolete or significantly simplified if tools
2
+ // are only defined/described in the system prompt and not passed to Vercel AI SDK.
3
+
4
+ // Let's comment it out for now, assuming it's not directly used in the new flow.
5
+ // If specific exports are needed elsewhere (like DEFAULT_SYSTEM_MESSAGE), they
6
+ // should be moved or imported directly from @probelabs/probe.
7
+
8
+
9
+ // Import tool generators and schemas from @probelabs/probe package
10
+ import {
11
+ searchTool,
12
+ queryTool,
13
+ extractTool,
14
+ DEFAULT_SYSTEM_MESSAGE,
15
+ attemptCompletionSchema,
16
+ attemptCompletionToolDefinition,
17
+ searchSchema,
18
+ querySchema,
19
+ extractSchema,
20
+ searchToolDefinition,
21
+ queryToolDefinition,
22
+ extractToolDefinition,
23
+ // Add the implement tool definition import if it exists in @probelabs/probe
24
+ // If not, we define it here. Assuming it's not in the package yet:
25
+ } from '@probelabs/probe';
26
+ import { randomUUID } from 'crypto';
27
+
28
+ // Generate a session ID
29
+ const sessionId = process.env.PROBE_SESSION_ID || randomUUID();
30
+ console.error(`Generated session ID for search caching: ${sessionId}`);
31
+
32
+ // Debug mode
33
+ const debug = process.env.DEBUG_CHAT === '1';
34
+
35
+ // Configure tools with the session ID
36
+ const configOptions = {
37
+ sessionId,
38
+ debug
39
+ };
40
+
41
+ // Create configured tool instances
42
+ export const tools = {
43
+ searchTool: searchTool(configOptions),
44
+ queryTool: queryTool(configOptions),
45
+ extractTool: extractTool(configOptions),
46
+ // Note: The actual implement tool *instance* comes from probeTool.js
47
+ // This file primarily deals with definitions for the system prompt.
48
+ };
49
+
50
+ // Export individual tools for direct use
51
+ export const { searchTool: searchToolInstance, queryTool: queryToolInstance, extractTool: extractToolInstance } = tools;
52
+
53
+ // For backward compatibility, export the original tool objects
54
+ export {
55
+ searchToolInstance as searchTool,
56
+ queryToolInstance as queryTool,
57
+ extractToolInstance as extractTool,
58
+ DEFAULT_SYSTEM_MESSAGE,
59
+ // Export schemas
60
+ searchSchema,
61
+ querySchema,
62
+ extractSchema,
63
+ attemptCompletionSchema,
64
+ // Export tool definitions
65
+ searchToolDefinition,
66
+ queryToolDefinition,
67
+ extractToolDefinition,
68
+ attemptCompletionToolDefinition,
69
+ };
70
+
71
+ // Define the implement tool XML definition
72
+ export const implementToolDefinition = `
73
+ ## implement
74
+ Description: Implement a given task. Can modify files. Can be used ONLY if task explicitly stated that something requires modification or implementation.
75
+
76
+ Parameters:
77
+ - task: (required) The task description. Should be as detailed as possible, ideally pointing to exact files which needs be modified or created.
78
+ - autoCommits: (optional) Whether to enable auto-commits in aider. Default is false.
79
+
80
+ Usage Example:
81
+
82
+ <examples>
83
+
84
+ User: Can you implement a function to calculate Fibonacci numbers in main.js?
85
+ <implement>
86
+ <task>Implement a recursive function to calculate the nth Fibonacci number in main.js</task>
87
+ </implement>
88
+
89
+ User: Can you implement a function to calculate Fibonacci numbers in main.js with auto-commits?
90
+ <implement>
91
+ <task>Implement a recursive function to calculate the nth Fibonacci number in main.js</task>
92
+ <autoCommits>true</autoCommits>
93
+ </implement>
94
+
95
+ </examples>
96
+ `;
97
+
98
+ // Define the listFiles tool XML definition
99
+ export const listFilesToolDefinition = `
100
+ ## listFiles
101
+ Description: List files and directories in a specified location.
102
+
103
+ Parameters:
104
+ - directory: (optional) The directory path to list files from. Defaults to current directory if not specified.
105
+
106
+ Usage Example:
107
+
108
+ <examples>
109
+
110
+ User: Can you list the files in the src directory?
111
+ <listFiles>
112
+ <directory>src</directory>
113
+ </listFiles>
114
+
115
+ User: What files are in the current directory?
116
+ <listFiles>
117
+ </listFiles>
118
+
119
+ </examples>
120
+ `;
121
+
122
+ // Define the searchFiles tool XML definition
123
+ export const searchFilesToolDefinition = `
124
+ ## searchFiles
125
+ Description: Find files with name matching a glob pattern with recursive search capability.
126
+
127
+ Parameters:
128
+ - pattern: (required) The glob pattern to search for (e.g., "**/*.js", "*.md").
129
+ - directory: (optional) The directory to search in. Defaults to current directory if not specified.
130
+ - recursive: (optional) Whether to search recursively. Defaults to true.
131
+
132
+ Usage Example:
133
+
134
+ <examples>
135
+
136
+ User: Can you find all JavaScript files in the project?
137
+ <searchFiles>
138
+ <pattern>**/*.js</pattern>
139
+ </searchFiles>
140
+
141
+ User: Find all markdown files in the docs directory, but only at the top level.
142
+ <searchFiles>
143
+ <pattern>*.md</pattern>
144
+ <directory>docs</directory>
145
+ <recursive>false</recursive>
146
+ </searchFiles>
147
+
148
+ </examples>
149
+ `;
150
+
151
+
152
+ // Import the XML parser function from @probelabs/probe
153
+ import { parseXmlToolCall } from '@probelabs/probe';
154
+
155
+ // Re-export the original parseXmlToolCall
156
+ export { parseXmlToolCall };
157
+
158
+ /**
159
+ * Enhanced XML parser that handles thinking tags
160
+ * This function removes any <thinking></thinking> tags from the input string
161
+ * before passing it to the original parseXmlToolCall function
162
+ * @param {string} xmlString - The XML string to parse
163
+ * @returns {Object|null} - The parsed tool call or null if no valid tool call found
164
+ */
165
+ export function parseXmlToolCallWithThinking(xmlString) {
166
+ // Extract thinking content if present (for potential logging or analysis)
167
+ const thinkingMatch = xmlString.match(/<thinking>([\s\S]*?)<\/thinking>/);
168
+ const thinkingContent = thinkingMatch ? thinkingMatch[1].trim() : null;
169
+
170
+ // Remove thinking tags and their content from the XML string
171
+ const cleanedXmlString = xmlString.replace(/<thinking>[\s\S]*?<\/thinking>/g, '').trim();
172
+
173
+ // Use the original parseXmlToolCall function to parse the cleaned XML string
174
+ const parsedTool = parseXmlToolCall(cleanedXmlString);
175
+
176
+ // If debugging is enabled, log the thinking content
177
+ if (process.env.DEBUG_CHAT === '1' && thinkingContent) {
178
+ console.log(`[DEBUG] AI Thinking Process:\n${thinkingContent}`);
179
+ }
180
+
181
+ return parsedTool;
182
+ }
183
+
184
+ // If tool instances are needed directly (e.g., for API endpoints bypassing the LLM loop),
185
+ // they are now created and exported from probeTool.js.
186
+ // We should ensure those are imported where needed.