feat(vision): bind task screenshots, route vision and resume budget pauses

This commit is contained in:
Agent Workbench Dev
2026-11-01 00:48:38 +08:00
parent 0d1ab743f1
commit 96a7ed19c7
79 changed files with 1721 additions and 36 deletions
+6
View File
@@ -4,6 +4,12 @@
*.png binary
*.jpg binary
*.ico binary
docs/vision-inputs-ae-evidence/** -text
docs/vision-inputs-ae-evidence/*.log binary
docs/vision-inputs-ae-evidence/**/*.log binary
docs/vision-inputs-*.json -text whitespace=blank-at-eol,blank-at-eof,space-before-tab,cr-at-eol
docs/vision-inputs-*.tap binary
docs/vision-inputs-*.txt binary
docs/model-protocols-*.txt -text
docs/companion-a-b-evidence/*.tap binary
docs/companion-c-e-evidence/**/*.tap binary
+9
View File
@@ -0,0 +1,9 @@
# 工程截图输入契约
1.18开发中。每个Task先支持一张PNG/JPEG,单图2MiB、解码上限16Mi像素。只接受用户主动选择的文件内容,不接受本机路径或远程URL。图片完整解码、PNG CRC/结束结构与尺寸通过,JPEG按EXIF方向归正;拒绝动态PNG和尾随负载。原字节/SHA与去元数据、最长边1024像素/768KiB的PNG发送副本分别保存。界面明确显示副本尺寸,原文件可下载。草稿属于会话/项目,发送时创建新的Task/Run引用,保留原draft与工件所属;同事务保存。移除仅作用于草稿,已发送的历史不会改写。
实际请求在当前Task注入一次发送副本,历史只存原附件引用;后续同Task请求保持同一图像身份。Chat使用image_url,Responses使用input_image,detail为high。所需vision能力从实际图像块推导,声明不替代验证;不兼容成员不能取得租约。图片不进入项目记忆和PWA壳缓存。
图像预留采用固定有界本地策略,并与文字估算、原请求字节及上游实际usage分列,不声称适用于所有品牌的精确计费。原参考:[OpenAI图片输入](https://developers.openai.com/api/docs/guides/images-vision),已实际读取;未知模型容量由用户按上游资料声明,不从名称自动提高。
中文工作台延续现有布局。在输入区上方放附件条,点击查看原图/发送副本,移除草稿后可刷新核对;执行历史显示绑定附件。预算暂停采用请求分解与同Task核对续接入口。独立页面或另开附件库会切断任务关系,本阶段不采用。手机权限与真实设备结论分别验收。
+27
View File
@@ -0,0 +1,27 @@
# 1.18 工程截图、视觉路由与同Task续接
开发基线0d1ab74,分支feat/vision-attachments-1.18。正式1.17/PID36552保持,所有新请求仅使用自有loopback固定响应服务。当前仍在验收,完整回归、独立发行、保留状态正式部署分别记录,不能用前置专项代替。
## A–C:附件输入与实际协议
PNG/JPEG原图完整解码,PNG逐块结束/CRC核对、JPEG扫描结构与EXIF方向归正;拒绝动态PNG、尾随负载、伪装、截断、超大编码或像素。原图2MiB/16Mi像素,发送副本去元数据并限制1024像素/768KiB,界面显示实际副本大小。每Task一张图,每会话最多8张草稿。草稿、撤回及已消费记录保留原所属;发送时创建新的Task/Run引用与工件记录,同SQLite事务保存,原文件不重写归属。
Chat image_url/Responses input_image实际HTTP每请求恰有一次图像,原providerMessages只有文字,原请求工件保留完整字节。模型池在租约前按vision需求排除未知/不支持成员,默认演示和未知legacy线路不能绕过。四色随机像素probe只验证一次合成图像识别,结论绑定连接/凭据修订,与工程推理效果分开。原图/副本在发送及核验时分别核对SHA和任务归属,热升级继续采用已有core新容器初始化及失败回滚。
首次专项24/30(含历史兼容),失败原件vision-core-first.log保留。产品问题是原实现试图改变持久draft工件归属,现改为新ID引用并保持数据库禁止移动约束;2MiB余数边界修正为413。测试另修正completion调用形状及中文拒绝断言。第二轮附件12/12通过。
## D:预算诊断及可核对续接
新Run预算暂停保存必需输入、请求格式/图像说明、目标与工程上下文、工具定义、历史依据、图像预留、响应/安全余量及Run/Task剩余。图片使用本地预留,不是厂商计费或任何品牌容量的硬保证。文字估算保持旧规则;原请求SHA仍涵盖完整Base64字节。
预览绑定原Task、Run、会话修订、配置/注册表/凭据身份、历史SHA和全部附件/实际工具。预览不调用模型;确认后在同Task新建Run,仅本次Run选择模型/预算,累计Task额度只能保留或明确增加。过期、篡改、容量被静默截小、修订变化和重复确认均拒绝;完成工具保留、未知结果仍须核对。五项专项最终5/5,原预算测试首次调用不存在的测试方法、第二轮封存比较误漏status的失败保留;后者修正后没有放宽封存校验。最终A–D合计17/17通过。
只读正式样本得到旧estimatedTokens=36771、旧记录未有新预算分解,且原公开样本没有可用的本次context-plan。不能把旧估算直接当必需输入,更不能补造旧暂停成因。新功能用独立含实际工具结果的Task复现并保存;未启动正式原任务。正式仍1.17/PID36552、17项目,连接和数据未修改。
## E:任务界面与手机观察
延续现有中文React工作台,在原输入上方添加截图、选择/撤回、预览和路由说明;原任务消息保留附件核对/下载,失败后任务文字及草稿保留。预算诊断在原会话内,通过预览和明确确认续接。手机仅按原项目观察权限查看当前Task截图、核对原字节和下载原图;不通过observe权限新增任务、上传或调整预算。
实际Edge桌面1440×1000、390×844及真实自有TLS网关的5组流程通过;首次UI失败源于QA修改全局配置会切回legacy、以及固定响应夹具误用旧Task工具结果,已按实际选路与最后用户消息修正。原失败与截图保留。回看发现预览曾显示被排除的池首成员,改为显示符合当前任务能力的成员,运行时间以分钟显示,窄屏移除/选择触控区域补强;修正后的结果单独记录。
构建通过。回看修正后第三轮5组完整UI再次通过,零pageerror;原失败未覆盖。相关兼容62/64原轮其余均通过,剩余2项为上述预算封存status问题,修正后5/5;完整整轮尚待F。新手机截图流程的Edge/TLS结果不当成iPhone实机,真实模型视觉工程与Purge收益继续按用户选择另行待验。A–E原件与字节身份见vision-inputs-ae-evidence/manifest.json。
+17
View File
@@ -0,0 +1,17 @@
# 1.18 阶段回顾
## A–D:维持原身份,再增加能力
附件输入首先是Task所属工程数据。数据库对持久记录归属不可移动的守卫阻止了初始实现,这是需要保持的约束;最终以新Task引用连接原字节,草稿和原工件身份均保持。真解码、方向、原图/发送副本SHA、视觉前选池和两协议实际HTTP一起验证;仅支持文件选择不能算工程视觉链路完成。
图像预算与普通文字估算分开,但实际请求仍封存全部字节。预算暂停必须解释限制来源,不能静默增大模型窗口或舍弃用户要求;同Task续接通过冻结预览、修订/容量核对和一次确认完成,旧结果和未知操作不自动重放。新专项17/17,原失败保留。
## E:回看内容,而不只看测试绿色
第一次成功流程的截图暴露预算预览显示了实际被排除的文字池成员;这会影响用户对发送对象的判断,因此改为列出符合本次任务能力的成员。保留原中文产品布局,不新增独立附件管理页面。手机沿用明确的观察/审批/停止权限,这次只添加观察数据,不让观察权限暗中变成上传或执行授权。
新Edge/窄屏/自有TLS流程与iPhone实机是不同证据;固定模型只检验协议和工程执行,不检验视觉推理水平。正式原任务只读复核,没有启动、改写或补造旧预算分解。
## F:尚待完成
完整历史回归、含附件工程交付、独立源码/便携/同载荷安装、原PID与所有数据保持升级、原生回看及证据封存仍是发行门槛。下一阶段计划应依据本阶段实际结果书写,不能把未完成项标成已交付。
@@ -0,0 +1,246 @@
{
"stage": "1.18 A-E",
"realModelRequests": 0,
"entries": [
{
"source": ".qa/vision-core-first.log",
"file": "vision-core-first.log",
"bytes": 12956,
"sha256": "aed4ba5d7809f9a4a977007fa0c8c9319e67b19a65f9afff7a96b4c9e4d4ba54"
},
{
"source": ".qa/vision-core-second.log",
"file": "vision-core-second.log",
"bytes": 1593,
"sha256": "42c14555f38e05263a1491c2b276973de290db3272e8dc4d49e557a388664152"
},
{
"source": ".qa/vision-budget-first.log",
"file": "vision-budget-first.log",
"bytes": 5962,
"sha256": "b48a9390baa1bcee64da60feb79ec73277e96073ebedd26294930740a0bbcd0b"
},
{
"source": ".qa/vision-budget-third.log",
"file": "vision-budget-third.log",
"bytes": 818,
"sha256": "74d6fd0b1638c47aa371c40b1cf515709b14823662ec2ec2ccfdf5ccd80ed5f3"
},
{
"source": ".qa/vision-compat-second.log",
"file": "vision-compat-second.log",
"bytes": 9266,
"sha256": "ccd33dc28ff6d99d32928ce7be31a6bbaff41e7d5f77974284b77b4a3fc1e90e"
},
{
"source": ".qa/vision-ad-final.log",
"file": "vision-ad-final.log",
"bytes": 2295,
"sha256": "98bc56787e12cfe76f0ab2595dfcf3fb811183b40f4aad6f5fbe1a44a3795e0d"
},
{
"source": ".qa/vision-ui-first.log",
"file": "vision-ui-first.log",
"bytes": 730,
"sha256": "29f931948910fee21fd81f43645b5202f567f0177b2c983cb9c384ec8a4b9793"
},
{
"source": ".qa/vision-ui-second.log",
"file": "vision-ui-second.log",
"bytes": 624,
"sha256": "c71b644facc20cac3c38d6fdeababb2aae5475e38a1870ce7d1f8cb2b3dc33da"
},
{
"source": ".qa/vision-ui-third.log",
"file": "vision-ui-third.log",
"bytes": 624,
"sha256": "e56ca23da0fc18a1a64ed7c52cbfa28be83381413b6602d78a8355ba5c47c1d4"
},
{
"source": ".qa/vision-e-build.log",
"file": "vision-e-build.log",
"bytes": 978,
"sha256": "c31aadf039f42c9d0b0e592d77e16a05df5d19f78cedc1f84d675a276f0bd82d"
},
{
"source": ".qa/vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54/desktop-attached.png",
"file": "vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54--desktop-attached.png",
"bytes": 88839,
"sha256": "e6fd08ee3360452e9240234ae720477fea0adf16be9dfb36c93afa96158540c9"
},
{
"source": ".qa/vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54/desktop-draft.png",
"file": "vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54--desktop-draft.png",
"bytes": 101507,
"sha256": "8a8ebe249ad4d8f36c328f0b4fd7240d3cb1b5c0d710584d2c63d9d472245c1c"
},
{
"source": ".qa/vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54/downloaded-original.png",
"file": "vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54--downloaded-original.png",
"bytes": 4864,
"sha256": "0f103ba6a48431e86d9257f0e147c1c36f68694038db2e22138c23dc3a90379b"
},
{
"source": ".qa/vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54/engineering-screenshot.png",
"file": "vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54--engineering-screenshot.png",
"bytes": 4864,
"sha256": "0f103ba6a48431e86d9257f0e147c1c36f68694038db2e22138c23dc3a90379b"
},
{
"source": ".qa/vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54/failure-desktop.png",
"file": "vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54--failure-desktop.png",
"bytes": 101204,
"sha256": "ac55b02ec54a6b53bc732f33005ace702136415a06dceae9adaa2a8577b97eb8"
},
{
"source": ".qa/vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54/forged.png",
"file": "vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54--forged.png",
"bytes": 14,
"sha256": "c803805acb8f3a172061fddfe2cbba43f373f715b4ddf7f1d9a09fa683b1106f"
},
{
"source": ".qa/vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54/narrow-attached.png",
"file": "vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54--narrow-attached.png",
"bytes": 41092,
"sha256": "9d6c4f37f0a0005622ddc7c7206449110307848c1fe0548ad30e964f94978213"
},
{
"source": ".qa/vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54/result.json",
"file": "vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54--result.json",
"bytes": 1126,
"sha256": "8e52939cf6077d9c9a91029279f3b9c81375d716261c9dabaa74fba666aae811"
},
{
"source": ".qa/vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f/companion-image.png",
"file": "vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f--companion-image.png",
"bytes": 28813,
"sha256": "62e7fe98ab6fb546a1ce26f4963d31f2ded3e4deab39c85fb82e2071dc4b8d7f"
},
{
"source": ".qa/vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f/desktop-attached.png",
"file": "vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f--desktop-attached.png",
"bytes": 88762,
"sha256": "a6fb6598c81be53415789ea464557a02e4439662e84feae0835b4e1570eca8f4"
},
{
"source": ".qa/vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f/desktop-budget-preview.png",
"file": "vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f--desktop-budget-preview.png",
"bytes": 153015,
"sha256": "71d22e2cfb2bd22c0d86e61a44cee92a02fef84fcb791332f9f269bb7650fccf"
},
{
"source": ".qa/vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f/desktop-draft.png",
"file": "vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f--desktop-draft.png",
"bytes": 101507,
"sha256": "8a8ebe249ad4d8f36c328f0b4fd7240d3cb1b5c0d710584d2c63d9d472245c1c"
},
{
"source": ".qa/vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f/desktop-image-stopped.png",
"file": "vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f--desktop-image-stopped.png",
"bytes": 97607,
"sha256": "4cb67e4873df723d3517554ac5b619ba1089b3d06a5d3d07e8fb53da254f9bde"
},
{
"source": ".qa/vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f/downloaded-original.png",
"file": "vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f--downloaded-original.png",
"bytes": 4864,
"sha256": "0f103ba6a48431e86d9257f0e147c1c36f68694038db2e22138c23dc3a90379b"
},
{
"source": ".qa/vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f/engineering-screenshot.png",
"file": "vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f--engineering-screenshot.png",
"bytes": 4864,
"sha256": "0f103ba6a48431e86d9257f0e147c1c36f68694038db2e22138c23dc3a90379b"
},
{
"source": ".qa/vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f/forged.png",
"file": "vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f--forged.png",
"bytes": 14,
"sha256": "c803805acb8f3a172061fddfe2cbba43f373f715b4ddf7f1d9a09fa683b1106f"
},
{
"source": ".qa/vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f/narrow-attached.png",
"file": "vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f--narrow-attached.png",
"bytes": 41045,
"sha256": "665ab6c42b3cb677ec276671b233043ae740ab96b4b85b9e808913f02578fb8c"
},
{
"source": ".qa/vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f/narrow-budget-preview.png",
"file": "vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f--narrow-budget-preview.png",
"bytes": 56986,
"sha256": "47b1c815bd2ccb4f09b36e839daeb7050979b919e20ff1301168e1c0743ebb3b"
},
{
"source": ".qa/vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f/result.json",
"file": "vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f--result.json",
"bytes": 2353,
"sha256": "5d661e71b905f08810c6d23f6dfa059631951154296fc8208490358196e46fb8"
},
{
"source": ".qa/vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb/companion-image.png",
"file": "vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb--companion-image.png",
"bytes": 28857,
"sha256": "7e6f6b96356d5ce645753768c24ded4461bbe91886f333d6f93855a92a8910b9"
},
{
"source": ".qa/vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb/desktop-attached.png",
"file": "vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb--desktop-attached.png",
"bytes": 88861,
"sha256": "5a68af81c3d5840b70734d7ac0d70d1fcf4c7fa9f140dbc5c8e1b9bae57fd93c"
},
{
"source": ".qa/vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb/desktop-budget-preview.png",
"file": "vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb--desktop-budget-preview.png",
"bytes": 153635,
"sha256": "9dcafa4c334f96e937a1be354a14f764b4f4be39afbf3f7aad513ba2992aceb2"
},
{
"source": ".qa/vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb/desktop-draft.png",
"file": "vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb--desktop-draft.png",
"bytes": 101507,
"sha256": "8a8ebe249ad4d8f36c328f0b4fd7240d3cb1b5c0d710584d2c63d9d472245c1c"
},
{
"source": ".qa/vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb/desktop-image-stopped.png",
"file": "vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb--desktop-image-stopped.png",
"bytes": 97752,
"sha256": "808ffa499eedfd1652caa320ac52d2f7810502f2220a45dd5abe04437fc9d6cf"
},
{
"source": ".qa/vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb/downloaded-original.png",
"file": "vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb--downloaded-original.png",
"bytes": 4864,
"sha256": "0f103ba6a48431e86d9257f0e147c1c36f68694038db2e22138c23dc3a90379b"
},
{
"source": ".qa/vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb/engineering-screenshot.png",
"file": "vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb--engineering-screenshot.png",
"bytes": 4864,
"sha256": "0f103ba6a48431e86d9257f0e147c1c36f68694038db2e22138c23dc3a90379b"
},
{
"source": ".qa/vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb/forged.png",
"file": "vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb--forged.png",
"bytes": 14,
"sha256": "c803805acb8f3a172061fddfe2cbba43f373f715b4ddf7f1d9a09fa683b1106f"
},
{
"source": ".qa/vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb/narrow-attached.png",
"file": "vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb--narrow-attached.png",
"bytes": 41125,
"sha256": "566a9c9cc865fb823691ea642b9c91e4f8deb4568d92d920efaf9e641bf504b2"
},
{
"source": ".qa/vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb/narrow-budget-preview.png",
"file": "vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb--narrow-budget-preview.png",
"bytes": 56640,
"sha256": "07415fab6f3423a16236467a00a6d999bccb87932a629717d03969b3f9ce64ea"
},
{
"source": ".qa/vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb/result.json",
"file": "vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb--result.json",
"bytes": 2353,
"sha256": "6f15b489a0a0f8f2f2ee8e734ea3480e6e188da5c45f68e62cc195650330904b"
}
]
}
@@ -0,0 +1,25 @@
✔ a budget pause persists concrete text/tool/history/image breakdown and never dispatches an oversized request (3199.9803ms)
✔ explicit frozen preview resumes the same Task in a new Run, preserves completed tools and does not change global config or selected model (4197.9668ms)
✔ insufficient budgets, silently clamped capacity and arbitrary config fields reject without a physical request or mutating task budget (2584.9962ms)
✔ changed session, changed registry, expiry and altered frozen preview all require a new explicit preview (3142.2672ms)
✔ preview preserves unknown invocation status and increasing Task allowance is committed only with confirmed new Run (3974.6054ms)
✔ PNG bytes are fully decoded, metadata-free and bounded; JPEG EXIF orientation is applied to the sent PNG (103.3543ms)
✔ forged type, short headers, CRC damage, incomplete chunks, trailing payloads, animation and dimension bombs reject (23.9248ms)
✔ draft image ownership, withdrawal, reload and atomic Task binding retain original SHA and original bytes (1592.5941ms)
✔ a failed session transaction restores draft status and cannot leave a Run consuming the attachment (1137.8139ms)
✔ draft limits, duplicate selection, source changes and cross-Task association reject before dispatch (2041.3517ms)
✔ demo and legacy paths refuse image dispatch without creating a Task or consuming the draft (887.0133ms)
✔ chat-completions sends one owned image per actual request, pairs original tools and verifies exact sealed bytes (3034.6431ms)
✔ responses sends one owned image per actual request, pairs original tools and verifies exact sealed bytes (2892.3659ms)
✔ mixed pool excludes unknown vision before lease and sends zero HTTP to the incompatible member (2345.6865ms)
✔ vision probe requires correct randomized pixel order and evidence expires when the connection revision changes (1253.9727ms)
✔ HTTP upload/read/withdraw uses session authorization, returns byte SHA and refuses unknown ownership (1103.0949ms)
✔ image accounting excludes Base64 as text but seals every original request byte and reserves image input separately (2.3442ms)
ℹ tests 17
ℹ suites 0
ℹ pass 17
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 17227.4962
@@ -0,0 +1,72 @@
✖ a budget pause persists concrete text/tool/history/image breakdown and never dispatches an oversized request (942.5897ms)
✖ explicit frozen preview resumes the same Task in a new Run, preserves completed tools and does not change global config or selected model (961.5493ms)
✖ insufficient budgets, silently clamped capacity and arbitrary config fields reject without a physical request or mutating task budget (1207.5803ms)
✖ changed session, changed registry, expiry and altered frozen preview all require a new explicit preview (1071.5479ms)
✖ preview preserves unknown invocation status and increasing Task allowance is committed only with confirmed new Run (1018.3573ms)
✔ PNG bytes are fully decoded, metadata-free and bounded; JPEG EXIF orientation is applied to the sent PNG (103.2372ms)
✔ forged type, short headers, CRC damage, incomplete chunks, trailing payloads, animation and dimension bombs reject (23.8496ms)
✔ draft image ownership, withdrawal, reload and atomic Task binding retain original SHA and original bytes (1743.7451ms)
✔ a failed session transaction restores draft status and cannot leave a Run consuming the attachment (1205.6103ms)
✔ draft limits, duplicate selection, source changes and cross-Task association reject before dispatch (2101.2044ms)
✔ demo and legacy paths refuse image dispatch without creating a Task or consuming the draft (687.6118ms)
✔ chat-completions sends one owned image per actual request, pairs original tools and verifies exact sealed bytes (2167.6013ms)
✔ responses sends one owned image per actual request, pairs original tools and verifies exact sealed bytes (1945.9025ms)
✔ mixed pool excludes unknown vision before lease and sends zero HTTP to the incompatible member (1614.9053ms)
✔ vision probe requires correct randomized pixel order and evidence expires when the connection revision changes (836.9181ms)
✔ HTTP upload/read/withdraw uses session authorization, returns byte SHA and refuses unknown ownership (703.0134ms)
✔ image accounting excludes Base64 as text but seals every original request byte and reserves image input separately (2.942ms)
ℹ tests 17
ℹ suites 0
ℹ pass 12
ℹ fail 5
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 13384.0766
✖ failing tests:
test at tests\budget-resume.test.mjs:19:1
✖ a budget pause persists concrete text/tool/history/image breakdown and never dispatches an oversized request (942.5897ms)
TypeError [Error]: f.store.updateConfig is not a function
at paused (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/budget-resume.test.mjs:10:60)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async TestContext.<anonymous> (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/budget-resume.test.mjs:20:11)
at async Test.run (node:internal/test_runner/test:1409:7)
at async startSubtestAfterBootstrap (node:internal/test_runner/harness:387:3)
test at tests\budget-resume.test.mjs:27:1
✖ explicit frozen preview resumes the same Task in a new Run, preserves completed tools and does not change global config or selected model (961.5493ms)
TypeError [Error]: f.store.updateConfig is not a function
at paused (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/budget-resume.test.mjs:10:60)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async TestContext.<anonymous> (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/budget-resume.test.mjs:28:11)
at async Test.run (node:internal/test_runner/test:1409:7)
at async Test.processPendingSubtests (node:internal/test_runner/test:974:7)
test at tests\budget-resume.test.mjs:38:1
✖ insufficient budgets, silently clamped capacity and arbitrary config fields reject without a physical request or mutating task budget (1207.5803ms)
TypeError [Error]: f.store.updateConfig is not a function
at paused (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/budget-resume.test.mjs:10:60)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async TestContext.<anonymous> (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/budget-resume.test.mjs:39:11)
at async Test.run (node:internal/test_runner/test:1409:7)
at async Test.processPendingSubtests (node:internal/test_runner/test:974:7)
test at tests\budget-resume.test.mjs:44:1
✖ changed session, changed registry, expiry and altered frozen preview all require a new explicit preview (1071.5479ms)
TypeError [Error]: f.store.updateConfig is not a function
at paused (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/budget-resume.test.mjs:10:60)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async TestContext.<anonymous> (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/budget-resume.test.mjs:45:11)
at async Test.run (node:internal/test_runner/test:1409:7)
at async Test.processPendingSubtests (node:internal/test_runner/test:974:7)
test at tests\budget-resume.test.mjs:56:1
✖ preview preserves unknown invocation status and increasing Task allowance is committed only with confirmed new Run (1018.3573ms)
TypeError [Error]: f.store.updateConfig is not a function
at paused (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/budget-resume.test.mjs:10:60)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async TestContext.<anonymous> (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/budget-resume.test.mjs:57:11)
at async Test.run (node:internal/test_runner/test:1409:7)
at async Test.processPendingSubtests (node:internal/test_runner/test:974:7)
@@ -0,0 +1,13 @@
✔ a budget pause persists concrete text/tool/history/image breakdown and never dispatches an oversized request (1877.4029ms)
✔ explicit frozen preview resumes the same Task in a new Run, preserves completed tools and does not change global config or selected model (2631.6384ms)
✔ insufficient budgets, silently clamped capacity and arbitrary config fields reject without a physical request or mutating task budget (1691.6229ms)
✔ changed session, changed registry, expiry and altered frozen preview all require a new explicit preview (2369.3845ms)
✔ preview preserves unknown invocation status and increasing Task allowance is committed only with confirmed new Run (2533.6439ms)
ℹ tests 5
ℹ suites 0
ℹ pass 5
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 11274.7023
@@ -0,0 +1,101 @@
✔ a budget pause persists concrete text/tool/history/image breakdown and never dispatches an oversized request (2997.0554ms)
✖ explicit frozen preview resumes the same Task in a new Run, preserves completed tools and does not change global config or selected model (3513.8586ms)
✔ insufficient budgets, silently clamped capacity and arbitrary config fields reject without a physical request or mutating task budget (3520.4991ms)
✔ changed session, changed registry, expiry and altered frozen preview all require a new explicit preview (3275.0687ms)
✖ preview preserves unknown invocation status and increasing Task allowance is committed only with confirmed new Run (3247.2136ms)
✔ pairing is short lived, single-use, generation-bound and validates exact permissions (965.5924ms)
✔ device transaction failure neither consumes the ticket nor leaves a credential (789.0047ms)
✔ devices have project and action boundaries; rotation, expiration, revocation and host changes reject old authority (1114.822ms)
✔ persistent registry stores hashes and a bounded audit, never raw credentials (1040.811ms)
✔ real TLS verifies IP SAN, CA chain, encrypted restart and public fingerprint (1273.6199ms)
✔ TLS sealing failure leaves listener closed and no plaintext or successful TLS registration (742.8388ms)
✔ HTTP pairing is concurrent single-use; secure cookie and strict origin/host checks (1093.9074ms)
✔ gateway never exposes management routes, arbitrary assets or unpaired project data (1121.7398ms)
✔ authorized project events paginate from original seq without leaking other project events or payloads (2176.9958ms)
✔ remote task projection excludes raw model history, host configuration, tool input and credentials (1064.2894ms)
✔ permission checks apply to direct remote mutation, not only UI controls (1064.1012ms)
✔ approval fingerprint and exact task/revision are bound; duplicate requests never execute twice (977.3428ms)
✔ unknown original operation is recorded and never replayed after response failure (1294.444ms)
✔ revocation and gateway closure reject old access without invoking runtime stop (1194.679ms)
✔ rate limits reject pairing brute force and do not persist candidate secrets (988.1917ms)
✔ real Windows CurrentUser DPAPI persists only a sealed CA and reopens it (2135.293ms)
✔ mobile approval executes the original Runtime command exactly once and rejects the later desktop decision (3246.1573ms)
✔ desktop rejection wins a concurrent mobile request and original command remains unexecuted (2258.763ms)
✔ phone stop waits for the original process exit and prevents later heartbeats and command replay (3645.9035ms)
✔ Run replacement during parent-stop wait is rejected rather than stopping the new Run (937.9841ms)
✔ diff pages preserve source SHA; report reads verify blobs and exclude unrelated artifact kinds (1484.4431ms)
✔ hot upgrade refuses an active gateway and restores closed gateway ownership on failure (923.7663ms)
✔ damaged device permissions or expiry fail closed and never overwrite the original registry (1138.4868ms)
✔ device revocation destroys its actual authenticated TLS connection (1193.174ms)
✔ companion observes only current Task screenshots, verifies original PNG bytes and loses access immediately on revoke (1513.6405ms)
✔ schema1 connections remain readable without inventing observed capabilities or migrating original state (1054.5251ms)
✔ protocol, unsupported capabilities and stream choice persist; client claims cannot forge verified evidence (794.7377ms)
✔ ability evidence belongs to exact connection and credential revision; unknown and unsupported reject required routing (0.2757ms)
✔ invalid declarations and inconsistent stream settings reject before registry, revision and credentials mutate (610.7537ms)
✔ saved engine budgets verify all Chat/Responses route variants and reject a mismatched output allowance (1215.7279ms)
✔ owned CC Switch SQLite imports the selected TOML Responses wire_api and leaves unknown clients untouched (1072.1526ms)
✔ Responses executes one original tool through Runtime, carries encrypted Items, reports raw usage and seals exact wire bytes (3025.5661ms)
✔ mixed-protocol pool keeps both actual variants and changes route on 429 without re-executing completed tools (3517.0097ms)
▶ Responses incomplete, failed, missing call identity and unsupported hosted outputs never dispatch a tool
✔ Reject {"body":{"id":"resp_owned","status":"incomplete","output":[{"type":"function_call","id":"fc_partial" (2101.2162ms)
✔ Reject {"body":{"id":"resp_owned","status":"failed","output":[{"type":"function_call","id":"fc_failed","cal (2247.4826ms)
✔ Reject {"body":{"id":"resp_owned","status":"completed","output":[{"type":"function_call","id":"fc_bad","cal (2081.4415ms)
✔ Reject {"body":{"id":"resp_owned","status":"completed","output":[{"type":"computer_call","id":"not-supporte (1807.2339ms)
✔ Responses incomplete, failed, missing call identity and unsupported hosted outputs never dispatch a tool (8238.5498ms)
▶ invalid JSON in a nonstream Chat or Responses tool group prevents every tool and pool replay
✔ chat-completions (1856.2509ms)
✔ responses (1984.9552ms)
✔ invalid JSON in a nonstream Chat or Responses tool group prevents every tool and pool replay (3841.6985ms)
✔ wire adapter preserves tool IDs but never passes Responses-private Items to Chat or another endpoint (0.1784ms)
✔ connection JSON import accepts explicit Responses protocol and continues to reject unknown protocols without reading client sessions (698.2482ms)
✔ HTTP download preserves original malformed SSE bytes and artifact SHA instead of decoding invalid UTF8 (2671.5639ms)
✔ real Chat SSE carries UTF8 and split tool JSON; Runtime executes only after DONE, stores partial progress and original usage (3549.964ms)
✔ Responses typed SSE validates original item identity, terminal data, raw usage and tool result pair (2055.8266ms)
✔ incomplete network stream retains unknown attempt and never automatically switches pool or dispatches fragment tools (1591.9915ms)
✔ stopping an active HTTP stream closes only original request and keeps partial text without executing tools (1387.9026ms)
✔ explicit streaming probe uses actual SSE despite unknown declaration and binds its own original attempt (634.4211ms)
✔ coalesced initial SSE events publish the latest partial state even when the upstream stays idle (1562.436ms)
✔ stream timeout closes the original HTTP response, preserves redacted capture and never retries (1006.5371ms)
✔ SSE accepts CR-only final event boundaries and retains exact invalid UTF8 bytes without dispatch (1.5802ms)
▶ stream parser rejects truncation, finish length, malformed JSON, duplicate sequence, changed final item and oversized data
✔ reject 0 (0.4007ms)
✔ reject 1 (0.2435ms)
✔ reject 2 (0.2688ms)
✔ reject 3 (5.7145ms)
✔ reject 4 (0.1532ms)
✔ reject 5 (0.1481ms)
✔ stream parser rejects truncation, finish length, malformed JSON, duplicate sequence, changed final item and oversized data (7.7568ms)
ℹ tests 64
ℹ suites 0
ℹ pass 62
ℹ fail 2
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 50232.4162
✖ failing tests:
test at tests\budget-resume.test.mjs:27:1
✖ explicit frozen preview resumes the same Task in a new Run, preserves completed tools and does not change global config or selected model (3513.8586ms)
Error: 原任务、连接或预算预览已变化,请重新准备后确认。
at fail (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/context/budget-resume.mjs:6:48)
at BudgetResume.verify (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/context/budget-resume.mjs:57:198)
at Runtime.resumeBudget (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/server/runtime.mjs:126:89)
at TestContext.<anonymous> (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/budget-resume.test.mjs:30:13)
at async Test.run (node:internal/test_runner/test:1409:7)
at async Test.processPendingSubtests (node:internal/test_runner/test:974:7) {
status: 409
}
test at tests\budget-resume.test.mjs:56:1
✖ preview preserves unknown invocation status and increasing Task allowance is committed only with confirmed new Run (3247.2136ms)
Error: 原任务、连接或预算预览已变化,请重新准备后确认。
at fail (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/context/budget-resume.mjs:6:48)
at BudgetResume.verify (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/context/budget-resume.mjs:57:198)
at Runtime.resumeBudget (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/server/runtime.mjs:126:89)
at TestContext.<anonymous> (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/budget-resume.test.mjs:61:13)
at async Test.run (node:internal/test_runner/test:1409:7)
at async Test.processPendingSubtests (node:internal/test_runner/test:974:7) {
status: 409
}
@@ -0,0 +1,158 @@
✔ PNG bytes are fully decoded, metadata-free and bounded; JPEG EXIF orientation is applied to the sent PNG (104.6542ms)
✖ forged type, short headers, CRC damage, incomplete chunks, trailing payloads, animation and dimension bombs reject (23.5584ms)
✖ draft image ownership, withdrawal, reload and atomic Task binding retain original SHA and original bytes (1095.482ms)
✔ a failed session transaction restores draft status and cannot leave a Run consuming the attachment (1074.7241ms)
✔ draft limits, duplicate selection, source changes and cross-Task association reject before dispatch (2223.6267ms)
✔ demo and legacy paths refuse image dispatch without creating a Task or consuming the draft (1187.2725ms)
✖ chat-completions sends one owned image per actual request, pairs original tools and verifies exact sealed bytes (1283.0097ms)
✖ responses sends one owned image per actual request, pairs original tools and verifies exact sealed bytes (1008.3599ms)
✖ mixed pool excludes unknown vision before lease and sends zero HTTP to the incompatible member (1287.0283ms)
✖ vision probe requires correct randomized pixel order and evidence expires when the connection revision changes (1014.5866ms)
✔ HTTP upload/read/withdraw uses session authorization, returns byte SHA and refuses unknown ownership (1169.7763ms)
✔ image accounting excludes Base64 as text but seals every original request byte and reserves image input separately (2.2418ms)
✔ schema1 connections remain readable without inventing observed capabilities or migrating original state (855.9471ms)
✔ protocol, unsupported capabilities and stream choice persist; client claims cannot forge verified evidence (1193.9145ms)
✔ ability evidence belongs to exact connection and credential revision; unknown and unsupported reject required routing (0.7101ms)
✔ invalid declarations and inconsistent stream settings reject before registry, revision and credentials mutate (1018.1341ms)
✔ saved engine budgets verify all Chat/Responses route variants and reject a mismatched output allowance (1371.9733ms)
✔ owned CC Switch SQLite imports the selected TOML Responses wire_api and leaves unknown clients untouched (1416.8663ms)
✔ Responses executes one original tool through Runtime, carries encrypted Items, reports raw usage and seals exact wire bytes (3365.0207ms)
✔ mixed-protocol pool keeps both actual variants and changes route on 429 without re-executing completed tools (3263.2217ms)
▶ Responses incomplete, failed, missing call identity and unsupported hosted outputs never dispatch a tool
✔ Reject {"body":{"id":"resp_owned","status":"incomplete","output":[{"type":"function_call","id":"fc_partial" (1190.0446ms)
✔ Reject {"body":{"id":"resp_owned","status":"failed","output":[{"type":"function_call","id":"fc_failed","cal (1248.8223ms)
✔ Reject {"body":{"id":"resp_owned","status":"completed","output":[{"type":"function_call","id":"fc_bad","cal (1388.761ms)
✔ Reject {"body":{"id":"resp_owned","status":"completed","output":[{"type":"computer_call","id":"not-supporte (1198.4518ms)
✔ Responses incomplete, failed, missing call identity and unsupported hosted outputs never dispatch a tool (5027.5271ms)
▶ invalid JSON in a nonstream Chat or Responses tool group prevents every tool and pool replay
✔ chat-completions (1340.444ms)
✔ responses (1234.363ms)
✔ invalid JSON in a nonstream Chat or Responses tool group prevents every tool and pool replay (2575.3827ms)
✔ wire adapter preserves tool IDs but never passes Responses-private Items to Chat or another endpoint (0.1751ms)
✔ connection JSON import accepts explicit Responses protocol and continues to reject unknown protocols without reading client sessions (589.5139ms)
ℹ tests 30
ℹ suites 0
ℹ pass 24
ℹ fail 6
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 20907.3335
✖ failing tests:
test at tests\input-attachments.test.mjs:38:1
✖ forged type, short headers, CRC damage, incomplete chunks, trailing payloads, animation and dimension bombs reject (23.5584ms)
AssertionError [ERR_ASSERTION]: The validation function is expected to return "true". Received false
Caught error:
Error: 图片编码或大小无效。
at TestContext.<anonymous> (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/input-attachments.test.mjs:48:10)
at Test.runInAsyncScope (node:async_hooks:227:14)
at Test.run (node:internal/test_runner/test:1402:25)
at Test.processPendingSubtests (node:internal/test_runner/test:974:18)
at Test.postRun (node:internal/test_runner/test:1542:19)
at Test.run (node:internal/test_runner/test:1467:12)
at async startSubtestAfterBootstrap (node:internal/test_runner/harness:387:3) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: Error: 图片编码或大小无效。
at reject (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/context/input-attachments.mjs:6:57)
at validateImage (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/context/input-attachments.mjs:87:110)
at file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/input-attachments.test.mjs:48:21
at getActual (node:assert:611:5)
at strict.throws (node:assert:759:24)
at TestContext.<anonymous> (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/input-attachments.test.mjs:48:10)
at Test.runInAsyncScope (node:async_hooks:227:14)
at Test.run (node:internal/test_runner/test:1402:25)
at Test.processPendingSubtests (node:internal/test_runner/test:974:18)
at Test.postRun (node:internal/test_runner/test:1542:19),
operator: 'throws',
diff: 'simple'
}
test at tests\input-attachments.test.mjs:51:1
✖ draft image ownership, withdrawal, reload and atomic Task binding retain original SHA and original bytes (1095.482ms)
AssertionError [ERR_ASSERTION]: The input did not match the regular expression /归属|所属|不存在/. Input:
'Error: 执行记录不属于当前会话。'
at TestContext.<anonymous> (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/input-attachments.test.mjs:55:58)
at Test.runInAsyncScope (node:async_hooks:227:14)
at Test.run (node:internal/test_runner/test:1402:25)
at Test.processPendingSubtests (node:internal/test_runner/test:974:18)
at Test.postRun (node:internal/test_runner/test:1542:19)
at Test.run (node:internal/test_runner/test:1467:12)
at async Test.processPendingSubtests (node:internal/test_runner/test:974:7) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: Error: 执行记录不属于当前会话。
at Store.owned (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/server/store.mjs:602:130)
at InputAttachments.get (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/context/input-attachments.mjs:115:39)
at InputAttachments.read (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/context/input-attachments.mjs:126:20)
at file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/input-attachments.test.mjs:55:77
at getActual (node:assert:611:5)
at strict.throws (node:assert:759:24)
at TestContext.<anonymous> (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/input-attachments.test.mjs:55:58)
at Test.runInAsyncScope (node:async_hooks:227:14)
at Test.run (node:internal/test_runner/test:1402:25)
at Test.processPendingSubtests (node:internal/test_runner/test:974:18),
expected: /归属|所属|不存在/,
operator: 'throws',
diff: 'simple'
}
test at tests\input-attachments.test.mjs:88:56
✖ chat-completions sends one owned image per actual request, pairs original tools and verifies exact sealed bytes (1283.0097ms)
Error: 持久执行记录不能移动到其他任务或项目。
at StateDatabase.writeRecords (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/storage/state-database.mjs:67:15)
at file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/storage/state-database.mjs:98:40
at StateDatabase.transaction (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/storage/state-database.mjs:37:26)
at StateDatabase.save (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/storage/state-database.mjs:97:17)
at Store.save (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/server/store.mjs:363:36)
at Store.beginRun (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/server/store.mjs:483:10)
at Runtime.start (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/server/runtime.mjs:188:31)
at TestContext.<anonymous> (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/input-attachments.test.mjs:97:77)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async Test.run (node:internal/test_runner/test:1409:7)
test at tests\input-attachments.test.mjs:88:56
✖ responses sends one owned image per actual request, pairs original tools and verifies exact sealed bytes (1008.3599ms)
Error: 持久执行记录不能移动到其他任务或项目。
at StateDatabase.writeRecords (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/storage/state-database.mjs:67:15)
at file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/storage/state-database.mjs:98:40
at StateDatabase.transaction (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/storage/state-database.mjs:37:26)
at StateDatabase.save (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/storage/state-database.mjs:97:17)
at Store.save (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/server/store.mjs:363:36)
at Store.beginRun (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/server/store.mjs:483:10)
at Runtime.start (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/server/runtime.mjs:188:31)
at TestContext.<anonymous> (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/input-attachments.test.mjs:97:77)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async Test.run (node:internal/test_runner/test:1409:7)
test at tests\input-attachments.test.mjs:106:1
✖ mixed pool excludes unknown vision before lease and sends zero HTTP to the incompatible member (1287.0283ms)
Error: 持久执行记录不能移动到其他任务或项目。
at StateDatabase.writeRecords (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/storage/state-database.mjs:67:15)
at file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/storage/state-database.mjs:98:40
at StateDatabase.transaction (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/storage/state-database.mjs:37:26)
at StateDatabase.save (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/storage/state-database.mjs:97:17)
at Store.save (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/server/store.mjs:363:36)
at Store.beginRun (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/server/store.mjs:483:10)
at Runtime.start (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/server/runtime.mjs:188:31)
at TestContext.<anonymous> (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/input-attachments.test.mjs:112:11)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async Test.run (node:internal/test_runner/test:1409:7)
test at tests\input-attachments.test.mjs:117:1
✖ vision probe requires correct randomized pixel order and evidence expires when the connection revision changes (1014.5866ms)
Error: 服务没有返回纯文本响应;未标为已验证。
at error (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/models/model-hub.mjs:11:56)
at ModelHub.probe (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/src/core/models/model-hub.mjs:143:91)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async TestContext.<anonymous> (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/input-attachments.test.mjs:125:3)
at async Test.run (node:internal/test_runner/test:1409:7)
at async Test.processPendingSubtests (node:internal/test_runner/test:974:7) {
status: 400
}
@@ -0,0 +1,20 @@
✔ PNG bytes are fully decoded, metadata-free and bounded; JPEG EXIF orientation is applied to the sent PNG (103.3022ms)
✔ forged type, short headers, CRC damage, incomplete chunks, trailing payloads, animation and dimension bombs reject (23.319ms)
✔ draft image ownership, withdrawal, reload and atomic Task binding retain original SHA and original bytes (921.1045ms)
✔ a failed session transaction restores draft status and cannot leave a Run consuming the attachment (674.857ms)
✔ draft limits, duplicate selection, source changes and cross-Task association reject before dispatch (1182.5494ms)
✔ demo and legacy paths refuse image dispatch without creating a Task or consuming the draft (705.6051ms)
✔ chat-completions sends one owned image per actual request, pairs original tools and verifies exact sealed bytes (1862.306ms)
✔ responses sends one owned image per actual request, pairs original tools and verifies exact sealed bytes (2011.1684ms)
✔ mixed pool excludes unknown vision before lease and sends zero HTTP to the incompatible member (1429.9673ms)
✔ vision probe requires correct randomized pixel order and evidence expires when the connection revision changes (883.0318ms)
✔ HTTP upload/read/withdraw uses session authorization, returns byte SHA and refuses unknown ownership (724.9261ms)
✔ image accounting excludes Base64 as text but seals every original request byte and reserves image input separately (3.0494ms)
ℹ tests 12
ℹ suites 0
ℹ pass 12
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 10766.1508
@@ -0,0 +1,20 @@
> local-agent-workbench@1.17.0 build
> tsc --noEmit && vite build && node scripts/build-mobile.mjs && node scripts/build-server.mjs
vite v7.3.7 building client environment for production...
transforming...
✓ 1729 modules transformed.
rendering chunks...
computing gzip size...
dist-client/.vite/manifest.json 0.55 kB │ gzip: 0.22 kB
dist-client/index.html 0.58 kB │ gzip: 0.40 kB
dist-client/mobile.html 0.82 kB │ gzip: 0.46 kB
dist-client/assets/mobile-CNDnI_ru.css 11.92 kB │ gzip: 3.12 kB
dist-client/assets/desktop-XQhtWX-k.css 138.56 kB │ gzip: 26.53 kB
dist-client/assets/mobile-DVWh54VU.js 24.31 kB │ gzip: 8.65 kB
dist-client/assets/x-Cc3T3VuL.js 225.51 kB │ gzip: 70.77 kB
dist-client/assets/desktop-DxyJCC9F.js 294.22 kB │ gzip: 83.36 kB
✓ built in 1.17s
Mobile shell built: 3 allowed assets; API and project data are never cached.
Server bundle built.
Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

@@ -0,0 +1,49 @@
{
"success": true,
"version": "1.17.0",
"appRoot": "D:\\Ai-project\\REA逆向\\Agent-Workbench",
"passed": [
"desktop upload, explicit route, refreshed draft, original download SHA, one paired tool and narrow task history",
"forged image rejects without losing task text or sending a model request",
"explicit budget preview and confirmation retain Task, attachment and completed tool while global capacity stays unchanged",
"paired TLS companion verifies same screenshot, refresh restores it and revoke clears project/image content",
"stopping screenshot SSE closes original HTTP and dispatches zero partial tools"
],
"screenshots": [
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb\\desktop-draft.png",
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb\\desktop-attached.png",
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb\\narrow-attached.png",
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb\\desktop-budget-preview.png",
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb\\narrow-budget-preview.png",
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb\\companion-image.png",
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb\\desktop-image-stopped.png"
],
"requests": [
{
"route": "/v1/responses",
"sha256": "53d125c9a125d4b4687dae6d7bb2a06ca4445b1dbfb15d933b0919c779f1dbcc",
"imageCount": 1
},
{
"route": "/v1/responses",
"sha256": "00ebfc2a3bebaeaab200e8d561f0f76ad01e69508437370450530ceb5f2b896c",
"imageCount": 1
},
{
"route": "/v1/responses",
"sha256": "762394eb8811ed1ca354fd99c46e980cbce18a0851923ba75d3e472a778d6cb2",
"imageCount": 1
},
{
"route": "/v1/responses",
"sha256": "7d358a6140bcb5d3684b1aec71606704c05e9e2e77d64f1c8e7a16fcb20a4a15",
"imageCount": 1
},
{
"route": "/v1/responses",
"sha256": "f364f9ba35c6f573a0b105b8ab984ceae02ab7f5b14d4195041a7ea8978c59e7",
"imageCount": 1
}
],
"pageErrors": []
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

@@ -0,0 +1,15 @@
{
"success": false,
"error": "Error: Timed out waiting for test state.\n at until (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/helpers.mjs:39:38)\n at process.processTicksAndRejections (node:internal/process/task_queues:104:5)\n at async file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/scripts/verify-vision-ui.mjs:68:291",
"passed": [
"desktop upload, explicit route, refreshed draft, original download SHA, one paired tool and narrow task history",
"forged image rejects without losing task text or sending a model request"
],
"screenshots": [
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54\\desktop-draft.png",
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54\\desktop-attached.png",
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54\\narrow-attached.png",
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54\\failure-desktop.png"
],
"pageErrors": []
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

@@ -0,0 +1,49 @@
{
"success": true,
"version": "1.17.0",
"appRoot": "D:\\Ai-project\\REA逆向\\Agent-Workbench",
"passed": [
"desktop upload, explicit route, refreshed draft, original download SHA, one paired tool and narrow task history",
"forged image rejects without losing task text or sending a model request",
"explicit budget preview and confirmation retain Task, attachment and completed tool while global capacity stays unchanged",
"paired TLS companion verifies same screenshot, refresh restores it and revoke clears project/image content",
"stopping screenshot SSE closes original HTTP and dispatches zero partial tools"
],
"screenshots": [
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f\\desktop-draft.png",
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f\\desktop-attached.png",
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f\\narrow-attached.png",
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f\\desktop-budget-preview.png",
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f\\narrow-budget-preview.png",
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f\\companion-image.png",
"D:\\Ai-project\\REA逆向\\Agent-Workbench\\.qa\\vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f\\desktop-image-stopped.png"
],
"requests": [
{
"route": "/v1/responses",
"sha256": "78d6e369fedfba0b639a1186c553461f6020cf3d4d36ab0fd2e86993d1660ec1",
"imageCount": 1
},
{
"route": "/v1/responses",
"sha256": "6aa8d7007e6c5a9f09c035338da8525bf7fada9e51b8e996534382389a49b0da",
"imageCount": 1
},
{
"route": "/v1/responses",
"sha256": "65839702be1224f7cbf72336d3144bdf777e8e842bcc025273a3377624658ba9",
"imageCount": 1
},
{
"route": "/v1/responses",
"sha256": "2409e8e8885dae045496f918a8b35ac1d3b8aecd40e525dd16102a468c9e2c34",
"imageCount": 1
},
{
"route": "/v1/responses",
"sha256": "aaa78d531d2f8bac75ee9be8889c46276a3f8da36fd0069e5bbcf99aeb5461cf",
"imageCount": 1
}
],
"pageErrors": []
}
@@ -0,0 +1,13 @@
PASS desktop upload, explicit route, refreshed draft, original download SHA, one paired tool and narrow task history
PASS forged image rejects without losing task text or sending a model request
EVIDENCE D:\Ai-project\REA逆向\Agent-Workbench\.qa\vision-ui-69df73a3-f93c-47fe-af3a-aa7f336d0e54
node:internal/modules/run_main:107
triggerUncaughtException(
^
Error: Timed out waiting for test state.
at until (file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/tests/helpers.mjs:39:38)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async file:///D:/Ai-project/REA%E9%80%86%E5%90%91/Agent-Workbench/scripts/verify-vision-ui.mjs:68:291
Node.js v24.22.1
@@ -0,0 +1,6 @@
PASS desktop upload, explicit route, refreshed draft, original download SHA, one paired tool and narrow task history
PASS forged image rejects without losing task text or sending a model request
PASS explicit budget preview and confirmation retain Task, attachment and completed tool while global capacity stays unchanged
PASS paired TLS companion verifies same screenshot, refresh restores it and revoke clears project/image content
PASS stopping screenshot SSE closes original HTTP and dispatches zero partial tools
EVIDENCE D:\Ai-project\REA逆向\Agent-Workbench\.qa\vision-ui-b2426469-35ac-4e5a-83ef-2f8c0260276f
@@ -0,0 +1,6 @@
PASS desktop upload, explicit route, refreshed draft, original download SHA, one paired tool and narrow task history
PASS forged image rejects without losing task text or sending a model request
PASS explicit budget preview and confirmation retain Task, attachment and completed tool while global capacity stays unchanged
PASS paired TLS companion verifies same screenshot, refresh restores it and revoke clears project/image content
PASS stopping screenshot SSE closes original HTTP and dispatches zero partial tools
EVIDENCE D:\Ai-project\REA逆向\Agent-Workbench\.qa\vision-ui-0354cc03-2cb2-4456-ac32-f87cd11b63cb
+7
View File
@@ -721,3 +721,10 @@ Responses已采用typed Items、call_id原配对和同线路加密reasoning续
1.17.0完整本地交付:Chat/Responses实际协议、有界SSE、完整工具组核验、能力选池、显式检测与原请求证据已实现。独立源码558/558、25类191组历史UI、随包原生窗口7项/原生流程9组/桌面三工程16节点、Responses三工程13节点及两套父Node8/8、React9/9、Python10/10通过;源码与便携各7组伴随端/5组新协议界面、同载荷隔离安装/重启/卸载7组、正式20页通过。正式PID36552/Provider保持,17项目/30全部会话/2590记录/4653事件,全部表每行/会话导出/工件原字节保持;1455条工件及1366个去重文件核对通过,9229关闭。公开模型中心仅增加逐项核对的默认能力字段,原存储不迁移。正式手机网关继续关闭、无设备/证书,未迁入QA身份。真实模型工程/Purge收益继续按用户选择单列待验,本轮真实模型请求0;1.17没有新增iPhone实机流式结论。
新协议不能只改Provider;实际请求预算、引擎完成核验、导入、能力筛选、原字节下载及主窗口选路必须共用同一契约。模型声明不替代实际检测,增量片段不替代终结结果。下一步按PLAN-1.18先用原证据审查任务上下文暂停,再接工程附件/视觉。
## 1.18起步
1.17已完成;当前完整请求预算按实际JSON字节估算,图片base64不能直接当文字token。采用所属附件引用存历史,仅在请求计划中解析原字节为Chat/Responses图像块,SHA仍封存完整实际正文;预算另列图像保守预留与真实usage。原暂停表明输入估算36,771高于16,000声明容量,需具体分解及同Task显式调整,不盲目提高配置。OpenAI官方images-vision已实际读取,data URL图像块与detail以原文为依据。
1.18恢复审查:Store.ensureStorage已按新core kind创建新容器,旧core保留可回滚,不需要历史写入迁移。输入附件绑定改为与run.started同一会话事务。恢复时多文件大批读取两次截断和一次猜测budgets路径失败;后续限定真实路径/小段。一次补丁因hot-upgrade长行锚点不匹配整批拒绝,已确认无部分写入并用准确短锚点修正。PNG/JPEG初始实现尚未通过验收。
+21 -4
View File
@@ -11,8 +11,10 @@
"@babel/parser": "7.29.11",
"@peculiar/x509": "3.1.0",
"diff": "^8.0.2",
"jpeg-js": "0.4.4",
"lucide-react": "^0.548.0",
"playwright": "1.64.1",
"pngjs": "7.0.0",
"qrcode": "1.5.4",
"react": "^19.2.0",
"react-dom": "^19.2.0",
@@ -1976,6 +1978,12 @@
"node": ">=8"
}
},
"node_modules/jpeg-js": {
"version": "0.4.4",
"resolved": "https://registry.npmjs.org/jpeg-js/-/jpeg-js-0.4.4.tgz",
"integrity": "sha512-WZzeDOEtTOBK4Mdsar0IqEU5sMr3vSV2RqkAIzUEV2BHnUfKGyswWFPFwK5EeDo93K3FohSHbLAjj0s1Wzd+dg==",
"license": "BSD-3-Clause"
},
"node_modules/js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
@@ -2169,12 +2177,12 @@
}
},
"node_modules/pngjs": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/pngjs/-/pngjs-5.0.0.tgz",
"integrity": "sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw==",
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/pngjs/-/pngjs-7.0.0.tgz",
"integrity": "sha512-LKWqWJRhstyYo9pGvgor/ivk2w94eSjE3RGVuzLGlr3NmD8bf7RcYGze1mNdEHRP6TRP6rMuDHk5t44hnTRyow==",
"license": "MIT",
"engines": {
"node": ">=10.13.0"
"node": ">=14.19.0"
}
},
"node_modules/postcss": {
@@ -2233,6 +2241,15 @@
"node": ">=10.13.0"
}
},
"node_modules/qrcode/node_modules/pngjs": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/pngjs/-/pngjs-5.0.0.tgz",
"integrity": "sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw==",
"license": "MIT",
"engines": {
"node": ">=10.13.0"
}
},
"node_modules/react": {
"version": "19.3.1",
"resolved": "https://registry.npmjs.org/react/-/react-19.3.1.tgz",
+2
View File
@@ -45,8 +45,10 @@
"@babel/parser": "7.29.11",
"@peculiar/x509": "3.1.0",
"diff": "^8.0.2",
"jpeg-js": "0.4.4",
"lucide-react": "^0.548.0",
"playwright": "1.64.1",
"pngjs": "7.0.0",
"qrcode": "1.5.4",
"react": "^19.2.0",
"react-dom": "^19.2.0",
+10
View File
@@ -841,3 +841,13 @@ F冻结前:Responses三工程13节点和父8/8/9/9/10/10、25类191组历史UI
最终不可变Agent-Workbench-1.17.0-win-x64-20261031150548103,来源a72dc0fbc1f3430f46b12ba0b1dbbe2c457056d8;封存659份原件/119368154字节。所有冻结输入/构建/原基准保持,文档/回顾/能力矩阵与下一1.18方案已同步。正式安装只stage/upgrade/activate各一次,后续为只读核对与原生回看。准备最终本地Git提交及独立ACCEPTANCE说明,不推送远端。
最终收尾复核:659份原件/119368154字节与Git暂存原字节严格一致,170份证据JSON、15份文档的342个本地链接、23份执行器语法及387输入/22构建/40基准全部通过。正式原生1.17窗口与模型中心已实际回看,窗口保留开启,原用户任务/空输入/既有预算暂停保持;未触发模型请求。封存首轮目录筛选失败在写入前停止,原失败/脚本保持,seal-retry成功及终结日志另有收据;产品验收与升级未重跑。最终文档、回顾、能力矩阵和1.18方案准备本地提交,之后生成绑定最终commit的独立ACCEPTANCE说明。
## 2026-11-01 1.18启动
干净基线0d1ab74,分支feat/vision-attachments-1.18。沿用planning-with-files/product-ui-ux/frontend-design并核对官方视觉协议。session-catchup无额外记录。首次只读猜测src/ui、src/mobile、server/server及model-protocols路径失败,已用rg定位client/mobile、app和core/models/protocols;大输出截断后改限定段。一次计划补丁因progress标题猜测被整批拒绝,无部分写入,改为已知task_plan锚点与追加日志。正式配置未动。
1.18 A–C首次专项24/30,原失败保存在.qa/vision-core-first.log:发现实际数据库禁止将已保存draft工件移到Task,因此采用新ID的Task绑定记录/原工件引用、原draft标consumed,同事务提交并保留原身份,不放宽数据库约束。2MB余数边界的HTTP状态已修正;三个fixture错误调用completion与中文归属断言已修正。第二轮附件12/12全部通过,两协议各2真实loopback请求/1实际工具、原请求SHA、vision前选池、四色合成probe均通过。仍不是实际模型视觉效果结论。
初次构建npm子脚本拾取系统Node16失败,已使用进程局部PATH指向固定Node24.22.1;第二轮构建通过。全局Node和正式PID未更改。后续预算/手机/UI专项与发行仍待验。
1.18 A–E回顾完成:附件12/12、预算5/5及最新联合17/17通过,桌面/390px/自有TLS新UI第三轮5组通过。原core/预算/UI失败及最终原件封存docs/vision-inputs-ae-evidence,原持久归属/预算status/QA选路/旧Task夹具原因分别记录。实际回看补正被排除池首模型的预览文案、分钟单位与窄屏触控区域;全部构建通过。正式只读确认1.17/PID36552/17项目,真实模型0请求。A–E本地Git保存后继续F工程/完整回归及发行,不将待验项称交付。
+89
View File
@@ -0,0 +1,89 @@
import fs from 'node:fs';
import path from 'node:path';
import http from 'node:http';
import https from 'node:https';
import assert from 'node:assert/strict';
import { createHash,randomUUID,X509Certificate } from 'node:crypto';
import { chromium,expect } from 'playwright/test';
import { fixture,launchWorkbench,until } from '../tests/helpers.mjs';
import { requestImages } from '../src/shared/contracts/model-request.mjs';
import { PNG } from 'pngjs';
if(process.argv.includes('--help')){console.log('node scripts/verify-vision-ui.mjs [--app-root <absolute-package>] — owned image HTTP, desktop/390px upload/history/download, exact Task budget resume, TLS companion read/revoke and original SSE stop. No configured model calls or iPhone claim.');process.exit(0);}
const args=process.argv.slice(2);assert.ok(!args.length||args.length===2&&args[0]==='--app-root'&&path.isAbsolute(args[1]));
const appRoot=fs.realpathSync.native(args[1]??process.cwd()),directory=path.resolve('.qa','vision-ui-'+randomUUID());fs.mkdirSync(directory,{recursive:true});
const disposers=[],t={after:fn=>disposers.push(fn)},f=fixture(t);f.store.close();
const requests=[],sockets=new Set(),held=new Set();let mode='success',closed=0;
const message=text=>({type:'message',role:'assistant',content:[{type:'output_text',text}]}),result=output=>({status:'completed',output,usage:{input_tokens:200,output_tokens:30,total_tokens:230}});
const model=http.createServer(async(req,res)=>{try{
const chunks=[];for await(const chunk of req)chunks.push(chunk);const body=JSON.parse(Buffer.concat(chunks));requests.push({route:req.url,body});
assert.ok(requestImages(body).length===1,'one screenshot per request');
assert.notEqual(body.model,'text-only','text member must never dispatch');
if(mode==='hold'){
assert.equal(body.stream,true);res.writeHead(200,{'Content-Type':'text/event-stream'});
res.write('data: '+JSON.stringify({type:'response.output_text.delta',sequence_number:0,delta:'截图正在核对;参数尚未完整。'})+'\n\n');
held.add(res);res.on('close',()=>{held.delete(res);closed++;});return;
}
const latestUser=body.input.findLastIndex(value=>value.role==='user'&&typeof value.content==='string');
const output=body.input.slice(latestUser+1).some(value=>value.type==='function_call_output')?[message('原截图与实际工程读取结果已经核对。')]
:[{type:'function_call',call_id:'image-files-'+requests.length,name:'list_files',arguments:'{"path":"","depth":1}'}];
res.writeHead(200,{'Content-Type':'application/json'});res.end(JSON.stringify(result(output)));
}catch(error){res.writeHead(500,{'Content-Type':'application/json'});res.end(JSON.stringify({error:{message:error.message}}));}});
model.on('connection',socket=>{sockets.add(socket);socket.on('close',()=>sockets.delete(socket));});await new Promise(resolve=>model.listen(0,'127.0.0.1',resolve));
const host=await launchWorkbench(t,f.data,{}, {appRoot,nodePath:args.length?path.join(appRoot,'runtime/node.exe'):process.execPath});assert.notEqual(new URL(host.url).port,'4318');
const browser=await chromium.launch({channel:'msedge',headless:true}),page=await browser.newPage({viewport:{width:1440,height:1000}}),passed=[],screenshots=[],errors=[];
page.on('pageerror',error=>errors.push(error.message));const get=()=>host.api('/sessions/'+f.session.id),mark=value=>{passed.push(value);console.log('PASS '+value);};
const sha=bytes=>createHash('sha256').update(bytes).digest('hex');
async function shot(target,name){const file=path.join(directory,name+'.png');await target.screenshot({path:file});screenshots.push(file);assert.ok(await target.locator('body').evaluate(node=>node.scrollWidth<=innerWidth),'page overflow '+name);}
let gateway,relay,cookie='',mobile;
try{
const raw=new PNG({width:1280,height:720});for(let y=0;y<720;y++)for(let x=0;x<1280;x++)raw.data.set(x>900?[190,60,50,255]:[28,76,74,255],(y*1280+x)*4);
const imageFile=path.join(directory,'engineering-screenshot.png');fs.writeFileSync(imageFile,PNG.sync.write(raw));
const baseUrl='http://127.0.0.1:'+model.address().port+'/v1';
const vision=await host.api('/model-center/connections',{name:'截图验收 Responses',model:'owned-vision',protocol:'responses',baseUrl,requiresKey:false,contextLimit:64000,capabilityDeclarations:{vision:'supported'}});
const center=await host.api('/model-center'),visionId=vision.id??center.connections.find(row=>row.name==='截图验收 Responses').id;
await host.api('/model-center/connections',{name:'纯文本排除样本',model:'text-only',baseUrl,requiresKey:false,contextLimit:64000});
const textId=(await host.api('/model-center')).connections.find(row=>row.model==='text-only').id;
const pool=await host.api('/model-center/pools',{name:'视觉验收池',members:[{connectionId:textId},{connectionId:visionId}]});
const poolId=pool.id??(await host.api('/model-center')).pools.find(row=>row.name==='视觉验收池').id;
await host.api('/model-center/select',{type:'pool',id:poolId});
await page.addInitScript(({projectId,sessionId})=>{localStorage.setItem('awb-project',projectId);localStorage.setItem('awb-session',sessionId);},{projectId:f.project.id,sessionId:f.session.id});
await page.goto(host.url);await page.waitForLoadState('networkidle');
await page.getByLabel('任务内容',{exact:true}).fill('根据这张截图核对当前工程,保留原工具结果。');
await page.getByLabel('选择工程截图',{exact:true}).setInputFiles(imageFile);await expect(page.locator('.input-draft')).toContainText('SHA-256 已核对');
await expect(page.locator('.input-route')).toContainText('视觉验收池');await shot(page,'desktop-draft');
await page.getByRole('button',{name:'查看截图 engineering-screenshot.png',exact:true}).click();const dialog=page.getByRole('dialog');await expect(dialog).toContainText('1280 × 720');
const downloadPromise=page.waitForEvent('download');await dialog.getByRole('button',{name:'下载原图',exact:true}).click();const download=await downloadPromise,file=path.join(directory,'downloaded-original.png');await download.saveAs(file);assert.equal(sha(fs.readFileSync(file)),sha(fs.readFileSync(imageFile)));await page.keyboard.press('Escape');
await page.reload();await expect(page.locator('.input-draft')).toContainText('SHA-256 已核对');await page.locator('.input-draft input[type=checkbox]').check();
await page.getByLabel('任务内容',{exact:true}).fill('根据截图核对工程。');await page.getByRole('button',{name:'发送任务',exact:true}).click();await until(async()=>(await get()).status==='completed',15000);
let session=await get();assert.equal(requests.length,2);assert.equal(session.execution.progress.completedTools,1);assert.equal(session.inputAttachments.filter(row=>row.status==='attached').length,1);
await expect(page.locator('.message-user .input-receipt')).toContainText('SHA-256 已核对');await shot(page,'desktop-attached');await page.setViewportSize({width:390,height:844});await shot(page,'narrow-attached');await page.setViewportSize({width:1440,height:1000});
mark('desktop upload, explicit route, refreshed draft, original download SHA, one paired tool and narrow task history');
const invalid=path.join(directory,'forged.png');fs.writeFileSync(invalid,'not a real PNG');await page.getByLabel('任务内容',{exact:true}).fill('失败后保留输入');await page.getByLabel('选择工程截图',{exact:true}).setInputFiles(invalid);await expect(page.locator('.toast')).toContainText('类型不符');await expect(page.getByLabel('任务内容',{exact:true})).toHaveValue('失败后保留输入');assert.equal(requests.length,2);mark('forged image rejects without losing task text or sending a model request');
// Reuse the actual completed tool group in the same Task after a deliberate
// insufficient context resume; no completed tool is requested again.
// Completed Tasks are immutable history. Start a new screenshot Task, stop at
// one tool round, then exercise budget continuation within that Task.
await host.api('/config',{...host.bootstrap.config,mode:'compatible',model:'unused',baseUrl,contextLimit:16000,maxSteps:1});
await host.api('/model-center/select',{type:'pool',id:poolId});
await page.reload();await page.getByLabel('选择工程截图',{exact:true}).setInputFiles(imageFile);await expect(page.locator('.input-draft')).toContainText('SHA-256 已核对');await page.getByLabel('任务内容',{exact:true}).fill('截图任务预算续接验收');await page.getByRole('button',{name:'发送任务',exact:true}).click();await until(async()=>(await get()).status==='paused',15000);
const original=await get(),taskId=original.execution.task.id,count=requests.length;
await host.api('/config',{...(await host.api('/bootstrap')).config,contextLimit:1000});await host.api('/model-center/select',{type:'pool',id:poolId});await host.api('/sessions/'+f.session.id+'/resume',{});await until(async()=>(await get()).execution.run.budgetPause,15000);
await page.reload();await expect(page.getByLabel('任务预算诊断')).toContainText('图像本地预留');await page.getByRole('button',{name:'核对预算并续接原任务',exact:true}).click();
await dialog.getByLabel('上下文窗口',{exact:true}).fill('64000');await dialog.getByLabel('新Run工具轮次',{exact:true}).fill('3');await dialog.getByRole('button',{name:'准备续接预览',exact:true}).click();await expect(dialog.locator('.budget-preview')).toContainText('保留 1 项完成工具、1 张附件');assert.equal(requests.length,count);await shot(page,'desktop-budget-preview');
await page.setViewportSize({width:390,height:844});await shot(page,'narrow-budget-preview');await dialog.getByRole('button',{name:'确认预算并续接',exact:true}).click();await until(async()=>(await get()).status==='completed',15000);
session=await get();assert.equal(session.execution.task.id,taskId);assert.equal(session.execution.progress.completedTools,1);assert.equal(requests.length,count+1);assert.equal((await host.api('/bootstrap')).config.contextLimit,1000);await page.setViewportSize({width:1440,height:1000});mark('explicit budget preview and confirmation retain Task, attachment and completed tool while global capacity stays unchanged');
const initial=await host.api('/companion'),reservation=http.createServer();assert.ok(initial.addresses.length);await new Promise(resolve=>reservation.listen(0,initial.addresses[0].address,resolve));const port=reservation.address().port;await new Promise(resolve=>reservation.close(resolve));
await host.api('/companion/start',{address:initial.addresses[0].address,port});gateway=await host.api('/companion');const certificate=await fetch(host.url+'/api/companion/certificate',{headers:{'X-Workbench-Token':host.bootstrap.token}}),ca=new X509Certificate(Buffer.from(await certificate.arrayBuffer())).toString(),target=new URL(gateway.origin);
const ticket=await host.api('/companion/pair',{projectIds:[f.project.id],permissions:{observe:true,approve:false,stop:false},expiresInHours:1});
relay=http.createServer((request,response)=>{const forwarded=https.request(new URL(request.url,target),{method:request.method,ca,servername:'',headers:{Host:target.host,Origin:target.origin,Connection:'close',...(cookie?{Cookie:cookie}:{}),...(request.headers['content-type']?{'Content-Type':request.headers['content-type']}:{})}},incoming=>{if(incoming.headers['set-cookie']?.length)cookie=incoming.headers['set-cookie'][0].split(';')[0];const headers={...incoming.headers};delete headers['set-cookie'];response.writeHead(incoming.statusCode,headers);incoming.pipe(response);});forwarded.on('error',()=>response.destroy());request.pipe(forwarded);});await new Promise(resolve=>relay.listen(0,'127.0.0.1',resolve));
mobile=await browser.newPage({viewport:{width:390,height:844},isMobile:true,hasTouch:true});mobile.on('pageerror',error=>errors.push(error.message));await mobile.goto('http://127.0.0.1:'+relay.address().port+'/#pair='+new URLSearchParams(new URL(ticket.url).hash.slice(1)).get('pair'));await mobile.getByRole('button',{name:'连接这台电脑',exact:true}).click();await mobile.locator('.mobile-task-row').first().click();
await expect(mobile.locator('.mobile-input-image')).toContainText('SHA-256 已核对');await mobile.locator('.mobile-input-image summary').click();await shot(mobile,'companion-image');await mobile.reload();await expect(mobile.locator('.mobile-task-row').first()).toBeVisible();await mobile.locator('.mobile-task-row').first().click();await expect(mobile.locator('.mobile-input-image')).toContainText('SHA-256 已核对');
const device=(await host.api('/companion')).devices.find(row=>row.status==='active');await host.api('/companion/devices/'+device.id+'/revoke',{revision:device.revision});await mobile.getByRole('button',{name:'刷新任务',exact:true}).click();await expect(mobile.locator('.mobile-input-image')).toHaveCount(0);await expect(mobile.getByRole('button',{name:'连接这台电脑',exact:true})).toBeVisible();mark('paired TLS companion verifies same screenshot, refresh restores it and revoke clears project/image content');
await host.api('/companion/close',{});gateway=null;
await host.api('/config',{...(await host.api('/bootstrap')).config,contextLimit:16000,maxSteps:3});
const connection=(await host.api('/model-center')).connections.find(row=>row.id===visionId);await host.api('/model-center/connections',{...connection,streaming:true,capabilityDeclarations:{...connection.capabilityDeclarations,streaming:'supported'}});await host.api('/model-center/select',{type:'connection',id:visionId});mode='hold';
await page.reload();await page.getByLabel('选择工程截图',{exact:true}).setInputFiles(imageFile);await expect(page.locator('.input-draft')).toContainText('SHA-256 已核对');await page.getByLabel('任务内容',{exact:true}).fill('截图流式停止验收');await page.getByRole('button',{name:'发送任务',exact:true}).click();await expect(page.getByLabel('模型输出片段',{exact:true}).last()).toContainText('截图正在核对');const stopping=await get();await page.getByRole('button',{name:'停止',exact:true}).click();await until(async()=>(await get()).status==='paused'&&closed===1,15000);session=await get();assert.equal(session.events.filter(row=>row.kind==='tool'&&row.runId===stopping.runId).length,0);await shot(page,'desktop-image-stopped');mark('stopping screenshot SSE closes original HTTP and dispatches zero partial tools');
assert.deepEqual(errors,[]);fs.writeFileSync(path.join(directory,'result.json'),JSON.stringify({success:true,version:host.bootstrap.version,appRoot,passed,screenshots,requests:requests.map(value=>({route:value.route,sha256:sha(JSON.stringify(value.body)),imageCount:requestImages(value.body).length})),pageErrors:errors},null,2));
}catch(error){await shot(page,'failure-desktop').catch(()=>{});if(mobile)await shot(mobile,'failure-mobile').catch(()=>{});fs.writeFileSync(path.join(directory,'result.json'),JSON.stringify({success:false,error:error.stack,passed,screenshots,pageErrors:errors},null,2));throw error;
}finally{console.log('EVIDENCE '+directory);await browser.close();if(relay)await new Promise(resolve=>{relay.closeAllConnections();relay.close(resolve);});if(gateway)await host.api('/companion/close',{});for(const response of held)response.destroy();for(const socket of sockets)socket.destroy();await new Promise(resolve=>model.close(resolve));for(const dispose of disposers.reverse())await dispose();}
+8 -4
View File
@@ -17,6 +17,8 @@ import { WorkerPanel } from './WorkerPanel';
import { DesktopPanel } from './DesktopPanel';
import { CompanionPanel } from './CompanionPanel';
import { desktop } from './desktop';
import { AttachmentComposer,InputImage } from './InputAttachments';
import { BudgetPausePanel } from './BudgetPausePanel';
const activeStates = ['running', 'awaiting_approval', 'stopping'];
const activeMcpStates = ['queued', 'connecting', 'discovering', 'calling', 'closing', 'stopping'];
@@ -53,6 +55,7 @@ export default function App() {
const [draft, setDraft] = useState('');
const [composer, setComposer] = useState('');
const [sending, setSending] = useState(false);
const [imageSelection,setImageSelection]=useState<{sessionId:string;ids:string[]}>({sessionId:'',ids:[]});
const [creatingSession, setCreatingSession] = useState(false);
const [tab, setTab] = useState<'file' | 'changes' | 'trace' | 'task' | 'index'>('file');
const [changeId, setChangeId] = useState('');
@@ -249,9 +252,9 @@ export default function App() {
try {
const target = session || await newSession();
if (!target) return;
acceptSession(await api<Session>('/sessions/' + target.id + '/messages', { content }));
acceptSession(await api<Session>('/sessions/' + target.id + '/messages', { content,attachmentIds:imageSelection.sessionId===target.id?imageSelection.ids:[] }));
if (selectedSessionRef.current === target.id) {
setComposer(previous => previous.trim() === content ? '' : previous); composerRef.current?.focus();
setComposer(previous => previous.trim() === content ? '' : previous); setImageSelection({sessionId:target.id,ids:[]}); composerRef.current?.focus();
}
} catch (error) { failure(error); }
finally { setSending(false); }
@@ -557,9 +560,10 @@ export default function App() {
{session?.recoveryNotice && <div className="recovery-note"><ShieldCheck size={16} /><div><strong>已恢复会话记录</strong><p>{session.recoveryNotice}</p></div></div>}
{entries.map(entry => 'message' in entry && entry.message ? <div key={entry.id} className={'message message-' + entry.message.role}><span className="message-avatar">{entry.message.role === 'user' ? '你' : entry.message.role === 'assistant' ? 'AW' : '·'}</span><div className="message-body"><div className="message-label">{entry.message.role === 'user' ? '你的任务' : entry.message.role === 'assistant' ? session?.executionMode === 'demo' ? '演示执行器' : '编程助手' : '工作台'}<time>{new Date(entry.date).toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })}</time></div><div className="message-text">{entry.message.role === 'system' && failureForMessage(entry.message)
? <FailureCard failure={failureForMessage(entry.message)!} onDiagnose={() => openDiagnostics()} onRetry={session?.status === 'failed' && session?.failure?.messageId === entry.message.id ? () => resumeSession() : undefined} busy={resuming || isRunning} />
: entry.message.role === 'assistant' ? <ResearchContent content={entry.message.content} /> : entry.message.content}</div></div></div> : 'event' in entry && entry.event ? <div key={entry.id} className="inline-event">{['tool', 'model'].includes(entry.event.kind) ? <><ToolRow event={entry.event} onSelect={() => { setEventId(entry.event!.id); showInspector('trace'); }} /><ModelStreamPreview event={entry.event} /></> : <div className={'system-event event-' + entry.event.phase}><span />{entry.event.label}{entry.event.output && <p>{entry.event.output}</p>}</div>}</div> : null)}
: entry.message.role === 'assistant' ? <ResearchContent content={entry.message.content} /> : entry.message.content}</div>{entry.message.attachmentIds?.map(id=>{const image=session?.inputAttachments?.find(value=>value.id===id);return image&&session?<InputImage key={id} sessionId={session.id} image={image} onError={failure}/>:null;})}</div></div> : 'event' in entry && entry.event ? <div key={entry.id} className="inline-event">{['tool', 'model'].includes(entry.event.kind) ? <><ToolRow event={entry.event} onSelect={() => { setEventId(entry.event!.id); showInspector('trace'); }} /><ModelStreamPreview event={entry.event} /></> : <div className={'system-event event-' + entry.event.phase}><span />{entry.event.label}{entry.event.output && <p>{entry.event.output}</p>}</div>}</div> : null)}
{isRunning && !approval && <div className="working-note"><LoaderCircle size={14} className="spin" /><span>{session?.executionMode === 'demo' ? '正在执行演示流程' : '正在处理任务'}</span></div>}
</div>}
{session&&<BudgetPausePanel key={session.id+session.execution?.run?.id} session={session} config={config} onSession={acceptSession}/>}
{approval && <div className="approval-card"><div className="approval-heading"><span><ShieldCheck size={17} /></span><div><strong>{approval.browserPlanId ? '确认实际页面检查' : approval.checkPlanId ? '确认工程检查' : '确认这次终端执行'}</strong><p>{approval.reason}</p></div></div><pre>{approval.command}</pre>
{approval.checkScripts?.filter(check => check.python).map(check => <p className="approval-shell" key={check.name}>Python {check.python!.runtime.version || '执行时核对版本'} · {check.python!.runtime.logicalExecutable || check.python!.runtime.executable || '解释器缺失'}</p>)}
<div className="approval-path"><Folder size={12} /><span>{approval.cwd}</span></div><p className="approval-shell">{approval.shell || '项目终端'} · UTF-8</p><p className="approval-scope">{approval.browserPlanId ? '按封存步骤操作当前构建,保存页面原结果。' : '确认后以你的系统权限执行。'}</p><div className="approval-actions"><button className="button secondary" onClick={() => decide(false)} disabled={deciding}>拒绝执行</button><button className="button primary" onClick={() => decide(true)} disabled={deciding}><Play size={14} />确认执行</button></div></div>}
@@ -567,7 +571,7 @@ export default function App() {
{canContinueReview && <button type="button" aria-label="继续检查与交付" className="review-callout" disabled={resuming} onClick={continueReviewed}><ClipboardCheck size={17} /><span><strong>继续检查与交付</strong><small>改动已应用,沿用原任务继续实际测试和修复。</small></span><ArrowRight size={17} /></button>}
<div ref={chatEnd} />
</section>
<footer className="composer-wrap"><form className="composer" onSubmit={event => { event.preventDefault(); submit(); }}><textarea ref={composerRef} aria-label="任务内容" placeholder={config.mode === 'demo' ? '先体验完整流程,或连接自己的模型开始开发…' : '描述项目任务,或询问工作台的执行状态与报错…'} value={composer} onChange={event => setComposer(event.target.value)} onKeyDown={event => { if ((event.ctrlKey || event.metaKey) && event.key === 'Enter') { event.preventDefault(); submit(); } }} maxLength={20000} rows={3} /><div className="composer-bottom"><span><Folder size={13} />{selectedProject?.name || '选择项目'}<span className="composer-divider" />{config.mode === 'demo' ? '固定演示脚本' : modelSelection.type !== 'legacy' ? modelSelection.name : '兼容模型服务'}</span>{isRunning ? <button type="button" className="stop-button" onClick={() => session && api('/sessions/' + session.id + '/stop', {}).catch(failure)}><Square size={13} />停止</button> : <button type="submit" className="send-button" aria-label="发送任务" disabled={!composer.trim() || sending || creatingSession || !ready || !!(sessionId && !session)}>{sending ? <LoaderCircle size={17} className="spin" /> : <ArrowUp size={18} />}</button>}</div></form><div className="composer-footnote"><span>Ctrl + Enter 发送 · 会话自动保存</span><span>{session?.estimatedTokens ? '上下文估算 ' + session.estimatedTokens.toLocaleString() + ' tokens' : '改动与执行结果可追溯'}</span></div></footer>
<footer className="composer-wrap"><form className="composer" onSubmit={event => { event.preventDefault(); submit(); }}><AttachmentComposer session={session} selectedIds={imageSelection.sessionId===session?.id?imageSelection.ids:[]} onSelection={(id,ids)=>setImageSelection({sessionId:id,ids})} onEnsureSession={newSession} onSession={acceptSession} onError={failure} disabled={isRunning||sending||creatingSession||!ready||restrictedWorker} routeName={modelSelection.type==='legacy'?'原模型连接':modelSelection.name} onModels={()=>setModelCenterOpen(true)}/><textarea ref={composerRef} aria-label="任务内容" placeholder={config.mode === 'demo' ? '先体验完整流程,或连接自己的模型开始开发…' : '描述项目任务,或询问工作台的执行状态与报错…'} value={composer} onChange={event => setComposer(event.target.value)} onKeyDown={event => { if ((event.ctrlKey || event.metaKey) && event.key === 'Enter') { event.preventDefault(); submit(); } }} maxLength={20000} rows={3} /><div className="composer-bottom"><span><Folder size={13} />{selectedProject?.name || '选择项目'}<span className="composer-divider" />{config.mode === 'demo' ? '固定演示脚本' : modelSelection.type !== 'legacy' ? modelSelection.name : '兼容模型服务'}</span>{isRunning ? <button type="button" className="stop-button" onClick={() => session && api('/sessions/' + session.id + '/stop', {}).catch(failure)}><Square size={13} />停止</button> : <button type="submit" className="send-button" aria-label="发送任务" disabled={!composer.trim() || sending || creatingSession || !ready || !!(sessionId && !session)}>{sending ? <LoaderCircle size={17} className="spin" /> : <ArrowUp size={18} />}</button>}</div></form><div className="composer-footnote"><span>Ctrl + Enter 发送 · 会话自动保存</span><span>{session?.estimatedTokens ? '上下文估算 ' + session.estimatedTokens.toLocaleString() + ' tokens' : '改动与执行结果可追溯'}</span></div></footer>
</main>
{((mobile && sidebarOpen) || (narrow && wide)) && <button type="button" className="panel-scrim" aria-label="关闭侧边面板" onClick={() => { setSidebarOpen(false); setWide(false); }} />}
<aside className="inspector">
+27
View File
@@ -0,0 +1,27 @@
import { useState } from 'react';
import { RotateCw } from 'lucide-react';
import { api } from './api';
import { Modal } from './components';
import type { Config,Session } from './types';
import './input-attachments.css';
type Fields={contextLimit:number;maxOutputTokens:number;maxRunTokens:number;maxTaskTokens:number;maxSteps:number;maxRunDurationMs:number};
type Preview={id:string;sha256:string;taskId:string;runId:string;config:Fields&{model:string};eligibleConnections:{id:string;name:string;model:string}[];budget:{inputBudget:number;contextLimit:number};completedToolIds:string[];unknownToolIds:string[];attachmentIds:string[];note:string};
const reasons:Record<string,string>={context_limit:'上下文窗口不足',token_limit:'本次运行预算不足',task_token_limit:'任务累计预算不足',time_limit:'本次运行时间已用完'};
const labels:Record<string,string>={transportAndImageFramingTokens:'请求格式与图片说明',goalAndContextTextTokens:'目标、全部要求及工程上下文',toolDefinitionTokens:'工具定义',historyAndEvidenceTokens:'必需历史及实际依据',imageReservationTokens:'图像本地预留'};
export function BudgetPausePanel({session,config,onSession}:{session:Session;config:Config;onSession:(value:Session)=>void}){
const [open,setOpen]=useState(false),[busy,setBusy]=useState(false),[error,setError]=useState(''),[plan,setPlan]=useState<Preview|null>(null);
const [fields,setFields]=useState<Fields>({contextLimit:session.execution?.run?.model.contextLimit??config.contextLimit,maxOutputTokens:session.execution?.run?.model.maxOutputTokens??config.maxOutputTokens,
maxRunTokens:config.maxRunTokens,maxTaskTokens:session.execution?.task?.budget.maxTokens??config.maxTaskTokens,maxSteps:config.maxSteps,maxRunDurationMs:config.maxRunDurationMs});
const [selection,setSelection]=useState(''),[options,setOptions]=useState<{value:string;name:string}[]>([]);
const run=session.execution?.run,pause=run?.budgetPause,reason=pause?.reason??run?.stopReason??'';
if(!['paused','failed'].includes(session.status)||!reasons[reason])return null;
async function start(){setOpen(true);setError('');setPlan(null);try{const center=await api<{selected:{type:string;id:string};connections:{id:string;name:string;contextLimit:number}[];pools:{id:string;name:string}[]}>('/model-center');setSelection(center.selected.type+':'+center.selected.id);setOptions([...center.connections.map(row=>({value:(row.id==='legacy-default'?'legacy':'connection')+':'+row.id,name:row.name+' · '+row.contextLimit.toLocaleString()+' 上下文'})),...center.pools.map(row=>({value:'pool:'+row.id,name:row.name+' · 按成员最小容量'}))]);}catch(cause){setError((cause as Error).message);}}
async function preview(){setBusy(true);setError('');setPlan(null);try{const [type,id]=selection.split(':');const value=await api<Preview>('/sessions/'+session.id+'/resume-preview',{...fields,...(selection?{selection:{type,id}}:{})});setPlan(value);onSession(await api<Session>('/sessions/'+session.id));}catch(cause){setError((cause as Error).message);}finally{setBusy(false);}}
async function confirm(){if(!plan)return;setBusy(true);setError('');try{onSession(await api<Session>('/sessions/'+session.id+'/resume-budget',{planId:plan.id,sha256:plan.sha256}));setOpen(false);}catch(cause){setError((cause as Error).message);}finally{setBusy(false);}}
return <aside className="budget-pause" aria-label="任务预算诊断"><h3>{reasons[reason]}</h3>{pause?.requiredInputTokens!==undefined?<><p>完整要求与必需输入估算 <strong>{pause.requiredInputTokens.toLocaleString()}</strong> tokens;当前可用输入 <strong>{pause.inputBudget?.toLocaleString()}</strong>。请求已暂停,原任务和工具结果保留。</p><dl className="budget-facts">{Object.entries(pause.breakdown??{}).map(([key,value])=><div key={key} style={{display:'contents'}}><dt>{labels[key]??key}</dt><dd>{value.toLocaleString()}</dd></div>)}<dt>所选上下文窗口</dt><dd>{pause.contextLimit?.toLocaleString()}</dd><dt>响应预留 / 安全余量</dt><dd>{pause.outputReservation?.toLocaleString()} / {pause.safetyTokens?.toLocaleString()}</dd><dt>运行 / 任务剩余</dt><dd>{pause.runRemainingTokens?.toLocaleString()??'不限'} / {pause.taskRemainingTokens?.toLocaleString()??'不限'}</dd></dl></>:<p>原 Task 已保存。可核对剩余预算和模型容量,再准备同一任务的新 Run;旧记录没有的预算分解不补造。</p>}
{!!pause?.imageReservationTokens&&<p>图像使用单独的本地预留,属于容量估算;实际计费与服务报告用量分列。</p>}<button type="button" className="button secondary" onClick={()=>void start()}><RotateCw size={14}/>核对预算并续接原任务</button>
{open&&<Modal title="续接原任务" description="先核对新Run的容量与预算,再确认执行。" onClose={()=>{if(!busy)setOpen(false);}} wide><p className="input-sha">Task {session.execution?.task?.id}<br/>原 Run {run?.id}</p><div className="budget-resume-fields"><label>本次模型连接或池<select aria-label="续接模型连接" value={selection} disabled={busy} onChange={event=>{setSelection(event.target.value);setPlan(null);}}>{options.map(row=><option key={row.value} value={row.value}>{row.name}</option>)}</select></label>{([['contextLimit','上下文窗口',1000,200000],['maxOutputTokens','响应预留',256,16000],['maxRunTokens','新Run累计tokens',1000,2000000],['maxTaskTokens','原任务累计tokens',1000,10000000],['maxSteps','新Run工具轮次',1,30],['maxRunDurationMs','新Run时间(分钟)',1,60]] as const).map(([key,label,min,max])=><label key={key}>{label}<input aria-label={label} type="number" min={min} max={max} value={key==='maxRunDurationMs'?fields[key]/60000:fields[key]} disabled={busy} onChange={event=>{setFields({...fields,[key]:Number(event.target.value)*(key==='maxRunDurationMs'?60000:1)});setPlan(null);}}/></label>)}</div><p>容量须符合服务实际限制;池按成员最小容量核对。新增预算只用于这次明确续接,不修改全局设置。</p>{error&&<p className="budget-error" role="alert">{error}</p>}<div className="modal-actions"><button type="button" className="button secondary" disabled={busy||!selection} onClick={()=>void preview()}>准备续接预览</button></div>{plan&&<div className="budget-preview" role="status"><strong>将创建原Task的新Run</strong><p>可用模型 {plan.eligibleConnections.length?plan.eligibleConnections.map(row=>row.name+' / '+row.model).join('、'):plan.config.model} · 上下文 {plan.budget.contextLimit.toLocaleString()} · 可用输入 {plan.budget.inputBudget.toLocaleString()} tokens</p><p>保留 {plan.completedToolIds.length} 项完成工具、{plan.attachmentIds.length} 张附件;{plan.unknownToolIds.length} 项未知结果仍须核对。</p><p>{plan.note}</p><p className="input-sha">预览 SHA-256 {plan.sha256}</p><div className="modal-actions"><button type="button" className="button primary" disabled={busy} onClick={()=>void confirm()}>确认预算并续接</button></div></div>}</Modal>}
</aside>;
}
+35
View File
@@ -0,0 +1,35 @@
import { useEffect,useRef,useState } from 'react';
import { ImagePlus,Download,X,LoaderCircle } from 'lucide-react';
import { api,downloadBlob,inputImageBlob } from './api';
import { Modal } from './components';
import type { InputAttachment,Session } from './types';
import './input-attachments.css';
export function InputImage({sessionId,image,onError}:{sessionId:string;image:InputAttachment;onError:(error:unknown)=>void}){
const [url,setUrl]=useState(''),[open,setOpen]=useState(false),[error,setError]=useState('');
useEffect(()=>{let alive=true,objectUrl='';setUrl('');setError('');void inputImageBlob(sessionId,image).then(blob=>{if(alive){objectUrl=URL.createObjectURL(blob);setUrl(objectUrl);}}).catch(cause=>{if(alive)setError(cause.message);});return()=>{alive=false;if(objectUrl)URL.revokeObjectURL(objectUrl);};},[sessionId,image.id,image.sentSha256]);
return <div className="input-receipt"><button type="button" className="input-thumbnail" aria-label={'查看截图 '+image.name} disabled={!url} onClick={()=>setOpen(true)}>{url?<img src={url} alt={image.name} width={72} height={48}/>:<span>{error?'读取失败':'核对中'}</span>}</button><div><strong>{image.name}</strong><span>发送副本 {image.sentWidth} × {image.sentHeight} · {Math.ceil(image.sentBytes/1024)} KB</span><small>{error|| (url?'SHA-256 已核对':'核对原字节…')}</small></div>
{open&&<Modal title="任务截图" description={image.name+' · 原图 '+image.width+' × '+image.height} onClose={()=>setOpen(false)} wide><img className="input-preview" src={url} alt={image.name}/><p className="input-sha">原图 SHA-256 {image.sha256}<br/>发送副本 SHA-256 {image.sentSha256}</p><p>发送副本已去除元数据并归正方向,最长边不超过1024像素、768KB。细小文字请先裁剪;原图完整保留。</p><div className="modal-actions"><button className="button secondary" type="button" onClick={()=>void inputImageBlob(sessionId,image,true).then(blob=>downloadBlob(blob,image.name)).catch(onError)}><Download size={14}/>下载原图</button><button className="button secondary" type="button" onClick={()=>void inputImageBlob(sessionId,image).then(blob=>downloadBlob(blob,'sent-'+image.id+'.png')).catch(onError)}>下载发送副本</button></div></Modal>}
</div>;
}
export function AttachmentComposer({session,selectedIds,onSelection,onEnsureSession,onSession,onError,disabled,routeName,onModels}:{session:Session|null;selectedIds:string[];onSelection:(id:string,ids:string[])=>void;onEnsureSession:()=>Promise<Session|null>;onSession:(value:Session)=>void;onError:(error:unknown)=>void;disabled:boolean;routeName:string;onModels:()=>void}){
const input=useRef<HTMLInputElement>(null),[busy,setBusy]=useState(false);
const drafts=session?.inputAttachments?.filter(value=>value.status==='draft')??[];
async function upload(file:File){
setBusy(true);
try{
if(file.size>2*1024*1024)throw new Error('单张截图最多2MB,请裁剪后添加。');
if(!['image/png','image/jpeg'].includes(file.type))throw new Error('请选择静态PNG或JPEG截图。');
const target=session??await onEnsureSession();if(!target)return;
const bytes=new Uint8Array(await file.arrayBuffer());let binary='';for(let p=0;p<bytes.length;p+=8192)binary+=String.fromCharCode(...bytes.subarray(p,p+8192));
const row=await api<InputAttachment>('/sessions/'+target.id+'/input-attachments',{name:file.name,mediaType:file.type,base64:btoa(binary)});
onSession(await api<Session>('/sessions/'+target.id));onSelection(target.id,[row.id]);
}catch(error){onError(error);}finally{setBusy(false);if(input.current)input.current.value='';}
}
async function remove(id:string){if(!session)return;setBusy(true);try{await api('/sessions/'+session.id+'/input-attachments/'+id,{},'DELETE');onSession(await api<Session>('/sessions/'+session.id));if(selectedIds.includes(id))onSelection(session.id,[]);}catch(error){onError(error);}finally{setBusy(false);}}
return <div className="input-composer"><div className="input-composer-tools"><button type="button" className="input-add" disabled={disabled||busy} onClick={()=>input.current?.click()}>{busy?<LoaderCircle size={15} className="spin"/>:<ImagePlus size={15}/>}添加截图</button><span>每任务1张 · PNG/JPEG · 原图≤2MB</span><input ref={input} type="file" accept="image/png,image/jpeg" aria-label="选择工程截图" hidden onChange={event=>{const file=event.target.files?.[0];if(file)void upload(file);}}/></div>
{!!drafts.length&&<div className="input-drafts">{drafts.map(image=><div className={'input-draft '+(selectedIds.includes(image.id)?'selected':'')} key={image.id}><label><input type="checkbox" checked={selectedIds.includes(image.id)} disabled={disabled||busy} onChange={event=>onSelection(session!.id,event.target.checked?[image.id]:[])}/><span>随任务发送</span></label><InputImage sessionId={session!.id} image={image} onError={onError}/><button type="button" className="input-remove" aria-label={'移除截图 '+image.name} disabled={disabled||busy} onClick={()=>void remove(image.id)}><X size={15}/></button></div>)}</div>}
{!!selectedIds.length&&<p className="input-route">将随文字发送至 <strong>{routeName}</strong>,池仅使用声明或检测支持视觉的成员。<button type="button" onClick={onModels}>核对模型能力</button><span>发送副本≤1024像素/768KB;图片预留单独估算,实际用量以服务返回为准。</span></p>}
</div>;
}
+2 -1
View File
@@ -77,7 +77,7 @@ export function ModelCenter({ onConfig, onLegacy, busy }: { onConfig: (value: Co
<footer><button className="button secondary" disabled={locked || !value.enabled} onClick={() => void act(async () => { const result = await api<{ config: Config }>('/model-center/select', { type: value.id === 'legacy-default' ? 'legacy' : 'connection', id: value.id }); onConfig(result.config, { type: value.id === 'legacy-default' ? 'legacy' : 'connection', id: value.id, name: value.name }); })}>{selected?.id === value.id ? <Check size={14} /> : <Route size={14} />}{selected?.id === value.id ? '当前使用' : '用于新任务'}</button>
<button className="button secondary" disabled={locked} onClick={() => { if (value.id === 'legacy-default') { onLegacy(); return; } setDraft({ ...initial, ...value, streaming: value.streaming === true, capabilityDeclarations: { ...initial.capabilityDeclarations, ...value.capabilityDeclarations } }); setKey(''); setPersistKey(false); setEditing(true); }}>编辑</button>
{value.id !== 'legacy-default' && <button className="mc-icon-action" aria-label={(value.enabled ? '停用' : '启用') + value.name} disabled={working} onClick={() => void act(async () => { await api('/model-center/toggle', { id: value.id, enabled: !value.enabled }); })}><Power size={15} />{value.enabled ? '停用' : '启用'}</button>}
<label className="mc-probe-scope">检测范围<select aria-label={value.name + '检测范围'} value={probeScopes[value.id] ?? 'text'} disabled={locked} onChange={event => setProbeScopes({ ...probeScopes, [value.id]: event.target.value })}><option value="text">文本响应</option><option value="tools">工具调用</option><option value="streaming">流式文本</option></select></label>
<label className="mc-probe-scope">检测范围<select aria-label={value.name + '检测范围'} value={probeScopes[value.id] ?? 'text'} disabled={locked} onChange={event => setProbeScopes({ ...probeScopes, [value.id]: event.target.value })}><option value="text">文本响应</option><option value="tools">工具调用</option><option value="streaming">流式文本</option><option value="vision">合成图像识别</option></select></label>
<button className="mc-probe" disabled={locked || !value.enabled} onClick={() => void act(async () => { const result = await api<{ scope: string }>('/model-center/probe', { id: value.id, scope: probeScopes[value.id] ?? 'text' }); if (alive.current) setNotice(capabilityLabels[result.scope] + '检测通过;只验证所选能力,原请求与用量已记入账本。'); })}>验证响应(调用模型)</button></footer>
</article>)}</div>
{editing && <form className="mc-editor" aria-label="编辑模型连接" onSubmit={event => { event.preventDefault(); void act(async () => { await api('/model-center/connections', { ...draft, ...(key ? { apiKey: key } : {}), ...(persistKey ? { persistKey: true } : {}) }); if (alive.current) { setKey(''); setEditing(false); setNotice(persistKey ? '连接与本机加密凭据已一起保存。' : '连接已保存。'); } }); }}>
@@ -87,6 +87,7 @@ export function ModelCenter({ onConfig, onLegacy, busy }: { onConfig: (value: Co
<label>接口协议<select aria-label="接口协议" value={draft.protocol} onChange={event => setDraft({ ...draft, protocol: event.target.value })}><option value="chat-completions">Chat Completions</option><option value="responses">OpenAI Responses</option></select></label>
<label>工具调用能力<select aria-label="工具调用能力" value={draft.capabilityDeclarations.tools} onChange={event => setDraft({ ...draft, capabilityDeclarations: { ...draft.capabilityDeclarations, tools: event.target.value } })}><option value="supported">服务声明支持</option><option value="unknown">尚未确定</option><option value="unsupported">明确不支持</option></select></label>
<label>流式能力<select aria-label="流式能力" value={draft.capabilityDeclarations.streaming} onChange={event => setDraft({ ...draft, streaming: event.target.value === 'supported' && draft.streaming, capabilityDeclarations: { ...draft.capabilityDeclarations, streaming: event.target.value } })}><option value="unknown">尚未确定</option><option value="supported">服务声明支持</option><option value="unsupported">明确不支持</option></select></label>
<label>视觉能力<select aria-label="视觉能力" value={draft.capabilityDeclarations.vision} onChange={event=>setDraft({...draft,capabilityDeclarations:{...draft.capabilityDeclarations,vision:event.target.value}})}><option value="unknown">尚未确定</option><option value="supported">服务声明支持</option><option value="unsupported">明确不支持</option></select></label>
<label className="mc-checkbox"><input type="checkbox" checked={draft.streaming} disabled={draft.capabilityDeclarations.streaming !== 'supported'} onChange={event => setDraft({ ...draft, streaming: event.target.checked })} />使用流式输出</label>
<label className="mc-full">接口根地址<input type="url" required value={draft.baseUrl} onChange={event => setDraft({ ...draft, baseUrl: event.target.value })} /></label>
<label>实际模型名称<input required value={draft.model} onChange={event => setDraft({ ...draft, model: event.target.value })} /></label>
+10 -2
View File
@@ -1,8 +1,8 @@
let accessToken = '';
export function setToken(token: string) { accessToken = token; }
export async function api<T>(path: string, input?: unknown): Promise<T> {
export async function api<T>(path: string, input?: unknown,method?:string): Promise<T> {
const response = await fetch('/api' + path, {
method: input === undefined ? 'GET' : 'POST',
method: method??(input === undefined ? 'GET' : 'POST'),
headers: { 'Content-Type': 'application/json', ...(accessToken ? { 'X-Workbench-Token': accessToken } : {}) },
...(input === undefined ? {} : { body: JSON.stringify(input) }),
});
@@ -56,3 +56,11 @@ export async function browserImageBlob(sessionId: string, jobId: string, artifac
if (!response.ok) { const value = await response.json().catch(() => ({})); throw new Error(value.error || '页面截图读取失败。'); }
return response.blob();
}
export async function inputImageBlob(sessionId:string,image:import('./types').InputAttachment,original=false):Promise<Blob>{
const response=await fetch('/api/sessions/'+sessionId+'/input-attachments/'+image.id+'/'+(original?'original':'image'),{headers:{'X-Workbench-Token':accessToken},cache:'no-store'});
if(!response.ok){const value=await response.json().catch(()=>({}));throw new Error(value.error||'截图读取失败,请刷新核对。');}
const bytes=await response.arrayBuffer(),digest=Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256',bytes)),value=>value.toString(16).padStart(2,'0')).join('');
if(digest!==(original?image.sha256:image.sentSha256))throw new Error('截图SHA-256核对失败,未展示或下载。');
return new Blob([bytes],{type:original?image.mediaType:'image/png'});
}
+2
View File
@@ -9,6 +9,8 @@ export interface CompanionStatus {
export interface MobileBrief { id: string; projectId: string; taskId?: string; runId?: string; title: string; status: string; revision: number; eventSeq: number; updatedAt: string }
export interface MobileUsage { totalTokens: number; unknownRequests: number; estimatedUnknownTokens: number }
export interface MobileTask extends MobileBrief {
inputAttachments?: import('./types').InputAttachment[];
budgetPause?: import('./types').BudgetPause|null;
task: { id: string; goal: string; status: string; usage: MobileUsage; budget: { maxTokens: number }; verification: { status: string } } | null;
run: { id: string; status: string; steps: number; toolCalls: number; stopReason: string | null; usage: MobileUsage } | null;
progress: { total: number; completed: number; unknown: { id: string; tool: string; state: string; runId: string }[] };
+3
View File
@@ -0,0 +1,3 @@
.input-composer{border-bottom:1px solid var(--line,#dce7e2);padding:8px 12px}.input-composer-tools{display:flex;align-items:center;gap:10px;flex-wrap:wrap}.input-composer-tools>span{font-size:11px;color:var(--muted,#52665f)}.input-add,.input-remove,.input-route button{display:inline-flex;align-items:center;gap:6px;border:0;background:transparent;color:inherit;padding:6px;cursor:pointer}.input-add:hover,.input-remove:hover{background:#edf3f1;border-radius:4px}.input-drafts{display:grid;gap:8px;margin-top:8px;max-height:220px;overflow:auto}.input-draft{display:flex;gap:10px;align-items:center;padding:8px;border:1px solid var(--line,#dce7e2);border-radius:5px;min-width:0}.input-draft.selected{border-color:var(--teal,#154b4a)}.input-draft>label{display:flex;gap:6px;font-size:11px;align-items:center;white-space:nowrap}.input-receipt{display:flex;gap:10px;align-items:center;min-width:0;margin:8px 0}.input-receipt>div{min-width:0;display:grid;gap:3px}.input-receipt strong{font-size:12px;overflow-wrap:anywhere}.input-receipt span,.input-receipt small{font-size:11px;color:var(--muted,#52665f)}.input-thumbnail{flex-shrink:0;border:1px solid var(--line,#dce7e2);background:transparent;cursor:pointer;padding:2px;width:78px;height:54px;border-radius:3px}.input-thumbnail img{object-fit:contain;display:block}.input-route{font-size:11px;line-height:1.7;margin:8px 0 2px;overflow-wrap:anywhere}.input-route button{color:var(--blue,#4664d9);text-decoration:underline}.input-route>span{display:block;color:var(--muted,#52665f)}.input-preview{display:block;max-width:100%;max-height:60vh;object-fit:contain;margin:auto}.input-sha{font-family:var(--font-mono,monospace);font-size:11px;overflow-wrap:anywhere;line-height:1.8}.input-remove{margin-left:auto}.budget-pause{margin:16px 24px;border-left:3px solid #cba760;padding:12px 16px;background:var(--paper,#fcfdfc);font-size:12px}.budget-pause h3{font-size:14px;margin:0 0 8px}.budget-pause p{line-height:1.7;overflow-wrap:anywhere}.budget-facts{display:grid;grid-template-columns:1fr auto;gap:6px 18px;margin:12px 0}.budget-facts dt{color:var(--muted,#52665f)}.budget-facts dd{margin:0;font-variant-numeric:tabular-nums}.budget-resume-fields{display:grid;grid-template-columns:1fr 1fr;gap:12px}.budget-resume-fields label{display:grid;gap:6px;font-size:12px}.budget-resume-fields input,.budget-resume-fields select{width:100%;min-width:0;padding:9px;border:1px solid var(--line,#dce7e2);border-radius:4px;background:var(--paper,#fcfdfc);color:inherit}.budget-preview{border-top:1px solid var(--line,#dce7e2);padding-top:12px;margin-top:16px}.budget-error{color:#87500b;line-height:1.7}
@media(max-width:620px){.input-draft{flex-wrap:wrap;gap:4px 10px}.input-draft>.input-receipt{width:calc(100% - 28px)}.input-draft>label{width:100%}.input-composer{padding:8px}.budget-pause{margin:12px}.budget-resume-fields{grid-template-columns:1fr}.budget-pause .button{width:100%;justify-content:center}}
@media(max-width:620px){.input-remove{min-width:44px;min-height:44px;justify-content:center}.input-draft>label{min-height:44px}.input-add{min-height:40px}}
+3
View File
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useState } from 'react';
import { ArrowLeft, ChevronRight, ClipboardCheck, FileDiff, Folder, Link2, RefreshCw, ShieldCheck, Square, Terminal, Wifi, WifiOff, X } from 'lucide-react';
import type { CompanionDevice, MobileBrief, MobileTask } from '../companion-types';
import { mobileApi, MobileError, verifiedText, verifyDigest } from './api';
import { MobileInputImage } from './MobileInputImage';
const stateLabel = (state: string) => ({ idle: '未开始', waiting: '等待审批', validating: '校验中', queued: '排队中', executing: '执行中', error: '错误', running: '执行中', awaiting_approval: '等待审批', stopping: '正在停止', completed: '已完成', needs_review: '待审查', failed: '失败', interrupted: '已中断', cancelled: '已停止', paused: '已暂停', unknown: '需核对', completed_with_changes: '待审查', passed: '通过', pending: '待处理', applied: '已应用', denied: '已拒绝', approved: '已批准', conflict: '有冲突', unverified: '需核对', stale: '已变化' } as Record<string, string>)[state] ?? state;
const time = (value: string) => new Date(value).toLocaleString('zh-CN', { month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' });
@@ -116,6 +117,8 @@ export function MobileApp({ initialToken }: { initialToken: string }) {
{me && selected && <main className="mobile-task-detail"><button className="mobile-back" onClick={() => { chosen.current = ''; setSelected(''); setTask(null); setDocument(null); }}><ArrowLeft size={18} />项目任务</button>{!selectedTask ? <div className="mobile-empty" role="status">正在读取原任务…</div> : <>
<div className="mobile-task-title"><span className="mobile-eyebrow">{projectName(selectedTask.projectId)}</span><h1>{selectedTask.title}</h1><div><span className={'mobile-state state-' + selectedTask.status}>{stateLabel(selectedTask.status)}</span><span>修订 {selectedTask.revision}</span></div><details className="mobile-goal"><summary>完整任务目标</summary><p>{selectedTask.task?.goal ?? '此会话尚未创建执行任务。'}</p></details><details><summary>原任务与运行</summary><code>Task {selectedTask.taskId ?? '未开始'}<br />Run {selectedTask.runId ?? '未开始'}</code></details></div>
{receipt && <p className="mobile-receipt" role="status">{receipt}</p>}
{selectedTask.inputAttachments?.map(image=><MobileInputImage key={image.id} sessionId={selectedTask.id} image={image} onError={cause=>{if(cause instanceof MobileError&&[401,403].includes(cause.status))revoke(cause.message);else setError(cause instanceof Error?cause.message:'截图读取失败。');}}/>)}
{selectedTask.budgetPause&&<aside className="mobile-unknown"><strong>原任务因预算暂停</strong><p>必需输入 {selectedTask.budgetPause.requiredInputTokens?.toLocaleString()??'旧记录未分解'};可用输入 {selectedTask.budgetPause.inputBudget?.toLocaleString()??'未记录'} tokens。请在电脑核对预算并预览续接,原工具结果保留。</p></aside>}
{!!selectedTask.progress.unknown.length && <div className="mobile-unknown"><strong>{selectedTask.progress.unknown.length} 项工具结果需要核对</strong><p>请在电脑核对原输入和实际结果。刷新、重连和手机审批均不会自动重新执行。</p>{selectedTask.progress.unknown.map(item => <code key={item.id}>{item.tool} · {stateLabel(item.state)}</code>)}</div>}
{!!selectedTask.approvals.length && <section className="mobile-approvals"><h2><ShieldCheck size={18} />等待你的确认</h2>{selectedTask.approvals.map(approval => <article key={approval.id}><span>{approval.shell}</span><pre>{approval.command}</pre><p>{approval.reason}</p>{!me.device.permissions.approve ? <p className="mobile-muted">此设备仅可观察,请在电脑审批。</p> : !approval.actionable ? <p className="mobile-muted">原审批已失效,请在电脑核对。</p> : <div className="mobile-action-pair"><button disabled={!fresh || !!busy} onClick={() => setDecision({ requestId: crypto.randomUUID(), kind: 'approve', task: selectedTask, approval, allow: false })}>拒绝</button><button className="mobile-primary" disabled={!fresh || !!busy} onClick={() => setDecision({ requestId: crypto.randomUUID(), kind: 'approve', task: selectedTask, approval, allow: true })}>核对并批准</button></div>}</article>)}</section>}
<nav className="mobile-tabs" aria-label="任务内容">{[['progress', '执行进展'], ['changes', '文件差异'], ['checks', '检查与报告']].map(([key, label]) => <button key={key} aria-current={tab === key ? 'page' : undefined} onClick={() => { setTab(key); setDocument(null); }}>{label}{key === 'changes' && !!selectedTask.changes.length && <span>{selectedTask.changes.length}</span>}</button>)}</nav>
+21
View File
@@ -0,0 +1,21 @@
import { useEffect,useState } from 'react';
import type { InputAttachment } from '../types';
import { MobileError } from './api';
async function readImage(sessionId:string,image:InputAttachment,original=false){
const controller=new AbortController(),timer=setTimeout(()=>controller.abort(),15000);
try{
const response=await fetch('/mobile-api/sessions/'+sessionId+'/input-attachments/'+image.id+'/'+(original?'original':'image'),{credentials:'same-origin',cache:'no-store',signal:controller.signal});
if(!response.ok){const value=await response.json().catch(()=>({}));throw new MobileError(value.error||'截图读取失败。',response.status);}
const bytes=await response.arrayBuffer();if(bytes.byteLength>(original?2*1024*1024:768*1024))throw new MobileError('截图超出允许大小。');
const digest=Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256',bytes)),value=>value.toString(16).padStart(2,'0')).join('');
if(digest!==(original?image.sha256:image.sentSha256))throw new MobileError('截图SHA-256核对失败,请在电脑核对。');
return new Blob([bytes],{type:original?image.mediaType:'image/png'});
}finally{clearTimeout(timer);}
}
export function MobileInputImage({sessionId,image,onError}:{sessionId:string;image:InputAttachment;onError:(cause:unknown)=>void}){
const [url,setUrl]=useState(''),[error,setError]=useState(''),[busy,setBusy]=useState(false);
useEffect(()=>{let alive=true,objectUrl='';setUrl('');setError('');void readImage(sessionId,image).then(blob=>{if(alive){objectUrl=URL.createObjectURL(blob);setUrl(objectUrl);}}).catch(cause=>{if(alive){setError(cause.message);onError(cause);}});return()=>{alive=false;if(objectUrl)URL.revokeObjectURL(objectUrl);};},[sessionId,image.id,image.sentSha256]);
async function download(){setBusy(true);try{const blob=await readImage(sessionId,image,true),href=URL.createObjectURL(blob),link=document.createElement('a');link.href=href;link.download=image.name;link.click();setTimeout(()=>URL.revokeObjectURL(href),1000);}catch(cause){onError(cause);}finally{setBusy(false);}}
return <section className="mobile-input-image"><h2>本任务截图</h2><strong>{image.name}</strong><p>{url?'SHA-256 已核对':error||'正在核对截图…'} · 发送副本 {image.sentWidth} × {image.sentHeight}</p>{url&&<details><summary>查看发送给模型的截图</summary><img src={url} alt={image.name}/><code>{image.sentSha256}</code></details>}<button disabled={busy||!url} onClick={()=>void download()}>核对并下载原图</button><p className="mobile-muted">原图 {image.width} × {image.height}。手机按现有项目观察权限读取;添加截图与预算续接在电脑操作。</p></section>;
}
+1
View File
@@ -6,3 +6,4 @@
.mobile-stream strong, .mobile-stream span { display: block; }
.mobile-stream span { color: #526658; font-size: 11px; margin-top: 6px; }
.mobile-stream pre { max-height: 240px; overflow-y: auto; margin-bottom: 0; }
.mobile-input-image{padding:18px 0;border-top:1px solid var(--line);border-bottom:1px solid var(--line);margin-top:18px}.mobile-input-image>strong{font-size:13px;overflow-wrap:anywhere}.mobile-input-image p{font-size:12px;color:var(--muted)}.mobile-input-image img{display:block;width:100%;max-height:60dvh;object-fit:contain}.mobile-input-image code{display:block;overflow-wrap:anywhere;font-size:10px;margin:10px 0}.mobile-input-image>button{margin-top:10px}.mobile-input-image details{font-size:13px}
+5 -1
View File
@@ -16,7 +16,10 @@ export interface WorkspaceRecord {
observation?: { rootState: string; branchHead: string | null; workspaceHead: string | null; workspaceBranch: string | null; registered: boolean; clean: boolean; contentsVerified: boolean; sourcePreserved: boolean; ready: boolean; fingerprint: string; observedAt: string; problems: string[] } | null;
}
export interface SessionBrief { id: string; projectId: string; title: string; status: string; revision: number; updatedAt: string; changeCount: number }
export interface Message { id: string; role: string; content: string; createdAt: string }
export interface Message { id: string; role: string; content: string; createdAt: string; attachmentIds?: string[] }
export interface InputAttachment { id:string;name:string;status:string;mediaType:string;taskId:string|null;runId:string|null;sha256:string;bytes:number;sentSha256:string;sentBytes:number;width:number;height:number;sentWidth:number;sentHeight:number;orientation:number }
export interface BudgetPause { reason:string;requiredInputTokens?:number;contextLimit?:number;inputBudget?:number;outputReservation?:number;safetyTokens?:number;runRemainingTokens?:number|null;taskRemainingTokens?:number|null;imageReservationTokens?:number;breakdown?:Record<string,number> }
export interface Run { budgetPause?:BudgetPause }
export interface ToolEvent {
id: string; kind: string; label: string; phase: string; createdAt: string; tool?: string;
input?: Record<string, unknown>; output?: string; durationMs?: number; startedAt?: string; finishedAt?: string;
@@ -42,6 +45,7 @@ export interface Session {
archived: boolean; recoveryNotice?: string | null; executionMode?: string;
failure?: RuntimeFailure | null; lastFailure?: RuntimeFailure | null;
execution?: ExecutionSnapshot;
inputAttachments?: InputAttachment[];
}
export interface RuntimeFailure {
source: string; stage: string; kind: string; title: string; message: string; messageId?: string;
+3
View File
@@ -9,6 +9,9 @@ export function mobileSession(store, runtime, session, redact = String) {
const checks = [...store.core.check_job.values()].filter(value => value.sessionId === session.id && value.taskId === session.taskId);
const result = {
...sessionBrief(session, redact),
inputAttachments:[...store.core.input_attachment.values()].filter(row=>row.sessionId===session.id&&row.taskId===session.taskId&&row.status==='attached')
.map(row=>pick(row,['id','name','status','mediaType','taskId','runId','sha256','bytes','sentSha256','sentBytes','width','height','sentWidth','sentHeight','orientation'])),
budgetPause:run?.budgetPause?pick(run.budgetPause,['reason','requiredInputTokens','contextLimit','inputBudget','outputReservation','safetyTokens','imageReservationTokens','breakdown']):null,
task: task ? { ...pick(task, ['id', 'status', 'budget', 'usage', 'verification']), goal: String(task.goal).slice(0, 12000) } : null,
run: run ? pick(run, ['id', 'taskId', 'status', 'budget', 'usage', 'steps', 'toolCalls', 'stopReason', 'startedAt', 'finishedAt']) : null,
progress: { total: tools.length, completed: tools.filter(value => value.state === 'completed').length,
+66
View File
@@ -0,0 +1,66 @@
import { randomUUID,createHash } from 'node:crypto';
import { budgetFor } from './request-plan.mjs';
import { accountedTokens,emptyUsage } from '../../shared/contracts/execution.mjs';
import { capabilityRejections } from '../../shared/contracts/model-capabilities.mjs';
const fail=(message,status=409)=>Object.assign(new Error(message),{status});
const hash=value=>createHash('sha256').update(JSON.stringify(value)).digest('hex');
const ranges={contextLimit:[1000,200000],maxOutputTokens:[256,16000],maxSteps:[1,30],maxRunTokens:[1000,2000000],maxTaskTokens:[1000,10000000],maxRunDurationMs:[1000,3600000]};
export class BudgetResume {
constructor(store,provider,runtime){this.store=store;this.provider=provider;this.runtime=runtime;}
current(session){
const task=this.store.core.task.get(session.taskId),run=this.store.core.run.get(session.runId);
if(!task||!run||run.taskId!==task.id||!['paused','failed'].includes(session.status)||this.runtime.projectHasActivity(session.projectId))throw fail('请等待原任务暂停后再准备续接。');
if([...this.store.core.worker.values()].some(row=>row.sessionId===session.id))throw fail('受限子任务请在父协作中处理预算。');
return {task,run};
}
prepare(session,input){
const {task,run}=this.current(session);
if(!input||Object.keys(input).some(key=>![...Object.keys(ranges),'selection'].includes(key)))throw fail('续接预览字段无效。',400);
const config={...this.store.config,maxTaskTokens:task.budget.maxTokens};
for(const [key,[minimum,maximum]] of Object.entries(ranges))if(input[key]!==undefined){
if(!Number.isSafeInteger(input[key])||input[key]<minimum||input[key]>maximum)throw fail('续接预算 '+key+' 超出允许范围。',400);
config[key]=input[key];
}
if(config.maxTaskTokens<task.budget.maxTokens||config.maxTaskTokens<=accountedTokens(task.usage))throw fail('任务累计预算只能保留或明确增加,并须高于已记账用量。',400);
const hub=this.provider.modelHub(this.store),selection=input.selection??hub.state.selected;
if(!selection||Object.keys(selection).some(key=>!['type','id'].includes(key))||!['connection','pool','legacy'].includes(selection.type)||typeof selection.id!=='string')throw fail('请选择原连接或模型中心已有连接/池。',400);
if(selection.type!=='legacy')config.mode='compatible';
const prepared=hub.prepare(config,selection);this.provider.validate(prepared);
if(prepared.contextLimit!==config.contextLimit||prepared.maxOutputTokens!==config.maxOutputTokens)throw fail('所选连接或池的容量小于填写值,请按实际最小容量修改预览。',400);
const images=this.runtime.inputAttachments().images(session,task),requirements=['text','tools',...(images.length?['vision']:[])];
if(images.length&&!prepared.modelRouting)throw fail('原任务有截图,请选模型中心支持视觉的连接。',400);
const members=prepared.modelRouting?.members??[],eligible=members.filter(member=>!capabilityRejections(member,[...requirements,...(member.streaming?['streaming']:[])],member.credentialRevision).length);
if(members.length&&!eligible.length)throw fail('所选连接没有满足原任务所需能力的成员。',400);
const budget=budgetFor(prepared,{budget:{maxTokens:prepared.maxRunTokens},usage:emptyUsage()},{...task,budget:{maxTokens:prepared.maxTaskTokens}});
if(budget.inputBudget<=0||run.budgetPause?.requiredInputTokens>budget.inputBudget)throw fail('预览预算仍容不下原暂停时的必需输入和响应预留,请调整后再准备。',400);
const record={schema:1,id:randomUUID(),sessionId:session.id,projectId:session.projectId,taskId:task.id,runId:run.id,status:'prepared',createdAt:new Date().toISOString(),
expiresAt:new Date(Date.now()+15*60000).toISOString(),expectedSessionRevision:session.revision+1,configRevision:this.store.config.configRevision,
registryRevision:hub.state.revision,selection:structuredClone(selection),config:structuredClone(prepared),budget,
eligibleConnections:eligible.map(member=>({id:member.id,name:member.name,model:member.model,protocol:member.protocol})),
before:{model:structuredClone(run.model),runBudget:structuredClone(run.budget),taskBudget:structuredClone(task.budget),taskUsage:structuredClone(task.usage)},
attachmentIds:[...(task.attachmentIds??[])],completedToolIds:[...this.store.core.tool.values()].filter(row=>row.taskId===task.id&&row.state==='completed').map(row=>row.id),
unknownToolIds:[...this.store.core.tool.values()].filter(row=>row.taskId===task.id&&row.requiresVerification).map(row=>row.id),
historySha256:hash(session.providerMessages),previousPause:structuredClone(run.budgetPause??null),
note:'仅作用于原Task的新Run;保留全部用户要求、附件及实际工具结果。不会改全局连接、重放完成工具或自动批准命令。'};
const artifact=this.store.artifactStore.write(session,run,JSON.stringify(record),{kind:'budget-resume-plan',mediaType:'application/json'});
this.store.core.artifact.set(artifact.id,artifact);record.artifactId=artifact.id;record.sha256=artifact.sha256;
this.store.putRecord('resume_plan',session,record,'budget.resume_prepared');return structuredClone(record);
}
verify(session,input){
this.current(session);
if(!input||Object.keys(input).some(key=>!['planId','sha256'].includes(key)))throw fail('确认需要原续接预览身份。',400);
const plan=this.store.owned('resume_plan',input.planId,session.id),artifact=this.store.owned('artifact',plan.artifactId,session.id);
const frozen=JSON.parse(this.store.artifactStore.read(artifact)),{artifactId,sha256,...identity}=plan;
if(plan.status!=='prepared'||input.sha256!==sha256||artifact.sha256!==sha256||hash(identity)!==hash(frozen)
||session.taskId!==plan.taskId||session.runId!==plan.runId||session.revision!==plan.expectedSessionRevision||Date.parse(plan.expiresAt)<Date.now()
||plan.configRevision!==this.store.config.configRevision||this.provider.modelHub(this.store).state.revision!==plan.registryRevision||hash(session.providerMessages)!==plan.historySha256)throw fail('原任务、连接或预算预览已变化,请重新准备后确认。');
for(const member of plan.config.modelRouting?.members??[]){
const current=this.provider.hub.connection(member.id);
if(current.revision!==member.revision||(this.provider.hub.credential(current)?.revision??0)!==member.credentialRevision)throw fail('模型连接身份已变化,请重新预览。');
}
this.runtime.inputAttachments().images(session,this.store.core.task.get(plan.taskId));
return plan;
}
}
+141
View File
@@ -0,0 +1,141 @@
import { randomUUID } from 'node:crypto';
import { PNG } from 'pngjs';
import jpeg from 'jpeg-js';
export const IMAGE_LIMITS = { bytes: 2 * 1024 * 1024, pixels: 16 * 1024 * 1024, dimension: 8192, sentDimension: 1024, sentBytes: 768 * 1024, perTask: 1, drafts: 8 };
const reject = (message, status = 400) => Object.assign(new Error(message), { status });
function dimensions(bytes, type) {
if (type === 'image/png' && bytes.length >= 33 && bytes.subarray(0, 8).equals(Buffer.from([137,80,78,71,13,10,26,10]))
&& bytes.readUInt32BE(8) === 13 && bytes.toString('ascii', 12, 16) === 'IHDR') {
let ended = false;
for (let offset = 8; offset < bytes.length;) {
if (offset + 12 > bytes.length) throw reject('PNG区块不完整。');
const length = bytes.readUInt32BE(offset), name = bytes.toString('ascii', offset + 4, offset + 8);
if (offset + length + 12 > bytes.length || ['acTL','fcTL','fdAT'].includes(name)) throw reject('只支持完整的静态PNG图片。');
offset += length + 12;
if (name === 'IEND') { ended = length === 0 && offset === bytes.length; break; }
}
if (!ended) throw reject('PNG结束区块或尾部内容无效。');
return { width: bytes.readUInt32BE(16), height: bytes.readUInt32BE(20), orientation: 1 };
}
if (type === 'image/jpeg' && bytes[0] === 255 && bytes[1] === 216 && bytes.at(-2) === 255 && bytes.at(-1) === 217) {
let size, orientation = 1;
for (let p = 2; p < bytes.length;) {
if (bytes[p++] !== 255) break;
while (bytes[p] === 255) p++;
const marker = bytes[p++];
if (marker === 217 && p === bytes.length && size) return { ...size, orientation };
if (p + 2 > bytes.length || marker === 216 || marker === 217) break;
const length = bytes.readUInt16BE(p);
if (length < 2 || p + length > bytes.length) break;
if ([192,193,194].includes(marker) && length >= 8) size = { width: bytes.readUInt16BE(p + 5), height: bytes.readUInt16BE(p + 3) };
if (marker === 225 && bytes.toString('ascii',p+2,p+8) === 'Exif\0\0') orientation = exifOrientation(bytes.subarray(p+8,p+length));
p += length;
if (marker === 218) {
// Scan data may contain escaped FF bytes and restart markers; the next
// real marker must still be parsed, including progressive scan headers.
while (p < bytes.length) {
if (bytes[p++] !== 255) continue;
const start = p - 1;
while (bytes[p] === 255) p++;
if (bytes[p] === 0 || bytes[p] >= 208 && bytes[p] <= 215) { p++; continue; }
p = start; break;
}
}
}
}
throw reject('图片内容与PNG/JPEG类型不符,或图片已损坏。');
}
function exifOrientation(bytes) {
try {
const little = bytes.toString('ascii',0,2) === 'II';
if (!little && bytes.toString('ascii',0,2) !== 'MM') throw new Error();
const u16 = offset => little ? bytes.readUInt16LE(offset) : bytes.readUInt16BE(offset);
const u32 = offset => little ? bytes.readUInt32LE(offset) : bytes.readUInt32BE(offset);
if (u16(2) !== 42) throw new Error();
const offset = u32(4), count = u16(offset);
if (offset < 8 || offset + 2 + count * 12 + 4 > bytes.length) throw new Error();
for (let i=0;i<count;i++) {
const entry=offset+2+i*12;
if (u16(entry)!==274) continue;
if(u16(entry+2)!==3 || u32(entry+4)!==1) throw new Error();
const value=u16(entry+8); if(value<1 || value>8) throw new Error(); return value;
}
return 1;
} catch { throw reject('JPEG方向元数据已损坏,请重新导出图片。'); }
}
function sentImage(decoded, orientation, maximum) {
const rotated = orientation >= 5;
const w = rotated ? decoded.height : decoded.width, h = rotated ? decoded.width : decoded.height;
const ratio = Math.min(1,maximum/Math.max(w,h)), width=Math.max(1,Math.round(w*ratio)), height=Math.max(1,Math.round(h*ratio));
const output = new PNG({width,height});
for(let y=0;y<height;y++) for(let x=0;x<width;x++) {
const u=Math.min(w-1,Math.floor(x*w/width)),v=Math.min(h-1,Math.floor(y*h/height));
const [sx,sy] = orientation===2 ? [decoded.width-1-u,v] : orientation===3 ? [decoded.width-1-u,decoded.height-1-v]
: orientation===4 ? [u,decoded.height-1-v] : orientation===5 ? [v,u] : orientation===6 ? [v,decoded.height-1-u]
: orientation===7 ? [decoded.width-1-v,decoded.height-1-u] : orientation===8 ? [decoded.width-1-v,u] : [u,v];
output.data.set(decoded.data.subarray((sy*decoded.width+sx)*4,(sy*decoded.width+sx)*4+4),(y*width+x)*4);
}
return { bytes:PNG.sync.write(output),width,height };
}
export function validateImage(input) {
if (!input || Object.keys(input).some(key => !['name','mediaType','base64'].includes(key)) || typeof input.name !== 'string' || !input.name.trim() || input.name.length > 160
|| /[\\/\x00-\x1f]/.test(input.name) || !['image/png','image/jpeg'].includes(input.mediaType) || typeof input.base64 !== 'string') throw reject('请选择PNG或JPEG图片,文件名不能包含路径。');
if (input.base64.length > Math.ceil(IMAGE_LIMITS.bytes / 3) * 4) throw reject('单张图片最多2MB,请先裁剪或压缩。',413);
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(input.base64)) throw reject('图片编码无效。');
const bytes = Buffer.from(input.base64,'base64');
if (bytes.length > IMAGE_LIMITS.bytes) throw reject('单张图片最多2MB,请先裁剪或压缩。',413);
if (!bytes.length || bytes.toString('base64') !== input.base64) throw reject('图片编码或大小无效。');
const size = dimensions(bytes,input.mediaType);
if (!size.width || !size.height || Math.max(size.width,size.height)>IMAGE_LIMITS.dimension || size.width*size.height>IMAGE_LIMITS.pixels) throw reject('图片尺寸过大,请裁剪后再添加。',413);
let decoded;
try { decoded = input.mediaType==='image/png' ? PNG.sync.read(bytes,{checkCRC:true}) : jpeg.decode(bytes,{useTArray:true,tolerantDecoding:false,maxResolutionInMP:16.8,maxMemoryUsageInMB:160}); }
catch { throw reject('图片无法完整解码,请重新导出PNG/JPEG。'); }
if (decoded.width!==size.width || decoded.height!==size.height) throw reject('图片实际尺寸不一致。');
let maximum = IMAGE_LIMITS.sentDimension, sent = sentImage(decoded,size.orientation,maximum);
while(sent.bytes.length>IMAGE_LIMITS.sentBytes && maximum>64) { maximum=Math.floor(maximum*0.75);sent=sentImage(decoded,size.orientation,maximum); }
if(sent.bytes.length>IMAGE_LIMITS.sentBytes)throw reject('图片发送副本超过大小限制,请先裁剪。',413);
return { bytes, sent:sent.bytes, width:size.width,height:size.height,orientation:size.orientation,sentWidth:sent.width,sentHeight:sent.height };
}
export class InputAttachments {
constructor(store, { busy=()=>false }={}) { this.store=store;this.busy=busy; }
list(session) { return [...this.store.core.input_attachment.values()].filter(row=>row.sessionId===session.id && ['draft','attached'].includes(row.status)).map(row=>structuredClone(row)); }
upload(session,input) {
if(this.busy(session.projectId))throw reject('请等待当前项目执行结束后再添加附件。',409);
if(this.list(session).filter(row=>row.status==='draft').length>=IMAGE_LIMITS.drafts)throw reject('待发送图片已满,请先移除不用的图片。',409);
const value=validateImage(input),identity={id:session.id,projectId:session.projectId,taskId:null,runId:null};
const original=this.store.artifactStore.write(identity,null,value.bytes,{kind:'input-image-original',mediaType:input.mediaType});
const sent=this.store.artifactStore.write(identity,null,value.sent,{kind:'input-image-sent',mediaType:'image/png'});
this.store.core.artifact.set(original.id,original);this.store.core.artifact.set(sent.id,sent);
const record={id:randomUUID(),sessionId:session.id,projectId:session.projectId,taskId:null,runId:null,status:'draft',name:input.name.trim(),mediaType:input.mediaType,
originalArtifactId:original.id,sentArtifactId:sent.id,sha256:original.sha256,bytes:original.bytes,sentSha256:sent.sha256,sentBytes:sent.bytes,
width:value.width,height:value.height,orientation:value.orientation,sentWidth:value.sentWidth,sentHeight:value.sentHeight,createdAt:new Date().toISOString()};
this.store.putRecord('input_attachment',session,record,'input_attachment.uploaded');return structuredClone(record);
}
get(session,id) { return this.store.owned('input_attachment',id,session.id); }
remove(session,id) {
const row=this.get(session,id);
if(row.status!=='draft'||this.busy(session.projectId))throw reject('已发送附件保留在原任务中;只能移除尚未发送的图片。',409);
row.status='withdrawn';this.store.save(session,{type:'input_attachment.withdrawn'});return this.list(session);
}
validateSelection(session,ids) {
if(!Array.isArray(ids)||ids.length>IMAGE_LIMITS.perTask||new Set(ids).size!==ids.length)throw reject('每个任务当前支持一张图片。');
return ids.map(id=>{const row=this.get(session,id);if(row.status!=='draft')throw reject('图片已发送或移除,请重新选择。',409);this.read(session,id);this.read(session,id,{original:true});return row;});
}
read(session,id,{original=false}={}) {
const row=this.get(session,id);if(row.status==='withdrawn')throw reject('这张待发送图片已移除。',410);
const artifact=this.store.owned('artifact',original?row.originalArtifactId:row.sentArtifactId,session.id);
if(row.projectId!==session.projectId || artifact.taskId!==row.taskId||artifact.runId!==row.runId||artifact.sha256!==(original?row.sha256:row.sentSha256)
||artifact.kind!==(original?'input-image-original':'input-image-sent') || artifact.mediaType!==(original?row.mediaType:'image/png') || artifact.bytes!==(original?row.bytes:row.sentBytes))throw reject('附件身份已变化,请核对原记录。',409);
if(row.status==='attached'){
const task=this.store.owned('task',row.taskId,session.id),run=this.store.owned('run',row.runId,session.id);
if(run.taskId!==task.id||!task.attachmentIds?.includes(row.id))throw reject('附件不属于原Task/Run。',409);
}
return {row,artifact,bytes:this.store.artifactStore.readBytes(artifact)};
}
images(session,task) {
return (task.attachmentIds??[]).map(id=>{const {row,bytes}=this.read(session,id);this.read(session,id,{original:true});if(row.taskId!==task.id||row.status!=='attached')throw reject('附件不属于当前任务。',409);
return {id:row.id,sha256:row.sentSha256,width:row.sentWidth,height:row.sentHeight,dataUrl:'data:image/png;base64,'+bytes.toString('base64')};});
}
}
+37 -6
View File
@@ -1,6 +1,6 @@
import { createHash, randomUUID } from 'node:crypto';
import { BudgetExceeded, accountedTokens } from '../../shared/contracts/execution.mjs';
import { completionBody, requestMetrics, requestVariants, requestHistory, outputReservation } from '../../shared/contracts/model-request.mjs';
import { completionBody, requestMetrics, requestVariants, requestHistory, outputReservation, requestImages } from '../../shared/contracts/model-request.mjs';
import { workingCandidates, workingDocument, workingEntry, workingMessage, verifyWorkingDocument } from './working-set.mjs';
import { latestToolDocument, latestToolMessage, verifyLatestToolDocument } from './tool-feedback.mjs';
import { projectMemoryMessage, MEMORY_CONTEXT_LIMITS } from '../memory/project-memory.mjs';
@@ -48,7 +48,7 @@ export function historyGroups(messages) {
return groups;
}
function budgetFor(config, run, task) {
export function budgetFor(config, run, task) {
const outputReservation = config.maxOutputTokens;
const safetyTokens = Math.max(512, Math.ceil(Math.min(config.contextLimit, 24000) * 0.1));
const remaining = (maximum, usage) => maximum > 0 ? Math.max(0, maximum - accountedTokens(usage)) : null;
@@ -118,11 +118,12 @@ function notice(reference, omitted, descriptions, evidence = []) {
].join('\n') };
}
function pause(budget, metrics) {
function pause(budget, metrics, breakdown) {
const error = new BudgetExceeded(budget.limitingReason,
'任务目标、完整追加要求与必需请求开销超过' + (budget.limitingReason === 'context_limit' ? '上下文窗口' : '剩余token预算') +
'。完整历史已保留;请核对模型上下文或任务预算后继续。');
error.contextBudget = { ...budget, requiredInputTokens: metrics.estimatedInputTokens };
error.contextBudget = { ...budget, requiredInputTokens: metrics.estimatedInputTokens, imageReservationTokens:metrics.imageReservationTokens??0,
imageEstimate:metrics.imageEstimate??null,breakdown:breakdown(metrics) };
return error;
}
@@ -162,6 +163,14 @@ export class RequestPlanner {
const groups = historyGroups(session.providerMessages), budget = budgetFor(config, run, task);
const lastUser = groups.findLast(group => group.messages[0].role === 'user');
const fixed = { role: 'system', content: system };
const breakdown = metrics => {
const empty=requestMetrics(completionBody(config,[],[])).estimatedInputTokens;
const fixedText=requestMetrics(completionBody(config,[fixed],[])).estimatedInputTokens;
const fixedTools=requestMetrics(completionBody(config,[fixed],tools)).estimatedInputTokens;
return {transportAndImageFramingTokens:empty-(metrics.imageReservationTokens??0),goalAndContextTextTokens:fixedText-empty,
toolDefinitionTokens:fixedTools-fixedText,historyAndEvidenceTokens:metrics.estimatedInputTokens-fixedTools,
imageReservationTokens:metrics.imageReservationTokens??0};
};
const ledger = new Map([...this.store.core.tool.values()].filter(tool => tool.sessionId === session.id).map(tool => [tool.callId, tool]));
const descriptions = new Map(groups.map(group => [group.index, describe(group, ledger, this.store.core.artifact)]));
const evidence = workingEvidence(groups, descriptions, this.store.core.artifact);
@@ -181,7 +190,7 @@ export class RequestPlanner {
if (before.estimatedInputTokens > budget.targetInputTokens) {
selected.clear(); if (lastUser) selected.add(lastUser.index);
const mandatory = metricsFor(selected);
if (mandatory.estimatedInputTokens > budget.inputBudget) throw pause(budget, mandatory);
if (mandatory.estimatedInputTokens > budget.inputBudget) throw pause(budget, mandatory, breakdown);
const observed = workingCandidates(this.store, session, run, groups);
// Reserve other small source files before admitting a new result group.
// Historical locator pages are optional; they cannot evict actual code.
@@ -295,7 +304,7 @@ export class RequestPlanner {
}
}
const body = completionBody(config, messages, tools), metrics = requestMetrics(body);
if (metrics.estimatedInputTokens > budget.inputBudget) throw pause(budget, metrics);
if (metrics.estimatedInputTokens > budget.inputBudget) throw pause(budget, metrics, breakdown);
const requestArtifact = this.artifact(session, run, body, 'model-request');
const record = { schemaVersion: 1, id: randomUUID(), sessionId: session.id, projectId: session.projectId, taskId: run.taskId,
runId: run.id, stepId, requestIndex: [...this.store.core.context_plan.values()].filter(plan => plan.runId === run.id).length + 1,
@@ -303,6 +312,8 @@ export class RequestPlanner {
requestSha256: metrics.sha256, requestBytes: metrics.bytes, estimatedInputTokens: metrics.estimatedInputTokens,
requestArtifactId: requestArtifact.id,
estimateMethod: metrics.estimateMethod, beforeInputTokens: before.estimatedInputTokens, beforeBytes: before.bytes, budget,
...(metrics.imageCount?{imageCount:metrics.imageCount,imageReservationTokens:metrics.imageReservationTokens,imageEstimate:metrics.imageEstimate,
inputImages:config.inputImages.map(({dataUrl,...identity})=>identity)}:{}),
mandatoryInputTokens: metricsFor(new Set(lastUser ? [lastUser.index] : []), true, []).estimatedInputTokens,
// The next result replaces the current latest-result feedback. Do not
// reserve both views when sizing that result's actual protocol page.
@@ -353,6 +364,26 @@ export function verifyPlanEvidence(store, session, plan, cache = new Map()) {
historyGroups(requestHistory(body));
for (const variant of requestVariants(body)) historyGroups(requestHistory(variant));
const frozen = JSON.parse(store.artifactStore.read(get(plan.artifactId, 'context-plan')));
for(const key of ['imageCount','imageReservationTokens','imageEstimate','inputImages']) {
if(JSON.stringify(frozen[key]??null)!==JSON.stringify(plan[key]??null))throw new Error('图片身份或预算与发送前封存不匹配。');
}
if(metrics.imageCount) {
if(metrics.imageCount!==plan.imageCount||metrics.imageReservationTokens!==plan.imageReservationTokens||metrics.imageEstimate!==plan.imageEstimate
||plan.inputImages?.length!==metrics.imageCount)throw new Error('图片预算与实际正文不匹配。');
for(const variant of requestVariants(body)) {
const images=requestImages(variant);
if(images.length!==plan.inputImages.length)throw new Error('图片请求线路不一致。');
for(const [index,url] of images.entries()) {
const identity=plan.inputImages[index],row=store.owned('input_attachment',identity.id,session.id);
const artifact=get(row.sentArtifactId,'input-image-sent',identity.sha256),bytes=store.artifactStore.readBytes(artifact);
const original=get(row.originalArtifactId,'input-image-original',row.sha256);store.artifactStore.readBytes(original);
if(row.taskId!==plan.taskId||row.status!=='attached'||artifact.taskId!==plan.taskId||artifact.runId!==row.runId
||original.taskId!==plan.taskId||original.runId!==row.runId
||row.sentSha256!==identity.sha256||row.sentWidth!==identity.width||row.sentHeight!==identity.height
||url!=='data:image/png;base64,'+bytes.toString('base64'))throw new Error('图片原字节或任务归属与实际正文不匹配。');
}
}
} else if(plan.imageCount||plan.inputImages?.length)throw new Error('请求缺少封存的图像。');
if (frozen.id !== plan.id || frozen.requestSha256 !== plan.requestSha256 || frozen.requestArtifactId !== plan.requestArtifactId
|| JSON.stringify(frozen.budget) !== JSON.stringify(plan.budget)) throw new Error('请求计划与发送前的封存记录不匹配。');
if ((frozen.workingSetArtifactId ?? null) !== (plan.workingSetArtifactId ?? null)
+10 -6
View File
@@ -2,6 +2,7 @@ import { randomUUID, createHash } from 'node:crypto';
import { setTimeout as delay } from 'node:timers/promises';
import { ModelRequestError } from '../../server/diagnostics.mjs';
import { CredentialVault } from './credential-vault.mjs';
import { visionProbe } from './vision-probe.mjs';
import { modelProtocol, capabilityDeclarations, capabilityView, capabilityRejections } from '../../shared/contracts/model-capabilities.mjs';
import { actualRequest, requestVariants } from '../../shared/contracts/model-request.mjs';
@@ -118,7 +119,7 @@ export class ModelHub {
storage: { credentials: this.credentialVault ? 'memory-or-windows-user-dpapi' : 'memory', restart: '临时凭据在宿主退出后需要重新填写;已明确本机加密保存的连接按用户与原配置加载。', attemptsRetained: 1000 } }; }
connection(id) { const value = this.connections().find(item => item.id === id); if (!value) throw error('模型连接不存在。', 404); return value; }
async probe(id, scope = 'text') {
if (!['text', 'tools', 'streaming'].includes(scope)) throw error('请选择文本、工具调用或流式检测。');
if (!['text', 'tools', 'streaming', 'vision'].includes(scope)) throw error('请选择文本、工具调用、流式或图像检测。');
if (this.probing) throw error('已有模型能力检测正在执行,请等待结束。', 409);
this.probing = true;
try {
@@ -131,13 +132,16 @@ export class ModelHub {
const config = { ...this.store.config, mode: 'compatible', model: connection.model, baseUrl: connection.baseUrl,
protocol: modelProtocol(connection.protocol), maxOutputTokens: 256, capabilityProbe: true, modelRouting: { type: 'connection', id: connection.id, revision: connection.revision,
strategy: 'round-robin', sticky: false, maxAttempts: 1, queueTimeoutMs: 1000, members: [member] } };
const visual=scope==='vision'?visionProbe():null;
if(visual)config.inputImages=[visual.image];
let attemptId;
const result = await this.provider.complete(config, [{ role: 'user', content: scope === 'tools' ? 'Call workbench_capability_echo with nonce ' + nonce + '. Do not reply with plain text.' : 'Reply OK.' }], null, undefined,
const result = await this.provider.complete(config, [{ role: 'user', content: visual?.prompt ?? (scope === 'tools' ? 'Call workbench_capability_echo with nonce ' + nonce + '. Do not reply with plain text.' : 'Reply OK.') }], null, undefined,
event => { if (event.modelAttemptId) attemptId = event.modelAttemptId; }, null, tools, { attempts: 1 });
if (scope === 'tools') {
const calls = result.message.tool_calls;
if (calls?.length !== 1 || calls[0].function.name !== 'workbench_capability_echo' || JSON.parse(calls[0].function.arguments).nonce !== nonce) throw error('服务没有返回要求的原工具调用;未标为已验证。');
} else if (!result.message.content.trim() || result.message.tool_calls?.length) throw error('服务没有返回纯文本响应;未标为已验证。');
if(visual&&result.message.content.trim().toUpperCase().replace(/\s/g,'')!==visual.expected)throw error('服务未正确识别合成图像的四色顺序,原请求保留,未标为视觉已验证。');
if (this.connection(id).revision !== connection.revision || (this.credential(connection)?.revision ?? 0) !== member.credentialRevision) throw error('检测期间连接已变化,原结果保留但不更新能力结论。', 409);
this.editRegistry(() => {
this.state.capabilityResults ??= {};
@@ -217,9 +221,8 @@ export class ModelHub {
this.save(config ?? (input.type !== 'legacy' ? { mode: 'compatible' } : null));
return this.view();
}
prepare(config) {
if (config.mode === 'demo' || this.state.selected.type === 'legacy') return config;
const selection = this.state.selected;
prepare(config, selection = this.state.selected) {
if (config.mode === 'demo' || selection.type === 'legacy') return config;
const pool = selection.type === 'pool' ? this.state.pools.find(value => value.id === selection.id) : null;
if (selection.type === 'pool' && !pool) throw error('选中的模型池不存在。');
const members = (pool?.members ?? [{ connectionId: selection.id, weight: 1 }]).map(value => ({ ...this.connection(value.connectionId), capabilityEvidence: this.state.capabilityResults?.[value.connectionId], weight: value.weight,
@@ -272,7 +275,8 @@ export class ModelHub {
async completeOwned(config, body, signal, onProgress, plan, execute) {
const routing = config.modelRouting, excluded = new Set(), deadline = Date.now() + Math.min(routing.queueTimeoutMs, 60000);
const requestId = plan?.id ?? randomUUID(), runId = plan?.runId ?? requestId;
const requirements = config.capabilityProbe ? [] : ['text', ...(requestVariants(body).some(value => value.tools?.length) ? ['tools'] : [])];
const requirements = config.capabilityProbe ? [] : ['text', ...(requestVariants(body).some(value => value.tools?.length) ? ['tools'] : []),
...(requestVariants(body).some(value => (value.messages??value.input??[]).some(message=>Array.isArray(message.content)&&message.content.some(part=>['image_url','input_image'].includes(part.type))))?['vision']:[])];
const rejections = config.capabilityProbe ? [] : routing.members.flatMap(value => capabilityRejections(value, [...requirements, ...(value.streaming ? ['streaming'] : [])], value.credentialRevision));
const eligibleRouting = { ...routing, members: routing.members.filter(value => !rejections.some(item => item.connectionId === value.id)) };
if (!eligibleRouting.members.length) {
+13
View File
@@ -0,0 +1,13 @@
import { randomInt, createHash, randomUUID } from 'node:crypto';
import { PNG } from 'pngjs';
// Synthetic pixels only. The expected order is never placed in the prompt.
export function visionProbe() {
const colors = [{name:'RED',rgb:[230,0,0]},{name:'GREEN',rgb:[0,180,0]},{name:'BLUE',rgb:[0,0,230]},{name:'YELLOW',rgb:[240,220,0]}];
for (let i=colors.length-1;i>0;i--) { const j=randomInt(i+1);[colors[i],colors[j]]=[colors[j],colors[i]]; }
const png=new PNG({width:128,height:128});
for(let y=0;y<128;y++)for(let x=0;x<128;x++)png.data.set([...colors[(y>=64?2:0)+(x>=64?1:0)].rgb,255],(y*128+x)*4);
const bytes=PNG.sync.write(png);
return {expected:colors.map(value=>value.name).join(','),prompt:'Read the four colored squares in this attached synthetic image in order: top-left, top-right, bottom-left, bottom-right. Reply only with four comma-separated English color names, using RED, GREEN, BLUE, YELLOW. Do not call tools.',
image:{id:randomUUID(),sha256:createHash('sha256').update(bytes).digest('hex'),width:128,height:128,dataUrl:'data:image/png;base64,'+bytes.toString('base64')}};
}
+22 -3
View File
@@ -48,12 +48,12 @@ function json(response, value, status = 200) {
'X-Content-Type-Options': 'nosniff' });
response.end(JSON.stringify(value));
}
async function body(request) {
async function body(request, maximum=2*1024*1024) {
if (!String(request.headers['content-type'] ?? '').startsWith('application/json')) throw Object.assign(new Error('请求需要 JSON。'), { status: 415 });
const chunks = []; let length = 0;
for await (const chunk of request) {
length += chunk.length;
if (length > 2 * 1024 * 1024) throw Object.assign(new Error('请求超过 2 MB。'), { status: 413 });
if (length > maximum) throw Object.assign(new Error('请求超过允许大小。'), { status: 413 });
chunks.push(chunk);
}
let input;
@@ -269,6 +269,23 @@ return async (request, response) => {
if (sessionMatch) {
const id = sessionMatch[1], action = sessionMatch[2] ?? '';
const session = store.session(id);
if (action === 'input-attachments') {
if (method === 'GET') return json(response,runtime.inputAttachments().list(session));
if (workerForProject(store,session.projectId)) throw workerConflict('截图附件请在父任务中添加。');
if (method === 'POST') return json(response,runtime.inputAttachments().upload(session,await body(request,3*1024*1024)),201);
}
const inputImage = action.match(/^input-attachments\/([a-f0-9-]+)(?:\/(image|original))?$/);
if (inputImage) {
const manager=runtime.inputAttachments();
if(method==='DELETE'&&!inputImage[2]) { await body(request);return json(response,manager.remove(session,inputImage[1])); }
if(method==='GET'&&inputImage[2]) {
const {row,artifact,bytes}=manager.read(session,inputImage[1],{original:inputImage[2]==='original'});
const download=inputImage[2]==='original'||url.searchParams.get('download')==='1';
response.writeHead(200,{'Content-Type':artifact.mediaType,'Cache-Control':'no-store','X-Content-Type-Options':'nosniff','X-Content-SHA256':artifact.sha256,
...(download?{'Content-Disposition':'attachment; filename="workbench-input-'+row.id+(artifact.mediaType==='image/png'?'.png':'.jpg')+'"'}:{})});
response.end(bytes);return;
}
}
if (method === 'POST' && workerForProject(store, session.projectId)
&& /^(?:mcp|engines|research|workspaces|delivery|browser|task-plans|task-proofs|task-checkpoints|collaborations)(?:\/|-|$)/.test(action)) throw workerConflict('受限子任务只开放原目标的读取、范围内改动和已审批检查;此操作请返回父项目。');
if (method === 'GET' && action === 'collaborations') return json(response, runtime.workerManager().view(session));
@@ -574,7 +591,7 @@ return async (request, response) => {
}
if (method === 'POST' && action === 'messages') {
const input = await body(request);
runtime.start(id, input.content);
runtime.start(id, input.content,false,{attachmentIds:input.attachmentIds??[]});
return json(response, store.publicSession(session), 202);
}
if (method === 'POST' && action === 'resume') {
@@ -582,6 +599,8 @@ return async (request, response) => {
runtime.resume(id, input.content);
return json(response, store.publicSession(session), 202);
}
if(method==='POST'&&action==='resume-preview')return json(response,runtime.budgetResumes().prepare(session,await body(request)),201);
if(method==='POST'&&action==='resume-budget'){runtime.resumeBudget(id,await body(request));return json(response,store.publicSession(session),202);}
if (method === 'POST' && action === 'continue-reviewed') {
await body(request); runtime.continueReviewed(id);
return json(response, store.publicSession(session), 202);
+10 -1
View File
@@ -9,6 +9,7 @@ import { CompanionTLS } from '../core/companion/tls-authority.mjs';
import { fields, companionError, companionHash, approvalBinding, operationInput } from '../shared/contracts/companion.mjs';
import { isId } from '../shared/contracts/execution.mjs';
import { mobileSession, sessionBrief, reportKinds } from '../core/companion/projection.mjs';
import { InputAttachments } from '../core/context/input-attachments.mjs';
import { hostAuthority } from '../core/desktop/host-authority.mjs';
export function companionGateway(context) {
@@ -179,7 +180,7 @@ export class CompanionGateway {
async handle(request, response) {
response.setHeader('Cache-Control', 'no-store'); response.setHeader('X-Content-Type-Options', 'nosniff');
response.setHeader('Referrer-Policy', 'no-referrer'); response.setHeader('X-Frame-Options', 'DENY');
response.setHeader('Content-Security-Policy', "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self'; object-src 'none'; base-uri 'none'; frame-ancestors 'none'; form-action 'self'");
response.setHeader('Content-Security-Policy', "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data: blob:; connect-src 'self'; object-src 'none'; base-uri 'none'; frame-ancestors 'none'; form-action 'self'");
try {
this.registry.assertHost();
if (!this.server?.listening || !this.origin || request.headers.host !== new URL(this.origin).host) throw companionError('手机网关地址已变化,请重新连接。', 421);
@@ -220,6 +221,14 @@ export class CompanionGateway {
if (limit < 1 || limit > 200) throw companionError('手机事件每页需要1至200条。');
return reply(response, this.events(device, after, limit));
}
const attachment=route.match(/^\/mobile-api\/sessions\/([a-f0-9-]+)\/input-attachments\/([a-f0-9-]+)\/(image|original)$/);
if(attachment&&method==='GET'){
const session=this.session(device,attachment[1]),manager=new InputAttachments(this.store),row=manager.get(session,attachment[2]);
if(row.taskId!==session.taskId||row.status!=='attached'||!(this.store.core.task.get(session.taskId)?.attachmentIds??[]).includes(row.id))throw companionError('当前任务没有这张截图。',404);
const {artifact,bytes}=manager.read(session,row.id,{original:attachment[3]==='original'});
response.writeHead(200,{'Content-Type':artifact.mediaType,'Content-Length':bytes.length,'X-Content-SHA256':artifact.sha256,
...(attachment[3]==='original'?{'Content-Disposition':'attachment; filename="workbench-input-'+row.id+(row.mediaType==='image/png'?'.png':'.jpg')+'"'}:{})});response.end(bytes);return;
}
const match = route.match(/^\/mobile-api\/sessions\/([a-f0-9-]+)(?:\/(approve|stop|changes\/([a-f0-9-]+)|reports\/([a-f0-9-]+)))?$/);
if (match) {
const session = this.session(device, match[1]);
+6
View File
@@ -34,6 +34,8 @@ export function installUpgrade(context, { appDirectory, updateServiceInfo = true
const oldStoreProperties = { ...store };
const oldRuntimeProperties = { appDirectory: runtime.appDirectory, workers: runtime.workers, controlledEngines: runtime.controlledEngines, checks: runtime.checks, deliveries: runtime.deliveries, codeIndex: runtime.codeIndex, changeSets: runtime.changeSets, contextPlans: runtime.contextPlans, workspaces: runtime.workspaces, research: runtime.research, engines: runtime.engines, browser: runtime.browser, taskPlans: runtime.taskPlans, projectMemories: runtime.projectMemories, taskCheckpoints: runtime.taskCheckpoints, skills: runtime.skills, mcp: runtime.mcp };
const oldUpdates = store.listeners('update');
const oldInputs = runtime.inputs;
const oldResumes = runtime.resumes;
const closeStorage = () => store.close();
if (oldUpdates.length > 1) throw new Error('Unexpected Store observers; preserve their ownership before upgrading.');
const handler = createRequestHandler({ appDirectory: root, server, store, provider, runtime, token, clients, started,
@@ -49,6 +51,8 @@ export function installUpgrade(context, { appDirectory, updateServiceInfo = true
}
runtime.appDirectory = root; runtime.workers = null; runtime.controlledEngines = null; runtime.checks = null; runtime.deliveries = null; runtime.codeIndex = null; runtime.changeSets = null; runtime.contextPlans = null; runtime.workspaces = null; runtime.research = null; runtime.engines = null; runtime.browser = null; runtime.taskPlans = null; runtime.projectMemories = null; runtime.taskCheckpoints = null; runtime.skills = null; runtime.mcp = null;
delete server.workbenchCompanion;
runtime.inputs = null;
runtime.resumes = null;
store.ensureStorage();
// A SQLite host can retain an artifact object from an earlier bundle.
// Reopen the same blobs through the new API without mutating that object;
@@ -80,6 +84,8 @@ export function installUpgrade(context, { appDirectory, updateServiceInfo = true
for (const key of Object.keys(store)) if (!Object.hasOwn(oldStoreProperties, key)) delete store[key];
Object.assign(store, oldStoreProperties);
Object.assign(runtime, oldRuntimeProperties);
if (oldInputs === undefined) delete runtime.inputs; else runtime.inputs = oldInputs;
if (oldResumes === undefined) delete runtime.resumes; else runtime.resumes = oldResumes;
Object.setPrototypeOf(store, oldPrototypes[0]); Object.setPrototypeOf(provider, oldPrototypes[1]); Object.setPrototypeOf(runtime, oldPrototypes[2]);
if (oldModelPrototypes.hub) Object.setPrototypeOf(provider.hub, oldModelPrototypes.hub);
if (oldModelPrototypes.importer) Object.setPrototypeOf(provider.hub.importer, oldModelPrototypes.importer);
+1
View File
@@ -210,6 +210,7 @@ export class Provider {
async complete(config, messages, project, signal, onProgress, requestPlan = null, tools = toolDefinitions, requestPolicy = {}) {
const body = completionBody(config, messages, tools);
assertPlannedRequest(body, requestPlan);
if (config.inputImages?.length && (!config.modelRouting || !this.hub || config.mode==='demo')) throw new Error('图片请求必须通过模型中心的视觉能力选路,尚未发送。');
if (config.mode === 'demo') return this.demo(messages, project);
this.validate(config);
const execute = async (selected, key, input, progress) => {
+21 -5
View File
@@ -14,6 +14,8 @@ import { projectEnvironment } from '../core/process-environment.mjs';
import { GitDelivery } from '../core/git-delivery.mjs';
import { ProjectIndex } from '../core/context/project-index.mjs';
import { RequestPlanner, verifyPlanEvidence } from '../core/context/request-plan.mjs';
import { InputAttachments } from '../core/context/input-attachments.mjs';
import { BudgetResume } from '../core/context/budget-resume.mjs';
import { artifactPage, filePage, readMessageBudget, recordArtifactRead, recordBrowserRead, clearReadStreak, recordSessionInspection, readMetadataReserve, BROWSER_READ_HINT } from '../core/context/read-budget.mjs';
import { ChangeSetManager } from '../core/workspaces/change-sets.mjs';
import { assertChangeSetsResolved } from '../shared/contracts/change-sets.mjs';
@@ -119,6 +121,9 @@ export class Runtime {
redact: value => this.provider.redact(value), projectBusy: projectId => this.projectHasActivity(projectId) });
}
requestPlanner() { return this.contextPlans ??= new RequestPlanner(this.store); }
inputAttachments() { return this.inputs ??= new InputAttachments(this.store,{busy:projectId=>this.projectHasActivity(projectId)}); }
budgetResumes(){return this.resumes??=new BudgetResume(this.store,this.provider,this);}
resumeBudget(id,input){const session=this.store.session(id),plan=this.budgetResumes().verify(session,input);return this.start(id,'',true,{resumePlan:plan});}
engineRunner() { return this.controlledEngines ??= new EngineRunner(this.store, this.provider, { appDirectory: this.appDirectory }); }
memoryManager() { return this.projectMemories ??= new ProjectMemoryManager(this.store); }
checkpointManager() { return this.taskCheckpoints ??= new TaskCheckpointManager(this.store, {
@@ -159,7 +164,7 @@ export class Runtime {
|| this.store.core.collaboration.get(worker.collaborationId)?.status !== 'running') throw workerConflict('子任务只能由所属父协作启动。');
return this.start(session.id, worker.goal, true, { workerAuthorization: workerAuthority, worker, workerConfig: config });
}
start(id, content, resume = false, { instructionSource = null, workerAuthorization = null, worker = null, workerConfig = null } = {}) {
start(id, content, resume = false, { instructionSource = null, workerAuthorization = null, worker = null, workerConfig = null, attachmentIds=[],resumePlan=null } = {}) {
const session = this.store.session(id);
assertWorkersResolved(this.store, session.projectId);
const boundWorker = workerForSession(this.store, session);
@@ -174,19 +179,24 @@ export class Runtime {
if ([...this.store.core.delivery_job.values()].some(job => job.projectId === session.projectId && job.requiresVerification)) throw Object.assign(new Error('项目有结果未知的Git交付,请先在所属任务中核对提交结果。'), { status: 409 });
if (!resume && (typeof content !== 'string' || !content.trim() || content.length > 20000)) throw new Error('任务内容不能为空,也不能超过 20,000 字符。');
const project = this.store.project(session.projectId);
const attachments=this.inputAttachments().validateSelection(session,attachmentIds);
if(attachments.length&&this.store.core.task.get(session.taskId)?.attachmentIds?.length&&!['completed','idle'].includes(this.store.core.task.get(session.taskId).status))throw Object.assign(new Error('当前任务已有截图,请新建任务再添加。'),{status:409});
safePath(project);
const controller = new AbortController();
const initialConfig = structuredClone(workerConfig ?? this.store.config);
const config = workerConfig ? initialConfig : this.provider.prepareConfig ? this.provider.prepareConfig(initialConfig, this.store) : initialConfig;
const initialConfig = structuredClone(resumePlan?.config ?? workerConfig ?? this.store.config);
const config = resumePlan || workerConfig ? initialConfig : this.provider.prepareConfig ? this.provider.prepareConfig(initialConfig, this.store) : initialConfig;
if (config.mode !== 'demo') this.provider.validate(config);
const record = this.store.beginRun(session, content, resume, config, { instructionSource });
if (attachments.length && config.mode==='demo') throw Object.assign(new Error('演示执行器不会读取图片,请先选择支持视觉的模型连接。'),{status:409});
if (attachments.length && !config.modelRouting) throw Object.assign(new Error('请在模型中心添加并声明支持视觉的连接,再发送图片。'),{status:409});
const record = this.store.beginRun(session, content, resume, config, { instructionSource, inputAttachments:attachments,resumePlan });
const run = { controller, id: record.id, taskId: record.taskId, project, record, config, ...(worker ? { worker } : {}) };
this.active.set(id, run);
session.status = 'running'; session.recoveryNotice = null; session.executionMode = config.mode;
session.runId = run.id;
if (session.title === '新任务') session.title = String(content).replace(/\s+/g, ' ').slice(0, 28);
if (!resume || content) {
this.store.message(session, 'user', String(content));
const userMessage=this.store.message(session, 'user', String(content));
if(attachments.length)userMessage.attachmentIds=attachments.map(row=>row.boundAttachmentId);
session.providerMessages.push({ role: 'user', content: String(content) });
}
if (resume) this.store.message(session, 'system', '从已保存的执行记录继续,已完成的工具结果保留。');
@@ -231,6 +241,8 @@ export class Runtime {
checkBudget(run.record, this.store.core.task.get(run.taskId));
const stepRecord = this.store.beginStep(session, run.record);
const task = this.store.core.task.get(run.taskId);
config.inputImages=this.inputAttachments().images(session,task);
if(config.inputImages.length&&config.mode==='demo')throw new Error('固定演示执行器不会读取图片;请连接并声明支持视觉的模型。');
const taskPlan = task.currentTaskPlanId ? await this.taskPlanner().inspect(session, { candidates: false }) : null;
const state = session.changes.filter(change => change.taskId === task.id || ['pending', 'conflict'].includes(change.status))
.map(change => ({ path: change.path, status: change.status, id: change.id, changeSetId: change.changeSetId ?? null }));
@@ -408,6 +420,10 @@ export class Runtime {
const budget = error instanceof BudgetExceeded ? error : signal.reason instanceof BudgetExceeded ? signal.reason : null;
if (signal.aborted || budget) {
run.stopReason = budget?.reason ?? 'cancelled';
if(budget)run.record.budgetPause={schema:1,reason:budget.reason,createdAt:now(),taskId:run.taskId,runId:run.id,
...(budget.contextBudget??{}),runUsage:structuredClone(run.record.usage),taskUsage:structuredClone(this.store.core.task.get(run.taskId).usage),
runBudget:structuredClone(run.record.budget),taskBudget:structuredClone(this.store.core.task.get(run.taskId).budget),
note:'本地预留估算与服务实际用量分开记录;图片预留不是厂商计费或容量保证。'};
for (const event of session.events.filter(item => item.kind === 'model' && item.runId === run.id && ['running', 'retrying'].includes(item.phase))) {
event.phase = 'interrupted'; event.finishedAt = now(); event.output = '模型请求已停止,已完成的工具结果保留。';
}
+19 -1
View File
@@ -450,8 +450,15 @@ export class Store extends EventEmitter {
return session;
}
beginRun(session, content, resume, config, { instructionSource = null, forceNewTask = false } = {}) {
beginRun(session, content, resume, config, { instructionSource = null, forceNewTask = false, inputAttachments = [],resumePlan=null } = {}) {
let task = this.core.task.get(session.taskId);
if(resumePlan&&(!resume||!task||resumePlan.taskId!==task.id||this.owned('resume_plan',resumePlan.id,session.id)!==resumePlan||resumePlan.status!=='prepared'))throw new Error('续接预览不属于原任务。');
// Bind inputs in the same session transaction as run.started.
const inputs = inputAttachments.map(row => {
if (this.owned('input_attachment',row.id,session.id) !== row || row.status !== 'draft') throw new Error('附件选择已变化。');
return {row,artifacts:[row.originalArtifactId,row.sentArtifactId].map(id=>this.owned('artifact',id,session.id))};
});
if (inputs.length>1 || inputs.length && !forceNewTask && task?.attachmentIds?.length && (resume || !['completed','idle'].includes(task.status))) throw new Error('当前任务已有截图,请新建任务再添加。');
const previousRunId = session.runId ?? null;
if (forceNewTask || !task || !resume && ['completed', 'idle'].includes(task.status)) {
const previous = task?.id ?? null;
@@ -466,8 +473,18 @@ export class Store extends EventEmitter {
task.workspaceIdentity ??= structuredClone(workspaceIdentity);
if (JSON.stringify(task.workspaceIdentity) !== JSON.stringify(workspaceIdentity)) throw Object.assign(new Error('任务的工作区身份已变化,不能将原任务移动到另一个工作区。'), { status: 409 });
const run = createRun(session, task, config, resume ? previousRunId : null);
if(resumePlan){task.budget.maxTokens=config.maxTaskTokens;run.resumePlanId=resumePlan.id;resumePlan.status='consumed';resumePlan.newRunId=run.id;}
run.workspaceIdentity = structuredClone(workspaceIdentity);
this.core.run.set(run.id, run); task.activeRunId = run.id;
for (const {row,artifacts} of inputs) {
const copies=artifacts.map(artifact=>({...artifact,id:randomUUID(),taskId:task.id,runId:run.id}));
for(const artifact of copies)this.core.artifact.set(artifact.id,artifact);
const bound={...row,id:randomUUID(),taskId:task.id,runId:run.id,status:'attached',sourceDraftId:row.id,
originalArtifactId:copies[0].id,sentArtifactId:copies[1].id};
this.core.input_attachment.set(bound.id,bound);
row.status='consumed';row.boundAttachmentId=bound.id;
}
if (inputs.length) task.attachmentIds=inputs.map(({row})=>row.boundAttachmentId);
session.taskId = task.id; session.runId = run.id; session.status = 'running';
this.save(session, { type: 'run.started', detail: { resumeOf: run.resumeOf } });
return run;
@@ -682,6 +699,7 @@ export class Store extends EventEmitter {
publicSession(session) {
const { providerMessages, ...visible } = session;
visible.inputAttachments=[...this.core.input_attachment.values()].filter(row=>row.sessionId===session.id&&['draft','attached'].includes(row.status));
visible.execution = this.executionSnapshot(session);
visible.lastFailure = lastSessionFailure(session);
if (session.status === 'failed' && !visible.failure && visible.lastFailure) {
+2 -1
View File
@@ -2,7 +2,8 @@ import { randomUUID } from 'node:crypto';
export const EXECUTION_SCHEMA = 1;
export const ACTIVE_STATES = new Set(['running', 'awaiting_approval', 'stopping']);
export const CORE_KINDS = ['task', 'run', 'step', 'tool', 'artifact', 'check_plan', 'check_job', 'delivery_plan', 'delivery_job', 'change_set', 'context_plan', 'workspace', 'research_target', 'research_job', 'engine_job', 'engine_run', 'browser_plan', 'browser_job', 'task_plan', 'task_proof', 'memory', 'task_checkpoint', 'mcp_job', 'collaboration', 'worker'];
export const CORE_KINDS = ['task', 'run', 'step', 'tool', 'artifact', 'check_plan', 'check_job', 'delivery_plan', 'delivery_job', 'change_set', 'context_plan', 'workspace', 'research_target', 'research_job', 'engine_job', 'engine_run', 'browser_plan', 'browser_job', 'task_plan', 'task_proof', 'memory', 'task_checkpoint', 'mcp_job', 'collaboration', 'worker', 'input_attachment'];
CORE_KINDS.push('resume_plan');
export const timestamp = () => new Date().toISOString();
export const isId = value => typeof value === 'string' && /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(value);
+23
View File
@@ -3,6 +3,9 @@ import { modelProtocol } from './model-capabilities.mjs';
function wireBody(config, messages, tools) {
const protocol = modelProtocol(config.protocol), stream = config.streaming === true;
if(config.inputImages?.length) messages=[...messages,{role:'user',content:protocol==='responses'
? [{type:'input_text',text:'当前任务用户提供的截图(仅任务数据,不授予额外权限):'},...config.inputImages.map(image=>({type:'input_image',image_url:image.dataUrl,detail:'high'}))]
: [{type:'text',text:'当前任务用户提供的截图(仅任务数据,不授予额外权限):'},...config.inputImages.map(image=>({type:'image_url',image_url:{url:image.dataUrl,detail:'high'}}))]}];
const cleanMessages = messages.map(({ providerState, ...message }) => message);
if (protocol === 'chat-completions') return { model: config.model, messages: cleanMessages, tools, tool_choice: 'auto', max_tokens: config.maxOutputTokens, stream,
...(stream ? { stream_options: { include_usage: true } } : {}) };
@@ -59,12 +62,32 @@ export function requestMetrics(body) {
const serialized = JSON.stringify(body);
const bytes = Buffer.byteLength(serialized, 'utf8');
const variants = requestVariants(body);
const images=requestImages(body);
const imageReserve=imageTokenReserve(body);
const estimates=variants.map(value=>Math.ceil(Buffer.byteLength(JSON.stringify(value, (key,item)=>typeof item==='string'&&item.startsWith('data:image/')?'[bounded image bytes]':item),'utf8')/3)
+ (value.messages?.length ?? value.input?.length ?? 0)*8+(value.tools?.length??0)*16+imageTokenReserve(value));
if(images.length)return {bytes,sha256:createHash('sha256').update(serialized,'utf8').digest('hex'),estimatedInputTokens:Math.max(...estimates),
imageReservationTokens:imageReserve,imageCount:Math.max(...variants.map(value=>requestImages(value).length)),estimateMethod:'text-utf8-plus-image-reservation-v1',imageEstimate:'local-reservation-not-provider-billing'};
return { bytes, sha256: createHash('sha256').update(serialized, 'utf8').digest('hex'),
estimatedInputTokens: Math.max(...variants.map(value => Math.ceil(Buffer.byteLength(JSON.stringify(value), 'utf8') / 3)
+ (value.messages?.length ?? value.input?.length ?? 0) * 8 + (value.tools?.length ?? 0) * 16)),
estimateMethod: body.kind === 'model-route-plan' ? 'maximum-wire-variant-utf8-v1' : 'utf8-third-plus-framing-v1' };
}
export function requestImages(body) {
return requestVariants(body).flatMap(value=>(value.messages??value.input??[]).flatMap(message=>Array.isArray(message.content)?message.content.filter(part=>['image_url','input_image'].includes(part.type)).map(part=>part.type==='image_url'?part.image_url?.url:part.image_url):[]));
}
export function imageTokenReserve(body){
return Math.max(0,...requestVariants(body).map(value=>requestImages(value).reduce((total,url)=>{
if(typeof url!=='string'||!url.startsWith('data:image/png;base64,'))throw new Error('视觉请求只允许已校验的PNG发送副本。');
const bytes=Buffer.from(url.slice(22,70),'base64');
if(bytes.length<24||!bytes.subarray(0,8).equals(Buffer.from([137,80,78,71,13,10,26,10]))||bytes.readUInt32BE(8)!==13||bytes.toString('ascii',12,16)!=='IHDR')throw new Error('视觉请求图像头不完整或类型不符。');
const width=bytes.readUInt32BE(16),height=bytes.readUInt32BE(20);
if(!width||!height||Math.max(width,height)>1024)throw new Error('视觉请求超过已校验副本范围。');
return total+Math.max(4096,Math.ceil(width/32)*Math.ceil(height/32)*4);
},0)));
}
export function assertPlannedRequest(body, plan) {
if (!plan) return;
const metrics = requestMetrics(body);
+11
View File
@@ -1,5 +1,16 @@
# Agent Workbench:核心代理能力研究与产品计划
## 2026-11-01 当前任务:1.18 工程附件、视觉与续接
用户授权全阶段开发及及时回顾;来源0d1ab74,分支feat/vision-attachments-1.18。保留正式1.17的原PID/Provider与数据;使用独立样本/端口,不提取Key、不触发真实模型请求;实机及真实推理按既有选择分别待验。
1. [complete] A:复核旧公开样本与源码,旧36771估算无本次必需输入分解,未补造;固定Task所属输入与派生引用契约。
2. [complete] B:PNG/JPEG真解码、方向/限额、原图/副本SHA、撤回/刷新与不可移动原记录;附件12/12通过。
3. [complete] C:两协议实际图像HTTP、vision租约前筛选与随机四色probe、原请求SHA及原SSE停止通过;真实视觉推理另行待验。
4. [complete] D:具体预算分解、绑定原身份的冻结预览与同Task新Run;5/5,A–D最新17/17,完成/未知工具保持。
5. [complete] E:中文桌面1440/390px与真实QA TLS网关5组流程通过;回看修正池成员显示/时间单位,修正轮5组通过。手机为观察/核对/下载,未扩权上传;iPhone新流程待实机。
6. [in_progress] F:含附件工程、完整历史回归、独立发行及保留状态升级、原生回看/证据/Git。
## 2026-10-31 当前任务:1.17 模型协议、流式执行与能力路由
用户授权下一阶段全量开发并及时回顾。基线299fb14/正式1.16.0,在feat/model-protocols-1.17按PLAN-1.17推进。正式PID36552/Provider和数据保持,开发使用自有loopback服务/独立数据/端口,不读取真实Key、不发真实模型请求;真实收益验收继续单列。不新建代理/goal/automation/chat。
+63
View File
@@ -0,0 +1,63 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { fixture,compatibleFixture,completion,until,call } from './helpers.mjs';
import { Provider } from '../src/server/provider.mjs';
import { Runtime } from '../src/server/runtime.mjs';
async function paused(t){
const f=fixture(t),server=await compatibleFixture(t,(_url,body)=>body.messages.some(row=>row.role==='tool')?completion([],'Finished from the original result'):completion([call('original-files','list_files',{path:'',depth:1})]));
const provider=new Provider(),hub=provider.modelHub(f.store),connection=hub.upsert({name:'Owned capacity',baseUrl:server.baseUrl,model:'owned',contextLimit:64000,requiresKey:false});
hub.select({type:'connection',id:connection.id});f.store.saveConfig({...f.store.config,maxSteps:1});
const runtime=new Runtime(f.store,provider);t.after(()=>runtime.stopAll());runtime.start(f.session.id,'Inspect the project, preserving all requirements.');await until(()=>!runtime.isActive(f.session.id));
assert.equal(f.session.status,'paused');assert.equal(f.store.core.tool.size,1);const taskId=f.session.taskId;
f.store.saveConfig({...f.store.config,contextLimit:1000});runtime.resume(f.session.id,'');await until(()=>!runtime.isActive(f.session.id));
assert.equal(f.session.taskId,taskId);assert.equal(f.session.status,'paused');assert.equal(server.requests.length,1);
return {...f,server,provider,hub,connection,runtime};
}
const prepare=f=>f.runtime.budgetResumes().prepare(f.session,{contextLimit:64000,maxRunTokens:200000,maxSteps:3});
test('a budget pause persists concrete text/tool/history/image breakdown and never dispatches an oversized request',async t=>{
const f=await paused(t),run=f.store.core.run.get(f.session.runId),pause=run.budgetPause;
assert.equal(pause.reason,'context_limit');assert.equal(pause.contextLimit,1000);assert.ok(pause.requiredInputTokens>pause.inputBudget);
assert.equal(Object.values(pause.breakdown).reduce((sum,value)=>sum+value,0),pause.requiredInputTokens);
assert.ok(pause.breakdown.toolDefinitionTokens>0);assert.equal(pause.imageReservationTokens,0);assert.equal(f.server.requests.length,1);
const rows=f.store.storage.load().records.filter(row=>row.kind==='run');assert.equal(rows.at(-1).value.budgetPause.requiredInputTokens,pause.requiredInputTokens);
});
test('explicit frozen preview resumes the same Task in a new Run, preserves completed tools and does not change global config or selected model',async t=>{
const f=await paused(t),before=structuredClone(f.store.config),selected=structuredClone(f.hub.state.selected),taskId=f.session.taskId,oldRun=f.session.runId;
const plan=prepare(f);assert.equal(f.server.requests.length,1);assert.equal(plan.completedToolIds.length,1);assert.equal(plan.taskId,taskId);
f.runtime.resumeBudget(f.session.id,{planId:plan.id,sha256:plan.sha256});await until(()=>!f.runtime.isActive(f.session.id));
assert.equal(f.session.status,'completed',JSON.stringify(f.session.messages));assert.equal(f.session.taskId,taskId);assert.notEqual(f.session.runId,oldRun);
assert.equal(f.store.core.run.get(f.session.runId).resumeOf,oldRun);assert.equal(f.store.core.run.get(f.session.runId).resumePlanId,plan.id);
assert.equal(f.store.core.tool.size,1);assert.equal(f.server.requests.length,2);assert.equal(f.store.core.resume_plan.get(plan.id).status,'consumed');
assert.deepEqual(f.store.config,before);assert.deepEqual(f.hub.state.selected,selected);
assert.throws(()=>f.runtime.resumeBudget(f.session.id,{planId:plan.id,sha256:plan.sha256}));
});
test('insufficient budgets, silently clamped capacity and arbitrary config fields reject without a physical request or mutating task budget',async t=>{
const f=await paused(t),before=structuredClone(f.store.core.task.get(f.session.taskId).budget);
for(const input of [{contextLimit:200000},{maxRunTokens:1000},{maxTaskTokens:1000},{apiKey:'forbidden'},{contextLimit:64000.5},{selection:{type:'connection',id:'missing'}}])assert.throws(()=>f.runtime.budgetResumes().prepare(f.session,input));
assert.equal(f.server.requests.length,1);assert.equal(f.store.core.resume_plan.size,0);assert.deepEqual(f.store.core.task.get(f.session.taskId).budget,before);
});
test('changed session, changed registry, expiry and altered frozen preview all require a new explicit preview',async t=>{
const f=await paused(t);let plan=prepare(f);f.store.message(f.session,'system','Owned review changed the revision');
assert.throws(()=>f.runtime.resumeBudget(f.session.id,{planId:plan.id,sha256:plan.sha256}),/已变化/);
plan=prepare(f);f.hub.upsert({...f.hub.connection(f.connection.id),name:'Revised'});
assert.throws(()=>f.runtime.resumeBudget(f.session.id,{planId:plan.id,sha256:plan.sha256}),/已变化/);
plan=prepare(f);f.store.core.resume_plan.get(plan.id).config.contextLimit=200000;
assert.throws(()=>f.runtime.resumeBudget(f.session.id,{planId:plan.id,sha256:plan.sha256}),/已变化/);
plan=prepare(f);f.store.core.resume_plan.get(plan.id).expiresAt=new Date(0).toISOString();
assert.throws(()=>f.runtime.resumeBudget(f.session.id,{planId:plan.id,sha256:plan.sha256}),/已变化/);
assert.equal(f.server.requests.length,1);
});
test('preview preserves unknown invocation status and increasing Task allowance is committed only with confirmed new Run',async t=>{
const f=await paused(t),tool=[...f.store.core.tool.values()][0];tool.requiresVerification=true;f.store.save(f.session);
const task=f.store.core.task.get(f.session.taskId),before=task.budget.maxTokens;
const plan=f.runtime.budgetResumes().prepare(f.session,{contextLimit:64000,maxTaskTokens:before+100000,maxSteps:3});
assert.deepEqual(plan.unknownToolIds,[tool.id]);assert.equal(task.budget.maxTokens,before);
f.runtime.resumeBudget(f.session.id,{planId:plan.id,sha256:plan.sha256});await until(()=>!f.runtime.isActive(f.session.id));
assert.equal(task.budget.maxTokens,before+100000);assert.equal(tool.requiresVerification,true);assert.equal(f.store.core.tool.size,1);
});
+20 -1
View File
@@ -14,6 +14,8 @@ import { CompanionGateway } from '../src/server/companion-gateway.mjs';
import { DeviceRegistry } from '../src/core/companion/device-registry.mjs';
import { CompanionTLS } from '../src/core/companion/tls-authority.mjs';
import { approvalBinding, companionHash } from '../src/shared/contracts/companion.mjs';
import { InputAttachments } from '../src/core/context/input-attachments.mjs';
import { PNG } from 'pngjs';
function setup(t) {
const value = fixture(t), host = { instanceId: randomUUID(), ownerId: randomUUID(), userSid: 'fixture-current-user', pid: process.pid, createdAt: new Date().toISOString() };
@@ -51,7 +53,7 @@ async function running(t) {
...(cookie ? { Cookie: cookie } : {}), ...(origin ? { Origin: origin } : {}), ...(data === undefined ? {} : { 'Content-Type': 'application/json' }), Connection: 'close', ...headers } }, res => {
const chunks = []; res.on('data', chunk => chunks.push(chunk)); res.on('end', () => {
const text = Buffer.concat(chunks).toString('utf8'); let body; try { body = JSON.parse(text); } catch { body = text; }
resolve({ status: res.statusCode, headers: res.headers, body });
resolve({ status: res.statusCode, headers: res.headers, body,bytes:Buffer.concat(chunks) });
});
}); req.on('error', reject); req.end(data === undefined ? undefined : JSON.stringify(data));
});
@@ -354,3 +356,20 @@ test('device revocation destroys its actual authenticated TLS connection', async
assert.ok(socket && !socket.destroyed); f.gateway.revoke(device.id, device.revision);
await until(() => socket.destroyed); agent.destroy();
});
test('companion observes only current Task screenshots, verifies original PNG bytes and loses access immediately on revoke',async t=>{
const f=await running(t),manager=new InputAttachments(f.store),png=new PNG({width:20,height:10});png.data.fill(255);
const row=manager.upload(f.session,{name:'工程截图.png',mediaType:'image/png',base64:PNG.sync.write(png).toString('base64')});
const run=f.store.beginRun(f.session,'Inspect',false,f.store.config,{inputAttachments:manager.validateSelection(f.session,[row.id])});
f.session.status='paused';f.store.finishRun(f.session,run,'context_limit');const id=f.store.core.task.get(run.taskId).attachmentIds[0];
const {cookie,device}=await f.pair(),route='/mobile-api/sessions/'+f.session.id+'/input-attachments/'+id;
const image=await f.request(route+'/image',undefined,{cookie});assert.equal(image.status,200);assert.equal(companionHash(image.bytes),row.sentSha256);
const original=await f.request(route+'/original',undefined,{cookie});assert.equal(original.status,200);assert.equal(companionHash(original.bytes),row.sha256);
const projection=await f.request('/mobile-api/sessions/'+f.session.id,undefined,{cookie});assert.equal(projection.body.inputAttachments[0].id,id);
assert.equal(projection.body.inputAttachments[0].originalArtifactId,undefined);assert.equal(projection.body.providerMessages,undefined);
const draft=manager.upload(f.session,{name:'draft.png',mediaType:'image/png',base64:PNG.sync.write(png).toString('base64')});
assert.equal((await f.request('/mobile-api/sessions/'+f.session.id+'/input-attachments/'+draft.id+'/image',undefined,{cookie})).status,404);
const other=f.store.createSession(f.project.id);assert.notEqual((await f.request('/mobile-api/sessions/'+other.id+'/input-attachments/'+id+'/image',undefined,{cookie})).status,200);
assert.equal((await f.request(route+'/image',{}, {cookie})).status,404);
f.registry.revoke(device.id,device.revision);assert.equal((await f.request(route+'/image',undefined,{cookie})).status,401);
});
+152
View File
@@ -0,0 +1,152 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import http from 'node:http';
import { createHash } from 'node:crypto';
import { PNG } from 'pngjs';
import jpeg from 'jpeg-js';
import { fixture,compatibleFixture,completion,until,assertToolPairs } from './helpers.mjs';
import { Store } from '../src/server/store.mjs';
import { Runtime } from '../src/server/runtime.mjs';
import { Provider } from '../src/server/provider.mjs';
import { createRequestHandler } from '../src/server/app.mjs';
import { InputAttachments,validateImage,IMAGE_LIMITS } from '../src/core/context/input-attachments.mjs';
import { verifyPlanEvidence } from '../src/core/context/request-plan.mjs';
import { completionBody,requestMetrics,requestImages } from '../src/shared/contracts/model-request.mjs';
export function pngInput(width=96,height=64) {
const png=new PNG({width,height});
for(let p=0;p<png.data.length;p+=4)png.data.set([34,110,180,255],p);
return {name:'工程截图.png',mediaType:'image/png',base64:PNG.sync.write(png).toString('base64')};
}
const sha=bytes=>createHash('sha256').update(bytes).digest('hex');
const withBytes=(bytes,mediaType='image/png')=>({name:'image.'+(mediaType==='image/png'?'png':'jpg'),mediaType,base64:bytes.toString('base64')});
test('PNG bytes are fully decoded, metadata-free and bounded; JPEG EXIF orientation is applied to the sent PNG',()=>{
const value=validateImage(pngInput(2048,512));
assert.equal(value.sentWidth,1024);assert.equal(value.sentHeight,256);assert.ok(value.sent.length<=IMAGE_LIMITS.sentBytes);
const rgba=Buffer.alloc(24*48*4);for(let p=0;p<rgba.length;p+=4)rgba.set([255,0,0,255],p);
const original=jpeg.encode({width:24,height:48,data:rgba},90).data;
const exif=Buffer.from('45786966000049492a0008000000010012010300010000000600000000000000','hex');
const segment=Buffer.alloc(4);segment[0]=255;segment[1]=225;segment.writeUInt16BE(exif.length+2,2);
const rotated=validateImage(withBytes(Buffer.concat([original.subarray(0,2),segment,exif,original.subarray(2)]),'image/jpeg'));
assert.equal(rotated.orientation,6);assert.equal(rotated.sentWidth,48);assert.equal(rotated.sentHeight,24);
assert.equal(rotated.sent.includes(Buffer.from('Exif')),false);assert.equal(rotated.width,24);assert.equal(rotated.height,48);
});
test('forged type, short headers, CRC damage, incomplete chunks, trailing payloads, animation and dimension bombs reject',()=>{
const bytes=Buffer.from(pngInput().base64,'base64');
for(const length of [0,1,8,16,22,24,32,bytes.length-1])assert.throws(()=>validateImage(withBytes(bytes.subarray(0,length))));
assert.throws(()=>validateImage(withBytes(bytes,'image/jpeg')),/类型不符/);
const corrupt=Buffer.from(bytes);corrupt[29]^=1;assert.throws(()=>validateImage(withBytes(corrupt)),/解码/);
assert.throws(()=>validateImage(withBytes(Buffer.concat([bytes,Buffer.from('payload')]))),/尾部/);
const animation=Buffer.from(bytes);animation.write('acTL',37,'ascii');assert.throws(()=>validateImage(withBytes(animation)),/静态/);
const huge=Buffer.from(bytes);huge.writeUInt32BE(9000,16);assert.throws(()=>validateImage(withBytes(huge)),error=>error.status===413);
assert.throws(()=>validateImage({...pngInput(),name:'../secret.png'}),/文件名/);
assert.throws(()=>validateImage({...pngInput(),base64:'%%%'}),/编码/);
assert.throws(()=>validateImage(withBytes(Buffer.alloc(IMAGE_LIMITS.bytes+1))),error=>error.status===413);
});
test('draft image ownership, withdrawal, reload and atomic Task binding retain original SHA and original bytes',t=>{
const f=fixture(t),manager=new InputAttachments(f.store),input=pngInput(),row=manager.upload(f.session,input);
assert.equal(row.taskId,null);assert.equal(row.runId,null);assert.equal(row.sha256,sha(Buffer.from(input.base64,'base64')));
assert.deepEqual(manager.read(f.session,row.id,{original:true}).bytes,Buffer.from(input.base64,'base64'));
const other=f.store.createSession(f.project.id);assert.throws(()=>manager.read(other,row.id),/归属|所属|不存在|不属于/);
const selected=manager.validateSelection(f.session,[row.id]),run=f.store.beginRun(f.session,'Inspect screenshot',false,f.store.config,{inputAttachments:selected});
const boundId=manager.get(f.session,row.id).boundAttachmentId;
assert.equal(manager.get(f.session,row.id).status,'consumed');assert.equal(manager.get(f.session,boundId).taskId,run.taskId);assert.equal(manager.images(f.session,f.store.core.task.get(run.taskId)).length,1);
assert.throws(()=>manager.remove(f.session,row.id),/已发送/);
const draft=manager.upload(f.session,pngInput(64,64));manager.remove(f.session,draft.id);assert.throws(()=>manager.read(f.session,draft.id),error=>error.status===410);
f.store.close();const restored=new Store(f.data);f.onCleanup(()=>restored.close());const reloaded=new InputAttachments(restored),session=restored.session(f.session.id);
assert.equal(reloaded.images(session,restored.core.task.get(run.taskId))[0].sha256,row.sentSha256);
assert.equal(reloaded.list(session).length,1);
});
test('a failed session transaction restores draft status and cannot leave a Run consuming the attachment',t=>{
const f=fixture(t),manager=new InputAttachments(f.store),row=manager.upload(f.session,pngInput()),save=f.store.storage.save;
f.store.storage.save=()=>{throw new Error('owned transaction failure');};
assert.throws(()=>f.store.beginRun(f.session,'Inspect',false,f.store.config,{inputAttachments:manager.validateSelection(f.session,[row.id])}),/transaction failure/);
f.store.storage.save=save;assert.equal(manager.get(f.session,row.id).status,'draft');assert.equal(f.store.core.run.size,0);assert.equal(f.session.runId,undefined);
});
test('draft limits, duplicate selection, source changes and cross-Task association reject before dispatch',t=>{
const f=fixture(t),manager=new InputAttachments(f.store),row=manager.upload(f.session,pngInput());
assert.throws(()=>manager.validateSelection(f.session,[row.id,row.id]),/一张/);
const artifact=f.store.core.artifact.get(row.sentArtifactId),file=path.join(f.store.artifactStore.root,artifact.relative);
fs.appendFileSync(file,'tampered');assert.throws(()=>manager.validateSelection(f.session,[row.id]),/校验失败/);
for(let i=1;i<8;i++)manager.upload(f.session,pngInput(i+10,10));
assert.throws(()=>manager.upload(f.session,pngInput(20,20)),/已满/);
});
test('demo and legacy paths refuse image dispatch without creating a Task or consuming the draft',async t=>{
const f=fixture(t),provider=new Provider(),runtime=new Runtime(f.store,provider),row=runtime.inputAttachments().upload(f.session,pngInput());
assert.throws(()=>runtime.start(f.session.id,'Inspect',false,{attachmentIds:[row.id]}),/演示/);
assert.equal(f.store.core.run.size,0);assert.equal(runtime.inputAttachments().get(f.session,row.id).status,'draft');
await assert.rejects(()=>provider.complete({...f.store.config,inputImages:[{dataUrl:'not-sent'}]},[],null),/视觉能力/);
});
for(const protocol of ['chat-completions','responses'])test(protocol+' sends one owned image per actual request, pairs original tools and verifies exact sealed bytes',async t=>{
const f=fixture(t),server=await compatibleFixture(t,(_url,body,requests)=>{
assert.equal(requestImages(body).length,1);
if(protocol==='responses')return {body:{status:'completed',output:requests.length===1?[{type:'function_call',call_id:'image_files',name:'list_files',arguments:'{"path":"","depth":1}'}]
:[{type:'message',role:'assistant',content:[{type:'output_text',text:'截图与工程已核对'}]}],usage:{input_tokens:300,output_tokens:20,total_tokens:320}}};
return completion(requests.length===1?[{id:'image_files',type:'function',function:{name:'list_files',arguments:'{"path":"","depth":1}'}}]:[],requests.length===1?'':'截图与工程已核对');
});
const provider=new Provider(),hub=provider.modelHub(f.store),connection=hub.upsert({name:'Owned visual',model:'fixture',baseUrl:server.baseUrl,protocol,requiresKey:false,contextLimit:64000,capabilityDeclarations:{vision:'supported'}});
hub.select({type:'connection',id:connection.id});const runtime=new Runtime(f.store,provider);t.after(()=>runtime.stopAll());
const row=runtime.inputAttachments().upload(f.session,pngInput());runtime.start(f.session.id,'只根据此图核对本工程',false,{attachmentIds:[row.id]});await until(()=>!runtime.isActive(f.session.id),15000);
assert.equal(f.session.status,'completed',JSON.stringify(f.session.messages));assert.equal(server.requests.length,2);assertToolPairs(f.session.providerMessages);
assert.equal(JSON.stringify(f.session.providerMessages).includes('data:image'),false);assert.deepEqual(f.session.messages.find(value=>value.role==='user').attachmentIds,f.store.core.task.get(f.session.taskId).attachmentIds);
for(const plan of f.store.core.context_plan.values()) {
assert.equal(plan.imageCount,1);assert.ok(plan.imageReservationTokens>=4096);assert.doesNotThrow(()=>verifyPlanEvidence(f.store,f.session,plan));
plan.inputImages[0].sha256='0'.repeat(64);assert.throws(()=>verifyPlanEvidence(f.store,f.session,plan),/图片/);plan.inputImages[0].sha256=row.sentSha256;
}
});
test('mixed pool excludes unknown vision before lease and sends zero HTTP to the incompatible member',async t=>{
const f=fixture(t),bad=await compatibleFixture(t,()=>{throw new Error('must not dispatch');}),good=await compatibleFixture(t,()=>completion([],'Done'));
const provider=new Provider(),hub=provider.modelHub(f.store),a=hub.upsert({name:'Text',model:'text',baseUrl:bad.baseUrl,requiresKey:false,contextLimit:64000}),
b=hub.upsert({name:'Vision',model:'vision',baseUrl:good.baseUrl,requiresKey:false,contextLimit:64000,capabilityDeclarations:{vision:'supported'}});
const pool=hub.pool({name:'Mixed',members:[{connectionId:a.id},{connectionId:b.id}]});hub.select({type:'pool',id:pool.id});
const runtime=new Runtime(f.store,provider);t.after(()=>runtime.stopAll());const row=runtime.inputAttachments().upload(f.session,pngInput());
runtime.start(f.session.id,'Inspect',false,{attachmentIds:[row.id]});await until(()=>!runtime.isActive(f.session.id));
assert.equal(f.session.status,'completed');assert.equal(bad.requests.length,0);assert.equal(good.requests.length,1);
const attempt=hub.view().attempts[0];assert.ok(attempt.requirements.includes('vision'));assert.ok(attempt.rejections.some(item=>item.connectionId===a.id&&item.capability==='vision'));
});
test('vision probe requires correct randomized pixel order and evidence expires when the connection revision changes',async t=>{
const f=fixture(t),server=await compatibleFixture(t,(_url,body)=>{
const png=PNG.sync.read(Buffer.from(requestImages(body)[0].split(',')[1],'base64'));
const names=[[230,0,0,'RED'],[0,180,0,'GREEN'],[0,0,230,'BLUE'],[240,220,0,'YELLOW']];
const result=[[10,10],[100,10],[10,100],[100,100]].map(([x,y])=>names.find(rgb=>rgb.slice(0,3).every((value,c)=>png.data[(y*128+x)*4+c]===value))[3]);
return completion([],result.join(','));
});
const provider=new Provider(),hub=provider.modelHub(f.store),connection=hub.upsert({name:'Probe',model:'owned',baseUrl:server.baseUrl,requiresKey:false});
await hub.probe(connection.id,'vision');assert.equal(hub.view().connections.find(value=>value.id===connection.id).capabilities.vision,'verified');
hub.upsert({...hub.connection(connection.id),name:'Changed'});assert.equal(hub.view().connections.find(value=>value.id===connection.id).capabilities.vision,'unknown');
const failed=await compatibleFixture(t,()=>completion([],'OK')),other=hub.upsert({name:'Blind',model:'owned',baseUrl:failed.baseUrl,requiresKey:false});
await assert.rejects(()=>hub.probe(other.id,'vision'),/未正确识别/);assert.equal(hub.view().connections.find(value=>value.id===other.id).capabilities.vision,'unknown');
});
test('HTTP upload/read/withdraw uses session authorization, returns byte SHA and refuses unknown ownership',async t=>{
const f=fixture(t),provider=new Provider(),runtime=new Runtime(f.store,provider),server=http.createServer();
server.on('request',createRequestHandler({appDirectory:process.cwd(),server,store:f.store,provider,runtime,token:'owned',clients:new Set(),started:Date.now(),getPort:()=>server.address().port}));
await new Promise(resolve=>server.listen(0,'127.0.0.1',resolve));t.after(()=>new Promise(resolve=>{server.closeAllConnections();server.close(resolve);}));
const root='http://127.0.0.1:'+server.address().port,base='/api/sessions/'+f.session.id+'/input-attachments';
const request=(route,method='GET',body,token='owned')=>fetch(root+route,{method,headers:{'X-Workbench-Token':token,'Content-Type':'application/json'},...(body?{body:JSON.stringify(body)}:{})});
assert.equal((await request(base,'POST',pngInput(),'invalid')).status,403);
const uploaded=await request(base,'POST',pngInput());assert.equal(uploaded.status,201);const row=await uploaded.json();
const image=await request(base+'/'+row.id+'/image');assert.equal(image.headers.get('X-Content-SHA256'),row.sentSha256);assert.equal(sha(Buffer.from(await image.arrayBuffer())),row.sentSha256);
const other=f.store.createSession(f.project.id);assert.equal((await request('/api/sessions/'+other.id+'/input-attachments/'+row.id+'/image')).status,404);
assert.equal((await request(base+'/'+row.id,'DELETE',{})).status,200);assert.equal((await request(base+'/'+row.id+'/image')).status,410);
});
test('image accounting excludes Base64 as text but seals every original request byte and reserves image input separately',()=>{
const value=validateImage(pngInput()),image={id:'owned',sha256:sha(value.sent),width:value.sentWidth,height:value.sentHeight,dataUrl:'data:image/png;base64,'+value.sent.toString('base64')};
const config={protocol:'responses',model:'owned',maxOutputTokens:512,inputImages:[image]};
const body=completionBody(config,[{role:'user',content:'Inspect'}],[]),metrics=requestMetrics(body);
assert.equal(metrics.bytes,Buffer.byteLength(JSON.stringify(body)));assert.equal(metrics.sha256,sha(JSON.stringify(body)));assert.equal(metrics.imageCount,1);
assert.equal(metrics.imageEstimate,'local-reservation-not-provider-billing');assert.equal(metrics.imageReservationTokens,4096);
assert.ok(metrics.estimatedInputTokens>4096);assert.equal(requestImages(body).length,1);
});