@fastgpt-plugin/cli 0.1.0-beta.6 → 0.1.0-beta.8
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/dist/index.js +365 -72
- package/package.json +9 -10
- package/templates/tool/index.toolset.ts +1 -2
package/dist/index.js
CHANGED
|
@@ -166,6 +166,7 @@ const ToolManifestSchema = z.object({
|
|
|
166
166
|
|
|
167
167
|
//#endregion
|
|
168
168
|
//#region src/build/index.ts
|
|
169
|
+
const SDK_FACTORY_PACKAGE = "@fastgpt-plugin/sdk-factory";
|
|
169
170
|
/**
|
|
170
171
|
* 核心构建逻辑:给定入口目录和输出目录,完成一次工具构建。
|
|
171
172
|
*
|
|
@@ -196,11 +197,11 @@ async function buildToolPackage(options) {
|
|
|
196
197
|
const tempIndexPath = path.join(tempDir, "index.ts");
|
|
197
198
|
const tBuildStart = Date.now();
|
|
198
199
|
await build({
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
200
|
+
config: false,
|
|
201
|
+
deps: {
|
|
202
|
+
alwaysBundle: (id) => !isSdkFactoryImport(id),
|
|
203
|
+
neverBundle: [SDK_FACTORY_PACKAGE, `${SDK_FACTORY_PACKAGE}/*`]
|
|
204
|
+
},
|
|
204
205
|
entry: { index: tempIndexPath },
|
|
205
206
|
outDir: outputDir,
|
|
206
207
|
format: [options.format],
|
|
@@ -378,6 +379,9 @@ function pickToolDescription$1(explicitDescription, fallbackSource) {
|
|
|
378
379
|
function getOptionalString$1(value) {
|
|
379
380
|
return typeof value === "string" ? value : void 0;
|
|
380
381
|
}
|
|
382
|
+
function isSdkFactoryImport(id) {
|
|
383
|
+
return id === SDK_FACTORY_PACKAGE || id.startsWith(`${SDK_FACTORY_PACKAGE}/`);
|
|
384
|
+
}
|
|
381
385
|
function escapeRegExp(value) {
|
|
382
386
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
383
387
|
}
|
|
@@ -539,7 +543,7 @@ var CheckCommand = class extends BaseCommand {
|
|
|
539
543
|
//#endregion
|
|
540
544
|
//#region package.json
|
|
541
545
|
var name = "@fastgpt-plugin/cli";
|
|
542
|
-
var version = "0.1.0-beta.
|
|
546
|
+
var version = "0.1.0-beta.8";
|
|
543
547
|
|
|
544
548
|
//#endregion
|
|
545
549
|
//#region src/constants.ts
|
|
@@ -1020,58 +1024,328 @@ const ToolRunInputSchema = z.object({
|
|
|
1020
1024
|
});
|
|
1021
1025
|
|
|
1022
1026
|
//#endregion
|
|
1023
|
-
//#region ../../packages/infrastructure/src/plugin/plugin-runtime/
|
|
1024
|
-
|
|
1027
|
+
//#region ../../packages/infrastructure/src/plugin/plugin-runtime/ports/channel/event/client.ts
|
|
1028
|
+
/**
|
|
1029
|
+
* client -> host 的事件集合。
|
|
1030
|
+
*
|
|
1031
|
+
* client 是插件运行侧,host 是插件宿主侧。这里的 method 只能由 client 发送,
|
|
1032
|
+
* host 只能在 handler 中接收。
|
|
1033
|
+
*/
|
|
1034
|
+
const PluginChannelClientMethod = {
|
|
1035
|
+
/**
|
|
1036
|
+
* 插件 runtime 初始化完成,host 收到后可以把 pod 标记为 ready。
|
|
1037
|
+
*/
|
|
1038
|
+
ready: "client.ready",
|
|
1039
|
+
/**
|
|
1040
|
+
* 插件 runtime 的 stdout/stderr 输出。
|
|
1041
|
+
*/
|
|
1042
|
+
stdio: "client.stdio",
|
|
1043
|
+
/**
|
|
1044
|
+
* 插件 runtime 主动报告启动失败、运行失败或崩溃信息。
|
|
1045
|
+
*/
|
|
1046
|
+
fail: "client.fail",
|
|
1047
|
+
/**
|
|
1048
|
+
* 插件反向调用 host 能力,例如 uploadFile、userInfo。
|
|
1049
|
+
*/
|
|
1050
|
+
request: "client.request"
|
|
1051
|
+
};
|
|
1052
|
+
const PluginChannelClientMethodSchema = z.enum([
|
|
1053
|
+
PluginChannelClientMethod.ready,
|
|
1054
|
+
PluginChannelClientMethod.stdio,
|
|
1055
|
+
PluginChannelClientMethod.fail,
|
|
1056
|
+
PluginChannelClientMethod.request
|
|
1057
|
+
]);
|
|
1058
|
+
const PluginChannelReadyParamsSchema = z.object({
|
|
1059
|
+
pid: z.number().optional(),
|
|
1060
|
+
version: z.string().optional(),
|
|
1061
|
+
runtimeMode: z.string().optional(),
|
|
1062
|
+
capabilities: z.array(z.string()).optional(),
|
|
1063
|
+
startedAt: z.number().optional(),
|
|
1064
|
+
meta: z.unknown().optional()
|
|
1065
|
+
});
|
|
1066
|
+
const PluginChannelStdioParamsSchema = z.object({
|
|
1067
|
+
stream: z.enum(["stdout", "stderr"]),
|
|
1068
|
+
chunk: z.string(),
|
|
1069
|
+
timestamp: z.number().optional()
|
|
1070
|
+
});
|
|
1071
|
+
const PluginChannelFailParamsSchema = z.object({
|
|
1072
|
+
reason: z.enum([
|
|
1073
|
+
"startup",
|
|
1074
|
+
"runtime",
|
|
1075
|
+
"crash",
|
|
1076
|
+
"shutdown",
|
|
1077
|
+
"unknown"
|
|
1078
|
+
]),
|
|
1079
|
+
error: z.object({
|
|
1080
|
+
code: z.string(),
|
|
1081
|
+
message: z.string(),
|
|
1082
|
+
data: z.unknown().optional()
|
|
1083
|
+
}).optional(),
|
|
1084
|
+
exitCode: z.number().nullable().optional(),
|
|
1085
|
+
signal: z.string().nullable().optional(),
|
|
1086
|
+
timestamp: z.number().optional()
|
|
1087
|
+
});
|
|
1088
|
+
|
|
1089
|
+
//#endregion
|
|
1090
|
+
//#region ../../packages/infrastructure/src/plugin/plugin-runtime/ports/channel/event/common.ts
|
|
1091
|
+
const PluginChannelCommonMethod = {
|
|
1092
|
+
/**
|
|
1093
|
+
* 双向通用的流 frame 通道。
|
|
1094
|
+
*
|
|
1095
|
+
* 业务侧不直接调用这个 method;使用 `request({ input })`、`createReply({ output })`
|
|
1096
|
+
* 或 `pipeStream()` 时由底层 channel 自动发送。
|
|
1097
|
+
*/
|
|
1098
|
+
streamFrame: "channel.stream" };
|
|
1099
|
+
const PluginChannelCommonMethodSchema = z.enum([PluginChannelCommonMethod.streamFrame]);
|
|
1100
|
+
|
|
1101
|
+
//#endregion
|
|
1102
|
+
//#region ../../packages/infrastructure/src/plugin/plugin-runtime/ports/channel/event/host.ts
|
|
1103
|
+
/**
|
|
1104
|
+
* host -> client 的事件集合。
|
|
1105
|
+
*
|
|
1106
|
+
* host 是插件宿主侧,client 是插件运行侧。这里的 method 只能由 host 发送,
|
|
1107
|
+
* client 只能在 handler 中接收。
|
|
1108
|
+
*/
|
|
1109
|
+
const PluginChannelHostMethod = {
|
|
1110
|
+
/**
|
|
1111
|
+
* 调用插件业务事件,例如 run。
|
|
1112
|
+
*/
|
|
1113
|
+
request: "host.request",
|
|
1114
|
+
/**
|
|
1115
|
+
* 健康检查。
|
|
1116
|
+
*/
|
|
1117
|
+
ping: "host.ping",
|
|
1118
|
+
/**
|
|
1119
|
+
* 通知插件 runtime 准备退出。
|
|
1120
|
+
*/
|
|
1121
|
+
shutdown: "host.shutdown"
|
|
1122
|
+
};
|
|
1123
|
+
const PluginChannelHostMethodSchema = z.enum([
|
|
1124
|
+
PluginChannelHostMethod.request,
|
|
1125
|
+
PluginChannelHostMethod.ping,
|
|
1126
|
+
PluginChannelHostMethod.shutdown
|
|
1127
|
+
]);
|
|
1128
|
+
const PluginChannelPingParamsSchema = z.object({ timestamp: z.number() });
|
|
1129
|
+
const PluginChannelPingResultSchema = z.object({
|
|
1130
|
+
timestamp: z.number(),
|
|
1131
|
+
receivedAt: z.number().optional()
|
|
1132
|
+
});
|
|
1133
|
+
const PluginChannelShutdownParamsSchema = z.object({
|
|
1134
|
+
reason: z.string().optional(),
|
|
1135
|
+
timeoutMs: z.number().nonnegative().optional()
|
|
1136
|
+
});
|
|
1137
|
+
const PluginChannelShutdownResultSchema = z.object({
|
|
1138
|
+
accepted: z.boolean(),
|
|
1139
|
+
message: z.string().optional()
|
|
1140
|
+
});
|
|
1141
|
+
|
|
1142
|
+
//#endregion
|
|
1143
|
+
//#region ../../packages/infrastructure/src/plugin/plugin-runtime/ports/channel/event/index.ts
|
|
1144
|
+
const PluginChannelKnownMethodSchema = z.union([
|
|
1145
|
+
PluginChannelClientMethodSchema,
|
|
1146
|
+
PluginChannelCommonMethodSchema,
|
|
1147
|
+
PluginChannelHostMethodSchema
|
|
1148
|
+
]);
|
|
1149
|
+
|
|
1150
|
+
//#endregion
|
|
1151
|
+
//#region ../../packages/infrastructure/src/plugin/plugin-runtime/ports/channel/message.ts
|
|
1152
|
+
/**
|
|
1153
|
+
* Channel 协议只描述可跨传输层传递的 JSON 数据。
|
|
1154
|
+
*
|
|
1155
|
+
* 它刻意不绑定 Node IPC、TCP、HTTP 等具体实现;不同 driver 只需要负责把这些
|
|
1156
|
+
* message 发给对端,并把收到的 message 重新交给 channel port 分发。
|
|
1157
|
+
*/
|
|
1158
|
+
const PluginChannelProtocolVersionSchema = z.literal("1.0");
|
|
1159
|
+
const PluginChannelMessageIdSchema = z.union([z.string(), z.number()]);
|
|
1160
|
+
const PluginChannelErrorSchema = z.object({
|
|
1161
|
+
code: z.string(),
|
|
1162
|
+
message: z.string(),
|
|
1163
|
+
data: z.unknown().optional()
|
|
1164
|
+
});
|
|
1165
|
+
/**
|
|
1166
|
+
* request message:需要对端返回 success/error。
|
|
1167
|
+
*
|
|
1168
|
+
* `method` 的合法集合由 `event/` 里的方向化类型控制;这里保持 string 是为了让
|
|
1169
|
+
* 底层协议可以承载未来扩展的 method。
|
|
1170
|
+
*/
|
|
1171
|
+
const PluginChannelRequestMessageSchema = z.object({
|
|
1172
|
+
protocol: PluginChannelProtocolVersionSchema,
|
|
1173
|
+
id: PluginChannelMessageIdSchema,
|
|
1174
|
+
method: z.string(),
|
|
1175
|
+
params: z.unknown().optional(),
|
|
1176
|
+
traceId: z.string().optional(),
|
|
1177
|
+
timestamp: z.number().optional()
|
|
1178
|
+
});
|
|
1179
|
+
/**
|
|
1180
|
+
* notification message:单向事件,不产生响应。
|
|
1181
|
+
*
|
|
1182
|
+
* ready、stdio、fail 和 stream frame 都属于 notification。
|
|
1183
|
+
*/
|
|
1184
|
+
const PluginChannelNotificationMessageSchema = PluginChannelRequestMessageSchema.omit({ id: true });
|
|
1185
|
+
/**
|
|
1186
|
+
* success message:request 的成功响应。
|
|
1187
|
+
*
|
|
1188
|
+
* 流式输出不会直接塞进 `result`,而是先返回一个 stream descriptor/envelope,
|
|
1189
|
+
* 再通过 `channel.stream` notification 发送 chunk。
|
|
1190
|
+
*/
|
|
1191
|
+
const PluginChannelSuccessMessageSchema = z.object({
|
|
1192
|
+
protocol: PluginChannelProtocolVersionSchema,
|
|
1193
|
+
id: PluginChannelMessageIdSchema,
|
|
1194
|
+
result: z.unknown().optional(),
|
|
1195
|
+
traceId: z.string().optional(),
|
|
1196
|
+
timestamp: z.number().optional()
|
|
1197
|
+
});
|
|
1198
|
+
/**
|
|
1199
|
+
* error message:request 的失败响应。
|
|
1200
|
+
*/
|
|
1201
|
+
const PluginChannelErrorMessageSchema = z.object({
|
|
1202
|
+
protocol: PluginChannelProtocolVersionSchema,
|
|
1203
|
+
id: PluginChannelMessageIdSchema,
|
|
1204
|
+
error: PluginChannelErrorSchema,
|
|
1205
|
+
traceId: z.string().optional(),
|
|
1206
|
+
timestamp: z.number().optional()
|
|
1207
|
+
});
|
|
1208
|
+
const PluginChannelMessageSchema = z.union([
|
|
1209
|
+
PluginChannelRequestMessageSchema,
|
|
1210
|
+
PluginChannelNotificationMessageSchema,
|
|
1211
|
+
PluginChannelSuccessMessageSchema,
|
|
1212
|
+
PluginChannelErrorMessageSchema
|
|
1213
|
+
]);
|
|
1214
|
+
const PluginChannelTransportSchema = z.enum([
|
|
1215
|
+
"ipc",
|
|
1216
|
+
"tcp",
|
|
1217
|
+
"http"
|
|
1218
|
+
]);
|
|
1219
|
+
/**
|
|
1220
|
+
* host:插件宿主侧,例如 local-pool 的主进程。
|
|
1221
|
+
* client:插件运行侧,例如 fork 出来的插件子进程或 debug runtime。
|
|
1222
|
+
*/
|
|
1223
|
+
const PluginChannelSideSchema = z.enum(["host", "client"]);
|
|
1224
|
+
const PluginChannelStreamDescriptorSchema = z.object({
|
|
1225
|
+
streamId: z.string(),
|
|
1226
|
+
streamName: z.string(),
|
|
1227
|
+
meta: z.unknown().optional()
|
|
1228
|
+
});
|
|
1229
|
+
/**
|
|
1230
|
+
* 流数据统一通过 notification 发送 frame。
|
|
1231
|
+
*
|
|
1232
|
+
* 一个 stream 生命周期为 start -> chunk* -> end/error。chunk 的 payload 保持
|
|
1233
|
+
* unknown,由具体事件类型决定真实数据结构。
|
|
1234
|
+
*/
|
|
1235
|
+
const PluginChannelStreamFrameSchema = z.discriminatedUnion("type", [
|
|
1236
|
+
z.object({
|
|
1237
|
+
type: z.literal("start"),
|
|
1238
|
+
streamId: z.string(),
|
|
1239
|
+
streamName: z.string(),
|
|
1240
|
+
meta: z.unknown().optional()
|
|
1241
|
+
}),
|
|
1242
|
+
z.object({
|
|
1243
|
+
type: z.literal("chunk"),
|
|
1244
|
+
streamId: z.string(),
|
|
1245
|
+
chunk: z.unknown()
|
|
1246
|
+
}),
|
|
1247
|
+
z.object({
|
|
1248
|
+
type: z.literal("end"),
|
|
1249
|
+
streamId: z.string()
|
|
1250
|
+
}),
|
|
1251
|
+
z.object({
|
|
1252
|
+
type: z.literal("error"),
|
|
1253
|
+
streamId: z.string(),
|
|
1254
|
+
error: PluginChannelErrorSchema
|
|
1255
|
+
})
|
|
1256
|
+
]);
|
|
1025
1257
|
|
|
1026
1258
|
//#endregion
|
|
1027
1259
|
//#region src/debug/runtime.ts
|
|
1028
1260
|
const LOCAL_DEBUG_RUNTIME_GLOBAL_KEY = "__FASTGPT_PLUGIN_LOCAL_DEBUG_RUNTIME__";
|
|
1029
|
-
const
|
|
1261
|
+
const LOCAL_DEBUG_REPLY_MARK = "__localDebugReply__";
|
|
1030
1262
|
var LocalDebugChannel = class {
|
|
1031
|
-
|
|
1263
|
+
transport = "local-debug";
|
|
1264
|
+
requestHandler = null;
|
|
1265
|
+
notificationHandler = null;
|
|
1266
|
+
errorHandlers = /* @__PURE__ */ new Set();
|
|
1267
|
+
closeHandlers = /* @__PURE__ */ new Set();
|
|
1268
|
+
constructor(side, runtime) {
|
|
1269
|
+
this.side = side;
|
|
1032
1270
|
this.runtime = runtime;
|
|
1033
1271
|
}
|
|
1272
|
+
async request(method, params, options) {
|
|
1273
|
+
return this.runtime.dispatchFromSide(this.side, method, params, options);
|
|
1274
|
+
}
|
|
1275
|
+
async notify(method, params, options) {
|
|
1276
|
+
await this.runtime.notifyFromSide(this.side, method, params, options);
|
|
1277
|
+
}
|
|
1034
1278
|
setRequestHandler(handler) {
|
|
1035
|
-
this.
|
|
1279
|
+
this.requestHandler = handler;
|
|
1036
1280
|
}
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1281
|
+
setNotificationHandler(handler) {
|
|
1282
|
+
this.notificationHandler = handler;
|
|
1283
|
+
}
|
|
1284
|
+
async waitForStream() {
|
|
1285
|
+
throw new Error("Local debug channel does not support detached stream waiters.");
|
|
1286
|
+
}
|
|
1287
|
+
async createWritableStream(streamName, options) {
|
|
1288
|
+
const stream = StreamData.create();
|
|
1289
|
+
return {
|
|
1290
|
+
streamId: options?.streamId ?? randomUUID(),
|
|
1291
|
+
streamName: options?.streamName ?? streamName,
|
|
1292
|
+
...options?.meta !== void 0 ? { meta: options.meta } : {},
|
|
1293
|
+
write: async (chunk) => stream.write(chunk),
|
|
1294
|
+
end: async () => stream.end(),
|
|
1295
|
+
fail: async (error) => stream.fail(error instanceof Error ? error : new Error(String(error)))
|
|
1296
|
+
};
|
|
1297
|
+
}
|
|
1298
|
+
async pipeStream() {
|
|
1299
|
+
throw new Error("Local debug channel does not support detached stream piping.");
|
|
1042
1300
|
}
|
|
1043
|
-
|
|
1301
|
+
createReply(result, options) {
|
|
1044
1302
|
return {
|
|
1045
|
-
[
|
|
1303
|
+
[LOCAL_DEBUG_REPLY_MARK]: true,
|
|
1046
1304
|
...result !== void 0 ? { result } : {},
|
|
1047
1305
|
...options?.output !== void 0 ? { output: options.output } : {},
|
|
1048
|
-
...options ? { options: {
|
|
1049
|
-
traceId: options.traceId,
|
|
1050
|
-
outputMeta: options.outputMeta,
|
|
1051
|
-
outputStreamId: options.outputStreamId
|
|
1052
|
-
} } : {}
|
|
1306
|
+
...options?.outputStream !== void 0 ? { outputStream: options.outputStream } : {}
|
|
1053
1307
|
};
|
|
1054
1308
|
}
|
|
1055
|
-
|
|
1056
|
-
this.
|
|
1309
|
+
onError(handler) {
|
|
1310
|
+
this.errorHandlers.add(handler);
|
|
1311
|
+
return () => {
|
|
1312
|
+
this.errorHandlers.delete(handler);
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
onClose(handler) {
|
|
1316
|
+
this.closeHandlers.add(handler);
|
|
1317
|
+
return () => {
|
|
1318
|
+
this.closeHandlers.delete(handler);
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
async close(reason) {
|
|
1322
|
+
this.closeHandlers.forEach((handler) => handler(reason));
|
|
1323
|
+
}
|
|
1324
|
+
async handleRequest(request) {
|
|
1325
|
+
if (!this.requestHandler) throw new Error(`Local debug request handler is not configured: ${String(request.method)}`);
|
|
1326
|
+
return this.requestHandler(request);
|
|
1327
|
+
}
|
|
1328
|
+
async handleNotification(notification) {
|
|
1329
|
+
await this.notificationHandler?.(notification);
|
|
1057
1330
|
}
|
|
1058
1331
|
};
|
|
1059
1332
|
var LocalDebugRuntime = class {
|
|
1060
|
-
pluginRequestHandler = null;
|
|
1061
1333
|
hostRequestHandler = null;
|
|
1062
1334
|
ready = false;
|
|
1063
1335
|
readyPromise;
|
|
1064
1336
|
resolveReady;
|
|
1337
|
+
hostChannel;
|
|
1065
1338
|
pluginChannel;
|
|
1066
1339
|
constructor() {
|
|
1067
|
-
this.
|
|
1340
|
+
this.hostChannel = new LocalDebugChannel("host", this);
|
|
1341
|
+
this.pluginChannel = new LocalDebugChannel("client", this);
|
|
1342
|
+
this.hostChannel.setNotificationHandler(async (notification) => {
|
|
1343
|
+
if (notification.method === PluginChannelClientMethod.ready) this.markReady();
|
|
1344
|
+
});
|
|
1068
1345
|
this.readyPromise = new Promise((resolve) => {
|
|
1069
1346
|
this.resolveReady = resolve;
|
|
1070
1347
|
});
|
|
1071
1348
|
}
|
|
1072
|
-
setPluginRequestHandler(handler) {
|
|
1073
|
-
this.pluginRequestHandler = handler;
|
|
1074
|
-
}
|
|
1075
1349
|
setHostRequestHandler(handler) {
|
|
1076
1350
|
this.hostRequestHandler = handler;
|
|
1077
1351
|
}
|
|
@@ -1084,27 +1358,59 @@ var LocalDebugRuntime = class {
|
|
|
1084
1358
|
await this.readyPromise;
|
|
1085
1359
|
}
|
|
1086
1360
|
async invokePlugin(method, params, options) {
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
});
|
|
1092
|
-
}
|
|
1093
|
-
async
|
|
1094
|
-
|
|
1095
|
-
const
|
|
1096
|
-
return
|
|
1097
|
-
|
|
1361
|
+
return this.hostChannel.request(PluginChannelHostMethod.request, {
|
|
1362
|
+
eventName: method,
|
|
1363
|
+
payload: params,
|
|
1364
|
+
returnStream: true
|
|
1365
|
+
}, options);
|
|
1366
|
+
}
|
|
1367
|
+
async dispatchFromSide(side, method, params, options) {
|
|
1368
|
+
const requestId = options?.id ?? randomUUID();
|
|
1369
|
+
const target = side === "host" ? this.pluginChannel : this.hostChannel;
|
|
1370
|
+
return toRequestResult(requestId, side === "client" && method === PluginChannelClientMethod.request ? await this.invokeHostRequest(params, options) : await target.handleRequest({
|
|
1371
|
+
id: requestId,
|
|
1098
1372
|
method,
|
|
1099
|
-
|
|
1100
|
-
traceId: options.traceId,
|
|
1101
|
-
|
|
1102
|
-
|
|
1373
|
+
params,
|
|
1374
|
+
...options?.traceId !== void 0 ? { traceId: options.traceId } : {},
|
|
1375
|
+
raw: {
|
|
1376
|
+
protocol: "1.0",
|
|
1377
|
+
id: requestId,
|
|
1378
|
+
method: String(method),
|
|
1379
|
+
params,
|
|
1380
|
+
...options?.traceId !== void 0 ? { traceId: options.traceId } : {},
|
|
1381
|
+
timestamp: Date.now()
|
|
1382
|
+
},
|
|
1383
|
+
waitForInputStream: async () => createIncomingStream({
|
|
1384
|
+
source: options?.input ?? StreamData.create(),
|
|
1385
|
+
streamName: String(method),
|
|
1386
|
+
streamId: randomUUID(),
|
|
1387
|
+
traceId: options?.traceId
|
|
1388
|
+
})
|
|
1103
1389
|
}), options);
|
|
1104
1390
|
}
|
|
1105
|
-
async
|
|
1106
|
-
|
|
1107
|
-
|
|
1391
|
+
async notifyFromSide(side, method, params, options) {
|
|
1392
|
+
await (side === "host" ? this.pluginChannel : this.hostChannel).handleNotification({
|
|
1393
|
+
method,
|
|
1394
|
+
params,
|
|
1395
|
+
...options?.traceId !== void 0 ? { traceId: options.traceId } : {},
|
|
1396
|
+
raw: {
|
|
1397
|
+
protocol: "1.0",
|
|
1398
|
+
method: String(method),
|
|
1399
|
+
params,
|
|
1400
|
+
...options?.traceId !== void 0 ? { traceId: options.traceId } : {},
|
|
1401
|
+
timestamp: Date.now()
|
|
1402
|
+
}
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
async invokeHostRequest(params, options) {
|
|
1406
|
+
if (!this.hostRequestHandler) throw new Error(`Local debug host handler is not configured: ${params.method}`);
|
|
1407
|
+
return this.hostRequestHandler({
|
|
1408
|
+
method: params.method,
|
|
1409
|
+
args: params.args,
|
|
1410
|
+
traceId: options?.traceId,
|
|
1411
|
+
input: options?.input,
|
|
1412
|
+
createReply: (result, replyOptions) => this.pluginChannel.createReply(result, replyOptions)
|
|
1413
|
+
});
|
|
1108
1414
|
}
|
|
1109
1415
|
};
|
|
1110
1416
|
const createLocalDebugRuntime = () => new LocalDebugRuntime();
|
|
@@ -1116,35 +1422,25 @@ const setCurrentLocalDebugRuntime = (runtime) => {
|
|
|
1116
1422
|
}
|
|
1117
1423
|
store[LOCAL_DEBUG_RUNTIME_GLOBAL_KEY] = runtime;
|
|
1118
1424
|
};
|
|
1119
|
-
function createMessage(method, params, options) {
|
|
1120
|
-
return {
|
|
1121
|
-
id: options?.requestId ?? randomUUID(),
|
|
1122
|
-
messageType: "request",
|
|
1123
|
-
method,
|
|
1124
|
-
params,
|
|
1125
|
-
traceId: options?.traceId,
|
|
1126
|
-
timestamp: Date.now()
|
|
1127
|
-
};
|
|
1128
|
-
}
|
|
1129
1425
|
function isLocalDebugReplyDescriptor(value) {
|
|
1130
|
-
return Boolean(value && typeof value === "object" &&
|
|
1426
|
+
return Boolean(value && typeof value === "object" && LOCAL_DEBUG_REPLY_MARK in value && value[LOCAL_DEBUG_REPLY_MARK] === true);
|
|
1131
1427
|
}
|
|
1132
|
-
function
|
|
1428
|
+
function toRequestResult(requestId, response, options) {
|
|
1133
1429
|
const inputDone = options?.input !== void 0 ? Promise.resolve() : void 0;
|
|
1134
1430
|
if (!isLocalDebugReplyDescriptor(response)) return {
|
|
1135
|
-
requestId
|
|
1431
|
+
requestId,
|
|
1136
1432
|
result: response,
|
|
1137
1433
|
...inputDone ? { inputDone } : {}
|
|
1138
1434
|
};
|
|
1139
1435
|
const output = response.output !== void 0 ? createIncomingStream({
|
|
1140
1436
|
source: response.output,
|
|
1141
|
-
streamName: response.
|
|
1142
|
-
streamId: response.
|
|
1143
|
-
traceId: response.
|
|
1144
|
-
meta: response.
|
|
1437
|
+
streamName: response.outputStream?.streamName ?? "stream",
|
|
1438
|
+
streamId: response.outputStream?.streamId ?? randomUUID(),
|
|
1439
|
+
traceId: response.outputStream?.traceId,
|
|
1440
|
+
meta: response.outputStream?.meta
|
|
1145
1441
|
}) : void 0;
|
|
1146
1442
|
return {
|
|
1147
|
-
requestId
|
|
1443
|
+
requestId,
|
|
1148
1444
|
result: response.result,
|
|
1149
1445
|
...output ? { output } : {},
|
|
1150
1446
|
...inputDone ? { inputDone } : {}
|
|
@@ -1310,11 +1606,8 @@ function pickTargetTool(snapshot, toolId) {
|
|
|
1310
1606
|
}
|
|
1311
1607
|
function createVirtualHostHandler(uploadDir) {
|
|
1312
1608
|
return async ({ method, args, input }) => {
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
const invokeMethod = payload.method;
|
|
1316
|
-
const invokeArgs = ensurePlainObject(payload.args);
|
|
1317
|
-
switch (invokeMethod) {
|
|
1609
|
+
const invokeArgs = ensurePlainObject(args);
|
|
1610
|
+
switch (method) {
|
|
1318
1611
|
case InvokeMethodEnum.uploadFile: {
|
|
1319
1612
|
const buffer = await readSourceToBuffer(input);
|
|
1320
1613
|
const fileName = sanitizeFileName(typeof invokeArgs.fileName === "string" && invokeArgs.fileName.trim().length > 0 ? invokeArgs.fileName : "debug-upload.bin");
|
|
@@ -1332,7 +1625,7 @@ function createVirtualHostHandler(uploadDir) {
|
|
|
1332
1625
|
accessURL: pathToFileURL(outputPath).href
|
|
1333
1626
|
};
|
|
1334
1627
|
}
|
|
1335
|
-
default: throw new Error(`本地虚拟环境暂不支持反向调用: ${String(
|
|
1628
|
+
default: throw new Error(`本地虚拟环境暂不支持反向调用: ${String(method)}`);
|
|
1336
1629
|
}
|
|
1337
1630
|
};
|
|
1338
1631
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastgpt-plugin/cli",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -16,13 +16,6 @@
|
|
|
16
16
|
"templates",
|
|
17
17
|
"skills"
|
|
18
18
|
],
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "tsdown",
|
|
21
|
-
"build:verbose": "tsdown",
|
|
22
|
-
"test": "vitest run",
|
|
23
|
-
"dev": "tsx src/index.ts",
|
|
24
|
-
"prepublishOnly": "pnpm run build"
|
|
25
|
-
},
|
|
26
19
|
"dependencies": {
|
|
27
20
|
"@oxc-parser/binding-wasm32-wasi": "^0.112.0",
|
|
28
21
|
"@inquirer/prompts": "^8.2.0",
|
|
@@ -30,7 +23,7 @@
|
|
|
30
23
|
"consola": "^3.4.2",
|
|
31
24
|
"es-toolkit": "^1.44.0",
|
|
32
25
|
"oxc-parser": "^0.112.0",
|
|
33
|
-
"tsdown": "
|
|
26
|
+
"tsdown": "^0.21.10",
|
|
34
27
|
"yazl": "^3.3.1",
|
|
35
28
|
"yaml": "^2.6.1",
|
|
36
29
|
"zod": "^4"
|
|
@@ -43,5 +36,11 @@
|
|
|
43
36
|
},
|
|
44
37
|
"engines": {
|
|
45
38
|
"node": ">=22.12.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsdown",
|
|
42
|
+
"build:verbose": "tsdown",
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"dev": "tsx src/index.ts"
|
|
46
45
|
}
|
|
47
|
-
}
|
|
46
|
+
}
|