@aipack-ai/cli 0.0.1 → 0.0.2

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.
@@ -1,11 +1,3 @@
1
- // src/cli.ts
2
- import chalk7 from "chalk";
3
-
4
- // src/commands/approvals.ts
5
- import path2 from "path";
6
- import chalk from "chalk";
7
- import { FileApprovalStore, createApprovalManager } from "@aipack-ai/agent";
8
-
9
1
  // src/version.ts
10
2
  import os from "os";
11
3
  import path from "path";
@@ -13,13 +5,13 @@ import path from "path";
13
5
  // package.json
14
6
  var package_default = {
15
7
  name: "@aipack-ai/cli",
16
- version: "0.0.1",
8
+ version: "0.0.2",
17
9
  description: "aipack CLI - \u57FA\u4E8E @aipack-ai/agent \u7684\u7EC8\u7AEF AI \u52A9\u624B",
18
10
  type: "module",
19
11
  main: "./dist/index.js",
20
12
  types: "./dist/index.d.ts",
21
13
  bin: {
22
- aipack: "dist/cli.js"
14
+ aipack: "dist/bin.js"
23
15
  },
24
16
  exports: {
25
17
  ".": {
@@ -35,7 +27,7 @@ var package_default = {
35
27
  build: "tsup",
36
28
  prebuild: "pnpm --filter @aipack-ai/agent build",
37
29
  typecheck: "tsc --noEmit",
38
- dev: "tsx src/cli.ts"
30
+ dev: "tsx src/bin.ts"
39
31
  },
40
32
  keywords: [
41
33
  "cli",
@@ -61,7 +53,7 @@ var package_default = {
61
53
  };
62
54
 
63
55
  // src/version.ts
64
- var APP_NAME = package_default.name.replace(/^@[^/]+\//, "");
56
+ var APP_NAME = Object.keys(package_default.bin ?? {})[0] ?? package_default.name.replace(/^@[^/]+\//, "");
65
57
  var VERSION = package_default.version;
66
58
  function defaultConfigDir() {
67
59
  return process.env.AIPACK_CONFIG_DIR ?? path.join(os.homedir(), ".aipack");
@@ -73,101 +65,6 @@ function encodeDir(p) {
73
65
  return p.replace(/[^a-zA-Z0-9_-]/g, "_");
74
66
  }
75
67
 
76
- // src/commands/approvals.ts
77
- function createStore() {
78
- return new FileApprovalStore({
79
- baseDir: path2.join(defaultConfigDir(), "approvals")
80
- });
81
- }
82
- async function handleApprovalsCommand(args) {
83
- const [sub, ...rest] = args;
84
- if (!sub || sub === "help" || sub === "--help") {
85
- printUsage();
86
- return 0;
87
- }
88
- const store = createStore();
89
- if (sub === "list") {
90
- const pending = await store.load();
91
- if (pending.length === 0) {
92
- console.log(chalk.dim("\uFF08\u65E0\u672A\u51B3\u5BA1\u6279\u5355\uFF09"));
93
- return 0;
94
- }
95
- for (const p of pending) {
96
- printApproval(p);
97
- }
98
- return 0;
99
- }
100
- if (sub === "approve" || sub === "deny") {
101
- const id = rest[0];
102
- if (!id) {
103
- console.error(chalk.red(`\u7528\u6CD5: aipack approvals ${sub} <id>`));
104
- return 1;
105
- }
106
- const manager = createApprovalManager({ store });
107
- await manager.restore();
108
- const ok = manager.resolve(id, sub === "approve");
109
- manager.close();
110
- if (!ok) {
111
- console.error(chalk.yellow(`\u5BA1\u6279\u5355 ${id} \u4E0D\u5B58\u5728\u6216\u5DF2\u7ED3\u7B97`));
112
- return 1;
113
- }
114
- console.log(chalk.green(`\u5DF2${sub === "approve" ? "\u6279\u51C6" : "\u9A73\u56DE"} ${id}`));
115
- return 0;
116
- }
117
- printUsage();
118
- console.error(chalk.red(`\u672A\u77E5\u5B50\u547D\u4EE4: ${sub}`));
119
- return 1;
120
- }
121
- function printApproval(p) {
122
- const created = new Date(p.createdAt).toLocaleString();
123
- const expires = p.expiresAt ? chalk.dim(` \u8FC7\u671F ${new Date(p.expiresAt).toLocaleTimeString()}`) : "";
124
- console.log(`${chalk.cyan(p.id)} ${chalk.bold(p.toolName)} ${chalk.dim(created)}${expires}`);
125
- if (p.permissions.length > 0) {
126
- console.log(chalk.dim(` \u80FD\u529B: ${p.permissions.join(", ")}`));
127
- }
128
- const argsStr = JSON.stringify(p.args);
129
- if (argsStr && argsStr !== "{}") {
130
- console.log(chalk.dim(` \u53C2\u6570: ${argsStr.length > 120 ? `${argsStr.slice(0, 120)}\u2026` : argsStr}`));
131
- }
132
- }
133
- function printUsage() {
134
- console.log(`\u7528\u6CD5:
135
- aipack approvals list \u5217\u51FA\u672A\u51B3\u5BA1\u6279\u5355
136
- aipack approvals approve <id> \u6279\u51C6
137
- aipack approvals deny <id> \u9A73\u56DE`);
138
- }
139
-
140
- // src/commands/models.ts
141
- import chalk2 from "chalk";
142
- import { getBuiltinProviders, getBuiltinModels, hasProviderConfigured } from "@aipack-ai/agent";
143
- function listModels(search) {
144
- const term = typeof search === "string" ? search.toLowerCase() : void 0;
145
- let total = 0;
146
- for (const provider of getBuiltinProviders()) {
147
- const models = getBuiltinModels(provider.id);
148
- const matched = term ? models.filter((m) => m.id.toLowerCase().includes(term) || m.name.toLowerCase().includes(term) || provider.id.includes(term)) : models;
149
- if (matched.length === 0) continue;
150
- const configured = hasProviderConfigured(provider.id);
151
- const badge = configured ? chalk2.green("\u2713") : chalk2.dim("\xB7");
152
- console.log(`${badge} ${chalk2.bold(provider.name)} ${chalk2.dim(`(${provider.id})`)}`);
153
- for (const m of matched) {
154
- const flags = [
155
- m.reasoning ? chalk2.dim("\u63A8\u7406") : null,
156
- `${m.contextWindow / 1e3 | 0}k`
157
- ].filter(Boolean).join(" ");
158
- console.log(` ${m.id.padEnd(44)} ${chalk2.dim(flags)}`);
159
- total++;
160
- }
161
- }
162
- console.log(chalk2.dim(`
163
- \u5171 ${total} \u4E2A\u6A21\u578B\u3002\u2713 = \u5DF2\u914D\u7F6E API Key\uFF08${getEnvHint()}\uFF09`));
164
- return 0;
165
- }
166
- function getEnvHint() {
167
- const provider = getBuiltinProviders().find((p) => hasProviderConfigured(p.id));
168
- return provider ? `${provider.envVar} \u5DF2\u8BBE\u7F6E` : "\u672A\u68C0\u6D4B\u5230\u4EFB\u4F55 API Key";
169
- }
170
-
171
68
  // src/args.ts
172
69
  var VALID_THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "max"];
173
70
  function isValidThinkingLevel(level) {
@@ -339,32 +236,13 @@ ${"\u73AF\u5883\u53D8\u91CF:"}
339
236
  `);
340
237
  }
341
238
 
342
- // src/builder.ts
343
- import fs2 from "fs/promises";
344
- import path4 from "path";
345
- import { pathToFileURL } from "url";
346
- import {
347
- createRuntime,
348
- adaptAiModel,
349
- createStreamFnFromAi,
350
- getBuiltinModel,
351
- getBuiltinModels as getBuiltinModels2,
352
- getBuiltinProviders as getBuiltinProviders2,
353
- BUILTIN_PROVIDERS,
354
- hasProviderConfigured as hasProviderConfigured2,
355
- createFileSessionStorage,
356
- createPermissionPolicy,
357
- createApprovalManager as createApprovalManager2,
358
- FileApprovalStore as FileApprovalStore2
359
- } from "@aipack-ai/agent";
360
-
361
239
  // src/tools.ts
362
240
  import fs from "fs/promises";
363
- import path3 from "path";
241
+ import path2 from "path";
364
242
  import { spawn } from "child_process";
365
243
  var workspaceRoot = process.cwd();
366
244
  function resolveInWorkspace(p) {
367
- const abs = path3.resolve(workspaceRoot, p);
245
+ const abs = path2.resolve(workspaceRoot, p);
368
246
  if (!abs.startsWith(workspaceRoot)) {
369
247
  throw new Error(`\u8DEF\u5F84\u8D8A\u754C\uFF1A${p}\uFF08\u5DE5\u4F5C\u533A\uFF1A${workspaceRoot}\uFF09`);
370
248
  }
@@ -430,7 +308,7 @@ var writeTool = {
430
308
  const args = rawArgs;
431
309
  try {
432
310
  const abs = resolveInWorkspace(args.file);
433
- await fs.mkdir(path3.dirname(abs), { recursive: true });
311
+ await fs.mkdir(path2.dirname(abs), { recursive: true });
434
312
  await fs.writeFile(abs, args.content, "utf8");
435
313
  return textResult(`\u5DF2\u5199\u5165 ${args.file}\uFF08${args.content.length} \u5B57\u7B26\uFF09`, { file: args.file });
436
314
  } catch (err) {
@@ -557,9 +435,26 @@ function selectTools(options) {
557
435
  }
558
436
 
559
437
  // src/builder.ts
438
+ import fs2 from "fs/promises";
439
+ import path3 from "path";
440
+ import { pathToFileURL } from "url";
441
+ import {
442
+ createRuntime,
443
+ adaptAiModel,
444
+ createStreamFnFromAi,
445
+ getBuiltinModel,
446
+ getBuiltinModels,
447
+ getBuiltinProviders,
448
+ BUILTIN_PROVIDERS,
449
+ hasProviderConfigured,
450
+ createFileSessionStorage,
451
+ createPermissionPolicy,
452
+ createApprovalManager,
453
+ FileApprovalStore
454
+ } from "@aipack-ai/agent";
560
455
  async function loadConfig(cwd) {
561
456
  for (const file of ["aipack.config.js", "aipack.config.mjs"]) {
562
- const full = path4.join(cwd, file);
457
+ const full = path3.join(cwd, file);
563
458
  try {
564
459
  await fs2.access(full);
565
460
  const mod = await import(pathToFileURL(full).href);
@@ -578,9 +473,9 @@ function splitModelSpec(args) {
578
473
  return { provider: args.provider, modelId: args.model };
579
474
  }
580
475
  function detectDefaultProvider() {
581
- for (const p of getBuiltinProviders2()) {
582
- if (hasProviderConfigured2(p.id)) {
583
- const models = getBuiltinModels2(p.id);
476
+ for (const p of getBuiltinProviders()) {
477
+ if (hasProviderConfigured(p.id)) {
478
+ const models = getBuiltinModels(p.id);
584
479
  if (models.length > 0) return { id: p.id, modelId: models[0].id };
585
480
  }
586
481
  }
@@ -654,9 +549,9 @@ async function buildRuntime(options) {
654
549
  const approvalCaps = new Set(config.approvals?.capabilities ?? DEFAULT_APPROVAL_CAPABILITIES);
655
550
  let approvalManager;
656
551
  if (approvalsEnabled) {
657
- approvalManager = createApprovalManager2({
658
- store: new FileApprovalStore2({
659
- baseDir: path4.join(defaultConfigDir(), "approvals")
552
+ approvalManager = createApprovalManager({
553
+ store: new FileApprovalStore({
554
+ baseDir: path3.join(defaultConfigDir(), "approvals")
660
555
  })
661
556
  });
662
557
  await approvalManager.restore();
@@ -731,14 +626,14 @@ function buildSystemPrompt(args) {
731
626
 
732
627
  // src/initial-message.ts
733
628
  import fs3 from "fs/promises";
734
- import path5 from "path";
629
+ import path4 from "path";
735
630
  var IMAGE_EXT = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp"]);
736
631
  async function buildInitialMessage(messages, fileArgs, stdinText) {
737
632
  const parts = [];
738
633
  const media = [];
739
634
  for (const file of fileArgs) {
740
- const abs = path5.resolve(process.cwd(), file);
741
- const ext = path5.extname(abs).toLowerCase();
635
+ const abs = path4.resolve(process.cwd(), file);
636
+ const ext = path4.extname(abs).toLowerCase();
742
637
  try {
743
638
  if (IMAGE_EXT.has(ext)) {
744
639
  const buf = await fs3.readFile(abs);
@@ -765,10 +660,10 @@ ${stdinText.trim()}
765
660
  }
766
661
 
767
662
  // src/modes/print.ts
768
- import chalk4 from "chalk";
663
+ import chalk2 from "chalk";
769
664
 
770
665
  // src/modes/render.ts
771
- import chalk3 from "chalk";
666
+ import chalk from "chalk";
772
667
  var ChunkRenderer = class {
773
668
  constructor(opts = {}) {
774
669
  this.opts = opts;
@@ -784,26 +679,26 @@ var ChunkRenderer = class {
784
679
  break;
785
680
  case "thinking": {
786
681
  if (this.opts.showThinking && chunk.content) {
787
- process.stdout.write(chalk3.dim(chunk.content));
682
+ process.stdout.write(chalk.dim(chunk.content));
788
683
  } else if (!this.thinkingShown) {
789
684
  this.thinkingShown = true;
790
- err.write(chalk3.dim(" (\u601D\u8003\u4E2D...)\n"));
685
+ err.write(chalk.dim(" (\u601D\u8003\u4E2D...)\n"));
791
686
  }
792
687
  break;
793
688
  }
794
689
  case "tool_start":
795
690
  this.inTool = true;
796
- err.write(chalk3.cyan(`
691
+ err.write(chalk.cyan(`
797
692
  \u2699 ${chunk.toolName} `));
798
693
  break;
799
694
  case "tool_end":
800
695
  if (this.inTool) {
801
- err.write(chunk.isError ? chalk3.red(" \u2717\n") : chalk3.green(" \u2713\n"));
696
+ err.write(chunk.isError ? chalk.red(" \u2717\n") : chalk.green(" \u2713\n"));
802
697
  this.inTool = false;
803
698
  }
804
699
  break;
805
700
  case "error":
806
- err.write(chalk3.red(`
701
+ err.write(chalk.red(`
807
702
  \u9519\u8BEF: ${chunk.content ?? "\u672A\u77E5\u9519\u8BEF"}
808
703
  `));
809
704
  break;
@@ -828,7 +723,7 @@ async function runPrintMode(runtime, request) {
828
723
  renderer.render(chunk);
829
724
  }
830
725
  } catch (err) {
831
- process.stderr.write(chalk4.red(`\u9519\u8BEF: ${err instanceof Error ? err.message : String(err)}
726
+ process.stderr.write(chalk2.red(`\u9519\u8BEF: ${err instanceof Error ? err.message : String(err)}
832
727
  `));
833
728
  process.exitCode = 1;
834
729
  return;
@@ -867,9 +762,9 @@ async function runJsonMode(runtime, request) {
867
762
 
868
763
  // src/modes/interactive.ts
869
764
  import readline2 from "readline";
870
- import chalk5 from "chalk";
765
+ import chalk3 from "chalk";
871
766
  import {
872
- getBuiltinModels as getBuiltinModels3,
767
+ getBuiltinModels as getBuiltinModels2,
873
768
  adaptAiModel as adaptAiModel2
874
769
  } from "@aipack-ai/agent";
875
770
 
@@ -921,20 +816,20 @@ async function runInteractiveMode(opts) {
921
816
  rl = readline2.createInterface({
922
817
  input: process.stdin,
923
818
  output: process.stdout,
924
- prompt: chalk5.blue("aipack> ")
819
+ prompt: chalk3.blue("aipack> ")
925
820
  });
926
821
  rl.on("SIGINT", () => {
927
822
  if (busy) {
928
- console.log(chalk5.yellow("\n\u4E2D\u65AD\u5F53\u524D\u8FD0\u884C..."));
823
+ console.log(chalk3.yellow("\n\u4E2D\u65AD\u5F53\u524D\u8FD0\u884C..."));
929
824
  runtime.abort(activeKey);
930
825
  return;
931
826
  }
932
827
  sigintCount++;
933
828
  if (sigintCount >= 2) {
934
- console.log(chalk5.dim("\n\u518D\u89C1"));
829
+ console.log(chalk3.dim("\n\u518D\u89C1"));
935
830
  rl.close();
936
831
  } else {
937
- console.log(chalk5.dim("\uFF08\u518D\u6309\u4E00\u6B21 Ctrl+C \u9000\u51FA\uFF09"));
832
+ console.log(chalk3.dim("\uFF08\u518D\u6309\u4E00\u6B21 Ctrl+C \u9000\u51FA\uFF09"));
938
833
  rl.prompt();
939
834
  setTimeout(() => {
940
835
  sigintCount = 0;
@@ -964,7 +859,7 @@ async function runInteractiveMode(opts) {
964
859
  renderer.render(chunk);
965
860
  }
966
861
  } catch (err) {
967
- console.log(chalk5.red(`\u9519\u8BEF: ${err instanceof Error ? err.message : String(err)}`));
862
+ console.log(chalk3.red(`\u9519\u8BEF: ${err instanceof Error ? err.message : String(err)}`));
968
863
  } finally {
969
864
  busy = false;
970
865
  rl.prompt();
@@ -984,104 +879,104 @@ async function runInteractiveMode(opts) {
984
879
  return;
985
880
  case "/model": {
986
881
  if (!rest) {
987
- console.log(chalk5.dim(`\u5F53\u524D\u6A21\u578B: ${model.aiModel.provider}/${model.aiModel.id}`));
988
- console.log(chalk5.dim("\u7528\u6CD5: /model provider/model-id\uFF08\u5982 /model deepseek/deepseek-chat\uFF09"));
882
+ console.log(chalk3.dim(`\u5F53\u524D\u6A21\u578B: ${model.aiModel.provider}/${model.aiModel.id}`));
883
+ console.log(chalk3.dim("\u7528\u6CD5: /model provider/model-id\uFF08\u5982 /model deepseek/deepseek-chat\uFF09"));
989
884
  break;
990
885
  }
991
886
  const slash = rest.indexOf("/");
992
887
  const provider = slash === -1 ? model.aiModel.provider : rest.slice(0, slash);
993
888
  const id = slash === -1 ? rest : rest.slice(slash + 1);
994
- const found = getBuiltinModels3(provider).find((m) => m.id === id);
889
+ const found = getBuiltinModels2(provider).find((m) => m.id === id);
995
890
  if (!found) {
996
- console.log(chalk5.yellow(`\u672A\u627E\u5230\u5185\u7F6E\u6A21\u578B ${provider}/${id}\uFF0C\u53EF\u7528:`));
997
- console.log(getBuiltinModels3(provider).map((m) => ` ${m.id}`).join("\n") || " (\u65E0)");
891
+ console.log(chalk3.yellow(`\u672A\u627E\u5230\u5185\u7F6E\u6A21\u578B ${provider}/${id}\uFF0C\u53EF\u7528:`));
892
+ console.log(getBuiltinModels2(provider).map((m) => ` ${m.id}`).join("\n") || " (\u65E0)");
998
893
  break;
999
894
  }
1000
895
  runtime.setModel(adaptAiModel2(found));
1001
896
  model.aiModel = found;
1002
897
  model.custom = false;
1003
- console.log(chalk5.green(`\u5DF2\u5207\u6362\u5230 ${provider}/${id}`));
898
+ console.log(chalk3.green(`\u5DF2\u5207\u6362\u5230 ${provider}/${id}`));
1004
899
  break;
1005
900
  }
1006
901
  case "/thinking": {
1007
902
  if (!VALID_THINKING.has(rest)) {
1008
- console.log(chalk5.dim("\u7528\u6CD5: /thinking <off|minimal|low|medium|high|max>"));
903
+ console.log(chalk3.dim("\u7528\u6CD5: /thinking <off|minimal|low|medium|high|max>"));
1009
904
  break;
1010
905
  }
1011
906
  runtime.setThinkingLevel(rest);
1012
- console.log(chalk5.green(`\u601D\u8003\u7EA7\u522B: ${rest}`));
907
+ console.log(chalk3.green(`\u601D\u8003\u7EA7\u522B: ${rest}`));
1013
908
  break;
1014
909
  }
1015
910
  case "/system": {
1016
911
  if (!rest) {
1017
- console.log(chalk5.dim("\u7528\u6CD5: /system <\u65B0\u7684\u7CFB\u7EDF\u63D0\u793A\u8BCD>"));
912
+ console.log(chalk3.dim("\u7528\u6CD5: /system <\u65B0\u7684\u7CFB\u7EDF\u63D0\u793A\u8BCD>"));
1018
913
  break;
1019
914
  }
1020
915
  runtime.setSystemPrompt(rest);
1021
- console.log(chalk5.green("\u7CFB\u7EDF\u63D0\u793A\u8BCD\u5DF2\u66F4\u65B0"));
916
+ console.log(chalk3.green("\u7CFB\u7EDF\u63D0\u793A\u8BCD\u5DF2\u66F4\u65B0"));
1022
917
  break;
1023
918
  }
1024
919
  case "/session":
1025
- console.log(`\u4F1A\u8BDD key: ${chalk5.cyan(activeKey)}`);
920
+ console.log(`\u4F1A\u8BDD key: ${chalk3.cyan(activeKey)}`);
1026
921
  console.log(`\u6D88\u606F\u6570: ${runtime.getMessages(activeKey).length}`);
1027
- console.log(`\u6301\u4E45\u5316: ${args.noSession ? chalk5.yellow("\u5426\uFF08--no-session\uFF09") : chalk5.green(storage ? "\u662F" : "\u5426\uFF08\u65E0\u5B58\u50A8\uFF09")}`);
922
+ console.log(`\u6301\u4E45\u5316: ${args.noSession ? chalk3.yellow("\u5426\uFF08--no-session\uFF09") : chalk3.green(storage ? "\u662F" : "\u5426\uFF08\u65E0\u5B58\u50A8\uFF09")}`);
1028
923
  break;
1029
924
  case "/sessions": {
1030
925
  if (!storage) {
1031
- console.log(chalk5.yellow("\u5F53\u524D\u4E3A\u4E34\u65F6\u4F1A\u8BDD\uFF0C\u65E0\u6301\u4E45\u5316\u5B58\u50A8"));
926
+ console.log(chalk3.yellow("\u5F53\u524D\u4E3A\u4E34\u65F6\u4F1A\u8BDD\uFF0C\u65E0\u6301\u4E45\u5316\u5B58\u50A8"));
1032
927
  break;
1033
928
  }
1034
929
  const sessions = await listSessionsByRecency(storage);
1035
930
  if (sessions.length === 0) {
1036
- console.log(chalk5.dim("\uFF08\u65E0\u5386\u53F2\u4F1A\u8BDD\uFF09"));
931
+ console.log(chalk3.dim("\uFF08\u65E0\u5386\u53F2\u4F1A\u8BDD\uFF09"));
1037
932
  break;
1038
933
  }
1039
- console.log(sessions.slice(0, 10).map((s, i) => `${s === activeKey ? chalk5.green("\u25B8 ") : " "}${i + 1}. ${s}`).join("\n"));
1040
- console.log(chalk5.dim("\u5207\u6362: \u9000\u51FA\u540E\u7528 aipack --session <key> \u6062\u590D"));
934
+ console.log(sessions.slice(0, 10).map((s, i) => `${s === activeKey ? chalk3.green("\u25B8 ") : " "}${i + 1}. ${s}`).join("\n"));
935
+ console.log(chalk3.dim("\u5207\u6362: \u9000\u51FA\u540E\u7528 aipack --session <key> \u6062\u590D"));
1041
936
  break;
1042
937
  }
1043
938
  case "/clear":
1044
939
  runtime.clearSession(activeKey);
1045
- console.log(chalk5.green("\u4F1A\u8BDD\u5DF2\u6E05\u7A7A\uFF08\u4EC5\u5185\u5B58\uFF09"));
940
+ console.log(chalk3.green("\u4F1A\u8BDD\u5DF2\u6E05\u7A7A\uFF08\u4EC5\u5185\u5B58\uFF09"));
1046
941
  break;
1047
942
  case "/tools":
1048
- console.log(chalk5.dim("\u5185\u7F6E\u5DE5\u5177\u901A\u8FC7 --tools/--exclude-tools \u914D\u7F6E\uFF1B\u5F53\u524D\u8FD0\u884C\u65F6\u672A\u63D0\u4F9B\u5217\u4E3E\u63A5\u53E3"));
943
+ console.log(chalk3.dim("\u5185\u7F6E\u5DE5\u5177\u901A\u8FC7 --tools/--exclude-tools \u914D\u7F6E\uFF1B\u5F53\u524D\u8FD0\u884C\u65F6\u672A\u63D0\u4F9B\u5217\u4E3E\u63A5\u53E3"));
1049
944
  break;
1050
945
  case "/approvals": {
1051
946
  if (!approvalManager) {
1052
- console.log(chalk5.yellow("\u5BA1\u6279\u672A\u542F\u7528\uFF08\u5728 aipack.config.js \u4E2D\u914D\u7F6E approvals.enabled: true\uFF09"));
947
+ console.log(chalk3.yellow("\u5BA1\u6279\u672A\u542F\u7528\uFF08\u5728 aipack.config.js \u4E2D\u914D\u7F6E approvals.enabled: true\uFF09"));
1053
948
  break;
1054
949
  }
1055
950
  const pending = approvalManager.list();
1056
951
  if (pending.length === 0) {
1057
- console.log(chalk5.dim("\uFF08\u65E0\u672A\u51B3\u5BA1\u6279\uFF09"));
952
+ console.log(chalk3.dim("\uFF08\u65E0\u672A\u51B3\u5BA1\u6279\uFF09"));
1058
953
  break;
1059
954
  }
1060
955
  for (const p of pending) {
1061
- console.log(`${chalk5.cyan(p.id)} ${p.request.toolName} ${chalk5.dim(new Date(p.createdAt).toLocaleString())}${p.restored ? chalk5.yellow(" (\u5B64\u513F)") : ""}`);
956
+ console.log(`${chalk3.cyan(p.id)} ${p.request.toolName} ${chalk3.dim(new Date(p.createdAt).toLocaleString())}${p.restored ? chalk3.yellow(" (\u5B64\u513F)") : ""}`);
1062
957
  }
1063
958
  break;
1064
959
  }
1065
960
  case "/approve":
1066
961
  case "/deny": {
1067
962
  if (!approvalManager) {
1068
- console.log(chalk5.yellow("\u5BA1\u6279\u672A\u542F\u7528"));
963
+ console.log(chalk3.yellow("\u5BA1\u6279\u672A\u542F\u7528"));
1069
964
  break;
1070
965
  }
1071
966
  if (!rest) {
1072
- console.log(chalk5.dim(`\u7528\u6CD5: ${cmd} <\u5BA1\u6279\u5355 id>`));
967
+ console.log(chalk3.dim(`\u7528\u6CD5: ${cmd} <\u5BA1\u6279\u5355 id>`));
1073
968
  break;
1074
969
  }
1075
970
  const ok = approvalManager.resolve(rest, cmd === "/approve");
1076
- console.log(ok ? chalk5.green("\u5DF2\u751F\u6548") : chalk5.yellow("\u5BA1\u6279\u5355\u4E0D\u5B58\u5728\u6216\u5DF2\u7ED3\u7B97"));
971
+ console.log(ok ? chalk3.green("\u5DF2\u751F\u6548") : chalk3.yellow("\u5BA1\u6279\u5355\u4E0D\u5B58\u5728\u6216\u5DF2\u7ED3\u7B97"));
1077
972
  break;
1078
973
  }
1079
974
  default:
1080
- console.log(chalk5.yellow(`\u672A\u77E5\u547D\u4EE4: ${cmd}\uFF08/help \u67E5\u770B\u5168\u90E8\uFF09`));
975
+ console.log(chalk3.yellow(`\u672A\u77E5\u547D\u4EE4: ${cmd}\uFF08/help \u67E5\u770B\u5168\u90E8\uFF09`));
1081
976
  }
1082
977
  }
1083
978
  function printSlashHelp() {
1084
- console.log(`${chalk5.bold("\u547D\u4EE4:")}
979
+ console.log(`${chalk3.bold("\u547D\u4EE4:")}
1085
980
  /model [provider/id] \u5207\u6362\u6A21\u578B\uFF08\u65E0\u53C2\u663E\u793A\u5F53\u524D\uFF09
1086
981
  /thinking <\u7EA7\u522B> off/minimal/low/medium/high/max
1087
982
  /system <\u6587\u672C> \u66FF\u6362\u7CFB\u7EDF\u63D0\u793A\u8BCD
@@ -1100,7 +995,7 @@ async function runInteractiveMode(opts) {
1100
995
  return;
1101
996
  }
1102
997
  if (busy) {
1103
- console.log(chalk5.dim("\uFF08\u8FD0\u884C\u4E2D\uFF0C\u8F93\u5165\u88AB\u5FFD\u7565\uFF1BCtrl+C \u4E2D\u65AD\uFF09"));
998
+ console.log(chalk3.dim("\uFF08\u8FD0\u884C\u4E2D\uFF0C\u8F93\u5165\u88AB\u5FFD\u7565\uFF1BCtrl+C \u4E2D\u65AD\uFF09"));
1104
999
  rl.prompt();
1105
1000
  return;
1106
1001
  }
@@ -1123,10 +1018,10 @@ async function runInteractiveMode(opts) {
1123
1018
  }
1124
1019
  };
1125
1020
  }
1126
- const modelLabel = `${model.aiModel.provider}/${model.aiModel.id}${model.custom ? chalk5.yellow(" (\u81EA\u5B9A\u4E49)") : ""}`;
1127
- console.log(chalk5.bold(`${APP_NAME} ${VERSION}`) + chalk5.dim(` \u4F1A\u8BDD: ${activeKey}${args.noSession ? " (\u4E34\u65F6)" : ""}`));
1128
- console.log(chalk5.dim(`\u6A21\u578B: ${modelLabel}`));
1129
- console.log(chalk5.dim("\u8F93\u5165 /help \u67E5\u770B\u547D\u4EE4\uFF0CCtrl+C \u4E2D\u65AD\u8FD0\u884C\uFF0C\u8FDE\u6309\u4E24\u6B21\u9000\u51FA\n"));
1021
+ const modelLabel = `${model.aiModel.provider}/${model.aiModel.id}${model.custom ? chalk3.yellow(" (\u81EA\u5B9A\u4E49)") : ""}`;
1022
+ console.log(chalk3.bold(`${APP_NAME} ${VERSION}`) + chalk3.dim(` \u4F1A\u8BDD: ${activeKey}${args.noSession ? " (\u4E34\u65F6)" : ""}`));
1023
+ console.log(chalk3.dim(`\u6A21\u578B: ${modelLabel}`));
1024
+ console.log(chalk3.dim("\u8F93\u5165 /help \u67E5\u770B\u547D\u4EE4\uFF0CCtrl+C \u4E2D\u65AD\u8FD0\u884C\uFF0C\u8FDE\u6309\u4E24\u6B21\u9000\u51FA\n"));
1130
1025
  setupRl();
1131
1026
  if (opts.initialMessages && opts.initialMessages.length > 0) {
1132
1027
  await send(opts.initialMessages.join("\n"));
@@ -1136,14 +1031,14 @@ async function runInteractiveMode(opts) {
1136
1031
  async function pickSessionInteractively(storage, currentKey) {
1137
1032
  const sessions = await listSessionsByRecency(storage);
1138
1033
  if (sessions.length === 0) {
1139
- console.log(chalk5.dim("\uFF08\u65E0\u5386\u53F2\u4F1A\u8BDD\uFF0C\u5C06\u65B0\u5EFA\uFF09"));
1034
+ console.log(chalk3.dim("\uFF08\u65E0\u5386\u53F2\u4F1A\u8BDD\uFF0C\u5C06\u65B0\u5EFA\uFF09"));
1140
1035
  return void 0;
1141
1036
  }
1142
- console.log(chalk5.bold("\u9009\u62E9\u4F1A\u8BDD:"));
1037
+ console.log(chalk3.bold("\u9009\u62E9\u4F1A\u8BDD:"));
1143
1038
  sessions.slice(0, 15).forEach((s, i) => {
1144
- console.log(`${s === currentKey ? chalk5.green("\u25B8 ") : " "}${i + 1}. ${s}`);
1039
+ console.log(`${s === currentKey ? chalk3.green("\u25B8 ") : " "}${i + 1}. ${s}`);
1145
1040
  });
1146
- console.log(chalk5.dim(" n. \u65B0\u4F1A\u8BDD"));
1041
+ console.log(chalk3.dim(" n. \u65B0\u4F1A\u8BDD"));
1147
1042
  const answer = await ask("\u7F16\u53F7: ");
1148
1043
  if (answer === "" || answer.toLowerCase() === "n") return void 0;
1149
1044
  const idx = Number.parseInt(answer, 10);
@@ -1154,7 +1049,7 @@ async function pickSessionInteractively(storage, currentKey) {
1154
1049
  }
1155
1050
 
1156
1051
  // src/select.ts
1157
- import chalk6 from "chalk";
1052
+ import chalk4 from "chalk";
1158
1053
  async function select(question, options, defaultIndex = 0) {
1159
1054
  const stdin = process.stdin;
1160
1055
  const out = process.stdout;
@@ -1168,7 +1063,7 @@ async function select(question, options, defaultIndex = 0) {
1168
1063
  function render() {
1169
1064
  for (let i = 0; i < options.length; i++) {
1170
1065
  const opt = options[i];
1171
- const line = i === selected ? `${chalk6.cyan("\u276F ")}${chalk6.bold(opt.label)}` : ` ${opt.label}`;
1066
+ const line = i === selected ? `${chalk4.cyan("\u276F ")}${chalk4.bold(opt.label)}` : ` ${opt.label}`;
1172
1067
  out.write(`\x1B[2K\r${line}
1173
1068
  `);
1174
1069
  }
@@ -1184,7 +1079,7 @@ async function select(question, options, defaultIndex = 0) {
1184
1079
  for (let i = 0; i < options.length; i++) out.write("\x1B[2K\r\n");
1185
1080
  out.write(`\x1B[${options.length}A`);
1186
1081
  const chosen = options.find((o) => o.value === value);
1187
- const summary = chosen ? chalk6.green(`\u2713 ${chosen.label}`) : chalk6.dim("\u5DF2\u53D6\u6D88");
1082
+ const summary = chosen ? chalk4.green(`\u2713 ${chosen.label}`) : chalk4.dim("\u5DF2\u53D6\u6D88");
1188
1083
  out.write(`\x1B[2K\r ${summary}
1189
1084
  `);
1190
1085
  resolve(value);
@@ -1212,7 +1107,7 @@ async function select(question, options, defaultIndex = 0) {
1212
1107
  }
1213
1108
  render();
1214
1109
  }
1215
- out.write(`${chalk6.yellow("?")} ${chalk6.bold(question)}
1110
+ out.write(`${chalk4.yellow("?")} ${chalk4.bold(question)}
1216
1111
  `);
1217
1112
  render();
1218
1113
  stdin.on("data", onData);
@@ -1275,6 +1170,107 @@ function createToolConfirmHandler(options = {}) {
1275
1170
  };
1276
1171
  }
1277
1172
 
1173
+ // src/cli.ts
1174
+ import chalk7 from "chalk";
1175
+
1176
+ // src/commands/approvals.ts
1177
+ import path5 from "path";
1178
+ import chalk5 from "chalk";
1179
+ import { FileApprovalStore as FileApprovalStore2, createApprovalManager as createApprovalManager2 } from "@aipack-ai/agent";
1180
+ function createStore() {
1181
+ return new FileApprovalStore2({
1182
+ baseDir: path5.join(defaultConfigDir(), "approvals")
1183
+ });
1184
+ }
1185
+ async function handleApprovalsCommand(args) {
1186
+ const [sub, ...rest] = args;
1187
+ if (!sub || sub === "help" || sub === "--help") {
1188
+ printUsage();
1189
+ return 0;
1190
+ }
1191
+ const store = createStore();
1192
+ if (sub === "list") {
1193
+ const pending = await store.load();
1194
+ if (pending.length === 0) {
1195
+ console.log(chalk5.dim("\uFF08\u65E0\u672A\u51B3\u5BA1\u6279\u5355\uFF09"));
1196
+ return 0;
1197
+ }
1198
+ for (const p of pending) {
1199
+ printApproval(p);
1200
+ }
1201
+ return 0;
1202
+ }
1203
+ if (sub === "approve" || sub === "deny") {
1204
+ const id = rest[0];
1205
+ if (!id) {
1206
+ console.error(chalk5.red(`\u7528\u6CD5: aipack approvals ${sub} <id>`));
1207
+ return 1;
1208
+ }
1209
+ const manager = createApprovalManager2({ store });
1210
+ await manager.restore();
1211
+ const ok = manager.resolve(id, sub === "approve");
1212
+ manager.close();
1213
+ if (!ok) {
1214
+ console.error(chalk5.yellow(`\u5BA1\u6279\u5355 ${id} \u4E0D\u5B58\u5728\u6216\u5DF2\u7ED3\u7B97`));
1215
+ return 1;
1216
+ }
1217
+ console.log(chalk5.green(`\u5DF2${sub === "approve" ? "\u6279\u51C6" : "\u9A73\u56DE"} ${id}`));
1218
+ return 0;
1219
+ }
1220
+ printUsage();
1221
+ console.error(chalk5.red(`\u672A\u77E5\u5B50\u547D\u4EE4: ${sub}`));
1222
+ return 1;
1223
+ }
1224
+ function printApproval(p) {
1225
+ const created = new Date(p.createdAt).toLocaleString();
1226
+ const expires = p.expiresAt ? chalk5.dim(` \u8FC7\u671F ${new Date(p.expiresAt).toLocaleTimeString()}`) : "";
1227
+ console.log(`${chalk5.cyan(p.id)} ${chalk5.bold(p.toolName)} ${chalk5.dim(created)}${expires}`);
1228
+ if (p.permissions.length > 0) {
1229
+ console.log(chalk5.dim(` \u80FD\u529B: ${p.permissions.join(", ")}`));
1230
+ }
1231
+ const argsStr = JSON.stringify(p.args);
1232
+ if (argsStr && argsStr !== "{}") {
1233
+ console.log(chalk5.dim(` \u53C2\u6570: ${argsStr.length > 120 ? `${argsStr.slice(0, 120)}\u2026` : argsStr}`));
1234
+ }
1235
+ }
1236
+ function printUsage() {
1237
+ console.log(`\u7528\u6CD5:
1238
+ aipack approvals list \u5217\u51FA\u672A\u51B3\u5BA1\u6279\u5355
1239
+ aipack approvals approve <id> \u6279\u51C6
1240
+ aipack approvals deny <id> \u9A73\u56DE`);
1241
+ }
1242
+
1243
+ // src/commands/models.ts
1244
+ import chalk6 from "chalk";
1245
+ import { getBuiltinProviders as getBuiltinProviders2, getBuiltinModels as getBuiltinModels3, hasProviderConfigured as hasProviderConfigured2 } from "@aipack-ai/agent";
1246
+ function listModels(search) {
1247
+ const term = typeof search === "string" ? search.toLowerCase() : void 0;
1248
+ let total = 0;
1249
+ for (const provider of getBuiltinProviders2()) {
1250
+ const models = getBuiltinModels3(provider.id);
1251
+ const matched = term ? models.filter((m) => m.id.toLowerCase().includes(term) || m.name.toLowerCase().includes(term) || provider.id.includes(term)) : models;
1252
+ if (matched.length === 0) continue;
1253
+ const configured = hasProviderConfigured2(provider.id);
1254
+ const badge = configured ? chalk6.green("\u2713") : chalk6.dim("\xB7");
1255
+ console.log(`${badge} ${chalk6.bold(provider.name)} ${chalk6.dim(`(${provider.id})`)}`);
1256
+ for (const m of matched) {
1257
+ const flags = [
1258
+ m.reasoning ? chalk6.dim("\u63A8\u7406") : null,
1259
+ `${m.contextWindow / 1e3 | 0}k`
1260
+ ].filter(Boolean).join(" ");
1261
+ console.log(` ${m.id.padEnd(44)} ${chalk6.dim(flags)}`);
1262
+ total++;
1263
+ }
1264
+ }
1265
+ console.log(chalk6.dim(`
1266
+ \u5171 ${total} \u4E2A\u6A21\u578B\u3002\u2713 = \u5DF2\u914D\u7F6E API Key\uFF08${getEnvHint()}\uFF09`));
1267
+ return 0;
1268
+ }
1269
+ function getEnvHint() {
1270
+ const provider = getBuiltinProviders2().find((p) => hasProviderConfigured2(p.id));
1271
+ return provider ? `${provider.envVar} \u5DF2\u8BBE\u7F6E` : "\u672A\u68C0\u6D4B\u5230\u4EFB\u4F55 API Key";
1272
+ }
1273
+
1278
1274
  // src/cli.ts
1279
1275
  import { createRequest } from "@aipack-ai/agent";
1280
1276
  async function main(argv) {
@@ -1363,12 +1359,6 @@ async function main(argv) {
1363
1359
  }
1364
1360
  return process.exitCode === 1 ? 1 : 0;
1365
1361
  }
1366
- if (process.argv[1] && /cli\.(js|mjs|ts)$/.test(process.argv[1])) {
1367
- main(process.argv.slice(2)).then((code) => process.exit(code)).catch((err) => {
1368
- console.error(chalk7.red(`\u81F4\u547D\u9519\u8BEF: ${err instanceof Error ? err.stack ?? err.message : String(err)}`));
1369
- process.exit(1);
1370
- });
1371
- }
1372
1362
 
1373
1363
  export {
1374
1364
  APP_NAME,
@@ -1399,4 +1389,4 @@ export {
1399
1389
  createToolConfirmHandler,
1400
1390
  main
1401
1391
  };
1402
- //# sourceMappingURL=chunk-DWPSBSRO.js.map
1392
+ //# sourceMappingURL=chunk-LXRCYMRS.js.map