Skip to content

Commit fde9d49

Browse files
committed
Plot search and thread references
1 parent e08fe14 commit fde9d49

4 files changed

Lines changed: 68 additions & 0 deletions

File tree

.changeset/search-notes-links.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@plotday/twister": minor
3+
---
4+
5+
Added: Semantic search tool for notes and links in the Plot tool, with configurable limit, threshold, and priority scope
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@plotday/twister": minor
3+
---
4+
5+
Added: Thread reference action type for navigating to related threads

twister/src/plot.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ export enum ActionType {
180180
conferencing = "conferencing",
181181
/** File attachment links stored in R2 */
182182
file = "file",
183+
/** Thread reference links for navigating to related threads */
184+
thread = "thread",
183185
}
184186

185187
/**
@@ -288,6 +290,12 @@ export type Action =
288290
fileSize: number;
289291
/** MIME type of the file */
290292
mimeType: string;
293+
}
294+
| {
295+
/** Thread reference action for navigating to a related thread */
296+
type: ActionType.thread;
297+
/** UUID of the referenced thread */
298+
threadId: Uuid;
291299
};
292300

293301
/**

twister/src/tools/plot.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,42 @@ export type LinkFilter = {
8383
limit?: number;
8484
};
8585

86+
type SearchResultBase = {
87+
thread: { id: string; title: string | null };
88+
priority: { id: string; title: string | null };
89+
similarity: number;
90+
};
91+
92+
export type NoteSearchResult = SearchResultBase & {
93+
type: 'note';
94+
id: string;
95+
content: string | null;
96+
};
97+
98+
export type LinkSearchResult = SearchResultBase & {
99+
type: 'link';
100+
id: string;
101+
title: string | null;
102+
sourceUrl: string | null;
103+
content: string | null;
104+
};
105+
106+
export type SearchResult = NoteSearchResult | LinkSearchResult;
107+
108+
/** Default number of search results returned */
109+
export const SEARCH_DEFAULT_LIMIT = 10;
110+
/** Maximum number of search results allowed */
111+
export const SEARCH_MAX_LIMIT = 30;
112+
113+
export type SearchOptions = {
114+
/** Max results to return (default: 10, max: 30) */
115+
limit?: number;
116+
/** Minimum similarity score 0-1 (default: 0.3) */
117+
threshold?: number;
118+
/** Scope search to this priority + descendants (default: twist's installed priority). Must be within the twist's allowed scope. */
119+
priorityId?: string;
120+
};
121+
86122
/**
87123
* Built-in tool for interacting with the core Plot data layer.
88124
*
@@ -197,6 +233,8 @@ export abstract class Plot extends ITool {
197233
contact?: {
198234
access?: ContactAccess;
199235
};
236+
/** Enable semantic search across notes and links in the twist's priority scope. */
237+
search?: true;
200238
};
201239

202240
/**
@@ -518,4 +556,16 @@ export abstract class Plot extends ITool {
518556
*/
519557
// eslint-disable-next-line @typescript-eslint/no-unused-vars
520558
abstract getLinks(filter?: LinkFilter): Promise<Array<{ link: Link; notes: Note[] }>>;
559+
560+
/**
561+
* Searches notes and links using semantic similarity.
562+
*
563+
* Requires `search: true` in Plot options.
564+
*
565+
* @param query - The search query text
566+
* @param options - Optional search configuration
567+
* @returns Promise resolving to array of search results ordered by similarity
568+
*/
569+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
570+
abstract search(query: string, options?: SearchOptions): Promise<SearchResult[]>;
521571
}

0 commit comments

Comments
 (0)