@aiti-ai/ext-shared 0.1.11 → 0.1.12

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.
@@ -15,7 +15,7 @@
15
15
 
16
16
  import assert from "node:assert/strict";
17
17
  import test from "node:test";
18
- import { readFileSync, readdirSync, statSync } from "node:fs";
18
+ import { readFileSync, readdirSync, statSync, existsSync } from "node:fs";
19
19
  import { join, dirname } from "node:path";
20
20
  import { fileURLToPath } from "node:url";
21
21
 
@@ -75,6 +75,10 @@ function listAgentExts() {
75
75
  return readdirSync(ROOT)
76
76
  .filter((name) => name.startsWith("aiti-") && name.endsWith("-agent"))
77
77
  .filter((name) => statSync(join(ROOT, name)).isDirectory())
78
+ // Real extension checkouts only: a stale dir holding just an ignored dist/
79
+ // (removed extension, build artifact left behind) must not enter the matrix —
80
+ // the aiti-opencode-agent removal left exactly such a shell (2026-11-14)
81
+ .filter((name) => existsSync(join(ROOT, name, "package.json")))
78
82
  .sort();
79
83
  }
80
84
 
@@ -23,7 +23,7 @@ import {
23
23
  captureSpawnEnvFeatures,
24
24
  } from "./agent-spawn-env.ts";
25
25
 
26
- const PROC_ENV = { PORT: "30142", PI_WEB_BASE_PATH: "/dev", HOME: "/home/pi", PATH: "/usr/bin" };
26
+ const PROC_ENV = { PORT: "3001", PI_WEB_BASE_PATH: "/dev", HOME: "/home/pi", PATH: "/usr/bin" };
27
27
 
