@allbluecn/dsh-compat 0.0.0-stage → 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.
- package/LICENSE +661 -0
- package/README.md +16 -2
- package/package.json +34 -3
- package/src/__tests__/package.test.ts +58 -0
- package/src/assemble/__tests__/assemble.test.ts +656 -0
- package/src/assemble/assemble.ts +383 -0
- package/src/assemble/resolve.ts +59 -0
- package/src/compat/__tests__/context.test.ts +211 -0
- package/src/compat/__tests__/events.test.ts +135 -0
- package/src/compat/__tests__/tool-adapter.test.ts +187 -0
- package/src/compat/__tests__/view-bridge.test.ts +108 -0
- package/src/compat/context.ts +498 -0
- package/src/compat/events.ts +189 -0
- package/src/compat/tool-adapter.ts +123 -0
- package/src/compat/view-bridge.ts +49 -0
- package/src/guard/assert-fetchable-url.ts +239 -0
- package/src/index.ts +52 -0
- package/src/patch/__tests__/patch.test.ts +250 -0
- package/src/patch/eval.ts +343 -0
- package/src/patch/merge.ts +45 -0
- package/src/patch/types.ts +37 -0
- package/src/patch/yaml.ts +75 -0
- package/src/plugin-safety/__tests__/build-approval.test.ts +149 -0
- package/src/plugin-safety/__tests__/install-spec.test.ts +148 -0
- package/src/plugin-safety/build-approval.ts +134 -0
- package/src/plugin-safety/index.ts +31 -0
- package/src/plugin-safety/install-spec.ts +189 -0
- package/src/report.ts +47 -0
- package/src/surface.ts +92 -0
package/README.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @allbluecn/dsh-compat
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
DSH 插件兼容层(TanStack ai-harness 对标)。一句话定位:把 DSH 插件生态(工具/命令/配置/渲染卡)适配到 ai-harness 0.4.0,产出可装配的 PluginContributions + 兼容面守护。
|
|
4
|
+
|
|
5
|
+
**纯度边界**:本包只依赖 `@tanstack/ai-harness` / `@tanstack/ai` / `@tanstack/ai-persistence` / `yaml`,零 apps/web import、零 `@/` 别名、零 prisma/serverFns。禁止引入服务端重依赖(会被客户端 split 拉进 bundle)。
|
|
6
|
+
|
|
7
|
+
## 工具视图桥(官方 resultMetadata)
|
|
8
|
+
|
|
9
|
+
- **协议**:`presentResult` 产出的视图 JSON 经官方 `setResultMetadata({ view })` 挂到 `ToolCallPart.resultMetadata.view`;工具 execute 返回原始 raw result,模型可见 tool result 不含视图。
|
|
10
|
+
- **ai-harness patch**:`patches/@tanstack__ai-harness@0.4.0.patch` 为官方 0.4.0 的 view reducer 补上应用元数据投影:实时 `TOOL_CALL_RESULT` 与持久化 transcript 重建两条路径都过滤 `metadata.tanstack` 和 `undefined`,其余顶层键写入 `resultMetadata`。
|
|
11
|
+
- **端到端证据**:`conformance/conformance.test.ts` C1 走真实 `assembleProfile → harness → tool execute → setResultMetadata → createSessionView` reducer,断言 view 可读、raw result 不变、模型 providerMessages 的 tool content 不含 `view`。
|
|
12
|
+
- **客户端契约**:`view.store.get().messages[*].parts[*]` 中 `type === 'tool-call'` 的 part 读 `part.resultMetadata.view`。字段形状 = DSH 插件 `presentResult` 产出的视图 JSON(`{ kind, title, rows, ... }`,由 DSH 视图 schema 约束)。
|
|
13
|
+
- **pending 态**:工具调用尚无 result metadata 时回退通用卡 shimmer(`presentCall` pending 视图无下发时机,差异已接受)。
|
|
14
|
+
- **软校验**:presenter 抛错、返回标量/数组或序列化失败时不挂视图、不炸回合、result 原样返回;客户端回退 `GenericToolCard`。
|
|
15
|
+
- **截断**:单视图 UTF-8 JSON 超过 256KB 时挂 `{ kind: 'view-truncated', truncated: true, originalBytes }`,客户端据此回退通用工具卡。
|
|
16
|
+
- **活更新语义**:视图一次性产出(execute 期),不活更。工具后台跑完需刷新卡片时,须另补 transcript 重投影路径。
|
|
17
|
+
- **模型不可见性**:官方 resultMetadata 与 tool result content 天然分离,不需要 strip middleware,也不改写 canonical messages。
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allbluecn/dsh-compat",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"license": "AGPL-3.0-or-later",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"src",
|
|
8
|
+
"README.md"
|
|
9
|
+
],
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"main": "./src/index.ts",
|
|
14
|
+
"types": "./src/index.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": "./src/index.ts",
|
|
17
|
+
"./guard/assert-fetchable-url": "./src/guard/assert-fetchable-url.ts",
|
|
18
|
+
"./plugin-safety": "./src/plugin-safety/index.ts"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"yaml": "2.9.0",
|
|
22
|
+
"@tanstack/ai-harness": "0.4.0",
|
|
23
|
+
"@tanstack/ai": "1.8.0",
|
|
24
|
+
"@tanstack/ai-persistence": "1.1.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"typescript": "^7",
|
|
28
|
+
"vitest": "^5.0.5",
|
|
29
|
+
"@types/node": "^26.6.6"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"test": "vitest",
|
|
33
|
+
"test:run": "vitest run",
|
|
34
|
+
"lint": "tsc --noEmit",
|
|
35
|
+
"typecheck": "tsc --noEmit"
|
|
36
|
+
}
|
|
6
37
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { DSH_COMPAT_PACKAGE } from '../index'
|
|
3
|
+
|
|
4
|
+
describe('dsh-compat 包基建', () => {
|
|
5
|
+
it('包可导入(源码直消费)', () => {
|
|
6
|
+
expect(DSH_COMPAT_PACKAGE).toBe('@allbluecn/dsh-compat')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('yaml 依赖可解析(精确 pin 2.9.0)', async () => {
|
|
10
|
+
const { parse } = await import('yaml')
|
|
11
|
+
expect(parse('a: 1')).toEqual({ a: 1 })
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('包纯度哨兵:递归全包扫描——每个 .ts 文件零 @/ 与零 @allbluecn/* 与零 prisma/serverFns/apps import', async () => {
|
|
15
|
+
// F1-6 carry-forward:由「只读 src/index.ts」加强为递归扫描 src/ 全部 .ts 文件
|
|
16
|
+
// (排除 node_modules / .d.ts / fixtures),每文件断言纯度。
|
|
17
|
+
// 包边界即纯度边界(规格 §4 P4):禁 import prisma / serverFns / app 代码。
|
|
18
|
+
// 断言锚定 `from '<bad>'`(import 语句),故 index.ts 的字符串字面量
|
|
19
|
+
// DSH_COMPAT_PACKAGE = '@allbluecn/dsh-compat'(非 import)不会误报。
|
|
20
|
+
const { readFileSync, readdirSync } = await import('node:fs')
|
|
21
|
+
const { join } = await import('node:path')
|
|
22
|
+
|
|
23
|
+
const srcRoot = join(__dirname, '..')
|
|
24
|
+
const FORBIDDEN: Array<[RegExp, string]> = [
|
|
25
|
+
[/from ['"]@\//, '路径别名 @/ import'],
|
|
26
|
+
[/from ['"]@allbluecn\//, '@allbluecn/* 包 import'],
|
|
27
|
+
[/from ['"][^'"]*prisma/, 'prisma import'],
|
|
28
|
+
[/from ['"][^'"]*serverFns/, 'serverFns import'],
|
|
29
|
+
[/from ['"][^'"]*apps\/web/, 'apps/web import'],
|
|
30
|
+
[/from ['"][^'"]*apps\/admin/, 'apps/admin import'],
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
// 递归收集 src/ 下全部 .ts 文件,排除 node_modules / .d.ts / fixtures
|
|
34
|
+
const collect = (dir: string): string[] => {
|
|
35
|
+
const out: string[] = []
|
|
36
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
37
|
+
if (entry.name === 'node_modules' || entry.name === 'fixtures') continue
|
|
38
|
+
const full = join(dir, entry.name)
|
|
39
|
+
if (entry.isDirectory()) out.push(...collect(full))
|
|
40
|
+
else if (entry.isFile() && entry.name.endsWith('.ts') && !entry.name.endsWith('.d.ts'))
|
|
41
|
+
out.push(full)
|
|
42
|
+
}
|
|
43
|
+
return out
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const files = collect(srcRoot).sort()
|
|
47
|
+
// 哨兵自身需有意义的扫描面:源码 + 测试文件均应被覆盖(现包约 27 个 .ts)
|
|
48
|
+
expect(files.length).toBeGreaterThan(20)
|
|
49
|
+
|
|
50
|
+
for (const file of files) {
|
|
51
|
+
const rel = file.slice(srcRoot.length + 1)
|
|
52
|
+
const src = readFileSync(file, 'utf8')
|
|
53
|
+
for (const [pattern, label] of FORBIDDEN) {
|
|
54
|
+
expect(src, `${rel} 违反包纯度(${label})`).not.toMatch(pattern)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
})
|