| 231 | name: StoreKey.Plugin, |
| 232 | version: 1, |
| 233 | onRehydrateStorage(state) { |
| 234 | // Skip store rehydration on server side |
| 235 | if (typeof window === "undefined") { |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | fetch("./plugins.json") |
| 240 | .then((res) => res.json()) |
| 241 | .then((res) => { |
| 242 | Promise.all( |
| 243 | res.map((item: any) => |
| 244 | // skip get schema |
| 245 | state.get(item.id) |
| 246 | ? item |
| 247 | : fetch(item.schema) |
| 248 | .then((res) => res.text()) |
| 249 | .then((content) => ({ |
| 250 | ...item, |
| 251 | content, |
| 252 | })) |
| 253 | .catch((e) => item), |
| 254 | ), |
| 255 | ).then((builtinPlugins: any) => { |
| 256 | builtinPlugins |
| 257 | .filter((item: any) => item?.content) |
| 258 | .forEach((item: any) => { |
| 259 | const plugin = state.create(item); |
| 260 | state.updatePlugin(plugin.id, (plugin) => { |
| 261 | const tool = FunctionToolService.add(plugin, true); |
| 262 | plugin.title = tool.api.definition.info.title; |
| 263 | plugin.version = tool.api.definition.info.version; |
| 264 | plugin.builtin = true; |
| 265 | }); |
| 266 | }); |
| 267 | }); |
| 268 | }); |
| 269 | }, |
| 270 | }, |
| 271 | ); |