dsh-pf-stream 0.0.0-stage → 0.1.0
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 +201 -0
- package/NOTICE +13 -0
- package/README.md +100 -2
- package/cordis.patch.yml +2 -0
- package/lib/entry/adapter.d.ts +21 -0
- package/lib/entry/adapter.js +112 -0
- package/lib/entry/adapter.js.map +1 -0
- package/lib/entry/legacyNormalizer.d.ts +16 -0
- package/lib/entry/legacyNormalizer.js +86 -0
- package/lib/entry/legacyNormalizer.js.map +1 -0
- package/lib/errors.d.ts +7 -0
- package/lib/errors.js +12 -0
- package/lib/errors.js.map +1 -0
- package/lib/index.d.ts +108 -0
- package/lib/index.js +109 -0
- package/lib/index.js.map +1 -0
- package/lib/session/state.d.ts +25 -0
- package/lib/session/state.js +255 -0
- package/lib/session/state.js.map +1 -0
- package/lib/stage0/decoder.d.ts +57 -0
- package/lib/stage0/decoder.js +229 -0
- package/lib/stage0/decoder.js.map +1 -0
- package/lib/stage0/ffmpeg.d.ts +34 -0
- package/lib/stage0/ffmpeg.js +90 -0
- package/lib/stage0/ffmpeg.js.map +1 -0
- package/lib/stage0/probe.d.ts +47 -0
- package/lib/stage0/probe.js +150 -0
- package/lib/stage0/probe.js.map +1 -0
- package/lib/stage1/gradient.d.ts +27 -0
- package/lib/stage1/gradient.js +85 -0
- package/lib/stage1/gradient.js.map +1 -0
- package/lib/stage1/perceive.d.ts +66 -0
- package/lib/stage1/perceive.js +233 -0
- package/lib/stage1/perceive.js.map +1 -0
- package/lib/stage2/stateMachine.d.ts +70 -0
- package/lib/stage2/stateMachine.js +180 -0
- package/lib/stage2/stateMachine.js.map +1 -0
- package/lib/stage2/switchDetector.d.ts +18 -0
- package/lib/stage2/switchDetector.js +34 -0
- package/lib/stage2/switchDetector.js.map +1 -0
- package/lib/stage3/deterministicRouter.d.ts +44 -0
- package/lib/stage3/deterministicRouter.js +203 -0
- package/lib/stage3/deterministicRouter.js.map +1 -0
- package/lib/stage3/streamSampler.d.ts +74 -0
- package/lib/stage3/streamSampler.js +497 -0
- package/lib/stage3/streamSampler.js.map +1 -0
- package/lib/stage4/canvasPacker.d.ts +60 -0
- package/lib/stage4/canvasPacker.js +161 -0
- package/lib/stage4/canvasPacker.js.map +1 -0
- package/lib/stage4/markers.d.ts +19 -0
- package/lib/stage4/markers.js +98 -0
- package/lib/stage4/markers.js.map +1 -0
- package/lib/stage4/viewport.d.ts +61 -0
- package/lib/stage4/viewport.js +151 -0
- package/lib/stage4/viewport.js.map +1 -0
- package/lib/stage5/controller.d.ts +61 -0
- package/lib/stage5/controller.js +260 -0
- package/lib/stage5/controller.js.map +1 -0
- package/lib/stage5/intent.d.ts +27 -0
- package/lib/stage5/intent.js +87 -0
- package/lib/stage5/intent.js.map +1 -0
- package/lib/stage6/history.d.ts +52 -0
- package/lib/stage6/history.js +155 -0
- package/lib/stage6/history.js.map +1 -0
- package/lib/stage6/precheck.d.ts +56 -0
- package/lib/stage6/precheck.js +86 -0
- package/lib/stage6/precheck.js.map +1 -0
- package/lib/tool/handler.d.ts +35 -0
- package/lib/tool/handler.js +56 -0
- package/lib/tool/handler.js.map +1 -0
- package/lib/tool/schema.d.ts +29 -0
- package/lib/tool/schema.js +59 -0
- package/lib/tool/schema.js.map +1 -0
- package/lib/tool/streamCall.d.ts +41 -0
- package/lib/tool/streamCall.js +105 -0
- package/lib/tool/streamCall.js.map +1 -0
- package/lib/types.d.ts +355 -0
- package/lib/types.js +11 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/ffmpegBin.d.ts +20 -0
- package/lib/utils/ffmpegBin.js +62 -0
- package/lib/utils/ffmpegBin.js.map +1 -0
- package/lib/utils/hash.d.ts +13 -0
- package/lib/utils/hash.js +24 -0
- package/lib/utils/hash.js.map +1 -0
- package/lib/utils/image.d.ts +32 -0
- package/lib/utils/image.js +135 -0
- package/lib/utils/image.js.map +1 -0
- package/lib/utils/pts.d.ts +15 -0
- package/lib/utils/pts.js +50 -0
- package/lib/utils/pts.js.map +1 -0
- package/package.json +48 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Weilv-D
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
dsh-pf-stream
|
|
2
|
+
Copyright 2026 Weilv-D
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this product except in compliance with the License.
|
|
6
|
+
|
|
7
|
+
This product includes design references to the following open-source projects
|
|
8
|
+
(no source code is verbatim copied; refer to docs/dsh-pf-stream 技术设计方案.md
|
|
9
|
+
section 2.5 for the reference-reuse inventory):
|
|
10
|
+
|
|
11
|
+
- dsh-video-see (MIT) — probing, rotation parsing, frame-size planning patterns
|
|
12
|
+
- dsh-video-lens (MIT) — bounded-concurrency frame extraction patterns
|
|
13
|
+
- dsh-see-now (Apache-2.0) — rawvideo streaming pipeline and tool contract patterns
|
package/README.md
CHANGED
|
@@ -1,3 +1,101 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-pf-stream
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
DeepSeek Harness(DSH)视频感知插件。模型通过一个工具即可"看"本地视频:
|
|
4
|
+
|
|
5
|
+
- **连续事件** → 自适应流式采样:运动时按位移积分抽取低 token 过程单元,停稳与顿挫波峰时定格高清焦点单元;
|
|
6
|
+
- **可疑时间点** → 确定性检视:元数据探测、指定时间戳抽帧、均匀切片、局部 RoI 放大复核。
|
|
7
|
+
|
|
8
|
+
全部输出画布对齐 DeepSeek-V4.1-Flash 视觉编码管线:42px 超像素网格、计费 `r×(c+1)+2`、单图 ≤1024 token,不触发服务端二次下采样。
|
|
9
|
+
|
|
10
|
+
## 能力路由
|
|
11
|
+
|
|
12
|
+
一个主工具 `dsh-pf-stream`,统一 `intent.action` 路由:
|
|
13
|
+
|
|
14
|
+
| action | 引擎 | 用途 |
|
|
15
|
+
| --- | --- | --- |
|
|
16
|
+
| `pf_stream`(默认) | 动态流式采样 | 运动中抽 336² 过程单元(P),停稳/波峰定格 672² 焦点单元(F);施密特四状态机 + 双层自适应调节(意图基准 + 内容自闭环 R1-R4) |
|
|
17
|
+
| `timestamps` | 确定性检视 | 指定时间戳单帧/组合高清检视,支持 `roi_hint` 局部放大 |
|
|
18
|
+
| `uniform` | 确定性检视 | 固定步长或目标帧数均匀切片 |
|
|
19
|
+
| `probe` | 确定性检视 | 仅元数据(显示宽高/旋转/末帧 PTS/流摘要),零视觉 token |
|
|
20
|
+
|
|
21
|
+
## 安装
|
|
22
|
+
|
|
23
|
+
前置条件:
|
|
24
|
+
|
|
25
|
+
- DSH 宿主(Node ≥ 20);
|
|
26
|
+
- `ffmpeg` 与 `ffprobe` 可执行文件。发现顺序:插件配置路径 → `DSH_FFMPEG_PATH` / `FFMPEG_PATH` → `DSH_FFMPEG_DIR` → `~/.dsh/tools/ffmpeg/bin` → `~/.dsh/bin` → `PATH`。
|
|
27
|
+
|
|
28
|
+
在 DSH 插件管理器中安装包 `dsh-pf-stream`。宿主经 `dsh.bundle.patch`(`cordis.patch.yml`)挂载插件;peer 依赖 `@deepseek-ai/cordis` 与 `@deepseek-ai/schemastery` 由宿主运行时解析。运行时直接依赖仅 `pngjs`(画布 PNG 编码,参数固定保证字节幂等)。
|
|
29
|
+
|
|
30
|
+
## 使用
|
|
31
|
+
|
|
32
|
+
流式感知(问"画面里写了什么"):
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"video_path": "D:/videos/demo.mp4",
|
|
37
|
+
"intent": { "action": "pf_stream", "focus": "detail", "mode": "dense" }
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
定点复核(在流式结果中发现 12.9s 处有文字):
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"video_path": "D:/videos/demo.mp4",
|
|
46
|
+
"intent": {
|
|
47
|
+
"action": "timestamps",
|
|
48
|
+
"timestamps_ms": [12900],
|
|
49
|
+
"roi_hint": { "x": 0.2, "y": 0.3, "w": 0.4, "h": 0.4 }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
顶层同时接受视频检视领域常见便捷字段(`start_time` / `end_time` / `timestamps` / `fps` / `interval` / `num_frames` / `crop` / `probe_only`),由入口适配器归一化为标准 `intent` 结构。
|
|
55
|
+
|
|
56
|
+
## 返回内容
|
|
57
|
+
|
|
58
|
+
每次调用返回一个或多个画布包:
|
|
59
|
+
|
|
60
|
+
- **PNG 画布**:四形态之一(见下表),双色隔离线阻断相邻单元边缘串扰,可选超像素角标渲染单元编号;
|
|
61
|
+
- **结构化元数据**:`packet_id`、每单元 PTS、token 网格 bbox、源采样 bbox、双载体 SHA-256;
|
|
62
|
+
- **时序提示行**:模型可读的 P/F 单元时间轴(如 `[Packet #42 | Anchor: #105 | #101(P, 12.1s, Left-Top) → …]`)。
|
|
63
|
+
|
|
64
|
+
会话级能力:意图跨调用持久化;同视频流式游标续窗(下次调用从上次位置继续);两级历史引用(热区最近 2 包整条带复用、冷区至多 4 个 F 锚点独立载体复用)与 Epoch Compaction(默认 6 包窗口)保持多轮对话 Prefix KV-Cache 前缀稳定。
|
|
65
|
+
|
|
66
|
+
## 画布与计费
|
|
67
|
+
|
|
68
|
+
| 形态 | 布局 | Token |
|
|
69
|
+
| --- | --- | --- |
|
|
70
|
+
| `FORM_1_STANDARD_STRIP` | 4P + 1F,1344×672 | 530 |
|
|
71
|
+
| `FORM_2_COMPACT_4P` | 4P,672×672 | 274 |
|
|
72
|
+
| `FORM_3_COMPACT_1F` | 1F,672×672 | 274 |
|
|
73
|
+
| `FORM_4_PARTIAL_STRIP` | 1-3P + 1F,1344×672 | 530 |
|
|
74
|
+
|
|
75
|
+
## 配置
|
|
76
|
+
|
|
77
|
+
| 配置项 | 默认 | 说明 |
|
|
78
|
+
| --- | --- | --- |
|
|
79
|
+
| `renderVisualId` | `true` | 单元左上角超像素反色角标 |
|
|
80
|
+
| `maxPacketsPerCall` | `64` | 单次调用返回包数上限 |
|
|
81
|
+
| `maxTokensBudgetPerCall` | `65536` | 单次调用视觉 token 预算 |
|
|
82
|
+
| `maxRequestBytes` | `56 MiB` | 请求字节软水位(Base64 后口径) |
|
|
83
|
+
| `maxColdRefs` | `4` | 冷区引用上限 |
|
|
84
|
+
| `defaultStreamWindowMs` | `10000` | `pts_window` 缺省时窗口长度(毫秒) |
|
|
85
|
+
| `streamWorkMaxEdge` | `2048` | 流式解码工作分辨率长边上限(定点检视恒全分辨率) |
|
|
86
|
+
| `epochCompactionWindow` | `6` | 热转冷批量收敛窗口(包数) |
|
|
87
|
+
| `meteringProfile.imageCountTiersEnabled` | `false` | ≥15 图单边 4096px 规则门控 |
|
|
88
|
+
|
|
89
|
+
完整配置、设计依据与 20 项工程边界验证方案见 `docs/dsh-pf-stream 技术设计方案.md`。
|
|
90
|
+
|
|
91
|
+
## 测试
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
pnpm test # boundary(纯逻辑)+ e2e(fixture 驱动),20 项边界用例
|
|
95
|
+
pnpm run build # TypeScript 编译
|
|
96
|
+
pnpm verify:host # 宿主契约自检(Schema 形状/关键字子集/依赖边界)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## 许可证
|
|
100
|
+
|
|
101
|
+
Apache-2.0。实现参考了 dsh-video-see、dsh-video-lens(MIT)与 dsh-see-now(Apache-2.0)的公开实现,无逐字复制;见 `NOTICE`。
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 入口适配器:顶层调用参数 → 标准 IntentDirective(含校验与钳制)。
|
|
3
|
+
*
|
|
4
|
+
* 校验规则(《五…》§1.3):枚举外值拒绝;pts_window/timestamps_ms 钳制 [0, last_pts_ms];
|
|
5
|
+
* roi_hint 钳制 [0,1];max_packets/max_tokens_budget 钳制到配置上限。
|
|
6
|
+
*/
|
|
7
|
+
import type { IntentDirective } from '../types.js';
|
|
8
|
+
export interface AdapterLimits {
|
|
9
|
+
lastPtsMs: number;
|
|
10
|
+
maxPackets: number;
|
|
11
|
+
maxTokensBudget: number;
|
|
12
|
+
}
|
|
13
|
+
export interface AdaptedCall {
|
|
14
|
+
intent: IntentDirective;
|
|
15
|
+
normalizedFrom: string[];
|
|
16
|
+
videoPath: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 归一化入口参数。args 为宿主传入的工具参数(含顶层历史便捷字段与 intent)。
|
|
20
|
+
*/
|
|
21
|
+
export declare function adaptCallArgs(args: Record<string, unknown>, limits: AdapterLimits): AdaptedCall;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 入口适配器:顶层调用参数 → 标准 IntentDirective(含校验与钳制)。
|
|
3
|
+
*
|
|
4
|
+
* 校验规则(《五…》§1.3):枚举外值拒绝;pts_window/timestamps_ms 钳制 [0, last_pts_ms];
|
|
5
|
+
* roi_hint 钳制 [0,1];max_packets/max_tokens_budget 钳制到配置上限。
|
|
6
|
+
*/
|
|
7
|
+
import { PfStreamError } from '../errors.js';
|
|
8
|
+
import { normalizeLegacyArgs } from './legacyNormalizer.js';
|
|
9
|
+
const ACTIONS = new Set(['pf_stream', 'timestamps', 'uniform', 'probe']);
|
|
10
|
+
const MODES = new Set(['dense', 'standard', 'sparse']);
|
|
11
|
+
const FOCUS = new Set(['motion', 'detail', 'balanced']);
|
|
12
|
+
function isRecord(v) {
|
|
13
|
+
return typeof v === 'object' && v !== null;
|
|
14
|
+
}
|
|
15
|
+
function clampRoi(roi) {
|
|
16
|
+
const x = Math.min(Math.max(roi.x, 0), 1);
|
|
17
|
+
const y = Math.min(Math.max(roi.y, 0), 1);
|
|
18
|
+
const w = Math.min(Math.max(roi.w, 1e-9), 1 - x);
|
|
19
|
+
const h = Math.min(Math.max(roi.h, 1e-9), 1 - y);
|
|
20
|
+
return { x, y, w, h };
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 归一化入口参数。args 为宿主传入的工具参数(含顶层历史便捷字段与 intent)。
|
|
24
|
+
*/
|
|
25
|
+
export function adaptCallArgs(args, limits) {
|
|
26
|
+
const videoPath = args['video_path'];
|
|
27
|
+
if (typeof videoPath !== 'string' || videoPath.length === 0) {
|
|
28
|
+
throw new PfStreamError('PFSTREAM_ARGS_VIDEO_PATH', 'video_path 必须为非空字符串');
|
|
29
|
+
}
|
|
30
|
+
const legacy = normalizeLegacyArgs(args, limits.lastPtsMs);
|
|
31
|
+
const rawIntent = isRecord(args['intent']) ? args['intent'] : {};
|
|
32
|
+
const intent = {};
|
|
33
|
+
const action = (rawIntent['action'] ?? legacy.intent.action);
|
|
34
|
+
if (action != null) {
|
|
35
|
+
if (!ACTIONS.has(action)) {
|
|
36
|
+
throw new PfStreamError('PFSTREAM_ARGS_ACTION', `action 枚举外值:${String(action)}`);
|
|
37
|
+
}
|
|
38
|
+
intent.action = action;
|
|
39
|
+
}
|
|
40
|
+
const mode = rawIntent['mode'];
|
|
41
|
+
if (mode != null) {
|
|
42
|
+
if (!MODES.has(mode))
|
|
43
|
+
throw new PfStreamError('PFSTREAM_ARGS_MODE', `mode 枚举外值:${String(mode)}`);
|
|
44
|
+
intent.mode = mode;
|
|
45
|
+
}
|
|
46
|
+
const focus = rawIntent['focus'];
|
|
47
|
+
if (focus != null) {
|
|
48
|
+
if (!FOCUS.has(focus))
|
|
49
|
+
throw new PfStreamError('PFSTREAM_ARGS_FOCUS', `focus 枚举外值:${String(focus)}`);
|
|
50
|
+
intent.focus = focus;
|
|
51
|
+
}
|
|
52
|
+
const roiRaw = (rawIntent['roi_hint'] ?? legacy.intent.roi_hint);
|
|
53
|
+
if (roiRaw != null) {
|
|
54
|
+
intent.roi_hint = clampRoi(roiRaw);
|
|
55
|
+
}
|
|
56
|
+
if (rawIntent['full_frame'] === true)
|
|
57
|
+
intent.full_frame = true;
|
|
58
|
+
const windowRaw = (rawIntent['pts_window'] ?? legacy.intent.pts_window);
|
|
59
|
+
if (windowRaw != null) {
|
|
60
|
+
if (!Array.isArray(windowRaw) || windowRaw.length !== 2) {
|
|
61
|
+
throw new PfStreamError('PFSTREAM_ARGS_WINDOW', 'pts_window 必须为 [start_ms, end_ms]');
|
|
62
|
+
}
|
|
63
|
+
const w0 = clampMs(windowRaw[0], limits.lastPtsMs);
|
|
64
|
+
const w1 = clampMs(windowRaw[1], limits.lastPtsMs);
|
|
65
|
+
intent.pts_window = [Math.min(w0, w1), Math.max(w0, w1)];
|
|
66
|
+
}
|
|
67
|
+
const tsRaw = (rawIntent['timestamps_ms'] ?? legacy.intent.timestamps_ms);
|
|
68
|
+
if (tsRaw != null) {
|
|
69
|
+
if (!Array.isArray(tsRaw) || tsRaw.length < 1) {
|
|
70
|
+
throw new PfStreamError('PFSTREAM_ARGS_TIMESTAMPS', 'timestamps_ms 必须为非空数组');
|
|
71
|
+
}
|
|
72
|
+
if (intent.action == null)
|
|
73
|
+
intent.action = 'timestamps';
|
|
74
|
+
intent.timestamps_ms = tsRaw.map((t) => clampMs(t, limits.lastPtsMs));
|
|
75
|
+
}
|
|
76
|
+
const intervalRaw = (rawIntent['interval_ms'] ?? legacy.intent.interval_ms);
|
|
77
|
+
if (intervalRaw != null) {
|
|
78
|
+
if (typeof intervalRaw !== 'number' || !(intervalRaw > 0)) {
|
|
79
|
+
throw new PfStreamError('PFSTREAM_ARGS_INTERVAL', 'interval_ms 必须为正数');
|
|
80
|
+
}
|
|
81
|
+
if (intent.action == null)
|
|
82
|
+
intent.action = 'uniform';
|
|
83
|
+
intent.interval_ms = intervalRaw;
|
|
84
|
+
}
|
|
85
|
+
const fcRaw = (rawIntent['frame_count'] ?? legacy.intent.frame_count);
|
|
86
|
+
if (fcRaw != null) {
|
|
87
|
+
if (typeof fcRaw !== 'number' || !(fcRaw >= 1)) {
|
|
88
|
+
throw new PfStreamError('PFSTREAM_ARGS_FRAME_COUNT', 'frame_count 必须为 ≥1 整数');
|
|
89
|
+
}
|
|
90
|
+
if (intent.action == null)
|
|
91
|
+
intent.action = 'uniform';
|
|
92
|
+
intent.frame_count = Math.min(Math.round(fcRaw), 128);
|
|
93
|
+
}
|
|
94
|
+
const mpRaw = rawIntent['max_packets'];
|
|
95
|
+
if (mpRaw != null && typeof mpRaw === 'number' && mpRaw >= 1) {
|
|
96
|
+
intent.max_packets = Math.min(Math.round(mpRaw), limits.maxPackets);
|
|
97
|
+
}
|
|
98
|
+
const mtbRaw = rawIntent['max_tokens_budget'];
|
|
99
|
+
if (mtbRaw != null && typeof mtbRaw === 'number' && mtbRaw >= 274) {
|
|
100
|
+
intent.max_tokens_budget = Math.min(Math.round(mtbRaw), limits.maxTokensBudget);
|
|
101
|
+
}
|
|
102
|
+
if (rawIntent['reset'] === true)
|
|
103
|
+
intent.reset = true;
|
|
104
|
+
return { intent, normalizedFrom: legacy.normalizedFrom, videoPath };
|
|
105
|
+
}
|
|
106
|
+
function clampMs(v, lastPtsMs) {
|
|
107
|
+
const n = typeof v === 'number' ? v : Number(v);
|
|
108
|
+
if (!Number.isFinite(n))
|
|
109
|
+
throw new PfStreamError('PFSTREAM_ARGS_PTS', `PTS 值非法:${String(v)}`);
|
|
110
|
+
return Math.min(Math.max(Math.round(n), 0), lastPtsMs);
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/entry/adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EA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ChD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAAE,MAAM,IAAI,aAAa,CAAC,mBAAmB,EAAE,WAAW,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC9F,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 历史便捷字段归一化(《五、双层自适应调节与统一参数映射》§1.1)。
|
|
3
|
+
*
|
|
4
|
+
* 输入便利层:start_time/end_time/time_range/timestamps/fps/interval/num_frames/
|
|
5
|
+
* frame_count/crop/bbox/roi/probe_only → 标准 IntentDirective 字段。
|
|
6
|
+
* 判秒规则:数值 ≤ 时长(秒)×1.5 判秒,超过判毫秒;归一化来源记入 normalizedFrom。
|
|
7
|
+
*/
|
|
8
|
+
import type { IntentDirective } from '../types.js';
|
|
9
|
+
export interface NormalizedIntent {
|
|
10
|
+
intent: IntentDirective;
|
|
11
|
+
/** 触发了归一化的来源字段名列表(审计与 normalized_from 元数据用)。 */
|
|
12
|
+
normalizedFrom: string[];
|
|
13
|
+
}
|
|
14
|
+
/** 数值或字符串时间 → 毫秒(判秒规则见模块注释)。 */
|
|
15
|
+
export declare function toMs(value: number | string, durationMs: number): number;
|
|
16
|
+
export declare function normalizeLegacyArgs(args: Record<string, unknown>, durationMs: number): NormalizedIntent;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 历史便捷字段归一化(《五、双层自适应调节与统一参数映射》§1.1)。
|
|
3
|
+
*
|
|
4
|
+
* 输入便利层:start_time/end_time/time_range/timestamps/fps/interval/num_frames/
|
|
5
|
+
* frame_count/crop/bbox/roi/probe_only → 标准 IntentDirective 字段。
|
|
6
|
+
* 判秒规则:数值 ≤ 时长(秒)×1.5 判秒,超过判毫秒;归一化来源记入 normalizedFrom。
|
|
7
|
+
*/
|
|
8
|
+
/** 数值或字符串时间 → 毫秒(判秒规则见模块注释)。 */
|
|
9
|
+
export function toMs(value, durationMs) {
|
|
10
|
+
const n = typeof value === 'string' ? Number.parseFloat(value) : value;
|
|
11
|
+
if (!Number.isFinite(n))
|
|
12
|
+
throw new Error(`时间值无法解析:${String(value)}`);
|
|
13
|
+
const secThreshold = (durationMs / 1000) * 1.5;
|
|
14
|
+
const ms = n <= secThreshold ? n * 1000 : n;
|
|
15
|
+
return Math.round(ms);
|
|
16
|
+
}
|
|
17
|
+
function normalizeRoi(raw) {
|
|
18
|
+
const clamp01 = (v) => Math.min(Math.max(v, 0), 1);
|
|
19
|
+
return {
|
|
20
|
+
x: clamp01(raw.x),
|
|
21
|
+
y: clamp01(raw.y),
|
|
22
|
+
w: Math.min(Math.max(raw.w, 0), 1 - clamp01(raw.x)),
|
|
23
|
+
h: Math.min(Math.max(raw.h, 0), 1 - clamp01(raw.y)),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function normalizeLegacyArgs(args, durationMs) {
|
|
27
|
+
const intent = {};
|
|
28
|
+
const normalizedFrom = [];
|
|
29
|
+
const has = (k) => Object.prototype.hasOwnProperty.call(args, k) && args[k] !== undefined;
|
|
30
|
+
if (has('start_time') || has('end_time') || has('time_range')) {
|
|
31
|
+
const start = has('start_time') ? toMs(args['start_time'], durationMs) : 0;
|
|
32
|
+
const end = has('end_time')
|
|
33
|
+
? toMs(args['end_time'], durationMs)
|
|
34
|
+
: Math.max(start, durationMs);
|
|
35
|
+
intent.pts_window = [start, end];
|
|
36
|
+
normalizedFrom.push('start_time/end_time');
|
|
37
|
+
}
|
|
38
|
+
if (has('time_range') && Array.isArray(args['time_range']) && args['time_range'].length === 2) {
|
|
39
|
+
const [a, b] = args['time_range'];
|
|
40
|
+
if (a !== undefined && b !== undefined) {
|
|
41
|
+
intent.pts_window = [toMs(a, durationMs), toMs(b, durationMs)];
|
|
42
|
+
normalizedFrom.push('time_range');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (has('timestamps') && Array.isArray(args['timestamps'])) {
|
|
46
|
+
intent.timestamps_ms = args['timestamps'].map((t) => toMs(t, durationMs));
|
|
47
|
+
intent.action = 'timestamps';
|
|
48
|
+
normalizedFrom.push('timestamps');
|
|
49
|
+
}
|
|
50
|
+
if (has('fps')) {
|
|
51
|
+
const fps = Number(args['fps']);
|
|
52
|
+
if (Number.isFinite(fps) && fps > 0) {
|
|
53
|
+
intent.interval_ms = Math.round(1000 / fps);
|
|
54
|
+
intent.action = 'uniform';
|
|
55
|
+
normalizedFrom.push('fps');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (has('interval')) {
|
|
59
|
+
const iv = Number(args['interval']);
|
|
60
|
+
if (Number.isFinite(iv) && iv > 0) {
|
|
61
|
+
intent.interval_ms = toMs(iv, durationMs);
|
|
62
|
+
intent.action = 'uniform';
|
|
63
|
+
normalizedFrom.push('interval');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (has('num_frames') || has('frame_count')) {
|
|
67
|
+
const fc = Number(args['num_frames'] ?? args['frame_count']);
|
|
68
|
+
if (Number.isFinite(fc) && fc >= 1) {
|
|
69
|
+
intent.frame_count = Math.min(Math.round(fc), 128);
|
|
70
|
+
if (intent.action == null)
|
|
71
|
+
intent.action = 'uniform';
|
|
72
|
+
normalizedFrom.push('num_frames/frame_count');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const roiRaw = (args['crop'] ?? args['bbox'] ?? args['roi']);
|
|
76
|
+
if (roiRaw && typeof roiRaw === 'object') {
|
|
77
|
+
intent.roi_hint = normalizeRoi(roiRaw);
|
|
78
|
+
normalizedFrom.push('crop/bbox/roi');
|
|
79
|
+
}
|
|
80
|
+
if (args['probe_only'] === true) {
|
|
81
|
+
intent.action = 'probe';
|
|
82
|
+
normalizedFrom.push('probe_only');
|
|
83
|
+
}
|
|
84
|
+
return { intent, normalizedFrom };
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=legacyNormalizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacyNormalizer.js","sourceRoot":"","sources":["../../src/entry/legacyNormalizer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,gCAAgC;AAChC,MAAM,UAAU,IAAI,CAAC,KAAsB,EAAE,UAAkB;IAC7D,MAAM,CAAC,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACvE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,WAAW,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACrE,MAAM,YAAY,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC;IAC/C,MAAM,EAAE,GAAG,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACxB,CAAC;AAED,SAAS,YAAY,CAAC,GAAmD;IACvE,MAAM,OAAO,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC3D,OAAO;QACL,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QACjB,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QACjB,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,CA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