smoltalk 0.5.1 → 0.7.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.
- package/README.md +67 -10
- package/dist/classes/message/UserMessage.d.ts +66 -5
- package/dist/classes/message/UserMessage.js +100 -21
- package/dist/classes/message/contentParts.d.ts +259 -0
- package/dist/classes/message/contentParts.js +44 -0
- package/dist/classes/message/index.d.ts +8 -2
- package/dist/classes/message/index.js +12 -0
- package/dist/classes/message/renderers/AnthropicRenderer.d.ts +43 -0
- package/dist/classes/message/renderers/AnthropicRenderer.js +19 -0
- package/dist/classes/message/renderers/GoogleRenderer.d.ts +35 -0
- package/dist/classes/message/renderers/GoogleRenderer.js +26 -0
- package/dist/classes/message/renderers/JSONRenderer.d.ts +8 -0
- package/dist/classes/message/renderers/JSONRenderer.js +21 -0
- package/dist/classes/message/renderers/OpenAIChatRenderer.d.ts +30 -0
- package/dist/classes/message/renderers/OpenAIChatRenderer.js +20 -0
- package/dist/classes/message/renderers/OpenAIResponsesRenderer.d.ts +39 -0
- package/dist/classes/message/renderers/OpenAIResponsesRenderer.js +23 -0
- package/dist/classes/message/renderers/PartRenderer.d.ts +14 -0
- package/dist/classes/message/renderers/PartRenderer.js +16 -0
- package/dist/client.d.ts +4 -0
- package/dist/client.js +37 -16
- package/dist/clients/anthropic.d.ts +24 -2
- package/dist/clients/anthropic.js +9 -4
- package/dist/clients/baseClient.d.ts +7 -0
- package/dist/clients/baseClient.js +39 -0
- package/dist/clients/deepinfra.d.ts +17 -0
- package/dist/clients/deepinfra.js +27 -0
- package/dist/clients/google.js +6 -4
- package/dist/clients/litellm.d.ts +19 -0
- package/dist/clients/litellm.js +32 -0
- package/dist/clients/ollama.js +12 -9
- package/dist/clients/openai.d.ts +41 -5
- package/dist/clients/openai.js +78 -14
- package/dist/clients/openaiCompat.d.ts +22 -0
- package/dist/clients/openaiCompat.js +33 -0
- package/dist/clients/openaiResponses.js +6 -4
- package/dist/clients/openrouter.d.ts +23 -0
- package/dist/clients/openrouter.js +76 -0
- package/dist/clients/resolveAttachments.d.ts +11 -0
- package/dist/clients/resolveAttachments.js +108 -0
- package/dist/embed/openai.d.ts +7 -1
- package/dist/embed/openai.js +8 -2
- package/dist/embed.d.ts +18 -4
- package/dist/embed.js +32 -4
- package/dist/files/BaseFileProvider.d.ts +29 -0
- package/dist/files/BaseFileProvider.js +38 -0
- package/dist/files/anthropic.d.ts +16 -0
- package/dist/files/anthropic.js +20 -0
- package/dist/files/google.d.ts +18 -0
- package/dist/files/google.js +38 -0
- package/dist/files/openai.d.ts +16 -0
- package/dist/files/openai.js +23 -0
- package/dist/files.d.ts +46 -0
- package/dist/files.js +70 -0
- package/dist/image/openaiCompat.d.ts +9 -0
- package/dist/image/openaiCompat.js +60 -0
- package/dist/image.d.ts +13 -2
- package/dist/image.js +28 -3
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/models.d.ts +22 -3
- package/dist/models.js +46 -3
- package/dist/statelogClient.js +2 -1
- package/dist/types.d.ts +28 -18
- package/dist/types.js +1 -4
- package/dist/util/attachments.d.ts +34 -0
- package/dist/util/attachments.js +62 -0
- package/dist/util/hostedTools.js +5 -1
- package/dist/util/imageRef.d.ts +16 -1
- package/dist/util/imageRef.js +95 -10
- package/dist/util/modalities.d.ts +2 -0
- package/dist/util/modalities.js +31 -0
- package/dist/util/provider.d.ts +32 -6
- package/dist/util/provider.js +38 -4
- package/dist/util/redact.d.ts +8 -0
- package/dist/util/redact.js +42 -0
- package/package.json +1 -1
package/dist/util/provider.d.ts
CHANGED
|
@@ -5,14 +5,40 @@ import type { ModelDataBlob } from "../modelData.js";
|
|
|
5
5
|
* Otherwise looks up the model in the registry.
|
|
6
6
|
*/
|
|
7
7
|
export declare function resolveProvider(modelName: string, explicitProvider?: string, modelData?: ModelDataBlob): string;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Minimal shape needed to read API keys / base URLs. Kept local to avoid
|
|
10
|
+
* importing SmolConfig (which would create a circular import).
|
|
11
|
+
*/
|
|
12
|
+
type NestedKeyConfig = {
|
|
13
|
+
apiKey?: {
|
|
14
|
+
openAi?: string;
|
|
15
|
+
google?: string;
|
|
16
|
+
anthropic?: string;
|
|
17
|
+
ollama?: string;
|
|
18
|
+
openRouter?: string;
|
|
19
|
+
deepInfra?: string;
|
|
20
|
+
liteLlm?: string;
|
|
21
|
+
openAiCompat?: string;
|
|
22
|
+
};
|
|
23
|
+
baseUrl?: {
|
|
24
|
+
ollama?: string;
|
|
25
|
+
openRouter?: string;
|
|
26
|
+
deepInfra?: string;
|
|
27
|
+
liteLlm?: string;
|
|
28
|
+
openAiCompat?: string;
|
|
29
|
+
};
|
|
13
30
|
};
|
|
14
31
|
/**
|
|
15
32
|
* Resolve the API key for a provider, checking config then env vars.
|
|
16
33
|
*/
|
|
17
|
-
export declare function resolveApiKey(provider: string, config:
|
|
34
|
+
export declare function resolveApiKey(provider: string, config: NestedKeyConfig): string | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Resolve the base URL for a provider, checking config then env vars then a
|
|
37
|
+
* baked-in default. Returns `undefined` when a provider requires the caller to
|
|
38
|
+
* supply one (litellm, openai-compat) and nothing was given.
|
|
39
|
+
*
|
|
40
|
+
* Centralized here so we don't duplicate the env-fallback table across
|
|
41
|
+
* embed.ts, image.ts, and each client constructor.
|
|
42
|
+
*/
|
|
43
|
+
export declare function resolveBaseUrl(provider: string, config: NestedKeyConfig): string | undefined;
|
|
18
44
|
export {};
|
package/dist/util/provider.js
CHANGED
|
@@ -18,16 +18,50 @@ export function resolveProvider(modelName, explicitProvider, modelData) {
|
|
|
18
18
|
* Resolve the API key for a provider, checking config then env vars.
|
|
19
19
|
*/
|
|
20
20
|
export function resolveApiKey(provider, config) {
|
|
21
|
+
const k = config.apiKey;
|
|
21
22
|
switch (provider) {
|
|
22
23
|
case "openai":
|
|
23
24
|
case "openai-responses":
|
|
24
|
-
return
|
|
25
|
+
return k?.openAi || process.env.OPENAI_API_KEY;
|
|
25
26
|
case "google":
|
|
26
|
-
return
|
|
27
|
+
return k?.google || process.env.GEMINI_API_KEY;
|
|
27
28
|
case "anthropic":
|
|
28
|
-
return
|
|
29
|
+
return k?.anthropic || process.env.ANTHROPIC_API_KEY;
|
|
29
30
|
case "ollama":
|
|
30
|
-
return
|
|
31
|
+
return k?.ollama;
|
|
32
|
+
case "openrouter":
|
|
33
|
+
return k?.openRouter || process.env.OPENROUTER_API_KEY;
|
|
34
|
+
case "deepinfra":
|
|
35
|
+
return k?.deepInfra || process.env.DEEPINFRA_API_KEY;
|
|
36
|
+
case "litellm":
|
|
37
|
+
return k?.liteLlm || process.env.LITELLM_API_KEY;
|
|
38
|
+
case "openai-compat":
|
|
39
|
+
return k?.openAiCompat || process.env.OPENAI_COMPAT_API_KEY;
|
|
40
|
+
default:
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Resolve the base URL for a provider, checking config then env vars then a
|
|
46
|
+
* baked-in default. Returns `undefined` when a provider requires the caller to
|
|
47
|
+
* supply one (litellm, openai-compat) and nothing was given.
|
|
48
|
+
*
|
|
49
|
+
* Centralized here so we don't duplicate the env-fallback table across
|
|
50
|
+
* embed.ts, image.ts, and each client constructor.
|
|
51
|
+
*/
|
|
52
|
+
export function resolveBaseUrl(provider, config) {
|
|
53
|
+
const b = config.baseUrl;
|
|
54
|
+
switch (provider) {
|
|
55
|
+
case "ollama":
|
|
56
|
+
return b?.ollama || process.env.OLLAMA_HOST;
|
|
57
|
+
case "openrouter":
|
|
58
|
+
return b?.openRouter || "https://openrouter.ai/api/v1";
|
|
59
|
+
case "deepinfra":
|
|
60
|
+
return b?.deepInfra || "https://api.deepinfra.com/v1/openai";
|
|
61
|
+
case "litellm":
|
|
62
|
+
return b?.liteLlm || process.env.LITELLM_BASE_URL;
|
|
63
|
+
case "openai-compat":
|
|
64
|
+
return b?.openAiCompat || process.env.OPENAI_COMPAT_BASE_URL;
|
|
31
65
|
default:
|
|
32
66
|
return undefined;
|
|
33
67
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep copy of `value` with attachment payloads (base64 / data URIs) replaced by
|
|
3
|
+
* a short summary, so logs and observability never carry large media blobs.
|
|
4
|
+
* Normal prose is left intact (only base64-shaped strings are summarized).
|
|
5
|
+
*/
|
|
6
|
+
export declare function redactAttachments(value: unknown): unknown;
|
|
7
|
+
/** Replace every occurrence of a secret (e.g. an API key) in text with a marker. */
|
|
8
|
+
export declare function redactSecret(text: string, secret?: string): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const MAX_STRING = 2048;
|
|
2
|
+
/**
|
|
3
|
+
* Deep copy of `value` with attachment payloads (base64 / data URIs) replaced by
|
|
4
|
+
* a short summary, so logs and observability never carry large media blobs.
|
|
5
|
+
* Normal prose is left intact (only base64-shaped strings are summarized).
|
|
6
|
+
*/
|
|
7
|
+
export function redactAttachments(value) {
|
|
8
|
+
if (typeof value === "string") {
|
|
9
|
+
return redactString(value);
|
|
10
|
+
}
|
|
11
|
+
if (Array.isArray(value)) {
|
|
12
|
+
return value.map((v) => redactAttachments(v));
|
|
13
|
+
}
|
|
14
|
+
if (value && typeof value === "object") {
|
|
15
|
+
const out = {};
|
|
16
|
+
for (const [k, v] of Object.entries(value)) {
|
|
17
|
+
out[k] = redactAttachments(v);
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function redactString(s) {
|
|
24
|
+
const marker = ";base64,";
|
|
25
|
+
if (s.startsWith("data:") && s.includes(marker)) {
|
|
26
|
+
const prefix = s.slice(0, s.indexOf(marker) + marker.length);
|
|
27
|
+
return `${prefix}[redacted ${s.length} chars]`;
|
|
28
|
+
}
|
|
29
|
+
// A bare base64 payload is a single unbroken token. Requiring zero whitespace
|
|
30
|
+
// keeps prose (which has spaces) intact even when it's long and punctuation-free.
|
|
31
|
+
if (s.length > MAX_STRING && /^[A-Za-z0-9+/=]+$/.test(s)) {
|
|
32
|
+
return `[redacted ${s.length} base64 chars]`;
|
|
33
|
+
}
|
|
34
|
+
return s;
|
|
35
|
+
}
|
|
36
|
+
/** Replace every occurrence of a secret (e.g. an API key) in text with a marker. */
|
|
37
|
+
export function redactSecret(text, secret) {
|
|
38
|
+
if (!secret) {
|
|
39
|
+
return text;
|
|
40
|
+
}
|
|
41
|
+
return text.split(secret).join("[redacted]");
|
|
42
|
+
}
|