@yaks/anthropic 0.0.0-stage → 0.2.36

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Jeff Peterson
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,115 @@
1
- # Temporary Holding Version
1
+ # @yaks/anthropic
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Anthropic's Messages API as an `@yaks/model` model, spoken over `fetch` with no
4
+ SDK, so a Worker that bundles it uploads only the few kilobytes it runs. Model
5
+ names are Anthropic's own: `claude-sonnet-5-5`, `claude-opus-5-5`,
6
+ `claude-haiku-5-5`.
7
+
8
+ ```ts ignore
9
+ import { messages } from '@yaks/anthropic'
10
+
11
+ let model = messages({ key: () => myPrivateKey })
12
+ let reply = await model({
13
+ model: 'claude-sonnet-5-5',
14
+ items: [{ kind: 'user', text: 'Hello' }],
15
+ tools: [],
16
+ })
17
+ ```
18
+
19
+ `key` is asked at the moment of each call, so a rotated key lands on the next
20
+ request. Take it from the vault (`reveal`), never from a graph row. The client
21
+ reads no credential and no base URL from the environment: `base` names another
22
+ root, `https://api.anthropic.com` by default.
23
+
24
+ ## What is sent and read
25
+
26
+ A request becomes one streamed `POST /v1/messages`:
27
+
28
+ - `Request.instructions` and the `instruction` items before the conversation are
29
+ the `system` prompt. An instruction later in the conversation is a text block
30
+ in the turn it falls in.
31
+ - Items become messages; consecutive items of one role share a message, so the
32
+ results of parallel calls answer together. A `call` is a `tool_use` block, a
33
+ `result` a `tool_result`, an `image` a base64 image block.
34
+ - Tools are sent in name order and the request carries top-level
35
+ `cache_control`, so each request reads the prefix the last one wrote. It is
36
+ kept five minutes, or an hour (`ttl: "1h"`, written at twice the input price
37
+ where five minutes cost 1.25 times) when `Request.cacheRetention` is 3600 or
38
+ more; the reply's `cacheExpiresAt` is the request's start plus that lifetime.
39
+ - `Request.tokens` is `max_tokens` (64,000 without it); `Request.effort`, when
40
+ it is one of `low`, `medium`, `high`, `xhigh`, `max`, is
41
+ `output_config.effort`. Thinking is left to the model's default.
42
+
43
+ - `web: true` (the provider's default, unless its options or `HARNESS_WEB=0`
44
+ turn it off) offers the API's own web search and page fetch after the tools:
45
+ `web_search_20260209` and `web_fetch_20260209`, which filter what they read
46
+ before it reaches the context, to the models that have them, and the plain
47
+ `web_search_20250305` and `web_fetch_20250910` to older ones. Each is used at
48
+ most four times a request and a fetched page is cut at 25,000 tokens, so the
49
+ model says the most a request can add (`hosted`: four searches, and 160,000
50
+ tokens read back, taking a search's results as 15,000, which the API does not
51
+ cut) for a meter to reserve. The API runs them within the request; nothing
52
+ comes back as a call.
53
+
54
+ Text deltas reach `onText` as they arrive. `onSubmit` runs before the POST and
55
+ `onAck` with `anthropic{response_id}` on the stream's first event. `signal`
56
+ stops the stream; the stop is thrown as the signal's reason, not a `ModelError`.
57
+ The reply's items are its text and `tool_use` blocks, in order. Text runs on as
58
+ one item across the blocks its citations split it into and the searches and
59
+ fetches between them, and each web page it cites is linked after the text citing
60
+ it, as `[title](<url>)`. Thinking blocks and the API's own tool blocks are not
61
+ kept, and the next request is sent without them, which the API accepts. A turn
62
+ the API paused (`pause_turn`) answers with what it said.
63
+
64
+ `usage` names input as Anthropic counts it plus what the cache read and wrote,
65
+ so `cached_tokens` and `cache_write_tokens` are parts of `input_tokens`, and the
66
+ searches it ran as `web_searches`, which a model's `web_search` price weighs (a
67
+ cent each at list price). A page fetch costs only the tokens it reads. The API
68
+ reports no dollars: a caller weighs usage at the model row's price.
69
+
70
+ ## Failures
71
+
72
+ Nothing is retried here; the caller retries, since a retry here could buy one
73
+ request twice. A rate limit, an overloaded or failing server, or a dropped
74
+ connection is a `ModelError` coded `busy`, with `retry.after` from
75
+ `Retry-After`; so is an `error` event mid-stream that names one, and a stream
76
+ that ends before its message does. A refused key is `key`, an unknown model
77
+ `model`, a spent credit balance `credit`, any other refused request `request`,
78
+ and a `refusal` stop `refusal`. A spent credit balance is never `limit`, the
79
+ code of a caller's own ceiling: the key's account running dry is a failure for
80
+ whoever holds the key. Typed questions and image or audio output are refused
81
+ before anything is sent.
82
+
83
+ ## Models and prices
84
+
85
+ `info(name)` reads the model from `/v1/models` for its context window and gives
86
+ the price `@yaks/model`'s `listPrice` has for the name (the API publishes none);
87
+ `list()` does the same for every model the key can use. `mark(reply, cache)`
88
+ writes `anthropic{response_id, cache_expires_at}`, the expiry being the
89
+ request's start plus the documented five minutes. `anthropicDoc` declares the
90
+ component.
91
+
92
+ ## Batches
93
+
94
+ `@yaks/anthropic/batches` is `@yaks/model/batch`'s `Batches` over Anthropic's
95
+ Message Batches: many Messages requests sent as one, answered within a day at
96
+ half the price. `submit` sends them and answers the batch's id; `ended` says
97
+ whether it has finished; `results` reads every answer, in any order, each found
98
+ by the `id` it was asked with. Each request's system text is marked with
99
+ `cache_control`, so a prefix every request shares is written to the cache once
100
+ and read by the requests after it. `entryOf` and `answerOf` turn one request and
101
+ one result between the neutral shapes and the API's.
102
+
103
+ ```ts ignore
104
+ import { batches } from '@yaks/anthropic/batches'
105
+
106
+ let api = batches({ key: () => myPrivateKey })
107
+ let id = await api.submit([{
108
+ id: 'a',
109
+ model: 'claude-opus-5-5',
110
+ system: shared,
111
+ text: 'Write to Ada.',
112
+ max: 16_000,
113
+ }])
114
+ if (await api.ended(id)) await api.results(id)
115
+ ```
@@ -0,0 +1,77 @@
1
+ import type { Answered, Asked, Batches } from "@yaks/model/batch";
2
+ import { type Wire } from "./wire.js";
3
+ /** One request of a batch as the API takes it: a Messages request's body,
4
+ * named so its result can be found again. */ export type Entry = {
5
+ custom_id: string;
6
+ params: Record<string, unknown>;
7
+ };
8
+ /** One request's result as the API gives it: its message, or why there is
9
+ * none. */ export type Result = {
10
+ custom_id: string;
11
+ result: {
12
+ type: 'succeeded';
13
+ message: {
14
+ content: {
15
+ type: string;
16
+ text?: string;
17
+ }[];
18
+ usage: {
19
+ input_tokens: number;
20
+ output_tokens: number;
21
+ cache_read_input_tokens?: number | null;
22
+ cache_creation_input_tokens?: number | null;
23
+ };
24
+ };
25
+ } | {
26
+ type: 'errored' | 'canceled' | 'expired';
27
+ error?: unknown;
28
+ };
29
+ };
30
+ /** A request as a Messages request's body, its system text cached. */ export declare let entryOf: (a: Asked) => Entry;
31
+ /**
32
+ * A result as an answer: its text and usage, counted as @yaks/model counts
33
+ * them (input includes what the cache read and wrote).
34
+ *
35
+ * ```ts
36
+ * import { answerOf } from '@yaks/anthropic/batches'
37
+ * import { assertEquals } from '@std/assert'
38
+ *
39
+ * assertEquals(answerOf({
40
+ * custom_id: 'a',
41
+ * result: {
42
+ * type: 'succeeded',
43
+ * message: {
44
+ * content: [{ type: 'text', text: 'hi' }],
45
+ * usage: { input_tokens: 10, output_tokens: 5, cache_read_input_tokens: 90 },
46
+ * },
47
+ * },
48
+ * }), {
49
+ * id: 'a',
50
+ * text: 'hi',
51
+ * usage: { input_tokens: 100, cached_tokens: 90, cache_write_tokens: 0, output_tokens: 5 },
52
+ * })
53
+ * assertEquals(answerOf({ custom_id: 'b', result: { type: 'expired' } }), {
54
+ * id: 'b',
55
+ * error: 'expired',
56
+ * })
57
+ * ```
58
+ */ export declare let answerOf: (r: Result) => Answered;
59
+ /** The batches of one key.
60
+ *
61
+ * ```ts
62
+ * import { batches } from '@yaks/anthropic/batches'
63
+ * import { assertEquals } from '@std/assert'
64
+ *
65
+ * let asked: string[] = []
66
+ * let fetch = (url: string | URL | Request, init?: RequestInit) => {
67
+ * asked.push(`${init?.method ?? 'GET'} ${url}`)
68
+ * return Promise.resolve(Response.json({ id: 'b1', processing_status: 'ended' }))
69
+ * }
70
+ * let api = batches({ fetch: fetch as typeof globalThis.fetch, key: () => 'k' })
71
+ * assertEquals(await api.ended('b1'), true)
72
+ * assertEquals(asked, ['GET https://api.anthropic.com/v1/messages/batches/b1'])
73
+ * ```
74
+ */ export declare let batches: (wire: Wire & {
75
+ key: () => string | Promise<string>;
76
+ }) => Batches;
77
+ //# sourceMappingURL=batches.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batches.d.ts","sources":["../batches.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,EAAE,KAAK,EAAE,OAAO,iCAAsC;AAE5E,SAAe,KAAK,IAAI,oBAAmB;AAE3C;2CAC2C,GAC3C,YAAY;EAAU,WAAW,MAAM;EAAE,QAAQ,OAAO,MAAM,EAAE,OAAO;;AAEvE;SACS,GACT,YAAY;EACV,WAAW,MAAM;EACjB;IAEI,MAAM;IACN;MACE;QAAW,MAAM,MAAM;QAAE,OAAO,MAAM;;MACtC;QACE,cAAc,MAAM;QACpB,eAAe,MAAM;QACrB,0BAA0B,MAAM,GAAG,IAAI;QACvC,8BAA8B,MAAM,GAAG,IAAI;;;;IAI7C,MAAM,YAAY,aAAa;IAAW,QAAQ,OAAO;;;AAGjE,oEAAoE,GACpE,OAAO,YAAI,UAAW,GAAG,UAAQ,MAY/B;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BC,GACD,OAAO,YAAI,WAAY,GAAG,WAAS,SAiBlC;AAED;;;;;;;;;;;;;;;CAeC,GACD,OAAO,YAAI,UACT,MAAM;EAAS,WAAW,MAAM,GAAG,QAAQ,MAAM;MAChD,QAuBF"}
@@ -0,0 +1,6 @@
1
+ import { type CacheContext, type Reply } from "@yaks/model";
2
+ /** `anthropic{response_id, cache_expires_at}` for a reply: the expiry is the
3
+ * request's start plus the cache's five minutes. */ export declare let mark: (reply: Reply, cache?: CacheContext) => {
4
+ anthropic: Record<string, unknown>;
5
+ };
6
+ //# sourceMappingURL=mark.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mark.d.ts","sources":["../mark.ts"],"names":[],"mappings":"AAEA,SAAS,KAAK,YAAY,EAAmB,KAAK,KAAK,2BAAgC;AAKvF;kDACkD,GAClD,OAAO,YAAI,OACT,OAAO,OACP,QAAQ;EACL,WAAW,OAAO,MAAM,EAAE,OAAO;EAKpC"}
package/_dist/mod.d.ts ADDED
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @yaks/anthropic implements @yaks/model's {@link Model} over Anthropic's
3
+ * Messages API, spoken over fetch. Every request streams: output text
4
+ * reaches `onText` as it is written, `signal` stops the request, and tool
5
+ * calls come back as `call` items for the caller to run.
6
+ *
7
+ * ```ts
8
+ * import { messages } from '@yaks/anthropic'
9
+ *
10
+ * let model = messages({ key: () => 'the key, from the vault' })
11
+ * // let reply = await model({
12
+ * // model: 'claude-sonnet-5-5',
13
+ * // items: [{ kind: 'user', text: 'Hello' }],
14
+ * // tools: [],
15
+ * // })
16
+ * ```
17
+ *
18
+ * The API keeps nothing between requests, so every request carries the whole
19
+ * conversation, and automatic prompt caching (`cache_control` on the request)
20
+ * reads the prefix the last request wrote. Thinking blocks are not carried
21
+ * back: the API answers a history without them, and the reasoning is private.
22
+ *
23
+ * @module
24
+ */ import { type Item, type Listed, type Model, type Request, type Tool, type Usage } from "@yaks/model";
25
+ import { type Scope } from "@yaks/fp";
26
+ import { anthropicDoc } from "./vocab.js";
27
+ import { mark } from "./mark.js";
28
+ import { READS } from "./reads.js";
29
+ import { type ApiUsage, type CacheControl, type Content, failure, type ModelInfo, type Param, type ToolParam } from "./wire.js";
30
+ export { anthropicDoc, failure, mark, READS };
31
+ export type Options = {
32
+ /** Obtain an Anthropic API key at the moment of the call. */ key: () => string | Promise<string>;
33
+ fetch?: typeof fetch;
34
+ /** The API's root, `https://api.anthropic.com` by default. */ base?: string;
35
+ /** Offer the API's own web search and page fetch. */ web?: boolean;
36
+ /** who may share a read under way (@yaks/model `Lent.scope`) */ scope?: Scope;
37
+ };
38
+ /** The turn a conversation opens with where it opens with none of the
39
+ * person's (a checkpoint that summarized every line, then its replies), since
40
+ * the API takes a conversation only from a user message. It is the same each
41
+ * request, so the next request's prefix is this one's. */ export declare let OPENER: string;
42
+ /** Instructions open the system prompt; one met later in the conversation is
43
+ * said as text in the turn it falls in, which every model accepts. */ export declare let system: (req: Request) => string | undefined;
44
+ /** The conversation as messages: consecutive blocks of one role share a
45
+ * message, so a turn's tool results answer together. The API takes a
46
+ * message's tool results before anything else in it, so a result placed after
47
+ * an image shown beside an earlier one joins the results ahead of it. */ export declare let conversation: (req: Request, rolling?: CacheControl) => Param[];
48
+ /** Tools in name order, so the cached prefix is the same each request. */ export declare let tools: (list: Tool[]) => ToolParam[];
49
+ /** Anthropic counts cache reads and writes beside `input_tokens`; here they
50
+ * are parts of it. */ export declare let usage: (u: ApiUsage) => Usage;
51
+ /** A reply's items in the order the model wrote them. Text runs on across the
52
+ * blocks its citations split it into and the searches and fetches the API ran
53
+ * within it, and each web page it cites is linked after the text citing it.
54
+ * A call's arguments are its input, or the text of an input cut short. */ export declare let items: (content: Content[]) => Item[];
55
+ /** What a reply's thinking blocks said, one paragraph a block, or nothing
56
+ * where it thought nothing it shows. */ export declare let thought: (content: Content[]) => string | undefined;
57
+ /** A model as the API lists it, at the price @yaks/model's list has for its
58
+ * name: the API says no price. */ export declare let listed: (m: ModelInfo) => Listed;
59
+ /** A model over the Messages API. Its `info` gives the context window the
60
+ * API lists and the price @yaks/model's list has for the name. Nothing is
61
+ * retried here: the caller retries, since a retry here could buy one request
62
+ * twice. */ export declare let messages: (options: Options) => Model;
63
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GAED,SAGE,KAAK,IAAI,EACT,KAAK,MAAM,EAGX,KAAK,KAAK,EAEV,KAAK,OAAO,EAEZ,KAAK,IAAI,EACT,KAAK,KAAK,2BACmB;AAE/B,SAAS,KAAK,KAAK,wBAAsC;AACzD,SAAS,YAAY,qBAAoB;AACzC,SAAS,IAAI,oBAAmB;AAChC,SAAS,KAAK,qBAAoB;AAElC,SACE,KAAK,QAAQ,EAGb,KAAK,YAAY,EAEjB,KAAK,OAAO,EAEZ,OAAO,EAGP,KAAK,SAAS,EAEd,KAAK,KAAK,EAEV,KAAK,SAAS,oBAEE;AAElB,SAAS,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,GAAE;AAE7C,YAAY;EACV,2DAA2D,GAC3D,WAAW,MAAM,GAAG,QAAQ,MAAM;EAClC,eAAe;EACf,4DAA4D,GAC5D,OAAO,MAAM;EACb,mDAAmD,GACnD,MAAM,OAAO;EACb,8DAA8D,GAC9D,QAAQ;;AAgBV;;;wDAGwD,GACxD,OAAO,YAAI,QAAQ,MAAM,CAGnB;AAEN;oEACoE,GACpE,OAAO,YAAI,SAAU,KAAK,YAAU,MAAM,GAAG,SAAS,CAKrD;AAgDD;;;uEAGuE,GACvE,OAAO,YAAI,eAAgB,KAAK,SAAS,UAAU,iBAAe,QAyBjE;AAyCD,wEAAwE,GACxE,OAAO,YAAI,QAAS,MAAM,WAAS,YAM5B;AAEP;oBACoB,GACpB,OAAO,YAAI,QAAS,GAAG,aAAW,MAajC;AAuBD;;;wEAGwE,GACxE,OAAO,YAAI,QAAS,SAAS,cAAY,OAwBxC;AAED;sCACsC,GACtC,OAAO,YAAI,UAAW,SAAS,cAAY,MAAM,GAAG,SAAS,CAEf;AAE9C;gCACgC,GAChC,OAAO,YAAI,SAAU,GAAG,cAAY,OAUnC;AA0CD;;;UAGU,GACV,OAAO,YAAI,WAAY,SAAS,YAAU,MA2IzC"}
@@ -0,0 +1,8 @@
1
+ import { type Lent, type Model } from "@yaks/model";
2
+ /** The plugin's options in a config. */ export type Options = {
3
+ /** the API key to call with, instead of the person's */ key?: string;
4
+ /** offer the API's web search and page fetch (default on, unless
5
+ * `HARNESS_WEB=0`) */ web?: boolean;
6
+ };
7
+ /** `anthropic`, over the host's connections and its key. */ export declare let providers: (lent: Lent, options?: Options) => Record<string, Model>;
8
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sources":["../provider.ts"],"names":[],"mappings":"AAOA,SAAwB,KAAK,IAAI,EAAE,KAAK,KAAK,2BAA4C;AAMzF,sCAAsC,GACtC,YAAY;EACV,sDAAsD,GACtD,MAAM,MAAM;EACZ;sBACoB,GACpB,MAAM,OAAO;;AAGf,0DAA0D,GAC1D,OAAO,YAAI,YACT,MAAM,MACN,UAAS,YACR,OAAO,MAAM,EAAE,OA+BjB"}
@@ -0,0 +1,2 @@
1
+ /** Native MIME types and raw-byte ceilings, before other request content. */ export declare let READS: Record<string, number>;
2
+ //# sourceMappingURL=reads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reads.d.ts","sources":["../reads.ts"],"names":[],"mappings":"AAUA,2EAA2E,GAC3E,OAAO,YAAI,OAAO,OAAO,MAAM,EAAE,MAAM,EAOtC"}
@@ -0,0 +1,6 @@
1
+ import type { VocabDoc } from "@yaks/vocab";
2
+ /** What this adapter records about a reply, in the form `loadVocab` accepts. */ export declare let anthropicDoc: VocabDoc;
3
+ /** What this package is: its manifest's description, the one place it is
4
+ * written, which a host stamps on each document here. */ export declare let description: string;
5
+ /** Every document this plugin declares. */ export declare let docs: VocabDoc[];
6
+ //# sourceMappingURL=vocab.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,2BAAgC;AAItD,8EAA8E,GAC9E,OAAO,YAAI,cAAc,SAAc;AAEvC;uDACuD,GACvD,OAAO,YAAI,aAAa,MAAM,CAAuB;AAErD,yCAAyC,GACzC,OAAO,YAAI,MAAM,WAA2B"}
@@ -0,0 +1,94 @@
1
+ import { ModelError } from "@yaks/model";
2
+ type Base64 = {
3
+ type: 'base64';
4
+ media_type: string;
5
+ data: string;
6
+ };
7
+ /** A block of a message sent. */ export type CacheControl = {
8
+ type: 'ephemeral';
9
+ ttl?: '1h';
10
+ };
11
+ export type Block = ({
12
+ type: 'text';
13
+ text: string;
14
+ } | {
15
+ type: 'image';
16
+ source: Base64;
17
+ } | {
18
+ type: 'document';
19
+ source: Base64 | {
20
+ type: 'text';
21
+ media_type: 'text/plain';
22
+ data: string;
23
+ };
24
+ title?: string;
25
+ } | {
26
+ type: 'tool_use';
27
+ id: string;
28
+ name: string;
29
+ input: unknown;
30
+ } | {
31
+ type: 'tool_result';
32
+ tool_use_id: string;
33
+ content: string;
34
+ }) & {
35
+ cache_control?: CacheControl;
36
+ };
37
+ /** A message sent: one role's turn. */ export type Param = {
38
+ role: 'user' | 'assistant';
39
+ content: Block[];
40
+ };
41
+ export type ToolParam = {
42
+ name: string;
43
+ description: string;
44
+ input_schema: Record<string, unknown>;
45
+ };
46
+ /** What a reply used, as the API counts it. */ export type ApiUsage = {
47
+ input_tokens?: number | null;
48
+ output_tokens: number;
49
+ cache_read_input_tokens?: number | null;
50
+ cache_creation_input_tokens?: number | null;
51
+ cache_creation?: {
52
+ ephemeral_1h_input_tokens?: number;
53
+ } | null;
54
+ server_tool_use?: {
55
+ web_search_requests?: number | null;
56
+ } | null;
57
+ };
58
+ /** Where a block of a reply's text came from: a web search result names its
59
+ * page by `url`. */ export type Citation = {
60
+ type: string;
61
+ url?: string;
62
+ title?: string | null;
63
+ };
64
+ /** A block of a reply: text, a tool call, or one this package passes by.
65
+ * `json` is a call's input as the stream has sent it so far. */ export type Content = {
66
+ type: string;
67
+ text?: string;
68
+ /** a thinking block's words */ thinking?: string;
69
+ id?: string;
70
+ name?: string;
71
+ input?: unknown;
72
+ json?: string;
73
+ citations?: Citation[];
74
+ };
75
+ export type ModelInfo = {
76
+ id: string;
77
+ display_name: string;
78
+ max_input_tokens?: number | null;
79
+ max_tokens?: number | null;
80
+ };
81
+ export type Wire = {
82
+ fetch?: typeof fetch;
83
+ base?: string;
84
+ };
85
+ /**
86
+ * What the API refused with, said the way a model's failure is said here: a
87
+ * rate limit or an overloaded or failing server is `busy` and may pass, the
88
+ * key's account out of credit is `credit`, a refused key is `key`, an unknown
89
+ * model is `model`, and a request it would not take is `request`. A spent
90
+ * credit balance is never `limit`: that is a caller's own ceiling, which is
91
+ * expected, while the account running dry is a failure of whoever holds the
92
+ * key. `status` is the HTTP status, or none for an error event mid-stream.
93
+ */ export declare let failure: (status: number | undefined, body: string, headers?: Headers) => ModelError;
94
+ //# sourceMappingURL=wire.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.d.ts","sources":["../wire.ts"],"names":[],"mappings":"AAGA,SAAS,UAAU,2BAAgC;KAQ9C;EAAW,MAAM;EAAU,YAAY,MAAM;EAAE,MAAM,MAAM;;AAEhE,+BAA+B,GAC/B,YAAY;EAAiB,MAAM;EAAa,MAAM;;AAEtD,YAAY;EAEJ,MAAM;EAAQ,MAAM,MAAM;;EAC1B,MAAM;EAAS,QAAQ;;EAEzB,MAAM;EACN,QAAQ;IAAW,MAAM;IAAQ,YAAY;IAAc,MAAM,MAAM;;EACvE,QAAQ,MAAM;;EAEZ,MAAM;EAAY,IAAI,MAAM;EAAE,MAAM,MAAM;EAAE,OAAO,OAAO;;EAC1D,MAAM;EAAe,aAAa,MAAM;EAAE,SAAS,MAAM;;EAE3D,gBAAgB;;AAEtB,qCAAqC,GACrC,YAAY;EAAU,MAAM,SAAS;EAAa,SAAS;;AAU3D,YAAY;EACV,MAAM,MAAM;EACZ,aAAa,MAAM;EACnB,cAAc,OAAO,MAAM,EAAE,OAAO;;AAWtC,6CAA6C,GAC7C,YAAY;EACV,eAAe,MAAM,GAAG,IAAI;EAC5B,eAAe,MAAM;EACrB,0BAA0B,MAAM,GAAG,IAAI;EACvC,8BAA8B,MAAM,GAAG,IAAI;EAC3C;IAAmB,4BAA4B,MAAM;MAAK,IAAI;EAC9D;IAAoB,sBAAsB,MAAM,GAAG,IAAI;MAAK,IAAI;;AAGlE;kBACkB,GAClB,YAAY;EAAa,MAAM,MAAM;EAAE,MAAM,MAAM;EAAE,QAAQ,MAAM,GAAG,IAAI;;AAE1E;8DAC8D,GAC9D,YAAY;EACV,MAAM,MAAM;EACZ,OAAO,MAAM;EACb,6BAA6B,GAC7B,WAAW,MAAM;EACjB,KAAK,MAAM;EACX,OAAO,MAAM;EACb,QAAQ,OAAO;EACf,OAAO,MAAM;EACb,YAAY;;AAed,YAAY;EACV,IAAI,MAAM;EACV,cAAc,MAAM;EACpB,mBAAmB,MAAM,GAAG,IAAI;EAChC,aAAa,MAAM,GAAG,IAAI;;AAqB5B,YAAY;EACV,eAAe;EACf,OAAO,MAAM;;AAsBf;;;;;;;;CAQC,GACD,OAAO,YAAI,UACT,QAAQ,MAAM,GAAG,SAAS,EAC1B,MAAM,MAAM,EACZ,UAAU,YACT,WAkBF"}