@ai-matrx/content-ir 0.19.21 → 0.19.26

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/index.cjs CHANGED
@@ -2128,7 +2128,7 @@ function stripKindDeep(value) {
2128
2128
  return value;
2129
2129
  }
2130
2130
 
2131
- // utils/text-case-converter.ts
2131
+ // text-case.ts
2132
2132
  var DEFAULT_WORD_REPLACEMENTS = {
2133
2133
  // Acronyms & initialisms
2134
2134
  "api": "API",
@@ -2396,6 +2396,24 @@ function formatText(text, options = {}) {
2396
2396
  }
2397
2397
  return result;
2398
2398
  }
2399
+ var IDENTIFIER_ACRONYMS = [
2400
+ "ID",
2401
+ "URL",
2402
+ "PDF",
2403
+ "HTML",
2404
+ "JSON",
2405
+ "API",
2406
+ "AI",
2407
+ "UI",
2408
+ "CSV",
2409
+ "SMS",
2410
+ "SEO",
2411
+ "LLM",
2412
+ "MCP",
2413
+ "UUID",
2414
+ "ISO"
2415
+ ];
2416
+ new Set(IDENTIFIER_ACRONYMS.map((a) => a.toLowerCase()));
2399
2417
 
2400
2418
  // core/schema-structure.ts
