@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.
Files changed (43) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/analysis/provider.d.ts +1 -1
  3. package/dist/analysis/provider.js +2 -1
  4. package/dist/attachments/gateway-ocr.js +13 -8
  5. package/dist/background/schedules.d.ts +5 -1
  6. package/dist/background/schedules.js +28 -3
  7. package/dist/calendar/mcp/index.d.ts +12 -12
  8. package/dist/cli/ai-model-command.js +6 -3
  9. package/dist/cli/analysis-choice.js +20 -4
  10. package/dist/cli/enrichment-consents-command.js +2 -0
  11. package/dist/cli/local-only-command.d.ts +10 -0
  12. package/dist/cli/local-only-command.js +103 -0
  13. package/dist/cli/messenger/conversations-command.js +1 -1
  14. package/dist/cli/messenger/replies-consents-command.js +12 -6
  15. package/dist/cli/model-catalogue-command.js +2 -0
  16. package/dist/cli/search-harder-consents-command.js +16 -1
  17. package/dist/documents.d.ts +1 -1
  18. package/dist/documents.js +1 -1
  19. package/dist/embeddings/remote.d.ts +2 -1
  20. package/dist/embeddings/remote.js +5 -3
  21. package/dist/errors/reasons.js +8 -0
  22. package/dist/meetings/mcp/index.d.ts +15 -15
  23. package/dist/models/ai.d.ts +16 -3
  24. package/dist/models/ai.js +19 -13
  25. package/dist/models/endpoint.d.ts +5 -0
  26. package/dist/models/endpoint.js +13 -0
  27. package/dist/models/index.d.ts +4 -0
  28. package/dist/models/index.js +9 -1
  29. package/dist/models/local-only.d.ts +17 -0
  30. package/dist/models/local-only.js +42 -0
  31. package/dist/models/purpose.d.ts +24 -0
  32. package/dist/models/purpose.js +26 -0
  33. package/dist/replies/rendering.js +10 -10
  34. package/dist/services/embeddings-maintenance.js +4 -1
  35. package/dist/services/enrichment.d.ts +1 -1
  36. package/dist/services/enrichment.js +27 -0
  37. package/dist/services/meeting-model.js +1 -1
  38. package/dist/services/search-harder.d.ts +11 -1
  39. package/dist/services/search-harder.js +38 -5
  40. package/dist/speech/openai.js +2 -0
  41. package/dist/speech/transcribe.d.ts +5 -2
  42. package/dist/speech/transcribe.js +14 -5
  43. package/package.json +1 -1
@@ -1,20 +1,22 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
- import { embeddingKeys, endpointKeyName } from "../embeddings/keys.js";
3
- import { modelGateway, modelTarget } from "../models/index.js";
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 = modelTarget(settings(), purpose);
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: (provider, target) => embeddingKeys(app, env, options.keyring).read(target.baseUrl === undefined ? provider : endpointKeyName(target.baseUrl))?.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 = modelTarget(settings(), "replies");
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;
@@ -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, { concurrency }),
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";
@@ -1,7 +1,9 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import * as v from "valibot";
3
3
  import { embeddingKeys, endpointKeyName } from "../embeddings/keys.js";
4
+ import { modelAddressAllowed, onThisComputer } from "../models/endpoint.js";
4
5
  import { modelGateway } from "../models/index.js";
6
+ import { localOnly } from "../models/local-only.js";
5
7
  import { costOf, DEFAULT_OFFER, enrichmentEndpoint, enrichmentPrice, estimateEnrichment, offeredModels, readEnrichmentSetting, } from "./enrichment-setting.js";
6
8
  /** One sync's share, as embedding is bounded per run; the next sync goes on where it stopped. */
7
9
  export const ENRICH_PER_RUN = 600;
@@ -62,6 +64,8 @@ export const ENRICHMENT_REASON_IDS = [
62
64
  "enrichment.rate-limited",
63
65
  "enrichment.bad-replies",
64
66
  "enrichment.cancelled",
67
+ "enrichment.local-only",
68
+ "enrichment.address-refused",
65
69
  "enrichment.error",
66
70
  ];
