@xpert-ai/contracts 3.16.0 → 3.17.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.
Files changed (34) hide show
  1. package/index.cjs.js +48 -12
  2. package/index.esm.js +38 -10
  3. package/package.json +1 -1
  4. package/src/agent/ai-model.d.ts +4 -1
  5. package/src/agent/graph.d.ts +2 -0
  6. package/src/ai/ai-model.model.d.ts +2 -1
  7. package/src/ai/evolution/candidate.d.ts +67 -0
  8. package/src/ai/evolution/capability-version.d.ts +45 -0
  9. package/src/ai/evolution/evaluation.d.ts +93 -0
  10. package/src/ai/evolution/example.d.ts +42 -0
  11. package/src/ai/evolution/experience.d.ts +21 -0
  12. package/src/ai/evolution/governance.d.ts +87 -0
  13. package/src/ai/evolution/index.d.ts +11 -0
  14. package/src/ai/evolution/learning-event.d.ts +69 -0
  15. package/src/ai/evolution/provider.d.ts +30 -0
  16. package/src/ai/evolution/release.d.ts +144 -0
  17. package/src/ai/evolution/runtime.d.ts +81 -0
  18. package/src/ai/evolution/target.d.ts +83 -0
  19. package/src/ai/index.d.ts +3 -0
  20. package/src/ai/knowledge-doc-chunk.model.d.ts +143 -0
  21. package/src/ai/knowledge-doc.model.d.ts +53 -4
  22. package/src/ai/knowledge-filter.model.d.ts +92 -0
  23. package/src/ai/knowledge-retrieval-log.model.d.ts +16 -0
  24. package/src/ai/knowledgebase-task.model.d.ts +3 -1
  25. package/src/ai/knowledgebase.model.d.ts +6 -0
  26. package/src/ai/membership.model.d.ts +40 -7
  27. package/src/ai/model-gateway.model.d.ts +5 -0
  28. package/src/ai/model-usage.model.d.ts +163 -0
  29. package/src/ai/role-permissions.d.ts +3 -1
  30. package/src/ai/xpert-agent-execution.model.d.ts +2 -0
  31. package/src/ai/xpert.model.d.ts +23 -11
  32. package/src/plugin.d.ts +4 -0
  33. package/src/tenant.model.d.ts +1 -1
  34. package/src/view-extension/model.d.ts +12 -1
