dsh-annotate-upper 0.0.0-stage → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +90 -2
- package/cordis.patch.yml +4 -0
- package/lib/client.js +1757 -0
- package/lib/index.js +1277 -0
- package/lib/overlay.js +1601 -0
- package/lib/shim.js +232 -0
- package/lib/types/client/index.d.ts +2 -0
- package/lib/types/index.d.ts +3 -0
- package/package.json +75 -4
package/lib/shim.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-annotate — page shim.
|
|
3
|
+
*
|
|
4
|
+
* Injected into every previewed HTML document, before any app script. The
|
|
5
|
+
* preview server serves the app at its own paths, so relative and root-absolute
|
|
6
|
+
* URLs already stay inside it; this shim covers what preserving paths cannot:
|
|
7
|
+
*
|
|
8
|
+
* - URLs built from the page's own origin (`fetch(location.origin + '/api')`),
|
|
9
|
+
* which are already correct here and must not be rewritten a second time;
|
|
10
|
+
* - absolute URLs pointing at the real upstream origin, which would leave the
|
|
11
|
+
* preview origin and become cross-origin (and therefore unannotatable);
|
|
12
|
+
* - WebSocket / EventSource, relayed to the target the preview represents;
|
|
13
|
+
* - SPA navigation, reported to the panel so the address bar follows.
|
|
14
|
+
*
|
|
15
|
+
* Everything is wrapped defensively: a broken shim must never break the app.
|
|
16
|
+
*/
|
|
17
|
+
;(function () {
|
|
18
|
+
var cfg = window.__DSH_ANNO__
|
|
19
|
+
if (!cfg || !cfg.upstream) return
|
|
20
|
+
window.__DSH_ANNO_SESSION__ = cfg.session || 'standalone'
|
|
21
|
+
|
|
22
|
+
// The desktop navigation capability has already been checked by the host.
|
|
23
|
+
// Remove it before app scripts, routers and subresource Referers see it.
|
|
24
|
+
try {
|
|
25
|
+
var cleanUrl = new URL(location.href)
|
|
26
|
+
if (cfg.parentOrigin === 'dsh-app://app' && cleanUrl.searchParams.has('__dsh_anno_key')) {
|
|
27
|
+
cleanUrl.search = cleanUrl.search.slice(1).split('&').filter(function (part) {
|
|
28
|
+
return !new URLSearchParams(part).has('__dsh_anno_key')
|
|
29
|
+
}).join('&')
|
|
30
|
+
history.replaceState(history.state, '', cleanUrl.href)
|
|
31
|
+
}
|
|
32
|
+
} catch (error) { void error }
|
|
33
|
+
|
|
34
|
+
var PROXIED = location.origin + cfg.prefix // '/' in the preview origin
|
|
35
|
+
var withSlash = cfg.prefix.slice(-1) === '/' ? cfg.prefix : cfg.prefix + '/'
|
|
36
|
+
|
|
37
|
+
function proxied(url) {
|
|
38
|
+
if (url.indexOf(PROXIED) === 0) return url
|
|
39
|
+
// Root-absolute paths have to be prefixed here: a base element cannot do it
|
|
40
|
+
// (URL parsing of '/x' replaces the whole path, base included).
|
|
41
|
+
if (url.charAt(0) === '/' && url.charAt(1) !== '/') return withSlash + url.slice(1)
|
|
42
|
+
if (url.indexOf(withSlash) === 0) return url
|
|
43
|
+
if (url.indexOf(cfg.upstream) === 0) return location.origin + withSlash + url.slice(cfg.upstream.replace(/\/$/, '').length + 1)
|
|
44
|
+
if (url.indexOf(location.origin) === 0) return location.origin + withSlash + url.slice(location.origin.length + 1)
|
|
45
|
+
return url
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function toAbsolute(url) {
|
|
49
|
+
try {
|
|
50
|
+
return new URL(url, location.href).href
|
|
51
|
+
} catch (error) {
|
|
52
|
+
return ''
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Same-origin (harness) or upstream-origin URLs are ours to rewrite. */
|
|
57
|
+
function needsRewrite(url) {
|
|
58
|
+
var absolute = toAbsolute(url)
|
|
59
|
+
if (!absolute) return false
|
|
60
|
+
if (absolute.indexOf(PROXIED) === 0) return false
|
|
61
|
+
var upstream = cfg.upstream.replace(/\/$/, '')
|
|
62
|
+
if (absolute.indexOf(upstream + '/') === 0 || absolute === upstream) return true
|
|
63
|
+
if (absolute.indexOf(location.origin + '/') === 0) return true
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ---- fetch ---------------------------------------------------------------
|
|
68
|
+
if (typeof window.fetch === 'function') {
|
|
69
|
+
var originalFetch = window.fetch
|
|
70
|
+
window.fetch = function (input, init) {
|
|
71
|
+
try {
|
|
72
|
+
if (typeof input === 'string' && needsRewrite(input)) {
|
|
73
|
+
input = proxied(input)
|
|
74
|
+
} else if (input && typeof input === 'object' && input.url && needsRewrite(input.url)) {
|
|
75
|
+
input = new Request(proxied(input.url), input)
|
|
76
|
+
}
|
|
77
|
+
} catch (error) {
|
|
78
|
+
void error
|
|
79
|
+
}
|
|
80
|
+
return originalFetch.call(this, input, init)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ---- XMLHttpRequest -----------------------------------------------------
|
|
85
|
+
if (window.XMLHttpRequest && window.XMLHttpRequest.prototype.open) {
|
|
86
|
+
var originalOpen = window.XMLHttpRequest.prototype.open
|
|
87
|
+
window.XMLHttpRequest.prototype.open = function (method, url) {
|
|
88
|
+
var args = Array.prototype.slice.call(arguments)
|
|
89
|
+
try {
|
|
90
|
+
if (typeof url === 'string' && needsRewrite(url)) args[1] = proxied(url)
|
|
91
|
+
} catch (error) {
|
|
92
|
+
void error
|
|
93
|
+
}
|
|
94
|
+
return originalOpen.apply(this, args)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ---- EventSource --------------------------------------------------------
|
|
99
|
+
if (window.EventSource) {
|
|
100
|
+
var OriginalEventSource = window.EventSource
|
|
101
|
+
var PatchedEventSource = function (url, config) {
|
|
102
|
+
try {
|
|
103
|
+
if (typeof url === 'string' && needsRewrite(url)) url = proxied(url)
|
|
104
|
+
} catch (error) {
|
|
105
|
+
void error
|
|
106
|
+
}
|
|
107
|
+
return new OriginalEventSource(url, config)
|
|
108
|
+
}
|
|
109
|
+
PatchedEventSource.prototype = OriginalEventSource.prototype
|
|
110
|
+
window.EventSource = PatchedEventSource
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ---- WebSocket ----------------------------------------------------------
|
|
114
|
+
// The harness only takes exact upgrade paths, so every socket funnels through
|
|
115
|
+
// one relay with its real target in the query string.
|
|
116
|
+
if (window.WebSocket) {
|
|
117
|
+
var OriginalWebSocket = window.WebSocket
|
|
118
|
+
var relayFor = function (url) {
|
|
119
|
+
var absolute = toAbsolute(url)
|
|
120
|
+
if (cfg.isolated) {
|
|
121
|
+
var socketUrl = new URL(absolute)
|
|
122
|
+
var httpOrigin = socketUrl.origin.replace(/^ws/, 'http')
|
|
123
|
+
if (httpOrigin === cfg.upstream || httpOrigin === location.origin) {
|
|
124
|
+
return location.origin.replace(/^http/, 'ws') + socketUrl.pathname + socketUrl.search
|
|
125
|
+
}
|
|
126
|
+
return url
|
|
127
|
+
}
|
|
128
|
+
var target = ''
|
|
129
|
+
if (absolute.indexOf(location.origin + withSlash) === 0) {
|
|
130
|
+
var rest = absolute.slice((location.origin + withSlash).length)
|
|
131
|
+
target = cfg.upstream.replace(/\/$/, '') + '/' + rest
|
|
132
|
+
} else if (absolute.indexOf(cfg.upstream.replace(/\/$/, '') + '/') === 0 || needsRewrite(url)) {
|
|
133
|
+
var parsed = new URL(absolute, location.href)
|
|
134
|
+
var path = parsed.pathname + parsed.search
|
|
135
|
+
target = cfg.upstream.replace(/\/$/, '') + (path.charAt(0) === '/' ? path : '/' + path)
|
|
136
|
+
} else {
|
|
137
|
+
return url
|
|
138
|
+
}
|
|
139
|
+
var scheme = location.protocol === 'https:' ? 'wss:' : 'ws:'
|
|
140
|
+
return (
|
|
141
|
+
scheme + '//' + location.host + cfg.relay + '?to=' + encodeURIComponent(cfg.enc) + '&path=' + encodeURIComponent(target)
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
var PatchedWebSocket = function (url, protocols) {
|
|
145
|
+
var finalUrl = url
|
|
146
|
+
try {
|
|
147
|
+
finalUrl = relayFor(url)
|
|
148
|
+
} catch (error) {
|
|
149
|
+
void error
|
|
150
|
+
}
|
|
151
|
+
return protocols === undefined ? new OriginalWebSocket(finalUrl) : new OriginalWebSocket(finalUrl, protocols)
|
|
152
|
+
}
|
|
153
|
+
PatchedWebSocket.prototype = OriginalWebSocket.prototype
|
|
154
|
+
;['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'].forEach(function (key) {
|
|
155
|
+
PatchedWebSocket[key] = OriginalWebSocket[key]
|
|
156
|
+
})
|
|
157
|
+
window.WebSocket = PatchedWebSocket
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (cfg.isolated) {
|
|
161
|
+
var cookiePrefix = 'anno_' + cfg.enc + '_'
|
|
162
|
+
var cookieDescriptor = Object.getOwnPropertyDescriptor(Document.prototype, 'cookie')
|
|
163
|
+
if (cookieDescriptor && cookieDescriptor.get && cookieDescriptor.set) {
|
|
164
|
+
Object.defineProperty(document, 'cookie', {
|
|
165
|
+
configurable: true,
|
|
166
|
+
get: function () {
|
|
167
|
+
return cookieDescriptor.get.call(document).split(';').map(function (s) { return s.trim() })
|
|
168
|
+
.filter(function (s) { return s.indexOf(cookiePrefix) === 0 })
|
|
169
|
+
.map(function (s) { return s.slice(cookiePrefix.length) }).join('; ')
|
|
170
|
+
},
|
|
171
|
+
set: function (value) { cookieDescriptor.set.call(document, cookiePrefix + String(value).replace(/;\s*domain=[^;]*/ig, '') + '; SameSite=None; Secure; Partitioned') }
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ---- navigation reporting ----------------------------------------------
|
|
177
|
+
function upstreamHref() {
|
|
178
|
+
var query = location.search
|
|
179
|
+
if (cfg.fileRoot) return new URL('.' + location.pathname + query + location.hash, cfg.fileRoot).href
|
|
180
|
+
if (cfg.page) {
|
|
181
|
+
var page = new URL(cfg.page)
|
|
182
|
+
page.search = query
|
|
183
|
+
page.hash = location.hash
|
|
184
|
+
return page.href
|
|
185
|
+
}
|
|
186
|
+
var href = location.origin + location.pathname + query + location.hash
|
|
187
|
+
if (href.indexOf(PROXIED) !== 0) return href
|
|
188
|
+
var rest = href.slice(PROXIED.length)
|
|
189
|
+
return cfg.upstream.replace(/\/$/, '') + '/' + rest
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function report() {
|
|
193
|
+
if (!cfg.parentOrigin) return
|
|
194
|
+
try {
|
|
195
|
+
window.parent.postMessage({ source: 'dsh-annotate-page', type: 'navigated', url: upstreamHref() }, cfg.parentOrigin)
|
|
196
|
+
} catch (error) {
|
|
197
|
+
void error
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
try {
|
|
202
|
+
// A router pushing '/settings' would otherwise move the document straight
|
|
203
|
+
// out of the proxy (the harness root has no such page).
|
|
204
|
+
var rewriteStateUrl = function (url) {
|
|
205
|
+
if (typeof url !== 'string' || url.charAt(0) !== '/' || url.indexOf('//') === 0) return url
|
|
206
|
+
if (url.indexOf(withSlash) === 0) return url
|
|
207
|
+
return withSlash + url.slice(1)
|
|
208
|
+
}
|
|
209
|
+
var pushState = history.pushState
|
|
210
|
+
history.pushState = function (state, title, url) {
|
|
211
|
+
var result = pushState.call(this, state, title, rewriteStateUrl(url))
|
|
212
|
+
report()
|
|
213
|
+
return result
|
|
214
|
+
}
|
|
215
|
+
var replaceState = history.replaceState
|
|
216
|
+
history.replaceState = function (state, title, url) {
|
|
217
|
+
var result = replaceState.call(this, state, title, rewriteStateUrl(url))
|
|
218
|
+
report()
|
|
219
|
+
return result
|
|
220
|
+
}
|
|
221
|
+
window.addEventListener('popstate', report)
|
|
222
|
+
window.addEventListener('hashchange', report)
|
|
223
|
+
window.addEventListener('load', report)
|
|
224
|
+
} catch (error) {
|
|
225
|
+
void error
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// A tiny surface the panel can poll if a message is missed.
|
|
229
|
+
window.__dshAnnoState = function () {
|
|
230
|
+
return { url: upstreamHref(), upstream: cfg.upstream }
|
|
231
|
+
}
|
|
232
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,77 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-annotate-upper",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.16",
|
|
4
|
+
"description": "Element annotation and review panel for the DeepSeek Harness Desktop and web client: pick UI elements in a live app preview, write notes, and send them to the conversation as one structured block",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "lib/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/types/index.d.ts",
|
|
11
|
+
"default": "./lib/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./client": {
|
|
14
|
+
"types": "./lib/types/client/index.d.ts",
|
|
15
|
+
"default": "./lib/client.js"
|
|
16
|
+
},
|
|
17
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/HelloQingTao/dsh-annotate-upper.git"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/HelloQingTao/dsh-annotate-upper#readme",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/HelloQingTao/dsh-annotate-upper/issues"
|
|
27
|
+
},
|
|
28
|
+
"author": "qinjing <alaliqing@gmail.com>",
|
|
29
|
+
"keywords": [
|
|
30
|
+
"deepseek-harness",
|
|
31
|
+
"dsh",
|
|
32
|
+
"dsh-plugin",
|
|
33
|
+
"annotation",
|
|
34
|
+
"review",
|
|
35
|
+
"devtools"
|
|
36
|
+
],
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=20",
|
|
39
|
+
"dsh": ">=0.2.0-rc.2 <0.3.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@deepseek-ai/cordis": "~4.0.4"
|
|
43
|
+
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"@deepseek-ai/cordis": {
|
|
46
|
+
"optional": true
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {},
|
|
53
|
+
"dsh": {
|
|
54
|
+
"bundle": {
|
|
55
|
+
"patch": "./cordis.patch.yml"
|
|
56
|
+
},
|
|
57
|
+
"client": {
|
|
58
|
+
"inject": [
|
|
59
|
+
"@deepseek-ai/dsh-client-runtime",
|
|
60
|
+
"@deepseek-ai/dsh-client-connection",
|
|
61
|
+
"@deepseek-ai/dsh-client-ui-slots",
|
|
62
|
+
"@deepseek-ai/dsh-client-ui-sidebar-right",
|
|
63
|
+
"@deepseek-ai/dsh-api-session-controller"
|
|
64
|
+
],
|
|
65
|
+
"platform": "web"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"files": [
|
|
69
|
+
"lib/index.js",
|
|
70
|
+
"lib/client.js",
|
|
71
|
+
"lib/shim.js",
|
|
72
|
+
"lib/overlay.js",
|
|
73
|
+
"lib/types/**/*.d.ts",
|
|
74
|
+
"cordis.patch.yml",
|
|
75
|
+
"README.md"
|
|
76
|
+
]
|
|
77
|
+
}
|