@qoder-ai/qmind-cli 5.0.0 → 5.1.1
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 +12 -0
- package/CHANGELOG.zh-CN.md +12 -0
- package/README.md +12 -1
- package/README.zh-CN.md +12 -1
- package/dist/{data-sources-DItXSL_s.js → data-sources-BPDVRCNK.js} +5 -2
- package/dist/{imports-CSg7ebnN.js → imports-DkL0FuBt.js} +33 -8
- package/dist/{management-iTQ9-Osc.js → management-BV5KWpJ8.js} +1 -1
- package/dist/{nezha-B_SP8BvK.js → nezha-Dgm3_VQA.js} +1 -1
- package/dist/{notes-BUq1ciGO.js → notes-3zUdvWqK.js} +1 -1
- package/dist/qmind.js +323 -62
- package/dist/{shared-evTnu_EB.js → shared-Cyj1bHGY.js} +180 -148
- package/dist/{source-upload-DckYHoRo.js → source-upload-UCVqDJod.js} +1 -1
- package/dist/{transfers-C0pXH5Qe.js → transfers-BcknzY_J.js} +2 -2
- package/dist/{wiki-_a2EAozi.js → wiki-ZHC_GTBb.js} +2 -2
- package/dist/{wiki-branches-DViaqEOy.js → wiki-branches-DVsfkeIS.js} +1 -1
- package/package.json +6 -6
package/dist/qmind.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { n as nezhaWebOfficePath } from "./nezha-
|
|
3
|
-
import { t as preflightSourceUpload } from "./source-upload-
|
|
1
|
+
import { $ as sourceWebOfficeTokenSchema, B as sharedNotebookListSchema, D as chatMessageListSchema, E as cancelQuestionResultSchema, G as sourceListSchema, H as sourceChildrenCountsSchema, I as notebookListSchema, J as sourceRawContentSchema, K as sourcePreviewSchema, L as notebookSchema, M as imageUploadTicketSchema, N as imageUrlsSchema, O as chatSessionListSchema, Q as sourceWebOfficeSessionSchema, R as retrieveNotebooksResultSchema, S as qmindRoutes, T as batchDeleteResultSchema, U as sourceContentSchema, V as sourceActionAccessSchema, W as sourceImportResultsSchema, X as sourceUploadCapabilitiesSchema, Y as sourceSchema, _ as assertCapability, a as invalidArgument$1, c as optionalRecord, d as pagination$1, dt as QMindError, et as taskRunListSchema, f as positiveInteger$1, g as stringList, i as httpUrl, k as chatSessionSchema, l as optionalString$1, m as requiredString$1, n as call, o as nonNegativeInteger$1, p as queryPath, q as sourceQuotaSchema, r as compactUndefined, rt as voidResponseSchema, s as optionalBoolean, t as assertNonEmptyPatch, tt as taskRunSchema, u as optionalTrimmedString, v as executeStream, x as qmindPath, z as retrieveResultSchema } from "./shared-Cyj1bHGY.js";
|
|
2
|
+
import { n as nezhaWebOfficePath } from "./nezha-Dgm3_VQA.js";
|
|
3
|
+
import { t as preflightSourceUpload } from "./source-upload-UCVqDJod.js";
|
|
4
4
|
import { basename, dirname, extname, join, relative, resolve, sep } from "node:path";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
7
|
-
import { chmod, copyFile, link, lstat, mkdir, mkdtemp, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
7
|
+
import { chmod, copyFile, link, lstat, mkdir, mkdtemp, open, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
8
8
|
import { homedir, tmpdir } from "node:os";
|
|
9
9
|
import lockfile from "proper-lockfile";
|
|
10
|
-
import open from "open";
|
|
11
|
-
import { createReadStream, createWriteStream } from "node:fs";
|
|
10
|
+
import open$1 from "open";
|
|
11
|
+
import { constants, createReadStream, createWriteStream } from "node:fs";
|
|
12
12
|
import { Readable } from "node:stream";
|
|
13
13
|
import { pipeline } from "node:stream/promises";
|
|
14
14
|
import { createParser } from "eventsource-parser";
|
|
@@ -178,6 +178,79 @@ function isQMindRetiredScene(scene) {
|
|
|
178
178
|
return scene === "compilation" || scene === "lint";
|
|
179
179
|
}
|
|
180
180
|
//#endregion
|
|
181
|
+
//#region ../sdk/src/retrieval-image.ts
|
|
182
|
+
const QMIND_RETRIEVAL_IMAGE_MAX_BYTES = 10485760;
|
|
183
|
+
const maxQueryImageBase64Length = 4 * Math.ceil(QMIND_RETRIEVAL_IMAGE_MAX_BYTES / 3);
|
|
184
|
+
const imageFormats = /* @__PURE__ */ new Set([
|
|
185
|
+
"jpeg",
|
|
186
|
+
"png",
|
|
187
|
+
"webp",
|
|
188
|
+
"bmp",
|
|
189
|
+
"tiff",
|
|
190
|
+
"gif"
|
|
191
|
+
]);
|
|
192
|
+
function normalizeImageFormat(value) {
|
|
193
|
+
const format = value.toLowerCase();
|
|
194
|
+
return format === "jpg" ? "jpeg" : format;
|
|
195
|
+
}
|
|
196
|
+
function isBase64(value) {
|
|
197
|
+
return value.length % 4 === 0 && /^[A-Za-z0-9+/]+={0,2}$/.test(value);
|
|
198
|
+
}
|
|
199
|
+
/** Check the encoding and size accepted by the retrieval API. Mind validates the image bytes. */
|
|
200
|
+
function qmindRetrievalImageIssue({ imageBase64, imageFormat, query }) {
|
|
201
|
+
if (imageBase64 === void 0) return imageFormat === void 0 ? void 0 : {
|
|
202
|
+
field: "imageFormat",
|
|
203
|
+
message: "imageFormat requires imageBase64"
|
|
204
|
+
};
|
|
205
|
+
if (query !== void 0 && query.length > 128) return {
|
|
206
|
+
field: "query",
|
|
207
|
+
message: `image retrieval query must be at most 128 UTF-16 units`
|
|
208
|
+
};
|
|
209
|
+
let payload = imageBase64;
|
|
210
|
+
const format = imageFormat === void 0 ? void 0 : normalizeImageFormat(imageFormat);
|
|
211
|
+
if (/^data:/i.test(imageBase64)) {
|
|
212
|
+
const header = /^data:image\/([a-zA-Z]{3,4});base64,/.exec(imageBase64);
|
|
213
|
+
const urlFormat = normalizeImageFormat(header?.[1] ?? "");
|
|
214
|
+
if (!header || !imageFormats.has(urlFormat)) return {
|
|
215
|
+
field: "imageBase64",
|
|
216
|
+
message: "invalid image data URL header"
|
|
217
|
+
};
|
|
218
|
+
if (format !== void 0 && format !== urlFormat) return {
|
|
219
|
+
field: "imageFormat",
|
|
220
|
+
message: "imageFormat does not match data URL"
|
|
221
|
+
};
|
|
222
|
+
payload = imageBase64.slice(header[0].length);
|
|
223
|
+
} else if (format === void 0 || !imageFormats.has(format)) return {
|
|
224
|
+
field: "imageFormat",
|
|
225
|
+
message: "raw imageBase64 requires imageFormat (jpeg, jpg, png, webp, bmp, tiff or gif)"
|
|
226
|
+
};
|
|
227
|
+
const tooLarge = {
|
|
228
|
+
field: "imageBase64",
|
|
229
|
+
message: "query image exceeds 10 MiB"
|
|
230
|
+
};
|
|
231
|
+
if (payload.length > maxQueryImageBase64Length) return tooLarge;
|
|
232
|
+
const base64 = payload.replace(/[\r\n]/g, "");
|
|
233
|
+
if (!isBase64(base64)) return {
|
|
234
|
+
field: "imageBase64",
|
|
235
|
+
message: "invalid image base64"
|
|
236
|
+
};
|
|
237
|
+
const padding = base64.endsWith("==") ? 2 : base64.endsWith("=") ? 1 : 0;
|
|
238
|
+
return base64.length / 4 * 3 - padding > 10485760 ? tooLarge : void 0;
|
|
239
|
+
}
|
|
240
|
+
/** Read an inline image from a retrieval hit without resolving URLs or decoding image bytes. */
|
|
241
|
+
function readQMindRetrievalImage(chunk) {
|
|
242
|
+
const url = chunk.metadata?.imageDataUrl;
|
|
243
|
+
if (typeof url !== "string" || url.length > 14e5) return void 0;
|
|
244
|
+
const header = /^data:(image\/(?:jpeg|png|webp));base64,/.exec(url);
|
|
245
|
+
if (!header) return void 0;
|
|
246
|
+
const data = url.slice(header[0].length).replace(/[\r\n]/g, "");
|
|
247
|
+
if (!isBase64(data)) return void 0;
|
|
248
|
+
return {
|
|
249
|
+
mimeType: header[1],
|
|
250
|
+
data
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
//#endregion
|
|
181
254
|
//#region ../sdk/src/operations/agents.ts
|
|
182
255
|
function isRecord$2(value) {
|
|
183
256
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -223,11 +296,24 @@ function billingContext(value) {
|
|
|
223
296
|
});
|
|
224
297
|
}
|
|
225
298
|
function retrieveBody(input) {
|
|
226
|
-
|
|
299
|
+
const fields = optionalRecord(input, "input");
|
|
300
|
+
if (!fields) throw invalidArgument$1("input must be an object", "input");
|
|
301
|
+
if (fields.imageUrl !== void 0 || fields.image_url !== void 0) throw invalidArgument$1("remote image URLs are unsupported", "imageUrl");
|
|
302
|
+
const imageBase64 = input.imageBase64 === void 0 ? void 0 : requiredString$1(input.imageBase64, "imageBase64");
|
|
303
|
+
const imageFormat = optionalTrimmedString(input.imageFormat, "imageFormat");
|
|
304
|
+
const query = imageBase64 ? optionalTrimmedString(input.query, "query") : requiredString$1(input.query, "query");
|
|
305
|
+
const issue = qmindRetrievalImageIssue({
|
|
306
|
+
imageBase64,
|
|
307
|
+
imageFormat: imageBase64 === void 0 ? input.imageFormat : imageFormat,
|
|
308
|
+
query
|
|
309
|
+
});
|
|
310
|
+
if (issue) throw invalidArgument$1(issue.message, issue.field);
|
|
227
311
|
return compactUndefined({
|
|
312
|
+
imageBase64,
|
|
313
|
+
imageFormat,
|
|
228
314
|
billingContext: billingContext(input.billingContext),
|
|
229
315
|
maxResults: nonNegativeInteger$1(input.maxResults, "maxResults"),
|
|
230
|
-
query
|
|
316
|
+
query,
|
|
231
317
|
queryHints: queryHints(input.queryHints),
|
|
232
318
|
scoreThreshold: finiteNumber(input.scoreThreshold, "scoreThreshold"),
|
|
233
319
|
sourceIds: stringList(input.sourceIds ?? [], "sourceIds"),
|
|
@@ -572,7 +658,7 @@ function createAgentOperations(context) {
|
|
|
572
658
|
//#region ../sdk/src/operations/notebooks.ts
|
|
573
659
|
function createNotebookOperations(context) {
|
|
574
660
|
let wikiOperations;
|
|
575
|
-
const loadWiki = () => wikiOperations ??= import("./wiki-branches-
|
|
661
|
+
const loadWiki = () => wikiOperations ??= import("./wiki-branches-DVsfkeIS.js").then(({ createWikiBranchOperations }) => createWikiBranchOperations(context));
|
|
576
662
|
return {
|
|
577
663
|
async copyFeaturedNotebook(notebookId, options) {
|
|
578
664
|
const notebook = requiredString$1(notebookId, "notebookId");
|
|
@@ -1602,7 +1688,7 @@ const noteOperationNames = [
|
|
|
1602
1688
|
function createLazyDataSourceOperations(context) {
|
|
1603
1689
|
let operations;
|
|
1604
1690
|
const load = () => {
|
|
1605
|
-
operations ??= import("./data-sources-
|
|
1691
|
+
operations ??= import("./data-sources-BPDVRCNK.js").then(({ createDataSourceOperations }) => createDataSourceOperations(context));
|
|
1606
1692
|
return operations;
|
|
1607
1693
|
};
|
|
1608
1694
|
return {
|
|
@@ -1622,7 +1708,7 @@ function createLazyDataSourceOperations(context) {
|
|
|
1622
1708
|
function createLazyTransferOperations(context) {
|
|
1623
1709
|
let operations;
|
|
1624
1710
|
const load = () => {
|
|
1625
|
-
operations ??= import("./transfers-
|
|
1711
|
+
operations ??= import("./transfers-BcknzY_J.js").then(({ createTransferOperations }) => createTransferOperations(context));
|
|
1626
1712
|
return operations;
|
|
1627
1713
|
};
|
|
1628
1714
|
return {
|
|
@@ -1633,7 +1719,7 @@ function createLazyTransferOperations(context) {
|
|
|
1633
1719
|
function createLazyWikiOperations(context) {
|
|
1634
1720
|
let operations;
|
|
1635
1721
|
const load = () => {
|
|
1636
|
-
operations ??= import("./wiki-
|
|
1722
|
+
operations ??= import("./wiki-ZHC_GTBb.js").then(({ createWikiOperations }) => createWikiOperations(context));
|
|
1637
1723
|
return operations;
|
|
1638
1724
|
};
|
|
1639
1725
|
return {
|
|
@@ -1645,7 +1731,7 @@ function createLazyWikiOperations(context) {
|
|
|
1645
1731
|
function createLazyNoteOperations(context) {
|
|
1646
1732
|
let operations;
|
|
1647
1733
|
const load = () => {
|
|
1648
|
-
operations ??= import("./notes-
|
|
1734
|
+
operations ??= import("./notes-3zUdvWqK.js").then(({ createNoteOperations }) => createNoteOperations(context));
|
|
1649
1735
|
return operations;
|
|
1650
1736
|
};
|
|
1651
1737
|
return Object.fromEntries(noteOperationNames.map((name) => [name, (...args) => load().then((loaded) => Reflect.apply(loaded[name], loaded, args))]));
|
|
@@ -1653,7 +1739,7 @@ function createLazyNoteOperations(context) {
|
|
|
1653
1739
|
function createLazyImportOperations(context) {
|
|
1654
1740
|
let operations;
|
|
1655
1741
|
const load = () => {
|
|
1656
|
-
operations ??= import("./imports-
|
|
1742
|
+
operations ??= import("./imports-DkL0FuBt.js").then(({ createImportOperations }) => createImportOperations(context));
|
|
1657
1743
|
return operations;
|
|
1658
1744
|
};
|
|
1659
1745
|
return Object.fromEntries(importOperationNames.map((name) => [name, (...args) => load().then((loaded) => Reflect.apply(loaded[name], loaded, args))]));
|
|
@@ -1661,7 +1747,7 @@ function createLazyImportOperations(context) {
|
|
|
1661
1747
|
function createLazyManagementOperations(context) {
|
|
1662
1748
|
let operations;
|
|
1663
1749
|
const load = () => {
|
|
1664
|
-
operations ??= import("./management-
|
|
1750
|
+
operations ??= import("./management-BV5KWpJ8.js").then(({ createManagementOperations }) => createManagementOperations(context));
|
|
1665
1751
|
return operations;
|
|
1666
1752
|
};
|
|
1667
1753
|
return Object.fromEntries(managementOperationNames.map((name) => [name, (...args) => load().then((loaded) => Reflect.apply(loaded[name], loaded, args))]));
|
|
@@ -1760,7 +1846,7 @@ function canonicalize(object, seen = /* @__PURE__ */ new Set()) {
|
|
|
1760
1846
|
}
|
|
1761
1847
|
//#endregion
|
|
1762
1848
|
//#region ../agent-core/src/contract.ts
|
|
1763
|
-
const CONTRACT_VERSION = "8.
|
|
1849
|
+
const CONTRACT_VERSION = "8.1.0";
|
|
1764
1850
|
const AGENT_ERROR_CODES = Object.freeze([
|
|
1765
1851
|
"invalid_input",
|
|
1766
1852
|
"selection_required",
|
|
@@ -1810,18 +1896,61 @@ const listNotebooksInputSchema = z.object({
|
|
|
1810
1896
|
]).optional(),
|
|
1811
1897
|
cursor: z.string().min(1).max(512).optional()
|
|
1812
1898
|
}).strict();
|
|
1813
|
-
const
|
|
1899
|
+
const retrieveParametersSchema = z.object({
|
|
1900
|
+
imageBase64: z.string().trim().min(1).describe("Image data URL or standard Base64. One image, up to 10 MiB before encoding.").optional(),
|
|
1901
|
+
imageFormat: z.string().trim().min(1).describe("Required for raw Base64: jpeg, jpg, png, webp, bmp, tiff or gif.").optional(),
|
|
1814
1902
|
maxResults: z.number().int().min(1).max(50).default(8),
|
|
1815
|
-
notebookId: opaqueId.optional(),
|
|
1903
|
+
notebookId: opaqueId.describe("Select one notebook. Pair with top-level sourceIds to restrict its sources. Choose notebookId or targets.").optional(),
|
|
1816
1904
|
targets: z.array(z.object({
|
|
1817
1905
|
notebookId: opaqueId,
|
|
1818
|
-
sourceIds: z.array(opaqueId).min(1).max(100).refine((ids) => new Set(ids).size === ids.length).optional()
|
|
1819
|
-
}).strict()).min(1).max(32).refine((targets) => new Set(targets.map((target) => target.notebookId)).size === targets.length).optional(),
|
|
1820
|
-
query: z.string().trim().min(1).max(2e3),
|
|
1821
|
-
scoreThreshold: z.number().min(0).max(1).optional(),
|
|
1822
|
-
sourceIds: z.array(opaqueId).min(1).max(50).refine((values) => new Set(values).size === values.length, { message: "sourceIds must be unique" }).optional(),
|
|
1906
|
+
sourceIds: z.array(opaqueId).min(1).max(100).refine((ids) => new Set(ids).size === ids.length).describe("Restrict this target to these source IDs within its notebook.").optional()
|
|
1907
|
+
}).strict()).min(1).max(32).refine((targets) => new Set(targets.map((target) => target.notebookId)).size === targets.length).describe("Select notebooks with one object per notebook, such as [{\"notebookId\":\"nb-1\"}]. Put sourceIds inside each target. Choose targets or top-level notebookId.").optional(),
|
|
1908
|
+
query: z.string().trim().min(1).max(2e3).describe(`Text query, up to 128 UTF-16 units with an image.`).optional(),
|
|
1909
|
+
scoreThreshold: z.number().min(0).max(1).describe("Minimum score for non-OTS retrieval.").optional(),
|
|
1910
|
+
sourceIds: z.array(opaqueId).min(1).max(50).refine((values) => new Set(values).size === values.length, { message: "sourceIds must be unique" }).describe("Restrict the notebook selected by top-level notebookId to these source IDs. With targets, put sourceIds inside each target.").optional(),
|
|
1823
1911
|
topK: z.number().int().min(1).max(100).optional()
|
|
1824
1912
|
}).strict().refine((value) => value.notebookId === void 0 || value.targets === void 0, { message: "notebookId and targets are mutually exclusive" }).refine((value) => value.sourceIds === void 0 || value.notebookId !== void 0, { message: "sourceIds requires notebookId; otherwise put sourceIds inside each target" });
|
|
1913
|
+
function localAttachmentRetrieveSchema(options) {
|
|
1914
|
+
const withReference = retrieveParametersSchema.safeExtend({ imageAttachmentRef: z.uuidv4().describe("Current-turn image reference supplied with the attached image by the host.").optional() });
|
|
1915
|
+
const pathField = { imagePath: z.string().min(1).max(4096).describe("Absolute path supplied with the attached local image.").optional() };
|
|
1916
|
+
if (options.reference) return options.path ? withReference.safeExtend(pathField).superRefine(validateAttachmentImage) : withReference.superRefine(validateAttachmentImage);
|
|
1917
|
+
return options.path ? retrieveParametersSchema.safeExtend(pathField).superRefine(validateAttachmentImage) : retrieveParametersSchema.superRefine(validateAttachmentImage);
|
|
1918
|
+
}
|
|
1919
|
+
localAttachmentRetrieveSchema({
|
|
1920
|
+
reference: true,
|
|
1921
|
+
path: false
|
|
1922
|
+
});
|
|
1923
|
+
function validateAttachmentImage(input, context) {
|
|
1924
|
+
if (input.imageAttachmentRef === void 0 && input.imagePath === void 0) return validateRetrievalImage(input, context);
|
|
1925
|
+
if (input.query !== void 0 && input.query.length > 128) context.addIssue({
|
|
1926
|
+
code: "custom",
|
|
1927
|
+
path: ["query"],
|
|
1928
|
+
message: `image retrieval query must be at most 128 UTF-16 units`
|
|
1929
|
+
});
|
|
1930
|
+
if (input.imageBase64 !== void 0 || input.imageFormat !== void 0 || input.imageAttachmentRef !== void 0 && input.imagePath !== void 0) context.addIssue({
|
|
1931
|
+
code: "custom",
|
|
1932
|
+
path: [input.imagePath === void 0 ? "imageAttachmentRef" : "imagePath"],
|
|
1933
|
+
message: "Choose a single image input."
|
|
1934
|
+
});
|
|
1935
|
+
}
|
|
1936
|
+
function validateRetrievalImage({ query, imageBase64, imageFormat }, context) {
|
|
1937
|
+
if (query === void 0 && imageBase64 === void 0 && imageFormat === void 0) context.addIssue({
|
|
1938
|
+
code: "custom",
|
|
1939
|
+
path: ["query"],
|
|
1940
|
+
message: "Provide query or imageBase64"
|
|
1941
|
+
});
|
|
1942
|
+
const issue = qmindRetrievalImageIssue({
|
|
1943
|
+
imageBase64,
|
|
1944
|
+
imageFormat,
|
|
1945
|
+
query
|
|
1946
|
+
});
|
|
1947
|
+
if (issue) context.addIssue({
|
|
1948
|
+
code: "custom",
|
|
1949
|
+
path: [issue.field],
|
|
1950
|
+
message: issue.message
|
|
1951
|
+
});
|
|
1952
|
+
}
|
|
1953
|
+
const retrieveInputSchema = retrieveParametersSchema.superRefine(validateRetrievalImage);
|
|
1825
1954
|
const listSourcesInputSchema = z.object({
|
|
1826
1955
|
notebookId: opaqueId,
|
|
1827
1956
|
page,
|
|
@@ -1951,7 +2080,15 @@ const agentToolDefinitions = Object.freeze([
|
|
|
1951
2080
|
},
|
|
1952
2081
|
{
|
|
1953
2082
|
deadlineMs: 6e4,
|
|
1954
|
-
description:
|
|
2083
|
+
description: [
|
|
2084
|
+
"Retrieve globally ranked context from QMind using text (query), an image (imageBase64), or both.",
|
|
2085
|
+
"For explicit selection, choose one form. Single notebook: `{\"query\":\"the question\",\"notebookId\":\"nb-1\"}`. One or more notebooks: `{\"query\":\"the question\",\"targets\":[{\"notebookId\":\"nb-1\"},{\"notebookId\":\"nb-2\"}]}`.",
|
|
2086
|
+
`Pass at most 32 unique notebooks per call. To restrict sources, put sourceIds beside a top-level notebookId or inside each target when using targets.`,
|
|
2087
|
+
"Omitting notebook selection uses configured defaults. maxResults caps the combined results.",
|
|
2088
|
+
"When notebook IDs are unknown, discover candidates with list_notebooks. To continue, pass the returned nextCursor as cursor. Select by summary and topics, with title and description as fallback.",
|
|
2089
|
+
"Search within the current organization and authorized retrieval scope, including configured sharing groups. Workspace links prioritize notebooks within that scope.",
|
|
2090
|
+
"For imageBase64, use the actual attachment bytes as an image data URL or as raw Base64 with imageFormat."
|
|
2091
|
+
].join(" "),
|
|
1955
2092
|
id: "qmind.retrieve",
|
|
1956
2093
|
intent: "read",
|
|
1957
2094
|
leaf: "retrieve"
|
|
@@ -2111,6 +2248,7 @@ const canonicalDescriptor = canonicalize(deepFreeze({
|
|
|
2111
2248
|
defaultRetrievalMode: "all?; explicit host opt-in searches each authorized target with concurrency at most 3 and bounded partial results",
|
|
2112
2249
|
defaultNotebookRelationship: "owned|shared|featured|all?; host discovery default independent of notebookPolicy; omitted means owned",
|
|
2113
2250
|
approvedDeletionTargets: "SourceDeletionTarget[1..100]?; host-only, must match fresh targets",
|
|
2251
|
+
includeRetrievalImages: "boolean?; host opt-in to inline images in retrieve results",
|
|
2114
2252
|
notebookPolicy: { selectNotebook: "host callback: excluded|allowed|preferred; request-local; intersects server ACL" },
|
|
2115
2253
|
notebookScope: {
|
|
2116
2254
|
allowedNotebookIds: "uniqueOpaqueId[]",
|
|
@@ -2284,11 +2422,13 @@ const canonicalDescriptor = canonicalize(deepFreeze({
|
|
|
2284
2422
|
defaults: { maxResults: 8 },
|
|
2285
2423
|
id: "qmind.retrieve",
|
|
2286
2424
|
input: {
|
|
2425
|
+
imageBase64: "image data URL or standard Base64?; at most 10 MiB decoded",
|
|
2426
|
+
imageFormat: "jpeg|jpg|png|webp|bmp|tiff|gif?; required for raw Base64",
|
|
2287
2427
|
maxResults: "integer:1..50?",
|
|
2288
2428
|
notebookId: "opaqueId?; exclusive with targets",
|
|
2289
|
-
targets:
|
|
2290
|
-
query:
|
|
2291
|
-
scoreThreshold: "number:0..1
|
|
2429
|
+
targets: `[{notebookId, sourceIds?}][1..32]?; unique notebooks`,
|
|
2430
|
+
query: `string:1..2000?; at most 128 UTF-16 units with an image; at least one of query and imageBase64 is required`,
|
|
2431
|
+
scoreThreshold: "number:0..1?; applies to non-OTS retrieval",
|
|
2292
2432
|
sourceIds: "uniqueOpaqueId[1..50]?",
|
|
2293
2433
|
topK: "integer:1..100?"
|
|
2294
2434
|
},
|
|
@@ -2298,6 +2438,7 @@ const canonicalDescriptor = canonicalize(deepFreeze({
|
|
|
2298
2438
|
chunkId: "opaqueId",
|
|
2299
2439
|
chunkIndex: "integer:0..",
|
|
2300
2440
|
content: "string",
|
|
2441
|
+
image: "{mimeType: image/jpeg|image/png|image/webp, data: Base64}?; bounded inline image",
|
|
2301
2442
|
notebookId: "opaqueId",
|
|
2302
2443
|
notebookTitle: "string",
|
|
2303
2444
|
originUrl: "string?",
|
|
@@ -3173,6 +3314,7 @@ const sourceStatus = /* @__PURE__ */ new Set([
|
|
|
3173
3314
|
"unsupported",
|
|
3174
3315
|
"failed"
|
|
3175
3316
|
]);
|
|
3317
|
+
const maxRetrievalImageChars = 28e5;
|
|
3176
3318
|
/**
|
|
3177
3319
|
* Snapshots and validates host policy at the Core boundary. Invocation context is not model input,
|
|
3178
3320
|
* but it still crosses an adapter seam and must fail closed when malformed.
|
|
@@ -3293,18 +3435,22 @@ function chunkLineRange(metadata) {
|
|
|
3293
3435
|
function chunkPromptContext(chunks) {
|
|
3294
3436
|
return chunks.map((chunk) => `[Notebook: ${chunk.notebookTitle} | NotebookID: ${chunk.notebookId} | Source: ${chunk.sourceTitle} | Chunk: ${chunk.chunkIndex} | SourceID: ${chunk.sourceId} | ChunkID: ${chunk.chunkId} | Score: ${chunk.score.toFixed(3)}]\n${chunk.content}`).join("\n\n---\n\n");
|
|
3295
3437
|
}
|
|
3438
|
+
function retrievalSelectionError(count, invocation) {
|
|
3439
|
+
if (count === 0 || count > 32 && invocation.defaultRetrievalMode !== "all") return failure$1(invocation.operationId, "selection_required", `Use list_notebooks overview to select one to 32 relevant notebooks.`);
|
|
3440
|
+
}
|
|
3296
3441
|
async function retrieve(client, input, invocation) {
|
|
3297
|
-
const targets = input.targets ?? (input.notebookId === void 0 ? invocation.defaultNotebookIds
|
|
3442
|
+
const targets = input.targets ?? (input.notebookId === void 0 ? (invocation.defaultNotebookIds ?? []).map((notebookId) => ({ notebookId })) : [{
|
|
3298
3443
|
notebookId: input.notebookId,
|
|
3299
3444
|
...input.sourceIds === void 0 ? {} : { sourceIds: input.sourceIds }
|
|
3300
3445
|
}]);
|
|
3301
|
-
|
|
3446
|
+
const selectionError = retrievalSelectionError(targets.length, invocation);
|
|
3447
|
+
if (selectionError) return selectionError;
|
|
3302
3448
|
const batches = [];
|
|
3303
3449
|
const batchSize = invocation.defaultRetrievalMode === "all" ? 1 : 32;
|
|
3304
3450
|
for (let offset = 0; offset < targets.length; offset += batchSize) batches.push(targets.slice(offset, offset + batchSize));
|
|
3305
3451
|
const results = [];
|
|
3306
3452
|
const warnings = [];
|
|
3307
|
-
|
|
3453
|
+
const failedCodes = /* @__PURE__ */ new Set();
|
|
3308
3454
|
const request = async (batch) => {
|
|
3309
3455
|
return client.retrieveNotebooks({
|
|
3310
3456
|
targets: batch.map(({ notebookId, sourceIds }) => ({
|
|
@@ -3313,7 +3459,9 @@ async function retrieve(client, input, invocation) {
|
|
|
3313
3459
|
...notebookSelection(invocation, notebookId) === "preferred" ? { preference: "preferred" } : {}
|
|
3314
3460
|
})),
|
|
3315
3461
|
maxResults: input.maxResults,
|
|
3316
|
-
query: input.query,
|
|
3462
|
+
...input.query === void 0 ? {} : { query: input.query },
|
|
3463
|
+
...input.imageBase64 === void 0 ? {} : { imageBase64: input.imageBase64 },
|
|
3464
|
+
...input.imageFormat === void 0 ? {} : { imageFormat: input.imageFormat },
|
|
3317
3465
|
...input.scoreThreshold === void 0 ? {} : { scoreThreshold: input.scoreThreshold },
|
|
3318
3466
|
...input.topK === void 0 ? {} : { topK: input.topK }
|
|
3319
3467
|
}, callOptions(invocation));
|
|
@@ -3327,8 +3475,9 @@ async function retrieve(client, input, invocation) {
|
|
|
3327
3475
|
settled.forEach((entry, index) => {
|
|
3328
3476
|
if (entry.status === "fulfilled") results.push(entry.value);
|
|
3329
3477
|
else {
|
|
3330
|
-
|
|
3331
|
-
if (
|
|
3478
|
+
const code = errorCode(entry.reason);
|
|
3479
|
+
if (batches.length === 1 || qmindOrganizationPolicyError(entry.reason) || code === "unauthenticated") throw entry.reason;
|
|
3480
|
+
failedCodes.add(code);
|
|
3332
3481
|
for (const target of current[index]) warnings.push({
|
|
3333
3482
|
code: "notebook_search_failed",
|
|
3334
3483
|
notebookId: target.notebookId
|
|
@@ -3336,7 +3485,10 @@ async function retrieve(client, input, invocation) {
|
|
|
3336
3485
|
}
|
|
3337
3486
|
});
|
|
3338
3487
|
}
|
|
3339
|
-
if (results.length === 0)
|
|
3488
|
+
if (results.length === 0) {
|
|
3489
|
+
const [code] = failedCodes;
|
|
3490
|
+
return failure$1(invocation.operationId, failedCodes.size === 1 && (code === "permission_denied" || code === "invalid_input") ? code : "upstream_unavailable", "Notebook retrieval failed.");
|
|
3491
|
+
}
|
|
3340
3492
|
const result = {
|
|
3341
3493
|
chunks: results.flatMap((item) => item.chunks.map((chunk) => {
|
|
3342
3494
|
if (chunkLineRange(chunk.metadata).lineStart !== void 0) return chunk;
|
|
@@ -3353,9 +3505,19 @@ async function retrieve(client, input, invocation) {
|
|
|
3353
3505
|
reranked: results.length === 1 && results[0].reranked
|
|
3354
3506
|
};
|
|
3355
3507
|
const bounded = result.chunks.slice(0, input.maxResults);
|
|
3508
|
+
let remainingImageChars = maxRetrievalImageChars;
|
|
3356
3509
|
return {
|
|
3357
3510
|
data: {
|
|
3358
|
-
chunks: bounded.map(
|
|
3511
|
+
chunks: bounded.map((chunk) => {
|
|
3512
|
+
const data = chunkData(chunk);
|
|
3513
|
+
const image = invocation.includeRetrievalImages === true ? readQMindRetrievalImage(chunk) : void 0;
|
|
3514
|
+
if (image === void 0 || image.data.length > remainingImageChars) return data;
|
|
3515
|
+
remainingImageChars -= image.data.length;
|
|
3516
|
+
return {
|
|
3517
|
+
...data,
|
|
3518
|
+
image
|
|
3519
|
+
};
|
|
3520
|
+
}),
|
|
3359
3521
|
promptContext: chunkPromptContext(bounded),
|
|
3360
3522
|
reranked: result.reranked,
|
|
3361
3523
|
total: result.total
|
|
@@ -3653,9 +3815,26 @@ async function organizeSource(client, tool, input, invocation) {
|
|
|
3653
3815
|
function validateQMindAgentInvocation(toolId, input, invocation) {
|
|
3654
3816
|
const parsed = agentToolInputSchemas[toolId].safeParse(input);
|
|
3655
3817
|
if (!parsed.success) return failure$1(invocation.operationId, "invalid_input", "The tool input is invalid.");
|
|
3818
|
+
return validateParsedScope(toolId, parsed.data, invocation);
|
|
3819
|
+
}
|
|
3820
|
+
const localAttachmentSchema = localAttachmentRetrieveSchema({
|
|
3821
|
+
reference: true,
|
|
3822
|
+
path: true
|
|
3823
|
+
});
|
|
3824
|
+
function validateAttachmentRetrieval(input, invocation) {
|
|
3825
|
+
const parsed = localAttachmentSchema.safeParse(input);
|
|
3826
|
+
if (!parsed.success || !parsed.data.imageAttachmentRef && !parsed.data.imagePath) return failure$1(invocation.operationId, "invalid_input", "The tool input is invalid.");
|
|
3827
|
+
const targets = targetedNotebookIds("qmind.retrieve", parsed.data, invocation);
|
|
3828
|
+
return validateParsedScope("qmind.retrieve", parsed.data, invocation) ?? retrievalSelectionError(targets?.length ?? 0, invocation) ?? {
|
|
3829
|
+
ok: true,
|
|
3830
|
+
data: parsed.data,
|
|
3831
|
+
meta: { operationId: invocation.operationId }
|
|
3832
|
+
};
|
|
3833
|
+
}
|
|
3834
|
+
function validateParsedScope(toolId, input, invocation) {
|
|
3656
3835
|
try {
|
|
3657
3836
|
invocation.assertCurrent?.();
|
|
3658
|
-
return enforceNotebookScope(toolId,
|
|
3837
|
+
return enforceNotebookScope(toolId, input, invocation, scopedNotebookIds(invocation));
|
|
3659
3838
|
} catch {
|
|
3660
3839
|
return failure$1(invocation.operationId, "permission_denied", "The host context is no longer valid.");
|
|
3661
3840
|
}
|
|
@@ -3748,6 +3927,33 @@ function outcomeFor(result) {
|
|
|
3748
3927
|
if (result.error.code === "outcome_unknown") return "outcome_unknown";
|
|
3749
3928
|
return "failed";
|
|
3750
3929
|
}
|
|
3930
|
+
async function prepareRetrievalImage(input, invocation, context, signal) {
|
|
3931
|
+
const validated = validateAttachmentRetrieval(input, invocation);
|
|
3932
|
+
if (!validated.ok) return validated;
|
|
3933
|
+
const { imageAttachmentRef, imagePath, ...parameters } = validated.data;
|
|
3934
|
+
try {
|
|
3935
|
+
const read = imagePath !== void 0 ? context.readImagePath : context.readImageAttachment;
|
|
3936
|
+
const locator = imagePath ?? imageAttachmentRef;
|
|
3937
|
+
if (!read || !locator) throw new Error("Image reader unavailable");
|
|
3938
|
+
signal.throwIfAborted();
|
|
3939
|
+
const imageBase64 = await read(locator, signal);
|
|
3940
|
+
signal.throwIfAborted();
|
|
3941
|
+
return {
|
|
3942
|
+
ok: true,
|
|
3943
|
+
data: {
|
|
3944
|
+
...parameters,
|
|
3945
|
+
imageBase64
|
|
3946
|
+
},
|
|
3947
|
+
meta: { operationId: invocation.operationId }
|
|
3948
|
+
};
|
|
3949
|
+
} catch (error) {
|
|
3950
|
+
const reason = signal.aborted ? signal.reason : error;
|
|
3951
|
+
if (reason instanceof Error && reason.name === "TimeoutError") return failure(invocation.operationId, "timeout", "The image attachment read timed out.");
|
|
3952
|
+
if (signal.aborted) return failure(invocation.operationId, "cancelled", "The image attachment read was cancelled.");
|
|
3953
|
+
if (error instanceof Error && "code" in error && error.code === "FILE_TOO_LARGE") return failure(invocation.operationId, "invalid_input", "Use a smaller image. QMind accepts up to 10 MiB.");
|
|
3954
|
+
return failure(invocation.operationId, "invalid_input", "This image attachment is unavailable for this request. Attach the image again.");
|
|
3955
|
+
}
|
|
3956
|
+
}
|
|
3751
3957
|
async function runQMindAgentOperation(dependencies, toolId, input, runtimeSignal, perRequestToken, operationContext = {}) {
|
|
3752
3958
|
const createId = dependencies.createId ?? randomUUID;
|
|
3753
3959
|
const now = dependencies.now ?? Date.now;
|
|
@@ -3778,11 +3984,15 @@ async function runQMindAgentOperation(dependencies, toolId, input, runtimeSignal
|
|
|
3778
3984
|
const code = abortCode(signal, timedOut);
|
|
3779
3985
|
result = failure(operationId, code, code === "timeout" ? "The QMind operation timed out." : "The QMind operation was cancelled.");
|
|
3780
3986
|
} else {
|
|
3781
|
-
const
|
|
3987
|
+
const invocation = {
|
|
3782
3988
|
...operationContext,
|
|
3989
|
+
defaultRetrievalMode: dependencies.defaultRetrievalMode,
|
|
3783
3990
|
operationId,
|
|
3784
3991
|
...dependencies.defaultNotebookIds === void 0 ? {} : { defaultNotebookIds: dependencies.defaultNotebookIds }
|
|
3785
|
-
}
|
|
3992
|
+
};
|
|
3993
|
+
const attachment = toolId === "qmind.retrieve" && input !== null && typeof input === "object" && ("imageAttachmentRef" in input && operationContext.readImageAttachment !== void 0 || "imagePath" in input && operationContext.readImagePath !== void 0) ? await prepareRetrievalImage(input, invocation, operationContext, signal) : void 0;
|
|
3994
|
+
const operationInput = attachment?.ok ? attachment.data : input;
|
|
3995
|
+
const denied = attachment?.ok === false ? attachment : validateQMindAgentInvocation(toolId, operationInput, invocation);
|
|
3786
3996
|
if (denied) result = denied;
|
|
3787
3997
|
else {
|
|
3788
3998
|
let fileSource;
|
|
@@ -3797,7 +4007,7 @@ async function runQMindAgentOperation(dependencies, toolId, input, runtimeSignal
|
|
|
3797
4007
|
}
|
|
3798
4008
|
if (requestedPath === void 0 || fileSource !== void 0) try {
|
|
3799
4009
|
operationContext.assertCurrent?.();
|
|
3800
|
-
result = await dependencies.core.invoke(toolId,
|
|
4010
|
+
result = await dependencies.core.invoke(toolId, operationInput, {
|
|
3801
4011
|
assertCurrent: operationContext.assertCurrent,
|
|
3802
4012
|
defaultRetrievalMode: dependencies.defaultRetrievalMode,
|
|
3803
4013
|
...operationContext.notebookPolicy === void 0 ? {} : { notebookPolicy: operationContext.notebookPolicy },
|
|
@@ -3805,6 +4015,7 @@ async function runQMindAgentOperation(dependencies, toolId, input, runtimeSignal
|
|
|
3805
4015
|
...fileSource === void 0 ? {} : { fileSource },
|
|
3806
4016
|
...dependencies.defaultNotebookIds === void 0 ? {} : { defaultNotebookIds: dependencies.defaultNotebookIds },
|
|
3807
4017
|
...operationContext.approvedDeletionTargets === void 0 ? {} : { approvedDeletionTargets: operationContext.approvedDeletionTargets },
|
|
4018
|
+
...operationContext.includeRetrievalImages === true ? { includeRetrievalImages: true } : {},
|
|
3808
4019
|
...operationContext.notebookScope === void 0 ? {} : { notebookScope: operationContext.notebookScope },
|
|
3809
4020
|
operationId,
|
|
3810
4021
|
signal,
|
|
@@ -5393,7 +5604,7 @@ function defaultReporter() {
|
|
|
5393
5604
|
}
|
|
5394
5605
|
function defaultBrowser() {
|
|
5395
5606
|
return Object.freeze({ async open(url) {
|
|
5396
|
-
(await open(url, { wait: false })).unref();
|
|
5607
|
+
(await open$1(url, { wait: false })).unref();
|
|
5397
5608
|
} });
|
|
5398
5609
|
}
|
|
5399
5610
|
async function tlsAuthority(path) {
|
|
@@ -5548,8 +5759,8 @@ function requestsNdjsonOutput(argv) {
|
|
|
5548
5759
|
//#region src/build-info.ts
|
|
5549
5760
|
/** Bundled identity, never inferred from argv, environment, or an endpoint. */
|
|
5550
5761
|
const QMIND_CLI_DISTRIBUTION = "global";
|
|
5551
|
-
const QMIND_CLI_VERSION = "5.
|
|
5552
|
-
const QMIND_CLI_BUILD_TIME = "2026-11-
|
|
5762
|
+
const QMIND_CLI_VERSION = "5.1.1";
|
|
5763
|
+
const QMIND_CLI_BUILD_TIME = "2026-11-28T02:53:38.000Z";
|
|
5553
5764
|
function qmindCliPlatform() {
|
|
5554
5765
|
return process.platform === "win32" ? "windows" : process.platform;
|
|
5555
5766
|
}
|
|
@@ -6307,6 +6518,7 @@ function renderRetrieve(value, format, multiNotebook = false) {
|
|
|
6307
6518
|
agentField(writer, "sourceUri", chunk.sourceUri);
|
|
6308
6519
|
agentField(writer, "score", chunk.score.toFixed(4));
|
|
6309
6520
|
agentField(writer, "tokenCount", chunk.tokenCount);
|
|
6521
|
+
agentField(writer, "imageMimeType", readQMindRetrievalImage(chunk)?.mimeType);
|
|
6310
6522
|
agentText(writer, "content", unescapeText(chunk.content));
|
|
6311
6523
|
});
|
|
6312
6524
|
value.citations.forEach((citation, index) => {
|
|
@@ -6356,6 +6568,8 @@ function renderRetrieve(value, format, multiNotebook = false) {
|
|
|
6356
6568
|
writer.line(`[${index + 1}] chunkId=${chunk.chunkId} sourceId=${chunk.sourceId} sourceTitle=${chunk.sourceTitle} score=${chunk.score.toFixed(4)} tokens=${chunk.tokenCount}`);
|
|
6357
6569
|
if ("notebookId" in chunk && "notebookTitle" in chunk) writer.line(` notebookId: ${oneLine(chunk.notebookId)} notebookTitle: ${oneLine(chunk.notebookTitle)}`);
|
|
6358
6570
|
if (chunk.sourceUri.length > 0) writer.line(` uri: ${chunk.sourceUri}`);
|
|
6571
|
+
const image = readQMindRetrievalImage(chunk);
|
|
6572
|
+
if (image !== void 0) writer.line(` image: ${image.mimeType}`);
|
|
6359
6573
|
if (chunk.content.length > 0) writer.line(` content: ${unescapeText(chunk.content)}`);
|
|
6360
6574
|
writer.line();
|
|
6361
6575
|
});
|
|
@@ -6946,11 +7160,12 @@ async function runCanonicalCommand(context, raw, tool, input) {
|
|
|
6946
7160
|
throw new QMindError("INVALID_ARGUMENT", `Invalid ${tool} arguments: ${fields.join(", ")}`);
|
|
6947
7161
|
}
|
|
6948
7162
|
const host = await hostFor(context, raw);
|
|
7163
|
+
const includeRetrievalImages = tool === "qmind.retrieve" && (raw.format === "json" || raw.format === "ndjson");
|
|
6949
7164
|
const result = await runQMindAgentOperation({
|
|
6950
7165
|
core: createQMindAgentCore(host.client),
|
|
6951
7166
|
createFileSource: (path) => host.createFileSource(path),
|
|
6952
7167
|
auditSink: { accept: () => {} }
|
|
6953
|
-
}, tool, parsed.data);
|
|
7168
|
+
}, tool, parsed.data, void 0, void 0, includeRetrievalImages ? { includeRetrievalImages: true } : void 0);
|
|
6954
7169
|
render(context, raw, {
|
|
6955
7170
|
kind: "json",
|
|
6956
7171
|
value: result
|
|
@@ -7058,6 +7273,44 @@ function registerCanonicalCommands(context, program) {
|
|
|
7058
7273
|
});
|
|
7059
7274
|
}
|
|
7060
7275
|
//#endregion
|
|
7276
|
+
//#region src/retrieval-image.ts
|
|
7277
|
+
async function readRetrievalImage(path) {
|
|
7278
|
+
const extension = extname(path).slice(1).toLowerCase();
|
|
7279
|
+
if (!/^(?:jpe?g|png|webp|bmp|tiff?|gif)$/.test(extension)) throw new QMindError("INVALID_ARGUMENT", "--image requires a JPEG, PNG, WebP, BMP, TIFF or GIF file");
|
|
7280
|
+
const tooLarge = new QMindError("INVALID_ARGUMENT", "--image must be at most 10 MiB");
|
|
7281
|
+
const unreadable = new QMindError("INVALID_ARGUMENT", "--image must be a readable, non-empty local file");
|
|
7282
|
+
const chunks = [];
|
|
7283
|
+
let size = 0;
|
|
7284
|
+
try {
|
|
7285
|
+
const file = await open(path, constants.O_RDONLY | constants.O_NONBLOCK);
|
|
7286
|
+
try {
|
|
7287
|
+
const info = await file.stat();
|
|
7288
|
+
if (!info.isFile() || info.size === 0) throw unreadable;
|
|
7289
|
+
if (info.size > 10485760) throw tooLarge;
|
|
7290
|
+
const stream = file.createReadStream({
|
|
7291
|
+
autoClose: false,
|
|
7292
|
+
end: QMIND_RETRIEVAL_IMAGE_MAX_BYTES
|
|
7293
|
+
});
|
|
7294
|
+
for await (const chunk of stream) {
|
|
7295
|
+
const bytes = chunk;
|
|
7296
|
+
size += bytes.byteLength;
|
|
7297
|
+
chunks.push(bytes);
|
|
7298
|
+
}
|
|
7299
|
+
} finally {
|
|
7300
|
+
await file.close();
|
|
7301
|
+
}
|
|
7302
|
+
} catch (error) {
|
|
7303
|
+
if (error === tooLarge) throw error;
|
|
7304
|
+
throw unreadable;
|
|
7305
|
+
}
|
|
7306
|
+
if (size === 0) throw unreadable;
|
|
7307
|
+
if (size > 10485760) throw tooLarge;
|
|
7308
|
+
return {
|
|
7309
|
+
imageBase64: Buffer.concat(chunks, size).toString("base64"),
|
|
7310
|
+
imageFormat: extension === "tif" ? "tiff" : extension
|
|
7311
|
+
};
|
|
7312
|
+
}
|
|
7313
|
+
//#endregion
|
|
7061
7314
|
//#region src/application.ts
|
|
7062
7315
|
const distribution = CLI_DISTRIBUTIONS[QMIND_CLI_DISTRIBUTION];
|
|
7063
7316
|
function registerCoreCommands(context, program) {
|
|
@@ -7140,30 +7393,34 @@ function registerCoreCommands(context, program) {
|
|
|
7140
7393
|
});
|
|
7141
7394
|
else context.io.stdout("deleted\n");
|
|
7142
7395
|
});
|
|
7143
|
-
withCommon(program.command("retrieve [query]").description("Retrieve context from
|
|
7396
|
+
withCommon(program.command("retrieve [query]").description("Retrieve context from notebooks using text, an image, or both")).option("--nb <ids>", `notebook IDs (required, comma-separated or repeatable, maximum 32)`, collectNotebookIds, []).option("--unified", "use unified retrieval with notebook identity, including for one notebook").addOption(new Option("--targets <json>", "JSON array of {notebookId, sourceIds?}; uses unified retrieval").argParser(parseTargets).conflicts(["nb", "sources"])).option("--score-threshold <number>", "minimum score for non-OTS retrieval (0..1)", scoreThreshold).option("-q, --query <query>", "retrieval query").option("--image <path>", "local query image (JPEG, PNG, WebP, BMP, TIFF or GIF, up to 10 MiB)").option("--sources <ids>", "comma-separated source IDs (single notebook only)", "").option("--top-k <number>", "joint recall candidate limit", integer, 0).option("--max-results <number>", "maximum context results across selected notebooks", integer, 0).action(async (query, raw) => {
|
|
7144
7397
|
const notebookIds = raw.nb;
|
|
7145
7398
|
const [notebookId] = notebookIds;
|
|
7146
7399
|
if (raw.targets === void 0 && notebookId === void 0) throw new QMindError("INVALID_ARGUMENT", "--nb is required");
|
|
7147
7400
|
if (notebookIds.length > 32) throw new QMindError("INVALID_ARGUMENT", `--nb accepts at most 32 distinct notebook IDs`);
|
|
7148
|
-
const
|
|
7149
|
-
|
|
7150
|
-
|
|
7151
|
-
|
|
7152
|
-
|
|
7401
|
+
const imagePath = stringOption(raw, "image");
|
|
7402
|
+
const text = stringOption(raw, "query") || query;
|
|
7403
|
+
const textQuery = imagePath === void 0 ? requiredString(text, "--query or positional query") : text?.trim() || void 0;
|
|
7404
|
+
if (imagePath !== void 0 && textQuery !== void 0 && textQuery.length > 128) throw new QMindError("INVALID_ARGUMENT", `image retrieval query must be at most 128 UTF-16 units`);
|
|
7405
|
+
const maxResults = numberOption(raw, "maxResults", 0);
|
|
7406
|
+
const topK = numberOption(raw, "topK", 0);
|
|
7407
|
+
const sourceIds = splitCsv(stringOption(raw, "sources"));
|
|
7408
|
+
if (maxResults < 0 || topK < 0) throw new QMindError("INVALID_ARGUMENT", "--top-k and --max-results must be non-negative");
|
|
7409
|
+
if (notebookIds.length > 1 && sourceIds.length > 0) throw new QMindError("INVALID_ARGUMENT", "--sources requires a single notebook");
|
|
7410
|
+
const criteria = {
|
|
7411
|
+
...textQuery === void 0 ? {} : { query: textQuery },
|
|
7412
|
+
...imagePath === void 0 ? {} : await readRetrievalImage(imagePath),
|
|
7153
7413
|
...raw.scoreThreshold === void 0 ? {} : { scoreThreshold: Number(raw.scoreThreshold) }
|
|
7154
7414
|
};
|
|
7155
|
-
if (input.maxResults < 0 || input.topK < 0) throw new QMindError("INVALID_ARGUMENT", "--top-k and --max-results must be non-negative");
|
|
7156
|
-
if (notebookIds.length > 1 && input.sourceIds.length > 0) throw new QMindError("INVALID_ARGUMENT", "--sources requires a single notebook");
|
|
7157
7415
|
if (raw.unified === true || raw.targets !== void 0) {
|
|
7158
7416
|
await runCanonicalCommand(context, raw, "qmind.retrieve", {
|
|
7159
|
-
|
|
7417
|
+
...criteria,
|
|
7160
7418
|
...raw.targets !== void 0 ? { targets: raw.targets } : notebookIds.length === 1 ? {
|
|
7161
7419
|
notebookId,
|
|
7162
|
-
...
|
|
7420
|
+
...sourceIds.length ? { sourceIds } : {}
|
|
7163
7421
|
} : { targets: notebookIds.map((id) => ({ notebookId: id })) },
|
|
7164
|
-
...
|
|
7165
|
-
...
|
|
7166
|
-
...input.scoreThreshold === void 0 ? {} : { scoreThreshold: input.scoreThreshold }
|
|
7422
|
+
...maxResults === 0 ? {} : { maxResults },
|
|
7423
|
+
...topK === 0 ? {} : { topK }
|
|
7167
7424
|
});
|
|
7168
7425
|
return;
|
|
7169
7426
|
}
|
|
@@ -7171,17 +7428,21 @@ function registerCoreCommands(context, program) {
|
|
|
7171
7428
|
if (notebookIds.length === 1 && notebookId !== void 0) {
|
|
7172
7429
|
render(context, raw, {
|
|
7173
7430
|
kind: "retrieve",
|
|
7174
|
-
value: await host.client.retrieve(notebookId,
|
|
7431
|
+
value: await host.client.retrieve(notebookId, {
|
|
7432
|
+
...criteria,
|
|
7433
|
+
maxResults,
|
|
7434
|
+
sourceIds,
|
|
7435
|
+
topK
|
|
7436
|
+
})
|
|
7175
7437
|
});
|
|
7176
7438
|
return;
|
|
7177
7439
|
}
|
|
7178
7440
|
render(context, raw, {
|
|
7179
7441
|
kind: "multiRetrieve",
|
|
7180
7442
|
value: await host.client.retrieveNotebooks({
|
|
7181
|
-
|
|
7182
|
-
|
|
7183
|
-
|
|
7184
|
-
...input.scoreThreshold === void 0 ? {} : { scoreThreshold: input.scoreThreshold },
|
|
7443
|
+
...criteria,
|
|
7444
|
+
maxResults,
|
|
7445
|
+
topK,
|
|
7185
7446
|
targets: notebookIds.map((notebookId) => ({ notebookId }))
|
|
7186
7447
|
})
|
|
7187
7448
|
});
|
|
@@ -7532,7 +7793,7 @@ async function runQMindCli(argv, options = {}) {
|
|
|
7532
7793
|
updater: options.updater ?? createQMindCliUpdater({ identity: {
|
|
7533
7794
|
artifactKind: "npm",
|
|
7534
7795
|
command: distribution.command,
|
|
7535
|
-
currentVersion: "5.
|
|
7796
|
+
currentVersion: "5.1.1",
|
|
7536
7797
|
distribution: distribution.id,
|
|
7537
7798
|
executablePath: process.execPath,
|
|
7538
7799
|
package: distribution.package,
|