@aparte/plugin-titler 0.16.10
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/LICENSE +21 -0
- package/README.md +48 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 aparté
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @aparte/plugin-titler
|
|
2
|
+
|
|
3
|
+
Auto-title conversations in [aparté](https://github.com/apartejs/aparte) with an
|
|
4
|
+
[aparte-titler](https://apartejs.dev/models/titler/) model: 3 to 6 words picked out of the
|
|
5
|
+
first message, in the browser, no API call. The model weighs 40 to 133 KB and titles in a few
|
|
6
|
+
milliseconds.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @aparte/plugin-titler @aparte/titler-latin
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import type { AparteConversationManager } from '@aparte/core';
|
|
14
|
+
import { loadTitler } from '@aparte/titler-latin'; // 17 European languages, 133 KB
|
|
15
|
+
import { setupTitler } from '@aparte/plugin-titler';
|
|
16
|
+
|
|
17
|
+
declare const manager: AparteConversationManager; // yours — the one the chat persists to
|
|
18
|
+
setupTitler(manager, { titler: loadTitler });
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`loadTitler` is called once, the first time a conversation needs a title — the model is not on
|
|
22
|
+
the page's critical path. A `Titler` instance or a promise of one (`loadTitler()`) is accepted
|
|
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).
|
|
25
|
+
|
|
26
|
+
`setupTitler` returns a teardown that gives the manager back the provider it had. For a manager
|
|
27
|
+
built with the `titleProvider` option, `createTitleProvider(options)` is the provider alone:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { AparteConversationManager, type AparteStorageAdapter } from '@aparte/core';
|
|
31
|
+
import { loadTitler } from '@aparte/titler-latin';
|
|
32
|
+
import { createTitleProvider } from '@aparte/plugin-titler';
|
|
33
|
+
|
|
34
|
+
declare const adapter: AparteStorageAdapter;
|
|
35
|
+
const manager = new AparteConversationManager(adapter, {
|
|
36
|
+
titleProvider: createTitleProvider({ titler: loadTitler, budget: 4 }),
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
An empty answer or a failed load leaves the default title (the message as typed): a titler that
|
|
41
|
+
fails never loses the message from the sidebar.
|
|
42
|
+
|
|
43
|
+
Pick the model for your languages — `@aparte/titler-latin` (17 languages, 133 KB),
|
|
44
|
+
`@aparte/titler-latin-mini` (the same 17, 96 KB), `@aparte/titler-efigsp` (en, fr, es, de, pt,
|
|
45
|
+
it, 77 KB), or `@aparte/titler` with a single-language file (40 KB) from the
|
|
46
|
+
[model repository](https://huggingface.co/apartejs/aparte-titler).
|
|
47
|
+
|
|
48
|
+
> ESM-only. Part of the aparté monorepo. Try the model at [apartejs.dev/models/titler/#demo](https://apartejs.dev/models/titler/#demo).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@aparte/plugin-titler` — auto-title conversations with an aparte-titler model.
|
|
3
|
+
*
|
|
4
|
+
* Core titles a conversation from its first user message, and the default is the
|
|
5
|
+
* message as typed. This plugin replaces that default with the words an
|
|
6
|
+
* [aparte-titler](https://apartejs.dev/models/titler/) model picks out of it — 3 to 6
|
|
7
|
+
* words, in the browser, no API call — through the manager's title provider seam.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { loadTitler } from '@aparte/titler-latin';
|
|
11
|
+
* import { setupTitler } from '@aparte/plugin-titler';
|
|
12
|
+
*
|
|
13
|
+
* setupTitler(manager, { titler: loadTitler });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* The plugin loads nothing on its own: it calls the loader you hand it, once, the
|
|
17
|
+
* first time a title is needed. Any object with `title(message, budget?)` works — the
|
|
18
|
+
* runtime's `Titler`, or one of your own.
|
|
19
|
+
*/
|
|
20
|
+
import type { AparteConversationManager, AparteConversationTitleProvider } from '@aparte/core';
|
|
21
|
+
/** What the plugin needs of a titler: `@aparte/titler`'s `Titler` has exactly this. */
|
|
22
|
+
export interface TitlerLike {
|
|
23
|
+
/** The title: the `budget` best-scored words of the message, in message order. */
|
|
24
|
+
title(message: string, budget?: number): string;
|
|
25
|
+
}
|
|
26
|
+
export interface TitlerOptions {
|
|
27
|
+
/**
|
|
28
|
+
* The model: a `Titler`, a promise of one (`loadTitler()`), or a loader called
|
|
29
|
+
* once, when the first title is needed — the shape that keeps the model out of
|
|
30
|
+
* the page's critical path.
|
|
31
|
+
*/
|
|
32
|
+
titler: TitlerLike | Promise<TitlerLike> | (() => TitlerLike | Promise<TitlerLike>);
|
|
33
|
+
/** Words to keep. Omitted, the model's own default applies (6). */
|
|
34
|
+
budget?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The title provider alone — for a manager built with the `titleProvider` option, or
|
|
38
|
+
* to compose with another provider. The model is resolved once and cached.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createTitleProvider(options: TitlerOptions): AparteConversationTitleProvider;
|
|
41
|
+
/**
|
|
42
|
+
* Register the model as the manager's title provider. Returns a teardown that gives
|
|
43
|
+
* the manager back the provider it had — unless another one was set since, which is
|
|
44
|
+
* then left alone.
|
|
45
|
+
*/
|
|
46
|
+
export declare function setupTitler(manager: AparteConversationManager, options: TitlerOptions): () => void;
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function createTitleProvider(options) {
|
|
2
|
+
let loaded;
|
|
3
|
+
const model = () => {
|
|
4
|
+
loaded ??= Promise.resolve(typeof options.titler === "function" ? options.titler() : options.titler);
|
|
5
|
+
return loaded;
|
|
6
|
+
};
|
|
7
|
+
return async (text) => {
|
|
8
|
+
const titler = await model();
|
|
9
|
+
return options.budget === void 0 ? titler.title(text) : titler.title(text, options.budget);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function setupTitler(manager, options) {
|
|
13
|
+
const previous = manager.getTitleProvider();
|
|
14
|
+
const provider = createTitleProvider(options);
|
|
15
|
+
manager.setTitleProvider(provider);
|
|
16
|
+
return () => {
|
|
17
|
+
if (manager.getTitleProvider() === provider) manager.setTitleProvider(previous);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
createTitleProvider,
|
|
22
|
+
setupTitler
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aparte/plugin-titler",
|
|
3
|
+
"version": "0.16.10",
|
|
4
|
+
"homepage": "https://apartejs.dev/plugins/titler/",
|
|
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
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"@aparte-workspace/source": "./src/index.ts",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@aparte/core": ">=0.16.10 <1.0.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"typescript": "^5.4.0",
|
|
32
|
+
"vite": "^6.0.0",
|
|
33
|
+
"@aparte/core": "0.16.10"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"aparte",
|
|
37
|
+
"plugin",
|
|
38
|
+
"titler",
|
|
39
|
+
"conversation-title",
|
|
40
|
+
"tiny-model",
|
|
41
|
+
"offline"
|
|
42
|
+
],
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/apartejs/aparte.git",
|
|
47
|
+
"directory": "packages/plugins/titler"
|
|
48
|
+
},
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/apartejs/aparte/issues"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"dev": "vite",
|
|
54
|
+
"build": "vite build && tsc -b --emitDeclarationOnly --force",
|
|
55
|
+
"preview": "vite preview",
|
|
56
|
+
"test": "vitest",
|
|
57
|
+
"test:run": "vitest run",
|
|
58
|
+
"test:coverage": "vitest run --coverage"
|
|
59
|
+
}
|
|
60
|
+
}
|