@wirecat/cli-core 0.640.0 → 0.642.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 +80 -0
- package/dist/analysis/provider.d.ts +1 -1
- package/dist/analysis/provider.js +2 -1
- package/dist/attachments/gateway-ocr.js +13 -8
- package/dist/background/schedules.d.ts +5 -1
- package/dist/background/schedules.js +28 -3
- package/dist/calendar/mcp/index.d.ts +12 -12
- package/dist/cli/ai-model-command.js +6 -3
- package/dist/cli/analysis-choice.js +20 -4
- package/dist/cli/enrichment-consents-command.js +2 -0
- package/dist/cli/local-only-command.d.ts +10 -0
- package/dist/cli/local-only-command.js +103 -0
- package/dist/cli/messenger/backfill-command.js +16 -1
- package/dist/cli/messenger/conversations-command.js +1 -1
- package/dist/cli/messenger/replies-consents-command.js +12 -6
- package/dist/cli/messenger/search-answers.js +2 -0
- package/dist/cli/model-catalogue-command.js +2 -0
- package/dist/cli/search-harder-consents-command.js +16 -1
- package/dist/cli/store-settings.d.ts +4 -1
- package/dist/cli/store-settings.js +26 -9
- package/dist/crm/cli/csv.js +2 -0
- package/dist/crm/cli/index.js +8 -2
- package/dist/crm/cli/search-all.js +4 -4
- package/dist/crm/stage-tasks.d.ts +8 -0
- package/dist/crm/stage-tasks.js +42 -0
- package/dist/documents.d.ts +1 -1
- package/dist/documents.js +1 -1
- package/dist/domain/crm.d.ts +6 -0
- package/dist/embeddings/remote.d.ts +2 -1
- package/dist/embeddings/remote.js +5 -3
- package/dist/entities/deal.d.ts +6 -0
- package/dist/entities/deal.js +3 -0
- package/dist/entities/index.d.ts +4 -0
- package/dist/errors/reasons.js +8 -0
- package/dist/meetings/mcp/index.d.ts +15 -15
- package/dist/models/ai.d.ts +16 -3
- package/dist/models/ai.js +19 -13
- package/dist/models/endpoint.d.ts +5 -0
- package/dist/models/endpoint.js +13 -0
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +9 -1
- package/dist/models/local-only.d.ts +17 -0
- package/dist/models/local-only.js +42 -0
- package/dist/models/purpose.d.ts +24 -0
- package/dist/models/purpose.js +26 -0
- package/dist/replies/rendering.js +10 -10
- package/dist/runs/events.d.ts +9 -1
- package/dist/runs/events.js +5 -1
- package/dist/runs/log-events.js +2 -0
- package/dist/services/deal-context.js +17 -0
- package/dist/services/embeddings-maintenance.js +4 -1
- package/dist/services/enrichment.d.ts +1 -1
- package/dist/services/enrichment.js +27 -0
- package/dist/services/meeting-model.js +1 -1
- package/dist/services/message-resolution.d.ts +1 -1
- package/dist/services/message-resolution.js +2 -2
- package/dist/services/messages-search.js +12 -5
- package/dist/services/search-all.d.ts +10 -3
- package/dist/services/search-all.js +10 -4
- package/dist/services/search-harder.d.ts +11 -1
- package/dist/services/search-harder.js +38 -5
- package/dist/speech/openai.js +2 -0
- package/dist/speech/transcribe.d.ts +5 -2
- package/dist/speech/transcribe.js +14 -5
- package/dist/store/index.d.ts +1 -1
- package/dist/store/sqlite/crm-rows.js +2 -0
- package/dist/store/sqlite/crm-settings.d.ts +26 -1
- package/dist/store/sqlite/crm-settings.js +104 -1
- package/dist/store/sqlite/crm.d.ts +12 -0
- package/dist/store/sqlite/crm.js +4 -1
- package/dist/store/sqlite/deals.d.ts +28 -5
- package/dist/store/sqlite/deals.js +158 -14
- package/dist/store/sqlite/lucene-fields.js +56 -3
- package/dist/store/sqlite/tasks.js +9 -8
- package/dist/tasks/model.d.ts +6 -2
- package/dist/tasks/service.d.ts +2 -0
- package/package.json +1 -1
|
@@ -38,6 +38,7 @@ export declare const meetingTools: ({
|
|
|
38
38
|
max_read_bytes?: undefined;
|
|
39
39
|
cursor?: undefined;
|
|
40
40
|
} | {
|
|
41
|
+
limit?: undefined;
|
|
41
42
|
event_id?: undefined;
|
|
42
43
|
series_id?: undefined;
|
|
43
44
|
page?: undefined;
|
|
@@ -53,11 +54,11 @@ export declare const meetingTools: ({
|
|
|
53
54
|
format?: undefined;
|
|
54
55
|
transcript_id?: undefined;
|
|
55
56
|
query?: undefined;
|
|
56
|
-
limit?: undefined;
|
|
57
57
|
scan_limit?: undefined;
|
|
58
58
|
max_read_bytes?: undefined;
|
|
59
59
|
cursor?: undefined;
|
|
60
60
|
} | {
|
|
61
|
+
limit?: undefined;
|
|
61
62
|
event_id?: undefined;
|
|
62
63
|
series_id?: undefined;
|
|
63
64
|
page?: undefined;
|
|
@@ -75,11 +76,11 @@ export declare const meetingTools: ({
|
|
|
75
76
|
format?: undefined;
|
|
76
77
|
transcript_id?: undefined;
|
|
77
78
|
query?: undefined;
|
|
78
|
-
limit?: undefined;
|
|
79
79
|
scan_limit?: undefined;
|
|
80
80
|
max_read_bytes?: undefined;
|
|
81
81
|
cursor?: undefined;
|
|
82
82
|
} | {
|
|
83
|
+
limit?: undefined;
|
|
83
84
|
event_id?: undefined;
|
|
84
85
|
series_id?: undefined;
|
|
85
86
|
page?: undefined;
|
|
@@ -101,7 +102,6 @@ export declare const meetingTools: ({
|
|
|
101
102
|
minimum: number;
|
|
102
103
|
};
|
|
103
104
|
query?: undefined;
|
|
104
|
-
limit?: undefined;
|
|
105
105
|
scan_limit?: undefined;
|
|
106
106
|
max_read_bytes?: undefined;
|
|
107
107
|
cursor?: undefined;
|
|
@@ -188,6 +188,7 @@ export declare const meetingTools: ({
|
|
|
188
188
|
max_read_bytes?: undefined;
|
|
189
189
|
cursor?: undefined;
|
|
190
190
|
} | {
|
|
191
|
+
limit?: undefined;
|
|
191
192
|
event_id?: undefined;
|
|
192
193
|
series_id?: undefined;
|
|
193
194
|
page?: undefined;
|
|
@@ -203,11 +204,11 @@ export declare const meetingTools: ({
|
|
|
203
204
|
format?: undefined;
|
|
204
205
|
transcript_id?: undefined;
|
|
205
206
|
query?: undefined;
|
|
206
|
-
limit?: undefined;
|
|
207
207
|
scan_limit?: undefined;
|
|
208
208
|
max_read_bytes?: undefined;
|
|
209
209
|
cursor?: undefined;
|
|
210
210
|
} | {
|
|
211
|
+
limit?: undefined;
|
|
211
212
|
event_id?: undefined;
|
|
212
213
|
series_id?: undefined;
|
|
213
214
|
page?: undefined;
|
|
@@ -225,11 +226,11 @@ export declare const meetingTools: ({
|
|
|
225
226
|
format?: undefined;
|
|
226
227
|
transcript_id?: undefined;
|
|
227
228
|
query?: undefined;
|
|
228
|
-
limit?: undefined;
|
|
229
229
|
scan_limit?: undefined;
|
|
230
230
|
max_read_bytes?: undefined;
|
|
231
231
|
cursor?: undefined;
|
|
232
232
|
} | {
|
|
233
|
+
limit?: undefined;
|
|
233
234
|
event_id?: undefined;
|
|
234
235
|
series_id?: undefined;
|
|
235
236
|
page?: undefined;
|
|
@@ -251,7 +252,6 @@ export declare const meetingTools: ({
|
|
|
251
252
|
minimum: number;
|
|
252
253
|
};
|
|
253
254
|
query?: undefined;
|
|
254
|
-
limit?: undefined;
|
|
255
255
|
scan_limit?: undefined;
|
|
256
256
|
max_read_bytes?: undefined;
|
|
257
257
|
cursor?: undefined;
|
|
@@ -338,6 +338,7 @@ export declare const meetingTools: ({
|
|
|
338
338
|
max_read_bytes?: undefined;
|
|
339
339
|
cursor?: undefined;
|
|
340
340
|
} | {
|
|
341
|
+
limit?: undefined;
|
|
341
342
|
event_id?: undefined;
|
|
342
343
|
series_id?: undefined;
|
|
343
344
|
page?: undefined;
|
|
@@ -353,11 +354,11 @@ export declare const meetingTools: ({
|
|
|
353
354
|
format?: undefined;
|
|
354
355
|
transcript_id?: undefined;
|
|
355
356
|
query?: undefined;
|
|
356
|
-
limit?: undefined;
|
|
357
357
|
scan_limit?: undefined;
|
|
358
358
|
max_read_bytes?: undefined;
|
|
359
359
|
cursor?: undefined;
|
|
360
360
|
} | {
|
|
361
|
+
limit?: undefined;
|
|
361
362
|
event_id?: undefined;
|
|
362
363
|
series_id?: undefined;
|
|
363
364
|
page?: undefined;
|
|
@@ -375,11 +376,11 @@ export declare const meetingTools: ({
|
|
|
375
376
|
format?: undefined;
|
|
376
377
|
transcript_id?: undefined;
|
|
377
378
|
query?: undefined;
|
|
378
|
-
limit?: undefined;
|
|
379
379
|
scan_limit?: undefined;
|
|
380
380
|
max_read_bytes?: undefined;
|
|
381
381
|
cursor?: undefined;
|
|
382
382
|
} | {
|
|
383
|
+
limit?: undefined;
|
|
383
384
|
event_id?: undefined;
|
|
384
385
|
series_id?: undefined;
|
|
385
386
|
page?: undefined;
|
|
@@ -401,7 +402,6 @@ export declare const meetingTools: ({
|
|
|
401
402
|
minimum: number;
|
|
402
403
|
};
|
|
403
404
|
query?: undefined;
|
|
404
|
-
limit?: undefined;
|
|
405
405
|
scan_limit?: undefined;
|
|
406
406
|
max_read_bytes?: undefined;
|
|
407
407
|
cursor?: undefined;
|
|
@@ -488,6 +488,7 @@ export declare const meetingTools: ({
|
|
|
488
488
|
max_read_bytes?: undefined;
|
|
489
489
|
cursor?: undefined;
|
|
490
490
|
} | {
|
|
491
|
+
limit?: undefined;
|
|
491
492
|
event_id?: undefined;
|
|
492
493
|
series_id?: undefined;
|
|
493
494
|
page?: undefined;
|
|
@@ -503,11 +504,11 @@ export declare const meetingTools: ({
|
|
|
503
504
|
format?: undefined;
|
|
504
505
|
transcript_id?: undefined;
|
|
505
506
|
query?: undefined;
|
|
506
|
-
limit?: undefined;
|
|
507
507
|
scan_limit?: undefined;
|
|
508
508
|
max_read_bytes?: undefined;
|
|
509
509
|
cursor?: undefined;
|
|
510
510
|
} | {
|
|
511
|
+
limit?: undefined;
|
|
511
512
|
event_id?: undefined;
|
|
512
513
|
series_id?: undefined;
|
|
513
514
|
page?: undefined;
|
|
@@ -525,11 +526,11 @@ export declare const meetingTools: ({
|
|
|
525
526
|
format?: undefined;
|
|
526
527
|
transcript_id?: undefined;
|
|
527
528
|
query?: undefined;
|
|
528
|
-
limit?: undefined;
|
|
529
529
|
scan_limit?: undefined;
|
|
530
530
|
max_read_bytes?: undefined;
|
|
531
531
|
cursor?: undefined;
|
|
532
532
|
} | {
|
|
533
|
+
limit?: undefined;
|
|
533
534
|
event_id?: undefined;
|
|
534
535
|
series_id?: undefined;
|
|
535
536
|
page?: undefined;
|
|
@@ -551,7 +552,6 @@ export declare const meetingTools: ({
|
|
|
551
552
|
minimum: number;
|
|
552
553
|
};
|
|
553
554
|
query?: undefined;
|
|
554
|
-
limit?: undefined;
|
|
555
555
|
scan_limit?: undefined;
|
|
556
556
|
max_read_bytes?: undefined;
|
|
557
557
|
cursor?: undefined;
|
|
@@ -638,6 +638,7 @@ export declare const meetingTools: ({
|
|
|
638
638
|
max_read_bytes?: undefined;
|
|
639
639
|
cursor?: undefined;
|
|
640
640
|
} | {
|
|
641
|
+
limit?: undefined;
|
|
641
642
|
event_id?: undefined;
|
|
642
643
|
series_id?: undefined;
|
|
643
644
|
page?: undefined;
|
|
@@ -653,11 +654,11 @@ export declare const meetingTools: ({
|
|
|
653
654
|
format?: undefined;
|
|
654
655
|
transcript_id?: undefined;
|
|
655
656
|
query?: undefined;
|
|
656
|
-
limit?: undefined;
|
|
657
657
|
scan_limit?: undefined;
|
|
658
658
|
max_read_bytes?: undefined;
|
|
659
659
|
cursor?: undefined;
|
|
660
660
|
} | {
|
|
661
|
+
limit?: undefined;
|
|
661
662
|
event_id?: undefined;
|
|
662
663
|
series_id?: undefined;
|
|
663
664
|
page?: undefined;
|
|
@@ -675,11 +676,11 @@ export declare const meetingTools: ({
|
|
|
675
676
|
format?: undefined;
|
|
676
677
|
transcript_id?: undefined;
|
|
677
678
|
query?: undefined;
|
|
678
|
-
limit?: undefined;
|
|
679
679
|
scan_limit?: undefined;
|
|
680
680
|
max_read_bytes?: undefined;
|
|
681
681
|
cursor?: undefined;
|
|
682
682
|
} | {
|
|
683
|
+
limit?: undefined;
|
|
683
684
|
event_id?: undefined;
|
|
684
685
|
series_id?: undefined;
|
|
685
686
|
page?: undefined;
|
|
@@ -701,7 +702,6 @@ export declare const meetingTools: ({
|
|
|
701
702
|
minimum: number;
|
|
702
703
|
};
|
|
703
704
|
query?: undefined;
|
|
704
|
-
limit?: undefined;
|
|
705
705
|
scan_limit?: undefined;
|
|
706
706
|
max_read_bytes?: undefined;
|
|
707
707
|
cursor?: undefined;
|
package/dist/models/ai.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { type CredentialSource, type KeyringStore } from "@wirecat/cli-base";
|
|
|
2
2
|
import * as v from "valibot";
|
|
3
3
|
import type { OcrPipeline } from "../attachments/ocr.js";
|
|
4
4
|
import type { AppIdentity } from "../ports/app.js";
|
|
5
|
+
import { modelAddressAllowed } from "./endpoint.js";
|
|
5
6
|
import type { ModelTarget } from "./types.js";
|
|
6
7
|
export declare const AI_PROVIDERS: readonly ["anthropic", "openai", "ollama"];
|
|
7
8
|
export type AiProvider = (typeof AI_PROVIDERS)[number];
|
|
8
|
-
|
|
9
|
-
export declare const aiAddressAllowed: (value: string) => boolean;
|
|
9
|
+
export declare const aiAddressAllowed: typeof modelAddressAllowed;
|
|
10
10
|
declare const settingShape: v.StrictObjectSchema<{
|
|
11
11
|
readonly provider: v.PicklistSchema<readonly ["anthropic", "openai", "ollama"], undefined>;
|
|
12
12
|
readonly model: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 200, undefined>]>;
|
|
@@ -45,7 +45,9 @@ export declare const aiKeys: (app: AppIdentity, env: NodeJS.ProcessEnv, keyring?
|
|
|
45
45
|
write: (origin: string, key: string) => CredentialSource;
|
|
46
46
|
remove: (origin: string) => CredentialSource[];
|
|
47
47
|
};
|
|
48
|
+
/** A model on this computer runs without a key; LM Studio or vLLM may still be given one. */
|
|
48
49
|
export declare const aiNeedsKey: (setting: AiSetting) => boolean;
|
|
50
|
+
export declare const aiTakesKey: (setting: AiSetting) => boolean;
|
|
49
51
|
export interface AiCallDeps {
|
|
50
52
|
app: AppIdentity;
|
|
51
53
|
env: NodeJS.ProcessEnv;
|
|
@@ -65,7 +67,18 @@ export declare const aiImageReader: (deps: AiCallDeps) => {
|
|
|
65
67
|
refused: AiImageRefusal;
|
|
66
68
|
};
|
|
67
69
|
/** False only for a model on this computer: Ollama, or any address on loopback. */
|
|
68
|
-
export declare const aiLeavesComputer: (setting: AiSetting) => boolean;
|
|
70
|
+
export declare const aiLeavesComputer: (setting: Pick<AiSetting, "provider" | "base_url">) => boolean;
|
|
71
|
+
/**
|
|
72
|
+
* The shared AI model as the target and key of a feature that has no model of its own configured (chat linking,
|
|
73
|
+
* replies, attachment OCR). The key is the one kept for its address, never another tool's.
|
|
74
|
+
*/
|
|
75
|
+
export declare const sharedModel: (deps: Pick<AiCallDeps, "app" | "env" | "keyring">) => {
|
|
76
|
+
target: ModelTarget & {
|
|
77
|
+
baseUrl: string;
|
|
78
|
+
};
|
|
79
|
+
key: string | undefined;
|
|
80
|
+
setting: AiSetting;
|
|
81
|
+
} | undefined;
|
|
69
82
|
export type AiTextRefusal = "ai.not-set" | "ai.key-missing";
|
|
70
83
|
export interface AiTextReader {
|
|
71
84
|
by: string;
|
package/dist/models/ai.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as v from "valibot";
|
|
|
3
3
|
import { embeddingKeys, endpointKeyName } from "../embeddings/keys.js";
|
|
4
4
|
import { storePath } from "../store/path.js";
|
|
5
5
|
import { readSharedSection, sharedConfigPath, writeSharedSection } from "../store/shared-config.js";
|
|
6
|
-
import {
|
|
6
|
+
import { modelAddressAllowed, onThisComputer } from "./endpoint.js";
|
|
7
7
|
import { modelGateway } from "./index.js";
|
|
8
8
|
export const AI_PROVIDERS = ["anthropic", "openai", "ollama"];
|
|
9
9
|
const DEFAULT_BASE_URL = {
|
|
@@ -16,14 +16,7 @@ const OFFICIAL = {
|
|
|
16
16
|
"https://api.anthropic.com": "anthropic",
|
|
17
17
|
};
|
|
18
18
|
const SECTION = "ai";
|
|
19
|
-
const
|
|
20
|
-
/** https anywhere; plain http only to this computer, so neither the text nor the key crosses a network unencrypted. */
|
|
21
|
-
export const aiAddressAllowed = (value) => {
|
|
22
|
-
if (!endpoint(value))
|
|
23
|
-
return false;
|
|
24
|
-
const url = new URL(value);
|
|
25
|
-
return url.protocol === "https:" || loopback(url.hostname);
|
|
26
|
-
};
|
|
19
|
+
export const aiAddressAllowed = modelAddressAllowed;
|
|
27
20
|
const consentShape = v.strictObject({
|
|
28
21
|
origin: v.string(),
|
|
29
22
|
model: v.string(),
|
|
@@ -63,7 +56,7 @@ export const aiSettingOf = (given) => {
|
|
|
63
56
|
? "this address is not allowed: use https, or http only on this computer"
|
|
64
57
|
: "name the model, 1 to 200 characters", { reason: field === "base_url" ? "ai.address-refused" : "ai.setting-invalid" });
|
|
65
58
|
}
|
|
66
|
-
if (checked.output.provider === "ollama" && !
|
|
59
|
+
if (checked.output.provider === "ollama" && !onThisComputer(aiBaseUrl(checked.output)))
|
|
67
60
|
throw new CliError("validation_error", "Ollama is read only on this computer", { reason: "ai.address-refused" });
|
|
68
61
|
return given.allowImages
|
|
69
62
|
? {
|
|
@@ -113,12 +106,15 @@ export const aiKeys = (app, env, keyring) => {
|
|
|
113
106
|
remove: (origin) => credentials.remove(account(origin)),
|
|
114
107
|
};
|
|
115
108
|
};
|
|
116
|
-
|
|
117
|
-
const
|
|
109
|
+
/** A model on this computer runs without a key; LM Studio or vLLM may still be given one. */
|
|
110
|
+
export const aiNeedsKey = (setting) => aiLeavesComputer(setting);
|
|
111
|
+
export const aiTakesKey = (setting) => setting.provider !== "ollama";
|
|
112
|
+
const keyFor = (setting, deps) => aiTakesKey(setting) ? aiKeys(deps.app, deps.env, deps.keyring).read(aiOrigin(setting))?.key : undefined;
|
|
118
113
|
const gatewayFor = (setting, deps, key) => modelGateway({
|
|
119
114
|
resolve: () => aiTarget(setting),
|
|
120
115
|
consent: () => true,
|
|
121
116
|
key: () => key,
|
|
117
|
+
env: deps.env,
|
|
122
118
|
...(deps.fetch ? { fetch: deps.fetch } : {}),
|
|
123
119
|
...(deps.signal ? { signal: deps.signal } : {}),
|
|
124
120
|
});
|
|
@@ -151,7 +147,17 @@ export const aiImageReader = (deps) => {
|
|
|
151
147
|
};
|
|
152
148
|
};
|
|
153
149
|
/** False only for a model on this computer: Ollama, or any address on loopback. */
|
|
154
|
-
export const aiLeavesComputer = (setting) => !
|
|
150
|
+
export const aiLeavesComputer = (setting) => !onThisComputer(aiBaseUrl(setting));
|
|
151
|
+
/**
|
|
152
|
+
* The shared AI model as the target and key of a feature that has no model of its own configured (chat linking,
|
|
153
|
+
* replies, attachment OCR). The key is the one kept for its address, never another tool's.
|
|
154
|
+
*/
|
|
155
|
+
export const sharedModel = (deps) => {
|
|
156
|
+
const setting = readAiSetting(aiSettingPath(deps.env));
|
|
157
|
+
if (!setting)
|
|
158
|
+
return undefined;
|
|
159
|
+
return { target: { ...aiTarget(setting), baseUrl: aiBaseUrl(setting) }, key: keyFor(setting, deps), setting };
|
|
160
|
+
};
|
|
155
161
|
/** The chosen model for text a tool sends on purpose; picking this reader by name is the owner's consent, as for images. */
|
|
156
162
|
export const aiTextReader = (deps) => {
|
|
157
163
|
const setting = readAiSetting(aiSettingPath(deps.env));
|
|
@@ -1 +1,6 @@
|
|
|
1
1
|
export declare const endpoint: (value: string) => boolean;
|
|
2
|
+
/** An address on this computer: localhost, 127.x.x.x or [::1]. */
|
|
3
|
+
export declare const onThisComputer: (value: string) => boolean;
|
|
4
|
+
/** https anywhere; plain http only to this computer, so neither the text nor the key crosses a network unencrypted. */
|
|
5
|
+
export declare const modelAddressAllowed: (value: string) => boolean;
|
|
6
|
+
export declare const PLAIN_HTTP_REFUSED = "this address is not allowed: use https, or http only on this computer";
|
package/dist/models/endpoint.js
CHANGED
|
@@ -7,3 +7,16 @@ export const endpoint = (value) => {
|
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
9
9
|
};
|
|
10
|
+
const loopback = (hostname) => hostname === "localhost" || hostname === "[::1]" || /^127(\.\d{1,3}){3}$/.test(hostname);
|
|
11
|
+
/** An address on this computer: localhost, 127.x.x.x or [::1]. */
|
|
12
|
+
export const onThisComputer = (value) => {
|
|
13
|
+
try {
|
|
14
|
+
return loopback(new URL(value).hostname);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/** https anywhere; plain http only to this computer, so neither the text nor the key crosses a network unencrypted. */
|
|
21
|
+
export const modelAddressAllowed = (value) => endpoint(value) && (new URL(value).protocol === "https:" || onThisComputer(value));
|
|
22
|
+
export const PLAIN_HTTP_REFUSED = "this address is not allowed: use https, or http only on this computer";
|
package/dist/models/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type ModelAdapter, type ModelAnswer, type ModelRequest, type ModelTarget } from "./types.js";
|
|
2
|
+
export { modelAddressAllowed, onThisComputer } from "./endpoint.js";
|
|
3
|
+
export { localOnly, readLocalOnly, refuseModelAddress, refuseOffComputer } from "./local-only.js";
|
|
2
4
|
export type { ModelSettings } from "./settings.js";
|
|
3
5
|
export { modelTarget } from "./settings.js";
|
|
4
6
|
export type { ModelAdapter, ModelAnswer, ModelImage, ModelRequest, ModelTarget, ModelUsage } from "./types.js";
|
|
@@ -9,6 +11,8 @@ export interface GatewayDeps {
|
|
|
9
11
|
adapters?: Readonly<Record<string, ModelAdapter>>;
|
|
10
12
|
fetch?: typeof fetch;
|
|
11
13
|
signal?: AbortSignal;
|
|
14
|
+
/** Where the local-only switch is read; the process's own when absent, so a caller cannot skip it by omission. */
|
|
15
|
+
env?: NodeJS.ProcessEnv;
|
|
12
16
|
}
|
|
13
17
|
export declare const modelGateway: (deps: GatewayDeps) => {
|
|
14
18
|
complete: (request: ModelRequest) => Promise<ModelAnswer>;
|
package/dist/models/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import { endpoint } from "./endpoint.js";
|
|
2
|
+
import { endpoint, modelAddressAllowed, PLAIN_HTTP_REFUSED } from "./endpoint.js";
|
|
3
|
+
import { refuseOffComputer } from "./local-only.js";
|
|
3
4
|
import { openai } from "./openai.js";
|
|
4
5
|
import { validateImages } from "./types.js";
|
|
6
|
+
export { modelAddressAllowed, onThisComputer } from "./endpoint.js";
|
|
7
|
+
export { localOnly, readLocalOnly, refuseModelAddress, refuseOffComputer } from "./local-only.js";
|
|
5
8
|
export { modelTarget } from "./settings.js";
|
|
6
9
|
export const modelGateway = (deps) => ({
|
|
7
10
|
complete: async (request) => {
|
|
@@ -29,6 +32,11 @@ export const modelGateway = (deps) => ({
|
|
|
29
32
|
const baseUrl = target.baseUrl ?? adapter.baseUrl;
|
|
30
33
|
if (!target.model.trim() || !endpoint(baseUrl))
|
|
31
34
|
throw new CliError("validation_error", "a model target needs a model and an HTTP/S endpoint without credentials, query or fragment");
|
|
35
|
+
if (!modelAddressAllowed(baseUrl))
|
|
36
|
+
throw new CliError("validation_error", `${PLAIN_HTTP_REFUSED}; no data was sent`, {
|
|
37
|
+
reason: "model.address-refused",
|
|
38
|
+
});
|
|
39
|
+
refuseOffComputer(deps.env ?? process.env, baseUrl, `${request.purpose} data`);
|
|
32
40
|
if (!(await deps.consent(request, { ...target, baseUrl })))
|
|
33
41
|
throw new CliError("permission_error", `model consent for ${request.purpose} is missing; no data was sent`);
|
|
34
42
|
const apiKey = await deps.key?.(target.provider, target);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
declare const Setting: v.StrictObjectSchema<{
|
|
4
|
+
readonly on: v.BooleanSchema<undefined>;
|
|
5
|
+
readonly at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, undefined>]>;
|
|
6
|
+
}, undefined>;
|
|
7
|
+
export type LocalOnlySetting = v.InferOutput<typeof Setting>;
|
|
8
|
+
/** The owner's switch, off when absent. A broken section reads as on: a typo must not let records out. */
|
|
9
|
+
export declare const readLocalOnly: (env: NodeJS.ProcessEnv) => LocalOnlySetting | undefined;
|
|
10
|
+
export declare const localOnly: (env: NodeJS.ProcessEnv) => boolean;
|
|
11
|
+
export declare const writeLocalOnly: (env: NodeJS.ProcessEnv, on: boolean) => void;
|
|
12
|
+
export declare const localOnlyRefusal: (what: string, where: string) => CliError;
|
|
13
|
+
/** Throws when local only is on and the address is not on this computer. */
|
|
14
|
+
export declare const refuseOffComputer: (env: NodeJS.ProcessEnv, address: string, what: string) => void;
|
|
15
|
+
/** What a setting command checks before it saves an address: https or this computer, and local only. */
|
|
16
|
+
export declare const refuseModelAddress: (env: NodeJS.ProcessEnv, address: string, what: string) => void;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
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";
|
|
5
|
+
import { modelAddressAllowed, onThisComputer, PLAIN_HTTP_REFUSED } from "./endpoint.js";
|
|
6
|
+
const SECTION = "local_only";
|
|
7
|
+
const Setting = v.strictObject({
|
|
8
|
+
on: v.boolean(),
|
|
9
|
+
at: v.pipe(v.string(), v.isoTimestamp()),
|
|
10
|
+
});
|
|
11
|
+
const pathOf = (env) => sharedConfigPath(storePath(env), env);
|
|
12
|
+
/** The owner's switch, off when absent. A broken section reads as on: a typo must not let records out. */
|
|
13
|
+
export const readLocalOnly = (env) => {
|
|
14
|
+
const section = readSharedSection(pathOf(env), SECTION);
|
|
15
|
+
if (section === undefined || section === null)
|
|
16
|
+
return undefined;
|
|
17
|
+
const checked = v.safeParse(Setting, section);
|
|
18
|
+
return checked.success ? checked.output : { on: true, at: new Date(0).toISOString() };
|
|
19
|
+
};
|
|
20
|
+
export const localOnly = (env) => readLocalOnly(env)?.on === true;
|
|
21
|
+
export const writeLocalOnly = (env, on) => writeSharedSection(pathOf(env), SECTION, on ? { on: true, at: new Date().toISOString() } : undefined);
|
|
22
|
+
export const localOnlyRefusal = (what, where) => new CliError("permission_error", `local only is on: ${what} would go to ${where}, which is not this computer; nothing was sent. ` +
|
|
23
|
+
"Choose a model on this computer, or turn local only off with `models local-only set off`", { reason: "local-only.refused" });
|
|
24
|
+
/** Throws when local only is on and the address is not on this computer. */
|
|
25
|
+
export const refuseOffComputer = (env, address, what) => {
|
|
26
|
+
if (!onThisComputer(address) && localOnly(env))
|
|
27
|
+
throw localOnlyRefusal(what, hostOf(address));
|
|
28
|
+
};
|
|
29
|
+
const hostOf = (address) => {
|
|
30
|
+
try {
|
|
31
|
+
return new URL(address).host;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return address;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/** What a setting command checks before it saves an address: https or this computer, and local only. */
|
|
38
|
+
export const refuseModelAddress = (env, address, what) => {
|
|
39
|
+
if (!modelAddressAllowed(address))
|
|
40
|
+
throw new CliError("validation_error", PLAIN_HTTP_REFUSED, { reason: "model.address-refused" });
|
|
41
|
+
refuseOffComputer(env, address, what);
|
|
42
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { KeyringStore } from "@wirecat/cli-base";
|
|
2
|
+
import type { AppIdentity } from "../ports/app.js";
|
|
3
|
+
import { type AiSetting } from "./ai.js";
|
|
4
|
+
import { type ModelSettings } from "./settings.js";
|
|
5
|
+
import type { ModelTarget } from "./types.js";
|
|
6
|
+
export interface PurposeModel {
|
|
7
|
+
target: ModelTarget & {
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
};
|
|
10
|
+
key: () => string | undefined;
|
|
11
|
+
/** The AI model chosen for every tool (`models ai`), not this purpose's own `models.<purpose>`. */
|
|
12
|
+
shared?: AiSetting;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The model a purpose calls: the flag or environment or config `models.<purpose>` (or `models.default`) first, then
|
|
16
|
+
* the shared AI model. `off` stays off; the shared model never replaces an explicit no.
|
|
17
|
+
*/
|
|
18
|
+
export declare const purposeModel: (settings: {
|
|
19
|
+
models?: ModelSettings;
|
|
20
|
+
}, purpose: string, deps: {
|
|
21
|
+
app: AppIdentity;
|
|
22
|
+
env: NodeJS.ProcessEnv;
|
|
23
|
+
keyring?: KeyringStore | undefined;
|
|
24
|
+
}) => PurposeModel | undefined;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { embeddingKeys, endpointKeyName } from "../embeddings/keys.js";
|
|
2
|
+
import { sharedModel } from "./ai.js";
|
|
3
|
+
import { modelTarget } from "./settings.js";
|
|
4
|
+
const HOSTED = {
|
|
5
|
+
openai: "https://api.openai.com/v1",
|
|
6
|
+
anthropic: "https://api.anthropic.com",
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The model a purpose calls: the flag or environment or config `models.<purpose>` (or `models.default`) first, then
|
|
10
|
+
* the shared AI model. `off` stays off; the shared model never replaces an explicit no.
|
|
11
|
+
*/
|
|
12
|
+
export const purposeModel = (settings, purpose, deps) => {
|
|
13
|
+
const configured = modelTarget(settings, purpose);
|
|
14
|
+
if (configured) {
|
|
15
|
+
const baseUrl = configured.baseUrl ?? HOSTED[configured.provider] ?? "";
|
|
16
|
+
return {
|
|
17
|
+
target: { ...configured, baseUrl },
|
|
18
|
+
key: () => embeddingKeys(deps.app, deps.env, deps.keyring).read(configured.baseUrl === undefined ? configured.provider : endpointKeyName(configured.baseUrl))?.key,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const provider = settings.models?.[purpose]?.provider ?? settings.models?.default?.provider;
|
|
22
|
+
if (provider === "off")
|
|
23
|
+
return undefined;
|
|
24
|
+
const shared = sharedModel(deps);
|
|
25
|
+
return shared ? { target: shared.target, key: () => shared.key, shared: shared.setting } : undefined;
|
|
26
|
+
};
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { modelGateway } from "../models/index.js";
|
|
3
|
+
import { purposeModel } from "../models/purpose.js";
|
|
4
4
|
import { mayModelReply, replyConsentPathFor, replyModelIdentity } from "./consents.js";
|
|
5
5
|
import { renderReplyTemplate, templateWarning } from "./template.js";
|
|
6
6
|
export const replyRenderer = (app, profile, settings, env, warn, options = {
|
|
7
7
|
ai: true,
|
|
8
8
|
}) => async (rule, message, chat, now) => {
|
|
9
|
+
const deps = { app, env, keyring: options.keyring };
|
|
9
10
|
let called;
|
|
10
11
|
const gateway = modelGateway({
|
|
11
12
|
signal: options.signal,
|
|
13
|
+
env,
|
|
12
14
|
resolve: (purpose) => {
|
|
13
|
-
called =
|
|
14
|
-
return called;
|
|
15
|
+
called = purposeModel(settings(), purpose, deps);
|
|
16
|
+
return called?.target;
|
|
15
17
|
},
|
|
16
18
|
consent: (_request, target) => mayModelReply(replyConsentPathFor(app, profile, env), replyModelIdentity(target.provider, target.baseUrl ?? ""), message.chatId),
|
|
17
|
-
key: (
|
|
19
|
+
key: () => called?.key(),
|
|
18
20
|
});
|
|
19
21
|
if (options.signal?.aborted)
|
|
20
22
|
throw new CliError("cancelled", "reply rendering cancelled");
|
|
@@ -36,12 +38,10 @@ export const replyRenderer = (app, profile, settings, env, warn, options = {
|
|
|
36
38
|
});
|
|
37
39
|
if (options.signal?.aborted)
|
|
38
40
|
throw new CliError("cancelled", "reply rendering cancelled");
|
|
39
|
-
const current =
|
|
40
|
-
const baseUrl = called?.baseUrl ??
|
|
41
|
-
(called?.provider === "anthropic" ? "https://api.anthropic.com" : "https://api.openai.com/v1");
|
|
41
|
+
const current = purposeModel(settings(), "replies", deps)?.target;
|
|
42
42
|
if (!called ||
|
|
43
|
-
JSON.stringify(current) !== JSON.stringify(called) ||
|
|
44
|
-
!mayModelReply(replyConsentPathFor(app, profile, env), replyModelIdentity(called.provider, baseUrl), message.chatId)) {
|
|
43
|
+
JSON.stringify(current) !== JSON.stringify(called.target) ||
|
|
44
|
+
!mayModelReply(replyConsentPathFor(app, profile, env), replyModelIdentity(called.target.provider, called.target.baseUrl), message.chatId)) {
|
|
45
45
|
throw new CliError("permission_error", "reply model consent or configuration changed during rendering");
|
|
46
46
|
}
|
|
47
47
|
return result;
|
package/dist/runs/events.d.ts
CHANGED
|
@@ -73,7 +73,15 @@ export interface StoreEvent {
|
|
|
73
73
|
op: "insert" | "update" | "delete";
|
|
74
74
|
n: number;
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
/** What a long command showed as its progress, so a run's log says what its window drew: counts, never a name. */
|
|
77
|
+
export interface ProgressEvent {
|
|
78
|
+
event: "progress";
|
|
79
|
+
/** `sync.progress`: the step that drew it. */
|
|
80
|
+
operation: string;
|
|
81
|
+
kind: "progress";
|
|
82
|
+
counts: Record<string, number>;
|
|
83
|
+
}
|
|
84
|
+
export type DiagnosticEvent = RequestEvent | CacheEvent | WarningEvent | StoreEvent | ProgressEvent;
|
|
77
85
|
export type EventSink = (event: DiagnosticEvent) => void;
|
|
78
86
|
/** A sentence for a person, and the warning event it stands for when there is one: a log record keeps only the event. */
|
|
79
87
|
export type Warn = (message: string, warning?: WarningEvent) => void;
|
package/dist/runs/events.js
CHANGED
|
@@ -11,6 +11,10 @@ export const providerErrorKey = (value) => typeof value === "string" && /^[A-Za-
|
|
|
11
11
|
export const renderEvent = (event) => {
|
|
12
12
|
if (event.event === "store")
|
|
13
13
|
return `${MARK.store} ${event.operation.padEnd(16)} ${event.table} ${event.op} ${event.n}`;
|
|
14
|
+
if (event.event === "progress")
|
|
15
|
+
return `${MARK.progress} ${event.operation.padEnd(16)} ${Object.entries(event.counts)
|
|
16
|
+
.map(([field, count]) => `${count} ${field}`)
|
|
17
|
+
.join(" ")}`;
|
|
14
18
|
if (event.event === "warning") {
|
|
15
19
|
const counts = Object.entries(event.counts ?? {}).map(([field, count]) => `${count} ${field}`);
|
|
16
20
|
return [`${MARK.warning} ${(event.operation ?? "").padEnd(16)} ${event.code}`, ...counts, event.detail]
|
|
@@ -55,6 +59,6 @@ export const renderEvent = (event) => {
|
|
|
55
59
|
}
|
|
56
60
|
return `${MARK[event.event]} ${event.operation.padEnd(16)} ${parts.join(" ")}`.trimEnd();
|
|
57
61
|
};
|
|
58
|
-
const MARK = { request: "→", response: "←", cache: "•", warning: "!", store: "+" };
|
|
62
|
+
const MARK = { request: "→", response: "←", cache: "•", warning: "!", store: "+", progress: "…" };
|
|
59
63
|
const age = (ms) => (ms < 1000 ? `${ms}ms` : `${Math.round(ms / 1000)}s`);
|
|
60
64
|
const size = (bytes) => (bytes < 1000 ? `${bytes} B` : `${(bytes / 1000).toFixed(1)} kB`);
|
package/dist/runs/log-events.js
CHANGED
|
@@ -10,6 +10,7 @@ export const CORE_LOG_EVENTS = defineLogEvents([
|
|
|
10
10
|
keys: ["operation", "reason"],
|
|
11
11
|
},
|
|
12
12
|
{ id: "store.write", meaning: "a committed write changed rows of one store table", keys: ["table", "op", "n"] },
|
|
13
|
+
{ id: "sync.progress", meaning: "what a sync's progress line showed: chats and messages so far", keys: ["counts"] },
|
|
13
14
|
{ id: "command.crashed", meaning: "a command failed on a bug; where, never what", keys: ["error_class", "frames"] },
|
|
14
15
|
{
|
|
15
16
|
id: "events.dropped",
|
|
@@ -34,4 +35,5 @@ export const DIAGNOSTIC_LOG_EVENTS = {
|
|
|
34
35
|
warning: "client.warning",
|
|
35
36
|
cache: "cache.answered",
|
|
36
37
|
store: "store.write",
|
|
38
|
+
progress: "sync.progress",
|
|
37
39
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { isUsable } from "../domain/relations.js";
|
|
3
|
+
import { isClosedState } from "../tasks/index.js";
|
|
3
4
|
import { coverageFor, edgesOf, grouped, namesOf, notRejected, organizationCategories, SECTION_LIMIT, STORE_PAGE, scopeOf, sectionOf, } from "./business-context.js";
|
|
4
5
|
import { communicationsOf } from "./communications.js";
|
|
5
6
|
import { moneyOf } from "./money-context.js";
|
|
@@ -74,6 +75,22 @@ export const dealContext = async (store, reference, { accounts, limit = SECTION_
|
|
|
74
75
|
const said = talks.counts.messages + talks.counts.mail + talks.counts.meetings;
|
|
75
76
|
const stages = await store.deals.stages(deal.ref);
|
|
76
77
|
const tasks = await openTasksOf(store, project ? [{ ref: project.ref, key: project.key }] : []);
|
|
78
|
+
const opened = await store.tasks.find({
|
|
79
|
+
where: { sql: "t.source_group = ?", params: [deal.ref] },
|
|
80
|
+
limit: STORE_PAGE,
|
|
81
|
+
});
|
|
82
|
+
for (const task of opened)
|
|
83
|
+
if (!isClosedState(task.status) && !tasks.tasks.some((one) => one.ref === task.ref))
|
|
84
|
+
tasks.tasks.push({
|
|
85
|
+
ref: task.ref,
|
|
86
|
+
key: task.key,
|
|
87
|
+
title: task.title,
|
|
88
|
+
status: task.status,
|
|
89
|
+
project: task.project,
|
|
90
|
+
dueAt: task.dueAt,
|
|
91
|
+
});
|
|
92
|
+
tasks.full ||= opened.length >= STORE_PAGE;
|
|
93
|
+
tasks.tasks.sort((a, b) => (a.dueAt ?? "~").localeCompare(b.dueAt ?? "~") || a.ref.localeCompare(b.ref));
|
|
77
94
|
return {
|
|
78
95
|
deal,
|
|
79
96
|
stages: sectionOf(stages, limit, null, { newest: true }),
|
|
@@ -33,7 +33,10 @@ export const embeddingTarget = (deps, choice = chosenTextModel(deps.env).id) =>
|
|
|
33
33
|
price: remote.price,
|
|
34
34
|
installed: true,
|
|
35
35
|
perBatch: PER_REQUEST * concurrency,
|
|
36
|
-
open: async () => (await import("../embeddings/remote.js")).openRemote(remote, apiKey, {
|
|
36
|
+
open: async () => (await import("../embeddings/remote.js")).openRemote(remote, apiKey, {
|
|
37
|
+
concurrency,
|
|
38
|
+
env: deps.env ?? process.env,
|
|
39
|
+
}),
|
|
37
40
|
};
|
|
38
41
|
}
|
|
39
42
|
const model = textModel(choice, deps.env);
|
|
@@ -22,7 +22,7 @@ export interface EnrichOptions {
|
|
|
22
22
|
signal?: AbortSignal;
|
|
23
23
|
}
|
|
24
24
|
/** Why a run stopped or failed, from a fixed list, so a window can say it in its own words. */
|
|
25
|
-
export declare const ENRICHMENT_REASON_IDS: readonly ["enrichment.no-key", "enrichment.key-rejected", "enrichment.unreachable", "enrichment.rate-limited", "enrichment.bad-replies", "enrichment.cancelled", "enrichment.error"];
|
|
25
|
+
export declare const ENRICHMENT_REASON_IDS: readonly ["enrichment.no-key", "enrichment.key-rejected", "enrichment.unreachable", "enrichment.rate-limited", "enrichment.bad-replies", "enrichment.cancelled", "enrichment.local-only", "enrichment.address-refused", "enrichment.error"];
|
|
26
26
|
export type EnrichmentReasonId = (typeof ENRICHMENT_REASON_IDS)[number];
|
|
27
27
|
export type EnrichRun = {
|
|
28
28
|
status: "off";
|