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

Function chat

github/index.ts:609–651  ·  view source on GitHub ↗
(text: string, files: PromptFiles = [])

Source from the content-addressed store, hash-verified

607}
608
609async function chat(text: string, files: PromptFiles = []) {
610 console.log("Sending message to opencode...")
611 const { providerID, modelID } = useEnvModel()
612 const agent = await resolveAgent()
613
614 const chat = await client.session.chat<true>({
615 path: session,
616 body: {
617 providerID,
618 modelID,
619 agent,
620 parts: [
621 {
622 type: "text",
623 text,
624 },
625 ...files.flatMap((f) => [
626 {
627 type: "file" as const,
628 mime: f.mime,
629 url: `data:${f.mime};base64,${f.content}`,
630 filename: f.filename,
631 source: {
632 type: "file" as const,
633 text: {
634 value: f.replacement,
635 start: f.start,
636 end: f.end,
637 },
638 path: f.filename,
639 },
640 },
641 ]),
642 ],
643 },
644 })
645
646 // @ts-ignore
647 const match = chat.data.parts.findLast((p) => p.type === "text")
648 if (!match) throw new Error("Failed to parse the text response")
649
650 return match.text
651}
652
653async function configureGit(appToken: string) {
654 // Do not change git config when running locally

Callers 2

index.tsFile · 0.70
summarizeFunction · 0.70

Calls 3

useEnvModelFunction · 0.85
resolveAgentFunction · 0.85
logMethod · 0.45

Tested by

no test coverage detected