@x12i/xtivix-schema 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,19 +1,19 @@
1
- # @x12i/xtivix-schema
2
-
3
- Canonical AI call record schema (JSON Schema v1.0), TypeScript types, metadata rules and model aliases for xtivix.
4
-
5
- Part of [xtivix](https://www.npmjs.com/package/@x12i/xtivix), which collects provider-side AI logs, normalizes them to one canonical record, stores them in MongoDB and forwards them to observability tools.
6
-
7
- ## Install
8
-
9
- ```bash
10
- npm install @x12i/xtivix-schema
11
- ```
12
-
13
- ## Usage
14
-
15
- ```ts
16
- import { SCHEMA_VERSION, SCHEMA_MAJOR, canonicalRecordSchema } from '@x12i/xtivix-schema';
17
- ```
18
-
19
- ESM only, Node.js 22 or newer. Type declarations are included.
1
+ # @x12i/xtivix-schema
2
+
3
+ Canonical AI call record schema (JSON Schema v1.0), TypeScript types, metadata rules and model aliases for xtivix.
4
+
5
+ Part of [xtivix](https://www.npmjs.com/package/@x12i/xtivix), which collects provider-side AI logs, normalizes them to one canonical record, stores them in MongoDB and forwards them to observability tools.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @x12i/xtivix-schema
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { SCHEMA_VERSION, SCHEMA_MAJOR, canonicalRecordSchema } from '@x12i/xtivix-schema';
17
+ ```
18
+
19
+ ESM only, Node.js 22 or newer. Type declarations are included.
@@ -43,6 +43,56 @@
43
43
  },
44
44
  "MetadataValue": {
45
45
  "type": ["string", "number", "boolean"]
46
+ },
47
+ "ContentAddress": {
48
+ "title": "ContentAddress",
49
+ "type": "object",
50
+ "additionalProperties": false,
51
+ "required": ["object_type", "content_type", "record_id"],
52
+ "properties": {
53
+ "object_type": { "type": "string", "minLength": 1, "maxLength": 128 },
54
+ "content_type": { "type": "string", "minLength": 1, "maxLength": 128 },
55
+ "record_id": { "type": "string", "minLength": 1, "maxLength": 256 }
56
+ }
57
+ },
58
+ "ExecutionPiece": {
59
+ "title": "ExecutionPiece",
60
+ "type": "object",
61
+ "additionalProperties": false,
62
+ "required": ["content_type"],
63
+ "properties": {
64
+ "object_type": { "type": "string", "minLength": 1, "maxLength": 128 },
65
+ "content_type": { "type": "string", "minLength": 1, "maxLength": 128 },
66
+ "record_id": { "type": "string", "minLength": 1, "maxLength": 256 },
67
+ "label": { "type": "string", "minLength": 1, "maxLength": 128 }
68
+ }
69
+ },
70
+ "ExecutionStep": {
71
+ "title": "ExecutionStep",
72
+ "type": "object",
73
+ "additionalProperties": false,
74
+ "required": ["id"],
75
+ "properties": {
76
+ "id": { "type": "string", "minLength": 1, "maxLength": 128 },
77
+ "pieces": { "type": "array", "maxItems": 32, "items": { "$ref": "#/definitions/ExecutionPiece" } }
78
+ }
79
+ },
80
+ "Execution": {
81
+ "title": "Execution",
82
+ "description": "Memorix subject address for the step that produced this call. Sources are the content types that were read. Target is the content type that was written.",
83
+ "type": "object",
84
+ "additionalProperties": false,
85
+ "required": ["org_id", "agent_id", "process_id", "skill", "step", "sources", "target"],
86
+ "properties": {
87
+ "org_id": { "type": "string", "minLength": 1, "maxLength": 128 },
88
+ "agent_id": { "type": "string", "minLength": 1, "maxLength": 128 },
89
+ "process_id": { "type": "string", "minLength": 1, "maxLength": 128 },
90
+ "run_id": { "type": "string", "minLength": 1, "maxLength": 256 },
91
+ "skill": { "type": "string", "minLength": 1, "maxLength": 128 },
92
+ "step": { "$ref": "#/definitions/ExecutionStep" },
93
+ "sources": { "type": "array", "minItems": 1, "maxItems": 32, "items": { "$ref": "#/definitions/ContentAddress" } },
94
+ "target": { "$ref": "#/definitions/ContentAddress" }
95
+ }
46
96
  }
47
97
  },
48
98
  "properties": {
@@ -83,6 +133,7 @@
83
133
  "additionalProperties": true,
84
134
  "properties": {
85
135
  "messages": { "type": "array", "items": { "$ref": "#/definitions/Message" } },
136
+ "raw": { "description": "Provider request value, kept so the original format can be shown. Redacted with the messages.", "tsType": "unknown" },
86
137
  "params": {
87
138
  "title": "RequestParams",
88
139
  "type": "object",
@@ -104,6 +155,7 @@
104
155
  "additionalProperties": true,
105
156
  "properties": {
106
157
  "messages": { "type": "array", "items": { "$ref": "#/definitions/Message" } },
158
+ "raw": { "description": "Provider response value, kept so the original format can be shown. Redacted with the messages.", "tsType": "unknown" },
107
159
  "finish_reason": { "type": "string" }
108
160
  }
109
161
  },
@@ -146,11 +198,15 @@
146
198
  "metadata": {
147
199
  "type": "object",
148
200
  "maxProperties": 50,
149
- "propertyNames": { "pattern": "^[a-z0-9_.-]{1,64}$" },
201
+ "propertyNames": { "pattern": "^[A-Za-z0-9_.-]{1,64}$" },
150
202
  "additionalProperties": { "$ref": "#/definitions/MetadataValue" }
151
203
  },
204
+ "execution": { "$ref": "#/definitions/Execution" },
152
205
  "tags": { "type": "array", "items": { "type": "string" } },
153
206
  "provider_metadata": { "type": "object", "additionalProperties": true },
207
+ "request_hash": { "type": "string", "description": "Hash of request messages after redaction. Absent when content is not stored (REC-8)." },
208
+ "system_hash": { "type": "string", "description": "Hash of system messages alone, after redaction (REC-8)." },
209
+ "response_hash": { "type": "string", "description": "Hash of response messages after redaction. Absent when content is not stored (REC-8)." },
154
210
  "content_state": { "type": "string", "enum": ["full", "redacted", "truncated", "absent"] },
155
211
  "content_omitted_reason": {
156
212
  "type": "string",
package/dist/index.d.ts CHANGED
@@ -29,10 +29,23 @@ interface CanonicalRecord {
29
29
  metadata: {
30
30
  [k: string]: MetadataValue;
31
31
  };
32
+ execution?: Execution;
32
33
  tags?: string[];
33
34
  provider_metadata?: {
34
35
  [k: string]: unknown;
35
36
  };
37
+ /**
38
+ * Hash of request messages after redaction. Absent when content is not stored (REC-8).
39
+ */
40
+ request_hash?: string;
41
+ /**
42
+ * Hash of system messages alone, after redaction (REC-8).
43
+ */
44
+ system_hash?: string;
45
+ /**
46
+ * Hash of response messages after redaction. Absent when content is not stored (REC-8).
47
+ */
48
+ response_hash?: string;
36
49
  content_state: 'full' | 'redacted' | 'truncated' | 'absent';
37
50
  content_omitted_reason?: 'store_content_off' | 'provider' | 'retention' | 'scope' | 'not_requested' | 'body_unavailable';
38
51
  redaction?: RecordRedaction;
@@ -58,6 +71,10 @@ interface RecordModel {
58
71
  }
59
72
  interface RecordRequest {
60
73
  messages?: Message[];
74
+ /**
75
+ * Provider request value, kept so the original format can be shown. Redacted with the messages.
76
+ */
77
+ raw?: unknown;
61
78
  params?: RequestParams;
62
79
  [k: string]: unknown;
63
80
  }
@@ -98,6 +115,10 @@ interface RequestParams {
98
115
  }
99
116
  interface RecordResponse {
100
117
  messages?: Message[];
118
+ /**
119
+ * Provider response value, kept so the original format can be shown. Redacted with the messages.
120
+ */
121
+ raw?: unknown;
101
122
  finish_reason?: string;
102
123
  [k: string]: unknown;
103
124
  }
@@ -121,12 +142,65 @@ interface RecordCost {
121
142
  source: 'provider' | 'none';
122
143
  [k: string]: unknown;
123
144
  }
145
+ /**
146
+ * Memorix subject address for the step that produced this call. Sources are the content types that were read. Target is the content type that was written.
147
+ */
148
+ interface Execution {
149
+ org_id: string;
150
+ agent_id: string;
151
+ process_id: string;
152
+ run_id?: string;
153
+ skill: string;
154
+ step: ExecutionStep;
155
+ /**
156
+ * @minItems 1
157
+ * @maxItems 32
158
+ */
159
+ sources: [ContentAddress, ...ContentAddress[]];
160
+ target: ContentAddress;
161
+ }
162
+ interface ExecutionStep {
163
+ id: string;
164
+ /**
165
+ * @maxItems 32
166
+ */
167
+ pieces?: ExecutionPiece[];
168
+ }
169
+ interface ExecutionPiece {
170
+ object_type?: string;
171
+ content_type: string;
172
+ record_id?: string;
173
+ label?: string;
174
+ }
175
+ interface ContentAddress {
176
+ object_type: string;
177
+ content_type: string;
178
+ record_id: string;
179
+ }
124
180
  interface RecordRedaction {
125
181
  policy?: string;
126
182
  version?: number;
127
183
  [k: string]: unknown;
128
184
  }
129
185
 
186
+ /** Provider metadata attribute that carries an execution block as a JSON string or object. */
187
+ declare const EXECUTION_METADATA_KEY = "xtivix.execution";
188
+ interface ExecutionNormalization {
189
+ ok: true;
190
+ execution: Execution;
191
+ }
192
+ interface ExecutionNormalizationError {
193
+ ok: false;
194
+ error: string;
195
+ }
196
+ /**
197
+ * Accepts the stored snake_case shape or the memorix camelCase shape, including a JSON string.
198
+ * Extra keys are dropped. A present value that is not a complete address is an error.
199
+ */
200
+ declare function normalizeExecution(input: unknown): ExecutionNormalization | ExecutionNormalizationError;
201
+ /** Removes `xtivix.execution` from a metadata bag so it is not flattened into scalar keys. */
202
+ declare function takeExecutionValue(bag: Record<string, unknown>): unknown | undefined;
203
+
130
204
  declare const SCHEMA_VERSION = "1.0";
131
205
  declare const SCHEMA_MAJOR = 1;
132
206
  declare const canonicalRecordSchema: Record<string, unknown>;
@@ -137,7 +211,7 @@ interface SchemaValidationResult {
137
211
  declare function validateRecord(record: unknown): SchemaValidationResult;
138
212
  declare const METADATA_KEY_RE: RegExp;
139
213
  declare const METADATA_MAX_KEYS = 50;
140
- declare const CONVENTIONAL_METADATA_KEYS: readonly ["user_id", "session_id", "trace_id"];
214
+ declare const CONVENTIONAL_METADATA_KEYS: readonly ["user_id", "session_id", "trace_id", "recordId", "objectType"];
141
215
  interface MetadataNormalization {
142
216
  metadata: Record<string, MetadataValue>;
143
217
  rejected: Record<string, unknown>;
@@ -153,4 +227,4 @@ declare function flattenMetadata(input: unknown, prefix?: string, out?: Record<s
153
227
  /** Best-effort canonical alias for a raw provider model name. Returns undefined when unknown. */
154
228
  declare function resolveModelAlias(raw: string | undefined | null): string | undefined;
155
229
 
156
- export { CONVENTIONAL_METADATA_KEYS, type CanonicalRecord, METADATA_KEY_RE, METADATA_MAX_KEYS, type Message, type MetadataNormalization, type MetadataValue, type Part, type RecordCost, type RecordError, type RecordModel, type RecordRedaction, type RecordRequest, type RecordResponse, type RecordSource, type RecordUsage, type RequestParams, SCHEMA_MAJOR, SCHEMA_VERSION, type SchemaValidationResult, type Timestamp, canonicalRecordSchema, flattenMetadata, normalizeMetadata, resolveModelAlias, validateRecord };
230
+ export { CONVENTIONAL_METADATA_KEYS, type CanonicalRecord, type ContentAddress, EXECUTION_METADATA_KEY, type Execution, type ExecutionNormalization, type ExecutionNormalizationError, type ExecutionPiece, type ExecutionStep, METADATA_KEY_RE, METADATA_MAX_KEYS, type Message, type MetadataNormalization, type MetadataValue, type Part, type RecordCost, type RecordError, type RecordModel, type RecordRedaction, type RecordRequest, type RecordResponse, type RecordSource, type RecordUsage, type RequestParams, SCHEMA_MAJOR, SCHEMA_VERSION, type SchemaValidationResult, type Timestamp, canonicalRecordSchema, flattenMetadata, normalizeExecution, normalizeMetadata, resolveModelAlias, takeExecutionValue, validateRecord };
package/dist/index.js CHANGED
@@ -51,6 +51,56 @@ var canonical_record_v1_default = {
51
51
  },
52
52
  MetadataValue: {
53
53
  type: ["string", "number", "boolean"]
54
+ },
55
+ ContentAddress: {
56
+ title: "ContentAddress",
57
+ type: "object",
58
+ additionalProperties: false,
59
+ required: ["object_type", "content_type", "record_id"],
60
+ properties: {
61
+ object_type: { type: "string", minLength: 1, maxLength: 128 },
62
+ content_type: { type: "string", minLength: 1, maxLength: 128 },
63
+ record_id: { type: "string", minLength: 1, maxLength: 256 }
64
+ }
65
+ },
66
+ ExecutionPiece: {
67
+ title: "ExecutionPiece",
68
+ type: "object",
69
+ additionalProperties: false,
70
+ required: ["content_type"],
71
+ properties: {
72
+ object_type: { type: "string", minLength: 1, maxLength: 128 },
73
+ content_type: { type: "string", minLength: 1, maxLength: 128 },
74
+ record_id: { type: "string", minLength: 1, maxLength: 256 },
75
+ label: { type: "string", minLength: 1, maxLength: 128 }
76
+ }
77
+ },
78
+ ExecutionStep: {
79
+ title: "ExecutionStep",
80
+ type: "object",
81
+ additionalProperties: false,
82
+ required: ["id"],
83
+ properties: {
84
+ id: { type: "string", minLength: 1, maxLength: 128 },
85
+ pieces: { type: "array", maxItems: 32, items: { $ref: "#/definitions/ExecutionPiece" } }
86
+ }
87
+ },
88
+ Execution: {
89
+ title: "Execution",
90
+ description: "Memorix subject address for the step that produced this call. Sources are the content types that were read. Target is the content type that was written.",
91
+ type: "object",
92
+ additionalProperties: false,
93
+ required: ["org_id", "agent_id", "process_id", "skill", "step", "sources", "target"],
94
+ properties: {
95
+ org_id: { type: "string", minLength: 1, maxLength: 128 },
96
+ agent_id: { type: "string", minLength: 1, maxLength: 128 },
97
+ process_id: { type: "string", minLength: 1, maxLength: 128 },
98
+ run_id: { type: "string", minLength: 1, maxLength: 256 },
99
+ skill: { type: "string", minLength: 1, maxLength: 128 },
100
+ step: { $ref: "#/definitions/ExecutionStep" },
101
+ sources: { type: "array", minItems: 1, maxItems: 32, items: { $ref: "#/definitions/ContentAddress" } },
102
+ target: { $ref: "#/definitions/ContentAddress" }
103
+ }
54
104
  }
55
105
  },
56
106
  properties: {
@@ -91,6 +141,7 @@ var canonical_record_v1_default = {
91
141
  additionalProperties: true,
92
142
  properties: {
93
143
  messages: { type: "array", items: { $ref: "#/definitions/Message" } },
144
+ raw: { description: "Provider request value, kept so the original format can be shown. Redacted with the messages.", tsType: "unknown" },
94
145
  params: {
95
146
  title: "RequestParams",
96
147
  type: "object",
@@ -112,6 +163,7 @@ var canonical_record_v1_default = {
112
163
  additionalProperties: true,
113
164
  properties: {
114
165
  messages: { type: "array", items: { $ref: "#/definitions/Message" } },
166
+ raw: { description: "Provider response value, kept so the original format can be shown. Redacted with the messages.", tsType: "unknown" },
115
167
  finish_reason: { type: "string" }
116
168
  }
117
169
  },
@@ -154,11 +206,15 @@ var canonical_record_v1_default = {
154
206
  metadata: {
155
207
  type: "object",
156
208
  maxProperties: 50,
157
- propertyNames: { pattern: "^[a-z0-9_.-]{1,64}$" },
209
+ propertyNames: { pattern: "^[A-Za-z0-9_.-]{1,64}$" },
158
210
  additionalProperties: { $ref: "#/definitions/MetadataValue" }
159
211
  },
212
+ execution: { $ref: "#/definitions/Execution" },
160
213
  tags: { type: "array", items: { type: "string" } },
161
214
  provider_metadata: { type: "object", additionalProperties: true },
215
+ request_hash: { type: "string", description: "Hash of request messages after redaction. Absent when content is not stored (REC-8)." },
216
+ system_hash: { type: "string", description: "Hash of system messages alone, after redaction (REC-8)." },
217
+ response_hash: { type: "string", description: "Hash of response messages after redaction. Absent when content is not stored (REC-8)." },
162
218
  content_state: { type: "string", enum: ["full", "redacted", "truncated", "absent"] },
163
219
  content_omitted_reason: {
164
220
  type: "string",
@@ -177,6 +233,106 @@ var canonical_record_v1_default = {
177
233
  }
178
234
  };
179
235
 
236
+ // src/execution.ts
237
+ var EXECUTION_METADATA_KEY = "xtivix.execution";
238
+ function normalizeExecution(input) {
239
+ let value = input;
240
+ if (typeof value === "string") {
241
+ try {
242
+ value = JSON.parse(value);
243
+ } catch {
244
+ return { ok: false, error: "xtivix.execution is not valid JSON" };
245
+ }
246
+ }
247
+ if (!isObject(value)) return { ok: false, error: "execution must be an object" };
248
+ const org_id = name(pick(value, "org_id", "orgId"), 128);
249
+ const agent_id = name(pick(value, "agent_id", "agentId"), 128);
250
+ const process_id = name(pick(value, "process_id", "processId"), 128);
251
+ const skill = name(value.skill, 128);
252
+ if (!org_id || !agent_id || !process_id || !skill) {
253
+ return { ok: false, error: "execution requires org_id, agent_id, process_id and skill" };
254
+ }
255
+ const runRaw = pick(value, "run_id", "runId");
256
+ const run_id = runRaw === void 0 ? void 0 : name(runRaw, 256);
257
+ if (runRaw !== void 0 && !run_id) return { ok: false, error: "execution.run_id is invalid" };
258
+ if (!isObject(value.step)) return { ok: false, error: "execution.step is required" };
259
+ const stepId = name(value.step.id ?? pick(value.step, "step_id", "stepId"), 128);
260
+ if (!stepId) return { ok: false, error: "execution.step.id is required" };
261
+ let pieces;
262
+ if (value.step.pieces !== void 0) {
263
+ if (!Array.isArray(value.step.pieces) || value.step.pieces.length > 32) {
264
+ return { ok: false, error: "execution.step.pieces must be an array of at most 32" };
265
+ }
266
+ pieces = [];
267
+ for (const item of value.step.pieces) {
268
+ const one = piece(item);
269
+ if (!one) return { ok: false, error: "each step piece needs a content_type" };
270
+ pieces.push(one);
271
+ }
272
+ }
273
+ if (!Array.isArray(value.sources) || value.sources.length < 1 || value.sources.length > 32) {
274
+ return { ok: false, error: "execution.sources must contain 1 to 32 addresses" };
275
+ }
276
+ const sources = [];
277
+ for (const item of value.sources) {
278
+ const address = contentAddress(item);
279
+ if (!address) return { ok: false, error: "each source needs object_type, content_type and record_id" };
280
+ sources.push(address);
281
+ }
282
+ const target = contentAddress(value.target);
283
+ if (!target) return { ok: false, error: "execution.target needs object_type, content_type and record_id" };
284
+ const execution = {
285
+ org_id,
286
+ agent_id,
287
+ process_id,
288
+ skill,
289
+ step: pieces ? { id: stepId, pieces } : { id: stepId },
290
+ sources,
291
+ target
292
+ };
293
+ if (run_id) execution.run_id = run_id;
294
+ return { ok: true, execution };
295
+ }
296
+ function takeExecutionValue(bag) {
297
+ if (!Object.prototype.hasOwnProperty.call(bag, EXECUTION_METADATA_KEY)) return void 0;
298
+ const value = bag[EXECUTION_METADATA_KEY];
299
+ delete bag[EXECUTION_METADATA_KEY];
300
+ return value;
301
+ }
302
+ function contentAddress(input) {
303
+ if (!isObject(input)) return void 0;
304
+ const object_type = name(pick(input, "object_type", "objectType"), 128);
305
+ const content_type = name(pick(input, "content_type", "contentType"), 128);
306
+ const record_id = name(pick(input, "record_id", "recordId"), 256);
307
+ if (!object_type || !content_type || !record_id) return void 0;
308
+ return { object_type, content_type, record_id };
309
+ }
310
+ function piece(input) {
311
+ if (!isObject(input)) return void 0;
312
+ const content_type = name(pick(input, "content_type", "contentType"), 128);
313
+ if (!content_type) return void 0;
314
+ const object_type = name(pick(input, "object_type", "objectType"), 128);
315
+ const record_id = name(pick(input, "record_id", "recordId"), 256);
316
+ const label = name(input.label, 128);
317
+ const out = { content_type };
318
+ if (object_type) out.object_type = object_type;
319
+ if (record_id) out.record_id = record_id;
320
+ if (label) out.label = label;
321
+ return out;
322
+ }
323
+ function pick(obj, snake, camel) {
324
+ return obj[snake] ?? obj[camel];
325
+ }
326
+ function name(value, max) {
327
+ if (typeof value !== "string") return void 0;
328
+ const s = value.trim();
329
+ if (!s || s.length > max || /\s/.test(s) || /[\u0000-\u001f\u007f]/.test(s)) return void 0;
330
+ return s;
331
+ }
332
+ function isObject(value) {
333
+ return !!value && typeof value === "object" && !Array.isArray(value);
334
+ }
335
+
180
336
  // src/index.ts
181
337
  var SCHEMA_VERSION = "1.0";
182
338
  var SCHEMA_MAJOR = 1;
@@ -196,9 +352,9 @@ function validateRecord(record) {
196
352
  const valid = validateFn(record);
197
353
  return { valid, errors: valid ? [] : formatErrors(validateFn.errors) };
198
354
  }
199
- var METADATA_KEY_RE = /^[a-z0-9_.-]{1,64}$/;
355
+ var METADATA_KEY_RE = /^[A-Za-z0-9_.-]{1,64}$/;
200
356
  var METADATA_MAX_KEYS = 50;
201
- var CONVENTIONAL_METADATA_KEYS = ["user_id", "session_id", "trace_id"];
357
+ var CONVENTIONAL_METADATA_KEYS = ["user_id", "session_id", "trace_id", "recordId", "objectType"];
202
358
  function normalizeMetadata(input) {
203
359
  const metadata = {};
204
360
  const rejected = {};
@@ -266,14 +422,17 @@ function resolveModelAlias(raw) {
266
422
  }
267
423
  export {
268
424
  CONVENTIONAL_METADATA_KEYS,
425
+ EXECUTION_METADATA_KEY,
269
426
  METADATA_KEY_RE,
270
427
  METADATA_MAX_KEYS,
271
428
  SCHEMA_MAJOR,
272
429
  SCHEMA_VERSION,
273
430
  canonicalRecordSchema,
274
431
  flattenMetadata,
432
+ normalizeExecution,
275
433
  normalizeMetadata,
276
434
  resolveModelAlias,
435
+ takeExecutionValue,
277
436
  validateRecord
278
437
  };
279
438
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../canonical-record.v1.json"],"sourcesContent":["import { readFileSync } from 'node:fs';\r\nimport { fileURLToPath } from 'node:url';\r\nimport path from 'node:path';\r\nimport AjvModule, { type ErrorObject, type ValidateFunction } from 'ajv';\r\nimport { parse as parseYaml } from 'yaml';\r\nimport schemaJson from '../canonical-record.v1.json' with { type: 'json' };\r\nimport type { CanonicalRecord, MetadataValue } from './types.gen.js';\r\n\r\nexport * from './types.gen.js';\r\n\r\nexport const SCHEMA_VERSION = '1.0';\r\nexport const SCHEMA_MAJOR = 1;\r\n\r\nexport const canonicalRecordSchema: Record<string, unknown> = schemaJson as Record<string, unknown>;\r\n\r\nfunction aliasFilePath(): string {\r\n if (process.env.XTIVIX_MODEL_ALIASES) return process.env.XTIVIX_MODEL_ALIASES;\r\n const here = path.dirname(fileURLToPath(import.meta.url));\r\n return path.join(here, '..', 'model-aliases.yaml');\r\n}\r\n\r\nconst Ajv = (AjvModule as unknown as { default: typeof AjvModule }).default ?? AjvModule;\r\nconst ajv = new Ajv({ allErrors: true, strict: false });\r\nconst validateFn: ValidateFunction = ajv.compile(canonicalRecordSchema);\r\n\r\nexport interface SchemaValidationResult {\r\n valid: boolean;\r\n errors: string[];\r\n}\r\n\r\nfunction formatErrors(errors: ErrorObject[] | null | undefined): string[] {\r\n return (errors ?? []).map((e) => `${e.instancePath || '/'} ${e.message ?? 'invalid'}`.trim());\r\n}\r\n\r\nexport function validateRecord(record: unknown): SchemaValidationResult {\r\n const valid = validateFn(record) as boolean;\r\n return { valid, errors: valid ? [] : formatErrors(validateFn.errors) };\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// Metadata rules (REC-5)\r\n// ---------------------------------------------------------------------------\r\n\r\nexport const METADATA_KEY_RE = /^[a-z0-9_.-]{1,64}$/;\r\nexport const METADATA_MAX_KEYS = 50;\r\nexport const CONVENTIONAL_METADATA_KEYS = ['user_id', 'session_id', 'trace_id'] as const;\r\n\r\nexport interface MetadataNormalization {\r\n metadata: Record<string, MetadataValue>;\r\n rejected: Record<string, unknown>;\r\n}\r\n\r\n/**\r\n * Applies REC-5: keys must match the pattern, values must be scalars, at most 50 keys.\r\n * Anything that breaks the rules is returned in `rejected` so the caller can keep it in\r\n * `provider_metadata.rejected_metadata` rather than dropping it.\r\n */\r\nexport function normalizeMetadata(input: Record<string, unknown> | undefined | null): MetadataNormalization {\r\n const metadata: Record<string, MetadataValue> = {};\r\n const rejected: Record<string, unknown> = {};\r\n if (!input) return { metadata, rejected };\r\n // Conventional keys first so they survive the key cap.\r\n const entries = Object.entries(input).sort(([a], [b]) => {\r\n const ia = (CONVENTIONAL_METADATA_KEYS as readonly string[]).indexOf(a);\r\n const ib = (CONVENTIONAL_METADATA_KEYS as readonly string[]).indexOf(b);\r\n return (ia === -1 ? 99 : ia) - (ib === -1 ? 99 : ib);\r\n });\r\n for (const [key, value] of entries) {\r\n const scalar =\r\n typeof value === 'string' ||\r\n typeof value === 'boolean' ||\r\n (typeof value === 'number' && Number.isFinite(value));\r\n if (!METADATA_KEY_RE.test(key) || !scalar || Object.keys(metadata).length >= METADATA_MAX_KEYS) {\r\n rejected[key] = value;\r\n continue;\r\n }\r\n metadata[key] = value as MetadataValue;\r\n }\r\n return { metadata, rejected };\r\n}\r\n\r\n/** Flattens nested JSON into dotted keys, e.g. `{a:{b:1}}` -> `{\"a.b\":1}`. Arrays are JSON-encoded. */\r\nexport function flattenMetadata(input: unknown, prefix = '', out: Record<string, unknown> = {}): Record<string, unknown> {\r\n if (input === null || input === undefined) return out;\r\n if (typeof input !== 'object' || Array.isArray(input)) {\r\n if (prefix) out[prefix] = Array.isArray(input) ? JSON.stringify(input) : input;\r\n return out;\r\n }\r\n for (const [k, v] of Object.entries(input as Record<string, unknown>)) {\r\n const key = prefix ? `${prefix}.${k}` : k;\r\n if (v && typeof v === 'object' && !Array.isArray(v)) flattenMetadata(v, key, out);\r\n else if (Array.isArray(v)) out[key] = JSON.stringify(v);\r\n else out[key] = v;\r\n }\r\n return out;\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// Model aliases (EXT-2)\r\n// ---------------------------------------------------------------------------\r\n\r\ninterface AliasRule {\r\n match: string;\r\n replace: string;\r\n reapply?: boolean;\r\n}\r\n\r\ninterface AliasFile {\r\n version: number;\r\n exact: Record<string, string>;\r\n rules: AliasRule[];\r\n}\r\n\r\nlet aliasCache: { exact: Map<string, string>; rules: Array<{ re: RegExp; replace: string; reapply: boolean }> } | undefined;\r\n\r\nfunction loadAliases() {\r\n if (aliasCache) return aliasCache;\r\n const file = parseYaml(readFileSync(aliasFilePath(), 'utf8')) as AliasFile;\r\n aliasCache = {\r\n exact: new Map(Object.entries(file.exact ?? {}).map(([k, v]) => [k.toLowerCase(), v])),\r\n rules: (file.rules ?? []).map((r) => ({ re: new RegExp(r.match, 'i'), replace: r.replace, reapply: !!r.reapply })),\r\n };\r\n return aliasCache;\r\n}\r\n\r\n/** Best-effort canonical alias for a raw provider model name. Returns undefined when unknown. */\r\nexport function resolveModelAlias(raw: string | undefined | null): string | undefined {\r\n if (!raw) return undefined;\r\n const { exact, rules } = loadAliases();\r\n let current = raw.trim().toLowerCase();\r\n for (let depth = 0; depth < 4; depth++) {\r\n const hit = exact.get(current);\r\n if (hit) return hit;\r\n let rewritten: string | undefined;\r\n let reapply = false;\r\n for (const rule of rules) {\r\n if (rule.re.test(current)) {\r\n rewritten = current.replace(rule.re, rule.replace);\r\n reapply = rule.reapply;\r\n break;\r\n }\r\n }\r\n if (rewritten === undefined) return undefined;\r\n if (!reapply) return exact.get(rewritten) ?? rewritten;\r\n current = rewritten;\r\n }\r\n return undefined;\r\n}\r\n\r\nexport type { CanonicalRecord };\r\n","{\r\n \"$schema\": \"http://json-schema.org/draft-07/schema#\",\r\n \"$id\": \"https://xtivix.dev/schemas/canonical-record.v1.json\",\r\n \"title\": \"CanonicalRecord\",\r\n \"description\": \"One provider-side AI call, normalized. Schema version 1.x. Changes within 1.x are additive; readers ignore unknown fields.\",\r\n \"type\": \"object\",\r\n \"required\": [\"schema_version\", \"id\", \"source\", \"provider_record_id\", \"started_at\", \"operation\", \"model\", \"status\", \"metadata\", \"content_state\"],\r\n \"additionalProperties\": true,\r\n \"definitions\": {\r\n \"Timestamp\": {\r\n \"type\": \"string\",\r\n \"pattern\": \"^\\\\d{4}-\\\\d{2}-\\\\d{2}T\\\\d{2}:\\\\d{2}:\\\\d{2}(\\\\.\\\\d{1,9})?Z$\"\r\n },\r\n \"Part\": {\r\n \"title\": \"Part\",\r\n \"type\": \"object\",\r\n \"required\": [\"type\"],\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"type\": { \"type\": \"string\", \"enum\": [\"text\", \"tool_call\", \"tool_result\", \"media_ref\"] },\r\n \"text\": { \"type\": \"string\" },\r\n \"tool_call_id\": { \"type\": \"string\" },\r\n \"name\": { \"type\": \"string\" },\r\n \"arguments\": { \"type\": \"string\", \"description\": \"Tool call arguments as a JSON string\" },\r\n \"content\": { \"type\": \"string\", \"description\": \"Tool result content\" },\r\n \"is_error\": { \"type\": \"boolean\" },\r\n \"media_type\": { \"type\": \"string\", \"enum\": [\"image\", \"audio\", \"video\", \"file\", \"other\"] },\r\n \"mime_type\": { \"type\": \"string\" },\r\n \"size_bytes\": { \"type\": \"number\" },\r\n \"uri\": { \"type\": \"string\" }\r\n }\r\n },\r\n \"Message\": {\r\n \"title\": \"Message\",\r\n \"type\": \"object\",\r\n \"required\": [\"role\", \"parts\"],\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"role\": { \"type\": \"string\", \"enum\": [\"system\", \"user\", \"assistant\", \"tool\"] },\r\n \"name\": { \"type\": \"string\" },\r\n \"parts\": { \"type\": \"array\", \"items\": { \"$ref\": \"#/definitions/Part\" } }\r\n }\r\n },\r\n \"MetadataValue\": {\r\n \"type\": [\"string\", \"number\", \"boolean\"]\r\n }\r\n },\r\n \"properties\": {\r\n \"schema_version\": { \"type\": \"string\", \"pattern\": \"^1\\\\.\\\\d+$\" },\r\n \"id\": { \"type\": \"string\", \"minLength\": 3, \"maxLength\": 512 },\r\n \"tenant_id\": { \"type\": \"string\", \"description\": \"Reserved for multi-tenancy (SEC-12). Unused in v1.\" },\r\n \"source\": {\r\n \"title\": \"RecordSource\",\r\n \"type\": \"object\",\r\n \"required\": [\"id\", \"provider\"],\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"id\": { \"type\": \"string\", \"pattern\": \"^[a-z0-9_-]{1,64}$\" },\r\n \"provider\": { \"type\": \"string\", \"enum\": [\"openrouter\", \"cloudflare_ai_gateway\", \"aws_bedrock\", \"custom\"] },\r\n \"scope\": { \"type\": \"string\" }\r\n }\r\n },\r\n \"provider_record_id\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 440 },\r\n \"started_at\": { \"$ref\": \"#/definitions/Timestamp\" },\r\n \"ended_at\": { \"$ref\": \"#/definitions/Timestamp\" },\r\n \"received_at\": { \"$ref\": \"#/definitions/Timestamp\" },\r\n \"ingested_at\": { \"$ref\": \"#/definitions/Timestamp\" },\r\n \"operation\": { \"type\": \"string\", \"enum\": [\"chat\", \"completion\", \"embedding\", \"image\", \"other\"] },\r\n \"model\": {\r\n \"title\": \"RecordModel\",\r\n \"type\": \"object\",\r\n \"required\": [\"raw\"],\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"raw\": { \"type\": \"string\" },\r\n \"canonical\": { \"type\": \"string\" },\r\n \"upstream_provider\": { \"type\": \"string\" }\r\n }\r\n },\r\n \"request\": {\r\n \"title\": \"RecordRequest\",\r\n \"type\": \"object\",\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"messages\": { \"type\": \"array\", \"items\": { \"$ref\": \"#/definitions/Message\" } },\r\n \"params\": {\r\n \"title\": \"RequestParams\",\r\n \"type\": \"object\",\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"temperature\": { \"type\": \"number\" },\r\n \"top_p\": { \"type\": \"number\" },\r\n \"max_tokens\": { \"type\": \"number\" },\r\n \"stream\": { \"type\": \"boolean\" },\r\n \"tools\": { \"type\": \"array\" },\r\n \"extra\": { \"type\": \"object\" }\r\n }\r\n }\r\n }\r\n },\r\n \"response\": {\r\n \"title\": \"RecordResponse\",\r\n \"type\": \"object\",\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"messages\": { \"type\": \"array\", \"items\": { \"$ref\": \"#/definitions/Message\" } },\r\n \"finish_reason\": { \"type\": \"string\" }\r\n }\r\n },\r\n \"status\": { \"type\": \"string\", \"enum\": [\"ok\", \"error\", \"cached\", \"filtered\"] },\r\n \"error\": {\r\n \"title\": \"RecordError\",\r\n \"type\": \"object\",\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"code\": { \"type\": \"string\" },\r\n \"message\": { \"type\": \"string\" },\r\n \"http_status\": { \"type\": \"number\" }\r\n }\r\n },\r\n \"usage\": {\r\n \"title\": \"RecordUsage\",\r\n \"type\": \"object\",\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"input_tokens\": { \"type\": \"number\" },\r\n \"output_tokens\": { \"type\": \"number\" },\r\n \"total_tokens\": { \"type\": \"number\" },\r\n \"cached_tokens\": { \"type\": \"number\" },\r\n \"reasoning_tokens\": { \"type\": \"number\" }\r\n }\r\n },\r\n \"cost\": {\r\n \"title\": \"RecordCost\",\r\n \"type\": \"object\",\r\n \"required\": [\"source\"],\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"amount\": { \"type\": \"number\" },\r\n \"currency\": { \"type\": \"string\" },\r\n \"source\": { \"type\": \"string\", \"enum\": [\"provider\", \"none\"] }\r\n }\r\n },\r\n \"latency_ms\": { \"type\": \"number\" },\r\n \"ttft_ms\": { \"type\": \"number\" },\r\n \"metadata\": {\r\n \"type\": \"object\",\r\n \"maxProperties\": 50,\r\n \"propertyNames\": { \"pattern\": \"^[a-z0-9_.-]{1,64}$\" },\r\n \"additionalProperties\": { \"$ref\": \"#/definitions/MetadataValue\" }\r\n },\r\n \"tags\": { \"type\": \"array\", \"items\": { \"type\": \"string\" } },\r\n \"provider_metadata\": { \"type\": \"object\", \"additionalProperties\": true },\r\n \"content_state\": { \"type\": \"string\", \"enum\": [\"full\", \"redacted\", \"truncated\", \"absent\"] },\r\n \"content_omitted_reason\": {\r\n \"type\": \"string\",\r\n \"enum\": [\"store_content_off\", \"provider\", \"retention\", \"scope\", \"not_requested\", \"body_unavailable\"]\r\n },\r\n \"redaction\": {\r\n \"title\": \"RecordRedaction\",\r\n \"type\": \"object\",\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"policy\": { \"type\": \"string\" },\r\n \"version\": { \"type\": \"number\" }\r\n }\r\n },\r\n \"raw\": { \"description\": \"Original provider payload, kept only when enabled for the source\" }\r\n }\r\n}\r\n"],"mappings":";AAAA,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,OAAO,UAAU;AACjB,OAAO,eAA4D;AACnE,SAAS,SAAS,iBAAiB;;;ACJnC;AAAA,EACE,SAAW;AAAA,EACX,KAAO;AAAA,EACP,OAAS;AAAA,EACT,aAAe;AAAA,EACf,MAAQ;AAAA,EACR,UAAY,CAAC,kBAAkB,MAAM,UAAU,sBAAsB,cAAc,aAAa,SAAS,UAAU,YAAY,eAAe;AAAA,EAC9I,sBAAwB;AAAA,EACxB,aAAe;AAAA,IACb,WAAa;AAAA,MACX,MAAQ;AAAA,MACR,SAAW;AAAA,IACb;AAAA,IACA,MAAQ;AAAA,MACN,OAAS;AAAA,MACT,MAAQ;AAAA,MACR,UAAY,CAAC,MAAM;AAAA,MACnB,sBAAwB;AAAA,MACxB,YAAc;AAAA,QACZ,MAAQ,EAAE,MAAQ,UAAU,MAAQ,CAAC,QAAQ,aAAa,eAAe,WAAW,EAAE;AAAA,QACtF,MAAQ,EAAE,MAAQ,SAAS;AAAA,QAC3B,cAAgB,EAAE,MAAQ,SAAS;AAAA,QACnC,MAAQ,EAAE,MAAQ,SAAS;AAAA,QAC3B,WAAa,EAAE,MAAQ,UAAU,aAAe,uCAAuC;AAAA,QACvF,SAAW,EAAE,MAAQ,UAAU,aAAe,sBAAsB;AAAA,QACpE,UAAY,EAAE,MAAQ,UAAU;AAAA,QAChC,YAAc,EAAE,MAAQ,UAAU,MAAQ,CAAC,SAAS,SAAS,SAAS,QAAQ,OAAO,EAA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ClB;AACA,SAAO;AACT;AAkBA,IAAI;AAEJ,SAAS,cAAc;AACrB,MAAI,WAAY,QAAO;AACvB,QAAM,OAAO,UAAU,aAAa,cAAc,GAAG,MAAM,CAAC;AAC5D,eAAa;AAAA,IACX,OAAO,IAAI,IAAI,OAAO,QAAQ,KAAK,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;AAAA,IACrF,QAAQ,KAAK,SAAS,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,OAAO,GAAG,GAAG,SAAS,EAAE,SAAS,SAAS,CAAC,CAAC,EAAE,QAAQ,EAAE;AAAA,EACnH;AACA,SAAO;AACT;AAGO,SAAS,kBAAkB,KAAoD;AACpF,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,EAAE,OAAO,MAAM,IAAI,YAAY;AACrC,MAAI,UAAU,IAAI,KAAK,EAAE,YAAY;AACrC,WAAS,QAAQ,GAAG,QAAQ,GAAG,SAAS;AACtC,UAAM,MAAM,MAAM,IAAI,OAAO;AAC7B,QAAI,IAAK,QAAO;AAChB,QAAI;AACJ,QAAI,UAAU;AACd,eAAW,QAAQ,OAAO;AACxB,UAAI,KAAK,GAAG,KAAK,OAAO,GAAG;AACzB,oBAAY,QAAQ,QAAQ,KAAK,IAAI,KAAK,OAAO;AACjD,kBAAU,KAAK;AACf;AAAA,MACF;AAAA,IACF;AACA,QAAI,cAAc,OAAW,QAAO;AACpC,QAAI,CAAC,QAAS,QAAO,MAAM,IAAI,SAAS,KAAK;AAC7C,cAAU;AAAA,EACZ;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../canonical-record.v1.json","../src/execution.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\r\nimport { fileURLToPath } from 'node:url';\r\nimport path from 'node:path';\r\nimport AjvModule, { type ErrorObject, type ValidateFunction } from 'ajv';\r\nimport { parse as parseYaml } from 'yaml';\r\nimport schemaJson from '../canonical-record.v1.json' with { type: 'json' };\r\nimport type { CanonicalRecord, MetadataValue } from './types.gen.js';\r\n\r\nexport * from './types.gen.js';\r\nexport * from './execution.js';\r\n\r\nexport const SCHEMA_VERSION = '1.0';\r\nexport const SCHEMA_MAJOR = 1;\r\n\r\nexport const canonicalRecordSchema: Record<string, unknown> = schemaJson as Record<string, unknown>;\r\n\r\nfunction aliasFilePath(): string {\r\n if (process.env.XTIVIX_MODEL_ALIASES) return process.env.XTIVIX_MODEL_ALIASES;\r\n const here = path.dirname(fileURLToPath(import.meta.url));\r\n return path.join(here, '..', 'model-aliases.yaml');\r\n}\r\n\r\nconst Ajv = (AjvModule as unknown as { default: typeof AjvModule }).default ?? AjvModule;\r\nconst ajv = new Ajv({ allErrors: true, strict: false });\r\nconst validateFn: ValidateFunction = ajv.compile(canonicalRecordSchema);\r\n\r\nexport interface SchemaValidationResult {\r\n valid: boolean;\r\n errors: string[];\r\n}\r\n\r\nfunction formatErrors(errors: ErrorObject[] | null | undefined): string[] {\r\n return (errors ?? []).map((e) => `${e.instancePath || '/'} ${e.message ?? 'invalid'}`.trim());\r\n}\r\n\r\nexport function validateRecord(record: unknown): SchemaValidationResult {\r\n const valid = validateFn(record) as boolean;\r\n return { valid, errors: valid ? [] : formatErrors(validateFn.errors) };\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// Metadata rules (REC-5)\r\n// ---------------------------------------------------------------------------\r\n\r\nexport const METADATA_KEY_RE = /^[A-Za-z0-9_.-]{1,64}$/;\r\nexport const METADATA_MAX_KEYS = 50;\r\nexport const CONVENTIONAL_METADATA_KEYS = ['user_id', 'session_id', 'trace_id', 'recordId', 'objectType'] as const;\r\n\r\nexport interface MetadataNormalization {\r\n metadata: Record<string, MetadataValue>;\r\n rejected: Record<string, unknown>;\r\n}\r\n\r\n/**\r\n * Applies REC-5: keys must match the pattern, values must be scalars, at most 50 keys.\r\n * Anything that breaks the rules is returned in `rejected` so the caller can keep it in\r\n * `provider_metadata.rejected_metadata` rather than dropping it.\r\n */\r\nexport function normalizeMetadata(input: Record<string, unknown> | undefined | null): MetadataNormalization {\r\n const metadata: Record<string, MetadataValue> = {};\r\n const rejected: Record<string, unknown> = {};\r\n if (!input) return { metadata, rejected };\r\n // Conventional keys first so they survive the key cap.\r\n const entries = Object.entries(input).sort(([a], [b]) => {\r\n const ia = (CONVENTIONAL_METADATA_KEYS as readonly string[]).indexOf(a);\r\n const ib = (CONVENTIONAL_METADATA_KEYS as readonly string[]).indexOf(b);\r\n return (ia === -1 ? 99 : ia) - (ib === -1 ? 99 : ib);\r\n });\r\n for (const [key, value] of entries) {\r\n const scalar =\r\n typeof value === 'string' ||\r\n typeof value === 'boolean' ||\r\n (typeof value === 'number' && Number.isFinite(value));\r\n if (!METADATA_KEY_RE.test(key) || !scalar || Object.keys(metadata).length >= METADATA_MAX_KEYS) {\r\n rejected[key] = value;\r\n continue;\r\n }\r\n metadata[key] = value as MetadataValue;\r\n }\r\n return { metadata, rejected };\r\n}\r\n\r\n/** Flattens nested JSON into dotted keys, e.g. `{a:{b:1}}` -> `{\"a.b\":1}`. Arrays are JSON-encoded. */\r\nexport function flattenMetadata(input: unknown, prefix = '', out: Record<string, unknown> = {}): Record<string, unknown> {\r\n if (input === null || input === undefined) return out;\r\n if (typeof input !== 'object' || Array.isArray(input)) {\r\n if (prefix) out[prefix] = Array.isArray(input) ? JSON.stringify(input) : input;\r\n return out;\r\n }\r\n for (const [k, v] of Object.entries(input as Record<string, unknown>)) {\r\n const key = prefix ? `${prefix}.${k}` : k;\r\n if (v && typeof v === 'object' && !Array.isArray(v)) flattenMetadata(v, key, out);\r\n else if (Array.isArray(v)) out[key] = JSON.stringify(v);\r\n else out[key] = v;\r\n }\r\n return out;\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// Model aliases (EXT-2)\r\n// ---------------------------------------------------------------------------\r\n\r\ninterface AliasRule {\r\n match: string;\r\n replace: string;\r\n reapply?: boolean;\r\n}\r\n\r\ninterface AliasFile {\r\n version: number;\r\n exact: Record<string, string>;\r\n rules: AliasRule[];\r\n}\r\n\r\nlet aliasCache: { exact: Map<string, string>; rules: Array<{ re: RegExp; replace: string; reapply: boolean }> } | undefined;\r\n\r\nfunction loadAliases() {\r\n if (aliasCache) return aliasCache;\r\n const file = parseYaml(readFileSync(aliasFilePath(), 'utf8')) as AliasFile;\r\n aliasCache = {\r\n exact: new Map(Object.entries(file.exact ?? {}).map(([k, v]) => [k.toLowerCase(), v])),\r\n rules: (file.rules ?? []).map((r) => ({ re: new RegExp(r.match, 'i'), replace: r.replace, reapply: !!r.reapply })),\r\n };\r\n return aliasCache;\r\n}\r\n\r\n/** Best-effort canonical alias for a raw provider model name. Returns undefined when unknown. */\r\nexport function resolveModelAlias(raw: string | undefined | null): string | undefined {\r\n if (!raw) return undefined;\r\n const { exact, rules } = loadAliases();\r\n let current = raw.trim().toLowerCase();\r\n for (let depth = 0; depth < 4; depth++) {\r\n const hit = exact.get(current);\r\n if (hit) return hit;\r\n let rewritten: string | undefined;\r\n let reapply = false;\r\n for (const rule of rules) {\r\n if (rule.re.test(current)) {\r\n rewritten = current.replace(rule.re, rule.replace);\r\n reapply = rule.reapply;\r\n break;\r\n }\r\n }\r\n if (rewritten === undefined) return undefined;\r\n if (!reapply) return exact.get(rewritten) ?? rewritten;\r\n current = rewritten;\r\n }\r\n return undefined;\r\n}\r\n\r\nexport type { CanonicalRecord };\r\n","{\r\n \"$schema\": \"http://json-schema.org/draft-07/schema#\",\r\n \"$id\": \"https://xtivix.dev/schemas/canonical-record.v1.json\",\r\n \"title\": \"CanonicalRecord\",\r\n \"description\": \"One provider-side AI call, normalized. Schema version 1.x. Changes within 1.x are additive; readers ignore unknown fields.\",\r\n \"type\": \"object\",\r\n \"required\": [\"schema_version\", \"id\", \"source\", \"provider_record_id\", \"started_at\", \"operation\", \"model\", \"status\", \"metadata\", \"content_state\"],\r\n \"additionalProperties\": true,\r\n \"definitions\": {\r\n \"Timestamp\": {\r\n \"type\": \"string\",\r\n \"pattern\": \"^\\\\d{4}-\\\\d{2}-\\\\d{2}T\\\\d{2}:\\\\d{2}:\\\\d{2}(\\\\.\\\\d{1,9})?Z$\"\r\n },\r\n \"Part\": {\r\n \"title\": \"Part\",\r\n \"type\": \"object\",\r\n \"required\": [\"type\"],\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"type\": { \"type\": \"string\", \"enum\": [\"text\", \"tool_call\", \"tool_result\", \"media_ref\"] },\r\n \"text\": { \"type\": \"string\" },\r\n \"tool_call_id\": { \"type\": \"string\" },\r\n \"name\": { \"type\": \"string\" },\r\n \"arguments\": { \"type\": \"string\", \"description\": \"Tool call arguments as a JSON string\" },\r\n \"content\": { \"type\": \"string\", \"description\": \"Tool result content\" },\r\n \"is_error\": { \"type\": \"boolean\" },\r\n \"media_type\": { \"type\": \"string\", \"enum\": [\"image\", \"audio\", \"video\", \"file\", \"other\"] },\r\n \"mime_type\": { \"type\": \"string\" },\r\n \"size_bytes\": { \"type\": \"number\" },\r\n \"uri\": { \"type\": \"string\" }\r\n }\r\n },\r\n \"Message\": {\r\n \"title\": \"Message\",\r\n \"type\": \"object\",\r\n \"required\": [\"role\", \"parts\"],\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"role\": { \"type\": \"string\", \"enum\": [\"system\", \"user\", \"assistant\", \"tool\"] },\r\n \"name\": { \"type\": \"string\" },\r\n \"parts\": { \"type\": \"array\", \"items\": { \"$ref\": \"#/definitions/Part\" } }\r\n }\r\n },\r\n \"MetadataValue\": {\r\n \"type\": [\"string\", \"number\", \"boolean\"]\r\n },\r\n \"ContentAddress\": {\r\n \"title\": \"ContentAddress\",\r\n \"type\": \"object\",\r\n \"additionalProperties\": false,\r\n \"required\": [\"object_type\", \"content_type\", \"record_id\"],\r\n \"properties\": {\r\n \"object_type\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 128 },\r\n \"content_type\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 128 },\r\n \"record_id\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 256 }\r\n }\r\n },\r\n \"ExecutionPiece\": {\r\n \"title\": \"ExecutionPiece\",\r\n \"type\": \"object\",\r\n \"additionalProperties\": false,\r\n \"required\": [\"content_type\"],\r\n \"properties\": {\r\n \"object_type\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 128 },\r\n \"content_type\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 128 },\r\n \"record_id\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 256 },\r\n \"label\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 128 }\r\n }\r\n },\r\n \"ExecutionStep\": {\r\n \"title\": \"ExecutionStep\",\r\n \"type\": \"object\",\r\n \"additionalProperties\": false,\r\n \"required\": [\"id\"],\r\n \"properties\": {\r\n \"id\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 128 },\r\n \"pieces\": { \"type\": \"array\", \"maxItems\": 32, \"items\": { \"$ref\": \"#/definitions/ExecutionPiece\" } }\r\n }\r\n },\r\n \"Execution\": {\r\n \"title\": \"Execution\",\r\n \"description\": \"Memorix subject address for the step that produced this call. Sources are the content types that were read. Target is the content type that was written.\",\r\n \"type\": \"object\",\r\n \"additionalProperties\": false,\r\n \"required\": [\"org_id\", \"agent_id\", \"process_id\", \"skill\", \"step\", \"sources\", \"target\"],\r\n \"properties\": {\r\n \"org_id\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 128 },\r\n \"agent_id\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 128 },\r\n \"process_id\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 128 },\r\n \"run_id\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 256 },\r\n \"skill\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 128 },\r\n \"step\": { \"$ref\": \"#/definitions/ExecutionStep\" },\r\n \"sources\": { \"type\": \"array\", \"minItems\": 1, \"maxItems\": 32, \"items\": { \"$ref\": \"#/definitions/ContentAddress\" } },\r\n \"target\": { \"$ref\": \"#/definitions/ContentAddress\" }\r\n }\r\n }\r\n },\r\n \"properties\": {\r\n \"schema_version\": { \"type\": \"string\", \"pattern\": \"^1\\\\.\\\\d+$\" },\r\n \"id\": { \"type\": \"string\", \"minLength\": 3, \"maxLength\": 512 },\r\n \"tenant_id\": { \"type\": \"string\", \"description\": \"Reserved for multi-tenancy (SEC-12). Unused in v1.\" },\r\n \"source\": {\r\n \"title\": \"RecordSource\",\r\n \"type\": \"object\",\r\n \"required\": [\"id\", \"provider\"],\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"id\": { \"type\": \"string\", \"pattern\": \"^[a-z0-9_-]{1,64}$\" },\r\n \"provider\": { \"type\": \"string\", \"enum\": [\"openrouter\", \"cloudflare_ai_gateway\", \"aws_bedrock\", \"custom\"] },\r\n \"scope\": { \"type\": \"string\" }\r\n }\r\n },\r\n \"provider_record_id\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 440 },\r\n \"started_at\": { \"$ref\": \"#/definitions/Timestamp\" },\r\n \"ended_at\": { \"$ref\": \"#/definitions/Timestamp\" },\r\n \"received_at\": { \"$ref\": \"#/definitions/Timestamp\" },\r\n \"ingested_at\": { \"$ref\": \"#/definitions/Timestamp\" },\r\n \"operation\": { \"type\": \"string\", \"enum\": [\"chat\", \"completion\", \"embedding\", \"image\", \"other\"] },\r\n \"model\": {\r\n \"title\": \"RecordModel\",\r\n \"type\": \"object\",\r\n \"required\": [\"raw\"],\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"raw\": { \"type\": \"string\" },\r\n \"canonical\": { \"type\": \"string\" },\r\n \"upstream_provider\": { \"type\": \"string\" }\r\n }\r\n },\r\n \"request\": {\r\n \"title\": \"RecordRequest\",\r\n \"type\": \"object\",\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"messages\": { \"type\": \"array\", \"items\": { \"$ref\": \"#/definitions/Message\" } },\r\n \"raw\": { \"description\": \"Provider request value, kept so the original format can be shown. Redacted with the messages.\", \"tsType\": \"unknown\" },\r\n \"params\": {\r\n \"title\": \"RequestParams\",\r\n \"type\": \"object\",\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"temperature\": { \"type\": \"number\" },\r\n \"top_p\": { \"type\": \"number\" },\r\n \"max_tokens\": { \"type\": \"number\" },\r\n \"stream\": { \"type\": \"boolean\" },\r\n \"tools\": { \"type\": \"array\" },\r\n \"extra\": { \"type\": \"object\" }\r\n }\r\n }\r\n }\r\n },\r\n \"response\": {\r\n \"title\": \"RecordResponse\",\r\n \"type\": \"object\",\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"messages\": { \"type\": \"array\", \"items\": { \"$ref\": \"#/definitions/Message\" } },\r\n \"raw\": { \"description\": \"Provider response value, kept so the original format can be shown. Redacted with the messages.\", \"tsType\": \"unknown\" },\r\n \"finish_reason\": { \"type\": \"string\" }\r\n }\r\n },\r\n \"status\": { \"type\": \"string\", \"enum\": [\"ok\", \"error\", \"cached\", \"filtered\"] },\r\n \"error\": {\r\n \"title\": \"RecordError\",\r\n \"type\": \"object\",\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"code\": { \"type\": \"string\" },\r\n \"message\": { \"type\": \"string\" },\r\n \"http_status\": { \"type\": \"number\" }\r\n }\r\n },\r\n \"usage\": {\r\n \"title\": \"RecordUsage\",\r\n \"type\": \"object\",\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"input_tokens\": { \"type\": \"number\" },\r\n \"output_tokens\": { \"type\": \"number\" },\r\n \"total_tokens\": { \"type\": \"number\" },\r\n \"cached_tokens\": { \"type\": \"number\" },\r\n \"reasoning_tokens\": { \"type\": \"number\" }\r\n }\r\n },\r\n \"cost\": {\r\n \"title\": \"RecordCost\",\r\n \"type\": \"object\",\r\n \"required\": [\"source\"],\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"amount\": { \"type\": \"number\" },\r\n \"currency\": { \"type\": \"string\" },\r\n \"source\": { \"type\": \"string\", \"enum\": [\"provider\", \"none\"] }\r\n }\r\n },\r\n \"latency_ms\": { \"type\": \"number\" },\r\n \"ttft_ms\": { \"type\": \"number\" },\r\n \"metadata\": {\r\n \"type\": \"object\",\r\n \"maxProperties\": 50,\r\n \"propertyNames\": { \"pattern\": \"^[A-Za-z0-9_.-]{1,64}$\" },\r\n \"additionalProperties\": { \"$ref\": \"#/definitions/MetadataValue\" }\r\n },\r\n \"execution\": { \"$ref\": \"#/definitions/Execution\" },\r\n \"tags\": { \"type\": \"array\", \"items\": { \"type\": \"string\" } },\r\n \"provider_metadata\": { \"type\": \"object\", \"additionalProperties\": true },\r\n \"request_hash\": { \"type\": \"string\", \"description\": \"Hash of request messages after redaction. Absent when content is not stored (REC-8).\" },\r\n \"system_hash\": { \"type\": \"string\", \"description\": \"Hash of system messages alone, after redaction (REC-8).\" },\r\n \"response_hash\": { \"type\": \"string\", \"description\": \"Hash of response messages after redaction. Absent when content is not stored (REC-8).\" },\r\n \"content_state\": { \"type\": \"string\", \"enum\": [\"full\", \"redacted\", \"truncated\", \"absent\"] },\r\n \"content_omitted_reason\": {\r\n \"type\": \"string\",\r\n \"enum\": [\"store_content_off\", \"provider\", \"retention\", \"scope\", \"not_requested\", \"body_unavailable\"]\r\n },\r\n \"redaction\": {\r\n \"title\": \"RecordRedaction\",\r\n \"type\": \"object\",\r\n \"additionalProperties\": true,\r\n \"properties\": {\r\n \"policy\": { \"type\": \"string\" },\r\n \"version\": { \"type\": \"number\" }\r\n }\r\n },\r\n \"raw\": { \"description\": \"Original provider payload, kept only when enabled for the source\" }\r\n }\r\n}\r\n","import type { ContentAddress, Execution, ExecutionPiece } from './types.gen.js';\r\n\r\n/** Provider metadata attribute that carries an execution block as a JSON string or object. */\r\nexport const EXECUTION_METADATA_KEY = 'xtivix.execution';\r\n\r\nexport interface ExecutionNormalization {\r\n ok: true;\r\n execution: Execution;\r\n}\r\n\r\nexport interface ExecutionNormalizationError {\r\n ok: false;\r\n error: string;\r\n}\r\n\r\n/**\r\n * Accepts the stored snake_case shape or the memorix camelCase shape, including a JSON string.\r\n * Extra keys are dropped. A present value that is not a complete address is an error.\r\n */\r\nexport function normalizeExecution(input: unknown): ExecutionNormalization | ExecutionNormalizationError {\r\n let value = input;\r\n if (typeof value === 'string') {\r\n try {\r\n value = JSON.parse(value) as unknown;\r\n } catch {\r\n return { ok: false, error: 'xtivix.execution is not valid JSON' };\r\n }\r\n }\r\n if (!isObject(value)) return { ok: false, error: 'execution must be an object' };\r\n\r\n const org_id = name(pick(value, 'org_id', 'orgId'), 128);\r\n const agent_id = name(pick(value, 'agent_id', 'agentId'), 128);\r\n const process_id = name(pick(value, 'process_id', 'processId'), 128);\r\n const skill = name(value.skill, 128);\r\n if (!org_id || !agent_id || !process_id || !skill) {\r\n return { ok: false, error: 'execution requires org_id, agent_id, process_id and skill' };\r\n }\r\n const runRaw = pick(value, 'run_id', 'runId');\r\n const run_id = runRaw === undefined ? undefined : name(runRaw, 256);\r\n if (runRaw !== undefined && !run_id) return { ok: false, error: 'execution.run_id is invalid' };\r\n\r\n if (!isObject(value.step)) return { ok: false, error: 'execution.step is required' };\r\n const stepId = name(value.step.id ?? pick(value.step, 'step_id', 'stepId'), 128);\r\n if (!stepId) return { ok: false, error: 'execution.step.id is required' };\r\n let pieces: ExecutionPiece[] | undefined;\r\n if (value.step.pieces !== undefined) {\r\n if (!Array.isArray(value.step.pieces) || value.step.pieces.length > 32) {\r\n return { ok: false, error: 'execution.step.pieces must be an array of at most 32' };\r\n }\r\n pieces = [];\r\n for (const item of value.step.pieces) {\r\n const one = piece(item);\r\n if (!one) return { ok: false, error: 'each step piece needs a content_type' };\r\n pieces.push(one);\r\n }\r\n }\r\n\r\n if (!Array.isArray(value.sources) || value.sources.length < 1 || value.sources.length > 32) {\r\n return { ok: false, error: 'execution.sources must contain 1 to 32 addresses' };\r\n }\r\n const sources: ContentAddress[] = [];\r\n for (const item of value.sources) {\r\n const address = contentAddress(item);\r\n if (!address) return { ok: false, error: 'each source needs object_type, content_type and record_id' };\r\n sources.push(address);\r\n }\r\n const target = contentAddress(value.target);\r\n if (!target) return { ok: false, error: 'execution.target needs object_type, content_type and record_id' };\r\n\r\n const execution: Execution = {\r\n org_id,\r\n agent_id,\r\n process_id,\r\n skill,\r\n step: pieces ? { id: stepId, pieces } : { id: stepId },\r\n sources: sources as Execution['sources'],\r\n target,\r\n };\r\n if (run_id) execution.run_id = run_id;\r\n return { ok: true, execution };\r\n}\r\n\r\n/** Removes `xtivix.execution` from a metadata bag so it is not flattened into scalar keys. */\r\nexport function takeExecutionValue(bag: Record<string, unknown>): unknown | undefined {\r\n if (!Object.prototype.hasOwnProperty.call(bag, EXECUTION_METADATA_KEY)) return undefined;\r\n const value = bag[EXECUTION_METADATA_KEY];\r\n delete bag[EXECUTION_METADATA_KEY];\r\n return value;\r\n}\r\n\r\nfunction contentAddress(input: unknown): ContentAddress | undefined {\r\n if (!isObject(input)) return undefined;\r\n const object_type = name(pick(input, 'object_type', 'objectType'), 128);\r\n const content_type = name(pick(input, 'content_type', 'contentType'), 128);\r\n const record_id = name(pick(input, 'record_id', 'recordId'), 256);\r\n if (!object_type || !content_type || !record_id) return undefined;\r\n return { object_type, content_type, record_id };\r\n}\r\n\r\nfunction piece(input: unknown): ExecutionPiece | undefined {\r\n if (!isObject(input)) return undefined;\r\n const content_type = name(pick(input, 'content_type', 'contentType'), 128);\r\n if (!content_type) return undefined;\r\n const object_type = name(pick(input, 'object_type', 'objectType'), 128);\r\n const record_id = name(pick(input, 'record_id', 'recordId'), 256);\r\n const label = name(input.label, 128);\r\n const out: ExecutionPiece = { content_type };\r\n if (object_type) out.object_type = object_type;\r\n if (record_id) out.record_id = record_id;\r\n if (label) out.label = label;\r\n return out;\r\n}\r\n\r\nfunction pick(obj: Record<string, unknown>, snake: string, camel: string): unknown {\r\n return obj[snake] ?? obj[camel];\r\n}\r\n\r\nfunction name(value: unknown, max: number): string | undefined {\r\n if (typeof value !== 'string') return undefined;\r\n const s = value.trim();\r\n if (!s || s.length > max || /\\s/.test(s) || /[\\u0000-\\u001f\\u007f]/.test(s)) return undefined;\r\n return s;\r\n}\r\n\r\nfunction isObject(value: unknown): value is Record<string, unknown> {\r\n return !!value && typeof value === 'object' && !Array.isArray(value);\r\n}\r\n"],"mappings":";AAAA,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,OAAO,UAAU;AACjB,OAAO,eAA4D;AACnE,SAAS,SAAS,iBAAiB;;;ACJnC;AAAA,EACE,SAAW;AAAA,EACX,KAAO;AAAA,EACP,OAAS;AAAA,EACT,aAAe;AAAA,EACf,MAAQ;AAAA,EACR,UAAY,CAAC,kBAAkB,MAAM,UAAU,sBAAsB,cAAc,aAAa,SAAS,UAAU,YAAY,eAAe;AAAA,EAC9I,sBAAwB;AAAA,EACxB,aAAe;AAAA,IACb,WAAa;AAAA,MACX,MAAQ;AAAA,MACR,SAAW;AAAA,IACb;AAAA,IACA,MAAQ;AAAA,MACN,OAAS;AAAA,MACT,MAAQ;AAAA,MACR,UAAY,CAAC,MAAM;AAAA,MACnB,sBAAwB;AAAA,MACxB,YAAc;AAAA,QACZ,MAAQ,EAAE,MAAQ,UAAU,MAAQ,CAAC,QAAQ,aAAa,eAAe,WAAW,EAAE;AAAA,QACtF,MAAQ,EAAE,MAAQ,SAAS;AAAA,QAC3B,cAAgB,EAAE,MAAQ,SAAS;AAAA,QACnC,MAAQ,EAAE,MAAQ,SAAS;AAAA,QAC3B,WAAa,EAAE,MAAQ,UAAU,aAAe,uCAAuC;AAAA,QACvF,SAAW,EAAE,MAAQ,UAAU,aAAe,sBAAsB;AAAA,QACpE,UAAY,EAAE,MAAQ,UAAU;AAAA,QAChC,YAAc,EAAE,MAAQ,UAAU,MAAQ,CAAC,SAAS,SAAS,SAAS,QAAQ,OAAO,EAAE;AAAA,QACvF,WAAa,EAAE,MAAQ,SAAS;AAAA,QAChC,YAAc,EAAE,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AAS;AACtC,UAAM,MAAM,MAAM,IAAI,OAAO;AAC7B,QAAI,IAAK,QAAO;AAChB,QAAI;AACJ,QAAI,UAAU;AACd,eAAW,QAAQ,OAAO;AACxB,UAAI,KAAK,GAAG,KAAK,OAAO,GAAG;AACzB,oBAAY,QAAQ,QAAQ,KAAK,IAAI,KAAK,OAAO;AACjD,kBAAU,KAAK;AACf;AAAA,MACF;AAAA,IACF;AACA,QAAI,cAAc,OAAW,QAAO;AACpC,QAAI,CAAC,QAAS,QAAO,MAAM,IAAI,SAAS,KAAK;AAC7C,cAAU;AAAA,EACZ;AACA,SAAO;AACT;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x12i/xtivix-schema",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Canonical AI call record schema (JSON Schema v1.0), TypeScript types, metadata rules and model aliases for xtivix",
5
5
  "keywords": [
6
6
  "xtivix",