@qoder-ai/qmind-cli 4.3.0 → 5.0.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.
- package/CHANGELOG.md +10 -0
- package/CHANGELOG.zh-CN.md +10 -0
- package/README.md +7 -3
- package/README.zh-CN.md +11 -7
- package/dist/data-sources-DItXSL_s.js +129 -0
- package/dist/{imports-Bb3NHsmd.js → imports-CSg7ebnN.js} +15 -16
- package/dist/management-iTQ9-Osc.js +206 -0
- package/dist/nezha-B_SP8BvK.js +13 -0
- package/dist/{notes-HS_N--cJ.js → notes-BUq1ciGO.js} +7 -8
- package/dist/qmind.js +434 -673
- package/dist/{schemas-DG7vaJMR.js → shared-evTnu_EB.js} +657 -45
- package/dist/{source-upload-XrNG4_4V.js → source-upload-DckYHoRo.js} +2 -3
- package/dist/{transfers-DONoEIKT.js → transfers-C0pXH5Qe.js} +11 -16
- package/dist/{wiki-DBT6JdyN.js → wiki-_a2EAozi.js} +3 -2
- package/dist/{wiki-branches-BfEMuXDW.js → wiki-branches-DViaqEOy.js} +3 -4
- package/package.json +5 -5
- package/dist/bot-gateway-C4c1bMi9.js +0 -374
- package/dist/management-BYR88TwO.js +0 -387
- package/dist/shared-CbvrtGyv.js +0 -386
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
//#region ../sdk/src/errors.ts
|
|
3
|
+
var QMindError = class extends Error {
|
|
4
|
+
code;
|
|
5
|
+
details;
|
|
6
|
+
dataSourceAppPermission;
|
|
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.code = code;
|
|
16
|
+
this.details = options.details;
|
|
17
|
+
this.dataSourceAppPermission = options.dataSourceAppPermission;
|
|
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
|
|
2
26
|
//#region ../sdk/src/imports.ts
|
|
3
27
|
const qmindFullSiteURLImportPageLimit = 2e3;
|
|
4
28
|
const runStatuses = Object.freeze({
|
|
@@ -119,7 +143,7 @@ function normalizeQMindTaskRunStatus(status) {
|
|
|
119
143
|
}
|
|
120
144
|
//#endregion
|
|
121
145
|
//#region ../sdk/src/schemas.ts
|
|
122
|
-
function isRecord(value) {
|
|
146
|
+
function isRecord$1(value) {
|
|
123
147
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
124
148
|
}
|
|
125
149
|
const wirePageNumberSchema = z.number().int().nonnegative().optional();
|
|
@@ -208,7 +232,7 @@ const sourcePageInfoSchema = z.object({
|
|
|
208
232
|
prevPage: wirePageNumberSchema,
|
|
209
233
|
totalSize: z.number().int().nonnegative().optional()
|
|
210
234
|
});
|
|
211
|
-
const sourceExternalBindingSchema = z.preprocess((value) => isRecord(value) ? {
|
|
235
|
+
const sourceExternalBindingSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
212
236
|
...value,
|
|
213
237
|
bindingId: value.bindingId ?? value.binding_id,
|
|
214
238
|
isRoot: value.isRoot ?? value.is_root
|
|
@@ -217,6 +241,15 @@ const sourceExternalBindingSchema = z.preprocess((value) => isRecord(value) ? {
|
|
|
217
241
|
isRoot: z.boolean().default(false),
|
|
218
242
|
provider: z.string().default("")
|
|
219
243
|
}));
|
|
244
|
+
const sourceDataSourceSchema = z.object({
|
|
245
|
+
dataSourceId: z.string(),
|
|
246
|
+
provider: z.string(),
|
|
247
|
+
rootSourceId: z.string(),
|
|
248
|
+
isRoot: z.boolean(),
|
|
249
|
+
readOnly: z.boolean(),
|
|
250
|
+
canDelete: z.boolean(),
|
|
251
|
+
originalFileUnavailable: z.boolean()
|
|
252
|
+
});
|
|
220
253
|
const sourceLearningSchema = z.object({
|
|
221
254
|
status: z.string().default("unknown"),
|
|
222
255
|
errorCode: z.string().default(""),
|
|
@@ -238,6 +271,7 @@ const sourceSchema = z.object({
|
|
|
238
271
|
errorCode: z.string().default(""),
|
|
239
272
|
errorMessage: z.string().default(""),
|
|
240
273
|
externalBinding: sourceExternalBindingSchema.optional(),
|
|
274
|
+
dataSource: sourceDataSourceSchema.optional(),
|
|
241
275
|
filename: z.string().optional(),
|
|
242
276
|
hasChildren: z.boolean().optional(),
|
|
243
277
|
id: z.string().min(1),
|
|
@@ -265,33 +299,6 @@ const sourceListSchema = z.object({
|
|
|
265
299
|
sources: z.array(sourceSchema).nullish().transform((sources) => sources ?? []),
|
|
266
300
|
totalSize: z.number().int().nonnegative().optional()
|
|
267
301
|
});
|
|
268
|
-
const sourceTreeNodeSchema = z.lazy(() => z.preprocess((value) => isRecord(value) ? {
|
|
269
|
-
...value,
|
|
270
|
-
updatedAt: value.updatedAt ?? value.updated_at
|
|
271
|
-
} : value, z.object({
|
|
272
|
-
learning: sourceLearningSchema.optional(),
|
|
273
|
-
learningStatus: z.string().optional(),
|
|
274
|
-
learningErrorCode: z.string().optional(),
|
|
275
|
-
metadata: z.record(z.string(), z.unknown()).nullable().optional(),
|
|
276
|
-
externalBinding: sourceExternalBindingSchema.optional(),
|
|
277
|
-
originUrl: z.string().optional(),
|
|
278
|
-
isEmailFolder: z.boolean().optional(),
|
|
279
|
-
isEmailAggregateMember: z.boolean().optional(),
|
|
280
|
-
isExternalSource: z.boolean().optional(),
|
|
281
|
-
files: z.array(sourceTreeNodeSchema).default([]),
|
|
282
|
-
hasChildren: z.boolean().optional(),
|
|
283
|
-
id: z.string().min(1),
|
|
284
|
-
name: z.string().default(""),
|
|
285
|
-
path: z.string().default(""),
|
|
286
|
-
sourceType: z.string().default(""),
|
|
287
|
-
status: z.string().default(""),
|
|
288
|
-
type: z.enum(["file", "directory"]),
|
|
289
|
-
updatedAt: timestampSchema.optional()
|
|
290
|
-
})));
|
|
291
|
-
const sourceTreeSchema = z.object({
|
|
292
|
-
totalSize: z.number().int().nonnegative().default(0),
|
|
293
|
-
tree: z.array(sourceTreeNodeSchema)
|
|
294
|
-
});
|
|
295
302
|
const sourceContentSchema = z.object({
|
|
296
303
|
content: z.string(),
|
|
297
304
|
contentType: z.string().default("text/markdown"),
|
|
@@ -304,7 +311,7 @@ const wireInt64Schema = z.union([z.number(), z.string()]).nullish().transform((v
|
|
|
304
311
|
return Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : 0;
|
|
305
312
|
});
|
|
306
313
|
const sourceUploadExtensionSchema = z.string().regex(/^\.[a-z0-9]+$/);
|
|
307
|
-
const sourceUploadMethodSchema = z.preprocess((value) => isRecord(value) ? {
|
|
314
|
+
const sourceUploadMethodSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
308
315
|
...value,
|
|
309
316
|
maxSizeBytes: value.maxSizeBytes ?? value.max_size_bytes,
|
|
310
317
|
supportedExtensions: value.supportedExtensions ?? value.supported_extensions
|
|
@@ -314,7 +321,7 @@ const sourceUploadMethodSchema = z.preprocess((value) => isRecord(value) ? {
|
|
|
314
321
|
method: z.string().min(1),
|
|
315
322
|
supportedExtensions: z.array(sourceUploadExtensionSchema).default([])
|
|
316
323
|
}));
|
|
317
|
-
const sourceUploadFileTypeSchema = z.preprocess((value) => isRecord(value) ? {
|
|
324
|
+
const sourceUploadFileTypeSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
318
325
|
...value,
|
|
319
326
|
displayName: value.displayName ?? value.display_name,
|
|
320
327
|
mimeTypes: value.mimeTypes ?? value.mime_types,
|
|
@@ -333,7 +340,7 @@ const sourceQuotaSchema = z.object({
|
|
|
333
340
|
planTier: z.string().min(1),
|
|
334
341
|
quotaEnabled: z.boolean()
|
|
335
342
|
}).refine((value) => !value.quotaEnabled || value.limitBytes > 0);
|
|
336
|
-
const sourceUploadCapabilitiesSchema = z.preprocess((value) => isRecord(value) ? {
|
|
343
|
+
const sourceUploadCapabilitiesSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
337
344
|
...value,
|
|
338
345
|
fileTypes: value.fileTypes ?? value.file_types,
|
|
339
346
|
uploadMethods: value.uploadMethods ?? value.upload_methods
|
|
@@ -351,16 +358,16 @@ const downloadOriginalActionAccessSchema = z.discriminatedUnion("state", [z.obje
|
|
|
351
358
|
state: z.literal("denied")
|
|
352
359
|
})]);
|
|
353
360
|
const sourceActionAccessSchema = z.preprocess((value) => {
|
|
354
|
-
if (!isRecord(value) || !Array.isArray(value.actions)) return value;
|
|
361
|
+
if (!isRecord$1(value) || !Array.isArray(value.actions)) return value;
|
|
355
362
|
return {
|
|
356
363
|
...value,
|
|
357
364
|
actions: value.actions.filter((action) => {
|
|
358
|
-
if (!isRecord(action)) return true;
|
|
365
|
+
if (!isRecord$1(action)) return true;
|
|
359
366
|
return typeof action.action !== "string" || action.action.length === 0 || action.action === "download_original";
|
|
360
367
|
})
|
|
361
368
|
};
|
|
362
369
|
}, z.object({ actions: z.array(downloadOriginalActionAccessSchema).length(1) }));
|
|
363
|
-
const sourceRawContentSchema = z.preprocess((value) => isRecord(value) ? {
|
|
370
|
+
const sourceRawContentSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
364
371
|
...value,
|
|
365
372
|
contentType: value.contentType ?? value.content_type,
|
|
366
373
|
sizeBytes: value.sizeBytes ?? value.size_bytes,
|
|
@@ -373,7 +380,7 @@ const sourceRawContentSchema = z.preprocess((value) => isRecord(value) ? {
|
|
|
373
380
|
sourceFormat: z.string().default(""),
|
|
374
381
|
sourceId: z.string().default("")
|
|
375
382
|
}));
|
|
376
|
-
const sourcePreviewSchema = z.preprocess((value) => isRecord(value) ? {
|
|
383
|
+
const sourcePreviewSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
377
384
|
...value,
|
|
378
385
|
contentType: value.contentType ?? value.content_type,
|
|
379
386
|
expiresAt: value.expiresAt ?? value.expires_at,
|
|
@@ -395,7 +402,7 @@ const webOfficeTokenFields = {
|
|
|
395
402
|
tokenVersion: officeTokenIntegerSchema
|
|
396
403
|
};
|
|
397
404
|
function webOfficeTokenAliases(value) {
|
|
398
|
-
return isRecord(value) ? {
|
|
405
|
+
return isRecord$1(value) ? {
|
|
399
406
|
...value,
|
|
400
407
|
accessToken: value.accessToken ?? value.access_token,
|
|
401
408
|
accessTokenExpiresAt: value.accessTokenExpiresAt ?? value.access_token_expires_at,
|
|
@@ -405,7 +412,7 @@ function webOfficeTokenAliases(value) {
|
|
|
405
412
|
}
|
|
406
413
|
const sourceWebOfficeSessionSchema = z.preprocess((value) => {
|
|
407
414
|
const aliased = webOfficeTokenAliases(value);
|
|
408
|
-
return isRecord(aliased) ? {
|
|
415
|
+
return isRecord$1(aliased) ? {
|
|
409
416
|
...aliased,
|
|
410
417
|
readOnly: aliased.readOnly ?? aliased.readonly,
|
|
411
418
|
sessionId: aliased.sessionId ?? aliased.session_id,
|
|
@@ -423,7 +430,7 @@ const sourceWebOfficeSessionSchema = z.preprocess((value) => {
|
|
|
423
430
|
webOfficeUrl: httpsUrlSchema
|
|
424
431
|
}));
|
|
425
432
|
const sourceWebOfficeTokenSchema = z.preprocess(webOfficeTokenAliases, z.object(webOfficeTokenFields));
|
|
426
|
-
const sourceChildrenCountsSchema = z.object({ counts: z.array(z.preprocess((value) => isRecord(value) ? {
|
|
433
|
+
const sourceChildrenCountsSchema = z.object({ counts: z.array(z.preprocess((value) => isRecord$1(value) ? {
|
|
427
434
|
...value,
|
|
428
435
|
parentId: value.parentId ?? value.parent_id
|
|
429
436
|
} : value, z.object({
|
|
@@ -431,7 +438,7 @@ const sourceChildrenCountsSchema = z.object({ counts: z.array(z.preprocess((valu
|
|
|
431
438
|
parentId: z.string().default("")
|
|
432
439
|
}))).nullish().transform((counts) => counts ?? []) }).transform((value) => value.counts);
|
|
433
440
|
const importProvidersSchema = z.object({ sources: z.array(z.object({ provider: z.string().default("") })).nullish().transform((sources) => sources ?? []) }).transform((value) => value.sources.filter((source) => source.provider.length > 0));
|
|
434
|
-
const aliDingImportRunSchema = z.preprocess((value) => isRecord(value) ? {
|
|
441
|
+
const aliDingImportRunSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
435
442
|
...value,
|
|
436
443
|
bindingId: value.bindingId ?? value.binding_id,
|
|
437
444
|
canonicalUrl: value.canonicalUrl ?? value.canonical_url,
|
|
@@ -500,7 +507,7 @@ const aliDingImportRunSchema = z.preprocess((value) => isRecord(value) ? {
|
|
|
500
507
|
status: normalizeQMindAliDingImportRunStatus(value.status),
|
|
501
508
|
...value.updatedAt === void 0 ? {} : { updatedAt: value.updatedAt }
|
|
502
509
|
}));
|
|
503
|
-
const aliDingImportRunItemSchema = z.preprocess((value) => isRecord(value) ? {
|
|
510
|
+
const aliDingImportRunItemSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
504
511
|
...value,
|
|
505
512
|
contentStatus: value.contentStatus ?? value.content_status,
|
|
506
513
|
descendantsStatus: value.descendantsStatus ?? value.descendants_status,
|
|
@@ -542,7 +549,7 @@ const aliDingImportRunItemSchema = z.preprocess((value) => isRecord(value) ? {
|
|
|
542
549
|
status: normalizeQMindAliDingImportItemStatus(value.status),
|
|
543
550
|
...value.updatedAt === void 0 ? {} : { updatedAt: value.updatedAt }
|
|
544
551
|
}));
|
|
545
|
-
const aliDingImportPageInfoSchema = z.preprocess((value) => isRecord(value) ? {
|
|
552
|
+
const aliDingImportPageInfoSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
546
553
|
...value,
|
|
547
554
|
currentPage: value.currentPage ?? value.current_page,
|
|
548
555
|
lastPage: value.lastPage ?? value.last_page,
|
|
@@ -584,7 +591,7 @@ const imageUrlsSchema = z.object({
|
|
|
584
591
|
expiresAt: z.string().optional(),
|
|
585
592
|
urls: z.record(z.string(), httpsUrlSchema)
|
|
586
593
|
});
|
|
587
|
-
const notebookCitationSchema = z.preprocess((value) => isRecord(value) ? {
|
|
594
|
+
const notebookCitationSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
588
595
|
...value,
|
|
589
596
|
chunkId: value.chunkId ?? value.chunk_id,
|
|
590
597
|
chunkIndex: value.chunkIndex ?? value.chunk_index,
|
|
@@ -618,7 +625,7 @@ const chatMessageSchema = z.object({
|
|
|
618
625
|
updatedAt: timestampSchema.optional(),
|
|
619
626
|
userId: z.string().optional()
|
|
620
627
|
});
|
|
621
|
-
const streamChatMessageSchema = z.preprocess((value) => isRecord(value) && Array.isArray(value.citations) ? {
|
|
628
|
+
const streamChatMessageSchema = z.preprocess((value) => isRecord$1(value) && Array.isArray(value.citations) ? {
|
|
622
629
|
...value,
|
|
623
630
|
citations: value.citations.map((citation) => typeof citation === "string" ? { sourceId: citation } : citation)
|
|
624
631
|
} : value, chatMessageSchema);
|
|
@@ -768,4 +775,609 @@ const retrieveNotebooksResultSchema = z.object({
|
|
|
768
775
|
total: z.number().int().nonnegative().default(0)
|
|
769
776
|
});
|
|
770
777
|
//#endregion
|
|
771
|
-
|
|
778
|
+
//#region ../sdk/src/protocol.ts
|
|
779
|
+
function encodeId(value) {
|
|
780
|
+
return encodeURIComponent(value);
|
|
781
|
+
}
|
|
782
|
+
function appendQuery(path, entries) {
|
|
783
|
+
const query = new URLSearchParams();
|
|
784
|
+
for (const [key, value] of entries) if (value !== void 0 && value !== "") query.set(key, String(value));
|
|
785
|
+
const suffix = query.toString();
|
|
786
|
+
return suffix ? `${path}?${suffix}` : path;
|
|
787
|
+
}
|
|
788
|
+
function streamError(message, details) {
|
|
789
|
+
return new QMindError("STREAM_ERROR", message, {
|
|
790
|
+
...details === void 0 ? {} : { details },
|
|
791
|
+
operation: "chat.stream"
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
function requiredString$1(value, field) {
|
|
795
|
+
if (value !== void 0 && value.length > 0) return value;
|
|
796
|
+
throw streamError(`stream event is missing ${field}`, { field });
|
|
797
|
+
}
|
|
798
|
+
function stringValue(value) {
|
|
799
|
+
return value ?? "";
|
|
800
|
+
}
|
|
801
|
+
function presentString(value, field) {
|
|
802
|
+
if (value !== void 0) return value;
|
|
803
|
+
throw streamError(`stream event is missing ${field}`, { field });
|
|
804
|
+
}
|
|
805
|
+
function decodeStreamEvent(body) {
|
|
806
|
+
const parsed = streamWireEventSchema.safeParse(body);
|
|
807
|
+
if (!parsed.success) throw streamError("stream event does not match the QMind contract", { issues: parsed.error.issues });
|
|
808
|
+
const event = parsed.data;
|
|
809
|
+
const eventType = event.eventType ?? event.event_type ?? event.type;
|
|
810
|
+
switch (eventType) {
|
|
811
|
+
case "message_start": return {
|
|
812
|
+
citations: event.citations ?? [],
|
|
813
|
+
reranked: event.reranked ?? false,
|
|
814
|
+
totalContextChunks: event.totalContextChunks ?? 0,
|
|
815
|
+
type: "messageStart",
|
|
816
|
+
...event.assistantMessageId === void 0 ? {} : { assistantMessageId: event.assistantMessageId },
|
|
817
|
+
...event.userMessage === void 0 ? {} : { userMessage: event.userMessage }
|
|
818
|
+
};
|
|
819
|
+
case "tool_call_start": return {
|
|
820
|
+
step: event.step ?? 0,
|
|
821
|
+
toolArguments: stringValue(event.toolArguments),
|
|
822
|
+
toolName: requiredString$1(event.toolName, "toolName"),
|
|
823
|
+
type: "toolCallStart",
|
|
824
|
+
...event.toolDisplayName === void 0 ? {} : { toolDisplayName: event.toolDisplayName }
|
|
825
|
+
};
|
|
826
|
+
case "tool_call_result": return {
|
|
827
|
+
step: event.step ?? 0,
|
|
828
|
+
toolName: requiredString$1(event.toolName, "toolName"),
|
|
829
|
+
toolResult: stringValue(event.toolResult),
|
|
830
|
+
type: "toolCallResult",
|
|
831
|
+
...event.toolDisplayName === void 0 ? {} : { toolDisplayName: event.toolDisplayName }
|
|
832
|
+
};
|
|
833
|
+
case "delta": return {
|
|
834
|
+
delta: presentString(event.delta, "delta"),
|
|
835
|
+
type: "delta"
|
|
836
|
+
};
|
|
837
|
+
case "batch_progress": return {
|
|
838
|
+
metadata: event.metadata ?? {},
|
|
839
|
+
type: "batchProgress"
|
|
840
|
+
};
|
|
841
|
+
case "heartbeat": return {
|
|
842
|
+
metadata: event.metadata ?? {},
|
|
843
|
+
type: "heartbeat"
|
|
844
|
+
};
|
|
845
|
+
case "cancel": return {
|
|
846
|
+
canceled: true,
|
|
847
|
+
type: "cancel",
|
|
848
|
+
...event.cancelReason === void 0 ? {} : { cancelReason: event.cancelReason }
|
|
849
|
+
};
|
|
850
|
+
case "message_complete": return {
|
|
851
|
+
canceled: event.canceled ?? false,
|
|
852
|
+
citations: event.citations ?? [],
|
|
853
|
+
metadata: event.metadata ?? {},
|
|
854
|
+
promptContext: event.promptContext ?? "",
|
|
855
|
+
reranked: event.reranked ?? false,
|
|
856
|
+
totalContextChunks: event.totalContextChunks ?? 0,
|
|
857
|
+
type: "messageComplete",
|
|
858
|
+
...event.assistantMessage === void 0 ? {} : { assistantMessage: event.assistantMessage },
|
|
859
|
+
...event.cancelReason === void 0 ? {} : { cancelReason: event.cancelReason }
|
|
860
|
+
};
|
|
861
|
+
case "error": return {
|
|
862
|
+
message: requiredString$1(event.errorMessage ?? event.error, "errorMessage"),
|
|
863
|
+
type: "error"
|
|
864
|
+
};
|
|
865
|
+
default: throw streamError("stream event has an unsupported event type", { eventType });
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
function decodeStreamPayload(payload) {
|
|
869
|
+
let value;
|
|
870
|
+
try {
|
|
871
|
+
value = JSON.parse(payload);
|
|
872
|
+
} catch (cause) {
|
|
873
|
+
throw streamError("stream event is not valid JSON", { cause });
|
|
874
|
+
}
|
|
875
|
+
return decodeStreamEvent(value);
|
|
876
|
+
}
|
|
877
|
+
const publicPrefix = "/qmind/api/v1";
|
|
878
|
+
function pathBuilder(prefix) {
|
|
879
|
+
return (...segments) => `${prefix}/${segments.map(encodeId).join("/")}`;
|
|
880
|
+
}
|
|
881
|
+
const qmindPath = pathBuilder(publicPrefix);
|
|
882
|
+
const qmindRoutes = {
|
|
883
|
+
featuredNotebookPath(notebookId) {
|
|
884
|
+
return notebookId === void 0 ? qmindPath("featured-notebooks") : qmindPath("featured-notebooks", notebookId);
|
|
885
|
+
},
|
|
886
|
+
listFeaturedNotebooksPath(input) {
|
|
887
|
+
return appendQuery(`${publicPrefix}/featured-notebooks`, [["page", input.page], ["page_size", input.pageSize]]);
|
|
888
|
+
},
|
|
889
|
+
listNotebooksPath(input) {
|
|
890
|
+
return appendQuery(`${publicPrefix}/notebooks`, [
|
|
891
|
+
["page", input.page],
|
|
892
|
+
["page_size", input.pageSize],
|
|
893
|
+
["client", input.client],
|
|
894
|
+
["retrieval_eligible_only", input.retrievalEligibleOnly]
|
|
895
|
+
]);
|
|
896
|
+
},
|
|
897
|
+
listSharedNotebooksPath(input) {
|
|
898
|
+
return appendQuery(`${publicPrefix}/notebooks/shared`, [
|
|
899
|
+
["page", input.page],
|
|
900
|
+
["page_size", input.pageSize],
|
|
901
|
+
["retrieval_eligible_only", input.retrievalEligibleOnly]
|
|
902
|
+
]);
|
|
903
|
+
},
|
|
904
|
+
notebookPath(notebookId) {
|
|
905
|
+
return notebookId === void 0 ? qmindPath("notebooks") : qmindPath("notebooks", notebookId);
|
|
906
|
+
},
|
|
907
|
+
wikiBranchesPath(notebookId) {
|
|
908
|
+
return qmindPath("notebooks", notebookId, "wiki-branches");
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
const scopeList = z.array(z.string().max(128).regex(/^[a-zA-Z][a-zA-Z0-9_]*(?:[.:][a-zA-Z0-9_]+)+$/)).min(1).max(16).refine((scopes) => new Set(scopes).size === scopes.length);
|
|
912
|
+
const permissionCapabilities = [
|
|
913
|
+
"wiki_spaces",
|
|
914
|
+
"wiki_children",
|
|
915
|
+
"wiki_node",
|
|
916
|
+
"drive_listing",
|
|
917
|
+
"document_read",
|
|
918
|
+
"document_export",
|
|
919
|
+
"file_download",
|
|
920
|
+
"document_media",
|
|
921
|
+
"whiteboard_image",
|
|
922
|
+
"embedded_sheet",
|
|
923
|
+
"embedded_bitable_fields",
|
|
924
|
+
"embedded_bitable_records",
|
|
925
|
+
"linked_document_titles",
|
|
926
|
+
"mentioned_user_lookup",
|
|
927
|
+
"mentioned_user_names"
|
|
928
|
+
];
|
|
929
|
+
function permissionEntries(entry) {
|
|
930
|
+
return z.array(z.unknown()).max(16).transform((values) => {
|
|
931
|
+
const seen = /* @__PURE__ */ new Set();
|
|
932
|
+
return values.flatMap((value) => {
|
|
933
|
+
const parsed = entry.safeParse(value);
|
|
934
|
+
if (!parsed.success || seen.has(parsed.data.capability)) return [];
|
|
935
|
+
seen.add(parsed.data.capability);
|
|
936
|
+
return [parsed.data];
|
|
937
|
+
});
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
const permissionGroups = permissionEntries(z.object({
|
|
941
|
+
capability: z.enum(permissionCapabilities),
|
|
942
|
+
anyOfScopes: scopeList
|
|
943
|
+
})).optional().catch(void 0);
|
|
944
|
+
const permissionGrants = permissionEntries(z.object({
|
|
945
|
+
capability: z.enum(permissionCapabilities),
|
|
946
|
+
grantedScopes: scopeList
|
|
947
|
+
})).optional().catch(void 0);
|
|
948
|
+
const dataSourceAppPermissionSchema = z.object({
|
|
949
|
+
requiredScopes: scopeList,
|
|
950
|
+
anyOf: z.boolean(),
|
|
951
|
+
permissionRequirements: permissionGroups,
|
|
952
|
+
permissionWarnings: permissionGroups,
|
|
953
|
+
permissionGrants
|
|
954
|
+
});
|
|
955
|
+
/** 只提取应用权限标识与匹配方式。 */
|
|
956
|
+
function readQMindDataSourceAppPermission(code, details) {
|
|
957
|
+
if (code !== "DataSourceAppPermissionRequired") return void 0;
|
|
958
|
+
const parsed = dataSourceAppPermissionSchema.safeParse(details);
|
|
959
|
+
return parsed.success ? parsed.data : void 0;
|
|
960
|
+
}
|
|
961
|
+
const dataSourceConfigurationSchema = z.object({
|
|
962
|
+
name: z.string().min(1).max(255),
|
|
963
|
+
provider: z.enum([
|
|
964
|
+
"feishu",
|
|
965
|
+
"feishu_drive",
|
|
966
|
+
"dingtalk"
|
|
967
|
+
]),
|
|
968
|
+
resourceIds: z.array(z.string().min(1)).max(1e3).default([]),
|
|
969
|
+
settings: z.record(z.string(), z.unknown()).default({}),
|
|
970
|
+
schedule: z.string().default(""),
|
|
971
|
+
paused: z.boolean().default(false),
|
|
972
|
+
syncDeletions: z.boolean().default(false)
|
|
973
|
+
});
|
|
974
|
+
const dataSourceSchema = z.object({
|
|
975
|
+
id: z.string().min(1),
|
|
976
|
+
configuration: dataSourceConfigurationSchema,
|
|
977
|
+
credentialsConfigured: z.boolean().default(false),
|
|
978
|
+
lastSyncAt: z.string().nullish()
|
|
979
|
+
});
|
|
980
|
+
const dataSourceResourceSchema = z.object({
|
|
981
|
+
externalId: z.string().min(1),
|
|
982
|
+
name: z.string(),
|
|
983
|
+
type: z.string(),
|
|
984
|
+
url: z.string().default(""),
|
|
985
|
+
parentId: z.string().default(""),
|
|
986
|
+
hasChildren: z.boolean().default(false)
|
|
987
|
+
});
|
|
988
|
+
const dataSourceRunSchema = z.object({
|
|
989
|
+
id: z.string().min(1),
|
|
990
|
+
status: z.enum([
|
|
991
|
+
"queued",
|
|
992
|
+
"running",
|
|
993
|
+
"success",
|
|
994
|
+
"partial",
|
|
995
|
+
"failed",
|
|
996
|
+
"canceled"
|
|
997
|
+
]),
|
|
998
|
+
startedAt: z.string().nullish(),
|
|
999
|
+
finishedAt: z.string().nullish(),
|
|
1000
|
+
total: z.number().int().default(0),
|
|
1001
|
+
created: z.number().int().default(0),
|
|
1002
|
+
updated: z.number().int().default(0),
|
|
1003
|
+
deleted: z.number().int().default(0),
|
|
1004
|
+
skipped: z.number().int().default(0),
|
|
1005
|
+
failed: z.number().int().default(0),
|
|
1006
|
+
errorCode: z.string().default(""),
|
|
1007
|
+
issuesTruncated: z.boolean().default(false),
|
|
1008
|
+
issues: z.array(z.object({
|
|
1009
|
+
externalId: z.string(),
|
|
1010
|
+
resourceId: z.string(),
|
|
1011
|
+
code: z.string(),
|
|
1012
|
+
retryState: z.string()
|
|
1013
|
+
})).default([])
|
|
1014
|
+
});
|
|
1015
|
+
const dataSourceListSchema = z.object({
|
|
1016
|
+
dataSources: z.array(dataSourceSchema).default([]),
|
|
1017
|
+
nextAfterId: z.string().default(""),
|
|
1018
|
+
availableProviders: z.array(z.string()).default([])
|
|
1019
|
+
});
|
|
1020
|
+
const dataSourceRunsSchema = z.object({
|
|
1021
|
+
runs: z.array(dataSourceRunSchema).default([]),
|
|
1022
|
+
nextBeforeStartedAt: z.string().nullish(),
|
|
1023
|
+
nextBeforeId: z.string().default("")
|
|
1024
|
+
});
|
|
1025
|
+
const dataSourcePreviewSchema = z.object({
|
|
1026
|
+
resources: z.array(dataSourceResourceSchema).default([]),
|
|
1027
|
+
permissionWarnings: permissionGroups,
|
|
1028
|
+
permissionGrants
|
|
1029
|
+
});
|
|
1030
|
+
//#endregion
|
|
1031
|
+
//#region ../sdk/src/wiki.ts
|
|
1032
|
+
/** 保留 HTTP 错误证据,并以有界状态供宿主选择本地化提示。 */
|
|
1033
|
+
var QMindWikiReadError = class extends QMindError {
|
|
1034
|
+
wikiState;
|
|
1035
|
+
constructor(wikiState, error) {
|
|
1036
|
+
super(error.code, error.message, {
|
|
1037
|
+
cause: error,
|
|
1038
|
+
...error.operation === void 0 ? {} : { operation: error.operation },
|
|
1039
|
+
...error.status === void 0 ? {} : { status: error.status },
|
|
1040
|
+
...error.upstreamCode === void 0 ? {} : { upstreamCode: error.upstreamCode },
|
|
1041
|
+
...error.requestId === void 0 ? {} : { requestId: error.requestId },
|
|
1042
|
+
details: error.details
|
|
1043
|
+
});
|
|
1044
|
+
this.wikiState = wikiState;
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
//#endregion
|
|
1048
|
+
//#region ../sdk/src/execution.ts
|
|
1049
|
+
const credentialHeaders = /* @__PURE__ */ new Set([
|
|
1050
|
+
"authorization",
|
|
1051
|
+
"cookie",
|
|
1052
|
+
"proxy-authorization",
|
|
1053
|
+
"x-csrf-token",
|
|
1054
|
+
"x-xsrf-token"
|
|
1055
|
+
]);
|
|
1056
|
+
function isRecord(value) {
|
|
1057
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1058
|
+
}
|
|
1059
|
+
function nestedRecord(value, key) {
|
|
1060
|
+
const nested = value[key];
|
|
1061
|
+
return isRecord(nested) ? nested : void 0;
|
|
1062
|
+
}
|
|
1063
|
+
function firstString(records, keys) {
|
|
1064
|
+
for (const record of records) {
|
|
1065
|
+
if (record === void 0) continue;
|
|
1066
|
+
for (const key of keys) {
|
|
1067
|
+
const value = record[key];
|
|
1068
|
+
if (typeof value === "string" && value.length > 0) return value;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
function headerValue(headers, name) {
|
|
1073
|
+
const normalizedName = name.toLowerCase();
|
|
1074
|
+
for (const [key, value] of Object.entries(headers)) if (key.toLowerCase() === normalizedName && value.length > 0) return value;
|
|
1075
|
+
}
|
|
1076
|
+
function errorCodeForStatus(status) {
|
|
1077
|
+
if (status === 401) return "AUTH_REQUIRED";
|
|
1078
|
+
if (status === 403) return "FORBIDDEN";
|
|
1079
|
+
if (status === 404) return "NOT_FOUND";
|
|
1080
|
+
if (status === 409) return "CONFLICT";
|
|
1081
|
+
if (status === 429) return "RATE_LIMITED";
|
|
1082
|
+
if (status >= 400 && status < 500) return "INVALID_ARGUMENT";
|
|
1083
|
+
return "REMOTE_ERROR";
|
|
1084
|
+
}
|
|
1085
|
+
function httpError(operation, response) {
|
|
1086
|
+
const body = response.body;
|
|
1087
|
+
const root = isRecord(body) ? body : void 0;
|
|
1088
|
+
const error = root === void 0 ? void 0 : nestedRecord(root, "error");
|
|
1089
|
+
const details = root === void 0 ? void 0 : nestedRecord(root, "details");
|
|
1090
|
+
const records = [
|
|
1091
|
+
root,
|
|
1092
|
+
error,
|
|
1093
|
+
details
|
|
1094
|
+
];
|
|
1095
|
+
const upstreamCode = firstString(records, [
|
|
1096
|
+
"errorCode",
|
|
1097
|
+
"error_code",
|
|
1098
|
+
"code"
|
|
1099
|
+
]);
|
|
1100
|
+
const dataSourceAppPermission = response.status === 400 && operation.startsWith("dataSources.") ? readQMindDataSourceAppPermission(upstreamCode, details) : void 0;
|
|
1101
|
+
const requestId = firstString(records, ["requestId", "request_id"]) ?? headerValue(response.headers, "x-request-id") ?? headerValue(response.headers, "request-id");
|
|
1102
|
+
const message = firstString(records, [
|
|
1103
|
+
"message",
|
|
1104
|
+
"errorMessage",
|
|
1105
|
+
"error_message"
|
|
1106
|
+
]) ?? `QMind request failed with HTTP ${response.status}`;
|
|
1107
|
+
const failure = new QMindError(errorCodeForStatus(response.status), message, {
|
|
1108
|
+
details: body,
|
|
1109
|
+
...dataSourceAppPermission ? { dataSourceAppPermission } : {},
|
|
1110
|
+
operation,
|
|
1111
|
+
...response.rawBody === void 0 ? {} : { rawBody: response.rawBody },
|
|
1112
|
+
...requestId === void 0 ? {} : { requestId },
|
|
1113
|
+
status: response.status,
|
|
1114
|
+
...upstreamCode === void 0 ? {} : { upstreamCode }
|
|
1115
|
+
});
|
|
1116
|
+
const state = headerValue(response.headers, "x-wiki-state");
|
|
1117
|
+
if (operation.startsWith("wiki.") && (state === "expired" || state === "busy" || state === "invalid" || state === "limit" || state === "missing")) return new QMindWikiReadError(state, failure);
|
|
1118
|
+
return failure;
|
|
1119
|
+
}
|
|
1120
|
+
function isAbortLike(cause) {
|
|
1121
|
+
return isRecord(cause) && (cause.name === "AbortError" && typeof cause.name === "string" || cause.code === "ABORT_ERR");
|
|
1122
|
+
}
|
|
1123
|
+
function transportError(operation, request, cause) {
|
|
1124
|
+
if (cause instanceof QMindError) return cause;
|
|
1125
|
+
const aborted = request.signal?.aborted === true || isAbortLike(cause);
|
|
1126
|
+
return new QMindError(aborted ? "ABORTED" : "NETWORK_ERROR", aborted ? "QMind request was aborted" : "QMind transport failed", {
|
|
1127
|
+
cause,
|
|
1128
|
+
operation
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
function requestWasAborted(request) {
|
|
1132
|
+
return request.signal?.aborted === true;
|
|
1133
|
+
}
|
|
1134
|
+
function assertWireRequestInvariant(request) {
|
|
1135
|
+
for (const [field, value] of [
|
|
1136
|
+
["connectTimeoutMs", request.connectTimeoutMs],
|
|
1137
|
+
["idleTimeoutMs", request.idleTimeoutMs],
|
|
1138
|
+
["timeoutMs", request.timeoutMs]
|
|
1139
|
+
]) if (!Number.isFinite(value ?? 1) || (value ?? 1) <= 0) throw new QMindError("INVALID_ARGUMENT", `${field} must be a positive finite number`, { details: { field } });
|
|
1140
|
+
if (request.destination.kind === "host") {
|
|
1141
|
+
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 } });
|
|
1142
|
+
return;
|
|
1143
|
+
}
|
|
1144
|
+
let url;
|
|
1145
|
+
try {
|
|
1146
|
+
url = new URL(request.destination.url);
|
|
1147
|
+
} catch (cause) {
|
|
1148
|
+
throw new QMindError("HOST_POLICY_ERROR", "signed destination must be a valid HTTPS URL", {
|
|
1149
|
+
cause,
|
|
1150
|
+
details: { destination: request.destination.kind }
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
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 } });
|
|
1154
|
+
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: {
|
|
1155
|
+
destination: request.destination.kind,
|
|
1156
|
+
header: header.toLowerCase()
|
|
1157
|
+
} });
|
|
1158
|
+
}
|
|
1159
|
+
function assertCapability(capabilities, capability, operation) {
|
|
1160
|
+
if (capabilities[capability]) return;
|
|
1161
|
+
throw new QMindError("UNSUPPORTED_OPERATION", `${operation} is unavailable on this client`, {
|
|
1162
|
+
details: { capability },
|
|
1163
|
+
operation
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
async function executeUnary(options) {
|
|
1167
|
+
const { capabilities, capability, operation, request, schema, transport } = options;
|
|
1168
|
+
assertCapability(capabilities, capability, operation);
|
|
1169
|
+
assertWireRequestInvariant(request);
|
|
1170
|
+
if (requestWasAborted(request)) throw new QMindError("ABORTED", "QMind request was aborted", { operation });
|
|
1171
|
+
let response;
|
|
1172
|
+
try {
|
|
1173
|
+
response = await transport.request(request);
|
|
1174
|
+
} catch (cause) {
|
|
1175
|
+
throw transportError(operation, request, cause);
|
|
1176
|
+
}
|
|
1177
|
+
if (response.status < 200 || response.status >= 300) throw httpError(operation, response);
|
|
1178
|
+
const body = response.body;
|
|
1179
|
+
const parsed = schema.safeParse(body);
|
|
1180
|
+
if (!parsed.success) throw new QMindError("PROTOCOL_ERROR", "server response does not match the QMind contract", {
|
|
1181
|
+
details: { issues: parsed.error.issues },
|
|
1182
|
+
operation,
|
|
1183
|
+
...response.rawBody === void 0 ? {} : { rawBody: response.rawBody },
|
|
1184
|
+
status: response.status
|
|
1185
|
+
});
|
|
1186
|
+
return parsed.data;
|
|
1187
|
+
}
|
|
1188
|
+
function streamContractError(operation, message, details) {
|
|
1189
|
+
return new QMindError("STREAM_ERROR", message, {
|
|
1190
|
+
...details === void 0 ? {} : { details },
|
|
1191
|
+
operation
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
function streamFailureResponse(response) {
|
|
1195
|
+
return {
|
|
1196
|
+
body: response.body,
|
|
1197
|
+
headers: response.headers,
|
|
1198
|
+
...response.rawBody === void 0 ? {} : { rawBody: response.rawBody },
|
|
1199
|
+
status: response.status
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
async function* executeStream(options) {
|
|
1203
|
+
const { capabilities, capability, operation, request, transport } = options;
|
|
1204
|
+
assertCapability(capabilities, capability, operation);
|
|
1205
|
+
assertWireRequestInvariant(request);
|
|
1206
|
+
if (requestWasAborted(request)) throw new QMindError("ABORTED", "QMind request was aborted", { operation });
|
|
1207
|
+
let response;
|
|
1208
|
+
try {
|
|
1209
|
+
response = await transport.stream(request);
|
|
1210
|
+
} catch (cause) {
|
|
1211
|
+
throw transportError(operation, request, cause);
|
|
1212
|
+
}
|
|
1213
|
+
if (response.kind === "response") {
|
|
1214
|
+
if (response.status >= 200 && response.status < 300) throw streamContractError(operation, "stream handshake returned no event stream", { status: response.status });
|
|
1215
|
+
throw httpError(operation, streamFailureResponse(response));
|
|
1216
|
+
}
|
|
1217
|
+
if (response.status < 200 || response.status >= 300) throw streamContractError(operation, "stream handshake returned events for a failure status", { status: response.status });
|
|
1218
|
+
let doneMarkerSeen = false;
|
|
1219
|
+
let started = false;
|
|
1220
|
+
let terminal = false;
|
|
1221
|
+
try {
|
|
1222
|
+
for await (const payload of response.events) {
|
|
1223
|
+
if (requestWasAborted(request)) throw new QMindError("ABORTED", "QMind request was aborted", { operation });
|
|
1224
|
+
if (payload.trim() === "[DONE]") {
|
|
1225
|
+
if (doneMarkerSeen) throw streamContractError(operation, "stream emitted more than one [DONE] marker");
|
|
1226
|
+
doneMarkerSeen = true;
|
|
1227
|
+
continue;
|
|
1228
|
+
}
|
|
1229
|
+
if (doneMarkerSeen) throw streamContractError(operation, "stream emitted an event after [DONE]");
|
|
1230
|
+
if (terminal) throw streamContractError(operation, "stream emitted an event after messageComplete");
|
|
1231
|
+
const event = decodeStreamPayload(payload);
|
|
1232
|
+
if (event.type === "error") throw streamContractError(operation, event.message, { event });
|
|
1233
|
+
if (event.type === "messageStart") {
|
|
1234
|
+
if (started) throw streamContractError(operation, "stream emitted duplicate messageStart");
|
|
1235
|
+
started = true;
|
|
1236
|
+
} else if (!started) throw streamContractError(operation, "stream event arrived before messageStart", { eventType: event.type });
|
|
1237
|
+
if (event.type === "messageComplete") terminal = true;
|
|
1238
|
+
yield event;
|
|
1239
|
+
}
|
|
1240
|
+
} catch (cause) {
|
|
1241
|
+
throw transportError(operation, request, cause);
|
|
1242
|
+
}
|
|
1243
|
+
if (requestWasAborted(request)) throw new QMindError("ABORTED", "QMind request was aborted", { operation });
|
|
1244
|
+
if (!terminal) throw streamContractError(operation, "stream ended before messageComplete", {
|
|
1245
|
+
doneMarkerSeen,
|
|
1246
|
+
started
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
//#endregion
|
|
1250
|
+
//#region ../sdk/src/operations/shared.ts
|
|
1251
|
+
function invalidArgument(message, field, details) {
|
|
1252
|
+
return new QMindError("INVALID_ARGUMENT", message, { details: details ?? { field } });
|
|
1253
|
+
}
|
|
1254
|
+
function requiredString(value, field) {
|
|
1255
|
+
if (typeof value !== "string" || value.trim().length === 0) throw invalidArgument(`${field} must be a non-empty string`, field);
|
|
1256
|
+
return value.trim();
|
|
1257
|
+
}
|
|
1258
|
+
function optionalString(value, field) {
|
|
1259
|
+
if (value === void 0) return void 0;
|
|
1260
|
+
if (typeof value !== "string") throw invalidArgument(`${field} must be a string`, field);
|
|
1261
|
+
return value;
|
|
1262
|
+
}
|
|
1263
|
+
/** Validate body text without trimming meaningful Markdown indentation or trailing newlines. */
|
|
1264
|
+
function requiredText(value, field) {
|
|
1265
|
+
const text = optionalString(value, field);
|
|
1266
|
+
if (text === void 0 || text.trim().length === 0) throw invalidArgument(`${field} must be a non-empty string`, field);
|
|
1267
|
+
return text;
|
|
1268
|
+
}
|
|
1269
|
+
function optionalTrimmedString(value, field) {
|
|
1270
|
+
const string = optionalString(value, field)?.trim();
|
|
1271
|
+
return string === "" ? void 0 : string;
|
|
1272
|
+
}
|
|
1273
|
+
function optionalRecord(value, field) {
|
|
1274
|
+
if (value === void 0) return void 0;
|
|
1275
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw invalidArgument(`${field} must be an object`, field);
|
|
1276
|
+
return value;
|
|
1277
|
+
}
|
|
1278
|
+
function optionalBoolean(value, field) {
|
|
1279
|
+
if (value === void 0) return void 0;
|
|
1280
|
+
if (typeof value !== "boolean") throw invalidArgument(`${field} must be a boolean`, field);
|
|
1281
|
+
return value;
|
|
1282
|
+
}
|
|
1283
|
+
function positiveInteger(value, field) {
|
|
1284
|
+
if (value === void 0) return void 0;
|
|
1285
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) throw invalidArgument(`${field} must be a positive integer`, field);
|
|
1286
|
+
return value;
|
|
1287
|
+
}
|
|
1288
|
+
function nonNegativeInteger(value, field) {
|
|
1289
|
+
if (value === void 0) return void 0;
|
|
1290
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) throw invalidArgument(`${field} must be a non-negative integer`, field);
|
|
1291
|
+
return value;
|
|
1292
|
+
}
|
|
1293
|
+
function pagination(input) {
|
|
1294
|
+
const page = positiveInteger(input.page, "page");
|
|
1295
|
+
const pageSize = positiveInteger(input.pageSize, "pageSize");
|
|
1296
|
+
return {
|
|
1297
|
+
...page === void 0 ? {} : { page },
|
|
1298
|
+
...pageSize === void 0 ? {} : { pageSize }
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
function stringList(value, field, options = {}) {
|
|
1302
|
+
if (!Array.isArray(value)) throw invalidArgument(`${field} must be an array`, field);
|
|
1303
|
+
const result = [];
|
|
1304
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1305
|
+
for (const item of value) {
|
|
1306
|
+
if (typeof item !== "string") throw invalidArgument(`${field} must contain only strings`, field);
|
|
1307
|
+
const normalized = item.trim();
|
|
1308
|
+
if (!normalized && !(options.keepEmptyString && item === "")) continue;
|
|
1309
|
+
if (seen.has(normalized)) continue;
|
|
1310
|
+
seen.add(normalized);
|
|
1311
|
+
result.push(normalized);
|
|
1312
|
+
}
|
|
1313
|
+
if (options.min !== void 0 && result.length < options.min) throw invalidArgument(`${field} must contain at least ${options.min} item(s)`, field);
|
|
1314
|
+
if (options.max !== void 0 && result.length > options.max) throw invalidArgument(`${field} must contain at most ${options.max} item(s)`, field);
|
|
1315
|
+
return result;
|
|
1316
|
+
}
|
|
1317
|
+
function httpUrl(value, field) {
|
|
1318
|
+
const raw = requiredString(value, field);
|
|
1319
|
+
let url;
|
|
1320
|
+
try {
|
|
1321
|
+
url = new URL(raw);
|
|
1322
|
+
} catch (cause) {
|
|
1323
|
+
throw invalidArgument(`${field} must be a valid HTTP(S) URL`, field, {
|
|
1324
|
+
cause,
|
|
1325
|
+
field
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
if (url.protocol !== "http:" && url.protocol !== "https:" || url.host.length === 0) throw invalidArgument(`${field} must be a valid HTTP(S) URL`, field);
|
|
1329
|
+
url.hash = "";
|
|
1330
|
+
return url.toString();
|
|
1331
|
+
}
|
|
1332
|
+
function compactUndefined(value) {
|
|
1333
|
+
return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== void 0));
|
|
1334
|
+
}
|
|
1335
|
+
function assertNonEmptyPatch(patch, field) {
|
|
1336
|
+
if (Object.keys(patch).length > 0) return;
|
|
1337
|
+
throw invalidArgument(`${field} must contain at least one change`, field);
|
|
1338
|
+
}
|
|
1339
|
+
function queryPath(path, entries) {
|
|
1340
|
+
const query = new URLSearchParams();
|
|
1341
|
+
for (const [key, value] of entries) if (value !== void 0 && value !== "") query.set(key, String(value));
|
|
1342
|
+
const suffix = query.toString();
|
|
1343
|
+
return suffix.length === 0 ? path : `${path}?${suffix}`;
|
|
1344
|
+
}
|
|
1345
|
+
function wireRequest(options) {
|
|
1346
|
+
const timeoutMs = options.callOptions?.timeoutMs;
|
|
1347
|
+
if (timeoutMs !== void 0 && (!Number.isFinite(timeoutMs) || timeoutMs <= 0)) throw invalidArgument("timeoutMs must be a positive finite number", "timeoutMs");
|
|
1348
|
+
const maxResponseBytes = options.callOptions?.maxResponseBytes;
|
|
1349
|
+
if (maxResponseBytes !== void 0 && (!Number.isSafeInteger(maxResponseBytes) || maxResponseBytes <= 0)) throw invalidArgument("maxResponseBytes must be a positive integer", "maxResponseBytes");
|
|
1350
|
+
const authorization = options.callOptions?.authorization?.trim();
|
|
1351
|
+
const headers = authorization ? {
|
|
1352
|
+
...options.headers,
|
|
1353
|
+
authorization: `Bearer ${authorization}`
|
|
1354
|
+
} : options.headers;
|
|
1355
|
+
return {
|
|
1356
|
+
...options.body === void 0 ? {} : { body: {
|
|
1357
|
+
kind: "json",
|
|
1358
|
+
value: options.body
|
|
1359
|
+
} },
|
|
1360
|
+
destination: {
|
|
1361
|
+
kind: "host",
|
|
1362
|
+
path: options.path
|
|
1363
|
+
},
|
|
1364
|
+
...headers === void 0 ? {} : { headers },
|
|
1365
|
+
idempotent: options.idempotent,
|
|
1366
|
+
method: options.method,
|
|
1367
|
+
...options.callOptions?.signal === void 0 ? {} : { signal: options.callOptions.signal },
|
|
1368
|
+
...timeoutMs === void 0 ? {} : { timeoutMs },
|
|
1369
|
+
...maxResponseBytes === void 0 ? {} : { maxResponseBytes }
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
function call(context, options) {
|
|
1373
|
+
return executeUnary({
|
|
1374
|
+
capability: options.capability,
|
|
1375
|
+
operation: options.operation,
|
|
1376
|
+
capabilities: context.capabilities,
|
|
1377
|
+
request: wireRequest(options),
|
|
1378
|
+
schema: options.schema,
|
|
1379
|
+
transport: context.transport
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
//#endregion
|
|
1383
|
+
export { sourceRawContentSchema as $, aliDingImportRunSchema as A, importProvidersSchema as B, dataSourceResourceSchema as C, qmindPath as D, pathBuilder as E, chatSessionSchema as F, sharedNotebookListSchema as G, notebookSchema as H, fullSiteURLImportConfirmationSchema as I, sourceContentSchema as J, sourceActionAccessSchema as K, fullSiteURLImportDiscoverySchema as L, cancelQuestionResultSchema as M, chatMessageListSchema as N, qmindRoutes as O, chatSessionListSchema as P, sourceQuotaSchema as Q, imageUploadTicketSchema as R, dataSourcePreviewSchema as S, dataSourceSchema as T, retrieveNotebooksResultSchema as U, notebookListSchema as V, retrieveResultSchema as W, sourceListSchema as X, sourceImportResultsSchema as Y, sourcePreviewSchema as Z, assertCapability as _, invalidArgument as a, taskRunListSchema as at, dataSourceConfigurationSchema as b, optionalRecord as c, voidResponseSchema as ct, pagination as d, sourceSchema as et, positiveInteger as f, stringList as g, requiredText as h, httpUrl as i, sourceWebOfficeTokenSchema as it, batchDeleteResultSchema as j, aliDingImportRunItemListSchema as k, optionalString as l, qmindFullSiteURLImportPageLimit as lt, requiredString as m, call as n, sourceUploadTicketSchema as nt, nonNegativeInteger as o, taskRunSchema as ot, queryPath as p, sourceChildrenCountsSchema as q, compactUndefined as r, sourceWebOfficeSessionSchema as rt, optionalBoolean as s, timestampSchema as st, assertNonEmptyPatch as t, sourceUploadCapabilitiesSchema as tt, optionalTrimmedString as u, QMindError as ut, executeStream as v, dataSourceRunsSchema as w, dataSourceListSchema as x, executeUnary as y, imageUrlsSchema as z };
|