|
4 | 4 |
|
5 | 5 | import { RequesterProtocol } from '../client-types'; |
6 | 6 | import { buildParams } from '../utils'; |
7 | | -import { ListSpacesOutput, ListSpacesOutputSchema, Space, SpaceSchema } from '../types'; |
| 7 | +import { |
| 8 | + ListSpacesOutput, |
| 9 | + ListSpacesOutputSchema, |
| 10 | + SearchResultBlockItem, |
| 11 | + SearchResultBlockItemSchema, |
| 12 | + Space, |
| 13 | + SpaceSchema, |
| 14 | + SpaceSearchResult, |
| 15 | + SpaceSearchResultSchema, |
| 16 | +} from '../types'; |
8 | 17 |
|
9 | 18 | export class SpacesAPI { |
10 | | - constructor(private requester: RequesterProtocol) {} |
| 19 | + constructor(private requester: RequesterProtocol) { } |
11 | 20 |
|
12 | 21 | async list(options?: { |
13 | 22 | limit?: number | null; |
@@ -58,5 +67,107 @@ export class SpacesAPI { |
58 | 67 | const data = await this.requester.request('GET', `/space/${spaceId}/configs`); |
59 | 68 | return SpaceSchema.parse(data); |
60 | 69 | } |
| 70 | + |
| 71 | + /** |
| 72 | + * Perform experience search within a space. |
| 73 | + * |
| 74 | + * This is the most advanced search option that can operate in two modes: |
| 75 | + * - fast: Quick semantic search (default) |
| 76 | + * - agentic: Iterative search with AI-powered refinement |
| 77 | + * |
| 78 | + * @param spaceId - The UUID of the space |
| 79 | + * @param options - Search options |
| 80 | + * @returns SpaceSearchResult containing cited blocks and optional final answer |
| 81 | + */ |
| 82 | + async experienceSearch( |
| 83 | + spaceId: string, |
| 84 | + options: { |
| 85 | + query: string; |
| 86 | + limit?: number | null; |
| 87 | + mode?: 'fast' | 'agentic' | null; |
| 88 | + semanticThreshold?: number | null; |
| 89 | + maxIterations?: number | null; |
| 90 | + } |
| 91 | + ): Promise<SpaceSearchResult> { |
| 92 | + const params = buildParams({ |
| 93 | + query: options.query, |
| 94 | + limit: options.limit ?? null, |
| 95 | + mode: options.mode ?? null, |
| 96 | + semantic_threshold: options.semanticThreshold ?? null, |
| 97 | + max_iterations: options.maxIterations ?? null, |
| 98 | + }); |
| 99 | + const data = await this.requester.request( |
| 100 | + 'GET', |
| 101 | + `/space/${spaceId}/experience_search`, |
| 102 | + { params: Object.keys(params).length > 0 ? params : undefined } |
| 103 | + ); |
| 104 | + return SpaceSearchResultSchema.parse(data); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Perform semantic global (glob) search for page/folder titles. |
| 109 | + * |
| 110 | + * Searches specifically for page/folder titles using semantic similarity, |
| 111 | + * similar to a semantic version of the glob command. |
| 112 | + * |
| 113 | + * @param spaceId - The UUID of the space |
| 114 | + * @param options - Search options |
| 115 | + * @returns List of SearchResultBlockItem objects matching the query |
| 116 | + */ |
| 117 | + async semanticGlobal( |
| 118 | + spaceId: string, |
| 119 | + options: { |
| 120 | + query: string; |
| 121 | + limit?: number | null; |
| 122 | + threshold?: number | null; |
| 123 | + } |
| 124 | + ): Promise<SearchResultBlockItem[]> { |
| 125 | + const params = buildParams({ |
| 126 | + query: options.query, |
| 127 | + limit: options.limit ?? null, |
| 128 | + threshold: options.threshold ?? null, |
| 129 | + }); |
| 130 | + const data = await this.requester.request( |
| 131 | + 'GET', |
| 132 | + `/space/${spaceId}/semantic_global`, |
| 133 | + { params: Object.keys(params).length > 0 ? params : undefined } |
| 134 | + ); |
| 135 | + return (data as unknown[]).map((item) => |
| 136 | + SearchResultBlockItemSchema.parse(item) |
| 137 | + ); |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * Perform semantic grep search for content blocks. |
| 142 | + * |
| 143 | + * Searches through content blocks (actual text content) using semantic similarity, |
| 144 | + * similar to a semantic version of the grep command. |
| 145 | + * |
| 146 | + * @param spaceId - The UUID of the space |
| 147 | + * @param options - Search options |
| 148 | + * @returns List of SearchResultBlockItem objects matching the query |
| 149 | + */ |
| 150 | + async semanticGrep( |
| 151 | + spaceId: string, |
| 152 | + options: { |
| 153 | + query: string; |
| 154 | + limit?: number | null; |
| 155 | + threshold?: number | null; |
| 156 | + } |
| 157 | + ): Promise<SearchResultBlockItem[]> { |
| 158 | + const params = buildParams({ |
| 159 | + query: options.query, |
| 160 | + limit: options.limit ?? null, |
| 161 | + threshold: options.threshold ?? null, |
| 162 | + }); |
| 163 | + const data = await this.requester.request( |
| 164 | + 'GET', |
| 165 | + `/space/${spaceId}/semantic_grep`, |
| 166 | + { params: Object.keys(params).length > 0 ? params : undefined } |
| 167 | + ); |
| 168 | + return (data as unknown[]).map((item) => |
| 169 | + SearchResultBlockItemSchema.parse(item) |
| 170 | + ); |
| 171 | + } |
61 | 172 | } |
62 | 173 |
|
0 commit comments