@qoder-ai/qmind-cli 3.3.0 → 3.5.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.
@@ -236,6 +236,7 @@ async function* executeStream(options) {
236
236
  }
237
237
  //#endregion
238
238
  //#region ../sdk/src/imports.ts
239
+ const qmindFullSiteURLImportPageLimit = 2e3;
239
240
  const runStatuses = Object.freeze({
240
241
  ALI_DING_IMPORT_RUN_STATUS_FAILED: "failed",
241
242
  ALI_DING_IMPORT_RUN_STATUS_PARTIAL: "partial",
@@ -373,7 +374,7 @@ const timestampPartsSchema = z.object({
373
374
  });
374
375
  const timestampSchema = z.union([z.iso.datetime({ offset: true }), timestampPartsSchema]).nullable().transform((value, context) => {
375
376
  if (value === null) return null;
376
- const milliseconds = typeof value === "string" ? Date.parse(value) : Number(value.seconds) * 1e3 + (value.nanos ?? 0) / 1e6;
377
+ const milliseconds = typeof value === "string" ? Date.parse(value) : Number(value.seconds) * 1e3 + Math.floor((value.nanos ?? 0) / 1e6);
377
378
  const date = new Date(milliseconds);
378
379
  if (!Number.isFinite(milliseconds) || Number.isNaN(date.valueOf())) {
379
380
  context.addIssue({
@@ -382,7 +383,8 @@ const timestampSchema = z.union([z.iso.datetime({ offset: true }), timestampPart
382
383
  });
383
384
  return z.NEVER;
384
385
  }
385
- return date.toISOString();
386
+ const canonicalFraction = (typeof value === "string" ? value.match(/\.(\d+)(?:Z|[+-]\d{2}:\d{2})$/u)?.[1] ?? "" : String(value.nanos ?? 0).padStart(9, "0")).replace(/0+$/u, "").padEnd(3, "0");
387
+ return date.toISOString().replace(/\.\d{3}Z$/u, `.${canonicalFraction}Z`);
386
388
  });
387
389
  const notebookOverviewSchema = z.object({
388
390
  status: z.string().default("empty"),
@@ -395,12 +397,13 @@ const notebookMaintenanceSchema = z.object({
395
397
  status: z.string().default("idle")
396
398
  });
397
399
  const notebookAccessInfoSchema = z.object({
400
+ canRenameNotebook: z.boolean().optional(),
398
401
  canDeleteNotebook: z.boolean(),
399
402
  canEdit: z.boolean(),
400
403
  canManageMembers: z.boolean(),
401
404
  canManageTasks: z.boolean(),
402
405
  currentUserPermission: z.string(),
403
- memberCount: z.number().int().nonnegative()
406
+ memberCount: z.number().int().nonnegative().optional()
404
407
  });
405
408
  const notebookSchema = z.object({
406
409
  access: notebookAccessInfoSchema.nullable().optional(),
@@ -434,85 +437,6 @@ const sharedNotebookListSchema = z.object({
434
437
  pageSize: wirePageNumberSchema,
435
438
  totalSize: z.number().int().nonnegative().default(0)
436
439
  });
437
- const wikiDocumentSchema = z.preprocess((value) => isRecord(value) ? {
438
- ...value,
439
- contentHash: value.contentHash ?? value.content_hash,
440
- contentUrl: value.contentUrl ?? value.content_url
441
- } : value, z.object({
442
- contentHash: z.string().default(""),
443
- contentUrl: z.string().min(1),
444
- language: z.string().default("")
445
- }));
446
- const wikiBranchSchema = z.preprocess((value) => isRecord(value) ? {
447
- ...value,
448
- commitTimestamp: value.commitTimestamp ?? value.commit_timestamp,
449
- knowledgeCount: value.knowledgeCount ?? value.knowledge_count,
450
- repoUrl: value.repoUrl ?? value.repo_url,
451
- resultVersion: value.resultVersion ?? value.result_version,
452
- updatedAt: value.updatedAt ?? value.updated_at
453
- } : value, z.object({
454
- branch: z.string().min(1),
455
- commitTimestamp: z.number().optional(),
456
- documents: z.array(wikiDocumentSchema).nullish().transform((documents) => documents ?? []),
457
- exists: z.boolean().optional(),
458
- knowledgeCount: z.number().int().nonnegative().default(0),
459
- repo: z.string().min(1),
460
- repoUrl: z.string().optional(),
461
- resultVersion: z.string().default(""),
462
- updatedAt: timestampSchema.optional()
463
- }));
464
- const wikiBranchListSchema = z.object({ branches: z.array(wikiBranchSchema).nullish().transform((branches) => branches ?? []) });
465
- const cardLinkSchema = z.object({
466
- description: z.string().optional(),
467
- linkType: z.string().default(""),
468
- targetId: z.string().min(1),
469
- targetTitle: z.string().optional()
470
- });
471
- const cardSchema = z.object({
472
- branch: z.string().optional(),
473
- cardType: z.string().optional(),
474
- category: z.string().optional(),
475
- content: z.string().default(""),
476
- createdAt: timestampSchema.optional(),
477
- extra: z.string().optional(),
478
- id: z.string().min(1),
479
- keywords: z.array(z.string()).default([]),
480
- knowledgeId: z.string().optional(),
481
- language: z.string().optional(),
482
- links: z.array(cardLinkSchema).default([]),
483
- notebookId: z.string().optional(),
484
- orgId: z.string().optional(),
485
- repo: z.string().optional(),
486
- score: z.number().optional(),
487
- source: z.string().optional(),
488
- title: z.string().default(""),
489
- updatedAt: timestampSchema.optional()
490
- });
491
- const cardCategoryCountSchema = z.object({
492
- category: z.string(),
493
- count: z.number().int().nonnegative()
494
- });
495
- const cardLanguageCountSchema = z.object({
496
- count: z.number().int().nonnegative(),
497
- language: z.string()
498
- });
499
- const cardAppliedFiltersSchema = z.object({
500
- branch: z.string().optional(),
501
- category: z.string().optional(),
502
- language: z.string().optional(),
503
- query: z.string().optional(),
504
- repo: z.string().optional(),
505
- source: z.string().optional()
506
- });
507
- const cardListSchema = z.object({
508
- appliedFilters: cardAppliedFiltersSchema.optional(),
509
- cards: z.array(cardSchema).nullish().transform((cards) => cards ?? []),
510
- categoryCounts: z.array(cardCategoryCountSchema).nullish().transform((counts) => counts ?? []),
511
- currentPage: wirePageNumberSchema,
512
- languageCounts: z.array(cardLanguageCountSchema).nullish().transform((counts) => counts ?? []),
513
- pageSize: wirePageNumberSchema,
514
- totalSize: z.number().int().nonnegative().default(0)
515
- });
516
440
  const sourcePageInfoSchema = z.object({
517
441
  currentPage: wirePageNumberSchema,
518
442
  lastPage: wirePageNumberSchema,
@@ -532,6 +456,8 @@ const sourceExternalBindingSchema = z.preprocess((value) => isRecord(value) ? {
532
456
  provider: z.string().default("")
533
457
  }));
534
458
  const sourceSchema = z.object({
459
+ learningStatus: z.string().optional(),
460
+ learningErrorCode: z.string().optional(),
535
461
  childrenCount: z.number().int().nonnegative().optional(),
536
462
  createdAt: timestampSchema.optional(),
537
463
  errorCode: z.string().default(""),
@@ -564,7 +490,13 @@ const sourceListSchema = z.object({
564
490
  sources: z.array(sourceSchema).nullish().transform((sources) => sources ?? []),
565
491
  totalSize: z.number().int().nonnegative().optional()
566
492
  });
567
- const sourceTreeNodeSchema = z.lazy(() => z.object({
493
+ const sourceTreeNodeSchema = z.lazy(() => z.preprocess((value) => isRecord(value) ? {
494
+ ...value,
495
+ updatedAt: value.updatedAt ?? value.updated_at
496
+ } : value, z.object({
497
+ learningStatus: z.string().optional(),
498
+ learningErrorCode: z.string().optional(),
499
+ metadata: z.record(z.string(), z.unknown()).nullable().optional(),
568
500
  externalBinding: sourceExternalBindingSchema.optional(),
569
501
  originUrl: z.string().optional(),
570
502
  isEmailFolder: z.boolean().optional(),
@@ -577,8 +509,9 @@ const sourceTreeNodeSchema = z.lazy(() => z.object({
577
509
  path: z.string().default(""),
578
510
  sourceType: z.string().default(""),
579
511
  status: z.string().default(""),
580
- type: z.enum(["file", "directory"])
581
- }));
512
+ type: z.enum(["file", "directory"]),
513
+ updatedAt: timestampSchema.optional()
514
+ })));
582
515
  const sourceTreeSchema = z.object({
583
516
  totalSize: z.number().int().nonnegative().default(0),
584
517
  tree: z.array(sourceTreeNodeSchema)
@@ -618,6 +551,12 @@ const sourceUploadFileTypeSchema = z.preprocess((value) => isRecord(value) ? {
618
551
  sourceType: z.string().min(1),
619
552
  uploadMethods: z.array(z.string().min(1)).default([])
620
553
  }));
554
+ const sourceQuotaSchema = z.object({
555
+ usedBytes: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
556
+ limitBytes: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
557
+ planTier: z.string().min(1),
558
+ quotaEnabled: z.boolean()
559
+ }).refine((value) => !value.quotaEnabled || value.limitBytes > 0);
621
560
  const sourceUploadCapabilitiesSchema = z.preprocess((value) => isRecord(value) ? {
622
561
  ...value,
623
562
  fileTypes: value.fileTypes ?? value.file_types,
@@ -853,9 +792,9 @@ const sourceImportResultSchema = z.object({
853
792
  url: z.string().default("")
854
793
  });
855
794
  const sourceImportResultsSchema = z.object({ results: z.array(sourceImportResultSchema) }).transform((value) => value.results);
856
- const batchMutationResultSchema = z.object({
857
- failureCount: z.number().int().nonnegative().default(0),
858
- successCount: z.number().int().nonnegative().default(0)
795
+ const batchDeleteResultSchema = z.object({
796
+ failureCount: z.number().int().nonnegative(),
797
+ successCount: z.number().int().nonnegative()
859
798
  });
860
799
  const voidResponseSchema = z.unknown().transform(() => void 0);
861
800
  const imageUploadTicketSchema = z.object({
@@ -975,25 +914,7 @@ const notebookContextChunkSchema = z.object({
975
914
  sourceUri: z.string().default(""),
976
915
  tokenCount: z.number().int().nonnegative().default(0)
977
916
  });
978
- const retrievedCardLinkSchema = z.object({
979
- description: z.string().optional(),
980
- linkType: z.string().default(""),
981
- targetId: z.string().min(1),
982
- targetTitle: z.string().optional()
983
- });
984
- const retrievedCardSchema = z.object({
985
- cardType: z.string().optional(),
986
- category: z.string().optional(),
987
- content: z.string().default(""),
988
- depth: z.number().int().nonnegative().default(0),
989
- id: z.string().min(1),
990
- keywords: z.array(z.string()).default([]),
991
- links: z.array(retrievedCardLinkSchema).default([]),
992
- score: z.number().finite().default(0),
993
- title: z.string().default("")
994
- });
995
917
  const retrieveResultSchema = z.object({
996
- cards: z.array(retrievedCardSchema).default([]),
997
918
  chunks: z.array(notebookContextChunkSchema).default([]),
998
919
  citations: z.array(notebookCitationSchema).default([]),
999
920
  promptContext: z.string().default(""),
@@ -1029,12 +950,47 @@ const taskRunSchema = z.object({
1029
950
  rawStatus: value.status,
1030
951
  status: normalizeQMindTaskRunStatus(value.status)
1031
952
  }));
953
+ const fullSiteURLImportDiscoverySchema = z.object({
954
+ discoveredCount: z.number().int().nonnegative(),
955
+ discoveryId: z.string().min(1),
956
+ droppedCount: z.number().int().nonnegative(),
957
+ entryUrl: z.string().url(),
958
+ expiresAt: timestampSchema,
959
+ indexCount: z.number().int().nonnegative(),
960
+ manifest: z.object({
961
+ kind: z.enum(["llms", "sitemap"]),
962
+ url: z.string().url()
963
+ }),
964
+ pages: z.array(z.object({
965
+ id: z.string().min(1),
966
+ url: z.string().url()
967
+ })).nullish().transform((pages) => pages ?? []),
968
+ returnedCount: z.number().int().nonnegative(),
969
+ truncated: z.boolean()
970
+ });
971
+ const fullSiteURLImportConfirmationSchema = z.object({
972
+ rootSource: sourceSchema,
973
+ taskRun: taskRunSchema
974
+ });
1032
975
  const taskRunListSchema = z.object({
1033
976
  currentPage: wirePageNumberSchema,
1034
977
  pageSize: wirePageNumberSchema,
1035
978
  runs: z.array(taskRunSchema).nullish().transform((runs) => runs ?? []),
1036
979
  totalSize: z.number().int().nonnegative().default(0)
1037
980
  });
981
+ const retrieveNotebooksResultSchema = z.object({
982
+ chunks: z.array(z.intersection(notebookContextChunkSchema, z.object({
983
+ notebookId: z.string().min(1),
984
+ notebookTitle: z.string()
985
+ }))).default([]),
986
+ citations: z.array(z.intersection(notebookCitationSchema, z.object({
987
+ notebookId: z.string().min(1),
988
+ notebookTitle: z.string()
989
+ }))).default([]),
990
+ promptContext: z.string().default(""),
991
+ reranked: z.boolean().default(false),
992
+ total: z.number().int().nonnegative().default(0)
993
+ });
1038
994
  //#endregion
1039
995
  //#region ../sdk/src/operations/shared.ts
1040
996
  function invalidArgument(message, field, details) {
@@ -1164,4 +1120,4 @@ function call(context, options) {
1164
1120
  });
1165
1121
  }
1166
1122
  //#endregion
1167
- export { QMIND_SOURCE_UPLOAD_MAX_BYTES as $, notebookSchema as A, sourceSchema as B, chatMessageListSchema as C, imageUrlsSchema as D, imageUploadTicketSchema as E, sourceContentSchema as F, sourceWebOfficeTokenSchema as G, sourceUploadCapabilitiesSchema as H, sourceImportResultsSchema as I, taskRunSchema as J, streamWireEventSchema as K, sourceListSchema as L, sharedNotebookListSchema as M, sourceActionAccessSchema as N, importProvidersSchema as O, sourceChildrenCountsSchema as P, QMIND_MULTIPART_UPLOAD_MAX_BYTES as Q, sourcePreviewSchema as R, cardSchema as S, chatSessionSchema as T, sourceUploadTicketSchema as U, sourceTreeSchema as V, sourceWebOfficeSessionSchema as W, voidResponseSchema as X, timestampSchema as Y, wikiBranchListSchema as Z, aliDingImportRunItemListSchema as _, invalidArgument as a, cancelQuestionResultSchema as b, optionalRecord as c, pagination as d, assertCapability as et, positiveInteger as f, stringList as g, requiredText as h, httpUrl as i, retrieveResultSchema as j, notebookListSchema as k, optionalString as l, requiredString as m, call as n, executeUnary as nt, nonNegativeInteger as o, queryPath as p, taskRunListSchema as q, compactUndefined as r, QMindError as rt, optionalBoolean as s, assertNonEmptyPatch as t, executeStream as tt, optionalTrimmedString as u, aliDingImportRunSchema as v, chatSessionListSchema as w, cardListSchema as x, batchMutationResultSchema as y, sourceRawContentSchema as z };
1123
+ export { QMIND_MULTIPART_UPLOAD_MAX_BYTES as $, notebookSchema as A, sourceQuotaSchema as B, chatSessionSchema as C, imageUrlsSchema as D, imageUploadTicketSchema as E, sourceChildrenCountsSchema as F, sourceUploadTicketSchema as G, sourceSchema as H, sourceContentSchema as I, streamWireEventSchema as J, sourceWebOfficeSessionSchema as K, sourceImportResultsSchema as L, retrieveResultSchema as M, sharedNotebookListSchema as N, importProvidersSchema as O, sourceActionAccessSchema as P, voidResponseSchema as Q, sourceListSchema as R, chatSessionListSchema as S, fullSiteURLImportDiscoverySchema as T, sourceTreeSchema as U, sourceRawContentSchema as V, sourceUploadCapabilitiesSchema as W, taskRunSchema as X, taskRunListSchema as Y, timestampSchema as Z, aliDingImportRunItemListSchema as _, invalidArgument as a, QMindError as at, cancelQuestionResultSchema as b, optionalRecord as c, pagination as d, QMIND_SOURCE_UPLOAD_MAX_BYTES as et, positiveInteger as f, stringList as g, requiredText as h, httpUrl as i, executeUnary as it, retrieveNotebooksResultSchema as j, notebookListSchema as k, optionalString as l, requiredString as m, call as n, assertCapability as nt, nonNegativeInteger as o, queryPath as p, sourceWebOfficeTokenSchema as q, compactUndefined as r, executeStream as rt, optionalBoolean as s, assertNonEmptyPatch as t, qmindFullSiteURLImportPageLimit as tt, optionalTrimmedString as u, aliDingImportRunSchema as v, fullSiteURLImportConfirmationSchema as w, chatMessageListSchema as x, batchDeleteResultSchema as y, sourcePreviewSchema as z };
@@ -1,4 +1,4 @@
1
- import { H as sourceUploadCapabilitiesSchema, m as requiredString, n as call } from "./shared-BFU7amCH.js";
1
+ import { W as sourceUploadCapabilitiesSchema, m as requiredString, n as call } from "./shared-DsqZroGJ.js";
2
2
  //#region ../sdk/src/operations/source-upload.ts
3
3
  /** Notebook-scoped edit preflight, not the deployment-level capabilities lookup. */
4
4
  async function preflightSourceUpload(context, notebookId, options) {
@@ -1,5 +1,5 @@
1
- import { $ as QMIND_SOURCE_UPLOAD_MAX_BYTES, B as sourceSchema, E as imageUploadTicketSchema, Q as QMIND_MULTIPART_UPLOAD_MAX_BYTES, U as sourceUploadTicketSchema, X as voidResponseSchema, a as invalidArgument, l as optionalString, m as requiredString, nt as executeUnary, p as queryPath, r as compactUndefined, rt as QMindError, u as optionalTrimmedString } from "./shared-BFU7amCH.js";
2
- import { t as preflightSourceUpload } from "./source-upload-D3rcA1v1.js";
1
+ import { $ as QMIND_MULTIPART_UPLOAD_MAX_BYTES, E as imageUploadTicketSchema, G as sourceUploadTicketSchema, H as sourceSchema, Q as voidResponseSchema, a as invalidArgument, at as QMindError, et as QMIND_SOURCE_UPLOAD_MAX_BYTES, it as executeUnary, l as optionalString, m as requiredString, p as queryPath, r as compactUndefined, u as optionalTrimmedString } from "./shared-DsqZroGJ.js";
2
+ import { t as preflightSourceUpload } from "./source-upload-DdZ0J4gC.js";
3
3
  //#region ../sdk/src/operations/transfers.ts
4
4
  function isRecord(value) {
5
5
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -0,0 +1,80 @@
1
+ import { Z as timestampSchema, a as invalidArgument, d as pagination, m as requiredString, n as call, p as queryPath, u as optionalTrimmedString } from "./shared-DsqZroGJ.js";
2
+ import { z } from "zod";
3
+ //#region ../sdk/src/operations/wiki-branches.ts
4
+ function isRecord(value) {
5
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6
+ }
7
+ const wikiDocumentSchema = z.preprocess((value) => isRecord(value) ? {
8
+ ...value,
9
+ contentHash: value.contentHash ?? value.content_hash,
10
+ contentUrl: value.contentUrl ?? value.content_url
11
+ } : value, z.object({
12
+ contentHash: z.string().default(""),
13
+ contentUrl: z.string().min(1),
14
+ language: z.string().default("")
15
+ }));
16
+ const wikiBranchSchema = z.preprocess((value) => isRecord(value) ? {
17
+ ...value,
18
+ commitTimestamp: value.commitTimestamp ?? value.commit_timestamp,
19
+ knowledgeCount: value.knowledgeCount ?? value.knowledge_count,
20
+ repoUrl: value.repoUrl ?? value.repo_url,
21
+ resultVersion: value.resultVersion ?? value.result_version,
22
+ updatedAt: value.updatedAt ?? value.updated_at
23
+ } : value, z.object({
24
+ branch: z.string().min(1),
25
+ commitTimestamp: z.number().optional(),
26
+ documents: z.array(wikiDocumentSchema).nullish().transform((documents) => documents ?? []),
27
+ exists: z.boolean().optional(),
28
+ imported: z.boolean().optional(),
29
+ knowledgeCount: z.number().int().nonnegative().default(0),
30
+ repo: z.string().min(1),
31
+ repoUrl: z.string().optional(),
32
+ resultVersion: z.string().default(""),
33
+ updatedAt: timestampSchema.optional()
34
+ }));
35
+ const wikiBranchListSchema = z.object({ branches: z.array(wikiBranchSchema).nullish().transform((branches) => branches ?? []) });
36
+ const wikiBranchPageSchema = z.object({
37
+ branches: z.array(wikiBranchSchema).nullable().transform((branches) => branches ?? []),
38
+ currentPage: z.number().int().positive(),
39
+ pageSize: z.number().int().positive().max(50),
40
+ totalSize: z.number().int().nonnegative()
41
+ });
42
+ /** Loaded only when RepoWiki discovery is requested, keeping Notebook startup small. */
43
+ function createWikiBranchOperations(context) {
44
+ return {
45
+ async listWikiBranches(notebookId, options) {
46
+ const id = requiredString(notebookId, "notebookId");
47
+ return (await call(context, {
48
+ callOptions: options,
49
+ capability: "wikiBranches.read",
50
+ idempotent: true,
51
+ method: "GET",
52
+ operation: "wikiBranches.list",
53
+ path: context.profile.wikiBranchesPath(id),
54
+ schema: wikiBranchListSchema
55
+ })).branches;
56
+ },
57
+ async listWikiBranchesPage(notebookId, input = {}, options) {
58
+ const id = requiredString(notebookId, "notebookId");
59
+ const { page = 1, pageSize = 20 } = pagination(input);
60
+ if (!Number.isSafeInteger(page)) throw invalidArgument("page is too large", "page");
61
+ const query = optionalTrimmedString(input.query, "query");
62
+ if (query && [...query].length > 256) throw invalidArgument("query must be at most 256 characters", "query");
63
+ return call(context, {
64
+ callOptions: options,
65
+ capability: "wikiBranches.page",
66
+ idempotent: true,
67
+ method: "GET",
68
+ operation: "wikiBranches.listPage",
69
+ path: queryPath(context.profile.wikiBranchesPath(id), [
70
+ ["page", page],
71
+ ["page_size", Math.min(pageSize, 50)],
72
+ ["query", query]
73
+ ]),
74
+ schema: wikiBranchPageSchema
75
+ });
76
+ }
77
+ };
78
+ }
79
+ //#endregion
80
+ export { createWikiBranchOperations };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qoder-ai/qmind-cli",
3
- "version": "3.3.0",
3
+ "version": "3.5.0",
4
4
  "description": "QMind command line interface",
5
5
  "bin": {
6
6
  "qmind": "bin/cli.js"
@@ -39,8 +39,8 @@
39
39
  "@types/picomatch": "4.0.3",
40
40
  "@types/proper-lockfile": "4.1.4",
41
41
  "@types/semver": "7.8.0",
42
- "@ali/qmind-node-host": "^2.3.4",
43
- "@ali/qmind-sdk": "^0.19.0"
42
+ "@ali/qmind-node-host": "^2.5.3",
43
+ "@ali/qmind-sdk": "^0.29.0"
44
44
  },
45
45
  "license": "UNLICENSED"
46
46
  }
@@ -1,132 +0,0 @@
1
- import { S as cardSchema, a as invalidArgument, c as optionalRecord, d as pagination, g as stringList, h as requiredText, l as optionalString, m as requiredString, n as call, p as queryPath, r as compactUndefined, u as optionalTrimmedString, x as cardListSchema, y as batchMutationResultSchema } from "./shared-BFU7amCH.js";
2
- import { z } from "zod";
3
- //#region ../sdk/src/operations/compilation-results.ts
4
- function linksBody(value, field) {
5
- if (value === void 0) return void 0;
6
- if (!Array.isArray(value)) throw invalidArgument(`${field} must be an array`, field);
7
- return value.map((value, index) => {
8
- const name = `${field}[${index}]`;
9
- const link = optionalRecord(value, name);
10
- const targetId = optionalTrimmedString(link?.targetId, `${name}.targetId`);
11
- const targetRef = optionalTrimmedString(link?.targetRef, `${name}.targetRef`);
12
- if (targetId === void 0 && targetRef === void 0) throw invalidArgument(`${name} requires targetId or targetRef`, name);
13
- return compactUndefined({
14
- description: optionalString(link?.description, `${name}.description`),
15
- linkType: optionalTrimmedString(link?.linkType, `${name}.linkType`),
16
- targetId,
17
- targetRef
18
- });
19
- });
20
- }
21
- function compilationResultBody(value) {
22
- if (!Array.isArray(value) || value.length === 0) throw invalidArgument("cards must be a non-empty array", "cards");
23
- return { cards: value.map((value, index) => {
24
- const name = `cards[${index}]`;
25
- const card = optionalRecord(value, name);
26
- return compactUndefined({
27
- cardType: optionalTrimmedString(card?.cardType, `${name}.cardType`),
28
- content: requiredText(card?.content, `${name}.content`),
29
- id: optionalTrimmedString(card?.id, `${name}.id`),
30
- keywords: card?.keywords === void 0 ? void 0 : stringList(card.keywords, `${name}.keywords`),
31
- links: linksBody(card?.links, `${name}.links`),
32
- refId: optionalTrimmedString(card?.refId, `${name}.refId`),
33
- title: requiredString(card?.title, `${name}.title`)
34
- });
35
- }) };
36
- }
37
- const saveCompilationResultSchema = z.object({
38
- cards: z.array(z.object({
39
- id: z.string().min(1),
40
- refId: z.string().optional()
41
- })).nullish().transform((cards) => cards ?? []),
42
- failureCount: z.number().int().nonnegative(),
43
- successCount: z.number().int().nonnegative()
44
- });
45
- //#endregion
46
- //#region ../sdk/src/operations/cards.ts
47
- function createCardOperations(context) {
48
- const listCards = async (notebookId, input = {}, options, featured = false) => {
49
- const notebook = requiredString(notebookId, "notebookId");
50
- const normalizedPage = pagination({
51
- page: input.page ?? 1,
52
- pageSize: input.pageSize ?? 20
53
- });
54
- const category = optionalTrimmedString(input.category, "category");
55
- const query = optionalTrimmedString(input.query, "query");
56
- const root = context.profile.apiPath(featured ? "featured-notebooks" : "notebooks", notebook, "cards");
57
- const path = queryPath(root, [
58
- ["category", category],
59
- ["query", query],
60
- ["page", normalizedPage.page],
61
- ["page_size", normalizedPage.pageSize]
62
- ]);
63
- return call(context, {
64
- callOptions: options,
65
- capability: featured ? "featuredNotebooks.read" : "cards.read",
66
- idempotent: true,
67
- method: "GET",
68
- operation: featured ? "featuredCards.list" : "cards.list",
69
- path,
70
- schema: cardListSchema
71
- });
72
- };
73
- return {
74
- async saveCompilationResult(notebookId, input, options) {
75
- const notebook = requiredString(notebookId, "notebookId");
76
- return call(context, {
77
- body: compilationResultBody(input?.cards),
78
- callOptions: options,
79
- capability: "cards.saveResults",
80
- idempotent: false,
81
- method: "POST",
82
- operation: "cards.saveCompilationResult",
83
- path: context.profile.apiPath("notebooks", notebook, "cards", "save-compilation-result"),
84
- schema: saveCompilationResultSchema
85
- });
86
- },
87
- async batchDeleteCards(notebookId, cardIds, options) {
88
- const notebook = requiredString(notebookId, "notebookId");
89
- const ids = stringList(cardIds, "cardIds", { min: 1 });
90
- return call(context, {
91
- body: { cardIds: ids },
92
- callOptions: options,
93
- capability: "cards.write",
94
- idempotent: false,
95
- method: "POST",
96
- operation: "cards.batchDelete",
97
- path: context.profile.apiPath("notebooks", notebook, "cards", "batch-delete"),
98
- schema: batchMutationResultSchema
99
- });
100
- },
101
- async deleteCard(notebookId, cardId, options) {
102
- const notebook = requiredString(notebookId, "notebookId");
103
- const card = requiredString(cardId, "cardId");
104
- return call(context, {
105
- callOptions: options,
106
- capability: "cards.write",
107
- idempotent: false,
108
- method: "DELETE",
109
- operation: "cards.delete",
110
- path: context.profile.apiPath("notebooks", notebook, "cards", card),
111
- schema: batchMutationResultSchema
112
- });
113
- },
114
- async getCard(notebookId, cardId, options) {
115
- const notebook = requiredString(notebookId, "notebookId");
116
- const card = requiredString(cardId, "cardId");
117
- return call(context, {
118
- callOptions: options,
119
- capability: "cards.read",
120
- idempotent: true,
121
- method: "GET",
122
- operation: "cards.get",
123
- path: context.profile.apiPath("notebooks", notebook, "cards", card),
124
- schema: cardSchema
125
- });
126
- },
127
- listCards: (notebookId, input, options) => listCards(notebookId, input, options),
128
- listFeaturedCards: (notebookId, input, options) => listCards(notebookId, input, options, true)
129
- };
130
- }
131
- //#endregion
132
- export { createCardOperations };