flare-redact 1.5.1 → 1.6.1

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.
@@ -0,0 +1,136 @@
1
+ import { type RedactOptions } from './index.js';
2
+ export type AgentFlowViolationReason = 'unknown_token' | 'key_position' | 'capability_denied' | 'capability_budget_exceeded' | 'sink_budget_exceeded';
3
+ export interface AgentFlowBudget {
4
+ /** Maximum restored placeholder occurrences across the lifetime of the flow. */
5
+ maxUses?: number;
6
+ /** Maximum distinct protected values restored to this sink. */
7
+ maxUniqueValues?: number;
8
+ /** Maximum cumulative UTF-8 bytes restored to this sink. */
9
+ maxBytes?: number;
10
+ }
11
+ export interface AgentFlowCapability {
12
+ /** Stable, audit-safe identifier. First matching capability wins. */
13
+ id: string;
14
+ /** Trusted source ids, or `*`. */
15
+ sources: readonly string[] | '*';
16
+ /** Detector ids, or `*`. Defaults to `*`. */
17
+ detectors?: readonly string[] | '*';
18
+ /** JSON Pointer patterns. `*` matches one segment; a terminal `**` matches descendants. */
19
+ paths: readonly string[];
20
+ /** Optional cumulative occurrence budget for this capability. */
21
+ maxUses?: number;
22
+ }
23
+ export interface AgentFlowSinkPolicy {
24
+ capabilities: readonly AgentFlowCapability[];
25
+ /** Cumulative sink-wide leakage budget. */
26
+ budget?: AgentFlowBudget;
27
+ }
28
+ export interface AgentFlowLimits {
29
+ /** Lifetime of a protected value before its mapping is forgotten. Default: 1 hour. */
30
+ tokenTtlMs: number;
31
+ /** Maximum live protected values. Default: 10,000. */
32
+ maxMappings: number;
33
+ /** Maximum retained value-free audit events. Default: 1,000. */
34
+ maxEvents: number;
35
+ }
36
+ export interface AgentFlowViolation {
37
+ reason: AgentFlowViolationReason;
38
+ sink: string;
39
+ /** JSON Pointer to the string carrying the placeholder. Empty string is the root. */
40
+ path: string;
41
+ source?: string;
42
+ detector?: string;
43
+ capability?: string;
44
+ limit?: keyof AgentFlowBudget;
45
+ }
46
+ export interface AgentFlowBudgetUsage {
47
+ uses: number;
48
+ uniqueValues: number;
49
+ bytes: number;
50
+ }
51
+ export interface AgentFlowDecision {
52
+ allowed: boolean;
53
+ sink: string;
54
+ occurrences: number;
55
+ restorable: number;
56
+ violations: readonly AgentFlowViolation[];
57
+ projectedBudget: Readonly<AgentFlowBudgetUsage>;
58
+ }
59
+ export type AgentFlowEvent = {
60
+ type: 'protected';
61
+ time: number;
62
+ source: string;
63
+ occurrences: number;
64
+ detectors: readonly string[];
65
+ liveMappings: number;
66
+ } | {
67
+ type: 'authorized';
68
+ time: number;
69
+ sink: string;
70
+ occurrences: number;
71
+ capabilities: readonly string[];
72
+ budget: Readonly<AgentFlowBudgetUsage>;
73
+ } | {
74
+ type: 'blocked';
75
+ time: number;
76
+ sink: string;
77
+ occurrences: number;
78
+ violations: readonly AgentFlowViolation[];
79
+ } | {
80
+ type: 'revoked';
81
+ time: number;
82
+ source?: string;
83
+ mappings: number;
84
+ };
85
+ export interface AgentFlowSnapshot {
86
+ liveMappings: number;
87
+ sources: Readonly<Record<string, number>>;
88
+ sinks: Readonly<Record<string, Readonly<AgentFlowBudgetUsage>>>;
89
+ events: readonly AgentFlowEvent[];
90
+ }
91
+ export interface AgentFlowOptions {
92
+ /** Detection policy applied before data enters model context. */
93
+ policy?: RedactOptions;
94
+ /** Runtime-owned sink policy. Never derive this object from model output. */
95
+ sinks?: Readonly<Record<string, AgentFlowSinkPolicy>>;
96
+ limits?: Partial<AgentFlowLimits>;
97
+ /** Receives value-free events only. */
98
+ onEvent?: (event: AgentFlowEvent) => void;
99
+ /** Injectable monotonic wall clock for deterministic tests. */
100
+ now?: () => number;
101
+ }
102
+ export interface AgentFlow {
103
+ /** Detect and replace sensitive source values before they enter model context. */
104
+ protectForModel<T>(source: string, value: T): T;
105
+ /** Inspect a model-produced sink call without restoring or consuming budget. */
106
+ inspectForSink(sink: string, value: unknown): AgentFlowDecision;
107
+ /** Atomically authorize and restore a sink call, or throw without restoring anything. */
108
+ authorizeForSink<T>(sink: string, value: T): T;
109
+ /** Restore all live mappings only at the trusted final application boundary. */
110
+ restoreForApp<T>(value: T): T;
111
+ /** Revoke every mapping minted by one trusted source. */
112
+ revokeSource(source: string): number;
113
+ /** Forget mappings and counters, replacing retained history with one reset event. */
114
+ reset(): void;
115
+ /** Value-free state suitable for audit logs and tests. */
116
+ snapshot(): AgentFlowSnapshot;
117
+ readonly size: number;
118
+ }
119
+ export declare class AgentFlowBlockedError extends Error {
120
+ readonly code = "ERR_AGENT_FLOW_BLOCKED";
121
+ readonly sink: string;
122
+ readonly decision: AgentFlowDecision;
123
+ constructor(decision: AgentFlowDecision);
124
+ }
125
+ export declare class AgentFlowLimitError extends Error {
126
+ readonly code = "ERR_AGENT_FLOW_LIMIT";
127
+ constructor(message: string);
128
+ }
129
+ /**
130
+ * FlareFlow: deterministic, model-independent information-flow enforcement for
131
+ * tool-using agents. The trusted runtime labels sources and sinks; model output
132
+ * can carry opaque placeholders but cannot grant itself permission to restore
133
+ * them.
134
+ */
135
+ export declare function createAgentFlow(options?: AgentFlowOptions): AgentFlow;
136
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAS/D,MAAM,MAAM,wBAAwB,GAChC,eAAe,GACf,cAAc,GACd,mBAAmB,GACnB,4BAA4B,GAC5B,sBAAsB,CAAC;AAE3B,MAAM,WAAW,eAAe;IAC9B,gFAAgF;IAChF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,qEAAqE;IACrE,EAAE,EAAE,MAAM,CAAC;IACX,kCAAkC;IAClC,OAAO,EAAE,SAAS,MAAM,EAAE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