agent-canvas 0.9.0-dev.11 → 0.9.0-dev.12
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/README.md +54 -0
- package/daemon/client/App.tsx +4 -0
- package/daemon/client/FileViewer.tsx +2 -2
- package/daemon/client/clientApi.ts +9 -3
- package/daemon/dist/client.css +1 -1
- package/daemon/dist/client.js +37 -37
- package/daemon/dist/components.js +38 -38
- package/daemon/review-widget/tsconfig.build.json +12 -0
- package/daemon/src/handlers/uploads.ts +11 -22
- package/daemon/src/remote-feedback.ts +24 -98
- package/daemon/src/review/proxy.ts +8 -3
- package/daemon/src/share-client.ts +341 -0
- package/daemon/src/share-responses.ts +41 -0
- package/daemon/src/share.ts +13 -121
- package/daemon/src/upload-image.ts +73 -0
- package/daemon/tsconfig.build.json +18 -0
- package/package.json +17 -5
- package/types/daemon/client/clientApi.d.ts +11 -0
- package/types/daemon/src/review/proxy.d.ts +1 -0
- package/types/daemon/src/share-client.d.ts +292 -0
- package/types/daemon/src/share-responses.d.ts +56 -0
- package/types/daemon/src/share.d.ts +3 -42
- package/types/daemon/src/upload-image.d.ts +30 -0
package/daemon/src/share.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { SessionManager, ShareEntry } from '@fabrika/canvas-kernel/server'
|
|
2
|
-
import {
|
|
2
|
+
import { createShare, pushShareToWorker as pushToWorker, revokeShareOnWorker, type SharePayload, type ShareResponse } from './share-client'
|
|
3
|
+
|
|
4
|
+
export { encryptSharePayload, type SharePayload, type ShareResponse } from './share-client'
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Canvas sharing: packages a specific revision into a self-contained
|
|
@@ -26,33 +28,6 @@ import { ENCRYPTION_META, type EncryptionMeta, encryptString, exportShareKey, ge
|
|
|
26
28
|
* fragment.
|
|
27
29
|
*/
|
|
28
30
|
|
|
29
|
-
export interface SharePayload {
|
|
30
|
-
version: 1
|
|
31
|
-
/** Present iff payload fields below are ciphertext rather than plaintext. */
|
|
32
|
-
encryption?: EncryptionMeta
|
|
33
|
-
origin: {
|
|
34
|
-
sessionId: string
|
|
35
|
-
revision: number
|
|
36
|
-
label?: string
|
|
37
|
-
createdAt: string
|
|
38
|
-
}
|
|
39
|
-
canvasFiles: Array<{
|
|
40
|
-
filename: string
|
|
41
|
-
compiledJs: string
|
|
42
|
-
sourceJsx?: string
|
|
43
|
-
}>
|
|
44
|
-
runtime: {
|
|
45
|
-
componentsVersion: string
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface ShareResponse {
|
|
50
|
-
shareId: string
|
|
51
|
-
url: string
|
|
52
|
-
ownerToken?: string
|
|
53
|
-
expiresAt?: string
|
|
54
|
-
}
|
|
55
|
-
|
|
56
31
|
export interface ShareConfig {
|
|
57
32
|
/** Base URL of the share worker, e.g. `https://canvas-share.example.workers.dev` */
|
|
58
33
|
endpoint: string
|
|
@@ -125,74 +100,9 @@ export function buildSharePayload(
|
|
|
125
100
|
}
|
|
126
101
|
}
|
|
127
102
|
|
|
128
|
-
/**
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
* Fields kept plaintext (and why):
|
|
132
|
-
* - `version`, `runtime.componentsVersion`: routing
|
|
133
|
-
* - `origin.revision`, `origin.createdAt`: indexing/display
|
|
134
|
-
* - `canvasFiles[].filename`: used as the route key by the worker
|
|
135
|
-
* Everything else (sessionId, label, compiledJs, sourceJsx) is encrypted.
|
|
136
|
-
*/
|
|
137
|
-
export async function encryptSharePayload(
|
|
138
|
-
payload: SharePayload,
|
|
139
|
-
key: CryptoKey,
|
|
140
|
-
): Promise<SharePayload> {
|
|
141
|
-
const canvasFiles = await Promise.all(
|
|
142
|
-
payload.canvasFiles.map(async (cf) => ({
|
|
143
|
-
filename: cf.filename,
|
|
144
|
-
compiledJs: await encryptString(key, cf.compiledJs),
|
|
145
|
-
...(cf.sourceJsx ? { sourceJsx: await encryptString(key, cf.sourceJsx) } : {}),
|
|
146
|
-
})),
|
|
147
|
-
)
|
|
148
|
-
return {
|
|
149
|
-
version: payload.version,
|
|
150
|
-
encryption: ENCRYPTION_META,
|
|
151
|
-
origin: {
|
|
152
|
-
sessionId: await encryptString(key, payload.origin.sessionId),
|
|
153
|
-
revision: payload.origin.revision,
|
|
154
|
-
...(payload.origin.label
|
|
155
|
-
? { label: await encryptString(key, payload.origin.label) }
|
|
156
|
-
: {}),
|
|
157
|
-
createdAt: payload.origin.createdAt,
|
|
158
|
-
},
|
|
159
|
-
canvasFiles,
|
|
160
|
-
runtime: payload.runtime,
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* POST the payload to the CF Worker. Returns the `shareId` + public URL
|
|
166
|
-
* assigned by the worker. Throws on any HTTP error — the caller is expected
|
|
167
|
-
* to surface the failure to the client (dialog) so the user can retry or
|
|
168
|
-
* fix their config.
|
|
169
|
-
*/
|
|
170
|
-
export async function pushShareToWorker(
|
|
171
|
-
payload: SharePayload,
|
|
172
|
-
config: ShareConfig,
|
|
173
|
-
): Promise<ShareResponse> {
|
|
174
|
-
const headers: Record<string, string> = { 'Content-Type': 'application/json' }
|
|
175
|
-
if (config.authToken) headers['Authorization'] = `Bearer ${config.authToken}`
|
|
176
|
-
|
|
177
|
-
const res = await fetch(`${config.endpoint}/shares`, {
|
|
178
|
-
method: 'POST',
|
|
179
|
-
headers,
|
|
180
|
-
body: JSON.stringify(payload),
|
|
181
|
-
})
|
|
182
|
-
if (!res.ok) {
|
|
183
|
-
const text = await res.text().catch(() => '')
|
|
184
|
-
throw new Error(`Share endpoint returned ${res.status}: ${text || res.statusText}`)
|
|
185
|
-
}
|
|
186
|
-
const data = (await res.json()) as { shareId?: string; url?: string; ownerToken?: string; expiresAt?: string }
|
|
187
|
-
if (!data.shareId || !data.url) {
|
|
188
|
-
throw new Error(`Share endpoint returned invalid response: ${JSON.stringify(data)}`)
|
|
189
|
-
}
|
|
190
|
-
return {
|
|
191
|
-
shareId: data.shareId,
|
|
192
|
-
url: data.url,
|
|
193
|
-
...(data.ownerToken ? { ownerToken: data.ownerToken } : {}),
|
|
194
|
-
...(data.expiresAt ? { expiresAt: data.expiresAt } : {}),
|
|
195
|
-
}
|
|
103
|
+
/** POST the payload to the configured worker (see share-client.ts). */
|
|
104
|
+
export function pushShareToWorker(payload: SharePayload, config: ShareConfig): Promise<ShareResponse> {
|
|
105
|
+
return pushToWorker(payload, config)
|
|
196
106
|
}
|
|
197
107
|
|
|
198
108
|
/**
|
|
@@ -208,27 +118,16 @@ export async function shareRevision(
|
|
|
208
118
|
config: ShareConfig,
|
|
209
119
|
): Promise<ShareEntry> {
|
|
210
120
|
const plaintext = buildSharePayload(sessionManager, sessionId, revision, config.componentsVersion)
|
|
211
|
-
|
|
212
|
-
const useEncryption = config.encryption !== false
|
|
213
|
-
let payload = plaintext
|
|
214
|
-
let encodedKey: string | undefined
|
|
215
|
-
if (useEncryption) {
|
|
216
|
-
const key = await generateShareKey()
|
|
217
|
-
encodedKey = await exportShareKey(key)
|
|
218
|
-
payload = await encryptSharePayload(plaintext, key)
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const response = await pushShareToWorker(payload, config)
|
|
222
|
-
const url = encodedKey ? `${response.url}#k=${encodedKey}` : response.url
|
|
121
|
+
const share = await createShare(plaintext, config)
|
|
223
122
|
|
|
224
123
|
const entry: ShareEntry = {
|
|
225
|
-
shareId:
|
|
226
|
-
url,
|
|
124
|
+
shareId: share.shareId,
|
|
125
|
+
url: share.url,
|
|
227
126
|
revision,
|
|
228
127
|
createdAt: new Date().toISOString(),
|
|
229
|
-
...(
|
|
230
|
-
...(
|
|
231
|
-
...(
|
|
128
|
+
...(share.ownerToken ? { ownerToken: share.ownerToken } : {}),
|
|
129
|
+
...(share.expiresAt ? { expiresAt: share.expiresAt } : {}),
|
|
130
|
+
...(share.encryptionKey ? { encryptionKey: share.encryptionKey } : {}),
|
|
232
131
|
}
|
|
233
132
|
sessionManager.addShare(sessionId, entry)
|
|
234
133
|
return entry
|
|
@@ -249,13 +148,6 @@ export async function revokeShare(
|
|
|
249
148
|
if (!entry) throw new Error(`Share ${shareId} not found`)
|
|
250
149
|
if (!entry.ownerToken) throw new Error('No owner token recorded for this share')
|
|
251
150
|
|
|
252
|
-
|
|
253
|
-
method: 'POST',
|
|
254
|
-
headers: { 'Authorization': `Bearer ${entry.ownerToken}` },
|
|
255
|
-
})
|
|
256
|
-
if (!res.ok) {
|
|
257
|
-
const text = await res.text().catch(() => '')
|
|
258
|
-
throw new Error(`Revoke failed: ${res.status} ${text}`)
|
|
259
|
-
}
|
|
151
|
+
await revokeShareOnWorker(config.endpoint, shareId, entry.ownerToken)
|
|
260
152
|
sessionManager.removeShare(sessionId, shareId)
|
|
261
153
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Annotation image uploads, shared by the local daemon and the canvas-share worker: which images an upload may carry
|
|
3
|
+
* and how a stored upload is served. Runtime-neutral (Bun and workerd).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Raster formats only: an SVG or any other active document would run script on the serving origin. */
|
|
7
|
+
const UPLOAD_IMAGE_TYPES = {
|
|
8
|
+
'image/png': 'png',
|
|
9
|
+
'image/jpeg': 'jpg',
|
|
10
|
+
'image/gif': 'gif',
|
|
11
|
+
'image/webp': 'webp',
|
|
12
|
+
} as const
|
|
13
|
+
|
|
14
|
+
export type UploadImageType = keyof typeof UPLOAD_IMAGE_TYPES
|
|
15
|
+
|
|
16
|
+
export interface UploadImage {
|
|
17
|
+
type: UploadImageType
|
|
18
|
+
extension: (typeof UPLOAD_IMAGE_TYPES)[UploadImageType]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const UPLOAD_IMAGE_REFUSED = 'Only PNG, JPEG, GIF and WebP images are accepted'
|
|
22
|
+
|
|
23
|
+
function isUploadImageType(type: string): type is UploadImageType {
|
|
24
|
+
return Object.hasOwn(UPLOAD_IMAGE_TYPES, type)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function startsWith(bytes: Uint8Array, offset: number, signature: readonly number[]): boolean {
|
|
28
|
+
return bytes.length >= offset + signature.length && signature.every((byte, i) => bytes[offset + i] === byte)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const ascii = (text: string) => Array.from(text, (c) => c.charCodeAt(0))
|
|
32
|
+
|
|
33
|
+
function sniffImageType(bytes: Uint8Array): UploadImageType | null {
|
|
34
|
+
if (startsWith(bytes, 0, [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])) return 'image/png'
|
|
35
|
+
if (startsWith(bytes, 0, [0xff, 0xd8, 0xff])) return 'image/jpeg'
|
|
36
|
+
if (startsWith(bytes, 0, ascii('GIF87a')) || startsWith(bytes, 0, ascii('GIF89a'))) return 'image/gif'
|
|
37
|
+
if (startsWith(bytes, 0, ascii('RIFF')) && startsWith(bytes, 8, ascii('WEBP'))) return 'image/webp'
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The image an upload carries, or null when its content is not an accepted raster format. The content's signature
|
|
43
|
+
* alone decides: a declared type means different things per runtime (Bun derives it from the file name).
|
|
44
|
+
*/
|
|
45
|
+
export function parseUploadImage(bytes: Uint8Array): UploadImage | null {
|
|
46
|
+
const type = sniffImageType(bytes)
|
|
47
|
+
if (type === null) return null
|
|
48
|
+
return { type, extension: UPLOAD_IMAGE_TYPES[type] }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const EXTENSION_TYPES: Record<string, UploadImageType> = {
|
|
52
|
+
png: 'image/png',
|
|
53
|
+
jpg: 'image/jpeg',
|
|
54
|
+
jpeg: 'image/jpeg',
|
|
55
|
+
gif: 'image/gif',
|
|
56
|
+
webp: 'image/webp',
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The accepted type a stored upload's file extension names. */
|
|
60
|
+
export function uploadImageTypeOfExtension(extension: string): UploadImageType | undefined {
|
|
61
|
+
const lower = extension.toLowerCase()
|
|
62
|
+
return Object.hasOwn(EXTENSION_TYPES, lower) ? EXTENSION_TYPES[lower] : undefined
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Response headers for a stored upload. Every upload is served inert (no sniffing, no script, sandboxed), which also
|
|
67
|
+
* covers files stored before the type allowlist; a type outside the allowlist is served as a download.
|
|
68
|
+
*/
|
|
69
|
+
export function uploadServeHeaders(storedType: string | undefined): Record<string, string> {
|
|
70
|
+
const inert = { 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'none'; sandbox" }
|
|
71
|
+
if (storedType !== undefined && isUploadImageType(storedType)) return { ...inert, 'Content-Type': storedType }
|
|
72
|
+
return { ...inert, 'Content-Type': 'application/octet-stream', 'Content-Disposition': 'attachment' }
|
|
73
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"incremental": true,
|
|
5
|
+
"tsBuildInfoFile": "../.tsbuild/daemon.tsbuildinfo"
|
|
6
|
+
},
|
|
7
|
+
"include": [
|
|
8
|
+
"src/**/*",
|
|
9
|
+
"client/**/*",
|
|
10
|
+
"review-widget/**/*.test.ts",
|
|
11
|
+
"langMap.ts"
|
|
12
|
+
],
|
|
13
|
+
"references": [
|
|
14
|
+
{ "path": "../../annotations/tsconfig.lib.json" },
|
|
15
|
+
{ "path": "../../canvas-kernel/tsconfig.lib.json" },
|
|
16
|
+
{ "path": "../../daemon-kit/tsconfig.lib.json" }
|
|
17
|
+
]
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-canvas",
|
|
3
|
-
"version": "0.9.0-dev.
|
|
3
|
+
"version": "0.9.0-dev.12",
|
|
4
4
|
"description": "Interactive visual canvas for Claude Code — rich annotatable documents in the browser",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,18 +38,30 @@
|
|
|
38
38
|
"./review/threads": {
|
|
39
39
|
"types": "./types/daemon/src/review/threads.d.ts",
|
|
40
40
|
"default": "./daemon/src/review/threads.ts"
|
|
41
|
+
},
|
|
42
|
+
"./share": {
|
|
43
|
+
"types": "./types/daemon/src/share-client.d.ts",
|
|
44
|
+
"default": "./daemon/src/share-client.ts"
|
|
45
|
+
},
|
|
46
|
+
"./share/responses": {
|
|
47
|
+
"types": "./types/daemon/src/share-responses.d.ts",
|
|
48
|
+
"default": "./daemon/src/share-responses.ts"
|
|
49
|
+
},
|
|
50
|
+
"./upload-image": {
|
|
51
|
+
"types": "./types/daemon/src/upload-image.d.ts",
|
|
52
|
+
"default": "./daemon/src/upload-image.ts"
|
|
41
53
|
}
|
|
42
54
|
},
|
|
43
55
|
"scripts": {
|
|
44
56
|
"build": "bun daemon/build.ts",
|
|
45
57
|
"release:prepare": "bun run build",
|
|
46
|
-
"typecheck": "
|
|
58
|
+
"typecheck": "tsrs --build tsconfig.build.json daemon/tsconfig.build.json daemon/review-widget/tsconfig.build.json",
|
|
47
59
|
"test": "bun test"
|
|
48
60
|
},
|
|
49
61
|
"dependencies": {
|
|
50
|
-
"@fabrika/annotations": "0.9.0-dev.
|
|
51
|
-
"@fabrika/canvas-kernel": "0.9.0-dev.
|
|
52
|
-
"@fabrika/daemon-kit": "0.9.0-dev.
|
|
62
|
+
"@fabrika/annotations": "0.9.0-dev.12",
|
|
63
|
+
"@fabrika/canvas-kernel": "0.9.0-dev.12",
|
|
64
|
+
"@fabrika/daemon-kit": "0.9.0-dev.12",
|
|
53
65
|
"@jridgewell/trace-mapping": "^0.3.31",
|
|
54
66
|
"marked": "^17.0.4",
|
|
55
67
|
"mermaid-parser-bundle": "^0.1.2",
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
* work in cleartext.
|
|
22
22
|
*/
|
|
23
23
|
import type { CanvasHost } from '@fabrika/canvas-kernel/client';
|
|
24
|
+
import type { SharedResponse } from '../src/share-responses';
|
|
24
25
|
import { type SessionMeta } from './apiSchemas';
|
|
26
|
+
import { type EncryptionMeta } from './shareCrypto';
|
|
25
27
|
declare global {
|
|
26
28
|
interface Window {
|
|
27
29
|
__CANVAS_SHARE__?: {
|
|
@@ -92,7 +94,15 @@ export interface SharedFeedbackPayload {
|
|
|
92
94
|
revision: number;
|
|
93
95
|
annotations: Array<Record<string, unknown>>;
|
|
94
96
|
generalNote?: string;
|
|
97
|
+
/** Structured answers to the canvas inputs; `generalNote` carries the same answers as markdown. */
|
|
98
|
+
responses?: SharedResponse[];
|
|
95
99
|
}
|
|
100
|
+
type EncryptedFeedbackBody = Omit<SharedFeedbackPayload, 'responses'> & {
|
|
101
|
+
responses?: string;
|
|
102
|
+
encryption: EncryptionMeta;
|
|
103
|
+
};
|
|
104
|
+
/** The feedback body for an encrypted share: every text field, and the responses as one blob, as ciphertext. */
|
|
105
|
+
export declare function encryptFeedback(payload: SharedFeedbackPayload, key: CryptoKey): Promise<EncryptedFeedbackBody>;
|
|
96
106
|
/**
|
|
97
107
|
* Submit feedback in shared mode. Throws on HTTP error. Caller is
|
|
98
108
|
* responsible for collecting + prompting for the reviewer's name before
|
|
@@ -110,3 +120,4 @@ export declare const WS_AVAILABLE: boolean;
|
|
|
110
120
|
* defaults: shared canvases come from the worker (and may be encrypted).
|
|
111
121
|
*/
|
|
112
122
|
export declare const canvasHost: CanvasHost;
|
|
123
|
+
export {};
|
|
@@ -23,6 +23,7 @@ export declare class ReviewProxies {
|
|
|
23
23
|
/** Serves every proxy a previous daemon served, on the same ports. */
|
|
24
24
|
restore(): void;
|
|
25
25
|
stop(): void;
|
|
26
|
+
/** `target` is an origin: the proxy sets each request's path on it. */
|
|
26
27
|
private listen;
|
|
27
28
|
private serve;
|
|
28
29
|
/** Connects to the application first, so the browser gets the subprotocol the application chose. */
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { decryptString, ENCRYPTION_META, type EncryptionMeta, encryptString, exportShareKey, generateShareKey, importShareKey } from '../client/shareCrypto';
|
|
3
|
+
import { type SharedResponse } from './share-responses';
|
|
4
|
+
/**
|
|
5
|
+
* Client for the canvas share worker, independent of the daemon's sessions.
|
|
6
|
+
*
|
|
7
|
+
* Exported as `agent-canvas/share` so another host can share a compiled
|
|
8
|
+
* canvas and read its feedback with the same wire format and end-to-end
|
|
9
|
+
* encryption the daemon uses. The daemon's own sharing (share.ts), its
|
|
10
|
+
* feedback poller (remote-feedback.ts), the shared page and the worker's
|
|
11
|
+
* validation are built on it.
|
|
12
|
+
*
|
|
13
|
+
* Encryption: see `daemon/client/shareCrypto.ts`; the key travels only in
|
|
14
|
+
* the URL fragment, so the worker stores ciphertext it cannot read.
|
|
15
|
+
*/
|
|
16
|
+
export { decryptString, ENCRYPTION_META, type EncryptionMeta, encryptString, exportShareKey, generateShareKey, importShareKey };
|
|
17
|
+
export { answeredResponses, MAX_SHARED_RESPONSE_TEXT, MAX_SHARED_RESPONSES, type SharedResponse, sharedResponseSchema, sharedResponsesSchema, } from './share-responses';
|
|
18
|
+
export interface SharePayload {
|
|
19
|
+
version: 1;
|
|
20
|
+
/** Present iff payload fields below are ciphertext rather than plaintext. */
|
|
21
|
+
encryption?: EncryptionMeta;
|
|
22
|
+
origin: {
|
|
23
|
+
sessionId: string;
|
|
24
|
+
revision: number;
|
|
25
|
+
label?: string;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
};
|
|
28
|
+
canvasFiles: Array<{
|
|
29
|
+
filename: string;
|
|
30
|
+
compiledJs: string;
|
|
31
|
+
sourceJsx?: string;
|
|
32
|
+
}>;
|
|
33
|
+
runtime: {
|
|
34
|
+
componentsVersion: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
declare const shareResponseSchema: z.ZodObject<{
|
|
38
|
+
shareId: z.ZodString;
|
|
39
|
+
url: z.ZodString;
|
|
40
|
+
ownerToken: z.ZodOptional<z.ZodString>;
|
|
41
|
+
expiresAt: z.ZodOptional<z.ZodString>;
|
|
42
|
+
}, "strip", z.ZodTypeAny, {
|
|
43
|
+
url: string;
|
|
44
|
+
shareId: string;
|
|
45
|
+
ownerToken?: string | undefined;
|
|
46
|
+
expiresAt?: string | undefined;
|
|
47
|
+
}, {
|
|
48
|
+
url: string;
|
|
49
|
+
shareId: string;
|
|
50
|
+
ownerToken?: string | undefined;
|
|
51
|
+
expiresAt?: string | undefined;
|
|
52
|
+
}>;
|
|
53
|
+
export type ShareResponse = z.infer<typeof shareResponseSchema>;
|
|
54
|
+
export interface ShareEndpoint {
|
|
55
|
+
/** Base URL of the share worker, without a trailing slash. */
|
|
56
|
+
endpoint: string;
|
|
57
|
+
/** Bearer token, when the worker sets SHARE_AUTH_TOKEN. */
|
|
58
|
+
authToken?: string;
|
|
59
|
+
}
|
|
60
|
+
/** A created share. `url` carries the `#k=` key when the share is encrypted. */
|
|
61
|
+
export interface CreatedShare extends ShareResponse {
|
|
62
|
+
/** The base64url key, when encrypted; it decrypts the share's feedback. */
|
|
63
|
+
encryptionKey?: string;
|
|
64
|
+
}
|
|
65
|
+
declare const annotationContextSchema: z.ZodObject<{
|
|
66
|
+
before: z.ZodString;
|
|
67
|
+
after: z.ZodString;
|
|
68
|
+
hierarchy: z.ZodArray<z.ZodString, "many">;
|
|
69
|
+
lineStart: z.ZodOptional<z.ZodNumber>;
|
|
70
|
+
lineEnd: z.ZodOptional<z.ZodNumber>;
|
|
71
|
+
}, "strip", z.ZodTypeAny, {
|
|
72
|
+
before: string;
|
|
73
|
+
after: string;
|
|
74
|
+
hierarchy: string[];
|
|
75
|
+
lineStart?: number | undefined;
|
|
76
|
+
lineEnd?: number | undefined;
|
|
77
|
+
}, {
|
|
78
|
+
before: string;
|
|
79
|
+
after: string;
|
|
80
|
+
hierarchy: string[];
|
|
81
|
+
lineStart?: number | undefined;
|
|
82
|
+
lineEnd?: number | undefined;
|
|
83
|
+
}>;
|
|
84
|
+
export interface SharedAnnotation {
|
|
85
|
+
id: string;
|
|
86
|
+
snippet: string;
|
|
87
|
+
note: string;
|
|
88
|
+
createdAt: string;
|
|
89
|
+
filePath?: string;
|
|
90
|
+
canvasFile?: string;
|
|
91
|
+
context?: z.infer<typeof annotationContextSchema>;
|
|
92
|
+
attachments?: {
|
|
93
|
+
url: string;
|
|
94
|
+
mime?: string;
|
|
95
|
+
}[];
|
|
96
|
+
}
|
|
97
|
+
/** A feedback entry as a reviewer submitted it, decrypted. */
|
|
98
|
+
export interface SharedFeedbackEntry {
|
|
99
|
+
id: string;
|
|
100
|
+
shareId: string;
|
|
101
|
+
revision: number;
|
|
102
|
+
submittedAt: string;
|
|
103
|
+
author: {
|
|
104
|
+
id: string;
|
|
105
|
+
name: string;
|
|
106
|
+
};
|
|
107
|
+
annotations: SharedAnnotation[];
|
|
108
|
+
generalNote?: string;
|
|
109
|
+
/** Structured answers; absent in entries from share pages that predate them. */
|
|
110
|
+
responses?: SharedResponse[];
|
|
111
|
+
/** How many responses did not fit the wire shape (a newer page, or tampering) and were left out. */
|
|
112
|
+
droppedResponses?: number;
|
|
113
|
+
}
|
|
114
|
+
/** A feedback entry as the worker returns it. In an encrypted entry the text
|
|
115
|
+
* fields, the annotation context (as JSON) and `responses` (as one JSON
|
|
116
|
+
* blob) are ciphertext. */
|
|
117
|
+
export declare const wireFeedbackEntrySchema: z.ZodObject<{
|
|
118
|
+
id: z.ZodString;
|
|
119
|
+
shareId: z.ZodString;
|
|
120
|
+
revision: z.ZodNumber;
|
|
121
|
+
submittedAt: z.ZodString;
|
|
122
|
+
author: z.ZodObject<{
|
|
123
|
+
id: z.ZodString;
|
|
124
|
+
name: z.ZodString;
|
|
125
|
+
}, "strip", z.ZodTypeAny, {
|
|
126
|
+
name: string;
|
|
127
|
+
id: string;
|
|
128
|
+
}, {
|
|
129
|
+
name: string;
|
|
130
|
+
id: string;
|
|
131
|
+
}>;
|
|
132
|
+
annotations: z.ZodArray<z.ZodObject<{
|
|
133
|
+
id: z.ZodString;
|
|
134
|
+
snippet: z.ZodString;
|
|
135
|
+
note: z.ZodString;
|
|
136
|
+
createdAt: z.ZodString;
|
|
137
|
+
filePath: z.ZodOptional<z.ZodString>;
|
|
138
|
+
canvasFile: z.ZodOptional<z.ZodString>;
|
|
139
|
+
context: z.ZodOptional<z.ZodUnknown>;
|
|
140
|
+
attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
141
|
+
url: z.ZodString;
|
|
142
|
+
mime: z.ZodOptional<z.ZodString>;
|
|
143
|
+
}, "strip", z.ZodTypeAny, {
|
|
144
|
+
url: string;
|
|
145
|
+
mime?: string | undefined;
|
|
146
|
+
}, {
|
|
147
|
+
url: string;
|
|
148
|
+
mime?: string | undefined;
|
|
149
|
+
}>, "many">>;
|
|
150
|
+
}, "strip", z.ZodTypeAny, {
|
|
151
|
+
id: string;
|
|
152
|
+
createdAt: string;
|
|
153
|
+
note: string;
|
|
154
|
+
snippet: string;
|
|
155
|
+
context?: unknown;
|
|
156
|
+
filePath?: string | undefined;
|
|
157
|
+
canvasFile?: string | undefined;
|
|
158
|
+
attachments?: {
|
|
159
|
+
url: string;
|
|
160
|
+
mime?: string | undefined;
|
|
161
|
+
}[] | undefined;
|
|
162
|
+
}, {
|
|
163
|
+
id: string;
|
|
164
|
+
createdAt: string;
|
|
165
|
+
note: string;
|
|
166
|
+
snippet: string;
|
|
167
|
+
context?: unknown;
|
|
168
|
+
filePath?: string | undefined;
|
|
169
|
+
canvasFile?: string | undefined;
|
|
170
|
+
attachments?: {
|
|
171
|
+
url: string;
|
|
172
|
+
mime?: string | undefined;
|
|
173
|
+
}[] | undefined;
|
|
174
|
+
}>, "many">;
|
|
175
|
+
generalNote: z.ZodOptional<z.ZodString>;
|
|
176
|
+
responses: z.ZodOptional<z.ZodUnknown>;
|
|
177
|
+
encryption: z.ZodOptional<z.ZodObject<{
|
|
178
|
+
alg: z.ZodString;
|
|
179
|
+
v: z.ZodNumber;
|
|
180
|
+
}, "strip", z.ZodTypeAny, {
|
|
181
|
+
alg: string;
|
|
182
|
+
v: number;
|
|
183
|
+
}, {
|
|
184
|
+
alg: string;
|
|
185
|
+
v: number;
|
|
186
|
+
}>>;
|
|
187
|
+
}, "strip", z.ZodTypeAny, {
|
|
188
|
+
revision: number;
|
|
189
|
+
id: string;
|
|
190
|
+
author: {
|
|
191
|
+
name: string;
|
|
192
|
+
id: string;
|
|
193
|
+
};
|
|
194
|
+
annotations: {
|
|
195
|
+
id: string;
|
|
196
|
+
createdAt: string;
|
|
197
|
+
note: string;
|
|
198
|
+
snippet: string;
|
|
199
|
+
context?: unknown;
|
|
200
|
+
filePath?: string | undefined;
|
|
201
|
+
canvasFile?: string | undefined;
|
|
202
|
+
attachments?: {
|
|
203
|
+
url: string;
|
|
204
|
+
mime?: string | undefined;
|
|
205
|
+
}[] | undefined;
|
|
206
|
+
}[];
|
|
207
|
+
shareId: string;
|
|
208
|
+
submittedAt: string;
|
|
209
|
+
generalNote?: string | undefined;
|
|
210
|
+
responses?: unknown;
|
|
211
|
+
encryption?: {
|
|
212
|
+
alg: string;
|
|
213
|
+
v: number;
|
|
214
|
+
} | undefined;
|
|
215
|
+
}, {
|
|
216
|
+
revision: number;
|
|
217
|
+
id: string;
|
|
218
|
+
author: {
|
|
219
|
+
name: string;
|
|
220
|
+
id: string;
|
|
221
|
+
};
|
|
222
|
+
annotations: {
|
|
223
|
+
id: string;
|
|
224
|
+
createdAt: string;
|
|
225
|
+
note: string;
|
|
226
|
+
snippet: string;
|
|
227
|
+
context?: unknown;
|
|
228
|
+
filePath?: string | undefined;
|
|
229
|
+
canvasFile?: string | undefined;
|
|
230
|
+
attachments?: {
|
|
231
|
+
url: string;
|
|
232
|
+
mime?: string | undefined;
|
|
233
|
+
}[] | undefined;
|
|
234
|
+
}[];
|
|
235
|
+
shareId: string;
|
|
236
|
+
submittedAt: string;
|
|
237
|
+
generalNote?: string | undefined;
|
|
238
|
+
responses?: unknown;
|
|
239
|
+
encryption?: {
|
|
240
|
+
alg: string;
|
|
241
|
+
v: number;
|
|
242
|
+
} | undefined;
|
|
243
|
+
}>;
|
|
244
|
+
export type WireFeedbackEntry = z.infer<typeof wireFeedbackEntrySchema>;
|
|
245
|
+
export interface FeedbackPage {
|
|
246
|
+
entries: WireFeedbackEntry[];
|
|
247
|
+
/** Ids of entries that did not match the wire format; they are skipped. */
|
|
248
|
+
malformed: string[];
|
|
249
|
+
/** High-water mark: pass it back as `since` on the next call. */
|
|
250
|
+
latestAt?: string;
|
|
251
|
+
}
|
|
252
|
+
/** The share no longer exists on the worker (revoked or expired). */
|
|
253
|
+
export declare class ShareGoneError extends Error {
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Encrypt a plaintext SharePayload, returning a new payload whose secret
|
|
257
|
+
* fields are ciphertext + the `encryption` marker.
|
|
258
|
+
* Fields kept plaintext (and why):
|
|
259
|
+
* - `version`, `runtime.componentsVersion`: routing
|
|
260
|
+
* - `origin.revision`, `origin.createdAt`: indexing/display
|
|
261
|
+
* - `canvasFiles[].filename`: used as the route key by the worker
|
|
262
|
+
* Everything else (sessionId, label, compiledJs, sourceJsx) is encrypted.
|
|
263
|
+
*/
|
|
264
|
+
export declare function encryptSharePayload(payload: SharePayload, key: CryptoKey): Promise<SharePayload>;
|
|
265
|
+
/**
|
|
266
|
+
* POST the payload to the worker. Returns the `shareId` + public URL
|
|
267
|
+
* assigned by the worker. Throws on any HTTP error or a response that is
|
|
268
|
+
* not a share.
|
|
269
|
+
*/
|
|
270
|
+
export declare function pushShareToWorker(payload: SharePayload, config: ShareEndpoint): Promise<ShareResponse>;
|
|
271
|
+
/**
|
|
272
|
+
* Encrypt (unless `encryption` is false) and upload a plaintext payload.
|
|
273
|
+
* The URL of an encrypted share carries the `#k=` fragment, so it can be
|
|
274
|
+
* handed to reviewers as is.
|
|
275
|
+
*/
|
|
276
|
+
export declare function createShare(payload: SharePayload, config: ShareEndpoint & {
|
|
277
|
+
encryption?: boolean;
|
|
278
|
+
}): Promise<CreatedShare>;
|
|
279
|
+
/** Revoke a share with the owner token returned when it was created. */
|
|
280
|
+
export declare function revokeShareOnWorker(endpoint: string, shareId: string, ownerToken: string): Promise<void>;
|
|
281
|
+
/**
|
|
282
|
+
* Feedback submitted since `since` (the previous `latestAt`, or "" for all).
|
|
283
|
+
* Throws ShareGoneError when the worker no longer serves the share.
|
|
284
|
+
*/
|
|
285
|
+
export declare function fetchShareFeedback(endpoint: string, shareId: string, since: string): Promise<FeedbackPage>;
|
|
286
|
+
/**
|
|
287
|
+
* The plaintext form of a feedback entry. An encrypted entry needs the
|
|
288
|
+
* share's key; a plaintext one (from an unencrypted share) needs none.
|
|
289
|
+
* Throws if a text field fails to decrypt. Responses that do not fit are
|
|
290
|
+
* left out and counted in `droppedResponses`, so the rest of the entry stays.
|
|
291
|
+
*/
|
|
292
|
+
export declare function decryptFeedbackEntry(entry: WireFeedbackEntry, key: CryptoKey | null): Promise<SharedFeedbackEntry>;
|