feat: 提供工作台应用开发发布技能与示例

This commit is contained in:
yige committed 2026-10-13 16:48:14 +08:00
1 parent 6cbc736a69
commit 0204c31f54
27 files changed
+874 -5

No files matched your search

@@ -0,0 +1,9 @@
MIT License
Copyright (c) 2026 DesireCore
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,128 @@
{
"schemaVersion": 1,
"canonicalization": "app-release-c14n-v1",
"definition": {
"id": "personal-notes-workbench",
"name": "个人笔记工作台",
"version": "1.0.0",
"productKind": "application",
"icon": "Notebook",
"iconLetter": "记",
"entrypoints": [
{
"id": "main",
"name": "笔记",
"kind": "embedded-web",
"serviceRef": "workbench:main"
}
],
"placementPolicy": {
"showInMyApps": true,
"allowNavPin": true,
"allowAgentBinding": true
}
},
"delivery": {
"type": "web-bundle",
"entrypoints": [
{
"entrypointId": "main",
"path": "ui/index.html"
}
]
},
"files": [
{
"path": "LICENSE",
"role": "license",
"sha256": "e863481f423546e8984c07ffa00609d338b7f7533f60e89392301028163aa89e",
"size": 1067
},
{
"path": "application.json",
"role": "definition",
"sha256": "6f173d257bbb07d85deefe203a18741ec31fed27f244dbce6e37ef42f6662a9a",
"size": 371
},
{
"path": "data-contract.json",
"role": "data-contract",
"sha256": "e195b2fd60a2798141c4c75ab57e0927d115bfba7888b0881b69dffa9dcb26cc",
"size": 266
},
{
"path": "ui/app.js",
"role": "ui",
"sha256": "3bc131e1afd3063e13373c6b64f86f9202a1bda78ce606e9137133c6e60abdae",
"size": 5204
},
{
"path": "ui/bridge.js",
"role": "ui",
"sha256": "0a436b5244acfd924b96274377c8758bf92ea665b0591afaddee064f48d0b599",
"size": 2939
},
{
"path": "ui/index.html",
"role": "ui",
"sha256": "e3c055e13440a8aa472bf2ca73a49c5af26eda0061e17d02a44a3c3de665c3b1",
"size": 2282
},
{
"path": "说明.md",
"role": "documentation",
"sha256": "6a0feb6f009f91430e0e809da6a4f4e81cd12b4e424f250b6adbaff07f9923dd",
"size": 1864
}
],
"source": {
"kind": "worktree",
"sha256": "83af9d981f282ca2ceb4103604b33e6cae07056d81a9718b72f13c5ab0b8527d"
},
"supportedPlatforms": [
"darwin",
"win32",
"linux",
"web"
],
"minimumClientVersion": "10.0.180",
"requiredCapabilities": [
"app-authoring-v1",
"release",
"web-bundle",
"bridge",
"data"
],
"dataContract": {
"schemaVersion": 1,
"formatVersion": "notes-v1",
"readableVersions": [
"notes-v1"
],
"writableVersions": [
"notes-v1"
],
"files": [
{
"key": "notes",
"path": "notes.json",
"maxBytes": 131072,
"contentType": "application/json"
}
],
"uninstallRetention": "retain"
},
"bridgeCapabilities": [
"connect",
"capabilities",
"readData",
"saveData",
"lookupDataMutation",
"publishSelection",
"requestWork",
"lookupRequest",
"readWork"
],
"instructionsPath": "说明.md",
"releaseDigest": "6ff9f35e8a14a2f35c4a0b1ee84755cfc63ef6e4d16860bb9e420b4514ae04b2"
}
@@ -0,0 +1,6 @@
{
"id": "personal-notes-workbench", "name": "个人笔记工作台", "version": "1.0.0", "productKind": "application",
"icon": "Notebook", "iconLetter": "记",
"entrypoints": [{ "id": "main", "name": "笔记", "kind": "embedded-web", "serviceRef": "workbench:main" }],
"placementPolicy": { "showInMyApps": true, "allowNavPin": true, "allowAgentBinding": true }
}
@@ -0,0 +1,5 @@
{
"schemaVersion": 1, "formatVersion": "notes-v1", "readableVersions": ["notes-v1"], "writableVersions": ["notes-v1"],
"files": [{ "key": "notes", "path": "notes.json", "maxBytes": 131072, "contentType": "application/json" }],
"uninstallRetention": "retain"
}
@@ -0,0 +1,13 @@
{
"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"],
"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" }
]
}
@@ -0,0 +1,68 @@
import { connectBridge } from './bridge.js'
const element = id => document.getElementById(id)
let bridge, connection, etag, notes = [], selected, pendingSave, pendingWork
const status = message => { element('status').textContent = message }
function render() {
element('notes').replaceChildren()
for (const note of notes) {
const row = document.createElement('li'), text = document.createElement('div'), button = document.createElement('button')
text.textContent = note.text; button.textContent = selected?.id === note.id ? '已选中' : '选择此笔记'
button.addEventListener('click', () => { selected = note; render() }); row.append(text,button); element('notes').append(row)
}
}
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()
status('已读取当前实例的数据。')
}
async function save() {
if (!pendingSave) {
const text = element('note').value.trim()
if (!text) return status('先输入笔记。')
pendingSave = {key:'notes',mutationId:crypto.randomUUID(),content:JSON.stringify({schemaVersion:1,notes:[...notes,{id:crypto.randomUUID(),revision:'1',text}]}),
...(etag ? {expectedETag:etag} : {expectedAbsent:true})}
}
try {
const receipt = await bridge.call('saveData',pendingSave)
if (receipt.status !== 'saved') throw new Error('save_result_unknown')
pendingSave = undefined; element('recover').disabled = true; element('note').value = ''; await read(); status('保存回执已核验。')
} catch (error) { element('recover').disabled = false; status(`保存尚未确认:${error.message}。保留原ID和正文,先查询原保存;未确认前不要添加另一条笔记。`) }
}
element('save').addEventListener('click',save)
element('refresh').addEventListener('click',() => pendingSave ? status('还有结果不明的原保存,请先查询。') : read().catch(error => status(error.message)))
element('recover').addEventListener('click',async () => {
if (!pendingSave) return
try {
const result = await bridge.call('lookupDataMutation',{key:'notes',mutationId:pendingSave.mutationId})
if (result.status === 'saved') { pendingSave = undefined; element('recover').disabled = true; element('note').value = ''; await read() }
else status(result.status === 'absent' ? '原保存明确未发生。可以用“保存笔记”重试同ID和原正文,冲突时读取并人工合并。' : '原保存仍不明确,请保留当前页面和原ID。')
} catch (error) { status(error.message) }
})
element('request').addEventListener('click',async () => {
const agentId = element('agent').value.trim()
if (!agentId || !selected) return element('work-status').textContent = '先选择笔记和实际Agent。'
if (pendingWork) return element('work-status').textContent = '已有待查询请求,请沿原ID恢复。'
pendingWork = {clientRequestId:crypto.randomUUID(),userMessageId:crypto.randomUUID(),agentId,
prompt:`请讨论这条笔记并给出可执行建议:${selected.text}`,scopeDescription:'读取notes来源文件核验所选笔记,只讨论该记录,不修改其他记录。',
selection:{schemaVersion:1,selectionRevision:crypto.randomUUID(),summary:`笔记ID:${selected.id},记录版本:${selected.revision},内容:${selected.text};正式实例对象引用授予读取notes来源文件。`,objects:connection.application && etag ?
[{schemaVersion:1,...connection.application,namespace:'data-files',objectId:'notes',revision:etag}] : []}}
element('work').disabled = false
try {
const proposal = await bridge.call('prepareWork',pendingWork)
element('work-status').textContent = `提案已准备,等待平台控件接纳。提案引用:${proposal.proposalRef}`
} catch (error) { element('work-status').textContent = `提案/请求结果尚未确认:${error.message};保留原请求ID查询。` }
})
element('work').addEventListener('click',async () => {
if (!pendingWork) return
try { element('work-status').textContent = JSON.stringify(await bridge.call('lookupRequest',{clientRequestId:pendingWork.clientRequestId}),null,2) }
catch (error) { element('work-status').textContent = error.message }
})
try {
bridge = await connectBridge(); connection = await bridge.call('connect')
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')
} catch (error) { status(`当前持久数据或协作能力不可用:${error.message}。未保存任何业务数据。`) }
@@ -0,0 +1,46 @@
/** 教学SDK适配:桌面有限preload;Web严格parent来源/nonce握手,没有管理token或任意invoke。 */
const methods = new Set(['connect','capabilities','publishSelection','prepareWork','lookupRequest','readWork','readData','saveData','lookupDataMutation'])
export async function connectBridge() {
if (window.desirecoreApp?.call) return window.desirecoreApp
if (window.parent === window) throw new Error('app_bridge_host_unavailable')
let origin
try { origin = new URL(document.referrer).origin } catch { throw new Error('app_bridge_host_origin_required') }
if (origin === 'null' || origin === location.origin) throw new Error('app_bridge_independent_origin_required')
return new Promise((resolve, reject) => {
let nonce
const timer = setTimeout(() => { window.removeEventListener('message', receive); reject(new Error('app_bridge_host_unavailable')) }, 15000)
function receive(event) {
if (event.source !== window.parent || event.origin !== origin || !event.data || typeof event.data !== 'object') return
if (event.data.protocol === 'desirecore-app-hello-v1' && typeof event.data.nonce === 'string' && !nonce) {
nonce = event.data.nonce
window.parent.postMessage({ protocol:'desirecore-app-ready-v1',nonce },origin)
} else if (nonce && event.data.protocol === 'desirecore-app-port-v1' && event.data.nonce === nonce && event.ports.length === 1) {
window.removeEventListener('message',receive); clearTimeout(timer); resolve(portClient(event.ports[0]))
}
}
window.addEventListener('message',receive)
})
}
function portClient(port) {
const pending = new Map(), listeners = new Set()
port.onmessage = event => {
const message = event.data
if (message?.protocol !== 'desirecore-app-bridge-v1') return
const request = pending.get(message.requestId)
if (request) { pending.delete(message.requestId); clearTimeout(request.timer); message.error ? request.reject(new Error(message.error)) : request.resolve(message.result) }
else if (message.event !== undefined) for (const listener of listeners) listener(message.event)
}
port.start()
return {
call(method,payload) {
if (!methods.has(method)) return Promise.reject(new Error('app_bridge_method_rejected'))
const requestId = crypto.randomUUID()
return new Promise((resolve,reject) => {
const timer = setTimeout(() => { pending.delete(requestId); reject(new Error('app_bridge_result_unknown')) },30000)
pending.set(requestId,{resolve,reject,timer}); port.postMessage({ protocol:'desirecore-app-bridge-v1',requestId,method,payload })
})
},
onEvent(callback) { listeners.add(callback); return () => listeners.delete(callback) },
close() { for (const request of pending.values()) { clearTimeout(request.timer); request.reject(new Error('app_bridge_closed')) }; pending.clear(); listeners.clear(); port.close() },
}
}
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="zh-CN"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>个人笔记工作台</title>
<style>
:root{font:16px/1.6 system-ui,sans-serif;color:#253447;background:#f1f5f9}body{max-width:920px;margin:40px auto;padding:0 24px}h1{font-size:30px;line-height:1.2}p{color:#526174}section{padding:24px;background:#fff;border:1px solid #dbe3ed;border-radius:16px;margin:20px 0}textarea{box-sizing:border-box;width:100%;min-height:140px;padding:14px;font:inherit;border:1px solid #becbdc;border-radius:8px}button,input{font:inherit;padding:9px 14px;border:1px solid #becbdc;border-radius:8px}button{background:#fff;cursor:pointer;margin:10px 6px 0 0}button.primary{background:#274c77;color:#fff;border-color:#274c77}button:disabled{opacity:.5;cursor:default}ul{padding:0;list-style:none}li{border-top:1px solid #e7edf4;padding:12px 0;white-space:pre-wrap}li button{margin-top:6px}output{display:block;margin-top:12px;color:#526174;white-space:pre-wrap;overflow-wrap:anywhere}label{display:block;margin-top:16px}input{max-width:100%;box-sizing:border-box;width:400px}@media(max-width:580px){body{margin:20px auto;padding:0 12px}section{padding:16px}}
</style>
<h1>个人笔记工作台</h1><p>先把想法记下来,再把选中的内容交给 Agent。业务数据与应用程序版本分别保存。</p>
<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><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>
<script type="module" src="./app.js"></script></html>
@@ -0,0 +1,11 @@
# 个人笔记工作台教学示例
这是可修改的最小材料,不是正式市场条目或已经完成的真实 Agent 验收。将示例复制到任务实际授权工作目录,用本 Skill 的 create-release.mjs 生成 app-release.json,再交平台 prepare/snapshot 预览与个人发布。
笔记保存在声明的 notes key,由平台按用户/实例/预览分配专用数据根。预览数据不自动成为正式数据;包中没有 notes.json。裸浏览器打开可看到页面,缺少可信桥时不会假装已持久保存。Web 须有独立 app origin 和真实 parent MessagePort;同源或无来源时桥拒绝。
保存使用 expectedETag/expectedAbsent;结果不明保留原 mutationId 和正文,先查原回执。示例只在当前页面保留待查询 ID,完整产品应通过获授权的视图状态或自身数据合同保存可恢复的请求引用,不能持久化平台 token。
“交给 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 仍取决于真实算力连接、权限和额度。平台能力未开放或未发行时保持不可用并说明原因。