@qoder-ai/qmind-cli 4.1.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,240 +1,4 @@
1
1
  import { z } from "zod";
2
- //#region ../sdk/src/errors.ts
3
- var QMindError = class extends Error {
4
- access;
5
- code;
6
- details;
7
- operation;
8
- rawBody;
9
- requestId;
10
- status;
11
- upstreamCode;
12
- constructor(code, message, options = {}) {
13
- super(message, { cause: options.cause });
14
- this.name = "QMindError";
15
- this.access = options.access;
16
- this.code = code;
17
- this.details = options.details;
18
- this.operation = options.operation;
19
- this.rawBody = options.rawBody;
20
- this.requestId = options.requestId;
21
- this.status = options.status;
22
- this.upstreamCode = options.upstreamCode;
23
- }
24
- };
25
- //#endregion
26
- //#region ../sdk/src/execution.ts
27
- const credentialHeaders = /* @__PURE__ */ new Set([
28
- "authorization",
29
- "cookie",
30
- "proxy-authorization",
31
- "x-csrf-token",
32
- "x-xsrf-token"
33
- ]);
34
- function isRecord$1(value) {
35
- return typeof value === "object" && value !== null && !Array.isArray(value);
36
- }
37
- function nestedRecord(value, key) {
38
- const nested = value[key];
39
- return isRecord$1(nested) ? nested : void 0;
40
- }
41
- function firstString(records, keys) {
42
- for (const record of records) {
43
- if (record === void 0) continue;
44
- for (const key of keys) {
45
- const value = record[key];
46
- if (typeof value === "string" && value.length > 0) return value;
47
- }
48
- }
49
- }
50
- function headerValue(headers, name) {
51
- const normalizedName = name.toLowerCase();
52
- for (const [key, value] of Object.entries(headers)) if (key.toLowerCase() === normalizedName && value.length > 0) return value;
53
- }
54
- function errorCodeForStatus(status) {
55
- if (status === 401) return "AUTH_REQUIRED";
56
- if (status === 403) return "FORBIDDEN";
57
- if (status === 404) return "NOT_FOUND";
58
- if (status === 409) return "CONFLICT";
59
- if (status === 429) return "RATE_LIMITED";
60
- if (status >= 400 && status < 500) return "INVALID_ARGUMENT";
61
- return "REMOTE_ERROR";
62
- }
63
- function httpError(access, operation, profile, response) {
64
- const body = profile.unwrapError(response.body);
65
- const root = isRecord$1(body) ? body : void 0;
66
- const records = [
67
- root,
68
- root === void 0 ? void 0 : nestedRecord(root, "error"),
69
- root === void 0 ? void 0 : nestedRecord(root, "details")
70
- ];
71
- const upstreamCode = firstString(records, [
72
- "errorCode",
73
- "error_code",
74
- "code"
75
- ]);
76
- const requestId = firstString(records, ["requestId", "request_id"]) ?? headerValue(response.headers, "x-request-id") ?? headerValue(response.headers, "request-id");
77
- const message = firstString(records, [
78
- "message",
79
- "errorMessage",
80
- "error_message"
81
- ]) ?? `QMind request failed with HTTP ${response.status}`;
82
- return new QMindError(errorCodeForStatus(response.status), message, {
83
- access,
84
- details: body,
85
- operation,
86
- ...response.rawBody === void 0 ? {} : { rawBody: response.rawBody },
87
- ...requestId === void 0 ? {} : { requestId },
88
- status: response.status,
89
- ...upstreamCode === void 0 ? {} : { upstreamCode }
90
- });
91
- }
92
- function isAbortLike(cause) {
93
- return isRecord$1(cause) && (cause.name === "AbortError" && typeof cause.name === "string" || cause.code === "ABORT_ERR");
94
- }
95
- function transportError(access, operation, request, cause) {
96
- if (cause instanceof QMindError) return cause;
97
- const aborted = request.signal?.aborted === true || isAbortLike(cause);
98
- return new QMindError(aborted ? "ABORTED" : "NETWORK_ERROR", aborted ? "QMind request was aborted" : "QMind transport failed", {
99
- access,
100
- cause,
101
- operation
102
- });
103
- }
104
- function requestWasAborted(request) {
105
- return request.signal?.aborted === true;
106
- }
107
- function assertWireRequestInvariant(request) {
108
- for (const [field, value] of [
109
- ["connectTimeoutMs", request.connectTimeoutMs],
110
- ["idleTimeoutMs", request.idleTimeoutMs],
111
- ["timeoutMs", request.timeoutMs]
112
- ]) if (!Number.isFinite(value ?? 1) || (value ?? 1) <= 0) throw new QMindError("INVALID_ARGUMENT", `${field} must be a positive finite number`, { details: { field } });
113
- if (request.destination.kind === "host") {
114
- if (!request.destination.path.startsWith("/") || request.destination.path.startsWith("//")) throw new QMindError("HOST_POLICY_ERROR", "host destination must be a root-relative path", { details: { destination: request.destination.kind } });
115
- return;
116
- }
117
- let url;
118
- try {
119
- url = new URL(request.destination.url);
120
- } catch (cause) {
121
- throw new QMindError("HOST_POLICY_ERROR", "signed destination must be a valid HTTPS URL", {
122
- cause,
123
- details: { destination: request.destination.kind }
124
- });
125
- }
126
- if (url.protocol !== "https:" || url.username.length > 0 || url.password.length > 0) throw new QMindError("HOST_POLICY_ERROR", "signed destination must be credential-free HTTPS", { details: { destination: request.destination.kind } });
127
- for (const header of Object.keys(request.headers ?? {})) if (credentialHeaders.has(header.toLowerCase())) throw new QMindError("HOST_POLICY_ERROR", "host credentials must never be sent to a signed destination", { details: {
128
- destination: request.destination.kind,
129
- header: header.toLowerCase()
130
- } });
131
- }
132
- function assertCapability(profile, capability, operation) {
133
- if (profile.capabilities[capability]) return;
134
- throw new QMindError("UNSUPPORTED_OPERATION", `${operation} is not supported by the ${profile.access} access profile`, {
135
- access: profile.access,
136
- details: { capability },
137
- operation
138
- });
139
- }
140
- async function executeUnary(options) {
141
- const { capability, operation, profile, request, schema, transport } = options;
142
- assertCapability(profile, capability, operation);
143
- assertWireRequestInvariant(request);
144
- if (requestWasAborted(request)) throw new QMindError("ABORTED", "QMind request was aborted", {
145
- access: profile.access,
146
- operation
147
- });
148
- let response;
149
- try {
150
- response = await transport.request(request);
151
- } catch (cause) {
152
- throw transportError(profile.access, operation, request, cause);
153
- }
154
- if (response.status < 200 || response.status >= 300) throw httpError(profile.access, operation, profile, response);
155
- const body = profile.unwrapSuccess(operation, response.body);
156
- const parsed = schema.safeParse(body);
157
- if (!parsed.success) throw new QMindError("PROTOCOL_ERROR", "server response does not match the QMind contract", {
158
- access: profile.access,
159
- details: { issues: parsed.error.issues },
160
- operation,
161
- ...response.rawBody === void 0 ? {} : { rawBody: response.rawBody },
162
- status: response.status
163
- });
164
- return parsed.data;
165
- }
166
- function streamContractError(profile, operation, message, details) {
167
- return new QMindError("STREAM_ERROR", message, {
168
- access: profile.access,
169
- ...details === void 0 ? {} : { details },
170
- operation
171
- });
172
- }
173
- function streamFailureResponse(response) {
174
- return {
175
- body: response.body,
176
- headers: response.headers,
177
- ...response.rawBody === void 0 ? {} : { rawBody: response.rawBody },
178
- status: response.status
179
- };
180
- }
181
- async function* executeStream(options) {
182
- const { capability, operation, profile, request, transport } = options;
183
- assertCapability(profile, capability, operation);
184
- assertWireRequestInvariant(request);
185
- if (requestWasAborted(request)) throw new QMindError("ABORTED", "QMind request was aborted", {
186
- access: profile.access,
187
- operation
188
- });
189
- let response;
190
- try {
191
- response = await transport.stream(request);
192
- } catch (cause) {
193
- throw transportError(profile.access, operation, request, cause);
194
- }
195
- if (response.kind === "response") {
196
- if (response.status >= 200 && response.status < 300) throw streamContractError(profile, operation, "stream handshake returned no event stream", { status: response.status });
197
- throw httpError(profile.access, operation, profile, streamFailureResponse(response));
198
- }
199
- if (response.status < 200 || response.status >= 300) throw streamContractError(profile, operation, "stream handshake returned events for a failure status", { status: response.status });
200
- let doneMarkerSeen = false;
201
- let started = false;
202
- let terminal = false;
203
- try {
204
- for await (const payload of response.events) {
205
- if (requestWasAborted(request)) throw new QMindError("ABORTED", "QMind request was aborted", {
206
- access: profile.access,
207
- operation
208
- });
209
- if (payload.trim() === "[DONE]") {
210
- if (doneMarkerSeen) throw streamContractError(profile, operation, "stream emitted more than one [DONE] marker");
211
- doneMarkerSeen = true;
212
- continue;
213
- }
214
- if (doneMarkerSeen) throw streamContractError(profile, operation, "stream emitted an event after [DONE]");
215
- if (terminal) throw streamContractError(profile, operation, "stream emitted an event after messageComplete");
216
- const event = profile.decodeStreamPayload(payload);
217
- if (event.type === "error") throw streamContractError(profile, operation, event.message, { event });
218
- if (event.type === "messageStart") {
219
- if (started) throw streamContractError(profile, operation, "stream emitted duplicate messageStart");
220
- started = true;
221
- } else if (!started) throw streamContractError(profile, operation, "stream event arrived before messageStart", { eventType: event.type });
222
- if (event.type === "messageComplete") terminal = true;
223
- yield event;
224
- }
225
- } catch (cause) {
226
- throw transportError(profile.access, operation, request, cause);
227
- }
228
- if (requestWasAborted(request)) throw new QMindError("ABORTED", "QMind request was aborted", {
229
- access: profile.access,
230
- operation
231
- });
232
- if (!terminal) throw streamContractError(profile, operation, "stream ended before messageComplete", {
233
- doneMarkerSeen,
234
- started
235
- });
236
- }
237
- //#endregion
238
2
  //#region ../sdk/src/imports.ts
