@astryxdesign/cli 0.7.16 → 0.7.17-canary.g49a475f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -86
- package/api/build/_adapter.d.mts +12 -0
- package/api/build/_adapter.mjs +51 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/build.doc.mjs +4 -3
- package/api/build/build.type.d.mts +2 -2
- package/api/build/build.type.mjs +3 -3
- package/api/build/kit/kind.d.mts +2 -1
- package/api/build/kit/kind.mjs +199 -10
- package/api/build/kit/kit.mjs +6 -4
- package/api/build/kit/rank.d.mts +4 -2
- package/api/build/kit/rank.mjs +125 -24
- package/api/build/kit/start.d.mts +5 -4
- package/api/build/kit/start.mjs +12 -8
- package/api/build/kit/weights.d.mts +39 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +340 -43
- package/api/build/kit/word-model.d.mts +23 -0
- package/api/build/kit/word-model.mjs +46 -0
- package/api/build/kit/words.d.mts +48 -0
- package/api/build/kit/words.mjs +90 -1
- package/api/component/__fixtures__/resolutions/modules.txt +4 -5
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +48 -6
- package/api/discover/_adapter.d.mts +1 -1
- package/api/discover/search/search.mjs +3 -2
- package/api/docs/_adapter.d.mts +26 -2
- package/api/docs/_adapter.mjs +219 -6
- package/api/docs/docs.d.mts +3 -0
- package/api/docs/docs.doc.mjs +7 -1
- package/api/docs/docs.mjs +12 -0
- package/api/docs/docs.type.d.mts +5 -0
- package/api/docs/docs.type.mjs +2 -0
- package/api/docs/node/node.mjs +1 -1
- package/api/doctor/_adapter.d.mts +27 -5
- package/api/doctor/_adapter.mjs +83 -10
- package/api/doctor/built-checks.mjs +40 -14
- package/api/doctor/doctor.d.mts +4 -3
- package/api/doctor/doctor.mjs +14 -7
- package/api/doctor/theme-checks.mjs +121 -17
- package/api/icon/_records.mjs +2 -1
- package/api/index.d.mts +2 -0
- package/api/index.mjs +2 -0
- package/api/integration/_adapter.d.mts +44 -0
- package/api/integration/_adapter.mjs +77 -1
- package/api/integration/authoring-checks.mjs +6 -6
- package/api/integration/example-scope.d.mts +14 -0
- package/api/integration/example-scope.mjs +44 -0
- package/api/integration/example-scope.type.d.mts +29 -0
- package/api/integration/example-scope.type.mjs +25 -0
- package/api/integration/integrationExampleScope.doc.d.mts +11 -0
- package/api/integration/integrationExampleScope.doc.mjs +59 -0
- package/api/integration/validate-integration.mjs +19 -1
- package/api/integration/validate-integration.type.d.mts +9 -0
- package/api/integration/validate-integration.type.mjs +1 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/render/_adapter.mjs +591 -195
- package/api/render/render.doc.mjs +11 -3
- package/api/render/render.type.d.mts +52 -0
- package/api/render/render.type.mjs +31 -1
- package/api/search/ORDERING.md +1 -1
- package/api/search/_adapter.d.mts +9 -0
- package/api/search/_adapter.mjs +85 -0
- package/api/search/_candidate-score.mjs +51 -32
- package/api/search/_fit-order.mjs +3 -3
- package/api/search/_gather-components.d.mts +3 -2
- package/api/search/_gather-components.mjs +12 -3
- package/api/search/_lexical.d.mts +5 -0
- package/api/search/_lexical.mjs +8 -2
- package/api/search/_result.d.mts +11 -9
- package/api/search/_result.mjs +4 -4
- package/api/search/_score.d.mts +6 -1
- package/api/search/_score.mjs +15 -3
- package/api/search/search-index.mjs +7 -1
- package/api/search/search.d.mts +1 -1
- package/api/theme/_adapter.mjs +12 -1
- package/api/theme/build/build.d.mts +75 -0
- package/api/theme/build/build.mjs +243 -58
- package/api/theme/build/font-warning.d.mts +7 -0
- package/api/theme/build/font-warning.mjs +17 -0
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +63 -2
- package/api/theme-edit/_adapter.mjs +771 -57
- package/api/theme-edit/_check.d.mts +40 -22
- package/api/theme-edit/_check.mjs +2029 -336
- package/api/theme-edit/_color.d.mts +10 -0
- package/api/theme-edit/_color.mjs +49 -1
- package/api/theme-edit/_compiler.mjs +9 -0
- package/api/theme-edit/_context.d.mts +3 -3
- package/api/theme-edit/_context.mjs +111 -48
- package/api/theme-edit/_css.d.mts +14 -0
- package/api/theme-edit/_css.mjs +46 -1
- package/api/theme-edit/_edit.d.mts +18 -4
- package/api/theme-edit/_edit.mjs +1685 -155
- package/api/theme-edit/_how-commands.d.mts +65 -0
- package/api/theme-edit/_how-commands.mjs +633 -1
- package/api/theme-edit/_how-question.d.mts +84 -0
- package/api/theme-edit/_how-question.mjs +5124 -281
- package/api/theme-edit/_how.mjs +140 -29
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_name-rule.d.mts +11 -0
- package/api/theme-edit/_name-rule.mjs +12 -0
- package/api/theme-edit/_normal.d.mts +257 -0
- package/api/theme-edit/_normal.mjs +1252 -0
- package/api/theme-edit/_palette.mjs +10 -4
- package/api/theme-edit/_parts.d.mts +10 -1
- package/api/theme-edit/_parts.mjs +179 -3
- package/api/theme-edit/_preview-app.d.mts +7 -1
- package/api/theme-edit/_preview-app.mjs +515 -148
- package/api/theme-edit/_preview.d.mts +100 -14
- package/api/theme-edit/_preview.mjs +549 -137
- package/api/theme-edit/_settings.d.mts +347 -30
- package/api/theme-edit/_settings.mjs +2971 -327
- package/api/theme-edit/_tables.d.mts +6 -0
- package/api/theme-edit/_tables.mjs +44 -1
- package/api/theme-edit/_vet.d.mts +18 -0
- package/api/theme-edit/_vet.mjs +32 -0
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -1
- package/api/theme-edit/themeEditHow.doc.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
- package/api/theme-edit/themeEditNew.doc.mjs +7 -4
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
- package/api/upgrade/run/run.mjs +4 -3
- package/assets/codemods/integration-discovery.mjs +2 -1
- package/assets/codemods/run-codemod.mjs +87 -7
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
- package/assets/component-list.generated.json +1 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -0
- package/assets/docs/theme.doc.dense.mjs +2 -2
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/render-pages.doc.mjs +44 -3
- package/assets/docs/tree/single-component.doc.mjs +4 -0
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/search-catalog.generated.json +2 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
- package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
- package/assets/templates/pages/blank/template.doc.mjs +1 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
- package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
- package/assets/templates/pages/documentation/template.doc.mjs +4 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
- package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +24 -2
- package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
- package/assets/templates/pages/library/template.doc.mjs +4 -1
- package/assets/templates/pages/login/template.doc.mjs +2 -1
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/template.doc.mjs +2 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
- package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/template.doc.mjs +5 -4
- package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
- package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/assets/theme.template.ts +6 -0
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +3 -3
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/component/categories.d.mts +37 -0
- package/authoring/doctypes/component/categories.mjs +54 -0
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +9 -0
- package/authoring/example/example.doc.d.mts +12 -0
- package/authoring/example/example.doc.mjs +69 -0
- package/authoring/example/preview.d.mts +92 -0
- package/authoring/example/preview.mjs +994 -0
- package/authoring/example/type.ts +102 -0
- package/authoring/index.d.mts +1 -0
- package/authoring/index.d.ts +12 -0
- package/authoring/index.mjs +3 -1
- package/clients/cli/bin/astryx.mjs +6 -9
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/component.doc.mjs +1 -1
- package/clients/cli/commands/component.mjs +22 -3
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +32 -14
- package/clients/cli/commands/experimental/render.mjs +42 -1
- package/clients/cli/commands/experimental/theme.mjs +163 -28
- package/clients/cli/commands/experimental-render.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
- package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
- package/clients/cli/commands/search.doc.mjs +2 -1
- package/clients/cli/commands/search.mjs +6 -1
- package/clients/cli/commands/template.mjs +4 -2
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +209 -8
- package/clients/cli/commands/upgrade.mjs +42 -7
- package/clients/cli/index.mjs +1 -1
- package/clients/cli/lib/cli-error.mjs +2 -1
- package/clients/cli/lib/component-format.mjs +205 -98
- package/clients/cli/lib/hook-format.mjs +9 -19
- package/clients/cli/lib/json-shim.mjs +77 -21
- package/clients/cli/lib/manifest.mjs +3 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/theme-state.d.mts +13 -1
- package/foundation/config/theme-state.mjs +47 -7
- package/foundation/discovery/authoring-self-docs.mjs +1 -0
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +56 -8
- package/foundation/discovery/component-replacement.mjs +130 -1
- package/foundation/discovery/copied-passages.mjs +2 -1
- package/foundation/discovery/doc-types.mjs +4 -3
- package/foundation/discovery/entry-name-files.d.mts +43 -0
- package/foundation/discovery/entry-name-files.mjs +264 -0
- package/foundation/discovery/hook-discovery.d.mts +8 -2
- package/foundation/discovery/hook-discovery.mjs +22 -8
- package/foundation/discovery/icon-definition-discovery.mjs +2 -1
- package/foundation/discovery/icon-set-checks.mjs +2 -1
- package/foundation/discovery/icon-set-discovery.mjs +2 -1
- package/foundation/discovery/integration-doc-files.mjs +2 -1
- package/foundation/discovery/package-exports.d.mts +10 -0
- package/foundation/discovery/package-exports.mjs +56 -3
- package/foundation/discovery/prop-drift.mjs +9 -9
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/stored-component-list.d.mts +43 -0
- package/foundation/discovery/stored-component-list.mjs +90 -0
- package/foundation/discovery/stored-search-catalog.d.mts +115 -0
- package/foundation/discovery/stored-search-catalog.mjs +297 -0
- package/foundation/discovery/stored-self-audit.d.mts +26 -10
- package/foundation/discovery/stored-self-audit.mjs +38 -18
- package/foundation/discovery/template-adapter.d.mts +52 -0
- package/foundation/discovery/template-adapter.mjs +176 -12
- package/foundation/discovery/template-icons.mjs +2 -1
- package/foundation/discovery/theme-discovery.mjs +3 -2
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/discovery/theming-targets.mjs +3 -2
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/inputs.mjs +3 -2
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +22 -0
- package/foundation/doc-compiler/stored-docs.mjs +49 -0
- package/foundation/env/semver.mjs +3 -1
- package/foundation/fonts/font-stylesheet.d.mts +31 -0
- package/foundation/fonts/font-stylesheet.mjs +115 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/file-protection.mjs +4 -3
- package/foundation/fs/gather-cache.d.mts +25 -4
- package/foundation/fs/gather-cache.mjs +164 -55
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +60 -0
- package/foundation/fs/kept-tree.mjs +154 -0
- package/foundation/fs/listing-cache.d.mts +7 -0
- package/foundation/fs/listing-cache.mjs +10 -0
- package/foundation/fs/module-loader.d.mts +24 -2
- package/foundation/fs/module-loader.mjs +94 -21
- package/foundation/fs/paths.d.mts +18 -0
- package/foundation/fs/paths.mjs +15 -2
- package/foundation/identity/provider-identity.d.mts +6 -0
- package/foundation/identity/provider-identity.mjs +10 -1
- package/foundation/integrations/contribution-inventory.mjs +4 -3
- package/foundation/integrations/example-code.d.mts +63 -0
- package/foundation/integrations/example-code.mjs +416 -0
- package/foundation/integrations/public-imports.d.mts +9 -0
- package/foundation/integrations/public-imports.mjs +3 -2
- package/foundation/integrations/validate-contributions.mjs +17 -45
- package/foundation/render/embedded-files.d.mts +6 -0
- package/foundation/render/embedded-files.mjs +25 -5
- package/foundation/render/embedded-imports.d.mts +39 -7
- package/foundation/render/embedded-imports.mjs +66 -27
- package/foundation/render/file-header.d.mts +66 -0
- package/foundation/render/file-header.mjs +118 -0
- package/foundation/render/host-answer.d.mts +18 -0
- package/foundation/render/host-answer.mjs +46 -0
- package/foundation/render/host-exit.d.mts +1 -0
- package/foundation/render/host-exit.mjs +6 -1
- package/foundation/render/html-reader.d.mts +55 -2
- package/foundation/render/html-reader.mjs +145 -26
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +121 -13
- package/foundation/render/picture-chrome.d.mts +4 -0
- package/foundation/render/picture-chrome.mjs +185 -0
- package/foundation/render/picture-playwright.d.mts +4 -0
- package/foundation/render/picture-playwright.mjs +34 -0
- package/foundation/render/rebuild.mjs +2 -1
- package/foundation/render/render-page.d.mts +35 -3
- package/foundation/render/render-page.mjs +316 -42
- package/foundation/render/source-block.d.mts +85 -6
- package/foundation/render/source-block.mjs +211 -20
- package/foundation/render/ts-paths.d.mts +69 -6
- package/foundation/render/ts-paths.mjs +326 -40
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +12 -1
- package/foundation/response/error-codes.mjs +11 -1
- package/foundation/response/response-types.doc.mjs +2 -2
- package/foundation/text/compare-text.d.mts +14 -0
- package/foundation/text/compare-text.mjs +68 -0
- package/foundation/text/string-utils.d.mts +3 -2
- package/foundation/text/string-utils.mjs +18 -4
- package/foundation/text/suggest-order.d.mts +9 -0
- package/foundation/text/suggest-order.mjs +15 -1
- package/foundation/xle/expand.mjs +2 -1
- package/host/index.mjs +8 -6
- package/package.json +7 -6
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @file Word weights for `build`'s START (spec:AST-048):
|
|
5
|
-
* per-template word weights, blended with the page ranker's own scores,
|
|
6
|
-
* the template an idea starts from.
|
|
4
|
+
* @file Word weights for `build`'s START (spec:AST-048): checked-in tables of
|
|
5
|
+
* per-template word weights, blended with the page ranker's own scores, pick
|
|
6
|
+
* the template an idea starts from. The call model (the file's top-level
|
|
7
|
+
* tables and blend) decides page or app shell; an optional pick model
|
|
8
|
+
* (`pick`) chooses which page once the call model calls a page.
|
|
7
9
|
*
|
|
8
10
|
* @input An idea, the ranker's output for it (`rankPages`, `pickStart`), the
|
|
9
11
|
* project's ready page templates, and the weights (`weights.json` beside this
|
|
@@ -20,6 +22,9 @@
|
|
|
20
22
|
*/
|
|
21
23
|
|
|
22
24
|
import {STOPWORDS} from '../../search/search.mjs';
|
|
25
|
+
import {keywordUnits, keywordWordsFor} from './words.mjs';
|
|
26
|
+
import {isWordModel} from './word-model.mjs';
|
|
27
|
+
import {compareText} from '../../../foundation/text/compare-text.mjs';
|
|
23
28
|
|
|
24
29
|
/** The app shell, as one candidate. */
|
|
25
30
|
export const SHELL = 'SHELL';
|
|
@@ -160,8 +165,34 @@ export function weightWords(idea) {
|
|
|
160
165
|
* @property {WeightTable[]} tables
|
|
161
166
|
* @property {number[]} blend three numbers per member (the tables, in order,
|
|
162
167
|
* with the ranker second), then one for `SHELL`
|
|
168
|
+
* @property {{tables: WeightTable[], blend: number[]}} [pick] the pick
|
|
169
|
+
* model: its own tables and blend numbers, used only to choose which page
|
|
170
|
+
* starts once the call model (the top-level tables and blend) has called a
|
|
171
|
+
* page. Without it, one model does both.
|
|
163
172
|
*/
|
|
164
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Whether the weights file carries a well-formed pick model. A malformed
|
|
176
|
+
* `pick` block is ignored, so one model then does both decisions.
|
|
177
|
+
* @param {WeightsFile} weights
|
|
178
|
+
* @returns {boolean}
|
|
179
|
+
*/
|
|
180
|
+
const hasPickModel = weights =>
|
|
181
|
+
isWordModel(weights.pick, weights.candidates.length);
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The pick model of a weights file: its `pick` tables and blend when present,
|
|
185
|
+
* else the file's own.
|
|
186
|
+
* @param {WeightsFile} weights
|
|
187
|
+
* @returns {WeightsFile}
|
|
188
|
+
*/
|
|
189
|
+
const pickModel = weights => {
|
|
190
|
+
const pick = weights.pick;
|
|
191
|
+
return pick && hasPickModel(weights)
|
|
192
|
+
? {...weights, tables: pick.tables, blend: pick.blend}
|
|
193
|
+
: weights;
|
|
194
|
+
};
|
|
195
|
+
|
|
165
196
|
/**
|
|
166
197
|
* A table's score for every candidate.
|
|
167
198
|
* @param {WeightTable} table
|
|
@@ -217,9 +248,15 @@ function memberFeatures(v) {
|
|
|
217
248
|
Math.max(1, finite.length),
|
|
218
249
|
) || 1;
|
|
219
250
|
const val = v.map(x => (x === undefined ? -1e9 : x));
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
251
|
+
// Equal values share the average of the ranks they span. That is the mean
|
|
252
|
+
// rank an arbitrary order gives them, which is what the blend numbers were
|
|
253
|
+
// fit on, and the candidates' order in the weights file never decides. Two
|
|
254
|
+
// or more candidates tied at a member's top share a rank above 0, so none
|
|
255
|
+
// of them gets the is-top feature.
|
|
256
|
+
const rank = val.map(
|
|
257
|
+
x =>
|
|
258
|
+
val.filter(y => y > x).length + (val.filter(y => y === x).length - 1) / 2,
|
|
259
|
+
);
|
|
223
260
|
return v.map((x, i) => [
|
|
224
261
|
x === undefined ? -4 : Math.max(-4, Math.min(4, (x - mean) / sd)),
|
|
225
262
|
1 / (rank[i] + 1),
|
|
@@ -233,32 +270,68 @@ function memberFeatures(v) {
|
|
|
233
270
|
* @property {string} [displayName]
|
|
234
271
|
* @property {string} [category]
|
|
235
272
|
* @property {string[]} [keywords]
|
|
273
|
+
* @property {string} [description]
|
|
274
|
+
* @property {string[]} [components]
|
|
275
|
+
*/
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* The words of a descriptor text as this file reads an idea: stemmed, less
|
|
279
|
+
* search's stopwords. Search's stopwords are no evidence: "to" in a "to-do
|
|
280
|
+
* list" keyword must not answer the "to" of "rows to track orders".
|
|
281
|
+
* @param {string} text
|
|
282
|
+
* @returns {string[]}
|
|
283
|
+
*/
|
|
284
|
+
const contentWords = text =>
|
|
285
|
+
weightWords(text)
|
|
286
|
+
.filter(w => !STOPWORDS.has(w))
|
|
287
|
+
.map(stem);
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* The words a template's descriptor gives an idea: every word of `texts`, and
|
|
291
|
+
* the words its keywords give the idea (`keywordWordsFor`): a phrase keyword
|
|
292
|
+
* counts all of its words when the idea names the whole phrase, and none of
|
|
293
|
+
* them otherwise.
|
|
294
|
+
* @param {string[]} texts
|
|
295
|
+
* @param {readonly string[]} keywords
|
|
296
|
+
* @param {string[]} order the idea's words, in order (`contentWords`)
|
|
297
|
+
* @returns {Set<string>}
|
|
236
298
|
*/
|
|
299
|
+
const descriptorWordsFor = (texts, keywords, order) =>
|
|
300
|
+
new Set([
|
|
301
|
+
...contentWords(texts.join(' ')),
|
|
302
|
+
...keywordWordsFor(keywordUnits(keywords, contentWords), order),
|
|
303
|
+
]);
|
|
237
304
|
|
|
238
305
|
/**
|
|
239
|
-
* How many of the idea's
|
|
240
|
-
*
|
|
306
|
+
* How many of the idea's words a template's own descriptor names: its display
|
|
307
|
+
* name, its category, and its keywords.
|
|
241
308
|
* @param {string} name
|
|
242
309
|
* @param {DescribedTemplate[]} catalog
|
|
243
|
-
* @param {
|
|
310
|
+
* @param {string[]} order the idea's words, in order (`contentWords`)
|
|
244
311
|
*/
|
|
245
|
-
function ownWords(name, catalog,
|
|
312
|
+
function ownWords(name, catalog, order) {
|
|
246
313
|
const t = catalog.find(c => c.name === name);
|
|
247
314
|
if (!t) return 0;
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
[t.displayName ?? '', t.category ?? '', ...(t.keywords ?? [])].join(' '),
|
|
253
|
-
)
|
|
254
|
-
.filter(w => !STOPWORDS.has(w))
|
|
255
|
-
.map(stem),
|
|
315
|
+
const own = descriptorWordsFor(
|
|
316
|
+
[t.displayName ?? '', t.category ?? ''],
|
|
317
|
+
t.keywords ?? [],
|
|
318
|
+
order,
|
|
256
319
|
);
|
|
257
320
|
let n = 0;
|
|
258
|
-
for (const w of
|
|
321
|
+
for (const w of new Set(order)) if (own.has(w)) n++;
|
|
259
322
|
return n;
|
|
260
323
|
}
|
|
261
324
|
|
|
325
|
+
/**
|
|
326
|
+
* A template's family: the part of its category before ` - `.
|
|
327
|
+
* @param {string} name
|
|
328
|
+
* @param {DescribedTemplate[]} catalog
|
|
329
|
+
*/
|
|
330
|
+
const familyOf = (name, catalog) =>
|
|
331
|
+
String(catalog.find(c => c.name === name)?.category ?? '')
|
|
332
|
+
.split(' - ')[0]
|
|
333
|
+
.trim();
|
|
334
|
+
|
|
262
335
|
/** How many fewer own words a template whose family the idea names first may
|
|
263
336
|
* name than the listed template it competes with, and still start. */
|
|
264
337
|
const FAMILY_SLACK = 2;
|
|
@@ -330,6 +403,224 @@ function blend(idea, ranked, pick, catalog, weights) {
|
|
|
330
403
|
return {cands, scores, position};
|
|
331
404
|
}
|
|
332
405
|
|
|
406
|
+
/**
|
|
407
|
+
* The most typical of the ready templates the ranker ties with `name` in its
|
|
408
|
+
* family (same score, and both the family's base or both variants): the one
|
|
409
|
+
* whose descriptor's words are shared by the most of its family's templates,
|
|
410
|
+
* on average. `name` keeps its
|
|
411
|
+
* place on an equal value. Reads only the templates' descriptors.
|
|
412
|
+
* @param {string} name
|
|
413
|
+
* @param {import('./rank.mjs').RankedPage[]} ranked
|
|
414
|
+
* @param {string[]} cands
|
|
415
|
+
* @returns {string}
|
|
416
|
+
*/
|
|
417
|
+
function typicalOfTie(name, ranked, cands) {
|
|
418
|
+
const self = ranked.find(r => r.name === name);
|
|
419
|
+
if (!self || self.family === SHELL_FAMILY || !self.family) return name;
|
|
420
|
+
let chosen = self;
|
|
421
|
+
for (const r of ranked) {
|
|
422
|
+
if (
|
|
423
|
+
r.score === self.score &&
|
|
424
|
+
r.family === self.family &&
|
|
425
|
+
r.base === self.base &&
|
|
426
|
+
cands.includes(r.name) &&
|
|
427
|
+
r.typical > chosen.typical
|
|
428
|
+
)
|
|
429
|
+
chosen = r;
|
|
430
|
+
}
|
|
431
|
+
return chosen.name;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* The words a template's whole descriptor gives an idea
|
|
436
|
+
* (`descriptorWordsFor`): its display name, category, keywords, description,
|
|
437
|
+
* and the names of the components its page composes.
|
|
438
|
+
* @param {DescribedTemplate} t
|
|
439
|
+
* @param {string[]} order the idea's words, in order (`contentWords`)
|
|
440
|
+
* @returns {Set<string>}
|
|
441
|
+
*/
|
|
442
|
+
function descriptorWords(t, order) {
|
|
443
|
+
const components = (t.components ?? []).map(c =>
|
|
444
|
+
c.replace(/([a-z0-9])([A-Z])/g, '$1 $2'),
|
|
445
|
+
);
|
|
446
|
+
return descriptorWordsFor(
|
|
447
|
+
[t.displayName ?? '', t.category ?? '', t.description ?? '', ...components],
|
|
448
|
+
t.keywords ?? [],
|
|
449
|
+
order,
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Which of a set of tied templates the idea names by its whole name: its
|
|
455
|
+
* display name or its id, as consecutive words of the idea ("a form wizard
|
|
456
|
+
* page" names `form-wizard`, "Form Wizard"). A whole name is stronger evidence
|
|
457
|
+
* than any descriptor word, so it settles an exact tie first.
|
|
458
|
+
* @param {string[]} names the tied templates' ids
|
|
459
|
+
* @param {string} idea
|
|
460
|
+
* @param {DescribedTemplate[]} catalog
|
|
461
|
+
* @returns {boolean[]} one flag per name, in order
|
|
462
|
+
*/
|
|
463
|
+
export function namedOutright(names, idea, catalog) {
|
|
464
|
+
const said = weightWords(idea).map(stem);
|
|
465
|
+
const holds = (/** @type {string[]} */ phrase) =>
|
|
466
|
+
phrase.length > 0 &&
|
|
467
|
+
said.some((_, i) => phrase.every((w, k) => said[i + k] === w));
|
|
468
|
+
return names.map(name => {
|
|
469
|
+
const t = catalog.find(c => c.name === name);
|
|
470
|
+
return [t?.displayName ?? '', name.replace(/-/g, ' ')].some(text =>
|
|
471
|
+
holds(weightWords(text).map(stem)),
|
|
472
|
+
);
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* How strongly each of a set of tied templates' own descriptors answers the
|
|
478
|
+
* idea. Words every tied template names cannot choose between them, so they
|
|
479
|
+
* are left out; each other word of the idea that a template's descriptor
|
|
480
|
+
* names adds its rarity among the templates of the tied templates' families.
|
|
481
|
+
* Reads only the templates' descriptors.
|
|
482
|
+
* @param {string[]} names the tied templates' ids
|
|
483
|
+
* @param {string} idea
|
|
484
|
+
* @param {DescribedTemplate[]} catalog
|
|
485
|
+
* @returns {number[]} one reading per name, in order
|
|
486
|
+
*/
|
|
487
|
+
export function tieReading(names, idea, catalog) {
|
|
488
|
+
const families = new Set(names.map(name => familyOf(name, catalog)));
|
|
489
|
+
const pool = catalog.filter(t => families.has(familyOf(t.name, catalog)));
|
|
490
|
+
const order = contentWords(idea);
|
|
491
|
+
const words = new Map(pool.map(t => [t.name, descriptorWords(t, order)]));
|
|
492
|
+
const df = (/** @type {string} */ w) =>
|
|
493
|
+
pool.filter(t => words.get(t.name)?.has(w)).length;
|
|
494
|
+
const said = new Set(order);
|
|
495
|
+
const own = names.map(name => words.get(name) ?? new Set());
|
|
496
|
+
const n = pool.length;
|
|
497
|
+
return names.map((_, i) => {
|
|
498
|
+
let s = 0;
|
|
499
|
+
for (const w of said) {
|
|
500
|
+
if (!own[i].has(w) || own.every(o => o.has(w))) continue;
|
|
501
|
+
const d = df(w);
|
|
502
|
+
s += Math.log(1 + (n - d + 0.5) / (d + 0.5));
|
|
503
|
+
}
|
|
504
|
+
return s;
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Settles an exact tie in the ranker: a tied template the idea names by its
|
|
510
|
+
* whole name starts (`namedOutright`); otherwise a fuller reading of each tied
|
|
511
|
+
* template's own descriptor decides. Words every tied template names cannot choose
|
|
512
|
+
* between them, so they are left out; each other word of the idea that a
|
|
513
|
+
* template's descriptor names adds its rarity within the family. The highest
|
|
514
|
+
* total starts. An equal total goes to the most typical of the family
|
|
515
|
+
* (`typicalOfTie`), then to `name`. Reads only the templates' descriptors.
|
|
516
|
+
* @param {string} name
|
|
517
|
+
* @param {string} idea
|
|
518
|
+
* @param {import('./rank.mjs').RankedPage[]} ranked
|
|
519
|
+
* @param {string[]} cands
|
|
520
|
+
* @param {DescribedTemplate[]} catalog
|
|
521
|
+
* @returns {string}
|
|
522
|
+
*/
|
|
523
|
+
function fullerOfTie(name, idea, ranked, cands, catalog) {
|
|
524
|
+
const self = ranked.find(r => r.name === name);
|
|
525
|
+
if (!self || self.family === SHELL_FAMILY || !self.family) return name;
|
|
526
|
+
const tied = ranked.filter(
|
|
527
|
+
r =>
|
|
528
|
+
r.score === self.score &&
|
|
529
|
+
r.family === self.family &&
|
|
530
|
+
r.base === self.base &&
|
|
531
|
+
cands.includes(r.name),
|
|
532
|
+
);
|
|
533
|
+
if (tied.length < 2) return name;
|
|
534
|
+
const named = namedOutright(
|
|
535
|
+
tied.map(r => r.name),
|
|
536
|
+
idea,
|
|
537
|
+
catalog,
|
|
538
|
+
);
|
|
539
|
+
if (named.filter(Boolean).length === 1) return tied[named.indexOf(true)].name;
|
|
540
|
+
const score = tieReading(
|
|
541
|
+
tied.map(r => r.name),
|
|
542
|
+
idea,
|
|
543
|
+
catalog,
|
|
544
|
+
);
|
|
545
|
+
const top = Math.max(...score);
|
|
546
|
+
if (top === 0) return typicalOfTie(name, ranked, cands);
|
|
547
|
+
const leaders = tied.filter((_, i) => score[i] >= top - 1e-9);
|
|
548
|
+
if (leaders.length === 1) return leaders[0].name;
|
|
549
|
+
const lead = leaders.some(r => r.name === name) ? self : leaders[0];
|
|
550
|
+
return typicalOfTie(
|
|
551
|
+
lead.name,
|
|
552
|
+
ranked,
|
|
553
|
+
leaders.map(r => r.name),
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* The pick model's best ready, non-shell template that `ok` accepts, or null
|
|
559
|
+
* when it has none.
|
|
560
|
+
* @param {string} idea
|
|
561
|
+
* @param {import('./rank.mjs').RankedPage[]} ranked
|
|
562
|
+
* @param {import('./rank.mjs').RankedPage | null} pick
|
|
563
|
+
* @param {DescribedTemplate[]} catalog
|
|
564
|
+
* @param {WeightsFile} weights
|
|
565
|
+
* @param {(c: string) => boolean} [ok]
|
|
566
|
+
* @returns {string | null}
|
|
567
|
+
*/
|
|
568
|
+
function bestPage(idea, ranked, pick, catalog, weights, ok = () => true) {
|
|
569
|
+
return pickOrder(idea, ranked, pick, catalog, weights).find(ok) ?? null;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Every ready, non-shell template in the pick model's order, best first.
|
|
574
|
+
* Templates the pick model scores exactly the same are ordered like an exact
|
|
575
|
+
* tie in the ranker: a template the idea names by its whole name first
|
|
576
|
+
* (`namedOutright`), then by how strongly each one's own descriptor answers
|
|
577
|
+
* the idea (`tieReading`), then by how typical of its family it is, then by
|
|
578
|
+
* name.
|
|
579
|
+
* The weights file's candidate order never decides.
|
|
580
|
+
* @param {string} idea
|
|
581
|
+
* @param {import('./rank.mjs').RankedPage[]} ranked
|
|
582
|
+
* @param {import('./rank.mjs').RankedPage | null} pick
|
|
583
|
+
* @param {DescribedTemplate[]} catalog
|
|
584
|
+
* @param {WeightsFile} weights
|
|
585
|
+
* @returns {string[]}
|
|
586
|
+
*/
|
|
587
|
+
function pickOrder(idea, ranked, pick, catalog, weights) {
|
|
588
|
+
const {cands, scores} = blend(
|
|
589
|
+
idea,
|
|
590
|
+
ranked,
|
|
591
|
+
pick,
|
|
592
|
+
catalog,
|
|
593
|
+
pickModel(weights),
|
|
594
|
+
);
|
|
595
|
+
const sorted = cands
|
|
596
|
+
.map((c, i) => ({c, s: scores[i]}))
|
|
597
|
+
.filter(x => x.c !== SHELL)
|
|
598
|
+
.sort((x, y) => y.s - x.s);
|
|
599
|
+
const typical = new Map(ranked.map(r => [r.name, r.typical]));
|
|
600
|
+
const out = [];
|
|
601
|
+
for (let i = 0; i < sorted.length;) {
|
|
602
|
+
let j = i + 1;
|
|
603
|
+
while (j < sorted.length && sorted[j].s === sorted[i].s) j++;
|
|
604
|
+
const run = sorted.slice(i, j).map(x => x.c);
|
|
605
|
+
if (run.length > 1) {
|
|
606
|
+
const reading = tieReading(run, idea, catalog);
|
|
607
|
+
const named = namedOutright(run, idea, catalog);
|
|
608
|
+
const at = new Map(run.map((c, k) => [c, reading[k]]));
|
|
609
|
+
const outright = new Map(run.map((c, k) => [c, named[k]]));
|
|
610
|
+
run.sort(
|
|
611
|
+
(a, b) =>
|
|
612
|
+
Number(outright.get(b)) - Number(outright.get(a)) ||
|
|
613
|
+
Number(at.get(b)) - Number(at.get(a)) ||
|
|
614
|
+
(typical.get(b) ?? 0) - (typical.get(a) ?? 0) ||
|
|
615
|
+
compareText(a, b),
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
out.push(...run);
|
|
619
|
+
i = j;
|
|
620
|
+
}
|
|
621
|
+
return out;
|
|
622
|
+
}
|
|
623
|
+
|
|
333
624
|
/**
|
|
334
625
|
* Every ready, non-shell template in the blend's own order, best first: the
|
|
335
626
|
* order the page start is chosen from, so the alternatives build names beside
|
|
@@ -343,12 +634,7 @@ function blend(idea, ranked, pick, catalog, weights) {
|
|
|
343
634
|
*/
|
|
344
635
|
export function blendOrder(idea, ranked, pick, catalog, weights) {
|
|
345
636
|
if (!weights) return null;
|
|
346
|
-
|
|
347
|
-
return cands
|
|
348
|
-
.map((c, i) => ({c, s: scores[i], i}))
|
|
349
|
-
.filter(x => x.c !== SHELL)
|
|
350
|
-
.sort((x, y) => y.s - x.s || x.i - y.i)
|
|
351
|
-
.map(x => x.c);
|
|
637
|
+
return pickOrder(idea, ranked, pick, catalog, weights);
|
|
352
638
|
}
|
|
353
639
|
|
|
354
640
|
/**
|
|
@@ -388,31 +674,39 @@ export function weighStart(
|
|
|
388
674
|
// The tables cannot judge a template they do not list (an integration's
|
|
389
675
|
// template, or one added since they were fit), so its own descriptor
|
|
390
676
|
// decides: the ranker's pick stands when the idea names as many words of its
|
|
391
|
-
// display name, category and keywords as of the
|
|
392
|
-
//
|
|
393
|
-
// listed template starts. Nothing learned about the template is involved,
|
|
677
|
+
// display name, category and keywords as of the best listed template's (the
|
|
678
|
+
// pick model's choice, as for every other page), or names its family first
|
|
679
|
+
// and nearly as many; otherwise that listed template starts. Nothing learned about the template is involved,
|
|
394
680
|
// so a new template competes on its own words.
|
|
395
681
|
if (kept && !position.has(kept)) {
|
|
396
|
-
const listed =
|
|
682
|
+
const listed = bestPage(idea, ranked, pick, catalog, weights, c =>
|
|
683
|
+
position.has(c),
|
|
684
|
+
);
|
|
397
685
|
if (!listed) return kept;
|
|
398
686
|
// The idea's own words, less search's stopwords: "basically" must not
|
|
399
687
|
// answer the "Basic" of a category.
|
|
400
|
-
const
|
|
401
|
-
const
|
|
402
|
-
const
|
|
403
|
-
const theirs = ownWords(listed, catalog, said);
|
|
404
|
-
if (mine >= theirs) return kept;
|
|
688
|
+
const order = contentWords(idea);
|
|
689
|
+
const mine = ownWords(kept, catalog, order);
|
|
690
|
+
const theirs = ownWords(listed, catalog, order);
|
|
405
691
|
// An idea that names the template's family before the listed one's
|
|
406
692
|
// ("a dashboard with a data table") is that family's page, unless it
|
|
407
693
|
// names far more of the listed template's words.
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
694
|
+
const stays =
|
|
695
|
+
mine >= theirs ||
|
|
696
|
+
(familyAt(kept, catalog, order) < familyAt(listed, catalog, order) &&
|
|
697
|
+
mine >= theirs - FAMILY_SLACK);
|
|
698
|
+
if (!stays) return listed;
|
|
699
|
+
// A tie in the ranker is no preference: every table that names "table"
|
|
700
|
+
// scores the same, and the alphabet must not choose the page. Among the
|
|
701
|
+
// family's templates the ranker ties with this unlisted one, the template
|
|
702
|
+
// whose own descriptor best matches the idea starts (`fullerOfTie`), then
|
|
703
|
+
// the one most typical of the family. Only the templates' descriptors
|
|
704
|
+
// decide this tie, never the tables.
|
|
705
|
+
return fullerOfTie(kept, idea, ranked, cands, catalog);
|
|
413
706
|
}
|
|
414
707
|
const top = best(() => true);
|
|
415
|
-
if (top !== SHELL)
|
|
708
|
+
if (top !== SHELL)
|
|
709
|
+
return bestPage(idea, ranked, pick, catalog, weights) ?? top;
|
|
416
710
|
// An idea that asks for a new page keeps the ranker's template rather than
|
|
417
711
|
// the shell.
|
|
418
712
|
if (newPage && kept) return kept;
|
|
@@ -420,8 +714,9 @@ export function weighStart(
|
|
|
420
714
|
}
|
|
421
715
|
|
|
422
716
|
/**
|
|
423
|
-
* The
|
|
424
|
-
*
|
|
717
|
+
* The call model's scores: the app shell's, the best non-shell template's and
|
|
718
|
+
* the runner-up's, with the page to start from (the pick model's choice when
|
|
719
|
+
* the file has one, else the call model's best page). Null without weights.
|
|
425
720
|
* @param {string} idea
|
|
426
721
|
* @param {import('./rank.mjs').RankedPage[]} ranked
|
|
427
722
|
* @param {import('./rank.mjs').RankedPage | null} pick
|
|
@@ -440,7 +735,9 @@ export function blendSummary(idea, ranked, pick, catalog, weights) {
|
|
|
440
735
|
rest.sort((x, y) => y.score - x.score || x.i - y.i);
|
|
441
736
|
return {
|
|
442
737
|
shell,
|
|
443
|
-
best:
|
|
738
|
+
best: hasPickModel(weights)
|
|
739
|
+
? bestPage(idea, ranked, pick, catalog, weights)
|
|
740
|
+
: (rest[0]?.name ?? null),
|
|
444
741
|
bestScore: rest[0]?.score ?? 0,
|
|
445
742
|
secondScore: rest[1]?.score ?? 0,
|
|
446
743
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @file The shape check for `build`'s checked-in word models (spec:AST-048).
|
|
6
|
+
*
|
|
7
|
+
* @input A parsed word model (tables and blend numbers) and the candidate
|
|
8
|
+
* count of its weights file.
|
|
9
|
+
* @output `isWordModel(model, n)`: whether the kit can read it.
|
|
10
|
+
* @position Beside weights.mjs (api/build/kit/). The adapter checks the
|
|
11
|
+
* weights file's call model with it, and weights.mjs checks the optional
|
|
12
|
+
* pick model with it. It imports nothing, so both can use it.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Whether a word model has the shape the kit reads, over `n` candidates: every
|
|
16
|
+
* table row has a weight per candidate, every bias a number per candidate, and
|
|
17
|
+
* the blend has three numbers per member (the tables plus the ranker) and one
|
|
18
|
+
* for the shell. The weights file's call model and its `pick` model share it.
|
|
19
|
+
* @param {any} model
|
|
20
|
+
* @param {number} n the candidate count
|
|
21
|
+
* @returns {boolean}
|
|
22
|
+
*/
|
|
23
|
+
export function isWordModel(model: any, n: number): boolean;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The shape check for `build`'s checked-in word models (spec:AST-048).
|
|
5
|
+
*
|
|
6
|
+
* @input A parsed word model (tables and blend numbers) and the candidate
|
|
7
|
+
* count of its weights file.
|
|
8
|
+
* @output `isWordModel(model, n)`: whether the kit can read it.
|
|
9
|
+
* @position Beside weights.mjs (api/build/kit/). The adapter checks the
|
|
10
|
+
* weights file's call model with it, and weights.mjs checks the optional
|
|
11
|
+
* pick model with it. It imports nothing, so both can use it.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Whether a word model has the shape the kit reads, over `n` candidates: every
|
|
16
|
+
* table row has a weight per candidate, every bias a number per candidate, and
|
|
17
|
+
* the blend has three numbers per member (the tables plus the ranker) and one
|
|
18
|
+
* for the shell. The weights file's call model and its `pick` model share it.
|
|
19
|
+
* @param {any} model
|
|
20
|
+
* @param {number} n the candidate count
|
|
21
|
+
* @returns {boolean}
|
|
22
|
+
*/
|
|
23
|
+
export function isWordModel(model, n) {
|
|
24
|
+
return (
|
|
25
|
+
n > 0 &&
|
|
26
|
+
Array.isArray(model?.tables) &&
|
|
27
|
+
model.tables.length > 0 &&
|
|
28
|
+
model.tables.every(
|
|
29
|
+
(/** @type {any} */ t) =>
|
|
30
|
+
Array.isArray(t?.words) &&
|
|
31
|
+
Array.isArray(t.rows) &&
|
|
32
|
+
t.rows.length === t.words.length &&
|
|
33
|
+
t.rows.every(
|
|
34
|
+
(/** @type {any} */ r) => typeof r === 'string' && r.length === n,
|
|
35
|
+
) &&
|
|
36
|
+
Array.isArray(t.bias) &&
|
|
37
|
+
t.bias.length === n &&
|
|
38
|
+
t.bias.every((/** @type {any} */ b) => Number.isFinite(b)) &&
|
|
39
|
+
Number.isFinite(t.clip) &&
|
|
40
|
+
Number.isFinite(t.step),
|
|
41
|
+
) &&
|
|
42
|
+
Array.isArray(model.blend) &&
|
|
43
|
+
model.blend.length === 3 * (model.tables.length + 1) + 1 &&
|
|
44
|
+
model.blend.every((/** @type {any} */ x) => Number.isFinite(x))
|
|
45
|
+
);
|
|
46
|
+
}
|
|
@@ -30,6 +30,47 @@ export function pairsOf(texts: string[]): Set<string>;
|
|
|
30
30
|
* @returns {Set<string>}
|
|
31
31
|
*/
|
|
32
32
|
export function containersOf(query: string): Set<string>;
|
|
33
|
+
/**
|
|
34
|
+
* A template's keywords as the units a request can match, each read with the
|
|
35
|
+
* caller's own word reader. A one-word keyword is that word. A longer keyword
|
|
36
|
+
* is one phrase unit, its words joined by single spaces: a request matches it
|
|
37
|
+
* only when it names those words in that order (`phrasesIn`), and its words
|
|
38
|
+
* never count alone. So "table of contents" on a docs page adds no "table" to
|
|
39
|
+
* that page, and a table request still reads as a table.
|
|
40
|
+
* @param {readonly string[]} keywords
|
|
41
|
+
* @param {(text: string) => string[]} read the caller's word reader
|
|
42
|
+
* @returns {string[]}
|
|
43
|
+
*/
|
|
44
|
+
export function keywordUnits(keywords: readonly string[], read: (text: string) => string[]): string[];
|
|
45
|
+
/**
|
|
46
|
+
* The phrase units (two or more words) a request names: the unit's words
|
|
47
|
+
* appear next to each other, in order, in the request's words as the same
|
|
48
|
+
* reader reads them.
|
|
49
|
+
* @param {readonly string[]} words the request's words, in order
|
|
50
|
+
* @param {Iterable<string>} units
|
|
51
|
+
* @returns {Set<string>}
|
|
52
|
+
*/
|
|
53
|
+
export function phrasesIn(words: readonly string[], units: Iterable<string>): Set<string>;
|
|
54
|
+
/**
|
|
55
|
+
* The words a template's keyword units give an idea: each one-word keyword,
|
|
56
|
+
* and every word of each phrase keyword the idea names (`phrasesIn`). A named
|
|
57
|
+
* phrase carries all of its words, as the same words listed one by one would;
|
|
58
|
+
* a phrase the idea does not name gives none of them.
|
|
59
|
+
* @param {readonly string[]} units the template's keyword units (`keywordUnits`)
|
|
60
|
+
* @param {readonly string[]} words the idea's words, in order, read the same way
|
|
61
|
+
* @returns {string[]}
|
|
62
|
+
*/
|
|
63
|
+
export function keywordWordsFor(units: readonly string[], words: readonly string[]): string[];
|
|
64
|
+
/**
|
|
65
|
+
* What each frame of an idea holds: for every container phrase ("settings in
|
|
66
|
+
* a modal", "in a settings modal"), the frame's terms with the words that
|
|
67
|
+
* name what sits in it: the head of the phrase right before the container
|
|
68
|
+
* phrase, and the container phrase's own other words. In "a toggle in a modal
|
|
69
|
+
* on the settings page" the modal holds the toggle, not the settings page.
|
|
70
|
+
* @param {string} query
|
|
71
|
+
* @returns {Map<string, Set<string>>} frame term -> terms it holds
|
|
72
|
+
*/
|
|
73
|
+
export function framesOf(query: string): Map<string, Set<string>>;
|
|
33
74
|
/**
|
|
34
75
|
* Family words, from the templates' own ids: a word in the ids of two or more
|
|
35
76
|
* templates of one family, plus the family's name when a template carries it.
|
|
@@ -49,6 +90,12 @@ export const HEAD_END: RegExp;
|
|
|
49
90
|
export const SHELL_FAMILY: "Shell";
|
|
50
91
|
/** A container phrase: "in a modal", "inside the side panel". */
|
|
51
92
|
export const CONTAINER_PHRASE: RegExp;
|
|
93
|
+
/**
|
|
94
|
+
* A place phrase: a preposition of place, then a determiner ("above the
|
|
95
|
+
* table", "into my dashboard"). CONTAINER_PHRASE is the narrower class of
|
|
96
|
+
* frames a page lives in ("in a modal"); this one names where a piece goes.
|
|
97
|
+
*/
|
|
98
|
+
export const PLACE_PHRASE: RegExp;
|
|
52
99
|
/**
|
|
53
100
|
* Where a phrase ends, for finding the word that heads it: punctuation and
|
|
54
101
|
* the words that join phrases.
|
|
@@ -69,5 +116,6 @@ export type RankedPage = {
|
|
|
69
116
|
family: string;
|
|
70
117
|
base: boolean;
|
|
71
118
|
matched: Set<string>;
|
|
119
|
+
typical: number;
|
|
72
120
|
};
|
|
73
121
|
export type IdeaKind = "page" | "part" | "edit";
|