@@ -0,0 +1,41 @@
1+import { Context, stream } from "@mariozechner/pi-ai";
2+import { getApiKey } from "./oauth";
3+import type { CliOptions } from "./types";
4+
5+export async function streamHeadless(options: CliOptions) {
6+ const apiKey = await getApiKey(options);
7+ const context: Context = {
8+ // TODO: Centralize prompts
9+ systemPrompt:
10+ "You are friendly coding assistant, answer user questions and complete given tasks with accuracy.",
11+ messages: [
12+ { content: options.prompt ?? "", role: "user", timestamp: Date.now() },
13+ ],
14+ tools: [],
15+ };
16+
17+ const s = stream(options.model, context, { apiKey });
18+ for await (const ev of s) {
19+ switch (ev.type) {
20+ case "start":
21+ console.log("Starting headless mode");
22+ break;
23+ case "text_start":
24+ console.log("Answering...")
25+ break;
26+ case "thinking_start":
27+ console.log("Thinking... or trying to...")
28+ break;
29+ case "done":
30+ console.log("Done.")
31+ break;
32+ case "error":
33+ console.log(`Error ${ev.error}`)
34+ break;
35+ }
36+ }
37+
38+ const finalMessage = await s.result();
39+ context.messages.push(finalMessage)
40+ console.log(finalMessage.content)
41+}