Skip to content

Commit faf00a1

Browse files
committed
🔧 refactor(Dockerfile, package.json, botservice.ts, mm-client.ts, ImagePlugin.ts, PluginBase.ts, vite.config.ts): package updates and code improvements
In Dockerfile, updated the node version from 16 to 20. This allows us to use the latest features and security patches. In package.json, updated several packages and added "node-fetch". This allows us to use the latest features and improves the stability and performance of the code. In botservice.ts, mm-client.ts, ImagePlugin.ts, PluginBase.ts, made several improvements to improve the readability and maintainability of the code.
1 parent fde42d4 commit faf00a1

File tree

9 files changed

+1383
-250
lines changed

9 files changed

+1383
-250
lines changed

‎Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# NPM builder image
2-
FROM node:16-slim as npm_builder
2+
FROM node:20-slim as npm_builder
33
#20.3.0-bookworm-slim (Debian 12)
44

55
WORKDIR /app
@@ -17,7 +17,7 @@ RUN rm -rf node_modules/ && npm ci --omit dev
1717

1818

1919
# NPM runtime image
20-
FROM node:16-slim as npm_runtime
20+
FROM node:20-slim as npm_runtime
2121

2222
WORKDIR /app
2323

‎dist/botservice.mjs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,21 @@ async function createImage(prompt) {
159159
}
160160

161161
// src/mm-client.ts
162-
import Log2 from "debug-level";
163162
import { WebSocket } from "ws";
163+
import fetch from "node-fetch";
164164
import pkg from "@mattermost/client";
165+
var { Client4, WebSocketClient } = pkg;
165166
if (!global.WebSocket) {
166167
global.WebSocket = WebSocket;
167168
}
168-
var { Client4, WebSocketClient } = pkg;
169-
var log = new Log2("bot");
169+
global.fetch = fetch;
170170
var mattermostToken = process.env["MATTERMOST_TOKEN"];
171171
var matterMostURLString = process.env["MATTERMOST_URL"];
172172
if (!mattermostToken || !matterMostURLString) {
173-
log.error("MATTERMOST_TOKEN or MATTERMOST_URL is undefined");
173+
botLog.error("MATTERMOST_TOKEN or MATTERMOST_URL is undefined");
174174
throw new Error("MATTERMOST_TOKEN or MATTERMOST_URL is undefined");
175175
}
176-
log.trace("Configuring Mattermost URL to " + matterMostURLString);
176+
botLog.trace("Configuring Mattermost URL to " + matterMostURLString);
177177
var mmClient = new Client4();
178178
mmClient.setUrl(matterMostURLString);
179179
mmClient.setToken(mattermostToken);
@@ -188,7 +188,7 @@ new Promise((_resolve, reject) => {
188188
}).then(() => {
189189
process.exit(0);
190190
}).catch((reason) => {
191-
log.error(reason);
191+
botLog.error(reason);
192192
process.exit(-1);
193193
});
194194
function workaroundWebsocketPackageLostIssue(webSocketClient) {
@@ -204,13 +204,12 @@ workaroundWebsocketPackageLostIssue(wsClient);
204204
wsClient.initialize(wsUrl.toString(), mattermostToken);
205205

206206
// src/plugins/PluginBase.ts
207-
import { Log as Log3 } from "debug-level";
208207
var PluginBase = class {
209208
constructor(key, description) {
210209
this.key = key;
211210
this.description = description;
212211
}
213-
log = new Log3("bot");
212+
log = botLog;
214213
pluginArguments = {};
215214
requiredArguments = [];
216215
setup() {
@@ -241,7 +240,7 @@ import FormData3 from "form-data";
241240
// src/plugins/GraphPlugin.ts
242241
import { ChatCompletionRequestMessageRoleEnum } from "openai";
243242
import FormData from "form-data";
244-
import fetch from "node-fetch";
243+
import fetch2 from "node-fetch";
245244
var GraphPlugin = class extends PluginBase {
246245
yFilesGPTServerUrl = process.env["YFILES_SERVER_URL"];
247246
yFilesEndpoint = this.yFilesGPTServerUrl ? new URL("/json-to-svg", this.yFilesGPTServerUrl) : void 0;
@@ -311,7 +310,7 @@ ${graphContent}`);
311310
return result;
312311
}
313312
async generateSvg(jsonString) {
314-
return fetch(this.yFilesEndpoint, {
313+
return fetch2(this.yFilesEndpoint, {
315314
method: "POST",
316315
body: jsonString,
317316
headers: {
@@ -356,7 +355,11 @@ var ImagePlugin = class extends PluginBase {
356355
const imagePrompt = await this.createImagePrompt(args.imageDescription);
357356
if (imagePrompt) {
358357
this.log.trace({ imageInputPrompt: args.imageDescription, imageOutputPrompt: imagePrompt });
359-
const base64Image = await createImage(imagePrompt);
358+
const base64Image = (
359+
/*this.img256 //*/
360+
/*this.sampleB64String */
361+
await createImage(imagePrompt)
362+
);
360363
if (base64Image) {
361364
const fileId = await this.base64ToFile(base64Image, msgData.post.channel_id);
362365
aiResponse.message = "Here is the image you requested: " + imagePrompt;

0 commit comments

Comments
 (0)