openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
120 lines (119 loc) • 5.69 kB
JavaScript
import { t as closedObject } from "./closed-object-B-B1FwhS.mjs";
import { t as stringLiteralUnion } from "./string-literal-union-C2qFTHSZ.mjs";
import { a as NonEmptyString } from "./primitives-C8sb4NEJ.mjs";
import { r as GatewayErrorDetailCodes, t as ErrorCodes } from "./gateway-error-details-B69XiHdh.mjs";
import { Type } from "typebox";
//#region packages/gateway-protocol/src/schema/error-codes.ts
const CronJobNotFoundErrorDetailsSchema = closedObject({
code: Type.Literal(GatewayErrorDetailCodes.CRON_JOB_NOT_FOUND),
jobId: NonEmptyString
});
/** Missing operator-scope details shared by WebSocket and HTTP responses. */
const MissingScopeErrorDetailsSchema = closedObject({
code: Type.Literal(GatewayErrorDetailCodes.MISSING_SCOPE),
missingScope: NonEmptyString,
requiredScopes: Type.Array(NonEmptyString, { minItems: 1 })
});
const McpAppViewExpiredErrorDetailsSchema = closedObject({ code: Type.Literal(GatewayErrorDetailCodes.MCP_APP_VIEW_EXPIRED) });
const OutboundDeliveryQueuedErrorDetailsSchema = closedObject({ code: Type.Literal(GatewayErrorDetailCodes.OUTBOUND_DELIVERY_QUEUED) });
const UserPrefsLimitExceededErrorDetailsSchema = closedObject({
code: Type.Literal(GatewayErrorDetailCodes.USER_PREFS_LIMIT_EXCEEDED),
limit: Type.Integer({ minimum: 1 }),
currentCount: Type.Integer({ minimum: 0 })
});
const UnknownAgentIdErrorDetailsSchema = closedObject({
code: Type.Literal(GatewayErrorDetailCodes.UNKNOWN_AGENT_ID),
agentId: NonEmptyString
});
const SetupAdmissionBusyErrorDetailsSchema = closedObject({ code: Type.Literal(GatewayErrorDetailCodes.SETUP_ADMISSION_BUSY) });
const GitHubPublicationSelectionRejectedErrorDetailsSchema = closedObject({
code: Type.Literal(GatewayErrorDetailCodes.GITHUB_PUBLICATION_SELECTION_REJECTED),
idempotencyKey: NonEmptyString
});
const WizardNotFoundErrorDetailsSchema = closedObject({ code: Type.Literal(GatewayErrorDetailCodes.WIZARD_NOT_FOUND) });
const ProjectCloneErrorDetailsSchema = closedObject({
code: Type.Literal(GatewayErrorDetailCodes.PROJECT_CLONE_FAILED),
cause: Type.String({ enum: [
"invalid_url",
"auth_required",
"not_found",
"network",
"target_exists",
"clone_failed"
] })
});
const SessionWorkspaceRecoveryRequiredErrorDetailsSchema = closedObject({
code: Type.Literal(GatewayErrorDetailCodes.SESSION_WORKSPACE_RECOVERY_REQUIRED),
cause: Type.Literal("device_offline"),
recoveryAction: Type.Literal("continue_on_gateway"),
sessionId: NonEmptyString,
source: closedObject({
generation: Type.Integer({ minimum: 0 }),
environmentId: NonEmptyString,
ownerEpoch: Type.Integer({ minimum: 1 })
})
});
/** Structured details emitted by method-level failures. */
const TaskWorktreeSourceRequiredErrorDetailsSchema = closedObject({
code: Type.Literal(GatewayErrorDetailCodes.TASK_WORKTREE_SOURCE_REQUIRED),
cwd: NonEmptyString
});
const ClawHubRiskAcknowledgementRequiredErrorDetailsSchema = closedObject({
code: Type.Literal(GatewayErrorDetailCodes.CLAWHUB_RISK_ACKNOWLEDGEMENT_REQUIRED),
warning: NonEmptyString
});
const TemplateReviewRequiredErrorDetailsSchema = closedObject({
code: Type.Literal(GatewayErrorDetailCodes.TEMPLATE_REVIEW_REQUIRED),
kind: stringLiteralUnion(["plugin", "skill"])
});
const PendingInputNotRetiredErrorDetailsSchema = closedObject({
code: Type.Literal(GatewayErrorDetailCodes.PENDING_INPUT_NOT_RETIRED),
inputIds: Type.Array(NonEmptyString, {
minItems: 1,
maxItems: 100
})
});
/** Structured details emitted by method-level failures. */
const GatewayErrorDetailsSchema = Type.Union([
CronJobNotFoundErrorDetailsSchema,
MissingScopeErrorDetailsSchema,
McpAppViewExpiredErrorDetailsSchema,
OutboundDeliveryQueuedErrorDetailsSchema,
UserPrefsLimitExceededErrorDetailsSchema,
ProjectCloneErrorDetailsSchema,
UnknownAgentIdErrorDetailsSchema,
WizardNotFoundErrorDetailsSchema,
SetupAdmissionBusyErrorDetailsSchema,
GitHubPublicationSelectionRejectedErrorDetailsSchema,
SessionWorkspaceRecoveryRequiredErrorDetailsSchema,
TaskWorktreeSourceRequiredErrorDetailsSchema,
ClawHubRiskAcknowledgementRequiredErrorDetailsSchema,
TemplateReviewRequiredErrorDetailsSchema,
PendingInputNotRetiredErrorDetailsSchema,
closedObject({ code: Type.Literal(GatewayErrorDetailCodes.TASK_HISTORY_PREVIEW_CAPACITY) }),
closedObject({ code: Type.Literal(GatewayErrorDetailCodes.OPENCLAW_CONFIG_READONLY) })
]);
/** Builds the canonical gateway error payload while preserving optional retry metadata. */
function errorShape(e, t, n) {
return {
code: e,
message: t,
...n
};
}
/** Builds structured details for a missing operator scope. */
function buildMissingScopeErrorDetails(e) {
const t = e.requiredScopes.length > 0 ? [...e.requiredScopes] : [e.missingScope];
return {
code: GatewayErrorDetailCodes.MISSING_SCOPE,
missingScope: e.missingScope,
requiredScopes: t
};
}
/** Builds a forbidden error for a missing operator scope without message parsing. */
function missingScopeErrorShape(e) {
const t = buildMissingScopeErrorDetails(e);
return errorShape(ErrorCodes.FORBIDDEN, `missing scope: ${e.missingScope}`, { details: t });
}
//#endregion
export { OutboundDeliveryQueuedErrorDetailsSchema as a, SetupAdmissionBusyErrorDetailsSchema as c, WizardNotFoundErrorDetailsSchema as d, buildMissingScopeErrorDetails as f, MissingScopeErrorDetailsSchema as i, TemplateReviewRequiredErrorDetailsSchema as l, missingScopeErrorShape as m, CronJobNotFoundErrorDetailsSchema as n, ProjectCloneErrorDetailsSchema as o, errorShape as p, GatewayErrorDetailsSchema as r, SessionWorkspaceRecoveryRequiredErrorDetailsSchema as s, ClawHubRiskAcknowledgementRequiredErrorDetailsSchema as t, UserPrefsLimitExceededErrorDetailsSchema as u };