@agentguard-run/spend 0.6.1 → 0.8.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/CHANGELOG.md +11 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -2
- package/dist/index.js.map +1 -1
- package/dist/outcomes/index.d.ts +6 -0
- package/dist/outcomes/index.d.ts.map +1 -0
- package/dist/outcomes/index.js +22 -0
- package/dist/outcomes/index.js.map +1 -0
- package/dist/outcomes/learning.d.ts +19 -0
- package/dist/outcomes/learning.d.ts.map +1 -0
- package/dist/outcomes/learning.js +104 -0
- package/dist/outcomes/learning.js.map +1 -0
- package/dist/outcomes/ledger.d.ts +42 -0
- package/dist/outcomes/ledger.d.ts.map +1 -0
- package/dist/outcomes/ledger.js +110 -0
- package/dist/outcomes/ledger.js.map +1 -0
- package/dist/outcomes/quality-gate.d.ts +12 -0
- package/dist/outcomes/quality-gate.d.ts.map +1 -0
- package/dist/outcomes/quality-gate.js +104 -0
- package/dist/outcomes/quality-gate.js.map +1 -0
- package/dist/outcomes/runtime.d.ts +21 -0
- package/dist/outcomes/runtime.d.ts.map +1 -0
- package/dist/outcomes/runtime.js +321 -0
- package/dist/outcomes/runtime.js.map +1 -0
- package/dist/outcomes/types.d.ts +147 -0
- package/dist/outcomes/types.d.ts.map +1 -0
- package/dist/outcomes/types.js +14 -0
- package/dist/outcomes/types.js.map +1 -0
- package/dist/router.d.ts +52 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +563 -0
- package/dist/router.js.map +1 -0
- package/dist/spend-guard.d.ts +31 -0
- package/dist/spend-guard.d.ts.map +1 -1
- package/dist/spend-guard.js +158 -3
- package/dist/spend-guard.js.map +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +14 -2
- package/src/outcomes/index.ts +5 -0
- package/src/outcomes/learning.ts +133 -0
- package/src/outcomes/ledger.ts +131 -0
- package/src/outcomes/quality-gate.ts +116 -0
- package/src/outcomes/runtime.ts +388 -0
- package/src/outcomes/types.ts +167 -0
- package/src/router.ts +614 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { CapabilityTier, SpendScope, SpendWindow } from '../types';
|
|
2
|
+
|
|
3
|
+
export type OutcomeVertical = 'law' | 'accounting' | 'insurance' | 'realestate' | 'ecommerce' | string;
|
|
4
|
+
export type OutcomeRole = 'drafter' | 'reviewer' | 'fallback';
|
|
5
|
+
export type OutcomeStatus = 'completed' | 'blocked' | 'failed' | 'quality_failed';
|
|
6
|
+
|
|
7
|
+
export interface OutcomeInputDefinition {
|
|
8
|
+
name: string;
|
|
9
|
+
type: 'string' | 'number' | 'boolean' | 'json' | 'date';
|
|
10
|
+
required?: boolean;
|
|
11
|
+
description?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface OutcomeSpendCaps {
|
|
15
|
+
maxCostCents: number;
|
|
16
|
+
window?: SpendWindow;
|
|
17
|
+
periodCapCents?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface OutcomeQualityGateRubric {
|
|
21
|
+
name: string;
|
|
22
|
+
weight?: number;
|
|
23
|
+
passThreshold?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface OutcomeQualityGateConfig {
|
|
27
|
+
passThreshold?: number;
|
|
28
|
+
reviewerTriggerScore?: number;
|
|
29
|
+
riskKeywords?: string[];
|
|
30
|
+
rubrics?: OutcomeQualityGateRubric[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface OutcomeContextInjection {
|
|
34
|
+
field: string;
|
|
35
|
+
label: string;
|
|
36
|
+
required?: boolean;
|
|
37
|
+
example?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface OutcomeTemplate {
|
|
41
|
+
slug: string;
|
|
42
|
+
vertical: OutcomeVertical;
|
|
43
|
+
systemPrompt: string;
|
|
44
|
+
inputs: OutcomeInputDefinition[];
|
|
45
|
+
outputFormat: string;
|
|
46
|
+
need: string;
|
|
47
|
+
capability: CapabilityTier;
|
|
48
|
+
spendCaps: OutcomeSpendCaps;
|
|
49
|
+
promptVersion: string;
|
|
50
|
+
contextInjection?: OutcomeContextInjection[];
|
|
51
|
+
blockedOrigins?: string[];
|
|
52
|
+
premiumAgent?: string;
|
|
53
|
+
disclaimer?: string;
|
|
54
|
+
qualityGate?: OutcomeQualityGateConfig;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface OutcomeExecutionContext {
|
|
58
|
+
scope: SpendScope;
|
|
59
|
+
customerId?: string;
|
|
60
|
+
posture?: string;
|
|
61
|
+
budgetTier?: string;
|
|
62
|
+
imageCapable?: boolean;
|
|
63
|
+
context?: Record<string, string>;
|
|
64
|
+
reviewerCascadeAuto?: boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface OutcomeModelRequest {
|
|
68
|
+
role: OutcomeRole;
|
|
69
|
+
model: string;
|
|
70
|
+
vertical: string;
|
|
71
|
+
outcome: string;
|
|
72
|
+
promptVersion: string;
|
|
73
|
+
systemPrompt: string;
|
|
74
|
+
userPrompt: string;
|
|
75
|
+
outputFormat: string;
|
|
76
|
+
metadata: Record<string, string | number | boolean>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface OutcomeModelResponse {
|
|
80
|
+
text: string;
|
|
81
|
+
inputTokens?: number;
|
|
82
|
+
outputTokens?: number;
|
|
83
|
+
costCents?: number;
|
|
84
|
+
qualityScore?: number;
|
|
85
|
+
confidence?: number;
|
|
86
|
+
verdict?: string;
|
|
87
|
+
durationMs?: number;
|
|
88
|
+
provenance?: Record<string, string | number | boolean>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface OutcomeModelRunner {
|
|
92
|
+
run(request: OutcomeModelRequest): Promise<OutcomeModelResponse>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface OutcomeDecisionLink {
|
|
96
|
+
role: OutcomeRole;
|
|
97
|
+
decisionId: string;
|
|
98
|
+
entryHash?: string;
|
|
99
|
+
modelRequested: string;
|
|
100
|
+
modelResolved: string;
|
|
101
|
+
projectedCents: number;
|
|
102
|
+
actualCents: number;
|
|
103
|
+
inputTokens: number;
|
|
104
|
+
outputTokens: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface OutcomeRuntimeReceipt {
|
|
108
|
+
receiptId: string;
|
|
109
|
+
timestamp: string;
|
|
110
|
+
vertical: string;
|
|
111
|
+
outcome: string;
|
|
112
|
+
promptVersion: string;
|
|
113
|
+
customerId?: string;
|
|
114
|
+
scopeKey: string;
|
|
115
|
+
status: OutcomeStatus;
|
|
116
|
+
drafter: {
|
|
117
|
+
model: string;
|
|
118
|
+
decisionId?: string;
|
|
119
|
+
costCents: number;
|
|
120
|
+
inputTokens: number;
|
|
121
|
+
outputTokens: number;
|
|
122
|
+
};
|
|
123
|
+
reviewer: {
|
|
124
|
+
model: string;
|
|
125
|
+
decisionId?: string;
|
|
126
|
+
costCents: number;
|
|
127
|
+
inputTokens: number;
|
|
128
|
+
outputTokens: number;
|
|
129
|
+
verdict: string;
|
|
130
|
+
} | null;
|
|
131
|
+
fallback: {
|
|
132
|
+
model: string;
|
|
133
|
+
decisionId?: string;
|
|
134
|
+
reason: string;
|
|
135
|
+
} | null;
|
|
136
|
+
triggerFired: string[];
|
|
137
|
+
qualityScore: number;
|
|
138
|
+
pass: boolean;
|
|
139
|
+
totalCostCents: number;
|
|
140
|
+
durationMs: number;
|
|
141
|
+
decisionLinks: OutcomeDecisionLink[];
|
|
142
|
+
metadata: {
|
|
143
|
+
need: string;
|
|
144
|
+
capability: CapabilityTier;
|
|
145
|
+
posture: string;
|
|
146
|
+
budgetTier: string;
|
|
147
|
+
blockedOrigins: string[];
|
|
148
|
+
provenance: Record<string, string | number | boolean>;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface OutcomeReceiptStore {
|
|
153
|
+
append(receipt: OutcomeRuntimeReceipt): Promise<void>;
|
|
154
|
+
readAll(): Promise<OutcomeRuntimeReceipt[]>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export class InMemoryOutcomeReceiptStore implements OutcomeReceiptStore {
|
|
158
|
+
private readonly receipts: OutcomeRuntimeReceipt[] = [];
|
|
159
|
+
|
|
160
|
+
async append(receipt: OutcomeRuntimeReceipt): Promise<void> {
|
|
161
|
+
this.receipts.push(receipt);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async readAll(): Promise<OutcomeRuntimeReceipt[]> {
|
|
165
|
+
return [...this.receipts];
|
|
166
|
+
}
|
|
167
|
+
}
|