@polka-codes/cli-shared 0.8.22 → 0.8.23

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.
Files changed (2) hide show
  1. package/dist/index.js +167 -65
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -36777,6 +36777,7 @@ __export(exports_allTools, {
36777
36777
  readFile: () => readFile_default,
36778
36778
  listFiles: () => listFiles_default,
36779
36779
  handOver: () => handOver_default,
36780
+ fetchUrl: () => fetchUrl_default,
36780
36781
  executeCommand: () => executeCommand_default,
36781
36782
  delegate: () => delegate_default,
36782
36783
  attemptCompletion: () => attemptCompletion_default,
@@ -37235,8 +37236,89 @@ var executeCommand_default = {
37235
37236
  handler: handler4,
37236
37237
  isAvailable: isAvailable4
37237
37238
  };
37238
- // ../core/src/tools/listFiles.ts
37239
+ // ../core/src/tools/fetchUrl.ts
37239
37240
  var toolInfo5 = {
37241
+ name: "fetch_url",
37242
+ 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.",
37243
+ parameters: [
37244
+ {
37245
+ name: "url",
37246
+ description: "One or more URLs to fetch, separated by commas if multiple.",
37247
+ required: true
37248
+ }
37249
+ ],
37250
+ examples: [
37251
+ {
37252
+ description: "Fetch a single webpage",
37253
+ parameters: [
37254
+ {
37255
+ name: "url",
37256
+ value: "https://example.com"
37257
+ }
37258
+ ]
37259
+ },
37260
+ {
37261
+ description: "Fetch multiple webpages",
37262
+ parameters: [
37263
+ {
37264
+ name: "url",
37265
+ value: "https://example.com,https://developer.mozilla.org/en-US/docs/Web/HTTP"
37266
+ }
37267
+ ]
37268
+ },
37269
+ {
37270
+ description: "Fetch a raw file from GitHub",
37271
+ parameters: [
37272
+ {
37273
+ name: "url",
37274
+ value: "https://raw.githubusercontent.com/user/repo/main/README.md"
37275
+ }
37276
+ ]
37277
+ }
37278
+ ],
37279
+ permissionLevel: 1 /* Read */
37280
+ };
37281
+ var handler5 = async (provider, args) => {
37282
+ if (!provider.fetchUrl) {
37283
+ return {
37284
+ type: "Error" /* Error */,
37285
+ message: "Not possible to fetch url. Abort."
37286
+ };
37287
+ }
37288
+ const urls = getStringArray(args, "url");
37289
+ if (urls.length === 0) {
37290
+ return {
37291
+ type: "Error" /* Error */,
37292
+ message: "No URLs provided. Please provide at least one URL to fetch."
37293
+ };
37294
+ }
37295
+ const results = [];
37296
+ for (const url of urls) {
37297
+ try {
37298
+ const content = provider.fetchUrl(url).then((res) => `<fetch_url_content url="${url}">${res}</fetch_url_content>`);
37299
+ results.push(content);
37300
+ } catch (error) {
37301
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
37302
+ results.push(Promise.resolve(`<fetch_url_error url="${url}">${errorMessage}</fetch_url_error>`));
37303
+ }
37304
+ }
37305
+ const resolvedResults = await Promise.all(results);
37306
+ return {
37307
+ type: "Reply" /* Reply */,
37308
+ message: resolvedResults.join(`
37309
+ `)
37310
+ };
37311
+ };
37312
+ var isAvailable5 = (provider) => {
37313
+ return typeof provider.fetchUrl === "function";
37314
+ };
37315
+ var fetchUrl_default = {
37316
+ ...toolInfo5,
37317
+ handler: handler5,
37318
+ isAvailable: isAvailable5
37319
+ };
37320
+ // ../core/src/tools/listFiles.ts
37321
+ var toolInfo6 = {
37240
37322
  name: "list_files",
37241
37323
  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.",
37242
37324
  parameters: [
@@ -37276,7 +37358,7 @@ var toolInfo5 = {
37276
37358
  ],
37277
37359
  permissionLevel: 1 /* Read */
37278
37360
  };
37279
- var handler5 = async (provider, args) => {
37361
+ var handler6 = async (provider, args) => {
37280
37362
  if (!provider.listFiles) {
37281
37363
  return {
37282
37364
  type: "Error" /* Error */,
@@ -37297,16 +37379,16 @@ ${files.join(`
37297
37379
  <list_files_truncated>${limitReached}</list_files_truncated>`
37298
37380
  };
37299
37381
  };
37300
- var isAvailable5 = (provider) => {
37382
+ var isAvailable6 = (provider) => {
37301
37383
  return !!provider.listFiles;
37302
37384
  };
37303
37385
  var listFiles_default = {
37304
- ...toolInfo5,
37305
- handler: handler5,
37306
- isAvailable: isAvailable5
37386
+ ...toolInfo6,
37387
+ handler: handler6,
37388
+ isAvailable: isAvailable6
37307
37389
  };
37308
37390
  // ../core/src/tools/readFile.ts
37309
- var toolInfo6 = {
37391
+ var toolInfo7 = {
37310
37392
  name: "read_file",
37311
37393
  description: "Request to read the contents of one or multiple files at the specified paths. Use comma separated paths to read multiple files. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. May not be suitable for other types of binary files, as it returns the raw content as a string. Try to list all the potential files are relevent to the task, and then use this tool to read all the relevant files.",
37312
37394
  parameters: [
@@ -37339,7 +37421,7 @@ var toolInfo6 = {
37339
37421
  ],
37340
37422
  permissionLevel: 1 /* Read */
37341
37423
  };
37342
- var handler6 = async (provider, args) => {
37424
+ var handler7 = async (provider, args) => {
37343
37425
  if (!provider.readFile) {
37344
37426
  return {
37345
37427
  type: "Error" /* Error */,
@@ -37367,16 +37449,16 @@ var handler6 = async (provider, args) => {
37367
37449
  `)
37368
37450
  };
37369
37451
  };
37370
- var isAvailable6 = (provider) => {
37452
+ var isAvailable7 = (provider) => {
37371
37453
  return !!provider.readFile;
37372
37454
  };
37373
37455
  var readFile_default = {
37374
- ...toolInfo6,
37375
- handler: handler6,
37376
- isAvailable: isAvailable6
37456
+ ...toolInfo7,
37457
+ handler: handler7,
37458
+ isAvailable: isAvailable7
37377
37459
  };
37378
37460
  // ../core/src/tools/replaceInFile.ts
37379
- var toolInfo7 = {
37461
+ var toolInfo8 = {
37380
37462
  name: "replace_in_file",
37381
37463
  description: "Request to replace sections of content in an existing file using SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file.",
37382
37464
  parameters: [
@@ -37528,7 +37610,7 @@ function oldFeature() {
37528
37610
  ],
37529
37611
  permissionLevel: 2 /* Write */
37530
37612
  };
37531
- var handler7 = async (provider, args) => {
37613
+ var handler8 = async (provider, args) => {
37532
37614
  if (!provider.readFile || !provider.writeFile) {
37533
37615
  return {
37534
37616
  type: "Error" /* Error */,
@@ -37551,16 +37633,16 @@ var handler7 = async (provider, args) => {
37551
37633
  message: `<replace_in_file_path>${path}</replace_in_file_path>`
37552
37634
  };
37553
37635
  };
37554
- var isAvailable7 = (provider) => {
37636
+ var isAvailable8 = (provider) => {
37555
37637
  return !!provider.readFile && !!provider.writeFile;
37556
37638
  };
37557
37639
  var replaceInFile_default = {
37558
- ...toolInfo7,
37559
- handler: handler7,
37560
- isAvailable: isAvailable7
37640
+ ...toolInfo8,
37641
+ handler: handler8,
37642
+ isAvailable: isAvailable8
37561
37643
  };
37562
37644
  // ../core/src/tools/searchFiles.ts
37563
- var toolInfo8 = {
37645
+ var toolInfo9 = {
37564
37646
  name: "search_files",
37565
37647
  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.",
37566
37648
  parameters: [
@@ -37604,7 +37686,7 @@ var toolInfo8 = {
37604
37686
  ],
37605
37687
  permissionLevel: 1 /* Read */
37606
37688
  };
37607
- var handler8 = async (provider, args) => {
37689
+ var handler9 = async (provider, args) => {
37608
37690
  if (!provider.searchFiles) {
37609
37691
  return {
37610
37692
  type: "Error" /* Error */,
@@ -37627,13 +37709,13 @@ ${files.join(`
37627
37709
  `
37628
37710
  };
37629
37711
  };
37630
- var isAvailable8 = (provider) => {
37712
+ var isAvailable9 = (provider) => {
37631
37713
  return !!provider.searchFiles;
37632
37714
  };
37633
37715
  var searchFiles_default = {
37634
- ...toolInfo8,
37635
- handler: handler8,
37636
- isAvailable: isAvailable8
37716
+ ...toolInfo9,
37717
+ handler: handler9,
37718
+ isAvailable: isAvailable9
37637
37719
  };
37638
37720
  // ../core/src/tools/updateKnowledge.ts
37639
37721
  var import_yaml = __toESM(require_dist(), 1);
@@ -37679,7 +37761,7 @@ function join(...parts) {
37679
37761
  }
37680
37762
 
37681
37763
  // ../core/src/tools/updateKnowledge.ts
37682
- var toolInfo9 = {
37764
+ var toolInfo10 = {
37683
37765
  name: "update_knowledge",
37684
37766
  description: "Update knowledge in a knowledge.ai.yml file with smart merging capabilities. This tool lets you add, update, or remove information using path-based updates and special directives.",
37685
37767
  parameters: [
@@ -37856,7 +37938,7 @@ function deepMerge(target, source) {
37856
37938
  }
37857
37939
  return output;
37858
37940
  }
37859
- var handler9 = async (provider, args) => {
37941
+ var handler10 = async (provider, args) => {
37860
37942
  if (!provider.readFile || !provider.writeFile) {
37861
37943
  return {
37862
37944
  type: "Error" /* Error */,
@@ -37928,16 +38010,16 @@ var handler9 = async (provider, args) => {
37928
38010
  };
37929
38011
  }
37930
38012
  };
37931
- var isAvailable9 = (provider) => {
38013
+ var isAvailable10 = (provider) => {
37932
38014
  return !!provider.readFile && !!provider.writeFile;
37933
38015
  };
37934
38016
  var updateKnowledge_default = {
37935
- ...toolInfo9,
37936
- handler: handler9,
37937
- isAvailable: isAvailable9
38017
+ ...toolInfo10,
38018
+ handler: handler10,
38019
+ isAvailable: isAvailable10
37938
38020
  };
37939
38021
  // ../core/src/tools/writeToFile.ts
37940
- var toolInfo10 = {
38022
+ var toolInfo11 = {
37941
38023
  name: "write_to_file",
37942
38024
  description: "Request to write content to a file at the specified path. If the file exists, it will be overwritten with the provided content. If the file doesn't exist, it will be created. This tool will automatically create any directories needed to write the file. Ensure that the output content does not include incorrect escaped character patterns such as `&lt;` and `&gt;`.",
37943
38025
  parameters: [
@@ -37982,7 +38064,7 @@ export default App;
37982
38064
  ],
37983
38065
  permissionLevel: 2 /* Write */
37984
38066
  };
37985
- var handler10 = async (provider, args) => {
38067
+ var handler11 = async (provider, args) => {
37986
38068
  if (!provider.writeFile) {
37987
38069
  return {
37988
38070
  type: "Error" /* Error */,
@@ -37997,16 +38079,16 @@ var handler10 = async (provider, args) => {
37997
38079
  message: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
37998
38080
  };
37999
38081
  };
38000
- var isAvailable10 = (provider) => {
38082
+ var isAvailable11 = (provider) => {
38001
38083
  return !!provider.writeFile;
38002
38084
  };
38003
38085
  var writeToFile_default = {
38004
- ...toolInfo10,
38005
- handler: handler10,
38006
- isAvailable: isAvailable10
38086
+ ...toolInfo11,
38087
+ handler: handler11,
38088
+ isAvailable: isAvailable11
38007
38089
  };
38008
38090
  // ../core/src/tools/handOver.ts
38009
- var toolInfo11 = {
38091
+ var toolInfo12 = {
38010
38092
  name: "hand_over",
38011
38093
  description: "Hand over the current task to another agent to complete. This tool MUST NOT to be used with any other tool.",
38012
38094
  parameters: [
@@ -38060,7 +38142,7 @@ var toolInfo11 = {
38060
38142
  ],
38061
38143
  permissionLevel: 0 /* None */
38062
38144
  };
38063
- var handler11 = async (_provider, args) => {
38145
+ var handler12 = async (_provider, args) => {
38064
38146
  const agentName = getString(args, "agent_name");
38065
38147
  const task = getString(args, "task");
38066
38148
  const context = getString(args, "context", undefined);
@@ -38073,16 +38155,16 @@ var handler11 = async (_provider, args) => {
38073
38155
  files
38074
38156
  };
38075
38157
  };
38076
- var isAvailable11 = (_provider) => {
38158
+ var isAvailable12 = (_provider) => {
38077
38159
  return true;
38078
38160
  };
38079
38161
  var handOver_default = {
38080
- ...toolInfo11,
38081
- handler: handler11,
38082
- isAvailable: isAvailable11
38162
+ ...toolInfo12,
38163
+ handler: handler12,
38164
+ isAvailable: isAvailable12
38083
38165
  };
38084
38166
  // ../core/src/tools/removeFile.ts
38085
- var toolInfo12 = {
38167
+ var toolInfo13 = {
38086
38168
  name: "remove_file",
38087
38169
  description: "Request to remove a file at the specified path.",
38088
38170
  parameters: [
@@ -38106,7 +38188,7 @@ var toolInfo12 = {
38106
38188
  ],
38107
38189
  permissionLevel: 2 /* Write */
38108
38190
  };
38109
- var handler12 = async (provider, args) => {
38191
+ var handler13 = async (provider, args) => {
38110
38192
  if (!provider.removeFile) {
38111
38193
  return {
38112
38194
  type: "Error" /* Error */,
@@ -38120,16 +38202,16 @@ var handler12 = async (provider, args) => {
38120
38202
  message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
38121
38203
  };
38122
38204
  };
38123
- var isAvailable12 = (provider) => {
38205
+ var isAvailable13 = (provider) => {
38124
38206
  return !!provider.removeFile;
38125
38207
  };
38126
38208
  var removeFile_default = {
38127
- ...toolInfo12,
38128
- handler: handler12,
38129
- isAvailable: isAvailable12
38209
+ ...toolInfo13,
38210
+ handler: handler13,
38211
+ isAvailable: isAvailable13
38130
38212
  };
38131
38213
  // ../core/src/tools/renameFile.ts
38132
- var toolInfo13 = {
38214
+ var toolInfo14 = {
38133
38215
  name: "rename_file",
38134
38216
  description: "Request to rename a file from source path to target path.",
38135
38217
  parameters: [
@@ -38163,7 +38245,7 @@ var toolInfo13 = {
38163
38245
  ],
38164
38246
  permissionLevel: 2 /* Write */
38165
38247
  };
38166
- var handler13 = async (provider, args) => {
38248
+ var handler14 = async (provider, args) => {
38167
38249
  if (!provider.renameFile) {
38168
38250
  return {
38169
38251
  type: "Error" /* Error */,
@@ -38178,13 +38260,13 @@ var handler13 = async (provider, args) => {
38178
38260
  message: `<rename_file_path>${targetPath}</rename_file_path><status>Success</status>`
38179
38261
  };
38180
38262
  };
38181
- var isAvailable13 = (provider) => {
38263
+ var isAvailable14 = (provider) => {
38182
38264
  return !!provider.renameFile;
38183
38265
  };
38184
38266
  var renameFile_default = {
38185
- ...toolInfo13,
38186
- handler: handler13,
38187
- isAvailable: isAvailable13
38267
+ ...toolInfo14,
38268
+ handler: handler14,
38269
+ isAvailable: isAvailable14
38188
38270
  };
38189
38271
  // ../core/src/getAvailableTools.ts
38190
38272
  var getAvailableTools = ({
@@ -38542,7 +38624,13 @@ ${joined}`;
38542
38624
  };
38543
38625
  var responsePrompts = {
38544
38626
  errorInvokeTool: (tool, error) => `An error occurred while invoking the tool "${tool}": ${error}`,
38545
- requireUseTool: "Error: You MUST use a tool before proceeding using XCM tags. e.g. <tool_tool_name>tool_name</tool_tool_name>",
38627
+ requireUseTool: `Error: No tool use detected. You MUST use a tool before proceeding.
38628
+ e.g. <tool_tool_name>tool_name</tool_tool_name>
38629
+
38630
+ Ensure the opening and closing tags are correctly nested and closed, and that you are using the correct tool name.
38631
+ Avoid unnecessary text or symbols before or after the tool use.
38632
+ Avoid unnecessary escape characters or special characters.
38633
+ `,
38546
38634
  toolResults: (tool, result) => `<tool_response>
38547
38635
  <tool_name>${tool}</tool_name>
38548
38636
  <tool_result>
@@ -38785,8 +38873,8 @@ ${instance.prompt}`;
38785
38873
  }
38786
38874
  async#invokeTool(name, args) {
38787
38875
  try {
38788
- const handler14 = this.handlers[name]?.handler;
38789
- if (!handler14) {
38876
+ const handler15 = this.handlers[name]?.handler;
38877
+ if (!handler15) {
38790
38878
  return {
38791
38879
  type: "Error" /* Error */,
38792
38880
  message: responsePrompts.errorInvokeTool(name, "Tool not found"),
@@ -38805,7 +38893,7 @@ ${instance.prompt}`;
38805
38893
  if (resp) {
38806
38894
  return resp;
38807
38895
  }
38808
- return await handler14(this.config.provider, args);
38896
+ return await handler15(this.config.provider, args);
38809
38897
  } catch (error) {
38810
38898
  return {
38811
38899
  type: "Error" /* Error */,
@@ -48014,15 +48102,15 @@ function useKeypress(userHandler) {
48014
48102
  signal.current = userHandler;
48015
48103
  useEffect((rl) => {
48016
48104
  let ignore = false;
48017
- const handler14 = withUpdates((_input, event) => {
48105
+ const handler15 = withUpdates((_input, event) => {
48018
48106
  if (ignore)
48019
48107
  return;
48020
48108
  signal.current(event, rl);
48021
48109
  });
48022
- rl.input.on("keypress", handler14);
48110
+ rl.input.on("keypress", handler15);
48023
48111
  return () => {
48024
48112
  ignore = true;
48025
- rl.input.removeListener("keypress", handler14);
48113
+ rl.input.removeListener("keypress", handler15);
48026
48114
  };
48027
48115
  }, []);
48028
48116
  }
@@ -48204,16 +48292,16 @@ class Emitter {
48204
48292
 
48205
48293
  class SignalExitBase {
48206
48294
  }
48207
- var signalExitWrap = (handler14) => {
48295
+ var signalExitWrap = (handler15) => {
48208
48296
  return {
48209
48297
  onExit(cb, opts) {
48210
- return handler14.onExit(cb, opts);
48298
+ return handler15.onExit(cb, opts);
48211
48299
  },
48212
48300
  load() {
48213
- return handler14.load();
48301
+ return handler15.load();
48214
48302
  },
48215
48303
  unload() {
48216
- return handler14.unload();
48304
+ return handler15.unload();
48217
48305
  }
48218
48306
  };
48219
48307
  };
@@ -48979,6 +49067,20 @@ var getProvider = (agentName, config2, options = {}) => {
48979
49067
  },
48980
49068
  attemptCompletion: async (result) => {
48981
49069
  return;
49070
+ },
49071
+ fetchUrl: async (url) => {
49072
+ const isRaw = url.startsWith("https://raw.githubusercontent.com/");
49073
+ const urlToFetch = isRaw ? url : `https://r.jina.ai/${url}`;
49074
+ try {
49075
+ const response = await fetch(urlToFetch);
49076
+ if (!response.ok) {
49077
+ throw new Error(`HTTP error! status: ${response.status}`);
49078
+ }
49079
+ return await response.text();
49080
+ } catch (error) {
49081
+ console.error("Error fetching URL:", error);
49082
+ throw error;
49083
+ }
48982
49084
  }
48983
49085
  };
48984
49086
  if (checkRipgrep()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli-shared",
3
- "version": "0.8.22",
3
+ "version": "0.8.23",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",
@@ -15,7 +15,7 @@
15
15
  "build": "bun build src/index.ts --outdir dist --target node"
16
16
  },
17
17
  "dependencies": {
18
- "@polka-codes/core": "0.8.10",
18
+ "@polka-codes/core": "0.8.22",
19
19
  "ignore": "^7.0.3",
20
20
  "lodash": "^4.17.21",
21
21
  "yaml": "^2.7.0",