@contractspec/lib.evolution 1.56.0 → 1.57.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/dist/analyzer/posthog-telemetry-reader.d.mts +24 -0
- package/dist/analyzer/posthog-telemetry-reader.d.mts.map +1 -0
- package/dist/analyzer/posthog-telemetry-reader.mjs +225 -0
- package/dist/analyzer/posthog-telemetry-reader.mjs.map +1 -0
- package/dist/analyzer/spec-analyzer.d.mts.map +1 -1
- package/dist/approval/integration.d.mts +2 -3
- package/dist/approval/integration.d.mts.map +1 -1
- package/dist/approval/integration.mjs +1 -1
- package/dist/generator/ai-spec-generator.d.mts +0 -1
- package/dist/generator/ai-spec-generator.d.mts.map +1 -1
- package/dist/generator/spec-generator.d.mts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +2 -1
- package/dist/types.d.mts.map +1 -1
- package/package.json +10 -10
- package/dist/ai-agent/src/approval/index.d.mts +0 -1
- package/dist/ai-agent/src/approval/workflow.d.mts +0 -136
- package/dist/ai-agent/src/approval/workflow.d.mts.map +0 -1
- package/dist/ai-agent/src/types.d.mts +0 -30
- package/dist/ai-agent/src/types.d.mts.map +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { OperationCoordinate, OperationMetricSample, SpecUsageStats } from "../types.mjs";
|
|
2
|
+
import { AnalyticsReader, DateRangeInput } from "@contractspec/lib.contracts/integrations/providers/analytics";
|
|
3
|
+
|
|
4
|
+
//#region src/analyzer/posthog-telemetry-reader.d.ts
|
|
5
|
+
interface ReadOperationSamplesInput {
|
|
6
|
+
operations?: OperationCoordinate[];
|
|
7
|
+
dateRange?: DateRangeInput;
|
|
8
|
+
limit?: number;
|
|
9
|
+
}
|
|
10
|
+
interface PosthogTelemetryReaderOptions {
|
|
11
|
+
eventPrefix?: string;
|
|
12
|
+
}
|
|
13
|
+
declare class PosthogTelemetryReader {
|
|
14
|
+
private readonly reader;
|
|
15
|
+
private readonly eventPrefix;
|
|
16
|
+
constructor(reader: AnalyticsReader, options?: PosthogTelemetryReaderOptions);
|
|
17
|
+
readOperationSamples(input: ReadOperationSamplesInput): Promise<OperationMetricSample[]>;
|
|
18
|
+
readAnomalyBaseline(operation: OperationCoordinate, windowDays?: number): Promise<SpecUsageStats | null>;
|
|
19
|
+
private readTopErrors;
|
|
20
|
+
private queryHogQL;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { PosthogTelemetryReader, PosthogTelemetryReaderOptions, ReadOperationSamplesInput };
|
|
24
|
+
//# sourceMappingURL=posthog-telemetry-reader.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posthog-telemetry-reader.d.mts","names":[],"sources":["../../src/analyzer/posthog-telemetry-reader.ts"],"mappings":";;;;UAWiB,yBAAA;EACf,UAAA,GAAa,mBAAA;EACb,SAAA,GAAY,cAAA;EACZ,KAAA;AAAA;AAAA,UAGe,6BAAA;EACf,WAAA;AAAA;AAAA,cAGW,sBAAA;EAAA,iBACM,MAAA;EAAA,iBACA,WAAA;cAGf,MAAA,EAAQ,eAAA,EACR,OAAA,GAAS,6BAAA;EAML,oBAAA,CACJ,KAAA,EAAO,yBAAA,GACN,OAAA,CAAQ,qBAAA;EAwBL,mBAAA,CACJ,SAAA,EAAW,mBAAA,EACX,UAAA,YACC,OAAA,CAAQ,cAAA;EAAA,QAkCG,aAAA;EAAA,QAiCA,UAAA;AAAA"}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
//#region src/analyzer/posthog-telemetry-reader.ts
|
|
2
|
+
var PosthogTelemetryReader = class {
|
|
3
|
+
reader;
|
|
4
|
+
eventPrefix;
|
|
5
|
+
constructor(reader, options = {}) {
|
|
6
|
+
this.reader = reader;
|
|
7
|
+
this.eventPrefix = options.eventPrefix ?? "observability";
|
|
8
|
+
}
|
|
9
|
+
async readOperationSamples(input) {
|
|
10
|
+
return mapOperationSamples(await this.queryHogQL({
|
|
11
|
+
query: [
|
|
12
|
+
"select",
|
|
13
|
+
" properties.operation as operationKey,",
|
|
14
|
+
" properties.version as version,",
|
|
15
|
+
" properties.durationMs as durationMs,",
|
|
16
|
+
" properties.success as success,",
|
|
17
|
+
" properties.errorCode as errorCode,",
|
|
18
|
+
" properties.tenantId as tenantId,",
|
|
19
|
+
" properties.traceId as traceId,",
|
|
20
|
+
" properties.metadata as metadata,",
|
|
21
|
+
" timestamp as timestamp",
|
|
22
|
+
"from events",
|
|
23
|
+
`where ${buildOperationWhereClause(this.eventPrefix, input)}`,
|
|
24
|
+
"order by timestamp desc",
|
|
25
|
+
`limit ${input.limit ?? 1e3}`
|
|
26
|
+
].join("\n"),
|
|
27
|
+
values: buildOperationValues(input)
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
async readAnomalyBaseline(operation, windowDays = 7) {
|
|
31
|
+
const dateRange = buildWindowRange(windowDays);
|
|
32
|
+
const stats = mapBaselineStats(await this.queryHogQL({
|
|
33
|
+
query: [
|
|
34
|
+
"select",
|
|
35
|
+
" count() as totalCalls,",
|
|
36
|
+
" avg(properties.durationMs) as averageLatencyMs,",
|
|
37
|
+
" quantile(0.95)(properties.durationMs) as p95LatencyMs,",
|
|
38
|
+
" quantile(0.99)(properties.durationMs) as p99LatencyMs,",
|
|
39
|
+
" max(properties.durationMs) as maxLatencyMs,",
|
|
40
|
+
" sum(if(properties.success = 1, 1, 0)) as successCount,",
|
|
41
|
+
" sum(if(properties.success = 0, 1, 0)) as errorCount",
|
|
42
|
+
"from events",
|
|
43
|
+
`where ${buildOperationWhereClause(this.eventPrefix, {
|
|
44
|
+
operations: [operation],
|
|
45
|
+
dateRange
|
|
46
|
+
})}`
|
|
47
|
+
].join("\n"),
|
|
48
|
+
values: buildOperationValues({
|
|
49
|
+
operations: [operation],
|
|
50
|
+
dateRange
|
|
51
|
+
})
|
|
52
|
+
}), operation, dateRange);
|
|
53
|
+
if (!stats) return null;
|
|
54
|
+
const topErrors = await this.readTopErrors(operation, dateRange);
|
|
55
|
+
return {
|
|
56
|
+
...stats,
|
|
57
|
+
topErrors
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async readTopErrors(operation, dateRange) {
|
|
61
|
+
return mapRows(await this.queryHogQL({
|
|
62
|
+
query: [
|
|
63
|
+
"select",
|
|
64
|
+
" properties.errorCode as errorCode,",
|
|
65
|
+
" count() as errorCount",
|
|
66
|
+
"from events",
|
|
67
|
+
`where ${buildOperationWhereClause(this.eventPrefix, {
|
|
68
|
+
operations: [operation],
|
|
69
|
+
dateRange
|
|
70
|
+
})} and properties.success = 0`,
|
|
71
|
+
"group by errorCode",
|
|
72
|
+
"order by errorCount desc",
|
|
73
|
+
"limit 5"
|
|
74
|
+
].join("\n"),
|
|
75
|
+
values: buildOperationValues({
|
|
76
|
+
operations: [operation],
|
|
77
|
+
dateRange
|
|
78
|
+
})
|
|
79
|
+
})).reduce((acc, row) => {
|
|
80
|
+
const code = asString(row.errorCode);
|
|
81
|
+
if (!code) return acc;
|
|
82
|
+
acc[code] = asNumber(row.errorCount);
|
|
83
|
+
return acc;
|
|
84
|
+
}, {});
|
|
85
|
+
}
|
|
86
|
+
async queryHogQL(input) {
|
|
87
|
+
if (!this.reader.queryHogQL) throw new Error("Analytics reader does not support HogQL queries.");
|
|
88
|
+
return this.reader.queryHogQL(input);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
function buildOperationWhereClause(eventPrefix, input) {
|
|
92
|
+
const clauses = [`event = '${eventPrefix}.operation'`];
|
|
93
|
+
if (input.operations?.length) clauses.push(`(${buildOperationFilters(input.operations)})`);
|
|
94
|
+
if (input.dateRange?.from) clauses.push("timestamp >= {dateFrom}");
|
|
95
|
+
if (input.dateRange?.to) clauses.push("timestamp < {dateTo}");
|
|
96
|
+
return clauses.join(" and ");
|
|
97
|
+
}
|
|
98
|
+
function buildOperationValues(input) {
|
|
99
|
+
const values = {
|
|
100
|
+
dateFrom: toIsoString(input.dateRange?.from),
|
|
101
|
+
dateTo: toIsoString(input.dateRange?.to)
|
|
102
|
+
};
|
|
103
|
+
input.operations?.forEach((op, index) => {
|
|
104
|
+
values[`operationKey${index}`] = op.key;
|
|
105
|
+
values[`operationVersion${index}`] = op.version;
|
|
106
|
+
if (op.tenantId) values[`operationTenant${index}`] = op.tenantId;
|
|
107
|
+
});
|
|
108
|
+
return values;
|
|
109
|
+
}
|
|
110
|
+
function buildOperationFilters(operations) {
|
|
111
|
+
return operations.map((op, index) => {
|
|
112
|
+
const clauses = [`properties.operation = {operationKey${index}}`, `properties.version = {operationVersion${index}}`];
|
|
113
|
+
if (op.tenantId) clauses.push(`properties.tenantId = {operationTenant${index}}`);
|
|
114
|
+
return `(${clauses.join(" and ")})`;
|
|
115
|
+
}).join(" or ");
|
|
116
|
+
}
|
|
117
|
+
function mapOperationSamples(result) {
|
|
118
|
+
return mapRows(result).flatMap((row) => {
|
|
119
|
+
const operationKey = asString(row.operationKey);
|
|
120
|
+
const version = asString(row.version);
|
|
121
|
+
const timestamp = asDate(row.timestamp);
|
|
122
|
+
if (!operationKey || !version || !timestamp) return [];
|
|
123
|
+
return [{
|
|
124
|
+
operation: {
|
|
125
|
+
key: operationKey,
|
|
126
|
+
version,
|
|
127
|
+
tenantId: asOptionalString(row.tenantId) ?? void 0
|
|
128
|
+
},
|
|
129
|
+
durationMs: asNumber(row.durationMs),
|
|
130
|
+
success: asBoolean(row.success),
|
|
131
|
+
timestamp,
|
|
132
|
+
errorCode: asOptionalString(row.errorCode) ?? void 0,
|
|
133
|
+
traceId: asOptionalString(row.traceId) ?? void 0,
|
|
134
|
+
metadata: isRecord(row.metadata) ? row.metadata : void 0
|
|
135
|
+
}];
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function mapBaselineStats(result, operation, dateRange) {
|
|
139
|
+
const row = mapRows(result)[0];
|
|
140
|
+
if (!row) return null;
|
|
141
|
+
const totalCalls = asNumber(row.totalCalls);
|
|
142
|
+
if (!totalCalls) return null;
|
|
143
|
+
const successCount = asNumber(row.successCount);
|
|
144
|
+
const errorCount = asNumber(row.errorCount);
|
|
145
|
+
return {
|
|
146
|
+
operation,
|
|
147
|
+
totalCalls,
|
|
148
|
+
successRate: totalCalls ? successCount / totalCalls : 0,
|
|
149
|
+
errorRate: totalCalls ? errorCount / totalCalls : 0,
|
|
150
|
+
averageLatencyMs: asNumber(row.averageLatencyMs),
|
|
151
|
+
p95LatencyMs: asNumber(row.p95LatencyMs),
|
|
152
|
+
p99LatencyMs: asNumber(row.p99LatencyMs),
|
|
153
|
+
maxLatencyMs: asNumber(row.maxLatencyMs),
|
|
154
|
+
lastSeenAt: /* @__PURE__ */ new Date(),
|
|
155
|
+
windowStart: toDate(dateRange.from) ?? /* @__PURE__ */ new Date(),
|
|
156
|
+
windowEnd: toDate(dateRange.to) ?? /* @__PURE__ */ new Date(),
|
|
157
|
+
topErrors: {}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function mapRows(result) {
|
|
161
|
+
if (!Array.isArray(result.results) || !Array.isArray(result.columns)) return [];
|
|
162
|
+
const columns = result.columns;
|
|
163
|
+
return result.results.flatMap((row) => {
|
|
164
|
+
if (!Array.isArray(row)) return [];
|
|
165
|
+
const record = {};
|
|
166
|
+
columns.forEach((column, index) => {
|
|
167
|
+
record[column] = row[index];
|
|
168
|
+
});
|
|
169
|
+
return [record];
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function buildWindowRange(windowDays) {
|
|
173
|
+
const windowEnd = /* @__PURE__ */ new Date();
|
|
174
|
+
return {
|
|
175
|
+
from: /* @__PURE__ */ new Date(windowEnd.getTime() - windowDays * 24 * 60 * 60 * 1e3),
|
|
176
|
+
to: windowEnd
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function asString(value) {
|
|
180
|
+
if (typeof value === "string" && value.trim()) return value;
|
|
181
|
+
if (typeof value === "number") return String(value);
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
function asOptionalString(value) {
|
|
185
|
+
if (typeof value === "string") return value;
|
|
186
|
+
if (typeof value === "number") return String(value);
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
function asNumber(value) {
|
|
190
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
191
|
+
if (typeof value === "string" && value.trim()) {
|
|
192
|
+
const parsed = Number(value);
|
|
193
|
+
if (Number.isFinite(parsed)) return parsed;
|
|
194
|
+
}
|
|
195
|
+
return 0;
|
|
196
|
+
}
|
|
197
|
+
function asBoolean(value) {
|
|
198
|
+
if (typeof value === "boolean") return value;
|
|
199
|
+
if (typeof value === "number") return value !== 0;
|
|
200
|
+
if (typeof value === "string") return value.toLowerCase() === "true";
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
function asDate(value) {
|
|
204
|
+
if (value instanceof Date) return value;
|
|
205
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
206
|
+
const date = new Date(value);
|
|
207
|
+
if (!Number.isNaN(date.getTime())) return date;
|
|
208
|
+
}
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
function toIsoString(value) {
|
|
212
|
+
if (!value) return void 0;
|
|
213
|
+
return typeof value === "string" ? value : value.toISOString();
|
|
214
|
+
}
|
|
215
|
+
function toDate(value) {
|
|
216
|
+
if (!value) return null;
|
|
217
|
+
return value instanceof Date ? value : new Date(value);
|
|
218
|
+
}
|
|
219
|
+
function isRecord(value) {
|
|
220
|
+
return typeof value === "object" && value !== null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
//#endregion
|
|
224
|
+
export { PosthogTelemetryReader };
|
|
225
|
+
//# sourceMappingURL=posthog-telemetry-reader.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posthog-telemetry-reader.mjs","names":[],"sources":["../../src/analyzer/posthog-telemetry-reader.ts"],"sourcesContent":["import type {\n AnalyticsReader,\n AnalyticsQueryResult,\n DateRangeInput,\n} from '@contractspec/lib.contracts/integrations/providers/analytics';\nimport type {\n OperationCoordinate,\n OperationMetricSample,\n SpecUsageStats,\n} from '../types';\n\nexport interface ReadOperationSamplesInput {\n operations?: OperationCoordinate[];\n dateRange?: DateRangeInput;\n limit?: number;\n}\n\nexport interface PosthogTelemetryReaderOptions {\n eventPrefix?: string;\n}\n\nexport class PosthogTelemetryReader {\n private readonly reader: AnalyticsReader;\n private readonly eventPrefix: string;\n\n constructor(\n reader: AnalyticsReader,\n options: PosthogTelemetryReaderOptions = {}\n ) {\n this.reader = reader;\n this.eventPrefix = options.eventPrefix ?? 'observability';\n }\n\n async readOperationSamples(\n input: ReadOperationSamplesInput\n ): Promise<OperationMetricSample[]> {\n const result = await this.queryHogQL({\n query: [\n 'select',\n ' properties.operation as operationKey,',\n ' properties.version as version,',\n ' properties.durationMs as durationMs,',\n ' properties.success as success,',\n ' properties.errorCode as errorCode,',\n ' properties.tenantId as tenantId,',\n ' properties.traceId as traceId,',\n ' properties.metadata as metadata,',\n ' timestamp as timestamp',\n 'from events',\n `where ${buildOperationWhereClause(this.eventPrefix, input)}`,\n 'order by timestamp desc',\n `limit ${input.limit ?? 1000}`,\n ].join('\\n'),\n values: buildOperationValues(input),\n });\n\n return mapOperationSamples(result);\n }\n\n async readAnomalyBaseline(\n operation: OperationCoordinate,\n windowDays = 7\n ): Promise<SpecUsageStats | null> {\n const dateRange = buildWindowRange(windowDays);\n const baseResult = await this.queryHogQL({\n query: [\n 'select',\n ' count() as totalCalls,',\n ' avg(properties.durationMs) as averageLatencyMs,',\n ' quantile(0.95)(properties.durationMs) as p95LatencyMs,',\n ' quantile(0.99)(properties.durationMs) as p99LatencyMs,',\n ' max(properties.durationMs) as maxLatencyMs,',\n ' sum(if(properties.success = 1, 1, 0)) as successCount,',\n ' sum(if(properties.success = 0, 1, 0)) as errorCount',\n 'from events',\n `where ${buildOperationWhereClause(this.eventPrefix, {\n operations: [operation],\n dateRange,\n })}`,\n ].join('\\n'),\n values: buildOperationValues({\n operations: [operation],\n dateRange,\n }),\n });\n\n const stats = mapBaselineStats(baseResult, operation, dateRange);\n if (!stats) return null;\n\n const topErrors = await this.readTopErrors(operation, dateRange);\n return {\n ...stats,\n topErrors,\n };\n }\n\n private async readTopErrors(\n operation: OperationCoordinate,\n dateRange: DateRangeInput\n ): Promise<Record<string, number>> {\n const result = await this.queryHogQL({\n query: [\n 'select',\n ' properties.errorCode as errorCode,',\n ' count() as errorCount',\n 'from events',\n `where ${buildOperationWhereClause(this.eventPrefix, {\n operations: [operation],\n dateRange,\n })} and properties.success = 0`,\n 'group by errorCode',\n 'order by errorCount desc',\n 'limit 5',\n ].join('\\n'),\n values: buildOperationValues({\n operations: [operation],\n dateRange,\n }),\n });\n\n const rows = mapRows(result);\n return rows.reduce<Record<string, number>>((acc, row) => {\n const code = asString(row.errorCode);\n if (!code) return acc;\n acc[code] = asNumber(row.errorCount);\n return acc;\n }, {});\n }\n\n private async queryHogQL(input: {\n query: string;\n values: Record<string, unknown>;\n }): Promise<AnalyticsQueryResult> {\n if (!this.reader.queryHogQL) {\n throw new Error('Analytics reader does not support HogQL queries.');\n }\n return this.reader.queryHogQL(input);\n }\n}\n\nfunction buildOperationWhereClause(\n eventPrefix: string,\n input: { operations?: OperationCoordinate[]; dateRange?: DateRangeInput }\n): string {\n const clauses = [`event = '${eventPrefix}.operation'`];\n if (input.operations?.length) {\n clauses.push(`(${buildOperationFilters(input.operations)})`);\n }\n if (input.dateRange?.from) {\n clauses.push('timestamp >= {dateFrom}');\n }\n if (input.dateRange?.to) {\n clauses.push('timestamp < {dateTo}');\n }\n return clauses.join(' and ');\n}\n\nfunction buildOperationValues(input: {\n operations?: OperationCoordinate[];\n dateRange?: DateRangeInput;\n}): Record<string, unknown> {\n const values: Record<string, unknown> = {\n dateFrom: toIsoString(input.dateRange?.from),\n dateTo: toIsoString(input.dateRange?.to),\n };\n input.operations?.forEach((op, index) => {\n values[`operationKey${index}`] = op.key;\n values[`operationVersion${index}`] = op.version;\n if (op.tenantId) {\n values[`operationTenant${index}`] = op.tenantId;\n }\n });\n return values;\n}\n\nfunction buildOperationFilters(operations: OperationCoordinate[]): string {\n return operations\n .map((op, index) => {\n const clauses = [\n `properties.operation = {operationKey${index}}`,\n `properties.version = {operationVersion${index}}`,\n ];\n if (op.tenantId) {\n clauses.push(`properties.tenantId = {operationTenant${index}}`);\n }\n return `(${clauses.join(' and ')})`;\n })\n .join(' or ');\n}\n\nfunction mapOperationSamples(\n result: AnalyticsQueryResult\n): OperationMetricSample[] {\n const rows = mapRows(result);\n return rows.flatMap((row) => {\n const operationKey = asString(row.operationKey);\n const version = asString(row.version);\n const timestamp = asDate(row.timestamp);\n if (!operationKey || !version || !timestamp) {\n return [];\n }\n return [\n {\n operation: {\n key: operationKey,\n version,\n tenantId: asOptionalString(row.tenantId) ?? undefined,\n },\n durationMs: asNumber(row.durationMs),\n success: asBoolean(row.success),\n timestamp,\n errorCode: asOptionalString(row.errorCode) ?? undefined,\n traceId: asOptionalString(row.traceId) ?? undefined,\n metadata: isRecord(row.metadata) ? row.metadata : undefined,\n },\n ];\n });\n}\n\nfunction mapBaselineStats(\n result: AnalyticsQueryResult,\n operation: OperationCoordinate,\n dateRange: DateRangeInput\n): SpecUsageStats | null {\n const rows = mapRows(result);\n const row = rows[0];\n if (!row) return null;\n const totalCalls = asNumber(row.totalCalls);\n if (!totalCalls) return null;\n const successCount = asNumber(row.successCount);\n const errorCount = asNumber(row.errorCount);\n return {\n operation,\n totalCalls,\n successRate: totalCalls ? successCount / totalCalls : 0,\n errorRate: totalCalls ? errorCount / totalCalls : 0,\n averageLatencyMs: asNumber(row.averageLatencyMs),\n p95LatencyMs: asNumber(row.p95LatencyMs),\n p99LatencyMs: asNumber(row.p99LatencyMs),\n maxLatencyMs: asNumber(row.maxLatencyMs),\n lastSeenAt: new Date(),\n windowStart: toDate(dateRange.from) ?? new Date(),\n windowEnd: toDate(dateRange.to) ?? new Date(),\n topErrors: {},\n };\n}\n\nfunction mapRows(result: AnalyticsQueryResult): Record<string, unknown>[] {\n if (!Array.isArray(result.results) || !Array.isArray(result.columns)) {\n return [];\n }\n const columns = result.columns;\n return result.results.flatMap((row) => {\n if (!Array.isArray(row)) return [];\n const record: Record<string, unknown> = {};\n columns.forEach((column, index) => {\n record[column] = row[index];\n });\n return [record];\n });\n}\n\nfunction buildWindowRange(windowDays: number): DateRangeInput {\n const windowEnd = new Date();\n const windowStart = new Date(\n windowEnd.getTime() - windowDays * 24 * 60 * 60 * 1000\n );\n return {\n from: windowStart,\n to: windowEnd,\n };\n}\n\nfunction asString(value: unknown): string | null {\n if (typeof value === 'string' && value.trim()) return value;\n if (typeof value === 'number') return String(value);\n return null;\n}\n\nfunction asOptionalString(value: unknown): string | null {\n if (typeof value === 'string') return value;\n if (typeof value === 'number') return String(value);\n return null;\n}\n\nfunction asNumber(value: unknown): number {\n if (typeof value === 'number' && Number.isFinite(value)) return value;\n if (typeof value === 'string' && value.trim()) {\n const parsed = Number(value);\n if (Number.isFinite(parsed)) return parsed;\n }\n return 0;\n}\n\nfunction asBoolean(value: unknown): boolean {\n if (typeof value === 'boolean') return value;\n if (typeof value === 'number') return value !== 0;\n if (typeof value === 'string') return value.toLowerCase() === 'true';\n return false;\n}\n\nfunction asDate(value: unknown): Date | null {\n if (value instanceof Date) return value;\n if (typeof value === 'string' || typeof value === 'number') {\n const date = new Date(value);\n if (!Number.isNaN(date.getTime())) return date;\n }\n return null;\n}\n\nfunction toIsoString(value?: string | Date): string | undefined {\n if (!value) return undefined;\n return typeof value === 'string' ? value : value.toISOString();\n}\n\nfunction toDate(value?: string | Date): Date | null {\n if (!value) return null;\n return value instanceof Date ? value : new Date(value);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n"],"mappings":";AAqBA,IAAa,yBAAb,MAAoC;CAClC,AAAiB;CACjB,AAAiB;CAEjB,YACE,QACA,UAAyC,EAAE,EAC3C;AACA,OAAK,SAAS;AACd,OAAK,cAAc,QAAQ,eAAe;;CAG5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,MAAM;;AAGxD,SAAS,SAAS,OAAkD;AAClE,QAAO,OAAO,UAAU,YAAY,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spec-analyzer.d.mts","names":[],"sources":["../../src/analyzer/spec-analyzer.ts"],"
|
|
1
|
+
{"version":3,"file":"spec-analyzer.d.mts","names":[],"sources":["../../src/analyzer/spec-analyzer.ts"],"mappings":";;;;;UAciB,mBAAA;EACf,MAAA,GAAS,MAAA;EACT,aAAA;EACA,kBAAA;EACA,qBAAA;EACA,uBAAA;AAAA;AAAA,cAcW,YAAA;EAAA,iBACM,MAAA;EAAA,iBACA,aAAA;EAAA,iBACA,kBAAA;EAAA,iBACA,qBAAA;EAAA,iBACA,uBAAA;cAEL,OAAA,GAAS,mBAAA;EAUrB,gBAAA,CAAiB,OAAA,EAAS,qBAAA,KAA0B,cAAA;EAmCpD,eAAA,CACE,KAAA,EAAO,cAAA,IACP,QAAA,GAAW,cAAA,KACV,WAAA;EAqFH,gBAAA,CACE,SAAA,EAAW,WAAA,IACX,KAAA,EAAO,cAAA,KACN,aAAA;EA6BH,oBAAA,CACE,KAAA,EAAO,cAAA,IACP,SAAA,EAAW,WAAA,IACX,gBAAA;IAAqB,KAAA,EAAO,cAAA;EAAA,IAC3B,gBAAA;EAAA,QAsEK,YAAA;EAAA,QAcA,eAAA;EAAA,QAoCA,UAAA;EAAA,QAMA,iBAAA;EAAA,QAeA,gBAAA;EAAA,QAaA,qBAAA;AAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { SpecSuggestion, SpecSuggestionFilters, SpecSuggestionRepository, SpecSuggestionWriter, SuggestionStatus } from "../types.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import "../ai-agent/src/approval/index.mjs";
|
|
2
|
+
import { ApprovalWorkflow } from "@contractspec/lib.ai-agent/approval";
|
|
3
|
+
import { AgentSessionState } from "@contractspec/lib.ai-agent/types";
|
|
5
4
|
|
|
6
5
|
//#region src/approval/integration.d.ts
|
|
7
6
|
interface SpecSuggestionOrchestratorOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.d.mts","names":[],"sources":["../../src/approval/integration.ts"],"
|
|
1
|
+
{"version":3,"file":"integration.d.mts","names":[],"sources":["../../src/approval/integration.ts"],"mappings":";;;;;UAYiB,iCAAA;EACf,UAAA,EAAY,wBAAA;EACZ,QAAA,GAAW,gBAAA;EACX,MAAA,GAAS,oBAAA;AAAA;AAAA,cAGE,0BAAA;EAAA,iBACkB,OAAA;cAAA,OAAA,EAAS,iCAAA;EAEhC,MAAA,CACJ,UAAA,EAAY,cAAA,EACZ,OAAA,GAAU,iBAAA,EACV,cAAA,YAAuB,OAAA,CAAA,cAAA;EAmBnB,OAAA,CAAQ,EAAA,UAAY,QAAA,UAAkB,KAAA,YAAc,OAAA;EAqBpD,MAAA,CAAO,EAAA,UAAY,QAAA,UAAkB,KAAA,YAAc,OAAA;EAQzD,IAAA,CAAK,OAAA,GAAU,qBAAA,GAAqB,OAAA,CAAA,cAAA;EAAA,QAItB,gBAAA;AAAA;AAAA,UAOC,iCAAA;EACf,SAAA;EACA,gBAAA,IAAoB,UAAA,EAAY,cAAA;AAAA;AAAA,cAGrB,0BAAA,YAAsC,oBAAA;EAAA,iBAChC,SAAA;EAAA,iBACA,gBAAA;cAIL,OAAA,GAAS,iCAAA;EAUf,KAAA,CAAM,UAAA,EAAY,cAAA,GAAiB,OAAA;AAAA;AAAA,cAU9B,gCAAA,YAA4C,wBAAA;EAAA,iBACtC,KAAA;EAEX,MAAA,CAAO,UAAA,EAAY,cAAA,GAAiB,OAAA;EAIpC,OAAA,CAAQ,EAAA,WAAa,OAAA,CAAQ,cAAA;EAI7B,YAAA,CACJ,EAAA,UACA,MAAA,EAAQ,gBAAA,EACR,QAAA;IAAa,QAAA;IAAmB,KAAA;IAAgB,SAAA,GAAY,IAAA;EAAA,IAC3D,OAAA;EAeG,IAAA,CAAK,OAAA,GAAU,qBAAA,GAAqB,OAAA,CAAA,cAAA;AAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import "@contractspec/lib.ai-agent/approval";
|
|
3
|
+
import { ApprovalWorkflow } from "@contractspec/lib.ai-agent/approval";
|
|
4
4
|
|
|
5
5
|
//#region src/approval/integration.ts
|
|
6
6
|
var SpecSuggestionOrchestrator = class {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-spec-generator.d.mts","names":[],"sources":["../../src/generator/ai-spec-generator.ts"],"
|
|
1
|
+
{"version":3,"file":"ai-spec-generator.d.mts","names":[],"sources":["../../src/generator/ai-spec-generator.ts"],"mappings":";;;;;;AA2CA;UAAiB,qBAAA;;EAEf,KAAA,EAAO,aAAA;EAAP;EAEA,eAAA,GAAkB,eAAA;EAAlB;EAEA,YAAA;AAAA;;;AASF;;;;cAAa,eAAA;EAAA,iBACM,KAAA;EAAA,iBACA,MAAA;EAAA,iBACA,YAAA;cAEL,OAAA,EAAS,qBAAA;EA8CV;;;EA5BL,kBAAA,CACJ,MAAA,EAAQ,aAAA,EACR,OAAA;IACE,iBAAA;IACA,YAAA,GAAe,MAAA;EAAA,IAEhB,OAAA,CAAQ,cAAA;EA5BM;;;EA+CX,aAAA,CACJ,OAAA,EAAS,aAAA,IACT,OAAA;IAAW,aAAA;EAAA,IACV,OAAA,CAAQ,cAAA;EA5BL;;;EA+CA,iBAAA,CAAkB,UAAA,EAAY,cAAA,GAAiB,OAAA,CAAQ,cAAA;EAAA,QAyCrD,WAAA;EAAA,QAiDA,eAAA;EAAA,QAkCA,iBAAA;EAAA,QA2BA,sBAAA;AAAA;;;;iBAgBM,qBAAA,CACd,MAAA,EAAQ,qBAAA,GACP,eAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spec-generator.d.mts","names":[],"sources":["../../src/generator/spec-generator.ts"],"
|
|
1
|
+
{"version":3,"file":"spec-generator.d.mts","names":[],"sources":["../../src/generator/spec-generator.ts"],"mappings":";;;;;;UAiBiB,oBAAA;EACf,MAAA,GAAS,eAAA;EACT,MAAA,GAAS,MAAA;EACT,KAAA,SAAc,IAAA;EACd,OAAA,IAAW,GAAA,UAAa,OAAA,cAAqB,gBAAA;AAAA;AAAA,UAG9B,mBAAA;EACf,OAAA;EACA,SAAA;EACA,UAAA,GAAa,sBAAA;EACb,IAAA,GAAO,sBAAA;EACP,IAAA,GAAO,gBAAA;EACP,IAAA;EACA,QAAA,GAAW,MAAA;EACX,MAAA,GAAS,gBAAA;EACT,IAAA;EACA,SAAA;AAAA;AAAA,KAGU,SAAA,GAAY,OAAA,CACtB,aAAA,CAAc,cAAA,EAAgB,cAAA,GAAiB,qBAAA;EAC3C,IAAA,GAAO,OAAA,CAAQ,gBAAA;AAAA;AAAA,cAER,aAAA;EAAA,iBACM,MAAA;EAAA,iBACA,MAAA;EAAA,iBACA,KAAA;EAAA,iBACA,OAAA;cAEL,OAAA,GAAS,oBAAA;EAOrB,kBAAA,CACE,MAAA,EAAQ,aAAA,EACR,OAAA,GAAS,mBAAA,GACR,cAAA;EAwCH,eAAA,CACE,SAAA,EAAW,mBAAA,EACX,KAAA,EAAO,SAAA,EACP,MAAA,EAAQ,aAAA,EACR,OAAA,GAAS,IAAA,CAAK,mBAAA,YAAiC,cAAA;EAejD,kBAAA,CACE,UAAA,EAAY,cAAA,EACZ,MAAA,GAAQ,eAAA;;;;UAgCF,YAAA;EAAA,QAeA,gBAAA;EAAA,QAOA,eAAA;AAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AnomalySeverity, EvolutionConfig, IntentPattern, OperationCoordinate, OperationMetricSample, OptimizationHint, PatternConfidence, SpecAnomaly, SpecSuggestion, SpecSuggestionFilters, SpecSuggestionProposal, SpecSuggestionRepository, SpecSuggestionWriter, SpecUsageStats, SuggestionEvidence, SuggestionStatus } from "./types.mjs";
|
|
2
2
|
import { SpecAnalyzer, SpecAnalyzerOptions } from "./analyzer/spec-analyzer.mjs";
|
|
3
|
+
import { PosthogTelemetryReader, PosthogTelemetryReaderOptions, ReadOperationSamplesInput } from "./analyzer/posthog-telemetry-reader.mjs";
|
|
3
4
|
import { GenerateSpecOptions, SpecGenerator, SpecGeneratorOptions, SpecPatch } from "./generator/spec-generator.mjs";
|
|
4
5
|
import { AISpecGenerator, AISpecGeneratorConfig, createAISpecGenerator } from "./generator/ai-spec-generator.mjs";
|
|
5
6
|
import { FileSystemSuggestionWriter, FileSystemSuggestionWriterOptions, InMemorySpecSuggestionRepository, SpecSuggestionOrchestrator, SpecSuggestionOrchestratorOptions } from "./approval/integration.mjs";
|
|
6
|
-
export { AISpecGenerator, AISpecGeneratorConfig, AnomalySeverity, EvolutionConfig, FileSystemSuggestionWriter, FileSystemSuggestionWriterOptions, GenerateSpecOptions, InMemorySpecSuggestionRepository, IntentPattern, OperationCoordinate, OperationMetricSample, OptimizationHint, PatternConfidence, SpecAnalyzer, SpecAnalyzerOptions, SpecAnomaly, SpecGenerator, SpecGeneratorOptions, SpecPatch, SpecSuggestion, SpecSuggestionFilters, SpecSuggestionOrchestrator, SpecSuggestionOrchestratorOptions, SpecSuggestionProposal, SpecSuggestionRepository, SpecSuggestionWriter, SpecUsageStats, SuggestionEvidence, SuggestionStatus, createAISpecGenerator };
|
|
7
|
+
export { AISpecGenerator, AISpecGeneratorConfig, AnomalySeverity, EvolutionConfig, FileSystemSuggestionWriter, FileSystemSuggestionWriterOptions, GenerateSpecOptions, InMemorySpecSuggestionRepository, IntentPattern, OperationCoordinate, OperationMetricSample, OptimizationHint, PatternConfidence, PosthogTelemetryReader, PosthogTelemetryReaderOptions, ReadOperationSamplesInput, SpecAnalyzer, SpecAnalyzerOptions, SpecAnomaly, SpecGenerator, SpecGeneratorOptions, SpecPatch, SpecSuggestion, SpecSuggestionFilters, SpecSuggestionOrchestrator, SpecSuggestionOrchestratorOptions, SpecSuggestionProposal, SpecSuggestionRepository, SpecSuggestionWriter, SpecUsageStats, SuggestionEvidence, SuggestionStatus, createAISpecGenerator };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SpecAnalyzer } from "./analyzer/spec-analyzer.mjs";
|
|
2
|
+
import { PosthogTelemetryReader } from "./analyzer/posthog-telemetry-reader.mjs";
|
|
2
3
|
import { SpecGenerator } from "./generator/spec-generator.mjs";
|
|
3
4
|
import { AISpecGenerator, createAISpecGenerator } from "./generator/ai-spec-generator.mjs";
|
|
4
5
|
import { FileSystemSuggestionWriter, InMemorySpecSuggestionRepository, SpecSuggestionOrchestrator } from "./approval/integration.mjs";
|
|
5
6
|
|
|
6
|
-
export { AISpecGenerator, FileSystemSuggestionWriter, InMemorySpecSuggestionRepository, SpecAnalyzer, SpecGenerator, SpecSuggestionOrchestrator, createAISpecGenerator };
|
|
7
|
+
export { AISpecGenerator, FileSystemSuggestionWriter, InMemorySpecSuggestionRepository, PosthogTelemetryReader, SpecAnalyzer, SpecGenerator, SpecSuggestionOrchestrator, createAISpecGenerator };
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;KAQY,eAAA;AAAA,KACA,gBAAA;AAAA,UAEK,mBAAA;EACf,GAAA;EACA,OAAA;EACA,QAAA;AAAA;AAAA,UAGe,qBAAA;EACf,SAAA,EAAW,mBAAA;EACX,UAAA;EACA,OAAA;EACA,SAAA,EAAW,IAAA;EACX,gBAAA;EACA,SAAA;EACA,YAAA;EACA,KAAA;EACA,OAAA;EACA,OAAA;EACA,QAAA,GAAW,MAAA;AAAA;AAAA,UAGI,cAAA;EACf,SAAA,EAAW,mBAAA;EACX,UAAA;EACA,WAAA;EACA,SAAA;EACA,gBA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AAA,CAAO,UAAA,EAAY,cAAA,GAAiB,OAAA;EACpC,OAAA,CAAQ,EAAA,WAAa,OAAA,CAAQ,cAAA;EAC7B,YAAA,CACE,EAAA,UACA,MAAA,EAAQ,gBAAA,EACR,QAAA;IAAa,QAAA;IAAmB,KAAA;IAAgB,SAAA,GAAY,IAAA;EAAA,IAC3D,OAAA;EACH,IAAA,CAAK,OAAA,GAAU,qBAAA,GAAwB,OAAA,CAAQ,cAAA;AAAA;AAAA,UAGhC,oBAAA;EACf,KAAA,CAAM,UAAA,EAAY,cAAA,GAAiB,OAAA;AAAA;AAAA,UAGpB,gBAAA;EACf,SAAA,EAAW,mBAAA;EACX,QAAA;EACA,OAAA;EACA,aAAA;EACA,kBAAA;EACA,cAAA,GAAiB,cAAA;EACjB,cAAA;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractspec/lib.evolution",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.57.0",
|
|
4
4
|
"description": "AI-powered contract evolution engine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contractspec",
|
|
@@ -29,21 +29,21 @@
|
|
|
29
29
|
"test": "bun test"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"ai": "6.0.
|
|
32
|
+
"ai": "6.0.73",
|
|
33
33
|
"zod": "^4.3.5",
|
|
34
|
-
"@contractspec/lib.ai-agent": "1.
|
|
35
|
-
"@contractspec/lib.contracts": "1.
|
|
36
|
-
"@contractspec/lib.lifecycle": "1.
|
|
37
|
-
"@contractspec/lib.observability": "1.
|
|
38
|
-
"@contractspec/lib.schema": "1.
|
|
34
|
+
"@contractspec/lib.ai-agent": "1.57.0",
|
|
35
|
+
"@contractspec/lib.contracts": "1.57.0",
|
|
36
|
+
"@contractspec/lib.lifecycle": "1.57.0",
|
|
37
|
+
"@contractspec/lib.observability": "1.57.0",
|
|
38
|
+
"@contractspec/lib.schema": "1.57.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@prisma/client": "7.3.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@contractspec/tool.tsdown": "1.
|
|
45
|
-
"@contractspec/tool.typescript": "1.
|
|
46
|
-
"tsdown": "^0.
|
|
44
|
+
"@contractspec/tool.tsdown": "1.57.0",
|
|
45
|
+
"@contractspec/tool.typescript": "1.57.0",
|
|
46
|
+
"tsdown": "^0.20.3",
|
|
47
47
|
"typescript": "^5.9.3"
|
|
48
48
|
},
|
|
49
49
|
"exports": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import { ApprovalRequest, ApprovalStatus, ApprovalStore, ApprovalWorkflow } from "./workflow.mjs";
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { ToolCallInfo } from "../types.mjs";
|
|
2
|
-
|
|
3
|
-
//#region ../ai-agent/src/approval/workflow.d.ts
|
|
4
|
-
type ApprovalStatus = 'pending' | 'approved' | 'rejected';
|
|
5
|
-
/**
|
|
6
|
-
* Approval request for a tool execution.
|
|
7
|
-
*
|
|
8
|
-
* When a tool has `needsApproval: true` in AI SDK v6, the agent
|
|
9
|
-
* will pause and wait for approval before executing the tool.
|
|
10
|
-
*/
|
|
11
|
-
interface ApprovalRequest {
|
|
12
|
-
/** Unique request ID */
|
|
13
|
-
id: string;
|
|
14
|
-
/** Agent session ID */
|
|
15
|
-
sessionId: string;
|
|
16
|
-
/** Agent ID */
|
|
17
|
-
agentId: string;
|
|
18
|
-
/** Tenant ID for scoping */
|
|
19
|
-
tenantId?: string;
|
|
20
|
-
/** Tool name requiring approval */
|
|
21
|
-
toolName: string;
|
|
22
|
-
/** Tool call ID from AI SDK */
|
|
23
|
-
toolCallId: string;
|
|
24
|
-
/** Tool arguments */
|
|
25
|
-
toolArgs: unknown;
|
|
26
|
-
/** Human-readable reason for approval */
|
|
27
|
-
reason: string;
|
|
28
|
-
/** When the approval was requested */
|
|
29
|
-
requestedAt: Date;
|
|
30
|
-
/** Current status */
|
|
31
|
-
status: ApprovalStatus;
|
|
32
|
-
/** Additional context payload */
|
|
33
|
-
payload?: Record<string, unknown>;
|
|
34
|
-
/** Who resolved the approval */
|
|
35
|
-
reviewer?: string;
|
|
36
|
-
/** When the approval was resolved */
|
|
37
|
-
resolvedAt?: Date;
|
|
38
|
-
/** Reviewer notes */
|
|
39
|
-
notes?: string;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Storage interface for approval requests.
|
|
43
|
-
*/
|
|
44
|
-
interface ApprovalStore {
|
|
45
|
-
create(request: ApprovalRequest): Promise<void>;
|
|
46
|
-
get(id: string): Promise<ApprovalRequest | null>;
|
|
47
|
-
getByToolCallId(toolCallId: string): Promise<ApprovalRequest | null>;
|
|
48
|
-
update(id: string, updates: Partial<Omit<ApprovalRequest, 'id' | 'sessionId'>>): Promise<void>;
|
|
49
|
-
list(options?: {
|
|
50
|
-
status?: ApprovalStatus;
|
|
51
|
-
agentId?: string;
|
|
52
|
-
tenantId?: string;
|
|
53
|
-
}): Promise<ApprovalRequest[]>;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Approval workflow for managing tool execution approvals.
|
|
57
|
-
*
|
|
58
|
-
* Integrates with AI SDK v6's `needsApproval` feature on tools.
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```typescript
|
|
62
|
-
* const workflow = new ApprovalWorkflow();
|
|
63
|
-
*
|
|
64
|
-
* // When a tool needs approval
|
|
65
|
-
* const request = await workflow.requestApproval({
|
|
66
|
-
* sessionId: 'sess_123',
|
|
67
|
-
* agentId: 'support.bot.v1',
|
|
68
|
-
* toolName: 'delete_account',
|
|
69
|
-
* toolCallId: 'call_abc',
|
|
70
|
-
* toolArgs: { userId: 'user_123' },
|
|
71
|
-
* reason: 'Account deletion requires human approval',
|
|
72
|
-
* });
|
|
73
|
-
*
|
|
74
|
-
* // When approval is granted
|
|
75
|
-
* await workflow.approve(request.id, 'admin@example.com', 'Verified identity');
|
|
76
|
-
*
|
|
77
|
-
* // Or rejected
|
|
78
|
-
* await workflow.reject(request.id, 'admin@example.com', 'Suspicious activity');
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
declare class ApprovalWorkflow {
|
|
82
|
-
private readonly store;
|
|
83
|
-
constructor(store?: ApprovalStore);
|
|
84
|
-
/**
|
|
85
|
-
* Request approval for a tool execution.
|
|
86
|
-
*/
|
|
87
|
-
requestApproval(params: {
|
|
88
|
-
sessionId: string;
|
|
89
|
-
agentId: string;
|
|
90
|
-
tenantId?: string;
|
|
91
|
-
toolName: string;
|
|
92
|
-
toolCallId: string;
|
|
93
|
-
toolArgs: unknown;
|
|
94
|
-
reason: string;
|
|
95
|
-
payload?: Record<string, unknown>;
|
|
96
|
-
}): Promise<ApprovalRequest>;
|
|
97
|
-
/**
|
|
98
|
-
* Request approval from an AI SDK tool call.
|
|
99
|
-
*/
|
|
100
|
-
requestApprovalFromToolCall(toolCall: ToolCallInfo, context: {
|
|
101
|
-
sessionId: string;
|
|
102
|
-
agentId: string;
|
|
103
|
-
tenantId?: string;
|
|
104
|
-
reason?: string;
|
|
105
|
-
}): Promise<ApprovalRequest>;
|
|
106
|
-
/**
|
|
107
|
-
* Approve a pending request.
|
|
108
|
-
*/
|
|
109
|
-
approve(id: string, reviewer: string, notes?: string): Promise<void>;
|
|
110
|
-
/**
|
|
111
|
-
* Reject a pending request.
|
|
112
|
-
*/
|
|
113
|
-
reject(id: string, reviewer: string, notes?: string): Promise<void>;
|
|
114
|
-
/**
|
|
115
|
-
* Get approval status for a tool call.
|
|
116
|
-
*/
|
|
117
|
-
getStatus(toolCallId: string): Promise<ApprovalStatus | null>;
|
|
118
|
-
/**
|
|
119
|
-
* Check if a tool call is approved.
|
|
120
|
-
*/
|
|
121
|
-
isApproved(toolCallId: string): Promise<boolean>;
|
|
122
|
-
/**
|
|
123
|
-
* List pending approvals.
|
|
124
|
-
*/
|
|
125
|
-
listPending(options?: {
|
|
126
|
-
agentId?: string;
|
|
127
|
-
tenantId?: string;
|
|
128
|
-
}): Promise<ApprovalRequest[]>;
|
|
129
|
-
/**
|
|
130
|
-
* Get approval request by ID.
|
|
131
|
-
*/
|
|
132
|
-
get(id: string): Promise<ApprovalRequest | null>;
|
|
133
|
-
}
|
|
134
|
-
//#endregion
|
|
135
|
-
export { ApprovalRequest, ApprovalStatus, ApprovalStore, ApprovalWorkflow };
|
|
136
|
-
//# sourceMappingURL=workflow.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.d.mts","names":[],"sources":["../../../../../ai-agent/src/approval/workflow.ts"],"sourcesContent":[],"mappings":";;;KAGY,cAAA;;AAAZ;AAQA;;;;AA0Be,UA1BE,eAAA,CA0BF;EAAI;EAQF,EAAA,EAAA,MAAA;EACC;EAAkB,SAAA,EAAA,MAAA;EACT;EAAR,OAAA,EAAA,MAAA;EAC4B;EAAR,QAAA,CAAA,EAAA,MAAA;EAGb;EAAL,QAAA,EAAA,MAAA;EAAR;EACR,UAAA,EAAA,MAAA;EAEQ;EAGC,QAAA,EAAA,OAAA;EAAR;EAAO,MAAA,EAAA,MAAA;EAyFA;EAEe,WAAA,EAvHb,IAuHa;EAcd;EACA,MAAA,EApIJ,cAoII;EAAR;EAuBQ,OAAA,CAAA,EAzJF,MAyJE,CAAA,MAAA,EAAA,OAAA,CAAA;EAOD;EAAR,QAAA,CAAA,EAAA,MAAA;EAe0D;EAYD,UAAA,CAAA,EAvL/C,IAuL+C;EAYf;EAAR,KAAA,CAAA,EAAA,MAAA;;;;;AA0Bd,UArNR,aAAA,CAqNQ;EAAO,MAAA,CAAA,OAAA,EApNd,eAoNc,CAAA,EApNI,OAoNJ,CAAA,IAAA,CAAA;mBAnNb,QAAQ;uCACY,QAAQ;8BAGlC,QAAQ,KAAK,wCACrB;;aAEQ;;;MAGP,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAyFD,gBAAA;;sBAEe;;;;;;;;;;;;cAcd;MACR,QAAQ;;;;wCAuBA;;;;;MAOT,QAAQ;;;;yDAekD;;;;wDAYD;;;;iCAYvB,QAAQ;;;;kCAQP;;;;;;;MAWlC,QAAQ;;;;mBAOW,QAAQ"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ModelMessage, StepResult, ToolSet } from "ai";
|
|
2
|
-
|
|
3
|
-
//#region ../ai-agent/src/types.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Simplified tool call type for ContractSpec usage.
|
|
7
|
-
* Compatible with AI SDK v6 TypedToolCall.
|
|
8
|
-
*/
|
|
9
|
-
interface ToolCallInfo {
|
|
10
|
-
type: 'tool-call';
|
|
11
|
-
toolCallId: string;
|
|
12
|
-
toolName: string;
|
|
13
|
-
args: unknown;
|
|
14
|
-
}
|
|
15
|
-
type AgentStatus = 'idle' | 'running' | 'waiting' | 'completed' | 'failed' | 'escalated';
|
|
16
|
-
interface AgentSessionState {
|
|
17
|
-
sessionId: string;
|
|
18
|
-
agentId: string;
|
|
19
|
-
tenantId?: string;
|
|
20
|
-
actorId?: string;
|
|
21
|
-
status: AgentStatus;
|
|
22
|
-
messages: ModelMessage[];
|
|
23
|
-
steps: StepResult<ToolSet>[];
|
|
24
|
-
createdAt: Date;
|
|
25
|
-
updatedAt: Date;
|
|
26
|
-
metadata?: Record<string, string>;
|
|
27
|
-
}
|
|
28
|
-
//#endregion
|
|
29
|
-
export { AgentSessionState, ToolCallInfo };
|
|
30
|
-
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../../../../ai-agent/src/types.ts"],"sourcesContent":[],"mappings":";;;;;AAWA;AAoCA;AA8DA;AAKU,UAvGO,YAAA,CAuGP;EACE,IAAA,EAAA,WAAA;EACQ,UAAA,EAAA,MAAA;EAAX,QAAA,EAAA,MAAA;EACI,IAAA,EAAA,OAAA;;KAtED,WAAA;UA8DK,iBAAA;;;;;UAKP;YACE;SACH,WAAW;aACP;aACA;aACA"}
|