@mccaskie-labs/workbench-ai 0.1.5 → 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 +17 -0
- package/README.md +2 -2
- package/dist/ai.js +22 -2
- package/dist/types.d.ts +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
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
|
+
|
|
9
|
+
## 0.2.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- Breaking: there is no built-in Gateway address any more (hard rule 13, `docs/install-plan.md`). `DEFAULT_GATEWAY_URL` is removed from workbench-config, `createAi` needs `url`, and `createMailer`'s gateway transport needs `gateway.url`. Pass the app's `WORKBENCH_GATEWAY_URL`, which Control writes into `wrangler.jsonc` when it creates a project. A missing address fails at start-up with `invalid_config` and the message "WORKBENCH_GATEWAY_URL is missing". The gateway manifest marks `WORKBENCH_GATEWAY_URL` required with no default.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
- @mccaskie-labs/workbench-config@0.2.0
|
|
19
|
+
|
|
3
20
|
## 0.1.5
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -10,14 +10,14 @@ npm install @mccaskie-labs/workbench-ai @mccaskie-labs/workbench-config zod
|
|
|
10
10
|
import { createAi } from '@mccaskie-labs/workbench-ai'
|
|
11
11
|
import { workbenchEnv } from '@mccaskie-labs/workbench-config'
|
|
12
12
|
|
|
13
|
-
const ai = createAi({ key: env.WORKBENCH_GATEWAY_KEY, env: workbenchEnv(env) })
|
|
13
|
+
const ai = createAi({ key: env.WORKBENCH_GATEWAY_KEY, env: workbenchEnv(env), url: env.WORKBENCH_GATEWAY_URL })
|
|
14
14
|
const r = await ai.text({ model: 'claude-default', job: 'article.write', prompt })
|
|
15
15
|
await save({ text: r.text, model: r.model, requestId: r.requestId })
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
| Export | What it does |
|
|
19
19
|
| --- | --- |
|
|
20
|
-
| `createAi({ key, env, url
|
|
20
|
+
| `createAi({ key, env, url, fetch? })` | The client. `url` is this install's Gateway address (`WORKBENCH_GATEWAY_URL`); there is no built-in one. Throws `invalid_config` at once if it is missing or the key isn't for `env` (`wbk_dev_`, `wbk_stg_`, `wbk_prd_`) |
|
|
21
21
|
| `ai.text(req)` | One reply as text. Throws `refused` on a refusal and `truncated` on `max_tokens`; never returns partial text |
|
|
22
22
|
| `ai.structured({ ...req, schema, mayLack? })` | JSON matching a zod schema, through structured outputs (`output_config.format`, not forced tool use). Asks once more for required fields left empty, except those in `mayLack`; throws `invalid_output` if they're still empty |
|
|
23
23
|
| `ai.stream(req)` | Async iterable of Anthropic stream events, then `finalMessage()`, which throws like `text` |
|
package/dist/ai.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Anthropic from "@anthropic-ai/sdk";
|
|
2
2
|
import { zodOutputFormat } from "@anthropic-ai/sdk/helpers/zod";
|
|
3
|
-
import { DEFAULT_GATEWAY_URL } from "@mccaskie-labs/workbench-config";
|
|
4
3
|
import { createCapture, isGatewayMeta, REQUEST_ID_HEADER } from "./capture.js";
|
|
5
4
|
import { errorFromGateway, WorkbenchAiError } from "./errors.js";
|
|
6
5
|
import { gatewayFetch } from "./http.js";
|
|
@@ -34,7 +33,11 @@ export function createAi(opts) {
|
|
|
34
33
|
if (!opts.key.startsWith(prefix)) {
|
|
35
34
|
throw new WorkbenchAiError("invalid_config", `WORKBENCH_GATEWAY_KEY is not a ${env} key (expected the ${prefix} prefix)`);
|
|
36
35
|
}
|
|
37
|
-
|
|
36
|
+
// No built-in address: each Workbench install has its own Gateway (hard rule 13).
|
|
37
|
+
if (typeof opts.url !== "string" || opts.url === "") {
|
|
38
|
+
throw new WorkbenchAiError("invalid_config", "WORKBENCH_GATEWAY_URL is missing");
|
|
39
|
+
}
|
|
40
|
+
const url = gatewayBase(opts.url, (m) => new WorkbenchAiError("invalid_config", m));
|
|
38
41
|
const baseFetch = opts.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
39
42
|
const client = (f) => new Anthropic({
|
|
40
43
|
apiKey: opts.key,
|
|
@@ -356,3 +359,20 @@ function budgetFrom(body, requestId) {
|
|
|
356
359
|
month: typeof b.month === "string" ? b.month : "",
|
|
357
360
|
};
|
|
358
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/dist/types.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ export interface AiOptions {
|
|
|
10
10
|
key: string;
|
|
11
11
|
/** From `workbenchEnv(env)`. Must match the key's environment. */
|
|
12
12
|
env: WorkbenchEnv;
|
|
13
|
-
/**
|
|
14
|
-
url
|
|
13
|
+
/** This install's Gateway address (`WORKBENCH_GATEWAY_URL`). There is no built-in one. */
|
|
14
|
+
url: string;
|
|
15
15
|
fetch?: typeof fetch;
|
|
16
16
|
}
|
|
17
17
|
export interface TextRequest {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mccaskie-labs/workbench-ai",
|
|
3
|
-
"version": "0.1
|
|
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",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@anthropic-ai/sdk": "^1.5.0",
|
|
39
|
-
"@mccaskie-labs/workbench-config": "^0.
|
|
39
|
+
"@mccaskie-labs/workbench-config": "^0.2.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"zod": "^4.1.0"
|