@cortexkit/opencode-openai-auth 1.6.2 → 1.7.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/bin.js +6 -6
- package/dist/{codex-request-D_In8uaR.d.ts → codex-request-CN4rD2kf.d.ts} +2 -832
- package/dist/{index-z8bptbrk.js → index-0p3cbtwq.js} +2 -2
- package/dist/{index-1qxz4s8a.js → index-2e2kqmsy.js} +2 -2
- package/dist/{index-b0ty9qam.js → index-7zy4vdd3.js} +2 -2
- package/dist/{index-ge60xry3.js → index-apkavdvq.js} +2 -2
- package/dist/{index-rf0ht3gc.js → index-b5459de4.js} +2 -2
- package/dist/{index-8xq099qf.js → index-dr93b3g6.js} +2 -2
- package/dist/{index-jkpg9d1p.js → index-g08eptzm.js} +1 -1
- package/dist/{index-ya9c5e4m.js → index-jaqm1xda.js} +1 -1
- package/dist/{index-79y7w9bz.js → index-p9vnmnzr.js} +1 -1
- package/dist/{index-xpc2hm9h.js → index-qg2syg0r.js} +15 -15
- package/dist/{index-x9nffaye.js → index-r4avvxf0.js} +1 -1
- package/dist/{index-k5anexvs.js → index-se9ykks8.js} +2 -2
- package/dist/{index-7nmdsmpp.js → index-yayz83vv.js} +2 -2
- package/dist/index.d.ts +4 -79
- package/dist/index.js +1 -1
- package/dist/{model-D22uj0OB.d.ts → protocol-BeeDdtpa.d.ts} +24 -66
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.d.ts +1 -1
- package/dist/rpc/protocol.js +1 -1
- package/dist/rpc/rpc-client.d.ts +2 -12
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/rpc/rpc-dir.js +1 -1
- package/dist/rpc-client-DlR9a0_7.d.ts +13 -0
- package/dist/{sidebar-state-Bb9L9oPq.d.ts → sidebar-state-DHsZ9axt.d.ts} +1 -3
- package/dist/sidebar-state.d.ts +2 -2
- package/dist/sidebar-state.js +1 -1
- package/dist/{token-xtq3457d.js → token-511npvw8.js} +1 -1
- package/dist/token-util-jsw1zdc6.js +1 -0
- package/dist/tui-preferences.js +1 -1
- package/dist/tui.d.ts +11 -2
- package/dist/v2/server.d.ts +2 -2
- package/dist/v2/server.js +2 -2
- package/package.json +1 -1
- package/src/tui-compiled/raw/tui/v2.tsx +88 -6
- package/src/tui-compiled/raw/tui.tsx +45 -3
- package/src/tui-compiled/runtime/tui/v2.js +66 -5
- package/src/tui-compiled/runtime/tui.js +32 -3
- package/dist/protocol-CK9guiFy.d.ts +0 -29
- package/dist/token-util-nyvn9866.js +0 -1
|
@@ -2,10 +2,36 @@ import { insert as _$insert } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
|
2
2
|
import { createElement as _$createElement } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
3
3
|
/** @jsxImportSource @opentui/solid */
|
|
4
4
|
|
|
5
|
+
import { createLogger } from "../logger.js";
|
|
5
6
|
import { isNotifyPayload } from "../rpc/protocol.js";
|
|
6
7
|
import { createRpcClient } from "../rpc/rpc-client.js";
|
|
7
8
|
import { resolveRpcDir } from "../rpc/rpc-dir.js";
|
|
8
9
|
import { openControlDialog } from "./v2-dialog.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* How long one `pending` poll may take before the client gives up on it.
|
|
13
|
+
* The shared default is 2 s, which a busy OpenCode server exceeds on every
|
|
14
|
+
* poll, so a queued menu waits for a lucky fast poll. Retrying with a longer
|
|
15
|
+
* budget is safe: the server prunes only notifications at or below the
|
|
16
|
+
* client's cursor (`drainNotifications` in common-auth
|
|
17
|
+
* `src/rpc/notifications.ts`), so a reply the client never read is sent again.
|
|
18
|
+
*/
|
|
19
|
+
export const PENDING_POLL_TIMEOUT_MS = 15_000;
|
|
20
|
+
/** Consecutive failed polls before the TUI says the server is slow. */
|
|
21
|
+
export const SLOW_SERVER_POLL_FAILURES = 3;
|
|
22
|
+
/** Poll failures log at most one line per minute, no matter how fast polls fail. */
|
|
23
|
+
export const POLL_FAILURE_LOG_INTERVAL_MS = 60_000;
|
|
24
|
+
/** Toast shown once per stretch of failed polls, through the host's surface. */
|
|
25
|
+
export const SLOW_SERVER_MESSAGE = 'Waiting for the OpenAI plugin: the OpenCode server is slow.';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The error's class for poll-failure logs: never its message, which can carry
|
|
29
|
+
* the request URL with the RPC bearer token.
|
|
30
|
+
*/
|
|
31
|
+
export function pollFailureClass(error) {
|
|
32
|
+
return error instanceof Error ? error.constructor.name : typeof error;
|
|
33
|
+
}
|
|
34
|
+
const log = createLogger('rpc-tui');
|
|
9
35
|
const KEY = Symbol.for('cortexkit.openai-auth.v2.tui');
|
|
10
36
|
/** Uses OpenCode 2's transport without running the OpenCode 1 UI registration. */
|
|
11
37
|
export async function setupTui(context, options = {}) {
|
|
@@ -21,6 +47,13 @@ export async function setupTui(context, options = {}) {
|
|
|
21
47
|
let dialogOpen = false;
|
|
22
48
|
let directory = '';
|
|
23
49
|
let client;
|
|
50
|
+
// Stretches of consecutive failed polls end at the next success, which
|
|
51
|
+
// re-arms both the log line and the slow-server toast.
|
|
52
|
+
let consecutiveFailures = 0;
|
|
53
|
+
let lastPollFailureLogAt = 0;
|
|
54
|
+
const makeClient = options.createRpcClient ?? ((dir, expectedPid) => createRpcClient(dir, expectedPid));
|
|
55
|
+
const setIntervalImpl = options.setIntervalImpl ?? setInterval;
|
|
56
|
+
const clearIntervalImpl = options.clearIntervalImpl ?? clearInterval;
|
|
24
57
|
const unmount = options.sidebarText === undefined ? options.sidebar ? context.ui.slot({
|
|
25
58
|
append: 'sidebar.content',
|
|
26
59
|
render: options.sidebar.render
|
|
@@ -39,17 +72,44 @@ export async function setupTui(context, options = {}) {
|
|
|
39
72
|
const sessionId = route.sessionID;
|
|
40
73
|
const session = context.data.session.get(sessionId);
|
|
41
74
|
if (!session) return;
|
|
75
|
+
// Counts one failed poll: after a few in a row the TUI says through the
|
|
76
|
+
// host's toast that the server is slow instead of staying silent, and
|
|
77
|
+
// logs at most one line a minute with the error class only.
|
|
78
|
+
const notePollFailure = error => {
|
|
79
|
+
consecutiveFailures++;
|
|
80
|
+
const now = Date.now();
|
|
81
|
+
if (now - lastPollFailureLogAt >= POLL_FAILURE_LOG_INTERVAL_MS) {
|
|
82
|
+
lastPollFailureLogAt = now;
|
|
83
|
+
log.warn('OpenAI plugin poll failed', {
|
|
84
|
+
error: pollFailureClass(error)
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (consecutiveFailures === SLOW_SERVER_POLL_FAILURES) context.ui.toast.show({
|
|
88
|
+
message: SLOW_SERVER_MESSAGE,
|
|
89
|
+
sessionID: sessionId
|
|
90
|
+
});
|
|
91
|
+
};
|
|
42
92
|
inFlight = true;
|
|
43
93
|
try {
|
|
44
94
|
if (directory !== session.location.directory) {
|
|
45
95
|
directory = session.location.directory;
|
|
46
96
|
const resolved = await resolveRpcDir(directory);
|
|
47
97
|
if (disposed) return;
|
|
48
|
-
client =
|
|
98
|
+
client = makeClient(resolved.dir, process.pid);
|
|
49
99
|
}
|
|
50
100
|
const rpc = client;
|
|
51
101
|
if (!rpc) return;
|
|
52
|
-
const
|
|
102
|
+
const pollStartedAt = Date.now();
|
|
103
|
+
const messages = await rpc.pending(state.lastIds.get(sessionId) ?? 0, sessionId, PENDING_POLL_TIMEOUT_MS);
|
|
104
|
+
// A poll counts as failed when it throws, or when it answers empty
|
|
105
|
+
// after taking at least its own timeout: a socket timeout resolves to
|
|
106
|
+
// no messages instead of throwing, so elapsed time is the only signal
|
|
107
|
+
// a slow server leaves. A fast empty poll is a healthy idle server.
|
|
108
|
+
if (messages.length === 0 && Date.now() - pollStartedAt >= PENDING_POLL_TIMEOUT_MS) {
|
|
109
|
+
notePollFailure(new Error(`RPC pending poll timed out after ${PENDING_POLL_TIMEOUT_MS} ms`));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
consecutiveFailures = 0;
|
|
53
113
|
if (disposed || context.ui.router.current().type !== 'session' || context.ui.router.current().sessionID !== sessionId) return;
|
|
54
114
|
for (const message of [...messages].sort((a, b) => a.id - b.id)) {
|
|
55
115
|
state.lastIds.set(sessionId, Math.max(state.lastIds.get(sessionId) ?? 0, message.id));
|
|
@@ -69,20 +129,21 @@ export async function setupTui(context, options = {}) {
|
|
|
69
129
|
});
|
|
70
130
|
}
|
|
71
131
|
}
|
|
72
|
-
} catch {
|
|
132
|
+
} catch (error) {
|
|
73
133
|
// The server can be absent while a location starts or is reloaded.
|
|
134
|
+
notePollFailure(error);
|
|
74
135
|
} finally {
|
|
75
136
|
inFlight = false;
|
|
76
137
|
}
|
|
77
138
|
};
|
|
78
|
-
const timer =
|
|
139
|
+
const timer = setIntervalImpl(() => {
|
|
79
140
|
void poll();
|
|
80
141
|
}, 500);
|
|
81
142
|
const mount = {
|
|
82
143
|
dispose() {
|
|
83
144
|
if (disposed) return;
|
|
84
145
|
disposed = true;
|
|
85
|
-
|
|
146
|
+
clearIntervalImpl(timer);
|
|
86
147
|
unmount?.();
|
|
87
148
|
options.sidebar?.dispose();
|
|
88
149
|
if (dialogOpen) context.ui.dialog.clear();
|
|
@@ -17,11 +17,11 @@ import { RGBA } from "opentui:runtime-module:%40opentui%2Fcore";
|
|
|
17
17
|
import { createEffect, createMemo, createSignal, For, Index, onCleanup, Show } from "opentui:runtime-module:solid-js";
|
|
18
18
|
import { createLogger } from "./logger.js";
|
|
19
19
|
import { isNotifyPayload } from "./rpc/protocol.js";
|
|
20
|
-
import { createRpcClient } from "./rpc/rpc-client.js";
|
|
20
|
+
import { createRpcClient, DEFAULT_RPC_TIMEOUT_MS } from "./rpc/rpc-client.js";
|
|
21
21
|
import { resolveRpcDir } from "./rpc/rpc-dir.js";
|
|
22
22
|
import { accountCreditsText, accountServesOnCredits, computeQuotaPacing, DEFAULT_SIDEBAR_STATE, displayWidth, fitCollapsedLabel, getCollapsedAccountLines, getCollapsedQuotaSummary, getPresentQuotaWindows, getSidebarState, resolveActiveAccount, resolveSessionSidebarRouting, resolveSessionStickyAccount, sidebarQuotaProjection } from "./sidebar-state.js";
|
|
23
23
|
import { openCommandDialog } from "./tui/command-dialogs.js";
|
|
24
|
-
import { setupTui } from "./tui/v2.js";
|
|
24
|
+
import { POLL_FAILURE_LOG_INTERVAL_MS, pollFailureClass, SLOW_SERVER_MESSAGE, SLOW_SERVER_POLL_FAILURES, setupTui } from "./tui/v2.js";
|
|
25
25
|
import { computeEffectiveOrder, DEFAULT_SLOT_ORDER, PLUGIN_KEY, queueTuiPreferenceUpdate, readTuiPreferencesFile, resolveOpenaiAuthPrefs, watchTuiPreferences } from "./tui-preferences.js";
|
|
26
26
|
const RPC_POLL_MS = 500;
|
|
27
27
|
let rpcPollStarted = false;
|
|
@@ -1421,13 +1421,39 @@ const tui = async api => {
|
|
|
1421
1421
|
});
|
|
1422
1422
|
let lastNotificationId = 0;
|
|
1423
1423
|
let rpcInFlight = false;
|
|
1424
|
+
// A stretch of consecutive failed polls ends at the next success, which
|
|
1425
|
+
// re-arms the slow-server toast.
|
|
1426
|
+
let rpcFailures = 0;
|
|
1427
|
+
let lastRpcFailureLogAt = 0;
|
|
1428
|
+
// Counts one failed poll: a throw, or an empty answer after taking at
|
|
1429
|
+
// least the poll's own timeout (a socket timeout resolves to no messages
|
|
1430
|
+
// instead of throwing, so elapsed time is the slow server's only signal).
|
|
1431
|
+
const noteRpcPollFailure = error => {
|
|
1432
|
+
rpcFailures++;
|
|
1433
|
+
const now = Date.now();
|
|
1434
|
+
if (now - lastRpcFailureLogAt >= POLL_FAILURE_LOG_INTERVAL_MS) {
|
|
1435
|
+
lastRpcFailureLogAt = now;
|
|
1436
|
+
log.warn('OpenAI plugin poll failed', {
|
|
1437
|
+
error: pollFailureClass(error)
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
if (rpcFailures === SLOW_SERVER_POLL_FAILURES) api.ui.toast({
|
|
1441
|
+
message: SLOW_SERVER_MESSAGE
|
|
1442
|
+
});
|
|
1443
|
+
};
|
|
1424
1444
|
setInterval(() => {
|
|
1425
1445
|
if (rpcInFlight) return;
|
|
1426
1446
|
const current = api.route.current;
|
|
1427
1447
|
const resolved = typeof current === 'function' ? current() : current;
|
|
1428
1448
|
const sessionId = resolved?.params?.sessionID;
|
|
1429
1449
|
rpcInFlight = true;
|
|
1450
|
+
const pollStartedAt = Date.now();
|
|
1430
1451
|
void rpcClient.pending(lastNotificationId, sessionId).then(messages => {
|
|
1452
|
+
if (messages.length === 0 && Date.now() - pollStartedAt >= DEFAULT_RPC_TIMEOUT_MS) {
|
|
1453
|
+
noteRpcPollFailure(new Error(`RPC pending poll timed out after ${DEFAULT_RPC_TIMEOUT_MS} ms`));
|
|
1454
|
+
return;
|
|
1455
|
+
}
|
|
1456
|
+
rpcFailures = 0;
|
|
1431
1457
|
for (const message of [...messages].sort((a, b) => a.id - b.id)) {
|
|
1432
1458
|
lastNotificationId = Math.max(lastNotificationId, message.id);
|
|
1433
1459
|
const payload = message.payload;
|
|
@@ -1439,7 +1465,10 @@ const tui = async api => {
|
|
|
1439
1465
|
}
|
|
1440
1466
|
openCommandDialog(api, payload, request => rpcClient.apply(buildApplyRequest(request, sessionId), MENU_APPLY_TIMEOUT_MS));
|
|
1441
1467
|
}
|
|
1442
|
-
}).catch(
|
|
1468
|
+
}).catch(error => {
|
|
1469
|
+
// The server can be absent while a location starts or is reloaded.
|
|
1470
|
+
noteRpcPollFailure(error);
|
|
1471
|
+
}).finally(() => {
|
|
1443
1472
|
rpcInFlight = false;
|
|
1444
1473
|
});
|
|
1445
1474
|
}, RPC_POLL_MS);
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { n as CommandApplyResult, r as CommandDialogPayload, s as NotifyKind, t as CommandApplyRequest } from "./model-D22uj0OB.js";
|
|
2
|
-
//#region ../core/dist/protocol.d.ts
|
|
3
|
-
/** The menu, as the slash command opens it in the TUI. */
|
|
4
|
-
type OpenDialogPayload = CommandDialogPayload;
|
|
5
|
-
/**
|
|
6
|
-
* A message for the user from work a menu action left running (a login that
|
|
7
|
-
* finishes after the action returned).
|
|
8
|
-
*/
|
|
9
|
-
interface NotifyPayload {
|
|
10
|
-
command: string;
|
|
11
|
-
notify: {
|
|
12
|
-
message: string;
|
|
13
|
-
kind: NotifyKind;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
interface RpcNotification {
|
|
17
|
-
id: number;
|
|
18
|
-
type: 'open-dialog';
|
|
19
|
-
payload: OpenDialogPayload | NotifyPayload;
|
|
20
|
-
sessionId?: string;
|
|
21
|
-
}
|
|
22
|
-
/** One action applied from the drawer. */
|
|
23
|
-
type ApplyRequest = CommandApplyRequest;
|
|
24
|
-
/** Its message and the refreshed menu. */
|
|
25
|
-
type ApplyResult = CommandApplyResult;
|
|
26
|
-
/** Whether a pushed notification is the menu itself or a message. */
|
|
27
|
-
declare function isNotifyPayload(payload: OpenDialogPayload | NotifyPayload): payload is NotifyPayload;
|
|
28
|
-
//#endregion
|
|
29
|
-
export { RpcNotification as a, OpenDialogPayload as i, ApplyResult as n, isNotifyPayload as o, NotifyPayload as r, ApplyRequest as t };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as a}from"./index-jkpg9d1p.js";import"./index-ya9c5e4m.js";export default a();
|