This guide explains how to integrate the PCN packages into your application: integration paths (Data360 preset vs custom data), dependencies, and what your app must provide.
- Framework: React 18+ (for UI). The core (
@pcn-js/core) can be used without React for HTML processing. - Data source: Use the Data360 preset for Data360 get_data, or wire your own tool/output shape with
@pcn-js/core+@pcn-js/ui. - Rendering: Use
ClaimMarkwhere you display claim values; optionally use Streamdown/react-markdown andstreamdownClaimComponentsfor<claim>tags in markdown. - Styling: Optional; import
@pcn-js/ui/styles.cssfor default claim/tooltip styles.
If your app uses the Data360 get_data API (tool results with claim_id, OBS_VALUE, REF_AREA, TIME_PERIOD):
- Install:
@pcn-js/core,@pcn-js/ui,@pcn-js/data360,react(andreact-domfor the UI). - Wrap your app in
Data360ClaimsProvider. - Ingest session data: use
IngestSessionData360withmessagesand optionalinitialMessages. - When rendering a data360 get_data tool result, wrap it in
IngestToolOutputwithtoolName={DATA360_GET_DATA_TOOL}. - Render claims with
ClaimMark(and optionallystreamdownClaimComponentsfor markdown). - Optional:
import "@pcn-js/ui/styles.css"for default styles.
See @pcn-js/data360 for full usage.
If your tool results have a different shape (different keys, multiple tools, or non–Data360 APIs):
- Install:
@pcn-js/core,@pcn-js/ui,react,react-dom. - Create a
ClaimsManagerand register one or more extractors (e.g.createDataPointExtractorfor array-of-points, or a custom(result) => ClaimEntry[]). - Wrap your app in
ClaimsProviderwith that manager. - When tool results arrive, call
manager.ingest(toolName, result)(or useIngestToolOutputwith your tool name). - Render claims with
ClaimMark(same as Path A). - Optional:
import "@pcn-js/ui/styles.css".
See @pcn-js/core (Claims manager, Data point extractor) and @pcn-js/ui.
| Package | Peer / runtime | Notes |
|---|---|---|
@pcn-js/core |
None (Node/browser) | Can be used without React for HTML/claims. |
@pcn-js/ui |
react ≥18, react-dom ≥18 |
React components and context. |
@pcn-js/data360 |
@pcn-js/core, @pcn-js/ui, react ≥18 |
Preset only; add if using Data360. |
- Build: Packages publish ESM + CJS and types; works with Vite, Next.js, Webpack, etc.
- No framework lock-in for core: Use
ClaimsManager,createDataPointExtractor,compareByPolicy,extractClaimsFromHtml,processPCNClaimsin any JS/TS app (including non-React).
- A React tree (for UI): So that
ClaimsProvider(orData360ClaimsProvider) andClaimMarkcan run. - Tool/output ingestion: When your backend or LLM returns tool results that contain claim data, you must either:
- Use
IngestToolOutputand render the tool result under it, or - Call
manager.ingest(toolName, result)yourself (e.g. fromuseEffector when messages update).
- Use
- Rendering of claim values: Where you display a number (or other claimable value), use
<ClaimMark id={claimId} policy={policy}>…</ClaimMark>. Theidmust match theclaim_id(or equivalent) produced by your extractor. - Message shape (if using session ingestion):
IngestSessionData360expects messages withparts(e.g. AI SDK / data-thinking). For other shapes, useextractData360Outputsor implement your own ingestion from messages.
Your tool might return something other than { data: [{ claim_id, OBS_VALUE, ... }] }. You can:
- Use
createDataPointExtractor(options)and map your keys:dataKey,claimIdKey,valueKey,countryKey,dateKey. Any key can be omitted. - Or implement a custom extractor:
(result: unknown) => ClaimEntry[], whereClaimEntryis{ id: string, claim: Claim }. Register it withmanager.registerExtractor(toolName, yourExtractor).
Claims are keyed by id; the UI looks up by that id in ClaimMark.
- Styles:
import "@pcn-js/ui/styles.css"for default claim and tooltip styles. You can omit it and style.pcn-claim,.verified-mark,.verify-pending,.pcn-claim-detailyourself. - Streamdown / react-markdown: Only if you render markdown that contains
<claim id="..." policy="rounded" decimals="2">…</claim>. UsestreamdownClaimComponentsorClaimMarkStreamdownfrom@pcn-js/ui. If claim tags do not render in production (0 claim nodes in DOM), see Troubleshooting. - Data360 package: Only if you use the Data360 get_data API; otherwise use core + ui and your own extractor.
If you depend on PCN via file:../../pcn/packages/... (e.g. in a monorepo):
- Build the PCN packages after changing them: from the PCN repo run
pnpm buildinpackages/core,packages/ui, and (if used)packages/data360. - In the consuming app, clear any bundler/cache (e.g. Next.js
.next) and reinstall if your package manager copies instead of symlinkingfile:deps. - Resolve peer warnings if needed (e.g. pnpm
peerDependencyRules.allowedVersionsfor@pcn-js/core/@pcn-js/uiwhen using file links).
| Concern | Supported? | Notes |
|---|---|---|
| Any React 18+ app | Yes | Use provider + ClaimMark + ingestion. |
| Non-React app | Core only | Use ClaimsManager, extractors, HTML helpers. |
| Data360 API | Yes | Use @pcn-js/data360 preset. |
| Other APIs/tools | Yes | Use core + ui + custom or data-point extractor. |
| Styling | Optional | Default CSS or your own. |
Markdown <claim> |
Optional | Use streamdown/react-markdown + streamdown components. |
| Tooltip / delay | Configurable | ClaimMark supports tooltipHideDelayMs. |