@gencode/plugin-sdk 0.0.4 → 0.0.6
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 +111 -25
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -125,34 +125,117 @@ export default function register(api: PluginApi) {
|
|
|
125
125
|
label: "收集用户反馈",
|
|
126
126
|
description: "Collect structured feedback from the user.",
|
|
127
127
|
schema: {
|
|
128
|
+
type: "object",
|
|
128
129
|
title: "用户反馈",
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
{
|
|
132
|
-
|
|
130
|
+
properties: {
|
|
131
|
+
rating: { type: "number", title: "评分" },
|
|
132
|
+
comment: { type: "string", title: "评论" },
|
|
133
|
+
},
|
|
134
|
+
required: ["rating"],
|
|
135
|
+
},
|
|
136
|
+
extra: {
|
|
137
|
+
ui: {
|
|
138
|
+
fields: {
|
|
139
|
+
comment: { widget: "textarea" },
|
|
140
|
+
},
|
|
141
|
+
},
|
|
133
142
|
},
|
|
134
143
|
});
|
|
135
144
|
}
|
|
136
145
|
```
|
|
137
146
|
|
|
138
|
-
###
|
|
147
|
+
### JSON Schema 约定
|
|
139
148
|
|
|
140
|
-
`schema
|
|
149
|
+
`schema` 现在遵循 JSON Schema 风格的对象定义,推荐至少提供:
|
|
141
150
|
|
|
142
|
-
|
|
|
151
|
+
| 字段 | 说明 |
|
|
143
152
|
|------|------|
|
|
144
|
-
| `
|
|
145
|
-
| `
|
|
146
|
-
| `
|
|
147
|
-
| `
|
|
148
|
-
| `
|
|
149
|
-
| `
|
|
150
|
-
| `
|
|
151
|
-
| `
|
|
153
|
+
| `type: "object"` | UI tool 顶层 schema 必填 |
|
|
154
|
+
| `properties` | 表单字段定义 |
|
|
155
|
+
| `required` | 必填字段列表 |
|
|
156
|
+
| `description` | 表单或字段说明 |
|
|
157
|
+
| `default` | 默认值 |
|
|
158
|
+
| `enum` | 单选枚举 |
|
|
159
|
+
| `format: "date"` | 日期输入 |
|
|
160
|
+
| `items.enum` | 多选枚举数组 |
|
|
161
|
+
|
|
162
|
+
示例:
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
schema: {
|
|
166
|
+
type: "object",
|
|
167
|
+
title: "报告参数",
|
|
168
|
+
properties: {
|
|
169
|
+
format: {
|
|
170
|
+
type: "string",
|
|
171
|
+
title: "输出格式",
|
|
172
|
+
enum: ["markdown", "pdf", "html"],
|
|
173
|
+
},
|
|
174
|
+
tags: {
|
|
175
|
+
type: "array",
|
|
176
|
+
title: "标签",
|
|
177
|
+
items: {
|
|
178
|
+
type: "string",
|
|
179
|
+
enum: ["tech", "ops", "finance"],
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
startDate: {
|
|
183
|
+
type: "string",
|
|
184
|
+
title: "开始日期",
|
|
185
|
+
format: "date",
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### `extra` 扩展字段
|
|
192
|
+
|
|
193
|
+
有些场景不适合完全按 JSON Schema 的标准字段渲染。此时可以通过 `extra` 透传一份 JSON-safe 扩展配置给前端,由接入方自行解释并渲染更高自定义的 UI。
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
api.registerUiTool({
|
|
197
|
+
name: "custom_summary_form",
|
|
198
|
+
label: "自定义摘要表单",
|
|
199
|
+
description: "Collect values through a custom-rendered panel.",
|
|
200
|
+
schema: {
|
|
201
|
+
type: "object",
|
|
202
|
+
title: "摘要确认",
|
|
203
|
+
properties: {
|
|
204
|
+
approved: { type: "boolean", title: "是否确认" },
|
|
205
|
+
comment: { type: "string", title: "补充说明" },
|
|
206
|
+
},
|
|
207
|
+
required: ["approved"],
|
|
208
|
+
},
|
|
209
|
+
extra: {
|
|
210
|
+
renderer: "summary-card",
|
|
211
|
+
sections: [
|
|
212
|
+
{ kind: "markdown", title: "摘要", content: "这里放自定义摘要内容" },
|
|
213
|
+
],
|
|
214
|
+
ui: {
|
|
215
|
+
fields: {
|
|
216
|
+
comment: { widget: "textarea", placeholder: "可选补充说明" },
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
约束:
|
|
224
|
+
|
|
225
|
+
- `extra` 只负责扩展前端渲染,不参与内置 JSON Schema 校验
|
|
226
|
+
- 用户提交结果仍然统一回传到 `values`
|
|
227
|
+
- 建议保持 JSON-safe,避免函数、类实例或不可序列化对象
|
|
228
|
+
|
|
229
|
+
推荐把非标准控件语义放在 `extra.ui.fields` 中,例如:
|
|
230
|
+
|
|
231
|
+
- `widget: "textarea"`
|
|
232
|
+
- `widget: "file"`
|
|
233
|
+
- `placeholder`
|
|
234
|
+
- `enumLabels`
|
|
152
235
|
|
|
153
236
|
### 自定义校验
|
|
154
237
|
|
|
155
|
-
内置
|
|
238
|
+
内置 JSON Schema 校验之外,可以提供 `validate` 函数做跨字段校验:
|
|
156
239
|
|
|
157
240
|
```ts
|
|
158
241
|
api.registerUiTool({
|
|
@@ -160,11 +243,13 @@ api.registerUiTool({
|
|
|
160
243
|
label: "选择日期范围",
|
|
161
244
|
description: "Collect a date range with cross-field validation.",
|
|
162
245
|
schema: {
|
|
246
|
+
type: "object",
|
|
163
247
|
title: "日期范围",
|
|
164
|
-
|
|
165
|
-
{
|
|
166
|
-
{
|
|
167
|
-
|
|
248
|
+
properties: {
|
|
249
|
+
startDate: { type: "string", title: "开始日期", format: "date" },
|
|
250
|
+
endDate: { type: "string", title: "结束日期", format: "date" },
|
|
251
|
+
},
|
|
252
|
+
required: ["startDate", "endDate"],
|
|
168
253
|
},
|
|
169
254
|
validate(values) {
|
|
170
255
|
const start = values.startDate as string;
|
|
@@ -187,16 +272,16 @@ api.registerUiTool({
|
|
|
187
272
|
| 维度 | `registerTool` | `registerUiTool` |
|
|
188
273
|
|------|---------------|-----------------|
|
|
189
274
|
| 用途 | 通用工具 | 收集前端表单输入 |
|
|
190
|
-
| 开发者关注点 | 完整 `execute` 实现 |
|
|
275
|
+
| 开发者关注点 | 完整 `execute` 实现 | 只需提供 JSON Schema + 元数据 |
|
|
191
276
|
| sessionId | 需要自行处理 | 框架自动绑定 |
|
|
192
277
|
| 暂停/恢复 | 需要手动抛出信号 | 框架自动处理 |
|
|
193
|
-
| 结果校验 | 自行实现 | 内置
|
|
278
|
+
| 结果校验 | 自行实现 | 内置 JSON Schema 校验 + 可选自定义 validator |
|
|
194
279
|
|
|
195
280
|
### 运行流程
|
|
196
281
|
|
|
197
282
|
1. LLM 调用 UI 工具 → 自动抛出 `UiToolPauseSignal` 暂停 agent
|
|
198
283
|
2. Runner 捕获信号,发出 `ui_tool_request` 进度事件(包含表单 schema)
|
|
199
|
-
3. 前端根据 schema
|
|
284
|
+
3. 前端根据 schema 渲染标准表单,或结合 `extra` 渲染自定义 UI
|
|
200
285
|
4. 用户提交后,CLI 带 `uiToolResume` 重新调用 agent
|
|
201
286
|
5. 框架自动校验数据(内置 + 自定义 validator)
|
|
202
287
|
6. 校验通过 → 工具返回提交值给 LLM → agent 继续执行
|
|
@@ -208,7 +293,8 @@ api.registerUiTool({
|
|
|
208
293
|
- `PluginUiToolDescriptor` — `registerUiTool` 的参数类型
|
|
209
294
|
- `PluginUiToolOptions` — 可选参数(如 `optional`)
|
|
210
295
|
- `UiToolSchema` — 表单 schema
|
|
211
|
-
- `
|
|
212
|
-
- `
|
|
296
|
+
- `UiToolJsonSchemaProperty` — 单个字段的 JSON Schema 定义
|
|
297
|
+
- `UiToolJsonSchemaType` — 支持的 JSON Schema `type`
|
|
298
|
+
- `UiToolExtra` — 前端扩展渲染负载
|
|
213
299
|
- `UiToolValidationError` — 校验错误
|
|
214
300
|
- `UiToolValidationResult` — 校验结果
|
package/dist/index.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export type { MemoryProvider, MemoryProviderContext, MemoryProviderFactory, Memo
|
|
|
7
7
|
export type { EmbeddingProvider, EmbeddingProviderContext, EmbeddingProviderFactory, EmbeddingProviderRegistration, } from "@gencode/agents";
|
|
8
8
|
export type { PluginHookName, PluginHookHandlerMap, PluginHookAgentContext, PluginHookBeforeModelResolveEvent, PluginHookBeforeModelResolveResult, PluginHookBeforePromptBuildEvent, PluginHookBeforePromptBuildResult, PluginHookLlmInputEvent, PluginHookLlmOutputEvent, PluginHookBeforeToolCallEvent, PluginHookBeforeToolCallResult, PluginHookAfterToolCallEvent, PluginHookAgentEndEvent, PluginHookBeforeCompactionEvent, PluginHookAfterCompactionEvent, PluginHookSessionStartEvent, PluginHookSessionEndEvent, PluginHookSessionResetEvent, PluginHookMemoryChangedEvent, } from "@gencode/agents";
|
|
9
9
|
export type { PluginRuntime } from "@gencode/agents";
|
|
10
|
-
export type {
|
|
10
|
+
export type { UiToolExtra, UiToolJsonSchemaProperty, UiToolJsonSchemaType, UiToolSchema, UiToolValidationError, UiToolValidationResult, } from "@gencode/shared";
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,cAAc,EACd,wBAAwB,EACxB,kBAAkB,EAClB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,iBAAiB,EACjB,wBAAwB,EACxB,wBAAwB,EACxB,6BAA6B,GAC9B,MA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BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,YAAY,EACV,WAAW,EACX,wBAAwB,EACxB,oBAAoB,EACpB,YAAY,EACZ,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gencode/plugin-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@gencode/agents": "0.0.
|
|
21
|
-
"@gencode/shared": "0.0.
|
|
20
|
+
"@gencode/agents": "0.0.42",
|
|
21
|
+
"@gencode/shared": "0.0.14"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"typescript": "^5.9.3"
|