smoltalk 0.9.0 → 0.10.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 (72) hide show
  1. package/README.md +141 -7
  2. package/dist/classes/message/AssistantMessage.d.ts +2 -0
  3. package/dist/classes/message/UserMessage.d.ts +21 -0
  4. package/dist/classes/message/UserMessage.js +3 -0
  5. package/dist/classes/message/contentParts.d.ts +71 -2
  6. package/dist/classes/message/contentParts.js +6 -0
  7. package/dist/classes/message/index.d.ts +5 -2
  8. package/dist/classes/message/index.js +7 -0
  9. package/dist/classes/message/renderers/AnthropicRenderer.d.ts +2 -1
  10. package/dist/classes/message/renderers/AnthropicRenderer.js +3 -0
  11. package/dist/classes/message/renderers/GoogleRenderer.d.ts +2 -1
  12. package/dist/classes/message/renderers/GoogleRenderer.js +3 -0
  13. package/dist/classes/message/renderers/JSONRenderer.d.ts +2 -1
  14. package/dist/classes/message/renderers/JSONRenderer.js +4 -0
  15. package/dist/classes/message/renderers/OpenAIChatRenderer.d.ts +8 -1
  16. package/dist/classes/message/renderers/OpenAIChatRenderer.js +18 -0
  17. package/dist/classes/message/renderers/OpenAIResponsesRenderer.d.ts +2 -1
  18. package/dist/classes/message/renderers/OpenAIResponsesRenderer.js +3 -0
  19. package/dist/classes/message/renderers/PartRenderer.d.ts +3 -2
  20. package/dist/classes/message/renderers/PartRenderer.js +3 -0
  21. package/dist/client.js +1 -0
  22. package/dist/clients/anthropic.js +1 -1
  23. package/dist/clients/baseClient.d.ts +13 -1
  24. package/dist/clients/baseClient.js +36 -7
  25. package/dist/clients/google.js +1 -1
  26. package/dist/clients/ollama.js +1 -1
  27. package/dist/clients/openai.d.ts +2 -1
  28. package/dist/clients/openai.js +15 -3
  29. package/dist/clients/openaiCompat.d.ts +2 -0
  30. package/dist/clients/openaiCompat.js +5 -0
  31. package/dist/clients/openaiResponses.js +1 -1
  32. package/dist/clients/resolveAttachments.d.ts +8 -4
  33. package/dist/clients/resolveAttachments.js +101 -50
  34. package/dist/embed.d.ts +4 -0
  35. package/dist/files.d.ts +1 -1
  36. package/dist/files.js +1 -1
  37. package/dist/image/google.js +2 -2
  38. package/dist/image/openai.js +3 -3
  39. package/dist/image.d.ts +1 -1
  40. package/dist/index.d.ts +10 -2
  41. package/dist/index.js +7 -1
  42. package/dist/model.d.ts +15 -4
  43. package/dist/model.js +48 -7
  44. package/dist/models.d.ts +143 -19
  45. package/dist/models.js +137 -30
  46. package/dist/speech/baseSpeechClient.d.ts +31 -0
  47. package/dist/speech/baseSpeechClient.js +98 -0
  48. package/dist/speech/openai.d.ts +6 -0
  49. package/dist/speech/openai.js +39 -0
  50. package/dist/speech.d.ts +40 -0
  51. package/dist/speech.js +57 -0
  52. package/dist/transcription/baseTranscriptionClient.d.ts +31 -0
  53. package/dist/transcription/baseTranscriptionClient.js +107 -0
  54. package/dist/transcription/openai.d.ts +6 -0
  55. package/dist/transcription/openai.js +59 -0
  56. package/dist/transcription.d.ts +51 -0
  57. package/dist/transcription.js +58 -0
  58. package/dist/types/tokenUsage.d.ts +4 -0
  59. package/dist/types/tokenUsage.js +4 -0
  60. package/dist/types.d.ts +3 -0
  61. package/dist/util/attachments.d.ts +1 -1
  62. package/dist/util/audioMime.d.ts +9 -0
  63. package/dist/util/audioMime.js +33 -0
  64. package/dist/util/{imageRef.d.ts → blobRef.d.ts} +9 -9
  65. package/dist/util/{imageRef.js → blobRef.js} +6 -13
  66. package/dist/util/mime.d.ts +21 -0
  67. package/dist/util/mime.js +52 -0
  68. package/dist/util/modalities.d.ts +6 -2
  69. package/dist/util/modalities.js +13 -15
  70. package/dist/util/provider.d.ts +2 -0
  71. package/dist/util/provider.js +1 -1
  72. package/package.json +1 -1
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Shared extension/MIME knowledge for attachments and audio. One table per
3
+ * format; every other ext↔MIME mapping in the package derives from these so
4
+ * the forward and inverse maps can't drift apart.
5
+ */
6
+ export type AudioFormat = {
7
+ /** Primary file extension, without the dot. */
8
+ extension: string;
9
+ /** Canonical MIME type. */
10
+ mimeType: string;
11
+ /** Other MIME strings that identify the same container. */
12
+ aliasMimeTypes: readonly string[];
13
+ /** Other extensions that map to this format. */
14
+ aliasExtensions: readonly string[];
15
+ };
16
+ export declare const AUDIO_FORMATS: readonly AudioFormat[];
17
+ /** Extension (with leading dot, lowercase) → MIME, across images, PDF, and audio. */
18
+ export declare const EXT_TO_MIME: Record<string, string>;
19
+ export declare function canonicalizeMime(mime: string): string;
20
+ /** The audio format a MIME string identifies, or null when unrecognized. */
21
+ export declare function audioFormatForMime(mime: string): AudioFormat | null;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Shared extension/MIME knowledge for attachments and audio. One table per
3
+ * format; every other ext↔MIME mapping in the package derives from these so
4
+ * the forward and inverse maps can't drift apart.
5
+ */
6
+ export const AUDIO_FORMATS = [
7
+ { extension: "mp3", mimeType: "audio/mpeg", aliasMimeTypes: ["audio/mp3"], aliasExtensions: ["mpeg", "mpga"] },
8
+ { extension: "wav", mimeType: "audio/wav", aliasMimeTypes: ["audio/x-wav"], aliasExtensions: [] },
9
+ { extension: "m4a", mimeType: "audio/m4a", aliasMimeTypes: ["audio/x-m4a"], aliasExtensions: [] },
10
+ { extension: "mp4", mimeType: "audio/mp4", aliasMimeTypes: ["video/mp4"], aliasExtensions: [] },
11
+ { extension: "ogg", mimeType: "audio/ogg", aliasMimeTypes: [], aliasExtensions: [] },
12
+ { extension: "flac", mimeType: "audio/flac", aliasMimeTypes: [], aliasExtensions: [] },
13
+ { extension: "webm", mimeType: "audio/webm", aliasMimeTypes: [], aliasExtensions: [] },
14
+ ];
15
+ const IMAGE_AND_DOCUMENT_EXT_TO_MIME = {
16
+ ".png": "image/png",
17
+ ".jpg": "image/jpeg",
18
+ ".jpeg": "image/jpeg",
19
+ ".webp": "image/webp",
20
+ ".gif": "image/gif",
21
+ ".pdf": "application/pdf",
22
+ };
23
+ function buildExtToMime() {
24
+ const table = { ...IMAGE_AND_DOCUMENT_EXT_TO_MIME };
25
+ for (const format of AUDIO_FORMATS) {
26
+ table[`.${format.extension}`] = format.mimeType;
27
+ for (const alias of format.aliasExtensions) {
28
+ table[`.${alias}`] = format.mimeType;
29
+ }
30
+ }
31
+ return table;
32
+ }
33
+ /** Extension (with leading dot, lowercase) → MIME, across images, PDF, and audio. */
34
+ export const EXT_TO_MIME = buildExtToMime();
35
+ // Strips parameters (e.g. ";codecs=opus") and normalizes case, so MediaRecorder-
36
+ // style MIME strings like "audio/webm;codecs=opus" or "AUDIO/MPEG" still match.
37
+ export function canonicalizeMime(mime) {
38
+ return mime.split(";")[0].trim().toLowerCase();
39
+ }
40
+ /** The audio format a MIME string identifies, or null when unrecognized. */
41
+ export function audioFormatForMime(mime) {
42
+ const canonical = canonicalizeMime(mime);
43
+ for (const format of AUDIO_FORMATS) {
44
+ if (format.mimeType === canonical) {
45
+ return format;
46
+ }
47
+ if (format.aliasMimeTypes.includes(canonical)) {
48
+ return format;
49
+ }
50
+ }
51
+ return null;
52
+ }
@@ -1,2 +1,6 @@
1
- import { PromptResult, Result, SmolConfig } from "../types.js";
2
- export declare function validateModalities(config: SmolConfig): Result<PromptResult> | null;
1
+ import { Message } from "../classes/message/index.js";
2
+ /** Modalities a model must positively declare in its data block — for these,
3
+ * "unknown" means "unsupported" (audio serialization is model-specific). */
4
+ export declare const MODALITIES_REQUIRING_DECLARATION: ReadonlySet<string>;
5
+ /** Which non-text input modalities the user messages actually use. */
6
+ export declare function neededInputModalities(messages: Message[]): string[];
@@ -1,10 +1,11 @@
1
1
  import { UserMessage } from "../classes/message/index.js";
