utilitas 1998.2.47 → 1998.2.49

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
@@ -1,7 +1,7 @@
1
1
  import { fileTypeFromBuffer } from 'file-type';
2
2
  import { end, loop } from './event.mjs';
3
3
  import { createWavHeader } from './media.mjs';
4
- import { search } from './shot.mjs';
4
+ import { checkSearch, search } from './shot.mjs';
5
5
  import { BASE64, BUFFER, DATAURL, MIME_BINARY, STREAM, convert } from './storage.mjs';
6
6
  import { create as createUoid } from './uoid.mjs';
7
7
  import { distill } from './web.mjs';
@@ -468,10 +468,21 @@ const tools = [
468
468
  },
469
469
  func: async args => await search(args?.keyword),
470
470
  showReq: true,
471
+ depend: checkSearch,
471
472
  },
472
473
  ];
473
474
 
474
- const toolsClaude = tools.map(x => ({
475
+ const toolsOpenAI = async () => {
476
+ const _tools = [];
477
+ for (const t of tools) {
478
+ (t.depend ? await t.depend() : true) ? _tools.push(t) : log(
479
+ `Tool is not ready: ${t.def.function.name}`
480
+ );
481
+ }
482
+ return _tools;
483
+ };
484
+
485
+ const toolsClaude = async () => (await toolsOpenAI()).map(x => ({
475
486
  ...x, def: {
476
487
  name: x.def.function.name,
477
488
  description: x.def.function.description,
@@ -479,7 +490,7 @@ const toolsClaude = tools.map(x => ({
479
490
  }
480
491
  }));
481
492
 
482
- const toolsGemini = tools.map(x => ({
493
+ const toolsGemini = async () => (await toolsOpenAI()).map(x => ({
483
494
  ...x, def: {
484
495
  name: x.def.function.name,
485
496
  description: x.def.function.description,
@@ -971,7 +982,7 @@ const promptChatGPT = async (content, options = {}) => {
971
982
  modalities?.find?.(x => x === AUDIO)
972
983
  && { voice: DEFAULT_MODELS[OPENAI_VOICE], format: 'pcm16' }
973
984
  ), ...history, ..._MODEL?.tools ? {
974
- tools: options.tools ?? tools.map(x => x.def),
985
+ tools: options.tools ?? (await toolsOpenAI()).map(x => x.def),
975
986
  } : {}, ...options.jsonMode ? {
976
987
  response_format: { type: JSON_OBJECT }
977
988
  } : {}, model: options.model, stream: true,
@@ -1056,7 +1067,7 @@ const promptClaude = async (content, options = {}) => {
1056
1067
  system, stream: true, ...options.reasoning ?? _MODEL?.reasoning ? {
1057
1068
  thinking: options.thinking || { type: 'enabled', budget_tokens: 1024 },
1058
1069
  } : {}, ..._MODEL?.tools ? { // https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking
1059
- tools: options.tools ?? toolsClaude.map(x => x.def),
1070
+ tools: options.tools ?? (await toolsClaude()).map(x => x.def),
1060
1071
  tool_choice: { type: 'auto' },
1061
1072
  betas: ['token-efficient-tools-2025-02-19'],
1062
1073
  // @todo: https://docs.anthropic.com/en/docs/build-with-claude/tool-use/token-efficient-tool-use
@@ -1168,7 +1179,7 @@ const promptGemini = async (content, options = {}) => {
1168
1179
  // https://ai.google.dev/gemini-api/docs/function-calling
1169
1180
  // { codeExecution: {} },
1170
1181
  // { googleSearch: {} },
1171
- { functionDeclarations: toolsGemini.map(x => x.def) },
1182
+ { functionDeclarations: (await toolsGemini()).map(x => x.def) },
1172
1183
  ],
1173
1184
  toolConfig: { functionCallingConfig: { mode: 'AUTO' } },
1174
1185
  }
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": "1998.2.47",
4
+ "version": "1998.2.49",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/lib/shot.mjs CHANGED
@@ -19,8 +19,9 @@ const buf2utf = buf => buf.toString('utf8');
19
19
  const [_JSON, _PARSED] = ['JSON', 'PARSED'];
20
20
  const getJson = async (u, o) => await get(u, { encode: _JSON, ...o || {} });
21
21
  const getParsedHtml = async (u, o) => await get(u, { encode: _PARSED, ...o || {} });
22
+ const checkSearch = () => googleApiKey && googleCx;
22
23
 
23
- let searchProvider, googleApiKey, googleCx;
24
+ let googleApiKey, googleCx;
24
25
 
25
26
  const defFetchOpt = {
26
27
  redirect: 'follow', follow: 3, timeout: 1000 * 10, headers: {
@@ -153,11 +154,9 @@ const get = async (url, options) => {
153
154
 
154
155
  const initSearch = (options) => {
155
156
  assert(
156
- options?.provider && options?.apiKey && options?.cx,
157
- 'Invalid search options.'
157
+ options?.apiKey && options?.cx, 'Invalid search options.'
158
158
  );
159
- return [searchProvider, googleApiKey, googleCx]
160
- = [options.provider, options.apiKey, options.cx];
159
+ return [googleApiKey, googleCx] = [options.apiKey, options.cx];
161
160
  };
162
161
 
163
162
  const search = async (query, options) => {
@@ -187,10 +186,9 @@ const search = async (query, options) => {
187
186
 
188
187
  export default get;
189
188
  export {
190
- checkVersion,
189
+ checkSearch, checkVersion,
191
190
  get,
192
- getCurrentIp,
193
- getCurrentPosition,
191
+ getCurrentIp, getCurrentPosition,
194
192
  getJson,
195
193
  getParsedHtml,
196
194
  getVersionOnNpm, initSearch, search
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": "1998.2.47",
4
+ "version": "1998.2.49",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",