@elevo-ai/plugin-sdk 0.4.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 +144 -0
- package/index.cjs.js +9 -0
- package/index.d.ts +275 -0
- package/index.esm.js +5 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# @elevo/plugin-sdk
|
|
2
|
+
|
|
3
|
+
Elevo Plugin SDK - 用于构建 Elevo 平台插件的开发工具包。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @elevo/plugin-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 使用
|
|
12
|
+
|
|
13
|
+
### 运行时 SDK
|
|
14
|
+
|
|
15
|
+
该包的运行时代码只会从 `window.ElevoPluginSDK` 读取 SDK 实例,主应用负责注入。插件代码通常仅导入类型。
|
|
16
|
+
|
|
17
|
+
### 在插件应用中使用
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import sdk from '@elevo/plugin-sdk';
|
|
21
|
+
|
|
22
|
+
// 插件应用组件
|
|
23
|
+
export default function MyPluginApp() {
|
|
24
|
+
const handleSendMessage = async () => {
|
|
25
|
+
await sdk.conversation.sendMessage({
|
|
26
|
+
role: 'user',
|
|
27
|
+
content: '执行某个操作',
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const handleListArtifacts = async () => {
|
|
32
|
+
const artifacts = await sdk.workspace.artifacts.list();
|
|
33
|
+
console.log('Artifacts:', artifacts);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div>
|
|
38
|
+
<h1>我的插件</h1>
|
|
39
|
+
<button onClick={handleSendMessage}>发送消息</button>
|
|
40
|
+
<button onClick={handleListArtifacts}>列出制品</button>
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 类型定义
|
|
47
|
+
|
|
48
|
+
SDK 导出了完整的 TypeScript 类型定义:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import type {
|
|
52
|
+
PluginConfig,
|
|
53
|
+
|
|
54
|
+
// Workspace API
|
|
55
|
+
WorkspaceAPI,
|
|
56
|
+
ArtifactsAPI,
|
|
57
|
+
Artifact,
|
|
58
|
+
ArtifactContent,
|
|
59
|
+
|
|
60
|
+
// Conversation API
|
|
61
|
+
ConversationAPI,
|
|
62
|
+
MessageEvent,
|
|
63
|
+
SendMessageInput,
|
|
64
|
+
|
|
65
|
+
// 错误类型
|
|
66
|
+
PluginSDKError,
|
|
67
|
+
} from '@elevo/plugin-sdk';
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## API 参考
|
|
71
|
+
|
|
72
|
+
### ElevoPluginSDK
|
|
73
|
+
|
|
74
|
+
主 SDK 接口,包含以下属性:
|
|
75
|
+
|
|
76
|
+
| 属性 | 类型 | 描述 |
|
|
77
|
+
|------|------|------|
|
|
78
|
+
| `workspace` | `WorkspaceAPI` | 工作空间 API |
|
|
79
|
+
| `conversation` | `ConversationAPI` | 对话 API |
|
|
80
|
+
| `config` | `PluginConfig` | 插件配置 |
|
|
81
|
+
|
|
82
|
+
### WorkspaceAPI
|
|
83
|
+
|
|
84
|
+
工作空间相关操作:
|
|
85
|
+
|
|
86
|
+
| 属性/方法 | 描述 |
|
|
87
|
+
|----------|------|
|
|
88
|
+
| `id` | 当前工作空间 ID |
|
|
89
|
+
| `artifacts` | 制品管理 API |
|
|
90
|
+
|
|
91
|
+
### ArtifactsAPI
|
|
92
|
+
|
|
93
|
+
制品管理操作:
|
|
94
|
+
|
|
95
|
+
| 方法 | 描述 |
|
|
96
|
+
|------|------|
|
|
97
|
+
| `list(options?)` | 列出工作空间制品 |
|
|
98
|
+
| `upload(file, options?)` | 上传文件作为制品 |
|
|
99
|
+
| `download(artifactId)` | 下载制品 |
|
|
100
|
+
| `getContent(artifactId)` | 获取制品内容(预览) |
|
|
101
|
+
|
|
102
|
+
### ConversationAPI
|
|
103
|
+
|
|
104
|
+
对话操作:
|
|
105
|
+
|
|
106
|
+
| 方法 | 描述 |
|
|
107
|
+
|------|------|
|
|
108
|
+
| `sendMessage(message)` | 发送消息给 Agent |
|
|
109
|
+
| `onMessage(callback)` | 订阅对话消息 |
|
|
110
|
+
|
|
111
|
+
## Vite 配置
|
|
112
|
+
|
|
113
|
+
如果你使用 Vite 构建插件应用,请使用以下配置:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
// vite.config.ts
|
|
117
|
+
import { defineConfig } from 'vite';
|
|
118
|
+
import react from '@vitejs/plugin-react';
|
|
119
|
+
|
|
120
|
+
export default defineConfig({
|
|
121
|
+
plugins: [react()],
|
|
122
|
+
build: {
|
|
123
|
+
lib: {
|
|
124
|
+
entry: 'src/App.tsx',
|
|
125
|
+
name: 'MyPluginApp', // 必须与 plugin.json 中的 entry 一致
|
|
126
|
+
fileName: 'app',
|
|
127
|
+
formats: ['umd'],
|
|
128
|
+
},
|
|
129
|
+
rollupOptions: {
|
|
130
|
+
external: ['react', 'react-dom'],
|
|
131
|
+
output: {
|
|
132
|
+
globals: {
|
|
133
|
+
react: 'React',
|
|
134
|
+
'react-dom': 'ReactDOM',
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## 许可证
|
|
143
|
+
|
|
144
|
+
MIT
|
package/index.cjs.js
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Workspace artifact (file or document)
|
|
5
|
+
*/
|
|
6
|
+
export interface Artifact {
|
|
7
|
+
id: string;
|
|
8
|
+
workspace_id: string;
|
|
9
|
+
conversation_id: string | null;
|
|
10
|
+
file_path: string;
|
|
11
|
+
file_size: number;
|
|
12
|
+
mime_type: string;
|
|
13
|
+
created_at: string;
|
|
14
|
+
created_by_agent: string | null;
|
|
15
|
+
tags: string[];
|
|
16
|
+
metadata: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Artifact content response
|
|
21
|
+
*/
|
|
22
|
+
export interface ArtifactContent {
|
|
23
|
+
artifact_id: string;
|
|
24
|
+
content: string;
|
|
25
|
+
encoding: 'utf-8' | 'base64';
|
|
26
|
+
is_preview: boolean;
|
|
27
|
+
preview_size?: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Workspace file information
|
|
32
|
+
*/
|
|
33
|
+
export interface WorkspaceFile {
|
|
34
|
+
path: string;
|
|
35
|
+
name: string;
|
|
36
|
+
size: number;
|
|
37
|
+
mime_type: string;
|
|
38
|
+
is_dir: boolean;
|
|
39
|
+
mod_time: string;
|
|
40
|
+
permission: 'readonly' | 'readwrite';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Conversation message event
|
|
45
|
+
*/
|
|
46
|
+
export interface MessageEvent {
|
|
47
|
+
type: 'message' | 'status' | 'error';
|
|
48
|
+
role?: 'user' | 'assistant';
|
|
49
|
+
content?: string;
|
|
50
|
+
status?: string;
|
|
51
|
+
error?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Plugin configuration
|
|
56
|
+
*/
|
|
57
|
+
export type PluginConfig = Record<string, unknown>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* ChatPanel component props
|
|
61
|
+
*/
|
|
62
|
+
export interface ChatPanelProps {
|
|
63
|
+
workspaceId: string;
|
|
64
|
+
className?: string;
|
|
65
|
+
options?: {
|
|
66
|
+
showHistory?: boolean;
|
|
67
|
+
showQuickActions?: boolean;
|
|
68
|
+
placeholder?: string;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ==================== SDK 接口 ====================
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Workspace artifacts API
|
|
76
|
+
*/
|
|
77
|
+
export interface ArtifactsAPI {
|
|
78
|
+
/**
|
|
79
|
+
* List workspace artifacts
|
|
80
|
+
* @param options - Optional filters (conversationId)
|
|
81
|
+
*/
|
|
82
|
+
list(options?: { conversationId?: string }): Promise<Artifact[]>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Upload a file as artifact
|
|
86
|
+
* @param file - File to upload
|
|
87
|
+
* @param options - Optional metadata (filePath, conversationId, tags)
|
|
88
|
+
*/
|
|
89
|
+
upload(
|
|
90
|
+
file: File,
|
|
91
|
+
options?: {
|
|
92
|
+
filePath?: string;
|
|
93
|
+
conversationId?: string;
|
|
94
|
+
tags?: string[];
|
|
95
|
+
metadata?: Record<string, unknown>;
|
|
96
|
+
}
|
|
97
|
+
): Promise<Artifact>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Download an artifact
|
|
101
|
+
* @param artifactId - Artifact ID
|
|
102
|
+
*/
|
|
103
|
+
download(artifactId: string): Promise<Blob>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Get artifact content (text or base64)
|
|
107
|
+
* @param artifactId - Artifact ID
|
|
108
|
+
*/
|
|
109
|
+
getContent(artifactId: string): Promise<ArtifactContent>;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Workspace files API - Read/write files in the workspace directory
|
|
114
|
+
*/
|
|
115
|
+
export interface FilesAPI {
|
|
116
|
+
/**
|
|
117
|
+
* List files in a directory
|
|
118
|
+
* @param dirPath - Directory path (empty string for root)
|
|
119
|
+
* @param pattern - Optional glob pattern to filter files
|
|
120
|
+
*/
|
|
121
|
+
list(dirPath?: string, pattern?: string): Promise<WorkspaceFile[]>;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Read file content
|
|
125
|
+
* @param filePath - File path relative to workspace root
|
|
126
|
+
*/
|
|
127
|
+
read(filePath: string): Promise<string>;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Write content to a file
|
|
131
|
+
* @param filePath - File path relative to workspace root
|
|
132
|
+
* @param content - File content
|
|
133
|
+
*/
|
|
134
|
+
write(filePath: string, content: string): Promise<void>;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Delete a file
|
|
138
|
+
* @param filePath - File path relative to workspace root
|
|
139
|
+
*/
|
|
140
|
+
delete(filePath: string): Promise<void>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Conversation API
|
|
145
|
+
*/
|
|
146
|
+
export interface ConversationAPI {
|
|
147
|
+
/**
|
|
148
|
+
* Send a message to the agent
|
|
149
|
+
* @param message - Message object
|
|
150
|
+
*/
|
|
151
|
+
sendMessage(message: { role: 'user'; content: string }): Promise<void>;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Subscribe to conversation messages
|
|
155
|
+
* @param callback - Message event handler
|
|
156
|
+
* @returns Unsubscribe function
|
|
157
|
+
*/
|
|
158
|
+
onMessage(callback: (event: MessageEvent) => void): () => void;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Workspace API
|
|
163
|
+
*/
|
|
164
|
+
export interface WorkspaceAPI {
|
|
165
|
+
id: string;
|
|
166
|
+
artifacts: ArtifactsAPI;
|
|
167
|
+
files: FilesAPI;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface ElevoPluginContributes {
|
|
171
|
+
sidebar?: ElevoPluginSidebarContributes;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface ElevoPluginSidebarContributes {
|
|
175
|
+
menuItems?: ElevoPluginSidebarMenuItem[];
|
|
176
|
+
menuItemOverrides?: ElevoPluginSidebarMenuItemOverride[];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export type MenuItemPosition = 'first' | 'last' | 'before' | 'after';
|
|
180
|
+
|
|
181
|
+
export interface MenuItemPlacement {
|
|
182
|
+
position: MenuItemPosition;
|
|
183
|
+
anchorId?: string;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export interface ElevoPluginSidebarMenuItem {
|
|
187
|
+
id: string;
|
|
188
|
+
labelKey: string;
|
|
189
|
+
defaultLabel: string;
|
|
190
|
+
icon: React.ComponentType<{ className?: string }>;
|
|
191
|
+
view: React.ComponentType<any>;
|
|
192
|
+
placement?: MenuItemPlacement;
|
|
193
|
+
order?: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface ElevoPluginSidebarMenuItemOverride {
|
|
197
|
+
id: string;
|
|
198
|
+
visible?: boolean;
|
|
199
|
+
placement?: MenuItemPlacement;
|
|
200
|
+
labelKey?: string;
|
|
201
|
+
defaultLabel?: string;
|
|
202
|
+
icon?: React.ComponentType<{ className?: string }>;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface ElevoPluginWithContributes {
|
|
206
|
+
contributes?: ElevoPluginContributes;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Routing API - URL parameter management for plugins
|
|
211
|
+
*/
|
|
212
|
+
export interface RoutingAPI {
|
|
213
|
+
/**
|
|
214
|
+
* Get current URL search parameters
|
|
215
|
+
* @returns URLSearchParams object
|
|
216
|
+
*/
|
|
217
|
+
getSearchParams(): URLSearchParams;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Update search parameters (merge mode)
|
|
221
|
+
* @param params - Parameters to update
|
|
222
|
+
* @example
|
|
223
|
+
* sdk.routing.updateSearchParams({ filter: 'open', page: '2' });
|
|
224
|
+
*/
|
|
225
|
+
updateSearchParams(params: Record<string, string>): void;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Replace search parameters (override mode)
|
|
229
|
+
* @param params - New parameters
|
|
230
|
+
*/
|
|
231
|
+
setSearchParams(params: Record<string, string>): void;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Navigate to another view
|
|
235
|
+
* @param viewId - Target view ID (plugin prefix will be added automatically)
|
|
236
|
+
* @param params - Optional query parameters
|
|
237
|
+
* @example
|
|
238
|
+
* sdk.routing.navigate('main-view', { branch: 'main' });
|
|
239
|
+
*/
|
|
240
|
+
navigate(viewId: string, params?: Record<string, string>): void;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Get current view ID (without plugin prefix)
|
|
244
|
+
* @returns Current view ID
|
|
245
|
+
* @example
|
|
246
|
+
* // URL: ?view=git-assistant:main-view
|
|
247
|
+
* sdk.routing.getCurrentView() // returns 'main-view'
|
|
248
|
+
*/
|
|
249
|
+
getCurrentView(): string | null;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Elevo Plugin SDK
|
|
254
|
+
*/
|
|
255
|
+
export interface ElevoPluginSDK {
|
|
256
|
+
workspace: WorkspaceAPI;
|
|
257
|
+
conversation: ConversationAPI;
|
|
258
|
+
config: PluginConfig;
|
|
259
|
+
contributes?: ElevoPluginContributes;
|
|
260
|
+
routing: RoutingAPI;
|
|
261
|
+
/**
|
|
262
|
+
* Plugin name (used internally for namespacing view IDs)
|
|
263
|
+
* @internal
|
|
264
|
+
*/
|
|
265
|
+
pluginName?: string;
|
|
266
|
+
/**
|
|
267
|
+
* TODO: UI Components that plugins can use
|
|
268
|
+
* Note: Some components may require specific context providers
|
|
269
|
+
*/
|
|
270
|
+
// components: PluginUIComponents;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export declare function usePluginSDK(): ElevoPluginSDK;
|
|
274
|
+
export declare function useInjectCSS(cssText: string): void;
|
|
275
|
+
export declare function CopilotPanel(): React.ReactElement;
|
package/index.esm.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elevo-ai/plugin-sdk",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Elevo Plugin SDK - Build plugins for the Elevo platform",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.cjs.js",
|
|
7
|
+
"module": "./index.esm.js",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"import": "./index.esm.js",
|
|
13
|
+
"require": "./index.cjs.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"index.d.ts",
|
|
18
|
+
"index.esm.js",
|
|
19
|
+
"index.cjs.js",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"elevo",
|
|
24
|
+
"plugin",
|
|
25
|
+
"sdk",
|
|
26
|
+
"ai",
|
|
27
|
+
"workspace"
|
|
28
|
+
],
|
|
29
|
+
"author": {
|
|
30
|
+
"name": "Elevo Team",
|
|
31
|
+
"email": "dev@elevo.vip"
|
|
32
|
+
},
|
|
33
|
+
"license": "Apache-2.0",
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": "^19.0.0"
|
|
36
|
+
}
|
|
37
|
+
}
|