MCPcopy Create free account
hub / github.com/anomalyco/opencode / chat

Function chat

packages/opencode/src/cli/cmd/github.handler.ts:889–974  ·  view source on GitHub ↗
(message: string, files: PromptFiles = [])

Source from the content-addressed store, hash-verified

887 }
888
889 async function chat(message: string, files: PromptFiles = []) {
890 console.log("Sending message to opencode...")
891
892 return runLocalEffect(
893 Effect.gen(function* () {
894 const prompt = sessionPrompt
895 const result = yield* prompt.prompt({
896 sessionID: session.id,
897 messageID: MessageID.ascending(),
898 variant,
899 model: {
900 providerID,
901 modelID,
902 },
903 // agent is omitted - server will use default_agent from config or fall back to "build"
904 parts: [
905 {
906 id: PartID.ascending(),
907 type: "text",
908 text: message,
909 },
910 ...files.flatMap((f) => [
911 {
912 id: PartID.ascending(),
913 type: "file" as const,
914 mime: f.mime,
915 url: `data:${f.mime};base64,${f.content}`,
916 filename: f.filename,
917 source: {
918 type: "file" as const,
919 text: {
920 value: f.replacement,
921 start: f.start,
922 end: f.end,
923 },
924 path: f.filename,
925 },
926 },
927 ]),
928 ],
929 })
930
931 if (result.info.role === "assistant" && result.info.error) {
932 const err = result.info.error
933 console.error("Agent error:", err)
934 if (err.name === "ContextOverflowError") throw new Error(formatPromptTooLargeError(files))
935 const message = "message" in err.data ? err.data.message : ""
936 throw new Error(`${err.name}: ${message}`)
937 }
938
939 const text = extractResponseText(result.parts)
940 if (text) return text
941
942 console.log("Requesting summary from agent...")
943 const summary = yield* prompt.prompt({
944 sessionID: session.id,
945 messageID: MessageID.ascending(),
946 variant,

Callers 2

github.handler.tsFile · 0.70
summarizeFunction · 0.70

Calls 5

extractResponseTextFunction · 0.90
runLocalEffectFunction · 0.70
promptMethod · 0.65
logMethod · 0.45

Tested by

no test coverage detected