67
71
  const REASON_TEXT = {
@@ -76,6 +80,8 @@ const reasonIdOf = (error) => {
76
80
  return "enrichment.key-rejected";
77
81
  if (error.details.reason === "model.unreachable")
78
82
  return "enrichment.unreachable";
83
+ if (error.details.reason === "local-only.refused")
84
+ return "enrichment.local-only";
79
85
  if (error.code === "rate_limited")
80
86
  return "enrichment.rate-limited";
81
87
  if (error.code === "cancelled")
@@ -126,6 +132,26 @@ export const enrichRecords = async (store, options) => {
126
132
  const target = { provider: setting.provider, model: setting.model, baseUrl };
127
133
  const apiKey = keyLookup(options, setting)?.key;
128
134
  const maxRecords = options.maxRecords ?? ENRICH_PER_RUN;
135
+ const refused = !modelAddressAllowed(baseUrl)
136
+ ? "enrichment.address-refused"
137
+ : !onThisComputer(baseUrl) && localOnly(options.env)
138
+ ? "enrichment.local-only"
139
+ : undefined;
140
+ if (refused)
141
+ return {
142
+ status: "stopped",
143
+ provider: setting.provider,
144
+ model: setting.model,
145
+ enriched: 0,
146
+ failed: 0,
147
+ left: (await enrichment.pending(Number.MAX_SAFE_INTEGER, options.narrow)).length,
148
+ usage: { input: 0, output: 0 },
149
+ cost_usd: 0,
150
+ reason: refused === "enrichment.local-only"
151
+ ? "local only is on and the model is not on this computer; nothing was sent"
152
+ : "the address is plain http to another computer: use https, or http only on this computer; nothing was sent",
153
+ reason_id: refused,
154
+ };
129
155
  // Without a key the public API answers 401 only after the records' text has left; a custom server may need none.
130
156
  if (apiKey === undefined && setting.base_url === undefined)
131
157
  return {
@@ -145,6 +171,7 @@ export const enrichRecords = async (store, options) => {
145
171
  // The setting exists only with the owner's yes for this provider and endpoint; the endpoint is checked again.
146
172
  consent: (_request, chosen) => chosen.provider === setting.provider && chosen.baseUrl === baseUrl,
147
173
  key: () => apiKey,
174
+ env: options.env,
148
175
  ...(options.adapters ? { adapters: options.adapters } : {}),
149
176
  ...(options.fetch ? { fetch: options.fetch } : {}),
150
177
  ...(options.signal ? { signal: options.signal } : {}),
@@ -179,7 +179,7 @@ export const openMeetingEmbedder = async (choice, options = {}) => {
179
179
  throw error;
180
180
  }
181
181
  };
182
- engine = openRemote(remote, key, { concurrency: 1, fetch: guarded, tries: 1 });
182
+ engine = openRemote(remote, key, { concurrency: 1, fetch: guarded, tries: 1, env: options.env ?? process.env });
183
183
  }
184
184
  if (signal?.aborted) {
185
185
  await engine.close();
@@ -12,6 +12,11 @@ export declare const HARDER_MODELS: Readonly<Record<EnrichmentProvider, string>>
12
12
  /** The search lab's setup (cli-testing search-lab, "Haiku rerank"): the top 30, each cut to 400 characters. */
13
13
  export declare const HARDER_CANDIDATES = 30;
14
14
  export declare const HARDER_CHARS = 400;
15
+ /** A hosted model answers in 1 to 2 s; a model on this computer's CPU can take tens of seconds for 30 hits. */
16
+ export declare const HARDER_TIMEOUT_S: {
17
+ readonly hosted: 5;
18
+ readonly local: 60;
19
+ };
15
20
  declare const Setting: v.StrictObjectSchema<{
16
21
  readonly provider: v.PicklistSchema<readonly ["openai", "anthropic"], undefined>;
17
22
  readonly model: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 200, undefined>]>;
@@ -23,7 +28,11 @@ export type HarderSetting = v.InferOutput<typeof Setting>;
23
28
  /** The owner's consent, or `undefined`: no section means `--harder` sends nothing. */
24
29
  export declare const readHarderSetting: (env: NodeJS.ProcessEnv) => HarderSetting | undefined;
25
30
  export declare const writeHarderSetting: (env: NodeJS.ProcessEnv, setting: HarderSetting | undefined) => void;
26
- export declare const HARDER_REASON_IDS: readonly ["harder.no-consent", "harder.no-key", "harder.bad-setting", "harder.later-page", "harder.too-few", "harder.timeout", "harder.key-rejected", "harder.unreachable", "harder.rate-limited", "harder.bad-reply", "harder.error"];
31
+ /** The owner's time limit in seconds, or `undefined` for the default by where the model runs. */
32
+ export declare const readHarderTimeout: (env: NodeJS.ProcessEnv) => number | undefined;
33
+ export declare const writeHarderTimeout: (env: NodeJS.ProcessEnv, seconds: number | undefined) => void;
34
+ export declare const harderTimeoutSeconds: (env: NodeJS.ProcessEnv, endpoint: string) => number;
35
+ export declare const HARDER_REASON_IDS: readonly ["harder.no-consent", "harder.no-key", "harder.bad-setting", "harder.local-only", "harder.address-refused", "harder.later-page", "harder.too-few", "harder.timeout", "harder.key-rejected", "harder.unreachable", "harder.rate-limited", "harder.bad-reply", "harder.error"];
27
36
  export type HarderReasonId = (typeof HARDER_REASON_IDS)[number];
28
37
  /** What `--harder` did: `applied` only when the model's order replaced the plain one. */
29
38
  export interface HarderResult {
@@ -70,6 +79,7 @@ export type HarderAccess = {
70
79
  model: string;
71
80
  endpoint: string;
72
81
  custom: boolean;
82
+ timeoutMs: number;
73
83
  key?: string;
74
84
  } | {
75
85
  ready: false;
@@ -1,6 +1,8 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import * as v from "valibot";
3
+ import { modelAddressAllowed, onThisComputer } from "../models/endpoint.js";
3
4
  import { modelGateway } from "../models/index.js";
5
+ import { localOnly } from "../models/local-only.js";
4
6
  import { readSharedSection, writeSharedSection } from "../store/shared-config.js";
5
7
  import { keyLookup, keyVariable } from "./enrichment.js";
6
8
  import { costOf, enrichmentEndpoint, enrichmentSettingPath, MODEL_CHOICE, } from "./enrichment-setting.js";
@@ -16,7 +18,9 @@ export const HARDER_MODELS = {
16
18
  /** The search lab's setup (cli-testing search-lab, "Haiku rerank"): the top 30, each cut to 400 characters. */
17
19
  export const HARDER_CANDIDATES = 30;
18
20
  export const HARDER_CHARS = 400;
19
- const TIMEOUT_MS = 5_000;
21
+ /** A hosted model answers in 1 to 2 s; a model on this computer's CPU can take tens of seconds for 30 hits. */
22
+ export const HARDER_TIMEOUT_S = { hosted: 5, local: 60 };
23
+ const TIMEOUT_SECTION = "search_harder_timeout_s";
20
24
  const Setting = v.strictObject({
21
25
  ...MODEL_CHOICE,
22
26
  /** When the owner agreed that a `--harder` search sends its question and hits; the setting exists only with it. */
@@ -34,10 +38,22 @@ export const readHarderSetting = (env) => {
34
38
  return checked.output;
35
39
  };
36
40
  export const writeHarderSetting = (env, setting) => writeSharedSection(enrichmentSettingPath(env), SECTION, setting === undefined ? undefined : v.parse(Setting, setting));
41
+ // Its own key beside search_harder: an older tool reads that section strictly and would refuse a new field in it.
42
+ const Timeout = v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(600));
43
+ /** The owner's time limit in seconds, or `undefined` for the default by where the model runs. */
44
+ export const readHarderTimeout = (env) => {
45
+ const value = readSharedSection(enrichmentSettingPath(env), TIMEOUT_SECTION);
46
+ const checked = v.safeParse(Timeout, value);
47
+ return checked.success ? checked.output : undefined;
48
+ };
49
+ export const writeHarderTimeout = (env, seconds) => writeSharedSection(enrichmentSettingPath(env), TIMEOUT_SECTION, seconds === undefined ? undefined : v.parse(Timeout, seconds));
50
+ export const harderTimeoutSeconds = (env, endpoint) => readHarderTimeout(env) ?? (onThisComputer(endpoint) ? HARDER_TIMEOUT_S.local : HARDER_TIMEOUT_S.hosted);
37
51
  export const HARDER_REASON_IDS = [
38
52
  "harder.no-consent",
39
53
  "harder.no-key",
40
54
  "harder.bad-setting",
55
+ "harder.local-only",
56
+ "harder.address-refused",
41
57
  "harder.later-page",
42
58
  "harder.too-few",
43
59
  "harder.timeout",
@@ -87,7 +103,9 @@ const REASON_TEXT = {
87
103
  "harder.bad-setting": "the search_harder setting cannot be read; nothing was sent",
88
104
  "harder.later-page": "--harder reorders the first page only; nothing was sent",
89
105
  "harder.too-few": "fewer than two hits to reorder; nothing was sent",
90
- "harder.timeout": `the model did not answer within ${TIMEOUT_MS / 1000} s`,
106
+ "harder.address-refused": "the address is plain http to another computer: use https, or http only on this computer; nothing was sent",
107
+ "harder.local-only": "local only is on and the model is not on this computer; nothing was sent",
108
+ "harder.timeout": "the model did not answer within the time limit",
91
109
  "harder.key-rejected": "the provider refused the key",
92
110
  "harder.unreachable": "the provider could not be reached",
93
111
  "harder.rate-limited": "the provider's rate limit was reached",
@@ -135,6 +153,15 @@ export const harderAccess = ({ env, command, ...options }) => {
135
153
  endpoint: enrichmentEndpoint(setting),
136
154
  custom: setting.base_url !== undefined,
137
155
  };
156
+ if (!modelAddressAllowed(chosen.endpoint))
157
+ return {
158
+ ready: false,
159
+ ...chosen,
160
+ reason_id: "harder.address-refused",
161
+ reason: REASON_TEXT["harder.address-refused"],
162
+ };
163
+ if (!onThisComputer(chosen.endpoint) && localOnly(env))
164
+ return { ready: false, ...chosen, reason_id: "harder.local-only", reason: REASON_TEXT["harder.local-only"] };
138
165
  let key;
139
166
  try {
140
167
  key = keyLookup({ env, ...options }, setting)?.key;
@@ -155,17 +182,23 @@ export const harderAccess = ({ env, command, ...options }) => {
155
182
  reason_id: "harder.no-key",
156
183
  reason: `no ${setting.provider} key: \`${tool} models keys set ${setting.provider}\` or set ${keyVariable(setting.provider)}; nothing was sent`,
157
184
  };
158
- return { ready: true, ...chosen, ...(key === undefined ? {} : { key }) };
185
+ return {
186
+ ready: true,
187
+ ...chosen,
188
+ timeoutMs: options.timeoutMs ?? harderTimeoutSeconds(env, chosen.endpoint) * 1000,
189
+ ...(key === undefined ? {} : { key }),
190
+ };
159
191
  };
160
- /** One call to the model under the 5 s limit; a failure comes back as its reason, never thrown. */
192
+ /** One call to the model under the time limit; a failure comes back as its reason, never thrown. */
161
193
  const ask = async (access, options, request) => {
162
194
  const limit = new AbortController();
163
- const timer = setTimeout(() => limit.abort(), options.timeoutMs ?? TIMEOUT_MS);
195
+ const timer = setTimeout(() => limit.abort(), access.timeoutMs);
164
196
  const gateway = modelGateway({
165
197
  resolve: () => ({ provider: access.provider, model: access.model, baseUrl: access.endpoint }),
166
198
  consent: (_request, chosen) => chosen.provider === access.provider && chosen.baseUrl === access.endpoint,
167
199
  key: () => access.key,
168
200
  signal: limit.signal,
201
+ env: options.env,
169
202
  ...(options.adapters ? { adapters: options.adapters } : {}),
170
203
  ...(options.fetch ? { fetch: options.fetch } : {}),
171
204
  });
@@ -2,6 +2,7 @@ import { setTimeout as wait } from "node:timers/promises";
2
2
  import { backoffMs, CliError, DEFAULT_RETRY } from "@wirecat/cli-base";
3
3
  import { providerWaitMs } from "@wirecat/cli-base/http";
4
4
  import { OPENAI_URL } from "../embeddings/remote.js";
5
+ import { refuseModelAddress } from "../models/local-only.js";
5
6
  import { filesPresent, modelsDirectory, vadPath } from "./install.js";
6
7
  import { OPENAI_TRANSCRIBE_MODEL, VAD } from "./models.js";
7
8
  import { SAMPLE_RATE, toModelRate } from "./recognize.js";
@@ -161,6 +162,7 @@ const checkKeywords = (keywords = []) => {
161
162
  * dialogue by `start`. `gpt-transcribe` gives no timestamps of its own, so the times are the detector's.
162
163
  */
163
164
  export const transcribeOpenAI = async (audio, options) => {
165
+ refuseModelAddress(options.env ?? process.env, options.baseUrl ?? OPENAI_URL, "audio");
164
166
  if (!options.apiKey)
165
167
  throw new CliError("authentication_error", "no OpenAI key — `models keys set openai`, or OPENAI_API_KEY", {
166
168
  reason: "transcription.no-key",
@@ -6,8 +6,9 @@ import type { Ffmpeg } from "./decode.js";
6
6
  import { type SpeechModel } from "./models.js";
7
7
  import type { Recognizer } from "./recognize.js";
8
8
  /**
9
- * `messenger`: its own recognition (Telegram Premium). `local`: a model on this machine. `auto`: the first, then the
10
- * second. `openai`: OpenAI's API, only when asked by name — `auto` never sends audio off the machine.
9
+ * `messenger`: its own recognition (Telegram Premium). `local`: a model on this machine. `auto`: the local model when
10
+ * it is downloaded, else the messenger's. `openai`: OpenAI's API, only when asked by name — `auto` never sends audio
11
+ * to OpenAI, and with local only on it never asks the messenger either.
11
12
  */
12
13
  export declare const TRANSCRIBE_WITH: readonly ["auto", "messenger", "local", "openai"];
13
14
  export type TranscribeWith = (typeof TRANSCRIBE_WITH)[number];
@@ -35,6 +36,8 @@ export interface Choice {
35
36
  fetch?: (url: string, init: RequestInit) => Promise<Response>;
36
37
  /** The command's own cancel and deadline, for a request that leaves the machine. */
37
38
  signal?: AbortSignal;
39
+ /** Local only is on: `auto` never asks the messenger. */
40
+ localOnly?: boolean;
38
41
  }
39
42
  /** A voice note, or an audio file someone sent — an iPhone recording reaches WhatsApp as `audio/mp4`. */
40
43
  export declare const isAudioFile: ({ kind, mime }: {
@@ -1,14 +1,16 @@
1
1
  import { CliError, isCliError } from "@wirecat/cli-base";
2
2
  import { fromFile } from "../cli/settings.js";
3
3
  import { embeddingKeys } from "../embeddings/keys.js";
4
+ import { localOnly, localOnlyRefusal } from "../models/local-only.js";
4
5
  import { readOnlyLockOf, readOnlyRefusal } from "../ports/app.js";
5
6
  import { capability } from "../ports/messenger.js";
6
7
  import { typedCommand } from "../runs/scope.js";
7
8
  import { installedBytes, isInstalled, megabytes, modelPath, modelsDirectory, vadPath } from "./install.js";
8
9
  import { OPENAI_TRANSCRIBE_MODEL, orderedModels, speechModel } from "./models.js";
9
10
  /**
10
- * `messenger`: its own recognition (Telegram Premium). `local`: a model on this machine. `auto`: the first, then the
11
- * second. `openai`: OpenAI's API, only when asked by name — `auto` never sends audio off the machine.
11
+ * `messenger`: its own recognition (Telegram Premium). `local`: a model on this machine. `auto`: the local model when
12
+ * it is downloaded, else the messenger's. `openai`: OpenAI's API, only when asked by name — `auto` never sends audio
13
+ * to OpenAI, and with local only on it never asks the messenger either.
12
14
  */
13
15
  export const TRANSCRIBE_WITH = ["auto", "messenger", "local", "openai"];
14
16
  /** A recording is read into memory whole; minutes of Opus are a few megabytes. */
@@ -23,7 +25,10 @@ export const choose = (messenger, settings, flags, env = process.env, keyring) =
23
25
  : (flags.with ?? fromFile(settings, "transcribeWith", "auto").value);
24
26
  // Refused only where something is heard: `models list` reads the same profile for its model alone.
25
27
  const known = TRANSCRIBE_WITH.includes(chosen);
28
+ const onlyHere = localOnly(env);
29
+ const offComputer = known && onlyHere && (chosen === "messenger" || chosen === "openai");
26
30
  return {
31
+ ...(onlyHere ? { localOnly: true } : {}),
27
32
  directory: modelsDirectory(env),
28
33
  with: known ? chosen : "auto",
29
34
  ...(known
@@ -33,7 +38,10 @@ export const choose = (messenger, settings, flags, env = process.env, keyring) =
33
38
  }),
34
39
  model: model === undefined ? orderedModels(messenger.speechModels)[0] : speechModel(model),
35
40
  transcribeModel: fromFile(settings, "transcribeModel", OPENAI_TRANSCRIBE_MODEL).value,
36
- ...(known && chosen === "openai" ? openaiAccess(messenger, env, keyring) : {}),
41
+ ...(known && chosen === "openai" && !offComputer ? openaiAccess(messenger, env, keyring) : {}),
42
+ ...(offComputer
43
+ ? { refusal: localOnlyRefusal("the voice message", chosen === "openai" ? "OpenAI" : messenger.provider) }
44
+ : {}),
37
45
  };
38
46
  };
39
47
  const openaiAccess = (messenger, env, keyring) => {
@@ -58,7 +66,8 @@ export const notDownloaded = (messenger, model) => new CliError("not_found", `th
58
66
  export const hearOnline = async (messenger, connection, chat, messageId, choice, read) => {
59
67
  if (choice.refusal)
60
68
  throw choice.refusal;
61
- if (choice.with === "auto" || choice.with === "messenger") {
69
+ const localReady = choice.with !== "openai" && isInstalled(choice.model, choice.directory);
70
+ if (choice.with === "messenger" || (choice.with === "auto" && !localReady && !choice.localOnly)) {
62
71
  const canAsk = typeof connection.transcribe === "function";
63
72
  if (choice.with === "messenger" || canAsk) {
64
73
  try {
@@ -72,7 +81,7 @@ export const hearOnline = async (messenger, connection, chat, messageId, choice,
72
81
  }
73
82
  }
74
83
  }
75
- if (choice.with !== "openai" && !isInstalled(choice.model, choice.directory))
84
+ if (choice.with !== "openai" && !localReady)
76
85
  throw notDownloaded(messenger, choice.model);
77
86
  const { files } = await capability(connection, "download", "download attachments")(chat, messageId);
78
87
  const voice = files.find(isAudioFile);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.641.0",
3
+ "version": "0.642.0",
4
4
  "description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Viacheslav Ptsarev",