UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

213 lines (212 loc) • 9.18 kB
import { t as closedObject } from "./closed-object-DGvQfpTV.mjs"; import { a as NonEmptyString } from "./primitives-hKIagADr.mjs"; import { Type } from "typebox"; //#region packages/gateway-protocol/src/node-presence.ts /** Canonical reasons accepted from native/background node presence events. */ const NODE_PRESENCE_ALIVE_REASONS = { BACKGROUND: "background", SILENT_PUSH: "silent_push", BACKGROUND_APP_REFRESH: "bg_app_refresh", SIGNIFICANT_LOCATION: "significant_location", MANUAL: "manual", CONNECT: "connect" }; //#endregion //#region packages/gateway-protocol/src/schema/nodes.ts const NodePluginToolNameSchema = Type.String({ minLength: 1, maxLength: 64, pattern: "^[A-Za-z][A-Za-z0-9_-]{0,63}$" }); const NodeSkillNameSchema = Type.String({ minLength: 1, maxLength: 64, pattern: "^(?!.*--)[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" }); const NodePendingWorkTypeSchema = Type.String({ enum: ["status.request", "location.request"] }); const NodePendingWorkPrioritySchema = Type.String({ enum: ["normal", "high"] }); /** Reasons a node can report itself alive without implying an operator action. */ const NodePresenceAliveReasonSchema = Type.Enum(NODE_PRESENCE_ALIVE_REASONS, { type: "string" }); /** Presence heartbeat payload sent by remote nodes to refresh gateway state. */ const NodePresenceAlivePayloadSchema = closedObject({ trigger: NodePresenceAliveReasonSchema, sentAtMs: Type.Optional(Type.Integer({ minimum: 0 })), displayName: Type.Optional(NonEmptyString), version: Type.Optional(NonEmptyString), platform: Type.Optional(NonEmptyString), deviceFamily: Type.Optional(NonEmptyString), modelIdentifier: Type.Optional(NonEmptyString), pushTransport: Type.Optional(NonEmptyString) }); /** Recent operator input activity reported by an interactive node. */ const NodePresenceActivityPayloadSchema = Type.Union([closedObject({ idleSeconds: Type.Integer({ minimum: 0, maximum: 2592e3 }), source: Type.Optional(Type.Union([Type.Literal("app"), Type.Literal("system")])), saturated: Type.Optional(Type.Boolean()) }), closedObject({ action: Type.Literal("clear") })]); const NodeLoadAverageSchema = Type.Number({ minimum: 0, maximum: 1e5 }); const NodeHostStatsPayloadSchema = Type.Refine(closedObject({ cpuCount: Type.Integer({ minimum: 1, maximum: 4096 }), loadAverage: Type.Optional(Type.Tuple([ NodeLoadAverageSchema, NodeLoadAverageSchema, NodeLoadAverageSchema ])), memoryTotalBytes: Type.Integer({ minimum: 0 }), memoryFreeBytes: Type.Integer({ minimum: 0 }), diskTotalBytes: Type.Optional(Type.Integer({ minimum: 0 })), diskAvailableBytes: Type.Optional(Type.Integer({ minimum: 0 })) }), (stats) => stats.memoryFreeBytes <= stats.memoryTotalBytes && (stats.diskTotalBytes === void 0 ? stats.diskAvailableBytes === void 0 : stats.diskAvailableBytes !== void 0 && stats.diskAvailableBytes <= stats.diskTotalBytes), () => "free resources must not exceed totals and disk values must be paired"); const NodeEventResultSchema = closedObject({ ok: Type.Boolean(), event: NonEmptyString, handled: Type.Boolean(), reason: Type.Optional(NonEmptyString) }); const NodePairListParamsSchema = closedObject({}); const NodePairApproveParamsSchema = closedObject({ requestId: NonEmptyString }); const NodePairRejectParamsSchema = closedObject({ requestId: NonEmptyString }); /** Removes an already paired node from the gateway trust set. */ const NodePairRemoveParamsSchema = closedObject({ nodeId: NonEmptyString }); /** Renames a paired node while preserving its stable node id. */ const NodeRenameParamsSchema = closedObject({ nodeId: NonEmptyString, displayName: NonEmptyString }); const NodeListParamsSchema = closedObject({}); /** Agent-visible tool descriptor advertised by a connected node. */ const NodePluginToolDescriptorSchema = closedObject({ pluginId: NonEmptyString, name: NodePluginToolNameSchema, description: NonEmptyString, parameters: Type.Optional(Type.Record(Type.String(), Type.Unknown())), command: Type.Optional(NonEmptyString), mcp: Type.Optional(closedObject({ server: NonEmptyString, tool: NonEmptyString })) }); /** Replaces the connected node's dynamic agent-visible plugin/MCP tool catalog. */ const NodePluginToolsUpdateParamsSchema = closedObject({ tools: Type.Array(NodePluginToolDescriptorSchema) }); /** Agent-visible skill descriptor advertised by a connected node. */ const NodeSkillDescriptorSchema = closedObject({ name: NodeSkillNameSchema, description: Type.String({ minLength: 1, maxLength: 1024 }), content: Type.String({ minLength: 1, maxLength: 65536 }) }); /** Replaces the connected node's agent-visible skill catalog. */ const NodeSkillsUpdateParamsSchema = closedObject({ skills: Type.Array(NodeSkillDescriptorSchema, { maxItems: 64 }) }); /** Acknowledges queued node work that the node has consumed. */ const NodePendingAckParamsSchema = closedObject({ ids: Type.Array(NonEmptyString, { minItems: 1 }) }); const NodeDescribeParamsSchema = closedObject({ nodeId: NonEmptyString }); /** Invokes a command on a paired node; idempotency allows safe retries. */ const NodeInvokeParamsSchema = closedObject({ nodeId: NonEmptyString, command: NonEmptyString, params: Type.Optional(Type.Unknown()), timeoutMs: Type.Optional(Type.Integer({ minimum: 0 })), idempotencyKey: NonEmptyString, sessionKey: Type.Optional(NonEmptyString), turnSourceChannel: Type.Optional(Type.String()), turnSourceTo: Type.Optional(Type.String()), turnSourceAccountId: Type.Optional(Type.String()), turnSourceThreadId: Type.Optional(Type.Union([Type.String(), Type.Number()])) }); const NodeInvokeResultParamsSchema = closedObject({ id: NonEmptyString, nodeId: NonEmptyString, ok: Type.Boolean(), payload: Type.Optional(Type.Unknown()), payloadJSON: Type.Optional(Type.String()), error: Type.Optional(closedObject({ code: Type.Optional(NonEmptyString), message: Type.Optional(NonEmptyString) })) }); /** Ordered UTF-8 output emitted while a node command invocation is running. */ const NodeInvokeProgressParamsSchema = closedObject({ invokeId: NonEmptyString, nodeId: NonEmptyString, seq: Type.Integer({ minimum: 0 }), chunk: Type.String({ maxLength: 16384 }) }); const NodeEventParamsSchema = closedObject({ event: NonEmptyString, payload: Type.Optional(Type.Unknown()), payloadJSON: Type.Optional(Type.String()) }); /** Request for a bounded batch of queued work assigned to the calling node. */ const NodePendingDrainParamsSchema = closedObject({ maxItems: Type.Optional(Type.Integer({ minimum: 1, maximum: 10 })) }); const NodePendingDrainItemSchema = closedObject({ id: NonEmptyString, type: NodePendingWorkTypeSchema, priority: Type.String({ enum: [ "default", "normal", "high" ] }), createdAtMs: Type.Integer({ minimum: 0 }), expiresAtMs: Type.Optional(Type.Union([Type.Integer({ minimum: 0 }), Type.Null()])), payload: Type.Optional(Type.Record(Type.String(), Type.Unknown())) }); const NodePendingDrainResultSchema = closedObject({ nodeId: NonEmptyString, revision: Type.Integer({ minimum: 0 }), items: Type.Array(NodePendingDrainItemSchema), hasMore: Type.Boolean() }); const NodePendingEnqueueParamsSchema = closedObject({ nodeId: NonEmptyString, type: NodePendingWorkTypeSchema, priority: Type.Optional(NodePendingWorkPrioritySchema), expiresInMs: Type.Optional(Type.Integer({ minimum: 1e3, maximum: 864e5 })), wake: Type.Optional(Type.Boolean()) }); const NodePendingEnqueueResultSchema = closedObject({ nodeId: NonEmptyString, revision: Type.Integer({ minimum: 0 }), queued: NodePendingDrainItemSchema, wakeTriggered: Type.Boolean() }); closedObject({ id: NonEmptyString, nodeId: NonEmptyString, command: NonEmptyString, paramsJSON: Type.Optional(Type.String()), timeoutMs: Type.Optional(Type.Integer({ minimum: 0 })), idempotencyKey: Type.Optional(NonEmptyString) }); /** Ordered input frame sent by the gateway to one long-lived node invoke. */ const NodeInvokeInputEventSchema = closedObject({ id: NonEmptyString, nodeId: NonEmptyString, seq: Type.Integer({ minimum: 0 }), payloadJSON: Type.String({ maxLength: 16384 }) }); const NodeInvokeCancelEventSchema = closedObject({ invokeId: NonEmptyString, nodeId: NonEmptyString }); //#endregion export { NodePresenceAlivePayloadSchema as C, NodeSkillsUpdateParamsSchema as D, NodeSkillDescriptorSchema as E, NODE_PRESENCE_ALIVE_REASONS as O, NodePresenceActivityPayloadSchema as S, NodeRenameParamsSchema as T, NodePendingDrainResultSchema as _, NodeInvokeCancelEventSchema as a, NodePluginToolDescriptorSchema as b, NodeInvokeProgressParamsSchema as c, NodePairApproveParamsSchema as d, NodePairListParamsSchema as f, NodePendingDrainParamsSchema as g, NodePendingAckParamsSchema as h, NodeHostStatsPayloadSchema as i, NodeInvokeResultParamsSchema as l, NodePairRemoveParamsSchema as m, NodeEventParamsSchema as n, NodeInvokeInputEventSchema as o, NodePairRejectParamsSchema as p, NodeEventResultSchema as r, NodeInvokeParamsSchema as s, NodeDescribeParamsSchema as t, NodeListParamsSchema as u, NodePendingEnqueueParamsSchema as v, NodePresenceAliveReasonSchema as w, NodePluginToolsUpdateParamsSchema as x, NodePendingEnqueueResultSchema as y };