@usepipa/pipa 0.4.2 → 0.4.3
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/README.md +1 -1
- package/package.json +1 -1
- package/src/opencode.mjs +21 -11
package/README.md
CHANGED
|
@@ -70,7 +70,7 @@ By default Pipa answers anyone who mentions it in a channel it can see. In a sha
|
|
|
70
70
|
|
|
71
71
|
A mention is only handled when the channel ID is in `allowedSlackChannelIds` **and** the author's user ID is in `allowedSlackUserIds`. Leave a list empty to allow any channel or any user. You can also set them non-interactively during setup with `PIPA_ALLOWED_CHANNEL_IDS` and `PIPA_ALLOWED_USER_IDS` (comma-separated).
|
|
72
72
|
|
|
73
|
-
To use an existing OpenCode server instead, set its URL before starting Pipa. Pipa
|
|
73
|
+
To use an existing OpenCode server instead, set its URL before starting Pipa. Pipa checks that the server can serve the configured workspace but does not start or stop it. If the server uses authentication, also set `OPENCODE_SERVER_USERNAME` and `OPENCODE_SERVER_PASSWORD`:
|
|
74
74
|
|
|
75
75
|
```sh
|
|
76
76
|
export PIPA_OPENCODE_ATTACH_URL=http://localhost:5555
|
package/package.json
CHANGED
package/src/opencode.mjs
CHANGED
|
@@ -38,7 +38,7 @@ export async function startSocketOpenCodeServer(config, options = {}) {
|
|
|
38
38
|
|
|
39
39
|
if (attachUrl) {
|
|
40
40
|
const baseUrl = normalizeBaseUrl(attachUrl);
|
|
41
|
-
await
|
|
41
|
+
await waitForWorkspace(baseUrl, config.workingDirectory, fetchImpl, headers, startupTimeoutMs);
|
|
42
42
|
return externalServer(baseUrl);
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -65,7 +65,7 @@ export async function startSocketOpenCodeServer(config, options = {}) {
|
|
|
65
65
|
child.stdout?.resume();
|
|
66
66
|
child.stderr?.resume();
|
|
67
67
|
await Promise.race([
|
|
68
|
-
|
|
68
|
+
waitForWorkspace(baseUrl, config.workingDirectory, fetchImpl, headers, startupTimeoutMs),
|
|
69
69
|
exit.then((code) => { throw new Error(`OpenCode server exited before startup with code ${code}.`); }),
|
|
70
70
|
]);
|
|
71
71
|
return ownedServer(baseUrl, child, exit, platform);
|
|
@@ -528,21 +528,23 @@ function externalServer(baseUrl) {
|
|
|
528
528
|
};
|
|
529
529
|
}
|
|
530
530
|
|
|
531
|
-
async function
|
|
531
|
+
async function waitForWorkspace(baseUrl, workingDirectory, fetchImpl, headers, timeoutMs) {
|
|
532
532
|
const deadline = Date.now() + timeoutMs;
|
|
533
533
|
while (Date.now() < deadline) {
|
|
534
534
|
try {
|
|
535
|
-
const
|
|
535
|
+
const status = await fetchImpl(serverUrl(baseUrl, "/session/status", workingDirectory), {
|
|
536
536
|
headers,
|
|
537
537
|
signal: AbortSignal.timeout(Math.min(5_000, Math.max(1, deadline - Date.now()))),
|
|
538
538
|
});
|
|
539
|
-
|
|
539
|
+
const sessions = status.ok ? await status.json() : null;
|
|
540
|
+
if (sessions && typeof sessions === "object" && !Array.isArray(sessions)
|
|
541
|
+
&& Object.values(sessions).every((session) => session && typeof session === "object" && typeof session.type === "string")) return;
|
|
540
542
|
} catch {
|
|
541
|
-
//
|
|
543
|
+
// OpenCode can accept its socket before the configured workspace is ready.
|
|
542
544
|
}
|
|
543
545
|
await delay(Math.min(250, Math.max(0, deadline - Date.now())));
|
|
544
546
|
}
|
|
545
|
-
throw new Error("OpenCode
|
|
547
|
+
throw new Error("OpenCode workspace readiness check timed out.");
|
|
546
548
|
}
|
|
547
549
|
|
|
548
550
|
function readListeningUrl(child, timeoutMs) {
|
|
@@ -684,10 +686,18 @@ function watchInteractions({ baseUrl, fetchImpl, headers, requestTimeoutMs, sess
|
|
|
684
686
|
while (!controller.signal.aborted) {
|
|
685
687
|
try {
|
|
686
688
|
const url = serverUrl(baseUrl, "/event", workingDirectory);
|
|
687
|
-
const
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
689
|
+
const connection = new AbortController();
|
|
690
|
+
const connectionTimer = setTimeout(() => connection.abort(new Error("OpenCode event connection timed out.")), requestTimeoutMs);
|
|
691
|
+
connectionTimer.unref?.();
|
|
692
|
+
let response;
|
|
693
|
+
try {
|
|
694
|
+
response = await fetchImpl(url, {
|
|
695
|
+
headers: { ...headers, accept: "text/event-stream" },
|
|
696
|
+
signal: AbortSignal.any([controller.signal, connection.signal]),
|
|
697
|
+
});
|
|
698
|
+
} finally {
|
|
699
|
+
clearTimeout(connectionTimer);
|
|
700
|
+
}
|
|
691
701
|
if (!response.ok) throw new OpenCodeRequestError(response.status);
|
|
692
702
|
await reconcile();
|
|
693
703
|
if (!subscribed) {
|