refactor(shared): dedupe protocol schema typing and session/media helpers

This commit is contained in:
Peter Steinberger
2026-03-02 15:39:18 +00:00
parent ee0d7ba6d6
commit 8768487aee
10 changed files with 224 additions and 353 deletions

View File

@@ -146,7 +146,7 @@ import {
WizardStepSchema, WizardStepSchema,
} from "./wizard.js"; } from "./wizard.js";
export const ProtocolSchemas: Record<string, TSchema> = { export const ProtocolSchemas = {
ConnectParams: ConnectParamsSchema, ConnectParams: ConnectParamsSchema,
HelloOk: HelloOkSchema, HelloOk: HelloOkSchema,
RequestFrame: RequestFrameSchema, RequestFrame: RequestFrameSchema,
@@ -272,6 +272,6 @@ export const ProtocolSchemas: Record<string, TSchema> = {
UpdateRunParams: UpdateRunParamsSchema, UpdateRunParams: UpdateRunParamsSchema,
TickEvent: TickEventSchema, TickEvent: TickEventSchema,
ShutdownEvent: ShutdownEventSchema, ShutdownEvent: ShutdownEventSchema,
}; } satisfies Record<string, TSchema>;
export const PROTOCOL_VERSION = 3 as const; export const PROTOCOL_VERSION = 3 as const;

View File

@@ -1,259 +1,124 @@
import type { Static } from "@sinclair/typebox"; import type { Static } from "@sinclair/typebox";
import type { import { ProtocolSchemas } from "./protocol-schemas.js";
AgentEventSchema,
AgentIdentityParamsSchema,
AgentIdentityResultSchema,
AgentWaitParamsSchema,
PollParamsSchema,
WakeParamsSchema,
} from "./agent.js";
import type {
AgentSummarySchema,
AgentsFileEntrySchema,
AgentsCreateParamsSchema,
AgentsCreateResultSchema,
AgentsDeleteParamsSchema,
AgentsDeleteResultSchema,
AgentsFilesGetParamsSchema,
AgentsFilesGetResultSchema,
AgentsFilesListParamsSchema,
AgentsFilesListResultSchema,
AgentsFilesSetParamsSchema,
AgentsFilesSetResultSchema,
AgentsListParamsSchema,
AgentsListResultSchema,
AgentsUpdateParamsSchema,
AgentsUpdateResultSchema,
ModelChoiceSchema,
ModelsListParamsSchema,
ModelsListResultSchema,
SkillsBinsParamsSchema,
SkillsBinsResultSchema,
SkillsInstallParamsSchema,
SkillsStatusParamsSchema,
SkillsUpdateParamsSchema,
ToolCatalogEntrySchema,
ToolCatalogGroupSchema,
ToolCatalogProfileSchema,
ToolsCatalogParamsSchema,
ToolsCatalogResultSchema,
} from "./agents-models-skills.js";
import type {
ChannelsLogoutParamsSchema,
TalkConfigParamsSchema,
TalkConfigResultSchema,
ChannelsStatusParamsSchema,
ChannelsStatusResultSchema,
TalkModeParamsSchema,
WebLoginStartParamsSchema,
WebLoginWaitParamsSchema,
} from "./channels.js";
import type {
ConfigApplyParamsSchema,
ConfigGetParamsSchema,
ConfigPatchParamsSchema,
ConfigSchemaParamsSchema,
ConfigSchemaResponseSchema,
ConfigSetParamsSchema,
UpdateRunParamsSchema,
} from "./config.js";
import type {
CronAddParamsSchema,
CronJobSchema,
CronListParamsSchema,
CronRemoveParamsSchema,
CronRunLogEntrySchema,
CronRunParamsSchema,
CronRunsParamsSchema,
CronStatusParamsSchema,
CronUpdateParamsSchema,
} from "./cron.js";
import type {
DevicePairApproveParamsSchema,
DevicePairListParamsSchema,
DevicePairRemoveParamsSchema,
DevicePairRejectParamsSchema,
DeviceTokenRevokeParamsSchema,
DeviceTokenRotateParamsSchema,
} from "./devices.js";
import type {
ExecApprovalsGetParamsSchema,
ExecApprovalsNodeGetParamsSchema,
ExecApprovalsNodeSetParamsSchema,
ExecApprovalsSetParamsSchema,
ExecApprovalsSnapshotSchema,
ExecApprovalRequestParamsSchema,
ExecApprovalResolveParamsSchema,
} from "./exec-approvals.js";
import type {
ConnectParamsSchema,
ErrorShapeSchema,
EventFrameSchema,
GatewayFrameSchema,
HelloOkSchema,
RequestFrameSchema,
ResponseFrameSchema,
ShutdownEventSchema,
TickEventSchema,
} from "./frames.js";
import type {
ChatAbortParamsSchema,
ChatEventSchema,
ChatInjectParamsSchema,
LogsTailParamsSchema,
LogsTailResultSchema,
} from "./logs-chat.js";
import type {
NodeDescribeParamsSchema,
NodeEventParamsSchema,
NodeInvokeParamsSchema,
NodeInvokeResultParamsSchema,
NodeListParamsSchema,
NodePairApproveParamsSchema,
NodePairListParamsSchema,
NodePairRejectParamsSchema,
NodePairRequestParamsSchema,
NodePairVerifyParamsSchema,
NodeRenameParamsSchema,
} from "./nodes.js";
import type { PushTestParamsSchema, PushTestResultSchema } from "./push.js";
import type {
SessionsCompactParamsSchema,
SessionsDeleteParamsSchema,
SessionsListParamsSchema,
SessionsPatchParamsSchema,
SessionsPreviewParamsSchema,
SessionsResetParamsSchema,
SessionsResolveParamsSchema,
SessionsUsageParamsSchema,
} from "./sessions.js";
import type { PresenceEntrySchema, SnapshotSchema, StateVersionSchema } from "./snapshot.js";
import type {
WizardCancelParamsSchema,
WizardNextParamsSchema,
WizardNextResultSchema,
WizardStartParamsSchema,
WizardStartResultSchema,
WizardStatusParamsSchema,
WizardStatusResultSchema,
WizardStepSchema,
} from "./wizard.js";
export type ConnectParams = Static<typeof ConnectParamsSchema>; type ProtocolSchemaName = keyof typeof ProtocolSchemas;
export type HelloOk = Static<typeof HelloOkSchema>; type SchemaType<TName extends ProtocolSchemaName> = Static<(typeof ProtocolSchemas)[TName]>;
export type RequestFrame = Static<typeof RequestFrameSchema>;
export type ResponseFrame = Static<typeof ResponseFrameSchema>; export type ConnectParams = SchemaType<"ConnectParams">;
export type EventFrame = Static<typeof EventFrameSchema>; export type HelloOk = SchemaType<"HelloOk">;
export type GatewayFrame = Static<typeof GatewayFrameSchema>; export type RequestFrame = SchemaType<"RequestFrame">;
export type Snapshot = Static<typeof SnapshotSchema>; export type ResponseFrame = SchemaType<"ResponseFrame">;
export type PresenceEntry = Static<typeof PresenceEntrySchema>; export type EventFrame = SchemaType<"EventFrame">;
export type ErrorShape = Static<typeof ErrorShapeSchema>; export type GatewayFrame = SchemaType<"GatewayFrame">;
export type StateVersion = Static<typeof StateVersionSchema>; export type Snapshot = SchemaType<"Snapshot">;
export type AgentEvent = Static<typeof AgentEventSchema>; export type PresenceEntry = SchemaType<"PresenceEntry">;
export type AgentIdentityParams = Static<typeof AgentIdentityParamsSchema>; export type ErrorShape = SchemaType<"ErrorShape">;
export type AgentIdentityResult = Static<typeof AgentIdentityResultSchema>; export type StateVersion = SchemaType<"StateVersion">;
export type PollParams = Static<typeof PollParamsSchema>; export type AgentEvent = SchemaType<"AgentEvent">;
export type AgentWaitParams = Static<typeof AgentWaitParamsSchema>; export type AgentIdentityParams = SchemaType<"AgentIdentityParams">;
export type WakeParams = Static<typeof WakeParamsSchema>; export type AgentIdentityResult = SchemaType<"AgentIdentityResult">;
export type NodePairRequestParams = Static<typeof NodePairRequestParamsSchema>; export type PollParams = SchemaType<"PollParams">;
export type NodePairListParams = Static<typeof NodePairListParamsSchema>; export type AgentWaitParams = SchemaType<"AgentWaitParams">;
export type NodePairApproveParams = Static<typeof NodePairApproveParamsSchema>; export type WakeParams = SchemaType<"WakeParams">;
export type NodePairRejectParams = Static<typeof NodePairRejectParamsSchema>; export type NodePairRequestParams = SchemaType<"NodePairRequestParams">;
export type NodePairVerifyParams = Static<typeof NodePairVerifyParamsSchema>; export type NodePairListParams = SchemaType<"NodePairListParams">;
export type NodeRenameParams = Static<typeof NodeRenameParamsSchema>; export type NodePairApproveParams = SchemaType<"NodePairApproveParams">;
export type NodeListParams = Static<typeof NodeListParamsSchema>; export type NodePairRejectParams = SchemaType<"NodePairRejectParams">;
export type NodeDescribeParams = Static<typeof NodeDescribeParamsSchema>; export type NodePairVerifyParams = SchemaType<"NodePairVerifyParams">;
export type NodeInvokeParams = Static<typeof NodeInvokeParamsSchema>; export type NodeRenameParams = SchemaType<"NodeRenameParams">;
export type NodeInvokeResultParams = Static<typeof NodeInvokeResultParamsSchema>; export type NodeListParams = SchemaType<"NodeListParams">;
export type NodeEventParams = Static<typeof NodeEventParamsSchema>; export type NodeDescribeParams = SchemaType<"NodeDescribeParams">;
export type PushTestParams = Static<typeof PushTestParamsSchema>; export type NodeInvokeParams = SchemaType<"NodeInvokeParams">;
export type PushTestResult = Static<typeof PushTestResultSchema>; export type NodeInvokeResultParams = SchemaType<"NodeInvokeResultParams">;
export type SessionsListParams = Static<typeof SessionsListParamsSchema>; export type NodeEventParams = SchemaType<"NodeEventParams">;
export type SessionsPreviewParams = Static<typeof SessionsPreviewParamsSchema>; export type PushTestParams = SchemaType<"PushTestParams">;
export type SessionsResolveParams = Static<typeof SessionsResolveParamsSchema>; export type PushTestResult = SchemaType<"PushTestResult">;
export type SessionsPatchParams = Static<typeof SessionsPatchParamsSchema>; export type SessionsListParams = SchemaType<"SessionsListParams">;
export type SessionsResetParams = Static<typeof SessionsResetParamsSchema>; export type SessionsPreviewParams = SchemaType<"SessionsPreviewParams">;
export type SessionsDeleteParams = Static<typeof SessionsDeleteParamsSchema>; export type SessionsResolveParams = SchemaType<"SessionsResolveParams">;
export type SessionsCompactParams = Static<typeof SessionsCompactParamsSchema>; export type SessionsPatchParams = SchemaType<"SessionsPatchParams">;
export type SessionsUsageParams = Static<typeof SessionsUsageParamsSchema>; export type SessionsResetParams = SchemaType<"SessionsResetParams">;
export type ConfigGetParams = Static<typeof ConfigGetParamsSchema>; export type SessionsDeleteParams = SchemaType<"SessionsDeleteParams">;
export type ConfigSetParams = Static<typeof ConfigSetParamsSchema>; export type SessionsCompactParams = SchemaType<"SessionsCompactParams">;
export type ConfigApplyParams = Static<typeof ConfigApplyParamsSchema>; export type SessionsUsageParams = SchemaType<"SessionsUsageParams">;
export type ConfigPatchParams = Static<typeof ConfigPatchParamsSchema>; export type ConfigGetParams = SchemaType<"ConfigGetParams">;
export type ConfigSchemaParams = Static<typeof ConfigSchemaParamsSchema>; export type ConfigSetParams = SchemaType<"ConfigSetParams">;
export type ConfigSchemaResponse = Static<typeof ConfigSchemaResponseSchema>; export type ConfigApplyParams = SchemaType<"ConfigApplyParams">;
export type WizardStartParams = Static<typeof WizardStartParamsSchema>; export type ConfigPatchParams = SchemaType<"ConfigPatchParams">;
export type WizardNextParams = Static<typeof WizardNextParamsSchema>; export type ConfigSchemaParams = SchemaType<"ConfigSchemaParams">;
export type WizardCancelParams = Static<typeof WizardCancelParamsSchema>; export type ConfigSchemaResponse = SchemaType<"ConfigSchemaResponse">;
export type WizardStatusParams = Static<typeof WizardStatusParamsSchema>; export type WizardStartParams = SchemaType<"WizardStartParams">;
export type WizardStep = Static<typeof WizardStepSchema>; export type WizardNextParams = SchemaType<"WizardNextParams">;
export type WizardNextResult = Static<typeof WizardNextResultSchema>; export type WizardCancelParams = SchemaType<"WizardCancelParams">;
export type WizardStartResult = Static<typeof WizardStartResultSchema>; export type WizardStatusParams = SchemaType<"WizardStatusParams">;
export type WizardStatusResult = Static<typeof WizardStatusResultSchema>; export type WizardStep = SchemaType<"WizardStep">;
export type TalkModeParams = Static<typeof TalkModeParamsSchema>; export type WizardNextResult = SchemaType<"WizardNextResult">;
export type TalkConfigParams = Static<typeof TalkConfigParamsSchema>; export type WizardStartResult = SchemaType<"WizardStartResult">;
export type TalkConfigResult = Static<typeof TalkConfigResultSchema>; export type WizardStatusResult = SchemaType<"WizardStatusResult">;
export type ChannelsStatusParams = Static<typeof ChannelsStatusParamsSchema>; export type TalkModeParams = SchemaType<"TalkModeParams">;
export type ChannelsStatusResult = Static<typeof ChannelsStatusResultSchema>; export type TalkConfigParams = SchemaType<"TalkConfigParams">;
export type ChannelsLogoutParams = Static<typeof ChannelsLogoutParamsSchema>; export type TalkConfigResult = SchemaType<"TalkConfigResult">;
export type WebLoginStartParams = Static<typeof WebLoginStartParamsSchema>; export type ChannelsStatusParams = SchemaType<"ChannelsStatusParams">;
export type WebLoginWaitParams = Static<typeof WebLoginWaitParamsSchema>; export type ChannelsStatusResult = SchemaType<"ChannelsStatusResult">;
export type AgentSummary = Static<typeof AgentSummarySchema>; export type ChannelsLogoutParams = SchemaType<"ChannelsLogoutParams">;
export type AgentsFileEntry = Static<typeof AgentsFileEntrySchema>; export type WebLoginStartParams = SchemaType<"WebLoginStartParams">;
export type AgentsCreateParams = Static<typeof AgentsCreateParamsSchema>; export type WebLoginWaitParams = SchemaType<"WebLoginWaitParams">;
export type AgentsCreateResult = Static<typeof AgentsCreateResultSchema>; export type AgentSummary = SchemaType<"AgentSummary">;
export type AgentsUpdateParams = Static<typeof AgentsUpdateParamsSchema>; export type AgentsFileEntry = SchemaType<"AgentsFileEntry">;
export type AgentsUpdateResult = Static<typeof AgentsUpdateResultSchema>; export type AgentsCreateParams = SchemaType<"AgentsCreateParams">;
export type AgentsDeleteParams = Static<typeof AgentsDeleteParamsSchema>; export type AgentsCreateResult = SchemaType<"AgentsCreateResult">;
export type AgentsDeleteResult = Static<typeof AgentsDeleteResultSchema>; export type AgentsUpdateParams = SchemaType<"AgentsUpdateParams">;
export type AgentsFilesListParams = Static<typeof AgentsFilesListParamsSchema>; export type AgentsUpdateResult = SchemaType<"AgentsUpdateResult">;
export type AgentsFilesListResult = Static<typeof AgentsFilesListResultSchema>; export type AgentsDeleteParams = SchemaType<"AgentsDeleteParams">;
export type AgentsFilesGetParams = Static<typeof AgentsFilesGetParamsSchema>; export type AgentsDeleteResult = SchemaType<"AgentsDeleteResult">;
export type AgentsFilesGetResult = Static<typeof AgentsFilesGetResultSchema>; export type AgentsFilesListParams = SchemaType<"AgentsFilesListParams">;
export type AgentsFilesSetParams = Static<typeof AgentsFilesSetParamsSchema>; export type AgentsFilesListResult = SchemaType<"AgentsFilesListResult">;
export type AgentsFilesSetResult = Static<typeof AgentsFilesSetResultSchema>; export type AgentsFilesGetParams = SchemaType<"AgentsFilesGetParams">;
export type AgentsListParams = Static<typeof AgentsListParamsSchema>; export type AgentsFilesGetResult = SchemaType<"AgentsFilesGetResult">;
export type AgentsListResult = Static<typeof AgentsListResultSchema>; export type AgentsFilesSetParams = SchemaType<"AgentsFilesSetParams">;
export type ModelChoice = Static<typeof ModelChoiceSchema>; export type AgentsFilesSetResult = SchemaType<"AgentsFilesSetResult">;
export type ModelsListParams = Static<typeof ModelsListParamsSchema>; export type AgentsListParams = SchemaType<"AgentsListParams">;
export type ModelsListResult = Static<typeof ModelsListResultSchema>; export type AgentsListResult = SchemaType<"AgentsListResult">;
export type SkillsStatusParams = Static<typeof SkillsStatusParamsSchema>; export type ModelChoice = SchemaType<"ModelChoice">;
export type ToolsCatalogParams = Static<typeof ToolsCatalogParamsSchema>; export type ModelsListParams = SchemaType<"ModelsListParams">;
export type ToolCatalogProfile = Static<typeof ToolCatalogProfileSchema>; export type ModelsListResult = SchemaType<"ModelsListResult">;
export type ToolCatalogEntry = Static<typeof ToolCatalogEntrySchema>; export type SkillsStatusParams = SchemaType<"SkillsStatusParams">;
export type ToolCatalogGroup = Static<typeof ToolCatalogGroupSchema>; export type ToolsCatalogParams = SchemaType<"ToolsCatalogParams">;
export type ToolsCatalogResult = Static<typeof ToolsCatalogResultSchema>; export type ToolCatalogProfile = SchemaType<"ToolCatalogProfile">;
export type SkillsBinsParams = Static<typeof SkillsBinsParamsSchema>; export type ToolCatalogEntry = SchemaType<"ToolCatalogEntry">;
export type SkillsBinsResult = Static<typeof SkillsBinsResultSchema>; export type ToolCatalogGroup = SchemaType<"ToolCatalogGroup">;
export type SkillsInstallParams = Static<typeof SkillsInstallParamsSchema>; export type ToolsCatalogResult = SchemaType<"ToolsCatalogResult">;
export type SkillsUpdateParams = Static<typeof SkillsUpdateParamsSchema>; export type SkillsBinsParams = SchemaType<"SkillsBinsParams">;
export type CronJob = Static<typeof CronJobSchema>; export type SkillsBinsResult = SchemaType<"SkillsBinsResult">;
export type CronListParams = Static<typeof CronListParamsSchema>; export type SkillsInstallParams = SchemaType<"SkillsInstallParams">;
export type CronStatusParams = Static<typeof CronStatusParamsSchema>; export type SkillsUpdateParams = SchemaType<"SkillsUpdateParams">;
export type CronAddParams = Static<typeof CronAddParamsSchema>; export type CronJob = SchemaType<"CronJob">;
export type CronUpdateParams = Static<typeof CronUpdateParamsSchema>; export type CronListParams = SchemaType<"CronListParams">;
export type CronRemoveParams = Static<typeof CronRemoveParamsSchema>; export type CronStatusParams = SchemaType<"CronStatusParams">;
export type CronRunParams = Static<typeof CronRunParamsSchema>; export type CronAddParams = SchemaType<"CronAddParams">;
export type CronRunsParams = Static<typeof CronRunsParamsSchema>; export type CronUpdateParams = SchemaType<"CronUpdateParams">;
export type CronRunLogEntry = Static<typeof CronRunLogEntrySchema>; export type CronRemoveParams = SchemaType<"CronRemoveParams">;
export type LogsTailParams = Static<typeof LogsTailParamsSchema>; export type CronRunParams = SchemaType<"CronRunParams">;
export type LogsTailResult = Static<typeof LogsTailResultSchema>; export type CronRunsParams = SchemaType<"CronRunsParams">;
export type ExecApprovalsGetParams = Static<typeof ExecApprovalsGetParamsSchema>; export type CronRunLogEntry = SchemaType<"CronRunLogEntry">;
export type ExecApprovalsSetParams = Static<typeof ExecApprovalsSetParamsSchema>; export type LogsTailParams = SchemaType<"LogsTailParams">;
export type ExecApprovalsNodeGetParams = Static<typeof ExecApprovalsNodeGetParamsSchema>; export type LogsTailResult = SchemaType<"LogsTailResult">;
export type ExecApprovalsNodeSetParams = Static<typeof ExecApprovalsNodeSetParamsSchema>; export type ExecApprovalsGetParams = SchemaType<"ExecApprovalsGetParams">;
export type ExecApprovalsSnapshot = Static<typeof ExecApprovalsSnapshotSchema>; export type ExecApprovalsSetParams = SchemaType<"ExecApprovalsSetParams">;
export type ExecApprovalRequestParams = Static<typeof ExecApprovalRequestParamsSchema>; export type ExecApprovalsNodeGetParams = SchemaType<"ExecApprovalsNodeGetParams">;
export type ExecApprovalResolveParams = Static<typeof ExecApprovalResolveParamsSchema>; export type ExecApprovalsNodeSetParams = SchemaType<"ExecApprovalsNodeSetParams">;
export type DevicePairListParams = Static<typeof DevicePairListParamsSchema>; export type ExecApprovalsSnapshot = SchemaType<"ExecApprovalsSnapshot">;
export type DevicePairApproveParams = Static<typeof DevicePairApproveParamsSchema>; export type ExecApprovalRequestParams = SchemaType<"ExecApprovalRequestParams">;
export type DevicePairRejectParams = Static<typeof DevicePairRejectParamsSchema>; export type ExecApprovalResolveParams = SchemaType<"ExecApprovalResolveParams">;
export type DevicePairRemoveParams = Static<typeof DevicePairRemoveParamsSchema>; export type DevicePairListParams = SchemaType<"DevicePairListParams">;
export type DeviceTokenRotateParams = Static<typeof DeviceTokenRotateParamsSchema>; export type DevicePairApproveParams = SchemaType<"DevicePairApproveParams">;
export type DeviceTokenRevokeParams = Static<typeof DeviceTokenRevokeParamsSchema>; export type DevicePairRejectParams = SchemaType<"DevicePairRejectParams">;
export type ChatAbortParams = Static<typeof ChatAbortParamsSchema>; export type DevicePairRemoveParams = SchemaType<"DevicePairRemoveParams">;
export type ChatInjectParams = Static<typeof ChatInjectParamsSchema>; export type DeviceTokenRotateParams = SchemaType<"DeviceTokenRotateParams">;
export type ChatEvent = Static<typeof ChatEventSchema>; export type DeviceTokenRevokeParams = SchemaType<"DeviceTokenRevokeParams">;
export type UpdateRunParams = Static<typeof UpdateRunParamsSchema>; export type ChatAbortParams = SchemaType<"ChatAbortParams">;
export type TickEvent = Static<typeof TickEventSchema>; export type ChatInjectParams = SchemaType<"ChatInjectParams">;
export type ShutdownEvent = Static<typeof ShutdownEventSchema>; export type ChatEvent = SchemaType<"ChatEvent">;
export type UpdateRunParams = SchemaType<"UpdateRunParams">;
export type TickEvent = SchemaType<"TickEvent">;
export type ShutdownEvent = SchemaType<"ShutdownEvent">;

View File

@@ -1,25 +1,11 @@
import type { WebSocketServer } from "ws";
import type { createSubsystemLogger } from "../logging/subsystem.js"; import type { createSubsystemLogger } from "../logging/subsystem.js";
import type { AuthRateLimiter } from "./auth-rate-limit.js";
import type { ResolvedGatewayAuth } from "./auth.js";
import type { GatewayRequestContext, GatewayRequestHandlers } from "./server-methods/types.js"; import type { GatewayRequestContext, GatewayRequestHandlers } from "./server-methods/types.js";
import { attachGatewayWsConnectionHandler } from "./server/ws-connection.js"; import {
import type { GatewayWsClient } from "./server/ws-types.js"; attachGatewayWsConnectionHandler,
type GatewayWsSharedHandlerParams,
} from "./server/ws-connection.js";
export function attachGatewayWsHandlers(params: { type GatewayWsRuntimeParams = GatewayWsSharedHandlerParams & {
wss: WebSocketServer;
clients: Set<GatewayWsClient>;
port: number;
gatewayHost?: string;
canvasHostEnabled: boolean;
canvasHostServerPort?: number;
resolvedAuth: ResolvedGatewayAuth;
/** Optional rate limiter for auth brute-force protection. */
rateLimiter?: AuthRateLimiter;
/** Browser-origin fallback limiter (loopback is never exempt). */
browserRateLimiter?: AuthRateLimiter;
gatewayMethods: string[];
events: string[];
logGateway: ReturnType<typeof createSubsystemLogger>; logGateway: ReturnType<typeof createSubsystemLogger>;
logHealth: ReturnType<typeof createSubsystemLogger>; logHealth: ReturnType<typeof createSubsystemLogger>;
logWsControl: ReturnType<typeof createSubsystemLogger>; logWsControl: ReturnType<typeof createSubsystemLogger>;
@@ -33,7 +19,9 @@ export function attachGatewayWsHandlers(params: {
}, },
) => void; ) => void;
context: GatewayRequestContext; context: GatewayRequestContext;
}) { };
export function attachGatewayWsHandlers(params: GatewayWsRuntimeParams) {
attachGatewayWsConnectionHandler({ attachGatewayWsConnectionHandler({
wss: params.wss, wss: params.wss,
clients: params.clients, clients: params.clients,

View File

@@ -58,7 +58,7 @@ const sanitizeLogValue = (value: string | undefined): string | undefined => {
return truncateUtf16Safe(cleaned, LOG_HEADER_MAX_LEN); return truncateUtf16Safe(cleaned, LOG_HEADER_MAX_LEN);
}; };
export function attachGatewayWsConnectionHandler(params: { export type GatewayWsSharedHandlerParams = {
wss: WebSocketServer; wss: WebSocketServer;
clients: Set<GatewayWsClient>; clients: Set<GatewayWsClient>;
port: number; port: number;
@@ -72,6 +72,9 @@ export function attachGatewayWsConnectionHandler(params: {
browserRateLimiter?: AuthRateLimiter; browserRateLimiter?: AuthRateLimiter;
gatewayMethods: string[]; gatewayMethods: string[];
events: string[]; events: string[];
};
export type AttachGatewayWsConnectionHandlerParams = GatewayWsSharedHandlerParams & {
logGateway: SubsystemLogger; logGateway: SubsystemLogger;
logHealth: SubsystemLogger; logHealth: SubsystemLogger;
logWsControl: SubsystemLogger; logWsControl: SubsystemLogger;
@@ -85,7 +88,9 @@ export function attachGatewayWsConnectionHandler(params: {
}, },
) => void; ) => void;
buildRequestContext: () => GatewayRequestContext; buildRequestContext: () => GatewayRequestContext;
}) { };
export function attachGatewayWsConnectionHandler(params: AttachGatewayWsConnectionHandlerParams) {
const { const {
wss, wss,
clients, clients,

View File

@@ -1,5 +1,10 @@
import type { ChatType } from "../channels/chat-type.js"; import type { ChatType } from "../channels/chat-type.js";
import type { SessionEntry } from "../config/sessions.js"; import type { SessionEntry } from "../config/sessions.js";
import type {
GatewayAgentRow as SharedGatewayAgentRow,
SessionsListResultBase,
SessionsPatchResultBase,
} from "../shared/session-types.js";
import type { DeliveryContext } from "../utils/delivery-context.js"; import type { DeliveryContext } from "../utils/delivery-context.js";
export type GatewaySessionsDefaults = { export type GatewaySessionsDefaults = {
@@ -44,17 +49,7 @@ export type GatewaySessionRow = {
lastAccountId?: string; lastAccountId?: string;
}; };
export type GatewayAgentRow = { export type GatewayAgentRow = SharedGatewayAgentRow;
id: string;
name?: string;
identity?: {
name?: string;
theme?: string;
emoji?: string;
avatar?: string;
avatarUrl?: string;
};
};
export type SessionPreviewItem = { export type SessionPreviewItem = {
role: "user" | "assistant" | "tool" | "system" | "other"; role: "user" | "assistant" | "tool" | "system" | "other";
@@ -72,18 +67,9 @@ export type SessionsPreviewResult = {
previews: SessionsPreviewEntry[]; previews: SessionsPreviewEntry[];
}; };
export type SessionsListResult = { export type SessionsListResult = SessionsListResultBase<GatewaySessionsDefaults, GatewaySessionRow>;
ts: number;
path: string;
count: number;
defaults: GatewaySessionsDefaults;
sessions: GatewaySessionRow[];
};
export type SessionsPatchResult = { export type SessionsPatchResult = SessionsPatchResultBase<SessionEntry> & {
ok: true;
path: string;
key: string;
entry: SessionEntry; entry: SessionEntry;
resolved?: { resolved?: {
modelProvider?: string; modelProvider?: string;

View File

@@ -1,6 +1,6 @@
import { normalizeGoogleModelId } from "../../../agents/models-config.providers.js"; import { normalizeGoogleModelId } from "../../../agents/models-config.providers.js";
import { parseGeminiAuth } from "../../../infra/gemini-auth.js"; import { parseGeminiAuth } from "../../../infra/gemini-auth.js";
import { assertOkOrThrowHttpError, fetchWithTimeoutGuarded, normalizeBaseUrl } from "../shared.js"; import { assertOkOrThrowHttpError, normalizeBaseUrl, postJsonRequest } from "../shared.js";
export async function generateGeminiInlineDataText(params: { export async function generateGeminiInlineDataText(params: {
buffer: Buffer; buffer: Buffer;
@@ -61,17 +61,14 @@ export async function generateGeminiInlineDataText(params: {
], ],
}; };
const { response: res, release } = await fetchWithTimeoutGuarded( const { response: res, release } = await postJsonRequest({
url, url,
{ headers,
method: "POST", body,
headers, timeoutMs: params.timeoutMs,
body: JSON.stringify(body),
},
params.timeoutMs,
fetchFn, fetchFn,
allowPrivate ? { ssrfPolicy: { allowPrivateNetwork: true } } : undefined, allowPrivateNetwork: allowPrivate,
); });
try { try {
await assertOkOrThrowHttpError(res, params.httpErrorLabel); await assertOkOrThrowHttpError(res, params.httpErrorLabel);

View File

@@ -1,5 +1,5 @@
import type { VideoDescriptionRequest, VideoDescriptionResult } from "../../types.js"; import type { VideoDescriptionRequest, VideoDescriptionResult } from "../../types.js";
import { assertOkOrThrowHttpError, fetchWithTimeoutGuarded, normalizeBaseUrl } from "../shared.js"; import { assertOkOrThrowHttpError, normalizeBaseUrl, postJsonRequest } from "../shared.js";
export const DEFAULT_MOONSHOT_VIDEO_BASE_URL = "https://api.moonshot.ai/v1"; export const DEFAULT_MOONSHOT_VIDEO_BASE_URL = "https://api.moonshot.ai/v1";
const DEFAULT_MOONSHOT_VIDEO_MODEL = "kimi-k2.5"; const DEFAULT_MOONSHOT_VIDEO_MODEL = "kimi-k2.5";
@@ -84,16 +84,13 @@ export async function describeMoonshotVideo(
], ],
}; };
const { response: res, release } = await fetchWithTimeoutGuarded( const { response: res, release } = await postJsonRequest({
url, url,
{ headers,
method: "POST", body,
headers, timeoutMs: params.timeoutMs,
body: JSON.stringify(body),
},
params.timeoutMs,
fetchFn, fetchFn,
); });
try { try {
await assertOkOrThrowHttpError(res, "Moonshot video description failed"); await assertOkOrThrowHttpError(res, "Moonshot video description failed");

View File

@@ -53,6 +53,27 @@ export async function postTranscriptionRequest(params: {
); );
} }
export async function postJsonRequest(params: {
url: string;
headers: Headers;
body: unknown;
timeoutMs: number;
fetchFn: typeof fetch;
allowPrivateNetwork?: boolean;
}) {
return fetchWithTimeoutGuarded(
params.url,
{
method: "POST",
headers: params.headers,
body: JSON.stringify(params.body),
},
params.timeoutMs,
params.fetchFn,
params.allowPrivateNetwork ? { ssrfPolicy: { allowPrivateNetwork: true } } : undefined,
);
}
export async function readErrorResponse(res: Response): Promise<string | undefined> { export async function readErrorResponse(res: Response): Promise<string | undefined> {
try { try {
const text = await res.text(); const text = await res.text();

View File

@@ -0,0 +1,28 @@
export type GatewayAgentIdentity = {
name?: string;
theme?: string;
emoji?: string;
avatar?: string;
avatarUrl?: string;
};
export type GatewayAgentRow = {
id: string;
name?: string;
identity?: GatewayAgentIdentity;
};
export type SessionsListResultBase<TDefaults, TRow> = {
ts: number;
path: string;
count: number;
defaults: TDefaults;
sessions: TRow[];
};
export type SessionsPatchResultBase<TEntry> = {
ok: true;
path: string;
key: string;
entry: TEntry;
};

View File

@@ -1,5 +1,10 @@
export type UpdateAvailable = import("../../../src/infra/update-startup.js").UpdateAvailable; export type UpdateAvailable = import("../../../src/infra/update-startup.js").UpdateAvailable;
import type { ConfigUiHints } from "../../../src/shared/config-ui-hints-types.js"; import type { ConfigUiHints } from "../../../src/shared/config-ui-hints-types.js";
import type {
GatewayAgentRow as SharedGatewayAgentRow,
SessionsListResultBase,
SessionsPatchResultBase,
} from "../../../src/shared/session-types.js";
export type { ConfigUiHints } from "../../../src/shared/config-ui-hints-types.js"; export type { ConfigUiHints } from "../../../src/shared/config-ui-hints-types.js";
export type ChannelsStatusSnapshot = { export type ChannelsStatusSnapshot = {
@@ -314,17 +319,7 @@ export type GatewaySessionsDefaults = {
contextTokens: number | null; contextTokens: number | null;
}; };
export type GatewayAgentRow = { export type GatewayAgentRow = SharedGatewayAgentRow;
id: string;
name?: string;
identity?: {
name?: string;
theme?: string;
emoji?: string;
avatar?: string;
avatarUrl?: string;
};
};
export type AgentsListResult = { export type AgentsListResult = {
defaultId: string; defaultId: string;
@@ -422,27 +417,16 @@ export type GatewaySessionRow = {
contextTokens?: number; contextTokens?: number;
}; };
export type SessionsListResult = { export type SessionsListResult = SessionsListResultBase<GatewaySessionsDefaults, GatewaySessionRow>;
ts: number;
path: string;
count: number;
defaults: GatewaySessionsDefaults;
sessions: GatewaySessionRow[];
};
export type SessionsPatchResult = { export type SessionsPatchResult = SessionsPatchResultBase<{
ok: true; sessionId: string;
path: string; updatedAt?: number;
key: string; thinkingLevel?: string;
entry: { verboseLevel?: string;
sessionId: string; reasoningLevel?: string;
updatedAt?: number; elevatedLevel?: string;
thinkingLevel?: string; }>;
verboseLevel?: string;
reasoningLevel?: string;
elevatedLevel?: string;
};
};
export type { export type {
CostUsageDailyEntry, CostUsageDailyEntry,