openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.98 kB
JavaScript
import"./openclaw-state-read-kysely-sync-DQyYiAw5.mjs";import"./openclaw-state-read-openclaw-state-db-schema-helpers-BkqUYEFY.mjs";import{g as e,h as t}from"./openclaw-state-read-placement-row-codec-H0QnPs2g.mjs";function normalizeGeneration(e){if(!Number.isSafeInteger(e)||e<0)throw Error(`Worker placement move source generation must be a non-negative integer`);return e}function boundedIdentifier(t,n,r=256){let i=e(t,n);if(i.length>r)throw Error(`Worker session placement ${n} exceeds ${r} characters`);return i}function normalizeOperationId(t){let n=e(t,`move operation id`);if(!n.startsWith(`move:v1:`)||n.length>128)throw Error(`Worker session placement move operation id is invalid`);return n}function normalizeWorkerPlacementMoveTarget(e){if(e.kind!==`profile`&&Object.hasOwn(e,`os`))throw Error(`Worker placement move operating system requires a profile target`);switch(e.kind){case`gateway`:return{kind:`gateway`};case`profile`:{let t=e.machineClass;return{kind:`profile`,profileId:boundedIdentifier(e.profileId,`move profile id`),...e.os===void 0?{}:{os:boundedIdentifier(e.os,`move operating system`,64)},...t===void 0?{}:{machineClass:boundedIdentifier(t,`move machine class`,128)}}}case`device`:return{kind:`device`,deviceId:boundedIdentifier(e.deviceId,`move device id`)}}throw Error(`Worker placement move target is invalid`)}function normalizeWorkerPlacementMoveSource(e){return{generation:normalizeGeneration(e.generation),environmentId:boundedIdentifier(e.environmentId,`move source environment id`),ownerEpoch:t(e.ownerEpoch,`move source owner epoch`)}}function normalizeAbandonSource(e){if(e===null)return!1;if(e===1)return!0;throw Error(`Invalid worker placement move source abandonment value`)}function workerPlacementMoveFromRow(t){let n=normalizeWorkerPlacementMoveSource({generation:t.source_generation,environmentId:t.source_environment_id,ownerEpoch:t.source_owner_epoch}),r;if(t.target_kind!==`profile`&&(t.target_machine_class!==null||t.target_os!==null))throw Error(`Invalid worker placement move target: ${t.target_kind}`);if(t.target_kind===`gateway`&&t.target_id===null)r={kind:`gateway`};else if(t.target_kind===`profile`&&t.target_id!==null)r=normalizeWorkerPlacementMoveTarget({kind:`profile`,profileId:t.target_id,...t.target_os===null?{}:{os:t.target_os},...t.target_machine_class===null?{}:{machineClass:t.target_machine_class}});else if(t.target_kind===`device`&&t.target_id!==null)r={kind:`device`,deviceId:boundedIdentifier(t.target_id,`move device id`)};else throw Error(`Invalid worker placement move target: ${t.target_kind}`);let i=normalizeAbandonSource(t.abandon_source);if(i&&r.kind!==`gateway`)throw Error(`Worker placement move source abandonment requires a Gateway target`);return{operationId:normalizeOperationId(t.operation_id),sessionId:e(t.session_id,`move session id`),source:n,target:r,abandonSource:i,lastError:t.last_error,createdAtMs:t.created_at_ms,updatedAtMs:t.updated_at_ms}}export{workerPlacementMoveFromRow as t};