Tela SDK for JavaScript
    Preparing search index...

    Class Tasks

    Tasks API resource.

    const tela = new TelaSDK({ apiKey: '...' })

    // Fetch a task by id
    const task = await tela.tasks.get('task-id')

    // Rename it
    await tela.tasks.rename('task-id', 'New name')

    // Approve it
    await tela.tasks.approve('task-id')

    // Edit its output
    await tela.tasks.setOutputContent('task-id', { foo: 'bar' })

    // List input files
    const files = await tela.tasks.getInputFiles('task-id')

    // Read the result regardless of canvas vs workflow shape
    const output = await tela.tasks.getOutput<MyOutput>('task-id')
    Index

    Constructors

    Methods

    • Approves a task by setting its status to completed. Convenience wrapper around update.

      Type Parameters

      • TOutput = unknown

      Parameters

      • id: string

      Returns Promise<Task<TOutput>>

    • Fetches a task by id.

      Type Parameters

      • TOutput = unknown

      Parameters

      • id: string

        The task id.

      • Optionaloptions: { includeAnalytics?: boolean }

        Optional flags.

        • OptionalincludeAnalytics?: boolean

          Include analytics data on the task.

      Returns Promise<Task<TOutput>>

    • Returns the input files attached to a task.

      Convenience helper around get that extracts and normalizes the inputContent.files[] array.

      Parameters

      • id: string

      Returns Promise<TaskInputFile[]>

    • Returns the parsed output of a task regardless of whether it came from a canvas execution or a workflow execution.

      Returns null if the task has no output yet.

      Type Parameters

      • TOutput = unknown

      Parameters

      • id: string

      Returns Promise<TOutput | null>

    • Patches a task's output content with a deep merge against the existing content.

      ⚠️ Merge semantics, not replace. The server iterates the keys of the provided payload and overlays them onto the current outputContent.content:

      • Keys you provide overwrite the existing values at the same path.
      • Nested objects are merged recursively.
      • Arrays of objects are merged positionally by index.
      • Keys you do not provide are left untouched — there is no way to delete a field through this API.

      If you only need to update a single (possibly nested) field, prefer patchOutputField which handles building the nested payload for you.

      Type Parameters

      • TOutput = unknown

      Parameters

      • id: string
      • content: Record<string, unknown> | Partial<TOutput>

      Returns Promise<Task<TOutput>>

      // Existing content: { name: 'foo', price: 10 }
      await tela.tasks.patchOutputContent(id, { price: 12 })
      // Result: { name: 'foo', price: 12 }
      // Existing content: { menu: { items: [{ name: 'A', price: 5 }] } }
      await tela.tasks.patchOutputContent(id, { menu: { items: [{ price: 6 }] } })
      // Result: { menu: { items: [{ name: 'A', price: 6 }] } }
    • Patches a single field of a task's output content using a dot-notation path.

      Internally builds a nested object that mirrors the path and submits it via patchOutputContent, relying on the server's deep-merge to leave sibling fields untouched.

      Path syntax:

      • foo.bar.baz — nested object keys
      • items.0.price — numeric segments are treated as array indices

      ⚠️ Use updateOutputContent for any change inside arrays. The server's deep-merge replaces an entire array whenever the patched array's length differs from the current one. This method only sends a sparse single-element array (e.g. [{ price: 7 }]), so an array index path will truncate the rest of the items. It is safe for object paths only (e.g. profile.email).

      Type Parameters

      • TOutput = unknown

      Parameters

      • id: string
      • path: string
      • value: unknown

      Returns Promise<Task<TOutput>>

      // Existing: { profile: { name: 'A', email: 'a@x' } }
      await tela.tasks.patchOutputField(id, 'profile.email', 'b@x')
      // Result: { profile: { name: 'A', email: 'b@x' } }
      // ❌ Do NOT use patchOutputField for array indices:
      // await tela.tasks.patchOutputField(id, 'items.0.price', 7)
      // → server replaces items[] with the single-element sparse array.

      // ✅ Use updateOutputContent instead:
      await tela.tasks.updateOutputContent(id, (current) => {
      current.items[0].price = 7
      })
    • Renames a task. Convenience wrapper around update.

      Type Parameters

      • TOutput = unknown

      Parameters

      • id: string
      • name: string

      Returns Promise<Task<TOutput>>

    • Re-runs a task. Returns the new execution metadata.

      Note: the server only allows re-running tasks in failed status. Calling this on a task in any other state will result in a 400 response.

      Parameters

      • id: string

      Returns Promise<TaskRerunResult>

    • Replaces a task's tags. Convenience wrapper around update.

      Type Parameters

      • TOutput = unknown

      Parameters

      • id: string
      • tags: string[]

      Returns Promise<Task<TOutput>>

    • Reverts approval on multiple tasks (sets them back to validating). Only tasks currently in completed status are eligible.

      Parameters

      • ids: string[]

      Returns Promise<TaskUndoApprovalBulkResult>

      If ids is empty.

    • Read-modify-write helper for safely updating any part of a task's output content — including array elements.

      Fetches the current output, hands you a deep clone via the updater callback (which can mutate it in place or return a new value), then submits the full updated content via patchOutputContent. Because the entire arrays are sent back, the server's "replace on length mismatch" array behavior never triggers — array element edits, additions, removals, and reorders all work correctly.

      Use this whenever:

      • You're modifying anything inside an array
      • You need the previous value to compute the new one
      • You're making multiple field changes in one logical operation

      For simple top-level patches without needing the current value, prefer patchOutputContent.

      Type Parameters

      • TOutput = unknown

      Parameters

      Returns Promise<Task<TOutput>>

      await tela.tasks.updateOutputContent<MenuOutput>(id, (current) => {
      current.menu.items[2].price = 9.99
      })
      await tela.tasks.updateOutputContent<TodoOutput>(id, (current) => {
      current.todos.push({ text: 'new task', done: false })
      })
      await tela.tasks.updateOutputContent(id, (current) => ({
      ...current,
      reviewed: true,
      }))

      If the task has no output content yet (still running).