@qoder-ai/qmind-cli 4.2.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 +16 -0
- package/CHANGELOG.zh-CN.md +16 -0
- package/README.md +9 -5
- package/README.zh-CN.md +11 -7
- package/dist/data-sources-DItXSL_s.js +129 -0
- package/dist/{imports-BZyUf1pq.js → imports-CSg7ebnN.js} +15 -15
- package/dist/management-iTQ9-Osc.js +206 -0
- package/dist/nezha-B_SP8BvK.js +13 -0
- package/dist/{notes-BRnv_Z10.js → notes-BUq1ciGO.js} +7 -7
- package/dist/qmind.js +5456 -5605
- package/dist/{shared-53S5tNf6.js → shared-evTnu_EB.js} +523 -265
- package/dist/{source-upload-DlOLtECT.js → source-upload-DckYHoRo.js} +2 -2
- package/dist/{transfers-cf1MXHdB.js → transfers-C0pXH5Qe.js} +94 -18
- package/dist/wiki-_a2EAozi.js +100 -0
- package/dist/{wiki-branches-DmgHlIxc.js → wiki-branches-DViaqEOy.js} +3 -3
- package/package.json +5 -5
- package/dist/bot-gateway-B5cW3ErV.js +0 -373
- package/dist/management-DQVj17Hn.js +0 -386
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
//#region ../sdk/src/errors.ts
|
|
3
3
|
var QMindError = class extends Error {
|
|
4
|
-
access;
|
|
5
4
|
code;
|
|
6
5
|
details;
|
|
6
|
+
dataSourceAppPermission;
|
|
7
7
|
operation;
|
|
8
8
|
rawBody;
|
|
9
9
|
requestId;
|
|
@@ -12,9 +12,9 @@ var QMindError = class extends Error {
|
|
|
12
12
|
constructor(code, message, options = {}) {
|
|
13
13
|
super(message, { cause: options.cause });
|
|
14
14
|
this.name = "QMindError";
|
|
15
|
-
this.access = options.access;
|
|
16
15
|
this.code = code;
|
|
17
16
|
this.details = options.details;
|
|
17
|
+
this.dataSourceAppPermission = options.dataSourceAppPermission;
|
|
18
18
|
this.operation = options.operation;
|
|
19
19
|
this.rawBody = options.rawBody;
|
|
20
20
|
this.requestId = options.requestId;
|
|
@@ -23,218 +23,6 @@ var QMindError = class extends Error {
|
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
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
26
|
//#region ../sdk/src/imports.ts
|
|
239
27
|
const qmindFullSiteURLImportPageLimit = 2e3;
|
|
240
28
|
const runStatuses = Object.freeze({
|
|
@@ -298,10 +86,6 @@ function normalizeQMindAliDingImportNodeKind(value) {
|
|
|
298
86
|
function normalizeQMindAliDingImportScope(value) {
|
|
299
87
|
return scopes[value] ?? "nodeSubtree";
|
|
300
88
|
}
|
|
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
89
|
Object.freeze({
|
|
306
90
|
canceled: {
|
|
307
91
|
order: 2,
|
|
@@ -359,7 +143,7 @@ function normalizeQMindTaskRunStatus(status) {
|
|
|
359
143
|
}
|
|
360
144
|
//#endregion
|
|
361
145
|
//#region ../sdk/src/schemas.ts
|
|
362
|
-
function isRecord(value) {
|
|
146
|
+
function isRecord$1(value) {
|
|
363
147
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
364
148
|
}
|
|
365
149
|
const wirePageNumberSchema = z.number().int().nonnegative().optional();
|
|
@@ -448,7 +232,7 @@ const sourcePageInfoSchema = z.object({
|
|
|
448
232
|
prevPage: wirePageNumberSchema,
|
|
449
233
|
totalSize: z.number().int().nonnegative().optional()
|
|
450
234
|
});
|
|
451
|
-
const sourceExternalBindingSchema = z.preprocess((value) => isRecord(value) ? {
|
|
235
|
+
const sourceExternalBindingSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
452
236
|
...value,
|
|
453
237
|
bindingId: value.bindingId ?? value.binding_id,
|
|
454
238
|
isRoot: value.isRoot ?? value.is_root
|
|
@@ -457,7 +241,29 @@ const sourceExternalBindingSchema = z.preprocess((value) => isRecord(value) ? {
|
|
|
457
241
|
isRoot: z.boolean().default(false),
|
|
458
242
|
provider: z.string().default("")
|
|
459
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
|
+
});
|
|
253
|
+
const sourceLearningSchema = z.object({
|
|
254
|
+
status: z.string().default("unknown"),
|
|
255
|
+
errorCode: z.string().default(""),
|
|
256
|
+
engine: z.string().default(""),
|
|
257
|
+
phase: z.string().default("unknown"),
|
|
258
|
+
currentRevision: z.union([z.string(), z.number().int()]).transform(String).default("0"),
|
|
259
|
+
completedRevision: z.union([z.string(), z.number().int()]).transform(String).default("0"),
|
|
260
|
+
observedAt: timestampSchema.optional(),
|
|
261
|
+
nextObserveAt: timestampSchema.optional(),
|
|
262
|
+
engineObservedAt: timestampSchema.optional(),
|
|
263
|
+
retryMode: z.string().default("none")
|
|
264
|
+
});
|
|
460
265
|
const sourceSchema = z.object({
|
|
266
|
+
learning: sourceLearningSchema.optional(),
|
|
461
267
|
learningStatus: z.string().optional(),
|
|
462
268
|
learningErrorCode: z.string().optional(),
|
|
463
269
|
childrenCount: z.number().int().nonnegative().optional(),
|
|
@@ -465,6 +271,7 @@ const sourceSchema = z.object({
|
|
|
465
271
|
errorCode: z.string().default(""),
|
|
466
272
|
errorMessage: z.string().default(""),
|
|
467
273
|
externalBinding: sourceExternalBindingSchema.optional(),
|
|
274
|
+
dataSource: sourceDataSourceSchema.optional(),
|
|
468
275
|
filename: z.string().optional(),
|
|
469
276
|
hasChildren: z.boolean().optional(),
|
|
470
277
|
id: z.string().min(1),
|
|
@@ -492,32 +299,6 @@ const sourceListSchema = z.object({
|
|
|
492
299
|
sources: z.array(sourceSchema).nullish().transform((sources) => sources ?? []),
|
|
493
300
|
totalSize: z.number().int().nonnegative().optional()
|
|
494
301
|
});
|
|
495
|
-
const sourceTreeNodeSchema = z.lazy(() => z.preprocess((value) => isRecord(value) ? {
|
|
496
|
-
...value,
|
|
497
|
-
updatedAt: value.updatedAt ?? value.updated_at
|
|
498
|
-
} : value, z.object({
|
|
499
|
-
learningStatus: z.string().optional(),
|
|
500
|
-
learningErrorCode: z.string().optional(),
|
|
501
|
-
metadata: z.record(z.string(), z.unknown()).nullable().optional(),
|
|
502
|
-
externalBinding: sourceExternalBindingSchema.optional(),
|
|
503
|
-
originUrl: z.string().optional(),
|
|
504
|
-
isEmailFolder: z.boolean().optional(),
|
|
505
|
-
isEmailAggregateMember: z.boolean().optional(),
|
|
506
|
-
isExternalSource: z.boolean().optional(),
|
|
507
|
-
files: z.array(sourceTreeNodeSchema).default([]),
|
|
508
|
-
hasChildren: z.boolean().optional(),
|
|
509
|
-
id: z.string().min(1),
|
|
510
|
-
name: z.string().default(""),
|
|
511
|
-
path: z.string().default(""),
|
|
512
|
-
sourceType: z.string().default(""),
|
|
513
|
-
status: z.string().default(""),
|
|
514
|
-
type: z.enum(["file", "directory"]),
|
|
515
|
-
updatedAt: timestampSchema.optional()
|
|
516
|
-
})));
|
|
517
|
-
const sourceTreeSchema = z.object({
|
|
518
|
-
totalSize: z.number().int().nonnegative().default(0),
|
|
519
|
-
tree: z.array(sourceTreeNodeSchema)
|
|
520
|
-
});
|
|
521
302
|
const sourceContentSchema = z.object({
|
|
522
303
|
content: z.string(),
|
|
523
304
|
contentType: z.string().default("text/markdown"),
|
|
@@ -530,7 +311,7 @@ const wireInt64Schema = z.union([z.number(), z.string()]).nullish().transform((v
|
|
|
530
311
|
return Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : 0;
|
|
531
312
|
});
|
|
532
313
|
const sourceUploadExtensionSchema = z.string().regex(/^\.[a-z0-9]+$/);
|
|
533
|
-
const sourceUploadMethodSchema = z.preprocess((value) => isRecord(value) ? {
|
|
314
|
+
const sourceUploadMethodSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
534
315
|
...value,
|
|
535
316
|
maxSizeBytes: value.maxSizeBytes ?? value.max_size_bytes,
|
|
536
317
|
supportedExtensions: value.supportedExtensions ?? value.supported_extensions
|
|
@@ -540,7 +321,7 @@ const sourceUploadMethodSchema = z.preprocess((value) => isRecord(value) ? {
|
|
|
540
321
|
method: z.string().min(1),
|
|
541
322
|
supportedExtensions: z.array(sourceUploadExtensionSchema).default([])
|
|
542
323
|
}));
|
|
543
|
-
const sourceUploadFileTypeSchema = z.preprocess((value) => isRecord(value) ? {
|
|
324
|
+
const sourceUploadFileTypeSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
544
325
|
...value,
|
|
545
326
|
displayName: value.displayName ?? value.display_name,
|
|
546
327
|
mimeTypes: value.mimeTypes ?? value.mime_types,
|
|
@@ -559,7 +340,7 @@ const sourceQuotaSchema = z.object({
|
|
|
559
340
|
planTier: z.string().min(1),
|
|
560
341
|
quotaEnabled: z.boolean()
|
|
561
342
|
}).refine((value) => !value.quotaEnabled || value.limitBytes > 0);
|
|
562
|
-
const sourceUploadCapabilitiesSchema = z.preprocess((value) => isRecord(value) ? {
|
|
343
|
+
const sourceUploadCapabilitiesSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
563
344
|
...value,
|
|
564
345
|
fileTypes: value.fileTypes ?? value.file_types,
|
|
565
346
|
uploadMethods: value.uploadMethods ?? value.upload_methods
|
|
@@ -577,16 +358,16 @@ const downloadOriginalActionAccessSchema = z.discriminatedUnion("state", [z.obje
|
|
|
577
358
|
state: z.literal("denied")
|
|
578
359
|
})]);
|
|
579
360
|
const sourceActionAccessSchema = z.preprocess((value) => {
|
|
580
|
-
if (!isRecord(value) || !Array.isArray(value.actions)) return value;
|
|
361
|
+
if (!isRecord$1(value) || !Array.isArray(value.actions)) return value;
|
|
581
362
|
return {
|
|
582
363
|
...value,
|
|
583
364
|
actions: value.actions.filter((action) => {
|
|
584
|
-
if (!isRecord(action)) return true;
|
|
365
|
+
if (!isRecord$1(action)) return true;
|
|
585
366
|
return typeof action.action !== "string" || action.action.length === 0 || action.action === "download_original";
|
|
586
367
|
})
|
|
587
368
|
};
|
|
588
369
|
}, z.object({ actions: z.array(downloadOriginalActionAccessSchema).length(1) }));
|
|
589
|
-
const sourceRawContentSchema = z.preprocess((value) => isRecord(value) ? {
|
|
370
|
+
const sourceRawContentSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
590
371
|
...value,
|
|
591
372
|
contentType: value.contentType ?? value.content_type,
|
|
592
373
|
sizeBytes: value.sizeBytes ?? value.size_bytes,
|
|
@@ -599,7 +380,7 @@ const sourceRawContentSchema = z.preprocess((value) => isRecord(value) ? {
|
|
|
599
380
|
sourceFormat: z.string().default(""),
|
|
600
381
|
sourceId: z.string().default("")
|
|
601
382
|
}));
|
|
602
|
-
const sourcePreviewSchema = z.preprocess((value) => isRecord(value) ? {
|
|
383
|
+
const sourcePreviewSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
603
384
|
...value,
|
|
604
385
|
contentType: value.contentType ?? value.content_type,
|
|
605
386
|
expiresAt: value.expiresAt ?? value.expires_at,
|
|
@@ -621,7 +402,7 @@ const webOfficeTokenFields = {
|
|
|
621
402
|
tokenVersion: officeTokenIntegerSchema
|
|
622
403
|
};
|
|
623
404
|
function webOfficeTokenAliases(value) {
|
|
624
|
-
return isRecord(value) ? {
|
|
405
|
+
return isRecord$1(value) ? {
|
|
625
406
|
...value,
|
|
626
407
|
accessToken: value.accessToken ?? value.access_token,
|
|
627
408
|
accessTokenExpiresAt: value.accessTokenExpiresAt ?? value.access_token_expires_at,
|
|
@@ -631,7 +412,7 @@ function webOfficeTokenAliases(value) {
|
|
|
631
412
|
}
|
|
632
413
|
const sourceWebOfficeSessionSchema = z.preprocess((value) => {
|
|
633
414
|
const aliased = webOfficeTokenAliases(value);
|
|
634
|
-
return isRecord(aliased) ? {
|
|
415
|
+
return isRecord$1(aliased) ? {
|
|
635
416
|
...aliased,
|
|
636
417
|
readOnly: aliased.readOnly ?? aliased.readonly,
|
|
637
418
|
sessionId: aliased.sessionId ?? aliased.session_id,
|
|
@@ -649,7 +430,7 @@ const sourceWebOfficeSessionSchema = z.preprocess((value) => {
|
|
|
649
430
|
webOfficeUrl: httpsUrlSchema
|
|
650
431
|
}));
|
|
651
432
|
const sourceWebOfficeTokenSchema = z.preprocess(webOfficeTokenAliases, z.object(webOfficeTokenFields));
|
|
652
|
-
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) ? {
|
|
653
434
|
...value,
|
|
654
435
|
parentId: value.parentId ?? value.parent_id
|
|
655
436
|
} : value, z.object({
|
|
@@ -657,7 +438,7 @@ const sourceChildrenCountsSchema = z.object({ counts: z.array(z.preprocess((valu
|
|
|
657
438
|
parentId: z.string().default("")
|
|
658
439
|
}))).nullish().transform((counts) => counts ?? []) }).transform((value) => value.counts);
|
|
659
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));
|
|
660
|
-
const aliDingImportRunSchema = z.preprocess((value) => isRecord(value) ? {
|
|
441
|
+
const aliDingImportRunSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
661
442
|
...value,
|
|
662
443
|
bindingId: value.bindingId ?? value.binding_id,
|
|
663
444
|
canonicalUrl: value.canonicalUrl ?? value.canonical_url,
|
|
@@ -726,7 +507,7 @@ const aliDingImportRunSchema = z.preprocess((value) => isRecord(value) ? {
|
|
|
726
507
|
status: normalizeQMindAliDingImportRunStatus(value.status),
|
|
727
508
|
...value.updatedAt === void 0 ? {} : { updatedAt: value.updatedAt }
|
|
728
509
|
}));
|
|
729
|
-
const aliDingImportRunItemSchema = z.preprocess((value) => isRecord(value) ? {
|
|
510
|
+
const aliDingImportRunItemSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
730
511
|
...value,
|
|
731
512
|
contentStatus: value.contentStatus ?? value.content_status,
|
|
732
513
|
descendantsStatus: value.descendantsStatus ?? value.descendants_status,
|
|
@@ -768,7 +549,7 @@ const aliDingImportRunItemSchema = z.preprocess((value) => isRecord(value) ? {
|
|
|
768
549
|
status: normalizeQMindAliDingImportItemStatus(value.status),
|
|
769
550
|
...value.updatedAt === void 0 ? {} : { updatedAt: value.updatedAt }
|
|
770
551
|
}));
|
|
771
|
-
const aliDingImportPageInfoSchema = z.preprocess((value) => isRecord(value) ? {
|
|
552
|
+
const aliDingImportPageInfoSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
772
553
|
...value,
|
|
773
554
|
currentPage: value.currentPage ?? value.current_page,
|
|
774
555
|
lastPage: value.lastPage ?? value.last_page,
|
|
@@ -810,7 +591,7 @@ const imageUrlsSchema = z.object({
|
|
|
810
591
|
expiresAt: z.string().optional(),
|
|
811
592
|
urls: z.record(z.string(), httpsUrlSchema)
|
|
812
593
|
});
|
|
813
|
-
const notebookCitationSchema = z.preprocess((value) => isRecord(value) ? {
|
|
594
|
+
const notebookCitationSchema = z.preprocess((value) => isRecord$1(value) ? {
|
|
814
595
|
...value,
|
|
815
596
|
chunkId: value.chunkId ?? value.chunk_id,
|
|
816
597
|
chunkIndex: value.chunkIndex ?? value.chunk_index,
|
|
@@ -844,7 +625,7 @@ const chatMessageSchema = z.object({
|
|
|
844
625
|
updatedAt: timestampSchema.optional(),
|
|
845
626
|
userId: z.string().optional()
|
|
846
627
|
});
|
|
847
|
-
const streamChatMessageSchema = z.preprocess((value) => isRecord(value) && Array.isArray(value.citations) ? {
|
|
628
|
+
const streamChatMessageSchema = z.preprocess((value) => isRecord$1(value) && Array.isArray(value.citations) ? {
|
|
848
629
|
...value,
|
|
849
630
|
citations: value.citations.map((citation) => typeof citation === "string" ? { sourceId: citation } : citation)
|
|
850
631
|
} : value, chatMessageSchema);
|
|
@@ -994,6 +775,478 @@ const retrieveNotebooksResultSchema = z.object({
|
|
|
994
775
|
total: z.number().int().nonnegative().default(0)
|
|
995
776
|
});
|
|
996
777
|
//#endregion
|
|
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
|
|
997
1250
|
//#region ../sdk/src/operations/shared.ts
|
|
998
1251
|
function invalidArgument(message, field, details) {
|
|
999
1252
|
return new QMindError("INVALID_ARGUMENT", message, { details: details ?? { field } });
|
|
@@ -1052,7 +1305,8 @@ function stringList(value, field, options = {}) {
|
|
|
1052
1305
|
for (const item of value) {
|
|
1053
1306
|
if (typeof item !== "string") throw invalidArgument(`${field} must contain only strings`, field);
|
|
1054
1307
|
const normalized = item.trim();
|
|
1055
|
-
if (normalized.
|
|
1308
|
+
if (!normalized && !(options.keepEmptyString && item === "")) continue;
|
|
1309
|
+
if (seen.has(normalized)) continue;
|
|
1056
1310
|
seen.add(normalized);
|
|
1057
1311
|
result.push(normalized);
|
|
1058
1312
|
}
|
|
@@ -1094,6 +1348,10 @@ function wireRequest(options) {
|
|
|
1094
1348
|
const maxResponseBytes = options.callOptions?.maxResponseBytes;
|
|
1095
1349
|
if (maxResponseBytes !== void 0 && (!Number.isSafeInteger(maxResponseBytes) || maxResponseBytes <= 0)) throw invalidArgument("maxResponseBytes must be a positive integer", "maxResponseBytes");
|
|
1096
1350
|
const authorization = options.callOptions?.authorization?.trim();
|
|
1351
|
+
const headers = authorization ? {
|
|
1352
|
+
...options.headers,
|
|
1353
|
+
authorization: `Bearer ${authorization}`
|
|
1354
|
+
} : options.headers;
|
|
1097
1355
|
return {
|
|
1098
1356
|
...options.body === void 0 ? {} : { body: {
|
|
1099
1357
|
kind: "json",
|
|
@@ -1103,7 +1361,7 @@ function wireRequest(options) {
|
|
|
1103
1361
|
kind: "host",
|
|
1104
1362
|
path: options.path
|
|
1105
1363
|
},
|
|
1106
|
-
...
|
|
1364
|
+
...headers === void 0 ? {} : { headers },
|
|
1107
1365
|
idempotent: options.idempotent,
|
|
1108
1366
|
method: options.method,
|
|
1109
1367
|
...options.callOptions?.signal === void 0 ? {} : { signal: options.callOptions.signal },
|
|
@@ -1115,11 +1373,11 @@ function call(context, options) {
|
|
|
1115
1373
|
return executeUnary({
|
|
1116
1374
|
capability: options.capability,
|
|
1117
1375
|
operation: options.operation,
|
|
1118
|
-
|
|
1376
|
+
capabilities: context.capabilities,
|
|
1119
1377
|
request: wireRequest(options),
|
|
1120
1378
|
schema: options.schema,
|
|
1121
1379
|
transport: context.transport
|
|
1122
1380
|
});
|
|
1123
1381
|
}
|
|
1124
1382
|
//#endregion
|
|
1125
|
-
export {
|
|
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 };
|