@akilium/telemetry-collector 0.1.9 → 0.1.11
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 +28 -1
- package/bin/akilium-telemetry.mjs +0 -0
- package/bin/status-reporter.mjs +1 -1
- package/dist/instrumentation/src/client.d.ts +77 -0
- package/dist/instrumentation/src/client.js +237 -0
- package/dist/instrumentation/src/codex-cli.d.ts +20 -0
- package/dist/instrumentation/src/codex-cli.js +92 -0
- package/dist/instrumentation/src/codex-execution.d.ts +27 -0
- package/dist/instrumentation/src/codex-execution.js +123 -0
- package/dist/instrumentation/src/index.d.ts +11 -0
- package/dist/instrumentation/src/index.js +11 -0
- package/dist/instrumentation/src/persisted-file.d.ts +18 -0
- package/dist/instrumentation/src/persisted-file.js +65 -0
- package/dist/instrumentation/src/posting-wrappers.d.ts +49 -0
- package/dist/instrumentation/src/posting-wrappers.js +76 -0
- package/dist/instrumentation/src/wrappers.d.ts +68 -0
- package/dist/instrumentation/src/wrappers.js +76 -0
- package/dist/integration-contracts/src/action-lineage.d.ts +120 -0
- package/dist/integration-contracts/src/action-lineage.js +208 -0
- package/dist/integration-contracts/src/activity-classification.d.ts +251 -0
- package/dist/integration-contracts/src/activity-classification.js +406 -0
- package/dist/integration-contracts/src/ai-execution.d.ts +62 -0
- package/dist/integration-contracts/src/ai-execution.js +244 -0
- package/dist/integration-contracts/src/ai-session.d.ts +282 -0
- package/dist/integration-contracts/src/ai-session.js +192 -0
- package/dist/integration-contracts/src/artifact-lineage.d.ts +140 -0
- package/dist/integration-contracts/src/artifact-lineage.js +236 -0
- package/dist/integration-contracts/src/lineage-validation.d.ts +14 -0
- package/dist/integration-contracts/src/lineage-validation.js +64 -0
- package/dist/integration-contracts/src/posting-lineage.d.ts +105 -0
- package/dist/integration-contracts/src/posting-lineage.js +147 -0
- package/lib/execution-capture.mjs +1 -1
- package/lib/session-activity.mjs +130 -0
- package/lib/session-titles.mjs +13 -1
- package/package.json +16 -25
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/** Strict, metadata-only execution evidence contract. Numeric usage remains in canonical source facts. */
|
|
2
|
+
export const AI_EXECUTION_EVIDENCE_CONTRACT_VERSION = "1.0.0";
|
|
3
|
+
export const AI_EXECUTION_EVIDENCE_LIMITS = {
|
|
4
|
+
maxBytes: 64 * 1024,
|
|
5
|
+
maxExecutions: 32,
|
|
6
|
+
maxFactReferencesPerExecution: 32,
|
|
7
|
+
};
|
|
8
|
+
/** Contract fixture mapping only. Runtime mappings require a separately verified adapter version. */
|
|
9
|
+
export const AI_EXECUTION_SOURCE_MAPPINGS = {
|
|
10
|
+
"codex-execution-fixture-v1": { provider: "codex", runtimeVersion: "fixture" },
|
|
11
|
+
"codex-execution-cli-0.166.0": { provider: "codex", runtimeVersion: "0.166.0" },
|
|
12
|
+
};
|
|
13
|
+
export class AiExecutionContractError extends Error {
|
|
14
|
+
problems;
|
|
15
|
+
constructor(problems) {
|
|
16
|
+
super(`Invalid AI execution evidence: ${problems.join("; ")}`);
|
|
17
|
+
this.problems = problems;
|
|
18
|
+
this.name = "AiExecutionContractError";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const PACKET_FIELDS = new Set([
|
|
22
|
+
"contractVersion", "reportId", "mappingVersion", "namespace", "protectedSessionKey",
|
|
23
|
+
"executions", "predecessorReportId", "correctionReason",
|
|
24
|
+
]);
|
|
25
|
+
const EXECUTION_FIELDS = new Set([
|
|
26
|
+
"executionKey", "turnKey", "parentExecutionKey", "retryOfExecutionKey", "traceKey",
|
|
27
|
+
"relatedSessionKey", "relationship", "kind", "operation", "status", "startedAt", "endedAt",
|
|
28
|
+
"occurredAt", "factReferences",
|
|
29
|
+
]);
|
|
30
|
+
const FACT_FIELDS = new Set(["kind", "recordId", "revision"]);
|
|
31
|
+
const KEY = /^[a-f0-9]{64}$/;
|
|
32
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
33
|
+
const SAFE_REVISION = /^[A-Za-z0-9._:-]{1,160}$/;
|
|
34
|
+
const NAMESPACE = /^[A-Za-z0-9._-]{1,64}$/;
|
|
35
|
+
const DATETIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
36
|
+
const KINDS = ["model_call", "tool_execution", "agent_execution"];
|
|
37
|
+
const OPERATIONS = [
|
|
38
|
+
"model_inference", "read_file", "write_file", "run_tests", "command_execution", "tool_other", "agent_invocation",
|
|
39
|
+
];
|
|
40
|
+
const STATUSES = ["started", "succeeded", "failed", "cancelled", "unknown"];
|
|
41
|
+
const FACT_KINDS = ["event", "cost_fact", "provider_metric_fact"];
|
|
42
|
+
const CORRECTIONS = ["source_correction", "binding_correction", "timing_correction"];
|
|
43
|
+
const TOOL_OPERATIONS = ["read_file", "write_file", "run_tests", "command_execution", "tool_other"];
|
|
44
|
+
function isRecord(value) {
|
|
45
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
46
|
+
}
|
|
47
|
+
function hasOnly(value, allowed, path, problems) {
|
|
48
|
+
if (Object.keys(value).some((key) => !allowed.has(key)))
|
|
49
|
+
problems.push(`${path} has unrecognized fields`);
|
|
50
|
+
}
|
|
51
|
+
function validDateTime(value) {
|
|
52
|
+
if (typeof value !== "string" || !DATETIME.test(value) || !Number.isFinite(Date.parse(value)))
|
|
53
|
+
return false;
|
|
54
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d{1,9})?(?:Z|([+-])(\d{2}):(\d{2}))$/.exec(value);
|
|
55
|
+
if (!match)
|
|
56
|
+
return false;
|
|
57
|
+
const [, yearText, monthText, dayText, hourText, minuteText, secondText, , offsetHour, offsetMinute] = match;
|
|
58
|
+
const year = Number(yearText), month = Number(monthText), day = Number(dayText);
|
|
59
|
+
const hour = Number(hourText), minute = Number(minuteText), second = Number(secondText);
|
|
60
|
+
const daysInMonth = month >= 1 && month <= 12
|
|
61
|
+
? new Date(Date.UTC(year, month, 0)).getUTCDate()
|
|
62
|
+
: 0;
|
|
63
|
+
return year > 0 && day >= 1 && day <= daysInMonth && hour <= 23 && minute <= 59 && second <= 59 &&
|
|
64
|
+
(offsetHour === undefined || Number(offsetHour) <= 23 && Number(offsetMinute) <= 59);
|
|
65
|
+
}
|
|
66
|
+
function fail(problems) {
|
|
67
|
+
throw new AiExecutionContractError(problems);
|
|
68
|
+
}
|
|
69
|
+
/** Parse a closed packet and enforce source mapping, membership, correction and timing semantics. */
|
|
70
|
+
export function parseAiExecutionEvidencePacket(input) {
|
|
71
|
+
if (!isRecord(input))
|
|
72
|
+
fail(["packet must be an object"]);
|
|
73
|
+
const problems = [];
|
|
74
|
+
hasOnly(input, PACKET_FIELDS, "packet", problems);
|
|
75
|
+
if (input.contractVersion !== AI_EXECUTION_EVIDENCE_CONTRACT_VERSION)
|
|
76
|
+
problems.push("contractVersion is unsupported");
|
|
77
|
+
if (typeof input.reportId !== "string" || !UUID.test(input.reportId))
|
|
78
|
+
problems.push("reportId must be a UUID");
|
|
79
|
+
if (typeof input.mappingVersion !== "string" || !(input.mappingVersion in AI_EXECUTION_SOURCE_MAPPINGS))
|
|
80
|
+
problems.push("mappingVersion is unsupported");
|
|
81
|
+
if (typeof input.namespace !== "string" || !NAMESPACE.test(input.namespace))
|
|
82
|
+
problems.push("namespace is invalid");
|
|
83
|
+
if (typeof input.protectedSessionKey !== "string" || !KEY.test(input.protectedSessionKey))
|
|
84
|
+
problems.push("protectedSessionKey is invalid");
|
|
85
|
+
if (!Array.isArray(input.executions) || input.executions.length < 1 || input.executions.length > AI_EXECUTION_EVIDENCE_LIMITS.maxExecutions) {
|
|
86
|
+
problems.push("executions must contain between 1 and 32 records");
|
|
87
|
+
}
|
|
88
|
+
const predecessor = input.predecessorReportId;
|
|
89
|
+
const correction = input.correctionReason;
|
|
90
|
+
if ((predecessor === undefined) !== (correction === undefined))
|
|
91
|
+
problems.push("correction fields must be supplied together");
|
|
92
|
+
if (predecessor !== undefined && (typeof predecessor !== "string" || !UUID.test(predecessor)))
|
|
93
|
+
problems.push("predecessorReportId must be a UUID");
|
|
94
|
+
if (correction !== undefined && (typeof correction !== "string" || !CORRECTIONS.includes(correction)))
|
|
95
|
+
problems.push("correctionReason is unsupported");
|
|
96
|
+
if (typeof input.reportId === "string" && input.reportId === predecessor)
|
|
97
|
+
problems.push("report cannot correct itself");
|
|
98
|
+
const parsed = [];
|
|
99
|
+
const executionKeys = new Set();
|
|
100
|
+
if (Array.isArray(input.executions)) {
|
|
101
|
+
for (const [index, raw] of input.executions.entries()) {
|
|
102
|
+
const path = `executions[${index}]`;
|
|
103
|
+
if (!isRecord(raw)) {
|
|
104
|
+
problems.push(`${path} must be an object`);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
hasOnly(raw, EXECUTION_FIELDS, path, problems);
|
|
108
|
+
const keyFields = ["executionKey", "turnKey", "parentExecutionKey", "retryOfExecutionKey", "traceKey", "relatedSessionKey"];
|
|
109
|
+
for (const field of keyFields) {
|
|
110
|
+
if (raw[field] !== undefined && (typeof raw[field] !== "string" || !KEY.test(raw[field])))
|
|
111
|
+
problems.push(`${path}.${field} is invalid`);
|
|
112
|
+
}
|
|
113
|
+
if (typeof raw.executionKey === "string") {
|
|
114
|
+
if (executionKeys.has(raw.executionKey))
|
|
115
|
+
problems.push(`${path}.executionKey duplicates another record`);
|
|
116
|
+
executionKeys.add(raw.executionKey);
|
|
117
|
+
}
|
|
118
|
+
if (raw.parentExecutionKey === raw.executionKey || raw.retryOfExecutionKey === raw.executionKey)
|
|
119
|
+
problems.push(`${path} cannot refer to itself`);
|
|
120
|
+
const kindOk = typeof raw.kind === "string" && KINDS.includes(raw.kind);
|
|
121
|
+
const operationOk = typeof raw.operation === "string" && OPERATIONS.includes(raw.operation);
|
|
122
|
+
const statusOk = typeof raw.status === "string" && STATUSES.includes(raw.status);
|
|
123
|
+
if (!kindOk)
|
|
124
|
+
problems.push(`${path}.kind is unsupported`);
|
|
125
|
+
if (!operationOk)
|
|
126
|
+
problems.push(`${path}.operation is unsupported`);
|
|
127
|
+
if (!statusOk)
|
|
128
|
+
problems.push(`${path}.status is unsupported`);
|
|
129
|
+
if (kindOk && operationOk) {
|
|
130
|
+
const pairAllowed = raw.kind === "model_call" ? raw.operation === "model_inference"
|
|
131
|
+
: raw.kind === "agent_execution" ? raw.operation === "agent_invocation"
|
|
132
|
+
: TOOL_OPERATIONS.includes(raw.operation);
|
|
133
|
+
if (!pairAllowed)
|
|
134
|
+
problems.push(`${path}.kind and operation are incompatible`);
|
|
135
|
+
}
|
|
136
|
+
if ((raw.relationship === undefined) !== (raw.relatedSessionKey === undefined))
|
|
137
|
+
problems.push(`${path} relationship and relatedSessionKey must be supplied together`);
|
|
138
|
+
if (raw.relationship !== undefined && raw.relationship !== "delegates_to" && raw.relationship !== "forks_to")
|
|
139
|
+
problems.push(`${path}.relationship is unsupported`);
|
|
140
|
+
if (raw.startedAt !== undefined && !validDateTime(raw.startedAt))
|
|
141
|
+
problems.push(`${path}.startedAt is invalid`);
|
|
142
|
+
if (raw.endedAt !== undefined && !validDateTime(raw.endedAt))
|
|
143
|
+
problems.push(`${path}.endedAt is invalid`);
|
|
144
|
+
if (raw.occurredAt !== undefined && !validDateTime(raw.occurredAt))
|
|
145
|
+
problems.push(`${path}.occurredAt is invalid`);
|
|
146
|
+
if (raw.occurredAt !== undefined && (raw.startedAt !== undefined || raw.endedAt !== undefined))
|
|
147
|
+
problems.push(`${path} must use occurredAt or span bounds, not both`);
|
|
148
|
+
if (raw.startedAt !== undefined && raw.endedAt !== undefined && Date.parse(raw.endedAt) < Date.parse(raw.startedAt))
|
|
149
|
+
problems.push(`${path} timing bounds are reversed`);
|
|
150
|
+
if (raw.status === "started" && raw.endedAt !== undefined)
|
|
151
|
+
problems.push(`${path}.endedAt is invalid for a started execution`);
|
|
152
|
+
if (!Array.isArray(raw.factReferences) || raw.factReferences.length > AI_EXECUTION_EVIDENCE_LIMITS.maxFactReferencesPerExecution) {
|
|
153
|
+
problems.push(`${path}.factReferences must contain at most 32 references`);
|
|
154
|
+
}
|
|
155
|
+
const factRefs = [];
|
|
156
|
+
const factKeys = new Set();
|
|
157
|
+
if (Array.isArray(raw.factReferences)) {
|
|
158
|
+
for (const [refIndex, ref] of raw.factReferences.entries()) {
|
|
159
|
+
const refPath = `${path}.factReferences[${refIndex}]`;
|
|
160
|
+
if (!isRecord(ref)) {
|
|
161
|
+
problems.push(`${refPath} must be an object`);
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
hasOnly(ref, FACT_FIELDS, refPath, problems);
|
|
165
|
+
if (typeof ref.kind !== "string" || !FACT_KINDS.includes(ref.kind))
|
|
166
|
+
problems.push(`${refPath}.kind is unsupported`);
|
|
167
|
+
if (typeof ref.recordId !== "string" || !UUID.test(ref.recordId))
|
|
168
|
+
problems.push(`${refPath}.recordId must be a UUID`);
|
|
169
|
+
if (typeof ref.revision !== "string" || !SAFE_REVISION.test(ref.revision))
|
|
170
|
+
problems.push(`${refPath}.revision is invalid`);
|
|
171
|
+
const factIdentity = `${String(ref.kind)}:${String(ref.recordId)}:${String(ref.revision)}`;
|
|
172
|
+
if (factKeys.has(factIdentity))
|
|
173
|
+
problems.push(`${refPath} duplicates another fact reference`);
|
|
174
|
+
factKeys.add(factIdentity);
|
|
175
|
+
if (FACT_KINDS.includes(ref.kind) && typeof ref.recordId === "string" && UUID.test(ref.recordId) && typeof ref.revision === "string" && SAFE_REVISION.test(ref.revision)) {
|
|
176
|
+
factRefs.push({ kind: ref.kind, recordId: ref.recordId.toLowerCase(), revision: ref.revision });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (typeof raw.executionKey === "string" && KEY.test(raw.executionKey) && kindOk && operationOk && statusOk) {
|
|
181
|
+
parsed.push({
|
|
182
|
+
executionKey: raw.executionKey,
|
|
183
|
+
...(typeof raw.turnKey === "string" ? { turnKey: raw.turnKey } : {}),
|
|
184
|
+
...(typeof raw.parentExecutionKey === "string" ? { parentExecutionKey: raw.parentExecutionKey } : {}),
|
|
185
|
+
...(typeof raw.retryOfExecutionKey === "string" ? { retryOfExecutionKey: raw.retryOfExecutionKey } : {}),
|
|
186
|
+
...(typeof raw.traceKey === "string" ? { traceKey: raw.traceKey } : {}),
|
|
187
|
+
...(typeof raw.relatedSessionKey === "string" ? { relatedSessionKey: raw.relatedSessionKey } : {}),
|
|
188
|
+
...(raw.relationship === "delegates_to" || raw.relationship === "forks_to" ? { relationship: raw.relationship } : {}),
|
|
189
|
+
kind: raw.kind,
|
|
190
|
+
operation: raw.operation,
|
|
191
|
+
status: raw.status,
|
|
192
|
+
...(typeof raw.startedAt === "string" && validDateTime(raw.startedAt) ? { startedAt: raw.startedAt } : {}),
|
|
193
|
+
...(typeof raw.endedAt === "string" && validDateTime(raw.endedAt) ? { endedAt: raw.endedAt } : {}),
|
|
194
|
+
...(typeof raw.occurredAt === "string" && validDateTime(raw.occurredAt) ? { occurredAt: raw.occurredAt } : {}),
|
|
195
|
+
factReferences: factRefs,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const samePacketKeys = new Set(parsed.map((record) => record.executionKey));
|
|
201
|
+
const edges = new Map(parsed.map((record) => [record.executionKey, [record.parentExecutionKey, record.retryOfExecutionKey]
|
|
202
|
+
.filter((key) => key !== undefined && samePacketKeys.has(key))]));
|
|
203
|
+
const visiting = new Set();
|
|
204
|
+
const visited = new Set();
|
|
205
|
+
const visit = (key) => {
|
|
206
|
+
if (visiting.has(key))
|
|
207
|
+
return true;
|
|
208
|
+
if (visited.has(key))
|
|
209
|
+
return false;
|
|
210
|
+
visiting.add(key);
|
|
211
|
+
for (const target of edges.get(key) ?? [])
|
|
212
|
+
if (visit(target))
|
|
213
|
+
return true;
|
|
214
|
+
visiting.delete(key);
|
|
215
|
+
visited.add(key);
|
|
216
|
+
return false;
|
|
217
|
+
};
|
|
218
|
+
if ([...edges.keys()].some(visit))
|
|
219
|
+
problems.push("execution parent and retry relationships cannot contain cycles");
|
|
220
|
+
if (problems.length > 0)
|
|
221
|
+
fail(problems);
|
|
222
|
+
return {
|
|
223
|
+
contractVersion: AI_EXECUTION_EVIDENCE_CONTRACT_VERSION,
|
|
224
|
+
reportId: input.reportId.toLowerCase(),
|
|
225
|
+
mappingVersion: input.mappingVersion,
|
|
226
|
+
namespace: input.namespace,
|
|
227
|
+
protectedSessionKey: input.protectedSessionKey,
|
|
228
|
+
executions: parsed,
|
|
229
|
+
...(typeof predecessor === "string" ? { predecessorReportId: predecessor.toLowerCase(), correctionReason: correction } : {}),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/** Enforce the UTF-8 wire limit before parsing, then apply closed structural validation. */
|
|
233
|
+
export function parseAiExecutionEvidenceBody(body) {
|
|
234
|
+
if (new TextEncoder().encode(body).byteLength > AI_EXECUTION_EVIDENCE_LIMITS.maxBytes)
|
|
235
|
+
fail(["payload exceeds 65536 bytes"]);
|
|
236
|
+
let parsed;
|
|
237
|
+
try {
|
|
238
|
+
parsed = JSON.parse(body);
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
fail(["payload is not valid JSON"]);
|
|
242
|
+
}
|
|
243
|
+
return parseAiExecutionEvidencePacket(parsed);
|
|
244
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/** Independently versioned, content-free AI session evidence and read contracts. */
|
|
2
|
+
export declare const AI_SESSION_EVIDENCE_CONTRACT_VERSION: "1.0.0";
|
|
3
|
+
export declare const AI_SESSION_EVIDENCE_CAPABILITY: "ai_session_evidence_v1";
|
|
4
|
+
export declare const AI_SESSION_EVIDENCE_LIMITS: {
|
|
5
|
+
readonly maxBytes: 65536;
|
|
6
|
+
readonly maxEvidenceReferences: 32;
|
|
7
|
+
readonly maxExplanationBytes: 2048;
|
|
8
|
+
};
|
|
9
|
+
export type SessionWorkType = "software_delivery" | "decision_support" | "knowledge_output";
|
|
10
|
+
export type SessionEvidenceState = "positive" | "negative" | "partial" | "unknown" | "disputed" | "not_applicable";
|
|
11
|
+
export interface AiSessionEvidenceReferenceV1 {
|
|
12
|
+
sourceId: string;
|
|
13
|
+
sourceRecordId: string;
|
|
14
|
+
revision: string;
|
|
15
|
+
mappingVersion: string;
|
|
16
|
+
}
|
|
17
|
+
export interface AiSessionReferenceV1 {
|
|
18
|
+
namespace: string;
|
|
19
|
+
protectedSessionKey: string;
|
|
20
|
+
mappingVersion: string;
|
|
21
|
+
segmentKey: null;
|
|
22
|
+
}
|
|
23
|
+
export type AiSessionRevisionKind = "artifact" | "contribution" | "commit" | "pull_request" | "deployment" | "decision" | "knowledge_output" | "validation" | "policy" | "model_comparison" | "outcome";
|
|
24
|
+
export interface AiSessionRevisionTargetV1 {
|
|
25
|
+
kind: AiSessionRevisionKind;
|
|
26
|
+
reference: AiSessionEvidenceReferenceV1;
|
|
27
|
+
}
|
|
28
|
+
export interface AiSessionMembershipV1 {
|
|
29
|
+
targetKind: "completion" | "action" | "work_context" | "parent" | "fork" | "equivalent_session";
|
|
30
|
+
target: AiSessionEvidenceReferenceV1;
|
|
31
|
+
relationship: "member" | "parent" | "fork" | "equivalent";
|
|
32
|
+
effectiveAt: string;
|
|
33
|
+
}
|
|
34
|
+
export interface AiSessionAssertionContextV1 {
|
|
35
|
+
goalDisposition: "achieved" | "unmet" | "partial" | "useful_stop" | "changed_direction" | null;
|
|
36
|
+
validationScope: string | null;
|
|
37
|
+
requiredCheck: boolean | null;
|
|
38
|
+
recipientRole: string | null;
|
|
39
|
+
modelId: string | null;
|
|
40
|
+
modelConfigurationRef: AiSessionEvidenceReferenceV1 | null;
|
|
41
|
+
taskRequirementsRef: AiSessionEvidenceReferenceV1 | null;
|
|
42
|
+
comparisonRef: AiSessionEvidenceReferenceV1 | null;
|
|
43
|
+
policyVersionRef: AiSessionEvidenceReferenceV1 | null;
|
|
44
|
+
conditionsChecked: boolean | null;
|
|
45
|
+
}
|
|
46
|
+
export interface AiSessionAssertionV1 {
|
|
47
|
+
kind: "goal" | "disposition" | "validation" | "acceptance" | "model_fit" | "approved_use" | "reuse" | "rework" | "outcome";
|
|
48
|
+
state: SessionEvidenceState;
|
|
49
|
+
effectiveAt: string;
|
|
50
|
+
target: AiSessionRevisionTargetV1 | null;
|
|
51
|
+
explanation: string;
|
|
52
|
+
evidence: AiSessionEvidenceReferenceV1[];
|
|
53
|
+
predecessorId: string | null;
|
|
54
|
+
context: AiSessionAssertionContextV1;
|
|
55
|
+
}
|
|
56
|
+
export type AiSessionLifecycleStage = "durable_output" | "committed" | "pr_included" | "merged" | "deployed" | "finding" | "reviewed" | "accepted_decision" | "acted_disposition" | "published" | "reused";
|
|
57
|
+
export interface AiSessionLifecycleV1 {
|
|
58
|
+
workType: SessionWorkType;
|
|
59
|
+
stage: AiSessionLifecycleStage;
|
|
60
|
+
from: AiSessionRevisionTargetV1;
|
|
61
|
+
to: AiSessionRevisionTargetV1;
|
|
62
|
+
environment: string | null;
|
|
63
|
+
inclusionEvidence: AiSessionEvidenceReferenceV1[];
|
|
64
|
+
transformationEvidence: AiSessionEvidenceReferenceV1 | null;
|
|
65
|
+
effectiveAt: string;
|
|
66
|
+
predecessorId: string | null;
|
|
67
|
+
}
|
|
68
|
+
export type AiSessionEvidencePacketV1 = {
|
|
69
|
+
contractVersion: typeof AI_SESSION_EVIDENCE_CONTRACT_VERSION;
|
|
70
|
+
reportId: string;
|
|
71
|
+
session: AiSessionReferenceV1;
|
|
72
|
+
occurredAt: string;
|
|
73
|
+
kind: "membership";
|
|
74
|
+
payload: AiSessionMembershipV1;
|
|
75
|
+
} | {
|
|
76
|
+
contractVersion: typeof AI_SESSION_EVIDENCE_CONTRACT_VERSION;
|
|
77
|
+
reportId: string;
|
|
78
|
+
session: AiSessionReferenceV1;
|
|
79
|
+
occurredAt: string;
|
|
80
|
+
kind: "assertion";
|
|
81
|
+
payload: AiSessionAssertionV1;
|
|
82
|
+
} | {
|
|
83
|
+
contractVersion: typeof AI_SESSION_EVIDENCE_CONTRACT_VERSION;
|
|
84
|
+
reportId: string;
|
|
85
|
+
session: AiSessionReferenceV1;
|
|
86
|
+
occurredAt: string;
|
|
87
|
+
kind: "lifecycle";
|
|
88
|
+
payload: AiSessionLifecycleV1;
|
|
89
|
+
};
|
|
90
|
+
export interface AiSessionReceiptV1 {
|
|
91
|
+
contractVersion: typeof AI_SESSION_EVIDENCE_CONTRACT_VERSION;
|
|
92
|
+
reportId: string;
|
|
93
|
+
receiptId: string;
|
|
94
|
+
state: "queued" | "binding_pending";
|
|
95
|
+
receivedAt: string;
|
|
96
|
+
}
|
|
97
|
+
export type AiSessionEvidenceErrorCode = "invalid_payload" | "invalid_enrollment" | "source_not_authorized" | "report_conflict" | "payload_too_large" | "unsupported_media_type" | "unsupported_contract" | "rate_limited" | "receiver_unavailable";
|
|
98
|
+
export interface AiSessionEvidenceErrorV1 {
|
|
99
|
+
code: AiSessionEvidenceErrorCode;
|
|
100
|
+
requestId: string;
|
|
101
|
+
}
|
|
102
|
+
export interface AiSessionPublicDimensionV1 {
|
|
103
|
+
name: "goal" | "validation" | "acceptance" | "progress" | "model_fit" | "approved_use";
|
|
104
|
+
state: SessionEvidenceState;
|
|
105
|
+
reasonCode: string;
|
|
106
|
+
reason: string;
|
|
107
|
+
evidence: AiSessionEvidenceReferenceV1[];
|
|
108
|
+
}
|
|
109
|
+
/** Public assessment deliberately has no weights, points, formulas, or private record identifiers. */
|
|
110
|
+
export interface AiSessionPublicAssessmentV1 {
|
|
111
|
+
state: "assessed" | "insufficient_evidence" | "mixed" | "pending" | "unsupported";
|
|
112
|
+
score: number | null;
|
|
113
|
+
methodVersion: string | null;
|
|
114
|
+
provisional: boolean;
|
|
115
|
+
confidence: "high" | "medium" | "low" | "unknown";
|
|
116
|
+
assessedMask: Array<"goal" | "validation" | "acceptance" | "progress" | "model_fit" | "approved_use">;
|
|
117
|
+
assessedCount: number;
|
|
118
|
+
applicableCount: number;
|
|
119
|
+
unweightedCoverage: number | null;
|
|
120
|
+
dimensions: AiSessionPublicDimensionV1[];
|
|
121
|
+
rankingEligible: boolean;
|
|
122
|
+
reasonCodes: string[];
|
|
123
|
+
}
|
|
124
|
+
export interface AiSessionPublicMoneyV1 {
|
|
125
|
+
amount: string | null;
|
|
126
|
+
currency: string | null;
|
|
127
|
+
basis: "direct" | "allocated" | "estimated" | null;
|
|
128
|
+
coverage: "complete" | "partial" | "unavailable";
|
|
129
|
+
unavailableReason: string | null;
|
|
130
|
+
basisReferences: AiSessionEvidenceReferenceV1[];
|
|
131
|
+
}
|
|
132
|
+
export interface AiSessionPublicTokensV1 {
|
|
133
|
+
input: string | null;
|
|
134
|
+
output: string | null;
|
|
135
|
+
total: string | null;
|
|
136
|
+
cachedInputSubset: string | null;
|
|
137
|
+
reasoningOutputSubset: string | null;
|
|
138
|
+
coverage: "complete" | "partial" | "unknown";
|
|
139
|
+
basisReferences: AiSessionEvidenceReferenceV1[];
|
|
140
|
+
}
|
|
141
|
+
export interface AiSessionPublicStageV1 {
|
|
142
|
+
stage: string | null;
|
|
143
|
+
qualification: "unknown" | "reported" | "source_confirmed" | "reviewed" | "independently_verified";
|
|
144
|
+
environment: string | null;
|
|
145
|
+
revision: string | null;
|
|
146
|
+
evidenceAt: string | null;
|
|
147
|
+
}
|
|
148
|
+
export interface AiSessionSummaryV1 {
|
|
149
|
+
sessionId: string;
|
|
150
|
+
title: string;
|
|
151
|
+
firstObservedAt: string | null;
|
|
152
|
+
lastObservedAt: string | null;
|
|
153
|
+
actualStartAt: string | null;
|
|
154
|
+
sourceId: string;
|
|
155
|
+
modelIds: string[];
|
|
156
|
+
workType: SessionWorkType | "mixed" | "unknown";
|
|
157
|
+
observationAge: "0_7_days" | "8_30_days" | "31_plus_days" | "unknown";
|
|
158
|
+
maturity: "completion_time" | "later_as_of" | "ongoing" | "unknown";
|
|
159
|
+
assessment: AiSessionPublicAssessmentV1;
|
|
160
|
+
stage: AiSessionPublicStageV1;
|
|
161
|
+
tokens: AiSessionPublicTokensV1;
|
|
162
|
+
money: AiSessionPublicMoneyV1[];
|
|
163
|
+
profileRevision: string;
|
|
164
|
+
}
|
|
165
|
+
export interface AiSessionSnapshotContextV1 {
|
|
166
|
+
asOf: string;
|
|
167
|
+
snapshotToken: string;
|
|
168
|
+
coverage: "complete" | "incomplete" | "unknown";
|
|
169
|
+
timeMeaning: "first_observed_cohort_with_observed_session_totals";
|
|
170
|
+
authorizedCount: number;
|
|
171
|
+
canonicalGeneration: string;
|
|
172
|
+
evidenceGeneration: string;
|
|
173
|
+
}
|
|
174
|
+
export interface AiSessionPageV1 {
|
|
175
|
+
context: AiSessionSnapshotContextV1;
|
|
176
|
+
items: AiSessionSummaryV1[];
|
|
177
|
+
continuation: string | null;
|
|
178
|
+
portfolioTokens: AiSessionPublicTokensV1;
|
|
179
|
+
portfolioMoney: AiSessionPublicMoneyV1[];
|
|
180
|
+
}
|
|
181
|
+
export interface AiSessionMapPointV1 {
|
|
182
|
+
sessionId: string;
|
|
183
|
+
quality: number;
|
|
184
|
+
investment: string;
|
|
185
|
+
partitionId: string;
|
|
186
|
+
stage: string | null;
|
|
187
|
+
confidence: "high" | "medium" | "low" | "unknown";
|
|
188
|
+
coverage: number | null;
|
|
189
|
+
}
|
|
190
|
+
export interface AiSessionMapBucketV1 {
|
|
191
|
+
bucketId: string;
|
|
192
|
+
count: number;
|
|
193
|
+
qualityMin: number;
|
|
194
|
+
qualityMax: number;
|
|
195
|
+
investmentMin: string;
|
|
196
|
+
investmentMax: string;
|
|
197
|
+
drilldownToken: string;
|
|
198
|
+
partitionId: string;
|
|
199
|
+
}
|
|
200
|
+
export interface AiSessionMapV1 {
|
|
201
|
+
context: AiSessionSnapshotContextV1;
|
|
202
|
+
mode: "points" | "aggregated";
|
|
203
|
+
points: AiSessionMapPointV1[];
|
|
204
|
+
buckets: AiSessionMapBucketV1[];
|
|
205
|
+
plottableCount: number;
|
|
206
|
+
excludedCount: number;
|
|
207
|
+
excludedQueryToken: string;
|
|
208
|
+
}
|
|
209
|
+
export interface AiSessionMapDrilldownPageV1 {
|
|
210
|
+
context: AiSessionSnapshotContextV1;
|
|
211
|
+
items: AiSessionSummaryV1[];
|
|
212
|
+
offset: number;
|
|
213
|
+
total: number;
|
|
214
|
+
}
|
|
215
|
+
export interface AiSessionPublicEvidenceItemV1 {
|
|
216
|
+
reference: AiSessionEvidenceReferenceV1;
|
|
217
|
+
relationship: "membership" | "assertion" | "lifecycle" | "usage";
|
|
218
|
+
qualification: "declared" | "reported" | "source_confirmed" | "reviewed" | "independently_verified";
|
|
219
|
+
effectiveAt: string;
|
|
220
|
+
recordedAt: string;
|
|
221
|
+
predecessorId: string | null;
|
|
222
|
+
assertion: AiSessionAssertionV1 | null;
|
|
223
|
+
assertionId: string | null;
|
|
224
|
+
membership: AiSessionMembershipV1 | null;
|
|
225
|
+
lifecycle: AiSessionLifecycleV1 | null;
|
|
226
|
+
}
|
|
227
|
+
export interface AiSessionPublicEvidencePageV1 {
|
|
228
|
+
context: AiSessionSnapshotContextV1;
|
|
229
|
+
items: AiSessionPublicEvidenceItemV1[];
|
|
230
|
+
continuation: string | null;
|
|
231
|
+
}
|
|
232
|
+
export interface AiSessionDetailV1 {
|
|
233
|
+
context: AiSessionSnapshotContextV1;
|
|
234
|
+
session: AiSessionSummaryV1;
|
|
235
|
+
refreshState: "queued" | "binding_pending" | "evaluating" | "ready" | "insufficient_evidence" | "failed" | "unsupported";
|
|
236
|
+
}
|
|
237
|
+
export interface AiSessionPublicGraphPageV1 {
|
|
238
|
+
context: AiSessionSnapshotContextV1;
|
|
239
|
+
nodes: Array<{
|
|
240
|
+
id: string;
|
|
241
|
+
kind: string;
|
|
242
|
+
label: string;
|
|
243
|
+
reference: AiSessionEvidenceReferenceV1 | null;
|
|
244
|
+
}>;
|
|
245
|
+
edges: Array<{
|
|
246
|
+
from: string;
|
|
247
|
+
to: string;
|
|
248
|
+
relationship: string;
|
|
249
|
+
qualification: "reported" | "source_confirmed" | "reviewed" | "independently_verified";
|
|
250
|
+
reference: AiSessionEvidenceReferenceV1;
|
|
251
|
+
}>;
|
|
252
|
+
continuation: string | null;
|
|
253
|
+
}
|
|
254
|
+
export interface AiSessionPublicReadErrorV1 {
|
|
255
|
+
code: "denied" | "unavailable" | "invalid_query" | "narrow_query" | "access_changed" | "snapshot_expired" | "conflict";
|
|
256
|
+
requestId: string;
|
|
257
|
+
}
|
|
258
|
+
export type AiSessionReadResultV1<T> = {
|
|
259
|
+
state: "available" | "empty";
|
|
260
|
+
value: T;
|
|
261
|
+
} | {
|
|
262
|
+
state: "denied" | "unavailable";
|
|
263
|
+
error: AiSessionPublicReadErrorV1;
|
|
264
|
+
};
|
|
265
|
+
export declare class AiSessionContractError extends Error {
|
|
266
|
+
readonly field: string;
|
|
267
|
+
readonly code: "invalid_payload" | "payload_too_large";
|
|
268
|
+
constructor(field: string, code?: "invalid_payload" | "payload_too_large");
|
|
269
|
+
}
|
|
270
|
+
/** Parse an already-decoded packet. Use parseAiSessionEvidenceBody at an HTTP boundary for byte limits. */
|
|
271
|
+
export declare function parseAiSessionEvidencePacket(input: unknown): AiSessionEvidencePacketV1;
|
|
272
|
+
/** Build and validate a v1 evidence packet before handing it to an enrolled sender. */
|
|
273
|
+
export declare function buildAiSessionEvidencePacket(input: Omit<AiSessionEvidencePacketV1, "contractVersion">): AiSessionEvidencePacketV1;
|
|
274
|
+
/** Build a whole-session membership report. V1 intentionally has no segment argument. */
|
|
275
|
+
export declare function buildAiSessionMembershipPacket(input: {
|
|
276
|
+
reportId: string;
|
|
277
|
+
session: AiSessionReferenceV1;
|
|
278
|
+
occurredAt: string;
|
|
279
|
+
payload: AiSessionMembershipV1;
|
|
280
|
+
}): AiSessionEvidencePacketV1;
|
|
281
|
+
/** Enforce the wire byte cap before JSON parsing and then apply strict structural validation. */
|
|
282
|
+
export declare function parseAiSessionEvidenceBody(raw: string): AiSessionEvidencePacketV1;
|