@opencode/server 2.0.23 → 2.0.25
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/api.js +5 -5
- package/dist/auth.js +1 -1
- package/dist/chunks/{options-bkk2wfbz.js → location-0d9kah4z.js} +7 -7
- package/dist/chunks/{options-swb5yrqf.js → location-0vyswjsz.js} +2 -2
- package/dist/chunks/{options-bptmkrac.js → location-16qfdx6b.js} +2 -2
- package/dist/chunks/{options-j54drd5e.js → location-1nwce8pe.js} +1 -1
- package/dist/chunks/{options-q4y3mw2d.js → location-1xva44q8.js} +2 -2
- package/dist/chunks/{options-54sczv30.js → location-2sy3c7de.js} +7 -7
- package/dist/chunks/{options-0b1t2b2s.js → location-4rww2e47.js} +2 -2
- package/dist/chunks/{options-da5stqtt.js → location-4znne276.js} +1 -1
- package/dist/chunks/{options-nxdx74sv.js → location-796j10e5.js} +1 -1
- package/dist/chunks/{options-mpbfcr4e.js → location-7gfv664k.js} +2 -2
- package/dist/chunks/{options-jskw5q1g.js → location-7rxakzjh.js} +1 -1
- package/dist/chunks/{options-6sgwm4gr.js → location-934cmkaf.js} +16 -2
- package/dist/chunks/{options-5p62ed52.js → location-93wjydnn.js} +11 -6
- package/dist/chunks/{options-ep84ha6r.js → location-9cw9axw5.js} +3 -3
- package/dist/chunks/{options-dvemjn3r.js → location-9gvk307e.js} +6 -6
- package/dist/chunks/{options-n7kafg5g.js → location-ajzgetf8.js} +2 -2
- package/dist/chunks/{options-anm12x33.js → location-anm12x33.js} +1 -1
- package/dist/chunks/{options-gdqqe6m4.js → location-ap5bajez.js} +33 -33
- package/dist/chunks/{options-aqzs83qc.js → location-c7mfxxxb.js} +4 -4
- package/dist/chunks/{options-3c937re8.js → location-ca257yb3.js} +2 -2
- package/dist/chunks/{options-vkrn1g9x.js → location-ceje7ncg.js} +15 -15
- package/dist/chunks/location-cqdj4ap7.js +106 -0
- package/dist/chunks/{options-m9wzfeff.js → location-dqsr2g0t.js} +2 -2
- package/dist/chunks/{options-acgs9zzk.js → location-f2c3fmpg.js} +3 -3
- package/dist/chunks/{options-wzq8v6r1.js → location-f7sjppyz.js} +62 -51
- package/dist/chunks/{options-nvmdgpqv.js → location-g85r3kcp.js} +2 -2
- package/dist/chunks/{options-30gqa6y8.js → location-gny2k2ap.js} +3 -3
- package/dist/chunks/{options-gtkdacvk.js → location-gtkdacvk.js} +1 -1
- package/dist/chunks/{options-ccfecbt4.js → location-hvft24jv.js} +1 -1
- package/dist/chunks/{options-387sf4vs.js → location-jzqzrtw5.js} +1 -1
- package/dist/chunks/{options-srcrrwjk.js → location-krn4521r.js} +2 -2
- package/dist/chunks/{options-7nkw7zmw.js → location-m9xs9t19.js} +6 -6
- package/dist/chunks/{options-w8db1rkr.js → location-n52yc5x0.js} +2 -2
- package/dist/chunks/{options-kr61w04k.js → location-sstsrjtg.js} +7 -7
- package/dist/chunks/{options-fsrvj92d.js → location-td9k2nw3.js} +2 -2
- package/dist/chunks/{options-2vy10eeh.js → location-v9pcqbqn.js} +2 -2
- package/dist/chunks/{options-5fmydwgy.js → location-vb9atgxj.js} +1 -1
- package/dist/chunks/{options-d00srfh1.js → location-w070c2h2.js} +1 -1
- package/dist/chunks/{options-62qjgyra.js → location-weqhmjbd.js} +2 -2
- package/dist/chunks/{options-k4rfktze.js → location-x2by5wsf.js} +7 -8
- package/dist/chunks/{options-5w24ch67.js → location-xsrtpxyd.js} +4 -4
- package/dist/chunks/{options-zhqf1t9m.js → location-y1grnrmm.js} +1 -1
- package/dist/chunks/{options-pg3sqc69.js → location-ym27c8rr.js} +3 -3
- package/dist/chunks/{options-qcy0p5fz.js → location-yybdkkb6.js} +2 -2
- package/dist/cors.js +1 -1
- package/dist/event-feed.js +5 -5
- package/dist/fetch.js +49 -49
- package/dist/handlers/agent.js +6 -6
- package/dist/handlers/command.js +6 -6
- package/dist/handlers/config.js +6 -6
- package/dist/handlers/credential.js +6 -6
- package/dist/handlers/debug.js +6 -6
- package/dist/handlers/event.js +7 -7
- package/dist/handlers/form.js +6 -6
- package/dist/handlers/fs.js +6 -6
- package/dist/handlers/generate.js +6 -6
- package/dist/handlers/integration.d.ts +1 -1
- package/dist/handlers/integration.js +6 -6
- package/dist/handlers/location.js +6 -6
- package/dist/handlers/mcp.js +6 -6
- package/dist/handlers/message.js +6 -6
- package/dist/handlers/migration.js +6 -6
- package/dist/handlers/model.js +6 -6
- package/dist/handlers/permission.js +6 -6
- package/dist/handlers/persistent-pty.js +8 -8
- package/dist/handlers/plugin.js +6 -6
- package/dist/handlers/project.js +6 -6
- package/dist/handlers/provider.js +6 -6
- package/dist/handlers/pty-socket.js +1 -1
- package/dist/handlers/pty.d.ts +2 -1
- package/dist/handlers/pty.js +9 -9
- package/dist/handlers/reference.js +6 -6
- package/dist/handlers/rpc.js +6 -6
- package/dist/handlers/server.js +9 -9
- package/dist/handlers/session-error.js +1 -1
- package/dist/handlers/session.js +6 -6
- package/dist/handlers/shell.js +6 -6
- package/dist/handlers/skill.js +6 -6
- package/dist/handlers/vcs.js +6 -6
- package/dist/handlers/websearch.js +6 -6
- package/dist/handlers/worktree.js +6 -6
- package/dist/handlers.js +43 -43
- package/dist/location.js +4 -4
- package/dist/middleware/authorization.js +2 -2
- package/dist/middleware/form-location.js +3 -3
- package/dist/middleware/schema-error.js +1 -1
- package/dist/middleware/session-location.js +3 -3
- package/dist/pairing.js +3 -3
- package/dist/process.d.ts +1 -1
- package/dist/process.js +54 -53
- package/dist/pty-environment.js +5 -5
- package/dist/request-tracing.js +1 -1
- package/dist/routes.js +46 -46
- package/dist/server-info.js +1 -1
- package/dist/service-status.js +3 -3
- package/dist/workerd.js +50 -50
- package/package.json +8 -9
- package/dist/chunks/options-jhsx8jtg.js +0 -34
- /package/dist/chunks/{options-9rqn6x4v.js → location-9rqn6x4v.js} +0 -0
- /package/dist/chunks/{options-hezj1jdf.js → location-hezj1jdf.js} +0 -0
- /package/dist/chunks/{options-q4bn6dy8.js → location-q4bn6dy8.js} +0 -0
- /package/dist/chunks/{options-smaf4a18.js → location-smaf4a18.js} +0 -0
- /package/dist/chunks/{options-t8yzmczr.js → location-t8yzmczr.js} +0 -0
- /package/dist/chunks/{options-yc7nft6q.js → location-yc7nft6q.js} +0 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {
|
|
2
|
+
response2
|
|
3
|
+
} from "./location-f2c3fmpg.js";
|
|
4
|
+
import {
|
|
5
|
+
Api2
|
|
6
|
+
} from "./location-9cw9axw5.js";
|
|
7
|
+
|
|
8
|
+
// src/handlers/fs.ts
|
|
9
|
+
import { FileSystem } from "@opencode/core/filesystem";
|
|
10
|
+
import { RelativePath } from "@opencode/core/schema";
|
|
11
|
+
import { FileNotFoundError } from "@opencode/protocol/errors";
|
|
12
|
+
import { Effect, Option, Stream } from "effect";
|
|
13
|
+
import { HttpServerResponse } from "effect/unstable/http";
|
|
14
|
+
import { HttpApiBuilder } from "effect/unstable/httpapi";
|
|
15
|
+
var FileSystemHandler2 = HttpApiBuilder.group(Api2, "server.fs", (handlers) => Effect.gen(function* () {
|
|
16
|
+
return handlers.handleRaw("fs.read", (ctx) => Effect.gen(function* () {
|
|
17
|
+
const path = yield* decodeRequestPath(ctx.request.url);
|
|
18
|
+
const fs = yield* FileSystem.Service;
|
|
19
|
+
const file = yield* fs.read({ path }).pipe(Effect.mapError((error) => new FileNotFoundError({ path: error.path, message: `File not found: ${error.path}` })));
|
|
20
|
+
return serveFile(ctx.request, file);
|
|
21
|
+
})).handle("fs.list", (ctx) => response2(Effect.gen(function* () {
|
|
22
|
+
const fs = yield* FileSystem.Service;
|
|
23
|
+
return yield* fs.list(ctx.query);
|
|
24
|
+
}))).handle("fs.find", (ctx) => response2(Effect.gen(function* () {
|
|
25
|
+
const fs = yield* FileSystem.Service;
|
|
26
|
+
return yield* fs.find(ctx.query);
|
|
27
|
+
}))).handle("fs.write", (ctx) => response2(Effect.gen(function* () {
|
|
28
|
+
const fs = yield* FileSystem.Service;
|
|
29
|
+
return yield* fs.write({ path: ctx.query.path, data: ctx.payload });
|
|
30
|
+
})));
|
|
31
|
+
}));
|
|
32
|
+
function decodeRequestPath(url) {
|
|
33
|
+
const raw = new URL(url, "http://localhost").pathname.slice(13);
|
|
34
|
+
return Effect.try({
|
|
35
|
+
try: () => RelativePath.make(decodeURIComponent(raw)),
|
|
36
|
+
catch: () => new FileNotFoundError({ path: raw, message: `File not found: ${raw}` })
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function serveFile(request, file) {
|
|
40
|
+
const etag = `W/"${file.size.toString(16)}-${Option.match(file.mtime, {
|
|
41
|
+
onNone: () => "0",
|
|
42
|
+
onSome: (mtime) => mtime.getTime().toString(16)
|
|
43
|
+
})}"`;
|
|
44
|
+
const lastModified = Option.getOrUndefined(Option.map(file.mtime, (mtime) => mtime.toUTCString()));
|
|
45
|
+
const validators = {
|
|
46
|
+
"cache-control": "no-cache, no-transform",
|
|
47
|
+
etag,
|
|
48
|
+
...lastModified === undefined ? {} : { "last-modified": lastModified }
|
|
49
|
+
};
|
|
50
|
+
if (isNotModified(request, etag, lastModified))
|
|
51
|
+
return HttpServerResponse.empty({ status: 304, headers: validators });
|
|
52
|
+
const rangeHeader = request.method === "GET" ? request.headers["range"] : undefined;
|
|
53
|
+
const range = rangeHeader !== undefined && matchesIfRange(request.headers["if-range"], etag, lastModified) ? parseRange(rangeHeader, file.size) : undefined;
|
|
54
|
+
if (range === "unsatisfiable")
|
|
55
|
+
return HttpServerResponse.empty({
|
|
56
|
+
status: 416,
|
|
57
|
+
headers: { "accept-ranges": "bytes", "content-range": `bytes */${file.size}` }
|
|
58
|
+
});
|
|
59
|
+
const offset = range?.start ?? 0;
|
|
60
|
+
const length = range === undefined ? file.size : range.end - range.start + 1;
|
|
61
|
+
return HttpServerResponse.stream(length === 0 ? Stream.empty : file.stream({ offset, bytesToRead: length }), {
|
|
62
|
+
status: range === undefined ? 200 : 206,
|
|
63
|
+
contentLength: length,
|
|
64
|
+
headers: {
|
|
65
|
+
...validators,
|
|
66
|
+
"accept-ranges": "bytes",
|
|
67
|
+
"content-type": file.mime,
|
|
68
|
+
...range === undefined ? {} : { "content-range": `bytes ${range.start}-${range.end}/${file.size}` }
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function isNotModified(request, etag, lastModified) {
|
|
73
|
+
const ifNoneMatch = request.headers["if-none-match"];
|
|
74
|
+
if (ifNoneMatch !== undefined)
|
|
75
|
+
return ifNoneMatch.split(",").some((tag) => tag.trim() === "*" || stripWeak(tag) === stripWeak(etag));
|
|
76
|
+
const ifModifiedSince = request.headers["if-modified-since"];
|
|
77
|
+
return ifModifiedSince !== undefined && lastModified !== undefined && Date.parse(lastModified) <= Date.parse(ifModifiedSince);
|
|
78
|
+
}
|
|
79
|
+
function matchesIfRange(ifRange, etag, lastModified) {
|
|
80
|
+
if (ifRange === undefined)
|
|
81
|
+
return true;
|
|
82
|
+
if (/^\s*(w\/)?"/i.test(ifRange))
|
|
83
|
+
return stripWeak(ifRange) === stripWeak(etag);
|
|
84
|
+
return lastModified !== undefined && Date.parse(ifRange) === Date.parse(lastModified);
|
|
85
|
+
}
|
|
86
|
+
function stripWeak(etag) {
|
|
87
|
+
return etag.trim().replace(/^w\//i, "");
|
|
88
|
+
}
|
|
89
|
+
function parseRange(header, size) {
|
|
90
|
+
const match = /^bytes=\s*(\d*)\s*-\s*(\d*)\s*$/i.exec(header.trim());
|
|
91
|
+
if (match === null || match[1] === "" && match[2] === "")
|
|
92
|
+
return;
|
|
93
|
+
if (match[1] === "") {
|
|
94
|
+
const suffix = Number(match[2]);
|
|
95
|
+
if (suffix === 0 || size === 0)
|
|
96
|
+
return "unsatisfiable";
|
|
97
|
+
return { start: Math.max(size - suffix, 0), end: size - 1 };
|
|
98
|
+
}
|
|
99
|
+
const start = Number(match[1]);
|
|
100
|
+
const end = match[2] === "" ? size - 1 : Number(match[2]);
|
|
101
|
+
if (start > end || start >= size)
|
|
102
|
+
return "unsatisfiable";
|
|
103
|
+
return { start, end: Math.min(end, size - 1) };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { FileSystemHandler2 };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
missingSession2
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./location-smaf4a18.js";
|
|
4
4
|
|
|
5
5
|
// src/location.ts
|
|
6
6
|
import { FileSystem } from "@opencode/core/filesystem";
|
|
@@ -51,7 +51,7 @@ function decode(input) {
|
|
|
51
51
|
return input;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
var
|
|
54
|
+
var layer5 = Layer.effect(LocationMiddleware2, Effect.gen(function* () {
|
|
55
55
|
const locations = yield* LocationServiceMap.Service;
|
|
56
56
|
return LocationMiddleware2.of((effect) => Effect.gen(function* () {
|
|
57
57
|
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
@@ -59,4 +59,4 @@ var layer3 = Layer.effect(LocationMiddleware2, Effect.gen(function* () {
|
|
|
59
59
|
}));
|
|
60
60
|
}));
|
|
61
61
|
|
|
62
|
-
export { LocationMiddleware2, locationErrors2, response2, sessionInfo2, requestRef2,
|
|
62
|
+
export { LocationMiddleware2, locationErrors2, response2, sessionInfo2, requestRef2, layer5 };
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
locationErrors2,
|
|
3
|
+
response2,
|
|
4
|
+
requestRef2
|
|
5
|
+
} from "./location-f2c3fmpg.js";
|
|
4
6
|
import {
|
|
5
7
|
Api2
|
|
6
|
-
} from "./
|
|
8
|
+
} from "./location-9cw9axw5.js";
|
|
7
9
|
import {
|
|
8
10
|
CorsConfig2,
|
|
9
11
|
isAllowedRequestOrigin2
|
|
10
|
-
} from "./
|
|
12
|
+
} from "./location-q4bn6dy8.js";
|
|
11
13
|
import {
|
|
12
|
-
|
|
13
|
-
} from "./
|
|
14
|
+
Service3
|
|
15
|
+
} from "./location-0d9kah4z.js";
|
|
14
16
|
import {
|
|
15
17
|
runPtySocket2
|
|
16
|
-
} from "./
|
|
18
|
+
} from "./location-hezj1jdf.js";
|
|
17
19
|
|
|
18
20
|
// src/handlers/pty.ts
|
|
19
21
|
import { Pty } from "@opencode/core/pty";
|
|
20
22
|
import { PtyProtocol } from "@opencode/core/pty/protocol";
|
|
21
23
|
import { PtyTicket } from "@opencode/core/pty/ticket";
|
|
22
24
|
import { Location } from "@opencode/core/location";
|
|
25
|
+
import { LocationServiceMap } from "@opencode/core/location-service-map";
|
|
23
26
|
import { Effect, Queue } from "effect";
|
|
24
27
|
import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
25
28
|
import { HttpApiBuilder, HttpApiSchema } from "effect/unstable/httpapi";
|
|
@@ -35,9 +38,10 @@ var ticketScope = Effect.gen(function* () {
|
|
|
35
38
|
return { directory: location.directory, workspaceID: location.workspaceID };
|
|
36
39
|
});
|
|
37
40
|
var PtyHandler2 = HttpApiBuilder.group(Api2, "server.pty", (handlers) => Effect.gen(function* () {
|
|
41
|
+
const locations = yield* LocationServiceMap.Service;
|
|
38
42
|
const tickets = yield* PtyTicket.Service;
|
|
39
43
|
const cors = yield* CorsConfig2;
|
|
40
|
-
const environment = yield*
|
|
44
|
+
const environment = yield* Service3;
|
|
41
45
|
return handlers.handle("pty.list", Effect.fn(function* () {
|
|
42
46
|
const pty = yield* Pty.Service;
|
|
43
47
|
return yield* response2(pty.list());
|
|
@@ -87,52 +91,59 @@ var PtyHandler2 = HttpApiBuilder.group(Api2, "server.pty", (handlers) => Effect.
|
|
|
87
91
|
})));
|
|
88
92
|
return yield* response2(tickets.issue({ ptyID: ctx.params.ptyID, ...yield* ticketScope }));
|
|
89
93
|
})).handleRaw("pty.connect", Effect.fn("PtyHandler.connect")(function* (ctx) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return HttpServerResponse.empty({ status: 404 });
|
|
94
|
+
if (!isAllowedRequestOrigin2(ctx.request.headers.origin, ctx.request.headers.host, cors))
|
|
95
|
+
return HttpServerResponse.empty({ status: 403 });
|
|
96
|
+
const ref = LocationServiceMap.canonical(requestRef2(ctx.request));
|
|
94
97
|
const url = new URL(ctx.request.url, "http://localhost");
|
|
95
98
|
const ticket = url.searchParams.get(PTY_CONNECT_TICKET_QUERY);
|
|
96
|
-
if (ticket
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
99
|
+
if (ticket && !(yield* tickets.consume({
|
|
100
|
+
ticket,
|
|
101
|
+
ptyID: ctx.params.ptyID,
|
|
102
|
+
directory: ref.directory,
|
|
103
|
+
workspaceID: ref.workspaceID
|
|
104
|
+
})))
|
|
105
|
+
return HttpServerResponse.empty({ status: 403 });
|
|
106
|
+
return yield* Effect.gen(function* () {
|
|
107
|
+
const pty = yield* Pty.Service;
|
|
108
|
+
const exists = yield* pty.get(ctx.params.ptyID).pipe(Effect.as(true), Effect.catchTag("Pty.NotFoundError", () => Effect.succeed(false)));
|
|
109
|
+
if (!exists)
|
|
110
|
+
return HttpServerResponse.empty({ status: 404 });
|
|
111
|
+
const parsedCursor = url.searchParams.get("cursor");
|
|
112
|
+
const cursorNumber = parsedCursor === null ? undefined : Number(parsedCursor);
|
|
113
|
+
const cursor = cursorNumber !== undefined && Number.isSafeInteger(cursorNumber) && cursorNumber >= -1 ? cursorNumber : undefined;
|
|
114
|
+
const socket = yield* Effect.orDie(ctx.request.upgrade);
|
|
115
|
+
const write = yield* socket.writer;
|
|
116
|
+
const closeAccepted = (event) => socket.runRaw(() => Effect.void, { onOpen: write(event).pipe(Effect.catch(() => Effect.void)) }).pipe(Effect.timeout("1 second"), Effect.catchReason("SocketError", "SocketCloseError", () => Effect.void), Effect.catch(() => Effect.void));
|
|
117
|
+
const outbox = yield* Queue.unbounded();
|
|
118
|
+
const attachment = yield* pty.attach(ctx.params.ptyID, {
|
|
119
|
+
cursor,
|
|
120
|
+
onData: (chunk) => Queue.offerUnsafe(outbox, chunk),
|
|
121
|
+
onEnd: () => Queue.offerUnsafe(outbox, new Socket.CloseEvent(1000))
|
|
122
|
+
}).pipe(Effect.catchTags({
|
|
123
|
+
"Pty.NotFoundError": () => closeAccepted(new Socket.CloseEvent(4404, "session not found")).pipe(Effect.as(undefined)),
|
|
124
|
+
"Pty.ExitedError": () => closeAccepted(new Socket.CloseEvent(4404, "session exited")).pipe(Effect.as(undefined))
|
|
125
|
+
}));
|
|
126
|
+
if (!attachment)
|
|
127
|
+
return HttpServerResponse.empty();
|
|
128
|
+
for (const chunk of PtyProtocol.chunks(attachment.replay))
|
|
129
|
+
Queue.offerUnsafe(outbox, chunk);
|
|
130
|
+
Queue.offerUnsafe(outbox, PtyProtocol.metaFrame(attachment.cursor));
|
|
131
|
+
attachment.activate();
|
|
132
|
+
const drain = Effect.gen(function* () {
|
|
133
|
+
while (true) {
|
|
134
|
+
const item = yield* Queue.take(outbox);
|
|
135
|
+
yield* write(item);
|
|
136
|
+
if (item instanceof Socket.CloseEvent)
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
yield* runPtySocket2(drain, socket.runRaw((message) => {
|
|
141
|
+
const decoded = PtyProtocol.decodeInput(message);
|
|
142
|
+
if (decoded !== undefined)
|
|
143
|
+
attachment.write(decoded);
|
|
144
|
+
}), attachment.detach).pipe(Effect.catchReason("SocketError", "SocketCloseError", () => Effect.void), Effect.orDie);
|
|
117
145
|
return HttpServerResponse.empty();
|
|
118
|
-
|
|
119
|
-
Queue.offerUnsafe(outbox, chunk);
|
|
120
|
-
Queue.offerUnsafe(outbox, PtyProtocol.metaFrame(attachment.cursor));
|
|
121
|
-
attachment.activate();
|
|
122
|
-
const drain = Effect.gen(function* () {
|
|
123
|
-
while (true) {
|
|
124
|
-
const item = yield* Queue.take(outbox);
|
|
125
|
-
yield* write(item);
|
|
126
|
-
if (item instanceof Socket.CloseEvent)
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
yield* runPtySocket2(drain, socket.runRaw((message) => {
|
|
131
|
-
const decoded = PtyProtocol.decodeInput(message);
|
|
132
|
-
if (decoded !== undefined)
|
|
133
|
-
attachment.write(decoded);
|
|
134
|
-
}), attachment.detach).pipe(Effect.catchReason("SocketError", "SocketCloseError", () => Effect.void), Effect.orDie);
|
|
135
|
-
return HttpServerResponse.empty();
|
|
146
|
+
}).pipe(Effect.provide(locations.get(ref)), locationErrors2);
|
|
136
147
|
}));
|
|
137
148
|
}));
|
|
138
149
|
|
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
missingMessage2,
|
|
4
4
|
failedMessageDecode2,
|
|
5
5
|
failedSnapshot2
|
|
6
|
-
} from "./
|
|
6
|
+
} from "./location-smaf4a18.js";
|
|
7
7
|
import {
|
|
8
8
|
locationErrors2
|
|
9
|
-
} from "./
|
|
9
|
+
} from "./location-f2c3fmpg.js";
|
|
10
10
|
import {
|
|
11
11
|
Api2
|
|
12
|
-
} from "./
|
|
12
|
+
} from "./location-9cw9axw5.js";
|
|
13
13
|
|
|
14
14
|
// src/handlers/session.ts
|
|
15
15
|
import { Session } from "@opencode/core/session";
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isAllowedCorsOrigin2
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./location-q4bn6dy8.js";
|
|
4
4
|
import {
|
|
5
5
|
createRoutes2
|
|
6
|
-
} from "./
|
|
6
|
+
} from "./location-ceje7ncg.js";
|
|
7
7
|
import {
|
|
8
8
|
__export
|
|
9
|
-
} from "./
|
|
9
|
+
} from "./location-9rqn6x4v.js";
|
|
10
10
|
|
|
11
11
|
// src/fetch.ts
|
|
12
12
|
var exports_fetch = {};
|
|
13
13
|
__export(exports_fetch, {
|
|
14
14
|
ServerFetch: () => exports_fetch,
|
|
15
|
-
make: () =>
|
|
15
|
+
make: () => make3
|
|
16
16
|
});
|
|
17
17
|
import { Context, Effect, Layer } from "effect";
|
|
18
18
|
import { HttpEffect, HttpMiddleware, HttpRouter, HttpServer } from "effect/unstable/http";
|
|
19
19
|
import { SessionRestart } from "@opencode/core/session/execution/restart";
|
|
20
|
-
var
|
|
20
|
+
var make3 = Effect.fn("ServerFetch.make")(function* (options = {}, boot = {}) {
|
|
21
21
|
const context = yield* Layer.build(createRoutes2(options, () => [], boot.overrides ?? []).pipe(Layer.provide(HttpServer.layerServices)));
|
|
22
22
|
yield* Effect.forkDetach(Context.get(context, SessionRestart.Service).resumeSuspendedSessions);
|
|
23
23
|
return Context.get(context, HttpRouter.HttpRouter).asHttpEffect().pipe(HttpMiddleware.cors({ allowedOrigins: (origin) => isAllowedCorsOrigin2(origin, options), maxAge: 86400 }), HttpEffect.toWebHandlerWith(context));
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
export {
|
|
26
|
+
export { make3, exports_fetch };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
requestRef2
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./location-f2c3fmpg.js";
|
|
4
4
|
import {
|
|
5
5
|
Api2
|
|
6
|
-
} from "./
|
|
6
|
+
} from "./location-9cw9axw5.js";
|
|
7
7
|
|
|
8
8
|
// src/handlers/debug.ts
|
|
9
9
|
import { LocationServiceMap } from "@opencode/core/location-service-map";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__export
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./location-9rqn6x4v.js";
|
|
4
4
|
|
|
5
5
|
// src/pairing.ts
|
|
6
6
|
var exports_pairing = {};
|
|
7
7
|
__export(exports_pairing, {
|
|
8
8
|
ServerPairing: () => exports_pairing,
|
|
9
|
-
Service: () =>
|
|
9
|
+
Service: () => Service5,
|
|
10
10
|
node: () => node3
|
|
11
11
|
});
|
|
12
12
|
import { Cache, Context, Duration, Effect, Layer } from "effect";
|
|
@@ -14,12 +14,12 @@ import { makeGlobalNode } from "@opencode/util/effect/app-node";
|
|
|
14
14
|
import { randomBytes } from "node:crypto";
|
|
15
15
|
var TTL = Duration.minutes(5);
|
|
16
16
|
|
|
17
|
-
class
|
|
17
|
+
class Service5 extends Context.Service()("@opencode/ServerPairing") {
|
|
18
18
|
}
|
|
19
19
|
var noLookup = () => Effect.die(new Error("ServerPairing cache must be used via set/invalidateWhen, never get"));
|
|
20
|
-
var layer = Layer.effect(
|
|
20
|
+
var layer = Layer.effect(Service5, Effect.gen(function* () {
|
|
21
21
|
const cache = yield* Cache.make({ capacity: 1000, lookup: noLookup, timeToLive: TTL });
|
|
22
|
-
return
|
|
22
|
+
return Service5.of({
|
|
23
23
|
issue: Effect.fn("ServerPairing.issue")(function* () {
|
|
24
24
|
const code = randomBytes(16).toString("base64url");
|
|
25
25
|
yield* Cache.set(cache, code, true);
|
|
@@ -30,6 +30,6 @@ var layer = Layer.effect(Service3, Effect.gen(function* () {
|
|
|
30
30
|
})
|
|
31
31
|
});
|
|
32
32
|
}));
|
|
33
|
-
var node3 = makeGlobalNode({ service:
|
|
33
|
+
var node3 = makeGlobalNode({ service: Service5, layer, deps: [] });
|
|
34
34
|
|
|
35
|
-
export {
|
|
35
|
+
export { Service5, node3, exports_pairing };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Api2
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./location-9cw9axw5.js";
|
|
4
4
|
import {
|
|
5
5
|
CorsConfig2,
|
|
6
6
|
isAllowedRequestOrigin2
|
|
7
|
-
} from "./
|
|
7
|
+
} from "./location-q4bn6dy8.js";
|
|
8
8
|
import {
|
|
9
9
|
runPtySocket2
|
|
10
|
-
} from "./
|
|
10
|
+
} from "./location-hezj1jdf.js";
|
|
11
11
|
|
|
12
12
|
// src/handlers/persistent-pty.ts
|
|
13
13
|
import { PersistentPty } from "@opencode/core/persistent-pty";
|
|
@@ -64,13 +64,12 @@ var PersistentPtyHandler2 = HttpApiBuilder.group(Api2, "server.experimental", (h
|
|
|
64
64
|
yield* pty.get(ctx.params.ptyID).pipe(mapTerminalError);
|
|
65
65
|
return { data: yield* tickets.issue({ ptyID: ctx.params.ptyID }) };
|
|
66
66
|
})).handleRaw("persistentPty.connect", Effect.fn("PersistentPtyHandler.connect")(function* (ctx) {
|
|
67
|
+
if (!isAllowedRequestOrigin2(ctx.request.headers.origin, ctx.request.headers.host, cors))
|
|
68
|
+
return HttpServerResponse.empty({ status: 403 });
|
|
67
69
|
const url = new URL(ctx.request.url, "http://localhost");
|
|
68
70
|
const ticket = url.searchParams.get(PTY_CONNECT_TICKET_QUERY);
|
|
69
|
-
if (ticket
|
|
70
|
-
|
|
71
|
-
if (!valid)
|
|
72
|
-
return HttpServerResponse.empty({ status: 403 });
|
|
73
|
-
}
|
|
71
|
+
if (ticket && !(yield* tickets.consume({ ticket, ptyID: ctx.params.ptyID })))
|
|
72
|
+
return HttpServerResponse.empty({ status: 403 });
|
|
74
73
|
const cursor = Number(url.searchParams.get("cursor") ?? "0");
|
|
75
74
|
const role = url.searchParams.get("role") === "observer" ? "observer" : "controller";
|
|
76
75
|
const framedInput = url.searchParams.get("input_protocol") === "1";
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__export
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./location-9rqn6x4v.js";
|
|
4
4
|
|
|
5
5
|
// src/service-status.ts
|
|
6
6
|
var exports_service_status = {};
|
|
7
7
|
__export(exports_service_status, {
|
|
8
8
|
Status: () => exports_service_status,
|
|
9
|
-
make: () =>
|
|
9
|
+
make: () => make2
|
|
10
10
|
});
|
|
11
11
|
import { Effect, Ref } from "effect";
|
|
12
|
-
var
|
|
12
|
+
var make2 = Effect.fnUntraced(function* (options = {}) {
|
|
13
13
|
const current = yield* Ref.make(options.initial ?? { type: "starting" });
|
|
14
14
|
const beginStopping = Ref.update(current, (status) => status.type === "stopping" ? status : { type: "stopping" });
|
|
15
15
|
return {
|
|
@@ -20,4 +20,4 @@ var make3 = Effect.fnUntraced(function* (options = {}) {
|
|
|
20
20
|
};
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
export {
|
|
23
|
+
export { make2, exports_service_status };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
missingSession2
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./location-smaf4a18.js";
|
|
4
4
|
import {
|
|
5
5
|
locationErrors2,
|
|
6
6
|
response2,
|
|
7
7
|
sessionInfo2
|
|
8
|
-
} from "./
|
|
8
|
+
} from "./location-f2c3fmpg.js";
|
|
9
9
|
import {
|
|
10
10
|
Api2
|
|
11
|
-
} from "./
|
|
11
|
+
} from "./location-9cw9axw5.js";
|
|
12
12
|
|
|
13
13
|
// src/handlers/permission.ts
|
|
14
14
|
import { Instance } from "@opencode/core/instance/service";
|
package/dist/cors.js
CHANGED