@@ -0,0 +1,87 @@
1
+ export interface EvolutionPageQuery {
2
+ page?: number;
3
+ pageSize?: number;
4
+ search?: string;
5
+ targetId?: string;
6
+ status?: string;
7
+ sort?: 'createdAt' | 'updatedAt' | 'status';
8
+ order?: 'ASC' | 'DESC';
9
+ }
10
+ export interface EvolutionPage<T> {
11
+ items: T[];
12
+ total: number;
13
+ page: number;
14
+ pageSize: number;
15
+ }
16
+ export interface ReviewLearningEventRequest {
17
+ reviewStatus: 'pending' | 'ignored' | 'golden';
18
+ }
19
+ export interface DiagnoseLearningEventsRequest {
20
+ eventIds: string[];
21
+ }
22
+ export interface EvolutionAnalysisResult {
23
+ diagnoses: import('./learning-event').EvolutionDiagnosis[];
24
+ clusters: import('./learning-event').EvolutionEventCluster[];
25
+ }
26
+ export interface CreateImprovementProposalRequest {
27
+ targetId: string;
28
+ scope: import('./target').EvolutionScope;
29
+ eventIds: string[];
30
+ title: string;
31
+ problemStatement: string;
32
+ rootCause: string;
33
+ changeHypothesis: string;
34
+ riskLevel: import('./target').EvolutionRiskLevel;
35
+ }
36
+ export interface BuildCandidateCommand {
37
+ proposalId: string;
38
+ proposalRevision: number;
39
+ changeSet: Record<string, string | number | boolean | string[]>;
40
+ }
41
+ export interface CreateDatasetSnapshotRequest {
42
+ datasetId: string;
43
+ targetId: string;
44
+ scope: import('./target').EvolutionScope;
45
+ name: string;
46
+ evaluatorVersion: string;
47
+ metricDefinitionVersion: string;
48
+ cases: import('./evaluation').GoldenCaseRevision[];
49
+ }
50
+ export interface EvaluateCandidateCommand {
51
+ candidateId: string;
52
+ datasetSnapshotId: string;
53
+ }
54
+ export interface DecideCandidateApprovalRequest {
55
+ evaluationRunId: string;
56
+ decision: 'approved' | 'rejected';
57
+ reason: string;
58
+ }
59
+ export interface CreateReleasePackageRequest {
60
+ candidateId: string;
61
+ evaluationRunId: string;
62
+ approvalIds: string[];
63
+ shadowMinimumSamples?: number;
64
+ }
65
+ export interface StartDeploymentRequest {
66
+ canaryPercent?: 5 | 25 | 50;
67
+ }
68
+ export interface CreateEvolutionCanaryTestOverrideRequest {
69
+ subjectKey: string;
70
+ reason: string;
71
+ /** Defaults to 30 minutes and is capped by the server. */
72
+ expiresInMinutes?: number;
73
+ }
74
+ export type EvolutionJobType = 'evaluation' | 'install' | 'shadow' | 'canary' | 'rollback';
75
+ export type EvolutionJobStatus = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
76
+ export interface EvolutionJob {
77
+ jobId: string;
78
+ jobType: EvolutionJobType;
79
+ resourceId: string;
80
+ status: EvolutionJobStatus;
81
+ queueJobId?: string;
82
+ errorCode?: string;
83
+ errorMessage?: string;
84
+ createdAt: string;
85
+ startedAt?: string;
86
+ completedAt?: string;
87
+ }
@@ -0,0 +1,11 @@
1
+ export * from './target';
2
+ export * from './capability-version';
3
+ export * from './learning-event';
4
+ export * from './candidate';
5
+ export * from './evaluation';
6
+ export * from './release';
7
+ export * from './provider';
8
+ export * from './example';
9
+ export * from './runtime';
10
+ export * from './governance';
11
+ export * from './experience';
@@ -0,0 +1,69 @@
1
+ import { EvolutionScope } from './target';
2
+ export type LearningEventType = 'prediction_reviewed' | 'execution_failed' | 'business_outcome';
3
+ export type LearningEventConfidence = 'L1' | 'L2' | 'L3' | 'L4';
4
+ export interface LearningEventInput {
5
+ eventId?: string;
6
+ eventType: LearningEventType;
7
+ schemaVersion: string;
8
+ idempotencyKey: string;
9
+ eventTime: string;
10
+ scope: EvolutionScope;
11
+ executionId?: string;
12
+ threadId?: string;
13
+ traceId?: string;
14
+ targetId: string;
15
+ decisionPoint: string;
16
+ subjectRef: string;
17
+ inputFingerprint: string;
18
+ predictionSummary: string;
19
+ finalOutcomeSummary: string;
20
+ confidence: number;
21
+ reasonCodes: string[];
22
+ capabilityVersionBundleId: string;
23
+ bundleHash: string;
24
+ trustLevel: LearningEventConfidence;
25
+ classification: 'public' | 'internal' | 'confidential';
26
+ redactionStatus: 'not_required' | 'redacted';
27
+ }
28
+ export interface LearningEvent extends LearningEventInput {
29
+ eventId: string;
30
+ createdAt: string;
31
+ reviewStatus?: 'pending' | 'ignored' | 'golden';
32
+ }
33
+ export interface EvolutionDiagnosis {
34
+ diagnosisId: string;
35
+ targetId: string;
36
+ scope: EvolutionScope;
37
+ eventIds: string[];
38
+ rootCause: string;
39
+ correctionSignature: string;
40
+ confidence: number;
41
+ createdAt: string;
42
+ }
43
+ export interface EvolutionEventCluster {
44
+ clusterId: string;
45
+ targetId: string;
46
+ scope: EvolutionScope;
47
+ correctionSignature: string;
48
+ eventIds: string[];
49
+ caseCount: number;
50
+ status: 'collecting' | 'proposal_ready' | 'closed';
51
+ createdAt: string;
52
+ updatedAt: string;
53
+ }
54
+ export interface ImprovementProposal {
55
+ proposalId: string;
56
+ revision: number;
57
+ targetId: string;
58
+ scope: EvolutionScope;
59
+ title: string;
60
+ problemStatement: string;
61
+ rootCause: string;
62
+ changeHypothesis: string;
63
+ evidenceEventIds: string[];
64
+ baseVersionId: string;
65
+ riskLevel: 'R1' | 'R2' | 'R3' | 'R4';
66
+ status: 'draft' | 'ready' | 'candidate_built' | 'rejected';
67
+ createdAt: string;
68
+ createdBy: string;
69
+ }
@@ -0,0 +1,30 @@
1
+ import { BuildEvolutionCandidateRequest, CandidateBuildResult, CandidateValidationResult, ExportEvolutionBaselineRequest, ExportEvolutionBaselineResult, ValidateEvolutionCandidateRequest } from './candidate';
2
+ import { MetricObservation, ReplayCaseRequest, ReplayCaseResult } from './evaluation';
3
+ import { ReleaseProviderReceipt, ReleaseProviderRequest } from './release';
4
+ import { EvolutionTargetDescriptor } from './target';
5
+ export interface EvolutionCandidateBuilder {
6
+ buildCandidate(request: BuildEvolutionCandidateRequest): Promise<CandidateBuildResult>;
7
+ validateCandidate(request: ValidateEvolutionCandidateRequest): Promise<CandidateValidationResult>;
8
+ }
9
+ export interface EvolutionBaselineExporter {
10
+ exportBaseline(request: ExportEvolutionBaselineRequest): Promise<ExportEvolutionBaselineResult>;
11
+ }
12
+ export interface EvolutionReplayEvaluator {
13
+ runReplayCase(request: ReplayCaseRequest): Promise<ReplayCaseResult>;
14
+ evaluateResult(request: ReplayCaseRequest, result: ReplayCaseResult): Promise<MetricObservation[]>;
15
+ }
16
+ export interface EvolutionReleaseProvider {
17
+ install(request: ReleaseProviderRequest): Promise<ReleaseProviderReceipt>;
18
+ activate(request: ReleaseProviderRequest): Promise<ReleaseProviderReceipt>;
19
+ rollback(request: ReleaseProviderRequest): Promise<ReleaseProviderReceipt>;
20
+ }
21
+ export interface EvolutionTargetProvider {
22
+ readonly descriptor: EvolutionTargetDescriptor;
23
+ readonly baselineExporter?: EvolutionBaselineExporter;
24
+ readonly candidateBuilder?: EvolutionCandidateBuilder;
25
+ readonly replayEvaluator?: EvolutionReplayEvaluator;
26
+ readonly releaseProvider?: EvolutionReleaseProvider;
27
+ }
28
+ export interface EvolutionProvider extends EvolutionTargetProvider {
29
+ describeTargets?(): Promise<EvolutionTargetDescriptor[]> | EvolutionTargetDescriptor[];
30
+ }
@@ -0,0 +1,144 @@
1
+ import { EvolutionChannel, EvolutionProviderContext, EvolutionScope } from './target';
2
+ export type EvolutionReleaseStatus = 'draft' | 'pending_approval' | 'approved' | 'installed' | 'shadow' | 'canary' | 'active' | 'paused' | 'rolled_back' | 'superseded';
3
+ export type EvolutionApprovalAuthority = 'standard' | 'administrator';
4
+ export type EvolutionReleaseGateProfile = 'standard' | 'manual_test';
5
+ /**
6
+ * Frozen staged-release gates. `manual_test` is accepted only by a
7
+ * non-production server and requires an administrator for gated actions.
8
+ */
9
+ export interface EvolutionReleaseGatePolicy {
10
+ profile: EvolutionReleaseGateProfile;
11
+ shadowMinimumSamples: number;
12
+ shadowMinimumDurationHours: number;
13
+ canaryMinimumSamples: number;
14
+ canaryMinimumDurationHours: number;
15
+ productionCanaryMinimumSamples: number;
16
+ productionCanaryMinimumDurationHours: number;
17
+ experienceMinimumSamples: number;
18
+ experienceMinimumDurationHours: number;
19
+ }
20
+ export interface ApprovalDecision {
21
+ approvalId: string;
22
+ candidateId: string;
23
+ candidateHash: string;
24
+ evaluationRunId: string;
25
+ scope: EvolutionScope;
26
+ decision: 'approved' | 'rejected';
27
+ actorId: string;
28
+ actorRole: string;
29
+ /** Stable role name recorded at decision time for audit display. */
30
+ actorRoleName?: string;
31
+ /**
32
+ * Administrator approvals are a governed single-approver path. Missing values
33
+ * are treated as `standard` for records created before this field existed.
34
+ */
35
+ approvalAuthority?: EvolutionApprovalAuthority;
36
+ reason: string;
37
+ decidedAt: string;
38
+ }
39
+ export interface ReleasePackage {
40
+ releasePackageId: string;
41
+ candidateId: string;
42
+ candidateHash: string;
43
+ targetId: string;
44
+ targetVersionId: string;
45
+ rollbackVersionId: string;
46
+ evaluationRunId: string;
47
+ scope: EvolutionScope;
48
+ status: EvolutionReleaseStatus;
49
+ approvalIds: string[];
50
+ artifactHash: string;
51
+ providerKey: string;
52
+ providerVersion: string;
53
+ /** Missing only on release packages created before gate policies were frozen. */
54
+ gatePolicy?: EvolutionReleaseGatePolicy;
55
+ /** @deprecated Read `gatePolicy.shadowMinimumSamples` for new release packages. */
56
+ shadowMinimumSamples: number;
57
+ canaryPercent: number;
58
+ createdAt: string;
59
+ createdBy: string;
60
+ }
61
+ export interface ReleaseDeployment {
62
+ deploymentId: string;
63
+ releasePackageId: string;
64
+ channel: EvolutionChannel;
65
+ scope: EvolutionScope;
66
+ status: EvolutionReleaseStatus;
67
+ dataSource: 'deterministic_replay' | 'runtime_telemetry';
68
+ sampleCount: number;
69
+ candidateAccuracy: number;
70
+ severeErrors: number;
71
+ canaryPercent: number;
72
+ observations: ReleaseRuntimeObservation[];
73
+ startedAt: string;
74
+ completedAt?: string;
75
+ }
76
+ export interface ReleaseRuntimeObservation {
77
+ observationId: string;
78
+ observedAt: string;
79
+ sequence: number;
80
+ sampleCount: number;
81
+ baselineAccuracy: number;
82
+ candidateAccuracy: number;
83
+ severeErrors: number;
84
+ p95LatencyMs: number;
85
+ averageCost: number;
86
+ }
87
+ export interface ReleaseProviderRequest {
88
+ context?: EvolutionProviderContext;
89
+ targetId: string;
90
+ versionId: string;
91
+ artifactHash: string;
92
+ scope: EvolutionScope;
93
+ releasePackageId: string;
94
+ actorId: string;
95
+ idempotencyKey: string;
96
+ }
97
+ export interface ReleaseProviderReceipt {
98
+ receiptId: string;
99
+ versionId: string;
100
+ operation: 'install' | 'activate' | 'rollback';
101
+ status: 'ready' | 'completed';
102
+ providerTraceId: string;
103
+ }
104
+ export interface EvolutionAuditEvent {
105
+ auditId: string;
106
+ releasePackageId?: string;
107
+ candidateId?: string;
108
+ action: string;
109
+ actorId: string;
110
+ actorRole: string;
111
+ summary: string;
112
+ metadata?: EvolutionAuditEventMetadata;
113
+ occurredAt: string;
114
+ }
115
+ export interface EvolutionAuditEventMetadata {
116
+ manualTestOverrideId?: string;
117
+ deploymentId?: string;
118
+ subjectKey?: string;
119
+ executionId?: string;
120
+ reason?: string;
121
+ overrideStatus?: EvolutionCanaryTestOverrideStatus;
122
+ }
123
+ export type EvolutionCanaryTestOverrideStatus = 'pending' | 'consumed' | 'expired';
124
+ /**
125
+ * Administrator-created, single-use Candidate assignment for one Canary subject.
126
+ * It is available only to releases frozen with the non-production `manual_test` gate profile.
127
+ */
128
+ export interface EvolutionCanaryTestOverride {
129
+ overrideId: string;
130
+ releasePackageId: string;
131
+ candidateId: string;
132
+ deploymentId: string;
133
+ targetId: string;
134
+ scope: EvolutionScope;
135
+ subjectKey: string;
136
+ status: EvolutionCanaryTestOverrideStatus;
137
+ reason: string;
138
+ createdBy: string;
139
+ createdByRole: string;
140
+ createdAt: string;
141
+ expiresAt: string;
142
+ consumedAt?: string;
143
+ consumedByExecutionId?: string;
144
+ }
@@ -0,0 +1,81 @@
1
+ import { LearningEvent, LearningEventInput } from './learning-event';
2
+ import { CapabilityVersion, CapabilityVersionBundle } from './capability-version';
3
+ import { EvolutionChannel, EvolutionExecutionMode, EvolutionScope } from './target';
4
+ export interface EvolutionRuntimeObservationInput {
5
+ observationId?: string;
6
+ targetId: string;
7
+ scope: EvolutionScope;
8
+ executionId: string;
9
+ bundleId: string;
10
+ deploymentId?: string;
11
+ subjectKey: string;
12
+ channel: EvolutionChannel;
13
+ success: boolean;
14
+ severeError: boolean;
15
+ latencyMs: number;
16
+ cost?: number;
17
+ correctionRequired?: boolean;
18
+ observedAt: string;
19
+ }
20
+ export interface EvolutionRuntimeObservation extends EvolutionRuntimeObservationInput {
21
+ observationId: string;
22
+ createdAt: string;
23
+ }
24
+ export interface ResolveCapabilityExecutionPlanRequest {
25
+ tenantId: string;
26
+ organizationId?: string | null;
27
+ scope: EvolutionScope;
28
+ targetIds: string[];
29
+ subjectKey: string;
30
+ executionId: string;
31
+ }
32
+ export interface CapabilityExecutionAssignment {
33
+ targetId: string;
34
+ channel: EvolutionChannel;
35
+ versionId: string;
36
+ deploymentId?: string;
37
+ selectionReason?: 'manual_test_override';
38
+ manualTestOverrideId?: string;
39
+ }
40
+ export interface CapabilityExecutionManualTestOverride {
41
+ overrideId: string;
42
+ releasePackageId: string;
43
+ deploymentId: string;
44
+ targetId: string;
45
+ consumedAt: string;
46
+ }
47
+ export interface CapabilityExecutionPlan {
48
+ executionId: string;
49
+ executionMode: EvolutionExecutionMode;
50
+ subjectKey: string;
51
+ bundle: CapabilityVersionBundle;
52
+ assignments: CapabilityExecutionAssignment[];
53
+ /** Explicit audit marker; never present for normal deterministic Canary routing. */
54
+ manualTestOverrides?: CapabilityExecutionManualTestOverride[];
55
+ shadowBundle?: CapabilityVersionBundle;
56
+ shadowAssignments?: CapabilityExecutionAssignment[];
57
+ resolvedAt: string;
58
+ }
59
+ export interface EvolutionRuntimeApi {
60
+ ingestLearningEvent(input: {
61
+ tenantId: string;
62
+ organizationId?: string | null;
63
+ event: LearningEventInput;
64
+ }): Promise<LearningEvent>;
65
+ resolveExecutionPlan(request: ResolveCapabilityExecutionPlanRequest): Promise<CapabilityExecutionPlan>;
66
+ getCapabilityBundle(input: {
67
+ tenantId: string;
68
+ organizationId?: string | null;
69
+ bundleId: string;
70
+ }): Promise<CapabilityVersionBundle>;
71
+ getCapabilityVersion(input: {
72
+ tenantId: string;
73
+ organizationId?: string | null;
74
+ versionId: string;
75
+ }): Promise<CapabilityVersion>;
76
+ recordRuntimeObservation(input: {
77
+ tenantId: string;
78
+ organizationId?: string | null;
79
+ observation: EvolutionRuntimeObservationInput;
80
+ }): Promise<EvolutionRuntimeObservation>;
81
+ }
@@ -0,0 +1,83 @@
1
+ import type { I18nText } from '../../i18n.model';
2
+ export type EvolutionTargetType = 'prompt_policy' | 'routing_policy' | 'extraction_policy' | 'test_fixture';
3
+ export type EvolutionScopeType = 'tenant' | 'organization' | 'workspace' | 'project';
4
+ export type EvolutionExecutionMode = 'production' | 'replay' | 'shadow' | 'canary';
5
+ export type EvolutionChannel = 'production' | 'shadow' | 'canary';
6
+ export type EvolutionRiskLevel = 'R1' | 'R2' | 'R3' | 'R4';
7
+ export interface EvolutionScopeDimensions {
8
+ productFamily?: string;
9
+ customerId?: string;
10
+ workspaceId?: string;
11
+ projectId?: string;
12
+ }
13
+ export interface EvolutionScope {
14
+ type: EvolutionScopeType;
15
+ key: string;
16
+ dimensions?: EvolutionScopeDimensions;
17
+ }
18
+ export interface EvolutionActor {
19
+ actorId: string;
20
+ actorType: 'human' | 'agent' | 'system';
21
+ actorRole?: string;
22
+ }
23
+ export interface EvolutionProviderContext {
24
+ tenantId: string;
25
+ organizationId?: string | null;
26
+ targetId: string;
27
+ scope: EvolutionScope;
28
+ correlationId: string;
29
+ executionId?: string;
30
+ actor: EvolutionActor;
31
+ }
32
+ export interface EvolutionTargetCapabilities {
33
+ candidateBuild: boolean;
34
+ replay: boolean;
35
+ shadow: boolean;
36
+ canary: boolean;
37
+ install: boolean;
38
+ rollback: boolean;
39
+ }
40
+ export type EvolutionCandidateChangeFieldType = 'string' | 'number' | 'boolean' | 'string_array' | 'select';
41
+ export interface EvolutionCandidateChangeFieldDescriptor {
42
+ key: string;
43
+ label: I18nText;
44
+ description?: I18nText;
45
+ type: EvolutionCandidateChangeFieldType;
46
+ required?: boolean;
47
+ placeholder?: I18nText;
48
+ defaultValue?: string | number | boolean | string[];
49
+ options?: Array<{
50
+ label: I18nText;
51
+ value: string;
52
+ }>;
53
+ }
54
+ /**
55
+ * Optional, provider-owned description used by the platform to render a
56
+ * domain-neutral Candidate Change Set editor. The platform never interprets
57
+ * the field keys or embeds domain rules of its own.
58
+ */
59
+ export interface EvolutionCandidateFormDescriptor {
60
+ description?: I18nText;
61
+ fields: EvolutionCandidateChangeFieldDescriptor[];
62
+ }
63
+ export interface EvolutionTargetDescriptor {
64
+ targetId: string;
65
+ targetType: EvolutionTargetType;
66
+ displayName: string;
67
+ providerKey: string;
68
+ providerVersion: string;
69
+ artifactSchemaVersion: string;
70
+ supportedScopes: EvolutionScopeType[];
71
+ riskLevel: EvolutionRiskLevel;
72
+ metricSetId: string;
73
+ relatedTargetIds?: string[];
74
+ candidateForm?: EvolutionCandidateFormDescriptor;
75
+ capabilities: EvolutionTargetCapabilities;
76
+ status: 'active' | 'disabled' | 'provider_unavailable';
77
+ }
78
+ export interface EvolutionArtifactRef {
79
+ uri: string;
80
+ hash: string;
81
+ schemaVersion: string;
82
+ mediaType: 'application/json';
83
+ }
package/src/ai/index.d.ts CHANGED
@@ -26,9 +26,11 @@ export * from './feature.model';
26
26
  export * from './membership.model';
