()
| 65 | } |
| 66 | |
| 67 | async onChatMessage() { |
| 68 | const workersai = createWorkersAI({ binding: this.env.AI }); |
| 69 | |
| 70 | const executor = new DynamicWorkerExecutor({ |
| 71 | loader: this.env.LOADER |
| 72 | }); |
| 73 | |
| 74 | const mcpTools = this.mcp.getAITools(); |
| 75 | const allTools = { ...this.tools, ...mcpTools }; |
| 76 | |
| 77 | const codemode = createCodeTool({ |
| 78 | tools: allTools, |
| 79 | executor |
| 80 | }); |
| 81 | |
| 82 | const result = streamText({ |
| 83 | model: workersai("@cf/moonshotai/kimi-k2.6", { |
| 84 | sessionAffinity: this.sessionAffinity |
| 85 | }), |
| 86 | system: |
| 87 | "You are a helpful project management assistant. " + |
| 88 | "You can create and manage projects, tasks, sprints, and comments using the codemode tool. " + |
| 89 | "When you need to perform operations, use the codemode tool to write JavaScript " + |
| 90 | "that calls the available functions on the `codemode` object.", |
| 91 | messages: pruneMessages({ |
| 92 | messages: await convertToModelMessages(this.messages), |
| 93 | toolCalls: "before-last-2-messages", |
| 94 | reasoning: "before-last-message" |
| 95 | }), |
| 96 | tools: { codemode }, |
| 97 | stopWhen: stepCountIs(10) |
| 98 | }); |
| 99 | |
| 100 | return result.toUIMessageStreamResponse(); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | export default { |
nothing calls this directly
no test coverage detected