Skip to content

iflb/tutti-client-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tutti JavaScript Client API

Installation

Node.js:

npm install @iflb/tutti-client

Usage

There are two ways to communicate with Tutti server: Call mode and Send mode.

Call mode

Calling commands with await prefix, the process waits there until the response is sent back, and receives it as a return value.

Directions

const data = await client.<namespace>.<command>({ <args object> }, awaited = true);

OR equivalently,

const data = await client.<namespace>.<command>.call(<args object>);

Send mode

Calling commands without await prefix, the process completes as soon as request is sent, and receives it in its listener.

Directions

Having defined a listener like below,

client.<namespace>.on('<command>', {
    success: (data) => {
        // do something for successful response...
    },
    error: (err) => {
        // do something for errors...
    },
    complete: () => {
        // do another thing to finalize request...
    }
});

Run:

client.<namespace>.<command>({ <args object> }, awaited = false);

OR equivalently,

client.<namespace>.<command>.send(<args object>);

Code Examples

Node.js:

const { TuttiClient } = require('@iflb/tutti-client');

async function main() {
    let client = new TuttiClient(true);
    await client.open('http://localhost:8080/ducts/wsd');

    // Sign in with an account first
    await client.resource.signIn({ user_name: 'admin', password: 'admin' })
    // Get a list of created projects
    const projects = await client.resource.listProjects();
    // List templates for the first project
    const templates = await client.resource.listTemplates({ project_name: projects[0].name });
}

main();

Browser:

<script src="https://unpkg.com/@iflb/tutti-client/dist/tutti.js"></script>
<script>
async function main() {
    const client = new tutti.TuttiClient(true);
    await client.open('http://localhost:8080/ducts/wsd');

    // Sign in with an account first
    await client.resource.signIn({ user_name: 'admin', password: 'admin' })
    // Get a list of created projects
    const projects = await client.resource.listProjects();
    // List templates for the first project
    const templates = await client.resource.listTemplates({ project_name: projects[0].name });
}
main();
</script>

Commands

Current options for namespaces are: resource, mturk.

TuttiClient.resource


checkProjectDiff

Checks whether the project is already rebuilt for the newest version.

Parameters
  • project_name: String
    • Tutti project name.
Returns
  • Boolean -- True if the project is in the newest version, thus no rebuild is needed.

createNanotaskGroup

Parameters
  • name: String
    • Name for the nanotask group. Must be unique.
  • nanotask_ids: Array
  • project_name: String
    • Tutti project name.
  • template_name: String
    • Tutti template name of a project.
Returns
  • String -- Created nanotask group ID.

createNanotasks

Parameters
  • project_name: String
    • Tutti project name.
  • template_name: String
    • Tutti template name of a project.
  • nanotasks: Array
  • tag: String
    • An arbitrary data field to tag nanotask for identifying purposes.
  • priority: Number
    • An integer value to represent nanotask importance. The smaller the value is, more prioritized the nanotask is among others. To learn more about nanotask priority, see Tutti's Programming Reference > Project Scheme.
  • num_assignable: Number
    • Maximum number of workers that can be assigned to nanotask.
Returns
  • Object
    • project_name: String
      • Tutti project name.
    • template_name: String
      • Tutti template name of a project.
    • nanotask_ids: Array

createProject

Parameters
  • project_name: String
    • Tutti project name.

createTemplate

Parameters
  • project_name: String
    • Tutti project name.
  • template_name: String
    • Tutti template name of a project.
  • preset_group_name: String
  • preset_name: String

deleteAccount

Parameters
  • user_id: String
    • User ID of Tutti account.

deleteNanotaskGroup

Parameters
  • nanotask_group_id: String

deleteNanotasks

Parameters
  • nanotask_ids: Array

deleteProject

Parameters
  • project_name: String
    • Tutti project name.

deleteTemplate

Parameters
  • project_name: String
    • Tutti project name.
  • template_name: String
    • Tutti template name of a project.

getNanotaskGroup

Parameters
  • nanotask_group_id: String

getProjectScheme

Parameters
  • project_name: String
    • Tutti project name.
  • cached: Boolean
    • Whether to return cached value in the response. Note that setting this value to false may result in slower responses.

getUserIds

Parameters
  • [None]

getWebServiceDescriptor

Parameters
  • [None]

listNanotaskGroups

Parameters
  • project_name: String
    • Tutti project name.
  • template_name: String
    • Tutti template name of a project.

listNanotasks

Parameters
  • project_name: String
    • Tutti project name.
  • template_name: String
    • Tutti template name of a project.

listNanotasksWithResponses

Parameters
  • project_name: String
    • Tutti project name.
  • template_name: String
    • Tutti template name of a project.

listNodeSessionsForWorkSession

Parameters
  • work_session_id: String
  • only_template: Boolean
    • If True, returns only node sessions for template nodes.

listProjects

Parameters
  • [None]

listProjectsWithResponses

Parameters
  • [None]

listResponsesForNanotask

Parameters
  • nanotask_id: String

listResponsesForProject

Parameters
  • project_name: String
    • Tutti project name.

listResponsesForTemplate

Parameters
  • project_name: String
    • Tutti project name.
  • template_name: String
    • Tutti template name of a project.

listResponsesForWorkSession

Parameters
  • work_session_id: String

listResponsesForWorker

Parameters
  • worker_id: String
    • Tutti's internal hash ID for worker.

listTemplatePresets

Parameters
  • project_name: String
    • Tutti project name.

