@rudra-js/anthropic 0.2.0 → 0.3.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/README.md CHANGED
@@ -21,15 +21,29 @@ const provider = createAnthropicProvider({ apiKey: process.env.ANTHROPIC_API_KEY
21
21
  const generator = createComponentGenerator({ provider });
22
22
  ```
23
23
 
24
- `model` defaults to `claude-opus-5`, the Claude model this package was written
25
- against; pass it to pin a different one. `maxTokens` and `baseUrl` are also
26
- optional.
24
+ `model` defaults to `claude-sonnet-5`, and `thinking` defaults to
25
+ `{ type: 'disabled' }`.
26
+
27
+ Both of those come from the same constraint. Generation runs on the request
28
+ path, inside `modelTimeoutMs`, which core defaults to 1500ms. A model that
29
+ reasons before it answers won't finish in time. Sonnet 5 reasons by default
30
+ when `thinking` is left out, so it's the leaving out that would break the
31
+ budget, not the choice of model.
32
+
33
+ Want a different model? Pass `model` to pin one, and raise `modelTimeoutMs` to
34
+ match while you're there. A quick heads-up on `thinking`: some models reject an
35
+ explicit `{ type: 'disabled' }` and reason whatever you do. Pass
36
+ `thinking: null` for those and we'll send no `thinking` field at all. Our
37
+ example shop pins `claude-opus-5` and gives `modelTimeoutMs` a full 60 seconds,
38
+ which is a demo talking, not a production setting.
39
+
40
+ `maxTokens` and `baseUrl` are optional too.
27
41
 
28
42
  ### An identity-linked key needs a workspace
29
43
 
30
- A key created against your identity rather than inside a workspace belongs to
31
- you across several of them, so the API cannot infer which one a request acts in
32
- and answers:
44
+ A key you made against your identity rather than inside a workspace belongs to
45
+ you across several of them. The API can't tell which one a request is acting in,
46
+ so it answers:
33
47
 
34
48
  ```
35
49
  400 invalid_request_error — anthropic-workspace-id is required when
@@ -45,38 +59,38 @@ createAnthropicProvider({
45
59
  });
46
60
  ```
47
61
 
48
- `fetch` is injectable, which is what the test suite uses in place of a network
49
- call.
62
+ `fetch` is injectable. That's how our test suite stands in for a network call.
50
63
 
51
- The tool schema sent to the model is derived from the `schema` on the
52
- `ProviderRequest` the same schema `@rudra-js/core` defines rather than a
53
- copy written out here. A second copy would be a second vocabulary: the
54
- reconciler would enforce one thing and the model would be told another.
64
+ The tool schema we send the model is derived from the `schema` on the
65
+ `ProviderRequest`, the same schema `@rudra-js/core` defines. We don't keep a
66
+ copy here. A second copy would be a second vocabulary, and then the reconciler
67
+ enforces one thing while the model is told another.
55
68
 
56
69
  ## Data handling
57
70
 
58
71
  Each generation is one POST to `https://api.anthropic.com/v1/messages`. Set
59
- `baseUrl` and it goes to that host instead a proxy, a gateway, or a
60
- region-specific endpoint you have.
72
+ `baseUrl` and it goes to that host instead, whether that's a proxy, a gateway,
73
+ or a region-specific endpoint you have.
61
74
 
62
- What is in that request is listed under **What the model sees** in the
75
+ What's in that request is listed under **What the model sees** in the
63
76
  [`@rudra-js/core` README](https://github.com/clivedsouza1010/rudra-js/tree/main/packages/core#what-the-model-sees).
64
77
  Read it before you send real shopper traffic. In cohort mode, the default, the
65
78
  request carries no individual. In per-shopper mode it carries that shopper's
66
79
  likes, dislikes, purchases, basket, views and recent searches.
67
80
 
68
- If your shop is in the EU or the UK, you are the one sending personal data to
69
- Anthropic, and you need a data processing agreement with them plus a transfer
70
- mechanism for the data leaving your region. Your shop is Anthropic's customer;
71
- this package is a piece of code in the middle and is not a party to anything.
72
-
73
- When the API answers with an error, the thrown `Error` carries the status code
74
- and the vendor's error category `anthropic responded 400
75
- (invalid_request_error)`. The vendor's own message is left out on purpose: it
76
- quotes the request back, and for this framework the request can hold a shopper's
77
- search terms, which an adopter's `console.error(error)` would then write to a
78
- log. A test in `anthropic-provider.test.ts` puts a search term in that message
79
- and asserts it does not reach the thrown error.
81
+ If your shop is in the EU or the UK, you're the one sending personal data to
82
+ Anthropic, so you'll need a data processing agreement with them plus a transfer
83
+ mechanism for the data leaving your region. Your shop is Anthropic's customer.
84
+ This package is a piece of code in the middle, and it _isn't_ a party to
85
+ anything.
86
+
87
+ When the API answers with an error, the `Error` we throw carries the status code
88
+ and the vendor's error category, like `anthropic responded 400
89
+ (invalid_request_error)`. We leave the vendor's own message out. It quotes the
90
+ request back, and for this framework the request can hold a shopper's search
91
+ terms, which an adopter's `console.error(error)` would then write to a log. A
92
+ test in `anthropic-provider.test.ts` puts a search term in that message and
93
+ asserts it does not reach the thrown error.
80
94
 
81
95
  ## Licence
82
96
 
@@ -11,6 +11,16 @@ export interface AnthropicProviderOptions {
11
11
  * infer which one a request acts in and rejects it with a 400.
12
12
  */
13
13
  workspaceId?: string;
14
+ /**
15
+ * Sent as the request's `thinking`. Defaults to `{ type: 'disabled' }`,
16
+ * because core budgets 1500ms for the whole call and a model that reasons
17
+ * before answering does not finish inside it. Pass `null` to send nothing,
18
+ * which is what a model that rejects an explicit `disabled` needs, and raise
19
+ * `modelTimeoutMs` to match when you do.
20
+ */
21
+ thinking?: {
22
+ type: 'adaptive' | 'disabled';
23
+ } | null;
14
24
  /** Injected so the adapter is testable without a network or an SDK. */
15
25
  fetch?: typeof globalThis.fetch;
16
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic-provider.d.ts","sourceRoot":"","sources":["../src/anthropic-provider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EAIlB,MAAM,gBAAgB,CAAC;AAExB,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uEAAuE;IACvE,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AA0CD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,wBAAwB,GAAG,iBAAiB,CA6H5F"}
1
+ {"version":3,"file":"anthropic-provider.d.ts","sourceRoot":"","sources":["../src/anthropic-provider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EAIlB,MAAM,gBAAgB,CAAC;AAExB,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE;QAAE,IAAI,EAAE,UAAU,GAAG,UAAU,CAAA;KAAE,GAAG,IAAI,CAAC;IACpD,uEAAuE;IACvE,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAyCD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,wBAAwB,GAAG,iBAAiB,CAgI5F"}
@@ -1,10 +1,9 @@
1
1
  import { z } from 'zod';
2
2
  const TOOL_NAME = 'emit_component_spec';
3
3
  /**
4
- * This model runs adaptive thinking by default, and thinking draws on the
5
- * same output budget as the tool call. A cap too close to what reasoning
6
- * alone can spend leaves no room for the tool block, so the default is well
7
- * above a typical spec's size rather than tuned to it.
4
+ * A model that reasons before answering draws on the same output budget as the
5
+ * tool call, and a cap close to what a spec needs leaves no room for it. The
6
+ * default is well above a typical spec's size rather than tuned to it.
8
7
  */
9
8
  const DEFAULT_MAX_TOKENS = 8192;
10
9
  function describeShape(input) {
@@ -37,7 +36,8 @@ function isToolUseBlock(candidate) {
37
36
  * and reach the generator as `provider-error` events.
38
37
  */
39
38
  export function createAnthropicProvider(options) {
40
- const model = options.model ?? 'claude-opus-5';
39
+ const model = options.model ?? 'claude-sonnet-5';
40
+ const thinking = options.thinking === undefined ? { type: 'disabled' } : options.thinking;
41
41
  const call = options.fetch ?? globalThis.fetch;
42
42
  // Trimmed so a caller-supplied `baseUrl` ending in `/` cannot turn into
43
43
  // `//v1/messages`. Done with a loop rather than `/\/+$/`: that pattern
@@ -71,6 +71,7 @@ export function createAnthropicProvider(options) {
71
71
  body: JSON.stringify({
72
72
  model,
73
73
  max_tokens: maxTokens,
74
+ ...(thinking ? { thinking } : {}),
74
75
  // Marked as the cached prefix. Anything per-shopper interpolated here
75
76
  // would destroy the prompt cache hit rate.
76
77
  system: [{ type: 'text', text: request.system, cache_control: { type: 'ephemeral' } }],
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic-provider.js","sourceRoot":"","sources":["../src/anthropic-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAwBxB,MAAM,SAAS,GAAG,qBAAqB,CAAC;AAExC;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAQhC,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,eAAe,KAAK,CAAC,MAAM,EAAE,CAAC;IAC/D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,OAAO,KAAK,CAAC,CAAC;IAE3D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,uBAAuB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAC1F,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC1F,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC,M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GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QACzB,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACvD,CAAC,CAAC;IAEF,MAAM,WAAW,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC;IAC7C,MAAM,YAAY,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC;IAC/C,MAAM,eAAe,GAAG,QAAQ,CAAC,yBAAyB,CAAC,CAAC;IAC5D,MAAM,gBAAgB,GAAG,QAAQ,CAAC,6BAA6B,CAAC,CAAC;IAEjE,MAAM,MAAM,GAAG;QACb,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;QACrD,GAAG,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC;QACvD,GAAG,CAAC,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC;QAC7D,GAAG,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC;KAChE,CAAC;IAEF,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7D,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rudra-js/anthropic",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "An Anthropic adapter for @rudra-js/core, with no vendor SDK and no dependencies",
5
5
  "keywords": [
6
6
  "anthropic",
@@ -47,11 +47,11 @@
47
47
  "access": "public"
48
48
  },
49
49
  "peerDependencies": {
50
- "@rudra-js/core": "^0.2.0",
50
+ "@rudra-js/core": "^0.3.1",
51
51
  "zod": "^4.5.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@rudra-js/core": "0.1.0",
54
+ "@rudra-js/core": "0.3.1",
55
55
  "zod": "^4.5.4"
56
56
  }
57
57
  }
@@ -18,6 +18,14 @@ export interface AnthropicProviderOptions {
18
18
  * infer which one a request acts in and rejects it with a 400.
19
19
  */
20
20
  workspaceId?: string;
21
+ /**
22
+ * Sent as the request's `thinking`. Defaults to `{ type: 'disabled' }`,
23
+ * because core budgets 1500ms for the whole call and a model that reasons
24
+ * before answering does not finish inside it. Pass `null` to send nothing,
25
+ * which is what a model that rejects an explicit `disabled` needs, and raise
26
+ * `modelTimeoutMs` to match when you do.
27
+ */
28
+ thinking?: { type: 'adaptive' | 'disabled' } | null;
21
29
  /** Injected so the adapter is testable without a network or an SDK. */
22
30
  fetch?: typeof globalThis.fetch;
23
31
  }
@@ -25,10 +33,9 @@ export interface AnthropicProviderOptions {
25
33
  const TOOL_NAME = 'emit_component_spec';
26
34
 
27
35
  /**
28
- * This model runs adaptive thinking by default, and thinking draws on the
29
- * same output budget as the tool call. A cap too close to what reasoning
30
- * alone can spend leaves no room for the tool block, so the default is well
31
- * above a typical spec's size rather than tuned to it.
36
+ * A model that reasons before answering draws on the same output budget as the
37
+ * tool call, and a cap close to what a spec needs leaves no room for it. The
38
+ * default is well above a typical spec's size rather than tuned to it.
32
39
  */
33
40
  const DEFAULT_MAX_TOKENS = 8192;
34
41
 
@@ -70,7 +77,9 @@ function isToolUseBlock(candidate: unknown): candidate is ToolUseBlock {
70
77
  * and reach the generator as `provider-error` events.
71
78
  */
72
79
  export function createAnthropicProvider(options: AnthropicProviderOptions): ComponentProvider {
73
- const model = options.model ?? 'claude-opus-5';
80
+ const model = options.model ?? 'claude-sonnet-5';
81
+ const thinking =
82
+ options.thinking === undefined ? { type: 'disabled' as const } : options.thinking;
74
83
  const call = options.fetch ?? globalThis.fetch;
75
84
  // Trimmed so a caller-supplied `baseUrl` ending in `/` cannot turn into
76
85
  // `//v1/messages`. Done with a loop rather than `/\/+$/`: that pattern
@@ -106,6 +115,7 @@ export function createAnthropicProvider(options: AnthropicProviderOptions): Comp
106
115
  body: JSON.stringify({
107
116
  model,
108
117
  max_tokens: maxTokens,
118
+ ...(thinking ? { thinking } : {}),
109
119
  // Marked as the cached prefix. Anything per-shopper interpolated here
110
120
  // would destroy the prompt cache hit rate.
111
121
  system: [{ type: 'text', text: request.system, cache_control: { type: 'ephemeral' } }],