sim 2.1.9-preview.105.1 → 2.1.10-preview.107.1

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/README.md CHANGED
@@ -188,6 +188,7 @@ The commands you will use most often are:
188
188
  | Upload or download files | `sim files upload ./report.pdf`, `sim files get <fileId>` |
189
189
  | Search knowledge bases | `sim knowledge search --query "refund policy" --kb <knowledgeBaseId>` |
190
190
  | Upload a knowledge document | `sim knowledge documents upload <knowledgeBaseId> ./handbook.pdf` |
191
+ | Export a knowledge base | `sim knowledge export <knowledgeBaseId> -o ./kb.simkb.zip` |
191
192
  | Manage integration credentials | `sim credentials --help` |
192
193
  | Manage workspace secrets | `sim secrets list`, `sim secrets set <name>` |
193
194
 
package/dist/index.js CHANGED
@@ -10474,6 +10474,25 @@ var V2_OPERATIONS = {
10474
10474
  }
10475
10475
  }
10476
10476
  },
10477
+ exportKnowledgeBase: {
10478
+ method: "GET",
10479
+ path: "/api/v2/knowledge/[knowledgeBaseId]/export",
10480
+ pathParams: ["knowledgeBaseId"],
10481
+ pathParamDocs: { knowledgeBaseId: "Unique knowledge base identifier." },
10482
+ responseMode: "binary",
10483
+ summary: "Export Knowledge Base",
10484
+ query: {
10485
+ workspaceId: {
10486
+ kind: "string",
10487
+ required: true,
10488
+ describe: "Workspace that owns the knowledge base."
10489
+ },
10490
+ vectors: {
10491
+ kind: "boolean",
10492
+ describe: "Include chunk vectors so an import into a deployment with the same embedding model reuses them instead of re-embedding."
10493
+ }
10494
+ }
10495
+ },
10477
10496
  exportWorkflow: {
10478
10497
  method: "GET",
10479
10498
  path: "/api/v2/workflows/[workflowId]/export",
@@ -17851,6 +17870,60 @@ function attachKnowledgeDocumentUpload(documents) {
17851
17870
  });
17852
17871
  }
17853
17872
 
17873
+ // src/commands/protocol/knowledge-export.ts
17874
+ import { basename as basename2, join as join3 } from "node:path";
17875
+ function attachmentFileName(contentDisposition) {
17876
+ if (!contentDisposition)
17877
+ return null;
17878
+ const encoded = /filename\*=UTF-8''([^;]+)/i.exec(contentDisposition)?.[1];
17879
+ if (encoded) {
17880
+ try {
17881
+ return safeBaseName(decodeURIComponent(encoded));
17882
+ } catch {}
17883
+ }
17884
+ const quoted = /filename="([^"]*)"/.exec(contentDisposition)?.[1];
17885
+ return quoted === undefined ? null : safeBaseName(quoted);
17886
+ }
17887
+ function safeBaseName(name) {
17888
+ const base = basename2(name.trim());
17889
+ return base && base !== "." && base !== ".." ? base : null;
17890
+ }
17891
+ function attachKnowledgeExport(knowledge) {
17892
+ knowledge.command("export").argument("<knowledgeBaseId>", "Knowledge base to export").allowExcessArguments(false).description("Export a knowledge base as a .simkb.zip bundle").option("-o, --output-file <path>", "Write the bundle to this path instead of the name the server suggests; pass - to stream it to stdout").option("--force", "Overwrite --output-file if it already exists").option("--no-vectors", "Leave chunk vectors out of the bundle, so an import re-embeds every chunk").action(async (knowledgeBaseId, options, command) => {
17893
+ const writesToStdout = options.outputFile === "-";
17894
+ if (writesToStdout && options.force) {
17895
+ throw new SimApiError("--force requires --output-file <path>", 0);
17896
+ }
17897
+ const { client, profile } = clientFrom(command);
17898
+ const workspaceId = client.requireWorkspace();
17899
+ const operation = V2_OPERATIONS.exportKnowledgeBase;
17900
+ const response = await client.requestRaw(resolvePath(operation.path, { knowledgeBaseId }), {
17901
+ method: operation.method,
17902
+ query: { workspaceId, vectors: options.vectors }
17903
+ });
17904
+ if (!response.body) {
17905
+ throw new SimApiError("Knowledge base export response was empty.", response.status);
17906
+ }
17907
+ if (writesToStdout) {
17908
+ const contentType = response.headers.get("content-type");
17909
+ if (process.stdout.isTTY && !isTerminalSafeContentType(contentType)) {
17910
+ await response.body.cancel();
17911
+ throw new SimApiError(`Refusing to write ${contentType ?? "unknown content"} to an interactive terminal. Use --output-file <path> or pipe stdout.`, 0);
17912
+ }
17913
+ await streamToStdout(response.body);
17914
+ return;
17915
+ }
17916
+ const target = options.outputFile ?? join3(process.cwd(), attachmentFileName(response.headers.get("content-disposition")) ?? `${knowledgeBaseId}.simkb.zip`);
17917
+ await saveToFile(response.body, target, Boolean(options.force));
17918
+ printProtocolResult(profile.output, {
17919
+ id: knowledgeBaseId,
17920
+ path: target,
17921
+ status: "saved",
17922
+ vectors: options.vectors
17923
+ });
17924
+ });
17925
+ }
17926
+
17854
17927
  // src/commands/protocol/logs-follow.ts
17855
17928
  var DEFAULT_BACKLOG = 10;
17856
17929
  var DEFAULT_INTERVAL_SECONDS = 3;
@@ -18800,6 +18873,7 @@ function attachProtocolCommands(program) {
18800
18873
  });
18801
18874
  const knowledge = group(program, "knowledge");
18802
18875
  attachKnowledgeDocumentUpload(group(knowledge, "documents"));
18876
+ attachKnowledgeExport(knowledge);
18803
18877
  attachResourceDirectoryCommands(knowledge, {
18804
18878
  kind: "knowledge",
18805
18879
  resources: "listKnowledgeBases",
@@ -19336,6 +19410,7 @@ Examples:
19336
19410
  $ sim knowledge search --query "refund policy" --kb 4c1b7f60-2d55-4a3e-9c18-70b6ea2f9d31
19337
19411
  $ sim workflows export 3a9e21d8-5f47-4c0b-b2ea-91d7c6034ef8 > wf.json
19338
19412
  $ sim workflows import --workflow @wf.json
19413
+ $ sim knowledge export 4c1b7f60-2d55-4a3e-9c18-70b6ea2f9d31 -o ./kb.simkb.zip
19339
19414
  $ sim whoami --profile dev
19340
19415
  `;
19341
19416
  var ROOT_VALUE_FLAGS = new Set([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sim",
3
- "version": "2.1.9-preview.105.1",
3
+ "version": "2.1.10-preview.107.1",
4
4
  "description": "Sim CLI - talk to the Sim API from your terminal",
5
5
  "type": "module",
6
6
  "bin": {