@wirecat/yandex-disk-cli 0.0.0-stage → 0.1.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 +25 -0
- package/LICENSE +204 -0
- package/README.md +243 -2
- package/contracts/wirecat.json +1554 -0
- package/dist/bin/ydisk.d.ts +3 -0
- package/dist/bin/ydisk.d.ts.map +1 -0
- package/dist/bin/ydisk.js +40 -0
- package/dist/bin/ydisk.js.map +1 -0
- package/dist/bundle/all-profiles-4OLZF3RT.js +279 -0
- package/dist/bundle/anthropic-DKB4OJXZ.js +91 -0
- package/dist/bundle/app-server-G4545SSV.js +247 -0
- package/dist/bundle/bun-RXEQKFED.js +169 -0
- package/dist/bundle/bun-sqlite-VHT5LN7U.js +76 -0
- package/dist/bundle/chunk-2BITUXGC.js +12289 -0
- package/dist/bundle/chunk-2CLWDQKA.js +39330 -0
- package/dist/bundle/chunk-2JFDOPKA.js +9575 -0
- package/dist/bundle/chunk-3GVI2MAO.js +106 -0
- package/dist/bundle/chunk-3SZBWBMI.js +131 -0
- package/dist/bundle/chunk-44VSEXW6.js +4054 -0
- package/dist/bundle/chunk-4YPRRQBE.js +95 -0
- package/dist/bundle/chunk-5COYRL5B.js +379 -0
- package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
- package/dist/bundle/chunk-5DM7DIZL.js +1402 -0
- package/dist/bundle/chunk-6R2DVTVZ.js +24 -0
- package/dist/bundle/chunk-762BS35H.js +2787 -0
- package/dist/bundle/chunk-AG64V7AB.js +1233 -0
- package/dist/bundle/chunk-BC5HGIXB.js +334 -0
- package/dist/bundle/chunk-BH7LFEX7.js +36 -0
- package/dist/bundle/chunk-BLNPGY7N.js +53 -0
- package/dist/bundle/chunk-CNIA2LJF.js +372 -0
- package/dist/bundle/chunk-COSXMDC7.js +230 -0
- package/dist/bundle/chunk-D72URWJE.js +532 -0
- package/dist/bundle/chunk-D7FO33KU.js +785 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-DJH26PQ3.js +1396 -0
- package/dist/bundle/chunk-DJPT7IUC.js +64567 -0
- package/dist/bundle/chunk-DTMSCZDW.js +209 -0
- package/dist/bundle/chunk-E6LGZ5LX.js +16 -0
- package/dist/bundle/chunk-E6YRIHS5.js +92 -0
- package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
- package/dist/bundle/chunk-F3DDSZTF.js +78 -0
- package/dist/bundle/chunk-F4WWTQNL.js +188 -0
- package/dist/bundle/chunk-FDDAUASC.js +1028 -0
- package/dist/bundle/chunk-FMNPG6N2.js +170 -0
- package/dist/bundle/chunk-FOKJ4POB.js +274 -0
- package/dist/bundle/chunk-G22C7JG6.js +731 -0
- package/dist/bundle/chunk-GA442SYZ.js +161 -0
- package/dist/bundle/chunk-GEBSW7UK.js +6848 -0
- package/dist/bundle/chunk-GGRKWAOK.js +594 -0
- package/dist/bundle/chunk-HHINRNZA.js +788 -0
- package/dist/bundle/chunk-HUZCL33L.js +128 -0
- package/dist/bundle/chunk-IALSIQVT.js +142 -0
- package/dist/bundle/chunk-IOXR2QBX.js +398 -0
- package/dist/bundle/chunk-J5CXR6VX.js +63 -0
- package/dist/bundle/chunk-J5PWSTOX.js +82 -0
- package/dist/bundle/chunk-J7BVAEHR.js +364 -0
- package/dist/bundle/chunk-JH46HMZW.js +1334 -0
- package/dist/bundle/chunk-JOBO7F6W.js +52 -0
- package/dist/bundle/chunk-JXZ5B3L5.js +2333 -0
- package/dist/bundle/chunk-KBIAMDZN.js +66 -0
- package/dist/bundle/chunk-KFVDL2QS.js +146 -0
- package/dist/bundle/chunk-LNHTLSR5.js +288 -0
- package/dist/bundle/chunk-M24RAKMJ.js +58 -0
- package/dist/bundle/chunk-MDQ57Q3H.js +1197 -0
- package/dist/bundle/chunk-MGUEZYFA.js +5546 -0
- package/dist/bundle/chunk-MLXQ4X5L.js +206 -0
- package/dist/bundle/chunk-NQAKARHE.js +54 -0
- package/dist/bundle/chunk-OF7VVUDQ.js +23 -0
- package/dist/bundle/chunk-OQVPE3XK.js +324 -0
- package/dist/bundle/chunk-OR3QG7UR.js +259 -0
- package/dist/bundle/chunk-OUUYVROP.js +76 -0
- package/dist/bundle/chunk-PQBAM64O.js +168 -0
- package/dist/bundle/chunk-PYVIA7WF.js +88 -0
- package/dist/bundle/chunk-Q6HK3PHE.js +72 -0
- package/dist/bundle/chunk-QB3KECV2.js +218 -0
- package/dist/bundle/chunk-QGWXSFYN.js +73 -0
- package/dist/bundle/chunk-RC5QAAAE.js +29 -0
- package/dist/bundle/chunk-RMJ26HLB.js +18 -0
- package/dist/bundle/chunk-S4UUN6LD.js +1410 -0
- package/dist/bundle/chunk-T7ZUDA4C.js +72 -0
- package/dist/bundle/chunk-TRCSMVV5.js +72 -0
- package/dist/bundle/chunk-UD2BQEKA.js +46 -0
- package/dist/bundle/chunk-V4TL55GS.js +1068 -0
- package/dist/bundle/chunk-VJNWN5VU.js +4072 -0
- package/dist/bundle/chunk-VRRNBLMA.js +1227 -0
- package/dist/bundle/chunk-WUCMMNFJ.js +771 -0
- package/dist/bundle/chunk-XDESE3NY.js +44 -0
- package/dist/bundle/chunk-XFLCVHSQ.js +50 -0
- package/dist/bundle/chunk-XQUUANA2.js +24600 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-Z2QEON7B.js +2275 -0
- package/dist/bundle/chunk-ZMJ56GME.js +7 -0
- package/dist/bundle/chunk-ZTSB3D7Q.js +100 -0
- package/dist/bundle/chunk-ZVJWD3FK.js +38 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/command-contract-YIOYGPJA.js +40 -0
- package/dist/bundle/command-server-entry-MHBQDXS4.js +169 -0
- package/dist/bundle/decode-NUGJIOUW.js +297 -0
- package/dist/bundle/definitions-AILHKEQT.js +2005 -0
- package/dist/bundle/dispatch-5LC4UEGY.js +411 -0
- package/dist/bundle/dist-4I2W6X2I.js +7577 -0
- package/dist/bundle/echarts-MHSH6PGC.js +42501 -0
- package/dist/bundle/embed-ZDXTHHYS.js +38 -0
- package/dist/bundle/embedder-XFEELFUL.js +111 -0
- package/dist/bundle/failure-5S7VPBYK.js +25 -0
- package/dist/bundle/first-run-JHCHT3RJ.js +29 -0
- package/dist/bundle/first-screen-FHGQ6QRV.js +40 -0
- package/dist/bundle/instructions-WKSMBUFX.js +11 -0
- package/dist/bundle/mcp-HS2ZDUVR.js +167 -0
- package/dist/bundle/mdast-util-from-markdown-R66F4HZA.js +1958 -0
- package/dist/bundle/mdast-util-gfm-LN2ELINH.js +2699 -0
- package/dist/bundle/meeting-combined-K4U4NYRZ.js +25 -0
- package/dist/bundle/meeting-model-KCEG6Y5O.js +26 -0
- package/dist/bundle/meeting-semantic-VYGSV3H6.js +22 -0
- package/dist/bundle/micromark-extension-gfm-5X7YT43T.js +1838 -0
- package/dist/bundle/node-CM6NC6UE.js +176 -0
- package/dist/bundle/node-KM3CUABH.js +2340 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-sqlite-5YDQ3LIJ.js +74 -0
- package/dist/bundle/notes-search-PGO7KM2U.js +62 -0
- package/dist/bundle/oauth-NY4C5UCK.js +20 -0
- package/dist/bundle/open-YNUTA6ZE.js +23 -0
- package/dist/bundle/openai-4CVT5PHH.js +241 -0
- package/dist/bundle/process-2XT3TL27.js +91 -0
- package/dist/bundle/program-FMIVF5T6.js +31904 -0
- package/dist/bundle/prompt-VNWY3H6S.js +17 -0
- package/dist/bundle/recognize-JS4PBPSZ.js +26 -0
- package/dist/bundle/remote-RCLFH4V2.js +32 -0
- package/dist/bundle/rerank-EG6VKYGO.js +52 -0
- package/dist/bundle/schemas-ED2LHKXK.js +645 -0
- package/dist/bundle/serve-AHG25QXB.js +199 -0
- package/dist/bundle/server-5FTB7WM3.js +78 -0
- package/dist/bundle/server-JNZVSAZE.js +209 -0
- package/dist/bundle/sqlite-runtime-XSZOAQPF.js +20 -0
- package/dist/bundle/state-XGVAJFF7.js +36 -0
- package/dist/bundle/store-OHSCWZEV.js +177 -0
- package/dist/bundle/store-PKSPKJXL.js +293 -0
- package/dist/bundle/store-maintenance-command-KAWGBSWK.js +69 -0
- package/dist/bundle/ydisk.js +183 -0
- package/dist/commands/api.d.ts +9 -0
- package/dist/commands/api.d.ts.map +1 -0
- package/dist/commands/api.js +59 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/comments.d.ts +3 -0
- package/dist/commands/comments.d.ts.map +1 -0
- package/dist/commands/comments.js +114 -0
- package/dist/commands/comments.js.map +1 -0
- package/dist/commands/files.d.ts +3 -0
- package/dist/commands/files.d.ts.map +1 -0
- package/dist/commands/files.js +272 -0
- package/dist/commands/files.js.map +1 -0
- package/dist/commands/library.d.ts +13 -0
- package/dist/commands/library.d.ts.map +1 -0
- package/dist/commands/library.js +118 -0
- package/dist/commands/library.js.map +1 -0
- package/dist/commands/session.d.ts +3 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +99 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/config.d.ts +18 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +62 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +80 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +77 -0
- package/dist/context.js.map +1 -0
- package/dist/generated/definitions.d.ts +3 -0
- package/dist/generated/definitions.d.ts.map +1 -0
- package/dist/generated/definitions.js +2001 -0
- package/dist/generated/definitions.js.map +1 -0
- package/dist/generated/manifest.d.ts +6 -0
- package/dist/generated/manifest.d.ts.map +1 -0
- package/dist/generated/manifest.js +1473 -0
- package/dist/generated/manifest.js.map +1 -0
- package/dist/generated/schemas.d.ts +127 -0
- package/dist/generated/schemas.d.ts.map +1 -0
- package/dist/generated/schemas.js +545 -0
- package/dist/generated/schemas.js.map +1 -0
- package/dist/generated/types.d.ts +829 -0
- package/dist/generated/types.d.ts.map +1 -0
- package/dist/generated/types.js +5 -0
- package/dist/generated/types.js.map +1 -0
- package/dist/identity.d.ts +10 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +33 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/program.d.ts +6 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +65 -0
- package/dist/program.js.map +1 -0
- package/dist/sample/comments.d.ts +61 -0
- package/dist/sample/comments.d.ts.map +1 -0
- package/dist/sample/comments.js +39 -0
- package/dist/sample/comments.js.map +1 -0
- package/dist/sample/records.d.ts +16 -0
- package/dist/sample/records.d.ts.map +1 -0
- package/dist/sample/records.js +22 -0
- package/dist/sample/records.js.map +1 -0
- package/dist/sample/transport.d.ts +42 -0
- package/dist/sample/transport.d.ts.map +1 -0
- package/dist/sample/transport.js +153 -0
- package/dist/sample/transport.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/dist/wcat.d.ts +3 -0
- package/dist/wcat.d.ts.map +1 -0
- package/dist/wcat.js +4 -0
- package/dist/wcat.js.map +1 -0
- package/dist/yandex/source.d.ts +39 -0
- package/dist/yandex/source.d.ts.map +1 -0
- package/dist/yandex/source.js +189 -0
- package/dist/yandex/source.js.map +1 -0
- package/dist/yandex/transport.d.ts +41 -0
- package/dist/yandex/transport.d.ts.map +1 -0
- package/dist/yandex/transport.js +152 -0
- package/dist/yandex/transport.js.map +1 -0
- package/dist/yandex/writes.d.ts +27 -0
- package/dist/yandex/writes.d.ts.map +1 -0
- package/dist/yandex/writes.js +61 -0
- package/dist/yandex/writes.js.map +1 -0
- package/package.json +88 -4
- package/skills/yandex-disk-cli/SKILL.md +46 -0
- package/skills/yandex-disk-cli/references/api/api-disk-operations-operation-id.md +13 -0
- package/skills/yandex-disk-cli/references/api/api-disk-public-resources.md +50 -0
- package/skills/yandex-disk-cli/references/api/api-disk-resources.md +171 -0
- package/skills/yandex-disk-cli/references/api/api-disk-trash-resources.md +48 -0
- package/skills/yandex-disk-cli/references/api/api-disk.md +13 -0
- package/skills/yandex-disk-cli/references/api.md +17 -0
|
@@ -0,0 +1,2275 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
safeName
|
|
5
|
+
} from "./chunk-BH7LFEX7.js";
|
|
6
|
+
import {
|
|
7
|
+
EmptyAnswer,
|
|
8
|
+
checkedOptions,
|
|
9
|
+
messagesFor,
|
|
10
|
+
range,
|
|
11
|
+
systemFor,
|
|
12
|
+
validateImages
|
|
13
|
+
} from "./chunk-OUUYVROP.js";
|
|
14
|
+
import {
|
|
15
|
+
questionLookup,
|
|
16
|
+
questionText
|
|
17
|
+
} from "./chunk-PQBAM64O.js";
|
|
18
|
+
import {
|
|
19
|
+
ANSWER_RESERVE_MS,
|
|
20
|
+
DEFAULT_IMAGE_MODEL,
|
|
21
|
+
codeOf,
|
|
22
|
+
deadlineMargin,
|
|
23
|
+
envName,
|
|
24
|
+
imageModel,
|
|
25
|
+
imageModelsDirectory,
|
|
26
|
+
isImageModelInstalled
|
|
27
|
+
} from "./chunk-IOXR2QBX.js";
|
|
28
|
+
import {
|
|
29
|
+
DEFAULT_TEXT_MODEL,
|
|
30
|
+
PREVIOUS_DEFAULT_TEXT_MODEL,
|
|
31
|
+
chosenTextModel,
|
|
32
|
+
meaningFloor,
|
|
33
|
+
textModel,
|
|
34
|
+
textModels,
|
|
35
|
+
vectorModelKey
|
|
36
|
+
} from "./chunk-BC5HGIXB.js";
|
|
37
|
+
import {
|
|
38
|
+
chatReferenceOf,
|
|
39
|
+
chatsMatching,
|
|
40
|
+
ensureAccount,
|
|
41
|
+
hasStems,
|
|
42
|
+
isId,
|
|
43
|
+
nearest,
|
|
44
|
+
peopleMatching,
|
|
45
|
+
pickChat,
|
|
46
|
+
pickPerson,
|
|
47
|
+
profilesOn
|
|
48
|
+
} from "./chunk-GGRKWAOK.js";
|
|
49
|
+
import {
|
|
50
|
+
DEFAULT_STEMMERS,
|
|
51
|
+
createStemmer
|
|
52
|
+
} from "./chunk-JXZ5B3L5.js";
|
|
53
|
+
import {
|
|
54
|
+
RRF_K,
|
|
55
|
+
SEARCH_QUERY,
|
|
56
|
+
isQueryLimit,
|
|
57
|
+
plainQuery,
|
|
58
|
+
validateFields
|
|
59
|
+
} from "./chunk-WUCMMNFJ.js";
|
|
60
|
+
import {
|
|
61
|
+
normalize
|
|
62
|
+
} from "./chunk-E6LGZ5LX.js";
|
|
63
|
+
import {
|
|
64
|
+
INTERNAL_NOTES,
|
|
65
|
+
accountsOfList,
|
|
66
|
+
entriesOfList,
|
|
67
|
+
fitting,
|
|
68
|
+
formatLocator,
|
|
69
|
+
holdsKindOf,
|
|
70
|
+
isAccountList,
|
|
71
|
+
isDocumentAccountProvider,
|
|
72
|
+
isFolderProvider,
|
|
73
|
+
isGroupName,
|
|
74
|
+
isImportedProvider,
|
|
75
|
+
isKind,
|
|
76
|
+
keyOf,
|
|
77
|
+
providerNamed,
|
|
78
|
+
sameAs,
|
|
79
|
+
sourceOf2 as sourceOf,
|
|
80
|
+
typedCommand
|
|
81
|
+
} from "./chunk-VRRNBLMA.js";
|
|
82
|
+
import {
|
|
83
|
+
isCliFailure,
|
|
84
|
+
sqliteCode
|
|
85
|
+
} from "./chunk-TRCSMVV5.js";
|
|
86
|
+
import {
|
|
87
|
+
normalizeTag
|
|
88
|
+
} from "./chunk-RC5QAAAE.js";
|
|
89
|
+
import {
|
|
90
|
+
dateRange,
|
|
91
|
+
parseLucene,
|
|
92
|
+
timezoneOf
|
|
93
|
+
} from "./chunk-VJNWN5VU.js";
|
|
94
|
+
import {
|
|
95
|
+
localOnly,
|
|
96
|
+
refuseOffComputer
|
|
97
|
+
} from "./chunk-Q6HK3PHE.js";
|
|
98
|
+
import {
|
|
99
|
+
PLAIN_HTTP_REFUSED,
|
|
100
|
+
endpoint,
|
|
101
|
+
endpointFetch,
|
|
102
|
+
modelAddressAllowed,
|
|
103
|
+
onThisComputer
|
|
104
|
+
} from "./chunk-CNIA2LJF.js";
|
|
105
|
+
import {
|
|
106
|
+
readSharedSection,
|
|
107
|
+
sharedConfigPath,
|
|
108
|
+
writeSharedSection
|
|
109
|
+
} from "./chunk-MDQ57Q3H.js";
|
|
110
|
+
import {
|
|
111
|
+
defaultThreads,
|
|
112
|
+
isTextModelInstalled,
|
|
113
|
+
openEmbedder,
|
|
114
|
+
textModelsDirectory
|
|
115
|
+
} from "./chunk-FDDAUASC.js";
|
|
116
|
+
import {
|
|
117
|
+
storePath
|
|
118
|
+
} from "./chunk-NQAKARHE.js";
|
|
119
|
+
import {
|
|
120
|
+
Credentials,
|
|
121
|
+
pathsAreOverridden,
|
|
122
|
+
resolvePaths
|
|
123
|
+
} from "./chunk-762BS35H.js";
|
|
124
|
+
import {
|
|
125
|
+
array,
|
|
126
|
+
check,
|
|
127
|
+
getDotPath,
|
|
128
|
+
integer,
|
|
129
|
+
isoTimestamp,
|
|
130
|
+
maxLength,
|
|
131
|
+
minLength,
|
|
132
|
+
minValue,
|
|
133
|
+
number,
|
|
134
|
+
object,
|
|
135
|
+
optional,
|
|
136
|
+
parse,
|
|
137
|
+
picklist,
|
|
138
|
+
pipe,
|
|
139
|
+
safeParse,
|
|
140
|
+
strictObject,
|
|
141
|
+
string,
|
|
142
|
+
transform,
|
|
143
|
+
trim,
|
|
144
|
+
union,
|
|
145
|
+
unknown
|
|
146
|
+
} from "./chunk-S4UUN6LD.js";
|
|
147
|
+
import {
|
|
148
|
+
CliError,
|
|
149
|
+
singleLine
|
|
150
|
+
} from "./chunk-T7ZUDA4C.js";
|
|
151
|
+
import {
|
|
152
|
+
__name
|
|
153
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
154
|
+
|
|
155
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/search/groups.js
|
|
156
|
+
var ALL = "all";
|
|
157
|
+
var OWNER_NOTES = { provider: "notes", account: INTERNAL_NOTES };
|
|
158
|
+
var NOT_GROUP_NAMES = /* @__PURE__ */ new Set([ALL, "bots"]);
|
|
159
|
+
var hasGroup = /* @__PURE__ */ __name((groups, name) => Object.hasOwn(groups, name), "hasGroup");
|
|
160
|
+
var membersOf = /* @__PURE__ */ __name((entries, context, unresolved) => {
|
|
161
|
+
const members = /* @__PURE__ */ new Map();
|
|
162
|
+
for (const entry of entries)
|
|
163
|
+
try {
|
|
164
|
+
for (const { provider, account } of accountsOfList(entry, context)) {
|
|
165
|
+
const known = members.get(keyOf({ provider, account }));
|
|
166
|
+
if (known)
|
|
167
|
+
known.entries.push(entry);
|
|
168
|
+
else
|
|
169
|
+
members.set(keyOf({ provider, account }), {
|
|
170
|
+
provider,
|
|
171
|
+
account,
|
|
172
|
+
entries: [entry],
|
|
173
|
+
reason: "setting",
|
|
174
|
+
profiles: [],
|
|
175
|
+
also_in: []
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if (!(error instanceof CliError))
|
|
180
|
+
throw error;
|
|
181
|
+
unresolved.push(entry);
|
|
182
|
+
}
|
|
183
|
+
return [...members.values()];
|
|
184
|
+
}, "membersOf");
|
|
185
|
+
var groupMembership = /* @__PURE__ */ __name((context) => {
|
|
186
|
+
const plain = { ...context, groups: {} };
|
|
187
|
+
const unresolved = [];
|
|
188
|
+
const groups = {};
|
|
189
|
+
for (const [name, entries] of Object.entries(context.groups))
|
|
190
|
+
if (name !== ALL)
|
|
191
|
+
groups[name] = membersOf(entries, plain, unresolved);
|
|
192
|
+
const system = [OWNER_NOTES, ...context.held.filter(({ id }) => id === 0)].map(keyOf);
|
|
193
|
+
const every = accountsOfList(ALL, plain).filter((one) => !system.includes(keyOf(one))).map(({ provider, account }) => ({
|
|
194
|
+
provider,
|
|
195
|
+
account,
|
|
196
|
+
entries: [sourceOf({ provider, account })],
|
|
197
|
+
reason: "all",
|
|
198
|
+
profiles: [],
|
|
199
|
+
also_in: []
|
|
200
|
+
}));
|
|
201
|
+
const recorded = Object.entries(context.profiles).flatMap(([app, named]) => Object.entries(named).map(([profile, key]) => ({ app, profile, key })));
|
|
202
|
+
const holding = /* @__PURE__ */ new Map();
|
|
203
|
+
for (const [name, members] of Object.entries(groups))
|
|
204
|
+
for (const one of members)
|
|
205
|
+
holding.set(keyOf(one), [...holding.get(keyOf(one)) ?? [], name]);
|
|
206
|
+
for (const [name, members] of [...Object.entries(groups), [ALL, every]])
|
|
207
|
+
for (const one of members) {
|
|
208
|
+
one.scope = context.held.find(sameAs(one))?.scope ?? "personal";
|
|
209
|
+
one.profiles = recorded.filter(({ key }) => sameAs(key)(one)).map(({ app, profile }) => `${app} ${profile}`);
|
|
210
|
+
one.also_in = (holding.get(keyOf(one)) ?? []).filter((other) => other !== name);
|
|
211
|
+
}
|
|
212
|
+
const duplicates = [...holding.entries()].filter(([, names]) => names.length > 1).map(([key, names]) => ({ member: key.replace("\0", ":"), groups: names }));
|
|
213
|
+
const shared = /* @__PURE__ */ __name((app, profile) => hasGroup(context.groups, profile) || recorded.some((other) => other.app !== app && other.profile === profile), "shared");
|
|
214
|
+
const suggested = recorded.filter(({ app, profile, key }) => isGroupName(profile) && !NOT_GROUP_NAMES.has(profile.toLowerCase()) && shared(app, profile) && !holding.get(keyOf(key))?.includes(profile)).map(({ app, profile, key }) => ({
|
|
215
|
+
group: profile,
|
|
216
|
+
member: sourceOf(key),
|
|
217
|
+
because: `profile named ${profile} (${app} ${profile})`
|
|
218
|
+
}));
|
|
219
|
+
return { groups: { ...groups, [ALL]: every }, duplicates, suggested, unresolved };
|
|
220
|
+
}, "groupMembership");
|
|
221
|
+
var inGroupOf = /* @__PURE__ */ __name((context, group) => (key) => group === ALL || (hasGroup(context.membership.groups, group) ? context.membership.groups[group] ?? [] : []).some(sameAs(key)), "inGroupOf");
|
|
222
|
+
var groupEntries = /* @__PURE__ */ __name((saved) => ({
|
|
223
|
+
...Object.fromEntries(Object.entries(saved).filter(([name]) => name !== ALL)),
|
|
224
|
+
[ALL]: [ALL]
|
|
225
|
+
}), "groupEntries");
|
|
226
|
+
|
|
227
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/search/lucene/meaning-parts.js
|
|
228
|
+
var WORD_FIELDS = /* @__PURE__ */ new Set(["text", "exact"]);
|
|
229
|
+
var fieldsOfQuery = /* @__PURE__ */ __name((root, everything) => {
|
|
230
|
+
let narrows = false;
|
|
231
|
+
const kept = /* @__PURE__ */ __name((node) => {
|
|
232
|
+
if (node.kind === "boolean")
|
|
233
|
+
return {
|
|
234
|
+
...node,
|
|
235
|
+
clauses: node.clauses.map(({ occur, node: node2 }) => {
|
|
236
|
+
if (occur !== "must_not")
|
|
237
|
+
return { occur, node: kept(node2) };
|
|
238
|
+
narrows = true;
|
|
239
|
+
return { occur, node: node2 };
|
|
240
|
+
})
|
|
241
|
+
};
|
|
242
|
+
if (!WORD_FIELDS.has(node.field)) {
|
|
243
|
+
narrows = true;
|
|
244
|
+
return node;
|
|
245
|
+
}
|
|
246
|
+
return { ...everything, span: node.span };
|
|
247
|
+
}, "kept");
|
|
248
|
+
const fields = kept(root);
|
|
249
|
+
return narrows ? fields : void 0;
|
|
250
|
+
}, "fieldsOfQuery");
|
|
251
|
+
var meaningWords = /* @__PURE__ */ __name((root) => {
|
|
252
|
+
const wanted = /* @__PURE__ */ __name((node) => node.kind === "boolean" ? node.clauses.flatMap(({ occur, node: node2 }) => occur === "must_not" ? [] : wanted(node2)) : WORD_FIELDS.has(node.field) && (node.operator === "term" || node.operator === "phrase") ? [node.value] : [], "wanted");
|
|
253
|
+
return wanted(root).join(" ").trim();
|
|
254
|
+
}, "meaningWords");
|
|
255
|
+
|
|
256
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/search/total.js
|
|
257
|
+
var TOTAL_CAP = 1e4;
|
|
258
|
+
var totalOf = /* @__PURE__ */ __name((count, shown, hasMore, exact = true) => {
|
|
259
|
+
const least = shown + (hasMore ? 1 : 0);
|
|
260
|
+
if (count === void 0 || count < least)
|
|
261
|
+
return { value: least, relation: "gte" };
|
|
262
|
+
if (count > TOTAL_CAP)
|
|
263
|
+
return { value: TOTAL_CAP, relation: "gte" };
|
|
264
|
+
return { value: count, relation: exact ? "eq" : "gte" };
|
|
265
|
+
}, "totalOf");
|
|
266
|
+
|
|
267
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/services/document-pictures.js
|
|
268
|
+
var openPictureEmbedderFor = /* @__PURE__ */ __name(async ({ env, command } = {}) => {
|
|
269
|
+
const model = imageModel(DEFAULT_IMAGE_MODEL);
|
|
270
|
+
const directory = imageModelsDirectory(env);
|
|
271
|
+
if (!isImageModelInstalled(model, directory))
|
|
272
|
+
throw new CliError("not_found", `the picture model is not downloaded \u2014 ${command === void 0 ? "install it with a WireCat CLI that has `images models download` (tg, max or wa); they share the model folder" : `\`${command} images models download ${model.id}\` fetches it`}`, { reason: "model.not-downloaded", model: model.id });
|
|
273
|
+
const { openPictureEmbedder } = await import("./embedder-XFEELFUL.js");
|
|
274
|
+
return openPictureEmbedder(model, directory);
|
|
275
|
+
}, "openPictureEmbedderFor");
|
|
276
|
+
|
|
277
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/services/document-source.js
|
|
278
|
+
var documentSource = /* @__PURE__ */ __name((note, accounts, profiles, file) => {
|
|
279
|
+
const metadata = note.frontMatter;
|
|
280
|
+
const account = accounts.find(({ id }) => String(id) === note.folderId);
|
|
281
|
+
if (note.source === "file" && account !== void 0 && isImportedProvider(account.provider))
|
|
282
|
+
return {
|
|
283
|
+
kind: "document",
|
|
284
|
+
provider: account.provider,
|
|
285
|
+
account: account.account,
|
|
286
|
+
...file?.url ? { url: file.url } : {}
|
|
287
|
+
};
|
|
288
|
+
const remote = note.source === "file" && (account !== void 0 && isDocumentAccountProvider(account.provider) || isDocumentAccountProvider(metadata?.source));
|
|
289
|
+
const profile = remote && account ? Object.entries(profiles).flatMap(([command, named]) => Object.entries(named).map(([name, key]) => ({ command, name, key }))).find(({ key }) => key.provider === account.provider && key.account === account.account || isFolderProvider(key.provider) && key.account === account.name) : void 0;
|
|
290
|
+
const url = file?.url ?? (remote && typeof metadata?.sourceUrl === "string" ? metadata.sourceUrl : void 0);
|
|
291
|
+
return {
|
|
292
|
+
kind: remote ? "document" : "note",
|
|
293
|
+
provider: profile ? profile.command : "notes",
|
|
294
|
+
account: profile?.name ?? note.folderId ?? "internal",
|
|
295
|
+
...remote && url !== void 0 ? { url } : {}
|
|
296
|
+
};
|
|
297
|
+
}, "documentSource");
|
|
298
|
+
|
|
299
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/embeddings/keys.js
|
|
300
|
+
var endpointKeyName = /* @__PURE__ */ __name((baseUrl) => {
|
|
301
|
+
const host = new URL(baseUrl).host;
|
|
302
|
+
return ["openai", "anthropic"].includes(host) ? `endpoint:${host}` : host;
|
|
303
|
+
}, "endpointKeyName");
|
|
304
|
+
var embeddingKeys = /* @__PURE__ */ __name((app, env = process.env, keyring) => {
|
|
305
|
+
const where = { appName: app.appName, prefix: app.envPrefix, env };
|
|
306
|
+
const credentials = /* @__PURE__ */ __name((provider) => new Credentials({
|
|
307
|
+
configDir: resolvePaths(where).config,
|
|
308
|
+
service: app.appName,
|
|
309
|
+
...["openai", "anthropic"].includes(provider) ? { envVar: envName(app, `${provider.toUpperCase()}_API_KEY`) } : {},
|
|
310
|
+
isolated: pathsAreOverridden(where),
|
|
311
|
+
env,
|
|
312
|
+
...keyring ? { keyring } : {},
|
|
313
|
+
warn: /* @__PURE__ */ __name((message) => process.stderr.write(`${message}
|
|
314
|
+
`), "warn")
|
|
315
|
+
}), "credentials");
|
|
316
|
+
const account = /* @__PURE__ */ __name((provider) => `embeddings:${provider}`, "account");
|
|
317
|
+
return {
|
|
318
|
+
read: /* @__PURE__ */ __name((provider) => {
|
|
319
|
+
const stored = credentials(provider).read(account(provider));
|
|
320
|
+
if (stored)
|
|
321
|
+
return { key: stored.secret, source: stored.source };
|
|
322
|
+
const shared = ["openai", "anthropic"].includes(provider) ? env[`${provider.toUpperCase()}_API_KEY`]?.trim() : void 0;
|
|
323
|
+
return shared ? { key: shared, source: "env" } : void 0;
|
|
324
|
+
}, "read"),
|
|
325
|
+
/** A key kept under the provider's own name, as an owner may have stored it by hand for the whole tool. */
|
|
326
|
+
readPlain: /* @__PURE__ */ __name((provider) => credentials(provider).read(provider)?.secret, "readPlain"),
|
|
327
|
+
write: /* @__PURE__ */ __name((provider, key) => credentials(provider).write(account(provider), key, { signIn: true }), "write"),
|
|
328
|
+
remove: /* @__PURE__ */ __name((provider) => credentials(provider).remove(account(provider)), "remove")
|
|
329
|
+
};
|
|
330
|
+
}, "embeddingKeys");
|
|
331
|
+
|
|
332
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/http/time-limit.js
|
|
333
|
+
var timeLimit = /* @__PURE__ */ __name((ms) => {
|
|
334
|
+
const controller = new AbortController();
|
|
335
|
+
const timer = setTimeout(() => controller.abort(new DOMException("The operation timed out.", "TimeoutError")), ms);
|
|
336
|
+
timer.unref();
|
|
337
|
+
return { signal: controller.signal, clear: /* @__PURE__ */ __name(() => clearTimeout(timer), "clear") };
|
|
338
|
+
}, "timeLimit");
|
|
339
|
+
var withTimeLimit = /* @__PURE__ */ __name(async (ms, run) => {
|
|
340
|
+
const limit = timeLimit(ms);
|
|
341
|
+
try {
|
|
342
|
+
return await run(limit.signal);
|
|
343
|
+
} finally {
|
|
344
|
+
limit.clear();
|
|
345
|
+
}
|
|
346
|
+
}, "withTimeLimit");
|
|
347
|
+
|
|
348
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/models/openai.js
|
|
349
|
+
var options = strictObject({
|
|
350
|
+
temperature: range(0, 2),
|
|
351
|
+
top_p: range(0, 1),
|
|
352
|
+
presence_penalty: range(-2, 2),
|
|
353
|
+
frequency_penalty: range(-2, 2),
|
|
354
|
+
seed: optional(pipe(number(), integer())),
|
|
355
|
+
stop: optional(union([string(), array(string())])),
|
|
356
|
+
response_format: optional(strictObject({ type: picklist(["text", "json_object"]) }))
|
|
357
|
+
});
|
|
358
|
+
var openai = {
|
|
359
|
+
images: true,
|
|
360
|
+
baseUrl: "https://api.openai.com/v1",
|
|
361
|
+
validate: /* @__PURE__ */ __name((given) => checkedOptions("openai", options, given), "validate"),
|
|
362
|
+
complete: /* @__PURE__ */ __name((target, request, checked, apiKey, fetcher) => withTimeLimit(12e4, async (deadline) => {
|
|
363
|
+
const response = await fetcher(`${target.baseUrl.replace(/\/+$/, "")}/chat/completions`, {
|
|
364
|
+
method: "POST",
|
|
365
|
+
headers: { "Content-Type": "application/json", ...apiKey ? { Authorization: `Bearer ${apiKey}` } : {} },
|
|
366
|
+
body: JSON.stringify({
|
|
367
|
+
...checked,
|
|
368
|
+
model: target.model,
|
|
369
|
+
messages: [
|
|
370
|
+
{ role: "system", content: systemFor(request) },
|
|
371
|
+
...messagesFor(request),
|
|
372
|
+
...request.images === void 0 ? [] : [
|
|
373
|
+
{
|
|
374
|
+
role: "user",
|
|
375
|
+
content: [
|
|
376
|
+
{ type: "text", text: request.prompt },
|
|
377
|
+
...request.images.map((image) => ({
|
|
378
|
+
type: "image_url",
|
|
379
|
+
image_url: { url: `data:${image.mimeType};base64,${image.data}`, detail: "high" }
|
|
380
|
+
}))
|
|
381
|
+
]
|
|
382
|
+
}
|
|
383
|
+
]
|
|
384
|
+
],
|
|
385
|
+
...new URL(target.baseUrl).hostname === "api.openai.com" ? { max_completion_tokens: request.maxTokens } : { max_tokens: request.maxTokens }
|
|
386
|
+
}),
|
|
387
|
+
signal: deadline,
|
|
388
|
+
redirect: "error"
|
|
389
|
+
});
|
|
390
|
+
if (!response.ok)
|
|
391
|
+
throw new Error("provider rejected request");
|
|
392
|
+
const body = await response.json();
|
|
393
|
+
const choice = body.choices?.[0];
|
|
394
|
+
const content = choice?.message?.content;
|
|
395
|
+
const total = body.usage?.total_tokens;
|
|
396
|
+
const counted = Number.isInteger(total) && (total ?? 0) >= 1;
|
|
397
|
+
const local = onThisComputer(target.baseUrl);
|
|
398
|
+
const finish = choice?.finish_reason ?? null;
|
|
399
|
+
if (finish !== "stop" && !(local && finish === null))
|
|
400
|
+
throw new Error("incomplete response");
|
|
401
|
+
if (typeof content !== "string" || content.trim() === "")
|
|
402
|
+
throw new EmptyAnswer();
|
|
403
|
+
if (!counted && !local)
|
|
404
|
+
throw new Error("incomplete response");
|
|
405
|
+
const { prompt_tokens: input, completion_tokens: output } = body.usage ?? {};
|
|
406
|
+
return {
|
|
407
|
+
text: content,
|
|
408
|
+
// No count from a server on this computer costs nothing; a rough one keeps the gateway's check meaningful.
|
|
409
|
+
tokens: counted ? total : Math.max(1, Math.ceil(content.length / 4)),
|
|
410
|
+
...Number.isInteger(input) && Number.isInteger(output) ? { usage: { input, output } } : {}
|
|
411
|
+
};
|
|
412
|
+
}), "complete")
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/models/index.js
|
|
416
|
+
var modelGateway = /* @__PURE__ */ __name((deps) => ({
|
|
417
|
+
complete: /* @__PURE__ */ __name(async (request) => {
|
|
418
|
+
if (deps.signal?.aborted)
|
|
419
|
+
throw new CliError("cancelled", "model request cancelled");
|
|
420
|
+
const target = deps.resolve(request.purpose);
|
|
421
|
+
if (!target || target.provider === "off")
|
|
422
|
+
throw new CliError("configuration_error", `models.${request.purpose}.provider is not configured; no model was called`);
|
|
423
|
+
if (!request.purpose || !Number.isSafeInteger(request.maxTokens) || request.maxTokens < 1 || typeof request.prompt !== "string")
|
|
424
|
+
throw new CliError("validation_error", "a model request needs a purpose, prompt and positive whole maxTokens");
|
|
425
|
+
validateImages(request.images);
|
|
426
|
+
let adapter = deps.adapters?.[target.provider];
|
|
427
|
+
if (!adapter && target.provider === "openai")
|
|
428
|
+
adapter = openai;
|
|
429
|
+
if (!adapter && target.provider === "anthropic")
|
|
430
|
+
adapter = (await import("./anthropic-DKB4OJXZ.js")).anthropic;
|
|
431
|
+
if (!adapter)
|
|
432
|
+
throw new CliError("validation_error", `no model adapter for ${target.provider}`);
|
|
433
|
+
if (request.images !== void 0 && adapter.images !== true)
|
|
434
|
+
throw new CliError("validation_error", "the model adapter does not support image inputs");
|
|
435
|
+
const options2 = adapter.validate(request.options ?? {});
|
|
436
|
+
const baseUrl = target.baseUrl ?? adapter.baseUrl;
|
|
437
|
+
if (!target.model.trim() || !endpoint(baseUrl))
|
|
438
|
+
throw new CliError("validation_error", "a model target needs a model and an HTTP/S endpoint without credentials, query or fragment");
|
|
439
|
+
if (!modelAddressAllowed(baseUrl))
|
|
440
|
+
throw new CliError("validation_error", `${PLAIN_HTTP_REFUSED}; no data was sent`, {
|
|
441
|
+
reason: "model.address-refused"
|
|
442
|
+
});
|
|
443
|
+
refuseOffComputer(deps.env ?? process.env, baseUrl, `${request.purpose} data`);
|
|
444
|
+
if (!await deps.consent(request, { ...target, baseUrl }))
|
|
445
|
+
throw new CliError("permission_error", `model consent for ${request.purpose} is missing; no data was sent`);
|
|
446
|
+
const apiKey = await deps.key?.(target.provider, target);
|
|
447
|
+
if (deps.signal?.aborted)
|
|
448
|
+
throw new CliError("cancelled", "model request cancelled");
|
|
449
|
+
const fetcher = deps.fetch ?? endpointFetch(baseUrl, 12e4);
|
|
450
|
+
let limited = false;
|
|
451
|
+
let unreachable = false;
|
|
452
|
+
let refused = false;
|
|
453
|
+
let status;
|
|
454
|
+
const cancellable = /* @__PURE__ */ __name(async (input, init) => {
|
|
455
|
+
const signal = init?.signal ?? (input instanceof Request ? input.signal : void 0);
|
|
456
|
+
let response;
|
|
457
|
+
try {
|
|
458
|
+
response = await fetcher(input, {
|
|
459
|
+
...init,
|
|
460
|
+
signal: deps.signal ? AbortSignal.any([deps.signal, ...signal ? [signal] : []]) : signal
|
|
461
|
+
});
|
|
462
|
+
} catch (error) {
|
|
463
|
+
unreachable = true;
|
|
464
|
+
throw error;
|
|
465
|
+
}
|
|
466
|
+
if (!response.ok)
|
|
467
|
+
status = response.status;
|
|
468
|
+
if (response.status === 429)
|
|
469
|
+
limited = true;
|
|
470
|
+
if (response.status === 401 || response.status === 403)
|
|
471
|
+
refused = true;
|
|
472
|
+
return response;
|
|
473
|
+
}, "cancellable");
|
|
474
|
+
try {
|
|
475
|
+
const answer = await adapter.complete({ ...target, baseUrl }, request, options2, apiKey, cancellable);
|
|
476
|
+
if (deps.signal?.aborted)
|
|
477
|
+
throw new Error("cancelled");
|
|
478
|
+
if (typeof answer.text !== "string" || !Number.isSafeInteger(answer.tokens) || answer.tokens < 1)
|
|
479
|
+
throw new Error("incomplete");
|
|
480
|
+
return { ...answer, provider: target.provider, model: target.model };
|
|
481
|
+
} catch (error) {
|
|
482
|
+
if (limited)
|
|
483
|
+
throw new CliError("rate_limited", `${request.purpose} provider rate limit reached; no result was stored`);
|
|
484
|
+
const reason = refused ? "model.key-rejected" : unreachable && !deps.signal?.aborted ? "model.unreachable" : error instanceof EmptyAnswer ? "model.empty-answer" : void 0;
|
|
485
|
+
throw new CliError("invalid_response", `${request.purpose} provider failed or returned an incomplete response; no result was stored`, reason === void 0 && status === void 0 ? void 0 : { ...reason === void 0 ? {} : { reason }, ...status === void 0 ? {} : { status } });
|
|
486
|
+
}
|
|
487
|
+
}, "complete")
|
|
488
|
+
}), "modelGateway");
|
|
489
|
+
|
|
490
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/services/enrichment-setting.js
|
|
491
|
+
var SECTION = "enrichment";
|
|
492
|
+
var ENRICHMENT_PROVIDERS = ["openai", "anthropic"];
|
|
493
|
+
var DEFAULT_BASE_URLS = {
|
|
494
|
+
openai: "https://api.openai.com/v1",
|
|
495
|
+
anthropic: "https://api.anthropic.com"
|
|
496
|
+
};
|
|
497
|
+
var MODEL_CHOICE = {
|
|
498
|
+
provider: picklist(ENRICHMENT_PROVIDERS),
|
|
499
|
+
model: pipe(string(), trim(), minLength(1), maxLength(200)),
|
|
500
|
+
base_url: optional(pipe(string(), check((value) => endpoint(value), "use an HTTP/S endpoint without credentials, query or fragment")))
|
|
501
|
+
};
|
|
502
|
+
var Setting = strictObject({
|
|
503
|
+
...MODEL_CHOICE,
|
|
504
|
+
/** When the owner agreed that records go to this provider and endpoint; the setting exists only with it. */
|
|
505
|
+
consented_at: pipe(string(), isoTimestamp())
|
|
506
|
+
});
|
|
507
|
+
var enrichmentSettingPath = /* @__PURE__ */ __name((env) => sharedConfigPath(storePath(env), env), "enrichmentSettingPath");
|
|
508
|
+
var readEnrichmentSetting = /* @__PURE__ */ __name((env) => {
|
|
509
|
+
const path = enrichmentSettingPath(env);
|
|
510
|
+
const section = readSharedSection(path, SECTION);
|
|
511
|
+
if (section === void 0 || section === null)
|
|
512
|
+
return void 0;
|
|
513
|
+
const checked = safeParse(Setting, section);
|
|
514
|
+
if (!checked.success)
|
|
515
|
+
throw new CliError("configuration_error", `${path}: enrichment.${getDotPath(checked.issues[0]) ?? "settings"} is invalid \u2014 ${checked.issues[0].message}`);
|
|
516
|
+
return checked.output;
|
|
517
|
+
}, "readEnrichmentSetting");
|
|
518
|
+
var writeEnrichmentSetting = /* @__PURE__ */ __name((env, setting) => writeSharedSection(enrichmentSettingPath(env), SECTION, setting === void 0 ? void 0 : parse(Setting, setting)), "writeEnrichmentSetting");
|
|
519
|
+
var enrichmentEndpoint = /* @__PURE__ */ __name((setting) => setting.base_url ?? DEFAULT_BASE_URLS[setting.provider], "enrichmentEndpoint");
|
|
520
|
+
var isEnrichmentProvider = /* @__PURE__ */ __name((value) => ENRICHMENT_PROVIDERS.includes(value), "isEnrichmentProvider");
|
|
521
|
+
var PRICES = {
|
|
522
|
+
"openai/gpt-4o-mini": {
|
|
523
|
+
input: 15e-8,
|
|
524
|
+
output: 6e-7,
|
|
525
|
+
source: "https://developers.openai.com/api/docs/pricing"
|
|
526
|
+
},
|
|
527
|
+
"anthropic/claude-haiku-5-5": {
|
|
528
|
+
input: 1e-7,
|
|
529
|
+
output: 5e-7,
|
|
530
|
+
source: "https://platform.claude.com/docs/en/about-claude/pricing"
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
var DEFAULT_OFFER = { provider: "openai", model: "gpt-4o-mini" };
|
|
534
|
+
var offeredModels = /* @__PURE__ */ __name(() => Object.entries(PRICES).map(([key, price]) => {
|
|
535
|
+
const [provider, model] = key.split("/");
|
|
536
|
+
return {
|
|
537
|
+
provider,
|
|
538
|
+
model,
|
|
539
|
+
default: provider === DEFAULT_OFFER.provider && model === DEFAULT_OFFER.model,
|
|
540
|
+
usd_per_million: {
|
|
541
|
+
input: Math.round(price.input * 1e8) / 100,
|
|
542
|
+
output: Math.round(price.output * 1e8) / 100
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
}), "offeredModels");
|
|
546
|
+
var enrichmentPrice = /* @__PURE__ */ __name((provider, model, baseUrl) => baseUrl === void 0 ? PRICES[`${provider}/${model}`] : void 0, "enrichmentPrice");
|
|
547
|
+
var OUTPUT_TOKENS_PER_RECORD = 70;
|
|
548
|
+
var PROMPT_TOKENS_PER_RECORD = 40;
|
|
549
|
+
var estimateEnrichment = /* @__PURE__ */ __name((records, chars, setting) => {
|
|
550
|
+
const input = Math.ceil(chars / 4) + records * PROMPT_TOKENS_PER_RECORD;
|
|
551
|
+
const output = records * OUTPUT_TOKENS_PER_RECORD;
|
|
552
|
+
const price = setting && enrichmentPrice(setting.provider, setting.model, setting.base_url);
|
|
553
|
+
return {
|
|
554
|
+
records,
|
|
555
|
+
input_tokens: input,
|
|
556
|
+
output_tokens: output,
|
|
557
|
+
usd: price ? Math.round((input * price.input + output * price.output) * 1e6) / 1e6 : null
|
|
558
|
+
};
|
|
559
|
+
}, "estimateEnrichment");
|
|
560
|
+
var costOf = /* @__PURE__ */ __name((usage, setting) => {
|
|
561
|
+
const price = enrichmentPrice(setting.provider, setting.model, setting.base_url);
|
|
562
|
+
return price ? Math.round((usage.input * price.input + usage.output * price.output) * 1e6) / 1e6 : null;
|
|
563
|
+
}, "costOf");
|
|
564
|
+
|
|
565
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/services/enrichment.js
|
|
566
|
+
var ENRICH_PER_RUN = 600;
|
|
567
|
+
var BATCH = 20;
|
|
568
|
+
var CONCURRENCY = 4;
|
|
569
|
+
var MAX_INPUT_CHARS = 4e3;
|
|
570
|
+
var MAX_FACTS = 5;
|
|
571
|
+
var MAX_QUESTIONS = 3;
|
|
572
|
+
var MAX_LINE = 400;
|
|
573
|
+
var MAX_FAILED_BATCHES = 3;
|
|
574
|
+
var ENRICH_BATCH_MS = 3e4;
|
|
575
|
+
var SYSTEM = `For each record, write what a memory system would store about it.
|
|
576
|
+
|
|
577
|
+
For each record:
|
|
578
|
+
- facts: one to three standalone sentences, each stating exactly one fact. Name people, projects and things in
|
|
579
|
+
full, leave no pronoun unresolved, and turn relative dates into absolute ones using the record's date. Keep
|
|
580
|
+
amounts, dates and times exactly. Say whether the fact is confirmed, only proposed, rejected or cancelled.
|
|
581
|
+
Small talk with no fact gets an empty list.
|
|
582
|
+
- questions: two questions a person might ask whose answer is in this record, in everyday words that differ
|
|
583
|
+
from the record's own words (synonyms, plainer terms). Empty for small talk.
|
|
584
|
+
|
|
585
|
+
Write in the record's own language. Reply with JSON only: {"records": [{"i": <index>, "facts": [...], "questions": [...]}]}, one entry per record.`;
|
|
586
|
+
var line = pipe(unknown(), transform((value) => typeof value === "string" ? value.replace(/\s+/g, " ").trim().slice(0, MAX_LINE) : ""));
|
|
587
|
+
var Reply = object({
|
|
588
|
+
records: array(object({
|
|
589
|
+
i: pipe(number(), integer(), minValue(0)),
|
|
590
|
+
facts: optional(array(line), []),
|
|
591
|
+
questions: optional(array(line), [])
|
|
592
|
+
}))
|
|
593
|
+
});
|
|
594
|
+
var parseEnrichmentReply = /* @__PURE__ */ __name((text) => {
|
|
595
|
+
const start = text.indexOf("{");
|
|
596
|
+
const end = text.lastIndexOf("}");
|
|
597
|
+
if (start < 0 || end < start)
|
|
598
|
+
throw new CliError("invalid_response", "the enrichment reply holds no JSON object");
|
|
599
|
+
let parsed;
|
|
600
|
+
try {
|
|
601
|
+
parsed = JSON.parse(text.slice(start, end + 1));
|
|
602
|
+
} catch {
|
|
603
|
+
throw new CliError("invalid_response", "the enrichment reply is not valid JSON");
|
|
604
|
+
}
|
|
605
|
+
const checked = safeParse(Reply, parsed);
|
|
606
|
+
if (!checked.success)
|
|
607
|
+
throw new CliError("invalid_response", "the enrichment reply does not have the asked shape");
|
|
608
|
+
return new Map(checked.output.records.map((row) => [
|
|
609
|
+
row.i,
|
|
610
|
+
[...row.facts.slice(0, MAX_FACTS), ...row.questions.slice(0, MAX_QUESTIONS)].filter(Boolean).join("\n")
|
|
611
|
+
]));
|
|
612
|
+
}, "parseEnrichmentReply");
|
|
613
|
+
var REASON_TEXT = {
|
|
614
|
+
"enrichment.key-rejected": "the provider refused the key; nothing more was sent",
|
|
615
|
+
"enrichment.unreachable": "the provider could not be reached; nothing more was sent",
|
|
616
|
+
"enrichment.deadline": "out of time before the run's deadline; the next sync goes on"
|
|
617
|
+
};
|
|
618
|
+
var reasonIdOf = /* @__PURE__ */ __name((error) => {
|
|
619
|
+
if (!(error instanceof CliError))
|
|
620
|
+
return "enrichment.bad-replies";
|
|
621
|
+
if (error.details.reason === "model.key-rejected")
|
|
622
|
+
return "enrichment.key-rejected";
|
|
623
|
+
if (error.details.reason === "model.unreachable")
|
|
624
|
+
return "enrichment.unreachable";
|
|
625
|
+
if (error.details.reason === "local-only.refused")
|
|
626
|
+
return "enrichment.local-only";
|
|
627
|
+
if (error.code === "rate_limited")
|
|
628
|
+
return "enrichment.rate-limited";
|
|
629
|
+
if (error.code === "cancelled")
|
|
630
|
+
return "enrichment.cancelled";
|
|
631
|
+
if (error.code === "invalid_response")
|
|
632
|
+
return "enrichment.bad-replies";
|
|
633
|
+
return "enrichment.error";
|
|
634
|
+
}, "reasonIdOf");
|
|
635
|
+
var recordsData = /* @__PURE__ */ __name((batch) => JSON.stringify(batch.map((record, i) => ({
|
|
636
|
+
i,
|
|
637
|
+
date: record.at === null ? null : new Date(record.at).toISOString().slice(0, 10),
|
|
638
|
+
kind: record.type === "email" ? "mail" : "note",
|
|
639
|
+
text: record.text.slice(0, MAX_INPUT_CHARS)
|
|
640
|
+
}))), "recordsData");
|
|
641
|
+
var keyLookup = /* @__PURE__ */ __name((options2, setting) => {
|
|
642
|
+
if (options2.key) {
|
|
643
|
+
const key2 = options2.key(setting.provider);
|
|
644
|
+
return key2 === void 0 ? void 0 : { key: key2, source: "given" };
|
|
645
|
+
}
|
|
646
|
+
const name = setting.base_url === void 0 ? setting.provider : endpointKeyName(setting.base_url);
|
|
647
|
+
if (options2.app) {
|
|
648
|
+
const keys = embeddingKeys(options2.app, options2.env, options2.keyring);
|
|
649
|
+
const stored = keys.read(name);
|
|
650
|
+
if (stored)
|
|
651
|
+
return {
|
|
652
|
+
key: stored.key,
|
|
653
|
+
source: stored.source === "file" ? "file" : stored.source === "keyring" ? "keyring" : "env"
|
|
654
|
+
};
|
|
655
|
+
const plain = setting.base_url === void 0 ? keys.readPlain(setting.provider) : void 0;
|
|
656
|
+
return plain === void 0 ? void 0 : { key: plain, source: "keyring" };
|
|
657
|
+
}
|
|
658
|
+
const key = setting.base_url === void 0 ? options2.env[keyVariable(setting.provider)]?.trim() : void 0;
|
|
659
|
+
return key ? { key, source: "env" } : void 0;
|
|
660
|
+
}, "keyLookup");
|
|
661
|
+
var keyVariable = /* @__PURE__ */ __name((provider) => `${provider.toUpperCase()}_API_KEY`, "keyVariable");
|
|
662
|
+
var enrichRecords = /* @__PURE__ */ __name(async (store, options2) => {
|
|
663
|
+
const setting = readEnrichmentSetting(options2.env);
|
|
664
|
+
if (!setting || !store.enrichment)
|
|
665
|
+
return { status: "off" };
|
|
666
|
+
const enrichment = store.enrichment;
|
|
667
|
+
const baseUrl = enrichmentEndpoint(setting);
|
|
668
|
+
const target = { provider: setting.provider, model: setting.model, baseUrl };
|
|
669
|
+
const apiKey = keyLookup(options2, setting)?.key;
|
|
670
|
+
const maxRecords = options2.maxRecords ?? ENRICH_PER_RUN;
|
|
671
|
+
const refused = !modelAddressAllowed(baseUrl) ? "enrichment.address-refused" : !onThisComputer(baseUrl) && localOnly(options2.env) ? "enrichment.local-only" : void 0;
|
|
672
|
+
if (refused)
|
|
673
|
+
return {
|
|
674
|
+
status: "stopped",
|
|
675
|
+
provider: setting.provider,
|
|
676
|
+
model: setting.model,
|
|
677
|
+
enriched: 0,
|
|
678
|
+
failed: 0,
|
|
679
|
+
left: (await enrichment.pending(Number.MAX_SAFE_INTEGER, options2.narrow)).length,
|
|
680
|
+
usage: { input: 0, output: 0 },
|
|
681
|
+
cost_usd: 0,
|
|
682
|
+
reason: refused === "enrichment.local-only" ? "local only is on and the model is not on this computer; nothing was sent" : "the address is plain http to another computer: use https, or http only on this computer; nothing was sent",
|
|
683
|
+
reason_id: refused
|
|
684
|
+
};
|
|
685
|
+
if (apiKey === void 0 && setting.base_url === void 0)
|
|
686
|
+
return {
|
|
687
|
+
status: "stopped",
|
|
688
|
+
provider: setting.provider,
|
|
689
|
+
model: setting.model,
|
|
690
|
+
enriched: 0,
|
|
691
|
+
failed: 0,
|
|
692
|
+
left: (await enrichment.pending(Number.MAX_SAFE_INTEGER, options2.narrow)).length,
|
|
693
|
+
usage: { input: 0, output: 0 },
|
|
694
|
+
cost_usd: 0,
|
|
695
|
+
reason: `no ${setting.provider} key: store one with \`models keys set ${setting.provider}\` or set ${keyVariable(setting.provider)}; nothing was sent`,
|
|
696
|
+
reason_id: "enrichment.no-key"
|
|
697
|
+
};
|
|
698
|
+
const until = options2.deadline ? options2.deadline.endsAt - deadlineMargin(options2.deadline) : Number.POSITIVE_INFINITY;
|
|
699
|
+
const timeUp = Number.isFinite(until) ? AbortSignal.timeout(Math.max(0, until - Date.now())) : void 0;
|
|
700
|
+
const signals = [options2.signal, timeUp].filter((one) => one !== void 0);
|
|
701
|
+
const signal = signals.length ? AbortSignal.any(signals) : void 0;
|
|
702
|
+
const gateway = modelGateway({
|
|
703
|
+
resolve: /* @__PURE__ */ __name(() => target, "resolve"),
|
|
704
|
+
// The setting exists only with the owner's yes for this provider and endpoint; the endpoint is checked again.
|
|
705
|
+
consent: /* @__PURE__ */ __name((_request, chosen) => chosen.provider === setting.provider && chosen.baseUrl === baseUrl, "consent"),
|
|
706
|
+
key: /* @__PURE__ */ __name(() => apiKey, "key"),
|
|
707
|
+
env: options2.env,
|
|
708
|
+
...options2.adapters ? { adapters: options2.adapters } : {},
|
|
709
|
+
...options2.fetch ? { fetch: options2.fetch } : {},
|
|
710
|
+
...signal ? { signal } : {}
|
|
711
|
+
});
|
|
712
|
+
const queue = await enrichment.pending(maxRecords, options2.narrow);
|
|
713
|
+
const batches = [];
|
|
714
|
+
for (let start = 0; start < queue.length; start += BATCH)
|
|
715
|
+
batches.push(queue.slice(start, start + BATCH));
|
|
716
|
+
const usage = { input: 0, output: 0 };
|
|
717
|
+
let enriched = 0;
|
|
718
|
+
let failed = 0;
|
|
719
|
+
let failedBatches = 0;
|
|
720
|
+
let reason;
|
|
721
|
+
let reasonId;
|
|
722
|
+
const ask = /* @__PURE__ */ __name(async (batch) => {
|
|
723
|
+
const answer = await gateway.complete({
|
|
724
|
+
purpose: "enrichment",
|
|
725
|
+
system: SYSTEM,
|
|
726
|
+
prompt: "Enrich each record of the data.",
|
|
727
|
+
data: recordsData(batch),
|
|
728
|
+
// The facts must keep names, amounts and dates exactly, which the default no-copy policy forbids.
|
|
729
|
+
allowSourceQuotes: true,
|
|
730
|
+
maxTokens: 8192,
|
|
731
|
+
...setting.provider === "openai" && setting.base_url === void 0 ? { options: { response_format: { type: "json_object" }, temperature: 0 } } : {}
|
|
732
|
+
});
|
|
733
|
+
const rows = parseEnrichmentReply(answer.text);
|
|
734
|
+
const used = answer.usage ?? { input: answer.tokens, output: 0 };
|
|
735
|
+
usage.input += used.input;
|
|
736
|
+
usage.output += used.output;
|
|
737
|
+
const answered = batch.flatMap((record, i) => {
|
|
738
|
+
const text = rows.get(i);
|
|
739
|
+
return text === void 0 ? [] : [
|
|
740
|
+
{
|
|
741
|
+
type: record.type,
|
|
742
|
+
id: record.id,
|
|
743
|
+
hash: record.hash,
|
|
744
|
+
provider: setting.provider,
|
|
745
|
+
model: setting.model,
|
|
746
|
+
text,
|
|
747
|
+
tokens: Math.round(answer.tokens / batch.length)
|
|
748
|
+
}
|
|
749
|
+
];
|
|
750
|
+
});
|
|
751
|
+
await enrichment.save(answered);
|
|
752
|
+
enriched += answered.length;
|
|
753
|
+
failed += batch.length - answered.length;
|
|
754
|
+
}, "ask");
|
|
755
|
+
let next = 0;
|
|
756
|
+
let slowest = 0;
|
|
757
|
+
const outOfTime = /* @__PURE__ */ __name(() => {
|
|
758
|
+
reason = REASON_TEXT["enrichment.deadline"];
|
|
759
|
+
reasonId = "enrichment.deadline";
|
|
760
|
+
}, "outOfTime");
|
|
761
|
+
const worker = /* @__PURE__ */ __name(async () => {
|
|
762
|
+
while (reason === void 0 && next < batches.length) {
|
|
763
|
+
if (Date.now() + Math.max(options2.batchMs ?? ENRICH_BATCH_MS, slowest) + ANSWER_RESERVE_MS >= until) {
|
|
764
|
+
outOfTime();
|
|
765
|
+
break;
|
|
766
|
+
}
|
|
767
|
+
const batch = batches[next++];
|
|
768
|
+
const started = Date.now();
|
|
769
|
+
try {
|
|
770
|
+
await ask(batch);
|
|
771
|
+
slowest = Math.max(slowest, Date.now() - started);
|
|
772
|
+
} catch (error) {
|
|
773
|
+
if (timeUp?.aborted && !options2.signal?.aborted) {
|
|
774
|
+
outOfTime();
|
|
775
|
+
break;
|
|
776
|
+
}
|
|
777
|
+
failed += batch.length;
|
|
778
|
+
const id = reasonIdOf(error);
|
|
779
|
+
if (id !== "enrichment.bad-replies" || ++failedBatches >= MAX_FAILED_BATCHES) {
|
|
780
|
+
reason = REASON_TEXT[id] ?? (error instanceof CliError ? error.message : "the enrichment provider failed");
|
|
781
|
+
reasonId = id;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
}, "worker");
|
|
786
|
+
await Promise.all(Array.from({ length: Math.min(options2.concurrency ?? CONCURRENCY, batches.length) }, () => worker()));
|
|
787
|
+
const left = (await enrichment.pending(Number.MAX_SAFE_INTEGER, options2.narrow)).length;
|
|
788
|
+
const none = enriched === 0 && failed > 0;
|
|
789
|
+
if (none && reason === void 0) {
|
|
790
|
+
reason = `the provider enriched none of the ${failed} records sent; they are sent again next sync`;
|
|
791
|
+
reasonId = "enrichment.bad-replies";
|
|
792
|
+
}
|
|
793
|
+
return {
|
|
794
|
+
status: none ? "failed" : reason === void 0 ? "done" : "stopped",
|
|
795
|
+
provider: setting.provider,
|
|
796
|
+
model: setting.model,
|
|
797
|
+
enriched,
|
|
798
|
+
failed,
|
|
799
|
+
left,
|
|
800
|
+
usage,
|
|
801
|
+
cost_usd: costOf(usage, setting),
|
|
802
|
+
...reason === void 0 ? {} : { reason },
|
|
803
|
+
...reasonId === void 0 ? {} : { reason_id: reasonId }
|
|
804
|
+
};
|
|
805
|
+
}, "enrichRecords");
|
|
806
|
+
var MEASURED = {
|
|
807
|
+
reworded_at_10: { off: 0.62, on: 0.79 },
|
|
808
|
+
own_words_first: { off: 0.54, on: 0.48 },
|
|
809
|
+
source: "https://github.com/WireCatLabs/cli-testing/pull/322"
|
|
810
|
+
};
|
|
811
|
+
var enrichmentState = /* @__PURE__ */ __name(async (store, env, estimateFor, keys = {}) => {
|
|
812
|
+
const setting = readEnrichmentSetting(env);
|
|
813
|
+
const counts = await store.enrichment?.counts() ?? {
|
|
814
|
+
records: 0,
|
|
815
|
+
enriched: 0,
|
|
816
|
+
pendingChars: 0,
|
|
817
|
+
pendingByType: { document: 0, note: 0, email: 0 }
|
|
818
|
+
};
|
|
819
|
+
const pending = counts.records - counts.enriched;
|
|
820
|
+
const chosen = estimateFor ?? setting ?? DEFAULT_OFFER;
|
|
821
|
+
const endpoint2 = enrichmentEndpoint(chosen);
|
|
822
|
+
const found = keyLookup({ env, ...keys }, chosen);
|
|
823
|
+
const notes = counts.pendingByType.document + counts.pendingByType.note;
|
|
824
|
+
return {
|
|
825
|
+
on: setting !== void 0,
|
|
826
|
+
provider: setting?.provider ?? null,
|
|
827
|
+
model: setting?.model ?? null,
|
|
828
|
+
endpoint: setting ? enrichmentEndpoint(setting) : null,
|
|
829
|
+
consented_at: setting?.consented_at ?? null,
|
|
830
|
+
target: {
|
|
831
|
+
provider: chosen.provider,
|
|
832
|
+
model: chosen.model,
|
|
833
|
+
endpoint: endpoint2,
|
|
834
|
+
endpoint_host: new URL(endpoint2).host,
|
|
835
|
+
key: { present: found !== void 0, source: found?.source ?? null, env_var: keyVariable(chosen.provider) },
|
|
836
|
+
price_known: enrichmentPrice(chosen.provider, chosen.model, chosen.base_url) !== void 0
|
|
837
|
+
},
|
|
838
|
+
records: counts.records,
|
|
839
|
+
enriched: counts.enriched,
|
|
840
|
+
pending,
|
|
841
|
+
estimate: estimateEnrichment(pending, counts.pendingChars, chosen),
|
|
842
|
+
per_sync: ENRICH_PER_RUN,
|
|
843
|
+
syncs_needed: Math.ceil(Math.max(notes, counts.pendingByType.email) / ENRICH_PER_RUN),
|
|
844
|
+
sends_new_records: true,
|
|
845
|
+
offered: offeredModels(),
|
|
846
|
+
measured: MEASURED
|
|
847
|
+
};
|
|
848
|
+
}, "enrichmentState");
|
|
849
|
+
|
|
850
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/services/meaning-model.js
|
|
851
|
+
var meaningModel = /* @__PURE__ */ __name(async (store, env = process.env) => {
|
|
852
|
+
const chosen = chosenTextModel(env);
|
|
853
|
+
if (chosen.from === "chosen" || chosen.id !== DEFAULT_TEXT_MODEL)
|
|
854
|
+
return chosen.id;
|
|
855
|
+
const models = textModels(env);
|
|
856
|
+
const current = models.find(({ id }) => id === DEFAULT_TEXT_MODEL);
|
|
857
|
+
const previous = models.find(({ id }) => id === PREVIOUS_DEFAULT_TEXT_MODEL);
|
|
858
|
+
if (!current || !previous || !isTextModelInstalled(previous, textModelsDirectory(env)))
|
|
859
|
+
return chosen.id;
|
|
860
|
+
const [now, before] = [vectorModelKey(current), vectorModelKey(previous)];
|
|
861
|
+
const counts = await store.vectors.vectorCounts([now, before]);
|
|
862
|
+
return (counts.get(before) ?? 0) > (counts.get(now) ?? 0) ? previous.id : current.id;
|
|
863
|
+
}, "meaningModel");
|
|
864
|
+
|
|
865
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/services/notes-title-tier.js
|
|
866
|
+
var plainQueryWords = /* @__PURE__ */ __name((query) => {
|
|
867
|
+
let root;
|
|
868
|
+
try {
|
|
869
|
+
root = parseLucene(`(${query})`, { ...SEARCH_QUERY, defaultField: "text" }).root;
|
|
870
|
+
} catch {
|
|
871
|
+
return void 0;
|
|
872
|
+
}
|
|
873
|
+
const leaves = root.kind === "predicate" ? [root] : root.clauses.map(({ occur, node }) => occur === "must" ? node : null);
|
|
874
|
+
const values = [];
|
|
875
|
+
for (const leaf of leaves) {
|
|
876
|
+
if (leaf?.kind !== "predicate" || leaf.implicit !== true || leaf.operator !== "term" && leaf.operator !== "phrase")
|
|
877
|
+
return void 0;
|
|
878
|
+
values.push(leaf.value);
|
|
879
|
+
}
|
|
880
|
+
const words = normalize(values.join(" "));
|
|
881
|
+
return words === "" || /["\\]/u.test(words) ? void 0 : words;
|
|
882
|
+
}, "plainQueryWords");
|
|
883
|
+
var titleQuery = /* @__PURE__ */ __name((words) => words.split(" ").map((word) => `title:"${word}"`).join(" AND "), "titleQuery");
|
|
884
|
+
var titleTiers = /* @__PURE__ */ __name((hits, words) => {
|
|
885
|
+
const rank = /* @__PURE__ */ __name(({ note }) => {
|
|
886
|
+
const title = normalize(note.title ?? "");
|
|
887
|
+
return title === words ? 0 : title.includes(words) ? 1 : 2;
|
|
888
|
+
}, "rank");
|
|
889
|
+
return [...hits].sort((a, b) => rank(a) - rank(b));
|
|
890
|
+
}, "titleTiers");
|
|
891
|
+
|
|
892
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/services/pictures.js
|
|
893
|
+
import { createHash } from "node:crypto";
|
|
894
|
+
import { lstat, readFile } from "node:fs/promises";
|
|
895
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
896
|
+
|
|
897
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/domain/models.js
|
|
898
|
+
var GROUP_SETTINGS = [
|
|
899
|
+
"allCanPin",
|
|
900
|
+
"onlyAdminsAdd",
|
|
901
|
+
"onlyAdminsCall",
|
|
902
|
+
"onlyOwnerEditsInfo",
|
|
903
|
+
"membersSeeLink"
|
|
904
|
+
];
|
|
905
|
+
var FOLDER_KINDS = ["contacts", "non-contacts", "groups", "channels", "bots"];
|
|
906
|
+
var FOLDER_SKIPS = ["muted", "read", "archived"];
|
|
907
|
+
var ADMIN_RIGHTS = ["read", "members", "admins", "info", "pin", "link", "post", "edit", "delete"];
|
|
908
|
+
var senderIsMe = /* @__PURE__ */ __name((message, account) => message.outgoing === true || message.senderId !== null && String(message.senderId) === account, "senderIsMe");
|
|
909
|
+
var MEDIA_KINDS = ["photo", "video", "file", "audio", "link"];
|
|
910
|
+
|
|
911
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/ports/messenger.js
|
|
912
|
+
var throughWrapper = /* @__PURE__ */ __name((inner, handled, wrap = (_, call) => call) => new Proxy(handled, {
|
|
913
|
+
get: /* @__PURE__ */ __name((own, key) => {
|
|
914
|
+
if (key in own)
|
|
915
|
+
return own[key];
|
|
916
|
+
const value = inner[key];
|
|
917
|
+
return typeof value === "function" ? wrap(String(key), (...args) => value.apply(inner, args)) : value;
|
|
918
|
+
}, "get"),
|
|
919
|
+
has: /* @__PURE__ */ __name((own, key) => key in own || key in inner, "has")
|
|
920
|
+
}), "throughWrapper");
|
|
921
|
+
var capability = /* @__PURE__ */ __name((adapter, method, what) => {
|
|
922
|
+
const found = adapter[method];
|
|
923
|
+
if (typeof found !== "function")
|
|
924
|
+
throw new CliError("validation_error", `this messenger cannot ${what}`);
|
|
925
|
+
return found.bind(adapter);
|
|
926
|
+
}, "capability");
|
|
927
|
+
|
|
928
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/services/file-download.js
|
|
929
|
+
import { createWriteStream, mkdirSync } from "node:fs";
|
|
930
|
+
import { link, rm } from "node:fs/promises";
|
|
931
|
+
import { join, resolve } from "node:path";
|
|
932
|
+
import { Readable, Transform } from "node:stream";
|
|
933
|
+
import { pipeline } from "node:stream/promises";
|
|
934
|
+
|
|
935
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/domain/recovery.js
|
|
936
|
+
var withRecovery = /* @__PURE__ */ __name((error) => ({
|
|
937
|
+
...error,
|
|
938
|
+
retryable: typeof error.retryable === "boolean" ? error.retryable : error.code === "rate_limited" || error.status === 429
|
|
939
|
+
}), "withRecovery");
|
|
940
|
+
|
|
941
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/services/batch.js
|
|
942
|
+
var actionable = /* @__PURE__ */ __name((error) => {
|
|
943
|
+
if (isCliFailure(error))
|
|
944
|
+
return withRecovery({ code: error.code, message: error.message, ...error.details });
|
|
945
|
+
if (error && typeof error === "object" && "code" in error && "message" in error && typeof error.code === "string" && typeof error.message === "string")
|
|
946
|
+
return withRecovery(error);
|
|
947
|
+
return withRecovery({
|
|
948
|
+
code: "generic_failure",
|
|
949
|
+
message: "the operation failed; inspect diagnostic logs and retry or skip unfinished read items"
|
|
950
|
+
});
|
|
951
|
+
}, "actionable");
|
|
952
|
+
var batchProgress = /* @__PURE__ */ __name((env = process.env) => {
|
|
953
|
+
const threshold = Number(env.MESSAGING_BATCH_MAX_ERROR_PERCENT ?? 50);
|
|
954
|
+
if (!Number.isInteger(threshold) || threshold < 1 || threshold > 100)
|
|
955
|
+
throw new CliError("validation_error", "MESSAGING_BATCH_MAX_ERROR_PERCENT must be a whole percentage from 1 to 100");
|
|
956
|
+
let attempted = 0;
|
|
957
|
+
let succeeded = 0;
|
|
958
|
+
let stopReason;
|
|
959
|
+
const failures = [];
|
|
960
|
+
return {
|
|
961
|
+
ok: /* @__PURE__ */ __name(() => {
|
|
962
|
+
attempted += 1;
|
|
963
|
+
succeeded += 1;
|
|
964
|
+
}, "ok"),
|
|
965
|
+
fail: /* @__PURE__ */ __name((id, stage, error, attachment) => {
|
|
966
|
+
attempted += 1;
|
|
967
|
+
const detail = actionable(error);
|
|
968
|
+
failures.push({ id, stage, error: detail, ...attachment === void 0 ? {} : { attachment } });
|
|
969
|
+
if (detail.code === "rate_limited" || detail.status === 429)
|
|
970
|
+
stopReason = "rate_limited";
|
|
971
|
+
else if (detail.code === "authentication_error")
|
|
972
|
+
stopReason = "authentication";
|
|
973
|
+
else if (detail.code === "cancelled")
|
|
974
|
+
stopReason = "cancelled";
|
|
975
|
+
else if (!stopReason && attempted >= 10 && failures.length * 100 / attempted > threshold)
|
|
976
|
+
stopReason = "error_rate";
|
|
977
|
+
return detail;
|
|
978
|
+
}, "fail"),
|
|
979
|
+
absorb: /* @__PURE__ */ __name((other) => {
|
|
980
|
+
attempted += other.attempted;
|
|
981
|
+
succeeded += other.succeeded;
|
|
982
|
+
failures.push(...other.failures);
|
|
983
|
+
if (other.stopReason === "rate_limited" || !stopReason)
|
|
984
|
+
stopReason = other.stopReason;
|
|
985
|
+
if (!stopReason && attempted >= 10 && failures.length * 100 / attempted > threshold)
|
|
986
|
+
stopReason = "error_rate";
|
|
987
|
+
}, "absorb"),
|
|
988
|
+
get stopped() {
|
|
989
|
+
return stopReason !== void 0;
|
|
990
|
+
},
|
|
991
|
+
get failed() {
|
|
992
|
+
return failures.length;
|
|
993
|
+
},
|
|
994
|
+
result: /* @__PURE__ */ __name(() => ({
|
|
995
|
+
attempted,
|
|
996
|
+
succeeded,
|
|
997
|
+
failed: failures.length,
|
|
998
|
+
errorRate: attempted === 0 ? 0 : failures.length / attempted,
|
|
999
|
+
failures,
|
|
1000
|
+
...stopReason === void 0 ? {} : { stopReason },
|
|
1001
|
+
maxErrorPercent: threshold
|
|
1002
|
+
}), "result")
|
|
1003
|
+
};
|
|
1004
|
+
}, "batchProgress");
|
|
1005
|
+
var mergeBatches = /* @__PURE__ */ __name((a, b) => {
|
|
1006
|
+
if (!a)
|
|
1007
|
+
return b;
|
|
1008
|
+
if (!b)
|
|
1009
|
+
return a;
|
|
1010
|
+
const attempted = a.attempted + b.attempted;
|
|
1011
|
+
const failed = a.failed + b.failed;
|
|
1012
|
+
const stopReason = a.stopReason === "rate_limited" || b.stopReason === "rate_limited" ? "rate_limited" : a.stopReason ?? b.stopReason;
|
|
1013
|
+
return {
|
|
1014
|
+
attempted,
|
|
1015
|
+
failed,
|
|
1016
|
+
succeeded: a.succeeded + b.succeeded,
|
|
1017
|
+
errorRate: attempted ? failed / attempted : 0,
|
|
1018
|
+
failures: [...a.failures, ...b.failures],
|
|
1019
|
+
maxErrorPercent: a.maxErrorPercent,
|
|
1020
|
+
...stopReason ? { stopReason } : {}
|
|
1021
|
+
};
|
|
1022
|
+
}, "mergeBatches");
|
|
1023
|
+
|
|
1024
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/services/file-download.js
|
|
1025
|
+
var refreshedFiles = /* @__PURE__ */ __name((files) => files.flatMap(({ kind, name, position, providerRef }) => providerRef === void 0 || Object.keys(providerRef).length === 0 ? [] : [
|
|
1026
|
+
{
|
|
1027
|
+
kind,
|
|
1028
|
+
providerRef,
|
|
1029
|
+
...name === void 0 ? {} : { name },
|
|
1030
|
+
...position === void 0 ? {} : { position }
|
|
1031
|
+
}
|
|
1032
|
+
]), "refreshedFiles");
|
|
1033
|
+
var recordPaths = /* @__PURE__ */ __name(async (messages, chat, message, files, saved, warn, onFailure) => {
|
|
1034
|
+
const downloaded = saved.map((one, index) => ({
|
|
1035
|
+
kind: one.kind,
|
|
1036
|
+
path: one.path,
|
|
1037
|
+
...files[index]?.name === void 0 ? {} : { name: files[index]?.name },
|
|
1038
|
+
...files[index]?.position === void 0 ? {} : { position: files[index]?.position },
|
|
1039
|
+
...files[index]?.providerRef === void 0 ? {} : { providerRef: files[index]?.providerRef }
|
|
1040
|
+
}));
|
|
1041
|
+
try {
|
|
1042
|
+
const kept = await messages.keepDownloaded(chat, message, downloaded);
|
|
1043
|
+
if (kept < downloaded.length && downloaded.some(({ providerRef }) => Object.keys(providerRef ?? {}).length > 0))
|
|
1044
|
+
warn(`message ${message}: a new file reference from the messenger was not saved; the next download asks again`);
|
|
1045
|
+
return kept;
|
|
1046
|
+
} catch (error) {
|
|
1047
|
+
onFailure?.(error);
|
|
1048
|
+
warn(`not recorded in the local store where message ${message}'s files went: ${error.message}`);
|
|
1049
|
+
return 0;
|
|
1050
|
+
}
|
|
1051
|
+
}, "recordPaths");
|
|
1052
|
+
var downloadMessage = /* @__PURE__ */ __name(async (messages, chat, message, output, warn) => {
|
|
1053
|
+
const { files } = await messages.download(chat, message);
|
|
1054
|
+
mkdirSync(output, { recursive: true });
|
|
1055
|
+
const result = await saveFiles(messages, chat, message, files, output, { unique: true, warn });
|
|
1056
|
+
if (result.batch.failed > 0)
|
|
1057
|
+
throw new CliError("provider_error", "some attachments failed; completed downloads are retained", {
|
|
1058
|
+
batch: result.batch,
|
|
1059
|
+
saved: result.saved
|
|
1060
|
+
});
|
|
1061
|
+
return result.saved;
|
|
1062
|
+
}, "downloadMessage");
|
|
1063
|
+
var saveFiles = /* @__PURE__ */ __name(async (messages, chat, message, files, output, { unique = false, warn, onSaved, batch = batchProgress() }) => {
|
|
1064
|
+
const saved = [];
|
|
1065
|
+
const successful = [];
|
|
1066
|
+
for (const [index, file] of files.entries()) {
|
|
1067
|
+
if (batch.stopped)
|
|
1068
|
+
break;
|
|
1069
|
+
try {
|
|
1070
|
+
const one = await save(file, output, `${message}-${index + 1}`, { unique });
|
|
1071
|
+
saved.push(one);
|
|
1072
|
+
successful.push(file);
|
|
1073
|
+
batch.ok();
|
|
1074
|
+
onSaved?.(one);
|
|
1075
|
+
} catch (error) {
|
|
1076
|
+
const issue = batch.fail(message, "download", error, (file.position ?? index) + 1);
|
|
1077
|
+
warn(`message ${message}, attachment ${(file.position ?? index) + 1}: ${issue.code} \u2014 ${issue.message}`);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
await recordPaths(messages, chat, message, successful, saved, warn, (error) => batch.fail(message, "record_downloads", error));
|
|
1081
|
+
return { saved, batch: batch.result() };
|
|
1082
|
+
}, "saveFiles");
|
|
1083
|
+
var EXTENSIONS = {
|
|
1084
|
+
"image/jpeg": "jpg",
|
|
1085
|
+
"image/png": "png",
|
|
1086
|
+
"image/webp": "webp",
|
|
1087
|
+
"image/gif": "gif",
|
|
1088
|
+
"video/mp4": "mp4",
|
|
1089
|
+
"video/webm": "webm",
|
|
1090
|
+
"audio/mpeg": "mp3",
|
|
1091
|
+
"audio/ogg": "ogg",
|
|
1092
|
+
"audio/mp4": "m4a",
|
|
1093
|
+
"application/pdf": "pdf"
|
|
1094
|
+
};
|
|
1095
|
+
var BY_KIND = { photo: "jpg" };
|
|
1096
|
+
var save = /* @__PURE__ */ __name(async (file, directory, fallbackName, { unique = false } = {}) => {
|
|
1097
|
+
const own = safeName(file.name);
|
|
1098
|
+
const fileName = /* @__PURE__ */ __name(() => {
|
|
1099
|
+
const extension = EXTENSIONS[file.mime ?? ""] ?? BY_KIND[file.kind];
|
|
1100
|
+
return own ?? (extension ? `${fallbackName}.${extension}` : fallbackName);
|
|
1101
|
+
}, "fileName");
|
|
1102
|
+
const partial = join(directory, `.${fileName()}.${process.pid}.part`);
|
|
1103
|
+
let bytes = 0;
|
|
1104
|
+
const counting = new Transform({
|
|
1105
|
+
transform(chunk, _encoding, done) {
|
|
1106
|
+
bytes += chunk.length;
|
|
1107
|
+
done(null, chunk);
|
|
1108
|
+
}
|
|
1109
|
+
});
|
|
1110
|
+
try {
|
|
1111
|
+
await pipeline(Readable.from(file.bytes()), counting, createWriteStream(partial, { flags: "wx", mode: 384 }));
|
|
1112
|
+
const name = fileName();
|
|
1113
|
+
const names = unique && own ? [name, `${fallbackName}-${own}`] : [name];
|
|
1114
|
+
for (const candidate of names) {
|
|
1115
|
+
const path2 = resolve(join(directory, candidate));
|
|
1116
|
+
const taken = await link(partial, path2).then(() => false, (error) => {
|
|
1117
|
+
if (error.code === "EEXIST")
|
|
1118
|
+
return true;
|
|
1119
|
+
throw error;
|
|
1120
|
+
});
|
|
1121
|
+
if (!taken)
|
|
1122
|
+
return { kind: file.kind, path: path2, bytes };
|
|
1123
|
+
}
|
|
1124
|
+
const path = resolve(join(directory, names.at(-1) ?? name));
|
|
1125
|
+
if (unique)
|
|
1126
|
+
return { kind: file.kind, path, bytes, existing: true };
|
|
1127
|
+
throw new CliError("validation_error", `${path} already exists \u2014 nothing was overwritten; choose --output-dir`);
|
|
1128
|
+
} finally {
|
|
1129
|
+
await rm(partial, { force: true });
|
|
1130
|
+
}
|
|
1131
|
+
}, "save");
|
|
1132
|
+
|
|
1133
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/services/deps.js
|
|
1134
|
+
var accountStore = /* @__PURE__ */ __name(async (deps) => (await deps.store()).forAccount(await deps.account()), "accountStore");
|
|
1135
|
+
var crossAccount = /* @__PURE__ */ __name((deps, _reason) => deps.store(), "crossAccount");
|
|
1136
|
+
var NO_LOCAL_STORE = "this answer comes from the messenger, not from the local store";
|
|
1137
|
+
var SQLITE_BUSY = 5;
|
|
1138
|
+
var storeAbsent = /* @__PURE__ */ __name((error) => {
|
|
1139
|
+
if (isCliFailure(error))
|
|
1140
|
+
return error.code === "validation_error" && error.message === NO_LOCAL_STORE;
|
|
1141
|
+
return error instanceof Error && sqliteCode(error) === SQLITE_BUSY;
|
|
1142
|
+
}, "storeAbsent");
|
|
1143
|
+
var accountUnknown = /* @__PURE__ */ __name((error) => isCliFailure(error) && (error.code === "not_found" || error.code === "authentication_error"), "accountUnknown");
|
|
1144
|
+
var unless = /* @__PURE__ */ __name(async (work, expected) => {
|
|
1145
|
+
try {
|
|
1146
|
+
return await work();
|
|
1147
|
+
} catch (error) {
|
|
1148
|
+
if (expected(error))
|
|
1149
|
+
return void 0;
|
|
1150
|
+
throw error;
|
|
1151
|
+
}
|
|
1152
|
+
}, "unless");
|
|
1153
|
+
var unlessBusy = /* @__PURE__ */ __name((work) => unless(work, storeAbsent), "unlessBusy");
|
|
1154
|
+
var accountStoreIfOpen = /* @__PURE__ */ __name(async (deps) => {
|
|
1155
|
+
const held = await storeIfOpen(deps);
|
|
1156
|
+
return held?.store.forAccount(held.account);
|
|
1157
|
+
}, "accountStoreIfOpen");
|
|
1158
|
+
var storeIfOpen = /* @__PURE__ */ __name(async (deps) => {
|
|
1159
|
+
const store = await unless(() => deps.store(), storeAbsent);
|
|
1160
|
+
const account = store && await unless(() => deps.account(), accountUnknown);
|
|
1161
|
+
return store && account ? { store, account } : void 0;
|
|
1162
|
+
}, "storeIfOpen");
|
|
1163
|
+
var fromStore = /* @__PURE__ */ __name((deps) => deps.offline || deps.reads === "store", "fromStore");
|
|
1164
|
+
var nothingStored = /* @__PURE__ */ __name((messenger) => `nothing stored for this chat yet \u2014 keep \`${typedCommand(messenger.app.command, "serve")}\` running`, "nothingStored");
|
|
1165
|
+
var OFFLINE = "--offline answers only from what is kept locally: `chats list|show`, `messages list|show|context|download`, `contacts list|show` and `review`";
|
|
1166
|
+
var onlineDeps = /* @__PURE__ */ __name((messenger, adapter, guard, where = {}) => ({
|
|
1167
|
+
messenger,
|
|
1168
|
+
...where,
|
|
1169
|
+
offline: false,
|
|
1170
|
+
guard,
|
|
1171
|
+
connection: /* @__PURE__ */ __name(async () => adapter, "connection"),
|
|
1172
|
+
account: /* @__PURE__ */ __name(async () => {
|
|
1173
|
+
const self = adapter.self();
|
|
1174
|
+
if (self === null)
|
|
1175
|
+
throw new CliError("authentication_error", "the connection does not know whose account it is");
|
|
1176
|
+
return { provider: messenger.provider, account: self };
|
|
1177
|
+
}, "account"),
|
|
1178
|
+
store: /* @__PURE__ */ __name(async () => {
|
|
1179
|
+
throw new CliError("validation_error", NO_LOCAL_STORE);
|
|
1180
|
+
}, "store")
|
|
1181
|
+
}), "onlineDeps");
|
|
1182
|
+
var storedDeps = /* @__PURE__ */ __name((messenger, store, account, guard) => ({
|
|
1183
|
+
messenger,
|
|
1184
|
+
offline: true,
|
|
1185
|
+
reads: messenger.history ?? "server",
|
|
1186
|
+
guard,
|
|
1187
|
+
account: /* @__PURE__ */ __name(async () => account, "account"),
|
|
1188
|
+
store: /* @__PURE__ */ __name(async () => store, "store"),
|
|
1189
|
+
connection: /* @__PURE__ */ __name(async () => {
|
|
1190
|
+
throw new CliError("validation_error", OFFLINE);
|
|
1191
|
+
}, "connection")
|
|
1192
|
+
}), "storedDeps");
|
|
1193
|
+
var storeModeDeps = /* @__PURE__ */ __name((messenger, store, account, guard) => ({ ...storedDeps(messenger, store, account, guard), offline: false, reads: "store" }), "storeModeDeps");
|
|
1194
|
+
|
|
1195
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/services/search-kind.js
|
|
1196
|
+
var NO_MAIL = "no_mail";
|
|
1197
|
+
var MAIL = "email";
|
|
1198
|
+
var groupLockOf = /* @__PURE__ */ __name((app, env) => {
|
|
1199
|
+
const lock = app === void 0 || env === void 0 ? void 0 : env[envName(app, "GROUP_LOCK")]?.trim();
|
|
1200
|
+
return lock && lock.toLowerCase() !== ALL ? lock : void 0;
|
|
1201
|
+
}, "groupLockOf");
|
|
1202
|
+
var listContextOf = /* @__PURE__ */ __name(async (store, account, app, stored, env) => {
|
|
1203
|
+
const all = stored ?? await store.accounts.storedAccounts();
|
|
1204
|
+
const held = all.some((one) => one.provider === account.provider && one.account === account.account) ? all : [...all, { id: 0, ...account, name: null, scope: "personal" }];
|
|
1205
|
+
const context = {
|
|
1206
|
+
held,
|
|
1207
|
+
groups: await store.accounts.accountGroups(),
|
|
1208
|
+
profiles: await store.accounts.profiles(),
|
|
1209
|
+
running: { provider: account.provider, ...app ? { command: app.command } : {} }
|
|
1210
|
+
};
|
|
1211
|
+
const membership = groupMembership(context);
|
|
1212
|
+
const groups = groupEntries(context.groups);
|
|
1213
|
+
const lock = groupLockOf(app, env);
|
|
1214
|
+
if (lock === void 0)
|
|
1215
|
+
return { ...context, groups, membership };
|
|
1216
|
+
const members = hasGroup(membership.groups, lock) ? membership.groups[lock] : void 0;
|
|
1217
|
+
if (!members)
|
|
1218
|
+
throw new CliError("permission_error", `this process is locked to group ${lock} (${envName(app, "GROUP_LOCK")}), which does not exist`);
|
|
1219
|
+
const only = new Set([...members, OWNER_NOTES].map(keyOf));
|
|
1220
|
+
const listedAs = /* @__PURE__ */ __name((one) => isFolderProvider(one.provider) || isDocumentAccountProvider(one.provider) ? { provider: "notes", account: String(one.id) } : one, "listedAs");
|
|
1221
|
+
return {
|
|
1222
|
+
...context,
|
|
1223
|
+
held: held.filter((one) => only.has(keyOf(listedAs(one)))),
|
|
1224
|
+
groups: { [lock]: groups[lock] ?? [] },
|
|
1225
|
+
membership: {
|
|
1226
|
+
groups: { [lock]: members },
|
|
1227
|
+
duplicates: membership.duplicates.filter(({ groups: names }) => names.includes(lock)),
|
|
1228
|
+
suggested: membership.suggested.filter(({ group }) => group === lock),
|
|
1229
|
+
unresolved: membership.unresolved
|
|
1230
|
+
},
|
|
1231
|
+
only
|
|
1232
|
+
};
|
|
1233
|
+
}, "listContextOf");
|
|
1234
|
+
var listedAccounts = /* @__PURE__ */ __name(async (store, account, source, app, kind, env) => {
|
|
1235
|
+
const lock = groupLockOf(app, env);
|
|
1236
|
+
if (source === void 0 && lock === void 0)
|
|
1237
|
+
return void 0;
|
|
1238
|
+
const stored = await store.accounts.storedAccounts();
|
|
1239
|
+
const registered = source !== void 0 && (isKind(source) || providerNamed(source) !== void 0 && !stored.some(({ provider }) => provider === source));
|
|
1240
|
+
if (lock === void 0 && source !== void 0 && !isAccountList(source) && !registered)
|
|
1241
|
+
return void 0;
|
|
1242
|
+
const entries = entriesOfList(source ?? `group:${lock}`, await listContextOf(store, account, app, stored, env));
|
|
1243
|
+
return fitting(entries, kind ? [kind] : ["messages", "mail"], `${app ? `${app.command} ` : ""}search ${kind ?? "messages"}`);
|
|
1244
|
+
}, "listedAccounts");
|
|
1245
|
+
var accountsOfKind = /* @__PURE__ */ __name((kind, chosen, held, explicit, command = void 0, mailAccount, listed = false) => {
|
|
1246
|
+
if (mailAccount !== void 0 && kind !== "mail")
|
|
1247
|
+
throw new CliError("validation_error", "--account names a mail account \u2014 memo search mail reads it");
|
|
1248
|
+
if (kind === void 0)
|
|
1249
|
+
return chosen;
|
|
1250
|
+
if (kind === "messages") {
|
|
1251
|
+
if (explicit === MAIL)
|
|
1252
|
+
throw new CliError("validation_error", "mail is searched with `memo search mail`, not search messages");
|
|
1253
|
+
return chosen.filter(({ provider }) => holdsKindOf(provider, "messages"));
|
|
1254
|
+
}
|
|
1255
|
+
if (explicit !== void 0 && explicit !== MAIL && explicit !== "all")
|
|
1256
|
+
throw new CliError("validation_error", `search mail reads mail only \u2014 \`${command === void 0 ? "" : `${command} `}search messages\` searches ${explicit}`);
|
|
1257
|
+
const mail = (listed ? chosen : held).filter(({ provider }) => holdsKindOf(provider, "mail"));
|
|
1258
|
+
if (mail.length === 0)
|
|
1259
|
+
throw new CliError("not_found", "no mail in the store yet \u2014 `memo sync --only mail --since-time <time>` imports it", {
|
|
1260
|
+
reason: NO_MAIL
|
|
1261
|
+
});
|
|
1262
|
+
const address = mailAccount?.trim().toLowerCase();
|
|
1263
|
+
const chosenMail = address === void 0 ? mail : mail.filter(({ account }) => account === address);
|
|
1264
|
+
if (chosenMail.length === 0)
|
|
1265
|
+
throw new CliError("not_found", `no mail account ${mailAccount} in the store \u2014 it holds ${mail.map(({ account }) => account).join(", ")}`);
|
|
1266
|
+
return chosenMail.map(({ provider, account }) => ({ provider, account }));
|
|
1267
|
+
}, "accountsOfKind");
|
|
1268
|
+
|
|
1269
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/services/message-resolution.js
|
|
1270
|
+
var readChatId = /* @__PURE__ */ __name(async (deps, reference, store, account) => {
|
|
1271
|
+
if (deps.reads !== "store")
|
|
1272
|
+
return keptChatId(deps.messenger, reference, store, account);
|
|
1273
|
+
const chatId = await keptChatId(deps.messenger, reference, store, account).catch((error) => {
|
|
1274
|
+
if (codeOf(error) === "not_found")
|
|
1275
|
+
throw new CliError("not_found", nothingStored(deps.messenger));
|
|
1276
|
+
throw error;
|
|
1277
|
+
});
|
|
1278
|
+
if (await store.messages.countMessages(account, chatId) === 0) {
|
|
1279
|
+
const all = (await store.chats.chats(account, { includeLeft: true })).items;
|
|
1280
|
+
const left = all.some((one) => one.id === chatId && one.membershipState === "left");
|
|
1281
|
+
throw new CliError("not_found", left ? LEFT_EMPTY : nothingStored(deps.messenger), { chat: chatId });
|
|
1282
|
+
}
|
|
1283
|
+
return chatId;
|
|
1284
|
+
}, "readChatId");
|
|
1285
|
+
var LEFT_EMPTY = "you left this chat, and the store holds none of its messages";
|
|
1286
|
+
var storedChatId = /* @__PURE__ */ __name((messenger, reference, store, account, { includeLeft = false } = {}) => {
|
|
1287
|
+
const renamed = /* @__PURE__ */ __name((id) => store.chats.renamedChatId(account, id), "renamed");
|
|
1288
|
+
const profilesOn2 = profilesOnAccount(store, messenger.app?.command, account.provider);
|
|
1289
|
+
const among = chatIdAmong(messenger, reference, account, {
|
|
1290
|
+
held: /* @__PURE__ */ __name(() => store.chats.chats(account, {}), "held"),
|
|
1291
|
+
renamed,
|
|
1292
|
+
left: /* @__PURE__ */ __name(async (id) => leftIn(await store.chats.chats(account, byId(id))), "left"),
|
|
1293
|
+
profilesOn: profilesOn2
|
|
1294
|
+
});
|
|
1295
|
+
if (!includeLeft)
|
|
1296
|
+
return among;
|
|
1297
|
+
return among.catch((error) => {
|
|
1298
|
+
if (codeOf(error) !== "not_found")
|
|
1299
|
+
throw error;
|
|
1300
|
+
return chatIdAmong(messenger, reference, account, {
|
|
1301
|
+
held: /* @__PURE__ */ __name(() => store.chats.chats(account, { includeLeft: true }), "held"),
|
|
1302
|
+
renamed,
|
|
1303
|
+
profilesOn: profilesOn2
|
|
1304
|
+
});
|
|
1305
|
+
});
|
|
1306
|
+
}, "storedChatId");
|
|
1307
|
+
var keptChatId = /* @__PURE__ */ __name((messenger, reference, store, account) => storedChatId(messenger, reference, store, account, { includeLeft: true }), "keptChatId");
|
|
1308
|
+
var chatIdIn = /* @__PURE__ */ __name((messenger, reference, store, { includeLeft = false } = {}) => {
|
|
1309
|
+
const renamed = /* @__PURE__ */ __name((id) => store.chats.renamedChatId(id), "renamed");
|
|
1310
|
+
const among = chatIdAmong(messenger, reference, store.account, {
|
|
1311
|
+
held: /* @__PURE__ */ __name(() => store.chats.chats({}), "held"),
|
|
1312
|
+
renamed,
|
|
1313
|
+
left: /* @__PURE__ */ __name(async (id) => leftIn(await store.chats.chats(byId(id))), "left")
|
|
1314
|
+
});
|
|
1315
|
+
if (!includeLeft)
|
|
1316
|
+
return among;
|
|
1317
|
+
return among.catch((error) => {
|
|
1318
|
+
if (codeOf(error) !== "not_found")
|
|
1319
|
+
throw error;
|
|
1320
|
+
return chatIdAmong(messenger, reference, store.account, {
|
|
1321
|
+
held: /* @__PURE__ */ __name(() => store.chats.chats({ includeLeft: true }), "held"),
|
|
1322
|
+
renamed
|
|
1323
|
+
});
|
|
1324
|
+
});
|
|
1325
|
+
}, "chatIdIn");
|
|
1326
|
+
var byId = /* @__PURE__ */ __name((id) => ({
|
|
1327
|
+
includeLeft: true,
|
|
1328
|
+
limit: 1,
|
|
1329
|
+
where: { sql: "chats.external_id = ?", params: [id] }
|
|
1330
|
+
}), "byId");
|
|
1331
|
+
var leftIn = /* @__PURE__ */ __name(({ items }) => items.some((one) => one.membershipState === "left"), "leftIn");
|
|
1332
|
+
var profilesOnAccount = /* @__PURE__ */ __name((store, app, provider) => async (account) => {
|
|
1333
|
+
if (app === void 0)
|
|
1334
|
+
return void 0;
|
|
1335
|
+
return profilesOn(await store.accounts.profiles(), app, { provider, account });
|
|
1336
|
+
}, "profilesOnAccount");
|
|
1337
|
+
var chatIdAmong = /* @__PURE__ */ __name(async (messenger, reference, account, { held, renamed, left, profilesOn: profilesOn2 }) => {
|
|
1338
|
+
const trimmed = reference.trim();
|
|
1339
|
+
if (messenger.savedChatId && ["me", "self", "saved"].includes(trimmed.toLowerCase())) {
|
|
1340
|
+
return messenger.savedChatId(account);
|
|
1341
|
+
}
|
|
1342
|
+
const named = chatReferenceOf(trimmed, account.provider);
|
|
1343
|
+
if (named)
|
|
1344
|
+
await ensureAccount(named, { account: account.account }, profilesOn2);
|
|
1345
|
+
if (named || /^-?\d+$/.test(trimmed)) {
|
|
1346
|
+
const typed = named?.chat ?? trimmed;
|
|
1347
|
+
const id = await renamed(typed) ?? typed;
|
|
1348
|
+
if (await left?.(id))
|
|
1349
|
+
throw new CliError("not_found", `you left chat ${id}`);
|
|
1350
|
+
return id;
|
|
1351
|
+
}
|
|
1352
|
+
const chats = (await held()).items;
|
|
1353
|
+
const exact = chats.find((one) => one.id === trimmed);
|
|
1354
|
+
if (exact)
|
|
1355
|
+
return exact.id;
|
|
1356
|
+
const moved = await renamed(trimmed);
|
|
1357
|
+
if (moved !== void 0 && chats.some((one) => one.id === moved))
|
|
1358
|
+
return moved;
|
|
1359
|
+
if (trimmed.startsWith("@")) {
|
|
1360
|
+
const username = trimmed.slice(1).toLowerCase();
|
|
1361
|
+
const found = chats.find((one) => String(one.providerMetadata?.username ?? "").toLowerCase() === username);
|
|
1362
|
+
if (!found)
|
|
1363
|
+
throw new CliError("not_found", `no stored chat is ${trimmed}`);
|
|
1364
|
+
return found.id;
|
|
1365
|
+
}
|
|
1366
|
+
return pickChat(trimmed, chats).id;
|
|
1367
|
+
}, "chatIdAmong");
|
|
1368
|
+
var ambiguousAcross = /* @__PURE__ */ __name((reference, what, candidates) => {
|
|
1369
|
+
const width = Math.max(...candidates.map(({ provider, id }) => `${provider} ${id}`.length));
|
|
1370
|
+
const lines = candidates.map(({ provider, id, label }) => ` ${`${provider} ${id}`.padEnd(width)} ${label}`);
|
|
1371
|
+
return new CliError("validation_error", `"${singleLine(reference)}" matches ${candidates.length} ${what} in different accounts \u2014 name one by its id, or narrow the search with in:<messenger>:
|
|
1372
|
+
${lines.join("\n")}`, { candidates: candidates.map(({ provider, id }) => ({ provider, id })) });
|
|
1373
|
+
}, "ambiguousAcross");
|
|
1374
|
+
var missing = /* @__PURE__ */ __name((error) => {
|
|
1375
|
+
if (codeOf(error) === "not_found")
|
|
1376
|
+
return void 0;
|
|
1377
|
+
throw error;
|
|
1378
|
+
}, "missing");
|
|
1379
|
+
var chatAmong = /* @__PURE__ */ __name(async (messenger, store, accounts, reference) => {
|
|
1380
|
+
const [only] = accounts;
|
|
1381
|
+
if (accounts.length === 1 && only)
|
|
1382
|
+
return { account: only, chatId: await storedChatId(messenger, reference, store, only, { includeLeft: true }) };
|
|
1383
|
+
const among = /* @__PURE__ */ __name(async (includeLeft) => (await Promise.all(accounts.map(async (account) => {
|
|
1384
|
+
const held = (await store.chats.chats(account, includeLeft ? { includeLeft } : {})).items;
|
|
1385
|
+
const chatId = await storedChatId(messenger, reference, store, account, { includeLeft }).catch(missing);
|
|
1386
|
+
const chat = held.find((one2) => one2.id === chatId);
|
|
1387
|
+
return chat ? [{ account, chat }] : [];
|
|
1388
|
+
}))).flat(), "among");
|
|
1389
|
+
const current = await among(false);
|
|
1390
|
+
const found = current.length > 0 ? current : await among(true);
|
|
1391
|
+
const [one] = found;
|
|
1392
|
+
if (found.length === 1 && one)
|
|
1393
|
+
return { account: one.account, chatId: one.chat.id };
|
|
1394
|
+
if (found.length === 0)
|
|
1395
|
+
throw new CliError("not_found", `no stored chat matches "${singleLine(reference)}"`);
|
|
1396
|
+
throw ambiguousAcross(reference, "chats", found.map(({ account, chat }) => ({
|
|
1397
|
+
provider: account.provider,
|
|
1398
|
+
id: chat.id,
|
|
1399
|
+
label: singleLine(chat.title ?? "")
|
|
1400
|
+
})));
|
|
1401
|
+
}, "chatAmong");
|
|
1402
|
+
var senderAmong = /* @__PURE__ */ __name(async (store, accounts, reference, field = "from") => {
|
|
1403
|
+
const providers = [...new Set(accounts.map(({ provider }) => provider))];
|
|
1404
|
+
const [only] = accounts;
|
|
1405
|
+
try {
|
|
1406
|
+
if (accounts.length === 1 && only) {
|
|
1407
|
+
const person = pickPerson(reference, await store.people.people(only.provider, { account: only.account }));
|
|
1408
|
+
return { provider: only.provider, id: person.id };
|
|
1409
|
+
}
|
|
1410
|
+
const found = (await Promise.all(providers.map(async (provider) => {
|
|
1411
|
+
const ids = accounts.filter((one2) => one2.provider === provider).map(({ account }) => account);
|
|
1412
|
+
const person = await store.people.people(provider, { accounts: ids }).then((people) => pickPerson(reference, people)).catch(missing);
|
|
1413
|
+
return person ? [{ provider, person }] : [];
|
|
1414
|
+
}))).flat();
|
|
1415
|
+
const [one] = found;
|
|
1416
|
+
if (found.length === 1 && one)
|
|
1417
|
+
return { provider: one.provider, id: one.person.id };
|
|
1418
|
+
if (found.length === 0) {
|
|
1419
|
+
throw new CliError("not_found", isId(reference) ? `no person ${reference} in what these accounts have seen` : `nobody matches "${reference}"`);
|
|
1420
|
+
}
|
|
1421
|
+
throw ambiguousAcross(reference, "people", found.map(({ provider, person }) => ({ provider, id: person.id, label: singleLine(person.name ?? "") })));
|
|
1422
|
+
} catch (error) {
|
|
1423
|
+
if (error instanceof CliError && error.code === "not_found") {
|
|
1424
|
+
throw new CliError("not_found", `${field}:${reference} \u2014 ${error.message}; a part of the name: ${field}:*${reference}*`, {
|
|
1425
|
+
reason: "query.no-match"
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
throw error;
|
|
1429
|
+
}
|
|
1430
|
+
}, "senderAmong");
|
|
1431
|
+
var MOST_NAME_MATCHES = 50;
|
|
1432
|
+
var patternRefused = /* @__PURE__ */ __name((field, pattern, what, found, near) => {
|
|
1433
|
+
if (found === 0) {
|
|
1434
|
+
const inside = `*${pattern.replace(/^\*+|\*+$/gu, "")}*`;
|
|
1435
|
+
const [closest] = near;
|
|
1436
|
+
throw new CliError("not_found", `${field}:${pattern} \u2014 no ${what} fits${near.length ? `; near: ${near.map(({ label }) => label).join(", ")}` : ""} \u2014 a pattern matches the whole name: ${pattern === inside ? "" : `write ${field}:${inside} for a part of it, or `}the name: ${field}:${JSON.stringify(closest?.label ?? pattern.replace(/[*?]/gu, ""))}`, { reason: "query.no-match", candidates: near.map(({ candidate }) => candidate) });
|
|
1437
|
+
}
|
|
1438
|
+
throw new CliError("validation_error", `${field}:${pattern} fits ${found} ${what}, more than ${MOST_NAME_MATCHES} \u2014 write more of the name`, { reason: "query.too-large", budget: "name matches", limit: MOST_NAME_MATCHES, complete: false });
|
|
1439
|
+
}, "patternRefused");
|
|
1440
|
+
var sendersMatching = /* @__PURE__ */ __name(async (store, accounts, field, pattern) => {
|
|
1441
|
+
const providers = [...new Set(accounts.map(({ provider }) => provider))];
|
|
1442
|
+
const seen = await Promise.all(providers.map(async (provider) => {
|
|
1443
|
+
const ids = accounts.filter((one) => one.provider === provider).map(({ account }) => account);
|
|
1444
|
+
const scope = ids.length === 1 ? { account: ids[0] } : { accounts: ids };
|
|
1445
|
+
return { provider, people: (await store.people.people(provider, scope)).all() };
|
|
1446
|
+
}));
|
|
1447
|
+
const found = seen.flatMap(({ provider, people }) => peopleMatching(pattern, people, { byAddress: provider === MAIL }).map(({ id }) => ({ provider, id })));
|
|
1448
|
+
if (found.length === 0 || found.length > MOST_NAME_MATCHES) {
|
|
1449
|
+
const people = seen.flatMap(({ people: people2 }) => people2);
|
|
1450
|
+
const near = nearest(pattern, people, ({ name, alias }) => [name, alias].filter(isText));
|
|
1451
|
+
patternRefused(field, pattern, "person", found.length, near.map(({ id, name, username }) => ({ id, label: name ?? id, candidate: { id, name, username } })));
|
|
1452
|
+
}
|
|
1453
|
+
return found;
|
|
1454
|
+
}, "sendersMatching");
|
|
1455
|
+
var chatsMatchingIn = /* @__PURE__ */ __name(async (store, accounts, pattern) => {
|
|
1456
|
+
const held = await Promise.all(accounts.map(async (account) => ({
|
|
1457
|
+
account,
|
|
1458
|
+
chats: (await store.chats.chats(account, { includeLeft: true })).items
|
|
1459
|
+
})));
|
|
1460
|
+
const found = held.flatMap(({ account, chats }) => chatsMatching(pattern, chats).map((chat) => ({ account, chatId: chat.id })));
|
|
1461
|
+
if (found.length === 0 || found.length > MOST_NAME_MATCHES) {
|
|
1462
|
+
const chats = held.flatMap(({ chats: chats2 }) => chats2);
|
|
1463
|
+
const near = nearest(pattern, chats, ({ title }) => [title].filter(isText));
|
|
1464
|
+
patternRefused("chat", pattern, "chat", found.length, near.map(({ id, title }) => ({ id, label: title ?? id, candidate: { id, title } })));
|
|
1465
|
+
}
|
|
1466
|
+
return found;
|
|
1467
|
+
}, "chatsMatchingIn");
|
|
1468
|
+
var isText = /* @__PURE__ */ __name((value) => typeof value === "string" && value !== "", "isText");
|
|
1469
|
+
|
|
1470
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/services/pictures.js
|
|
1471
|
+
var PICTURE_MAX_BYTES = 25 * 1024 * 1024;
|
|
1472
|
+
var PICTURE_FLOOR = 0.25;
|
|
1473
|
+
var PAGE = 50;
|
|
1474
|
+
var SAVE_EVERY = 8;
|
|
1475
|
+
var PICTURES_OFF = "picture search is off for this profile \u2014 set pictureSearch to true in its config to turn it on";
|
|
1476
|
+
var missingModel = /* @__PURE__ */ __name((id) => `the picture model is not downloaded \u2014 \`images models download ${id}\` fetches it`, "missingModel");
|
|
1477
|
+
var plainWords = /* @__PURE__ */ __name((query) => query.replace(/\b(?:text|content|transcript|filename):("[^"]*"|\S+)/gi, "$1").replace(/\b[a-z_]+:("[^"]*"|\[[^\]]*\]|\{[^}]*\}|\([^)]*\)|\S+)/gi, " ").replace(/\b(?:AND|OR|NOT)\b/g, " ").replace(/[()"+\-~^*?\\[\]{}!|&]/g, " ").replace(/\s+/g, " ").trim(), "plainWords");
|
|
1478
|
+
var pictureBytes = /* @__PURE__ */ __name(async (picture, files, read) => {
|
|
1479
|
+
if (picture.localPath) {
|
|
1480
|
+
try {
|
|
1481
|
+
const found = await lstat(picture.localPath);
|
|
1482
|
+
if (found.isFile() && found.size <= PICTURE_MAX_BYTES)
|
|
1483
|
+
return await readFile(picture.localPath);
|
|
1484
|
+
} catch {
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
const images = (await files()).filter(({ kind, mime }) => kind === "photo" || mime?.startsWith("image/"));
|
|
1488
|
+
const file = images.find(({ position }) => position === picture.position) ?? (images.every(({ position }) => position === void 0) ? images[0] : void 0);
|
|
1489
|
+
if (!file || file.size !== void 0 && file.size > PICTURE_MAX_BYTES)
|
|
1490
|
+
return void 0;
|
|
1491
|
+
const parts = [];
|
|
1492
|
+
let total = 0;
|
|
1493
|
+
for await (const part of file.bytes()) {
|
|
1494
|
+
total += part.length;
|
|
1495
|
+
if (total > PICTURE_MAX_BYTES)
|
|
1496
|
+
return void 0;
|
|
1497
|
+
parts.push(part);
|
|
1498
|
+
}
|
|
1499
|
+
await read(file);
|
|
1500
|
+
return Buffer.concat(parts);
|
|
1501
|
+
}, "pictureBytes");
|
|
1502
|
+
var picturesService = /* @__PURE__ */ __name((deps) => {
|
|
1503
|
+
let opened;
|
|
1504
|
+
const open = /* @__PURE__ */ __name(async () => {
|
|
1505
|
+
if (deps.pictureEmbedder)
|
|
1506
|
+
return deps.pictureEmbedder();
|
|
1507
|
+
const model2 = imageModel(DEFAULT_IMAGE_MODEL);
|
|
1508
|
+
const directory = imageModelsDirectory(deps.env);
|
|
1509
|
+
if (!isImageModelInstalled(model2, directory))
|
|
1510
|
+
throw new CliError("not_found", missingModel(model2.id), { reason: "model.not-downloaded", model: model2.id });
|
|
1511
|
+
const { openPictureEmbedder } = await import("./embedder-XFEELFUL.js");
|
|
1512
|
+
return openPictureEmbedder(model2, directory);
|
|
1513
|
+
}, "open");
|
|
1514
|
+
const embedder = /* @__PURE__ */ __name(() => {
|
|
1515
|
+
opened ??= open().catch((error) => {
|
|
1516
|
+
opened = void 0;
|
|
1517
|
+
throw error;
|
|
1518
|
+
});
|
|
1519
|
+
return opened;
|
|
1520
|
+
}, "embedder");
|
|
1521
|
+
const model = imageModel(DEFAULT_IMAGE_MODEL);
|
|
1522
|
+
return {
|
|
1523
|
+
/**
|
|
1524
|
+
* Gives the images no vector yet one, reading each through the messenger's own download and keeping nothing
|
|
1525
|
+
* of the file: only the vector and the hash of its bytes. One at a time, with a pause, and nothing is marked
|
|
1526
|
+
* read. Run again, it goes on where the last run stopped: an image with a vector is not read twice.
|
|
1527
|
+
*/
|
|
1528
|
+
embed: /* @__PURE__ */ __name(async ({ chat, limit, pauseMs = 250, signal }) => {
|
|
1529
|
+
if (!deps.pictures)
|
|
1530
|
+
throw new CliError("validation_error", PICTURES_OFF);
|
|
1531
|
+
const store = await deps.store();
|
|
1532
|
+
const account = await deps.account();
|
|
1533
|
+
const chatId = chat === void 0 ? void 0 : await storedChatId(deps.messenger, chat, store, account, { includeLeft: true });
|
|
1534
|
+
const use = await embedder();
|
|
1535
|
+
const result = { model: model.key, embedded: 0, skipped: 0, failed: 0, more: false };
|
|
1536
|
+
const pending = [];
|
|
1537
|
+
const flush = /* @__PURE__ */ __name(async () => {
|
|
1538
|
+
if (pending.length === 0)
|
|
1539
|
+
return;
|
|
1540
|
+
await store.vectors.savePictures(account, model.key, model.dims, pending.splice(0));
|
|
1541
|
+
}, "flush");
|
|
1542
|
+
let after = 0;
|
|
1543
|
+
let seen = 0;
|
|
1544
|
+
try {
|
|
1545
|
+
while (seen < limit) {
|
|
1546
|
+
const page = await store.vectors.picturesToEmbed(account, {
|
|
1547
|
+
...chatId === void 0 ? {} : { chatId },
|
|
1548
|
+
after,
|
|
1549
|
+
limit: Math.min(PAGE, limit - seen)
|
|
1550
|
+
});
|
|
1551
|
+
if (page.length === 0)
|
|
1552
|
+
break;
|
|
1553
|
+
let downloaded;
|
|
1554
|
+
for (const picture of page) {
|
|
1555
|
+
if (signal?.aborted)
|
|
1556
|
+
throw new CliError("cancelled", "picture embedding cancelled");
|
|
1557
|
+
after = picture.attachmentPk;
|
|
1558
|
+
seen += 1;
|
|
1559
|
+
const files = /* @__PURE__ */ __name(() => {
|
|
1560
|
+
if (downloaded?.message !== `${picture.chatId}/${picture.messageId}`) {
|
|
1561
|
+
downloaded = {
|
|
1562
|
+
message: `${picture.chatId}/${picture.messageId}`,
|
|
1563
|
+
files: (async () => {
|
|
1564
|
+
const download = capability(await deps.connection(), "download", "download attachments");
|
|
1565
|
+
return (await download(picture.chatId, picture.messageId)).files;
|
|
1566
|
+
})()
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
return downloaded.files;
|
|
1570
|
+
}, "files");
|
|
1571
|
+
try {
|
|
1572
|
+
const bytes = await pictureBytes(picture, files, async (file) => {
|
|
1573
|
+
const refreshed = refreshedFiles([file]);
|
|
1574
|
+
if (refreshed.length === 0)
|
|
1575
|
+
return;
|
|
1576
|
+
await store.attachments.keepProviderRefs(account, picture.chatId, picture.messageId, refreshed).catch(() => void 0);
|
|
1577
|
+
});
|
|
1578
|
+
if (!bytes) {
|
|
1579
|
+
result.skipped += 1;
|
|
1580
|
+
continue;
|
|
1581
|
+
}
|
|
1582
|
+
const vector = await use.embedImage(bytes);
|
|
1583
|
+
pending.push({
|
|
1584
|
+
attachmentPk: picture.attachmentPk,
|
|
1585
|
+
hash: createHash("sha256").update(bytes).digest("hex"),
|
|
1586
|
+
bytes: bytes.length,
|
|
1587
|
+
occurredAt: picture.sentAt,
|
|
1588
|
+
vector
|
|
1589
|
+
});
|
|
1590
|
+
result.embedded += 1;
|
|
1591
|
+
if (pending.length >= SAVE_EVERY)
|
|
1592
|
+
await flush();
|
|
1593
|
+
} catch (error) {
|
|
1594
|
+
if (error instanceof CliError && error.code === "cancelled")
|
|
1595
|
+
throw error;
|
|
1596
|
+
result.failed += 1;
|
|
1597
|
+
}
|
|
1598
|
+
if (pauseMs > 0)
|
|
1599
|
+
await sleep(pauseMs, void 0, signal ? { signal } : {}).catch(() => {
|
|
1600
|
+
});
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
result.more = seen >= limit && (await store.vectors.picturesToEmbed(account, {
|
|
1604
|
+
after,
|
|
1605
|
+
limit: 1,
|
|
1606
|
+
...chatId === void 0 ? {} : { chatId }
|
|
1607
|
+
})).length > 0;
|
|
1608
|
+
} finally {
|
|
1609
|
+
await flush();
|
|
1610
|
+
await use.close();
|
|
1611
|
+
opened = void 0;
|
|
1612
|
+
}
|
|
1613
|
+
return result;
|
|
1614
|
+
}, "embed"),
|
|
1615
|
+
/** The pictures nearest to what the words describe, as their messages; the lane beside the text hits. */
|
|
1616
|
+
lane: /* @__PURE__ */ __name(async (query, { chat, since, limit = 5 } = {}) => {
|
|
1617
|
+
if (!deps.pictures)
|
|
1618
|
+
return {};
|
|
1619
|
+
const words = plainWords(query);
|
|
1620
|
+
if (words === "")
|
|
1621
|
+
return {};
|
|
1622
|
+
const store = await deps.store();
|
|
1623
|
+
const account = await deps.account();
|
|
1624
|
+
const chatId = chat === void 0 ? void 0 : await storedChatId(deps.messenger, chat, store, account, { includeLeft: true });
|
|
1625
|
+
let vector;
|
|
1626
|
+
try {
|
|
1627
|
+
const use = await embedder();
|
|
1628
|
+
vector = await use.embedQuery(words);
|
|
1629
|
+
} catch (error) {
|
|
1630
|
+
if (error instanceof CliError && error.code === "not_found")
|
|
1631
|
+
return { picturesSkipped: error.message, picturesModel: model.id };
|
|
1632
|
+
throw error;
|
|
1633
|
+
} finally {
|
|
1634
|
+
const held = opened;
|
|
1635
|
+
opened = void 0;
|
|
1636
|
+
await held?.then((use) => use.close()).catch(() => {
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
const near = await store.vectors.nearestPictures(account, {
|
|
1640
|
+
...chatId === void 0 ? {} : { chatId },
|
|
1641
|
+
...since === void 0 ? {} : { since },
|
|
1642
|
+
model: model.key,
|
|
1643
|
+
limit,
|
|
1644
|
+
query: vector
|
|
1645
|
+
});
|
|
1646
|
+
const hits = await Promise.all(near.filter(({ score }) => score >= PICTURE_FLOOR).map(async ({ chatId: chatKey, messageId, score }) => {
|
|
1647
|
+
const message = await store.messages.message(account, messageId, { chatId: chatKey });
|
|
1648
|
+
if (!message)
|
|
1649
|
+
return [];
|
|
1650
|
+
return [
|
|
1651
|
+
{
|
|
1652
|
+
locator: formatLocator({
|
|
1653
|
+
provider: account.provider,
|
|
1654
|
+
account: account.account,
|
|
1655
|
+
chat: chatKey,
|
|
1656
|
+
message: messageId
|
|
1657
|
+
}),
|
|
1658
|
+
chatId: chatKey,
|
|
1659
|
+
messageId,
|
|
1660
|
+
timestamp: message.timestamp,
|
|
1661
|
+
senderName: message.senderName,
|
|
1662
|
+
senderIsMe: senderIsMe(message, account.account),
|
|
1663
|
+
score: Number(score.toFixed(4))
|
|
1664
|
+
}
|
|
1665
|
+
];
|
|
1666
|
+
}));
|
|
1667
|
+
return { pictures: hits.flat() };
|
|
1668
|
+
}, "lane")
|
|
1669
|
+
};
|
|
1670
|
+
}, "picturesService");
|
|
1671
|
+
var withPictures = /* @__PURE__ */ __name((messages, pictures) => ({
|
|
1672
|
+
...messages,
|
|
1673
|
+
search: /* @__PURE__ */ __name(async (request) => {
|
|
1674
|
+
const found = await messages.search(request);
|
|
1675
|
+
if (request.kind === "mail" || request.discover || request.text === void 0)
|
|
1676
|
+
return found;
|
|
1677
|
+
if (request.offset)
|
|
1678
|
+
return found;
|
|
1679
|
+
const chat = request.chat ?? found.coverage?.chat;
|
|
1680
|
+
const lane = await pictures.lane(request.text, chat === void 0 ? {} : { chat }).catch((error) => ({ picturesSkipped: error instanceof Error ? error.message : String(error) }));
|
|
1681
|
+
return { ...found, ...lane };
|
|
1682
|
+
}, "search")
|
|
1683
|
+
}), "withPictures");
|
|
1684
|
+
|
|
1685
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/services/notes-search.js
|
|
1686
|
+
var storeQuery = /* @__PURE__ */ __name(async (store, text, { exact, timezone } = {}) => resolvedQuery(store, parsedQuery(text, exact), timezone), "storeQuery");
|
|
1687
|
+
var parsedQuery = /* @__PURE__ */ __name((text, exact) => validateFields(parseLucene(text, { ...SEARCH_QUERY, defaultField: exact ? "exact" : "text" })).root, "parsedQuery");
|
|
1688
|
+
var resolvedQuery = /* @__PURE__ */ __name(async (store, root, timezone) => {
|
|
1689
|
+
const ast = { root };
|
|
1690
|
+
const zone = timezoneOf(timezone);
|
|
1691
|
+
const resolve2 = /* @__PURE__ */ __name((node) => {
|
|
1692
|
+
if (node.kind === "boolean")
|
|
1693
|
+
return { ...node, clauses: node.clauses.map(({ occur, node: node2 }) => ({ occur, node: resolve2(node2) })) };
|
|
1694
|
+
if (node.field !== "date")
|
|
1695
|
+
return node;
|
|
1696
|
+
return {
|
|
1697
|
+
...node,
|
|
1698
|
+
resolution: {
|
|
1699
|
+
date: dateRange(node.value, node.operator === "range" ? node.upper ?? "*" : node.value, node.operator === "range" ? node.lower_inclusive === true : true, node.operator === "range" ? node.upper_inclusive === true : true, zone, node.span)
|
|
1700
|
+
}
|
|
1701
|
+
};
|
|
1702
|
+
}, "resolve");
|
|
1703
|
+
const stemmers = hasStems(ast.root) ? await store.searchIndex.stemmers() : void 0;
|
|
1704
|
+
if (stemmers === null)
|
|
1705
|
+
throw new CliError("validation_error", "the store asks for stemmers this tool does not know \u2014 upgrade this tool, or search exact forms with --exact", { reason: "stemmer.unknown" });
|
|
1706
|
+
return {
|
|
1707
|
+
root: resolve2(ast.root),
|
|
1708
|
+
...hasStems(ast.root) ? { stemmer: createStemmer(stemmers ?? DEFAULT_STEMMERS) } : {}
|
|
1709
|
+
};
|
|
1710
|
+
}, "resolvedQuery");
|
|
1711
|
+
var searchNotesQuery = /* @__PURE__ */ __name(async (store, request) => {
|
|
1712
|
+
if (!request.text.trim())
|
|
1713
|
+
throw new CliError("validation_error", "say what to find in the notes");
|
|
1714
|
+
const { root, stemmer } = await storeQuery(store, request.text, request);
|
|
1715
|
+
return store.notes.search({
|
|
1716
|
+
root,
|
|
1717
|
+
limit: request.limit,
|
|
1718
|
+
...request.offset === void 0 ? {} : { offset: request.offset },
|
|
1719
|
+
...request.newest ? { newest: true } : {},
|
|
1720
|
+
...request.folderIds ? { folderIds: request.folderIds } : {},
|
|
1721
|
+
...request.withInternal ? { withInternal: true } : {},
|
|
1722
|
+
...request.source ? { source: request.source } : {},
|
|
1723
|
+
...request.signal ? { signal: request.signal } : {},
|
|
1724
|
+
...stemmer ? { stemmer } : {}
|
|
1725
|
+
});
|
|
1726
|
+
}, "searchNotesQuery");
|
|
1727
|
+
var NOTE_BATCH = 8;
|
|
1728
|
+
var downloadHint = /* @__PURE__ */ __name((model, command) => command === void 0 ? `install it with a WireCat CLI that has \`models download\` (tg, max or wa); they share the model folder` : `\`${command} models download ${model}\``, "downloadHint");
|
|
1729
|
+
var localModel = /* @__PURE__ */ __name((choice, env, command) => {
|
|
1730
|
+
const model = textModel(choice ?? chosenTextModel(env).id, env);
|
|
1731
|
+
const directory = textModelsDirectory(env);
|
|
1732
|
+
if (!isTextModelInstalled(model, directory))
|
|
1733
|
+
throw new CliError("not_found", `${model.id} is not downloaded \u2014 ${downloadHint(model.id, command)}`, {
|
|
1734
|
+
reason: "model.not-downloaded",
|
|
1735
|
+
model: model.id
|
|
1736
|
+
});
|
|
1737
|
+
return { model, directory, key: vectorModelKey(model) };
|
|
1738
|
+
}, "localModel");
|
|
1739
|
+
var withLocal = /* @__PURE__ */ __name(async (model, directory, threads, work, shared) => {
|
|
1740
|
+
if (shared)
|
|
1741
|
+
return work(await shared.get(vectorModelKey(model), () => openEmbedder(model, directory, { threads: threads ?? defaultThreads() })));
|
|
1742
|
+
const embedder = await openEmbedder(model, directory, { threads: threads ?? defaultThreads() });
|
|
1743
|
+
try {
|
|
1744
|
+
return await work(embedder);
|
|
1745
|
+
} finally {
|
|
1746
|
+
await embedder.close();
|
|
1747
|
+
}
|
|
1748
|
+
}, "withLocal");
|
|
1749
|
+
var stopsAt = /* @__PURE__ */ __name((deadline) => deadline ? deadline.endsAt - deadlineMargin(deadline) : Number.POSITIVE_INFINITY, "stopsAt");
|
|
1750
|
+
var embedChunks = /* @__PURE__ */ __name(async (store, source, { model: choice, maxChunks = Number.POSITIVE_INFINITY, env, threads, command, deadline, signal } = {}) => {
|
|
1751
|
+
const { model, directory, key } = localModel(choice, env, command);
|
|
1752
|
+
if ((await source.chunksToEmbed(key, { limit: 1 })).length === 0)
|
|
1753
|
+
return { model: model.id, embedded: 0, left: false };
|
|
1754
|
+
const until = stopsAt(deadline);
|
|
1755
|
+
const stopped = /* @__PURE__ */ __name((slowest) => signal?.aborted ? "cancelled" : Date.now() + slowest >= until ? "deadline" : void 0, "stopped");
|
|
1756
|
+
const stop = /* @__PURE__ */ __name(async (embedded, why) => {
|
|
1757
|
+
const remaining = await source.chunksLeft?.(key);
|
|
1758
|
+
return { model: model.id, embedded, left: true, stopped: why, ...remaining === void 0 ? {} : { remaining } };
|
|
1759
|
+
}, "stop");
|
|
1760
|
+
const early = stopped(0);
|
|
1761
|
+
if (early)
|
|
1762
|
+
return stop(0, early);
|
|
1763
|
+
return withLocal(model, directory, threads, async (embedder) => {
|
|
1764
|
+
let embedded = 0;
|
|
1765
|
+
let after;
|
|
1766
|
+
let slowest = 0;
|
|
1767
|
+
while (embedded < maxChunks) {
|
|
1768
|
+
const started = Date.now();
|
|
1769
|
+
const batch = await source.chunksToEmbed(key, {
|
|
1770
|
+
limit: Math.min(NOTE_BATCH, maxChunks - embedded),
|
|
1771
|
+
...after === void 0 ? {} : { after }
|
|
1772
|
+
});
|
|
1773
|
+
if (batch.length === 0)
|
|
1774
|
+
break;
|
|
1775
|
+
const why = stopped(slowest);
|
|
1776
|
+
if (why)
|
|
1777
|
+
return stop(embedded, why);
|
|
1778
|
+
after = batch.at(-1)?.hash;
|
|
1779
|
+
const vectors = await embedder.embed(batch.map(({ text }) => text), "passage");
|
|
1780
|
+
await store.vectors.saveVectors(key, model.dims, batch.map(({ hash }, index) => ({ hash, vector: vectors[index] })));
|
|
1781
|
+
embedded += batch.length;
|
|
1782
|
+
slowest = Math.max(slowest, Date.now() - started);
|
|
1783
|
+
}
|
|
1784
|
+
const left = (await source.chunksToEmbed(key, { limit: 1, ...after === void 0 ? {} : { after } })).length > 0;
|
|
1785
|
+
return { model: model.id, embedded, left };
|
|
1786
|
+
});
|
|
1787
|
+
}, "embedChunks");
|
|
1788
|
+
var enrichedFirst = /* @__PURE__ */ __name(async (store, types, options2, embed) => {
|
|
1789
|
+
let enrichment;
|
|
1790
|
+
try {
|
|
1791
|
+
const run = await enrichRecords(store, {
|
|
1792
|
+
env: options2.env ?? process.env,
|
|
1793
|
+
narrow: { types },
|
|
1794
|
+
...options2.app ? { app: options2.app } : {},
|
|
1795
|
+
...options2.keyring ? { keyring: options2.keyring } : {},
|
|
1796
|
+
...options2.enrichWith,
|
|
1797
|
+
...options2.deadline ? { deadline: options2.deadline } : {},
|
|
1798
|
+
...options2.signal ? { signal: options2.signal } : {}
|
|
1799
|
+
});
|
|
1800
|
+
if (run.status !== "off")
|
|
1801
|
+
enrichment = run;
|
|
1802
|
+
} catch (error) {
|
|
1803
|
+
enrichment = {
|
|
1804
|
+
status: "failed",
|
|
1805
|
+
reason: error instanceof Error ? error.message : "enrichment failed",
|
|
1806
|
+
reason_id: "enrichment.error"
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1809
|
+
let embedded;
|
|
1810
|
+
try {
|
|
1811
|
+
embedded = await embed();
|
|
1812
|
+
} catch (error) {
|
|
1813
|
+
if (enrichment && error instanceof CliError)
|
|
1814
|
+
throw new CliError(error.code, error.message, { ...error.details, enrichment });
|
|
1815
|
+
throw error;
|
|
1816
|
+
}
|
|
1817
|
+
if (!enrichment)
|
|
1818
|
+
return embedded;
|
|
1819
|
+
const more = enrichment.status !== "failed" && enrichment.left > 0 && enrichment.enriched > 0;
|
|
1820
|
+
return { ...embedded, left: embedded.left || more, enrichment };
|
|
1821
|
+
}, "enrichedFirst");
|
|
1822
|
+
var embedNotes = /* @__PURE__ */ __name((store, options2 = {}) => enrichedFirst(store, ["document", "note"], options2, () => embedChunks(store, store.notes, options2)), "embedNotes");
|
|
1823
|
+
var embedEvents = /* @__PURE__ */ __name((store, options2 = {}) => embedChunks(store, store.calendar, options2), "embedEvents");
|
|
1824
|
+
var embedMail = /* @__PURE__ */ __name((store, options2 = {}) => enrichedFirst(store, ["email"], options2, () => embedChunks(store, store.mail, options2)), "embedMail");
|
|
1825
|
+
var nearestNotes = /* @__PURE__ */ __name(async (store, query, options2) => {
|
|
1826
|
+
const { key, vector, floor } = await queryVector(store, query, options2);
|
|
1827
|
+
const nearest2 = await store.notes.nearest(key, vector, {
|
|
1828
|
+
limit: options2.limit,
|
|
1829
|
+
...options2.folderIds ? { folderIds: options2.folderIds } : {},
|
|
1830
|
+
...options2.withInternal ? { withInternal: true } : {},
|
|
1831
|
+
...options2.source ? { source: options2.source } : {}
|
|
1832
|
+
});
|
|
1833
|
+
return nearest2.filter(({ score }) => score > floor);
|
|
1834
|
+
}, "nearestNotes");
|
|
1835
|
+
var queryVector = /* @__PURE__ */ __name(async (store, query, { model: choice, folderIds, withInternal, source, env, threads, command, embedders }) => {
|
|
1836
|
+
if (!query.trim())
|
|
1837
|
+
throw new CliError("validation_error", "say what to find in the notes");
|
|
1838
|
+
const { model, directory, key } = localModel(choice ?? await meaningModel(store, env), env, command);
|
|
1839
|
+
const scope = {
|
|
1840
|
+
...folderIds ? { folderIds } : {},
|
|
1841
|
+
...withInternal ? { withInternal: true } : {},
|
|
1842
|
+
...source ? { source } : {}
|
|
1843
|
+
};
|
|
1844
|
+
if (!await store.notes.embedded(key, scope))
|
|
1845
|
+
throw new CliError("not_found", `nothing searched here has vectors of ${model.id} yet, so only words were matched`);
|
|
1846
|
+
const [vector] = await withLocal(model, directory, threads, (embedder) => embedder.embed([query], "query"), embedders);
|
|
1847
|
+
return { key, vector, floor: meaningFloor(key) };
|
|
1848
|
+
}, "queryVector");
|
|
1849
|
+
var nearestAmong = /* @__PURE__ */ __name(async (store, query, refs, options2) => {
|
|
1850
|
+
const { key, vector, floor } = await queryVector(store, query, options2);
|
|
1851
|
+
return (await store.notes.scoreNotes(key, vector, refs)).filter(({ score }) => score > floor);
|
|
1852
|
+
}, "nearestAmong");
|
|
1853
|
+
var MAX_LINE2 = 200;
|
|
1854
|
+
var MAX_NOTES_OFFSET = 1e3;
|
|
1855
|
+
var CANDIDATES = 50;
|
|
1856
|
+
var firstLine = /* @__PURE__ */ __name((text, query) => {
|
|
1857
|
+
const words = query.toLowerCase().split(/\s+/).map((word) => word.replace(/^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu, "")).filter((word) => word.length > 2 && !["and", "or", "not"].includes(word));
|
|
1858
|
+
const lines = text.split("\n");
|
|
1859
|
+
const found = lines.find((line2) => words.some((word) => line2.toLowerCase().includes(word)));
|
|
1860
|
+
return (found ?? lines.find((line2) => line2.trim() !== "") ?? "").trim().slice(0, MAX_LINE2);
|
|
1861
|
+
}, "firstLine");
|
|
1862
|
+
var pictureLane = /* @__PURE__ */ __name(async (store, query, { folderIds, source, limit, env, command, embedder }) => {
|
|
1863
|
+
const words = plainWords(query);
|
|
1864
|
+
if (words === "" || source === "internal")
|
|
1865
|
+
return {};
|
|
1866
|
+
let vector;
|
|
1867
|
+
try {
|
|
1868
|
+
const use = embedder ?? await openPictureEmbedderFor({
|
|
1869
|
+
...env === void 0 ? {} : { env },
|
|
1870
|
+
...command === void 0 ? {} : { command }
|
|
1871
|
+
});
|
|
1872
|
+
try {
|
|
1873
|
+
vector = await use.embedQuery(words);
|
|
1874
|
+
} finally {
|
|
1875
|
+
if (!embedder)
|
|
1876
|
+
await use.close();
|
|
1877
|
+
}
|
|
1878
|
+
} catch (error) {
|
|
1879
|
+
if (error instanceof CliError && error.code === "not_found")
|
|
1880
|
+
return { pictures_skipped: error.message };
|
|
1881
|
+
throw error;
|
|
1882
|
+
}
|
|
1883
|
+
const near = await store.notes.nearestPictures(imageModel(DEFAULT_IMAGE_MODEL).key, vector, {
|
|
1884
|
+
limit,
|
|
1885
|
+
...folderIds === void 0 ? {} : { folderIds }
|
|
1886
|
+
});
|
|
1887
|
+
return {
|
|
1888
|
+
pictures: near.filter(({ score }) => score >= PICTURE_FLOOR).map(({ ref, score }) => ({ ref, score: Number(score.toFixed(4)) }))
|
|
1889
|
+
};
|
|
1890
|
+
}, "pictureLane");
|
|
1891
|
+
var noteSourceOfQuery = /* @__PURE__ */ __name((query) => {
|
|
1892
|
+
let root;
|
|
1893
|
+
try {
|
|
1894
|
+
root = parseLucene(query, { ...SEARCH_QUERY, defaultField: "text" }).root;
|
|
1895
|
+
} catch {
|
|
1896
|
+
return { rest: query };
|
|
1897
|
+
}
|
|
1898
|
+
const required = root.kind === "predicate" ? [root] : root.clauses.flatMap(({ occur, node }) => occur === "must" && node.kind === "predicate" ? [node] : []);
|
|
1899
|
+
const typed = required.find(({ field, operator }) => field === "source" && (operator === "term" || operator === "phrase"));
|
|
1900
|
+
const source = typed?.value.toLowerCase();
|
|
1901
|
+
if (typed === void 0 || source !== "internal" && source !== "file")
|
|
1902
|
+
return { rest: query };
|
|
1903
|
+
const rest = `${query.slice(0, typed.span.start).replace(/\s*(?:AND|&&)\s*$/u, "")} ${query.slice(typed.span.end).replace(/^\s*(?:AND|&&)\s*/u, "")}`.trim();
|
|
1904
|
+
try {
|
|
1905
|
+
if (rest)
|
|
1906
|
+
parseLucene(rest, { ...SEARCH_QUERY, defaultField: "text" });
|
|
1907
|
+
} catch {
|
|
1908
|
+
return { source, rest: query };
|
|
1909
|
+
}
|
|
1910
|
+
return { source, rest };
|
|
1911
|
+
}, "noteSourceOfQuery");
|
|
1912
|
+
var EVERY_NOTE = { kind: "predicate", field: "in", operator: "term", value: "notes" };
|
|
1913
|
+
var fieldsOfQuery2 = /* @__PURE__ */ __name((root) => fieldsOfQuery(root, EVERY_NOTE), "fieldsOfQuery");
|
|
1914
|
+
var allOf = /* @__PURE__ */ __name((nodes) => nodes.length <= 1 ? nodes[0] : {
|
|
1915
|
+
kind: "boolean",
|
|
1916
|
+
clauses: nodes.map((node) => ({ occur: "must", node })),
|
|
1917
|
+
span: { start: 0, end: 0 }
|
|
1918
|
+
}, "allOf");
|
|
1919
|
+
var matching = /* @__PURE__ */ __name(async (store, refs, root, scope) => {
|
|
1920
|
+
if (refs.length === 0)
|
|
1921
|
+
return /* @__PURE__ */ new Map();
|
|
1922
|
+
const resolved = await resolvedQuery(store, root ?? { ...EVERY_NOTE, span: { start: 0, end: 0 } }, scope.timezone);
|
|
1923
|
+
const found = await store.notes.search({
|
|
1924
|
+
root: resolved.root,
|
|
1925
|
+
refs,
|
|
1926
|
+
limit: refs.length,
|
|
1927
|
+
...scope.folderIds ? { folderIds: scope.folderIds } : {},
|
|
1928
|
+
...scope.withInternal ? { withInternal: true } : {},
|
|
1929
|
+
...scope.source ? { source: scope.source } : {},
|
|
1930
|
+
...resolved.stemmer ? { stemmer: resolved.stemmer } : {}
|
|
1931
|
+
});
|
|
1932
|
+
return new Map(found.items.map(({ ref, note, at }) => [ref, { note, at }]));
|
|
1933
|
+
}, "matching");
|
|
1934
|
+
var RANK_WITHIN = 2e3;
|
|
1935
|
+
var filterRefs = /* @__PURE__ */ __name(async (store, narrowing, scope) => {
|
|
1936
|
+
const resolved = await resolvedQuery(store, narrowing, scope.timezone);
|
|
1937
|
+
try {
|
|
1938
|
+
const found = await store.notes.matchingRefs({
|
|
1939
|
+
root: resolved.root,
|
|
1940
|
+
limit: RANK_WITHIN,
|
|
1941
|
+
...scope.folderIds ? { folderIds: scope.folderIds } : {},
|
|
1942
|
+
...scope.withInternal ? { withInternal: true } : {},
|
|
1943
|
+
...scope.source ? { source: scope.source } : {},
|
|
1944
|
+
...resolved.stemmer ? { stemmer: resolved.stemmer } : {}
|
|
1945
|
+
});
|
|
1946
|
+
return found.hasMore ? void 0 : found.refs;
|
|
1947
|
+
} catch (error) {
|
|
1948
|
+
if (isQueryLimit(error))
|
|
1949
|
+
return void 0;
|
|
1950
|
+
throw error;
|
|
1951
|
+
}
|
|
1952
|
+
}, "filterRefs");
|
|
1953
|
+
var notesTotal = /* @__PURE__ */ __name(async (store, text, { exact, scope, shown, hasMore }, others, othersComplete) => {
|
|
1954
|
+
let words;
|
|
1955
|
+
try {
|
|
1956
|
+
const { root, stemmer } = await storeQuery(store, text, {
|
|
1957
|
+
exact,
|
|
1958
|
+
...scope.timezone ? { timezone: scope.timezone } : {}
|
|
1959
|
+
});
|
|
1960
|
+
words = await store.notes.matchingRefs({
|
|
1961
|
+
root,
|
|
1962
|
+
limit: TOTAL_CAP,
|
|
1963
|
+
...scope.folderIds ? { folderIds: scope.folderIds } : {},
|
|
1964
|
+
...scope.withInternal ? { withInternal: true } : {},
|
|
1965
|
+
...scope.source ? { source: scope.source } : {},
|
|
1966
|
+
...stemmer ? { stemmer } : {}
|
|
1967
|
+
});
|
|
1968
|
+
} catch (error) {
|
|
1969
|
+
if (isQueryLimit(error))
|
|
1970
|
+
return totalOf(void 0, shown, hasMore);
|
|
1971
|
+
throw error;
|
|
1972
|
+
}
|
|
1973
|
+
const count = (/* @__PURE__ */ new Set([...words.refs, ...others])).size + (words.hasMore ? 1 : 0);
|
|
1974
|
+
return totalOf(count, shown, hasMore, othersComplete);
|
|
1975
|
+
}, "notesTotal");
|
|
1976
|
+
var searchNotes = /* @__PURE__ */ __name(async (store, query, { limit = 20, offset = 0, tag, filter: expression, folderIds, withInternal, source: given, exact = false, discover = false, timezone, env, command, embedders, pictures: withPictures2 = false, pictureLimit = 5, pictureEmbedder } = {}) => {
|
|
1977
|
+
query = plainQuery(query);
|
|
1978
|
+
const typed = noteSourceOfQuery(query);
|
|
1979
|
+
const source = given ?? typed.source;
|
|
1980
|
+
const rest = typed.source !== void 0 && typed.source === source ? typed.rest : query;
|
|
1981
|
+
const label = tag === void 0 ? void 0 : normalizeTag(tag);
|
|
1982
|
+
const filter = [expression ? `(${expression})` : "", label === void 0 ? "" : `tag:${label}`].filter(Boolean).join(" AND ") || void 0;
|
|
1983
|
+
const lookup = discover && !exact ? questionLookup(query) : void 0;
|
|
1984
|
+
const parsed = query.trim() ? parsedQuery(lookup === void 0 ? query : questionText(query), exact) : void 0;
|
|
1985
|
+
const words = parsed === void 0 ? "" : meaningWords(parsed);
|
|
1986
|
+
const narrowing = allOf([
|
|
1987
|
+
...parsed === void 0 ? [] : [fieldsOfQuery2(parsed)].filter((node) => node !== void 0),
|
|
1988
|
+
...filter === void 0 ? [] : [parsedQuery(filter)]
|
|
1989
|
+
]);
|
|
1990
|
+
const asked = lookup ?? query;
|
|
1991
|
+
const text = [asked.trim() ? `(${asked})` : "", filter ?? ""].filter(Boolean).join(" AND ");
|
|
1992
|
+
const window = offset + limit;
|
|
1993
|
+
const scope = {
|
|
1994
|
+
...folderIds === void 0 ? {} : { folderIds },
|
|
1995
|
+
...withInternal ? { withInternal: true } : {},
|
|
1996
|
+
...source === void 0 ? {} : { source },
|
|
1997
|
+
...timezone === void 0 ? {} : { timezone }
|
|
1998
|
+
};
|
|
1999
|
+
let meaningSkipped;
|
|
2000
|
+
let meaning;
|
|
2001
|
+
const cosines = /* @__PURE__ */ new Map();
|
|
2002
|
+
let meaningRefs;
|
|
2003
|
+
let meaningComplete = true;
|
|
2004
|
+
if (exact)
|
|
2005
|
+
meaningSkipped = "--exact searches words as written";
|
|
2006
|
+
else if (words) {
|
|
2007
|
+
const lane2 = {
|
|
2008
|
+
command,
|
|
2009
|
+
...env === void 0 ? {} : { env },
|
|
2010
|
+
...embedders === void 0 ? {} : { embedders },
|
|
2011
|
+
...folderIds === void 0 ? {} : { folderIds },
|
|
2012
|
+
...withInternal ? { withInternal: true } : {},
|
|
2013
|
+
...source === void 0 ? {} : { source }
|
|
2014
|
+
};
|
|
2015
|
+
const depth = Math.max(window, CANDIDATES);
|
|
2016
|
+
try {
|
|
2017
|
+
const within = narrowing === void 0 ? void 0 : await filterRefs(store, narrowing, scope);
|
|
2018
|
+
let nearest2;
|
|
2019
|
+
if (within === void 0) {
|
|
2020
|
+
nearest2 = await nearestNotes(store, words, { ...lane2, limit: depth });
|
|
2021
|
+
meaningComplete = nearest2.length < depth;
|
|
2022
|
+
} else {
|
|
2023
|
+
const ranked2 = within.length ? await nearestAmong(store, words, within, lane2) : [];
|
|
2024
|
+
meaningRefs = new Set(ranked2.map(({ ref }) => ref));
|
|
2025
|
+
nearest2 = ranked2.slice(0, depth);
|
|
2026
|
+
}
|
|
2027
|
+
const allowed = await matching(store, nearest2.map(({ ref }) => ref), narrowing, scope);
|
|
2028
|
+
meaning = nearest2.flatMap(({ ref, score }) => {
|
|
2029
|
+
const found = allowed.get(ref);
|
|
2030
|
+
if (found)
|
|
2031
|
+
cosines.set(ref, score);
|
|
2032
|
+
return found ? [{ ref, ...found }] : [];
|
|
2033
|
+
});
|
|
2034
|
+
meaningRefs ??= new Set(meaning.map(({ ref }) => ref));
|
|
2035
|
+
} catch (error) {
|
|
2036
|
+
if (!(error instanceof CliError && error.code === "not_found"))
|
|
2037
|
+
throw error;
|
|
2038
|
+
meaningSkipped = error.message;
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
const titleWords = plainQueryWords(rest);
|
|
2042
|
+
const titled = titleWords === void 0 ? { items: [], hasMore: false } : await searchNotesQuery(store, {
|
|
2043
|
+
text: [titleQuery(titleWords), filter ?? ""].filter(Boolean).join(" AND "),
|
|
2044
|
+
limit: Math.max(window, CANDIDATES),
|
|
2045
|
+
...scope
|
|
2046
|
+
});
|
|
2047
|
+
const tier = titleWords === void 0 ? [] : titleTiers(titled.items, titleWords);
|
|
2048
|
+
const tierRefs = new Set(tier.map(({ ref }) => ref));
|
|
2049
|
+
const slice = meaning === void 0 && tier.length === 0;
|
|
2050
|
+
const matched = await searchNotesQuery(store, {
|
|
2051
|
+
text,
|
|
2052
|
+
limit: slice ? limit : Math.max(window, CANDIDATES) + tier.length,
|
|
2053
|
+
offset: slice ? offset : 0,
|
|
2054
|
+
exact,
|
|
2055
|
+
...scope
|
|
2056
|
+
});
|
|
2057
|
+
const ranked = /* @__PURE__ */ new Map();
|
|
2058
|
+
const add = /* @__PURE__ */ __name((list, by) => list.forEach(({ ref, note, at }, rank) => {
|
|
2059
|
+
if (tierRefs.has(ref))
|
|
2060
|
+
return;
|
|
2061
|
+
const held = ranked.get(ref) ?? { note, at, score: 0, foundBy: [] };
|
|
2062
|
+
held.foundBy.push(by);
|
|
2063
|
+
ranked.set(ref, held);
|
|
2064
|
+
const vote = 1 / (RRF_K + rank + 1);
|
|
2065
|
+
if (by === "meaning" && lookup !== void 0 && held.foundBy.includes("words"))
|
|
2066
|
+
held.score = Math.max(held.score, vote);
|
|
2067
|
+
else
|
|
2068
|
+
held.score += vote;
|
|
2069
|
+
}), "add");
|
|
2070
|
+
add(matched.items, "words");
|
|
2071
|
+
if (meaning !== void 0)
|
|
2072
|
+
add(meaning, "meaning");
|
|
2073
|
+
const ordered = [
|
|
2074
|
+
...tier.map(({ ref, note, at }) => [ref, { note, at, score: 0, foundBy: ["title"] }]),
|
|
2075
|
+
...[...ranked.entries()].sort(([, a], [, b]) => b.score - a.score)
|
|
2076
|
+
];
|
|
2077
|
+
const page = slice ? ordered : ordered.slice(offset, window);
|
|
2078
|
+
const hasMore = slice ? matched.hasMore : ordered.length > window || matched.hasMore || titled.hasMore;
|
|
2079
|
+
const total = await notesTotal(store, text, { exact, scope, shown: offset + page.length, hasMore }, [...tier.map(({ ref }) => ref), ...meaningRefs ?? []], meaningComplete);
|
|
2080
|
+
const hits = [];
|
|
2081
|
+
const counts = /* @__PURE__ */ new Map();
|
|
2082
|
+
const accounts = await store.accounts.storedAccounts();
|
|
2083
|
+
const profiles = await store.accounts.profiles();
|
|
2084
|
+
for (const [ref, { note, at, foundBy }] of page) {
|
|
2085
|
+
const links = (await store.notes.links({ from: ref })).map(({ to, targetText, kind, anchor }) => ({
|
|
2086
|
+
to,
|
|
2087
|
+
target_text: targetText,
|
|
2088
|
+
kind,
|
|
2089
|
+
anchor
|
|
2090
|
+
}));
|
|
2091
|
+
hits.push({
|
|
2092
|
+
ref,
|
|
2093
|
+
source: note.source,
|
|
2094
|
+
folder_id: note.folderId,
|
|
2095
|
+
path: note.path,
|
|
2096
|
+
title: note.title,
|
|
2097
|
+
...documentSource(note, accounts, profiles, note.source === "file" ? (await store.files.ofDocument(note.ref))[0] : void 0),
|
|
2098
|
+
updated_at: at,
|
|
2099
|
+
excerpt: firstLine(note.text, words),
|
|
2100
|
+
links,
|
|
2101
|
+
found_by: foundBy,
|
|
2102
|
+
...cosines.has(ref) ? { meaning_score: cosines.get(ref) } : {}
|
|
2103
|
+
});
|
|
2104
|
+
for (const link2 of new Map(links.map((link3) => [link3.to ?? `?${link3.target_text}`, link3])).values()) {
|
|
2105
|
+
const key = link2.to ?? `?${link2.target_text}`;
|
|
2106
|
+
const known = counts.get(key) ?? { ref: link2.to, name: link2.target_text, notes: 0 };
|
|
2107
|
+
known.notes++;
|
|
2108
|
+
counts.set(key, known);
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
const names = new Map([...await store.knowledge.organizations(), ...await store.knowledge.projects()].map(({ ref, name }) => [
|
|
2112
|
+
ref,
|
|
2113
|
+
name
|
|
2114
|
+
]));
|
|
2115
|
+
for (const record of counts.values()) {
|
|
2116
|
+
if (record.ref && names.has(record.ref))
|
|
2117
|
+
record.name = names.get(record.ref) ?? record.name;
|
|
2118
|
+
if (record.ref?.startsWith("person:"))
|
|
2119
|
+
record.name = (await store.people.personByUid(record.ref.slice("person:".length)))?.name ?? record.name;
|
|
2120
|
+
if (record.ref?.startsWith("note:") || record.ref?.startsWith("document:"))
|
|
2121
|
+
record.name = (await store.notes.note(record.ref).catch(() => void 0))?.title ?? record.name;
|
|
2122
|
+
}
|
|
2123
|
+
const lane = withPictures2 ? await pictureLane(store, words, {
|
|
2124
|
+
folderIds,
|
|
2125
|
+
source,
|
|
2126
|
+
limit: pictureLimit,
|
|
2127
|
+
env,
|
|
2128
|
+
command,
|
|
2129
|
+
embedder: pictureEmbedder
|
|
2130
|
+
}) : {};
|
|
2131
|
+
if (lane.pictures && narrowing !== void 0) {
|
|
2132
|
+
const allowed = await matching(store, lane.pictures.map(({ ref }) => ref), narrowing, scope);
|
|
2133
|
+
lane.pictures = lane.pictures.filter(({ ref }) => allowed.has(ref));
|
|
2134
|
+
}
|
|
2135
|
+
return {
|
|
2136
|
+
query,
|
|
2137
|
+
...label === void 0 ? {} : { tag: label },
|
|
2138
|
+
...filter === void 0 ? {} : { filter },
|
|
2139
|
+
by: meaning === void 0 ? "words" : "words and meaning",
|
|
2140
|
+
...meaningSkipped === void 0 ? {} : { meaning_skipped: meaningSkipped },
|
|
2141
|
+
items: hits,
|
|
2142
|
+
total,
|
|
2143
|
+
hasMore,
|
|
2144
|
+
...hasMore && window <= MAX_NOTES_OFFSET ? { nextOffset: window } : {},
|
|
2145
|
+
linked: [...counts.values()].sort((a, b) => b.notes - a.notes || (a.name ?? a.ref ?? "").localeCompare(b.name ?? b.ref ?? "")),
|
|
2146
|
+
...lane
|
|
2147
|
+
};
|
|
2148
|
+
}, "searchNotes");
|
|
2149
|
+
var notesScopeOf = /* @__PURE__ */ __name((accounts, stored = []) => {
|
|
2150
|
+
const folderIds = accounts.filter(({ provider, account }) => provider !== "notes" || account !== INTERNAL_NOTES).map(({ provider, account }) => provider === "notes" ? account : String(stored.find((one) => one.provider === provider && one.account === account)?.id ?? 0));
|
|
2151
|
+
if (!folderIds.length)
|
|
2152
|
+
return { source: "internal" };
|
|
2153
|
+
return { folderIds, ...accounts.length > folderIds.length ? { withInternal: true } : {} };
|
|
2154
|
+
}, "notesScopeOf");
|
|
2155
|
+
var importAccounts = /* @__PURE__ */ __name(async (store) => (await store.accounts.storedAccounts()).filter(({ provider }) => isImportedProvider(provider)), "importAccounts");
|
|
2156
|
+
var searchNotesOf = /* @__PURE__ */ __name(async (store, account, text, { accounts: list, app, env, ...query }) => {
|
|
2157
|
+
text = plainQuery(text);
|
|
2158
|
+
const own = app?.command ?? query.command;
|
|
2159
|
+
const what = `${own === void 0 ? "" : `${own} `}search notes`;
|
|
2160
|
+
const held = [
|
|
2161
|
+
{ provider: "notes", account: INTERNAL_NOTES },
|
|
2162
|
+
...(await store.notes.folders()).map(({ id }) => ({ provider: "notes", account: id })),
|
|
2163
|
+
...(await store.notes.documentsAccounts()).map(({ id }) => ({ provider: "notes", account: id })),
|
|
2164
|
+
...[await store.notes.addedAccount()].flatMap((added) => added ? [{ provider: "notes", account: added.id }] : []),
|
|
2165
|
+
...(await importAccounts(store)).map(({ provider, account: account2 }) => ({ provider, account: account2 }))
|
|
2166
|
+
];
|
|
2167
|
+
const lock = groupLockOf(app, env);
|
|
2168
|
+
const typedScope = list ?? (lock === void 0 ? void 0 : `group:${lock}`);
|
|
2169
|
+
const notesScope = typedScope !== void 0 && /(^|,)\s*group:/i.test(typedScope) ? `${typedScope},${sourceOf(OWNER_NOTES)}` : typedScope;
|
|
2170
|
+
const named = notesScope === void 0 ? { accounts: held, skipped: [] } : fitting(entriesOfList(notesScope, await listContextOf(store, account, app, void 0, env)), ["notes", "documents"], what);
|
|
2171
|
+
const source = query.source ?? noteSourceOfQuery(text).source;
|
|
2172
|
+
const internal = /* @__PURE__ */ __name(({ provider, account: account2 }) => provider === "notes" && account2 === INTERNAL_NOTES, "internal");
|
|
2173
|
+
const typed = named.accounts.filter((one) => source === void 0 || internal(one) === (source === "internal"));
|
|
2174
|
+
if (!typed.length && list !== void 0)
|
|
2175
|
+
throw new CliError("validation_error", source === "internal" ? "the query's source:internal keeps the notes written in memo, and the --source list names none of them: add notes:internal to --source, or drop source:internal from the query" : "the query's source:file keeps the files from notes folders, and the --source list names none of them: add notes:<folder id> to --source, or drop source:file from the query");
|
|
2176
|
+
const scope = list === void 0 ? {} : notesScopeOf(typed, await store.accounts.storedAccounts());
|
|
2177
|
+
const found = await searchNotes(store, text, {
|
|
2178
|
+
...query,
|
|
2179
|
+
...scope,
|
|
2180
|
+
...source ? { source } : {},
|
|
2181
|
+
...env === void 0 ? {} : { env }
|
|
2182
|
+
});
|
|
2183
|
+
return {
|
|
2184
|
+
...found,
|
|
2185
|
+
accounts: typed.map(({ provider, account: account2 }) => ({ resource: "notes", provider, account: account2 })),
|
|
2186
|
+
skipped: named.skipped
|
|
2187
|
+
};
|
|
2188
|
+
}, "searchNotesOf");
|
|
2189
|
+
|
|
2190
|
+
export {
|
|
2191
|
+
accountStore,
|
|
2192
|
+
crossAccount,
|
|
2193
|
+
unlessBusy,
|
|
2194
|
+
accountStoreIfOpen,
|
|
2195
|
+
storeIfOpen,
|
|
2196
|
+
fromStore,
|
|
2197
|
+
nothingStored,
|
|
2198
|
+
OFFLINE,
|
|
2199
|
+
onlineDeps,
|
|
2200
|
+
storedDeps,
|
|
2201
|
+
storeModeDeps,
|
|
2202
|
+
withTimeLimit,
|
|
2203
|
+
throughWrapper,
|
|
2204
|
+
capability,
|
|
2205
|
+
NOT_GROUP_NAMES,
|
|
2206
|
+
inGroupOf,
|
|
2207
|
+
MAIL,
|
|
2208
|
+
groupLockOf,
|
|
2209
|
+
listContextOf,
|
|
2210
|
+
listedAccounts,
|
|
2211
|
+
accountsOfKind,
|
|
2212
|
+
readChatId,
|
|
2213
|
+
storedChatId,
|
|
2214
|
+
chatIdIn,
|
|
2215
|
+
profilesOnAccount,
|
|
2216
|
+
chatAmong,
|
|
2217
|
+
senderAmong,
|
|
2218
|
+
sendersMatching,
|
|
2219
|
+
chatsMatchingIn,
|
|
2220
|
+
withRecovery,
|
|
2221
|
+
actionable,
|
|
2222
|
+
batchProgress,
|
|
2223
|
+
mergeBatches,
|
|
2224
|
+
refreshedFiles,
|
|
2225
|
+
downloadMessage,
|
|
2226
|
+
saveFiles,
|
|
2227
|
+
save,
|
|
2228
|
+
GROUP_SETTINGS,
|
|
2229
|
+
FOLDER_KINDS,
|
|
2230
|
+
FOLDER_SKIPS,
|
|
2231
|
+
ADMIN_RIGHTS,
|
|
2232
|
+
senderIsMe,
|
|
2233
|
+
MEDIA_KINDS,
|
|
2234
|
+
PICTURE_MAX_BYTES,
|
|
2235
|
+
plainWords,
|
|
2236
|
+
pictureBytes,
|
|
2237
|
+
picturesService,
|
|
2238
|
+
withPictures,
|
|
2239
|
+
TOTAL_CAP,
|
|
2240
|
+
totalOf,
|
|
2241
|
+
fieldsOfQuery,
|
|
2242
|
+
meaningWords,
|
|
2243
|
+
meaningModel,
|
|
2244
|
+
endpointKeyName,
|
|
2245
|
+
embeddingKeys,
|
|
2246
|
+
modelGateway,
|
|
2247
|
+
ENRICHMENT_PROVIDERS,
|
|
2248
|
+
MODEL_CHOICE,
|
|
2249
|
+
enrichmentSettingPath,
|
|
2250
|
+
readEnrichmentSetting,
|
|
2251
|
+
writeEnrichmentSetting,
|
|
2252
|
+
enrichmentEndpoint,
|
|
2253
|
+
isEnrichmentProvider,
|
|
2254
|
+
enrichmentPrice,
|
|
2255
|
+
costOf,
|
|
2256
|
+
keyLookup,
|
|
2257
|
+
keyVariable,
|
|
2258
|
+
enrichmentState,
|
|
2259
|
+
plainQueryWords,
|
|
2260
|
+
storeQuery,
|
|
2261
|
+
searchNotesQuery,
|
|
2262
|
+
localModel,
|
|
2263
|
+
withLocal,
|
|
2264
|
+
embedNotes,
|
|
2265
|
+
embedEvents,
|
|
2266
|
+
embedMail,
|
|
2267
|
+
nearestNotes,
|
|
2268
|
+
noteSourceOfQuery,
|
|
2269
|
+
fieldsOfQuery2,
|
|
2270
|
+
RANK_WITHIN,
|
|
2271
|
+
searchNotes,
|
|
2272
|
+
notesScopeOf,
|
|
2273
|
+
importAccounts,
|
|
2274
|
+
searchNotesOf
|
|
2275
|
+
};
|