27
27
  export * from './model-access.model';
28
28
  export * from './model-gateway.model';
29
+ export * from './model-usage.model';
29
30
  export * from './rag';
30
31
  export * from './rag-web';
31
32
  export * from './knowledgebase.model';
33
+ export * from './knowledge-filter.model';
32
34
  export * from './knowledge-doc.model';
33
35
  export * from './knowledge-doc-page.model';
34
36
  export * from './role-permissions';
@@ -65,3 +67,4 @@ export * from './context-compression.model';
65
67
  export * from './sandbox';
66
68
  export * from './message-content.utils';
67
69
  export * from './mobile.model';
70
+ export * from './evolution';
@@ -11,6 +11,134 @@ export type TDocumentAsset = {
11
11
  order?: number;
12
12
  altText?: string;
13
13
  };
14
+ /** Stable, provider-neutral layout categories understood by the preview UI. */
15
+ export type DocumentAnalysisBlockType = 'text' | 'title' | 'table' | 'image' | 'formula' | 'header' | 'footer' | 'footnote' | 'page-number' | 'seal' | 'other';
16
+ /** Rectangle in the transformer-reported page coordinate system; values are not normalized to 0..1. */
17
+ export type DocumentAnalysisBounds = {
18
+ x: number;
19
+ y: number;
20
+ width: number;
21
+ height: number;
22
+ };
23
+ /** Polygon vertex in the transformer-reported page coordinate system. */
24
+ export type DocumentAnalysisPoint = {
25
+ x: number;
26
+ y: number;
27
+ };
28
+ /**
29
+ * Provider-neutral page-layout metadata emitted by a document transformer before text splitting.
30
+ * Coordinates use the top-left of the recognized page as their origin.
31
+ */
32
+ export type DocumentLayoutMetadata = {
33
+ schemaVersion: 1;
34
+ /** Global, 1-based source-document page number, including documents converted in batches. */
35
+ page: number;
36
+ /** Provider-reported page dimensions used to project bounds over the rendered source page. */
37
+ pageWidth: number;
38
+ pageHeight: number;
39
+ /** Stable identifier and reading order before downstream text splitting. */
40
+ blockId: string;
41
+ order: number;
42
+ type: DocumentAnalysisBlockType;
43
+ providerType?: string;
44
+ providerSubType?: string;
45
+ bounds?: DocumentAnalysisBounds;
46
+ polygon?: DocumentAnalysisPoint[];
47
+ /** Optional archived image/table asset associated with this exact layout block. */
48
+ asset?: TDocumentAsset;
49
+ /** Lossless provider payload retained for inspection; consumers must not assume its schema. */
50
+ raw?: Record<string, unknown>;
51
+ };
52
+ /** Provider-neutral description of the structured document produced by a transformer. */
53
+ export type DocumentAnalysisMetadata = {
54
+ schemaVersion: 1;
55
+ provider: string;
56
+ engine?: string;
57
+ pageCount?: number;
58
+ coordinateSystem: 'page-top-left';
59
+ markdownAsset?: TDocumentAsset;
60
+ /** Provider-neutral page/block payload used to materialize the protected analysis preview. */
61
+ analysisAsset?: TDocumentAsset;
62
+ /** Durable offset map from the merged Markdown back to source pages and layout blocks. */
63
+ sourceMapAsset?: TDocumentAsset;
64
+ rawAssets?: TDocumentAsset[];
65
+ };
66
+ /** One source block archived before the converter merges layout fragments into Markdown. */
67
+ export type DocumentAnalysisSourceBlock = {
68
+ id: string;
69
+ order: number;
70
+ type: DocumentAnalysisBlockType;
71
+ providerType?: string;
72
+ providerSubType?: string;
73
+ markdown: string;
74
+ bounds?: DocumentAnalysisBounds;
75
+ polygon?: DocumentAnalysisPoint[];
76
+ asset?: TDocumentAsset;
77
+ raw?: Record<string, unknown>;
78
+ };
79
+ /** Provider-neutral page record stored by a document converter for later preview materialization. */
80
+ export type DocumentAnalysisSourcePage = {
81
+ schemaVersion: 1;
82
+ page: number;
83
+ width: number;
84
+ height: number;
85
+ blocks: DocumentAnalysisSourceBlock[];
86
+ };
87
+ /** File payload referenced by `DocumentAnalysisMetadata.analysisAsset`. */
88
+ export type DocumentAnalysisSource = {
89
+ schemaVersion: 1;
90
+ pages: DocumentAnalysisSourcePage[];
91
+ };
92
+ /** A character interval in merged Markdown and its corresponding source-document range. */
93
+ export type DocumentMarkdownSourceMapEntry = {
94
+ startOffset: number;
95
+ endOffset: number;
96
+ pageStart: number;
97
+ pageEnd: number;
98
+ blockIds?: string[];
99
+ assets?: TDocumentAsset[];
100
+ };
101
+ /** Ephemeral/durable source map consumed by splitters to restore page and asset provenance. */
102
+ export type DocumentMarkdownSourceMap = {
103
+ schemaVersion: 1;
104
+ entries: DocumentMarkdownSourceMapEntry[];
105
+ };
106
+ /** Read model returned for one block in the paged analysis-preview API. */
107
+ export type KnowledgeDocumentAnalysisBlock = {
108
+ id: string;
109
+ order: number;
110
+ type: DocumentAnalysisBlockType;
111
+ providerType?: string;
112
+ providerSubType?: string;
113
+ markdown: string;
114
+ bounds?: DocumentAnalysisBounds;
115
+ polygon?: DocumentAnalysisPoint[];
116
+ assetId?: string;
117
+ };
118
+ /** Self-contained page record loaded independently for large documents. */
119
+ export type KnowledgeDocumentAnalysisPage = {
120
+ schemaVersion: 1;
121
+ page: number;
122
+ width: number;
123
+ height: number;
124
+ markdown: string;
125
+ blocks: KnowledgeDocumentAnalysisBlock[];
126
+ };
127
+ /** Capability response; unavailable snapshots expose a reason instead of throwing during page setup. */
128
+ export type KnowledgeDocumentAnalysisPreview = {
129
+ available: false;
130
+ reason: 'missing' | 'stale' | 'corrupt' | 'unsupported';
131
+ } | {
132
+ available: true;
133
+ schemaVersion: 1;
134
+ provider: string;
135
+ engine?: string;
136
+ pageCount: number;
137
+ pages: number[];
138
+ sourceType?: string;
139
+ sourceMimeType?: string;
140
+ views: Array<'markdown' | 'structure' | 'tables' | 'images' | 'json'>;
141
+ };
14
142
  export interface IDocChunkMetadata {
15
143
  chunkId: string;
16
144
  parentId?: string | null;
@@ -27,6 +155,21 @@ export interface IDocChunkMetadata {
27
155
  * Associated assets like images, videos, etc.
28
156
  */
29
157
  assets?: TDocumentAsset[];
158
+ /** Explicit content discriminator so generic preprocessing does not flatten Markdown syntax. */
159
+ contentFormat?: 'text' | 'markdown';
160
+ /** Global source page for a chunk contained entirely within one page. */
161
+ page?: number;
162
+ /** Inclusive global source-page interval when a chunk spans multiple pages. */
163
+ pageStart?: number;
164
+ pageEnd?: number;
165
+ /** Stable pre-merge layout identifiers contributing content to this chunk. */
166
+ sourceBlockIds?: string[];
167
+ /** Pre-split offset map; splitters must consume it instead of copying it to every final chunk. */
168
+ markdownSourceMap?: DocumentMarkdownSourceMap;
169
+ /** Durable source-map asset retained after the inline pre-split map is consumed. */
170
+ sourceMapAsset?: TDocumentAsset;
171
+ /** Original structured layout before text splitting. */
172
+ documentLayout?: DocumentLayoutMetadata;
30
173
  /**
31
174
  * Whether the chunk is represented as a vector in the vector store
32
175
  */