dsh-workrally 0.2.1 → 0.3.0

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 CHANGED
@@ -63,6 +63,8 @@ dsh plugin --profile desktop remove dsh-workrally
63
63
  ### 任务
64
64
 
65
65
  - 只记录 `workrally` / `workrally1` 这两个连接下的生成、查询、展示类工具结果,按对话分开显示。
66
+ - WorkRally logo 旁的「刷新全部」会先清掉宿主端的模板/灵感缓存,再重读任务进度、画布额度和模板合集;只读取,不会重新提交生成。
67
+ - 「我的媒资」在画布页签之后,只列出无限画布生成并入库的素材。可以按画布和类型筛选,卡片上显示提示词;双击查看完整画面和提示词,点标题回到画布。
66
68
  - 「刷新进度」只查询已记录任务的状态,不会重新提交生成。
67
69
  - 成果详情里可以看到提示词、参数和参考素材。
68
70
  - 「放进对话」「基于此继续改」只把内容写进输入框,由你确认后再发送。
package/lib/account.js CHANGED
@@ -165,6 +165,8 @@ export const createAccount = ({ warn }) => {
165
165
  transport: 'streamable-http',
166
166
  url: MCP_URL,
167
167
  headers: { Authorization: `Bearer ${token}` },
168
+ // WorkRally 的 initialize.instructions 约 34 KB,内置默认上限 32 KB 会把连接判为失败。
169
+ maxInstructionBytes: 131072,
168
170
  });
169
171
  };
170
172
 
@@ -309,6 +311,20 @@ export const createAccount = ({ warn }) => {
309
311
  return this.status();
310
312
  },
311
313
 
