@agent-native/creative-context 0.0.0-beta-20260820202238
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.
- package/README.md +154 -0
- package/agent-native.eject.json +41 -0
- package/agent-native.package.json +119 -0
- package/dist/actions/confirm-canonical-logo.d.ts +6 -0
- package/dist/actions/confirm-canonical-logo.d.ts.map +1 -0
- package/dist/actions/confirm-canonical-logo.js +19 -0
- package/dist/actions/confirm-canonical-logo.js.map +1 -0
- package/dist/actions/continue-context-import.d.ts +22 -0
- package/dist/actions/continue-context-import.d.ts.map +1 -0
- package/dist/actions/continue-context-import.js +13 -0
- package/dist/actions/continue-context-import.js.map +1 -0
- package/dist/actions/creative-context-a2a.d.ts +10 -0
- package/dist/actions/creative-context-a2a.d.ts.map +1 -0
- package/dist/actions/creative-context-a2a.js +66 -0
- package/dist/actions/creative-context-a2a.js.map +1 -0
- package/dist/actions/get-brand-profile.d.ts +33 -0
- package/dist/actions/get-brand-profile.d.ts.map +1 -0
- package/dist/actions/get-brand-profile.js +13 -0
- package/dist/actions/get-brand-profile.js.map +1 -0
- package/dist/actions/get-context-import-status.d.ts +22 -0
- package/dist/actions/get-context-import-status.d.ts.map +1 -0
- package/dist/actions/get-context-import-status.js +12 -0
- package/dist/actions/get-context-import-status.js.map +1 -0
- package/dist/actions/get-context-item.d.ts +2 -0
- package/dist/actions/get-context-item.d.ts.map +1 -0
- package/dist/actions/get-context-item.js +2 -0
- package/dist/actions/get-context-item.js.map +1 -0
- package/dist/actions/get-context-pack.d.ts +7 -0
- package/dist/actions/get-context-pack.d.ts.map +1 -0
- package/dist/actions/get-context-pack.js +12 -0
- package/dist/actions/get-context-pack.js.map +1 -0
- package/dist/actions/get-creative-context.d.ts +157 -0
- package/dist/actions/get-creative-context.d.ts.map +1 -0
- package/dist/actions/get-creative-context.js +148 -0
- package/dist/actions/get-creative-context.js.map +1 -0
- package/dist/actions/get-google-picker-session.d.ts +10 -0
- package/dist/actions/get-google-picker-session.d.ts.map +1 -0
- package/dist/actions/get-google-picker-session.js +38 -0
- package/dist/actions/get-google-picker-session.js.map +1 -0
- package/dist/actions/index.d.ts +3 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +73 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/infer-brand-dna.d.ts +52 -0
- package/dist/actions/infer-brand-dna.d.ts.map +1 -0
- package/dist/actions/infer-brand-dna.js +13 -0
- package/dist/actions/infer-brand-dna.js.map +1 -0
- package/dist/actions/list-canonical-logo-candidates.d.ts +9 -0
- package/dist/actions/list-canonical-logo-candidates.d.ts.map +1 -0
- package/dist/actions/list-canonical-logo-candidates.js +82 -0
- package/dist/actions/list-canonical-logo-candidates.js.map +1 -0
- package/dist/actions/list-context-connections.d.ts +22 -0
- package/dist/actions/list-context-connections.d.ts.map +1 -0
- package/dist/actions/list-context-connections.js +43 -0
- package/dist/actions/list-context-connections.js.map +1 -0
- package/dist/actions/list-context-memberships.d.ts +11 -0
- package/dist/actions/list-context-memberships.d.ts.map +1 -0
- package/dist/actions/list-context-memberships.js +47 -0
- package/dist/actions/list-context-memberships.js.map +1 -0
- package/dist/actions/list-context-packs.d.ts +10 -0
- package/dist/actions/list-context-packs.d.ts.map +1 -0
- package/dist/actions/list-context-packs.js +16 -0
- package/dist/actions/list-context-packs.js.map +1 -0
- package/dist/actions/list-context-sources.d.ts +12 -0
- package/dist/actions/list-context-sources.d.ts.map +1 -0
- package/dist/actions/list-context-sources.js +20 -0
- package/dist/actions/list-context-sources.js.map +1 -0
- package/dist/actions/list-context-suggestions.d.ts +13 -0
- package/dist/actions/list-context-suggestions.d.ts.map +1 -0
- package/dist/actions/list-context-suggestions.js +28 -0
- package/dist/actions/list-context-suggestions.js.map +1 -0
- package/dist/actions/list-creative-contexts.d.ts +12 -0
- package/dist/actions/list-creative-contexts.d.ts.map +1 -0
- package/dist/actions/list-creative-contexts.js +28 -0
- package/dist/actions/list-creative-contexts.js.map +1 -0
- package/dist/actions/manage-brand-profile.d.ts +28 -0
- package/dist/actions/manage-brand-profile.d.ts.map +1 -0
- package/dist/actions/manage-brand-profile.js +47 -0
- package/dist/actions/manage-brand-profile.js.map +1 -0
- package/dist/actions/manage-context-membership.d.ts +64 -0
- package/dist/actions/manage-context-membership.d.ts.map +1 -0
- package/dist/actions/manage-context-membership.js +70 -0
- package/dist/actions/manage-context-membership.js.map +1 -0
- package/dist/actions/manage-context-pack.d.ts +36 -0
- package/dist/actions/manage-context-pack.d.ts.map +1 -0
- package/dist/actions/manage-context-pack.js +71 -0
- package/dist/actions/manage-context-pack.js.map +1 -0
- package/dist/actions/manage-context-source.d.ts +51 -0
- package/dist/actions/manage-context-source.d.ts.map +1 -0
- package/dist/actions/manage-context-source.js +130 -0
- package/dist/actions/manage-context-source.js.map +1 -0
- package/dist/actions/manage-creative-context.d.ts +28 -0
- package/dist/actions/manage-creative-context.d.ts.map +1 -0
- package/dist/actions/manage-creative-context.js +65 -0
- package/dist/actions/manage-creative-context.js.map +1 -0
- package/dist/actions/manage-layout-template.d.ts +13 -0
- package/dist/actions/manage-layout-template.d.ts.map +1 -0
- package/dist/actions/manage-layout-template.js +43 -0
- package/dist/actions/manage-layout-template.js.map +1 -0
- package/dist/actions/preview-context-import.d.ts +23 -0
- package/dist/actions/preview-context-import.d.ts.map +1 -0
- package/dist/actions/preview-context-import.js +57 -0
- package/dist/actions/preview-context-import.js.map +1 -0
- package/dist/actions/process-context-purge.d.ts +37 -0
- package/dist/actions/process-context-purge.d.ts.map +1 -0
- package/dist/actions/process-context-purge.js +20 -0
- package/dist/actions/process-context-purge.js.map +1 -0
- package/dist/actions/propose-brand-dna.d.ts +15 -0
- package/dist/actions/propose-brand-dna.d.ts.map +1 -0
- package/dist/actions/propose-brand-dna.js +19 -0
- package/dist/actions/propose-brand-dna.js.map +1 -0
- package/dist/actions/propose-canonical-logo.d.ts +9 -0
- package/dist/actions/propose-canonical-logo.d.ts.map +1 -0
- package/dist/actions/propose-canonical-logo.js +16 -0
- package/dist/actions/propose-canonical-logo.js.map +1 -0
- package/dist/actions/publish-brand-dna.d.ts +13 -0
- package/dist/actions/publish-brand-dna.d.ts.map +1 -0
- package/dist/actions/publish-brand-dna.js +23 -0
- package/dist/actions/publish-brand-dna.js.map +1 -0
- package/dist/actions/recommend-context-roots.d.ts +14 -0
- package/dist/actions/recommend-context-roots.d.ts.map +1 -0
- package/dist/actions/recommend-context-roots.js +22 -0
- package/dist/actions/recommend-context-roots.js.map +1 -0
- package/dist/actions/record-context-feedback.d.ts +10 -0
- package/dist/actions/record-context-feedback.d.ts.map +1 -0
- package/dist/actions/record-context-feedback.js +14 -0
- package/dist/actions/record-context-feedback.js.map +1 -0
- package/dist/actions/review-context-items.d.ts +35 -0
- package/dist/actions/review-context-items.d.ts.map +1 -0
- package/dist/actions/review-context-items.js +65 -0
- package/dist/actions/review-context-items.js.map +1 -0
- package/dist/actions/run-embedding-bakeoff.d.ts +15 -0
- package/dist/actions/run-embedding-bakeoff.d.ts.map +1 -0
- package/dist/actions/run-embedding-bakeoff.js +72 -0
- package/dist/actions/run-embedding-bakeoff.js.map +1 -0
- package/dist/actions/search-creative-context.d.ts +80 -0
- package/dist/actions/search-creative-context.d.ts.map +1 -0
- package/dist/actions/search-creative-context.js +42 -0
- package/dist/actions/search-creative-context.js.map +1 -0
- package/dist/actions/set-brand-dna.d.ts +15 -0
- package/dist/actions/set-brand-dna.d.ts.map +1 -0
- package/dist/actions/set-brand-dna.js +19 -0
- package/dist/actions/set-brand-dna.js.map +1 -0
- package/dist/actions/start-context-enrichment.d.ts +25 -0
- package/dist/actions/start-context-enrichment.d.ts.map +1 -0
- package/dist/actions/start-context-enrichment.js +48 -0
- package/dist/actions/start-context-enrichment.js.map +1 -0
- package/dist/actions/start-context-import.d.ts +24 -0
- package/dist/actions/start-context-import.d.ts.map +1 -0
- package/dist/actions/start-context-import.js +37 -0
- package/dist/actions/start-context-import.js.map +1 -0
- package/dist/client/CreativeContextChip.d.ts +18 -0
- package/dist/client/CreativeContextChip.d.ts.map +1 -0
- package/dist/client/CreativeContextChip.js +80 -0
- package/dist/client/CreativeContextChip.js.map +1 -0
- package/dist/client/CreativeContextPanel.d.ts +73 -0
- package/dist/client/CreativeContextPanel.d.ts.map +1 -0
- package/dist/client/CreativeContextPanel.js +1171 -0
- package/dist/client/CreativeContextPanel.js.map +1 -0
- package/dist/client/CreativeContextSettingsLink.d.ts +4 -0
- package/dist/client/CreativeContextSettingsLink.d.ts.map +1 -0
- package/dist/client/CreativeContextSettingsLink.js +8 -0
- package/dist/client/CreativeContextSettingsLink.js.map +1 -0
- package/dist/client/CreativeContextShareTab.d.ts +56 -0
- package/dist/client/CreativeContextShareTab.d.ts.map +1 -0
- package/dist/client/CreativeContextShareTab.js +213 -0
- package/dist/client/CreativeContextShareTab.js.map +1 -0
- package/dist/client/actions.d.ts +474 -0
- package/dist/client/actions.d.ts.map +1 -0
- package/dist/client/actions.js +411 -0
- package/dist/client/actions.js.map +1 -0
- package/dist/client/agent-tab.d.ts +10 -0
- package/dist/client/agent-tab.d.ts.map +1 -0
- package/dist/client/agent-tab.js +32 -0
- package/dist/client/agent-tab.js.map +1 -0
- package/dist/client/application-state.d.ts +24 -0
- package/dist/client/application-state.d.ts.map +1 -0
- package/dist/client/application-state.js +111 -0
- package/dist/client/application-state.js.map +1 -0
- package/dist/client/google-slides-picker.d.ts +19 -0
- package/dist/client/google-slides-picker.d.ts.map +1 -0
- package/dist/client/google-slides-picker.js +106 -0
- package/dist/client/google-slides-picker.js.map +1 -0
- package/dist/client/index.d.ts +10 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +10 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/messages.d.ts +5 -0
- package/dist/client/messages.d.ts.map +1 -0
- package/dist/client/messages.js +1158 -0
- package/dist/client/messages.js.map +1 -0
- package/dist/connectors/context.d.ts +9 -0
- package/dist/connectors/context.d.ts.map +1 -0
- package/dist/connectors/context.js +59 -0
- package/dist/connectors/context.js.map +1 -0
- package/dist/connectors/document-parser.d.ts +2 -0
- package/dist/connectors/document-parser.d.ts.map +1 -0
- package/dist/connectors/document-parser.js +2 -0
- package/dist/connectors/document-parser.js.map +1 -0
- package/dist/connectors/figma-native.d.ts +18 -0
- package/dist/connectors/figma-native.d.ts.map +1 -0
- package/dist/connectors/figma-native.js +883 -0
- package/dist/connectors/figma-native.js.map +1 -0
- package/dist/connectors/figma.d.ts +10 -0
- package/dist/connectors/figma.d.ts.map +1 -0
- package/dist/connectors/figma.js +166 -0
- package/dist/connectors/figma.js.map +1 -0
- package/dist/connectors/google-slides-native.d.ts +58 -0
- package/dist/connectors/google-slides-native.d.ts.map +1 -0
- package/dist/connectors/google-slides-native.js +1118 -0
- package/dist/connectors/google-slides-native.js.map +1 -0
- package/dist/connectors/google-slides.d.ts +15 -0
- package/dist/connectors/google-slides.d.ts.map +1 -0
- package/dist/connectors/google-slides.js +895 -0
- package/dist/connectors/google-slides.js.map +1 -0
- package/dist/connectors/index.d.ts +21 -0
- package/dist/connectors/index.d.ts.map +1 -0
- package/dist/connectors/index.js +45 -0
- package/dist/connectors/index.js.map +1 -0
- package/dist/connectors/manual.d.ts +9 -0
- package/dist/connectors/manual.d.ts.map +1 -0
- package/dist/connectors/manual.js +91 -0
- package/dist/connectors/manual.js.map +1 -0
- package/dist/connectors/normalize.d.ts +42 -0
- package/dist/connectors/normalize.d.ts.map +1 -0
- package/dist/connectors/normalize.js +335 -0
- package/dist/connectors/normalize.js.map +1 -0
- package/dist/connectors/notion.d.ts +10 -0
- package/dist/connectors/notion.d.ts.map +1 -0
- package/dist/connectors/notion.js +393 -0
- package/dist/connectors/notion.js.map +1 -0
- package/dist/connectors/private-artifacts.d.ts +39 -0
- package/dist/connectors/private-artifacts.d.ts.map +1 -0
- package/dist/connectors/private-artifacts.js +175 -0
- package/dist/connectors/private-artifacts.js.map +1 -0
- package/dist/connectors/provider-response.d.ts +20 -0
- package/dist/connectors/provider-response.d.ts.map +1 -0
- package/dist/connectors/provider-response.js +98 -0
- package/dist/connectors/provider-response.js.map +1 -0
- package/dist/connectors/recommendations.d.ts +25 -0
- package/dist/connectors/recommendations.d.ts.map +1 -0
- package/dist/connectors/recommendations.js +172 -0
- package/dist/connectors/recommendations.js.map +1 -0
- package/dist/connectors/registry.d.ts +10 -0
- package/dist/connectors/registry.d.ts.map +1 -0
- package/dist/connectors/registry.js +34 -0
- package/dist/connectors/registry.js.map +1 -0
- package/dist/connectors/rendered-design.d.ts +68 -0
- package/dist/connectors/rendered-design.d.ts.map +1 -0
- package/dist/connectors/rendered-design.js +362 -0
- package/dist/connectors/rendered-design.js.map +1 -0
- package/dist/connectors/rendered-page.d.ts +115 -0
- package/dist/connectors/rendered-page.d.ts.map +1 -0
- package/dist/connectors/rendered-page.js +1036 -0
- package/dist/connectors/rendered-page.js.map +1 -0
- package/dist/connectors/smart-defaults.d.ts +9 -0
- package/dist/connectors/smart-defaults.d.ts.map +1 -0
- package/dist/connectors/smart-defaults.js +72 -0
- package/dist/connectors/smart-defaults.js.map +1 -0
- package/dist/connectors/types.d.ts +79 -0
- package/dist/connectors/types.d.ts.map +1 -0
- package/dist/connectors/types.js +2 -0
- package/dist/connectors/types.js.map +1 -0
- package/dist/connectors/upload.d.ts +9 -0
- package/dist/connectors/upload.d.ts.map +1 -0
- package/dist/connectors/upload.js +440 -0
- package/dist/connectors/upload.js.map +1 -0
- package/dist/connectors/website.d.ts +20 -0
- package/dist/connectors/website.d.ts.map +1 -0
- package/dist/connectors/website.js +616 -0
- package/dist/connectors/website.js.map +1 -0
- package/dist/embeddings/index.d.ts +3 -0
- package/dist/embeddings/index.d.ts.map +1 -0
- package/dist/embeddings/index.js +3 -0
- package/dist/embeddings/index.js.map +1 -0
- package/dist/embeddings/providers.d.ts +2 -0
- package/dist/embeddings/providers.d.ts.map +1 -0
- package/dist/embeddings/providers.js +2 -0
- package/dist/embeddings/providers.js.map +1 -0
- package/dist/embeddings/types.d.ts +2 -0
- package/dist/embeddings/types.d.ts.map +1 -0
- package/dist/embeddings/types.js +2 -0
- package/dist/embeddings/types.js.map +1 -0
- package/dist/eval/acceptance-fixtures.d.ts +3 -0
- package/dist/eval/acceptance-fixtures.d.ts.map +1 -0
- package/dist/eval/acceptance-fixtures.js +84 -0
- package/dist/eval/acceptance-fixtures.js.map +1 -0
- package/dist/eval/acceptance.d.ts +114 -0
- package/dist/eval/acceptance.d.ts.map +1 -0
- package/dist/eval/acceptance.js +260 -0
- package/dist/eval/acceptance.js.map +1 -0
- package/dist/eval/fixtures.d.ts +16 -0
- package/dist/eval/fixtures.d.ts.map +1 -0
- package/dist/eval/fixtures.js +119 -0
- package/dist/eval/fixtures.js.map +1 -0
- package/dist/eval/index.d.ts +63 -0
- package/dist/eval/index.d.ts.map +1 -0
- package/dist/eval/index.js +174 -0
- package/dist/eval/index.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/jobs/background-worker.d.ts +31 -0
- package/dist/jobs/background-worker.d.ts.map +1 -0
- package/dist/jobs/background-worker.js +315 -0
- package/dist/jobs/background-worker.js.map +1 -0
- package/dist/jobs/import-runner.d.ts +3 -0
- package/dist/jobs/import-runner.d.ts.map +1 -0
- package/dist/jobs/import-runner.js +613 -0
- package/dist/jobs/import-runner.js.map +1 -0
- package/dist/jobs/index.d.ts +9 -0
- package/dist/jobs/index.d.ts.map +1 -0
- package/dist/jobs/index.js +8 -0
- package/dist/jobs/index.js.map +1 -0
- package/dist/jobs/progress.d.ts +3 -0
- package/dist/jobs/progress.d.ts.map +1 -0
- package/dist/jobs/progress.js +30 -0
- package/dist/jobs/progress.js.map +1 -0
- package/dist/jobs/rebuild.d.ts +13 -0
- package/dist/jobs/rebuild.d.ts.map +1 -0
- package/dist/jobs/rebuild.js +178 -0
- package/dist/jobs/rebuild.js.map +1 -0
- package/dist/jobs/server-worker.d.ts +16 -0
- package/dist/jobs/server-worker.d.ts.map +1 -0
- package/dist/jobs/server-worker.js +262 -0
- package/dist/jobs/server-worker.js.map +1 -0
- package/dist/jobs/store-adapter.d.ts +3 -0
- package/dist/jobs/store-adapter.d.ts.map +1 -0
- package/dist/jobs/store-adapter.js +37 -0
- package/dist/jobs/store-adapter.js.map +1 -0
- package/dist/jobs/types.d.ts +138 -0
- package/dist/jobs/types.d.ts.map +1 -0
- package/dist/jobs/types.js +2 -0
- package/dist/jobs/types.js.map +1 -0
- package/dist/jobs/worker.d.ts +27 -0
- package/dist/jobs/worker.d.ts.map +1 -0
- package/dist/jobs/worker.js +90 -0
- package/dist/jobs/worker.js.map +1 -0
- package/dist/media-url.d.ts +7 -0
- package/dist/media-url.d.ts.map +1 -0
- package/dist/media-url.js +15 -0
- package/dist/media-url.js.map +1 -0
- package/dist/native-artifact-reassembly.d.ts +25 -0
- package/dist/native-artifact-reassembly.d.ts.map +1 -0
- package/dist/native-artifact-reassembly.js +262 -0
- package/dist/native-artifact-reassembly.js.map +1 -0
- package/dist/native-artifact.d.ts +88 -0
- package/dist/native-artifact.d.ts.map +1 -0
- package/dist/native-artifact.js +86 -0
- package/dist/native-artifact.js.map +1 -0
- package/dist/schema/index.d.ts +7111 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +469 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/migrations.d.ts +10 -0
- package/dist/schema/migrations.d.ts.map +1 -0
- package/dist/schema/migrations.js +333 -0
- package/dist/schema/migrations.js.map +1 -0
- package/dist/search/fusion.d.ts +2 -0
- package/dist/search/fusion.d.ts.map +1 -0
- package/dist/search/fusion.js +2 -0
- package/dist/search/fusion.js.map +1 -0
- package/dist/search/mode.d.ts +4 -0
- package/dist/search/mode.d.ts.map +1 -0
- package/dist/search/mode.js +13 -0
- package/dist/search/mode.js.map +1 -0
- package/dist/search/postgres-fts.d.ts +2 -0
- package/dist/search/postgres-fts.d.ts.map +1 -0
- package/dist/search/postgres-fts.js +2 -0
- package/dist/search/postgres-fts.js.map +1 -0
- package/dist/server/brand-context.d.ts +15 -0
- package/dist/server/brand-context.d.ts.map +1 -0
- package/dist/server/brand-context.js +149 -0
- package/dist/server/brand-context.js.map +1 -0
- package/dist/server/context.d.ts +77 -0
- package/dist/server/context.d.ts.map +1 -0
- package/dist/server/context.js +63 -0
- package/dist/server/context.js.map +1 -0
- package/dist/server/enrichment.d.ts +24 -0
- package/dist/server/enrichment.d.ts.map +1 -0
- package/dist/server/enrichment.js +138 -0
- package/dist/server/enrichment.js.map +1 -0
- package/dist/server/generation-artifact-access.d.ts +21 -0
- package/dist/server/generation-artifact-access.d.ts.map +1 -0
- package/dist/server/generation-artifact-access.js +113 -0
- package/dist/server/generation-artifact-access.js.map +1 -0
- package/dist/server/generation-context.d.ts +220 -0
- package/dist/server/generation-context.d.ts.map +1 -0
- package/dist/server/generation-context.js +432 -0
- package/dist/server/generation-context.js.map +1 -0
- package/dist/server/index.d.ts +27 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +115 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/isolated-a2a.d.ts +175 -0
- package/dist/server/isolated-a2a.d.ts.map +1 -0
- package/dist/server/isolated-a2a.js +312 -0
- package/dist/server/isolated-a2a.js.map +1 -0
- package/dist/server/media.d.ts +15 -0
- package/dist/server/media.d.ts.map +1 -0
- package/dist/server/media.js +108 -0
- package/dist/server/media.js.map +1 -0
- package/dist/server/native-resource-capture.d.ts +78 -0
- package/dist/server/native-resource-capture.d.ts.map +1 -0
- package/dist/server/native-resource-capture.js +94 -0
- package/dist/server/native-resource-capture.js.map +1 -0
- package/dist/server/prompt-provider.d.ts +5 -0
- package/dist/server/prompt-provider.d.ts.map +1 -0
- package/dist/server/prompt-provider.js +59 -0
- package/dist/server/prompt-provider.js.map +1 -0
- package/dist/server/public-serialization.d.ts +160 -0
- package/dist/server/public-serialization.d.ts.map +1 -0
- package/dist/server/public-serialization.js +108 -0
- package/dist/server/public-serialization.js.map +1 -0
- package/dist/server/resource-paths.d.ts +3 -0
- package/dist/server/resource-paths.d.ts.map +1 -0
- package/dist/server/resource-paths.js +5 -0
- package/dist/server/resource-paths.js.map +1 -0
- package/dist/server/retrieval.d.ts +83 -0
- package/dist/server/retrieval.d.ts.map +1 -0
- package/dist/server/retrieval.js +445 -0
- package/dist/server/retrieval.js.map +1 -0
- package/dist/server/safe-native-preview.d.ts +15 -0
- package/dist/server/safe-native-preview.d.ts.map +1 -0
- package/dist/server/safe-native-preview.js +148 -0
- package/dist/server/safe-native-preview.js.map +1 -0
- package/dist/store/brand.d.ts +47 -0
- package/dist/store/brand.d.ts.map +1 -0
- package/dist/store/brand.js +346 -0
- package/dist/store/brand.js.map +1 -0
- package/dist/store/content.d.ts +134 -0
- package/dist/store/content.d.ts.map +1 -0
- package/dist/store/content.js +1677 -0
- package/dist/store/content.js.map +1 -0
- package/dist/store/contexts.d.ts +216 -0
- package/dist/store/contexts.d.ts.map +1 -0
- package/dist/store/contexts.js +1346 -0
- package/dist/store/contexts.js.map +1 -0
- package/dist/store/generation.d.ts +28 -0
- package/dist/store/generation.d.ts.map +1 -0
- package/dist/store/generation.js +140 -0
- package/dist/store/generation.js.map +1 -0
- package/dist/store/helpers.d.ts +12 -0
- package/dist/store/helpers.d.ts.map +1 -0
- package/dist/store/helpers.js +41 -0
- package/dist/store/helpers.js.map +1 -0
- package/dist/store/index.d.ts +11 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +11 -0
- package/dist/store/index.js.map +1 -0
- package/dist/store/inference.d.ts +57 -0
- package/dist/store/inference.d.ts.map +1 -0
- package/dist/store/inference.js +279 -0
- package/dist/store/inference.js.map +1 -0
- package/dist/store/jobs.d.ts +80 -0
- package/dist/store/jobs.d.ts.map +1 -0
- package/dist/store/jobs.js +428 -0
- package/dist/store/jobs.js.map +1 -0
- package/dist/store/native-artifact-summary.d.ts +7 -0
- package/dist/store/native-artifact-summary.d.ts.map +1 -0
- package/dist/store/native-artifact-summary.js +10 -0
- package/dist/store/native-artifact-summary.js.map +1 -0
- package/dist/store/packs.d.ts +36 -0
- package/dist/store/packs.d.ts.map +1 -0
- package/dist/store/packs.js +438 -0
- package/dist/store/packs.js.map +1 -0
- package/dist/store/purge.d.ts +16 -0
- package/dist/store/purge.d.ts.map +1 -0
- package/dist/store/purge.js +354 -0
- package/dist/store/purge.js.map +1 -0
- package/dist/store/sources.d.ts +76 -0
- package/dist/store/sources.d.ts.map +1 -0
- package/dist/store/sources.js +525 -0
- package/dist/store/sources.js.map +1 -0
- package/dist/store/suggestions.d.ts +29 -0
- package/dist/store/suggestions.d.ts.map +1 -0
- package/dist/store/suggestions.js +270 -0
- package/dist/store/suggestions.js.map +1 -0
- package/dist/types.d.ts +578 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/dist/untrusted-reference.d.ts +8 -0
- package/dist/untrusted-reference.d.ts.map +1 -0
- package/dist/untrusted-reference.js +19 -0
- package/dist/untrusted-reference.js.map +1 -0
- package/dist/vector/index.d.ts +2 -0
- package/dist/vector/index.d.ts.map +1 -0
- package/dist/vector/index.js +2 -0
- package/dist/vector/index.js.map +1 -0
- package/dist/vector/pgvector.d.ts +2 -0
- package/dist/vector/pgvector.d.ts.map +1 -0
- package/dist/vector/pgvector.js +2 -0
- package/dist/vector/pgvector.js.map +1 -0
- package/docs/evaluation.md +92 -0
- package/docs/llms-full.txt +168 -0
- package/docs/llms.txt +76 -0
- package/docs/skills/creative-context/SKILL.md +90 -0
- package/package.json +100 -0
- package/src/actions/agent-input-schemas.spec.ts +46 -0
- package/src/actions/confirm-canonical-logo.ts +20 -0
- package/src/actions/continue-context-import.ts +15 -0
- package/src/actions/creative-context-a2a.spec.ts +162 -0
- package/src/actions/creative-context-a2a.ts +88 -0
- package/src/actions/get-brand-profile.ts +16 -0
- package/src/actions/get-context-import-status.ts +13 -0
- package/src/actions/get-context-item.ts +1 -0
- package/src/actions/get-context-pack.ts +14 -0
- package/src/actions/get-creative-context.spec.ts +435 -0
- package/src/actions/get-creative-context.ts +197 -0
- package/src/actions/get-google-picker-session.spec.ts +62 -0
- package/src/actions/get-google-picker-session.ts +45 -0
- package/src/actions/index.ts +75 -0
- package/src/actions/infer-brand-dna.ts +15 -0
- package/src/actions/job-public-serialization.spec.ts +143 -0
- package/src/actions/list-canonical-logo-candidates.ts +121 -0
- package/src/actions/list-context-connections.spec.ts +23 -0
- package/src/actions/list-context-connections.ts +51 -0
- package/src/actions/list-context-memberships.ts +56 -0
- package/src/actions/list-context-packs.ts +17 -0
- package/src/actions/list-context-sources.ts +21 -0
- package/src/actions/list-context-suggestions.ts +30 -0
- package/src/actions/list-creative-contexts.spec.ts +38 -0
- package/src/actions/list-creative-contexts.ts +32 -0
- package/src/actions/manage-brand-profile.ts +58 -0
- package/src/actions/manage-context-membership.ts +80 -0
- package/src/actions/manage-context-pack.ts +81 -0
- package/src/actions/manage-context-source.ts +151 -0
- package/src/actions/manage-creative-context.ts +73 -0
- package/src/actions/manage-layout-template.ts +51 -0
- package/src/actions/preview-context-import.spec.ts +64 -0
- package/src/actions/preview-context-import.ts +61 -0
- package/src/actions/process-context-purge.ts +28 -0
- package/src/actions/propose-brand-dna.ts +22 -0
- package/src/actions/propose-canonical-logo.ts +19 -0
- package/src/actions/publish-brand-dna.ts +25 -0
- package/src/actions/recommend-context-roots.ts +24 -0
- package/src/actions/record-context-feedback.ts +16 -0
- package/src/actions/review-context-items.ts +69 -0
- package/src/actions/run-embedding-bakeoff.ts +90 -0
- package/src/actions/search-creative-context.ts +48 -0
- package/src/actions/set-brand-dna.ts +22 -0
- package/src/actions/start-context-enrichment.ts +52 -0
- package/src/actions/start-context-import.ts +38 -0
- package/src/client/CreativeContextChip.spec.ts +59 -0
- package/src/client/CreativeContextChip.tsx +243 -0
- package/src/client/CreativeContextPanel.tsx +3600 -0
- package/src/client/CreativeContextSettingsLink.tsx +30 -0
- package/src/client/CreativeContextShareTab.spec.ts +70 -0
- package/src/client/CreativeContextShareTab.tsx +666 -0
- package/src/client/actions.spec.ts +177 -0
- package/src/client/actions.ts +1024 -0
- package/src/client/agent-tab.tsx +56 -0
- package/src/client/application-state.spec.ts +46 -0
- package/src/client/application-state.ts +158 -0
- package/src/client/google-slides-picker.spec.ts +36 -0
- package/src/client/google-slides-picker.ts +146 -0
- package/src/client/index.ts +102 -0
- package/src/client/messages.ts +1370 -0
- package/src/client/source-config.spec.ts +166 -0
- package/src/connectors/connectors.spec.ts +778 -0
- package/src/connectors/context.ts +83 -0
- package/src/connectors/document-parser.ts +5 -0
- package/src/connectors/figma-native.ts +1192 -0
- package/src/connectors/figma-native.visual.spec.ts +221 -0
- package/src/connectors/figma.spec.ts +812 -0
- package/src/connectors/figma.ts +257 -0
- package/src/connectors/fixtures/google-slides-native.json +353 -0
- package/src/connectors/google-slides-native.spec.ts +804 -0
- package/src/connectors/google-slides-native.ts +1656 -0
- package/src/connectors/google-slides-native.visual.spec.ts +119 -0
- package/src/connectors/google-slides.ts +1171 -0
- package/src/connectors/index.ts +112 -0
- package/src/connectors/manual.ts +132 -0
- package/src/connectors/normalize.spec.ts +144 -0
- package/src/connectors/normalize.ts +475 -0
- package/src/connectors/notion.ts +529 -0
- package/src/connectors/private-artifacts.spec.ts +95 -0
- package/src/connectors/private-artifacts.ts +248 -0
- package/src/connectors/provider-response.ts +144 -0
- package/src/connectors/recommendations.ts +237 -0
- package/src/connectors/registry.ts +48 -0
- package/src/connectors/rendered-design.spec.ts +171 -0
- package/src/connectors/rendered-design.ts +495 -0
- package/src/connectors/rendered-page.spec.ts +388 -0
- package/src/connectors/rendered-page.ts +1387 -0
- package/src/connectors/smart-defaults.spec.ts +135 -0
- package/src/connectors/smart-defaults.ts +87 -0
- package/src/connectors/types.ts +113 -0
- package/src/connectors/upload.spec.ts +175 -0
- package/src/connectors/upload.ts +548 -0
- package/src/connectors/website.spec.ts +465 -0
- package/src/connectors/website.ts +777 -0
- package/src/embeddings/index.ts +2 -0
- package/src/embeddings/providers.spec.ts +73 -0
- package/src/embeddings/providers.ts +1 -0
- package/src/embeddings/types.ts +6 -0
- package/src/eval/acceptance-fixtures.ts +97 -0
- package/src/eval/acceptance.spec.ts +92 -0
- package/src/eval/acceptance.ts +371 -0
- package/src/eval/connectors-golden.spec.ts +421 -0
- package/src/eval/eval.spec.ts +166 -0
- package/src/eval/fixtures/README.md +17 -0
- package/src/eval/fixtures/figma-brand-system-v1.json +140 -0
- package/src/eval/fixtures/figma-brand-system-v2.json +127 -0
- package/src/eval/fixtures/launch-hero.png +0 -0
- package/src/eval/fixtures/launch-system-v1.pptx +0 -0
- package/src/eval/fixtures/launch-system-v2.pptx +0 -0
- package/src/eval/fixtures/notion-brand-root.json +218 -0
- package/src/eval/fixtures/pricing-hero.png +0 -0
- package/src/eval/fixtures/rendered-brand-page.html +76 -0
- package/src/eval/fixtures.spec.ts +43 -0
- package/src/eval/fixtures.ts +136 -0
- package/src/eval/index.ts +291 -0
- package/src/eval/library-flow.acceptance.spec.tsx +145 -0
- package/src/index.ts +4 -0
- package/src/jobs/background-worker.ts +423 -0
- package/src/jobs/import-runner.spec.ts +582 -0
- package/src/jobs/import-runner.ts +791 -0
- package/src/jobs/index.ts +40 -0
- package/src/jobs/progress.ts +37 -0
- package/src/jobs/rebuild.ts +245 -0
- package/src/jobs/server-worker.spec.ts +181 -0
- package/src/jobs/server-worker.ts +354 -0
- package/src/jobs/store-adapter.ts +52 -0
- package/src/jobs/types.ts +147 -0
- package/src/jobs/worker.ts +152 -0
- package/src/manifest.spec.ts +26 -0
- package/src/media-url.ts +17 -0
- package/src/native-artifact-reassembly.spec.ts +386 -0
- package/src/native-artifact-reassembly.ts +406 -0
- package/src/native-artifact.ts +102 -0
- package/src/schema/index.ts +527 -0
- package/src/schema/migrations.spec.ts +41 -0
- package/src/schema/migrations.ts +338 -0
- package/src/search/fusion.spec.ts +21 -0
- package/src/search/fusion.ts +1 -0
- package/src/search/mode.spec.ts +28 -0
- package/src/search/mode.ts +21 -0
- package/src/search/postgres-fts.spec.ts +63 -0
- package/src/search/postgres-fts.ts +1 -0
- package/src/server/brand-context.spec.ts +43 -0
- package/src/server/brand-context.ts +160 -0
- package/src/server/context.ts +162 -0
- package/src/server/enrichment.spec.ts +94 -0
- package/src/server/enrichment.ts +166 -0
- package/src/server/generation-artifact-access.spec.ts +104 -0
- package/src/server/generation-artifact-access.ts +217 -0
- package/src/server/generation-context-a2a.spec.ts +282 -0
- package/src/server/generation-context-off.spec.ts +213 -0
- package/src/server/generation-context.spec.ts +124 -0
- package/src/server/generation-context.ts +639 -0
- package/src/server/index.spec.ts +30 -0
- package/src/server/index.ts +163 -0
- package/src/server/isolated-a2a.spec.ts +184 -0
- package/src/server/isolated-a2a.ts +416 -0
- package/src/server/media.spec.ts +120 -0
- package/src/server/media.ts +136 -0
- package/src/server/native-resource-capture.spec.ts +121 -0
- package/src/server/native-resource-capture.ts +198 -0
- package/src/server/prompt-provider.spec.ts +78 -0
- package/src/server/prompt-provider.ts +73 -0
- package/src/server/public-serialization.spec.ts +150 -0
- package/src/server/public-serialization.ts +130 -0
- package/src/server/resource-paths.spec.ts +9 -0
- package/src/server/resource-paths.ts +5 -0
- package/src/server/retrieval-vector.spec.ts +180 -0
- package/src/server/retrieval.ts +590 -0
- package/src/server/safe-native-preview.spec.ts +29 -0
- package/src/server/safe-native-preview.ts +199 -0
- package/src/store/access.integration.spec.ts +3523 -0
- package/src/store/brand.ts +458 -0
- package/src/store/content.ts +2317 -0
- package/src/store/contexts.ts +1840 -0
- package/src/store/generation.ts +226 -0
- package/src/store/helpers.ts +53 -0
- package/src/store/index.ts +10 -0
- package/src/store/inference.spec.ts +84 -0
- package/src/store/inference.ts +339 -0
- package/src/store/invariants.spec.ts +119 -0
- package/src/store/jobs.ts +674 -0
- package/src/store/native-artifact-summary.ts +13 -0
- package/src/store/packs.ts +721 -0
- package/src/store/purge.ts +463 -0
- package/src/store/sources.spec.ts +102 -0
- package/src/store/sources.ts +692 -0
- package/src/store/suggestions.ts +361 -0
- package/src/types.ts +671 -0
- package/src/untrusted-reference.spec.ts +22 -0
- package/src/untrusted-reference.ts +24 -0
- package/src/vector/index.ts +1 -0
- package/src/vector/pgvector.spec.ts +115 -0
- package/src/vector/pgvector.ts +1 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { createGeminiEmbeddingFamily } from "./providers.js";
|
|
4
|
+
|
|
5
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
6
|
+
|
|
7
|
+
describe("Gemini embedding request contract", () => {
|
|
8
|
+
it("uses current REST dimension casing and retrieval prefixes", async () => {
|
|
9
|
+
const fetchMock = vi.fn(async (_url: string, init: RequestInit) => {
|
|
10
|
+
const body = JSON.parse(String(init.body));
|
|
11
|
+
return new Response(
|
|
12
|
+
JSON.stringify({ embedding: { values: [0.1, 0.2, 0.3] } }),
|
|
13
|
+
{ status: 200, headers: { "content-type": "application/json" } },
|
|
14
|
+
);
|
|
15
|
+
});
|
|
16
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
17
|
+
const family = createGeminiEmbeddingFamily("test-key", 3);
|
|
18
|
+
await family.embed([{ text: "pricing hero" }], "query");
|
|
19
|
+
await family.embed([{ text: "three pricing cards" }], "document");
|
|
20
|
+
const queryBody = JSON.parse(
|
|
21
|
+
String((fetchMock.mock.calls[0]?.[1] as RequestInit).body),
|
|
22
|
+
);
|
|
23
|
+
const documentBody = JSON.parse(
|
|
24
|
+
String((fetchMock.mock.calls[1]?.[1] as RequestInit).body),
|
|
25
|
+
);
|
|
26
|
+
expect(queryBody.output_dimensionality).toBe(3);
|
|
27
|
+
expect(queryBody).not.toHaveProperty("outputDimensionality");
|
|
28
|
+
expect(queryBody.content.parts[0].text).toBe(
|
|
29
|
+
"task: search result | query: pricing hero",
|
|
30
|
+
);
|
|
31
|
+
expect(documentBody.content.parts[0].text).toBe(
|
|
32
|
+
"title: none | text: three pricing cards",
|
|
33
|
+
);
|
|
34
|
+
expect(family.supportedImageMimeTypes).toEqual(["image/png", "image/jpeg"]);
|
|
35
|
+
expect((fetchMock.mock.calls[0]?.[1] as RequestInit).signal).toBeDefined();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("never echoes provider response bodies into errors", async () => {
|
|
39
|
+
vi.stubGlobal(
|
|
40
|
+
"fetch",
|
|
41
|
+
vi.fn(
|
|
42
|
+
async () =>
|
|
43
|
+
new Response("secret customer content from imported corpus", {
|
|
44
|
+
status: 400,
|
|
45
|
+
}),
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
const family = createGeminiEmbeddingFamily("test-key", 3);
|
|
49
|
+
await expect(
|
|
50
|
+
family.embed([{ text: "private customer phrase" }], "document"),
|
|
51
|
+
).rejects.toThrow("gemini/gemini-embedding-2 failed with status 400");
|
|
52
|
+
await expect(
|
|
53
|
+
family.embed([{ text: "private customer phrase" }], "document"),
|
|
54
|
+
).rejects.not.toThrow(/secret customer content|private customer phrase/);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("rejects oversized successful provider responses before JSON parsing", async () => {
|
|
58
|
+
vi.stubGlobal(
|
|
59
|
+
"fetch",
|
|
60
|
+
vi.fn(
|
|
61
|
+
async () =>
|
|
62
|
+
new Response("{}", {
|
|
63
|
+
status: 200,
|
|
64
|
+
headers: { "content-length": "1000001" },
|
|
65
|
+
}),
|
|
66
|
+
),
|
|
67
|
+
);
|
|
68
|
+
const family = createGeminiEmbeddingFamily("test-key", 3);
|
|
69
|
+
await expect(family.embed([{ text: "pricing" }], "query")).rejects.toThrow(
|
|
70
|
+
/exceeds 1000000 bytes/,
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@agent-native/core/embeddings";
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { ContextAcceptanceCase } from "./acceptance.js";
|
|
2
|
+
|
|
3
|
+
const forbidden = [
|
|
4
|
+
"INJECTION_EXECUTED",
|
|
5
|
+
"system prompt",
|
|
6
|
+
"secret token",
|
|
7
|
+
] as const;
|
|
8
|
+
|
|
9
|
+
export const CREATIVE_CONTEXT_ACCEPTANCE_CASES: readonly ContextAcceptanceCase[] =
|
|
10
|
+
[
|
|
11
|
+
{
|
|
12
|
+
id: "launch-scorecard-slide",
|
|
13
|
+
prompt: "Draft an executive launch scorecard slide.",
|
|
14
|
+
reference:
|
|
15
|
+
"Launch scorecard with four KPI tiles, a purple trend line, and one sentence of interpretation for each trend.",
|
|
16
|
+
expectedContextKeys: ["upload:launch-system-v2"],
|
|
17
|
+
requiredTerms: ["four KPI tiles", "purple trend line", "interpretation"],
|
|
18
|
+
forbiddenTerms: forbidden,
|
|
19
|
+
contextOff: {
|
|
20
|
+
output: "Executive launch scorecard with key business metrics.",
|
|
21
|
+
usedContextKeys: [],
|
|
22
|
+
},
|
|
23
|
+
contextOn: {
|
|
24
|
+
output:
|
|
25
|
+
"Launch scorecard with four KPI tiles, a purple trend line, and one sentence of interpretation for each trend.",
|
|
26
|
+
usedContextKeys: ["upload:launch-system-v2"],
|
|
27
|
+
contextPackId: "pack:launch-scorecard",
|
|
28
|
+
provenanceKeys: ["upload:launch-system-v2"],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: "pricing-hero-frame",
|
|
33
|
+
prompt: "Design a pricing hero for the website.",
|
|
34
|
+
reference:
|
|
35
|
+
"Use an ink background, Inter 56 heading, three pricing cards, and one purple Start free trial button.",
|
|
36
|
+
expectedContextKeys: ["figma:brand-system-v2"],
|
|
37
|
+
requiredTerms: ["Inter 56", "three pricing cards", "Start free trial"],
|
|
38
|
+
forbiddenTerms: forbidden,
|
|
39
|
+
contextOff: {
|
|
40
|
+
output: "A modern pricing hero with a headline, cards, and a button.",
|
|
41
|
+
usedContextKeys: [],
|
|
42
|
+
},
|
|
43
|
+
contextOn: {
|
|
44
|
+
output:
|
|
45
|
+
"Use an ink background, Inter 56 heading, three pricing cards, and one purple Start free trial button.",
|
|
46
|
+
usedContextKeys: ["figma:brand-system-v2"],
|
|
47
|
+
contextPackId: "pack:pricing-hero",
|
|
48
|
+
provenanceKeys: ["figma:brand-system-v2"],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "launch-voice-copy",
|
|
53
|
+
prompt: "Write the launch announcement opening and CTA.",
|
|
54
|
+
reference:
|
|
55
|
+
"Lead with the user outcome in direct active voice, support it with one verified metric, and close with one explicit trial action.",
|
|
56
|
+
expectedContextKeys: ["notion:launch-narrative-v2"],
|
|
57
|
+
requiredTerms: ["user outcome", "verified metric", "trial action"],
|
|
58
|
+
forbiddenTerms: forbidden,
|
|
59
|
+
contextOff: {
|
|
60
|
+
output:
|
|
61
|
+
"We are thrilled to announce our revolutionary best-in-class platform. Learn more today.",
|
|
62
|
+
usedContextKeys: [],
|
|
63
|
+
},
|
|
64
|
+
contextOn: {
|
|
65
|
+
output:
|
|
66
|
+
"Lead with the user outcome in direct active voice, support it with one verified metric, and close with one explicit trial action.",
|
|
67
|
+
usedContextKeys: ["notion:launch-narrative-v2"],
|
|
68
|
+
contextPackId: "pack:launch-voice",
|
|
69
|
+
provenanceKeys: ["notion:launch-narrative-v2"],
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: "rendered-campaign-page",
|
|
74
|
+
prompt: "Create a campaign page that proves adoption.",
|
|
75
|
+
reference:
|
|
76
|
+
"Use the purple and ink palette, show activation plus 18 percent in a four-metric proof grid, and end with Start free trial.",
|
|
77
|
+
expectedContextKeys: ["web:rendered-brand-page"],
|
|
78
|
+
requiredTerms: [
|
|
79
|
+
"purple and ink",
|
|
80
|
+
"activation plus 18 percent",
|
|
81
|
+
"Start free trial",
|
|
82
|
+
],
|
|
83
|
+
forbiddenTerms: forbidden,
|
|
84
|
+
contextOff: {
|
|
85
|
+
output:
|
|
86
|
+
"Use an attractive palette, a collection of metrics, and a compelling call to action.",
|
|
87
|
+
usedContextKeys: [],
|
|
88
|
+
},
|
|
89
|
+
contextOn: {
|
|
90
|
+
output:
|
|
91
|
+
"Use the purple and ink palette, show activation plus 18 percent in a four-metric proof grid, and end with Start free trial.",
|
|
92
|
+
usedContextKeys: ["web:rendered-brand-page"],
|
|
93
|
+
contextPackId: "pack:campaign-page",
|
|
94
|
+
provenanceKeys: ["web:rendered-brand-page"],
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
] as const;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { CREATIVE_CONTEXT_ACCEPTANCE_CASES } from "./acceptance-fixtures.js";
|
|
4
|
+
import {
|
|
5
|
+
assertContextAcceptanceGates,
|
|
6
|
+
ContextAcceptanceReportSchema,
|
|
7
|
+
createBlindPreferencePacket,
|
|
8
|
+
runContextAcceptanceEvaluation,
|
|
9
|
+
scoreBlindPreferences,
|
|
10
|
+
} from "./acceptance.js";
|
|
11
|
+
|
|
12
|
+
describe("deterministic context-on versus context-off acceptance", () => {
|
|
13
|
+
it("emits a stable schema-valid report and passes correctness gates", () => {
|
|
14
|
+
const input = {
|
|
15
|
+
corpusId: "creative-context-realistic-v1",
|
|
16
|
+
cases: CREATIVE_CONTEXT_ACCEPTANCE_CASES,
|
|
17
|
+
};
|
|
18
|
+
const first = runContextAcceptanceEvaluation(input);
|
|
19
|
+
const repeated = runContextAcceptanceEvaluation(input);
|
|
20
|
+
|
|
21
|
+
expect(repeated).toEqual(first);
|
|
22
|
+
expect(ContextAcceptanceReportSchema.parse(first)).toEqual(first);
|
|
23
|
+
expect(first).toMatchObject({
|
|
24
|
+
schemaVersion: 1,
|
|
25
|
+
runId: expect.stringMatching(/^cc-eval-[a-f0-9]{16}$/),
|
|
26
|
+
summary: {
|
|
27
|
+
caseCount: 4,
|
|
28
|
+
contextOnWins: 4,
|
|
29
|
+
contextOffWins: 0,
|
|
30
|
+
ties: 0,
|
|
31
|
+
contextOnWinRate: 1,
|
|
32
|
+
contextOnRequiredTermCoverage: 1,
|
|
33
|
+
forbiddenOutputHits: 0,
|
|
34
|
+
missingContextPacks: 0,
|
|
35
|
+
missingProvenance: 0,
|
|
36
|
+
optOutContamination: 0,
|
|
37
|
+
},
|
|
38
|
+
gates: { passed: true, failures: [] },
|
|
39
|
+
manualBlindPreference: {
|
|
40
|
+
status: "pending",
|
|
41
|
+
scoredTrials: 0,
|
|
42
|
+
contextOnPreferenceRate: null,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
expect(() => assertContextAcceptanceGates(first)).not.toThrow();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("fails on injection output, missing provenance, or context-off contamination", () => {
|
|
49
|
+
const broken = structuredClone(CREATIVE_CONTEXT_ACCEPTANCE_CASES);
|
|
50
|
+
broken[0]!.contextOn.output += " INJECTION_EXECUTED";
|
|
51
|
+
broken[1]!.contextOn.provenanceKeys = [];
|
|
52
|
+
broken[2]!.contextOff.usedContextKeys = ["notion:leaked-context"];
|
|
53
|
+
const report = runContextAcceptanceEvaluation({
|
|
54
|
+
corpusId: "creative-context-adversarial-failure",
|
|
55
|
+
cases: broken,
|
|
56
|
+
thresholds: { minimumContextOnWinRate: 0 },
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
expect(report.gates).toMatchObject({ passed: false });
|
|
60
|
+
expect(report.gates.failures).toEqual(
|
|
61
|
+
expect.arrayContaining([
|
|
62
|
+
"forbidden output was emitted",
|
|
63
|
+
"provenance is incomplete",
|
|
64
|
+
"context-off contains context evidence",
|
|
65
|
+
]),
|
|
66
|
+
);
|
|
67
|
+
expect(() => assertContextAcceptanceGates(report)).toThrow(
|
|
68
|
+
/forbidden output.*provenance.*context-off/i,
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("creates a repeatable blind packet while keeping the answer key separate", () => {
|
|
73
|
+
const packet = createBlindPreferencePacket(
|
|
74
|
+
CREATIVE_CONTEXT_ACCEPTANCE_CASES,
|
|
75
|
+
);
|
|
76
|
+
expect(
|
|
77
|
+
createBlindPreferencePacket(CREATIVE_CONTEXT_ACCEPTANCE_CASES),
|
|
78
|
+
).toEqual(packet);
|
|
79
|
+
expect(packet.worksheet).toHaveLength(4);
|
|
80
|
+
expect(packet.answerKey).toHaveLength(4);
|
|
81
|
+
expect(JSON.stringify(packet.worksheet)).not.toContain(
|
|
82
|
+
"contextOnCandidate",
|
|
83
|
+
);
|
|
84
|
+
const preferences = Object.fromEntries(
|
|
85
|
+
packet.answerKey.map((entry) => [entry.caseId, entry.contextOnCandidate]),
|
|
86
|
+
);
|
|
87
|
+
expect(scoreBlindPreferences(packet.answerKey, preferences)).toEqual({
|
|
88
|
+
scoredTrials: 4,
|
|
89
|
+
contextOnPreferenceRate: 1,
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
export interface ContextAcceptanceArtifact {
|
|
6
|
+
output: string;
|
|
7
|
+
usedContextKeys: readonly string[];
|
|
8
|
+
contextPackId?: string | null;
|
|
9
|
+
provenanceKeys?: readonly string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ContextAcceptanceCase {
|
|
13
|
+
id: string;
|
|
14
|
+
prompt: string;
|
|
15
|
+
reference: string;
|
|
16
|
+
expectedContextKeys: readonly string[];
|
|
17
|
+
requiredTerms: readonly string[];
|
|
18
|
+
forbiddenTerms: readonly string[];
|
|
19
|
+
contextOff: ContextAcceptanceArtifact;
|
|
20
|
+
contextOn: ContextAcceptanceArtifact;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ContextAcceptanceThresholds {
|
|
24
|
+
minimumCases: number;
|
|
25
|
+
minimumContextOnWinRate: number;
|
|
26
|
+
minimumRequiredTermCoverage: number;
|
|
27
|
+
minimumMeanEditDistanceReduction: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const DEFAULT_THRESHOLDS: ContextAcceptanceThresholds = {
|
|
31
|
+
minimumCases: 4,
|
|
32
|
+
minimumContextOnWinRate: 0.75,
|
|
33
|
+
minimumRequiredTermCoverage: 1,
|
|
34
|
+
minimumMeanEditDistanceReduction: 0,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const ConditionSchema = z.object({
|
|
38
|
+
outputHash: z.string().regex(/^[a-f0-9]{64}$/),
|
|
39
|
+
requiredTermCoverage: z.number().min(0).max(1),
|
|
40
|
+
forbiddenHits: z.array(z.string()),
|
|
41
|
+
editDistance: z.number().int().nonnegative(),
|
|
42
|
+
usedContextKeys: z.array(z.string()),
|
|
43
|
+
contextPackId: z.string().nullable(),
|
|
44
|
+
provenanceKeys: z.array(z.string()),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const ContextAcceptanceReportSchema = z.object({
|
|
48
|
+
schemaVersion: z.literal(1),
|
|
49
|
+
corpusId: z.string().min(1),
|
|
50
|
+
runId: z.string().regex(/^cc-eval-[a-f0-9]{16}$/),
|
|
51
|
+
cases: z.array(
|
|
52
|
+
z.object({
|
|
53
|
+
id: z.string().min(1),
|
|
54
|
+
contextOff: ConditionSchema,
|
|
55
|
+
contextOn: ConditionSchema,
|
|
56
|
+
winner: z.enum(["context-on", "context-off", "tie"]),
|
|
57
|
+
contextPackRecorded: z.boolean(),
|
|
58
|
+
provenanceComplete: z.boolean(),
|
|
59
|
+
optOutStructurallyClean: z.boolean(),
|
|
60
|
+
}),
|
|
61
|
+
),
|
|
62
|
+
summary: z.object({
|
|
63
|
+
caseCount: z.number().int().nonnegative(),
|
|
64
|
+
contextOnWins: z.number().int().nonnegative(),
|
|
65
|
+
contextOffWins: z.number().int().nonnegative(),
|
|
66
|
+
ties: z.number().int().nonnegative(),
|
|
67
|
+
contextOnWinRate: z.number().min(0).max(1),
|
|
68
|
+
contextOnRequiredTermCoverage: z.number().min(0).max(1),
|
|
69
|
+
meanEditDistanceReduction: z.number(),
|
|
70
|
+
forbiddenOutputHits: z.number().int().nonnegative(),
|
|
71
|
+
missingContextPacks: z.number().int().nonnegative(),
|
|
72
|
+
missingProvenance: z.number().int().nonnegative(),
|
|
73
|
+
optOutContamination: z.number().int().nonnegative(),
|
|
74
|
+
}),
|
|
75
|
+
thresholds: z.object({
|
|
76
|
+
minimumCases: z.number().int().positive(),
|
|
77
|
+
minimumContextOnWinRate: z.number().min(0).max(1),
|
|
78
|
+
minimumRequiredTermCoverage: z.number().min(0).max(1),
|
|
79
|
+
minimumMeanEditDistanceReduction: z.number(),
|
|
80
|
+
}),
|
|
81
|
+
gates: z.object({ passed: z.boolean(), failures: z.array(z.string()) }),
|
|
82
|
+
manualBlindPreference: z.object({
|
|
83
|
+
status: z.enum(["pending", "complete"]),
|
|
84
|
+
scoredTrials: z.number().int().nonnegative(),
|
|
85
|
+
contextOnPreferenceRate: z.number().min(0).max(1).nullable(),
|
|
86
|
+
}),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export type ContextAcceptanceReport = z.infer<
|
|
90
|
+
typeof ContextAcceptanceReportSchema
|
|
91
|
+
>;
|
|
92
|
+
|
|
93
|
+
function normalized(value: string): string {
|
|
94
|
+
return value.toLocaleLowerCase("en-US").replace(/\s+/g, " ").trim();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function unique(values: readonly string[]): string[] {
|
|
98
|
+
return [
|
|
99
|
+
...new Set(values.map((value) => value.trim()).filter(Boolean)),
|
|
100
|
+
].sort();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function condition(
|
|
104
|
+
artifact: ContextAcceptanceArtifact,
|
|
105
|
+
acceptanceCase: ContextAcceptanceCase,
|
|
106
|
+
) {
|
|
107
|
+
const output = normalized(artifact.output);
|
|
108
|
+
const required = unique(acceptanceCase.requiredTerms);
|
|
109
|
+
const forbidden = unique(acceptanceCase.forbiddenTerms).filter((term) =>
|
|
110
|
+
output.includes(normalized(term)),
|
|
111
|
+
);
|
|
112
|
+
const matched = required.filter((term) => output.includes(normalized(term)));
|
|
113
|
+
return {
|
|
114
|
+
outputHash: createHash("sha256").update(artifact.output).digest("hex"),
|
|
115
|
+
requiredTermCoverage: required.length
|
|
116
|
+
? matched.length / required.length
|
|
117
|
+
: 1,
|
|
118
|
+
forbiddenHits: forbidden,
|
|
119
|
+
editDistance: levenshtein(output, normalized(acceptanceCase.reference)),
|
|
120
|
+
usedContextKeys: unique(artifact.usedContextKeys),
|
|
121
|
+
contextPackId: artifact.contextPackId?.trim() || null,
|
|
122
|
+
provenanceKeys: unique(artifact.provenanceKeys ?? []),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function winner(
|
|
127
|
+
off: ReturnType<typeof condition>,
|
|
128
|
+
on: ReturnType<typeof condition>,
|
|
129
|
+
): "context-on" | "context-off" | "tie" {
|
|
130
|
+
if (on.forbiddenHits.length !== off.forbiddenHits.length) {
|
|
131
|
+
return on.forbiddenHits.length < off.forbiddenHits.length
|
|
132
|
+
? "context-on"
|
|
133
|
+
: "context-off";
|
|
134
|
+
}
|
|
135
|
+
if (on.requiredTermCoverage !== off.requiredTermCoverage) {
|
|
136
|
+
return on.requiredTermCoverage > off.requiredTermCoverage
|
|
137
|
+
? "context-on"
|
|
138
|
+
: "context-off";
|
|
139
|
+
}
|
|
140
|
+
if (on.editDistance !== off.editDistance) {
|
|
141
|
+
return on.editDistance < off.editDistance ? "context-on" : "context-off";
|
|
142
|
+
}
|
|
143
|
+
return "tie";
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function runContextAcceptanceEvaluation(input: {
|
|
147
|
+
corpusId: string;
|
|
148
|
+
cases: readonly ContextAcceptanceCase[];
|
|
149
|
+
thresholds?: Partial<ContextAcceptanceThresholds>;
|
|
150
|
+
}): ContextAcceptanceReport {
|
|
151
|
+
const thresholds = { ...DEFAULT_THRESHOLDS, ...input.thresholds };
|
|
152
|
+
const cases = [...input.cases]
|
|
153
|
+
.sort((left, right) => left.id.localeCompare(right.id))
|
|
154
|
+
.map((acceptanceCase) => {
|
|
155
|
+
const contextOff = condition(acceptanceCase.contextOff, acceptanceCase);
|
|
156
|
+
const contextOn = condition(acceptanceCase.contextOn, acceptanceCase);
|
|
157
|
+
const expected = new Set(unique(acceptanceCase.expectedContextKeys));
|
|
158
|
+
const contextPackRecorded = Boolean(contextOn.contextPackId);
|
|
159
|
+
const provenanceComplete = [...expected].every((key) =>
|
|
160
|
+
contextOn.provenanceKeys.includes(key),
|
|
161
|
+
);
|
|
162
|
+
const optOutStructurallyClean =
|
|
163
|
+
contextOff.usedContextKeys.length === 0 &&
|
|
164
|
+
contextOff.contextPackId === null &&
|
|
165
|
+
contextOff.provenanceKeys.length === 0;
|
|
166
|
+
return {
|
|
167
|
+
id: acceptanceCase.id,
|
|
168
|
+
contextOff,
|
|
169
|
+
contextOn,
|
|
170
|
+
winner: winner(contextOff, contextOn),
|
|
171
|
+
contextPackRecorded,
|
|
172
|
+
provenanceComplete,
|
|
173
|
+
optOutStructurallyClean,
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
const count = cases.length;
|
|
177
|
+
const contextOnWins = cases.filter(
|
|
178
|
+
(entry) => entry.winner === "context-on",
|
|
179
|
+
).length;
|
|
180
|
+
const contextOffWins = cases.filter(
|
|
181
|
+
(entry) => entry.winner === "context-off",
|
|
182
|
+
).length;
|
|
183
|
+
const ties = count - contextOnWins - contextOffWins;
|
|
184
|
+
const average = (values: readonly number[]) =>
|
|
185
|
+
values.length
|
|
186
|
+
? values.reduce((total, value) => total + value, 0) / values.length
|
|
187
|
+
: 0;
|
|
188
|
+
const summary = {
|
|
189
|
+
caseCount: count,
|
|
190
|
+
contextOnWins,
|
|
191
|
+
contextOffWins,
|
|
192
|
+
ties,
|
|
193
|
+
contextOnWinRate: count ? contextOnWins / count : 0,
|
|
194
|
+
contextOnRequiredTermCoverage: average(
|
|
195
|
+
cases.map((entry) => entry.contextOn.requiredTermCoverage),
|
|
196
|
+
),
|
|
197
|
+
meanEditDistanceReduction: average(
|
|
198
|
+
cases.map((entry) => {
|
|
199
|
+
const baseline = entry.contextOff.editDistance;
|
|
200
|
+
return baseline > 0
|
|
201
|
+
? (baseline - entry.contextOn.editDistance) / baseline
|
|
202
|
+
: entry.contextOn.editDistance === 0
|
|
203
|
+
? 0
|
|
204
|
+
: -1;
|
|
205
|
+
}),
|
|
206
|
+
),
|
|
207
|
+
forbiddenOutputHits: cases.reduce(
|
|
208
|
+
(total, entry) => total + entry.contextOn.forbiddenHits.length,
|
|
209
|
+
0,
|
|
210
|
+
),
|
|
211
|
+
missingContextPacks: cases.filter((entry) => !entry.contextPackRecorded)
|
|
212
|
+
.length,
|
|
213
|
+
missingProvenance: cases.filter((entry) => !entry.provenanceComplete)
|
|
214
|
+
.length,
|
|
215
|
+
optOutContamination: cases.filter((entry) => !entry.optOutStructurallyClean)
|
|
216
|
+
.length,
|
|
217
|
+
};
|
|
218
|
+
const failures: string[] = [];
|
|
219
|
+
if (summary.caseCount < thresholds.minimumCases) {
|
|
220
|
+
failures.push(
|
|
221
|
+
`case count ${summary.caseCount} is below ${thresholds.minimumCases}`,
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
if (summary.contextOnWinRate < thresholds.minimumContextOnWinRate) {
|
|
225
|
+
failures.push(
|
|
226
|
+
`context-on win rate ${summary.contextOnWinRate.toFixed(3)} is below ${thresholds.minimumContextOnWinRate.toFixed(3)}`,
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
if (
|
|
230
|
+
summary.contextOnRequiredTermCoverage <
|
|
231
|
+
thresholds.minimumRequiredTermCoverage
|
|
232
|
+
) {
|
|
233
|
+
failures.push(
|
|
234
|
+
`required-term coverage ${summary.contextOnRequiredTermCoverage.toFixed(3)} is below ${thresholds.minimumRequiredTermCoverage.toFixed(3)}`,
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
if (
|
|
238
|
+
summary.meanEditDistanceReduction <
|
|
239
|
+
thresholds.minimumMeanEditDistanceReduction
|
|
240
|
+
) {
|
|
241
|
+
failures.push(
|
|
242
|
+
`edit-distance reduction ${summary.meanEditDistanceReduction.toFixed(3)} is below ${thresholds.minimumMeanEditDistanceReduction.toFixed(3)}`,
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
if (summary.forbiddenOutputHits)
|
|
246
|
+
failures.push("forbidden output was emitted");
|
|
247
|
+
if (summary.missingContextPacks) failures.push("context packs are missing");
|
|
248
|
+
if (summary.missingProvenance) failures.push("provenance is incomplete");
|
|
249
|
+
if (summary.optOutContamination)
|
|
250
|
+
failures.push("context-off contains context evidence");
|
|
251
|
+
const report: ContextAcceptanceReport = {
|
|
252
|
+
schemaVersion: 1,
|
|
253
|
+
corpusId: input.corpusId,
|
|
254
|
+
runId: `cc-eval-${createHash("sha256")
|
|
255
|
+
.update(
|
|
256
|
+
JSON.stringify({
|
|
257
|
+
corpusId: input.corpusId,
|
|
258
|
+
cases,
|
|
259
|
+
thresholds,
|
|
260
|
+
}),
|
|
261
|
+
)
|
|
262
|
+
.digest("hex")
|
|
263
|
+
.slice(0, 16)}`,
|
|
264
|
+
cases,
|
|
265
|
+
summary,
|
|
266
|
+
thresholds,
|
|
267
|
+
gates: { passed: failures.length === 0, failures },
|
|
268
|
+
manualBlindPreference: {
|
|
269
|
+
status: "pending",
|
|
270
|
+
scoredTrials: 0,
|
|
271
|
+
contextOnPreferenceRate: null,
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
return ContextAcceptanceReportSchema.parse(report);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function assertContextAcceptanceGates(
|
|
278
|
+
report: ContextAcceptanceReport,
|
|
279
|
+
): void {
|
|
280
|
+
const parsed = ContextAcceptanceReportSchema.parse(report);
|
|
281
|
+
if (!parsed.gates.passed) {
|
|
282
|
+
throw new Error(
|
|
283
|
+
`Creative context acceptance gates failed: ${parsed.gates.failures.join("; ")}`,
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export interface BlindPreferenceWorksheetRow {
|
|
289
|
+
caseId: string;
|
|
290
|
+
prompt: string;
|
|
291
|
+
candidateA: string;
|
|
292
|
+
candidateB: string;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export interface BlindPreferenceAnswerKey {
|
|
296
|
+
caseId: string;
|
|
297
|
+
contextOnCandidate: "A" | "B";
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export function createBlindPreferencePacket(
|
|
301
|
+
cases: readonly ContextAcceptanceCase[],
|
|
302
|
+
): {
|
|
303
|
+
worksheet: BlindPreferenceWorksheetRow[];
|
|
304
|
+
answerKey: BlindPreferenceAnswerKey[];
|
|
305
|
+
} {
|
|
306
|
+
const worksheet: BlindPreferenceWorksheetRow[] = [];
|
|
307
|
+
const answerKey: BlindPreferenceAnswerKey[] = [];
|
|
308
|
+
for (const entry of [...cases].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
309
|
+
const contextOnCandidate =
|
|
310
|
+
parseInt(
|
|
311
|
+
createHash("sha256").update(entry.id).digest("hex").slice(0, 2),
|
|
312
|
+
16,
|
|
313
|
+
) % 2
|
|
314
|
+
? "A"
|
|
315
|
+
: "B";
|
|
316
|
+
worksheet.push({
|
|
317
|
+
caseId: entry.id,
|
|
318
|
+
prompt: entry.prompt,
|
|
319
|
+
candidateA:
|
|
320
|
+
contextOnCandidate === "A"
|
|
321
|
+
? entry.contextOn.output
|
|
322
|
+
: entry.contextOff.output,
|
|
323
|
+
candidateB:
|
|
324
|
+
contextOnCandidate === "B"
|
|
325
|
+
? entry.contextOn.output
|
|
326
|
+
: entry.contextOff.output,
|
|
327
|
+
});
|
|
328
|
+
answerKey.push({ caseId: entry.id, contextOnCandidate });
|
|
329
|
+
}
|
|
330
|
+
return { worksheet, answerKey };
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export function scoreBlindPreferences(
|
|
334
|
+
answerKey: readonly BlindPreferenceAnswerKey[],
|
|
335
|
+
scores: Readonly<Record<string, "A" | "B" | "tie">>,
|
|
336
|
+
): { scoredTrials: number; contextOnPreferenceRate: number } {
|
|
337
|
+
let scoredTrials = 0;
|
|
338
|
+
let contextOnPreferences = 0;
|
|
339
|
+
for (const entry of answerKey) {
|
|
340
|
+
const score = scores[entry.caseId];
|
|
341
|
+
if (!score) continue;
|
|
342
|
+
scoredTrials++;
|
|
343
|
+
if (score === entry.contextOnCandidate) contextOnPreferences++;
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
scoredTrials,
|
|
347
|
+
contextOnPreferenceRate: scoredTrials
|
|
348
|
+
? contextOnPreferences / scoredTrials
|
|
349
|
+
: 0,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function levenshtein(left: string, right: string): number {
|
|
354
|
+
if (left === right) return 0;
|
|
355
|
+
if (!left.length) return right.length;
|
|
356
|
+
if (!right.length) return left.length;
|
|
357
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
358
|
+
for (let leftIndex = 1; leftIndex <= left.length; leftIndex++) {
|
|
359
|
+
const current = [leftIndex];
|
|
360
|
+
for (let rightIndex = 1; rightIndex <= right.length; rightIndex++) {
|
|
361
|
+
current[rightIndex] = Math.min(
|
|
362
|
+
(current[rightIndex - 1] ?? 0) + 1,
|
|
363
|
+
(previous[rightIndex] ?? 0) + 1,
|
|
364
|
+
(previous[rightIndex - 1] ?? 0) +
|
|
365
|
+
(left[leftIndex - 1] === right[rightIndex - 1] ? 0 : 1),
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
previous = current;
|
|
369
|
+
}
|
|
370
|
+
return previous[right.length] ?? 0;
|
|
371
|
+
}
|