@rheonic/sdk 0.1.0-beta.4 → 0.1.0-beta.6
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 +3 -1
- package/dist/eventBuilder.d.ts +1 -0
- package/dist/protectEngine.d.ts +1 -1
- package/dist/protectEngine.js +1 -1
- package/dist/providers/anthropicAdapter.js +7 -5
- package/dist/providers/googleAdapter.js +7 -5
- package/dist/providers/openaiAdapter.js +7 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -120,12 +120,14 @@ await client.captureEvent(
|
|
|
120
120
|
buildEvent({
|
|
121
121
|
provider: "openai",
|
|
122
122
|
model: "gpt-4o-mini",
|
|
123
|
-
request: { endpoint: "/chat/completions", feature: "assistant" },
|
|
123
|
+
request: { endpoint: "/chat/completions", feature: "assistant", token_explosion_tokens: 64 },
|
|
124
124
|
response: { total_tokens: 64, latency_ms: 120, http_status: 200 },
|
|
125
125
|
}),
|
|
126
126
|
);
|
|
127
127
|
```
|
|
128
128
|
|
|
129
|
+
`token_explosion_tokens` is optional. Set it only for custom/manual events when you want token-explosion detection to use the same request-context signal that the SDK instrumentation sends to both protect and ingest.
|
|
130
|
+
|
|
129
131
|
## Reference
|
|
130
132
|
|
|
131
133
|
Full quickstart:
|
package/dist/eventBuilder.d.ts
CHANGED
package/dist/protectEngine.d.ts
CHANGED
package/dist/protectEngine.js
CHANGED
|
@@ -229,7 +229,7 @@ function parseBlockedUntilMs(value) {
|
|
|
229
229
|
return parsed;
|
|
230
230
|
}
|
|
231
231
|
function parseDecision(value) {
|
|
232
|
-
if (value === "
|
|
232
|
+
if (value === "clamp" || value === "block" || value === "allow") {
|
|
233
233
|
return value;
|
|
234
234
|
}
|
|
235
235
|
return "allow";
|
|
@@ -55,9 +55,10 @@ export function instrumentAnthropic(anthropicClient, options) {
|
|
|
55
55
|
request: {
|
|
56
56
|
endpoint: options.endpoint,
|
|
57
57
|
feature: options.feature,
|
|
58
|
+
token_explosion_tokens: typeof estimatedInputTokens === "number" ? estimatedInputTokens : undefined,
|
|
58
59
|
input_tokens_estimate: typeof estimatedInputTokens === "number" ? estimatedInputTokens : undefined,
|
|
59
|
-
protect_decision: protectDecision.decision
|
|
60
|
-
protect_reason: protectDecision.decision
|
|
60
|
+
protect_decision: protectDecision.decision !== "allow" ? protectDecision.decision : undefined,
|
|
61
|
+
protect_reason: protectDecision.decision !== "allow" ? protectDecision.reason : undefined,
|
|
61
62
|
},
|
|
62
63
|
response: {
|
|
63
64
|
latency_ms: Date.now() - startedAt,
|
|
@@ -75,9 +76,10 @@ export function instrumentAnthropic(anthropicClient, options) {
|
|
|
75
76
|
request: {
|
|
76
77
|
endpoint: options.endpoint,
|
|
77
78
|
feature: options.feature,
|
|
79
|
+
token_explosion_tokens: typeof estimatedInputTokens === "number" ? estimatedInputTokens : undefined,
|
|
78
80
|
input_tokens_estimate: typeof estimatedInputTokens === "number" ? estimatedInputTokens : undefined,
|
|
79
|
-
protect_decision: protectDecision.decision
|
|
80
|
-
protect_reason: protectDecision.decision
|
|
81
|
+
protect_decision: protectDecision.decision !== "allow" ? protectDecision.decision : undefined,
|
|
82
|
+
protect_reason: protectDecision.decision !== "allow" ? protectDecision.reason : undefined,
|
|
81
83
|
},
|
|
82
84
|
response: {
|
|
83
85
|
latency_ms: Date.now() - startedAt,
|
|
@@ -153,7 +155,7 @@ function extractHttpStatus(error) {
|
|
|
153
155
|
return undefined;
|
|
154
156
|
}
|
|
155
157
|
function maybeApplyAnthropicClamp(args, decision) {
|
|
156
|
-
if (decision.decision !== "
|
|
158
|
+
if (decision.decision !== "clamp") {
|
|
157
159
|
return args;
|
|
158
160
|
}
|
|
159
161
|
if (!decision.applyClampEnabled) {
|
|
@@ -55,9 +55,10 @@ export function instrumentGoogle(googleModel, options) {
|
|
|
55
55
|
request: {
|
|
56
56
|
endpoint: options.endpoint,
|
|
57
57
|
feature: options.feature,
|
|
58
|
+
token_explosion_tokens: typeof estimatedInputTokens === "number" ? estimatedInputTokens : undefined,
|
|
58
59
|
input_tokens_estimate: typeof estimatedInputTokens === "number" ? estimatedInputTokens : undefined,
|
|
59
|
-
protect_decision: protectDecision.decision
|
|
60
|
-
protect_reason: protectDecision.decision
|
|
60
|
+
protect_decision: protectDecision.decision !== "allow" ? protectDecision.decision : undefined,
|
|
61
|
+
protect_reason: protectDecision.decision !== "allow" ? protectDecision.reason : undefined,
|
|
61
62
|
},
|
|
62
63
|
response: {
|
|
63
64
|
latency_ms: Date.now() - startedAt,
|
|
@@ -75,9 +76,10 @@ export function instrumentGoogle(googleModel, options) {
|
|
|
75
76
|
request: {
|
|
76
77
|
endpoint: options.endpoint,
|
|
77
78
|
feature: options.feature,
|
|
79
|
+
token_explosion_tokens: typeof estimatedInputTokens === "number" ? estimatedInputTokens : undefined,
|
|
78
80
|
input_tokens_estimate: typeof estimatedInputTokens === "number" ? estimatedInputTokens : undefined,
|
|
79
|
-
protect_decision: protectDecision.decision
|
|
80
|
-
protect_reason: protectDecision.decision
|
|
81
|
+
protect_decision: protectDecision.decision !== "allow" ? protectDecision.decision : undefined,
|
|
82
|
+
protect_reason: protectDecision.decision !== "allow" ? protectDecision.reason : undefined,
|
|
81
83
|
},
|
|
82
84
|
response: {
|
|
83
85
|
latency_ms: Date.now() - startedAt,
|
|
@@ -166,7 +168,7 @@ function extractHttpStatus(error) {
|
|
|
166
168
|
return undefined;
|
|
167
169
|
}
|
|
168
170
|
function maybeApplyGoogleClamp(args, decision) {
|
|
169
|
-
if (decision.decision !== "
|
|
171
|
+
if (decision.decision !== "clamp") {
|
|
170
172
|
return args;
|
|
171
173
|
}
|
|
172
174
|
if (!decision.applyClampEnabled) {
|
|
@@ -56,8 +56,9 @@ export function instrumentOpenAI(openaiClient, options) {
|
|
|
56
56
|
request: {
|
|
57
57
|
endpoint: options.endpoint,
|
|
58
58
|
feature: options.feature,
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
token_explosion_tokens: typeof estimatedInputTokens === "number" ? estimatedInputTokens : undefined,
|
|
60
|
+
protect_decision: protectDecision.decision !== "allow" ? protectDecision.decision : undefined,
|
|
61
|
+
protect_reason: protectDecision.decision !== "allow" ? protectDecision.reason : undefined,
|
|
61
62
|
},
|
|
62
63
|
response: {
|
|
63
64
|
latency_ms: Date.now() - startedAt,
|
|
@@ -75,8 +76,9 @@ export function instrumentOpenAI(openaiClient, options) {
|
|
|
75
76
|
request: {
|
|
76
77
|
endpoint: options.endpoint,
|
|
77
78
|
feature: options.feature,
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
token_explosion_tokens: typeof estimatedInputTokens === "number" ? estimatedInputTokens : undefined,
|
|
80
|
+
protect_decision: protectDecision.decision !== "allow" ? protectDecision.decision : undefined,
|
|
81
|
+
protect_reason: protectDecision.decision !== "allow" ? protectDecision.reason : undefined,
|
|
80
82
|
},
|
|
81
83
|
response: {
|
|
82
84
|
latency_ms: Date.now() - startedAt,
|
|
@@ -118,7 +120,7 @@ function extractMaxOutputTokens(args) {
|
|
|
118
120
|
return undefined;
|
|
119
121
|
}
|
|
120
122
|
function maybeApplyOpenAIClamp(args, decision) {
|
|
121
|
-
if (decision.decision !== "
|
|
123
|
+
if (decision.decision !== "clamp") {
|
|
122
124
|
return args;
|
|
123
125
|
}
|
|
124
126
|
if (!decision.applyClampEnabled) {
|
package/package.json
CHANGED