@qoder-ai/qmind-cli 4.2.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.
@@ -0,0 +1,386 @@
1
+ //#region ../sdk/src/errors.ts
2
+ var QMindError = class extends Error {
3
+ access;
4
+ code;
5
+ details;
6
+ operation;
7
+ rawBody;
8
+ requestId;
9
+ status;
10
+ upstreamCode;
11
+ constructor(code, message, options = {}) {
12
+ super(message, { cause: options.cause });
13
+ this.name = "QMindError";
14
+ this.access = options.access;
15
+ this.code = code;
16
+ this.details = options.details;
17
+ this.operation = options.operation;
18
+ this.rawBody = options.rawBody;
19
+ this.requestId = options.requestId;
20
+ this.status = options.status;
21
+ this.upstreamCode = options.upstreamCode;
22
+ }
23
+ };
24
+ //#endregion
25
+ //#region ../sdk/src/wiki.ts
26
+ /** 保留 HTTP 错误证据,并以有界状态供宿主选择本地化提示。 */
27
+ var QMindWikiReadError = class extends QMindError {
28
+ wikiState;
29
+ constructor(wikiState, error) {
30
+ super(error.code, error.message, {
31
+ cause: error,
32
+ ...error.access === void 0 ? {} : { access: error.access },
33
+ ...error.operation === void 0 ? {} : { operation: error.operation },
34
+ ...error.status === void 0 ? {} : { status: error.status },
35
+ ...error.upstreamCode === void 0 ? {} : { upstreamCode: error.upstreamCode },
36
+ ...error.requestId === void 0 ? {} : { requestId: error.requestId },
37
+ details: error.details
38
+ });
39
+ this.wikiState = wikiState;
40
+ }
41
+ };
42
+ //#endregion
43
+ //#region ../sdk/src/execution.ts
44
+ const credentialHeaders = /* @__PURE__ */ new Set([
45
+ "authorization",
46
+ "cookie",
47
+ "proxy-authorization",
48
+ "x-csrf-token",
49
+ "x-xsrf-token"
50
+ ]);
51
+ function isRecord(value) {
52
+ return typeof value === "object" && value !== null && !Array.isArray(value);
53
+ }
54
+ function nestedRecord(value, key) {
55
+ const nested = value[key];
56
+ return isRecord(nested) ? nested : void 0;
57
+ }
58
+ function firstString(records, keys) {
59
+ for (const record of records) {
60
+ if (record === void 0) continue;
61
+ for (const key of keys) {
62
+ const value = record[key];
63
+ if (typeof value === "string" && value.length > 0) return value;
64
+ }
65
+ }
66
+ }
67
+ function headerValue(headers, name) {
68
+ const normalizedName = name.toLowerCase();
69
+ for (const [key, value] of Object.entries(headers)) if (key.toLowerCase() === normalizedName && value.length > 0) return value;
70
+ }
71
+ function errorCodeForStatus(status) {
72
+ if (status === 401) return "AUTH_REQUIRED";
73
+ if (status === 403) return "FORBIDDEN";
74
+ if (status === 404) return "NOT_FOUND";
75
+ if (status === 409) return "CONFLICT";
76
+ if (status === 429) return "RATE_LIMITED";
77
+ if (status >= 400 && status < 500) return "INVALID_ARGUMENT";
78
+ return "REMOTE_ERROR";
79
+ }
80
+ function httpError(access, operation, profile, response) {
81
+ const body = profile.unwrapError(response.body);
82
+ const root = isRecord(body) ? body : void 0;
83
+ const records = [
84
+ root,
85
+ root === void 0 ? void 0 : nestedRecord(root, "error"),
86
+ root === void 0 ? void 0 : nestedRecord(root, "details")
87
+ ];
88
+ const upstreamCode = firstString(records, [
89
+ "errorCode",
90
+ "error_code",
91
+ "code"
92
+ ]);
93
+ const requestId = firstString(records, ["requestId", "request_id"]) ?? headerValue(response.headers, "x-request-id") ?? headerValue(response.headers, "request-id");
94
+ const message = firstString(records, [
95
+ "message",
96
+ "errorMessage",
97
+ "error_message"
98
+ ]) ?? `QMind request failed with HTTP ${response.status}`;
99
+ const failure = new QMindError(errorCodeForStatus(response.status), message, {
100
+ access,
101
+ details: body,
102
+ operation,
103
+ ...response.rawBody === void 0 ? {} : { rawBody: response.rawBody },
104
+ ...requestId === void 0 ? {} : { requestId },
105
+ status: response.status,
106
+ ...upstreamCode === void 0 ? {} : { upstreamCode }
107
+ });
108
+ const state = headerValue(response.headers, "x-wiki-state");
109
+ if (operation.startsWith("wiki.") && (state === "expired" || state === "busy" || state === "invalid" || state === "limit" || state === "missing")) return new QMindWikiReadError(state, failure);
110
+ return failure;
111
+ }
112
+ function isAbortLike(cause) {
113
+ return isRecord(cause) && (cause.name === "AbortError" && typeof cause.name === "string" || cause.code === "ABORT_ERR");
114
+ }
115
+ function transportError(access, operation, request, cause) {
116
+ if (cause instanceof QMindError) return cause;
117
+ const aborted = request.signal?.aborted === true || isAbortLike(cause);
118
+ return new QMindError(aborted ? "ABORTED" : "NETWORK_ERROR", aborted ? "QMind request was aborted" : "QMind transport failed", {
119
+ access,
120
+ cause,
121
+ operation
122
+ });
123
+ }
124
+ function requestWasAborted(request) {
125
+ return request.signal?.aborted === true;
126
+ }
127
+ function assertWireRequestInvariant(request) {
128
+ for (const [field, value] of [
129
+ ["connectTimeoutMs", request.connectTimeoutMs],
130
+ ["idleTimeoutMs", request.idleTimeoutMs],
131
+ ["timeoutMs", request.timeoutMs]
132
+ ]) if (!Number.isFinite(value ?? 1) || (value ?? 1) <= 0) throw new QMindError("INVALID_ARGUMENT", `${field} must be a positive finite number`, { details: { field } });
133
+ if (request.destination.kind === "host") {
134
+ 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 } });
135
+ return;
136
+ }
137
+ let url;
138
+ try {
139
+ url = new URL(request.destination.url);
140
+ } catch (cause) {
141
+ throw new QMindError("HOST_POLICY_ERROR", "signed destination must be a valid HTTPS URL", {
142
+ cause,
143
+ details: { destination: request.destination.kind }
144
+ });
145
+ }
146
+ 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 } });
147
+ 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: {
148
+ destination: request.destination.kind,
149
+ header: header.toLowerCase()
150
+ } });
151
+ }
152
+ function assertCapability(profile, capability, operation) {
153
+ if (profile.capabilities[capability]) return;
154
+ throw new QMindError("UNSUPPORTED_OPERATION", `${operation} is not supported by the ${profile.access} access profile`, {
155
+ access: profile.access,
156
+ details: { capability },
157
+ operation
158
+ });
159
+ }
160
+ async function executeUnary(options) {
161
+ const { capability, operation, profile, request, schema, transport } = options;
162
+ assertCapability(profile, capability, operation);
163
+ assertWireRequestInvariant(request);
164
+ if (requestWasAborted(request)) throw new QMindError("ABORTED", "QMind request was aborted", {
165
+ access: profile.access,
166
+ operation
167
+ });
168
+ let response;
169
+ try {
170
+ response = await transport.request(request);
171
+ } catch (cause) {
172
+ throw transportError(profile.access, operation, request, cause);
173
+ }
174
+ if (response.status < 200 || response.status >= 300) throw httpError(profile.access, operation, profile, response);
175
+ const body = profile.unwrapSuccess(operation, response.body);
176
+ const parsed = schema.safeParse(body);
177
+ if (!parsed.success) throw new QMindError("PROTOCOL_ERROR", "server response does not match the QMind contract", {
178
+ access: profile.access,
179
+ details: { issues: parsed.error.issues },
180
+ operation,
181
+ ...response.rawBody === void 0 ? {} : { rawBody: response.rawBody },
182
+ status: response.status
183
+ });
184
+ return parsed.data;
185
+ }
186
+ function streamContractError(profile, operation, message, details) {
187
+ return new QMindError("STREAM_ERROR", message, {
188
+ access: profile.access,
189
+ ...details === void 0 ? {} : { details },
190
+ operation
191
+ });
192
+ }
193
+ function streamFailureResponse(response) {
194
+ return {
195
+ body: response.body,
196
+ headers: response.headers,
197
+ ...response.rawBody === void 0 ? {} : { rawBody: response.rawBody },
198
+ status: response.status
199
+ };
200
+ }
201
+ async function* executeStream(options) {
202
+ const { capability, operation, profile, request, transport } = options;
203
+ assertCapability(profile, capability, operation);
204
+ assertWireRequestInvariant(request);
205
+ if (requestWasAborted(request)) throw new QMindError("ABORTED", "QMind request was aborted", {
206
+ access: profile.access,
207
+ operation
208
+ });
209
+ let response;
210
+ try {
211
+ response = await transport.stream(request);
212
+ } catch (cause) {
213
+ throw transportError(profile.access, operation, request, cause);
214
+ }
215
+ if (response.kind === "response") {
216
+ if (response.status >= 200 && response.status < 300) throw streamContractError(profile, operation, "stream handshake returned no event stream", { status: response.status });
217
+ throw httpError(profile.access, operation, profile, streamFailureResponse(response));
218
+ }
219
+ if (response.status < 200 || response.status >= 300) throw streamContractError(profile, operation, "stream handshake returned events for a failure status", { status: response.status });
220
+ let doneMarkerSeen = false;
221
+ let started = false;
222
+ let terminal = false;
223
+ try {
224
+ for await (const payload of response.events) {
225
+ if (requestWasAborted(request)) throw new QMindError("ABORTED", "QMind request was aborted", {
226
+ access: profile.access,
227
+ operation
228
+ });
229
+ if (payload.trim() === "[DONE]") {
230
+ if (doneMarkerSeen) throw streamContractError(profile, operation, "stream emitted more than one [DONE] marker");
231
+ doneMarkerSeen = true;
232
+ continue;
233
+ }
234
+ if (doneMarkerSeen) throw streamContractError(profile, operation, "stream emitted an event after [DONE]");
235
+ if (terminal) throw streamContractError(profile, operation, "stream emitted an event after messageComplete");
236
+ const event = profile.decodeStreamPayload(payload);
237
+ if (event.type === "error") throw streamContractError(profile, operation, event.message, { event });
238
+ if (event.type === "messageStart") {
239
+ if (started) throw streamContractError(profile, operation, "stream emitted duplicate messageStart");
240
+ started = true;
241
+ } else if (!started) throw streamContractError(profile, operation, "stream event arrived before messageStart", { eventType: event.type });
242
+ if (event.type === "messageComplete") terminal = true;
243
+ yield event;
244
+ }
245
+ } catch (cause) {
246
+ throw transportError(profile.access, operation, request, cause);
247
+ }
248
+ if (requestWasAborted(request)) throw new QMindError("ABORTED", "QMind request was aborted", {
249
+ access: profile.access,
250
+ operation
251
+ });
252
+ if (!terminal) throw streamContractError(profile, operation, "stream ended before messageComplete", {
253
+ doneMarkerSeen,
254
+ started
255
+ });
256
+ }
257
+ //#endregion
258
+ //#region ../sdk/src/operations/shared.ts
259
+ function invalidArgument(message, field, details) {
260
+ return new QMindError("INVALID_ARGUMENT", message, { details: details ?? { field } });
261
+ }
262
+ function requiredString(value, field) {
263
+ if (typeof value !== "string" || value.trim().length === 0) throw invalidArgument(`${field} must be a non-empty string`, field);
264
+ return value.trim();
265
+ }
266
+ function optionalString(value, field) {
267
+ if (value === void 0) return void 0;
268
+ if (typeof value !== "string") throw invalidArgument(`${field} must be a string`, field);
269
+ return value;
270
+ }
271
+ /** Validate body text without trimming meaningful Markdown indentation or trailing newlines. */
272
+ function requiredText(value, field) {
273
+ const text = optionalString(value, field);
274
+ if (text === void 0 || text.trim().length === 0) throw invalidArgument(`${field} must be a non-empty string`, field);
275
+ return text;
276
+ }
277
+ function optionalTrimmedString(value, field) {
278
+ const string = optionalString(value, field)?.trim();
279
+ return string === "" ? void 0 : string;
280
+ }
281
+ function optionalRecord(value, field) {
282
+ if (value === void 0) return void 0;
283
+ if (typeof value !== "object" || value === null || Array.isArray(value)) throw invalidArgument(`${field} must be an object`, field);
284
+ return value;
285
+ }
286
+ function optionalBoolean(value, field) {
287
+ if (value === void 0) return void 0;
288
+ if (typeof value !== "boolean") throw invalidArgument(`${field} must be a boolean`, field);
289
+ return value;
290
+ }
291
+ function positiveInteger(value, field) {
292
+ if (value === void 0) return void 0;
293
+ if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) throw invalidArgument(`${field} must be a positive integer`, field);
294
+ return value;
295
+ }
296
+ function nonNegativeInteger(value, field) {
297
+ if (value === void 0) return void 0;
298
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0) throw invalidArgument(`${field} must be a non-negative integer`, field);
299
+ return value;
300
+ }
301
+ function pagination(input) {
302
+ const page = positiveInteger(input.page, "page");
303
+ const pageSize = positiveInteger(input.pageSize, "pageSize");
304
+ return {
305
+ ...page === void 0 ? {} : { page },
306
+ ...pageSize === void 0 ? {} : { pageSize }
307
+ };
308
+ }
309
+ function stringList(value, field, options = {}) {
310
+ if (!Array.isArray(value)) throw invalidArgument(`${field} must be an array`, field);
311
+ const result = [];
312
+ const seen = /* @__PURE__ */ new Set();
313
+ for (const item of value) {
314
+ if (typeof item !== "string") throw invalidArgument(`${field} must contain only strings`, field);
315
+ const normalized = item.trim();
316
+ if (normalized.length === 0 || seen.has(normalized)) continue;
317
+ seen.add(normalized);
318
+ result.push(normalized);
319
+ }
320
+ if (options.min !== void 0 && result.length < options.min) throw invalidArgument(`${field} must contain at least ${options.min} item(s)`, field);
321
+ if (options.max !== void 0 && result.length > options.max) throw invalidArgument(`${field} must contain at most ${options.max} item(s)`, field);
322
+ return result;
323
+ }
324
+ function httpUrl(value, field) {
325
+ const raw = requiredString(value, field);
326
+ let url;
327
+ try {
328
+ url = new URL(raw);
329
+ } catch (cause) {
330
+ throw invalidArgument(`${field} must be a valid HTTP(S) URL`, field, {
331
+ cause,
332
+ field
333
+ });
334
+ }
335
+ if (url.protocol !== "http:" && url.protocol !== "https:" || url.host.length === 0) throw invalidArgument(`${field} must be a valid HTTP(S) URL`, field);
336
+ url.hash = "";
337
+ return url.toString();
338
+ }
339
+ function compactUndefined(value) {
340
+ return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== void 0));
341
+ }
342
+ function assertNonEmptyPatch(patch, field) {
343
+ if (Object.keys(patch).length > 0) return;
344
+ throw invalidArgument(`${field} must contain at least one change`, field);
345
+ }
346
+ function queryPath(path, entries) {
347
+ const query = new URLSearchParams();
348
+ for (const [key, value] of entries) if (value !== void 0 && value !== "") query.set(key, String(value));
349
+ const suffix = query.toString();
350
+ return suffix.length === 0 ? path : `${path}?${suffix}`;
351
+ }
352
+ function wireRequest(options) {
353
+ const timeoutMs = options.callOptions?.timeoutMs;
354
+ if (timeoutMs !== void 0 && (!Number.isFinite(timeoutMs) || timeoutMs <= 0)) throw invalidArgument("timeoutMs must be a positive finite number", "timeoutMs");
355
+ const maxResponseBytes = options.callOptions?.maxResponseBytes;
356
+ if (maxResponseBytes !== void 0 && (!Number.isSafeInteger(maxResponseBytes) || maxResponseBytes <= 0)) throw invalidArgument("maxResponseBytes must be a positive integer", "maxResponseBytes");
357
+ const authorization = options.callOptions?.authorization?.trim();
358
+ return {
359
+ ...options.body === void 0 ? {} : { body: {
360
+ kind: "json",
361
+ value: options.body
362
+ } },
363
+ destination: {
364
+ kind: "host",
365
+ path: options.path
366
+ },
367
+ ...authorization === void 0 || authorization.length === 0 ? {} : { headers: { authorization: `Bearer ${authorization}` } },
368
+ idempotent: options.idempotent,
369
+ method: options.method,
370
+ ...options.callOptions?.signal === void 0 ? {} : { signal: options.callOptions.signal },
371
+ ...timeoutMs === void 0 ? {} : { timeoutMs },
372
+ ...maxResponseBytes === void 0 ? {} : { maxResponseBytes }
373
+ };
374
+ }
375
+ function call(context, options) {
376
+ return executeUnary({
377
+ capability: options.capability,
378
+ operation: options.operation,
379
+ profile: context.profile,
380
+ request: wireRequest(options),
381
+ schema: options.schema,
382
+ transport: context.transport
383
+ });
384
+ }
385
+ //#endregion
386
+ export { assertCapability as _, invalidArgument as a, QMindError as b, optionalRecord as c, pagination as d, positiveInteger as f, stringList as g, requiredText as h, httpUrl as i, optionalString as l, requiredString as m, call as n, nonNegativeInteger as o, queryPath as p, compactUndefined as r, optionalBoolean as s, assertNonEmptyPatch as t, optionalTrimmedString as u, executeStream as v, executeUnary as y };
@@ -1,4 +1,5 @@
1
- import { W as sourceUploadCapabilitiesSchema, m as requiredString, n as call } from "./shared-53S5tNf6.js";
1
+ import { O as sourceUploadCapabilitiesSchema } from "./schemas-DG7vaJMR.js";
2
+ import { m as requiredString, n as call } from "./shared-CbvrtGyv.js";
2
3
  //#region ../sdk/src/operations/source-upload.ts
