@aparte/plugin-titler 0.19.2 → 0.19.3

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 CHANGED
@@ -21,7 +21,9 @@ setupTitler(manager, { titler: loadTitler });
21
21
  `loadTitler` is called once, the first time a conversation needs a title — the model is not on
22
22
  the page's critical path. A `Titler` instance or a promise of one (`loadTitler()`) is accepted
23
23
  in the same place, and so is any object with `title(message, budget?)` of your own
24
- (`TitlerLike`). `budget` caps the number of words (the model's default is 6).
24
+ (`TitlerLike`). `budget` caps the words (a short message can give fewer); without it the model keeps, among its six
25
+ best-scored words, those it is at least half sure of, never fewer than three — and every word of a
26
+ message of four words or fewer.
25
27
 
26
28
  `setupTitler` returns a teardown that gives the manager back the provider it had. For a manager
27
29
  built with the `titleProvider` option, `createTitleProvider(options)` is the provider alone:
package/dist/index.d.ts CHANGED
@@ -30,7 +30,11 @@ export interface TitlerOptions {
30
30
  * the page's critical path.
31
31
  */
32
32
  titler: TitlerLike | Promise<TitlerLike> | (() => TitlerLike | Promise<TitlerLike>);
33
- /** Words to keep. Omitted, the model's own default applies (6). */
33
+ /**
34
+ * At most this many words (a short message can give fewer). Omitted, the model decides: among
35
+ * its six best-scored words, those it is at least half sure of, never fewer than three — and
36
+ * every word of a message of four words or fewer.
37
+ */
34
38
  budget?: number;
35
39
  }
36
40
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,yBAAyB,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAE/F,uFAAuF;AACvF,MAAM,WAAW,UAAU;IACvB,kFAAkF;IAClF,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACnD;AAED,MAAM,WAAW,aAAa;IAC1B;;;;OAIG;IACH,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IACpF,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,GAAG,+BAA+B,CAgB3F;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,yBAAyB,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,IAAI,CAOlG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,yBAAyB,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAE/F,uFAAuF;AACvF,MAAM,WAAW,UAAU;IACvB,kFAAkF;IAClF,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACnD;AAED,MAAM,WAAW,aAAa;IAC1B;;;;OAIG;IACH,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IACpF;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,GAAG,+BAA+B,CAgB3F;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,yBAAyB,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,IAAI,CAOlG"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * `@aparte/plugin-titler` — auto-title conversations with an aparte-titler model.\n *\n * Core titles a conversation from its first user message, and the default is the\n * message as typed. This plugin replaces that default with the words an\n * [aparte-titler](https://apartejs.dev/models/titler/) model picks out of it — 3 to 6\n * words, in the browser, no API call — through the manager's title provider seam.\n *\n * ```ts\n * import { loadTitler } from '@aparte/titler-latin';\n * import { setupTitler } from '@aparte/plugin-titler';\n *\n * setupTitler(manager, { titler: loadTitler });\n * ```\n *\n * The plugin loads nothing on its own: it calls the loader you hand it, once, the\n * first time a title is needed. Any object with `title(message, budget?)` works — the\n * runtime's `Titler`, or one of your own.\n */\nimport type { AparteConversationManager, AparteConversationTitleProvider } from '@aparte/core';\n\n/** What the plugin needs of a titler: `@aparte/titler`'s `Titler` has exactly this. */\nexport interface TitlerLike {\n /** The title: the `budget` best-scored words of the message, in message order. */\n title(message: string, budget?: number): string;\n}\n\nexport interface TitlerOptions {\n /**\n * The model: a `Titler`, a promise of one (`loadTitler()`), or a loader called\n * once, when the first title is needed — the shape that keeps the model out of\n * the page's critical path.\n */\n titler: TitlerLike | Promise<TitlerLike> | (() => TitlerLike | Promise<TitlerLike>);\n /** Words to keep. Omitted, the model's own default applies (6). */\n budget?: number;\n}\n\n/**\n * The title provider alone — for a manager built with the `titleProvider` option, or\n * to compose with another provider. The model is resolved once and cached.\n */\nexport function createTitleProvider(options: TitlerOptions): AparteConversationTitleProvider {\n let loaded: Promise<TitlerLike> | undefined;\n const model = (): Promise<TitlerLike> => {\n loaded ??= Promise.resolve(typeof options.titler === 'function' ? options.titler() : options.titler)\n // A REJECTED promise must not be the cache: one transient failure (the\n // model fetch, a CSP hiccup on the dynamic import) would otherwise leave\n // every later conversation with its default title, for the life of the\n // page and with nothing said. The next title retries; the throw still\n // reaches the caller. Same rule, same reason, as `@aparte/plugin-shiki`.\n .catch((err: unknown) => { loaded = undefined; throw err; });\n return loaded;\n };\n return async (text) => {\n const titler = await model();\n return options.budget === undefined ? titler.title(text) : titler.title(text, options.budget);\n };\n}\n\n/**\n * Register the model as the manager's title provider. Returns a teardown that gives\n * the manager back the provider it had — unless another one was set since, which is\n * then left alone.\n */\nexport function setupTitler(manager: AparteConversationManager, options: TitlerOptions): () => void {\n const previous = manager.getTitleProvider();\n const provider = createTitleProvider(options);\n manager.setTitleProvider(provider);\n return () => {\n if (manager.getTitleProvider() === provider) manager.setTitleProvider(previous);\n };\n}\n"],"names":[],"mappings":"AA0CO,SAAS,oBAAoB,SAAyD;AACzF,MAAI;AACJ,QAAM,QAAQ,MAA2B;AACrC,eAAW,QAAQ,QAAQ,OAAO,QAAQ,WAAW,aAAa,QAAQ,OAAA,IAAW,QAAQ,MAAM,EAM9F,MAAM,CAAC,QAAiB;AAAE,eAAS;AAAW,YAAM;AAAA,IAAK,CAAC;AAC/D,WAAO;AAAA,EACX;AACA,SAAO,OAAO,SAAS;AACnB,UAAM,SAAS,MAAM,MAAA;AACrB,WAAO,QAAQ,WAAW,SAAY,OAAO,MAAM,IAAI,IAAI,OAAO,MAAM,MAAM,QAAQ,MAAM;AAAA,EAChG;AACJ;AAOO,SAAS,YAAY,SAAoC,SAAoC;AAChG,QAAM,WAAW,QAAQ,iBAAA;AACzB,QAAM,WAAW,oBAAoB,OAAO;AAC5C,UAAQ,iBAAiB,QAAQ;AACjC,SAAO,MAAM;AACT,QAAI,QAAQ,iBAAA,MAAuB,SAAU,SAAQ,iBAAiB,QAAQ;AAAA,EAClF;AACJ;"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * `@aparte/plugin-titler` — auto-title conversations with an aparte-titler model.\n *\n * Core titles a conversation from its first user message, and the default is the\n * message as typed. This plugin replaces that default with the words an\n * [aparte-titler](https://apartejs.dev/models/titler/) model picks out of it — 3 to 6\n * words, in the browser, no API call — through the manager's title provider seam.\n *\n * ```ts\n * import { loadTitler } from '@aparte/titler-latin';\n * import { setupTitler } from '@aparte/plugin-titler';\n *\n * setupTitler(manager, { titler: loadTitler });\n * ```\n *\n * The plugin loads nothing on its own: it calls the loader you hand it, once, the\n * first time a title is needed. Any object with `title(message, budget?)` works — the\n * runtime's `Titler`, or one of your own.\n */\nimport type { AparteConversationManager, AparteConversationTitleProvider } from '@aparte/core';\n\n/** What the plugin needs of a titler: `@aparte/titler`'s `Titler` has exactly this. */\nexport interface TitlerLike {\n /** The title: the `budget` best-scored words of the message, in message order. */\n title(message: string, budget?: number): string;\n}\n\nexport interface TitlerOptions {\n /**\n * The model: a `Titler`, a promise of one (`loadTitler()`), or a loader called\n * once, when the first title is needed — the shape that keeps the model out of\n * the page's critical path.\n */\n titler: TitlerLike | Promise<TitlerLike> | (() => TitlerLike | Promise<TitlerLike>);\n /**\n * At most this many words (a short message can give fewer). Omitted, the model decides: among\n * its six best-scored words, those it is at least half sure of, never fewer than three — and\n * every word of a message of four words or fewer.\n */\n budget?: number;\n}\n\n/**\n * The title provider alone — for a manager built with the `titleProvider` option, or\n * to compose with another provider. The model is resolved once and cached.\n */\nexport function createTitleProvider(options: TitlerOptions): AparteConversationTitleProvider {\n let loaded: Promise<TitlerLike> | undefined;\n const model = (): Promise<TitlerLike> => {\n loaded ??= Promise.resolve(typeof options.titler === 'function' ? options.titler() : options.titler)\n // A REJECTED promise must not be the cache: one transient failure (the\n // model fetch, a CSP hiccup on the dynamic import) would otherwise leave\n // every later conversation with its default title, for the life of the\n // page and with nothing said. The next title retries; the throw still\n // reaches the caller. Same rule, same reason, as `@aparte/plugin-shiki`.\n .catch((err: unknown) => { loaded = undefined; throw err; });\n return loaded;\n };\n return async (text) => {\n const titler = await model();\n return options.budget === undefined ? titler.title(text) : titler.title(text, options.budget);\n };\n}\n\n/**\n * Register the model as the manager's title provider. Returns a teardown that gives\n * the manager back the provider it had — unless another one was set since, which is\n * then left alone.\n */\nexport function setupTitler(manager: AparteConversationManager, options: TitlerOptions): () => void {\n const previous = manager.getTitleProvider();\n const provider = createTitleProvider(options);\n manager.setTitleProvider(provider);\n return () => {\n if (manager.getTitleProvider() === provider) manager.setTitleProvider(previous);\n };\n}\n"],"names":[],"mappings":"AA8CO,SAAS,oBAAoB,SAAyD;AACzF,MAAI;AACJ,QAAM,QAAQ,MAA2B;AACrC,eAAW,QAAQ,QAAQ,OAAO,QAAQ,WAAW,aAAa,QAAQ,OAAA,IAAW,QAAQ,MAAM,EAM9F,MAAM,CAAC,QAAiB;AAAE,eAAS;AAAW,YAAM;AAAA,IAAK,CAAC;AAC/D,WAAO;AAAA,EACX;AACA,SAAO,OAAO,SAAS;AACnB,UAAM,SAAS,MAAM,MAAA;AACrB,WAAO,QAAQ,WAAW,SAAY,OAAO,MAAM,IAAI,IAAI,OAAO,MAAM,MAAM,QAAQ,MAAM;AAAA,EAChG;AACJ;AAOO,SAAS,YAAY,SAAoC,SAAoC;AAChG,QAAM,WAAW,QAAQ,iBAAA;AACzB,QAAM,WAAW,oBAAoB,OAAO;AAC5C,UAAQ,iBAAiB,QAAQ;AACjC,SAAO,MAAM;AACT,QAAI,QAAQ,iBAAA,MAAuB,SAAU,SAAQ,iBAAiB,QAAQ;AAAA,EAClF;AACJ;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aparte/plugin-titler",
3
- "version": "0.19.2",
3
+ "version": "0.19.3",
4
4
  "homepage": "https://apartejs.dev/plugins/titler/",
5
5
  "description": "Auto-title conversations with an aparte-titler model — 3 to 6 words of the first message, in the browser, no API call.",
6
6
  "type": "module",
@@ -25,12 +25,12 @@
25
25
  "node": ">=18"
26
26
  },
27
27
  "peerDependencies": {
28
- "@aparte/core": ">=0.19.2 <1.0.0"
28
+ "@aparte/core": ">=0.19.3 <1.0.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "typescript": "^5.4.0",
32
32
  "vite": "^6.0.0",
33
- "@aparte/core": "0.19.2"
33
+ "@aparte/core": "0.19.3"
34
34
  },
35
35
  "keywords": [
36
36
  "aparte",