@cortexkit/opencode-anthropic-auth 2.8.0 → 2.9.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/dist/cli.js +1 -1
- package/dist/index-s1efwnr3.js +45 -0
- package/dist/index.js +1 -1
- package/dist/v2/adapter.d.ts +2 -2
- package/dist/v2/server.js +9 -9
- package/package.json +2 -2
- package/src/rpc/rpc-server.ts +34 -3
- package/dist/index-m901y2pg.js +0 -45
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/opencode-anthropic-auth",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"@clack/prompts": "^1.6.0",
|
|
80
|
-
"@cortexkit/anthropic-auth-core": "2.
|
|
80
|
+
"@cortexkit/anthropic-auth-core": "2.9.0",
|
|
81
81
|
"@cortexkit/claustrum-client": "0.17.0",
|
|
82
82
|
"@cortexkit/private-files": "0.2.2",
|
|
83
83
|
"@cortexkit/subc-client": "^0.24",
|
package/src/rpc/rpc-server.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type IncomingMessage,
|
|
6
6
|
type ServerResponse,
|
|
7
7
|
} from 'node:http'
|
|
8
|
+
import type { Socket } from 'node:net'
|
|
8
9
|
import { join } from 'node:path'
|
|
9
10
|
import {
|
|
10
11
|
type CommandApplyRequest,
|
|
@@ -59,13 +60,43 @@ export async function startRpcServer(
|
|
|
59
60
|
options: RpcServerOptions,
|
|
60
61
|
): Promise<RpcServerHandle> {
|
|
61
62
|
const token = randomBytes(32).toString('hex')
|
|
63
|
+
const connections = new Set<Socket>()
|
|
64
|
+
let stopping = false
|
|
65
|
+
let closing: Promise<void> | undefined
|
|
62
66
|
const server = createServer((req, res) => {
|
|
63
67
|
void dispatch(req, res)
|
|
64
68
|
})
|
|
69
|
+
server.on('connection', (socket) => {
|
|
70
|
+
connections.add(socket)
|
|
71
|
+
socket.once('close', () => connections.delete(socket))
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
function closeServer(): Promise<void> {
|
|
75
|
+
closing ??= (async () => {
|
|
76
|
+
stopping = true
|
|
77
|
+
await new Promise<void>((resolve) => server.close(() => resolve()))
|
|
78
|
+
// Bun closes connections that were idle when close() ran, but a request
|
|
79
|
+
// active at that point can leave its keep-alive socket open after replying.
|
|
80
|
+
// Wait for the replies first, then close every remaining owned socket.
|
|
81
|
+
await Promise.all(
|
|
82
|
+
[...connections].map(
|
|
83
|
+
(socket) =>
|
|
84
|
+
new Promise<void>((resolve) => {
|
|
85
|
+
socket.once('close', () => resolve())
|
|
86
|
+
socket.destroy()
|
|
87
|
+
}),
|
|
88
|
+
),
|
|
89
|
+
)
|
|
90
|
+
})()
|
|
91
|
+
return closing
|
|
92
|
+
}
|
|
65
93
|
|
|
66
94
|
async function dispatch(req: IncomingMessage, res: ServerResponse) {
|
|
67
95
|
const json = (status: number, value: unknown) => {
|
|
68
|
-
res.writeHead(status, {
|
|
96
|
+
res.writeHead(status, {
|
|
97
|
+
'content-type': 'application/json',
|
|
98
|
+
...(stopping && { connection: 'close' }),
|
|
99
|
+
})
|
|
69
100
|
res.end(JSON.stringify(value))
|
|
70
101
|
}
|
|
71
102
|
try {
|
|
@@ -129,7 +160,7 @@ export async function startRpcServer(
|
|
|
129
160
|
try {
|
|
130
161
|
await writePortFile(options.dir, { port, token, pid: process.pid })
|
|
131
162
|
} catch (error) {
|
|
132
|
-
await
|
|
163
|
+
await closeServer()
|
|
133
164
|
throw error
|
|
134
165
|
}
|
|
135
166
|
|
|
@@ -137,7 +168,7 @@ export async function startRpcServer(
|
|
|
137
168
|
port,
|
|
138
169
|
token,
|
|
139
170
|
async stop() {
|
|
140
|
-
await
|
|
171
|
+
await closeServer()
|
|
141
172
|
try {
|
|
142
173
|
const portFile = join(options.dir, `port-${process.pid}.json`)
|
|
143
174
|
const current = JSON.parse(await readFile(portFile, 'utf8')) as {
|