|
|
@@ -51,6 +51,7 @@ import { $, fileURLToPath } from "bun"
|
|
|
import { ConfigMarkdown } from "../config/markdown"
|
|
|
import { SessionSummary } from "./summary"
|
|
|
import { Config } from "@/config/config"
|
|
|
+import { NamedError } from "@/util/error"
|
|
|
|
|
|
export namespace SessionPrompt {
|
|
|
const log = Log.create({ service: "session.prompt" })
|
|
|
@@ -735,17 +736,8 @@ export namespace SessionPrompt {
|
|
|
}
|
|
|
}
|
|
|
const args = { filePath: filepath, offset, limit }
|
|
|
- const result = await ReadTool.init().then((t) =>
|
|
|
- t.execute(args, {
|
|
|
- sessionID: input.sessionID,
|
|
|
- abort: new AbortController().signal,
|
|
|
- agent: input.agent!,
|
|
|
- messageID: info.id,
|
|
|
- extra: { bypassCwdCheck: true },
|
|
|
- metadata: async () => {},
|
|
|
- }),
|
|
|
- )
|
|
|
- return [
|
|
|
+
|
|
|
+ const pieces: MessageV2.Part[] = [
|
|
|
{
|
|
|
id: Identifier.ascending("part"),
|
|
|
messageID: info.id,
|
|
|
@@ -754,21 +746,55 @@ export namespace SessionPrompt {
|
|
|
synthetic: true,
|
|
|
text: `Called the Read tool with the following input: ${JSON.stringify(args)}`,
|
|
|
},
|
|
|
- {
|
|
|
- id: Identifier.ascending("part"),
|
|
|
- messageID: info.id,
|
|
|
- sessionID: input.sessionID,
|
|
|
- type: "text",
|
|
|
- synthetic: true,
|
|
|
- text: result.output,
|
|
|
- },
|
|
|
- {
|
|
|
- ...part,
|
|
|
- id: part.id ?? Identifier.ascending("part"),
|
|
|
- messageID: info.id,
|
|
|
- sessionID: input.sessionID,
|
|
|
- },
|
|
|
]
|
|
|
+
|
|
|
+ await ReadTool.init()
|
|
|
+ .then(async (t) => {
|
|
|
+ const result = await t.execute(args, {
|
|
|
+ sessionID: input.sessionID,
|
|
|
+ abort: new AbortController().signal,
|
|
|
+ agent: input.agent!,
|
|
|
+ messageID: info.id,
|
|
|
+ extra: { bypassCwdCheck: true },
|
|
|
+ metadata: async () => {},
|
|
|
+ })
|
|
|
+ pieces.push(
|
|
|
+ {
|
|
|
+ id: Identifier.ascending("part"),
|
|
|
+ messageID: info.id,
|
|
|
+ sessionID: input.sessionID,
|
|
|
+ type: "text",
|
|
|
+ synthetic: true,
|
|
|
+ text: result.output,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ ...part,
|
|
|
+ id: part.id ?? Identifier.ascending("part"),
|
|
|
+ messageID: info.id,
|
|
|
+ sessionID: input.sessionID,
|
|
|
+ },
|
|
|
+ )
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ log.error("failed to read file", { error })
|
|
|
+ const message = error instanceof Error ? error.message : error.toString()
|
|
|
+ Bus.publish(Session.Event.Error, {
|
|
|
+ sessionID: input.sessionID,
|
|
|
+ error: new NamedError.Unknown({
|
|
|
+ message,
|
|
|
+ }).toObject(),
|
|
|
+ })
|
|
|
+ pieces.push({
|
|
|
+ id: Identifier.ascending("part"),
|
|
|
+ messageID: info.id,
|
|
|
+ sessionID: input.sessionID,
|
|
|
+ type: "text",
|
|
|
+ synthetic: true,
|
|
|
+ text: `Read tool failed to read ${filepath} with the following error: ${message}`,
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ return pieces
|
|
|
}
|
|
|
|
|
|
if (part.mime === "application/x-directory") {
|