@aiti-ai/ext-shared 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -22
- package/README.zh-CN.md +27 -0
- package/agent-capability-contract.test.mjs +5 -1
- package/agent-launch.test.mjs +7 -7
- package/agent-spawn-env.test.mjs +5 -5
- package/agent-spawn-env.ts +1 -1
- package/dev-pack.mjs +3 -3
- package/ext-entry-contracts.test.mjs +9 -3
- package/ext-model-state.test.mjs +8 -2
- package/ext-model-state.ts +21 -0
- package/lazy-loading-metrics.mjs +2 -2
- package/package.json +3 -3
- package/reload-instances.mjs +3 -3
package/README.md
CHANGED
|
@@ -1,36 +1,26 @@
|
|
|
1
1
|
# @aiti-ai/ext-shared
|
|
2
2
|
|
|
3
|
-
> aiti-agent
|
|
3
|
+
> Server-side shared layer for aiti-agent extensions: agent-spawn-env (spawn env governance / resolveCliLaunch), seed-tool (history-replay seeds), cursor-cli-store (Cursor CLI session reader), exec-async, git-ops-client and more. Declared in each extension's package.json and installed into the shared node_modules root by extman reconcile (resolved via jiti walk-up).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[English](./README.md) · 简体中文见 [README.zh-CN.md](./README.zh-CN.md)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## About aiti
|
|
8
8
|
|
|
9
9
|
This package is part of the **aiti** ecosystem — a personal AI development workbench powered by [pi](https://pi.dev): **aiti-agent** (a self-hosted web workbench built on the open-source [pi-web](https://github.com/aiti-ai/pi-web)) plus debug injection into mainstream dev tools (aiti-devtools) and a rich extension system.
|
|
10
10
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
11
|
+
- Workbench (aiti-agent, built on pi-web): <https://github.com/aiti-ai/pi-web>
|
|
12
|
+
- Ecosystem monorepo: <https://github.com/aiti-ai/aiti-ai>
|
|
13
|
+
- Site: <https://aiti.pw>
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Install
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Not installed directly — it is the shared runtime dependency of aiti extensions. Extensions declare it in their `package.json` dependencies; extman reconcile installs it once into the shared root `node_modules`, where it is resolved via jiti walk-up.
|
|
18
18
|
|
|
19
|
-
##
|
|
19
|
+
## Documentation
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
随 aiti-agent 扩展体系部署(extman 安装 / deploy 脚本拷贝到 `~/.pi/web/extensions/`),一般不单独 npm 安装;作为依赖被引用时经 extman reconcile 自动装入共享 node_modules。
|
|
26
|
-
|
|
27
|
-
Deployed as part of the aiti-agent extension system (extman install / deploy scripts copy it to `~/.pi/web/extensions/`); usually not installed standalone.
|
|
28
|
-
|
|
29
|
-
## 文档 · Documentation
|
|
30
|
-
|
|
31
|
-
- 中文完整文档(aiti-docs): <https://aiti.pw/guide/ext-services.html>
|
|
32
|
-
- English docs: <https://aiti.pw/en/guide/ext-services.html>
|
|
33
|
-
- 扩展注册表 / registry: <https://aiti.pw/extensions.html> · machine-readable <https://aiti.pw/extensions.json>
|
|
21
|
+
- Documentation (English): <https://aiti.pw/en/guide/ext-services.html>
|
|
22
|
+
- 文档(中文): <https://aiti.pw/guide/ext-services.html>
|
|
23
|
+
- Extension registry: <https://aiti.pw/extensions.html> · machine-readable <https://aiti.pw/extensions.json>
|
|
34
24
|
|
|
35
25
|
## License
|
|
36
26
|
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# @aiti-ai/ext-shared
|
|
2
|
+
|
|
3
|
+
> aiti-agent 扩展的服务端共享层:agent-spawn-env(spawn env 治理 / resolveCliLaunch)、seed-tool(历史回放种子)、cursor-cli-store(Cursor CLI 会话读取器)、exec-async、git-ops-client 等共享模块。扩展 package.json 声明依赖后由 extman reconcile 统一装进共享根 node_modules,jiti walk-up 解析。
|
|
4
|
+
|
|
5
|
+
简体中文 · English see [README.md](./README.md)
|
|
6
|
+
|
|
7
|
+
## 关于 aiti
|
|
8
|
+
|
|
9
|
+
本包是 **aiti** 生态的组成部分——以 [pi](https://pi.dev) 为引擎的个人 AI 开发工作台与本地调试注入生态:**aiti-agent**(自托管 Web 工作台,基于开源项目 [pi-web](https://github.com/aiti-ai/pi-web) 构建,浏览器为主操作面)+ 各开发工具内的调试注入(aiti-devtools)+ 丰富的扩展体系。
|
|
10
|
+
|
|
11
|
+
- 工作台(aiti-agent,基于 pi-web): <https://github.com/aiti-ai/pi-web>
|
|
12
|
+
- 生态仓库: <https://github.com/aiti-ai/aiti-ai>
|
|
13
|
+
- 官网: <https://aiti.pw>
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
不直接安装——aiti 扩展的运行时共享依赖。扩展在各自 `package.json` 的 dependencies 里声明本包;extman reconcile 统一装入共享根 `node_modules`(jiti walk-up 解析)。
|
|
18
|
+
|
|
19
|
+
## 文档
|
|
20
|
+
|
|
21
|
+
- 中文文档: <https://aiti.pw/guide/ext-services.html>
|
|
22
|
+
- Documentation (English): <https://aiti.pw/en/guide/ext-services.html>
|
|
23
|
+
- 扩展注册表: <https://aiti.pw/extensions.html> · machine-readable <https://aiti.pw/extensions.json>
|
|
24
|
+
|
|
25
|
+
## 许可证
|
|
26
|
+
|
|
27
|
+
MIT
|
|
@@ -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
|
|
package/agent-launch.test.mjs
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
captureSpawnEnvFeatures,
|
|
24
24
|
} from "./agent-spawn-env.ts";
|
|
25
25
|
|
|
26
|
-
const PROC_ENV = { PORT: "
|
|
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:
|
|
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=
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
});
|
package/agent-spawn-env.test.mjs
CHANGED
|
@@ -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: "
|
|
27
|
-
assert.equal(piWebSelfBase({ PORT: "
|
|
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: "
|
|
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: "
|
|
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: "
|
|
102
|
+
processEnv: { PORT: "3002" },
|
|
103
103
|
warn: () => {},
|
|
104
104
|
});
|
|
105
105
|
assert.equal("LEAKY" in out, false, "排除治理透传变量");
|
package/agent-spawn-env.ts
CHANGED
|
@@ -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=
|
|
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:
|
|
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
|
-
-
|
|
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
|
|
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
|
|
118
|
-
//
|
|
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
|
|
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
|
}
|
package/ext-model-state.test.mjs
CHANGED
|
@@ -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 }), []);
|
package/ext-model-state.ts
CHANGED
|
@@ -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 去重(先到先得——外部自身目录优先)。
|
package/lazy-loading-metrics.mjs
CHANGED
|
@@ -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:
|
|
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:
|
|
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,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiti-ai/ext-shared",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": ". Declared in each ex",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./agent-accounts": "./agent-accounts.ts",
|
|
8
8
|
"./agent-interaction": "./agent-interaction.ts",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"license": "MIT",
|
|
56
56
|
"aitiExtProtocol": "1.0",
|
|
57
|
-
"contentHash": "
|
|
57
|
+
"contentHash": "347806e4edfb6a9f",
|
|
58
58
|
"repository": {
|
|
59
59
|
"type": "git",
|
|
60
60
|
"url": "git+https://github.com/aiti-ai/aiti-ai.git",
|
package/reload-instances.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* _shared/reload-instances.mjs · pi-web 双实例热重载(各扩展 deploy.mjs 共用)
|
|
3
3
|
*
|
|
4
|
-
* dev
|
|
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",
|
|
32
|
-
buildInstance("prod", "AITI_PROD_PORT",
|
|
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
|
|