@aparte/plugin-titler 0.16.11 → 0.17.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.
@@ -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,CAU3F;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,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"}
package/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  function createTitleProvider(options) {
2
2
  let loaded;
3
3
  const model = () => {
4
- loaded ??= Promise.resolve(typeof options.titler === "function" ? options.titler() : options.titler);
4
+ loaded ??= Promise.resolve(typeof options.titler === "function" ? options.titler() : options.titler).catch((err) => {
5
+ loaded = void 0;
6
+ throw err;
7
+ });
5
8
  return loaded;
6
9
  };
7
10
  return async (text) => {
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 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,WAAW,QAAQ,MAAM;AACnG,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 /** 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;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aparte/plugin-titler",
3
- "version": "0.16.11",
3
+ "version": "0.17.0",
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.16.11 <1.0.0"
28
+ "@aparte/core": ">=0.17.0 <1.0.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "typescript": "^5.4.0",
32
32
  "vite": "^6.0.0",
33
- "@aparte/core": "0.16.11"
33
+ "@aparte/core": "0.17.0"
34
34
  },
35
35
  "keywords": [
36
36
  "aparte",