openxgen 0.4.0 → 0.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.
package/dist/index.js CHANGED
@@ -95,7 +95,7 @@ function addProvider(provider) {
95
95
  const store = getProvidersStore();
96
96
  store.providers = store.providers.filter((p) => p.id !== provider.id);
97
97
  store.providers.push(provider);
98
- if (!store.defaultId) store.defaultId = provider.id;
98
+ store.defaultId = provider.id;
99
99
  writeJson(PROVIDERS_FILE, store, true);
100
100
  }
101
101
  function removeProvider(id) {
@@ -318,6 +318,16 @@ var init_auth = __esm({
318
318
  });
319
319
 
320
320
  // src/api/workflow.ts
321
+ var workflow_exports = {};
322
+ __export(workflow_exports, {
323
+ executeWorkflow: () => executeWorkflow,
324
+ executeWorkflowStream: () => executeWorkflowStream,
325
+ getExecutionStatus: () => getExecutionStatus,
326
+ getIOLogs: () => getIOLogs,
327
+ getWorkflowDetail: () => getWorkflowDetail,
328
+ getWorkflowListDetail: () => getWorkflowListDetail,
329
+ listWorkflows: () => listWorkflows
330
+ });
321
331
  async function listWorkflows(userId) {
322
332
  const client2 = getClient();
323
333
  const params = {};
@@ -345,6 +355,16 @@ async function executeWorkflowStream(request) {
345
355
  });
346
356
  return res.data;
347
357
  }
358
+ async function executeWorkflow(request) {
359
+ const client2 = getClient();
360
+ const res = await client2.post("/api/workflow/execute/based_id", request);
361
+ return res.data;
362
+ }
363
+ async function getExecutionStatus(executionId) {
364
+ const client2 = getClient();
365
+ const res = await client2.get(`/api/workflow/execute/status/${executionId}`);
366
+ return res.data;
367
+ }
348
368
  async function getIOLogs(workflowId, limit = 20) {
349
369
  const client2 = getClient();
350
370
  const params = { limit };
@@ -475,6 +495,178 @@ var init_sse = __esm({
475
495
  }
476
496
  });
477
497
 
498
+ // src/utils/markdown.ts
499
+ import chalk6 from "chalk";
500
+ function renderMarkdown(text) {
501
+ let result = text;
502
+ result = result.replace(CODE_BLOCK_RE, (_match, lang, code) => {
503
+ const trimmed = code.trimEnd();
504
+ const header = lang ? chalk6.gray(` \u2500\u2500 ${lang} \u2500\u2500`) : chalk6.gray(" \u2500\u2500 code \u2500\u2500");
505
+ const lines = trimmed.split("\n").map((l) => chalk6.white(` ${l}`)).join("\n");
506
+ return `
507
+ ${header}
508
+ ${lines}
509
+ ${chalk6.gray(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")}
510
+ `;
511
+ });
512
+ result = result.replace(INLINE_CODE_RE, (_m, code) => chalk6.cyan(`\`${code}\``));
513
+ result = result.replace(BOLD_RE, (_m, text2) => chalk6.bold(text2));
514
+ result = result.replace(HEADING_RE, (_m, hashes, text2) => {
515
+ if (hashes.length === 1) return chalk6.bold.underline(text2);
516
+ if (hashes.length === 2) return chalk6.bold(text2);
517
+ return chalk6.bold.dim(text2);
518
+ });
519
+ result = result.replace(LIST_RE, (_m, indent, text2) => `${indent}${chalk6.cyan("\u2022")} ${text2}`);
520
+ result = result.replace(LINK_RE, (_m, label, url) => `${chalk6.blue.underline(label)} ${chalk6.gray(`(${url})`)}`);
521
+ return result;
522
+ }
523
+ var CODE_BLOCK_RE, INLINE_CODE_RE, BOLD_RE, HEADING_RE, LIST_RE, LINK_RE;
524
+ var init_markdown = __esm({
525
+ "src/utils/markdown.ts"() {
526
+ "use strict";
527
+ CODE_BLOCK_RE = /```(\w*)\n([\s\S]*?)```/g;
528
+ INLINE_CODE_RE = /`([^`]+)`/g;
529
+ BOLD_RE = /\*\*(.+?)\*\*/g;
530
+ HEADING_RE = /^(#{1,3})\s+(.+)$/gm;
531
+ LIST_RE = /^(\s*)[-*]\s+(.+)$/gm;
532
+ LINK_RE = /\[([^\]]+)\]\(([^)]+)\)/g;
533
+ }
534
+ });
535
+
536
+ // src/commands/workflow/run.ts
537
+ var run_exports = {};
538
+ __export(run_exports, {
539
+ workflowRun: () => workflowRun
540
+ });
541
+ import chalk7 from "chalk";
542
+ import { randomUUID } from "crypto";
543
+ async function workflowRun(workflowId, input, opts) {
544
+ const auth = requireAuth();
545
+ let workflowName = workflowId;
546
+ try {
547
+ const detail = await getWorkflowDetail(workflowId);
548
+ workflowName = detail.workflow_name ?? workflowId;
549
+ } catch {
550
+ }
551
+ if (!input) {
552
+ if (opts.interactive || !process.stdin.isTTY) {
553
+ const { createInterface: createInterface7 } = await import("readline");
554
+ const rl = createInterface7({ input: process.stdin, output: process.stdout });
555
+ input = await new Promise((resolve) => {
556
+ rl.question(chalk7.cyan("\uC785\uB825> "), (answer) => {
557
+ rl.close();
558
+ resolve(answer.trim());
559
+ });
560
+ });
561
+ } else {
562
+ printError("\uC785\uB825\uAC12\uC774 \uD544\uC694\uD569\uB2C8\uB2E4. \uC0AC\uC6A9\uBC95:");
563
+ console.log(' xgen workflow run <id> "\uC785\uB825 \uD14D\uC2A4\uFFFD\uFFFD\uFFFD"');
564
+ console.log(" xgen workflow run -i <id>");
565
+ process.exit(1);
566
+ }
567
+ }
568
+ if (!input) {
569
+ printError("\uC785\uB825\uAC12\uC774 \uBE44\uC5B4\uC788\uC2B5\uB2C8\uB2E4");
570
+ process.exit(1);
571
+ }
572
+ const interactionId = `cli_${randomUUID().slice(0, 8)}`;
573
+ printHeader(`\uC2E4\uD589: ${workflowName}`);
574
+ printInfo(`\uC785\uB825: ${input}`);
575
+ console.log();
576
+ try {
577
+ const stream = await executeWorkflowStream({
578
+ workflow_id: workflowId,
579
+ workflow_name: workflowName,
580
+ input_data: input,
581
+ interaction_id: interactionId
582
+ });
583
+ let hasOutput = false;
584
+ let fullResponse = "";
585
+ await parseSSEStream(
586
+ stream,
587
+ (event) => {
588
+ switch (event.type) {
589
+ case "token":
590
+ if (event.content) {
591
+ if (!hasOutput) {
592
+ hasOutput = true;
593
+ console.log();
594
+ }
595
+ process.stdout.write(event.content);
596
+ fullResponse += event.content;
597
+ }
598
+ break;
599
+ case "log":
600
+ if (opts.logs && event.content) {
601
+ process.stderr.write(chalk7.gray(`[LOG] ${event.content}
602
+ `));
603
+ }
604
+ break;
605
+ case "node_status":
606
+ if (opts.logs) {
607
+ const nodeName = event.node_name ?? event.node_id ?? "?";
608
+ const status = event.status ?? "?";
609
+ process.stderr.write(
610
+ chalk7.gray(`[\uB178\uB4DC] ${nodeName}: ${status}
611
+ `)
612
+ );
613
+ }
614
+ break;
615
+ case "tool":
616
+ if (opts.logs) {
617
+ process.stderr.write(chalk7.gray(`[\uB3C4\uAD6C] ${JSON.stringify(event.data)}
618
+ `));
619
+ }
620
+ break;
621
+ case "complete":
622
+ break;
623
+ case "error":
624
+ console.log();
625
+ printError(event.error ?? event.content ?? "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958");
626
+ break;
627
+ default:
628
+ if (event.content) {
629
+ if (!hasOutput) {
630
+ process.stdout.write(chalk7.green("\uC751\uB2F5: "));
631
+ hasOutput = true;
632
+ }
633
+ process.stdout.write(event.content);
634
+ }
635
+ }
636
+ },
637
+ () => {
638
+ if (hasOutput) {
639
+ console.log();
640
+ if (fullResponse.includes("```") || fullResponse.includes("**")) {
641
+ console.log(chalk7.gray("\u2500".repeat(40)));
642
+ console.log(renderMarkdown(fullResponse));
643
+ }
644
+ }
645
+ console.log();
646
+ console.log(chalk7.gray(`\uC138\uC158: ${interactionId}`));
647
+ },
648
+ (err) => {
649
+ console.log();
650
+ printError(`\uC2A4\uD2B8\uB9AC\uBC0D \uC624\uB958: ${err.message}`);
651
+ }
652
+ );
653
+ } catch (err) {
654
+ const msg = err?.response?.data?.detail ?? err.message;
655
+ printError(`\uC2E4\uD589 \uC2E4\uD328: ${msg}`);
656
+ process.exit(1);
657
+ }
658
+ }
659
+ var init_run = __esm({
660
+ "src/commands/workflow/run.ts"() {
661
+ "use strict";
662
+ init_store();
663
+ init_workflow();
664
+ init_sse();
665
+ init_format();
666
+ init_markdown();
667
+ }
668
+ });
669
+
478
670
  // src/commands/chat.ts
