@isdk/ai-tool 0.0.3 → 0.0.4

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.
Files changed (67) hide show
  1. package/dist/{chunk-DGMU4VSJ.mjs → chunk-ZXBTGYVX.mjs} +104 -127
  2. package/dist/funcs.js +103 -126
  3. package/dist/funcs.mjs +2 -2
  4. package/dist/index.js +103 -126
  5. package/dist/index.mjs +2 -2
  6. package/dist/test/util.js +1 -2
  7. package/dist/test/util.mjs +2 -3
  8. package/docs/classes/AbortError.md +11 -11
  9. package/docs/classes/AlreadyExistsError.md +11 -11
  10. package/docs/classes/BaseError.md +11 -11
  11. package/docs/classes/ClientTools.md +51 -51
  12. package/docs/classes/CommonError.md +11 -11
  13. package/docs/classes/EventClient.md +73 -73
  14. package/docs/classes/EventServer.md +71 -71
  15. package/docs/classes/EventToolFunc.md +41 -41
  16. package/docs/classes/FStringPromptTemplate.md +18 -18
  17. package/docs/classes/FewShotPromptTemplate.md +22 -22
  18. package/docs/classes/GolangPromptTemplate.md +18 -18
  19. package/docs/classes/HFEnvironment.md +9 -9
  20. package/docs/classes/HFInterpreter.md +17 -17
  21. package/docs/classes/HFTemplate.md +4 -4
  22. package/docs/classes/HfPromptTemplate.md +18 -18
  23. package/docs/classes/NotFoundError.md +11 -11
  24. package/docs/classes/NotImplementationError.md +11 -11
  25. package/docs/classes/PromptExampleSelector.md +8 -8
  26. package/docs/classes/PromptTemplate.md +17 -17
  27. package/docs/classes/ReadableStreamError.md +11 -11
  28. package/docs/classes/ResClientTools.md +57 -57
  29. package/docs/classes/ResServerTools.md +55 -55
  30. package/docs/classes/SSEChannel.md +15 -15
  31. package/docs/classes/ServerTools.md +48 -48
  32. package/docs/classes/ToolFunc.md +38 -38
  33. package/docs/enums/ErrorCode.md +19 -19
  34. package/docs/enums/XXHashAlgorithm.md +2 -2
  35. package/docs/interfaces/AIChatAssistantMessageParam.md +6 -6
  36. package/docs/interfaces/AIChatContentPartImage.md +2 -2
  37. package/docs/interfaces/AIChatContentPartText.md +2 -2
  38. package/docs/interfaces/AIChatMessageParamBase.md +1 -1
  39. package/docs/interfaces/AIChatMessageToolCall.md +3 -3
  40. package/docs/interfaces/AIChatSystemMessageParam.md +3 -3
  41. package/docs/interfaces/AIChatToolMessageParam.md +4 -4
  42. package/docs/interfaces/AIChatUserMessageParam.md +7 -7
  43. package/docs/interfaces/AIResult.md +4 -4
  44. package/docs/interfaces/AIStreamCallbacksAndOptions.md +6 -6
  45. package/docs/interfaces/AIStreamParser.md +1 -1
  46. package/docs/interfaces/AIStreamParserOptions.md +1 -1
  47. package/docs/interfaces/BaseFunc.md +7 -7
  48. package/docs/interfaces/BaseFuncItem.md +6 -6
  49. package/docs/interfaces/ClientFuncItem.md +10 -10
  50. package/docs/interfaces/DotenvExpandOptions.md +3 -3
  51. package/docs/interfaces/DotenvExpandOutput.md +2 -2
  52. package/docs/interfaces/EventClientFuncParams.md +4 -4
  53. package/docs/interfaces/EventServerFuncParams.md +5 -5
  54. package/docs/interfaces/FewShotPromptTemplateOptions.md +11 -11
  55. package/docs/interfaces/FuncItem.md +7 -7
  56. package/docs/interfaces/FuncParam.md +5 -5
  57. package/docs/interfaces/PromptExampleSelectorOptions.md +2 -2
  58. package/docs/interfaces/PromptTemplateOptions.md +6 -6
  59. package/docs/interfaces/RemoteFuncItem.md +10 -10
  60. package/docs/interfaces/ResClientFuncParams.md +2 -2
  61. package/docs/interfaces/ResServerFuncParams.md +5 -5
  62. package/docs/interfaces/SanitizeFilenameOptions.md +2 -2
  63. package/docs/interfaces/ServerFuncItem.md +11 -11
  64. package/docs/interfaces/ServerFuncParams.md +2 -2
  65. package/docs/modules.md +110 -110
  66. package/package.json +12 -13
  67. /package/dist/{chunk-EZFPVSGF.mjs → chunk-U5DDQYSF.mjs} +0 -0
