@chatluna/v1-shared-adapter 1.0.10 → 1.0.12

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.cjs CHANGED
@@ -340,7 +340,7 @@ function convertMessageToMessageChunk(message) {
340
340
  const content = message.content ?? "";
341
341
  const reasoningContent = message.reasoning_content ?? "";
342
342
  const role = ((message.role?.length ?? 0) > 0 ? message.role : "assistant").toLowerCase();
343
- let additionalKwargs;
343
+ const additionalKwargs = {};
344
344
  if (reasoningContent.length > 0) {
345
345
  additionalKwargs.reasoning_content = reasoningContent;
346
346
  }
@@ -442,6 +442,7 @@ __name(convertDeltaToMessageChunk, "convertDeltaToMessageChunk");
442
442
  // src/requester.ts
443
443
  var import_messages2 = require("@langchain/core/messages");
444
444
  var import_string2 = require("koishi-plugin-chatluna/utils/string");
445
+ var import_logger = require("koishi-plugin-chatluna/utils/logger");
445
446
  async function buildChatCompletionParams(params, plugin, enableGoogleSearch, supportImageInput2) {
446
447
  const base = {
447
448
  model: params.model,
@@ -604,15 +605,16 @@ async function processResponse(requestContext, response) {
604
605
  __name(processResponse, "processResponse");
605
606
  async function* completionStream(requestContext, params, completionUrl = "chat/completions", enableGoogleSearch, supportImageInput2) {
606
607
  const { modelRequester } = requestContext;
608
+ const chatCompletionParams = await buildChatCompletionParams(
609
+ params,
610
+ requestContext.plugin,
611
+ enableGoogleSearch ?? false,
612
+ supportImageInput2 ?? true
613
+ );
607
614
  try {
608
615
  const response = await modelRequester.post(
609
616
  completionUrl,
610
- await buildChatCompletionParams(
611
- params,
612
- requestContext.plugin,
613
- enableGoogleSearch ?? false,
614
- supportImageInput2 ?? true
615
- ),
617
+ chatCompletionParams,
616
618
  {
617
619
  signal: params.signal
618
620
  }
@@ -620,6 +622,13 @@ async function* completionStream(requestContext, params, completionUrl = "chat/c
620
622
  const iterator = (0, import_sse.sseIterable)(response);
621
623
  yield* processStreamResponse(requestContext, iterator);
622
624
  } catch (e) {
625
+ if (requestContext.ctx.chatluna.config.isLog) {
626
+ await (0, import_logger.trackLogToLocal)(
627
+ "Request",
628
+ JSON.stringify(chatCompletionParams),
629
+ requestContext.ctx.logger("")
630
+ );
631
+ }
623
632
  if (e instanceof import_error.ChatLunaError) {
624
633
  throw e;
625
634
  } else {
@@ -647,6 +656,13 @@ async function completion(requestContext, params, completionUrl = "chat/completi
647
656
  );
648
657
  return await processResponse(requestContext, response);
649
658
  } catch (e) {
659
+ if (requestContext.ctx.chatluna.config.isLog) {
660
+ await (0, import_logger.trackLogToLocal)(
661
+ "Request",
662
+ JSON.stringify(chatCompletionParams),
663
+ requestContext.ctx.logger("")
664
+ );
665
+ }
650
666
  if (e instanceof import_error.ChatLunaError) {
651
667
  throw e;
652
668
  } else {
package/lib/index.mjs CHANGED
@@ -310,7 +310,7 @@ function convertMessageToMessageChunk(message) {
310
310
  const content = message.content ?? "";
311
311
  const reasoningContent = message.reasoning_content ?? "";
312
312
  const role = ((message.role?.length ?? 0) > 0 ? message.role : "assistant").toLowerCase();
313
- let additionalKwargs;
313
+ const additionalKwargs = {};
314
314
  if (reasoningContent.length > 0) {
315
315
  additionalKwargs.reasoning_content = reasoningContent;
316
316
  }
@@ -412,6 +412,7 @@ __name(convertDeltaToMessageChunk, "convertDeltaToMessageChunk");
412
412
  // src/requester.ts
413
413
  import { AIMessageChunk as AIMessageChunk2 } from "@langchain/core/messages";
414
414
  import { getMessageContent } from "koishi-plugin-chatluna/utils/string";
415
+ import { trackLogToLocal } from "koishi-plugin-chatluna/utils/logger";
415
416
  async function buildChatCompletionParams(params, plugin, enableGoogleSearch, supportImageInput2) {
416
417
  const base = {
417
418
  model: params.model,
@@ -574,15 +575,16 @@ async function processResponse(requestContext, response) {
574
575
  __name(processResponse, "processResponse");
575
576
  async function* completionStream(requestContext, params, completionUrl = "chat/completions", enableGoogleSearch, supportImageInput2) {
576
577
  const { modelRequester } = requestContext;
578
+ const chatCompletionParams = await buildChatCompletionParams(
579
+ params,
580
+ requestContext.plugin,
581
+ enableGoogleSearch ?? false,
582
+ supportImageInput2 ?? true
583
+ );
577
584
  try {
578
585
  const response = await modelRequester.post(
579
586
  completionUrl,
580
- await buildChatCompletionParams(
581
- params,
582
- requestContext.plugin,
583
- enableGoogleSearch ?? false,
584
- supportImageInput2 ?? true
585
- ),
587
+ chatCompletionParams,
586
588
  {
587
589
  signal: params.signal
588
590
  }
@@ -590,6 +592,13 @@ async function* completionStream(requestContext, params, completionUrl = "chat/c
590
592
  const iterator = sseIterable(response);
591
593
  yield* processStreamResponse(requestContext, iterator);
592
594
  } catch (e) {
595
+ if (requestContext.ctx.chatluna.config.isLog) {
596
+ await trackLogToLocal(
597
+ "Request",
598
+ JSON.stringify(chatCompletionParams),
599
+ requestContext.ctx.logger("")
600
+ );
601
+ }
593
602
  if (e instanceof ChatLunaError) {
594
603
  throw e;
595
604
  } else {
@@ -617,6 +626,13 @@ async function completion(requestContext, params, completionUrl = "chat/completi
617
626
  );
618
627
  return await processResponse(requestContext, response);
619
628
  } catch (e) {
629
+ if (requestContext.ctx.chatluna.config.isLog) {
630
+ await trackLogToLocal(
631
+ "Request",
632
+ JSON.stringify(chatCompletionParams),
633
+ requestContext.ctx.logger("")
634
+ );
635
+ }
620
636
  if (e instanceof ChatLunaError) {
621
637
  throw e;
622
638
  } else {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chatluna/v1-shared-adapter",
3
3
  "description": "chatluna shared adapter",
4
- "version": "1.0.10",
4
+ "version": "1.0.12",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.mjs",
7
7
  "typings": "lib/index.d.ts",
@@ -22,13 +22,13 @@
22
22
  "repository": {
23
23
  "type": "git",
24
24
  "url": "https://github.com/ChatLunaLab/chatluna.git",
25
- "directory": "packages/openai-like-adapter"
25
+ "directory": "packages/shared-adapter"
26
26
  },
27
27
  "license": "AGPL-3.0",
28
28
  "bugs": {
29
29
  "url": "https://github.com/ChatLunaLab/chatluna/issues"
30
30
  },
31
- "homepage": "https://github.com/ChatLunaLab/chatluna/tree/v1-dev/packages/openai-like-adapter#readme",
31
+ "homepage": "https://github.com/ChatLunaLab/chatluna/tree/v1-dev/packages/shared-adapter#readme",
32
32
  "scripts": {
33
33
  "build": "atsc -b"
34
34
  },
@@ -62,14 +62,14 @@
62
62
  "dependencies": {
63
63
  "@langchain/core": "0.3.62",
64
64
  "zod": "3.25.76",
65
- "zod-to-json-schema": "^3.24.5"
65
+ "zod-to-json-schema": "^3.24.6"
66
66
  },
67
67
  "devDependencies": {
68
68
  "atsc": "^2.1.0",
69
- "koishi": "^4.18.7"
69
+ "koishi": "^4.18.9"
70
70
  },
71
71
  "peerDependencies": {
72
- "koishi": "^4.18.7",
73
- "koishi-plugin-chatluna": "^1.3.0-alpha.44"
72
+ "koishi": "^4.18.9",
73
+ "koishi-plugin-chatluna": "^1.3.0-alpha.53"
74
74
  }
75
75
  }