@bike4mind/cli 0.2.64-worktree-refactor-extract-search-query-builders.21815 → 0.2.64
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/bin/bike4mind-cli.mjs +6 -6
- package/dist/BubblewrapRuntime-BHbtqvLx.mjs +72 -0
- package/dist/ConfigStore-CllM6jOf.mjs +8614 -0
- package/dist/ImageStore-DaKT_Ew8.mjs +202 -0
- package/dist/ProxyManager-Dl2nFk-A.mjs +259 -0
- package/dist/ProxyManager-kiOD1X8-.mjs +3 -0
- package/dist/SandboxOrchestrator-BEW3rqYi.mjs +159 -0
- package/dist/SandboxOrchestrator-CHZgSR3P.mjs +3 -0
- package/dist/SandboxRuntimeAdapter-C1B4t20N.mjs +57 -0
- package/dist/SandboxRuntimeAdapter-D7UAG13n.mjs +3 -0
- package/dist/SeatbeltRuntime-D4m0VOcD.mjs +116 -0
- package/dist/StderrViolationParser-D0afQ3-1.mjs +70 -0
- package/dist/ViolationLogStore-CZl35HcA.mjs +96 -0
- package/dist/bashExecute-BTkdqlSs-5foM20Lb.mjs +466 -0
- package/dist/commands/doctorCommand.mjs +101 -0
- package/dist/commands/headlessCommand.mjs +319 -0
- package/dist/commands/mcpCommand.mjs +218 -0
- package/dist/commands/updateCommand.mjs +40 -0
- package/dist/createFile-yQfh8uvk-I-yM5DxC.mjs +63 -0
- package/dist/deleteFile-DKHfnyny-G3b1Kj2T.mjs +66 -0
- package/dist/globFiles-D1en6joM-8jekiXdX.mjs +100 -0
- package/dist/grepSearch-aMamoBn_-DCJcY8JS.mjs +173 -0
- package/dist/index.mjs +6722 -0
- package/dist/pathValidation-Cgjh5WQO-DiCZTcq6.mjs +63 -0
- package/dist/store-Dw1nZX2Y.mjs +128 -0
- package/dist/store-nZExNOWX.mjs +3 -0
- package/dist/terminalSetup-rmr1P8KF.mjs +254 -0
- package/dist/tools-C6M5aW8W.mjs +20907 -0
- package/dist/treeSitterEngine-DCSXcm_3.mjs +309 -0
- package/dist/types-DBEjF9YS.mjs +59 -0
- package/dist/types-DK3P88Px.mjs +3 -0
- package/dist/updateChecker-Cu9dkHxV.mjs +120 -0
- package/package.json +10 -10
- package/dist/BubblewrapRuntime-PMIOLWKR.js +0 -71
- package/dist/HydrationEngine-YL2HWJ3V.js +0 -9
- package/dist/ImageStore-MMUOUPI2.js +0 -224
- package/dist/ProxyManager-HEB4TLVX.js +0 -7
- package/dist/SandboxOrchestrator-UIJ5GYBB.js +0 -8
- package/dist/SandboxRuntimeAdapter-FQ56MAB2.js +0 -13
- package/dist/SeatbeltRuntime-EE3TTLEP.js +0 -98
- package/dist/StderrViolationParser-7OYPM2DJ.js +0 -59
- package/dist/ViolationLogStore-RIIUVURH.js +0 -104
- package/dist/artifactExtractor-R7DIP2XO.js +0 -180
- package/dist/bashExecute-GLGLD3JD.js +0 -379
- package/dist/chunk-4BIBE3J7.js +0 -48
- package/dist/chunk-5LZS5CVJ.js +0 -161
- package/dist/chunk-BDQBOLYG.js +0 -120
- package/dist/chunk-BPFEGDC7.js +0 -192
- package/dist/chunk-EPIYC3LA.js +0 -13770
- package/dist/chunk-G4ZGEQFT.js +0 -250
- package/dist/chunk-GQGOWACU.js +0 -770
- package/dist/chunk-J6ZBI6TI.js +0 -1079
- package/dist/chunk-JW3JRHH7.js +0 -12433
- package/dist/chunk-KQAMBXAW.js +0 -163
- package/dist/chunk-KUVV2NAB.js +0 -19125
- package/dist/chunk-LTLJRF6I.js +0 -44
- package/dist/chunk-PFBYGCOW.js +0 -449
- package/dist/chunk-QWB6ZYY4.js +0 -48
- package/dist/chunk-SGPRXN4C.js +0 -245
- package/dist/chunk-UZUHPHZC.js +0 -95
- package/dist/chunk-WBE7SQUB.js +0 -241
- package/dist/chunk-Y4WOJJM3.js +0 -147
- package/dist/commands/doctorCommand.js +0 -87
- package/dist/commands/headlessCommand.js +0 -380
- package/dist/commands/mcpCommand.js +0 -203
- package/dist/commands/updateCommand.js +0 -42
- package/dist/create-C4VEEEYR.js +0 -12
- package/dist/createFile-6PSPLW6R.js +0 -71
- package/dist/deleteFile-AUSRLWIK.js +0 -73
- package/dist/formatConverter-5QEJDW24.js +0 -7
- package/dist/globFiles-TSRN64N2.js +0 -120
- package/dist/grepSearch-634XWZOJ.js +0 -216
- package/dist/index.js +0 -6779
- package/dist/llmMarkdownGenerator-Z6NB26TT.js +0 -371
- package/dist/markdownGenerator-SK2ZQQL4.js +0 -269
- package/dist/mementoService-N4IM6QAC.js +0 -12
- package/dist/notificationDeduplicator-HUC53NEW.js +0 -9
- package/dist/src-F4KZCAA2.js +0 -319
- package/dist/src-ISX322I7.js +0 -1101
- package/dist/store-CAB6BV3P.js +0 -11
- package/dist/subtractCredits-D4KEM6VU.js +0 -12
- package/dist/terminalSetup-C5FHMLC3.js +0 -214
- package/dist/treeSitterEngine-4SGFQDY3.js +0 -330
- package/dist/types-KB5NP6T4.js +0 -7
- package/dist/utils-JCHWDM4Z.js +0 -31
package/dist/chunk-SGPRXN4C.js
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// package.json
|
|
4
|
-
var package_default = {
|
|
5
|
-
name: "@bike4mind/cli",
|
|
6
|
-
version: "0.2.64-worktree-refactor-extract-search-query-builders.21815+404e2d395",
|
|
7
|
-
type: "module",
|
|
8
|
-
description: "Interactive CLI tool for Bike4Mind with ReAct agents",
|
|
9
|
-
license: "UNLICENSED",
|
|
10
|
-
author: "Bike4Mind",
|
|
11
|
-
repository: {
|
|
12
|
-
type: "git",
|
|
13
|
-
url: "git+https://github.com/bike4mind/lumina5.git"
|
|
14
|
-
},
|
|
15
|
-
homepage: "https://github.com/bike4mind/lumina5#readme",
|
|
16
|
-
bugs: "https://github.com/bike4mind/lumina5/issues",
|
|
17
|
-
publishConfig: {
|
|
18
|
-
access: "public"
|
|
19
|
-
},
|
|
20
|
-
keywords: [
|
|
21
|
-
"cli",
|
|
22
|
-
"ai",
|
|
23
|
-
"bike4mind",
|
|
24
|
-
"agent",
|
|
25
|
-
"mcp",
|
|
26
|
-
"react-agent"
|
|
27
|
-
],
|
|
28
|
-
bin: {
|
|
29
|
-
b4m: "./bin/bike4mind-cli.mjs",
|
|
30
|
-
bike4mind: "./bin/bike4mind-cli.mjs"
|
|
31
|
-
},
|
|
32
|
-
files: [
|
|
33
|
-
"dist",
|
|
34
|
-
"bin"
|
|
35
|
-
],
|
|
36
|
-
scripts: {
|
|
37
|
-
dev: "tsx src/index.tsx",
|
|
38
|
-
build: "tsup",
|
|
39
|
-
typecheck: "tsc --noEmit",
|
|
40
|
-
test: "vitest run",
|
|
41
|
-
"test:watch": "vitest",
|
|
42
|
-
start: "node dist/index.js",
|
|
43
|
-
prepublishOnly: "pnpm build",
|
|
44
|
-
postinstall: `node -e "try { require('better-sqlite3') } catch(e) { if(e.message.includes('bindings')) { console.log('\\n\u26A0\uFE0F Rebuilding better-sqlite3 native bindings...'); require('child_process').execSync('pnpm rebuild better-sqlite3', {stdio:'inherit'}) } }"`
|
|
45
|
-
},
|
|
46
|
-
dependencies: {
|
|
47
|
-
"@anthropic-ai/sdk": "^0.79.0",
|
|
48
|
-
"@aws-sdk/client-apigatewaymanagementapi": "^3.1012.0",
|
|
49
|
-
"@aws-sdk/client-bedrock-runtime": "^3.1012.0",
|
|
50
|
-
"@aws-sdk/client-cloudwatch": "^3.1012.0",
|
|
51
|
-
"@aws-sdk/client-lambda": "^3.1012.0",
|
|
52
|
-
"@aws-sdk/client-s3": "^3.1012.0",
|
|
53
|
-
"@aws-sdk/client-sqs": "^3.1012.0",
|
|
54
|
-
"@aws-sdk/client-transcribe": "^3.1012.0",
|
|
55
|
-
"@aws-sdk/credential-provider-node": "^3.972.22",
|
|
56
|
-
"@aws-sdk/s3-request-presigner": "^3.1012.0",
|
|
57
|
-
"@casl/ability": "^6.8.0",
|
|
58
|
-
"@google/genai": "^1.46.0",
|
|
59
|
-
"@joplin/turndown-plugin-gfm": "^1.0.64",
|
|
60
|
-
"@mendable/firecrawl-js": "^1.29.3",
|
|
61
|
-
"@modelcontextprotocol/sdk": "1.27.1",
|
|
62
|
-
"@octokit/rest": "^22.0.1",
|
|
63
|
-
"@opensearch-project/opensearch": "2.11.0",
|
|
64
|
-
"@smithy/node-http-handler": "^4.5.0",
|
|
65
|
-
"async-mutex": "^0.5.0",
|
|
66
|
-
axios: "^1.13.6",
|
|
67
|
-
bcryptjs: "^3.0.2",
|
|
68
|
-
"better-sqlite3": "^12.8.0",
|
|
69
|
-
cheerio: "1.0.0-rc.12",
|
|
70
|
-
"cli-highlight": "^2.1.11",
|
|
71
|
-
"csv-parse": "^6.2.0",
|
|
72
|
-
dayjs: "^1.11.20",
|
|
73
|
-
diff: "^8.0.2",
|
|
74
|
-
dotenv: "^17.0.0",
|
|
75
|
-
"eventsource-parser": "^3.0.6",
|
|
76
|
-
exceljs: "^4.4.0",
|
|
77
|
-
fdir: "^6.5.0",
|
|
78
|
-
"file-type": "^18.7.0",
|
|
79
|
-
"fuse.js": "^7.1.0",
|
|
80
|
-
fzf: "^0.5.2",
|
|
81
|
-
glob: "^13.0.6",
|
|
82
|
-
"gray-matter": "^4.0.3",
|
|
83
|
-
ignore: "^7.0.5",
|
|
84
|
-
ink: "^6.8.0",
|
|
85
|
-
"ink-select-input": "^6.2.0",
|
|
86
|
-
"ink-spinner": "^5.0.0",
|
|
87
|
-
"ink-text-input": "^6.0.0",
|
|
88
|
-
jsonwebtoken: "^9.0.3",
|
|
89
|
-
lodash: "^4.17.21",
|
|
90
|
-
mammoth: "^1.12.0",
|
|
91
|
-
marked: "^15.0.11",
|
|
92
|
-
mathjs: "^14.2.0",
|
|
93
|
-
"mime-types": "^2.1.35",
|
|
94
|
-
mongoose: "^8.8.3",
|
|
95
|
-
ollama: "^0.6.3",
|
|
96
|
-
open: "^11.0.0",
|
|
97
|
-
openai: "^6.32.0",
|
|
98
|
-
"p-limit": "^7.3.0",
|
|
99
|
-
picomatch: "^4.0.3",
|
|
100
|
-
qrcode: "^1.5.4",
|
|
101
|
-
react: "^19.2.4",
|
|
102
|
-
sharp: "^0.34.5",
|
|
103
|
-
speakeasy: "^2.0.0",
|
|
104
|
-
tiktoken: "^1.0.22",
|
|
105
|
-
"tree-sitter-wasms": "^0.1.13",
|
|
106
|
-
turndown: "^7.2.2",
|
|
107
|
-
undici: "^7.24.4",
|
|
108
|
-
unpdf: "^0.10.0",
|
|
109
|
-
uuid: "^13.0.0",
|
|
110
|
-
voyageai: "^0.0.4",
|
|
111
|
-
"web-tree-sitter": "0.25.10",
|
|
112
|
-
ws: "^8.19.0",
|
|
113
|
-
xlsx: "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
|
|
114
|
-
yargs: "^17.7.2",
|
|
115
|
-
yauzl: "^3.1.3",
|
|
116
|
-
zod: "^4.3.6",
|
|
117
|
-
"zod-validation-error": "^5.0.0",
|
|
118
|
-
zustand: "^4.5.4"
|
|
119
|
-
},
|
|
120
|
-
devDependencies: {
|
|
121
|
-
"@bike4mind/agents": "0.4.2-worktree-refactor-extract-search-query-builders.21815+404e2d395",
|
|
122
|
-
"@bike4mind/common": "2.75.1-worktree-refactor-extract-search-query-builders.21815+404e2d395",
|
|
123
|
-
"@bike4mind/mcp": "1.33.21-worktree-refactor-extract-search-query-builders.21815+404e2d395",
|
|
124
|
-
"@bike4mind/services": "2.69.1-worktree-refactor-extract-search-query-builders.21815+404e2d395",
|
|
125
|
-
"@bike4mind/utils": "2.16.3-worktree-refactor-extract-search-query-builders.21815+404e2d395",
|
|
126
|
-
"@types/better-sqlite3": "^7.6.13",
|
|
127
|
-
"@types/jsonwebtoken": "^9.0.4",
|
|
128
|
-
"@types/node": "^22.9.0",
|
|
129
|
-
"@types/picomatch": "^4.0.2",
|
|
130
|
-
"@types/react": "^19.2.14",
|
|
131
|
-
"@types/ws": "^8.18.1",
|
|
132
|
-
"@types/yargs": "^17.0.35",
|
|
133
|
-
"ink-testing-library": "^4.0.0",
|
|
134
|
-
tsup: "^8.5.1",
|
|
135
|
-
tsx: "^4.21.0",
|
|
136
|
-
typescript: "^5.9.3",
|
|
137
|
-
vitest: "^4.1.0"
|
|
138
|
-
},
|
|
139
|
-
optionalDependencies: {
|
|
140
|
-
"@vscode/ripgrep": "^1.17.1"
|
|
141
|
-
},
|
|
142
|
-
gitHead: "404e2d3952995da448d39a93f695efb03884dcdd"
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
// src/utils/updateChecker.ts
|
|
146
|
-
import { promises as fs } from "fs";
|
|
147
|
-
import path from "path";
|
|
148
|
-
import { homedir } from "os";
|
|
149
|
-
import axios from "axios";
|
|
150
|
-
var CACHE_FILE = path.join(homedir(), ".bike4mind", "update-check.json");
|
|
151
|
-
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
152
|
-
var NPM_REGISTRY_URL = "https://registry.npmjs.org/@bike4mind/cli/latest";
|
|
153
|
-
var FETCH_TIMEOUT_MS = 5e3;
|
|
154
|
-
function compareSemver(a, b) {
|
|
155
|
-
const partsA = a.split(".").map(Number);
|
|
156
|
-
const partsB = b.split(".").map(Number);
|
|
157
|
-
for (let i = 0; i < 3; i++) {
|
|
158
|
-
const segA = partsA[i] ?? 0;
|
|
159
|
-
const segB = partsB[i] ?? 0;
|
|
160
|
-
if (segA < segB) return -1;
|
|
161
|
-
if (segA > segB) return 1;
|
|
162
|
-
}
|
|
163
|
-
return 0;
|
|
164
|
-
}
|
|
165
|
-
async function fetchLatestVersion() {
|
|
166
|
-
try {
|
|
167
|
-
const response = await axios.get(NPM_REGISTRY_URL, {
|
|
168
|
-
timeout: FETCH_TIMEOUT_MS,
|
|
169
|
-
headers: { Accept: "application/json" }
|
|
170
|
-
});
|
|
171
|
-
const version = response.data?.version;
|
|
172
|
-
return typeof version === "string" ? version : null;
|
|
173
|
-
} catch {
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
async function readCache() {
|
|
178
|
-
try {
|
|
179
|
-
const data = await fs.readFile(CACHE_FILE, "utf-8");
|
|
180
|
-
const parsed = JSON.parse(data);
|
|
181
|
-
if (parsed && typeof parsed.lastChecked === "string" && typeof parsed.latestVersion === "string") {
|
|
182
|
-
return parsed;
|
|
183
|
-
}
|
|
184
|
-
return null;
|
|
185
|
-
} catch {
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
async function writeCache(cache) {
|
|
190
|
-
try {
|
|
191
|
-
await fs.mkdir(path.dirname(CACHE_FILE), { recursive: true });
|
|
192
|
-
await fs.writeFile(CACHE_FILE, JSON.stringify(cache, null, 2), "utf-8");
|
|
193
|
-
} catch {
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
async function checkForUpdate(currentVersion) {
|
|
197
|
-
try {
|
|
198
|
-
const cache = await readCache();
|
|
199
|
-
if (cache && cache.currentVersion === currentVersion) {
|
|
200
|
-
const age = Date.now() - new Date(cache.lastChecked).getTime();
|
|
201
|
-
if (age < CACHE_TTL_MS) {
|
|
202
|
-
return {
|
|
203
|
-
currentVersion,
|
|
204
|
-
latestVersion: cache.latestVersion,
|
|
205
|
-
updateAvailable: compareSemver(cache.latestVersion, currentVersion) > 0
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
const latestVersion = await fetchLatestVersion();
|
|
210
|
-
if (!latestVersion) return null;
|
|
211
|
-
await writeCache({
|
|
212
|
-
lastChecked: (/* @__PURE__ */ new Date()).toISOString(),
|
|
213
|
-
latestVersion,
|
|
214
|
-
currentVersion
|
|
215
|
-
});
|
|
216
|
-
return {
|
|
217
|
-
currentVersion,
|
|
218
|
-
latestVersion,
|
|
219
|
-
updateAvailable: compareSemver(latestVersion, currentVersion) > 0
|
|
220
|
-
};
|
|
221
|
-
} catch {
|
|
222
|
-
return null;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
async function forceCheckForUpdate(currentVersion) {
|
|
226
|
-
const latestVersion = await fetchLatestVersion();
|
|
227
|
-
if (!latestVersion) return null;
|
|
228
|
-
await writeCache({
|
|
229
|
-
lastChecked: (/* @__PURE__ */ new Date()).toISOString(),
|
|
230
|
-
latestVersion,
|
|
231
|
-
currentVersion
|
|
232
|
-
});
|
|
233
|
-
return {
|
|
234
|
-
currentVersion,
|
|
235
|
-
latestVersion,
|
|
236
|
-
updateAvailable: compareSemver(latestVersion, currentVersion) > 0
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export {
|
|
241
|
-
package_default,
|
|
242
|
-
fetchLatestVersion,
|
|
243
|
-
checkForUpdate,
|
|
244
|
-
forceCheckForUpdate
|
|
245
|
-
};
|
package/dist/chunk-UZUHPHZC.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
BadRequestError,
|
|
4
|
-
checkStorageLimitForFile,
|
|
5
|
-
getFileExtension,
|
|
6
|
-
getMimeTypeByExtension,
|
|
7
|
-
getSettingsMap,
|
|
8
|
-
getSettingsValue,
|
|
9
|
-
secureParameters
|
|
10
|
-
} from "./chunk-EPIYC3LA.js";
|
|
11
|
-
import {
|
|
12
|
-
KnowledgeType,
|
|
13
|
-
SupportedFabFileMimeTypes
|
|
14
|
-
} from "./chunk-JW3JRHH7.js";
|
|
15
|
-
|
|
16
|
-
// ../../b4m-core/packages/services/dist/src/fabFileService/create.js
|
|
17
|
-
import { z } from "zod";
|
|
18
|
-
import { v4 as uuidv4 } from "uuid";
|
|
19
|
-
var createFabFileSchema = z.object({
|
|
20
|
-
fileName: z.string(),
|
|
21
|
-
mimeType: z.string(),
|
|
22
|
-
fileSize: z.number(),
|
|
23
|
-
type: z.enum(KnowledgeType),
|
|
24
|
-
content: z.union([z.string(), z.instanceof(Buffer)]).optional(),
|
|
25
|
-
organizationId: z.string().optional(),
|
|
26
|
-
/**
|
|
27
|
-
* Content type of the file
|
|
28
|
-
* @example 'text/markdown'
|
|
29
|
-
* @example 'application/pdf'
|
|
30
|
-
* @example 'application/octet-stream' for binary files
|
|
31
|
-
*/
|
|
32
|
-
contentType: z.string().optional(),
|
|
33
|
-
public: z.boolean().optional(),
|
|
34
|
-
prefix: z.string().optional(),
|
|
35
|
-
system: z.boolean().optional(),
|
|
36
|
-
tags: z.array(z.object({ name: z.string(), strength: z.number() })).optional(),
|
|
37
|
-
systemPriority: z.number().optional(),
|
|
38
|
-
sessionId: z.string().optional(),
|
|
39
|
-
contentHash: z.string().optional(),
|
|
40
|
-
batchId: z.string().optional(),
|
|
41
|
-
relativePath: z.string().optional()
|
|
42
|
-
});
|
|
43
|
-
var DEFAULT_MAX_FILE_SIZE = 20;
|
|
44
|
-
var DEFAULT_EXPIRE_IN_SECONDS = 3600 * 24 * 5;
|
|
45
|
-
var createFabFile = async (userId, parameters, { db, storage }) => {
|
|
46
|
-
const params = secureParameters(parameters, createFabFileSchema);
|
|
47
|
-
const user = await db.users.findById(userId);
|
|
48
|
-
if (!user)
|
|
49
|
-
throw new BadRequestError("User not found");
|
|
50
|
-
let ext = "";
|
|
51
|
-
let mimeType = parameters.mimeType;
|
|
52
|
-
ext = getFileExtension(params.fileName);
|
|
53
|
-
mimeType = params.mimeType || getMimeTypeByExtension(ext);
|
|
54
|
-
if (!mimeType) {
|
|
55
|
-
mimeType = SupportedFabFileMimeTypes.TXT_PLAIN;
|
|
56
|
-
}
|
|
57
|
-
if (!Object.values(SupportedFabFileMimeTypes).some((type) => type === mimeType)) {
|
|
58
|
-
throw new BadRequestError(`File type ${mimeType} is not supported`);
|
|
59
|
-
}
|
|
60
|
-
let filePath = params.prefix ? `${params.prefix}/` : "";
|
|
61
|
-
filePath += `${uuidv4()}${ext ? `.${ext}` : ".txt"}`;
|
|
62
|
-
const maxFileSize = getSettingsValue("MaxFileSize", await getSettingsMap(db), DEFAULT_MAX_FILE_SIZE) * 1024 * 1024;
|
|
63
|
-
if (params.fileSize >= maxFileSize)
|
|
64
|
-
throw new BadRequestError("File size exceeds maximum file size");
|
|
65
|
-
await checkStorageLimitForFile(user, params.fileSize, params.organizationId, db.organizations?.findById);
|
|
66
|
-
const buildData = {
|
|
67
|
-
userId,
|
|
68
|
-
...params,
|
|
69
|
-
mimeType,
|
|
70
|
-
filePath,
|
|
71
|
-
users: [],
|
|
72
|
-
groups: [],
|
|
73
|
-
isGlobalRead: false,
|
|
74
|
-
isGlobalWrite: false,
|
|
75
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
76
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
77
|
-
};
|
|
78
|
-
if (params.content) {
|
|
79
|
-
await storage.upload(filePath, params.content, {
|
|
80
|
-
ContentType: params.contentType,
|
|
81
|
-
ContentLength: params.fileSize
|
|
82
|
-
});
|
|
83
|
-
buildData.fileUrl = await storage.generateSignedUrl(filePath, DEFAULT_EXPIRE_IN_SECONDS, "get");
|
|
84
|
-
buildData.fileUrlExpireAt = new Date(Date.now() + DEFAULT_EXPIRE_IN_SECONDS * 1e3);
|
|
85
|
-
} else {
|
|
86
|
-
buildData.presignedUrl = await storage.generateSignedUrl(filePath, 600, "put");
|
|
87
|
-
}
|
|
88
|
-
const result = await db.fabFiles.create(buildData);
|
|
89
|
-
return result;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export {
|
|
93
|
-
createFabFileSchema,
|
|
94
|
-
createFabFile
|
|
95
|
-
};
|
package/dist/chunk-WBE7SQUB.js
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
EmbeddingFactory,
|
|
4
|
-
computeCosineSimilarity,
|
|
5
|
-
getProviderFromModel,
|
|
6
|
-
getSettingsByNames,
|
|
7
|
-
obfuscateApiKey,
|
|
8
|
-
secureParameters
|
|
9
|
-
} from "./chunk-EPIYC3LA.js";
|
|
10
|
-
import {
|
|
11
|
-
ApiKeyType,
|
|
12
|
-
MementoTier,
|
|
13
|
-
isSupportedEmbeddingModel
|
|
14
|
-
} from "./chunk-JW3JRHH7.js";
|
|
15
|
-
|
|
16
|
-
// ../../b4m-core/packages/services/dist/src/apiKeyService/get.js
|
|
17
|
-
import { z } from "zod";
|
|
18
|
-
var getApiKeySchema = z.object({
|
|
19
|
-
type: z.enum(ApiKeyType),
|
|
20
|
-
nullIfMissing: z.boolean().optional(),
|
|
21
|
-
obfuscate: z.boolean().optional(),
|
|
22
|
-
demoKeyName: z.string().optional()
|
|
23
|
-
});
|
|
24
|
-
var getApiKey = async (userId, params, { db }) => {
|
|
25
|
-
const { type, obfuscate } = secureParameters(params, getApiKeySchema);
|
|
26
|
-
const apiKey = await db.apiKeys.findByUserIdAndType(userId, type);
|
|
27
|
-
if (apiKey && obfuscate) {
|
|
28
|
-
return {
|
|
29
|
-
...apiKey,
|
|
30
|
-
apiKey: obfuscateApiKey(apiKey.apiKey)
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
return apiKey;
|
|
34
|
-
};
|
|
35
|
-
var getMultipleApiKeys = async (userId, types, { db }, options) => {
|
|
36
|
-
const apiKeys = await db.apiKeys.findByUserIdAndTypes(userId, types);
|
|
37
|
-
if (options?.obfuscate) {
|
|
38
|
-
return apiKeys.map((apiKey) => ({
|
|
39
|
-
...apiKey,
|
|
40
|
-
apiKey: obfuscateApiKey(apiKey.apiKey)
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
return apiKeys;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// ../../b4m-core/packages/services/dist/src/apiKeyService/getEffective.js
|
|
47
|
-
var DEMO_KEY_MAP = {
|
|
48
|
-
[ApiKeyType.openai]: "openaiDemoKey",
|
|
49
|
-
[ApiKeyType.anthropic]: "anthropicDemoKey",
|
|
50
|
-
[ApiKeyType.gemini]: "geminiDemoKey",
|
|
51
|
-
[ApiKeyType.xai]: "xaiApiKey",
|
|
52
|
-
[ApiKeyType.bfl]: "bflApiKey",
|
|
53
|
-
[ApiKeyType.voyageai]: "voyageApiKey"
|
|
54
|
-
};
|
|
55
|
-
var getSerperKey = async (adapters) => {
|
|
56
|
-
const { db } = adapters;
|
|
57
|
-
const settings = await db.adminSettings.findBySettingName("SerperKey");
|
|
58
|
-
return settings?.settingValue;
|
|
59
|
-
};
|
|
60
|
-
var getOpenWeatherKey = async (adapters) => {
|
|
61
|
-
const { db } = adapters;
|
|
62
|
-
const settings = await db.adminSettings.findBySettingName("OpenWeatherKey");
|
|
63
|
-
return settings?.settingValue;
|
|
64
|
-
};
|
|
65
|
-
var getWolframAlphaKey = async (adapters) => {
|
|
66
|
-
const { db } = adapters;
|
|
67
|
-
const settings = await db.adminSettings.findBySettingName("WolframAlphaKey");
|
|
68
|
-
return settings?.settingValue;
|
|
69
|
-
};
|
|
70
|
-
var getEffectiveApiKey = async (userId, params, adapters) => {
|
|
71
|
-
const { db } = adapters;
|
|
72
|
-
const apiKey = await getApiKey(userId, params, adapters);
|
|
73
|
-
let key = apiKey?.apiKey;
|
|
74
|
-
if (!key) {
|
|
75
|
-
const demoKeyName = params.demoKeyName || DEMO_KEY_MAP[params.type];
|
|
76
|
-
if (demoKeyName) {
|
|
77
|
-
const settings = await db.adminSettings.findBySettingName(demoKeyName);
|
|
78
|
-
key = settings?.settingValue;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return key;
|
|
82
|
-
};
|
|
83
|
-
var getEffectiveLLMApiKeys = async (userId, adapters, options) => {
|
|
84
|
-
const { db } = adapters;
|
|
85
|
-
const logger = options?.logger;
|
|
86
|
-
const apiKeyFetchStartTime = Date.now();
|
|
87
|
-
const adminSettingNames = [
|
|
88
|
-
"openaiDemoKey",
|
|
89
|
-
"anthropicDemoKey",
|
|
90
|
-
"geminiDemoKey",
|
|
91
|
-
"bflApiKey",
|
|
92
|
-
"xaiApiKey",
|
|
93
|
-
"voyageApiKey",
|
|
94
|
-
"ollamaBackend",
|
|
95
|
-
"EnableOllama"
|
|
96
|
-
];
|
|
97
|
-
const [userApiKeys, adminSettings] = await Promise.all([
|
|
98
|
-
getMultipleApiKeys(userId, [ApiKeyType.openai, ApiKeyType.anthropic, ApiKeyType.gemini, ApiKeyType.bfl, ApiKeyType.xai, ApiKeyType.voyageai], adapters),
|
|
99
|
-
getSettingsByNames(adminSettingNames, { adminSettings: db.adminSettings }, { logger })
|
|
100
|
-
]);
|
|
101
|
-
const userKeyMap = /* @__PURE__ */ new Map();
|
|
102
|
-
userApiKeys.forEach((key) => userKeyMap.set(key.type, key));
|
|
103
|
-
const openaiUserKey = userKeyMap.get(ApiKeyType.openai) || null;
|
|
104
|
-
const anthropicUserKey = userKeyMap.get(ApiKeyType.anthropic) || null;
|
|
105
|
-
const geminiUserKey = userKeyMap.get(ApiKeyType.gemini) || null;
|
|
106
|
-
const bflUserKey = userKeyMap.get(ApiKeyType.bfl) || null;
|
|
107
|
-
const xaiUserKey = userKeyMap.get(ApiKeyType.xai) || null;
|
|
108
|
-
const voyageaiUserKey = userKeyMap.get(ApiKeyType.voyageai) || null;
|
|
109
|
-
const openaiDemoKey = adminSettings["openaiDemoKey"];
|
|
110
|
-
const anthropicDemoKey = adminSettings["anthropicDemoKey"];
|
|
111
|
-
const geminiDemoKey = adminSettings["geminiDemoKey"];
|
|
112
|
-
const bflDemoKey = adminSettings["bflApiKey"];
|
|
113
|
-
const xaiDemoKey = adminSettings["xaiApiKey"];
|
|
114
|
-
const voyageaiDemoKey = adminSettings["voyageApiKey"];
|
|
115
|
-
const ollamaBackend = adminSettings["ollamaBackend"];
|
|
116
|
-
const enableOllama = adminSettings["EnableOllama"];
|
|
117
|
-
const totalTime = Date.now() - apiKeyFetchStartTime;
|
|
118
|
-
if (logger) {
|
|
119
|
-
logger.info(`\u{1F4E6} API key + admin settings parallel fetch completed in ${totalTime}ms`);
|
|
120
|
-
}
|
|
121
|
-
const ollamaEnabled = enableOllama === "true" || enableOllama === true;
|
|
122
|
-
const keyOrExpired = (apiKey) => {
|
|
123
|
-
if (!apiKey)
|
|
124
|
-
return null;
|
|
125
|
-
if (apiKey.expiresAt && apiKey.expiresAt < /* @__PURE__ */ new Date())
|
|
126
|
-
return "expired";
|
|
127
|
-
return apiKey.apiKey;
|
|
128
|
-
};
|
|
129
|
-
return {
|
|
130
|
-
openai: keyOrExpired(openaiUserKey) || openaiDemoKey || null,
|
|
131
|
-
anthropic: keyOrExpired(anthropicUserKey) || anthropicDemoKey || null,
|
|
132
|
-
gemini: keyOrExpired(geminiUserKey) || geminiDemoKey || null,
|
|
133
|
-
bfl: keyOrExpired(bflUserKey) || bflDemoKey || null,
|
|
134
|
-
xai: keyOrExpired(xaiUserKey) || xaiDemoKey || null,
|
|
135
|
-
voyageai: keyOrExpired(voyageaiUserKey) || voyageaiDemoKey || null,
|
|
136
|
-
ollama: ollamaEnabled ? ollamaBackend || null : null
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
// ../../b4m-core/packages/services/dist/src/mementoService/getRelevantMementos.js
|
|
141
|
-
async function getRelevantMementos(userId, prompt, options = {}, adapters) {
|
|
142
|
-
const { topK = 5, minSimilarity = 0.7, tier = MementoTier.HOT, embeddingModel: providedEmbeddingModel, apiKeyTable: providedApiKeyTable, logger } = options;
|
|
143
|
-
logger?.updateMetadata({
|
|
144
|
-
promptLength: prompt.length
|
|
145
|
-
});
|
|
146
|
-
const apiKeyTable = providedApiKeyTable || await getEffectiveLLMApiKeys(userId, {
|
|
147
|
-
db: {
|
|
148
|
-
apiKeys: adapters.db.apiKeys,
|
|
149
|
-
adminSettings: adapters.db.adminSettings
|
|
150
|
-
}
|
|
151
|
-
}, { logger });
|
|
152
|
-
let embeddingModel = providedEmbeddingModel;
|
|
153
|
-
if (!embeddingModel) {
|
|
154
|
-
const defaultModel = await adapters.db.adminSettings.getSettingsValue("defaultEmbeddingModel");
|
|
155
|
-
if (!defaultModel || !isSupportedEmbeddingModel(defaultModel)) {
|
|
156
|
-
throw new Error("Default embedding model not configured. Please configure it in admin settings.");
|
|
157
|
-
}
|
|
158
|
-
embeddingModel = defaultModel;
|
|
159
|
-
}
|
|
160
|
-
logger?.debug?.("Using embedding model for memento retrieval:", embeddingModel);
|
|
161
|
-
const requiredProvider = getProviderFromModel(embeddingModel);
|
|
162
|
-
const embeddingConfig = {};
|
|
163
|
-
if (requiredProvider === "openai") {
|
|
164
|
-
if (!apiKeyTable?.openai) {
|
|
165
|
-
throw new Error("OpenAI API key is required for memento retrieval but not found.");
|
|
166
|
-
}
|
|
167
|
-
embeddingConfig.openaiApiKey = apiKeyTable.openai;
|
|
168
|
-
} else if (requiredProvider === "voyageai") {
|
|
169
|
-
if (!apiKeyTable?.voyageai) {
|
|
170
|
-
throw new Error("VoyageAI API key is required for memento retrieval but not found.");
|
|
171
|
-
}
|
|
172
|
-
embeddingConfig.voyageApiKey = apiKeyTable.voyageai;
|
|
173
|
-
}
|
|
174
|
-
const embeddingFactory = new EmbeddingFactory(embeddingConfig);
|
|
175
|
-
const embeddingService = embeddingFactory.createEmbeddingService(embeddingModel);
|
|
176
|
-
logger?.debug?.("Generating embedding for prompt:", prompt.substring(0, 100));
|
|
177
|
-
try {
|
|
178
|
-
const promptEmbedding = await embeddingService.generateEmbedding(prompt);
|
|
179
|
-
const mementos = await adapters.db.mementos.findByUserId(userId, {
|
|
180
|
-
tier: tier === "all" ? void 0 : tier,
|
|
181
|
-
select: "summary embedding weight tags fullContent lastAccessedAt"
|
|
182
|
-
});
|
|
183
|
-
logger?.debug?.(`Found ${mementos.length} mementos to search through (tier: ${tier})`);
|
|
184
|
-
if (mementos.length === 0) {
|
|
185
|
-
logger?.debug?.("No mementos found for user");
|
|
186
|
-
return [];
|
|
187
|
-
}
|
|
188
|
-
const mementosWithScores = mementos.reduce((acc, memento) => {
|
|
189
|
-
if (!memento.embedding || memento.embedding.length === 0) {
|
|
190
|
-
logger?.warn?.(`Memento ${memento.id} missing embedding, skipping`);
|
|
191
|
-
return acc;
|
|
192
|
-
}
|
|
193
|
-
const similarity = computeCosineSimilarity(promptEmbedding, memento.embedding);
|
|
194
|
-
if (similarity >= minSimilarity) {
|
|
195
|
-
acc.push({
|
|
196
|
-
memento,
|
|
197
|
-
similarity
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
return acc;
|
|
201
|
-
}, []);
|
|
202
|
-
const sortedMementos = mementosWithScores.sort((a, b) => b.similarity - a.similarity).slice(0, topK);
|
|
203
|
-
logger?.debug?.(`Returning ${sortedMementos.length} relevant mementos (min similarity: ${minSimilarity}, topK: ${topK})`);
|
|
204
|
-
if (sortedMementos.length > 0) {
|
|
205
|
-
logger?.debug?.(`Top memento similarity: ${sortedMementos[0].similarity.toFixed(3)} - "${sortedMementos[0].memento.summary}"`);
|
|
206
|
-
}
|
|
207
|
-
return sortedMementos;
|
|
208
|
-
} catch (error) {
|
|
209
|
-
logger?.warn?.("Error generating embedding for prompt, returning empty array:", error);
|
|
210
|
-
return [];
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// ../../b4m-core/packages/services/dist/src/mementoService/findMostSimilarMemento.js
|
|
215
|
-
function findMostSimilarMemento(targetEmbedding, mementos) {
|
|
216
|
-
let highestSimilarity = 0;
|
|
217
|
-
let mostSimilarMemento = null;
|
|
218
|
-
for (const memento of mementos) {
|
|
219
|
-
if (!memento.embedding || memento.embedding.length === 0) {
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
const similarity = computeCosineSimilarity(targetEmbedding, memento.embedding);
|
|
223
|
-
if (similarity > highestSimilarity) {
|
|
224
|
-
highestSimilarity = similarity;
|
|
225
|
-
mostSimilarMemento = memento;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return {
|
|
229
|
-
memento: mostSimilarMemento,
|
|
230
|
-
similarity: highestSimilarity
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export {
|
|
235
|
-
getSerperKey,
|
|
236
|
-
getOpenWeatherKey,
|
|
237
|
-
getWolframAlphaKey,
|
|
238
|
-
getEffectiveApiKey,
|
|
239
|
-
getRelevantMementos,
|
|
240
|
-
findMostSimilarMemento
|
|
241
|
-
};
|