@dbx-tools/search 0.6.223 → 0.6.225
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 +25 -3
- package/index.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -2
- package/lib/src/plugin.d.ts +9 -5
- package/lib/src/plugin.js +26 -28
- package/lib/src/runtime.d.ts +19 -12
- package/lib/src/runtime.js +30 -22
- package/lib/src/tool.d.ts +17 -7
- package/lib/src/tool.js +31 -17
- package/package.json +7 -7
- package/src/plugin.ts +27 -30
- package/src/runtime.ts +32 -23
- package/src/tool.ts +45 -17
package/src/tool.ts
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
* The `search`, `universal_search`, and (opt-in) `add_documents`,
|
|
3
3
|
* `create_index`, and `sync_index` Mastra tools.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* App-integrated agents should consume the plugin's native toolkit so calls
|
|
6
|
+
* retain that plugin's config and provider backend. These standalone factories
|
|
7
|
+
* capture an explicit runtime or build an isolated one from config plus a
|
|
8
|
+
* provider. They run under the caller's OBO scope (the client resolves the
|
|
9
|
+
* execution context's workspace client), so search runs as the requesting user
|
|
10
|
+
* and Unity Catalog ACLs apply.
|
|
10
11
|
*
|
|
11
12
|
* The same tools are exposed to AppKit's own agents through the plugin's
|
|
12
|
-
* `ToolProvider` (see `plugin.ts`)
|
|
13
|
+
* `ToolProvider` (see `plugin.ts`).
|
|
13
14
|
*
|
|
14
15
|
* @module
|
|
15
16
|
*/
|
|
@@ -17,10 +18,12 @@
|
|
|
17
18
|
import { search as sharedSearch, type UpsertResult } from "@dbx-tools/shared-search";
|
|
18
19
|
import { createTool } from "@mastra/core/tools";
|
|
19
20
|
import { z } from "zod";
|
|
21
|
+
import { toSearchOptions, toUniversalSearchOptions } from "./_search-options.ts";
|
|
22
|
+
import type { SearchReadBackend } from "./client.ts";
|
|
23
|
+
import type { SearchPluginConfig } from "./config.ts";
|
|
20
24
|
import { toCreateIndexOptions } from "./index-tools.ts";
|
|
21
25
|
import { toDocumentArray } from "./query.ts";
|
|
22
|
-
import {
|
|
23
|
-
import { toSearchOptions, toUniversalSearchOptions } from "./_search-options.ts";
|
|
26
|
+
import { createSearchRuntime, type SearchRuntime } from "./runtime.ts";
|
|
24
27
|
import {
|
|
25
28
|
ADD_DOCUMENTS_TOOL_DESCRIPTION,
|
|
26
29
|
CREATE_INDEX_TOOL_DESCRIPTION,
|
|
@@ -35,10 +38,30 @@ import {
|
|
|
35
38
|
universalSearchToolSchema,
|
|
36
39
|
} from "./schema.ts";
|
|
37
40
|
|
|
38
|
-
/**
|
|
41
|
+
/** Options accepted by every standalone tool factory. */
|
|
39
42
|
export interface SearchToolOptions {
|
|
40
43
|
/** Override the tool id (defaults per tool). */
|
|
41
44
|
id?: string;
|
|
45
|
+
/** Isolated runtime used by this standalone tool. Mutually exclusive with config/backend. */
|
|
46
|
+
runtime?: SearchRuntime;
|
|
47
|
+
/** Config used to create an isolated runtime. */
|
|
48
|
+
config?: SearchPluginConfig;
|
|
49
|
+
/** Provider used when creating a runtime from config. */
|
|
50
|
+
readBackend?: SearchReadBackend;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Resolve the isolated runtime captured by one standalone tool factory. */
|
|
54
|
+
function toolRuntime(options: SearchToolOptions): SearchRuntime {
|
|
55
|
+
if (options.runtime && (options.config || options.readBackend)) {
|
|
56
|
+
throw new TypeError("search tool options accept runtime or config/readBackend, not both");
|
|
57
|
+
}
|
|
58
|
+
return (
|
|
59
|
+
options.runtime ??
|
|
60
|
+
createSearchRuntime({
|
|
61
|
+
config: options.config,
|
|
62
|
+
readBackend: options.readBackend,
|
|
63
|
+
})
|
|
64
|
+
);
|
|
42
65
|
}
|
|
43
66
|
|
|
44
67
|
/**
|
|
@@ -57,6 +80,7 @@ export interface SearchToolOptions {
|
|
|
57
80
|
* ```
|
|
58
81
|
*/
|
|
59
82
|
export function searchTool(options: SearchToolOptions = {}) {
|
|
83
|
+
const runtime = toolRuntime(options);
|
|
60
84
|
return createTool({
|
|
61
85
|
id: options.id ?? "search",
|
|
62
86
|
description: SEARCH_TOOL_DESCRIPTION,
|
|
@@ -64,14 +88,14 @@ export function searchTool(options: SearchToolOptions = {}) {
|
|
|
64
88
|
outputSchema: searchResultSchema,
|
|
65
89
|
execute: async (input, context) => {
|
|
66
90
|
const request = searchToolSchema.parse(input);
|
|
67
|
-
|
|
68
|
-
return client.search(request.query, toSearchOptions(request, context?.abortSignal));
|
|
91
|
+
return runtime.client.search(request.query, toSearchOptions(request, context?.abortSignal));
|
|
69
92
|
},
|
|
70
93
|
});
|
|
71
94
|
}
|
|
72
95
|
|
|
73
96
|
/** Build the `universal_search` tool (federated search across every index). */
|
|
74
97
|
export function universalSearchTool(options: SearchToolOptions = {}) {
|
|
98
|
+
const runtime = toolRuntime(options);
|
|
75
99
|
return createTool({
|
|
76
100
|
id: options.id ?? "universal_search",
|
|
77
101
|
description: UNIVERSAL_SEARCH_TOOL_DESCRIPTION,
|
|
@@ -79,8 +103,7 @@ export function universalSearchTool(options: SearchToolOptions = {}) {
|
|
|
79
103
|
outputSchema: searchResultSchema,
|
|
80
104
|
execute: async (input, context) => {
|
|
81
105
|
const request = universalSearchToolSchema.parse(input);
|
|
82
|
-
|
|
83
|
-
return client.universalSearch(
|
|
106
|
+
return runtime.client.universalSearch(
|
|
84
107
|
request.query,
|
|
85
108
|
toUniversalSearchOptions(request, context?.abortSignal),
|
|
86
109
|
);
|
|
@@ -93,6 +116,7 @@ export function universalSearchTool(options: SearchToolOptions = {}) {
|
|
|
93
116
|
* Only install it when the plugin's write surface is enabled.
|
|
94
117
|
*/
|
|
95
118
|
export function addDocumentsTool(options: SearchToolOptions = {}) {
|
|
119
|
+
const runtime = toolRuntime(options);
|
|
96
120
|
const inputSchema = sharedSearch.searchDocumentSchema
|
|
97
121
|
.array()
|
|
98
122
|
.describe("Documents to add or update. Each must include the index primary key.");
|
|
@@ -104,7 +128,7 @@ export function addDocumentsTool(options: SearchToolOptions = {}) {
|
|
|
104
128
|
.extend({ documents: inputSchema }),
|
|
105
129
|
outputSchema: sharedSearch.upsertResultSchema,
|
|
106
130
|
execute: async (input, context): Promise<UpsertResult> => {
|
|
107
|
-
const { client, config } =
|
|
131
|
+
const { client, config } = runtime;
|
|
108
132
|
const record = input as { index?: string; documents: unknown };
|
|
109
133
|
const documents = toDocumentArray(record.documents);
|
|
110
134
|
const index = record.index ?? config.defaultIndex ?? "";
|
|
@@ -120,6 +144,7 @@ export function addDocumentsTool(options: SearchToolOptions = {}) {
|
|
|
120
144
|
* key, and columns from the request + plugin config.
|
|
121
145
|
*/
|
|
122
146
|
export function createIndexTool(options: SearchToolOptions = {}) {
|
|
147
|
+
const runtime = toolRuntime(options);
|
|
123
148
|
return createTool({
|
|
124
149
|
id: options.id ?? "create_index",
|
|
125
150
|
description: CREATE_INDEX_TOOL_DESCRIPTION,
|
|
@@ -127,8 +152,10 @@ export function createIndexTool(options: SearchToolOptions = {}) {
|
|
|
127
152
|
outputSchema: indexInfoSchema,
|
|
128
153
|
execute: async (input, context) => {
|
|
129
154
|
const request = createIndexToolSchema.parse(input);
|
|
130
|
-
|
|
131
|
-
|
|
155
|
+
return runtime.client.createIndex(
|
|
156
|
+
request.name,
|
|
157
|
+
toCreateIndexOptions(request, context?.abortSignal),
|
|
158
|
+
);
|
|
132
159
|
},
|
|
133
160
|
});
|
|
134
161
|
}
|
|
@@ -144,6 +171,7 @@ const syncIndexResultSchema = z.object({
|
|
|
144
171
|
* source table). Only install it when the plugin's write surface is enabled.
|
|
145
172
|
*/
|
|
146
173
|
export function syncIndexTool(options: SearchToolOptions = {}) {
|
|
174
|
+
const runtime = toolRuntime(options);
|
|
147
175
|
return createTool({
|
|
148
176
|
id: options.id ?? "sync_index",
|
|
149
177
|
description: SYNC_INDEX_TOOL_DESCRIPTION,
|
|
@@ -151,7 +179,7 @@ export function syncIndexTool(options: SearchToolOptions = {}) {
|
|
|
151
179
|
outputSchema: syncIndexResultSchema,
|
|
152
180
|
execute: async (input, context) => {
|
|
153
181
|
const request = syncIndexToolSchema.parse(input);
|
|
154
|
-
const { client, config } =
|
|
182
|
+
const { client, config } = runtime;
|
|
155
183
|
const index = request.index ?? config.defaultIndex ?? "";
|
|
156
184
|
await client.syncIndex(index, context?.abortSignal);
|
|
157
185
|
return { index, synced: true };
|