Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 9,121 Bytes
d15f07c | 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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | // API client for the policy-question registry (cross-jurisdiction policy
// questions + canonical arguments + comparative rollups).
import api from '../lib/api'
export interface PolicyQuestionSummary {
question_id: string
canonical_text: string | null
topic_code: string | null
primary_theme: string | null
cofog_code: string | null
scope: string | null
status: string | null
instances_total: number
jurisdictions_total: number
jurisdictions_approved: number
// Linked local decisions that adopted or recommended a moratorium (#483).
moratorium_count: number
// Curated "featured" questions (homepage "big questions"). `display_order`
// controls their sequence; both may be absent on older API responses.
is_featured?: boolean
display_order?: number | null
// Real money & talk (dbt policy_question mart). money_total = dollars moved by
// this question's local decisions; *_share = its slice of ALL civic decisions.
money_total?: number
money_share?: number
talk_share?: number
// Real meetings whose transcript discusses this question's alias keyword(s)
// (dbt question_transcript_link). A high-recall keyword signal — distinct from
// the structured decision instances — that powers the "discussed in N meetings"
// fallback for questions with no mapped decisions.
discussion_meeting_count?: number
}
// A real meeting whose transcript discusses the question's alias keyword(s).
export interface QuestionMeeting {
video_id: string
event_title: string | null
event_date: string | null
state_code: string | null
state: string | null
city: string | null
jurisdiction_name: string | null
video_url: string | null
n_alias_hits: number
// Verbatim transcript passage with the alias words wrapped in <mark> (ts_headline,
// built in dbt question_transcript_link, #499). Render with highlightSnippet.
evidence: string | null
start_seconds: number | null
// The recording at start_seconds; null when the transcript is untimed.
jump_url: string | null
}
// The rollup's outcome families (dbt macro question_outcome_family).
export type OutcomeFamily = 'approved' | 'denied' | 'moratorium' | 'deferred' | 'other'
export const OUTCOME_FAMILIES: OutcomeFamily[] = ['approved', 'denied', 'moratorium', 'deferred', 'other']
// The place scope every figure of a detail response is counted over (#499).
export interface QuestionScope {
level: 'national' | 'state' | 'city'
state_code: string | null
city: string | null
}
// A linked decision whose net_dollar_impact adds up to money_total.
export interface QuestionMoneySource {
event_decision_id: string
title: string | null
jurisdiction_name: string | null
state_code: string | null
outcome_family: OutcomeFamily | null
occurred_at: string | null
net_dollar_impact: number
}
// One quarter of a question's history (real). instances = how often it came up;
// money = net_dollar_impact of that quarter's linked local decisions.
export interface QuestionTrendPoint {
quarter_start: string
instances: number
money: number
}
export interface CanonicalArgument {
argument_id: string
stance: string | null
label: string | null
summary: string | null
source_role: string | null
frame_id: string | null
frame_label: string | null
member_count: number
}
export interface QuestionRollup {
instances_total: number
// Date range of the counted instances (#508 summary: "since May 2026").
first_occurred_at?: string | null
last_occurred_at?: string | null
decisions_total: number
bills_total: number
jurisdictions_total: number
jurisdictions_approved: number
states_total: number
approved_count: number
denied_count: number
deferred_count: number
moratorium_count: number
other_count: number
}
export interface QuestionInstance {
instance_id: string
source_type: string
source_id: string
state_code: string | null
jurisdiction_name: string | null
city: string | null
outcome_raw: string | null
outcome_normalized: string | null
outcome_family?: OutcomeFamily | null
occurred_at: string | null
assign_score: number | null
// #508: what was decided, where and who (built in dbt; null/empty for a bill).
event_decision_id?: string | null
headline?: string | null
// Street-level address that agrees with the decision's own government; null when none.
place_label?: string | null
// Companies named for the decision (its own text, or its meeting's passages), with the matched text.
company_names?: string[]
company_evidence?: string | null
company_mentions?: QuestionCompanyMention[]
// Tracked Epoch AI sites near the decision's government — NOT its subject.
nearby_sites?: QuestionNearbySite[]
}
// A company named for a decision: the exact words matched, and a verbatim excerpt with
// them in <mark> (render with highlightSnippet). evidence_source says where the words are:
// the decision's own text, or (#525) a passage of its own meeting, in which case jump_url
// opens the recording (at start_seconds, the passage's moment, when the transcript is timed).
export interface QuestionCompanyMention {
operator_name: string
matched_text: string
evidence: string | null
evidence_source?: 'decision_text' | 'meeting_passage'
start_seconds?: number | null
jump_url?: string | null
}
export interface QuestionNearbySite {
data_center_site_id: string
site_name: string | null
owner: string | null
}
export interface QuestionRelation {
relation_type: string
direction: string
evidence: string | null
question_id: string
canonical_text: string | null
scope: string | null
}
export interface PolicyQuestionDetail extends Omit<PolicyQuestionSummary, 'scope'> {
first_seen: string | null
// The question's level (local | state | both).
question_scope: string | null
// The place scope of every count / money / meeting figure below (#499).
scope: QuestionScope
rollup: QuestionRollup
// The decisions whose net_dollar_impact sums to money_total.
money_sources: QuestionMoneySource[]
// Browse Topics topic named like one of the question's aliases, if any.
topic_id: number | null
topic_name: string | null
arguments: CanonicalArgument[]
sample_instances: QuestionInstance[]
relations: QuestionRelation[]
// Per quarter, counted over the same scope (and outcome) as the rollup.
trend: QuestionTrendPoint[]
// With an outcome: the counts for that family only (the dashboard summary).
outcome?: OutcomeFamily | null
outcome_rollup?: QuestionRollup | null
}
export async function fetchPolicyQuestions(params?: {
theme?: string
scope?: string
limit?: number
// When true, request only the curated/featured questions (homepage
// "big questions" rail), ordered by display_order server-side.
featured?: boolean
}): Promise<PolicyQuestionSummary[]> {
const q = new URLSearchParams()
if (params?.theme) q.set('theme', params.theme)
if (params?.scope) q.set('scope', params.scope)
if (params?.limit) q.set('limit', String(params.limit))
if (params?.featured) q.set('featured', 'true')
const res = await api.get(`/policy-question/?${q.toString()}`)
return res.data
}
export interface QuestionPlaceScope {
state?: string
city?: string
}
const scopeParams = (scope?: QuestionPlaceScope) => {
const q = new URLSearchParams()
if (scope?.state) q.set('state', scope.state)
if (scope?.city) q.set('city', scope.city)
return q
}
// One question; with a state/city every count and the money figure are for that scope.
// With an outcome, outcome_rollup / trend / sample_instances are for that family too.
export async function fetchPolicyQuestion(
id: string,
scope?: QuestionPlaceScope & { outcome?: OutcomeFamily },
): Promise<PolicyQuestionDetail> {
const q = scopeParams(scope)
if (scope?.outcome) q.set('outcome', scope.outcome)
const qs = q.toString()
const res = await api.get(`/policy-question/${id}${qs ? `?${qs}` : ''}`)
return res.data
}
export async function fetchQuestionInstances(
id: string,
params: QuestionPlaceScope & {
outcome?: OutcomeFamily
order?: 'relevance' | 'recent'
limit?: number
offset?: number
} = {},
): Promise<QuestionInstance[]> {
const q = scopeParams(params)
if (params.outcome) q.set('outcome', params.outcome)
if (params.order) q.set('order', params.order)
q.set('limit', String(params.limit ?? 50))
q.set('offset', String(params.offset ?? 0))
const res = await api.get(`/policy-question/${id}/instances?${q.toString()}`)
return res.data
}
// Real meetings whose transcript discusses the question's alias keyword(s), newest
// first, scoped to the state/city. The scoped total is the detail's
// discussion_meeting_count.
export async function fetchQuestionMeetings(
id: string,
params: QuestionPlaceScope & { limit?: number; offset?: number } = {},
): Promise<QuestionMeeting[]> {
const q = scopeParams(params)
q.set('limit', String(params.limit ?? 50))
q.set('offset', String(params.offset ?? 0))
const res = await api.get(`/policy-question/${id}/meetings?${q.toString()}`)
return res.data
}
|