@lapis-notes/api 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/CHANGELOG.md +9 -0
- package/LICENSE.md +4 -0
- package/README.md +43 -0
- package/dist/__tests__/data-adapter-conformance.js +205 -0
- package/dist/__tests__/lapis-runtime-manifest.js +32 -0
- package/dist/__tests__/svelte-internal-client.d.ts +3 -0
- package/dist/agent-result-views.d.ts +52 -0
- package/dist/agent-result-views.js +89 -0
- package/dist/agent-skills.d.ts +99 -0
- package/dist/agent-skills.js +182 -0
- package/dist/agent-tools.d.ts +92 -0
- package/dist/agent-tools.js +139 -0
- package/dist/app-database-host.d.ts +4 -0
- package/dist/app-database-host.js +4 -0
- package/dist/app-shell-plugin-persistence.d.ts +15 -0
- package/dist/app-shell-plugin-persistence.js +34 -0
- package/dist/app-url.d.ts +54 -0
- package/dist/app-url.js +269 -0
- package/dist/application-compatibility.d.ts +31 -0
- package/dist/application-compatibility.js +64 -0
- package/dist/application-state.svelte.d.ts +14 -0
- package/dist/application-state.svelte.js +30 -0
- package/dist/assets/lapis-logo.svg +471 -0
- package/dist/bases.d.ts +281 -0
- package/dist/bases.js +475 -0
- package/dist/cache.svelte.d.ts +569 -0
- package/dist/cache.svelte.js +1433 -0
- package/dist/command.svelte.d.ts +337 -0
- package/dist/command.svelte.js +571 -0
- package/dist/compat.d.ts +29 -0
- package/dist/compat.js +30 -0
- package/dist/components/configuration/configuration.css +199 -0
- package/dist/components/configuration/date-setting.svelte +71 -0
- package/dist/components/configuration/date-setting.svelte.d.ts +8 -0
- package/dist/components/configuration/list-setting.svelte +128 -0
- package/dist/components/configuration/list-setting.svelte.d.ts +13 -0
- package/dist/components/configuration/object-array-row-grip.svelte +78 -0
- package/dist/components/configuration/object-array-row-grip.svelte.d.ts +9 -0
- package/dist/components/configuration/object-array-row.svelte +163 -0
- package/dist/components/configuration/object-array-row.svelte.d.ts +19 -0
- package/dist/components/configuration/object-array-setting.svelte +196 -0
- package/dist/components/configuration/object-array-setting.svelte.d.ts +15 -0
- package/dist/components/configuration/object-array-table-dnd.d.ts +8 -0
- package/dist/components/configuration/object-array-table-dnd.js +10 -0
- package/dist/components/configuration/object-array-utils.d.ts +11 -0
- package/dist/components/configuration/object-array-utils.js +103 -0
- package/dist/components/configuration/object-grid-setting.svelte +79 -0
- package/dist/components/configuration/object-grid-setting.svelte.d.ts +10 -0
- package/dist/components/configuration/object-map-row.svelte +147 -0
- package/dist/components/configuration/object-map-row.svelte.d.ts +15 -0
- package/dist/components/configuration/object-map-setting.svelte +137 -0
- package/dist/components/configuration/object-map-setting.svelte.d.ts +14 -0
- package/dist/components/configuration/object-map-types.d.ts +5 -0
- package/dist/components/configuration/object-map-types.js +1 -0
- package/dist/components/configuration/options-combobox-setting.svelte +129 -0
- package/dist/components/configuration/options-combobox-setting.svelte.d.ts +12 -0
- package/dist/components/copy-button/button.svelte +93 -0
- package/dist/components/copy-button/button.svelte.d.ts +13 -0
- package/dist/components/copy-button/index.d.ts +2 -0
- package/dist/components/copy-button/index.js +2 -0
- package/dist/components/editor/editor.css +565 -0
- package/dist/components/editor/editor.d.ts +33 -0
- package/dist/components/editor/editor.js +132 -0
- package/dist/components/editor/editor.svelte +176 -0
- package/dist/components/editor/editor.svelte.d.ts +15 -0
- package/dist/components/editor/embedded-editor-surface.d.ts +12 -0
- package/dist/components/editor/embedded-editor-surface.js +22 -0
- package/dist/components/editor/embedded-editor-surface.svelte +115 -0
- package/dist/components/editor/embedded-editor-surface.svelte.d.ts +17 -0
- package/dist/components/editor/extensions/autocomplete/index.d.ts +2 -0
- package/dist/components/editor/extensions/autocomplete/index.js +2 -0
- package/dist/components/editor/extensions/autocomplete/lapis-code-mirror-autocomplete.d.ts +16 -0
- package/dist/components/editor/extensions/autocomplete/lapis-code-mirror-autocomplete.js +34 -0
- package/dist/components/editor/extensions/autocomplete/vault-completion-sources.d.ts +27 -0
- package/dist/components/editor/extensions/autocomplete/vault-completion-sources.js +55 -0
- package/dist/components/editor/extensions/class-highlighter/index.d.ts +1 -0
- package/dist/components/editor/extensions/class-highlighter/index.js +47 -0
- package/dist/components/editor/extensions/fold-gutter/index.d.ts +8 -0
- package/dist/components/editor/extensions/fold-gutter/index.js +40 -0
- package/dist/components/editor/extensions/gutter-line-style-sync/index.d.ts +2 -0
- package/dist/components/editor/extensions/gutter-line-style-sync/index.js +118 -0
- package/dist/components/editor/extensions/lint/index.d.ts +4 -0
- package/dist/components/editor/extensions/lint/index.js +4 -0
- package/dist/components/editor/extensions/lint/lapis-code-mirror-lint.d.ts +26 -0
- package/dist/components/editor/extensions/lint/lapis-code-mirror-lint.js +101 -0
- package/dist/components/editor/extensions/lint/lapis-lint-diagnostic-helpers.d.ts +8 -0
- package/dist/components/editor/extensions/lint/lapis-lint-diagnostic-helpers.js +7 -0
- package/dist/components/editor/extensions/lint/lapis-lint-diagnostic.d.ts +20 -0
- package/dist/components/editor/extensions/lint/lapis-lint-diagnostic.js +47 -0
- package/dist/components/editor/extensions/lint/lapis-lint-hover-tooltip.d.ts +9 -0
- package/dist/components/editor/extensions/lint/lapis-lint-hover-tooltip.js +373 -0
- package/dist/components/editor/extensions/lint/lapis-lint-inline-widget.d.ts +31 -0
- package/dist/components/editor/extensions/lint/lapis-lint-inline-widget.js +191 -0
- package/dist/components/editor/extensions/lint/lapis-lint-tooltip.svelte +176 -0
- package/dist/components/editor/extensions/lint/lapis-lint-tooltip.svelte.d.ts +15 -0
- package/dist/components/editor/extensions/lint/lint-tooltip-actions.d.ts +11 -0
- package/dist/components/editor/extensions/lint/lint-tooltip-actions.js +21 -0
- package/dist/components/editor/extensions/lint/mount-lint-tooltip.d.ts +16 -0
- package/dist/components/editor/extensions/lint/mount-lint-tooltip.js +60 -0
- package/dist/components/editor/extensions/search/dom.d.ts +2 -0
- package/dist/components/editor/extensions/search/dom.js +6 -0
- package/dist/components/editor/extensions/search/index.d.ts +35 -0
- package/dist/components/editor/extensions/search/index.js +44 -0
- package/dist/components/editor/extensions/search/search.svelte +335 -0
- package/dist/components/editor/extensions/search/search.svelte.d.ts +8 -0
- package/dist/components/editor/index.d.ts +9 -0
- package/dist/components/editor/index.js +9 -0
- package/dist/components/editor/language-service/dom.d.ts +1 -0
- package/dist/components/editor/language-service/dom.js +6 -0
- package/dist/components/editor/language-service/index.d.ts +28 -0
- package/dist/components/editor/language-service/index.js +342 -0
- package/dist/components/empty-view/empty-view.css +39 -0
- package/dist/components/empty-view/empty-view.svelte +26 -0
- package/dist/components/empty-view/empty-view.svelte.d.ts +9 -0
- package/dist/components/empty-view/index.d.ts +2 -0
- package/dist/components/empty-view/index.js +2 -0
- package/dist/components/icon/icon-list.css +74 -0
- package/dist/components/icon/icon-list.svelte +213 -0
- package/dist/components/icon/icon-list.svelte.d.ts +11 -0
- package/dist/components/icon/icon.svelte +15 -0
- package/dist/components/icon/icon.svelte.d.ts +7 -0
- package/dist/components/icon/index.d.ts +3 -0
- package/dist/components/icon/index.js +3 -0
- package/dist/components/menu/context-menu.svelte +89 -0
- package/dist/components/menu/context-menu.svelte.d.ts +11 -0
- package/dist/components/menu/drawer-menu.svelte +83 -0
- package/dist/components/menu/drawer-menu.svelte.d.ts +8 -0
- package/dist/components/menu/dropdown-menu.svelte +89 -0
- package/dist/components/menu/dropdown-menu.svelte.d.ts +11 -0
- package/dist/components/menu/index.d.ts +6 -0
- package/dist/components/menu/index.js +6 -0
- package/dist/components/menu/menu.css +139 -0
- package/dist/components/menu/menu.svelte +37 -0
- package/dist/components/menu/menu.svelte.d.ts +11 -0
- package/dist/components/menu/mobile-menu-query.svelte.d.ts +3 -0
- package/dist/components/menu/mobile-menu-query.svelte.js +21 -0
- package/dist/components/menu/popover-menu.svelte +90 -0
- package/dist/components/menu/popover-menu.svelte.d.ts +10 -0
- package/dist/components/select/index.d.ts +2 -0
- package/dist/components/select/index.js +2 -0
- package/dist/components/select/select.svelte +72 -0
- package/dist/components/select/select.svelte.d.ts +25 -0
- package/dist/configuration-option-source-providers.d.ts +17 -0
- package/dist/configuration-option-source-providers.js +59 -0
- package/dist/configuration-option-source-registry.d.ts +59 -0
- package/dist/configuration-option-source-registry.js +123 -0
- package/dist/configuration.svelte.d.ts +258 -0
- package/dist/configuration.svelte.js +887 -0
- package/dist/context-keys.svelte.d.ts +42 -0
- package/dist/context-keys.svelte.js +278 -0
- package/dist/context.svelte.d.ts +247 -0
- package/dist/context.svelte.js +540 -0
- package/dist/daily-document-provider.d.ts +38 -0
- package/dist/daily-document-provider.js +176 -0
- package/dist/design-core-button-types.d.ts +7 -0
- package/dist/design-core-button-types.js +1 -0
- package/dist/diagnostics.d.ts +93 -0
- package/dist/diagnostics.js +84 -0
- package/dist/dialog-portal.d.ts +3 -0
- package/dist/dialog-portal.js +3 -0
- package/dist/docs-api.d.ts +44 -0
- package/dist/docs-api.js +29 -0
- package/dist/editor-view-registry.d.ts +35 -0
- package/dist/editor-view-registry.js +112 -0
- package/dist/editor.svelte.d.ts +126 -0
- package/dist/editor.svelte.js +454 -0
- package/dist/embed-registry.d.ts +15 -0
- package/dist/embed-registry.js +16 -0
- package/dist/enhance.d.ts +111 -0
- package/dist/enhance.js +309 -0
- package/dist/events.d.ts +28 -0
- package/dist/events.js +49 -0
- package/dist/file-manager.d.ts +90 -0
- package/dist/file-manager.js +289 -0
- package/dist/file-tools/app-tools.d.ts +3 -0
- package/dist/file-tools/app-tools.js +242 -0
- package/dist/file-tools/index.d.ts +3 -0
- package/dist/file-tools/index.js +3 -0
- package/dist/file-tools/paths.d.ts +14 -0
- package/dist/file-tools/paths.js +33 -0
- package/dist/file-tools/vault-operations.d.ts +3 -0
- package/dist/file-tools/vault-operations.js +60 -0
- package/dist/generated/plugin-host-modules.schema.generated.d.ts +371 -0
- package/dist/generated/plugin-host-modules.schema.generated.js +374 -0
- package/dist/glob.d.ts +15 -0
- package/dist/glob.js +68 -0
- package/dist/history.svelte.d.ts +24 -0
- package/dist/history.svelte.js +74 -0
- package/dist/hooks/createVirtualizer.svelte.d.ts +7 -0
- package/dist/hooks/createVirtualizer.svelte.js +70 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/is-mobile.svelte.d.ts +5 -0
- package/dist/hooks/is-mobile.svelte.js +23 -0
- package/dist/hooks/mountComponent.svelte.d.ts +7 -0
- package/dist/hooks/mountComponent.svelte.js +16 -0
- package/dist/hooks/use-text-highlight.d.ts +17 -0
- package/dist/hooks/use-text-highlight.js +82 -0
- package/dist/hooks/useBoundingRect.svelte.d.ts +11 -0
- package/dist/hooks/useBoundingRect.svelte.js +46 -0
- package/dist/icons/index.d.ts +57 -0
- package/dist/icons/index.js +288 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.js +87 -0
- package/dist/language-service/index.d.ts +9 -0
- package/dist/language-service/index.js +7 -0
- package/dist/language-service/manager.d.ts +47 -0
- package/dist/language-service/manager.js +404 -0
- package/dist/language-service/types.d.ts +92 -0
- package/dist/language-service/types.js +1 -0
- package/dist/language-service/virtual-document.d.ts +11 -0
- package/dist/language-service/virtual-document.js +45 -0
- package/dist/language-service/worker-protocol.d.ts +63 -0
- package/dist/language-service/worker-protocol.js +1 -0
- package/dist/language-service/worker-provider.d.ts +9 -0
- package/dist/language-service/worker-provider.js +38 -0
- package/dist/lapis-extension.d.ts +244 -0
- package/dist/lapis-extension.js +591 -0
- package/dist/links.d.ts +34 -0
- package/dist/links.js +191 -0
- package/dist/loaders.d.ts +9 -0
- package/dist/loaders.js +59 -0
- package/dist/localization-manager.svelte.d.ts +56 -0
- package/dist/localization-manager.svelte.js +157 -0
- package/dist/logging.d.ts +172 -0
- package/dist/logging.js +352 -0
- package/dist/markdown-extension-registry.d.ts +31 -0
- package/dist/markdown-extension-registry.js +31 -0
- package/dist/markdown-file-surface-registry.d.ts +25 -0
- package/dist/markdown-file-surface-registry.js +23 -0
- package/dist/markdown.d.ts +205 -0
- package/dist/markdown.js +147 -0
- package/dist/menu-utils.d.ts +1 -0
- package/dist/menu-utils.js +47 -0
- package/dist/menu.svelte.d.ts +121 -0
- package/dist/menu.svelte.js +295 -0
- package/dist/metadata-value.d.ts +10 -0
- package/dist/metadata-value.js +173 -0
- package/dist/metadata.svelte.d.ts +106 -0
- package/dist/metadata.svelte.js +608 -0
- package/dist/notifications.d.ts +209 -0
- package/dist/notifications.js +338 -0
- package/dist/open-file.d.ts +23 -0
- package/dist/open-file.js +102 -0
- package/dist/platform.d.ts +86 -0
- package/dist/platform.js +86 -0
- package/dist/plugin-asset-server.d.ts +60 -0
- package/dist/plugin-asset-server.js +222 -0
- package/dist/plugin-assets.d.ts +4 -0
- package/dist/plugin-assets.js +3 -0
- package/dist/plugin-capability-facade.d.ts +104 -0
- package/dist/plugin-capability-facade.js +61 -0
- package/dist/plugin-dependency-resolver.d.ts +36 -0
- package/dist/plugin-dependency-resolver.js +54 -0
- package/dist/plugin-dependency-scanner.d.ts +9 -0
- package/dist/plugin-dependency-scanner.js +274 -0
- package/dist/plugin-distribution/canonical-json.d.ts +1 -0
- package/dist/plugin-distribution/canonical-json.js +40 -0
- package/dist/plugin-distribution/compatibility.d.ts +5 -0
- package/dist/plugin-distribution/compatibility.js +38 -0
- package/dist/plugin-distribution/errors.d.ts +11 -0
- package/dist/plugin-distribution/errors.js +13 -0
- package/dist/plugin-distribution/hashes.d.ts +2 -0
- package/dist/plugin-distribution/hashes.js +17 -0
- package/dist/plugin-distribution/index.d.ts +18 -0
- package/dist/plugin-distribution/index.js +18 -0
- package/dist/plugin-distribution/installed-plugin-state.d.ts +20 -0
- package/dist/plugin-distribution/installed-plugin-state.js +73 -0
- package/dist/plugin-distribution/installer.d.ts +89 -0
- package/dist/plugin-distribution/installer.js +395 -0
- package/dist/plugin-distribution/manager.d.ts +128 -0
- package/dist/plugin-distribution/manager.js +358 -0
- package/dist/plugin-distribution/path-safety.d.ts +2 -0
- package/dist/plugin-distribution/path-safety.js +20 -0
- package/dist/plugin-distribution/plugin-bundle-verifier.d.ts +28 -0
- package/dist/plugin-distribution/plugin-bundle-verifier.js +96 -0
- package/dist/plugin-distribution/plugin-bundle-worker.d.ts +34 -0
- package/dist/plugin-distribution/plugin-bundle-worker.js +99 -0
- package/dist/plugin-distribution/plugin-bundle.d.ts +16 -0
- package/dist/plugin-distribution/plugin-bundle.js +244 -0
- package/dist/plugin-distribution/plugin-bundle.worker.d.ts +1 -0
- package/dist/plugin-distribution/plugin-bundle.worker.js +38 -0
- package/dist/plugin-distribution/registry-cache.d.ts +26 -0
- package/dist/plugin-distribution/registry-cache.js +85 -0
- package/dist/plugin-distribution/registry-client.d.ts +36 -0
- package/dist/plugin-distribution/registry-client.js +115 -0
- package/dist/plugin-distribution/reserved-ids.d.ts +4 -0
- package/dist/plugin-distribution/reserved-ids.js +10 -0
- package/dist/plugin-distribution/runtime-validation.d.ts +14 -0
- package/dist/plugin-distribution/runtime-validation.js +388 -0
- package/dist/plugin-distribution/schemas.d.ts +4895 -0
- package/dist/plugin-distribution/schemas.js +299 -0
- package/dist/plugin-distribution/signing.d.ts +5 -0
- package/dist/plugin-distribution/signing.js +38 -0
- package/dist/plugin-distribution/types.d.ts +217 -0
- package/dist/plugin-distribution/types.js +1 -0
- package/dist/plugin-install-progress.d.ts +15 -0
- package/dist/plugin-install-progress.js +86 -0
- package/dist/plugin-manager.d.ts +306 -0
- package/dist/plugin-manager.js +2848 -0
- package/dist/plugin-runtime-entry.d.ts +19 -0
- package/dist/plugin-runtime-entry.js +135 -0
- package/dist/plugin.d.ts +350 -0
- package/dist/plugin.js +754 -0
- package/dist/popover.d.ts +20 -0
- package/dist/popover.js +32 -0
- package/dist/promise-worker.d.ts +22 -0
- package/dist/promise-worker.js +65 -0
- package/dist/prompt-confirm.d.ts +9 -0
- package/dist/prompt-confirm.js +33 -0
- package/dist/search-document-provider.d.ts +45 -0
- package/dist/search-document-provider.js +54 -0
- package/dist/search-query/index.d.ts +78 -0
- package/dist/search-query/index.js +426 -0
- package/dist/search-query/parser.d.ts +3 -0
- package/dist/search-query/parser.js +16 -0
- package/dist/search-query/parser.terms.js +26 -0
- package/dist/search-query/search-query.grammar +128 -0
- package/dist/search.d.ts +19 -0
- package/dist/search.js +104 -0
- package/dist/setting-section-layout.d.ts +19 -0
- package/dist/setting-section-layout.js +194 -0
- package/dist/settings.svelte.d.ts +474 -0
- package/dist/settings.svelte.js +1421 -0
- package/dist/source-text-file-view.d.ts +25 -0
- package/dist/source-text-file-view.js +78 -0
- package/dist/status-bar.svelte.d.ts +29 -0
- package/dist/status-bar.svelte.js +72 -0
- package/dist/storage/app-database.d.ts +860 -0
- package/dist/storage/app-database.js +2372 -0
- package/dist/storage/blob-store.d.ts +12 -0
- package/dist/storage/blob-store.js +1 -0
- package/dist/storage/browser-app-database-coordination.d.ts +35 -0
- package/dist/storage/browser-app-database-coordination.js +207 -0
- package/dist/storage/browser-coordinated-app-database.d.ts +109 -0
- package/dist/storage/browser-coordinated-app-database.js +704 -0
- package/dist/storage/browser.d.ts +153 -0
- package/dist/storage/browser.js +794 -0
- package/dist/storage/desktop-native.d.ts +184 -0
- package/dist/storage/desktop-native.js +415 -0
- package/dist/storage/fs.d.ts +188 -0
- package/dist/storage/fs.js +307 -0
- package/dist/storage/index-projection.d.ts +236 -0
- package/dist/storage/index-projection.js +402 -0
- package/dist/storage/index.d.ts +17 -0
- package/dist/storage/index.js +17 -0
- package/dist/storage/keyval.d.ts +94 -0
- package/dist/storage/keyval.js +199 -0
- package/dist/storage/memory-vault-adapter.d.ts +44 -0
- package/dist/storage/memory-vault-adapter.js +351 -0
- package/dist/storage/native-vault-bootstrap-kv.d.ts +22 -0
- package/dist/storage/native-vault-bootstrap-kv.js +96 -0
- package/dist/storage/path.d.ts +22 -0
- package/dist/storage/path.js +110 -0
- package/dist/storage/search-embedding-provider.d.ts +75 -0
- package/dist/storage/search-embedding-provider.js +446 -0
- package/dist/storage/search-embedding-worker.d.ts +1 -0
- package/dist/storage/search-embedding-worker.js +63 -0
- package/dist/storage/search-query-evaluator.d.ts +14 -0
- package/dist/storage/search-query-evaluator.js +678 -0
- package/dist/storage/task-projection.d.ts +152 -0
- package/dist/storage/task-projection.js +154 -0
- package/dist/storage/turso-app-database.d.ts +150 -0
- package/dist/storage/turso-app-database.js +2671 -0
- package/dist/storage/vault-session.d.ts +37 -0
- package/dist/storage/vault-session.js +196 -0
- package/dist/storage/vault-state.d.ts +74 -0
- package/dist/storage/vault-state.js +181 -0
- package/dist/storage/vault.svelte.d.ts +257 -0
- package/dist/storage/vault.svelte.js +661 -0
- package/dist/suggest.d.ts +193 -0
- package/dist/suggest.js +391 -0
- package/dist/tasks.d.ts +7 -0
- package/dist/tasks.js +18 -0
- package/dist/telemetry.d.ts +116 -0
- package/dist/telemetry.js +103 -0
- package/dist/utils.d.ts +55 -0
- package/dist/utils.js +314 -0
- package/dist/vault-api.d.ts +5 -0
- package/dist/vault-api.js +3 -0
- package/dist/vault-maintenance-commands.d.ts +5 -0
- package/dist/vault-maintenance-commands.js +32 -0
- package/dist/view.svelte.d.ts +215 -0
- package/dist/view.svelte.js +381 -0
- package/dist/vite-env.d.ts +2 -0
- package/dist/workspace-host-internal.d.ts +7 -0
- package/dist/workspace-host-internal.js +7 -0
- package/dist/workspace-host.d.ts +10 -0
- package/dist/workspace-host.js +14 -0
- package/dist/workspace-layout-commands.d.ts +3 -0
- package/dist/workspace-layout-commands.js +72 -0
- package/dist/workspace-layout-normalizer.d.ts +92 -0
- package/dist/workspace-layout-normalizer.js +301 -0
- package/dist/workspace-layouts.d.ts +7 -0
- package/dist/workspace-layouts.js +23 -0
- package/dist/workspace-trust.d.ts +32 -0
- package/dist/workspace-trust.js +72 -0
- package/dist/workspace.svelte.d.ts +796 -0
- package/dist/workspace.svelte.js +4380 -0
- package/package.json +240 -0
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
async function defaultTransformersRuntimeLoader() {
|
|
2
|
+
return (await import("@huggingface/transformers"));
|
|
3
|
+
}
|
|
4
|
+
let transformersRuntimeLoader = defaultTransformersRuntimeLoader;
|
|
5
|
+
const DEFAULT_DIMENSIONS = 48;
|
|
6
|
+
const DEFAULT_REMOTE_HOST = "https://huggingface.co/";
|
|
7
|
+
const DEFAULT_REMOTE_PATH_TEMPLATE = "{model}/resolve/{revision}/";
|
|
8
|
+
function normalizeText(value) {
|
|
9
|
+
return value.trim().toLowerCase();
|
|
10
|
+
}
|
|
11
|
+
function hashString(value) {
|
|
12
|
+
let hash = 2166136261;
|
|
13
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
14
|
+
hash ^= value.charCodeAt(index);
|
|
15
|
+
hash = Math.imul(hash, 16777619);
|
|
16
|
+
}
|
|
17
|
+
return hash >>> 0;
|
|
18
|
+
}
|
|
19
|
+
function featureTerms(value) {
|
|
20
|
+
const normalized = normalizeText(value);
|
|
21
|
+
if (!normalized.length) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
const features = [];
|
|
25
|
+
for (const token of normalized.match(/[\p{L}\p{N}_-]+/gu) ?? []) {
|
|
26
|
+
features.push(`tok:${token}`);
|
|
27
|
+
if (token.length >= 3) {
|
|
28
|
+
for (let index = 0; index <= token.length - 3; index += 1) {
|
|
29
|
+
features.push(`tri:${token.slice(index, index + 3)}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return [...new Set(features)];
|
|
34
|
+
}
|
|
35
|
+
function normalizeVector(values) {
|
|
36
|
+
const magnitude = Math.sqrt(values.reduce((total, value) => total + value * value, 0));
|
|
37
|
+
if (!magnitude) {
|
|
38
|
+
return values;
|
|
39
|
+
}
|
|
40
|
+
return values.map((value) => value / magnitude);
|
|
41
|
+
}
|
|
42
|
+
function embedText(text, dimensions) {
|
|
43
|
+
const vector = new Array(dimensions).fill(0);
|
|
44
|
+
for (const feature of featureTerms(text)) {
|
|
45
|
+
const hash = hashString(feature);
|
|
46
|
+
const index = hash % dimensions;
|
|
47
|
+
const sign = (hash & 1) === 0 ? 1 : -1;
|
|
48
|
+
vector[index] += sign;
|
|
49
|
+
}
|
|
50
|
+
return normalizeVector(vector);
|
|
51
|
+
}
|
|
52
|
+
function fingerprint(text) {
|
|
53
|
+
return hashString(normalizeText(text)).toString(16);
|
|
54
|
+
}
|
|
55
|
+
function trimModelPath(path) {
|
|
56
|
+
const normalized = path?.trim();
|
|
57
|
+
return normalized?.length ? normalized : undefined;
|
|
58
|
+
}
|
|
59
|
+
function normalizeEmbeddingRows(value) {
|
|
60
|
+
if (!Array.isArray(value)) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
if (value.length > 0 && value.every((entry) => typeof entry === "number")) {
|
|
64
|
+
return [value];
|
|
65
|
+
}
|
|
66
|
+
return value
|
|
67
|
+
.filter(Array.isArray)
|
|
68
|
+
.map((entry) => entry
|
|
69
|
+
.map((item) => Number(item))
|
|
70
|
+
.filter((item) => Number.isFinite(item)))
|
|
71
|
+
.filter((entry) => entry.length > 0);
|
|
72
|
+
}
|
|
73
|
+
function cloneRuntimeStatus(value) {
|
|
74
|
+
return { ...value };
|
|
75
|
+
}
|
|
76
|
+
function normalizeProgress(value) {
|
|
77
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
const normalized = value > 1 ? value / 100 : value;
|
|
81
|
+
return Math.max(0, Math.min(1, normalized));
|
|
82
|
+
}
|
|
83
|
+
function runtimeMessage(event) {
|
|
84
|
+
const parts = [event.status, event.name ?? event.file].filter(Boolean);
|
|
85
|
+
return parts.length ? parts.join(": ") : undefined;
|
|
86
|
+
}
|
|
87
|
+
class TokenHashSearchEmbeddingProvider {
|
|
88
|
+
config;
|
|
89
|
+
runtimeStatus;
|
|
90
|
+
constructor(config) {
|
|
91
|
+
this.config = {
|
|
92
|
+
...config,
|
|
93
|
+
modelId: config.modelId ?? "lapis/token-hash-v0",
|
|
94
|
+
modelVersion: config.modelVersion ?? "0",
|
|
95
|
+
dimensions: config.dimensions ?? DEFAULT_DIMENSIONS,
|
|
96
|
+
};
|
|
97
|
+
this.runtimeStatus = {
|
|
98
|
+
providerKind: "token-hash",
|
|
99
|
+
phase: "ready",
|
|
100
|
+
modelId: this.config.modelId,
|
|
101
|
+
message: "Token-hash fallback is ready",
|
|
102
|
+
progress: 1,
|
|
103
|
+
updatedAt: Date.now(),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
async ready() {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
async embedDocument(document) {
|
|
110
|
+
const dimensions = this.config.dimensions ?? DEFAULT_DIMENSIONS;
|
|
111
|
+
return (document.chunks ?? [])
|
|
112
|
+
.filter((chunk) => chunk.text.trim().length)
|
|
113
|
+
.map((chunk) => ({
|
|
114
|
+
chunkId: chunk.id,
|
|
115
|
+
vector: embedText(chunk.text, dimensions),
|
|
116
|
+
fingerprint: fingerprint(chunk.text),
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
async embedQuery(query) {
|
|
120
|
+
if (!featureTerms(query).length) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return embedText(query, this.config.dimensions ?? DEFAULT_DIMENSIONS);
|
|
124
|
+
}
|
|
125
|
+
getRuntimeStatus() {
|
|
126
|
+
return cloneRuntimeStatus(this.runtimeStatus);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const EMBEDDING_WORKER_TIMEOUT_MS = 5 * 60_000;
|
|
130
|
+
let browserSearchEmbeddingWorkerFactory = null;
|
|
131
|
+
function canUseBrowserEmbeddingWorker() {
|
|
132
|
+
return (typeof window !== "undefined" &&
|
|
133
|
+
browserSearchEmbeddingWorkerFactory !== null);
|
|
134
|
+
}
|
|
135
|
+
export function setBrowserSearchEmbeddingWorkerFactory(factory) {
|
|
136
|
+
browserSearchEmbeddingWorkerFactory = factory;
|
|
137
|
+
}
|
|
138
|
+
function createEmbeddingWorkerRequestId() {
|
|
139
|
+
if (typeof crypto !== "undefined" &&
|
|
140
|
+
typeof crypto.randomUUID === "function") {
|
|
141
|
+
return crypto.randomUUID();
|
|
142
|
+
}
|
|
143
|
+
return `embedding-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
144
|
+
}
|
|
145
|
+
class BrowserWorkerSearchEmbeddingProvider {
|
|
146
|
+
config;
|
|
147
|
+
worker = null;
|
|
148
|
+
runtimeStatus;
|
|
149
|
+
pending = new Map();
|
|
150
|
+
constructor(config) {
|
|
151
|
+
this.config = { ...config };
|
|
152
|
+
this.runtimeStatus = {
|
|
153
|
+
providerKind: "transformers-js",
|
|
154
|
+
phase: "downloading",
|
|
155
|
+
modelId: config.modelId,
|
|
156
|
+
message: "Waiting to initialize embedding worker",
|
|
157
|
+
progress: 0,
|
|
158
|
+
updatedAt: Date.now(),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
ready() {
|
|
162
|
+
return this.invoke("ready");
|
|
163
|
+
}
|
|
164
|
+
embedDocument(document) {
|
|
165
|
+
return this.invoke("embedDocument", document);
|
|
166
|
+
}
|
|
167
|
+
embedQuery(query) {
|
|
168
|
+
return this.invoke("embedQuery", query);
|
|
169
|
+
}
|
|
170
|
+
getRuntimeStatus() {
|
|
171
|
+
return cloneRuntimeStatus(this.runtimeStatus);
|
|
172
|
+
}
|
|
173
|
+
dispose() {
|
|
174
|
+
this.worker?.terminate();
|
|
175
|
+
this.worker = null;
|
|
176
|
+
for (const request of this.pending.values()) {
|
|
177
|
+
clearTimeout(request.timeoutId);
|
|
178
|
+
request.reject(new Error("Embedding worker disposed"));
|
|
179
|
+
}
|
|
180
|
+
this.pending.clear();
|
|
181
|
+
}
|
|
182
|
+
invoke(method, argument) {
|
|
183
|
+
const worker = this.ensureWorker();
|
|
184
|
+
const requestId = createEmbeddingWorkerRequestId();
|
|
185
|
+
return new Promise((resolve, reject) => {
|
|
186
|
+
const timeoutId = setTimeout(() => {
|
|
187
|
+
this.pending.delete(requestId);
|
|
188
|
+
reject(new Error(`Embedding worker request timed out: ${method}`));
|
|
189
|
+
}, EMBEDDING_WORKER_TIMEOUT_MS);
|
|
190
|
+
this.pending.set(requestId, {
|
|
191
|
+
resolve: (value) => resolve(value),
|
|
192
|
+
reject,
|
|
193
|
+
timeoutId,
|
|
194
|
+
});
|
|
195
|
+
worker.postMessage({
|
|
196
|
+
type: "search-embedding-request",
|
|
197
|
+
requestId,
|
|
198
|
+
method,
|
|
199
|
+
config: this.config,
|
|
200
|
+
argument,
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
ensureWorker() {
|
|
205
|
+
if (this.worker)
|
|
206
|
+
return this.worker;
|
|
207
|
+
if (!browserSearchEmbeddingWorkerFactory) {
|
|
208
|
+
throw new Error("Embedding worker factory is unavailable");
|
|
209
|
+
}
|
|
210
|
+
const worker = browserSearchEmbeddingWorkerFactory();
|
|
211
|
+
worker.addEventListener("message", (event) => {
|
|
212
|
+
const message = event.data;
|
|
213
|
+
if (message?.type === "search-embedding-status") {
|
|
214
|
+
this.runtimeStatus = cloneRuntimeStatus(message.status);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (message?.type !== "search-embedding-response")
|
|
218
|
+
return;
|
|
219
|
+
const request = this.pending.get(message.requestId);
|
|
220
|
+
if (!request)
|
|
221
|
+
return;
|
|
222
|
+
if (message.status) {
|
|
223
|
+
this.runtimeStatus = cloneRuntimeStatus(message.status);
|
|
224
|
+
}
|
|
225
|
+
clearTimeout(request.timeoutId);
|
|
226
|
+
this.pending.delete(message.requestId);
|
|
227
|
+
if (message.success)
|
|
228
|
+
request.resolve(message.result);
|
|
229
|
+
else
|
|
230
|
+
request.reject(new Error(message.error ?? "Embedding worker failed"));
|
|
231
|
+
});
|
|
232
|
+
worker.addEventListener("error", (event) => {
|
|
233
|
+
const error = new Error(event.message || "Embedding worker crashed");
|
|
234
|
+
this.runtimeStatus = {
|
|
235
|
+
...this.runtimeStatus,
|
|
236
|
+
phase: "error",
|
|
237
|
+
message: error.message,
|
|
238
|
+
updatedAt: Date.now(),
|
|
239
|
+
};
|
|
240
|
+
for (const request of this.pending.values()) {
|
|
241
|
+
clearTimeout(request.timeoutId);
|
|
242
|
+
request.reject(error);
|
|
243
|
+
}
|
|
244
|
+
this.pending.clear();
|
|
245
|
+
worker.terminate();
|
|
246
|
+
if (this.worker === worker)
|
|
247
|
+
this.worker = null;
|
|
248
|
+
});
|
|
249
|
+
this.worker = worker;
|
|
250
|
+
return worker;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
class TransformersJsSearchEmbeddingProvider {
|
|
254
|
+
config;
|
|
255
|
+
extractorPromise = null;
|
|
256
|
+
runtimeStatus;
|
|
257
|
+
sawDownloadProgress = false;
|
|
258
|
+
constructor(config) {
|
|
259
|
+
this.config = {
|
|
260
|
+
...config,
|
|
261
|
+
modelVersion: config.modelVersion ?? config.revision,
|
|
262
|
+
device: config.device ?? "wasm",
|
|
263
|
+
pooling: config.pooling ?? "mean",
|
|
264
|
+
normalize: config.normalize ?? true,
|
|
265
|
+
allowRemoteModels: config.allowRemoteModels ?? true,
|
|
266
|
+
localModelPath: trimModelPath(config.localModelPath),
|
|
267
|
+
wasmPaths: trimModelPath(config.wasmPaths),
|
|
268
|
+
};
|
|
269
|
+
this.runtimeStatus = {
|
|
270
|
+
providerKind: "transformers-js",
|
|
271
|
+
phase: "downloading",
|
|
272
|
+
modelId: this.config.modelId,
|
|
273
|
+
message: "Waiting to initialize embedding runtime",
|
|
274
|
+
progress: 0,
|
|
275
|
+
updatedAt: Date.now(),
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
async ready() {
|
|
279
|
+
await this.getExtractor();
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
282
|
+
async embedDocument(document) {
|
|
283
|
+
const chunks = (document.chunks ?? []).filter((chunk) => chunk.text.trim().length);
|
|
284
|
+
if (!chunks.length) {
|
|
285
|
+
return [];
|
|
286
|
+
}
|
|
287
|
+
const vectors = await this.embedTexts(chunks.map((chunk) => chunk.text));
|
|
288
|
+
return chunks
|
|
289
|
+
.map((chunk, index) => {
|
|
290
|
+
const vector = vectors[index];
|
|
291
|
+
if (!vector?.length) {
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
chunkId: chunk.id,
|
|
296
|
+
vector,
|
|
297
|
+
fingerprint: fingerprint(chunk.text),
|
|
298
|
+
};
|
|
299
|
+
})
|
|
300
|
+
.filter((entry) => Boolean(entry));
|
|
301
|
+
}
|
|
302
|
+
async embedQuery(query) {
|
|
303
|
+
if (!query.trim().length) {
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
const [vector] = await this.embedTexts([query]);
|
|
307
|
+
return vector?.length ? vector : null;
|
|
308
|
+
}
|
|
309
|
+
getRuntimeStatus() {
|
|
310
|
+
return cloneRuntimeStatus(this.runtimeStatus);
|
|
311
|
+
}
|
|
312
|
+
async embedTexts(texts) {
|
|
313
|
+
const extractor = await this.getExtractor();
|
|
314
|
+
this.updateRuntimeStatus({
|
|
315
|
+
phase: "embedding",
|
|
316
|
+
message: `Embedding ${texts.length} item${texts.length === 1 ? "" : "s"}`,
|
|
317
|
+
progress: 1,
|
|
318
|
+
});
|
|
319
|
+
try {
|
|
320
|
+
const output = await extractor(texts, {
|
|
321
|
+
pooling: this.config.pooling,
|
|
322
|
+
normalize: this.config.normalize,
|
|
323
|
+
});
|
|
324
|
+
return normalizeEmbeddingRows(output.tolist());
|
|
325
|
+
}
|
|
326
|
+
finally {
|
|
327
|
+
this.updateRuntimeStatus({
|
|
328
|
+
phase: "ready",
|
|
329
|
+
message: this.readyMessage(),
|
|
330
|
+
progress: 1,
|
|
331
|
+
file: undefined,
|
|
332
|
+
loadedBytes: undefined,
|
|
333
|
+
totalBytes: undefined,
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
async getExtractor() {
|
|
338
|
+
if (!this.extractorPromise) {
|
|
339
|
+
this.extractorPromise = this.loadExtractor().catch((error) => {
|
|
340
|
+
this.extractorPromise = null;
|
|
341
|
+
this.updateRuntimeStatus({
|
|
342
|
+
phase: "error",
|
|
343
|
+
message: error instanceof Error ? error.message : String(error),
|
|
344
|
+
});
|
|
345
|
+
throw error;
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
return this.extractorPromise;
|
|
349
|
+
}
|
|
350
|
+
async loadExtractor() {
|
|
351
|
+
const runtime = await transformersRuntimeLoader();
|
|
352
|
+
const hasExplicitLocalModelPath = Boolean(this.config.localModelPath);
|
|
353
|
+
runtime.env.allowLocalModels = hasExplicitLocalModelPath;
|
|
354
|
+
runtime.env.allowRemoteModels = this.config.allowRemoteModels ?? true;
|
|
355
|
+
runtime.env.remoteHost ||= DEFAULT_REMOTE_HOST;
|
|
356
|
+
runtime.env.remotePathTemplate ||= DEFAULT_REMOTE_PATH_TEMPLATE;
|
|
357
|
+
if (hasExplicitLocalModelPath) {
|
|
358
|
+
runtime.env.localModelPath = this.config.localModelPath;
|
|
359
|
+
}
|
|
360
|
+
if (this.config.wasmPaths) {
|
|
361
|
+
runtime.env.backends ??= {};
|
|
362
|
+
runtime.env.backends.onnx ??= {};
|
|
363
|
+
runtime.env.backends.onnx.wasm ??= {};
|
|
364
|
+
runtime.env.backends.onnx.wasm.wasmPaths = this.config.wasmPaths;
|
|
365
|
+
}
|
|
366
|
+
this.updateRuntimeStatus({
|
|
367
|
+
phase: "downloading",
|
|
368
|
+
message: "Initializing embedding runtime",
|
|
369
|
+
progress: 0,
|
|
370
|
+
});
|
|
371
|
+
const extractor = await runtime.pipeline("feature-extraction", this.config.modelId, {
|
|
372
|
+
revision: this.config.revision,
|
|
373
|
+
dtype: this.config.dtype,
|
|
374
|
+
device: this.config.device,
|
|
375
|
+
progress_callback: (event) => {
|
|
376
|
+
this.sawDownloadProgress = true;
|
|
377
|
+
this.updateRuntimeStatus({
|
|
378
|
+
phase: "downloading",
|
|
379
|
+
message: runtimeMessage(event) ?? "Downloading embedding model",
|
|
380
|
+
progress: normalizeProgress(event.progress) ?? this.runtimeStatus.progress,
|
|
381
|
+
file: event.file ?? event.name,
|
|
382
|
+
loadedBytes: typeof event.loaded === "number" ? event.loaded : undefined,
|
|
383
|
+
totalBytes: typeof event.total === "number" ? event.total : undefined,
|
|
384
|
+
});
|
|
385
|
+
},
|
|
386
|
+
});
|
|
387
|
+
this.updateRuntimeStatus({
|
|
388
|
+
phase: "ready",
|
|
389
|
+
message: this.readyMessage(),
|
|
390
|
+
progress: 1,
|
|
391
|
+
file: undefined,
|
|
392
|
+
loadedBytes: undefined,
|
|
393
|
+
totalBytes: undefined,
|
|
394
|
+
});
|
|
395
|
+
return extractor;
|
|
396
|
+
}
|
|
397
|
+
updateRuntimeStatus(patch) {
|
|
398
|
+
this.runtimeStatus = {
|
|
399
|
+
...this.runtimeStatus,
|
|
400
|
+
...patch,
|
|
401
|
+
providerKind: "transformers-js",
|
|
402
|
+
modelId: patch.modelId ?? this.runtimeStatus.modelId ?? this.config.modelId,
|
|
403
|
+
updatedAt: Date.now(),
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
readyMessage() {
|
|
407
|
+
if (this.sawDownloadProgress) {
|
|
408
|
+
return "Embedding model downloaded and cached in browser";
|
|
409
|
+
}
|
|
410
|
+
if (this.config.allowRemoteModels === false && this.config.localModelPath) {
|
|
411
|
+
return `Embedding model loaded from ${this.config.localModelPath}`;
|
|
412
|
+
}
|
|
413
|
+
if (this.config.allowRemoteModels === false) {
|
|
414
|
+
return "Embedding model loaded without remote downloads";
|
|
415
|
+
}
|
|
416
|
+
return "Embedding model ready from browser cache or existing local files";
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
export function createSearchEmbeddingProvider(config) {
|
|
420
|
+
if (!config) {
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
switch (config.kind) {
|
|
424
|
+
case "token-hash":
|
|
425
|
+
return new TokenHashSearchEmbeddingProvider(config);
|
|
426
|
+
case "transformers-js":
|
|
427
|
+
return canUseBrowserEmbeddingWorker()
|
|
428
|
+
? new BrowserWorkerSearchEmbeddingProvider(config)
|
|
429
|
+
: new TransformersJsSearchEmbeddingProvider(config);
|
|
430
|
+
default:
|
|
431
|
+
return null;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
export function setSearchEmbeddingProviderRuntimeLoaderForTests(loader) {
|
|
435
|
+
transformersRuntimeLoader = loader ?? defaultTransformersRuntimeLoader;
|
|
436
|
+
}
|
|
437
|
+
export function cosineSimilarity(left, right) {
|
|
438
|
+
if (!left.length || left.length !== right.length) {
|
|
439
|
+
return 0;
|
|
440
|
+
}
|
|
441
|
+
let score = 0;
|
|
442
|
+
for (let index = 0; index < left.length; index += 1) {
|
|
443
|
+
score += left[index] * right[index];
|
|
444
|
+
}
|
|
445
|
+
return score;
|
|
446
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { createSearchEmbeddingProvider, } from "./search-embedding-provider";
|
|
2
|
+
const workerScope = globalThis;
|
|
3
|
+
let activeConfig = "";
|
|
4
|
+
let provider = null;
|
|
5
|
+
async function ensureProvider(config) {
|
|
6
|
+
const serialized = JSON.stringify(config);
|
|
7
|
+
if (provider && serialized === activeConfig)
|
|
8
|
+
return provider;
|
|
9
|
+
await provider?.dispose?.();
|
|
10
|
+
provider = createSearchEmbeddingProvider(config);
|
|
11
|
+
activeConfig = serialized;
|
|
12
|
+
if (!provider)
|
|
13
|
+
throw new Error("Embedding provider is unavailable");
|
|
14
|
+
return provider;
|
|
15
|
+
}
|
|
16
|
+
function publishStatus(current) {
|
|
17
|
+
workerScope.postMessage({
|
|
18
|
+
type: "search-embedding-status",
|
|
19
|
+
status: current.getRuntimeStatus(),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
workerScope.addEventListener("message", (event) => {
|
|
23
|
+
const request = event.data;
|
|
24
|
+
if (!request || request.type !== "search-embedding-request")
|
|
25
|
+
return;
|
|
26
|
+
void (async () => {
|
|
27
|
+
let current = null;
|
|
28
|
+
let statusTimer = null;
|
|
29
|
+
try {
|
|
30
|
+
current = await ensureProvider(request.config);
|
|
31
|
+
publishStatus(current);
|
|
32
|
+
statusTimer = setInterval(() => publishStatus(current), 100);
|
|
33
|
+
const result = request.method === "ready"
|
|
34
|
+
? await current.ready()
|
|
35
|
+
: request.method === "embedDocument"
|
|
36
|
+
? await current.embedDocument(request.argument)
|
|
37
|
+
: await current.embedQuery(String(request.argument ?? ""));
|
|
38
|
+
publishStatus(current);
|
|
39
|
+
workerScope.postMessage({
|
|
40
|
+
type: "search-embedding-response",
|
|
41
|
+
requestId: request.requestId,
|
|
42
|
+
success: true,
|
|
43
|
+
result,
|
|
44
|
+
status: current.getRuntimeStatus(),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (current)
|
|
49
|
+
publishStatus(current);
|
|
50
|
+
workerScope.postMessage({
|
|
51
|
+
type: "search-embedding-response",
|
|
52
|
+
requestId: request.requestId,
|
|
53
|
+
success: false,
|
|
54
|
+
error: error instanceof Error ? error.message : String(error),
|
|
55
|
+
status: current?.getRuntimeStatus(),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
if (statusTimer)
|
|
60
|
+
clearInterval(statusTimer);
|
|
61
|
+
}
|
|
62
|
+
})();
|
|
63
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AppDatabasePropertyRecord, AppDatabaseSearchField, AppDatabaseSearchRange, SearchDocumentRecord } from "./app-database";
|
|
2
|
+
export interface SearchQueryEvaluationOptions {
|
|
3
|
+
caseSensitive?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface SearchQueryTextRangeOptions extends SearchQueryEvaluationOptions {
|
|
6
|
+
field?: AppDatabaseSearchField;
|
|
7
|
+
}
|
|
8
|
+
export interface SearchQueryDocumentEvaluation {
|
|
9
|
+
matched: boolean;
|
|
10
|
+
score: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function isStructuredSearchQuery(query: string): boolean;
|
|
13
|
+
export declare function evaluateSearchQueryForDocument(document: SearchDocumentRecord, query: string, properties?: AppDatabasePropertyRecord[], options?: SearchQueryEvaluationOptions): SearchQueryDocumentEvaluation;
|
|
14
|
+
export declare function findSearchQueryRangesInText(text: string, query: string, options?: SearchQueryTextRangeOptions): AppDatabaseSearchRange[];
|