showcase/shell-docs/src/content/reference/vue/hooks/useThreads.mdx
<OpsPlatformCTA variant="card" title="useThreads needs an Enterprise Intelligence Platform project" body="Sign up for a free account to get a public license key and start syncing threads." ctaLabel="Create a free account" surface="docs_reference_vue_use_threads" />
useThreads is a Vue 3 composable for managing conversation threads on the Enterprise Intelligence Platform. It fetches the thread list for a given agent, keeps it synchronized in realtime via the core thread store's realtime channel, and exposes mutation methods for renaming, archiving, and deleting threads.
Threads are sorted by recency — by lastRunAt when present, falling back to updatedAt, then createdAt (most recent first). The composable supports cursor-based pagination when a limit is provided. All inputs accept refs, computeds, or getters (MaybeRefOrGetter), so changing the thread context reactively re-fetches the list.
import { useThreads } from "@copilotkit/vue/v2";
function useThreads(input: UseThreadsInput): UseThreadsResult
<script setup lang="ts">
import { useThreads } from "@copilotkit/vue/v2"; // [!code highlight]
const {
threads,
isLoading,
renameThread,
archiveThread,
deleteThread,
} = useThreads({ agentId: "my-agent" }); // [!code highlight]
</script>
<template>
<div v-if="isLoading">Loading threads...</div>
<ul v-else>
<li v-for="thread in threads" :key="thread.id">
<span>{{ thread.name ?? "Untitled" }}</span>
<button @click="renameThread(thread.id, 'New name')">Rename</button>
<button @click="archiveThread(thread.id)">Archive</button>
<button @click="deleteThread(thread.id)">Delete</button>
</li>
</ul>
</template>
Because inputs accept refs and getters, you can drive the thread list from reactive state. Switching agentId automatically re-fetches the list.
<script setup lang="ts">
import { ref } from "vue";
import { useThreads } from "@copilotkit/vue/v2";
const agentId = ref("support-agent");
const includeArchived = ref(false);
const { threads, hasMoreThreads, fetchMoreThreads } = useThreads({
agentId, // ref -- changing it re-fetches threads
includeArchived,
limit: 20,
});
</script>
<template>
<select v-model="agentId">
<option value="support-agent">Support</option>
<option value="sales-agent">Sales</option>
</select>
<label>
<input type="checkbox" v-model="includeArchived" />
Show archived
</label>
<ul>
<li v-for="thread in threads" :key="thread.id">
{{ thread.name ?? "Untitled" }}
</li>
</ul>
<button v-if="hasMoreThreads" @click="fetchMoreThreads">Load more</button>
</template>
isLoading stays true to avoid an empty-list flash.error reports a configuration error and the thread store is cleared.threads array stays sorted by recency descending — by lastRunAt when present, falling back to updatedAt, then createdAt.generateThreadNames on the runtime.onScopeDispose).