avantgate 2.2.0 → 2.3.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 +3 -1
- package/dist/control-layer.d.ts +20 -2
- package/dist/control-layer.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +283 -29
- package/dist/index.mjs +275 -29
- package/dist/middleware.d.ts +15 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/presets.d.ts +13 -0
- package/dist/presets.d.ts.map +1 -0
- package/dist/types.d.ts +38 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -94,7 +94,7 @@ Contact our team at [contact@gatewall.fr](mailto:contact@gatewall.fr) for privat
|
|
|
94
94
|
| 📊 **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) |
|
|
95
95
|
| 💶 **Accounting** | [Financial Normalizer](docs/finance/normalizer.md) |
|
|
96
96
|
| 🎨 **Presentation Plane** | [Headless UI Canvas & React Bindings](docs/ui/headless-canvas.md) |
|
|
97
|
-
| 🚀 **Release Notes** | [v2.1.0 Release Notes](docs/release/release-2.1.0.md) • [v2.0.0 Release Notes](docs/release/release-2.0.0.md) • [v1.9.0 Release Notes](docs/release/release-1.9.0.md) |
|
|
97
|
+
| 🚀 **Release Notes** | [v2.3.0 Release Notes](docs/release/release-2.3.0.md) • [v2.2.0 Release Notes](docs/release/release-2.2.0.md) • [v2.1.0 Release Notes](docs/release/release-2.1.0.md) • [v2.0.0 Release Notes](docs/release/release-2.0.0.md) • [v1.9.0 Release Notes](docs/release/release-1.9.0.md) |
|
|
98
98
|
|
|
99
99
|
---
|
|
100
100
|
|
|
@@ -127,6 +127,8 @@ pnpm add avantgate zod
|
|
|
127
127
|
yarn add avantgate zod
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
+
> 🚀 **Quickstart Guide:** See [**Getting Started with AvantGate**](docs/getting-started.md) for 3-minute quickstart recipes with launch-safe presets and compile-time anti-IDOR tools.
|
|
131
|
+
|
|
130
132
|
### 🧩 Subpath Exports
|
|
131
133
|
|
|
132
134
|
| Import Path | Description | Documentation |
|
package/dist/control-layer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import type { ControlLayerConfig, ExecutionResult, StructuredExecutionResult, GenerateStructuredOutputOptions, LLMProviderPort } from "./types";
|
|
2
|
+
import type { ControlLayerConfig, ExecutionResult, StructuredExecutionResult, GenerateStructuredOutputOptions, LLMProviderPort, ChatMessage } from "./types";
|
|
3
3
|
export declare class AvantGateControlLayer {
|
|
4
4
|
private config;
|
|
5
5
|
private cachedPricingAdapter?;
|
|
@@ -19,11 +19,26 @@ export declare class AvantGateControlLayer {
|
|
|
19
19
|
private executeProviderPipeline;
|
|
20
20
|
private assembleResult;
|
|
21
21
|
private notifyAuditSink;
|
|
22
|
+
private prepareInputMessages;
|
|
23
|
+
private handleShortCircuit;
|
|
24
|
+
private dispatchPromptExecution;
|
|
25
|
+
private finalizeExecutionResult;
|
|
26
|
+
private runAfterHooks;
|
|
22
27
|
execute: (options: {
|
|
23
|
-
userQuery
|
|
28
|
+
userQuery?: string;
|
|
29
|
+
systemPrompt?: string;
|
|
30
|
+
messages?: ChatMessage[];
|
|
31
|
+
temperature?: number;
|
|
32
|
+
providerOverride?: LLMProviderPort;
|
|
33
|
+
metadata?: Record<string, unknown>;
|
|
34
|
+
}) => Promise<ExecutionResult>;
|
|
35
|
+
executePrompt: (options: {
|
|
36
|
+
userQuery?: string;
|
|
24
37
|
systemPrompt?: string;
|
|
38
|
+
messages?: ChatMessage[];
|
|
25
39
|
temperature?: number;
|
|
26
40
|
providerOverride?: LLMProviderPort;
|
|
41
|
+
metadata?: Record<string, unknown>;
|
|
27
42
|
}) => Promise<ExecutionResult>;
|
|
28
43
|
executeStructured: <T>(options: {
|
|
29
44
|
userQuery: string;
|
|
@@ -42,6 +57,9 @@ export declare class AvantGateControlLayer {
|
|
|
42
57
|
private buildStructuredResult;
|
|
43
58
|
private notifyAuditSinkSafe;
|
|
44
59
|
private waitRetryBackoff;
|
|
60
|
+
private handleStructuredShortCircuit;
|
|
61
|
+
private runStructuredAfterHooks;
|
|
62
|
+
private executeStructuredLoop;
|
|
45
63
|
generateStructuredOutput: <T>(options: GenerateStructuredOutputOptions<T>) => Promise<StructuredExecutionResult<T>>;
|
|
46
64
|
}
|
|
47
65
|
export declare const createLLMControlLayer: (config: ControlLayerConfig) => AvantGateControlLayer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-layer.d.ts","sourceRoot":"","sources":["../src/control-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EACf,yBAAyB,EACzB,+BAA+B,EAC/B,eAAe,
|
|
1
|
+
{"version":3,"file":"control-layer.d.ts","sourceRoot":"","sources":["../src/control-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EACf,yBAAyB,EACzB,+BAA+B,EAC/B,eAAe,EACf,WAAW,EAIZ,MAAM,SAAS,CAAC;AAkBjB,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,oBAAoB,CAAC,CAAuB;gBAExC,MAAM,EAAE,kBAAkB;IAgBtC,OAAO,CAAC,qBAAqB,CAU3B;IAEF,OAAO,CAAC,kBAAkB,CAaxB;IAEF,OAAO,CAAC,aAAa,CAcnB;IAEF,OAAO,CAAC,mBAAmB,CAqBzB;IAEF,OAAO,CAAC,yBAAyB,CAiB/B;IAEF,OAAO,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C9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,0BAA0B,CAAC;AACzC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -39,6 +39,7 @@ __export(index_exports, {
|
|
|
39
39
|
ConfigurationError: () => ConfigurationError,
|
|
40
40
|
DEFAULT_MODEL_PRICES: () => DEFAULT_MODEL_PRICES,
|
|
41
41
|
HttpProviderClient: () => HttpProviderClient,
|
|
42
|
+
PRESETS: () => PRESETS,
|
|
42
43
|
PricingRegistry: () => PricingRegistry,
|
|
43
44
|
PromptBuilder: () => PromptBuilder,
|
|
44
45
|
PromptRegistry: () => PromptRegistry,
|
|
@@ -51,11 +52,18 @@ __export(index_exports, {
|
|
|
51
52
|
WorkflowValidationError: () => WorkflowValidationError,
|
|
52
53
|
ZenLLMControlLayer: () => AvantGateControlLayer,
|
|
53
54
|
applyOutputGuards: () => applyOutputGuards,
|
|
55
|
+
applySingleAfterMiddleware: () => applySingleAfterMiddleware,
|
|
56
|
+
applySingleBeforeMiddleware: () => applySingleBeforeMiddleware,
|
|
54
57
|
calculateCostUSD: () => calculateCostUSD,
|
|
55
58
|
createAvantGate: () => createAvantGate,
|
|
59
|
+
createDevPermissiveConfig: () => createDevPermissiveConfig,
|
|
60
|
+
createEnterpriseStrictConfig: () => createEnterpriseStrictConfig,
|
|
56
61
|
createHttpProviderClient: () => createHttpProviderClient,
|
|
57
62
|
createLLMControlLayer: () => createLLMControlLayer,
|
|
63
|
+
createLaunchSafeConfig: () => createLaunchSafeConfig,
|
|
58
64
|
defineWorkflow: () => defineWorkflow,
|
|
65
|
+
executeAfterResponseHooks: () => executeAfterResponseHooks,
|
|
66
|
+
executeBeforeRequestHooks: () => executeBeforeRequestHooks,
|
|
59
67
|
executeWorkflow: () => executeWorkflow,
|
|
60
68
|
extractAndCleanJSON: () => extractAndCleanJSON,
|
|
61
69
|
isWorkflowAbortSignal: () => isWorkflowAbortSignal,
|
|
@@ -1347,6 +1355,63 @@ var applyOutputGuards = (rawOutput, options) => {
|
|
|
1347
1355
|
};
|
|
1348
1356
|
};
|
|
1349
1357
|
|
|
1358
|
+
// src/middleware.ts
|
|
1359
|
+
var applySingleBeforeMiddleware = async (middleware, current, model, temperature) => {
|
|
1360
|
+
if (!middleware.beforeRequest) return current;
|
|
1361
|
+
const result = await middleware.beforeRequest({
|
|
1362
|
+
messages: current.messages,
|
|
1363
|
+
model,
|
|
1364
|
+
temperature,
|
|
1365
|
+
metadata: current.metadata
|
|
1366
|
+
});
|
|
1367
|
+
if (!result) return current;
|
|
1368
|
+
return {
|
|
1369
|
+
messages: result.messages ?? current.messages,
|
|
1370
|
+
shortCircuit: result.shortCircuit,
|
|
1371
|
+
metadata: current.metadata
|
|
1372
|
+
};
|
|
1373
|
+
};
|
|
1374
|
+
var executeBeforeRequestHooks = async (middlewares, context) => {
|
|
1375
|
+
if (!middlewares || middlewares.length === 0) {
|
|
1376
|
+
return { messages: context.messages, metadata: context.metadata };
|
|
1377
|
+
}
|
|
1378
|
+
let current = {
|
|
1379
|
+
messages: context.messages,
|
|
1380
|
+
metadata: context.metadata
|
|
1381
|
+
};
|
|
1382
|
+
for (const middleware of middlewares) {
|
|
1383
|
+
current = await applySingleBeforeMiddleware(middleware, current, context.model, context.temperature);
|
|
1384
|
+
if (current.shortCircuit) return current;
|
|
1385
|
+
}
|
|
1386
|
+
return current;
|
|
1387
|
+
};
|
|
1388
|
+
var applySingleAfterMiddleware = async (middleware, current, baseContext) => {
|
|
1389
|
+
if (!middleware.afterResponse) return current;
|
|
1390
|
+
const result = await middleware.afterResponse({
|
|
1391
|
+
...baseContext,
|
|
1392
|
+
responseText: current.responseText,
|
|
1393
|
+
metadata: current.metadata
|
|
1394
|
+
});
|
|
1395
|
+
if (!result) return current;
|
|
1396
|
+
return {
|
|
1397
|
+
responseText: result.responseText ?? current.responseText,
|
|
1398
|
+
metadata: result.metadata ?? current.metadata
|
|
1399
|
+
};
|
|
1400
|
+
};
|
|
1401
|
+
var executeAfterResponseHooks = async (middlewares, context) => {
|
|
1402
|
+
if (!middlewares || middlewares.length === 0) {
|
|
1403
|
+
return { responseText: context.responseText, metadata: context.metadata };
|
|
1404
|
+
}
|
|
1405
|
+
let current = {
|
|
1406
|
+
responseText: context.responseText,
|
|
1407
|
+
metadata: context.metadata
|
|
1408
|
+
};
|
|
1409
|
+
for (const middleware of middlewares) {
|
|
1410
|
+
current = await applySingleAfterMiddleware(middleware, current, context);
|
|
1411
|
+
}
|
|
1412
|
+
return current;
|
|
1413
|
+
};
|
|
1414
|
+
|
|
1350
1415
|
// src/control-layer.ts
|
|
1351
1416
|
var AvantGateControlLayer = class {
|
|
1352
1417
|
config;
|
|
@@ -1590,28 +1655,103 @@ var AvantGateControlLayer = class {
|
|
|
1590
1655
|
attempts: result.attempts
|
|
1591
1656
|
});
|
|
1592
1657
|
};
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1658
|
+
prepareInputMessages = (options) => {
|
|
1659
|
+
if (options.messages && options.messages.length > 0) {
|
|
1660
|
+
return this.sanitizeIncomingMessages(options.messages);
|
|
1661
|
+
}
|
|
1662
|
+
if (options.userQuery !== void 0) {
|
|
1663
|
+
const sanitizedQuery = this.applySecurityGuards(options.userQuery);
|
|
1664
|
+
return this.buildMessages(options.systemPrompt, sanitizedQuery);
|
|
1665
|
+
}
|
|
1666
|
+
throw new ConfigurationError("[AvantGate Input Guard] Either 'userQuery' or 'messages' must be provided.");
|
|
1667
|
+
};
|
|
1668
|
+
handleShortCircuit = async (shortCircuit, targetModel) => {
|
|
1669
|
+
const sanitizedText = this.applyOutputSecurityGuards(shortCircuit.text);
|
|
1670
|
+
const result = {
|
|
1671
|
+
text: sanitizedText,
|
|
1672
|
+
tokens: {
|
|
1673
|
+
prompt: shortCircuit.tokens?.promptTokens ?? 0,
|
|
1674
|
+
completion: shortCircuit.tokens?.completionTokens ?? 0,
|
|
1675
|
+
total: shortCircuit.tokens?.totalTokens ?? 0
|
|
1676
|
+
},
|
|
1677
|
+
costUSD: shortCircuit.costUSD ?? 0,
|
|
1678
|
+
modelUsed: `${targetModel}:shortcircuit`,
|
|
1679
|
+
failoverOccurred: false,
|
|
1680
|
+
attempts: 0
|
|
1681
|
+
};
|
|
1682
|
+
await this.notifyAuditSink(result);
|
|
1683
|
+
return result;
|
|
1684
|
+
};
|
|
1685
|
+
dispatchPromptExecution = async (messages, temperature, providerOverride) => {
|
|
1686
|
+
const query = messages[messages.length - 1]?.content ?? "";
|
|
1687
|
+
if (providerOverride) {
|
|
1688
|
+
return this.executeOverrideProvider(providerOverride, messages, query, temperature);
|
|
1689
|
+
}
|
|
1690
|
+
if (this.getProviderChain().length === 0) {
|
|
1600
1691
|
if (this.config.mockSimulation) {
|
|
1601
|
-
const
|
|
1602
|
-
|
|
1603
|
-
|
|
1692
|
+
const sim = this.executeSimulation(query);
|
|
1693
|
+
return {
|
|
1694
|
+
responseText: sim.text,
|
|
1695
|
+
usage: { promptTokens: sim.tokens.prompt, completionTokens: sim.tokens.completion, totalTokens: sim.tokens.total },
|
|
1696
|
+
modelUsed: sim.modelUsed,
|
|
1697
|
+
failoverOccurred: false,
|
|
1698
|
+
attempts: 1
|
|
1699
|
+
};
|
|
1604
1700
|
}
|
|
1605
1701
|
throw new ConfigurationError(
|
|
1606
1702
|
"[AvantGate Configuration Error] No active LLM provider configured. Provide a client implementing LLMProviderPort or configure credentials (apiKey / baseUrl)."
|
|
1607
1703
|
);
|
|
1608
1704
|
}
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1705
|
+
return this.executeProviderPipeline(messages, query, temperature);
|
|
1706
|
+
};
|
|
1707
|
+
finalizeExecutionResult = async (output, responseText) => {
|
|
1708
|
+
const sanitizedText = this.applyOutputSecurityGuards(responseText);
|
|
1709
|
+
const hitTokens = output.usage.promptCacheHitTokens ?? 0;
|
|
1710
|
+
const costUSD = this.calculateCost(output.modelUsed, output.usage.promptTokens, output.usage.completionTokens, hitTokens);
|
|
1711
|
+
this.checkPostExecutionBudget(output.usage.totalTokens, costUSD);
|
|
1712
|
+
const tokens = { prompt: output.usage.promptTokens, completion: output.usage.completionTokens, total: output.usage.totalTokens };
|
|
1713
|
+
const result = {
|
|
1714
|
+
text: sanitizedText,
|
|
1715
|
+
tokens,
|
|
1716
|
+
costUSD,
|
|
1717
|
+
modelUsed: output.modelUsed,
|
|
1718
|
+
failoverOccurred: output.failoverOccurred,
|
|
1719
|
+
attempts: output.attempts
|
|
1720
|
+
};
|
|
1612
1721
|
await this.notifyAuditSink(result);
|
|
1613
1722
|
return result;
|
|
1614
1723
|
};
|
|
1724
|
+
runAfterHooks = async (beforeState, output) => {
|
|
1725
|
+
const tokens = { prompt: output.usage.promptTokens, completion: output.usage.completionTokens, total: output.usage.totalTokens };
|
|
1726
|
+
const costUSD = this.calculateCost(output.modelUsed, output.usage.promptTokens, output.usage.completionTokens);
|
|
1727
|
+
return executeAfterResponseHooks(this.config.middlewares, {
|
|
1728
|
+
messages: beforeState.messages,
|
|
1729
|
+
responseText: output.responseText,
|
|
1730
|
+
modelUsed: output.modelUsed,
|
|
1731
|
+
tokens,
|
|
1732
|
+
costUSD,
|
|
1733
|
+
attempts: output.attempts,
|
|
1734
|
+
failoverOccurred: output.failoverOccurred,
|
|
1735
|
+
metadata: beforeState.metadata
|
|
1736
|
+
});
|
|
1737
|
+
};
|
|
1738
|
+
execute = async (options) => {
|
|
1739
|
+
const inputMessages = this.prepareInputMessages(options);
|
|
1740
|
+
const beforeState = await executeBeforeRequestHooks(this.config.middlewares, {
|
|
1741
|
+
messages: inputMessages,
|
|
1742
|
+
model: this.config.primary.model,
|
|
1743
|
+
temperature: options.temperature,
|
|
1744
|
+
metadata: options.metadata
|
|
1745
|
+
});
|
|
1746
|
+
if (beforeState.shortCircuit) {
|
|
1747
|
+
return this.handleShortCircuit(beforeState.shortCircuit, this.config.primary.model);
|
|
1748
|
+
}
|
|
1749
|
+
await this.verifyPromptBudget(beforeState.messages, this.config.primary.model);
|
|
1750
|
+
const output = await this.dispatchPromptExecution(beforeState.messages, options.temperature, options.providerOverride);
|
|
1751
|
+
const afterState = await this.runAfterHooks(beforeState, output);
|
|
1752
|
+
return this.finalizeExecutionResult(output, afterState.responseText);
|
|
1753
|
+
};
|
|
1754
|
+
executePrompt = this.execute;
|
|
1615
1755
|
executeStructured = async (options) => {
|
|
1616
1756
|
const rawResult = await this.execute({
|
|
1617
1757
|
userQuery: options.userQuery,
|
|
@@ -1746,28 +1886,56 @@ var AvantGateControlLayer = class {
|
|
|
1746
1886
|
const delay = initialDelay * Math.pow(factor, attempt);
|
|
1747
1887
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1748
1888
|
};
|
|
1749
|
-
|
|
1750
|
-
const
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1889
|
+
handleStructuredShortCircuit = async (shortCircuit, options, targetModel) => {
|
|
1890
|
+
const { parsedData, sanitizedResponse } = this.parseAndValidateStructuredResult(
|
|
1891
|
+
shortCircuit.text,
|
|
1892
|
+
options
|
|
1893
|
+
);
|
|
1894
|
+
const tokens = {
|
|
1895
|
+
prompt: shortCircuit.tokens?.promptTokens ?? 0,
|
|
1896
|
+
completion: shortCircuit.tokens?.completionTokens ?? 0,
|
|
1897
|
+
total: shortCircuit.tokens?.totalTokens ?? 0
|
|
1898
|
+
};
|
|
1899
|
+
const result = {
|
|
1900
|
+
data: parsedData,
|
|
1901
|
+
rawText: sanitizedResponse,
|
|
1902
|
+
tokens,
|
|
1903
|
+
costUSD: shortCircuit.costUSD ?? 0,
|
|
1904
|
+
modelUsed: `${targetModel}:shortcircuit`,
|
|
1905
|
+
failoverOccurred: false
|
|
1906
|
+
};
|
|
1907
|
+
await this.notifyAuditSinkSafe(sanitizedResponse, result, 0);
|
|
1908
|
+
return result;
|
|
1909
|
+
};
|
|
1910
|
+
runStructuredAfterHooks = async (messages, output, attempt) => {
|
|
1911
|
+
const tokens = { prompt: output.promptTokens, completion: output.completionTokens, total: output.promptTokens + output.completionTokens };
|
|
1912
|
+
const costUSD = this.calculateCost(output.modelUsed, output.promptTokens, output.completionTokens);
|
|
1913
|
+
return executeAfterResponseHooks(this.config.middlewares, {
|
|
1914
|
+
messages,
|
|
1915
|
+
responseText: output.responseText,
|
|
1916
|
+
modelUsed: output.modelUsed,
|
|
1917
|
+
tokens,
|
|
1918
|
+
costUSD,
|
|
1919
|
+
attempts: attempt,
|
|
1920
|
+
failoverOccurred: output.failoverOccurred
|
|
1921
|
+
});
|
|
1922
|
+
};
|
|
1923
|
+
executeStructuredLoop = async (options, messages, targetModel, maxRetries) => {
|
|
1754
1924
|
let lastError;
|
|
1755
|
-
let
|
|
1756
|
-
let
|
|
1925
|
+
let accPrompt = 0;
|
|
1926
|
+
let accComp = 0;
|
|
1757
1927
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
1758
1928
|
try {
|
|
1759
|
-
const output = await this.dispatchProviderAttempt(options,
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
const
|
|
1763
|
-
|
|
1764
|
-
options
|
|
1765
|
-
);
|
|
1929
|
+
const output = await this.dispatchProviderAttempt(options, messages, targetModel);
|
|
1930
|
+
accPrompt += output.promptTokens;
|
|
1931
|
+
accComp += output.completionTokens;
|
|
1932
|
+
const afterState = await this.runStructuredAfterHooks(messages, output, attempt + 1);
|
|
1933
|
+
const { parsedData, sanitizedResponse } = this.parseAndValidateStructuredResult(afterState.responseText, options);
|
|
1766
1934
|
const result = this.buildStructuredResult({
|
|
1767
1935
|
data: parsedData,
|
|
1768
1936
|
rawText: sanitizedResponse,
|
|
1769
|
-
promptTokens:
|
|
1770
|
-
completionTokens:
|
|
1937
|
+
promptTokens: accPrompt,
|
|
1938
|
+
completionTokens: accComp,
|
|
1771
1939
|
modelUsed: output.modelUsed,
|
|
1772
1940
|
failoverOccurred: output.failoverOccurred
|
|
1773
1941
|
});
|
|
@@ -1780,6 +1948,21 @@ var AvantGateControlLayer = class {
|
|
|
1780
1948
|
}
|
|
1781
1949
|
throw lastError;
|
|
1782
1950
|
};
|
|
1951
|
+
generateStructuredOutput = async (options) => {
|
|
1952
|
+
const maxRetries = options.maxRetries ?? this.config.retryOptions?.maxRetries ?? 2;
|
|
1953
|
+
const targetModel = options.model ?? this.config.primary.model;
|
|
1954
|
+
const processedMessages = this.sanitizeIncomingMessages(options.messages);
|
|
1955
|
+
const beforeState = await executeBeforeRequestHooks(this.config.middlewares, {
|
|
1956
|
+
messages: processedMessages,
|
|
1957
|
+
model: targetModel,
|
|
1958
|
+
temperature: options.temperature
|
|
1959
|
+
});
|
|
1960
|
+
if (beforeState.shortCircuit) {
|
|
1961
|
+
return this.handleStructuredShortCircuit(beforeState.shortCircuit, options, targetModel);
|
|
1962
|
+
}
|
|
1963
|
+
await this.verifyPromptBudget(beforeState.messages, targetModel);
|
|
1964
|
+
return this.executeStructuredLoop(options, beforeState.messages, targetModel, maxRetries);
|
|
1965
|
+
};
|
|
1783
1966
|
};
|
|
1784
1967
|
var createLLMControlLayer = (config) => {
|
|
1785
1968
|
return new AvantGateControlLayer(config);
|
|
@@ -2687,6 +2870,69 @@ var defineWorkflow = (config) => {
|
|
|
2687
2870
|
}
|
|
2688
2871
|
};
|
|
2689
2872
|
};
|
|
2873
|
+
|
|
2874
|
+
// src/presets.ts
|
|
2875
|
+
var createLaunchSafeConfig = (options) => {
|
|
2876
|
+
const defaultSecurity = {
|
|
2877
|
+
detectPromptInjection: true,
|
|
2878
|
+
maskPII: true,
|
|
2879
|
+
outputDLP: true,
|
|
2880
|
+
blockSecretLeaks: true,
|
|
2881
|
+
secretLeakAction: "REDACT"
|
|
2882
|
+
};
|
|
2883
|
+
const defaultRetries = { maxRetries: 2, initialDelayMs: 300, backoffFactor: 1.5 };
|
|
2884
|
+
return {
|
|
2885
|
+
maxTokenBudget: 8192,
|
|
2886
|
+
maxCostUSD: 0.5,
|
|
2887
|
+
...options,
|
|
2888
|
+
retryOptions: { ...defaultRetries, ...options.retryOptions },
|
|
2889
|
+
security: { ...defaultSecurity, ...options.security }
|
|
2890
|
+
};
|
|
2891
|
+
};
|
|
2892
|
+
var createEnterpriseStrictConfig = (options) => {
|
|
2893
|
+
const defaultSecurity = {
|
|
2894
|
+
detectPromptInjection: true,
|
|
2895
|
+
maskPII: true,
|
|
2896
|
+
outputDLP: true,
|
|
2897
|
+
blockSecretLeaks: true,
|
|
2898
|
+
secretLeakAction: "BLOCK"
|
|
2899
|
+
};
|
|
2900
|
+
const defaultRetries = {
|
|
2901
|
+
maxRetries: 3,
|
|
2902
|
+
initialDelayMs: 500,
|
|
2903
|
+
backoffFactor: 2
|
|
2904
|
+
};
|
|
2905
|
+
return {
|
|
2906
|
+
maxTokenBudget: 4096,
|
|
2907
|
+
maxCostUSD: 0.15,
|
|
2908
|
+
...options,
|
|
2909
|
+
retryOptions: { ...defaultRetries, ...options.retryOptions },
|
|
2910
|
+
security: { ...defaultSecurity, ...options.security }
|
|
2911
|
+
};
|
|
2912
|
+
};
|
|
2913
|
+
var createDevPermissiveConfig = (options) => {
|
|
2914
|
+
const defaultSecurity = {
|
|
2915
|
+
detectPromptInjection: false,
|
|
2916
|
+
maskPII: false,
|
|
2917
|
+
outputDLP: false,
|
|
2918
|
+
blockSecretLeaks: false
|
|
2919
|
+
};
|
|
2920
|
+
const defaultRetries = {
|
|
2921
|
+
maxRetries: 1,
|
|
2922
|
+
initialDelayMs: 200,
|
|
2923
|
+
backoffFactor: 1
|
|
2924
|
+
};
|
|
2925
|
+
return {
|
|
2926
|
+
...options,
|
|
2927
|
+
retryOptions: { ...defaultRetries, ...options.retryOptions },
|
|
2928
|
+
security: { ...defaultSecurity, ...options.security }
|
|
2929
|
+
};
|
|
2930
|
+
};
|
|
2931
|
+
var PRESETS = {
|
|
2932
|
+
LAUNCH_SAFE: createLaunchSafeConfig,
|
|
2933
|
+
ENTERPRISE_STRICT: createEnterpriseStrictConfig,
|
|
2934
|
+
DEV_PERMISSIVE: createDevPermissiveConfig
|
|
2935
|
+
};
|
|
2690
2936
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2691
2937
|
0 && (module.exports = {
|
|
2692
2938
|
AvantGateBudgetExceededError,
|
|
@@ -2698,6 +2944,7 @@ var defineWorkflow = (config) => {
|
|
|
2698
2944
|
ConfigurationError,
|
|
2699
2945
|
DEFAULT_MODEL_PRICES,
|
|
2700
2946
|
HttpProviderClient,
|
|
2947
|
+
PRESETS,
|
|
2701
2948
|
PricingRegistry,
|
|
2702
2949
|
PromptBuilder,
|
|
2703
2950
|
PromptRegistry,
|
|
@@ -2710,11 +2957,18 @@ var defineWorkflow = (config) => {
|
|
|
2710
2957
|
WorkflowValidationError,
|
|
2711
2958
|
ZenLLMControlLayer,
|
|
2712
2959
|
applyOutputGuards,
|
|
2960
|
+
applySingleAfterMiddleware,
|
|
2961
|
+
applySingleBeforeMiddleware,
|
|
2713
2962
|
calculateCostUSD,
|
|
2714
2963
|
createAvantGate,
|
|
2964
|
+
createDevPermissiveConfig,
|
|
2965
|
+
createEnterpriseStrictConfig,
|
|
2715
2966
|
createHttpProviderClient,
|
|
2716
2967
|
createLLMControlLayer,
|
|
2968
|
+
createLaunchSafeConfig,
|
|
2717
2969
|
defineWorkflow,
|
|
2970
|
+
executeAfterResponseHooks,
|
|
2971
|
+
executeBeforeRequestHooks,
|
|
2718
2972
|
executeWorkflow,
|
|
2719
2973
|
extractAndCleanJSON,
|
|
2720
2974
|
isWorkflowAbortSignal,
|
package/dist/index.mjs
CHANGED
|
@@ -736,6 +736,63 @@ var applyOutputGuards = (rawOutput, options) => {
|
|
|
736
736
|
};
|
|
737
737
|
};
|
|
738
738
|
|
|
739
|
+
// src/middleware.ts
|
|
740
|
+
var applySingleBeforeMiddleware = async (middleware, current, model, temperature) => {
|
|
741
|
+
if (!middleware.beforeRequest) return current;
|
|
742
|
+
const result = await middleware.beforeRequest({
|
|
743
|
+
messages: current.messages,
|
|
744
|
+
model,
|
|
745
|
+
temperature,
|
|
746
|
+
metadata: current.metadata
|
|
747
|
+
});
|
|
748
|
+
if (!result) return current;
|
|
749
|
+
return {
|
|
750
|
+
messages: result.messages ?? current.messages,
|
|
751
|
+
shortCircuit: result.shortCircuit,
|
|
752
|
+
metadata: current.metadata
|
|
753
|
+
};
|
|
754
|
+
};
|
|
755
|
+
var executeBeforeRequestHooks = async (middlewares, context) => {
|
|
756
|
+
if (!middlewares || middlewares.length === 0) {
|
|
757
|
+
return { messages: context.messages, metadata: context.metadata };
|
|
758
|
+
}
|
|
759
|
+
let current = {
|
|
760
|
+
messages: context.messages,
|
|
761
|
+
metadata: context.metadata
|
|
762
|
+
};
|
|
763
|
+
for (const middleware of middlewares) {
|
|
764
|
+
current = await applySingleBeforeMiddleware(middleware, current, context.model, context.temperature);
|
|
765
|
+
if (current.shortCircuit) return current;
|
|
766
|
+
}
|
|
767
|
+
return current;
|
|
768
|
+
};
|
|
769
|
+
var applySingleAfterMiddleware = async (middleware, current, baseContext) => {
|
|
770
|
+
if (!middleware.afterResponse) return current;
|
|
771
|
+
const result = await middleware.afterResponse({
|
|
772
|
+
...baseContext,
|
|
773
|
+
responseText: current.responseText,
|
|
774
|
+
metadata: current.metadata
|
|
775
|
+
});
|
|
776
|
+
if (!result) return current;
|
|
777
|
+
return {
|
|
778
|
+
responseText: result.responseText ?? current.responseText,
|
|
779
|
+
metadata: result.metadata ?? current.metadata
|
|
780
|
+
};
|
|
781
|
+
};
|
|
782
|
+
var executeAfterResponseHooks = async (middlewares, context) => {
|
|
783
|
+
if (!middlewares || middlewares.length === 0) {
|
|
784
|
+
return { responseText: context.responseText, metadata: context.metadata };
|
|
785
|
+
}
|
|
786
|
+
let current = {
|
|
787
|
+
responseText: context.responseText,
|
|
788
|
+
metadata: context.metadata
|
|
789
|
+
};
|
|
790
|
+
for (const middleware of middlewares) {
|
|
791
|
+
current = await applySingleAfterMiddleware(middleware, current, context);
|
|
792
|
+
}
|
|
793
|
+
return current;
|
|
794
|
+
};
|
|
795
|
+
|
|
739
796
|
// src/control-layer.ts
|
|
740
797
|
var AvantGateControlLayer = class {
|
|
741
798
|
config;
|
|
@@ -979,28 +1036,103 @@ var AvantGateControlLayer = class {
|
|
|
979
1036
|
attempts: result.attempts
|
|
980
1037
|
});
|
|
981
1038
|
};
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1039
|
+
prepareInputMessages = (options) => {
|
|
1040
|
+
if (options.messages && options.messages.length > 0) {
|
|
1041
|
+
return this.sanitizeIncomingMessages(options.messages);
|
|
1042
|
+
}
|
|
1043
|
+
if (options.userQuery !== void 0) {
|
|
1044
|
+
const sanitizedQuery = this.applySecurityGuards(options.userQuery);
|
|
1045
|
+
return this.buildMessages(options.systemPrompt, sanitizedQuery);
|
|
1046
|
+
}
|
|
1047
|
+
throw new ConfigurationError("[AvantGate Input Guard] Either 'userQuery' or 'messages' must be provided.");
|
|
1048
|
+
};
|
|
1049
|
+
handleShortCircuit = async (shortCircuit, targetModel) => {
|
|
1050
|
+
const sanitizedText = this.applyOutputSecurityGuards(shortCircuit.text);
|
|
1051
|
+
const result = {
|
|
1052
|
+
text: sanitizedText,
|
|
1053
|
+
tokens: {
|
|
1054
|
+
prompt: shortCircuit.tokens?.promptTokens ?? 0,
|
|
1055
|
+
completion: shortCircuit.tokens?.completionTokens ?? 0,
|
|
1056
|
+
total: shortCircuit.tokens?.totalTokens ?? 0
|
|
1057
|
+
},
|
|
1058
|
+
costUSD: shortCircuit.costUSD ?? 0,
|
|
1059
|
+
modelUsed: `${targetModel}:shortcircuit`,
|
|
1060
|
+
failoverOccurred: false,
|
|
1061
|
+
attempts: 0
|
|
1062
|
+
};
|
|
1063
|
+
await this.notifyAuditSink(result);
|
|
1064
|
+
return result;
|
|
1065
|
+
};
|
|
1066
|
+
dispatchPromptExecution = async (messages, temperature, providerOverride) => {
|
|
1067
|
+
const query = messages[messages.length - 1]?.content ?? "";
|
|
1068
|
+
if (providerOverride) {
|
|
1069
|
+
return this.executeOverrideProvider(providerOverride, messages, query, temperature);
|
|
1070
|
+
}
|
|
1071
|
+
if (this.getProviderChain().length === 0) {
|
|
989
1072
|
if (this.config.mockSimulation) {
|
|
990
|
-
const
|
|
991
|
-
|
|
992
|
-
|
|
1073
|
+
const sim = this.executeSimulation(query);
|
|
1074
|
+
return {
|
|
1075
|
+
responseText: sim.text,
|
|
1076
|
+
usage: { promptTokens: sim.tokens.prompt, completionTokens: sim.tokens.completion, totalTokens: sim.tokens.total },
|
|
1077
|
+
modelUsed: sim.modelUsed,
|
|
1078
|
+
failoverOccurred: false,
|
|
1079
|
+
attempts: 1
|
|
1080
|
+
};
|
|
993
1081
|
}
|
|
994
1082
|
throw new ConfigurationError(
|
|
995
1083
|
"[AvantGate Configuration Error] No active LLM provider configured. Provide a client implementing LLMProviderPort or configure credentials (apiKey / baseUrl)."
|
|
996
1084
|
);
|
|
997
1085
|
}
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1086
|
+
return this.executeProviderPipeline(messages, query, temperature);
|
|
1087
|
+
};
|
|
1088
|
+
finalizeExecutionResult = async (output, responseText) => {
|
|
1089
|
+
const sanitizedText = this.applyOutputSecurityGuards(responseText);
|
|
1090
|
+
const hitTokens = output.usage.promptCacheHitTokens ?? 0;
|
|
1091
|
+
const costUSD = this.calculateCost(output.modelUsed, output.usage.promptTokens, output.usage.completionTokens, hitTokens);
|
|
1092
|
+
this.checkPostExecutionBudget(output.usage.totalTokens, costUSD);
|
|
1093
|
+
const tokens = { prompt: output.usage.promptTokens, completion: output.usage.completionTokens, total: output.usage.totalTokens };
|
|
1094
|
+
const result = {
|
|
1095
|
+
text: sanitizedText,
|
|
1096
|
+
tokens,
|
|
1097
|
+
costUSD,
|
|
1098
|
+
modelUsed: output.modelUsed,
|
|
1099
|
+
failoverOccurred: output.failoverOccurred,
|
|
1100
|
+
attempts: output.attempts
|
|
1101
|
+
};
|
|
1001
1102
|
await this.notifyAuditSink(result);
|
|
1002
1103
|
return result;
|
|
1003
1104
|
};
|
|
1105
|
+
runAfterHooks = async (beforeState, output) => {
|
|
1106
|
+
const tokens = { prompt: output.usage.promptTokens, completion: output.usage.completionTokens, total: output.usage.totalTokens };
|
|
1107
|
+
const costUSD = this.calculateCost(output.modelUsed, output.usage.promptTokens, output.usage.completionTokens);
|
|
1108
|
+
return executeAfterResponseHooks(this.config.middlewares, {
|
|
1109
|
+
messages: beforeState.messages,
|
|
1110
|
+
responseText: output.responseText,
|
|
1111
|
+
modelUsed: output.modelUsed,
|
|
1112
|
+
tokens,
|
|
1113
|
+
costUSD,
|
|
1114
|
+
attempts: output.attempts,
|
|
1115
|
+
failoverOccurred: output.failoverOccurred,
|
|
1116
|
+
metadata: beforeState.metadata
|
|
1117
|
+
});
|
|
1118
|
+
};
|
|
1119
|
+
execute = async (options) => {
|
|
1120
|
+
const inputMessages = this.prepareInputMessages(options);
|
|
1121
|
+
const beforeState = await executeBeforeRequestHooks(this.config.middlewares, {
|
|
1122
|
+
messages: inputMessages,
|
|
1123
|
+
model: this.config.primary.model,
|
|
1124
|
+
temperature: options.temperature,
|
|
1125
|
+
metadata: options.metadata
|
|
1126
|
+
});
|
|
1127
|
+
if (beforeState.shortCircuit) {
|
|
1128
|
+
return this.handleShortCircuit(beforeState.shortCircuit, this.config.primary.model);
|
|
1129
|
+
}
|
|
1130
|
+
await this.verifyPromptBudget(beforeState.messages, this.config.primary.model);
|
|
1131
|
+
const output = await this.dispatchPromptExecution(beforeState.messages, options.temperature, options.providerOverride);
|
|
1132
|
+
const afterState = await this.runAfterHooks(beforeState, output);
|
|
1133
|
+
return this.finalizeExecutionResult(output, afterState.responseText);
|
|
1134
|
+
};
|
|
1135
|
+
executePrompt = this.execute;
|
|
1004
1136
|
executeStructured = async (options) => {
|
|
1005
1137
|
const rawResult = await this.execute({
|
|
1006
1138
|
userQuery: options.userQuery,
|
|
@@ -1135,28 +1267,56 @@ var AvantGateControlLayer = class {
|
|
|
1135
1267
|
const delay = initialDelay * Math.pow(factor, attempt);
|
|
1136
1268
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1137
1269
|
};
|
|
1138
|
-
|
|
1139
|
-
const
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1270
|
+
handleStructuredShortCircuit = async (shortCircuit, options, targetModel) => {
|
|
1271
|
+
const { parsedData, sanitizedResponse } = this.parseAndValidateStructuredResult(
|
|
1272
|
+
shortCircuit.text,
|
|
1273
|
+
options
|
|
1274
|
+
);
|
|
1275
|
+
const tokens = {
|
|
1276
|
+
prompt: shortCircuit.tokens?.promptTokens ?? 0,
|
|
1277
|
+
completion: shortCircuit.tokens?.completionTokens ?? 0,
|
|
1278
|
+
total: shortCircuit.tokens?.totalTokens ?? 0
|
|
1279
|
+
};
|
|
1280
|
+
const result = {
|
|
1281
|
+
data: parsedData,
|
|
1282
|
+
rawText: sanitizedResponse,
|
|
1283
|
+
tokens,
|
|
1284
|
+
costUSD: shortCircuit.costUSD ?? 0,
|
|
1285
|
+
modelUsed: `${targetModel}:shortcircuit`,
|
|
1286
|
+
failoverOccurred: false
|
|
1287
|
+
};
|
|
1288
|
+
await this.notifyAuditSinkSafe(sanitizedResponse, result, 0);
|
|
1289
|
+
return result;
|
|
1290
|
+
};
|
|
1291
|
+
runStructuredAfterHooks = async (messages, output, attempt) => {
|
|
1292
|
+
const tokens = { prompt: output.promptTokens, completion: output.completionTokens, total: output.promptTokens + output.completionTokens };
|
|
1293
|
+
const costUSD = this.calculateCost(output.modelUsed, output.promptTokens, output.completionTokens);
|
|
1294
|
+
return executeAfterResponseHooks(this.config.middlewares, {
|
|
1295
|
+
messages,
|
|
1296
|
+
responseText: output.responseText,
|
|
1297
|
+
modelUsed: output.modelUsed,
|
|
1298
|
+
tokens,
|
|
1299
|
+
costUSD,
|
|
1300
|
+
attempts: attempt,
|
|
1301
|
+
failoverOccurred: output.failoverOccurred
|
|
1302
|
+
});
|
|
1303
|
+
};
|
|
1304
|
+
executeStructuredLoop = async (options, messages, targetModel, maxRetries) => {
|
|
1143
1305
|
let lastError;
|
|
1144
|
-
let
|
|
1145
|
-
let
|
|
1306
|
+
let accPrompt = 0;
|
|
1307
|
+
let accComp = 0;
|
|
1146
1308
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
1147
1309
|
try {
|
|
1148
|
-
const output = await this.dispatchProviderAttempt(options,
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
const
|
|
1152
|
-
|
|
1153
|
-
options
|
|
1154
|
-
);
|
|
1310
|
+
const output = await this.dispatchProviderAttempt(options, messages, targetModel);
|
|
1311
|
+
accPrompt += output.promptTokens;
|
|
1312
|
+
accComp += output.completionTokens;
|
|
1313
|
+
const afterState = await this.runStructuredAfterHooks(messages, output, attempt + 1);
|
|
1314
|
+
const { parsedData, sanitizedResponse } = this.parseAndValidateStructuredResult(afterState.responseText, options);
|
|
1155
1315
|
const result = this.buildStructuredResult({
|
|
1156
1316
|
data: parsedData,
|
|
1157
1317
|
rawText: sanitizedResponse,
|
|
1158
|
-
promptTokens:
|
|
1159
|
-
completionTokens:
|
|
1318
|
+
promptTokens: accPrompt,
|
|
1319
|
+
completionTokens: accComp,
|
|
1160
1320
|
modelUsed: output.modelUsed,
|
|
1161
1321
|
failoverOccurred: output.failoverOccurred
|
|
1162
1322
|
});
|
|
@@ -1169,6 +1329,21 @@ var AvantGateControlLayer = class {
|
|
|
1169
1329
|
}
|
|
1170
1330
|
throw lastError;
|
|
1171
1331
|
};
|
|
1332
|
+
generateStructuredOutput = async (options) => {
|
|
1333
|
+
const maxRetries = options.maxRetries ?? this.config.retryOptions?.maxRetries ?? 2;
|
|
1334
|
+
const targetModel = options.model ?? this.config.primary.model;
|
|
1335
|
+
const processedMessages = this.sanitizeIncomingMessages(options.messages);
|
|
1336
|
+
const beforeState = await executeBeforeRequestHooks(this.config.middlewares, {
|
|
1337
|
+
messages: processedMessages,
|
|
1338
|
+
model: targetModel,
|
|
1339
|
+
temperature: options.temperature
|
|
1340
|
+
});
|
|
1341
|
+
if (beforeState.shortCircuit) {
|
|
1342
|
+
return this.handleStructuredShortCircuit(beforeState.shortCircuit, options, targetModel);
|
|
1343
|
+
}
|
|
1344
|
+
await this.verifyPromptBudget(beforeState.messages, targetModel);
|
|
1345
|
+
return this.executeStructuredLoop(options, beforeState.messages, targetModel, maxRetries);
|
|
1346
|
+
};
|
|
1172
1347
|
};
|
|
1173
1348
|
var createLLMControlLayer = (config) => {
|
|
1174
1349
|
return new AvantGateControlLayer(config);
|
|
@@ -1489,6 +1664,69 @@ var PromptRegistry = class {
|
|
|
1489
1664
|
this.registry.clear();
|
|
1490
1665
|
}
|
|
1491
1666
|
};
|
|
1667
|
+
|
|
1668
|
+
// src/presets.ts
|
|
1669
|
+
var createLaunchSafeConfig = (options) => {
|
|
1670
|
+
const defaultSecurity = {
|
|
1671
|
+
detectPromptInjection: true,
|
|
1672
|
+
maskPII: true,
|
|
1673
|
+
outputDLP: true,
|
|
1674
|
+
blockSecretLeaks: true,
|
|
1675
|
+
secretLeakAction: "REDACT"
|
|
1676
|
+
};
|
|
1677
|
+
const defaultRetries = { maxRetries: 2, initialDelayMs: 300, backoffFactor: 1.5 };
|
|
1678
|
+
return {
|
|
1679
|
+
maxTokenBudget: 8192,
|
|
1680
|
+
maxCostUSD: 0.5,
|
|
1681
|
+
...options,
|
|
1682
|
+
retryOptions: { ...defaultRetries, ...options.retryOptions },
|
|
1683
|
+
security: { ...defaultSecurity, ...options.security }
|
|
1684
|
+
};
|
|
1685
|
+
};
|
|
1686
|
+
var createEnterpriseStrictConfig = (options) => {
|
|
1687
|
+
const defaultSecurity = {
|
|
1688
|
+
detectPromptInjection: true,
|
|
1689
|
+
maskPII: true,
|
|
1690
|
+
outputDLP: true,
|
|
1691
|
+
blockSecretLeaks: true,
|
|
1692
|
+
secretLeakAction: "BLOCK"
|
|
1693
|
+
};
|
|
1694
|
+
const defaultRetries = {
|
|
1695
|
+
maxRetries: 3,
|
|
1696
|
+
initialDelayMs: 500,
|
|
1697
|
+
backoffFactor: 2
|
|
1698
|
+
};
|
|
1699
|
+
return {
|
|
1700
|
+
maxTokenBudget: 4096,
|
|
1701
|
+
maxCostUSD: 0.15,
|
|
1702
|
+
...options,
|
|
1703
|
+
retryOptions: { ...defaultRetries, ...options.retryOptions },
|
|
1704
|
+
security: { ...defaultSecurity, ...options.security }
|
|
1705
|
+
};
|
|
1706
|
+
};
|
|
1707
|
+
var createDevPermissiveConfig = (options) => {
|
|
1708
|
+
const defaultSecurity = {
|
|
1709
|
+
detectPromptInjection: false,
|
|
1710
|
+
maskPII: false,
|
|
1711
|
+
outputDLP: false,
|
|
1712
|
+
blockSecretLeaks: false
|
|
1713
|
+
};
|
|
1714
|
+
const defaultRetries = {
|
|
1715
|
+
maxRetries: 1,
|
|
1716
|
+
initialDelayMs: 200,
|
|
1717
|
+
backoffFactor: 1
|
|
1718
|
+
};
|
|
1719
|
+
return {
|
|
1720
|
+
...options,
|
|
1721
|
+
retryOptions: { ...defaultRetries, ...options.retryOptions },
|
|
1722
|
+
security: { ...defaultSecurity, ...options.security }
|
|
1723
|
+
};
|
|
1724
|
+
};
|
|
1725
|
+
var PRESETS = {
|
|
1726
|
+
LAUNCH_SAFE: createLaunchSafeConfig,
|
|
1727
|
+
ENTERPRISE_STRICT: createEnterpriseStrictConfig,
|
|
1728
|
+
DEV_PERMISSIVE: createDevPermissiveConfig
|
|
1729
|
+
};
|
|
1492
1730
|
export {
|
|
1493
1731
|
BudgetExceededError as AvantGateBudgetExceededError,
|
|
1494
1732
|
ConfigurationError as AvantGateConfigurationError,
|
|
@@ -1499,6 +1737,7 @@ export {
|
|
|
1499
1737
|
ConfigurationError,
|
|
1500
1738
|
DEFAULT_MODEL_PRICES,
|
|
1501
1739
|
HttpProviderClient,
|
|
1740
|
+
PRESETS,
|
|
1502
1741
|
PricingRegistry,
|
|
1503
1742
|
PromptBuilder,
|
|
1504
1743
|
PromptRegistry,
|
|
@@ -1511,11 +1750,18 @@ export {
|
|
|
1511
1750
|
WorkflowValidationError,
|
|
1512
1751
|
AvantGateControlLayer as ZenLLMControlLayer,
|
|
1513
1752
|
applyOutputGuards,
|
|
1753
|
+
applySingleAfterMiddleware,
|
|
1754
|
+
applySingleBeforeMiddleware,
|
|
1514
1755
|
calculateCostUSD,
|
|
1515
1756
|
createAvantGate,
|
|
1757
|
+
createDevPermissiveConfig,
|
|
1758
|
+
createEnterpriseStrictConfig,
|
|
1516
1759
|
createHttpProviderClient,
|
|
1517
1760
|
createLLMControlLayer,
|
|
1761
|
+
createLaunchSafeConfig,
|
|
1518
1762
|
defineWorkflow,
|
|
1763
|
+
executeAfterResponseHooks,
|
|
1764
|
+
executeBeforeRequestHooks,
|
|
1519
1765
|
executeWorkflow,
|
|
1520
1766
|
extractAndCleanJSON,
|
|
1521
1767
|
isWorkflowAbortSignal,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AvantGateMiddleware, BeforeRequestContext, BeforeRequestResult, AfterResponseContext, ChatMessage } from "./types";
|
|
2
|
+
export interface BeforeExecutionState {
|
|
3
|
+
messages: ChatMessage[];
|
|
4
|
+
metadata?: Record<string, unknown>;
|
|
5
|
+
shortCircuit?: BeforeRequestResult["shortCircuit"];
|
|
6
|
+
}
|
|
7
|
+
export interface AfterExecutionState {
|
|
8
|
+
responseText: string;
|
|
9
|
+
metadata?: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export declare const applySingleBeforeMiddleware: (middleware: AvantGateMiddleware, current: BeforeExecutionState, model: string, temperature?: number) => Promise<BeforeExecutionState>;
|
|
12
|
+
export declare const executeBeforeRequestHooks: (middlewares: AvantGateMiddleware[] | undefined, context: BeforeRequestContext) => Promise<BeforeExecutionState>;
|
|
13
|
+
export declare const applySingleAfterMiddleware: (middleware: AvantGateMiddleware, current: AfterExecutionState, baseContext: Omit<AfterResponseContext, "responseText" | "metadata">) => Promise<AfterExecutionState>;
|
|
14
|
+
export declare const executeAfterResponseHooks: (middlewares: AvantGateMiddleware[] | undefined, context: AfterResponseContext) => Promise<AfterExecutionState>;
|
|
15
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,YAAY,CAAC,EAAE,mBAAmB,CAAC,cAAc,CAAC,CAAC;CACpD;AAED,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,eAAO,MAAM,2BAA2B,GACtC,YAAY,mBAAmB,EAC/B,SAAS,oBAAoB,EAC7B,OAAO,MAAM,EACb,cAAc,MAAM,KACnB,OAAO,CAAC,oBAAoB,CAc9B,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,aAAa,mBAAmB,EAAE,GAAG,SAAS,EAC9C,SAAS,oBAAoB,KAC5B,OAAO,CAAC,oBAAoB,CAa9B,CAAC;AAEF,eAAO,MAAM,0BAA0B,GACrC,YAAY,mBAAmB,EAC/B,SAAS,mBAAmB,EAC5B,aAAa,IAAI,CAAC,oBAAoB,EAAE,cAAc,GAAG,UAAU,CAAC,KACnE,OAAO,CAAC,mBAAmB,CAY7B,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,aAAa,mBAAmB,EAAE,GAAG,SAAS,EAC9C,SAAS,oBAAoB,KAC5B,OAAO,CAAC,mBAAmB,CAY7B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ControlLayerConfig, ProviderConfig } from "./types";
|
|
2
|
+
export interface PresetBaseOptions extends Partial<ControlLayerConfig> {
|
|
3
|
+
primary: ProviderConfig;
|
|
4
|
+
}
|
|
5
|
+
export declare const createLaunchSafeConfig: (options: PresetBaseOptions) => ControlLayerConfig;
|
|
6
|
+
export declare const createEnterpriseStrictConfig: (options: PresetBaseOptions) => ControlLayerConfig;
|
|
7
|
+
export declare const createDevPermissiveConfig: (options: PresetBaseOptions) => ControlLayerConfig;
|
|
8
|
+
export declare const PRESETS: {
|
|
9
|
+
LAUNCH_SAFE: (options: PresetBaseOptions) => ControlLayerConfig;
|
|
10
|
+
ENTERPRISE_STRICT: (options: PresetBaseOptions) => ControlLayerConfig;
|
|
11
|
+
DEV_PERMISSIVE: (options: PresetBaseOptions) => ControlLayerConfig;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=presets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../src/presets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAA+B,MAAM,SAAS,CAAC;AAE/F,MAAM,WAAW,iBAAkB,SAAQ,OAAO,CAAC,kBAAkB,CAAC;IACpE,OAAO,EAAE,cAAc,CAAC;CACzB;AAED,eAAO,MAAM,sBAAsB,GAAI,SAAS,iBAAiB,KAAG,kBAgBnE,CAAC;AAEF,eAAO,MAAM,4BAA4B,GAAI,SAAS,iBAAiB,KAAG,kBAoBzE,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,SAAS,iBAAiB,KAAG,kBAiBtE,CAAC;AAEF,eAAO,MAAM,OAAO;2BA3D4B,iBAAiB,KAAG,kBAAkB;iCAkBhC,iBAAiB,KAAG,kBAAkB;8BAsBzC,iBAAiB,KAAG,kBAAkB;CAuBxF,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -115,6 +115,43 @@ export interface FinanceFeaturesConfig {
|
|
|
115
115
|
export interface FeaturesConfig {
|
|
116
116
|
finance?: FinanceFeaturesConfig;
|
|
117
117
|
}
|
|
118
|
+
export interface BeforeRequestContext {
|
|
119
|
+
messages: ChatMessage[];
|
|
120
|
+
model: string;
|
|
121
|
+
temperature?: number;
|
|
122
|
+
metadata?: Record<string, unknown>;
|
|
123
|
+
}
|
|
124
|
+
export interface BeforeRequestResult {
|
|
125
|
+
messages?: ChatMessage[];
|
|
126
|
+
shortCircuit?: {
|
|
127
|
+
text: string;
|
|
128
|
+
tokens?: LLMUsage;
|
|
129
|
+
costUSD?: number;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export interface AfterResponseContext {
|
|
133
|
+
messages: ChatMessage[];
|
|
134
|
+
responseText: string;
|
|
135
|
+
modelUsed: string;
|
|
136
|
+
tokens: {
|
|
137
|
+
prompt: number;
|
|
138
|
+
completion: number;
|
|
139
|
+
total: number;
|
|
140
|
+
};
|
|
141
|
+
costUSD: number;
|
|
142
|
+
attempts: number;
|
|
143
|
+
failoverOccurred: boolean;
|
|
144
|
+
metadata?: Record<string, unknown>;
|
|
145
|
+
}
|
|
146
|
+
export interface AfterResponseResult {
|
|
147
|
+
responseText?: string;
|
|
148
|
+
metadata?: Record<string, unknown>;
|
|
149
|
+
}
|
|
150
|
+
export interface AvantGateMiddleware {
|
|
151
|
+
name: string;
|
|
152
|
+
beforeRequest?: (context: BeforeRequestContext) => Promise<BeforeRequestResult | void> | BeforeRequestResult | void;
|
|
153
|
+
afterResponse?: (context: AfterResponseContext) => Promise<AfterResponseResult | void> | AfterResponseResult | void;
|
|
154
|
+
}
|
|
118
155
|
export interface ControlLayerConfig {
|
|
119
156
|
primary: ProviderConfig;
|
|
120
157
|
fallback?: ProviderConfig;
|
|
@@ -131,6 +168,7 @@ export interface ControlLayerConfig {
|
|
|
131
168
|
pricingCacheTtlMs?: number;
|
|
132
169
|
customPricing?: Record<string, ModelPrice>;
|
|
133
170
|
mockSimulation?: boolean;
|
|
171
|
+
middlewares?: AvantGateMiddleware[];
|
|
134
172
|
}
|
|
135
173
|
export interface ExecutionResult {
|
|
136
174
|
text: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;IAC/C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,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C;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,eAAe,CAAC;IACnC,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "avantgate",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Zero-infrastructure, in-process AI Application Firewall (AI-WAF), privacy control plane & headless UI canvas for TypeScript: real-time prompt guardrails, zero-egress PII redaction, deterministic tool envelopes, anti-IDOR defense, pre-flight token budgets, and multi-model failover.",
|
|
5
5
|
"author": "Gatewall Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -96,7 +96,9 @@
|
|
|
96
96
|
],
|
|
97
97
|
"scripts": {
|
|
98
98
|
"build": "tsup src/index.ts src/finance/index.ts src/agent/index.ts src/workflow/index.ts src/client/index.ts src/ui/index.ts src/ui/react/index.ts --format cjs --format esm --clean && tsc --emitDeclarationOnly --outDir dist",
|
|
99
|
-
"test": "tsx tests/avantgate.test.ts && tsx tests/preflight-budget.test.ts && tsx tests/sqlite-pricing-adapter.test.ts && tsx tests/financial-normalizer.test.ts && tsx tests/prompt-builder.test.ts && tsx tests/pii-extended.test.ts && tsx tests/output-dlp-secret-guard.test.ts && npm run test:agent && npm run test:workflow && npm run test:client && npm run test:ui",
|
|
99
|
+
"test": "tsx tests/avantgate.test.ts && tsx tests/preflight-budget.test.ts && tsx tests/sqlite-pricing-adapter.test.ts && tsx tests/financial-normalizer.test.ts && tsx tests/prompt-builder.test.ts && tsx tests/pii-extended.test.ts && tsx tests/output-dlp-secret-guard.test.ts && tsx tests/middleware-lifecycle.test.ts && tsx tests/presets.test.ts && npm run test:agent && npm run test:workflow && npm run test:client && npm run test:ui",
|
|
100
|
+
"test:presets": "tsx tests/presets.test.ts",
|
|
101
|
+
"test:middleware": "tsx tests/middleware-lifecycle.test.ts",
|
|
100
102
|
"test:ui": "tsx tests/ui/envelope.test.ts && tsx tests/ui/reducer.test.ts && tsx tests/ui/sanitize.test.ts && tsx tests/ui/react-registry.test.tsx",
|
|
101
103
|
"test:secrets": "tsx tests/output-dlp-secret-guard.test.ts",
|
|
102
104
|
"test:pricing": "tsx tests/sqlite-pricing-adapter.test.ts",
|