openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
349 lines (348 loc) • 13.9 kB
JavaScript
import { t as closedObject } from "./closed-object-B-B1FwhS.mjs";
import { a as NonEmptyString } from "./primitives-C8sb4NEJ.mjs";
import { t as NODE_WORKER_CAPACITY_MAX } from "./worker-capacity-CiGeSXP9.mjs";
import { Type } from "typebox";
//#region packages/gateway-protocol/src/schema/environments.ts
/**
* Environment inventory protocol schemas.
*
* Environments are runtime targets such as local hosts, VMs, or remote workers;
* this schema layer only describes their gateway-visible status summary.
*/
/** Runtime availability state for an environment target. */
const EnvironmentStatusSchema = Type.String({ enum: [
"available",
"unavailable",
"starting",
"stopping",
"error"
] });
const EnvironmentTrustSchema = Type.String({ enum: ["persistent", "disposable"] });
/** Operational desktop state reported by the current native node connection. */
const DesktopAvailabilitySchema = closedObject({ state: Type.Union([
Type.Literal("locked"),
Type.Literal("unlocked"),
Type.Literal("unknown")
]) });
/** Durable lifecycle states for plugin-provisioned worker environments. */
const WorkerEnvironmentStateSchema = Type.Union([
Type.Literal("requested"),
Type.Literal("provisioning"),
Type.Literal("bootstrapping"),
Type.Literal("ready"),
Type.Literal("attached"),
Type.Literal("idle"),
Type.Literal("draining"),
Type.Literal("destroying"),
Type.Literal("destroyed"),
Type.Literal("failed"),
Type.Literal("orphaned")
]);
/** Process-local SSH tunnel connectivity for a worker environment. */
const WorkerTunnelStatusSchema = Type.Union([
Type.Literal("stopped"),
Type.Literal("connecting"),
Type.Literal("connected"),
Type.Literal("reconnecting")
]);
/** Closed app ids a worker desktop may advertise and launch. */
const WorkerDesktopAppIdSchema = Type.Union([Type.Literal("browser"), Type.Literal("terminal")]);
/** Actionable issue attached only to runtime targets that need operator intervention. */
const RuntimeTargetIssueSchema = Type.Union([closedObject({
code: Type.Literal("update-required"),
action: Type.Literal("update-and-reconnect"),
updateCommand: Type.Literal("openclaw update"),
headlessReconnectCommand: Type.Literal("openclaw node restart")
}), closedObject({
code: Type.Literal("worker-host-unavailable"),
message: Type.String({
minLength: 1,
maxLength: 1024
})
})]);
const NodeWorkerBundleStatusSchema = Type.Union([closedObject({
status: Type.Literal("installed"),
version: NonEmptyString
}), closedObject({ status: Type.Literal("missing") })]);
/** Bounded live worker slots advertised by a connected node host. */
const WorkerSlotSummarySchema = Type.Refine(closedObject({
total: Type.Integer({
minimum: 1,
maximum: NODE_WORKER_CAPACITY_MAX
}),
available: Type.Integer({
minimum: 0,
maximum: NODE_WORKER_CAPACITY_MAX
}),
reclaimableIdle: Type.Optional(Type.Integer({
minimum: 0,
maximum: 2
}))
}), (e) => e.available + (e.reclaimableIdle ?? 0) <= e.total, (e) => `available worker slots ${e.available} exceed total ${e.total}`);
/** Gateway-owned authority state for one runtime-required node command. */
const RequiredNodeCommandStateSchema = Type.Union([
Type.Literal("invocable"),
Type.Literal("pending-approval"),
Type.Literal("undeclared"),
Type.Literal("unauthorized")
]);
const RequiredNodeCommandSchema = closedObject({
command: Type.String({
minLength: 1,
maxLength: 128
}),
state: RequiredNodeCommandStateSchema,
message: Type.Optional(NonEmptyString)
});
/** Worker-only lifecycle metadata layered onto the existing environment projection. */
const WorkerEnvironmentStartStatusSchema = Type.Union([closedObject({
mode: Type.Literal("snapshot"),
phase: Type.Optional(Type.Literal("saving"))
}), closedObject({
mode: Type.Literal("cold"),
reason: Type.Union([
Type.Literal("no-snapshot-yet"),
Type.Literal("setup-changed"),
Type.Literal("snapshot-retiring"),
Type.Literal("snapshot-unavailable"),
Type.Literal("os-unsupported"),
Type.Literal("warm-images-off"),
Type.Literal("capture-paused"),
Type.Literal("backend-cannot-snapshot"),
Type.Literal("class-unknown")
]),
phase: Type.Union([
Type.Literal("provisioning"),
Type.Literal("preparing"),
Type.Literal("saving")
])
})]);
const WorkerEnvironmentMetadataSchema = closedObject({
profileId: Type.Optional(NonEmptyString),
providerId: NonEmptyString,
leaseId: Type.Optional(NonEmptyString),
state: WorkerEnvironmentStateSchema,
startStatus: Type.Optional(WorkerEnvironmentStartStatusSchema),
ageMs: Type.Integer({ minimum: 0 }),
idleMs: Type.Optional(Type.Integer({ minimum: 0 })),
destroyRequestedAtMs: Type.Optional(Type.Integer({ minimum: 0 })),
attachedSessionIds: Type.Array(NonEmptyString),
tunnelStatus: WorkerTunnelStatusSchema,
error: Type.Optional(NonEmptyString),
desktop: Type.Optional(Type.Boolean()),
desktopApps: Type.Optional(Type.Array(WorkerDesktopAppIdSchema, {
maxItems: 8,
uniqueItems: true
}))
});
function createEnvironmentSummaryProperties() {
return {
id: NonEmptyString,
type: NonEmptyString,
label: Type.Optional(NonEmptyString),
status: EnvironmentStatusSchema,
platform: Type.Optional(NonEmptyString),
sessionHost: Type.Optional(Type.Boolean()),
workerSlots: Type.Optional(WorkerSlotSummarySchema),
workerHost: Type.Optional(closedObject({ deviceFolders: Type.Optional(Type.Literal(true)) })),
workerBundle: Type.Optional(NodeWorkerBundleStatusSchema),
lastConnectedAtMs: Type.Optional(Type.Integer({ minimum: 0 })),
lastDisconnectedAtMs: Type.Optional(Type.Integer({ minimum: 0 })),
lastSeenAtMs: Type.Optional(Type.Integer({ minimum: 0 })),
lastSeenReason: Type.Optional(NonEmptyString),
trust: Type.Optional(EnvironmentTrustSchema),
capabilities: Type.Optional(Type.Array(NonEmptyString)),
invocableCommands: Type.Optional(Type.Array(Type.String({
minLength: 1,
maxLength: 128
}), {
maxItems: 128,
uniqueItems: true
})),
desktop: Type.Optional(Type.Boolean()),
desktopAvailability: Type.Optional(DesktopAvailabilitySchema),
issues: Type.Optional(Type.Array(RuntimeTargetIssueSchema, {
minItems: 1,
maxItems: 8
})),
worker: Type.Optional(WorkerEnvironmentMetadataSchema),
preparation: Type.Optional(closedObject({
purpose: Type.Union([Type.Literal("reserve"), Type.Literal("build")]),
key: NonEmptyString,
details: Type.Optional(closedObject({
demandAtMs: Type.Integer({ minimum: 0 }),
expiresAtMs: Type.Integer({ minimum: 0 }),
consumedAtMs: Type.Union([Type.Integer({ minimum: 0 }), Type.Null()]),
project: Type.Optional(closedObject({
label: Type.Optional(NonEmptyString),
baseCommit: NonEmptyString
}))
}))
}))
};
}
/** Public environment summary shown in listings and status responses. */
const EnvironmentSummarySchema = closedObject({
...createEnvironmentSummaryProperties(),
requiredNodeCommand: Type.Optional(RequiredNodeCommandSchema),
desktopSetup: Type.Optional(closedObject({
state: Type.Union([
Type.Literal("ready"),
Type.Literal("needs-server"),
Type.Literal("unsupported"),
Type.Literal("managed")
]),
detail: Type.Optional(NonEmptyString)
}))
});
/** Optional runtime scope or profile-only projection for environment discovery. */
const EnvironmentsListParamsSchema = closedObject({
runtimeId: Type.Optional(Type.String({
minLength: 1,
maxLength: 128
})),
projection: Type.Optional(Type.Literal("profiles")),
includeDesktopSetup: Type.Optional(Type.Boolean()),
includePreparedDetails: Type.Optional(Type.Boolean())
});
/** Provider-authored machine choice for one configured worker profile. */
const WorkerMachineOptionSchema = closedObject({
id: Type.String({
minLength: 1,
maxLength: 128
}),
label: Type.String({
minLength: 1,
maxLength: 128
}),
cpu: Type.Optional(Type.Integer({
minimum: 1,
maximum: 65536
})),
memoryGb: Type.Optional(Type.Integer({
minimum: 1,
maximum: 65536
})),
default: Type.Optional(Type.Boolean()),
os: Type.Optional(Type.String({
minLength: 1,
maxLength: 64
}))
});
const WorkerMachineOptionsSchema = Type.Array(WorkerMachineOptionSchema, {
minItems: 1,
maxItems: 64
});
/** Provider-authored operating system choice for one configured worker profile. */
const WorkerOperatingSystemSchema = closedObject({
id: Type.String({
minLength: 1,
maxLength: 64
}),
label: Type.String({
minLength: 1,
maxLength: 64
}),
default: Type.Optional(Type.Boolean()),
disabledReason: Type.Optional(Type.String({
minLength: 1,
maxLength: 256
}))
});
/** Placement execution modes shared by runtime requirements and worker providers. */
const WorkerExecutionModeSchema = Type.Union([Type.Literal("worker-turn"), Type.Literal("remote-exec")]);
/** Configured worker target exposed without provider settings or credentials. */
const WorkerEnvironmentProfileSummarySchema = closedObject({
id: NonEmptyString,
providerId: NonEmptyString,
inference: Type.Optional(Type.Literal("worker")),
readyWorkers: Type.Optional(Type.Integer({ minimum: 0 })),
providerDisplayId: Type.Optional(Type.String({
pattern: "^[a-z][a-z0-9-]{0,63}(?![\\s\\S])",
maxLength: 64
})),
trust: Type.Optional(EnvironmentTrustSchema),
executionMode: Type.Optional(WorkerExecutionModeSchema),
executionModes: Type.Optional(Type.Union([Type.Tuple([WorkerExecutionModeSchema]), Type.Tuple([Type.Literal("worker-turn"), Type.Literal("remote-exec")])])),
machines: Type.Optional(WorkerMachineOptionsSchema),
operatingSystems: Type.Optional(Type.Array(WorkerOperatingSystemSchema, {
minItems: 1,
maxItems: 8
}))
});
/** A discoverable config proposal, never an admitted placement destination. */
const SuggestedWorkerProfileSummarySchema = closedObject({
id: NonEmptyString,
providerId: NonEmptyString,
providerDisplayId: Type.Optional(Type.String({
pattern: "^[a-z][a-z0-9-]{0,63}(?![\\s\\S])",
maxLength: 64
}))
});
const EnvironmentsAdoptSuggestedProfileParamsSchema = closedObject({});
const EnvironmentsAdoptSuggestedProfileResultSchema = closedObject({ profile: WorkerEnvironmentProfileSummarySchema });
/** Profile-only requests leave environments empty without reading inventory. */
const EnvironmentsListResultSchema = closedObject({
requiredProfile: Type.Optional(NonEmptyString),
environments: Type.Array(EnvironmentSummarySchema),
profiles: Type.Optional(Type.Array(WorkerEnvironmentProfileSummarySchema)),
dispatchableProfileIds: Type.Optional(Type.Array(NonEmptyString, { uniqueItems: true })),
suggestedProfile: Type.Optional(SuggestedWorkerProfileSummarySchema),
preparedPool: Type.Optional(closedObject({
maxTotal: Type.Integer({ minimum: 0 }),
reservedEnvironmentIds: Type.Array(NonEmptyString, { uniqueItems: true })
}))
});
/** Status lookup request for one environment id. */
const EnvironmentsStatusParamsSchema = closedObject({
environmentId: NonEmptyString,
includePreparedDetails: Type.Optional(Type.Boolean())
});
/** Status lookup result for one environment id. */
const EnvironmentsStatusResultSchema = closedObject(createEnvironmentSummaryProperties());
/** Creates a worker environment from one configured provider profile. */
const EnvironmentsCreateParamsSchema = closedObject({
profileId: NonEmptyString,
idempotencyKey: NonEmptyString
});
/** Create result uses the same public summary shape as list and status. */
const EnvironmentsCreateResultSchema = closedObject(createEnvironmentSummaryProperties());
/** Prepares a configured profile's local Git project without dispatching a session. */
const EnvironmentsPrepareParamsSchema = closedObject({
profileId: NonEmptyString,
projectPath: NonEmptyString
});
const EnvironmentsPrepareResultSchema = closedObject({
environmentId: NonEmptyString,
preparationKey: NonEmptyString,
reused: Type.Boolean()
});
/** Destroys one durable worker environment by its gateway-owned id. */
const EnvironmentsDestroyParamsSchema = closedObject({
environmentId: NonEmptyString,
force: Type.Optional(Type.Boolean())
});
/** Destroy result exposes the terminal worker lifecycle state. */
const EnvironmentsDestroyResultSchema = closedObject(createEnvironmentSummaryProperties());
const WorkerDesktopObserveParamsSchema = closedObject({
environmentId: NonEmptyString,
control: Type.Optional(Type.Boolean())
});
const WorkerDesktopObserveResultSchema = closedObject({
transport: Type.String({ enum: ["rfb"] }),
wsPath: NonEmptyString,
expiresAtMs: Type.Integer({ minimum: 0 }),
control: Type.Boolean(),
canResize: Type.Optional(Type.Boolean()),
vncPassword: Type.Optional(NonEmptyString)
});
const WorkerDesktopLaunchParamsSchema = closedObject({
environmentId: NonEmptyString,
app: WorkerDesktopAppIdSchema
});
const WorkerDesktopLaunchResultSchema = closedObject({
app: WorkerDesktopAppIdSchema,
status: Type.Literal("ready")
});
//#endregion
export { WorkerTunnelStatusSchema as A, WorkerDesktopObserveResultSchema as C, WorkerExecutionModeSchema as D, WorkerEnvironmentStateSchema as E, WorkerMachineOptionsSchema as O, WorkerDesktopObserveParamsSchema as S, WorkerEnvironmentStartStatusSchema as T, RequiredNodeCommandStateSchema as _, EnvironmentsAdoptSuggestedProfileResultSchema as a, WorkerDesktopLaunchParamsSchema as b, EnvironmentsDestroyParamsSchema as c, EnvironmentsListResultSchema as d, EnvironmentsPrepareParamsSchema as f, RequiredNodeCommandSchema as g, EnvironmentsStatusResultSchema as h, EnvironmentsAdoptSuggestedProfileParamsSchema as i, WorkerOperatingSystemSchema as k, EnvironmentsDestroyResultSchema as l, EnvironmentsStatusParamsSchema as m, EnvironmentStatusSchema as n, EnvironmentsCreateParamsSchema as o, EnvironmentsPrepareResultSchema as p, EnvironmentSummarySchema as r, EnvironmentsCreateResultSchema as s, DesktopAvailabilitySchema as t, EnvironmentsListParamsSchema as u, SuggestedWorkerProfileSummarySchema as v, WorkerEnvironmentMetadataSchema as w, WorkerDesktopLaunchResultSchema as x, WorkerDesktopAppIdSchema as y };