@qoder-ai/qmind-cli 3.4.0 → 4.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.
@@ -397,12 +397,13 @@ const notebookMaintenanceSchema = z.object({
397
397
  status: z.string().default("idle")
398
398
  });
399
399
  const notebookAccessInfoSchema = z.object({
400
+ canRenameNotebook: z.boolean().optional(),
400
401
  canDeleteNotebook: z.boolean(),
401
402
  canEdit: z.boolean(),
402
403
  canManageMembers: z.boolean(),
403
404
  canManageTasks: z.boolean(),
404
405
  currentUserPermission: z.string(),
405
- memberCount: z.number().int().nonnegative()
406
+ memberCount: z.number().int().nonnegative().optional()
406
407
  });
407
408
  const notebookSchema = z.object({
408
409
  access: notebookAccessInfoSchema.nullable().optional(),
@@ -422,12 +423,14 @@ const notebookSchema = z.object({
422
423
  userId: z.string().default("")
423
424
  });
424
425
  const notebookListSchema = z.object({
426
+ retrievalEligibleOnlyApplied: z.boolean().optional(),
425
427
  currentPage: wirePageNumberSchema,
426
428
  notebooks: z.array(notebookSchema).nullish().transform((notebooks) => notebooks ?? []),
427
429
  pageSize: wirePageNumberSchema,
428
430
  totalSize: z.number().int().nonnegative().default(0)
429
431
  });
430
432
  const sharedNotebookListSchema = z.object({
433
+ retrievalEligibleOnlyApplied: z.boolean().optional(),
431
434
  currentPage: wirePageNumberSchema,
432
435
  notebooks: z.array(z.object({
433
436
  notebook: notebookSchema,
@@ -436,57 +439,6 @@ const sharedNotebookListSchema = z.object({
436
439
  pageSize: wirePageNumberSchema,
437
440
  totalSize: z.number().int().nonnegative().default(0)
438
441
  });
439
- const cardLinkSchema = z.object({
440
- description: z.string().optional(),
441
- linkType: z.string().default(""),
442
- targetId: z.string().min(1),
443
- targetTitle: z.string().optional()
444
- });
445
- const cardSchema = z.object({
446
- branch: z.string().optional(),
447
- cardType: z.string().optional(),
448
- category: z.string().optional(),
449
- content: z.string().default(""),
450
- createdAt: timestampSchema.optional(),
451
- extra: z.string().optional(),
452
- id: z.string().min(1),
453
- keywords: z.array(z.string()).default([]),
454
- knowledgeId: z.string().optional(),
455
- language: z.string().optional(),
456
- links: z.array(cardLinkSchema).default([]),
457
- notebookId: z.string().optional(),
458
- orgId: z.string().optional(),
459
- repo: z.string().optional(),
460
- score: z.number().optional(),
461
- source: z.string().optional(),
462
- title: z.string().default(""),
463
- updatedAt: timestampSchema.optional()
464
- });
465
- const cardCategoryCountSchema = z.object({
466
- category: z.string(),
467
- count: z.number().int().nonnegative()
468
- });
469
- const cardLanguageCountSchema = z.object({
470
- count: z.number().int().nonnegative(),
471
- language: z.string()
472
- });
473
- const cardAppliedFiltersSchema = z.object({
474
- branch: z.string().optional(),
475
- category: z.string().optional(),
476
- language: z.string().optional(),
477
- query: z.string().optional(),
478
- repo: z.string().optional(),
479
- source: z.string().optional()
480
- });
481
- const cardListSchema = z.object({
482
- appliedFilters: cardAppliedFiltersSchema.optional(),
483
- cards: z.array(cardSchema).nullish().transform((cards) => cards ?? []),
484
- categoryCounts: z.array(cardCategoryCountSchema).nullish().transform((counts) => counts ?? []),
485
- currentPage: wirePageNumberSchema,
486
- languageCounts: z.array(cardLanguageCountSchema).nullish().transform((counts) => counts ?? []),
487
- pageSize: wirePageNumberSchema,
488
- totalSize: z.number().int().nonnegative().default(0)
489
- });
490
442
  const sourcePageInfoSchema = z.object({
491
443
  currentPage: wirePageNumberSchema,
492
444
  lastPage: wirePageNumberSchema,
@@ -506,6 +458,8 @@ const sourceExternalBindingSchema = z.preprocess((value) => isRecord(value) ? {
506
458
  provider: z.string().default("")
507
459
  }));
508
460
  const sourceSchema = z.object({
461
+ learningStatus: z.string().optional(),
462
+ learningErrorCode: z.string().optional(),
509
463
  childrenCount: z.number().int().nonnegative().optional(),
510
464
  createdAt: timestampSchema.optional(),
511
465
  errorCode: z.string().default(""),
@@ -542,6 +496,8 @@ const sourceTreeNodeSchema = z.lazy(() => z.preprocess((value) => isRecord(value
542
496
  ...value,
543
497
  updatedAt: value.updatedAt ?? value.updated_at
544
498
  } : value, z.object({
499
+ learningStatus: z.string().optional(),
500
+ learningErrorCode: z.string().optional(),
545
501
  metadata: z.record(z.string(), z.unknown()).nullable().optional(),
546
502
  externalBinding: sourceExternalBindingSchema.optional(),
547
503
  originUrl: z.string().optional(),
@@ -597,6 +553,12 @@ const sourceUploadFileTypeSchema = z.preprocess((value) => isRecord(value) ? {
597
553
  sourceType: z.string().min(1),
598
554
  uploadMethods: z.array(z.string().min(1)).default([])
599
555
  }));
556
+ const sourceQuotaSchema = z.object({
557
+ usedBytes: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
558
+ limitBytes: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
559
+ planTier: z.string().min(1),
560
+ quotaEnabled: z.boolean()
561
+ }).refine((value) => !value.quotaEnabled || value.limitBytes > 0);
600
562
  const sourceUploadCapabilitiesSchema = z.preprocess((value) => isRecord(value) ? {
601
563
  ...value,
602
564
  fileTypes: value.fileTypes ?? value.file_types,
@@ -832,10 +794,6 @@ const sourceImportResultSchema = z.object({
832
794
  url: z.string().default("")
833
795
  });
834
796
  const sourceImportResultsSchema = z.object({ results: z.array(sourceImportResultSchema) }).transform((value) => value.results);
835
- const batchMutationResultSchema = z.object({
836
- failureCount: z.number().int().nonnegative().default(0),
837
- successCount: z.number().int().nonnegative().default(0)
838
- });
839
797
  const batchDeleteResultSchema = z.object({
840
798
  failureCount: z.number().int().nonnegative(),
841
799
  successCount: z.number().int().nonnegative()
@@ -958,25 +916,7 @@ const notebookContextChunkSchema = z.object({
958
916
  sourceUri: z.string().default(""),
959
917
  tokenCount: z.number().int().nonnegative().default(0)
960
918
  });
961
- const retrievedCardLinkSchema = z.object({
962
- description: z.string().optional(),
963
- linkType: z.string().default(""),
964
- targetId: z.string().min(1),
965
- targetTitle: z.string().optional()
966
- });
967
- const retrievedCardSchema = z.object({
968
- cardType: z.string().optional(),
969
- category: z.string().optional(),
970
- content: z.string().default(""),
971
- depth: z.number().int().nonnegative().default(0),
972
- id: z.string().min(1),
973
- keywords: z.array(z.string()).default([]),
974
- links: z.array(retrievedCardLinkSchema).default([]),
975
- score: z.number().finite().default(0),
976
- title: z.string().default("")
977
- });
978
919
  const retrieveResultSchema = z.object({
979
- cards: z.array(retrievedCardSchema).default([]),
980
920
  chunks: z.array(notebookContextChunkSchema).default([]),
981
921
  citations: z.array(notebookCitationSchema).default([]),
982
922
  promptContext: z.string().default(""),
@@ -1182,4 +1122,4 @@ function call(context, options) {
1182
1122
  });
1183
1123
  }
1184
1124
  //#endregion
1185
- export { timestampSchema as $, imageUrlsSchema as A, sourceImportResultsSchema as B, cardSchema as C, fullSiteURLImportConfirmationSchema as D, chatSessionSchema as E, retrieveResultSchema as F, sourceTreeSchema as G, sourcePreviewSchema as H, sharedNotebookListSchema as I, sourceWebOfficeSessionSchema as J, sourceUploadCapabilitiesSchema as K, sourceActionAccessSchema as L, notebookListSchema as M, notebookSchema as N, fullSiteURLImportDiscoverySchema as O, retrieveNotebooksResultSchema as P, taskRunSchema as Q, sourceChildrenCountsSchema as R, cardListSchema as S, chatSessionListSchema as T, sourceRawContentSchema as U, sourceListSchema as V, sourceSchema as W, streamWireEventSchema as X, sourceWebOfficeTokenSchema as Y, taskRunListSchema as Z, aliDingImportRunItemListSchema as _, invalidArgument as a, executeStream as at, batchMutationResultSchema as b, optionalRecord as c, pagination as d, voidResponseSchema as et, positiveInteger as f, stringList as g, requiredText as h, httpUrl as i, assertCapability as it, importProvidersSchema as j, imageUploadTicketSchema as k, optionalString as l, requiredString as m, call as n, QMIND_SOURCE_UPLOAD_MAX_BYTES as nt, nonNegativeInteger as o, executeUnary as ot, queryPath as p, sourceUploadTicketSchema as q, compactUndefined as r, qmindFullSiteURLImportPageLimit as rt, optionalBoolean as s, QMindError as st, assertNonEmptyPatch as t, QMIND_MULTIPART_UPLOAD_MAX_BYTES as tt, optionalTrimmedString as u, aliDingImportRunSchema as v, chatMessageListSchema as w, cancelQuestionResultSchema as x, batchDeleteResultSchema as y, sourceContentSchema as z };
1125
+ export { QMIND_MULTIPART_UPLOAD_MAX_BYTES as $, notebookSchema as A, sourceQuotaSchema as B, chatSessionSchema as C, imageUrlsSchema as D, imageUploadTicketSchema as E, sourceChildrenCountsSchema as F, sourceUploadTicketSchema as G, sourceSchema as H, sourceContentSchema as I, streamWireEventSchema as J, sourceWebOfficeSessionSchema as K, sourceImportResultsSchema as L, retrieveResultSchema as M, sharedNotebookListSchema as N, importProvidersSchema as O, sourceActionAccessSchema as P, voidResponseSchema as Q, sourceListSchema as R, chatSessionListSchema as S, fullSiteURLImportDiscoverySchema as T, sourceTreeSchema as U, sourceRawContentSchema as V, sourceUploadCapabilitiesSchema as W, taskRunSchema as X, taskRunListSchema as Y, timestampSchema as Z, aliDingImportRunItemListSchema as _, invalidArgument as a, QMindError as at, cancelQuestionResultSchema as b, optionalRecord as c, pagination as d, QMIND_SOURCE_UPLOAD_MAX_BYTES as et, positiveInteger as f, stringList as g, requiredText as h, httpUrl as i, executeUnary as it, retrieveNotebooksResultSchema as j, notebookListSchema as k, optionalString as l, requiredString as m, call as n, assertCapability as nt, nonNegativeInteger as o, queryPath as p, sourceWebOfficeTokenSchema as q, compactUndefined as r, executeStream as rt, optionalBoolean as s, assertNonEmptyPatch as t, qmindFullSiteURLImportPageLimit as tt, optionalTrimmedString as u, aliDingImportRunSchema as v, fullSiteURLImportConfirmationSchema as w, chatMessageListSchema as x, batchDeleteResultSchema as y, sourcePreviewSchema as z };
@@ -1,4 +1,4 @@
1
- import { K as sourceUploadCapabilitiesSchema, m as requiredString, n as call } from "./shared-DBGAKppE.js";
1
+ import { W as sourceUploadCapabilitiesSchema, m as requiredString, n as call } from "./shared-53S5tNf6.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 { W as sourceSchema, a as invalidArgument, et as voidResponseSchema, k as imageUploadTicketSchema, l as optionalString, m as requiredString, nt as QMIND_SOURCE_UPLOAD_MAX_BYTES, ot as executeUnary, p as queryPath, q as sourceUploadTicketSchema, r as compactUndefined, st as QMindError, tt as QMIND_MULTIPART_UPLOAD_MAX_BYTES, u as optionalTrimmedString } from "./shared-DBGAKppE.js";
2
- import { t as preflightSourceUpload } from "./source-upload-CCasR8MW.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-53S5tNf6.js";
2
+ import { t as preflightSourceUpload } from "./source-upload-DlOLtECT.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);
@@ -28,9 +28,12 @@ function transferOptions(options) {
28
28
  function uploadMetadata(value) {
29
29
  if (value === void 0) return {};
30
30
  if (!isRecord(value)) throw invalidArgument("metadata must be an object", "metadata");
31
+ const parentSourceId = optionalString(value.parentSourceId, "parentSourceId");
32
+ const path = optionalString(value.path, "path");
33
+ if (parentSourceId && !path?.trim()) throw invalidArgument("path is required when parentSourceId is set", "path");
31
34
  return {
32
- parentSourceId: optionalString(value.parentSourceId, "parentSourceId"),
33
- path: optionalString(value.path, "path"),
35
+ parentSourceId,
36
+ path,
34
37
  sha256: optionalTrimmedString(value.sha256, "sha256"),
35
38
  sourceType: optionalTrimmedString(value.sourceType, "sourceType"),
36
39
  title: optionalTrimmedString(value.title, "title")
@@ -1,4 +1,4 @@
1
- import { $ as timestampSchema, a as invalidArgument, d as pagination, m as requiredString, n as call, p as queryPath, u as optionalTrimmedString } from "./shared-DBGAKppE.js";
1
+ import { Z as timestampSchema, a as invalidArgument, d as pagination, m as requiredString, n as call, p as queryPath, u as optionalTrimmedString } from "./shared-53S5tNf6.js";
2
2
  import { z } from "zod";
3
3
  //#region ../sdk/src/operations/wiki-branches.ts
4
4
  function isRecord(value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qoder-ai/qmind-cli",
3
- "version": "3.4.0",
3
+ "version": "4.0.0",
4
4
  "description": "QMind command line interface",
5
5
  "bin": {
6
6
  "qmind": "bin/cli.js"
@@ -16,31 +16,33 @@
16
16
  "README.zh-CN.md"
17
17
  ],
18
18
  "engines": {
19
- "node": ">=20.18.1"
19
+ "node": ">=22.19.0"
20
20
  },
21
21
  "publishConfig": {
22
22
  "access": "public",
23
23
  "registry": "https://registry.npmjs.org"
24
24
  },
25
25
  "dependencies": {
26
- "commander": "14.0.2",
27
- "entities": "6.0.1",
28
- "eventsource-parser": "3.1.1",
29
- "open": "11.0.0",
30
- "p-limit": "7.3.1",
31
- "picomatch": "4.0.5",
26
+ "commander": "15.0.0",
27
+ "entities": "8.1.0",
28
+ "eventsource-parser": "4.1.2",
29
+ "open": "11.0.4",
30
+ "p-limit": "7.3.3",
31
+ "picomatch": "4.0.7",
32
32
  "proper-lockfile": "4.1.2",
33
33
  "semver": "7.8.5",
34
- "undici": "7.29.0",
35
- "zod": "4.3.6"
34
+ "undici": "8.12.2",
35
+ "zod": "4.6.7"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/node": "24.13.3",
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.18",
43
- "@ali/qmind-sdk": "^0.24.1"
42
+ "@ali/qmind-node-host": "^3.0.0",
43
+ "@ali/qmind-sdk": "^0.33.1"
44
44
  },
45
- "license": "UNLICENSED"
45
+ "license": "UNLICENSED",
46
+ "readme": "# QMind CLI for Qoder Global\n\n[简体中文](./README.zh-CN.md)\n\nThe QMind command-line interface for Qoder Global lets you sign in, manage knowledge bases and sources, retrieve content, run RAG and task workflows, and synchronize local directories.\n\nPackage: `@qoder-ai/qmind-cli` · command: `qmind`\n\n## Install\n\nNode.js `>=22.19.0` is required.\n\n```sh\nnpm install --global @qoder-ai/qmind-cli\nqmind version\nqmind --help\n```\n\nUpgrade and uninstall through npm. `qmind self-update` only prints the npm upgrade command and never modifies npm-managed files.\n\n```sh\nnpm update --global @qoder-ai/qmind-cli\nnpm uninstall --global @qoder-ai/qmind-cli\n```\n\nThe Native standalone CLI uses the verified Global release channel instead. An installer-managed\nNative executable can check or apply the latest release without Node.js or npm:\n\n```sh\nqmind update --check\nqmind update\n```\n\n`self-update` remains an alias for `update`. The updater rejects channel/URL overrides, downgrades,\nunowned executables, release checksum mismatches, and modified installer bytes. Windows schedules\nreplacement after the running executable exits and records details beside the executable.\n\n## Quick start\n\n```sh\nqmind login\nqmind notebook list\nqmind source list --nb <notebook-id>\nqmind retrieve --nb <notebook-id> \"What must be checked before release?\"\n```\n\nInteractive login opens a browser and stores the session in a local file vault. For CI and agents, prefer an environment variable and structured output:\n\n```sh\nexport QMIND_TOKEN='<token>'\nqmind notebook list --non-interactive --format json\nqmind retrieve --nb <notebook-id> --format agent \"What is the deployment process?\"\n```\n\nDo not put tokens in command arguments, repositories, or logs. Run `qmind logout` to remove the current local session.\n\n## Commands\n\n| Command | Purpose |\n| ------------------------ | ---------------------------------------- |\n| `login` / `logout` | Sign in or remove local credentials |\n| `notebook` | Manage knowledge bases |\n| `source` | Manage knowledge-base sources |\n| `retrieve` | Retrieve context without invoking an LLM |\n| `rag` | Ask questions using a knowledge base |\n| `task` | Manage task runs |\n| `upload-folder` / `sync` | Synchronize a local directory |\n| `image` | Obtain image upload or access URLs |\n| `version` | Print version and build information |\n| `update` / `self-update` | Update an installer-managed Native CLI |\n\n`task create` does not start `compilation` or `lint` runs; `task list` and `task get` can still inspect historical runs for those scenes. `source import-site` does not provide an automatic compilation option.\n\nRun `qmind <command> --help` for complete options. Domain commands support formats such as `table`, `json`, `agent`, and `ndjson`. stdout contains results; progress and diagnostics go to stderr. Exit codes are `0` for success, `1` for runtime failure/partial success/cancellation, and `2` for invalid usage.\n\n## Multi-notebook retrieval\n\n`retrieve --nb` accepts comma-separated or repeated Notebook IDs, deduplicating up to 5 distinct notebooks:\n\n```sh\nqmind retrieve --nb nb-1,nb-2 \"What is the deployment process?\" --format json\nqmind retrieve --nb nb-1 --nb nb-2 \"What is the deployment process?\" --format agent\n```\n\n- Selection is explicit; the CLI never defaults to all accessible notebooks.\n- Multiple notebooks use one unified retrieval request. The server jointly retrieves and reranks Source chunks; output retains server ranking and each chunk/citation's `notebookId` and `notebookTitle`.\n- `--top-k` controls the joint recall candidate budget per route/query/channel; it is not multiplied by notebook count. `--max-results` limits the final results across all selected notebooks. Zero uses server defaults.\n- `--sources` requires a single notebook. A single deduplicated notebook keeps the existing retrieval endpoint. All retrieval output formats expose chunks and citations without knowledge cards.\n- Multi-notebook JSON returns `{ chunks, citations, promptContext, total, reranked }`. NDJSON emits one `kind: \"chunk\"` record per returned chunk, in server order; zero hits emit no records. Table and agent output also identify each evidence item's notebook.\n- Unified retrieval fails as one request when a target is invalid or inaccessible. The CLI reports the error without retrying notebooks individually or constructing partial-success results. Retrieval results no longer contain a `cards` field.\n\n## Directory synchronization\n\nReview the plan before allowing remote deletions:\n\n```sh\nqmind upload-folder --nb <notebook-id> --dir ./docs --mode if-changed --dry-run\n```\n\nRemoving `--dry-run` enables writes. `--delete` treats the remote source root as a mirror of the local directory and removes extra remote entries. Concurrency must be between `1` and `10`.\n\n## Configuration and authentication\n\nThis package has a fixed Qoder Global identity. Renaming the executable, changing its install path, or setting product-selection environment variables cannot switch products. Production is the default; `--env test` and `--env daily` select supported debug presets. A custom target requires both `--sash` and `--dashboard` and cannot be combined with an explicit `--env`.\n\n```sh\nqmind login --env test\nQMIND_DEBUG_TOKEN='<debug-token>' qmind notebook list --env test --non-interactive --format json\nqmind login --sash http://localhost:8080 --dashboard http://localhost:3000\n```\n\nProduction token priority is `--token > QMIND_TOKEN > current production vault`. Debug token priority is `--token > QMIND_DEBUG_TOKEN > current debug vault`; credentials are never borrowed across targets.\n\nState is stored under `<state-root>/cli/global/<target>/`, where the state root is `QMIND_HOME` or `~/.qmind`. The CLI does not install, load, or access the OS Keyring. Credential files are plaintext JSON, not encrypted storage. On POSIX, partition directories use mode `0700` and files use `0600`; these modes do not represent Windows ACLs. Writes use atomic replacement, file locking, and compare-and-swap protection for refreshes.\n\nAfter upgrading from the legacy unpartitioned store, sign in again. Root-level config/credential files, `~/.qmind-env`, and old Keyring entries are not read, imported, or deleted automatically.\n\nThe shared 3.x Global/CN release is a breaking upgrade from Global 2.x. Upgrade this package with npm, then run `qmind login`; do not copy legacy credentials into the new partition. Existing versions before the shared release describe the Global/shared implementation only and do not imply a historical CN publication.\n\nCommon variables include `QMIND_TOKEN`, `QMIND_DEBUG_TOKEN`, `QMIND_HOME`, `QMIND_CLIENT`, `QMIND_NON_INTERACTIVE`, `QMIND_REQUEST_TIMEOUT_MS`, `QMIND_STREAM_IDLE_TIMEOUT_MS`, and `QMIND_TLS_CA_FILE`. `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` are supported. TLS verification is strict by default, and credentials are not forwarded to signed object-storage URLs.\n\n## Shared notebook discovery and access\n\n```sh\nqmind notebook list --shared --page 1 --page-size 20\nqmind notebook list --shared --format json\nqmind notebook get <notebook-id> --format json\n```\n\nBoth notebook collections support `--page` and `--page-size`. `--shared` cannot be combined with `--filter-client`. Shared results use the same flat `notebooks` output as the ordinary list and preserve the membership `permission`. JSON/NDJSON preserve server-provided `access` (current role, member count and action permissions); Agent output expands these fields. Table lists show role and member count, while details show action permissions. Missing permissions are not inferred and display as `unknown` in tables.\n",
47
+ "readmeFilename": "README.md"
46
48
  }
@@ -1,132 +0,0 @@
1
- import { C as cardSchema, S as cardListSchema, a as invalidArgument, b as batchMutationResultSchema, 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 } from "./shared-DBGAKppE.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 };