@ai-matrx/content-ir 0.1.2 → 0.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/CHANGELOG.md +16 -0
- package/README.md +6 -0
- package/dist/index.cjs +300 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +324 -1
- package/dist/index.d.ts +324 -1
- package/dist/index.js +283 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4111,6 +4111,288 @@ function kindSchemaToJsonSchema(kind, resolve, options = {}) {
|
|
|
4111
4111
|
return { name: kind, schema: { ...rootNode, $defs: defs }, strict, unresolved };
|
|
4112
4112
|
}
|
|
4113
4113
|
|
|
4114
|
-
|
|
4114
|
+
// wire/partial-kind.ts
|
|
4115
|
+
var IR_PARTIAL_KEY = "__ir_partial";
|
|
4116
|
+
var PARTIAL_STATES = [
|
|
4117
|
+
"partial",
|
|
4118
|
+
"superseded",
|
|
4119
|
+
"retracted"
|
|
4120
|
+
];
|
|
4121
|
+
function isRecord5(value) {
|
|
4122
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4123
|
+
}
|
|
4124
|
+
function readPath(value) {
|
|
4125
|
+
if (!Array.isArray(value)) return null;
|
|
4126
|
+
return value.every(
|
|
4127
|
+
(segment) => typeof segment === "string" || typeof segment === "number"
|
|
4128
|
+
) ? value : null;
|
|
4129
|
+
}
|
|
4130
|
+
function readDiscriminator(value) {
|
|
4131
|
+
if (!isRecord5(value)) return null;
|
|
4132
|
+
if (value.format === "json" && value.key === "__kind") {
|
|
4133
|
+
return { format: "json", key: "__kind" };
|
|
4134
|
+
}
|
|
4135
|
+
if (value.format === "xml" && typeof value.tag === "string") {
|
|
4136
|
+
return { format: "xml", tag: value.tag };
|
|
4137
|
+
}
|
|
4138
|
+
if (value.format === "fence" && typeof value.language === "string") {
|
|
4139
|
+
return { format: "fence", language: value.language };
|
|
4140
|
+
}
|
|
4141
|
+
return null;
|
|
4142
|
+
}
|
|
4143
|
+
function readResidue(value) {
|
|
4144
|
+
if (value === null) return null;
|
|
4145
|
+
if (!isRecord5(value)) return void 0;
|
|
4146
|
+
const extra = value.extra;
|
|
4147
|
+
const optionalMissing = value.optionalMissing;
|
|
4148
|
+
const notices = value.notices;
|
|
4149
|
+
if (extra !== null && !isRecord5(extra)) return void 0;
|
|
4150
|
+
if (optionalMissing !== null && (!Array.isArray(optionalMissing) || !optionalMissing.every((item) => typeof item === "string"))) {
|
|
4151
|
+
return void 0;
|
|
4152
|
+
}
|
|
4153
|
+
if (notices !== null && (!Array.isArray(notices) || !notices.every(
|
|
4154
|
+
(notice) => isRecord5(notice) && typeof notice.code === "string" && typeof notice.message === "string" && (notice.at === void 0 || typeof notice.at === "number")
|
|
4155
|
+
))) {
|
|
4156
|
+
return void 0;
|
|
4157
|
+
}
|
|
4158
|
+
return { extra, optionalMissing, notices };
|
|
4159
|
+
}
|
|
4160
|
+
function readPartialKindEvent(metadata) {
|
|
4161
|
+
if (!isRecord5(metadata)) return null;
|
|
4162
|
+
const candidate = metadata[IR_PARTIAL_KEY];
|
|
4163
|
+
if (!isRecord5(candidate)) return null;
|
|
4164
|
+
if (candidate.v !== IR_VERSION) return null;
|
|
4165
|
+
if (typeof candidate.engine !== "string") return null;
|
|
4166
|
+
if (typeof candidate.seq !== "number" || !Number.isFinite(candidate.seq)) {
|
|
4167
|
+
return null;
|
|
4168
|
+
}
|
|
4169
|
+
const state = candidate.state;
|
|
4170
|
+
if (typeof state !== "string") return null;
|
|
4171
|
+
if (!PARTIAL_STATES.includes(state)) return null;
|
|
4172
|
+
if (state === "partial") {
|
|
4173
|
+
const root = candidate.root;
|
|
4174
|
+
if (!isRecord5(root)) return null;
|
|
4175
|
+
if (root.role !== "structured") return null;
|
|
4176
|
+
if (root.status !== "streaming") return null;
|
|
4177
|
+
if (root.kindState !== "speculative") return null;
|
|
4178
|
+
if (typeof root.kind !== "string" || !root.kind) return null;
|
|
4179
|
+
if (!isRecord5(root.value)) return null;
|
|
4180
|
+
const discriminator = readDiscriminator(root.discriminator);
|
|
4181
|
+
const path = readPath(root.path);
|
|
4182
|
+
const residue = readResidue(root.residue);
|
|
4183
|
+
if (discriminator === null || path === null || residue === void 0) {
|
|
4184
|
+
return null;
|
|
4185
|
+
}
|
|
4186
|
+
return {
|
|
4187
|
+
v: IR_VERSION,
|
|
4188
|
+
engine: candidate.engine,
|
|
4189
|
+
state: "partial",
|
|
4190
|
+
seq: candidate.seq,
|
|
4191
|
+
fingerprint: typeof candidate.fingerprint === "string" ? candidate.fingerprint : "",
|
|
4192
|
+
root: {
|
|
4193
|
+
role: "structured",
|
|
4194
|
+
kind: root.kind,
|
|
4195
|
+
kindState: "speculative",
|
|
4196
|
+
discriminator,
|
|
4197
|
+
path,
|
|
4198
|
+
status: "streaming",
|
|
4199
|
+
value: root.value,
|
|
4200
|
+
residue
|
|
4201
|
+
}
|
|
4202
|
+
};
|
|
4203
|
+
}
|
|
4204
|
+
if (typeof candidate.kind !== "string" || !candidate.kind) return null;
|
|
4205
|
+
if (state === "superseded") {
|
|
4206
|
+
return {
|
|
4207
|
+
v: IR_VERSION,
|
|
4208
|
+
engine: candidate.engine,
|
|
4209
|
+
state: "superseded",
|
|
4210
|
+
seq: candidate.seq,
|
|
4211
|
+
kind: candidate.kind
|
|
4212
|
+
};
|
|
4213
|
+
}
|
|
4214
|
+
if (typeof candidate.reason !== "string" || !candidate.reason) return null;
|
|
4215
|
+
if (candidate.becameKind !== null && typeof candidate.becameKind !== "string") {
|
|
4216
|
+
return null;
|
|
4217
|
+
}
|
|
4218
|
+
if (candidate.becameBlockType !== null && typeof candidate.becameBlockType !== "string") {
|
|
4219
|
+
return null;
|
|
4220
|
+
}
|
|
4221
|
+
return {
|
|
4222
|
+
v: IR_VERSION,
|
|
4223
|
+
engine: candidate.engine,
|
|
4224
|
+
state: "retracted",
|
|
4225
|
+
seq: candidate.seq,
|
|
4226
|
+
kind: candidate.kind,
|
|
4227
|
+
reason: candidate.reason,
|
|
4228
|
+
becameKind: candidate.becameKind,
|
|
4229
|
+
becameBlockType: candidate.becameBlockType
|
|
4230
|
+
};
|
|
4231
|
+
}
|
|
4232
|
+
function sanitizeInboundPartialKindMetadata(metadata, context, hooks = {}) {
|
|
4233
|
+
if (!isRecord5(metadata) || !(IR_PARTIAL_KEY in metadata)) {
|
|
4234
|
+
return metadata ?? void 0;
|
|
4235
|
+
}
|
|
4236
|
+
if (readPartialKindEvent(metadata) !== null) return metadata;
|
|
4237
|
+
const { [IR_PARTIAL_KEY]: raw, ...rest } = metadata;
|
|
4238
|
+
hooks.reportMalformed?.({ blockId: context.blockId, raw });
|
|
4239
|
+
return rest;
|
|
4240
|
+
}
|
|
4241
|
+
function isProvisionalKind(event) {
|
|
4242
|
+
return event !== null && event.state === "partial";
|
|
4243
|
+
}
|
|
4244
|
+
function isTerminalKindEvent(event) {
|
|
4245
|
+
return event !== null && (event.state === "superseded" || event.state === "retracted");
|
|
4246
|
+
}
|
|
4247
|
+
function advancePartialKind(seen, blockId, event) {
|
|
4248
|
+
if (event === null) return null;
|
|
4249
|
+
const last = seen[blockId];
|
|
4250
|
+
if (last !== void 0 && event.seq <= last) return null;
|
|
4251
|
+
return event;
|
|
4252
|
+
}
|
|
4253
|
+
function makePartialKindStalenessGate() {
|
|
4254
|
+
const seen = {};
|
|
4255
|
+
const lastAccepted = {};
|
|
4256
|
+
const terminated = {};
|
|
4257
|
+
return (blockId, metadata) => {
|
|
4258
|
+
if (!isRecord5(metadata)) return metadata;
|
|
4259
|
+
if (!(IR_PARTIAL_KEY in metadata)) {
|
|
4260
|
+
const open = lastAccepted[blockId];
|
|
4261
|
+
if (terminated[blockId] || open === void 0) return metadata;
|
|
4262
|
+
return { ...metadata, [IR_PARTIAL_KEY]: open };
|
|
4263
|
+
}
|
|
4264
|
+
const parsed = readPartialKindEvent(metadata);
|
|
4265
|
+
if (parsed === null) return metadata;
|
|
4266
|
+
if (advancePartialKind(seen, blockId, parsed) !== null) {
|
|
4267
|
+
seen[blockId] = parsed.seq;
|
|
4268
|
+
lastAccepted[blockId] = metadata[IR_PARTIAL_KEY];
|
|
4269
|
+
if (isTerminalKindEvent(parsed)) terminated[blockId] = true;
|
|
4270
|
+
return metadata;
|
|
4271
|
+
}
|
|
4272
|
+
const carried = lastAccepted[blockId];
|
|
4273
|
+
if (carried === void 0 || carried === metadata[IR_PARTIAL_KEY]) {
|
|
4274
|
+
return metadata;
|
|
4275
|
+
}
|
|
4276
|
+
return { ...metadata, [IR_PARTIAL_KEY]: carried };
|
|
4277
|
+
};
|
|
4278
|
+
}
|
|
4279
|
+
|
|
4280
|
+
// wire/runtime-wrapper.ts
|
|
4281
|
+
var NODE_OUTCOME_KIND = "node_outcome";
|
|
4282
|
+
var RUN_RESULT_KIND = "run_result";
|
|
4283
|
+
function isRecord6(value) {
|
|
4284
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4285
|
+
}
|
|
4286
|
+
function str(source, key) {
|
|
4287
|
+
const value = source[key];
|
|
4288
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
4289
|
+
}
|
|
4290
|
+
function num(source, key) {
|
|
4291
|
+
const value = source[key];
|
|
4292
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
4293
|
+
}
|
|
4294
|
+
function bool(source, key) {
|
|
4295
|
+
const value = source[key];
|
|
4296
|
+
return typeof value === "boolean" ? value : null;
|
|
4297
|
+
}
|
|
4298
|
+
function strings(source, key) {
|
|
4299
|
+
const value = source[key];
|
|
4300
|
+
if (!Array.isArray(value)) return null;
|
|
4301
|
+
const out = value.filter((item) => typeof item === "string");
|
|
4302
|
+
return out.length > 0 ? out : null;
|
|
4303
|
+
}
|
|
4304
|
+
function readOutputRef(frame, ref) {
|
|
4305
|
+
let cursor = frame;
|
|
4306
|
+
for (const segment of ref.split(".")) {
|
|
4307
|
+
if (!isRecord6(cursor)) return void 0;
|
|
4308
|
+
if (!(segment in cursor)) return void 0;
|
|
4309
|
+
cursor = cursor[segment];
|
|
4310
|
+
}
|
|
4311
|
+
return cursor;
|
|
4312
|
+
}
|
|
4313
|
+
function rehydrateNodeOutcome(raw, frame) {
|
|
4314
|
+
if (!isRecord6(raw)) return null;
|
|
4315
|
+
if (raw[KIND_KEY] !== NODE_OUTCOME_KIND) return null;
|
|
4316
|
+
const ref = str(raw, "output_ref");
|
|
4317
|
+
const resolved = ref === null ? void 0 : readOutputRef(frame, ref);
|
|
4318
|
+
return readNodeOutcomeValue(
|
|
4319
|
+
resolved === void 0 ? raw : { ...raw, output: resolved }
|
|
4320
|
+
);
|
|
4321
|
+
}
|
|
4322
|
+
function readNodeOutcomeValue(raw) {
|
|
4323
|
+
if (!isRecord6(raw)) return null;
|
|
4324
|
+
const runId = str(raw, "run_id");
|
|
4325
|
+
const nodeId = str(raw, "node_id");
|
|
4326
|
+
if (!runId || !nodeId) return null;
|
|
4327
|
+
const output = raw.output ?? null;
|
|
4328
|
+
return {
|
|
4329
|
+
__kind: NODE_OUTCOME_KIND,
|
|
4330
|
+
run_id: runId,
|
|
4331
|
+
node_id: nodeId,
|
|
4332
|
+
workflow_id: str(raw, "workflow_id"),
|
|
4333
|
+
step: num(raw, "step"),
|
|
4334
|
+
attempt: num(raw, "attempt") ?? 1,
|
|
4335
|
+
status: str(raw, "status") ?? "completed",
|
|
4336
|
+
started_at: str(raw, "started_at"),
|
|
4337
|
+
ended_at: str(raw, "ended_at"),
|
|
4338
|
+
duration_ms: num(raw, "duration_ms"),
|
|
4339
|
+
output_kind: str(raw, "output_kind"),
|
|
4340
|
+
output_kind_ok: bool(raw, "output_kind_ok"),
|
|
4341
|
+
output_kind_errors: strings(raw, "output_kind_errors"),
|
|
4342
|
+
output
|
|
4343
|
+
};
|
|
4344
|
+
}
|
|
4345
|
+
function rehydrateRunResult(raw, frame) {
|
|
4346
|
+
if (!isRecord6(raw)) return null;
|
|
4347
|
+
if (raw[KIND_KEY] !== RUN_RESULT_KIND) return null;
|
|
4348
|
+
const ref = str(raw, "output_ref");
|
|
4349
|
+
const resolved = ref === null ? void 0 : readOutputRef(frame, ref);
|
|
4350
|
+
const outputs = Array.isArray(raw.outputs) ? raw.outputs.map((child) => rehydrateNodeOutcome(child, frame) ?? child) : [];
|
|
4351
|
+
return readRunResultValue({
|
|
4352
|
+
...raw,
|
|
4353
|
+
...resolved === void 0 ? {} : { output: resolved },
|
|
4354
|
+
outputs
|
|
4355
|
+
});
|
|
4356
|
+
}
|
|
4357
|
+
function readRunResultValue(raw) {
|
|
4358
|
+
if (!isRecord6(raw)) return null;
|
|
4359
|
+
const runId = str(raw, "run_id");
|
|
4360
|
+
if (!runId) return null;
|
|
4361
|
+
const output = raw.output ?? null;
|
|
4362
|
+
const outputs = Array.isArray(raw.outputs) ? raw.outputs.map((child) => readNodeOutcomeValue(child)).filter((child) => child !== null) : [];
|
|
4363
|
+
return {
|
|
4364
|
+
__kind: RUN_RESULT_KIND,
|
|
4365
|
+
run_id: runId,
|
|
4366
|
+
workflow_id: str(raw, "workflow_id"),
|
|
4367
|
+
status: str(raw, "status") ?? "completed",
|
|
4368
|
+
started_at: str(raw, "started_at"),
|
|
4369
|
+
ended_at: str(raw, "ended_at"),
|
|
4370
|
+
duration_ms: num(raw, "duration_ms"),
|
|
4371
|
+
output_kind: str(raw, "output_kind"),
|
|
4372
|
+
output,
|
|
4373
|
+
outputs
|
|
4374
|
+
};
|
|
4375
|
+
}
|
|
4376
|
+
function kindVerdictOf(wrapper) {
|
|
4377
|
+
if (wrapper.output_kind_ok === true) return "passed";
|
|
4378
|
+
if (wrapper.output_kind_ok === false) return "failed";
|
|
4379
|
+
return "unchecked";
|
|
4380
|
+
}
|
|
4381
|
+
|
|
4382
|
+
// wire/emit-payload.ts
|
|
4383
|
+
function withRootKind(kind, value) {
|
|
4384
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
4385
|
+
return { [KIND_KEY]: kind, ...value };
|
|
4386
|
+
}
|
|
4387
|
+
return value;
|
|
4388
|
+
}
|
|
4389
|
+
function emitPayloadJson(kind, value) {
|
|
4390
|
+
return JSON.stringify(withRootKind(kind, value), null, 2);
|
|
4391
|
+
}
|
|
4392
|
+
function emitPayloadFence(kind, value) {
|
|
4393
|
+
return "```json\n" + emitPayloadJson(kind, value) + "\n```";
|
|
4394
|
+
}
|
|
4395
|
+
|
|
4396
|
+
export { IR_ENVELOPE_CACHE_VERSION, IR_ENVELOPE_KEY, IR_PARTIAL_KEY, IR_VERSION, IrTree, JSON_DISCRIMINATOR, JsonStreamTokenizer, KIND_KEY, KindStorageError, KindStreamParser, NODE_OUTCOME_KIND, ParseSession, ROOT_STORAGE_NAME, RUN_RESULT_KIND, advancePartialKind, buildAgentSchemaWithRenderBlockSupport, buildCompliantKindSnapshot, classifyInboundEnvelopeMetadata, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, convertAiSchemaToBlockFields, createFingerprinter, createKindStreamParser, describeDualGateFailure, disposeParseSession, emitPayloadFence, emitPayloadJson, emptyValueForFieldSchema, envelopeCacheFromEnvelopes, envelopeFromCompleteValue, fenceDiscriminator, fieldsToDbPayload, fingerprintText, formatBlockLabel, getParseSession, injectKindIntoObjectSchema, irPathIsUnderOrEqual, irPathKey, irPathLabel, irPathsEqual, isCanonicalBlockIR, isDuplicateBlockSlug, isEmptyResidue, isIrEnvelopeCache, isJsonAnyField, isProvisionalKind, isScalarArrayType, isTerminalKindEvent, kindSchemaToJsonSchema, kindSchemaToStorage, kindVerdictOf, makePartialKindStalenessGate, mergeResidueIntoValue, normalizeAiSchemaInput, normalizeJsonRegion, openParseSession, readEnvelope, readNodeOutcomeValue, readObjectKind, readOutputRef, readPartialKindEvent, readRunResultValue, reconstructRegionValue, rehydrateNodeOutcome, rehydrateRunResult, reuseEnvelopeIfCurrent, runKindDualGate, runSchemaConversion, sanitizeInboundEnvelopeMetadata, sanitizeInboundPartialKindMetadata, scalarArrayItemType, schemaLayoutMode, schemaStructureDepth, setJsonRootKeyLookup, storageToKindSchema, stripKindDeep, validateBlockSchemaSavePlan, validateStructuralLeg, withRootKind, xmlDiscriminator };
|
|
4115
4397
|
//# sourceMappingURL=index.js.map
|
|
4116
4398
|
//# sourceMappingURL=index.js.map
|