@tenova/swt3-ai 0.3.4 → 0.3.5
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 +77 -2
- package/dist/adapters/anthropic.d.ts +32 -0
- package/dist/adapters/anthropic.d.ts.map +1 -0
- package/dist/adapters/anthropic.js +299 -0
- package/dist/adapters/anthropic.js.map +1 -0
- package/dist/adapters/bedrock.d.ts +33 -0
- package/dist/adapters/bedrock.d.ts.map +1 -0
- package/dist/adapters/bedrock.js +267 -0
- package/dist/adapters/bedrock.js.map +1 -0
- package/dist/adapters/openai.d.ts +19 -0
- package/dist/adapters/openai.d.ts.map +1 -0
- package/dist/adapters/openai.js +288 -0
- package/dist/adapters/openai.js.map +1 -0
- package/dist/adapters/vercel-ai.d.ts +64 -0
- package/dist/adapters/vercel-ai.d.ts.map +1 -0
- package/dist/adapters/vercel-ai.js +68 -0
- package/dist/adapters/vercel-ai.js.map +1 -0
- package/dist/buffer.d.ts +42 -0
- package/dist/buffer.d.ts.map +1 -0
- package/dist/buffer.js +161 -0
- package/dist/buffer.js.map +1 -0
- package/dist/clearing.d.ts +29 -0
- package/dist/clearing.d.ts.map +1 -0
- package/dist/clearing.js +308 -0
- package/dist/clearing.js.map +1 -0
- package/dist/demo.d.ts +11 -0
- package/dist/demo.d.ts.map +1 -0
- package/dist/demo.js +238 -0
- package/dist/demo.js.map +1 -0
- package/dist/fingerprint.d.ts +29 -0
- package/dist/fingerprint.d.ts.map +1 -0
- package/dist/fingerprint.js +57 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/handoff.d.ts +17 -0
- package/dist/handoff.d.ts.map +1 -0
- package/dist/handoff.js +82 -0
- package/dist/handoff.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/signing.d.ts +20 -0
- package/dist/signing.d.ts.map +1 -0
- package/dist/signing.js +28 -0
- package/dist/signing.js.map +1 -0
- package/dist/types.d.ts +98 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -0
- package/dist/witness.d.ts +142 -0
- package/dist/witness.d.ts.map +1 -0
- package/dist/witness.js +345 -0
- package/dist/witness.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Witness your AI. Prove it followed the rules. Cryptographic accountability for e
|
|
|
8
8
|
|
|
9
9
|
**SWT3 AI Witness SDK for TypeScript**: tamper-proof evidence that your AI is doing what you say it does. Every inference hashed. Every tool call recorded. Every resource access checked against scope. No prompts or responses ever leave your infrastructure.
|
|
10
10
|
|
|
11
|
-
Works with OpenAI, Anthropic, Vercel AI SDK, and any OpenAI-compatible endpoint (vLLM, Ollama, Azure, Llama.cpp).
|
|
11
|
+
Works with OpenAI, Anthropic, AWS Bedrock, Vercel AI SDK, and any OpenAI-compatible endpoint (vLLM, Ollama, Azure, Llama.cpp).
|
|
12
12
|
|
|
13
13
|
The EU AI Act takes effect **August 2, 2026**. When regulators ask "prove your AI followed the rules," you need more than logs. You need cryptographic proof.
|
|
14
14
|
|
|
@@ -178,6 +178,75 @@ The `agentId` survives all clearing levels. The `signingKey` produces a cryptogr
|
|
|
178
178
|
- Fleet-wide governance dashboards
|
|
179
179
|
- Agent-scoped evidence packages for auditors
|
|
180
180
|
|
|
181
|
+
## Gatekeeper Mode (Pre-Call Enforcement)
|
|
182
|
+
|
|
183
|
+
New in v0.3.4. Require guardrails to be active *before* the model is called, not just observed after:
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
import { Witness, GatekeeperError } from "@tenova/swt3-ai";
|
|
187
|
+
|
|
188
|
+
const witness = new Witness({
|
|
189
|
+
endpoint: "...",
|
|
190
|
+
apiKey: "axm_...",
|
|
191
|
+
tenantId: "...",
|
|
192
|
+
strict: true,
|
|
193
|
+
guardrailsRequired: 2,
|
|
194
|
+
guardrailNames: ["content-filter", "pii-scanner"],
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const client = witness.wrap(new OpenAI()) as OpenAI;
|
|
198
|
+
|
|
199
|
+
// If fewer than 2 guardrails are active, this throws GatekeeperError
|
|
200
|
+
// BEFORE the model call happens. No inference runs without safeguards.
|
|
201
|
+
try {
|
|
202
|
+
const response = await client.chat.completions.create({
|
|
203
|
+
model: "gpt-4o",
|
|
204
|
+
messages: [{ role: "user", content: "..." }],
|
|
205
|
+
});
|
|
206
|
+
} catch (e) {
|
|
207
|
+
if (e instanceof GatekeeperError) {
|
|
208
|
+
console.log(`Blocked: ${e.message}`);
|
|
209
|
+
// An AI-GRD.3 FAIL anchor is minted recording the gate failure
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Gatekeeper mode mints an **AI-GRD.3** anchor with:
|
|
215
|
+
- **factor_a** = required guardrail count
|
|
216
|
+
- **factor_b** = actual guardrail count
|
|
217
|
+
- **factor_c** = 1 if gate passed, 0 if blocked
|
|
218
|
+
|
|
219
|
+
## Multi-Agent Chain Linking
|
|
220
|
+
|
|
221
|
+
New in v0.3.4. Link anchors across agents in a multi-step pipeline using `cycleId`:
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
const witness = new Witness({
|
|
225
|
+
endpoint: "...",
|
|
226
|
+
apiKey: "axm_...",
|
|
227
|
+
tenantId: "...",
|
|
228
|
+
agentId: "step-1-classifier",
|
|
229
|
+
cycleId: "txn-review-abc123", // shared across all agents in the chain
|
|
230
|
+
});
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
The `cycleId` survives all clearing levels and appears in every anchor. An auditor can reconstruct the full decision chain by filtering on a single cycle ID.
|
|
234
|
+
|
|
235
|
+
## Policy Version Binding
|
|
236
|
+
|
|
237
|
+
New in v0.3.4. Tie every anchor to the specific policy configuration that was in effect:
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
const witness = new Witness({
|
|
241
|
+
endpoint: "...",
|
|
242
|
+
apiKey: "axm_...",
|
|
243
|
+
tenantId: "...",
|
|
244
|
+
policyVersion: "v2.1.0-prod-2026-04-20",
|
|
245
|
+
});
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
The SDK hashes the policy version string (SHA-256, first 12 characters) and includes it in every payload. When policies change between audit periods, the hash changes — proving which rules were in effect for each inference.
|
|
249
|
+
|
|
181
250
|
## What Gets Witnessed
|
|
182
251
|
|
|
183
252
|
Each inference produces anchors for these checks. Every check maps to a regulation.
|
|
@@ -249,6 +318,7 @@ Translation: "Access attempt occurred. Target was outside declared scope. Access
|
|
|
249
318
|
| AI-MDL.2 | 1 (required) | 1 if version recorded | 0 | PASS if b >= a |
|
|
250
319
|
| AI-GRD.1 | Required count | Active count | 1 if all passed | PASS if b >= a |
|
|
251
320
|
| AI-GRD.2 | 1 (clean expected) | 0 if refusal | 0 | PASS if b >= a |
|
|
321
|
+
| AI-GRD.3 | Required count | Active count | 1=passed, 0=blocked | PASS if b >= a AND c == 1 |
|
|
252
322
|
| AI-TOOL.1 | 1 (called) | Latency (ms) | 1=success, 0=error | PASS if b >= a |
|
|
253
323
|
| AI-ACC.1 | 1 (accessed) | 1=in scope, 0=out | 1=granted, 0=denied | PASS if b >= a |
|
|
254
324
|
| AI-ID.1 | 1 (required) | 1 if identity present | 0 | PASS if b >= a |
|
|
@@ -372,6 +442,11 @@ const witness = new Witness({
|
|
|
372
442
|
| `guardrailNames` | [] | Active guardrail names |
|
|
373
443
|
| `agentId` | - | Agent identity (survives all clearing levels) |
|
|
374
444
|
| `signingKey` | - | HMAC-SHA256 key for payload signing |
|
|
445
|
+
| `cycleId` | - | Multi-agent chain link (survives all clearing levels) |
|
|
446
|
+
| `policyVersion` | - | Policy config identifier (hashed in payloads) |
|
|
447
|
+
| `strict` | false | Gatekeeper mode: block inference if guardrails insufficient |
|
|
448
|
+
| `latencyThresholdMs` | 30000 | AI-INF.2 latency limit (ms) |
|
|
449
|
+
| `guardrailsRequired` | 0 | AI-GRD.1 minimum guardrail count |
|
|
375
450
|
| `factorHandoff` | - | "file" for local factor export |
|
|
376
451
|
| `factorHandoffPath` | - | Directory for handoff files |
|
|
377
452
|
|
|
@@ -379,7 +454,7 @@ const witness = new Witness({
|
|
|
379
454
|
|
|
380
455
|
| Method | Description |
|
|
381
456
|
|--------|-------------|
|
|
382
|
-
| `witness.wrap(client)` | Returns a Proxy that behaves identically to the original client. Supports OpenAI and
|
|
457
|
+
| `witness.wrap(client)` | Returns a Proxy that behaves identically to the original client. Supports OpenAI, Anthropic, and AWS Bedrock. |
|
|
383
458
|
| `witness.wrapTool(fn, name?)` | Wraps a function for tool call witnessing (AI-TOOL.1). |
|
|
384
459
|
| `witness.wrapAccess(fn, resource?, scope?)` | Wraps a function for resource access witnessing (AI-ACC.1). |
|
|
385
460
|
| `witness.vercelOnFinish(opts?)` | Returns an onFinish callback for Vercel AI SDK streamText/generateText. |
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SWT3 AI Witness SDK — Anthropic Adapter (ES6 Proxy).
|
|
3
|
+
*
|
|
4
|
+
* Wraps the Anthropic client so that `client.messages.create()` is
|
|
5
|
+
* intercepted for witnessing. Two levels deep (simpler than OpenAI).
|
|
6
|
+
*
|
|
7
|
+
* Handles both:
|
|
8
|
+
* - Non-streaming: Message response object
|
|
9
|
+
* - Streaming: MessageStream — accumulates content_block_delta events
|
|
10
|
+
* for hashing, witnesses after stream_message_stop
|
|
11
|
+
*
|
|
12
|
+
* Anthropic response structure:
|
|
13
|
+
* response.content → ContentBlock[] (text, tool_use, etc.)
|
|
14
|
+
* response.model → string
|
|
15
|
+
* response.stop_reason → "end_turn" | "max_tokens" | "stop_sequence" | "tool_use"
|
|
16
|
+
* response.usage → { input_tokens, output_tokens }
|
|
17
|
+
*
|
|
18
|
+
* Anthropic streaming:
|
|
19
|
+
* The SDK returns a MessageStream with:
|
|
20
|
+
* - Symbol.asyncIterator → yields MessageStreamEvent objects
|
|
21
|
+
* - .on("message", cb) → fires when complete message is assembled
|
|
22
|
+
* - .finalMessage() → Promise<Message> (the assembled message)
|
|
23
|
+
*
|
|
24
|
+
* Events: message_start, content_block_start, content_block_delta,
|
|
25
|
+
* content_block_stop, message_delta, message_stop
|
|
26
|
+
*/
|
|
27
|
+
import type { Witness } from "../witness.js";
|
|
28
|
+
/**
|
|
29
|
+
* Wrap an Anthropic client with an ES6 Proxy for transparent witnessing.
|
|
30
|
+
*/
|
|
31
|
+
export declare function wrapAnthropic(client: unknown, witness: Witness): unknown;
|
|
32
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/adapters/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAYxE"}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SWT3 AI Witness SDK — Anthropic Adapter (ES6 Proxy).
|
|
3
|
+
*
|
|
4
|
+
* Wraps the Anthropic client so that `client.messages.create()` is
|
|
5
|
+
* intercepted for witnessing. Two levels deep (simpler than OpenAI).
|
|
6
|
+
*
|
|
7
|
+
* Handles both:
|
|
8
|
+
* - Non-streaming: Message response object
|
|
9
|
+
* - Streaming: MessageStream — accumulates content_block_delta events
|
|
10
|
+
* for hashing, witnesses after stream_message_stop
|
|
11
|
+
*
|
|
12
|
+
* Anthropic response structure:
|
|
13
|
+
* response.content → ContentBlock[] (text, tool_use, etc.)
|
|
14
|
+
* response.model → string
|
|
15
|
+
* response.stop_reason → "end_turn" | "max_tokens" | "stop_sequence" | "tool_use"
|
|
16
|
+
* response.usage → { input_tokens, output_tokens }
|
|
17
|
+
*
|
|
18
|
+
* Anthropic streaming:
|
|
19
|
+
* The SDK returns a MessageStream with:
|
|
20
|
+
* - Symbol.asyncIterator → yields MessageStreamEvent objects
|
|
21
|
+
* - .on("message", cb) → fires when complete message is assembled
|
|
22
|
+
* - .finalMessage() → Promise<Message> (the assembled message)
|
|
23
|
+
*
|
|
24
|
+
* Events: message_start, content_block_start, content_block_delta,
|
|
25
|
+
* content_block_stop, message_delta, message_stop
|
|
26
|
+
*/
|
|
27
|
+
import { sha256Truncated } from "../fingerprint.js";
|
|
28
|
+
/**
|
|
29
|
+
* Wrap an Anthropic client with an ES6 Proxy for transparent witnessing.
|
|
30
|
+
*/
|
|
31
|
+
export function wrapAnthropic(client, witness) {
|
|
32
|
+
return new Proxy(client, {
|
|
33
|
+
get(target, prop) {
|
|
34
|
+
if (typeof prop === "symbol")
|
|
35
|
+
return Reflect.get(target, prop);
|
|
36
|
+
const real = Reflect.get(target, prop);
|
|
37
|
+
if (prop === "messages") {
|
|
38
|
+
return createMessagesProxy(real, witness);
|
|
39
|
+
}
|
|
40
|
+
return real;
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function createMessagesProxy(messages, witness) {
|
|
45
|
+
return new Proxy(messages, {
|
|
46
|
+
get(target, prop) {
|
|
47
|
+
if (typeof prop === "symbol")
|
|
48
|
+
return Reflect.get(target, prop);
|
|
49
|
+
const real = Reflect.get(target, prop);
|
|
50
|
+
if (prop === "create") {
|
|
51
|
+
return createInterceptor(real, witness);
|
|
52
|
+
}
|
|
53
|
+
// Anthropic also has messages.stream() — intercept that too
|
|
54
|
+
if (prop === "stream") {
|
|
55
|
+
return createStreamInterceptor(real, witness);
|
|
56
|
+
}
|
|
57
|
+
return real;
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// ── Non-streaming / auto-detect interceptor ─────────────────────────
|
|
62
|
+
function createInterceptor(realMethod, witness) {
|
|
63
|
+
return function interceptedCreate(...args) {
|
|
64
|
+
const kwargs = (args[0] ?? {});
|
|
65
|
+
const messages = kwargs.messages;
|
|
66
|
+
const system = kwargs.system;
|
|
67
|
+
const model = kwargs.model ?? "unknown";
|
|
68
|
+
const isStreaming = kwargs.stream === true;
|
|
69
|
+
const promptText = extractPromptText(messages, system);
|
|
70
|
+
const promptHash = sha256Truncated(promptText);
|
|
71
|
+
// Hash system prompt separately (instruction drift detection)
|
|
72
|
+
const systemPromptText = extractSystemOnly(system);
|
|
73
|
+
const systemPromptHash = systemPromptText ? sha256Truncated(systemPromptText) : undefined;
|
|
74
|
+
// Gatekeeper pre-call check (strict mode only)
|
|
75
|
+
if (witness.strict) {
|
|
76
|
+
witness.gateCheck(messages, model);
|
|
77
|
+
}
|
|
78
|
+
const start = performance.now();
|
|
79
|
+
const result = realMethod.call(this, ...args);
|
|
80
|
+
if (isStreaming) {
|
|
81
|
+
// Streaming via create({ stream: true }) — returns a Stream
|
|
82
|
+
return handleStreaming(result, witness, model, promptHash, start, systemPromptHash);
|
|
83
|
+
}
|
|
84
|
+
// Non-streaming — result is Promise<Message>
|
|
85
|
+
return result.then((response) => {
|
|
86
|
+
const elapsedMs = Math.round(performance.now() - start);
|
|
87
|
+
const record = extractRecord(response, model, promptHash, elapsedMs, systemPromptHash);
|
|
88
|
+
witness.record(record);
|
|
89
|
+
return response;
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// ── Explicit .stream() interceptor ──────────────────────────────────
|
|
94
|
+
function createStreamInterceptor(realMethod, witness) {
|
|
95
|
+
return function interceptedStream(...args) {
|
|
96
|
+
const kwargs = (args[0] ?? {});
|
|
97
|
+
const messages = kwargs.messages;
|
|
98
|
+
const system = kwargs.system;
|
|
99
|
+
const model = kwargs.model ?? "unknown";
|
|
100
|
+
const promptText = extractPromptText(messages, system);
|
|
101
|
+
const promptHash = sha256Truncated(promptText);
|
|
102
|
+
const systemPromptText = extractSystemOnly(system);
|
|
103
|
+
const systemPromptHash = systemPromptText ? sha256Truncated(systemPromptText) : undefined;
|
|
104
|
+
// Gatekeeper pre-call check (strict mode only)
|
|
105
|
+
if (witness.strict) {
|
|
106
|
+
witness.gateCheck(messages, model);
|
|
107
|
+
}
|
|
108
|
+
const start = performance.now();
|
|
109
|
+
const result = realMethod.call(this, ...args);
|
|
110
|
+
return handleStreaming(result, witness, model, promptHash, start, systemPromptHash);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
// ── Streaming Handler ───────────────────────────────────────────────
|
|
114
|
+
async function* streamAccumulator(stream, witness, model, promptHash, startTime, systemPromptHash) {
|
|
115
|
+
const textParts = [];
|
|
116
|
+
let actualModel = model;
|
|
117
|
+
let stopReason = "";
|
|
118
|
+
let inputTokens;
|
|
119
|
+
let outputTokens;
|
|
120
|
+
for await (const event of stream) {
|
|
121
|
+
// Yield to developer immediately
|
|
122
|
+
yield event;
|
|
123
|
+
const e = event;
|
|
124
|
+
const type = e.type;
|
|
125
|
+
if (type === "message_start") {
|
|
126
|
+
const msg = e.message;
|
|
127
|
+
if (msg?.model)
|
|
128
|
+
actualModel = msg.model;
|
|
129
|
+
const usage = msg?.usage;
|
|
130
|
+
if (usage?.input_tokens)
|
|
131
|
+
inputTokens = usage.input_tokens;
|
|
132
|
+
}
|
|
133
|
+
if (type === "content_block_delta") {
|
|
134
|
+
const delta = e.delta;
|
|
135
|
+
if (delta?.type === "text_delta" && delta?.text) {
|
|
136
|
+
textParts.push(delta.text);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (type === "message_delta") {
|
|
140
|
+
const delta = e.delta;
|
|
141
|
+
if (delta?.stop_reason)
|
|
142
|
+
stopReason = delta.stop_reason;
|
|
143
|
+
const usage = e.usage;
|
|
144
|
+
if (usage?.output_tokens)
|
|
145
|
+
outputTokens = usage.output_tokens;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// Stream complete — witness
|
|
149
|
+
const elapsedMs = Math.round(performance.now() - startTime);
|
|
150
|
+
const responseText = textParts.join("");
|
|
151
|
+
const hasRefusal = !["end_turn", "max_tokens", "stop_sequence", "tool_use"].includes(stopReason);
|
|
152
|
+
const record = {
|
|
153
|
+
modelId: actualModel,
|
|
154
|
+
modelHash: sha256Truncated(actualModel),
|
|
155
|
+
promptHash,
|
|
156
|
+
responseHash: sha256Truncated(responseText),
|
|
157
|
+
latencyMs: elapsedMs,
|
|
158
|
+
inputTokens,
|
|
159
|
+
outputTokens,
|
|
160
|
+
guardrailsActive: 0,
|
|
161
|
+
guardrailsRequired: 0,
|
|
162
|
+
guardrailPassed: true,
|
|
163
|
+
hasRefusal,
|
|
164
|
+
provider: "anthropic",
|
|
165
|
+
systemPromptHash,
|
|
166
|
+
guardrailNames: [],
|
|
167
|
+
};
|
|
168
|
+
witness.record(record);
|
|
169
|
+
}
|
|
170
|
+
function handleStreaming(streamResult, witness, model, promptHash, startTime, systemPromptHash) {
|
|
171
|
+
// Anthropic's stream() returns a MessageStream directly (not a Promise)
|
|
172
|
+
// But create({ stream: true }) may return a Promise<Stream>
|
|
173
|
+
if (streamResult && typeof streamResult.then === "function") {
|
|
174
|
+
return streamResult.then((stream) => wrapAnthropicStream(stream, witness, model, promptHash, startTime, systemPromptHash));
|
|
175
|
+
}
|
|
176
|
+
return wrapAnthropicStream(streamResult, witness, model, promptHash, startTime, systemPromptHash);
|
|
177
|
+
}
|
|
178
|
+
function wrapAnthropicStream(stream, witness, model, promptHash, startTime, systemPromptHash) {
|
|
179
|
+
const s = stream;
|
|
180
|
+
const gen = streamAccumulator(s, witness, model, promptHash, startTime, systemPromptHash);
|
|
181
|
+
return new Proxy(s, {
|
|
182
|
+
get(target, prop) {
|
|
183
|
+
if (prop === Symbol.asyncIterator) {
|
|
184
|
+
return () => gen;
|
|
185
|
+
}
|
|
186
|
+
const value = Reflect.get(target, prop);
|
|
187
|
+
if (typeof value === "function") {
|
|
188
|
+
// Wrap finalMessage() to also witness the complete response
|
|
189
|
+
if (prop === "finalMessage") {
|
|
190
|
+
return async function wrappedFinalMessage() {
|
|
191
|
+
const msg = await value.call(target);
|
|
192
|
+
// The stream accumulator will have already witnessed via iteration,
|
|
193
|
+
// but if someone calls finalMessage() WITHOUT iterating, we need
|
|
194
|
+
// to witness from the assembled message.
|
|
195
|
+
return msg;
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return value.bind(target);
|
|
199
|
+
}
|
|
200
|
+
return value;
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
// ── Factor Extraction ──────────────────────────────────────────────
|
|
205
|
+
function extractSystemOnly(system) {
|
|
206
|
+
if (typeof system === "string" && system)
|
|
207
|
+
return system;
|
|
208
|
+
if (Array.isArray(system)) {
|
|
209
|
+
const parts = [];
|
|
210
|
+
for (const block of system) {
|
|
211
|
+
if (typeof block === "object" && block !== null) {
|
|
212
|
+
const b = block;
|
|
213
|
+
if (b.type === "text" && typeof b.text === "string") {
|
|
214
|
+
parts.push(b.text);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return parts.length > 0 ? parts.join("\n") : undefined;
|
|
219
|
+
}
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
function extractPromptText(messages, system = "") {
|
|
223
|
+
const parts = [];
|
|
224
|
+
// System prompt
|
|
225
|
+
if (typeof system === "string" && system) {
|
|
226
|
+
parts.push(system);
|
|
227
|
+
}
|
|
228
|
+
else if (Array.isArray(system)) {
|
|
229
|
+
for (const block of system) {
|
|
230
|
+
if (typeof block === "object" && block !== null) {
|
|
231
|
+
const b = block;
|
|
232
|
+
if (b.type === "text" && typeof b.text === "string") {
|
|
233
|
+
parts.push(b.text);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// Messages
|
|
239
|
+
if (Array.isArray(messages)) {
|
|
240
|
+
for (const msg of messages) {
|
|
241
|
+
if (typeof msg === "object" && msg !== null) {
|
|
242
|
+
const m = msg;
|
|
243
|
+
const content = m.content;
|
|
244
|
+
if (typeof content === "string") {
|
|
245
|
+
parts.push(content);
|
|
246
|
+
}
|
|
247
|
+
else if (Array.isArray(content)) {
|
|
248
|
+
for (const block of content) {
|
|
249
|
+
if (typeof block === "object" && block !== null) {
|
|
250
|
+
const b = block;
|
|
251
|
+
if (b.type === "text" && typeof b.text === "string") {
|
|
252
|
+
parts.push(b.text);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return parts.join("\n");
|
|
261
|
+
}
|
|
262
|
+
function extractRecord(response, model, promptHash, elapsedMs, systemPromptHash) {
|
|
263
|
+
const r = response;
|
|
264
|
+
// Extract text from content blocks
|
|
265
|
+
let responseText = "";
|
|
266
|
+
const contentBlocks = r.content;
|
|
267
|
+
if (Array.isArray(contentBlocks)) {
|
|
268
|
+
const texts = [];
|
|
269
|
+
for (const block of contentBlocks) {
|
|
270
|
+
if (block.type === "text" && typeof block.text === "string") {
|
|
271
|
+
texts.push(block.text);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
responseText = texts.join("\n");
|
|
275
|
+
}
|
|
276
|
+
const stopReason = r.stop_reason ?? "";
|
|
277
|
+
const hasRefusal = !["end_turn", "max_tokens", "stop_sequence", "tool_use"].includes(stopReason);
|
|
278
|
+
const usage = r.usage;
|
|
279
|
+
const inputTokens = usage?.input_tokens;
|
|
280
|
+
const outputTokens = usage?.output_tokens;
|
|
281
|
+
const actualModel = r.model ?? model;
|
|
282
|
+
return {
|
|
283
|
+
modelId: actualModel,
|
|
284
|
+
modelHash: sha256Truncated(actualModel),
|
|
285
|
+
promptHash,
|
|
286
|
+
responseHash: sha256Truncated(responseText),
|
|
287
|
+
latencyMs: elapsedMs,
|
|
288
|
+
inputTokens,
|
|
289
|
+
outputTokens,
|
|
290
|
+
guardrailsActive: 0,
|
|
291
|
+
guardrailsRequired: 0,
|
|
292
|
+
guardrailPassed: true,
|
|
293
|
+
hasRefusal,
|
|
294
|
+
provider: "anthropic",
|
|
295
|
+
systemPromptHash,
|
|
296
|
+
guardrailNames: [],
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/adapters/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIpD;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAe,EAAE,OAAgB;IAC7D,OAAO,IAAI,KAAK,CAAC,MAAgB,EAAE;QACjC,GAAG,CAAC,MAAc,EAAE,IAAqB;YACvC,IAAI,OAAO,IAAI,KAAK,QAAQ;gBAAE,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAC/D,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAEvC,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;gBACxB,OAAO,mBAAmB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC5C,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,SAAS,mBAAmB,CAAC,QAAiB,EAAE,OAAgB;IAC9D,OAAO,IAAI,KAAK,CAAC,QAAkB,EAAE;QACnC,GAAG,CAAC,MAAc,EAAE,IAAqB;YACvC,IAAI,OAAO,IAAI,KAAK,QAAQ;gBAAE,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAC/D,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAEvC,IAAI,IAAI,KAAK,QAAQ,EA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,CAAC,WAAW,CAAC;QACvC,UAAU;QACV,YAAY,EAAE,eAAe,CAAC,YAAY,CAAC;QAC3C,SAAS,EAAE,SAAS;QACpB,WAAW;QACX,YAAY;QACZ,gBAAgB,EAAE,CAAC;QACnB,kBAAkB,EAAE,CAAC;QACrB,eAAe,EAAE,IAAI;QACrB,UAAU;QACV,QAAQ,EAAE,WAAW;QACrB,gBAAgB;QAChB,cAAc,EAAE,EAAE;KACnB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SWT3 AI Witness SDK — AWS Bedrock Adapter (ES6 Proxy).
|
|
3
|
+
*
|
|
4
|
+
* Wraps the @aws-sdk/client-bedrock-runtime client so that
|
|
5
|
+
* `client.send(new ConverseCommand(...))` and
|
|
6
|
+
* `client.send(new InvokeModelCommand(...))` are intercepted.
|
|
7
|
+
*
|
|
8
|
+
* AWS Bedrock uses the Command pattern:
|
|
9
|
+
* const response = await client.send(new ConverseCommand({ modelId, messages }));
|
|
10
|
+
*
|
|
11
|
+
* The adapter intercepts `send()` and checks if the command is a
|
|
12
|
+
* ConverseCommand or InvokeModelCommand to extract factors.
|
|
13
|
+
*
|
|
14
|
+
* Copyright (c) 2026 Tenable Nova LLC. Apache 2.0. Patent pending.
|
|
15
|
+
*/
|
|
16
|
+
import type { Witness } from "../witness.js";
|
|
17
|
+
/**
|
|
18
|
+
* Wrap a BedrockRuntimeClient with transparent witnessing.
|
|
19
|
+
*
|
|
20
|
+
* Usage:
|
|
21
|
+
* import { BedrockRuntimeClient, ConverseCommand } from "@aws-sdk/client-bedrock-runtime";
|
|
22
|
+
* import { Witness } from "@tenova/swt3-ai";
|
|
23
|
+
*
|
|
24
|
+
* const witness = new Witness({ endpoint, apiKey, tenantId });
|
|
25
|
+
* const client = witness.wrap(new BedrockRuntimeClient({ region: "us-east-1" }));
|
|
26
|
+
*
|
|
27
|
+
* const response = await client.send(new ConverseCommand({
|
|
28
|
+
* modelId: "anthropic.claude-3-5-sonnet-20241022-v2:0",
|
|
29
|
+
* messages: [{ role: "user", content: [{ text: "Hello" }] }],
|
|
30
|
+
* }));
|
|
31
|
+
*/
|
|
32
|
+
export declare function wrapBedrock(client: unknown, witness: Witness): unknown;
|
|
33
|
+
//# sourceMappingURL=bedrock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bedrock.d.ts","sourceRoot":"","sources":["../../src/adapters/bedrock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAatE"}
|