openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
661 lines (660 loc) • 24.9 kB
JavaScript
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs";
import { r as truncateUtf16Safe } from "./utf16-slice-CuDyEXgS.mjs";
import { t as closedObject } from "./closed-object-B-B1FwhS.mjs";
import { t as stringLiteralUnion } from "./string-literal-union-C2qFTHSZ.mjs";
import { a as NonEmptyString, i as InputProvenanceSchema, t as ChatSendSessionKeyString } from "./primitives-C8sb4NEJ.mjs";
import { c as SessionPermissionModeSchema, f as SessionToolOverridesSchema, m as SessionVisibilitySchema } from "./sessions-row--OlDxAaX.mjs";
import { n as CHAT_WORK_CONTEXT_LIMITS, t as CHAT_WORK_CONTEXT_DETAIL_LIMITS } from "./chat-work-context-Cl_nCvJH.mjs";
import { n as CHAT_MESSAGE_MAX_CHARS, t as CHAT_HISTORY_MAX_ENTRIES } from "./chat-history-constants-BGgHv5E_.mjs";
import { Type } from "typebox";
//#region packages/gateway-protocol/src/human-mention-limits.ts
const MAX_HUMAN_MENTIONS = 10;
const MAX_MENTIONABLE_USERS = 100;
const MENTION_INBOX_MAX_ITEMS = 100;
//#endregion
//#region packages/gateway-protocol/src/schema/human-mentions.ts
const MentionReferenceSchema = Type.String({
minLength: 1,
maxLength: 256
});
const MentionLabelSchema = Type.String({
minLength: 1,
maxLength: 256
});
const MentionSessionKeySchema = Type.String({
minLength: 1,
maxLength: 512
});
const MentionAvatarUrlSchema = Type.String({
minLength: 1,
maxLength: 2048
});
const MentionTimestampSchema = Type.Integer({
minimum: 0,
maximum: Number.MAX_SAFE_INTEGER
});
/** Explicit selections bound to UTF-16 offsets in the submitted message text. */
const HumanMentionSchema = closedObject({
profileId: MentionReferenceSchema,
start: Type.Integer({
minimum: 0,
maximum: Number.MAX_SAFE_INTEGER
}),
end: Type.Integer({
minimum: 1,
maximum: Number.MAX_SAFE_INTEGER
})
});
const HumanMentionsSchema = Type.Array(HumanMentionSchema, { maxItems: 10 });
const UsersMentionableParamsSchema = Type.Union([closedObject({
sessionKey: MentionSessionKeySchema,
agentId: Type.Optional(MentionReferenceSchema),
query: Type.Optional(Type.String({ maxLength: 128 }))
}), closedObject({
agentId: MentionReferenceSchema,
visibility: Type.Optional(SessionVisibilitySchema),
query: Type.Optional(Type.String({ maxLength: 128 }))
})]);
const MentionableUserSchema = closedObject({
profileId: MentionReferenceSchema,
displayName: MentionLabelSchema,
avatarUrl: Type.Optional(MentionAvatarUrlSchema),
online: Type.Boolean()
});
const UsersMentionableResultSchema = closedObject({
users: Type.Array(MentionableUserSchema, { maxItems: 100 }),
truncated: Type.Boolean()
});
const MentionInboxItemSchema = closedObject({
id: MentionReferenceSchema,
senderProfileId: MentionReferenceSchema,
senderLabel: MentionLabelSchema,
senderAvatarUrl: Type.Optional(MentionAvatarUrlSchema),
sessionKey: MentionSessionKeySchema,
agentId: MentionReferenceSchema,
sessionTitle: MentionLabelSchema,
messageId: MentionReferenceSchema,
createdAt: MentionTimestampSchema,
expiresAt: MentionTimestampSchema,
excerpt: Type.Optional(Type.String({ maxLength: 280 }))
});
const MentionsListParamsSchema = closedObject({});
const MentionsDismissParamsSchema = closedObject({ ids: Type.Array(MentionReferenceSchema, {
maxItems: 100,
uniqueItems: true
}) });
const MentionInboxVersionProperties = {
gatewayInstanceId: MentionReferenceSchema,
revision: Type.Integer({
minimum: 0,
maximum: Number.MAX_SAFE_INTEGER
})
};
const MentionsListResultSchema = closedObject({
...MentionInboxVersionProperties,
items: Type.Array(MentionInboxItemSchema, { maxItems: 100 })
});
const MentionsChangedEventSchema = closedObject(MentionInboxVersionProperties);
const MentionsFailedEventSchema = closedObject({
gatewayInstanceId: MentionReferenceSchema,
sessionKey: MentionSessionKeySchema,
agentId: MentionReferenceSchema,
messageId: MentionReferenceSchema,
errorMessage: Type.String({
minLength: 1,
maxLength: 512
})
});
//#endregion
//#region packages/gateway-protocol/src/schema/logs-chat.ts
/** Cursor-based request for the gateway log tail endpoint. */
const LogsTailParamsSchema = closedObject({
cursor: Type.Optional(Type.Integer({ minimum: 0 })),
limit: Type.Optional(Type.Integer({
minimum: 1,
maximum: 5e3
})),
maxBytes: Type.Optional(Type.Integer({
minimum: 1,
maximum: 1e6
}))
});
/** Gateway log tail payload returned to dashboard clients. */
const LogsTailResultSchema = closedObject({
file: NonEmptyString,
cursor: Type.Integer({ minimum: 0 }),
size: Type.Integer({ minimum: 0 }),
lines: Type.Array(Type.String()),
truncated: Type.Optional(Type.Boolean()),
reset: Type.Optional(Type.Boolean()),
skippedBytes: Type.Optional(Type.Integer({ minimum: 0 }))
});
/** Session-scoped history request used by WebChat and native WebSocket clients. */
const ChatHistoryParamsSchema = closedObject({
sessionKey: NonEmptyString,
agentId: Type.Optional(NonEmptyString),
cursor: Type.Optional(Type.String()),
knownState: Type.Optional(closedObject({
pendingInputs: Type.Optional(Type.String({
minLength: 1,
maxLength: 64
})),
sessionInfo: Type.Optional(Type.String({
minLength: 1,
maxLength: 64
})),
commands: Type.Optional(Type.String({
minLength: 1,
maxLength: 64
}))
})),
limit: Type.Optional(Type.Integer({
minimum: 1,
maximum: CHAT_HISTORY_MAX_ENTRIES
})),
maxBytes: Type.Optional(Type.Integer({ minimum: 1024 })),
offset: Type.Optional(Type.Integer({ minimum: 0 })),
pendingBefore: Type.Optional(Type.Integer({ minimum: 1 })),
inputRunIds: Type.Optional(Type.Array(Type.String({
minLength: 1,
maxLength: 256
}), {
minItems: 1,
maxItems: 50,
uniqueItems: true
})),
messageId: Type.Optional(NonEmptyString),
sessionId: Type.Optional(NonEmptyString),
maxChars: Type.Optional(Type.Integer({
minimum: 1,
maximum: 5e5
})),
toolResultMaxChars: Type.Optional(Type.Integer({
minimum: 1,
maximum: 5e5
}))
});
/** Resolve a short chat link and fetch its first page under the same discovery policy. */
const ChatStartupParamsSchema = Type.Union([ChatHistoryParamsSchema, closedObject({
shortId: NonEmptyString,
slugHint: Type.Optional(NonEmptyString),
agentId: NonEmptyString,
limit: ChatHistoryParamsSchema.properties.limit,
maxBytes: ChatHistoryParamsSchema.properties.maxBytes,
toolResultMaxChars: ChatHistoryParamsSchema.properties.toolResultMaxChars
})]);
/** Accepted input awaiting a turn, separate from canonical model history. */
const ChatPendingInputsPageSchema = closedObject({
items: Type.Array(closedObject({
id: NonEmptyString,
runId: Type.Optional(Type.String({
minLength: 1,
maxLength: 256
})),
message: Type.Unknown(),
acceptedAt: Type.Number(),
state: Type.String({ enum: [
"queued",
"cancelled",
"interrupted"
] }),
queued: Type.Optional(Type.Literal(true))
}), { maxItems: 20 }),
total: Type.Integer({ minimum: 0 }),
queuedCount: Type.Optional(Type.Integer({ minimum: 0 })),
nextBefore: Type.Optional(Type.Integer({ minimum: 1 }))
});
/** Exact accepted-input custody, independent of display pagination and message identity. */
const ChatInputReceiptsSchema = Type.Array(Type.Union([closedObject({
runId: Type.String({
minLength: 1,
maxLength: 256
}),
state: Type.Literal("pending"),
queued: Type.Optional(Type.Literal(true)),
cancelled: Type.Optional(Type.Literal(true))
}), closedObject({
runId: Type.String({
minLength: 1,
maxLength: 256
}),
state: Type.Literal("consumed"),
consumedByEventId: NonEmptyString
})]), { maxItems: 50 });
/** Consumed-only compatibility projection for existing v4 clients. */
const ChatInputConsumptionsSchema = Type.Array(closedObject({
runId: Type.String({
minLength: 1,
maxLength: 256
}),
consumedByEventId: NonEmptyString
}), { maxItems: 50 });
/** Legacy persisted activity receipts; retained so existing history still validates. */
const AgentActivityDelegationSchema = closedObject({
runId: Type.String({
minLength: 1,
maxLength: 256
}),
childSessionKey: Type.String({
minLength: 1,
maxLength: 1024
}),
label: Type.Optional(Type.String({
minLength: 1,
maxLength: 512
})),
groupId: Type.Optional(Type.String({
minLength: 1,
maxLength: 512
})),
runtimeMs: Type.Optional(Type.Number({
minimum: 0,
maximum: Number.MAX_SAFE_INTEGER
})),
status: stringLiteralUnion([
"accepted",
"done",
"failed",
"killed",
"timeout"
])
});
const AgentActivityItemSchema = closedObject({
delegation: Type.Optional(Type.Array(AgentActivityDelegationSchema, { maxItems: 32 })),
itemId: NonEmptyString,
phase: stringLiteralUnion([
"start",
"update",
"end"
]),
kind: Type.String(),
title: Type.String(),
status: Type.Optional(stringLiteralUnion([
"running",
"completed",
"failed",
"blocked",
"skipped"
])),
name: Type.Optional(Type.String()),
meta: Type.Optional(Type.String()),
commandBearing: Type.Optional(Type.Boolean()),
toolCallId: Type.Optional(Type.String()),
unpairedCall: Type.Optional(Type.Boolean()),
startedAt: Type.Optional(Type.Number()),
endedAt: Type.Optional(Type.Number()),
error: Type.Optional(Type.String()),
summary: Type.Optional(Type.String()),
progressText: Type.Optional(Type.String()),
suppressChannelProgress: Type.Optional(Type.Boolean()),
hideFromChannelProgress: Type.Optional(Type.Boolean()),
approvalId: Type.Optional(Type.String()),
approvalSlug: Type.Optional(Type.String())
});
const ChatHistoryActivitySchema = closedObject({
messageId: NonEmptyString,
items: Type.Array(AgentActivityItemSchema)
});
/**
* Bounded forward catch-up response. Clients replay `messages` as `session.message`
* payloads. There is no continuation loop: more than 200 raw events or the byte
* budget returns `reset`, and the client fetches a fresh tail page.
*/
const ChatHistoryDeltaResultSchema = closedObject({
kind: Type.Literal("delta"),
messages: Type.Array(Type.Unknown()),
activity: Type.Optional(Type.Array(ChatHistoryActivitySchema)),
deltaCursor: Type.String(),
sessionInfo: Type.Optional(Type.Unknown()),
sessionInfoSnapshotAt: Type.Optional(Type.Number()),
stateRevision: Type.Optional(ChatHistoryParamsSchema.properties.knownState),
agentsList: Type.Optional(Type.Unknown()),
inFlightRun: Type.Optional(Type.Unknown()),
metadata: Type.Optional(Type.Unknown()),
pendingInputs: Type.Optional(ChatPendingInputsPageSchema),
inputReceipts: Type.Optional(ChatInputReceiptsSchema),
inputConsumptions: Type.Optional(ChatInputConsumptionsSchema)
});
/** Normal cursor discontinuity; clients recover with a fresh tail request. */
const ChatHistoryResetResultSchema = closedObject({ kind: Type.Literal("reset") });
/** Closed cursor outcome union. */
const ChatHistoryCursorResultSchema = Type.Union([ChatHistoryDeltaResultSchema, ChatHistoryResetResultSchema]);
/** Lightweight metadata; session scope preserves the persisted auth-profile selection. */
const ChatMetadataParamsSchema = Object.assign(closedObject({
agentId: Type.Optional(NonEmptyString),
includeModels: Type.Optional(Type.Boolean({ description: "Include model and account selection metadata (default true). Set false when reading models.list separately." })),
ifRevision: Type.Optional(Type.String({
minLength: 1,
description: "For includeModels:false, omit unchanged commands."
})),
authProfileId: Type.Optional(Type.String({
minLength: 1,
maxLength: 256,
description: "Preview your own saved model account for a new chat without changing defaults. Cannot be combined with sessionKey."
})),
sessionKey: Type.Optional(Type.String({
minLength: 1,
description: "Read the authorized session's persisted auth-profile selection instead of neutral agent metadata."
}))
}), { not: { required: ["sessionKey", "authProfileId"] } });
/** Transient composer prediction anchored to a completed session run. */
const ChatPredictParamsSchema = closedObject({
sessionKey: NonEmptyString,
runId: NonEmptyString
});
/** Transient composer text only; null means there is no suggestion. */
const ChatPredictResultSchema = closedObject({ text: Type.Union([Type.String({ maxLength: 500 }), Type.Null()]) });
/** Dismiss displayed pending inputs that ended interrupted or cancelled. */
const ChatPendingInputsDismissParamsSchema = closedObject({
sessionKey: NonEmptyString,
agentId: Type.Optional(NonEmptyString),
sessionId: NonEmptyString,
inputIds: Type.Array(NonEmptyString, {
minItems: 1,
maxItems: 100,
uniqueItems: true
})
});
const ChatPendingInputsDismissResultSchema = closedObject({
dismissedIds: Type.Array(NonEmptyString, { maxItems: 100 }),
runIds: Type.Array(Type.String({
minLength: 1,
maxLength: 256
}), { maxItems: 100 }),
missingIds: Type.Array(NonEmptyString, { maxItems: 100 })
});
/** Batched purpose-title request for tool calls rendered in the Control UI. */
const ChatToolTitlesParamsSchema = closedObject({
sessionKey: NonEmptyString,
agentId: Type.Optional(NonEmptyString),
items: Type.Array(closedObject({
id: Type.String({
minLength: 1,
maxLength: 64
}),
name: Type.String({
minLength: 1,
maxLength: 200
}),
input: Type.String({
minLength: 1,
maxLength: 4e3
})
}), {
minItems: 1,
maxItems: 24
})
});
/**
* Titles keyed by the caller-provided item id; missing ids mean no title.
* `disabled: true` tells clients the gateway has tool titles switched off so
* they stop requesting for the rest of the session.
*/
const ChatToolTitlesResultSchema = closedObject({
titles: Type.Record(Type.String(), Type.String()),
disabled: Type.Optional(Type.Boolean())
});
/** Fetches one stored chat message without forcing history callers to request huge payloads. */
const ChatMessageGetParamsSchema = closedObject({
sessionKey: NonEmptyString,
agentId: Type.Optional(NonEmptyString),
sessionId: Type.Optional(NonEmptyString),
messageId: NonEmptyString,
maxChars: Type.Optional(Type.Integer({
minimum: 1,
maximum: CHAT_MESSAGE_MAX_CHARS
}))
});
/**
* Single-message lookup result. History messages also carry this envelope as
* `__openclaw.replyToMessage`: a display preview capped at 500 chars per field
* and 8 KiB, or an unavailable reason. It never changes the persisted transcript.
*/
const ChatMessageGetResultSchema = closedObject({
ok: Type.Boolean(),
message: Type.Optional(Type.Unknown()),
unavailableReason: Type.Optional(stringLiteralUnion([
"not_found",
"oversized",
"not_visible"
]))
});
/** Permissive attachment envelope shared by chat and session entrypoints. */
const ChatAttachmentSchema = Type.Object({
type: Type.Optional(Type.String()),
mimeType: Type.Optional(Type.String()),
fileName: Type.Optional(Type.String()),
origin: Type.Optional(stringLiteralUnion(["paste", "file"])),
content: Type.Optional(Type.Unknown()),
sizeBytes: Type.Optional(Type.Number()),
durationMs: Type.Optional(Type.Number()),
width: Type.Optional(Type.Number()),
height: Type.Optional(Type.Number())
}, { additionalProperties: true });
/** Attachment list shared by chat.send and session creation's initial turn. */
const ChatAttachmentsSchema = Type.Array(ChatAttachmentSchema);
/** Opaque, out-of-band plugin bindings carried separately from model input. */
const RunToolBindingsSchema = Type.Record(Type.String({
minLength: 1,
maxLength: 128
}), Type.Unknown(), { maxProperties: 16 });
const QUEUE_MODES = [
"steer",
"followup",
"collect",
"interrupt"
];
const ChatSendIntentSchema = closedObject({
kind: Type.Literal("session-goal-start"),
version: Type.Literal(1),
issuedAtMs: Type.Integer({ minimum: 0 })
});
const ChatWorkContextSchema = closedObject({
page: Type.String({
minLength: 1,
maxLength: CHAT_WORK_CONTEXT_LIMITS.page
}),
title: Type.Optional(Type.String({ maxLength: CHAT_WORK_CONTEXT_LIMITS.title })),
sessionKey: Type.Optional(Type.String({ maxLength: CHAT_WORK_CONTEXT_LIMITS.sessionKey })),
sessionId: Type.Optional(Type.String({ maxLength: CHAT_WORK_CONTEXT_LIMITS.sessionId })),
agentId: Type.Optional(Type.String({ maxLength: CHAT_WORK_CONTEXT_LIMITS.agentId })),
workspace: Type.Optional(Type.String({ maxLength: CHAT_WORK_CONTEXT_LIMITS.workspace })),
file: Type.Optional(Type.String({ maxLength: CHAT_WORK_CONTEXT_LIMITS.file })),
selection: Type.Optional(Type.String({ maxLength: CHAT_WORK_CONTEXT_LIMITS.selection })),
detail: Type.Optional(Type.Record(Type.String({ pattern: "^[\\s\\S]*$" }), Type.String({ maxLength: CHAT_WORK_CONTEXT_DETAIL_LIMITS.value }), {
maxProperties: CHAT_WORK_CONTEXT_DETAIL_LIMITS.fields,
propertyNames: Type.String({
minLength: 1,
maxLength: CHAT_WORK_CONTEXT_DETAIL_LIMITS.key
})
}))
});
/** User-to-agent send request; idempotency key lets clients safely retry transport failures. */
const ChatSendParamsSchema = closedObject({
sessionKey: ChatSendSessionKeyString,
agentId: Type.Optional(NonEmptyString),
sessionId: Type.Optional(NonEmptyString),
message: Type.String(),
mentions: Type.Optional(HumanMentionsSchema),
workContext: Type.Optional(ChatWorkContextSchema),
intent: Type.Optional(ChatSendIntentSchema),
thinking: Type.Optional(Type.String()),
fastMode: Type.Optional(Type.Union([
Type.Boolean(),
Type.Literal("auto"),
Type.Literal("ultrafast")
])),
fastAutoOnSeconds: Type.Optional(Type.Integer({ minimum: 1 })),
queueMode: Type.Optional(Type.String({ enum: [...QUEUE_MODES] })),
deliver: Type.Optional(Type.Boolean()),
originatingChannel: Type.Optional(Type.String()),
originatingTo: Type.Optional(Type.String()),
originatingAccountId: Type.Optional(Type.String()),
originatingThreadId: Type.Optional(Type.String()),
replyToId: Type.Optional(NonEmptyString),
attachments: Type.Optional(ChatAttachmentsSchema),
toolBindings: Type.Optional(RunToolBindingsSchema),
timeoutMs: Type.Optional(Type.Integer({ minimum: 0 })),
systemInputProvenance: Type.Optional(InputProvenanceSchema),
systemProvenanceReceipt: Type.Optional(Type.String()),
suppressCommandInterpretation: Type.Optional(Type.Boolean()),
expectedLeafEntryId: Type.Optional(Type.Union([NonEmptyString, Type.Null()])),
expectedSessionRoutingContract: Type.Optional(NonEmptyString),
expectedPermissionMode: Type.Optional(Type.Union([SessionPermissionModeSchema, Type.Null()])),
expectedToolOverrides: Type.Optional(Type.Union([SessionToolOverridesSchema, Type.Null()])),
idempotencyKey: NonEmptyString
});
/** Cancels the active or named run for a chat session. */
const ChatAbortParamsSchema = closedObject({
sessionKey: NonEmptyString,
agentId: Type.Optional(NonEmptyString),
sessionId: Type.Optional(NonEmptyString),
runId: Type.Optional(NonEmptyString),
preserveSideRuns: Type.Optional(Type.Boolean()),
discardPendingInput: Type.Optional(Type.Boolean())
});
/** Inserts an operator-visible synthetic message into an existing chat transcript. */
const ChatInjectParamsSchema = closedObject({
sessionKey: NonEmptyString,
agentId: Type.Optional(NonEmptyString),
message: NonEmptyString,
label: Type.Optional(Type.String({ maxLength: 100 }))
});
/** Shared event fields preserve stream ordering and route events to the right session. */
const ChatEventBaseSchema = {
runId: NonEmptyString,
sessionKey: NonEmptyString,
agentId: Type.Optional(NonEmptyString),
spawnedBy: Type.Optional(NonEmptyString),
seq: Type.Integer({ minimum: 0 })
};
/** Stable error categories exposed over the chat stream. */
const ChatEventErrorKindSchema = stringLiteralUnion([
"refusal",
"timeout",
"rate_limit",
"context_length",
"state_contention",
"unknown"
]);
/** Transient preparation and model-call stages; model waits can recur during a run. */
const ChatRunStartupPhaseSchema = stringLiteralUnion([
"waiting_for_state",
"preparing_workspace",
"naming_worktree",
"preparing_worktree_base",
"creating_worktree",
"running_setup",
"provisioning_environment",
"preparing_context",
"memory_flushing",
"starting_model",
"waiting_for_model"
]);
/** Transient working status; only the run owner publishes terminal failures. */
const ChatStatusEventSchema = closedObject({
...ChatEventBaseSchema,
state: Type.Literal("status"),
phase: ChatRunStartupPhaseSchema,
waitReason: Type.Optional(stringLiteralUnion(["response", "slot"])),
retry: Type.Optional(closedObject({
attempt: Type.Integer({
minimum: 1,
maximum: 10
}),
maxAttempts: Type.Integer({
minimum: 1,
maximum: 10
}),
reason: stringLiteralUnion([
"rate_limit",
"overloaded",
"server_error",
"timeout",
"output_limit"
]),
retryAt: Type.Optional(Type.Number({ minimum: 0 }))
}))
});
/** Incremental assistant output event; `replace` marks full-content refresh deltas. */
const ChatDeltaEventSchema = closedObject({
...ChatEventBaseSchema,
state: Type.Literal("delta"),
message: Type.Optional(Type.Unknown()),
deltaText: Type.String(),
replace: Type.Optional(Type.Boolean()),
usage: Type.Optional(Type.Unknown())
});
/** Successful terminal event for a completed chat run. */
const ChatFinalEventSchema = closedObject({
...ChatEventBaseSchema,
state: Type.Literal("final"),
message: Type.Optional(Type.Unknown()),
usage: Type.Optional(Type.Unknown()),
stopReason: Type.Optional(Type.String()),
yielded: Type.Optional(Type.Literal(true))
});
/** Terminal event for user-initiated or coordinator-initiated cancellation. */
const ChatAbortedEventSchema = closedObject({
...ChatEventBaseSchema,
state: Type.Literal("aborted"),
localModelMayStillBeFinishing: Type.Optional(Type.Literal(true)),
message: Type.Optional(Type.Unknown()),
errorMessage: Type.Optional(Type.String()),
stopReason: Type.Optional(Type.String())
});
const CHAT_ERROR_DETAIL_MAX_CHARS = 300;
const ChatErrorDetailTextSchema = Type.Optional(Type.String({ maxLength: CHAT_ERROR_DETAIL_MAX_CHARS }));
const ChatErrorDetailSchema = closedObject({
provider: ChatErrorDetailTextSchema,
model: ChatErrorDetailTextSchema,
failoverReason: ChatErrorDetailTextSchema,
providerRuntimeFailureKind: ChatErrorDetailTextSchema,
providerErrorCode: ChatErrorDetailTextSchema,
providerErrorType: ChatErrorDetailTextSchema,
httpStatus: Type.Optional(Type.Integer({
minimum: 100,
maximum: 599
})),
providerErrorMessagePreview: ChatErrorDetailTextSchema
});
/** Bounds already-redacted provider facts before lifecycle and chat publication. */
function projectChatErrorDetail(e) {
const t = asOptionalRecord(e);
if (!t) return;
const readText = (e) => typeof e === "string" && e.trim() ? truncateUtf16Safe(e.trim(), CHAT_ERROR_DETAIL_MAX_CHARS) : void 0;
const n = typeof t.httpStatus === "number" ? t.httpStatus : void 0;
const r = {
provider: readText(t.provider),
model: readText(t.model),
failoverReason: readText(t.failoverReason),
providerRuntimeFailureKind: readText(t.providerRuntimeFailureKind),
providerErrorCode: readText(t.providerErrorCode),
providerErrorType: readText(t.providerErrorType),
httpStatus: n !== void 0 && Number.isInteger(n) && n >= 100 && n <= 599 ? n : void 0,
providerErrorMessagePreview: readText(t.providerErrorMessagePreview)
};
return Object.values(r).some((e) => e !== void 0) ? r : void 0;
}
/** Terminal event for failed chat runs with optional sanitized provider diagnostics. */
const ChatErrorEventSchema = closedObject({
...ChatEventBaseSchema,
state: Type.Literal("error"),
message: Type.Optional(Type.Unknown()),
errorMessage: Type.Optional(Type.String()),
errorKind: Type.Optional(ChatEventErrorKindSchema),
suppressErrorNotice: Type.Optional(Type.Boolean()),
errorDetail: Type.Optional(ChatErrorDetailSchema),
usage: Type.Optional(Type.Unknown()),
stopReason: Type.Optional(Type.String())
});
/** Public chat stream event union consumed by gateway protocol validators. */
const ChatEventSchema = Type.Union([
ChatStatusEventSchema,
ChatDeltaEventSchema,
ChatFinalEventSchema,
ChatAbortedEventSchema,
ChatErrorEventSchema
]);
//#endregion
export { MentionsFailedEventSchema as A, projectChatErrorDetail as C, MentionableUserSchema as D, MentionInboxItemSchema as E, MAX_HUMAN_MENTIONS as F, MAX_MENTIONABLE_USERS as I, MENTION_INBOX_MAX_ITEMS as L, MentionsListResultSchema as M, UsersMentionableParamsSchema as N, MentionsChangedEventSchema as O, UsersMentionableResultSchema as P, LogsTailResultSchema as S, HumanMentionsSchema as T, ChatStartupParamsSchema as _, ChatHistoryActivitySchema as a, ChatToolTitlesResultSchema as b, ChatMessageGetParamsSchema as c, ChatPendingInputsDismissResultSchema as d, ChatPendingInputsPageSchema as f, ChatSendParamsSchema as g, ChatRunStartupPhaseSchema as h, ChatEventSchema as i, MentionsListParamsSchema as j, MentionsDismissParamsSchema as k, ChatMetadataParamsSchema as l, ChatPredictResultSchema as m, ChatAbortParamsSchema as n, ChatHistoryParamsSchema as o, ChatPredictParamsSchema as p, ChatAttachmentsSchema as r, ChatInjectParamsSchema as s, AgentActivityItemSchema as t, ChatPendingInputsDismissParamsSchema as u, ChatStatusEventSchema as v, HumanMentionSchema as w, LogsTailParamsSchema as x, ChatToolTitlesParamsSchema as y };