@wirecat/drive-cli 0.64.0 → 0.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/drive.js +2 -2
- package/dist/bundle/{all-profiles-BPPT2AK5.js → all-profiles-PD7GJHFA.js} +14 -13
- package/dist/bundle/{anthropic-JW6GOJUD.js → anthropic-PJKFON5H.js} +20 -11
- package/dist/bundle/{app-server-KAQIOJMZ.js → app-server-6ELQA6FJ.js} +59 -56
- package/dist/bundle/{bun-UT7GNTPV.js → bun-P54TGES2.js} +2 -2
- package/dist/bundle/{bun-sqlite-2OIVV3LS.js → bun-sqlite-TND5ZRJH.js} +12 -8
- package/dist/bundle/chunk-2AFI4KGI.js +185 -0
- package/dist/bundle/{chunk-WWCYTMAV.js → chunk-3HXNDF6Q.js} +2 -2
- package/dist/bundle/{chunk-46CD64J2.js → chunk-3ONWN3IA.js} +166 -53
- package/dist/bundle/{chunk-4YRENUB5.js → chunk-42G2XNPN.js} +2 -2
- package/dist/bundle/chunk-4AOINPN2.js +66 -0
- package/dist/bundle/{chunk-ZF6GUZCE.js → chunk-4EDWLR22.js} +1 -1
- package/dist/bundle/{chunk-BEZJA44H.js → chunk-4Y5YBFMS.js} +7 -7
- package/dist/bundle/{chunk-B7XBIOMR.js → chunk-54V4H6PM.js} +16 -16
- package/dist/bundle/{chunk-4CNTID2X.js → chunk-5XSBCMAF.js} +4 -4
- package/dist/bundle/{chunk-IDAK4DDK.js → chunk-6DCLZLGX.js} +1 -1
- package/dist/bundle/{chunk-G4KEKKDE.js → chunk-7AQGVX5O.js} +20 -20
- package/dist/bundle/{chunk-34BIDKF4.js → chunk-7TAP7Y2E.js} +508 -155
- package/dist/bundle/{chunk-BZ2ZKILM.js → chunk-A27UVLPK.js} +3 -3
- package/dist/bundle/{chunk-SIOIMO62.js → chunk-A4QNADEX.js} +57 -51
- package/dist/bundle/{chunk-FXBHOCJK.js → chunk-ADLS6FVG.js} +1 -1
- package/dist/bundle/{chunk-66AF4FBW.js → chunk-B2LPCHQN.js} +4 -4
- package/dist/bundle/{chunk-M73NNJ3X.js → chunk-CGQRZRTH.js} +2 -2
- package/dist/bundle/{chunk-KVW4XNKB.js → chunk-CWLL63JD.js} +107 -48
- package/dist/bundle/{chunk-CPMRM3GQ.js → chunk-D6Z43SOG.js} +1592 -335
- package/dist/bundle/{chunk-QXCKJUZY.js → chunk-D7WB54P7.js} +111 -27
- package/dist/bundle/{chunk-VT2UFYPJ.js → chunk-DA63E2UM.js} +13 -9
- package/dist/bundle/{chunk-2FEZ24DK.js → chunk-ECEP4SO3.js} +20 -20
- package/dist/bundle/{chunk-ZSZJLJIA.js → chunk-EHU6EYGO.js} +38 -28
- package/dist/bundle/{chunk-EJ4PNHPP.js → chunk-ELJUBPY4.js} +1 -1
- package/dist/bundle/{chunk-F2VDAG32.js → chunk-EM7NL5ES.js} +3 -3
- package/dist/bundle/{chunk-O2QO5UZC.js → chunk-EU5MD24W.js} +13 -13
- package/dist/bundle/{chunk-KIN6PDFE.js → chunk-EZ2OLYEK.js} +4 -4
- package/dist/bundle/{chunk-OH3K2E7X.js → chunk-F56DRBGY.js} +655 -1220
- package/dist/bundle/{chunk-VIJ6ACYB.js → chunk-FA6JNXCC.js} +8 -8
- package/dist/bundle/{chunk-KE4XPPRQ.js → chunk-FBHSWQU7.js} +1531 -136
- package/dist/bundle/{chunk-ZRZ4HTCK.js → chunk-GW3LBY3T.js} +51 -67
- package/dist/bundle/{chunk-6B37XO6B.js → chunk-HP3NT6JJ.js} +3 -3
- package/dist/bundle/{chunk-IX7NQJLY.js → chunk-I272E6UR.js} +9 -8
- package/dist/bundle/{chunk-5HSRQ53R.js → chunk-IBO23OID.js} +2 -2
- package/dist/bundle/{chunk-EZ6O3ST3.js → chunk-II4S2DBJ.js} +3 -3
- package/dist/bundle/{chunk-3NULZGQU.js → chunk-IKHOIXJR.js} +2 -2
- package/dist/bundle/{chunk-JRXFW7HE.js → chunk-IMHW7VIV.js} +5 -5
- package/dist/bundle/{chunk-USLZE36C.js → chunk-JMJIH6JH.js} +6 -6
- package/dist/bundle/{chunk-C7WBNOYW.js → chunk-JPPPLKAO.js} +26 -1
- package/dist/bundle/{chunk-EQEGJVO2.js → chunk-LMKPP2JP.js} +1 -1
- package/dist/bundle/{chunk-G3NULXOM.js → chunk-M7ELUGU6.js} +4 -4
- package/dist/bundle/{chunk-6G53ZFUT.js → chunk-MCPOZNWG.js} +1 -1
- package/dist/bundle/{chunk-EWGVDFPT.js → chunk-NI5PD5KM.js} +39203 -35871
- package/dist/bundle/{chunk-AHB4OJCI.js → chunk-NQ5XMSLA.js} +3678 -2049
- package/dist/bundle/chunk-NQRTKYJB.js +257 -0
- package/dist/bundle/{chunk-3J5KAFNA.js → chunk-O6K2E7OA.js} +3917 -3005
- package/dist/bundle/{chunk-J62DI53V.js → chunk-O7ZDCOZE.js} +1 -1
- package/dist/bundle/{chunk-XPXKD63J.js → chunk-OFJXHEFT.js} +13 -13
- package/dist/bundle/chunk-OWMZUWCM.js +109 -0
- package/dist/bundle/chunk-PHOL2DZM.js +138 -0
- package/dist/bundle/{chunk-KG2XKEHL.js → chunk-PLP5527C.js} +5 -5
- package/dist/bundle/{chunk-5ZBR55US.js → chunk-RNHGQ35R.js} +1 -1
- package/dist/bundle/{chunk-IK6KH3RE.js → chunk-RX5CJ55S.js} +1 -1
- package/dist/bundle/{chunk-K6BSB53R.js → chunk-SE352DBY.js} +1 -1
- package/dist/bundle/chunk-SEQWBZYH.js +18 -0
- package/dist/bundle/{chunk-LOMW6F2E.js → chunk-SIWXYB4E.js} +3734 -3448
- package/dist/bundle/{chunk-GW3U6OLD.js → chunk-SNLSEYJO.js} +1 -1
- package/dist/bundle/{chunk-UJR272CP.js → chunk-SS4LKLD7.js} +52 -605
- package/dist/bundle/{chunk-BEUAICUD.js → chunk-TMHF4BCL.js} +2 -2
- package/dist/bundle/{chunk-BDYWZ7JE.js → chunk-TOVWMURV.js} +30 -6
- package/dist/bundle/{chunk-N622LRPM.js → chunk-TTP4NOP3.js} +4 -4
- package/dist/bundle/chunk-UTNRBOEN.js +53 -0
- package/dist/bundle/{chunk-36GPBPWM.js → chunk-VDZY3L7U.js} +3 -1
- package/dist/bundle/chunk-VHQYWFWV.js +13 -0
- package/dist/bundle/{chunk-VPLFD5RJ.js → chunk-VLXWAH5E.js} +4 -4
- package/dist/bundle/{chunk-UIEA6FIV.js → chunk-VMAMRFFC.js} +23 -23
- package/dist/bundle/{chunk-HW4UPST2.js → chunk-W2XY6C5S.js} +2 -2
- package/dist/bundle/{chunk-P7DEGRZA.js → chunk-WRAUO5EJ.js} +22 -24
- package/dist/bundle/{chunk-QEAD2LF4.js → chunk-WRMJN6UQ.js} +3 -3
- package/dist/bundle/{chunk-UD55VB2N.js → chunk-WVJHZIDH.js} +3 -3
- package/dist/bundle/{chunk-B67BLRAI.js → chunk-X7YGGWXI.js} +1 -59
- package/dist/bundle/{chunk-EC2XGDKJ.js → chunk-XPWZSW6Y.js} +4 -4
- package/dist/bundle/{chunk-E2LBCCTG.js → chunk-XYE7XZPB.js} +5 -5
- package/dist/bundle/{chunk-TNV2FXVK.js → chunk-Y5PKRITX.js} +5 -5
- package/dist/bundle/{chunk-5OFA5EXE.js → chunk-Z2ADO6UA.js} +2 -2
- package/dist/bundle/{chunk-PBMSBCVB.js → chunk-ZD4MB7NH.js} +1 -1
- package/dist/bundle/{chunk-2W464HAE.js → chunk-ZILALBYQ.js} +4 -4
- package/dist/bundle/{chunk-OEVHZOHC.js → chunk-ZR2EJPMQ.js} +44 -15
- package/dist/bundle/command-contract-25E4PYMD.js +40 -0
- package/dist/bundle/command-server-entry-36JXYIJB.js +170 -0
- package/dist/bundle/{decode-HTOQ6S3V.js → decode-T5ZW57WZ.js} +8 -8
- package/dist/bundle/{dispatch-SH5SP6LA.js → dispatch-RMA2XFYA.js} +9 -9
- package/dist/bundle/drive.js +11 -11
- package/dist/bundle/{echarts-KFHB6SLX.js → echarts-KQ44LPSF.js} +2 -2
- package/dist/bundle/{embed-YATFB2PN.js → embed-Q7XST53J.js} +9 -9
- package/dist/bundle/{embedder-MQPDFGTJ.js → embedder-RWZSBVW2.js} +12 -12
- package/dist/bundle/entry-HPLW4QL2.js +25 -0
- package/dist/bundle/{failure-4FQL4XJI.js → failure-7NP4QPIN.js} +4 -4
- package/dist/bundle/first-run-RL3RKYZW.js +30 -0
- package/dist/bundle/first-screen-NX3TM2VJ.js +38 -0
- package/dist/bundle/google-DPD5N6AQ.js +42 -0
- package/dist/bundle/{google-api-QMFGCXBM.js → google-api-P5DRHD7L.js} +61 -55
- package/dist/bundle/grants-TX4MHLI4.js +109 -0
- package/dist/bundle/{identity-FYVDK4M2.js → identity-VDV6CHRW.js} +6 -6
- package/dist/bundle/{instructions-D3GF3B7M.js → instructions-Q45FVY6H.js} +1 -1
- package/dist/bundle/{login-COFZ2IWP.js → login-XKN3NI6X.js} +67 -61
- package/dist/bundle/{mcp-RKJG22KM.js → mcp-7KQUJNFN.js} +2 -2
- package/dist/bundle/{node-OFICOKX3.js → node-MSW565D3.js} +2 -2
- package/dist/bundle/{node-KM3CUABH.js → node-P4E63KXA.js} +9 -9
- package/dist/bundle/{node-sqlite-DNBTDOXD.js → node-sqlite-S74XVVHL.js} +13 -9
- package/dist/bundle/oauth-6R7AWAES.js +22 -0
- package/dist/bundle/{open-PTPR2YWX.js → open-P7UQG7XJ.js} +8 -8
- package/dist/bundle/{openai-2KV5LUW4.js → openai-DDHJ57KZ.js} +19 -40
- package/dist/bundle/{process-EAW6NST2.js → process-NMUB5SHK.js} +1 -1
- package/dist/bundle/{program-6UV5Q5YN.js → program-PJNWP6JW.js} +294 -137
- package/dist/bundle/{prompt-634TPMJK.js → prompt-VOSMK4C2.js} +8 -8
- package/dist/bundle/{reasons-DDWCEYSQ.js → reasons-KDAXOC5S.js} +5 -5
- package/dist/bundle/{recognize-SJO6QUDW.js → recognize-GZIY63HS.js} +7 -7
- package/dist/bundle/{remote-6JXZITKF.js → remote-V3YGN7LN.js} +10 -10
- package/dist/bundle/{rerank-MD5VOPQ6.js → rerank-XRU6AVN7.js} +10 -10
- package/dist/bundle/{serve-LZTROA2M.js → serve-NDOAFA57.js} +12 -12
- package/dist/bundle/{server-NSA3UAFY.js → server-BKGWJYMC.js} +46 -44
- package/dist/bundle/server-QD2MUJJZ.js +72 -0
- package/dist/bundle/{services-F5A6XQCV.js → services-TYDMFQCA.js} +101 -41
- package/dist/bundle/{sqlite-runtime-7YF6REKS.js → sqlite-runtime-UAFJKSJR.js} +9 -9
- package/dist/bundle/{start-MUFLE6FA.js → start-2ZLDP2OE.js} +7 -7
- package/dist/bundle/{state-UC54F3YZ.js → state-6SP27J2K.js} +9 -9
- package/dist/bundle/{store-J53YNAH6.js → store-4UUY545Q.js} +25 -18
- package/dist/bundle/{store-F5FJGWMR.js → store-EJN27MXI.js} +61 -28
- package/dist/bundle/store-maintenance-command-LETURZDC.js +60 -0
- package/dist/bundle/tokens-MTFJPTYT.js +107 -0
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +6 -5
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/context.d.ts +4 -2
- package/dist/commands/context.d.ts.map +1 -1
- package/dist/commands/context.js.map +1 -1
- package/dist/commands/documents.d.ts +2 -0
- package/dist/commands/documents.d.ts.map +1 -1
- package/dist/commands/documents.js +39 -3
- package/dist/commands/documents.js.map +1 -1
- package/dist/config.d.ts +13 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +32 -2
- package/dist/config.js.map +1 -1
- package/dist/documents-add.d.ts +49 -0
- package/dist/documents-add.d.ts.map +1 -0
- package/dist/documents-add.js +122 -0
- package/dist/documents-add.js.map +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +9 -1
- package/dist/errors.js.map +1 -1
- package/dist/knowledge.d.ts +1 -1
- package/dist/knowledge.d.ts.map +1 -1
- package/dist/knowledge.js +15 -17
- package/dist/knowledge.js.map +1 -1
- package/dist/model.d.ts +3 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js.map +1 -1
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +22 -15
- package/dist/program.js.map +1 -1
- package/dist/reasons.d.ts.map +1 -1
- package/dist/reasons.js +25 -0
- package/dist/reasons.js.map +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +20 -0
- package/dist/store.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
- package/dist/bundle/chunk-DD7EFG6B.js +0 -35
- package/dist/bundle/chunk-GSMYXGFR.js +0 -62
- package/dist/bundle/command-contract-H5OYJOPF.js +0 -38
- package/dist/bundle/entry-YZBB647C.js +0 -22
- package/dist/bundle/first-run-5JT3UQZB.js +0 -30
- package/dist/bundle/first-screen-BEMDEWO7.js +0 -36
- package/dist/bundle/google-DVADVICN.js +0 -36
- package/dist/bundle/grants-WKB2E4TA.js +0 -103
- package/dist/bundle/oauth-PDQHWFBF.js +0 -22
- package/dist/bundle/server-GT7X666D.js +0 -69
- package/dist/bundle/store-maintenance-command-GJVXLBAB.js +0 -58
- package/dist/bundle/tokens-H2EJKGA5.js +0 -101
- package/dist/bundle/{chunk-SW6C6WH5.js → chunk-YVNHQFLC.js} +0 -0
- package/dist/bundle/{mdast-util-from-markdown-FXEPSNER.js → mdast-util-from-markdown-CE73EWJ2.js} +3 -3
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
embeddingKeys,
|
|
5
|
+
endpointKeyName,
|
|
6
|
+
modelGateway
|
|
7
|
+
} from "./chunk-FBHSWQU7.js";
|
|
8
|
+
import {
|
|
9
|
+
endpoint
|
|
10
|
+
} from "./chunk-OWMZUWCM.js";
|
|
11
|
+
import {
|
|
12
|
+
readSharedSection,
|
|
13
|
+
sharedConfigPath,
|
|
14
|
+
writeSharedSection
|
|
15
|
+
} from "./chunk-4Y5YBFMS.js";
|
|
16
|
+
import {
|
|
17
|
+
storePath
|
|
18
|
+
} from "./chunk-UTNRBOEN.js";
|
|
19
|
+
import {
|
|
20
|
+
Credentials,
|
|
21
|
+
isMovedRun,
|
|
22
|
+
resolvePaths
|
|
23
|
+
} from "./chunk-7AQGVX5O.js";
|
|
24
|
+
import {
|
|
25
|
+
check,
|
|
26
|
+
getDotPath,
|
|
27
|
+
maxLength,
|
|
28
|
+
minLength,
|
|
29
|
+
optional,
|
|
30
|
+
picklist,
|
|
31
|
+
pipe,
|
|
32
|
+
safeParse,
|
|
33
|
+
strictObject,
|
|
34
|
+
string,
|
|
35
|
+
trim
|
|
36
|
+
} from "./chunk-TOVWMURV.js";
|
|
37
|
+
import {
|
|
38
|
+
CliError,
|
|
39
|
+
isCliError
|
|
40
|
+
} from "./chunk-ELJUBPY4.js";
|
|
41
|
+
import {
|
|
42
|
+
__name
|
|
43
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
44
|
+
|
|
45
|
+
// dist/errors.js
|
|
46
|
+
var googleError = /* @__PURE__ */ __name((error) => {
|
|
47
|
+
if (isCliError(error))
|
|
48
|
+
return error;
|
|
49
|
+
const value = error;
|
|
50
|
+
if (value?.name === "AbortError" || value?.code === "ERR_CANCELED")
|
|
51
|
+
return new CliError("cancelled", "Google operation was cancelled", { reason: "command.cancelled" });
|
|
52
|
+
const status = value?.status ?? value?.response?.status;
|
|
53
|
+
const payload = value?.response?.data?.error;
|
|
54
|
+
const reason = typeof payload === "string" ? payload : payload?.errors?.[0]?.reason;
|
|
55
|
+
const told = status === 403 && typeof reason === "string" && /^[A-Za-z]{1,64}$/.test(reason) ? { google_reason: reason } : {};
|
|
56
|
+
const disabled = typeof payload === "object" && payload !== null && Array.isArray(payload.details) && payload.details.some((detail) => detail !== null && typeof detail === "object" && "@type" in detail && detail["@type"] === "type.googleapis.com/google.rpc.ErrorInfo" && "domain" in detail && detail.domain === "googleapis.com" && "reason" in detail && detail.reason === "SERVICE_DISABLED");
|
|
57
|
+
if (reason === "invalid_grant" || reason === "invalid_token")
|
|
58
|
+
return new CliError("authentication_error", "Google sign-in is no longer valid \u2014 run drive <profile> session start again", {
|
|
59
|
+
reason: "oauth.expired"
|
|
60
|
+
});
|
|
61
|
+
if (reason === "invalid_client")
|
|
62
|
+
return new CliError("configuration_error", "Google rejected the OAuth application; check its Desktop client setup", {
|
|
63
|
+
reason: "sign-in.client-rejected"
|
|
64
|
+
});
|
|
65
|
+
if (status === 403 && (reason === "accessNotConfigured" || disabled))
|
|
66
|
+
return new CliError("configuration_error", "Google API is disabled for this OAuth project; its owner must enable it in Google Cloud API Library", { reason: "api.disabled", status });
|
|
67
|
+
if (reason === "rateLimitExceeded" || reason === "userRateLimitExceeded" || reason === "dailyLimitExceeded" || reason === "quotaExceeded")
|
|
68
|
+
return new CliError("rate_limited", "Google rate limit reached; retry the command", {
|
|
69
|
+
retryable: true,
|
|
70
|
+
...status ? { status } : {},
|
|
71
|
+
...told
|
|
72
|
+
});
|
|
73
|
+
if (reason === "exportSizeLimitExceeded")
|
|
74
|
+
return new CliError("validation_error", "Google exports at most 10 MB of a native file; this one is larger", {
|
|
75
|
+
reason: "export.too-large"
|
|
76
|
+
});
|
|
77
|
+
if (status === 401)
|
|
78
|
+
return new CliError("authentication_error", "Google sign-in expired \u2014 run drive <profile> session start again", {
|
|
79
|
+
reason: "oauth.expired"
|
|
80
|
+
});
|
|
81
|
+
if (status === 403)
|
|
82
|
+
return new CliError("permission_error", "Google denied this operation; check access and OAuth permissions", {
|
|
83
|
+
status,
|
|
84
|
+
...told
|
|
85
|
+
});
|
|
86
|
+
if (status === 404)
|
|
87
|
+
return new CliError("not_found", "Google source is unavailable or no longer accessible", { status });
|
|
88
|
+
if (status === 429)
|
|
89
|
+
return new CliError("rate_limited", "Google rate limit reached; retry the command", { retryable: true, status });
|
|
90
|
+
if (status !== void 0)
|
|
91
|
+
return new CliError("provider_error", `Google request failed (HTTP ${status})`, { status });
|
|
92
|
+
return new CliError("provider_unavailable", "Google request failed; no request or credential details were logged", {
|
|
93
|
+
retryable: true
|
|
94
|
+
});
|
|
95
|
+
}, "googleError");
|
|
96
|
+
var offlineRefused = /* @__PURE__ */ __name((what = "this command may require network access") => new CliError("permission_error", `${what}; --offline was requested`, { reason: "offline.refused" }), "offlineRefused");
|
|
97
|
+
|
|
98
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/models/ai.js
|
|
99
|
+
var AI_PROVIDERS = ["anthropic", "openai", "ollama"];
|
|
100
|
+
var DEFAULT_BASE_URL = {
|
|
101
|
+
anthropic: "https://api.anthropic.com",
|
|
102
|
+
openai: "https://api.openai.com/v1",
|
|
103
|
+
ollama: "http://127.0.0.1:11434/v1"
|
|
104
|
+
};
|
|
105
|
+
var OFFICIAL = {
|
|
106
|
+
"https://api.openai.com": "openai",
|
|
107
|
+
"https://api.anthropic.com": "anthropic"
|
|
108
|
+
};
|
|
109
|
+
var SECTION = "ai";
|
|
110
|
+
var loopback = /* @__PURE__ */ __name((hostname) => hostname === "localhost" || hostname === "[::1]" || /^127(\.\d{1,3}){3}$/.test(hostname), "loopback");
|
|
111
|
+
var aiAddressAllowed = /* @__PURE__ */ __name((value) => {
|
|
112
|
+
if (!endpoint(value))
|
|
113
|
+
return false;
|
|
114
|
+
const url = new URL(value);
|
|
115
|
+
return url.protocol === "https:" || loopback(url.hostname);
|
|
116
|
+
}, "aiAddressAllowed");
|
|
117
|
+
var consentShape = strictObject({
|
|
118
|
+
origin: string(),
|
|
119
|
+
model: string(),
|
|
120
|
+
at: string()
|
|
121
|
+
});
|
|
122
|
+
var settingShape = strictObject({
|
|
123
|
+
provider: picklist(AI_PROVIDERS),
|
|
124
|
+
model: pipe(string(), trim(), minLength(1), maxLength(200)),
|
|
125
|
+
base_url: optional(pipe(string(), check(aiAddressAllowed, "use https, or http only on this computer"))),
|
|
126
|
+
images: optional(consentShape)
|
|
127
|
+
});
|
|
128
|
+
var aiSettingPath = /* @__PURE__ */ __name((env) => sharedConfigPath(storePath(env), env), "aiSettingPath");
|
|
129
|
+
var readAiSetting = /* @__PURE__ */ __name((path) => {
|
|
130
|
+
const section = readSharedSection(path, SECTION);
|
|
131
|
+
if (section === void 0)
|
|
132
|
+
return void 0;
|
|
133
|
+
const checked = safeParse(settingShape, section);
|
|
134
|
+
if (!checked.success)
|
|
135
|
+
throw new CliError("configuration_error", `${path}: ai.${getDotPath(checked.issues[0]) ?? "setting"} is invalid`, {
|
|
136
|
+
reason: "ai.setting-invalid"
|
|
137
|
+
});
|
|
138
|
+
return checked.output;
|
|
139
|
+
}, "readAiSetting");
|
|
140
|
+
var writeAiSetting = /* @__PURE__ */ __name((path, setting) => writeSharedSection(path, SECTION, setting), "writeAiSetting");
|
|
141
|
+
var aiSettingOf = /* @__PURE__ */ __name((given) => {
|
|
142
|
+
const draft = {
|
|
143
|
+
provider: given.provider,
|
|
144
|
+
model: given.model,
|
|
145
|
+
...given.baseUrl?.trim() ? { base_url: given.baseUrl.trim().replace(/\/+$/, "") } : {}
|
|
146
|
+
};
|
|
147
|
+
const checked = safeParse(settingShape, draft);
|
|
148
|
+
if (!checked.success) {
|
|
149
|
+
const field = getDotPath(checked.issues[0]);
|
|
150
|
+
throw new CliError("validation_error", field === "provider" ? `the provider is one of ${AI_PROVIDERS.join(", ")}` : field === "base_url" ? "this address is not allowed: use https, or http only on this computer" : "name the model, 1 to 200 characters", { reason: field === "base_url" ? "ai.address-refused" : "ai.setting-invalid" });
|
|
151
|
+
}
|
|
152
|
+
if (checked.output.provider === "ollama" && !loopback(new URL(aiBaseUrl(checked.output)).hostname))
|
|
153
|
+
throw new CliError("validation_error", "Ollama is read only on this computer", { reason: "ai.address-refused" });
|
|
154
|
+
return given.allowImages ? {
|
|
155
|
+
...checked.output,
|
|
156
|
+
images: { origin: aiOrigin(checked.output), model: checked.output.model, at: (/* @__PURE__ */ new Date()).toISOString() }
|
|
157
|
+
} : checked.output;
|
|
158
|
+
}, "aiSettingOf");
|
|
159
|
+
var aiBaseUrl = /* @__PURE__ */ __name((setting) => setting.base_url ?? DEFAULT_BASE_URL[setting.provider], "aiBaseUrl");
|
|
160
|
+
var aiOrigin = /* @__PURE__ */ __name((setting) => new URL(aiBaseUrl(setting)).origin, "aiOrigin");
|
|
161
|
+
var aiTarget = /* @__PURE__ */ __name((setting) => ({
|
|
162
|
+
provider: setting.provider === "anthropic" ? "anthropic" : "openai",
|
|
163
|
+
model: setting.model,
|
|
164
|
+
baseUrl: aiBaseUrl(setting)
|
|
165
|
+
}), "aiTarget");
|
|
166
|
+
var aiImagesAllowed = /* @__PURE__ */ __name((setting) => setting.images?.origin === aiOrigin(setting) && setting.images.model === setting.model, "aiImagesAllowed");
|
|
167
|
+
var aiKeys = /* @__PURE__ */ __name((app, env, keyring) => {
|
|
168
|
+
const where = { appName: "WireCat", prefix: "WIRECAT", env };
|
|
169
|
+
const credentials = new Credentials({
|
|
170
|
+
configDir: resolvePaths(where).config,
|
|
171
|
+
service: "WireCat",
|
|
172
|
+
// A tool run with its own folders moved (MEMO_CONFIG_DIR…) is a test or a sandbox, not the owner.
|
|
173
|
+
isolated: isMovedRun(where) || isMovedRun({ appName: app.appName, prefix: app.envPrefix, env }),
|
|
174
|
+
env,
|
|
175
|
+
...keyring ? { keyring } : {},
|
|
176
|
+
warn: /* @__PURE__ */ __name((message) => process.stderr.write(`${message}
|
|
177
|
+
`), "warn")
|
|
178
|
+
});
|
|
179
|
+
const account = /* @__PURE__ */ __name((origin) => `ai:${origin}`, "account");
|
|
180
|
+
return {
|
|
181
|
+
read: /* @__PURE__ */ __name((origin) => {
|
|
182
|
+
const stored = credentials.read(account(origin));
|
|
183
|
+
if (stored)
|
|
184
|
+
return { key: stored.secret, source: stored.source };
|
|
185
|
+
const official = OFFICIAL[origin];
|
|
186
|
+
const legacy = official ?? (origin.startsWith("https://") ? endpointKeyName(origin) : void 0);
|
|
187
|
+
const found = legacy === void 0 ? void 0 : embeddingKeys(app, env, keyring).read(legacy);
|
|
188
|
+
return found ? { key: found.key, source: found.source === "env" ? "environment" : found.source } : void 0;
|
|
189
|
+
}, "read"),
|
|
190
|
+
write: /* @__PURE__ */ __name((origin, key) => credentials.write(account(origin), key, { signIn: true }), "write"),
|
|
191
|
+
remove: /* @__PURE__ */ __name((origin) => credentials.remove(account(origin)), "remove")
|
|
192
|
+
};
|
|
193
|
+
}, "aiKeys");
|
|
194
|
+
var aiNeedsKey = /* @__PURE__ */ __name((setting) => setting.provider !== "ollama", "aiNeedsKey");
|
|
195
|
+
var keyFor = /* @__PURE__ */ __name((setting, deps) => aiNeedsKey(setting) ? aiKeys(deps.app, deps.env, deps.keyring).read(aiOrigin(setting))?.key : void 0, "keyFor");
|
|
196
|
+
var gatewayFor = /* @__PURE__ */ __name((setting, deps, key) => modelGateway({
|
|
197
|
+
resolve: /* @__PURE__ */ __name(() => aiTarget(setting), "resolve"),
|
|
198
|
+
consent: /* @__PURE__ */ __name(() => true, "consent"),
|
|
199
|
+
key: /* @__PURE__ */ __name(() => key, "key"),
|
|
200
|
+
...deps.fetch ? { fetch: deps.fetch } : {},
|
|
201
|
+
...deps.signal ? { signal: deps.signal } : {}
|
|
202
|
+
}), "gatewayFor");
|
|
203
|
+
var reasonOf = /* @__PURE__ */ __name((error) => {
|
|
204
|
+
if (!(error instanceof CliError))
|
|
205
|
+
return "ai.failed";
|
|
206
|
+
if (error.code === "rate_limited")
|
|
207
|
+
return "ai.rate-limited";
|
|
208
|
+
const { reason, status } = error.details;
|
|
209
|
+
if (reason === "model.key-rejected")
|
|
210
|
+
return "ai.key-rejected";
|
|
211
|
+
if (reason === "model.unreachable")
|
|
212
|
+
return "ai.unreachable";
|
|
213
|
+
if (status === 402)
|
|
214
|
+
return "ai.no-credit";
|
|
215
|
+
if (status === 404)
|
|
216
|
+
return "ai.model-unknown";
|
|
217
|
+
if (typeof status === "number" && status >= 500)
|
|
218
|
+
return "ai.provider-error";
|
|
219
|
+
return "ai.failed";
|
|
220
|
+
}, "reasonOf");
|
|
221
|
+
var checkAi = /* @__PURE__ */ __name(async (deps) => {
|
|
222
|
+
const setting = readAiSetting(aiSettingPath(deps.env));
|
|
223
|
+
if (!setting)
|
|
224
|
+
return { ok: false, reason: "ai.not-set", ms: null };
|
|
225
|
+
const key = keyFor(setting, deps);
|
|
226
|
+
if (aiNeedsKey(setting) && !key)
|
|
227
|
+
return { ok: false, reason: "ai.key-missing", ms: null };
|
|
228
|
+
const started = Date.now();
|
|
229
|
+
try {
|
|
230
|
+
await gatewayFor(setting, deps, key).complete({
|
|
231
|
+
purpose: "check",
|
|
232
|
+
system: "Reply with the word OK.",
|
|
233
|
+
prompt: "OK?",
|
|
234
|
+
// Reasoning models spend tokens before they answer; too low a cap reads as a broken setup.
|
|
235
|
+
maxTokens: 2048
|
|
236
|
+
});
|
|
237
|
+
return { ok: true, reason: "ai.ok", ms: Date.now() - started };
|
|
238
|
+
} catch (error) {
|
|
239
|
+
return { ok: false, reason: reasonOf(error), ms: null };
|
|
240
|
+
}
|
|
241
|
+
}, "checkAi");
|
|
242
|
+
|
|
243
|
+
export {
|
|
244
|
+
AI_PROVIDERS,
|
|
245
|
+
aiSettingPath,
|
|
246
|
+
readAiSetting,
|
|
247
|
+
writeAiSetting,
|
|
248
|
+
aiSettingOf,
|
|
249
|
+
aiBaseUrl,
|
|
250
|
+
aiOrigin,
|
|
251
|
+
aiImagesAllowed,
|
|
252
|
+
aiKeys,
|
|
253
|
+
aiNeedsKey,
|
|
254
|
+
checkAi,
|
|
255
|
+
googleError,
|
|
256
|
+
offlineRefused
|
|
257
|
+
};
|