@exulu/backend 5.6.0 → 5.7.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/dist/{chunk-SJNP75II.js → chunk-TAXHJJ5R.js} +65 -7
- package/dist/{convert-exulu-tools-to-ai-sdk-tools-7TYZVHEQ.js → convert-exulu-tools-to-ai-sdk-tools-BPZSN22N.js} +1 -1
- package/dist/index.cjs +307 -38
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +212 -13
- package/ee/tokenizer.test.ts +178 -0
- package/ee/tokenizer.ts +80 -6
- package/package.json +1 -1
|
@@ -1723,7 +1723,7 @@ var ExuluTool = class _ExuluTool {
|
|
|
1723
1723
|
if (!agent) {
|
|
1724
1724
|
throw new Error("Agent not found.");
|
|
1725
1725
|
}
|
|
1726
|
-
const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-
|
|
1726
|
+
const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-BPZSN22N.js");
|
|
1727
1727
|
const tools = await convertExuluToolsToAiSdkTools2(
|
|
1728
1728
|
[this],
|
|
1729
1729
|
[],
|
|
@@ -5776,23 +5776,57 @@ import { Tiktoken } from "tiktoken/lite";
|
|
|
5776
5776
|
import { load } from "tiktoken/load";
|
|
5777
5777
|
import registry from "tiktoken/registry.json" with { type: "json" };
|
|
5778
5778
|
import models from "tiktoken/model_to_encoding.json" with { type: "json" };
|
|
5779
|
+
var ranksByEncoding = /* @__PURE__ */ new Map();
|
|
5780
|
+
var loadRanks = (encoding) => {
|
|
5781
|
+
const cached = ranksByEncoding.get(encoding);
|
|
5782
|
+
if (cached) return cached;
|
|
5783
|
+
const time = performance.now();
|
|
5784
|
+
console.log("[EXULU] Loading tokenizer ranks.", encoding);
|
|
5785
|
+
const pending = load(registry[encoding]).then((ranks) => {
|
|
5786
|
+
console.log("[EXULU] Loaded tokenizer ranks.", encoding, performance.now() - time);
|
|
5787
|
+
return ranks;
|
|
5788
|
+
}).catch((error) => {
|
|
5789
|
+
ranksByEncoding.delete(encoding);
|
|
5790
|
+
throw error;
|
|
5791
|
+
});
|
|
5792
|
+
ranksByEncoding.set(encoding, pending);
|
|
5793
|
+
return pending;
|
|
5794
|
+
};
|
|
5779
5795
|
var ExuluTokenizer = class {
|
|
5780
5796
|
constructor() {
|
|
5781
5797
|
}
|
|
5782
5798
|
encoder = null;
|
|
5799
|
+
/** Remembered so `ensure()` can rebuild an encoder that `free()` released. */
|
|
5800
|
+
modelName = null;
|
|
5783
5801
|
async create(modelName) {
|
|
5802
|
+
this.modelName = modelName;
|
|
5784
5803
|
if (this.encoder) {
|
|
5785
5804
|
return this.encoder;
|
|
5786
5805
|
}
|
|
5787
|
-
const
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
console.log("[EXULU] Loaded tokenizer.", modelName, performance.now() - time);
|
|
5791
|
-
const encoder = new Tiktoken(model.bpe_ranks, model.special_tokens, model.pat_str);
|
|
5792
|
-
console.log("[EXULU] Set encoder.");
|
|
5806
|
+
const ranks = await loadRanks(models[modelName]);
|
|
5807
|
+
const encoder = new Tiktoken(ranks.bpe_ranks, ranks.special_tokens, ranks.pat_str);
|
|
5808
|
+
console.log("[EXULU] Set encoder.", modelName);
|
|
5793
5809
|
this.encoder = encoder;
|
|
5794
5810
|
return encoder;
|
|
5795
5811
|
}
|
|
5812
|
+
/**
|
|
5813
|
+
* The encoder, rebuilt if a previous `chunk()` freed it.
|
|
5814
|
+
*
|
|
5815
|
+
* Both chunkers free their tokenizer at the end of every `chunk()`, so an
|
|
5816
|
+
* instance that is used twice — directly, or via `chunkBatch`, which calls
|
|
5817
|
+
* `chunk()` once per text — needs its encoder back. Rebuilding is cheap:
|
|
5818
|
+
* the ranks are already cached process-wide, so this costs a `Tiktoken`
|
|
5819
|
+
* construction and no network.
|
|
5820
|
+
*/
|
|
5821
|
+
async ensure() {
|
|
5822
|
+
if (this.encoder) {
|
|
5823
|
+
return this.encoder;
|
|
5824
|
+
}
|
|
5825
|
+
if (!this.modelName) {
|
|
5826
|
+
throw new Error("Tokenizer not initialized");
|
|
5827
|
+
}
|
|
5828
|
+
return this.create(this.modelName);
|
|
5829
|
+
}
|
|
5796
5830
|
async decode(tokens) {
|
|
5797
5831
|
if (!this.encoder) {
|
|
5798
5832
|
throw new Error("Tokenizer not initialized");
|
|
@@ -5837,6 +5871,7 @@ var ExuluTokenizer = class {
|
|
|
5837
5871
|
console.log("[EXULU] Freeing tokenizer.");
|
|
5838
5872
|
if (this.encoder) {
|
|
5839
5873
|
this.encoder.free();
|
|
5874
|
+
this.encoder = null;
|
|
5840
5875
|
}
|
|
5841
5876
|
}
|
|
5842
5877
|
};
|
|
@@ -6328,6 +6363,7 @@ var SentenceChunker = class _SentenceChunker extends BaseChunker {
|
|
|
6328
6363
|
if (!text.trim()) {
|
|
6329
6364
|
return [];
|
|
6330
6365
|
}
|
|
6366
|
+
await this.tokenizer.ensure();
|
|
6331
6367
|
const sentences = await this._prepareSentences(text);
|
|
6332
6368
|
if (!sentences.length) {
|
|
6333
6369
|
return [];
|
|
@@ -10293,6 +10329,28 @@ var agentSessionsSchema = {
|
|
|
10293
10329
|
name: "currenttask",
|
|
10294
10330
|
type: "text",
|
|
10295
10331
|
required: false
|
|
10332
|
+
},
|
|
10333
|
+
// Chat-list activity (see src/exulu/session-activity.ts). All three stay
|
|
10334
|
+
// NULL on existing rows, so no historical conversation starts out looking
|
|
10335
|
+
// unread.
|
|
10336
|
+
{
|
|
10337
|
+
// Non-null while a turn is producing an answer.
|
|
10338
|
+
name: "generating_since",
|
|
10339
|
+
type: "date",
|
|
10340
|
+
required: false
|
|
10341
|
+
},
|
|
10342
|
+
{
|
|
10343
|
+
// When the most recent answer finished.
|
|
10344
|
+
name: "last_answer_at",
|
|
10345
|
+
type: "date",
|
|
10346
|
+
required: false
|
|
10347
|
+
},
|
|
10348
|
+
{
|
|
10349
|
+
// When someone last had the session open. last_answer_at later than
|
|
10350
|
+
// this is an answer nobody has read.
|
|
10351
|
+
name: "last_seen_at",
|
|
10352
|
+
type: "date",
|
|
10353
|
+
required: false
|
|
10296
10354
|
}
|
|
10297
10355
|
]
|
|
10298
10356
|
};
|