opentool 0.19.1 → 0.19.2
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.
|
@@ -6,6 +6,9 @@ type NewsPropositionStatus = NewsPropositionAnswer | "no_matching_event";
|
|
|
6
6
|
type NewsContinuationAction = "continue" | "skip" | "pause";
|
|
7
7
|
type NewsPredictionMarketMatchedMarket = {
|
|
8
8
|
marketId: string;
|
|
9
|
+
eventId?: string | null;
|
|
10
|
+
eventSlug?: string | null;
|
|
11
|
+
eventTitle?: string | null;
|
|
9
12
|
conditionId?: string | null;
|
|
10
13
|
title: string;
|
|
11
14
|
slug?: string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/adapters/news/signals.ts"],"names":[],"mappings":";AAAA,IAAM,4BAAA,GAA+B;AAiMrC,SAAS,2BAA2B,QAAA,EAAuC;AACzE,EAAA,MAAM,mBAAA,GAAsB,YAAY,UAAA,CAAW,KAAA;AACnD,EAAA,IAAI,CAAC,mBAAA,EAAqB;AACxB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,mBAAA;AACT;AAEO,SAAS,uBAAuB,QAAA,EAAkC;AACvE,EAAA,MAAM,KAAA,GAAQ,QAAA,IAAY,OAAA,CAAQ,GAAA,CAAI,oBAAA,IAAwB,4BAAA;AAC9D,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,MAAM,IAAI,MAAM,mCAAmC,CAAA;AAAA,EACrD;AACA,EAAA,MAAM,OAAA,GAAU,MAAM,IAAA,EAAK;AAC3B,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,MAAM,mCAAmC,CAAA;AAAA,EACrD;AACA,EAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AAClC;AAEA,SAAS,cAAc,KAAA,EAAkD;AACvE,EAAA,IAAI,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MAAA,EAAQ,sCAAA;AAAA,MACR,aAAa,IAAA,CAAK,IAAA;AAAA,MAClB,iBAAiB;AAAC,KACpB;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,KAAA;AAAA,IACT,MAAA,EAAQ,aAAA;AAAA,IACR,MAAA,EAAQ,CAAA,8BAAA,EAAiC,eAAA,CAAgB,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA,CAAA;AAAA,IACnE,aAAa,IAAA,CAAK,IAAA;AAAA,IAClB;AAAA,GACF;AACF;AAEO,IAAM,mBAAN,MAAuB;AAAA,EAI5B,WAAA,CAAY,MAAA,GAAiC,EAAC,EAAG;AAC/C,IAAA,IAAA,CAAK,WAAA,GAAc,sBAAA,CAAuB,MAAA,CAAO,WAAW,CAAA;AAC5D,IAAA,IAAA,CAAK,mBAAA,GAAsB,0BAAA,CAA2B,MAAA,CAAO,mBAAmB,CAAA;AAAA,EAClF;AAAA,EAEA,YACE,MAAA,EACA;AACA,IAAA,OAAO,oBAAA,CAAqB;AAAA,MAC1B,GAAG,MAAA;AAAA,MACH,aAAa,IAAA,CAAK,WAAA;AAAA,MAClB,qBAAqB,IAAA,CAAK;AAAA,KAC3B,CAAA;AAAA,EACH;AAAA,EAEA,kBACE,MAAA,EACA;AACA,IAAA,OAAO,0BAAA,CAA2B;AAAA,MAChC,GAAG,MAAA;AAAA,MACH,aAAa,IAAA,CAAK,WAAA;AAAA,MAClB,qBAAqB,IAAA,CAAK;AAAA,KAC3B,CAAA;AAAA,EACH;AACF","file":"index.js","sourcesContent":["const DEFAULT_OPENPOND_GATEWAY_URL = \"https://gateway.openpond.dev\";\n\nexport type NewsEventState =\n | \"monitoring\"\n | \"escalation\"\n | \"de_escalation\"\n | \"resolved\"\n | \"contradiction\";\n\nexport type NewsSignalValue =\n | \"none\"\n | \"escalation\"\n | \"de_escalation\"\n | \"resolved\"\n | \"contradiction\";\n\nexport type NewsPropositionAnswer = \"yes\" | \"no\" | \"unclear\";\nexport type NewsPropositionStatus = NewsPropositionAnswer | \"no_matching_event\";\nexport type NewsContinuationAction = \"continue\" | \"skip\" | \"pause\";\n\nexport type NewsPredictionMarketMatchedMarket = {\n marketId: string;\n conditionId?: string | null;\n title: string;\n slug?: string | null;\n category?: string | null;\n yesProbability?: number | null;\n noProbability?: number | null;\n leadingOutcome?: string | null;\n leadingProbability?: number | null;\n volume?: number | null;\n liquidity?: number | null;\n openInterest?: number | null;\n probabilityDelta1h?: number | null;\n probabilityDelta24h?: number | null;\n fetchedAt: string;\n};\n\nexport type NewsPredictionMarketContext = {\n matchedMarkets: NewsPredictionMarketMatchedMarket[];\n consensusProbability?: number | null;\n probabilityDelta1h?: number | null;\n probabilityDelta24h?: number | null;\n liquidityWeightedScore?: number | null;\n predictionDisagreementScore?: number | null;\n dataAgeMs?: number | null;\n} | null;\n\nexport type NewsSignalEvidence = {\n articleId: string;\n sourceId: string;\n sourceName: string;\n title: string;\n canonicalUrl: string;\n claimType: string;\n claimPolarity: string;\n evidenceConfidence: number;\n evidenceAt: string;\n summary?: string | null;\n contentPreview?: string | null;\n};\n\nexport type NewsSignalConfidenceBreakdown = {\n baseScore: number;\n winningBucketScore: number;\n opposingPenalty: number;\n contradictionPenalty: number;\n stateBonus: number;\n finalScore: number;\n};\n\nexport type NewsEventSignalPolicy = {\n minConfidence: number;\n minIndependentSources: number;\n minTierASources: number;\n cooldownMinutes: number;\n allowedSourceIds?: string[];\n};\n\nexport type NewsEventSignal = {\n eventId: string;\n eventKey: string;\n title: string | null;\n eventState: NewsEventState;\n eventConfidence: number;\n confidenceBreakdown: NewsSignalConfidenceBreakdown;\n signal: NewsSignalValue;\n triggerPassed: boolean;\n policyRisk: \"low\" | \"medium\" | \"high\";\n effectivePolicy: NewsEventSignalPolicy;\n whyNotTriggered: string | null;\n warnings: string[];\n contradictionCount: number;\n supportingSourceCount: number;\n tierASourceCount: number;\n rebuttingSourceSummary: Array<{\n sourceId: string;\n sourceName: string;\n title: string;\n }>;\n evidence: NewsSignalEvidence[];\n dataAgeMs: number | null;\n predictionMarketContext: NewsPredictionMarketContext;\n};\n\nexport type NewsPropositionSignal = {\n question: string;\n query: string | null;\n propositionType: string | null;\n propositionStatus: NewsPropositionStatus;\n answer: NewsPropositionAnswer;\n propositionConfidence: number;\n reasoning: string;\n evidenceWindowSummary: string;\n resolvedEventId: string | null;\n resolvedEventKey: string | null;\n resolvedEventTitle: string | null;\n eventState: NewsEventState | null;\n eventConfidence: number | null;\n confidenceBreakdown: NewsSignalConfidenceBreakdown | null;\n supportingEvidence: NewsSignalEvidence[];\n rebuttingEvidence: NewsSignalEvidence[];\n supportingEvidenceArticleIds: string[];\n rebuttingEvidenceArticleIds: string[];\n operatorReviewRecommended: boolean;\n dataAgeMs: number | null;\n predictionMarketContext: NewsPredictionMarketContext;\n};\n\nexport type NewsEventSignalRequest = {\n gatewayBase?: string | null;\n fetchImplementation?: typeof fetch;\n query?: string;\n eventKey?: string;\n asOf?: string | Date | null;\n includePredictionMarkets?: boolean;\n ingestOnRequest?: boolean;\n maxAgeHours?: number;\n minConfidence?: number;\n minIndependentSources?: number;\n minTierASources?: number;\n};\n\nexport type NewsPropositionSignalRequest = {\n gatewayBase?: string | null;\n fetchImplementation?: typeof fetch;\n question: string;\n query?: string;\n eventKey?: string;\n propositionType?: string;\n asOf?: string | Date | null;\n includePredictionMarkets?: boolean;\n ingestOnRequest?: boolean;\n maxAgeHours?: number;\n candidateLimit?: number;\n};\n\nexport type NewsSignalClientConfig = {\n gatewayBase?: string | null;\n fetchImplementation?: typeof fetch;\n};\n\nexport type NewsEventContinuationGate = {\n mode: \"event\";\n minConfidence?: number;\n maxDataAgeMs?: number;\n minIndependentSources?: number;\n minTierASources?: number;\n requireTriggerPassed?: boolean;\n onBlocked?: Exclude<NewsContinuationAction, \"continue\">;\n};\n\nexport type NewsPropositionContinuationGate = {\n mode: \"proposition\";\n expectedAnswer?: NewsPropositionAnswer;\n minConfidence?: number;\n maxDataAgeMs?: number;\n requireResolvedEvent?: boolean;\n onBlocked?: Exclude<NewsContinuationAction, \"continue\">;\n};\n\nexport type NewsContinuationGate =\n | NewsEventContinuationGate\n | NewsPropositionContinuationGate;\n\nexport type NewsContinuationGateResult = {\n allowed: boolean;\n action: NewsContinuationAction;\n reason: string;\n matchedRule: NewsContinuationGate[\"mode\"];\n blockingFactors: string[];\n};\n\nfunction resolveFetchImplementation(override?: typeof fetch): typeof fetch {\n const fetchImplementation = override ?? globalThis.fetch;\n if (!fetchImplementation) {\n throw new Error(\n \"No fetch implementation available. Provide one via NewsSignalClientConfig.fetchImplementation.\",\n );\n }\n return fetchImplementation;\n}\n\nexport function resolveNewsGatewayBase(override?: string | null): string {\n const value = override ?? process.env.OPENPOND_GATEWAY_URL ?? DEFAULT_OPENPOND_GATEWAY_URL;\n if (typeof value !== \"string\") {\n throw new Error(\"OPENPOND_GATEWAY_URL is required.\");\n }\n const trimmed = value.trim();\n if (!trimmed) {\n throw new Error(\"OPENPOND_GATEWAY_URL is required.\");\n }\n return trimmed.replace(/\\/$/, \"\");\n}\n\nfunction normalizeAsOf(value?: string | Date | null): string | undefined {\n if (value == null) return undefined;\n const date = value instanceof Date ? value : new Date(value);\n if (Number.isNaN(date.getTime())) {\n throw new Error(\"asOf must be a valid ISO-8601 datetime or Date.\");\n }\n return date.toISOString();\n}\n\nasync function postGatewayJson<T>(params: {\n path: string;\n body: Record<string, unknown>;\n gatewayBase?: string | null | undefined;\n fetchImplementation?: typeof fetch | undefined;\n}): Promise<T> {\n const gatewayBase = resolveNewsGatewayBase(params.gatewayBase);\n const fetchImplementation = resolveFetchImplementation(params.fetchImplementation);\n const response = await fetchImplementation(`${gatewayBase}${params.path}`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify(params.body),\n });\n const text = await response.text().catch(() => \"\");\n let payload: unknown = null;\n try {\n payload = text ? (JSON.parse(text) as unknown) : null;\n } catch {\n payload = text;\n }\n if (!response.ok) {\n throw new Error(\n `Gateway request failed (${response.status}) for ${params.path}: ${\n typeof payload === \"string\" && payload ? payload : \"no_body\"\n }`,\n );\n }\n return payload as T;\n}\n\nexport async function fetchNewsEventSignal(\n params: NewsEventSignalRequest,\n): Promise<NewsEventSignal> {\n if (!params.query?.trim() && !params.eventKey?.trim()) {\n throw new Error(\"query or eventKey is required.\");\n }\n\n return postGatewayJson<NewsEventSignal>({\n path: \"/v1/news/event-signal\",\n gatewayBase: params.gatewayBase,\n fetchImplementation: params.fetchImplementation,\n body: {\n ...(params.query?.trim() ? { query: params.query.trim() } : {}),\n ...(params.eventKey?.trim() ? { eventKey: params.eventKey.trim() } : {}),\n ...(normalizeAsOf(params.asOf) ? { asOf: normalizeAsOf(params.asOf) } : {}),\n ...(typeof params.includePredictionMarkets === \"boolean\"\n ? { includePredictionMarkets: params.includePredictionMarkets }\n : {}),\n ...(typeof params.ingestOnRequest === \"boolean\"\n ? { ingestOnRequest: params.ingestOnRequest }\n : {}),\n ...(typeof params.maxAgeHours === \"number\" ? { maxAgeHours: params.maxAgeHours } : {}),\n policy: {\n ...(typeof params.minConfidence === \"number\"\n ? { minConfidence: params.minConfidence }\n : {}),\n ...(typeof params.minIndependentSources === \"number\"\n ? { minIndependentSources: params.minIndependentSources }\n : {}),\n ...(typeof params.minTierASources === \"number\"\n ? { minTierASources: params.minTierASources }\n : {}),\n },\n },\n });\n}\n\nexport async function fetchNewsPropositionSignal(\n params: NewsPropositionSignalRequest,\n): Promise<NewsPropositionSignal> {\n const question = params.question.trim();\n if (!question) {\n throw new Error(\"question is required.\");\n }\n\n return postGatewayJson<NewsPropositionSignal>({\n path: \"/v1/news/event-proposition-signal\",\n gatewayBase: params.gatewayBase,\n fetchImplementation: params.fetchImplementation,\n body: {\n question,\n ...(params.query?.trim() ? { query: params.query.trim() } : {}),\n ...(params.eventKey?.trim() ? { eventKey: params.eventKey.trim() } : {}),\n ...(params.propositionType?.trim()\n ? { propositionType: params.propositionType.trim() }\n : {}),\n ...(normalizeAsOf(params.asOf) ? { asOf: normalizeAsOf(params.asOf) } : {}),\n ...(typeof params.includePredictionMarkets === \"boolean\"\n ? { includePredictionMarkets: params.includePredictionMarkets }\n : {}),\n ...(typeof params.ingestOnRequest === \"boolean\"\n ? { ingestOnRequest: params.ingestOnRequest }\n : {}),\n ...(typeof params.maxAgeHours === \"number\" ? { maxAgeHours: params.maxAgeHours } : {}),\n ...(typeof params.candidateLimit === \"number\"\n ? { candidateLimit: params.candidateLimit }\n : {}),\n },\n });\n}\n\nexport function evaluateNewsContinuationGate(\n signal: NewsEventSignal | NewsPropositionSignal,\n gate: NewsContinuationGate,\n): NewsContinuationGateResult {\n const blockedAction = gate.onBlocked ?? \"skip\";\n const blockingFactors: string[] = [];\n\n if (gate.mode === \"event\") {\n const eventSignal = signal as NewsEventSignal;\n if (gate.requireTriggerPassed !== false && !eventSignal.triggerPassed) {\n blockingFactors.push(\"trigger_not_passed\");\n }\n if (\n typeof gate.minConfidence === \"number\" &&\n eventSignal.eventConfidence < gate.minConfidence\n ) {\n blockingFactors.push(\"confidence_below_threshold\");\n }\n if (\n typeof gate.maxDataAgeMs === \"number\" &&\n typeof eventSignal.dataAgeMs === \"number\" &&\n eventSignal.dataAgeMs > gate.maxDataAgeMs\n ) {\n blockingFactors.push(\"signal_too_stale\");\n }\n if (\n typeof gate.minIndependentSources === \"number\" &&\n eventSignal.supportingSourceCount < gate.minIndependentSources\n ) {\n blockingFactors.push(\"insufficient_supporting_sources\");\n }\n if (\n typeof gate.minTierASources === \"number\" &&\n eventSignal.tierASourceCount < gate.minTierASources\n ) {\n blockingFactors.push(\"insufficient_tier_a_sources\");\n }\n } else {\n const propositionSignal = signal as NewsPropositionSignal;\n if (\n gate.requireResolvedEvent !== false &&\n propositionSignal.propositionStatus === \"no_matching_event\"\n ) {\n blockingFactors.push(\"no_matching_event\");\n }\n if (\n gate.expectedAnswer &&\n propositionSignal.answer !== gate.expectedAnswer\n ) {\n blockingFactors.push(\"unexpected_answer\");\n }\n if (\n typeof gate.minConfidence === \"number\" &&\n propositionSignal.propositionConfidence < gate.minConfidence\n ) {\n blockingFactors.push(\"confidence_below_threshold\");\n }\n if (\n typeof gate.maxDataAgeMs === \"number\" &&\n typeof propositionSignal.dataAgeMs === \"number\" &&\n propositionSignal.dataAgeMs > gate.maxDataAgeMs\n ) {\n blockingFactors.push(\"signal_too_stale\");\n }\n }\n\n if (blockingFactors.length === 0) {\n return {\n allowed: true,\n action: \"continue\",\n reason: \"All continuation gate checks passed.\",\n matchedRule: gate.mode,\n blockingFactors: [],\n };\n }\n\n return {\n allowed: false,\n action: blockedAction,\n reason: `Blocked by continuation gate: ${blockingFactors.join(\", \")}.`,\n matchedRule: gate.mode,\n blockingFactors,\n };\n}\n\nexport class NewsSignalClient {\n private readonly gatewayBase: string;\n private readonly fetchImplementation: typeof fetch;\n\n constructor(config: NewsSignalClientConfig = {}) {\n this.gatewayBase = resolveNewsGatewayBase(config.gatewayBase);\n this.fetchImplementation = resolveFetchImplementation(config.fetchImplementation);\n }\n\n eventSignal(\n params: Omit<NewsEventSignalRequest, \"gatewayBase\" | \"fetchImplementation\">,\n ) {\n return fetchNewsEventSignal({\n ...params,\n gatewayBase: this.gatewayBase,\n fetchImplementation: this.fetchImplementation,\n });\n }\n\n propositionSignal(\n params: Omit<NewsPropositionSignalRequest, \"gatewayBase\" | \"fetchImplementation\">,\n ) {\n return fetchNewsPropositionSignal({\n ...params,\n gatewayBase: this.gatewayBase,\n fetchImplementation: this.fetchImplementation,\n });\n }\n}\n\nexport { DEFAULT_OPENPOND_GATEWAY_URL };\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/news/signals.ts"],"names":[],"mappings":";AAAA,IAAM,4BAAA,GAA+B;AAkMrC,SAAS,2BAA2B,QAAA,EAAuC;AACzE,EAAA,MAAM,mBAAA,GAAsB,YAAY,UAAA,CAAW,KAAA;AACnD,EAAA,IAAI,CAAC,mBAAA,EAAqB;AACxB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,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IAAA,CAAK,WAAA;AAAA,MAClB,qBAAqB,IAAA,CAAK;AAAA,KAC3B,CAAA;AAAA,EACH;AAAA,EAEA,kBACE,MAAA,EACA;AACA,IAAA,OAAO,0BAAA,CAA2B;AAAA,MAChC,GAAG,MAAA;AAAA,MACH,aAAa,IAAA,CAAK,WAAA;AAAA,MAClB,qBAAqB,IAAA,CAAK;AAAA,KAC3B,CAAA;AAAA,EACH;AACF","file":"index.js","sourcesContent":["const DEFAULT_OPENPOND_GATEWAY_URL = \"https://gateway.openpond.dev\";\n\nexport type NewsEventState =\n | \"monitoring\"\n | \"escalation\"\n | \"de_escalation\"\n | \"resolved\"\n | \"contradiction\";\n\nexport type NewsSignalValue =\n | \"none\"\n | \"escalation\"\n | \"de_escalation\"\n | \"resolved\"\n | \"contradiction\";\n\nexport type NewsPropositionAnswer = \"yes\" | \"no\" | \"unclear\";\nexport type NewsPropositionStatus = NewsPropositionAnswer | \"no_matching_event\";\nexport type NewsContinuationAction = \"continue\" | \"skip\" | \"pause\";\n\nexport type NewsPredictionMarketMatchedMarket = {\n marketId: string;\n eventId?: string | null;\n eventSlug?: string | null;\n eventTitle?: string | null;\n conditionId?: string | null;\n title: string;\n slug?: string | null;\n category?: string | null;\n yesProbability?: number | null;\n noProbability?: number | null;\n leadingOutcome?: string | null;\n leadingProbability?: number | null;\n volume?: number | null;\n liquidity?: number | null;\n openInterest?: number | null;\n probabilityDelta1h?: number | null;\n probabilityDelta24h?: number | null;\n fetchedAt: string;\n};\n\nexport type NewsPredictionMarketContext = {\n matchedMarkets: NewsPredictionMarketMatchedMarket[];\n consensusProbability?: number | null;\n probabilityDelta1h?: number | null;\n probabilityDelta24h?: number | null;\n liquidityWeightedScore?: number | null;\n predictionDisagreementScore?: number | null;\n dataAgeMs?: number | null;\n} | null;\n\nexport type NewsSignalEvidence = {\n articleId: string;\n sourceId: string;\n sourceName: string;\n title: string;\n canonicalUrl: string;\n claimType: string;\n claimPolarity: string;\n evidenceConfidence: number;\n evidenceAt: string;\n summary?: string | null;\n contentPreview?: string | null;\n};\n\nexport type NewsSignalConfidenceBreakdown = {\n baseScore: number;\n winningBucketScore: number;\n opposingPenalty: number;\n contradictionPenalty: number;\n stateBonus: number;\n finalScore: number;\n};\n\nexport type NewsEventSignalPolicy = {\n minConfidence: number;\n minIndependentSources: number;\n minTierASources: number;\n cooldownMinutes: number;\n allowedSourceIds?: string[];\n};\n\nexport type NewsEventSignal = {\n eventId: string;\n eventKey: string;\n title: string | null;\n eventState: NewsEventState;\n eventConfidence: number;\n confidenceBreakdown: NewsSignalConfidenceBreakdown;\n signal: NewsSignalValue;\n triggerPassed: boolean;\n policyRisk: \"low\" | \"medium\" | \"high\";\n effectivePolicy: NewsEventSignalPolicy;\n whyNotTriggered: string | null;\n warnings: string[];\n contradictionCount: number;\n supportingSourceCount: number;\n tierASourceCount: number;\n rebuttingSourceSummary: Array<{\n sourceId: string;\n sourceName: string;\n title: string;\n }>;\n evidence: NewsSignalEvidence[];\n dataAgeMs: number | null;\n predictionMarketContext: NewsPredictionMarketContext;\n};\n\nexport type NewsPropositionSignal = {\n question: string;\n query: string | null;\n propositionType: string | null;\n propositionStatus: NewsPropositionStatus;\n answer: NewsPropositionAnswer;\n propositionConfidence: number;\n reasoning: string;\n evidenceWindowSummary: string;\n resolvedEventId: string | null;\n resolvedEventKey: string | null;\n resolvedEventTitle: string | null;\n eventState: NewsEventState | null;\n eventConfidence: number | null;\n confidenceBreakdown: NewsSignalConfidenceBreakdown | null;\n supportingEvidence: NewsSignalEvidence[];\n rebuttingEvidence: NewsSignalEvidence[];\n supportingEvidenceArticleIds: string[];\n rebuttingEvidenceArticleIds: string[];\n operatorReviewRecommended: boolean;\n dataAgeMs: number | null;\n predictionMarketContext: NewsPredictionMarketContext;\n};\n\nexport type NewsEventSignalRequest = {\n gatewayBase?: string | null;\n fetchImplementation?: typeof fetch;\n query?: string;\n eventKey?: string;\n asOf?: string | Date | null;\n includePredictionMarkets?: boolean;\n ingestOnRequest?: boolean;\n maxAgeHours?: number;\n minConfidence?: number;\n minIndependentSources?: number;\n minTierASources?: number;\n};\n\nexport type NewsPropositionSignalRequest = {\n gatewayBase?: string | null;\n fetchImplementation?: typeof fetch;\n question: string;\n query?: string;\n eventKey?: string;\n propositionType?: string;\n asOf?: string | Date | null;\n includePredictionMarkets?: boolean;\n ingestOnRequest?: boolean;\n maxAgeHours?: number;\n candidateLimit?: number;\n};\n\nexport type NewsSignalClientConfig = {\n gatewayBase?: string | null;\n fetchImplementation?: typeof fetch;\n};\n\nexport type NewsEventContinuationGate = {\n mode: \"event\";\n minConfidence?: number;\n maxDataAgeMs?: number;\n minIndependentSources?: number;\n minTierASources?: number;\n requireTriggerPassed?: boolean;\n onBlocked?: Exclude<NewsContinuationAction, \"continue\">;\n};\n\nexport type NewsPropositionContinuationGate = {\n mode: \"proposition\";\n expectedAnswer?: NewsPropositionAnswer;\n minConfidence?: number;\n maxDataAgeMs?: number;\n requireResolvedEvent?: boolean;\n onBlocked?: Exclude<NewsContinuationAction, \"continue\">;\n};\n\nexport type NewsContinuationGate = NewsEventContinuationGate | NewsPropositionContinuationGate;\n\nexport type NewsContinuationGateResult = {\n allowed: boolean;\n action: NewsContinuationAction;\n reason: string;\n matchedRule: NewsContinuationGate[\"mode\"];\n blockingFactors: string[];\n};\n\nfunction resolveFetchImplementation(override?: typeof fetch): typeof fetch {\n const fetchImplementation = override ?? globalThis.fetch;\n if (!fetchImplementation) {\n throw new Error(\n \"No fetch implementation available. Provide one via NewsSignalClientConfig.fetchImplementation.\",\n );\n }\n return fetchImplementation;\n}\n\nexport function resolveNewsGatewayBase(override?: string | null): string {\n const value = override ?? process.env.OPENPOND_GATEWAY_URL ?? DEFAULT_OPENPOND_GATEWAY_URL;\n if (typeof value !== \"string\") {\n throw new Error(\"OPENPOND_GATEWAY_URL is required.\");\n }\n const trimmed = value.trim();\n if (!trimmed) {\n throw new Error(\"OPENPOND_GATEWAY_URL is required.\");\n }\n return trimmed.replace(/\\/$/, \"\");\n}\n\nfunction normalizeAsOf(value?: string | Date | null): string | undefined {\n if (value == null) return undefined;\n const date = value instanceof Date ? value : new Date(value);\n if (Number.isNaN(date.getTime())) {\n throw new Error(\"asOf must be a valid ISO-8601 datetime or Date.\");\n }\n return date.toISOString();\n}\n\nasync function postGatewayJson<T>(params: {\n path: string;\n body: Record<string, unknown>;\n gatewayBase?: string | null | undefined;\n fetchImplementation?: typeof fetch | undefined;\n}): Promise<T> {\n const gatewayBase = resolveNewsGatewayBase(params.gatewayBase);\n const fetchImplementation = resolveFetchImplementation(params.fetchImplementation);\n const response = await fetchImplementation(`${gatewayBase}${params.path}`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify(params.body),\n });\n const text = await response.text().catch(() => \"\");\n let payload: unknown = null;\n try {\n payload = text ? (JSON.parse(text) as unknown) : null;\n } catch {\n payload = text;\n }\n if (!response.ok) {\n throw new Error(\n `Gateway request failed (${response.status}) for ${params.path}: ${\n typeof payload === \"string\" && payload ? payload : \"no_body\"\n }`,\n );\n }\n return payload as T;\n}\n\nexport async function fetchNewsEventSignal(\n params: NewsEventSignalRequest,\n): Promise<NewsEventSignal> {\n if (!params.query?.trim() && !params.eventKey?.trim()) {\n throw new Error(\"query or eventKey is required.\");\n }\n\n return postGatewayJson<NewsEventSignal>({\n path: \"/v1/news/event-signal\",\n gatewayBase: params.gatewayBase,\n fetchImplementation: params.fetchImplementation,\n body: {\n ...(params.query?.trim() ? { query: params.query.trim() } : {}),\n ...(params.eventKey?.trim() ? { eventKey: params.eventKey.trim() } : {}),\n ...(normalizeAsOf(params.asOf) ? { asOf: normalizeAsOf(params.asOf) } : {}),\n ...(typeof params.includePredictionMarkets === \"boolean\"\n ? { includePredictionMarkets: params.includePredictionMarkets }\n : {}),\n ...(typeof params.ingestOnRequest === \"boolean\"\n ? { ingestOnRequest: params.ingestOnRequest }\n : {}),\n ...(typeof params.maxAgeHours === \"number\" ? { maxAgeHours: params.maxAgeHours } : {}),\n policy: {\n ...(typeof params.minConfidence === \"number\"\n ? { minConfidence: params.minConfidence }\n : {}),\n ...(typeof params.minIndependentSources === \"number\"\n ? { minIndependentSources: params.minIndependentSources }\n : {}),\n ...(typeof params.minTierASources === \"number\"\n ? { minTierASources: params.minTierASources }\n : {}),\n },\n },\n });\n}\n\nexport async function fetchNewsPropositionSignal(\n params: NewsPropositionSignalRequest,\n): Promise<NewsPropositionSignal> {\n const question = params.question.trim();\n if (!question) {\n throw new Error(\"question is required.\");\n }\n\n return postGatewayJson<NewsPropositionSignal>({\n path: \"/v1/news/event-proposition-signal\",\n gatewayBase: params.gatewayBase,\n fetchImplementation: params.fetchImplementation,\n body: {\n question,\n ...(params.query?.trim() ? { query: params.query.trim() } : {}),\n ...(params.eventKey?.trim() ? { eventKey: params.eventKey.trim() } : {}),\n ...(params.propositionType?.trim() ? { propositionType: params.propositionType.trim() } : {}),\n ...(normalizeAsOf(params.asOf) ? { asOf: normalizeAsOf(params.asOf) } : {}),\n ...(typeof params.includePredictionMarkets === \"boolean\"\n ? { includePredictionMarkets: params.includePredictionMarkets }\n : {}),\n ...(typeof params.ingestOnRequest === \"boolean\"\n ? { ingestOnRequest: params.ingestOnRequest }\n : {}),\n ...(typeof params.maxAgeHours === \"number\" ? { maxAgeHours: params.maxAgeHours } : {}),\n ...(typeof params.candidateLimit === \"number\"\n ? { candidateLimit: params.candidateLimit }\n : {}),\n },\n });\n}\n\nexport function evaluateNewsContinuationGate(\n signal: NewsEventSignal | NewsPropositionSignal,\n gate: NewsContinuationGate,\n): NewsContinuationGateResult {\n const blockedAction = gate.onBlocked ?? \"skip\";\n const blockingFactors: string[] = [];\n\n if (gate.mode === \"event\") {\n const eventSignal = signal as NewsEventSignal;\n if (gate.requireTriggerPassed !== false && !eventSignal.triggerPassed) {\n blockingFactors.push(\"trigger_not_passed\");\n }\n if (\n typeof gate.minConfidence === \"number\" &&\n eventSignal.eventConfidence < gate.minConfidence\n ) {\n blockingFactors.push(\"confidence_below_threshold\");\n }\n if (\n typeof gate.maxDataAgeMs === \"number\" &&\n typeof eventSignal.dataAgeMs === \"number\" &&\n eventSignal.dataAgeMs > gate.maxDataAgeMs\n ) {\n blockingFactors.push(\"signal_too_stale\");\n }\n if (\n typeof gate.minIndependentSources === \"number\" &&\n eventSignal.supportingSourceCount < gate.minIndependentSources\n ) {\n blockingFactors.push(\"insufficient_supporting_sources\");\n }\n if (\n typeof gate.minTierASources === \"number\" &&\n eventSignal.tierASourceCount < gate.minTierASources\n ) {\n blockingFactors.push(\"insufficient_tier_a_sources\");\n }\n } else {\n const propositionSignal = signal as NewsPropositionSignal;\n if (\n gate.requireResolvedEvent !== false &&\n propositionSignal.propositionStatus === \"no_matching_event\"\n ) {\n blockingFactors.push(\"no_matching_event\");\n }\n if (gate.expectedAnswer && propositionSignal.answer !== gate.expectedAnswer) {\n blockingFactors.push(\"unexpected_answer\");\n }\n if (\n typeof gate.minConfidence === \"number\" &&\n propositionSignal.propositionConfidence < gate.minConfidence\n ) {\n blockingFactors.push(\"confidence_below_threshold\");\n }\n if (\n typeof gate.maxDataAgeMs === \"number\" &&\n typeof propositionSignal.dataAgeMs === \"number\" &&\n propositionSignal.dataAgeMs > gate.maxDataAgeMs\n ) {\n blockingFactors.push(\"signal_too_stale\");\n }\n }\n\n if (blockingFactors.length === 0) {\n return {\n allowed: true,\n action: \"continue\",\n reason: \"All continuation gate checks passed.\",\n matchedRule: gate.mode,\n blockingFactors: [],\n };\n }\n\n return {\n allowed: false,\n action: blockedAction,\n reason: `Blocked by continuation gate: ${blockingFactors.join(\", \")}.`,\n matchedRule: gate.mode,\n blockingFactors,\n };\n}\n\nexport class NewsSignalClient {\n private readonly gatewayBase: string;\n private readonly fetchImplementation: typeof fetch;\n\n constructor(config: NewsSignalClientConfig = {}) {\n this.gatewayBase = resolveNewsGatewayBase(config.gatewayBase);\n this.fetchImplementation = resolveFetchImplementation(config.fetchImplementation);\n }\n\n eventSignal(params: Omit<NewsEventSignalRequest, \"gatewayBase\" | \"fetchImplementation\">) {\n return fetchNewsEventSignal({\n ...params,\n gatewayBase: this.gatewayBase,\n fetchImplementation: this.fetchImplementation,\n });\n }\n\n propositionSignal(\n params: Omit<NewsPropositionSignalRequest, \"gatewayBase\" | \"fetchImplementation\">,\n ) {\n return fetchNewsPropositionSignal({\n ...params,\n gatewayBase: this.gatewayBase,\n fetchImplementation: this.fetchImplementation,\n });\n }\n}\n\nexport { DEFAULT_OPENPOND_GATEWAY_URL };\n"]}
|