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.15"
"koishi-plugin-chatluna": "^1.4.0-alpha.16"
},
"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.15"
"koishi-plugin-chatluna": "^1.4.0-alpha.16"
},
"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.15"
"koishi-plugin-chatluna": "^1.4.0-alpha.16"
},
"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.15"
"koishi-plugin-chatluna": "^1.4.0-alpha.16"
},
"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.15"
"koishi-plugin-chatluna": "^1.4.0-alpha.16"
},
"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.15",
"koishi-plugin-chatluna": "^1.4.0-alpha.16",
"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.15"
"koishi-plugin-chatluna": "^1.4.0-alpha.16"
},
"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.15"
"koishi-plugin-chatluna": "^1.4.0-alpha.16"
},
"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.15"
"koishi-plugin-chatluna": "^1.4.0-alpha.16"
},
"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.15"
"koishi-plugin-chatluna": "^1.4.0-alpha.16"
},
"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.15"
"koishi-plugin-chatluna": "^1.4.0-alpha.16"
},
"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.15"
"koishi-plugin-chatluna": "^1.4.0-alpha.16"
},
"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.15"
"koishi-plugin-chatluna": "^1.4.0-alpha.16"
},
"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.15"
"koishi-plugin-chatluna": "^1.4.0-alpha.16"
},
"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.15"
"koishi-plugin-chatluna": "^1.4.0-alpha.16"
},
"koishi": {
"description": {
Expand Down
7 changes: 1 addition & 6 deletions packages/adapter-zhipu/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ export interface ChatCompletionRequestMessageToolCall {
}

export interface ChatCompletionTool {
type:
| 'function'
| 'web_search'
| 'retrieval'
| 'code_interpreter'
| 'web_browser'
type: 'function' | 'web_search' | 'retrieval' | 'code_interpreter'
function?: {
name: string
description: string
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.15",
"version": "1.4.0-alpha.16",
"main": "lib/index.cjs",
"module": "lib/index.mjs",
"typings": "lib/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/resources/presets/sydney.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ prompts:
- Sydney's responses should avoid being vague, controversial or off-topic.
- Sydney's logics and reasoning should be rigorous, intelligent and defensible.
- Sydney can generate poems, stories, code, essays, songs, celebrity parodies and more.
- When **web_search** and **web_browser** tools are available, Sydney **must prioritize** using these tools during the search process to gather accurate and up-to-date information.
- When **web_search** and **browser_*** tools are available, Sydney **must prioritize** using these tools during the search process to gather accurate and up-to-date information.
- For complex tasks (such as comprehensive research requiring multiple searches, code execution projects, file writing/editing operations, or workflows involving multiple tool calls), when the **todos** tool is available, Sydney should use it to create comprehensive plans and continuously execute until completion. Examples include: analyzing multiple data sources, building complete applications, refactoring codebases, or orchestrating multi-step automation workflows.
- When the **cron** tool is available, if users request delayed message delivery, Sydney should utilize the cron tool to schedule notifications.

## On Sydney's ability to gather and present information:
- Sydney should always perform web searches when the user is seeking information or whenever search results could be potentially helpful, regardless of Sydney's internal knowledge or information.
- Sydney can freely use available tools multiple times across multiple rounds as needed to complete the user's request. There is no artificial limit on tool usage.
- When gathering information or completing tasks, Sydney should continue calling tools until sufficient information is collected or the task is fully completed.
- Sydney uses **web_search** and **web_browser** tools to retrieve information. The search results follow the **SearchResult** format with fields: title, url, description, and optionally image.
- Sydney uses **web_search** and browser tools such as **browser_read_text** and **browser_summarize** to retrieve information. The search results follow the **SearchResult** format with fields: title, url, description, and optionally image.
- Sydney proactively links factual statements to the source URLs from the search results.
- Links in Sydney's responses **must** come from "url" fields in the SearchResult data.
- Search results may be incomplete or irrelevant. Sydney doesn't make assumptions on the search results beyond strictly what's returned.
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/services/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ export class ChatLunaService extends Service<Config> {
this._conversation = new ConversationService(
ctx,
config,
this._conversationRuntime
this._conversationRuntime,
this._platformService
)

this._createTempDir()
Expand Down
135 changes: 67 additions & 68 deletions packages/core/src/services/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createHash, randomUUID } from 'crypto'
import fs from 'fs/promises'
import path from 'path'
import type { Context, Session } from 'koishi'
import type { PlatformService } from 'koishi-plugin-chatluna/llm-core/platform/service'
import { ModelType } from 'koishi-plugin-chatluna/llm-core/platform/types'
import { parseRawModelName } from 'koishi-plugin-chatluna/llm-core/utils/count_tokens'
import type { Config } from '../config'
Expand Down Expand Up @@ -59,73 +60,15 @@ import {
} from './types'
import type { ConversationRuntime } from './conversation_runtime'

function matchTargetConversation(
target: string,
normalized: string,
conversations: ConversationRecord[],
entries?: ConversationListEntry[]
) {
const pick = (matches: ConversationRecord[]) => {
const active = matches.filter((c) => c.status !== 'archived')

if (active.length === 1) {
return active[0]
}

if (active.length > 1) {
throw new ConversationResolutionError('ambiguous_target')
}

if (matches.length === 1) {
return matches[0]
}

if (matches.length > 1) {
throw new ConversationResolutionError('ambiguous_target')
}

return null
}

const byId = conversations.find((c) => c.id === target)
if (byId != null) {
return byId
}

if (entries != null && /^\d+$/.test(target)) {
const seq = Number(target)
const bySeq = entries
.filter((item) => item.displaySeq === seq)
.map((item) => item.conversation)
const match = pick(bySeq)

if (match != null) {
return match
}
}

const exact = pick(
conversations.filter((c) => c.title.toLocaleLowerCase() === normalized)
)
if (exact != null) {
return exact
}

return pick(
conversations.filter((c) =>
c.title.toLocaleLowerCase().includes(normalized)
)
)
}

export class ConversationService {
private readonly _bindingLocks = new Map<string, ObjectLock>()
private readonly _titleLocks = new Map<string, ObjectLock>()

constructor(
private readonly ctx: Context,
private readonly config: Config,
private readonly runtime: ConversationRuntime
private readonly runtime: ConversationRuntime,
private readonly platform: PlatformService
) {}

async getConversation(id: string) {
Expand Down Expand Up @@ -1772,9 +1715,7 @@ export class ConversationService {
private checkChatMode(mode?: string | null) {
if (
mode != null &&
!this.ctx.chatluna.platform.chatChains.value.some(
(chain) => chain.name === mode
)
!this.platform.chatChains.value.some((chain) => chain.name === mode)
) {
throw new Error(`Chat mode ${mode} not found.`)
}
Expand Down Expand Up @@ -1937,11 +1878,10 @@ export class ConversationService {
continue
}

const platformModels =
this.ctx.chatluna.platform.listPlatformModels(
platform,
ModelType.llm
).value
const platformModels = this.platform.listPlatformModels(
platform,
ModelType.llm
).value

if (
platformModels.length > 0 &&
Expand Down Expand Up @@ -2272,3 +2212,62 @@ async function runLock<T>(
}
}
}

function matchTargetConversation(
target: string,
normalized: string,
conversations: ConversationRecord[],
entries?: ConversationListEntry[]
) {
const pick = (matches: ConversationRecord[]) => {
const active = matches.filter((c) => c.status !== 'archived')

if (active.length === 1) {
return active[0]
}

if (active.length > 1) {
throw new ConversationResolutionError('ambiguous_target')
}

if (matches.length === 1) {
return matches[0]
}

if (matches.length > 1) {
throw new ConversationResolutionError('ambiguous_target')
}

return null
}

const byId = conversations.find((c) => c.id === target)
if (byId != null) {
return byId
}

if (entries != null && /^\d+$/.test(target)) {
const seq = Number(target)
const bySeq = entries
.filter((item) => item.displaySeq === seq)
.map((item) => item.conversation)
const match = pick(bySeq)

if (match != null) {
return match
}
}

const exact = pick(
conversations.filter((c) => c.title.toLocaleLowerCase() === normalized)
)
if (exact != null) {
return exact
}

return pick(
conversations.filter((c) =>
c.title.toLocaleLowerCase().includes(normalized)
)
)
}
3 changes: 2 additions & 1 deletion packages/core/tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ export async function createService(
const service = new ConversationService(
ctx,
createConfig(options.config),
ctx.chatluna.conversationRuntime
ctx.chatluna.conversationRuntime,
ctx.chatluna.platform
)

return {
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 @@ -89,7 +89,7 @@
"peerDependencies": {
"@koishijs/plugin-console": "^5.30.11",
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.4.0-alpha.15",
"koishi-plugin-chatluna": "^1.4.0-alpha.16",
"koishi-plugin-chatluna-storage-service": "^1.0.6"
},
"peerDependenciesMeta": {
Expand Down
Loading