@mccaskie-labs/workbench-ai 0.2.0 → 0.2.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @mccaskie-labs/workbench-ai
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - `WORKBENCH_GATEWAY_URL` must be an https URL (or http to localhost while developing), since the project key goes in every request's headers. A placeholder or other non-URL fails at start-up with `invalid_config`. Email: a `--wb-email-*` value mapped to the project's own `:root` variable (`var(--accent)`, or `var(--x, fallback)`) is filled in, and anything still holding `var()` is left out so the default stays, because mail apps don't support custom properties. `--wb-email-*` values are now taken only from plain `:root` rules, so a theme rule can't override every email.
8
+
3
9
  ## 0.2.0
4
10
 
5
11
  ### Minor Changes
package/dist/ai.js CHANGED
@@ -37,7 +37,7 @@ export function createAi(opts) {
37
37
  if (typeof opts.url !== "string" || opts.url === "") {
38
38
  throw new WorkbenchAiError("invalid_config", "WORKBENCH_GATEWAY_URL is missing");
39
39
  }
40
- const url = opts.url.replace(/\/+$/, "");
40
+ const url = gatewayBase(opts.url, (m) => new WorkbenchAiError("invalid_config", m));
41
41
  const baseFetch = opts.fetch ?? ((input, init) => globalThis.fetch(input, init));
42
42
  const client = (f) => new Anthropic({
43
43
  apiKey: opts.key,
@@ -359,3 +359,20 @@ function budgetFrom(body, requestId) {
359
359
  month: typeof b.month === "string" ? b.month : "",
360
360
  };
361
361
  }
362
+ /**
363
+ * The Gateway's address, checked: the project key goes in every request's
364
+ * headers, so only https, or http to this computer while developing.
365
+ */
366
+ function gatewayBase(raw, fail) {
367
+ let u;
368
+ try {
369
+ u = new URL(raw);
370
+ }
371
+ catch {
372
+ throw fail("WORKBENCH_GATEWAY_URL isn't a URL");
373
+ }
374
+ const local = u.hostname === "localhost" || u.hostname === "127.0.0.1" || u.hostname === "[::1]";
375
+ if (u.protocol !== "https:" && !(u.protocol === "http:" && local))
376
+ throw fail("WORKBENCH_GATEWAY_URL must be an https URL");
377
+ return raw.replace(/\/+$/, "");
378
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mccaskie-labs/workbench-ai",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Claude through the Workbench Gateway: text, structured output, streaming and budget status, with no Anthropic key in the app. Refusals and truncations throw; createFakeAi for tests.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",