feat(p7): AI tables + enums + migration + events + InferencePort contract

Task 7.1: 7 AI-proposal-layer tables (IiosAiJob, IiosAiModelRun, IiosAiArtifact,
IiosAiClaim, IiosAiEvidenceLink, IiosAiToolCall, IiosEmbeddingRef) + enums;
migration ai-init. Adds ai.job.created / ai.artifact.proposed / ai.artifact.accepted
events and a standalone InferencePort contract (not part of sealed IiosPlatformPorts).
resetDb truncates the new tables.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-01 16:26:21 +05:30
parent 54c47dd133
commit 42bb99c09f
6 changed files with 419 additions and 0 deletions
+3
View File
@@ -43,6 +43,9 @@ export const IIOS_EVENTS = {
callbackRequested: 'com.insignia.iios.support.callback.requested.v1',
routeDecisionPreviewed: 'com.insignia.iios.route.decision.previewed.v1',
routeApproved: 'com.insignia.iios.route.approved.v1',
aiJobCreated: 'com.insignia.iios.ai.job.created.v1',
aiArtifactProposed: 'com.insignia.iios.ai.artifact.proposed.v1',
aiArtifactAccepted: 'com.insignia.iios.ai.artifact.accepted.v1',
notificationQueued: 'com.insignia.iios.notification.queued.v1',
deliveryAttempted: 'com.insignia.iios.delivery.attempted.v1',
} as const;
+1
View File
@@ -2,6 +2,7 @@ export * from './scope';
export * from './enums';
export * from './ingest';
export * from './ports';
export * from './inference';
export * from './events';
export * from './commands';
export * from './errors';
+61
View File
@@ -0,0 +1,61 @@
/**
* The AI inference port (P7). A standalone contract — deliberately NOT part of the
* sealed `IiosPlatformPorts`: AI is an internal "AI Factory" whose model execution
* routes through the Capability Broker in P9. In P7 it is a faked, deterministic,
* golden provider (no network). Every result carries the provenance the critics
* mandate (model/prompt version, tokens, cost, confidence, abstention, evidence).
*/
export type AiJobType = 'CLASSIFY' | 'SUMMARIZE' | 'EXTRACT';
export type AiArtifactType = 'CLASSIFICATION' | 'SUMMARY' | 'TRANSCRIPT' | 'DIGEST' | 'EXTRACTION';
export type AiClaimType = 'MODERATION_FLAG' | 'EVENT' | 'FAQ' | 'INTENT' | 'PRIORITY';
export interface InferenceRequest {
jobType: AiJobType;
text: string;
purpose: string;
scopeId: string;
/** The kernel interaction this inference is about — used as the default evidence source. */
interactionId?: string;
}
export interface InferenceClaim {
claimType: AiClaimType;
claimJson: Record<string, unknown>;
confidence: number;
}
export interface InferenceEvidence {
sourceType: string;
sourceId: string;
spanRef?: string;
relevanceScore?: number;
}
export interface InferenceModelRun {
model: string;
modelVersion: string;
promptVersion: string;
tokensIn: number;
tokensOut: number;
costUnits: number;
latencyMs: number;
}
export interface InferenceResult {
artifactType: AiArtifactType;
content: unknown;
confidence: number;
explanation?: string;
/** Set when the model declines to assert a claim (Scenario 7 abstention). */
abstentionReason?: string;
claims: InferenceClaim[];
evidence: InferenceEvidence[];
modelRun: InferenceModelRun;
}
export interface InferencePort {
infer(req: InferenceRequest): Promise<InferenceResult>;
}