fix(codemode): return promises from combinators (#35782)
This commit is contained in:
parent
a6449cb45c
commit
39cceeb143
14 changed files with 1794 additions and 479 deletions
|
|
@ -169,9 +169,12 @@ function formatResult(result: CodeMode.Result) {
|
|||
: [result.error.message, ...(result.error.suggestions ?? []).filter((hint) => !result.error.message.includes(hint))]
|
||||
.join("\n")
|
||||
.trim()
|
||||
if (!result.logs || result.logs.length === 0) return output
|
||||
const logs = `Logs:\n${result.logs.join("\n")}`
|
||||
return output === "" ? logs : `${output}\n\n${logs}`
|
||||
const warnings =
|
||||
result.ok && result.warnings && result.warnings.length > 0
|
||||
? `Warnings:\n${result.warnings.map((item) => `- [${item.kind}] ${item.message}`).join("\n")}`
|
||||
: undefined
|
||||
const logs = result.logs && result.logs.length > 0 ? `Logs:\n${result.logs.join("\n")}` : undefined
|
||||
return [output, warnings, logs].filter((part) => part !== undefined && part !== "").join("\n\n")
|
||||
}
|
||||
|
||||
function formatValue(value: CodeMode.DataValue) {
|
||||
|
|
|
|||
47
packages/core/test/tool-execute.test.ts
Normal file
47
packages/core/test/tool-execute.test.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import { expect, test } from "bun:test"
|
||||
import { ExecuteTool } from "@opencode-ai/core/tool/execute"
|
||||
import { Tool } from "@opencode-ai/core/tool/tool"
|
||||
import { Agent } from "@opencode-ai/schema/agent"
|
||||
import { Session } from "@opencode-ai/schema/session"
|
||||
import { SessionMessage } from "@opencode-ai/schema/session-message"
|
||||
import { Effect, Schema } from "effect"
|
||||
|
||||
test("execute preserves successful results with visible unhandled rejections", async () => {
|
||||
const child = Tool.make({
|
||||
description: "Always fail",
|
||||
input: Schema.Struct({}),
|
||||
output: Schema.String,
|
||||
execute: () => Effect.fail(new Tool.Failure({ message: "Lookup refused" })),
|
||||
})
|
||||
const execute = ExecuteTool.create(new Map([["fail", { tool: child, name: "fail" }]]))
|
||||
const result = await Effect.runPromise(
|
||||
Tool.settle(
|
||||
execute,
|
||||
{
|
||||
type: "tool-call",
|
||||
id: "call_execute",
|
||||
name: "execute",
|
||||
input: { code: `tools.fail({}); return "done"` },
|
||||
},
|
||||
{
|
||||
sessionID: Session.ID.make("ses_execute"),
|
||||
agent: Agent.ID.make("build"),
|
||||
assistantMessageID: SessionMessage.ID.make("msg_execute"),
|
||||
toolCallID: "call_execute",
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
expect(result.structured).toEqual({ toolCalls: [{ tool: "fail", status: "error" }] })
|
||||
expect(result.content).toEqual([
|
||||
{
|
||||
type: "text",
|
||||
text: [
|
||||
"done",
|
||||
"",
|
||||
"Warnings:",
|
||||
"- [ToolFailure] Unhandled rejection from an un-awaited promise: Lookup refused",
|
||||
].join("\n"),
|
||||
},
|
||||
])
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue