@wirecat/cli-core 0.641.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 +30 -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/conversations-command.js +1 -1
- package/dist/cli/messenger/replies-consents-command.js +12 -6
- package/dist/cli/model-catalogue-command.js +2 -0
- package/dist/cli/search-harder-consents-command.js +16 -1
- package/dist/documents.d.ts +1 -1
- package/dist/documents.js +1 -1
- package/dist/embeddings/remote.d.ts +2 -1
- package/dist/embeddings/remote.js +5 -3
- 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/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/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/package.json +1 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { annotate } from "@wirecat/cli-base/commands";
|
|
3
3
|
import { Command } from "commander";
|
|
4
|
+
import { parseDuration } from "../domain/duration.js";
|
|
5
|
+
import { refuseModelAddress } from "../models/local-only.js";
|
|
4
6
|
import { agentOf } from "../runs/run-context.js";
|
|
5
7
|
import { keyLookup, keyVariable } from "../services/enrichment.js";
|
|
6
8
|
import { ENRICHMENT_PROVIDERS, enrichmentEndpoint, enrichmentPrice, isEnrichmentProvider, readEnrichmentSetting, } from "../services/enrichment-setting.js";
|
|
7
|
-
import { HARDER_CANDIDATES, HARDER_CHARS, HARDER_MODELS, readHarderSetting, writeHarderSetting, } from "../services/search-harder.js";
|
|
9
|
+
import { HARDER_CANDIDATES, HARDER_CHARS, HARDER_MODELS, HARDER_TIMEOUT_S, harderTimeoutSeconds, readHarderSetting, readHarderTimeout, writeHarderSetting, writeHarderTimeout, } from "../services/search-harder.js";
|
|
8
10
|
import { grantsAuthority, LOCAL_READ, LOCAL_WRITE } from "./effects.js";
|
|
9
11
|
import { itemOf } from "./envelope.js";
|
|
10
12
|
// One search: 30 hits of up to 400 characters plus the prompt, and a short list of hit numbers back.
|
|
@@ -45,6 +47,8 @@ const state = (app, options, given) => {
|
|
|
45
47
|
endpoint: enrichmentEndpoint(chosen),
|
|
46
48
|
...(enrichment ? { proposed_from: "enrichment" } : {}),
|
|
47
49
|
consented_at: setting?.consented_at ?? null,
|
|
50
|
+
timeout_s: harderTimeoutSeconds(env, enrichmentEndpoint(chosen)),
|
|
51
|
+
timeout_set: readHarderTimeout(env) !== undefined,
|
|
48
52
|
candidates: HARDER_CANDIDATES,
|
|
49
53
|
chars_per_hit: HARDER_CHARS,
|
|
50
54
|
usd_per_million: price
|
|
@@ -55,6 +59,12 @@ const state = (app, options, given) => {
|
|
|
55
59
|
off_command: `${app.command} models search-consents revoke`,
|
|
56
60
|
};
|
|
57
61
|
};
|
|
62
|
+
const seconds = (value) => {
|
|
63
|
+
const ms = parseDuration(value, "--timeout");
|
|
64
|
+
if (ms < 1000 || ms > 600_000)
|
|
65
|
+
throw new CliError("validation_error", "--timeout takes 1s to 10m");
|
|
66
|
+
return Math.round(ms / 1000);
|
|
67
|
+
};
|
|
58
68
|
/**
|
|
59
69
|
* The owner's consent that `search all --harder` may send a question and its hits to a hosted model. Off until
|
|
60
70
|
* `set … --yes`; with it, still only a search that asks with --harder sends anything.
|
|
@@ -77,6 +87,8 @@ export const harderConsentsCommand = (app, options) => {
|
|
|
77
87
|
.argument("<provider>", `the provider that receives the question and hits: ${ENRICHMENT_PROVIDERS.join(" or ")}`)
|
|
78
88
|
.option("--model <model>", `the provider's model; ${HARDER_MODELS.anthropic} or ${HARDER_MODELS.openai} if left out`)
|
|
79
89
|
.option("--base-url <url>", "the address of an OpenAI-compatible model API (OpenRouter…); needs --model")
|
|
90
|
+
.option("--timeout <duration>", `how long a --harder search waits for the model, 1s to 10m (30s, 2m); ${HARDER_TIMEOUT_S.hosted} s for a hosted model, ` +
|
|
91
|
+
`${HARDER_TIMEOUT_S.local} s for one on this computer until one is set; kept until set again`, seconds)
|
|
80
92
|
.option("--yes", "agree that a --harder search sends its question and hits, and allow it")
|
|
81
93
|
.action(function (provider, given) {
|
|
82
94
|
if (!isEnrichmentProvider(provider))
|
|
@@ -95,6 +107,7 @@ export const harderConsentsCommand = (app, options) => {
|
|
|
95
107
|
model: given.model ?? HARDER_MODELS[provider],
|
|
96
108
|
...(given.baseUrl === undefined ? {} : { base_url: given.baseUrl }),
|
|
97
109
|
};
|
|
110
|
+
refuseModelAddress(env, enrichmentEndpoint(chosen), "a --harder search's question and hits");
|
|
98
111
|
if (!given.yes) {
|
|
99
112
|
const now = state(app, options, chosen);
|
|
100
113
|
options.diagnostic(`${now.consent}\nNothing changed — add --yes to allow it.`);
|
|
@@ -102,6 +115,8 @@ export const harderConsentsCommand = (app, options) => {
|
|
|
102
115
|
return;
|
|
103
116
|
}
|
|
104
117
|
writeHarderSetting(env, { ...chosen, consented_at: new Date().toISOString() });
|
|
118
|
+
if (given.timeout !== undefined)
|
|
119
|
+
writeHarderTimeout(env, given.timeout);
|
|
105
120
|
options.diagnostic(`search all --harder may now call ${provider} ${chosen.model}`);
|
|
106
121
|
options.output(itemOf({ ...state(app, options), changed: true }), this);
|
|
107
122
|
});
|
package/dist/documents.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ export { columnName, sheetText } from "./attachments/sheets.js";
|
|
|
8
8
|
export * from "./documents/index.js";
|
|
9
9
|
export { isPublicAddress } from "./fetch/addresses.js";
|
|
10
10
|
export { type FetchedPage, type FetchPageOptions, fetchPage, nodeTransport, PAGE_LIMITS, PAGE_USER_AGENT, type PageLimits, type PageLookup, type PageRequest, type PageResponse, type PageTransport, type ResolvedAddress, } from "./fetch/page.js";
|
|
11
|
-
export { AI_PROVIDERS, type AiImageRefusal, type AiProvider, type AiSetting, type AiTextReader, type AiTextRefusal, aiImageReader, aiLeavesComputer, aiSettingPath, aiTextReader, readAiSetting, } from "./models/ai.js";
|
|
11
|
+
export { AI_PROVIDERS, type AiImageRefusal, type AiProvider, type AiSetting, type AiTextReader, type AiTextRefusal, aiImageReader, aiLeavesComputer, aiSettingPath, aiTextReader, readAiSetting, sharedModel, } from "./models/ai.js";
|
|
12
12
|
export { registerReader } from "./readers/registry.js";
|
|
13
13
|
export type { ReadContext, Reader, Section } from "./readers/types.js";
|
package/dist/documents.js
CHANGED
|
@@ -6,5 +6,5 @@ export { columnName, sheetText } from "./attachments/sheets.js";
|
|
|
6
6
|
export * from "./documents/index.js";
|
|
7
7
|
export { isPublicAddress } from "./fetch/addresses.js";
|
|
8
8
|
export { fetchPage, nodeTransport, PAGE_LIMITS, PAGE_USER_AGENT, } from "./fetch/page.js";
|
|
9
|
-
export { AI_PROVIDERS, aiImageReader, aiLeavesComputer, aiSettingPath, aiTextReader, readAiSetting, } from "./models/ai.js";
|
|
9
|
+
export { AI_PROVIDERS, aiImageReader, aiLeavesComputer, aiSettingPath, aiTextReader, readAiSetting, sharedModel, } from "./models/ai.js";
|
|
10
10
|
export { registerReader } from "./readers/registry.js";
|
|
@@ -35,8 +35,9 @@ export declare const remoteModel: ({ model, baseUrl, dims, }: {
|
|
|
35
35
|
export declare const remoteKey: ({ provider, model, dims }: RemoteModel) => string;
|
|
36
36
|
export type Fetch = (url: string, init: RequestInit) => Promise<Response>;
|
|
37
37
|
/** Up to `concurrency` requests at once; a 429 waits for `Retry-After`, a server error is tried again. */
|
|
38
|
-
export declare const openRemote: (remote: RemoteModel, apiKey: string | undefined, { concurrency, fetch: post, tries }
|
|
38
|
+
export declare const openRemote: (remote: RemoteModel, apiKey: string | undefined, { concurrency, fetch: post, tries, env, }: {
|
|
39
39
|
concurrency?: number;
|
|
40
40
|
fetch?: Fetch;
|
|
41
41
|
tries?: number;
|
|
42
|
+
env?: NodeJS.ProcessEnv;
|
|
42
43
|
}) => Embedder;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { setTimeout } from "node:timers/promises";
|
|
2
2
|
import { CliError } from "@wirecat/cli-base";
|
|
3
|
+
import { onThisComputer } from "../models/endpoint.js";
|
|
4
|
+
import { refuseModelAddress } from "../models/local-only.js";
|
|
3
5
|
import { unit } from "./embed.js";
|
|
4
6
|
export const OPENAI_URL = "https://api.openai.com/v1";
|
|
5
7
|
/** OpenAI's models, from its pricing page as read on 2026-10-02. */
|
|
@@ -10,9 +12,8 @@ export const OPENAI_MODELS = {
|
|
|
10
12
|
export const DEFAULT_OPENAI_MODEL = "text-embedding-3-small";
|
|
11
13
|
/** OpenAI's limits per request (2,048 inputs, 300,000 tokens); a chunk is at most ~400 tokens. */
|
|
12
14
|
const PER_REQUEST = 256;
|
|
13
|
-
const LOCAL = new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
|
|
14
15
|
/** A server on this machine: nothing leaves it, so nothing is asked. */
|
|
15
|
-
export const isLocal = (baseUrl) =>
|
|
16
|
+
export const isLocal = (baseUrl) => onThisComputer(baseUrl);
|
|
16
17
|
export const remoteModel = ({ model = DEFAULT_OPENAI_MODEL, baseUrl, dims, }) => {
|
|
17
18
|
const known = baseUrl === undefined ? OPENAI_MODELS[model] : undefined;
|
|
18
19
|
if (baseUrl === undefined && !known) {
|
|
@@ -34,7 +35,8 @@ export const remoteModel = ({ model = DEFAULT_OPENAI_MODEL, baseUrl, dims, }) =>
|
|
|
34
35
|
/** The vector key of a remote model, beside `local:<model>:<dims>`. */
|
|
35
36
|
export const remoteKey = ({ provider, model, dims }) => `${provider}:${model}:${dims}`;
|
|
36
37
|
/** Up to `concurrency` requests at once; a 429 waits for `Retry-After`, a server error is tried again. */
|
|
37
|
-
export const openRemote = (remote, apiKey, { concurrency = 4, fetch: post = fetch, tries = 5
|
|
38
|
+
export const openRemote = (remote, apiKey, { concurrency = 4, fetch: post = fetch, tries = 5, env, }) => {
|
|
39
|
+
refuseModelAddress(env ?? process.env, remote.baseUrl, "text to embed");
|
|
38
40
|
const request = async (input) => {
|
|
39
41
|
for (let attempt = 1;; attempt++) {
|
|
40
42
|
let response;
|
package/dist/errors/reasons.js
CHANGED
|
@@ -63,6 +63,14 @@ const OTHERS = [
|
|
|
63
63
|
["model.offline", "permission_error", "downloading a model needs the network; --offline was requested"],
|
|
64
64
|
["model.key-rejected", "invalid_response", "the model provider refused the API key (401 or 403)"],
|
|
65
65
|
["model.unreachable", "invalid_response", "the model provider could not be reached over the network"],
|
|
66
|
+
validation("model.address-refused", "the model address must be https, or http only on this computer"),
|
|
67
|
+
[
|
|
68
|
+
"local-only.refused",
|
|
69
|
+
"permission_error",
|
|
70
|
+
"local only is on and the address is not on this computer; nothing was sent",
|
|
71
|
+
],
|
|
72
|
+
["local-only.owner-only", "permission_error", "only the owner turns local only off, not an agent"],
|
|
73
|
+
["ai.images-not-allowed", "permission_error", "the AI model may not read pictures; models ai set --allow-remote"],
|
|
66
74
|
[
|
|
67
75
|
"ai.owner-only",
|
|
68
76
|
"permission_error",
|
|
@@ -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
|
+
};
|