@qoder-ai/qmind-cli 3.0.0 → 3.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 +20 -0
- package/CHANGELOG.zh-CN.md +20 -0
- package/README.md +25 -13
- package/README.zh-CN.md +25 -13
- package/dist/bot-gateway-CB6KrV15.js +373 -0
- package/dist/cards-JaeY0mah.js +132 -0
- package/dist/{imports-Da88W09Q.js → imports-CHEgKeR5.js} +3 -3
- package/dist/{management-xYuUDFtg.js → management-J4OEjnLA.js} +5 -4
- package/dist/notes-CxkxuWdP.js +128 -0
- package/dist/qmind.js +396 -395
- package/dist/{shared-DwycozMA.js → shared-9iPJsfjP.js} +15 -6
- package/dist/source-upload-mZ-N52xb.js +17 -0
- package/dist/transfers-BRx_Hrlz.js +254 -0
- package/package.json +5 -3
- package/dist/cards-2J6ebaI0.js +0 -75
package/dist/qmind.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as notebookSchema, B as sourceSchema, C as chatMessageListSchema, D as imageUrlsSchema, E as imageUploadTicketSchema, F as sourceContentSchema, G as sourceWebOfficeTokenSchema, H as sourceUploadCapabilitiesSchema, I as sourceImportResultsSchema, J as taskRunSchema, K as streamWireEventSchema, L as sourceListSchema, M as sharedNotebookListSchema, N as sourceActionAccessSchema, P as sourceChildrenCountsSchema, R as sourcePreviewSchema, T as chatSessionSchema, V as sourceTreeSchema, W as sourceWebOfficeSessionSchema, X as voidResponseSchema, Z as wikiBranchListSchema, a as invalidArgument$1, b as cancelQuestionResultSchema, c as optionalRecord, d as pagination$1, et as assertCapability, f as positiveInteger$1, g as stringList, i as httpUrl, j as retrieveResultSchema, k as notebookListSchema, l as optionalString$1, m as requiredString$2, n as call, o as nonNegativeInteger$1, p as queryPath, q as taskRunListSchema, r as compactUndefined, rt as QMindError, s as optionalBoolean, t as assertNonEmptyPatch, tt as executeStream, u as optionalTrimmedString, w as chatSessionListSchema, y as batchMutationResultSchema, z as sourceRawContentSchema } from "./shared-9iPJsfjP.js";
|
|
2
|
+
import { t as preflightSourceUpload } from "./source-upload-mZ-N52xb.js";
|
|
2
3
|
import { createInterface } from "node:readline/promises";
|
|
3
4
|
import { basename, dirname, extname, join, relative, resolve, sep } from "node:path";
|
|
4
5
|
import { z } from "zod";
|
|
5
6
|
import { createHash, randomBytes } from "node:crypto";
|
|
6
|
-
import { chmod, copyFile, link, lstat, mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
7
|
-
import { homedir } from "node:os";
|
|
7
|
+
import { chmod, copyFile, link, lstat, mkdir, mkdtemp, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
8
|
+
import { homedir, tmpdir } from "node:os";
|
|
8
9
|
import lockfile from "proper-lockfile";
|
|
9
10
|
import open from "open";
|
|
10
11
|
import { createReadStream, createWriteStream } from "node:fs";
|
|
@@ -16,9 +17,12 @@ import { Command, CommanderError, Option } from "commander";
|
|
|
16
17
|
import pLimit from "p-limit";
|
|
17
18
|
import picomatch from "picomatch";
|
|
18
19
|
import { decodeHTML } from "entities";
|
|
20
|
+
import { execFile, spawn } from "node:child_process";
|
|
21
|
+
import { promisify } from "node:util";
|
|
22
|
+
import semver from "semver";
|
|
19
23
|
//#region ../sdk/src/operations/agents.ts
|
|
20
24
|
const workflowPrompt = "Follow the system prompt strictly: use the provided tools to discover, process and prepare the result, then emit the final report. Do NOT greet, do NOT ask for clarification — act immediately.";
|
|
21
|
-
function isRecord$
|
|
25
|
+
function isRecord$2(value) {
|
|
22
26
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23
27
|
}
|
|
24
28
|
function finiteNumber(value, field) {
|
|
@@ -62,7 +66,7 @@ function billingContext(value) {
|
|
|
62
66
|
});
|
|
63
67
|
}
|
|
64
68
|
function retrieveBody(input) {
|
|
65
|
-
if (!isRecord$
|
|
69
|
+
if (!isRecord$2(input)) throw invalidArgument$1("input must be an object", "input");
|
|
66
70
|
return compactUndefined({
|
|
67
71
|
billingContext: billingContext(input.billingContext),
|
|
68
72
|
maxResults: nonNegativeInteger$1(input.maxResults, "maxResults"),
|
|
@@ -74,7 +78,7 @@ function retrieveBody(input) {
|
|
|
74
78
|
});
|
|
75
79
|
}
|
|
76
80
|
function chatSessionBody(input = {}) {
|
|
77
|
-
if (!isRecord$
|
|
81
|
+
if (!isRecord$2(input)) throw invalidArgument$1("input must be an object", "input");
|
|
78
82
|
return compactUndefined({
|
|
79
83
|
metadata: optionalRecord(input.metadata, "metadata"),
|
|
80
84
|
modelOverride: optionalTrimmedString(input.modelOverride, "modelOverride"),
|
|
@@ -84,7 +88,7 @@ function chatSessionBody(input = {}) {
|
|
|
84
88
|
});
|
|
85
89
|
}
|
|
86
90
|
function streamBody(input) {
|
|
87
|
-
if (!isRecord$
|
|
91
|
+
if (!isRecord$2(input)) throw invalidArgument$1("input must be an object", "input");
|
|
88
92
|
return compactUndefined({
|
|
89
93
|
content: requiredString$2(input.content, "content"),
|
|
90
94
|
maxResults: nonNegativeInteger$1(input.maxResults, "maxResults"),
|
|
@@ -95,7 +99,7 @@ function streamBody(input) {
|
|
|
95
99
|
});
|
|
96
100
|
}
|
|
97
101
|
function taskRunBody(input) {
|
|
98
|
-
if (!isRecord$
|
|
102
|
+
if (!isRecord$2(input)) throw invalidArgument$1("input must be an object", "input");
|
|
99
103
|
return compactUndefined({
|
|
100
104
|
chatSessionId: optionalTrimmedString(input.chatSessionId, "chatSessionId"),
|
|
101
105
|
config: optionalRecord(input.config, "config"),
|
|
@@ -108,7 +112,7 @@ function taskRunBody(input) {
|
|
|
108
112
|
});
|
|
109
113
|
}
|
|
110
114
|
function taskRunListPath(context, notebookId, input = {}) {
|
|
111
|
-
if (!isRecord$
|
|
115
|
+
if (!isRecord$2(input)) throw invalidArgument$1("input must be an object", "input");
|
|
112
116
|
const normalizedPage = pagination$1(input);
|
|
113
117
|
const status = optionalTrimmedString(input.status, "status");
|
|
114
118
|
if (status !== void 0 && ![
|
|
@@ -159,6 +163,19 @@ function streamCallOptions(options) {
|
|
|
159
163
|
};
|
|
160
164
|
}
|
|
161
165
|
function createAgentOperations(context) {
|
|
166
|
+
const getChatSessionFor = (notebookId, sessionId, options, featured) => {
|
|
167
|
+
const notebook = requiredString$2(notebookId, "notebookId");
|
|
168
|
+
const session = requiredString$2(sessionId, "sessionId");
|
|
169
|
+
return call(context, {
|
|
170
|
+
callOptions: options,
|
|
171
|
+
capability: featured ? "featuredNotebooks.read" : "chat",
|
|
172
|
+
idempotent: true,
|
|
173
|
+
method: "GET",
|
|
174
|
+
operation: featured ? "featuredChatSessions.get" : "chatSessions.get",
|
|
175
|
+
path: context.profile.apiPath(featured ? "featured-notebooks" : "notebooks", notebook, "chat-sessions", session),
|
|
176
|
+
schema: chatSessionSchema
|
|
177
|
+
});
|
|
178
|
+
};
|
|
162
179
|
const createChatSessionFor = (notebookId, input, options, featured) => {
|
|
163
180
|
const notebook = requiredString$2(notebookId, "notebookId");
|
|
164
181
|
return call(context, {
|
|
@@ -202,7 +219,7 @@ function createAgentOperations(context) {
|
|
|
202
219
|
const cancelQuestionFor = (notebookId, sessionId, input = {}, options, featured = false) => {
|
|
203
220
|
const notebook = requiredString$2(notebookId, "notebookId");
|
|
204
221
|
const session = requiredString$2(sessionId, "sessionId");
|
|
205
|
-
if (!isRecord$
|
|
222
|
+
if (!isRecord$2(input)) throw invalidArgument$1("input must be an object", "input");
|
|
206
223
|
return call(context, {
|
|
207
224
|
body: compactUndefined({ reason: optionalTrimmedString(input.reason, "reason") }),
|
|
208
225
|
callOptions: options,
|
|
@@ -252,7 +269,7 @@ function createAgentOperations(context) {
|
|
|
252
269
|
const session = requiredString$2(sessionId, "sessionId");
|
|
253
270
|
return call(context, {
|
|
254
271
|
callOptions: options,
|
|
255
|
-
capability: featured ? "
|
|
272
|
+
capability: featured ? "featuredChat.delete" : "chat",
|
|
256
273
|
idempotent: false,
|
|
257
274
|
method: "DELETE",
|
|
258
275
|
operation: featured ? "featuredChatSessions.delete" : "chatSessions.delete",
|
|
@@ -261,7 +278,7 @@ function createAgentOperations(context) {
|
|
|
261
278
|
});
|
|
262
279
|
};
|
|
263
280
|
const startAgentRunFor = async (notebookId, input, options, featured) => {
|
|
264
|
-
if (!isRecord$
|
|
281
|
+
if (!isRecord$2(input)) throw invalidArgument$1("input must be an object", "input");
|
|
265
282
|
if (input.scene !== "rag" && input.scene !== "compilation" && input.scene !== "lint") throw invalidArgument$1("scene must be rag, compilation or lint", "scene");
|
|
266
283
|
const notebook = requiredString$2(notebookId, "notebookId");
|
|
267
284
|
const scene = input.scene;
|
|
@@ -279,6 +296,8 @@ function createAgentOperations(context) {
|
|
|
279
296
|
};
|
|
280
297
|
};
|
|
281
298
|
return {
|
|
299
|
+
getChatSession: (notebookId, sessionId, options) => getChatSessionFor(notebookId, sessionId, options, false),
|
|
300
|
+
getFeaturedChatSession: (notebookId, sessionId, options) => getChatSessionFor(notebookId, sessionId, options, true),
|
|
282
301
|
cancelFeaturedQuestion: (notebookId, sessionId, input, options) => cancelQuestionFor(notebookId, sessionId, input, options, true),
|
|
283
302
|
cancelQuestion: (notebookId, sessionId, input, options) => cancelQuestionFor(notebookId, sessionId, input, options),
|
|
284
303
|
createChatSession,
|
|
@@ -350,6 +369,18 @@ function createAgentOperations(context) {
|
|
|
350
369
|
//#region ../sdk/src/operations/notebooks.ts
|
|
351
370
|
function createNotebookOperations(context) {
|
|
352
371
|
return {
|
|
372
|
+
async copyFeaturedNotebook(notebookId, options) {
|
|
373
|
+
const notebook = requiredString$2(notebookId, "notebookId");
|
|
374
|
+
return call(context, {
|
|
375
|
+
callOptions: options,
|
|
376
|
+
capability: "featuredNotebooks.copy",
|
|
377
|
+
idempotent: false,
|
|
378
|
+
method: "POST",
|
|
379
|
+
operation: "featuredNotebooks.copy",
|
|
380
|
+
path: context.profile.apiPath("featured-notebooks", notebook, "copy"),
|
|
381
|
+
schema: notebookSchema
|
|
382
|
+
});
|
|
383
|
+
},
|
|
353
384
|
async createNotebook(input, options) {
|
|
354
385
|
const title = requiredString$2(input?.title, "title");
|
|
355
386
|
const description = optionalString$1(input?.description, "description");
|
|
@@ -511,7 +542,9 @@ function buildSourceTree(sources) {
|
|
|
511
542
|
const parentIds = new Set(sources.filter((source) => sourcesById.has(source.parentSourceId) && !createsSourceCycle(source, sourcesById)).map((source) => source.parentSourceId));
|
|
512
543
|
const nodesById = /* @__PURE__ */ new Map();
|
|
513
544
|
for (const source of sources) nodesById.set(source.id, {
|
|
545
|
+
...source.externalBinding === void 0 ? {} : { externalBinding: source.externalBinding },
|
|
514
546
|
files: [],
|
|
547
|
+
hasChildren: source.hasChildren ?? (source.childrenCount === void 0 ? source.isDir : source.childrenCount > 0),
|
|
515
548
|
id: source.id,
|
|
516
549
|
name: source.title,
|
|
517
550
|
path: source.path,
|
|
@@ -641,6 +674,14 @@ function createSourceOperations(context) {
|
|
|
641
674
|
});
|
|
642
675
|
};
|
|
643
676
|
const listSources = (notebookId, input, options) => readSourcePage(notebookId, input, options);
|
|
677
|
+
const normalizeChildrenPage = (page) => ({
|
|
678
|
+
...page,
|
|
679
|
+
sources: page.sources.map((source) => ({
|
|
680
|
+
...source,
|
|
681
|
+
hasChildren: source.hasChildren ?? (source.childrenCount === void 0 ? source.isDir : source.childrenCount > 0)
|
|
682
|
+
}))
|
|
683
|
+
});
|
|
684
|
+
const isMissingChildrenRoute = (error) => error instanceof QMindError && (error.status === 404 || error.status === 405 || error.upstreamCode?.toLowerCase() === "routenotfound");
|
|
644
685
|
const listFeaturedSources = async (notebookId, input = {}, options) => {
|
|
645
686
|
const notebook = requiredString$2(notebookId, "notebookId");
|
|
646
687
|
const normalizedPage = pagination$1({
|
|
@@ -665,6 +706,43 @@ function createSourceOperations(context) {
|
|
|
665
706
|
schema: sourceListSchema
|
|
666
707
|
});
|
|
667
708
|
};
|
|
709
|
+
const listSourceChildrenPage = async (featured, notebookId, input, options) => {
|
|
710
|
+
const notebook = requiredString$2(notebookId, "notebookId");
|
|
711
|
+
const { page, pageSize } = pagination$1({
|
|
712
|
+
page: input.page ?? 1,
|
|
713
|
+
pageSize: input.pageSize ?? 100
|
|
714
|
+
});
|
|
715
|
+
const parentSourceId = optionalString$1(input.parentSourceId, "parentSourceId");
|
|
716
|
+
const collection = featured ? "featured-notebooks" : "notebooks";
|
|
717
|
+
const operation = featured ? "featuredSources.children.list" : "sources.children.list";
|
|
718
|
+
if (featured || context.profile.access !== "sash") try {
|
|
719
|
+
const result = await call(context, {
|
|
720
|
+
callOptions: options,
|
|
721
|
+
capability: featured ? "featuredNotebooks.read" : "sources.children",
|
|
722
|
+
idempotent: true,
|
|
723
|
+
method: "GET",
|
|
724
|
+
operation,
|
|
725
|
+
path: queryPath(context.profile.apiPath(collection, notebook, "source-tree", "children"), [
|
|
726
|
+
["parent_source_id", parentSourceId],
|
|
727
|
+
["page", page],
|
|
728
|
+
["page_size", pageSize]
|
|
729
|
+
]),
|
|
730
|
+
schema: sourceListSchema.nullable()
|
|
731
|
+
});
|
|
732
|
+
if (result !== null) return normalizeChildrenPage(result);
|
|
733
|
+
} catch (error) {
|
|
734
|
+
if (!isMissingChildrenRoute(error)) throw error;
|
|
735
|
+
}
|
|
736
|
+
const fallbackInput = {
|
|
737
|
+
page,
|
|
738
|
+
pageSize,
|
|
739
|
+
parentSourceId,
|
|
740
|
+
view: "children"
|
|
741
|
+
};
|
|
742
|
+
return normalizeChildrenPage(featured ? await listFeaturedSources(notebook, fallbackInput, options) : await readSourcePage(notebook, fallbackInput, options, "sources.children.list"));
|
|
743
|
+
};
|
|
744
|
+
const listSourceChildren = (notebookId, input = {}, options) => listSourceChildrenPage(false, notebookId, input, options);
|
|
745
|
+
const listFeaturedSourceChildren = (notebookId, input = {}, options) => listSourceChildrenPage(true, notebookId, input, options);
|
|
668
746
|
const collectAllSources = async (notebookId, input = {}, options, operation) => {
|
|
669
747
|
const notebook = requiredString$2(notebookId, "notebookId");
|
|
670
748
|
const pageSize = positiveInteger$1(input.pageSize, "pageSize") ?? 200;
|
|
@@ -903,6 +981,9 @@ function createSourceOperations(context) {
|
|
|
903
981
|
schema: sourceUploadCapabilitiesSchema
|
|
904
982
|
});
|
|
905
983
|
},
|
|
984
|
+
preflightSourceUpload(notebookId, options) {
|
|
985
|
+
return preflightSourceUpload(context, notebookId, options);
|
|
986
|
+
},
|
|
906
987
|
async getFeaturedSourceTree(notebookId, options) {
|
|
907
988
|
return buildSourceTree((await listFeaturedSources(notebookId, {
|
|
908
989
|
page: 1,
|
|
@@ -910,6 +991,8 @@ function createSourceOperations(context) {
|
|
|
910
991
|
}, options)).sources);
|
|
911
992
|
},
|
|
912
993
|
getSourceTree,
|
|
994
|
+
listFeaturedSourceChildren,
|
|
995
|
+
listSourceChildren,
|
|
913
996
|
async importSite(notebookId, input, options) {
|
|
914
997
|
const notebook = requiredString$2(notebookId, "notebookId");
|
|
915
998
|
return call(context, {
|
|
@@ -1045,225 +1128,17 @@ function createSourceOperations(context) {
|
|
|
1045
1128
|
};
|
|
1046
1129
|
}
|
|
1047
1130
|
//#endregion
|
|
1048
|
-
//#region ../sdk/src/operations/transfers.ts
|
|
1049
|
-
function isRecord$2(value) {
|
|
1050
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1051
|
-
}
|
|
1052
|
-
function binarySource(value) {
|
|
1053
|
-
if (!isRecord$2(value)) throw invalidArgument$1("source must be a QMindBinarySource", "source");
|
|
1054
|
-
const filename = requiredString$2(value.filename, "source.filename");
|
|
1055
|
-
const mimeType = requiredString$2(value.mimeType, "source.mimeType");
|
|
1056
|
-
const size = value.size;
|
|
1057
|
-
if (typeof size !== "number" || !Number.isSafeInteger(size) || size <= 0) throw invalidArgument$1("source.size must be a positive safe integer", "source.size");
|
|
1058
|
-
if (typeof value.open !== "function") throw invalidArgument$1("source.open must be a function", "source.open");
|
|
1059
|
-
const source = value;
|
|
1060
|
-
return {
|
|
1061
|
-
filename,
|
|
1062
|
-
mimeType,
|
|
1063
|
-
open: () => source.open(),
|
|
1064
|
-
size
|
|
1065
|
-
};
|
|
1066
|
-
}
|
|
1067
|
-
function transferOptions(options) {
|
|
1068
|
-
if (options === void 0) return {};
|
|
1069
|
-
if (!isRecord$2(options)) throw invalidArgument$1("options must be an object", "options");
|
|
1070
|
-
if (options.onProgress !== void 0 && typeof options.onProgress !== "function") throw invalidArgument$1("onProgress must be a function", "onProgress");
|
|
1071
|
-
return options;
|
|
1072
|
-
}
|
|
1073
|
-
function uploadMetadata(value) {
|
|
1074
|
-
if (value === void 0) return {};
|
|
1075
|
-
if (!isRecord$2(value)) throw invalidArgument$1("metadata must be an object", "metadata");
|
|
1076
|
-
return {
|
|
1077
|
-
parentSourceId: optionalString$1(value.parentSourceId, "parentSourceId"),
|
|
1078
|
-
path: optionalString$1(value.path, "path"),
|
|
1079
|
-
sha256: optionalTrimmedString(value.sha256, "sha256"),
|
|
1080
|
-
sourceType: optionalTrimmedString(value.sourceType, "sourceType"),
|
|
1081
|
-
title: optionalTrimmedString(value.title, "title")
|
|
1082
|
-
};
|
|
1083
|
-
}
|
|
1084
|
-
function progressReporter(context, operation, strategy, totalBytes, options) {
|
|
1085
|
-
let lastUploadedBytes = 0;
|
|
1086
|
-
const notify = (phase, uploadedBytes) => {
|
|
1087
|
-
if (!Number.isSafeInteger(uploadedBytes) || uploadedBytes < lastUploadedBytes) throw new QMindError("HOST_POLICY_ERROR", "upload progress must be a monotonic integer", {
|
|
1088
|
-
access: context.profile.access,
|
|
1089
|
-
details: {
|
|
1090
|
-
lastUploadedBytes,
|
|
1091
|
-
totalBytes,
|
|
1092
|
-
uploadedBytes
|
|
1093
|
-
},
|
|
1094
|
-
operation
|
|
1095
|
-
});
|
|
1096
|
-
if (uploadedBytes > totalBytes) throw new QMindError("HOST_POLICY_ERROR", "upload progress exceeds source size", {
|
|
1097
|
-
access: context.profile.access,
|
|
1098
|
-
details: {
|
|
1099
|
-
totalBytes,
|
|
1100
|
-
uploadedBytes
|
|
1101
|
-
},
|
|
1102
|
-
operation
|
|
1103
|
-
});
|
|
1104
|
-
lastUploadedBytes = uploadedBytes;
|
|
1105
|
-
const progress = {
|
|
1106
|
-
phase,
|
|
1107
|
-
strategy,
|
|
1108
|
-
totalBytes,
|
|
1109
|
-
uploadedBytes
|
|
1110
|
-
};
|
|
1111
|
-
options.onProgress?.(progress);
|
|
1112
|
-
};
|
|
1113
|
-
return {
|
|
1114
|
-
complete: () => notify("uploading", totalBytes),
|
|
1115
|
-
registering: () => notify("registering", totalBytes),
|
|
1116
|
-
start: () => notify("uploading", 0),
|
|
1117
|
-
update: (uploadedBytes) => notify("uploading", uploadedBytes)
|
|
1118
|
-
};
|
|
1119
|
-
}
|
|
1120
|
-
function requestOptions(options) {
|
|
1121
|
-
return {
|
|
1122
|
-
...options.signal === void 0 ? {} : { signal: options.signal },
|
|
1123
|
-
...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs }
|
|
1124
|
-
};
|
|
1125
|
-
}
|
|
1126
|
-
function transferCall(context, operation, request, schema) {
|
|
1127
|
-
return executeUnary({
|
|
1128
|
-
capability: operation.startsWith("images.") ? "images.presignUpload" : "transfers",
|
|
1129
|
-
operation,
|
|
1130
|
-
profile: context.profile,
|
|
1131
|
-
request,
|
|
1132
|
-
schema,
|
|
1133
|
-
transport: context.transport
|
|
1134
|
-
});
|
|
1135
|
-
}
|
|
1136
|
-
function hostRequest(path, method, idempotent, options, body) {
|
|
1137
|
-
const authorization = options.authorization?.trim();
|
|
1138
|
-
return {
|
|
1139
|
-
body,
|
|
1140
|
-
destination: {
|
|
1141
|
-
kind: "host",
|
|
1142
|
-
path
|
|
1143
|
-
},
|
|
1144
|
-
...authorization === void 0 || authorization.length === 0 ? {} : { headers: { authorization: `Bearer ${authorization}` } },
|
|
1145
|
-
idempotent,
|
|
1146
|
-
method,
|
|
1147
|
-
...requestOptions(options)
|
|
1148
|
-
};
|
|
1149
|
-
}
|
|
1150
|
-
function signedUploadRequest(ticket, source, progress, options) {
|
|
1151
|
-
return {
|
|
1152
|
-
body: {
|
|
1153
|
-
kind: "binary",
|
|
1154
|
-
onProgress: progress.update,
|
|
1155
|
-
source
|
|
1156
|
-
},
|
|
1157
|
-
destination: {
|
|
1158
|
-
kind: "signed",
|
|
1159
|
-
url: ticket.uploadUrl
|
|
1160
|
-
},
|
|
1161
|
-
headers: ticket.headers,
|
|
1162
|
-
idempotent: true,
|
|
1163
|
-
method: "PUT",
|
|
1164
|
-
...requestOptions(options)
|
|
1165
|
-
};
|
|
1166
|
-
}
|
|
1167
|
-
function createTransferOperations(context) {
|
|
1168
|
-
return {
|
|
1169
|
-
async uploadImage(notebookId, sourceId, rawSource, rawOptions) {
|
|
1170
|
-
const notebook = requiredString$2(notebookId, "notebookId");
|
|
1171
|
-
const sourceIdValue = requiredString$2(sourceId, "sourceId");
|
|
1172
|
-
const source = binarySource(rawSource);
|
|
1173
|
-
const options = transferOptions(rawOptions);
|
|
1174
|
-
if (source.size > 52428800) throw new QMindError("FILE_TOO_LARGE", "image exceeds the 50 MiB upload limit", {
|
|
1175
|
-
access: context.profile.access,
|
|
1176
|
-
details: {
|
|
1177
|
-
limitBytes: QMIND_MULTIPART_UPLOAD_MAX_BYTES,
|
|
1178
|
-
size: source.size
|
|
1179
|
-
},
|
|
1180
|
-
operation: "images.upload"
|
|
1181
|
-
});
|
|
1182
|
-
const ticket = await transferCall(context, "images.presignUpload", hostRequest(context.profile.apiPath("notebooks", notebook, "sources", sourceIdValue, "images", "presign"), "POST", false, options, {
|
|
1183
|
-
kind: "json",
|
|
1184
|
-
value: {
|
|
1185
|
-
filename: source.filename,
|
|
1186
|
-
mimeType: source.mimeType,
|
|
1187
|
-
size: source.size
|
|
1188
|
-
}
|
|
1189
|
-
}), imageUploadTicketSchema);
|
|
1190
|
-
const progress = progressReporter(context, "images.upload", "presigned", source.size, options);
|
|
1191
|
-
progress.start();
|
|
1192
|
-
await transferCall(context, "images.upload", signedUploadRequest(ticket, source, progress, options), voidResponseSchema);
|
|
1193
|
-
progress.complete();
|
|
1194
|
-
return ticket;
|
|
1195
|
-
},
|
|
1196
|
-
async uploadSource(notebookId, rawSource, rawMetadata, rawOptions) {
|
|
1197
|
-
const notebook = requiredString$2(notebookId, "notebookId");
|
|
1198
|
-
const source = binarySource(rawSource);
|
|
1199
|
-
const metadata = uploadMetadata(rawMetadata);
|
|
1200
|
-
const options = transferOptions(rawOptions);
|
|
1201
|
-
if (source.size > 524288e3) throw new QMindError("FILE_TOO_LARGE", "file exceeds the 500 MiB upload limit", {
|
|
1202
|
-
access: context.profile.access,
|
|
1203
|
-
details: {
|
|
1204
|
-
limitBytes: QMIND_SOURCE_UPLOAD_MAX_BYTES,
|
|
1205
|
-
size: source.size
|
|
1206
|
-
},
|
|
1207
|
-
operation: "transfers.source.multipart"
|
|
1208
|
-
});
|
|
1209
|
-
if (source.size <= 52428800) {
|
|
1210
|
-
const progress = progressReporter(context, "transfers.source.multipart", "multipart", source.size, options);
|
|
1211
|
-
progress.start();
|
|
1212
|
-
const fields = compactUndefined({
|
|
1213
|
-
parent_source_id: metadata.parentSourceId,
|
|
1214
|
-
path: metadata.path,
|
|
1215
|
-
retain_original_file: "true",
|
|
1216
|
-
source_type: metadata.sourceType,
|
|
1217
|
-
title: metadata.title
|
|
1218
|
-
});
|
|
1219
|
-
const result = await transferCall(context, "transfers.source.multipart", hostRequest(queryPath(context.profile.apiPath("notebooks", notebook, "sources", "upload"), [["client", context.client]]), "POST", false, options, {
|
|
1220
|
-
file: source,
|
|
1221
|
-
fields,
|
|
1222
|
-
kind: "multipart",
|
|
1223
|
-
onProgress: progress.update
|
|
1224
|
-
}), sourceSchema);
|
|
1225
|
-
progress.complete();
|
|
1226
|
-
return result;
|
|
1227
|
-
}
|
|
1228
|
-
const ticket = await transferCall(context, "transfers.source.presign", hostRequest(context.profile.apiPath("notebooks", notebook, "sources", "presign"), "POST", false, options, {
|
|
1229
|
-
kind: "json",
|
|
1230
|
-
value: {
|
|
1231
|
-
filename: source.filename,
|
|
1232
|
-
mimeType: source.mimeType,
|
|
1233
|
-
size: source.size
|
|
1234
|
-
}
|
|
1235
|
-
}), sourceUploadTicketSchema);
|
|
1236
|
-
const progress = progressReporter(context, "transfers.source.upload", "presigned", source.size, options);
|
|
1237
|
-
progress.start();
|
|
1238
|
-
await transferCall(context, "transfers.source.upload", signedUploadRequest(ticket, source, progress, options), voidResponseSchema);
|
|
1239
|
-
progress.complete();
|
|
1240
|
-
progress.registering();
|
|
1241
|
-
return transferCall(context, "transfers.source.register", hostRequest(context.profile.apiPath("notebooks", notebook, "sources", "register"), "POST", false, options, {
|
|
1242
|
-
kind: "json",
|
|
1243
|
-
value: compactUndefined({
|
|
1244
|
-
filename: source.filename,
|
|
1245
|
-
mimeType: source.mimeType,
|
|
1246
|
-
parentSourceId: metadata.parentSourceId,
|
|
1247
|
-
path: metadata.path,
|
|
1248
|
-
sha256: metadata.sha256,
|
|
1249
|
-
size: source.size,
|
|
1250
|
-
sourceType: metadata.sourceType,
|
|
1251
|
-
title: metadata.title,
|
|
1252
|
-
uri: ticket.uri
|
|
1253
|
-
})
|
|
1254
|
-
}), sourceSchema);
|
|
1255
|
-
}
|
|
1256
|
-
};
|
|
1257
|
-
}
|
|
1258
|
-
//#endregion
|
|
1259
1131
|
//#region ../sdk/src/capabilities.ts
|
|
1260
1132
|
const dashboardCapabilities = Object.freeze({
|
|
1261
|
-
botGateway:
|
|
1133
|
+
botGateway: true,
|
|
1262
1134
|
"cards.read": true,
|
|
1263
1135
|
"cards.write": true,
|
|
1136
|
+
"cards.saveResults": true,
|
|
1264
1137
|
chat: true,
|
|
1138
|
+
"featuredChat.delete": false,
|
|
1265
1139
|
compilation: true,
|
|
1266
1140
|
"featuredNotebooks.read": true,
|
|
1141
|
+
"featuredNotebooks.copy": true,
|
|
1267
1142
|
"images.presignUpload": false,
|
|
1268
1143
|
"images.presignUrls": false,
|
|
1269
1144
|
"imports.aliDing": true,
|
|
@@ -1272,14 +1147,15 @@ const dashboardCapabilities = Object.freeze({
|
|
|
1272
1147
|
"notebooks.filterByClient": false,
|
|
1273
1148
|
"notebooks.read": true,
|
|
1274
1149
|
"notebooks.write": true,
|
|
1275
|
-
"notes.read":
|
|
1276
|
-
"notes.write":
|
|
1150
|
+
"notes.read": true,
|
|
1151
|
+
"notes.write": true,
|
|
1152
|
+
"notes.saveCondensation": true,
|
|
1277
1153
|
retrieval: true,
|
|
1278
1154
|
scheduledTasks: true,
|
|
1279
1155
|
"sharedNotebooks.read": true,
|
|
1280
1156
|
"sources.children": true,
|
|
1281
1157
|
"sources.childrenCount": true,
|
|
1282
|
-
"sources.actionAccess":
|
|
1158
|
+
"sources.actionAccess": false,
|
|
1283
1159
|
"sources.importWeb": true,
|
|
1284
1160
|
"sources.preview": true,
|
|
1285
1161
|
"sources.rawContent": true,
|
|
@@ -1297,9 +1173,12 @@ const sashCapabilities = Object.freeze({
|
|
|
1297
1173
|
botGateway: false,
|
|
1298
1174
|
"cards.read": true,
|
|
1299
1175
|
"cards.write": true,
|
|
1176
|
+
"cards.saveResults": false,
|
|
1300
1177
|
chat: true,
|
|
1178
|
+
"featuredChat.delete": false,
|
|
1301
1179
|
compilation: false,
|
|
1302
1180
|
"featuredNotebooks.read": false,
|
|
1181
|
+
"featuredNotebooks.copy": true,
|
|
1303
1182
|
"images.presignUpload": true,
|
|
1304
1183
|
"images.presignUrls": true,
|
|
1305
1184
|
"imports.aliDing": false,
|
|
@@ -1308,8 +1187,9 @@ const sashCapabilities = Object.freeze({
|
|
|
1308
1187
|
"notebooks.filterByClient": true,
|
|
1309
1188
|
"notebooks.read": true,
|
|
1310
1189
|
"notebooks.write": true,
|
|
1311
|
-
"notes.read":
|
|
1312
|
-
"notes.write":
|
|
1190
|
+
"notes.read": true,
|
|
1191
|
+
"notes.write": true,
|
|
1192
|
+
"notes.saveCondensation": false,
|
|
1313
1193
|
retrieval: true,
|
|
1314
1194
|
scheduledTasks: false,
|
|
1315
1195
|
"sharedNotebooks.read": false,
|
|
@@ -1554,7 +1434,8 @@ const cardOperationNames = [
|
|
|
1554
1434
|
"deleteCard",
|
|
1555
1435
|
"getCard",
|
|
1556
1436
|
"listCards",
|
|
1557
|
-
"listFeaturedCards"
|
|
1437
|
+
"listFeaturedCards",
|
|
1438
|
+
"saveCompilationResult"
|
|
1558
1439
|
];
|
|
1559
1440
|
const importOperationNames = [
|
|
1560
1441
|
"getAliDingImportRun",
|
|
@@ -1563,10 +1444,60 @@ const importOperationNames = [
|
|
|
1563
1444
|
"startAliDingKnowledgeBaseImport",
|
|
1564
1445
|
"startAliDingNodeSubtreeImport"
|
|
1565
1446
|
];
|
|
1447
|
+
const noteOperationNames = [
|
|
1448
|
+
"createNote",
|
|
1449
|
+
"deleteNote",
|
|
1450
|
+
"getNote",
|
|
1451
|
+
"listNotes",
|
|
1452
|
+
"saveCondensationResult",
|
|
1453
|
+
"updateNote"
|
|
1454
|
+
];
|
|
1455
|
+
const botGatewayOperationNames = [
|
|
1456
|
+
"listPlatformApps",
|
|
1457
|
+
"createPlatformApp",
|
|
1458
|
+
"updatePlatformApp",
|
|
1459
|
+
"deletePlatformApp",
|
|
1460
|
+
"listExpertBindings",
|
|
1461
|
+
"updateExpertBinding",
|
|
1462
|
+
"deleteExpertBinding",
|
|
1463
|
+
"listGroupBindings",
|
|
1464
|
+
"createGroupBinding",
|
|
1465
|
+
"updateGroupBinding",
|
|
1466
|
+
"deleteGroupBinding",
|
|
1467
|
+
"publishDingTalk",
|
|
1468
|
+
"inviteDingTalkExpert"
|
|
1469
|
+
];
|
|
1470
|
+
function createLazyTransferOperations(context) {
|
|
1471
|
+
let operations;
|
|
1472
|
+
const load = () => {
|
|
1473
|
+
operations ??= import("./transfers-BRx_Hrlz.js").then(({ createTransferOperations }) => createTransferOperations(context));
|
|
1474
|
+
return operations;
|
|
1475
|
+
};
|
|
1476
|
+
return {
|
|
1477
|
+
uploadImage: (...args) => load().then((loaded) => loaded.uploadImage(...args)),
|
|
1478
|
+
uploadSource: (...args) => load().then((loaded) => loaded.uploadSource(...args))
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
function createLazyBotGatewayOperations(context) {
|
|
1482
|
+
let operations;
|
|
1483
|
+
const load = () => {
|
|
1484
|
+
operations ??= import("./bot-gateway-CB6KrV15.js").then(({ createBotGatewayOperations }) => createBotGatewayOperations(context));
|
|
1485
|
+
return operations;
|
|
1486
|
+
};
|
|
1487
|
+
return Object.fromEntries(botGatewayOperationNames.map((name) => [name, (...args) => load().then((loaded) => Reflect.apply(loaded[name], loaded, args))]));
|
|
1488
|
+
}
|
|
1489
|
+
function createLazyNoteOperations(context) {
|
|
1490
|
+
let operations;
|
|
1491
|
+
const load = () => {
|
|
1492
|
+
operations ??= import("./notes-CxkxuWdP.js").then(({ createNoteOperations }) => createNoteOperations(context));
|
|
1493
|
+
return operations;
|
|
1494
|
+
};
|
|
1495
|
+
return Object.fromEntries(noteOperationNames.map((name) => [name, (...args) => load().then((loaded) => Reflect.apply(loaded[name], loaded, args))]));
|
|
1496
|
+
}
|
|
1566
1497
|
function createLazyCardOperations(context) {
|
|
1567
1498
|
let operations;
|
|
1568
1499
|
const load = () => {
|
|
1569
|
-
operations ??= import("./cards-
|
|
1500
|
+
operations ??= import("./cards-JaeY0mah.js").then(({ createCardOperations }) => createCardOperations(context));
|
|
1570
1501
|
return operations;
|
|
1571
1502
|
};
|
|
1572
1503
|
return Object.fromEntries(cardOperationNames.map((name) => [name, (...args) => load().then((loaded) => Reflect.apply(loaded[name], loaded, args))]));
|
|
@@ -1574,7 +1505,7 @@ function createLazyCardOperations(context) {
|
|
|
1574
1505
|
function createLazyImportOperations(context) {
|
|
1575
1506
|
let operations;
|
|
1576
1507
|
const load = () => {
|
|
1577
|
-
operations ??= import("./imports-
|
|
1508
|
+
operations ??= import("./imports-CHEgKeR5.js").then(({ createImportOperations }) => createImportOperations(context));
|
|
1578
1509
|
return operations;
|
|
1579
1510
|
};
|
|
1580
1511
|
return Object.fromEntries(importOperationNames.map((name) => [name, (...args) => load().then((loaded) => Reflect.apply(loaded[name], loaded, args))]));
|
|
@@ -1582,7 +1513,7 @@ function createLazyImportOperations(context) {
|
|
|
1582
1513
|
function createLazyManagementOperations(context) {
|
|
1583
1514
|
let operations;
|
|
1584
1515
|
const load = () => {
|
|
1585
|
-
operations ??= import("./management-
|
|
1516
|
+
operations ??= import("./management-J4OEjnLA.js").then(({ createManagementOperations }) => createManagementOperations(context));
|
|
1586
1517
|
return operations;
|
|
1587
1518
|
};
|
|
1588
1519
|
return Object.fromEntries(managementOperationNames.map((name) => [name, (...args) => load().then((loaded) => Reflect.apply(loaded[name], loaded, args))]));
|
|
@@ -1605,7 +1536,9 @@ function createQMindClient(options) {
|
|
|
1605
1536
|
...createSourceOperations(context),
|
|
1606
1537
|
...createLazyImportOperations(context),
|
|
1607
1538
|
...createLazyManagementOperations(context),
|
|
1608
|
-
...
|
|
1539
|
+
...createLazyNoteOperations(context),
|
|
1540
|
+
...createLazyBotGatewayOperations(context),
|
|
1541
|
+
...createLazyTransferOperations(context),
|
|
1609
1542
|
...createAgentOperations(context),
|
|
1610
1543
|
supports(capability) {
|
|
1611
1544
|
return profile.capabilities[capability] === true;
|
|
@@ -1650,12 +1583,12 @@ function errorCodeForStatus(status) {
|
|
|
1650
1583
|
if (status >= 400 && status < 500) return "INVALID_ARGUMENT";
|
|
1651
1584
|
return "REMOTE_ERROR";
|
|
1652
1585
|
}
|
|
1653
|
-
function record$
|
|
1586
|
+
function record$2(value) {
|
|
1654
1587
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
1655
1588
|
}
|
|
1656
1589
|
function responseString(response, ...keys) {
|
|
1657
|
-
const body = record$
|
|
1658
|
-
const nestedError = record$
|
|
1590
|
+
const body = record$2(response.body);
|
|
1591
|
+
const nestedError = record$2(body?.error);
|
|
1659
1592
|
for (const source of [body, nestedError]) for (const key of keys) {
|
|
1660
1593
|
const value = source?.[key];
|
|
1661
1594
|
if (typeof value === "string" && value.length > 0) return value;
|
|
@@ -2762,40 +2695,43 @@ function createQMindNodeTransport(options) {
|
|
|
2762
2695
|
const url = requestUrl(origin, request$2);
|
|
2763
2696
|
const attempts = request$2.idempotent ? maxRetries + 1 : 1;
|
|
2764
2697
|
let lastFailure;
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
try {
|
|
2698
|
+
const timeoutMs = request$2.timeoutMs ?? requestTimeoutMs;
|
|
2699
|
+
const deadline = requestDeadline(request$2.signal, timeoutMs);
|
|
2700
|
+
try {
|
|
2701
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) try {
|
|
2769
2702
|
debugRequest(options, request$2, url);
|
|
2770
2703
|
const encoded = encodeBody(request$2, `----qmind-${randomBytes(18).toString("hex")}`);
|
|
2771
2704
|
const response = await request(url, {
|
|
2772
2705
|
...encoded.body === void 0 ? {} : { body: encoded.body },
|
|
2773
|
-
bodyTimeout:
|
|
2706
|
+
bodyTimeout: timeoutMs,
|
|
2774
2707
|
dispatcher: dispatcherFor(request$2),
|
|
2775
2708
|
headers: encoded.headers,
|
|
2776
|
-
headersTimeout:
|
|
2709
|
+
headersTimeout: timeoutMs,
|
|
2777
2710
|
idempotent: request$2.idempotent,
|
|
2778
2711
|
method: request$2.method,
|
|
2779
2712
|
signal: deadline.signal
|
|
2780
2713
|
});
|
|
2781
2714
|
if (attempt + 1 < attempts && RETRYABLE_STATUS.has(response.statusCode)) {
|
|
2782
2715
|
await response.body.dump();
|
|
2783
|
-
await abortableSleep(250 * 2 ** attempt,
|
|
2716
|
+
await abortableSleep(250 * 2 ** attempt, deadline.signal);
|
|
2784
2717
|
continue;
|
|
2785
2718
|
}
|
|
2786
2719
|
return await wireResponse(response);
|
|
2787
2720
|
} catch (cause) {
|
|
2788
2721
|
lastFailure = cause;
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
await abortableSleep(250 * 2 ** attempt,
|
|
2792
|
-
|
|
2722
|
+
if (attempt + 1 >= attempts || request$2.signal?.aborted === true || deadline.timedOut) break;
|
|
2723
|
+
try {
|
|
2724
|
+
await abortableSleep(250 * 2 ** attempt, deadline.signal);
|
|
2725
|
+
} catch (backoffCause) {
|
|
2726
|
+
lastFailure = backoffCause;
|
|
2727
|
+
break;
|
|
2793
2728
|
}
|
|
2794
|
-
|
|
2795
|
-
deadline.dispose();
|
|
2729
|
+
continue;
|
|
2796
2730
|
}
|
|
2731
|
+
throw transportFailure(request$2, lastFailure, deadline.timedOut);
|
|
2732
|
+
} finally {
|
|
2733
|
+
deadline.dispose();
|
|
2797
2734
|
}
|
|
2798
|
-
throw transportFailure(request$2, lastFailure, lastDeadlineExpired);
|
|
2799
2735
|
},
|
|
2800
2736
|
async stream(request$3) {
|
|
2801
2737
|
assertWireRequest(request$3);
|
|
@@ -3040,8 +2976,8 @@ function requestsJsonOutput(argv) {
|
|
|
3040
2976
|
//#region src/build-info.ts
|
|
3041
2977
|
/** Bundled identity, never inferred from argv, environment, or an endpoint. */
|
|
3042
2978
|
const QMIND_CLI_DISTRIBUTION = "global";
|
|
3043
|
-
const QMIND_CLI_VERSION = "3.
|
|
3044
|
-
const QMIND_CLI_BUILD_TIME = "2026-09-
|
|
2979
|
+
const QMIND_CLI_VERSION = "3.1.1";
|
|
2980
|
+
const QMIND_CLI_BUILD_TIME = "2026-09-04T10:59:00.000Z";
|
|
3045
2981
|
function qmindCliPlatform() {
|
|
3046
2982
|
return process.platform === "win32" ? "windows" : process.platform;
|
|
3047
2983
|
}
|
|
@@ -3057,6 +2993,7 @@ const CLI_DISTRIBUTIONS = Object.freeze({
|
|
|
3057
2993
|
command: "qmind",
|
|
3058
2994
|
package: "@qoder-ai/qmind-cli",
|
|
3059
2995
|
productId: "qoder",
|
|
2996
|
+
nativePublicRoot: "https://download.qoder.com/qmind-cli",
|
|
3060
2997
|
gitTagSlug: "qmind-cli",
|
|
3061
2998
|
readmeDirectory: ".",
|
|
3062
2999
|
productNames: {
|
|
@@ -3069,6 +3006,7 @@ const CLI_DISTRIBUTIONS = Object.freeze({
|
|
|
3069
3006
|
command: "qmind-cn",
|
|
3070
3007
|
package: "@qodercn-ai/qmind-cli",
|
|
3071
3008
|
productId: "qoder-cn",
|
|
3009
|
+
nativePublicRoot: "https://static.qoder.com.cn/qmind-cli-cn",
|
|
3072
3010
|
gitTagSlug: "qmind-cli-cn",
|
|
3073
3011
|
readmeDirectory: "readmes/cn",
|
|
3074
3012
|
productNames: {
|
|
@@ -3136,7 +3074,7 @@ function validateMapping(value) {
|
|
|
3136
3074
|
}
|
|
3137
3075
|
return result;
|
|
3138
3076
|
}
|
|
3139
|
-
async function sha256(path) {
|
|
3077
|
+
async function sha256$1(path) {
|
|
3140
3078
|
const hash = createHash("sha256");
|
|
3141
3079
|
for await (const chunk of createReadStream(path)) hash.update(chunk);
|
|
3142
3080
|
return hash.digest("hex");
|
|
@@ -3187,7 +3125,7 @@ function createNodeQMindFolderSyncFileSystem() {
|
|
|
3187
3125
|
skipped
|
|
3188
3126
|
};
|
|
3189
3127
|
},
|
|
3190
|
-
sha256,
|
|
3128
|
+
sha256: sha256$1,
|
|
3191
3129
|
async writeMapping(path, mapping) {
|
|
3192
3130
|
await mkdir(dirname(path), { recursive: true });
|
|
3193
3131
|
await writeFile(path, `${JSON.stringify(mapping, null, 2)}\n`, { mode: 384 });
|
|
@@ -3428,7 +3366,7 @@ function parseQMindCliOutputFormat(value) {
|
|
|
3428
3366
|
if (value === "json" || value === "agent" || value === "ndjson") return value;
|
|
3429
3367
|
return "table";
|
|
3430
3368
|
}
|
|
3431
|
-
function record(value) {
|
|
3369
|
+
function record$1(value) {
|
|
3432
3370
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
3433
3371
|
}
|
|
3434
3372
|
function stringValue(value) {
|
|
@@ -3479,15 +3417,12 @@ function timestamp(value) {
|
|
|
3479
3417
|
return (/* @__PURE__ */ new Date(parsed.seconds * 1e3)).toISOString().replace(".000Z", "Z");
|
|
3480
3418
|
}
|
|
3481
3419
|
function optionalMap(value) {
|
|
3482
|
-
const result = record(value);
|
|
3420
|
+
const result = record$1(value);
|
|
3483
3421
|
return Object.keys(result).length === 0 ? void 0 : result;
|
|
3484
3422
|
}
|
|
3485
|
-
function optionalStrings(value) {
|
|
3486
|
-
return Array.isArray(value) && value.length > 0 ? value.map(stringValue) : void 0;
|
|
3487
|
-
}
|
|
3488
3423
|
function pagination(value) {
|
|
3489
3424
|
if (value === void 0 || value === null) return "";
|
|
3490
|
-
const page = record(value);
|
|
3425
|
+
const page = record$1(value);
|
|
3491
3426
|
if ([
|
|
3492
3427
|
page.totalSize,
|
|
3493
3428
|
page.currentPage,
|
|
@@ -3497,7 +3432,7 @@ function pagination(value) {
|
|
|
3497
3432
|
return ` (server totalSize=${numberValue(page.totalSize)}, page=${numberValue(page.currentPage)}/${numberValue(page.lastPage)}, pageSize=${numberValue(page.pageSize)})`;
|
|
3498
3433
|
}
|
|
3499
3434
|
function goNotebook(value) {
|
|
3500
|
-
const source = record(value);
|
|
3435
|
+
const source = record$1(value);
|
|
3501
3436
|
const settings = optionalMap(source.settings);
|
|
3502
3437
|
return {
|
|
3503
3438
|
id: stringValue(source.id),
|
|
@@ -3522,7 +3457,7 @@ function goNotebookList(value) {
|
|
|
3522
3457
|
}
|
|
3523
3458
|
function goPage(value) {
|
|
3524
3459
|
if (value === void 0 || value === null) return void 0;
|
|
3525
|
-
const source = record(value);
|
|
3460
|
+
const source = record$1(value);
|
|
3526
3461
|
return {
|
|
3527
3462
|
prevPage: numberValue(source.prevPage),
|
|
3528
3463
|
currentPage: numberValue(source.currentPage),
|
|
@@ -3534,7 +3469,7 @@ function goPage(value) {
|
|
|
3534
3469
|
};
|
|
3535
3470
|
}
|
|
3536
3471
|
function goSource(value) {
|
|
3537
|
-
const source = record(value);
|
|
3472
|
+
const source = record$1(value);
|
|
3538
3473
|
const metadata = optionalMap(source.metadata);
|
|
3539
3474
|
return {
|
|
3540
3475
|
id: stringValue(source.id),
|
|
@@ -3565,45 +3500,6 @@ function goSourceList(value) {
|
|
|
3565
3500
|
pageSize: numberValue(value.pageSize)
|
|
3566
3501
|
};
|
|
3567
3502
|
}
|
|
3568
|
-
function goCardLink(value) {
|
|
3569
|
-
const source = record(value);
|
|
3570
|
-
return {
|
|
3571
|
-
linkType: stringValue(source.linkType),
|
|
3572
|
-
targetId: stringValue(source.targetId),
|
|
3573
|
-
...source.targetTitle ? { targetTitle: stringValue(source.targetTitle) } : {},
|
|
3574
|
-
...source.description ? { description: stringValue(source.description) } : {}
|
|
3575
|
-
};
|
|
3576
|
-
}
|
|
3577
|
-
function goCard(value) {
|
|
3578
|
-
const source = record(value);
|
|
3579
|
-
const keywords = optionalStrings(source.keywords);
|
|
3580
|
-
const links = Array.isArray(source.links) && source.links.length > 0 ? source.links.map(goCardLink) : void 0;
|
|
3581
|
-
return {
|
|
3582
|
-
id: stringValue(source.id),
|
|
3583
|
-
...source.knowledgeId ? { knowledgeId: stringValue(source.knowledgeId) } : {},
|
|
3584
|
-
orgId: stringValue(source.orgId),
|
|
3585
|
-
...source.notebookId ? { notebookId: stringValue(source.notebookId) } : {},
|
|
3586
|
-
source: stringValue(source.source),
|
|
3587
|
-
...source.cardType ? { cardType: stringValue(source.cardType) } : {},
|
|
3588
|
-
...source.category ? { category: stringValue(source.category) } : {},
|
|
3589
|
-
...source.repo ? { repo: stringValue(source.repo) } : {},
|
|
3590
|
-
title: stringValue(source.title),
|
|
3591
|
-
content: stringValue(source.content),
|
|
3592
|
-
...keywords === void 0 ? {} : { keywords },
|
|
3593
|
-
...links === void 0 ? {} : { links },
|
|
3594
|
-
...source.extra ? { extra: stringValue(source.extra) } : {},
|
|
3595
|
-
createdAt: goTimestamp(source.createdAt),
|
|
3596
|
-
updatedAt: goTimestamp(source.updatedAt)
|
|
3597
|
-
};
|
|
3598
|
-
}
|
|
3599
|
-
function goCardList(value) {
|
|
3600
|
-
return {
|
|
3601
|
-
cards: value.cards.map(goCard),
|
|
3602
|
-
totalSize: numberValue(value.totalSize),
|
|
3603
|
-
currentPage: numberValue(value.currentPage),
|
|
3604
|
-
pageSize: numberValue(value.pageSize)
|
|
3605
|
-
};
|
|
3606
|
-
}
|
|
3607
3503
|
function goRetrieve(value) {
|
|
3608
3504
|
return {
|
|
3609
3505
|
chunks: value.chunks.map((chunk) => ({
|
|
@@ -3690,32 +3586,6 @@ function renderAgentSource(writer, value, index = 0) {
|
|
|
3690
3586
|
agentField(writer, "updatedAt", timestamp(value.updatedAt));
|
|
3691
3587
|
agentText(writer, "error", value.errorMessage);
|
|
3692
3588
|
}
|
|
3693
|
-
function renderAgentCard(writer, value, index, score) {
|
|
3694
|
-
writer.line("---");
|
|
3695
|
-
agentField(writer, "type", "card");
|
|
3696
|
-
if (index > 0) agentField(writer, "index", index);
|
|
3697
|
-
if (score !== void 0) agentField(writer, "score", score.toFixed(4));
|
|
3698
|
-
agentField(writer, "id", value.id);
|
|
3699
|
-
agentField(writer, "knowledgeId", value.knowledgeId);
|
|
3700
|
-
agentField(writer, "notebookId", value.notebookId);
|
|
3701
|
-
agentField(writer, "source", value.source);
|
|
3702
|
-
agentField(writer, "cardType", value.cardType);
|
|
3703
|
-
agentField(writer, "category", value.category);
|
|
3704
|
-
agentField(writer, "repo", value.repo);
|
|
3705
|
-
agentField(writer, "title", value.title);
|
|
3706
|
-
if (value.keywords.length > 0) agentField(writer, "keywords", value.keywords.join(", "));
|
|
3707
|
-
agentField(writer, "createdAt", timestamp(value.createdAt));
|
|
3708
|
-
agentField(writer, "updatedAt", timestamp(value.updatedAt));
|
|
3709
|
-
agentText(writer, "content", value.content);
|
|
3710
|
-
if (value.links.length > 0) {
|
|
3711
|
-
writer.line("links:");
|
|
3712
|
-
for (const link of value.links) {
|
|
3713
|
-
writer.line(` - targetId: ${link.targetId}`);
|
|
3714
|
-
agentField(writer, " linkType", link.linkType);
|
|
3715
|
-
agentField(writer, " description", link.description);
|
|
3716
|
-
}
|
|
3717
|
-
}
|
|
3718
|
-
}
|
|
3719
3589
|
function json(value, pretty) {
|
|
3720
3590
|
return `${JSON.stringify(value, null, pretty ? 2 : 0)}\n`;
|
|
3721
3591
|
}
|
|
@@ -3822,42 +3692,6 @@ function renderSourceList(value, format) {
|
|
|
3822
3692
|
}
|
|
3823
3693
|
return writer.toString();
|
|
3824
3694
|
}
|
|
3825
|
-
function renderCardList(value, format) {
|
|
3826
|
-
if (format === "json") return json(goCardList(value), true);
|
|
3827
|
-
if (format === "ndjson") return value.cards.map((item) => json(goCard(item), false)).join("");
|
|
3828
|
-
const writer = new TextWriter();
|
|
3829
|
-
if (format === "agent") {
|
|
3830
|
-
agentHeader(writer, "cards", value.totalSize || value.cards.length);
|
|
3831
|
-
value.cards.forEach((item, index) => renderAgentCard(writer, item, index + 1));
|
|
3832
|
-
} else if (value.cards.length === 0) writer.line("No cards found.");
|
|
3833
|
-
else {
|
|
3834
|
-
writer.line(`Total: ${value.totalSize || value.cards.length}`);
|
|
3835
|
-
writer.line();
|
|
3836
|
-
table(writer, [
|
|
3837
|
-
"ID",
|
|
3838
|
-
"TYPE",
|
|
3839
|
-
"CATEGORY",
|
|
3840
|
-
"TITLE",
|
|
3841
|
-
"LINKS",
|
|
3842
|
-
"UPDATED"
|
|
3843
|
-
], value.cards.map((item) => [
|
|
3844
|
-
truncate(item.id, 36),
|
|
3845
|
-
truncate(item.cardType, 8),
|
|
3846
|
-
truncate(item.category, 16),
|
|
3847
|
-
truncate(item.title, 30),
|
|
3848
|
-
item.links.length,
|
|
3849
|
-
timestamp(item.updatedAt)
|
|
3850
|
-
]), [
|
|
3851
|
-
36,
|
|
3852
|
-
8,
|
|
3853
|
-
16,
|
|
3854
|
-
30,
|
|
3855
|
-
5,
|
|
3856
|
-
20
|
|
3857
|
-
], 125);
|
|
3858
|
-
}
|
|
3859
|
-
return writer.toString();
|
|
3860
|
-
}
|
|
3861
3695
|
function renderRetrieve(value, format) {
|
|
3862
3696
|
if (format === "json") return json(goRetrieve(value), true);
|
|
3863
3697
|
if (format === "ndjson") return [...value.chunks.map((item) => ({
|
|
@@ -3983,7 +3817,6 @@ function renderQMindCliPresentation(presentation, format) {
|
|
|
3983
3817
|
case "notebookList": return renderNotebookList(presentation.value, format);
|
|
3984
3818
|
case "source": return renderSource(presentation.value, format);
|
|
3985
3819
|
case "sourceList": return renderSourceList(presentation.value, format);
|
|
3986
|
-
case "cardList": return renderCardList(presentation.value, format);
|
|
3987
3820
|
case "retrieve": return renderRetrieve(presentation.value, format);
|
|
3988
3821
|
case "imageUpload": return json({
|
|
3989
3822
|
uploadUrl: presentation.value.uploadUrl,
|
|
@@ -4183,6 +4016,182 @@ function createQMindCliStreamRenderer(format) {
|
|
|
4183
4016
|
};
|
|
4184
4017
|
}
|
|
4185
4018
|
//#endregion
|
|
4019
|
+
//#region src/update.ts
|
|
4020
|
+
const execFileAsync = promisify(execFile);
|
|
4021
|
+
const SHA256 = /^[a-f0-9]{64}$/u;
|
|
4022
|
+
const MAX_CHANNEL_BYTES = 65536;
|
|
4023
|
+
const MAX_RELEASE_BYTES = 4194304;
|
|
4024
|
+
const MAX_INSTALLER_BYTES = 1048576;
|
|
4025
|
+
function sha256(bytes) {
|
|
4026
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
4027
|
+
}
|
|
4028
|
+
function record(value, label) {
|
|
4029
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) throw new Error(`${label} is invalid`);
|
|
4030
|
+
return value;
|
|
4031
|
+
}
|
|
4032
|
+
function string(value, label) {
|
|
4033
|
+
if (typeof value !== "string" || value.length === 0) throw new Error(`${label} is invalid`);
|
|
4034
|
+
return value;
|
|
4035
|
+
}
|
|
4036
|
+
async function boundedBytes(fetcher, url, limit, label) {
|
|
4037
|
+
const response = await fetcher(url, {
|
|
4038
|
+
redirect: "error",
|
|
4039
|
+
signal: AbortSignal.timeout(3e4)
|
|
4040
|
+
});
|
|
4041
|
+
if (!response.ok) throw new Error(`${label} request failed with HTTP ${response.status}`);
|
|
4042
|
+
if (response.url.length > 0 && response.url !== url) throw new Error(`${label} redirected`);
|
|
4043
|
+
const declared = Number(response.headers.get("content-length"));
|
|
4044
|
+
if (Number.isFinite(declared) && declared > limit) throw new Error(`${label} is too large`);
|
|
4045
|
+
const bytes = Buffer.from(await response.arrayBuffer());
|
|
4046
|
+
if (bytes.length === 0 || bytes.length > limit) throw new Error(`${label} is too large`);
|
|
4047
|
+
return bytes;
|
|
4048
|
+
}
|
|
4049
|
+
function parseJson(bytes, label) {
|
|
4050
|
+
try {
|
|
4051
|
+
return record(JSON.parse(bytes.toString("utf8")), label);
|
|
4052
|
+
} catch {
|
|
4053
|
+
throw new Error(`${label} is invalid`);
|
|
4054
|
+
}
|
|
4055
|
+
}
|
|
4056
|
+
function channelFrom(bytes, identity) {
|
|
4057
|
+
const channel = parseJson(bytes, "native update channel");
|
|
4058
|
+
const release = record(channel.release, "native update channel release");
|
|
4059
|
+
const version = string(channel.version, "native update channel version");
|
|
4060
|
+
const releaseSha256 = string(release.sha256, "native update release checksum");
|
|
4061
|
+
const releaseKey = string(release.key, "native update release key");
|
|
4062
|
+
if (channel.schema !== "qmind-native-channel-v1" || channel.distribution !== identity.distribution || semver.valid(version) !== version || !SHA256.test(releaseSha256) || releaseKey !== `releases/${version}/release.json` || channel.releaseSetId !== `${identity.distribution}/v${version}/${releaseSha256}`) throw new Error("native update channel identity rejected");
|
|
4063
|
+
return {
|
|
4064
|
+
releaseKey,
|
|
4065
|
+
releaseSha256,
|
|
4066
|
+
version
|
|
4067
|
+
};
|
|
4068
|
+
}
|
|
4069
|
+
function installerFrom(bytes, identity, version) {
|
|
4070
|
+
const release = parseJson(bytes, "native update release");
|
|
4071
|
+
if (release.schema !== "qmind-native-release-v1" || release.distribution !== identity.distribution || release.version !== version || !Array.isArray(release.artifacts)) throw new Error("native update release identity rejected");
|
|
4072
|
+
const selector = identity.platform === "win32" ? "ps1" : "sh";
|
|
4073
|
+
const expectedBasename = `${identity.command}-install-v${version}.${selector}`;
|
|
4074
|
+
const matches = release.artifacts.filter((value) => {
|
|
4075
|
+
const artifact = record(value, "native update artifact");
|
|
4076
|
+
return artifact.role === "script" && artifact.selector === selector && artifact.basename === expectedBasename && Number.isSafeInteger(artifact.size) && typeof artifact.sha256 === "string" && SHA256.test(artifact.sha256);
|
|
4077
|
+
});
|
|
4078
|
+
if (matches.length !== 1) throw new Error("native update installer is missing or ambiguous");
|
|
4079
|
+
const artifact = matches[0];
|
|
4080
|
+
return {
|
|
4081
|
+
basename: expectedBasename,
|
|
4082
|
+
sha256: artifact.sha256,
|
|
4083
|
+
size: artifact.size
|
|
4084
|
+
};
|
|
4085
|
+
}
|
|
4086
|
+
async function executeNativeInstaller(input) {
|
|
4087
|
+
const executableName = input.platform === "win32" ? `${input.command}.exe` : input.command;
|
|
4088
|
+
const actualName = basename(input.executablePath);
|
|
4089
|
+
if (input.platform === "win32" ? actualName.toLowerCase() !== executableName.toLowerCase() : actualName !== executableName) throw new Error("native update requires an installer-managed executable");
|
|
4090
|
+
const installDirectory = dirname(input.executablePath);
|
|
4091
|
+
const temporary = await mkdtemp(join(tmpdir(), `${input.command}-update-`));
|
|
4092
|
+
const extension = input.platform === "win32" ? "ps1" : "sh";
|
|
4093
|
+
const installerPath = join(temporary, `installer.${extension}`);
|
|
4094
|
+
await writeFile(installerPath, input.bytes, { mode: 384 });
|
|
4095
|
+
if (input.platform !== "win32") try {
|
|
4096
|
+
await execFileAsync("/bin/sh", [
|
|
4097
|
+
installerPath,
|
|
4098
|
+
"--artifact-root",
|
|
4099
|
+
input.artifactRoot,
|
|
4100
|
+
"--install-dir",
|
|
4101
|
+
installDirectory
|
|
4102
|
+
], {
|
|
4103
|
+
maxBuffer: 1048576,
|
|
4104
|
+
timeout: 3e5
|
|
4105
|
+
});
|
|
4106
|
+
return { status: "completed" };
|
|
4107
|
+
} finally {
|
|
4108
|
+
await rm(temporary, {
|
|
4109
|
+
force: true,
|
|
4110
|
+
recursive: true
|
|
4111
|
+
});
|
|
4112
|
+
}
|
|
4113
|
+
const wrapperPath = join(temporary, "apply-update.ps1");
|
|
4114
|
+
const logPath = join(installDirectory, `.${input.command}.update.log`);
|
|
4115
|
+
await writeFile(wrapperPath, `#Requires -Version 5.1\nparam([int]$ParentProcessId,[string]$InstallerPath,[string]$ArtifactRoot,[string]$InstallDirectory,[string]$LogPath,[string]$TemporaryDirectory)\n$ErrorActionPreference = "Stop"\ntry {\n Wait-Process -Id $ParentProcessId -ErrorAction SilentlyContinue\n & $InstallerPath -ArtifactRoot $ArtifactRoot -InstallDir $InstallDirectory *>&1 | Out-File -LiteralPath $LogPath -Encoding utf8\n} catch {\n $_ | Out-File -LiteralPath $LogPath -Encoding utf8\n} finally {\n Remove-Item -LiteralPath $TemporaryDirectory -Recurse -Force -ErrorAction SilentlyContinue\n}\n`, { mode: 384 });
|
|
4116
|
+
const child = spawn("powershell.exe", [
|
|
4117
|
+
"-NoLogo",
|
|
4118
|
+
"-NoProfile",
|
|
4119
|
+
"-ExecutionPolicy",
|
|
4120
|
+
"Bypass",
|
|
4121
|
+
"-File",
|
|
4122
|
+
wrapperPath,
|
|
4123
|
+
String(process.pid),
|
|
4124
|
+
installerPath,
|
|
4125
|
+
input.artifactRoot,
|
|
4126
|
+
installDirectory,
|
|
4127
|
+
logPath,
|
|
4128
|
+
temporary
|
|
4129
|
+
], {
|
|
4130
|
+
detached: true,
|
|
4131
|
+
stdio: "ignore",
|
|
4132
|
+
windowsHide: true
|
|
4133
|
+
});
|
|
4134
|
+
await new Promise((resolvePromise, reject) => {
|
|
4135
|
+
child.once("spawn", resolvePromise);
|
|
4136
|
+
child.once("error", reject);
|
|
4137
|
+
});
|
|
4138
|
+
child.unref();
|
|
4139
|
+
return {
|
|
4140
|
+
status: "scheduled",
|
|
4141
|
+
logPath
|
|
4142
|
+
};
|
|
4143
|
+
}
|
|
4144
|
+
function createQMindCliUpdater(options) {
|
|
4145
|
+
const { identity } = options;
|
|
4146
|
+
const fetcher = options.fetcher ?? fetch;
|
|
4147
|
+
const executeInstaller = options.executeInstaller ?? executeNativeInstaller;
|
|
4148
|
+
return Object.freeze({ async run({ check }) {
|
|
4149
|
+
if (identity.artifactKind === "npm") return {
|
|
4150
|
+
status: "unsupported",
|
|
4151
|
+
command: `npm update --global ${identity.package}`
|
|
4152
|
+
};
|
|
4153
|
+
const channelUrl = `${identity.publicRoot}/latest/channel`;
|
|
4154
|
+
const channel = channelFrom(await boundedBytes(fetcher, channelUrl, MAX_CHANNEL_BYTES, "native update channel"), identity);
|
|
4155
|
+
const releaseUrl = `${identity.publicRoot}/${channel.releaseKey}`;
|
|
4156
|
+
const releaseBytes = await boundedBytes(fetcher, releaseUrl, MAX_RELEASE_BYTES, "native update release");
|
|
4157
|
+
if (sha256(releaseBytes) !== channel.releaseSha256) throw new Error("native update release checksum mismatch");
|
|
4158
|
+
const installer = installerFrom(releaseBytes, identity, channel.version);
|
|
4159
|
+
const comparison = semver.compare(channel.version, identity.currentVersion);
|
|
4160
|
+
if (comparison < 0) throw new Error("native update channel would downgrade the current version");
|
|
4161
|
+
if (comparison === 0) return {
|
|
4162
|
+
status: "up-to-date",
|
|
4163
|
+
currentVersion: identity.currentVersion,
|
|
4164
|
+
latestVersion: channel.version
|
|
4165
|
+
};
|
|
4166
|
+
if (check) return {
|
|
4167
|
+
status: "available",
|
|
4168
|
+
currentVersion: identity.currentVersion,
|
|
4169
|
+
latestVersion: channel.version
|
|
4170
|
+
};
|
|
4171
|
+
const artifactRoot = `${identity.publicRoot}/releases/${channel.version}`;
|
|
4172
|
+
const installerBytes = await boundedBytes(fetcher, `${artifactRoot}/${installer.basename}`, MAX_INSTALLER_BYTES, "native update installer");
|
|
4173
|
+
if (installerBytes.length !== installer.size || sha256(installerBytes) !== installer.sha256) throw new Error("native update installer checksum mismatch");
|
|
4174
|
+
const execution = await executeInstaller({
|
|
4175
|
+
artifactRoot,
|
|
4176
|
+
bytes: installerBytes,
|
|
4177
|
+
command: identity.command,
|
|
4178
|
+
executablePath: identity.executablePath,
|
|
4179
|
+
platform: identity.platform,
|
|
4180
|
+
version: channel.version
|
|
4181
|
+
});
|
|
4182
|
+
return execution.status === "scheduled" ? {
|
|
4183
|
+
status: "scheduled",
|
|
4184
|
+
currentVersion: identity.currentVersion,
|
|
4185
|
+
latestVersion: channel.version,
|
|
4186
|
+
logPath: execution.logPath ?? join(dirname(identity.executablePath), `.${identity.command}.update.log`)
|
|
4187
|
+
} : {
|
|
4188
|
+
status: "updated",
|
|
4189
|
+
currentVersion: identity.currentVersion,
|
|
4190
|
+
latestVersion: channel.version
|
|
4191
|
+
};
|
|
4192
|
+
} });
|
|
4193
|
+
}
|
|
4194
|
+
//#endregion
|
|
4186
4195
|
//#region src/application.ts
|
|
4187
4196
|
const distribution = CLI_DISTRIBUTIONS[QMIND_CLI_DISTRIBUTION];
|
|
4188
4197
|
function processIO() {
|
|
@@ -4289,22 +4298,6 @@ function withCommon(command, output = true) {
|
|
|
4289
4298
|
if (output) command.option("--format <format>", "output format: table | json | agent | ndjson", "table");
|
|
4290
4299
|
return command;
|
|
4291
4300
|
}
|
|
4292
|
-
function registerCardQueryCommand(context, command) {
|
|
4293
|
-
withCommon(command).option("--nb <id>", "notebook ID (required)").option("-q, --query <query>", "search query", "").option("--cat <category>", "category filter", "").option("--page <number>", "page number", integer, 0).option("--page-size <number>", "page size", integer, 20).action(async (raw) => {
|
|
4294
|
-
const host = await hostFor(context, raw);
|
|
4295
|
-
const page = positiveNumberOption(raw, "page", 0);
|
|
4296
|
-
const pageSize = positiveNumberOption(raw, "pageSize", 20);
|
|
4297
|
-
render(context, raw, {
|
|
4298
|
-
kind: "cardList",
|
|
4299
|
-
value: await host.client.listCards(requiredString(raw.nb, "--nb"), {
|
|
4300
|
-
category: String(raw.cat ?? ""),
|
|
4301
|
-
...page === void 0 ? {} : { page },
|
|
4302
|
-
...pageSize === void 0 ? {} : { pageSize },
|
|
4303
|
-
query: String(raw.query ?? "")
|
|
4304
|
-
})
|
|
4305
|
-
});
|
|
4306
|
-
});
|
|
4307
|
-
}
|
|
4308
4301
|
function registerCoreCommands(context, program) {
|
|
4309
4302
|
withCommon(program.command("login").description("Authorize via browser and save credentials"), false).option("--client-id <id>", "OAuth App client_id").action(async (raw) => {
|
|
4310
4303
|
const host = await hostFor(context, raw);
|
|
@@ -4344,12 +4337,6 @@ function registerCoreCommands(context, program) {
|
|
|
4344
4337
|
await (await hostFor(context, raw)).client.deleteNotebook(notebookId);
|
|
4345
4338
|
context.io.stdout("deleted\n");
|
|
4346
4339
|
});
|
|
4347
|
-
const cards = program.command("cards").description("Manage notebook cards");
|
|
4348
|
-
for (const action of ["list", "search"]) {
|
|
4349
|
-
const description = action === "search" ? "Search notebook cards" : "List notebook cards";
|
|
4350
|
-
registerCardQueryCommand(context, cards.command(action).description(description));
|
|
4351
|
-
registerCardQueryCommand(context, program.command(action).description(`${description} (alias for cards ${action})`));
|
|
4352
|
-
}
|
|
4353
4340
|
withCommon(program.command("retrieve [query]").description("Retrieve notebook context without an LLM call")).option("--nb <id>", "notebook ID (required)").option("-q, --query <query>", "retrieval query").option("--sources <ids>", "comma-separated source IDs", "").option("--top-k <number>", "top-k for retrieval", integer, 0).option("--max-results <number>", "maximum context results", integer, 0).action(async (query, raw) => {
|
|
4354
4341
|
render(context, raw, {
|
|
4355
4342
|
kind: "retrieve",
|
|
@@ -4626,13 +4613,18 @@ function registerSyncCommand(context, program) {
|
|
|
4626
4613
|
if (result.exitCode === 1) context.exitCode = 1;
|
|
4627
4614
|
});
|
|
4628
4615
|
}
|
|
4629
|
-
function registerUpdateCommand(program) {
|
|
4630
|
-
program.command("self-update").description("
|
|
4616
|
+
function registerUpdateCommand(context, program) {
|
|
4617
|
+
program.command("update").alias("self-update").description("Update a Native CLI or show the npm upgrade path").option("--url <url>", "legacy update URL (ignored)").addOption(new Option("--channel <channel>", "legacy release channel (ignored)").choices([
|
|
4631
4618
|
"stable",
|
|
4632
4619
|
"beta",
|
|
4633
4620
|
"daily"
|
|
4634
|
-
]).default("stable")).option("--public-key <key>", "legacy public key (ignored)").option("--check", "legacy check mode (ignored)").option("--force", "legacy reinstall mode (ignored)").option("--allow-downgrade", "legacy downgrade mode (ignored)").action(() => {
|
|
4635
|
-
|
|
4621
|
+
]).default("stable")).option("--public-key <key>", "legacy public key (ignored)").option("--check", "legacy check mode (ignored)").option("--force", "legacy reinstall mode (ignored)").option("--allow-downgrade", "legacy downgrade mode (ignored)").action(async (raw) => {
|
|
4622
|
+
const result = await context.updater.run({ check: raw.check === true });
|
|
4623
|
+
if (result.status === "unsupported") throw new QMindError("UNSUPPORTED_OPERATION", `self-update is unavailable for npm installs; run ${result.command}`);
|
|
4624
|
+
if (result.status === "up-to-date") context.io.stdout(`${distribution.command} ${result.currentVersion} is up to date\n`);
|
|
4625
|
+
else if (result.status === "available") context.io.stdout(`${distribution.command} ${result.latestVersion} is available (current ${result.currentVersion})\n`);
|
|
4626
|
+
else if (result.status === "scheduled") context.io.stdout(`${distribution.command} update to ${result.latestVersion} is scheduled; details: ${result.logPath}\n`);
|
|
4627
|
+
else context.io.stdout(`updated ${distribution.command} from ${result.currentVersion} to ${result.latestVersion}\n`);
|
|
4636
4628
|
});
|
|
4637
4629
|
}
|
|
4638
4630
|
/** Internal parser adapter. Product consumers should call runQMindCli(). */
|
|
@@ -4649,7 +4641,7 @@ function createQMindCliProgram(context) {
|
|
|
4649
4641
|
registerSceneCommands(context, program);
|
|
4650
4642
|
registerTaskCommands(context, program);
|
|
4651
4643
|
registerSyncCommand(context, program);
|
|
4652
|
-
registerUpdateCommand(program);
|
|
4644
|
+
registerUpdateCommand(context, program);
|
|
4653
4645
|
return program;
|
|
4654
4646
|
}
|
|
4655
4647
|
async function runQMindCli(argv, options = {}) {
|
|
@@ -4660,12 +4652,21 @@ async function runQMindCli(argv, options = {}) {
|
|
|
4660
4652
|
host: void 0,
|
|
4661
4653
|
hostFactory: options.hostFactory ?? createQMindCliHost,
|
|
4662
4654
|
hostOptions: options.hostOptions ?? {},
|
|
4663
|
-
io
|
|
4655
|
+
io,
|
|
4656
|
+
updater: options.updater ?? createQMindCliUpdater({ identity: {
|
|
4657
|
+
artifactKind: "npm",
|
|
4658
|
+
command: distribution.command,
|
|
4659
|
+
currentVersion: "3.1.1",
|
|
4660
|
+
distribution: distribution.id,
|
|
4661
|
+
executablePath: process.execPath,
|
|
4662
|
+
package: distribution.package,
|
|
4663
|
+
platform: process.platform,
|
|
4664
|
+
publicRoot: distribution.nativePublicRoot
|
|
4665
|
+
} })
|
|
4664
4666
|
};
|
|
4665
4667
|
const normalized = normalizeLegacyArgv(argv);
|
|
4666
4668
|
const requiresLegacyAction = normalized.length === 0 || normalized.length === 1 && (/* @__PURE__ */ new Set([
|
|
4667
4669
|
"notebook",
|
|
4668
|
-
"cards",
|
|
4669
4670
|
"source",
|
|
4670
4671
|
"image"
|
|
4671
4672
|
])).has(normalized[0] ?? "");
|