diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index e638be4..d0762d6 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -172,7 +172,9 @@ in only after reading its terms, and only on a deployment whose callers you trust: the daily caps (200 answers per caller, 500 upstream calls per provider) and the 5-minute shared cache are per process, and a caller is the address `clientKey()` sees. The public preview runs no broker, so it uses no house key; -turning one on there is an owner decision under this checklist. +turning one on there is an owner decision under this checklist. FRED's terms require +every app other people use to show its notice and a link to its API terms; each +FRED block and the FRED install review do (`attribution` in `curatedApis.ts`). ### Connect (OAuth sign-in) diff --git a/src/blocks/capability/CapabilityBlock.tsx b/src/blocks/capability/CapabilityBlock.tsx index f98b19c..963530c 100644 --- a/src/blocks/capability/CapabilityBlock.tsx +++ b/src/blocks/capability/CapabilityBlock.tsx @@ -15,6 +15,8 @@ import { EffectPill } from '@/components/apis/ApiReview'; import { KeyField, keySlotOf, useHasKey, useHouseKeyCovers } from '@/components/apis/KeyField'; import { useRememberingKeys } from '@/components/apis/RememberKeys'; import { SignInPrompt, useSignIn } from '@/components/apis/SignIn'; +import { ProviderAttribution } from '@/components/apis/ProviderAttribution'; +import { attributionFor } from '@/core/capabilities/curatedApis'; import { argumentsFrom, CapabilityInputs, constantOf, inputSummaryOf, missingInputs } from './CapabilityInputs'; import { CapabilityResult } from './CapabilityResult'; @@ -97,6 +99,8 @@ export function CapabilityBlockView({ instanceId }: { instanceId: string }) { const signIn = useSignIn(manifest); const needsSignIn = signIn !== null && !signIn.signedIn; const needsCredential = needsKey || needsSignIn; + // A provider whose terms require a notice on every app screen that uses it (FRED). + const attribution = attributionFor(manifest); const sideEffect = manifest?.effect === 'write' || manifest?.effect === 'destructive'; const params = isPlainParams(block?.params) ? block.params : {}; @@ -271,6 +275,7 @@ export function CapabilityBlockView({ instanceId }: { instanceId: string }) {
) : null} + {attribution ?{previewError}
) : null} diff --git a/src/blocks/capability/ProviderAttribution.component.test.tsx b/src/blocks/capability/ProviderAttribution.component.test.tsx new file mode 100644 index 0000000..0a052e7 --- /dev/null +++ b/src/blocks/capability/ProviderAttribution.component.test.tsx @@ -0,0 +1,51 @@ +// @vitest-environment happy-dom +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; +import { render, screen } from '@testing-library/react'; +import { CapabilityBlockView } from './CapabilityBlock'; +import { attributionFor, curatedApi } from '@/core/capabilities/curatedApis'; +import { compileOpenApi } from '@/core/capabilities/openapi'; +import { clearCapabilities, installProposal } from '@/core/capabilities/registry'; +import { blockRegistry } from '@/core/registry/BlockRegistry'; +import { useBlockStore, useWireStore } from '@/core/stores'; + +const NOTICE = 'This product uses the FRED® API but is not endorsed or certified by the Federal Reserve Bank of St. Louis.'; + +function fredManifests() { + const fred = curatedApi('omni:fred')!; + return compileOpenApi(fred.spec, { sourceLocator: fred.entry.specUrl, brokerOrigins: fred.brokerOrigins }).manifests; +} + +beforeEach(() => { + clearCapabilities(); + useBlockStore.setState({ blocks: [], activeShellId: 'root' }); + useWireStore.setState({ wires: [] }); +}); +afterEach(() => { + clearCapabilities(); + useBlockStore.setState({ blocks: [] }); +}); + +describe('FRED attribution', () => { + it('applies to every FRED operation, by its origin, however it was installed', () => { + for (const manifest of fredManifests()) expect(attributionFor(manifest)?.notice).toBe(NOTICE); + const pasted = compileOpenApi(curatedApi('omni:fred')!.spec).manifests[0]; + expect(attributionFor(pasted)?.notice).toBe(NOTICE); + }); + + it('does not apply to other APIs', () => { + const metaculus = curatedApi('omni:metaculus')!; + const [manifest] = compileOpenApi(metaculus.spec, { brokerOrigins: metaculus.brokerOrigins }).manifests; + expect(attributionFor(manifest)).toBeNull(); + }); + + it('shows the notice and the terms link on a FRED block, before any run', () => { + const [manifest] = fredManifests(); + expect(installProposal(manifest).ok).toBe(true); + const instanceId = useBlockStore.getState().addBlock(blockRegistry.get(manifest.id)!, { x: 0, y: 0 }); + render(These operations read your own account, so they need a sign-in with read-only access. Place them, then sign in from the block. diff --git a/src/components/apis/ProviderAttribution.tsx b/src/components/apis/ProviderAttribution.tsx new file mode 100644 index 0000000..526c845 --- /dev/null +++ b/src/components/apis/ProviderAttribution.tsx @@ -0,0 +1,19 @@ +'use client'; + +import type { Attribution } from '@/core/capabilities/curatedApis'; + +/** + * What a provider's terms require an app to show (FRED's notice and terms + * link), in the provider's own words. Not collapsible: the terms ask for it + * to be shown prominently. + */ +export function ProviderAttribution({ attribution }: { attribution: Attribution }) { + return ( +
+ {attribution.notice} Using this block means agreeing to the{' '} + + {attribution.termsTitle} + . +
+ ); +} diff --git a/src/core/capabilities/curatedApis.ts b/src/core/capabilities/curatedApis.ts index 38d17b1..a07b934 100644 --- a/src/core/capabilities/curatedApis.ts +++ b/src/core/capabilities/curatedApis.ts @@ -5,6 +5,7 @@ import type { ApiIndexEntry } from './apiIndex'; import type { KeyGuide } from './keyGuide'; +import type { CapabilityManifest } from './manifest'; import { ALPHA_VANTAGE_SPEC } from './curated/alphaVantage'; import { BLS_SPEC } from './curated/bls'; import { FRED_SPEC } from './curated/fred'; @@ -20,6 +21,16 @@ export interface CuratedApi { keyGuide?: Omit