koishi-plugin-chatluna-anuneko-api-adapter 1.0.0 → 1.0.1

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.
Files changed (3) hide show
  1. package/lib/index.js +13 -13
  2. package/package.json +1 -1
  3. package/src/index.ts +14 -14
package/lib/index.js CHANGED
@@ -428,7 +428,7 @@ function apply(ctx, config2) {
428
428
  if (config2.cookie) {
429
429
  headers["Cookie"] = config2.cookie;
430
430
  }
431
- logger2.info("创建新会话...");
431
+ logInfo("创建新会话...");
432
432
  const createResponse = await fetch("https://anuneko.com/api/v1/chat", {
433
433
  method: "POST",
434
434
  headers,
@@ -439,10 +439,10 @@ function apply(ctx, config2) {
439
439
  if (!chatId) {
440
440
  return "❌ 创建会话失败";
441
441
  }
442
- logger2.info("会话创建成功,ID:", chatId);
442
+ logInfo("会话创建成功,ID:", chatId);
443
443
  const url = `https://anuneko.com/api/v1/msg/${chatId}/stream`;
444
444
  const data = { contents: [message] };
445
- logger2.info("发送消息...");
445
+ logInfo("发送消息...");
446
446
  const response = await fetch(url, {
447
447
  method: "POST",
448
448
  headers,
@@ -459,13 +459,13 @@ function apply(ctx, config2) {
459
459
  const { done, value } = await reader.read();
460
460
  if (done) break;
461
461
  const chunkStr = decoder.decode(value, { stream: true });
462
- logger2.info("收到数据块:", chunkStr.substring(0, 200));
462
+ logInfo("收到数据块:", chunkStr.substring(0, 200));
463
463
  const lines = chunkStr.split("\n");
464
464
  for (const line of lines) {
465
465
  if (!line.trim()) {
466
466
  continue;
467
467
  }
468
- logger2.info("处理行:", line.substring(0, 100));
468
+ logInfo("处理行:", line.substring(0, 100));
469
469
  if (!line.startsWith("data: ")) {
470
470
  logger2.warn("非 data: 格式的行:", line);
471
471
  continue;
@@ -474,31 +474,31 @@ function apply(ctx, config2) {
474
474
  if (!rawJson) continue;
475
475
  try {
476
476
  const j = JSON.parse(rawJson);
477
- logger2.info("解析的 JSON:", JSON.stringify(j));
477
+ logInfo("解析的 JSON:", JSON.stringify(j));
478
478
  if (j.msg_id) {
479
479
  currentMsgId = j.msg_id;
480
- logger2.info("更新 msg_id:", currentMsgId);
480
+ logInfo("更新 msg_id:", currentMsgId);
481
481
  }
482
482
  if (j.c && Array.isArray(j.c)) {
483
- logger2.info("处理多分支内容");
483
+ logInfo("处理多分支内容");
484
484
  for (const choice of j.c) {
485
485
  const idx = choice.c ?? 0;
486
486
  if (idx === 0 && choice.v) {
487
487
  result += choice.v;
488
- logger2.info("添加内容:", choice.v);
488
+ logInfo("添加内容:", choice.v);
489
489
  }
490
490
  }
491
491
  } else if (j.v && typeof j.v === "string") {
492
492
  result += j.v;
493
- logger2.info("添加常规内容:", j.v);
493
+ logInfo("添加常规内容:", j.v);
494
494
  }
495
495
  } catch (error) {
496
496
  logger2.error("解析 JSON 失败:", rawJson, error);
497
497
  }
498
498
  }
499
499
  }
500
- logger2.info("最终结果长度:", result.length);
501
- logger2.info("最终结果内容:", result);
500
+ logInfo("最终结果长度:", result.length);
501
+ logInfo("最终结果内容:", result);
502
502
  if (currentMsgId) {
503
503
  await fetch("https://anuneko.com/api/v1/msg/select-choice", {
504
504
  method: "POST",
@@ -506,7 +506,7 @@ function apply(ctx, config2) {
506
506
  body: JSON.stringify({ msg_id: currentMsgId, choice_idx: 0 })
507
507
  });
508
508
  }
509
- logger2.info("收到完整响应");
509
+ logInfo("收到完整响应");
510
510
  return result || "❌ 未收到响应";
511
511
  } catch (error) {
512
512
  logger2.error("请求失败:", error);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-chatluna-anuneko-api-adapter",
3
3
  "description": "anuneko API adapter for ChatLuna, using pearktrue API.",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/src/index.ts CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  } from 'koishi-plugin-chatluna/utils/error'
7
7
  import { createLogger } from 'koishi-plugin-chatluna/utils/logger'
8
8
  import { AnunekoClient } from './anuneko-client'
9
- import { initializeLogger } from './logger'
9
+ import { initializeLogger, logInfo } from './logger'
10
10
 
11
11
  export let logger: Logger
12
12
  export let anunekoClient: any = null
@@ -53,7 +53,7 @@ export function apply(ctx: Context, config: Config) {
53
53
  }
54
54
 
55
55
  // 创建新会话
56
- logger.info('创建新会话...')
56
+ logInfo('创建新会话...')
57
57
  const createResponse = await fetch('https://anuneko.com/api/v1/chat', {
58
58
  method: 'POST',
59
59
  headers,
@@ -66,13 +66,13 @@ export function apply(ctx: Context, config: Config) {
66
66
  return '❌ 创建会话失败'
67
67
  }
68
68
 
69
- logger.info('会话创建成功,ID:', chatId)
69
+ logInfo('会话创建成功,ID:', chatId)
70
70
 
71
71
  // 发送消息并获取流式响应
72
72
  const url = `https://anuneko.com/api/v1/msg/${chatId}/stream`
73
73
  const data = { contents: [message] }
74
74
 
75
- logger.info('发送消息...')
75
+ logInfo('发送消息...')
76
76
  const response = await fetch(url, {
77
77
  method: 'POST',
78
78
  headers,
@@ -95,7 +95,7 @@ export function apply(ctx: Context, config: Config) {
95
95
  if (done) break
96
96
 
97
97
  const chunkStr = decoder.decode(value, { stream: true })
98
- logger.info('收到数据块:', chunkStr.substring(0, 200))
98
+ logInfo('收到数据块:', chunkStr.substring(0, 200))
99
99
 
100
100
  const lines = chunkStr.split('\n')
101
101
 
@@ -104,7 +104,7 @@ export function apply(ctx: Context, config: Config) {
104
104
  continue
105
105
  }
106
106
 
107
- logger.info('处理行:', line.substring(0, 100))
107
+ logInfo('处理行:', line.substring(0, 100))
108
108
 
109
109
  if (!line.startsWith('data: ')) {
110
110
  logger.warn('非 data: 格式的行:', line)
@@ -116,28 +116,28 @@ export function apply(ctx: Context, config: Config) {
116
116
 
117
117
  try {
118
118
  const j = JSON.parse(rawJson)
119
- logger.info('解析的 JSON:', JSON.stringify(j))
119
+ logInfo('解析的 JSON:', JSON.stringify(j))
120
120
 
121
121
  if (j.msg_id) {
122
122
  currentMsgId = j.msg_id
123
- logger.info('更新 msg_id:', currentMsgId)
123
+ logInfo('更新 msg_id:', currentMsgId)
124
124
  }
125
125
 
126
126
  // 处理多分支内容
127
127
  if (j.c && Array.isArray(j.c)) {
128
- logger.info('处理多分支内容')
128
+ logInfo('处理多分支内容')
129
129
  for (const choice of j.c) {
130
130
  const idx = choice.c ?? 0
131
131
  if (idx === 0 && choice.v) {
132
132
  result += choice.v
133
- logger.info('添加内容:', choice.v)
133
+ logInfo('添加内容:', choice.v)
134
134
  }
135
135
  }
136
136
  }
137
137
  // 处理常规内容
138
138
  else if (j.v && typeof j.v === 'string') {
139
139
  result += j.v
140
- logger.info('添加常规内容:', j.v)
140
+ logInfo('添加常规内容:', j.v)
141
141
  }
142
142
  } catch (error) {
143
143
  logger.error('解析 JSON 失败:', rawJson, error)
@@ -145,8 +145,8 @@ export function apply(ctx: Context, config: Config) {
145
145
  }
146
146
  }
147
147
 
148
- logger.info('最终结果长度:', result.length)
149
- logger.info('最终结果内容:', result)
148
+ logInfo('最终结果长度:', result.length)
149
+ logInfo('最终结果内容:', result)
150
150
 
151
151
  // 自动选择分支
152
152
  if (currentMsgId) {
@@ -157,7 +157,7 @@ export function apply(ctx: Context, config: Config) {
157
157
  })
158
158
  }
159
159
 
160
- logger.info('收到完整响应')
160
+ logInfo('收到完整响应')
161
161
  return result || '❌ 未收到响应'
162
162
  } catch (error) {
163
163
  logger.error('请求失败:', error)