koishi-plugin-memesluna 0.5.5 → 0.5.7

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/lib/index.js CHANGED
@@ -1481,23 +1481,39 @@ var MemesLunaService = class extends import_koishi.Service {
1481
1481
  await this.ctx.database.remove("memesluna_endpoints", { name: name2 });
1482
1482
  return true;
1483
1483
  }
1484
- async buildRouteInventory(backendPath) {
1484
+ async buildRouteInventory(backendPath, synonymGroups) {
1485
1485
  const endpoints = await this.getEndpoints();
1486
1486
  const collections = await this.getCollections();
1487
- const lines = [];
1488
- for (const endpoint of endpoints) {
1489
- const desc = endpoint.description || endpoint.name;
1490
- lines.push(`- 端点名: ${endpoint.name} | 描述: ${desc} | 接口地址: ${backendPath}/${endpoint.name}`);
1487
+ const sections = [];
1488
+ if (endpoints.length > 0) {
1489
+ const endpointLines = endpoints.map((ep) => {
1490
+ const desc = ep.description || ep.name;
1491
+ return ` - ${ep.name}:${desc} → ${backendPath}/${ep.name}`;
1492
+ });
1493
+ sections.push(`【端点转发】
1494
+ ${endpointLines.join("\n")}`);
1491
1495
  }
1496
+ const collectionLines = [];
1492
1497
  for (const collection of collections) {
1493
1498
  const info = await this.getCollectionInfo(collection);
1494
1499
  if (info?.hasContent) {
1495
- const desc = info.description || collection;
1496
- const displayName = desc.endsWith("表情包") ? desc : `${desc}表情包`;
1497
- lines.push(`- ${displayName} | 描述: ${collection} | 表情包路径: ${backendPath}/${collection}`);
1500
+ const desc = info.description ? `(${info.description})` : "";
1501
+ collectionLines.push(` - ${collection}${desc} ${backendPath}/${collection}`);
1498
1502
  }
1499
1503
  }
1500
- return lines.join("\n");
1504
+ if (collectionLines.length > 0) {
1505
+ sections.push(`【表情包合集】
1506
+ ${collectionLines.join("\n")}`);
1507
+ }
1508
+ if (synonymGroups && synonymGroups.length > 0) {
1509
+ const groupLines = synonymGroups.filter((g) => g.length > 0).map((g) => ` ${g.join(" / ")}`);
1510
+ if (groupLines.length > 0) {
1511
+ sections.push(`【情绪/标签】(每行为同一组,组内任意词均可作为路由)
1512
+ ${groupLines.join("\n")}
1513
+ 标签路由格式:${backendPath}/标签名`);
1514
+ }
1515
+ }
1516
+ return sections.join("\n\n");
1501
1517
  }
1502
1518
  };
1503
1519
 
@@ -1732,22 +1748,18 @@ var Config = import_koishi2.Schema.intersect([
1732
1748
  selfUrl: import_koishi2.Schema.string().default("").description("插件对外暴露的完整地址(含协议和端口),留空则自动使用 Koishi server.selfUrl"),
1733
1749
  injectVariables: import_koishi2.Schema.boolean().default(true).description("开启后向 ChatLuna 注入 {{endpoint}} 路由列表和 {{memesluna}} 使用说明,让 AI 能发图"),
1734
1750
  variableRefreshIntervalMs: import_koishi2.Schema.number().min(30 * 1e3).max(60 * 60 * 1e3).default(5 * 60 * 1e3).description("ChatLuna 变量自动刷新间隔(毫秒),新增合集或路由后最多等待这么久才生效"),
1735
- injectVariablesPrompt: import_koishi2.Schema.string().role("textarea").default(`你可以使用表情包来丰富你的回复。可用的表情包合集如下:
1751
+ injectVariablesPrompt: import_koishi2.Schema.string().role("textarea").default(`你可以根据自己当前的心情或者动作从标签中选择合适的表情发送,也可以根据需要选择合适的表情包合集或端点。
1736
1752
 
1737
- {endpoint}
1753
+ 可用的路由如下:
1738
1754
 
1739
- 使用方法:
1740
- - 合集名路由:{base_url}/memesluna/合集名 自动随机返回该合集的图片
1741
- - 端点名路由: {base_url}/memesluna/端点名 自动随机返回该端点的图片
1742
- - 标签名路由:{base_url}/memesluna/标签名 按标签跨合集随机返回图片(可用标签如:{tags})
1743
- - 合集搜索:{base_url}/memesluna/合集名?q=关键词 在合集中按语义搜索
1755
+ {endpoint}
1744
1756
 
1745
- 使用方法:
1746
- 直接用 {base_url} 拼接路径即可,合集名和标签名不要重名,合集优先匹配。只使用上面列出的合集名和标签名,不要自己编造路径。
1747
- 例如:
1748
- 如果你想发送"开心"标签下的表情包,请在回复中包含类似{base_url}/memesluna/开心
1749
- 如果你想发送"vrchat" 合集下的表情包,请在回复中包含类似{base_url}/memesluna/vrchat
1750
- 如果你想发送"lai" 端点的表情包,请在回复中包含类似{base_url}/memesluna/lai`).description("注入 ChatLuna 的提示词模板,支持占位符:{endpoint}(路由列表)、{base_url}(服务地址)、{tags}(所有可用标签)")
1757
+ 使用规则:
1758
+ - 直接将路径拼接到 {base_url} 后即可,例如 {base_url}/memesluna/开心
1759
+ - 合集名和标签名不要重名,合集优先匹配
1760
+ - 只使用上面列出的名称,不要自己编造路径
1761
+ - 标签路由按情绪跨合集随机返图,合集路由在指定合集内随机,端点路由转发到外部图源
1762
+ - 合集搜索:{base_url}/memesluna/合集名?q=关键词 可按语义搜索指定合集`).description("注入 ChatLuna 的提示词模板,支持占位符:{endpoint}(路由列表)、{base_url}(服务地址)、{tags}(所有可用标签)")
1751
1763
  }).description("基础配置"),
1752
1764
  import_koishi2.Schema.object({
1753
1765
  autoCollect: import_koishi2.Schema.boolean().default(false).description("开启后自动监听群聊消息,高频出现的图片会自动进入暂缓区等待审核"),
@@ -2192,7 +2204,8 @@ async function getPromptTags(ctx, config) {
2192
2204
  __name(getPromptTags, "getPromptTags");
2193
2205
  async function updateMemesVariable(ctx, config, service) {
2194
2206
  const baseUrl = toAbsoluteBaseUrl(ctx, config);
2195
- const inventory = await service.buildRouteInventory(config.backendPath);
2207
+ const synonymGroups = parseSynonymGroups(config.synonymGroups || []);
2208
+ const inventory = await service.buildRouteInventory(config.backendPath, synonymGroups);
2196
2209
  const tagsStr = await getPromptTags(ctx, config);
2197
2210
  ctx.chatluna.promptRenderer.setVariable("endpoint", inventory || "- 暂无可用路由");
2198
2211
  const memeslunaText = config.injectVariablesPrompt.replaceAll("{endpoint}", inventory || "- 暂无可用路由").replaceAll("{base_url}", baseUrl).replaceAll("{tags}", tagsStr);
@@ -2569,7 +2582,8 @@ function applyServer(ctx, config, service) {
2569
2582
  const endpoints = await service.getEndpoints();
2570
2583
  const collections = await service.getCollections();
2571
2584
  const collectionInfos = await Promise.all(collections.map((name2) => service.getCollectionInfo(name2)));
2572
- const inventory = await service.buildRouteInventory(basePath);
2585
+ const synonymGroups = parseSynonymGroups(config.synonymGroups || []);
2586
+ const inventory = await service.buildRouteInventory(basePath, synonymGroups);
2573
2587
  const tagsStr = await getPromptTags(ctx, config);
2574
2588
  const llmPrompt = config.injectVariablesPrompt.replaceAll("{endpoint}", inventory || "- 暂无可用路由").replaceAll("{base_url}", baseUrl).replaceAll("{tags}", tagsStr);
2575
2589
  koa.body = {
package/lib/service.d.ts CHANGED
@@ -176,7 +176,7 @@ export declare class MemesLunaService extends Service {
176
176
  addEndpoint(input: ApiEndpointInput): Promise<string>;
177
177
  updateEndpoint(name: string, input: Partial<ApiEndpointInput>): Promise<boolean>;
178
178
  deleteEndpoint(name: string): Promise<boolean>;
179
- buildRouteInventory(backendPath: string): Promise<string>;
179
+ buildRouteInventory(backendPath: string, synonymGroups?: string[][]): Promise<string>;
180
180
  }
181
181
  declare module 'koishi' {
182
182
  interface Context {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-memesluna",
3
3
  "description": "Image Forward service for Koishi with ChatLuna integration",
4
- "version": "0.5.5",
4
+ "version": "0.5.7",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "types": "lib/index.d.ts",