@yanlinglabs/winter-provider-runtime 0.0.2
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 +21 -0
- package/NOTICE +41 -0
- package/README.md +109 -0
- package/dist/adapters/anthropic/console-oauth.d.ts +101 -0
- package/dist/adapters/anthropic/index.d.ts +4 -0
- package/dist/adapters/anthropic/messages.d.ts +76 -0
- package/dist/adapters/bedrock/converse.d.ts +143 -0
- package/dist/adapters/bedrock/crc32.d.ts +9 -0
- package/dist/adapters/bedrock/credentials.d.ts +32 -0
- package/dist/adapters/bedrock/eventstream.d.ts +65 -0
- package/dist/adapters/bedrock/index.d.ts +8 -0
- package/dist/adapters/bedrock/sigv4.d.ts +119 -0
- package/dist/adapters/bedrock/testing.d.ts +46 -0
- package/dist/adapters/content-blocks.d.ts +7 -0
- package/dist/adapters/google/adc.d.ts +35 -0
- package/dist/adapters/google/generate-content.d.ts +136 -0
- package/dist/adapters/google/index.d.ts +8 -0
- package/dist/adapters/google/jwt-rs256.d.ts +36 -0
- package/dist/adapters/google/vertex.d.ts +15 -0
- package/dist/adapters/index.d.ts +34 -0
- package/dist/adapters/oauth/device-code.d.ts +32 -0
- package/dist/adapters/oauth/refresh.d.ts +40 -0
- package/dist/adapters/openai/azure.d.ts +38 -0
- package/dist/adapters/openai/chat-completions.d.ts +86 -0
- package/dist/adapters/openai/codex-config.d.ts +42 -0
- package/dist/adapters/openai/codex-oauth.d.ts +47 -0
- package/dist/adapters/openai/index.d.ts +20 -0
- package/dist/adapters/openai/local.d.ts +16 -0
- package/dist/adapters/openai/pkce.d.ts +111 -0
- package/dist/adapters/openai/quota.d.ts +99 -0
- package/dist/adapters/openai/responses.d.ts +142 -0
- package/dist/adapters/openai/shared.d.ts +359 -0
- package/dist/adapters/openai/testing.d.ts +59 -0
- package/dist/adapters/openai/xai-derived-shapes.d.ts +67 -0
- package/dist/adapters/openai/xai-oauth.d.ts +102 -0
- package/dist/adapters/openai/xai-oauth.testing.d.ts +62 -0
- package/dist/adapters/privileged-headers.d.ts +51 -0
- package/dist/adapters/refusals.d.ts +10 -0
- package/dist/address-classifier.d.ts +17 -0
- package/dist/bun-required.d.ts +54 -0
- package/dist/continuity/decoration.d.ts +89 -0
- package/dist/continuity/domains.d.ts +92 -0
- package/dist/continuity/fixtures.d.ts +44 -0
- package/dist/continuity/handoff.d.ts +94 -0
- package/dist/continuity/index.d.ts +10 -0
- package/dist/continuity/renderer.d.ts +111 -0
- package/dist/continuity/warnings.d.ts +46 -0
- package/dist/credentials/env.d.ts +6 -0
- package/dist/credentials/file.d.ts +21 -0
- package/dist/credentials/memory.d.ts +8 -0
- package/dist/credentials/types.d.ts +38 -0
- package/dist/discovery.d.ts +15 -0
- package/dist/endpoint-policy.d.ts +127 -0
- package/dist/errors.d.ts +68 -0
- package/dist/http.d.ts +29 -0
- package/dist/identity.d.ts +62 -0
- package/dist/index-5z94gxhk.js +43790 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +3194 -0
- package/dist/registry.d.ts +136 -0
- package/dist/retry.d.ts +38 -0
- package/dist/sse.d.ts +12 -0
- package/dist/testing.d.ts +19 -0
- package/dist/testing.js +432 -0
- package/dist/types.d.ts +376 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 yanlingLabs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
NOTICE
|
|
2
|
+
======
|
|
3
|
+
|
|
4
|
+
Third-party attributions for the Winter agent SDK.
|
|
5
|
+
|
|
6
|
+
This file records material that Winter DERIVED FROM third-party artifacts. Winter copies no source
|
|
7
|
+
code from any of them; what it takes is protocol facts — endpoint URLs, form-field names, client
|
|
8
|
+
identifiers and scope strings — which it needs in order to speak to a vendor's service at all. Each
|
|
9
|
+
entry names the exact commit the values were read at, so the derivation is re-checkable.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
-------------------------------------------------------------------------------
|
|
13
|
+
xai-org/grok-build
|
|
14
|
+
-------------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
Repository: https://github.com/xai-org/grok-build
|
|
17
|
+
Commit: 72a61251fcffb464bcc687aeb5a998e5a98ec0c9
|
|
18
|
+
License: Apache License, Version 2.0
|
|
19
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
20
|
+
Copyright: Copyright 2023-2026 SpaceXAI
|
|
21
|
+
|
|
22
|
+
Winter's `xai-oauth` provider derives the following constants and request shapes from this
|
|
23
|
+
repository's authentication module, in order to perform its own OAuth 2.0 device authorization
|
|
24
|
+
grant (RFC 8628) against xAI's public, secret-less OAuth client:
|
|
25
|
+
|
|
26
|
+
- the public OAuth client identifier
|
|
27
|
+
- the OAuth issuer, device-authorization endpoint and token endpoint
|
|
28
|
+
- the requested scope set
|
|
29
|
+
- the name of the form field the flow carries a client identity in
|
|
30
|
+
- the shape (field names) of the device-authorization and token requests
|
|
31
|
+
|
|
32
|
+
No source code from this repository is copied into Winter, and no part of Winter is a derivative
|
|
33
|
+
work of it. The derivation is recorded, with per-value line citations, in:
|
|
34
|
+
|
|
35
|
+
packages/conformance/compat/xai/grok-build/derived-shapes-p6b-xai.md
|
|
36
|
+
|
|
37
|
+
Winter identifies ITSELF in that flow. It sends its own `User-Agent` (`winter-agent-sdk/<version>`)
|
|
38
|
+
and its own name in the flow's identity field, and it does not send xAI's product-identity or
|
|
39
|
+
telemetry headers. Winter is not affiliated with or endorsed by SpaceXAI, and "Grok" and "Grok Build"
|
|
40
|
+
are the marks of their owner; they appear here and in the capture solely to identify the artifact
|
|
41
|
+
these values were derived from.
|
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# `@yanlinglabs/winter-provider-runtime`
|
|
2
|
+
|
|
3
|
+
Winter's provider layer: the adapter registry, the shipped provider adapters (OpenAI Responses and
|
|
4
|
+
Chat Completions, Anthropic Messages, Google generateContent, Bedrock Converse, the OAuth-backed
|
|
5
|
+
codex/xAI/Console flows), the credential-ref surface, endpoint policy, retry/stall handling and the
|
|
6
|
+
honest-identity headers every request carries.
|
|
7
|
+
|
|
8
|
+
This package is published to GitHub Packages under restricted access (`@yanlinglabs` scope). The
|
|
9
|
+
registry is chosen by the release workflow, not by a committed pin — see [RELEASING.md](https://github.com/yanlingLabs/winter-agent-sdk/blob/main/RELEASING.md).
|
|
10
|
+
|
|
11
|
+
## What it ships
|
|
12
|
+
|
|
13
|
+
| Import | What it is |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| `@yanlinglabs/winter-provider-runtime` | The full barrel: the registry, the adapters, credential refs and stores, endpoint policy, the error taxonomy, and the identity surface. |
|
|
16
|
+
| `@yanlinglabs/winter-provider-runtime/testing` | Test-support helpers a consumer's own adapter tests need: descriptor/context builders, the SigV4 and event-stream primitives, the loopback OAuth/chat fakes, and the fixture catalog. |
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
Published to **both** registries — but not because a consumer of the wrapper needs it. The wrapper
|
|
21
|
+
`@yanlinglabs/winter-agent-sdk` SPAWNS the compiled `winter` runtime rather than importing this
|
|
22
|
+
package, so `npm install @yanlinglabs/winter-agent-sdk` does not pull it in. It is on public npm
|
|
23
|
+
because `@yanlinglabs/winter-provider-conformance` — a harness the out-of-repo router package uses as
|
|
24
|
+
a dev dependency — imports it, and a published manifest pins its dependencies at an exact version: a
|
|
25
|
+
harness on npm whose own dependency is not there is an install that 404s.
|
|
26
|
+
|
|
27
|
+
### From public npm (anyone)
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npm install @yanlinglabs/winter-provider-runtime
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Nothing else is needed: the `@yanlinglabs` scope is public on npm.
|
|
34
|
+
|
|
35
|
+
### From GitHub Packages (the `yanlingLabs` org)
|
|
36
|
+
|
|
37
|
+
GitHub Packages needs the scope pointed at it and an authenticated read, even for a public package.
|
|
38
|
+
In your project's `.npmrc`:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
@yanlinglabs:registry=https://npm.pkg.github.com
|
|
42
|
+
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
…with `GITHUB_TOKEN` in the environment — a personal access token carrying `read:packages`, never a
|
|
46
|
+
literal in the file. Then `npm install @yanlinglabs/winter-provider-runtime` as usual.
|
|
47
|
+
|
|
48
|
+
**The published packages contain COMPILED OUTPUT ONLY.** Each tarball ships `dist/` — the bundled
|
|
49
|
+
JavaScript a consumer imports and the `.d.ts` declarations their type-checker reads — plus its data
|
|
50
|
+
files, `README.md` and `LICENSE`. It does **not** ship `src/`: the TypeScript sources live at
|
|
51
|
+
<https://github.com/yanlingLabs/winter-agent-sdk>, which is where to read them, file an issue, or send
|
|
52
|
+
a patch.
|
|
53
|
+
|
|
54
|
+
## Bun-only surface
|
|
55
|
+
|
|
56
|
+
This package declares `engines.node` and every entry point **imports** cleanly under Node 18+ (the
|
|
57
|
+
compiled emit under `dist/` is what a non-Bun runtime resolves, via each export's `default`
|
|
58
|
+
condition; Bun resolves the `bun` condition and gets the TypeScript source unchanged). Importable is
|
|
59
|
+
not the same as runnable on every path — these exports need the Bun runtime:
|
|
60
|
+
|
|
61
|
+
| Function | Import | Needs | Why |
|
|
62
|
+
| --- | --- | --- | --- |
|
|
63
|
+
| `startCodexLogin()` | `@yanlinglabs/winter-provider-runtime` | `Bun.serve` | The authorization-code flow receives the vendor's redirect on `127.0.0.1`, which needs a real HTTP listener. |
|
|
64
|
+
| `startAnthropicConsoleLogin()` | `@yanlinglabs/winter-provider-runtime` | `Bun.serve` | Same flow, same listener. |
|
|
65
|
+
| `startXaiOauthFake()` | `@yanlinglabs/winter-provider-runtime/testing` | `Bun.serve` | Binds a loopback server on `127.0.0.1:0` to stand in for the vendor. |
|
|
66
|
+
| `startXaiChatFake()` | `@yanlinglabs/winter-provider-runtime/testing` | `Bun.serve` | Same. |
|
|
67
|
+
|
|
68
|
+
(Internally all four go through one `runLoginFlow`/`Bun.serve` seam, which is not on either barrel
|
|
69
|
+
and which a consumer cannot call.)
|
|
70
|
+
|
|
71
|
+
Each throws `BunRequiredError` (exported from both barrels) as its FIRST action — before any network
|
|
72
|
+
call, file write or credential read — naming the function, the Bun API and what to do instead. Catch
|
|
73
|
+
it by identity:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { startCodexLogin, BunRequiredError } from "@yanlinglabs/winter-provider-runtime";
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
await startCodexLogin(store, options);
|
|
80
|
+
} catch (err) {
|
|
81
|
+
if (err instanceof BunRequiredError) {
|
|
82
|
+
// Complete the login in a Bun process, then pass the resulting credential ref to this session.
|
|
83
|
+
}
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### `BunRequiredError` is THIS package's own class
|
|
89
|
+
|
|
90
|
+
`@yanlinglabs/winter-conformance` exports a class with the same name and shape, and the two are
|
|
91
|
+
deliberately **not** the same type — the packages share no dependency, so there is no module either
|
|
92
|
+
could import it from. **Catch the one you imported.** Within this package it is one type across every
|
|
93
|
+
subpath: an error thrown by `./testing`'s fakes satisfies `instanceof BunRequiredError` imported from
|
|
94
|
+
the main barrel, and vice versa, under Node as well as Bun (the compiled emit gives each export entry
|
|
95
|
+
its own bundle, so the class carries a package-scoped `Symbol.for` brand to make that hold).
|
|
96
|
+
|
|
97
|
+
**`startXaiLogin()` is NOT on this list**, deliberately: xAI's login is RFC 8628 device-code, which is
|
|
98
|
+
`fetch` and polling only — no listener, no spawn — so it runs under Node like the rest of the package.
|
|
99
|
+
|
|
100
|
+
Everything else — the registry, every adapter's `streamTurn`, discovery, the credential stores, the
|
|
101
|
+
endpoint policy and the identity helpers — is plain Node-compatible code over `fetch` and `node:*`.
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
MIT — see [`LICENSE`](./LICENSE), which ships in the published tarball.
|
|
106
|
+
|
|
107
|
+
This package's xAI OAuth provider derives its client id, endpoints, scope set and request field names
|
|
108
|
+
from the Apache-2.0 licensed `xai-org/grok-build`; that attribution is in [`NOTICE`](./NOTICE), which
|
|
109
|
+
ships in the tarball beside this file.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { CredentialRef, CredentialStore } from "../../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The Console OAuth constants, derived from `@anthropic-ai/claude-agent-sdk@0.3.250`.
|
|
4
|
+
*
|
|
5
|
+
* Pinned field-by-field against `compat/anthropic/0.3.250/derived-p6b.ts`. Note what is NOT here:
|
|
6
|
+
* the consumer authorize host, the consumer origin, the two `claude_cli`-scoped endpoints, and the
|
|
7
|
+
* vendor's own product beta. A constant that exists is a constant something can come to use, so the
|
|
8
|
+
* excluded ones live only in the capture document, as a record of the exclusion.
|
|
9
|
+
*/
|
|
10
|
+
export declare const CONSOLE_OAUTH: {
|
|
11
|
+
/** A PUBLIC PKCE client id from a public npm artifact — there is no client secret, and none is sent. */
|
|
12
|
+
readonly clientId: "9d1c250a-e61b-44d9-88ed-5944d1962f5e";
|
|
13
|
+
readonly authorizeUrl: "https://platform.claude.com/oauth/authorize";
|
|
14
|
+
readonly tokenUrl: "https://platform.claude.com/v1/oauth/token";
|
|
15
|
+
/** The account id is NOT in the token response; it is read from here, as `account.uuid`. */
|
|
16
|
+
readonly profileUrl: "https://api.anthropic.com/api/oauth/profile";
|
|
17
|
+
readonly scope: "user:inference user:profile";
|
|
18
|
+
/**
|
|
19
|
+
* `0` — an ephemeral port, and the DERIVED value rather than a test convenience. This client's
|
|
20
|
+
* registration accepts a loopback URI on any port; codex's fixed 1455/1457 pair is the opposite
|
|
21
|
+
* case, and copying that shape here would bind a port for no reason and fight a concurrent login.
|
|
22
|
+
*/
|
|
23
|
+
readonly callbackPort: 0;
|
|
24
|
+
readonly callbackPath: "/callback";
|
|
25
|
+
/** The `anthropic-beta` value that accompanies an OAuth bearer on every request. */
|
|
26
|
+
readonly betaHeader: "oauth-2025-04-20";
|
|
27
|
+
/**
|
|
28
|
+
* The profile-response field that names the credential record, as a dotted path.
|
|
29
|
+
*
|
|
30
|
+
* Present so that EVERY field of the capture's derived table has a counterpart here and the
|
|
31
|
+
* constants test gates all nine — a derived value with no shipped twin is a value nothing stops
|
|
32
|
+
* from drifting. `fetchAccountId` reads exactly this path; it is stated rather than walked because
|
|
33
|
+
* one fixed shape does not need a path interpreter.
|
|
34
|
+
*/
|
|
35
|
+
readonly accountIdPath: "account.uuid";
|
|
36
|
+
};
|
|
37
|
+
/** How long before expiry a token is renewed rather than used. One minute of slack over a turn that may take seconds to start. */
|
|
38
|
+
export declare const OAUTH_REFRESH_WINDOW_MS = 60000;
|
|
39
|
+
/**
|
|
40
|
+
* The ONE provider id whose `oauth` credential is an Anthropic Console one.
|
|
41
|
+
*
|
|
42
|
+
* NOT A FORMALITY, and the reason it is a named constant rather than a string literal in a
|
|
43
|
+
* condition: R6b-5 makes this adapter MULTI-PROVIDER — a third party that speaks the Anthropic
|
|
44
|
+
* Messages dialect ships as its own `<id>-anthropic` row on this same `adapterId`, with its own
|
|
45
|
+
* `defaultEndpoints.api`. Nothing upstream of the adapter checks that a stored credential's KIND
|
|
46
|
+
* matches its row's `authKinds`, so without this gate an `oauth` credential stored against a sibling
|
|
47
|
+
* row would have its REFRESH TOKEN posted to `platform.claude.com` — a third party's credential sent
|
|
48
|
+
* to Anthropic — and would stamp Anthropic's beta on that third party's request. Both are the same
|
|
49
|
+
* mistake the `bearer` arm already refuses to make, with a considerably worse failure.
|
|
50
|
+
*/
|
|
51
|
+
export declare const ANTHROPIC_CONSOLE_PROVIDER_ID = "anthropic";
|
|
52
|
+
/**
|
|
53
|
+
* The ONE spelling of an Anthropic OAuth record's name (R6-10).
|
|
54
|
+
*
|
|
55
|
+
* Exported and used by both the login and the adapter, because a host that assembles
|
|
56
|
+
* `anthropic:<id>` by hand will eventually assemble it differently from whatever reads it — a
|
|
57
|
+
* credential written to a key nothing looks up, failing as "no credential configured" with the
|
|
58
|
+
* record sitting right there.
|
|
59
|
+
*/
|
|
60
|
+
export declare function anthropicCredentialRef(accountId: string, service?: string): Extract<CredentialRef, {
|
|
61
|
+
kind: "keychain";
|
|
62
|
+
}>;
|
|
63
|
+
export interface AnthropicConsoleLoginOptions {
|
|
64
|
+
/** Opens the browser. HOST-supplied: the SDK never shells out to one itself. */
|
|
65
|
+
openUrl: (url: string) => Promise<void>;
|
|
66
|
+
/** Overridden by a fixture; production uses `CONSOLE_OAUTH`'s own values. */
|
|
67
|
+
authorizeUrl?: string;
|
|
68
|
+
tokenUrl?: string;
|
|
69
|
+
profileUrl?: string;
|
|
70
|
+
callbackPort?: number;
|
|
71
|
+
timeoutMs?: number;
|
|
72
|
+
/** The Keychain service the record lands in — `config.keychainService` from the host. */
|
|
73
|
+
service?: string;
|
|
74
|
+
onAuthStatus?: (status: {
|
|
75
|
+
isAuthenticating: boolean;
|
|
76
|
+
output?: string[];
|
|
77
|
+
error?: string;
|
|
78
|
+
}) => void;
|
|
79
|
+
}
|
|
80
|
+
export interface AnthropicConsoleLoginResult {
|
|
81
|
+
ref: Extract<CredentialRef, {
|
|
82
|
+
kind: "keychain";
|
|
83
|
+
}>;
|
|
84
|
+
accountId: string;
|
|
85
|
+
/** Epoch milliseconds. */
|
|
86
|
+
expiresAt: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The host-invoked Console login. Runs the PKCE loopback flow, asks who signed in, and PERSISTS the
|
|
90
|
+
* result through the credential store — returning the ref a session should then be configured with.
|
|
91
|
+
*
|
|
92
|
+
* WHY THERE IS A SECOND REQUEST. The token response carries no account of any kind (the capture's
|
|
93
|
+
* §2.3), so unlike codex — where the id token's own claim names the record — the account id has to
|
|
94
|
+
* be fetched. `GET /api/oauth/profile` under the new bearer is what the pinned artifact itself does,
|
|
95
|
+
* and `user:profile` is in the scope precisely to authorise it.
|
|
96
|
+
*
|
|
97
|
+
* A LOGIN THAT CANNOT NAME ITS RECORD IS A REFUSAL, not a fallback to some default slot: R6-10 is
|
|
98
|
+
* explicit that a credential occupies one record per provider/account, and `anthropic:undefined`
|
|
99
|
+
* would be a shared global slot wearing a per-account name.
|
|
100
|
+
*/
|
|
101
|
+
export declare function startAnthropicConsoleLogin(store: CredentialStore, options: AnthropicConsoleLoginOptions): Promise<AnthropicConsoleLoginResult>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ANTHROPIC_ADAPTER_ID, ANTHROPIC_API_VERSION, ANTHROPIC_DEFAULT_BASE_URL, ANTHROPIC_DEFAULT_MAX_TOKENS, createAnthropicMessagesAdapter, findDescriptor, mapAnthropicEffort, toWireMessages, } from "./messages.js";
|
|
2
|
+
export type { AnthropicAdapterOptions, EffortMapping } from "./messages.js";
|
|
3
|
+
export { CONSOLE_OAUTH, OAUTH_REFRESH_WINDOW_MS, anthropicCredentialRef, startAnthropicConsoleLogin } from "./console-oauth.js";
|
|
4
|
+
export type { AnthropicConsoleLoginOptions, AnthropicConsoleLoginResult } from "./console-oauth.js";
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { WinterCatalog, WinterModelDescriptor } from "@yanlinglabs/winter-provider-catalog";
|
|
2
|
+
import { type RetryPolicyOptions } from "../../retry.js";
|
|
3
|
+
import type { ProviderAdapter, ProviderMessageLike, TurnRequest } from "../../types.js";
|
|
4
|
+
/** The provider id this adapter is registered for, and the catalog's own `adapterId` for it. */
|
|
5
|
+
export declare const ANTHROPIC_ADAPTER_ID = "winter.anthropic-messages";
|
|
6
|
+
/** The GENERATED endpoint. Immutable (R6-11); a user override rides `ConnectionProfile.baseUrl`. Pinned to the catalog row by a test. */
|
|
7
|
+
export declare const ANTHROPIC_DEFAULT_BASE_URL = "https://api.anthropic.com";
|
|
8
|
+
/** The `anthropic-version` header every request carries. A protocol header, never a privileged one (R6-L). */
|
|
9
|
+
export declare const ANTHROPIC_API_VERSION = "2023-06-01";
|
|
10
|
+
/**
|
|
11
|
+
* The wire `max_tokens` when neither the request nor the descriptor names one.
|
|
12
|
+
*
|
|
13
|
+
* DISCLOSED GAP-FILL: `max_tokens` is mandatory on this endpoint, `streamTurn` receives no
|
|
14
|
+
* descriptor guarantee, and the seed catalog carries no `maxOutputTokens` evidence for either
|
|
15
|
+
* Anthropic row. Capture (F) observed the pinned runtime sending 64000 for `claude-sonnet-5`, but
|
|
16
|
+
* that is one model's ceiling and inventing it for every model would be a capability claim with no
|
|
17
|
+
* evidence behind it. 4096 is the value the family's own documentation has used as the conservative
|
|
18
|
+
* default for as long as the endpoint has existed; a host that wants more sets
|
|
19
|
+
* `TurnRequest.maxOutputTokens` or the descriptor carries `maxOutputTokens` evidence.
|
|
20
|
+
*/
|
|
21
|
+
export declare const ANTHROPIC_DEFAULT_MAX_TOKENS = 4096;
|
|
22
|
+
export interface AnthropicAdapterOptions {
|
|
23
|
+
/** The catalog the descriptor is looked up in. Defaults to the compiled one; injected in tests so a fixture owns its own rows. */
|
|
24
|
+
catalog?: WinterCatalog;
|
|
25
|
+
/** Milliseconds allowed for RESPONSE HEADERS. Not a bound on the generation -- mid-stream silence is `ctx.stallTimeoutMs`'s job. */
|
|
26
|
+
requestTimeoutMs?: number;
|
|
27
|
+
maxBodyBytes?: number;
|
|
28
|
+
/** Injected for deterministic retry fixtures (no real sleeping, no real jitter). */
|
|
29
|
+
retry?: RetryPolicyOptions;
|
|
30
|
+
/** `anthropic-beta` values, joined with commas. A PROTOCOL header (R6-L): every endpoint needs it to be spoken to, and it names no account. */
|
|
31
|
+
betas?: string[];
|
|
32
|
+
defaultMaxOutputTokens?: number;
|
|
33
|
+
/**
|
|
34
|
+
* The OAuth token endpoint a near-expiry `oauth` credential is renewed through (D20).
|
|
35
|
+
*
|
|
36
|
+
* Injectable for a fixture exactly as codex's is; production uses `CONSOLE_OAUTH.tokenUrl`. It has
|
|
37
|
+
* no effect on an `api-key` credential, which is every other row this adapter serves.
|
|
38
|
+
*/
|
|
39
|
+
tokenUrl?: string;
|
|
40
|
+
}
|
|
41
|
+
export declare function toWireMessages(messages: ProviderMessageLike[]): Array<{
|
|
42
|
+
role: "user" | "assistant";
|
|
43
|
+
content: Record<string, unknown>[];
|
|
44
|
+
}>;
|
|
45
|
+
/** Looks a descriptor up by provider + the id/alias/key the request named. `undefined` for an `allowUnlisted` passthrough, which is a FACT the checks below fail closed on. */
|
|
46
|
+
export declare function findDescriptor(catalog: WinterCatalog, providerId: string, model: string): WinterModelDescriptor | undefined;
|
|
47
|
+
export type EffortMapping = {
|
|
48
|
+
ok: true;
|
|
49
|
+
value: {
|
|
50
|
+
type: "enabled";
|
|
51
|
+
budget_tokens: number;
|
|
52
|
+
};
|
|
53
|
+
} | {
|
|
54
|
+
ok: false;
|
|
55
|
+
reason: string;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Effort -> the model's VERIFIED vocabulary, or a refusal (WS-13 §8.2).
|
|
59
|
+
*
|
|
60
|
+
* A NUMBER is mapped to the nearest declared tier by treating it as a 0-100 intensity across the
|
|
61
|
+
* model's own `reasoning.efforts` list. The pin admits a numeric effort on exactly one surface
|
|
62
|
+
* (`AgentDefinition.effort`, `sdk.d.ts:87`) and states no unit, range or mapping for it -- so this
|
|
63
|
+
* is gap-filling, disclosed, and it can only ever select a tier the model already declares.
|
|
64
|
+
*/
|
|
65
|
+
export declare function mapAnthropicEffort(effort: TurnRequest["effort"], descriptor: WinterModelDescriptor | undefined): EffortMapping;
|
|
66
|
+
/**
|
|
67
|
+
* At which event this family's COMPLETE in-dialect block is captured, from the descriptor's own
|
|
68
|
+
* `completionEvent` evidence (Minor 7).
|
|
69
|
+
*
|
|
70
|
+
* Matched LENIENTLY by mention, for the same reason as the Google resolver: the field is a prose-ish
|
|
71
|
+
* `CapabilityEvidence<string>`. An unrecognised value falls back to `block-stop`, this family's real
|
|
72
|
+
* per-block terminator -- the conservative answer, since it is the earliest point at which a block is
|
|
73
|
+
* genuinely complete and holding longer can only ever delay a capture, never take a partial one.
|
|
74
|
+
*/
|
|
75
|
+
export declare function anthropicCaptureEvent(descriptor: WinterModelDescriptor | undefined): "block-stop" | "message-stop";
|
|
76
|
+
export declare function createAnthropicMessagesAdapter(opts?: AnthropicAdapterOptions): ProviderAdapter;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { WinterModelDescriptor } from "@yanlinglabs/winter-provider-catalog";
|
|
2
|
+
import type { DiscoveryContext, ProviderAdapter, ProviderError, ProviderMessageLike, TurnRequest } from "../../types.js";
|
|
3
|
+
import { type RetryPolicyOptions } from "../../retry.js";
|
|
4
|
+
import { type IdentityHeaderLookup } from "../../identity.js";
|
|
5
|
+
export declare const BEDROCK_ADAPTER_ID = "winter.bedrock-converse";
|
|
6
|
+
export declare const BEDROCK_ADAPTER_VERSION = "1";
|
|
7
|
+
/** Resolves a provider-local model id to its catalog row, or `undefined` for an id the catalog does not list. */
|
|
8
|
+
export type DescriptorLookup = (modelId: string) => WinterModelDescriptor | undefined;
|
|
9
|
+
export interface BedrockAdapterOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The descriptor for a provider-local model id. **REQUIRED** (controller ruling, matching Lane A).
|
|
12
|
+
*
|
|
13
|
+
* It is not optional precisely BECAUSE nothing fails to compile without it: the frozen
|
|
14
|
+
* `ProviderAdapter` hands a descriptor to `mapEffort` and `capabilities` but NOT to `streamTurn`,
|
|
15
|
+
* while WS-13 §8.2 requires the effort, thinking, tool and limit refusals to happen BEFORE a
|
|
16
|
+
* request is sent. An adapter built without a lookup is a WEAKER adapter, not a broken one — the
|
|
17
|
+
* tools-on-a-non-tool-calling-model and output-token-limit refusals simply vanish, silently — so
|
|
18
|
+
* the type makes the decision explicit instead. A caller with no catalog passes
|
|
19
|
+
* `descriptors: () => undefined` and has SAID so.
|
|
20
|
+
*/
|
|
21
|
+
descriptors: DescriptorLookup;
|
|
22
|
+
/**
|
|
23
|
+
* Whether a model's answer is streamed. Default: always.
|
|
24
|
+
*
|
|
25
|
+
* `GetFoundationModel`/`ListFoundationModels` report `responseStreamingSupported`, and a model
|
|
26
|
+
* without it must be driven through `Converse` — whose completed JSON this adapter maps into the
|
|
27
|
+
* IDENTICAL `ProviderEvent` sequence, so a consumer cannot tell which operation answered.
|
|
28
|
+
*/
|
|
29
|
+
streaming?: (modelId: string) => boolean;
|
|
30
|
+
/** R6-L PRIVILEGED: cross-account confused-deputy identifiers. They name the operator's account topology and must never reach a user endpoint. */
|
|
31
|
+
sourceAccount?: string;
|
|
32
|
+
sourceArn?: string;
|
|
33
|
+
/**
|
|
34
|
+
* The ADAPTER'S OWN endpoint, carrying GENERATED provenance. Defaults to the region-derived
|
|
35
|
+
* `https://bedrock-runtime.<region>.amazonaws.com` / `https://bedrock.<region>.amazonaws.com` pair.
|
|
36
|
+
*
|
|
37
|
+
* **A HOST MUST NOT SET THIS.** A host endpoint is `connection.baseUrl`, which is deliberately a
|
|
38
|
+
* USER endpoint and therefore loses privileged headers — that difference is the whole of R6-L, and
|
|
39
|
+
* setting this instead would silently restore them for an endpoint the reviewed catalog never
|
|
40
|
+
* named. It exists because the gate's POSITIVE branch is otherwise untestable: a generated
|
|
41
|
+
* endpoint is by definition a real AWS hostname, so without this seam "the privileged header rides
|
|
42
|
+
* a generated endpoint" could only be asserted about intent, never about a live request.
|
|
43
|
+
*
|
|
44
|
+
* `connection.baseUrl`, when present, still WINS over this — a host's explicit redirection is
|
|
45
|
+
* never overridden by an adapter's own default.
|
|
46
|
+
*/
|
|
47
|
+
vendorBaseUrl?: string;
|
|
48
|
+
maxBodyBytes?: number;
|
|
49
|
+
timeoutMs?: number;
|
|
50
|
+
retry?: RetryPolicyOptions;
|
|
51
|
+
/** Injected so a fixture can pin a signature against a known-answer vector. */
|
|
52
|
+
now?: () => Date;
|
|
53
|
+
/**
|
|
54
|
+
* WS-13b §7/§8.4 (fix-wave R-FW-2): the per-ROW second identity field, looked up by
|
|
55
|
+
* `ctx.connection.providerId`.
|
|
56
|
+
*
|
|
57
|
+
* A CONSTRUCTION OPTION here rather than a catalog derivation (the shape the Anthropic and Google
|
|
58
|
+
* families use), because this adapter takes a `descriptors` lookup and never a catalog.
|
|
59
|
+
* `createShippedAdapters` supplies it; a fixture that omits it gets `{}`, which is what every
|
|
60
|
+
* Bedrock row carries today.
|
|
61
|
+
*/
|
|
62
|
+
identityHeaders?: IdentityHeaderLookup;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Bedrock's structured error code, which `normalizeHttpError` cannot find on its own.
|
|
66
|
+
*
|
|
67
|
+
* The frozen normalizer reads `error.code` / `error.type` / `error.status` — the three JSON dialects
|
|
68
|
+
* of the P6 cohort. Bedrock is a fourth: its REST-JSON error body is a bare `{"message": "..."}` and
|
|
69
|
+
* the machine-readable value rides the `x-amzn-errortype` HEADER (or, on some paths, a `__type`
|
|
70
|
+
* field). Both spellings carry a trailing namespace (`ThrottlingException:http://internal…`,
|
|
71
|
+
* `com.amazon.coral#ValidationException`) that is stripped here so the code is the bare exception
|
|
72
|
+
* name — which is what a consumer matches on and what the corpus asserts is preserved verbatim.
|
|
73
|
+
*
|
|
74
|
+
* Read off the FULL body, before any truncation, for the same reason `errors.ts` states: a cap
|
|
75
|
+
* applied first slices away exactly the field a consumer wants.
|
|
76
|
+
*/
|
|
77
|
+
export declare function bedrockErrorCode(headers: Headers, body: string): string | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Re-exported from `errors.ts`, where this now lives (T2 carry).
|
|
80
|
+
*
|
|
81
|
+
* It was written here because the gap it closes was found here — `scanForSecrets` is pattern-based,
|
|
82
|
+
* and while it does know `AKIA…`/`ASIA…` access key IDS, no pattern can match a SECRET access key
|
|
83
|
+
* (forty base64-ish characters) without matching arbitrary prose, so one echoed back by an endpoint
|
|
84
|
+
* survived verbatim into `ProviderError.message`. But nothing about "the pattern scanner cannot have
|
|
85
|
+
* a pattern for MY family's shapeless credential" is Bedrock-specific, and the next family to notice
|
|
86
|
+
* would have written a second copy. The shared normalizer takes a per-request `secrets` list now; this name stays so the
|
|
87
|
+
* lane's own fixtures and any external caller keep working.
|
|
88
|
+
*/
|
|
89
|
+
export { redactCredentialMaterial } from "../../errors.js";
|
|
90
|
+
/** The five-way taxonomy from the HTTP status (the frozen normalizer's job), with Bedrock's own code layered on. */
|
|
91
|
+
export declare function normalizeBedrockError(status: number, headers: Headers, body: string, secrets?: readonly string[]): ProviderError;
|
|
92
|
+
type BedrockBlock = Record<string, unknown>;
|
|
93
|
+
/**
|
|
94
|
+
* Winter's message list -> Bedrock's `messages`.
|
|
95
|
+
*
|
|
96
|
+
* TWO SHAPE RULES BEDROCK ENFORCES AND WINTER'S UNION DOES NOT: roles are only `user` and
|
|
97
|
+
* `assistant` (a `tool` message becomes a `user` message carrying `toolResult` blocks, which is
|
|
98
|
+
* Bedrock's own convention), and the two must strictly ALTERNATE. Consecutive same-role messages are
|
|
99
|
+
* merged by concatenating their content, which is lossless — the alternative, sending them as-is, is
|
|
100
|
+
* a `ValidationException` naming nothing the caller can act on.
|
|
101
|
+
*/
|
|
102
|
+
export declare function toBedrockMessages(messages: readonly ProviderMessageLike[]): Array<{
|
|
103
|
+
role: "user" | "assistant";
|
|
104
|
+
content: BedrockBlock[];
|
|
105
|
+
}>;
|
|
106
|
+
export interface BedrockRequestBody {
|
|
107
|
+
messages: Array<{
|
|
108
|
+
role: string;
|
|
109
|
+
content: BedrockBlock[];
|
|
110
|
+
}>;
|
|
111
|
+
system?: Array<{
|
|
112
|
+
text: string;
|
|
113
|
+
}>;
|
|
114
|
+
inferenceConfig?: BedrockBlock;
|
|
115
|
+
toolConfig?: BedrockBlock;
|
|
116
|
+
additionalModelRequestFields?: BedrockBlock;
|
|
117
|
+
}
|
|
118
|
+
/** Builds the shared Converse/ConverseStream body. Every refusal this can raise happens before a socket is opened. */
|
|
119
|
+
export declare function buildConverseBody(req: TurnRequest, descriptor: WinterModelDescriptor | undefined, mappedEffort: string | undefined): BedrockRequestBody;
|
|
120
|
+
/**
|
|
121
|
+
* WS-13 §8.2: map onto the model's VERIFIED vocabulary, or refuse BEFORE a request is sent.
|
|
122
|
+
*
|
|
123
|
+
* Standalone rather than a method so `streamTurn`'s pre-request check and the frozen
|
|
124
|
+
* `ProviderAdapter.mapEffort` seam are provably the SAME rule — a second copy is exactly how an
|
|
125
|
+
* adapter comes to refuse a selection at one door and send it at another.
|
|
126
|
+
*/
|
|
127
|
+
export declare function mapBedrockEffort(effort: TurnRequest["effort"], model: WinterModelDescriptor): {
|
|
128
|
+
ok: true;
|
|
129
|
+
value: unknown;
|
|
130
|
+
} | {
|
|
131
|
+
ok: false;
|
|
132
|
+
reason: string;
|
|
133
|
+
};
|
|
134
|
+
export interface BedrockAdapter extends ProviderAdapter {
|
|
135
|
+
/** The raw `ListFoundationModels` rows, including `responseStreamingSupported` — the input a host needs to build `BedrockAdapterOptions.streaming`. */
|
|
136
|
+
listFoundationModels(ctx: DiscoveryContext): Promise<Array<{
|
|
137
|
+
modelId: string;
|
|
138
|
+
modelName?: string;
|
|
139
|
+
inputModalities?: string[];
|
|
140
|
+
responseStreamingSupported?: boolean;
|
|
141
|
+
}>>;
|
|
142
|
+
}
|
|
143
|
+
export declare function createBedrockConverseAdapter(options: BedrockAdapterOptions): BedrockAdapter;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CRC-32 of `bytes`, as an unsigned 32-bit number.
|
|
3
|
+
*
|
|
4
|
+
* `seed` carries a running CRC so a message can be checksummed across the buffers it arrived in
|
|
5
|
+
* without concatenating them first — which matters here because an event-stream frame's message CRC
|
|
6
|
+
* covers everything before it, and that span is routinely megabytes for an image-bearing turn.
|
|
7
|
+
* Passing a previous result back in continues the same computation exactly.
|
|
8
|
+
*/
|
|
9
|
+
export declare function crc32(bytes: Uint8Array, seed?: number): number;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ProviderContext } from "../../types.js";
|
|
2
|
+
import type { AwsSigningCredentials } from "./sigv4.js";
|
|
3
|
+
/**
|
|
4
|
+
* The marker that distinguishes "no credential is configured or present" from "a credential was
|
|
5
|
+
* rejected".
|
|
6
|
+
*
|
|
7
|
+
* Both are `code: "auth"` — they are the same taxonomy branch — but they are DIFFERENT ANSWERS to
|
|
8
|
+
* `validateCredential`, and telling a user their key is invalid when they never configured one sends
|
|
9
|
+
* them to debug the wrong thing entirely. It rides `providerCode` because that field is exactly "a
|
|
10
|
+
* finer, machine-readable code beneath the coarse taxonomy", and it is Winter-namespaced so it can
|
|
11
|
+
* never collide with a code AWS returns.
|
|
12
|
+
*/
|
|
13
|
+
export declare const WINTER_CREDENTIAL_MISSING = "WinterCredentialMissing";
|
|
14
|
+
/**
|
|
15
|
+
* Resolves the context's credential ref into AWS signing material.
|
|
16
|
+
*
|
|
17
|
+
* EVERY FAILURE MESSAGE IS BUILT FROM A LOCATOR, never from a value: `redactRef` renders the ref
|
|
18
|
+
* (which is addressing information and is what makes the message actionable) and `redactMaterial`
|
|
19
|
+
* renders a wrong-kind material as `***(kind)`. A credential error message is one of the most
|
|
20
|
+
* reliably-logged strings in any system.
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolveAwsCredentials(ctx: ProviderContext): Promise<AwsSigningCredentials>;
|
|
23
|
+
/**
|
|
24
|
+
* The region this connection signs for.
|
|
25
|
+
*
|
|
26
|
+
* A HARD REQUIREMENT with no default, and that is a security property rather than pedantry: the
|
|
27
|
+
* region is part of the credential SCOPE, so a wrong one is not a routing mistake but a signature
|
|
28
|
+
* that will not verify — and a silent `us-east-1` default would send a European operator's requests,
|
|
29
|
+
* and their data, to a jurisdiction they never chose. R6-16 puts the region in the connection
|
|
30
|
+
* profile; absent, the session refuses to start rather than guessing.
|
|
31
|
+
*/
|
|
32
|
+
export declare function requireRegion(ctx: ProviderContext): string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS's own documented ceilings: 16 MiB per message, 128 KiB of headers. Enforced rather than
|
|
3
|
+
* assumed — `total length` is attacker-controlled in the only sense that matters (it is four bytes
|
|
4
|
+
* off a socket), and a decoder that honoured a 4 GiB length would buffer until the process died.
|
|
5
|
+
* `boundedFetch`'s `maxBodyBytes` bounds the WHOLE response; this bounds one frame.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MAX_EVENT_STREAM_MESSAGE_BYTES: number;
|
|
8
|
+
export declare const MAX_EVENT_STREAM_HEADER_BYTES: number;
|
|
9
|
+
export type EventStreamDecodeErrorCode = "prelude-crc" | "message-crc" | "length" | "header" | "limit";
|
|
10
|
+
/** A malformed frame. Carries a CODE rather than only a message so the adapter can normalize it without matching on prose. */
|
|
11
|
+
export declare class EventStreamDecodeError extends Error {
|
|
12
|
+
readonly code: EventStreamDecodeErrorCode;
|
|
13
|
+
constructor(code: EventStreamDecodeErrorCode, message: string);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A decoded header value.
|
|
17
|
+
*
|
|
18
|
+
* Every AWS header type is decoded, not just the string type Bedrock uses in practice, and that is a
|
|
19
|
+
* robustness decision rather than completeness for its own sake: header parsing is POSITIONAL, so an
|
|
20
|
+
* unrecognised value type has no length and the parser cannot skip past it — one unexpected type
|
|
21
|
+
* byte would desynchronise the rest of the header block and every frame after it. Decoding all ten
|
|
22
|
+
* means an unexpected type is carried, not fatal.
|
|
23
|
+
*/
|
|
24
|
+
export type EventStreamHeaderValue = boolean | number | bigint | string | Uint8Array;
|
|
25
|
+
export interface EventStreamMessage {
|
|
26
|
+
/** Header names are used verbatim (`:message-type`, `:event-type`, `:content-type`) — AWS's are case-sensitive and colon-prefixed. */
|
|
27
|
+
headers: Record<string, EventStreamHeaderValue>;
|
|
28
|
+
payload: Uint8Array;
|
|
29
|
+
}
|
|
30
|
+
export interface EventStreamDecoder {
|
|
31
|
+
/** Feeds bytes in; returns every message those bytes COMPLETED, in order. Throws `EventStreamDecodeError` on a malformed frame. */
|
|
32
|
+
push(chunk: Uint8Array): EventStreamMessage[];
|
|
33
|
+
/** Bytes held back as a partial frame. `> 0` at end-of-stream means the response was truncated. */
|
|
34
|
+
pending(): number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* An incremental event-stream decoder.
|
|
38
|
+
*
|
|
39
|
+
* BUFFERS BY CONCATENATION, deliberately, rather than keeping a chunk list and a cursor. A frame is
|
|
40
|
+
* bounded at 16 MiB and the common one is a few hundred bytes, so the copy is not where a streaming
|
|
41
|
+
* turn spends its time — and the alternative (a rope with cross-chunk reads) is exactly the kind of
|
|
42
|
+
* index arithmetic that produces a decoder which works until a frame lands on a chunk boundary in
|
|
43
|
+
* the one place nobody tested. `eventstream.test.ts` feeds a frame BYTE BY BYTE for that reason.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createEventStreamDecoder(): EventStreamDecoder;
|
|
46
|
+
/** The `:message-type` values AWS defines. `event` is a stream item; the other two are terminal failures. */
|
|
47
|
+
export type EventStreamMessageType = "event" | "exception" | "error";
|
|
48
|
+
/** A header read as a string, or `undefined` when absent or of another type. The accessor every caller should use — a header's TYPE is wire data, not an assumption. */
|
|
49
|
+
export declare function stringHeader(message: EventStreamMessage, name: string): string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* The frame's `:message-type`, defaulting to `event`.
|
|
52
|
+
*
|
|
53
|
+
* The default is the documented behaviour rather than leniency: AWS's own decoders treat an absent
|
|
54
|
+
* `:message-type` as an event, and Bedrock's happy path is entirely events.
|
|
55
|
+
*/
|
|
56
|
+
export declare function messageType(message: EventStreamMessage): EventStreamMessageType;
|
|
57
|
+
/**
|
|
58
|
+
* The frame's payload as parsed JSON, or `undefined` when it is not JSON at all.
|
|
59
|
+
*
|
|
60
|
+
* `undefined` rather than a throw, because the two cases have different meanings to the adapter: a
|
|
61
|
+
* frame whose payload is unparseable is a `bad_request`-class provider failure (corpus case
|
|
62
|
+
* `error-malformed`), while an EMPTY payload is legitimate — `contentBlockStop` and the exception
|
|
63
|
+
* frames carry nothing.
|
|
64
|
+
*/
|
|
65
|
+
export declare function jsonPayload(message: EventStreamMessage): Record<string, unknown> | undefined;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { BEDROCK_ADAPTER_ID, BEDROCK_ADAPTER_VERSION, bedrockErrorCode, buildConverseBody, createBedrockConverseAdapter, mapBedrockEffort, normalizeBedrockError, toBedrockMessages, } from "./converse.js";
|
|
2
|
+
export type { BedrockAdapter, BedrockAdapterOptions, BedrockRequestBody } from "./converse.js";
|
|
3
|
+
export { requireRegion, resolveAwsCredentials } from "./credentials.js";
|
|
4
|
+
export { EventStreamDecodeError, MAX_EVENT_STREAM_HEADER_BYTES, MAX_EVENT_STREAM_MESSAGE_BYTES, createEventStreamDecoder, jsonPayload, messageType, stringHeader, } from "./eventstream.js";
|
|
5
|
+
export type { EventStreamDecodeErrorCode, EventStreamDecoder, EventStreamHeaderValue, EventStreamMessage, EventStreamMessageType } from "./eventstream.js";
|
|
6
|
+
export { crc32 } from "./crc32.js";
|
|
7
|
+
export { BEDROCK_SERVICE, SIGV4_ALGORITHM, awsUriEncode, buildCanonicalRequest, buildStringToSign, canonicalQuery, canonicalUri, computeSignature, amzDate, parseAuthorization, sha256Hex, signRequest, signingKey, } from "./sigv4.js";
|
|
8
|
+
export type { AwsSigningCredentials, CanonicalRequestInput, ParsedAuthorization, SignRequestInput, SignedRequest } from "./sigv4.js";
|