mirror of
https://git.openapi.site/https://github.com/desirecore/agent-desirecore.git
synced 2026-12-05 12:49:39 +08:00
feat: 完善应用运行与成果恢复知识
This commit is contained in:
1 parent
54e5286729
commit
cbc00707c3
15 files changed
+280
-48
No files matched your search
@@ -53,8 +53,8 @@
|
||||
{
|
||||
"path": "ui/app.js",
|
||||
"role": "ui",
|
||||
"sha256": "3bc131e1afd3063e13373c6b64f86f9202a1bda78ce606e9137133c6e60abdae",
|
||||
"size": 5204
|
||||
"sha256": "5ece9785b32efa8d30531354a8775b93ee1c4b6a470ffc37e86625d9c01b2b35",
|
||||
"size": 9111
|
||||
},
|
||||
{
|
||||
"path": "ui/bridge.js",
|
||||
@@ -65,19 +65,19 @@
|
||||
{
|
||||
"path": "ui/index.html",
|
||||
"role": "ui",
|
||||
"sha256": "e3c055e13440a8aa472bf2ca73a49c5af26eda0061e17d02a44a3c3de665c3b1",
|
||||
"size": 2282
|
||||
"sha256": "83de1fc2216834dc4326d607af45f2174609772b08a03acf6a98197363eec5a8",
|
||||
"size": 2624
|
||||
},
|
||||
{
|
||||
"path": "说明.md",
|
||||
"role": "documentation",
|
||||
"sha256": "6a0feb6f009f91430e0e809da6a4f4e81cd12b4e424f250b6adbaff07f9923dd",
|
||||
"size": 1864
|
||||
"sha256": "4d7acded6df683128241eefa6c822e00e84a4299d4e018f8087e2274b8e9be60",
|
||||
"size": 2542
|
||||
}
|
||||
],
|
||||
"source": {
|
||||
"kind": "worktree",
|
||||
"sha256": "83af9d981f282ca2ceb4103604b33e6cae07056d81a9718b72f13c5ab0b8527d"
|
||||
"sha256": "dcc8715ce3cbbae44a067fc579ab5f232c36512651f13015121b022e71c28bba"
|
||||
},
|
||||
"supportedPlatforms": [
|
||||
"darwin",
|
||||
@@ -91,7 +91,8 @@
|
||||
"release",
|
||||
"web-bundle",
|
||||
"bridge",
|
||||
"data"
|
||||
"data",
|
||||
"view-state"
|
||||
],
|
||||
"dataContract": {
|
||||
"schemaVersion": 1,
|
||||
@@ -121,8 +122,19 @@
|
||||
"publishSelection",
|
||||
"requestWork",
|
||||
"lookupRequest",
|
||||
"readWork"
|
||||
"readWork",
|
||||
"controlWork",
|
||||
"openResource",
|
||||
"saveViewState"
|
||||
],
|
||||
"viewStateContract": {
|
||||
"schemaVersion": 1,
|
||||
"keys": [
|
||||
"selection"
|
||||
],
|
||||
"maxBytes": 1024,
|
||||
"formatVersion": "1"
|
||||
},
|
||||
"instructionsPath": "说明.md",
|
||||
"releaseDigest": "6ff9f35e8a14a2f35c4a0b1ee84755cfc63ef6e4d16860bb9e420b4514ae04b2"
|
||||
"releaseDigest": "d7c42fb1c8165d972e0a09fe00be53c58cdc4ec5f6408ac646a5b7add337c06a"
|
||||
}
|
||||
@@ -1,13 +1,79 @@
|
||||
{
|
||||
"description": "显式收录教学程序材料,业务notes.json只属于实例数据根,不进入发行包。",
|
||||
"delivery": { "type": "web-bundle", "entrypoints": [{ "entrypointId": "main", "path": "ui/index.html" }] },
|
||||
"supportedPlatforms": ["darwin", "win32", "linux", "web"],
|
||||
"requiredCapabilities": ["app-authoring-v1", "release", "web-bundle", "bridge", "data"],
|
||||
"bridgeCapabilities": ["connect", "capabilities", "readData", "saveData", "lookupDataMutation", "publishSelection", "requestWork", "lookupRequest", "readWork"],
|
||||
"delivery": {
|
||||
"type": "web-bundle",
|
||||
"entrypoints": [
|
||||
{
|
||||
"entrypointId": "main",
|
||||
"path": "ui/index.html"
|
||||
}
|
||||
]
|
||||
},
|
||||
"supportedPlatforms": [
|
||||
"darwin",
|
||||
"win32",
|
||||
"linux",
|
||||
"web"
|
||||
],
|
||||
"requiredCapabilities": [
|
||||
"app-authoring-v1",
|
||||
"release",
|
||||
"web-bundle",
|
||||
"bridge",
|
||||
"data",
|
||||
"view-state"
|
||||
],
|
||||
"bridgeCapabilities": [
|
||||
"connect",
|
||||
"capabilities",
|
||||
"readData",
|
||||
"saveData",
|
||||
"lookupDataMutation",
|
||||
"publishSelection",
|
||||
"requestWork",
|
||||
"lookupRequest",
|
||||
"readWork",
|
||||
"controlWork",
|
||||
"openResource",
|
||||
"saveViewState"
|
||||
],
|
||||
"dataContractPath": "data-contract.json",
|
||||
"files": [
|
||||
{ "path": "application.json", "role": "definition" }, { "path": "ui/index.html", "role": "ui" },
|
||||
{ "path": "ui/bridge.js", "role": "ui" }, { "path": "ui/app.js", "role": "ui" },
|
||||
{ "path": "data-contract.json", "role": "data-contract" }, { "path": "说明.md", "role": "documentation" }, { "path": "LICENSE", "role": "license" }
|
||||
]
|
||||
{
|
||||
"path": "application.json",
|
||||
"role": "definition"
|
||||
},
|
||||
{
|
||||
"path": "ui/index.html",
|
||||
"role": "ui"
|
||||
},
|
||||
{
|
||||
"path": "ui/bridge.js",
|
||||
"role": "ui"
|
||||
},
|
||||
{
|
||||
"path": "ui/app.js",
|
||||
"role": "ui"
|
||||
},
|
||||
{
|
||||
"path": "data-contract.json",
|
||||
"role": "data-contract"
|
||||
},
|
||||
{
|
||||
"path": "说明.md",
|
||||
"role": "documentation"
|
||||
},
|
||||
{
|
||||
"path": "LICENSE",
|
||||
"role": "license"
|
||||
}
|
||||
],
|
||||
"viewStateContract": {
|
||||
"schemaVersion": 1,
|
||||
"keys": [
|
||||
"selection"
|
||||
],
|
||||
"maxBytes": 1024,
|
||||
"formatVersion": "1"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { connectBridge } from './bridge.js'
|
||||
const element = id => document.getElementById(id)
|
||||
let bridge, connection, etag, notes = [], selected, pendingSave, pendingWork
|
||||
let bridge, connection, etag, notes = [], selected, rememberedNoteId, pendingSave, pendingWork, pendingViewState, viewRevision = 'none'
|
||||
const status = message => { element('status').textContent = message }
|
||||
function render() {
|
||||
element('notes').replaceChildren()
|
||||
@@ -14,7 +14,7 @@ async function read() {
|
||||
const result = await bridge.call('readData',{key:'notes'})
|
||||
const value = result.exists ? JSON.parse(result.content) : {schemaVersion:1,notes:[]}
|
||||
if (value.schemaVersion !== 1 || !Array.isArray(value.notes)) throw new Error('notes_format_unsupported')
|
||||
notes = value.notes; etag = result.etag; selected = notes.find(note => note.id === selected?.id); render()
|
||||
notes = value.notes; etag = result.etag; selected = notes.find(note => note.id === (selected?.id ?? rememberedNoteId)); render()
|
||||
status('已读取当前实例的数据。')
|
||||
}
|
||||
async function save() {
|
||||
@@ -56,13 +56,59 @@ element('request').addEventListener('click',async () => {
|
||||
})
|
||||
element('work').addEventListener('click',async () => {
|
||||
if (!pendingWork) return
|
||||
try { element('work-status').textContent = JSON.stringify(await bridge.call('lookupRequest',{clientRequestId:pendingWork.clientRequestId}),null,2) }
|
||||
try { element('work-status').textContent = JSON.stringify(await bridge.call('lookupRequest',{agentId:pendingWork.agentId,clientRequestId:pendingWork.clientRequestId}),null,2) }
|
||||
catch (error) { element('work-status').textContent = error.message }
|
||||
})
|
||||
element('progress').addEventListener('click',async () => {
|
||||
if (!pendingWork) return
|
||||
try {
|
||||
const snapshot = await bridge.call('readWork',{agentId:pendingWork.agentId,clientRequestId:pendingWork.clientRequestId})
|
||||
element('work-status').textContent = `准入:${snapshot.admission};执行:${snapshot.execution}。执行完成后仍需核读实际成果。`
|
||||
element('cancel').disabled = !connection.capabilities?.includes('controlWork') || !snapshot.availableActions?.includes('abort')
|
||||
element('results').replaceChildren()
|
||||
for (const [index, resource] of (snapshot.resources ?? []).entries()) {
|
||||
const row = document.createElement('li'), button = document.createElement('button')
|
||||
button.textContent = `${resource.role === 'evidence' ? '查看证据' : '打开成果'} ${index + 1}`
|
||||
button.disabled = !connection.capabilities?.includes('openResource')
|
||||
button.addEventListener('click',async () => {
|
||||
try {
|
||||
const result = await bridge.call('openResource',{locator:resource.locator})
|
||||
element('work-status').textContent = result.state === 'navigation-requested' ? '已请求平台定位该成果,文件正文继续由原授权入口核验。' : result.opened === true ? '平台已打开获授权对象。' : '定位结果尚未确认。'
|
||||
} catch (error) { element('work-status').textContent = `成果未打开:${error.message}` }
|
||||
})
|
||||
row.append(button); element('results').append(row)
|
||||
}
|
||||
} catch (error) { element('work-status').textContent = `进度暂不可读:${error.message}` }
|
||||
})
|
||||
element('cancel').addEventListener('click',async () => {
|
||||
if (!pendingWork) return
|
||||
try {
|
||||
const receipt = await bridge.call('controlWork',{agentId:pendingWork.agentId,clientRequestId:pendingWork.clientRequestId,action:'abort'})
|
||||
element('work-status').textContent = `原工作停止结果:${receipt.status}。requested 仅表示停止意图已接纳,结果未知时沿原请求查询。`
|
||||
} catch (error) { element('work-status').textContent = `停止未确认:${error.message}` }
|
||||
})
|
||||
element('remember').addEventListener('click',async () => {
|
||||
if (!pendingViewState) pendingViewState = {schemaVersion:1,key:'selection',state:JSON.stringify({selectedNoteId:selected?.id ?? null}),
|
||||
persistence:'device',expectedRevision:viewRevision,mutationId:crypto.randomUUID()}
|
||||
try {
|
||||
const receipt = await bridge.call('saveViewState',pendingViewState)
|
||||
if (receipt.persistence !== 'device' || typeof receipt.revision !== 'string') throw new Error('view_save_result_unknown')
|
||||
viewRevision = receipt.revision; pendingViewState = undefined
|
||||
element('view-status').textContent = '已在这台设备记住所选位置。笔记正文仍由实例数据单独保存。'
|
||||
} catch (error) { element('view-status').textContent = `位置保存未确认:${error.message}。再次点击重试原ID、正文与修订,不覆盖其他更新。` }
|
||||
})
|
||||
try {
|
||||
bridge = await connectBridge(); connection = await bridge.call('connect')
|
||||
const remembered = connection.viewStates?.find(value => value.key === 'selection' && value.persistence === 'device')
|
||||
if (remembered) {
|
||||
viewRevision = remembered.revision
|
||||
try { const state = JSON.parse(remembered.state); if (typeof state.selectedNoteId === 'string') rememberedNoteId = state.selectedNoteId } catch { element('view-status').textContent = '此前位置格式不可读,已保留原偏好。' }
|
||||
}
|
||||
bridge.onEvent(event => { if (event?.type === 'work-accepted' && event.clientRequestId === pendingWork?.clientRequestId)
|
||||
element('work-status').textContent = `平台接纳回执:${JSON.stringify(event.result)}。通过原请求继续查询,接纳不等于业务完成。` })
|
||||
await read(); element('save').disabled = !connection.capabilities?.includes('saveData'); element('refresh').disabled = false
|
||||
element('request').disabled = !connection.capabilities?.includes('requestWork')
|
||||
element('progress').disabled = !connection.capabilities?.includes('readWork')
|
||||
element('remember').disabled = !connection.capabilities?.includes('saveViewState') || connection.deviceViewState?.state !== 'available'
|
||||
if (element('remember').disabled) element('view-status').textContent = `设备位置记忆不可用:${connection.deviceViewState?.reason ?? '未授权'}。业务笔记仍可按实际数据能力保存。`
|
||||
} catch (error) { status(`当前持久数据或协作能力不可用:${error.message}。未保存任何业务数据。`) }
|
||||
@@ -8,7 +8,8 @@
|
||||
<section><label for="note">新笔记</label><textarea id="note" placeholder="输入一条笔记"></textarea>
|
||||
<button id="save" class="primary" disabled>保存笔记</button><button id="refresh" disabled>读取最新版本</button><button id="recover" disabled>查询原保存</button>
|
||||
<output id="status" aria-live="polite">正在连接应用宿主…</output><ul id="notes"></ul></section>
|
||||
<section><button id="remember" disabled>在这台设备记住所选位置</button><output id="view-status" aria-live="polite">只保存所选笔记的位置,不保存笔记正文。</output></section>
|
||||
<section><h2>与 Agent 协作</h2><p>教学示例使用实际 Agent ID;应用可以自行设计选择器。工作须由平台控件接纳。</p>
|
||||
<label for="agent">本次 Agent ID</label><input id="agent" placeholder="由当前授权的 Agent 配置提供">
|
||||
<button id="request" disabled>交给 Agent 讨论选中笔记</button><button id="work" disabled>查询原请求</button><output id="work-status" aria-live="polite">尚未准备请求。</output></section>
|
||||
<button id="request" disabled>交给 Agent 讨论选中笔记</button><button id="work" disabled>查询原请求</button><button id="progress" disabled>读取原工作与成果</button><button id="cancel" disabled>停止原工作</button><output id="work-status" aria-live="polite">尚未准备请求。</output><ul id="results"></ul></section>
|
||||
<script type="module" src="./app.js"></script></html>
|
||||
@@ -9,3 +9,7 @@
|
||||
“交给 Agent”先准备提案。真正提交在平台控件上确认,再从 work-accepted 或同请求 lookup 得到真实接纳/Task 状态;页面不能自己签 intent。正式实例引用已声明notes来源文件:namespace为data-files、objectId为notes、revision为readData的真实ETag,平台不猜测notes JSON内部业务schema。选中笔记的稳定id、记录版本及可见文字留在summary;授权范围明确包含读取来源文件并仅讨论所选记录。Agent读取真实文件后定位记录,不能把未实现的notes业务对象owner说成已支持。预览只发讨论摘要,不借正式实例身份。
|
||||
|
||||
更新保持原安装/data scope并先核验 notes-v1兼容;程序回退不恢复旧笔记。卸载默认保留业务数据。示例无需第三方服务,调用 Agent 仍取决于真实算力连接、权限和额度。平台能力未开放或未发行时保持不可用并说明原因。
|
||||
|
||||
工作查询保留原 agentId 和 clientRequestId;只有 readWork 返回的真实 Task 成果 locator 才可交 openResource 定位,navigation-requested 不等于文件正文已打开。当前 controlWork 只按 availableActions 支持 abort;未关联 Task 的工作成果列表可以为空,不凭 UI 编造 Task。
|
||||
|
||||
用户可显式选择“在这台设备记住所选位置”。示例 viewStateContract 只允许 selection 键并限制 1024 字节,不保存笔记正文;需实际 saveViewState grant,设备保存保持原 mutationId、expectedRevision 和正文。能力缺失时保持业务数据与视图偏好分别报告,预览不借正式设备状态。
|
||||
Reference in new issue
Block a user