utilitas 2000.3.36 → 2000.3.39

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.
package/lib/alan.mjs CHANGED
@@ -1072,14 +1072,16 @@ const promptGoogle = async (aiId, prompt, options = {}) => {
1072
1072
  x => x.raiFilteredReason
1073
1073
  )?.raiFilteredReason || ERROR_GENERATING);
1074
1074
  if (!options?.raw) {
1075
+ const model = packModelLabel([provider, M.source, M.name]);
1075
1076
  resp = {
1076
- text: '', images: await Promise.all((
1077
+ text: `🎨 by ${model}`,
1078
+ images: await Promise.all((
1077
1079
  resp?.generatedImages || []
1078
1080
  ).map(async x => ({
1079
1081
  data: await convert(x.image.imageBytes, {
1080
1082
  input: BASE64, suffix: 'png', ...options || {}
1081
1083
  }), mimeType: x.image.mimeType,
1082
- }))), model: packModelLabel([provider, M.source, M.name]),
1084
+ }))), model,
1083
1085
  }
1084
1086
  }
1085
1087
  } else if (M?.video) {
@@ -1110,8 +1112,10 @@ const promptGoogle = async (aiId, prompt, options = {}) => {
1110
1112
  if (options?.videoRaw) {
1111
1113
  resp = resp?.response?.generatedVideos;
1112
1114
  } else if (!options?.videoRaw) {
1115
+ const model = packModelLabel([provider, M.source, M.name]);
1113
1116
  resp = {
1114
- text: '', videos: await Promise.all(resp?.response?.generatedVideos?.filter(
1117
+ text: `🎬 by ${model}`,
1118
+ videos: await Promise.all(resp?.response?.generatedVideos?.filter(
1115
1119
  x => x?.video?.uri
1116
1120
  ).map(async x => {
1117
1121
  const downloadPath = `${getTempPath({
@@ -1126,7 +1130,7 @@ const promptGoogle = async (aiId, prompt, options = {}) => {
1126
1130
  input: FILE, suffix: 'mp4', ...options || {}
1127
1131
  }), mimeType: MIME_MP4, jobId: resp.name,
1128
1132
  };
1129
- })), model: packModelLabel([provider, M.source, M.name]),
1133
+ })), model,
1130
1134
  };
1131
1135
  }
1132
1136
  } else if (M?.audio) { // https://ai.google.dev/gemini-api/docs/speech-generation#voices
@@ -1146,12 +1150,13 @@ const promptGoogle = async (aiId, prompt, options = {}) => {
1146
1150
  const rawAudio = resp?.candidates?.[0]?.content?.parts?.[0]?.inlineData;
1147
1151
  assert(rawAudio, ERROR_GENERATING, 500);
1148
1152
  if (!options?.raw) {
1153
+ const model = packModelLabel([provider, M.source, M.name]);
1149
1154
  resp = {
1150
- text: '', audio: {
1155
+ text: `🗣️ by ${model}`, audio: {
1151
1156
  data: await packPcmToWav(rawAudio?.data, {
1152
1157
  input: BASE64, suffix: wav, ...options || {},
1153
1158
  }), mimeType: MIME_WAV,
1154
- }, model: packModelLabel([provider, M.source, M.name]),
1159
+ }, model,
1155
1160
  };
1156
1161
  }
1157
1162
  } else {
@@ -1183,13 +1188,14 @@ const promptOpenAI = async (aiId, prompt, options = {}) => {
1183
1188
  input: prompt, ...options?.params || {},
1184
1189
  });
1185
1190
  if (!options?.raw) {
1191
+ const model = packModelLabel([provider, M.source, M.name]);
1186
1192
  resp = {
1187
- text: '', audio: {
1193
+ text: `🗣️ by ${model}`, audio: {
1188
1194
  data: await convert(Buffer.from(
1189
1195
  await resp.arrayBuffer()
1190
1196
  ), { suffix: OGG_EXT, ...options || {} }),
1191
1197
  mimeType: MIME_OGG,
1192
- }, model: packModelLabel([provider, M.source, M.name]),
1198
+ }, model,
1193
1199
  };
1194
1200
  }
1195
1201
  } else if (M?.hearing) {
@@ -1245,8 +1251,7 @@ const initChat = async (options = {}) => {
1245
1251
  };
1246
1252
 
1247
1253
  const defaultSession = session => ({
1248
- messages: [], systemPrompt: chatConfig.systemPrompt,
1249
- threadId: null, ...session || {},
1254
+ messages: [], systemPrompt: chatConfig.systemPrompt, ...session || {},
1250
1255
  });
1251
1256
 
1252
1257
  const assertSessionId = sessionId => {
@@ -1347,8 +1352,8 @@ const stt = async (audio, options = {}) => await distillFile(
1347
1352
 
1348
1353
  const prompt = async (input, options = {}) => {
1349
1354
  const ai = await getAi(options?.aiId, options);
1350
- const tag = `${ai.provider} (${ai.model.name})`;
1351
- options.log && log(`Prompt ${tag}: ${JSON.stringify(input)}`);
1355
+ const tag = packModelLabel([ai.provider, ai.model.source, ai.model.name]);
1356
+ options.log && log(`Prompt ${tag}: ${JSON.stringify(input || '[ATTACHMENTS]')}`);
1352
1357
  const resp = await ai.prompt(input, options);
1353
1358
  options.log && log(`Response ${tag}: ${JSON.stringify(resp.text)}`);
1354
1359
  return resp;
package/lib/manifest.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const manifest = {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "2000.3.36",
4
+ "version": "2000.3.39",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/lib/utilitas.mjs CHANGED
@@ -218,6 +218,22 @@ const ensureDate = (dt, options) => {
218
218
  return dt;
219
219
  };
220
220
 
221
+ const uptime = () => {
222
+ let resp = `${getTimeIcon(new Date())} ${new Date().toTimeString(
223
+ ).split(' ')[0].split(':').slice(0, 2).join(':')} up`;
224
+ let seconds = process.uptime();
225
+ const days = Math.floor(seconds / (3600 * 24));
226
+ seconds -= days * 3600 * 24;
227
+ let hours = Math.floor(seconds / 3600);
228
+ seconds -= hours * 3600;
229
+ hours = hours.toString().padStart(2, '0');
230
+ let minutes = Math.floor(seconds / 60);
231
+ minutes = minutes.toString().padStart(2, '0');
232
+ seconds = Math.floor(seconds % 60).toString().padStart(2, '0');
233
+ days > 0 && (resp += ` ${days} day${days > 1 ? 's' : ''},`);
234
+ return `${resp} ${hours}:${minutes}:${seconds}`;
235
+ };
236
+
221
237
  const getRandomIndexInArray = (array, options) => {
222
238
  const count = ~~options?.count;
223
239
  const result = randomArray([...array.keys()]).slice(0, count || 1);
@@ -936,6 +952,7 @@ export {
936
952
  verifyPhone,
937
953
  verifyUrl,
938
954
  verifyUuid,
955
+ uptime,
939
956
  voidFunc,
940
957
  which
941
958
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "2000.3.36",
4
+ "version": "2000.3.39",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",