@polka-codes/runner 0.8.22 → 0.8.24

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 +234 -94
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -31282,9 +31282,9 @@ var require_event_target = __commonJS((exports, module) => {
31282
31282
  }
31283
31283
  Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
31284
31284
  var EventTarget = {
31285
- addEventListener(type, handler14, options = {}) {
31285
+ addEventListener(type, handler15, options = {}) {
31286
31286
  for (const listener of this.listeners(type)) {
31287
- if (!options[kForOnEventAttribute] && listener[kListener] === handler14 && !listener[kForOnEventAttribute]) {
31287
+ if (!options[kForOnEventAttribute] && listener[kListener] === handler15 && !listener[kForOnEventAttribute]) {
31288
31288
  return;
31289
31289
  }
31290
31290
  }
@@ -31295,7 +31295,7 @@ var require_event_target = __commonJS((exports, module) => {
31295
31295
  data: isBinary ? data : data.toString()
31296
31296
  });
31297
31297
  event[kTarget] = this;
31298
- callListener(handler14, this, event);
31298
+ callListener(handler15, this, event);
31299
31299
  };
31300
31300
  } else if (type === "close") {
31301
31301
  wrapper = function onClose(code, message) {
@@ -31305,7 +31305,7 @@ var require_event_target = __commonJS((exports, module) => {
31305
31305
  wasClean: this._closeFrameReceived && this._closeFrameSent
31306
31306
  });
31307
31307
  event[kTarget] = this;
31308
- callListener(handler14, this, event);
31308
+ callListener(handler15, this, event);
31309
31309
  };
31310
31310
  } else if (type === "error") {
31311
31311
  wrapper = function onError(error) {
@@ -31314,28 +31314,28 @@ var require_event_target = __commonJS((exports, module) => {
31314
31314
  message: error.message
31315
31315
  });
31316
31316
  event[kTarget] = this;
31317
- callListener(handler14, this, event);
31317
+ callListener(handler15, this, event);
31318
31318
  };
31319
31319
  } else if (type === "open") {
31320
31320
  wrapper = function onOpen() {
31321
31321
  const event = new Event("open");
31322
31322
  event[kTarget] = this;
31323
- callListener(handler14, this, event);
31323
+ callListener(handler15, this, event);
31324
31324
  };
31325
31325
  } else {
31326
31326
  return;
31327
31327
  }
31328
31328
  wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
31329
- wrapper[kListener] = handler14;
31329
+ wrapper[kListener] = handler15;
31330
31330
  if (options.once) {
31331
31331
  this.once(type, wrapper);
31332
31332
  } else {
31333
31333
  this.on(type, wrapper);
31334
31334
  }
31335
31335
  },
31336
- removeEventListener(type, handler14) {
31336
+ removeEventListener(type, handler15) {
31337
31337
  for (const listener of this.listeners(type)) {
31338
- if (listener[kListener] === handler14 && !listener[kForOnEventAttribute]) {
31338
+ if (listener[kListener] === handler15 && !listener[kForOnEventAttribute]) {
31339
31339
  this.removeListener(type, listener);
31340
31340
  break;
31341
31341
  }
@@ -31861,16 +31861,16 @@ var require_websocket = __commonJS((exports, module) => {
31861
31861
  }
31862
31862
  return null;
31863
31863
  },
31864
- set(handler14) {
31864
+ set(handler15) {
31865
31865
  for (const listener of this.listeners(method)) {
31866
31866
  if (listener[kForOnEventAttribute]) {
31867
31867
  this.removeListener(method, listener);
31868
31868
  break;
31869
31869
  }
31870
31870
  }
31871
- if (typeof handler14 !== "function")
31871
+ if (typeof handler15 !== "function")
31872
31872
  return;
31873
- this.addEventListener(method, handler14, {
31873
+ this.addEventListener(method, handler15, {
31874
31874
  [kForOnEventAttribute]: true
31875
31875
  });
31876
31876
  }
@@ -32748,7 +32748,7 @@ var {
32748
32748
  Help
32749
32749
  } = import__.default;
32750
32750
  // package.json
32751
- var version = "0.8.22";
32751
+ var version = "0.8.24";
32752
32752
 
32753
32753
  // src/runner.ts
32754
32754
  import { execSync } from "node:child_process";
@@ -42043,6 +42043,7 @@ __export(exports_allTools, {
42043
42043
  readFile: () => readFile_default,
42044
42044
  listFiles: () => listFiles_default,
42045
42045
  handOver: () => handOver_default,
42046
+ fetchUrl: () => fetchUrl_default,
42046
42047
  executeCommand: () => executeCommand_default,
42047
42048
  delegate: () => delegate_default,
42048
42049
  attemptCompletion: () => attemptCompletion_default,
@@ -42501,8 +42502,89 @@ var executeCommand_default = {
42501
42502
  handler: handler4,
42502
42503
  isAvailable: isAvailable4
42503
42504
  };
42504
- // ../core/src/tools/listFiles.ts
42505
+ // ../core/src/tools/fetchUrl.ts
42505
42506
  var toolInfo5 = {
42507
+ name: "fetch_url",
42508
+ 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.",
42509
+ parameters: [
42510
+ {
42511
+ name: "url",
42512
+ description: "One or more URLs to fetch, separated by commas if multiple.",
42513
+ required: true
42514
+ }
42515
+ ],
42516
+ examples: [
42517
+ {
42518
+ description: "Fetch a single webpage",
42519
+ parameters: [
42520
+ {
42521
+ name: "url",
42522
+ value: "https://example.com"
42523
+ }
42524
+ ]
42525
+ },
42526
+ {
42527
+ description: "Fetch multiple webpages",
42528
+ parameters: [
42529
+ {
42530
+ name: "url",
42531
+ value: "https://example.com,https://developer.mozilla.org/en-US/docs/Web/HTTP"
42532
+ }
42533
+ ]
42534
+ },
42535
+ {
42536
+ description: "Fetch a raw file from GitHub",
42537
+ parameters: [
42538
+ {
42539
+ name: "url",
42540
+ value: "https://raw.githubusercontent.com/user/repo/main/README.md"
42541
+ }
42542
+ ]
42543
+ }
42544
+ ],
42545
+ permissionLevel: 1 /* Read */
42546
+ };
42547
+ var handler5 = async (provider, args) => {
42548
+ if (!provider.fetchUrl) {
42549
+ return {
42550
+ type: "Error" /* Error */,
42551
+ message: "Not possible to fetch url. Abort."
42552
+ };
42553
+ }
42554
+ const urls = getStringArray(args, "url");
42555
+ if (urls.length === 0) {
42556
+ return {
42557
+ type: "Error" /* Error */,
42558
+ message: "No URLs provided. Please provide at least one URL to fetch."
42559
+ };
42560
+ }
42561
+ const results = [];
42562
+ for (const url of urls) {
42563
+ try {
42564
+ const content = provider.fetchUrl(url).then((res) => `<fetch_url_content url="${url}">${res}</fetch_url_content>`);
42565
+ results.push(content);
42566
+ } catch (error) {
42567
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
42568
+ results.push(Promise.resolve(`<fetch_url_error url="${url}">${errorMessage}</fetch_url_error>`));
42569
+ }
42570
+ }
42571
+ const resolvedResults = await Promise.all(results);
42572
+ return {
42573
+ type: "Reply" /* Reply */,
42574
+ message: resolvedResults.join(`
42575
+ `)
42576
+ };
42577
+ };
42578
+ var isAvailable5 = (provider) => {
42579
+ return typeof provider.fetchUrl === "function";
42580
+ };
42581
+ var fetchUrl_default = {
42582
+ ...toolInfo5,
42583
+ handler: handler5,
42584
+ isAvailable: isAvailable5
42585
+ };
42586
+ // ../core/src/tools/listFiles.ts
42587
+ var toolInfo6 = {
42506
42588
  name: "list_files",
42507
42589
  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.",
42508
42590
  parameters: [
@@ -42542,7 +42624,7 @@ var toolInfo5 = {
42542
42624
  ],
42543
42625
  permissionLevel: 1 /* Read */
42544
42626
  };
42545
- var handler5 = async (provider, args) => {
42627
+ var handler6 = async (provider, args) => {
42546
42628
  if (!provider.listFiles) {
42547
42629
  return {
42548
42630
  type: "Error" /* Error */,
@@ -42563,16 +42645,16 @@ ${files.join(`
42563
42645
  <list_files_truncated>${limitReached}</list_files_truncated>`
42564
42646
  };
42565
42647
  };
42566
- var isAvailable5 = (provider) => {
42648
+ var isAvailable6 = (provider) => {
42567
42649
  return !!provider.listFiles;
42568
42650
  };
42569
42651
  var listFiles_default = {
42570
- ...toolInfo5,
42571
- handler: handler5,
42572
- isAvailable: isAvailable5
42652
+ ...toolInfo6,
42653
+ handler: handler6,
42654
+ isAvailable: isAvailable6
42573
42655
  };
42574
42656
  // ../core/src/tools/readFile.ts
42575
- var toolInfo6 = {
42657
+ var toolInfo7 = {
42576
42658
  name: "read_file",
42577
42659
  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.",
42578
42660
  parameters: [
@@ -42605,7 +42687,7 @@ var toolInfo6 = {
42605
42687
  ],
42606
42688
  permissionLevel: 1 /* Read */
42607
42689
  };
42608
- var handler6 = async (provider, args) => {
42690
+ var handler7 = async (provider, args) => {
42609
42691
  if (!provider.readFile) {
42610
42692
  return {
42611
42693
  type: "Error" /* Error */,
@@ -42633,16 +42715,16 @@ var handler6 = async (provider, args) => {
42633
42715
  `)
42634
42716
  };
42635
42717
  };
42636
- var isAvailable6 = (provider) => {
42718
+ var isAvailable7 = (provider) => {
42637
42719
  return !!provider.readFile;
42638
42720
  };
42639
42721
  var readFile_default = {
42640
- ...toolInfo6,
42641
- handler: handler6,
42642
- isAvailable: isAvailable6
42722
+ ...toolInfo7,
42723
+ handler: handler7,
42724
+ isAvailable: isAvailable7
42643
42725
  };
42644
42726
  // ../core/src/tools/replaceInFile.ts
42645
- var toolInfo7 = {
42727
+ var toolInfo8 = {
42646
42728
  name: "replace_in_file",
42647
42729
  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.",
42648
42730
  parameters: [
@@ -42794,7 +42876,7 @@ function oldFeature() {
42794
42876
  ],
42795
42877
  permissionLevel: 2 /* Write */
42796
42878
  };
42797
- var handler7 = async (provider, args) => {
42879
+ var handler8 = async (provider, args) => {
42798
42880
  if (!provider.readFile || !provider.writeFile) {
42799
42881
  return {
42800
42882
  type: "Error" /* Error */,
@@ -42817,16 +42899,16 @@ var handler7 = async (provider, args) => {
42817
42899
  message: `<replace_in_file_path>${path}</replace_in_file_path>`
42818
42900
  };
42819
42901
  };
42820
- var isAvailable7 = (provider) => {
42902
+ var isAvailable8 = (provider) => {
42821
42903
  return !!provider.readFile && !!provider.writeFile;
42822
42904
  };
42823
42905
  var replaceInFile_default = {
42824
- ...toolInfo7,
42825
- handler: handler7,
42826
- isAvailable: isAvailable7
42906
+ ...toolInfo8,
42907
+ handler: handler8,
42908
+ isAvailable: isAvailable8
42827
42909
  };
42828
42910
  // ../core/src/tools/searchFiles.ts
42829
- var toolInfo8 = {
42911
+ var toolInfo9 = {
42830
42912
  name: "search_files",
42831
42913
  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.",
42832
42914
  parameters: [
@@ -42870,7 +42952,7 @@ var toolInfo8 = {
42870
42952
  ],
42871
42953
  permissionLevel: 1 /* Read */
42872
42954
  };
42873
- var handler8 = async (provider, args) => {
42955
+ var handler9 = async (provider, args) => {
42874
42956
  if (!provider.searchFiles) {
42875
42957
  return {
42876
42958
  type: "Error" /* Error */,
@@ -42893,13 +42975,13 @@ ${files.join(`
42893
42975
  `
42894
42976
  };
42895
42977
  };
42896
- var isAvailable8 = (provider) => {
42978
+ var isAvailable9 = (provider) => {
42897
42979
  return !!provider.searchFiles;
42898
42980
  };
42899
42981
  var searchFiles_default = {
42900
- ...toolInfo8,
42901
- handler: handler8,
42902
- isAvailable: isAvailable8
42982
+ ...toolInfo9,
42983
+ handler: handler9,
42984
+ isAvailable: isAvailable9
42903
42985
  };
42904
42986
  // ../core/src/tools/updateKnowledge.ts
42905
42987
  var import_yaml = __toESM(require_dist(), 1);
@@ -42945,7 +43027,7 @@ function join(...parts) {
42945
43027
  }
42946
43028
 
42947
43029
  // ../core/src/tools/updateKnowledge.ts
42948
- var toolInfo9 = {
43030
+ var toolInfo10 = {
42949
43031
  name: "update_knowledge",
42950
43032
  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.",
42951
43033
  parameters: [
@@ -43122,7 +43204,7 @@ function deepMerge(target, source) {
43122
43204
  }
43123
43205
  return output;
43124
43206
  }
43125
- var handler9 = async (provider, args) => {
43207
+ var handler10 = async (provider, args) => {
43126
43208
  if (!provider.readFile || !provider.writeFile) {
43127
43209
  return {
43128
43210
  type: "Error" /* Error */,
@@ -43194,18 +43276,18 @@ var handler9 = async (provider, args) => {
43194
43276
  };
43195
43277
  }
43196
43278
  };
43197
- var isAvailable9 = (provider) => {
43279
+ var isAvailable10 = (provider) => {
43198
43280
  return !!provider.readFile && !!provider.writeFile;
43199
43281
  };
43200
43282
  var updateKnowledge_default = {
43201
- ...toolInfo9,
43202
- handler: handler9,
43203
- isAvailable: isAvailable9
43283
+ ...toolInfo10,
43284
+ handler: handler10,
43285
+ isAvailable: isAvailable10
43204
43286
  };
43205
43287
  // ../core/src/tools/writeToFile.ts
43206
- var toolInfo10 = {
43288
+ var toolInfo11 = {
43207
43289
  name: "write_to_file",
43208
- 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;`.",
43290
+ 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;`, `&gt;`, or `&amp;`. Also ensure there is no unwanted CDATA tags in the content.",
43209
43291
  parameters: [
43210
43292
  {
43211
43293
  name: "path",
@@ -43248,7 +43330,7 @@ export default App;
43248
43330
  ],
43249
43331
  permissionLevel: 2 /* Write */
43250
43332
  };
43251
- var handler10 = async (provider, args) => {
43333
+ var handler11 = async (provider, args) => {
43252
43334
  if (!provider.writeFile) {
43253
43335
  return {
43254
43336
  type: "Error" /* Error */,
@@ -43256,23 +43338,26 @@ var handler10 = async (provider, args) => {
43256
43338
  };
43257
43339
  }
43258
43340
  const path = getString(args, "path");
43259
- const content = getString(args, "content");
43341
+ let content = getString(args, "content");
43342
+ const trimmedContent = content.trim();
43343
+ if (trimmedContent.startsWith("<![CDATA[") && content.endsWith("]]>"))
43344
+ content = trimmedContent.slice(9, -3);
43260
43345
  await provider.writeFile(path, content);
43261
43346
  return {
43262
43347
  type: "Reply" /* Reply */,
43263
43348
  message: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
43264
43349
  };
43265
43350
  };
43266
- var isAvailable10 = (provider) => {
43351
+ var isAvailable11 = (provider) => {
43267
43352
  return !!provider.writeFile;
43268
43353
  };
43269
43354
  var writeToFile_default = {
43270
- ...toolInfo10,
43271
- handler: handler10,
43272
- isAvailable: isAvailable10
43355
+ ...toolInfo11,
43356
+ handler: handler11,
43357
+ isAvailable: isAvailable11
43273
43358
  };
43274
43359
  // ../core/src/tools/handOver.ts
43275
- var toolInfo11 = {
43360
+ var toolInfo12 = {
43276
43361
  name: "hand_over",
43277
43362
  description: "Hand over the current task to another agent to complete. This tool MUST NOT to be used with any other tool.",
43278
43363
  parameters: [
@@ -43326,7 +43411,7 @@ var toolInfo11 = {
43326
43411
  ],
43327
43412
  permissionLevel: 0 /* None */
43328
43413
  };
43329
- var handler11 = async (_provider, args) => {
43414
+ var handler12 = async (_provider, args) => {
43330
43415
  const agentName = getString(args, "agent_name");
43331
43416
  const task = getString(args, "task");
43332
43417
  const context = getString(args, "context", undefined);
@@ -43339,16 +43424,16 @@ var handler11 = async (_provider, args) => {
43339
43424
  files
43340
43425
  };
43341
43426
  };
43342
- var isAvailable11 = (_provider) => {
43427
+ var isAvailable12 = (_provider) => {
43343
43428
  return true;
43344
43429
  };
43345
43430
  var handOver_default = {
43346
- ...toolInfo11,
43347
- handler: handler11,
43348
- isAvailable: isAvailable11
43431
+ ...toolInfo12,
43432
+ handler: handler12,
43433
+ isAvailable: isAvailable12
43349
43434
  };
43350
43435
  // ../core/src/tools/removeFile.ts
43351
- var toolInfo12 = {
43436
+ var toolInfo13 = {
43352
43437
  name: "remove_file",
43353
43438
  description: "Request to remove a file at the specified path.",
43354
43439
  parameters: [
@@ -43372,7 +43457,7 @@ var toolInfo12 = {
43372
43457
  ],
43373
43458
  permissionLevel: 2 /* Write */
43374
43459
  };
43375
- var handler12 = async (provider, args) => {
43460
+ var handler13 = async (provider, args) => {
43376
43461
  if (!provider.removeFile) {
43377
43462
  return {
43378
43463
  type: "Error" /* Error */,
@@ -43386,16 +43471,16 @@ var handler12 = async (provider, args) => {
43386
43471
  message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
43387
43472
  };
43388
43473
  };
43389
- var isAvailable12 = (provider) => {
43474
+ var isAvailable13 = (provider) => {
43390
43475
  return !!provider.removeFile;
43391
43476
  };
43392
43477
  var removeFile_default = {
43393
- ...toolInfo12,
43394
- handler: handler12,
43395
- isAvailable: isAvailable12
43478
+ ...toolInfo13,
43479
+ handler: handler13,
43480
+ isAvailable: isAvailable13
43396
43481
  };
43397
43482
  // ../core/src/tools/renameFile.ts
43398
- var toolInfo13 = {
43483
+ var toolInfo14 = {
43399
43484
  name: "rename_file",
43400
43485
  description: "Request to rename a file from source path to target path.",
43401
43486
  parameters: [
@@ -43429,7 +43514,7 @@ var toolInfo13 = {
43429
43514
  ],
43430
43515
  permissionLevel: 2 /* Write */
43431
43516
  };
43432
- var handler13 = async (provider, args) => {
43517
+ var handler14 = async (provider, args) => {
43433
43518
  if (!provider.renameFile) {
43434
43519
  return {
43435
43520
  type: "Error" /* Error */,
@@ -43444,13 +43529,13 @@ var handler13 = async (provider, args) => {
43444
43529
  message: `<rename_file_path>${targetPath}</rename_file_path><status>Success</status>`
43445
43530
  };
43446
43531
  };
43447
- var isAvailable13 = (provider) => {
43532
+ var isAvailable14 = (provider) => {
43448
43533
  return !!provider.renameFile;
43449
43534
  };
43450
43535
  var renameFile_default = {
43451
- ...toolInfo13,
43452
- handler: handler13,
43453
- isAvailable: isAvailable13
43536
+ ...toolInfo14,
43537
+ handler: handler14,
43538
+ isAvailable: isAvailable14
43454
43539
  };
43455
43540
  // ../core/src/getAvailableTools.ts
43456
43541
  var getAvailableTools = ({
@@ -43808,13 +43893,34 @@ ${joined}`;
43808
43893
  };
43809
43894
  var responsePrompts = {
43810
43895
  errorInvokeTool: (tool, error) => `An error occurred while invoking the tool "${tool}": ${error}`,
43811
- requireUseTool: "Error: You MUST use a tool before proceeding using XCM tags. e.g. <tool_tool_name>tool_name</tool_tool_name>",
43812
- toolResults: (tool, result) => `<tool_response>
43813
- <tool_name>${tool}</tool_name>
43814
- <tool_result>
43815
- ${result}
43816
- </tool_result>
43817
- </tool_response>`,
43896
+ requireUseTool: `Error: No tool use detected. You MUST use a tool before proceeding.
43897
+ e.g. <tool_tool_name>tool_name</tool_tool_name>
43898
+
43899
+ Ensure the opening and closing tags are correctly nested and closed, and that you are using the correct tool name.
43900
+ Avoid unnecessary text or symbols before or after the tool use.
43901
+ Avoid unnecessary escape characters or special characters.
43902
+ `,
43903
+ toolResults: (tool, result) => {
43904
+ if (typeof result === "string") {
43905
+ return [
43906
+ {
43907
+ type: "text",
43908
+ text: `<tool_response name=${tool}>${result}</tool_response>`
43909
+ }
43910
+ ];
43911
+ }
43912
+ return [
43913
+ {
43914
+ type: "text",
43915
+ text: `<tool_response name=${tool}>`
43916
+ },
43917
+ ...result,
43918
+ {
43919
+ type: "text",
43920
+ text: "</tool_response>"
43921
+ }
43922
+ ];
43923
+ },
43818
43924
  commandResult: (command, exitCode, stdout, stderr) => `<command>${command}</command>
43819
43925
  <command_exit_code>${exitCode}</command_exit_code>
43820
43926
  <command_stdout>
@@ -43978,23 +44084,26 @@ ${instance.prompt}`;
43978
44084
  await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name });
43979
44085
  const toolResp = await this.#invokeTool(content.name, content.params);
43980
44086
  switch (toolResp.type) {
43981
- case "Reply" /* Reply */:
44087
+ case "Reply" /* Reply */: {
43982
44088
  await this.#callback({ kind: "ToolReply" /* ToolReply */, agent: this, tool: content.name });
43983
44089
  toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
43984
44090
  break;
44091
+ }
43985
44092
  case "Exit" /* Exit */:
43986
44093
  if (toolResponses.length > 0) {
43987
44094
  break outer;
43988
44095
  }
43989
44096
  return { type: "exit", reason: toolResp };
43990
- case "Invalid" /* Invalid */:
44097
+ case "Invalid" /* Invalid */: {
43991
44098
  await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, agent: this, tool: content.name });
43992
44099
  toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
43993
44100
  break outer;
43994
- case "Error" /* Error */:
44101
+ }
44102
+ case "Error" /* Error */: {
43995
44103
  await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name });
43996
44104
  toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
43997
44105
  break outer;
44106
+ }
43998
44107
  case "Interrupted" /* Interrupted */:
43999
44108
  await this.#callback({ kind: "ToolInterrupted" /* ToolInterrupted */, agent: this, tool: content.name });
44000
44109
  return { type: "exit", reason: toolResp };
@@ -44044,15 +44153,13 @@ ${instance.prompt}`;
44044
44153
  if (toolResponses.length === 0) {
44045
44154
  return { type: "reply", message: responsePrompts.requireUseTool };
44046
44155
  }
44047
- const finalResp = toolResponses.filter((resp) => resp.type === "response").map(({ tool, response: response2 }) => responsePrompts.toolResults(tool, response2)).join(`
44048
-
44049
- `);
44156
+ const finalResp = toolResponses.filter((resp) => resp.type === "response").flatMap(({ tool, response: response2 }) => responsePrompts.toolResults(tool, response2));
44050
44157
  return { type: "reply", message: finalResp };
44051
44158
  }
44052
44159
  async#invokeTool(name, args) {
44053
44160
  try {
44054
- const handler14 = this.handlers[name]?.handler;
44055
- if (!handler14) {
44161
+ const handler15 = this.handlers[name]?.handler;
44162
+ if (!handler15) {
44056
44163
  return {
44057
44164
  type: "Error" /* Error */,
44058
44165
  message: responsePrompts.errorInvokeTool(name, "Tool not found"),
@@ -44071,7 +44178,7 @@ ${instance.prompt}`;
44071
44178
  if (resp) {
44072
44179
  return resp;
44073
44180
  }
44074
- return await handler14(this.config.provider, args);
44181
+ return await handler15(this.config.provider, args);
44075
44182
  } catch (error) {
44076
44183
  return {
44077
44184
  type: "Error" /* Error */,
@@ -53266,15 +53373,15 @@ function useKeypress(userHandler) {
53266
53373
  signal.current = userHandler;
53267
53374
  useEffect((rl) => {
53268
53375
  let ignore = false;
53269
- const handler14 = withUpdates((_input, event) => {
53376
+ const handler15 = withUpdates((_input, event) => {
53270
53377
  if (ignore)
53271
53378
  return;
53272
53379
  signal.current(event, rl);
53273
53380
  });
53274
- rl.input.on("keypress", handler14);
53381
+ rl.input.on("keypress", handler15);
53275
53382
  return () => {
53276
53383
  ignore = true;
53277
- rl.input.removeListener("keypress", handler14);
53384
+ rl.input.removeListener("keypress", handler15);
53278
53385
  };
53279
53386
  }, []);
53280
53387
  }
@@ -53456,16 +53563,16 @@ class Emitter {
53456
53563
 
53457
53564
  class SignalExitBase {
53458
53565
  }
53459
- var signalExitWrap = (handler14) => {
53566
+ var signalExitWrap = (handler15) => {
53460
53567
  return {
53461
53568
  onExit(cb, opts) {
53462
- return handler14.onExit(cb, opts);
53569
+ return handler15.onExit(cb, opts);
53463
53570
  },
53464
53571
  load() {
53465
- return handler14.load();
53572
+ return handler15.load();
53466
53573
  },
53467
53574
  unload() {
53468
- return handler14.unload();
53575
+ return handler15.unload();
53469
53576
  }
53470
53577
  };
53471
53578
  };
@@ -54231,6 +54338,20 @@ var getProvider = (agentName, config2, options = {}) => {
54231
54338
  },
54232
54339
  attemptCompletion: async (result) => {
54233
54340
  return;
54341
+ },
54342
+ fetchUrl: async (url) => {
54343
+ const isRaw = url.startsWith("https://raw.githubusercontent.com/");
54344
+ const urlToFetch = isRaw ? url : `https://r.jina.ai/${url}`;
54345
+ try {
54346
+ const response = await fetch(urlToFetch);
54347
+ if (!response.ok) {
54348
+ throw new Error(`HTTP error! status: ${response.status}`);
54349
+ }
54350
+ return await response.text();
54351
+ } catch (error) {
54352
+ console.error("Error fetching URL:", error);
54353
+ throw error;
54354
+ }
54234
54355
  }
54235
54356
  };
54236
54357
  if (checkRipgrep()) {
@@ -58269,6 +58390,25 @@ var wsIncomingMessageSchema = z3.discriminatedUnion("type", [
58269
58390
  z3.object({ type: z3.literal("get_files") }),
58270
58391
  z3.object({ type: z3.literal("done") })
58271
58392
  ]);
58393
+ var textBlockParamSchema = z3.object({
58394
+ type: z3.literal("text"),
58395
+ text: z3.string()
58396
+ });
58397
+ var imageBlockParamSchema = z3.object({
58398
+ type: z3.literal("image"),
58399
+ source: z3.union([
58400
+ z3.object({
58401
+ data: z3.string(),
58402
+ media_type: z3.string(),
58403
+ type: z3.literal("base64")
58404
+ }),
58405
+ z3.object({
58406
+ type: z3.literal("url"),
58407
+ url: z3.string()
58408
+ })
58409
+ ])
58410
+ });
58411
+ var userContentSchema = z3.union([z3.string(), z3.array(z3.union([textBlockParamSchema, imageBlockParamSchema]))]);
58272
58412
  var wsOutgoingMessageSchema = z3.discriminatedUnion("type", [
58273
58413
  z3.object({
58274
58414
  type: z3.literal("pending_tools_response"),
@@ -58276,7 +58416,7 @@ var wsOutgoingMessageSchema = z3.discriminatedUnion("type", [
58276
58416
  responses: z3.array(z3.object({
58277
58417
  index: z3.number(),
58278
58418
  tool: z3.string(),
58279
- response: z3.string()
58419
+ response: userContentSchema
58280
58420
  }))
58281
58421
  }),
58282
58422
  z3.object({
@@ -58551,7 +58691,7 @@ class Runner {
58551
58691
  }
58552
58692
  };
58553
58693
  const respMsg = await fn();
58554
- if (typeof respMsg === "string") {
58694
+ if (typeof respMsg === "string" || Array.isArray(respMsg)) {
58555
58695
  responses.push({
58556
58696
  index: request.index,
58557
58697
  tool: request.tool,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/runner",
3
- "version": "0.8.22",
3
+ "version": "0.8.24",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",
@@ -17,8 +17,8 @@
17
17
  "build": "bun build src/index.ts --outdir dist --target node"
18
18
  },
19
19
  "dependencies": {
20
- "@polka-codes/cli-shared": "0.8.10",
21
- "@polka-codes/core": "0.8.10",
20
+ "@polka-codes/cli-shared": "0.8.22",
21
+ "@polka-codes/core": "0.8.22",
22
22
  "commander": "^13.0.0",
23
23
  "dotenv": "^16.4.7",
24
24
  "ignore": "^7.0.3",