@xpert-ai/plugin-drawio 0.1.1 → 0.2.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/.xpertai-plugin/plugin.json +1 -1
- package/dist/index.js +153 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/constants.js +43 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/drawio-view.provider.js +435 -0
- package/dist/lib/drawio-view.provider.js.map +1 -0
- package/dist/lib/drawio.middleware.js +159 -0
- package/dist/lib/drawio.middleware.js.map +1 -0
- package/dist/lib/drawio.plugin.js +27 -0
- package/dist/lib/drawio.plugin.js.map +1 -0
- package/dist/lib/drawio.service.js +415 -0
- package/dist/lib/drawio.service.js.map +1 -0
- package/dist/lib/drawio.templates.js +78 -0
- package/dist/lib/drawio.templates.js.map +1 -0
- package/dist/lib/entities/drawio-action-log.entity.js +69 -0
- package/dist/lib/entities/drawio-action-log.entity.js.map +1 -0
- package/dist/lib/entities/drawio-drawing-version.entity.js +86 -0
- package/dist/lib/entities/drawio-drawing-version.entity.js.map +1 -0
- package/dist/lib/entities/drawio-drawing.entity.js +94 -0
- package/dist/lib/entities/drawio-drawing.entity.js.map +1 -0
- package/dist/lib/entities/index.js +4 -0
- package/dist/lib/entities/index.js.map +1 -0
- package/dist/lib/remote-components/drawio-workbench/src/i18n.js +95 -0
- package/dist/lib/remote-components/drawio-workbench/src/i18n.js.map +1 -0
- package/dist/lib/remote-components/drawio-workbench/src/react-dom-client-shim.js +4 -0
- package/dist/lib/remote-components/drawio-workbench/src/react-dom-client-shim.js.map +1 -0
- package/dist/lib/remote-components/drawio-workbench/src/react-dom-shim.js +11 -0
- package/dist/lib/remote-components/drawio-workbench/src/react-dom-shim.js.map +1 -0
- package/dist/lib/remote-components/drawio-workbench/src/react-jsx-runtime-shim.js +8 -0
- package/dist/lib/remote-components/drawio-workbench/src/react-jsx-runtime-shim.js.map +1 -0
- package/dist/lib/remote-components/drawio-workbench/src/react-shim.js +36 -0
- package/dist/lib/remote-components/drawio-workbench/src/react-shim.js.map +1 -0
- package/dist/lib/remote-components/drawio-workbench/src/runtime.js +198 -0
- package/dist/lib/remote-components/drawio-workbench/src/runtime.js.map +1 -0
- package/dist/lib/remote-components/drawio-workbench/src/styles.js +290 -0
- package/dist/lib/remote-components/drawio-workbench/src/styles.js.map +1 -0
- package/dist/lib/remote-components/drawio-workbench/src/vendor.js +4 -0
- package/dist/lib/remote-components/drawio-workbench/src/vendor.js.map +1 -0
- package/dist/lib/types.js +2 -0
- package/dist/lib/types.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpert-ai/plugin-drawio",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "draw.io/diagrams.net app plugin for agent-created diagrams, reviewable XML versions, Mermaid drafts, and an embedded editor workbench.",
|
|
5
5
|
"author": "XpertAI",
|
|
6
6
|
"homepage": "https://github.com/xpert-ai/xpert-plugins/tree/main/community/apps/drawio",
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { DRAWIO_AGENT_DRAWING_CAPABILITY, DRAWIO_FEATURE, DRAWIO_ICON, DRAWIO_MIDDLEWARE_NAME, DRAWIO_PROVIDER_KEY, DRAWIO_TEMPLATE_CAPABILITY, DRAWIO_TEMPLATE_PROVIDER_KEY, DRAWIO_WORKBENCH_CAPABILITY, DRAWIO_WORKBENCH_VIEW_KEY } from './lib/constants.js';
|
|
6
|
+
import { DrawioPlugin } from './lib/drawio.plugin.js';
|
|
7
|
+
import { drawioTemplates } from './lib/drawio.templates.js';
|
|
8
|
+
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const packageJson = JSON.parse(readFileSync(join(moduleDir, '../package.json'), 'utf8'));
|
|
10
|
+
const ConfigSchema = z.object({});
|
|
11
|
+
const plugin = {
|
|
12
|
+
meta: {
|
|
13
|
+
name: packageJson.name,
|
|
14
|
+
version: packageJson.version,
|
|
15
|
+
level: 'system',
|
|
16
|
+
targetApps: ['data-xpert', 'xpert'],
|
|
17
|
+
targetAppMeta: {
|
|
18
|
+
'data-xpert': {
|
|
19
|
+
types: ['workbench-view', 'assistant-tool', 'business-app'],
|
|
20
|
+
capabilities: [
|
|
21
|
+
DRAWIO_FEATURE,
|
|
22
|
+
DRAWIO_WORKBENCH_CAPABILITY,
|
|
23
|
+
DRAWIO_AGENT_DRAWING_CAPABILITY,
|
|
24
|
+
DRAWIO_TEMPLATE_CAPABILITY
|
|
25
|
+
],
|
|
26
|
+
marketplace: {
|
|
27
|
+
contents: [
|
|
28
|
+
{
|
|
29
|
+
type: 'app',
|
|
30
|
+
name: 'drawio',
|
|
31
|
+
displayName: 'draw.io',
|
|
32
|
+
description: 'Create, update, version, review, import, export, and convert Agent-generated draw.io diagrams.',
|
|
33
|
+
icon: {
|
|
34
|
+
type: 'svg',
|
|
35
|
+
value: DRAWIO_ICON,
|
|
36
|
+
color: '#2563eb'
|
|
37
|
+
},
|
|
38
|
+
operations: [
|
|
39
|
+
{
|
|
40
|
+
name: 'create-drawio-drawings',
|
|
41
|
+
displayName: 'Create draw.io diagrams',
|
|
42
|
+
description: 'Create reviewable diagrams from Agent-generated diagrams.net XML or Mermaid drafts.',
|
|
43
|
+
access: 'write'
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'save-drawio-versions',
|
|
47
|
+
displayName: 'Save diagram versions',
|
|
48
|
+
description: 'Persist XML scenes, metadata patches, and Mermaid conversions as versioned diagram records.',
|
|
49
|
+
access: 'write'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'review-drawio-workbench',
|
|
53
|
+
displayName: 'Review draw.io workbench',
|
|
54
|
+
description: 'Open draw.io to inspect, manually edit, restore, import, and export diagrams.',
|
|
55
|
+
access: 'read'
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: 'view',
|
|
61
|
+
name: DRAWIO_WORKBENCH_VIEW_KEY,
|
|
62
|
+
displayName: 'draw.io Workbench',
|
|
63
|
+
description: 'Workbench view for diagram lists, embedded draw.io editing, Mermaid import, and version history.'
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
type: 'tool',
|
|
67
|
+
name: DRAWIO_MIDDLEWARE_NAME,
|
|
68
|
+
displayName: 'draw.io Agent Tools',
|
|
69
|
+
description: 'Assistant middleware tools for creating diagrams, saving XML versions, patching metadata, saving Mermaid drafts, searching diagrams, and reporting failures.'
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
type: 'assistant-template',
|
|
73
|
+
name: 'drawio-assistant',
|
|
74
|
+
displayName: 'draw.io Drawing Assistant Template',
|
|
75
|
+
description: 'Prebuilt assistant template for Agent-managed diagram creation and draw.io review workflows.'
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
runtime: {
|
|
80
|
+
middlewareProviders: [DRAWIO_MIDDLEWARE_NAME],
|
|
81
|
+
viewProviders: [DRAWIO_PROVIDER_KEY],
|
|
82
|
+
templateProviders: [DRAWIO_TEMPLATE_PROVIDER_KEY]
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
xpert: {
|
|
86
|
+
types: ['assistant-template', 'skill', 'app', 'xpertai-bundle'],
|
|
87
|
+
capabilities: [
|
|
88
|
+
DRAWIO_FEATURE,
|
|
89
|
+
DRAWIO_WORKBENCH_CAPABILITY,
|
|
90
|
+
DRAWIO_AGENT_DRAWING_CAPABILITY,
|
|
91
|
+
DRAWIO_TEMPLATE_CAPABILITY
|
|
92
|
+
],
|
|
93
|
+
marketplace: {
|
|
94
|
+
contents: [
|
|
95
|
+
{
|
|
96
|
+
type: 'skill',
|
|
97
|
+
name: 'index',
|
|
98
|
+
displayName: 'draw.io Agent Drawing',
|
|
99
|
+
description: 'Workflow skill for Agent-managed draw.io diagrams, Mermaid drafts, XML versions, and Workbench review.',
|
|
100
|
+
tags: ['skill', 'drawio', 'agent-drawing']
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
type: 'assistant-template',
|
|
104
|
+
name: 'drawio-assistant',
|
|
105
|
+
displayName: 'draw.io Drawing Assistant',
|
|
106
|
+
description: 'Assistant template for draw.io diagram workflows.'
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: 'app',
|
|
110
|
+
name: 'drawio',
|
|
111
|
+
displayName: 'draw.io',
|
|
112
|
+
description: 'Workbench and Agent middleware tools for draw.io diagrams.'
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
category: 'middleware',
|
|
119
|
+
icon: {
|
|
120
|
+
type: 'svg',
|
|
121
|
+
value: DRAWIO_ICON,
|
|
122
|
+
color: '#2563eb'
|
|
123
|
+
},
|
|
124
|
+
displayName: 'draw.io',
|
|
125
|
+
description: 'Agentic draw.io plugin for structured diagram generation, XML versioning, review, and Mermaid import.',
|
|
126
|
+
keywords: ['drawio', 'diagram', 'whiteboard', 'mermaid', 'middleware', 'view-extension', 'assistant-template'],
|
|
127
|
+
author: 'XpertAI Team'
|
|
128
|
+
},
|
|
129
|
+
config: {
|
|
130
|
+
schema: ConfigSchema
|
|
131
|
+
},
|
|
132
|
+
templates: drawioTemplates,
|
|
133
|
+
register(ctx) {
|
|
134
|
+
ctx.logger.log('register drawio plugin');
|
|
135
|
+
return { module: DrawioPlugin, global: true };
|
|
136
|
+
},
|
|
137
|
+
async onStart(ctx) {
|
|
138
|
+
ctx.logger.log('drawio plugin started');
|
|
139
|
+
},
|
|
140
|
+
async onStop(ctx) {
|
|
141
|
+
ctx.logger.log('drawio plugin stopped');
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
export default plugin;
|
|
145
|
+
export * from './lib/constants.js';
|
|
146
|
+
export * from './lib/types.js';
|
|
147
|
+
export * from './lib/entities/index.js';
|
|
148
|
+
export * from './lib/drawio.plugin.js';
|
|
149
|
+
export * from './lib/drawio.service.js';
|
|
150
|
+
export * from './lib/drawio.middleware.js';
|
|
151
|
+
export * from './lib/drawio-view.provider.js';
|
|
152
|
+
export * from './lib/drawio.templates.js';
|
|
153
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export const DRAWIO_PLUGIN_NAME = '@xpert-ai/plugin-drawio';
|
|
2
|
+
export const DRAWIO_PROVIDER_KEY = 'drawio';
|
|
3
|
+
export const DRAWIO_MIDDLEWARE_NAME = 'DrawioMiddleware';
|
|
4
|
+
export const DRAWIO_TEMPLATE_PROVIDER_KEY = 'drawioTemplates';
|
|
5
|
+
export const DRAWIO_FEATURE = 'drawio';
|
|
6
|
+
export const DRAWIO_AGENT_DRAWING_CAPABILITY = 'drawio-agent-drawing';
|
|
7
|
+
export const DRAWIO_WORKBENCH_CAPABILITY = 'drawio-workbench';
|
|
8
|
+
export const DRAWIO_TEMPLATE_CAPABILITY = 'drawio-assistant-template';
|
|
9
|
+
export const DRAWIO_WORKBENCH_VIEW_KEY = 'drawio_workbench';
|
|
10
|
+
export const DRAWIO_REMOTE_ENTRY_KEY = 'drawio-workbench';
|
|
11
|
+
export const AGENT_WORKBENCH_MAIN_SLOT = 'agent.workbench.main';
|
|
12
|
+
export const AGENT_WORKBENCH_FIXED_SLOT = 'agent.workbench.fixed';
|
|
13
|
+
export const ASSISTANT_CHAT_SEND_MESSAGE_COMMAND = 'assistant.chat.send_message';
|
|
14
|
+
export const DRAWIO_CREATE_DRAWING_TOOL_NAME = 'drawio_create_diagram';
|
|
15
|
+
export const DRAWIO_SAVE_SCENE_VERSION_TOOL_NAME = 'drawio_save_scene_version';
|
|
16
|
+
export const DRAWIO_PATCH_SCENE_TOOL_NAME = 'drawio_patch_scene';
|
|
17
|
+
export const DRAWIO_SAVE_MERMAID_DRAFT_TOOL_NAME = 'drawio_save_mermaid_draft';
|
|
18
|
+
export const DRAWIO_SEARCH_DRAWINGS_TOOL_NAME = 'drawio_search_diagrams';
|
|
19
|
+
export const DRAWIO_GET_DRAWING_TOOL_NAME = 'drawio_get_diagram';
|
|
20
|
+
export const DRAWIO_UPDATE_DRAWING_STATUS_TOOL_NAME = 'drawio_update_diagram_status';
|
|
21
|
+
export const DRAWIO_REPORT_FAILURE_TOOL_NAME = 'drawio_report_failure';
|
|
22
|
+
export const DRAWIO_MIDDLEWARE_TOOL_NAMES = [
|
|
23
|
+
DRAWIO_CREATE_DRAWING_TOOL_NAME,
|
|
24
|
+
DRAWIO_SAVE_SCENE_VERSION_TOOL_NAME,
|
|
25
|
+
DRAWIO_PATCH_SCENE_TOOL_NAME,
|
|
26
|
+
DRAWIO_SAVE_MERMAID_DRAFT_TOOL_NAME,
|
|
27
|
+
DRAWIO_SEARCH_DRAWINGS_TOOL_NAME,
|
|
28
|
+
DRAWIO_GET_DRAWING_TOOL_NAME,
|
|
29
|
+
DRAWIO_UPDATE_DRAWING_STATUS_TOOL_NAME,
|
|
30
|
+
DRAWIO_REPORT_FAILURE_TOOL_NAME
|
|
31
|
+
];
|
|
32
|
+
export const DRAWIO_ICON = `<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 256 256" fill="none">
|
|
33
|
+
<rect width="256" height="256" rx="40" fill="#F8FAFC"/>
|
|
34
|
+
<rect x="42" y="48" width="172" height="132" rx="20" fill="#FFFFFF" stroke="#F59E0B" stroke-width="10"/>
|
|
35
|
+
<rect x="72" y="84" width="46" height="34" rx="8" fill="#FEF3C7" stroke="#92400E" stroke-width="7"/>
|
|
36
|
+
<rect x="144" y="84" width="46" height="34" rx="8" fill="#DBEAFE" stroke="#1D4ED8" stroke-width="7"/>
|
|
37
|
+
<rect x="108" y="136" width="46" height="34" rx="8" fill="#DCFCE7" stroke="#15803D" stroke-width="7"/>
|
|
38
|
+
<path d="M118 101H144" stroke="#0F172A" stroke-width="7" stroke-linecap="round"/>
|
|
39
|
+
<path d="M158 118L138 136" stroke="#0F172A" stroke-width="7" stroke-linecap="round"/>
|
|
40
|
+
<path d="M96 118L116 136" stroke="#0F172A" stroke-width="7" stroke-linecap="round"/>
|
|
41
|
+
<path d="M76 206C99 188 126 184 154 195C170 201 187 198 202 184" stroke="#F59E0B" stroke-width="10" stroke-linecap="round"/>
|
|
42
|
+
</svg>`;
|
|
43
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAA;AAC3D,MAAM,CAAC,MAAM,mBAAmB,GAAG,QAAQ,CAAA;AAC3C,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAA;AACxD,MAAM,CAAC,MAAM,4BAA4B,GAAG,iBAAiB,CAAA;AAC7D,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAA;AACtC,MAAM,CAAC,MAAM,+BAA+B,GAAG,sBAAsB,CAAA;AACrE,MAAM,CAAC,MAAM,2BAA2B,GAAG,kBAAkB,CAAA;AAC7D,MAAM,CAAC,MAAM,0BAA0B,GAAG,2BAA2B,CAAA;AACrE,MAAM,CAAC,MAAM,yBAAyB,GAAG,kBAAkB,CAAA;AAC3D,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAA;AACzD,MAAM,CAAC,MAAM,yBAAyB,GAAG,sBAAsB,CAAA;AAC/D,MAAM,CAAC,MAAM,0BAA0B,GAAG,uBAAuB,CAAA;AACjE,MAAM,CAAC,MAAM,mCAAmC,GAAG,6BAA6B,CAAA;AAEhF,MAAM,CAAC,MAAM,+BAA+B,GAAG,uBAAuB,CAAA;AACtE,MAAM,CAAC,MAAM,mCAAmC,GAAG,2BAA2B,CAAA;AAC9E,MAAM,CAAC,MAAM,4BAA4B,GAAG,oBAAoB,CAAA;AAChE,MAAM,CAAC,MAAM,mCAAmC,GAAG,2BAA2B,CAAA;AAC9E,MAAM,CAAC,MAAM,gCAAgC,GAAG,wBAAwB,CAAA;AACxE,MAAM,CAAC,MAAM,4BAA4B,GAAG,oBAAoB,CAAA;AAChE,MAAM,CAAC,MAAM,sCAAsC,GAAG,8BAA8B,CAAA;AACpF,MAAM,CAAC,MAAM,+BAA+B,GAAG,uBAAuB,CAAA;AAEtE,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,+BAA+B;IAC/B,mCAAmC;IACnC,4BAA4B;IAC5B,mCAAmC;IACnC,gCAAgC;IAChC,4BAA4B;IAC5B,sCAAsC;IACtC,+BAA+B;CACvB,CAAA;AAEV,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;OAUpB,CAAA"}
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Injectable } from '@nestjs/common';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
import { dirname, join } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { renderRemoteReactIframeHtml, ViewExtensionProvider } from '@xpert-ai/plugin-sdk';
|
|
9
|
+
import { AGENT_WORKBENCH_FIXED_SLOT, AGENT_WORKBENCH_MAIN_SLOT, ASSISTANT_CHAT_SEND_MESSAGE_COMMAND, DRAWIO_FEATURE, DRAWIO_ICON, DRAWIO_MIDDLEWARE_TOOL_NAMES, DRAWIO_PLUGIN_NAME, DRAWIO_PROVIDER_KEY, DRAWIO_REMOTE_ENTRY_KEY, DRAWIO_WORKBENCH_VIEW_KEY } from './constants.js';
|
|
10
|
+
import { DrawioService } from './drawio.service.js';
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = dirname(__filename);
|
|
13
|
+
const requireFromHere = createRequire(__filename);
|
|
14
|
+
const text = (en_US, zh_Hans) => ({ en_US, zh_Hans });
|
|
15
|
+
let DrawioViewProvider = class DrawioViewProvider {
|
|
16
|
+
constructor(service) {
|
|
17
|
+
this.service = service;
|
|
18
|
+
}
|
|
19
|
+
supports(context) {
|
|
20
|
+
return context.hostType === 'agent';
|
|
21
|
+
}
|
|
22
|
+
getViewManifests(context, slot) {
|
|
23
|
+
if (context.hostType !== 'agent' || (slot !== AGENT_WORKBENCH_MAIN_SLOT && slot !== AGENT_WORKBENCH_FIXED_SLOT)) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
const fixed = slot === AGENT_WORKBENCH_FIXED_SLOT;
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
key: DRAWIO_WORKBENCH_VIEW_KEY,
|
|
30
|
+
title: text('draw.io Workbench', 'draw.io 绘图工作台'),
|
|
31
|
+
description: text('Create, review, edit, version, import, export, and convert Agent-generated diagrams.', '创建、审核、编辑、版本化、导入导出并转换 Agent 生成的图形。'),
|
|
32
|
+
icon: {
|
|
33
|
+
type: 'svg',
|
|
34
|
+
value: DRAWIO_ICON,
|
|
35
|
+
color: '#f59e0b',
|
|
36
|
+
alt: 'draw.io'
|
|
37
|
+
},
|
|
38
|
+
hostType: 'agent',
|
|
39
|
+
slot,
|
|
40
|
+
order: 40,
|
|
41
|
+
refreshable: true,
|
|
42
|
+
activation: {
|
|
43
|
+
requiredFeatures: [DRAWIO_FEATURE]
|
|
44
|
+
},
|
|
45
|
+
...(fixed
|
|
46
|
+
? {
|
|
47
|
+
workbench: {
|
|
48
|
+
fixed: true,
|
|
49
|
+
menu: {
|
|
50
|
+
enabled: true,
|
|
51
|
+
label: text('draw.io', 'draw.io 绘图'),
|
|
52
|
+
order: 40,
|
|
53
|
+
icon: {
|
|
54
|
+
type: 'svg',
|
|
55
|
+
value: DRAWIO_ICON,
|
|
56
|
+
alt: 'draw.io'
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
: {}),
|
|
62
|
+
source: {
|
|
63
|
+
provider: DRAWIO_PROVIDER_KEY,
|
|
64
|
+
plugin: DRAWIO_PLUGIN_NAME
|
|
65
|
+
},
|
|
66
|
+
view: {
|
|
67
|
+
type: 'remote_component',
|
|
68
|
+
runtime: 'react',
|
|
69
|
+
protocolVersion: 1,
|
|
70
|
+
component: {
|
|
71
|
+
isolation: 'iframe',
|
|
72
|
+
entry: DRAWIO_REMOTE_ENTRY_KEY
|
|
73
|
+
},
|
|
74
|
+
dataSource: {
|
|
75
|
+
mode: 'platform'
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
dataSource: {
|
|
79
|
+
mode: 'platform',
|
|
80
|
+
querySchema: {
|
|
81
|
+
supportsPagination: true,
|
|
82
|
+
supportsSearch: true,
|
|
83
|
+
supportsParameters: true,
|
|
84
|
+
defaultPageSize: 20
|
|
85
|
+
},
|
|
86
|
+
cache: {
|
|
87
|
+
enabled: false
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
hostEvents: {
|
|
91
|
+
subscriptions: [
|
|
92
|
+
{
|
|
93
|
+
key: 'drawio-tool-completed',
|
|
94
|
+
event: 'assistant.tool.completed',
|
|
95
|
+
filter: {
|
|
96
|
+
sources: ['chatkit'],
|
|
97
|
+
toolNames: [...DRAWIO_MIDDLEWARE_TOOL_NAMES]
|
|
98
|
+
},
|
|
99
|
+
action: {
|
|
100
|
+
type: 'forward',
|
|
101
|
+
debounceMs: 1000
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
clientCommands: [
|
|
107
|
+
{
|
|
108
|
+
key: ASSISTANT_CHAT_SEND_MESSAGE_COMMAND,
|
|
109
|
+
label: text('Send to Assistant Chat', '发送到 Assistant 对话')
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
actions: [
|
|
113
|
+
{ key: 'refresh', label: text('Refresh', '刷新'), icon: 'ri-refresh-line', placement: 'toolbar', actionType: 'refresh' },
|
|
114
|
+
{ key: 'create_drawing', label: text('New Drawing', '新建图形'), icon: 'ri-add-line', placement: 'toolbar', actionType: 'invoke' },
|
|
115
|
+
{ key: 'save_scene_version', label: text('Save Version', '保存版本'), icon: 'ri-save-line', placement: 'toolbar', actionType: 'invoke' },
|
|
116
|
+
{ key: 'restore_version', label: text('Restore Version', '恢复版本'), icon: 'ri-history-line', actionType: 'invoke' },
|
|
117
|
+
{ key: 'mark_reviewed', label: text('Mark Reviewed', '标记已审核'), icon: 'ri-check-line', actionType: 'invoke' },
|
|
118
|
+
{ key: 'mark_draft', label: text('Move Back to Draft', '退回草稿'), icon: 'ri-edit-line', actionType: 'invoke' },
|
|
119
|
+
{ key: 'archive_drawing', label: text('Archive Drawing', '归档图形'), icon: 'ri-archive-line', actionType: 'invoke' },
|
|
120
|
+
{
|
|
121
|
+
key: 'import_scene_file',
|
|
122
|
+
label: text('Import draw.io File', '导入 draw.io 文件'),
|
|
123
|
+
icon: 'ri-upload-cloud-line',
|
|
124
|
+
placement: 'toolbar',
|
|
125
|
+
actionType: 'invoke',
|
|
126
|
+
transport: 'file'
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
key: 'save_converted_mermaid_scene',
|
|
130
|
+
label: text('Save Converted Mermaid Scene', '保存 Mermaid 转换结果'),
|
|
131
|
+
icon: 'ri-git-branch-line',
|
|
132
|
+
actionType: 'invoke'
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
key: 'prepare_agent_draw_message',
|
|
136
|
+
label: text('Ask Assistant to Draw', '让 Assistant 绘图'),
|
|
137
|
+
icon: 'ri-send-plane-line',
|
|
138
|
+
placement: 'toolbar',
|
|
139
|
+
actionType: 'invoke'
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
async getRemoteComponentEntry(_context, viewKey, component) {
|
|
146
|
+
if (viewKey !== DRAWIO_WORKBENCH_VIEW_KEY || component.entry !== DRAWIO_REMOTE_ENTRY_KEY) {
|
|
147
|
+
return {
|
|
148
|
+
html: '<!doctype html><html><body>Unsupported draw.io component.</body></html>',
|
|
149
|
+
contentType: 'text/html; charset=utf-8'
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const componentDir = join(__dirname, 'remote-components', DRAWIO_REMOTE_ENTRY_KEY);
|
|
153
|
+
const appScript = await readFile(join(componentDir, 'app.js'), 'utf8');
|
|
154
|
+
const appCssPath = join(componentDir, 'app.css');
|
|
155
|
+
const appCss = existsSync(appCssPath) ? await readFile(appCssPath, 'utf8') : '';
|
|
156
|
+
const react = await readPackageFile('react', 'umd/react.production.min.js');
|
|
157
|
+
const reactDom = await readPackageFile('react-dom', 'umd/react-dom.production.min.js');
|
|
158
|
+
return {
|
|
159
|
+
html: renderRemoteReactIframeHtml({
|
|
160
|
+
title: 'draw.io Workbench',
|
|
161
|
+
lang: 'zh-Hans',
|
|
162
|
+
reactUmd: react,
|
|
163
|
+
reactDomUmd: reactDom,
|
|
164
|
+
appScript,
|
|
165
|
+
appCss
|
|
166
|
+
}),
|
|
167
|
+
contentType: 'text/html; charset=utf-8'
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
async getViewData(context, viewKey, query) {
|
|
171
|
+
if (viewKey !== DRAWIO_WORKBENCH_VIEW_KEY) {
|
|
172
|
+
return {};
|
|
173
|
+
}
|
|
174
|
+
return this.service.getWorkbenchData(scopeFromContext(context), {
|
|
175
|
+
drawingId: getStringParameter(query.parameters, 'drawingId') ?? query.selectionId,
|
|
176
|
+
status: getStringParameter(query.parameters, 'status'),
|
|
177
|
+
kind: getStringParameter(query.parameters, 'kind'),
|
|
178
|
+
search: query.search,
|
|
179
|
+
page: query.page,
|
|
180
|
+
pageSize: query.pageSize
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
async executeViewAction(context, viewKey, actionKey, request) {
|
|
184
|
+
if (viewKey !== DRAWIO_WORKBENCH_VIEW_KEY) {
|
|
185
|
+
return failure('Unsupported view', '不支持的视图');
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
const scope = scopeFromContext(context);
|
|
189
|
+
if (actionKey === 'refresh') {
|
|
190
|
+
return success('draw.io view refreshed', 'draw.io 视图已刷新');
|
|
191
|
+
}
|
|
192
|
+
if (actionKey === 'create_drawing') {
|
|
193
|
+
const result = await this.service.createDrawing(scope, {
|
|
194
|
+
title: requireStringInput(request.input, 'title', 'Diagram title is required.'),
|
|
195
|
+
description: getStringInput(request.input, 'description'),
|
|
196
|
+
kind: getStringInput(request.input, 'kind'),
|
|
197
|
+
tags: getStringArrayInput(request.input, 'tags'),
|
|
198
|
+
source: 'workbench'
|
|
199
|
+
});
|
|
200
|
+
return {
|
|
201
|
+
...success('Diagram created', '图形已创建'),
|
|
202
|
+
data: result
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
if (actionKey === 'save_scene_version' || actionKey === 'save_converted_mermaid_scene') {
|
|
206
|
+
const drawingId = requireDrawingId(request);
|
|
207
|
+
const result = await this.service.saveSceneVersion(scope, {
|
|
208
|
+
drawingId,
|
|
209
|
+
xml: getStringInput(request.input, 'xml'),
|
|
210
|
+
mermaidSource: getStringInput(request.input, 'mermaidSource'),
|
|
211
|
+
previewSvg: getStringInput(request.input, 'previewSvg'),
|
|
212
|
+
previewPng: getStringInput(request.input, 'previewPng'),
|
|
213
|
+
descriptor: getRecordInput(request.input, 'descriptor'),
|
|
214
|
+
sourceType: actionKey === 'save_converted_mermaid_scene' ? 'workbench_mermaid' : 'workbench',
|
|
215
|
+
changeSummary: getStringInput(request.input, 'changeSummary')
|
|
216
|
+
});
|
|
217
|
+
return {
|
|
218
|
+
...success('Diagram version saved', '图形版本已保存'),
|
|
219
|
+
data: result
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
if (actionKey === 'restore_version') {
|
|
223
|
+
const result = await this.service.restoreVersion(scope, requireDrawingId(request), requireStringInput(request.input, 'versionId', 'Version id is required.'), getStringInput(request.input, 'changeSummary'));
|
|
224
|
+
return {
|
|
225
|
+
...success('Diagram version restored', '图形版本已恢复'),
|
|
226
|
+
data: result
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
if (actionKey === 'archive_drawing') {
|
|
230
|
+
const result = await this.service.updateDrawingStatus(scope, {
|
|
231
|
+
drawingId: requireDrawingId(request),
|
|
232
|
+
status: 'archived',
|
|
233
|
+
reason: getStringInput(request.input, 'reason')
|
|
234
|
+
});
|
|
235
|
+
return {
|
|
236
|
+
...success('Diagram archived', '图形已归档'),
|
|
237
|
+
data: result
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
if (actionKey === 'mark_reviewed' || actionKey === 'mark_draft') {
|
|
241
|
+
const status = actionKey === 'mark_reviewed' ? 'reviewed' : 'draft';
|
|
242
|
+
const result = await this.service.updateDrawingStatus(scope, {
|
|
243
|
+
drawingId: requireDrawingId(request),
|
|
244
|
+
status,
|
|
245
|
+
reason: getStringInput(request.input, 'reason')
|
|
246
|
+
});
|
|
247
|
+
return {
|
|
248
|
+
...success(status === 'reviewed' ? 'Diagram marked as reviewed' : 'Diagram moved back to draft', status === 'reviewed' ? '图形已标记为已审核' : '图形已退回草稿'),
|
|
249
|
+
data: result
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
if (actionKey === 'prepare_agent_draw_message') {
|
|
253
|
+
const prompt = requireStringInput(request.input, 'prompt', 'Drawing request is required.');
|
|
254
|
+
return {
|
|
255
|
+
...success('Assistant draw request prepared', 'Assistant 绘图请求已准备'),
|
|
256
|
+
data: {
|
|
257
|
+
commandKey: ASSISTANT_CHAT_SEND_MESSAGE_COMMAND,
|
|
258
|
+
payload: {
|
|
259
|
+
text: buildAgentDrawPrompt(prompt, getStringInput(request.input, 'drawingId'))
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
refresh: false
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
return failure('Unsupported action', '不支持的操作');
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
const message = getActionErrorMessage(error, 'draw.io action failed');
|
|
269
|
+
return {
|
|
270
|
+
success: false,
|
|
271
|
+
message: text(message, message)
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async executeViewFileAction(context, viewKey, actionKey, request, file) {
|
|
276
|
+
if (viewKey !== DRAWIO_WORKBENCH_VIEW_KEY) {
|
|
277
|
+
return failure('Unsupported view', '不支持的视图');
|
|
278
|
+
}
|
|
279
|
+
if (actionKey !== 'import_scene_file') {
|
|
280
|
+
return failure('Unsupported file action', '不支持的文件操作');
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
const scene = parseDrawioFile(file);
|
|
284
|
+
const drawingId = getStringInput(request.input, 'drawingId') ?? getStringParameter(request.parameters, 'drawingId');
|
|
285
|
+
const scope = scopeFromContext(context);
|
|
286
|
+
const result = drawingId
|
|
287
|
+
? await this.service.saveSceneVersion(scope, {
|
|
288
|
+
drawingId,
|
|
289
|
+
xml: scene.xml,
|
|
290
|
+
mermaidSource: scene.mermaidSource,
|
|
291
|
+
previewSvg: scene.previewSvg,
|
|
292
|
+
previewPng: scene.previewPng,
|
|
293
|
+
descriptor: scene.descriptor,
|
|
294
|
+
sourceType: 'import',
|
|
295
|
+
changeSummary: `Imported ${file.originalname ?? 'draw.io file'}`
|
|
296
|
+
})
|
|
297
|
+
: await this.service.createDrawing(scope, {
|
|
298
|
+
title: getStringInput(request.input, 'title') ?? removeDrawioExtension(file.originalname) ?? 'Imported draw.io Diagram',
|
|
299
|
+
description: getStringInput(request.input, 'description'),
|
|
300
|
+
kind: 'diagram',
|
|
301
|
+
source: 'import',
|
|
302
|
+
xml: scene.xml,
|
|
303
|
+
mermaidSource: scene.mermaidSource,
|
|
304
|
+
previewSvg: scene.previewSvg,
|
|
305
|
+
previewPng: scene.previewPng,
|
|
306
|
+
descriptor: scene.descriptor,
|
|
307
|
+
changeSummary: `Imported ${file.originalname ?? 'draw.io file'}`
|
|
308
|
+
});
|
|
309
|
+
return {
|
|
310
|
+
...success('draw.io file imported', 'draw.io 文件已导入'),
|
|
311
|
+
data: result
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
catch (error) {
|
|
315
|
+
const message = getActionErrorMessage(error, 'Failed to import draw.io file');
|
|
316
|
+
return {
|
|
317
|
+
success: false,
|
|
318
|
+
message: text(message, message)
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
DrawioViewProvider = __decorate([
|
|
324
|
+
Injectable(),
|
|
325
|
+
ViewExtensionProvider(DRAWIO_PROVIDER_KEY),
|
|
326
|
+
__metadata("design:paramtypes", [DrawioService])
|
|
327
|
+
], DrawioViewProvider);
|
|
328
|
+
export { DrawioViewProvider };
|
|
329
|
+
async function readPackageFile(packageName, relativePath) {
|
|
330
|
+
const packageRoot = dirname(requireFromHere.resolve(`${packageName}/package.json`));
|
|
331
|
+
return readFile(join(packageRoot, relativePath), 'utf8');
|
|
332
|
+
}
|
|
333
|
+
function scopeFromContext(context) {
|
|
334
|
+
return {
|
|
335
|
+
tenantId: context.tenantId,
|
|
336
|
+
organizationId: context.organizationId ?? null,
|
|
337
|
+
workspaceId: context.workspaceId ?? null,
|
|
338
|
+
projectId: null,
|
|
339
|
+
userId: context.userId,
|
|
340
|
+
assistantId: context.hostType === 'agent' ? context.hostId : null
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function success(en_US, zh_Hans) {
|
|
344
|
+
return {
|
|
345
|
+
success: true,
|
|
346
|
+
message: text(en_US, zh_Hans),
|
|
347
|
+
refresh: true
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function failure(en_US, zh_Hans) {
|
|
351
|
+
return {
|
|
352
|
+
success: false,
|
|
353
|
+
message: text(en_US, zh_Hans)
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
function requireDrawingId(request) {
|
|
357
|
+
return (getStringInput(request.input, 'drawingId') ??
|
|
358
|
+
getStringParameter(request.parameters, 'drawingId') ??
|
|
359
|
+
requireString(request.targetId, 'Drawing id is required.'));
|
|
360
|
+
}
|
|
361
|
+
function requireStringInput(input, key, message) {
|
|
362
|
+
return requireString(getStringInput(input, key), message);
|
|
363
|
+
}
|
|
364
|
+
function requireString(value, message) {
|
|
365
|
+
const normalized = value?.trim();
|
|
366
|
+
if (!normalized) {
|
|
367
|
+
throw new Error(message);
|
|
368
|
+
}
|
|
369
|
+
return normalized;
|
|
370
|
+
}
|
|
371
|
+
function getStringInput(input, key) {
|
|
372
|
+
const value = input?.[key];
|
|
373
|
+
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
374
|
+
}
|
|
375
|
+
function getStringArrayInput(input, key) {
|
|
376
|
+
const value = input?.[key];
|
|
377
|
+
if (!Array.isArray(value)) {
|
|
378
|
+
return undefined;
|
|
379
|
+
}
|
|
380
|
+
return value.filter((item) => typeof item === 'string' && item.trim().length > 0).map((item) => item.trim());
|
|
381
|
+
}
|
|
382
|
+
function getRecordInput(input, key) {
|
|
383
|
+
const value = input?.[key];
|
|
384
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
385
|
+
}
|
|
386
|
+
function getStringParameter(parameters, key) {
|
|
387
|
+
const value = parameters?.[key];
|
|
388
|
+
if (typeof value === 'string' && value.trim()) {
|
|
389
|
+
return value.trim();
|
|
390
|
+
}
|
|
391
|
+
return undefined;
|
|
392
|
+
}
|
|
393
|
+
function getActionErrorMessage(error, fallback) {
|
|
394
|
+
return error instanceof Error && error.message ? error.message : fallback;
|
|
395
|
+
}
|
|
396
|
+
function parseDrawioFile(file) {
|
|
397
|
+
const raw = file.buffer.toString('utf8');
|
|
398
|
+
const trimmed = raw.trim();
|
|
399
|
+
if (trimmed.startsWith('{')) {
|
|
400
|
+
const parsed = JSON.parse(trimmed);
|
|
401
|
+
return {
|
|
402
|
+
xml: typeof parsed.xml === 'string' ? parsed.xml : null,
|
|
403
|
+
mermaidSource: typeof parsed.mermaidSource === 'string' ? parsed.mermaidSource : null,
|
|
404
|
+
previewSvg: typeof parsed.previewSvg === 'string' ? parsed.previewSvg : null,
|
|
405
|
+
previewPng: typeof parsed.previewPng === 'string' ? parsed.previewPng : null,
|
|
406
|
+
descriptor: parsed.descriptor && typeof parsed.descriptor === 'object' && !Array.isArray(parsed.descriptor)
|
|
407
|
+
? parsed.descriptor
|
|
408
|
+
: {}
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
return {
|
|
412
|
+
xml: trimmed,
|
|
413
|
+
mermaidSource: null,
|
|
414
|
+
previewSvg: trimmed.startsWith('<svg') ? trimmed : null,
|
|
415
|
+
previewPng: null,
|
|
416
|
+
descriptor: {}
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
function removeDrawioExtension(name) {
|
|
420
|
+
const normalized = name?.trim();
|
|
421
|
+
if (!normalized) {
|
|
422
|
+
return undefined;
|
|
423
|
+
}
|
|
424
|
+
return normalized.replace(/\.(drawio|diagram|xml)(?:\.json)?$/i, '').replace(/\.json$/i, '') || normalized;
|
|
425
|
+
}
|
|
426
|
+
function buildAgentDrawPrompt(prompt, drawingId) {
|
|
427
|
+
const context = drawingId ? `请更新当前 draw.io 图形 drawingId=${drawingId}。` : '请创建一张新的 draw.io 图形。';
|
|
428
|
+
return `${context}
|
|
429
|
+
|
|
430
|
+
用户绘图需求:
|
|
431
|
+
${prompt}
|
|
432
|
+
|
|
433
|
+
请优先判断是否适合 Mermaid 草稿;流程图、架构流、状态流可调用 drawio_save_mermaid_draft。需要精确布局或自由图形时,生成 diagrams.net/draw.io XML 并调用 drawio_create_diagram、drawio_save_scene_version 或 drawio_patch_scene。更新已有图形前先调用 drawio_get_diagram。`;
|
|
434
|
+
}
|
|
435
|
+
//# sourceMappingURL=drawio-view.provider.js.map
|