avantgate 1.8.1 → 2.0.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 CHANGED
@@ -88,10 +88,10 @@ Contact our team at [contact@gatewall.fr](mailto:contact@gatewall.fr) for privat
88
88
 
89
89
  | Pillar | Core Capabilities & Architecture |
90
90
  |---|---|
91
- | 🛡️ **AI-WAF & Privacy** | • **Prompt Guardrails**: Blocks prompt injections, jailbreaks & exfiltration *pre-flight*.<br/>• **Zero-Egress DLP**: In-process redaction of emails, phone numbers, IBANs & EU tax IDs.<br/>• **Self-Repairing Outputs**: Native Zod validation with automatic JSON heuristic repair. |
92
- | 🛑 **Agent Isolation & Anti-IDOR** | • **Dual-Channel DTOs**: Streams full records to UI while injecting sanitized summaries into LLM.<br/>• **Anti-IDOR Boundary**: Compile-time tenant scoping (`createTenantTool`) & runtime ownership checks.<br/>• **Infinite Loop Shield**: Detects and breaks recursive agent tool execution loops. |
93
- | 💰 **FinOps & Resilience** | • **Denial-of-Wallet**: Enforces hard token & USD budgets *before* external inference spend.<br/>• **Multi-Model Failover**: Instant client-side routing to fallback models or local Ollama on 429/500.<br/>• **Live Cost Ledger**: Token burn calculation & pricing adapters with zero external DB. |
94
- | ⚡ **Sagas & Telemetry** | • **Deterministic Sagas (`avantgate/workflow`)**: In-process FSM with automatic reverse compensation ($k-1 \to 0$).<br/>• **Human-in-the-Loop (HITL)**: Non-blocking suspension & approval queues for high-risk tools.<br/>• **Lightweight Telemetry (`avantgate/client`)**: < 1.7 KB client SDK & async audit bridge to GateWall. |
91
+ | 🛡️ **AI-WAF & Privacy** | • **Prompt Guardrails**: Blocks prompt injections, jailbreaks & exfiltration *pre-flight*.<br/>• **Zero-Egress DLP**: In-process redaction of emails, phone numbers, IBANs & EU tax IDs.<br/>• **Bidirectional Secret Guard**: Active DLP masking of API keys & database credentials in LLM outputs and error traces.<br/>• **Self-Repairing Outputs**: Native Zod validation with automatic JSON heuristic repair. |
92
+ | 🛑 **Agent Isolation & Anti-IDOR** | • **Dual-Channel DTOs**: Streams full records to UI while injecting sanitized summaries into LLM.<br/>• **Anti-IDOR Boundary**: Compile-time tenant scoping (`createTenantTool`) & runtime ownership checks.<br/>• **Server Idempotency Guard**: Zero-infra in-process guard (`withServerIdempotency`) with memory or storage adapters.<br/>• **Infinite Loop Shield**: Detects and breaks recursive agent tool execution loops. |
93
+ | 💰 **FinOps & Resilience** | • **Denial-of-Wallet**: Enforces hard token & USD budgets *before* external inference spend.<br/>• **Multi-Model Failover**: Instant client-side routing to fallback models or local Ollama on 429/500.<br/>• **FinOps Batch Deduplication**: Prevents double-counting of tokens & costs during network retries on GateWall.<br/>• **Live Cost Ledger**: Token burn calculation & pricing adapters with zero external DB. |
94
+ | ⚡ **Sagas, Replay & Telemetry** | • **Deterministic Sagas (`avantgate/workflow`)**: In-process FSM with automatic reverse compensation ($k-1 \to 0$).<br/>• **In-Context Replay (`avantgate/client`)**: React hook (`useTask`) with causal parent linkage (`parentRunId`) & `Idempotency-Key`.<br/>• **Human-in-the-Loop (HITL)**: Non-blocking suspension, approval queues & fail-closed 24h SLA timeout (TTL).<br/>• **Lightweight Telemetry**: < 1.7 KB client SDK & async audit bridge to GateWall. |
95
95
 
96
96
  ---
97
97
 
@@ -104,8 +104,9 @@ Contact our team at [contact@gatewall.fr](mailto:contact@gatewall.fr) for privat
104
104
  | 💰 **FinOps & Cost** | [Pre-Flight Budget Guards](docs/finops/budget-guards.md) • [Pricing Adapters & SQLite](docs/finops/pricing-adapters.md) |
105
105
  | 🤖 **Agents & Tools** | [Isolated Tools & DTOs](docs/agents/isolated-tools.md) • [Agent Runtime Manual](docs/agents/agent-runtime.md) • [Inter-Tool Chaining](docs/agents/inter-tool-chaining.md) |
106
106
  | 🔄 **Deterministic Sagas** | [Durable Workflows Engine](docs/workflows/durable-workflows.md) |
107
- | 📊 **Observability** | [GateWall Cockpit Console](docs/observability/gatewall-cockpit.md) • [Telemetry & Browser SDK](docs/observability/telemetry-and-browser-sdk.md) |
107
+ | 📊 **Observability & Cockpit** | [GateWall Cockpit Console](docs/observability/gatewall-cockpit.md) • [Telemetry & Browser SDK](docs/observability/telemetry-and-browser-sdk.md) • [GateWall vs. Temporal](docs/observability/temporal-and-gatewall.md) |
108
108
  | 💶 **Accounting** | [Financial Normalizer](docs/finance/normalizer.md) |
109
+ | 🚀 **Release Notes** | [v2.0.0 Release Notes](docs/release/release-2.0.0.md) • [v1.9.0 Release Notes](docs/release/release-1.9.0.md) |
109
110
 
110
111
  ---
111
112
 
@@ -119,10 +120,11 @@ Contact our team at [contact@gatewall.fr](mailto:contact@gatewall.fr) for privat
119
120
  | **Prompt Injection Defense** | ❌ None | ⚠️ Passive detection | ✅ **Active Pre-Flight Guard (Blocks before spend)** |
120
121
  | **Agent Tool Data Isolation** | ❌ Entire DB entity in LLM | ❌ No agent tool awareness | ✅ **Dual-Channel DTO (`clientDto` vs `llmDto`)** |
121
122
  | **Row-Level Security & Anti-IDOR** | ❌ Manual code | ❌ Not supported | ✅ **Native `dataAccessGuard` & Domain Boundary** |
123
+ | **Bidirectional Idempotency** | ❌ Manual / none | ⚠️ Basic header relay | ✅ **Native causal key derivation + server guard + batch deduplication** |
122
124
  | **Infrastructure Overhead** | None | SaaS Subscription | ✅ **$0 / Zero Servers (Pure npm package)** |
123
125
  | **Multi-Model Failover** | ❌ App crashes | ⚠️ Proxy-dependent | ✅ **Built-in Fallback Router & Exponential Retry** |
124
126
  | **Zod Schema Auto-Repair** | ❌ No | ❌ No | ✅ **Built-in JSON Heuristic Repair** |
125
- | **Hierarchical Session Replay** | ❌ None | ⚠️ Flat span waterfall | ✅ **Causality Tree + Dual-Channel Isolation** |
127
+ | **Hierarchical Session Replay** | ❌ None | ⚠️ Flat span waterfall | ✅ **Causality Tree + In-Context Replay (`useTask`)** |
126
128
 
127
129
  ---
128
130
 
@@ -142,9 +144,9 @@ yarn add avantgate zod
142
144
  |---|---|
143
145
  | `avantgate` | Core control plane: token budgets, cost ledger, prompt guards, multi-model failover & Zod repair. |