28
28
  test("resolveCliLaunch:缺省 command=defaultCommand,args=[...prefix, ...driverArgs]", () => {
29
29
  const r = resolveCliLaunch({
@@ -52,7 +52,7 @@ test("resolveCliLaunch:command 覆盖生效(driverArgs 不含原 CLI 名由
52
52
 
53
53
  test("resolveCliLaunch:generic 路径自动注入 AITI_BRIDGE_URL(本机实例推导)", () => {
54
54
  const r = resolveCliLaunch({ defaultCommand: "job", processEnv: PROC_ENV });
55
- assert.equal(r.env.AITI_BRIDGE_URL, "http://127.0.0.1:30142/dev/api/extensions/aiti-devtools");
55
+ assert.equal(r.env.AITI_BRIDGE_URL, "http://127.0.0.1:3001/dev/api/extensions/aiti-devtools");
56
56
  });
57
57
 
58
58
  test("resolveCliLaunch:显式 env 已带 AITI_BRIDGE_URL 则保持(不重复注入)", () => {
@@ -74,7 +74,7 @@ test("resolveCliLaunch:$VAR / ${cwd} 展开(argsPrefix + memberEnv;工作
74
74
  processEnv: PROC_ENV,
75
75
  cwd: "/tmp/proj",
76
76
  });
77
- assert.deepEqual(r.args, ["-v", "/tmp/proj:/tmp/proj", "-w", "/tmp/proj", "-e", "K=30142"]);
77
+ assert.deepEqual(r.args, ["-v", "/tmp/proj:/tmp/proj", "-w", "/tmp/proj", "-e", "K=3001"]);
78
78
  assert.equal(r.env.WORK, "/tmp/proj/x");
79
79
  assert.equal(r.env.FROM_ENV, "/home/pi/y");
80
80
  assert.equal(r.warnings.length, 0);
@@ -109,11 +109,11 @@ test("resolveCliLaunch:未定义引用 → 空串 + warning(argsPrefix 与 m
109
109
  test("resolveCliLaunch:bridge=host.docker.internal 替换主机保留端口路径", () => {
110
110
  const r = resolveCliLaunch({
111
111
  defaultCommand: "claude",
112
- env: { AITI_BRIDGE_URL: "http://127.0.0.1:30142/dev/api/extensions/aiti-devtools" },
112
+ env: { AITI_BRIDGE_URL: "http://127.0.0.1:3001/dev/api/extensions/aiti-devtools" },
113
113
  bridge: "host.docker.internal",
114
114
  processEnv: PROC_ENV,
115
115
  });
116
- assert.equal(r.env.AITI_BRIDGE_URL, "http://host.docker.internal:30142/dev/api/extensions/aiti-devtools");
116
+ assert.equal(r.env.AITI_BRIDGE_URL, "http://host.docker.internal:3001/dev/api/extensions/aiti-devtools");
117
117
  });
118
118
 
119
119
  test("resolveCliLaunch:bridge=off 移除;显式 URL 直接采用(支持 ${cwd})", () => {
@@ -126,7 +126,7 @@ test("resolveCliLaunch:bridge=off 移除;显式 URL 直接采用(支持 ${
126
126
  processEnv: PROC_ENV,
127
127
  });
128
128
  assert.equal(url.env.AITI_BRIDGE_URL, "http://bridge.local:8777");
129
- assert.equal(url.env.HINT, "http://127.0.0.1:30142/dev/api/extensions/aiti-devtools",
129
+ assert.equal(url.env.HINT, "http://127.0.0.1:3001/dev/api/extensions/aiti-devtools",
130
130
  "成员 env 在 bridge 重写前展开,看到的是重写前值(自动注入默认)");
131
131
  });
132
132
 
@@ -138,7 +138,7 @@ test("resolveCliLaunch:非法 bridge 模式按 inherit + warning;warn 回调
138
138
  processEnv: PROC_ENV,
139
139
  warn: (m) => viaCb.push(m),
140
140
  });
141
- assert.equal(r.env.AITI_BRIDGE_URL, "http://127.0.0.1:30142/dev/api/extensions/aiti-devtools");
141
+ assert.equal(r.env.AITI_BRIDGE_URL, "http://127.0.0.1:3001/dev/api/extensions/aiti-devtools");
142
142
  assert.equal(r.warnings.length, 1);
143
143
  assert.equal(viaCb.length, 1);
144
144
  });
@@ -23,13 +23,13 @@ import {
23
23
  } from "./agent-spawn-env.ts";
24
24
 
25
25
  test("piWebSelfBase:PORT + PI_WEB_BASE_PATH 归一(尾斜杠剥除)", () => {
26
- assert.equal(piWebSelfBase({ PORT: "30142", PI_WEB_BASE_PATH: "/dev/" }), "http://127.0.0.1:30142/dev");
27
- assert.equal(piWebSelfBase({ PORT: "20341", PI_WEB_BASE_PATH: "" }), "http://127.0.0.1:20341");
26
+ assert.equal(piWebSelfBase({ PORT: "3001", PI_WEB_BASE_PATH: "/dev/" }), "http://127.0.0.1:3001/dev");
27
+ assert.equal(piWebSelfBase({ PORT: "3002", PI_WEB_BASE_PATH: "" }), "http://127.0.0.1:3002");
28
28
  assert.equal(piWebSelfBase({ PI_WEB_BASE_PATH: "/dev" }), "http://127.0.0.1:3000/dev", "缺 PORT 回落 3000");
29
29
  });
30
30
 
31
31
  test("bridgeEnv:端点带扩展路径签名", () => {
32
- assert.equal(bridgeEnv({ PORT: "20341" }).AITI_BRIDGE_URL, "http://127.0.0.1:20341/api/extensions/aiti-devtools");
32
+ assert.equal(bridgeEnv({ PORT: "3002" }).AITI_BRIDGE_URL, "http://127.0.0.1:3002/api/extensions/aiti-devtools");
33
33
  });
34
34
 
35
35
  test("parseEnvList:设置/排除/注释/非法行", () => {
@@ -85,7 +85,7 @@ test("agentSpawnEnv:白名单 < 自动 bridge < 用户列表(可覆盖自动
85
85
  cli: "zcode",
86
86
  governance,
87
87
  envList: "AITI_BRIDGE_URL=http://override:1/mcp\nUSERV=$UNDEF2",
88
- processEnv: { PORT: "20341", UNDEF2: "pv" },
88
+ processEnv: { PORT: "3002", UNDEF2: "pv" },
89
89
  warn: () => {},
90
90
  });
91
91
  assert.equal(out.PATH, "/bin");
@@ -99,7 +99,7 @@ test("agentSpawnEnv:-NAME 急救——拔掉透传漏进来的变量,也可
99
99
  cli: "zcode",
100
100
  governance,
101
101
  envList: "-LEAKY\n-AITI_BRIDGE_URL",
102
- processEnv: { PORT: "20341" },
102
+ processEnv: { PORT: "3002" },
103
103
  warn: () => {},
104
104
  });
105
105
  assert.equal("LEAKY" in out, false, "排除治理透传变量");
@@ -48,7 +48,7 @@ export function registerSpawnEnvDefaults(extId: string, list: string): void {
48
48
  }
49
49
 
50
50
  /** pi-web 自身实例基地址(同进程推导;127.0.0.1 直连不走 nginx/Authelia)。
51
- * dev=30142 + /dev、prod=20341 + 空(48);155/23 随各自服务单元的 PORT/PI_WEB_BASE_PATH。 */
51
+ * dev=3001 + /dev、prod=3002 + 空(48);155/23 随各自服务单元的 PORT/PI_WEB_BASE_PATH。 */
52
52
  export function piWebSelfBase(processEnv?: Record<string, string | undefined>): string {
53
53
  const env = processEnv ?? (process.env as Record<string, string | undefined>);
54
54
  const port = env.PORT || "3000";
package/dev-pack.mjs CHANGED
@@ -54,11 +54,11 @@ export function agentsMdTemplate(extId) {
54
54
  ## 小改现场流程(改文案/样式/小逻辑)
55
55
  1. 改 \`src/\` 下对应源码
56
56
  2. \`node tools/build.mjs\`(client 有构建产物的扩展;纯服务端改动跳过)
57
- 3. \`curl -X POST http://127.0.0.1:30142/api/extensions/reload\`(dev;prod 20341;外部经 nginx 带 basePath:/dev、/mac、/mdev、/win、/wdev → \`/xxx/api/extensions/reload\`)
57
+ 3. \`curl -X POST http://127.0.0.1:3001/api/extensions/reload\`(dev;prod 3002;外部经 nginx 带 basePath:/dev、/mac、/mdev、/win、/wdev → \`/xxx/api/extensions/reload\`)
58
58
  4. 浏览器刷新页面验证
59
59
 
60
60
  ## 大改回源码仓
61
- - 源码仓:\`~/workspace/pi-work/pi-web-ext/${extId}/\`(git 管理,deploy 同步回本目录)
61
+ - 源码仓:\`extensions/${extId}/\`(git 管理,deploy 同步回本目录)
62
62
  - 改完在源码仓跑 \`node tools/deploy.mjs\`(或仓库根 \`node scripts/deploy-all.mjs --only ${extId}\`)
63
63
 
64
64
  ## 数据目录(数据分层:config / cache)
@@ -69,7 +69,7 @@ export function agentsMdTemplate(extId) {
69
69
 
70
70
  ## 红线
71
71
  - 禁轮询(setInterval 拉取);需要等待用事件/回调/SSE(桥的 SSE、aiti-event-bus topics)
72
- - 禁重启生产服务(pi-web 20341 等 restart 须用户明确同意)
72
+ - 禁重启生产服务(pi-web 3002 等 restart 须用户明确同意)
73
73
  - 禁手改 dist/ 与运行时平铺文件;跨扩展通信走 ctx.services(禁 globalThis.__ext 直穿)
74
74
  - 服务端:SQLite 一律 WAL + 分批小事务(批间 setImmediate 让步);禁 execFileSync 调 >1s 外部程序;>8MB 文件禁同步读
75
75
  `;
@@ -114,10 +114,16 @@ test("index.ts 静态 ui 声明的插槽键全部合法", () => {
114
114
  for (const name of listExts()) {
115
115
  const indexSrc = existsSync(join(extRoot, name, "index.ts")) ? readFileSync(join(extRoot, name, "index.ts"), "utf8") : null;
116
116
  if (!indexSrc) continue;
117
- // ui 块里的非插槽元数据键(宿主 registerDeclaredSlots 会多声明但无消费方;ai-helper 聚合读):
118
- // i18n/provides/clientDependsOn/clientImmediately 是宿主过滤的白名单,helpers 是 aiti-helper 的聚合元数据
117
+ // Scan only the top-level ui: { ... } block — a whole-file 4-space sweep also hits
118
+ // same-named keys inside agent tool declarations (session_search's promptGuidelines:
119
+ // [...] was flagged as an unknown slot, 2026-11-11)
120
+ const uiBlock = indexSrc.match(/^ ui: \{([\s\S]*?)\n \},/m)?.[1] ?? "";
121
+ // Non-slot metadata keys inside the ui block (the host's registerDeclaredSlots
122
+ // declares them with no consumer; ai-helper aggregation reads them):
123
+ // i18n/provides/clientDependsOn/clientImmediately are host-filtered whitelist,
124
+ // helpers is aiti-helper aggregation metadata
119
125
  const UI_META_KEYS = new Set(["i18n", "provides", "clientDependsOn", "clientImmediately", "helpers"]);
120
- for (const m of indexSrc.matchAll(/^\s{4}([a-zA-Z]+):\s*\[$/gm)) {
126
+ for (const m of uiBlock.matchAll(/^ {4}([a-zA-Z]+): \[$/gm)) {
121
127
  if (!VALID_SLOTS.has(m[1]) && !UI_META_KEYS.has(m[1])) bad.push(`${name}: ui.${m[1]}`);
122
128
  }
123
129
  }
@@ -162,18 +162,24 @@ test("piModelsFromModelsConfig: models.json 扁平化 + label 尾注 + 容错",
162
162
  "zai-coding-cn": {
163
163
  apiKey: "k",
164
164
  models: [
165
- { id: "glm-4.7", name: "GLM-4.7", api: "openai-completions", contextWindow: 204800 },
165
+ { id: "glm-4.7", name: "GLM-4.7", api: "openai-completions", contextWindow: 204800, cost: { input: 0.6, output: 2.2, cacheRead: 0.11, cacheWrite: 0 } },
166
166
  { id: "glm-5.3", name: "GLM-5.3", api: "anthropic-messages" },
167
+ { id: "glm-free", name: "GLM-Free", api: "openai-completions", cost: { input: 0, output: 0 } },
168
+ { id: "glm-bad", name: "GLM-Bad", api: "openai-completions", cost: { input: "x", output: null } },
167
169
  ],
168
170
  },
169
171
  broken: { models: "not-an-array" },
170
172
  empty: {},
171
173
  },
172
174
  });
173
- assert.deepEqual(out.map((m) => m.id), ["glm-4.7", "glm-5.3"]);
175
+ assert.deepEqual(out.map((m) => m.id), ["glm-4.7", "glm-5.3", "glm-free", "glm-bad"]);
174
176
  assert.ok(out.every((m) => m.provider === "pi" && m.source === "pi"));
175
177
  assert.match(String(out[0].label), /GLM-4\.7 · openai-completions · 200k/);
178
+ assert.equal(out[0].hint, "$0.6/$2.2 per M", "cost 费率进 hint(与宿主 formatModelCostHint 同格式)");
176
179
  assert.equal(out[1].label, "GLM-5.3 · anthropic-messages");
180
+ assert.equal(out[1].hint, undefined, "无 cost → 无 hint");
181
+ assert.equal(out[2].hint, undefined, "全零 cost(免费)→ 无 hint");
182
+ assert.equal(out[3].hint, undefined, "非法 cost → 无 hint(不编数据)");
177
183
  assert.deepEqual(piModelsFromModelsConfig(null), []);
178
184
  assert.deepEqual(piModelsFromModelsConfig({}), []);
179
185
  assert.deepEqual(piModelsFromModelsConfig({ providers: null }), []);
@@ -43,6 +43,9 @@ export type ExtModelEntry = {
43
43
  provider: string;
44
44
  label?: string;
45
45
  source?: "ext" | "pi";
46
+ /** Right-aligned dim text in the model picker row (e.g. qoder billing coefficient "0.5x").
47
+ * Locale-neutral string rendered as-is; absent → host falls back to the provider id. */
48
+ hint?: string;
46
49
  };
47
50
 
48
51
  export type ExtModelState = {
@@ -272,11 +275,13 @@ export function piModelsFromModelsConfig(config: unknown): ExtModelEntry[] {
272
275
  const bits: string[] = [];
273
276
  if (typeof m.api === "string" && m.api) bits.push(String(m.api));
274
277
  if (typeof m.contextWindow === "number" && m.contextWindow > 0) bits.push(`${Math.round(m.contextWindow / 1024)}k`);
278
+ const hint = piCostHint(m);
275
279
  out.push({
276
280
  id: m.id,
277
281
  provider: "pi",
278
282
  label: bits.length > 0 ? `${String(m.name ?? m.id)} · ${bits.join(" · ")}` : String(m.name ?? m.id),
279
283
  source: "pi",
284
+ ...(hint ? { hint } : {}),
280
285
  });
281
286
  void provKey; // pi 目录按模型平铺;来源 provider key 不进 UI(避免与 provider 分组语义冲突)
282
287
  }
@@ -284,6 +289,22 @@ export function piModelsFromModelsConfig(config: unknown): ExtModelEntry[] {
284
289
  return out;
285
290
  }
286
291
 
292
+ /**
293
+ * models.json 模型的 cost(pi ModelCost,美元/百万 token)→ 选择器行 hint("$0.6/$2.2 per M")。
294
+ * 格式与宿主 lib/model-visibility.ts 的 formatModelCostHint 一致(跨层复制,改格式两处同步);
295
+ * cache 费率/分档不进(槽位窄);缺失/全零 → 无 hint(不编数据)。
296
+ */
297
+ function piCostHint(m: { cost?: { input?: unknown; output?: unknown } | null }): string | undefined {
298
+ const c = m.cost;
299
+ if (!c || typeof c !== "object") return undefined;
300
+ const inRate = typeof c.input === "number" && Number.isFinite(c.input) ? c.input : null;
301
+ const outRate = typeof c.output === "number" && Number.isFinite(c.output) ? c.output : null;
302
+ if (inRate === null && outRate === null) return undefined;
303
+ if ((inRate ?? 0) === 0 && (outRate ?? 0) === 0) return undefined;
304
+ const trim = (n: number) => n.toFixed(3).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
305
+ return `$${trim(inRate ?? 0)}/$${trim(outRate ?? 0)} per M`;
306
+ }
307
+
287
308
  /**
288
309
  * 合并目录:外部自身条目在前(source:"ext"),pi 条目在后(source:"pi");
289
310
  * 以 provider+id 去重(先到先得——外部自身目录优先)。
@@ -7,10 +7,10 @@
7
7
  *
8
8
  * node tools/lazy-loading-metrics.mjs [baseUrl] [timeoutMs]
9
9
  *
10
- * 默认 baseUrl = http://127.0.0.1:30142/dev(dev 实例)。生产传 https://pi.example.com。
10
+ * 默认 baseUrl = http://127.0.0.1:3001/dev(dev 实例)。生产传 https://pi.example.com。
11
11
  * 依赖:无(Node 内置 fetch;页面侧注入采集脚本经 CDP 不可用时降级为 bundle 字节求和)。
12
12
  */
13
- const base = (process.argv[2] || "http://127.0.0.1:30142/dev").replace(/\/$/, "");
13
+ const base = (process.argv[2] || "http://127.0.0.1:3001/dev").replace(/\/$/, "");
14
14
  const manifestUrl = `${base}/api/extensions/manifest`;
15
15
 
16
16
  const d = await fetch(manifestUrl).then((r) => r.json()).catch(() => null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiti-ai/ext-shared",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "type": "module",
5
5
  "description": "pi-web 扩展共享层(_shared 原地 package 化)——exports 子路径逐文件暴露",
6
6
  "exports": {
@@ -54,7 +54,7 @@
54
54
  },
55
55
  "license": "MIT",
56
56
  "aitiExtProtocol": "1.0",
57
- "contentHash": "5946d83874103ee4",
57
+ "contentHash": "fe72c9a5a10bf886",
58
58
  "repository": {
59
59
  "type": "git",
60
60
  "url": "git+https://github.com/aiti-ai/aiti-ai.git",
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * _shared/reload-instances.mjs · pi-web 双实例热重载(各扩展 deploy.mjs 共用)
3
3
  *
4
- * dev 30142 / 生产 20341;端口可经 AITI_DEV_PORT / AITI_PROD_PORT 覆盖;
4
+ * dev 3001 / 生产 3002;端口可经 AITI_DEV_PORT / AITI_PROD_PORT 覆盖;
5
5
  * basePath 双 env(AITI_DEV_BASE_PATH / AITI_PROD_BASE_PATH)按机器设值,
6
6
  * 推荐值不带斜杠(48:dev 与 空;155:系统级 wdev 与 win)——git-bash 启动
7
7
  * 原生程序时会把 / 开头的 env 值做 MSYS 路径转换(/wdev → D:/apps/Git/wdev)
@@ -28,8 +28,8 @@ function buildInstance(name, portEnv, portDefault, pathEnv, pathDefault) {
28
28
  /** 双实例清单(dev/prod 各 {name, base});reload-instances 与 reconcile-deps 等共用。 */
29
29
  export function buildInstances() {
30
30
  return [
31
- buildInstance("dev", "AITI_DEV_PORT", 30142, "AITI_DEV_BASE_PATH", "/dev"),
32
- buildInstance("prod", "AITI_PROD_PORT", 20341, "AITI_PROD_BASE_PATH", ""),
31
+ buildInstance("dev", "AITI_DEV_PORT", 3001, "AITI_DEV_BASE_PATH", "/dev"),
32
+ buildInstance("prod", "AITI_PROD_PORT", 3002, "AITI_PROD_BASE_PATH", ""),
33
33
  ];
34
34
  }
35
35