314
+ /** 切换或重新绑定 WorkRally 账号:卸载旧令牌并立即拉起浏览器授权。 */
315
+ async relogin() {
316
+ if (!scope) return this.status();
317
+ clearTimeout(timer);
318
+ unmount();
319
+ try {
320
+ await scope.credentials.deleteRecord?.(RECORD_KEY);
321
+ } catch {
322
+ // ignore if deleteRecord unsupported; login overwrites on completion
323
+ }
324
+ set('signed-out');
325
+ return this.login();
326
+ },
327
+
312
328
  status() {
313
329
  return {
314
330
  status: phase,
package/lib/catalog.js ADDED
@@ -0,0 +1,109 @@
1
+ /** 工作台目录:画布、生图模型、视频模型的只读缓存。数据全部来自 WorkRally MCP,失败时返回空。 */
2
+ import { callNativeTool, normalizeToolResult } from './mcp.js';
3
+
4
+ const TTL_MS = 60_000;
5
+ const cache = { at: 0, data: null };
6
+
7
+ const payloadOf = (result) => {
8
+ const normalized = normalizeToolResult(result);
9
+ if (normalized.error) throw new Error(normalized.error);
10
+ for (const payload of normalized.payloads) {
11
+ if (payload && typeof payload === 'object') return payload;
12
+ }
13
+ throw new Error('WorkRally 没有返回可读结果');
14
+ };
15
+
16
+ const listUrl = (base, pattern) => (typeof base === 'string' && typeof pattern === 'string'
17
+ ? `${base.replace(/\/$/, '')}${pattern}`
18
+ : '');
19
+
20
+ export const mapCanvases = (payload, base, pattern) => {
21
+ const list = Array.isArray(payload?.list) ? payload.list : [];
22
+ return list.map((row) => {
23
+ const project = row?.project;
24
+ if (!project?.id) return null;
25
+ return {
26
+ id: String(project.id),
27
+ title: String(project.title || '未命名画布'),
28
+ thumb: typeof project.thumbnail_url === 'string' ? project.thumbnail_url : '',
29
+ images: Number(project.image_count) || 0,
30
+ videos: Number(project.video_count) || 0,
31
+ texts: Number(project.text_count) || 0,
32
+ updated: String(project.updated_at || ''),
33
+ mine: Boolean(project.is_author),
34
+ url: listUrl(base, String(pattern || '').replace(':id', project.id)),
35
+ };
36
+ }).filter(Boolean);
37
+ };
38
+
39
+ export const mapImageModels = (payload) => {
40
+ const models = Array.isArray(payload?.models) ? payload.models : [];
41
+ return models.map(model => ({
42
+ id: String(model.model_id || ''),
43
+ name: String(model.name || model.model_id || ''),
44
+ recommend: Boolean(model.is_recommend),
45
+ resolutions: Array.isArray(model.resolution_options) ? model.resolution_options : [],
46
+ aspects: Array.isArray(model.aspect_ratios) ? model.aspect_ratios : [],
47
+ qualities: Array.isArray(model.infer_quality_options) ? model.infer_quality_options : [],
48
+ })).filter(model => model.id);
49
+ };
50
+
51
+ const VIDEO_MODES = [
52
+ ['text_providers', 'Text', '单图驱动'],
53
+ ['first_last_frame_providers', 'FirstLastFrame', '首尾帧'],
54
+ ['subject_to_video_providers', 'SubjectToVideo', '参考主体'],
55
+ ['video_edit_providers', 'VideoEdit', '视频编辑'],
56
+ ['smart_edit_providers', 'SmartEdit', '智能编辑'],
57
+ ];
58
+
59
+ export const mapVideoModes = (payload) => VIDEO_MODES.map(([key, mode, label]) => ({
60
+ mode,
61
+ label,
62
+ models: (Array.isArray(payload?.[key]) ? payload[key] : []).map(model => ({
63
+ id: String(model.provider || ''),
64
+ name: String(model.label || model.provider || ''),
65
+ recommend: Boolean(model.is_recommend),
66
+ resolutions: Array.isArray(model.resolution_options) ? model.resolution_options : [],
67
+ durations: Array.isArray(model.duration_options) ? model.duration_options : [],
68
+ sound: Boolean(model.support_audio),
69
+ draft: Boolean(model.support_draft),
70
+ erase: Boolean(model.support_erase_subtitles),
71
+ })).filter(model => model.id),
72
+ })).filter(group => group.models.length);
73
+
74
+ const canvasPattern = (payload) => {
75
+ for (const rows of Object.values(payload?.modules || {})) {
76
+ for (const entry of Array.isArray(rows) ? rows : []) {
77
+ if (entry?.name === '无限画布编辑' && typeof entry.pattern === 'string') return entry.pattern;
78
+ if (typeof entry?.pattern === 'string' && entry.pattern.includes(':id') && /canvas/i.test(entry.pattern)) return entry.pattern;
79
+ }
80
+ }
81
+ return '';
82
+ };
83
+
84
+ export const getCatalog = async (ctx, sessionId = '') => {
85
+ if (cache.data && Date.now() - cache.at < TTL_MS) return cache.data;
86
+ const call = (action, args) => callNativeTool(ctx, { serverName: 'workrally', action, args, sessionId }, AbortSignal.timeout(20_000));
87
+ const [canvasRes, imageRes, videoRes, urlRes] = await Promise.allSettled([
88
+ call('canvas_manage', { action: 'list', page: 1, page_size: 12 }),
89
+ call('canvas_image_model_list', {}),
90
+ call('canvas_video_provider_config', {}),
91
+ call('workrally_url', { action: 'list' }),
92
+ ]);
93
+ const canvasPayload = canvasRes.status === 'fulfilled' ? payloadOf(canvasRes.value) : null;
94
+ const imagePayload = imageRes.status === 'fulfilled' ? payloadOf(imageRes.value) : null;
95
+ const videoPayload = videoRes.status === 'fulfilled' ? payloadOf(videoRes.value) : null;
96
+ const urlPayload = urlRes.status === 'fulfilled' ? payloadOf(urlRes.value) : null;
97
+ if (!canvasPayload && !imagePayload && !videoPayload) throw new Error('WorkRally 目录暂时不可用');
98
+ const data = {
99
+ canvases: canvasPayload ? mapCanvases(canvasPayload, urlPayload?.base_url, canvasPattern(urlPayload)) : [],
100
+ imageModels: imagePayload ? mapImageModels(imagePayload) : [],
101
+ videoModes: videoPayload ? mapVideoModes(videoPayload) : [],
102
+ at: new Date().toISOString(),
103
+ };
104
+ cache.at = Date.now();
105
+ cache.data = data;
106
+ return data;
107
+ };
108
+
109
+ export const resetCatalog = () => { cache.at = 0; cache.data = null; };