opencode-miniterm 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test/test.ts ADDED
@@ -0,0 +1,115 @@
1
+ import { spawn } from "node:child_process";
2
+
3
+ const AUTH_USERNAME = process.env.OPENCODE_SERVER_USERNAME || "opencode";
4
+ const AUTH_PASSWORD = process.env.OPENCODE_SERVER_PASSWORD || "";
5
+
6
+ function getAuthHeaders() {
7
+ const headers: Record<string, string> = { "Content-Type": "application/json" };
8
+ if (AUTH_PASSWORD) {
9
+ const credentials = Buffer.from(`${AUTH_USERNAME}:${AUTH_PASSWORD}`).toString("base64");
10
+ headers["Authorization"] = `Basic ${credentials}`;
11
+ }
12
+ return headers;
13
+ }
14
+
15
+ async function startServer(): Promise<ReturnType<typeof spawn>> {
16
+ const server = spawn("opencode", ["serve"], {
17
+ stdio: "pipe",
18
+ shell: true,
19
+ cwd: process.cwd(),
20
+ });
21
+
22
+ server.stdout.on("data", (data) => console.log("[stdout]", data.toString()));
23
+ server.stderr.on("data", (data) => console.log("[stderr]", data.toString()));
24
+
25
+ console.log("Waiting for server to start...");
26
+ await new Promise((resolve) => setTimeout(resolve, 3000));
27
+
28
+ return server;
29
+ }
30
+
31
+ async function main(): Promise<void> {
32
+ const server = await startServer();
33
+
34
+ try {
35
+ console.log("Creating session...");
36
+ const auth = getAuthHeaders();
37
+ console.log("Auth headers:", {
38
+ ...auth,
39
+ Authorization: auth.Authorization?.substring(0, 20) + "...",
40
+ });
41
+
42
+ const sessionRes = await fetch("http://127.0.0.1:4096/session", {
43
+ method: "POST",
44
+ headers: auth,
45
+ body: JSON.stringify({}),
46
+ });
47
+
48
+ console.log("Session response status:", sessionRes.status);
49
+ const sessionText = await sessionRes.text();
50
+ console.log("Session response:", sessionText);
51
+
52
+ if (!sessionRes.ok) {
53
+ throw new Error("Failed to create session");
54
+ }
55
+
56
+ const session = JSON.parse(sessionText);
57
+ console.log("Session ID:", session.id);
58
+
59
+ console.log("Getting provider config...");
60
+ const providerRes = await fetch("http://127.0.0.1:4096/config/providers", {
61
+ headers: auth,
62
+ });
63
+ const providerText = await providerRes.text();
64
+ console.log("Provider config response status:", providerRes.status);
65
+ console.log("Provider config:", providerText);
66
+
67
+ console.log("Sending message with model object, 30 second timeout...");
68
+ const controller = new AbortController();
69
+ const timeout = setTimeout(() => controller.abort(), 30000);
70
+
71
+ try {
72
+ const requestBody = {
73
+ model: {
74
+ modelID: "big-pickle",
75
+ providerID: "opencode",
76
+ },
77
+ parts: [{ type: "text", text: "hi" }],
78
+ };
79
+ console.log("Request body:", JSON.stringify(requestBody));
80
+
81
+ const msgRes = await fetch(`http://127.0.0.1:4096/session/${session.id}/message`, {
82
+ method: "POST",
83
+ headers: auth,
84
+ body: JSON.stringify(requestBody),
85
+ signal: controller.signal,
86
+ });
87
+
88
+ clearTimeout(timeout);
89
+
90
+ console.log("Message response status:", msgRes.status);
91
+ const msgText = await msgRes.text();
92
+ console.log("Message response:", msgText);
93
+ } catch (error) {
94
+ clearTimeout(timeout);
95
+ if (error instanceof Error && error.name === "AbortError") {
96
+ console.error("Message send timed out after 30 seconds");
97
+ } else {
98
+ console.error(
99
+ "Message send error:",
100
+ error instanceof Error ? error.message : String(error),
101
+ );
102
+ }
103
+ }
104
+ } catch (error) {
105
+ console.error(
106
+ "Error:",
107
+ error instanceof Error ? `${error.message} ${error.stack || ""}` : String(error),
108
+ );
109
+ } finally {
110
+ server.kill();
111
+ process.exit(0);
112
+ }
113
+ }
114
+
115
+ main();
package/tsconfig.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Environment setup & latest features
4
+ "lib": ["ESNext"],
5
+ "target": "ESNext",
6
+ "module": "Preserve",
7
+ "moduleDetection": "force",
8
+ "jsx": "react-jsx",
9
+ "allowJs": true,
10
+
11
+ // Bundler mode
12
+ "moduleResolution": "bundler",
13
+ "allowImportingTsExtensions": true,
14
+ "verbatimModuleSyntax": true,
15
+ "noEmit": true,
16
+
17
+ // Best practices
18
+ "strict": true,
19
+ "skipLibCheck": true,
20
+ "noFallthroughCasesInSwitch": true,
21
+ "noUncheckedIndexedAccess": true,
22
+ "noImplicitOverride": true,
23
+
24
+ // Some stricter flags (disabled by default)
25
+ "noUnusedLocals": false,
26
+ "noUnusedParameters": false,
27
+ "noPropertyAccessFromIndexSignature": false
28
+ }
29
+ }