144
146
  | `avantgate/finance` | Financial data normalizer (accounting parentheses, EU/US/UK/CH currencies & magnitudes). |
145
- | `avantgate/agent` | *(Preview / Experimental)* Durable step runner, Human-in-the-Loop, dual-channel PII tool isolation & storage adapters. |
147
+ | `avantgate/agent` | Durable step runner, Human-in-the-Loop, dual-channel PII tool isolation, server idempotency (`withServerIdempotency`), & storage adapters. |
146
148
  | `avantgate/workflow` | Deterministic sequential state machine, automatic reverse Saga rollback, durable HITL checkpoints & agent tool conversion. |
147
- | `avantgate/client` | Lightweight front-end SDK (< 1.7 KB) & React hook to stream browser security alerts & metrics directly to GateWall. |
149
+ | `avantgate/client` | Front-end SDK (< 1.7 KB) with in-context task replay (`useTask`, `createTaskRunner`), causal idempotency helpers (`getIdempotencyHeaders`), & GateWall telemetry adapter. |
148
150
 
149
151
  ---
150
152
 
@@ -0,0 +1,13 @@
1
+ import type { StepStorageAdapter } from "./types";
2
+ export interface IdempotencyStore {
3
+ get(key: string): Promise<unknown | undefined> | unknown | undefined;
4
+ set(key: string, value: unknown, ttlSeconds?: number): Promise<void> | void;
5
+ }
6
+ export interface ServerIdempotencyResult<TResult> {
7
+ result: TResult;
8
+ isCached: boolean;
9
+ }
10
+ export declare const withServerIdempotency: <TResult>(idempotencyKey: string | null | undefined, store: IdempotencyStore, handler: () => Promise<TResult>, ttlSeconds?: number) => Promise<ServerIdempotencyResult<TResult>>;
11
+ export declare const createMemoryIdempotencyStore: () => IdempotencyStore;
12
+ export declare const createAdapterIdempotencyStore: (adapter: StepStorageAdapter, namespace?: string) => IdempotencyStore;
13
+ //# sourceMappingURL=idempotency-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idempotency-guard.d.ts","sourceRoot":"","sources":["../../src/agent/idempotency-guard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,GAAG,OAAO,GAAG,SAAS,CAAC;IACrE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC7E;AAED,MAAM,WAAW,uBAAuB,CAAC,OAAO;IAC9C,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,eAAO,MAAM,qBAAqB,GAAU,OAAO,EACjD,gBAAgB,MAAM,GAAG,IAAI,GAAG,SAAS,EACzC,OAAO,gBAAgB,EACvB,SAAS,MAAM,OAAO,CAAC,OAAO,CAAC,EAC/B,mBAAkB,KACjB,OAAO,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAc1C,CAAC;AAEF,eAAO,MAAM,4BAA4B,QAAO,gBAoB/C,CAAC;AAEF,eAAO,MAAM,6BAA6B,GACxC,SAAS,kBAAkB,EAC3B,kBAAyB,KACxB,gBAyBF,CAAC"}
@@ -15,4 +15,5 @@ export * from "./tool-invoker";
15
15
  export * from "./tool-state";
16
16
  export * from "./adapters";
17
17
  export * from "./telemetry";
18
+ export * from "./idempotency-guard";
18
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
@@ -45,13 +45,16 @@ __export(agent_exports, {
45
45
  ToolSubCallQuotaError: () => ToolSubCallQuotaError,
46
46
  applyToolStrategy: () => applyToolStrategy,
47
47
  auditToolResult: () => auditToolResult,
48
+ createAdapterIdempotencyStore: () => createAdapterIdempotencyStore,
48
49
  createCustomStorageAdapter: () => createCustomStorageAdapter,
49
50
  createIsolatedTool: () => createIsolatedTool,
51
+ createMemoryIdempotencyStore: () => createMemoryIdempotencyStore,
50
52
  createStepRunner: () => createStepRunner,
51
53
  createTenantTool: () => createTenantTool,
52
54
  createToolInvoker: () => createToolInvoker,
53
55
  createToolSharedState: () => createToolSharedState,
54
- dto: () => dto
56
+ dto: () => dto,
57
+ withServerIdempotency: () => withServerIdempotency
55
58
  });
56
59
  module.exports = __toCommonJS(agent_exports);
57
60
 
@@ -2072,6 +2075,67 @@ var HttpTelemetryExporter = class {
2072
2075
  await this.flush();
2073
2076
  }
2074
2077
  };
2078
+
2079
+ // src/agent/idempotency-guard.ts
2080
+ var withServerIdempotency = async (idempotencyKey, store, handler, ttlSeconds = 86400) => {
2081
+ if (!idempotencyKey) {
2082
+ const result2 = await handler();
2083
+ return { result: result2, isCached: false };
2084
+ }
2085
+ const cached = await store.get(idempotencyKey);
2086
+ if (cached !== void 0) {
2087
+ return { result: cached, isCached: true };
2088
+ }
2089
+ const result = await handler();
2090
+ await store.set(idempotencyKey, result, ttlSeconds);
2091
+ return { result, isCached: false };
2092
+ };
2093
+ var createMemoryIdempotencyStore = () => {
2094
+ const cache = /* @__PURE__ */ new Map();
2095
+ return {
2096
+ get: (key) => {
2097
+ const entry = cache.get(key);
2098
+ if (!entry) {
2099
+ return void 0;
2100
+ }
2101
+ if (entry.expiresAt && Date.now() > entry.expiresAt) {
2102
+ cache.delete(key);
2103
+ return void 0;
2104
+ }
2105
+ return entry.value;
2106
+ },
2107
+ set: (key, value, ttlSeconds) => {
2108
+ const expiresAt = ttlSeconds ? Date.now() + ttlSeconds * 1e3 : void 0;
2109
+ cache.set(key, { value, expiresAt });
2110
+ }
2111
+ };
2112
+ };
2113
+ var createAdapterIdempotencyStore = (adapter, namespace = "idempotency") => {
2114
+ return {
2115
+ get: async (key) => {
2116
+ const scopedKey = `${namespace}:${key}`;
2117
+ if (adapter.getStateValue) {
2118
+ const val = await adapter.getStateValue(scopedKey);
2119
+ return val === null ? void 0 : val;
2120
+ }
2121
+ if (adapter.getCachedToolResult) {
2122
+ const val = await adapter.getCachedToolResult(scopedKey);
2123
+ return val === null ? void 0 : val;
2124
+ }
2125
+ return void 0;
2126
+ },
2127
+ set: async (key, value, ttlSeconds) => {
2128
+ const scopedKey = `${namespace}:${key}`;
2129
+ if (adapter.setStateValue) {
2130
+ await adapter.setStateValue(scopedKey, value, ttlSeconds);
2131
+ return;
2132
+ }
2133
+ if (adapter.setCachedToolResult) {
2134
+ await adapter.setCachedToolResult(scopedKey, value, ttlSeconds ?? 86400);
2135
+ }
2136
+ }
2137
+ };
2138
+ };
2075
2139
  // Annotate the CommonJS export names for ESM import in node:
2076
2140
  0 && (module.exports = {
2077
2141
  AccessControlToolStrategy,
@@ -2099,11 +2163,14 @@ var HttpTelemetryExporter = class {
2099
2163
  ToolSubCallQuotaError,
2100
2164
  applyToolStrategy,
2101
2165
  auditToolResult,
2166
+ createAdapterIdempotencyStore,
2102
2167
  createCustomStorageAdapter,
2103
2168
  createIsolatedTool,
2169
+ createMemoryIdempotencyStore,
2104
2170
  createStepRunner,
2105
2171
  createTenantTool,
2106
2172
  createToolInvoker,
2107
2173
  createToolSharedState,
2108
- dto
2174
+ dto,
2175
+ withServerIdempotency
2109
2176
  });
@@ -1630,6 +1630,67 @@ var HttpTelemetryExporter = class {
1630
1630
  await this.flush();
1631
1631
  }
1632
1632
  };
