highflame 0.2.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 +579 -0
- package/dist/index.cjs +705 -0
- package/dist/index.d.cts +644 -0
- package/dist/index.d.ts +644 -0
- package/dist/index.js +666 -0
- package/package.json +46 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated types from spec/shield-v1.yaml — DO NOT EDIT.
|
|
3
|
+
*
|
|
4
|
+
* Regenerate: python codegen/generate.py --spec spec/shield-v1.yaml
|
|
5
|
+
*/
|
|
6
|
+
/** Type of content being evaluated. */
|
|
7
|
+
type ContentType = "prompt" | "response" | "tool_call" | "file";
|
|
8
|
+
/** Guard evaluation decision. */
|
|
9
|
+
type Decision = "allow" | "deny";
|
|
10
|
+
/** enforce: block on deny. monitor: allow + log. alert: allow + signal. */
|
|
11
|
+
type Mode = "enforce" | "monitor" | "alert";
|
|
12
|
+
/** Authenticated agent identity from token claims. */
|
|
13
|
+
interface AgentIdentityTrace {
|
|
14
|
+
/** Agent identifier. */
|
|
15
|
+
agent_id: string;
|
|
16
|
+
/** Type of agent (e.g. claude, cursor, custom). */
|
|
17
|
+
agent_type: string;
|
|
18
|
+
/** Trust level (verified, unverified, etc.). */
|
|
19
|
+
trust_level: string;
|
|
20
|
+
/** Agent framework (e.g. Python SDK, Node SDK). */
|
|
21
|
+
framework?: string;
|
|
22
|
+
/** Publisher/organization. */
|
|
23
|
+
publisher?: string;
|
|
24
|
+
/** Authentication method: api_key or jwt. */
|
|
25
|
+
auth_method: string;
|
|
26
|
+
}
|
|
27
|
+
/** Specification of a context key emitted by a detector. */
|
|
28
|
+
interface ContextKeySpec {
|
|
29
|
+
/** Context key name (e.g. injection_score). */
|
|
30
|
+
key: string;
|
|
31
|
+
/** Cedar type: long, bool, string, or set. */
|
|
32
|
+
type: string;
|
|
33
|
+
/** Human-readable description. */
|
|
34
|
+
description: string;
|
|
35
|
+
/** Value range (e.g. 0-100). */
|
|
36
|
+
range?: string;
|
|
37
|
+
}
|
|
38
|
+
/** Entity in the Cedar evaluation context. */
|
|
39
|
+
interface EntityDebug {
|
|
40
|
+
/** Entity type. */
|
|
41
|
+
type: string;
|
|
42
|
+
/** Entity ID. */
|
|
43
|
+
id: string;
|
|
44
|
+
/** Parent entity UIDs. */
|
|
45
|
+
parents?: string[];
|
|
46
|
+
}
|
|
47
|
+
/** Resolved tenant identity. */
|
|
48
|
+
interface TenantDebug {
|
|
49
|
+
account_id: string;
|
|
50
|
+
project_id: string;
|
|
51
|
+
application_id: string;
|
|
52
|
+
}
|
|
53
|
+
/** Cedar evaluation debug info (when debug=true). */
|
|
54
|
+
interface DebugInfo {
|
|
55
|
+
/** Product namespace. */
|
|
56
|
+
product: string;
|
|
57
|
+
/** Cedar namespace (e.g. Guardrails). */
|
|
58
|
+
namespace: string;
|
|
59
|
+
/** Principal entity type. */
|
|
60
|
+
principal_type: string;
|
|
61
|
+
/** Principal entity ID. */
|
|
62
|
+
principal_id: string;
|
|
63
|
+
/** Cedar action. */
|
|
64
|
+
action: string;
|
|
65
|
+
/** Resource entity type. */
|
|
66
|
+
resource_type: string;
|
|
67
|
+
/** Resource entity ID. */
|
|
68
|
+
resource_id: string;
|
|
69
|
+
/** Entity hierarchy. */
|
|
70
|
+
entities: EntityDebug[];
|
|
71
|
+
/** Number of loaded policies. */
|
|
72
|
+
loaded_policy_count: number;
|
|
73
|
+
tenant: TenantDebug;
|
|
74
|
+
}
|
|
75
|
+
/** Summary of a loaded Cedar policy. */
|
|
76
|
+
interface PolicySummary {
|
|
77
|
+
/** Database UUID. */
|
|
78
|
+
policy_id: string;
|
|
79
|
+
/** Human-readable name. */
|
|
80
|
+
policy_name: string;
|
|
81
|
+
/** Policy mode: enforce, monitor, or alert. */
|
|
82
|
+
mode: string;
|
|
83
|
+
/** Policy domain category. */
|
|
84
|
+
category?: string;
|
|
85
|
+
/** Cedar @id annotations from this policy. */
|
|
86
|
+
rule_ids: string[];
|
|
87
|
+
}
|
|
88
|
+
/** Response from GET /v1/debug/policies. */
|
|
89
|
+
interface DebugPoliciesResponse {
|
|
90
|
+
/** Product namespace inspected. */
|
|
91
|
+
product: string;
|
|
92
|
+
/** Whether the evaluator has loaded policies. */
|
|
93
|
+
has_policies: boolean;
|
|
94
|
+
/** Number of distinct DB policies loaded. */
|
|
95
|
+
policy_count: number;
|
|
96
|
+
/** Loaded policies with metadata. */
|
|
97
|
+
policies: PolicySummary[];
|
|
98
|
+
}
|
|
99
|
+
/** File operation context. */
|
|
100
|
+
interface FileContext {
|
|
101
|
+
/** File path. */
|
|
102
|
+
path: string;
|
|
103
|
+
/** File operation: read, write, delete, append, etc. */
|
|
104
|
+
operation: string;
|
|
105
|
+
/** File size in bytes. */
|
|
106
|
+
size?: number;
|
|
107
|
+
/** File MIME type. */
|
|
108
|
+
mime_type?: string;
|
|
109
|
+
}
|
|
110
|
+
/** MCP server interaction context. */
|
|
111
|
+
interface MCPContext {
|
|
112
|
+
/** MCP server name. */
|
|
113
|
+
server_name: string;
|
|
114
|
+
/** MCP server URL. */
|
|
115
|
+
server_url?: string;
|
|
116
|
+
/** Transport protocol: sse, stdio, http. */
|
|
117
|
+
transport?: string;
|
|
118
|
+
/** Whether the server passed trust/signature verification. */
|
|
119
|
+
verified?: boolean;
|
|
120
|
+
/** Advertised MCP capabilities from server manifest. */
|
|
121
|
+
capabilities?: string[];
|
|
122
|
+
}
|
|
123
|
+
/** LLM model context (provider, temperature, token usage). */
|
|
124
|
+
interface ModelContext {
|
|
125
|
+
/** LLM provider (e.g. openai, anthropic). */
|
|
126
|
+
provider?: string;
|
|
127
|
+
/** Model name (e.g. gpt-4, claude-3). */
|
|
128
|
+
model?: string;
|
|
129
|
+
/** Temperature setting. */
|
|
130
|
+
temperature?: number;
|
|
131
|
+
/** Tokens consumed so far in the session. */
|
|
132
|
+
tokens_used?: number;
|
|
133
|
+
/** Max token limit for the session. */
|
|
134
|
+
max_tokens?: number;
|
|
135
|
+
}
|
|
136
|
+
/** Tool call context for agentic evaluation. */
|
|
137
|
+
interface ToolContext {
|
|
138
|
+
/** Tool name. */
|
|
139
|
+
name: string;
|
|
140
|
+
/** Whether the tool is built-in to the LLM or externally registered. */
|
|
141
|
+
is_builtin: boolean;
|
|
142
|
+
/** Tool arguments as a JSON object. */
|
|
143
|
+
arguments?: Record<string, unknown>;
|
|
144
|
+
/** MCP server ID (for externally-registered tools). */
|
|
145
|
+
server_id?: string;
|
|
146
|
+
/** Tool description from MCP manifest, for tool-poisoning analysis. */
|
|
147
|
+
description?: string;
|
|
148
|
+
}
|
|
149
|
+
/** Request body for POST /v1/detect. Detection only, no policy evaluation. */
|
|
150
|
+
interface DetectRequest {
|
|
151
|
+
/** Content to analyze. */
|
|
152
|
+
content: string;
|
|
153
|
+
content_type: ContentType;
|
|
154
|
+
/** Specific detectors to run. Empty runs all enabled detectors. */
|
|
155
|
+
detectors?: string[];
|
|
156
|
+
/** Caller-provided metadata passed through to detectors. */
|
|
157
|
+
metadata?: Record<string, unknown>;
|
|
158
|
+
/** Reference material for context-aware detection. */
|
|
159
|
+
contexts?: string[];
|
|
160
|
+
/** Session ID for cross-turn state tracking. */
|
|
161
|
+
session_id?: string;
|
|
162
|
+
tool?: ToolContext;
|
|
163
|
+
model?: ModelContext;
|
|
164
|
+
file?: FileContext;
|
|
165
|
+
mcp?: MCPContext;
|
|
166
|
+
}
|
|
167
|
+
/** Result from a single detector execution. */
|
|
168
|
+
interface DetectorResult {
|
|
169
|
+
/** Detector name (e.g. injection, secrets, toxicity). */
|
|
170
|
+
name: string;
|
|
171
|
+
/** Detector tier: fast, standard, or slow. */
|
|
172
|
+
tier: string;
|
|
173
|
+
/** Detector execution latency in milliseconds. */
|
|
174
|
+
latency_ms: number;
|
|
175
|
+
/** Emitted context attributes (e.g. injection_score, contains_secrets). */
|
|
176
|
+
context: Record<string, unknown>;
|
|
177
|
+
/** Detector status: healthy, degraded, error, or timeout. */
|
|
178
|
+
status: string;
|
|
179
|
+
/** Error message (when status is error or timeout). */
|
|
180
|
+
error?: string;
|
|
181
|
+
}
|
|
182
|
+
/** Response from POST /v1/detect. */
|
|
183
|
+
interface DetectResponse {
|
|
184
|
+
/** Per-detector results. */
|
|
185
|
+
detectors: DetectorResult[];
|
|
186
|
+
/** Merged context from all detectors. */
|
|
187
|
+
context: Record<string, unknown>;
|
|
188
|
+
/** Total detection latency in milliseconds. */
|
|
189
|
+
latency_ms: number;
|
|
190
|
+
/** Detector tiers that ran. */
|
|
191
|
+
tiers_evaluated: string[];
|
|
192
|
+
}
|
|
193
|
+
/** Metadata about an available detector. */
|
|
194
|
+
interface DetectorInfo {
|
|
195
|
+
/** Detector name. */
|
|
196
|
+
name: string;
|
|
197
|
+
/** Detector version. */
|
|
198
|
+
version: string;
|
|
199
|
+
/** Detector tier: fast, standard, or slow. */
|
|
200
|
+
tier: string;
|
|
201
|
+
/** Keys this detector may emit. */
|
|
202
|
+
context_keys: ContextKeySpec[];
|
|
203
|
+
/** Detector status: healthy, degraded, or disabled. */
|
|
204
|
+
status: string;
|
|
205
|
+
/** Human-readable display name. */
|
|
206
|
+
display_name?: string;
|
|
207
|
+
/** What the detector detects. */
|
|
208
|
+
description?: string;
|
|
209
|
+
/** Detection category (e.g. Security, Content Safety). */
|
|
210
|
+
category?: string;
|
|
211
|
+
/** Whether the detector accepts configuration. */
|
|
212
|
+
configurable?: boolean;
|
|
213
|
+
/** Configuration schema type (if configurable). */
|
|
214
|
+
config_type?: string;
|
|
215
|
+
/** Tags for filtering. */
|
|
216
|
+
tags?: string[];
|
|
217
|
+
/** Typical latency estimate. */
|
|
218
|
+
latency?: string;
|
|
219
|
+
}
|
|
220
|
+
/** Entry in the detector optimization plan. */
|
|
221
|
+
interface DetectorPlanEntry {
|
|
222
|
+
/** Detector name. */
|
|
223
|
+
name: string;
|
|
224
|
+
/** Detector tier. */
|
|
225
|
+
tier: string;
|
|
226
|
+
/** Why included/excluded: policy_required, always_run, not_required. */
|
|
227
|
+
reason: string;
|
|
228
|
+
/** Full scoped config (dry run only). */
|
|
229
|
+
config?: Record<string, unknown>;
|
|
230
|
+
}
|
|
231
|
+
/** A Cedar policy that contributed to the guard decision. */
|
|
232
|
+
interface DeterminingPolicy {
|
|
233
|
+
/** Cedar @id annotation (e.g. secrets-block-prompts). */
|
|
234
|
+
rule_id: string;
|
|
235
|
+
/** Database UUID (for dashboard linking). */
|
|
236
|
+
policy_id?: string;
|
|
237
|
+
/** Human-readable policy name. */
|
|
238
|
+
policy_name?: string;
|
|
239
|
+
/** Cedar effect: permit or forbid. */
|
|
240
|
+
effect?: string;
|
|
241
|
+
/** Policy mode: enforce, monitor, or alert. */
|
|
242
|
+
mode?: string;
|
|
243
|
+
/** Policy domain (e.g. secrets, pii, injection). */
|
|
244
|
+
category?: string;
|
|
245
|
+
/** From Cedar @severity annotation. */
|
|
246
|
+
severity?: string;
|
|
247
|
+
/** From Cedar @tags annotation. */
|
|
248
|
+
tags?: string[];
|
|
249
|
+
/** Custom Cedar annotations. */
|
|
250
|
+
annotations?: Record<string, string>;
|
|
251
|
+
}
|
|
252
|
+
/** Request body for POST /v1/guard. */
|
|
253
|
+
interface GuardRequest {
|
|
254
|
+
/** Content to evaluate (prompt text, tool call arguments, file content, etc.). */
|
|
255
|
+
content: string;
|
|
256
|
+
content_type: ContentType;
|
|
257
|
+
/** Cedar action (e.g. process_prompt, call_tool, read_file, write_file). */
|
|
258
|
+
action: string;
|
|
259
|
+
/** Specific detectors to run. Empty runs all enabled detectors. */
|
|
260
|
+
detectors?: string[];
|
|
261
|
+
mode?: Mode;
|
|
262
|
+
/** Enable early exit on deny after each tier (skips slower tiers). */
|
|
263
|
+
early_exit?: boolean;
|
|
264
|
+
/** Include structured policy explanation showing why each determining policy matched. */
|
|
265
|
+
explain?: boolean;
|
|
266
|
+
/** Caller-provided metadata passed through to detectors. */
|
|
267
|
+
metadata?: Record<string, unknown>;
|
|
268
|
+
/** Reference material for context-aware detection (hallucination, groundedness). */
|
|
269
|
+
contexts?: string[];
|
|
270
|
+
/** Session ID for cross-turn state tracking. */
|
|
271
|
+
session_id?: string;
|
|
272
|
+
tool?: ToolContext;
|
|
273
|
+
model?: ModelContext;
|
|
274
|
+
file?: FileContext;
|
|
275
|
+
mcp?: MCPContext;
|
|
276
|
+
/** When true, only run detectors whose outputs are referenced by active policies. */
|
|
277
|
+
optimize?: boolean;
|
|
278
|
+
/** When true and optimize is true, return the optimization plan without executing. */
|
|
279
|
+
dry_run?: boolean;
|
|
280
|
+
/** Include debug_info showing exact Cedar evaluation inputs. */
|
|
281
|
+
debug?: boolean;
|
|
282
|
+
}
|
|
283
|
+
/** Detector optimization plan (when optimize=true). */
|
|
284
|
+
interface OptimizationReport {
|
|
285
|
+
/** Context keys required by active policies. */
|
|
286
|
+
required_context_keys: string[];
|
|
287
|
+
/** Detectors required by policies. */
|
|
288
|
+
required_detectors: DetectorPlanEntry[];
|
|
289
|
+
/** Detectors skipped (not required by policies). */
|
|
290
|
+
skipped_detectors: DetectorPlanEntry[];
|
|
291
|
+
/** Policies matching this action/product scope. */
|
|
292
|
+
active_policies: string[];
|
|
293
|
+
/** Why this optimization plan was chosen. */
|
|
294
|
+
reason: string;
|
|
295
|
+
/** True if fell back to running all detectors. */
|
|
296
|
+
fallback_to_all: boolean;
|
|
297
|
+
}
|
|
298
|
+
/** Root cause analysis for a triggered detection. */
|
|
299
|
+
interface RootCause {
|
|
300
|
+
/** Human-readable summary of the root cause. */
|
|
301
|
+
summary: string;
|
|
302
|
+
/** Detector that triggered. */
|
|
303
|
+
detector: string;
|
|
304
|
+
/** Key-value pairs explaining the threat. */
|
|
305
|
+
labels?: Record<string, string>;
|
|
306
|
+
/** Context values that caused the trigger. */
|
|
307
|
+
triggering_context: Record<string, unknown>;
|
|
308
|
+
/** Supporting evidence. */
|
|
309
|
+
evidence?: Record<string, unknown>;
|
|
310
|
+
/** Policy IDs triggered by this root cause. */
|
|
311
|
+
triggered_policies: string[];
|
|
312
|
+
}
|
|
313
|
+
/** Session state changes after evaluation. */
|
|
314
|
+
interface SessionDelta {
|
|
315
|
+
/** Updated turn count. */
|
|
316
|
+
turn_count: number;
|
|
317
|
+
/** Updated cumulative risk score (0-100). */
|
|
318
|
+
cumulative_risk: number;
|
|
319
|
+
/** Tokens used in this turn. */
|
|
320
|
+
tokens_used_delta?: number;
|
|
321
|
+
/** Action performed in this turn. */
|
|
322
|
+
new_action?: string;
|
|
323
|
+
}
|
|
324
|
+
/** Response from POST /v1/guard. */
|
|
325
|
+
interface GuardResponse {
|
|
326
|
+
decision: Decision;
|
|
327
|
+
/** Cedar decision before mode override. */
|
|
328
|
+
actual_decision?: string;
|
|
329
|
+
/** True if decision was changed by per-policy mode. */
|
|
330
|
+
mode_overridden?: boolean;
|
|
331
|
+
/** Strictest mode among determining policies. */
|
|
332
|
+
effective_mode?: string;
|
|
333
|
+
/** True when alert-mode policy fired. */
|
|
334
|
+
alerted?: boolean;
|
|
335
|
+
/** Human-readable policy decision reasoning. */
|
|
336
|
+
policy_reason?: string;
|
|
337
|
+
/** Mode override explanation (monitor/alert). */
|
|
338
|
+
mode_reason?: string;
|
|
339
|
+
/** Cedar diagnostic errors (rare). */
|
|
340
|
+
eval_errors?: string;
|
|
341
|
+
/** Unique audit trail ID. */
|
|
342
|
+
audit_id?: string;
|
|
343
|
+
/** Request trace ID. */
|
|
344
|
+
request_id?: string;
|
|
345
|
+
/** Response timestamp (RFC 3339). */
|
|
346
|
+
timestamp: string;
|
|
347
|
+
/** Policies that determined the decision. */
|
|
348
|
+
determining_policies?: DeterminingPolicy[];
|
|
349
|
+
/** Per-detector results. */
|
|
350
|
+
detectors: DetectorResult[];
|
|
351
|
+
/** Merged detector context. */
|
|
352
|
+
context: Record<string, unknown>;
|
|
353
|
+
/** Total evaluation latency in milliseconds. */
|
|
354
|
+
latency_ms: number;
|
|
355
|
+
/** Cedar evaluation latency in milliseconds. */
|
|
356
|
+
eval_latency_ms?: number;
|
|
357
|
+
/** Detector tiers that ran (fast, standard, slow). */
|
|
358
|
+
tiers_evaluated: string[];
|
|
359
|
+
/** Detector tiers skipped due to early exit. */
|
|
360
|
+
tiers_skipped?: string[];
|
|
361
|
+
session_delta?: SessionDelta;
|
|
362
|
+
agent_identity?: AgentIdentityTrace;
|
|
363
|
+
/** Structured policy explanation (when explain=true). */
|
|
364
|
+
explanation?: Record<string, unknown>;
|
|
365
|
+
/** Root cause analysis for triggered detections. */
|
|
366
|
+
root_causes?: RootCause[];
|
|
367
|
+
/** Cedar-normalized context (when debug=true). */
|
|
368
|
+
projected_context?: Record<string, unknown>;
|
|
369
|
+
optimization?: OptimizationReport;
|
|
370
|
+
debug_info?: DebugInfo;
|
|
371
|
+
}
|
|
372
|
+
/** Response from GET /v1/health. */
|
|
373
|
+
interface HealthResponse {
|
|
374
|
+
/** Overall health status. */
|
|
375
|
+
status: "healthy" | "degraded";
|
|
376
|
+
/** Per-detector health status. */
|
|
377
|
+
detectors?: Record<string, string>;
|
|
378
|
+
/** Cedar evaluator status. */
|
|
379
|
+
evaluator?: "ready" | "no_policies";
|
|
380
|
+
}
|
|
381
|
+
/** Response from GET /v1/detectors. */
|
|
382
|
+
interface ListDetectorsResponse {
|
|
383
|
+
/** Available detectors. */
|
|
384
|
+
detectors: DetectorInfo[];
|
|
385
|
+
/** Total number of registered detectors. */
|
|
386
|
+
count: number;
|
|
387
|
+
}
|
|
388
|
+
/** RFC 9457 Problem Details error format. */
|
|
389
|
+
interface ProblemDetails {
|
|
390
|
+
/** HTTP status code. */
|
|
391
|
+
status: number;
|
|
392
|
+
/** Short error title. */
|
|
393
|
+
title: string;
|
|
394
|
+
/** Detailed error message. */
|
|
395
|
+
detail?: string;
|
|
396
|
+
}
|
|
397
|
+
/** A Server-Sent Event from the guard stream. */
|
|
398
|
+
interface StreamEvent {
|
|
399
|
+
/** Event type: detector_result (per-detector), decision (final), or error. */
|
|
400
|
+
type: "detector_result" | "decision" | "error";
|
|
401
|
+
/** Event payload (DetectorResult for detector_result, GuardResponse for decision). */
|
|
402
|
+
data: Record<string, unknown>;
|
|
403
|
+
}
|
|
404
|
+
/** Response from the token exchange endpoint (used by SDK auth). */
|
|
405
|
+
interface TokenResponse {
|
|
406
|
+
/** RS256 JWT token. */
|
|
407
|
+
access_token: string;
|
|
408
|
+
/** Token type (always Bearer). */
|
|
409
|
+
token_type?: string;
|
|
410
|
+
/** Token lifetime in seconds. */
|
|
411
|
+
expires_in: number;
|
|
412
|
+
/** Account ID from token claims. */
|
|
413
|
+
account_id?: string;
|
|
414
|
+
/** Gateway ID from token claims. */
|
|
415
|
+
gateway_id?: string;
|
|
416
|
+
/** Project ID from token claims. */
|
|
417
|
+
project_id?: string;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Highflame SDK client — resource-based HTTP client for Highflame guardrails.
|
|
422
|
+
*
|
|
423
|
+
* Uses native fetch (Node 18+, browsers) with zero runtime dependencies.
|
|
424
|
+
*
|
|
425
|
+
* Usage:
|
|
426
|
+
*
|
|
427
|
+
* ```typescript
|
|
428
|
+
* import { Highflame } from "highflame";
|
|
429
|
+
*
|
|
430
|
+
* const client = new Highflame({ apiKey: "hf_sk_..." });
|
|
431
|
+
*
|
|
432
|
+
* // Guard
|
|
433
|
+
* const resp = await client.guard.evaluatePrompt("Hello world");
|
|
434
|
+
* const resp = await client.guard.evaluateToolCall("shell", { cmd: "ls" });
|
|
435
|
+
*
|
|
436
|
+
* // Detect (no policy evaluation)
|
|
437
|
+
* const resp = await client.detect.run({ content: "...", content_type: "prompt" });
|
|
438
|
+
*
|
|
439
|
+
* // List detectors
|
|
440
|
+
* const detectors = await client.detectors.list();
|
|
441
|
+
*
|
|
442
|
+
* // Debug
|
|
443
|
+
* const policies = await client.debug.policies();
|
|
444
|
+
* ```
|
|
445
|
+
*/
|
|
446
|
+
|
|
447
|
+
/** SDK version — kept in sync with package.json via `make version-sync`. */
|
|
448
|
+
declare const VERSION = "0.2.0";
|
|
449
|
+
/**
|
|
450
|
+
* Pluggable logger interface.
|
|
451
|
+
*
|
|
452
|
+
* Pass any object that satisfies this interface (e.g. `console`, a pino
|
|
453
|
+
* instance, or a custom wrapper) via `HighflameOptions.logger`.
|
|
454
|
+
*
|
|
455
|
+
* When no logger is provided, all logging is silently dropped.
|
|
456
|
+
*/
|
|
457
|
+
interface Logger {
|
|
458
|
+
debug(message: string, ...args: unknown[]): void;
|
|
459
|
+
info(message: string, ...args: unknown[]): void;
|
|
460
|
+
warn(message: string, ...args: unknown[]): void;
|
|
461
|
+
}
|
|
462
|
+
interface HighflameOptions {
|
|
463
|
+
/** Service API key (`hf_sk_...`) or a raw JWT. */
|
|
464
|
+
apiKey: string;
|
|
465
|
+
/** Base URL of the guard service. Defaults to Highflame SaaS. */
|
|
466
|
+
baseUrl?: string;
|
|
467
|
+
/** Token exchange URL. Defaults to Highflame SaaS. Only used for `hf_sk_*` keys. */
|
|
468
|
+
tokenUrl?: string;
|
|
469
|
+
/** Request timeout in milliseconds. Default: 30000. */
|
|
470
|
+
timeout?: number;
|
|
471
|
+
/** Number of retries on 429/5xx. Default: 2. */
|
|
472
|
+
maxRetries?: number;
|
|
473
|
+
/** Override X-Account-ID header. */
|
|
474
|
+
accountId?: string;
|
|
475
|
+
/** Override X-Project-ID header. */
|
|
476
|
+
projectId?: string;
|
|
477
|
+
/**
|
|
478
|
+
* Extra headers merged into every request. Useful for passing
|
|
479
|
+
* custom routing or identity headers.
|
|
480
|
+
*
|
|
481
|
+
* Example: `{ "X-Custom-Routing": "my-service" }`
|
|
482
|
+
*/
|
|
483
|
+
defaultHeaders?: Record<string, string>;
|
|
484
|
+
/**
|
|
485
|
+
* Optional logger for debug/info/warn messages. Pass `console` for quick
|
|
486
|
+
* debugging, or a structured logger (pino, winston) for production.
|
|
487
|
+
*
|
|
488
|
+
* Default: no logging.
|
|
489
|
+
*/
|
|
490
|
+
logger?: Logger;
|
|
491
|
+
}
|
|
492
|
+
/** Options accepted by individual request methods. */
|
|
493
|
+
interface RequestOptions {
|
|
494
|
+
/** Per-request timeout override in milliseconds. */
|
|
495
|
+
timeout?: number;
|
|
496
|
+
}
|
|
497
|
+
declare class GuardResource {
|
|
498
|
+
private readonly _client;
|
|
499
|
+
constructor(_client: Highflame);
|
|
500
|
+
/** Evaluate content against guard policies (POST /v1/guard). */
|
|
501
|
+
evaluate(request: GuardRequest, options?: RequestOptions): Promise<GuardResponse>;
|
|
502
|
+
/** Shorthand: evaluate a user prompt. */
|
|
503
|
+
evaluatePrompt(content: string, options?: {
|
|
504
|
+
mode?: Mode;
|
|
505
|
+
session_id?: string;
|
|
506
|
+
} & RequestOptions): Promise<GuardResponse>;
|
|
507
|
+
/** Shorthand: evaluate a tool call. */
|
|
508
|
+
evaluateToolCall(toolName: string, args?: Record<string, unknown>, options?: {
|
|
509
|
+
mode?: Mode;
|
|
510
|
+
session_id?: string;
|
|
511
|
+
} & RequestOptions): Promise<GuardResponse>;
|
|
512
|
+
/** Stream guard evaluation results (POST /v1/guard/stream). */
|
|
513
|
+
stream(request: GuardRequest, options?: RequestOptions): AsyncIterable<StreamEvent>;
|
|
514
|
+
}
|
|
515
|
+
declare class DetectResource {
|
|
516
|
+
private readonly _client;
|
|
517
|
+
constructor(_client: Highflame);
|
|
518
|
+
/** Run detectors without policy evaluation (POST /v1/detect). */
|
|
519
|
+
run(request: DetectRequest, options?: RequestOptions): Promise<DetectResponse>;
|
|
520
|
+
}
|
|
521
|
+
declare class DetectorsResource {
|
|
522
|
+
private readonly _client;
|
|
523
|
+
constructor(_client: Highflame);
|
|
524
|
+
/** List available detectors (GET /v1/detectors). */
|
|
525
|
+
list(options?: RequestOptions): Promise<ListDetectorsResponse>;
|
|
526
|
+
}
|
|
527
|
+
declare class DebugResource {
|
|
528
|
+
private readonly _client;
|
|
529
|
+
constructor(_client: Highflame);
|
|
530
|
+
/** Inspect loaded policies (GET /v1/debug/policies). */
|
|
531
|
+
policies(product?: string, options?: RequestOptions): Promise<DebugPoliciesResponse>;
|
|
532
|
+
}
|
|
533
|
+
declare class Highflame {
|
|
534
|
+
#private;
|
|
535
|
+
readonly guard: GuardResource;
|
|
536
|
+
readonly detect: DetectResource;
|
|
537
|
+
readonly detectors: DetectorsResource;
|
|
538
|
+
readonly debug: DebugResource;
|
|
539
|
+
constructor(options: HighflameOptions);
|
|
540
|
+
get accountId(): string;
|
|
541
|
+
get projectId(): string;
|
|
542
|
+
/** Get auth headers (exposed for external use with custom HTTP clients). */
|
|
543
|
+
getAuthHeaders(): Promise<Record<string, string>>;
|
|
544
|
+
/** @internal */
|
|
545
|
+
_fetchWithRetry(path: string, init: RequestInit, overrideTimeout?: number): Promise<Response>;
|
|
546
|
+
/** @internal */
|
|
547
|
+
_postJSON<T>(path: string, body: unknown, overrideTimeout?: number): Promise<T>;
|
|
548
|
+
/** @internal */
|
|
549
|
+
_getJSON<T>(path: string, overrideTimeout?: number): Promise<T>;
|
|
550
|
+
/** @internal */
|
|
551
|
+
_stream(path: string, body: unknown, overrideTimeout?: number): AsyncGenerator<StreamEvent>;
|
|
552
|
+
toString(): string;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Error hierarchy for the Highflame SDK.
|
|
557
|
+
*/
|
|
558
|
+
|
|
559
|
+
/** Base class for all SDK errors. */
|
|
560
|
+
declare class HighflameError extends Error {
|
|
561
|
+
constructor(message: string);
|
|
562
|
+
}
|
|
563
|
+
/** HTTP error from the API (RFC 9457 Problem Details). */
|
|
564
|
+
declare class APIError extends HighflameError {
|
|
565
|
+
readonly status: number;
|
|
566
|
+
readonly title: string;
|
|
567
|
+
readonly detail: string;
|
|
568
|
+
constructor(status: number, title: string, detail: string);
|
|
569
|
+
}
|
|
570
|
+
/** 401 Unauthorized — invalid or expired credentials. */
|
|
571
|
+
declare class AuthenticationError extends APIError {
|
|
572
|
+
constructor(detail?: string);
|
|
573
|
+
}
|
|
574
|
+
/** 429 Too Many Requests — rate limit exceeded. */
|
|
575
|
+
declare class RateLimitError extends APIError {
|
|
576
|
+
constructor(detail?: string);
|
|
577
|
+
}
|
|
578
|
+
/** Connection or timeout failure communicating with the API. */
|
|
579
|
+
declare class APIConnectionError extends HighflameError {
|
|
580
|
+
constructor(message: string);
|
|
581
|
+
}
|
|
582
|
+
/** Thrown by Shield wrappers when the guard decision is 'deny'. */
|
|
583
|
+
declare class BlockedError extends HighflameError {
|
|
584
|
+
readonly response: GuardResponse;
|
|
585
|
+
constructor(response: GuardResponse);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Shield — higher-order function wrapper for guardrails.
|
|
590
|
+
*
|
|
591
|
+
* JavaScript/TypeScript equivalent of the Python Shield decorator facade.
|
|
592
|
+
* Wraps any function (sync or async) with a guard check that throws
|
|
593
|
+
* {@link BlockedError} when the guard decision is "deny".
|
|
594
|
+
*
|
|
595
|
+
* Usage:
|
|
596
|
+
*
|
|
597
|
+
* ```typescript
|
|
598
|
+
* import { Shield, Highflame, BlockedError } from "highflame";
|
|
599
|
+
*
|
|
600
|
+
* const client = new Highflame({ apiKey: "hf_sk_xxx" });
|
|
601
|
+
* const shield = new Shield(client);
|
|
602
|
+
*
|
|
603
|
+
* const chat = shield.prompt(async (message: string) => llm.complete(message));
|
|
604
|
+
* const shell = shield.tool(async (cmd: string) => exec(cmd));
|
|
605
|
+
* ```
|
|
606
|
+
*/
|
|
607
|
+
|
|
608
|
+
interface PromptOptions {
|
|
609
|
+
mode?: Mode;
|
|
610
|
+
contentArg?: number;
|
|
611
|
+
sessionId?: string;
|
|
612
|
+
}
|
|
613
|
+
interface ToolOptions {
|
|
614
|
+
mode?: Mode;
|
|
615
|
+
toolName?: string;
|
|
616
|
+
sessionId?: string;
|
|
617
|
+
}
|
|
618
|
+
interface ToolResponseOptions {
|
|
619
|
+
mode?: Mode;
|
|
620
|
+
toolName?: string;
|
|
621
|
+
sessionId?: string;
|
|
622
|
+
}
|
|
623
|
+
interface ModelResponseOptions {
|
|
624
|
+
mode?: Mode;
|
|
625
|
+
sessionId?: string;
|
|
626
|
+
}
|
|
627
|
+
interface WrapOptions {
|
|
628
|
+
contentType: GuardRequest["content_type"];
|
|
629
|
+
action: GuardRequest["action"];
|
|
630
|
+
contentArg?: number;
|
|
631
|
+
mode?: Mode;
|
|
632
|
+
sessionId?: string;
|
|
633
|
+
}
|
|
634
|
+
declare class Shield {
|
|
635
|
+
private readonly client;
|
|
636
|
+
constructor(client: Highflame);
|
|
637
|
+
prompt<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn | Promise<TReturn>, options?: PromptOptions): (...args: TArgs) => Promise<Awaited<TReturn>>;
|
|
638
|
+
tool<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn | Promise<TReturn>, options?: ToolOptions): (...args: TArgs) => Promise<Awaited<TReturn>>;
|
|
639
|
+
toolResponse<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn | Promise<TReturn>, options?: ToolResponseOptions): (...args: TArgs) => Promise<Awaited<TReturn>>;
|
|
640
|
+
modelResponse<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn | Promise<TReturn>, options?: ModelResponseOptions): (...args: TArgs) => Promise<Awaited<TReturn>>;
|
|
641
|
+
wrap(options: WrapOptions): <TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn | Promise<TReturn>) => (...args: TArgs) => Promise<Awaited<TReturn>>;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
export { APIConnectionError, APIError, type AgentIdentityTrace, AuthenticationError, BlockedError, type ContentType, type ContextKeySpec, type DebugInfo, type DebugPoliciesResponse, DebugResource, type Decision, type DetectRequest, DetectResource, type DetectResponse, type DetectorInfo, type DetectorResult, DetectorsResource, type DeterminingPolicy, type FileContext, type GuardRequest, GuardResource, type GuardResponse, type HealthResponse, Highflame, HighflameError, type HighflameOptions, type ListDetectorsResponse, type Logger, type MCPContext, type Mode, type ModelContext, type ModelResponseOptions, type OptimizationReport, type PolicySummary, type ProblemDetails, type PromptOptions, RateLimitError, type RequestOptions, type RootCause, type SessionDelta, Shield, type StreamEvent, type TokenResponse, type ToolContext, type ToolOptions, type ToolResponseOptions, VERSION, type WrapOptions };
|