utilitas 1999.1.72 → 1999.1.73

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
@@ -911,13 +911,10 @@ const handleToolsCall = async (msg, options) => {
911
911
  toolsResponse = (toolsResponse + m).trim();
912
912
  await streamResp({ text: options?.delta ? m : toolsResponse }, options);
913
913
  };
914
- const calls = msg.tool_calls || msg.content || msg.parts || [];
914
+ const calls = msg.tool_calls || msg.content
915
+ || (msg.parts ? msg.parts.filter(x => x.functionCall) : null) || [];
915
916
  if (calls.length) {
916
- switch (options?.flavor) {
917
- case ANTHROPIC: preRes.push(msg); break;
918
- case GEMINI: preRes.push(msg); break;
919
- case OPENAI: default: preRes.push(msg); break;
920
- }
917
+ preRes.push(msg);
921
918
  for (const fn of calls) {
922
919
  switch (options?.flavor) {
923
920
  case ANTHROPIC:
@@ -977,7 +974,7 @@ const handleToolsCall = async (msg, options) => {
977
974
  if (content.length) {
978
975
  switch (options?.flavor) {
979
976
  case ANTHROPIC: content = [{ role: user, content }]; break;
980
- case GEMINI: content = [{ role: FUNC, parts: content }]; break;
977
+ case GEMINI: content = [{ role: user, parts: content }]; break;
981
978
  }
982
979
  }
983
980
  responded && await resp(TOOLS_END);
@@ -1183,8 +1180,10 @@ const packGeminiReferences = (chunks, supports) => {
1183
1180
 
1184
1181
  const promptGemini = async (aiId, content, options = {}) => {
1185
1182
  let { provider, client, model } = await getAi(aiId);
1186
- let [event, result, references, functionCalls, responded, images] =
1187
- [null, options.result ?? '', null, [], false, []];
1183
+ let [
1184
+ event, result, text, thinking, references, functionCalls, responded,
1185
+ images, thinkEnd,
1186
+ ] = [null, options.result ?? '', '', '', null, [], false, [], false];
1188
1187
  options.model = options.model || model.name;
1189
1188
  model?.image === true && (options.imageMode = true);
1190
1189
  assert(!(options.imageMode && !model.image), 'Image mode is not supported.');
@@ -1198,12 +1197,11 @@ const promptGemini = async (aiId, content, options = {}) => {
1198
1197
  const chat = client.chats.create({
1199
1198
  model: options.model, history, config: {
1200
1199
  responseMimeType: options.jsonMode ? MIME_JSON : MIME_TEXT,
1200
+ thinkingConfig: model.reasoning ? { includeThoughts: true } : {},
1201
1201
  systemInstruction, responseModalities: options.modalities || (
1202
1202
  options.imageMode ? [TEXT, IMAGE] : undefined
1203
1203
  ), ...options?.config || {}, ...model?.tools && !options.jsonMode
1204
- // @todo: Gemini 2.5 flash 05-20 refusing to use certain tool calls
1205
- // https://discuss.ai.google.dev/t/gemini-2-5-flash-05-20-refusing-to-use-certain-tool-calls/84086
1206
- && ![GEMINI_20_FLASH, GEMINI_25_FLASH].includes(options.model)
1204
+ && ![GEMINI_20_FLASH].includes(options.model)
1207
1205
  ? (options.tools ?? {
1208
1206
  tools: [
1209
1207
  // @todo: Gemini will failed when using these tools together.
@@ -1228,15 +1226,23 @@ const promptGemini = async (aiId, content, options = {}) => {
1228
1226
  chunk?.promptFeedback?.blockReason
1229
1227
  );
1230
1228
  event = chunk?.candidates?.[0];
1231
- let [deltaText, deltaImages] = ['', []];
1229
+ let [deltaText, deltaThink, deltaImages] = ['', '', []];
1232
1230
  event?.content?.parts?.map(x => {
1233
- if (x.text) { deltaText = x.text; }
1231
+ if (x.text && x.thought) { deltaThink = x.text; }
1232
+ else if (x.text) { deltaText = x.text; }
1234
1233
  else if (x.functionCall) { functionCalls.push(x); }
1235
1234
  else if (x.inlineData?.mimeType === MIME_PNG) {
1236
1235
  deltaImages.push(x.inlineData);
1237
1236
  images.push(x.inlineData);
1238
1237
  }
1239
1238
  });
1239
+ text += deltaText;
1240
+ thinking += deltaThink;
1241
+ deltaThink && deltaThink === thinking
1242
+ && (deltaThink = `${THINK_STR}\n${deltaThink}`);
1243
+ thinking && deltaText && !thinkEnd
1244
+ && (thinkEnd = deltaThink = `${deltaThink}${THINK_END}\n\n`);
1245
+ deltaText = deltaThink + deltaText;
1240
1246
  const rfc = packGeminiReferences(
1241
1247
  event?.groundingMetadata?.groundingChunks,
1242
1248
  event?.groundingMetadata?.groundingSupports
@@ -1250,9 +1256,15 @@ const promptGemini = async (aiId, content, options = {}) => {
1250
1256
  images: options.delta ? deltaImages : images,
1251
1257
  }, options);
1252
1258
  }
1259
+ event = {
1260
+ role: MODEL, parts: [
1261
+ ...thinking ? [{ thought: true, text: thinking }] : [],
1262
+ ...text ? [{ text }] : [],
1263
+ ...functionCalls,
1264
+ ],
1265
+ };
1253
1266
  const { toolsResult, toolsResponse } = await handleToolsCall(
1254
- { role: MODEL, parts: functionCalls },
1255
- { ...options, result, flavor: GEMINI }
1267
+ event, { ...options, result, flavor: GEMINI }
1256
1268
  );
1257
1269
  if (toolsResult.length
1258
1270
  && countToolCalls(toolsResponse) < MAX_TOOL_RECURSION) {
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": "1999.1.72",
4
+ "version": "1999.1.73",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/lib/web.mjs CHANGED
@@ -198,7 +198,7 @@ const search = async (query, options = {}) => {
198
198
  return options?.raw ? resp.content : {
199
199
  totalResults: resp?.content?.searchInformation?.totalResults || 0,
200
200
  startIndex: resp?.content?.queries?.request?.[0]?.startIndex || 1,
201
- items: resp?.content?.items.map(x => ({
201
+ items: (resp?.content?.items || []).map(x => ({
202
202
  title: x.title, link: options?.image ? null : x.link,
203
203
  snippet: x.snippet, image: (
204
204
  options?.image ? x.link : x.pagemap?.cse_image?.[0]?.src
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": "1999.1.72",
4
+ "version": "1999.1.73",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",