bfi-cli 0.1.42 → 0.1.43

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.
@@ -4,22 +4,24 @@ import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import os from "node:os";
6
6
  const CACHE_FILE = path.join(os.homedir(), ".bfi", "agents-cache.json");
7
- const CACHE_TTL_MS = 1440 * 60 * 1e3;
8
7
  function loadCache() {
9
8
  try {
10
9
  if (fs.existsSync(CACHE_FILE)) {
11
10
  const raw = JSON.parse(fs.readFileSync(CACHE_FILE, "utf8"));
12
- if (Date.now() - raw.timestamp < CACHE_TTL_MS) return raw;
11
+ if (raw && Array.isArray(raw.agents)) return {
12
+ maxUpdatedAt: typeof raw.maxUpdatedAt === "number" ? raw.maxUpdatedAt : 0,
13
+ agents: raw.agents
14
+ };
13
15
  }
14
16
  } catch {}
15
17
  return null;
16
18
  }
17
- function saveCache(agents) {
19
+ function saveCache(agents, maxUpdatedAt) {
18
20
  try {
19
21
  const dir = path.dirname(CACHE_FILE);
20
22
  if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
21
23
  fs.writeFileSync(CACHE_FILE, JSON.stringify({
22
- timestamp: Date.now(),
24
+ maxUpdatedAt,
23
25
  agents
24
26
  }));
25
27
  } catch {}
@@ -42,21 +44,32 @@ function mapCustomEntry(name, entry) {
42
44
  detectInstalled: async () => false
43
45
  };
44
46
  }
47
+ function parseLastModifiedHeader(headers) {
48
+ const raw = headers?.["last-modified"];
49
+ if (!raw) return 0;
50
+ const value = Array.isArray(raw) ? raw[0] : raw;
51
+ return Number(value) || 0;
52
+ }
45
53
  async function resolveAgents(api) {
46
54
  const merged = /* @__PURE__ */ new Map();
47
55
  for (const [name, config] of Object.entries(agents)) merged.set(name, config);
48
56
  if (api) {
49
57
  let remoteAgents = null;
58
+ let shouldSaveCache = false;
59
+ let newMaxUpdatedAt = 0;
50
60
  const cache = loadCache();
51
- if (cache) remoteAgents = cache.agents;
52
- else try {
53
- const resp = await api.getAgents();
54
- const list = resp.data || resp;
55
- if (Array.isArray(list)) {
56
- remoteAgents = list.map(mapToAgentConfig);
57
- saveCache(remoteAgents);
61
+ try {
62
+ const resp = await api.getAgents(cache?.maxUpdatedAt);
63
+ if (resp.status === 304) remoteAgents = cache.agents.map(mapToAgentConfig);
64
+ else if (resp.status >= 200 && resp.status < 300 && Array.isArray(resp.body)) {
65
+ remoteAgents = resp.body.map(mapToAgentConfig);
66
+ newMaxUpdatedAt = parseLastModifiedHeader(resp.headers);
67
+ shouldSaveCache = remoteAgents.length > 0;
58
68
  }
59
- } catch {}
69
+ } catch {
70
+ if (cache) remoteAgents = cache.agents.map(mapToAgentConfig);
71
+ }
72
+ if (shouldSaveCache && remoteAgents) saveCache(remoteAgents, newMaxUpdatedAt);
60
73
  if (remoteAgents) for (const agent of remoteAgents) merged.set(agent.name, agent);
61
74
  }
62
75
  const config = loadGlobalConfig();
package/dist/cli.mjs CHANGED
@@ -664,8 +664,10 @@ var SkillHubAPI = class {
664
664
  confirmWarnings
665
665
  } })).body;
666
666
  }
667
- async getAgents() {
668
- return (await this.request("GET", "/public/agents")).body;
667
+ async getAgents(ifModifiedSince) {
668
+ const options = {};
669
+ if (ifModifiedSince && ifModifiedSince > 0) options.headers = { "If-Modified-Since": String(ifModifiedSince) };
670
+ return this.request("GET", "/public/agents", options);
669
671
  }
670
672
  async uploadDoc(fileBuffer, fileName) {
671
673
  const url = new URL(this.buildUrl("/public/process-docs"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bfi-cli",
3
- "version": "0.1.42",
3
+ "version": "0.1.43",
4
4
  "description": "用友大业财BFI统一命令行工具,支持技能,技能包,元数据,UI元数据等",
5
5
  "type": "module",
6
6
  "bin": {
@@ -62,10 +62,9 @@ bfi skills add <来源> -y # 跳过确认
62
62
  ### 1.4 技能包操作
63
63
  ```bash
64
64
  bfi skills package search # 列出所有技能包
65
- bfi skills package info @ns/pkg # 查看包详情
65
+ bfi skills package info @ns/pkg # 查看包详情
66
66
 
67
67
  bfi skills package search <关键词> # 按关键词搜索
68
- bfi skills package info @ns/pkg # 查看包详情
69
68
 
70
69
  bfi skills package install @ns/pkg # 安装包(含全部技能)
71
70
  bfi skills package list # 查看已安装的包