-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanswer-graph-generation.ts
More file actions
134 lines (121 loc) · 4.08 KB
/
Copy pathanswer-graph-generation.ts
File metadata and controls
134 lines (121 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import type {
AlertLevel,
ClaimConfidenceLevel,
CounterpointRelationKind,
ClaimRecencyStatus,
ClaimSupportKind,
PropagationStepKind,
SourceSnapshotType,
} from "@prisma/client";
import type { AnswerGraphJson } from "@/types/answer-graph";
import type { SourceCandidate } from "@/types/source-intake";
import type { InvestigationMode } from "@/server/analysis/investigation-limits";
/** Input for generating graph + evidence payload for a single analysis run. */
export type GenerateAnswerGraphInput = {
question: string;
sourceCandidates?: SourceCandidate[];
mode?: InvestigationMode;
};
/** One source row to persist as `source_snapshots` (order preserved). */
export type GeneratedSourceSnapshot = {
label: string;
sourceType: SourceSnapshotType;
url: string | null;
excerpt: string | null;
publishedAt?: Date | null;
};
export type GeneratedClaimSupportInput = {
sourcePlaceholderId: string;
supportKind: ClaimSupportKind;
isPrimarySource?: boolean;
supportingQuote?: string | null;
contradictionNote?: string | null;
};
export type GeneratedClaimConfidenceInput = {
score: number;
level: ClaimConfidenceLevel;
summary: string;
hasPrimarySource: boolean;
independentSourceCount: number;
hasSupportingQuote: boolean;
recencyStatus: ClaimRecencyStatus;
hasContradiction: boolean;
};
export type GeneratedCounterpointInput = {
summary: string;
relationKind?: CounterpointRelationKind;
graphNodeId?: string | null;
};
export type GeneratedPropagationChainStepInput = {
stepKind: PropagationStepKind;
order: number;
label: string;
detail?: string | null;
sourcePlaceholderId?: string | null;
claimGraphNodeId?: string | null;
answerSegmentKey?: string | null;
};
/** One claim row + graph node id + source placeholders (`__src_0__`, …) before persist. */
export type GeneratedEvidenceClaimInput = {
summary: string;
graphNodeId: string | null;
/** Legacy path; converted into direct supports when `supports` is omitted. */
supportedSourcePlaceholderIds: string[];
/** Preferred normalized support relations for this claim. */
supports?: GeneratedClaimSupportInput[];
/** Explainable confidence for this claim. */
confidence?: GeneratedClaimConfidenceInput;
/** When set, persisted as `counterpoints` rows for this claim. */
counterpoints?: GeneratedCounterpointInput[];
/** Ordered provenance/explanation chain for this claim. */
propagationChain?: GeneratedPropagationChainStepInput[];
/** When set, persisted as `alerts` rows with this claim's id. */
alerts?: { level: AlertLevel; message: string }[];
};
/** Optional structured evidence rows; omit for minimal stub runs. */
export type GeneratedEvidenceBundle = {
claims: GeneratedEvidenceClaimInput[];
/**
* Legacy: one counterargument applied to the first claim when that claim has no `counterpoints`.
* Prefer per-claim `counterpoints` on each `claims[]` entry.
*/
counterpoint?: {
summary: string;
};
/**
* Legacy: answer-scoped alert (`alerts.claim_id` null). Prefer per-claim `alerts` on `claims[]`.
*/
alert?: {
level: AlertLevel;
message: string;
};
};
/** Persistable result of a successful generation step (DB writer consumes this). */
/**
* provider出力を永続化用へ正規化した中間payload。
* graphJsonは描画スナップショットで、claim/source実体は別テーブルへ保存される。
*/
export type GeneratedAnswerGraphPayload = {
answer: {
title: string | null;
model: string | null;
content: string;
graphJson: AnswerGraphJson;
};
sources: GeneratedSourceSnapshot[];
evidence?: GeneratedEvidenceBundle;
};
export type GenerateAnswerGraphSuccess = {
kind: "success";
payload: GeneratedAnswerGraphPayload;
};
export type GenerateAnswerGraphFailure = {
kind: "failure";
/** Safe-for-UI message; also persisted on `analysis_runs.last_error_message` when the run fails. */
errorMessage: string;
/** Optional detail for server logs only (not stored by default). */
cause?: unknown;
};
export type GenerateAnswerGraphResult =
| GenerateAnswerGraphSuccess
| GenerateAnswerGraphFailure;