smoltalk 0.15.3 → 0.17.0

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 (54) hide show
  1. package/README.md +62 -0
  2. package/dist/clients/anthropic.js +3 -2
  3. package/dist/clients/baseClient.js +4 -3
  4. package/dist/clients/google.js +2 -1
  5. package/dist/clients/llamaCppLoader.js +2 -2
  6. package/dist/clients/mlx.d.ts +12 -1
  7. package/dist/clients/mlx.js +23 -0
  8. package/dist/clients/ollama.d.ts +1 -1
  9. package/dist/clients/ollama.js +1 -1
  10. package/dist/clients/openai.d.ts +2 -1
  11. package/dist/clients/openai.js +5 -3
  12. package/dist/clients/openaiResponses.js +3 -2
  13. package/dist/clients/resolveAttachments.js +2 -1
  14. package/dist/clients/structuredAfterTools.d.ts +36 -0
  15. package/dist/clients/structuredAfterTools.js +87 -0
  16. package/dist/clients/validationRetry.d.ts +5 -0
  17. package/dist/clients/validationRetry.js +24 -0
  18. package/dist/embed/openai.js +3 -2
  19. package/dist/files/anthropic.js +2 -2
  20. package/dist/files/openai.js +2 -2
  21. package/dist/image/google.js +3 -2
  22. package/dist/image/openai.js +3 -2
  23. package/dist/image/openaiCompat.js +3 -2
  24. package/dist/index.d.ts +1 -0
  25. package/dist/index.js +2 -0
  26. package/dist/modelRefresh.js +10 -11
  27. package/dist/models.d.ts +298 -56
  28. package/dist/models.js +331 -66
  29. package/dist/platform.browser.d.ts +5 -0
  30. package/dist/platform.browser.js +13 -0
  31. package/dist/platform.d.ts +33 -0
  32. package/dist/platform.js +13 -0
  33. package/dist/platform.node.d.ts +5 -0
  34. package/dist/platform.node.js +17 -0
  35. package/dist/speech/google.js +2 -1
  36. package/dist/speech/groq.js +1 -0
  37. package/dist/speech/mlx.js +1 -0
  38. package/dist/speech/openai.js +1 -1
  39. package/dist/speech/openaiCompat.js +1 -1
  40. package/dist/statelogClient.js +2 -1
  41. package/dist/transcription/google.js +3 -2
  42. package/dist/transcription/groq.js +1 -0
  43. package/dist/transcription/openai.js +1 -1
  44. package/dist/transcription/openaiCompat.js +1 -1
  45. package/dist/types.d.ts +6 -0
  46. package/dist/util/attachments.js +2 -1
  47. package/dist/util/base64.d.ts +17 -0
  48. package/dist/util/base64.js +59 -0
  49. package/dist/util/blobRef.js +18 -12
  50. package/dist/util/fileExtension.d.ts +7 -0
  51. package/dist/util/fileExtension.js +15 -0
  52. package/dist/util/provider.d.ts +1 -0
  53. package/dist/util/provider.js +16 -14
  54. package/package.json +14 -2
@@ -2,19 +2,19 @@
2
2
  * Fetching refreshed model data from a remote or on-disk catalog.
3
3
  *
4
4
  * Split out of modelData.ts so that module — and therefore models.ts, and
5
- * therefore the model registry — carries no Node dependency. Everything here
6
- * needs a Node runtime (node:fs, Buffer, process.env); everything in
7
- * modelData.ts is pure and bundles for the browser.
5
+ * therefore the model registry — stays pure. This file reaches the platform
6
+ * through #platform: a `file:` URL works on Node and throws in a browser,
7
+ * and `https:` works on both.
8
8
  */
9
- import { readFile } from "node:fs/promises";
10
- import { fileURLToPath } from "node:url";
9
+ import { env, readTextFromFileUrl } from "#platform";
10
+ import { utf8ByteLength } from "./util/base64.js";
11
11
  import { parseModelDataBlob } from "./modelData.js";
12
12
  import { failure } from "./types/result.js";
13
13
  export const DEFAULT_MODEL_DATA_URL = "https://raw.githubusercontent.com/egonSchiele/smoltalk/main/packages/smoltalk/data/model-data.json";
14
14
  const MAX_BYTES = 10_000_000;
15
15
  const TIMEOUT_MS = 15_000;
16
16
  function enforceSizeCap(text) {
17
- if (Buffer.byteLength(text, "utf8") > MAX_BYTES) {
17
+ if (utf8ByteLength(text) > MAX_BYTES) {
18
18
  throw new Error(`Model data exceeds the ${MAX_BYTES}-byte cap`);
19
19
  }
20
20
  return text;
@@ -24,9 +24,7 @@ function enforceSizeCap(text) {
24
24
  // integration test). Any other scheme is rejected.
25
25
  async function defaultFetcher(url, signal) {
26
26
  if (url.startsWith("file://")) {
27
- const path = fileURLToPath(url);
28
- const text = await readFile(path, "utf8");
29
- return enforceSizeCap(text);
27
+ return enforceSizeCap(await readTextFromFileUrl(url));
30
28
  }
31
29
  if (url.startsWith("https://")) {
32
30
  const res = await fetch(url, { signal });
@@ -39,8 +37,9 @@ async function defaultFetcher(url, signal) {
39
37
  }
40
38
  export async function refreshModels(opts = {}) {
41
39
  let url = DEFAULT_MODEL_DATA_URL;
42
- if (process.env.SMOLTALK_MODEL_DATA_URL) {
43
- url = process.env.SMOLTALK_MODEL_DATA_URL;
40
+ const fromEnv = env("SMOLTALK_MODEL_DATA_URL");
41
+ if (fromEnv) {
42
+ url = fromEnv;
44
43
  }
45
44
  if (opts.url) {
46
45
  url = opts.url;