@opencode/client 2.0.8 → 2.0.9
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/dist/chunks/pty-handoff-1tbj6z39.js +81 -0
- package/dist/chunks/pty-handoff-4tveyqeh.js +34 -0
- package/dist/chunks/pty-handoff-65kht65h.js +62 -0
- package/dist/chunks/pty-handoff-6mptkzbc.js +0 -0
- package/dist/chunks/pty-handoff-9rqn6x4v.js +16 -0
- package/dist/chunks/pty-handoff-atpwm825.js +1638 -0
- package/dist/chunks/pty-handoff-bssvn03b.js +594 -0
- package/dist/chunks/pty-handoff-frbwqjmf.js +145 -0
- package/dist/chunks/pty-handoff-m2eywc8w.js +0 -0
- package/dist/chunks/pty-handoff-n3c99vt5.js +11 -0
- package/dist/chunks/pty-handoff-nqd0dnpk.js +112 -0
- package/dist/chunks/pty-handoff-qav6mfdz.js +0 -0
- package/dist/chunks/pty-handoff-radw39tv.js +1402 -0
- package/dist/chunks/pty-handoff-sxt88q69.js +12 -0
- package/dist/chunks/pty-handoff-t1xa31vm.js +39 -0
- package/dist/chunks/pty-handoff-txckps9j.js +57 -0
- package/dist/chunks/pty-handoff-vgxtr9hm.js +30 -0
- package/dist/chunks/pty-handoff-vmytr4q8.js +4 -0
- package/dist/chunks/pty-handoff-vyas3vgt.js +0 -0
- package/dist/chunks/pty-handoff-xgnj2w4v.js +20 -0
- package/dist/chunks/pty-handoff-y2etg5bs.js +9 -0
- package/dist/chunks/pty-handoff-ydhz1zrh.js +238 -0
- package/dist/chunks/pty-handoff-yepdgb80.js +44 -0
- package/dist/chunks/pty-handoff-zadn5mwr.js +52 -0
- package/dist/contract.js +12 -1
- package/dist/effect/client.d.ts +4 -4
- package/dist/effect/client.js +15 -29
- package/dist/effect/generated/client-error.js +6 -5
- package/dist/effect/generated/client.d.ts +4 -4
- package/dist/effect/generated/client.js +8 -582
- package/dist/effect/generated/index.js +12 -2
- package/dist/effect/index.js +75 -30
- package/dist/effect/rpc.js +11 -49
- package/dist/effect/service.js +238 -245
- package/dist/promise/client.js +14 -13
- package/dist/promise/generated/client-error.js +6 -8
- package/dist/promise/generated/client.js +7 -1396
- package/dist/promise/generated/index.js +75 -3
- package/dist/promise/generated/types.d.ts +90 -88
- package/dist/promise/generated/types.js +66 -34
- package/dist/promise/index.js +79 -2
- package/dist/promise/rpc.js +7 -86
- package/dist/promise/service.js +230 -227
- package/dist/pty-handoff.js +14 -121
- package/dist/rpc-runtime.js +14 -32
- package/dist/service-contender.js +10 -56
- package/dist/service-timing.d.ts +0 -1
- package/dist/service-timing.js +9 -18
- package/dist/service-version.js +6 -9
- package/dist/service.js +1 -0
- package/dist/shared-events.js +8 -137
- package/dist/solid/connection.js +10 -246
- package/dist/solid/data.js +18 -1774
- package/dist/solid/index.js +32 -3
- package/dist/solid/pty.js +8 -41
- package/package.json +4 -4
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/service-version.ts
|
|
2
|
+
function matchesVersion2(version, options) {
|
|
3
|
+
if (options.version === undefined)
|
|
4
|
+
return true;
|
|
5
|
+
if (version === undefined)
|
|
6
|
+
return false;
|
|
7
|
+
if (typeof options.version === "function")
|
|
8
|
+
return options.version(version);
|
|
9
|
+
return version === options.version;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { matchesVersion2 };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./pty-handoff-9rqn6x4v.js";
|
|
4
|
+
|
|
5
|
+
// src/rpc-runtime.ts
|
|
6
|
+
var exports_rpc_runtime = {};
|
|
7
|
+
__export(exports_rpc_runtime, {
|
|
8
|
+
RpcRuntime: () => exports_rpc_runtime,
|
|
9
|
+
event: () => event2,
|
|
10
|
+
eventType: () => eventType2,
|
|
11
|
+
read: () => read2,
|
|
12
|
+
readError: () => readError2
|
|
13
|
+
});
|
|
14
|
+
import { RpcError, RpcInternalError } from "@opencode/protocol/errors";
|
|
15
|
+
import { Effect, Schema } from "effect";
|
|
16
|
+
function read2(schema, value) {
|
|
17
|
+
return Schema.isSchema(schema) ? Schema.decodeUnknownEffect(schema)(value) : Effect.succeed(value);
|
|
18
|
+
}
|
|
19
|
+
function readError2(method, error) {
|
|
20
|
+
if (!(error instanceof RpcError) && !(error instanceof RpcInternalError))
|
|
21
|
+
return Effect.fail(error);
|
|
22
|
+
if (!method.errors || !Object.hasOwn(method.errors, error.type)) {
|
|
23
|
+
return Effect.fail(error.data === undefined ? { type: error.type, message: error.message } : { type: error.type, message: error.message, data: error.data });
|
|
24
|
+
}
|
|
25
|
+
return read2(method.errors[error.type], error.data).pipe(Effect.catch((cause) => Effect.die(cause)), Effect.flatMap((data) => Effect.fail(data === undefined ? { type: error.type, message: error.message } : { type: error.type, message: error.message, data })));
|
|
26
|
+
}
|
|
27
|
+
var event2 = Effect.fn("Client.Rpc.event")(function* (definition, name, schema, event) {
|
|
28
|
+
const data = yield* read2(schema.schema, event.data);
|
|
29
|
+
return {
|
|
30
|
+
...event,
|
|
31
|
+
type: eventType2(definition, name),
|
|
32
|
+
data
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
function eventType2(definition, name) {
|
|
36
|
+
return `rpc.${definition.id}.${name}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { read2, readError2, event2, eventType2, exports_rpc_runtime };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/service-contender.ts
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
var stderrLimit = 8 * 1024;
|
|
4
|
+
function spawnServiceContender2(command, args, env) {
|
|
5
|
+
const child = spawn(command, args, {
|
|
6
|
+
detached: true,
|
|
7
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
8
|
+
env: { ...process.env, ...env }
|
|
9
|
+
});
|
|
10
|
+
let error;
|
|
11
|
+
let closed = false;
|
|
12
|
+
let stderr = Buffer.alloc(0);
|
|
13
|
+
const onStderr = (chunk) => {
|
|
14
|
+
const tail = chunk.subarray(-stderrLimit);
|
|
15
|
+
stderr = tail.length === stderrLimit ? Buffer.from(tail) : Buffer.concat([stderr.subarray(-(stderrLimit - tail.length)), tail]);
|
|
16
|
+
};
|
|
17
|
+
child.stderr?.on("data", onStderr);
|
|
18
|
+
if (child.stderr !== null && "unref" in child.stderr && typeof child.stderr.unref === "function")
|
|
19
|
+
child.stderr.unref();
|
|
20
|
+
child.once("error", (cause) => {
|
|
21
|
+
error = new Error("Failed to start server", { cause });
|
|
22
|
+
});
|
|
23
|
+
child.once("close", () => {
|
|
24
|
+
closed = true;
|
|
25
|
+
});
|
|
26
|
+
child.unref();
|
|
27
|
+
return {
|
|
28
|
+
child,
|
|
29
|
+
error: () => error,
|
|
30
|
+
closed: () => closed,
|
|
31
|
+
stderr: () => stderr.toString("utf8").trim(),
|
|
32
|
+
release: () => {
|
|
33
|
+
child.stderr?.off("data", onStderr);
|
|
34
|
+
child.stderr?.resume();
|
|
35
|
+
stderr = Buffer.alloc(0);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function contenderFailure2(contender) {
|
|
40
|
+
const error = contender.error();
|
|
41
|
+
if (error !== undefined)
|
|
42
|
+
return error;
|
|
43
|
+
if (contender.child.exitCode !== null && contender.child.exitCode !== 0)
|
|
44
|
+
return startupError(`Server process exited with code ${contender.child.exitCode}`, contender.stderr());
|
|
45
|
+
if (contender.child.signalCode !== null)
|
|
46
|
+
return startupError(`Server process terminated by ${contender.child.signalCode}`, contender.stderr());
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
function contenderFinished2(contender) {
|
|
50
|
+
return contender.error() !== undefined || contender.closed();
|
|
51
|
+
}
|
|
52
|
+
function startupError(message, stderr) {
|
|
53
|
+
return new Error(stderr ? `${message}
|
|
54
|
+
${stderr}` : message);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { spawnServiceContender2, contenderFailure2, contenderFinished2 };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
make7
|
|
3
|
+
} from "./pty-handoff-frbwqjmf.js";
|
|
4
|
+
import {
|
|
5
|
+
make6
|
|
6
|
+
} from "./pty-handoff-radw39tv.js";
|
|
7
|
+
import {
|
|
8
|
+
makeRpc2
|
|
9
|
+
} from "./pty-handoff-1tbj6z39.js";
|
|
10
|
+
import {
|
|
11
|
+
__export
|
|
12
|
+
} from "./pty-handoff-9rqn6x4v.js";
|
|
13
|
+
|
|
14
|
+
// src/promise/client.ts
|
|
15
|
+
var exports_client3 = {};
|
|
16
|
+
__export(exports_client3, {
|
|
17
|
+
OpenCode: () => exports_client3,
|
|
18
|
+
make: () => make5
|
|
19
|
+
});
|
|
20
|
+
function make5(options) {
|
|
21
|
+
const raw = make6(options);
|
|
22
|
+
const events = make7((signal, onActivity) => raw.event.subscribe({ signal, onActivity }));
|
|
23
|
+
return {
|
|
24
|
+
...raw,
|
|
25
|
+
rpc: Object.assign(makeRpc2(raw, events), raw.rpc),
|
|
26
|
+
event: events
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { make5, exports_client3 };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// src/contract.ts
|
|
2
|
+
import { ClientApi as ClientApi2, effectOmitEndpoints as effectOmitEndpoints2, groupNames as groupNames2, promiseOmitEndpoints as promiseOmitEndpoints2 } from "@opencode/protocol/client";
|
|
3
|
+
|
|
4
|
+
export { ClientApi2, effectOmitEndpoints2, groupNames2, promiseOmitEndpoints2 };
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/service-timing.ts
|
|
2
|
+
var timings = new WeakMap;
|
|
3
|
+
var defaultEnsureTiming2 = {
|
|
4
|
+
pollInterval: 25,
|
|
5
|
+
requestTimeout: 2000,
|
|
6
|
+
spawnDelay: 5000,
|
|
7
|
+
maxSpawnDelay: 30000,
|
|
8
|
+
promiseTimeout: 120000,
|
|
9
|
+
stopPollInterval: 50,
|
|
10
|
+
stopPollAttempts: 100
|
|
11
|
+
};
|
|
12
|
+
function ensureTiming2(options) {
|
|
13
|
+
return timings.get(options) ?? defaultEnsureTiming2;
|
|
14
|
+
}
|
|
15
|
+
function withEnsureTiming2(options, overrides) {
|
|
16
|
+
timings.set(options, { ...defaultEnsureTiming2, ...overrides });
|
|
17
|
+
return options;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { defaultEnsureTiming2, ensureTiming2, withEnsureTiming2 };
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
// src/solid/connection.ts
|
|
2
|
+
import { batch, onCleanup } from "solid-js";
|
|
3
|
+
import { createStore } from "solid-js/store";
|
|
4
|
+
var connectTimeout = 2000;
|
|
5
|
+
var reconnectDelay = 1000;
|
|
6
|
+
var connectionHistoryLimit = 50;
|
|
7
|
+
var defaultIdleTimeout2 = 45000;
|
|
8
|
+
var foregroundIdleThreshold2 = 20000;
|
|
9
|
+
function createClientConnection2(initialApi, options) {
|
|
10
|
+
const abort = new AbortController;
|
|
11
|
+
const history = [];
|
|
12
|
+
const idleTimeout = options.idleTimeout ?? defaultIdleTimeout2;
|
|
13
|
+
const [connection, setConnection] = createStore({ status: "connecting", attempt: 0 });
|
|
14
|
+
let api = initialApi;
|
|
15
|
+
let pending = [];
|
|
16
|
+
let flushTimer;
|
|
17
|
+
let stream;
|
|
18
|
+
let current;
|
|
19
|
+
let run;
|
|
20
|
+
let started = false;
|
|
21
|
+
let generation = 0;
|
|
22
|
+
let lastActivity = 0;
|
|
23
|
+
let forced = false;
|
|
24
|
+
function record(status, attempt, error) {
|
|
25
|
+
history.push({ type: "client.connection", created: Date.now(), data: { status, attempt, error } });
|
|
26
|
+
if (history.length > connectionHistoryLimit)
|
|
27
|
+
history.shift();
|
|
28
|
+
}
|
|
29
|
+
function publish(event) {
|
|
30
|
+
pending.push(event);
|
|
31
|
+
if (flushTimer)
|
|
32
|
+
return;
|
|
33
|
+
flushTimer = setTimeout(() => {
|
|
34
|
+
flushTimer = undefined;
|
|
35
|
+
const events = pending;
|
|
36
|
+
pending = [];
|
|
37
|
+
batch(() => events.forEach(options.onEvent));
|
|
38
|
+
}, options.flushInterval ?? 10);
|
|
39
|
+
}
|
|
40
|
+
async function connect(signal, attempt) {
|
|
41
|
+
let connectedAt;
|
|
42
|
+
const request = new AbortController;
|
|
43
|
+
current = request;
|
|
44
|
+
const cancel = () => request.abort(signal.reason);
|
|
45
|
+
const timeout = setTimeout(() => request.abort(new Error("Timed out connecting to server")), connectTimeout);
|
|
46
|
+
signal.addEventListener("abort", cancel, { once: true });
|
|
47
|
+
let watchdog;
|
|
48
|
+
const touch = () => {
|
|
49
|
+
lastActivity = Date.now();
|
|
50
|
+
if (connectedAt === undefined)
|
|
51
|
+
return;
|
|
52
|
+
clearTimeout(watchdog);
|
|
53
|
+
watchdog = setTimeout(() => request.abort(new Error("Event stream stalled")), idleTimeout);
|
|
54
|
+
};
|
|
55
|
+
try {
|
|
56
|
+
record(attempt === 0 ? "connecting" : "reconnecting", attempt);
|
|
57
|
+
options.log?.info?.("event stream connecting", { attempt });
|
|
58
|
+
const iterator = api.event.subscribe({ signal: request.signal, onActivity: touch })[Symbol.asyncIterator]();
|
|
59
|
+
const first = await iterator.next();
|
|
60
|
+
if (signal.aborted)
|
|
61
|
+
return { error: undefined, connectedAt };
|
|
62
|
+
if (first.done)
|
|
63
|
+
return {
|
|
64
|
+
error: request.signal.reason instanceof Error ? request.signal.reason : new Error("Event stream disconnected"),
|
|
65
|
+
connectedAt
|
|
66
|
+
};
|
|
67
|
+
if (first.value.type !== "server.connected")
|
|
68
|
+
return { error: new Error("Event stream did not start with server.connected"), connectedAt };
|
|
69
|
+
clearTimeout(timeout);
|
|
70
|
+
record("connected", attempt);
|
|
71
|
+
connectedAt = Date.now();
|
|
72
|
+
touch();
|
|
73
|
+
options.log?.info?.("event stream connected");
|
|
74
|
+
publish(first.value);
|
|
75
|
+
setConnection({ status: "connected", attempt: 0, error: undefined });
|
|
76
|
+
while (!signal.aborted) {
|
|
77
|
+
const event = await iterator.next();
|
|
78
|
+
if (signal.aborted)
|
|
79
|
+
return { error: undefined, connectedAt };
|
|
80
|
+
if (event.done)
|
|
81
|
+
return {
|
|
82
|
+
error: request.signal.reason instanceof Error ? request.signal.reason : new Error("Event stream disconnected"),
|
|
83
|
+
connectedAt
|
|
84
|
+
};
|
|
85
|
+
touch();
|
|
86
|
+
if ("durable" in event.value && event.value.durable)
|
|
87
|
+
options.log?.debug?.("event", {
|
|
88
|
+
type: event.value.type,
|
|
89
|
+
aggregateID: event.value.durable.aggregateID,
|
|
90
|
+
seq: event.value.durable.seq
|
|
91
|
+
});
|
|
92
|
+
publish(event.value);
|
|
93
|
+
}
|
|
94
|
+
return { error: undefined, connectedAt };
|
|
95
|
+
} catch (error) {
|
|
96
|
+
return { error, connectedAt };
|
|
97
|
+
} finally {
|
|
98
|
+
request.abort();
|
|
99
|
+
if (current === request)
|
|
100
|
+
current = undefined;
|
|
101
|
+
clearTimeout(timeout);
|
|
102
|
+
clearTimeout(watchdog);
|
|
103
|
+
signal.removeEventListener("abort", cancel);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function runStream(active) {
|
|
107
|
+
let attempt = 0;
|
|
108
|
+
while (!abort.signal.aborted && started && generation === active) {
|
|
109
|
+
setConnection({ status: attempt === 0 ? "connecting" : "reconnecting", attempt });
|
|
110
|
+
const controller = new AbortController;
|
|
111
|
+
stream = controller;
|
|
112
|
+
const cancel = () => controller.abort(abort.signal.reason);
|
|
113
|
+
abort.signal.addEventListener("abort", cancel);
|
|
114
|
+
const result = await connect(controller.signal, attempt);
|
|
115
|
+
abort.signal.removeEventListener("abort", cancel);
|
|
116
|
+
if (abort.signal.aborted || !started || generation !== active)
|
|
117
|
+
return;
|
|
118
|
+
if (result.connectedAt !== undefined && Date.now() - result.connectedAt >= reconnectDelay)
|
|
119
|
+
attempt = 0;
|
|
120
|
+
attempt += 1;
|
|
121
|
+
const message = errorMessage(result.error);
|
|
122
|
+
record("disconnected", attempt, message);
|
|
123
|
+
options.log?.info?.("event stream disconnected", { attempt, error: message });
|
|
124
|
+
setConnection({ status: "reconnecting", attempt, error: message });
|
|
125
|
+
if (options.reconnect) {
|
|
126
|
+
const next = await options.reconnect(controller.signal).catch((error) => {
|
|
127
|
+
if (!controller.signal.aborted)
|
|
128
|
+
options.log?.info?.("server resolution failed", { attempt, error: errorMessage(error) });
|
|
129
|
+
});
|
|
130
|
+
if (abort.signal.aborted || controller.signal.aborted || !started || generation !== active)
|
|
131
|
+
return;
|
|
132
|
+
if (next) {
|
|
133
|
+
api = next;
|
|
134
|
+
if (attempt === 1)
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (forced) {
|
|
139
|
+
forced = false;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
await wait(reconnectDelay, controller.signal);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function start() {
|
|
146
|
+
if (started)
|
|
147
|
+
return run;
|
|
148
|
+
started = true;
|
|
149
|
+
forced = false;
|
|
150
|
+
const active = ++generation;
|
|
151
|
+
const previous = run;
|
|
152
|
+
const current = (async () => {
|
|
153
|
+
if (previous)
|
|
154
|
+
await previous;
|
|
155
|
+
await runStream(active);
|
|
156
|
+
})().finally(() => {
|
|
157
|
+
if (run !== current)
|
|
158
|
+
return;
|
|
159
|
+
run = undefined;
|
|
160
|
+
});
|
|
161
|
+
run = current;
|
|
162
|
+
return run;
|
|
163
|
+
}
|
|
164
|
+
function stop() {
|
|
165
|
+
if (!started)
|
|
166
|
+
return;
|
|
167
|
+
started = false;
|
|
168
|
+
generation += 1;
|
|
169
|
+
stream?.abort();
|
|
170
|
+
setConnection({ status: "connecting", attempt: 0, error: undefined });
|
|
171
|
+
}
|
|
172
|
+
function resync(reason) {
|
|
173
|
+
if (!started || connection.status !== "connected")
|
|
174
|
+
return;
|
|
175
|
+
options.log?.info?.("event stream resync", { reason, idle: Date.now() - lastActivity });
|
|
176
|
+
forced = true;
|
|
177
|
+
current?.abort(new Error(reason));
|
|
178
|
+
}
|
|
179
|
+
if (options.pageLifecycle) {
|
|
180
|
+
const pagehide = () => stop();
|
|
181
|
+
const pageshow = () => void start();
|
|
182
|
+
const visibility = () => {
|
|
183
|
+
if (document.visibilityState !== "visible")
|
|
184
|
+
return;
|
|
185
|
+
if (Date.now() - lastActivity < foregroundIdleThreshold2)
|
|
186
|
+
return;
|
|
187
|
+
resync("Page returned to the foreground after the event stream went quiet");
|
|
188
|
+
};
|
|
189
|
+
const online = () => resync("Network connection restored");
|
|
190
|
+
window.addEventListener("pagehide", pagehide);
|
|
191
|
+
window.addEventListener("pageshow", pageshow);
|
|
192
|
+
window.addEventListener("online", online);
|
|
193
|
+
document.addEventListener("visibilitychange", visibility);
|
|
194
|
+
onCleanup(() => {
|
|
195
|
+
window.removeEventListener("pagehide", pagehide);
|
|
196
|
+
window.removeEventListener("pageshow", pageshow);
|
|
197
|
+
window.removeEventListener("online", online);
|
|
198
|
+
document.removeEventListener("visibilitychange", visibility);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
start();
|
|
202
|
+
onCleanup(() => {
|
|
203
|
+
stop();
|
|
204
|
+
abort.abort();
|
|
205
|
+
if (flushTimer)
|
|
206
|
+
clearTimeout(flushTimer);
|
|
207
|
+
pending = [];
|
|
208
|
+
});
|
|
209
|
+
return {
|
|
210
|
+
status: () => connection.status,
|
|
211
|
+
attempt: () => connection.attempt,
|
|
212
|
+
error: () => connection.error,
|
|
213
|
+
internal: {
|
|
214
|
+
history: () => history.slice(),
|
|
215
|
+
resync
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function errorMessage(error) {
|
|
220
|
+
if (error === undefined)
|
|
221
|
+
return;
|
|
222
|
+
if (error instanceof Error)
|
|
223
|
+
return error.message;
|
|
224
|
+
return String(error);
|
|
225
|
+
}
|
|
226
|
+
function wait(delay, signal) {
|
|
227
|
+
return new Promise((resolve) => {
|
|
228
|
+
const timer = setTimeout(done, delay);
|
|
229
|
+
signal.addEventListener("abort", done, { once: true });
|
|
230
|
+
function done() {
|
|
231
|
+
clearTimeout(timer);
|
|
232
|
+
signal.removeEventListener("abort", done);
|
|
233
|
+
resolve();
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export { defaultIdleTimeout2, foregroundIdleThreshold2, createClientConnection2 };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/solid/pty.ts
|
|
2
|
+
function createPtyClient2(api, options) {
|
|
3
|
+
return {
|
|
4
|
+
async connect(input) {
|
|
5
|
+
const result = await api.pty.connect.token({
|
|
6
|
+
ptyID: input.ptyID,
|
|
7
|
+
location: input.location,
|
|
8
|
+
"x-opencode-ticket": "1"
|
|
9
|
+
});
|
|
10
|
+
const url = new URL(`/api/pty/${encodeURIComponent(input.ptyID)}/connect`, options.url);
|
|
11
|
+
if (input.location?.directory)
|
|
12
|
+
url.searchParams.set("location[directory]", input.location.directory);
|
|
13
|
+
if (input.cursor !== undefined)
|
|
14
|
+
url.searchParams.set("cursor", String(input.cursor));
|
|
15
|
+
url.searchParams.set("ticket", result.data.ticket);
|
|
16
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
17
|
+
const socket = options.openSocket?.(url) ?? new WebSocket(url);
|
|
18
|
+
socket.binaryType = "arraybuffer";
|
|
19
|
+
return socket;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function createPersistentPtyClient2(api, options) {
|
|
24
|
+
return {
|
|
25
|
+
async connect(input) {
|
|
26
|
+
const token = await api.experimental.persistentPty.connectToken({
|
|
27
|
+
ptyID: input.ptyID,
|
|
28
|
+
"x-opencode-ticket": "1"
|
|
29
|
+
});
|
|
30
|
+
const url = new URL(`/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}/connect`, options.url);
|
|
31
|
+
url.searchParams.set("ticket", token.ticket);
|
|
32
|
+
url.searchParams.set("cursor", String(input.cursor));
|
|
33
|
+
url.searchParams.set("attachment_id", input.attachmentID);
|
|
34
|
+
url.searchParams.set("takeover", String(input.takeover ?? false));
|
|
35
|
+
url.searchParams.set("input_protocol", "1");
|
|
36
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
37
|
+
const socket = options.openSocket?.(url) ?? new WebSocket(url);
|
|
38
|
+
socket.binaryType = "arraybuffer";
|
|
39
|
+
return socket;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { createPtyClient2, createPersistentPtyClient2 };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
make7
|
|
3
|
+
} from "./pty-handoff-frbwqjmf.js";
|
|
4
|
+
import {
|
|
5
|
+
ClientError2
|
|
6
|
+
} from "./pty-handoff-y2etg5bs.js";
|
|
7
|
+
import {
|
|
8
|
+
make4
|
|
9
|
+
} from "./pty-handoff-bssvn03b.js";
|
|
10
|
+
import {
|
|
11
|
+
make3,
|
|
12
|
+
aborted2
|
|
13
|
+
} from "./pty-handoff-65kht65h.js";
|
|
14
|
+
import {
|
|
15
|
+
__export
|
|
16
|
+
} from "./pty-handoff-9rqn6x4v.js";
|
|
17
|
+
|
|
18
|
+
// src/effect/client.ts
|
|
19
|
+
var exports_client = {};
|
|
20
|
+
__export(exports_client, {
|
|
21
|
+
OpenCode: () => exports_client,
|
|
22
|
+
make: () => make2
|
|
23
|
+
});
|
|
24
|
+
import { Cause, Context, Effect, Stream } from "effect";
|
|
25
|
+
import { HttpClient, HttpClientRequest } from "effect/unstable/http";
|
|
26
|
+
var CurrentHeaders = Context.Reference("@opencode/client/effect/rpc/headers", {
|
|
27
|
+
defaultValue: () => {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
var make2 = Effect.fn("OpenCode.make")(function* (options) {
|
|
32
|
+
const httpClient = yield* HttpClient.HttpClient;
|
|
33
|
+
const raw = yield* make4(options).pipe(Effect.provideService(HttpClient.HttpClient, HttpClient.mapRequestEffect(httpClient, (request) => Effect.map(CurrentHeaders, (headers) => headers ? HttpClientRequest.setHeaders(request, new Headers(headers)) : request))));
|
|
34
|
+
const context = yield* Effect.context();
|
|
35
|
+
const native = raw.event.subscribe();
|
|
36
|
+
|
|
37
|
+
class EventFailure {
|
|
38
|
+
cause;
|
|
39
|
+
constructor(cause) {
|
|
40
|
+
this.cause = cause;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const shared = make7((signal) => Stream.toAsyncIterableWith(native.pipe(Stream.interruptWhen(aborted2(signal)), Stream.catchCause((cause) => Stream.fail(new EventFailure(cause)))), context));
|
|
44
|
+
const subscribe = () => Stream.fromAsyncIterable(shared.subscribe(), (error) => error).pipe(Stream.catch((error) => Stream.failCause(error instanceof EventFailure ? error.cause : Cause.fail(new ClientError2({ cause: error })))));
|
|
45
|
+
return {
|
|
46
|
+
...raw,
|
|
47
|
+
event: { ...raw.event, subscribe },
|
|
48
|
+
rpc: Object.assign(make3((input, options) => raw.rpc.call(input).pipe(Effect.provideService(CurrentHeaders, options?.headers)), subscribe), raw.rpc)
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export { make2, exports_client };
|
package/dist/contract.js
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
ClientApi2,
|
|
3
|
+
effectOmitEndpoints2,
|
|
4
|
+
groupNames2,
|
|
5
|
+
promiseOmitEndpoints2
|
|
6
|
+
} from "./chunks/pty-handoff-vmytr4q8.js";
|
|
7
|
+
export {
|
|
8
|
+
ClientApi2 as ClientApi,
|
|
9
|
+
effectOmitEndpoints2 as effectOmitEndpoints,
|
|
10
|
+
groupNames2 as groupNames,
|
|
11
|
+
promiseOmitEndpoints2 as promiseOmitEndpoints
|
|
12
|
+
};
|
package/dist/effect/client.d.ts
CHANGED
|
@@ -420,7 +420,7 @@ export declare const make: (options?: {
|
|
|
420
420
|
readonly [x: string]: unknown;
|
|
421
421
|
};
|
|
422
422
|
readonly command: string;
|
|
423
|
-
readonly status: "
|
|
423
|
+
readonly status: "timeout" | "running" | "exited" | "killed";
|
|
424
424
|
readonly time: {
|
|
425
425
|
readonly started: number;
|
|
426
426
|
readonly completed?: number | undefined;
|
|
@@ -445,7 +445,7 @@ export declare const make: (options?: {
|
|
|
445
445
|
readonly id: string & import("effect/Brand").Brand<"Event.ID">;
|
|
446
446
|
readonly data: {
|
|
447
447
|
readonly id: string & import("effect/Brand").Brand<"Shell.ID">;
|
|
448
|
-
readonly status: "
|
|
448
|
+
readonly status: "timeout" | "running" | "exited" | "killed";
|
|
449
449
|
readonly exit?: number | undefined;
|
|
450
450
|
};
|
|
451
451
|
readonly type: "shell.exited";
|
|
@@ -1042,7 +1042,7 @@ export declare const make: (options?: {
|
|
|
1042
1042
|
readonly [x: string]: unknown;
|
|
1043
1043
|
};
|
|
1044
1044
|
readonly command: string;
|
|
1045
|
-
readonly status: "
|
|
1045
|
+
readonly status: "timeout" | "running" | "exited" | "killed";
|
|
1046
1046
|
readonly time: {
|
|
1047
1047
|
readonly started: number;
|
|
1048
1048
|
readonly completed?: number | undefined;
|
|
@@ -1078,7 +1078,7 @@ export declare const make: (options?: {
|
|
|
1078
1078
|
readonly [x: string]: unknown;
|
|
1079
1079
|
};
|
|
1080
1080
|
readonly command: string;
|
|
1081
|
-
readonly status: "
|
|
1081
|
+
readonly status: "timeout" | "running" | "exited" | "killed";
|
|
1082
1082
|
readonly time: {
|
|
1083
1083
|
readonly started: number;
|
|
1084
1084
|
readonly completed?: number | undefined;
|
package/dist/effect/client.js
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class EventFailure {
|
|
17
|
-
cause;
|
|
18
|
-
constructor(cause) {
|
|
19
|
-
this.cause = cause;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
const shared = SharedEvents.make((signal) => Stream.toAsyncIterableWith(native.pipe(Stream.interruptWhen(RpcClientRuntime.aborted(signal)), Stream.catchCause((cause) => Stream.fail(new EventFailure(cause)))), context));
|
|
23
|
-
const subscribe = () => Stream.fromAsyncIterable(shared.subscribe(), (error) => error).pipe(Stream.catch((error) => Stream.failCause(error instanceof EventFailure ? error.cause : Cause.fail(new ClientError({ cause: error })))));
|
|
24
|
-
return {
|
|
25
|
-
...raw,
|
|
26
|
-
event: { ...raw.event, subscribe },
|
|
27
|
-
rpc: Object.assign(RpcClientRuntime.make((input, options) => raw.rpc.call(input).pipe(Effect.provideService(CurrentHeaders, options?.headers)), subscribe), raw.rpc),
|
|
28
|
-
};
|
|
29
|
-
});
|
|
1
|
+
import {
|
|
2
|
+
make2,
|
|
3
|
+
exports_client
|
|
4
|
+
} from "../chunks/pty-handoff-zadn5mwr.js";
|
|
5
|
+
import"../chunks/pty-handoff-65kht65h.js";
|
|
6
|
+
import"../chunks/pty-handoff-6mptkzbc.js";
|
|
7
|
+
import"../chunks/pty-handoff-bssvn03b.js";
|
|
8
|
+
import"../chunks/pty-handoff-y2etg5bs.js";
|
|
9
|
+
import"../chunks/pty-handoff-frbwqjmf.js";
|
|
10
|
+
import"../chunks/pty-handoff-vmytr4q8.js";
|
|
11
|
+
import"../chunks/pty-handoff-t1xa31vm.js";
|
|
12
|
+
export {
|
|
13
|
+
exports_client as OpenCode,
|
|
14
|
+
make2 as make
|
|
15
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import {
|
|
2
|
+
ClientError2
|
|
3
|
+
} from "../../chunks/pty-handoff-y2etg5bs.js";
|
|
4
|
+
export {
|
|
5
|
+
ClientError2 as ClientError
|
|
6
|
+
};
|
|
@@ -575,7 +575,7 @@ export declare const make: (options?: {
|
|
|
575
575
|
readonly [x: string]: unknown;
|
|
576
576
|
};
|
|
577
577
|
readonly command: string;
|
|
578
|
-
readonly status: "
|
|
578
|
+
readonly status: "timeout" | "running" | "exited" | "killed";
|
|
579
579
|
readonly time: {
|
|
580
580
|
readonly started: number;
|
|
581
581
|
readonly completed?: number | undefined;
|
|
@@ -600,7 +600,7 @@ export declare const make: (options?: {
|
|
|
600
600
|
readonly id: string & import("effect/Brand").Brand<"Event.ID">;
|
|
601
601
|
readonly data: {
|
|
602
602
|
readonly id: string & import("effect/Brand").Brand<"Shell.ID">;
|
|
603
|
-
readonly status: "
|
|
603
|
+
readonly status: "timeout" | "running" | "exited" | "killed";
|
|
604
604
|
readonly exit?: number | undefined;
|
|
605
605
|
};
|
|
606
606
|
readonly type: "shell.exited";
|
|
@@ -1197,7 +1197,7 @@ export declare const make: (options?: {
|
|
|
1197
1197
|
readonly [x: string]: unknown;
|
|
1198
1198
|
};
|
|
1199
1199
|
readonly command: string;
|
|
1200
|
-
readonly status: "
|
|
1200
|
+
readonly status: "timeout" | "running" | "exited" | "killed";
|
|
1201
1201
|
readonly time: {
|
|
1202
1202
|
readonly started: number;
|
|
1203
1203
|
readonly completed?: number | undefined;
|
|
@@ -1233,7 +1233,7 @@ export declare const make: (options?: {
|
|
|
1233
1233
|
readonly [x: string]: unknown;
|
|
1234
1234
|
};
|
|
1235
1235
|
readonly command: string;
|
|
1236
|
-
readonly status: "
|
|
1236
|
+
readonly status: "timeout" | "running" | "exited" | "killed";
|
|
1237
1237
|
readonly time: {
|
|
1238
1238
|
readonly started: number;
|
|
1239
1239
|
readonly completed?: number | undefined;
|