@agent-native/creative-context 0.1.0
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 +108 -0
- package/agent-native.package.json +104 -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 +7 -0
- package/dist/actions/continue-context-import.d.ts.map +1 -0
- package/dist/actions/continue-context-import.js +10 -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 +119 -0
- package/dist/actions/get-creative-context.d.ts.map +1 -0
- package/dist/actions/get-creative-context.js +112 -0
- package/dist/actions/get-creative-context.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 +63 -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-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/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-pack.d.ts +33 -0
- package/dist/actions/manage-context-pack.d.ts.map +1 -0
- package/dist/actions/manage-context-pack.js +65 -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 +137 -0
- package/dist/actions/manage-context-source.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 +22 -0
- package/dist/actions/process-context-purge.d.ts.map +1 -0
- package/dist/actions/process-context-purge.js +19 -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 +75 -0
- package/dist/actions/search-creative-context.d.ts.map +1 -0
- package/dist/actions/search-creative-context.js +41 -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 +10 -0
- package/dist/actions/start-context-enrichment.d.ts.map +1 -0
- package/dist/actions/start-context-enrichment.js +46 -0
- package/dist/actions/start-context-enrichment.js.map +1 -0
- package/dist/actions/start-context-import.d.ts +9 -0
- package/dist/actions/start-context-import.d.ts.map +1 -0
- package/dist/actions/start-context-import.js +36 -0
- package/dist/actions/start-context-import.js.map +1 -0
- package/dist/client/CreativeContextChip.d.ts +13 -0
- package/dist/client/CreativeContextChip.d.ts.map +1 -0
- package/dist/client/CreativeContextChip.js +45 -0
- package/dist/client/CreativeContextChip.js.map +1 -0
- package/dist/client/CreativeContextPanel.d.ts +131 -0
- package/dist/client/CreativeContextPanel.d.ts.map +1 -0
- package/dist/client/CreativeContextPanel.js +778 -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/actions.d.ts +256 -0
- package/dist/client/actions.d.ts.map +1 -0
- package/dist/client/actions.js +89 -0
- package/dist/client/actions.js.map +1 -0
- package/dist/client/agent-tab.d.ts +9 -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 +22 -0
- package/dist/client/application-state.d.ts.map +1 -0
- package/dist/client/application-state.js +88 -0
- package/dist/client/application-state.js.map +1 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +8 -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 +1059 -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 +896 -0
- package/dist/connectors/google-slides.js.map +1 -0
- package/dist/connectors/index.d.ts +20 -0
- package/dist/connectors/index.d.ts.map +1 -0
- package/dist/connectors/index.js +44 -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 +35 -0
- package/dist/connectors/normalize.d.ts.map +1 -0
- package/dist/connectors/normalize.js +216 -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-page.d.ts +101 -0
- package/dist/connectors/rendered-page.d.ts.map +1 -0
- package/dist/connectors/rendered-page.js +504 -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 +7 -0
- package/dist/embeddings/providers.d.ts.map +1 -0
- package/dist/embeddings/providers.js +176 -0
- package/dist/embeddings/providers.js.map +1 -0
- package/dist/embeddings/types.d.ts +19 -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 +252 -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 +5519 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +374 -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 +253 -0
- package/dist/schema/migrations.js.map +1 -0
- package/dist/search/fusion.d.ts +15 -0
- package/dist/search/fusion.d.ts.map +1 -0
- package/dist/search/fusion.js +25 -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 +22 -0
- package/dist/search/postgres-fts.d.ts.map +1 -0
- package/dist/search/postgres-fts.js +83 -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 +23 -0
- package/dist/server/enrichment.d.ts.map +1 -0
- package/dist/server/enrichment.js +136 -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 +111 -0
- package/dist/server/generation-artifact-access.js.map +1 -0
- package/dist/server/generation-context.d.ts +204 -0
- package/dist/server/generation-context.d.ts.map +1 -0
- package/dist/server/generation-context.js +310 -0
- package/dist/server/generation-context.js.map +1 -0
- package/dist/server/index.d.ts +22 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +96 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/isolated-a2a.d.ts +172 -0
- package/dist/server/isolated-a2a.d.ts.map +1 -0
- package/dist/server/isolated-a2a.js +310 -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 +93 -0
- package/dist/server/media.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 +78 -0
- package/dist/server/retrieval.d.ts.map +1 -0
- package/dist/server/retrieval.js +443 -0
- package/dist/server/retrieval.js.map +1 -0
- package/dist/server/untrusted-reference.d.ts +8 -0
- package/dist/server/untrusted-reference.d.ts.map +1 -0
- package/dist/server/untrusted-reference.js +19 -0
- package/dist/server/untrusted-reference.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 +360 -0
- package/dist/store/brand.js.map +1 -0
- package/dist/store/content.d.ts +120 -0
- package/dist/store/content.d.ts.map +1 -0
- package/dist/store/content.js +1437 -0
- package/dist/store/content.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 +10 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +10 -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/packs.d.ts +33 -0
- package/dist/store/packs.d.ts.map +1 -0
- package/dist/store/packs.js +321 -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 +256 -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 +538 -0
- package/dist/store/sources.js.map +1 -0
- package/dist/store/suggestions.d.ts +28 -0
- package/dist/store/suggestions.d.ts.map +1 -0
- package/dist/store/suggestions.js +250 -0
- package/dist/store/suggestions.js.map +1 -0
- package/dist/types.d.ts +493 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.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 +28 -0
- package/dist/vector/pgvector.d.ts.map +1 -0
- package/dist/vector/pgvector.js +117 -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 +74 -0
- package/package.json +91 -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 +12 -0
- package/src/actions/creative-context-a2a.spec.ts +64 -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 +315 -0
- package/src/actions/get-creative-context.ts +148 -0
- package/src/actions/index.ts +65 -0
- package/src/actions/infer-brand-dna.ts +15 -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-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/manage-brand-profile.ts +58 -0
- package/src/actions/manage-context-pack.ts +75 -0
- package/src/actions/manage-context-source.ts +154 -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 +25 -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 +47 -0
- package/src/actions/set-brand-dna.ts +22 -0
- package/src/actions/start-context-enrichment.ts +50 -0
- package/src/actions/start-context-import.ts +37 -0
- package/src/client/CreativeContextChip.tsx +162 -0
- package/src/client/CreativeContextPanel.tsx +2442 -0
- package/src/client/CreativeContextSettingsLink.tsx +30 -0
- package/src/client/actions.ts +438 -0
- package/src/client/agent-tab.tsx +58 -0
- package/src/client/application-state.spec.ts +41 -0
- package/src/client/application-state.ts +130 -0
- package/src/client/index.ts +62 -0
- package/src/client/messages.ts +1240 -0
- package/src/client/source-config.spec.ts +152 -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 +1172 -0
- package/src/connectors/index.ts +103 -0
- package/src/connectors/manual.ts +132 -0
- package/src/connectors/normalize.ts +277 -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-page.ts +705 -0
- package/src/connectors/smart-defaults.spec.ts +135 -0
- package/src/connectors/smart-defaults.ts +87 -0
- package/src/connectors/types.ts +115 -0
- package/src/connectors/upload.spec.ts +175 -0
- package/src/connectors/upload.ts +548 -0
- package/src/connectors/website.spec.ts +509 -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 +228 -0
- package/src/embeddings/types.ts +24 -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 +141 -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 +792 -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 +159 -0
- package/src/jobs/server-worker.ts +344 -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 +411 -0
- package/src/schema/migrations.spec.ts +41 -0
- package/src/schema/migrations.ts +258 -0
- package/src/search/fusion.spec.ts +21 -0
- package/src/search/fusion.ts +39 -0
- package/src/search/mode.spec.ts +28 -0
- package/src/search/mode.ts +21 -0
- package/src/search/postgres-fts.spec.ts +71 -0
- package/src/search/postgres-fts.ts +112 -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.ts +163 -0
- package/src/server/generation-artifact-access.ts +216 -0
- package/src/server/generation-context-a2a.spec.ts +131 -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 +493 -0
- package/src/server/index.ts +135 -0
- package/src/server/isolated-a2a.spec.ts +164 -0
- package/src/server/isolated-a2a.ts +413 -0
- package/src/server/media.spec.ts +92 -0
- package/src/server/media.ts +117 -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 +149 -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 +587 -0
- package/src/server/untrusted-reference.spec.ts +22 -0
- package/src/server/untrusted-reference.ts +24 -0
- package/src/store/access.integration.spec.ts +1922 -0
- package/src/store/brand.ts +477 -0
- package/src/store/content.ts +1900 -0
- package/src/store/generation.ts +226 -0
- package/src/store/helpers.ts +53 -0
- package/src/store/index.ts +9 -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 +672 -0
- package/src/store/packs.ts +466 -0
- package/src/store/purge.ts +321 -0
- package/src/store/sources.spec.ts +102 -0
- package/src/store/sources.ts +708 -0
- package/src/store/suggestions.ts +333 -0
- package/src/types.ts +571 -0
- package/src/vector/index.ts +1 -0
- package/src/vector/pgvector.spec.ts +98 -0
- package/src/vector/pgvector.ts +164 -0
|
@@ -0,0 +1,1192 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
collectFallbackNodeIds,
|
|
5
|
+
collectImageFillRefs,
|
|
6
|
+
extractFigmaTopLevelFrames,
|
|
7
|
+
mapFigmaNodeToHtml,
|
|
8
|
+
type FidelityEntry,
|
|
9
|
+
type FigmaBoundingBox,
|
|
10
|
+
type FigmaNode,
|
|
11
|
+
} from "@agent-native/core/ingestion";
|
|
12
|
+
|
|
13
|
+
import { creativeContextMediaUrl } from "../media-url.js";
|
|
14
|
+
import {
|
|
15
|
+
parseNativeCreativeArtifact,
|
|
16
|
+
type NativeCreativeArtifact,
|
|
17
|
+
type NativeCreativeArtifactFidelityReport,
|
|
18
|
+
} from "../native-artifact.js";
|
|
19
|
+
import type { ContextMediaInput, NormalizedContextItem } from "../types.js";
|
|
20
|
+
import { normalizeContextItem } from "./normalize.js";
|
|
21
|
+
import { rehostRemoteMedia } from "./private-artifacts.js";
|
|
22
|
+
import {
|
|
23
|
+
asRecord,
|
|
24
|
+
executeConnectorProviderRequest,
|
|
25
|
+
stringValue,
|
|
26
|
+
} from "./provider-response.js";
|
|
27
|
+
import type { ContextConnectorExecutionContext } from "./types.js";
|
|
28
|
+
|
|
29
|
+
export const MAX_INLINE_NATIVE_CODE_BYTES = 128 * 1024;
|
|
30
|
+
const MAX_ARTBOARD_DIMENSION = 12_000;
|
|
31
|
+
const MAX_ARTBOARD_AREA = 24_000_000;
|
|
32
|
+
const MAX_DIRECT_CHILDREN = 200;
|
|
33
|
+
const MAX_HIERARCHY_DEPTH = 12;
|
|
34
|
+
const MAX_SEARCH_TEXT_CHARS = 40_000;
|
|
35
|
+
const MAX_MANIFEST_CHILDREN_PER_BUCKET = 64;
|
|
36
|
+
|
|
37
|
+
interface FigmaFileInfo {
|
|
38
|
+
name: string;
|
|
39
|
+
version?: string;
|
|
40
|
+
lastModified?: string;
|
|
41
|
+
editorType?: string;
|
|
42
|
+
role?: string;
|
|
43
|
+
document: Record<string, unknown>;
|
|
44
|
+
components: Record<string, unknown>;
|
|
45
|
+
warnings: string[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface CompileContext {
|
|
49
|
+
fileKey: string;
|
|
50
|
+
fileName: string;
|
|
51
|
+
sourceUrl: string;
|
|
52
|
+
sourceVersion?: string;
|
|
53
|
+
sourceModifiedAt?: string;
|
|
54
|
+
connectionId?: string;
|
|
55
|
+
context: ContextConnectorExecutionContext;
|
|
56
|
+
assets: FigmaAssetRegistry;
|
|
57
|
+
artifacts: Map<string, CompiledArtifact>;
|
|
58
|
+
warnings: string[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface CompiledArtifact {
|
|
62
|
+
externalId: string;
|
|
63
|
+
nodeId: string;
|
|
64
|
+
nodeName: string;
|
|
65
|
+
item: NormalizedContextItem;
|
|
66
|
+
nativeArtifact: NativeCreativeArtifact;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface ArtifactAssets {
|
|
70
|
+
fallbackImageUrls: Record<string, string>;
|
|
71
|
+
imageFillUrls: Record<string, string>;
|
|
72
|
+
media: ContextMediaInput[];
|
|
73
|
+
assetRefs: string[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function fetchFigmaNativeContextItems(input: {
|
|
77
|
+
fileKey: string;
|
|
78
|
+
sourceTitle: string;
|
|
79
|
+
sourceUrl: string;
|
|
80
|
+
sourceModifiedAt?: string;
|
|
81
|
+
connectionId?: string;
|
|
82
|
+
context: ContextConnectorExecutionContext;
|
|
83
|
+
}): Promise<{ items: NormalizedContextItem[]; warnings: string[] }> {
|
|
84
|
+
const file = await fetchFigmaFileInfo(input);
|
|
85
|
+
const compileContext: CompileContext = {
|
|
86
|
+
fileKey: input.fileKey,
|
|
87
|
+
fileName: file.name,
|
|
88
|
+
sourceUrl: input.sourceUrl,
|
|
89
|
+
sourceVersion: file.version,
|
|
90
|
+
sourceModifiedAt: file.lastModified ?? input.sourceModifiedAt,
|
|
91
|
+
connectionId: input.connectionId,
|
|
92
|
+
context: input.context,
|
|
93
|
+
assets: new FigmaAssetRegistry({
|
|
94
|
+
fileKey: input.fileKey,
|
|
95
|
+
sourceUrl: input.sourceUrl,
|
|
96
|
+
sourceVersion: file.version ?? file.lastModified ?? "current",
|
|
97
|
+
connectionId: input.connectionId,
|
|
98
|
+
context: input.context,
|
|
99
|
+
}),
|
|
100
|
+
artifacts: new Map(),
|
|
101
|
+
warnings: [...file.warnings],
|
|
102
|
+
};
|
|
103
|
+
const topLevel = extractFigmaTopLevelFrames(file.document);
|
|
104
|
+
const inventory = new Map<
|
|
105
|
+
string,
|
|
106
|
+
{ id: string; name: string; type: string; optional?: boolean }
|
|
107
|
+
>();
|
|
108
|
+
for (const node of topLevel) {
|
|
109
|
+
const id = stringValue(node.id);
|
|
110
|
+
if (!id) continue;
|
|
111
|
+
inventory.set(id, {
|
|
112
|
+
id,
|
|
113
|
+
name: stringValue(node.name) ?? `Node ${id}`,
|
|
114
|
+
type: stringValue(node.type) ?? "FRAME",
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
for (const [id, value] of Object.entries(file.components)) {
|
|
118
|
+
const component = asRecord(value);
|
|
119
|
+
inventory.set(id, {
|
|
120
|
+
id,
|
|
121
|
+
name: stringValue(component?.name) ?? `Component ${id}`,
|
|
122
|
+
type: "COMPONENT",
|
|
123
|
+
optional: true,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
for (const entry of inventory.values()) {
|
|
128
|
+
if (compileContext.artifacts.has(externalId(input.fileKey, entry.id))) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
await compileNodeHierarchy(entry.id, compileContext, 0);
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (!entry.optional) throw error;
|
|
135
|
+
compileContext.warnings.push(
|
|
136
|
+
`Figma component ${entry.name} could not be hydrated: ${error instanceof Error ? error.message : String(error)}`,
|
|
137
|
+
);
|
|
138
|
+
inventory.delete(entry.id);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const artifacts = [...compileContext.artifacts.values()];
|
|
143
|
+
const fileText = [
|
|
144
|
+
`${file.name} Figma inventory`,
|
|
145
|
+
...[...inventory.values()].map((entry) => `${entry.type}: ${entry.name}`),
|
|
146
|
+
].join("\n");
|
|
147
|
+
const parent = normalizeContextItem({
|
|
148
|
+
externalId: input.fileKey,
|
|
149
|
+
kind: "figma-file",
|
|
150
|
+
title: file.name,
|
|
151
|
+
canonicalUrl: input.sourceUrl,
|
|
152
|
+
mimeType: "application/vnd.figma.file",
|
|
153
|
+
content: fileText,
|
|
154
|
+
sourceModifiedAt: compileContext.sourceModifiedAt,
|
|
155
|
+
sourceVersion: compileContext.sourceVersion,
|
|
156
|
+
parseStatus: "parsed",
|
|
157
|
+
provenance: { provider: "figma", fileKey: input.fileKey },
|
|
158
|
+
metadata: {
|
|
159
|
+
provider: "figma",
|
|
160
|
+
version: file.version,
|
|
161
|
+
editorType: file.editorType,
|
|
162
|
+
role: file.role,
|
|
163
|
+
inventoryDepth: 2,
|
|
164
|
+
artifactCount: artifacts.length,
|
|
165
|
+
childExternalIds: artifacts
|
|
166
|
+
.filter((artifact) => inventory.has(artifact.nodeId))
|
|
167
|
+
.map((artifact) => artifact.externalId),
|
|
168
|
+
},
|
|
169
|
+
chunks: [{ ordinal: 0, kind: "text", text: fileText }],
|
|
170
|
+
edges: artifacts
|
|
171
|
+
.filter((artifact) => inventory.has(artifact.nodeId))
|
|
172
|
+
.map((artifact) => ({
|
|
173
|
+
relation: "contains-native-artifact",
|
|
174
|
+
toExternalId: artifact.externalId,
|
|
175
|
+
})),
|
|
176
|
+
});
|
|
177
|
+
return {
|
|
178
|
+
items: [parent, ...artifacts.map((artifact) => artifact.item)],
|
|
179
|
+
warnings: compileContext.warnings,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async function fetchFigmaFileInfo(input: {
|
|
184
|
+
fileKey: string;
|
|
185
|
+
sourceTitle: string;
|
|
186
|
+
sourceModifiedAt?: string;
|
|
187
|
+
connectionId?: string;
|
|
188
|
+
context: ContextConnectorExecutionContext;
|
|
189
|
+
}): Promise<FigmaFileInfo> {
|
|
190
|
+
const requestFile = async (depth: number) =>
|
|
191
|
+
asRecord(
|
|
192
|
+
await executeConnectorProviderRequest(input.context.providerApi, {
|
|
193
|
+
provider: "figma",
|
|
194
|
+
method: "GET",
|
|
195
|
+
path: `/files/${encodeURIComponent(input.fileKey)}`,
|
|
196
|
+
query: { depth },
|
|
197
|
+
connectionId: input.connectionId,
|
|
198
|
+
maxBytes: 4 * 1024 * 1024,
|
|
199
|
+
}),
|
|
200
|
+
);
|
|
201
|
+
let value: Record<string, unknown> | null;
|
|
202
|
+
const warnings: string[] = [];
|
|
203
|
+
try {
|
|
204
|
+
value = await requestFile(2);
|
|
205
|
+
} catch (error) {
|
|
206
|
+
if (!isProviderSizeFailure(error)) throw error;
|
|
207
|
+
value = await requestFile(1);
|
|
208
|
+
const document = asRecord(value?.document);
|
|
209
|
+
const pages = Array.isArray(document?.children) ? document.children : [];
|
|
210
|
+
const hydratedPages: Record<string, unknown>[] = [];
|
|
211
|
+
for (const pageValue of pages) {
|
|
212
|
+
const page = asRecord(pageValue);
|
|
213
|
+
const pageId = stringValue(page?.id);
|
|
214
|
+
if (!pageId) continue;
|
|
215
|
+
const payload = asRecord(
|
|
216
|
+
await executeConnectorProviderRequest(input.context.providerApi, {
|
|
217
|
+
provider: "figma",
|
|
218
|
+
method: "GET",
|
|
219
|
+
path: `/files/${encodeURIComponent(input.fileKey)}/nodes`,
|
|
220
|
+
query: { ids: pageId, depth: 1 },
|
|
221
|
+
connectionId: input.connectionId,
|
|
222
|
+
maxBytes: 4 * 1024 * 1024,
|
|
223
|
+
}),
|
|
224
|
+
);
|
|
225
|
+
const hydrated = asRecord(
|
|
226
|
+
asRecord(asRecord(payload?.nodes)?.[pageId])?.document,
|
|
227
|
+
);
|
|
228
|
+
if (hydrated) hydratedPages.push(hydrated);
|
|
229
|
+
}
|
|
230
|
+
value = {
|
|
231
|
+
...value,
|
|
232
|
+
document: { ...document, children: hydratedPages },
|
|
233
|
+
components: {},
|
|
234
|
+
};
|
|
235
|
+
warnings.push(
|
|
236
|
+
"Figma file inventory exceeded the bounded depth-2 response, so pages were inventoried independently at depth 1.",
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
if (!value || !asRecord(value.document)) {
|
|
240
|
+
throw new Error(`Figma file ${input.fileKey} returned no document.`);
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
name: stringValue(value.name) ?? input.sourceTitle,
|
|
244
|
+
version: stringValue(value.version),
|
|
245
|
+
lastModified: stringValue(value.lastModified) ?? input.sourceModifiedAt,
|
|
246
|
+
editorType: stringValue(value.editorType),
|
|
247
|
+
role: stringValue(value.role),
|
|
248
|
+
document: asRecord(value.document)!,
|
|
249
|
+
components: asRecord(value.components) ?? {},
|
|
250
|
+
warnings,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async function compileNodeHierarchy(
|
|
255
|
+
nodeId: string,
|
|
256
|
+
input: CompileContext,
|
|
257
|
+
depth: number,
|
|
258
|
+
): Promise<CompiledArtifact> {
|
|
259
|
+
const id = externalId(input.fileKey, nodeId);
|
|
260
|
+
const existing = input.artifacts.get(id);
|
|
261
|
+
if (existing) return existing;
|
|
262
|
+
|
|
263
|
+
const shallow = await fetchFigmaNode(nodeId, input, 2);
|
|
264
|
+
if (depth < MAX_HIERARCHY_DEPTH && shouldSplitBeforeFullFetch(shallow)) {
|
|
265
|
+
const split = await compileSplitNode(shallow, input, depth);
|
|
266
|
+
if (split) return split;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
let full: FigmaNode;
|
|
270
|
+
try {
|
|
271
|
+
full = await fetchFigmaNode(nodeId, input);
|
|
272
|
+
} catch (error) {
|
|
273
|
+
if (
|
|
274
|
+
depth < MAX_HIERARCHY_DEPTH &&
|
|
275
|
+
isProviderSizeFailure(error) &&
|
|
276
|
+
canSplitAtChildren(shallow)
|
|
277
|
+
) {
|
|
278
|
+
const split = await compileSplitNode(shallow, input, depth);
|
|
279
|
+
if (split) return split;
|
|
280
|
+
}
|
|
281
|
+
if (isProviderSizeFailure(error)) {
|
|
282
|
+
input.warnings.push(
|
|
283
|
+
`Figma node ${shallow.name ?? nodeId} was indivisible and exceeded the provider response bound; a localized rendered fallback was stored.`,
|
|
284
|
+
);
|
|
285
|
+
return compileRenderedFallback(shallow, input);
|
|
286
|
+
}
|
|
287
|
+
throw error;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const estimated = compileWithPlaceholderAssets(full);
|
|
291
|
+
if (
|
|
292
|
+
Buffer.byteLength(estimated.html, "utf8") > MAX_INLINE_NATIVE_CODE_BYTES
|
|
293
|
+
) {
|
|
294
|
+
if (depth < MAX_HIERARCHY_DEPTH && canSplitAtChildren(full)) {
|
|
295
|
+
const split = await compileSplitNode(full, input, depth);
|
|
296
|
+
if (split) return split;
|
|
297
|
+
}
|
|
298
|
+
input.warnings.push(
|
|
299
|
+
`Figma node ${full.name ?? nodeId} produced more than 128 KiB of indivisible native code; a localized rendered fallback was stored.`,
|
|
300
|
+
);
|
|
301
|
+
return compileRenderedFallback(full, input);
|
|
302
|
+
}
|
|
303
|
+
return compileOrdinaryNode(full, input);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
async function fetchFigmaNode(
|
|
307
|
+
nodeId: string,
|
|
308
|
+
input: CompileContext,
|
|
309
|
+
depth?: number,
|
|
310
|
+
): Promise<FigmaNode> {
|
|
311
|
+
const payload = asRecord(
|
|
312
|
+
await executeConnectorProviderRequest(input.context.providerApi, {
|
|
313
|
+
provider: "figma",
|
|
314
|
+
method: "GET",
|
|
315
|
+
path: `/files/${encodeURIComponent(input.fileKey)}/nodes`,
|
|
316
|
+
query: { ids: nodeId, ...(depth ? { depth } : {}) },
|
|
317
|
+
connectionId: input.connectionId,
|
|
318
|
+
maxBytes: 4 * 1024 * 1024,
|
|
319
|
+
}),
|
|
320
|
+
);
|
|
321
|
+
const entry = asRecord(asRecord(payload?.nodes)?.[nodeId]);
|
|
322
|
+
const document = asRecord(entry?.document);
|
|
323
|
+
if (!document) {
|
|
324
|
+
throw new Error(`Figma node ${nodeId} returned no document.`);
|
|
325
|
+
}
|
|
326
|
+
return document as unknown as FigmaNode;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
async function compileOrdinaryNode(
|
|
330
|
+
node: FigmaNode,
|
|
331
|
+
input: CompileContext,
|
|
332
|
+
): Promise<CompiledArtifact> {
|
|
333
|
+
const artifactId = externalId(input.fileKey, node.id);
|
|
334
|
+
const assets = await input.assets.forNode(node, artifactId);
|
|
335
|
+
const mapped = mapFigmaNodeToHtml(node, {
|
|
336
|
+
fallbackImageUrls: assets.fallbackImageUrls,
|
|
337
|
+
imageFillUrls: assets.imageFillUrls,
|
|
338
|
+
});
|
|
339
|
+
const html = wrapFigmaDocument(mapped.html || "<div></div>", node);
|
|
340
|
+
if (Buffer.byteLength(html, "utf8") > MAX_INLINE_NATIVE_CODE_BYTES) {
|
|
341
|
+
return compileRenderedFallback(node, input);
|
|
342
|
+
}
|
|
343
|
+
const fidelityReport = nativeFidelityReportFromEntries(
|
|
344
|
+
mapped.fidelity.entries,
|
|
345
|
+
);
|
|
346
|
+
const nativeArtifact = parseNativeCreativeArtifact({
|
|
347
|
+
schemaVersion: 1,
|
|
348
|
+
app: "design",
|
|
349
|
+
format: "design-html",
|
|
350
|
+
rootExternalId: artifactId,
|
|
351
|
+
sourceBounds: normalizedBounds(node.absoluteBoundingBox),
|
|
352
|
+
fidelityReport,
|
|
353
|
+
...(assets.assetRefs.length ? { assetRefs: assets.assetRefs } : {}),
|
|
354
|
+
});
|
|
355
|
+
const item = nativeItem({
|
|
356
|
+
input,
|
|
357
|
+
node,
|
|
358
|
+
externalId: artifactId,
|
|
359
|
+
html,
|
|
360
|
+
nativeArtifact,
|
|
361
|
+
media: assets.media,
|
|
362
|
+
edges: figmaUsageEdges(node, input.fileKey),
|
|
363
|
+
});
|
|
364
|
+
const artifact = {
|
|
365
|
+
externalId: artifactId,
|
|
366
|
+
nodeId: node.id,
|
|
367
|
+
nodeName: node.name ?? node.id,
|
|
368
|
+
item,
|
|
369
|
+
nativeArtifact,
|
|
370
|
+
};
|
|
371
|
+
input.artifacts.set(artifactId, artifact);
|
|
372
|
+
return artifact;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
async function compileRenderedFallback(
|
|
376
|
+
node: FigmaNode,
|
|
377
|
+
input: CompileContext,
|
|
378
|
+
): Promise<CompiledArtifact> {
|
|
379
|
+
const artifactId = externalId(input.fileKey, node.id);
|
|
380
|
+
const assets = await input.assets.forRenderedFallback(node, artifactId);
|
|
381
|
+
const mapped = mapFigmaNodeToHtml(node, {
|
|
382
|
+
fallbackImageUrls: assets.fallbackImageUrls,
|
|
383
|
+
forceImageFallbackNodeIds: new Set([node.id]),
|
|
384
|
+
});
|
|
385
|
+
const html = wrapFigmaDocument(mapped.html || "<div></div>", node);
|
|
386
|
+
const fidelityReport = nativeFidelityReportFromEntries(
|
|
387
|
+
mapped.fidelity.entries,
|
|
388
|
+
);
|
|
389
|
+
const nativeArtifact = parseNativeCreativeArtifact({
|
|
390
|
+
schemaVersion: 1,
|
|
391
|
+
app: "design",
|
|
392
|
+
format: "design-html",
|
|
393
|
+
rootExternalId: artifactId,
|
|
394
|
+
sourceBounds: normalizedBounds(node.absoluteBoundingBox),
|
|
395
|
+
fidelityReport,
|
|
396
|
+
assetRefs: assets.assetRefs,
|
|
397
|
+
});
|
|
398
|
+
const item = nativeItem({
|
|
399
|
+
input,
|
|
400
|
+
node,
|
|
401
|
+
externalId: artifactId,
|
|
402
|
+
html,
|
|
403
|
+
nativeArtifact,
|
|
404
|
+
media: assets.media,
|
|
405
|
+
edges: figmaUsageEdges(node, input.fileKey),
|
|
406
|
+
});
|
|
407
|
+
const artifact = {
|
|
408
|
+
externalId: artifactId,
|
|
409
|
+
nodeId: node.id,
|
|
410
|
+
nodeName: node.name ?? node.id,
|
|
411
|
+
item,
|
|
412
|
+
nativeArtifact,
|
|
413
|
+
};
|
|
414
|
+
input.artifacts.set(artifactId, artifact);
|
|
415
|
+
return artifact;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
async function compileSplitNode(
|
|
419
|
+
node: FigmaNode,
|
|
420
|
+
input: CompileContext,
|
|
421
|
+
depth: number,
|
|
422
|
+
): Promise<CompiledArtifact | null> {
|
|
423
|
+
if (!canSplitAtChildren(node)) return null;
|
|
424
|
+
const children = (node.children ?? []).filter(
|
|
425
|
+
(child) => child.visible !== false,
|
|
426
|
+
);
|
|
427
|
+
const artifactId = externalId(input.fileKey, node.id);
|
|
428
|
+
const bounds = normalizedBounds(node.absoluteBoundingBox) ?? {
|
|
429
|
+
x: 0,
|
|
430
|
+
y: 0,
|
|
431
|
+
width: 1,
|
|
432
|
+
height: 1,
|
|
433
|
+
};
|
|
434
|
+
let manifestChildren = children.map((child, index) => ({
|
|
435
|
+
externalId: externalId(input.fileKey, child.id),
|
|
436
|
+
sourceNodeId: child.id,
|
|
437
|
+
bounds: relativeBounds(child.absoluteBoundingBox, bounds),
|
|
438
|
+
...(flattenTransform(child.relativeTransform)
|
|
439
|
+
? { transform: flattenTransform(child.relativeTransform) }
|
|
440
|
+
: {}),
|
|
441
|
+
zOrder: index,
|
|
442
|
+
}));
|
|
443
|
+
const placeholders = manifestChildren
|
|
444
|
+
.map(
|
|
445
|
+
(child) =>
|
|
446
|
+
`<div data-creative-context-child="${escapeAttribute(child.externalId)}" style="position:absolute;left:${round(child.bounds.x)}px;top:${round(child.bounds.y)}px;width:${round(child.bounds.width)}px;height:${round(child.bounds.height)}px;z-index:${child.zOrder}"></div>`,
|
|
447
|
+
)
|
|
448
|
+
.join("\n");
|
|
449
|
+
const minimumShell = wrapFigmaDocument(`<div>${placeholders}</div>`, node);
|
|
450
|
+
let compiledChildren: CompiledArtifact[] = [];
|
|
451
|
+
for (const child of children) {
|
|
452
|
+
compiledChildren.push(
|
|
453
|
+
await compileNodeHierarchy(child.id, input, depth + 1),
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
let boundedPlaceholders = placeholders;
|
|
457
|
+
if (Buffer.byteLength(minimumShell, "utf8") > MAX_INLINE_NATIVE_CODE_BYTES) {
|
|
458
|
+
const bucketed = compileManifestBuckets({
|
|
459
|
+
node,
|
|
460
|
+
input,
|
|
461
|
+
parentBounds: bounds,
|
|
462
|
+
manifestChildren,
|
|
463
|
+
compiledChildren,
|
|
464
|
+
});
|
|
465
|
+
manifestChildren = bucketed.manifestChildren;
|
|
466
|
+
compiledChildren = bucketed.compiledChildren;
|
|
467
|
+
boundedPlaceholders = manifestPlaceholders(manifestChildren);
|
|
468
|
+
}
|
|
469
|
+
const shellNode: FigmaNode = { ...node, children: [] };
|
|
470
|
+
const shellAssets = await input.assets.forNode(shellNode, artifactId);
|
|
471
|
+
const shell = mapFigmaNodeToHtml(shellNode, {
|
|
472
|
+
fallbackImageUrls: shellAssets.fallbackImageUrls,
|
|
473
|
+
imageFillUrls: shellAssets.imageFillUrls,
|
|
474
|
+
});
|
|
475
|
+
const shellWithChildren = insertBeforeLastClosingDiv(
|
|
476
|
+
shell.html || "<div></div>",
|
|
477
|
+
boundedPlaceholders,
|
|
478
|
+
);
|
|
479
|
+
const html = wrapFigmaDocument(shellWithChildren, node);
|
|
480
|
+
if (Buffer.byteLength(html, "utf8") > MAX_INLINE_NATIVE_CODE_BYTES) {
|
|
481
|
+
input.warnings.push(
|
|
482
|
+
`Figma node ${node.name ?? node.id} produced a hierarchical shell larger than 128 KiB; a localized rendered fallback was stored.`,
|
|
483
|
+
);
|
|
484
|
+
return compileRenderedFallback(node, input);
|
|
485
|
+
}
|
|
486
|
+
const fidelityReport = aggregateFidelity([
|
|
487
|
+
nativeFidelityReportFromEntries(shell.fidelity.entries),
|
|
488
|
+
...compiledChildren.map((child) => child.nativeArtifact.fidelityReport),
|
|
489
|
+
]);
|
|
490
|
+
const nativeArtifact = parseNativeCreativeArtifact({
|
|
491
|
+
schemaVersion: 1,
|
|
492
|
+
app: "design",
|
|
493
|
+
format: "design-html",
|
|
494
|
+
rootExternalId: artifactId,
|
|
495
|
+
sourceBounds: bounds,
|
|
496
|
+
childExternalIds: manifestChildren.map((child) => child.externalId),
|
|
497
|
+
manifest: { kind: "hierarchical-artboard", children: manifestChildren },
|
|
498
|
+
fidelityReport,
|
|
499
|
+
...(shellAssets.assetRefs.length
|
|
500
|
+
? { assetRefs: shellAssets.assetRefs }
|
|
501
|
+
: {}),
|
|
502
|
+
});
|
|
503
|
+
const item = nativeItem({
|
|
504
|
+
input,
|
|
505
|
+
node,
|
|
506
|
+
externalId: artifactId,
|
|
507
|
+
html,
|
|
508
|
+
nativeArtifact,
|
|
509
|
+
media: shellAssets.media,
|
|
510
|
+
edges: [
|
|
511
|
+
...figmaUsageEdges(node, input.fileKey),
|
|
512
|
+
...manifestChildren.map((child) => ({
|
|
513
|
+
relation: "contains-native-child",
|
|
514
|
+
toExternalId: child.externalId,
|
|
515
|
+
metadata: {
|
|
516
|
+
bounds: child.bounds,
|
|
517
|
+
transform: child.transform,
|
|
518
|
+
zOrder: child.zOrder,
|
|
519
|
+
},
|
|
520
|
+
})),
|
|
521
|
+
],
|
|
522
|
+
});
|
|
523
|
+
const artifact = {
|
|
524
|
+
externalId: artifactId,
|
|
525
|
+
nodeId: node.id,
|
|
526
|
+
nodeName: node.name ?? node.id,
|
|
527
|
+
item,
|
|
528
|
+
nativeArtifact,
|
|
529
|
+
};
|
|
530
|
+
input.artifacts.set(artifactId, artifact);
|
|
531
|
+
return artifact;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function compileManifestBuckets(input: {
|
|
535
|
+
node: FigmaNode;
|
|
536
|
+
input: CompileContext;
|
|
537
|
+
parentBounds: { x: number; y: number; width: number; height: number };
|
|
538
|
+
manifestChildren: Array<
|
|
539
|
+
NonNullable<NativeCreativeArtifact["manifest"]>["children"][number]
|
|
540
|
+
>;
|
|
541
|
+
compiledChildren: CompiledArtifact[];
|
|
542
|
+
}): {
|
|
543
|
+
manifestChildren: Array<
|
|
544
|
+
NonNullable<NativeCreativeArtifact["manifest"]>["children"][number]
|
|
545
|
+
>;
|
|
546
|
+
compiledChildren: CompiledArtifact[];
|
|
547
|
+
} {
|
|
548
|
+
const parentExternalId = externalId(input.input.fileKey, input.node.id);
|
|
549
|
+
const parentChildren: Array<
|
|
550
|
+
NonNullable<NativeCreativeArtifact["manifest"]>["children"][number]
|
|
551
|
+
> = [];
|
|
552
|
+
const bucketArtifacts: CompiledArtifact[] = [];
|
|
553
|
+
for (
|
|
554
|
+
let offset = 0;
|
|
555
|
+
offset < input.manifestChildren.length;
|
|
556
|
+
offset += MAX_MANIFEST_CHILDREN_PER_BUCKET
|
|
557
|
+
) {
|
|
558
|
+
const entries = input.manifestChildren.slice(
|
|
559
|
+
offset,
|
|
560
|
+
offset + MAX_MANIFEST_CHILDREN_PER_BUCKET,
|
|
561
|
+
);
|
|
562
|
+
const childArtifacts = input.compiledChildren.slice(
|
|
563
|
+
offset,
|
|
564
|
+
offset + MAX_MANIFEST_CHILDREN_PER_BUCKET,
|
|
565
|
+
);
|
|
566
|
+
const bucketIndex = Math.floor(offset / MAX_MANIFEST_CHILDREN_PER_BUCKET);
|
|
567
|
+
const bucketExternalId = `${parentExternalId}:manifest-bucket:${bucketIndex}`;
|
|
568
|
+
const bucketSourceNodeId = `${input.node.id}:manifest-bucket:${bucketIndex}`;
|
|
569
|
+
const bucketBounds = unionManifestBounds(entries);
|
|
570
|
+
const bucketChildren = entries.map((entry) => ({
|
|
571
|
+
...entry,
|
|
572
|
+
bounds: {
|
|
573
|
+
x: round(entry.bounds.x - bucketBounds.x),
|
|
574
|
+
y: round(entry.bounds.y - bucketBounds.y),
|
|
575
|
+
width: entry.bounds.width,
|
|
576
|
+
height: entry.bounds.height,
|
|
577
|
+
},
|
|
578
|
+
}));
|
|
579
|
+
const bucketHtml = wrapFigmaDocument(
|
|
580
|
+
`<div style="position:relative;width:${round(bucketBounds.width)}px;height:${round(bucketBounds.height)}px">${manifestPlaceholders(bucketChildren)}</div>`,
|
|
581
|
+
input.node,
|
|
582
|
+
);
|
|
583
|
+
if (Buffer.byteLength(bucketHtml, "utf8") > MAX_INLINE_NATIVE_CODE_BYTES) {
|
|
584
|
+
throw new Error(
|
|
585
|
+
`Figma manifest bucket ${bucketExternalId} exceeded 128 KiB.`,
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
const nativeArtifact = parseNativeCreativeArtifact({
|
|
589
|
+
schemaVersion: 1,
|
|
590
|
+
app: "design",
|
|
591
|
+
format: "design-html",
|
|
592
|
+
rootExternalId: bucketExternalId,
|
|
593
|
+
sourceBounds: {
|
|
594
|
+
x: 0,
|
|
595
|
+
y: 0,
|
|
596
|
+
width: bucketBounds.width,
|
|
597
|
+
height: bucketBounds.height,
|
|
598
|
+
},
|
|
599
|
+
childExternalIds: bucketChildren.map((child) => child.externalId),
|
|
600
|
+
manifest: { kind: "hierarchical-artboard", children: bucketChildren },
|
|
601
|
+
fidelityReport: aggregateFidelity(
|
|
602
|
+
childArtifacts.map((child) => child.nativeArtifact.fidelityReport),
|
|
603
|
+
),
|
|
604
|
+
});
|
|
605
|
+
const bucketNode: FigmaNode = {
|
|
606
|
+
id: bucketSourceNodeId,
|
|
607
|
+
name: `${input.node.name ?? input.node.id} segment ${bucketIndex + 1}`,
|
|
608
|
+
type: "SECTION",
|
|
609
|
+
absoluteBoundingBox: {
|
|
610
|
+
x: 0,
|
|
611
|
+
y: 0,
|
|
612
|
+
width: bucketBounds.width,
|
|
613
|
+
height: bucketBounds.height,
|
|
614
|
+
},
|
|
615
|
+
children: [],
|
|
616
|
+
};
|
|
617
|
+
const artifact: CompiledArtifact = {
|
|
618
|
+
externalId: bucketExternalId,
|
|
619
|
+
nodeId: bucketSourceNodeId,
|
|
620
|
+
nodeName: bucketNode.name!,
|
|
621
|
+
nativeArtifact,
|
|
622
|
+
item: nativeItem({
|
|
623
|
+
input: input.input,
|
|
624
|
+
node: bucketNode,
|
|
625
|
+
externalId: bucketExternalId,
|
|
626
|
+
html: bucketHtml,
|
|
627
|
+
nativeArtifact,
|
|
628
|
+
media: [],
|
|
629
|
+
edges: bucketChildren.map((child) => ({
|
|
630
|
+
relation: "contains-native-child",
|
|
631
|
+
toExternalId: child.externalId,
|
|
632
|
+
metadata: {
|
|
633
|
+
bounds: child.bounds,
|
|
634
|
+
transform: child.transform,
|
|
635
|
+
zOrder: child.zOrder,
|
|
636
|
+
},
|
|
637
|
+
})),
|
|
638
|
+
}),
|
|
639
|
+
};
|
|
640
|
+
input.input.artifacts.set(bucketExternalId, artifact);
|
|
641
|
+
bucketArtifacts.push(artifact);
|
|
642
|
+
parentChildren.push({
|
|
643
|
+
externalId: bucketExternalId,
|
|
644
|
+
sourceNodeId: bucketSourceNodeId.slice(0, 256),
|
|
645
|
+
bounds: bucketBounds,
|
|
646
|
+
zOrder: entries[0]?.zOrder ?? bucketIndex,
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
return {
|
|
650
|
+
manifestChildren: parentChildren,
|
|
651
|
+
compiledChildren: bucketArtifacts,
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
function manifestPlaceholders(
|
|
656
|
+
children: Array<
|
|
657
|
+
NonNullable<NativeCreativeArtifact["manifest"]>["children"][number]
|
|
658
|
+
>,
|
|
659
|
+
): string {
|
|
660
|
+
return children
|
|
661
|
+
.map(
|
|
662
|
+
(child) =>
|
|
663
|
+
`<div data-creative-context-child="${escapeAttribute(child.externalId)}" style="position:absolute;left:${round(child.bounds.x)}px;top:${round(child.bounds.y)}px;width:${round(child.bounds.width)}px;height:${round(child.bounds.height)}px;z-index:${child.zOrder}"></div>`,
|
|
664
|
+
)
|
|
665
|
+
.join("\n");
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
function unionManifestBounds(
|
|
669
|
+
children: Array<
|
|
670
|
+
NonNullable<NativeCreativeArtifact["manifest"]>["children"][number]
|
|
671
|
+
>,
|
|
672
|
+
): { x: number; y: number; width: number; height: number } {
|
|
673
|
+
const left = Math.min(...children.map((child) => child.bounds.x));
|
|
674
|
+
const top = Math.min(...children.map((child) => child.bounds.y));
|
|
675
|
+
const right = Math.max(
|
|
676
|
+
...children.map((child) => child.bounds.x + child.bounds.width),
|
|
677
|
+
);
|
|
678
|
+
const bottom = Math.max(
|
|
679
|
+
...children.map((child) => child.bounds.y + child.bounds.height),
|
|
680
|
+
);
|
|
681
|
+
return {
|
|
682
|
+
x: round(left),
|
|
683
|
+
y: round(top),
|
|
684
|
+
width: Math.max(0, round(right - left)),
|
|
685
|
+
height: Math.max(0, round(bottom - top)),
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
function nativeItem(input: {
|
|
690
|
+
input: CompileContext;
|
|
691
|
+
node: FigmaNode;
|
|
692
|
+
externalId: string;
|
|
693
|
+
html: string;
|
|
694
|
+
nativeArtifact: NativeCreativeArtifact;
|
|
695
|
+
media: ContextMediaInput[];
|
|
696
|
+
edges: Array<{
|
|
697
|
+
relation: string;
|
|
698
|
+
toExternalId: string;
|
|
699
|
+
metadata?: Record<string, unknown>;
|
|
700
|
+
}>;
|
|
701
|
+
}): NormalizedContextItem {
|
|
702
|
+
const text = extractSearchText(input.node);
|
|
703
|
+
const tokens = extractCodeTokens(input.html);
|
|
704
|
+
return normalizeContextItem({
|
|
705
|
+
externalId: input.externalId,
|
|
706
|
+
kind: input.nativeArtifact.manifest
|
|
707
|
+
? "figma-artboard-manifest"
|
|
708
|
+
: input.node.type === "COMPONENT"
|
|
709
|
+
? "figma-component"
|
|
710
|
+
: "figma-frame",
|
|
711
|
+
title: `${input.input.fileName} — ${input.node.name ?? input.node.id}`,
|
|
712
|
+
canonicalUrl: figmaNodeUrl(input.input.sourceUrl, input.node.id),
|
|
713
|
+
mimeType: "text/html",
|
|
714
|
+
content: input.html,
|
|
715
|
+
preserveContent: true,
|
|
716
|
+
summary: `${input.node.type} compiled to editable Design HTML/CSS${input.nativeArtifact.manifest ? ` in ${input.nativeArtifact.manifest.children.length} bounded child artifacts` : ""}.`,
|
|
717
|
+
sourceModifiedAt: input.input.sourceModifiedAt,
|
|
718
|
+
sourceVersion: input.input.sourceVersion,
|
|
719
|
+
parseStatus: "parsed",
|
|
720
|
+
provenance: {
|
|
721
|
+
provider: "figma",
|
|
722
|
+
fileKey: input.input.fileKey,
|
|
723
|
+
nodeId: input.node.id,
|
|
724
|
+
compiler: "@agent-native/core/ingestion:figma-node-to-html",
|
|
725
|
+
},
|
|
726
|
+
metadata: {
|
|
727
|
+
provider: "figma",
|
|
728
|
+
version: input.input.sourceVersion,
|
|
729
|
+
nodeType: input.node.type,
|
|
730
|
+
nativeArtifact: input.nativeArtifact,
|
|
731
|
+
},
|
|
732
|
+
chunks: [
|
|
733
|
+
...(text
|
|
734
|
+
? [
|
|
735
|
+
{
|
|
736
|
+
ordinal: 0,
|
|
737
|
+
kind: "text",
|
|
738
|
+
text,
|
|
739
|
+
metadata: { role: "source-text" },
|
|
740
|
+
},
|
|
741
|
+
]
|
|
742
|
+
: []),
|
|
743
|
+
{
|
|
744
|
+
ordinal: text ? 1 : 0,
|
|
745
|
+
kind: "code",
|
|
746
|
+
text: tokens,
|
|
747
|
+
metadata: { role: "code-tokens", format: "design-html" },
|
|
748
|
+
},
|
|
749
|
+
],
|
|
750
|
+
media: input.media,
|
|
751
|
+
edges: [
|
|
752
|
+
{ relation: "part-of-figma-file", toExternalId: input.input.fileKey },
|
|
753
|
+
...input.edges,
|
|
754
|
+
],
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
function compileWithPlaceholderAssets(node: FigmaNode) {
|
|
759
|
+
return {
|
|
760
|
+
html: wrapFigmaDocument(
|
|
761
|
+
mapFigmaNodeToHtml(node, {
|
|
762
|
+
fallbackImageUrls: Object.fromEntries(
|
|
763
|
+
collectFallbackNodeIds(node).map((id) => [
|
|
764
|
+
id,
|
|
765
|
+
`/figma-fallback/${id}`,
|
|
766
|
+
]),
|
|
767
|
+
),
|
|
768
|
+
imageFillUrls: Object.fromEntries(
|
|
769
|
+
collectImageFillRefs(node).map((ref) => [ref, `/figma-image/${ref}`]),
|
|
770
|
+
),
|
|
771
|
+
}).html,
|
|
772
|
+
node,
|
|
773
|
+
),
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
class FigmaAssetRegistry {
|
|
778
|
+
private readonly rehosted = new Map<string, Promise<ContextMediaInput>>();
|
|
779
|
+
private imageFillSourceUrls?: Promise<Record<string, string>>;
|
|
780
|
+
|
|
781
|
+
constructor(
|
|
782
|
+
private readonly input: {
|
|
783
|
+
fileKey: string;
|
|
784
|
+
sourceUrl: string;
|
|
785
|
+
sourceVersion: string;
|
|
786
|
+
connectionId?: string;
|
|
787
|
+
context: ContextConnectorExecutionContext;
|
|
788
|
+
},
|
|
789
|
+
) {}
|
|
790
|
+
|
|
791
|
+
async forNode(
|
|
792
|
+
node: FigmaNode,
|
|
793
|
+
artifactExternalId: string,
|
|
794
|
+
): Promise<ArtifactAssets> {
|
|
795
|
+
const fallbackIds = collectFallbackNodeIds(node);
|
|
796
|
+
const imageRefs = collectImageFillRefs(node);
|
|
797
|
+
return this.resolveAssets({
|
|
798
|
+
artifactExternalId,
|
|
799
|
+
fallbackIds,
|
|
800
|
+
imageRefs,
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
async forRenderedFallback(
|
|
805
|
+
node: FigmaNode,
|
|
806
|
+
artifactExternalId: string,
|
|
807
|
+
): Promise<ArtifactAssets> {
|
|
808
|
+
return this.resolveAssets({
|
|
809
|
+
artifactExternalId,
|
|
810
|
+
fallbackIds: [node.id],
|
|
811
|
+
imageRefs: [],
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
private async resolveAssets(input: {
|
|
816
|
+
artifactExternalId: string;
|
|
817
|
+
fallbackIds: string[];
|
|
818
|
+
imageRefs: string[];
|
|
819
|
+
}): Promise<ArtifactAssets> {
|
|
820
|
+
const fallbackSourceUrls = await this.renderUrls(input.fallbackIds, "png");
|
|
821
|
+
const imageFillSourceUrls = input.imageRefs.length
|
|
822
|
+
? await this.imageFillUrls()
|
|
823
|
+
: {};
|
|
824
|
+
const fallbackImageUrls: Record<string, string> = {};
|
|
825
|
+
const imageFillUrls: Record<string, string> = {};
|
|
826
|
+
const media: ContextMediaInput[] = [];
|
|
827
|
+
const assetRefs: string[] = [];
|
|
828
|
+
|
|
829
|
+
for (const nodeId of input.fallbackIds) {
|
|
830
|
+
const url = fallbackSourceUrls[nodeId];
|
|
831
|
+
if (!url)
|
|
832
|
+
throw new Error(`Figma could not render fallback node ${nodeId}.`);
|
|
833
|
+
const entry = await this.rehost(`fallback:${nodeId}`, url, {
|
|
834
|
+
nodeId,
|
|
835
|
+
role: "rendered-fallback",
|
|
836
|
+
});
|
|
837
|
+
const withId = this.forArtifact(
|
|
838
|
+
entry,
|
|
839
|
+
input.artifactExternalId,
|
|
840
|
+
`fallback:${nodeId}`,
|
|
841
|
+
);
|
|
842
|
+
const route = creativeContextMediaUrl({ mediaId: withId.id });
|
|
843
|
+
fallbackImageUrls[nodeId] = route;
|
|
844
|
+
media.push(withId);
|
|
845
|
+
assetRefs.push(route);
|
|
846
|
+
}
|
|
847
|
+
for (const imageRef of input.imageRefs) {
|
|
848
|
+
const url = imageFillSourceUrls[imageRef];
|
|
849
|
+
if (!url)
|
|
850
|
+
throw new Error(`Figma image fill ${imageRef} could not be resolved.`);
|
|
851
|
+
const entry = await this.rehost(`fill:${imageRef}`, url, {
|
|
852
|
+
imageRef,
|
|
853
|
+
role: "image-fill",
|
|
854
|
+
});
|
|
855
|
+
const withId = this.forArtifact(
|
|
856
|
+
entry,
|
|
857
|
+
input.artifactExternalId,
|
|
858
|
+
`fill:${imageRef}`,
|
|
859
|
+
);
|
|
860
|
+
const route = creativeContextMediaUrl({ mediaId: withId.id });
|
|
861
|
+
imageFillUrls[imageRef] = route;
|
|
862
|
+
media.push(withId);
|
|
863
|
+
assetRefs.push(route);
|
|
864
|
+
}
|
|
865
|
+
return { fallbackImageUrls, imageFillUrls, media, assetRefs };
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
private forArtifact(
|
|
869
|
+
media: ContextMediaInput,
|
|
870
|
+
artifactExternalId: string,
|
|
871
|
+
assetKey: string,
|
|
872
|
+
): ContextMediaInput & { id: string } {
|
|
873
|
+
return {
|
|
874
|
+
...media,
|
|
875
|
+
id: stableMediaId(
|
|
876
|
+
this.input.fileKey,
|
|
877
|
+
artifactExternalId,
|
|
878
|
+
assetKey,
|
|
879
|
+
media.contentHash ?? this.input.sourceVersion,
|
|
880
|
+
),
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
private rehost(
|
|
885
|
+
key: string,
|
|
886
|
+
url: string,
|
|
887
|
+
metadata: Record<string, unknown>,
|
|
888
|
+
): Promise<ContextMediaInput> {
|
|
889
|
+
const existing = this.rehosted.get(key);
|
|
890
|
+
if (existing) return existing;
|
|
891
|
+
const promise = rehostRemoteMedia({
|
|
892
|
+
url,
|
|
893
|
+
provenanceUrl: this.input.sourceUrl,
|
|
894
|
+
filename: `${this.input.fileKey}-${safeFilename(key)}`,
|
|
895
|
+
kind: "image",
|
|
896
|
+
context: this.input.context,
|
|
897
|
+
metadata: {
|
|
898
|
+
provider: "figma",
|
|
899
|
+
fileKey: this.input.fileKey,
|
|
900
|
+
...metadata,
|
|
901
|
+
},
|
|
902
|
+
});
|
|
903
|
+
this.rehosted.set(key, promise);
|
|
904
|
+
return promise;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
private async imageFillUrls(): Promise<Record<string, string>> {
|
|
908
|
+
if (!this.imageFillSourceUrls) {
|
|
909
|
+
this.imageFillSourceUrls = executeConnectorProviderRequest(
|
|
910
|
+
this.input.context.providerApi,
|
|
911
|
+
{
|
|
912
|
+
provider: "figma",
|
|
913
|
+
method: "GET",
|
|
914
|
+
path: `/files/${encodeURIComponent(this.input.fileKey)}/images`,
|
|
915
|
+
connectionId: this.input.connectionId,
|
|
916
|
+
maxBytes: 4 * 1024 * 1024,
|
|
917
|
+
},
|
|
918
|
+
).then((value) => {
|
|
919
|
+
const images = asRecord(asRecord(value)?.images) ?? {};
|
|
920
|
+
return Object.fromEntries(
|
|
921
|
+
Object.entries(images).filter(
|
|
922
|
+
(entry): entry is [string, string] => typeof entry[1] === "string",
|
|
923
|
+
),
|
|
924
|
+
);
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
return this.imageFillSourceUrls;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
private async renderUrls(
|
|
931
|
+
ids: string[],
|
|
932
|
+
format: "png" | "svg",
|
|
933
|
+
): Promise<Record<string, string>> {
|
|
934
|
+
if (!ids.length) return {};
|
|
935
|
+
const result: Record<string, string> = {};
|
|
936
|
+
for (let offset = 0; offset < ids.length; offset += 50) {
|
|
937
|
+
const batch = ids.slice(offset, offset + 50);
|
|
938
|
+
const payload = asRecord(
|
|
939
|
+
await executeConnectorProviderRequest(this.input.context.providerApi, {
|
|
940
|
+
provider: "figma",
|
|
941
|
+
method: "GET",
|
|
942
|
+
path: `/images/${encodeURIComponent(this.input.fileKey)}`,
|
|
943
|
+
query: { ids: batch.join(","), format, scale: 2 },
|
|
944
|
+
connectionId: this.input.connectionId,
|
|
945
|
+
maxBytes: 1024 * 1024,
|
|
946
|
+
}),
|
|
947
|
+
);
|
|
948
|
+
for (const [id, url] of Object.entries(asRecord(payload?.images) ?? {})) {
|
|
949
|
+
if (typeof url === "string" && url) result[id] = url;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
return result;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
function shouldSplitBeforeFullFetch(node: FigmaNode): boolean {
|
|
957
|
+
const bounds = node.absoluteBoundingBox;
|
|
958
|
+
return Boolean(
|
|
959
|
+
canSplitAtChildren(node) &&
|
|
960
|
+
((bounds &&
|
|
961
|
+
(bounds.width > MAX_ARTBOARD_DIMENSION ||
|
|
962
|
+
bounds.height > MAX_ARTBOARD_DIMENSION ||
|
|
963
|
+
bounds.width * bounds.height > MAX_ARTBOARD_AREA)) ||
|
|
964
|
+
(node.children?.length ?? 0) > MAX_DIRECT_CHILDREN),
|
|
965
|
+
);
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
function canSplitAtChildren(node: FigmaNode): boolean {
|
|
969
|
+
if (node.type === "GROUP") return false;
|
|
970
|
+
const children = (node.children ?? []).filter(
|
|
971
|
+
(child) => child.visible !== false,
|
|
972
|
+
);
|
|
973
|
+
if (children.length < 2) return false;
|
|
974
|
+
if (node.isMask || children.some((child) => child.isMask)) return false;
|
|
975
|
+
return true;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
function isProviderSizeFailure(error: unknown): boolean {
|
|
979
|
+
return /4 MB|too large|response bound|exceeded.*limit|maximum response/i.test(
|
|
980
|
+
error instanceof Error ? error.message : String(error),
|
|
981
|
+
);
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
export function nativeFidelityReportFromEntries(
|
|
985
|
+
entries: FidelityEntry[],
|
|
986
|
+
): NativeCreativeArtifactFidelityReport {
|
|
987
|
+
const reasons = (level: FidelityEntry["level"]) =>
|
|
988
|
+
entries
|
|
989
|
+
.filter((entry) => entry.level === level)
|
|
990
|
+
.map((entry) => ({
|
|
991
|
+
nodeId: entry.nodeId,
|
|
992
|
+
nodeName: entry.nodeName,
|
|
993
|
+
nodeType: entry.nodeType,
|
|
994
|
+
reasons: entry.notes,
|
|
995
|
+
}))
|
|
996
|
+
.slice(0, 1_000);
|
|
997
|
+
const approximated = reasons("approximated");
|
|
998
|
+
const imageFallback = reasons("image-fallback");
|
|
999
|
+
return {
|
|
1000
|
+
exact: { count: entries.filter((entry) => entry.level === "exact").length },
|
|
1001
|
+
approximated: {
|
|
1002
|
+
count: entries.filter((entry) => entry.level === "approximated").length,
|
|
1003
|
+
reasons: approximated,
|
|
1004
|
+
},
|
|
1005
|
+
imageFallback: {
|
|
1006
|
+
count: entries.filter((entry) => entry.level === "image-fallback").length,
|
|
1007
|
+
reasons: imageFallback,
|
|
1008
|
+
},
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
function aggregateFidelity(
|
|
1013
|
+
reports: NativeCreativeArtifactFidelityReport[],
|
|
1014
|
+
): NativeCreativeArtifactFidelityReport {
|
|
1015
|
+
return {
|
|
1016
|
+
exact: {
|
|
1017
|
+
count: reports.reduce((sum, report) => sum + report.exact.count, 0),
|
|
1018
|
+
},
|
|
1019
|
+
approximated: {
|
|
1020
|
+
count: reports.reduce(
|
|
1021
|
+
(sum, report) => sum + report.approximated.count,
|
|
1022
|
+
0,
|
|
1023
|
+
),
|
|
1024
|
+
reasons: reports
|
|
1025
|
+
.flatMap((report) => report.approximated.reasons)
|
|
1026
|
+
.slice(0, 1_000),
|
|
1027
|
+
},
|
|
1028
|
+
imageFallback: {
|
|
1029
|
+
count: reports.reduce(
|
|
1030
|
+
(sum, report) => sum + report.imageFallback.count,
|
|
1031
|
+
0,
|
|
1032
|
+
),
|
|
1033
|
+
reasons: reports
|
|
1034
|
+
.flatMap((report) => report.imageFallback.reasons)
|
|
1035
|
+
.slice(0, 1_000),
|
|
1036
|
+
},
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
function extractSearchText(node: FigmaNode): string {
|
|
1041
|
+
const values: string[] = [];
|
|
1042
|
+
const visit = (current: FigmaNode) => {
|
|
1043
|
+
if (values.join("\n").length >= MAX_SEARCH_TEXT_CHARS) return;
|
|
1044
|
+
if (current.name) values.push(current.name);
|
|
1045
|
+
if (current.characters) values.push(current.characters);
|
|
1046
|
+
for (const child of current.children ?? []) visit(child);
|
|
1047
|
+
};
|
|
1048
|
+
visit(node);
|
|
1049
|
+
return values.join("\n").slice(0, MAX_SEARCH_TEXT_CHARS);
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
function extractCodeTokens(html: string): string {
|
|
1053
|
+
const tokens = new Set(
|
|
1054
|
+
(html.match(/[A-Za-z][A-Za-z0-9_-]{2,}/g) ?? []).map((token) =>
|
|
1055
|
+
token.toLowerCase(),
|
|
1056
|
+
),
|
|
1057
|
+
);
|
|
1058
|
+
return [...tokens].slice(0, 4_000).join(" ");
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
function wrapFigmaDocument(fragment: string, node: FigmaNode): string {
|
|
1062
|
+
return `<!doctype html>
|
|
1063
|
+
<html>
|
|
1064
|
+
<head>
|
|
1065
|
+
<meta charset="utf-8" />
|
|
1066
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
1067
|
+
<style>*,*::before,*::after{box-sizing:border-box}html,body{margin:0;min-width:100%;min-height:100%}</style>
|
|
1068
|
+
</head>
|
|
1069
|
+
<body>
|
|
1070
|
+
${fragment}
|
|
1071
|
+
</body>
|
|
1072
|
+
</html>`;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
function figmaUsageEdges(
|
|
1076
|
+
node: FigmaNode,
|
|
1077
|
+
fileKey: string,
|
|
1078
|
+
): Array<{
|
|
1079
|
+
relation: string;
|
|
1080
|
+
toExternalId: string;
|
|
1081
|
+
metadata?: Record<string, unknown>;
|
|
1082
|
+
}> {
|
|
1083
|
+
const edges = new Map<
|
|
1084
|
+
string,
|
|
1085
|
+
{
|
|
1086
|
+
relation: string;
|
|
1087
|
+
toExternalId: string;
|
|
1088
|
+
metadata?: Record<string, unknown>;
|
|
1089
|
+
}
|
|
1090
|
+
>();
|
|
1091
|
+
const visit = (current: FigmaNode) => {
|
|
1092
|
+
if (current.componentId) {
|
|
1093
|
+
edges.set(`component:${current.componentId}`, {
|
|
1094
|
+
relation: "instance-of-component",
|
|
1095
|
+
toExternalId: `${fileKey}:${current.componentId}`,
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
const styles = (
|
|
1099
|
+
current as FigmaNode & {
|
|
1100
|
+
styles?: Record<string, unknown>;
|
|
1101
|
+
}
|
|
1102
|
+
).styles;
|
|
1103
|
+
for (const [styleType, styleId] of Object.entries(styles ?? {})) {
|
|
1104
|
+
if (typeof styleId !== "string" || !styleId) continue;
|
|
1105
|
+
edges.set(`style:${styleId}`, {
|
|
1106
|
+
relation: "uses-figma-token",
|
|
1107
|
+
toExternalId: `${fileKey}:style:${styleId}`,
|
|
1108
|
+
metadata: { styleType },
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
for (const child of current.children ?? []) visit(child);
|
|
1112
|
+
};
|
|
1113
|
+
visit(node);
|
|
1114
|
+
return [...edges.values()];
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
function normalizedBounds(bounds: FigmaBoundingBox | undefined) {
|
|
1118
|
+
return bounds
|
|
1119
|
+
? {
|
|
1120
|
+
x: round(bounds.x),
|
|
1121
|
+
y: round(bounds.y),
|
|
1122
|
+
width: Math.max(0, round(bounds.width)),
|
|
1123
|
+
height: Math.max(0, round(bounds.height)),
|
|
1124
|
+
}
|
|
1125
|
+
: undefined;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
function relativeBounds(
|
|
1129
|
+
child: FigmaBoundingBox | undefined,
|
|
1130
|
+
parent: { x: number; y: number; width: number; height: number },
|
|
1131
|
+
) {
|
|
1132
|
+
return child
|
|
1133
|
+
? {
|
|
1134
|
+
x: round(child.x - parent.x),
|
|
1135
|
+
y: round(child.y - parent.y),
|
|
1136
|
+
width: Math.max(0, round(child.width)),
|
|
1137
|
+
height: Math.max(0, round(child.height)),
|
|
1138
|
+
}
|
|
1139
|
+
: { x: 0, y: 0, width: parent.width, height: parent.height };
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
function flattenTransform(
|
|
1143
|
+
transform: FigmaNode["relativeTransform"],
|
|
1144
|
+
): [number, number, number, number, number, number] | undefined {
|
|
1145
|
+
return transform
|
|
1146
|
+
? [
|
|
1147
|
+
transform[0][0],
|
|
1148
|
+
transform[0][1],
|
|
1149
|
+
transform[0][2],
|
|
1150
|
+
transform[1][0],
|
|
1151
|
+
transform[1][1],
|
|
1152
|
+
transform[1][2],
|
|
1153
|
+
]
|
|
1154
|
+
: undefined;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
function insertBeforeLastClosingDiv(html: string, children: string): string {
|
|
1158
|
+
const index = html.lastIndexOf("</div>");
|
|
1159
|
+
return index < 0
|
|
1160
|
+
? `${html}\n${children}`
|
|
1161
|
+
: `${html.slice(0, index)}\n${children}\n${html.slice(index)}`;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
function externalId(fileKey: string, nodeId: string): string {
|
|
1165
|
+
return `${fileKey}:${nodeId}`;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
function stableMediaId(...values: string[]): string {
|
|
1169
|
+
return `ccm_${createHash("sha256").update(values.join("\u0000")).digest("hex").slice(0, 28)}`;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
function safeFilename(value: string): string {
|
|
1173
|
+
return value.replace(/[^A-Za-z0-9._-]/g, "-").slice(0, 120);
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
function figmaNodeUrl(value: string, nodeId: string): string {
|
|
1177
|
+
const url = new URL(value);
|
|
1178
|
+
url.searchParams.set("node-id", nodeId);
|
|
1179
|
+
return url.href;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
function escapeAttribute(value: string): string {
|
|
1183
|
+
return value
|
|
1184
|
+
.replace(/&/g, "&")
|
|
1185
|
+
.replace(/"/g, """)
|
|
1186
|
+
.replace(/</g, "<")
|
|
1187
|
+
.replace(/>/g, ">");
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
function round(value: number): number {
|
|
1191
|
+
return Math.round(value * 100) / 100;
|
|
1192
|
+
}
|