package/dist/funcs.js CHANGED
@@ -392,8 +392,7 @@ var ToolFunc = class _ToolFunc extends import_property_manager.AdvancePropertyMa
392
392
  runSync(params) {
393
393
  const isPosParams = this.params && Array.isArray(this.params);
394
394
  if (Array.isArray(params)) {
395
- if (isPosParams)
396
- return this.func(...params);
395
+ if (isPosParams) return this.func(...params);
397
396
  throwError2("the function is not support array params, the params must be object!", this.name);
398
397
  }
399
398
  if (isPosParams) {
@@ -601,22 +600,19 @@ var SSEChannel = class {
601
600
  * @throws Will throw an error if the channel is closed.
602
601
  */
603
602
  publish(data, eventName) {
604
- if (!this.active)
605
- throwError2("Channel closed", "SSEChannel", SSEChannelAlreadyClosedErrCode);
603
+ if (!this.active) throwError2("Channel closed", "SSEChannel", SSEChannelAlreadyClosedErrCode);
606
604
  let output;
607
605
  let id;
608
606
  let _eventName = eventName;
609
607
  if (!data && !eventName) {
610
- if (!this.clients.size)
611
- return;
608
+ if (!this.clients.size) return;
612
609
  output = "data: \n\n";
613
610
  } else {
614
611
  id = this.nextID++;
615
612
  if (typeof data === "object") {
616
613
  if (data.event) {
617
614
  _eventName = data.event;
618
- if (data.data !== void 0)
619
- data = JSON.stringify(data.data);
615
+ if (data.data !== void 0) data = JSON.stringify(data.data);
620
616
  } else {
621
617
  data = JSON.stringify(data);
622
618
  }
@@ -643,8 +639,7 @@ var SSEChannel = class {
643
639
  * @throws Will throw an error if the channel is closed.
644
640
  */
645
641
  subscribe(req, res, events) {
646
- if (!this.active)
647
- throwError2("Channel closed", "SSEChannel", SSEChannelAlreadyClosedErrCode);
642
+ if (!this.active) throwError2("Channel closed", "SSEChannel", SSEChannelAlreadyClosedErrCode);
648
643
  const c = { req, res, events };
649
644
  const maxStreamDuration = this.options.maxStreamDuration;
650
645
  let cacheControl = "max-age=0, stale-while-revalidate=0, stale-if-error=0, no-transform";
@@ -805,8 +800,7 @@ var import_transformers = require("@xenova/transformers");
805
800
  var import_secondary_cache = require("secondary-cache");
806
801
  function _lrucache({ key, value, options } = {}) {
807
802
  if (key === void 0) {
808
- if (options)
809
- this.cache.setDefaultOptions(options);
803
+ if (options) this.cache.setDefaultOptions(options);
810
804
  } else if (value === null) {
811
805
  return this.cache.del(key);
812
806
  } else if (value !== void 0) {
@@ -1059,8 +1053,7 @@ async function _splitSegments({ texts, model } = {}) {
1059
1053
  }
1060
1054
  }
1061
1055
  }
1062
- if (segment.length)
1063
- segments2.push([...segment]);
1056
+ if (segment.length) segments2.push([...segment]);
1064
1057
  return segments2;
1065
1058
  }
1066
1059
  var splitSegments = new ServerTools("splitSegments", {
@@ -1668,8 +1661,7 @@ function tokenize(source, options = {}) {
1668
1661
  while (predicate(src[cursorPosition])) {
1669
1662
  if (src[cursorPosition] === "\\") {
1670
1663
  ++cursorPosition;
1671
- if (cursorPosition >= src.length)
1672
- throw new SyntaxError("Unexpected end of input");
1664
+ if (cursorPosition >= src.length) throw new SyntaxError("Unexpected end of input");
1673
1665
  const escaped = src[cursorPosition++];
1674
1666
  const unescaped = ESCAPE_CHARACTERS.get(escaped);
1675
1667
  if (unescaped === void 0) {
@@ -1679,83 +1671,81 @@ function tokenize(source, options = {}) {
1679
1671
  continue;
1680
1672
  }
1681
1673
  str += src[cursorPosition++];
1682
- if (cursorPosition >= src.length)
1683
- throw new SyntaxError("Unexpected end of input");
1674
+ if (cursorPosition >= src.length) throw new SyntaxError("Unexpected end of input");
1684
1675
  }
1685
1676
  return str;
1686
1677
  };
1687
- main:
1688
- while (cursorPosition < src.length) {
1689
- const lastTokenType = tokens.at(-1)?.type;
1690
- if (lastTokenType === void 0 || lastTokenType === TOKEN_TYPES.CloseStatement || lastTokenType === TOKEN_TYPES.CloseExpression) {
1691
- let text = "";
1692
- while (cursorPosition < src.length && // Keep going until we hit the next Jinja statement or expression
1693
- !(src[cursorPosition] === "{" && (src[cursorPosition + 1] === "%" || src[cursorPosition + 1] === "{"))) {
1694
- text += src[cursorPosition++];
1695
- }
1696
- if (text.length > 0) {
1697
- tokens.push(new Token(text, TOKEN_TYPES.Text));
1698
- continue;
1699
- }
1700
- }
1701
- consumeWhile((char2) => /\s/.test(char2));
1702
- const char = src[cursorPosition];
1703
- if (char === "-" || char === "+") {
1704
- const lastTokenType2 = tokens.at(-1)?.type;
1705
- if (lastTokenType2 === TOKEN_TYPES.Text || lastTokenType2 === void 0) {
1706
- throw new SyntaxError(`Unexpected character: ${char}`);
1707
- }
1708
- switch (lastTokenType2) {
1709
- case TOKEN_TYPES.Identifier:
1710
- case TOKEN_TYPES.NumericLiteral:
1711
- case TOKEN_TYPES.BooleanLiteral:
1712
- case TOKEN_TYPES.StringLiteral:
1713
- case TOKEN_TYPES.CloseParen:
1714
- case TOKEN_TYPES.CloseSquareBracket:
1715
- break;
1716
- default: {
1717
- ++cursorPosition;
1718
- const num = consumeWhile(isInteger);
1719
- tokens.push(
1720
- new Token(`${char}${num}`, num.length > 0 ? TOKEN_TYPES.NumericLiteral : TOKEN_TYPES.UnaryOperator)
1721
- );
1722
- continue;
1723
- }
1724
- }
1678
+ main: while (cursorPosition < src.length) {
1679
+ const lastTokenType = tokens.at(-1)?.type;
1680
+ if (lastTokenType === void 0 || lastTokenType === TOKEN_TYPES.CloseStatement || lastTokenType === TOKEN_TYPES.CloseExpression) {
1681
+ let text = "";
1682
+ while (cursorPosition < src.length && // Keep going until we hit the next Jinja statement or expression
1683
+ !(src[cursorPosition] === "{" && (src[cursorPosition + 1] === "%" || src[cursorPosition + 1] === "{"))) {
1684
+ text += src[cursorPosition++];
1685
+ }
1686
+ if (text.length > 0) {
1687
+ tokens.push(new Token(text, TOKEN_TYPES.Text));
1688
+ continue;
1725
1689
  }
1726
- for (const [char2, token] of ORDERED_MAPPING_TABLE) {
1727
- const slice2 = src.slice(cursorPosition, cursorPosition + char2.length);
1728
- if (slice2 === char2) {
1729
- tokens.push(new Token(char2, token));
1730
- cursorPosition += char2.length;
1731
- continue main;
1690
+ }
1691
+ consumeWhile((char2) => /\s/.test(char2));
1692
+ const char = src[cursorPosition];
1693
+ if (char === "-" || char === "+") {
1694
+ const lastTokenType2 = tokens.at(-1)?.type;
1695
+ if (lastTokenType2 === TOKEN_TYPES.Text || lastTokenType2 === void 0) {
1696
+ throw new SyntaxError(`Unexpected character: ${char}`);
1697
+ }
1698
+ switch (lastTokenType2) {
1699
+ case TOKEN_TYPES.Identifier:
1700
+ case TOKEN_TYPES.NumericLiteral:
1701
+ case TOKEN_TYPES.BooleanLiteral:
1702
+ case TOKEN_TYPES.StringLiteral:
1703
+ case TOKEN_TYPES.CloseParen:
1704
+ case TOKEN_TYPES.CloseSquareBracket:
1705
+ break;
1706
+ default: {
1707
+ ++cursorPosition;
1708
+ const num = consumeWhile(isInteger);
1709
+ tokens.push(
1710
+ new Token(`${char}${num}`, num.length > 0 ? TOKEN_TYPES.NumericLiteral : TOKEN_TYPES.UnaryOperator)
1711
+ );
1712
+ continue;
1732
1713
  }
1733
1714
  }
1734
- if (char === "'" || char === '"') {
1735
- ++cursorPosition;
1736
- const str = consumeWhile((c) => c !== char);
1737
- tokens.push(new Token(str, TOKEN_TYPES.StringLiteral));
1738
- ++cursorPosition;
1739
- continue;
1740
- }
1741
- if (isInteger(char)) {
1742
- const num = consumeWhile(isInteger);
1743
- tokens.push(new Token(num, TOKEN_TYPES.NumericLiteral));
1744
- continue;
1715
+ }
1716
+ for (const [char2, token] of ORDERED_MAPPING_TABLE) {
1717
+ const slice2 = src.slice(cursorPosition, cursorPosition + char2.length);
1718
+ if (slice2 === char2) {
1719
+ tokens.push(new Token(char2, token));
1720
+ cursorPosition += char2.length;
1721
+ continue main;
1745
1722
  }
1746
- if (isWord(char)) {
1747
- const word = consumeWhile(isWord);
1748
- const type = Object.hasOwn(KEYWORDS, word) ? KEYWORDS[word] : TOKEN_TYPES.Identifier;
1749
- if (type === TOKEN_TYPES.In && tokens.at(-1)?.type === TOKEN_TYPES.Not) {
1750
- tokens.pop();
1751
- tokens.push(new Token("not in", TOKEN_TYPES.NotIn));
1752
- } else {
1753
- tokens.push(new Token(word, type));
1754
- }
1755
- continue;
1723
+ }
1724
+ if (char === "'" || char === '"') {
1725
+ ++cursorPosition;
1726
+ const str = consumeWhile((c) => c !== char);
1727
+ tokens.push(new Token(str, TOKEN_TYPES.StringLiteral));
1728
+ ++cursorPosition;
1729
+ continue;
1730
+ }
1731
+ if (isInteger(char)) {
1732
+ const num = consumeWhile(isInteger);
1733
+ tokens.push(new Token(num, TOKEN_TYPES.NumericLiteral));
1734
+ continue;
1735
+ }
1736
+ if (isWord(char)) {
1737
+ const word = consumeWhile(isWord);
1738
+ const type = Object.hasOwn(KEYWORDS, word) ? KEYWORDS[word] : TOKEN_TYPES.Identifier;
1739
+ if (type === TOKEN_TYPES.In && tokens.at(-1)?.type === TOKEN_TYPES.Not) {
1740
+ tokens.pop();
1741
+ tokens.push(new Token("not in", TOKEN_TYPES.NotIn));
1742
+ } else {
1743
+ tokens.push(new Token(word, type));
1756
1744
  }
1757
- throw new SyntaxError(`Unexpected character: ${char}`);
1745
+ continue;
1758
1746
  }
1747
+ throw new SyntaxError(`Unexpected character: ${char}`);
1748
+ }
1759
1749
  return tokens;
1760
1750
  }
1761
1751
 
@@ -3051,8 +3041,7 @@ var Interpreter = class {
3051
3041
  return new StringValue(result);
3052
3042
  }
3053
3043
  evaluate(statement, environment) {
3054
- if (statement === void 0)
3055
- return new UndefinedValue();
3044
+ if (statement === void 0) return new UndefinedValue();
3056
3045
  switch (statement.type) {
3057
3046
  case "Program":
3058
3047
  return this.evalProgram(statement, environment);
@@ -3869,8 +3858,7 @@ function createEventStreamTransformer(customParser) {
3869
3858
  const parsedMessage = customParser ? customParser(event2.data, {
3870
3859
  event: event2.event
3871
3860
  }) : event2.data;
3872
- if (parsedMessage)
3873
- controller.enqueue(parsedMessage);
3861
+ if (parsedMessage) controller.enqueue(parsedMessage);
3874
3862
  }
3875
3863
  }
3876
3864
  );
@@ -3886,15 +3874,13 @@ function createCallbacksTransformer(cb) {
3886
3874
  const callbacks = cb || {};
3887
3875
  return new TransformStream({
3888
3876
  async start() {
3889
- if (callbacks.onStart)
3890
- await callbacks.onStart();
3877
+ if (callbacks.onStart) await callbacks.onStart();
3891
3878
  },
3892
3879
  async transform(message, controller) {
3893
3880
  const content = typeof message === "string" ? message : message.content;
3894
3881
  controller.enqueue(textEncoder.encode(content));
3895
3882
  aggregatedResponse += content;
3896
- if (callbacks.onToken)
3897
- await callbacks.onToken(content);
3883
+ if (callbacks.onToken) await callbacks.onToken(content);
3898
3884
  if (callbacks.onText && typeof message === "string") {
3899
3885
  await callbacks.onText(message);
3900
3886
  }
@@ -3914,8 +3900,7 @@ function trimStartOfStreamHelper() {
3914
3900
  return (text) => {
3915
3901
  if (isStreamStart) {
3916
3902
  text = text.trimStart();
3917
- if (text)
3918
- isStreamStart = false;
3903
+ if (text) isStreamStart = false;
3919
3904
  }
3920
3905
  return text;
3921
3906
  };
@@ -3942,10 +3927,8 @@ function readableFromAsyncIterable(iterable) {
3942
3927
  return new ReadableStream({
3943
3928
  async pull(controller) {
3944
3929
  const { done, value } = await it.next();
3945
- if (done)
3946
- controller.close();
3947
- else
3948
- controller.enqueue(value);
3930
+ if (done) controller.close();
3931
+ else controller.enqueue(value);
3949
3932
  },
3950
3933
  async cancel(reason) {
3951
3934
  await it.return?.(reason);
@@ -4018,8 +4001,7 @@ var XXHashAlgorithm = /* @__PURE__ */ ((XXHashAlgorithm2) => {
4018
4001
  return XXHashAlgorithm2;
4019
4002
  })(XXHashAlgorithm || {});
4020
4003
  function xxhash(value, hashAlgo = 111 /* xxhash64 */, seed = SEED) {
4021
- if (value.buffer)
4022
- value = value.buffer;
4004
+ if (value.buffer) value = value.buffer;
4023
4005
  let result;
4024
4006
  if (hashAlgo !== 112 /* xxhash32 */) {
4025
4007
  result = h64(value, seed);
@@ -4208,8 +4190,7 @@ function isObject(value) {
4208
4190
  return !!value && value.constructor === Object;
4209
4191
  }
4210
4192
  function getKeysPath(value) {
4211
- if (!value)
4212
- return [];
4193
+ if (!value) return [];
4213
4194
  return getKeys(value, [], "");
4214
4195
  }
4215
4196
  function getKeys(obj, paths, dot = ".") {
@@ -4431,27 +4412,26 @@ function jsonFilterToWhere(filter, wrapKey) {
4431
4412
  }
4432
4413
  if (Array.isArray(filter)) {
4433
4414
  andQuery.push(generateAndClause(filter, wrapKey));
4434
- } else
4435
- for (const [key, value] of Object.entries(filter)) {
4436
- if (key === "$and") {
4437
- andQuery.push(`(${generateAndClause(filter[key], wrapKey)})`);
4438
- } else if (key === "$or") {
4439
- andQuery.push(`(${generateOrClause(filter[key], wrapKey)})`);
4415
+ } else for (const [key, value] of Object.entries(filter)) {
4416
+ if (key === "$and") {
4417
+ andQuery.push(`(${generateAndClause(filter[key], wrapKey)})`);
4418
+ } else if (key === "$or") {
4419
+ andQuery.push(`(${generateOrClause(filter[key], wrapKey)})`);
4420
+ } else {
4421
+ const tValue = typeof value;
4422
+ if (value == null) {
4423
+ andQuery.push(`${wrapKey(key)} IS NULL`);
4424
+ } else if (tValue === "object" && !Array.isArray(value)) {
4425
+ andQuery.push(generateCondition(wrapKey(key), value));
4426
+ } else if (tValue === "string") {
4427
+ andQuery.push(`${wrapKey(key)}='${value}'`);
4428
+ } else if (tValue === "number" || tValue === "boolean") {
4429
+ andQuery.push(`${wrapKey(key)}=${value}`);
4440
4430
  } else {
4441
- const tValue = typeof value;
4442
- if (value == null) {
4443
- andQuery.push(`${wrapKey(key)} IS NULL`);
4444
- } else if (tValue === "object" && !Array.isArray(value)) {
4445
- andQuery.push(generateCondition(wrapKey(key), value));
4446
- } else if (tValue === "string") {
4447
- andQuery.push(`${wrapKey(key)}='${value}'`);
4448
- } else if (tValue === "number" || tValue === "boolean") {
4449
- andQuery.push(`${wrapKey(key)}=${value}`);
4450
- } else {
4451
- throw new Error(`Unsupported value type for key ${key}`);
4452
- }
4431
+ throw new Error(`Unsupported value type for key ${key}`);
4453
4432
  }
4454
4433
  }
4434
+ }
4455
4435
  ;
4456
4436
  return andQuery.length > 1 ? andQuery.join(" AND ") : andQuery[0];
4457
4437
  }
@@ -4479,8 +4459,7 @@ var ClientTools = class _ClientTools extends ToolFunc {
4479
4459
  "Content-Type": "application/json"
4480
4460
  } });
4481
4461
  const items = await res.json();
4482
- if (items)
4483
- this.loadFromSync(items);
4462
+ if (items) this.loadFromSync(items);
4484
4463
  } else {
4485
4464
  throwError2("missing apiRoot to load tools", "ClientTools");
4486
4465
  }
@@ -4786,8 +4765,7 @@ var EventClient = class extends ResClientTools {
4786
4765
  for (const event2 of events) {
4787
4766
  if (!this._forwardEvents.has(event2)) {
4788
4767
  this._forwardEvents.add(event2);
4789
- if (this.on)
4790
- this.on(event2, this.ebListener);
4768
+ if (this.on) this.on(event2, this.ebListener);
4791
4769
  }
4792
4770
  }
4793
4771
  }
@@ -4806,8 +4784,7 @@ var EventClient = class extends ResClientTools {
4806
4784
  for (const event2 of events) {
4807
4785
  if (this._forwardEvents.has(event2)) {
4808
4786
  this._forwardEvents.delete(event2);
4809
- if (this.off)
4810
- this.off(event2, this.ebListener);
4787
+ if (this.off) this.off(event2, this.ebListener);
4811
4788
  }
4812
4789
  }
4813
4790
  }
package/dist/funcs.mjs CHANGED
@@ -15,8 +15,8 @@ import {
15
15
  segments,
16
16
  similarity,
17
17
  splitSegments
18
- } from "./chunk-DGMU4VSJ.mjs";
19
- import "./chunk-EZFPVSGF.mjs";
18
+ } from "./chunk-ZXBTGYVX.mjs";
19
+ import "./chunk-U5DDQYSF.mjs";
20
20
  export {
21
21
  EventClient,
22
22
  EventServer,