@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 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:
@@ -3,6 +3,7 @@ export interface EventRequest {
3
3
  feature?: string;
4
4
  input_tokens?: number;
5
5
  input_tokens_estimate?: number;
6
+ token_explosion_tokens?: number;
6
7
  max_output_tokens?: number;
7
8
  protect_decision?: string;
8
9
  protect_reason?: string;
@@ -1,4 +1,4 @@
1
- export type ProtectDecision = "allow" | "warn" | "block";
1
+ export type ProtectDecision = "allow" | "clamp" | "block";
2
2
  export type ProtectFailMode = "open" | "closed";
3
3
  export interface ProtectContext {
4
4
  provider: string;
@@ -229,7 +229,7 @@ function parseBlockedUntilMs(value) {
229
229
  return parsed;
230
230
  }
231
231
  function parseDecision(value) {
232
- if (value === "warn" || value === "block" || value === "allow") {
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 === "warn" ? "warn" : undefined,
60
- protect_reason: protectDecision.decision === "warn" ? protectDecision.reason : 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,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 === "warn" ? "warn" : undefined,
80
- protect_reason: protectDecision.decision === "warn" ? protectDecision.reason : undefined,
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 !== "warn" || decision.reason !== "near_cap") {
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 === "warn" ? "warn" : undefined,
60
- protect_reason: protectDecision.decision === "warn" ? protectDecision.reason : 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,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 === "warn" ? "warn" : undefined,
80
- protect_reason: protectDecision.decision === "warn" ? protectDecision.reason : undefined,
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 !== "warn" || decision.reason !== "near_cap") {
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
- protect_decision: protectDecision.decision === "warn" ? "warn" : undefined,
60
- protect_reason: protectDecision.decision === "warn" ? protectDecision.reason : undefined,
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
- protect_decision: protectDecision.decision === "warn" ? "warn" : undefined,
79
- protect_reason: protectDecision.decision === "warn" ? protectDecision.reason : undefined,
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 !== "warn" || decision.reason !== "near_cap") {
123
+ if (decision.decision !== "clamp") {
122
124
  return args;
123
125
  }
124
126
  if (!decision.applyClampEnabled) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rheonic/sdk",
3
- "version": "0.1.0-beta.4",
3
+ "version": "0.1.0-beta.6",
4
4
  "description": "Node.js SDK for Rheonic observability and protect preflight enforcement.",
5
5
  "author": "Rheonic <founder@rheonic.dev>",
6
6
  "license": "MIT",