koishi-plugin-chatluna 1.1.0 → 1.1.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.
- package/lib/chains/chain.d.ts +1 -1
- package/lib/chains/index.cjs +1 -5
- package/lib/chains/index.mjs +1 -5
- package/lib/index.cjs +6 -9
- package/lib/index.mjs +6 -9
- package/lib/llm-core/model/base.cjs +3 -3
- package/lib/llm-core/model/base.mjs +3 -3
- package/lib/llm-core/platform/model.cjs +5 -0
- package/lib/llm-core/platform/model.d.ts +3 -0
- package/lib/llm-core/platform/model.mjs +5 -0
- package/lib/services/chat.cjs +29 -4
- package/lib/services/chat.mjs +29 -4
- package/lib/services/message_transform.d.ts +3 -2
- package/package.json +1 -1
package/lib/chains/chain.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare class ChainMiddleware {
|
|
|
43
43
|
constructor(name: string, execute: ChainMiddlewareFunction, graph: ChatChainDependencyGraph);
|
|
44
44
|
before<T extends keyof ChainMiddlewareName>(name: T): this;
|
|
45
45
|
after<T extends keyof ChainMiddlewareName>(name: T): this;
|
|
46
|
-
run(session: Session, options: ChainMiddlewareContext): Promise<string | h[] | h[][]
|
|
46
|
+
run(session: Session, options: ChainMiddlewareContext): Promise<string | h[] | ChainMiddlewareRunStatus | h[][]>;
|
|
47
47
|
}
|
|
48
48
|
export interface ChainMiddlewareContext {
|
|
49
49
|
config: Config;
|
package/lib/chains/index.cjs
CHANGED
|
@@ -732,11 +732,7 @@ async function getTemplateConversationRoom(ctx, config) {
|
|
|
732
732
|
}
|
|
733
733
|
__name(getTemplateConversationRoom, "getTemplateConversationRoom");
|
|
734
734
|
async function getConversationRoomCount(ctx) {
|
|
735
|
-
const count = await ctx.database.
|
|
736
|
-
"chathub_room",
|
|
737
|
-
(row) => import_koishi2.$.max(row.roomId),
|
|
738
|
-
{}
|
|
739
|
-
);
|
|
735
|
+
const count = await ctx.database.select("chathub_room").execute((row) => import_koishi2.$.max(row.roomId));
|
|
740
736
|
return count;
|
|
741
737
|
}
|
|
742
738
|
__name(getConversationRoomCount, "getConversationRoomCount");
|
package/lib/chains/index.mjs
CHANGED
|
@@ -690,11 +690,7 @@ async function getTemplateConversationRoom(ctx, config) {
|
|
|
690
690
|
}
|
|
691
691
|
__name(getTemplateConversationRoom, "getTemplateConversationRoom");
|
|
692
692
|
async function getConversationRoomCount(ctx) {
|
|
693
|
-
const count = await ctx.database.
|
|
694
|
-
"chathub_room",
|
|
695
|
-
(row) => $.max(row.roomId),
|
|
696
|
-
{}
|
|
697
|
-
);
|
|
693
|
+
const count = await ctx.database.select("chathub_room").execute((row) => $.max(row.roomId));
|
|
698
694
|
return count;
|
|
699
695
|
}
|
|
700
696
|
__name(getConversationRoomCount, "getConversationRoomCount");
|
package/lib/index.cjs
CHANGED
|
@@ -1746,11 +1746,7 @@ async function getTemplateConversationRoom(ctx, config) {
|
|
|
1746
1746
|
}
|
|
1747
1747
|
__name(getTemplateConversationRoom, "getTemplateConversationRoom");
|
|
1748
1748
|
async function getConversationRoomCount(ctx) {
|
|
1749
|
-
const count = await ctx.database.
|
|
1750
|
-
"chathub_room",
|
|
1751
|
-
(row) => import_koishi4.$.max(row.roomId),
|
|
1752
|
-
{}
|
|
1753
|
-
);
|
|
1749
|
+
const count = await ctx.database.select("chathub_room").execute((row) => import_koishi4.$.max(row.roomId));
|
|
1754
1750
|
return count;
|
|
1755
1751
|
}
|
|
1756
1752
|
__name(getConversationRoomCount, "getConversationRoomCount");
|
|
@@ -3070,7 +3066,6 @@ function apply24(ctx, config, chain) {
|
|
|
3070
3066
|
} else {
|
|
3071
3067
|
await context.send(
|
|
3072
3068
|
session.text(".change_or_keep", [
|
|
3073
|
-
session.text(".action.select"),
|
|
3074
3069
|
session.text(".field.chat_mode"),
|
|
3075
3070
|
chatMode
|
|
3076
3071
|
])
|
|
@@ -3905,7 +3900,10 @@ function apply41(ctx, config, chain) {
|
|
|
3905
3900
|
try {
|
|
3906
3901
|
await readImage(url);
|
|
3907
3902
|
} catch (error) {
|
|
3908
|
-
logger.warn(
|
|
3903
|
+
logger.warn(
|
|
3904
|
+
`read image ${url} error, check your chat adapter`,
|
|
3905
|
+
error
|
|
3906
|
+
);
|
|
3909
3907
|
return;
|
|
3910
3908
|
}
|
|
3911
3909
|
}
|
|
@@ -5501,7 +5499,6 @@ function apply57(ctx, config, chain) {
|
|
|
5501
5499
|
} else {
|
|
5502
5500
|
await context.send(
|
|
5503
5501
|
session.text(".change_or_keep", [
|
|
5504
|
-
session.text(".action.select"),
|
|
5505
5502
|
session.text(".field.chat_mode"),
|
|
5506
5503
|
chatMode
|
|
5507
5504
|
])
|
|
@@ -5523,7 +5520,7 @@ function apply57(ctx, config, chain) {
|
|
|
5523
5520
|
break;
|
|
5524
5521
|
}
|
|
5525
5522
|
await context.send(
|
|
5526
|
-
session.text(".
|
|
5523
|
+
session.text(".invalid_chat_mode", [
|
|
5527
5524
|
visibility,
|
|
5528
5525
|
availableChatModes.join(", ")
|
|
5529
5526
|
])
|
package/lib/index.mjs
CHANGED
|
@@ -1737,11 +1737,7 @@ async function getTemplateConversationRoom(ctx, config) {
|
|
|
1737
1737
|
}
|
|
1738
1738
|
__name(getTemplateConversationRoom, "getTemplateConversationRoom");
|
|
1739
1739
|
async function getConversationRoomCount(ctx) {
|
|
1740
|
-
const count = await ctx.database.
|
|
1741
|
-
"chathub_room",
|
|
1742
|
-
(row) => $.max(row.roomId),
|
|
1743
|
-
{}
|
|
1744
|
-
);
|
|
1740
|
+
const count = await ctx.database.select("chathub_room").execute((row) => $.max(row.roomId));
|
|
1745
1741
|
return count;
|
|
1746
1742
|
}
|
|
1747
1743
|
__name(getConversationRoomCount, "getConversationRoomCount");
|
|
@@ -3064,7 +3060,6 @@ function apply24(ctx, config, chain) {
|
|
|
3064
3060
|
} else {
|
|
3065
3061
|
await context.send(
|
|
3066
3062
|
session.text(".change_or_keep", [
|
|
3067
|
-
session.text(".action.select"),
|
|
3068
3063
|
session.text(".field.chat_mode"),
|
|
3069
3064
|
chatMode
|
|
3070
3065
|
])
|
|
@@ -3899,7 +3894,10 @@ function apply41(ctx, config, chain) {
|
|
|
3899
3894
|
try {
|
|
3900
3895
|
await readImage(url);
|
|
3901
3896
|
} catch (error) {
|
|
3902
|
-
logger.warn(
|
|
3897
|
+
logger.warn(
|
|
3898
|
+
`read image ${url} error, check your chat adapter`,
|
|
3899
|
+
error
|
|
3900
|
+
);
|
|
3903
3901
|
return;
|
|
3904
3902
|
}
|
|
3905
3903
|
}
|
|
@@ -5507,7 +5505,6 @@ function apply57(ctx, config, chain) {
|
|
|
5507
5505
|
} else {
|
|
5508
5506
|
await context.send(
|
|
5509
5507
|
session.text(".change_or_keep", [
|
|
5510
|
-
session.text(".action.select"),
|
|
5511
5508
|
session.text(".field.chat_mode"),
|
|
5512
5509
|
chatMode
|
|
5513
5510
|
])
|
|
@@ -5529,7 +5526,7 @@ function apply57(ctx, config, chain) {
|
|
|
5529
5526
|
break;
|
|
5530
5527
|
}
|
|
5531
5528
|
await context.send(
|
|
5532
|
-
session.text(".
|
|
5529
|
+
session.text(".invalid_chat_mode", [
|
|
5533
5530
|
visibility,
|
|
5534
5531
|
availableChatModes.join(", ")
|
|
5535
5532
|
])
|
|
@@ -65,15 +65,15 @@ var ChatLunaSaveableVectorStore = class extends import_vectorstores.VectorStore
|
|
|
65
65
|
}
|
|
66
66
|
similaritySearchVectorWithScore(...args) {
|
|
67
67
|
this.checkActive();
|
|
68
|
+
if (args[0].length === 0) {
|
|
69
|
+
throw new Error("Embedding dismension is 0");
|
|
70
|
+
}
|
|
68
71
|
if (this.similaritySearchVectorWithScoreFunction) {
|
|
69
72
|
return this.similaritySearchVectorWithScoreFunction(
|
|
70
73
|
this._store,
|
|
71
74
|
...args
|
|
72
75
|
);
|
|
73
76
|
}
|
|
74
|
-
if (args[0].length === 0) {
|
|
75
|
-
throw new Error("Embedding dismension is 0");
|
|
76
|
-
}
|
|
77
77
|
return this._store.similaritySearchVectorWithScore(
|
|
78
78
|
args[0],
|
|
79
79
|
args[1],
|
|
@@ -44,15 +44,15 @@ var ChatLunaSaveableVectorStore = class extends VectorStore {
|
|
|
44
44
|
}
|
|
45
45
|
similaritySearchVectorWithScore(...args) {
|
|
46
46
|
this.checkActive();
|
|
47
|
+
if (args[0].length === 0) {
|
|
48
|
+
throw new Error("Embedding dismension is 0");
|
|
49
|
+
}
|
|
47
50
|
if (this.similaritySearchVectorWithScoreFunction) {
|
|
48
51
|
return this.similaritySearchVectorWithScoreFunction(
|
|
49
52
|
this._store,
|
|
50
53
|
...args
|
|
51
54
|
);
|
|
52
55
|
}
|
|
53
|
-
if (args[0].length === 0) {
|
|
54
|
-
throw new Error("Embedding dismension is 0");
|
|
55
|
-
}
|
|
56
56
|
return this._store.similaritySearchVectorWithScore(
|
|
57
57
|
args[0],
|
|
58
58
|
args[1],
|
|
@@ -175,6 +175,7 @@ var ChatLunaChatModel = class extends import_chat_models.BaseChatModel {
|
|
|
175
175
|
this._modelName = _options.model ?? _options.modelInfo.name;
|
|
176
176
|
this._maxModelContextSize = _options.modelMaxContextSize;
|
|
177
177
|
this._modelInfo = _options.modelInfo;
|
|
178
|
+
this._isThinkModel = _options.isThinkModel ?? false;
|
|
178
179
|
}
|
|
179
180
|
static {
|
|
180
181
|
__name(this, "ChatLunaChatModel");
|
|
@@ -185,6 +186,7 @@ var ChatLunaChatModel = class extends import_chat_models.BaseChatModel {
|
|
|
185
186
|
_modelName;
|
|
186
187
|
_maxModelContextSize;
|
|
187
188
|
_modelInfo;
|
|
189
|
+
_isThinkModel;
|
|
188
190
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
189
191
|
lc_serializable = false;
|
|
190
192
|
get callKeys() {
|
|
@@ -511,6 +513,9 @@ var ChatLunaChatModel = class extends import_chat_models.BaseChatModel {
|
|
|
511
513
|
get modelInfo() {
|
|
512
514
|
return this._modelInfo;
|
|
513
515
|
}
|
|
516
|
+
get isThinkModel() {
|
|
517
|
+
return this._isThinkModel;
|
|
518
|
+
}
|
|
514
519
|
_modelType() {
|
|
515
520
|
return "base_chat_model";
|
|
516
521
|
}
|
|
@@ -43,6 +43,7 @@ export interface ChatLunaModelInput extends ChatLunaModelCallOptions {
|
|
|
43
43
|
requester: ModelRequester;
|
|
44
44
|
maxConcurrency?: number;
|
|
45
45
|
maxRetries?: number;
|
|
46
|
+
isThinkModel?: boolean;
|
|
46
47
|
}
|
|
47
48
|
export declare class ChatLunaChatModel extends BaseChatModel<ChatLunaModelCallOptions> {
|
|
48
49
|
private _options;
|
|
@@ -51,6 +52,7 @@ export declare class ChatLunaChatModel extends BaseChatModel<ChatLunaModelCallOp
|
|
|
51
52
|
private _modelName;
|
|
52
53
|
private _maxModelContextSize;
|
|
53
54
|
private _modelInfo;
|
|
55
|
+
private _isThinkModel;
|
|
54
56
|
lc_serializable: boolean;
|
|
55
57
|
constructor(_options: ChatLunaModelInput);
|
|
56
58
|
get callKeys(): (keyof ChatLunaModelCallOptions)[];
|
|
@@ -78,6 +80,7 @@ export declare class ChatLunaChatModel extends BaseChatModel<ChatLunaModelCallOp
|
|
|
78
80
|
_llmType(): string;
|
|
79
81
|
get modelName(): string;
|
|
80
82
|
get modelInfo(): ModelInfo;
|
|
83
|
+
get isThinkModel(): boolean;
|
|
81
84
|
_modelType(): string;
|
|
82
85
|
/** @ignore */
|
|
83
86
|
_combineLLMOutput(...llmOutputs: any[]): any;
|
|
@@ -157,6 +157,7 @@ var ChatLunaChatModel = class extends BaseChatModel {
|
|
|
157
157
|
this._modelName = _options.model ?? _options.modelInfo.name;
|
|
158
158
|
this._maxModelContextSize = _options.modelMaxContextSize;
|
|
159
159
|
this._modelInfo = _options.modelInfo;
|
|
160
|
+
this._isThinkModel = _options.isThinkModel ?? false;
|
|
160
161
|
}
|
|
161
162
|
static {
|
|
162
163
|
__name(this, "ChatLunaChatModel");
|
|
@@ -167,6 +168,7 @@ var ChatLunaChatModel = class extends BaseChatModel {
|
|
|
167
168
|
_modelName;
|
|
168
169
|
_maxModelContextSize;
|
|
169
170
|
_modelInfo;
|
|
171
|
+
_isThinkModel;
|
|
170
172
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
171
173
|
lc_serializable = false;
|
|
172
174
|
get callKeys() {
|
|
@@ -493,6 +495,9 @@ var ChatLunaChatModel = class extends BaseChatModel {
|
|
|
493
495
|
get modelInfo() {
|
|
494
496
|
return this._modelInfo;
|
|
495
497
|
}
|
|
498
|
+
get isThinkModel() {
|
|
499
|
+
return this._isThinkModel;
|
|
500
|
+
}
|
|
496
501
|
_modelType() {
|
|
497
502
|
return "base_chat_model";
|
|
498
503
|
}
|
package/lib/services/chat.cjs
CHANGED
|
@@ -692,17 +692,24 @@ var MessageTransformer = class {
|
|
|
692
692
|
async transform(session, elements, message = {
|
|
693
693
|
content: "",
|
|
694
694
|
additional_kwargs: {}
|
|
695
|
-
}, quote = false) {
|
|
695
|
+
}, quote = false, model) {
|
|
696
696
|
for (const element of elements) {
|
|
697
697
|
const transformFunction = this._transformFunctions[element.type];
|
|
698
698
|
if (transformFunction != null) {
|
|
699
699
|
const result = await transformFunction(
|
|
700
700
|
session,
|
|
701
701
|
element,
|
|
702
|
-
message
|
|
702
|
+
message,
|
|
703
|
+
model
|
|
703
704
|
);
|
|
704
705
|
if (result === false && element.children) {
|
|
705
|
-
await this.transform(
|
|
706
|
+
await this.transform(
|
|
707
|
+
session,
|
|
708
|
+
element.children,
|
|
709
|
+
message,
|
|
710
|
+
false,
|
|
711
|
+
model
|
|
712
|
+
);
|
|
706
713
|
}
|
|
707
714
|
}
|
|
708
715
|
}
|
|
@@ -714,7 +721,8 @@ var MessageTransformer = class {
|
|
|
714
721
|
content: "",
|
|
715
722
|
additional_kwargs: {}
|
|
716
723
|
},
|
|
717
|
-
true
|
|
724
|
+
true,
|
|
725
|
+
model
|
|
718
726
|
);
|
|
719
727
|
if (quoteMessage.content.length > 0 && quoteMessage.content !== "[image]") {
|
|
720
728
|
message.additional_kwargs["raw_content"] = message.content;
|
|
@@ -749,6 +757,23 @@ Please consider this quote when generating your response. User's message: ${mess
|
|
|
749
757
|
delete this._transformFunctions[type];
|
|
750
758
|
};
|
|
751
759
|
}
|
|
760
|
+
replace(type, transformFunction) {
|
|
761
|
+
if (type === "text") {
|
|
762
|
+
throw new import_error2.ChatLunaError(
|
|
763
|
+
import_error2.ChatLunaErrorCode.UNKNOWN_ERROR,
|
|
764
|
+
new Error("text transform function already exists")
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
if (this._transformFunctions[type] == null) {
|
|
768
|
+
import_koishi_plugin_chatluna.logger?.warn(
|
|
769
|
+
`transform function for ${type} not exists. Check your installed plugins.`
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
this._transformFunctions[type] = transformFunction;
|
|
773
|
+
return () => {
|
|
774
|
+
delete this._transformFunctions[type];
|
|
775
|
+
};
|
|
776
|
+
}
|
|
752
777
|
};
|
|
753
778
|
|
|
754
779
|
// src/services/chat.ts
|
package/lib/services/chat.mjs
CHANGED
|
@@ -681,17 +681,24 @@ var MessageTransformer = class {
|
|
|
681
681
|
async transform(session, elements, message = {
|
|
682
682
|
content: "",
|
|
683
683
|
additional_kwargs: {}
|
|
684
|
-
}, quote = false) {
|
|
684
|
+
}, quote = false, model) {
|
|
685
685
|
for (const element of elements) {
|
|
686
686
|
const transformFunction = this._transformFunctions[element.type];
|
|
687
687
|
if (transformFunction != null) {
|
|
688
688
|
const result = await transformFunction(
|
|
689
689
|
session,
|
|
690
690
|
element,
|
|
691
|
-
message
|
|
691
|
+
message,
|
|
692
|
+
model
|
|
692
693
|
);
|
|
693
694
|
if (result === false && element.children) {
|
|
694
|
-
await this.transform(
|
|
695
|
+
await this.transform(
|
|
696
|
+
session,
|
|
697
|
+
element.children,
|
|
698
|
+
message,
|
|
699
|
+
false,
|
|
700
|
+
model
|
|
701
|
+
);
|
|
695
702
|
}
|
|
696
703
|
}
|
|
697
704
|
}
|
|
@@ -703,7 +710,8 @@ var MessageTransformer = class {
|
|
|
703
710
|
content: "",
|
|
704
711
|
additional_kwargs: {}
|
|
705
712
|
},
|
|
706
|
-
true
|
|
713
|
+
true,
|
|
714
|
+
model
|
|
707
715
|
);
|
|
708
716
|
if (quoteMessage.content.length > 0 && quoteMessage.content !== "[image]") {
|
|
709
717
|
message.additional_kwargs["raw_content"] = message.content;
|
|
@@ -738,6 +746,23 @@ Please consider this quote when generating your response. User's message: ${mess
|
|
|
738
746
|
delete this._transformFunctions[type];
|
|
739
747
|
};
|
|
740
748
|
}
|
|
749
|
+
replace(type, transformFunction) {
|
|
750
|
+
if (type === "text") {
|
|
751
|
+
throw new ChatLunaError2(
|
|
752
|
+
ChatLunaErrorCode2.UNKNOWN_ERROR,
|
|
753
|
+
new Error("text transform function already exists")
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
if (this._transformFunctions[type] == null) {
|
|
757
|
+
logger2?.warn(
|
|
758
|
+
`transform function for ${type} not exists. Check your installed plugins.`
|
|
759
|
+
);
|
|
760
|
+
}
|
|
761
|
+
this._transformFunctions[type] = transformFunction;
|
|
762
|
+
return () => {
|
|
763
|
+
delete this._transformFunctions[type];
|
|
764
|
+
};
|
|
765
|
+
}
|
|
741
766
|
};
|
|
742
767
|
|
|
743
768
|
// src/services/chat.ts
|
|
@@ -5,7 +5,8 @@ export declare class MessageTransformer {
|
|
|
5
5
|
private _config;
|
|
6
6
|
private _transformFunctions;
|
|
7
7
|
constructor(_config: Config);
|
|
8
|
-
transform(session: Session, elements: h[], message?: Message, quote?: boolean): Promise<Message>;
|
|
8
|
+
transform(session: Session, elements: h[], message?: Message, quote?: boolean, model?: string): Promise<Message>;
|
|
9
9
|
intercept(type: string, transformFunction: MessageTransformFunction): () => void;
|
|
10
|
+
replace(type: string, transformFunction: MessageTransformFunction): () => void;
|
|
10
11
|
}
|
|
11
|
-
export type MessageTransformFunction = (session: Session, element: h, message: Message) => Promise<boolean | void>;
|
|
12
|
+
export type MessageTransformFunction = (session: Session, element: h, message: Message, model?: string) => Promise<boolean | void>;
|