From 987adc2cbc9dd8bb0560f341a85328cd6b6fd0ce Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 7 Nov 2023 21:45:36 +0100 Subject: [PATCH] Fixes for the r2ai r2papi --- typescript/index.ts | 28 ++++++++++++++++++++++++---- typescript/package-lock.json | 4 ++-- typescript/package.json | 2 +- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/typescript/index.ts b/typescript/index.ts index be4f290..bff5ceb 100644 --- a/typescript/index.ts +++ b/typescript/index.ts @@ -991,11 +991,15 @@ class R2AI { available : boolean = false; model : string = ""; constructor (num, model) { - this.available = r2.call(`r2ai -h`).trim() !== ""; + this.available = r2.cmd('r2ai -h').trim() !== ""; if (this.available) { - r2.call(`r2ai -n ${num}`) + if (num) { + r2.call(`r2ai -n ${num}`) + } // r2.call('r2ai -e DEBUG=1') - this.model = model; + if (model) { + this.model = model; + } } else { console.error("ERROR: r2ai is not installed"); } @@ -1010,11 +1014,27 @@ class R2AI { r2.call(`r2ai -r ${msg}`) } } + setModel(modelName) { + if (this.available) { + r2.call(`r2ai -m ${this.model}`) + } + } + getModel() { + if (this.available) { + return r2.call("r2ai -m"); + } + return this.model; + } + listModels() { + if (this.available) { + return r2.call("r2ai -M").trim().split(/\n/g); + } + return []; + } query(msg) { if (!this.available || msg == '') { return ''; } - r2.call(`r2ai -m ${this.model}`) const fmsg = msg.trim().replace(/\n/g, '.'); return r2.call(`r2ai ${fmsg}`) } diff --git a/typescript/package-lock.json b/typescript/package-lock.json index 3f4bb4d..c0bd385 100644 --- a/typescript/package-lock.json +++ b/typescript/package-lock.json @@ -1,12 +1,12 @@ { "name": "r2papi", - "version": "0.2.4", + "version": "0.2.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "r2papi", - "version": "0.2.4", + "version": "0.2.5", "license": "MIT", "devDependencies": { "r2pipe": "^2.8.4", diff --git a/typescript/package.json b/typescript/package.json index 9b94abc..8161920 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -1,6 +1,6 @@ { "name": "r2papi", - "version": "0.2.4", + "version": "0.2.5", "description": "r2api on top of r2pipe for typescript and js", "author": "", "homepage": "http://www.radare.org",