fix (all): path and fs normalization.
This commit is contained in:
parent
698df5a830
commit
27ebf35579
15 changed files with 116 additions and 116 deletions
|
@ -152,8 +152,8 @@ export class GBAdminService implements IGBAdminService {
|
|||
const packageName = text.split(' ')[1];
|
||||
const importer = new GBImporter(min.core);
|
||||
const deployer = new GBDeployer(min.core, importer);
|
||||
const path = GBUtil.getGBAIPath(min.botId, null, packageName);
|
||||
const localFolder = path.join('work', path);
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, null, packageName);
|
||||
const localFolder = path.join('work', packagePath);
|
||||
await deployer.undeployPackageFromLocalPath(min.instance, localFolder);
|
||||
}
|
||||
|
||||
|
|
|
@ -1035,7 +1035,7 @@ export class DialogKeywords {
|
|||
|
||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
const botId = min.instance.botId;
|
||||
const path = GBUtil.getGBAIPath(botId);
|
||||
const packagePath = GBUtil.getGBAIPath(botId);
|
||||
let url = `${baseUrl}/drive/root:/${path}:/children`;
|
||||
|
||||
GBLogEx.info(min, `Loading HEAR AS .xlsx options from Sheet: ${url}`);
|
||||
|
|
|
@ -224,8 +224,8 @@ export class GBVMService extends GBService {
|
|||
|
||||
public static async loadConnections(min) {
|
||||
// Loads storage custom connections.
|
||||
const path = GBUtil.getGBAIPath(min.botId, null);
|
||||
const filePath = path.join('work', path, 'connections.json');
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, null);
|
||||
const filePath = path.join('work', packagePath, 'connections.json');
|
||||
let connections = [];
|
||||
if (fs.existsSync(filePath)) {
|
||||
connections = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
||||
|
@ -756,11 +756,11 @@ export class GBVMService extends GBService {
|
|||
|
||||
private async getTextFromWord(folder: string, filename: string) {
|
||||
return new Promise<string>(async (resolve, reject) => {
|
||||
const path = urlJoin(folder, filename);
|
||||
textract.fromFileWithPath(path, { preserveLineBreaks: true }, (error, text) => {
|
||||
const filePath = urlJoin(folder, filename);
|
||||
textract.fromFileWithPath(filePath, { preserveLineBreaks: true }, (error, text) => {
|
||||
if (error) {
|
||||
if (error.message.startsWith('File not correctly recognized as zip file')) {
|
||||
text = fs.readFileSync(path, 'utf8');
|
||||
text = fs.readFileSync(filePath, 'utf8');
|
||||
} else {
|
||||
reject(error);
|
||||
}
|
||||
|
@ -1090,8 +1090,8 @@ export class GBVMService extends GBService {
|
|||
}
|
||||
|
||||
const botId = min.botId;
|
||||
const path = GBUtil.getGBAIPath(min.botId, `gbdialog`);
|
||||
const gbdialogPath = urlJoin(process.cwd(), 'work', path);
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, `gbdialog`);
|
||||
const gbdialogPath = urlJoin(process.cwd(), 'work', packagePath);
|
||||
const scriptFilePath = urlJoin(gbdialogPath, `${text}.js`);
|
||||
|
||||
let code = min.sandBoxMap[text];
|
||||
|
|
|
@ -75,9 +75,9 @@ export class ImageProcessingServices {
|
|||
});
|
||||
|
||||
const botId = min.instance.botId;
|
||||
const path = GBUtil.getGBAIPath(min.botId);
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId);
|
||||
// TODO: const img = await joinImages(paths);
|
||||
const localName = path.join('work', path, 'cache', `img-mrg${GBAdminService.getRndReadableIdentifier()}.png`);
|
||||
const localName = path.join('work', packagePath, 'cache', `img-mrg${GBAdminService.getRndReadableIdentifier()}.png`);
|
||||
const url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', path.basename(localName));
|
||||
// img.toFile(localName);
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ import { setFlagsFromString } from 'v8';
|
|||
import { runInNewContext } from 'vm';
|
||||
import { IgApiClient } from 'instagram-private-api';
|
||||
import { readFileSync } from 'fs';
|
||||
import { resolve } from 'path';
|
||||
import path, { resolve } from 'path';
|
||||
import { GBLog, GBMinInstance } from 'botlib';
|
||||
import { GBConfigService } from '../../core.gbapp/services/GBConfigService.js';
|
||||
import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||
|
@ -48,7 +48,7 @@ import urlJoin from 'url-join';
|
|||
import Excel from 'exceljs';
|
||||
import { BufferWindowMemory } from 'langchain/memory';
|
||||
import csvdb from 'csv-database';
|
||||
import path from 'path';
|
||||
import packagePath from 'path';
|
||||
import ComputerVisionClient from '@azure/cognitiveservices-computervision';
|
||||
import ApiKeyCredentials from '@azure/ms-rest-js';
|
||||
import alasql from 'alasql';
|
||||
|
@ -570,8 +570,8 @@ export class SystemKeywords {
|
|||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
|
||||
const botId = min.instance.botId;
|
||||
const path = GBUtil.getGBAIPath(botId, 'gbdata');
|
||||
let document = await this.internalGetDocument(client, baseUrl, path, file);
|
||||
const packagePath = GBUtil.getGBAIPath(botId, 'gbdata');
|
||||
let document = await this.internalGetDocument(client, baseUrl, packagePath, file);
|
||||
let sheets = await client.api(`${baseUrl}/drive/items/${document.id}/workbook/worksheets`).get();
|
||||
let body = { values: [[]] };
|
||||
|
||||
|
@ -655,7 +655,7 @@ export class SystemKeywords {
|
|||
GBLogEx.info(min, `Saving '${file}' (SAVE file).`);
|
||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
const botId = min.instance.botId;
|
||||
const path = GBUtil.getGBAIPath(min.botId, `gbdrive`);
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, `gbdrive`);
|
||||
|
||||
// Checks if it is a GB FILE object.
|
||||
|
||||
|
@ -665,7 +665,7 @@ export class SystemKeywords {
|
|||
|
||||
try {
|
||||
data = GBServer.globals.files[data].data; // TODO
|
||||
await client.api(`${baseUrl}/drive/root:/${path}/${file}:/content`).put(data);
|
||||
await client.api(`${baseUrl}/drive/root:/${packagePath}/${file}:/content`).put(data);
|
||||
} catch (error) {
|
||||
if (error.code === 'itemNotFound') {
|
||||
GBLogEx.info(min, `BASIC source file not found: ${file}.`);
|
||||
|
@ -874,12 +874,12 @@ export class SystemKeywords {
|
|||
GBLogEx.info(min, `Saving '${file}' (SAVE). Args: ${args.join(',')}.`);
|
||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
const botId = min.instance.botId;
|
||||
const path = GBUtil.getGBAIPath(botId, 'gbdata');
|
||||
const packagePath = GBUtil.getGBAIPath(botId, 'gbdata');
|
||||
|
||||
let sheets;
|
||||
let document;
|
||||
try {
|
||||
document = await this.internalGetDocument(client, baseUrl, path, file);
|
||||
document = await this.internalGetDocument(client, baseUrl, packagePath, file);
|
||||
sheets = await client.api(`${baseUrl}/drive/items/${document.id}/workbook/worksheets`).get();
|
||||
} catch (e) {
|
||||
if (e.cause === 404) {
|
||||
|
@ -887,11 +887,11 @@ export class SystemKeywords {
|
|||
|
||||
const blank = path.join(process.env.PWD, 'blank.xlsx');
|
||||
const data = fs.readFileSync(blank);
|
||||
await client.api(`${baseUrl}/drive/root:/${path}/${file}:/content`).put(data);
|
||||
await client.api(`${baseUrl}/drive/root:/${packagePath}/${file}:/content`).put(data);
|
||||
|
||||
// Tries to open again.
|
||||
|
||||
document = await this.internalGetDocument(client, baseUrl, path, file);
|
||||
document = await this.internalGetDocument(client, baseUrl, packagePath, file);
|
||||
sheets = await client.api(`${baseUrl}/drive/items/${document.id}/workbook/worksheets`).get();
|
||||
} else {
|
||||
throw e;
|
||||
|
@ -993,9 +993,9 @@ export class SystemKeywords {
|
|||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
const botId = min.instance.botId;
|
||||
('');
|
||||
const path = GBUtil.getGBAIPath(botId, 'gbdata');
|
||||
const packagePath = GBUtil.getGBAIPath(botId, 'gbdata');
|
||||
|
||||
let document = await this.internalGetDocument(client, baseUrl, path, file);
|
||||
let document = await this.internalGetDocument(client, baseUrl, packagePath, file);
|
||||
|
||||
// Creates workbook session that will be discarded.
|
||||
|
||||
|
@ -1091,7 +1091,7 @@ export class SystemKeywords {
|
|||
args.shift();
|
||||
|
||||
const botId = min.instance.botId;
|
||||
const path = GBUtil.getGBAIPath(botId, 'gbdata');
|
||||
const packagePath = GBUtil.getGBAIPath(botId, 'gbdata');
|
||||
|
||||
// MAX LINES property.
|
||||
|
||||
|
@ -1183,7 +1183,7 @@ export class SystemKeywords {
|
|||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
|
||||
let document;
|
||||
document = await this.internalGetDocument(client, baseUrl, path, file);
|
||||
document = await this.internalGetDocument(client, baseUrl, packagePath, file);
|
||||
|
||||
// Creates workbook session that will be discarded.
|
||||
|
||||
|
@ -1519,8 +1519,8 @@ export class SystemKeywords {
|
|||
if (user) {
|
||||
ChatServices.userSystemPrompt[user.userSystemId] = text;
|
||||
|
||||
const path = GBUtil.getGBAIPath(min.botId);
|
||||
const systemPromptFile = urlJoin(process.cwd(), 'work', path, 'users', user.userSystemId, 'systemPrompt.txt');
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId);
|
||||
const systemPromptFile = urlJoin(process.cwd(), 'work', packagePath, 'users', user.userSystemId, 'systemPrompt.txt');
|
||||
fs.writeFileSync(systemPromptFile, text);
|
||||
}
|
||||
}
|
||||
|
@ -1535,7 +1535,7 @@ export class SystemKeywords {
|
|||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
const botId = min.instance.botId;
|
||||
let path = GBUtil.getGBAIPath(min.botId, `gbdrive`);
|
||||
let packagePath = GBUtil.getGBAIPath(min.botId, `gbdrive`);
|
||||
|
||||
// Extracts each part of path to call create folder to each
|
||||
// one of them.
|
||||
|
@ -1556,18 +1556,18 @@ export class SystemKeywords {
|
|||
};
|
||||
|
||||
try {
|
||||
lastFolder = await client.api(`${baseUrl}/drive/root:/${path}:/children`).post(body);
|
||||
lastFolder = await client.api(`${baseUrl}/drive/root:/${packagePath}:/children`).post(body);
|
||||
} catch (error) {
|
||||
if (error.code !== 'nameAlreadyExists') {
|
||||
throw error;
|
||||
} else {
|
||||
lastFolder = await client.api(`${baseUrl}/drive/root:/${urlJoin(path, item)}`).get();
|
||||
lastFolder = await client.api(`${baseUrl}/drive/root:/${urlJoin(packagePath, item)}`).get();
|
||||
}
|
||||
}
|
||||
|
||||
// Increments path to the next child be created.
|
||||
|
||||
path = urlJoin(path, item);
|
||||
packagePath = urlJoin(packagePath, item);
|
||||
});
|
||||
return lastFolder;
|
||||
}
|
||||
|
@ -1584,8 +1584,8 @@ export class SystemKeywords {
|
|||
public async shareFolder({ pid, folder, email, message }) {
|
||||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
const path = GBUtil.getGBAIPath(min.botId, `gbdrive`);
|
||||
const root = urlJoin(path, folder);
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, `gbdrive`);
|
||||
const root = urlJoin(packagePath, folder);
|
||||
|
||||
const src = await client.api(`${baseUrl}/drive/root:/${root}`).get();
|
||||
|
||||
|
@ -1602,11 +1602,11 @@ export class SystemKeywords {
|
|||
await client.api(`https://graph.microsoft.com/v1.0/drives/${driveId}/items/${itemId}/invite`).post(body);
|
||||
}
|
||||
|
||||
public async internalCreateDocument(min, path, content) {
|
||||
GBLogEx.info(min, `CREATE DOCUMENT '${path}...'`);
|
||||
public async internalCreateDocument(min, filePath, content) {
|
||||
GBLogEx.info(min, `CREATE DOCUMENT '${filePath}...'`);
|
||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
const gbaiName = GBUtil.getGBAIPath(min.botId);
|
||||
const tmpDocx = urlJoin(gbaiName, path);
|
||||
const tmpDocx = urlJoin(gbaiName, filePath);
|
||||
|
||||
// Templates a blank {content} tag inside the blank.docx.
|
||||
|
||||
|
@ -1624,9 +1624,9 @@ export class SystemKeywords {
|
|||
await client.api(`${baseUrl}/drive/root:/${tmpDocx}:/content`).put(buf);
|
||||
}
|
||||
|
||||
public async createDocument({ pid, path, content }) {
|
||||
public async createDocument({ pid, packagePath, content }) {
|
||||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||
this.internalCreateDocument(min, path, content);
|
||||
this.internalCreateDocument(min, packagePath, content);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1710,10 +1710,10 @@ export class SystemKeywords {
|
|||
dest = dest.replace(/\\/gi, '/');
|
||||
|
||||
// Determines full path at source and destination.
|
||||
const path = GBUtil.getGBAIPath(min.botId, `gbdrive`);
|
||||
const root = path;
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, `gbdrive`);
|
||||
const root = packagePath;
|
||||
const srcPath = urlJoin(root, src);
|
||||
const dstPath = urlJoin(path, dest);
|
||||
const dstPath = urlJoin(packagePath, dest);
|
||||
|
||||
// Checks if the destination contains subfolders that
|
||||
// need to be created.
|
||||
|
@ -2239,12 +2239,12 @@ export class SystemKeywords {
|
|||
}
|
||||
} else {
|
||||
const botId = min.instance.botId;
|
||||
const path = GBUtil.getGBAIPath(botId, 'gbdata');
|
||||
const packagePath = GBUtil.getGBAIPath(botId, 'gbdata');
|
||||
|
||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
|
||||
let document;
|
||||
document = await this.internalGetDocument(client, baseUrl, path, file);
|
||||
document = await this.internalGetDocument(client, baseUrl, packagePath, file);
|
||||
|
||||
// Creates workbook session that will be discarded.
|
||||
|
||||
|
@ -2586,7 +2586,7 @@ export class SystemKeywords {
|
|||
GBLogEx.info(min, `Auto saving '${file.filename}' (SAVE file).`);
|
||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
|
||||
const path = GBUtil.getGBAIPath(min.botId, `gbdrive`);
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, `gbdrive`);
|
||||
const fileName = file.url ? file.url : file.name;
|
||||
const contentType = mime.lookup(fileName);
|
||||
const ext = path.extname(fileName).substring(1);
|
||||
|
@ -2599,7 +2599,7 @@ export class SystemKeywords {
|
|||
|
||||
const today = [day, month, year].join('-');
|
||||
const result = await client
|
||||
.api(`${baseUrl}/drive/root:/${path}/${today}/${kind.category}/${fileName}:/content`)
|
||||
.api(`${baseUrl}/drive/root:/${packagePath}/${today}/${kind.category}/${fileName}:/content`)
|
||||
.put(file.data);
|
||||
|
||||
return { contentType, ext, kind, category: kind['category'] };
|
||||
|
@ -2676,9 +2676,9 @@ export class SystemKeywords {
|
|||
|
||||
// Retrieves all files in remote folder.
|
||||
|
||||
let path = GBUtil.getGBAIPath(min.botId);
|
||||
path = urlJoin(path, remotePath);
|
||||
let url = `${baseUrl}/drive/root:/${path}:/children`;
|
||||
let packagePath = GBUtil.getGBAIPath(min.botId);
|
||||
packagePath = urlJoin(packagePath, remotePath);
|
||||
let url = `${baseUrl}/drive/root:/${packagePath}:/children`;
|
||||
|
||||
const res = await client.api(url).get();
|
||||
const documents = res.value;
|
||||
|
@ -2725,16 +2725,16 @@ export class SystemKeywords {
|
|||
if (GBConfigService.get('STORAGE_NAME')) {
|
||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
const gbaiName = GBUtil.getGBAIPath(min.botId);
|
||||
let path = '/' + urlJoin(gbaiName, `${min.botId}.gbdrive`);
|
||||
let template = await this.internalGetDocument(client, baseUrl, path, file);
|
||||
let packagePath = '/' + urlJoin(gbaiName, `${min.botId}.gbdrive`);
|
||||
let template = await this.internalGetDocument(client, baseUrl, packagePath, file);
|
||||
let url = template['@microsoft.graph.downloadUrl'];
|
||||
const res = await fetch(url);
|
||||
let buf: any = Buffer.from(await res.arrayBuffer());
|
||||
data = new Uint8Array(buf);
|
||||
}
|
||||
else {
|
||||
let path = GBUtil.getGBAIPath(min.botId, `gbdrive`);
|
||||
let filePath = path.join(GBConfigService.get('STORAGE_LIBRARY'), path, file);
|
||||
let packagePath = GBUtil.getGBAIPath(min.botId, `gbdrive`);
|
||||
let filePath = path.join(GBConfigService.get('STORAGE_LIBRARY'), packagePath, file);
|
||||
data = fs.readFileSync(filePath, 'utf8');
|
||||
data = new Uint8Array(Buffer.from(data, 'utf8'));
|
||||
}
|
||||
|
|
|
@ -680,9 +680,9 @@ ENDPOINT_UPDATE=true
|
|||
|
||||
const maxLines = 512;
|
||||
const file = 'Config.xlsx';
|
||||
const path = GBUtil.getGBAIPath(min.botId, `gbot`);
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, `gbot`);
|
||||
|
||||
let document = await new SystemKeywords().internalGetDocument(client, baseUrl, path, file);
|
||||
let document = await new SystemKeywords().internalGetDocument(client, baseUrl, packagePath, file);
|
||||
|
||||
// Creates book session that will be discarded.
|
||||
|
||||
|
@ -716,8 +716,8 @@ ENDPOINT_UPDATE=true
|
|||
)
|
||||
.patch(body);
|
||||
} else {
|
||||
let path = GBUtil.getGBAIPath(min.botId, `gbot`);
|
||||
const config = path.join(GBConfigService.get('STORAGE_LIBRARY'), path, 'config.csv');
|
||||
let packagePath = GBUtil.getGBAIPath(min.botId, `gbot`);
|
||||
const config = path.join(GBConfigService.get('STORAGE_LIBRARY'), packagePath, 'config.csv');
|
||||
|
||||
const db = await csvdb(config, ['name', 'value'], ',');
|
||||
if (await db.get({ name: name })) {
|
||||
|
|
|
@ -56,7 +56,6 @@ import { GBImporter } from './GBImporterService.js';
|
|||
import { TeamsService } from '../../teams.gblib/services/TeamsService.js';
|
||||
import MicrosoftGraph from '@microsoft/microsoft-graph-client';
|
||||
import { GBLogEx } from './GBLogEx.js';
|
||||
import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js';
|
||||
import { GBUtil } from '../../../src/util.js';
|
||||
import { HNSWLib } from '@langchain/community/vectorstores/hnswlib';
|
||||
import { OpenAIEmbeddings } from '@langchain/openai';
|
||||
|
@ -148,7 +147,7 @@ export class GBDeployer implements IGBDeployer {
|
|||
const gbappPackages: string[] = [];
|
||||
const generalPackages: string[] = [];
|
||||
|
||||
async function scanPackageDirectory(path) {
|
||||
async function scanPackageDirectory(directory) {
|
||||
// Gets all directories.
|
||||
|
||||
const isDirectory = source => fs.lstatSync(source).isDirectory();
|
||||
|
@ -156,7 +155,7 @@ export class GBDeployer implements IGBDeployer {
|
|||
fs.readdirSync(source)
|
||||
.map(name => path.join(source, name))
|
||||
.filter(isDirectory);
|
||||
const dirs = getDirectories(path);
|
||||
const dirs = getDirectories(directory);
|
||||
await CollectionUtil.asyncForEach(dirs, async element => {
|
||||
// For each folder, checks its extensions looking for valid packages.
|
||||
|
||||
|
@ -503,7 +502,7 @@ export class GBDeployer implements IGBDeployer {
|
|||
}
|
||||
|
||||
await CollectionUtil.asyncForEach(parts, async item => {
|
||||
pathBase = path.join(pathBase, item);
|
||||
pathBase = packagePath.join(pathBase, item);
|
||||
if (!fs.existsSync(pathBase)) {
|
||||
fs.mkdirSync(pathBase);
|
||||
}
|
||||
|
@ -511,9 +510,9 @@ export class GBDeployer implements IGBDeployer {
|
|||
|
||||
// Retrieves all files in remote folder.
|
||||
|
||||
let path = GBUtil.getGBAIPath(min.botId);
|
||||
path = urlJoin(path, remotePath);
|
||||
let url = `${baseUrl}/drive/root:/${path}:/children`;
|
||||
let packagePath = GBUtil.getGBAIPath(min.botId);
|
||||
packagePath = urlJoin(packagePath, remotePath);
|
||||
let url = `${baseUrl}/drive/root:/${packagePath}:/children`;
|
||||
|
||||
GBLogEx.info(min, `Download URL: ${url}`);
|
||||
|
||||
|
@ -527,7 +526,7 @@ export class GBDeployer implements IGBDeployer {
|
|||
// Download files or navigate to directory to recurse.
|
||||
|
||||
await CollectionUtil.asyncForEach(documents, async item => {
|
||||
const itemPath = path.join(localPath, remotePath, item.name);
|
||||
const itemPath = packagePath.join(localPath, remotePath, item.name);
|
||||
|
||||
if (item.folder) {
|
||||
if (!fs.existsSync(itemPath)) {
|
||||
|
@ -658,16 +657,16 @@ export class GBDeployer implements IGBDeployer {
|
|||
con['storagePort'] = min.core.getParam<string>(min.instance, `${connectionName} Port`, null);
|
||||
con['storagePassword'] = min.core.getParam<string>(min.instance, `${connectionName} Password`, null);
|
||||
} else if (file) {
|
||||
const path = GBUtil.getGBAIPath(min.botId, 'gbdata');
|
||||
con['storageFile'] = path.join(GBConfigService.get('STORAGE_LIBRARY'), path, file);
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, 'gbdata');
|
||||
con['storageFile'] = path.join(GBConfigService.get('STORAGE_LIBRARY'), packagePath, file);
|
||||
} else {
|
||||
GBLogEx.debug(min, `No storage information found for ${connectionName}, missing storage name or file.`);
|
||||
}
|
||||
connections.push(con);
|
||||
});
|
||||
|
||||
const path = GBUtil.getGBAIPath(min.botId, null);
|
||||
const localFolder = path.join('work', path, 'connections.json');
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, null);
|
||||
const localFolder = path.join('work', packagePath, 'connections.json');
|
||||
fs.writeFileSync(localFolder, JSON.stringify(connections), { encoding: null });
|
||||
|
||||
// Updates instance object.
|
||||
|
@ -726,8 +725,8 @@ export class GBDeployer implements IGBDeployer {
|
|||
* Removes the package local files from cache.
|
||||
*/
|
||||
public async cleanupPackage(instance: IGBInstance, packageName: string) {
|
||||
const path = GBUtil.getGBAIPath(instance.botId, null, packageName);
|
||||
const localFolder = path.join('work', path);
|
||||
const packagePath = GBUtil.getGBAIPath(instance.botId, null, packageName);
|
||||
const localFolder = path.join('work', packagePath);
|
||||
rimraf.sync(localFolder);
|
||||
}
|
||||
|
||||
|
|
|
@ -1095,7 +1095,7 @@ export class GBMinService {
|
|||
ps: null,
|
||||
qs: null
|
||||
});
|
||||
const path = GBUtil.getGBAIPath(min.botId);
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId);
|
||||
const folder = `work/${path}/cache`;
|
||||
const filename = `${GBAdminService.generateUuid()}.png`;
|
||||
|
||||
|
@ -1271,8 +1271,8 @@ export class GBMinService {
|
|||
private static async downloadAttachmentAndWrite(attachment) {
|
||||
const url = attachment.contentUrl;
|
||||
const localFolder = 'work';
|
||||
const path = GBUtil.getGBAIPath(this['min'].botId);
|
||||
const localFileName = path.join(localFolder, path, 'uploads', attachment.name);
|
||||
const packagePath = GBUtil.getGBAIPath(this['min'].botId);
|
||||
const localFileName = path.join(localFolder, packagePath, 'uploads', attachment.name);
|
||||
|
||||
let buffer;
|
||||
if (url.startsWith('data:')) {
|
||||
|
|
|
@ -303,29 +303,29 @@ export class GBSSR {
|
|||
}
|
||||
|
||||
|
||||
let path = GBUtil.getGBAIPath(botId, `gbui`);
|
||||
let packagePath = GBUtil.getGBAIPath(botId, `gbui`);
|
||||
|
||||
// Checks if the bot has an .gbui published or use default.gbui.
|
||||
|
||||
if (!fs.existsSync(path)) {
|
||||
path = GBUtil.getGBAIPath(minBoot.botId, `gbui`);
|
||||
if (!fs.existsSync(packagePath)) {
|
||||
packagePath = GBUtil.getGBAIPath(minBoot.botId, `gbui`);
|
||||
}
|
||||
let parts = req.url.replace(`/${botId}`, '').split('?');
|
||||
let url = parts[0];
|
||||
|
||||
if (min && req.originalUrl && prerender && exclude && fs.existsSync(path)) {
|
||||
if (min && req.originalUrl && prerender && exclude && fs.existsSync(packagePath)) {
|
||||
|
||||
// Reads from static HTML when a bot is crawling.
|
||||
|
||||
path = path.join(process.env.PWD, 'work', path, 'index.html');
|
||||
const html = fs.readFileSync(path, 'utf8');
|
||||
packagePath = path.join(process.env.PWD, 'work', packagePath, 'index.html');
|
||||
const html = fs.readFileSync(packagePath, 'utf8');
|
||||
res.status(200).send(html);
|
||||
return true;
|
||||
} else {
|
||||
|
||||
// Servers default.gbui web application.
|
||||
|
||||
path = path.join(
|
||||
packagePath = path.join(
|
||||
process.env.PWD,
|
||||
GBDeployer.deployFolder,
|
||||
GBMinService.uiPackage,
|
||||
|
@ -333,14 +333,14 @@ export class GBSSR {
|
|||
url === '/' || url === '' ? `index.html` : url
|
||||
);
|
||||
if (GBServer.globals.wwwroot && url === '/') {
|
||||
path = GBServer.globals.wwwroot + "/index.html"; // TODO.
|
||||
packagePath = GBServer.globals.wwwroot + "/index.html"; // TODO.
|
||||
}
|
||||
if (!min && !url.startsWith("/static") && GBServer.globals.wwwroot) {
|
||||
path = path.join(GBServer.globals.wwwroot, url);
|
||||
packagePath = packagePath.join(GBServer.globals.wwwroot, url);
|
||||
}
|
||||
if (fs.existsSync(path)) {
|
||||
if (fs.existsSync(packagePath)) {
|
||||
if (min) {
|
||||
let html = fs.readFileSync(path, 'utf8');
|
||||
let html = fs.readFileSync(packagePath, 'utf8');
|
||||
html = html.replace(/\{p\}/gi, min.botId);
|
||||
html = html.replace(/\{botId\}/gi, min.botId);
|
||||
html = html.replace(/\{theme\}/gi, min.instance.theme ? min.instance.theme :
|
||||
|
@ -348,7 +348,7 @@ export class GBSSR {
|
|||
html = html.replace(/\{title\}/gi, min.instance.title);
|
||||
res.send(html).end();
|
||||
} else {
|
||||
res.sendFile(path);
|
||||
res.sendFile(packagePath);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
@ -246,8 +246,8 @@ export class AskDialog extends IGBDialog {
|
|||
|
||||
for (const key in results.sources) {
|
||||
const source = results.sources[key];
|
||||
const path = GBUtil.getGBAIPath(min.botId, `gbkb`);
|
||||
let url = urlJoin('kb', path, 'docs', path.basename(source.file));
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, `gbkb`);
|
||||
let url = urlJoin('kb', packagePath, 'docs', path.basename(source.file));
|
||||
url = `${url}#page=${source.page}&toolbar=0&messages=0&statusbar=0&navpanes=0`;
|
||||
urls.push({ url: url });
|
||||
}
|
||||
|
|
|
@ -164,8 +164,8 @@ export class KBService implements IGBKBService {
|
|||
|
||||
// Extracts botId from URL.
|
||||
|
||||
let path = /(http[s]?:\/\/)?([^\/\s]+\/)(.*)/gi;
|
||||
const botId = url.replace(path, ($0, $1, $2, $3) => {
|
||||
let packagePath = /(http[s]?:\/\/)?([^\/\s]+\/)(.*)/gi;
|
||||
const botId = url.replace(packagePath, ($0, $1, $2, $3) => {
|
||||
return $3.substr($3.indexOf('/'));
|
||||
});
|
||||
|
||||
|
@ -555,9 +555,9 @@ export class KBService implements IGBKBService {
|
|||
const isBasic = answer.toLowerCase().startsWith('/basic');
|
||||
if (/TALK\s*\".*\"/gi.test(answer) || isBasic) {
|
||||
const code = isBasic ? answer.substr(6) : answer;
|
||||
const path = GBUtil.getGBAIPath(min.botId, `gbdialog`);
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, `gbdialog`);
|
||||
const scriptName = `tmp${GBAdminService.getRndReadableIdentifier()}.docx`;
|
||||
const localName = path.join('work', path, `${scriptName}`);
|
||||
const localName = path.join('work', packagePath, `${scriptName}`);
|
||||
fs.writeFileSync(localName, code, { encoding: null });
|
||||
answer = scriptName;
|
||||
|
||||
|
@ -630,13 +630,13 @@ export class KBService implements IGBKBService {
|
|||
answer.endsWith('.xls') ||
|
||||
answer.endsWith('.xlsx')
|
||||
) {
|
||||
const path = GBUtil.getGBAIPath(min.botId, `gbkb`);
|
||||
const doc = urlJoin(GBServer.globals.publicAddress, 'kb', path, 'assets', answer);
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, `gbkb`);
|
||||
const doc = urlJoin(GBServer.globals.publicAddress, 'kb', packagePath, 'assets', answer);
|
||||
const url = `http://view.officeapps.live.com/op/view.aspx?src=${doc}`;
|
||||
await this.playUrl(min, min.conversationalService, step, url, channel);
|
||||
} else if (answer.endsWith('.pdf')) {
|
||||
const path = GBUtil.getGBAIPath(min.botId, `gbkb`);
|
||||
const url = urlJoin('kb', path, 'assets', answer);
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, `gbkb`);
|
||||
const url = urlJoin('kb', packagePath, 'assets', answer);
|
||||
await this.playUrl(min, min.conversationalService, step, url, channel);
|
||||
} else if (answer.format === '.md') {
|
||||
await min.conversationalService['playMarkdown'](min, answer, channel, step, GBMinService.userMobile(step));
|
||||
|
@ -737,8 +737,8 @@ export class KBService implements IGBKBService {
|
|||
});
|
||||
}
|
||||
} else if (file !== null && file.name.endsWith('.docx')) {
|
||||
let path = GBUtil.getGBAIPath(instance.botId, `gbkb`);
|
||||
const localName = path.join('work', path, 'articles', file.name);
|
||||
let packagePath = GBUtil.getGBAIPath(instance.botId, `gbkb`);
|
||||
const localName = path.join('work', packagePath, 'articles', file.name);
|
||||
let loader = new DocxLoader(localName);
|
||||
let doc = await loader.load();
|
||||
let content = doc[0].pageContent;
|
||||
|
@ -758,8 +758,8 @@ export class KBService implements IGBKBService {
|
|||
|
||||
data.answers.push(answer);
|
||||
} else if (file !== null && file.name.endsWith('.toc.docx')) {
|
||||
const path = GBUtil.getGBAIPath(instance.botId, `gbkb`);
|
||||
const localName = path.join('work', path, 'articles', file.name);
|
||||
const packagePath = GBUtil.getGBAIPath(instance.botId, `gbkb`);
|
||||
const localName = path.join('work', packagePath, 'articles', file.name);
|
||||
const buffer = fs.readFileSync(localName, { encoding: null });
|
||||
var options = {
|
||||
buffer: buffer,
|
||||
|
@ -885,8 +885,8 @@ export class KBService implements IGBKBService {
|
|||
await GBLogEx.info(min, `Processing URL: ${url}.`);
|
||||
visited.add(url);
|
||||
|
||||
const path = GBUtil.getGBAIPath(min.botId, `gbot`);
|
||||
const directoryPath = path.join(process.env.PWD, 'work', path, 'Website');
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, `gbot`);
|
||||
const directoryPath = path.join(process.env.PWD, 'work', packagePath, 'Website');
|
||||
const filename = await GBUtil.savePage(url, page, directoryPath);
|
||||
|
||||
if (!filename) {
|
||||
|
@ -1023,8 +1023,8 @@ export class KBService implements IGBKBService {
|
|||
|
||||
website.endsWith('/') ? website.substring(0, website.length - 1) : website;
|
||||
|
||||
let path = GBUtil.getGBAIPath(min.botId, `gbot`);
|
||||
const directoryPath = path.join(process.env.PWD, 'work', path, 'Website');
|
||||
let packagePath = GBUtil.getGBAIPath(min.botId, `gbot`);
|
||||
const directoryPath = path.join(process.env.PWD, 'work', packagePath, 'Website');
|
||||
fs.rmSync(directoryPath, { recursive: true, force: true });
|
||||
|
||||
let browser = await puppeteer.launch({ headless: false });
|
||||
|
@ -1032,7 +1032,7 @@ export class KBService implements IGBKBService {
|
|||
|
||||
let logo = await this.getLogoByPage(min, page);
|
||||
if (logo) {
|
||||
path = GBUtil.getGBAIPath(min.botId);
|
||||
packagePath = GBUtil.getGBAIPath(min.botId);
|
||||
|
||||
const baseUrl = page.url().split('/').slice(0, 3).join('/');
|
||||
logo = logo.startsWith('https') ? logo : urlJoin(baseUrl, logo);
|
||||
|
@ -1040,7 +1040,7 @@ export class KBService implements IGBKBService {
|
|||
try {
|
||||
const logoBinary = await page.goto(logo);
|
||||
const buffer = await logoBinary.buffer();
|
||||
const logoFilename = path.basename(logo);
|
||||
const logoFilename = packagePath.basename(logo);
|
||||
// TODO: sharp(buffer)
|
||||
// .resize({
|
||||
// width: 48,
|
||||
|
@ -1396,10 +1396,10 @@ export class KBService implements IGBKBService {
|
|||
if (channel === 'whatsapp') {
|
||||
await min.conversationalService.sendFile(min, step, null, answer.content, '');
|
||||
} else {
|
||||
const path = GBUtil.getGBAIPath(min.botId, `gbkb`);
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, `gbkb`);
|
||||
await conversationalService.sendEvent(min, step, 'play', {
|
||||
playerType: 'video',
|
||||
data: urlJoin(path, 'videos', answer.content)
|
||||
data: urlJoin(packagePath, 'videos', answer.content)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -568,6 +568,7 @@ export class ChatServices {
|
|||
Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the LIMIT clause as per SQL. You can order the results to return the most informative data in the database.
|
||||
Never query for all columns from a table. You must query only the columns that are needed to answer the question. Wrap each column name in double quotes (") to denote them as delimited identifiers.
|
||||
Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.
|
||||
Attention not to generate ambiguous column name, qualifing tables on joins.
|
||||
|
||||
VERY IMPORTANT: Return just the generated SQL command as plain text with no Markdown or formmating.
|
||||
------------
|
||||
|
@ -708,8 +709,8 @@ export class ChatServices {
|
|||
|
||||
// Adds .gbdialog as functions if any to LLM Functions.
|
||||
await CollectionUtil.asyncForEach(Object.keys(min.scriptMap), async script => {
|
||||
const path = GBUtil.getGBAIPath(min.botId, 'gbdialog', null);
|
||||
const jsonFile = path.join('work', path, `${script}.json`);
|
||||
const packagePath = GBUtil.getGBAIPath(min.botId, 'gbdialog', null);
|
||||
const jsonFile = path.join('work', packagePath, `${script}.json`);
|
||||
|
||||
if (fs.existsSync(jsonFile) && script.toLowerCase() !== 'start.vbs') {
|
||||
const funcJSON = JSON.parse(fs.readFileSync(jsonFile, 'utf8'));
|
||||
|
|
|
@ -112,7 +112,7 @@ export class Package implements IGBPackage {
|
|||
|
||||
|
||||
|
||||
public async getTasksMarkdown(path, file) {
|
||||
public async getTasksMarkdown(packagePath, file) {
|
||||
|
||||
let token =
|
||||
await this.adminService.acquireElevatedToken(this.instanceId);
|
||||
|
@ -126,7 +126,7 @@ export class Package implements IGBPackage {
|
|||
let libraryId = process.env.STORAGE_LIBRARY;
|
||||
|
||||
let res = await client.api(
|
||||
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`)
|
||||
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${packagePath}:/children`)
|
||||
.get();
|
||||
|
||||
let document = res.value.filter(m => {
|
||||
|
|
|
@ -139,7 +139,7 @@ export class GBOService {
|
|||
done(null, token);
|
||||
}
|
||||
});
|
||||
const path = `/`;
|
||||
const packagePath = `/`;
|
||||
let res = await client.api(
|
||||
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${templateLibraryId}/drive/root/children`)
|
||||
.get();
|
||||
|
|
|
@ -763,14 +763,14 @@ export class WhatsappDirectLine extends GBService {
|
|||
|
||||
// Set folder based on media type
|
||||
let folder = mediaType === 'video' ? 'videos' : 'images';
|
||||
let path = GBUtil.getGBAIPath(min.botId, `gbkb`);
|
||||
path = path.join(process.env.PWD, 'work', path, folder, mediaFile);
|
||||
let packagePath = GBUtil.getGBAIPath(min.botId, `gbkb`);
|
||||
packagePath = path.join(process.env.PWD, 'work', packagePath, folder, mediaFile);
|
||||
|
||||
text = text.substring(mediaFile.length + 1).trim();
|
||||
text = text.replace(/\n/g, '\\n');
|
||||
|
||||
// Upload the media file based on media type
|
||||
const handleMedia = await min.whatsAppDirectLine.uploadLargeFile(min, path);
|
||||
const handleMedia = await min.whatsAppDirectLine.uploadLargeFile(min, packagePath);
|
||||
|
||||
let data: any = {
|
||||
name: template,
|
||||
|
|
Loading…
Add table
Reference in a new issue