@agent-native/core 0.103.0 → 0.104.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/corpus/README.md +2 -2
- package/corpus/core/CHANGELOG.md +36 -0
- package/corpus/core/package.json +9 -2
- package/corpus/core/src/agent/engine/credential-errors.ts +2 -2
- package/corpus/core/src/agent/production-agent.ts +30 -0
- package/corpus/core/src/agent/run-store.ts +12 -2
- package/corpus/core/src/cli/create.ts +1 -0
- package/corpus/core/src/cli/skills-content/visual-plan-skill.ts +30 -11
- package/corpus/core/src/cli/templates-meta.ts +4 -3
- package/corpus/core/src/client/AgentAskPopover.tsx +89 -0
- package/corpus/core/src/client/AgentChatHome.tsx +4 -0
- package/corpus/core/src/client/AgentPanel.tsx +321 -223
- package/corpus/core/src/client/AssistantChat.tsx +6 -10
- package/corpus/core/src/client/MultiTabAssistantChat.tsx +53 -372
- package/corpus/core/src/client/agent-chat-adapter.ts +13 -1
- package/corpus/core/src/client/agent-page/AgentContextTab.tsx +133 -149
- package/corpus/core/src/client/agent-page/AgentEmptyState.tsx +44 -0
- package/corpus/core/src/client/agent-page/AgentJobsTab.tsx +153 -82
- package/corpus/core/src/client/agent-page/AgentTabFrame.tsx +39 -0
- package/corpus/core/src/client/agent-page/AgentTabsPage.tsx +368 -356
- package/corpus/core/src/client/agent-page/types.ts +1 -1
- package/corpus/core/src/client/analytics.ts +51 -5
- package/corpus/core/src/client/chat/run-recovery.tsx +12 -4
- package/corpus/core/src/client/composer/PromptComposer.tsx +5 -15
- package/corpus/core/src/client/composer/TiptapComposer.tsx +32 -3
- package/corpus/core/src/client/dynamic-suggestions.ts +3 -3
- package/corpus/core/src/client/index.ts +16 -1
- package/corpus/core/src/client/resources/ResourceTree.tsx +249 -38
- package/corpus/core/src/client/resources/ResourcesPanel.tsx +307 -140
- package/corpus/core/src/client/session-replay.ts +158 -5
- package/corpus/core/src/client/settings/AutomationsSection.tsx +30 -10
- package/corpus/core/src/client/settings/SettingsPanel.tsx +3 -2
- package/corpus/core/src/client/settings/SettingsTabsPage.tsx +2 -0
- package/corpus/core/src/client/settings/agent-settings-search.ts +2 -2
- package/corpus/core/src/client/use-chat-threads.ts +2 -0
- package/corpus/core/src/connections/catalog.ts +49 -7
- package/corpus/core/src/db/index.ts +6 -1
- package/corpus/core/src/extensions/actions.ts +106 -16
- package/corpus/core/src/extensions/content-patch.ts +22 -0
- package/corpus/core/src/extensions/routes.ts +18 -0
- package/corpus/core/src/extensions/store.ts +8 -0
- package/corpus/core/src/index.ts +3 -0
- package/corpus/core/src/ingestion/docx.ts +158 -0
- package/corpus/core/src/ingestion/figma-node-to-html.ts +1860 -0
- package/corpus/core/src/ingestion/figma.ts +548 -0
- package/corpus/core/src/ingestion/index.ts +107 -0
- package/corpus/core/src/ingestion/media.ts +264 -0
- package/corpus/core/src/ingestion/notion.ts +121 -0
- package/corpus/core/src/ingestion/office.ts +214 -0
- package/corpus/core/src/ingestion/orchestration.ts +160 -0
- package/corpus/core/src/ingestion/pptx.ts +333 -0
- package/corpus/core/src/ingestion/selection.ts +81 -0
- package/corpus/core/src/ingestion/website.ts +151 -0
- package/corpus/core/src/integrations/plugin.ts +45 -37
- package/corpus/core/src/localization/default-messages.ts +35 -12
- package/corpus/core/src/observability/hosted-model-experiment.ts +118 -0
- package/corpus/core/src/observability/traces.ts +5 -3
- package/corpus/core/src/provider-api/index.ts +452 -8
- package/corpus/core/src/scripts/agent-engines/list-agent-engines.ts +18 -1
- package/corpus/core/src/search-utils/index.ts +112 -0
- package/corpus/core/src/secrets/register-framework-secrets.ts +61 -0
- package/corpus/core/src/server/action-discovery.ts +33 -8
- package/corpus/core/src/server/agent-chat/framework-prompts.ts +2 -2
- package/corpus/core/src/server/agent-chat/prompt-resources.ts +144 -0
- package/corpus/core/src/server/agent-chat-plugin.ts +6 -0
- package/corpus/core/src/server/core-routes-plugin.ts +12 -0
- package/corpus/core/src/server/index.ts +30 -0
- package/corpus/core/src/server/workspace-provider-oauth.ts +583 -0
- package/corpus/core/src/styles/agent-native.css +9 -0
- package/corpus/core/src/templates/default/app/i18n/en-US.ts +3 -3
- package/corpus/core/src/templates/workspace-core/.agents/skills/extensions/SKILL.md +14 -5
- package/corpus/core/src/templates/workspace-root/.env.example +12 -0
- package/corpus/core/src/vite/client.ts +2 -0
- package/corpus/core/src/workspace-connections/index.ts +6 -0
- package/corpus/core/src/workspace-connections/lifecycle.ts +43 -0
- package/corpus/core/src/workspace-connections/store.ts +16 -0
- package/corpus/templates/analytics/.agents/skills/dashboard-management/SKILL.md +46 -3
- package/corpus/templates/analytics/AGENTS.md +9 -0
- package/corpus/templates/analytics/actions/dashboard-mutation-api.ts +120 -6
- package/corpus/templates/analytics/actions/mutate-dashboard.ts +92 -30
- package/corpus/templates/analytics/actions/update-dashboard.ts +5 -5
- package/corpus/templates/analytics/app/components/dashboard/SqlChart.tsx +313 -220
- package/corpus/templates/analytics/app/components/layout/CommandPalette.tsx +2 -2
- package/corpus/templates/analytics/app/components/layout/Layout.tsx +9 -6
- package/corpus/templates/analytics/app/components/layout/Sidebar.tsx +90 -64
- package/corpus/templates/analytics/app/i18n-data.ts +3 -3
- package/corpus/templates/analytics/app/lib/dashboard-list-loading.ts +25 -0
- package/corpus/templates/analytics/app/lib/item-popularity.ts +13 -4
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/DashboardFilterBar.tsx +1 -1
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/pivot.ts +8 -3
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/types.ts +1 -0
- package/corpus/templates/analytics/app/pages/sessions/SessionDetailPage.tsx +15 -3
- package/corpus/templates/analytics/changelog/2026-07-16-dashboard-filter-defaults-can-now-be-changed-reliably-withou.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-16-dashboard-lists-load-in-one-stable-order-without-popping-bet.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-16-fixed-dashboard-filter-dropdown-text-alignment.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-16-recurring-signed-in-users-can-now-be-viewed-as-weekly-bars-b.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-16-the-analytics-agent-can-now-duplicate-a-chart-and-place-the-.md +6 -0
- package/corpus/templates/analytics/seeds/dashboards/agent-native-templates-first-party.json +41 -1
- package/corpus/templates/analytics/server/lib/dashboard-catalog.ts +1 -1
- package/corpus/templates/analytics/server/lib/first-party-metric-catalog.ts +47 -1
- package/corpus/templates/analytics/server/lib/session-replay.ts +68 -0
- package/corpus/templates/analytics/server/plugins/agent-chat.ts +1 -0
- package/corpus/templates/analytics/server/routes/sessions/lookup.get.ts +47 -0
- package/corpus/templates/assets/.agents/skills/asset-generation/SKILL.md +16 -9
- package/corpus/templates/assets/.agents/skills/creative-context/SKILL.md +86 -0
- package/corpus/templates/assets/AGENTS.md +10 -0
- package/corpus/templates/assets/actions/create-generation-session.ts +59 -1
- package/corpus/templates/assets/actions/edit-image.ts +2 -0
- package/corpus/templates/assets/actions/generate-asset.ts +52 -0
- package/corpus/templates/assets/actions/generate-image-batch.ts +55 -0
- package/corpus/templates/assets/actions/generate-image.ts +219 -1
- package/corpus/templates/assets/actions/open-asset-picker.ts +14 -0
- package/corpus/templates/assets/actions/refine-image.ts +3 -0
- package/corpus/templates/assets/actions/restyle-image.ts +2 -0
- package/corpus/templates/assets/agent-native.app-skill.json +4 -0
- package/corpus/templates/assets/app/components/layout/Layout.tsx +2 -0
- package/corpus/templates/assets/app/i18n/zh-TW.ts +3 -0
- package/corpus/templates/assets/app/i18n-data.ts +29 -13
- package/corpus/templates/assets/app/routes/agent.tsx +7 -1
- package/corpus/templates/assets/app/routes/library.tsx +9 -0
- package/corpus/templates/assets/app/routes/settings.tsx +3 -0
- package/corpus/templates/assets/changelog/2026-07-16-creative-context-library.md +6 -0
- package/corpus/templates/assets/package.json +1 -0
- package/corpus/templates/assets/server/lib/image-processing.ts +1 -22
- package/corpus/templates/assets/server/plugins/creative-context.ts +205 -0
- package/corpus/templates/brain/app/i18n-data.ts +3 -3
- package/corpus/templates/brain/app/lib/brain.ts +1 -1
- package/corpus/templates/brain/server/lib/search.ts +17 -67
- package/corpus/templates/calendar/app/i18n-data.ts +3 -3
- package/corpus/templates/calendar/app/pages/BookingLinksPage.tsx +19 -18
- package/corpus/templates/chat/app/i18n/en-US.ts +3 -3
- package/corpus/templates/chat/app/lib/agent-page.tsx +10 -1
- package/corpus/templates/clips/.agents/skills/meetings/SKILL.md +1 -1
- package/corpus/templates/clips/AGENTS.md +4 -0
- package/corpus/templates/clips/actions/cleanup-transcript.ts +35 -4
- package/corpus/templates/clips/actions/create-meeting.ts +6 -2
- package/corpus/templates/clips/actions/create-organization.ts +3 -2
- package/corpus/templates/clips/actions/create-recording.ts +4 -1
- package/corpus/templates/clips/actions/finalize-recording.ts +44 -7
- package/corpus/templates/clips/actions/import-loom-recording.ts +4 -1
- package/corpus/templates/clips/actions/lib/create-recording-schema.ts +2 -2
- package/corpus/templates/clips/actions/list-meetings.ts +23 -5
- package/corpus/templates/clips/actions/list-organization-state.ts +1 -1
- package/corpus/templates/clips/actions/remove-silences.ts +10 -1
- package/corpus/templates/clips/actions/request-transcript.ts +53 -11
- package/corpus/templates/clips/actions/search-recordings-utils.ts +7 -0
- package/corpus/templates/clips/actions/search-recordings.ts +5 -8
- package/corpus/templates/clips/actions/set-organization-branding.ts +2 -2
- package/corpus/templates/clips/actions/stitch-recordings.ts +10 -5
- package/corpus/templates/clips/actions/update-ai-request-status.ts +38 -0
- package/corpus/templates/clips/app/components/editor/editor-layout.tsx +3 -4
- package/corpus/templates/clips/app/components/editor/editor-selection.ts +19 -0
- package/corpus/templates/clips/app/components/editor/stitch-manager.tsx +10 -10
- package/corpus/templates/clips/app/components/library/bulk-action-toolbar.tsx +1 -2
- package/corpus/templates/clips/app/components/library/library-grid.tsx +101 -93
- package/corpus/templates/clips/app/components/player/video-player.tsx +11 -0
- package/corpus/templates/clips/app/components/workspace/branding-editor.tsx +53 -1
- package/corpus/templates/clips/app/i18n/ar-SA.ts +7 -1
- package/corpus/templates/clips/app/i18n/de-DE.ts +7 -1
- package/corpus/templates/clips/app/i18n/en-US.ts +10 -4
- package/corpus/templates/clips/app/i18n/es-ES.ts +7 -1
- package/corpus/templates/clips/app/i18n/fr-FR.ts +7 -1
- package/corpus/templates/clips/app/i18n/hi-IN.ts +7 -1
- package/corpus/templates/clips/app/i18n/ja-JP.ts +7 -1
- package/corpus/templates/clips/app/i18n/ko-KR.ts +7 -1
- package/corpus/templates/clips/app/i18n/pt-BR.ts +7 -1
- package/corpus/templates/clips/app/i18n/zh-CN.ts +6 -1
- package/corpus/templates/clips/app/i18n/zh-TW.ts +6 -1
- package/corpus/templates/clips/app/routes/_app.settings._index.tsx +5 -9
- package/corpus/templates/clips/app/routes/_app.settings.organization.tsx +6 -2
- package/corpus/templates/clips/app/routes/r.$recordingId.tsx +129 -27
- package/corpus/templates/clips/app/routes/record.tsx +23 -2
- package/corpus/templates/clips/app/routes/share.$shareId.tsx +6 -2
- package/corpus/templates/clips/changelog/2026-07-16-authorized-viewers-can-open-shared-private-clips-without-a-m.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-16-camera-bubble-hover-controls-appear-above-the-face.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-16-chrome-extension-recovers-stale-recorder-state.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-16-clips-agent-chat-no-longer-shows-a-separate-workspace-header.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-16-clips-search-now-matches-recording-content-without-requiring.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-16-declined-meetings-no-longer-show-desktop-reminders.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-16-failed-desktop-saves-now-show-their-local-recovery-copy.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-16-long-desktop-clips-now-preserve-complete-playback-synced-aud.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-16-long-recording-lists-keep-stitch-and-library-actions-visible.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-16-organization-admins-can-choose-new-recording-visibility.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-16-remove-silences-now-shows-queued-active-completed-and-failed.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-16-settings-no-longer-repeats-the-builder-connection-status-in-.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-16-transcripts-now-appear-from-native-browser-speech-sooner-wit.md +6 -0
- package/corpus/templates/clips/chrome-extension/public/manifest.json +1 -1
- package/corpus/templates/clips/chrome-extension/src/background.ts +73 -1
- package/corpus/templates/clips/chrome-extension/src/native-recording-state.ts +32 -0
- package/corpus/templates/clips/chrome-extension/src/native-transcription.ts +248 -0
- package/corpus/templates/clips/chrome-extension/src/offscreen.ts +106 -0
- package/corpus/templates/clips/desktop/src/app.tsx +66 -28
- package/corpus/templates/clips/desktop/src/lib/recorder.ts +335 -285
- package/corpus/templates/clips/desktop/src/lib/single-flight.ts +7 -0
- package/corpus/templates/clips/desktop/src/lib/upload-verification.ts +51 -0
- package/corpus/templates/clips/desktop/src/overlays/bubble.tsx +2 -2
- package/corpus/templates/clips/desktop/src/overlays/finalizing.tsx +10 -2
- package/corpus/templates/clips/desktop/src/styles.css +13 -11
- package/corpus/templates/clips/desktop/src-tauri/src/clips/mod.rs +8 -9
- package/corpus/templates/clips/desktop/src-tauri/src/meetings_watcher.rs +1 -0
- package/corpus/templates/clips/desktop/src-tauri/src/native_screen/custom_capture.rs +88 -13
- package/corpus/templates/clips/desktop/src-tauri/src/native_screen/live_upload.rs +13 -2
- package/corpus/templates/clips/desktop/src-tauri/src/native_screen.rs +241 -6
- package/corpus/templates/clips/server/db/schema.ts +2 -2
- package/corpus/templates/clips/server/lib/builder-media-compression.ts +64 -67
- package/corpus/templates/clips/server/lib/calendar-event-classification.ts +19 -0
- package/corpus/templates/clips/server/lib/google-calendar-client.ts +1 -0
- package/corpus/templates/clips/server/lib/recordings.ts +40 -1
- package/corpus/templates/clips/server/plugins/agent-chat.ts +1 -0
- package/corpus/templates/clips/server/plugins/db.ts +2 -2
- package/corpus/templates/clips/server/routes/api/auth/google-calendar.get.ts +1 -1
- package/corpus/templates/clips/server/routes/api/public-recording.get.ts +14 -5
- package/corpus/templates/clips/server/routes/api/uploads/[recordingId]/chunk.post.ts +51 -1
- package/corpus/templates/clips/server/routes/api/video/[recordingId].get.ts +1 -64
- package/corpus/templates/clips/shared/media-worker-contract.ts +32 -15
- package/corpus/templates/content/.agents/skills/content/SKILL.md +16 -0
- package/corpus/templates/content/.agents/skills/creative-context/SKILL.md +85 -0
- package/corpus/templates/content/.agents/skills/notion-integration/SKILL.md +8 -0
- package/corpus/templates/content/AGENTS.md +9 -0
- package/corpus/templates/content/actions/create-document.ts +94 -0
- package/corpus/templates/content/actions/edit-document.ts +144 -4
- package/corpus/templates/content/actions/update-document.ts +138 -0
- package/corpus/templates/content/agent-native.app-skill.json +4 -0
- package/corpus/templates/content/app/components/layout/Layout.tsx +2 -0
- package/corpus/templates/content/app/i18n/zh-TW.ts +3 -0
- package/corpus/templates/content/app/i18n-data.ts +13 -4
- package/corpus/templates/content/app/routes/_app.agent.tsx +2 -1
- package/corpus/templates/content/app/routes/_app.settings.tsx +3 -0
- package/corpus/templates/content/changelog/2026-07-16-creative-context-library.md +6 -0
- package/corpus/templates/content/package.json +1 -0
- package/corpus/templates/content/server/plugins/creative-context.ts +31 -0
- package/corpus/templates/design/.agents/skills/creative-context/SKILL.md +116 -0
- package/corpus/templates/design/.agents/skills/design-generation/SKILL.md +16 -0
- package/corpus/templates/design/.agents/skills/design-systems/SKILL.md +8 -0
- package/corpus/templates/design/AGENTS.md +6 -0
- package/corpus/templates/design/actions/clone-creative-context-design.ts +176 -0
- package/corpus/templates/design/actions/edit-design.ts +128 -0
- package/corpus/templates/design/actions/generate-design.ts +278 -14
- package/corpus/templates/design/actions/generate-screens.ts +42 -1
- package/corpus/templates/design/agent-native.app-skill.json +4 -0
- package/corpus/templates/design/app/components/layout/Layout.tsx +7 -3
- package/corpus/templates/design/app/i18n/zh-TW.ts +3 -0
- package/corpus/templates/design/app/i18n-data.ts +10 -4
- package/corpus/templates/design/app/routes/agent.tsx +2 -1
- package/corpus/templates/design/app/routes/settings.tsx +3 -0
- package/corpus/templates/design/changelog/2026-07-16-creative-context-library.md +6 -0
- package/corpus/templates/design/changelog/2026-07-16-design-agent-chat-no-longer-shows-a-separate-workspace-header.md +6 -0
- package/corpus/templates/design/package.json +1 -0
- package/corpus/templates/design/server/lib/figma-design-context.ts +5 -335
- package/corpus/templates/design/server/lib/figma-node-to-html.ts +1 -1859
- package/corpus/templates/design/server/lib/import-design-files.ts +6 -8
- package/corpus/templates/design/server/plugins/creative-context.ts +31 -0
- package/corpus/templates/design/shared/generation-session.ts +7 -0
- package/corpus/templates/dispatch/app/i18n-data.ts +3 -3
- package/corpus/templates/forms/app/i18n/en-US.ts +3 -3
- package/corpus/templates/macros/app/i18n/en-US.ts +3 -3
- package/corpus/templates/mail/app/components/email/EmailThread.tsx +35 -5
- package/corpus/templates/mail/app/i18n/en-US.ts +3 -3
- package/corpus/templates/mail/changelog/2026-07-16-mail-previews-now-expand-to-show-the-full-message-without-an.md +6 -0
- package/corpus/templates/plan/.agents/skills/visual-plan/SKILL.md +30 -11
- package/corpus/templates/plan/AGENTS.md +21 -1
- package/corpus/templates/plan/actions/get-visual-plan.ts +1 -1
- package/corpus/templates/plan/actions/patch-visual-plan-source.ts +161 -0
- package/corpus/templates/plan/actions/read-visual-plan-source.ts +1 -1
- package/corpus/templates/plan/actions/update-visual-plan.ts +126 -10
- package/corpus/templates/plan/app/hooks/use-plans.ts +2 -0
- package/corpus/templates/plan/app/i18n/en-US.ts +3 -3
- package/corpus/templates/plan/app/pages/PlansPage.tsx +65 -62
- package/corpus/templates/plan/changelog/2026-07-16-local-plan-previews-now-load-annotations-containing-html-lik.md +6 -0
- package/corpus/templates/plan/changelog/2026-07-16-plan-agents-now-prevent-stale-edits-from-overwriting-newer-p.md +6 -0
- package/corpus/templates/plan/server/plan-mdx.ts +75 -2
- package/corpus/templates/slides/.agents/skills/create-deck/SKILL.md +21 -4
- package/corpus/templates/slides/.agents/skills/creative-context/SKILL.md +122 -0
- package/corpus/templates/slides/.agents/skills/design-systems/SKILL.md +11 -0
- package/corpus/templates/slides/.agents/skills/slide-editing/SKILL.md +12 -3
- package/corpus/templates/slides/AGENTS.md +6 -0
- package/corpus/templates/slides/actions/add-slide.ts +230 -14
- package/corpus/templates/slides/actions/clone-context-slide.ts +302 -0
- package/corpus/templates/slides/actions/create-deck.ts +130 -0
- package/corpus/templates/slides/actions/extract-pdf.ts +6 -2
- package/corpus/templates/slides/actions/import-file.ts +5 -4
- package/corpus/templates/slides/actions/patch-deck.ts +200 -10
- package/corpus/templates/slides/actions/update-slide.ts +208 -15
- package/corpus/templates/slides/app/components/layout/Layout.tsx +2 -0
- package/corpus/templates/slides/app/components/visual-editor/CanvasCommentPins.tsx +16 -1
- package/corpus/templates/slides/app/i18n/ar-SA.ts +3 -0
- package/corpus/templates/slides/app/i18n/de-DE.ts +3 -0
- package/corpus/templates/slides/app/i18n/en-US.ts +6 -3
- package/corpus/templates/slides/app/i18n/es-ES.ts +3 -0
- package/corpus/templates/slides/app/i18n/fr-FR.ts +3 -0
- package/corpus/templates/slides/app/i18n/hi-IN.ts +3 -0
- package/corpus/templates/slides/app/i18n/ja-JP.ts +3 -0
- package/corpus/templates/slides/app/i18n/ko-KR.ts +3 -0
- package/corpus/templates/slides/app/i18n/pt-BR.ts +3 -0
- package/corpus/templates/slides/app/i18n/zh-CN.ts +3 -0
- package/corpus/templates/slides/app/i18n/zh-TW.ts +3 -0
- package/corpus/templates/slides/app/lib/validate-native-slide-html.ts +176 -0
- package/corpus/templates/slides/app/routes/agent.tsx +7 -1
- package/corpus/templates/slides/app/routes/settings.tsx +3 -0
- package/corpus/templates/slides/changelog/2026-07-16-creative-context-library.md +6 -0
- package/corpus/templates/slides/changelog/2026-07-16-google-slides-native-cloning.md +6 -0
- package/corpus/templates/slides/package.json +1 -0
- package/corpus/templates/slides/server/handlers/import/docx-parser.ts +4 -85
- package/corpus/templates/slides/server/handlers/import/pptx-parser.ts +7 -421
- package/corpus/templates/slides/server/plugins/creative-context.ts +166 -0
- package/dist/agent/engine/credential-errors.d.ts +1 -1
- package/dist/agent/engine/credential-errors.d.ts.map +1 -1
- package/dist/agent/engine/credential-errors.js +2 -2
- package/dist/agent/engine/credential-errors.js.map +1 -1
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +25 -0
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/run-store.d.ts.map +1 -1
- package/dist/agent/run-store.js +12 -2
- package/dist/agent/run-store.js.map +1 -1
- package/dist/cli/create.d.ts.map +1 -1
- package/dist/cli/create.js +1 -0
- package/dist/cli/create.js.map +1 -1
- package/dist/cli/skills-content/visual-plan-skill.d.ts +1 -1
- package/dist/cli/skills-content/visual-plan-skill.d.ts.map +1 -1
- package/dist/cli/skills-content/visual-plan-skill.js +30 -11
- package/dist/cli/skills-content/visual-plan-skill.js.map +1 -1
- package/dist/cli/templates-meta.d.ts.map +1 -1
- package/dist/cli/templates-meta.js +4 -3
- package/dist/cli/templates-meta.js.map +1 -1
- package/dist/client/AgentAskPopover.d.ts +11 -0
- package/dist/client/AgentAskPopover.d.ts.map +1 -0
- package/dist/client/AgentAskPopover.js +30 -0
- package/dist/client/AgentAskPopover.js.map +1 -0
- package/dist/client/AgentChatHome.d.ts +1 -1
- package/dist/client/AgentChatHome.d.ts.map +1 -1
- package/dist/client/AgentChatHome.js +2 -2
- package/dist/client/AgentChatHome.js.map +1 -1
- package/dist/client/AgentPanel.d.ts +9 -19
- package/dist/client/AgentPanel.d.ts.map +1 -1
- package/dist/client/AgentPanel.js +119 -80
- package/dist/client/AgentPanel.js.map +1 -1
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +4 -4
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/MultiTabAssistantChat.d.ts +3 -9
- package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
- package/dist/client/MultiTabAssistantChat.js +49 -189
- package/dist/client/MultiTabAssistantChat.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +12 -1
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/agent-page/AgentContextTab.d.ts.map +1 -1
- package/dist/client/agent-page/AgentContextTab.js +26 -28
- package/dist/client/agent-page/AgentContextTab.js.map +1 -1
- package/dist/client/agent-page/AgentEmptyState.d.ts +13 -0
- package/dist/client/agent-page/AgentEmptyState.d.ts.map +1 -0
- package/dist/client/agent-page/AgentEmptyState.js +6 -0
- package/dist/client/agent-page/AgentEmptyState.js.map +1 -0
- package/dist/client/agent-page/AgentJobsTab.d.ts +1 -1
- package/dist/client/agent-page/AgentJobsTab.d.ts.map +1 -1
- package/dist/client/agent-page/AgentJobsTab.js +90 -58
- package/dist/client/agent-page/AgentJobsTab.js.map +1 -1
- package/dist/client/agent-page/AgentTabFrame.d.ts +12 -0
- package/dist/client/agent-page/AgentTabFrame.d.ts.map +1 -0
- package/dist/client/agent-page/AgentTabFrame.js +7 -0
- package/dist/client/agent-page/AgentTabFrame.js.map +1 -0
- package/dist/client/agent-page/AgentTabsPage.d.ts +9 -1
- package/dist/client/agent-page/AgentTabsPage.d.ts.map +1 -1
- package/dist/client/agent-page/AgentTabsPage.js +135 -99
- package/dist/client/agent-page/AgentTabsPage.js.map +1 -1
- package/dist/client/agent-page/types.d.ts +1 -1
- package/dist/client/agent-page/types.d.ts.map +1 -1
- package/dist/client/agent-page/types.js.map +1 -1
- package/dist/client/analytics.d.ts +10 -3
- package/dist/client/analytics.d.ts.map +1 -1
- package/dist/client/analytics.js +37 -2
- package/dist/client/analytics.js.map +1 -1
- package/dist/client/chat/run-recovery.d.ts.map +1 -1
- package/dist/client/chat/run-recovery.js +10 -3
- package/dist/client/chat/run-recovery.js.map +1 -1
- package/dist/client/composer/PromptComposer.d.ts.map +1 -1
- package/dist/client/composer/PromptComposer.js +2 -2
- package/dist/client/composer/PromptComposer.js.map +1 -1
- package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
- package/dist/client/composer/TiptapComposer.js +15 -3
- package/dist/client/composer/TiptapComposer.js.map +1 -1
- package/dist/client/dynamic-suggestions.js +3 -3
- package/dist/client/dynamic-suggestions.js.map +1 -1
- package/dist/client/index.d.ts +4 -3
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +3 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/resources/ResourceTree.d.ts +5 -1
- package/dist/client/resources/ResourceTree.d.ts.map +1 -1
- package/dist/client/resources/ResourceTree.js +74 -5
- package/dist/client/resources/ResourceTree.js.map +1 -1
- package/dist/client/resources/ResourcesPanel.d.ts +11 -2
- package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
- package/dist/client/resources/ResourcesPanel.js +105 -31
- package/dist/client/resources/ResourcesPanel.js.map +1 -1
- package/dist/client/session-replay.d.ts +28 -0
- package/dist/client/session-replay.d.ts.map +1 -1
- package/dist/client/session-replay.js +122 -8
- package/dist/client/session-replay.js.map +1 -1
- package/dist/client/settings/AutomationsSection.d.ts +3 -1
- package/dist/client/settings/AutomationsSection.d.ts.map +1 -1
- package/dist/client/settings/AutomationsSection.js +16 -6
- package/dist/client/settings/AutomationsSection.js.map +1 -1
- package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
- package/dist/client/settings/SettingsPanel.js +3 -3
- package/dist/client/settings/SettingsPanel.js.map +1 -1
- package/dist/client/settings/SettingsTabsPage.d.ts +2 -0
- package/dist/client/settings/SettingsTabsPage.d.ts.map +1 -1
- package/dist/client/settings/SettingsTabsPage.js.map +1 -1
- package/dist/client/settings/agent-settings-search.js +2 -2
- package/dist/client/settings/agent-settings-search.js.map +1 -1
- package/dist/client/use-chat-threads.d.ts +2 -0
- package/dist/client/use-chat-threads.d.ts.map +1 -1
- package/dist/client/use-chat-threads.js.map +1 -1
- package/dist/collab/awareness.d.ts +2 -2
- package/dist/collab/awareness.d.ts.map +1 -1
- package/dist/collab/routes.d.ts +1 -1
- package/dist/connections/catalog.d.ts +41 -7
- package/dist/connections/catalog.d.ts.map +1 -1
- package/dist/connections/catalog.js +40 -7
- package/dist/connections/catalog.js.map +1 -1
- package/dist/db/index.d.ts +2 -2
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +2 -2
- package/dist/db/index.js.map +1 -1
- package/dist/extensions/actions.d.ts.map +1 -1
- package/dist/extensions/actions.js +85 -15
- package/dist/extensions/actions.js.map +1 -1
- package/dist/extensions/content-patch.d.ts +4 -0
- package/dist/extensions/content-patch.d.ts.map +1 -1
- package/dist/extensions/content-patch.js +18 -0
- package/dist/extensions/content-patch.js.map +1 -1
- package/dist/extensions/routes.d.ts.map +1 -1
- package/dist/extensions/routes.js +14 -0
- package/dist/extensions/routes.js.map +1 -1
- package/dist/extensions/store.d.ts +1 -0
- package/dist/extensions/store.d.ts.map +1 -1
- package/dist/extensions/store.js +4 -1
- package/dist/extensions/store.js.map +1 -1
- package/dist/file-upload/actions/upload-image.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/ingestion/docx.d.ts +16 -0
- package/dist/ingestion/docx.d.ts.map +1 -0
- package/dist/ingestion/docx.js +129 -0
- package/dist/ingestion/docx.js.map +1 -0
- package/dist/ingestion/figma-node-to-html.d.ts +304 -0
- package/dist/ingestion/figma-node-to-html.d.ts.map +1 -0
- package/dist/ingestion/figma-node-to-html.js +1292 -0
- package/dist/ingestion/figma-node-to-html.js.map +1 -0
- package/dist/ingestion/figma.d.ts +115 -0
- package/dist/ingestion/figma.d.ts.map +1 -0
- package/dist/ingestion/figma.js +399 -0
- package/dist/ingestion/figma.js.map +1 -0
- package/dist/ingestion/index.d.ts +11 -0
- package/dist/ingestion/index.d.ts.map +1 -0
- package/dist/ingestion/index.js +11 -0
- package/dist/ingestion/index.js.map +1 -0
- package/dist/ingestion/media.d.ts +36 -0
- package/dist/ingestion/media.d.ts.map +1 -0
- package/dist/ingestion/media.js +178 -0
- package/dist/ingestion/media.js.map +1 -0
- package/dist/ingestion/notion.d.ts +12 -0
- package/dist/ingestion/notion.d.ts.map +1 -0
- package/dist/ingestion/notion.js +104 -0
- package/dist/ingestion/notion.js.map +1 -0
- package/dist/ingestion/office.d.ts +45 -0
- package/dist/ingestion/office.d.ts.map +1 -0
- package/dist/ingestion/office.js +141 -0
- package/dist/ingestion/office.js.map +1 -0
- package/dist/ingestion/orchestration.d.ts +52 -0
- package/dist/ingestion/orchestration.d.ts.map +1 -0
- package/dist/ingestion/orchestration.js +89 -0
- package/dist/ingestion/orchestration.js.map +1 -0
- package/dist/ingestion/pptx.d.ts +28 -0
- package/dist/ingestion/pptx.d.ts.map +1 -0
- package/dist/ingestion/pptx.js +255 -0
- package/dist/ingestion/pptx.js.map +1 -0
- package/dist/ingestion/selection.d.ts +20 -0
- package/dist/ingestion/selection.d.ts.map +1 -0
- package/dist/ingestion/selection.js +52 -0
- package/dist/ingestion/selection.js.map +1 -0
- package/dist/ingestion/website.d.ts +27 -0
- package/dist/ingestion/website.d.ts.map +1 -0
- package/dist/ingestion/website.js +100 -0
- package/dist/ingestion/website.js.map +1 -0
- package/dist/integrations/plugin.d.ts.map +1 -1
- package/dist/integrations/plugin.js +32 -27
- package/dist/integrations/plugin.js.map +1 -1
- package/dist/localization/default-messages.d.ts +22 -0
- package/dist/localization/default-messages.d.ts.map +1 -1
- package/dist/localization/default-messages.js +31 -9
- package/dist/localization/default-messages.js.map +1 -1
- package/dist/observability/hosted-model-experiment.d.ts +39 -0
- package/dist/observability/hosted-model-experiment.d.ts.map +1 -0
- package/dist/observability/hosted-model-experiment.js +90 -0
- package/dist/observability/hosted-model-experiment.js.map +1 -0
- package/dist/observability/routes.d.ts +5 -5
- package/dist/observability/traces.d.ts.map +1 -1
- package/dist/observability/traces.js +5 -3
- package/dist/observability/traces.js.map +1 -1
- package/dist/progress/routes.d.ts +1 -1
- package/dist/provider-api/index.d.ts +35 -4
- package/dist/provider-api/index.d.ts.map +1 -1
- package/dist/provider-api/index.js +339 -8
- package/dist/provider-api/index.js.map +1 -1
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/scripts/agent-engines/list-agent-engines.d.ts.map +1 -1
- package/dist/scripts/agent-engines/list-agent-engines.js +18 -1
- package/dist/scripts/agent-engines/list-agent-engines.js.map +1 -1
- package/dist/search-utils/index.d.ts +12 -0
- package/dist/search-utils/index.d.ts.map +1 -0
- package/dist/search-utils/index.js +95 -0
- package/dist/search-utils/index.js.map +1 -0
- package/dist/secrets/register-framework-secrets.d.ts.map +1 -1
- package/dist/secrets/register-framework-secrets.js +57 -0
- package/dist/secrets/register-framework-secrets.js.map +1 -1
- package/dist/secrets/routes.d.ts +9 -9
- package/dist/server/action-discovery.d.ts +8 -0
- package/dist/server/action-discovery.d.ts.map +1 -1
- package/dist/server/action-discovery.js +26 -9
- package/dist/server/action-discovery.js.map +1 -1
- package/dist/server/agent-chat/framework-prompts.js +2 -2
- package/dist/server/agent-chat/framework-prompts.js.map +1 -1
- package/dist/server/agent-chat/prompt-resources.d.ts +19 -0
- package/dist/server/agent-chat/prompt-resources.d.ts.map +1 -1
- package/dist/server/agent-chat/prompt-resources.js +95 -0
- package/dist/server/agent-chat/prompt-resources.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +7 -0
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +5 -0
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/server/index.d.ts +5 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +5 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/workspace-provider-oauth.d.ts +48 -0
- package/dist/server/workspace-provider-oauth.d.ts.map +1 -0
- package/dist/server/workspace-provider-oauth.js +415 -0
- package/dist/server/workspace-provider-oauth.js.map +1 -0
- package/dist/styles/agent-native.css +9 -0
- package/dist/templates/chat/app/i18n/en-US.ts +3 -3
- package/dist/templates/chat/app/lib/agent-page.tsx +10 -1
- package/dist/templates/default/app/i18n/en-US.ts +3 -3
- package/dist/templates/workspace-core/.agents/skills/extensions/SKILL.md +14 -5
- package/dist/templates/workspace-root/.env.example +12 -0
- package/dist/vite/client.d.ts.map +1 -1
- package/dist/vite/client.js +2 -0
- package/dist/vite/client.js.map +1 -1
- package/dist/workspace-connections/index.d.ts +1 -0
- package/dist/workspace-connections/index.d.ts.map +1 -1
- package/dist/workspace-connections/index.js +1 -0
- package/dist/workspace-connections/index.js.map +1 -1
- package/dist/workspace-connections/lifecycle.d.ts +16 -0
- package/dist/workspace-connections/lifecycle.d.ts.map +1 -0
- package/dist/workspace-connections/lifecycle.js +14 -0
- package/dist/workspace-connections/lifecycle.js.map +1 -0
- package/dist/workspace-connections/store.d.ts.map +1 -1
- package/dist/workspace-connections/store.js +16 -0
- package/dist/workspace-connections/store.js.map +1 -1
- package/package.json +10 -3
- package/src/templates/chat/app/i18n/en-US.ts +3 -3
- package/src/templates/chat/app/lib/agent-page.spec.tsx +10 -1
- package/src/templates/chat/app/lib/agent-page.tsx +10 -1
- package/src/templates/default/app/i18n/en-US.ts +3 -3
- package/src/templates/workspace-core/.agents/skills/extensions/SKILL.md +14 -5
- package/src/templates/workspace-root/.env.example +12 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
export function fingerprintMedia(data, mimeType) {
|
|
3
|
+
return {
|
|
4
|
+
sha256: createHash("sha256").update(data).digest("hex"),
|
|
5
|
+
byteLength: data.byteLength,
|
|
6
|
+
...(mimeType ? { mimeType } : {}),
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function extractCssColors(value) {
|
|
10
|
+
const colors = new Set();
|
|
11
|
+
const pattern = /(?:#[0-9a-f]{3,8}\b|(?:rgb|hsl)a?\([^)]*\)|\b(?:transparent|currentColor)\b)/gi;
|
|
12
|
+
for (const match of value.match(pattern) ?? [])
|
|
13
|
+
colors.add(match.trim());
|
|
14
|
+
return [...colors];
|
|
15
|
+
}
|
|
16
|
+
export function rankColorSamples(samples, limit = 24) {
|
|
17
|
+
const counts = new Map();
|
|
18
|
+
for (const sample of samples) {
|
|
19
|
+
const normalized = sample.trim().replace(/\s+/g, " ").toLowerCase();
|
|
20
|
+
if (!normalized ||
|
|
21
|
+
normalized === "rgba(0, 0, 0, 0)" ||
|
|
22
|
+
normalized === "transparent")
|
|
23
|
+
continue;
|
|
24
|
+
counts.set(normalized, (counts.get(normalized) ?? 0) + 1);
|
|
25
|
+
}
|
|
26
|
+
return [...counts.entries()]
|
|
27
|
+
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
|
28
|
+
.slice(0, Math.max(1, limit))
|
|
29
|
+
.map(([color]) => color);
|
|
30
|
+
}
|
|
31
|
+
export async function extractDominantColors(data, limit = 6) {
|
|
32
|
+
const sharp = await loadSharp();
|
|
33
|
+
if (!sharp) {
|
|
34
|
+
throw new Error("Image palette extraction requires the optional sharp dependency.");
|
|
35
|
+
}
|
|
36
|
+
const output = await sharp(Buffer.from(data), { failOn: "none" })
|
|
37
|
+
.resize(64, 64, { fit: "inside" })
|
|
38
|
+
.removeAlpha()
|
|
39
|
+
.raw()
|
|
40
|
+
.toBuffer({ resolveWithObject: true });
|
|
41
|
+
const buckets = new Map();
|
|
42
|
+
for (let index = 0; index < output.data.length; index += 3) {
|
|
43
|
+
const key = [
|
|
44
|
+
output.data[index],
|
|
45
|
+
output.data[index + 1],
|
|
46
|
+
output.data[index + 2],
|
|
47
|
+
]
|
|
48
|
+
.map((channel) => Math.round(channel / 32) * 32)
|
|
49
|
+
.map((channel) => Math.max(0, Math.min(255, channel)).toString(16).padStart(2, "0"))
|
|
50
|
+
.join("");
|
|
51
|
+
buckets.set(key, (buckets.get(key) ?? 0) + 1);
|
|
52
|
+
}
|
|
53
|
+
return [...buckets.entries()]
|
|
54
|
+
.sort((a, b) => b[1] - a[1])
|
|
55
|
+
.slice(0, Math.max(1, limit))
|
|
56
|
+
.map(([hex]) => `#${hex.toUpperCase()}`);
|
|
57
|
+
}
|
|
58
|
+
export async function compareRasterImages(input) {
|
|
59
|
+
const maxInputBytes = input.maxInputBytes ?? 20 * 1024 * 1024;
|
|
60
|
+
if (input.source.byteLength > maxInputBytes ||
|
|
61
|
+
input.rendered.byteLength > maxInputBytes) {
|
|
62
|
+
throw new Error(`Image comparison input exceeds ${maxInputBytes} bytes.`);
|
|
63
|
+
}
|
|
64
|
+
const sharp = await loadSharp();
|
|
65
|
+
if (!sharp) {
|
|
66
|
+
throw new Error("Image comparison requires the optional sharp dependency.");
|
|
67
|
+
}
|
|
68
|
+
const source = sharp(Buffer.from(input.source), { failOn: "none" });
|
|
69
|
+
const rendered = sharp(Buffer.from(input.rendered), { failOn: "none" });
|
|
70
|
+
const [sourceMetadata, renderedMetadata] = await Promise.all([
|
|
71
|
+
source.metadata(),
|
|
72
|
+
rendered.metadata(),
|
|
73
|
+
]);
|
|
74
|
+
if (!sourceMetadata.width ||
|
|
75
|
+
!sourceMetadata.height ||
|
|
76
|
+
sourceMetadata.width !== renderedMetadata.width ||
|
|
77
|
+
sourceMetadata.height !== renderedMetadata.height ||
|
|
78
|
+
sourceMetadata.channels !== renderedMetadata.channels) {
|
|
79
|
+
throw new Error("Image comparison requires identical dimensions and channels.");
|
|
80
|
+
}
|
|
81
|
+
const [sourcePixels, renderedPixels] = await Promise.all([
|
|
82
|
+
source.raw().toBuffer(),
|
|
83
|
+
rendered.raw().toBuffer(),
|
|
84
|
+
]);
|
|
85
|
+
if (sourcePixels.byteLength !== renderedPixels.byteLength) {
|
|
86
|
+
throw new Error("Image comparison buffers have different lengths.");
|
|
87
|
+
}
|
|
88
|
+
let difference = 0;
|
|
89
|
+
for (let index = 0; index < sourcePixels.length; index++) {
|
|
90
|
+
difference += Math.abs(sourcePixels[index] - renderedPixels[index]);
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
meanAbsoluteDifference: difference / sourcePixels.length,
|
|
94
|
+
width: sourceMetadata.width,
|
|
95
|
+
height: sourceMetadata.height,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/** Crops a bounded raster region without retaining the source image. */
|
|
99
|
+
export async function cropImageRegion(input) {
|
|
100
|
+
const maxInputBytes = input.maxInputBytes ?? 20 * 1024 * 1024;
|
|
101
|
+
const maxOutputPixels = input.maxOutputPixels ?? 16_000_000;
|
|
102
|
+
if (input.data.byteLength > maxInputBytes) {
|
|
103
|
+
throw new Error(`Image crop input exceeds ${maxInputBytes} bytes.`);
|
|
104
|
+
}
|
|
105
|
+
const region = Object.fromEntries(["left", "top", "width", "height"].map((key) => [
|
|
106
|
+
key,
|
|
107
|
+
Math.round(input[key]),
|
|
108
|
+
]));
|
|
109
|
+
if (region.left < 0 ||
|
|
110
|
+
region.top < 0 ||
|
|
111
|
+
region.width <= 0 ||
|
|
112
|
+
region.height <= 0 ||
|
|
113
|
+
region.width * region.height > maxOutputPixels) {
|
|
114
|
+
throw new Error("Image crop region is invalid or exceeds the pixel limit.");
|
|
115
|
+
}
|
|
116
|
+
const sharp = await loadSharp();
|
|
117
|
+
if (!sharp) {
|
|
118
|
+
throw new Error("Image cropping requires the optional sharp dependency.");
|
|
119
|
+
}
|
|
120
|
+
const pipeline = sharp(Buffer.from(input.data), { failOn: "none" });
|
|
121
|
+
const metadata = await pipeline.metadata();
|
|
122
|
+
if (!metadata.width ||
|
|
123
|
+
!metadata.height ||
|
|
124
|
+
region.left + region.width > metadata.width ||
|
|
125
|
+
region.top + region.height > metadata.height) {
|
|
126
|
+
throw new Error("Image crop region falls outside the source image.");
|
|
127
|
+
}
|
|
128
|
+
const data = await pipeline.extract(region).png().toBuffer();
|
|
129
|
+
return {
|
|
130
|
+
data: new Uint8Array(data),
|
|
131
|
+
mimeType: "image/png",
|
|
132
|
+
width: region.width,
|
|
133
|
+
height: region.height,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export async function readBoundedResponseBytes(response, maxBytes) {
|
|
137
|
+
if (!Number.isInteger(maxBytes) || maxBytes <= 0) {
|
|
138
|
+
throw new Error("maxBytes must be a positive integer.");
|
|
139
|
+
}
|
|
140
|
+
const contentLength = Number(response.headers.get("content-length"));
|
|
141
|
+
if (Number.isFinite(contentLength) && contentLength > maxBytes) {
|
|
142
|
+
throw new Error(`Remote artifact exceeds ${maxBytes} bytes.`);
|
|
143
|
+
}
|
|
144
|
+
if (!response.body)
|
|
145
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
146
|
+
const reader = response.body.getReader();
|
|
147
|
+
const chunks = [];
|
|
148
|
+
let total = 0;
|
|
149
|
+
while (true) {
|
|
150
|
+
const { done, value } = await reader.read();
|
|
151
|
+
if (done)
|
|
152
|
+
break;
|
|
153
|
+
total += value.byteLength;
|
|
154
|
+
if (total > maxBytes) {
|
|
155
|
+
await reader.cancel();
|
|
156
|
+
throw new Error(`Remote artifact exceeds ${maxBytes} bytes.`);
|
|
157
|
+
}
|
|
158
|
+
chunks.push(value);
|
|
159
|
+
}
|
|
160
|
+
const joined = new Uint8Array(total);
|
|
161
|
+
let offset = 0;
|
|
162
|
+
for (const chunk of chunks) {
|
|
163
|
+
joined.set(chunk, offset);
|
|
164
|
+
offset += chunk.byteLength;
|
|
165
|
+
}
|
|
166
|
+
return joined;
|
|
167
|
+
}
|
|
168
|
+
async function loadSharp() {
|
|
169
|
+
const specifier = "sharp";
|
|
170
|
+
try {
|
|
171
|
+
const module = (await import(/* @vite-ignore */ specifier));
|
|
172
|
+
return module.default ?? module;
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=media.js.map
|
|
@@ -0,0 +1 @@
|
|
|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C;AA2BD,KAAK,UAAU,SAAS;IACtB,MAAM,SAAS,GAAG,OAAO,CAAC;IAC1B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAEzD,CAAC;QACF,OAAO,MAAM,CAAC,OAAO,IAAK,MAAkC,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\n\nexport interface MediaFingerprint {\n sha256: string;\n byteLength: number;\n mimeType?: string;\n}\n\nexport function fingerprintMedia(\n data: Uint8Array,\n mimeType?: string,\n): MediaFingerprint {\n return {\n sha256: createHash(\"sha256\").update(data).digest(\"hex\"),\n byteLength: data.byteLength,\n ...(mimeType ? { mimeType } : {}),\n };\n}\n\nexport function extractCssColors(value: string): string[] {\n const colors = new Set<string>();\n const pattern =\n /(?:#[0-9a-f]{3,8}\\b|(?:rgb|hsl)a?\\([^)]*\\)|\\b(?:transparent|currentColor)\\b)/gi;\n for (const match of value.match(pattern) ?? []) colors.add(match.trim());\n return [...colors];\n}\n\nexport function rankColorSamples(\n samples: readonly string[],\n limit = 24,\n): string[] {\n const counts = new Map<string, number>();\n for (const sample of samples) {\n const normalized = sample.trim().replace(/\\s+/g, \" \").toLowerCase();\n if (\n !normalized ||\n normalized === \"rgba(0, 0, 0, 0)\" ||\n normalized === \"transparent\"\n )\n continue;\n counts.set(normalized, (counts.get(normalized) ?? 0) + 1);\n }\n return [...counts.entries()]\n .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))\n .slice(0, Math.max(1, limit))\n .map(([color]) => color);\n}\n\nexport async function extractDominantColors(\n data: Uint8Array,\n limit = 6,\n): Promise<string[]> {\n const sharp = await loadSharp();\n if (!sharp) {\n throw new Error(\n \"Image palette extraction requires the optional sharp dependency.\",\n );\n }\n const output = await sharp(Buffer.from(data), { failOn: \"none\" })\n .resize(64, 64, { fit: \"inside\" })\n .removeAlpha()\n .raw()\n .toBuffer({ resolveWithObject: true });\n const buckets = new Map<string, number>();\n for (let index = 0; index < output.data.length; index += 3) {\n const key = [\n output.data[index],\n output.data[index + 1],\n output.data[index + 2],\n ]\n .map((channel) => Math.round(channel / 32) * 32)\n .map((channel) =>\n Math.max(0, Math.min(255, channel)).toString(16).padStart(2, \"0\"),\n )\n .join(\"\");\n buckets.set(key, (buckets.get(key) ?? 0) + 1);\n }\n return [...buckets.entries()]\n .sort((a, b) => b[1] - a[1])\n .slice(0, Math.max(1, limit))\n .map(([hex]) => `#${hex.toUpperCase()}`);\n}\n\nexport interface CroppedImageRegion {\n data: Uint8Array;\n mimeType: \"image/png\";\n width: number;\n height: number;\n}\n\nexport async function compareRasterImages(input: {\n source: Uint8Array;\n rendered: Uint8Array;\n maxInputBytes?: number;\n}): Promise<{ meanAbsoluteDifference: number; width: number; height: number }> {\n const maxInputBytes = input.maxInputBytes ?? 20 * 1024 * 1024;\n if (\n input.source.byteLength > maxInputBytes ||\n input.rendered.byteLength > maxInputBytes\n ) {\n throw new Error(`Image comparison input exceeds ${maxInputBytes} bytes.`);\n }\n const sharp = await loadSharp();\n if (!sharp) {\n throw new Error(\"Image comparison requires the optional sharp dependency.\");\n }\n const source = sharp(Buffer.from(input.source), { failOn: \"none\" });\n const rendered = sharp(Buffer.from(input.rendered), { failOn: \"none\" });\n const [sourceMetadata, renderedMetadata] = await Promise.all([\n source.metadata(),\n rendered.metadata(),\n ]);\n if (\n !sourceMetadata.width ||\n !sourceMetadata.height ||\n sourceMetadata.width !== renderedMetadata.width ||\n sourceMetadata.height !== renderedMetadata.height ||\n sourceMetadata.channels !== renderedMetadata.channels\n ) {\n throw new Error(\n \"Image comparison requires identical dimensions and channels.\",\n );\n }\n const [sourcePixels, renderedPixels] = await Promise.all([\n source.raw().toBuffer(),\n rendered.raw().toBuffer(),\n ]);\n if (sourcePixels.byteLength !== renderedPixels.byteLength) {\n throw new Error(\"Image comparison buffers have different lengths.\");\n }\n let difference = 0;\n for (let index = 0; index < sourcePixels.length; index++) {\n difference += Math.abs(sourcePixels[index]! - renderedPixels[index]!);\n }\n return {\n meanAbsoluteDifference: difference / sourcePixels.length,\n width: sourceMetadata.width,\n height: sourceMetadata.height,\n };\n}\n\n/** Crops a bounded raster region without retaining the source image. */\nexport async function cropImageRegion(input: {\n data: Uint8Array;\n left: number;\n top: number;\n width: number;\n height: number;\n maxInputBytes?: number;\n maxOutputPixels?: number;\n}): Promise<CroppedImageRegion> {\n const maxInputBytes = input.maxInputBytes ?? 20 * 1024 * 1024;\n const maxOutputPixels = input.maxOutputPixels ?? 16_000_000;\n if (input.data.byteLength > maxInputBytes) {\n throw new Error(`Image crop input exceeds ${maxInputBytes} bytes.`);\n }\n const region = Object.fromEntries(\n ([\"left\", \"top\", \"width\", \"height\"] as const).map((key) => [\n key,\n Math.round(input[key]),\n ]),\n ) as { left: number; top: number; width: number; height: number };\n if (\n region.left < 0 ||\n region.top < 0 ||\n region.width <= 0 ||\n region.height <= 0 ||\n region.width * region.height > maxOutputPixels\n ) {\n throw new Error(\"Image crop region is invalid or exceeds the pixel limit.\");\n }\n const sharp = await loadSharp();\n if (!sharp) {\n throw new Error(\"Image cropping requires the optional sharp dependency.\");\n }\n const pipeline = sharp(Buffer.from(input.data), { failOn: \"none\" });\n const metadata = await pipeline.metadata();\n if (\n !metadata.width ||\n !metadata.height ||\n region.left + region.width > metadata.width ||\n region.top + region.height > metadata.height\n ) {\n throw new Error(\"Image crop region falls outside the source image.\");\n }\n const data = await pipeline.extract(region).png().toBuffer();\n return {\n data: new Uint8Array(data),\n mimeType: \"image/png\",\n width: region.width,\n height: region.height,\n };\n}\n\nexport async function readBoundedResponseBytes(\n response: Response,\n maxBytes: number,\n): Promise<Uint8Array> {\n if (!Number.isInteger(maxBytes) || maxBytes <= 0) {\n throw new Error(\"maxBytes must be a positive integer.\");\n }\n const contentLength = Number(response.headers.get(\"content-length\"));\n if (Number.isFinite(contentLength) && contentLength > maxBytes) {\n throw new Error(`Remote artifact exceeds ${maxBytes} bytes.`);\n }\n if (!response.body) return new Uint8Array(await response.arrayBuffer());\n const reader = response.body.getReader();\n const chunks: Uint8Array[] = [];\n let total = 0;\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n total += value.byteLength;\n if (total > maxBytes) {\n await reader.cancel();\n throw new Error(`Remote artifact exceeds ${maxBytes} bytes.`);\n }\n chunks.push(value);\n }\n const joined = new Uint8Array(total);\n let offset = 0;\n for (const chunk of chunks) {\n joined.set(chunk, offset);\n offset += chunk.byteLength;\n }\n return joined;\n}\n\ninterface SharpPipeline {\n resize(\n width: number,\n height: number,\n options: { fit: \"inside\" },\n ): SharpPipeline;\n removeAlpha(): SharpPipeline;\n metadata(): Promise<{ width?: number; height?: number; channels?: number }>;\n extract(region: {\n left: number;\n top: number;\n width: number;\n height: number;\n }): SharpPipeline;\n png(): SharpPipeline;\n toBuffer(): Promise<Buffer>;\n raw(): SharpPipeline;\n toBuffer(options: { resolveWithObject: true }): Promise<{ data: Uint8Array }>;\n}\n\ntype SharpFactory = (\n data: Buffer,\n options: { failOn: \"none\" },\n) => SharpPipeline;\n\nasync function loadSharp(): Promise<SharpFactory | null> {\n const specifier = \"sharp\";\n try {\n const module = (await import(/* @vite-ignore */ specifier)) as {\n default?: SharpFactory;\n };\n return module.default ?? (module as unknown as SharpFactory);\n } catch {\n return null;\n }\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface NotionMarkdownSection {
|
|
2
|
+
heading: string | null;
|
|
3
|
+
headingLevel: number | null;
|
|
4
|
+
markdown: string;
|
|
5
|
+
}
|
|
6
|
+
export interface NotionMarkdownResult {
|
|
7
|
+
markdown: string;
|
|
8
|
+
sections: NotionMarkdownSection[];
|
|
9
|
+
}
|
|
10
|
+
export declare function notionBlocksToMarkdown(blocks: readonly unknown[]): NotionMarkdownResult;
|
|
11
|
+
export declare function notionBlockToMarkdown(block: Record<string, unknown>, type?: string): string;
|
|
12
|
+
//# sourceMappingURL=notion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notion.d.ts","sourceRoot":"","sources":["../../src/ingestion/notion.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,qBAAqB,EAAE,CAAC;CACnC;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,SAAS,OAAO,EAAE,GACzB,oBAAoB,CAmCtB;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,IAAI,SAAgC,GACnC,MAAM,CA2CR"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export function notionBlocksToMarkdown(blocks) {
|
|
2
|
+
const sections = [];
|
|
3
|
+
let current = {
|
|
4
|
+
heading: null,
|
|
5
|
+
headingLevel: null,
|
|
6
|
+
markdown: "",
|
|
7
|
+
};
|
|
8
|
+
const flush = () => {
|
|
9
|
+
const markdown = current.markdown.trim();
|
|
10
|
+
if (markdown)
|
|
11
|
+
sections.push({ ...current, markdown });
|
|
12
|
+
};
|
|
13
|
+
for (const value of blocks) {
|
|
14
|
+
const block = asRecord(value);
|
|
15
|
+
const type = stringValue(block?.type);
|
|
16
|
+
if (!block || !type)
|
|
17
|
+
continue;
|
|
18
|
+
const line = notionBlockToMarkdown(block, type);
|
|
19
|
+
if (!line)
|
|
20
|
+
continue;
|
|
21
|
+
const heading = type.match(/^heading_([1-3])$/);
|
|
22
|
+
if (heading) {
|
|
23
|
+
flush();
|
|
24
|
+
const headingLevel = Number(heading[1]);
|
|
25
|
+
current = {
|
|
26
|
+
heading: richText(asRecord(block[type])?.rich_text),
|
|
27
|
+
headingLevel,
|
|
28
|
+
markdown: line,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
current.markdown += `${current.markdown ? "\n\n" : ""}${line}`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
flush();
|
|
36
|
+
return {
|
|
37
|
+
markdown: sections.map((section) => section.markdown).join("\n\n"),
|
|
38
|
+
sections,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function notionBlockToMarkdown(block, type = stringValue(block.type) ?? "") {
|
|
42
|
+
const payload = asRecord(block[type]) ?? {};
|
|
43
|
+
const text = richText(payload.rich_text);
|
|
44
|
+
switch (type) {
|
|
45
|
+
case "heading_1":
|
|
46
|
+
case "heading_2":
|
|
47
|
+
case "heading_3":
|
|
48
|
+
return `${"#".repeat(Number(type.slice(-1)))} ${text}`.trim();
|
|
49
|
+
case "bulleted_list_item":
|
|
50
|
+
return `- ${text}`.trim();
|
|
51
|
+
case "numbered_list_item":
|
|
52
|
+
return `1. ${text}`.trim();
|
|
53
|
+
case "to_do":
|
|
54
|
+
return `- [${payload.checked === true ? "x" : " "}] ${text}`.trim();
|
|
55
|
+
case "quote":
|
|
56
|
+
return text
|
|
57
|
+
.split("\n")
|
|
58
|
+
.map((line) => `> ${line}`)
|
|
59
|
+
.join("\n");
|
|
60
|
+
case "code":
|
|
61
|
+
return `\`\`\`${stringValue(payload.language) ?? ""}\n${text}\n\`\`\``;
|
|
62
|
+
case "divider":
|
|
63
|
+
return "---";
|
|
64
|
+
case "bookmark":
|
|
65
|
+
case "embed": {
|
|
66
|
+
const url = stringValue(payload.url);
|
|
67
|
+
return url ? `[${url}](${url})` : "";
|
|
68
|
+
}
|
|
69
|
+
case "child_page":
|
|
70
|
+
return `## ${stringValue(payload.title) ?? "Untitled page"}`;
|
|
71
|
+
case "image":
|
|
72
|
+
case "video":
|
|
73
|
+
case "audio":
|
|
74
|
+
case "file":
|
|
75
|
+
case "pdf": {
|
|
76
|
+
const file = asRecord(payload.file) ?? asRecord(payload.external);
|
|
77
|
+
const url = stringValue(file?.url);
|
|
78
|
+
const caption = richText(payload.caption) || type;
|
|
79
|
+
return url ? `` : caption;
|
|
80
|
+
}
|
|
81
|
+
default:
|
|
82
|
+
return text;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function richText(value) {
|
|
86
|
+
return (Array.isArray(value) ? value : [])
|
|
87
|
+
.map((part) => {
|
|
88
|
+
const record = asRecord(part);
|
|
89
|
+
return (stringValue(record?.plain_text) ??
|
|
90
|
+
stringValue(asRecord(record?.text)?.content) ??
|
|
91
|
+
"");
|
|
92
|
+
})
|
|
93
|
+
.join("")
|
|
94
|
+
.trim();
|
|
95
|
+
}
|
|
96
|
+
function asRecord(value) {
|
|
97
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
98
|
+
? value
|
|
99
|
+
: null;
|
|
100
|
+
}
|
|
101
|
+
function stringValue(value) {
|
|
102
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=notion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notion.js","sourceRoot":"","sources":["../../src/ingestion/notion.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,sBAAsB,CACpC,MAA0B;IAE1B,MAAM,QAAQ,GAA4B,EAAE,CAAC;IAC7C,IAAI,OAAO,GAA0B;QACnC,OAAO,EAAE,IAAI;QACb,YAAY,EAAE,IAAI;QAClB,QAAQ,EAAE,EAAE;KACb,CAAC;IACF,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACzC,IAAI,QAAQ;YAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;IACxD,CAAC,CAAC;IACF,KAAK,MAAM,KAAK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CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9E,CAAC","sourcesContent":["export interface NotionMarkdownSection {\n heading: string | null;\n headingLevel: number | null;\n markdown: string;\n}\n\nexport interface NotionMarkdownResult {\n markdown: string;\n sections: NotionMarkdownSection[];\n}\n\nexport function notionBlocksToMarkdown(\n blocks: readonly unknown[],\n): NotionMarkdownResult {\n const sections: NotionMarkdownSection[] = [];\n let current: NotionMarkdownSection = {\n heading: null,\n headingLevel: null,\n markdown: \"\",\n };\n const flush = () => {\n const markdown = current.markdown.trim();\n if (markdown) sections.push({ ...current, markdown });\n };\n for (const value of blocks) {\n const block = asRecord(value);\n const type = stringValue(block?.type);\n if (!block || !type) continue;\n const line = notionBlockToMarkdown(block, type);\n if (!line) continue;\n const heading = type.match(/^heading_([1-3])$/);\n if (heading) {\n flush();\n const headingLevel = Number(heading[1]);\n current = {\n heading: richText(asRecord(block[type])?.rich_text),\n headingLevel,\n markdown: line,\n };\n } else {\n current.markdown += `${current.markdown ? \"\\n\\n\" : \"\"}${line}`;\n }\n }\n flush();\n return {\n markdown: sections.map((section) => section.markdown).join(\"\\n\\n\"),\n sections,\n };\n}\n\nexport function notionBlockToMarkdown(\n block: Record<string, unknown>,\n type = stringValue(block.type) ?? \"\",\n): string {\n const payload = asRecord(block[type]) ?? {};\n const text = richText(payload.rich_text);\n switch (type) {\n case \"heading_1\":\n case \"heading_2\":\n case \"heading_3\":\n return `${\"#\".repeat(Number(type.slice(-1)))} ${text}`.trim();\n case \"bulleted_list_item\":\n return `- ${text}`.trim();\n case \"numbered_list_item\":\n return `1. ${text}`.trim();\n case \"to_do\":\n return `- [${payload.checked === true ? \"x\" : \" \"}] ${text}`.trim();\n case \"quote\":\n return text\n .split(\"\\n\")\n .map((line) => `> ${line}`)\n .join(\"\\n\");\n case \"code\":\n return `\\`\\`\\`${stringValue(payload.language) ?? \"\"}\\n${text}\\n\\`\\`\\``;\n case \"divider\":\n return \"---\";\n case \"bookmark\":\n case \"embed\": {\n const url = stringValue(payload.url);\n return url ? `[${url}](${url})` : \"\";\n }\n case \"child_page\":\n return `## ${stringValue(payload.title) ?? \"Untitled page\"}`;\n case \"image\":\n case \"video\":\n case \"audio\":\n case \"file\":\n case \"pdf\": {\n const file = asRecord(payload.file) ?? asRecord(payload.external);\n const url = stringValue(file?.url);\n const caption = richText(payload.caption) || type;\n return url ? `` : caption;\n }\n default:\n return text;\n }\n}\n\nfunction richText(value: unknown): string {\n return (Array.isArray(value) ? value : [])\n .map((part) => {\n const record = asRecord(part);\n return (\n stringValue(record?.plain_text) ??\n stringValue(asRecord(record?.text)?.content) ??\n \"\"\n );\n })\n .join(\"\")\n .trim();\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | null {\n return value && typeof value === \"object\" && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : null;\n}\n\nfunction stringValue(value: unknown): string | undefined {\n return typeof value === \"string\" && value.trim() ? value.trim() : undefined;\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type OfficeDocumentType = "pptx" | "docx" | "pdf" | "txt" | "md" | "csv";
|
|
2
|
+
export interface ParseOfficeDocumentInput {
|
|
3
|
+
data: Uint8Array;
|
|
4
|
+
fileName: string;
|
|
5
|
+
mimeType?: string;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
}
|
|
8
|
+
export interface ParsedOfficeDocument {
|
|
9
|
+
text: string;
|
|
10
|
+
fileType: OfficeDocumentType;
|
|
11
|
+
title: string;
|
|
12
|
+
parser: "structured-pptx" | "mammoth-docx" | "officeparser-pdf" | "plain-text";
|
|
13
|
+
parts: OfficeDocumentPart[];
|
|
14
|
+
metadata: Record<string, unknown>;
|
|
15
|
+
warnings: string[];
|
|
16
|
+
}
|
|
17
|
+
export interface OfficeDocumentPart {
|
|
18
|
+
kind: "slide" | "section" | "page" | "document";
|
|
19
|
+
index: number;
|
|
20
|
+
title: string;
|
|
21
|
+
text: string;
|
|
22
|
+
notes?: string;
|
|
23
|
+
textRuns?: ParsedPptxTextRun[];
|
|
24
|
+
images?: ParsedPptxImage[];
|
|
25
|
+
metadata?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
export interface OfficeDocumentAst {
|
|
28
|
+
type?: string;
|
|
29
|
+
metadata?: Record<string, unknown>;
|
|
30
|
+
warnings?: unknown[];
|
|
31
|
+
toText(): string | Promise<string>;
|
|
32
|
+
}
|
|
33
|
+
export interface OfficeDocumentParser {
|
|
34
|
+
parseOffice(data: Uint8Array, options: {
|
|
35
|
+
fileType: OfficeDocumentType;
|
|
36
|
+
abortSignal?: AbortSignal;
|
|
37
|
+
extractAttachments: boolean;
|
|
38
|
+
ignoreNotes: boolean;
|
|
39
|
+
}): Promise<OfficeDocumentAst>;
|
|
40
|
+
}
|
|
41
|
+
export declare function parseOfficeDocument(input: ParseOfficeDocumentInput, parser?: OfficeDocumentParser): Promise<ParsedOfficeDocument>;
|
|
42
|
+
export declare function detectOfficeDocumentType(fileName: string, mimeType?: string): OfficeDocumentType;
|
|
43
|
+
export declare function normalizeDocumentText(value: string): string;
|
|
44
|
+
import { type ParsedPptxImage, type ParsedPptxTextRun } from "./pptx.js";
|
|
45
|
+
//# sourceMappingURL=office.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"office.d.ts","sourceRoot":"","sources":["../../src/ingestion/office.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,CAAC;AAEhF,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB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CAAC;CAC/B;AAED,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,wBAAwB,EAC/B,MAAM,CAAC,EAAE,oBAAoB,GAC5B,OAAO,CAAC,oBAAoB,CAAC,CAyG/B;AAED,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,MAAM,GAChB,kBAAkB,CAapB;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO3D;AAqBD,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACvB,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
export async function parseOfficeDocument(input, parser) {
|
|
2
|
+
const fileType = detectOfficeDocumentType(input.fileName, input.mimeType);
|
|
3
|
+
if (fileType === "txt" || fileType === "md" || fileType === "csv") {
|
|
4
|
+
const text = normalizeDocumentText(new TextDecoder().decode(input.data));
|
|
5
|
+
return {
|
|
6
|
+
text,
|
|
7
|
+
fileType,
|
|
8
|
+
title: input.fileName,
|
|
9
|
+
parser: "plain-text",
|
|
10
|
+
parts: [{ kind: "document", index: 0, title: input.fileName, text }],
|
|
11
|
+
metadata: {},
|
|
12
|
+
warnings: [],
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (fileType === "pptx") {
|
|
16
|
+
const presentation = await parsePptxPresentation(input.data);
|
|
17
|
+
const parts = presentation.slides.map((slide, index) => {
|
|
18
|
+
const body = normalizeDocumentText(slide.texts.map((run) => run.content).join("\n"));
|
|
19
|
+
return {
|
|
20
|
+
kind: "slide",
|
|
21
|
+
index,
|
|
22
|
+
title: slide.texts
|
|
23
|
+
.find((run) => run.content.trim())
|
|
24
|
+
?.content.trim()
|
|
25
|
+
.slice(0, 160) ?? `Slide ${index + 1}`,
|
|
26
|
+
text: normalizeDocumentText([body, slide.notes ? `Speaker notes\n${slide.notes}` : ""]
|
|
27
|
+
.filter(Boolean)
|
|
28
|
+
.join("\n\n")),
|
|
29
|
+
notes: slide.notes,
|
|
30
|
+
textRuns: slide.texts,
|
|
31
|
+
images: slide.images,
|
|
32
|
+
metadata: {
|
|
33
|
+
layoutHint: slide.layoutHint,
|
|
34
|
+
theme: presentation.theme,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
text: parts.map((part) => part.text).join("\n\n"),
|
|
40
|
+
fileType,
|
|
41
|
+
title: presentation.title,
|
|
42
|
+
parser: "structured-pptx",
|
|
43
|
+
parts,
|
|
44
|
+
metadata: { theme: presentation.theme, slideCount: parts.length },
|
|
45
|
+
warnings: [],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (fileType === "docx") {
|
|
49
|
+
const document = await parseDocxDocument(input.data);
|
|
50
|
+
const parts = document.sections.map((section, index) => {
|
|
51
|
+
const html = sanitizeInertDocumentHtml(section.html);
|
|
52
|
+
return {
|
|
53
|
+
kind: "section",
|
|
54
|
+
index,
|
|
55
|
+
title: section.heading || `Section ${index + 1}`,
|
|
56
|
+
text: normalizeDocumentText([section.heading, section.text].filter(Boolean).join("\n\n")),
|
|
57
|
+
metadata: { html },
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
text: normalizeDocumentText(document.text),
|
|
62
|
+
fileType,
|
|
63
|
+
title: document.title,
|
|
64
|
+
parser: "mammoth-docx",
|
|
65
|
+
parts,
|
|
66
|
+
metadata: { sectionCount: parts.length },
|
|
67
|
+
warnings: [],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const resolvedParser = parser ?? (await loadOfficeParser());
|
|
71
|
+
if (!resolvedParser) {
|
|
72
|
+
throw new Error(`Parsing ${fileType.toUpperCase()} uploads requires the optional officeparser dependency.`);
|
|
73
|
+
}
|
|
74
|
+
const ast = await resolvedParser.parseOffice(input.data, {
|
|
75
|
+
fileType,
|
|
76
|
+
abortSignal: input.signal,
|
|
77
|
+
extractAttachments: false,
|
|
78
|
+
ignoreNotes: false,
|
|
79
|
+
});
|
|
80
|
+
const text = normalizeDocumentText(await ast.toText());
|
|
81
|
+
const pages = text.split(/\f+/).map(normalizeDocumentText).filter(Boolean);
|
|
82
|
+
const parts = (pages.length > 0 ? pages : [text]).map((page, index) => ({
|
|
83
|
+
kind: "page",
|
|
84
|
+
index,
|
|
85
|
+
title: `Page ${index + 1}`,
|
|
86
|
+
text: page,
|
|
87
|
+
}));
|
|
88
|
+
return {
|
|
89
|
+
text,
|
|
90
|
+
fileType: isOfficeDocumentType(ast.type) ? ast.type : fileType,
|
|
91
|
+
title: input.fileName,
|
|
92
|
+
parser: "officeparser-pdf",
|
|
93
|
+
parts,
|
|
94
|
+
metadata: ast.metadata ?? {},
|
|
95
|
+
warnings: (ast.warnings ?? []).map(String),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export function detectOfficeDocumentType(fileName, mimeType) {
|
|
99
|
+
const mime = mimeType?.toLowerCase() ?? "";
|
|
100
|
+
if (mime.includes("presentationml"))
|
|
101
|
+
return "pptx";
|
|
102
|
+
if (mime.includes("wordprocessingml"))
|
|
103
|
+
return "docx";
|
|
104
|
+
if (mime.includes("pdf"))
|
|
105
|
+
return "pdf";
|
|
106
|
+
if (mime.includes("markdown"))
|
|
107
|
+
return "md";
|
|
108
|
+
if (mime.includes("csv"))
|
|
109
|
+
return "csv";
|
|
110
|
+
if (mime.startsWith("text/"))
|
|
111
|
+
return "txt";
|
|
112
|
+
const extension = fileName.toLowerCase().match(/\.([a-z0-9]+)$/)?.[1];
|
|
113
|
+
if (isOfficeDocumentType(extension))
|
|
114
|
+
return extension;
|
|
115
|
+
throw new Error(`Unsupported upload type ${mimeType ?? extension ?? "unknown"}; supported formats are PPTX, DOCX, PDF, and text.`);
|
|
116
|
+
}
|
|
117
|
+
export function normalizeDocumentText(value) {
|
|
118
|
+
return value
|
|
119
|
+
.replace(/\r\n?/g, "\n")
|
|
120
|
+
.replace(/[\t\f\v ]+/g, " ")
|
|
121
|
+
.replace(/ *\n */g, "\n")
|
|
122
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
123
|
+
.trim();
|
|
124
|
+
}
|
|
125
|
+
async function loadOfficeParser() {
|
|
126
|
+
const specifier = "officeparser";
|
|
127
|
+
try {
|
|
128
|
+
const module = (await import(specifier));
|
|
129
|
+
return module.OfficeParser ?? null;
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function isOfficeDocumentType(value) {
|
|
136
|
+
return (typeof value === "string" &&
|
|
137
|
+
["pptx", "docx", "pdf", "txt", "md", "csv"].includes(value));
|
|
138
|
+
}
|
|
139
|
+
import { parseDocxDocument, sanitizeInertDocumentHtml } from "./docx.js";
|
|
140
|
+
import { parsePptxPresentation, } from "./pptx.js";
|
|
141
|
+
//# sourceMappingURL=office.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"office.js","sourceRoot":"","sources":["../../src/ingestion/office.ts"],"names":[],"mappings":"AAqDA,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,KAA+B,EAC/B,MAA6B;IAE7B,MAAM,QAAQ,GAAG,wBAAwB,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC1E,IAAI,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;QAClE,MAAM,IAAI,GAAG,qBAAqB,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACzE,OAAO;YACL,IAAI;YACJ,QAAQ;YACR,KAAK,EAAE,KAAK,CAAC,QAAQ;YACrB,MAAM,EAAE,YAAY;YACpB,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,QAAQ,EA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AC;AAED,KAAK,UAAU,gBAAgB;IAC7B,MAAM,SAAS,GAAG,cAAc,CAAC;IACjC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,SAAS,CAAC,CAEtC,CAAC;QACF,OAAO,MAAM,CAAC,YAAY,IAAI,IAAI,CAAC;IACrC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAc;IAC1C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACxB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAC1E,CAAC;AACJ,CAAC;AACD,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AACzE,OAAO,EACL,qBAAqB,GAGtB,MAAM,WAAW,CAAC","sourcesContent":["export type OfficeDocumentType = \"pptx\" | \"docx\" | \"pdf\" | \"txt\" | \"md\" | \"csv\";\n\nexport interface ParseOfficeDocumentInput {\n data: Uint8Array;\n fileName: string;\n mimeType?: string;\n signal?: AbortSignal;\n}\n\nexport interface ParsedOfficeDocument {\n text: string;\n fileType: OfficeDocumentType;\n title: string;\n parser:\n | \"structured-pptx\"\n | \"mammoth-docx\"\n | \"officeparser-pdf\"\n | \"plain-text\";\n parts: OfficeDocumentPart[];\n metadata: Record<string, unknown>;\n warnings: string[];\n}\n\nexport interface OfficeDocumentPart {\n kind: \"slide\" | \"section\" | \"page\" | \"document\";\n index: number;\n title: string;\n text: string;\n notes?: string;\n textRuns?: ParsedPptxTextRun[];\n images?: ParsedPptxImage[];\n metadata?: Record<string, unknown>;\n}\n\nexport interface OfficeDocumentAst {\n type?: string;\n metadata?: Record<string, unknown>;\n warnings?: unknown[];\n toText(): string | Promise<string>;\n}\n\nexport interface OfficeDocumentParser {\n parseOffice(\n data: Uint8Array,\n options: {\n fileType: OfficeDocumentType;\n abortSignal?: AbortSignal;\n extractAttachments: boolean;\n ignoreNotes: boolean;\n },\n ): Promise<OfficeDocumentAst>;\n}\n\nexport async function parseOfficeDocument(\n input: ParseOfficeDocumentInput,\n parser?: OfficeDocumentParser,\n): Promise<ParsedOfficeDocument> {\n const fileType = detectOfficeDocumentType(input.fileName, input.mimeType);\n if (fileType === \"txt\" || fileType === \"md\" || fileType === \"csv\") {\n const text = normalizeDocumentText(new TextDecoder().decode(input.data));\n return {\n text,\n fileType,\n title: input.fileName,\n parser: \"plain-text\",\n parts: [{ kind: \"document\", index: 0, title: input.fileName, text }],\n metadata: {},\n warnings: [],\n };\n }\n if (fileType === \"pptx\") {\n const presentation = await parsePptxPresentation(input.data);\n const parts = presentation.slides.map((slide, index) => {\n const body = normalizeDocumentText(\n slide.texts.map((run) => run.content).join(\"\\n\"),\n );\n return {\n kind: \"slide\" as const,\n index,\n title:\n slide.texts\n .find((run) => run.content.trim())\n ?.content.trim()\n .slice(0, 160) ?? `Slide ${index + 1}`,\n text: normalizeDocumentText(\n [body, slide.notes ? `Speaker notes\\n${slide.notes}` : \"\"]\n .filter(Boolean)\n .join(\"\\n\\n\"),\n ),\n notes: slide.notes,\n textRuns: slide.texts,\n images: slide.images,\n metadata: {\n layoutHint: slide.layoutHint,\n theme: presentation.theme,\n },\n };\n });\n return {\n text: parts.map((part) => part.text).join(\"\\n\\n\"),\n fileType,\n title: presentation.title,\n parser: \"structured-pptx\",\n parts,\n metadata: { theme: presentation.theme, slideCount: parts.length },\n warnings: [],\n };\n }\n if (fileType === \"docx\") {\n const document = await parseDocxDocument(input.data);\n const parts = document.sections.map((section, index) => {\n const html = sanitizeInertDocumentHtml(section.html);\n return {\n kind: \"section\" as const,\n index,\n title: section.heading || `Section ${index + 1}`,\n text: normalizeDocumentText(\n [section.heading, section.text].filter(Boolean).join(\"\\n\\n\"),\n ),\n metadata: { html },\n };\n });\n return {\n text: normalizeDocumentText(document.text),\n fileType,\n title: document.title,\n parser: \"mammoth-docx\",\n parts,\n metadata: { sectionCount: parts.length },\n warnings: [],\n };\n }\n const resolvedParser = parser ?? (await loadOfficeParser());\n if (!resolvedParser) {\n throw new Error(\n `Parsing ${fileType.toUpperCase()} uploads requires the optional officeparser dependency.`,\n );\n }\n const ast = await resolvedParser.parseOffice(input.data, {\n fileType,\n abortSignal: input.signal,\n extractAttachments: false,\n ignoreNotes: false,\n });\n const text = normalizeDocumentText(await ast.toText());\n const pages = text.split(/\\f+/).map(normalizeDocumentText).filter(Boolean);\n const parts = (pages.length > 0 ? pages : [text]).map((page, index) => ({\n kind: \"page\" as const,\n index,\n title: `Page ${index + 1}`,\n text: page,\n }));\n return {\n text,\n fileType: isOfficeDocumentType(ast.type) ? ast.type : fileType,\n title: input.fileName,\n parser: \"officeparser-pdf\",\n parts,\n metadata: ast.metadata ?? {},\n warnings: (ast.warnings ?? []).map(String),\n };\n}\n\nexport function detectOfficeDocumentType(\n fileName: string,\n mimeType?: string,\n): OfficeDocumentType {\n const mime = mimeType?.toLowerCase() ?? \"\";\n if (mime.includes(\"presentationml\")) return \"pptx\";\n if (mime.includes(\"wordprocessingml\")) return \"docx\";\n if (mime.includes(\"pdf\")) return \"pdf\";\n if (mime.includes(\"markdown\")) return \"md\";\n if (mime.includes(\"csv\")) return \"csv\";\n if (mime.startsWith(\"text/\")) return \"txt\";\n const extension = fileName.toLowerCase().match(/\\.([a-z0-9]+)$/)?.[1];\n if (isOfficeDocumentType(extension)) return extension;\n throw new Error(\n `Unsupported upload type ${mimeType ?? extension ?? \"unknown\"}; supported formats are PPTX, DOCX, PDF, and text.`,\n );\n}\n\nexport function normalizeDocumentText(value: string): string {\n return value\n .replace(/\\r\\n?/g, \"\\n\")\n .replace(/[\\t\\f\\v ]+/g, \" \")\n .replace(/ *\\n */g, \"\\n\")\n .replace(/\\n{3,}/g, \"\\n\\n\")\n .trim();\n}\n\nasync function loadOfficeParser(): Promise<OfficeDocumentParser | null> {\n const specifier = \"officeparser\";\n try {\n const module = (await import(specifier)) as {\n OfficeParser?: OfficeDocumentParser;\n };\n return module.OfficeParser ?? null;\n } catch {\n return null;\n }\n}\n\nfunction isOfficeDocumentType(value: unknown): value is OfficeDocumentType {\n return (\n typeof value === \"string\" &&\n ([\"pptx\", \"docx\", \"pdf\", \"txt\", \"md\", \"csv\"] as string[]).includes(value)\n );\n}\nimport { parseDocxDocument, sanitizeInertDocumentHtml } from \"./docx.js\";\nimport {\n parsePptxPresentation,\n type ParsedPptxImage,\n type ParsedPptxTextRun,\n} from \"./pptx.js\";\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export type IngestionPhase = "inventory" | "fetch" | "completed";
|
|
2
|
+
export interface IngestionCheckpoint {
|
|
3
|
+
phase: IngestionPhase;
|
|
4
|
+
cursor: string | null;
|
|
5
|
+
inventoryComplete: boolean;
|
|
6
|
+
itemOffset: number;
|
|
7
|
+
itemsInventoried: number;
|
|
8
|
+
itemsProcessed: number;
|
|
9
|
+
itemsFailed: number;
|
|
10
|
+
}
|
|
11
|
+
export interface IngestionLease {
|
|
12
|
+
owner: string;
|
|
13
|
+
token: string;
|
|
14
|
+
acquiredAt: number;
|
|
15
|
+
expiresAt: number;
|
|
16
|
+
}
|
|
17
|
+
export interface AcquireIngestionLeaseInput {
|
|
18
|
+
owner: string;
|
|
19
|
+
token: string;
|
|
20
|
+
ttlMs: number;
|
|
21
|
+
now?: number;
|
|
22
|
+
}
|
|
23
|
+
export type AcquireIngestionLeaseResult = {
|
|
24
|
+
acquired: true;
|
|
25
|
+
lease: IngestionLease;
|
|
26
|
+
} | {
|
|
27
|
+
acquired: false;
|
|
28
|
+
lease: IngestionLease;
|
|
29
|
+
};
|
|
30
|
+
export interface IngestionBudgetLimits {
|
|
31
|
+
runtimeMs: number;
|
|
32
|
+
itemBudget: number;
|
|
33
|
+
batchBudget: number;
|
|
34
|
+
}
|
|
35
|
+
export interface IngestionBudgetState {
|
|
36
|
+
startedAt: number;
|
|
37
|
+
items: number;
|
|
38
|
+
batches: number;
|
|
39
|
+
}
|
|
40
|
+
export type IngestionBudgetStopReason = "runtime" | "items" | "batches" | null;
|
|
41
|
+
export declare function createIngestionCheckpoint(): IngestionCheckpoint;
|
|
42
|
+
export declare function acquireIngestionLease(current: IngestionLease | null | undefined, input: AcquireIngestionLeaseInput): AcquireIngestionLeaseResult;
|
|
43
|
+
export declare function renewIngestionLease(current: IngestionLease, input: Pick<AcquireIngestionLeaseInput, "token" | "ttlMs" | "now">): IngestionLease | null;
|
|
44
|
+
export declare function releaseIngestionLease(current: IngestionLease | null | undefined, token: string): null | IngestionLease;
|
|
45
|
+
export declare function createIngestionBudgetState(now?: number): IngestionBudgetState;
|
|
46
|
+
export declare function consumeIngestionBudget(state: IngestionBudgetState, input: {
|
|
47
|
+
items?: number;
|
|
48
|
+
batches?: number;
|
|
49
|
+
}): IngestionBudgetState;
|
|
50
|
+
export declare function ingestionBudgetStopReason(limits: IngestionBudgetLimits, state: IngestionBudgetState, now?: number): IngestionBudgetStopReason;
|
|
51
|
+
export declare function assertInventoryComplete(checkpoint: Pick<IngestionCheckpoint, "inventoryComplete">): void;
|
|
52
|
+
//# sourceMappingURL=orchestration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestration.d.ts","sourceRoot":"","sources":["../../src/ingestion/orchestration.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,OAAO,GAAG,WAAW,CAAC;AAEjE,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,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