@open-mercato/search 0.10.1-develop.7601.1.e057b693a8 → 0.10.1-develop.7614.1.75d5ac1a6a
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/dist/modules/search/ai-tools.js +48 -3
- package/dist/modules/search/ai-tools.js.map +2 -2
- package/dist/modules/search/frontend/components/sections/VectorSearchSection.js +37 -4
- package/dist/modules/search/frontend/components/sections/VectorSearchSection.js.map +2 -2
- package/dist/modules/search/i18n/de.json +2 -0
- package/dist/modules/search/i18n/en.json +2 -0
- package/dist/modules/search/i18n/es.json +2 -0
- package/dist/modules/search/i18n/ko.json +2 -0
- package/dist/modules/search/i18n/pl.json +2 -0
- package/package.json +4 -4
- package/src/modules/search/__tests__/ai-tools.aggregate.test.ts +94 -4
- package/src/modules/search/__tests__/ai-tools.get.test.ts +101 -4
- package/src/modules/search/__tests__/ai-tools.query.test.ts +122 -0
- package/src/modules/search/ai-tools.ts +72 -3
- package/src/modules/search/frontend/components/sections/VectorSearchSection.tsx +43 -6
- package/src/modules/search/frontend/components/sections/__tests__/VectorSearchSection.test.tsx +123 -1
- package/src/modules/search/i18n/de.json +2 -0
- package/src/modules/search/i18n/en.json +2 -0
- package/src/modules/search/i18n/es.json +2 -0
- package/src/modules/search/i18n/ko.json +2 -0
- package/src/modules/search/i18n/pl.json +2 -0
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
filterSearchResultsByEntityAccess,
|
|
5
5
|
resolveReadableEntityTypes
|
|
6
6
|
} from "./lib/entity-access.js";
|
|
7
|
+
import { resolveOrganizationScopeForRequest } from "@open-mercato/core/modules/directory/utils/organizationScope";
|
|
8
|
+
import { resolveOrganizationScopeFilter } from "@open-mercato/core/modules/directory/utils/organizationScopeFilter";
|
|
7
9
|
class SearchToolAuthorizationError extends Error {
|
|
8
10
|
constructor(message) {
|
|
9
11
|
super(message);
|
|
@@ -35,6 +37,24 @@ function authorizeEntityAccess(entityType, ctx) {
|
|
|
35
37
|
}
|
|
36
38
|
return config;
|
|
37
39
|
}
|
|
40
|
+
async function resolveActorOrganizationScope(ctx) {
|
|
41
|
+
if (!ctx.userId) return { organizationId: void 0, organizationIds: void 0, denyAll: true };
|
|
42
|
+
const auth = {
|
|
43
|
+
sub: ctx.userId,
|
|
44
|
+
tenantId: ctx.tenantId,
|
|
45
|
+
orgId: ctx.organizationId,
|
|
46
|
+
isSuperAdmin: ctx.isSuperAdmin
|
|
47
|
+
};
|
|
48
|
+
const scope = await resolveOrganizationScopeForRequest({
|
|
49
|
+
container: ctx.container,
|
|
50
|
+
auth,
|
|
51
|
+
selectedId: ctx.organizationId
|
|
52
|
+
});
|
|
53
|
+
const scopeFilter = resolveOrganizationScopeFilter(scope, auth);
|
|
54
|
+
const denyAll = Array.isArray(scope.filterIds) && scope.filterIds.length === 0;
|
|
55
|
+
const organizationId = typeof scope.selectedId === "string" && scope.selectedId.trim().length > 0 ? scope.selectedId.trim() : void 0;
|
|
56
|
+
return { organizationId, organizationIds: scopeFilter.organizationIds, denyAll };
|
|
57
|
+
}
|
|
38
58
|
function stripSensitiveFields(record, config) {
|
|
39
59
|
const sensitive = /* @__PURE__ */ new Set([
|
|
40
60
|
...config.fieldPolicy?.hashOnly ?? [],
|
|
@@ -83,9 +103,14 @@ Searches customers, products, orders, deals, and more in one call.`,
|
|
|
83
103
|
if (readableEntityTypes && readableEntityTypes.length === 0) {
|
|
84
104
|
return { query: input.query, totalResults: 0, results: [] };
|
|
85
105
|
}
|
|
106
|
+
const orgScope = await resolveActorOrganizationScope(ctx);
|
|
107
|
+
if (orgScope.denyAll) {
|
|
108
|
+
return { query: input.query, totalResults: 0, results: [] };
|
|
109
|
+
}
|
|
86
110
|
const rawResults = await searchService.search(input.query, {
|
|
87
111
|
tenantId: ctx.tenantId,
|
|
88
|
-
organizationId:
|
|
112
|
+
organizationId: orgScope.organizationId,
|
|
113
|
+
organizationIds: orgScope.organizationIds,
|
|
89
114
|
entityTypes: readableEntityTypes,
|
|
90
115
|
strategies: input.strategies,
|
|
91
116
|
limit: input.limit
|
|
@@ -144,10 +169,20 @@ const searchGetTool = {
|
|
|
144
169
|
throw new Error("Tenant context is required");
|
|
145
170
|
}
|
|
146
171
|
const entityConfig = authorizeEntityAccess(input.entityType, ctx);
|
|
172
|
+
const orgScope = await resolveActorOrganizationScope(ctx);
|
|
173
|
+
if (orgScope.denyAll) {
|
|
174
|
+
return {
|
|
175
|
+
found: false,
|
|
176
|
+
entityType: input.entityType,
|
|
177
|
+
recordId: input.recordId,
|
|
178
|
+
error: "Record not found"
|
|
179
|
+
};
|
|
180
|
+
}
|
|
147
181
|
const queryEngine = ctx.container.resolve("queryEngine");
|
|
148
182
|
const result = await queryEngine.query(input.entityType, {
|
|
149
183
|
tenantId: ctx.tenantId,
|
|
150
|
-
organizationId:
|
|
184
|
+
organizationId: orgScope.organizationId,
|
|
185
|
+
organizationIds: orgScope.organizationIds,
|
|
151
186
|
filters: { id: input.recordId },
|
|
152
187
|
includeCustomFields: true,
|
|
153
188
|
page: { page: 1, pageSize: 1 }
|
|
@@ -250,10 +285,20 @@ const searchAggregateTool = {
|
|
|
250
285
|
`[internal] Field "${input.groupBy}" is not an allowed grouping key for "${input.entityType}"`
|
|
251
286
|
);
|
|
252
287
|
}
|
|
288
|
+
const orgScope = await resolveActorOrganizationScope(ctx);
|
|
289
|
+
if (orgScope.denyAll) {
|
|
290
|
+
return {
|
|
291
|
+
entityType: input.entityType,
|
|
292
|
+
groupBy: input.groupBy,
|
|
293
|
+
total: 0,
|
|
294
|
+
buckets: []
|
|
295
|
+
};
|
|
296
|
+
}
|
|
253
297
|
const queryEngine = ctx.container.resolve("queryEngine");
|
|
254
298
|
const result = await queryEngine.query(input.entityType, {
|
|
255
299
|
tenantId: ctx.tenantId,
|
|
256
|
-
organizationId:
|
|
300
|
+
organizationId: orgScope.organizationId,
|
|
301
|
+
organizationIds: orgScope.organizationIds,
|
|
257
302
|
page: { page: 1, pageSize: 100 }
|
|
258
303
|
});
|
|
259
304
|
const counts = /* @__PURE__ */ new Map();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/modules/search/ai-tools.ts"],
|
|
4
|
-
"sourcesContent": ["import { z } from 'zod'\nimport type {\n SearchEntityConfig,\n SearchResult,\n SearchStrategyId,\n} from '@open-mercato/shared/modules/search'\nimport { authorizeFeatures } from '@open-mercato/shared/security/featurePolicy'\nimport {\n filterSearchResultsByEntityAccess,\n resolveReadableEntityTypes,\n type SearchEntityConfigLookup,\n} from './lib/entity-access'\n\n/**\n * AI Tools definitions for the Search module.\n *\n * These tool definitions are discovered by the ai-assistant module's generator\n * and registered as MCP tools. The search module does not depend on ai-assistant.\n *\n * Tool Definition Format:\n * - name: Unique tool identifier (module_action format, no dots allowed)\n * - description: Human-readable description for AI clients\n * - inputSchema: Zod schema for input validation\n * - requiredFeatures: ACL features required to execute\n * - handler: Async function that executes the tool\n */\n\n/**\n * Tool context provided by the MCP server at execution time.\n */\ntype ToolContext = {\n tenantId: string | null\n organizationId: string | null\n userId: string | null\n container: {\n resolve: <T = unknown>(name: string) => T\n }\n userFeatures: string[]\n isSuperAdmin: boolean\n}\n\n/**\n * Tool definition structure.\n */\ntype AiToolDefinition = {\n name: string\n description: string\n inputSchema: z.ZodType<any>\n requiredFeatures?: string[]\n /**\n * Optional flag \u2014 when true, the tool is treated as a write by the\n * agent runtime and routed through the pending-action approval card.\n * Mirrors the public `AiToolDefinition.isMutation` flag without taking\n * a hard dependency on `@open-mercato/ai-assistant` here.\n */\n isMutation?: boolean\n handler: (input: any, ctx: ToolContext) => Promise<unknown>\n}\n\n/**\n * Minimal shape of the `searchIndexer` DI service consumed by the per-entity\n * ACL / field-policy resolution below. Aliased rather than redeclared so the\n * tools and the global-search route cannot drift apart, and still narrow enough\n * to avoid importing the full `SearchIndexer` class into the tool module.\n */\ntype SearchIndexerLike = SearchEntityConfigLookup\n\nclass SearchToolAuthorizationError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'SearchToolAuthorizationError'\n }\n}\n\n/**\n * Resolve the search config for an entity type and enforce the per-entity view\n * feature(s). Data-returning tools (`search_get` / `search_aggregate`) MUST NOT\n * rely on the search-administration `search.view` feature to gate record reads.\n *\n * Fails closed: when the entity is not configured for search, or has no\n * `aclFeatures` declared, access is denied so records are never exposed without\n * an explicit owning-module grant.\n */\nfunction authorizeEntityAccess(entityType: string, ctx: ToolContext): SearchEntityConfig {\n const searchIndexer = ctx.container.resolve<SearchIndexerLike>('searchIndexer')\n const config = searchIndexer.getEntityConfig(entityType)\n\n if (!config) {\n throw new SearchToolAuthorizationError(\n `[internal] Entity type \"${entityType}\" is not configured for search`\n )\n }\n\n if (ctx.isSuperAdmin) return config\n\n const required = config.aclFeatures\n if (!required || required.length === 0) {\n throw new SearchToolAuthorizationError(\n `[internal] Entity type \"${entityType}\" does not declare aclFeatures; access denied`\n )\n }\n\n if (!authorizeFeatures(required, {\n grantedFeatures: ctx.userFeatures,\n unrestricted: ctx.isSuperAdmin,\n })) {\n throw new SearchToolAuthorizationError(\n `[internal] Insufficient permissions for entity \"${entityType}\". Required: ${required.join(', ')}`\n )\n }\n\n return config\n}\n\n/**\n * Strip fields that the entity's field policy marks as sensitive\n * (`hashOnly` exact-match PII or fully `excluded`) from a query-engine record.\n * Defense-in-depth so even an authorized caller never receives decrypted PII or\n * fields a `fieldPolicy` keeps out of search.\n */\nfunction stripSensitiveFields(\n record: Record<string, unknown>,\n config: SearchEntityConfig\n): Record<string, unknown> {\n const sensitive = new Set<string>([\n ...(config.fieldPolicy?.hashOnly ?? []),\n ...(config.fieldPolicy?.excluded ?? []),\n ])\n if (sensitive.size === 0) return record\n const safe: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(record)) {\n if (sensitive.has(key)) continue\n safe[key] = value\n }\n return safe\n}\n\n/**\n * Determine whether a field is a safe aggregation grouping key for an entity.\n * Only fields explicitly declared `searchable` are allowed; `hashOnly` and\n * `excluded` (PII / sensitive) fields can never be enumerated via group-by.\n */\nfunction isGroupByAllowed(field: string, config: SearchEntityConfig): boolean {\n const sensitive = new Set<string>([\n ...(config.fieldPolicy?.hashOnly ?? []),\n ...(config.fieldPolicy?.excluded ?? []),\n ])\n if (sensitive.has(field)) return false\n const searchable = config.fieldPolicy?.searchable ?? []\n return searchable.includes(field)\n}\n\n// =============================================================================\n// Tool Definitions\n// =============================================================================\n\nconst searchQueryTool: AiToolDefinition = {\n name: 'search_query',\n description: `Search across all data using hybrid search. Use this FIRST for finding records.\n\nReturns: title, subtitle, entityType, recordId, url for each match.\nSearches customers, products, orders, deals, and more in one call.`,\n inputSchema: z.object({\n query: z.string().min(1).describe('The search query text'),\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .optional()\n .default(20)\n .describe('Maximum number of results to return (default: 20)'),\n entityTypes: z\n .array(z.string())\n .optional()\n .describe(\n 'Filter to specific entity types (e.g., [\"customers:customer_person_profile\", \"catalog:product\"])'\n ),\n strategies: z\n .array(z.enum(['fulltext', 'vector', 'tokens']))\n .optional()\n .describe('Specific search strategies to use (default: all available)'),\n }),\n requiredFeatures: ['search.global'],\n handler: async (input, ctx) => {\n if (!ctx.tenantId) {\n throw new Error('Tenant context is required for search')\n }\n\n const searchService = ctx.container.resolve<{\n search: (query: string, options: any) => Promise<SearchResult[]>\n }>('searchService')\n\n // Same rule the HTTP palette applies: `search.global` authorizes using search,\n // not reading every indexed entity type. The query is narrowed to the readable\n // types so `limit` is not spent on records that would be filtered out, and the\n // results are filtered afterwards as defense in depth.\n const searchIndexer = ctx.container.resolve<SearchIndexerLike>('searchIndexer')\n const subject = { grantedFeatures: ctx.userFeatures, isSuperAdmin: ctx.isSuperAdmin }\n const readableEntityTypes = resolveReadableEntityTypes(searchIndexer, subject, input.entityTypes)\n if (readableEntityTypes && readableEntityTypes.length === 0) {\n return { query: input.query, totalResults: 0, results: [] }\n }\n\n const rawResults = await searchService.search(input.query, {\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId,\n entityTypes: readableEntityTypes,\n strategies: input.strategies as SearchStrategyId[],\n limit: input.limit,\n })\n\n const results = filterSearchResultsByEntityAccess(rawResults, searchIndexer, subject)\n\n return {\n query: input.query,\n totalResults: results.length,\n results: results.map((result) => ({\n entityType: result.entityId,\n recordId: result.recordId,\n score: Math.round(result.score * 100) / 100,\n source: result.source,\n title: result.presenter?.title ?? result.recordId,\n subtitle: result.presenter?.subtitle,\n url: result.url,\n })),\n }\n },\n}\n\nconst searchStatusTool: AiToolDefinition = {\n name: 'search_status',\n description:\n 'Get the current status of the search module, including available search strategies and their availability.',\n inputSchema: z.object({}),\n requiredFeatures: ['search.view'],\n handler: async (_input, ctx) => {\n const searchService = ctx.container.resolve<{\n getStrategies: () => Array<{\n id: string\n name: string\n priority: number\n isAvailable: () => Promise<boolean>\n }>\n getDefaultStrategies: () => string[]\n }>('searchService')\n\n const strategies = searchService.getStrategies()\n const defaultStrategies = searchService.getDefaultStrategies()\n\n const strategyStatus = await Promise.all(\n strategies.map(async (strategy) => ({\n id: strategy.id,\n name: strategy.name,\n priority: strategy.priority,\n isAvailable: await strategy.isAvailable(),\n isDefault: defaultStrategies.includes(strategy.id),\n }))\n )\n\n return {\n strategiesRegistered: strategies.length,\n defaultStrategies,\n strategies: strategyStatus,\n }\n },\n}\n\n// =============================================================================\n// search.get - Retrieve full record details by entity type and ID\n// =============================================================================\n\nconst searchGetTool: AiToolDefinition = {\n name: 'search_get',\n description: `Get full record details by entityType and recordId from search_query results.`,\n inputSchema: z.object({\n entityType: z\n .string()\n .describe('The entity type (e.g., \"customers:customer_company_profile\", \"customers:customer_deal\")'),\n recordId: z.string().describe('The record ID (UUID)'),\n }),\n requiredFeatures: ['search.view'],\n handler: async (input, ctx) => {\n if (!ctx.tenantId) {\n throw new Error('Tenant context is required')\n }\n\n const entityConfig = authorizeEntityAccess(input.entityType, ctx)\n\n const queryEngine = ctx.container.resolve<{\n query: (entityId: string, options: any) => Promise<{ items: unknown[]; total: number }>\n }>('queryEngine')\n\n const result = await queryEngine.query(input.entityType, {\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId,\n filters: { id: input.recordId },\n includeCustomFields: true,\n page: { page: 1, pageSize: 1 },\n })\n\n const rawRecord = result.items[0] as Record<string, unknown> | undefined\n if (!rawRecord) {\n return {\n found: false,\n entityType: input.entityType,\n recordId: input.recordId,\n error: 'Record not found',\n }\n }\n\n const record = stripSensitiveFields(rawRecord, entityConfig)\n\n // Extract custom fields\n const customFields: Record<string, unknown> = {}\n const standardFields: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(record)) {\n if (key.startsWith('cf:') || key.startsWith('cf_')) {\n customFields[key.replace(/^cf[:_]/, '')] = value\n } else {\n standardFields[key] = value\n }\n }\n\n // Build URL based on entity type\n let url: string | null = null\n const id = record.id ?? record.entity_id ?? input.recordId\n if (input.entityType.includes('person')) {\n url = `/backend/customers/people/${id}`\n } else if (input.entityType.includes('company')) {\n url = `/backend/customers/companies/${id}`\n } else if (input.entityType.includes('deal')) {\n url = `/backend/customers/deals/${id}`\n } else if (input.entityType.includes('activity')) {\n const entityId = record.entity_id ?? record.entityId\n url = entityId ? `/backend/customers/companies/${entityId}#activity-${id}` : null\n }\n\n return {\n found: true,\n entityType: input.entityType,\n recordId: input.recordId,\n record: standardFields,\n customFields: Object.keys(customFields).length > 0 ? customFields : undefined,\n url,\n }\n },\n}\n\n// =============================================================================\n// search.schema - Discover searchable entities and their fields\n// =============================================================================\n\nconst searchSchemaTool: AiToolDefinition = {\n name: 'search_schema',\n description:\n 'Discover searchable entities and their fields. Use this to learn what data can be searched and what fields are available for filtering.',\n inputSchema: z.object({\n entityType: z\n .string()\n .optional()\n .describe('Optional: Get schema for a specific entity type only'),\n }),\n requiredFeatures: ['search.view'],\n handler: async (input, ctx) => {\n const searchIndexer = ctx.container.resolve<{\n getAllEntityConfigs: () => Array<{\n entityId: string\n enabled?: boolean\n priority?: number\n strategies?: string[]\n fieldPolicy?: {\n searchable?: string[]\n hashOnly?: string[]\n excluded?: string[]\n }\n }>\n }>('searchIndexer')\n\n const allConfigs = searchIndexer.getAllEntityConfigs()\n const entities: Array<{\n entityId: string\n enabled: boolean\n priority: number\n strategies?: string[]\n searchableFields?: string[]\n hashOnlyFields?: string[]\n excludedFields?: string[]\n }> = []\n\n for (const entityConfig of allConfigs) {\n if (input.entityType && entityConfig.entityId !== input.entityType) {\n continue\n }\n\n entities.push({\n entityId: entityConfig.entityId,\n enabled: entityConfig.enabled !== false,\n priority: entityConfig.priority ?? 5,\n strategies: entityConfig.strategies,\n searchableFields: entityConfig.fieldPolicy?.searchable,\n hashOnlyFields: entityConfig.fieldPolicy?.hashOnly,\n excludedFields: entityConfig.fieldPolicy?.excluded,\n })\n }\n\n if (input.entityType && entities.length === 0) {\n return {\n found: false,\n entityType: input.entityType,\n error: 'Entity type not configured for search',\n }\n }\n\n return {\n totalEntities: entities.length,\n entities: entities.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0)),\n }\n },\n}\n\n// =============================================================================\n// search.aggregate - Get counts grouped by field values\n// =============================================================================\n\nconst searchAggregateTool: AiToolDefinition = {\n name: 'search_aggregate',\n description:\n 'Get record counts grouped by a field value. Useful for analytics like \"how many deals by stage?\" or \"customers by status\". Samples up to 100 records \u2014 percentages may not reflect the full dataset for large entity sets.',\n inputSchema: z.object({\n entityType: z\n .string()\n .describe('The entity type to aggregate (e.g., \"customers:customer_deal\")'),\n groupBy: z\n .string()\n .describe('The field to group by (e.g., \"status\", \"industry\", \"pipeline_stage\")'),\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .optional()\n .default(20)\n .describe('Maximum number of buckets to return (default: 20)'),\n }),\n requiredFeatures: ['search.view'],\n handler: async (input, ctx) => {\n if (!ctx.tenantId) {\n throw new Error('Tenant context is required')\n }\n\n const entityConfig = authorizeEntityAccess(input.entityType, ctx)\n\n if (!isGroupByAllowed(input.groupBy, entityConfig)) {\n throw new SearchToolAuthorizationError(\n `[internal] Field \"${input.groupBy}\" is not an allowed grouping key for \"${input.entityType}\"`\n )\n }\n\n const queryEngine = ctx.container.resolve<{\n query: (entityId: string, options: any) => Promise<{ items: unknown[]; total: number }>\n }>('queryEngine')\n\n // Fetch records and aggregate in memory\n // Note: For large datasets, this should use database GROUP BY\n const result = await queryEngine.query(input.entityType, {\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId,\n page: { page: 1, pageSize: 100 },\n })\n\n const counts = new Map<string | null, number>()\n for (const item of result.items as Record<string, unknown>[]) {\n const value = item[input.groupBy]\n const key = value === null || value === undefined ? null : String(value)\n counts.set(key, (counts.get(key) ?? 0) + 1)\n }\n\n const total = result.items.length\n const buckets = Array.from(counts.entries())\n .map(([value, count]) => ({\n value,\n count,\n percentage: Math.round((count / total) * 100 * 100) / 100,\n }))\n .sort((a, b) => b.count - a.count)\n .slice(0, input.limit)\n\n return {\n entityType: input.entityType,\n groupBy: input.groupBy,\n total,\n buckets,\n }\n },\n}\n\nconst searchReindexTool: AiToolDefinition = {\n name: 'search_reindex',\n description:\n 'Trigger a reindex operation for search data. This rebuilds the search index for the specified entity type or all entities.',\n inputSchema: z.object({\n entityType: z\n .string()\n .optional()\n .describe(\n 'Specific entity type to reindex (e.g., \"customers:customer_person_profile\"). If not provided, reindexes all entities.'\n ),\n strategy: z\n .enum(['fulltext', 'vector'])\n .optional()\n .default('fulltext')\n .describe('Which search strategy to reindex (default: fulltext)'),\n recreateIndex: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to recreate the index from scratch (default: false)'),\n }),\n requiredFeatures: ['search.reindex'],\n // Reindex changes server-side index state \u2014 must surface as a write so\n // any agent that whitelists it routes through the approval card.\n isMutation: true,\n handler: async (input, ctx) => {\n if (!ctx.tenantId) {\n throw new Error('Tenant context is required for reindex')\n }\n\n const searchIndexer = ctx.container.resolve<{\n reindexEntityToFulltext: (params: any) => Promise<any>\n reindexAllToFulltext: (params: any) => Promise<any>\n reindexEntityToVector: (params: any) => Promise<void>\n reindexAllToVector: (params: any) => Promise<void>\n }>('searchIndexer')\n\n const baseParams = {\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId,\n recreateIndex: input.recreateIndex,\n useQueue: true,\n }\n\n if (input.strategy === 'vector') {\n if (input.entityType) {\n await searchIndexer.reindexEntityToVector({\n ...baseParams,\n entityId: input.entityType,\n })\n return {\n status: 'started',\n strategy: 'vector',\n entityType: input.entityType,\n message: `Vector reindex started for ${input.entityType}`,\n }\n } else {\n await searchIndexer.reindexAllToVector(baseParams)\n return {\n status: 'started',\n strategy: 'vector',\n entityType: 'all',\n message: 'Vector reindex started for all entities',\n }\n }\n } else {\n if (input.entityType) {\n const result = await searchIndexer.reindexEntityToFulltext({\n ...baseParams,\n entityId: input.entityType,\n })\n return {\n status: 'completed',\n strategy: 'fulltext',\n entityType: input.entityType,\n ...result,\n }\n } else {\n const result = await searchIndexer.reindexAllToFulltext(baseParams)\n return {\n status: 'completed',\n strategy: 'fulltext',\n entityType: 'all',\n ...result,\n }\n }\n }\n },\n}\n\n// =============================================================================\n// Export\n// =============================================================================\n\n/**\n * All AI tools exported by the search module.\n * Discovered by ai-assistant module's generator.\n */\nexport const aiTools = [\n searchQueryTool,\n searchStatusTool,\n searchGetTool,\n searchSchemaTool,\n searchAggregateTool,\n searchReindexTool,\n]\n\nexport default aiTools\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,SAAS;AAMlB,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;
|
|
4
|
+
"sourcesContent": ["import { z } from 'zod'\nimport type {\n SearchEntityConfig,\n SearchResult,\n SearchStrategyId,\n} from '@open-mercato/shared/modules/search'\nimport { authorizeFeatures } from '@open-mercato/shared/security/featurePolicy'\nimport {\n filterSearchResultsByEntityAccess,\n resolveReadableEntityTypes,\n type SearchEntityConfigLookup,\n} from './lib/entity-access'\nimport { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'\nimport { resolveOrganizationScopeFilter } from '@open-mercato/core/modules/directory/utils/organizationScopeFilter'\nimport type { AuthContext } from '@open-mercato/shared/lib/auth/server'\nimport type { AwilixContainer } from 'awilix'\n\n/**\n * AI Tools definitions for the Search module.\n *\n * These tool definitions are discovered by the ai-assistant module's generator\n * and registered as MCP tools. The search module does not depend on ai-assistant.\n *\n * Tool Definition Format:\n * - name: Unique tool identifier (module_action format, no dots allowed)\n * - description: Human-readable description for AI clients\n * - inputSchema: Zod schema for input validation\n * - requiredFeatures: ACL features required to execute\n * - handler: Async function that executes the tool\n */\n\n/**\n * Tool context provided by the MCP server at execution time.\n */\ntype ToolContext = {\n tenantId: string | null\n organizationId: string | null\n userId: string | null\n container: {\n resolve: <T = unknown>(name: string) => T\n }\n userFeatures: string[]\n isSuperAdmin: boolean\n}\n\n/**\n * Tool definition structure.\n */\ntype AiToolDefinition = {\n name: string\n description: string\n inputSchema: z.ZodType<any>\n requiredFeatures?: string[]\n /**\n * Optional flag \u2014 when true, the tool is treated as a write by the\n * agent runtime and routed through the pending-action approval card.\n * Mirrors the public `AiToolDefinition.isMutation` flag without taking\n * a hard dependency on `@open-mercato/ai-assistant` here.\n */\n isMutation?: boolean\n handler: (input: any, ctx: ToolContext) => Promise<unknown>\n}\n\n/**\n * Minimal shape of the `searchIndexer` DI service consumed by the per-entity\n * ACL / field-policy resolution below. Aliased rather than redeclared so the\n * tools and the global-search route cannot drift apart, and still narrow enough\n * to avoid importing the full `SearchIndexer` class into the tool module.\n */\ntype SearchIndexerLike = SearchEntityConfigLookup\n\nclass SearchToolAuthorizationError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'SearchToolAuthorizationError'\n }\n}\n\n/**\n * Resolve the search config for an entity type and enforce the per-entity view\n * feature(s). Data-returning tools (`search_get` / `search_aggregate`) MUST NOT\n * rely on the search-administration `search.view` feature to gate record reads.\n *\n * Fails closed: when the entity is not configured for search, or has no\n * `aclFeatures` declared, access is denied so records are never exposed without\n * an explicit owning-module grant.\n */\nfunction authorizeEntityAccess(entityType: string, ctx: ToolContext): SearchEntityConfig {\n const searchIndexer = ctx.container.resolve<SearchIndexerLike>('searchIndexer')\n const config = searchIndexer.getEntityConfig(entityType)\n\n if (!config) {\n throw new SearchToolAuthorizationError(\n `[internal] Entity type \"${entityType}\" is not configured for search`\n )\n }\n\n if (ctx.isSuperAdmin) return config\n\n const required = config.aclFeatures\n if (!required || required.length === 0) {\n throw new SearchToolAuthorizationError(\n `[internal] Entity type \"${entityType}\" does not declare aclFeatures; access denied`\n )\n }\n\n if (!authorizeFeatures(required, {\n grantedFeatures: ctx.userFeatures,\n unrestricted: ctx.isSuperAdmin,\n })) {\n throw new SearchToolAuthorizationError(\n `[internal] Insufficient permissions for entity \"${entityType}\". Required: ${required.join(', ')}`\n )\n }\n\n return config\n}\n\n/**\n * Resolve the actor's allowed-organization scope the same way the HTTP search\n * route does, so AI search tools can never return results outside a\n * restricted user's organization allowlist \u2014 even when their current\n * organization is null. Mirrors packages/search/.../api/search/route.ts.\n *\n * `organizationId` is the re-validated selection (`scope.selectedId`), not the\n * raw `ctx.organizationId` \u2014 `SearchOptions.organizationId` takes precedence\n * over `organizationIds` in `normalizeOrganizationFilter`, so passing the\n * unvalidated context value through would let a stale/out-of-allowlist\n * selection bypass the allowlist below.\n */\nasync function resolveActorOrganizationScope(ctx: ToolContext): Promise<{\n organizationId: string | undefined\n organizationIds: string[] | undefined\n denyAll: boolean\n}> {\n if (!ctx.userId) return { organizationId: undefined, organizationIds: undefined, denyAll: true }\n const auth: AuthContext = {\n sub: ctx.userId,\n tenantId: ctx.tenantId,\n orgId: ctx.organizationId,\n isSuperAdmin: ctx.isSuperAdmin,\n }\n const scope = await resolveOrganizationScopeForRequest({\n container: ctx.container as unknown as AwilixContainer,\n auth,\n selectedId: ctx.organizationId,\n })\n const scopeFilter = resolveOrganizationScopeFilter(scope, auth)\n const denyAll = Array.isArray(scope.filterIds) && scope.filterIds.length === 0\n const organizationId = typeof scope.selectedId === 'string' && scope.selectedId.trim().length > 0\n ? scope.selectedId.trim()\n : undefined\n return { organizationId, organizationIds: scopeFilter.organizationIds, denyAll }\n}\n\n/**\n * Strip fields that the entity's field policy marks as sensitive\n * (`hashOnly` exact-match PII or fully `excluded`) from a query-engine record.\n * Defense-in-depth so even an authorized caller never receives decrypted PII or\n * fields a `fieldPolicy` keeps out of search.\n */\nfunction stripSensitiveFields(\n record: Record<string, unknown>,\n config: SearchEntityConfig\n): Record<string, unknown> {\n const sensitive = new Set<string>([\n ...(config.fieldPolicy?.hashOnly ?? []),\n ...(config.fieldPolicy?.excluded ?? []),\n ])\n if (sensitive.size === 0) return record\n const safe: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(record)) {\n if (sensitive.has(key)) continue\n safe[key] = value\n }\n return safe\n}\n\n/**\n * Determine whether a field is a safe aggregation grouping key for an entity.\n * Only fields explicitly declared `searchable` are allowed; `hashOnly` and\n * `excluded` (PII / sensitive) fields can never be enumerated via group-by.\n */\nfunction isGroupByAllowed(field: string, config: SearchEntityConfig): boolean {\n const sensitive = new Set<string>([\n ...(config.fieldPolicy?.hashOnly ?? []),\n ...(config.fieldPolicy?.excluded ?? []),\n ])\n if (sensitive.has(field)) return false\n const searchable = config.fieldPolicy?.searchable ?? []\n return searchable.includes(field)\n}\n\n// =============================================================================\n// Tool Definitions\n// =============================================================================\n\nconst searchQueryTool: AiToolDefinition = {\n name: 'search_query',\n description: `Search across all data using hybrid search. Use this FIRST for finding records.\n\nReturns: title, subtitle, entityType, recordId, url for each match.\nSearches customers, products, orders, deals, and more in one call.`,\n inputSchema: z.object({\n query: z.string().min(1).describe('The search query text'),\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .optional()\n .default(20)\n .describe('Maximum number of results to return (default: 20)'),\n entityTypes: z\n .array(z.string())\n .optional()\n .describe(\n 'Filter to specific entity types (e.g., [\"customers:customer_person_profile\", \"catalog:product\"])'\n ),\n strategies: z\n .array(z.enum(['fulltext', 'vector', 'tokens']))\n .optional()\n .describe('Specific search strategies to use (default: all available)'),\n }),\n requiredFeatures: ['search.global'],\n handler: async (input, ctx) => {\n if (!ctx.tenantId) {\n throw new Error('Tenant context is required for search')\n }\n\n const searchService = ctx.container.resolve<{\n search: (query: string, options: any) => Promise<SearchResult[]>\n }>('searchService')\n\n // Same rule the HTTP palette applies: `search.global` authorizes using search,\n // not reading every indexed entity type. The query is narrowed to the readable\n // types so `limit` is not spent on records that would be filtered out, and the\n // results are filtered afterwards as defense in depth.\n const searchIndexer = ctx.container.resolve<SearchIndexerLike>('searchIndexer')\n const subject = { grantedFeatures: ctx.userFeatures, isSuperAdmin: ctx.isSuperAdmin }\n const readableEntityTypes = resolveReadableEntityTypes(searchIndexer, subject, input.entityTypes)\n if (readableEntityTypes && readableEntityTypes.length === 0) {\n return { query: input.query, totalResults: 0, results: [] }\n }\n\n const orgScope = await resolveActorOrganizationScope(ctx)\n if (orgScope.denyAll) {\n return { query: input.query, totalResults: 0, results: [] }\n }\n\n const rawResults = await searchService.search(input.query, {\n tenantId: ctx.tenantId,\n organizationId: orgScope.organizationId,\n organizationIds: orgScope.organizationIds,\n entityTypes: readableEntityTypes,\n strategies: input.strategies as SearchStrategyId[],\n limit: input.limit,\n })\n\n const results = filterSearchResultsByEntityAccess(rawResults, searchIndexer, subject)\n\n return {\n query: input.query,\n totalResults: results.length,\n results: results.map((result) => ({\n entityType: result.entityId,\n recordId: result.recordId,\n score: Math.round(result.score * 100) / 100,\n source: result.source,\n title: result.presenter?.title ?? result.recordId,\n subtitle: result.presenter?.subtitle,\n url: result.url,\n })),\n }\n },\n}\n\nconst searchStatusTool: AiToolDefinition = {\n name: 'search_status',\n description:\n 'Get the current status of the search module, including available search strategies and their availability.',\n inputSchema: z.object({}),\n requiredFeatures: ['search.view'],\n handler: async (_input, ctx) => {\n const searchService = ctx.container.resolve<{\n getStrategies: () => Array<{\n id: string\n name: string\n priority: number\n isAvailable: () => Promise<boolean>\n }>\n getDefaultStrategies: () => string[]\n }>('searchService')\n\n const strategies = searchService.getStrategies()\n const defaultStrategies = searchService.getDefaultStrategies()\n\n const strategyStatus = await Promise.all(\n strategies.map(async (strategy) => ({\n id: strategy.id,\n name: strategy.name,\n priority: strategy.priority,\n isAvailable: await strategy.isAvailable(),\n isDefault: defaultStrategies.includes(strategy.id),\n }))\n )\n\n return {\n strategiesRegistered: strategies.length,\n defaultStrategies,\n strategies: strategyStatus,\n }\n },\n}\n\n// =============================================================================\n// search.get - Retrieve full record details by entity type and ID\n// =============================================================================\n\nconst searchGetTool: AiToolDefinition = {\n name: 'search_get',\n description: `Get full record details by entityType and recordId from search_query results.`,\n inputSchema: z.object({\n entityType: z\n .string()\n .describe('The entity type (e.g., \"customers:customer_company_profile\", \"customers:customer_deal\")'),\n recordId: z.string().describe('The record ID (UUID)'),\n }),\n requiredFeatures: ['search.view'],\n handler: async (input, ctx) => {\n if (!ctx.tenantId) {\n throw new Error('Tenant context is required')\n }\n\n const entityConfig = authorizeEntityAccess(input.entityType, ctx)\n\n const orgScope = await resolveActorOrganizationScope(ctx)\n if (orgScope.denyAll) {\n return {\n found: false,\n entityType: input.entityType,\n recordId: input.recordId,\n error: 'Record not found',\n }\n }\n\n const queryEngine = ctx.container.resolve<{\n query: (entityId: string, options: any) => Promise<{ items: unknown[]; total: number }>\n }>('queryEngine')\n\n const result = await queryEngine.query(input.entityType, {\n tenantId: ctx.tenantId,\n organizationId: orgScope.organizationId,\n organizationIds: orgScope.organizationIds,\n filters: { id: input.recordId },\n includeCustomFields: true,\n page: { page: 1, pageSize: 1 },\n })\n\n const rawRecord = result.items[0] as Record<string, unknown> | undefined\n if (!rawRecord) {\n return {\n found: false,\n entityType: input.entityType,\n recordId: input.recordId,\n error: 'Record not found',\n }\n }\n\n const record = stripSensitiveFields(rawRecord, entityConfig)\n\n // Extract custom fields\n const customFields: Record<string, unknown> = {}\n const standardFields: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(record)) {\n if (key.startsWith('cf:') || key.startsWith('cf_')) {\n customFields[key.replace(/^cf[:_]/, '')] = value\n } else {\n standardFields[key] = value\n }\n }\n\n // Build URL based on entity type\n let url: string | null = null\n const id = record.id ?? record.entity_id ?? input.recordId\n if (input.entityType.includes('person')) {\n url = `/backend/customers/people/${id}`\n } else if (input.entityType.includes('company')) {\n url = `/backend/customers/companies/${id}`\n } else if (input.entityType.includes('deal')) {\n url = `/backend/customers/deals/${id}`\n } else if (input.entityType.includes('activity')) {\n const entityId = record.entity_id ?? record.entityId\n url = entityId ? `/backend/customers/companies/${entityId}#activity-${id}` : null\n }\n\n return {\n found: true,\n entityType: input.entityType,\n recordId: input.recordId,\n record: standardFields,\n customFields: Object.keys(customFields).length > 0 ? customFields : undefined,\n url,\n }\n },\n}\n\n// =============================================================================\n// search.schema - Discover searchable entities and their fields\n// =============================================================================\n\nconst searchSchemaTool: AiToolDefinition = {\n name: 'search_schema',\n description:\n 'Discover searchable entities and their fields. Use this to learn what data can be searched and what fields are available for filtering.',\n inputSchema: z.object({\n entityType: z\n .string()\n .optional()\n .describe('Optional: Get schema for a specific entity type only'),\n }),\n requiredFeatures: ['search.view'],\n handler: async (input, ctx) => {\n const searchIndexer = ctx.container.resolve<{\n getAllEntityConfigs: () => Array<{\n entityId: string\n enabled?: boolean\n priority?: number\n strategies?: string[]\n fieldPolicy?: {\n searchable?: string[]\n hashOnly?: string[]\n excluded?: string[]\n }\n }>\n }>('searchIndexer')\n\n const allConfigs = searchIndexer.getAllEntityConfigs()\n const entities: Array<{\n entityId: string\n enabled: boolean\n priority: number\n strategies?: string[]\n searchableFields?: string[]\n hashOnlyFields?: string[]\n excludedFields?: string[]\n }> = []\n\n for (const entityConfig of allConfigs) {\n if (input.entityType && entityConfig.entityId !== input.entityType) {\n continue\n }\n\n entities.push({\n entityId: entityConfig.entityId,\n enabled: entityConfig.enabled !== false,\n priority: entityConfig.priority ?? 5,\n strategies: entityConfig.strategies,\n searchableFields: entityConfig.fieldPolicy?.searchable,\n hashOnlyFields: entityConfig.fieldPolicy?.hashOnly,\n excludedFields: entityConfig.fieldPolicy?.excluded,\n })\n }\n\n if (input.entityType && entities.length === 0) {\n return {\n found: false,\n entityType: input.entityType,\n error: 'Entity type not configured for search',\n }\n }\n\n return {\n totalEntities: entities.length,\n entities: entities.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0)),\n }\n },\n}\n\n// =============================================================================\n// search.aggregate - Get counts grouped by field values\n// =============================================================================\n\nconst searchAggregateTool: AiToolDefinition = {\n name: 'search_aggregate',\n description:\n 'Get record counts grouped by a field value. Useful for analytics like \"how many deals by stage?\" or \"customers by status\". Samples up to 100 records \u2014 percentages may not reflect the full dataset for large entity sets.',\n inputSchema: z.object({\n entityType: z\n .string()\n .describe('The entity type to aggregate (e.g., \"customers:customer_deal\")'),\n groupBy: z\n .string()\n .describe('The field to group by (e.g., \"status\", \"industry\", \"pipeline_stage\")'),\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .optional()\n .default(20)\n .describe('Maximum number of buckets to return (default: 20)'),\n }),\n requiredFeatures: ['search.view'],\n handler: async (input, ctx) => {\n if (!ctx.tenantId) {\n throw new Error('Tenant context is required')\n }\n\n const entityConfig = authorizeEntityAccess(input.entityType, ctx)\n\n if (!isGroupByAllowed(input.groupBy, entityConfig)) {\n throw new SearchToolAuthorizationError(\n `[internal] Field \"${input.groupBy}\" is not an allowed grouping key for \"${input.entityType}\"`\n )\n }\n\n const orgScope = await resolveActorOrganizationScope(ctx)\n if (orgScope.denyAll) {\n return {\n entityType: input.entityType,\n groupBy: input.groupBy,\n total: 0,\n buckets: [],\n }\n }\n\n const queryEngine = ctx.container.resolve<{\n query: (entityId: string, options: any) => Promise<{ items: unknown[]; total: number }>\n }>('queryEngine')\n\n // Fetch records and aggregate in memory\n // Note: For large datasets, this should use database GROUP BY\n const result = await queryEngine.query(input.entityType, {\n tenantId: ctx.tenantId,\n organizationId: orgScope.organizationId,\n organizationIds: orgScope.organizationIds,\n page: { page: 1, pageSize: 100 },\n })\n\n const counts = new Map<string | null, number>()\n for (const item of result.items as Record<string, unknown>[]) {\n const value = item[input.groupBy]\n const key = value === null || value === undefined ? null : String(value)\n counts.set(key, (counts.get(key) ?? 0) + 1)\n }\n\n const total = result.items.length\n const buckets = Array.from(counts.entries())\n .map(([value, count]) => ({\n value,\n count,\n percentage: Math.round((count / total) * 100 * 100) / 100,\n }))\n .sort((a, b) => b.count - a.count)\n .slice(0, input.limit)\n\n return {\n entityType: input.entityType,\n groupBy: input.groupBy,\n total,\n buckets,\n }\n },\n}\n\nconst searchReindexTool: AiToolDefinition = {\n name: 'search_reindex',\n description:\n 'Trigger a reindex operation for search data. This rebuilds the search index for the specified entity type or all entities.',\n inputSchema: z.object({\n entityType: z\n .string()\n .optional()\n .describe(\n 'Specific entity type to reindex (e.g., \"customers:customer_person_profile\"). If not provided, reindexes all entities.'\n ),\n strategy: z\n .enum(['fulltext', 'vector'])\n .optional()\n .default('fulltext')\n .describe('Which search strategy to reindex (default: fulltext)'),\n recreateIndex: z\n .boolean()\n .optional()\n .default(false)\n .describe('Whether to recreate the index from scratch (default: false)'),\n }),\n requiredFeatures: ['search.reindex'],\n // Reindex changes server-side index state \u2014 must surface as a write so\n // any agent that whitelists it routes through the approval card.\n isMutation: true,\n handler: async (input, ctx) => {\n if (!ctx.tenantId) {\n throw new Error('Tenant context is required for reindex')\n }\n\n const searchIndexer = ctx.container.resolve<{\n reindexEntityToFulltext: (params: any) => Promise<any>\n reindexAllToFulltext: (params: any) => Promise<any>\n reindexEntityToVector: (params: any) => Promise<void>\n reindexAllToVector: (params: any) => Promise<void>\n }>('searchIndexer')\n\n const baseParams = {\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId,\n recreateIndex: input.recreateIndex,\n useQueue: true,\n }\n\n if (input.strategy === 'vector') {\n if (input.entityType) {\n await searchIndexer.reindexEntityToVector({\n ...baseParams,\n entityId: input.entityType,\n })\n return {\n status: 'started',\n strategy: 'vector',\n entityType: input.entityType,\n message: `Vector reindex started for ${input.entityType}`,\n }\n } else {\n await searchIndexer.reindexAllToVector(baseParams)\n return {\n status: 'started',\n strategy: 'vector',\n entityType: 'all',\n message: 'Vector reindex started for all entities',\n }\n }\n } else {\n if (input.entityType) {\n const result = await searchIndexer.reindexEntityToFulltext({\n ...baseParams,\n entityId: input.entityType,\n })\n return {\n status: 'completed',\n strategy: 'fulltext',\n entityType: input.entityType,\n ...result,\n }\n } else {\n const result = await searchIndexer.reindexAllToFulltext(baseParams)\n return {\n status: 'completed',\n strategy: 'fulltext',\n entityType: 'all',\n ...result,\n }\n }\n }\n },\n}\n\n// =============================================================================\n// Export\n// =============================================================================\n\n/**\n * All AI tools exported by the search module.\n * Discovered by ai-assistant module's generator.\n */\nexport const aiTools = [\n searchQueryTool,\n searchStatusTool,\n searchGetTool,\n searchSchemaTool,\n searchAggregateTool,\n searchReindexTool,\n]\n\nexport default aiTools\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS;AAMlB,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,0CAA0C;AACnD,SAAS,sCAAsC;AA0D/C,MAAM,qCAAqC,MAAM;AAAA,EAC/C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAWA,SAAS,sBAAsB,YAAoB,KAAsC;AACvF,QAAM,gBAAgB,IAAI,UAAU,QAA2B,eAAe;AAC9E,QAAM,SAAS,cAAc,gBAAgB,UAAU;AAEvD,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR,2BAA2B,UAAU;AAAA,IACvC;AAAA,EACF;AAEA,MAAI,IAAI,aAAc,QAAO;AAE7B,QAAM,WAAW,OAAO;AACxB,MAAI,CAAC,YAAY,SAAS,WAAW,GAAG;AACtC,UAAM,IAAI;AAAA,MACR,2BAA2B,UAAU;AAAA,IACvC;AAAA,EACF;AAEA,MAAI,CAAC,kBAAkB,UAAU;AAAA,IAC/B,iBAAiB,IAAI;AAAA,IACrB,cAAc,I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,OAAO;AACL,cAAM,SAAS,MAAM,cAAc,qBAAqB,UAAU;AAClE,eAAO;AAAA,UACL,QAAQ;AAAA,UACR,UAAU;AAAA,UACV,YAAY;AAAA,UACZ,GAAG;AAAA,QACL;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAUO,MAAM,UAAU;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAO,mBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -80,6 +80,10 @@ const EMBEDDING_PROVIDERS = {
|
|
|
80
80
|
]
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
|
+
function flashRequestError(err, fallbackMessage) {
|
|
84
|
+
const message = err instanceof Error && err.message.trim() ? err.message : fallbackMessage;
|
|
85
|
+
flash(message, "error");
|
|
86
|
+
}
|
|
83
87
|
function VectorSearchSection({
|
|
84
88
|
embeddingSettings,
|
|
85
89
|
embeddingLoading,
|
|
@@ -96,6 +100,7 @@ function VectorSearchSection({
|
|
|
96
100
|
const [selectedModel, setSelectedModel] = React.useState(null);
|
|
97
101
|
const [customModelName, setCustomModelName] = React.useState("");
|
|
98
102
|
const [customDimension, setCustomDimension] = React.useState(768);
|
|
103
|
+
const [ollamaBaseUrlDraft, setOllamaBaseUrlDraft] = React.useState(null);
|
|
99
104
|
const [pendingEmbeddingConfig, setPendingEmbeddingConfig] = React.useState(null);
|
|
100
105
|
const [showEmbeddingConfirmDialog, setShowEmbeddingConfirmDialog] = React.useState(false);
|
|
101
106
|
const [vectorReindexing, setVectorReindexing] = React.useState(false);
|
|
@@ -162,7 +167,8 @@ function VectorSearchSection({
|
|
|
162
167
|
autoIndexingPreviousRef.current = body.settings.autoIndexingEnabled;
|
|
163
168
|
}
|
|
164
169
|
flash(t("search.settings.messages.saved", "Settings saved"), "success");
|
|
165
|
-
} catch {
|
|
170
|
+
} catch (err) {
|
|
171
|
+
flashRequestError(err, t("search.settings.errors.saveFailed", "Failed to save settings"));
|
|
166
172
|
if (embeddingSettings) {
|
|
167
173
|
onEmbeddingSettingsUpdate({ ...embeddingSettings, autoIndexingEnabled: autoIndexingPreviousRef.current });
|
|
168
174
|
}
|
|
@@ -175,6 +181,7 @@ function VectorSearchSection({
|
|
|
175
181
|
setSelectedModel(null);
|
|
176
182
|
setCustomModelName("");
|
|
177
183
|
setCustomDimension(768);
|
|
184
|
+
setOllamaBaseUrlDraft(null);
|
|
178
185
|
};
|
|
179
186
|
const handleModelChange = (modelId) => {
|
|
180
187
|
setSelectedModel(modelId);
|
|
@@ -207,6 +214,10 @@ function VectorSearchSection({
|
|
|
207
214
|
dimension,
|
|
208
215
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
209
216
|
};
|
|
217
|
+
const ollamaBaseUrl = (ollamaBaseUrlDraft ?? savedOllamaBaseUrl).trim();
|
|
218
|
+
if (newProviderId === "ollama" && ollamaBaseUrl) {
|
|
219
|
+
newConfig.baseUrl = ollamaBaseUrl;
|
|
220
|
+
}
|
|
210
221
|
if (embeddingSettings?.indexedDimension || embeddingSettings?.embeddingConfig) {
|
|
211
222
|
setPendingEmbeddingConfig(newConfig);
|
|
212
223
|
setShowEmbeddingConfirmDialog(true);
|
|
@@ -219,6 +230,7 @@ function VectorSearchSection({
|
|
|
219
230
|
setSelectedModel(null);
|
|
220
231
|
setCustomModelName("");
|
|
221
232
|
setCustomDimension(768);
|
|
233
|
+
setOllamaBaseUrlDraft(null);
|
|
222
234
|
};
|
|
223
235
|
const applyEmbeddingConfig = async (config) => {
|
|
224
236
|
setEmbeddingSaving(true);
|
|
@@ -236,9 +248,11 @@ function VectorSearchSection({
|
|
|
236
248
|
);
|
|
237
249
|
setSelectedProvider(null);
|
|
238
250
|
setSelectedModel(null);
|
|
251
|
+
setOllamaBaseUrlDraft(null);
|
|
239
252
|
flash(t("search.settings.messages.providerSaved", "Embedding provider saved"), "success");
|
|
240
253
|
await onRefreshEmbeddings();
|
|
241
|
-
} catch {
|
|
254
|
+
} catch (err) {
|
|
255
|
+
flashRequestError(err, t("search.settings.errors.saveFailed", "Failed to save settings"));
|
|
242
256
|
} finally {
|
|
243
257
|
setEmbeddingSaving(false);
|
|
244
258
|
}
|
|
@@ -270,7 +284,8 @@ function VectorSearchSection({
|
|
|
270
284
|
);
|
|
271
285
|
flash(t("search.settings.messages.reindexStarted", "Reindex started"), "success");
|
|
272
286
|
await fetchActivityLogs();
|
|
273
|
-
} catch {
|
|
287
|
+
} catch (err) {
|
|
288
|
+
flashRequestError(err, t("search.settings.errors.reindexFailed", "Reindex failed"));
|
|
274
289
|
} finally {
|
|
275
290
|
setVectorReindexing(false);
|
|
276
291
|
}
|
|
@@ -282,6 +297,7 @@ function VectorSearchSection({
|
|
|
282
297
|
const savedProviderInfo = EMBEDDING_PROVIDERS[savedProvider];
|
|
283
298
|
const savedModel = embeddingSettings?.embeddingConfig?.model ?? savedProviderInfo.defaultModel;
|
|
284
299
|
const savedDimension = embeddingSettings?.embeddingConfig?.dimension ?? savedProviderInfo.models[0]?.dimension ?? 768;
|
|
300
|
+
const savedOllamaBaseUrl = savedProvider === "ollama" ? embeddingSettings?.embeddingConfig?.baseUrl ?? "" : "";
|
|
285
301
|
const savedModelIsPredefined = savedProviderInfo.models.some((m) => m.id === savedModel);
|
|
286
302
|
const savedCustomModel = !savedModelIsPredefined && savedModel ? { id: savedModel, name: savedModel, dimension: savedDimension } : null;
|
|
287
303
|
const displayProvider = selectedProvider ?? savedProvider;
|
|
@@ -291,7 +307,7 @@ function VectorSearchSection({
|
|
|
291
307
|
const displayModelIsSavedCustom = !isCustomModel && displayProvider === savedProvider && savedCustomModel && displayModel === savedCustomModel.id;
|
|
292
308
|
const displayModelInfo = isCustomModel ? null : displayModelIsSavedCustom ? savedCustomModel : displayProviderInfo.models.find((m) => m.id === displayModel) ?? displayProviderInfo.models[0];
|
|
293
309
|
const displayDimension = isCustomModel ? customDimension : displayModelInfo?.dimension ?? 768;
|
|
294
|
-
const hasUnsavedEmbeddingChanges = selectedProvider !== null && selectedProvider !== savedProvider || selectedModel !== null && selectedModel !== savedModel || selectedProvider !== null && selectedModel === null && displayProviderInfo.defaultModel !== savedModel || isCustomModel && (customModelName.trim() !== "" || customDimension !== 768);
|
|
310
|
+
const hasUnsavedEmbeddingChanges = selectedProvider !== null && selectedProvider !== savedProvider || selectedModel !== null && selectedModel !== savedModel || selectedProvider !== null && selectedModel === null && displayProviderInfo.defaultModel !== savedModel || isCustomModel && (customModelName.trim() !== "" || customDimension !== 768) || displayProvider === "ollama" && ollamaBaseUrlDraft !== null && ollamaBaseUrlDraft.trim() !== savedOllamaBaseUrl;
|
|
295
311
|
const isEmbeddingConfigured = embeddingSettings?.configuredProviders?.includes(savedProvider);
|
|
296
312
|
const providerOptions = ["openai", "google", "mistral", "cohere", "bedrock", "ollama"];
|
|
297
313
|
const activeDriver = vectorStoreConfig?.drivers.find((driver) => driver.id === vectorStoreConfig.currentDriver);
|
|
@@ -431,6 +447,23 @@ function VectorSearchSection({
|
|
|
431
447
|
}
|
|
432
448
|
)
|
|
433
449
|
] }),
|
|
450
|
+
providerId === "ollama" && /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
|
|
451
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "ollama-base-url", className: "text-xs font-medium", children: t("search.settings.ollama.baseUrl.label", "Base URL") }),
|
|
452
|
+
/* @__PURE__ */ jsx(
|
|
453
|
+
Input,
|
|
454
|
+
{
|
|
455
|
+
id: "ollama-base-url",
|
|
456
|
+
type: "url",
|
|
457
|
+
size: "sm",
|
|
458
|
+
value: ollamaBaseUrlDraft ?? savedOllamaBaseUrl,
|
|
459
|
+
onChange: (e) => setOllamaBaseUrlDraft(e.target.value),
|
|
460
|
+
placeholder: "http://localhost:11434",
|
|
461
|
+
"aria-describedby": "ollama-base-url-hint",
|
|
462
|
+
disabled: embeddingLoading || embeddingSaving
|
|
463
|
+
}
|
|
464
|
+
),
|
|
465
|
+
/* @__PURE__ */ jsx("p", { id: "ollama-base-url-hint", className: "text-xs text-muted-foreground", children: t("search.settings.ollama.baseUrl.hint", "Leave empty to use the OLLAMA_BASE_URL environment variable.") })
|
|
466
|
+
] }),
|
|
434
467
|
isCustomModel && /* @__PURE__ */ jsxs("div", { className: "space-y-2 rounded border border-input bg-muted/30 p-2", children: [
|
|
435
468
|
/* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
|
|
436
469
|
/* @__PURE__ */ jsx(Label, { htmlFor: `custom-model-name-${providerId}`, className: "text-xs font-medium", children: t("search.settings.model.namePlaceholder", "Model name") }),
|