@lincyaw/workspace 1.0.0-rc.147 → 1.0.0-rc.149
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/package.json +6 -6
- package/src/node/document-index.ts +11 -1
- package/src/node/tree-routes.ts +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/workspace",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.149",
|
|
4
4
|
"description": "Presmium's workspace service (presmium serve): documents, their history, reviews and the workspace site",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
"mime-types": "3.0.2",
|
|
39
39
|
"playwright-chromium": "1.64.1",
|
|
40
40
|
"yaml": "^2.9.1",
|
|
41
|
-
"@lincyaw/compiler": "1.0.0-rc.
|
|
42
|
-
"@lincyaw/design": "1.0.0-rc.
|
|
43
|
-
"@lincyaw/kernel": "1.0.0-rc.
|
|
44
|
-
"@lincyaw/server": "1.0.0-rc.
|
|
41
|
+
"@lincyaw/compiler": "1.0.0-rc.149",
|
|
42
|
+
"@lincyaw/design": "1.0.0-rc.149",
|
|
43
|
+
"@lincyaw/kernel": "1.0.0-rc.149",
|
|
44
|
+
"@lincyaw/server": "1.0.0-rc.149"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/mime-types": "^3.0.1",
|
|
48
|
-
"@lincyaw/mcp": "1.0.0-rc.
|
|
48
|
+
"@lincyaw/mcp": "1.0.0-rc.149"
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -66,6 +66,7 @@ export interface IndexEntry {
|
|
|
66
66
|
export interface TrashedEntry extends IndexEntry { record: TrashRecord }
|
|
67
67
|
|
|
68
68
|
interface FileState { mtimeMs: number, size: number, entry?: IndexEntry }
|
|
69
|
+
interface LocatedDocument { document: PresmiumDocument, dir: string, trashed: boolean }
|
|
69
70
|
|
|
70
71
|
const dirOf = (entry: string) => entry.split('/').slice(0, -1).join('/')
|
|
71
72
|
|
|
@@ -454,7 +455,7 @@ export class DocumentIndex {
|
|
|
454
455
|
}
|
|
455
456
|
|
|
456
457
|
/** The whole document by ID, read from its file (in the workspace or in the trash). */
|
|
457
|
-
async read(id: DocumentId): Promise<
|
|
458
|
+
async read(id: DocumentId): Promise<LocatedDocument | undefined> {
|
|
458
459
|
const entry = this.#now().documents.get(id) ?? this.#trash.get(id)
|
|
459
460
|
if (!entry) return undefined
|
|
460
461
|
try {
|
|
@@ -566,7 +567,16 @@ export class DocumentIndex {
|
|
|
566
567
|
}
|
|
567
568
|
|
|
568
569
|
async embedSource(id: DocumentId, block: BlockId): Promise<EmbedSource> {
|
|
570
|
+
return this.#embedSource(id, block, await this.read(id))
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/** One current file snapshot for this batch only; later requests read the source again. */
|
|
574
|
+
async embedSources(id: DocumentId, blocks: readonly BlockId[]): Promise<EmbedSource[]> {
|
|
569
575
|
const located = await this.read(id)
|
|
576
|
+
return blocks.map(block => this.#embedSource(id, block, located))
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
#embedSource(id: DocumentId, block: BlockId, located: LocatedDocument | undefined): EmbedSource {
|
|
570
580
|
const blocks = located && blockSubtree(located.document, block)
|
|
571
581
|
if (!located || !blocks) return { document: id, title: located?.document.metadata.title ?? '', block, missing: true, ...located?.trashed ? { trashed: true } : {} }
|
|
572
582
|
const { document } = located
|
package/src/node/tree-routes.ts
CHANGED
|
@@ -77,6 +77,19 @@ export function treeRoutes(index: DocumentIndex, operations: TreeOperations | un
|
|
|
77
77
|
}),
|
|
78
78
|
'document/preview': get(request => index.preview(required(request, 'id'), { ...optional(request, 'section') !== undefined ? { section: optional(request, 'section') } : {}, ...optional(request, 'block') !== undefined ? { block: optional(request, 'block') } : {} })),
|
|
79
79
|
'embed/source': get(request => index.embedSource(required(request, 'document'), required(request, 'block'))),
|
|
80
|
+
'embed/sources': {
|
|
81
|
+
role: 'reader',
|
|
82
|
+
maxBody: 32768,
|
|
83
|
+
handle: request => catchRequestErrors(async () => {
|
|
84
|
+
if (request.method !== 'POST') throw new RequestError(405, 'POST')
|
|
85
|
+
const body: unknown = await request.json().catch(() => undefined)
|
|
86
|
+
if (!isRecord(body) || !isId(body.document) || !Array.isArray(body.blocks)
|
|
87
|
+
|| body.blocks.length < 1 || body.blocks.length > 20 || !body.blocks.every(isId)
|
|
88
|
+
|| Object.keys(body).some(key => key !== 'document' && key !== 'blocks')) throw new RequestError(400, 'embed.sources-invalid')
|
|
89
|
+
await index.ready()
|
|
90
|
+
return jsonResponse(await index.embedSources(body.document, body.blocks))
|
|
91
|
+
}),
|
|
92
|
+
},
|
|
80
93
|
'tree/attention': get(() => index.attention()),
|
|
81
94
|
'tree/events': {
|
|
82
95
|
role: 'reader',
|