fix(basic.gblib): Debugger improvements.
This commit is contained in:
parent
2de41ee250
commit
3e68858bb0
5 changed files with 65 additions and 33 deletions
4
boot.mjs
4
boot.mjs
|
@ -13,7 +13,7 @@ console.log(`██ █ ███ █ █ ██ ██ ██
|
||||||
console.log(`██ ███ ████ █ ██ █ ████ █████ ██████ ██ ████ █ █ █ ██ `);
|
console.log(`██ ███ ████ █ ██ █ ████ █████ ██████ ██ ████ █ █ █ ██ `);
|
||||||
console.log(`██ ██ █ █ ██ █ █ ██ ██ ██ ██ ██ ██ █ ██ ██ █ █ `);
|
console.log(`██ ██ █ █ ██ █ █ ██ ██ ██ ██ ██ ██ █ ██ ██ █ █ `);
|
||||||
console.log(` █████ █████ █ ███ █████ ██ ██ ██ ██ ██████ ████ █████ █ ███ 3.0`);
|
console.log(` █████ █████ █ ███ █████ ██ ██ ██ ██ ██████ ████ █████ █ ███ 3.0`);
|
||||||
console.log(` botserver@${pjson.version}, botlib@${pjson.dependencies.botlib}, botbuilder@${pjson.dependencies.botbuilder}, node@${process.version.replace('v', '')}, ${process.platform} ${process.arch}`);
|
process.stdout.write(` botserver@${pjson.version}, botlib@${pjson.dependencies.botlib}, botbuilder@${pjson.dependencies.botbuilder}, node@${process.version.replace('v', '')}, ${process.platform} ${process.arch}`);
|
||||||
|
|
||||||
var now = () => {
|
var now = () => {
|
||||||
return new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '') + ' UTC';
|
return new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '') + ' UTC';
|
||||||
|
@ -22,7 +22,7 @@ var __dirname = process.env.PWD || process.cwd();
|
||||||
try {
|
try {
|
||||||
var run = () => {
|
var run = () => {
|
||||||
import('./dist/src/app.js').then((gb)=> {
|
import('./dist/src/app.js').then((gb)=> {
|
||||||
console.log(``);
|
console.log(`\n`);
|
||||||
gb.GBServer.run()
|
gb.GBServer.run()
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -65,6 +65,7 @@
|
||||||
"@google-cloud/pubsub": "3.2.1",
|
"@google-cloud/pubsub": "3.2.1",
|
||||||
"@google-cloud/translate": "7.0.4",
|
"@google-cloud/translate": "7.0.4",
|
||||||
"@hubspot/api-client": "7.1.2",
|
"@hubspot/api-client": "7.1.2",
|
||||||
|
"@koa/cors": "4.0.0",
|
||||||
"@microsoft/microsoft-graph-client": "3.0.4",
|
"@microsoft/microsoft-graph-client": "3.0.4",
|
||||||
"@nlpjs/basic": "4.26.1",
|
"@nlpjs/basic": "4.26.1",
|
||||||
"@nosferatu500/textract": "3.1.2",
|
"@nosferatu500/textract": "3.1.2",
|
||||||
|
|
|
@ -45,6 +45,7 @@ import { WebAutomationServices } from './services/WebAutomationServices.js';
|
||||||
import { ImageProcessingServices } from './services/ImageProcessingServices.js';
|
import { ImageProcessingServices } from './services/ImageProcessingServices.js';
|
||||||
import { DebuggerService } from './services/DebuggerService.js';
|
import { DebuggerService } from './services/DebuggerService.js';
|
||||||
import Koa from 'koa';
|
import Koa from 'koa';
|
||||||
|
import cors from '@koa/cors';
|
||||||
import { createRpcServer } from '@push-rpc/core';
|
import { createRpcServer } from '@push-rpc/core';
|
||||||
import { createHttpKoaMiddleware } from '@push-rpc/http';
|
import { createHttpKoaMiddleware } from '@push-rpc/http';
|
||||||
import { HttpServerOptions } from '@push-rpc/http/dist/server.js';
|
import { HttpServerOptions } from '@push-rpc/http/dist/server.js';
|
||||||
|
@ -63,6 +64,7 @@ export function createKoaHttpServer(
|
||||||
const { onError, onConnection, middleware } = createHttpKoaMiddleware(getRemoteId, opts);
|
const { onError, onConnection, middleware } = createHttpKoaMiddleware(getRemoteId, opts);
|
||||||
|
|
||||||
const app = new Koa();
|
const app = new Koa();
|
||||||
|
app.use(cors({ origin: '*' }));
|
||||||
app.use(koaBody.koaBody({ multipart: true }));
|
app.use(koaBody.koaBody({ multipart: true }));
|
||||||
app.use(middleware);
|
app.use(middleware);
|
||||||
const server = app.listen(port);
|
const server = app.listen(port);
|
||||||
|
@ -117,10 +119,10 @@ export class GBBasicPackage implements IGBPackage {
|
||||||
disconnected(remoteId: string, connections: number): void {},
|
disconnected(remoteId: string, connections: number): void {},
|
||||||
connected(remoteId: string, connections: number): void {},
|
connected(remoteId: string, connections: number): void {},
|
||||||
messageIn(...params): void {
|
messageIn(...params): void {
|
||||||
GBLogEx.info(min, 'API IN' + params);
|
GBLogEx.info(min, '[IN] ' + params);
|
||||||
},
|
},
|
||||||
messageOut(...params): void {
|
messageOut(...params): void {
|
||||||
GBLogEx.info(min, 'API OUT ' + params);
|
GBLogEx.info(min, '[OUT] ' + params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -156,7 +158,7 @@ export class GBBasicPackage implements IGBPackage {
|
||||||
GBServer.globals.debuggers[botId].stateInfo = 'Stopped';
|
GBServer.globals.debuggers[botId].stateInfo = 'Stopped';
|
||||||
GBServer.globals.debuggers[botId].childProcess = null;
|
GBServer.globals.debuggers[botId].childProcess = null;
|
||||||
GBServer.globals.debuggers[botId].client = null;
|
GBServer.globals.debuggers[botId].client = null;
|
||||||
GBServer.globals.debuggers[botId].conversationsMap = {};
|
GBServer.globals.debuggers[botId].conversationId = null;
|
||||||
GBServer.globals.debuggers[botId].watermarkMap = {};
|
GBServer.globals.debuggers[botId].watermarkMap = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,10 +34,8 @@
|
||||||
|
|
||||||
import { GBLog, GBMinInstance } from 'botlib';
|
import { GBLog, GBMinInstance } from 'botlib';
|
||||||
import { GBServer } from '../../../src/app.js';
|
import { GBServer } from '../../../src/app.js';
|
||||||
import { GuaribasUser } from '../../security.gbapp/models/index.js';
|
|
||||||
import { DialogKeywords } from './DialogKeywords.js';
|
|
||||||
import Fs from 'fs';
|
import Fs from 'fs';
|
||||||
import Swagger from 'swagger-client';
|
import SwaggerClient from 'swagger-client';
|
||||||
import { spawn } from 'child_process';
|
import { spawn } from 'child_process';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -135,12 +133,12 @@ export class DebuggerService {
|
||||||
'valueOf'
|
'valueOf'
|
||||||
];
|
];
|
||||||
|
|
||||||
public async breakpoint ({ botId, line }) {
|
public async setBreakpoint({ botId, line }) {
|
||||||
GBLog.info(`BASIC: Enabled breakpoint for ${botId} on ${line}.`);
|
GBLog.info(`BASIC: Enabled breakpoint for ${botId} on ${line}.`);
|
||||||
GBServer.globals.debuggers[botId].breaks.push(Number.parseInt(line));
|
GBServer.globals.debuggers[botId].breaks.push(Number.parseInt(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async resume ({ botId }) {
|
public async resume({ botId }) {
|
||||||
if (GBServer.globals.debuggers[botId].state === 2) {
|
if (GBServer.globals.debuggers[botId].state === 2) {
|
||||||
const client = GBServer.globals.debuggers[botId].client;
|
const client = GBServer.globals.debuggers[botId].client;
|
||||||
await client.Debugger.resume();
|
await client.Debugger.resume();
|
||||||
|
@ -153,7 +151,7 @@ export class DebuggerService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async stop ({ botId }) {
|
public async stop({ botId }) {
|
||||||
GBServer.globals.debuggers[botId].state = 0;
|
GBServer.globals.debuggers[botId].state = 0;
|
||||||
GBServer.globals.debuggers[botId].stateInfo = 'Stopped';
|
GBServer.globals.debuggers[botId].stateInfo = 'Stopped';
|
||||||
|
|
||||||
|
@ -166,7 +164,7 @@ export class DebuggerService {
|
||||||
return { status: 'OK' };
|
return { status: 'OK' };
|
||||||
}
|
}
|
||||||
|
|
||||||
public async step ({ botId }) {
|
public async step({ botId }) {
|
||||||
if (GBServer.globals.debuggers[botId].state === 2) {
|
if (GBServer.globals.debuggers[botId].state === 2) {
|
||||||
GBServer.globals.debuggers[botId].stateInfo = 'Break';
|
GBServer.globals.debuggers[botId].stateInfo = 'Break';
|
||||||
const client = GBServer.globals.debuggers[botId].client;
|
const client = GBServer.globals.debuggers[botId].client;
|
||||||
|
@ -178,7 +176,7 @@ export class DebuggerService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async context ({ botId }) {
|
public async getContext({ botId }) {
|
||||||
const conversationsMap = GBServer.globals.debuggers[botId].conversationsMap;
|
const conversationsMap = GBServer.globals.debuggers[botId].conversationsMap;
|
||||||
const watermarkMap = GBServer.globals.debuggers[botId].watermarkMap;
|
const watermarkMap = GBServer.globals.debuggers[botId].watermarkMap;
|
||||||
|
|
||||||
|
@ -186,7 +184,7 @@ export class DebuggerService {
|
||||||
let messages = [];
|
let messages = [];
|
||||||
const client = GBServer.globals.debuggers[botId].client;
|
const client = GBServer.globals.debuggers[botId].client;
|
||||||
if (client) {
|
if (client) {
|
||||||
const response = await client.Conversations.Conversations_GetActivities({
|
const response = await client.apis.Conversations.Conversations_GetActivities({
|
||||||
conversationId: conversationId,
|
conversationId: conversationId,
|
||||||
watermark: watermarkMap[botId]
|
watermark: watermarkMap[botId]
|
||||||
});
|
});
|
||||||
|
@ -215,11 +213,10 @@ export class DebuggerService {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getRunning ({ botId, botApiKey, scriptName }) {
|
public async start({ botId, botApiKey, scriptName }) {
|
||||||
const conversationsMap = GBServer.globals.debuggers[botId].conversationsMap;
|
const conversationsMap = GBServer.globals.debuggers[botId].conversationsMap;
|
||||||
|
|
||||||
let error;
|
let error;
|
||||||
botId = botId[0];
|
|
||||||
if (!GBServer.globals.debuggers[botId]) {
|
if (!GBServer.globals.debuggers[botId]) {
|
||||||
GBServer.globals.debuggers[botId] = {};
|
GBServer.globals.debuggers[botId] = {};
|
||||||
}
|
}
|
||||||
|
@ -242,29 +239,26 @@ export class DebuggerService {
|
||||||
|
|
||||||
let min: GBMinInstance = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
let min: GBMinInstance = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
||||||
|
|
||||||
GBServer.globals.debuggers[botId].client = await new Swagger({
|
const client = await new SwaggerClient({
|
||||||
spec: JSON.parse(Fs.readFileSync('directline-3.0.json', 'utf8')),
|
spec: JSON.parse(Fs.readFileSync('directline-3.0.json', 'utf8')),
|
||||||
usePromise: true
|
requestInterceptor: req => {
|
||||||
|
req.headers['Authorization'] = `Bearer ${min.instance.webchatKey}`;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
const client = GBServer.globals.debuggers[botId].client;
|
GBServer.globals.debuggers[botId].client = client;
|
||||||
client.clientAuthorizations.add(
|
const response = await client.apis.Conversations.Conversations_StartConversation();
|
||||||
'AuthorizationBotConnector',
|
|
||||||
new Swagger.ApiKeyAuthorization('Authorization', `Bearer ${min.instance.webchatKey}`, 'header')
|
|
||||||
);
|
|
||||||
const response = await client.Conversations.Conversations_StartConversation();
|
|
||||||
const conversationId = response.obj.conversationId;
|
const conversationId = response.obj.conversationId;
|
||||||
conversationsMap[botId] = conversationId;
|
GBServer.globals.debuggers[botId].conversationId = conversationId;
|
||||||
GBServer.globals.debugConversationId = conversationId;
|
|
||||||
|
|
||||||
client.Conversations.Conversations_PostActivity({
|
client.apis.Conversations.Conversations_PostActivity({
|
||||||
conversationId: conversationId,
|
conversationId: conversationId,
|
||||||
activity: {
|
activity: {
|
||||||
textFormat: 'plain',
|
textFormat: 'plain',
|
||||||
text: `/calldbg ${scriptName}`,
|
text: `/calldbg ${scriptName}`,
|
||||||
type: 'message',
|
type: 'message',
|
||||||
from: {
|
from: {
|
||||||
id: 'test',
|
id: 'word',
|
||||||
name: 'test'
|
name: 'word'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -272,4 +266,39 @@ export class DebuggerService {
|
||||||
return { status: 'OK' };
|
return { status: 'OK' };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async sendMessage({ botId, botApiKey, text }) {
|
||||||
|
const conversationsMap = GBServer.globals.debuggers[botId].conversationsMap;
|
||||||
|
|
||||||
|
let error;
|
||||||
|
if (!GBServer.globals.debuggers[botId]) {
|
||||||
|
GBServer.globals.debuggers[botId] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GBServer.globals.debuggers[botId].state != 1) {
|
||||||
|
error = `Cannot sendMessage to an stopped process. ${botId}`;
|
||||||
|
return { error: error };
|
||||||
|
}
|
||||||
|
|
||||||
|
let min: GBMinInstance = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
||||||
|
|
||||||
|
const client = GBServer.globals.debuggers[botId].client;
|
||||||
|
const conversationId = GBServer.globals.debuggers[botId].conversationId;
|
||||||
|
|
||||||
|
client.apis.Conversations.Conversations_PostActivity({
|
||||||
|
conversationId: conversationId,
|
||||||
|
activity: {
|
||||||
|
textFormat: 'plain',
|
||||||
|
text: text,
|
||||||
|
type: 'message',
|
||||||
|
from: {
|
||||||
|
id: 'word',
|
||||||
|
name: 'word'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return { status: 'OK' };
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,13 +212,13 @@ export class GBVMService extends GBService {
|
||||||
|
|
||||||
let url;
|
let url;
|
||||||
url = 'http://localhost:${GBVMService.API_PORT}/api/v3/${min.botId}/dk';
|
url = 'http://localhost:${GBVMService.API_PORT}/api/v3/${min.botId}/dk';
|
||||||
const dk = (await createRpcClient(0, async () => createHttpClient(url))).remote;
|
const dk = (await createRpcClient(0, () => createHttpClient(url))).remote;
|
||||||
url = 'http://localhost:${GBVMService.API_PORT}/api/v3/${min.botId}/sys';
|
url = 'http://localhost:${GBVMService.API_PORT}/api/v3/${min.botId}/sys';
|
||||||
const sys = (await createRpcClient(0, async () => createHttpClient(url))).remote;
|
const sys = (await createRpcClient(0, () => createHttpClient(url))).remote;
|
||||||
url = 'http://localhost:${GBVMService.API_PORT}/api/v3/${min.botId}/wa';
|
url = 'http://localhost:${GBVMService.API_PORT}/api/v3/${min.botId}/wa';
|
||||||
const wa = (await createRpcClient(0, async () => createHttpClient(url))).remote;
|
const wa = (await createRpcClient(0, () => createHttpClient(url))).remote;
|
||||||
url = 'http://localhost:${GBVMService.API_PORT}/api/v3/${min.botId}/img';
|
url = 'http://localhost:${GBVMService.API_PORT}/api/v3/${min.botId}/img';
|
||||||
const img = (await createRpcClient(0, async () => createHttpClient(url))).remote;
|
const img = (await createRpcClient(0, () => createHttpClient(url))).remote;
|
||||||
|
|
||||||
// Unmarshalls Local variables from server VM.
|
// Unmarshalls Local variables from server VM.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue