@dbx-tools/search 0.9.5 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -10
- package/index.ts +2 -2
- package/lib/index.d.ts +2 -2
- package/lib/index.js +3 -3
- package/lib/src/client.js +11 -11
- package/lib/src/config.js +15 -15
- package/lib/src/index-options.js +34 -0
- package/lib/src/lakebase-plugin.js +7 -7
- package/lib/src/lakebase.js +7 -7
- package/lib/src/native.js +5 -5
- package/lib/src/plugin.d.ts +16 -19
- package/lib/src/plugin.js +30 -38
- package/lib/src/runtime.d.ts +0 -12
- package/lib/src/runtime.js +1 -17
- package/lib/src/schema.js +14 -14
- package/lib/src/tool.js +6 -6
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/client.ts +10 -10
- package/src/config.ts +28 -17
- package/src/lakebase-plugin.ts +6 -6
- package/src/lakebase.ts +9 -6
- package/src/native.ts +4 -4
- package/src/plugin.ts +33 -51
- package/src/runtime.ts +0 -18
- package/src/schema.ts +13 -13
- package/src/tool.ts +5 -5
- package/lib/src/index-tools.js +0 -34
- /package/lib/src/{index-tools.d.ts → index-options.d.ts} +0 -0
- /package/src/{index-tools.ts → index-options.ts} +0 -0
package/src/plugin.ts
CHANGED
|
@@ -21,22 +21,14 @@
|
|
|
21
21
|
* @module
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
toolsFromRegistry,
|
|
30
|
-
type AgentToolDefinition,
|
|
31
|
-
type ToolProvider,
|
|
32
|
-
type ToolRegistry,
|
|
33
|
-
} from "@databricks/appkit/beta";
|
|
34
|
-
import { plugin as appkitPlugin } from "@dbx-tools/appkit";
|
|
35
|
-
import { error as sharedError, log, string } from "@dbx-tools/shared-core";
|
|
36
|
-
import { search as sharedSearch, type SearchClientConfig } from "@dbx-tools/shared-search";
|
|
24
|
+
import { toPlugin, type IAppRouter, type PluginManifest } from "@databricks/appkit";
|
|
25
|
+
import { aiSearch, defineTool, type ToolRegistry } from "@databricks/appkit/beta";
|
|
26
|
+
import { pluginRegistry, ToolRegistryPlugin } from "@dbx-tools/appkit";
|
|
27
|
+
import { errorUtils, log, stringUtils } from "@dbx-tools/shared-core";
|
|
28
|
+
import { searchSchemas, type SearchClientConfig } from "@dbx-tools/shared-search";
|
|
37
29
|
import { toSearchOptions, toUniversalSearchOptions } from "./_search-options.ts";
|
|
38
30
|
import { SEARCH_CONFIG_SCHEMA, resolveSearchConfig, type SearchPluginConfig } from "./config.ts";
|
|
39
|
-
import { toCreateIndexOptions } from "./index-
|
|
31
|
+
import { toCreateIndexOptions } from "./index-options.ts";
|
|
40
32
|
import { nativeAiSearchBackend } from "./native.ts";
|
|
41
33
|
import { toDocumentArray } from "./query.ts";
|
|
42
34
|
import { createSearchRuntime, setSearchReadBackend, type SearchRuntime } from "./runtime.ts";
|
|
@@ -74,7 +66,7 @@ const INDEX_SYNC_ROUTE = "/index/sync";
|
|
|
74
66
|
* ```ts
|
|
75
67
|
* import { createApp, server } from "@databricks/appkit";
|
|
76
68
|
* import { aiSearch } from "@databricks/appkit/beta";
|
|
77
|
-
* import {
|
|
69
|
+
* import { search } from "@dbx-tools/search";
|
|
78
70
|
*
|
|
79
71
|
* await createApp({
|
|
80
72
|
* plugins: [
|
|
@@ -87,7 +79,7 @@ const INDEX_SYNC_ROUTE = "/index/sync";
|
|
|
87
79
|
* },
|
|
88
80
|
* },
|
|
89
81
|
* }),
|
|
90
|
-
*
|
|
82
|
+
* search({
|
|
91
83
|
* index: "main.support.docs",
|
|
92
84
|
* indexes: [{ name: "main.support.docs", alias: "docs" }],
|
|
93
85
|
* }),
|
|
@@ -95,7 +87,7 @@ const INDEX_SYNC_ROUTE = "/index/sync";
|
|
|
95
87
|
* });
|
|
96
88
|
* ```
|
|
97
89
|
*/
|
|
98
|
-
export class SearchPlugin extends
|
|
90
|
+
export class SearchPlugin extends ToolRegistryPlugin<SearchPluginConfig> {
|
|
99
91
|
static manifest = {
|
|
100
92
|
name: "search",
|
|
101
93
|
displayName: "AI Search",
|
|
@@ -125,19 +117,19 @@ export class SearchPlugin extends Plugin<SearchPluginConfig> implements ToolProv
|
|
|
125
117
|
* autoInheritable: every tool runs under the caller's identity, so it must be
|
|
126
118
|
* granted explicitly.
|
|
127
119
|
*/
|
|
128
|
-
|
|
120
|
+
protected get toolRegistry(): ToolRegistry {
|
|
129
121
|
const { config, readBackend } = this.runtime;
|
|
130
122
|
const registry: ToolRegistry = {
|
|
131
123
|
search: defineTool({
|
|
132
124
|
description: SEARCH_TOOL_DESCRIPTION,
|
|
133
|
-
schema:
|
|
125
|
+
schema: searchSchemas.searchRequestSchema,
|
|
134
126
|
annotations: { effect: "read", requiresUserContext: true },
|
|
135
127
|
autoInheritable: false,
|
|
136
128
|
execute: async (args, signal) => this.runSearch(args, signal),
|
|
137
129
|
}),
|
|
138
130
|
universal_search: defineTool({
|
|
139
131
|
description: UNIVERSAL_SEARCH_TOOL_DESCRIPTION,
|
|
140
|
-
schema:
|
|
132
|
+
schema: searchSchemas.universalSearchRequestSchema,
|
|
141
133
|
annotations: { effect: "read", requiresUserContext: true },
|
|
142
134
|
autoInheritable: false,
|
|
143
135
|
execute: async (args, signal) => this.runUniversalSearch(args, signal),
|
|
@@ -146,9 +138,9 @@ export class SearchPlugin extends Plugin<SearchPluginConfig> implements ToolProv
|
|
|
146
138
|
if (config.allowWrite) {
|
|
147
139
|
registry.add_documents = defineTool({
|
|
148
140
|
description: ADD_DOCUMENTS_TOOL_DESCRIPTION,
|
|
149
|
-
schema:
|
|
141
|
+
schema: searchSchemas.searchRequestSchema
|
|
150
142
|
.pick({ index: true })
|
|
151
|
-
.extend({ documents:
|
|
143
|
+
.extend({ documents: searchSchemas.searchDocumentSchema.array() }),
|
|
152
144
|
annotations: { effect: "write", requiresUserContext: true },
|
|
153
145
|
autoInheritable: false,
|
|
154
146
|
execute: async (args, signal) => this.runAddDocuments(args, signal),
|
|
@@ -156,14 +148,14 @@ export class SearchPlugin extends Plugin<SearchPluginConfig> implements ToolProv
|
|
|
156
148
|
if (readBackend?.supportsLifecycle) {
|
|
157
149
|
registry.create_index = defineTool({
|
|
158
150
|
description: CREATE_INDEX_TOOL_DESCRIPTION,
|
|
159
|
-
schema:
|
|
151
|
+
schema: searchSchemas.createIndexRequestSchema,
|
|
160
152
|
annotations: { effect: "write", requiresUserContext: true },
|
|
161
153
|
autoInheritable: false,
|
|
162
154
|
execute: async (args, signal) => this.runCreateIndex(args, signal),
|
|
163
155
|
});
|
|
164
156
|
registry.sync_index = defineTool({
|
|
165
157
|
description: SYNC_INDEX_TOOL_DESCRIPTION,
|
|
166
|
-
schema:
|
|
158
|
+
schema: searchSchemas.syncIndexRequestSchema,
|
|
167
159
|
annotations: { effect: "write", requiresUserContext: true },
|
|
168
160
|
autoInheritable: false,
|
|
169
161
|
execute: async (args, signal) => this.runSyncIndex(args, signal),
|
|
@@ -199,7 +191,7 @@ export class SearchPlugin extends Plugin<SearchPluginConfig> implements ToolProv
|
|
|
199
191
|
|
|
200
192
|
/** Resolve the registered AppKit-compatible AI Search provider. */
|
|
201
193
|
private resolveProviderBackend(): ReturnType<typeof nativeAiSearchBackend> {
|
|
202
|
-
const provider =
|
|
194
|
+
const provider = pluginRegistry.require(this.context, aiSearch, this).exports();
|
|
203
195
|
return nativeAiSearchBackend(provider, resolveSearchConfig(this.config));
|
|
204
196
|
}
|
|
205
197
|
|
|
@@ -212,7 +204,7 @@ export class SearchPlugin extends Plugin<SearchPluginConfig> implements ToolProv
|
|
|
212
204
|
private async runEnsureOnSetup(config: SearchRuntime["config"]): Promise<void> {
|
|
213
205
|
const spec = config.ensureOnSetup;
|
|
214
206
|
if (!spec) return;
|
|
215
|
-
const index =
|
|
207
|
+
const index = stringUtils.trimToNull(spec.index) ?? config.defaultIndex;
|
|
216
208
|
if (!index) {
|
|
217
209
|
logger.warn("ensure-skipped", {
|
|
218
210
|
reason: "no index name (set `index` or `ensureOnSetup.index`)",
|
|
@@ -245,7 +237,7 @@ export class SearchPlugin extends Plugin<SearchPluginConfig> implements ToolProv
|
|
|
245
237
|
rowCount: info.rowCount ?? 0,
|
|
246
238
|
});
|
|
247
239
|
} catch (cause) {
|
|
248
|
-
logger.warn("ensure-failed", { index, message:
|
|
240
|
+
logger.warn("ensure-failed", { index, message: errorUtils.errorMessage(cause) });
|
|
249
241
|
}
|
|
250
242
|
}
|
|
251
243
|
|
|
@@ -290,7 +282,7 @@ export class SearchPlugin extends Plugin<SearchPluginConfig> implements ToolProv
|
|
|
290
282
|
path: UNIVERSAL_ROUTE,
|
|
291
283
|
handler: async (req, res) => {
|
|
292
284
|
await this.respond(res, "universalSearch", () => {
|
|
293
|
-
const request =
|
|
285
|
+
const request = searchSchemas.universalSearchRequestSchema.parse(req.body ?? {});
|
|
294
286
|
return this.asUser(req).runUniversalSearch(request);
|
|
295
287
|
});
|
|
296
288
|
},
|
|
@@ -365,7 +357,7 @@ export class SearchPlugin extends Plugin<SearchPluginConfig> implements ToolProv
|
|
|
365
357
|
try {
|
|
366
358
|
res.json(await run());
|
|
367
359
|
} catch (cause) {
|
|
368
|
-
const message =
|
|
360
|
+
const message = errorUtils.errorMessage(cause);
|
|
369
361
|
logger.warn("route-failed", { operation, message });
|
|
370
362
|
res.status(500).json({ error: message });
|
|
371
363
|
}
|
|
@@ -389,44 +381,34 @@ export class SearchPlugin extends Plugin<SearchPluginConfig> implements ToolProv
|
|
|
389
381
|
return payload as unknown as Record<string, unknown>;
|
|
390
382
|
}
|
|
391
383
|
|
|
392
|
-
/** AppKit `ToolProvider`: the tool definitions offered to an agent. */
|
|
393
|
-
getAgentTools(): AgentToolDefinition[] {
|
|
394
|
-
return toolsFromRegistry(this.tools);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/** AppKit `ToolProvider`: run one tool call, validating input against its schema. */
|
|
398
|
-
async executeAgentTool(name: string, args: unknown, signal?: AbortSignal): Promise<unknown> {
|
|
399
|
-
return executeFromRegistry(this.tools, name, args, signal);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
384
|
override exports() {
|
|
403
385
|
return {
|
|
404
386
|
/** Search one index (default when omitted). Runs as the current context user. */
|
|
405
|
-
search: (request:
|
|
387
|
+
search: (request: searchSchemas.SearchRequest, signal?: AbortSignal) =>
|
|
406
388
|
this.runSearch(request, signal),
|
|
407
389
|
/** Search across every configured index and merge the hits. */
|
|
408
|
-
universalSearch: (request:
|
|
390
|
+
universalSearch: (request: searchSchemas.UniversalSearchRequest, signal?: AbortSignal) =>
|
|
409
391
|
this.runUniversalSearch(request, signal),
|
|
410
392
|
/** Add or update documents in a direct-access index (throws when writes are disabled). */
|
|
411
393
|
addDocuments: (request: { index?: string; documents: unknown }, signal?: AbortSignal) =>
|
|
412
394
|
this.runAddDocuments(request, signal),
|
|
413
395
|
/** Create a Vector Search index (throws when writes are disabled). */
|
|
414
|
-
createIndex: (request:
|
|
396
|
+
createIndex: (request: searchSchemas.CreateIndexRequest, signal?: AbortSignal) =>
|
|
415
397
|
this.runCreateIndex(request, signal),
|
|
416
398
|
/** Sync a Delta Sync index from its source table (throws when writes are disabled). */
|
|
417
|
-
syncIndex: (request:
|
|
399
|
+
syncIndex: (request: searchSchemas.SyncIndexRequest, signal?: AbortSignal) =>
|
|
418
400
|
this.runSyncIndex(request, signal),
|
|
419
401
|
};
|
|
420
402
|
}
|
|
421
403
|
|
|
422
404
|
private async runSearch(args: unknown, signal?: AbortSignal) {
|
|
423
|
-
const request =
|
|
405
|
+
const request = searchSchemas.searchRequestSchema.parse(args);
|
|
424
406
|
const { client } = this.runtime;
|
|
425
407
|
return client.search(request.query, toSearchOptions(request, signal));
|
|
426
408
|
}
|
|
427
409
|
|
|
428
410
|
private async runUniversalSearch(args: unknown, signal?: AbortSignal) {
|
|
429
|
-
const request =
|
|
411
|
+
const request = searchSchemas.universalSearchRequestSchema.parse(args);
|
|
430
412
|
const { client } = this.runtime;
|
|
431
413
|
return client.universalSearch(request.query, toUniversalSearchOptions(request, signal));
|
|
432
414
|
}
|
|
@@ -440,13 +422,13 @@ export class SearchPlugin extends Plugin<SearchPluginConfig> implements ToolProv
|
|
|
440
422
|
}
|
|
441
423
|
|
|
442
424
|
private async runCreateIndex(args: unknown, signal?: AbortSignal) {
|
|
443
|
-
const request =
|
|
425
|
+
const request = searchSchemas.createIndexRequestSchema.parse(args);
|
|
444
426
|
const { client } = this.runtime;
|
|
445
427
|
return client.createIndex(request.name, toCreateIndexOptions(request, signal));
|
|
446
428
|
}
|
|
447
429
|
|
|
448
430
|
private async runSyncIndex(args: unknown, signal?: AbortSignal) {
|
|
449
|
-
const request =
|
|
431
|
+
const request = searchSchemas.syncIndexRequestSchema.parse(args);
|
|
450
432
|
const { client, config } = this.runtime;
|
|
451
433
|
const index = request.index ?? config.defaultIndex ?? "";
|
|
452
434
|
await client.syncIndex(index, signal);
|
|
@@ -460,8 +442,8 @@ export class SearchPlugin extends Plugin<SearchPluginConfig> implements ToolProv
|
|
|
460
442
|
* @example
|
|
461
443
|
* ```ts
|
|
462
444
|
* import { createApp, server } from "@databricks/appkit";
|
|
463
|
-
* import {
|
|
464
|
-
* import { agents,
|
|
445
|
+
* import { search } from "@dbx-tools/search";
|
|
446
|
+
* import { agents, mastra } from "@dbx-tools/appkit-mastra";
|
|
465
447
|
*
|
|
466
448
|
* const support = agents.createAgent({
|
|
467
449
|
* instructions: "Answer from the docs; use `search` to find them.",
|
|
@@ -473,8 +455,8 @@ export class SearchPlugin extends Plugin<SearchPluginConfig> implements ToolProv
|
|
|
473
455
|
* await createApp({
|
|
474
456
|
* plugins: [
|
|
475
457
|
* server(),
|
|
476
|
-
*
|
|
477
|
-
*
|
|
458
|
+
* search({ index: "main.support.docs" }),
|
|
459
|
+
* mastra({ agents: support }),
|
|
478
460
|
* ],
|
|
479
461
|
* });
|
|
480
462
|
* ```
|
package/src/runtime.ts
CHANGED
|
@@ -43,21 +43,3 @@ export function setSearchReadBackend(runtime: SearchRuntime, readBackend: Search
|
|
|
43
43
|
runtime.readBackend = readBackend;
|
|
44
44
|
runtime.client = createSearchClient(runtime.config, undefined, readBackend);
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Build an isolated standalone runtime.
|
|
49
|
-
*
|
|
50
|
-
* @deprecated Use {@link createSearchRuntime}. This compatibility helper
|
|
51
|
-
* returns a new runtime on every call and never reads or updates plugin state.
|
|
52
|
-
*/
|
|
53
|
-
export function getSearchRuntime(options?: SearchRuntimeOptions): SearchRuntime {
|
|
54
|
-
return createSearchRuntime(options);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @deprecated Plugin runtimes are instance-owned and need no global reset.
|
|
59
|
-
* This compatibility helper is intentionally a no-op.
|
|
60
|
-
*/
|
|
61
|
-
export function resetSearchRuntime(): void {
|
|
62
|
-
return;
|
|
63
|
-
}
|
package/src/schema.ts
CHANGED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { stringUtils } from "@dbx-tools/shared-core";
|
|
11
|
+
import { searchSchemas } from "@dbx-tools/shared-search";
|
|
12
12
|
|
|
13
13
|
/** Description the model reads for the `search` tool. */
|
|
14
|
-
export const SEARCH_TOOL_DESCRIPTION =
|
|
14
|
+
export const SEARCH_TOOL_DESCRIPTION = stringUtils.toDescription(`
|
|
15
15
|
Search a Databricks AI Search (Vector Search) index for the documents most
|
|
16
16
|
relevant to a query. Pass a natural-language question or keywords; hybrid
|
|
17
17
|
matching combines semantic similarity with keyword ranking, so exact terms
|
|
@@ -22,7 +22,7 @@ export const SEARCH_TOOL_DESCRIPTION = string.toDescription(`
|
|
|
22
22
|
`);
|
|
23
23
|
|
|
24
24
|
/** Description the model reads for the `universal_search` tool. */
|
|
25
|
-
export const UNIVERSAL_SEARCH_TOOL_DESCRIPTION =
|
|
25
|
+
export const UNIVERSAL_SEARCH_TOOL_DESCRIPTION = stringUtils.toDescription(`
|
|
26
26
|
Search across every configured AI Search index at once and return the best
|
|
27
27
|
matches from all of them, merged and ranked. Use it when the right index
|
|
28
28
|
isn't known in advance or when an answer may live in any of several
|
|
@@ -30,7 +30,7 @@ export const UNIVERSAL_SEARCH_TOOL_DESCRIPTION = string.toDescription(`
|
|
|
30
30
|
`);
|
|
31
31
|
|
|
32
32
|
/** Description the model reads for the `add_documents` tool. */
|
|
33
|
-
export const ADD_DOCUMENTS_TOOL_DESCRIPTION =
|
|
33
|
+
export const ADD_DOCUMENTS_TOOL_DESCRIPTION = stringUtils.toDescription(`
|
|
34
34
|
Add or update documents in a direct-access AI Search index. Pass an array of
|
|
35
35
|
documents as JSON objects; each MUST include the index's primary-key column.
|
|
36
36
|
Only available when the app enables the write surface. Use it to index new
|
|
@@ -38,7 +38,7 @@ export const ADD_DOCUMENTS_TOOL_DESCRIPTION = string.toDescription(`
|
|
|
38
38
|
`);
|
|
39
39
|
|
|
40
40
|
/** Description the model reads for the `create_index` tool. */
|
|
41
|
-
export const CREATE_INDEX_TOOL_DESCRIPTION =
|
|
41
|
+
export const CREATE_INDEX_TOOL_DESCRIPTION = stringUtils.toDescription(`
|
|
42
42
|
Create a Databricks AI Search (Vector Search) index. For the common case pass
|
|
43
43
|
a Delta source table (catalog.schema.table): Databricks computes embeddings
|
|
44
44
|
from its text column and keeps the index synced. To create a direct-access
|
|
@@ -50,26 +50,26 @@ export const CREATE_INDEX_TOOL_DESCRIPTION = string.toDescription(`
|
|
|
50
50
|
`);
|
|
51
51
|
|
|
52
52
|
/** Description the model reads for the `sync_index` tool. */
|
|
53
|
-
export const SYNC_INDEX_TOOL_DESCRIPTION =
|
|
53
|
+
export const SYNC_INDEX_TOOL_DESCRIPTION = stringUtils.toDescription(`
|
|
54
54
|
Refresh a Delta Sync AI Search index from its source table so newly added or
|
|
55
55
|
changed rows become searchable. Optionally name the index (defaults to the
|
|
56
56
|
app's default index). Only available when the app enables the write surface.
|
|
57
57
|
`);
|
|
58
58
|
|
|
59
59
|
/** Schema for the `search` tool input (the shared request schema). */
|
|
60
|
-
export const searchToolSchema =
|
|
60
|
+
export const searchToolSchema = searchSchemas.searchRequestSchema;
|
|
61
61
|
|
|
62
62
|
/** Schema for the `universal_search` tool input. */
|
|
63
|
-
export const universalSearchToolSchema =
|
|
63
|
+
export const universalSearchToolSchema = searchSchemas.universalSearchRequestSchema;
|
|
64
64
|
|
|
65
65
|
/** Schema for the `search` / `universal_search` tool output. */
|
|
66
|
-
export const searchResultSchema =
|
|
66
|
+
export const searchResultSchema = searchSchemas.searchResultSchema;
|
|
67
67
|
|
|
68
68
|
/** Schema for the `create_index` tool input. */
|
|
69
|
-
export const createIndexToolSchema =
|
|
69
|
+
export const createIndexToolSchema = searchSchemas.createIndexRequestSchema;
|
|
70
70
|
|
|
71
71
|
/** Schema for the `create_index` tool output (a resolved index definition). */
|
|
72
|
-
export const indexInfoSchema =
|
|
72
|
+
export const indexInfoSchema = searchSchemas.indexInfoSchema;
|
|
73
73
|
|
|
74
74
|
/** Schema for the `sync_index` tool input. */
|
|
75
|
-
export const syncIndexToolSchema =
|
|
75
|
+
export const syncIndexToolSchema = searchSchemas.syncIndexRequestSchema;
|
package/src/tool.ts
CHANGED
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
* @module
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import {
|
|
18
|
+
import { searchSchemas, type UpsertResult } from "@dbx-tools/shared-search";
|
|
19
19
|
import { createTool } from "@mastra/core/tools";
|
|
20
20
|
import { z } from "zod";
|
|
21
21
|
import { toSearchOptions, toUniversalSearchOptions } from "./_search-options.ts";
|
|
22
22
|
import type { SearchReadBackend } from "./client.ts";
|
|
23
23
|
import type { SearchPluginConfig } from "./config.ts";
|
|
24
|
-
import { toCreateIndexOptions } from "./index-
|
|
24
|
+
import { toCreateIndexOptions } from "./index-options.ts";
|
|
25
25
|
import { toDocumentArray } from "./query.ts";
|
|
26
26
|
import { createSearchRuntime, type SearchRuntime } from "./runtime.ts";
|
|
27
27
|
import {
|
|
@@ -117,16 +117,16 @@ export function universalSearchTool(options: SearchToolOptions = {}) {
|
|
|
117
117
|
*/
|
|
118
118
|
export function addDocumentsTool(options: SearchToolOptions = {}) {
|
|
119
119
|
const runtime = toolRuntime(options);
|
|
120
|
-
const inputSchema =
|
|
120
|
+
const inputSchema = searchSchemas.searchDocumentSchema
|
|
121
121
|
.array()
|
|
122
122
|
.describe("Documents to add or update. Each must include the index primary key.");
|
|
123
123
|
return createTool({
|
|
124
124
|
id: options.id ?? "add_documents",
|
|
125
125
|
description: ADD_DOCUMENTS_TOOL_DESCRIPTION,
|
|
126
|
-
inputSchema:
|
|
126
|
+
inputSchema: searchSchemas.searchRequestSchema
|
|
127
127
|
.pick({ index: true })
|
|
128
128
|
.extend({ documents: inputSchema }),
|
|
129
|
-
outputSchema:
|
|
129
|
+
outputSchema: searchSchemas.upsertResultSchema,
|
|
130
130
|
execute: async (input, context): Promise<UpsertResult> => {
|
|
131
131
|
const { client, config } = runtime;
|
|
132
132
|
const record = input as { index?: string; documents: unknown };
|
package/lib/src/index-tools.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared translation from the browser-safe {@link CreateIndexRequest} wire
|
|
3
|
-
* shape onto the client's {@link CreateIndexOptions}. Lives in its own module
|
|
4
|
-
* because both the Mastra `create_index` tool (`tool.ts`) and the AppKit tool
|
|
5
|
-
* provider (`plugin.ts`) build the same options object, and the mapping (which
|
|
6
|
-
* optional fields to spread, folding in the abort signal) is easy to let drift
|
|
7
|
-
* between the two.
|
|
8
|
-
*
|
|
9
|
-
* @module
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Map a validated {@link CreateIndexRequest} onto {@link CreateIndexOptions},
|
|
13
|
-
* spreading only the fields that were supplied so the client's own defaults
|
|
14
|
-
* (endpoint, embedding model, primary key, text column) still apply, and
|
|
15
|
-
* folding in the caller's abort signal.
|
|
16
|
-
*/
|
|
17
|
-
export function toCreateIndexOptions(request, signal) {
|
|
18
|
-
return {
|
|
19
|
-
...(request.sourceTable ? { sourceTable: request.sourceTable } : {}),
|
|
20
|
-
...(request.primaryKey ? { primaryKey: request.primaryKey } : {}),
|
|
21
|
-
...(request.embeddingSourceColumn
|
|
22
|
-
? { embeddingSourceColumn: request.embeddingSourceColumn }
|
|
23
|
-
: {}),
|
|
24
|
-
...(request.embeddingModel ? { embeddingModel: request.embeddingModel } : {}),
|
|
25
|
-
...(request.endpoint ? { endpoint: request.endpoint } : {}),
|
|
26
|
-
...(request.embeddingDimension !== undefined
|
|
27
|
-
? { embeddingDimension: request.embeddingDimension }
|
|
28
|
-
: {}),
|
|
29
|
-
...(request.pipelineType ? { pipelineType: request.pipelineType } : {}),
|
|
30
|
-
...(request.columnsToSync ? { columnsToSync: request.columnsToSync } : {}),
|
|
31
|
-
...(signal ? { signal } : {}),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXgtdG9vbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgtdG9vbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7OztHQVNHO0FBS0g7Ozs7O0dBS0c7QUFDSCxNQUFNLFVBQVUsb0JBQW9CLENBQ2xDLE9BQTJCLEVBQzNCLE1BQW9CO0lBRXBCLE9BQU87UUFDTCxHQUFHLENBQUMsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDLENBQUMsRUFBRSxXQUFXLEVBQUUsT0FBTyxDQUFDLFdBQVcsRUFBRSxDQUFDLENBQUMsQ0FBQyxFQUFFLENBQUM7UUFDcEUsR0FBRyxDQUFDLE9BQU8sQ0FBQyxVQUFVLENBQUMsQ0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