Skip to content

Commit b5e0935

Browse files
committed
docs(twoslash): fix ChatLuna API samples
Align the Agent and preset examples with the current ChatLuna types so the docs build passes without unexpected Twoslash errors.
1 parent ddf3dc6 commit b5e0935

File tree

2 files changed

+40
-21
lines changed

2 files changed

+40
-21
lines changed

docs/development/call-core-services/agent.md

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ const agent = await ctx.chatluna.createAgent({
4848
```ts twoslash
4949
// @noImplicitAny: false
5050
// @strictNullChecks: false
51-
import { Context, Schema } from 'koishi'
51+
import { Context, Schema, type Session } from 'koishi'
5252

5353
const ctx = new Context()
54-
54+
const session = {} as Session
5555

5656
import type {} from "koishi-plugin-chatluna/services/chat";
5757

@@ -100,10 +100,10 @@ console.log(result.message);
100100
```ts twoslash
101101
// @noImplicitAny: false
102102
// @strictNullChecks: false
103-
import { Context, Schema } from 'koishi'
103+
import { Context, Schema, type Session } from 'koishi'
104104

105105
const ctx = new Context()
106-
106+
const session = {} as Session
107107

108108
import type {} from "koishi-plugin-chatluna/services/chat";
109109

@@ -147,10 +147,10 @@ console.log(result.output);
147147
```ts twoslash
148148
// @noImplicitAny: false
149149
// @strictNullChecks: false
150-
import { Context, Schema } from 'koishi'
150+
import { Context, Schema, type Session } from 'koishi'
151151

152152
const ctx = new Context()
153-
153+
const session = {} as Session
154154

155155
import type {} from "koishi-plugin-chatluna/services/chat";
156156

@@ -309,7 +309,6 @@ import { Context, Schema } from 'koishi'
309309

310310
const ctx = new Context()
311311

312-
313312
import type {} from "koishi-plugin-chatluna/services/chat";
314313
import {
315314
createTaskTool,
@@ -390,16 +389,19 @@ const main = await ctx.chatluna.createAgent({
390389
```ts twoslash
391390
// @noImplicitAny: false
392391
// @strictNullChecks: false
393-
import { Context, Schema } from 'koishi'
392+
import { Context, Schema, type Session } from 'koishi'
394393

395394
const ctx = new Context()
395+
const session = {} as Session
396+
const modelRef = await ctx.chatluna.createChatModel("openai/gpt-5-nano")
396397

397398

398399
import type {} from "koishi-plugin-chatluna/services/chat";
399400
import {
400401
createTaskTool,
401402
renderAvailableAgents,
402403
} from "koishi-plugin-chatluna/llm-core/agent";
404+
import type { ChatLunaToolRunnable } from "koishi-plugin-chatluna/llm-core/platform/types";
403405

404406
const planner = await ctx.chatluna.createAgent({
405407
name: "planner",
@@ -447,21 +449,23 @@ const taskRuntime = createTaskTool({
447449
});
448450

449451
// ---cut---
452+
const runConfig = {
453+
configurable: {
454+
session,
455+
conversationId: "conversation-id",
456+
source: "chatluna",
457+
model: modelRef.value,
458+
},
459+
} as ChatLunaToolRunnable;
460+
450461
const result = await taskRuntime.runTask(
451462
{
452463
action: "run",
453464
agent: "researcher",
454465
prompt: "搜索 Anthropic 最近发布的模型更新,并整理成中文摘要",
455466
background: true,
456467
},
457-
{
458-
configurable: {
459-
session,
460-
conversationId: "conversation-id",
461-
source: "chatluna",
462-
model: modelRef.value,
463-
},
464-
} as any,
468+
runConfig,
465469
);
466470

467471
console.log(result);
@@ -472,16 +476,18 @@ console.log(result);
472476
```ts twoslash
473477
// @noImplicitAny: false
474478
// @strictNullChecks: false
475-
import { Context, Schema } from 'koishi'
479+
import { Context, Schema, type Session } from 'koishi'
476480

477481
const ctx = new Context()
478-
482+
const session = {} as Session
483+
const modelRef = await ctx.chatluna.createChatModel("openai/gpt-5-nano")
479484

480485
import type {} from "koishi-plugin-chatluna/services/chat";
481486
import {
482487
createTaskTool,
483488
renderAvailableAgents,
484489
} from "koishi-plugin-chatluna/llm-core/agent";
490+
import type { ChatLunaToolRunnable } from "koishi-plugin-chatluna/llm-core/platform/types";
485491

486492
const planner = await ctx.chatluna.createAgent({
487493
name: "planner",
@@ -529,6 +535,15 @@ const taskRuntime = createTaskTool({
529535
});
530536

531537
// ---cut---
538+
const runConfig = {
539+
configurable: {
540+
session,
541+
conversationId: "conversation-id",
542+
source: "chatluna",
543+
model: modelRef.value,
544+
},
545+
} as ChatLunaToolRunnable;
546+
532547
await taskRuntime.runTask({ action: "list" }, runConfig);
533548
await taskRuntime.runTask({ action: "status", id: "task-id" }, runConfig);
534549
await taskRuntime.runTask(

docs/development/call-core-services/preset.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ const prompt = computed(() => {
107107
preset: presetRef,
108108
tokenCounter: (text) => model.getNumTokens(text),
109109
sendTokenLimit: model.getModelMaxContextSize(),
110-
promptRenderService: ctx.chatluna.promptRenderer
110+
promptRenderService: ctx.chatluna.promptRenderer,
111+
contextManager: ctx.chatluna.contextManager
111112
})
112113
})
113114

@@ -122,6 +123,7 @@ const chain = computed(() => prompt.value.pipe(modelRef.value))
122123
- `tokenCounter`: Token 计数函数,用于计算文本的 Token 数量
123124
- `sendTokenLimit`: 发送消息的 Token 限制
124125
- `promptRenderService`: 提示词渲染服务
126+
- `contextManager`: 上下文管理服务,用于组装历史消息与上下文注入
125127

126128
## 创建简单的对话链
127129

@@ -149,7 +151,8 @@ const prompt = computed(() => {
149151
preset: presetRef,
150152
tokenCounter: (text) => model.getNumTokens(text),
151153
sendTokenLimit: model.getModelMaxContextSize(),
152-
promptRenderService: ctx.chatluna.promptRenderer
154+
promptRenderService: ctx.chatluna.promptRenderer,
155+
contextManager: ctx.chatluna.contextManager
153156
})
154157
})
155158

@@ -214,7 +217,8 @@ const prompt = computed(() => {
214217
preset: presetRef,
215218
tokenCounter: (text) => model.getNumTokens(text),
216219
sendTokenLimit: model.getModelMaxContextSize(),
217-
promptRenderService: ctx.chatluna.promptRenderer
220+
promptRenderService: ctx.chatluna.promptRenderer,
221+
contextManager: ctx.chatluna.contextManager
218222
})
219223
})
220224

0 commit comments

Comments
 (0)