feat: expand tui gateway client
This commit is contained in:
@@ -19,7 +19,7 @@ Updated: 2026-01-03
|
|||||||
|
|
||||||
## Checklist
|
## Checklist
|
||||||
- [x] Protocol + server: sessions.patch supports model overrides; agent events include tool results (text-only payloads).
|
- [x] Protocol + server: sessions.patch supports model overrides; agent events include tool results (text-only payloads).
|
||||||
- [ ] Gateway TUI client: add session/model helpers + stricter typing.
|
- [x] Gateway TUI client: add session/model helpers + stricter typing.
|
||||||
- [ ] TUI UI kit: theme + components (editor, message feed, tool cards, selectors).
|
- [ ] TUI UI kit: theme + components (editor, message feed, tool cards, selectors).
|
||||||
- [ ] TUI controller: keybindings + Clawdis slash commands + history/stream wiring.
|
- [ ] TUI controller: keybindings + Clawdis slash commands + history/stream wiring.
|
||||||
- [ ] Docs + changelog updated for the new TUI behavior.
|
- [ ] Docs + changelog updated for the new TUI behavior.
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
import { randomUUID } from "node:crypto";
|
import { randomUUID } from "node:crypto";
|
||||||
import { loadConfig } from "../config/config.js";
|
import { loadConfig } from "../config/config.js";
|
||||||
import { GatewayClient } from "../gateway/client.js";
|
import { GatewayClient } from "../gateway/client.js";
|
||||||
import { PROTOCOL_VERSION } from "../gateway/protocol/index.js";
|
import {
|
||||||
|
type HelloOk,
|
||||||
|
PROTOCOL_VERSION,
|
||||||
|
type SessionsListParams,
|
||||||
|
type SessionsPatchParams,
|
||||||
|
} from "../gateway/protocol/index.js";
|
||||||
import { VERSION } from "../version.js";
|
import { VERSION } from "../version.js";
|
||||||
|
|
||||||
export type GatewayConnectionOptions = {
|
export type GatewayConnectionOptions = {
|
||||||
@@ -21,6 +26,24 @@ export type ChatSendOptions = {
|
|||||||
export type GatewayEvent = {
|
export type GatewayEvent = {
|
||||||
event: string;
|
event: string;
|
||||||
payload?: unknown;
|
payload?: unknown;
|
||||||
|
seq?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type GatewaySessionList = {
|
||||||
|
ts: number;
|
||||||
|
path: string;
|
||||||
|
count: number;
|
||||||
|
defaults?: { model?: string | null; contextTokens?: number | null };
|
||||||
|
sessions: Array<{
|
||||||
|
key: string;
|
||||||
|
sessionId?: string;
|
||||||
|
updatedAt?: number | null;
|
||||||
|
thinkingLevel?: string;
|
||||||
|
verboseLevel?: string;
|
||||||
|
model?: string;
|
||||||
|
contextTokens?: number | null;
|
||||||
|
displayName?: string;
|
||||||
|
}>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class GatewayChatClient {
|
export class GatewayChatClient {
|
||||||
@@ -28,6 +51,7 @@ export class GatewayChatClient {
|
|||||||
private readyPromise: Promise<void>;
|
private readyPromise: Promise<void>;
|
||||||
private resolveReady?: () => void;
|
private resolveReady?: () => void;
|
||||||
readonly connection: { url: string; token?: string; password?: string };
|
readonly connection: { url: string; token?: string; password?: string };
|
||||||
|
hello?: HelloOk;
|
||||||
|
|
||||||
onEvent?: (evt: GatewayEvent) => void;
|
onEvent?: (evt: GatewayEvent) => void;
|
||||||
onConnected?: () => void;
|
onConnected?: () => void;
|
||||||
@@ -53,12 +77,17 @@ export class GatewayChatClient {
|
|||||||
instanceId: randomUUID(),
|
instanceId: randomUUID(),
|
||||||
minProtocol: PROTOCOL_VERSION,
|
minProtocol: PROTOCOL_VERSION,
|
||||||
maxProtocol: PROTOCOL_VERSION,
|
maxProtocol: PROTOCOL_VERSION,
|
||||||
onHelloOk: () => {
|
onHelloOk: (hello) => {
|
||||||
|
this.hello = hello;
|
||||||
this.resolveReady?.();
|
this.resolveReady?.();
|
||||||
this.onConnected?.();
|
this.onConnected?.();
|
||||||
},
|
},
|
||||||
onEvent: (evt) => {
|
onEvent: (evt) => {
|
||||||
this.onEvent?.({ event: evt.event, payload: evt.payload });
|
this.onEvent?.({
|
||||||
|
event: evt.event,
|
||||||
|
payload: evt.payload,
|
||||||
|
seq: evt.seq,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
onClose: (_code, reason) => {
|
onClose: (_code, reason) => {
|
||||||
this.onDisconnected?.(reason);
|
this.onDisconnected?.(reason);
|
||||||
@@ -111,12 +140,34 @@ export class GatewayChatClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async listSessions(opts?: { limit?: number; activeMinutes?: number }) {
|
async listSessions(opts?: SessionsListParams) {
|
||||||
return await this.client.request("sessions.list", {
|
return await this.client.request<GatewaySessionList>("sessions.list", {
|
||||||
limit: opts?.limit,
|
limit: opts?.limit,
|
||||||
activeMinutes: opts?.activeMinutes,
|
activeMinutes: opts?.activeMinutes,
|
||||||
|
includeGlobal: opts?.includeGlobal,
|
||||||
|
includeUnknown: opts?.includeUnknown,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async patchSession(opts: SessionsPatchParams) {
|
||||||
|
return await this.client.request("sessions.patch", opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
async resetSession(key: string) {
|
||||||
|
return await this.client.request("sessions.reset", { key });
|
||||||
|
}
|
||||||
|
|
||||||
|
async listModels(): Promise<
|
||||||
|
Array<{
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
provider: string;
|
||||||
|
contextWindow?: number;
|
||||||
|
}>
|
||||||
|
> {
|
||||||
|
const res = await this.client.request<{ models?: unknown }>("models.list");
|
||||||
|
return Array.isArray(res?.models) ? (res.models as Array<any>) : [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveGatewayConnection(opts: GatewayConnectionOptions) {
|
export function resolveGatewayConnection(opts: GatewayConnectionOptions) {
|
||||||
|
|||||||
Reference in New Issue
Block a user