import { n as __exportAll } from "./chunk-YKewjYmz.js";
import { A as array, F as object, I as string, M as lazy, N as literal, O as _enum, P as number, R as datetime, _ as defaultBaseState, a as BaseDocumentStateSchema, c as baseLoadFromInput, d as createAction, h as createState, i as BaseDocumentHeaderSchema, k as any, l as baseSaveToFileHandle, m as createReducer, o as baseActions, s as baseCreateDocument, y as isDocumentAction, z as generateId } from "./dist-DZj99xX4.js";
//#region document-models/source/v1/gen/schema/zod.ts
const isDefinedNonNullAny = (v) => v !== void 0 && v !== null;
const definedNonNullAnySchema = any().refine((v) => isDefinedNonNullAny(v));
const SourceStatusSchema = _enum([
	"ARCHIVED",
	"EXTRACTED",
	"EXTRACTING",
	"INBOX"
]);
const SourceTypeSchema = _enum([
	"ARTICLE",
	"BOOK_CHAPTER",
	"CONVERSATION",
	"DOCUMENTATION",
	"MANUAL_ENTRY",
	"PAPER",
	"TRANSCRIPT",
	"WEB_PAGE"
]);
function AddExtractedClaimInputSchema() {
	return object({ claimRef: string() });
}
function ExtractionStatsSchema() {
	return object({
		__typename: literal("ExtractionStats").optional(),
		claimCount: number(),
		extractedAt: datetime().nullish(),
		extractedBy: string().nullish(),
		skipRate: number(),
		skippedCount: number()
	});
}
function IngestSourceInputSchema() {
	return object({
		author: string().nullish(),
		content: string(),
		createdAt: datetime(),
		createdBy: string().nullish(),
		description: string().nullish(),
		method: string().nullish(),
		publishedAt: datetime().nullish(),
		sourceType: SourceTypeSchema,
		title: string(),
		tool: string().nullish(),
		url: string().nullish()
	});
}
function RecordExtractionStatsInputSchema() {
	return object({
		claimCount: number(),
		extractedAt: datetime(),
		extractedBy: string().nullish(),
		skipRate: number(),
		skippedCount: number()
	});
}
function SetSourceStatusInputSchema() {
	return object({ status: SourceStatusSchema });
}
function SourceProvenanceSchema() {
	return object({
		__typename: literal("SourceProvenance").optional(),
		author: string().nullish(),
		method: string().nullish(),
		publishedAt: datetime().nullish(),
		tool: string().nullish(),
		url: string().nullish()
	});
}
function SourceStateSchema() {
	return object({
		__typename: literal("SourceState").optional(),
		content: string().nullish(),
		createdAt: datetime().nullish(),
		createdBy: string().nullish(),
		description: string().nullish(),
		extractedClaims: array(string()),
		extractionStats: lazy(() => ExtractionStatsSchema().nullish()),
		provenance: lazy(() => SourceProvenanceSchema().nullish()),
		sourceType: SourceTypeSchema.nullish(),
		status: SourceStatusSchema.nullish(),
		title: string().nullish()
	});
}
//#endregion
//#region document-models/source/v1/gen/source-management/creators.ts
/**
* WARNING: DO NOT EDIT
* This file is auto-generated and updated by codegen
*/
var creators_exports = /* @__PURE__ */ __exportAll({
	addExtractedClaim: () => addExtractedClaim,
	ingestSource: () => ingestSource,
	recordExtractionStats: () => recordExtractionStats,
	setSourceStatus: () => setSourceStatus
});
const ingestSource = (input) => createAction("INGEST_SOURCE", { ...input }, void 0, IngestSourceInputSchema, "global");
const setSourceStatus = (input) => createAction("SET_SOURCE_STATUS", { ...input }, void 0, SetSourceStatusInputSchema, "global");
const addExtractedClaim = (input) => createAction("ADD_EXTRACTED_CLAIM", { ...input }, void 0, AddExtractedClaimInputSchema, "global");
const recordExtractionStats = (input) => createAction("RECORD_EXTRACTION_STATS", { ...input }, void 0, RecordExtractionStatsInputSchema, "global");
//#endregion
//#region document-models/source/v1/actions.ts
/**
* WARNING: DO NOT EDIT
* This file is auto-generated and updated by codegen
*/
/** Actions for the Source document model */
const actions = {
	...baseActions,
	...creators_exports
};
//#endregion
//#region document-models/source/v1/gen/document-model.ts
const documentModel = {
	author: {
		name: "BAI",
		website: "https://bai.powerhouse.io/"
	},
	description: "Ingested source material — articles, papers, transcripts, and other content that feeds the knowledge extraction pipeline",
	extension: "",
	id: "bai/source",
	name: "Source",
	specifications: [{
		changeLog: [],
		modules: [{
			description: "Source lifecycle and extraction tracking",
			id: "source-management",
			name: "source-management",
			operations: [
				{
					description: "Add new source material",
					errors: [],
					examples: [],
					id: "ingest-source",
					name: "INGEST_SOURCE",
					reducer: "state.title = action.input.title;\nstate.content = action.input.content;\nstate.sourceType = action.input.sourceType;\nstate.description = action.input.description || null;\nstate.status = \"INBOX\";\nstate.createdAt = action.input.createdAt;\nstate.createdBy = action.input.createdBy || null;\nif (action.input.url || action.input.author || action.input.publishedAt) {\n    state.provenance = {\n        url: action.input.url || null,\n        author: action.input.author || null,\n        publishedAt: action.input.publishedAt || null,\n        method: action.input.method || null,\n        tool: action.input.tool || null,\n    };\n}",
					schema: "input IngestSourceInput {\n    title: String!\n    content: String!\n    sourceType: SourceType!\n    description: String\n    url: String\n    author: String\n    publishedAt: DateTime\n    method: String\n    tool: String\n    createdAt: DateTime!\n    createdBy: String\n}",
					template: "Add new source material",
					scope: "global"
				},
				{
					description: "Transition source status",
					errors: [],
					examples: [],
					id: "set-source-status",
					name: "SET_SOURCE_STATUS",
					reducer: "state.status = action.input.status;",
					schema: "input SetSourceStatusInput {\n    status: SourceStatus!\n}",
					template: "Transition source status",
					scope: "global"
				},
				{
					description: "Link an extracted claim to this source",
					errors: [],
					examples: [],
					id: "add-extracted-claim",
					name: "ADD_EXTRACTED_CLAIM",
					reducer: "state.extractedClaims.push(action.input.claimRef);",
					schema: "input AddExtractedClaimInput {\n    claimRef: String!\n}",
					template: "Link an extracted claim to this source",
					scope: "global"
				},
				{
					description: "Record extraction statistics",
					errors: [],
					examples: [],
					id: "record-extraction-stats",
					name: "RECORD_EXTRACTION_STATS",
					reducer: "state.extractionStats = {\n    claimCount: action.input.claimCount,\n    skippedCount: action.input.skippedCount,\n    skipRate: action.input.skipRate,\n    extractedAt: action.input.extractedAt,\n    extractedBy: action.input.extractedBy || null,\n};",
					schema: "input RecordExtractionStatsInput {\n    claimCount: Int!\n    skippedCount: Int!\n    skipRate: Float!\n    extractedAt: DateTime!\n    extractedBy: String\n}",
					template: "Record extraction statistics",
					scope: "global"
				}
			]
		}],
		state: {
			global: {
				examples: [],
				initialValue: "{\n    \"title\": null,\n    \"description\": null,\n    \"content\": null,\n    \"sourceType\": null,\n    \"status\": \"INBOX\",\n    \"provenance\": null,\n    \"extractedClaims\": [],\n    \"extractionStats\": null,\n    \"createdAt\": null,\n    \"createdBy\": null\n}",
				schema: "enum SourceType {\n    ARTICLE\n    PAPER\n    BOOK_CHAPTER\n    TRANSCRIPT\n    DOCUMENTATION\n    CONVERSATION\n    WEB_PAGE\n    MANUAL_ENTRY\n}\n\nenum SourceStatus {\n    INBOX\n    EXTRACTING\n    EXTRACTED\n    ARCHIVED\n}\n\ntype SourceProvenance {\n    url: String\n    author: String\n    publishedAt: DateTime\n    method: String\n    tool: String\n}\n\ntype ExtractionStats {\n    claimCount: Int!\n    skippedCount: Int!\n    skipRate: Float!\n    extractedAt: DateTime\n    extractedBy: String\n}\n\ntype SourceState {\n    title: String\n    description: String\n    content: String\n    sourceType: SourceType\n    status: SourceStatus\n    provenance: SourceProvenance\n    extractedClaims: [String!]!\n    extractionStats: ExtractionStats\n    createdAt: DateTime\n    createdBy: String\n}"
			},
			local: {
				examples: [],
				initialValue: "",
				schema: ""
			}
		},
		version: 1
	}]
};
//#endregion
//#region document-models/source/v1/src/reducers/source-management.ts
const sourceSourceManagementOperations = {
	ingestSourceOperation(state, action) {
		state.title = action.input.title;
		state.content = action.input.content;
		state.sourceType = action.input.sourceType;
		state.description = action.input.description || null;
		state.status = "INBOX";
		state.createdAt = action.input.createdAt;
		state.createdBy = action.input.createdBy || null;
		if (action.input.url || action.input.author || action.input.publishedAt) state.provenance = {
			url: action.input.url || null,
			author: action.input.author || null,
			publishedAt: action.input.publishedAt || null,
			method: action.input.method || null,
			tool: action.input.tool || null
		};
	},
	setSourceStatusOperation(state, action) {
		state.status = action.input.status;
	},
	addExtractedClaimOperation(state, action) {
		state.extractedClaims.push(action.input.claimRef);
	},
	recordExtractionStatsOperation(state, action) {
		state.extractionStats = {
			claimCount: action.input.claimCount,
			skippedCount: action.input.skippedCount,
			skipRate: action.input.skipRate,
			extractedAt: action.input.extractedAt,
			extractedBy: action.input.extractedBy || null
		};
	}
};
//#endregion
//#region document-models/source/v1/gen/reducer.ts
const stateReducer = (state, action, dispatch) => {
	if (isDocumentAction(action)) return state;
	switch (action.type) {
		case "INGEST_SOURCE":
			IngestSourceInputSchema().parse(action.input);
			sourceSourceManagementOperations.ingestSourceOperation(state[action.scope], action, dispatch);
			break;
		case "SET_SOURCE_STATUS":
			SetSourceStatusInputSchema().parse(action.input);
			sourceSourceManagementOperations.setSourceStatusOperation(state[action.scope], action, dispatch);
			break;
		case "ADD_EXTRACTED_CLAIM":
			AddExtractedClaimInputSchema().parse(action.input);
			sourceSourceManagementOperations.addExtractedClaimOperation(state[action.scope], action, dispatch);
			break;
		case "RECORD_EXTRACTION_STATS":
			RecordExtractionStatsInputSchema().parse(action.input);
			sourceSourceManagementOperations.recordExtractionStatsOperation(state[action.scope], action, dispatch);
			break;
		default: return state;
	}
};
const reducer = createReducer(stateReducer);
//#endregion
//#region document-models/source/v1/gen/document-type.ts
/**
* WARNING: DO NOT EDIT
* This file is auto-generated and updated by codegen
*/
const sourceDocumentType = "bai/source";
//#endregion
//#region document-models/source/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 Source document */
const SourceDocumentHeaderSchema = BaseDocumentHeaderSchema.extend({ documentType: literal(sourceDocumentType) });
/** Schema for validating the state object of a Source document */
const SourcePHStateSchema = BaseDocumentStateSchema.extend({ global: SourceStateSchema() });
const SourceDocumentSchema = object({
	header: SourceDocumentHeaderSchema,
	state: SourcePHStateSchema,
	initialState: SourcePHStateSchema
});
/** Simple helper function to check if a state object is a Source document state object */
function isSourceState(state) {
	return SourcePHStateSchema.safeParse(state).success;
}
/** Simple helper function to assert that a document state object is a Source document state object */
function assertIsSourceState(state) {
	SourcePHStateSchema.parse(state);
}
/** Simple helper function to check if a document is a Source document */
function isSourceDocument(document) {
	return SourceDocumentSchema.safeParse(document).success;
}
/** Simple helper function to assert that a document is a Source document */
function assertIsSourceDocument(document) {
	SourceDocumentSchema.parse(document);
}
//#endregion
//#region document-models/source/v1/gen/utils.ts
const initialGlobalState = {
	title: null,
	description: null,
	content: null,
	sourceType: null,
	status: "INBOX",
	provenance: null,
	extractedClaims: [],
	extractionStats: null,
	createdAt: null,
	createdBy: null
};
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 = sourceDocumentType;
		document.header.id = generateId();
		return document;
	},
	saveToFileHandle(document, input) {
		return baseSaveToFileHandle(document, input);
	},
	loadFromInput(input) {
		return baseLoadFromInput(input, reducer);
	},
	isStateOfType(state) {
		return isSourceState(state);
	},
	assertIsStateOfType(state) {
		return assertIsSourceState(state);
	},
	isDocumentOfType(document) {
		return isSourceDocument(document);
	},
	assertIsDocumentOfType(document) {
		return assertIsSourceDocument(document);
	}
};
//#endregion
//#region document-models/source/v1/src/utils.ts
var utils_exports = /* @__PURE__ */ __exportAll({});
//#endregion
//#region document-models/source/v1/utils.ts
/** Utils for the Source document model */
const utils = {
	...utils$1,
	...utils_exports
};
//#endregion
//#region document-models/source/v1/module.ts
/** Document model module for the Source document type */
const Source = {
	version: 1,
	reducer,
	actions,
	utils,
	documentModel: createState(defaultBaseState(), documentModel)
};
//#endregion
export { SourceTypeSchema as A, ExtractionStatsSchema as C, SourceProvenanceSchema as D, SetSourceStatusInputSchema as E, isDefinedNonNullAny as M, SourceStateSchema as O, AddExtractedClaimInputSchema as S, RecordExtractionStatsInputSchema as T, addExtractedClaim as _, utils$1 as a, recordExtractionStats as b, SourcePHStateSchema as c, isSourceDocument as d, isSourceState as f, actions as g, documentModel as h, initialLocalState as i, definedNonNullAnySchema as j, SourceStatusSchema as k, assertIsSourceDocument as l, reducer as m, utils as n, SourceDocumentHeaderSchema as o, sourceDocumentType as p, initialGlobalState as r, SourceDocumentSchema as s, Source as t, assertIsSourceState as u, creators_exports as v, IngestSourceInputSchema as w, setSourceStatus as x, ingestSource as y };

//# sourceMappingURL=module-C4lB_Yyh.js.map