2401
2419
  function formatBlockLabel(key) {
@@ -3188,13 +3206,13 @@ function makeKindJsonSchemaProperty(kindSlug, strict) {
3188
3206
  return { ...base2, enum: [kindSlug] };
3189
3207
  }
3190
3208
  function injectKindIntoObjectSchema(objectSchema, kindSlug, strict) {
3191
- const clone = deepClone(objectSchema);
3192
- const properties = isRecord4(clone.properties) ? { ...clone.properties } : {};
3209
+ const clone2 = deepClone(objectSchema);
3210
+ const properties = isRecord4(clone2.properties) ? { ...clone2.properties } : {};
3193
3211
  properties[KIND_KEY] = makeKindJsonSchemaProperty(kindSlug, strict);
3194
- const required = Array.isArray(clone.required) ? clone.required.filter((k) => typeof k === "string") : [];
3212
+ const required = Array.isArray(clone2.required) ? clone2.required.filter((k) => typeof k === "string") : [];
3195
3213
  const nextRequired = required.includes(KIND_KEY) ? required : [KIND_KEY, ...required];
3196
3214
  return {
3197
- ...clone,
3215
+ ...clone2,
3198
3216
  properties,
3199
3217
  required: nextRequired,
3200
3218
  ...strict ? { additionalProperties: false } : {}
@@ -4391,8 +4409,132 @@ function kindSchemaToJsonSchema(kind, resolve, options = {}) {
4391
4409
  return { name: kind, schema: { ...rootNode, $defs: defs }, strict, unresolved };
4392
4410
  }
4393
4411
 
4412
+ // convert/control-keys.ts
4413
+ var CONTROL_KEYS = ["_replaces", "_new", "_record_id", "_records"];
4414
+ var RECORD_DISPOSITION = "record";
4415
+ var KIND_KEY2 = "__kind";
4416
+ var DOCUMENT_KEYS = /* @__PURE__ */ new Set(["$schema", "$id", "$defs", "definitions", "title", "description"]);
4417
+ var CONTROL = new Set(CONTROL_KEYS);
4418
+ function controlKeysApplyTo(disposition) {
4419
+ return disposition === RECORD_DISPOSITION;
4420
+ }
4421
+ function clone(value) {
4422
+ return value === void 0 ? value : JSON.parse(JSON.stringify(value));
4423
+ }
4424
+ function isObjectSchema(schema) {
4425
+ if (!schema || typeof schema !== "object" || Array.isArray(schema)) return false;
4426
+ const s = schema;
4427
+ return s.type === "object" && !!s.properties && typeof s.properties === "object" && !Array.isArray(s.properties);
4428
+ }
4429
+ function requiredOf(schema) {
4430
+ return Array.isArray(schema.required) ? schema.required : [];
4431
+ }
4432
+ function recordObject(schema) {
4433
+ const item = {};
4434
+ for (const [k, v] of Object.entries(schema)) {
4435
+ if (!DOCUMENT_KEYS.has(k)) item[k] = clone(v);
4436
+ }
4437
+ const props = {};
4438
+ for (const [k, v] of Object.entries(item.properties)) {
4439
+ if (k !== KIND_KEY2 && !CONTROL.has(k)) props[k] = v;
4440
+ }
4441
+ item.properties = props;
4442
+ const required = requiredOf(item).filter((k) => k !== KIND_KEY2 && !CONTROL.has(k));
4443
+ if (required.length > 0) item.required = required;
4444
+ else delete item.required;
4445
+ return item;
4446
+ }
4447
+ function stored(schema) {
4448
+ const out = clone(schema);
4449
+ const item = recordObject(schema);
4450
+ const props = out.properties;
4451
+ props._replaces = { type: ["string", "null"], format: "uuid" };
4452
+ props._new = { type: ["boolean", "null"] };
4453
+ props._record_id = { type: ["string", "null"], format: "uuid" };
4454
+ props._records = { type: ["array", "null"], items: item };
4455
+ const rootRequired = requiredOf(out).filter((k) => !CONTROL.has(k));
4456
+ const lifted = rootRequired.filter((k) => k !== KIND_KEY2);
4457
+ if (lifted.length > 0) {
4458
+ const kept = rootRequired.filter((k) => k === KIND_KEY2);
4459
+ if (kept.length > 0) out.required = kept;
4460
+ else delete out.required;
4461
+ const branch = {
4462
+ if: {
4463
+ anyOf: [
4464
+ { required: ["_record_id"], properties: { _record_id: { type: "string" } } },
4465
+ { required: ["_records"], properties: { _records: { type: "array" } } }
4466
+ ]
4467
+ },
4468
+ else: { required: lifted }
4469
+ };
4470
+ out.allOf = Array.isArray(out.allOf) ? [...out.allOf, branch] : [branch];
4471
+ }
4472
+ return out;
4473
+ }
4474
+ function authored(schema, many, allowEdit) {
4475
+ const signals = {
4476
+ _replaces: { type: "string", format: "uuid" },
4477
+ _new: { type: "boolean" }
4478
+ };
4479
+ if (allowEdit) signals._record_id = { type: "string", format: "uuid" };
4480
+ if (!many) {
4481
+ const out2 = clone(schema);
4482
+ Object.assign(out2.properties, clone(signals));
4483
+ const required = requiredOf(out2).filter((k) => !CONTROL.has(k));
4484
+ if (required.length > 0 || "required" in out2) out2.required = required;
4485
+ return out2;
4486
+ }
4487
+ const out = {};
4488
+ for (const [k, v] of Object.entries(schema)) {
4489
+ if (DOCUMENT_KEYS.has(k)) out[k] = clone(v);
4490
+ }
4491
+ out.type = "object";
4492
+ const kindProp = schema.properties[KIND_KEY2];
4493
+ const properties = {};
4494
+ if (kindProp !== void 0) properties[KIND_KEY2] = clone(kindProp);
4495
+ properties._records = { type: "array", items: recordObject(schema) };
4496
+ Object.assign(properties, clone(signals));
4497
+ out.properties = properties;
4498
+ out.required = [KIND_KEY2, "_records"].filter((k) => k in properties);
4499
+ out.additionalProperties = false;
4500
+ return out;
4501
+ }
4502
+ function withControlKeys(schema, options) {
4503
+ const { mode, many = false, allowEdit = false } = options;
4504
+ if (mode !== "stored" && mode !== "authored") {
4505
+ throw new Error(`withControlKeys: mode must be "stored" or "authored", got ${String(mode)}`);
4506
+ }
4507
+ if (!isObjectSchema(schema)) return schema;
4508
+ return mode === "stored" ? stored(schema) : authored(schema, many, allowEdit);
4509
+ }
4510
+ var CONTROL_KEY_FIELDS = Object.freeze({
4511
+ _replaces: { type: "string", nullable: true },
4512
+ _new: { type: "boolean", nullable: true },
4513
+ _record_id: { type: "string", nullable: true },
4514
+ // A batch's items are records of this kind WITHOUT `__kind`; the render layer reads them
4515
+ // as opaque JSON (never stricter than the store, which validates each item).
4516
+ _records: { type: "json[]", nullable: true }
4517
+ });
4518
+ function withControlKeyFields(schema) {
4519
+ if (schema.root) return schema;
4520
+ const fields = { ...schema.fields };
4521
+ for (const key of CONTROL_KEYS) {
4522
+ if (!(key in fields)) fields[key] = { ...CONTROL_KEY_FIELDS[key] };
4523
+ }
4524
+ return { ...schema, fields };
4525
+ }
4526
+ function stripControlKeys(value) {
4527
+ const values = {};
4528
+ const signals = {};
4529
+ for (const [k, v] of Object.entries(value)) {
4530
+ if (CONTROL.has(k)) signals[k] = v;
4531
+ else values[k] = v;
4532
+ }
4533
+ return { values, signals };
4534
+ }
4535
+
4394
4536
  // convert/json-schema-to-kind.ts
4395
- function kindSchemaFromJsonSchema(kind, jsonSchema) {
4537
+ function kindSchemaFromJsonSchema(kind, jsonSchema, options = {}) {
4396
4538
  if (jsonSchema === null || jsonSchema === void 0) {
4397
4539
  return { schema: null, children: {}, problems: [] };
4398
4540
  }
@@ -4423,6 +4565,9 @@ function kindSchemaFromJsonSchema(kind, jsonSchema) {
4423
4565
  if (draft.slug === kind) schema = asKindSchema;
4424
4566
  else children[draft.slug] = asKindSchema;
4425
4567
  }
4568
+ if (schema && controlKeysApplyTo(options.disposition)) {
4569
+ schema = withControlKeyFields(schema);
4570
+ }
4426
4571
  return { schema, children, problems: converted.problems };
4427
4572
  }
4428
4573
 
@@ -7933,6 +8078,8 @@ exports.BacktickRuns = BacktickRuns;
7933
8078
  exports.CALLOUT_NAMES = CALLOUT_NAMES;
7934
8079
  exports.CAPABILITY_BY_CLASS = CAPABILITY_BY_CLASS;
7935
8080
  exports.CLASSES = CLASSES;
8081
+ exports.CONTROL_KEYS = CONTROL_KEYS;
8082
+ exports.CONTROL_KEY_FIELDS = CONTROL_KEY_FIELDS;
7936
8083
  exports.DIRECTIVE_VERSION = DIRECTIVE_VERSION;
7937
8084
  exports.DirectiveDecodeError = DirectiveDecodeError;
7938
8085
  exports.FENCE_OPENER_WHITESPACE = FENCE_OPENER_WHITESPACE;
@@ -7952,6 +8099,7 @@ exports.KindStreamParser = KindStreamParser;
7952
8099
  exports.NESTING_FENCE_LANGUAGES = NESTING_FENCE_LANGUAGES;
7953
8100
  exports.NODE_OUTCOME_KIND = NODE_OUTCOME_KIND;
7954
8101
  exports.ParseSession = ParseSession;
8102
+ exports.RECORD_DISPOSITION = RECORD_DISPOSITION;
7955
8103
  exports.RESERVED_PREFIX = RESERVED_PREFIX;
7956
8104
  exports.ROOT_STORAGE_NAME = ROOT_STORAGE_NAME;
7957
8105
  exports.RUN_RESULT_KIND = RUN_RESULT_KIND;
@@ -7979,6 +8127,7 @@ exports.collectReferencedKinds = collectReferencedKinds;
7979
8127
  exports.collectSchemaReferencedKinds = collectSchemaReferencedKinds;
7980
8128
  exports.compareWithExistingKindSchema = compareWithExistingKindSchema;
7981
8129
  exports.continuesTable = continuesTable;
8130
+ exports.controlKeysApplyTo = controlKeysApplyTo;
7982
8131
  exports.convertAiSchemaToBlockFields = convertAiSchemaToBlockFields;
7983
8132
  exports.createFingerprinter = createFingerprinter;
7984
8133
  exports.createKindStreamParser = createKindStreamParser;
@@ -8065,6 +8214,7 @@ exports.opensTable = opensTable;
8065
8214
  exports.pairDisplayMath = pairDisplayMath;
8066
8215
  exports.parseDirectiveSlug = parseDirectiveSlug;
8067
8216
  exports.parseFenceOpener = parseFenceOpener;
8217
+ exports.pendingCodeSpanStart = pendingCodeSpanStart;
8068
8218
  exports.pendingDisplayMathOpener = pendingDisplayMathOpener;
8069
8219
  exports.readEnvelope = readEnvelope;
8070
8220
  exports.readNodeOutcomeValue = readNodeOutcomeValue;
@@ -8097,6 +8247,7 @@ exports.splitsSurrogatePair = splitsSurrogatePair;
8097
8247
  exports.startsHtmlBlock = startsHtmlBlock;
8098
8248
  exports.startsPipelessTable = startsPipelessTable;
8099
8249
  exports.storageToKindSchema = storageToKindSchema;
8250
+ exports.stripControlKeys = stripControlKeys;
8100
8251
  exports.stripKindDeep = stripKindDeep;
8101
8252
  exports.tableContainerIndent = tableContainerIndent;
8102
8253
  exports.tableStartsAt = tableStartsAt;
@@ -8110,6 +8261,8 @@ exports.tryDecodeDirectiveContent = tryDecodeDirectiveContent;
8110
8261
  exports.unescapeCellPipes = unescapeCellPipes;
8111
8262
  exports.validateBlockSchemaSavePlan = validateBlockSchemaSavePlan;
8112
8263
  exports.validateStructuralLeg = validateStructuralLeg;
8264
+ exports.withControlKeyFields = withControlKeyFields;
8265
+ exports.withControlKeys = withControlKeys;
8113
8266
  exports.withRootKind = withRootKind;
8114
8267
  exports.xmlDiscriminator = xmlDiscriminator;
8115
8268
  //# sourceMappingURL=index.cjs.map