@kindgi/adapter-model-shared 0.0.0-bootstrap.0 → 0.1.6-rc.0
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 +201 -0
- package/README.md +57 -2
- package/dist/ai-sdk/index.d.ts +6 -0
- package/dist/ai-sdk/index.d.ts.map +1 -0
- package/dist/ai-sdk/index.js +8 -0
- package/dist/ai-sdk/index.js.map +1 -0
- package/dist/ai-sdk/provider.d.ts +36 -0
- package/dist/ai-sdk/provider.d.ts.map +1 -0
- package/dist/ai-sdk/provider.js +457 -0
- package/dist/ai-sdk/provider.js.map +1 -0
- package/dist/cost.d.ts +32 -0
- package/dist/cost.d.ts.map +1 -0
- package/dist/cost.js +43 -0
- package/dist/cost.js.map +1 -0
- package/dist/errors.d.ts +38 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +57 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/retries.d.ts +35 -0
- package/dist/retries.d.ts.map +1 -0
- package/dist/retries.js +69 -0
- package/dist/retries.js.map +1 -0
- package/package.json +54 -4
- package/src/ai-sdk/index.ts +12 -0
- package/src/ai-sdk/provider.ts +573 -0
- package/src/cost.ts +82 -0
- package/src/errors.ts +90 -0
- package/src/index.ts +23 -0
- package/src/retries.ts +104 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Kindgi Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@kindgi/adapter-model-shared`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared plumbing for Kindgi's model adapters: what every adapter needs to turn a vendor's API into a [`@kindgi/capabilities`](../../capabilities/) `ModelProvider` the same way.
|
|
4
|
+
|
|
5
|
+
Today's engine for sending the requests is the [AI SDK](https://ai-sdk.dev)'s provider packages (`@ai-sdk/*`), called at the provider-spec level (`doGenerate`). It never uses the `ai` package, its agent loop or Vercel's gateway, so no request goes anywhere but the vendor's own API. The engine sits behind one module, `@kindgi/adapter-model-shared/ai-sdk`, the only entry point whose types are a library's. Swapping it later touches that module and the adapters that hand their models in, nothing else.
|
|
6
|
+
|
|
7
|
+
`@kindgi/adapter-model-shared/ai-sdk` is for Kindgi's own adapters. It has no compatibility promise across a change of engine: an adapter you write yourself should implement `ModelProvider` from `@kindgi/capabilities`, which stays.
|
|
8
|
+
|
|
9
|
+
## What every adapter gets
|
|
10
|
+
|
|
11
|
+
- **Retries are Kindgi's.** One send makes one HTTP attempt. The provider makes up to `attempts` in all (default 3) on a retryable failure: 408, 409, 429, 5xx, or no response.
|
|
12
|
+
- It waits what the vendor asks (`retry-after-ms`, `retry-after`), or backs off exponentially with jitter.
|
|
13
|
+
- A vendor asking for more than 60 s ends the call at once, its wait in the message (`… (the vendor asks to wait 120 s)`), rather than retrying early into a limit it named.
|
|
14
|
+
- An answer the library can't read (a malformed 200, an empty body) is tried once more, not twice: each answer may be billed.
|
|
15
|
+
- Each attempt is counted (`@kindgi/capabilities/attempts`): a result's `attempts`, or `attemptsOf(error)` for a failed call.
|
|
16
|
+
- An abort, before the first attempt, in flight or during a wait, rejects with the caller's reason.
|
|
17
|
+
- **Errors are typed.** A failed call throws `ModelProviderError` with a `kind`:
|
|
18
|
+
- `auth`: 401, 403;
|
|
19
|
+
- `rate-limited`: 429;
|
|
20
|
+
- `unavailable`: 408 (the vendor timing out), 409, 424 (Bedrock's model failure), 5xx, and an answer the library can't read;
|
|
21
|
+
- `context-too-long` and `content-filter`, read from the vendor's words on a 400, 413 or 422 ("maximum context length", "prompt is too long", not any mention of "context");
|
|
22
|
+
- `invalid-request`, including a request the library refuses before sending it;
|
|
23
|
+
- `network`: no response at all (`fetch failed`, a connection reset or refused, DNS, a socket timeout). A host refused before any connection (a system-style code that isn't a dropped connection's, such as the runtime's egress refusal `EKINDGIEGRESS`) is `network` too, never retried.
|
|
24
|
+
- A redirect the request won't follow (an adapter's credential goes to its endpoint only) is `unavailable`, never retried.
|
|
25
|
+
It also has the HTTP `status`. Its message is the vendor's own words after the status (`401 {"message":"…"}`), as other adapters' failed calls read.
|
|
26
|
+
- An adapter's own `ModelProviderError` (its sign-in failed, say) ends the call as it is, never retried, even when the library re-wrapped it as a connection failure.
|
|
27
|
+
- Anything else (a bug, ours or the library's) propagates as it is, not retried and not dressed as the vendor's answer.
|
|
28
|
+
- **A stop the library has no unified reason for** is `error`, except running out of context (Bedrock's `model_context_window_exceeded`), which is `length`.
|
|
29
|
+
- **The reasoning state survives a pause.** A provider's opaque state (reasoning with its signature or encrypted content, each text part with its own text and id, a tool call's thought signature) is kept, in order, in the first tool call's `signature`.
|
|
30
|
+
- It goes back on the next call to the same provider's same model, so a durable run can stop after a tool call, restart, and resume with no loss.
|
|
31
|
+
- Another model's state is never sent, nor another provider's for a model of the same name.
|
|
32
|
+
- When the trail's text no longer matches the answer's (a caller trimmed or redacted it), the trail's text goes back alone, where the first text part was, without the state that was about other words.
|
|
33
|
+
- **Tool names:** `.` → `__` on send and back on receive, since vendors refuse dots. The system prompt names them as sent.
|
|
34
|
+
- **Usage onto Kindgi's counters:** prompt (cache reads and writes included), completion, cache read and write, and reasoning tokens. The adapter's own cost formula prices them, and `rawUsage` is the vendor's usage as sent.
|
|
35
|
+
- **Settings a model refuses are dropped, with a warning:** a temperature on a model registered `sampling: false` gives `sampling-unsupported`, never a 400. Lowest thinking is the engine's portable reasoning level.
|
|
36
|
+
- **`traceparent`** is sent as a header only when the call has one.
|
|
37
|
+
- **For audit:** the served model (`servedModel`) and the vendor's request id (`providerRequestId`).
|
|
38
|
+
|
|
39
|
+
## Exports
|
|
40
|
+
|
|
41
|
+
**`@kindgi/adapter-model-shared`, in Kindgi's terms:**
|
|
42
|
+
- **`ModelProviderError`** (`kind`, `status`) and `ModelProviderErrorKind`;
|
|
43
|
+
- `kindOf(failure)` and `modelProviderError(failure, cause)`: a failed response as a typed error;
|
|
44
|
+
- `withRetries(send, policy)`, `backoffMs(headers, attempt)`, `vendorWaitMs(headers)`, `MAX_VENDOR_WAIT_MS`, `RetryPolicy`, `RetryableFailure`: the retry policy, library-free. A failure's `maxAttempts` caps its own attempts below the policy's; its `kind` says what it is when no status can.
|
|
45
|
+
- **`tokenCostUsd(model, usage, options?)`**: a call's cost from the model's registered rates. It covers prompt and completion, cache reads and writes as multiples of the prompt rate, the long-context tier and the data-residency uplift. The arithmetic is the same as the OpenAI-compatible and Anthropic adapters' own: tests in those adapters hold them equal on the bundled presets, since this package never depends on an adapter. What a missing cache multiplier means is the adapter's to say: `cacheReadMultiplier` / `cacheWriteMultiplier`, default 1.
|
|
46
|
+
|
|
47
|
+
**`@kindgi/adapter-model-shared/ai-sdk`, where an adapter hands its model in:** `createAiSdkModelProvider(options)` returns a `ModelProvider`. Its `options`:
|
|
48
|
+
- `metadata`: the registration's `ProviderMetadata`;
|
|
49
|
+
- `languageModel(name, fetch)`: the engine's model for a model name, sending with the `fetch` it's given (each HTTP attempt is counted through it);
|
|
50
|
+
- `providerOptions?(model)`: provider options on every call (Azure: `{ azure: { store: false } }`);
|
|
51
|
+
- `cost(model, usage)`: the adapter's cost formula;
|
|
52
|
+
- `attempts?`: HTTP attempts in all on a retryable failure (default 3);
|
|
53
|
+
- `beforeAttempt?(signal)`: run before each HTTP attempt, inside the retries, with the call's abort signal. An adapter signs in here (a token, a key, the runtime's identity) when its library would report a failure as a plain error, and throws a `ModelProviderError`. What it returns is that attempt's own: the adapter's code the library calls during the attempt (a credential provider, a fetch wrapper) reads it with `attemptPrepared()`, and calls running at once never see each other's;
|
|
54
|
+
- `explain?(error)`: a sentence after a failed call's message, where the vendor's words don't say what to check (Bedrock's 403). The kind, status and attempts stay as they are.
|
|
55
|
+
|
|
56
|
+
## Pins
|
|
57
|
+
|
|
58
|
+
The engine's packages change often (two releases of one of them in a day during the evaluation). Every `@ai-sdk/*` dependency here, and in the adapters built on it, is **pinned exactly** and bumped on purpose, with the live cases re-run per bump. Kindgi keeps its own copy of the AI SDK's source and of the exact package files it pins.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Today's engine, the AI SDK's provider packages: where an adapter hands its provider in.
|
|
3
|
+
* The only entry point of this package whose types are a library's.
|
|
4
|
+
*/
|
|
5
|
+
export { type AiSdkModelProviderOptions, attemptPrepared, createAiSdkModelProvider, } from './provider.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai-sdk/index.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,OAAO,EACL,KAAK,yBAAyB,EAC9B,eAAe,EACf,wBAAwB,GACzB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
/**
|
|
4
|
+
* Today's engine, the AI SDK's provider packages: where an adapter hands its provider in.
|
|
5
|
+
* The only entry point of this package whose types are a library's.
|
|
6
|
+
*/
|
|
7
|
+
export { attemptPrepared, createAiSdkModelProvider, } from './provider.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ai-sdk/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC;;;GAGG;AACH,OAAO,EAEL,eAAe,EACf,wBAAwB,GACzB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { LanguageModelV4, SharedV4ProviderOptions } from '@ai-sdk/provider';
|
|
2
|
+
import type { ModelInfo, ModelProvider, ProviderMetadata, UsageCounters } from '@kindgi/capabilities';
|
|
3
|
+
import { ModelProviderError } from '../errors.js';
|
|
4
|
+
export interface AiSdkModelProviderOptions {
|
|
5
|
+
readonly metadata: ProviderMetadata;
|
|
6
|
+
/** The provider's model for a name, sending with `fetch` (it counts each HTTP attempt). */
|
|
7
|
+
readonly languageModel: (name: string, fetch: typeof globalThis.fetch) => LanguageModelV4;
|
|
8
|
+
/** Provider options on every call (OpenAI: `store: false`). */
|
|
9
|
+
readonly providerOptions?: (model: ModelInfo) => SharedV4ProviderOptions | undefined;
|
|
10
|
+
/** Our cost formula for this vendor, from its usage. */
|
|
11
|
+
readonly cost: (model: ModelInfo, usage: UsageCounters) => number;
|
|
12
|
+
/** HTTP attempts in all on a retryable failure (408, 409, 429, 5xx, network). Default 3. */
|
|
13
|
+
readonly attempts?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Run before each HTTP attempt, inside the retries, with the call's abort signal: where an
|
|
16
|
+
* adapter signs in (the runtime's identity, a key) itself, so a failure is typed by the adapter
|
|
17
|
+
* rather than by its library. What it returns is this attempt's own (`attemptPrepared()`), for
|
|
18
|
+
* the adapter's code the library calls during the attempt. A `ModelProviderError` thrown here
|
|
19
|
+
* (or anywhere in the adapter's own code) ends the call as it is, never retried.
|
|
20
|
+
*/
|
|
21
|
+
readonly beforeAttempt?: (signal: AbortSignal | undefined) => Promise<unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* A sentence for a failed call's message, where the vendor's own words don't say what to
|
|
24
|
+
* check (Bedrock's 403: the IAM policy, or the account's access to the model). Undefined:
|
|
25
|
+
* the message as it is.
|
|
26
|
+
*/
|
|
27
|
+
readonly explain?: (error: ModelProviderError) => string | undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* What this attempt's `beforeAttempt` returned, read from code the library calls during the
|
|
31
|
+
* attempt (a credential provider, a fetch wrapper); undefined outside one. Per attempt, so calls
|
|
32
|
+
* running at once never see each other's.
|
|
33
|
+
*/
|
|
34
|
+
export declare function attemptPrepared<T>(): T | undefined;
|
|
35
|
+
export declare function createAiSdkModelProvider(options: AiSdkModelProviderOptions): ModelProvider;
|
|
36
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/ai-sdk/provider.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EACV,eAAe,EAMf,uBAAuB,EACxB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EAIV,SAAS,EAET,aAAa,EAEb,gBAAgB,EAChB,aAAa,EACd,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EAAE,kBAAkB,EAAsB,MAAM,cAAc,CAAC;AAGtE,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,2FAA2F;IAC3F,QAAQ,CAAC,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,KAAK,eAAe,CAAC;IAC1F,+DAA+D;IAC/D,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,uBAAuB,GAAG,SAAS,CAAC;IACrF,wDAAwD;IACxD,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,KAAK,MAAM,CAAC;IAClE,4FAA4F;IAC5F,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;;OAMG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/E;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,MAAM,GAAG,SAAS,CAAC;CACtE;AAKD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,KAAK,CAAC,GAAG,SAAS,CAElD;AAKD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,aAAa,CAsI1F"}
|