dsh-plugin-inspiration-workbench 0.10.0 → 0.13.2
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 +27 -1
- package/lib/client.js +4175 -181
- package/lib/client.js.map +4 -4
- package/package.json +8 -2
- package/src/client/board.js +484 -29
- package/src/client/card-tools.js +1 -0
- package/src/client/docx-text.js +93 -0
- package/src/client/file-preview.js +103 -0
- package/src/client/file-store.js +74 -0
- package/src/client/flow-recorder.js +58 -0
- package/src/client/index.jsx +3 -4
- package/src/client/persistence.js +31 -0
- package/src/client/popovers.js +2 -2
- package/src/client/render.js +1 -0
- package/src/client/sessions.js +79 -8
- package/src/client/styles.css +116 -2
- package/src/client/task-ai.js +83 -0
- package/src/client/task-controller.js +620 -0
- package/src/client/task-intelligence.js +545 -0
- package/src/client/task-model.js +264 -0
- package/src/client/task-store.js +118 -0
- package/src/client/task-view.css +1263 -0
- package/src/client/task-view.js +1688 -0
- package/src/host/index.js +69 -7
package/src/client/card-tools.js
CHANGED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** Minimal, dependency-free DOCX text extraction for browser previews. */
|
|
2
|
+
function findEndOfCentralDirectory(view) {
|
|
3
|
+
const start = Math.max(0, view.byteLength - 65557);
|
|
4
|
+
for (let index = view.byteLength - 22; index >= start; index -= 1) {
|
|
5
|
+
if (view.getUint32(index, true) === 0x06054b50) return index;
|
|
6
|
+
}
|
|
7
|
+
return -1;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async function inflate(data) {
|
|
11
|
+
if (typeof DecompressionStream === 'undefined') throw new Error('当前浏览器不支持 DOCX 解压');
|
|
12
|
+
const stream = new Blob([data]).stream().pipeThrough(new DecompressionStream('deflate-raw'));
|
|
13
|
+
return await new Response(stream).arrayBuffer();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function readZipEntry(buffer, entryName) {
|
|
17
|
+
const view = new DataView(buffer);
|
|
18
|
+
const decoder = new TextDecoder();
|
|
19
|
+
const end = findEndOfCentralDirectory(view);
|
|
20
|
+
if (end < 0) throw new Error('不是有效的 DOCX 文件');
|
|
21
|
+
const count = view.getUint16(end + 10, true);
|
|
22
|
+
let cursor = view.getUint32(end + 16, true);
|
|
23
|
+
for (let index = 0; index < count; index += 1) {
|
|
24
|
+
if (view.getUint32(cursor, true) !== 0x02014b50) break;
|
|
25
|
+
const method = view.getUint16(cursor + 10, true);
|
|
26
|
+
const compressedSize = view.getUint32(cursor + 20, true);
|
|
27
|
+
const nameLength = view.getUint16(cursor + 28, true);
|
|
28
|
+
const extraLength = view.getUint16(cursor + 30, true);
|
|
29
|
+
const commentLength = view.getUint16(cursor + 32, true);
|
|
30
|
+
const localOffset = view.getUint32(cursor + 42, true);
|
|
31
|
+
const name = decoder.decode(new Uint8Array(buffer, cursor + 46, nameLength));
|
|
32
|
+
if (name === entryName) {
|
|
33
|
+
if (view.getUint32(localOffset, true) !== 0x04034b50) throw new Error('DOCX 本地文件头损坏');
|
|
34
|
+
const localNameLength = view.getUint16(localOffset + 26, true);
|
|
35
|
+
const localExtraLength = view.getUint16(localOffset + 28, true);
|
|
36
|
+
const offset = localOffset + 30 + localNameLength + localExtraLength;
|
|
37
|
+
const bytes = buffer.slice(offset, offset + compressedSize);
|
|
38
|
+
if (method === 0) return bytes;
|
|
39
|
+
if (method === 8) return await inflate(bytes);
|
|
40
|
+
throw new Error('DOCX 使用了暂不支持的压缩方式');
|
|
41
|
+
}
|
|
42
|
+
cursor += 46 + nameLength + extraLength + commentLength;
|
|
43
|
+
}
|
|
44
|
+
throw new Error('DOCX 中找不到 document.xml');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function xmlText(xml) {
|
|
48
|
+
return xml
|
|
49
|
+
.replace(/<\/w:(p|tr)\b[^>]*>/g, '\n')
|
|
50
|
+
.replace(/<\/w:tc\b[^>]*>/g, '\t')
|
|
51
|
+
.replace(/<[^>]+>/g, '')
|
|
52
|
+
.replace(/</g, '<')
|
|
53
|
+
.replace(/>/g, '>')
|
|
54
|
+
.replace(/"/g, '"')
|
|
55
|
+
.replace(/'/g, "'")
|
|
56
|
+
.replace(/&/g, '&')
|
|
57
|
+
.replace(/\r/g, '')
|
|
58
|
+
.replace(/[ \t]+/g, ' ')
|
|
59
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
60
|
+
.trim();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function extractDocxText(buffer) {
|
|
64
|
+
const bytes = await readZipEntry(buffer, 'word/document.xml');
|
|
65
|
+
const xml = new TextDecoder().decode(bytes);
|
|
66
|
+
return xmlText(xml).slice(0, 240000);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function extractPptxText(buffer) {
|
|
70
|
+
const decoder = new TextDecoder();
|
|
71
|
+
const slides = [];
|
|
72
|
+
const view = new DataView(buffer);
|
|
73
|
+
const end = findEndOfCentralDirectory(view);
|
|
74
|
+
if (end < 0) throw new Error('不是有效的 PPTX 文件');
|
|
75
|
+
const count = view.getUint16(end + 10, true);
|
|
76
|
+
let cursor = view.getUint32(end + 16, true);
|
|
77
|
+
const names = [];
|
|
78
|
+
for (let index = 0; index < count; index += 1) {
|
|
79
|
+
if (view.getUint32(cursor, true) !== 0x02014b50) break;
|
|
80
|
+
const nameLength = view.getUint16(cursor + 28, true);
|
|
81
|
+
const extraLength = view.getUint16(cursor + 30, true);
|
|
82
|
+
const commentLength = view.getUint16(cursor + 32, true);
|
|
83
|
+
const name = decoder.decode(new Uint8Array(buffer, cursor + 46, nameLength));
|
|
84
|
+
if (/^ppt\/slides\/slide\d+\.xml$/.test(name)) names.push(name);
|
|
85
|
+
cursor += 46 + nameLength + extraLength + commentLength;
|
|
86
|
+
}
|
|
87
|
+
names.sort((a, b) => Number(a.match(/\d+/)[0]) - Number(b.match(/\d+/)[0]));
|
|
88
|
+
for (const name of names.slice(0, 30)) {
|
|
89
|
+
const xml = decoder.decode(await readZipEntry(buffer, name));
|
|
90
|
+
slides.push('## ' + name + '\n' + xmlText(xml));
|
|
91
|
+
}
|
|
92
|
+
return slides.join('\n\n').slice(0, 240000);
|
|
93
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { extractDocxText, extractPptxText } from './docx-text.js';
|
|
2
|
+
|
|
3
|
+
export function fileKind(file) {
|
|
4
|
+
const type = String(file?.type || '').toLowerCase();
|
|
5
|
+
const name = String(file?.name || '').toLowerCase();
|
|
6
|
+
if (type.startsWith('image/') || /\.(png|jpe?g|gif|webp|svg|bmp|avif)$/.test(name)) return 'image';
|
|
7
|
+
if (type === 'application/pdf' || /\.pdf$/.test(name)) return 'pdf';
|
|
8
|
+
if (/\.(docx)$/.test(name)) return 'docx';
|
|
9
|
+
if (/\.(pptx)$/.test(name)) return 'pptx';
|
|
10
|
+
if (/\.(html?|xhtml)$/.test(name) || type === 'text/html') return 'html';
|
|
11
|
+
if (type.startsWith('text/') || /\.(txt|md|markdown|json|jsonl|csv|tsv|xml|ya?ml|log|js|mjs|cjs|ts|tsx|jsx|css|scss|less|py|java|go|rs|sql|sh|bash|zsh|env|ini|toml|vue|svelte)$/.test(name)) return 'text';
|
|
12
|
+
return 'other';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function formatBytes(value) {
|
|
16
|
+
const size = Number(value) || 0;
|
|
17
|
+
if (size < 1024) return size + ' B';
|
|
18
|
+
if (size < 1024 * 1024) return (size / 1024).toFixed(size < 10240 ? 1 : 0) + ' KB';
|
|
19
|
+
return (size / 1024 / 1024).toFixed(1) + ' MB';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function buildFilePreview(file) {
|
|
23
|
+
const kind = fileKind(file);
|
|
24
|
+
if (kind === 'image' || kind === 'pdf') return { kind, url: URL.createObjectURL(file.blob || file) };
|
|
25
|
+
if (kind === 'docx') return { kind, text: await extractDocxText(await (file.blob || file).arrayBuffer()) };
|
|
26
|
+
if (kind === 'pptx') return { kind, text: await extractPptxText(await (file.blob || file).arrayBuffer()) };
|
|
27
|
+
if (kind === 'html' || kind === 'text') {
|
|
28
|
+
const buffer = await (file.blob || file).slice(0, 1024 * 1024).text();
|
|
29
|
+
return { kind, text: buffer };
|
|
30
|
+
}
|
|
31
|
+
return { kind: 'other', text: '暂不支持此格式的直接预览,可下载后查看。' };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function openFilePreview(file, options = {}) {
|
|
35
|
+
const dialog = document.createElement('dialog');
|
|
36
|
+
dialog.className = 'iwb-file-dialog';
|
|
37
|
+
dialog.setAttribute('aria-label', file.name || '文件预览');
|
|
38
|
+
document.body.appendChild(dialog);
|
|
39
|
+
const close = () => dialog.close();
|
|
40
|
+
dialog.innerHTML = '<div class="iwb-file-dialog-head"><div><h2></h2><p></p></div><button type="button" class="iwb-file-dialog-close" aria-label="关闭预览">×</button></div><div class="iwb-file-dialog-body"></div><div class="iwb-file-dialog-foot"><a class="iwb-btn" download>下载文件</a></div>';
|
|
41
|
+
dialog.querySelector('h2').textContent = file.name || '文件预览';
|
|
42
|
+
dialog.querySelector('p').textContent = formatBytes(file.size) + ' · ' + (file.type || '文件');
|
|
43
|
+
dialog.querySelector('.iwb-file-dialog-close').addEventListener('click', close);
|
|
44
|
+
const download = dialog.querySelector('a');
|
|
45
|
+
download.download = file.name || 'download';
|
|
46
|
+
const body = dialog.querySelector('.iwb-file-dialog-body');
|
|
47
|
+
body.textContent = '正在读取预览…';
|
|
48
|
+
let url = '';
|
|
49
|
+
dialog.addEventListener('close', () => {
|
|
50
|
+
if (url) URL.revokeObjectURL(url);
|
|
51
|
+
dialog.remove();
|
|
52
|
+
options.onClose?.();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
void buildFilePreview(file).then((preview) => {
|
|
56
|
+
body.textContent = '';
|
|
57
|
+
if (preview.url) {
|
|
58
|
+
url = preview.url;
|
|
59
|
+
download.href = url;
|
|
60
|
+
if (preview.kind === 'image') {
|
|
61
|
+
const image = document.createElement('img');
|
|
62
|
+
image.className = 'iwb-file-preview-image';
|
|
63
|
+
image.alt = file.name || '图片预览';
|
|
64
|
+
image.src = url;
|
|
65
|
+
body.appendChild(image);
|
|
66
|
+
} else {
|
|
67
|
+
const frame = document.createElement('iframe');
|
|
68
|
+
frame.className = 'iwb-file-preview-frame';
|
|
69
|
+
frame.sandbox = '';
|
|
70
|
+
frame.src = url;
|
|
71
|
+
body.appendChild(frame);
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (preview.kind === 'html') {
|
|
76
|
+
const frame = document.createElement('iframe');
|
|
77
|
+
frame.className = 'iwb-file-preview-frame';
|
|
78
|
+
frame.sandbox = '';
|
|
79
|
+
frame.srcdoc = preview.text;
|
|
80
|
+
body.appendChild(frame);
|
|
81
|
+
download.href = URL.createObjectURL(file.blob || file);
|
|
82
|
+
url = download.href;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const pre = document.createElement('pre');
|
|
86
|
+
pre.className = 'iwb-file-preview-text';
|
|
87
|
+
pre.textContent = preview.text || '这个文件没有可显示的文本内容。';
|
|
88
|
+
body.appendChild(pre);
|
|
89
|
+
if (preview.kind !== 'other') {
|
|
90
|
+
download.href = URL.createObjectURL(file.blob || file);
|
|
91
|
+
url = download.href;
|
|
92
|
+
} else {
|
|
93
|
+
download.href = URL.createObjectURL(file.blob || file);
|
|
94
|
+
url = download.href;
|
|
95
|
+
}
|
|
96
|
+
}).catch((error) => {
|
|
97
|
+
body.textContent = error?.message || '预览失败,请下载后查看。';
|
|
98
|
+
download.href = URL.createObjectURL(file.blob || file);
|
|
99
|
+
url = download.href;
|
|
100
|
+
});
|
|
101
|
+
dialog.showModal();
|
|
102
|
+
return dialog;
|
|
103
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** Binary file persistence for canvas cards. Metadata stays in layout JSON; blobs live in IndexedDB. */
|
|
2
|
+
const DB_NAME = 'inspiration-workbench-files';
|
|
3
|
+
const STORE_NAME = 'files';
|
|
4
|
+
|
|
5
|
+
function openDatabase() {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const request = indexedDB.open(DB_NAME, 1);
|
|
8
|
+
request.onupgradeneeded = () => {
|
|
9
|
+
const db = request.result;
|
|
10
|
+
if (!db.objectStoreNames.contains(STORE_NAME)) db.createObjectStore(STORE_NAME, { keyPath: 'id' });
|
|
11
|
+
};
|
|
12
|
+
request.onsuccess = () => resolve(request.result);
|
|
13
|
+
request.onerror = () => reject(request.error);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createFileStore() {
|
|
18
|
+
const memory = new Map();
|
|
19
|
+
let databasePromise = null;
|
|
20
|
+
const database = () => {
|
|
21
|
+
if (typeof indexedDB === 'undefined') return null;
|
|
22
|
+
databasePromise ||= openDatabase().catch(() => null);
|
|
23
|
+
return databasePromise;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
async put(file) {
|
|
28
|
+
const id = file.id || 'file-' + crypto.randomUUID();
|
|
29
|
+
const record = {
|
|
30
|
+
id,
|
|
31
|
+
name: file.name || '未命名文件',
|
|
32
|
+
type: file.type || 'application/octet-stream',
|
|
33
|
+
size: Number(file.size) || 0,
|
|
34
|
+
lastModified: Number(file.lastModified) || Date.now(),
|
|
35
|
+
blob: file.blob || file,
|
|
36
|
+
};
|
|
37
|
+
memory.set(id, record);
|
|
38
|
+
const db = await database();
|
|
39
|
+
if (db) {
|
|
40
|
+
await new Promise((resolve, reject) => {
|
|
41
|
+
const transaction = db.transaction(STORE_NAME, 'readwrite');
|
|
42
|
+
transaction.objectStore(STORE_NAME).put(record);
|
|
43
|
+
transaction.oncomplete = resolve;
|
|
44
|
+
transaction.onerror = () => reject(transaction.error);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return id;
|
|
48
|
+
},
|
|
49
|
+
async get(id) {
|
|
50
|
+
const db = await database();
|
|
51
|
+
if (db) {
|
|
52
|
+
const stored = await new Promise((resolve, reject) => {
|
|
53
|
+
const request = db.transaction(STORE_NAME, 'readonly').objectStore(STORE_NAME).get(id);
|
|
54
|
+
request.onsuccess = () => resolve(request.result || null);
|
|
55
|
+
request.onerror = () => reject(request.error);
|
|
56
|
+
});
|
|
57
|
+
if (stored) return stored;
|
|
58
|
+
}
|
|
59
|
+
return memory.get(id) || null;
|
|
60
|
+
},
|
|
61
|
+
async remove(id) {
|
|
62
|
+
memory.delete(id);
|
|
63
|
+
const db = await database();
|
|
64
|
+
if (db) {
|
|
65
|
+
await new Promise((resolve, reject) => {
|
|
66
|
+
const transaction = db.transaction(STORE_NAME, 'readwrite');
|
|
67
|
+
transaction.objectStore(STORE_NAME).delete(id);
|
|
68
|
+
transaction.oncomplete = resolve;
|
|
69
|
+
transaction.onerror = () => reject(transaction.error);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Bounded, append-only record of actual pipeline delivery attempts. */
|
|
2
|
+
export function createFlowRecorder({ initialEvents, onChange, now = () => Date.now(), limit = 500 }) {
|
|
3
|
+
let events = (Array.isArray(initialEvents) ? initialEvents : []).filter((event) => event && typeof event === 'object').slice(-limit);
|
|
4
|
+
let sequence = events.length;
|
|
5
|
+
|
|
6
|
+
function notify() {
|
|
7
|
+
onChange?.(events.slice());
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function record(input) {
|
|
11
|
+
const sourceSessionId = String(input?.sourceSessionId || '');
|
|
12
|
+
const targetId = String(input?.targetId || '');
|
|
13
|
+
if (!sourceSessionId || !targetId) return null;
|
|
14
|
+
const targetKind = input?.targetKind === 'note' ? 'note' : 'session';
|
|
15
|
+
const event = {
|
|
16
|
+
id: String(input?.id || 'flow-' + now().toString(36) + '-' + (++sequence).toString(36)),
|
|
17
|
+
at: Number(input?.at) || now(),
|
|
18
|
+
canvasId: String(input?.canvasId || ''),
|
|
19
|
+
taskId: String(input?.taskId || ''),
|
|
20
|
+
sourceSessionId,
|
|
21
|
+
targetId,
|
|
22
|
+
targetKind,
|
|
23
|
+
edgeKey: String(input?.edgeKey || sourceSessionId + '=>' + targetKind + ':' + targetId),
|
|
24
|
+
status: String(input?.status || 'waiting'),
|
|
25
|
+
mode: input?.mode === 'draft' ? 'draft' : 'send',
|
|
26
|
+
message: String(input?.message || '').slice(0, 500),
|
|
27
|
+
fingerprint: String(input?.fingerprint || '').slice(0, 180),
|
|
28
|
+
};
|
|
29
|
+
events = [...events, event].slice(-limit);
|
|
30
|
+
notify();
|
|
31
|
+
return event;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
record,
|
|
36
|
+
events: () => events.slice(),
|
|
37
|
+
latestByEdge() {
|
|
38
|
+
const latest = new Map();
|
|
39
|
+
for (const event of events) {
|
|
40
|
+
const previous = latest.get(event.edgeKey);
|
|
41
|
+
if (!previous || event.at >= previous.at) latest.set(event.edgeKey, event);
|
|
42
|
+
}
|
|
43
|
+
return latest;
|
|
44
|
+
},
|
|
45
|
+
forCanvas(canvasId) {
|
|
46
|
+
if (!canvasId) return [];
|
|
47
|
+
return events.filter((event) => event.canvasId === canvasId);
|
|
48
|
+
},
|
|
49
|
+
replace(next) {
|
|
50
|
+
events = (Array.isArray(next) ? next : []).filter((event) => event && typeof event === 'object').slice(-limit);
|
|
51
|
+
sequence = events.length;
|
|
52
|
+
},
|
|
53
|
+
clear() {
|
|
54
|
+
events = [];
|
|
55
|
+
notify();
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
package/src/client/index.jsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { useEffect, useRef } from 'react';
|
|
2
2
|
import styles from './styles.css';
|
|
3
|
+
import taskStyles from './task-view.css';
|
|
3
4
|
import { createBoard } from './board';
|
|
4
5
|
import { createSessionsAdapter } from './sessions';
|
|
5
6
|
import { createApprovalHub } from './approvals';
|
|
@@ -13,7 +14,6 @@ const zh = {
|
|
|
13
14
|
title: '灵感工作台',
|
|
14
15
|
new: '新建会话卡',
|
|
15
16
|
arrange: '排列',
|
|
16
|
-
'attach.file': '附件',
|
|
17
17
|
canvas: '画布',
|
|
18
18
|
'canvas.title': '画布',
|
|
19
19
|
'canvas.active': '当前画布:{name}',
|
|
@@ -313,7 +313,6 @@ const en = {
|
|
|
313
313
|
title: 'Inspiration workbench',
|
|
314
314
|
new: 'New conversation card',
|
|
315
315
|
arrange: 'Arrange',
|
|
316
|
-
'attach.file': 'Attachment',
|
|
317
316
|
canvas: 'Canvas',
|
|
318
317
|
'canvas.title': 'Canvas',
|
|
319
318
|
'canvas.active': 'Current canvas: {name}',
|
|
@@ -730,7 +729,7 @@ function WorkbenchPanel() {
|
|
|
730
729
|
return React.createElement('div', { ref: hostRef, style: { height: '100%', minHeight: 0 } });
|
|
731
730
|
}
|
|
732
731
|
|
|
733
|
-
export const inject = ['slots', 'locale', 'sessions', 'layout', 'uiWorkspace', 'remote', 'remote.session', '
|
|
732
|
+
export const inject = ['slots', 'locale', 'sessions', 'layout', 'uiWorkspace', 'remote', 'remote.session', 'workspaces', 'conversation'];
|
|
734
733
|
|
|
735
734
|
export async function apply(ctx) {
|
|
736
735
|
runtime.ctx = ctx;
|
|
@@ -741,7 +740,7 @@ export async function apply(ctx) {
|
|
|
741
740
|
styleNode.dataset.iwb = '1';
|
|
742
741
|
document.head.appendChild(styleNode);
|
|
743
742
|
}
|
|
744
|
-
styleNode.textContent = styles;
|
|
743
|
+
styleNode.textContent = styles + '\n' + taskStyles;
|
|
745
744
|
|
|
746
745
|
const locale = ctx.get?.('locale') ?? ctx.locale;
|
|
747
746
|
if (locale?.register) {
|
|
@@ -96,3 +96,34 @@ export async function pushCanvases(canvases, activeCanvas) {
|
|
|
96
96
|
return null;
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
+
|
|
100
|
+
/** Task state and transition history, bounded by the Host on every write. */
|
|
101
|
+
export async function fetchTaskState() {
|
|
102
|
+
try {
|
|
103
|
+
const response = await request('/tasks', { method: 'GET' });
|
|
104
|
+
const body = await response.json();
|
|
105
|
+
if (!body || !Array.isArray(body.tasks) || !Array.isArray(body.flowEvents)) return null;
|
|
106
|
+
return {
|
|
107
|
+
rev: Number(body.rev) || 0,
|
|
108
|
+
updatedAt: Number(body.updatedAt) || 0,
|
|
109
|
+
tasks: body.tasks,
|
|
110
|
+
flowEvents: body.flowEvents,
|
|
111
|
+
};
|
|
112
|
+
} catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export async function pushTaskState(tasks, flowEvents, clientId) {
|
|
118
|
+
try {
|
|
119
|
+
const response = await request('/tasks', {
|
|
120
|
+
method: 'PUT',
|
|
121
|
+
headers: { 'content-type': 'application/json' },
|
|
122
|
+
body: JSON.stringify({ tasks, flowEvents, clientId }),
|
|
123
|
+
});
|
|
124
|
+
const body = await response.json().catch(() => ({}));
|
|
125
|
+
return { rev: Number(body?.rev) || 0, updatedAt: Number(body?.updatedAt) || 0 };
|
|
126
|
+
} catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
package/src/client/popovers.js
CHANGED
|
@@ -376,7 +376,7 @@ export function createWorkspaceMenu(deps) {
|
|
|
376
376
|
}
|
|
377
377
|
const workspaces = adapter.listWorkspaces?.() || [];
|
|
378
378
|
if (!workspaces.length) {
|
|
379
|
-
|
|
379
|
+
toast('当前没有可用工作区,请先在 DSH 中添加工作区,再创建会话');
|
|
380
380
|
return;
|
|
381
381
|
}
|
|
382
382
|
const pop = el('div', 'iwb-popover iwb-workspaces');
|
|
@@ -544,7 +544,7 @@ export function createSettingsMenu(deps) {
|
|
|
544
544
|
resetBtn.type = 'button';
|
|
545
545
|
resetBtn.textContent = t('settings.reset');
|
|
546
546
|
resetBtn.addEventListener('click', () => {
|
|
547
|
-
|
|
547
|
+
resetLayout();
|
|
548
548
|
closeSettings();
|
|
549
549
|
toast(t('settings.resetDone'));
|
|
550
550
|
});
|
package/src/client/render.js
CHANGED
|
@@ -253,6 +253,7 @@ export function createRenderers(deps) {
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
function questionNode(card, pending) {
|
|
256
|
+
const answerable = pending?.answerable !== false;
|
|
256
257
|
const draft = answerDraft(card, pending);
|
|
257
258
|
const node = el('div', 'iwb-question');
|
|
258
259
|
const head = el('div', 'iwb-question-head');
|
package/src/client/sessions.js
CHANGED
|
@@ -501,6 +501,21 @@ export function createSessionsAdapter(ctx) {
|
|
|
501
501
|
}
|
|
502
502
|
}
|
|
503
503
|
|
|
504
|
+
function retainCompatible(sessionId) {
|
|
505
|
+
if (typeof sessions?.retain === 'function') {
|
|
506
|
+
return sessions.retain(sessionId, { source: 'inspirationWorkbench' });
|
|
507
|
+
}
|
|
508
|
+
if (typeof sessions?.binding === 'function') {
|
|
509
|
+
const wrap = (binding) => ({ binding, ready: Promise.resolve(binding), release: () => {} });
|
|
510
|
+
const existing = sessions.binding(sessionId);
|
|
511
|
+
if (existing) return wrap(existing);
|
|
512
|
+
sessions.open?.(sessionId);
|
|
513
|
+
const opened = sessions.binding(sessionId);
|
|
514
|
+
if (opened) return wrap(opened);
|
|
515
|
+
}
|
|
516
|
+
throw new Error('当前 DSH 版本不支持会话绑定,无法读取这条会话');
|
|
517
|
+
}
|
|
518
|
+
|
|
504
519
|
function open(sessionId, onChange) {
|
|
505
520
|
if (!sessions) {
|
|
506
521
|
onChange();
|
|
@@ -508,13 +523,7 @@ export function createSessionsAdapter(ctx) {
|
|
|
508
523
|
}
|
|
509
524
|
let entry = entries.get(sessionId);
|
|
510
525
|
if (!entry) {
|
|
511
|
-
let reference;
|
|
512
|
-
try {
|
|
513
|
-
reference = sessions.retain(sessionId, { source: 'inspirationWorkbench' });
|
|
514
|
-
} catch {
|
|
515
|
-
// Older builds type `source` as a closed union; the tag is only bookkeeping.
|
|
516
|
-
reference = sessions.retain(sessionId, { source: 'gateway' });
|
|
517
|
-
}
|
|
526
|
+
let reference = retainCompatible(sessionId);
|
|
518
527
|
entry = { reference, binding: null, listeners: new Set(), unsubs: [] };
|
|
519
528
|
entries.set(sessionId, entry);
|
|
520
529
|
if (reference.binding) attach(sessionId, entry);
|
|
@@ -746,7 +755,7 @@ export function createSessionsAdapter(ctx) {
|
|
|
746
755
|
|
|
747
756
|
const remoteSession = () => {
|
|
748
757
|
try {
|
|
749
|
-
return ctx.
|
|
758
|
+
return ctx.get?.('remote')?.session;
|
|
750
759
|
} catch {
|
|
751
760
|
return undefined;
|
|
752
761
|
}
|
|
@@ -757,6 +766,11 @@ export function createSessionsAdapter(ctx) {
|
|
|
757
766
|
let catalogPromise = null;
|
|
758
767
|
|
|
759
768
|
async function modelCatalog() {
|
|
769
|
+
if (!remoteSession()?.modelCatalog) {
|
|
770
|
+
catalogCache = { groups: [] };
|
|
771
|
+
catalogAt = Date.now();
|
|
772
|
+
return catalogCache;
|
|
773
|
+
}
|
|
760
774
|
const stale = catalogCache && Date.now() - catalogAt > 60000;
|
|
761
775
|
if (catalogCache && !stale) return catalogCache;
|
|
762
776
|
if (stale) {
|
|
@@ -868,6 +882,10 @@ export function createSessionsAdapter(ctx) {
|
|
|
868
882
|
}
|
|
869
883
|
}
|
|
870
884
|
|
|
885
|
+
function modelSelection(sessionId) {
|
|
886
|
+
return selectionOf(sessionId);
|
|
887
|
+
}
|
|
888
|
+
|
|
871
889
|
async function selectModel(sessionId, selection) {
|
|
872
890
|
const remote = remoteSession();
|
|
873
891
|
if (!remote?.selectModel) throw new Error('当前版本没有提供模型切换');
|
|
@@ -943,6 +961,21 @@ export function createSessionsAdapter(ctx) {
|
|
|
943
961
|
return listWorkspaces().find((workspace) => workspace.sessionIds.includes(sessionId)) || null;
|
|
944
962
|
}
|
|
945
963
|
|
|
964
|
+
async function createWorkspace({ path }) {
|
|
965
|
+
const service = workspacesService();
|
|
966
|
+
if (!service?.create) throw new Error('当前版本没有提供工作区创建接口');
|
|
967
|
+
const result = await service.create({ path });
|
|
968
|
+
const workspace = result?.value?.workspace || result?.workspace || result?.value || result;
|
|
969
|
+
const id = workspace?.workspaceId || workspace?.id;
|
|
970
|
+
if (!id) throw new Error('工作区创建失败,请检查路径是否有效');
|
|
971
|
+
return {
|
|
972
|
+
id: String(id),
|
|
973
|
+
title: workspace.title || path.split('/').filter(Boolean).pop() || path,
|
|
974
|
+
path: workspace.path || path,
|
|
975
|
+
sessionIds: workspace.sessionIds || [],
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
|
|
946
979
|
async function createSession(options) {
|
|
947
980
|
if (!sessions?.create) throw new Error('当前版本没有提供静默新建会话的接口');
|
|
948
981
|
const request = {};
|
|
@@ -951,11 +984,46 @@ export function createSessionsAdapter(ctx) {
|
|
|
951
984
|
return await sessions.create(request);
|
|
952
985
|
}
|
|
953
986
|
|
|
987
|
+
async function waitForReady(sessionId, options) {
|
|
988
|
+
const timeoutMs = Number(options?.timeoutMs) || 15000;
|
|
989
|
+
const startedAt = Date.now();
|
|
990
|
+
while (Date.now() - startedAt < timeoutMs) {
|
|
991
|
+
if (bindingOf(sessionId)) return true;
|
|
992
|
+
await new Promise((resolve) => setTimeout(resolve, 60));
|
|
993
|
+
}
|
|
994
|
+
throw new Error('会话打开超时,请稍后重试');
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
function listRecentSessions(limit) {
|
|
998
|
+
try {
|
|
999
|
+
const rows = sessions?.list?.getSnapshot?.()?.byId || {};
|
|
1000
|
+
const cap = Math.max(1, Math.min(100, Number(limit) || 30));
|
|
1001
|
+
return Object.values(rows)
|
|
1002
|
+
.map((row) => {
|
|
1003
|
+
const sessionId = row.sessionId || row.id || row.key || '';
|
|
1004
|
+
const activityAt = Number(row.lastActivityAt || row.activityAt || row.updatedAt || row.createdAt) || 0;
|
|
1005
|
+
return {
|
|
1006
|
+
sessionId: String(sessionId),
|
|
1007
|
+
title: row.displayTitle || row.title || '未命名会话',
|
|
1008
|
+
activityAt,
|
|
1009
|
+
archived: Boolean(row.archived || row.archivedAt || row.deletedAt),
|
|
1010
|
+
workspace: workspaceOf(String(sessionId))?.title || '',
|
|
1011
|
+
};
|
|
1012
|
+
})
|
|
1013
|
+
.filter((row) => row.sessionId && !row.archived)
|
|
1014
|
+
.sort((left, right) => right.activityAt - left.activityAt)
|
|
1015
|
+
.slice(0, cap);
|
|
1016
|
+
} catch {
|
|
1017
|
+
return [];
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
|
|
954
1021
|
return {
|
|
955
1022
|
available: Boolean(sessions),
|
|
956
1023
|
hasModelPicker: () => Boolean(remoteSession()?.selectModel),
|
|
957
1024
|
modelCatalog,
|
|
958
1025
|
selectModel,
|
|
1026
|
+
modelSelection,
|
|
959
1027
|
selectionOf,
|
|
960
1028
|
answerQuestion,
|
|
961
1029
|
open,
|
|
@@ -966,6 +1034,9 @@ export function createSessionsAdapter(ctx) {
|
|
|
966
1034
|
loadOlder,
|
|
967
1035
|
titleOf,
|
|
968
1036
|
createSession,
|
|
1037
|
+
createWorkspace,
|
|
1038
|
+
waitForReady,
|
|
1039
|
+
listRecentSessions,
|
|
969
1040
|
listWorkspaces,
|
|
970
1041
|
workspaceOf,
|
|
971
1042
|
pollStates,
|