useThreads
Vue 3 composable for listing and mutating CopilotKit threads
Open your coding agent in your project's folder, or in an empty folder for a new app.This runs in a coding agent on your computer.
Overview
useThreads is a Vue 3 composable for reading the active thread list for an agent and mutating that list from the client. It accepts reactive inputs for a required agent id, archived filter, page size, and an enabled flag. When enabled is false, the hook clears its thread-store context and skips /threads entirely; that is how the threads drawer stays idle while unlicensed.
useThreads activates when the connected runtime provides the thread endpoints it needs. It stays idle when the runtime explicitly reports that thread listing is unavailable.
The hook returns normalized thread records with only the fields the Vue UI consumes: id, agentId, name, archived, createdAt, updatedAt, and optional lastRunAt. Threads are ordered by lastRunAt, then updatedAt, then createdAt.
error includes runtime and configuration problems such as a missing runtime
URL or unsupported thread endpoints. listError only reports genuine list
and mutation failures from the thread store.
Signature
import { useThreads } from "@copilotkit/vue/v2";
function useThreads(input: UseThreadsInput): UseThreadsResult;Parameters
Prop
Type
Return Value
Prop
Type
Usage
Listing threads
<script setup lang="ts">
import { computed } from "vue";
import { useThreads } from "@copilotkit/vue/v2";
const { threads, isLoading, listError, refetchThreads } = useThreads({
agentId: "support-agent",
includeArchived: true,
limit: 20,
});
const activeThreads = computed(() =>
threads.value.filter((thread) => !thread.archived),
);
</script>Paginating manually
<script setup lang="ts">
import { useThreads } from "@copilotkit/vue/v2";
const { hasMoreThreads, fetchMoreThreads, fetchMoreError } = useThreads({
agentId: "support-agent",
limit: 20,
});
</script>Behavior
- The hook stays reactive to
agentId,includeArchived,limit, andenabled. - When the runtime URL is missing or the runtime reports thread endpoints as unsupported,
erroris set andlistErrorstays focused on store failures. enabled: falseclears the thread-store context and skips/threads; that is what keeps unlicensed thread drawers from fetching.- Mutations are optimistic in the core store. Delete rolls back if the request fails.
fetchMoreErroris tracked separately so a failed "load more" request can show inline without losing the loaded list.- Threads are sorted by
lastRunAt, thenupdatedAt, thencreatedAt.
Related
CopilotKitProvider
Configure the runtime URL that powers thread syncing. For cloud-hosted Intelligence, keep CPK_INTELLIGENCE_API_KEY on the runtime server.
CopilotThreadsDrawer
Use the prebuilt drawer that lists and manages threads with this composable.
useAgent
Access and run the agent whose threads you are listing.
useCopilotChatConfiguration
Read the shared chat configuration context.