3
4
  /** Notebook-scoped edit preflight, not the deployment-level capabilities lookup. */
4
5
  async function preflightSourceUpload(context, notebookId, options) {
@@ -1,5 +1,85 @@
1
- import { $ as QMIND_MULTIPART_UPLOAD_MAX_BYTES, E as imageUploadTicketSchema, G as sourceUploadTicketSchema, H as sourceSchema, Q as voidResponseSchema, a as invalidArgument, at as QMindError, et as QMIND_SOURCE_UPLOAD_MAX_BYTES, it as executeUnary, l as optionalString, m as requiredString, p as queryPath, r as compactUndefined, u as optionalTrimmedString } from "./shared-53S5tNf6.js";
2
- import { t as preflightSourceUpload } from "./source-upload-DlOLtECT.js";
1
+ import { E as sourceSchema, I as voidResponseSchema, k as sourceUploadTicketSchema, u as imageUploadTicketSchema } from "./schemas-DG7vaJMR.js";
2
+ import { a as invalidArgument, b as QMindError, l as optionalString, m as requiredString, p as queryPath, r as compactUndefined, u as optionalTrimmedString, y as executeUnary } from "./shared-CbvrtGyv.js";
3
+ import { t as preflightSourceUpload } from "./source-upload-XrNG4_4V.js";
4
+ //#region ../sdk/src/workflows.ts
5
+ const QMIND_MULTIPART_UPLOAD_MAX_BYTES = 52428800;
6
+ const QMIND_SOURCE_UPLOAD_MAX_BYTES = 157286400;
7
+ //#endregion
8
+ //#region ../sdk/src/source-upload-guidance.ts
9
+ const formats = [
10
+ {
11
+ name: "PDF",
12
+ extensions: [".pdf"],
13
+ maxSizeMB: 150
14
+ },
15
+ {
16
+ name: "Word",
17
+ extensions: [".doc", ".docx"],
18
+ maxSizeMB: 150
19
+ },
20
+ {
21
+ name: "Excel",
22
+ extensions: [".xls", ".xlsx"],
23
+ maxSizeMB: 150
24
+ },
25
+ {
26
+ name: "PPT",
27
+ extensions: [".ppt", ".pptx"],
28
+ maxSizeMB: 150
29
+ },
30
+ {
31
+ name: "Markdown",
32
+ extensions: [
33
+ ".md",
34
+ ".markdown",
35
+ ".mdown",
36
+ ".mdx"
37
+ ],
38
+ maxSizeMB: 50
39
+ },
40
+ {
41
+ name: "TXT",
42
+ extensions: [".txt"],
43
+ maxSizeMB: 50
44
+ },
45
+ {
46
+ name: "CSV",
47
+ extensions: [".csv"],
48
+ maxSizeMB: 50
49
+ },
50
+ {
51
+ name: "HTML",
52
+ extensions: [".html", ".htm"],
53
+ maxSizeMB: 50
54
+ },
55
+ {
56
+ name: "images",
57
+ extensions: [
58
+ ".png",
59
+ ".jpg",
60
+ ".jpeg",
61
+ ".gif",
62
+ ".webp",
63
+ ".bmp",
64
+ ".ico",
65
+ ".tiff",
66
+ ".tif",
67
+ ".svg"
68
+ ],
69
+ maxSizeMB: 20
70
+ },
71
+ {
72
+ name: "email",
73
+ extensions: [".eml"],
74
+ maxSizeMB: 50
75
+ }
76
+ ];
77
+ /** 按实际后缀读取上限,不能通过 MIME 或 sourceType 放宽。 */
78
+ function getQMindSourceUploadMaxBytes(filename) {
79
+ const extension = filename.slice(filename.lastIndexOf(".")).toLowerCase();
80
+ return (formats.find((item) => item.extensions.includes(extension))?.maxSizeMB ?? 50) * 1024 * 1024;
81
+ }
82
+ //#endregion
3
83
  //#region ../sdk/src/operations/transfers.ts
4
84
  function isRecord(value) {
5
85
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -146,7 +226,7 @@ function selectSourceUploadStrategy(source, capabilities) {
146
226
  details: { reason: "unsupported-extension" },
147
227
  operation: "sources.uploadPreflight"
148
228
  });
149
- const limit = (method) => Math.min(method.maxSizeBytes, method.method === "multipart" ? QMIND_MULTIPART_UPLOAD_MAX_BYTES : QMIND_SOURCE_UPLOAD_MAX_BYTES);
229
+ const limit = (method) => Math.min(method.maxSizeBytes, getQMindSourceUploadMaxBytes(source.filename), method.method === "multipart" ? QMIND_MULTIPART_UPLOAD_MAX_BYTES : QMIND_SOURCE_UPLOAD_MAX_BYTES);
150
230
  if (matching.find((method) => method.method === "multipart" && source.size <= limit(method))) return "multipart";
151
231
  if (matching.some((method) => method.method === "presign" && source.size <= limit(method))) return "presigned";
152
232
  throw new QMindError("FILE_TOO_LARGE", "file exceeds the available upload size limit", {
@@ -193,10 +273,11 @@ function createTransferOperations(context) {
193
273
  const metadata = uploadMetadata(rawMetadata);
194
274
  const options = transferOptions(rawOptions);
195
275
  const requestOptions = transferRequestOptions(options);
196
- if (source.size > 524288e3) throw new QMindError("FILE_TOO_LARGE", "file exceeds the 500 MiB upload limit", {
276
+ const limitBytes = getQMindSourceUploadMaxBytes(source.filename);
277
+ if (source.size > limitBytes) throw new QMindError("FILE_TOO_LARGE", "file exceeds the upload size limit for this format", {
197
278
  access: context.profile.access,
198
279
  details: {
199
- limitBytes: QMIND_SOURCE_UPLOAD_MAX_BYTES,
280
+ limitBytes,
200
281
  size: source.size
201
282
  },
202
283
  operation: "transfers.source.multipart"
@@ -0,0 +1,99 @@
1
+ import { a as invalidArgument, b as QMindError, m as requiredString, n as call, o as nonNegativeInteger, p as queryPath, u as optionalTrimmedString } from "./shared-CbvrtGyv.js";
2
+ import { z } from "zod";
3
+ //#region ../sdk/src/operations/wiki.ts
4
+ const partSchema = z.number().int().nonnegative();
5
+ const catalogSchema = z.object({
6
+ snapshotToken: z.string().min(1),
7
+ branch: z.string().min(1),
8
+ language: z.string().min(1),
9
+ entries: z.array(z.object({
10
+ id: z.string().min(1),
11
+ name: z.string(),
12
+ parentId: z.string(),
13
+ order: partSchema,
14
+ parts: partSchema,
15
+ anchors: z.array(z.object({
16
+ name: z.string(),
17
+ part: partSchema
18
+ })).nullable().transform((value) => value ?? [])
19
+ })).nullable().transform((value) => value ?? [])
20
+ });
21
+ const sectionSchema = z.object({
22
+ snapshotToken: z.string().min(1),
23
+ content: z.string(),
24
+ raw: z.boolean()
25
+ });
26
+ const searchSchema = z.object({
27
+ snapshotToken: z.string().min(1),
28
+ truncated: z.boolean(),
29
+ hits: z.array(z.object({
30
+ sectionId: z.string().min(1),
31
+ part: partSchema,
32
+ snippet: z.string()
33
+ })).nullable().transform((value) => value ?? [])
34
+ });
35
+ function scopeQuery(input) {
36
+ return [
37
+ ["repo", requiredString(input?.repo, "repo")],
38
+ ["branch", optionalTrimmedString(input?.branch, "branch")],
39
+ ["language", optionalTrimmedString(input?.language, "language")]
40
+ ];
41
+ }
42
+ function snapshotQuery(input) {
43
+ return [
44
+ ["repo", requiredString(input?.repo, "repo")],
45
+ ["branch", requiredString(input?.branch, "branch")],
46
+ ["language", requiredString(input?.language, "language")],
47
+ ["snapshotToken", requiredString(input?.snapshotToken, "snapshotToken")]
48
+ ];
49
+ }
50
+ function verifySnapshot(value, expected) {
51
+ if (value.snapshotToken !== expected) throw new QMindError("PROTOCOL_ERROR", "RepoWiki response belongs to a different snapshot");
52
+ return value;
53
+ }
54
+ function createWikiOperations(context) {
55
+ const path = (input, operation) => context.profile.wikiReadPath(requiredString(input?.organizationId, "organizationId"), operation);
56
+ return {
57
+ async getWikiCatalog(input, options) {
58
+ return call(context, {
59
+ callOptions: options,
60
+ capability: "wiki.read",
61
+ idempotent: true,
62
+ method: "GET",
63
+ operation: "wiki.catalog",
64
+ path: queryPath(path(input, "catalog"), scopeQuery(input)),
65
+ schema: catalogSchema
66
+ });
67
+ },
68
+ async getWikiSection(input, options) {
69
+ const part = nonNegativeInteger(input?.part, "part");
70
+ if (part === void 0 || part > 2147483647) throw invalidArgument("part must be a non-negative int32", "part");
71
+ return verifySnapshot(await call(context, {
72
+ callOptions: options,
73
+ capability: "wiki.read",
74
+ idempotent: true,
75
+ method: "GET",
76
+ operation: "wiki.section",
77
+ path: queryPath(path(input, "section"), [
78
+ ...snapshotQuery(input),
79
+ ["sectionId", requiredString(input?.sectionId, "sectionId")],
80
+ ["part", part]
81
+ ]),
82
+ schema: sectionSchema
83
+ }), input.snapshotToken.trim());
84
+ },
85
+ async searchWikiSections(input, options) {
86
+ return verifySnapshot(await call(context, {
87
+ callOptions: options,
88
+ capability: "wiki.read",
89
+ idempotent: true,
90
+ method: "GET",
91
+ operation: "wiki.search",
92
+ path: queryPath(path(input, "search"), [...snapshotQuery(input), ["query", requiredString(input?.query, "query")]]),
93
+ schema: searchSchema
94
+ }), input.snapshotToken.trim());
95
+ }
96
+ };
97
+ }
98
+ //#endregion
99
+ export { createWikiOperations };
@@ -1,4 +1,5 @@
1
- import { Z as timestampSchema, a as invalidArgument, d as pagination, m as requiredString, n as call, p as queryPath, u as optionalTrimmedString } from "./shared-53S5tNf6.js";
1
+ import { F as timestampSchema } from "./schemas-DG7vaJMR.js";
2
+ import { a as invalidArgument, d as pagination, m as requiredString, n as call, p as queryPath, u as optionalTrimmedString } from "./shared-CbvrtGyv.js";
2
3
  import { z } from "zod";
3
4
  //#region ../sdk/src/operations/wiki-branches.ts
4
5
  function isRecord(value) {