1633
+
1634
+ // src/agent/idempotency-guard.ts
1635
+ var withServerIdempotency = async (idempotencyKey, store, handler, ttlSeconds = 86400) => {
1636
+ if (!idempotencyKey) {
1637
+ const result2 = await handler();
1638
+ return { result: result2, isCached: false };
1639
+ }
1640
+ const cached = await store.get(idempotencyKey);
1641
+ if (cached !== void 0) {
1642
+ return { result: cached, isCached: true };
1643
+ }
1644
+ const result = await handler();
1645
+ await store.set(idempotencyKey, result, ttlSeconds);
1646
+ return { result, isCached: false };
1647
+ };
1648
+ var createMemoryIdempotencyStore = () => {
1649
+ const cache = /* @__PURE__ */ new Map();
1650
+ return {
1651
+ get: (key) => {
1652
+ const entry = cache.get(key);
1653
+ if (!entry) {
1654
+ return void 0;
1655
+ }
1656
+ if (entry.expiresAt && Date.now() > entry.expiresAt) {
1657
+ cache.delete(key);
1658
+ return void 0;
1659
+ }
1660
+ return entry.value;
1661
+ },
1662
+ set: (key, value, ttlSeconds) => {
1663
+ const expiresAt = ttlSeconds ? Date.now() + ttlSeconds * 1e3 : void 0;
1664
+ cache.set(key, { value, expiresAt });
1665
+ }
1666
+ };
1667
+ };
1668
+ var createAdapterIdempotencyStore = (adapter, namespace = "idempotency") => {
1669
+ return {
1670
+ get: async (key) => {
1671
+ const scopedKey = `${namespace}:${key}`;
1672
+ if (adapter.getStateValue) {
1673
+ const val = await adapter.getStateValue(scopedKey);
1674
+ return val === null ? void 0 : val;
1675
+ }
1676
+ if (adapter.getCachedToolResult) {
1677
+ const val = await adapter.getCachedToolResult(scopedKey);
1678
+ return val === null ? void 0 : val;
1679
+ }
1680
+ return void 0;
1681
+ },
1682
+ set: async (key, value, ttlSeconds) => {
1683
+ const scopedKey = `${namespace}:${key}`;
1684
+ if (adapter.setStateValue) {
1685
+ await adapter.setStateValue(scopedKey, value, ttlSeconds);
1686
+ return;
1687
+ }
1688
+ if (adapter.setCachedToolResult) {
1689
+ await adapter.setCachedToolResult(scopedKey, value, ttlSeconds ?? 86400);
1690
+ }
1691
+ }
1692
+ };
1693
+ };
1633
1694
  export {
1634
1695
  AccessControlToolStrategy,
1635
1696
  AgentToolFactory,
@@ -1656,11 +1717,14 @@ export {
1656
1717
  ToolSubCallQuotaError,
1657
1718
  applyToolStrategy,
1658
1719
  auditToolResult,
1720
+ createAdapterIdempotencyStore,
1659
1721
  createCustomStorageAdapter,
1660
1722
  createIsolatedTool,
1723
+ createMemoryIdempotencyStore,
1661
1724
  createStepRunner,
1662
1725
  createTenantTool,
1663
1726
  createToolInvoker,
1664
1727
  createToolSharedState,
1665
- dto
1728
+ dto,
1729
+ withServerIdempotency
1666
1730
  };
@@ -43,6 +43,9 @@ export interface ToolExecutionTelemetryEvent extends BaseTelemetryEvent {
43
43
  success: boolean;
44
44
  parentToolId?: string;
45
45
  depth?: number;
46
+ attempts?: number;
47
+ maxRetries?: number;
48
+ retriedErrors?: string[];
46
49
  llmSummary?: unknown;
47
50
  piiFilteredCount?: number;
48
51
  tokenCount?: number;
@@ -75,6 +78,11 @@ export interface TelemetryIngestPayload {
75
78
  timestamp: string;
76
79
  events: TelemetryEvent[];
77
80
  usage?: TelemetryUsageSummary;
81
+ metadata?: {
82
+ retryOf?: string;
83
+ replayedBy?: string;
84
+ [key: string]: unknown;
85
+ };
78
86
  }
79
87
  /**
80
88
  * Configuration options for the HTTP Telemetry Exporter.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/agent/telemetry/types.ts"],"names":[],"mappings":"AAAA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,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,KAAK,CAAC,EAAE,qBAAqB,CAAC;IAC9B,QAAQ,CAAC,EAAE;QACT,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;IACvB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC"}
@@ -15,9 +15,9 @@ export interface TrackFeedbackOptions {
15
15
  comment?: string;
16
16
  }
17
17
  /**
18
- * Public interface for the universal (framework-agnostic) avantGate telemetry client.
18
+ * Public interface for the universal (framework-agnostic) telemetry client.
19
19
  */
20
- export interface AvantGateClient {
20
+ export interface Client {
21
21
  trackSecurityAlert: (alertType: ClientSecurityAlertEvent["alertType"], details: TrackSecurityAlertDetails) => void;
22
22
  trackClientDataRendered: (toolId: string, options?: TrackDataRenderedOptions) => void;
23
23
  trackFeedback: (feedback: TrackFeedbackOptions) => void;
@@ -30,8 +30,8 @@ export interface AvantGateClient {
30
30
  exporter: BrowserTelemetryExporter;
31
31
  }
32
32
  /**
33
- * Creates a universal, framework-agnostic avantGate client instance.
33
+ * Creates a universal, framework-agnostic client instance.
34
34
  * Works seamlessly in Vite (Vanilla JS, Vue, Svelte, SolidJS), Next.js, or browser scripts.
35
35
  */
36
- export declare const createAvantGateClient: (config: BrowserTelemetryExporterConfig) => AvantGateClient;
36
+ export declare const createClient: (config: BrowserTelemetryExporterConfig) => Client;
37
37
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EACV,8BAA8B,EAC9B,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,yBAAyB;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,wBAAwB;IACvC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;CACxC;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;IAChC,GAAG,CAAC,EAAE,SAAS,GAAG,YAAY,GAAG,QAAQ,GAAG,WAAW,CAAC;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,CAClB,SAAS,EAAE,wBAAwB,CAAC,WAAW,CAAC,EAChD,OAAO,EAAE,yBAAyB,KAC/B,IAAI,CAAC;IACV,uBAAuB,EAAE,CACvB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,wBAAwB,KAC/B,IAAI,CAAC;IACV,aAAa,EAAE,CAAC,QAAQ,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACxD,aAAa,EAAE,CAAC,OAAO,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACzE,KAAK,EAAE,MAAM,OAAO,CAA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CAAA;KAAE,KAAK,IAAI,CAAC;IACzE,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,EAAE,wBAAwB,CAAC;CACpC;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,GACvB,QAAQ,8BAA8B,KACrC,MAkDF,CAAC"}
@@ -1,5 +1,9 @@
1
1
  export { BrowserTelemetryExporter } from "./browser-exporter";
2
- export { createAvantGateClient, type AvantGateClient, type TrackSecurityAlertDetails, type TrackDataRenderedOptions, type TrackFeedbackOptions, } from "./client";
3
- export { useAvantGateTelemetry } from "./useAvantGateTelemetry";
4
- export type { ClientSecurityAlertEvent, ClientDataRenderedEvent, UserFeedbackEvent, ClientTelemetryEvent, BrowserTelemetryExporterConfig, ClientTelemetryIngestPayload, } from "./types";
2
+ export { createClient, type Client, type TrackDataRenderedOptions, type TrackFeedbackOptions, type TrackSecurityAlertDetails, } from "./client";
3
+ export { useTask } from "./useTask";
4
+ export { useTelemetry } from "./useTelemetry";
5
+ export { createTaskRunner, type TaskRunner, type TaskRunnerOptions, } from "./task-runner";
6
+ export { deriveOpaqueTaskId, generateRunId, createInitialTaskState, validateRetryEligibility, getIdempotencyKey, getIdempotencyHeaders, } from "./task-utils";
7
+ export type { TaskExecutionContext, TaskState, UseTaskOptions, UseTaskReturn, } from "./task-types";
8
+ export type { BrowserTelemetryExporterConfig, ClientDataRenderedEvent, ClientSecurityAlertEvent, ClientTelemetryEvent, ClientTelemetryIngestPayload, UserFeedbackEvent, } from "./types";
5
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EACL,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,GAC1B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EACV,wBAAwB,EACxB,uBAAuB,EACvB,iBAAiB,EACjB,oBAAoB,EACpB,8BAA8B,EAC9B,4BAA4B,GAC7B,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EACL,YAAY,EACZ,KAAK,MAAM,EACX,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,GAC/B,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EACL,gBAAgB,EAChB,KAAK,UAAU,EACf,KAAK,iBAAiB,GACvB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,sBAAsB,EACtB,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,oBAAoB,EACpB,SAAS,EACT,cAAc,EACd,aAAa,GACd,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,4BAA4B,EAC5B,iBAAiB,GAClB,MAAM,SAAS,CAAC"}
@@ -21,8 +21,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var client_exports = {};
22
22
  __export(client_exports, {
23
23
  BrowserTelemetryExporter: () => BrowserTelemetryExporter,
24
- createAvantGateClient: () => createAvantGateClient,
25
- useAvantGateTelemetry: () => useAvantGateTelemetry
24
+ createClient: () => createClient,
25
+ createInitialTaskState: () => createInitialTaskState,
26
+ createTaskRunner: () => createTaskRunner,
27
+ deriveOpaqueTaskId: () => deriveOpaqueTaskId,
28
+ generateRunId: () => generateRunId,
29
+ getIdempotencyHeaders: () => getIdempotencyHeaders,
30
+ getIdempotencyKey: () => getIdempotencyKey,
31
+ useTask: () => useTask,
32
+ useTelemetry: () => useTelemetry,
33
+ validateRetryEligibility: () => validateRetryEligibility
26
34
  });
27
35
  module.exports = __toCommonJS(client_exports);
28
36
 
@@ -162,7 +170,7 @@ var BrowserTelemetryExporter = class {
162
170
  };
163
171
 
164
172
  // src/client/client.ts
165
- var createAvantGateClient = (config) => {
173
+ var createClient = (config) => {
166
174
  const exporter = new BrowserTelemetryExporter(config);
167
175
  const trackSecurityAlert = (alertType, details) => {
168
176
  const snippet = details.snippet ?? details.matchedPatternSnippet;
@@ -204,44 +212,246 @@ var createAvantGateClient = (config) => {
204
212
  };
205
213
  };
206
214
 
207
- // src/client/useAvantGateTelemetry.ts
215
+ // src/client/useTask.ts
208
216
  var import_react = require("react");
209
- var useAvantGateTelemetry = (config) => {
210
- const clientRef = (0, import_react.useRef)(null);
211
- if (!clientRef.current) {
212
- clientRef.current = createAvantGateClient(config);
217
+
218
+ // src/client/task-utils.ts
219
+ var import_crypto = require("crypto");
220
+ var deriveOpaqueTaskId = (taskName, tenantSalt) => {
221
+ if (!tenantSalt) {
222
+ return taskName;
223
+ }
224
+ const digest = (0, import_crypto.createHmac)("sha256", tenantSalt).update(taskName).digest("hex").slice(0, 12);
225
+ return `tsk_${digest}`;
226
+ };
227
+ var generateRunId = (taskId) => {
228
+ const timestamp = Date.now();
229
+ const randomSuffix = Math.random().toString(36).slice(2, 7);
230
+ return `run_${taskId}_${timestamp}_${randomSuffix}`;
231
+ };
232
+ var createInitialTaskState = (taskId, tenantId) => ({
233
+ isRunning: false,
234
+ isFailed: false,
235
+ isSuccess: false,
236
+ attempts: 0,
237
+ error: null,
238
+ data: null,
239
+ runId: null,
240
+ parentRunId: null,
241
+ taskId,
242
+ tenantId: tenantId ?? null
243
+ });
244
+ var validateRetryEligibility = ({
245
+ isRunning,
246
+ attemptCount,
247
+ maxRetries,
248
+ hasPreviousInput
249
+ }) => {
250
+ if (isRunning) {
251
+ throw new Error("Task is already running");
252
+ }
253
+ if (attemptCount >= maxRetries) {
254
+ throw new Error(`Maximum manual retry limit (${maxRetries}) reached. Please reset.`);
213
255
  }
256
+ if (!hasPreviousInput) {
257
+ throw new Error("Cannot retry: no previous execution input found");
258
+ }
259
+ };
260
+ var getIdempotencyKey = (ctx) => ctx.parentRunId ?? ctx.runId;
261
+ var getIdempotencyHeaders = (ctx) => ({
262
+ "Idempotency-Key": getIdempotencyKey(ctx)
263
+ });
264
+
265
+ // src/client/task-runner.ts
266
+ var createTaskRunner = (initialOptions) => {
267
+ let options = { ...initialOptions };
268
+ let opaqueTaskId = deriveOpaqueTaskId(options.taskName, options.tenantSalt);
269
+ let state = createInitialTaskState(opaqueTaskId, options.tenantId);
270
+ let lastInput = null;
271
+ const listeners = /* @__PURE__ */ new Set();
272
+ const notify = () => {
273
+ listeners.forEach((listener) => listener(state));
274
+ };
275
+ const setState = (updater) => {
276
+ state = updater(state);
277
+ notify();
278
+ };
279
+ const markExecutionStart = (newRunId, parentRunId) => {
280
+ setState((prev) => ({
281
+ ...prev,
282
+ isRunning: true,
283
+ isFailed: false,
284
+ isSuccess: false,
285
+ error: null,
286
+ attempts: prev.attempts + 1,
287
+ runId: newRunId,
288
+ parentRunId: parentRunId ?? null
289
+ }));
290
+ };
291
+ const handleExecutionSuccess = (result) => {
292
+ setState((prev) => ({
293
+ ...prev,
294
+ isRunning: false,
295
+ isSuccess: true,
296
+ data: result
297
+ }));
298
+ options.onSuccess?.(result);
299
+ };
300
+ const handleExecutionError = (err) => {
301
+ const errorObj = err instanceof Error ? err : new Error(String(err));
302
+ setState((prev) => ({
303
+ ...prev,
304
+ isRunning: false,
305
+ isFailed: true,
306
+ error: errorObj
307
+ }));
308
+ options.onError?.(errorObj);
309
+ return errorObj;
310
+ };
311
+ const executeTask = async (input, parentRunId) => {
312
+ lastInput = input;
313
+ const newRunId = generateRunId(opaqueTaskId);
314
+ markExecutionStart(newRunId, parentRunId);
315
+ try {
316
+ const result = await options.handler(input, {
317
+ runId: newRunId,
318
+ parentRunId,
319
+ attempt: state.attempts,
320
+ taskId: opaqueTaskId,
321
+ tenantId: options.tenantId
322
+ });
323
+ handleExecutionSuccess(result);
324
+ return result;
325
+ } catch (err) {
326
+ throw handleExecutionError(err);
327
+ }
328
+ };
329
+ const run = (input) => {
330
+ state = { ...state, attempts: 0 };
331
+ return executeTask(input);
332
+ };
333
+ const retry = () => {
334
+ validateRetryEligibility({
335
+ isRunning: state.isRunning,
336
+ attemptCount: state.attempts,
337
+ maxRetries: options.maxManualRetries ?? 3,
338
+ hasPreviousInput: lastInput !== null
339
+ });
340
+ return executeTask(lastInput, state.runId ?? void 0);
341
+ };
342
+ const reset = () => {
343
+ lastInput = null;
344
+ setState(() => createInitialTaskState(opaqueTaskId, options.tenantId));
345
+ };
346
+ const updateOptions = (newOptions) => {
347
+ options = { ...options, ...newOptions };
348
+ opaqueTaskId = deriveOpaqueTaskId(options.taskName, options.tenantSalt);
349
+ setState((prev) => ({
350
+ ...prev,
351
+ taskId: opaqueTaskId,
352
+ tenantId: options.tenantId ?? null
353
+ }));
354
+ };
355
+ const subscribe = (listener) => {
356
+ listeners.add(listener);
357
+ return () => {
358
+ listeners.delete(listener);
359
+ };
360
+ };
361
+ const destroy = () => {
362
+ listeners.clear();
363
+ };
364
+ return {
365
+ getState: () => state,
366
+ subscribe,
367
+ run,
368
+ retry,
369
+ reset,
370
+ updateOptions,
371
+ destroy
372
+ };
373
+ };
374
+
375
+ // src/client/useTask.ts
376
+ var useTask = (options) => {
377
+ const runnerRef = (0, import_react.useRef)(null);
378
+ if (!runnerRef.current) {
379
+ runnerRef.current = createTaskRunner(options);
380
+ }
381
+ const [state, setState] = (0, import_react.useState)(
382
+ () => runnerRef.current.getState()
383
+ );
384
+ (0, import_react.useEffect)(() => {
385
+ runnerRef.current?.updateOptions(options);
386
+ });
387
+ (0, import_react.useEffect)(() => {
388
+ const runner = runnerRef.current;
389
+ if (!runner) return;
390
+ return runner.subscribe(setState);
391
+ }, []);
214
392
  (0, import_react.useEffect)(() => {
393
+ return () => {
394
+ runnerRef.current?.destroy();
395
+ runnerRef.current = null;
396
+ };
397
+ }, []);
398
+ const run = (0, import_react.useCallback)(
399
+ (input) => runnerRef.current.run(input),
400
+ []
401
+ );
402
+ const retry = (0, import_react.useCallback)(
403
+ () => runnerRef.current.retry(),
404
+ []
405
+ );
406
+ const reset = (0, import_react.useCallback)(() => {
407
+ runnerRef.current.reset();
408
+ }, []);
409
+ return {
410
+ ...state,
411
+ run,
412
+ retry,
413
+ reset
414
+ };
415
+ };
416
+
417
+ // src/client/useTelemetry.ts
418
+ var import_react2 = require("react");
419
+ var useTelemetry = (config) => {
420
+ const clientRef = (0, import_react2.useRef)(null);
421
+ if (!clientRef.current) {
422
+ clientRef.current = createClient(config);
423
+ }
424
+ (0, import_react2.useEffect)(() => {
215
425
  clientRef.current?.updateContext({
216
426
  runId: config.runId,
217
427
  agentName: config.agentName
218
428
  });
219
429
  }, [config.runId, config.agentName]);
220
- (0, import_react.useEffect)(() => {
430
+ (0, import_react2.useEffect)(() => {
221
431
  return () => {
222
432
  clientRef.current?.destroy();
223
433
  clientRef.current = null;
224
434
  };
225
435
  }, []);
226
- const trackSecurityAlert = (0, import_react.useCallback)(
436
+ const trackSecurityAlert = (0, import_react2.useCallback)(
227
437
  (alertType, details) => {
228
438
  clientRef.current?.trackSecurityAlert(alertType, details);
229
439
  },
230
440
  []
231
441
  );
232
- const trackClientDataRendered = (0, import_react.useCallback)(
442
+ const trackClientDataRendered = (0, import_react2.useCallback)(
233
443
  (toolId, options) => {
234
444
  clientRef.current?.trackClientDataRendered(toolId, options);
235
445
  },
236
446
  []
237
447
  );
238
- const trackFeedback = (0, import_react.useCallback)(
448
+ const trackFeedback = (0, import_react2.useCallback)(
239
449
  (feedback) => {
240
450
  clientRef.current?.trackFeedback(feedback);
241
451
  },
242
452
  []
243
453
  );
244
- return (0, import_react.useMemo)(
454
+ return (0, import_react2.useMemo)(
245
455
  () => ({
246
456
  trackSecurityAlert,
247
457
  trackClientDataRendered,
@@ -254,6 +464,14 @@ var useAvantGateTelemetry = (config) => {
254
464
  // Annotate the CommonJS export names for ESM import in node:
255
465
  0 && (module.exports = {
256
466
  BrowserTelemetryExporter,
257
- createAvantGateClient,
258
- useAvantGateTelemetry
467
+ createClient,
468
+ createInitialTaskState,
469
+ createTaskRunner,
470
+ deriveOpaqueTaskId,
471
+ generateRunId,
472
+ getIdempotencyHeaders,
473
+ getIdempotencyKey,
474
+ useTask,
475
+ useTelemetry,
476
+ validateRetryEligibility
259
477
  });
@@ -136,7 +136,7 @@ var BrowserTelemetryExporter = class {
136
136
  };
137
137
 
138
138
  // src/client/client.ts
139
- var createAvantGateClient = (config) => {
139
+ var createClient = (config) => {
140
140
  const exporter = new BrowserTelemetryExporter(config);
141
141
  const trackSecurityAlert = (alertType, details) => {
142
142
  const snippet = details.snippet ?? details.matchedPatternSnippet;
@@ -178,38 +178,240 @@ var createAvantGateClient = (config) => {
178
178
  };
179
179
  };
180
180
 
181
- // src/client/useAvantGateTelemetry.ts
182
- import { useRef, useEffect, useCallback, useMemo } from "react";
183
- var useAvantGateTelemetry = (config) => {
184
- const clientRef = useRef(null);
185
- if (!clientRef.current) {
186
- clientRef.current = createAvantGateClient(config);
181
+ // src/client/useTask.ts
182
+ import { useCallback, useEffect, useRef, useState } from "react";
183
+
184
+ // src/client/task-utils.ts
185
+ import { createHmac } from "crypto";
186
+ var deriveOpaqueTaskId = (taskName, tenantSalt) => {
187
+ if (!tenantSalt) {
188
+ return taskName;
189
+ }
190
+ const digest = createHmac("sha256", tenantSalt).update(taskName).digest("hex").slice(0, 12);
191
+ return `tsk_${digest}`;
192
+ };
193
+ var generateRunId = (taskId) => {
194
+ const timestamp = Date.now();
195
+ const randomSuffix = Math.random().toString(36).slice(2, 7);
196
+ return `run_${taskId}_${timestamp}_${randomSuffix}`;
197
+ };
198
+ var createInitialTaskState = (taskId, tenantId) => ({
199
+ isRunning: false,
200
+ isFailed: false,
201
+ isSuccess: false,
202
+ attempts: 0,
203
+ error: null,
204
+ data: null,
205
+ runId: null,
206
+ parentRunId: null,
207
+ taskId,
208
+ tenantId: tenantId ?? null
209
+ });
210
+ var validateRetryEligibility = ({
211
+ isRunning,
212
+ attemptCount,
213
+ maxRetries,
214
+ hasPreviousInput
215
+ }) => {
216
+ if (isRunning) {
217
+ throw new Error("Task is already running");
218
+ }
219
+ if (attemptCount >= maxRetries) {
220
+ throw new Error(`Maximum manual retry limit (${maxRetries}) reached. Please reset.`);
221
+ }
222
+ if (!hasPreviousInput) {
223
+ throw new Error("Cannot retry: no previous execution input found");
187
224
  }
225
+ };
226
+ var getIdempotencyKey = (ctx) => ctx.parentRunId ?? ctx.runId;
227
+ var getIdempotencyHeaders = (ctx) => ({
228
+ "Idempotency-Key": getIdempotencyKey(ctx)
229
+ });
230
+
231
+ // src/client/task-runner.ts
232
+ var createTaskRunner = (initialOptions) => {
233
+ let options = { ...initialOptions };
234
+ let opaqueTaskId = deriveOpaqueTaskId(options.taskName, options.tenantSalt);
235
+ let state = createInitialTaskState(opaqueTaskId, options.tenantId);
236
+ let lastInput = null;
237
+ const listeners = /* @__PURE__ */ new Set();
238
+ const notify = () => {
239
+ listeners.forEach((listener) => listener(state));
240
+ };
241
+ const setState = (updater) => {
242
+ state = updater(state);
243
+ notify();
244
+ };
245
+ const markExecutionStart = (newRunId, parentRunId) => {
246
+ setState((prev) => ({
247
+ ...prev,
248
+ isRunning: true,
249
+ isFailed: false,
250
+ isSuccess: false,
251
+ error: null,
252
+ attempts: prev.attempts + 1,
253
+ runId: newRunId,
254
+ parentRunId: parentRunId ?? null
255
+ }));
256
+ };
257
+ const handleExecutionSuccess = (result) => {
258
+ setState((prev) => ({
259
+ ...prev,
260
+ isRunning: false,
261
+ isSuccess: true,
262
+ data: result
263
+ }));
264
+ options.onSuccess?.(result);
265
+ };
266
+ const handleExecutionError = (err) => {
267
+ const errorObj = err instanceof Error ? err : new Error(String(err));
268
+ setState((prev) => ({
269
+ ...prev,
270
+ isRunning: false,
271
+ isFailed: true,
272
+ error: errorObj
273
+ }));
274
+ options.onError?.(errorObj);
275
+ return errorObj;
276
+ };
277
+ const executeTask = async (input, parentRunId) => {
278
+ lastInput = input;
279
+ const newRunId = generateRunId(opaqueTaskId);
280
+ markExecutionStart(newRunId, parentRunId);
281
+ try {
282
+ const result = await options.handler(input, {
283
+ runId: newRunId,
284
+ parentRunId,
285
+ attempt: state.attempts,
286
+ taskId: opaqueTaskId,
287
+ tenantId: options.tenantId
288
+ });
289
+ handleExecutionSuccess(result);
290
+ return result;
291
+ } catch (err) {
292
+ throw handleExecutionError(err);
293
+ }
294
+ };
295
+ const run = (input) => {
296
+ state = { ...state, attempts: 0 };
297
+ return executeTask(input);
298
+ };
299
+ const retry = () => {
300
+ validateRetryEligibility({
301
+ isRunning: state.isRunning,
302
+ attemptCount: state.attempts,
303
+ maxRetries: options.maxManualRetries ?? 3,
304
+ hasPreviousInput: lastInput !== null
305
+ });
306
+ return executeTask(lastInput, state.runId ?? void 0);
307
+ };
308
+ const reset = () => {
309
+ lastInput = null;
310
+ setState(() => createInitialTaskState(opaqueTaskId, options.tenantId));
311
+ };
312
+ const updateOptions = (newOptions) => {
313
+ options = { ...options, ...newOptions };
314
+ opaqueTaskId = deriveOpaqueTaskId(options.taskName, options.tenantSalt);
315
+ setState((prev) => ({
316
+ ...prev,
317
+ taskId: opaqueTaskId,
318
+ tenantId: options.tenantId ?? null
319
+ }));
320
+ };
321
+ const subscribe = (listener) => {
322
+ listeners.add(listener);
323
+ return () => {
324
+ listeners.delete(listener);
325
+ };
326
+ };
327
+ const destroy = () => {
328
+ listeners.clear();
329
+ };
330
+ return {
331
+ getState: () => state,
332
+ subscribe,
333
+ run,
334
+ retry,
335
+ reset,
336
+ updateOptions,
337
+ destroy
338
+ };
339
+ };
340
+
341
+ // src/client/useTask.ts
342
+ var useTask = (options) => {
343
+ const runnerRef = useRef(null);
344
+ if (!runnerRef.current) {
345
+ runnerRef.current = createTaskRunner(options);
346
+ }
347
+ const [state, setState] = useState(
348
+ () => runnerRef.current.getState()
349
+ );
188
350
  useEffect(() => {
351
+ runnerRef.current?.updateOptions(options);
352
+ });
353
+ useEffect(() => {
354
+ const runner = runnerRef.current;
355
+ if (!runner) return;
356
+ return runner.subscribe(setState);
357
+ }, []);
358
+ useEffect(() => {
359
+ return () => {
360
+ runnerRef.current?.destroy();
361
+ runnerRef.current = null;
362
+ };
363
+ }, []);
364
+ const run = useCallback(
365
+ (input) => runnerRef.current.run(input),
366
+ []
367
+ );
368
+ const retry = useCallback(
369
+ () => runnerRef.current.retry(),
370
+ []
371
+ );
372
+ const reset = useCallback(() => {
373
+ runnerRef.current.reset();
374
+ }, []);
375
+ return {
376
+ ...state,
377
+ run,
378
+ retry,
379
+ reset
380
+ };
381
+ };
382
+
383
+ // src/client/useTelemetry.ts
384
+ import { useCallback as useCallback2, useEffect as useEffect2, useMemo, useRef as useRef2 } from "react";
385
+ var useTelemetry = (config) => {
386
+ const clientRef = useRef2(null);
387
+ if (!clientRef.current) {
388
+ clientRef.current = createClient(config);
389
+ }
390
+ useEffect2(() => {
189
391
  clientRef.current?.updateContext({
190
392
  runId: config.runId,
191
393
  agentName: config.agentName
192
394
  });
193
395
  }, [config.runId, config.agentName]);
194
- useEffect(() => {
396
+ useEffect2(() => {
195
397
  return () => {
196
398
  clientRef.current?.destroy();
197
399
  clientRef.current = null;
198
400
  };
199
401
  }, []);
200
- const trackSecurityAlert = useCallback(
402
+ const trackSecurityAlert = useCallback2(
201
403
  (alertType, details) => {
202
404
  clientRef.current?.trackSecurityAlert(alertType, details);
203
405
  },
204
406
  []
205
407
  );
206
- const trackClientDataRendered = useCallback(
408
+ const trackClientDataRendered = useCallback2(
207
409
  (toolId, options) => {
208
410
  clientRef.current?.trackClientDataRendered(toolId, options);
209
411
  },
210
412
  []
211
413
  );
212
- const trackFeedback = useCallback(
414
+ const trackFeedback = useCallback2(
213
415
  (feedback) => {
214
416
  clientRef.current?.trackFeedback(feedback);
215
417
  },
@@ -227,6 +429,14 @@ var useAvantGateTelemetry = (config) => {
227
429
  };
228
430
  export {
229
431
  BrowserTelemetryExporter,
230
- createAvantGateClient,
231
- useAvantGateTelemetry
432
+ createClient,
433
+ createInitialTaskState,
434
+ createTaskRunner,
435
+ deriveOpaqueTaskId,
436
+ generateRunId,
437
+ getIdempotencyHeaders,
438
+ getIdempotencyKey,
439
+ useTask,
440
+ useTelemetry,
441
+ validateRetryEligibility
232
442
  };
@@ -0,0 +1,13 @@
1
+ import { TaskState, UseTaskOptions } from "./task-types";
2
+ export type TaskRunnerOptions<TInput, TOutput> = UseTaskOptions<TInput, TOutput>;
3
+ export interface TaskRunner<TInput, TOutput> {
4
+ getState: () => TaskState<TOutput>;
5
+ subscribe: (listener: (state: TaskState<TOutput>) => void) => () => void;
6
+ run: (input: TInput) => Promise<TOutput>;
7
+ retry: () => Promise<TOutput>;
8
+ reset: () => void;
9
+ updateOptions: (newOptions: Partial<UseTaskOptions<TInput, TOutput>>) => void;
10
+ destroy: () => void;
11
+ }
12
+ export declare const createTaskRunner: <TInput, TOutput>(initialOptions: UseTaskOptions<TInput, TOutput>) => TaskRunner<TInput, TOutput>;
13
+ //# sourceMappingURL=task-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-runner.d.ts","sourceRoot":"","sources":["../../src/client/task-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAQzD,MAAM,MAAM,iBAAiB,CAAC,MAAM,EAAE,OAAO,IAAI,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjF,MAAM,WAAW,UAAU,CAAC,MAAM,EAAE,OAAO;IACzC,QAAQ,EAAE,MAAM,SAAS,CAAC,OAAO,CAAC,CAAC;IACnC,SAAS,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;IACzE,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACzC,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,aAAa,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC;IAC9E,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,eAAO,MAAM,gBAAgB,GAAI,MAAM,EAAE,OAAO,EAC9C,gBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,KAC9C,UAAU,CAAC,MAAM,EAAE,OAAO,CAiI5B,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Context provided to task handlers during execution.
3
+ */
4
+ export interface TaskExecutionContext {
5
+ runId: string;
6
+ parentRunId?: string;
7
+ attempt: number;
8
+ taskId: string;
9
+ tenantId?: string;
10
+ }
11
+ /**
12
+ * Configuration options for the useTask hook.
13
+ */
14
+ export interface UseTaskOptions<TInput, TOutput> {
15
+ taskName: string;
16
+ tenantId?: string;
17
+ tenantSalt?: string;
18
+ maxManualRetries?: number;
19
+ handler: (input: TInput, context: TaskExecutionContext) => Promise<TOutput>;
20
+ onSuccess?: (data: TOutput) => void;
21
+ onError?: (error: Error) => void;
22
+ }
23
+ /**
24
+ * State snapshot of the task lifecycle.
25
+ */
26
+ export interface TaskState<TOutput> {
27
+ isRunning: boolean;
28
+ isFailed: boolean;
29
+ isSuccess: boolean;
30
+ attempts: number;
31
+ error: Error | null;
32
+ data: TOutput | null;
33
+ runId: string | null;
34
+ parentRunId: string | null;
35
+ taskId: string;
36
+ tenantId: string | null;
37
+ }
38
+ /**
39
+ * Return interface of useTask.
40
+ */
41
+ export interface UseTaskReturn<TInput, TOutput> extends TaskState<TOutput> {
42
+ run: (input: TInput) => Promise<TOutput>;
43
+ retry: () => Promise<TOutput>;
44
+ reset: () => void;
45
+ }
46
+ //# sourceMappingURL=task-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-types.d.ts","sourceRoot":"","sources":["../../src/client/task-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,MAAM,EAAE,OAAO;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5E,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACpC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,OAAO;IAChC,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IACrB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,MAAM,EAAE,OAAO,CAAE,SAAQ,SAAS,CAAC,OAAO,CAAC;IACxE,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACzC,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB"}
@@ -0,0 +1,37 @@
1
+ import { TaskState } from "./task-types";
2
+ /**
3
+ * Derives an opaque task identifier using HMAC-SHA256 with tenant salt.
4
+ * Why: Guarantees Zero-Knowledge Telemetry by obfuscating confidential business operations
5
+ * (e.g. "wire_transfer", "patient_biopsy") in logs while preserving deterministic correlation.
6
+ */
7
+ export declare const deriveOpaqueTaskId: (taskName: string, tenantSalt?: string) => string;
8
+ /**
9
+ * Generates a scoped unique run ID for a task attempt.
10
+ * Why: Provides deterministic prefixing for APM tracing and Cockpit session linking.
11
+ */
12
+ export declare const generateRunId: (taskId: string) => string;
13
+ /**
14
+ * Creates the initial default state for a task.
15
+ * Why: Reusable reset baseline ensuring consistency across mount and reset cycles.
16
+ */
17
+ export declare const createInitialTaskState: <TOutput>(taskId: string, tenantId?: string) => TaskState<TOutput>;
18
+ export interface RetryValidationParams {
19
+ isRunning: boolean;
20
+ attemptCount: number;
21
+ maxRetries: number;
22
+ hasPreviousInput: boolean;
23
+ }
24
+ /**
25
+ * Validates whether a retry attempt is permitted.
26
+ * Why: Protects against FinOps token budget exhaustion and UI double-click race conditions.
27
+ */
28
+ export declare const validateRetryEligibility: ({ isRunning, attemptCount, maxRetries, hasPreviousInput, }: RetryValidationParams) => void;
29
+ export declare const getIdempotencyKey: (ctx: {
30
+ runId: string;
31
+ parentRunId?: string | null;
32
+ }) => string;
33
+ export declare const getIdempotencyHeaders: (ctx: {
34
+ runId: string;
35
+ parentRunId?: string | null;
36
+ }) => Record<string, string>;
37
+ //# sourceMappingURL=task-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-utils.d.ts","sourceRoot":"","sources":["../../src/client/task-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,EAAE,aAAa,MAAM,KAAG,MAS1E,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,QAAQ,MAAM,KAAG,MAI9C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,GAAI,OAAO,EAC5C,QAAQ,MAAM,EACd,WAAW,MAAM,KAChB,SAAS,CAAC,OAAO,CAWlB,CAAC;AAEH,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED;;;GAGG;AACH,eAAO,MAAM,wBAAwB,GAAI,4DAKtC,qBAAqB,KAAG,IAU1B,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,KAAK;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,KAAG,MAAsC,CAAC;AAE3C,eAAO,MAAM,qBAAqB,GAAI,KAAK;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAEvB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { TaskState, TaskExecutionContext, UseTaskOptions, UseTaskReturn } from "./task-types";
2
+ import { deriveOpaqueTaskId } from "./task-utils";
3
+ import { createTaskRunner, type TaskRunner, type TaskRunnerOptions } from "./task-runner";
4
+ export { deriveOpaqueTaskId, createTaskRunner, type TaskState, type TaskExecutionContext, type UseTaskOptions, type UseTaskReturn, type TaskRunner, type TaskRunnerOptions, };
5
+ export declare const useTask: <TInput, TOutput>(options: UseTaskOptions<TInput, TOutput>) => UseTaskReturn<TInput, TOutput>;
6
+ //# sourceMappingURL=useTask.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTask.d.ts","sourceRoot":"","sources":["../../src/client/useTask.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,oBAAoB,EACpB,cAAc,EACd,aAAa,EACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EACL,gBAAgB,EAChB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACvB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,iBAAiB,GACvB,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,MAAM,EAAE,OAAO,EACrC,SAAS,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,KACvC,aAAa,CAAC,MAAM,EAAE,OAAO,CAgD/B,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type TrackDataRenderedOptions, type TrackFeedbackOptions, type TrackSecurityAlertDetails } from "./client";
2
+ import type { BrowserTelemetryExporterConfig, ClientSecurityAlertEvent } from "./types";
3
+ export type { TrackDataRenderedOptions, TrackFeedbackOptions, TrackSecurityAlertDetails, };
4
+ export declare const useTelemetry: (config: BrowserTelemetryExporterConfig) => {
5
+ trackSecurityAlert: (alertType: ClientSecurityAlertEvent["alertType"], details: TrackSecurityAlertDetails) => void;
6
+ trackClientDataRendered: (toolId: string, options?: TrackDataRenderedOptions) => void;
7
+ trackFeedback: (feedback: TrackFeedbackOptions) => void;
8
+ exporter: import("./browser-exporter").BrowserTelemetryExporter | undefined;
9
+ };
10
+ //# sourceMappingURL=useTelemetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTelemetry.d.ts","sourceRoot":"","sources":["../../src/client/useTelemetry.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC/B,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EACV,8BAA8B,EAC9B,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAEjB,YAAY,EACV,wBAAwB,EACxB,oBAAoB,EACpB,yBAAyB,GAC1B,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,QAAQ,8BAA8B;oCAuBlD,wBAAwB,CAAC,WAAW,CAAC,WACvC,yBAAyB,KACjC,IAAI;sCAQG,MAAM,YACJ,wBAAwB,KACjC,IAAI;8BAOI,oBAAoB,KAAG,IAAI;;CAezC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "avantgate",
3
- "version": "1.8.1",
3
+ "version": "2.0.0",
4
4
  "description": "Zero-infrastructure, in-process AI Application Firewall (AI-WAF) & privacy control plane for TypeScript: real-time prompt guardrails, zero-egress PII redaction, agent tool isolation, anti-IDOR defense, pre-flight token budgets, and multi-model failover.",
5
5
  "author": "Gatewall Team",
6
6
  "license": "MIT",
@@ -88,20 +88,21 @@
88
88
  "test:finance": "tsx tests/financial-normalizer.test.ts",
89
89
  "test:prompts": "tsx tests/prompt-builder.test.ts",
90
90
  "test:pii": "tsx tests/pii-extended.test.ts",
91
- "test:agent": "tsx tests/agent/step-runner.test.ts && tsx tests/agent/isolated-tool.test.ts && tsx tests/agent/dto-pattern.test.ts && tsx tests/agent/tool-patterns.test.ts && tsx tests/agent/storage-adapters.test.ts && tsx tests/agent/tool-aliasing.test.ts && tsx tests/agent/tool-chaining.test.ts && tsx tests/agent/tool-storage.test.ts && tsx tests/agent/telemetry-exporter.test.ts && tsx tests/agent/platform-adapter.test.ts && tsx tests/agent/tool-governance.test.ts && tsx tests/agent/tool-impact.test.ts",
91
+ "test:agent": "tsx tests/agent/step-runner.test.ts && tsx tests/agent/isolated-tool.test.ts && tsx tests/agent/dto-pattern.test.ts && tsx tests/agent/tool-patterns.test.ts && tsx tests/agent/storage-adapters.test.ts && tsx tests/agent/tool-aliasing.test.ts && tsx tests/agent/tool-chaining.test.ts && tsx tests/agent/tool-storage.test.ts && tsx tests/agent/telemetry-exporter.test.ts && tsx tests/agent/platform-adapter.test.ts && tsx tests/agent/tool-governance.test.ts && tsx tests/agent/tool-impact.test.ts && tsx tests/agent/idempotency-guard.test.ts",
92
92
  "test:workflow": "tsx tests/workflow/workflow-saga.test.ts && tsx tests/workflow/workflow-abort.test.ts",
93
- "test:client": "tsx tests/client/browser-exporter.test.ts",
93
+ "test:client": "tsx tests/client/browser-exporter.test.ts && tsx tests/client/use-avantgate-task.test.ts && tsx tests/client/task-runner.test.ts",
94
94
  "test:demo": "tsx tests/agent/prospect-ai-demo-scenario.test.ts",
95
95
  "gatewall": "npm --prefix gatewall run dev",
96
96
  "gatewall:dev": "npm --prefix gatewall run dev",
97
97
  "gatewall:build": "npm --prefix gatewall run build",
98
+ "gatewall:seed": "npm --prefix gatewall run seed:mock",
98
99
  "gatewall:start": "npm --prefix gatewall run start",
99
100
  "gatewall:docker": "docker compose up -d",
100
101
  "lint": "tsc --noEmit",
101
102
  "prepublishOnly": "npm run build && npm test"
102
103
  },
103
104
  "dependencies": {
104
- "zod": "^3.23.0 || ^4.0.0"
105
+ "zod": "^4.6.5"
105
106
  },
106
107
  "devDependencies": {
107
108
  "@types/node": "^26.6.2",
@@ -1,14 +0,0 @@
1
- import { type TrackSecurityAlertDetails, type TrackDataRenderedOptions, type TrackFeedbackOptions } from "./client";
2
- import type { BrowserTelemetryExporterConfig, ClientSecurityAlertEvent } from "./types";
3
- export type { TrackSecurityAlertDetails, TrackDataRenderedOptions, TrackFeedbackOptions, };
4
- /**
5
- * Lightweight React Hook for front-end telemetry and client-side security event tracking.
6
- * Encapsulates lifecycle management, useRef persistence, useCallback and useMemo optimization.
7
- */
8
- export declare const useAvantGateTelemetry: (config: BrowserTelemetryExporterConfig) => {
9
- trackSecurityAlert: (alertType: ClientSecurityAlertEvent["alertType"], details: TrackSecurityAlertDetails) => void;
10
- trackClientDataRendered: (toolId: string, options?: TrackDataRenderedOptions) => void;
11
- trackFeedback: (feedback: TrackFeedbackOptions) => void;
12
- exporter: import("./browser-exporter").BrowserTelemetryExporter | undefined;
13
- };
14
- //# sourceMappingURL=useAvantGateTelemetry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAvantGateTelemetry.d.ts","sourceRoot":"","sources":["../../src/client/useAvantGateTelemetry.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EAC1B,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EACV,8BAA8B,EAC9B,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAEjB,YAAY,EACV,yBAAyB,EACzB,wBAAwB,EACxB,oBAAoB,GACrB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,8BAA8B;oCAuB3D,wBAAwB,CAAC,WAAW,CAAC,WACvC,yBAAyB,KACjC,IAAI;sCAQG,MAAM,YACJ,wBAAwB,KACjC,IAAI;8BAOI,oBAAoB,KAAG,IAAI;;CAezC,CAAC"}