(text: string, files: PromptFiles = [])
| 607 | } |
| 608 | |
| 609 | async 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 | |
| 653 | async function configureGit(appToken: string) { |
| 654 | // Do not change git config when running locally |
no test coverage detected