Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.7 KB
Raw Blame
import { Property, createAction } from '@activepieces/pieces-framework';
import { onfleetAuth } from '../..';
import { common } from '../common';

import Onfleet from '@onfleet/node-onfleet';

export const updateWorker = createAction({
  auth: onfleetAuth,
  name: 'update_worker',
  displayName: 'Update Worker',
  description: 'Update an existing worker',
  audience: 'both',
  aiMetadata: { description: 'Updates an existing Onfleet worker (driver) by worker ID, changing fields such as name, team membership, capacity, or display name. Not idempotent: it patches the live worker and reassigning teams replaces the prior set. Use create-worker to add a new driver.', idempotent: false },
  props: {
    worker: common.worker,
    name: Property.ShortText({
      displayName: 'Name',
      description: 'Name of the worker',
      required: false,
    }),
    teams: common.teams,
    capacity: Property.Number({
      displayName: 'Capacity',
      description: 'The maximum number of units this worker can carry',
      required: false,
    }),
    displayName: Property.ShortText({
      displayName: 'Display Name',
      required: false,
    }),
  },
  async run(context) {
    const onfleetApi = new Onfleet(context.auth.secret_text);

    const options: any = {};

    if (context.propsValue.name) options.name = context.propsValue.name;
    if (context.propsValue.teams) options.teams = context.propsValue.teams;
    if (context.propsValue.capacity)
      options.capacity = context.propsValue.capacity;
    if (context.propsValue.displayName)
      options.displayName = context.propsValue.displayName;

    return await onfleetApi.workers.update(
      context.propsValue.worker as string,
      options
    );
  },
});