smoltalk 0.15.2 → 0.15.3

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 CHANGED
@@ -615,12 +615,12 @@ const r = await decide(
615
615
  );
616
616
  ```
617
617
 
618
- `provider: "typesafe"` is required for any model name the registry does not
619
- know. It says "this endpoint speaks the decision protocol".
618
+ For a Laya model name the registry does not know, set `provider: "typesafe"`
619
+ to select its decision protocol.
620
620
 
621
621
  OpenRouter and Vercel AI Gateway also serve Jev over this protocol, so no
622
- TypeSafe account is needed. OpenRouter's model name, `jev-1.13`, is in the
623
- registry:
622
+ TypeSafe account is needed. To use OpenRouter, set `provider: "openrouter"`
623
+ and provide `OPENROUTER_API_KEY` or `config.apiKey.openRouter`:
624
624
 
625
625
  ```typescript
626
626
  import { decide } from "smoltalk";
@@ -630,12 +630,17 @@ const r = await decide(
630
630
  { refund: { type: "noul", instructions: "Is the customer asking for money back?" } },
631
631
  {
632
632
  model: "jev-1.13",
633
- apiKey: { typesafe: process.env.OPENROUTER_API_KEY },
634
- baseUrl: { typesafe: "https://openrouter.ai/api" },
633
+ provider: "openrouter",
634
+ apiKey: { openRouter: process.env.OPENROUTER_API_KEY },
635
635
  },
636
636
  );
637
637
  ```
638
638
 
639
+ OpenRouter requests go to `https://openrouter.ai/api/v1/systemone`. Set
640
+ `baseUrl.openRouter` to override the API base URL, including its version
641
+ path; `decide()` appends `/systemone`. Without an explicit provider,
642
+ `jev-1.13` still defaults to TypeSafe.
643
+
639
644
  Vercel's base URL is `https://ai-gateway.vercel.sh/typesafe` and its model
640
645
  name is `typesafe-ai/jev`, which needs `provider: "typesafe"`.
641
646
 
package/dist/decide.d.ts CHANGED
@@ -53,15 +53,18 @@ export type DecideConfig = {
53
53
  model: string;
54
54
  /** Required when the model is not in the registry. */
55
55
  provider?: string;
56
- /** API keys, nested by provider. Falls back to TYPESAFE_API_KEY. */
56
+ /** API keys, nested by provider. Falls back to TYPESAFE_API_KEY or OPENROUTER_API_KEY. */
57
57
  apiKey?: {
58
58
  typesafe?: string;
59
+ openRouter?: string;
59
60
  [provider: string]: string | undefined;
60
61
  };
61
- /** Custom base URLs, nested by provider. Falls back to TYPESAFE_BASE_URL,
62
- * then TypeSafe's host. Point `typesafe` at a Laya server to use Laya. */
62
+ /** Custom base URLs, nested by provider. TypeSafe falls back to TYPESAFE_BASE_URL,
63
+ * then its host. OpenRouter defaults to https://openrouter.ai/api/v1.
64
+ * Point `typesafe` at a Laya server to use Laya. */
63
65
  baseUrl?: {
64
66
  typesafe?: string;
67
+ openRouter?: string;
65
68
  [provider: string]: string | undefined;
66
69
  };
67
70
  /** Refreshed model data to layer over the baked-in registry. */
package/dist/decide.js CHANGED
@@ -9,8 +9,8 @@
9
9
  *
10
10
  * `decide()` follows the shape of `embed()`: payload first, config last,
11
11
  * provider and key and base URL resolved through the shared helpers. There
12
- * is one provider, `typesafe`, which is the wire protocol. A Laya server
13
- * speaks the same protocol, so it is reached by setting `baseUrl.typesafe`.
12
+ * are two providers: `typesafe` and `openrouter`. A Laya server speaks the
13
+ * TypeSafe protocol, so it is reached by setting `baseUrl.typesafe`.
14
14
  */
15
15
  import { z } from "zod";
16
16
  import { success, failure } from "./types/result.js";
@@ -151,8 +151,8 @@ export async function decide(state, questions, config) {
151
151
  catch (err) {
152
152
  return failure(errorMessage(err));
153
153
  }
154
- if (provider !== DECISION_PROVIDER) {
155
- return failure(`Provider "${provider}" does not answer decisions. Only "${DECISION_PROVIDER}" does; set config.provider to it for a model the registry does not know.`);
154
+ if (provider !== DECISION_PROVIDER && provider !== "openrouter") {
155
+ return failure(`Provider "${provider}" does not answer decisions. Use "${DECISION_PROVIDER}" or "openrouter"; set config.provider for a model the registry does not know.`);
156
156
  }
157
157
  // The registry entry for the requested name, when there is one. It sets
158
158
  // the question cap and the price. A Laya model has no entry and no price.
@@ -164,15 +164,18 @@ export async function decide(state, questions, config) {
164
164
  }
165
165
  const apiKey = resolveApiKey(provider, config);
166
166
  if (!apiKey) {
167
- return failure("No TypeSafe API key provided. Set config.apiKey.typesafe or the TYPESAFE_API_KEY environment variable.");
167
+ return failure(provider === "openrouter"
168
+ ? "No OpenRouter API key provided. Set config.apiKey.openRouter or the OPENROUTER_API_KEY environment variable."
169
+ : "No TypeSafe API key provided. Set config.apiKey.typesafe or the TYPESAFE_API_KEY environment variable.");
168
170
  }
169
171
  const baseUrl = resolveBaseUrl(provider, config).replace(/\/+$/, "");
172
+ const endpoint = provider === "openrouter" ? `${baseUrl}/systemone` : `${baseUrl}/v1/systemone`;
170
173
  if (config.abortSignal?.aborted) {
171
174
  return failure("Request was aborted");
172
175
  }
173
176
  let response;
174
177
  try {
175
- response = await fetch(`${baseUrl}/v1/systemone`, {
178
+ response = await fetch(endpoint, {
176
179
  method: "POST",
177
180
  headers: {
178
181
  Authorization: `Bearer ${apiKey}`,
package/dist/models.js CHANGED
@@ -1975,7 +1975,15 @@ export const decisionModels = [
1975
1975
  type: "decision",
1976
1976
  modelName: "jev-1.13",
1977
1977
  provider: "typesafe",
1978
- description: "Jev 1.13, the name OpenRouter serves it under (baseUrl.typesafe = https://openrouter.ai/api). Same price and protocol as jev-latest.",
1978
+ description: "Jev 1.13 through the TypeSafe decision protocol. Same price and question limit as jev-latest.",
1979
+ inputTokenCost: 0.042,
1980
+ maxQuestions: 64,
1981
+ },
1982
+ {
1983
+ type: "decision",
1984
+ modelName: "jev-1.13",
1985
+ provider: "openrouter",
1986
+ description: "Jev 1.13 through OpenRouter. Answers yes/no, choice, and score questions with calibrated probabilities.",
1979
1987
  inputTokenCost: 0.042,
1980
1988
  maxQuestions: 64,
1981
1989
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smoltalk",
3
- "version": "0.15.2",
3
+ "version": "0.15.3",
4
4
  "description": "A common interface for LLM APIs",
5
5
  "homepage": "https://github.com/egonSchiele/smoltalk",
6
6
  "files": [