239
3
  const qmindFullSiteURLImportPageLimit = 2e3;
240
4
  const runStatuses = Object.freeze({
@@ -298,10 +62,6 @@ function normalizeQMindAliDingImportNodeKind(value) {
298
62
  function normalizeQMindAliDingImportScope(value) {
299
63
  return scopes[value] ?? "nodeSubtree";
300
64
  }
301
- //#endregion
302
- //#region ../sdk/src/workflows.ts
303
- const QMIND_MULTIPART_UPLOAD_MAX_BYTES = 52428800;
304
- const QMIND_SOURCE_UPLOAD_MAX_BYTES = 524288e3;
305
65
  Object.freeze({
306
66
  canceled: {
307
67
  order: 2,
@@ -457,7 +217,20 @@ const sourceExternalBindingSchema = z.preprocess((value) => isRecord(value) ? {
457
217
  isRoot: z.boolean().default(false),
458
218
  provider: z.string().default("")
459
219
  }));
220
+ const sourceLearningSchema = z.object({
221
+ status: z.string().default("unknown"),
222
+ errorCode: z.string().default(""),
223
+ engine: z.string().default(""),
224
+ phase: z.string().default("unknown"),
225
+ currentRevision: z.union([z.string(), z.number().int()]).transform(String).default("0"),
226
+ completedRevision: z.union([z.string(), z.number().int()]).transform(String).default("0"),
227
+ observedAt: timestampSchema.optional(),
228
+ nextObserveAt: timestampSchema.optional(),
229
+ engineObservedAt: timestampSchema.optional(),
230
+ retryMode: z.string().default("none")
231
+ });
460
232
  const sourceSchema = z.object({
233
+ learning: sourceLearningSchema.optional(),
461
234
  learningStatus: z.string().optional(),
462
235
  learningErrorCode: z.string().optional(),
463
236
  childrenCount: z.number().int().nonnegative().optional(),
@@ -496,6 +269,7 @@ const sourceTreeNodeSchema = z.lazy(() => z.preprocess((value) => isRecord(value
496
269
  ...value,
497
270
  updatedAt: value.updatedAt ?? value.updated_at
498
271
  } : value, z.object({
272
+ learning: sourceLearningSchema.optional(),
499
273
  learningStatus: z.string().optional(),
500
274
  learningErrorCode: z.string().optional(),
501
275
  metadata: z.record(z.string(), z.unknown()).nullable().optional(),
@@ -994,132 +768,4 @@ const retrieveNotebooksResultSchema = z.object({
994
768
  total: z.number().int().nonnegative().default(0)
995
769
  });
996
770
  //#endregion
997
- //#region ../sdk/src/operations/shared.ts
998
- function invalidArgument(message, field, details) {
999
- return new QMindError("INVALID_ARGUMENT", message, { details: details ?? { field } });
1000
- }
1001
- function requiredString(value, field) {
1002
- if (typeof value !== "string" || value.trim().length === 0) throw invalidArgument(`${field} must be a non-empty string`, field);
1003
- return value.trim();
1004
- }
1005
- function optionalString(value, field) {
1006
- if (value === void 0) return void 0;
1007
- if (typeof value !== "string") throw invalidArgument(`${field} must be a string`, field);
1008
- return value;
1009
- }
1010
- /** Validate body text without trimming meaningful Markdown indentation or trailing newlines. */
1011
- function requiredText(value, field) {
1012
- const text = optionalString(value, field);
1013
- if (text === void 0 || text.trim().length === 0) throw invalidArgument(`${field} must be a non-empty string`, field);
1014
- return text;
1015
- }
1016
- function optionalTrimmedString(value, field) {
1017
- const string = optionalString(value, field)?.trim();
1018
- return string === "" ? void 0 : string;
1019
- }
1020
- function optionalRecord(value, field) {
1021
- if (value === void 0) return void 0;
1022
- if (typeof value !== "object" || value === null || Array.isArray(value)) throw invalidArgument(`${field} must be an object`, field);
1023
- return value;
1024
- }
1025
- function optionalBoolean(value, field) {
1026
- if (value === void 0) return void 0;
1027
- if (typeof value !== "boolean") throw invalidArgument(`${field} must be a boolean`, field);
1028
- return value;
1029
- }
1030
- function positiveInteger(value, field) {
1031
- if (value === void 0) return void 0;
1032
- if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) throw invalidArgument(`${field} must be a positive integer`, field);
1033
- return value;
1034
- }
1035
- function nonNegativeInteger(value, field) {
1036
- if (value === void 0) return void 0;
1037
- if (typeof value !== "number" || !Number.isInteger(value) || value < 0) throw invalidArgument(`${field} must be a non-negative integer`, field);
1038
- return value;
1039
- }
1040
- function pagination(input) {
1041
- const page = positiveInteger(input.page, "page");
1042
- const pageSize = positiveInteger(input.pageSize, "pageSize");
1043
- return {
1044
- ...page === void 0 ? {} : { page },
1045
- ...pageSize === void 0 ? {} : { pageSize }
1046
- };
1047
- }
1048
- function stringList(value, field, options = {}) {
1049
- if (!Array.isArray(value)) throw invalidArgument(`${field} must be an array`, field);
1050
- const result = [];
1051
- const seen = /* @__PURE__ */ new Set();
1052
- for (const item of value) {
1053
- if (typeof item !== "string") throw invalidArgument(`${field} must contain only strings`, field);
1054
- const normalized = item.trim();
1055
- if (normalized.length === 0 || seen.has(normalized)) continue;
1056
- seen.add(normalized);
1057
- result.push(normalized);
1058
- }
1059
- if (options.min !== void 0 && result.length < options.min) throw invalidArgument(`${field} must contain at least ${options.min} item(s)`, field);
1060
- if (options.max !== void 0 && result.length > options.max) throw invalidArgument(`${field} must contain at most ${options.max} item(s)`, field);
1061
- return result;
1062
- }
1063
- function httpUrl(value, field) {
1064
- const raw = requiredString(value, field);
1065
- let url;
1066
- try {
1067
- url = new URL(raw);
1068
- } catch (cause) {
1069
- throw invalidArgument(`${field} must be a valid HTTP(S) URL`, field, {
1070
- cause,
1071
- field
1072
- });
1073
- }
1074
- if (url.protocol !== "http:" && url.protocol !== "https:" || url.host.length === 0) throw invalidArgument(`${field} must be a valid HTTP(S) URL`, field);
1075
- url.hash = "";
1076
- return url.toString();
1077
- }
1078
- function compactUndefined(value) {
1079
- return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== void 0));
1080
- }
1081
- function assertNonEmptyPatch(patch, field) {
1082
- if (Object.keys(patch).length > 0) return;
1083
- throw invalidArgument(`${field} must contain at least one change`, field);
1084
- }
1085
- function queryPath(path, entries) {
1086
- const query = new URLSearchParams();
1087
- for (const [key, value] of entries) if (value !== void 0 && value !== "") query.set(key, String(value));
1088
- const suffix = query.toString();
1089
- return suffix.length === 0 ? path : `${path}?${suffix}`;
1090
- }
1091
- function wireRequest(options) {
1092
- const timeoutMs = options.callOptions?.timeoutMs;
1093
- if (timeoutMs !== void 0 && (!Number.isFinite(timeoutMs) || timeoutMs <= 0)) throw invalidArgument("timeoutMs must be a positive finite number", "timeoutMs");
1094
- const maxResponseBytes = options.callOptions?.maxResponseBytes;
1095
- if (maxResponseBytes !== void 0 && (!Number.isSafeInteger(maxResponseBytes) || maxResponseBytes <= 0)) throw invalidArgument("maxResponseBytes must be a positive integer", "maxResponseBytes");
1096
- const authorization = options.callOptions?.authorization?.trim();
1097
- return {
1098
- ...options.body === void 0 ? {} : { body: {
1099
- kind: "json",
1100
- value: options.body
1101
- } },
1102
- destination: {
1103
- kind: "host",
1104
- path: options.path
1105
- },
1106
- ...authorization === void 0 || authorization.length === 0 ? {} : { headers: { authorization: `Bearer ${authorization}` } },
1107
- idempotent: options.idempotent,
1108
- method: options.method,
1109
- ...options.callOptions?.signal === void 0 ? {} : { signal: options.callOptions.signal },
1110
- ...timeoutMs === void 0 ? {} : { timeoutMs },
1111
- ...maxResponseBytes === void 0 ? {} : { maxResponseBytes }
1112
- };
1113
- }
1114
- function call(context, options) {
1115
- return executeUnary({
1116
- capability: options.capability,
1117
- operation: options.operation,
1118
- profile: context.profile,
1119
- request: wireRequest(options),
1120
- schema: options.schema,
1121
- transport: context.transport
1122
- });
1123
- }
1124
- //#endregion
1125
- export { QMIND_MULTIPART_UPLOAD_MAX_BYTES as $, notebookSchema as A, sourceQuotaSchema as B, chatSessionSchema as C, imageUrlsSchema as D, imageUploadTicketSchema as E, sourceChildrenCountsSchema as F, sourceUploadTicketSchema as G, sourceSchema as H, sourceContentSchema as I, streamWireEventSchema as J, sourceWebOfficeSessionSchema as K, sourceImportResultsSchema as L, retrieveResultSchema as M, sharedNotebookListSchema as N, importProvidersSchema as O, sourceActionAccessSchema as P, voidResponseSchema as Q, sourceListSchema as R, chatSessionListSchema as S, fullSiteURLImportDiscoverySchema as T, sourceTreeSchema as U, sourceRawContentSchema as V, sourceUploadCapabilitiesSchema as W, taskRunSchema as X, taskRunListSchema as Y, timestampSchema as Z, aliDingImportRunItemListSchema as _, invalidArgument as a, QMindError as at, cancelQuestionResultSchema as b, optionalRecord as c, pagination as d, QMIND_SOURCE_UPLOAD_MAX_BYTES as et, positiveInteger as f, stringList as g, requiredText as h, httpUrl as i, executeUnary as it, retrieveNotebooksResultSchema as j, notebookListSchema as k, optionalString as l, requiredString as m, call as n, assertCapability as nt, nonNegativeInteger as o, queryPath as p, sourceWebOfficeTokenSchema as q, compactUndefined as r, executeStream as rt, optionalBoolean as s, assertNonEmptyPatch as t, qmindFullSiteURLImportPageLimit as tt, optionalTrimmedString as u, aliDingImportRunSchema as v, fullSiteURLImportConfirmationSchema as w, chatMessageListSchema as x, batchDeleteResultSchema as y, sourcePreviewSchema as z };
771
+ export { sourceWebOfficeSessionSchema as A, sourcePreviewSchema as C, sourceTreeSchema as D, sourceSchema as E, timestampSchema as F, voidResponseSchema as I, qmindFullSiteURLImportPageLimit as L, streamWireEventSchema as M, taskRunListSchema as N, sourceUploadCapabilitiesSchema as O, taskRunSchema as P, sourceListSchema as S, sourceRawContentSchema as T, sharedNotebookListSchema as _, chatMessageListSchema as a, sourceContentSchema as b, fullSiteURLImportConfirmationSchema as c, imageUrlsSchema as d, importProvidersSchema as f, retrieveResultSchema as g, retrieveNotebooksResultSchema as h, cancelQuestionResultSchema as i, sourceWebOfficeTokenSchema as j, sourceUploadTicketSchema as k, fullSiteURLImportDiscoverySchema as l, notebookSchema as m, aliDingImportRunSchema as n, chatSessionListSchema as o, notebookListSchema as p, batchDeleteResultSchema as r, chatSessionSchema as s, aliDingImportRunItemListSchema as t, imageUploadTicketSchema as u, sourceActionAccessSchema as v, sourceQuotaSchema as w, sourceImportResultsSchema as x, sourceChildrenCountsSchema as y };