@polka-codes/core 0.9.86 → 0.9.89
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 +27 -1
- package/dist/_tsup-dts-rollup.d.ts +349 -14
- package/dist/index.d.ts +15 -0
- package/dist/index.js +482 -272
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -126,114 +126,184 @@ function computeRateLimitBackoffSeconds(count, baseSeconds = 2, capSeconds = 60)
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
// src/config.ts
|
|
129
|
+
import { z as z2 } from "zod";
|
|
130
|
+
|
|
131
|
+
// src/config/memory.ts
|
|
129
132
|
import { z } from "zod";
|
|
130
|
-
var
|
|
131
|
-
z.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
133
|
+
var memoryConfigSchema = z.object({
|
|
134
|
+
enabled: z.boolean().optional().default(true),
|
|
135
|
+
type: z.enum(["sqlite", "memory"]).optional().default("sqlite"),
|
|
136
|
+
path: z.string().optional().default("~/.config/polka-codes/memory.sqlite")
|
|
137
|
+
}).strict().optional();
|
|
138
|
+
var DEFAULT_MEMORY_CONFIG = {
|
|
139
|
+
enabled: true,
|
|
140
|
+
type: "sqlite",
|
|
141
|
+
path: "~/.config/polka-codes/memory.sqlite"
|
|
142
|
+
};
|
|
143
|
+
function resolveHomePath(path) {
|
|
144
|
+
if (path.startsWith("~")) {
|
|
145
|
+
return `${process.env.HOME}${path.slice(1)}`;
|
|
146
|
+
}
|
|
147
|
+
return path;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/config.ts
|
|
151
|
+
var ruleSchema = z2.union([
|
|
152
|
+
z2.string(),
|
|
153
|
+
z2.object({ path: z2.string() }).strict(),
|
|
154
|
+
z2.object({ url: z2.string() }).strict(),
|
|
155
|
+
z2.object({
|
|
156
|
+
repo: z2.string(),
|
|
157
|
+
path: z2.string(),
|
|
158
|
+
tag: z2.string().optional(),
|
|
159
|
+
commit: z2.string().optional(),
|
|
160
|
+
branch: z2.string().optional()
|
|
140
161
|
}).strict()
|
|
141
162
|
]);
|
|
142
|
-
var providerConfigSchema =
|
|
143
|
-
apiKey:
|
|
144
|
-
defaultModel:
|
|
145
|
-
defaultParameters:
|
|
146
|
-
location:
|
|
147
|
-
project:
|
|
148
|
-
keyFile:
|
|
149
|
-
baseUrl:
|
|
163
|
+
var providerConfigSchema = z2.object({
|
|
164
|
+
apiKey: z2.string().optional(),
|
|
165
|
+
defaultModel: z2.string().optional(),
|
|
166
|
+
defaultParameters: z2.record(z2.string(), z2.any()).optional(),
|
|
167
|
+
location: z2.string().optional(),
|
|
168
|
+
project: z2.string().optional(),
|
|
169
|
+
keyFile: z2.string().optional(),
|
|
170
|
+
baseUrl: z2.string().optional(),
|
|
171
|
+
name: z2.string().optional()
|
|
172
|
+
// For OpenAI-compatible providers
|
|
150
173
|
});
|
|
151
|
-
var providerModelSchema =
|
|
152
|
-
provider:
|
|
153
|
-
model:
|
|
154
|
-
parameters:
|
|
155
|
-
budget:
|
|
156
|
-
rules:
|
|
174
|
+
var providerModelSchema = z2.object({
|
|
175
|
+
provider: z2.string().optional(),
|
|
176
|
+
model: z2.string().optional(),
|
|
177
|
+
parameters: z2.record(z2.string(), z2.any()).optional(),
|
|
178
|
+
budget: z2.number().positive().optional(),
|
|
179
|
+
rules: z2.array(ruleSchema).optional().or(z2.string()).optional()
|
|
157
180
|
});
|
|
158
|
-
var scriptSchema =
|
|
181
|
+
var scriptSchema = z2.union([
|
|
159
182
|
// Type 1: Simple shell command (backward compatible)
|
|
160
|
-
|
|
183
|
+
z2.string(),
|
|
161
184
|
// Type 2: Object with command and description (backward compatible)
|
|
162
|
-
|
|
163
|
-
command:
|
|
164
|
-
description:
|
|
185
|
+
z2.object({
|
|
186
|
+
command: z2.string(),
|
|
187
|
+
description: z2.string()
|
|
165
188
|
}).strict(),
|
|
166
189
|
// Type 3: Reference to dynamic workflow YAML
|
|
167
|
-
|
|
168
|
-
workflow:
|
|
190
|
+
z2.object({
|
|
191
|
+
workflow: z2.string(),
|
|
169
192
|
// Path to .yml workflow file
|
|
170
|
-
description:
|
|
171
|
-
input:
|
|
193
|
+
description: z2.string().optional(),
|
|
194
|
+
input: z2.record(z2.string(), z2.any()).optional()
|
|
172
195
|
// Default workflow input
|
|
173
196
|
}).strict(),
|
|
174
197
|
// Type 4: TypeScript script file (NEW)
|
|
175
|
-
|
|
176
|
-
script:
|
|
198
|
+
z2.object({
|
|
199
|
+
script: z2.string(),
|
|
177
200
|
// Path to .ts file
|
|
178
|
-
description:
|
|
179
|
-
permissions:
|
|
180
|
-
fs:
|
|
181
|
-
network:
|
|
182
|
-
subprocess:
|
|
201
|
+
description: z2.string().optional(),
|
|
202
|
+
permissions: z2.object({
|
|
203
|
+
fs: z2.enum(["read", "write", "none"]).optional(),
|
|
204
|
+
network: z2.boolean().optional(),
|
|
205
|
+
subprocess: z2.boolean().optional()
|
|
183
206
|
}).optional(),
|
|
184
|
-
timeout:
|
|
207
|
+
timeout: z2.number().int().positive().max(36e5).optional(),
|
|
185
208
|
// Max 1 hour in milliseconds
|
|
186
|
-
memory:
|
|
209
|
+
memory: z2.number().int().positive().min(64).max(8192).optional()
|
|
187
210
|
// 64MB-8GB in MB
|
|
188
211
|
}).strict()
|
|
189
212
|
]);
|
|
190
|
-
var mcpServerConfigSchema =
|
|
191
|
-
command:
|
|
192
|
-
args:
|
|
193
|
-
env:
|
|
194
|
-
tools:
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
provider:
|
|
199
|
-
model:
|
|
200
|
-
parameters:
|
|
213
|
+
var mcpServerConfigSchema = z2.object({
|
|
214
|
+
command: z2.string(),
|
|
215
|
+
args: z2.array(z2.string()).optional(),
|
|
216
|
+
env: z2.record(z2.string(), z2.string()).optional(),
|
|
217
|
+
tools: z2.record(
|
|
218
|
+
z2.string(),
|
|
219
|
+
z2.boolean().or(
|
|
220
|
+
z2.object({
|
|
221
|
+
provider: z2.string().optional(),
|
|
222
|
+
model: z2.string().optional(),
|
|
223
|
+
parameters: z2.record(z2.string(), z2.unknown()).optional()
|
|
201
224
|
}).strict()
|
|
202
225
|
)
|
|
203
226
|
).optional()
|
|
204
227
|
}).strict();
|
|
205
|
-
var
|
|
206
|
-
|
|
207
|
-
|
|
228
|
+
var agentContinuousImprovementSchema = z2.object({
|
|
229
|
+
sleepTimeOnNoTasks: z2.number().int().optional(),
|
|
230
|
+
sleepTimeBetweenTasks: z2.number().int().optional(),
|
|
231
|
+
maxCycles: z2.number().int().optional()
|
|
232
|
+
}).strict().optional();
|
|
233
|
+
var agentDiscoverySchema = z2.object({
|
|
234
|
+
enabledStrategies: z2.array(z2.string()).optional(),
|
|
235
|
+
cacheTime: z2.number().int().optional(),
|
|
236
|
+
checkChanges: z2.boolean().optional()
|
|
237
|
+
}).strict().optional();
|
|
238
|
+
var agentSafetySchema = z2.object({
|
|
239
|
+
enabledChecks: z2.array(z2.string()).optional(),
|
|
240
|
+
blockDestructive: z2.boolean().optional(),
|
|
241
|
+
maxFileSize: z2.number().int().optional()
|
|
242
|
+
}).strict().optional();
|
|
243
|
+
var agentHealthCheckSchema = z2.object({
|
|
244
|
+
enabled: z2.boolean().optional(),
|
|
245
|
+
interval: z2.number().int().optional()
|
|
246
|
+
}).strict().optional();
|
|
247
|
+
var agentApprovalSchema = z2.object({
|
|
248
|
+
level: z2.enum(["none", "destructive", "commits", "all"]).optional(),
|
|
249
|
+
autoApproveSafeTasks: z2.boolean().optional(),
|
|
250
|
+
maxAutoApprovalCost: z2.number().optional()
|
|
251
|
+
}).strict().optional();
|
|
252
|
+
var agentSchema = z2.object({
|
|
253
|
+
preset: z2.string().optional(),
|
|
254
|
+
strategy: z2.enum(["goal-directed", "continuous-improvement"]).optional(),
|
|
255
|
+
continueOnCompletion: z2.boolean().optional(),
|
|
256
|
+
maxIterations: z2.number().int().optional(),
|
|
257
|
+
timeout: z2.number().int().optional(),
|
|
258
|
+
requireApprovalFor: z2.enum(["none", "destructive", "commits", "all"]).optional(),
|
|
259
|
+
autoApproveSafeTasks: z2.boolean().optional(),
|
|
260
|
+
maxAutoApprovalCost: z2.number().optional(),
|
|
261
|
+
pauseOnError: z2.boolean().optional(),
|
|
262
|
+
workingBranch: z2.string().optional(),
|
|
263
|
+
destructiveOperations: z2.array(z2.string()).optional(),
|
|
264
|
+
maxConcurrency: z2.number().int().optional(),
|
|
265
|
+
autoSaveInterval: z2.number().int().optional(),
|
|
266
|
+
workingDir: z2.string().optional(),
|
|
267
|
+
continuousImprovement: agentContinuousImprovementSchema,
|
|
268
|
+
discovery: agentDiscoverySchema,
|
|
269
|
+
safety: agentSafetySchema,
|
|
270
|
+
healthCheck: agentHealthCheckSchema,
|
|
271
|
+
approval: agentApprovalSchema
|
|
272
|
+
}).strict().optional();
|
|
273
|
+
var configSchema = z2.object({
|
|
274
|
+
prices: z2.record(
|
|
275
|
+
z2.string(),
|
|
208
276
|
// provider
|
|
209
|
-
|
|
210
|
-
|
|
277
|
+
z2.record(
|
|
278
|
+
z2.string(),
|
|
211
279
|
// model
|
|
212
|
-
|
|
213
|
-
inputPrice:
|
|
214
|
-
outputPrice:
|
|
215
|
-
cacheWritesPrice:
|
|
216
|
-
cacheReadsPrice:
|
|
280
|
+
z2.object({
|
|
281
|
+
inputPrice: z2.number().optional(),
|
|
282
|
+
outputPrice: z2.number().optional(),
|
|
283
|
+
cacheWritesPrice: z2.number().optional(),
|
|
284
|
+
cacheReadsPrice: z2.number().optional()
|
|
217
285
|
})
|
|
218
286
|
)
|
|
219
287
|
).optional(),
|
|
220
|
-
providers:
|
|
221
|
-
defaultProvider:
|
|
222
|
-
defaultModel:
|
|
223
|
-
defaultParameters:
|
|
224
|
-
maxMessageCount:
|
|
225
|
-
budget:
|
|
226
|
-
retryCount:
|
|
227
|
-
requestTimeoutSeconds:
|
|
228
|
-
summaryThreshold:
|
|
229
|
-
scripts:
|
|
230
|
-
commands:
|
|
231
|
-
tools:
|
|
232
|
-
search: providerModelSchema.or(
|
|
288
|
+
providers: z2.record(z2.string(), providerConfigSchema).optional(),
|
|
289
|
+
defaultProvider: z2.string().optional(),
|
|
290
|
+
defaultModel: z2.string().optional(),
|
|
291
|
+
defaultParameters: z2.record(z2.string(), z2.any()).optional(),
|
|
292
|
+
maxMessageCount: z2.number().int().positive().optional(),
|
|
293
|
+
budget: z2.number().positive().optional(),
|
|
294
|
+
retryCount: z2.number().int().min(0).optional(),
|
|
295
|
+
requestTimeoutSeconds: z2.number().int().positive().optional(),
|
|
296
|
+
summaryThreshold: z2.number().int().positive().optional(),
|
|
297
|
+
scripts: z2.record(z2.string(), scriptSchema).optional(),
|
|
298
|
+
commands: z2.record(z2.string(), providerModelSchema).optional(),
|
|
299
|
+
tools: z2.object({
|
|
300
|
+
search: providerModelSchema.or(z2.boolean()).optional()
|
|
233
301
|
}).optional(),
|
|
234
|
-
mcpServers:
|
|
235
|
-
rules:
|
|
236
|
-
excludeFiles:
|
|
302
|
+
mcpServers: z2.record(z2.string(), mcpServerConfigSchema).optional(),
|
|
303
|
+
rules: z2.array(ruleSchema).optional().or(z2.string()).optional(),
|
|
304
|
+
excludeFiles: z2.array(z2.string()).optional(),
|
|
305
|
+
agent: agentSchema,
|
|
306
|
+
memory: memoryConfigSchema
|
|
237
307
|
}).strict().nullish();
|
|
238
308
|
|
|
239
309
|
// src/fs/node-provider.ts
|
|
@@ -336,11 +406,11 @@ import { parse } from "yaml";
|
|
|
336
406
|
import { ZodError } from "zod";
|
|
337
407
|
|
|
338
408
|
// src/skills/types.ts
|
|
339
|
-
import { z as
|
|
340
|
-
var skillMetadataSchema =
|
|
341
|
-
name:
|
|
342
|
-
description:
|
|
343
|
-
allowedTools:
|
|
409
|
+
import { z as z3 } from "zod";
|
|
410
|
+
var skillMetadataSchema = z3.object({
|
|
411
|
+
name: z3.string().regex(/^[a-z0-9-]+$/, "Skill name must be lowercase letters, numbers, and hyphens").max(64, "Skill name must be at most 64 characters"),
|
|
412
|
+
description: z3.string().max(1024, "Description must be at most 1024 characters"),
|
|
413
|
+
allowedTools: z3.array(z3.string()).optional()
|
|
344
414
|
});
|
|
345
415
|
var SkillDiscoveryError = class extends Error {
|
|
346
416
|
constructor(message, path) {
|
|
@@ -754,19 +824,19 @@ function getSkillStats(skill) {
|
|
|
754
824
|
}
|
|
755
825
|
|
|
756
826
|
// src/skills/tools/listSkills.ts
|
|
757
|
-
import { z as
|
|
758
|
-
var ListSkillsInputSchema =
|
|
759
|
-
filter:
|
|
827
|
+
import { z as z4 } from "zod";
|
|
828
|
+
var ListSkillsInputSchema = z4.object({
|
|
829
|
+
filter: z4.string().optional().describe("Optional filter string to match against skill names and descriptions")
|
|
760
830
|
});
|
|
761
|
-
var ListSkillsOutputSchema =
|
|
762
|
-
skills:
|
|
763
|
-
|
|
764
|
-
name:
|
|
765
|
-
description:
|
|
766
|
-
source:
|
|
831
|
+
var ListSkillsOutputSchema = z4.object({
|
|
832
|
+
skills: z4.array(
|
|
833
|
+
z4.object({
|
|
834
|
+
name: z4.string(),
|
|
835
|
+
description: z4.string(),
|
|
836
|
+
source: z4.enum(["personal", "project", "plugin"])
|
|
767
837
|
})
|
|
768
838
|
),
|
|
769
|
-
total:
|
|
839
|
+
total: z4.number()
|
|
770
840
|
});
|
|
771
841
|
async function listSkills(input, context) {
|
|
772
842
|
const { filter } = input;
|
|
@@ -792,20 +862,20 @@ var listSkillsToolInfo = {
|
|
|
792
862
|
};
|
|
793
863
|
|
|
794
864
|
// src/skills/tools/loadSkill.ts
|
|
795
|
-
import { z as
|
|
796
|
-
var LoadSkillInputSchema =
|
|
797
|
-
skillName:
|
|
865
|
+
import { z as z5 } from "zod";
|
|
866
|
+
var LoadSkillInputSchema = z5.object({
|
|
867
|
+
skillName: z5.string().describe("The name of the skill to load")
|
|
798
868
|
});
|
|
799
|
-
var LoadSkillOutputSchema =
|
|
800
|
-
success:
|
|
801
|
-
skill:
|
|
802
|
-
name:
|
|
803
|
-
description:
|
|
804
|
-
content:
|
|
805
|
-
availableFiles:
|
|
869
|
+
var LoadSkillOutputSchema = z5.object({
|
|
870
|
+
success: z5.boolean(),
|
|
871
|
+
skill: z5.object({
|
|
872
|
+
name: z5.string(),
|
|
873
|
+
description: z5.string(),
|
|
874
|
+
content: z5.string(),
|
|
875
|
+
availableFiles: z5.array(z5.string())
|
|
806
876
|
}).optional(),
|
|
807
|
-
error:
|
|
808
|
-
warnings:
|
|
877
|
+
error: z5.string().optional(),
|
|
878
|
+
warnings: z5.array(z5.string()).optional()
|
|
809
879
|
});
|
|
810
880
|
async function loadSkill(input, context) {
|
|
811
881
|
const { skillName } = input;
|
|
@@ -854,15 +924,15 @@ var loadSkillToolInfo = {
|
|
|
854
924
|
};
|
|
855
925
|
|
|
856
926
|
// src/skills/tools/readSkillFile.ts
|
|
857
|
-
import { z as
|
|
858
|
-
var ReadSkillFileInputSchema =
|
|
859
|
-
skillName:
|
|
860
|
-
filename:
|
|
927
|
+
import { z as z6 } from "zod";
|
|
928
|
+
var ReadSkillFileInputSchema = z6.object({
|
|
929
|
+
skillName: z6.string().describe("The name of the skill"),
|
|
930
|
+
filename: z6.string().describe('The name of the file to read (e.g., "reference.md", "scripts/helper.py")')
|
|
861
931
|
});
|
|
862
|
-
var ReadSkillFileOutputSchema =
|
|
863
|
-
success:
|
|
864
|
-
content:
|
|
865
|
-
error:
|
|
932
|
+
var ReadSkillFileOutputSchema = z6.object({
|
|
933
|
+
success: z6.boolean(),
|
|
934
|
+
content: z6.string().optional(),
|
|
935
|
+
error: z6.string().optional()
|
|
866
936
|
});
|
|
867
937
|
async function readSkillFile(input, context) {
|
|
868
938
|
const { skillName, filename } = input;
|
|
@@ -900,16 +970,16 @@ var readSkillFileToolInfo = {
|
|
|
900
970
|
};
|
|
901
971
|
|
|
902
972
|
// src/tools/askFollowupQuestion.ts
|
|
903
|
-
import { z as
|
|
904
|
-
var questionObject =
|
|
905
|
-
prompt:
|
|
906
|
-
options:
|
|
973
|
+
import { z as z7 } from "zod";
|
|
974
|
+
var questionObject = z7.object({
|
|
975
|
+
prompt: z7.string().describe("The text of the question.").meta({ usageValue: "question text here" }),
|
|
976
|
+
options: z7.array(z7.string()).default([]).describe("Ordered list of suggested answers (omit if none).").meta({ usageValue: "suggested answer here" })
|
|
907
977
|
});
|
|
908
978
|
var toolInfo = {
|
|
909
979
|
name: "askFollowupQuestion",
|
|
910
980
|
description: "Call this when vital details are missing. Pose each follow-up as one direct, unambiguous question. If it speeds the reply, add up to five short, mutually-exclusive answer options. Group any related questions in the same call to avoid a back-and-forth chain.",
|
|
911
|
-
parameters:
|
|
912
|
-
questions:
|
|
981
|
+
parameters: z7.object({
|
|
982
|
+
questions: z7.array(questionObject).describe("One or more follow-up questions you need answered before you can continue.").meta({ usageValue: "questions here" })
|
|
913
983
|
}).meta({
|
|
914
984
|
examples: [
|
|
915
985
|
{
|
|
@@ -997,18 +1067,41 @@ var askFollowupQuestion_default = {
|
|
|
997
1067
|
};
|
|
998
1068
|
|
|
999
1069
|
// src/tools/executeCommand.ts
|
|
1000
|
-
import { z as
|
|
1070
|
+
import { z as z8 } from "zod";
|
|
1001
1071
|
|
|
1002
|
-
// src/tools/
|
|
1003
|
-
function
|
|
1072
|
+
// src/tools/response-builders.ts
|
|
1073
|
+
function createSuccessResponse(value, type = "text") {
|
|
1074
|
+
return {
|
|
1075
|
+
success: true,
|
|
1076
|
+
message: { type, value }
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
function createErrorResponse(message) {
|
|
1080
|
+
return {
|
|
1081
|
+
success: false,
|
|
1082
|
+
message: { type: "error-text", value: message }
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
function createProviderErrorResponse(capability) {
|
|
1004
1086
|
return {
|
|
1005
1087
|
success: false,
|
|
1006
1088
|
message: {
|
|
1007
1089
|
type: "error-text",
|
|
1008
|
-
value: `Not possible to ${
|
|
1090
|
+
value: `Not possible to ${capability}.`
|
|
1009
1091
|
}
|
|
1010
1092
|
};
|
|
1011
1093
|
}
|
|
1094
|
+
function createValidationErrorResponse(errors) {
|
|
1095
|
+
return {
|
|
1096
|
+
success: false,
|
|
1097
|
+
message: {
|
|
1098
|
+
type: "error-text",
|
|
1099
|
+
value: `Validation failed: ${errors.message}`
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
// src/tools/utils.ts
|
|
1012
1105
|
function preprocessBoolean(val) {
|
|
1013
1106
|
return typeof val === "string" ? val.toLowerCase() === "true" : val;
|
|
1014
1107
|
}
|
|
@@ -1029,9 +1122,9 @@ function createFileElement(tagName, path, content, attrs) {
|
|
|
1029
1122
|
var toolInfo2 = {
|
|
1030
1123
|
name: "executeCommand",
|
|
1031
1124
|
description: "Run a single CLI command. The command is always executed in the project-root working directory (regardless of earlier commands). Prefer one-off shell commands over wrapper scripts for flexibility. **IMPORTANT**: After an `execute_command` call, you MUST stop and NOT allowed to make further tool calls in the same message.",
|
|
1032
|
-
parameters:
|
|
1033
|
-
command:
|
|
1034
|
-
requiresApproval:
|
|
1125
|
+
parameters: z8.object({
|
|
1126
|
+
command: z8.string().describe("The exact command to run (valid for the current OS). It must be correctly formatted and free of harmful instructions.").meta({ usageValue: "your-command-here" }),
|
|
1127
|
+
requiresApproval: z8.preprocess(preprocessBoolean, z8.boolean().optional().default(false)).describe(
|
|
1035
1128
|
"Set to `true` for commands that install/uninstall software, modify or delete files, change system settings, perform network operations, or have other side effects. Use `false` for safe, read-only, or purely local development actions (e.g., listing files, make a build, running tests)."
|
|
1036
1129
|
).meta({ usageValue: "true | false" })
|
|
1037
1130
|
}).meta({
|
|
@@ -1048,7 +1141,7 @@ var toolInfo2 = {
|
|
|
1048
1141
|
};
|
|
1049
1142
|
var handler2 = async (provider, args) => {
|
|
1050
1143
|
if (!provider.executeCommand) {
|
|
1051
|
-
return
|
|
1144
|
+
return createProviderErrorResponse("execute command. Abort");
|
|
1052
1145
|
}
|
|
1053
1146
|
const { command, requiresApproval } = toolInfo2.parameters.parse(args);
|
|
1054
1147
|
try {
|
|
@@ -1102,16 +1195,16 @@ var executeCommand_default = {
|
|
|
1102
1195
|
};
|
|
1103
1196
|
|
|
1104
1197
|
// src/tools/fetchUrl.ts
|
|
1105
|
-
import { z as
|
|
1198
|
+
import { z as z9 } from "zod";
|
|
1106
1199
|
var toolInfo3 = {
|
|
1107
1200
|
name: "fetchUrl",
|
|
1108
1201
|
description: "Fetch the content located at one or more HTTP(S) URLs and return it in Markdown format. This works for standard web pages as well as raw files (e.g. README.md, source code) hosted on platforms like GitHub.",
|
|
1109
|
-
parameters:
|
|
1110
|
-
url:
|
|
1202
|
+
parameters: z9.object({
|
|
1203
|
+
url: z9.preprocess((val) => {
|
|
1111
1204
|
if (!val) return [];
|
|
1112
1205
|
const values = Array.isArray(val) ? val : [val];
|
|
1113
1206
|
return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
|
|
1114
|
-
},
|
|
1207
|
+
}, z9.array(z9.string())).describe("One or more URLs to fetch, separated by commas if multiple.").meta({ usageValue: "url" })
|
|
1115
1208
|
}).meta({
|
|
1116
1209
|
examples: [
|
|
1117
1210
|
{
|
|
@@ -1180,15 +1273,15 @@ var fetchUrl_default = {
|
|
|
1180
1273
|
};
|
|
1181
1274
|
|
|
1182
1275
|
// src/tools/listFiles.ts
|
|
1183
|
-
import { z as
|
|
1276
|
+
import { z as z10 } from "zod";
|
|
1184
1277
|
var toolInfo4 = {
|
|
1185
1278
|
name: "listFiles",
|
|
1186
1279
|
description: "Request to list files and directories within the specified directory. If recursive is true, it will list all files and directories recursively. If recursive is false or not provided, it will only list the top-level contents. Do not use this tool to confirm the existence of files you may have created, as the user will let you know if the files were created successfully or not.",
|
|
1187
|
-
parameters:
|
|
1188
|
-
path:
|
|
1189
|
-
maxCount:
|
|
1190
|
-
recursive:
|
|
1191
|
-
includeIgnored:
|
|
1280
|
+
parameters: z10.object({
|
|
1281
|
+
path: z10.string().describe("The path of the directory to list contents for (relative to the current working directory)").meta({ usageValue: "Directory path here" }),
|
|
1282
|
+
maxCount: z10.coerce.number().optional().default(2e3).describe("The maximum number of files to list. Default to 2000").meta({ usageValue: "Maximum number of files to list (optional)" }),
|
|
1283
|
+
recursive: z10.preprocess(preprocessBoolean, z10.boolean().optional().default(true)).describe("Whether to list files recursively. Use true for recursive listing, false or omit for top-level only.").meta({ usageValue: "true or false (optional)" }),
|
|
1284
|
+
includeIgnored: z10.preprocess(preprocessBoolean, z10.boolean().optional().default(false)).describe("Whether to include ignored files. Use true to include files ignored by .gitignore.").meta({ usageValue: "true or false (optional)" })
|
|
1192
1285
|
}).meta({
|
|
1193
1286
|
examples: [
|
|
1194
1287
|
{
|
|
@@ -1203,7 +1296,7 @@ var toolInfo4 = {
|
|
|
1203
1296
|
};
|
|
1204
1297
|
var handler4 = async (provider, args) => {
|
|
1205
1298
|
if (!provider.listFiles) {
|
|
1206
|
-
return
|
|
1299
|
+
return createProviderErrorResponse("list files");
|
|
1207
1300
|
}
|
|
1208
1301
|
const { path, maxCount, recursive, includeIgnored } = toolInfo4.parameters.parse(args);
|
|
1209
1302
|
const [files, limitReached] = await provider.listFiles(path, recursive, maxCount, includeIgnored);
|
|
@@ -1286,12 +1379,12 @@ var MockProvider = class {
|
|
|
1286
1379
|
};
|
|
1287
1380
|
|
|
1288
1381
|
// src/tools/readBinaryFile.ts
|
|
1289
|
-
import { z as
|
|
1382
|
+
import { z as z11 } from "zod";
|
|
1290
1383
|
var toolInfo5 = {
|
|
1291
1384
|
name: "readBinaryFile",
|
|
1292
1385
|
description: "Read a binary file from a URL or local path. Use file:// prefix to access local files. This can be used to access non-text files such as PDFs or images.",
|
|
1293
|
-
parameters:
|
|
1294
|
-
url:
|
|
1386
|
+
parameters: z11.object({
|
|
1387
|
+
url: z11.string().describe("The URL or local path of the file to read.")
|
|
1295
1388
|
})
|
|
1296
1389
|
};
|
|
1297
1390
|
var handler5 = async (provider, args) => {
|
|
@@ -1338,17 +1431,43 @@ var readBinaryFile_default = {
|
|
|
1338
1431
|
};
|
|
1339
1432
|
|
|
1340
1433
|
// src/tools/readFile.ts
|
|
1341
|
-
import { z as
|
|
1434
|
+
import { z as z12 } from "zod";
|
|
1342
1435
|
var toolInfo6 = {
|
|
1343
1436
|
name: "readFile",
|
|
1344
|
-
description:
|
|
1345
|
-
|
|
1346
|
-
|
|
1437
|
+
description: `Request to read the contents of one or multiple files at the specified paths.
|
|
1438
|
+
|
|
1439
|
+
When to use:
|
|
1440
|
+
- Examining file contents you don't know
|
|
1441
|
+
- Analyzing code, reviewing text files, extracting configuration info
|
|
1442
|
+
- Reading multiple files at once (use comma-separated paths)
|
|
1443
|
+
- Understanding file structure before editing
|
|
1444
|
+
|
|
1445
|
+
When NOT to use:
|
|
1446
|
+
- For file existence checks: Use listFiles instead
|
|
1447
|
+
- For searching within files: Use grep instead
|
|
1448
|
+
- For file name searches: Use searchFiles instead
|
|
1449
|
+
- Prefer this tool over executeCommand with cat/head/tail
|
|
1450
|
+
|
|
1451
|
+
Features:
|
|
1452
|
+
- Supports comma-separated paths for multiple files
|
|
1453
|
+
- Line numbers included for easy reference
|
|
1454
|
+
- Optional offset/limit for partial file reading
|
|
1455
|
+
- Automatically handles different file types
|
|
1456
|
+
|
|
1457
|
+
IMPORTANT:
|
|
1458
|
+
- Line numbers are included for easy reference
|
|
1459
|
+
- Use offset/limit for large files to read specific sections`,
|
|
1460
|
+
parameters: z12.object({
|
|
1461
|
+
path: z12.preprocess((val) => {
|
|
1347
1462
|
if (!val) return [];
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1463
|
+
if (Array.isArray(val)) {
|
|
1464
|
+
return val.filter((s) => typeof s === "string" && s.length > 0);
|
|
1465
|
+
}
|
|
1466
|
+
return val.split(",").filter((s) => s.length > 0);
|
|
1467
|
+
}, z12.array(z12.string())).describe("The path of the file to read").meta({ usageValue: "Comma separated paths here" }),
|
|
1468
|
+
offset: z12.number().optional().describe("Skip first N lines (for partial file reading)").meta({ usageValue: "100" }),
|
|
1469
|
+
limit: z12.number().optional().describe("Read at most N lines (for partial file reading)").meta({ usageValue: "50" }),
|
|
1470
|
+
includeIgnored: z12.preprocess(preprocessBoolean, z12.boolean().nullish().default(false)).describe("Whether to include ignored files. Use true to include files ignored by .gitignore.").meta({ usageValue: "true or false (optional)" })
|
|
1352
1471
|
}).meta({
|
|
1353
1472
|
examples: [
|
|
1354
1473
|
{
|
|
@@ -1362,23 +1481,53 @@ var toolInfo6 = {
|
|
|
1362
1481
|
input: {
|
|
1363
1482
|
path: "src/main.js,src/index.js"
|
|
1364
1483
|
}
|
|
1484
|
+
},
|
|
1485
|
+
{
|
|
1486
|
+
description: "Read partial file (lines 100-150)",
|
|
1487
|
+
input: {
|
|
1488
|
+
path: "src/large-file.ts",
|
|
1489
|
+
offset: 100,
|
|
1490
|
+
limit: 50
|
|
1491
|
+
}
|
|
1365
1492
|
}
|
|
1366
1493
|
]
|
|
1367
1494
|
})
|
|
1368
1495
|
};
|
|
1369
1496
|
var handler6 = async (provider, args) => {
|
|
1370
1497
|
if (!provider.readFile) {
|
|
1371
|
-
return
|
|
1498
|
+
return createProviderErrorResponse("read file");
|
|
1499
|
+
}
|
|
1500
|
+
const parsed = toolInfo6.parameters.safeParse(args);
|
|
1501
|
+
if (!parsed.success) {
|
|
1502
|
+
return {
|
|
1503
|
+
success: false,
|
|
1504
|
+
message: {
|
|
1505
|
+
type: "error-text",
|
|
1506
|
+
value: `Invalid arguments for readFile: ${parsed.error.message}`
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1372
1509
|
}
|
|
1373
|
-
const { path: paths, includeIgnored } =
|
|
1510
|
+
const { path: paths, offset, limit, includeIgnored } = parsed.data;
|
|
1374
1511
|
const resp = [];
|
|
1375
1512
|
for (const path of paths) {
|
|
1376
1513
|
const fileContent = await provider.readFile(path, includeIgnored ?? false);
|
|
1377
1514
|
if (!fileContent) {
|
|
1378
1515
|
resp.push(createFileElement("read_file_file_content", path, void 0, { file_not_found: "true" }));
|
|
1379
|
-
|
|
1380
|
-
resp.push(createFileElement("read_file_file_content", path, fileContent));
|
|
1516
|
+
continue;
|
|
1381
1517
|
}
|
|
1518
|
+
let lines = fileContent.split("\n");
|
|
1519
|
+
const start = offset ?? 0;
|
|
1520
|
+
const end = limit ? start + limit : lines.length;
|
|
1521
|
+
if (offset !== void 0 || limit !== void 0) {
|
|
1522
|
+
lines = lines.slice(start, end);
|
|
1523
|
+
}
|
|
1524
|
+
const lineOffset = offset ?? 0;
|
|
1525
|
+
const numberedContent = lines.map((line, i) => {
|
|
1526
|
+
const lineNumber = lineOffset + i + 1;
|
|
1527
|
+
const paddedNumber = String(lineNumber).padStart(6, " ");
|
|
1528
|
+
return `${paddedNumber}\u2192${line}`;
|
|
1529
|
+
}).join("\n");
|
|
1530
|
+
resp.push(createFileElement("read_file_file_content", path, numberedContent));
|
|
1382
1531
|
}
|
|
1383
1532
|
return {
|
|
1384
1533
|
success: true,
|
|
@@ -1394,12 +1543,12 @@ var readFile_default = {
|
|
|
1394
1543
|
};
|
|
1395
1544
|
|
|
1396
1545
|
// src/tools/removeFile.ts
|
|
1397
|
-
import { z as
|
|
1546
|
+
import { z as z13 } from "zod";
|
|
1398
1547
|
var toolInfo7 = {
|
|
1399
1548
|
name: "removeFile",
|
|
1400
1549
|
description: "Request to remove a file at the specified path.",
|
|
1401
|
-
parameters:
|
|
1402
|
-
path:
|
|
1550
|
+
parameters: z13.object({
|
|
1551
|
+
path: z13.string().describe("The path of the file to remove").meta({ usageValue: "File path here" })
|
|
1403
1552
|
}).meta({
|
|
1404
1553
|
examples: [
|
|
1405
1554
|
{
|
|
@@ -1413,7 +1562,7 @@ var toolInfo7 = {
|
|
|
1413
1562
|
};
|
|
1414
1563
|
var handler7 = async (provider, args) => {
|
|
1415
1564
|
if (!provider.removeFile) {
|
|
1416
|
-
return
|
|
1565
|
+
return createProviderErrorResponse("remove file");
|
|
1417
1566
|
}
|
|
1418
1567
|
const parsed = toolInfo7.parameters.safeParse(args);
|
|
1419
1568
|
if (!parsed.success) {
|
|
@@ -1441,13 +1590,13 @@ var removeFile_default = {
|
|
|
1441
1590
|
};
|
|
1442
1591
|
|
|
1443
1592
|
// src/tools/renameFile.ts
|
|
1444
|
-
import { z as
|
|
1593
|
+
import { z as z14 } from "zod";
|
|
1445
1594
|
var toolInfo8 = {
|
|
1446
1595
|
name: "renameFile",
|
|
1447
1596
|
description: "Request to rename a file from source path to target path.",
|
|
1448
|
-
parameters:
|
|
1449
|
-
source_path:
|
|
1450
|
-
target_path:
|
|
1597
|
+
parameters: z14.object({
|
|
1598
|
+
source_path: z14.string().describe("The current path of the file").meta({ usageValue: "Source file path here" }),
|
|
1599
|
+
target_path: z14.string().describe("The new path for the file").meta({ usageValue: "Target file path here" })
|
|
1451
1600
|
}).meta({
|
|
1452
1601
|
examples: [
|
|
1453
1602
|
{
|
|
@@ -1486,7 +1635,7 @@ var renameFile_default = {
|
|
|
1486
1635
|
};
|
|
1487
1636
|
|
|
1488
1637
|
// src/tools/replaceInFile.ts
|
|
1489
|
-
import { z as
|
|
1638
|
+
import { z as z15 } from "zod";
|
|
1490
1639
|
|
|
1491
1640
|
// src/tools/utils/replaceInFile.ts
|
|
1492
1641
|
var replaceInFile = (fileContent, diff) => {
|
|
@@ -1582,10 +1731,46 @@ var replaceInFile = (fileContent, diff) => {
|
|
|
1582
1731
|
// src/tools/replaceInFile.ts
|
|
1583
1732
|
var toolInfo9 = {
|
|
1584
1733
|
name: "replaceInFile",
|
|
1585
|
-
description:
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1734
|
+
description: `Request to replace sections of content in an existing file using
|
|
1735
|
+
SEARCH/REPLACE blocks.
|
|
1736
|
+
|
|
1737
|
+
When to use:
|
|
1738
|
+
- Making targeted changes to specific parts of a file
|
|
1739
|
+
- Replacing variable names, function signatures, imports
|
|
1740
|
+
- Fixing bugs in existing code
|
|
1741
|
+
- When you know the exact content to replace
|
|
1742
|
+
|
|
1743
|
+
When NOT to use:
|
|
1744
|
+
- For creating new files: Use writeToFile instead
|
|
1745
|
+
- For completely replacing file contents: Use writeToFile instead
|
|
1746
|
+
- When you don't know the exact content: Read file first
|
|
1747
|
+
|
|
1748
|
+
SEARCH/REPLACE FORMAT:
|
|
1749
|
+
<<<<<<< SEARCH
|
|
1750
|
+
[exact content to find]
|
|
1751
|
+
=======
|
|
1752
|
+
[new content to replace with]
|
|
1753
|
+
>>>>>>> REPLACE
|
|
1754
|
+
|
|
1755
|
+
Critical rules:
|
|
1756
|
+
1. SEARCH content must match EXACTLY (character-for-character including whitespace)
|
|
1757
|
+
2. Each block replaces only first occurrence
|
|
1758
|
+
3. Include just enough lines for uniqueness (not too many, not too few)
|
|
1759
|
+
4. Keep blocks concise (don't include long unchanged sections)
|
|
1760
|
+
5. List blocks in order they appear in file
|
|
1761
|
+
6. Use multiple blocks for multiple independent changes
|
|
1762
|
+
|
|
1763
|
+
Special operations:
|
|
1764
|
+
- Move code: Two blocks (delete from original + insert at new location)
|
|
1765
|
+
- Delete code: Empty REPLACE section
|
|
1766
|
+
|
|
1767
|
+
IMPORTANT CONSTRAINTS:
|
|
1768
|
+
- SEARCH text must match file content exactly
|
|
1769
|
+
- Each block is independent (doesn't affect other blocks)
|
|
1770
|
+
- Cannot use for appending or inserting without SEARCH context`,
|
|
1771
|
+
parameters: z15.object({
|
|
1772
|
+
path: z15.string().describe("The path of the file to modify").meta({ usageValue: "File path here" }),
|
|
1773
|
+
diff: z15.string().describe(
|
|
1589
1774
|
`One or more SEARCH/REPLACE blocks following this exact format:
|
|
1590
1775
|
\`\`\`
|
|
1591
1776
|
<<<<<<< SEARCH
|
|
@@ -1609,7 +1794,7 @@ Critical rules:
|
|
|
1609
1794
|
* Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
|
|
1610
1795
|
4. Special operations:
|
|
1611
1796
|
* To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
|
|
1612
|
-
* To delete code:
|
|
1797
|
+
* To delete code: Empty REPLACE section`
|
|
1613
1798
|
).meta({ usageValue: "Search and replace blocks here" })
|
|
1614
1799
|
}).meta({
|
|
1615
1800
|
examples: [
|
|
@@ -1771,12 +1956,12 @@ var replaceInFile_default = {
|
|
|
1771
1956
|
};
|
|
1772
1957
|
|
|
1773
1958
|
// src/tools/search.ts
|
|
1774
|
-
import { z as
|
|
1959
|
+
import { z as z16 } from "zod";
|
|
1775
1960
|
var toolInfo10 = {
|
|
1776
1961
|
name: "search",
|
|
1777
1962
|
description: "Search the web for information using Google Search. Use this tool to find current information, facts, news, documentation, or research that is not available in your training data. Returns comprehensive search results with relevant content extracted from the web.",
|
|
1778
|
-
parameters:
|
|
1779
|
-
query:
|
|
1963
|
+
parameters: z16.object({
|
|
1964
|
+
query: z16.string().describe("The query to search for").meta({ usageValue: "Your search query here" })
|
|
1780
1965
|
}).meta({
|
|
1781
1966
|
examples: [
|
|
1782
1967
|
{
|
|
@@ -1826,18 +2011,18 @@ var search_default = {
|
|
|
1826
2011
|
};
|
|
1827
2012
|
|
|
1828
2013
|
// src/tools/searchFiles.ts
|
|
1829
|
-
import { z as
|
|
2014
|
+
import { z as z17 } from "zod";
|
|
1830
2015
|
var toolInfo11 = {
|
|
1831
2016
|
name: "searchFiles",
|
|
1832
2017
|
description: "Request to perform a regex search across files in a specified directory, outputting context-rich results that include surrounding lines. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.",
|
|
1833
|
-
parameters:
|
|
1834
|
-
path:
|
|
2018
|
+
parameters: z17.object({
|
|
2019
|
+
path: z17.string().describe(
|
|
1835
2020
|
"The path of the directory to search in (relative to the current working directory). This directory will be recursively searched."
|
|
1836
2021
|
).meta({ usageValue: "Directory path here" }),
|
|
1837
|
-
regex:
|
|
2022
|
+
regex: z17.string().describe("The regular expression pattern to search for. Uses Rust regex syntax.").meta({
|
|
1838
2023
|
usageValue: "Your regex pattern here"
|
|
1839
2024
|
}),
|
|
1840
|
-
filePattern:
|
|
2025
|
+
filePattern: z17.string().optional().describe(
|
|
1841
2026
|
'Comma-separated glob pattern to filter files (e.g., "*.ts" for TypeScript files or "*.ts,*.js" for both TypeScript and JavaScript files). If not provided, it will search all files (*).'
|
|
1842
2027
|
).meta({
|
|
1843
2028
|
usageValue: "file pattern here (optional)"
|
|
@@ -1907,20 +2092,20 @@ var searchFiles_default = {
|
|
|
1907
2092
|
};
|
|
1908
2093
|
|
|
1909
2094
|
// src/tools/todo.ts
|
|
1910
|
-
import { z as
|
|
1911
|
-
var TodoStatus =
|
|
1912
|
-
var TodoItemSchema =
|
|
1913
|
-
id:
|
|
1914
|
-
title:
|
|
1915
|
-
description:
|
|
2095
|
+
import { z as z18 } from "zod";
|
|
2096
|
+
var TodoStatus = z18.enum(["open", "completed", "closed"]);
|
|
2097
|
+
var TodoItemSchema = z18.object({
|
|
2098
|
+
id: z18.string(),
|
|
2099
|
+
title: z18.string(),
|
|
2100
|
+
description: z18.string(),
|
|
1916
2101
|
status: TodoStatus
|
|
1917
2102
|
});
|
|
1918
|
-
var UpdateTodoItemInputSchema =
|
|
1919
|
-
operation:
|
|
1920
|
-
id:
|
|
1921
|
-
parentId:
|
|
1922
|
-
title:
|
|
1923
|
-
description:
|
|
2103
|
+
var UpdateTodoItemInputSchema = z18.object({
|
|
2104
|
+
operation: z18.enum(["add", "update"]),
|
|
2105
|
+
id: z18.string().nullish(),
|
|
2106
|
+
parentId: z18.string().nullish(),
|
|
2107
|
+
title: z18.string().nullish(),
|
|
2108
|
+
description: z18.string().nullish(),
|
|
1924
2109
|
status: TodoStatus.nullish()
|
|
1925
2110
|
}).superRefine((data, ctx) => {
|
|
1926
2111
|
if (data.operation === "add") {
|
|
@@ -1941,18 +2126,38 @@ var UpdateTodoItemInputSchema = z17.object({
|
|
|
1941
2126
|
}
|
|
1942
2127
|
}
|
|
1943
2128
|
});
|
|
1944
|
-
var UpdateTodoItemOutputSchema =
|
|
1945
|
-
id:
|
|
2129
|
+
var UpdateTodoItemOutputSchema = z18.object({
|
|
2130
|
+
id: z18.string()
|
|
1946
2131
|
});
|
|
1947
2132
|
|
|
1948
2133
|
// src/tools/writeToFile.ts
|
|
1949
|
-
import { z as
|
|
2134
|
+
import { z as z19 } from "zod";
|
|
1950
2135
|
var toolInfo12 = {
|
|
1951
2136
|
name: "writeToFile",
|
|
1952
|
-
description:
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
2137
|
+
description: `Request to write content to a file at the specified path.
|
|
2138
|
+
|
|
2139
|
+
When to use:
|
|
2140
|
+
- Creating new files
|
|
2141
|
+
- Completely replacing file contents
|
|
2142
|
+
- When you have the complete intended content
|
|
2143
|
+
|
|
2144
|
+
When NOT to use:
|
|
2145
|
+
- For modifying existing files: Use replaceInFile instead
|
|
2146
|
+
- For appending content: Use executeCommand with echo >> instead
|
|
2147
|
+
- For targeted edits: Use replaceInFile instead
|
|
2148
|
+
|
|
2149
|
+
Features:
|
|
2150
|
+
- Automatically creates any directories needed
|
|
2151
|
+
- Overwrites existing files completely
|
|
2152
|
+
- Must provide complete file content (no truncation)
|
|
2153
|
+
|
|
2154
|
+
IMPORTANT CONSTRAINT:
|
|
2155
|
+
- Always provide COMPLETE intended content (no omissions)
|
|
2156
|
+
- Ensure no incorrect escape sequences (<, >, &)
|
|
2157
|
+
- Ensure no unwanted CDATA tags in content`,
|
|
2158
|
+
parameters: z19.object({
|
|
2159
|
+
path: z19.string().describe("The path of the file to write to").meta({ usageValue: "File path here" }),
|
|
2160
|
+
content: z19.string().describe(
|
|
1956
2161
|
"The content to write to the file. ALWAYS provide the COMPLETE intended content of the file, without any truncation or omissions. You MUST include ALL parts of the file, even if they haven't been modified."
|
|
1957
2162
|
).meta({ usageValue: "Your file content here" })
|
|
1958
2163
|
}).meta({
|
|
@@ -1980,7 +2185,7 @@ export default App;
|
|
|
1980
2185
|
};
|
|
1981
2186
|
var handler12 = async (provider, args) => {
|
|
1982
2187
|
if (!provider.writeFile) {
|
|
1983
|
-
return
|
|
2188
|
+
return createProviderErrorResponse("write file");
|
|
1984
2189
|
}
|
|
1985
2190
|
const parsed = toolInfo12.parameters.safeParse(args);
|
|
1986
2191
|
if (!parsed.success) {
|
|
@@ -1992,9 +2197,7 @@ var handler12 = async (provider, args) => {
|
|
|
1992
2197
|
}
|
|
1993
2198
|
};
|
|
1994
2199
|
}
|
|
1995
|
-
|
|
1996
|
-
const trimmedContent = content.trim();
|
|
1997
|
-
if (trimmedContent.startsWith("<![CDATA[") && trimmedContent.endsWith("]]>")) content = trimmedContent.slice(9, -3);
|
|
2200
|
+
const { path, content } = parsed.data;
|
|
1998
2201
|
await provider.writeFile(path, content);
|
|
1999
2202
|
return {
|
|
2000
2203
|
success: true,
|
|
@@ -2159,7 +2362,7 @@ var UsageMeter = class {
|
|
|
2159
2362
|
|
|
2160
2363
|
// src/workflow/agent.workflow.ts
|
|
2161
2364
|
import { jsonSchema } from "ai";
|
|
2162
|
-
import { toJSONSchema, z as
|
|
2365
|
+
import { toJSONSchema, z as z20 } from "zod";
|
|
2163
2366
|
|
|
2164
2367
|
// src/workflow/types.ts
|
|
2165
2368
|
var TaskEventKind = /* @__PURE__ */ ((TaskEventKind2) => {
|
|
@@ -2243,7 +2446,7 @@ var agentWorkflow = async (input, { step, tools, logger }) => {
|
|
|
2243
2446
|
}
|
|
2244
2447
|
const validated = input.outputSchema.safeParse(parsed.data);
|
|
2245
2448
|
if (!validated.success) {
|
|
2246
|
-
const errorMessage = `Output validation failed. Error: ${
|
|
2449
|
+
const errorMessage = `Output validation failed. Error: ${z20.prettifyError(validated.error)}. Please correct the output.`;
|
|
2247
2450
|
nextMessage = [{ role: "user", content: errorMessage }];
|
|
2248
2451
|
continue;
|
|
2249
2452
|
}
|
|
@@ -2325,63 +2528,63 @@ var agentWorkflow = async (input, { step, tools, logger }) => {
|
|
|
2325
2528
|
|
|
2326
2529
|
// src/workflow/dynamic.ts
|
|
2327
2530
|
import { parse as parse2 } from "yaml";
|
|
2328
|
-
import { z as
|
|
2531
|
+
import { z as z22 } from "zod";
|
|
2329
2532
|
|
|
2330
2533
|
// src/workflow/dynamic-types.ts
|
|
2331
|
-
import { z as
|
|
2332
|
-
var WorkflowInputDefinitionSchema =
|
|
2333
|
-
id:
|
|
2334
|
-
description:
|
|
2335
|
-
default:
|
|
2534
|
+
import { z as z21 } from "zod";
|
|
2535
|
+
var WorkflowInputDefinitionSchema = z21.object({
|
|
2536
|
+
id: z21.string(),
|
|
2537
|
+
description: z21.string().nullish(),
|
|
2538
|
+
default: z21.any().nullish()
|
|
2336
2539
|
});
|
|
2337
|
-
var WorkflowStepDefinitionSchema =
|
|
2338
|
-
id:
|
|
2339
|
-
tools:
|
|
2340
|
-
task:
|
|
2341
|
-
output:
|
|
2342
|
-
expected_outcome:
|
|
2540
|
+
var WorkflowStepDefinitionSchema = z21.object({
|
|
2541
|
+
id: z21.string(),
|
|
2542
|
+
tools: z21.array(z21.string()).nullish(),
|
|
2543
|
+
task: z21.string(),
|
|
2544
|
+
output: z21.string().nullish(),
|
|
2545
|
+
expected_outcome: z21.string().nullish(),
|
|
2343
2546
|
/**
|
|
2344
2547
|
* Optional JSON schema or other metadata for future structured outputs.
|
|
2345
2548
|
* Not interpreted by core today.
|
|
2346
2549
|
*/
|
|
2347
|
-
outputSchema:
|
|
2550
|
+
outputSchema: z21.any().nullish(),
|
|
2348
2551
|
/**
|
|
2349
2552
|
* Optional timeout in milliseconds. Step execution will be aborted if it exceeds this duration.
|
|
2350
2553
|
*/
|
|
2351
|
-
timeout:
|
|
2554
|
+
timeout: z21.number().positive().nullish()
|
|
2352
2555
|
});
|
|
2353
|
-
var WhileLoopStepSchema =
|
|
2354
|
-
id:
|
|
2355
|
-
while:
|
|
2356
|
-
condition:
|
|
2357
|
-
steps:
|
|
2556
|
+
var WhileLoopStepSchema = z21.object({
|
|
2557
|
+
id: z21.string(),
|
|
2558
|
+
while: z21.object({
|
|
2559
|
+
condition: z21.string().describe("JavaScript expression that evaluates to true/false"),
|
|
2560
|
+
steps: z21.array(z21.lazy(() => WorkflowControlFlowStepSchema))
|
|
2358
2561
|
}),
|
|
2359
|
-
output:
|
|
2562
|
+
output: z21.string().nullish()
|
|
2360
2563
|
});
|
|
2361
|
-
var IfElseStepSchema =
|
|
2362
|
-
id:
|
|
2363
|
-
if:
|
|
2364
|
-
condition:
|
|
2365
|
-
thenBranch:
|
|
2366
|
-
elseBranch:
|
|
2564
|
+
var IfElseStepSchema = z21.object({
|
|
2565
|
+
id: z21.string(),
|
|
2566
|
+
if: z21.object({
|
|
2567
|
+
condition: z21.string().describe("JavaScript expression that evaluates to true/false"),
|
|
2568
|
+
thenBranch: z21.array(z21.lazy(() => WorkflowControlFlowStepSchema)),
|
|
2569
|
+
elseBranch: z21.array(z21.lazy(() => WorkflowControlFlowStepSchema)).optional()
|
|
2367
2570
|
}),
|
|
2368
|
-
output:
|
|
2571
|
+
output: z21.string().nullish()
|
|
2369
2572
|
});
|
|
2370
|
-
var BreakStepSchema =
|
|
2371
|
-
break:
|
|
2573
|
+
var BreakStepSchema = z21.object({
|
|
2574
|
+
break: z21.literal(true)
|
|
2372
2575
|
});
|
|
2373
|
-
var ContinueStepSchema =
|
|
2374
|
-
continue:
|
|
2576
|
+
var ContinueStepSchema = z21.object({
|
|
2577
|
+
continue: z21.literal(true)
|
|
2375
2578
|
});
|
|
2376
|
-
var TryCatchStepSchema =
|
|
2377
|
-
id:
|
|
2378
|
-
try:
|
|
2379
|
-
trySteps:
|
|
2380
|
-
catchSteps:
|
|
2579
|
+
var TryCatchStepSchema = z21.object({
|
|
2580
|
+
id: z21.string(),
|
|
2581
|
+
try: z21.object({
|
|
2582
|
+
trySteps: z21.array(z21.lazy(() => WorkflowControlFlowStepSchema)),
|
|
2583
|
+
catchSteps: z21.array(z21.lazy(() => WorkflowControlFlowStepSchema))
|
|
2381
2584
|
}),
|
|
2382
|
-
output:
|
|
2585
|
+
output: z21.string().nullish()
|
|
2383
2586
|
});
|
|
2384
|
-
var WorkflowControlFlowStepSchema =
|
|
2587
|
+
var WorkflowControlFlowStepSchema = z21.union([
|
|
2385
2588
|
WorkflowStepDefinitionSchema,
|
|
2386
2589
|
WhileLoopStepSchema,
|
|
2387
2590
|
IfElseStepSchema,
|
|
@@ -2389,14 +2592,14 @@ var WorkflowControlFlowStepSchema = z20.union([
|
|
|
2389
2592
|
ContinueStepSchema,
|
|
2390
2593
|
TryCatchStepSchema
|
|
2391
2594
|
]);
|
|
2392
|
-
var WorkflowDefinitionSchema =
|
|
2393
|
-
task:
|
|
2394
|
-
inputs:
|
|
2395
|
-
steps:
|
|
2396
|
-
output:
|
|
2595
|
+
var WorkflowDefinitionSchema = z21.object({
|
|
2596
|
+
task: z21.string(),
|
|
2597
|
+
inputs: z21.array(WorkflowInputDefinitionSchema).nullish(),
|
|
2598
|
+
steps: z21.array(WorkflowControlFlowStepSchema),
|
|
2599
|
+
output: z21.string().nullish()
|
|
2397
2600
|
});
|
|
2398
|
-
var WorkflowFileSchema =
|
|
2399
|
-
workflows:
|
|
2601
|
+
var WorkflowFileSchema = z21.object({
|
|
2602
|
+
workflows: z21.record(z21.string(), WorkflowDefinitionSchema)
|
|
2400
2603
|
});
|
|
2401
2604
|
|
|
2402
2605
|
// src/workflow/dynamic.ts
|
|
@@ -2405,26 +2608,26 @@ function convertJsonSchemaToZod(schema) {
|
|
|
2405
2608
|
if (schema.enum) {
|
|
2406
2609
|
const enumValues = schema.enum;
|
|
2407
2610
|
if (enumValues.length === 0) {
|
|
2408
|
-
return
|
|
2611
|
+
return z22.never();
|
|
2409
2612
|
}
|
|
2410
2613
|
if (enumValues.every((v) => typeof v === "string")) {
|
|
2411
|
-
return
|
|
2614
|
+
return z22.enum(enumValues);
|
|
2412
2615
|
}
|
|
2413
|
-
const literals = enumValues.map((v) =>
|
|
2616
|
+
const literals = enumValues.map((v) => z22.literal(v));
|
|
2414
2617
|
if (literals.length === 1) {
|
|
2415
2618
|
return literals[0];
|
|
2416
2619
|
}
|
|
2417
|
-
return
|
|
2620
|
+
return z22.union([literals[0], literals[1], ...literals.slice(2)]);
|
|
2418
2621
|
}
|
|
2419
2622
|
if (Array.isArray(schema.type)) {
|
|
2420
2623
|
const types = schema.type;
|
|
2421
2624
|
if (types.includes("null") && types.length === 2) {
|
|
2422
2625
|
const nonNullType = types.find((t) => t !== "null");
|
|
2423
|
-
if (nonNullType === "string") return
|
|
2424
|
-
if (nonNullType === "number") return
|
|
2626
|
+
if (nonNullType === "string") return z22.string().nullable();
|
|
2627
|
+
if (nonNullType === "number") return z22.number().nullable();
|
|
2425
2628
|
if (nonNullType === "integer")
|
|
2426
|
-
return
|
|
2427
|
-
if (nonNullType === "boolean") return
|
|
2629
|
+
return z22.number().refine((val) => Number.isInteger(val)).nullable();
|
|
2630
|
+
if (nonNullType === "boolean") return z22.boolean().nullable();
|
|
2428
2631
|
if (nonNullType === "object") {
|
|
2429
2632
|
const shape = {};
|
|
2430
2633
|
if (schema.properties) {
|
|
@@ -2434,24 +2637,24 @@ function convertJsonSchemaToZod(schema) {
|
|
|
2434
2637
|
shape[propName] = isRequired ? propZod : propZod.optional();
|
|
2435
2638
|
}
|
|
2436
2639
|
}
|
|
2437
|
-
return
|
|
2640
|
+
return z22.object(shape).nullable();
|
|
2438
2641
|
}
|
|
2439
|
-
if (nonNullType === "array") return
|
|
2642
|
+
if (nonNullType === "array") return z22.array(z22.any()).nullable();
|
|
2440
2643
|
}
|
|
2441
|
-
return
|
|
2644
|
+
return z22.any();
|
|
2442
2645
|
}
|
|
2443
2646
|
const type = schema.type;
|
|
2444
2647
|
switch (type) {
|
|
2445
2648
|
case "string":
|
|
2446
|
-
return
|
|
2649
|
+
return z22.string();
|
|
2447
2650
|
case "number":
|
|
2448
|
-
return
|
|
2651
|
+
return z22.number();
|
|
2449
2652
|
case "integer":
|
|
2450
|
-
return
|
|
2653
|
+
return z22.number().refine((val) => Number.isInteger(val), { message: "Expected an integer" });
|
|
2451
2654
|
case "boolean":
|
|
2452
|
-
return
|
|
2655
|
+
return z22.boolean();
|
|
2453
2656
|
case "null":
|
|
2454
|
-
return
|
|
2657
|
+
return z22.null();
|
|
2455
2658
|
case "object": {
|
|
2456
2659
|
const shape = {};
|
|
2457
2660
|
if (schema.properties) {
|
|
@@ -2462,23 +2665,23 @@ function convertJsonSchemaToZod(schema) {
|
|
|
2462
2665
|
}
|
|
2463
2666
|
}
|
|
2464
2667
|
if (schema.additionalProperties === true) {
|
|
2465
|
-
return
|
|
2668
|
+
return z22.object(shape).passthrough();
|
|
2466
2669
|
}
|
|
2467
2670
|
if (typeof schema.additionalProperties === "object") {
|
|
2468
2671
|
const additionalSchema = convertJsonSchemaToZod(schema.additionalProperties);
|
|
2469
|
-
return
|
|
2672
|
+
return z22.intersection(z22.object(shape), z22.record(z22.string(), additionalSchema));
|
|
2470
2673
|
}
|
|
2471
|
-
return
|
|
2674
|
+
return z22.object(shape);
|
|
2472
2675
|
}
|
|
2473
2676
|
case "array": {
|
|
2474
2677
|
if (!schema.items) {
|
|
2475
|
-
return
|
|
2678
|
+
return z22.array(z22.any());
|
|
2476
2679
|
}
|
|
2477
2680
|
const itemSchema = convertJsonSchemaToZod(schema.items);
|
|
2478
|
-
return
|
|
2681
|
+
return z22.array(itemSchema);
|
|
2479
2682
|
}
|
|
2480
2683
|
default:
|
|
2481
|
-
return
|
|
2684
|
+
return z22.any();
|
|
2482
2685
|
}
|
|
2483
2686
|
}
|
|
2484
2687
|
var TOOL_GROUPS = {
|
|
@@ -2549,7 +2752,7 @@ function parseDynamicWorkflowDefinition(source) {
|
|
|
2549
2752
|
const raw = parse2(source);
|
|
2550
2753
|
const validated = WorkflowFileSchema.safeParse(raw);
|
|
2551
2754
|
if (!validated.success) {
|
|
2552
|
-
return { success: false, error:
|
|
2755
|
+
return { success: false, error: z22.prettifyError(validated.error) };
|
|
2553
2756
|
}
|
|
2554
2757
|
const validation = validateWorkflowFile(validated.data);
|
|
2555
2758
|
if (!validation.success) {
|
|
@@ -2842,9 +3045,9 @@ async function executeStepWithAgent(stepDef, workflowId, input, state, context,
|
|
|
2842
3045
|
toolsForAgent.push({
|
|
2843
3046
|
name: "runWorkflow",
|
|
2844
3047
|
description: "Run a named sub-workflow defined in the current workflow file.",
|
|
2845
|
-
parameters:
|
|
2846
|
-
workflowId:
|
|
2847
|
-
input:
|
|
3048
|
+
parameters: z22.object({
|
|
3049
|
+
workflowId: z22.string().describe("Sub-workflow id to run"),
|
|
3050
|
+
input: z22.any().nullish().describe("Optional input object for the sub-workflow")
|
|
2848
3051
|
}),
|
|
2849
3052
|
handler: async () => {
|
|
2850
3053
|
return { success: false, message: { type: "error-text", value: "runWorkflow is virtual." } };
|
|
@@ -3446,6 +3649,7 @@ var makeStepFn = () => {
|
|
|
3446
3649
|
export {
|
|
3447
3650
|
BreakStepSchema,
|
|
3448
3651
|
ContinueStepSchema,
|
|
3652
|
+
DEFAULT_MEMORY_CONFIG,
|
|
3449
3653
|
IGNORED_DIRECTORIES,
|
|
3450
3654
|
IfElseStepSchema,
|
|
3451
3655
|
ListSkillsInputSchema,
|
|
@@ -3484,6 +3688,10 @@ export {
|
|
|
3484
3688
|
convertJsonSchemaToZod,
|
|
3485
3689
|
createContext,
|
|
3486
3690
|
createDynamicWorkflow,
|
|
3691
|
+
createErrorResponse,
|
|
3692
|
+
createProviderErrorResponse,
|
|
3693
|
+
createSuccessResponse,
|
|
3694
|
+
createValidationErrorResponse,
|
|
3487
3695
|
executeCommand_default as executeCommand,
|
|
3488
3696
|
fetchUrl_default as fetchUrl,
|
|
3489
3697
|
fromJsonModelMessage,
|
|
@@ -3495,6 +3703,7 @@ export {
|
|
|
3495
3703
|
loadSkillToolInfo,
|
|
3496
3704
|
makeStepFn,
|
|
3497
3705
|
mcpServerConfigSchema,
|
|
3706
|
+
memoryConfigSchema,
|
|
3498
3707
|
parseDynamicWorkflowDefinition,
|
|
3499
3708
|
parseJsonFromMarkdown,
|
|
3500
3709
|
providerConfigSchema,
|
|
@@ -3507,6 +3716,7 @@ export {
|
|
|
3507
3716
|
renameFile_default as renameFile,
|
|
3508
3717
|
replaceInFile_default as replaceInFile,
|
|
3509
3718
|
replaceInFile as replaceInFileHelper,
|
|
3719
|
+
resolveHomePath,
|
|
3510
3720
|
responsePrompts,
|
|
3511
3721
|
ruleSchema,
|
|
3512
3722
|
scriptSchema,
|