@tensorcost/sdk 0.3.1 → 0.5.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/README.md +61 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/bedrock.d.ts +48 -0
- package/dist/providers/bedrock.d.ts.map +1 -0
- package/dist/providers/bedrock.js +277 -0
- package/dist/providers/bedrock.js.map +1 -0
- package/dist/providers/detect.d.ts +9 -3
- package/dist/providers/detect.d.ts.map +1 -1
- package/dist/providers/detect.js +24 -6
- package/dist/providers/detect.js.map +1 -1
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +1 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/wrap.d.ts +5 -0
- package/dist/wrap.d.ts.map +1 -1
- package/dist/wrap.js +22 -1
- package/dist/wrap.js.map +1 -1
- package/package.json +12 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @tensorcost/sdk
|
|
2
2
|
|
|
3
|
-
One-line wrapper SDK for TensorCost — fire-and-forget LLM observability for OpenAI and
|
|
3
|
+
One-line wrapper SDK for TensorCost — fire-and-forget LLM observability for OpenAI, Anthropic, and AWS Bedrock clients in Node.js.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -84,7 +84,7 @@ const resp = await client.chat.completions.create({
|
|
|
84
84
|
});
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
`wrap()` throws `TensorCostConfigError` at
|
|
87
|
+
`wrap()` throws `TensorCostConfigError` at `wrap()` time if `appliedMode: true` and neither `proxyUrl` nor `TENSORCOST_PROXY_URL` is set. AWS Bedrock is not supported in applied mode — SigV4 signing happens inside the AWS SDK before the proxy layer can intercept it; passing a Bedrock client with `appliedMode: true` throws `TensorCostConfigError` immediately. Observe-only mode works fine for Bedrock.
|
|
88
88
|
|
|
89
89
|
See [`docs/features/inference-proxy-applied-mode.md`](../../docs/features/inference-proxy-applied-mode.md) for the proxy-side design.
|
|
90
90
|
|
|
@@ -191,15 +191,72 @@ Only metadata — never prompt or completion content:
|
|
|
191
191
|
- Status (`success` / `error`) and error class/message on failure
|
|
192
192
|
- A correlation UUID
|
|
193
193
|
|
|
194
|
+
## AWS Bedrock (observe-only)
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
import {
|
|
198
|
+
BedrockRuntimeClient,
|
|
199
|
+
InvokeModelCommand,
|
|
200
|
+
} from "@aws-sdk/client-bedrock-runtime";
|
|
201
|
+
import { wrap } from "@tensorcost/sdk";
|
|
202
|
+
|
|
203
|
+
// The only change: wrap() before passing the client to the rest of your code.
|
|
204
|
+
const client = wrap(
|
|
205
|
+
new BedrockRuntimeClient({ region: process.env.AWS_REGION ?? "us-east-1" }),
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
// Everything else is unchanged.
|
|
209
|
+
const response = await client.send(
|
|
210
|
+
new InvokeModelCommand({
|
|
211
|
+
modelId: "anthropic.claude-3-haiku-20240307-v1:0",
|
|
212
|
+
body: JSON.stringify({
|
|
213
|
+
anthropic_version: "bedrock-2023-05-31",
|
|
214
|
+
max_tokens: 64,
|
|
215
|
+
messages: [{ role: "user", content: "What is 2 + 2?" }],
|
|
216
|
+
}),
|
|
217
|
+
contentType: "application/json",
|
|
218
|
+
accept: "application/json",
|
|
219
|
+
}),
|
|
220
|
+
);
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
The SDK registers a Smithy middleware on `client.middlewareStack` that intercepts every `client.send()` call and emits a fire-and-forget observation with the model id, token counts, latency, and status. Your code is otherwise unchanged.
|
|
224
|
+
|
|
225
|
+
### Supported commands
|
|
226
|
+
|
|
227
|
+
| Command | Operation recorded | Token counts |
|
|
228
|
+
|---|---|---|
|
|
229
|
+
| `InvokeModelCommand` | `bedrock.invoke_model` | Parsed from response body (Anthropic-on-Bedrock and Nova/Titan shapes) |
|
|
230
|
+
| `ConverseCommand` | `bedrock.converse` | Read from `response.usage.inputTokens / outputTokens` |
|
|
231
|
+
| `InvokeModelWithResponseStreamCommand` | `bedrock.invoke_model_stream` | Not yet — placeholder observation with `null` tokens |
|
|
232
|
+
| `ConverseStreamCommand` | `bedrock.converse_stream` | Not yet — placeholder observation with `null` tokens |
|
|
233
|
+
|
|
234
|
+
Per-chunk token accounting for streaming commands is a follow-up workstream. The placeholder observations record latency and success/error status, which is enough for alerting and anomaly detection. Token cost attribution will arrive once per-model pricing is wired in on the backend.
|
|
235
|
+
|
|
236
|
+
### Applied mode
|
|
237
|
+
|
|
238
|
+
Applied mode (`{ appliedMode: true }`) is not supported for Bedrock. AWS Bedrock uses SigV4 request signing inside the AWS SDK before our middleware sees the request, so we cannot intercept and re-route it the way we do for OpenAI/Anthropic HTTP-Bearer clients. Calling `wrap(bedrockClient, { appliedMode: true })` throws `TensorCostConfigError` immediately.
|
|
239
|
+
|
|
240
|
+
### Installation
|
|
241
|
+
|
|
242
|
+
`@aws-sdk/client-bedrock-runtime` is an optional peer dependency — you only need it if you're using Bedrock. The SDK will not pull it in for OpenAI/Anthropic-only users.
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
npm install @aws-sdk/client-bedrock-runtime
|
|
246
|
+
# or
|
|
247
|
+
pnpm add @aws-sdk/client-bedrock-runtime
|
|
248
|
+
```
|
|
249
|
+
|
|
194
250
|
## Currently supported
|
|
195
251
|
|
|
196
252
|
- OpenAI (`openai` >= 4.x) — `chat.completions.create`, `completions.create`
|
|
197
253
|
- Anthropic (`@anthropic-ai/sdk` >= 0.x) — `messages.create`
|
|
254
|
+
- AWS Bedrock (`@aws-sdk/client-bedrock-runtime` >= 3.x) — `InvokeModelCommand`, `ConverseCommand` (observe-only)
|
|
198
255
|
|
|
199
256
|
## Coming soon
|
|
200
257
|
|
|
201
|
-
-
|
|
202
|
-
- Streaming
|
|
258
|
+
- Azure OpenAI, Vertex
|
|
259
|
+
- Streaming token accounting for Bedrock (`InvokeModelWithResponseStreamCommand`, `ConverseStreamCommand`)
|
|
203
260
|
- Tool / function calling (multi-call trace stitching)
|
|
204
261
|
|
|
205
262
|
## License
|
package/dist/index.js
CHANGED
|
@@ -2,5 +2,5 @@ export { wrap } from "./wrap.js";
|
|
|
2
2
|
export { MissingConfigError, TensorCostConfigError } from "./config.js";
|
|
3
3
|
export { UnsupportedClientError } from "./providers/detect.js";
|
|
4
4
|
export { TensorCostError, TensorCostNetworkError, TensorCostTimeoutError, TensorCostProxyError, TensorCostQuotaError, TensorCostProviderError, } from "./errors.js";
|
|
5
|
-
export const version = "0.4.0";
|
|
5
|
+
export const version = "0.4.0"; // Bedrock observe-only support added
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AAarB,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AAarB,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,qCAAqC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS Bedrock observe-only client wrapping.
|
|
3
|
+
*
|
|
4
|
+
* Bedrock differs fundamentally from OpenAI and Anthropic: requests go through
|
|
5
|
+
* the AWS Smithy client's `send()` method rather than named sub-resource methods
|
|
6
|
+
* like `chat.completions.create`. The Smithy client also handles SigV4 signing
|
|
7
|
+
* internally, so we cannot intercept the HTTP layer with a baseURL redirect the
|
|
8
|
+
* way applied mode does for the HTTP-Bearer providers.
|
|
9
|
+
*
|
|
10
|
+
* What we CAN do: register a Smithy middleware on `client.middlewareStack` that
|
|
11
|
+
* wraps the inner `next()` handler. Every `client.send(command)` call passes
|
|
12
|
+
* through the middleware stack, so this gives us a clean before/after hook with
|
|
13
|
+
* access to the command input and the resolved output.
|
|
14
|
+
*
|
|
15
|
+
* Supported commands (non-streaming):
|
|
16
|
+
* - InvokeModelCommand → operation "bedrock.invoke_model"
|
|
17
|
+
* - ConverseCommand → operation "bedrock.converse"
|
|
18
|
+
*
|
|
19
|
+
* Streaming commands (token accounting deferred):
|
|
20
|
+
* - InvokeModelWithResponseStreamCommand → operation "bedrock.invoke_model_stream"
|
|
21
|
+
* - ConverseStreamCommand → operation "bedrock.converse_stream"
|
|
22
|
+
*
|
|
23
|
+
* For streaming commands we emit an observation with input_tokens=null,
|
|
24
|
+
* output_tokens=null, and a note in error_message that per-chunk token
|
|
25
|
+
* accounting is not yet implemented. The observation still records latency
|
|
26
|
+
* and success/error status — enough for cost attribution once per-model
|
|
27
|
+
* pricing and a token estimator are wired in.
|
|
28
|
+
*
|
|
29
|
+
* Token-count extraction:
|
|
30
|
+
* Bedrock does not standardise usage across model families. We probe three
|
|
31
|
+
* common shapes in order:
|
|
32
|
+
* 1. Anthropic-on-Bedrock (InvokeModel): body JSON → usage.input_tokens / output_tokens
|
|
33
|
+
* 2. Amazon Nova / Titan (InvokeModel): body JSON → usage.inputTokens / outputTokens
|
|
34
|
+
* 3. Converse API (any model): response.usage.inputTokens / outputTokens
|
|
35
|
+
* If none match we emit 0/0 and log a warning so operators can report gaps.
|
|
36
|
+
*
|
|
37
|
+
* Applied mode:
|
|
38
|
+
* Not supported. SigV4 signing happens inside the AWS SDK before our
|
|
39
|
+
* middleware sees the request, and the signed URL/headers are region-specific.
|
|
40
|
+
* wrap(bedrockClient, { appliedMode: true }) throws TensorCostConfigError
|
|
41
|
+
* immediately in wrap.ts (before this module is called).
|
|
42
|
+
*/
|
|
43
|
+
import type { ObservationTransport } from "../transport.js";
|
|
44
|
+
export declare function install(client: unknown, transport: ObservationTransport, tenantId: string | null, environment: string | null, connectionId: string | null): void;
|
|
45
|
+
export declare const __test__: {
|
|
46
|
+
MIDDLEWARE_NAME: string;
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=bedrock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bedrock.d.ts","sourceRoot":"","sources":["../../src/providers/bedrock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAgK5D,wBAAgB,OAAO,CACrB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,oBAAoB,EAC/B,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,WAAW,EAAE,MAAM,GAAG,IAAI,EAC1B,YAAY,EAAE,MAAM,GAAG,IAAI,GAC1B,IAAI,CAoIN;AAED,eAAO,MAAM,QAAQ;;CAAsB,CAAC"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS Bedrock observe-only client wrapping.
|
|
3
|
+
*
|
|
4
|
+
* Bedrock differs fundamentally from OpenAI and Anthropic: requests go through
|
|
5
|
+
* the AWS Smithy client's `send()` method rather than named sub-resource methods
|
|
6
|
+
* like `chat.completions.create`. The Smithy client also handles SigV4 signing
|
|
7
|
+
* internally, so we cannot intercept the HTTP layer with a baseURL redirect the
|
|
8
|
+
* way applied mode does for the HTTP-Bearer providers.
|
|
9
|
+
*
|
|
10
|
+
* What we CAN do: register a Smithy middleware on `client.middlewareStack` that
|
|
11
|
+
* wraps the inner `next()` handler. Every `client.send(command)` call passes
|
|
12
|
+
* through the middleware stack, so this gives us a clean before/after hook with
|
|
13
|
+
* access to the command input and the resolved output.
|
|
14
|
+
*
|
|
15
|
+
* Supported commands (non-streaming):
|
|
16
|
+
* - InvokeModelCommand → operation "bedrock.invoke_model"
|
|
17
|
+
* - ConverseCommand → operation "bedrock.converse"
|
|
18
|
+
*
|
|
19
|
+
* Streaming commands (token accounting deferred):
|
|
20
|
+
* - InvokeModelWithResponseStreamCommand → operation "bedrock.invoke_model_stream"
|
|
21
|
+
* - ConverseStreamCommand → operation "bedrock.converse_stream"
|
|
22
|
+
*
|
|
23
|
+
* For streaming commands we emit an observation with input_tokens=null,
|
|
24
|
+
* output_tokens=null, and a note in error_message that per-chunk token
|
|
25
|
+
* accounting is not yet implemented. The observation still records latency
|
|
26
|
+
* and success/error status — enough for cost attribution once per-model
|
|
27
|
+
* pricing and a token estimator are wired in.
|
|
28
|
+
*
|
|
29
|
+
* Token-count extraction:
|
|
30
|
+
* Bedrock does not standardise usage across model families. We probe three
|
|
31
|
+
* common shapes in order:
|
|
32
|
+
* 1. Anthropic-on-Bedrock (InvokeModel): body JSON → usage.input_tokens / output_tokens
|
|
33
|
+
* 2. Amazon Nova / Titan (InvokeModel): body JSON → usage.inputTokens / outputTokens
|
|
34
|
+
* 3. Converse API (any model): response.usage.inputTokens / outputTokens
|
|
35
|
+
* If none match we emit 0/0 and log a warning so operators can report gaps.
|
|
36
|
+
*
|
|
37
|
+
* Applied mode:
|
|
38
|
+
* Not supported. SigV4 signing happens inside the AWS SDK before our
|
|
39
|
+
* middleware sees the request, and the signed URL/headers are region-specific.
|
|
40
|
+
* wrap(bedrockClient, { appliedMode: true }) throws TensorCostConfigError
|
|
41
|
+
* immediately in wrap.ts (before this module is called).
|
|
42
|
+
*/
|
|
43
|
+
import { randomUUID } from "node:crypto";
|
|
44
|
+
const SDK_VERSION = "tensorcost-node/0.4.0";
|
|
45
|
+
// Marker placed on the middleware to prevent double-registration when
|
|
46
|
+
// wrap() is called twice on the same client.
|
|
47
|
+
const MIDDLEWARE_NAME = "__tensorcost_bedrock_observe__";
|
|
48
|
+
// ── Helpers ───────────────────────────────────────────────────────────────────
|
|
49
|
+
function nowIso() {
|
|
50
|
+
return new Date().toISOString();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Map a Smithy commandName string to the Operation we record in the
|
|
54
|
+
* observation envelope. Falls through to "bedrock.invoke_model" for
|
|
55
|
+
* unknown command names so we always record something.
|
|
56
|
+
*/
|
|
57
|
+
function commandToOperation(commandName) {
|
|
58
|
+
switch (commandName) {
|
|
59
|
+
case "InvokeModelCommand":
|
|
60
|
+
return { operation: "bedrock.invoke_model", isStreaming: false };
|
|
61
|
+
case "ConverseCommand":
|
|
62
|
+
return { operation: "bedrock.converse", isStreaming: false };
|
|
63
|
+
case "InvokeModelWithResponseStreamCommand":
|
|
64
|
+
return { operation: "bedrock.invoke_model_stream", isStreaming: true };
|
|
65
|
+
case "ConverseStreamCommand":
|
|
66
|
+
return { operation: "bedrock.converse_stream", isStreaming: true };
|
|
67
|
+
default:
|
|
68
|
+
// Unknown Bedrock command — record it under invoke_model so it still
|
|
69
|
+
// shows up in the dashboard rather than being silently dropped.
|
|
70
|
+
return { operation: "bedrock.invoke_model", isStreaming: false };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Extract token counts from an InvokeModel response body.
|
|
75
|
+
*
|
|
76
|
+
* The response body is a Uint8Array containing a JSON document whose
|
|
77
|
+
* shape depends on the model family. We try two common shapes and fall
|
|
78
|
+
* back to null/null rather than throwing.
|
|
79
|
+
*/
|
|
80
|
+
function extractInvokeModelTokens(output) {
|
|
81
|
+
// The `body` field is a Uint8Array (or Buffer in Node).
|
|
82
|
+
const rawBody = output.body;
|
|
83
|
+
if (!rawBody)
|
|
84
|
+
return { input: null, output: null };
|
|
85
|
+
let parsed;
|
|
86
|
+
try {
|
|
87
|
+
const text = typeof rawBody === "string"
|
|
88
|
+
? rawBody
|
|
89
|
+
: Buffer.from(rawBody).toString("utf-8");
|
|
90
|
+
parsed = JSON.parse(text);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
console.warn("tensorcost: could not parse Bedrock InvokeModel response body for token counts");
|
|
94
|
+
return { input: null, output: null };
|
|
95
|
+
}
|
|
96
|
+
const usage = parsed.usage;
|
|
97
|
+
if (!usage || typeof usage !== "object") {
|
|
98
|
+
console.warn("tensorcost: Bedrock InvokeModel response has no usage field — " +
|
|
99
|
+
"token counts will be missing. If this is a new model family, " +
|
|
100
|
+
"please open an issue at https://github.com/vaadhlabs/tensorcost.");
|
|
101
|
+
return { input: null, output: null };
|
|
102
|
+
}
|
|
103
|
+
// Anthropic-on-Bedrock: usage.input_tokens / output_tokens
|
|
104
|
+
if (typeof usage.input_tokens === "number" ||
|
|
105
|
+
typeof usage.output_tokens === "number") {
|
|
106
|
+
return {
|
|
107
|
+
input: typeof usage.input_tokens === "number" ? usage.input_tokens : null,
|
|
108
|
+
output: typeof usage.output_tokens === "number" ? usage.output_tokens : null,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
// Amazon Nova / Titan: usage.inputTokens / outputTokens
|
|
112
|
+
if (typeof usage.inputTokens === "number" ||
|
|
113
|
+
typeof usage.outputTokens === "number") {
|
|
114
|
+
return {
|
|
115
|
+
input: typeof usage.inputTokens === "number" ? usage.inputTokens : null,
|
|
116
|
+
output: typeof usage.outputTokens === "number" ? usage.outputTokens : null,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
console.warn("tensorcost: Bedrock InvokeModel usage shape not recognised — " +
|
|
120
|
+
"token counts will be missing. Known shapes: " +
|
|
121
|
+
"Anthropic (usage.input_tokens/output_tokens), " +
|
|
122
|
+
"Nova/Titan (usage.inputTokens/outputTokens).");
|
|
123
|
+
return { input: null, output: null };
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Extract token counts from a Converse API response.
|
|
127
|
+
*
|
|
128
|
+
* The Converse API has a standardised usage block regardless of model
|
|
129
|
+
* family: response.usage.inputTokens / outputTokens.
|
|
130
|
+
*/
|
|
131
|
+
function extractConverseTokens(output) {
|
|
132
|
+
const usage = output.usage;
|
|
133
|
+
if (!usage || typeof usage !== "object") {
|
|
134
|
+
return { input: null, output: null };
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
input: typeof usage.inputTokens === "number" ? usage.inputTokens : null,
|
|
138
|
+
output: typeof usage.outputTokens === "number" ? usage.outputTokens : null,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
// ── Public install() ──────────────────────────────────────────────────────────
|
|
142
|
+
export function install(client, transport, tenantId, environment, connectionId) {
|
|
143
|
+
if (!client || typeof client !== "object")
|
|
144
|
+
return;
|
|
145
|
+
const c = client;
|
|
146
|
+
const middlewareStack = c.middlewareStack;
|
|
147
|
+
if (!middlewareStack || typeof middlewareStack.add !== "function") {
|
|
148
|
+
console.warn("tensorcost: BedrockRuntimeClient does not expose a middlewareStack — " +
|
|
149
|
+
"observations will not be recorded. Is @aws-sdk/client-bedrock-runtime >= 3.x installed?");
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
// Guard against double-registration when wrap() is called twice on the
|
|
153
|
+
// same client. The identify() API is available from SDK v3 onwards.
|
|
154
|
+
if (typeof middlewareStack.identify === "function") {
|
|
155
|
+
const existing = middlewareStack.identify();
|
|
156
|
+
const alreadyInstalled = existing.some(([name]) => name === MIDDLEWARE_NAME);
|
|
157
|
+
if (alreadyInstalled)
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const middleware = (next, context) => async (args) => {
|
|
161
|
+
const startedAt = performance.now();
|
|
162
|
+
const requestAt = nowIso();
|
|
163
|
+
const correlationId = randomUUID();
|
|
164
|
+
// modelId lives in the command input for both InvokeModel and Converse.
|
|
165
|
+
const modelId = typeof args.input.modelId === "string" ? args.input.modelId : "unknown";
|
|
166
|
+
const { operation, isStreaming } = commandToOperation(context.commandName);
|
|
167
|
+
const commonFields = {
|
|
168
|
+
sdk_version: SDK_VERSION,
|
|
169
|
+
provider: "bedrock",
|
|
170
|
+
model: modelId,
|
|
171
|
+
operation,
|
|
172
|
+
request_at: requestAt,
|
|
173
|
+
correlation_id: correlationId,
|
|
174
|
+
tenant_id: tenantId,
|
|
175
|
+
...(environment !== null ? { environment } : {}),
|
|
176
|
+
...(connectionId !== null ? { connection_id: connectionId } : {}),
|
|
177
|
+
};
|
|
178
|
+
// Streaming commands: we cannot aggregate tokens across chunks without
|
|
179
|
+
// collecting the full stream. Emit a placeholder observation now —
|
|
180
|
+
// per-chunk token accounting is a follow-up workstream.
|
|
181
|
+
if (isStreaming) {
|
|
182
|
+
let status = "success";
|
|
183
|
+
let errorMessage = null;
|
|
184
|
+
let result;
|
|
185
|
+
try {
|
|
186
|
+
result = await next(args);
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
status = "error";
|
|
190
|
+
errorMessage = `${err.name}: ${err.message}`;
|
|
191
|
+
const latencyMs = performance.now() - startedAt;
|
|
192
|
+
const obs = {
|
|
193
|
+
...commonFields,
|
|
194
|
+
response_at: nowIso(),
|
|
195
|
+
input_tokens: null,
|
|
196
|
+
output_tokens: null,
|
|
197
|
+
cost_usd_cents: null,
|
|
198
|
+
status: "error",
|
|
199
|
+
error_message: errorMessage,
|
|
200
|
+
};
|
|
201
|
+
try {
|
|
202
|
+
transport.post(obs);
|
|
203
|
+
}
|
|
204
|
+
catch { /* fail-open */ }
|
|
205
|
+
throw err;
|
|
206
|
+
}
|
|
207
|
+
const latencyMs = performance.now() - startedAt;
|
|
208
|
+
void latencyMs; // recorded via response_at timestamp difference
|
|
209
|
+
const obs = {
|
|
210
|
+
...commonFields,
|
|
211
|
+
response_at: nowIso(),
|
|
212
|
+
input_tokens: null,
|
|
213
|
+
output_tokens: null,
|
|
214
|
+
cost_usd_cents: null,
|
|
215
|
+
status,
|
|
216
|
+
// Signal to operators that this is a streaming placeholder, not a gap.
|
|
217
|
+
error_message: "streaming: per-chunk token accounting not yet implemented",
|
|
218
|
+
};
|
|
219
|
+
try {
|
|
220
|
+
transport.post(obs);
|
|
221
|
+
}
|
|
222
|
+
catch { /* fail-open */ }
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
// Non-streaming path: InvokeModel + Converse.
|
|
226
|
+
try {
|
|
227
|
+
const result = await next(args);
|
|
228
|
+
const latencyMs = performance.now() - startedAt;
|
|
229
|
+
void latencyMs;
|
|
230
|
+
let input = null;
|
|
231
|
+
let output = null;
|
|
232
|
+
if (operation === "bedrock.converse") {
|
|
233
|
+
({ input, output } = extractConverseTokens(result.output));
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
({ input, output } = extractInvokeModelTokens(result.output));
|
|
237
|
+
}
|
|
238
|
+
const obs = {
|
|
239
|
+
...commonFields,
|
|
240
|
+
response_at: nowIso(),
|
|
241
|
+
input_tokens: input,
|
|
242
|
+
output_tokens: output,
|
|
243
|
+
cost_usd_cents: null,
|
|
244
|
+
status: "success",
|
|
245
|
+
error_message: null,
|
|
246
|
+
};
|
|
247
|
+
try {
|
|
248
|
+
transport.post(obs);
|
|
249
|
+
}
|
|
250
|
+
catch { /* fail-open */ }
|
|
251
|
+
return result;
|
|
252
|
+
}
|
|
253
|
+
catch (err) {
|
|
254
|
+
const obs = {
|
|
255
|
+
...commonFields,
|
|
256
|
+
response_at: nowIso(),
|
|
257
|
+
input_tokens: null,
|
|
258
|
+
output_tokens: null,
|
|
259
|
+
cost_usd_cents: null,
|
|
260
|
+
status: "error",
|
|
261
|
+
error_message: `${err.name}: ${err.message}`,
|
|
262
|
+
};
|
|
263
|
+
try {
|
|
264
|
+
transport.post(obs);
|
|
265
|
+
}
|
|
266
|
+
catch { /* fail-open */ }
|
|
267
|
+
throw err;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
middlewareStack.add(middleware, {
|
|
271
|
+
step: "build",
|
|
272
|
+
name: MIDDLEWARE_NAME,
|
|
273
|
+
priority: "normal",
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
export const __test__ = { MIDDLEWARE_NAME };
|
|
277
|
+
//# sourceMappingURL=bedrock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bedrock.js","sourceRoot":"","sources":["../../src/providers/bedrock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAE5C,sEAAsE;AACtE,6CAA6C;AAC7C,MAAM,eAAe,GAAG,gCAAgC,CAAC;AAmCzD,iFAAiF;AAEjF,SAAS,MAAM;IACb,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,SAAS,kBAAkB,CAAC,WAA+B;IAIzD,QAAQ,WAAW,EAAE,CAAC;QACpB,KAAK,oBAAoB;YACvB,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;QACnE,KAAK,iBAAiB;YACpB,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;QAC/D,KAAK,sCAAsC;YACzC,OAAO,EAAE,SAAS,EAAE,6BAA6B,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;QACzE,KAAK,uBAAu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AW,EAAE,MAAM,EAAE;gBACrB,YAAY,EAAE,KAAK;gBACnB,aAAa,EAAE,MAAM;gBACrB,cAAc,EAAE,IAAI;gBACpB,MAAM,EAAE,SAAS;gBACjB,aAAa,EAAE,IAAI;aACpB,CAAC;YACF,IAAI,CAAC;gBAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC;YACtD,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,GAAG,GAAgB;gBACvB,GAAG,YAAY;gBACf,WAAW,EAAE,MAAM,EAAE;gBACrB,YAAY,EAAE,IAAI;gBAClB,aAAa,EAAE,IAAI;gBACnB,cAAc,EAAE,IAAI;gBACpB,MAAM,EAAE,OAAO;gBACf,aAAa,EAAE,GAAI,GAAa,CAAC,IAAI,KAAM,GAAa,CAAC,OAAO,EAAE;aACnE,CAAC;YACF,IAAI,CAAC;gBAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC;YACtD,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC,CAAC;IAEF,eAAe,CAAC,GAAG,CAAC,UAAU,EAAE;QAC9B,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,eAAe;QACrB,QAAQ,EAAE,QAAQ;KACnB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Provider detection — duck-typed.
|
|
3
3
|
*
|
|
4
|
-
* We avoid importing `openai
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* We avoid importing `openai`, `@anthropic-ai/sdk`, or
|
|
5
|
+
* `@aws-sdk/client-bedrock-runtime` at runtime so that the SDK has zero
|
|
6
|
+
* peer-dep cost when the customer only uses one provider. Detection
|
|
7
|
+
* inspects the shape of the client object instead.
|
|
8
|
+
*
|
|
9
|
+
* Bedrock detection uses the Smithy-generated `config.serviceId` field,
|
|
10
|
+
* which is the most precise available discriminator — it's set by the
|
|
11
|
+
* AWS SDK generator and does not depend on the constructor name (which
|
|
12
|
+
* minifiers can change).
|
|
7
13
|
*/
|
|
8
14
|
import type { Provider } from "../types.js";
|
|
9
15
|
export declare class UnsupportedClientError extends Error {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../src/providers/detect.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../src/providers/detect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,QAAQ,CAiDxD"}
|
package/dist/providers/detect.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Provider detection — duck-typed.
|
|
3
3
|
*
|
|
4
|
-
* We avoid importing `openai
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* We avoid importing `openai`, `@anthropic-ai/sdk`, or
|
|
5
|
+
* `@aws-sdk/client-bedrock-runtime` at runtime so that the SDK has zero
|
|
6
|
+
* peer-dep cost when the customer only uses one provider. Detection
|
|
7
|
+
* inspects the shape of the client object instead.
|
|
8
|
+
*
|
|
9
|
+
* Bedrock detection uses the Smithy-generated `config.serviceId` field,
|
|
10
|
+
* which is the most precise available discriminator — it's set by the
|
|
11
|
+
* AWS SDK generator and does not depend on the constructor name (which
|
|
12
|
+
* minifiers can change).
|
|
7
13
|
*/
|
|
8
14
|
export class UnsupportedClientError extends Error {
|
|
9
15
|
constructor(message) {
|
|
@@ -13,9 +19,20 @@ export class UnsupportedClientError extends Error {
|
|
|
13
19
|
}
|
|
14
20
|
export function detectProvider(client) {
|
|
15
21
|
if (client === null || typeof client !== "object") {
|
|
16
|
-
throw new UnsupportedClientError("tensorcost: wrap() requires an object (an OpenAI or
|
|
22
|
+
throw new UnsupportedClientError("tensorcost: wrap() requires an object (an OpenAI, Anthropic, or BedrockRuntimeClient instance).");
|
|
17
23
|
}
|
|
18
24
|
const c = client;
|
|
25
|
+
// BedrockRuntimeClient (AWS SDK v3 / Smithy): has a `send()` method AND
|
|
26
|
+
// config.serviceId === "Bedrock Runtime". We check this first because
|
|
27
|
+
// Smithy clients have a generic enough shape that the OpenAI/Anthropic
|
|
28
|
+
// checks could theoretically collide on oddly-named properties.
|
|
29
|
+
const hasBedrockShape = typeof c.send === "function" &&
|
|
30
|
+
c.config != null &&
|
|
31
|
+
typeof c.config === "object" &&
|
|
32
|
+
c.config.serviceId === "Bedrock Runtime";
|
|
33
|
+
if (hasBedrockShape) {
|
|
34
|
+
return "bedrock";
|
|
35
|
+
}
|
|
19
36
|
// OpenAI: has chat.completions.create OR completions.create
|
|
20
37
|
const chat = c.chat;
|
|
21
38
|
const chatCompletions = chat && typeof chat === "object" ? chat.completions : undefined;
|
|
@@ -33,7 +50,8 @@ export function detectProvider(client) {
|
|
|
33
50
|
if (hasAnthropicShape) {
|
|
34
51
|
return "anthropic";
|
|
35
52
|
}
|
|
36
|
-
throw new UnsupportedClientError("tensorcost: client does not look like an OpenAI or
|
|
37
|
-
"(missing chat.completions.create / completions.create / messages.create
|
|
53
|
+
throw new UnsupportedClientError("tensorcost: client does not look like an OpenAI, Anthropic, or BedrockRuntimeClient instance " +
|
|
54
|
+
"(missing chat.completions.create / completions.create / messages.create / " +
|
|
55
|
+
"send+config.serviceId='Bedrock Runtime').");
|
|
38
56
|
}
|
|
39
57
|
//# sourceMappingURL=detect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect.js","sourceRoot":"","sources":["../../src/providers/detect.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"detect.js","sourceRoot":"","sources":["../../src/providers/detect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED,MAAM,UAAU,cAAc,CAAC,MAAe;IAC5C,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAClD,MAAM,IAAI,sBAAsB,CAC9B,iGAAiG,CAClG,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,GAAG,MAA6B,CAAC;IAExC,wEAAwE;IACxE,sEAAsE;IACtE,uEAAuE;IACvE,gEAAgE;IAChE,MAAM,eAAe,GACnB,OAAO,CAAC,CAAC,IAAI,KAAK,UAAU;QAC5B,CAAC,CAAC,MAAM,IAAI,IAAI;QAChB,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ;QAC3B,CAAC,CAAC,MAAkC,CAAC,SAAS,KAAK,iBAAiB,CAAC;IAExE,IAAI,eAAe,EAAE,CAAC;QACpB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,4DAA4D;IAC5D,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;IACpB,MAAM,eAAe,GACnB,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;IAClE,MAAM,cAAc,GAClB,CAAC,eAAe,IAAI,OAAO,eAAe,CAAC,MAAM,KAAK,UAAU,CAAC;QACjE,CAAC,CAAC,CAAC,WAAW,IAAI,OAAO,CAAC,CAAC,WAAW,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC;IAEhE,iCAAiC;IACjC,MAAM,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;IAC5B,MAAM,iBAAiB,GACrB,QAAQ,IAAI,OAAO,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC;IAEpD,wEAAwE;IACxE,qEAAqE;IACrE,sEAAsE;IACtE,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,IAAI,iBAAiB,EAAE,CAAC;QACtB,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,MAAM,IAAI,sBAAsB,CAC9B,+FAA+F;QAC7F,4EAA4E;QAC5E,2CAA2C,CAC9C,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,cAAc,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,iBAAiB,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,cAAc,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,iBAAiB,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,eAAe,MAAM,cAAc,CAAC"}
|
package/dist/providers/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,cAAc,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,iBAAiB,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,cAAc,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,iBAAiB,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,eAAe,MAAM,cAAc,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { LifecycleEventCallback } from "./telemetry.js";
|
|
9
9
|
import type { RetryConfig } from "./retry.js";
|
|
10
|
-
export type Provider = "openai" | "anthropic";
|
|
11
|
-
export type Operation = "chat.completions" | "completions" | "messages";
|
|
10
|
+
export type Provider = "openai" | "anthropic" | "bedrock";
|
|
11
|
+
export type Operation = "chat.completions" | "completions" | "messages" | "bedrock.invoke_model" | "bedrock.converse" | "bedrock.invoke_model_stream" | "bedrock.converse_stream";
|
|
12
12
|
export type ObservationStatus = "success" | "error";
|
|
13
13
|
/**
|
|
14
14
|
* Wire shape posted to `POST /api/proxy/observation`. Mirrors the
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAA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,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;;;;;;;;;;OAcG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAKlB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAE7B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;IAE1C;;;;;;;;;;;;;;;;OAgBG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;;;;;;OAQG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB;;;;;OAKG;IACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B;;;;OAIG;IACH,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,OAAO,CAAC;IAClB,kCAAkC;IAClC,WAAW,EAAE,OAAO,CAAC;IACrB;;;;OAIG;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAGxB,KAAK,EAAE,WAAW,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,sBAAsB,GAAG,SAAS,CAAC;IACrD,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B"}
|
package/dist/wrap.d.ts
CHANGED
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
* Hardening (v0.4.0): applied-mode requests now go through the proxy-client
|
|
15
15
|
* module which adds retries, timeouts, typed errors, telemetry hooks, and
|
|
16
16
|
* the fail-open circuit breaker.
|
|
17
|
+
*
|
|
18
|
+
* Bedrock (v0.4.0): observe-only. Applied mode is not supported for Bedrock —
|
|
19
|
+
* wrap(bedrockClient, { appliedMode: true }) throws TensorCostConfigError.
|
|
20
|
+
* The Smithy middleware registered on client.middlewareStack intercepts
|
|
21
|
+
* every client.send() call transparently.
|
|
17
22
|
*/
|
|
18
23
|
import type { WrapOptions } from "./types.js";
|
|
19
24
|
export declare function wrap<T>(client: T, options?: WrapOptions): T;
|
package/dist/wrap.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../src/wrap.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../src/wrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAWH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,GAAE,WAAgB,GAAG,CAAC,CAqF/D"}
|
package/dist/wrap.js
CHANGED
|
@@ -14,13 +14,20 @@
|
|
|
14
14
|
* Hardening (v0.4.0): applied-mode requests now go through the proxy-client
|
|
15
15
|
* module which adds retries, timeouts, typed errors, telemetry hooks, and
|
|
16
16
|
* the fail-open circuit breaker.
|
|
17
|
+
*
|
|
18
|
+
* Bedrock (v0.4.0): observe-only. Applied mode is not supported for Bedrock —
|
|
19
|
+
* wrap(bedrockClient, { appliedMode: true }) throws TensorCostConfigError.
|
|
20
|
+
* The Smithy middleware registered on client.middlewareStack intercepts
|
|
21
|
+
* every client.send() call transparently.
|
|
17
22
|
*/
|
|
18
23
|
import { resolveConfig } from "./config.js";
|
|
24
|
+
import { TensorCostConfigError } from "./config.js";
|
|
19
25
|
import { ObservationTransport } from "./transport.js";
|
|
20
26
|
import { detectProvider } from "./providers/detect.js";
|
|
21
27
|
import { installAppliedMode } from "./applied.js";
|
|
22
28
|
import * as openaiProvider from "./providers/openai.js";
|
|
23
29
|
import * as anthropicProvider from "./providers/anthropic.js";
|
|
30
|
+
import * as bedrockProvider from "./providers/bedrock.js";
|
|
24
31
|
import { CircuitBreaker } from "./circuit.js";
|
|
25
32
|
export function wrap(client, options = {}) {
|
|
26
33
|
// resolveConfig throws MissingConfigError when apiKey is absent, and
|
|
@@ -33,6 +40,16 @@ export function wrap(client, options = {}) {
|
|
|
33
40
|
failOpen: config.failOpen,
|
|
34
41
|
});
|
|
35
42
|
const provider = detectProvider(client);
|
|
43
|
+
// Bedrock does not support applied mode. SigV4 signing happens inside
|
|
44
|
+
// the AWS SDK before our middleware can intercept the request, and the
|
|
45
|
+
// signed URL/headers are region-specific. Fail loudly here rather than
|
|
46
|
+
// silently ignoring the option — the customer almost certainly made a
|
|
47
|
+
// configuration mistake.
|
|
48
|
+
if (provider === "bedrock" && config.appliedMode) {
|
|
49
|
+
throw new TensorCostConfigError("TensorCost applied mode is not supported for AWS Bedrock clients. " +
|
|
50
|
+
"Bedrock uses SigV4 signing that cannot be intercepted at the proxy layer. " +
|
|
51
|
+
"Remove { appliedMode: true } or use an OpenAI / Anthropic client instead.");
|
|
52
|
+
}
|
|
36
53
|
// Applied mode: redirect the client to the proxy before installing
|
|
37
54
|
// the observe-only wrappers. Order matters — installAppliedMode mutates
|
|
38
55
|
// baseURL and defaultHeaders, and the provider wrappers capture the
|
|
@@ -56,7 +73,7 @@ export function wrap(client, options = {}) {
|
|
|
56
73
|
circuit,
|
|
57
74
|
});
|
|
58
75
|
}
|
|
59
|
-
else {
|
|
76
|
+
else if (provider === "anthropic") {
|
|
60
77
|
anthropicProvider.install(client, transport, config.tenantId, config.environment, config.connectionId, {
|
|
61
78
|
appliedMode: config.appliedMode,
|
|
62
79
|
proxyUrl: config.proxyUrl,
|
|
@@ -67,6 +84,10 @@ export function wrap(client, options = {}) {
|
|
|
67
84
|
circuit,
|
|
68
85
|
});
|
|
69
86
|
}
|
|
87
|
+
else {
|
|
88
|
+
// provider === "bedrock"
|
|
89
|
+
bedrockProvider.install(client, transport, config.tenantId, config.environment, config.connectionId);
|
|
90
|
+
}
|
|
70
91
|
return client;
|
|
71
92
|
}
|
|
72
93
|
//# sourceMappingURL=wrap.js.map
|
package/dist/wrap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrap.js","sourceRoot":"","sources":["../src/wrap.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"wrap.js","sourceRoot":"","sources":["../src/wrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,cAAc,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,iBAAiB,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,eAAe,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9C,MAAM,UAAU,IAAI,CAAI,MAAS,EAAE,UAAuB,EAAE;IAC1D,qEAAqE;IACrE,gEAAgE;IAChE,mEAAmE;IACnE,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,SAAS,GAAG,IAAI,oBAAoB,CAAC;QACzC,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;KAC1B,CAAC,CAAC;IAEH,MA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AAE,MAAM,CAAC,WAAW;YAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;YACzC,eAAe,EAAE,MAAM,CAAC,eAAe;YACvC,OAAO;SACR,CACF,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,yBAAyB;QACzB,eAAe,CAAC,OAAO,CACrB,MAAM,EACN,SAAS,EACT,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,WAAW,EAClB,MAAM,CAAC,YAAY,CACpB,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tensorcost/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "One-line wrapper SDK for TensorCost — fire-and-forget LLM observability for OpenAI and
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "One-line wrapper SDK for TensorCost — fire-and-forget LLM observability for OpenAI, Anthropic, and AWS Bedrock clients.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
"llm",
|
|
27
27
|
"openai",
|
|
28
28
|
"anthropic",
|
|
29
|
+
"bedrock",
|
|
30
|
+
"aws",
|
|
29
31
|
"observability",
|
|
30
32
|
"cost",
|
|
31
33
|
"tensorcost"
|
|
@@ -39,6 +41,14 @@
|
|
|
39
41
|
"test": "vitest run --coverage",
|
|
40
42
|
"lint": "echo 'no lint configured'"
|
|
41
43
|
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@aws-sdk/client-bedrock-runtime": "^3.0.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependenciesMeta": {
|
|
48
|
+
"@aws-sdk/client-bedrock-runtime": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
42
52
|
"devDependencies": {
|
|
43
53
|
"@types/node": "^22.0.0",
|
|
44
54
|
"@vitest/coverage-v8": "^2.1",
|