import { r as __exportAll } from "./chunk-BSw8zbkd.mjs";
import { A as any, B as generateId, F as number, I as object, L as string, M as boolean, N as lazy, P as literal, a as BaseDocumentHeaderSchema, b as isDocumentAction, c as baseCreateDocument, f as createAction, g as createState, h as createReducer, j as array, l as baseLoadFromInput, o as BaseDocumentStateSchema, s as baseActions, u as baseSaveToFileHandle, v as defaultBaseState, z as datetime } from "./dist-RakiOObV.mjs";
//#region document-models/derivation/v1/gen/schema/zod.ts
const isDefinedNonNullAny = (v) => v !== void 0 && v !== null;
const definedNonNullAnySchema = any().refine((v) => isDefinedNonNullAny(v));
function AddReseedEntryInputSchema() {
	return object({
		changes: array(string()),
		id: string(),
		reason: string(),
		reseededAt: datetime()
	});
}
function AddSignalInputSchema() {
	return object({
		id: string(),
		influencedDimensions: array(string()),
		interpretation: string(),
		utterance: string()
	});
}
function ClaimReferenceSchema() {
	return object({
		__typename: literal("ClaimReference").optional(),
		claimRef: string(),
		id: string(),
		strength: string(),
		supportsDecision: string()
	});
}
function CoherenceCheckSchema() {
	return object({
		__typename: literal("CoherenceCheck").optional(),
		coherent: boolean(),
		dimensionPair: array(string()),
		explanation: string()
	});
}
function DerivationSignalSchema() {
	return object({
		__typename: literal("DerivationSignal").optional(),
		id: string(),
		influencedDimensions: array(string()),
		interpretation: string(),
		utterance: string()
	});
}
function DerivationStateSchema() {
	return object({
		__typename: literal("DerivationState").optional(),
		claimReferences: array(lazy(() => ClaimReferenceSchema())),
		coherenceResults: array(lazy(() => CoherenceCheckSchema())),
		derivedAt: datetime().nullish(),
		dimensionRationale: array(lazy(() => DimensionRationaleSchema())),
		engineVersion: string().nullish(),
		featureDecisions: array(lazy(() => FeatureDecisionSchema())),
		reseedHistory: array(lazy(() => ReseedEntrySchema())),
		signals: array(lazy(() => DerivationSignalSchema()))
	});
}
function DimensionRationaleSchema() {
	return object({
		__typename: literal("DimensionRationale").optional(),
		confidence: number(),
		dimension: string(),
		failureModes: array(string()),
		position: number(),
		rationale: string(),
		supportingClaims: array(string())
	});
}
function FeatureDecisionSchema() {
	return object({
		__typename: literal("FeatureDecision").optional(),
		enabled: boolean(),
		feature: string(),
		rationale: string(),
		supportingClaims: array(string())
	});
}
function InitializeDerivationInputSchema() {
	return object({
		derivedAt: datetime(),
		engineVersion: string()
	});
}
function ReseedEntrySchema() {
	return object({
		__typename: literal("ReseedEntry").optional(),
		changes: array(string()),
		id: string(),
		reason: string(),
		reseededAt: datetime()
	});
}
function UpdateDimensionRationaleInputSchema() {
	return object({
		confidence: number(),
		dimension: string(),
		failureModes: array(string()),
		position: number(),
		rationale: string(),
		supportingClaims: array(string())
	});
}
//#endregion
//#region document-models/derivation/v1/gen/derivation-management/creators.ts
/**
* WARNING: DO NOT EDIT
* This file is auto-generated and updated by codegen
*/
var creators_exports = /* @__PURE__ */ __exportAll({
	addReseedEntry: () => addReseedEntry,
	addSignal: () => addSignal,
	initializeDerivation: () => initializeDerivation,
	updateDimensionRationale: () => updateDimensionRationale
});
const initializeDerivation = (input) => createAction("INITIALIZE_DERIVATION", { ...input }, void 0, InitializeDerivationInputSchema, "global");
const addSignal = (input) => createAction("ADD_SIGNAL", { ...input }, void 0, AddSignalInputSchema, "global");
const addReseedEntry = (input) => createAction("ADD_RESEED_ENTRY", { ...input }, void 0, AddReseedEntryInputSchema, "global");
const updateDimensionRationale = (input) => createAction("UPDATE_DIMENSION_RATIONALE", { ...input }, void 0, UpdateDimensionRationaleInputSchema, "global");
//#endregion
//#region document-models/derivation/v1/actions.ts
/**
* WARNING: DO NOT EDIT
* This file is auto-generated and updated by codegen
*/
/** Actions for the Derivation document model */
const actions = {
	...baseActions,
	...creators_exports
};
//#endregion
//#region document-models/derivation/v1/gen/document-model.ts
const documentModel = {
	author: {
		name: "BAI",
		website: "https://bai.powerhouse.io/"
	},
	description: "Derivation record — audit trail of vault configuration decisions backed by research claims, dimension rationale, and coherence checks",
	extension: "",
	id: "bai/derivation",
	name: "Derivation",
	specifications: [{
		changeLog: [],
		modules: [{
			description: "Derivation audit trail",
			id: "derivation-management",
			name: "derivation-management",
			operations: [
				{
					description: "Initialize derivation record",
					errors: [],
					examples: [],
					id: "initialize-derivation",
					name: "INITIALIZE_DERIVATION",
					reducer: "state.engineVersion = action.input.engineVersion;\nstate.derivedAt = action.input.derivedAt;",
					schema: "input InitializeDerivationInput {\n    engineVersion: String!\n    derivedAt: DateTime!\n}",
					template: "Initialize derivation record",
					scope: "global"
				},
				{
					description: "Record a user signal that influenced derivation",
					errors: [],
					examples: [],
					id: "add-signal",
					name: "ADD_SIGNAL",
					reducer: "state.signals.push({\n    id: action.input.id,\n    utterance: action.input.utterance,\n    influencedDimensions: action.input.influencedDimensions,\n    interpretation: action.input.interpretation,\n});",
					schema: "input AddSignalInput {\n    id: OID!\n    utterance: String!\n    influencedDimensions: [String!]!\n    interpretation: String!\n}",
					template: "Record a user signal that influenced derivation",
					scope: "global"
				},
				{
					description: "Record a re-derivation event",
					errors: [],
					examples: [],
					id: "add-reseed-entry",
					name: "ADD_RESEED_ENTRY",
					reducer: "state.reseedHistory.push({\n    id: action.input.id,\n    reseededAt: action.input.reseededAt,\n    reason: action.input.reason,\n    changes: action.input.changes,\n});",
					schema: "input AddReseedEntryInput {\n    id: OID!\n    reseededAt: DateTime!\n    reason: String!\n    changes: [String!]!\n}",
					template: "Record a re-derivation event",
					scope: "global"
				},
				{
					description: "Update rationale for a dimension position",
					errors: [],
					examples: [],
					id: "update-dimension-rationale",
					name: "UPDATE_DIMENSION_RATIONALE",
					reducer: "const existing = state.dimensionRationale.findIndex(d => d.dimension === action.input.dimension);\nconst entry = {\n    dimension: action.input.dimension,\n    position: action.input.position,\n    confidence: action.input.confidence,\n    rationale: action.input.rationale,\n    supportingClaims: action.input.supportingClaims,\n    failureModes: action.input.failureModes,\n};\nif (existing >= 0) {\n    state.dimensionRationale[existing] = entry;\n} else {\n    state.dimensionRationale.push(entry);\n}",
					schema: "input UpdateDimensionRationaleInput {\n    dimension: String!\n    position: Int!\n    confidence: Float!\n    rationale: String!\n    supportingClaims: [String!]!\n    failureModes: [String!]!\n}",
					template: "Update rationale for a dimension position",
					scope: "global"
				}
			]
		}],
		state: {
			global: {
				examples: [],
				initialValue: "{\n    \"engineVersion\": null,\n    \"derivedAt\": null,\n    \"signals\": [],\n    \"dimensionRationale\": [],\n    \"claimReferences\": [],\n    \"featureDecisions\": [],\n    \"coherenceResults\": [],\n    \"reseedHistory\": []\n}",
				schema: "type DerivationSignal {\n    id: OID!\n    utterance: String!\n    influencedDimensions: [String!]!\n    interpretation: String!\n}\n\ntype DimensionRationale {\n    dimension: String!\n    position: Int!\n    confidence: Float!\n    rationale: String!\n    supportingClaims: [String!]!\n    failureModes: [String!]!\n}\n\ntype ClaimReference {\n    id: OID!\n    claimRef: String!\n    supportsDecision: String!\n    strength: String!\n}\n\ntype FeatureDecision {\n    feature: String!\n    enabled: Boolean!\n    rationale: String!\n    supportingClaims: [String!]!\n}\n\ntype CoherenceCheck {\n    dimensionPair: [String!]!\n    coherent: Boolean!\n    explanation: String!\n}\n\ntype ReseedEntry {\n    id: OID!\n    reseededAt: DateTime!\n    reason: String!\n    changes: [String!]!\n}\n\ntype DerivationState {\n    engineVersion: String\n    derivedAt: DateTime\n    signals: [DerivationSignal!]!\n    dimensionRationale: [DimensionRationale!]!\n    claimReferences: [ClaimReference!]!\n    featureDecisions: [FeatureDecision!]!\n    coherenceResults: [CoherenceCheck!]!\n    reseedHistory: [ReseedEntry!]!\n}"
			},
			local: {
				examples: [],
				initialValue: "",
				schema: ""
			}
		},
		version: 1
	}]
};
//#endregion
//#region document-models/derivation/v1/src/reducers/derivation-management.ts
const derivationDerivationManagementOperations = {
	initializeDerivationOperation(state, action) {
		state.engineVersion = action.input.engineVersion;
		state.derivedAt = action.input.derivedAt;
	},
	addSignalOperation(state, action) {
		state.signals.push({
			id: action.input.id,
			utterance: action.input.utterance,
			influencedDimensions: action.input.influencedDimensions,
			interpretation: action.input.interpretation
		});
	},
	addReseedEntryOperation(state, action) {
		state.reseedHistory.push({
			id: action.input.id,
			reseededAt: action.input.reseededAt,
			reason: action.input.reason,
			changes: action.input.changes
		});
	},
	updateDimensionRationaleOperation(state, action) {
		const existing = state.dimensionRationale.findIndex((d) => d.dimension === action.input.dimension);
		const entry = {
			dimension: action.input.dimension,
			position: action.input.position,
			confidence: action.input.confidence,
			rationale: action.input.rationale,
			supportingClaims: action.input.supportingClaims,
			failureModes: action.input.failureModes
		};
		if (existing >= 0) state.dimensionRationale[existing] = entry;
		else state.dimensionRationale.push(entry);
	}
};
//#endregion
//#region document-models/derivation/v1/gen/reducer.ts
const stateReducer = (state, action, dispatch) => {
	if (isDocumentAction(action)) return state;
	switch (action.type) {
		case "INITIALIZE_DERIVATION":
			InitializeDerivationInputSchema().parse(action.input);
			derivationDerivationManagementOperations.initializeDerivationOperation(state[action.scope], action, dispatch);
			break;
		case "ADD_SIGNAL":
			AddSignalInputSchema().parse(action.input);
			derivationDerivationManagementOperations.addSignalOperation(state[action.scope], action, dispatch);
			break;
		case "ADD_RESEED_ENTRY":
			AddReseedEntryInputSchema().parse(action.input);
			derivationDerivationManagementOperations.addReseedEntryOperation(state[action.scope], action, dispatch);
			break;
		case "UPDATE_DIMENSION_RATIONALE":
			UpdateDimensionRationaleInputSchema().parse(action.input);
			derivationDerivationManagementOperations.updateDimensionRationaleOperation(state[action.scope], action, dispatch);
			break;
		default: return state;
	}
};
const reducer = createReducer(stateReducer);
//#endregion
//#region document-models/derivation/v1/gen/document-type.ts
/**
* WARNING: DO NOT EDIT
* This file is auto-generated and updated by codegen
*/
const derivationDocumentType = "bai/derivation";
//#endregion
//#region document-models/derivation/v1/gen/document-schema.ts
/**
* WARNING: DO NOT EDIT
* This file is auto-generated and updated by codegen
*/
/** Schema for validating the header object of a Derivation document */
const DerivationDocumentHeaderSchema = BaseDocumentHeaderSchema.extend({ documentType: literal(derivationDocumentType) });
/** Schema for validating the state object of a Derivation document */
const DerivationPHStateSchema = BaseDocumentStateSchema.extend({ global: DerivationStateSchema() });
const DerivationDocumentSchema = object({
	header: DerivationDocumentHeaderSchema,
	state: DerivationPHStateSchema,
	initialState: DerivationPHStateSchema
});
/** Simple helper function to check if a state object is a Derivation document state object */
function isDerivationState(state) {
	return DerivationPHStateSchema.safeParse(state).success;
}
/** Simple helper function to assert that a document state object is a Derivation document state object */
function assertIsDerivationState(state) {
	DerivationPHStateSchema.parse(state);
}
/** Simple helper function to check if a document is a Derivation document */
function isDerivationDocument(document) {
	return DerivationDocumentSchema.safeParse(document).success;
}
/** Simple helper function to assert that a document is a Derivation document */
function assertIsDerivationDocument(document) {
	DerivationDocumentSchema.parse(document);
}
//#endregion
//#region document-models/derivation/v1/gen/utils.ts
const initialGlobalState = {
	engineVersion: null,
	derivedAt: null,
	signals: [],
	dimensionRationale: [],
	claimReferences: [],
	featureDecisions: [],
	coherenceResults: [],
	reseedHistory: []
};
const initialLocalState = {};
const utils$1 = {
	fileExtension: "",
	createState(state) {
		return {
			...defaultBaseState(),
			global: {
				...initialGlobalState,
				...state?.global
			},
			local: {
				...initialLocalState,
				...state?.local
			}
		};
	},
	createDocument(state) {
		const document = baseCreateDocument(utils$1.createState, state);
		document.header.documentType = derivationDocumentType;
		document.header.id = generateId();
		return document;
	},
	saveToFileHandle(document, input) {
		return baseSaveToFileHandle(document, input);
	},
	loadFromInput(input) {
		return baseLoadFromInput(input, reducer);
	},
	isStateOfType(state) {
		return isDerivationState(state);
	},
	assertIsStateOfType(state) {
		return assertIsDerivationState(state);
	},
	isDocumentOfType(document) {
		return isDerivationDocument(document);
	},
	assertIsDocumentOfType(document) {
		return assertIsDerivationDocument(document);
	}
};
//#endregion
//#region document-models/derivation/v1/src/utils.ts
var utils_exports = /* @__PURE__ */ __exportAll({});
//#endregion
//#region document-models/derivation/v1/utils.ts
/** Utils for the Derivation document model */
const utils = {
	...utils$1,
	...utils_exports
};
//#endregion
//#region document-models/derivation/v1/module.ts
/** Document model module for the Derivation document type */
const Derivation = {
	version: 1,
	reducer,
	actions,
	utils,
	documentModel: createState(defaultBaseState(), documentModel)
};
//#endregion
export { InitializeDerivationInputSchema as A, AddSignalInputSchema as C, DerivationStateSchema as D, DerivationSignalSchema as E, UpdateDimensionRationaleInputSchema as M, definedNonNullAnySchema as N, DimensionRationaleSchema as O, isDefinedNonNullAny as P, AddReseedEntryInputSchema as S, CoherenceCheckSchema as T, addReseedEntry as _, utils$1 as a, initializeDerivation as b, DerivationPHStateSchema as c, isDerivationDocument as d, isDerivationState as f, actions as g, documentModel as h, initialLocalState as i, ReseedEntrySchema as j, FeatureDecisionSchema as k, assertIsDerivationDocument as l, reducer as m, utils as n, DerivationDocumentHeaderSchema as o, derivationDocumentType as p, initialGlobalState as r, DerivationDocumentSchema as s, Derivation as t, assertIsDerivationState as u, addSignal as v, ClaimReferenceSchema as w, updateDimensionRationale as x, creators_exports as y };

//# sourceMappingURL=module-Gqycgj5Q.mjs.map