Creating Plot Twists
    Preparing search index...

    Class PlotAbstract

    Built-in tool for interacting with the core Plot data layer.

    The Plot tool provides twists with the ability to create and manage threads, priorities, and contacts within the Plot system. This is the primary interface for twists to persist data and interact with the Plot database.

    class MyTwist extends Twist {
    private plot: Plot;

    constructor(id: string, tools: ToolBuilder) {
    super();
    this.plot = tools.get(Plot);
    }

    async activate() {
    // Create a welcome thread
    await this.plot.createThread({
    title: "Welcome to Plot!",
    actions: [{
    title: "Get Started",
    type: ActionType.external,
    url: "https://plot.day/docs"
    }]
    });
    }
    }

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    • Creates a new thread in the Plot system.

      The thread will be automatically assigned an ID and author information based on the current execution context. All other fields from NewThread will be preserved in the created thread.

      Parameters

      Returns Promise<Uuid>

      Promise resolving to the created thread's ID

    • Creates multiple threads in a single batch operation.

      This method efficiently creates multiple threads at once, which is more performant than calling createThread() multiple times individually. All threads are created with the same author and access control rules.

      Parameters

      Returns Promise<Uuid[]>

      Promise resolving to array of created thread IDs

    • Updates an existing thread in the Plot system.

      Important: This method only updates existing threads. It will throw an error if the thread does not exist. Use createThread() to create or update (upsert) threads.

      Only the fields provided in the update object will be modified - all other fields remain unchanged. This enables partial updates without needing to fetch and resend the entire thread object.

      For tags, provide a Record<number, boolean> where true adds a tag and false removes it. Tags not included in the update remain unchanged.

      When updating the parent, the thread's path will be automatically recalculated to maintain the correct hierarchical structure.

      Scheduling is handled separately via createSchedule() / updateSchedule().

      Parameters

      • thread: ThreadUpdate

        The thread update containing the ID or source and fields to change

      Returns Promise<void>

      Promise that resolves when the update is complete

      Error if the thread does not exist

      // Mark a task as complete
      await this.plot.updateThread({
      id: "task-123",
      done: new Date()
      });

      // Add and remove tags
      await this.plot.updateThread({
      id: "thread-789",
      tags: {
      1: true, // Add tag with ID 1
      2: false // Remove tag with ID 2
      }
      });
    • Retrieves all notes within a thread.

      Notes are detailed entries within a thread, ordered by creation time. Each note can contain markdown content, actions, and other detailed information related to the parent thread.

      Parameters

      • thread: ThreadFields

        The thread whose notes to retrieve

      Returns Promise<Note[]>

      Promise resolving to array of notes in the thread

    • Creates a new note in a thread.

      Notes provide detailed content within a thread, supporting markdown, actions, and other rich content. The note will be automatically assigned an ID and author information based on the current execution context.

      Parameters

      • note: NewNote

        The note data to create

      Returns Promise<Uuid>

      Promise resolving to the created note's ID

      // Create a note with content
      await this.plot.createNote({
      thread: { id: "thread-123" },
      note: "Discussion notes from the meeting...",
      contentType: "markdown"
      });

      // Create a note with actions
      await this.plot.createNote({
      thread: { id: "thread-456" },
      note: "Meeting recording available",
      actions: [{
      type: ActionType.external,
      title: "View Recording",
      url: "https://example.com/recording"
      }]
      });
    • Creates multiple notes in a single batch operation.

      This method efficiently creates multiple notes at once, which is more performant than calling createNote() multiple times individually. All notes are created with the same author and access control rules.

      Parameters

      • notes: NewNote[]

        Array of note data to create

      Returns Promise<Uuid[]>

      Promise resolving to array of created note IDs

      // Create multiple notes in one batch
      await this.plot.createNotes([
      {
      thread: { id: "thread-123" },
      note: "First message in thread"
      },
      {
      thread: { id: "thread-123" },
      note: "Second message in thread"
      }
      ]);
    • Updates an existing note in the Plot system.

      Important: This method only updates existing notes. It will throw an error if the note does not exist. Use createNote() to create or update (upsert) notes.

      Only the fields provided in the update object will be modified - all other fields remain unchanged. This enables partial updates without needing to fetch and resend the entire note object.

      Parameters

      • note: NoteUpdate

        The note update containing the ID or key and fields to change

      Returns Promise<void>

      Promise that resolves when the update is complete

      Error if the note does not exist

      // Update note content
      await this.plot.updateNote({
      id: "note-123",
      note: "Updated content with more details"
      });

      // Add tags to a note
      await this.plot.updateNote({
      id: "note-456",
      twistTags: {
      [Tag.Important]: true
      }
      });
    • Retrieves a thread by ID or source.

      This method enables lookup of threads either by their unique ID or by their source identifier (canonical URL from an external system). Archived threads are included in the results.

      Parameters

      • thread: { id: Uuid } | { source: string }

        Thread lookup by ID or source

      Returns Promise<ThreadFields | null>

      Promise resolving to the matching thread or null if not found

    • Retrieves a note by ID or key.

      This method enables lookup of notes either by their unique ID or by their key (unique identifier within the thread). Archived notes are included in the results.

      Parameters

      • note: { id: Uuid } | { key: string }

        Note lookup by ID or key

      Returns Promise<Note | null>

      Promise resolving to the matching note or null if not found

    • Creates a new priority in the Plot system.

      Priorities serve as organizational containers for threads and twists. The created priority will be automatically assigned a unique ID.

      Parameters

      Returns Promise<Priority & { created: boolean }>

      Promise resolving to the complete created priority

    • Retrieves a priority by ID or key.

      Archived priorities are included in the results.

      Parameters

      • priority: { id: Uuid } | { key: string }

        Priority lookup by ID or key

      Returns Promise<Priority | null>

      Promise resolving to the matching priority or null if not found

    • Updates an existing priority in the Plot system.

      The priority is identified by either its ID or key. Only the fields specified in the update will be changed.

      Parameters

      • update: PriorityUpdate

        Priority update containing ID/key and fields to change

      Returns Promise<void>

      Promise that resolves when the update is complete

    • Retrieves actors by their IDs.

      Actors represent users, contacts, or twists in the Plot system. This method requires ContactAccess.Read permission.

      Parameters

      • ids: ActorId[]

        Array of actor IDs to retrieve

      Returns Promise<Actor[]>

      Promise resolving to array of actors

    • Returns the full Actor for the user who installed this twist. Useful for per-user operations like schedule creation, or when the owner's name or email is needed.

      Returns Promise<Actor>

    • Returns the user ID (twist_instance.owner_id) that installed this twist. This is the same value exposed on Twist via this.userId.

      Returns Promise<string>

    • Returns the owner user's root priority ID. Used as the implicit default when an operation needs a priority but the caller didn't supply one — for example, plot.createPriority() without a parent, or plot.getThreads() without an explicit priorityId.

      On the server, priority resolution for newly created threads/links happens automatically via match_priority_for_user; twists rarely need to call this directly.

      Returns Promise<string>

    • Creates a new schedule for a thread.

      Schedules define when a thread occurs in time. A thread can have multiple schedules (shared and per-user).

      Parameters

      Returns Promise<Schedule>

      Promise resolving to the created schedule

      // Schedule a timed event
      const threadId = await this.plot.createThread({
      title: "Team standup"
      });
      await this.plot.createSchedule({
      threadId,
      start: new Date("2025-01-15T10:00:00Z"),
      end: new Date("2025-01-15T10:30:00Z"),
      recurrenceRule: "FREQ=DAILY;BYDAY=MO,TU,WE,TH,FR"
      });
    • Retrieves all schedules for a thread.

      Parameters

      • threadId: Uuid

        The thread whose schedules to retrieve

      Returns Promise<Schedule[]>

      Promise resolving to array of schedules for the thread

    • Retrieves links from connected source channels.

      Requires link: true in Plot options.

      Parameters

      • Optionalfilter: LinkFilter

        Optional filter criteria for links

      Returns Promise<{ link: Link; notes: Note[] }[]>

      Promise resolving to array of links with their notes

    • Searches notes and links using semantic similarity.

      Requires search: true in Plot options.

      Parameters

      • query: string

        The search query text

      • Optionaloptions: SearchOptions

        Optional search configuration

      Returns Promise<SearchResult[]>

      Promise resolving to array of search results ordered by similarity

    • Lists threads owned by the twist's user.

      Requires ThreadAccess.Full.

      Parameters

      • Optionaloptions: {
            priorityId?: Uuid;
            includeDescendants?: boolean;
            includeArchived?: boolean;
            limit?: number;
            offset?: number;
        }

        Query options for filtering threads

        • OptionalpriorityId?: Uuid

          Priority to list threads from. Must be owned by the twist owner. When omitted, defaults to the owner's root priority.

        • OptionalincludeDescendants?: boolean

          Include threads from descendant priorities. Default: true.

        • OptionalincludeArchived?: boolean

          Include archived threads. Default: false.

        • Optionallimit?: number

          Maximum number of threads to return. Default: 50, max: 200.

        • Optionaloffset?: number

          Number of threads to skip for pagination. Default: 0.

      Returns Promise<ThreadFields[]>

      Promise resolving to array of threads

    • Lists priorities owned by the twist's user.

      Requires PriorityAccess.Full.

      Parameters

      • Optionaloptions: { parentId?: Uuid; includeDescendants?: boolean; includeArchived?: boolean }

        Query options for filtering priorities

        • OptionalparentId?: Uuid

          Parent priority to list children of. Must be owned by the twist owner. When omitted, defaults to the owner's root priority.

        • OptionalincludeDescendants?: boolean

          Include all descendants, not just direct children. Default: false.

        • OptionalincludeArchived?: boolean

          Include archived priorities. Default: false.

      Returns Promise<Priority[]>

      Promise resolving to array of priorities

    • Updates a link.

      Requires LinkAccess.Full. Set threadId to move the link to a different thread.

      Parameters

      • link: LinkUpdate

        The link update containing the ID and fields to change

      Returns Promise<void>

      Promise that resolves when the update is complete

    • Creates a plan of operations for user approval.

      Returns an Action that can be attached to a note. The user can approve, deny, or request changes. On approval, operations are executed by the API.

      Requires requireApproval: true in Plot options.

      Parameters

      • options: { title: string; operations: PlanOperation[]; callback: Callback }

        Plan configuration

        • title: string

          Human-readable title summarizing the plan

        • operations: PlanOperation[]

          Array of operations to execute on approval

        • callback: Callback

          Callback invoked with (action, approved: boolean) when the user responds

      Returns Action

      An Action of type plan to attach to a note

    Properties

    Options: {
        thread?: { access?: ThreadAccess; defaultMention?: boolean };
        note?: { defaultMention?: boolean; intents?: NoteIntentHandler[] };
        link?: true | { access?: LinkAccess };
        priority?: { access?: PriorityAccess };
        contact?: { access?: Read };
        search?: true;
        requireApproval?: boolean;
    }

    Configuration options for the Plot tool.

    Important: All permissions must be explicitly requested. There are no default permissions.

    Type Declaration

    • Optionalthread?: { access?: ThreadAccess; defaultMention?: boolean }
      • Optionalaccess?: ThreadAccess

        Capability to create Notes and modify tags. Must be explicitly set to grant permissions.

      • OptionaldefaultMention?: boolean

        When true, auto-mention this twist on new notes in threads where it authored content.

    • Optionalnote?: { defaultMention?: boolean; intents?: NoteIntentHandler[] }
      • OptionaldefaultMention?: boolean

        When true, auto-mention this twist on new notes in threads where it was @-mentioned.

      • Optionalintents?: NoteIntentHandler[]

        Respond to mentions in notes.

        When a note mentions this twist, the system will match the note content against these intents and call the matching handler.

        intents: [{
        description: "Schedule or reschedule calendar events",
        examples: ["Schedule a meeting tomorrow at 2pm", "Move my 3pm meeting to 4pm"],
        handler: this.onSchedulingRequest
        }, {
        description: "Find available meeting times",
        examples: ["When am I free this week?", "Find time for a 1 hour meeting"],
        handler: this.onAvailabilityRequest
        }]
    • Optionallink?: true | { access?: LinkAccess }

      Enable link processing from connected source channels.

    • Optionalpriority?: { access?: PriorityAccess }
    • Optionalcontact?: { access?: Read }
    • Optionalsearch?: true

      Enable semantic search across notes and links owned by the twist's user.

    • OptionalrequireApproval?: boolean

      When true, admin write operations (on threads/notes/links/priorities not created by this twist) require user approval via plan actions instead of executing immediately. Read operations and operations on the twist's own content still work directly.

    // Minimal configuration with required permissions
    build(build: ToolBuilder) {
    return {
    plot: build(Plot, {
    thread: {
    access: ThreadAccess.Create
    }
    })
    };
    }

    // Full configuration with callbacks
    build(build: ToolBuilder) {
    return {
    plot: build(Plot, {
    thread: {
    access: ThreadAccess.Create,
    },
    note: {
    intents: [{
    description: "Schedule meetings",
    examples: ["Schedule a meeting tomorrow"],
    handler: this.onSchedulingIntent
    }],
    },
    link: true,
    priority: {
    access: PriorityAccess.Full
    },
    contact: {
    access: ContactAccess.Read
    }
    })
    };
    }