479
671
  import chalk9 from "chalk";
480
672
  import { createInterface as createInterface2 } from "readline";
@@ -706,11 +898,34 @@ ${chalk9.cyan("\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
706
898
  }
707
899
  });
708
900
 
709
- // src/commands/provider.ts
901
+ // src/utils/ui.ts
710
902
  import chalk10 from "chalk";
711
903
  import { createInterface as createInterface3 } from "readline";
712
- import OpenAI from "openai";
713
- function prompt2(question) {
904
+ function box(lines, color = "cyan") {
905
+ const c = chalk10[color];
906
+ const inner = W - 4;
907
+ const top = c(" \u256D" + "\u2500".repeat(inner) + "\u256E");
908
+ const bot = c(" \u2570" + "\u2500".repeat(inner) + "\u256F");
909
+ const body = lines.map((line) => {
910
+ const clean = line.replace(/\x1b\[[0-9;]*m/g, "");
911
+ const pad = Math.max(0, inner - clean.length);
912
+ return c(" \u2502 ") + line + " ".repeat(pad) + c(" \u2502");
913
+ });
914
+ return [top, ...body, bot].join("\n");
915
+ }
916
+ function divider(label) {
917
+ if (label) {
918
+ const rest = W - label.length - 6;
919
+ return chalk10.gray(` \u2500\u2500 ${label} ${"\u2500".repeat(Math.max(0, rest))}`);
920
+ }
921
+ return chalk10.gray(" " + "\u2500".repeat(W - 2));
922
+ }
923
+ function statusDot(active, label, detail) {
924
+ const dot = active ? chalk10.green("\u25CF") : chalk10.gray("\u25CB");
925
+ const d = detail ? chalk10.gray(` ${detail}`) : "";
926
+ return ` ${dot} ${label}${d}`;
927
+ }
928
+ function ask(question) {
714
929
  return new Promise((resolve) => {
715
930
  const rl = createInterface3({ input: process.stdin, output: process.stdout });
716
931
  rl.question(question, (answer) => {
@@ -719,77 +934,115 @@ function prompt2(question) {
719
934
  });
720
935
  });
721
936
  }
937
+ function welcome() {
938
+ const logo = chalk10.cyan(`
939
+ \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588
940
+ \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588 \u2588\u2588
941
+ \u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588
942
+ \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588
943
+ \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588`) + chalk10.white.bold(`
944
+ \u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588
945
+ \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588 \u2588\u2588
946
+ \u2588\u2588\u2588 \u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588
947
+ \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588
948
+ \u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588`);
949
+ return logo;
950
+ }
951
+ var W;
952
+ var init_ui = __esm({
953
+ "src/utils/ui.ts"() {
954
+ "use strict";
955
+ W = Math.min(process.stdout.columns || 60, 70);
956
+ }
957
+ });
958
+
959
+ // src/commands/provider.ts
960
+ import chalk11 from "chalk";
961
+ import OpenAI from "openai";
962
+ function detectEnvKey(preset) {
963
+ if (!preset.envKey) return null;
964
+ return process.env[preset.envKey] ?? null;
965
+ }
722
966
  async function guidedProviderSetup() {
723
- console.log(chalk10.cyan.bold("\n \u26A1 OPEN XGEN \u2014 \uD504\uB85C\uBC14\uC774\uB354 \uC124\uC815\n"));
724
- console.log(chalk10.gray(" AI \uC5D0\uC774\uC804\uD2B8\uB97C \uC0AC\uC6A9\uD558\uB824\uBA74 \uD504\uB85C\uBC14\uC774\uB354\uB97C \uC124\uC815\uD558\uC138\uC694.\n"));
725
- console.log(chalk10.bold(" \uD504\uB85C\uBC14\uC774\uB354 \uC120\uD0DD:\n"));
967
+ console.log();
968
+ console.log(box(["OPEN XGEN \u2014 \uD504\uB85C\uBC14\uC774\uB354 \uC124\uC815", "", chalk11.gray("AI \uC5D0\uC774\uC804\uD2B8\uC5D0 \uC0AC\uC6A9\uD560 LLM\uC744 \uC120\uD0DD\uD558\uC138\uC694.")]));
969
+ console.log();
970
+ console.log(chalk11.bold(" \uD504\uB85C\uBC14\uC774\uB354 \uC120\uD0DD:\n"));
726
971
  PRESETS.forEach((p, i) => {
727
- console.log(` ${chalk10.cyan(`${i + 1})`)} ${p.label} ${chalk10.gray(`\u2014 ${p.defaultModel}`)}`);
972
+ const envDetected = detectEnvKey(p);
973
+ const envTag = envDetected ? chalk11.green(" [\uD0A4 \uAC10\uC9C0\uB428]") : "";
974
+ const free = !p.needsKey ? chalk11.green(" [\uBB34\uB8CC]") : "";
975
+ console.log(` ${chalk11.cyan(`${String(i + 1).padStart(2)}.`)} ${p.label}${free}${envTag}`);
976
+ console.log(` ${chalk11.gray(p.defaultModel)}`);
728
977
  });
729
978
  console.log();
730
- const choice = await prompt2(chalk10.white(" \uBC88\uD638 \uC120\uD0DD: "));
979
+ const choice = await ask(chalk11.cyan(" \uBC88\uD638: "));
731
980
  const idx = parseInt(choice) - 1;
732
981
  if (isNaN(idx) || idx < 0 || idx >= PRESETS.length) {
733
- printError("\uC798\uBABB\uB41C \uC120\uD0DD\uC785\uB2C8\uB2E4.");
982
+ console.log(chalk11.red(" \uC798\uBABB\uB41C \uC120\uD0DD.\n"));
734
983
  return null;
735
984
  }
736
985
  const preset = PRESETS[idx];
737
- console.log(chalk10.green(`
738
- \u2713 ${preset.label} \uC120\uD0DD\uB428
986
+ console.log(chalk11.green(`
987
+ \u2713 ${preset.label}
739
988
  `));
740
989
  let apiKey = "";
741
990
  if (preset.needsKey) {
742
- console.log(chalk10.gray(` ${preset.keyHint}
743
- `));
744
- apiKey = await prompt2(chalk10.white(" API Key: "));
991
+ const envKey = detectEnvKey(preset);
992
+ if (envKey) {
993
+ console.log(chalk11.green(` API Key \uC790\uB3D9 \uAC10\uC9C0 (${preset.envKey})`));
994
+ const useEnv = await ask(chalk11.white(` \uC774 \uD0A4\uB97C \uC0AC\uC6A9\uD560\uAE4C\uC694? (Y/n): `));
995
+ if (useEnv.toLowerCase() !== "n") {
996
+ apiKey = envKey;
997
+ }
998
+ }
745
999
  if (!apiKey) {
746
- printError("API Key\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4.");
747
- return null;
1000
+ console.log(chalk11.gray(` \uBC1C\uAE09: ${preset.keyHint}
1001
+ `));
1002
+ apiKey = await ask(chalk11.white(" API Key: "));
1003
+ if (!apiKey) {
1004
+ console.log(chalk11.red(" API Key \uD544\uC694.\n"));
1005
+ return null;
1006
+ }
748
1007
  }
749
1008
  }
750
1009
  let baseUrl = preset.baseUrl;
751
- if (preset.type === "custom") {
752
- const url = await prompt2(chalk10.white(" Base URL: "));
753
- if (!url) {
754
- printError("Base URL\uC774 \uD544\uC694\uD569\uB2C8\uB2E4.");
1010
+ if (preset.label === "\uAE30\uD0C0 (OpenAI \uD638\uD658 \uC11C\uBC84)") {
1011
+ baseUrl = await ask(chalk11.white(" Base URL: "));
1012
+ if (!baseUrl) {
1013
+ console.log(chalk11.red(" URL \uD544\uC694.\n"));
755
1014
  return null;
756
1015
  }
757
- baseUrl = url;
758
- } else if (preset.type === "ollama") {
759
- const url = await prompt2(chalk10.white(` Base URL [${preset.baseUrl}]: `));
760
- if (url) baseUrl = url;
761
1016
  }
762
1017
  let model = preset.defaultModel;
763
1018
  if (preset.models.length > 0) {
764
- console.log(chalk10.bold("\n \uBAA8\uB378 \uC120\uD0DD:\n"));
1019
+ console.log(chalk11.bold("\n \uBAA8\uB378:\n"));
1020
+ const defaultIdx = preset.models.indexOf(preset.defaultModel);
765
1021
  preset.models.forEach((m, i) => {
766
- const isDefault = m === preset.defaultModel ? chalk10.gray(" (\uAE30\uBCF8)") : "";
767
- console.log(` ${chalk10.cyan(`${i + 1})`)} ${m}${isDefault}`);
1022
+ const tag = i === defaultIdx ? chalk11.green(" \u2190 \uCD94\uCC9C") : "";
1023
+ console.log(` ${chalk11.cyan(`${String(i + 1).padStart(2)}.`)} ${m}${tag}`);
768
1024
  });
769
- console.log(` ${chalk10.cyan(`${preset.models.length + 1})`)} \uC9C1\uC811 \uC785\uB825`);
1025
+ console.log(` ${chalk11.cyan(`${String(preset.models.length + 1).padStart(2)}.`)} \uC9C1\uC811 \uC785\uB825`);
770
1026
  console.log();
771
- const defaultIdx = preset.models.indexOf(preset.defaultModel);
772
- const mc = await prompt2(chalk10.white(` \uBC88\uD638 \uC120\uD0DD [${defaultIdx + 1}]: `));
773
- if (!mc) {
1027
+ const mc = await ask(chalk11.cyan(` \uBC88\uD638 [${defaultIdx + 1}]: `));
1028
+ if (!mc || mc === String(defaultIdx + 1)) {
774
1029
  model = preset.defaultModel;
775
1030
  } else {
776
1031
  const mi = parseInt(mc) - 1;
777
- if (!isNaN(mi) && mi >= 0 && mi < preset.models.length) {
1032
+ if (mi >= 0 && mi < preset.models.length) {
778
1033
  model = preset.models[mi];
779
1034
  } else if (parseInt(mc) === preset.models.length + 1) {
780
- model = await prompt2(chalk10.white(" \uBAA8\uB378 \uC774\uB984: ")) || preset.defaultModel;
781
- } else {
782
- model = preset.defaultModel;
1035
+ model = await ask(chalk11.white(" \uBAA8\uB378\uBA85: ")) || preset.defaultModel;
783
1036
  }
784
1037
  }
785
- } else {
786
- model = await prompt2(chalk10.white(` \uBAA8\uB378 \uC774\uB984 [${preset.defaultModel}]: `)) || preset.defaultModel;
1038
+ } else if (preset.label === "\uAE30\uD0C0 (OpenAI \uD638\uD658 \uC11C\uBC84)") {
1039
+ model = await ask(chalk11.white(` \uBAA8\uB378\uBA85 [${preset.defaultModel}]: `)) || preset.defaultModel;
787
1040
  }
788
- console.log(chalk10.green(`
789
- \u2713 \uBAA8\uB378: ${model}`));
790
- console.log(chalk10.gray("\n \uC5F0\uACB0 \uD14C\uC2A4\uD2B8 \uC911..."));
1041
+ console.log(chalk11.green(`
1042
+ \u2713 ${preset.label} \xB7 ${model}`));
1043
+ console.log(chalk11.gray(" \uC5F0\uACB0 \uD14C\uC2A4\uD2B8 \uC911...\n"));
791
1044
  const provider = {
792
- id: preset.type,
1045
+ id: preset.label.toLowerCase().replace(/[^a-z0-9]/g, "-").replace(/-+/g, "-"),
793
1046
  name: preset.label,
794
1047
  type: preset.type,
795
1048
  baseUrl,
@@ -797,50 +1050,41 @@ async function guidedProviderSetup() {
797
1050
  model
798
1051
  };
799
1052
  try {
800
- const client2 = new OpenAI({
801
- apiKey: apiKey || "ollama",
802
- baseURL: baseUrl
803
- });
804
- const res = await client2.chat.completions.create({
1053
+ const client2 = new OpenAI({ apiKey: apiKey || "ollama", baseURL: baseUrl });
1054
+ await client2.chat.completions.create({
805
1055
  model,
806
1056
  messages: [{ role: "user", content: "Hi" }],
807
1057
  max_tokens: 5
808
1058
  });
809
- if (res.choices[0]) {
810
- console.log(chalk10.green(" \u2713 \uC5F0\uACB0 \uC131\uACF5!\n"));
811
- }
1059
+ console.log(chalk11.green(" \u2713 \uC5F0\uACB0 \uC131\uACF5!\n"));
812
1060
  } catch (err) {
813
- console.log(chalk10.yellow(` \u26A0 \uC5F0\uACB0 \uD14C\uC2A4\uD2B8 \uC2E4\uD328: ${err.message}`));
814
- console.log(chalk10.gray(" \uC124\uC815\uC740 \uC800\uC7A5\uB429\uB2C8\uB2E4. \uB098\uC911\uC5D0 \uB2E4\uC2DC \uC2DC\uB3C4\uD558\uC138\uC694.\n"));
1061
+ console.log(chalk11.yellow(` \u26A0 \uD14C\uC2A4\uD2B8 \uC2E4\uD328: ${err.message}`));
1062
+ console.log(chalk11.gray(" \uC124\uC815\uC740 \uC800\uC7A5\uB429\uB2C8\uB2E4.\n"));
815
1063
  }
816
1064
  addProvider(provider);
817
- console.log(chalk10.green.bold(` \u2713 ${preset.label} (${model}) \uC124\uC815 \uC644\uB8CC!
818
- `));
819
- console.log(chalk10.gray(` \uC774\uC81C ${chalk10.cyan("xgen agent")} \uB610\uB294 ${chalk10.cyan("xgen")} \uC73C\uB85C \uC2DC\uC791\uD558\uC138\uC694.
1065
+ console.log(chalk11.green.bold(` \u2713 \uC124\uC815 \uC644\uB8CC! ${preset.label} (${model})
820
1066
  `));
821
1067
  return provider;
822
1068
  }
823
1069
  function registerProviderCommand(program2) {
824
1070
  const prov = program2.command("provider").description("AI \uD504\uB85C\uBC14\uC774\uB354 \uAD00\uB9AC");
825
- prov.command("add").description("\uD504\uB85C\uBC14\uC774\uB354 \uCD94\uAC00 (\uAC00\uC774\uB4DC \uC124\uC815)").action(async () => {
1071
+ prov.command("add").description("\uD504\uB85C\uBC14\uC774\uB354 \uCD94\uAC00").action(async () => {
826
1072
  await guidedProviderSetup();
827
1073
  });
828
1074
  prov.command("list").alias("ls").description("\uD504\uB85C\uBC14\uC774\uB354 \uBAA9\uB85D").action(() => {
829
1075
  const providers = getProviders();
830
1076
  const defaultP = getDefaultProvider();
831
1077
  if (providers.length === 0) {
832
- console.log(chalk10.yellow("\n \uD504\uB85C\uBC14\uC774\uB354\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4."));
833
- console.log(` ${chalk10.cyan("xgen provider add")} \uB85C \uCD94\uAC00\uD558\uC138\uC694.
834
- `);
1078
+ console.log(chalk11.yellow("\n \uD504\uB85C\uBC14\uC774\uB354 \uC5C6\uC74C. xgen provider add\n"));
835
1079
  return;
836
1080
  }
837
- console.log(chalk10.cyan.bold(`
1081
+ console.log(chalk11.cyan.bold(`
838
1082
  \uD504\uB85C\uBC14\uC774\uB354 (${providers.length}\uAC1C)
839
1083
  `));
840
1084
  printTable(
841
1085
  ["", "ID", "\uC774\uB984", "\uD0C0\uC785", "\uBAA8\uB378"],
842
1086
  providers.map((p) => [
843
- p.id === defaultP?.id ? chalk10.green("\u25CF") : " ",
1087
+ p.id === defaultP?.id ? chalk11.green("\u25CF") : " ",
844
1088
  p.id,
845
1089
  p.name,
846
1090
  p.type,
@@ -850,18 +1094,10 @@ function registerProviderCommand(program2) {
850
1094
  console.log();
851
1095
  });
852
1096
  prov.command("remove <id>").description("\uD504\uB85C\uBC14\uC774\uB354 \uC81C\uAC70").action((id) => {
853
- if (removeProvider(id)) {
854
- printSuccess(`\uD504\uB85C\uBC14\uC774\uB354 \uC81C\uAC70: ${id}`);
855
- } else {
856
- printError(`\uD504\uB85C\uBC14\uC774\uB354\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${id}`);
857
- }
1097
+ removeProvider(id) ? printSuccess(`\uC81C\uAC70: ${id}`) : printError(`\uC5C6\uC74C: ${id}`);
858
1098
  });
859
1099
  prov.command("use <id>").description("\uAE30\uBCF8 \uD504\uB85C\uBC14\uC774\uB354 \uC124\uC815").action((id) => {
860
- if (setDefaultProvider(id)) {
861
- printSuccess(`\uAE30\uBCF8 \uD504\uB85C\uBC14\uC774\uB354: ${id}`);
862
- } else {
863
- printError(`\uD504\uB85C\uBC14\uC774\uB354\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${id}`);
864
- }
1100
+ setDefaultProvider(id) ? printSuccess(`\uAE30\uBCF8: ${id}`) : printError(`\uC5C6\uC74C: ${id}`);
865
1101
  });
866
1102
  }
867
1103
  var PRESETS;
@@ -870,44 +1106,143 @@ var init_provider = __esm({
870
1106
  "use strict";
871
1107
  init_store();
872
1108
  init_format();
1109
+ init_ui();
873
1110
  PRESETS = [
874
1111
  {
875
1112
  label: "OpenAI",
876
1113
  type: "openai",
877
1114
  defaultModel: "gpt-4o-mini",
878
- models: ["gpt-4o", "gpt-4o-mini", "gpt-4.1", "gpt-4.1-mini", "o3-mini"],
1115
+ models: [
1116
+ "gpt-4o",
1117
+ "gpt-4o-mini",
1118
+ "gpt-4.1",
1119
+ "gpt-4.1-mini",
1120
+ "gpt-4.1-nano",
1121
+ "o3-mini",
1122
+ "o4-mini",
1123
+ "gpt-3.5-turbo"
1124
+ ],
879
1125
  needsKey: true,
880
- keyHint: "https://platform.openai.com/api-keys \uC5D0\uC11C \uBC1C\uAE09"
1126
+ keyHint: "https://platform.openai.com/api-keys",
1127
+ envKey: "OPENAI_API_KEY"
881
1128
  },
882
1129
  {
883
1130
  label: "Google Gemini",
884
1131
  type: "gemini",
885
1132
  baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai",
886
1133
  defaultModel: "gemini-2.0-flash",
887
- models: ["gemini-2.0-flash", "gemini-2.5-pro-preview-06-05", "gemini-2.5-flash-preview-05-20"],
1134
+ models: [
1135
+ "gemini-2.5-pro-preview-06-05",
1136
+ "gemini-2.5-flash-preview-05-20",
1137
+ "gemini-2.0-flash",
1138
+ "gemini-2.0-flash-lite",
1139
+ "gemini-1.5-pro",
1140
+ "gemini-1.5-flash"
1141
+ ],
1142
+ needsKey: true,
1143
+ keyHint: "https://aistudio.google.com/apikey",
1144
+ envKey: "GEMINI_API_KEY"
1145
+ },
1146
+ {
1147
+ label: "Anthropic (Claude)",
1148
+ type: "anthropic",
1149
+ baseUrl: "https://api.anthropic.com/v1",
1150
+ defaultModel: "claude-sonnet-4-20250514",
1151
+ models: [
1152
+ "claude-opus-4-20250514",
1153
+ "claude-sonnet-4-20250514",
1154
+ "claude-haiku-4-5-20251001",
1155
+ "claude-3.5-sonnet-20241022"
1156
+ ],
888
1157
  needsKey: true,
889
- keyHint: "https://aistudio.google.com/apikey \uC5D0\uC11C \uBC1C\uAE09"
1158
+ keyHint: "https://console.anthropic.com/settings/keys",
1159
+ envKey: "ANTHROPIC_API_KEY"
890
1160
  },
891
1161
  {
892
- label: "Ollama (\uB85C\uCEEC)",
1162
+ label: "Ollama (\uB85C\uCEEC \uBB34\uB8CC)",
893
1163
  type: "ollama",
894
1164
  baseUrl: "http://localhost:11434/v1",
895
1165
  defaultModel: "llama3.1",
896
- models: ["llama3.1", "llama3.2", "codellama", "mistral", "qwen2.5-coder"],
1166
+ models: [
1167
+ "llama3.1",
1168
+ "llama3.2",
1169
+ "llama3.3",
1170
+ "codellama",
1171
+ "deepseek-coder-v2",
1172
+ "qwen2.5-coder",
1173
+ "qwen2.5",
1174
+ "mistral",
1175
+ "mixtral",
1176
+ "phi3",
1177
+ "gemma2"
1178
+ ],
897
1179
  needsKey: false,
898
- keyHint: "https://ollama.ai \uC5D0\uC11C \uC124\uCE58"
1180
+ keyHint: "https://ollama.ai \uC124\uCE58 \uD6C4 ollama pull <\uBAA8\uB378>"
899
1181
  },
900
1182
  {
901
- label: "Anthropic (Claude)",
902
- type: "anthropic",
903
- baseUrl: "https://api.anthropic.com/v1",
904
- defaultModel: "claude-sonnet-4-20250514",
905
- models: ["claude-sonnet-4-20250514", "claude-opus-4-20250514", "claude-haiku-4-5-20251001"],
1183
+ label: "Groq (\uBE60\uB978 \uCD94\uB860)",
1184
+ type: "custom",
1185
+ baseUrl: "https://api.groq.com/openai/v1",
1186
+ defaultModel: "llama-3.3-70b-versatile",
1187
+ models: [
1188
+ "llama-3.3-70b-versatile",
1189
+ "llama-3.1-8b-instant",
1190
+ "mixtral-8x7b-32768",
1191
+ "gemma2-9b-it"
1192
+ ],
1193
+ needsKey: true,
1194
+ keyHint: "https://console.groq.com/keys",
1195
+ envKey: "GROQ_API_KEY"
1196
+ },
1197
+ {
1198
+ label: "Together AI",
1199
+ type: "custom",
1200
+ baseUrl: "https://api.together.xyz/v1",
1201
+ defaultModel: "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
1202
+ models: [
1203
+ "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
1204
+ "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
1205
+ "mistralai/Mixtral-8x7B-Instruct-v0.1",
1206
+ "Qwen/Qwen2.5-72B-Instruct-Turbo"
1207
+ ],
1208
+ needsKey: true,
1209
+ keyHint: "https://api.together.xyz/settings/api-keys",
1210
+ envKey: "TOGETHER_API_KEY"
1211
+ },
1212
+ {
1213
+ label: "OpenRouter (\uBA40\uD2F0 \uBAA8\uB378)",
1214
+ type: "custom",
1215
+ baseUrl: "https://openrouter.ai/api/v1",
1216
+ defaultModel: "openai/gpt-4o-mini",
1217
+ models: [
1218
+ "openai/gpt-4o",
1219
+ "openai/gpt-4o-mini",
1220
+ "anthropic/claude-sonnet-4",
1221
+ "anthropic/claude-haiku-4.5",
1222
+ "google/gemini-2.0-flash-exp",
1223
+ "meta-llama/llama-3.3-70b-instruct",
1224
+ "deepseek/deepseek-chat-v3"
1225
+ ],
1226
+ needsKey: true,
1227
+ keyHint: "https://openrouter.ai/keys",
1228
+ envKey: "OPENROUTER_API_KEY"
1229
+ },
1230
+ {
1231
+ label: "DeepSeek",
1232
+ type: "custom",
1233
+ baseUrl: "https://api.deepseek.com/v1",
1234
+ defaultModel: "deepseek-chat",
1235
+ models: [
1236
+ "deepseek-chat",
1237
+ "deepseek-coder",
1238
+ "deepseek-reasoner"
1239
+ ],
906
1240
  needsKey: true,
907
- keyHint: "https://console.anthropic.com/settings/keys \uC5D0\uC11C \uBC1C\uAE09"
1241
+ keyHint: "https://platform.deepseek.com/api_keys",
1242
+ envKey: "DEEPSEEK_API_KEY"
908
1243
  },
909
1244
  {
910
- label: "Custom (OpenAI \uD638\uD658 \uC11C\uBC84)",
1245
+ label: "\uAE30\uD0C0 (OpenAI \uD638\uD658 \uC11C\uBC84)",
911
1246
  type: "custom",
912
1247
  defaultModel: "gpt-4o-mini",
913
1248
  models: [],
@@ -1547,61 +1882,91 @@ var init_client2 = __esm({
1547
1882
  }
1548
1883
  });
1549
1884
 
1550
- // src/utils/ui.ts
1551
- import chalk11 from "chalk";
1552
- import { createInterface as createInterface5 } from "readline";
1553
- function box(lines, color = "cyan") {
1554
- const c = chalk11[color];
1555
- const inner = W - 4;
1556
- const top = c(" \u256D" + "\u2500".repeat(inner) + "\u256E");
1557
- const bot = c(" \u2570" + "\u2500".repeat(inner) + "\u256F");
1558
- const body = lines.map((line) => {
1559
- const clean = line.replace(/\x1b\[[0-9;]*m/g, "");
1560
- const pad = Math.max(0, inner - clean.length);
1561
- return c(" \u2502 ") + line + " ".repeat(pad) + c(" \u2502");
1885
+ // src/api/document.ts
1886
+ var document_exports = {};
1887
+ __export(document_exports, {
1888
+ getDocumentInfo: () => getDocumentInfo,
1889
+ listDocuments: () => listDocuments,
1890
+ uploadDocument: () => uploadDocument
1891
+ });
1892
+ import { createReadStream, statSync } from "fs";
1893
+ import { basename } from "path";
1894
+ async function listDocuments(collectionId) {
1895
+ const client2 = getClient();
1896
+ const params = {};
1897
+ if (collectionId) params.collection_id = collectionId;
1898
+ const res = await client2.get("/api/documents/list", { params });
1899
+ return res.data.documents ?? res.data ?? [];
1900
+ }
1901
+ async function uploadDocument(filePath, collectionId, name) {
1902
+ const client2 = getClient();
1903
+ const stat = statSync(filePath);
1904
+ const fileName = name || basename(filePath);
1905
+ const FormData = (await import("buffer")).Blob ? globalThis.FormData : null;
1906
+ if (!FormData) throw new Error("FormData not available");
1907
+ const form = new FormData();
1908
+ const fileBlob = new Blob([createReadStream(filePath)]);
1909
+ form.append("file", fileBlob, fileName);
1910
+ if (collectionId) form.append("collection_id", collectionId);
1911
+ const res = await client2.post("/api/documents/upload", form, {
1912
+ headers: { "Content-Type": "multipart/form-data" },
1913
+ maxBodyLength: stat.size + 1024 * 1024
1562
1914
  });
1563
- return [top, ...body, bot].join("\n");
1915
+ return res.data;
1564
1916
  }
1565
- function divider(label) {
1566
- if (label) {
1567
- const rest = W - label.length - 6;
1568
- return chalk11.gray(` \u2500\u2500 ${label} ${"\u2500".repeat(Math.max(0, rest))}`);
1569
- }
1570
- return chalk11.gray(" " + "\u2500".repeat(W - 2));
1917
+ async function getDocumentInfo(docId) {
1918
+ const client2 = getClient();
1919
+ const res = await client2.get(`/api/documents/${docId}`);
1920
+ return res.data;
1571
1921
  }
1572
- function statusDot(active, label, detail) {
1573
- const dot = active ? chalk11.green("\u25CF") : chalk11.gray("\u25CB");
1574
- const d = detail ? chalk11.gray(` ${detail}`) : "";
1575
- return ` ${dot} ${label}${d}`;
1922
+ var init_document = __esm({
1923
+ "src/api/document.ts"() {
1924
+ "use strict";
1925
+ init_client();
1926
+ }
1927
+ });
1928
+
1929
+ // src/api/ontology.ts
1930
+ var ontology_exports = {};
1931
+ __export(ontology_exports, {
1932
+ getGraphStats: () => getGraphStats,
1933
+ listGraphs: () => listGraphs,
1934
+ queryGraphRAG: () => queryGraphRAG,
1935
+ queryGraphRAGMultiTurn: () => queryGraphRAGMultiTurn
1936
+ });
1937
+ async function queryGraphRAG(query, graphId, opts) {
1938
+ const client2 = getClient();
1939
+ const res = await client2.post("/api/graph-rag", {
1940
+ query,
1941
+ graph_id: graphId,
1942
+ use_scs: opts?.scs ?? true
1943
+ });
1944
+ return res.data;
1576
1945
  }
1577
- function ask(question) {
1578
- return new Promise((resolve) => {
1579
- const rl = createInterface5({ input: process.stdin, output: process.stdout });
1580
- rl.question(question, (answer) => {
1581
- rl.close();
1582
- resolve(answer.trim());
1583
- });
1946
+ async function queryGraphRAGMultiTurn(query, sessionId, graphId, opts) {
1947
+ const client2 = getClient();
1948
+ const res = await client2.post("/api/graph-rag/multi-turn", {
1949
+ query,
1950
+ session_id: sessionId,
1951
+ graph_id: graphId,
1952
+ max_turns: opts?.maxTurns ?? 5
1584
1953
  });
1954
+ return res.data;
1585
1955
  }
1586
- function welcome() {
1587
- const logo = chalk11.cyan(`
1588
- \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588
1589
- \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588 \u2588\u2588
1590
- \u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588
1591
- \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588
1592
- \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588`) + chalk11.white.bold(`
1593
- \u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588
1594
- \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588 \u2588\u2588
1595
- \u2588\u2588\u2588 \u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588
1596
- \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588
1597
- \u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588`);
1598
- return logo;
1956
+ async function getGraphStats(graphId) {
1957
+ const client2 = getClient();
1958
+ const res = await client2.get(`/api/graph/${graphId}/stats`);
1959
+ return res.data;
1599
1960
  }
1600
- var W;
1601
- var init_ui = __esm({
1602
- "src/utils/ui.ts"() {
1961
+ async function listGraphs() {
1962
+ const client2 = getClient();
1963
+ const res = await client2.get("/api/graph/list");
1964
+ return res.data.graphs ?? res.data ?? [];
1965
+ }
1966
+ var init_ontology = __esm({
1967
+ "src/api/ontology.ts"() {
1603
1968
  "use strict";
1604
- W = Math.min(process.stdout.columns || 60, 70);
1969
+ init_client();
1605
1970
  }
1606
1971
  });
1607
1972
 
@@ -1617,23 +1982,13 @@ function showStatus() {
1617
1982
  const auth = getAuth();
1618
1983
  console.log(divider("\uC0C1\uD0DC"));
1619
1984
  console.log();
1620
- if (provider) {
1621
- console.log(statusDot(true, chalk12.bold("AI \uC5D0\uC774\uC804\uD2B8"), `${provider.name} \xB7 ${provider.model}`));
1622
- } else {
1623
- console.log(statusDot(false, "AI \uC5D0\uC774\uC804\uD2B8", "\uBBF8\uC124\uC815"));
1624
- }
1625
- if (server && auth) {
1626
- console.log(statusDot(true, chalk12.bold("XGEN \uC11C\uBC84"), `${auth.username} \xB7 ${server.replace("https://", "")}`));
1627
- } else if (server) {
1628
- console.log(statusDot(false, "XGEN \uC11C\uBC84", `${server.replace("https://", "")} \xB7 \uB85C\uADF8\uC778 \uD544\uC694`));
1629
- } else {
1630
- console.log(statusDot(false, "XGEN \uC11C\uBC84", "\uBBF8\uC5F0\uACB0"));
1631
- }
1985
+ console.log(provider ? statusDot(true, chalk12.bold("AI \uC5D0\uC774\uC804\uD2B8"), `${provider.name} \xB7 ${provider.model}`) : statusDot(false, "AI \uC5D0\uC774\uC804\uD2B8", "\uBBF8\uC124\uC815"));
1986
+ console.log(server && auth ? statusDot(true, chalk12.bold("XGEN \uC11C\uBC84"), `${auth.username} \xB7 ${server.replace("https://", "")}`) : server ? statusDot(false, "XGEN \uC11C\uBC84", `${server.replace("https://", "")} \xB7 \uB85C\uADF8\uC778 \uD544\uC694`) : statusDot(false, "XGEN \uC11C\uBC84", "\uBBF8\uC5F0\uACB0"));
1632
1987
  console.log();
1633
1988
  }
1634
1989
  async function homeMenu() {
1635
1990
  console.log(welcome());
1636
- console.log(chalk12.gray(" v0.3.2\n"));
1991
+ console.log(chalk12.gray(" v0.4.1\n"));
1637
1992
  showStatus();
1638
1993
  while (true) {
1639
1994
  const provider = getDefaultProvider();
@@ -1642,77 +1997,182 @@ async function homeMenu() {
1642
1997
  const hasServer = !!(server && auth);
1643
1998
  const items = [];
1644
1999
  items.push({
1645
- label: provider ? `${chalk12.bold("AI \uC5D0\uC774\uC804\uD2B8")} ${chalk12.gray(`(${provider.model})`)}` : chalk12.bold("AI \uC5D0\uC774\uC804\uD2B8 \uC2DC\uC791\uD558\uAE30"),
1646
- hint: provider ? "\uB300\uD654 \uC2DC\uC791" : "\uD504\uB85C\uBC14\uC774\uB354 \uC124\uC815 \u2192 \uBC14\uB85C \uC2DC\uC791",
2000
+ key: "a",
2001
+ label: chalk12.bold("AI \uC5D0\uC774\uC804\uD2B8"),
2002
+ hint: provider ? `${provider.model} \xB7 \uB300\uD654 \uC2DC\uC791` : "\uD504\uB85C\uBC14\uC774\uB354 \uC124\uC815 \uD6C4 \uC2DC\uC791",
1647
2003
  action: async () => {
1648
2004
  await agentRepl();
1649
2005
  console.log();
1650
2006
  showStatus();
1651
- return false;
1652
2007
  }
1653
2008
  });
1654
2009
  if (hasServer) {
1655
2010
  items.push({
2011
+ key: "c",
1656
2012
  label: chalk12.bold("\uC6CC\uD06C\uD50C\uB85C\uC6B0 \uCC44\uD305"),
1657
2013
  hint: `${auth.username}@${server.replace("https://", "")}`,
1658
2014
  action: async () => {
1659
2015
  await chat();
1660
2016
  console.log();
1661
2017
  showStatus();
1662
- return false;
1663
2018
  }
1664
2019
  });
1665
2020
  items.push({
2021
+ key: "w",
1666
2022
  label: "\uC6CC\uD06C\uD50C\uB85C\uC6B0 \uBAA9\uB85D",
1667
- hint: "\uC870\uD68C",
2023
+ hint: "\uC804\uCCB4 \uC6CC\uD06C\uD50C\uB85C\uC6B0 \uC870\uD68C",
2024
+ action: async () => {
2025
+ const { workflowList: workflowList2 } = await Promise.resolve().then(() => (init_list(), list_exports));
2026
+ await workflowList2({ detail: true });
2027
+ }
2028
+ });
2029
+ items.push({
2030
+ key: "r",
2031
+ label: "\uC6CC\uD06C\uD50C\uB85C\uC6B0 \uC2E4\uD589",
2032
+ hint: "ID \uC785\uB825 \u2192 \uC2E4\uD589",
1668
2033
  action: async () => {
1669
2034
  const { workflowList: workflowList2 } = await Promise.resolve().then(() => (init_list(), list_exports));
1670
2035
  await workflowList2({ detail: false });
1671
- return false;
2036
+ const id = await ask(chalk12.white("\n \uC6CC\uD06C\uD50C\uB85C\uC6B0 ID (\uC804\uCCB4): "));
2037
+ if (!id) return;
2038
+ const input = await ask(chalk12.white(" \uC785\uB825 \uBA54\uC2DC\uC9C0: "));
2039
+ if (!input) return;
2040
+ const { workflowRun: workflowRun2 } = await Promise.resolve().then(() => (init_run(), run_exports));
2041
+ await workflowRun2(id, input, { logs: false, interactive: false });
2042
+ }
2043
+ });
2044
+ items.push({
2045
+ key: "d",
2046
+ label: "\uBB38\uC11C \uAD00\uB9AC",
2047
+ hint: "\uBB38\uC11C \uBAA9\uB85D \uC870\uD68C",
2048
+ action: async () => {
2049
+ try {
2050
+ const { listDocuments: listDocuments2 } = await Promise.resolve().then(() => (init_document(), document_exports));
2051
+ const docs = await listDocuments2();
2052
+ if (!docs.length) {
2053
+ console.log(chalk12.yellow("\n \uBB38\uC11C\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.\n"));
2054
+ return;
2055
+ }
2056
+ console.log(chalk12.bold(`
2057
+ \uBB38\uC11C (${docs.length}\uAC1C)
2058
+ `));
2059
+ docs.forEach((d, i) => {
2060
+ console.log(` ${chalk12.cyan(`${i + 1}.`)} ${d.file_name ?? d.name ?? "-"} ${chalk12.gray(d.file_type ?? "")}`);
2061
+ });
2062
+ console.log();
2063
+ } catch (err) {
2064
+ console.log(chalk12.red(` \uC624\uB958: ${err.message}
2065
+ `));
2066
+ }
2067
+ }
2068
+ });
2069
+ items.push({
2070
+ key: "o",
2071
+ label: "\uC628\uD1A8\uB85C\uC9C0 \uC9C8\uC758",
2072
+ hint: "GraphRAG \uC6D0\uC0F7 \uC9C8\uC758",
2073
+ action: async () => {
2074
+ const question = await ask(chalk12.white("\n \uC9C8\uBB38: "));
2075
+ if (!question) return;
2076
+ try {
2077
+ console.log(chalk12.gray(" \uC9C8\uC758 \uC911...\n"));
2078
+ const { queryGraphRAG: queryGraphRAG2 } = await Promise.resolve().then(() => (init_ontology(), ontology_exports));
2079
+ const result = await queryGraphRAG2(question);
2080
+ if (result.answer) {
2081
+ console.log(chalk12.bold(" \uB2F5\uBCC0:"));
2082
+ console.log(` ${result.answer}`);
2083
+ }
2084
+ if (result.sources?.length) {
2085
+ console.log(chalk12.bold("\n \uCD9C\uCC98:"));
2086
+ result.sources.forEach((s) => console.log(chalk12.gray(` - ${s}`)));
2087
+ }
2088
+ console.log();
2089
+ } catch (err) {
2090
+ console.log(chalk12.red(` \uC624\uB958: ${err.message}
2091
+ `));
2092
+ }
2093
+ }
2094
+ });
2095
+ items.push({
2096
+ key: "h",
2097
+ label: "\uC2E4\uD589 \uC774\uB825",
2098
+ hint: "\uC6CC\uD06C\uD50C\uB85C\uC6B0 \uC2E4\uD589 \uC774\uB825",
2099
+ action: async () => {
2100
+ try {
2101
+ const { getIOLogs: getIOLogs2 } = await Promise.resolve().then(() => (init_workflow(), workflow_exports));
2102
+ const logs = await getIOLogs2(void 0, 10);
2103
+ if (!logs.length) {
2104
+ console.log(chalk12.yellow("\n \uC2E4\uD589 \uC774\uB825\uC774 \uC5C6\uC2B5\uB2C8\uB2E4.\n"));
2105
+ return;
2106
+ }
2107
+ console.log(chalk12.bold(`
2108
+ \uCD5C\uADFC \uC2E4\uD589 \uC774\uB825 (${logs.length}\uAC1C)
2109
+ `));
2110
+ logs.forEach((log, i) => {
2111
+ console.log(` ${chalk12.cyan(`${i + 1}.`)} ${chalk12.gray(log.created_at ?? "-")}`);
2112
+ console.log(` \uC785\uB825: ${(log.input_data ?? "").slice(0, 50)}`);
2113
+ console.log(` \uCD9C\uB825: ${chalk12.gray((log.output_data ?? "").slice(0, 50))}`);
2114
+ });
2115
+ console.log();
2116
+ } catch (err) {
2117
+ console.log(chalk12.red(` \uC624\uB958: ${err.message}
2118
+ `));
2119
+ }
1672
2120
  }
1673
2121
  });
1674
2122
  }
1675
2123
  items.push({
1676
- label: hasServer ? "XGEN \uC11C\uBC84 \uC7AC\uC124\uC815" : chalk12.bold("XGEN \uC11C\uBC84 \uC5F0\uACB0"),
1677
- hint: hasServer ? "\uC11C\uBC84 \uBCC0\uACBD / \uC7AC\uB85C\uADF8\uC778" : "\uC11C\uBC84 URL + \uB85C\uADF8\uC778",
2124
+ key: "s",
2125
+ label: hasServer ? "\uC11C\uBC84 \uC7AC\uC124\uC815" : chalk12.bold("XGEN \uC11C\uBC84 \uC5F0\uACB0"),
2126
+ hint: hasServer ? "\uC11C\uBC84 \uBCC0\uACBD / \uC7AC\uB85C\uADF8\uC778" : "URL + \uB85C\uADF8\uC778",
1678
2127
  action: async () => {
1679
2128
  await serverSetup();
1680
2129
  showStatus();
1681
- return false;
1682
2130
  }
1683
2131
  });
1684
2132
  items.push({
2133
+ key: "p",
1685
2134
  label: "\uD504\uB85C\uBC14\uC774\uB354 \uAD00\uB9AC",
1686
- hint: `${getProviders().length}\uAC1C \uB4F1\uB85D\uB428`,
2135
+ hint: `${getProviders().length}\uAC1C \uB4F1\uB85D`,
1687
2136
  action: async () => {
1688
2137
  await providerMenu();
1689
2138
  showStatus();
1690
- return false;
1691
2139
  }
1692
2140
  });
1693
2141
  console.log(divider("\uBA54\uB274"));
1694
- for (let i = 0; i < items.length; i++) {
1695
- const num = chalk12.cyan.bold(` ${String(i + 1).padStart(2)}.`);
1696
- console.log(` ${num} ${items[i].label}`);
1697
- console.log(` ${chalk12.gray(items[i].hint)}`);
2142
+ console.log();
2143
+ if (hasServer) {
2144
+ console.log(chalk12.gray(" AI"));
2145
+ }
2146
+ const aiItem = items.find((i) => i.key === "a");
2147
+ console.log(` ${chalk12.cyan.bold(aiItem.key + ".")} ${aiItem.label} ${chalk12.gray("\u2014 " + aiItem.hint)}`);
2148
+ if (hasServer) {
2149
+ console.log();
2150
+ console.log(chalk12.gray(" XGEN \uD50C\uB7AB\uD3FC"));
2151
+ for (const item of items.filter((i) => ["c", "w", "r", "d", "o", "h"].includes(i.key))) {
2152
+ console.log(` ${chalk12.cyan.bold(item.key + ".")} ${item.label} ${chalk12.gray("\u2014 " + item.hint)}`);
2153
+ }
2154
+ }
2155
+ console.log();
2156
+ console.log(chalk12.gray(" \uC124\uC815"));
2157
+ for (const item of items.filter((i) => ["s", "p"].includes(i.key))) {
2158
+ console.log(` ${chalk12.cyan.bold(item.key + ".")} ${item.label} ${chalk12.gray("\u2014 " + item.hint)}`);
1698
2159
  }
1699
- console.log(` ${chalk12.gray(" q. \uC885\uB8CC")}`);
2160
+ console.log(` ${chalk12.gray("q. \uC885\uB8CC")}`);
1700
2161
  console.log();
1701
2162
  const choice = await ask(chalk12.cyan(" \u276F "));
1702
- if (choice === "q" || choice === "exit" || choice === "") {
1703
- if (choice === "") continue;
1704
- console.log(chalk12.gray("\n \u{1F44B} \uB2E4\uC74C\uC5D0 \uB610.\n"));
2163
+ if (choice === "q" || choice === "exit") {
2164
+ console.log(chalk12.gray("\n \u{1F44B}\n"));
1705
2165
  break;
1706
2166
  }
1707
- const idx = parseInt(choice) - 1;
1708
- if (isNaN(idx) || idx < 0 || idx >= items.length) {
1709
- console.log(chalk12.red(` \uC798\uBABB\uB41C \uC785\uB825\uC785\uB2C8\uB2E4.
2167
+ if (!choice) continue;
2168
+ const selected = items.find((i) => i.key === choice);
2169
+ if (!selected) {
2170
+ console.log(chalk12.red(` "${choice}" \u2014 \uC798\uBABB\uB41C \uC785\uB825
1710
2171
  `));
1711
2172
  continue;
1712
2173
  }
1713
2174
  try {
1714
- const shouldExit = await items[idx].action();
1715
- if (shouldExit) break;
2175
+ await selected.action();
1716
2176
  } catch (err) {
1717
2177
  console.log(chalk12.red(`
1718
2178
  \uC624\uB958: ${err.message}
@@ -1722,7 +2182,7 @@ async function homeMenu() {
1722
2182
  }
1723
2183
  async function serverSetup() {
1724
2184
  console.log();
1725
- console.log(box(["XGEN \uC11C\uBC84 \uC5F0\uACB0"], "cyan"));
2185
+ console.log(box(["XGEN \uC11C\uBC84 \uC5F0\uACB0"]));
1726
2186
  console.log();
1727
2187
  const currentServer = getServer();
1728
2188
  const urlInput = await ask(
@@ -1730,19 +2190,17 @@ async function serverSetup() {
1730
2190
  );
1731
2191
  const url = urlInput || currentServer;
1732
2192
  if (!url) {
1733
- console.log(chalk12.red(" URL\uC774 \uD544\uC694\uD569\uB2C8\uB2E4.\n"));
2193
+ console.log(chalk12.red(" URL \uD544\uC694.\n"));
1734
2194
  return;
1735
2195
  }
1736
2196
  const { setServer: setServer2 } = await Promise.resolve().then(() => (init_store(), store_exports));
1737
2197
  setServer2(url);
1738
- console.log(chalk12.green(` \u2713 \uC11C\uBC84: ${url}
2198
+ console.log(chalk12.green(` \u2713 ${url}
1739
2199
  `));
1740
- console.log(chalk12.bold(" \uB85C\uADF8\uC778"));
1741
- console.log();
1742
2200
  const email = await ask(chalk12.white(" \uC774\uBA54\uC77C: "));
1743
2201
  const password = await ask(chalk12.white(" \uBE44\uBC00\uBC88\uD638: "));
1744
2202
  if (!email || !password) {
1745
- console.log(chalk12.red(" \uC774\uBA54\uC77C\uACFC \uBE44\uBC00\uBC88\uD638\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4.\n"));
2203
+ console.log(chalk12.red(" \uD544\uC694.\n"));
1746
2204
  return;
1747
2205
  }
1748
2206
  try {
@@ -1776,7 +2234,7 @@ async function providerMenu() {
1776
2234
  const providers = getProviders();
1777
2235
  const defaultP = getDefaultProvider();
1778
2236
  console.log();
1779
- console.log(box(["\uD504\uB85C\uBC14\uC774\uB354 \uAD00\uB9AC"], "cyan"));
2237
+ console.log(box(["\uD504\uB85C\uBC14\uC774\uB354 \uAD00\uB9AC"]));
1780
2238
  console.log();
1781
2239
  if (providers.length > 0) {
1782
2240
  for (const p of providers) {
@@ -1785,42 +2243,34 @@ async function providerMenu() {
1785
2243
  }
1786
2244
  console.log();
1787
2245
  } else {
1788
- console.log(chalk12.gray(" \uB4F1\uB85D\uB41C \uD504\uB85C\uBC14\uC774\uB354\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.\n"));
1789
- }
1790
- const items = ["\uC0C8\uB85C \uCD94\uAC00"];
1791
- if (providers.length > 1) items.push("\uAE30\uBCF8 \uBCC0\uACBD");
1792
- if (providers.length > 0) items.push("\uC0AD\uC81C");
1793
- items.push("\uB3CC\uC544\uAC00\uAE30");
1794
- items.forEach((item, i) => {
1795
- console.log(` ${chalk12.cyan(`${i + 1}.`)} ${item}`);
1796
- });
2246
+ console.log(chalk12.gray(" \uC5C6\uC74C\n"));
2247
+ }
2248
+ const opts = ["\uC0C8\uB85C \uCD94\uAC00"];
2249
+ if (providers.length > 1) opts.push("\uAE30\uBCF8 \uBCC0\uACBD");
2250
+ if (providers.length > 0) opts.push("\uC0AD\uC81C");
2251
+ opts.push("\uB3CC\uC544\uAC00\uAE30");
2252
+ opts.forEach((o, i) => console.log(` ${chalk12.cyan(`${i + 1}.`)} ${o}`));
1797
2253
  console.log();
1798
- const choice = await ask(chalk12.cyan(" \u276F "));
1799
- const ci = parseInt(choice);
2254
+ const c = await ask(chalk12.cyan(" \u276F "));
2255
+ const ci = parseInt(c);
1800
2256
  if (ci === 1) {
1801
2257
  await guidedProviderSetup();
1802
- } else if (items[ci - 1] === "\uAE30\uBCF8 \uBCC0\uACBD") {
2258
+ } else if (opts[ci - 1] === "\uAE30\uBCF8 \uBCC0\uACBD") {
1803
2259
  console.log();
1804
- providers.forEach((p, i) => {
1805
- console.log(` ${chalk12.cyan(`${i + 1}.`)} ${p.name} (${p.model})`);
1806
- });
2260
+ providers.forEach((p, i) => console.log(` ${chalk12.cyan(`${i + 1}.`)} ${p.name} (${p.model})`));
1807
2261
  console.log();
1808
- const pc = await ask(chalk12.cyan(" \u276F "));
1809
- const pi = parseInt(pc) - 1;
2262
+ const pi = parseInt(await ask(chalk12.cyan(" \u276F "))) - 1;
1810
2263
  if (pi >= 0 && pi < providers.length) {
1811
2264
  const { setDefaultProvider: setDefaultProvider2 } = await Promise.resolve().then(() => (init_store(), store_exports));
1812
2265
  setDefaultProvider2(providers[pi].id);
1813
2266
  console.log(chalk12.green(` \u2713 \uAE30\uBCF8: ${providers[pi].name}
1814
2267
  `));
1815
2268
  }
1816
- } else if (items[ci - 1] === "\uC0AD\uC81C") {
2269
+ } else if (opts[ci - 1] === "\uC0AD\uC81C") {
1817
2270
  console.log();
1818
- providers.forEach((p, i) => {
1819
- console.log(` ${chalk12.cyan(`${i + 1}.`)} ${p.name} (${p.model})`);
1820
- });
2271
+ providers.forEach((p, i) => console.log(` ${chalk12.cyan(`${i + 1}.`)} ${p.name} (${p.model})`));
1821
2272
  console.log();
1822
- const dc = await ask(chalk12.white(" \uC0AD\uC81C\uD560 \uBC88\uD638: "));
1823
- const di = parseInt(dc) - 1;
2273
+ const di = parseInt(await ask(chalk12.white(" \uC0AD\uC81C \uBC88\uD638: "))) - 1;
1824
2274
  if (di >= 0 && di < providers.length) {
1825
2275
  const { removeProvider: removeProvider2 } = await Promise.resolve().then(() => (init_store(), store_exports));
1826
2276
  removeProvider2(providers[di].id);
@@ -1842,7 +2292,7 @@ var init_home = __esm({
1842
2292
 
1843
2293
  // src/commands/agent.ts
1844
2294
  import chalk13 from "chalk";
1845
- import { createInterface as createInterface6 } from "readline";
2295
+ import { createInterface as createInterface5 } from "readline";
1846
2296
  async function agentRepl() {
1847
2297
  let provider = getDefaultProvider();
1848
2298
  if (!provider) {
@@ -1880,7 +2330,7 @@ async function agentRepl() {
1880
2330
  `${chalk13.gray("/help \uB3C4\uC6C0\uB9D0 \xB7 /home \uD648 \xB7 /exit \uC885\uB8CC")}`
1881
2331
  ]));
1882
2332
  console.log();
1883
- const rl = createInterface6({ input: process.stdin, output: process.stdout });
2333
+ const rl = createInterface5({ input: process.stdin, output: process.stdout });
1884
2334
  const askUser = () => new Promise((resolve) => rl.question(chalk13.cyan.bold(" \u276F "), (a) => resolve(a.trim())));
1885
2335
  process.on("SIGINT", () => {
1886
2336
  console.log(chalk13.gray("\n\uC885\uB8CC\uD569\uB2C8\uB2E4."));
@@ -2277,163 +2727,8 @@ async function workflowInfo(workflowId) {
2277
2727
  }
2278
2728
  }
2279
2729
 
2280
- // src/commands/workflow/run.ts
2281
- init_store();
2282
- init_workflow();
2283
- init_sse();
2284
- init_format();
2285
- import chalk7 from "chalk";
2286
- import { randomUUID } from "crypto";
2287
-
2288
- // src/utils/markdown.ts
2289
- import chalk6 from "chalk";
2290
- var CODE_BLOCK_RE = /```(\w*)\n([\s\S]*?)```/g;
2291
- var INLINE_CODE_RE = /`([^`]+)`/g;
2292
- var BOLD_RE = /\*\*(.+?)\*\*/g;
2293
- var HEADING_RE = /^(#{1,3})\s+(.+)$/gm;
2294
- var LIST_RE = /^(\s*)[-*]\s+(.+)$/gm;
2295
- var LINK_RE = /\[([^\]]+)\]\(([^)]+)\)/g;
2296
- function renderMarkdown(text) {
2297
- let result = text;
2298
- result = result.replace(CODE_BLOCK_RE, (_match, lang, code) => {
2299
- const trimmed = code.trimEnd();
2300
- const header = lang ? chalk6.gray(` \u2500\u2500 ${lang} \u2500\u2500`) : chalk6.gray(" \u2500\u2500 code \u2500\u2500");
2301
- const lines = trimmed.split("\n").map((l) => chalk6.white(` ${l}`)).join("\n");
2302
- return `
2303
- ${header}
2304
- ${lines}
2305
- ${chalk6.gray(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")}
2306
- `;
2307
- });
2308
- result = result.replace(INLINE_CODE_RE, (_m, code) => chalk6.cyan(`\`${code}\``));
2309
- result = result.replace(BOLD_RE, (_m, text2) => chalk6.bold(text2));
2310
- result = result.replace(HEADING_RE, (_m, hashes, text2) => {
2311
- if (hashes.length === 1) return chalk6.bold.underline(text2);
2312
- if (hashes.length === 2) return chalk6.bold(text2);
2313
- return chalk6.bold.dim(text2);
2314
- });
2315
- result = result.replace(LIST_RE, (_m, indent, text2) => `${indent}${chalk6.cyan("\u2022")} ${text2}`);
2316
- result = result.replace(LINK_RE, (_m, label, url) => `${chalk6.blue.underline(label)} ${chalk6.gray(`(${url})`)}`);
2317
- return result;
2318
- }
2319
-
2320
- // src/commands/workflow/run.ts
2321
- async function workflowRun(workflowId, input, opts) {
2322
- const auth = requireAuth();
2323
- let workflowName = workflowId;
2324
- try {
2325
- const detail = await getWorkflowDetail(workflowId);
2326
- workflowName = detail.workflow_name ?? workflowId;
2327
- } catch {
2328
- }
2329
- if (!input) {
2330
- if (opts.interactive || !process.stdin.isTTY) {
2331
- const { createInterface: createInterface8 } = await import("readline");
2332
- const rl = createInterface8({ input: process.stdin, output: process.stdout });
2333
- input = await new Promise((resolve) => {
2334
- rl.question(chalk7.cyan("\uC785\uB825> "), (answer) => {
2335
- rl.close();
2336
- resolve(answer.trim());
2337
- });
2338
- });
2339
- } else {
2340
- printError("\uC785\uB825\uAC12\uC774 \uD544\uC694\uD569\uB2C8\uB2E4. \uC0AC\uC6A9\uBC95:");
2341
- console.log(' xgen workflow run <id> "\uC785\uB825 \uD14D\uC2A4\uFFFD\uFFFD\uFFFD"');
2342
- console.log(" xgen workflow run -i <id>");
2343
- process.exit(1);
2344
- }
2345
- }
2346
- if (!input) {
2347
- printError("\uC785\uB825\uAC12\uC774 \uBE44\uC5B4\uC788\uC2B5\uB2C8\uB2E4");
2348
- process.exit(1);
2349
- }
2350
- const interactionId = `cli_${randomUUID().slice(0, 8)}`;
2351
- printHeader(`\uC2E4\uD589: ${workflowName}`);
2352
- printInfo(`\uC785\uB825: ${input}`);
2353
- console.log();
2354
- try {
2355
- const stream = await executeWorkflowStream({
2356
- workflow_id: workflowId,
2357
- workflow_name: workflowName,
2358
- input_data: input,
2359
- interaction_id: interactionId
2360
- });
2361
- let hasOutput = false;
2362
- let fullResponse = "";
2363
- await parseSSEStream(
2364
- stream,
2365
- (event) => {
2366
- switch (event.type) {
2367
- case "token":
2368
- if (event.content) {
2369
- if (!hasOutput) {
2370
- hasOutput = true;
2371
- console.log();
2372
- }
2373
- process.stdout.write(event.content);
2374
- fullResponse += event.content;
2375
- }
2376
- break;
2377
- case "log":
2378
- if (opts.logs && event.content) {
2379
- process.stderr.write(chalk7.gray(`[LOG] ${event.content}
2380
- `));
2381
- }
2382
- break;
2383
- case "node_status":
2384
- if (opts.logs) {
2385
- const nodeName = event.node_name ?? event.node_id ?? "?";
2386
- const status = event.status ?? "?";
2387
- process.stderr.write(
2388
- chalk7.gray(`[\uB178\uB4DC] ${nodeName}: ${status}
2389
- `)
2390
- );
2391
- }
2392
- break;
2393
- case "tool":
2394
- if (opts.logs) {
2395
- process.stderr.write(chalk7.gray(`[\uB3C4\uAD6C] ${JSON.stringify(event.data)}
2396
- `));
2397
- }
2398
- break;
2399
- case "complete":
2400
- break;
2401
- case "error":
2402
- console.log();
2403
- printError(event.error ?? event.content ?? "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958");
2404
- break;
2405
- default:
2406
- if (event.content) {
2407
- if (!hasOutput) {
2408
- process.stdout.write(chalk7.green("\uC751\uB2F5: "));
2409
- hasOutput = true;
2410
- }
2411
- process.stdout.write(event.content);
2412
- }
2413
- }
2414
- },
2415
- () => {
2416
- if (hasOutput) {
2417
- console.log();
2418
- if (fullResponse.includes("```") || fullResponse.includes("**")) {
2419
- console.log(chalk7.gray("\u2500".repeat(40)));
2420
- console.log(renderMarkdown(fullResponse));
2421
- }
2422
- }
2423
- console.log();
2424
- console.log(chalk7.gray(`\uC138\uC158: ${interactionId}`));
2425
- },
2426
- (err) => {
2427
- console.log();
2428
- printError(`\uC2A4\uD2B8\uB9AC\uBC0D \uC624\uB958: ${err.message}`);
2429
- }
2430
- );
2431
- } catch (err) {
2432
- const msg = err?.response?.data?.detail ?? err.message;
2433
- printError(`\uC2E4\uD589 \uC2E4\uD328: ${msg}`);
2434
- process.exit(1);
2435
- }
2436
- }
2730
+ // src/commands/workflow/index.ts
2731
+ init_run();
2437
2732
 
2438
2733
  // src/commands/workflow/history.ts
2439
2734
  init_store();
@@ -2489,43 +2784,9 @@ init_agent();
2489
2784
 
2490
2785
  // src/commands/doc.ts
2491
2786
  init_store();
2492
- import chalk14 from "chalk";
2493
-
2494
- // src/api/document.ts
2495
- init_client();
2496
- import { createReadStream, statSync } from "fs";
2497
- import { basename } from "path";
2498
- async function listDocuments(collectionId) {
2499
- const client2 = getClient();
2500
- const params = {};
2501
- if (collectionId) params.collection_id = collectionId;
2502
- const res = await client2.get("/api/documents/list", { params });
2503
- return res.data.documents ?? res.data ?? [];
2504
- }
2505
- async function uploadDocument(filePath, collectionId, name) {
2506
- const client2 = getClient();
2507
- const stat = statSync(filePath);
2508
- const fileName = name || basename(filePath);
2509
- const FormData = (await import("buffer")).Blob ? globalThis.FormData : null;
2510
- if (!FormData) throw new Error("FormData not available");
2511
- const form = new FormData();
2512
- const fileBlob = new Blob([createReadStream(filePath)]);
2513
- form.append("file", fileBlob, fileName);
2514
- if (collectionId) form.append("collection_id", collectionId);
2515
- const res = await client2.post("/api/documents/upload", form, {
2516
- headers: { "Content-Type": "multipart/form-data" },
2517
- maxBodyLength: stat.size + 1024 * 1024
2518
- });
2519
- return res.data;
2520
- }
2521
- async function getDocumentInfo(docId) {
2522
- const client2 = getClient();
2523
- const res = await client2.get(`/api/documents/${docId}`);
2524
- return res.data;
2525
- }
2526
-
2527
- // src/commands/doc.ts
2787
+ init_document();
2528
2788
  init_format();
2789
+ import chalk14 from "chalk";
2529
2790
  function registerDocCommand(program2) {
2530
2791
  const doc = program2.command("doc").description("\uBB38\uC11C \uAD00\uB9AC");
2531
2792
  doc.command("list").alias("ls").description("\uBB38\uC11C \uBAA9\uB85D \uC870\uD68C").option("-c, --collection <id>", "\uCEEC\uB809\uC158 ID").action(async (opts) => {
@@ -2579,38 +2840,10 @@ function registerDocCommand(program2) {
2579
2840
 
2580
2841
  // src/commands/ontology.ts
2581
2842
  init_store();
2582
- import chalk15 from "chalk";
2583
- import { createInterface as createInterface7 } from "readline";
2584
-
2585
- // src/api/ontology.ts
2586
- init_client();
2587
- async function queryGraphRAG(query, graphId, opts) {
2588
- const client2 = getClient();
2589
- const res = await client2.post("/api/graph-rag", {
2590
- query,
2591
- graph_id: graphId,
2592
- use_scs: opts?.scs ?? true
2593
- });
2594
- return res.data;
2595
- }
2596
- async function queryGraphRAGMultiTurn(query, sessionId, graphId, opts) {
2597
- const client2 = getClient();
2598
- const res = await client2.post("/api/graph-rag/multi-turn", {
2599
- query,
2600
- session_id: sessionId,
2601
- graph_id: graphId,
2602
- max_turns: opts?.maxTurns ?? 5
2603
- });
2604
- return res.data;
2605
- }
2606
- async function getGraphStats(graphId) {
2607
- const client2 = getClient();
2608
- const res = await client2.get(`/api/graph/${graphId}/stats`);
2609
- return res.data;
2610
- }
2611
-
2612
- // src/commands/ontology.ts
2843
+ init_ontology();
2613
2844
  init_format();
2845
+ import chalk15 from "chalk";
2846
+ import { createInterface as createInterface6 } from "readline";
2614
2847
  import { randomUUID as randomUUID3 } from "crypto";
2615
2848
  function registerOntologyCommand(program2) {
2616
2849
  const ont = program2.command("ontology").alias("ont").description("\uC628\uD1A8\uB85C\uC9C0 GraphRAG \uC9C8\uC758");
@@ -2641,7 +2874,7 @@ function registerOntologyCommand(program2) {
2641
2874
  const sessionId = randomUUID3();
2642
2875
  printHeader("Ontology Chat");
2643
2876
  console.log(chalk15.gray("\uBA40\uD2F0\uD134 GraphRAG \uB300\uD654. exit\uB85C \uC885\uB8CC.\n"));
2644
- const rl = createInterface7({ input: process.stdin, output: process.stdout });
2877
+ const rl = createInterface6({ input: process.stdin, output: process.stdout });
2645
2878
  const ask2 = () => new Promise((resolve) => rl.question(chalk15.green("\u276F "), (a) => resolve(a.trim())));
2646
2879
  while (true) {
2647
2880
  const input = await ask2();