listTemplates

Parameters
  • project_name: String
    • Tutti project name.

listTemplatesWithResponses

Parameters
  • project_name: String
    • Tutti project name.

listWorkSessionsWithResponses

Parameters
  • project_name: String
    • Tutti project name.

listWorkersForProject

Parameters
  • project_name: String
    • Tutti project name.

listWorkersWithResponses

Parameters
  • project_name: String
    • Tutti project name.

rebuildProject

Parameters
  • project_name: String
    • Tutti project name.

signIn

Parameters
  • user_name: String, default null
    • User name of Tutti account.
  • password_hash: String, default null
    • MD5-hashed password (hex-digested) of Tutti account.
  • access_token: String, default null
    • Valid access token obtained in previous logins.
  • ...args:
    • Accepts only password key (non-hashed password of Tutti account). This is not recommended; use password_hash or access_token instead.

signOut

Parameters
  • [None]

signUp

Parameters
  • user_name: String
    • User name of Tutti account.
  • password:
  • privilege_ids: Array
    • Priviledge IDs to associate with account. Currently not in use.

TuttiClient.mturk


addCredentials

Parameters
  • access_key_id: String
    • Access Key ID of MTurk credentials.
  • secret_access_key: String
    • Secret Access Key of MTurk credentials.
  • label:

addHITsToTuttiHITBatch

Parameters
  • batch_id: String
    • Tutti's internal hash ID for Tutti HIT Batch.
  • hit_params: Object
    • Parameters for CreateHIT operation of MTurk.
  • num_hits: Number
    • Number of HITs to create for Tutti HIT Batch.

approveAssignments

Parameters
  • assignment_ids: Array
    • List of MTurk Assignment IDs.
  • requester_feedback:
  • override_rejection:

associateQualificationsWithWorkers

Parameters
  • qualification_type_id:
  • worker_ids: Array
    • List of MTurk Worker IDs.
  • integer_value:
  • send_notification:

createQualificationType

Parameters
  • name:
  • description:
  • auto_granted:
  • qualification_type_status:

createTuttiHITBatch

Parameters
  • name:
  • project_name: String
    • Tutti project name.
  • hit_type_params: Object
    • Parameters for CreateHITType operation of MTurk.
  • hit_params: Object
    • Parameters for CreateHIT operation of MTurk.
  • num_hits: Number
    • Number of HITs to create for Tutti HIT Batch.

deleteCredentials

Parameters
  • credentials_id: String
    • Tutti's internal hash ID for registered MTurk credentials.

deleteHITs

Parameters
  • request_id: String
    • Arbitrary string value to identify response for this request.
  • hit_ids: Array
    • List of MTurk HIT Ids.

deleteQualificationTypes

Parameters
  • qualification_type_ids: Array
    • List of MTurk Qualification type IDs.

deleteTuttiHITBatch

Parameters
  • request_id: String
    • Arbitrary string value to identify response for this request.
  • batch_id: String
    • Tutti's internal hash ID for Tutti HIT Batch.

execBoto3

Parameters
  • method:
  • parameters:

expireHITs

Parameters
  • request_id: String
    • Arbitrary string value to identify response for this request.
  • hit_ids: Array
    • List of MTurk HIT Ids.

getActiveCredentials

Parameters
  • [None]

getCredentials

Parameters
  • credentials_id: String
    • Tutti's internal hash ID for registered MTurk credentials.

listAssignmentsForTuttiHITBatch

Parameters
  • batch_id: String
    • Tutti's internal hash ID for Tutti HIT Batch.
  • cached: Boolean
    • Whether to return cached value in the response. Note that setting this value to false may result in slower responses.

listCredentials

Parameters
  • [None]

listHITTypes

Parameters
  • [None]

listHITsForTuttiHITBatch

Parameters
  • batch_id: String
    • Tutti's internal hash ID for Tutti HIT Batch.
  • cached: Boolean
    • Whether to return cached value in the response. Note that setting this value to false may result in slower responses.

listQualificationTypes

Parameters
  • query:
  • only_user_defined: Boolean
    • Whether to filter out Qualification types of other requesters in the results. This is directly passed to MustBeOwnedByCaller parameter for MTurk's ListQualificationTypes operation.
  • cached: Boolean
    • Whether to return cached value in the response. Note that setting this value to false may result in slower responses.

listTuttiHITBatches

Parameters
  • [None]

listTuttiHITBatchesWithHITs

Parameters
  • [None]

listWorkers

Parameters
  • [None]

notifyWorkers

Parameters
  • subject:
  • message_text:
  • worker_ids: Array
    • List of MTurk Worker IDs.

rejectAssignments

Parameters
  • assignment_ids: Array
    • List of MTurk Assignment IDs.
  • requester_feedback:

renameCredentials

Parameters
  • credentials_id: String
    • Tutti's internal hash ID for registered MTurk credentials.
  • label:

sendBonus

Parameters
  • worker_ids: Array
    • List of MTurk Worker IDs.
  • bonus_amount:
  • assignment_ids: Array
    • List of MTurk Assignment IDs.
  • reason:

setActiveCredentials

Parameters
  • credentials_id: String
    • Tutti's internal hash ID for registered MTurk credentials.

setActiveSandboxMode

Parameters
  • is_sandbox: Boolean
    • Activation of Sandbox mode for MTurk credentials.

About

JavaScript client library for Tutti.ai.

Resources

Stars

Watchers

Forks

Packages

No packages published