@wirecat/cli-core 0.608.0 → 0.609.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/CHANGELOG.md +67 -1
- package/dist/background/deliver.d.ts +12 -1
- package/dist/background/deliver.js +38 -5
- package/dist/background/report/render.d.ts +61 -0
- package/dist/background/report/render.js +208 -0
- package/dist/background/report/schema.d.ts +66 -0
- package/dist/background/report/schema.js +191 -0
- package/dist/background/report/templates/morning-digest.email.en.liquid +79 -0
- package/dist/background/report/templates/morning-digest.email.ru.liquid +79 -0
- package/dist/background/report/templates/morning-digest.telegram.en.liquid +77 -0
- package/dist/background/report/templates/morning-digest.telegram.ru.liquid +77 -0
- package/dist/background/report/templates/morning-digest.text.en.liquid +76 -0
- package/dist/background/report/templates/morning-digest.text.ru.liquid +76 -0
- package/dist/background/report/view.d.ts +88 -0
- package/dist/background/report/view.js +152 -0
- package/dist/background/schedules.d.ts +6 -1
- package/dist/background/schedules.js +24 -7
- package/dist/cli/embedding-choice.d.ts +4 -1
- package/dist/cli/embedding-choice.js +6 -3
- package/dist/cli/messenger/models-command.js +46 -18
- package/dist/cli/messenger/search-answers.js +11 -2
- package/dist/cli/model-catalogue-command.d.ts +33 -0
- package/dist/cli/model-catalogue-command.js +110 -21
- package/dist/cli/schedule/schedule-command.js +18 -0
- package/dist/cli/store-settings.js +39 -3
- package/dist/crm/cli/csv.d.ts +18 -5
- package/dist/crm/cli/csv.js +30 -19
- package/dist/crm/cli/index.d.ts +1 -0
- package/dist/crm/cli/index.js +1 -0
- package/dist/embeddings/models.d.ts +185 -5
- package/dist/embeddings/models.js +119 -5
- package/dist/entities/index.d.ts +24 -0
- package/dist/entities/index.js +2 -1
- package/dist/entities/model.d.ts +42 -1
- package/dist/entities/model.js +20 -1
- package/dist/render/liquid.d.ts +14 -0
- package/dist/render/liquid.js +30 -0
- package/dist/replies/template.js +3 -22
- package/dist/search/lucene/plain.js +4 -1
- package/dist/search/question-plan.js +2 -1
- package/dist/sends/permissions.js +4 -0
- package/dist/services/embeddings-maintenance.d.ts +1 -1
- package/dist/services/embeddings-maintenance.js +6 -6
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +2 -0
- package/dist/services/meeting-model.d.ts +1 -1
- package/dist/services/meeting-model.js +4 -4
- package/dist/services/messages-meaning.js +25 -4
- package/dist/services/model-downloads.js +1 -1
- package/dist/services/notes-search.d.ts +1 -1
- package/dist/services/notes-search.js +2 -2
- package/dist/services/search-all.d.ts +2 -0
- package/dist/services/search-all.js +30 -8
- package/dist/services/text-model-choice.d.ts +50 -0
- package/dist/services/text-model-choice.js +151 -0
- package/dist/store/exports.d.ts +1 -0
- package/dist/store/exports.js +1 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.js +1 -0
- package/dist/store/sqlite/owner-languages.d.ts +13 -0
- package/dist/store/sqlite/owner-languages.js +49 -0
- package/dist/store/sqlite/reported-relations.js +5 -1
- package/dist/store/sqlite/vectors.d.ts +2 -0
- package/dist/store/sqlite/vectors.js +5 -0
- package/dist/store/vectors.d.ts +2 -0
- package/dist/store/vectors.js +1 -0
- package/package.json +2 -2
- package/parity.json +13 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
1
2
|
import type { ModelFile } from "../speech/models.js";
|
|
2
3
|
/**
|
|
3
4
|
* The text embedding models `conversations embed` can use, each **pinned to one commit** and checked by
|
|
@@ -8,6 +9,10 @@ import type { ModelFile } from "../speech/models.js";
|
|
|
8
9
|
export interface TextModel {
|
|
9
10
|
id: string;
|
|
10
11
|
title: string;
|
|
12
|
+
/** How large it is next to the others, for a picker: small is fast, large reads best and is slowest. */
|
|
13
|
+
size?: "small" | "medium" | "large";
|
|
14
|
+
/** Added by the owner with `models add`, kept in the shared models file. */
|
|
15
|
+
custom?: boolean;
|
|
11
16
|
languages: string;
|
|
12
17
|
licence: string;
|
|
13
18
|
/** A licence the user accepts before the model is downloaded, or nothing for an open one. */
|
|
@@ -15,8 +20,8 @@ export interface TextModel {
|
|
|
15
20
|
dims: number;
|
|
16
21
|
/** What the model was trained on; a longer text is cut. */
|
|
17
22
|
maxTokens: number;
|
|
18
|
-
/** About how many ~300-token chunks a second one session embeds on 8 threads, for the estimate. */
|
|
19
|
-
chunksPerSecond
|
|
23
|
+
/** About how many ~300-token chunks a second one session embeds on 8 threads, for the estimate; unknown for most custom models. */
|
|
24
|
+
chunksPerSecond?: number;
|
|
20
25
|
/** How the model's output becomes one vector. */
|
|
21
26
|
pooling: "mean" | "sentence_embedding";
|
|
22
27
|
/** Prepended to a search and to a stored chunk: the model was trained with them. */
|
|
@@ -31,7 +36,178 @@ export interface TextModel {
|
|
|
31
36
|
}
|
|
32
37
|
export declare const TEXT_MODELS: TextModel[];
|
|
33
38
|
export declare const DEFAULT_TEXT_MODEL = "e5-small";
|
|
34
|
-
|
|
39
|
+
/** A model the owner adds: the same shape as a built-in one, so it is downloaded, checked and loaded the same way. */
|
|
40
|
+
export declare const CustomTextModelShape: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
41
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "is not a model id: a-z, 0-9, . _ -">]>;
|
|
42
|
+
readonly title: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 300, undefined>]>;
|
|
43
|
+
readonly languages: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 300, undefined>]>;
|
|
44
|
+
readonly licence: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 300, undefined>]>;
|
|
45
|
+
readonly terms: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UrlAction<string, undefined>]>, undefined>;
|
|
46
|
+
readonly dims: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 8192, undefined>]>;
|
|
47
|
+
readonly maxTokens: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 16, undefined>, v.MaxValueAction<number, 32768, undefined>]>;
|
|
48
|
+
readonly chunksPerSecond: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0.01, undefined>]>, undefined>;
|
|
49
|
+
readonly pooling: v.PicklistSchema<["mean", "sentence_embedding"], undefined>;
|
|
50
|
+
readonly prefix: v.StrictObjectSchema<{
|
|
51
|
+
readonly query: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 200, undefined>]>;
|
|
52
|
+
readonly passage: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 200, undefined>]>;
|
|
53
|
+
}, undefined>;
|
|
54
|
+
readonly onnx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "is not a file inside the model's folder">]>;
|
|
55
|
+
readonly externalData: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "is not a file inside the model's folder">]>, undefined>;
|
|
56
|
+
readonly files: v.SchemaWithPipe<readonly [v.ArraySchema<v.StrictObjectSchema<{
|
|
57
|
+
readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "is not a file inside the model's folder">]>;
|
|
58
|
+
readonly url: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UrlAction<string, undefined>, v.StartsWithAction<string, "https://", "has to be an https address">]>;
|
|
59
|
+
readonly sha256: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "has to be a sha256 in hex">]>;
|
|
60
|
+
readonly bytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
61
|
+
}, undefined>, undefined>, v.MinLengthAction<{
|
|
62
|
+
name: string;
|
|
63
|
+
url: string;
|
|
64
|
+
sha256: string;
|
|
65
|
+
bytes: number;
|
|
66
|
+
}[], 1, undefined>, v.MaxLengthAction<{
|
|
67
|
+
name: string;
|
|
68
|
+
url: string;
|
|
69
|
+
sha256: string;
|
|
70
|
+
bytes: number;
|
|
71
|
+
}[], 16, undefined>]>;
|
|
72
|
+
}, undefined>, v.CheckAction<{
|
|
73
|
+
id: string;
|
|
74
|
+
title: string;
|
|
75
|
+
languages: string;
|
|
76
|
+
licence: string;
|
|
77
|
+
terms?: string | undefined;
|
|
78
|
+
dims: number;
|
|
79
|
+
maxTokens: number;
|
|
80
|
+
chunksPerSecond?: number | undefined;
|
|
81
|
+
pooling: "mean" | "sentence_embedding";
|
|
82
|
+
prefix: {
|
|
83
|
+
query: string;
|
|
84
|
+
passage: string;
|
|
85
|
+
};
|
|
86
|
+
onnx: string;
|
|
87
|
+
externalData?: string | undefined;
|
|
88
|
+
files: {
|
|
89
|
+
name: string;
|
|
90
|
+
url: string;
|
|
91
|
+
sha256: string;
|
|
92
|
+
bytes: number;
|
|
93
|
+
}[];
|
|
94
|
+
}, "takes the id of a model this version ships; choose another">, v.CheckAction<{
|
|
95
|
+
id: string;
|
|
96
|
+
title: string;
|
|
97
|
+
languages: string;
|
|
98
|
+
licence: string;
|
|
99
|
+
terms?: string | undefined;
|
|
100
|
+
dims: number;
|
|
101
|
+
maxTokens: number;
|
|
102
|
+
chunksPerSecond?: number | undefined;
|
|
103
|
+
pooling: "mean" | "sentence_embedding";
|
|
104
|
+
prefix: {
|
|
105
|
+
query: string;
|
|
106
|
+
passage: string;
|
|
107
|
+
};
|
|
108
|
+
onnx: string;
|
|
109
|
+
externalData?: string | undefined;
|
|
110
|
+
files: {
|
|
111
|
+
name: string;
|
|
112
|
+
url: string;
|
|
113
|
+
sha256: string;
|
|
114
|
+
bytes: number;
|
|
115
|
+
}[];
|
|
116
|
+
}, "has to list its onnx file, its external data and tokenizer.json and tokenizer_config.json among files">]>;
|
|
117
|
+
export type CustomTextModel = v.InferOutput<typeof CustomTextModelShape>;
|
|
118
|
+
declare const TextModelsSection: v.StrictObjectSchema<{
|
|
119
|
+
readonly use: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "is not a model id: a-z, 0-9, . _ -">]>, undefined>;
|
|
120
|
+
readonly custom: v.OptionalSchema<v.ArraySchema<v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
121
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "is not a model id: a-z, 0-9, . _ -">]>;
|
|
122
|
+
readonly title: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 300, undefined>]>;
|
|
123
|
+
readonly languages: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 300, undefined>]>;
|
|
124
|
+
readonly licence: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 300, undefined>]>;
|
|
125
|
+
readonly terms: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UrlAction<string, undefined>]>, undefined>;
|
|
126
|
+
readonly dims: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 8192, undefined>]>;
|
|
127
|
+
readonly maxTokens: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 16, undefined>, v.MaxValueAction<number, 32768, undefined>]>;
|
|
128
|
+
readonly chunksPerSecond: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0.01, undefined>]>, undefined>;
|
|
129
|
+
readonly pooling: v.PicklistSchema<["mean", "sentence_embedding"], undefined>;
|
|
130
|
+
readonly prefix: v.StrictObjectSchema<{
|
|
131
|
+
readonly query: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 200, undefined>]>;
|
|
132
|
+
readonly passage: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 200, undefined>]>;
|
|
133
|
+
}, undefined>;
|
|
134
|
+
readonly onnx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "is not a file inside the model's folder">]>;
|
|
135
|
+
readonly externalData: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "is not a file inside the model's folder">]>, undefined>;
|
|
136
|
+
readonly files: v.SchemaWithPipe<readonly [v.ArraySchema<v.StrictObjectSchema<{
|
|
137
|
+
readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "is not a file inside the model's folder">]>;
|
|
138
|
+
readonly url: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UrlAction<string, undefined>, v.StartsWithAction<string, "https://", "has to be an https address">]>;
|
|
139
|
+
readonly sha256: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "has to be a sha256 in hex">]>;
|
|
140
|
+
readonly bytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
141
|
+
}, undefined>, undefined>, v.MinLengthAction<{
|
|
142
|
+
name: string;
|
|
143
|
+
url: string;
|
|
144
|
+
sha256: string;
|
|
145
|
+
bytes: number;
|
|
146
|
+
}[], 1, undefined>, v.MaxLengthAction<{
|
|
147
|
+
name: string;
|
|
148
|
+
url: string;
|
|
149
|
+
sha256: string;
|
|
150
|
+
bytes: number;
|
|
151
|
+
}[], 16, undefined>]>;
|
|
152
|
+
}, undefined>, v.CheckAction<{
|
|
153
|
+
id: string;
|
|
154
|
+
title: string;
|
|
155
|
+
languages: string;
|
|
156
|
+
licence: string;
|
|
157
|
+
terms?: string | undefined;
|
|
158
|
+
dims: number;
|
|
159
|
+
maxTokens: number;
|
|
160
|
+
chunksPerSecond?: number | undefined;
|
|
161
|
+
pooling: "mean" | "sentence_embedding";
|
|
162
|
+
prefix: {
|
|
163
|
+
query: string;
|
|
164
|
+
passage: string;
|
|
165
|
+
};
|
|
166
|
+
onnx: string;
|
|
167
|
+
externalData?: string | undefined;
|
|
168
|
+
files: {
|
|
169
|
+
name: string;
|
|
170
|
+
url: string;
|
|
171
|
+
sha256: string;
|
|
172
|
+
bytes: number;
|
|
173
|
+
}[];
|
|
174
|
+
}, "takes the id of a model this version ships; choose another">, v.CheckAction<{
|
|
175
|
+
id: string;
|
|
176
|
+
title: string;
|
|
177
|
+
languages: string;
|
|
178
|
+
licence: string;
|
|
179
|
+
terms?: string | undefined;
|
|
180
|
+
dims: number;
|
|
181
|
+
maxTokens: number;
|
|
182
|
+
chunksPerSecond?: number | undefined;
|
|
183
|
+
pooling: "mean" | "sentence_embedding";
|
|
184
|
+
prefix: {
|
|
185
|
+
query: string;
|
|
186
|
+
passage: string;
|
|
187
|
+
};
|
|
188
|
+
onnx: string;
|
|
189
|
+
externalData?: string | undefined;
|
|
190
|
+
files: {
|
|
191
|
+
name: string;
|
|
192
|
+
url: string;
|
|
193
|
+
sha256: string;
|
|
194
|
+
bytes: number;
|
|
195
|
+
}[];
|
|
196
|
+
}, "has to list its onnx file, its external data and tokenizer.json and tokenizer_config.json among files">]>, undefined>, undefined>;
|
|
197
|
+
}, undefined>;
|
|
198
|
+
export type TextModelsSection = v.InferOutput<typeof TextModelsSection>;
|
|
199
|
+
/** The shared settings file every WireCat CLI reads, so one choice serves tg, MAX, memo and the rest. */
|
|
200
|
+
export declare const textModelsFile: (env?: NodeJS.ProcessEnv) => string;
|
|
201
|
+
export declare const readTextModelsSection: (env?: NodeJS.ProcessEnv) => TextModelsSection;
|
|
202
|
+
export declare const writeTextModelsSection: (section: TextModelsSection, env?: NodeJS.ProcessEnv) => void;
|
|
203
|
+
/** The models this version ships, then the owner's own. */
|
|
204
|
+
export declare const textModels: (env?: NodeJS.ProcessEnv) => TextModel[];
|
|
205
|
+
export declare const textModel: (id: string, env?: NodeJS.ProcessEnv) => TextModel;
|
|
206
|
+
/** The model every embed and every search by meaning uses when none is named: the owner's `models use`, or e5-small. */
|
|
207
|
+
export declare const chosenTextModel: (env?: NodeJS.ProcessEnv) => {
|
|
208
|
+
id: string;
|
|
209
|
+
from: "chosen" | "default";
|
|
210
|
+
};
|
|
35
211
|
/**
|
|
36
212
|
* Cross-encoders that read a question and one hit together and score how well the hit answers it: discovery's
|
|
37
213
|
* last step. Pinned and checked as the text models are, and kept beside them. Picked in the evidence-pipeline
|
|
@@ -50,7 +226,11 @@ export interface RerankModel {
|
|
|
50
226
|
export declare const RERANK_MODELS: RerankModel[];
|
|
51
227
|
export declare const DEFAULT_RERANK_MODEL = "mmarco";
|
|
52
228
|
export declare const rerankModel: (id: string) => RerankModel;
|
|
53
|
-
/**
|
|
54
|
-
|
|
229
|
+
/**
|
|
230
|
+
* A vector's model: the provider, the model and its size — vectors of two of them never mix. A custom model's key also
|
|
231
|
+
* carries its weights' hash, so an id the owner redefines as another model starts from no vectors.
|
|
232
|
+
*/
|
|
55
233
|
export declare const vectorModelKey: (model: TextModel) => string;
|
|
234
|
+
/** The cosine a meaning hit must beat, measured in bench/search-quality; an unmeasured model keeps every hit. */
|
|
56
235
|
export declare const meaningFloor: (key: string) => number;
|
|
236
|
+
export {};
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
import { storePath } from "../store/path.js";
|
|
4
|
+
import { readSharedSection, sharedConfigPath, writeSharedSection } from "../store/shared-config.js";
|
|
2
5
|
const huggingFace = (repository, commit) => (name) => `https://huggingface.co/${repository}/resolve/${commit}/${name}`;
|
|
3
6
|
const e5 = huggingFace("Xenova/multilingual-e5-small", "761b726dd34fb83930e26aab4e9ac3899aa1fa78");
|
|
7
|
+
const e5Large = huggingFace("Xenova/multilingual-e5-large", "00fc3aeb3dbb95842de2ac1961d33c6319acf57b");
|
|
4
8
|
const gemma = huggingFace("onnx-community/embeddinggemma-300m-ONNX", "5090578d9565bb06545b4552f76e6bc2c93e4a66");
|
|
5
9
|
export const TEXT_MODELS = [
|
|
6
10
|
{
|
|
7
11
|
id: "e5-small",
|
|
8
12
|
title: "multilingual-e5-small, 8-bit",
|
|
13
|
+
size: "small",
|
|
9
14
|
languages: "about 100 languages, Russian and English among them",
|
|
10
15
|
licence: "MIT",
|
|
11
16
|
dims: 384,
|
|
@@ -39,6 +44,7 @@ export const TEXT_MODELS = [
|
|
|
39
44
|
{
|
|
40
45
|
id: "embeddinggemma",
|
|
41
46
|
title: "EmbeddingGemma 300M, 4-bit",
|
|
47
|
+
size: "medium",
|
|
42
48
|
languages: "over 100 languages — the best of the two on chat, about seven times slower",
|
|
43
49
|
licence: "Gemma Terms of Use",
|
|
44
50
|
terms: "https://ai.google.dev/gemma/terms",
|
|
@@ -76,15 +82,117 @@ export const TEXT_MODELS = [
|
|
|
76
82
|
},
|
|
77
83
|
],
|
|
78
84
|
},
|
|
85
|
+
{
|
|
86
|
+
id: "e5-large",
|
|
87
|
+
title: "multilingual-e5-large, 8-bit",
|
|
88
|
+
size: "large",
|
|
89
|
+
languages: "about 100 languages, Russian and English among them — reads better than e5-small, several times slower",
|
|
90
|
+
licence: "MIT",
|
|
91
|
+
dims: 1024,
|
|
92
|
+
maxTokens: 512,
|
|
93
|
+
// 2026-11-07, one 8-thread session on the Ryzen AI 9 HX 470 while other benchmarks ran: 3.4 chunks/s.
|
|
94
|
+
chunksPerSecond: 4,
|
|
95
|
+
pooling: "mean",
|
|
96
|
+
prefix: { query: "query: ", passage: "passage: " },
|
|
97
|
+
onnx: "onnx/model_quantized.onnx",
|
|
98
|
+
files: [
|
|
99
|
+
{
|
|
100
|
+
name: "onnx/model_quantized.onnx",
|
|
101
|
+
url: e5Large("onnx/model_quantized.onnx"),
|
|
102
|
+
sha256: "0a8d65db9a36f810ba5da15249f13145fcdc7890e6656f1fd38cd8b7c4db1fca",
|
|
103
|
+
bytes: 561_768_762,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: "tokenizer.json",
|
|
107
|
+
url: e5Large("tokenizer.json"),
|
|
108
|
+
sha256: "62c24cdc13d4c9952d63718d6c9fa4c287974249e16b7ade6d5a85e7bbb75626",
|
|
109
|
+
bytes: 17_082_660,
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "tokenizer_config.json",
|
|
113
|
+
url: e5Large("tokenizer_config.json"),
|
|
114
|
+
sha256: "efb5c0d09722e5fe59a462cd2a9976ee216d55b037597d997cd3fe833216da15",
|
|
115
|
+
bytes: 418,
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
79
119
|
];
|
|
80
120
|
export const DEFAULT_TEXT_MODEL = "e5-small";
|
|
81
|
-
|
|
82
|
-
|
|
121
|
+
const SECTION = "text_models";
|
|
122
|
+
const slug = v.pipe(v.string(), v.regex(/^[a-z0-9][a-z0-9._-]{0,62}$/, "is not a model id: a-z, 0-9, . _ -"));
|
|
123
|
+
const words = v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(300));
|
|
124
|
+
/** Joined under the model's folder: never absolute, never climbing out of it. */
|
|
125
|
+
const fileName = v.pipe(v.string(), v.check((name) => /^[\w.-]+(\/[\w.-]+)*$/.test(name) && !name.split("/").some((part) => part === ".." || part === "."), "is not a file inside the model's folder"));
|
|
126
|
+
const modelFile = v.strictObject({
|
|
127
|
+
name: fileName,
|
|
128
|
+
url: v.pipe(v.string(), v.url(), v.startsWith("https://", "has to be an https address")),
|
|
129
|
+
sha256: v.pipe(v.string(), v.regex(/^[0-9a-f]{64}$/, "has to be a sha256 in hex")),
|
|
130
|
+
bytes: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
131
|
+
});
|
|
132
|
+
/** A model the owner adds: the same shape as a built-in one, so it is downloaded, checked and loaded the same way. */
|
|
133
|
+
export const CustomTextModelShape = v.pipe(v.strictObject({
|
|
134
|
+
id: slug,
|
|
135
|
+
title: words,
|
|
136
|
+
languages: words,
|
|
137
|
+
licence: words,
|
|
138
|
+
terms: v.optional(v.pipe(v.string(), v.url())),
|
|
139
|
+
dims: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(8192)),
|
|
140
|
+
maxTokens: v.pipe(v.number(), v.integer(), v.minValue(16), v.maxValue(32_768)),
|
|
141
|
+
chunksPerSecond: v.optional(v.pipe(v.number(), v.minValue(0.01))),
|
|
142
|
+
pooling: v.picklist(["mean", "sentence_embedding"]),
|
|
143
|
+
prefix: v.strictObject({
|
|
144
|
+
query: v.pipe(v.string(), v.maxLength(200)),
|
|
145
|
+
passage: v.pipe(v.string(), v.maxLength(200)),
|
|
146
|
+
}),
|
|
147
|
+
onnx: fileName,
|
|
148
|
+
externalData: v.optional(fileName),
|
|
149
|
+
files: v.pipe(v.array(modelFile), v.minLength(1), v.maxLength(16)),
|
|
150
|
+
}), v.check((model) => !TEXT_MODELS.some((one) => one.id === model.id), "takes the id of a model this version ships; choose another"), v.check((model) => {
|
|
151
|
+
const names = model.files.map(({ name }) => name);
|
|
152
|
+
return [model.onnx, model.externalData, "tokenizer.json", "tokenizer_config.json"].every((name) => name === undefined || names.includes(name));
|
|
153
|
+
}, "has to list its onnx file, its external data and tokenizer.json and tokenizer_config.json among files"));
|
|
154
|
+
const TextModelsSection = v.strictObject({
|
|
155
|
+
use: v.optional(slug),
|
|
156
|
+
custom: v.optional(v.array(CustomTextModelShape)),
|
|
157
|
+
});
|
|
158
|
+
/** The shared settings file every WireCat CLI reads, so one choice serves tg, MAX, memo and the rest. */
|
|
159
|
+
export const textModelsFile = (env = process.env) => sharedConfigPath(storePath(env), env);
|
|
160
|
+
export const readTextModelsSection = (env = process.env) => {
|
|
161
|
+
const path = textModelsFile(env);
|
|
162
|
+
const section = readSharedSection(path, SECTION);
|
|
163
|
+
if (section === undefined)
|
|
164
|
+
return {};
|
|
165
|
+
const checked = v.safeParse(TextModelsSection, section);
|
|
166
|
+
if (!checked.success) {
|
|
167
|
+
const issue = checked.issues[0];
|
|
168
|
+
const at = issue ? v.getDotPath(issue) : null;
|
|
169
|
+
throw new CliError("configuration_error", `${path}: ${SECTION}${at ? `.${at}` : ""} ${issue?.message ?? "is not valid"}`);
|
|
170
|
+
}
|
|
171
|
+
const ids = checked.output.custom?.map(({ id }) => id) ?? [];
|
|
172
|
+
const twice = ids.find((id, at) => ids.indexOf(id) !== at);
|
|
173
|
+
if (twice)
|
|
174
|
+
throw new CliError("configuration_error", `${path}: ${SECTION}.custom names ${twice} twice`);
|
|
175
|
+
return checked.output;
|
|
176
|
+
};
|
|
177
|
+
export const writeTextModelsSection = (section, env = process.env) => writeSharedSection(textModelsFile(env), SECTION, section.use === undefined && !section.custom?.length ? undefined : section);
|
|
178
|
+
/** The models this version ships, then the owner's own. */
|
|
179
|
+
export const textModels = (env = process.env) => [
|
|
180
|
+
...TEXT_MODELS,
|
|
181
|
+
...(readTextModelsSection(env).custom ?? []).map((model) => ({ ...model, custom: true })),
|
|
182
|
+
];
|
|
183
|
+
export const textModel = (id, env = process.env) => {
|
|
184
|
+
const known = textModels(env);
|
|
185
|
+
const found = known.find((model) => model.id === id);
|
|
83
186
|
if (!found) {
|
|
84
|
-
throw new CliError("validation_error", `no text model ${id} — one of: ${
|
|
187
|
+
throw new CliError("validation_error", `no text model ${id} — one of: ${known.map((model) => model.id).join(", ")}`);
|
|
85
188
|
}
|
|
86
189
|
return found;
|
|
87
190
|
};
|
|
191
|
+
/** The model every embed and every search by meaning uses when none is named: the owner's `models use`, or e5-small. */
|
|
192
|
+
export const chosenTextModel = (env = process.env) => {
|
|
193
|
+
const use = readTextModelsSection(env).use;
|
|
194
|
+
return use === undefined ? { id: DEFAULT_TEXT_MODEL, from: "default" } : { id: use, from: "chosen" };
|
|
195
|
+
};
|
|
88
196
|
const mmarco = huggingFace("cross-encoder/mmarco-mMiniLMv2-L12-H384-v1", "1427fd652930e4ba29e8149678df786c240d8825");
|
|
89
197
|
const bge = huggingFace("onnx-community/bge-reranker-v2-m3-ONNX", "6f5ff65298512715a1e669753bc754d2bc8f367b");
|
|
90
198
|
export const RERANK_MODELS = [
|
|
@@ -154,7 +262,13 @@ export const rerankModel = (id) => {
|
|
|
154
262
|
}
|
|
155
263
|
return found;
|
|
156
264
|
};
|
|
265
|
+
/**
|
|
266
|
+
* A vector's model: the provider, the model and its size — vectors of two of them never mix. A custom model's key also
|
|
267
|
+
* carries its weights' hash, so an id the owner redefines as another model starts from no vectors.
|
|
268
|
+
*/
|
|
269
|
+
export const vectorModelKey = (model) => {
|
|
270
|
+
const weights = model.custom ? model.files.find(({ name }) => name === model.onnx)?.sha256.slice(0, 12) : undefined;
|
|
271
|
+
return `local:${model.id}${weights ? `@${weights}` : ""}:${model.dims}`;
|
|
272
|
+
};
|
|
157
273
|
/** The cosine a meaning hit must beat, measured in bench/search-quality; an unmeasured model keeps every hit. */
|
|
158
|
-
/** A vector's model: the provider, the model and its size — vectors of two of them never mix. */
|
|
159
|
-
export const vectorModelKey = (model) => `local:${model.id}:${model.dims}`;
|
|
160
274
|
export const meaningFloor = (key) => (key === "local:e5-small:384" ? 0.8 : 0);
|
package/dist/entities/index.d.ts
CHANGED
|
@@ -9931,6 +9931,11 @@ export declare const ENTITIES: {
|
|
|
9931
9931
|
readonly title: v.StringSchema<undefined>;
|
|
9932
9932
|
readonly languages: v.StringSchema<undefined>;
|
|
9933
9933
|
readonly licence: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
9934
|
+
readonly terms: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
9935
|
+
readonly size: v.OptionalSchema<v.PicklistSchema<["small", "medium", "large"], undefined>, undefined>;
|
|
9936
|
+
readonly dims: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
9937
|
+
readonly chunks_per_second: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
|
|
9938
|
+
readonly custom: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
9934
9939
|
readonly size_bytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
9935
9940
|
readonly downloaded: v.BooleanSchema<undefined>;
|
|
9936
9941
|
readonly default: v.BooleanSchema<undefined>;
|
|
@@ -10211,6 +10216,25 @@ export declare const ENTITIES: {
|
|
|
10211
10216
|
readonly command: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
10212
10217
|
}, undefined>, undefined>;
|
|
10213
10218
|
}, undefined>;
|
|
10219
|
+
readonly "model.chosen": v.StrictObjectSchema<{
|
|
10220
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
10221
|
+
readonly kind: v.PicklistSchema<["audio", "text", "image", "reranker"], undefined>;
|
|
10222
|
+
readonly title: v.StringSchema<undefined>;
|
|
10223
|
+
readonly languages: v.StringSchema<undefined>;
|
|
10224
|
+
readonly licence: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
10225
|
+
readonly terms: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
10226
|
+
readonly size: v.OptionalSchema<v.PicklistSchema<["small", "medium", "large"], undefined>, undefined>;
|
|
10227
|
+
readonly dims: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
10228
|
+
readonly chunks_per_second: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
|
|
10229
|
+
readonly custom: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
10230
|
+
readonly size_bytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
10231
|
+
readonly downloaded: v.BooleanSchema<undefined>;
|
|
10232
|
+
readonly default: v.BooleanSchema<undefined>;
|
|
10233
|
+
readonly path: v.StringSchema<undefined>;
|
|
10234
|
+
readonly previous: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
10235
|
+
readonly to_embed: v.NullableSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
10236
|
+
readonly estimate_seconds: v.NullableSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
10237
|
+
}, undefined>;
|
|
10214
10238
|
readonly model_key: v.StrictObjectSchema<{
|
|
10215
10239
|
readonly provider: v.StringSchema<undefined>;
|
|
10216
10240
|
readonly stored: v.OptionalSchema<v.PicklistSchema<["environment", "keyring", "file"], undefined>, undefined>;
|
package/dist/entities/index.js
CHANGED
|
@@ -66,7 +66,7 @@ import { messageLink } from "./message-link.js";
|
|
|
66
66
|
import { evidencePacket, messageLinks, messageTranscript } from "./message-read.js";
|
|
67
67
|
import { messageDownload, messageSync } from "./message-transfer.js";
|
|
68
68
|
import { messageSend, messageWrite } from "./message-write.js";
|
|
69
|
-
import { model } from "./model.js";
|
|
69
|
+
import { chosenModel, model } from "./model.js";
|
|
70
70
|
import { modelKey, removedModelKey, storedModelKey } from "./model-key.js";
|
|
71
71
|
import { note } from "./note.js";
|
|
72
72
|
import { officialStats } from "./official-stats.js";
|
|
@@ -340,6 +340,7 @@ export const ENTITIES = {
|
|
|
340
340
|
chat_folder_order: chatFolderOrder,
|
|
341
341
|
chat_rules: chatRules,
|
|
342
342
|
chat_moderation: chatModeration,
|
|
343
|
+
"model.chosen": chosenModel,
|
|
343
344
|
model_key: modelKey,
|
|
344
345
|
"model_key.stored": storedModelKey,
|
|
345
346
|
"model_key.removed": removedModelKey,
|
package/dist/entities/model.d.ts
CHANGED
|
@@ -10,11 +10,52 @@ export declare const model: v.StrictObjectSchema<{
|
|
|
10
10
|
/** Which languages it reads, in words. */
|
|
11
11
|
readonly languages: v.StringSchema<undefined>;
|
|
12
12
|
readonly licence: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
13
|
+
/** A text model's licence terms to accept with `models download --accept-terms`. */
|
|
14
|
+
readonly terms: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
15
|
+
/** A text model's size next to the others: small is fastest, large reads best. */
|
|
16
|
+
readonly size: v.OptionalSchema<v.PicklistSchema<["small", "medium", "large"], undefined>, undefined>;
|
|
17
|
+
/** A text model's vector length. */
|
|
18
|
+
readonly dims: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
19
|
+
/** About how many chunks a second a text model embeds here, when measured. */
|
|
20
|
+
readonly chunks_per_second: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
|
|
21
|
+
/** A text model the owner added with `models add`. */
|
|
22
|
+
readonly custom: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
13
23
|
/** What its files take on disk once downloaded. */
|
|
14
24
|
readonly size_bytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
15
25
|
readonly downloaded: v.BooleanSchema<undefined>;
|
|
16
|
-
/** The one used when no model is named. */
|
|
26
|
+
/** The one used when no model is named: for text, the one `models use` chose. */
|
|
17
27
|
readonly default: v.BooleanSchema<undefined>;
|
|
18
28
|
/** The folder its files are in once downloaded, so an agent can place them by hand. */
|
|
19
29
|
readonly path: v.StringSchema<undefined>;
|
|
20
30
|
}, undefined>;
|
|
31
|
+
/** `models set`: the model now in use, the one before it, and what the next syncs still embed with it. */
|
|
32
|
+
export declare const chosenModel: v.StrictObjectSchema<{
|
|
33
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
34
|
+
readonly kind: v.PicklistSchema<["audio", "text", "image", "reranker"], undefined>;
|
|
35
|
+
readonly title: v.StringSchema<undefined>;
|
|
36
|
+
/** Which languages it reads, in words. */
|
|
37
|
+
readonly languages: v.StringSchema<undefined>;
|
|
38
|
+
readonly licence: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
39
|
+
/** A text model's licence terms to accept with `models download --accept-terms`. */
|
|
40
|
+
readonly terms: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
41
|
+
/** A text model's size next to the others: small is fastest, large reads best. */
|
|
42
|
+
readonly size: v.OptionalSchema<v.PicklistSchema<["small", "medium", "large"], undefined>, undefined>;
|
|
43
|
+
/** A text model's vector length. */
|
|
44
|
+
readonly dims: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
45
|
+
/** About how many chunks a second a text model embeds here, when measured. */
|
|
46
|
+
readonly chunks_per_second: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
|
|
47
|
+
/** A text model the owner added with `models add`. */
|
|
48
|
+
readonly custom: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
49
|
+
/** What its files take on disk once downloaded. */
|
|
50
|
+
readonly size_bytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
51
|
+
readonly downloaded: v.BooleanSchema<undefined>;
|
|
52
|
+
/** The one used when no model is named: for text, the one `models use` chose. */
|
|
53
|
+
readonly default: v.BooleanSchema<undefined>;
|
|
54
|
+
/** The folder its files are in once downloaded, so an agent can place them by hand. */
|
|
55
|
+
readonly path: v.StringSchema<undefined>;
|
|
56
|
+
readonly previous: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
57
|
+
/** Chunk texts the previous model has vectors for and this one has not; `null` when no store is there to count. */
|
|
58
|
+
readonly to_embed: v.NullableSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
59
|
+
/** Embedding time alone at the model's speed, done a part per sync; `null` when the speed or the count is unknown. */
|
|
60
|
+
readonly estimate_seconds: v.NullableSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
61
|
+
}, undefined>;
|
package/dist/entities/model.js
CHANGED
|
@@ -11,11 +11,30 @@ export const model = v.strictObject({
|
|
|
11
11
|
/** Which languages it reads, in words. */
|
|
12
12
|
languages: text,
|
|
13
13
|
licence: v.optional(text),
|
|
14
|
+
/** A text model's licence terms to accept with `models download --accept-terms`. */
|
|
15
|
+
terms: v.optional(text),
|
|
16
|
+
/** A text model's size next to the others: small is fastest, large reads best. */
|
|
17
|
+
size: v.optional(v.picklist(["small", "medium", "large"])),
|
|
18
|
+
/** A text model's vector length. */
|
|
19
|
+
dims: v.optional(count),
|
|
20
|
+
/** About how many chunks a second a text model embeds here, when measured. */
|
|
21
|
+
chunks_per_second: v.optional(v.number()),
|
|
22
|
+
/** A text model the owner added with `models add`. */
|
|
23
|
+
custom: v.optional(v.boolean()),
|
|
14
24
|
/** What its files take on disk once downloaded. */
|
|
15
25
|
size_bytes: count,
|
|
16
26
|
downloaded: v.boolean(),
|
|
17
|
-
/** The one used when no model is named. */
|
|
27
|
+
/** The one used when no model is named: for text, the one `models use` chose. */
|
|
18
28
|
default: v.boolean(),
|
|
19
29
|
/** The folder its files are in once downloaded, so an agent can place them by hand. */
|
|
20
30
|
path: text,
|
|
21
31
|
});
|
|
32
|
+
/** `models set`: the model now in use, the one before it, and what the next syncs still embed with it. */
|
|
33
|
+
export const chosenModel = v.strictObject({
|
|
34
|
+
...model.entries,
|
|
35
|
+
previous: id,
|
|
36
|
+
/** Chunk texts the previous model has vectors for and this one has not; `null` when no store is there to count. */
|
|
37
|
+
to_embed: v.nullable(count),
|
|
38
|
+
/** Embedding time alone at the model's speed, done a part per sync; `null` when the speed or the count is unknown. */
|
|
39
|
+
estimate_seconds: v.nullable(count),
|
|
40
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Liquid } from "liquidjs";
|
|
2
|
+
export interface LiquidLimits {
|
|
3
|
+
/** Characters of template source. */
|
|
4
|
+
parse: number;
|
|
5
|
+
/** Bytes a render may allocate, as LiquidJS counts them. */
|
|
6
|
+
memory: number;
|
|
7
|
+
milliseconds: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The one Liquid engine for owner-written templates (reply rules, report templates): unknown variables and filters
|
|
11
|
+
* are errors, only own properties are read, and `include`, `render` and `layout` are refused, so a template cannot
|
|
12
|
+
* read a file.
|
|
13
|
+
*/
|
|
14
|
+
export declare const safeLiquid: (limits: LiquidLimits) => Liquid;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Liquid, Tag } from "liquidjs";
|
|
2
|
+
/**
|
|
3
|
+
* The one Liquid engine for owner-written templates (reply rules, report templates): unknown variables and filters
|
|
4
|
+
* are errors, only own properties are read, and `include`, `render` and `layout` are refused, so a template cannot
|
|
5
|
+
* read a file.
|
|
6
|
+
*/
|
|
7
|
+
export const safeLiquid = (limits) => {
|
|
8
|
+
const engine = new Liquid({
|
|
9
|
+
ownPropertyOnly: true,
|
|
10
|
+
strictVariables: true,
|
|
11
|
+
strictFilters: true,
|
|
12
|
+
lenientIf: false,
|
|
13
|
+
parseLimit: limits.parse,
|
|
14
|
+
renderLimit: limits.milliseconds,
|
|
15
|
+
memoryLimit: limits.memory,
|
|
16
|
+
preserveTimezones: true,
|
|
17
|
+
});
|
|
18
|
+
for (const name of ["include", "render", "layout"]) {
|
|
19
|
+
engine.registerTag(name, class extends Tag {
|
|
20
|
+
constructor(token, tokens, liquid) {
|
|
21
|
+
super(token, tokens, liquid);
|
|
22
|
+
throw new Error("templates cannot read files");
|
|
23
|
+
}
|
|
24
|
+
render() {
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return engine;
|
|
30
|
+
};
|
package/dist/replies/template.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import { Context,
|
|
2
|
+
import { Context, Tag, } from "liquidjs";
|
|
3
|
+
import { safeLiquid } from "../render/liquid.js";
|
|
3
4
|
export const TEMPLATE_LIMITS = {
|
|
4
5
|
parse: 32_768,
|
|
5
6
|
renders: 2_000,
|
|
@@ -56,27 +57,7 @@ export const renderReplyTemplate = async (reply, input) => {
|
|
|
56
57
|
.formatToParts(input.now)
|
|
57
58
|
.map(({ type, value }) => [type, value]));
|
|
58
59
|
const localTime = `${parts.year}-${parts.month}-${parts.day}T${parts.hour}:${parts.minute}:${parts.second}${parts.timeZoneName?.replace("GMT", "") || "+00:00"}`;
|
|
59
|
-
const engine =
|
|
60
|
-
ownPropertyOnly: true,
|
|
61
|
-
strictVariables: true,
|
|
62
|
-
strictFilters: true,
|
|
63
|
-
lenientIf: false,
|
|
64
|
-
parseLimit: limits.parse,
|
|
65
|
-
renderLimit: limits.milliseconds,
|
|
66
|
-
memoryLimit: limits.memory,
|
|
67
|
-
preserveTimezones: true,
|
|
68
|
-
});
|
|
69
|
-
for (const name of ["include", "render", "layout"]) {
|
|
70
|
-
engine.registerTag(name, class extends Tag {
|
|
71
|
-
constructor(token, tokens, liquid) {
|
|
72
|
-
super(token, tokens, liquid);
|
|
73
|
-
throw new Error("reply templates cannot read files");
|
|
74
|
-
}
|
|
75
|
-
render() {
|
|
76
|
-
return "";
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
60
|
+
const engine = safeLiquid({ parse: limits.parse, memory: limits.memory, milliseconds: limits.milliseconds });
|
|
80
61
|
engine.registerTag("ai", class extends Tag {
|
|
81
62
|
body = [];
|
|
82
63
|
fallback = null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isCliError } from "@wirecat/cli-base";
|
|
1
|
+
import { CliError, isCliError } from "@wirecat/cli-base";
|
|
2
2
|
import { parseLucene, walkQuery } from "@wirecat/cli-base/query";
|
|
3
3
|
import { QUERY_FIELDS } from "./registry.js";
|
|
4
4
|
import { MESSAGE_PARSING } from "./types.js";
|
|
@@ -92,6 +92,9 @@ const without = (text, leaves) => [...leaves]
|
|
|
92
92
|
* search to report. `fields` are the names a list of its own (memories: `text`, `scope`) reads as fields.
|
|
93
93
|
*/
|
|
94
94
|
export const plainQuery = (text, fields = SEARCH_FIELDS) => {
|
|
95
|
+
// `""`, a lone `?` or an emoji holds nothing the word index keeps, so it would find nothing and say nothing.
|
|
96
|
+
if (text.trim() && !/[\p{L}\p{N}*]/u.test(text))
|
|
97
|
+
throw new CliError("validation_error", `search needs a letter or a digit to look for; ${JSON.stringify(text)} has none`);
|
|
95
98
|
let current = text;
|
|
96
99
|
let whole = false;
|
|
97
100
|
for (let tries = 0; tries <= 64; tries++) {
|
|
@@ -81,7 +81,8 @@ export function planQuestion(text, strict = false) {
|
|
|
81
81
|
const bypass = strict ||
|
|
82
82
|
!natural ||
|
|
83
83
|
implicitTextTerms(cleaned).size === 0 ||
|
|
84
|
-
|
|
84
|
+
// A quoted single word is how `plainQuery` keeps `10:30` or `HH:MM` literal; it is no phrase the asker wrote.
|
|
85
|
+
textual.some((p) => !(p.operator === "term" || (p.operator === "phrase" && !/\s/u.test(p.value))) || p.field === "exact");
|
|
85
86
|
if (bypass)
|
|
86
87
|
return {
|
|
87
88
|
changed: false,
|