feat(openclaw-plugin): add image preview URLs#2798
Draft
qin-ctx wants to merge 1 commit into
Draft
Conversation
Add optional preview_url enrichment for recalled OpenViking image resources so agents can surface temporary frontend preview links when explicitly enabled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
viking://resources/...下的图片时,可调用 OpenViking/api/v1/content/preview_url获取临时预览地址。enableResourcePreviewUrls,默认false;不开启时不会调用预览接口,也不会在ov_search表格中显示空的preview_url列,安装/setup 流程不暴露该配置。auto-recall注入上下文、memory_recall工具输出、ov_search表格与details.resources[].preview_url。preview-url.ts在发布包和远端安装路径中可用。背景
OpenViking 服务新增了内容预览接口:
成功响应:
{ "status": "ok", "result": { "preview_url": "https://tos.example.com/openviking/gallery/photo.png?X-Amz-Signature=***" }, "time": 0.012 }插件侧需要在召回到图片资源时,把该临时预览地址透出给模型或工具调用方。最终回答中是否展示 URL 仍由业务/模型回答层决定;OpenViking 插件只负责把 URL 放到可见上下文或工具输出中。
数据结构
1. 召回结果项
FindResultItem新增可选字段:字段语义:
preview_url是本次运行临时补充的预览地址。enableResourcePreviewUrls: true且命中图片资源时才会尝试补充。2. 预览接口返回结构
客户端新增方法:
它复用现有
request(),因此继续带上 API Key、租户头和X-OpenViking-Actor-Peer。3. 配置结构
MemoryOpenVikingConfig新增隐藏开关:默认值:
{ "enableResourcePreviewUrls": false }手工开启示例:
{ "plugins": { "entries": { "openviking": { "config": { "mode": "remote", "baseUrl": "http://127.0.0.1:1933", "apiKey": "${OPENVIKING_API_KEY}", "recallTargetTypes": ["resource", "user", "agent"], "enableResourcePreviewUrls": true } } } } }该字段没有加入
uiHints,因此不会在安装/setup 流程中暴露。处理流程
auto-recall
代码流程是:
withPreviewUrls()的规则:viking://resources/开头的资源。.png、.jpg、.jpeg、.webp、.gif、.bmp、.svg、.avif。viking://resources/gallery/photo.png#chunk-1会用viking://resources/gallery/photo.png请求。Claw 实际看到的上下文形态
这里不是把 JSON 字段直接给 Claw。
FindResultItem.preview_url是插件内部字段,最终会被formatMemoryLine()渲染成<preview_url>...</preview_url>文本。buildRecallContextBlock(memoryLines)实际结构是:因此 topK 多条结果会展开成多条
memoryLines。开启预览 URL 且第一条图片成功补到 URL 时,latest user message 前面会 prepend 类似内容:不开启
enableResourcePreviewUrls,或者没有图片资源成功补到 URL 时,结构保持原样,不会出现提示行和<preview_url>:memory_recall
memory_recall也会在开关开启时对选中的图片资源补preview_url,然后通过buildMemoryLinesWithBudget()输出。例如:ov_search
ov_search在开关开启且资源命中图片 URL 时,会在表格中按需增加preview_url列,并在结构化 details 中返回:输出示例:
不开启时不会显示空列:
Test plan
npm test -- --run tests/ut/config.test.ts tests/ut/client.test.ts tests/ut/build-memory-lines.test.ts tests/ut/plugin-query-formatters.test.ts tests/ut/plugin-modules.test.tsnpm test -- --run tests/ut/manifest-contracts.test.ts tests/ut/setup-modules.test.ts tests/ut/setup-config-writer.test.ts tests/ut/setup-command.test.ts tests/ut/setup-cli.test.tsnpm run typechecknpm run buildgit diff --check