Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/adapter-azure-openai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"resolutions": {
"@langchain/core": "^0.3.80",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-claude/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"resolutions": {
"@langchain/core": "^0.3.80",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-deepseek/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"koishi": {
"category": "ai",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-dify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-doubao/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-gemini/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40",
"koishi-plugin-chatluna": "^1.4.0-alpha.41",
"koishi-plugin-chatluna-storage-service": "^1.0.6"
},
"peerDependenciesMeta": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-hunyuan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-ollama/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"resolutions": {
"@langchain/core": "^0.3.80",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-openai-like/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-openai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-qwen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-rwkv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-spark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-wenxin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-zhipu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-plugin-chatluna",
"description": "chatluna for koishi",
"version": "1.4.0-alpha.40",
"version": "1.4.0-alpha.41",
"main": "lib/index.cjs",
"module": "lib/index.mjs",
"typings": "lib/index.d.ts",
Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/render/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,14 @@ export abstract class BufferedRenderStreamSession implements RenderStreamSession

const result: h[] = []
for (const part of parts) {
result.push(...(await this.renderText(part)))
const elements = await this.renderText(part)
result.push(
...(this.options.split && this.options.split !== 'none'
? elements.map((el) =>
el.type === 'message' ? el : h('message', el)
)
: elements)
)
Comment on lines +111 to +117

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

When split mode is enabled, mapping each individual element to a message element causes formatting elements (such as bold text, links, or images) within a single sentence/paragraph to be split into separate messages. This results in broken rendering and multiple fragmented messages in the chat client.

Instead, the entire array of elements for a single part should be wrapped in a single message element (unless it already contains message elements).

            if (elements.length > 0) {
                result.push(
                    ...(this.options.split && this.options.split !== 'none'
                        ? elements.some((el) => el.type === 'message')
                            ? elements
                            : [h('message', ...elements)]
                        : elements)
                )
            }

}
return result.length > 0 ? result : null
}
Expand Down
14 changes: 12 additions & 2 deletions packages/core/src/render/koishi-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ class KoishiElementStreamSession implements RenderStreamSession {
return transformAndEscape([h.text(this.text + '●')])
}

const elements = this.splitter.writeText(text)
let elements = this.splitter.writeText(text)
if (this.options.split && this.options.split !== 'none') {
elements = elements.map((el) =>
el.type === 'message' ? el : h('message', el)
)
}
Comment on lines +77 to +82

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

When split mode is enabled, mapping each individual element to a message element causes elements that are part of the same text block to be split into separate messages. Wrapping the entire array of elements in a single message element (unless it already contains message elements) preserves the integrity of the message structure.

Suggested change
let elements = this.splitter.writeText(text)
if (this.options.split && this.options.split !== 'none') {
elements = elements.map((el) =>
el.type === 'message' ? el : h('message', el)
)
}
let elements = this.splitter.writeText(text)
if (this.options.split && this.options.split !== 'none' && elements.length > 0) {
elements = elements.some((el) => el.type === 'message')
? elements
: [h('message', ...elements)]
}

return elements.length > 0 ? elements : null
}

Expand All @@ -84,7 +89,12 @@ class KoishiElementStreamSession implements RenderStreamSession {
return transformAndEscape([h.text(this.text)])
}

const elements = this.splitter.flush()
let elements = this.splitter.flush()
if (this.options.split && this.options.split !== 'none') {
elements = elements.map((el) =>
el.type === 'message' ? el : h('message', el)
)
}
Comment on lines +92 to +97

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

When split mode is enabled, mapping each individual element to a message element causes elements that are part of the same text block to be split into separate messages. Wrapping the entire array of elements in a single message element (unless it already contains message elements) preserves the integrity of the message structure.

Suggested change
let elements = this.splitter.flush()
if (this.options.split && this.options.split !== 'none') {
elements = elements.map((el) =>
el.type === 'message' ? el : h('message', el)
)
}
let elements = this.splitter.flush()
if (this.options.split && this.options.split !== 'none' && elements.length > 0) {
elements = elements.some((el) => el.type === 'message')
? elements
: [h('message', ...elements)]
}

return elements.length > 0 ? elements : null
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/render/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class ReplyStream {
return await this.queue.edit(processed)
}

await this.context.send(processed)
await this.context.send([processed])
}

private async censor(elements: h[]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"peerDependencies": {
"@koishijs/plugin-console": "^5.30.11",
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40",
"koishi-plugin-chatluna": "^1.4.0-alpha.41",
"koishi-plugin-chatluna-storage-service": "^1.0.6"
},
"peerDependenciesMeta": {
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-long-memory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"resolutions": {
"@langchain/core": "^0.3.80",
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40",
"koishi-plugin-chatluna": "^1.4.0-alpha.41",
"koishi-plugin-chatluna-agent": "^1.0.41",
"koishi-plugin-chatluna-storage-service": "^1.0.6"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-usage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"peerDependencies": {
"@koishijs/plugin-console": "^5.30.11",
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40",
"koishi-plugin-chatluna": "^1.4.0-alpha.41",
"koishi-plugin-puppeteer": "^3.9.0"
},
"peerDependenciesMeta": {
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-variable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"resolutions": {
"@langchain/core": "^0.3.80",
Expand Down
2 changes: 1 addition & 1 deletion packages/renderer-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/service-embeddings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/service-multimodal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40",
"koishi-plugin-chatluna": "^1.4.0-alpha.41",
"koishi-plugin-ffmpeg-path": "^2.0.0"
},
"peerDependenciesMeta": {
Expand Down
2 changes: 1 addition & 1 deletion packages/service-search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40",
"koishi-plugin-chatluna": "^1.4.0-alpha.41",
"koishi-plugin-chatluna-agent": "^1.0.41"
},
"peerDependenciesMeta": {
Expand Down
2 changes: 1 addition & 1 deletion packages/service-vector-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@zilliz/milvus2-sdk-node": "^2.6.2",
"faiss-node": "^0.5.1",
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
},
"peerDependenciesMeta": {
"@zilliz/milvus2-sdk-node": {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.40"
"koishi-plugin-chatluna": "^1.4.0-alpha.41"
}
}
Loading