feat: add ws chat attachments

This commit is contained in:
Peter Steinberger
2025-12-09 23:16:57 +01:00
parent e80e5b0801
commit 1dd5c97ae0
25 changed files with 987 additions and 882 deletions

View File

@@ -3,6 +3,10 @@ import {
type AgentEvent,
AgentEventSchema,
AgentParamsSchema,
type ChatEvent,
ChatEventSchema,
ChatHistoryParamsSchema,
ChatSendParamsSchema,
ErrorCodes,
type ErrorShape,
ErrorShapeSchema,
@@ -51,6 +55,9 @@ export const validateRequestFrame =
ajv.compile<RequestFrame>(RequestFrameSchema);
export const validateSendParams = ajv.compile(SendParamsSchema);
export const validateAgentParams = ajv.compile(AgentParamsSchema);
export const validateChatHistoryParams = ajv.compile(ChatHistoryParamsSchema);
export const validateChatSendParams = ajv.compile(ChatSendParamsSchema);
export const validateChatEvent = ajv.compile(ChatEventSchema);
export function formatValidationErrors(
errors: ErrorObject[] | null | undefined,
@@ -72,8 +79,11 @@ export {
ErrorShapeSchema,
StateVersionSchema,
AgentEventSchema,
ChatEventSchema,
SendParamsSchema,
AgentParamsSchema,
ChatHistoryParamsSchema,
ChatSendParamsSchema,
TickEventSchema,
ShutdownEventSchema,
ProtocolSchemas,
@@ -95,6 +105,7 @@ export type {
ErrorShape,
StateVersion,
AgentEvent,
ChatEvent,
TickEvent,
ShutdownEvent,
};

View File

@@ -219,6 +219,45 @@ export const AgentParamsSchema = Type.Object(
{ additionalProperties: false },
);
// WebChat/WebSocket-native chat methods
export const ChatHistoryParamsSchema = Type.Object(
{
sessionKey: NonEmptyString,
},
{ additionalProperties: false },
);
export const ChatSendParamsSchema = Type.Object(
{
sessionKey: NonEmptyString,
message: NonEmptyString,
thinking: Type.Optional(Type.String()),
deliver: Type.Optional(Type.Boolean()),
attachments: Type.Optional(Type.Array(Type.Unknown())),
timeoutMs: Type.Optional(Type.Integer({ minimum: 0 })),
idempotencyKey: NonEmptyString,
},
{ additionalProperties: false },
);
export const ChatEventSchema = Type.Object(
{
runId: NonEmptyString,
sessionKey: NonEmptyString,
seq: Type.Integer({ minimum: 0 }),
state: Type.Union([
Type.Literal("delta"),
Type.Literal("final"),
Type.Literal("error"),
]),
message: Type.Optional(Type.Unknown()),
errorMessage: Type.Optional(Type.String()),
usage: Type.Optional(Type.Unknown()),
stopReason: Type.Optional(Type.String()),
},
{ additionalProperties: false },
);
export const ProtocolSchemas: Record<string, TSchema> = {
Hello: HelloSchema,
HelloOk: HelloOkSchema,
@@ -234,6 +273,9 @@ export const ProtocolSchemas: Record<string, TSchema> = {
AgentEvent: AgentEventSchema,
SendParams: SendParamsSchema,
AgentParams: AgentParamsSchema,
ChatHistoryParams: ChatHistoryParamsSchema,
ChatSendParams: ChatSendParamsSchema,
ChatEvent: ChatEventSchema,
TickEvent: TickEventSchema,
ShutdownEvent: ShutdownEventSchema,
};
@@ -252,6 +294,7 @@ export type PresenceEntry = Static<typeof PresenceEntrySchema>;
export type ErrorShape = Static<typeof ErrorShapeSchema>;
export type StateVersion = Static<typeof StateVersionSchema>;
export type AgentEvent = Static<typeof AgentEventSchema>;
export type ChatEvent = Static<typeof ChatEventSchema>;
export type TickEvent = Static<typeof TickEventSchema>;
export type ShutdownEvent = Static<typeof ShutdownEventSchema>;