2
- import { modelSupportsInputModality } from "../models.js";
3
- import { failure } from "../types.js";
4
- export function validateModalities(config) {
5
- let needsImage = false;
6
- let needsPdf = false;
7
- for (const msg of config.messages) {
2
+ /** Modalities a model must positively declare in its data block — for these,
3
+ * "unknown" means "unsupported" (audio serialization is model-specific). */
4
+ export const MODALITIES_REQUIRING_DECLARATION = new Set(["audio"]);
5
+ /** Which non-text input modalities the user messages actually use. */
6
+ export function neededInputModalities(messages) {
7
+ const needed = new Set();
8
+ for (const msg of messages) {
8
9
  if (!(msg instanceof UserMessage)) {
9
10
  continue;
10
11
  }
@@ -14,18 +15,15 @@ export function validateModalities(config) {
14
15
  }
15
16
  for (const part of parts) {
16
17
  if (part.type === "image") {
17
- needsImage = true;
18
+ needed.add("image");
18
19
  }
19
20
  if (part.type === "file") {
20
- needsPdf = true;
21
+ needed.add("pdf");
22
+ }
23
+ if (part.type === "audio") {
24
+ needed.add("audio");
21
25
  }
22
26
  }
23
27
  }
24
- if (needsImage && modelSupportsInputModality(config.model, "image", config.modelData) === false) {
25
- return failure(`Model ${config.model} does not support image input.`);
26
- }
27
- if (needsPdf && modelSupportsInputModality(config.model, "pdf", config.modelData) === false) {
28
- return failure(`Model ${config.model} does not support PDF/document input.`);
29
- }
30
- return null;
28
+ return [...needed];
31
29
  }
@@ -19,6 +19,8 @@ type NestedKeyConfig = {
19
19
  deepInfra?: string;
20
20
  liteLlm?: string;
21
21
  openAiCompat?: string;
22
+ /** Arbitrary provider names, for keys targeting a custom-registered provider. */
23
+ [provider: string]: string | undefined;
22
24
  };
23
25
  baseUrl?: {
24
26
  ollama?: string;
@@ -38,7 +38,7 @@ export function resolveApiKey(provider, config) {
38
38
  case "openai-compat":
39
39
  return k?.openAiCompat || process.env.OPENAI_COMPAT_API_KEY;
40
40
  default:
41
- return undefined;
41
+ return config.apiKey?.[provider];
42
42
  }
43
43
  }
44
44
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smoltalk",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "A common interface for LLM APIs",
5
5
  "homepage": "https://github.com/egonSchiele/smoltalk",
6
6
  "files": [