@aiti-ai/ext-shared 0.1.8 → 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.
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
## 来源 · Origin
|
|
6
|
+
|
|
7
|
+
本包是 **aiti** 生态的组成部分——以 [pi](https://pi.dev) 为引擎的个人 AI 开发工作台与本地调试注入生态:**aiti-agent**(自托管 Web 工作台,基于开源项目 [pi-web](https://github.com/aiti-ai/pi-web) 构建,浏览器为主操作面)+ 各开发工具内的调试注入(aiti-devtools)+ 丰富的扩展体系。
|
|
8
|
+
|
|
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
|
+
|
|
11
|
+
- 工作台 / workbench: <https://github.com/aiti-ai/pi-web>
|
|
12
|
+
- 生态仓库 / monorepo: <https://github.com/aiti-ai/aiti-ai>
|
|
13
|
+
- 官网 / site: <https://aiti.pw>
|
|
14
|
+
|
|
15
|
+
## 功能定位(中文)
|
|
16
|
+
|
|
17
|
+
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 解析。
|
|
18
|
+
|
|
19
|
+
## Positioning (English)
|
|
20
|
+
|
|
21
|
+
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).
|
|
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>
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
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
|
|
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiti-ai/ext-shared",
|
|
3
|
-
"version": "0.1.
|
|
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": "
|
|
57
|
+
"contentHash": "fe72c9a5a10bf886",
|
|
58
58
|
"repository": {
|
|
59
59
|
"type": "git",
|
|
60
60
|
"url": "git+https://github.com/aiti-ai/aiti-ai.git",
|